Skip to content

Commit c455d81

Browse files
committed
Merge pull request #107352 from aaronfranke/blend-fbx-naming-version
Implement naming version system for FBX and Blend importers like glTF
2 parents 875a097 + a56b3a9 commit c455d81

File tree

7 files changed

+55
-2
lines changed

7 files changed

+55
-2
lines changed

modules/fbx/editor/editor_scene_importer_fbx2gltf.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Node *EditorSceneFormatImporterFBX2GLTF::import_scene(const String &p_path, uint
9898
gltf.instantiate();
9999
Ref<GLTFState> state;
100100
state.instantiate();
101+
if (p_options.has("fbx/naming_version")) {
102+
int naming_version = p_options["fbx/naming_version"];
103+
gltf->set_naming_version(naming_version);
104+
}
101105
if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) {
102106
state->set_import_as_skeleton_bones(true);
103107
}
@@ -133,10 +137,17 @@ Variant EditorSceneFormatImporterFBX2GLTF::get_option_visibility(const String &p
133137

134138
void EditorSceneFormatImporterFBX2GLTF::get_import_options(const String &p_path,
135139
List<ResourceImporter::ImportOption> *r_options) {
140+
// This function must be empty to avoid both FBX2glTF and UFBX adding the same options to FBX files.
136141
}
137142

138143
void EditorSceneFormatImporterFBX2GLTF::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {
139144
if (!p_import_params.has("fbx/importer")) {
140145
p_import_params["fbx/importer"] = EditorSceneFormatImporterUFBX::FBX_IMPORTER_UFBX;
141146
}
147+
if (!p_import_params.has("fbx/naming_version")) {
148+
// If a .fbx's existing import file is missing the FBX
149+
// naming compatibility version, we need to use version 1.
150+
// Version 1 is the behavior before this option was added.
151+
p_import_params["fbx/naming_version"] = 1;
152+
}
142153
}

modules/fbx/editor/editor_scene_importer_ufbx.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t
5959
state.instantiate();
6060
print_verbose(vformat("FBX path: %s", p_path));
6161
String path = ProjectSettings::get_singleton()->globalize_path(p_path);
62+
if (p_options.has("fbx/naming_version")) {
63+
int naming_version = p_options["fbx/naming_version"];
64+
fbx->set_naming_version(naming_version);
65+
}
6266
bool allow_geometry_helper_nodes = p_options.has("fbx/allow_geometry_helper_nodes") ? (bool)p_options["fbx/allow_geometry_helper_nodes"] : false;
6367
if (allow_geometry_helper_nodes) {
6468
state->set_allow_geometry_helper_nodes(allow_geometry_helper_nodes);
@@ -94,11 +98,18 @@ void EditorSceneFormatImporterUFBX::get_import_options(const String &p_path,
9498
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/importer", PROPERTY_HINT_ENUM, "ufbx,FBX2glTF"), FBX_IMPORTER_UFBX));
9599
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::BOOL, "fbx/allow_geometry_helper_nodes"), false));
96100
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/embedded_image_handling", PROPERTY_HINT_ENUM, "Discard All Textures,Extract Textures,Embed as Basis Universal,Embed as Uncompressed", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), FBXState::HANDLE_BINARY_EXTRACT_TEXTURES));
101+
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/naming_version", PROPERTY_HINT_ENUM, "Godot 4.0 or 4.1,Godot 4.2 to 4.4,Godot 4.5 or later"), 2));
97102
}
98103
}
99104

100105
void EditorSceneFormatImporterUFBX::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {
101106
if (!p_import_params.has("fbx/importer")) {
102107
p_import_params["fbx/importer"] = EditorSceneFormatImporterUFBX::FBX_IMPORTER_FBX2GLTF;
103108
}
109+
if (!p_import_params.has("fbx/naming_version")) {
110+
// If a .fbx's existing import file is missing the FBX
111+
// naming compatibility version, we need to use version 1.
112+
// Version 1 is the behavior before this option was added.
113+
p_import_params["fbx/naming_version"] = 1;
114+
}
104115
}

modules/fbx/fbx_document.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,11 @@ Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state, const String &p_searc
22172217
ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR);
22182218

