.attachToBone() Orientation Issues

This is my blender setup:

I export the FPS mesh and the center cube as two seperate glb files.

The center cube acts as a gimbal with movement animations (etc start move, stop move, jump), the FPS mesh has action animations (etc reload, shoot, draw). My idea is to parent the FPS mesh to the cube so that I can mix and match animations.

The orientation of each object is correct when I import them into babylon, but why does my FPS mesh end up mirrored when I parent it to the single bone in the cube using .attachToBone()?

1 Like

I wonder if this is related to the post ArcRotateCamera's Radius affects the Rotation/Position of attachToBone Meshes solved by @Evgeni_Popov.

@erey, which version of Babylon.js are you on?

I’m using to latest version, referencing https://cdn.babylonjs.com/babylon.js in my source.

I think this issue has something to do with the orientation of the cube bone. When a mesh is being attached to the bone and the bone is in an orientation different than whatever babylon.js interprets as the default orientation, that transformation difference is then also applied to the mesh object.

For example if I switch the cube bone direction in blender (remapping all constraints and animations to still work the same way with the new bone orientation)

The FPS mesh and cube are imported individually correctly into babylon, but attaching the mesh to the cube results in this:

So I think I have to fix the bone orientation in Blender by mirroring it or if there is some way of “baking” the bone orientation in babylon.

@erey, as a test, could you try to use https://preview.babylonjs.com/babylon.js instead of https://cdn.babylonjs.com/babylon.js?

The issue still exists with that version.

Ok so here is what I’ve explored: The cube bone has local axes xyz, when mesh is attached to the bone, the mesh is orientated such that it’s local axes match with the bone’s axes. Since the bone’s axes are flipped, the mesh also ends up flipped.

This means the issue lies in the original blender model or the glb importer.

I’ve tried correcting the bone’s axes in Blender, and while rotation and location changes in Blender are reflected in babylon, reflections are not. No matter how I reflect the bone in Blender, it still ends up in babylon with the same incorrect xyz axis relationship (But in a different rotation).

@erey, if you share the Blender files, we can help look into this further

Adding @bghgary in case he is aware of export issues on the blender glb front ?

erey.zip (96.7 KB)

Here’s the blender file along with a simple code demonstration of the issue from line 83 to 92.