Skip to content

Commit

Permalink
Add legacy flag
Browse files Browse the repository at this point in the history
  • Loading branch information
JonqsGames committed Oct 26, 2024
1 parent d7e5466 commit 05fc82e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions doc/classes/ResourceImporterScene.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<member name="nodes/import_as_skeleton_bones" type="bool" setter="" getter="" default="false">
Treat all nodes in the imported scene as if they are bones within a single [Skeleton3D]. Can be used to guarantee that imported animations target skeleton bones rather than nodes. May also be used to assign the [code]"Root"[/code] bone in a [BoneMap]. See [url=$DOCS_URL/tutorials/assets_pipeline/retargeting_3d_skeletons.html]Retargeting 3D Skeletons[/url] for more information.
</member>
<member name="nodes/legacy_attachements_import" type="bool" setter="" getter="" default="false">
If [code]true[/code], use the legacy import method creating a bone and a [BoneAttachment3D] for each mesh parented to a bone.
</member>
<member name="nodes/root_name" type="String" setter="" getter="" default="&quot;&quot;">
Override for the root node name. If empty, the root node will use what the scene specifies, or the file name if the scene does not specify a root name.
</member>
Expand Down
1 change: 1 addition & 0 deletions editor/import/3d/resource_importer_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,7 @@ void ResourceImporterScene::get_import_options(const String &p_path, List<Import
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/apply_root_scale"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/import_as_skeleton_bones"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/legacy_attachements_import"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/use_node_type_suffixes"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/ensure_tangents"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/generate_lods"), true));
Expand Down
3 changes: 3 additions & 0 deletions modules/gltf/doc_classes/GLTFDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
The user-friendly name of the export image format. This is used when exporting the glTF file, including writing to a file and writing to a byte array.
By default, Godot allows the following options: "None", "PNG", "JPEG", "Lossless WebP", and "Lossy WebP". Support for more image formats can be added in [GLTFDocumentExtension] classes.
</member>
<member name="legacy_attachements_import" type="bool" setter="set_legacy_attachements_import" getter="get_legacy_attachements_import" default="false">
If [code]true[/code], use the legacy import method creating a bone and a [BoneAttachment3D] for each mesh parented to a bone.
</member>
<member name="lossy_quality" type="float" setter="set_lossy_quality" getter="get_lossy_quality" default="0.75">
If [member image_format] is a lossy image format, this determines the lossy quality of the image. On a range of [code]0.0[/code] to [code]1.0[/code], where [code]0.0[/code] is the lowest quality and [code]1.0[/code] is the highest quality. A lossy quality of [code]1.0[/code] is not the same as lossless.
</member>
Expand Down
5 changes: 5 additions & 0 deletions modules/gltf/editor/editor_scene_importer_gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ 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);
}
if (p_options.has("nodes/legacy_attachements_import")) {
gltf->set_legacy_attachements_import((bool)p_options["nodes/legacy_attachements_import"]);
}else {
gltf->set_legacy_attachements_import(true);
}
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);
}
Expand Down
22 changes: 16 additions & 6 deletions modules/gltf/gltf_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,15 @@ int GLTFDocument::get_naming_version() const {
return _naming_version;
}

void GLTFDocument::set_legacy_attachements_import(bool p_legacy_attachements_import) {
_legacy_attachements_import = p_legacy_attachements_import;
}

bool GLTFDocument::get_legacy_attachements_import() const {
return _legacy_attachements_import;
}


void GLTFDocument::set_image_format(const String &p_image_format) {
_image_format = p_image_format;
}
Expand Down Expand Up @@ -5124,7 +5133,7 @@ BoneAttachment3D *GLTFDocument::_generate_bone_attachment(Ref<GLTFState> p_state
Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index];
Ref<GLTFNode> bone_node = p_state->nodes[p_bone_index];
BoneAttachment3D *bone_attachment = memnew(BoneAttachment3D);
print_verbose("glTF: Creating bone attachment for: " + bone_node->get_name());
print_verbose("glTF: Creating bone attachment for: " + _legacy_attachements_import ? gltf_node->get_name() : bone_node->get_name());

Check failure on line 5136 in modules/gltf/gltf_document.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

