Attach mesh to bone strange behaviour

When I try to attach mesh to a bone during runtime attached mesh ends up having wrong position and rotation. Everything is fine when mesh is attached at code initialization.


Here you can see hair mesh is attached to head bones of both characters. On the left during code initialization and on the right after delay (using setTimeout)
I dont know if it’s something wrong with hair mesh or skeleton of character.
Here’s playground: Babylon.js Playground
Thank you :slight_smile:

If you look starting at line 1679, you will see the definition of the hair mesh. It has no matrix weights nor matrix indices. Attaching it in runtime will add those. You need to get the armature modifier on the hair mesh in Blender to export already attached.

1 Like

What if I want to attach that mesh to different characters with different armatures? Is it going to work with multiple armature modifiers for same mesh?

If you wish attach to different mesh, why not just always attach at run time?

Ok, I applied armature modifier to hair mesh, but results are the same. https://playground.babylonjs.com/#QLFUZR#1
I guess I’m misunderstanding something?

My goal is to attach at runtime, but as you see hair is transformed not the way I want.

EDIT:
https://playground.babylonjs.com/#QLFUZR#2
Here you can see I attach box, and in both cases box is positioned same way.

MORE EDIT
Okay it looks like I have figured it out. Meshes are attached to the head of the bone and in this case head must be pointing upwards. Bone I was attaching to was another way around: head - down, tail - up. And that resulted in hair mesh being rotated 180 degrees along x axis. I have created another bone dedicated for attaching hair and now it looks good.

Sorry for pointless topic :confused: