summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/editor_node.cpp2
-rw-r--r--editor/editor_plugin.cpp11
-rw-r--r--editor/editor_plugin.h4
-rw-r--r--editor/import/editor_import_collada.cpp2
-rw-r--r--editor/import/editor_import_collada.h2
-rw-r--r--editor/import/editor_scene_importer_gltf.cpp2
-rw-r--r--editor/import/editor_scene_importer_gltf.h2
-rw-r--r--editor/import/resource_importer_obj.cpp2
-rw-r--r--editor/import/resource_importer_obj.h2
-rw-r--r--editor/import/resource_importer_scene.cpp152
-rw-r--r--editor/import/resource_importer_scene.h19
11 files changed, 190 insertions, 10 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 76d77ac7a1..0252358a27 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -3364,6 +3364,8 @@ void EditorNode::register_editor_types() {
ClassDB::register_virtual_class<EditorInterface>();
ClassDB::register_class<EditorExportPlugin>();
ClassDB::register_class<EditorResourceConversionPlugin>();
+ ClassDB::register_class<EditorSceneImporter>();
+
// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
ClassDB::register_class<EditorScenePostImport>();
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index 9b1a3cbd72..a39e4d6efb 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -581,6 +581,15 @@ void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporte
EditorExport::get_singleton()->remove_export_plugin(p_exporter);
}
+void EditorPlugin::add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer) {
+ ResourceImporterScene::get_singleton()->add_importer(p_importer);
+}
+
+void EditorPlugin::remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer) {
+ ResourceImporterScene::get_singleton()->remove_importer(p_importer);
+
+}
+
void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
if (get_script_instance() && get_script_instance()->has_method("set_window_layout")) {
@@ -636,6 +645,8 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
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_export_plugin", "exporter"), &EditorPlugin::add_export_plugin);
ClassDB::bind_method(D_METHOD("remove_export_plugin", "exporter"), &EditorPlugin::remove_export_plugin);
ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);
diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h
index 31b887b30f..89a6d3d250 100644
--- a/editor/editor_plugin.h
+++ b/editor/editor_plugin.h
@@ -35,6 +35,7 @@
#include "scene/gui/tool_button.h"
#include "scene/main/node.h"
#include "scene/resources/texture.h"
+#include "editor/import/resource_importer_scene.h"
#include "undo_redo.h"
/**
@@ -200,6 +201,9 @@ public:
void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
+ void add_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
+ void remove_scene_import_plugin(const Ref<EditorSceneImporter> &p_importer);
+
EditorPlugin();
virtual ~EditorPlugin();
};
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index f51bc2d6be..c38391c71b 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -1979,7 +1979,7 @@ 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) {
+Ref<Animation> EditorSceneImporterCollada::import_animation(const String &p_path, uint32_t p_flags,int p_bake_fps) {
ColladaImport state;
diff --git a/editor/import/editor_import_collada.h b/editor/import/editor_import_collada.h
index 865a72739f..986b5b766f 100644
--- a/editor/import/editor_import_collada.h
+++ b/editor/import/editor_import_collada.h
@@ -40,7 +40,7 @@ public:
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps = NULL, Error *r_err = NULL);
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags);
+ virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags,int p_bake_fps);
EditorSceneImporterCollada();
};
diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp
index f704d97373..e801f3e7c3 100644
--- a/editor/import/editor_scene_importer_gltf.cpp
+++ b/editor/import/editor_scene_importer_gltf.cpp
@@ -2106,7 +2106,7 @@ Node *EditorSceneImporterGLTF::import_scene(const String &p_path, uint32_t p_fla
return scene;
}
-Ref<Animation> EditorSceneImporterGLTF::import_animation(const String &p_path, uint32_t p_flags) {
+Ref<Animation> EditorSceneImporterGLTF::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
return Ref<Animation>();
}
diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h
index d9479fae6f..0c8000427e 100644
--- a/editor/import/editor_scene_importer_gltf.h
+++ b/editor/import/editor_scene_importer_gltf.h
@@ -296,7 +296,7 @@ public:
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps = NULL, Error *r_err = NULL);
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags);
+ virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags,int p_bake_fps);
EditorSceneImporterGLTF();
};
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index 14bda9bb4e..0297a6c24e 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -426,7 +426,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in
return scene;
}
-Ref<Animation> EditorOBJImporter::import_animation(const String &p_path, uint32_t p_flags) {
+Ref<Animation> EditorOBJImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) {
return Ref<Animation>();
}
diff --git a/editor/import/resource_importer_obj.h b/editor/import/resource_importer_obj.h
index 7eeceeabbe..09dc8ac8a1 100644
--- a/editor/import/resource_importer_obj.h
+++ b/editor/import/resource_importer_obj.h
@@ -40,7 +40,7 @@ public:
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = NULL);
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags);
+ virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags,int p_bake_fps);
EditorOBJImporter();
};
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 6484c37ffe..4ef8ec48a0 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -47,6 +47,94 @@
#include "scene/resources/ray_shape.h"
#include "scene/resources/sphere_shape.h"
+
+
+uint32_t EditorSceneImporter::get_import_flags() const {
+
+ if (get_script_instance()) {
+ return get_script_instance()->call("_get_import_flags");
+ }
+
+ ERR_FAIL_V(0);
+}
+void EditorSceneImporter::get_extensions(List<String> *r_extensions) const {
+
+ if (get_script_instance()) {
+ Array arr= get_script_instance()->call("_get_extensions");
+ for(int i=0;i<arr.size();i++) {
+ r_extensions->push_back(arr[i]);
+ }
+ return;
+ }
+
+ ERR_FAIL();
+
+}
+Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
+
+ if (get_script_instance()) {
+ return get_script_instance()->call("_import_scene",p_path,p_flags,p_bake_fps);
+ }
+
+ ERR_FAIL_V(NULL);
+
+}
+
+Ref<Animation> EditorSceneImporter::import_animation(const String &p_path, uint32_t p_flags,int p_bake_fps) {
+
+ if (get_script_instance()) {
+ return get_script_instance()->call("_import_animation",p_path,p_flags);
+ }
+
+ ERR_FAIL_V(NULL);
+
+}
+
+//for documenters, these functions are useful when an importer calls an external conversion helper (like, fbx2gltf),
+//and you want to load the resulting file
+
+Node* EditorSceneImporter::import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps) {
+
+ return ResourceImporterScene::get_singleton()->import_scene_from_other_importer(this,p_path,p_flags,p_bake_fps);
+
+}
+
+Ref<Animation> EditorSceneImporter::import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps) {
+
+ return ResourceImporterScene::get_singleton()->import_animation_from_other_importer(this,p_path,p_flags,p_bake_fps);
+
+}
+
+void EditorSceneImporter::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("import_scene_from_other_importer","path","flags","bake_fps"),&EditorSceneImporter::import_scene_from_other_importer);
+ ClassDB::bind_method(D_METHOD("import_animation_from_other_importer","path","flags","bake_fps"),&EditorSceneImporter::import_animation_from_other_importer);
+
+ BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_flags"));
+ BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_extensions"));
+
+ MethodInfo mi = MethodInfo(Variant::OBJECT, "_import_scene",PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps"));
+ mi.return_val.class_name="Node";
+ BIND_VMETHOD(mi);
+ mi = MethodInfo(Variant::OBJECT, "_import_animation",PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps"));
+ mi.return_val.class_name="Animation";
+ BIND_VMETHOD(mi);
+
+ BIND_CONSTANT( IMPORT_SCENE );
+ BIND_CONSTANT( IMPORT_ANIMATION );
+ BIND_CONSTANT( IMPORT_ANIMATION_DETECT_LOOP );
+ BIND_CONSTANT( IMPORT_ANIMATION_OPTIMIZE );
+ BIND_CONSTANT( IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS );
+ BIND_CONSTANT( IMPORT_ANIMATION_KEEP_VALUE_TRACKS );
+ BIND_CONSTANT( IMPORT_GENERATE_TANGENT_ARRAYS );
+ BIND_CONSTANT( IMPORT_FAIL_ON_MISSING_DEPENDENCIES );
+ BIND_CONSTANT( IMPORT_MATERIALS_IN_INSTANCES );
+ BIND_CONSTANT( IMPORT_USE_COMPRESSION );
+
+}
+
+
+/////////////////////////////////
void EditorScenePostImport::_bind_methods() {
BIND_VMETHOD(MethodInfo("post_import", PropertyInfo(Variant::OBJECT, "scene")));
@@ -1083,6 +1171,70 @@ void ResourceImporterScene::_replace_owner(Node *p_node, Node *p_scene, Node *p_
Node *n = p_node->get_child(i);
_replace_owner(n, p_scene, p_new_owner);
}
+
+}
+
+Node* ResourceImporterScene::import_scene_from_other_importer(EditorSceneImporter *p_exception,const String &p_path, uint32_t p_flags, int p_bake_fps) {
+
+ Ref<EditorSceneImporter> importer;
+ String ext = p_path.get_extension().to_lower();
+
+ for (Set<Ref<EditorSceneImporter> >::Element *E = importers.front(); E; E = E->next()) {
+
+ if (E->get().ptr()==p_exception)
+ continue;
+ List<String> extensions;
+ E->get()->get_extensions(&extensions);
+
+ for (List<String>::Element *F = extensions.front(); F; F = F->next()) {
+
+ if (F->get().to_lower() == ext) {
+
+ importer = E->get();
+ break;
+ }
+ }
+
+ if (importer.is_valid())
+ break;
+ }
+
+ ERR_FAIL_COND_V(!importer.is_valid(),NULL);
+
+ List<String> missing;
+ Error err;
+ return importer->import_scene(p_path,p_flags,p_bake_fps,&missing,&err);
+}
+
+Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(EditorSceneImporter *p_exception,const String &p_path, uint32_t p_flags, int p_bake_fps) {
+
+
+ Ref<EditorSceneImporter> importer;
+ String ext = p_path.get_extension().to_lower();
+
+ for (Set<Ref<EditorSceneImporter> >::Element *E = importers.front(); E; E = E->next()) {
+
+ if (E->get().ptr()==p_exception)
+ continue;
+ List<String> extensions;
+ E->get()->get_extensions(&extensions);
+
+ for (List<String>::Element *F = extensions.front(); F; F = F->next()) {
+
+ if (F->get().to_lower() == ext) {
+
+ importer = E->get();
+ break;
+ }
+ }
+
+ if (importer.is_valid())
+ break;
+ }
+
+ ERR_FAIL_COND_V(!importer.is_valid(),NULL);
+
+ return importer->import_animation(p_path,p_flags,p_bake_fps);
}
Error ResourceImporterScene::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index cbdafe8e21..fc6ce05fa4 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -40,7 +40,13 @@ class Material;
class EditorSceneImporter : public Reference {
GDCLASS(EditorSceneImporter, Reference);
+protected:
+
+ static void _bind_methods();
+
+ Node* import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
+ Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
public:
enum ImportFlags {
IMPORT_SCENE = 1,
@@ -56,10 +62,11 @@ public:
};
- virtual uint32_t get_import_flags() const = 0;
- virtual void get_extensions(List<String> *r_extensions) const = 0;
- virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = NULL) = 0;
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags) = 0;
+
+ virtual uint32_t get_import_flags() const;
+ virtual void get_extensions(List<String> *r_extensions) const;
+ virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = NULL);
+ virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags,int p_bake_fps);
EditorSceneImporter() {}
};
@@ -114,6 +121,7 @@ public:
const Set<Ref<EditorSceneImporter> > &get_importers() const { return importers; }
void add_importer(Ref<EditorSceneImporter> p_importer) { importers.insert(p_importer); }
+ void remove_importer(Ref<EditorSceneImporter> p_importer) { importers.erase(p_importer); }
virtual String get_importer_name() const;
virtual String get_visible_name() const;
@@ -139,6 +147,9 @@ public:
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL);
+ Node* import_scene_from_other_importer(EditorSceneImporter *p_exception,const String &p_path, uint32_t p_flags, int p_bake_fps);
+ Ref<Animation> import_animation_from_other_importer(EditorSceneImporter *p_exception,const String &p_path, uint32_t p_flags, int p_bake_fps);
+
ResourceImporterScene();
};