Relative position of CSG2 mesh and meshes it was derived from

Hi Everyone-

I know how to do this using the old CSG classes but can’t figure out how to do it with CSG2.

This playground shows a simple method for creating 4 walls (example just shows 1) on the 4 faces of a box by subtracting an offset box from the original box. The box that is subtracted also has the y scale increased.

The resulting shape is correct but I can’t figure out a way to set the position. In this case the y is incorrect because both shapes are body centered and the “wall” is a little shorter. Any ideas?

Thanks in advance.

Flex

cc @Deltakosh

Hi!

CSG2.toMesh() defaults to centerMesh: true, which recenters the geometry around the origin. To preserve the alignment, disable it on both conversions:

const clone = BABYLON.CSG2.FromMesh(shadow)
    .toMesh("clone", scene, { centerMesh: false });
// Keep your scaling and subtraction code.
const wall1 = csg.subtract(BABYLON.CSG2.FromMesh(clone))
    .toMesh("wall1", scene, { centerMesh: false });

Remove both wall1.position assignments: FromMesh() already applies the input world transform.