Implement naming version system for FBX and Blend importers like glTF

This commit is contained in:
Aaron Franke
2025-06-10 00:41:33 -07:00
parent db57f282fa
commit a56b3a93d3
7 changed files with 55 additions and 2 deletions

View File

@ -98,6 +98,10 @@ Node *EditorSceneFormatImporterFBX2GLTF::import_scene(const String &p_path, uint
gltf.instantiate();
Ref<GLTFState> state;
state.instantiate();
if (p_options.has("fbx/naming_version")) {
int naming_version = p_options["fbx/naming_version"];
gltf->set_naming_version(naming_version);
}
if (p_options.has(SNAME("nodes/import_as_skeleton_bones")) ? (bool)p_options[SNAME("nodes/import_as_skeleton_bones")] : false) {
state->set_import_as_skeleton_bones(true);
}
@ -133,10 +137,17 @@ Variant EditorSceneFormatImporterFBX2GLTF::get_option_visibility(const String &p
void EditorSceneFormatImporterFBX2GLTF::get_import_options(const String &p_path,
List<ResourceImporter::ImportOption> *r_options) {
// This function must be empty to avoid both FBX2glTF and UFBX adding the same options to FBX files.
}
void EditorSceneFormatImporterFBX2GLTF::handle_compatibility_options(HashMap<StringName, Variant> &p_import_params) const {
if (!p_import_params.has("fbx/importer")) {
p_import_params["fbx/importer"] = EditorSceneFormatImporterUFBX::FBX_IMPORTER_UFBX;
}
if (!p_import_params.has("fbx/naming_version")) {
// If a .fbx's existing import file is missing the FBX
// naming compatibility version, we need to use version 1.
// Version 1 is the behavior before this option was added.
p_import_params["fbx/naming_version"] = 1;
}
}

View File

@ -59,6 +59,10 @@ Node *EditorSceneFormatImporterUFBX::import_scene(const String &p_path, uint32_t
state.instantiate();
print_verbose(vformat("FBX path: %s", p_path));
String path = ProjectSettings::get_singleton()->globalize_path(p_path);
if (p_options.has("fbx/naming_version")) {
int naming_version = p_options["fbx/naming_version"];
fbx->set_naming_version(naming_version);
}
bool allow_geometry_helper_nodes = p_options.has("fbx/allow_geometry_helper_nodes") ? (bool)p_options["fbx/allow_geometry_helper_nodes"] : false;
if (allow_geometry_helper_nodes) {
state->set_allow_geometry_helper_nodes(allow_geometry_helper_nodes);
@ -94,6 +98,7 @@ void EditorSceneFormatImporterUFBX::get_import_options(const String &p_path,
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::INT, "fbx/importer", PROPERTY_HINT_ENUM, "ufbx,FBX2glTF"), FBX_IMPORTER_UFBX));
r_options->push_back(ResourceImporterScene::ImportOption(PropertyInfo(Variant::BOOL, "fbx/allow_geometry_helper_nodes"), false));
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));
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));
}
}
@ -101,4 +106,10 @@ void EditorSceneFormatImporterUFBX::handle_compatibility_options(HashMap<StringN
if (!p_import_params.has("fbx/importer")) {
p_import_params["fbx/importer"] = EditorSceneFormatImporterUFBX::FBX_IMPORTER_FBX2GLTF;
}
if (!p_import_params.has("fbx/naming_version")) {
// If a .fbx's existing import file is missing the FBX
// naming compatibility version, we need to use version 1.
// Version 1 is the behavior before this option was added.
p_import_params["fbx/naming_version"] = 1;
}
}

View File

@ -2217,7 +2217,11 @@ Error FBXDocument::_parse_fbx_state(Ref<FBXState> p_state, const String &p_searc
ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR);
/* DETERMINE SKELETONS */
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>());
if (p_state->get_import_as_skeleton_bones()) {
err = SkinTool::_determine_skeletons(p_state->skins, p_state->nodes, p_state->skeletons, p_state->root_nodes, true);
} else {
err = SkinTool::_determine_skeletons(p_state->skins, p_state->nodes, p_state->skeletons, Vector<GLTFNodeIndex>(), _naming_version < 2);
}
ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR);
/* CREATE SKELETONS */
@ -2490,6 +2494,14 @@ Error FBXDocument::append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint3
return ERR_UNAVAILABLE;
}
void FBXDocument::set_naming_version(int p_version) {
_naming_version = p_version;
}
int FBXDocument::get_naming_version() const {
return _naming_version;
}
Vector3 FBXDocument::_as_vec3(const ufbx_vec3 &p_vector) {
return Vector3(real_t(p_vector.x), real_t(p_vector.y), real_t(p_vector.z));
}

View File

@ -62,6 +62,9 @@ public:
PackedByteArray generate_buffer(Ref<GLTFState> p_state) override;
Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) override;
void set_naming_version(int p_version);
int get_naming_version() const;
private:
String _get_texture_path(const String &p_base_directory, const String &p_source_file_path) const;
void _process_uv_set(PackedVector2Array &uv_array);