adding 'bool' to a string does not append to the string [-Werror,-Wstring-plus-int]

Check failure on line 5136 in modules/gltf/gltf_document.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Werror,-Wparentheses]

Check failure on line 5136 in modules/gltf/gltf_document.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

adding 'bool' to a string does not append to the string [-Werror,-Wstring-plus-int]

Check failure on line 5136 in modules/gltf/gltf_document.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

operator '?:' has lower precedence than '+'; '+' will be evaluated first [-Werror,-Wparentheses]

ERR_FAIL_COND_V(!bone_node->joint, nullptr);

Expand Down Expand Up @@ -5606,7 +5615,7 @@ void GLTFDocument::_convert_mesh_instance_to_gltf(MeshInstance3D *p_scene_parent
void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root) {
Ref<GLTFNode> gltf_node = p_state->nodes[p_node_index];

if (gltf_node->skeleton >= 0 && gltf_node->mesh < 0) {
if (gltf_node->skeleton >= 0 && (gltf_node->mesh < 0 || _legacy_attachements_import)) {
_generate_skeleton_bone_node(p_state, p_node_index, p_scene_parent, p_scene_root);
return;
}
Expand All @@ -5622,7 +5631,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIn
if (non_bone_parented_to_skeleton && gltf_node->skin < 0) {
// Bone Attachment - Parent Case
Ref<GLTFNode> bone_node = p_state->nodes[gltf_node->parent];
BoneAttachment3D *bone_attachment = Object::cast_to<BoneAttachment3D>(p_scene_parent->find_child(bone_node->get_name().validate_node_name(), true));
BoneAttachment3D *bone_attachment = (_legacy_attachements_import) ? nullptr : Object::cast_to<BoneAttachment3D>(p_scene_parent->find_child(bone_node->get_name().validate_node_name(), true));
if (bone_attachment == nullptr) {
bone_attachment = _generate_bone_attachment(p_state, active_skeleton, p_node_index, gltf_node->parent);

Expand All @@ -5634,7 +5643,7 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIn
bone_attachment->set_owner(p_scene_root);

// There is no gltf_node that represent this, so just directly create a unique name
bone_attachment->set_name(bone_node->get_name());
bone_attachment->set_name((_legacy_attachements_import) ? gltf_node->get_name() : bone_node->get_name());
}
// We change the scene_parent to our bone attachment now. We do not set current_node because we want to make the node
// and attach it to the bone_attachment
Expand Down Expand Up @@ -5755,7 +5764,8 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> p_state, const GL
p_scene_parent->add_child(bone_attachment, true);

// Find the correct bone_idx so we can properly serialize it.
bone_attachment->set_bone_idx(active_skeleton->find_bone(gltf_node->get_name()));
Ref<GLTFNode> bone_node = p_state->nodes[gltf_node->parent];
bone_attachment->set_bone_idx(active_skeleton->find_bone(bone_node->get_name()));

bone_attachment->set_owner(p_scene_root);

Expand Down Expand Up @@ -5793,7 +5803,7 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> p_state, const GL
args.append(p_scene_root);
current_node->propagate_call(StringName("set_owner"), args);
}
// Do not set transform here. Transform is already applied to our bone.
current_node->set_transform(gltf_node->transform);
current_node->set_name(gltf_node->get_name());
}

Expand Down
3 changes: 3 additions & 0 deletions modules/gltf/gltf_document.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GLTFDocument : public Resource {
int _naming_version = 1;
String _image_format = "PNG";
float _lossy_quality = 0.75f;
bool _legacy_attachements_import = false;
Ref<GLTFDocumentExtension> _image_save_extension;
RootNodeMode _root_node_mode = RootNodeMode::ROOT_NODE_MODE_SINGLE_ROOT;

Expand All @@ -97,6 +98,8 @@ class GLTFDocument : public Resource {

void set_naming_version(int p_version);
int get_naming_version() const;
void set_legacy_attachements_import(bool p_legacy_attachements_import);
bool get_legacy_attachements_import() const;
void set_image_format(const String &p_image_format);
String get_image_format() const;
void set_lossy_quality(float p_lossy_quality);
Expand Down

0 comments on commit 05fc82e

Please sign in to comment.