Skip to content

Commit

Permalink
Merge pull request godotengine#53813 from reduz/editor-import-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Oct 15, 2021
2 parents 5bc0e40 + b3bf90b commit 55c71ba
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 109 deletions.
28 changes: 21 additions & 7 deletions doc/classes/EditorPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@
<argument index="0" name="importer" type="EditorImportPlugin" />
<description>
Registers a new [EditorImportPlugin]. Import plugins are used to import custom and unsupported assets as a custom [Resource] type.
[b]Note:[/b] If you want to import custom 3D asset formats use [method add_scene_import_plugin] instead.
[b]Note:[/b] If you want to import custom 3D asset formats use [method add_scene_format_importer_plugin] instead.
See [method add_inspector_plugin] for an example of how to register a plugin.
</description>
</method>
Expand All @@ -405,11 +405,18 @@
[/codeblocks]
</description>
</method>
<method name="add_scene_import_plugin">
<method name="add_scene_format_importer_plugin">
<return type="void" />
<argument index="0" name="scene_importer" type="EditorSceneImporter" />
<argument index="0" name="scene_format_importer" type="EditorSceneFormatImporter" />
<description>
Registers a new [EditorSceneImporter]. Scene importers are used to import custom 3D asset formats as scenes.
Registers a new [EditorSceneFormatImporter]. Scene importers are used to import custom 3D asset formats as scenes.
</description>
</method>
<method name="add_scene_post_import_plugin">
<return type="void" />
<argument index="0" name="scene_import_plugin" type="EditorScenePostImportPlugin" />
<description>
Add a [EditorScenePostImportPlugin]. These plugins allow customizing the import process of 3D assets by adding new options to the import dialogs.
</description>
</method>
<method name="add_spatial_gizmo_plugin">
Expand Down Expand Up @@ -553,11 +560,18 @@
Removes an inspector plugin registered by [method add_import_plugin]
</description>
</method>
<method name="remove_scene_import_plugin">
<method name="remove_scene_format_importer_plugin">
<return type="void" />
<argument index="0" name="scene_format_importer" type="EditorSceneFormatImporter" />
<description>
Removes a scene format importer registered by [method add_scene_format_importer_plugin].
</description>
</method>
<method name="remove_scene_post_import_plugin">
<return type="void" />
<argument index="0" name="scene_importer" type="EditorSceneImporter" />
<argument index="0" name="scene_import_plugin" type="EditorScenePostImportPlugin" />
<description>
Removes a scene importer registered by [method add_scene_import_plugin].
Remove the [EditorScenePostImportPlugin], added with [method add_scene_post_import_plugin].
</description>
</method>
<method name="remove_spatial_gizmo_plugin">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSceneImporter" inherits="RefCounted" version="4.0">
<class name="EditorSceneFormatImporter" inherits="RefCounted" version="4.0">
<brief_description>
Imports scenes from third-parties' 3D files.
</brief_description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSceneImporterFBX" inherits="EditorSceneImporter" version="4.0">
<class name="EditorSceneFormatImporterFBX" inherits="EditorSceneFormatImporter" version="4.0">
<brief_description>
FBX 3D asset importer.
</brief_description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSceneImporterGLTF" inherits="EditorSceneImporter" version="4.0">
<class name="EditorSceneFormatImporterGLTF" inherits="EditorSceneFormatImporter" version="4.0">
<brief_description>
</brief_description>
<description>
Expand Down
116 changes: 116 additions & 0 deletions doc/classes/EditorScenePostImportPlugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorScenePostImportPlugin" inherits="RefCounted" version="4.0">
<brief_description>
Plugin to control and modifying the process of importing a scene.
</brief_description>
<description>
This plugin type exists to modify the process of importing scenes, allowing to change the content as well as add importer options at every stage of the process.
</description>
<tutorials>
</tutorials>
<methods>
<method name="_get_import_options" qualifiers="virtual">
<return type="void" />
<description>
Override to add general import options. These will appear in the main import dock on the editor. Add options via [method add_import_option] and [method add_import_option_advanced].
</description>
</method>
<method name="_get_internal_import_options" qualifiers="virtual">
<return type="void" />
<argument index="0" name="category" type="int" />
<description>
Override to add internal import options. These will appear in the 3D scene import dialog. Add options via [method add_import_option] and [method add_import_option_advanced].
</description>
</method>
<method name="_get_internal_option_update_view_required" qualifiers="virtual const">
<return type="Variant" />
<argument index="0" name="category" type="int" />
<argument index="1" name="option" type="String" />
<description>
Return true whether updating the 3D view of the import dialog needs to be updated if an option has changed.
</description>
</method>
<method name="_get_internal_option_visibility" qualifiers="virtual const">
<return type="Variant" />
<argument index="0" name="category" type="int" />
<argument index="1" name="option" type="String" />
<description>
Return true or false whether a given option should be visible. Return null to ignore.
</description>
</method>
<method name="_get_option_visibility" qualifiers="virtual const">
<return type="Variant" />
<argument index="0" name="option" type="String" />
<description>
Return true or false whether a given option should be visible. Return null to ignore.
</description>
</method>
<method name="_internal_process" qualifiers="virtual">
<return type="void" />
<argument index="0" name="category" type="int" />
<argument index="1" name="base_node" type="Node" />
<argument index="2" name="node" type="Node" />
<argument index="3" name="resource" type="Resource" />
<description>
Process a specific node or resource for a given category.
</description>
</method>
<method name="_post_process" qualifiers="virtual">
<return type="void" />
<argument index="0" name="scene" type="Node" />
<description>
Post process the scene. This function is called after the final scene has been configured.
</description>
</method>
<method name="_pre_process" qualifiers="virtual">
<return type="void" />
<argument index="0" name="scene" type="Node" />
<description>
Pre Process the scene. This function is called right after the scene format loader loaded the scene and no changes have been made.
</description>
</method>
<method name="add_import_option">
<return type="void" />
<argument index="0" name="name" type="String" />
<argument index="1" name="value" type="Variant" />
<description>
Add a specific import option (name and default value only). This function can only be called from [method _get_import_options] and [method _get_internal_import_options].
</description>
</method>
<method name="add_import_option_advanced">
<return type="void" />
<argument index="0" name="type" type="int" enum="Variant.Type" />
<argument index="1" name="name" type="String" />
<argument index="2" name="default_value" type="Variant" />
<argument index="3" name="hint" type="int" enum="PropertyHint" default="0" />
<argument index="4" name="hint_string" type="String" default="&quot;&quot;" />
<argument index="5" name="usage_flags" type="int" default="7" />
<description>
Add a specific import option. This function can only be called from [method _get_import_options] and [method _get_internal_import_options].
</description>
</method>
<method name="get_option_value" qualifiers="const">
<return type="Variant" />
<argument index="0" name="name" type="StringName" />
<description>
Query the value of an option. This function can only be called from those querying visibility, or processing.
</description>
</method>
</methods>
<constants>
<constant name="INTERNAL_IMPORT_CATEGORY_NODE" value="0" enum="InternalImportCategory">
</constant>
<constant name="INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE" value="1" enum="InternalImportCategory">
</constant>
<constant name="INTERNAL_IMPORT_CATEGORY_MESH" value="2" enum="InternalImportCategory">
</constant>
<constant name="INTERNAL_IMPORT_CATEGORY_MATERIAL" value="3" enum="InternalImportCategory">
</constant>
<constant name="INTERNAL_IMPORT_CATEGORY_ANIMATION" value="4" enum="InternalImportCategory">
</constant>
<constant name="INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE" value="5" enum="InternalImportCategory">
</constant>
<constant name="INTERNAL_IMPORT_CATEGORY_MAX" value="6" enum="InternalImportCategory">
</constant>
</constants>
</class>
7 changes: 4 additions & 3 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3848,7 +3848,8 @@ void EditorNode::register_editor_types() {
GDREGISTER_VIRTUAL_CLASS(EditorInterface);
GDREGISTER_CLASS(EditorExportPlugin);
GDREGISTER_CLASS(EditorResourceConversionPlugin);
GDREGISTER_CLASS(EditorSceneImporter);
GDREGISTER_CLASS(EditorSceneFormatImporter);
GDREGISTER_CLASS(EditorScenePostImportPlugin);
GDREGISTER_CLASS(EditorInspector);
GDREGISTER_CLASS(EditorInspectorPlugin);
GDREGISTER_CLASS(EditorProperty);
Expand Down Expand Up @@ -5935,15 +5936,15 @@ EditorNode::EditorNode() {
ResourceFormatImporter::get_singleton()->add_importer(import_scene);

{
Ref<EditorSceneImporterCollada> import_collada;
Ref<EditorSceneFormatImporterCollada> import_collada;
import_collada.instantiate();
import_scene->add_importer(import_collada);

Ref<EditorOBJImporter> import_obj2;
import_obj2.instantiate();
import_scene->add_importer(import_obj2);

Ref<EditorSceneImporterESCN> import_escn;
Ref<EditorSceneFormatImporterESCN> import_escn;
import_escn.instantiate();
import_scene->add_importer(import_escn);
}
Expand Down
17 changes: 13 additions & 4 deletions editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,16 +762,23 @@ void EditorPlugin::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_p
EditorInspector::remove_inspector_plugin(p_plugin);
}

void EditorPlugin::add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer) {
void EditorPlugin::add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer) {
ERR_FAIL_COND(!p_importer.is_valid());
ResourceImporterScene::get_singleton()->add_importer(p_importer);
}

