KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.48k stars 316 forks source link

Request for bone length to be exported #181

Closed mjdave closed 5 years ago

mjdave commented 6 years ago

Bones have a concept of length in Blender, which currently is not exported. This is useful, particularly when trying to load another object in-game at a location relative to the end of a bone. You can parent an object to a bone in Blender, and it is rendered in Blender relative to the end of the bone. But there is no way to get it in the correct place after it has been exported without the offset along the length of the bone.

To get the data I needed in-engine I simply added the following to gltf2_generate.py at line 1913 in generate_nodes()

node['length'] = blender_bone.length

donmccurdy commented 6 years ago

Hi @mjdave — glTF does not have a concept of bone length, so the information would need to be placed somewhere like...

node['extras']['length'] = blender_bone.length

... in order to have a valid file. But I'm not sure whether this should be added to the exporter, or include position of the end of the bone, or recommend attaching an (empty) node to use for the attachment point.

donmccurdy commented 5 years ago

One thing we could do, though, would be to add "leaf" bones — just another node at the end of the last bone in the chain. The FBX exporter has an option for this, and it allows you to attach things there for instance. Marking as an enhancement, would be good to hear if there are other use cases...

donmccurdy commented 5 years ago

I've moved this issue to the new repository as a possible future enhancement.

setpixel commented 5 years ago

Yes - this is a pretty important thing to visualize the bones. For now I'm just adding a bone to the end of every dangling bone. +1 for leaf bones

jjcasmar commented 5 years ago

I have a fix for this issue. Im adding a new node to the nodes hierarchy for the bone tail. When an object is parented to a bone diretly, its parented to the tail node in gltf. The fix is for the old exporter (glTF-Blender-Exporter), but probably is easy to adapt.

setpixel commented 5 years ago

@jjcasmar could you send me a copy of your fixed exporter? I could really use leaf bone exports. Also, I will be your best friend!

jjcasmar commented 5 years ago

Its based on the previous version of the exporter, so the patch is (probably) not valid for this code.

You can find a version of it in the Kuesa repo. https://github.com/KDAB/kuesa-blender

mjdave commented 5 years ago

In the latest exporter shipping with 2.8, nodes which are parented to bones are exported with the translation relative to the tail, and not the head of the bone. This is a nice solution for my use case here, so I think this bug could now be closed.