How to place 3D-model to the scene from plugin/module?

I want to place 3D-models to scene like FileSystem drag-n-drop, but from my plugin or native module. I’m investigating the topic and see two ways:

  1. do raycast from editor camera to calculate 3D position, but it is not trivial (at least How to get the editor's camera?)
  2. Investigate filesystem_dock.cpp, but this is absolutely not understandable code for me. Especially without docs.

So, what way do you recommend to use? Maybe something other? Simplier? Maybe do you know some plugins which implements this feature?

You could try using the same drag data format as the editor uses. It sends a Dictionary with the format:

{ 
  "type": "files",
  "files": ["res://assets/characters_3d/Dancing.fbx"], 
  "from": @Tree@5833:<Tree#533934925590> 
}

So create a dictionary in _get_drag_data() with that same format.

{ 
  "type": "files",
  "files": [<path to your file>], 
  "from": null # I don't think this is needed
}

The first problem is that I don’t have any files. I generate a scene object (model, mesh, node, etc.) inside my plugin. Then I click a button and my model should be connected to the 3D cursor like in the previous movie.

I think here is how the editor does it godot/editor/plugins/node_3d_editor_plugin.cpp at 0bcc0e92b3f0ac57d4c4650722f347593a258572 · godotengine/godot · GitHub