void EditorPlugin::remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer) {
void EditorPlugin::remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer) {
ERR_FAIL_COND(!p_importer.is_valid());
ResourceImporterScene::get_singleton()->remove_importer(p_importer);
}

void EditorPlugin::add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin) {
ResourceImporterScene::get_singleton()->add_post_importer_plugin(p_plugin);
}
void EditorPlugin::remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin) {
ResourceImporterScene::get_singleton()->remove_post_importer_plugin(p_plugin);
}

int find(const PackedStringArray &a, const String &v) {
const String *r = a.ptr();
for (int j = 0; j < a.size(); ++j) {
Expand Down Expand Up @@ -879,8 +886,10 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_translation_parser_plugin", "parser"), &EditorPlugin::remove_translation_parser_plugin);
ClassDB::bind_method(D_METHOD("add_import_plugin", "importer"), &EditorPlugin::add_import_plugin);
ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin);
ClassDB::bind_method(D_METHOD("add_scene_import_plugin", "scene_importer"), &EditorPlugin::add_scene_import_plugin);
ClassDB::bind_method(D_METHOD("remove_scene_import_plugin", "scene_importer"), &EditorPlugin::remove_scene_import_plugin);
ClassDB::bind_method(D_METHOD("add_scene_format_importer_plugin", "scene_format_importer"), &EditorPlugin::add_scene_format_importer_plugin);
ClassDB::bind_method(D_METHOD("remove_scene_format_importer_plugin", "scene_format_importer"), &EditorPlugin::remove_scene_format_importer_plugin);
ClassDB::bind_method(D_METHOD("add_scene_post_import_plugin", "scene_import_plugin"), &EditorPlugin::add_scene_post_import_plugin);
ClassDB::bind_method(D_METHOD("remove_scene_post_import_plugin", "scene_import_plugin"), &EditorPlugin::remove_scene_post_import_plugin);
ClassDB::bind_method(D_METHOD("add_export_plugin", "plugin"), &EditorPlugin::add_export_plugin);
ClassDB::bind_method(D_METHOD("remove_export_plugin", "plugin"), &EditorPlugin::remove_export_plugin);
ClassDB::bind_method(D_METHOD("add_spatial_gizmo_plugin", "plugin"), &EditorPlugin::add_spatial_gizmo_plugin);
Expand Down
7 changes: 5 additions & 2 deletions editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ class EditorPlugin : public Node {
void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);

void add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
void remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
void add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer);
void remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer);

