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?

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.

2 Likes