godot icon indicating copy to clipboard operation
godot copied to clipboard

Blender asset import creates a new bone for every object parented to same bone

Open smix8 opened this issue 2 years ago • 8 comments

Godot version

c3ed7af

System information

Windows 10

Issue description

When importing a Blender 3D asset the Godot asset importer creates a new bone and a new BoneAttachment3D for each object that was parented to a skeleton bone, e.g. each mesh item. Even if this behavior is wanted there is imo a bug when 100 objects are parented all to the very same bone in Blender the Godot importer adds +100 additional bones instead of just one extra bone.

This can result in a very excessive amount of extra bones on complex skeletons with many attachments for e.g. character customization. As mentioned in related https://github.com/godotengine/godot/issues/75915 having so many extra bones is slow to work with and consumes performance for mostly nothing.

Godot 3 did not add extra bones for each bone attachment but this was apparently changed to solve other bugs with bone index shuffling like https://github.com/godotengine/godot/issues/64512 and https://github.com/godotengine/godot/issues/61641.

Steps to reproduce

  • Open the attached Blender test file (was made with Blender 3.40)
  • See both meshes are parented to the same bone.
  • Copy blend file to Godot and let importer run.
  • See that Godot created two new extra bones that did not exist in the original skeleton.

Minimal reproduction project

BlenderTestFile.zip

smix8 avatar Apr 11 '23 00:04 smix8

Was this behavior added at some point in the 4.0 alpha? This may be tough since it is old, but can you identify the commit or PR that added this in Blame or Bisect?

TokageItLab avatar Apr 25 '24 04:04 TokageItLab

Consider there are duplicated issues for this from 4.0.2 and my issues is even older it was somewhere in Godot 4.0 alpha. Likely from the begin with the GLTF importer rework as Godot 3 does not have the problem.

smix8 avatar Apr 25 '24 06:04 smix8

It would be caused by #72158 - this was where I changed skeletons to recursively contain all gltf nodes (which includes mesh nodes).

This fix was made in response to issues such as #67773 in which meshes were also bones. glTF doesn't distinguish nodes from bones, so it is difficult to adapt data to use an armature/skeleton model.

lyuma avatar Apr 25 '24 06:04 lyuma

In other words, is the problem dependent on Blender's scene tree structure and should be fixed by the glTF exporter? I remember glTF breaking depending on the parent-child relationship between the mesh and armature when I export it from blender.

TokageItLab avatar Apr 25 '24 12:04 TokageItLab

In a strictly technical sense, there is no problem. The glTF spec doesn't specify how to map things to/from nodes to armatures.

Blender does a pretty good job of including various hints in the exported gltf. So there is no way to improve Blender's gltf exporter other then maybe some extension that says like it's ok to listen to the hints precisely

Godot ignores a lot of those hints because they can be unreliable from other DCC. In that PR, I changed Godot to prefer correctness and stability across imports at the expense of a few extra bones. I believe the current approach is more correct.

I respect that some people such as smix want fewer bones as an import option, so this is something I can work on. There were some problems with the code we inherited from Godot 3, especially in the instance of nested armatures. I am worried about reintroducing the Godot 3 code exactly so it would be better to properly design this feature rather than just do what godot 3 did

lyuma avatar Apr 25 '24 15:04 lyuma

In summary, I am proposing two separate things here.

  1. An extension for blender or an import option which is true in godot that says "trust the unreliable gltf hints exactly". This option or extension would disable all of the godot skeleton detection code and assume the gltf skeletons and skins are divided precisely into armatures in the way blender does.
  2. An option for some sort of armature detection that works more similarly to godot 3, but ideally simplify the logic since the code we inherited for this purpose is highly complex, slow and easy to break compatibility.

lyuma avatar Apr 25 '24 15:04 lyuma

  1. An extension for blender or an import option which is true in godot that says "trust the unreliable gltf hints exactly". This option or extension would disable all of the godot skeleton detection code and assume the gltf skeletons and skins are divided precisely into armatures in the way blender does.

Method 1 sounds more like the right way to go than 2.

TokageItLab avatar Apr 25 '24 17:04 TokageItLab

I want to note that the extra "new bones" created for each bone-child mesh contain the offsets of the mesh from the skeleton as the BoneAttachment3D node copies the transforms of the bone it is assigned to.

These if these new bones were to be removed either BoneAttachment3D should have support for "transform offsets" or the offsets should be applied to the mesh itself.

KnightNine avatar May 02 '24 00:05 KnightNine