void add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer);
void remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_importer);

void add_autoload_singleton(const String &p_name, const String &p_path);
void remove_autoload_singleton(const String &p_name);
Expand Down
14 changes: 7 additions & 7 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,15 +1748,15 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) {
/*************************************** SCENE ***********************************/
/*********************************************************************************/

uint32_t EditorSceneImporterCollada::get_import_flags() const {
uint32_t EditorSceneFormatImporterCollada::get_import_flags() const {
return IMPORT_SCENE | IMPORT_ANIMATION;
}

void EditorSceneImporterCollada::get_extensions(List<String> *r_extensions) const {
void EditorSceneFormatImporterCollada::get_extensions(List<String> *r_extensions) const {
r_extensions->push_back("dae");
}

Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
if (r_err) {
*r_err = OK;
}
Expand All @@ -1769,7 +1769,7 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_
state.use_mesh_builtin_materials = true;
state.bake_fps = p_bake_fps;

Error err = state.load(p_path, flags, p_flags & EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS, false);
Error err = state.load(p_path, flags, p_flags & EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, false);

if (r_err) {
*r_err = err;
Expand Down Expand Up @@ -1812,12 +1812,12 @@ Node *EditorSceneImporterCollada::import_scene(const String &p_path, uint32_t p_
return state.scene;
}

Ref<Animation> EditorSceneImporterCollada::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
Ref<Animation> EditorSceneFormatImporterCollada::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
ColladaImport state;

state.use_mesh_builtin_materials = false;

Error err = state.load(p_path, Collada::IMPORT_FLAG_ANIMATION, p_flags & EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS);
Error err = state.load(p_path, Collada::IMPORT_FLAG_ANIMATION, p_flags & EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS);
ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load animation from file '" + p_path + "'.");

state.create_animations(true);
Expand All @@ -1833,5 +1833,5 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String &p_path
return anim;
}

EditorSceneImporterCollada::EditorSceneImporterCollada() {
EditorSceneFormatImporterCollada::EditorSceneFormatImporterCollada() {
}
6 changes: 3 additions & 3 deletions editor/import/editor_import_collada.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@

#include "editor/import/resource_importer_scene.h"

class EditorSceneImporterCollada : public EditorSceneImporter {
GDCLASS(EditorSceneImporterCollada, EditorSceneImporter);
class EditorSceneFormatImporterCollada : public EditorSceneFormatImporter {
GDCLASS(EditorSceneFormatImporterCollada, EditorSceneFormatImporter);

public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps = nullptr, Error *r_err = nullptr) override;
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) override;

EditorSceneImporterCollada();
EditorSceneFormatImporterCollada();
};

#endif
4 changes: 2 additions & 2 deletions editor/import/resource_importer_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

#include "resource_importer_scene.h"

class EditorOBJImporter : public EditorSceneImporter {
GDCLASS(EditorOBJImporter, EditorSceneImporter);
class EditorOBJImporter : public EditorSceneFormatImporter {
GDCLASS(EditorOBJImporter, EditorSceneFormatImporter);

public:
virtual uint32_t get_import_flags() const override;
Expand Down
Loading

0 comments on commit 55c71ba

Please sign in to comment.