# Position-Bug(?) after CSG-subtract

**URL:** <https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639>\
**Category:** Questions\
**Created:** [September 13, 2019, 4:54pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639 "2019-09-13T16:54:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![issabln](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@issabln](https://forum.babylonjs.com/u/issabln)\
**Post date:** [September 13, 2019, 4:54pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/1 "2019-09-13T16:54:05Z")

</div>

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](https://www.babylonjs-playground.com/#T6NP3F#12)

Changing the pivot doesn’t affect the gizmo position

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 13, 2019, 4:57pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/2 "2019-09-13T16:57:55Z")

</div>

gizmos feels correct to me:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/b/b5efa862010ba2f6c8168ad7237f590471db5350.jpeg)

---

<div class="post-metadata">

**Author:** ![issabln](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@issabln](https://forum.babylonjs.com/u/issabln)\
**Post date:** [September 13, 2019, 4:59pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/3 "2019-09-13T16:59:55Z")

</div>

Try the other one, it’s more obvious there

![grafik](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/3bfbf8da6f0c1bd3c257f7703132772106af6e1b.png)

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

![grafik](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/6/6aea0c7d3b6f77eefc61d5b4c78998a07ae7963d.png)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 13, 2019, 5:08pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/4 "2019-09-13T17:08:22Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![issabln](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@issabln](https://forum.babylonjs.com/u/issabln)\
**Post date:** [September 13, 2019, 8:07pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/5 "2019-09-13T20:07:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 13, 2019, 9:26pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/6 "2019-09-13T21:26:02Z")

</div>

here we are: [https://www.babylonjs-playground.com/#T6NP3F#13](https://www.babylonjs-playground.com/#T6NP3F#13)

---

<div class="post-metadata">

**Author:** ![issabln](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@issabln](https://forum.babylonjs.com/u/issabln)\
**Post date:** [September 13, 2019, 10:02pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/7 "2019-09-13T22:02:01Z")

</div>

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

 ![grafik](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/2/244f55a38931f5b80c67c0f1a4645211814f39ea.png)

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?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 16, 2019, 3:14pm UTC](https://forum.babylonjs.com/t/position-bug-after-csg-subtract/5639/8 "2019-09-16T15:14:14Z")

</div>

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