diff --git a/modules/gltf/SCsub b/modules/gltf/SCsub index b4b3897e7..f3dbc55c4 100644 --- a/modules/gltf/SCsub +++ b/modules/gltf/SCsub @@ -18,5 +18,7 @@ env_gltf.add_source_files(env.modules_sources, "gltf_document.cpp") env_gltf.add_source_files(env.modules_sources, "extensions/*.cpp") env_gltf.add_source_files(env.modules_sources, "structures/*.cpp") -#if env["tools"]: -# env_gltf.add_source_files(env.modules_sources, "editor/*.cpp") +if env["tools"]: + env_gltf.add_source_files(env.modules_sources, "editor/editor_scene_importer_gltf.cpp") + env_gltf.add_source_files(env.modules_sources, "editor/editor_scene_importer_fbx.cpp") + #env_gltf.add_source_files(env.modules_sources, "editor/*.cpp") diff --git a/modules/gltf/editor/editor_scene_importer_fbx.cpp b/modules/gltf/editor/editor_scene_importer_fbx.cpp index faad2d315..0b54a3c25 100644 --- a/modules/gltf/editor/editor_scene_importer_fbx.cpp +++ b/modules/gltf/editor/editor_scene_importer_fbx.cpp @@ -35,7 +35,8 @@ #include "../gltf_document.h" #include "../gltf_state.h" -#include "core/config/project_settings.h" +#include "core/os/os.h" +#include "core/project_settings.h" #include "editor/editor_settings.h" #include "scene/main/node.h" #include "scene/resources/animation.h" @@ -48,16 +49,14 @@ void EditorSceneFormatImporterFBX::get_extensions(List *r_extensions) co r_extensions->push_back("fbx"); } -Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags, - const HashMap &p_options, int p_bake_fps, - List *r_missing_deps, Error *r_err) { +Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List *r_missing_deps, Error *r_err) { // Get global paths for source and sink. // Don't use `c_escape()` as it can generate broken paths. These paths will be // enclosed in double quotes by OS::execute(), so we only need to escape those. // `c_escape_multiline()` seems to do this (escapes `\` and `"` only). const String source_global = ProjectSettings::get_singleton()->globalize_path(p_path).c_escape_multiline(); - const String sink = ProjectSettings::get_singleton()->get_imported_files_path().plus_file( + const String sink = ProjectSettings::get_singleton()->get_project_data_path().plus_file( vformat("%s-%s.glb", p_path.get_file().get_basename(), p_path.md5_text())); const String sink_global = ProjectSettings::get_singleton()->globalize_path(sink).c_escape_multiline(); @@ -75,7 +74,8 @@ Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t String standard_out; int ret; - OS::get_singleton()->execute(fbx2gltf_path, args, &standard_out, &ret, true); + OS::get_singleton()->execute(fbx2gltf_path, args, true, nullptr, &standard_out, &ret, true); + print_verbose(fbx2gltf_path); print_verbose(standard_out); @@ -91,27 +91,33 @@ Node *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t // Use GLTFDocument instead of glTF importer to keep image references. Ref gltf; - gltf.instantiate(); + gltf.instance(); Ref state; - state.instantiate(); + state.instance(); + print_verbose(vformat("glTF path: %s", sink)); Error err = gltf->append_from_file(sink, state, p_flags, p_bake_fps); + if (err != OK) { if (r_err) { *r_err = FAILED; } return nullptr; } + return gltf->generate_scene(state, p_bake_fps); } -Variant EditorSceneFormatImporterFBX::get_option_visibility(const String &p_path, bool p_for_animation, - const String &p_option, const HashMap &p_options) { +bool EditorSceneFormatImporterFBX::get_option_visibility(const String &p_option, const Map &p_options) const { return true; } -void EditorSceneFormatImporterFBX::get_import_options(const String &p_path, - List *r_options) { +void EditorSceneFormatImporterFBX::get_import_options(List *r_options, int p_preset) const { +} + +EditorSceneFormatImporterFBX::EditorSceneFormatImporterFBX() { +} +EditorSceneFormatImporterFBX::~EditorSceneFormatImporterFBX() { } #endif // TOOLS_ENABLED diff --git a/modules/gltf/editor/editor_scene_importer_fbx.h b/modules/gltf/editor/editor_scene_importer_fbx.h index d76455641..8c32a33f3 100644 --- a/modules/gltf/editor/editor_scene_importer_fbx.h +++ b/modules/gltf/editor/editor_scene_importer_fbx.h @@ -38,19 +38,19 @@ class Animation; class Node; -class EditorSceneFormatImporterFBX : public EditorSceneFormatImporter { - GDCLASS(EditorSceneFormatImporterFBX, EditorSceneFormatImporter); +class EditorSceneFormatImporterFBX : public EditorSceneImporter { + GDCLASS(EditorSceneFormatImporterFBX, EditorSceneImporter); public: - virtual uint32_t get_import_flags() const override; - virtual void get_extensions(List *r_extensions) const override; - virtual Node *import_scene(const String &p_path, uint32_t p_flags, - const HashMap &p_options, int p_bake_fps, - List *r_missing_deps, Error *r_err = nullptr) override; - virtual void get_import_options(const String &p_path, - List *r_options) override; - virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option, - const HashMap &p_options) override; + virtual uint32_t get_import_flags() const; + virtual void get_extensions(List *r_extensions) const; + virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List *r_missing_deps = nullptr, Error *r_err = nullptr); + + virtual bool get_option_visibility(const String &p_option, const Map &p_options) const; + virtual void get_import_options(List *r_options, int p_preset = 0) const; + + EditorSceneFormatImporterFBX(); + ~EditorSceneFormatImporterFBX(); }; #endif // TOOLS_ENABLED diff --git a/modules/gltf/editor/editor_scene_importer_gltf.cpp b/modules/gltf/editor/editor_scene_importer_gltf.cpp index 3fadec516..9277f17a7 100644 --- a/modules/gltf/editor/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor/editor_scene_importer_gltf.cpp @@ -47,20 +47,27 @@ void EditorSceneFormatImporterGLTF::get_extensions(List *r_extensions) c } Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t p_flags, - const HashMap &p_options, int p_bake_fps, - List *r_missing_deps, Error *r_err) { + int p_bake_fps, uint32_t p_compress_flags, List *r_missing_deps, Error *r_err) { + Ref doc; - doc.instantiate(); + doc.instance(); Ref state; - state.instantiate(); + state.instance(); + Error err = doc->append_from_file(p_path, state, p_flags, p_bake_fps); + if (err != OK) { if (r_err) { *r_err = err; } return nullptr; } + return doc->generate_scene(state, p_bake_fps); } +Ref EditorSceneFormatImporterGLTF::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { + return Ref(); +} + #endif // TOOLS_ENABLED diff --git a/modules/gltf/editor/editor_scene_importer_gltf.h b/modules/gltf/editor/editor_scene_importer_gltf.h index 909683749..b0cf10d12 100644 --- a/modules/gltf/editor/editor_scene_importer_gltf.h +++ b/modules/gltf/editor/editor_scene_importer_gltf.h @@ -41,15 +41,15 @@ class Animation; class Node; -class EditorSceneFormatImporterGLTF : public EditorSceneFormatImporter { - GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneFormatImporter); +class EditorSceneFormatImporterGLTF : public EditorSceneImporter { + GDCLASS(EditorSceneFormatImporterGLTF, EditorSceneImporter); public: - virtual uint32_t get_import_flags() const override; - virtual void get_extensions(List *r_extensions) const override; - virtual Node *import_scene(const String &p_path, uint32_t p_flags, - const HashMap &p_options, int p_bake_fps, - List *r_missing_deps, Error *r_err = nullptr) override; + virtual uint32_t get_import_flags() const; + virtual void get_extensions(List *r_extensions) const; + + virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, uint32_t p_compress_flags, List *r_missing_deps = nullptr, Error *r_err = nullptr); + virtual Ref import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps); }; #endif // TOOLS_ENABLED diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 25301ebd0..8318f0d7f 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -7201,6 +7201,9 @@ GLTFDocument::GLTFDocument() { document_extensions.push_back(extension_editor); } +GLTFDocument::~GLTFDocument() { +} + PoolByteArray GLTFDocument::_serialize_glb_buffer(Ref state, Error *r_err) { Error err = _encode_buffer_glb(state, ""); if (r_err) { @@ -7290,11 +7293,11 @@ Node *GLTFDocument::generate_scene(Ref state, int32_t p_bake_fps) { } } - const GLTFNodeIndex* scene_nodes_ptr = NULL; + const GLTFNodeIndex *scene_nodes_ptr = NULL; while ((scene_nodes_ptr = state->scene_nodes.next(scene_nodes_ptr))) { - //for (KeyValue E : state->scene_nodes) { - GLTFNodeIndex E_key = *scene_nodes_ptr; - Node ** E_value = state->scene_nodes.getptr(E_key); + //for (KeyValue E : state->scene_nodes) { + GLTFNodeIndex E_key = *scene_nodes_ptr; + Node **E_value = state->scene_nodes.getptr(E_key); ERR_CONTINUE(!E_value); diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 9d41dfb3b..2d1417dbb 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -42,6 +42,7 @@ #include "scene/resources/material.h" class Camera; +class GLTFDocumentExtension; class GLTFDocument : public Resource { GDCLASS(GLTFDocument, Resource); @@ -356,6 +357,7 @@ public: Error _parse(Ref state, String p_path, FileAccess *f, int p_bake_fps); GLTFDocument(); + ~GLTFDocument(); protected: static void _bind_methods(); diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp index 50e9718f4..59b9e26d0 100644 --- a/modules/gltf/register_types.cpp +++ b/modules/gltf/register_types.cpp @@ -75,11 +75,6 @@ void unregister_gltf_types() { /* - - - - - #ifdef TOOLS_ENABLED #include "core/project_settings.h" #include "editor/editor_node.h"