Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import scenes as AnimationLibrary #60177

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions doc/classes/EditorSceneFormatImporter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@
<method name="_get_option_visibility" qualifiers="virtual const">
<return type="Variant" />
<argument index="0" name="path" type="String" />
<argument index="1" name="option" type="String" />
<description>
</description>
</method>
<method name="_import_animation" qualifiers="virtual">
<return type="Animation" />
<argument index="0" name="path" type="String" />
<argument index="1" name="flags" type="int" />
<argument index="2" name="options" type="Dictionary" />
<argument index="3" name="bake_fps" type="int" />
<argument index="1" name="for_animation" type="bool" />
<argument index="2" name="option" type="String" />
<description>
</description>
</method>
Expand All @@ -63,5 +55,7 @@
</constant>
<constant name="IMPORT_USE_NAMED_SKIN_BINDS" value="16">
</constant>
<constant name="IMPORT_DISCARD_MESHES_AND_MATERIALS" value="32">
</constant>
</constants>
</class>
6 changes: 4 additions & 2 deletions doc/classes/EditorScenePostImportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@
<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" />
<argument index="1" name="for_animation" type="bool" />
<argument index="2" 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="path" type="String" />
<argument index="1" name="option" type="String" />
<argument index="1" name="for_animation" type="bool" />
<argument index="2" name="option" type="String" />
<description>
Return true or false whether a given option should be visible. Return null to ignore.
</description>
Expand Down
11 changes: 8 additions & 3 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5997,18 +5997,22 @@ EditorNode::EditorNode() {
import_scene.instantiate();
ResourceFormatImporter::get_singleton()->add_importer(import_scene);

Ref<ResourceImporterScene> import_animation;
import_animation = Ref<ResourceImporterScene>(memnew(ResourceImporterScene(true)));
ResourceFormatImporter::get_singleton()->add_importer(import_animation);

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

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

Ref<EditorSceneFormatImporterESCN> import_escn;
import_escn.instantiate();
import_scene->add_importer(import_escn);
ResourceImporterScene::add_importer(import_escn);
}

Ref<ResourceImporterBitMap> import_bitmap;
Expand Down Expand Up @@ -7245,6 +7249,7 @@ EditorNode::EditorNode() {
EditorNode::~EditorNode() {
EditorInspector::cleanup_plugins();
EditorTranslationParser::get_singleton()->clean_parsers();
ResourceImporterScene::clean_up_importer_plugins();

remove_print_handler(&print_handler);
EditorHelp::cleanup_doc();
Expand Down
8 changes: 4 additions & 4 deletions editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,20 +763,20 @@ void EditorPlugin::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_p

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

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);
ResourceImporterScene::remove_importer(p_importer);
}

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

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

int find(const PackedStringArray &a, const String &v) {
Expand Down
24 changes: 22 additions & 2 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorit

{
List<String> importer_exts;
ResourceImporterScene::get_singleton()->get_recognized_extensions(&importer_exts);
ResourceImporterScene::get_scene_singleton()->get_recognized_extensions(&importer_exts);
String extension = fpath.get_extension();
for (const String &E : importer_exts) {
if (extension.nocasecmp_to(E) == 0) {
Expand All @@ -1000,7 +1000,27 @@ void FileSystemDock::_select_file(const String &p_path, bool p_select_in_favorit
}

if (is_imported) {
ResourceImporterScene::get_singleton()->show_advanced_options(fpath);
ResourceImporterScene::get_scene_singleton()->show_advanced_options(fpath);
} else {
EditorNode::get_singleton()->open_request(fpath);
}
} else if (ResourceLoader::get_resource_type(fpath) == "AnimationLibrary") {
bool is_imported = false;

{
List<String> importer_exts;
ResourceImporterScene::get_animation_singleton()->get_recognized_extensions(&importer_exts);
String extension = fpath.get_extension();
for (const String &E : importer_exts) {
if (extension.nocasecmp_to(E) == 0) {
is_imported = true;
break;
}
}
}

if (is_imported) {
ResourceImporterScene::get_animation_singleton()->show_advanced_options(fpath);
} else {
EditorNode::get_singleton()->open_request(fpath);
}
Expand Down
21 changes: 0 additions & 21 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,26 +1817,5 @@ Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint3
return state.scene;
}

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

state.use_mesh_builtin_materials = false;

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);
if (state.scene) {
memdelete(state.scene);
}

if (state.animations.size() == 0) {
return Ref<Animation>();
}
Ref<Animation> anim = state.animations[0];

return anim;
}

EditorSceneFormatImporterCollada::EditorSceneFormatImporterCollada() {
}
1 change: 0 additions & 1 deletion editor/import/editor_import_collada.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class EditorSceneFormatImporterCollada : public EditorSceneFormatImporter {
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, const Map<StringName, Variant> &p_options, 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, const Map<StringName, Variant> &p_options, int p_bake_fps) override;

EditorSceneFormatImporterCollada();
};
Expand Down
4 changes: 0 additions & 4 deletions editor/import/resource_importer_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,6 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, co
return scene;
}

Ref<Animation> EditorOBJImporter::import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) {
return Ref<Animation>();
}

void EditorOBJImporter::get_extensions(List<String> *r_extensions) const {
r_extensions->push_back("obj");
}
Expand Down
1 change: 0 additions & 1 deletion editor/import/resource_importer_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class EditorOBJImporter : public EditorSceneFormatImporter {
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, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr) override;
virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) override;

EditorOBJImporter();
};
Expand Down
Loading