Position-Bug(?) after CSG-subtract

After using CSG-subtract the position of the two (or more) subtracted meshes stay the same as the previous one (relative to the new one) before using CSG. thus when attaching these meshes to a gizmo, the gizmo is at a wrong position ( at the previous mesh, which doesn’t existing anymore), instead of being in the center of the mesh. It’s a bit hard to explain, just click at the two hemispheres and you’ll see what I mean:

https://www.babylonjs-playground.com/#T6NP3F#12

Changing the pivot doesn’t affect the gizmo position

gizmos feels correct to me:

Try the other one, it’s more obvious there

grafik

When you drag the fuller one over the other, you’ll see that the gizmos of both are at the same position

grafik

Ok I see, this is expected as the vertices remain unchanged. So the center of mass (barycenter) remain the same.

You can move the pivot point by using mesh.bakeTransformIntoVertices(translationmatrix)

I’m trying it now four hours, could you please show it on one of the hemispheres, so I can understand the principle?

here we are: https://www.babylonjs-playground.com/#T6NP3F#13

thanks, but that works for that case only, I’ve tried figuring out the center of the mesh and translating the pivot towards it, but I can’t figure it out. I tried getting it through the bounding box, but only crap comes out (as the little sphere shows).

var oldPivotTranslation = newMesh.getBoundingInfo().boundingBox.centerWorld.clone();
var sphere = BABYLON.Mesh.CreateSphere(“sphere”, 15, 1, scene);
sphere.position = oldPivotTranslation

Why is that? I mean the bounding box is correctly around the hemisphere (as seen below). Why doesn’t getBoundingInfo().boundingBox.centerWorld give me that position?

Again this is because the vertices are not centered on 0. You need to bake a translation into the mesh to restore the center