From e3767627a5be8e23ef9923018b6aa79c48961319 Mon Sep 17 00:00:00 2001 From: "K. S. Ernest (iFire) Lee" Date: Thu, 22 Feb 2024 11:34:32 -0800 Subject: [PATCH] Remove scene/3d/model_*.h from FBX commit. Update GLTFDocument inheritance, method names, and parameters. Refactor FBXDocument methods for consistency with GLTFDocument. Update FBX and GLTF importers to use boolean flag for helper nodes. --- .../EditorSceneFormatImporterFBX2GLTF.xml | 2 +- modules/fbx/doc_classes/FBXDocument.xml | 2 +- modules/fbx/doc_classes/FBXState.xml | 3 +- .../editor/editor_scene_importer_fbx2gltf.cpp | 4 +- .../fbx/editor/editor_scene_importer_ufbx.cpp | 4 +- modules/fbx/fbx_document.cpp | 13 ++-- modules/fbx/fbx_document.h | 18 ++--- modules/fbx/fbx_state.cpp | 4 +- modules/gltf/config.py | 3 - modules/gltf/doc_classes/GLTFDocument.xml | 2 +- .../doc_classes/GLTFDocumentExtension.xml | 2 +- modules/gltf/doc_classes/GLTFState.xml | 13 +--- modules/gltf/doc_classes/ModelDocument3D.xml | 67 ----------------- modules/gltf/doc_classes/ModelState3D.xml | 9 --- .../editor_scene_exporter_gltf_plugin.cpp | 4 +- .../editor/editor_scene_importer_blend.cpp | 6 +- .../editor/editor_scene_importer_gltf.cpp | 4 +- modules/gltf/extensions/gltf_spec_gloss.h | 1 - modules/gltf/gltf_defines.h | 1 - modules/gltf/gltf_document.compat.inc | 72 ------------------- modules/gltf/gltf_document.cpp | 26 +++++-- modules/gltf/gltf_document.h | 34 +++------ modules/gltf/gltf_state.h | 6 +- modules/gltf/model_state_3d.h | 40 ----------- modules/gltf/register_types.cpp | 4 -- .../{model_document_3d.cpp => skin_tool.cpp} | 28 +------- .../gltf/{model_document_3d.h => skin_tool.h} | 42 +++-------- modules/gltf/structures/gltf_accessor.h | 1 - modules/gltf/structures/gltf_buffer_view.h | 1 - modules/gltf/structures/gltf_node.h | 1 - modules/gltf/structures/gltf_skeleton.h | 1 - modules/gltf/structures/gltf_skin.h | 1 - 32 files changed, 78 insertions(+), 341 deletions(-) delete mode 100644 modules/gltf/doc_classes/ModelDocument3D.xml delete mode 100644 modules/gltf/doc_classes/ModelState3D.xml delete mode 100644 modules/gltf/gltf_document.compat.inc delete mode 100644 modules/gltf/model_state_3d.h rename modules/gltf/{model_document_3d.cpp => skin_tool.cpp} (95%) rename modules/gltf/{model_document_3d.h => skin_tool.h} (76%) diff --git a/modules/fbx/doc_classes/EditorSceneFormatImporterFBX2GLTF.xml b/modules/fbx/doc_classes/EditorSceneFormatImporterFBX2GLTF.xml index 3945304fc6b0..e30782780ffd 100644 --- a/modules/fbx/doc_classes/EditorSceneFormatImporterFBX2GLTF.xml +++ b/modules/fbx/doc_classes/EditorSceneFormatImporterFBX2GLTF.xml @@ -6,7 +6,7 @@ Imports Autodesk FBX 3D scenes by way of converting them to glTF 2.0 using the FBX2glTF command line tool. The location of the FBX2glTF binary is set via the [member EditorSettings.filesystem/import/fbx2gltf/fbx2gltf_path] editor setting. - This importer is only used if [member ProjectSettings.filesystem/import/fbx2gltf/enabled] is enabled, otherwise [code].fbx[/code] files present in the project folder are not imported. + This importer is only used if [member ProjectSettings.filesystem/import/fbx2gltf/enabled] is set to [code]true[/code]. diff --git a/modules/fbx/doc_classes/FBXDocument.xml b/modules/fbx/doc_classes/FBXDocument.xml index c7772f5a21cf..db1d77c0f11f 100644 --- a/modules/fbx/doc_classes/FBXDocument.xml +++ b/modules/fbx/doc_classes/FBXDocument.xml @@ -1,5 +1,5 @@ - + Handles FBX documents. diff --git a/modules/fbx/doc_classes/FBXState.xml b/modules/fbx/doc_classes/FBXState.xml index 5866c455c941..5b39c2414795 100644 --- a/modules/fbx/doc_classes/FBXState.xml +++ b/modules/fbx/doc_classes/FBXState.xml @@ -8,7 +8,8 @@ - + + When true, the boolean flag means the import process used auxiliary nodes, called geometry helper nodes. These nodes help preserve the pivots and transformations of the original 3D model during import. diff --git a/modules/fbx/editor/editor_scene_importer_fbx2gltf.cpp b/modules/fbx/editor/editor_scene_importer_fbx2gltf.cpp index feadcd6f2ab4..8207149d16e5 100644 --- a/modules/fbx/editor/editor_scene_importer_fbx2gltf.cpp +++ b/modules/fbx/editor/editor_scene_importer_fbx2gltf.cpp @@ -105,7 +105,7 @@ Node *EditorSceneFormatImporterFBX2GLTF::import_scene(const String &p_path, uint Ref state; state.instantiate(); print_verbose(vformat("glTF path: %s", sink)); - Error err = gltf->append_data_from_file(sink, state, p_flags, p_path.get_base_dir()); + Error err = gltf->append_from_file(sink, state, p_flags, p_path.get_base_dir()); if (err != OK) { if (r_err) { *r_err = FAILED; @@ -116,7 +116,7 @@ Node *EditorSceneFormatImporterFBX2GLTF::import_scene(const String &p_path, uint #ifndef DISABLE_DEPRECATED bool trimming = p_options.has("animation/trimming") ? (bool)p_options["animation/trimming"] : false; bool remove_immutable = p_options.has("animation/remove_immutable_tracks") ? (bool)p_options["animation/remove_immutable_tracks"] : true; - return gltf->generate_scene_from_data(state, (float)p_options["animation/fps"], trimming, remove_immutable); + return gltf->generate_scene(state, (float)p_options["animation/fps"], trimming, remove_immutable); #else return gltf->create_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"], (bool)p_options["animation/remove_immutable_tracks"]); #endif diff --git a/modules/fbx/editor/editor_scene_importer_ufbx.cpp b/modules/fbx/editor/editor_scene_importer_ufbx.cpp index 0d7cec7ebaaa..721caedc7c96 100644 --- a/modules/fbx/editor/editor_scene_importer_ufbx.cpp +++ b/modules/fbx/editor/editor_scene_importer_ufbx.cpp @@ -74,14 +74,14 @@ Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t state->set_handle_binary_image(enum_option); } p_flags |= EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS; - Error err = fbx->append_data_from_file(path, state, p_flags, p_path.get_base_dir()); + Error err = fbx->append_from_file(path, state, p_flags, p_path.get_base_dir()); if (err != OK) { if (r_err) { *r_err = FAILED; } return nullptr; } - return fbx->generate_scene_from_data(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"], (bool)p_options["animation/remove_immutable_tracks"]); + return fbx->generate_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"], (bool)p_options["animation/remove_immutable_tracks"]); } Variant EditorSceneFormatImporterUFBX::get_option_visibility(const String &p_path, bool p_for_animation, diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp index 9ce818a84c91..2f8fd79be580 100644 --- a/modules/fbx/fbx_document.cpp +++ b/modules/fbx/fbx_document.cpp @@ -48,6 +48,7 @@ #include "modules/gltf/extensions/gltf_light.h" #include "modules/gltf/gltf_defines.h" +#include "modules/gltf/skin_tool.h" #include "modules/gltf/structures/gltf_animation.h" #include "modules/gltf/structures/gltf_camera.h" @@ -2006,7 +2007,7 @@ Error FBXDocument::_parse(Ref p_state, String p_path, Ref void FBXDocument::_bind_methods() { } -Node *FBXDocument::generate_scene_from_data(Ref p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) { +Node *FBXDocument::generate_scene(Ref p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) { Ref state = p_state; ERR_FAIL_COND_V(state.is_null(), nullptr); ERR_FAIL_NULL_V(state, nullptr); @@ -2031,7 +2032,7 @@ Node *FBXDocument::generate_scene_from_data(Ref p_state, float p_b return root; } -Error FBXDocument::append_data_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags) { +Error FBXDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags) { Ref state = p_state; ERR_FAIL_COND_V(state.is_null(), ERR_INVALID_PARAMETER); ERR_FAIL_NULL_V(p_bytes.ptr(), ERR_INVALID_DATA); @@ -2123,7 +2124,7 @@ Error FBXDocument::_parse_fbx_state(Ref p_state, const String &p_searc return OK; } -Error FBXDocument::append_data_from_file(String p_path, Ref p_state, uint32_t p_flags, String p_base_path) { +Error FBXDocument::append_from_file(String p_path, Ref p_state, uint32_t p_flags, String p_base_path) { Ref state = p_state; ERR_FAIL_COND_V(state.is_null(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_path.is_empty(), ERR_FILE_NOT_FOUND); @@ -2342,15 +2343,15 @@ Error FBXDocument::_parse_skins(Ref p_state) { return OK; } -PackedByteArray FBXDocument::generate_buffer_from_data(Ref p_state) { +PackedByteArray FBXDocument::generate_buffer(Ref p_state) { return PackedByteArray(); } -Error FBXDocument::write_to_filesystem_from_data(Ref p_state, const String &p_path) { +Error write_to_filesystem(Ref p_state, const String &p_path) { return ERR_UNAVAILABLE; } -Error FBXDocument::append_data_from_scene(Node *p_node, Ref p_state, uint32_t p_flags) { +Error FBXDocument::append_from_scene(Node *p_node, Ref p_state, uint32_t p_flags) { return ERR_UNAVAILABLE; } diff --git a/modules/fbx/fbx_document.h b/modules/fbx/fbx_document.h index 2db11c4a50a7..ba48eb11aee1 100644 --- a/modules/fbx/fbx_document.h +++ b/modules/fbx/fbx_document.h @@ -34,12 +34,12 @@ #include "fbx_state.h" #include "modules/gltf/gltf_defines.h" -#include "modules/gltf/model_document_3d.h" +#include "modules/gltf/gltf_document.h" #include -class FBXDocument : public ModelDocument3D { - GDCLASS(FBXDocument, ModelDocument3D); +class FBXDocument : public GLTFDocument { + GDCLASS(FBXDocument, GLTFDocument); public: enum { @@ -53,14 +53,14 @@ class FBXDocument : public ModelDocument3D { static String _gen_unique_name(HashSet &unique_names, const String &p_name); public: - virtual Error append_data_from_file(String p_path, Ref p_state, uint32_t p_flags = 0, String p_base_path = String()) override; - virtual Error append_data_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags = 0) override; - virtual Error append_data_from_scene(Node *p_node, Ref p_state, uint32_t p_flags = 0) override; + Error append_from_file(String p_path, Ref p_state, uint32_t p_flags = 0, String p_base_path = String()); + Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags = 0); + Error append_from_scene(Node *p_node, Ref p_state, uint32_t p_flags = 0); public: - virtual Node *generate_scene_from_data(Ref p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true) override; - virtual PackedByteArray generate_buffer_from_data(Ref p_state) override; - virtual Error write_to_filesystem_from_data(Ref p_state, const String &p_path) override; + Node *generate_scene(Ref p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true); + PackedByteArray generate_buffer(Ref p_state); + Error write_to_filesystem(Ref p_state, const String &p_path); protected: static void _bind_methods(); diff --git a/modules/fbx/fbx_state.cpp b/modules/fbx/fbx_state.cpp index 30a3b8141a6a..0b42a86533f9 100644 --- a/modules/fbx/fbx_state.cpp +++ b/modules/fbx/fbx_state.cpp @@ -31,8 +31,8 @@ #include "fbx_state.h" void FBXState::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_allow_geometry_helper_nodes"), &FBXState::get_root_nodes); - ClassDB::bind_method(D_METHOD("set_allow_geometry_helper_nodes", "allow"), &FBXState::set_root_nodes); + ClassDB::bind_method(D_METHOD("get_allow_geometry_helper_nodes"), &FBXState::get_allow_geometry_helper_nodes); + ClassDB::bind_method(D_METHOD("set_allow_geometry_helper_nodes", "allow"), &FBXState::set_allow_geometry_helper_nodes); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_geometry_helper_nodes"), "set_allow_geometry_helper_nodes", "get_allow_geometry_helper_nodes"); } diff --git a/modules/gltf/config.py b/modules/gltf/config.py index 9da246fe1be9..67233db5796f 100644 --- a/modules/gltf/config.py +++ b/modules/gltf/config.py @@ -28,9 +28,6 @@ def get_doc_classes(): "GLTFState", "GLTFTexture", "GLTFTextureSampler", - # FIXME: Remove once those classes are decoupled from the gltf module. - "ModelDocument3D", - "ModelState3D", ] diff --git a/modules/gltf/doc_classes/GLTFDocument.xml b/modules/gltf/doc_classes/GLTFDocument.xml index d8b36c3ebfa6..1f172633da0e 100644 --- a/modules/gltf/doc_classes/GLTFDocument.xml +++ b/modules/gltf/doc_classes/GLTFDocument.xml @@ -1,5 +1,5 @@ - + Class for importing and exporting glTF files in and out of Godot. diff --git a/modules/gltf/doc_classes/GLTFDocumentExtension.xml b/modules/gltf/doc_classes/GLTFDocumentExtension.xml index 9fb5c4f22021..0eabcb5022e8 100644 --- a/modules/gltf/doc_classes/GLTFDocumentExtension.xml +++ b/modules/gltf/doc_classes/GLTFDocumentExtension.xml @@ -55,7 +55,7 @@ Part of the export process. This method is run after [method _convert_scene_node] and before [method _get_saveable_image_formats]. - This method can be used to alter the state before performing serialization. It runs every time when generating a buffer with [method ModelDocument3D.generate_buffer_from_data] or writing to the file system with [method ModelDocument3D.write_to_filesystem_from_data]. + This method can be used to alter the state before performing serialization. It runs every time when generating a buffer with [method GLTFDocument.generate_buffer] or writing to the file system with [method GLTFDocument.write_to_filesystem]. diff --git a/modules/gltf/doc_classes/GLTFState.xml b/modules/gltf/doc_classes/GLTFState.xml index 7672c2ccba7f..100750f40005 100644 --- a/modules/gltf/doc_classes/GLTFState.xml +++ b/modules/gltf/doc_classes/GLTFState.xml @@ -1,5 +1,5 @@ - + Represents all data of a GLTF file. @@ -41,11 +41,6 @@ The argument should be the [GLTFDocumentExtension] name (does not have to match the extension name in the GLTF file), and the return value can be anything you set. If nothing was set, the return value is null. - - - - - @@ -177,12 +172,6 @@ The first argument should be the [GLTFDocumentExtension] name (does not have to match the extension name in the GLTF file), and the second argument can be anything you want. - - - - - - diff --git a/modules/gltf/doc_classes/ModelDocument3D.xml b/modules/gltf/doc_classes/ModelDocument3D.xml deleted file mode 100644 index 1a63df6e888c..000000000000 --- a/modules/gltf/doc_classes/ModelDocument3D.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - Takes a [PackedByteArray] defining a model and imports the data to the given [ModelState3D] object through the [param state] parameter. - [b]Note:[/b] The [param base_path] tells [method append_data_from_buffer] where to find dependencies and can be empty. - - - - - - - - - - Takes a path to a model file and imports the data at that file path to the given [ModelState3D] object through the [param state] parameter. - [b]Note:[/b] The [param base_path] tells [method append_data_from_file] where to find dependencies and can be empty. - - - - - - - - - Takes a Godot Engine scene node and exports it and its descendants to the given [ModelState3D] object through the [param state] parameter. - - - - - - - Takes a [ModelState3D] object through the [param state] parameter and returns a model [PackedByteArray]. - - - - - - - - - - Takes a [ModelState3D] object through the [param state] parameter and returns a Godot Engine scene node. - - - - - - - - Takes a [ModelState3D] object through the [param state] parameter and writes a model file to the filesystem. - - - - diff --git a/modules/gltf/doc_classes/ModelState3D.xml b/modules/gltf/doc_classes/ModelState3D.xml deleted file mode 100644 index fdbeb3b70860..000000000000 --- a/modules/gltf/doc_classes/ModelState3D.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp index 111f1cc6962c..fee81563755e 100644 --- a/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp +++ b/modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp @@ -107,11 +107,11 @@ void SceneExporterGLTFPlugin::_export_scene_as_gltf(const String &p_file_path) { state->set_copyright(_export_settings->get_copyright()); int32_t flags = 0; flags |= EditorSceneFormatImporter::IMPORT_USE_NAMED_SKIN_BINDS; - Error err = _gltf_document->append_data_from_scene(root, state, flags); + Error err = _gltf_document->append_from_scene(root, state, flags); if (err != OK) { ERR_PRINT(vformat("glTF2 save scene error %s.", itos(err))); } - err = _gltf_document->write_to_filesystem_from_data(state, p_file_path); + err = _gltf_document->write_to_filesystem(state, p_file_path); if (err != OK) { ERR_PRINT(vformat("glTF2 save scene error %s.", itos(err))); } diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp index 5387d68af447..a91856c4a147 100644 --- a/modules/gltf/editor/editor_scene_importer_blend.cpp +++ b/modules/gltf/editor/editor_scene_importer_blend.cpp @@ -288,7 +288,7 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_ base_dir = sink.get_base_dir(); } state->set_scene_name(blend_basename); - err = gltf->append_data_from_file(sink.get_basename() + ".gltf", state, p_flags, base_dir); + err = gltf->append_from_file(sink.get_basename() + ".gltf", state, p_flags, base_dir); if (err != OK) { if (r_err) { *r_err = FAILED; @@ -299,9 +299,9 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_ #ifndef DISABLE_DEPRECATED bool trimming = p_options.has("animation/trimming") ? (bool)p_options["animation/trimming"] : false; bool remove_immutable = p_options.has("animation/remove_immutable_tracks") ? (bool)p_options["animation/remove_immutable_tracks"] : true; - return gltf->generate_scene_from_data(state, (float)p_options["animation/fps"], trimming, remove_immutable); + return gltf->generate_scene(state, (float)p_options["animation/fps"], trimming, remove_immutable); #else - return gltf->create_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"], (bool)p_options["animation/remove_immutable_tracks"]); + return gltf->generate_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"], (bool)p_options["animation/remove_immutable_tracks"]); #endif } diff --git a/modules/gltf/editor/editor_scene_importer_gltf.cpp b/modules/gltf/editor/editor_scene_importer_gltf.cpp index 844e657d4b93..38d7f5521b51 100644 --- a/modules/gltf/editor/editor_scene_importer_gltf.cpp +++ b/modules/gltf/editor/editor_scene_importer_gltf.cpp @@ -59,7 +59,7 @@ Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t int32_t enum_option = p_options["gltf/embedded_image_handling"]; state->set_handle_binary_image(enum_option); } - Error err = gltf->append_data_from_file(p_path, state, p_flags); + Error err = gltf->append_from_file(p_path, state, p_flags); if (err != OK) { if (r_err) { *r_err = err; @@ -73,7 +73,7 @@ Node *EditorSceneFormatImporterGLTF::import_scene(const String &p_path, uint32_t #ifndef DISABLE_DEPRECATED bool trimming = p_options.has("animation/trimming") ? (bool)p_options["animation/trimming"] : false; bool remove_immutable = p_options.has("animation/remove_immutable_tracks") ? (bool)p_options["animation/remove_immutable_tracks"] : true; - return gltf->generate_scene_from_data(state, (float)p_options["animation/fps"], trimming, remove_immutable); + return gltf->generate_scene(state, (float)p_options["animation/fps"], trimming, remove_immutable); #else return gltf->create_scene(state, (float)p_options["animation/fps"], (bool)p_options["animation/trimming"], (bool)p_options["animation/remove_immutable_tracks"]); #endif diff --git a/modules/gltf/extensions/gltf_spec_gloss.h b/modules/gltf/extensions/gltf_spec_gloss.h index 4d9e7f231b72..46acd6797938 100644 --- a/modules/gltf/extensions/gltf_spec_gloss.h +++ b/modules/gltf/extensions/gltf_spec_gloss.h @@ -43,7 +43,6 @@ class Image; class GLTFSpecGloss : public Resource { GDCLASS(GLTFSpecGloss, Resource); friend class GLTFDocument; - friend class ModelDocument3D; private: Ref diffuse_img = nullptr; diff --git a/modules/gltf/gltf_defines.h b/modules/gltf/gltf_defines.h index 71e57518e106..d044105b4218 100644 --- a/modules/gltf/gltf_defines.h +++ b/modules/gltf/gltf_defines.h @@ -38,7 +38,6 @@ struct GLTFAccessor; class GLTFAnimation; class GLTFBufferView; class GLTFCamera; -class ModelDocument3D; class GLTFDocument; class GLTFDocumentExtension; class GLTFLight; diff --git a/modules/gltf/gltf_document.compat.inc b/modules/gltf/gltf_document.compat.inc deleted file mode 100644 index d6edfcffa2f2..000000000000 --- a/modules/gltf/gltf_document.compat.inc +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************/ -/* gltf_document.compat.inc */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifndef DISABLE_DEPRECATED - -Error GLTFDocument::append_from_file_81746(String p_path, Ref p_state, uint32_t p_flags, String p_base_path) { - return append_data_from_file(p_path, p_state, p_flags, p_base_path); -} - -Error GLTFDocument::append_from_buffer_81746(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags) { - return append_data_from_buffer(p_bytes, p_base_path, p_state, p_flags); -} - -Error GLTFDocument::append_from_scene_81746(Node *p_node, Ref p_state, uint32_t p_flags) { - return append_data_from_scene(p_node, p_state, p_flags); -} - -Node *GLTFDocument::generate_scene_81746(Ref p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) { - return generate_scene_from_data(p_state, p_bake_fps, p_trimming, p_remove_immutable_tracks); -} - -PackedByteArray GLTFDocument::generate_buffer_81746(Ref p_state) { - return generate_buffer_from_data(p_state); -} - -Error GLTFDocument::write_to_filesystem_81746(Ref p_state, const String &p_path) { - return write_to_filesystem_from_data(p_state, p_path); -} - -void GLTFDocument::_bind_compatibility_methods() { - ClassDB::bind_method(D_METHOD("append_from_file", "path", "state", "flags", "base_path"), - &GLTFDocument::append_from_file_81746, DEFVAL(0), DEFVAL(String())); - ClassDB::bind_method(D_METHOD("append_from_buffer", "bytes", "base_path", "state", "flags"), - &GLTFDocument::append_from_buffer_81746, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("append_from_scene", "node", "state", "flags"), - &GLTFDocument::append_from_scene_81746, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("generate_scene", "state", "bake_fps", "trimming", "remove_immutable_tracks"), - &GLTFDocument::generate_scene_81746, DEFVAL(30), DEFVAL(false), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("generate_buffer", "state"), - &GLTFDocument::generate_buffer_81746); - ClassDB::bind_method(D_METHOD("write_to_filesystem", "state", "path"), - &GLTFDocument::write_to_filesystem_81746); -} - -#endif // DISABLE_DEPRECATED diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 2117e858baff..7949d64920db 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -29,10 +29,10 @@ /**************************************************************************/ #include "gltf_document.h" -#include "gltf_document.compat.inc" #include "extensions/gltf_spec_gloss.h" #include "gltf_state.h" +#include "skin_tool.h" #include "core/config/project_settings.h" #include "core/crypto/crypto_core.h" @@ -6713,6 +6713,18 @@ void GLTFDocument::_bind_methods() { ClassDB::bind_method(D_METHOD("get_lossy_quality"), &GLTFDocument::get_lossy_quality); ClassDB::bind_method(D_METHOD("set_root_node_mode", "root_node_mode"), &GLTFDocument::set_root_node_mode); ClassDB::bind_method(D_METHOD("get_root_node_mode"), &GLTFDocument::get_root_node_mode); + ClassDB::bind_method(D_METHOD("append_from_file", "path", "state", "flags", "base_path"), + &GLTFDocument::append_from_file, DEFVAL(0), DEFVAL(String())); + ClassDB::bind_method(D_METHOD("append_from_buffer", "bytes", "base_path", "state", "flags"), + &GLTFDocument::append_from_buffer, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("append_from_scene", "node", "state", "flags"), + &GLTFDocument::append_from_scene, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("generate_scene", "state", "bake_fps", "trimming", "remove_immutable_tracks"), + &GLTFDocument::generate_scene, DEFVAL(30), DEFVAL(false), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("generate_buffer", "state"), + &GLTFDocument::generate_buffer); + ClassDB::bind_method(D_METHOD("write_to_filesystem", "state", "path"), + &GLTFDocument::write_to_filesystem); ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_format"), "set_image_format", "get_image_format"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lossy_quality"), "set_lossy_quality", "get_lossy_quality"); @@ -6937,7 +6949,7 @@ Error GLTFDocument::_parse_gltf_state(Ref p_state, const String &p_se return OK; } -PackedByteArray GLTFDocument::generate_buffer_from_data(Ref p_state) { +PackedByteArray GLTFDocument::generate_buffer(Ref p_state) { Ref state = p_state; ERR_FAIL_NULL_V(state, PackedByteArray()); // For buffers, set the state filename to an empty string, but @@ -6949,7 +6961,7 @@ PackedByteArray GLTFDocument::generate_buffer_from_data(Ref p_stat return bytes; } -Error GLTFDocument::write_to_filesystem_from_data(Ref p_state, const String &p_path) { +Error GLTFDocument::write_to_filesystem(Ref p_state, const String &p_path) { Ref state = p_state; ERR_FAIL_NULL_V(state, ERR_INVALID_PARAMETER); state->base_path = p_path.get_base_dir(); @@ -6965,7 +6977,7 @@ Error GLTFDocument::write_to_filesystem_from_data(Ref p_state, con return OK; } -Node *GLTFDocument::generate_scene_from_data(Ref p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) { +Node *GLTFDocument::generate_scene(Ref p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) { Ref state = p_state; ERR_FAIL_NULL_V(state, nullptr); ERR_FAIL_INDEX_V(0, state->root_nodes.size(), nullptr); @@ -7006,7 +7018,7 @@ Node *GLTFDocument::generate_scene_from_data(Ref p_state, float p_ return root; } -Error GLTFDocument::append_data_from_scene(Node *p_node, Ref p_state, uint32_t p_flags) { +Error GLTFDocument::append_from_scene(Node *p_node, Ref p_state, uint32_t p_flags) { Ref state = p_state; ERR_FAIL_COND_V(state.is_null(), FAILED); state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; @@ -7044,7 +7056,7 @@ Error GLTFDocument::append_data_from_scene(Node *p_node, Ref p_sta return OK; } -Error GLTFDocument::append_data_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags) { +Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags) { Ref state = p_state; ERR_FAIL_COND_V(state.is_null(), FAILED); // TODO Add missing texture and missing .bin file paths to r_missing_deps 2021-09-10 fire @@ -7068,7 +7080,7 @@ Error GLTFDocument::append_data_from_buffer(PackedByteArray p_bytes, String p_ba return OK; } -Error GLTFDocument::append_data_from_file(String p_path, Ref p_state, uint32_t p_flags, String p_base_path) { +Error GLTFDocument::append_from_file(String p_path, Ref p_state, uint32_t p_flags, String p_base_path) { Ref state = p_state; // TODO Add missing texture and missing .bin file paths to r_missing_deps 2021-09-10 fire if (state == Ref()) { diff --git a/modules/gltf/gltf_document.h b/modules/gltf/gltf_document.h index 75e708ee0a3b..04de2ac5f8ea 100644 --- a/modules/gltf/gltf_document.h +++ b/modules/gltf/gltf_document.h @@ -35,8 +35,6 @@ #include "extensions/gltf_spec_gloss.h" #include "gltf_defines.h" #include "gltf_state.h" -#include "model_document_3d.h" -#include "model_state_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/3d/multimesh_instance_3d.h" @@ -49,8 +47,8 @@ #include "modules/gridmap/grid_map.h" #endif // MODULE_GRIDMAP_ENABLED -class GLTFDocument : public ModelDocument3D { - GDCLASS(GLTFDocument, ModelDocument3D); +class GLTFDocument : public Resource { + GDCLASS(GLTFDocument, Resource); public: const int32_t JOINT_GROUP_SIZE = 4; @@ -83,16 +81,6 @@ class GLTFDocument : public ModelDocument3D { ROOT_NODE_MODE_MULTI_ROOT, }; -public: - virtual Error append_data_from_file(String p_path, Ref p_state, uint32_t p_flags = 0, String p_base_path = String()) override; - virtual Error append_data_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags = 0) override; - virtual Error append_data_from_scene(Node *p_node, Ref p_state, uint32_t p_flags = 0) override; - -public: - virtual Node *generate_scene_from_data(Ref p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true) override; - virtual PackedByteArray generate_buffer_from_data(Ref p_state) override; - virtual Error write_to_filesystem_from_data(Ref p_state, const String &p_path) override; - private: const float BAKE_FPS = 30.0f; int _naming_version = 1; @@ -320,18 +308,14 @@ class GLTFDocument : public ModelDocument3D { static float get_perceived_brightness(const Color p_color); static float get_max_component(const Color &p_color); -#ifndef DISABLE_DEPRECATED -protected: - Error append_from_file_81746(String p_path, Ref p_state, uint32_t p_flags = 0, String p_base_path = String()); - Error append_from_buffer_81746(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags = 0); - Error append_from_scene_81746(Node *p_node, Ref p_state, uint32_t p_flags = 0); - - Node *generate_scene_81746(Ref p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true); - PackedByteArray generate_buffer_81746(Ref p_state); - Error write_to_filesystem_81746(Ref p_state, const String &p_path); +public: + Error append_from_file(String p_path, Ref p_state, uint32_t p_flags = 0, String p_base_path = String()); + Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags = 0); + Error append_from_scene(Node *p_node, Ref p_state, uint32_t p_flags = 0); - static void _bind_compatibility_methods(); -#endif + Node *generate_scene(Ref p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true); + PackedByteArray generate_buffer(Ref p_state); + Error write_to_filesystem(Ref p_state, const String &p_path); public: Error _parse_gltf_state(Ref p_state, const String &p_search_path); diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h index bf3c38f7dc62..c7171e0e68ca 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -32,7 +32,6 @@ #define GLTF_STATE_H #include "extensions/gltf_light.h" -#include "model_state_3d.h" #include "structures/gltf_accessor.h" #include "structures/gltf_animation.h" #include "structures/gltf_buffer_view.h" @@ -46,9 +45,8 @@ #include "scene/3d/importer_mesh_instance_3d.h" -class GLTFState : public ModelState3D { - GDCLASS(GLTFState, ModelState3D); - friend class ModelDocument3D; +class GLTFState : public Resource { + GDCLASS(GLTFState, Resource); friend class GLTFDocument; protected: diff --git a/modules/gltf/model_state_3d.h b/modules/gltf/model_state_3d.h deleted file mode 100644 index 442ce7845ab0..000000000000 --- a/modules/gltf/model_state_3d.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************/ -/* model_state_3d.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifndef MODEL_STATE_3D_H -#define MODEL_STATE_3D_H - -#include "core/io/resource.h" - -class ModelState3D : public Resource { - GDCLASS(ModelState3D, Resource); -}; - -#endif // MODEL_STATE_3D_H diff --git a/modules/gltf/register_types.cpp b/modules/gltf/register_types.cpp index 61aba09a5834..53e9f2b84c95 100644 --- a/modules/gltf/register_types.cpp +++ b/modules/gltf/register_types.cpp @@ -101,10 +101,6 @@ static void _editor_init() { void initialize_gltf_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SCENE) { - // FIXME: Should be decoupled from gltf module. - GDREGISTER_ABSTRACT_CLASS(ModelState3D); - GDREGISTER_ABSTRACT_CLASS(ModelDocument3D); - // glTF API available at runtime. GDREGISTER_CLASS(GLTFAccessor); GDREGISTER_CLASS(GLTFAnimation); diff --git a/modules/gltf/model_document_3d.cpp b/modules/gltf/skin_tool.cpp similarity index 95% rename from modules/gltf/model_document_3d.cpp rename to modules/gltf/skin_tool.cpp index 47efc734d3e6..404549d672a4 100644 --- a/modules/gltf/model_document_3d.cpp +++ b/modules/gltf/skin_tool.cpp @@ -1,5 +1,5 @@ /**************************************************************************/ -/* model_document_3d.cpp */ +/* skin_tool.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ -#include "model_document_3d.h" - -#include "structures/gltf_skeleton.h" -#include "structures/gltf_skin.h" - -#include "core/math/disjoint_set.h" -#include "core/variant/dictionary.h" -#include "scene/3d/skeleton_3d.h" +#include "skin_tool.h" SkinNodeIndex SkinTool::_find_highest_node(Vector> &r_nodes, const Vector &p_subset) { int highest = -1; @@ -804,19 +797,4 @@ String SkinTool::_sanitize_bone_name(const String &p_name) { bone_name = bone_name.replace(":", "_"); bone_name = bone_name.replace("/", "_"); return bone_name; -} - -void ModelDocument3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("append_data_from_file", "path", "state", "flags", "base_path"), - &ModelDocument3D::append_data_from_file, DEFVAL(0), DEFVAL(String())); - ClassDB::bind_method(D_METHOD("append_data_from_buffer", "bytes", "base_path", "state", "flags"), - &ModelDocument3D::append_data_from_buffer, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("append_data_from_scene", "node", "state", "flags"), - &ModelDocument3D::append_data_from_scene, DEFVAL(0)); - ClassDB::bind_method(D_METHOD("generate_scene_from_data", "state", "bake_fps", "trimming", "remove_immutable_tracks"), - &ModelDocument3D::generate_scene_from_data, DEFVAL(30), DEFVAL(false), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("generate_buffer_from_data", "state"), - &ModelDocument3D::generate_buffer_from_data); - ClassDB::bind_method(D_METHOD("write_to_filesystem_from_data", "state", "path"), - &ModelDocument3D::write_to_filesystem_from_data); -} +} \ No newline at end of file diff --git a/modules/gltf/model_document_3d.h b/modules/gltf/skin_tool.h similarity index 76% rename from modules/gltf/model_document_3d.h rename to modules/gltf/skin_tool.h index ff92bb628298..04723f4c18b7 100644 --- a/modules/gltf/model_document_3d.h +++ b/modules/gltf/skin_tool.h @@ -1,5 +1,5 @@ /**************************************************************************/ -/* model_document_3d.h */ +/* skin_tool.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,24 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ -#ifndef MODEL_DOCUMENT_3D_H -#define MODEL_DOCUMENT_3D_H - -// FIXME: This should be in `scene`, but it CANNOT depend on the gltf module, -// as that completely breaks the purpose of modules (encapsulation, opt-out). +#ifndef SKIN_TOOL_H +#define SKIN_TOOL_H #include "gltf_defines.h" -#include "model_state_3d.h" -#include "structures/gltf_node.h" -#include "structures/gltf_skeleton.h" -#include "structures/gltf_skin.h" -#include "core/io/resource.h" -#include "core/templates/hash_map.h" -#include "core/templates/hash_set.h" +#include "modules/gltf/structures/gltf_node.h" +#include "modules/gltf/structures/gltf_skeleton.h" +#include "modules/gltf/structures/gltf_skin.h" + +#include "core/math/disjoint_set.h" #include "core/templates/rb_set.h" -#include "scene/main/node.h" -#include "scene/resources/skin.h" using SkinNodeIndex = int; using SkinSkeletonIndex = int; @@ -102,21 +95,4 @@ class SkinTool { static Error _create_skins(Vector> &skins, Vector> &nodes, bool use_named_skin_binds, HashSet &unique_names); }; -class ModelDocument3D : public Resource { - GDCLASS(ModelDocument3D, Resource); - -protected: - static void _bind_methods(); - -public: - virtual Error append_data_from_file(String p_path, Ref p_state, uint32_t p_flags = 0, String p_base_path = String()) = 0; - virtual Error append_data_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref p_state, uint32_t p_flags = 0) = 0; - virtual Error append_data_from_scene(Node *p_node, Ref p_state, uint32_t p_flags = 0) = 0; - -public: - virtual Node *generate_scene_from_data(Ref p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true) = 0; - virtual PackedByteArray generate_buffer_from_data(Ref p_state) = 0; - virtual Error write_to_filesystem_from_data(Ref p_state, const String &p_path) = 0; -}; - -#endif // MODEL_DOCUMENT_3D_H +#endif // SKIN_TOOL_H \ No newline at end of file diff --git a/modules/gltf/structures/gltf_accessor.h b/modules/gltf/structures/gltf_accessor.h index 66bc608110d9..82759ba9906f 100644 --- a/modules/gltf/structures/gltf_accessor.h +++ b/modules/gltf/structures/gltf_accessor.h @@ -38,7 +38,6 @@ struct GLTFAccessor : public Resource { GDCLASS(GLTFAccessor, Resource); friend class GLTFDocument; - friend class ModelDocument3D; private: GLTFBufferViewIndex buffer_view = -1; diff --git a/modules/gltf/structures/gltf_buffer_view.h b/modules/gltf/structures/gltf_buffer_view.h index b20336c39dd0..1c7bd5c5c73d 100644 --- a/modules/gltf/structures/gltf_buffer_view.h +++ b/modules/gltf/structures/gltf_buffer_view.h @@ -37,7 +37,6 @@ class GLTFBufferView : public Resource { GDCLASS(GLTFBufferView, Resource); - friend class ModelDocument3D; friend class GLTFDocument; private: diff --git a/modules/gltf/structures/gltf_node.h b/modules/gltf/structures/gltf_node.h index 71465c4002c5..63399fb32bc4 100644 --- a/modules/gltf/structures/gltf_node.h +++ b/modules/gltf/structures/gltf_node.h @@ -37,7 +37,6 @@ class GLTFNode : public Resource { GDCLASS(GLTFNode, Resource); - friend class ModelDocument3D; friend class GLTFDocument; friend class SkinTool; friend class FBXDocument; diff --git a/modules/gltf/structures/gltf_skeleton.h b/modules/gltf/structures/gltf_skeleton.h index 8c51972917ce..2ed85b0cae62 100644 --- a/modules/gltf/structures/gltf_skeleton.h +++ b/modules/gltf/structures/gltf_skeleton.h @@ -39,7 +39,6 @@ class GLTFSkeleton : public Resource { GDCLASS(GLTFSkeleton, Resource); - friend class ModelDocument3D; friend class GLTFDocument; friend class SkinTool; friend class FBXDocument; diff --git a/modules/gltf/structures/gltf_skin.h b/modules/gltf/structures/gltf_skin.h index e14d0c5271e8..ce863da45ddc 100644 --- a/modules/gltf/structures/gltf_skin.h +++ b/modules/gltf/structures/gltf_skin.h @@ -41,7 +41,6 @@ class TypedArray; class GLTFSkin : public Resource { GDCLASS(GLTFSkin, Resource); - friend class ModelDocument3D; friend class GLTFDocument; friend class SkinTool; friend class FBXDocument;