The model's location handle is not at the center of the model. Can you set the model center point in code instead of through the model editor?

The model’s location handle is not at the center of the model. Can you set the model center point in code instead of through the model editor?
The following model (475.6 KB)

How do you get an action handle to coincide with the center of the Model???

Yep you can calculate how much the model is offset from the origin and then apply the opposite translation and finally use bakeTransformIntoVertices Mesh | Babylon.js Documentation ( to save that into the model.

1 Like

How to obtain this origin offset and is there a corresponding method

Yes, there is. There always is (well, nearly :grin:)
The solution is around getting the bounding box hierarchy of the model/mesh and submeshes.
This is the link to a similar topic I shared just recently

If you look at how the object’s position has been translated after moving it from ‘getHierarchyBoundingVectors’, you’ll find the values in there (in the root of the model).

Else, the easy way is simply to create a new transformNode and parent the object to the new node after repositioning it from its bounding box hierarchy. Next use the new transformNode as a pivot.
Hope this helps, else let us know…
Meanwhile, have a great day :sunglasses:

positionGizmo How to make the operation handle to move to the center of the model, tried for a long time, can not solve, have a big boss

How does the operation handle and the center point of the model move

I gave you my solution (one of em) and one that does not transform the model.
Don’t know why it wouldn’t match your needs? May be you should try explain a bit more…

1 Like

You don’t. At least not with this method. What it does is that it takes the size of all the hierarchy (mesh and submeshes) bounding boxes. From the total of the bounding boxes sizes, the scripts halfs it.
And from there it offsets the position of the parent to the new center/location. BUT IT DOESN’T CHANGE the original mesh PIVOT/CENTER. Reason why, to have a new center (for placing a gizmo) you should parent it to a new pivot which will become your new center.

Look at this screenshot below. After operation, when you select the root (mesh[0]) of the transformed object, you can see the values resulting from the translation to a new center. The object is now repositioned on the x,y,z axis in the world space to have the center of all bounding boxes at zero origin. But then again, the original pivot of the mesh is unchanged. If you select the parent, renamed as “displaymesh” and rotate it, you will see it rotate around its original pivot.

Edit: And then, to answer your question, what I do is that I take this old parent and I parent it to a new transformNode (here I called it ‘anchor’). Now, you can already see that the gizmo is at the center of the new parent ‘anchor’ and if you select 'anchor and rotate it, it will make all children rotate around its center. Of course, it does also the same for scaling or position. So, in short the answer is, the ‘anchor’ is the new parent you want to interact with.

1 Like

OK, thanks. I’ll try it, too

Obviously, the origin and geometric center of the model are not together

1 Like

Obviously it isn’t :grin: Obviously, this solution relies on making a new parent (herein called ‘anchor’).
The ‘anchor’ (new transform node root for the model) has its handles in the center of the object. The object root hierarchy is displaced towards the new root.

For the convenience of others looking at the same topic, let me link this to your other thread in which people will find a solution to actually move the pivot on the root object itself (without reparenting to new). Eventually also keeping with the original position and scale of the imported object/mesh.

1 Like