Where does gizmo attached to Mesh?

Hello,

When we add gizmo to a mesh like this:

gizmoManager.attachToMesh(mesh)

Which Vector3 exacty the gizmo positioned?

I am asking this because I merged some meshes and now when I am trying to attach gizmo it attaches far away than mesh and same position for all meshes.

cc @Cedric

Gizmos are attached to local origin.
If the gizmo appears far away from the mesh you attached it to, it means the local (0,0,0) is not ‘inside’ the mesh.

Hello @Cedric,

Thanks for your answer. I checked the boundingbox and it looks right. Are we talking about _localMatrix here? How can I change the local position to boundingbox center do you have idea?

can you provide a playground ?

You can see here:

Solved it!

Thanks to old topic from another forum and Deltakosh’s solution:

So if anyone has the same problem after merging meshes you have to add this:

let boundingInfo = meshMerged.getBoundingInfo().boundingBox;
let middlePivot = new BABYLON.Vector3(boundingInfo.center.x, boundingInfo.center.y, boundingInfo.center.z);                        
meshMerged.setPivotMatrix(BABYLON.Matrix.Translation(-boundingInfo.center.x, -boundingInfo.center.y, -boundingInfo.center.z), false);
meshMerged.bakeCurrentTransformIntoVertices();
meshMerged.setPivotMatrix(BABYLON.Matrix.Identity());                        
meshMerged.position = middlePivot;
meshMerged.refreshBoundingInfo();
4 Likes