22192219
/* DETERMINE SKELETONS */
2220-
err = SkinTool::_determine_skeletons(p_state->skins, p_state->nodes, p_state->skeletons, p_state->get_import_as_skeleton_bones() ? p_state->root_nodes : Vector<GLTFNodeIndex>());
2220+
if (p_state->get_import_as_skeleton_bones()) {
2221+
err = SkinTool::_determine_skeletons(p_state->skins, p_state->nodes, p_state->skeletons, p_state->root_nodes, true);
2222+
} else {
2223+
err = SkinTool::_determine_skeletons(p_state->skins, p_state->nodes, p_state->skeletons, Vector<GLTFNodeIndex>(), _naming_version < 2);
2224+
}
22212225
ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR);
22222226

22232227
/* CREATE SKELETONS */
@@ -2490,6 +2494,14 @@ Error FBXDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint3
24902494
return ERR_UNAVAILABLE;
24912495
}
24922496

2497+
void FBXDocument::set_naming_version(int p_version) {
2498+
_naming_version = p_version;
2499+
}
2500+
2501+
int FBXDocument::get_naming_version() const {
2502+
return _naming_version;
2503+
}
2504+
24932505
Vector3 FBXDocument::_as_vec3(const ufbx_vec3 &p_vector) {
24942506
return Vector3(real_t(p_vector.x), real_t(p_vector.y), real_t(p_vector.z));
24952507
}

modules/fbx/fbx_document.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class FBXDocument : public GLTFDocument {
6262
PackedByteArray generate_buffer(Ref<GLTFState> p_state) override;
6363
Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) override;
6464

65+
void set_naming_version(int p_version);
66+
int get_naming_version() const;
67+
6568
private:
6669
String _get_texture_path(const String &p_base_directory, const String &p_source_file_path) const;
6770
void _process_uv_set(PackedVector2Array &uv_array);

modules/gltf/editor/editor_scene_importer_blend.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_
306306
Ref<GLTFState> state;
307307
state.instantiate();
308308

309+
if (p_options.has("gltf/naming_version")) {
310+
int naming_version = p_options["gltf/naming_version"];
311+
gltf->set_naming_version(naming_version);
312+
}
309313
if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) {
310314
state->set_import_as_skeleton_bones(true);
311315
}
@@ -371,6 +375,17 @@ void EditorSceneFormatImporterBlend::get_import_options(const String &p_path, Li
371375
ADD_OPTION_BOOL("blender/animation/limit_playback", true);
372376
ADD_OPTION_BOOL("blender/animation/always_sample", true);
373377
ADD_OPTION_BOOL("blender/animation/group_tracks", true);
378+
379+
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "gltf/naming_version", PROPERTY_HINT_ENUM, "Godot 4.0 or 4.1,Godot 4.2 to 4.4,Godot 4.5 or later"), 2));
380+
}
381+
382+
void EditorSceneFormatImporterBlend::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {
383+
if (!p_import_params.has("gltf/naming_version")) {
384+
// If a .blend's existing import file is missing the glTF
385+
// naming compatibility version, we need to use version 1.
386+
// Version 1 is the behavior before this option was added.
387+
p_import_params["gltf/naming_version"] = 1;
388+
}
374389
}
375390

376391
///////////////////////////

modules/gltf/editor/editor_scene_importer_blend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class EditorSceneFormatImporterBlend : public EditorSceneFormatImporter {
7373
List<ResourceImporter::ImportOption> *r_options) override;
7474
virtual Variant get_option_visibility(const String &p_path, const String &p_scene_import_type, const String &p_option,
7575
const HashMap<StringName, Variant> &p_options) override;
76+
virtual void handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const override;
7677
};
7778

7879
class LineEdit;

modules/gltf/skin_tool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class SkinTool {
9090
Vector<Ref<GLTFNode>> &r_nodes,
9191
Vector<Ref<GLTFSkeleton>> &r_skeletons,
9292
const Vector<GLTFNodeIndex> &p_single_skeleton_root,
93-
bool p_turn_non_joint_descendants_into_bones = false);
93+
bool p_turn_non_joint_descendants_into_bones);
9494
static Error _create_skeletons(
9595
HashSet<String> &r_unique_names,
9696
Vector<Ref<GLTFSkin>> &r_skins,

0 commit comments

Comments
 (0)