Skip to content

Commit

Permalink
Remove scene/3d/model_*.h from FBX commit.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fire committed Feb 23, 2024
1 parent 46044ff commit e376762
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 341 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>
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].
</description>
<tutorials>
</tutorials>
Expand Down
2 changes: 1 addition & 1 deletion modules/fbx/doc_classes/FBXDocument.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="FBXDocument" inherits="ModelDocument3D" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<class name="FBXDocument" inherits="GLTFDocument" experimental="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Handles FBX documents.
</brief_description>
Expand Down
3 changes: 2 additions & 1 deletion modules/fbx/doc_classes/FBXState.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<tutorials>
</tutorials>
<members>
<member name="allow_geometry_helper_nodes" type="PackedInt32Array" setter="set_allow_geometry_helper_nodes" getter="get_allow_geometry_helper_nodes" default="PackedInt32Array()">
<member name="allow_geometry_helper_nodes" type="bool" setter="set_allow_geometry_helper_nodes" getter="get_allow_geometry_helper_nodes" default="false">
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.
</member>
</members>
</class>
4 changes: 2 additions & 2 deletions modules/fbx/editor/editor_scene_importer_fbx2gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Node *EditorSceneFormatImporterFBX2GLTF::import_scene(const String &p_path, uint
Ref<GLTFState> 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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/fbx/editor/editor_scene_importer_ufbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 7 additions & 6 deletions modules/fbx/fbx_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -2006,7 +2007,7 @@ Error FBXDocument::_parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess>
void FBXDocument::_bind_methods() {
}

Node *FBXDocument::generate_scene_from_data(Ref<ModelState3D> p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) {
Node *FBXDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) {
Ref<FBXState> state = p_state;
ERR_FAIL_COND_V(state.is_null(), nullptr);
ERR_FAIL_NULL_V(state, nullptr);
Expand All @@ -2031,7 +2032,7 @@ Node *FBXDocument::generate_scene_from_data(Ref<ModelState3D> p_state, float p_b
return root;
}

Error FBXDocument::append_data_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<ModelState3D> p_state, uint32_t p_flags) {
Error FBXDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags) {
Ref<FBXState> state = p_state;
ERR_FAIL_COND_V(state.is_null(), ERR_INVALID_PARAMETER);
ERR_FAIL_NULL_V(p_bytes.ptr(), ERR_INVALID_DATA);
Expand Down Expand Up @@ -2123,7 +2124,7 @@ Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state, const String &p_searc
return OK;
}

Error FBXDocument::append_data_from_file(String p_path, Ref<ModelState3D> p_state, uint32_t p_flags, String p_base_path) {
Error FBXDocument::append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags, String p_base_path) {
Ref<FBXState> 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);
Expand Down Expand Up @@ -2342,15 +2343,15 @@ Error FBXDocument::_parse_skins(Ref<FBXState> p_state) {
return OK;
}

PackedByteArray FBXDocument::generate_buffer_from_data(Ref<ModelState3D> p_state) {
PackedByteArray FBXDocument::generate_buffer(Ref<GLTFState> p_state) {
return PackedByteArray();
}

Error FBXDocument::write_to_filesystem_from_data(Ref<ModelState3D> p_state, const String &p_path) {
Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) {
return ERR_UNAVAILABLE;
}

Error FBXDocument::append_data_from_scene(Node *p_node, Ref<ModelState3D> p_state, uint32_t p_flags) {
Error FBXDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags) {
return ERR_UNAVAILABLE;
}

Expand Down
18 changes: 9 additions & 9 deletions modules/fbx/fbx_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ufbx.h>

class FBXDocument : public ModelDocument3D {
GDCLASS(FBXDocument, ModelDocument3D);
class FBXDocument : public GLTFDocument {
GDCLASS(FBXDocument, GLTFDocument);

public:
enum {
Expand All @@ -53,14 +53,14 @@ class FBXDocument : public ModelDocument3D {
static String _gen_unique_name(HashSet<String> &unique_names, const String &p_name);

public:
virtual Error append_data_from_file(String p_path, Ref<ModelState3D> 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<ModelState3D> p_state, uint32_t p_flags = 0) override;
virtual Error append_data_from_scene(Node *p_node, Ref<ModelState3D> p_state, uint32_t p_flags = 0) override;
Error append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, String p_base_path = String());
Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags = 0);
Error append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags = 0);

public:
virtual Node *generate_scene_from_data(Ref<ModelState3D> 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<ModelState3D> p_state) override;
virtual Error write_to_filesystem_from_data(Ref<ModelState3D> p_state, const String &p_path) override;
Node *generate_scene(Ref<GLTFState> p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true);
PackedByteArray generate_buffer(Ref<GLTFState> p_state);
Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path);

protected:
static void _bind_methods();
Expand Down
4 changes: 2 additions & 2 deletions modules/fbx/fbx_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
3 changes: 0 additions & 3 deletions modules/gltf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ def get_doc_classes():
"GLTFState",
"GLTFTexture",
"GLTFTextureSampler",
# FIXME: Remove once those classes are decoupled from the gltf module.
"ModelDocument3D",
"ModelState3D",
]


Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/doc_classes/GLTFDocument.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GLTFDocument" inherits="ModelDocument3D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<class name="GLTFDocument" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Class for importing and exporting glTF files in and out of Godot.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion modules/gltf/doc_classes/GLTFDocumentExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<param index="0" name="state" type="GLTFState" />
<description>
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].
</description>
</method>
<method name="_generate_scene_node" qualifiers="virtual">
Expand Down
13 changes: 1 addition & 12 deletions modules/gltf/doc_classes/GLTFState.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GLTFState" inherits="ModelState3D" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<class name="GLTFState" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Represents all data of a GLTF file.
</brief_description>
Expand Down Expand Up @@ -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.
</description>
</method>
<method name="get_allow_geometry_helper_nodes">
<return type="PackedInt32Array" />
<description>
</description>
</method>
<method name="get_animation_player">
<return type="AnimationPlayer" />
<param index="0" name="idx" type="int" />
Expand Down Expand Up @@ -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.
</description>
</method>
<method name="set_allow_geometry_helper_nodes">
<return type="void" />
<param index="0" name="allow" type="PackedInt32Array" />
<description>
</description>
</method>
<method name="set_animations">
<return type="void" />
<param index="0" name="animations" type="GLTFAnimation[]" />
Expand Down
67 changes: 0 additions & 67 deletions modules/gltf/doc_classes/ModelDocument3D.xml

This file was deleted.

9 changes: 0 additions & 9 deletions modules/gltf/doc_classes/ModelState3D.xml

This file was deleted.

4 changes: 2 additions & 2 deletions modules/gltf/editor/editor_scene_exporter_gltf_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
6 changes: 3 additions & 3 deletions modules/gltf/editor/editor_scene_importer_blend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions modules/gltf/editor/editor_scene_importer_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion modules/gltf/extensions/gltf_spec_gloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Image;
class GLTFSpecGloss : public Resource {
GDCLASS(GLTFSpecGloss, Resource);
friend class GLTFDocument;
friend class ModelDocument3D;

private:
Ref<Image> diffuse_img = nullptr;
Expand Down
1 change: 0 additions & 1 deletion modules/gltf/gltf_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct GLTFAccessor;
class GLTFAnimation;
class GLTFBufferView;
class GLTFCamera;
class ModelDocument3D;
class GLTFDocument;
class GLTFDocumentExtension;
class GLTFLight;
Expand Down
Loading

0 comments on commit e376762

Please sign in to comment.