Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give bone attachments in the GLTF importer stable and proper names, and deduplicate. #47290

Conversation

mortarroad
Copy link
Contributor

Same as #47270, but for master.

@fire
Copy link
Member

fire commented Mar 24, 2021

I put this onto my bucket list. The changes to the import dialogue took my time for today.

@Calinou Calinou added this to the 4.0 milestone Mar 24, 2021
@fire
Copy link
Member

fire commented Mar 26, 2021

@mortarroad Since I'm here, can you give me a visual and an import project of before and after.

I want to approve without compiling the engine and importing.

Edited: I mean a regular test case project without .import / .godot.

@mortarroad
Copy link
Contributor Author

You mean the project with an .import folder?
I've got nothing pretty, just a chain of bones with cubes, if that's enough.
And I'll have to recompile, too.

@mortarroad
Copy link
Contributor Author

@fire If that's okay, I will only provide an example after I've fixed another issue that I found:

Currently, unique names for nodes are enforced globally, even though in Godot unique names are only required within each parent node.
Now, if a bone has the same name as a node (for example a "head" node parented to the "head" bone), one of them will be renamed, even though it is not required.

I think that should be fixed too, before this can be merged.

@mortarroad
Copy link
Contributor Author

On master, the set of all unique names is part of the public interface.
But I'm not really sure that there is a reason to do this at all.
Node::add_child can already generate nice names, so that would even remove complexity.

Is there a reason why the name uniqueness is enforced in the importer?

@fire
Copy link
Member

fire commented Mar 26, 2021

All gltf nodes must have unique names, so the gltf importer enforces it there.

@mortarroad
Copy link
Contributor Author

Ah, so I suppose I can just get rid of it for BoneAttachments, since those aren't GLTF nodes anyway.

@mortarroad mortarroad force-pushed the master-import-gltf-bone-names branch from daa6711 to c5380a8 Compare March 26, 2021 21:53
@mortarroad
Copy link
Contributor Author

I will update the PR against 3.x soon.

Before:
before

After:
after

GLTFBoneNameTest-master.zip

GLTFBoneNameTest-fixed-bone-names.zip

@fire
Copy link
Member

fire commented Mar 29, 2021

My opinion is that if we are auto-generating the names of the bone attachments we can make them unique in the entire scene. Having two nodes with the same name looks ugly :D

Although Godot only enforces uniqueness on sibling nodes, the fact Godot can also export a gltf2 scene means I want both import and export to be symmetrical.

Thoughts?

@mortarroad
Copy link
Contributor Author

I think the name should stay identical to the name in the file, if possible.
For example, having a "head" MeshInstance attached to a BoneAttachment called "head2" doesn't make any sense.

@fire
Copy link
Member

fire commented Mar 29, 2021

When I want to move the head do I animate the "head" or "head"/ "head" node in the animation player?

I also recall that the BoneAttachment3D has a relation to a bone. Maybe we can use that name? Like BoneNameBoneAttachment3D (original.bone_CasingBoneAttachment3D is fine too).

@mortarroad
Copy link
Contributor Author

Hm, I had also thought about adding a prefix / postfix and I think it is acceptable, though I'd prefer a short one if possible.
I'd still prefer to avoid renaming, if it is not necessary.
And in the end, it's the users fault, if their object hierarchy is named in a confusing way :P

@fire
Copy link
Member

fire commented Mar 31, 2021

I agree with Hm, I had also thought about adding a prefix / postfix and I think it is acceptable, though I'd prefer a short one if possible.. Want to modify the pr?

@mortarroad
Copy link
Contributor Author

Hm, I'm not sure what the best prefix would be.
"Bone" would fit in the style, but only if the bone's name is in PascalCase, too, and I don't think we can assume that.
Otherwise something like "bone_" could be good.
Automatically detecting which prefix should be used would be possible, but I think it's not a great idea because it is less predictable.

What's also possible is converting the bone's name into PascalCase, then the "Bone" prefix could be used. (There seems to be a function for that, but it's local to the mono module and would have to be moved.)

@fire
Copy link
Member

fire commented Mar 31, 2021

Is that camelcase_to_underscore()?

@mortarroad
Copy link
Contributor Author

No, I meant the other way around, because nodes are usually in PascalCase.
It looks like this is the only function that does this:

static String snake_to_pascal_case(const String &p_identifier, bool p_input_is_upper = false) {

@mortarroad
Copy link
Contributor Author

I suppose that's overthinking it.
I'd either go with "Bone" or "Bone_" as the prefix.
Which would you prefer? I'll update the PR accordingly.

@mortarroad
Copy link
Contributor Author

I think getting the prefix perfectly right isn't as big of an issue, since a user can always rename these using a post import script (see EditorScenePostImport).

@fire
Copy link
Member

fire commented Jun 8, 2021

Can you help get this reviewed by rebasing? Thanks!

@fire fire self-assigned this Jun 8, 2021
@mortarroad
Copy link
Contributor Author

I'm a bit confused what the new code does; and I have no files to test it with.
I don't understand in what situation it would happen.

@fire
Copy link
Member

fire commented Jun 8, 2021

I thought the design was name the boneattachments after the bone?

@mortarroad
Copy link
Contributor Author

Yes.
I mean for rebasing. I'll have to take a closer look at what changed meanwhile; the changes are non-trivial.

@mortarroad mortarroad force-pushed the master-import-gltf-bone-names branch from c5380a8 to 0719cf1 Compare June 14, 2021 09:25
@mortarroad
Copy link
Contributor Author

PR that caused the conflict #48915
So perhaps @lyuma could review too?

The updated version assumes that _get_or_generate_bone_attachment will always be called with the same scene_parent and scene_root for the same bone_index.
I haven't tested very much. master is just very glitchy all around.

@mortarroad
Copy link
Contributor Author

The iOS build failure looks spurious.

@fire fire requested a review from lyuma September 30, 2021 17:11
@fire
Copy link
Member

fire commented Oct 16, 2021

The code has changed a bit, can you review?

@fire
Copy link
Member

fire commented Dec 20, 2021

The bone attachment code was revised can you update and see if your changes apply? It's holiday season so things will be delayed.

@mortarroad mortarroad force-pushed the master-import-gltf-bone-names branch from 0719cf1 to 6b44674 Compare December 21, 2021 19:29
@mortarroad mortarroad force-pushed the master-import-gltf-bone-names branch from 6b44674 to 2174b02 Compare December 21, 2021 19:36
@mortarroad
Copy link
Contributor Author

I did a rebase, but I don't currently have the time to do testing.

@fire
Copy link
Member

fire commented May 25, 2022

Will need to go through the tests @lyuma made with the odd skeletons.

https://github.com/godotengine/godot-tests/tree/master/tests/gltf_skeleton_tests

@fire fire requested a review from a team August 24, 2022 15:27
@fire
Copy link
Member

fire commented Jan 27, 2023

Fixed by: #72162

@akien-mga
Copy link
Member

Superseded by #72162.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants