Three-csg-ts position of mesh doesn't translate in csg-ts subtraction


I’m using three-csg-ts and I’m creating door cutouts in walls, but setting the position of the door before CSG.subtract() doesn’t seem to do anything.

Here’s the code:
const leftDoor = createDoorGeometry(this.doorDepth, this.doorHeight, this.doorWidth);
leftDoor.position.set( -this.roomWidth / 2, -this.roomHeight/2 + 2, 0)

//to create the wall
const leftWall = createWallGeometry(0.1, this.roomHeight, this.roomDepth)
//wall with door cutout
this.leftWallwithDoor = CSG.subtract(leftWall, leftDoor);

I’ve tried:
leftDoor.geometry.applyMatrix4( new THREE.Matrix4().makeTranslation(-this.roomWidth / 2, -this.roomHeight/2 + 2, 0))

but neither seem to do anything. Any help on translating the geometry before CSG subtraction would be much appreciated!

After you reposition, make sure to call .updateMatrix()
and/or .updateMatrixWorld() on the object.
( and/or .updateMatrixWorld(true) if the other ones don’t work :slight_smile:
Those are normally called indirectly by the renderer.render, but if you modify an object and then immediately operate on it, it’s matrices will be stale.

1 Like

Ahh yes, thank you! I’ve tried those as well, but then the door completely disappears after I call CSG.subtract. I don’t know if I have to use a different library perhaps?

Assuming you tried updating the matrices on both the door and wall object, right after you create them, and that didn’t work…

then perhaps you could:

make a reproduction in something like Glitch, and we can take a look…

Or, there is also the three-meshbvh-csg library… if you want to try an alternative that has some nice properties like being faster for complex meshes:

(full disclosure: I ported/wrote the original library that three-csg-ts was forked from)
GitHub - manthrax/THREE-CSGMesh: Conversion of a CSG library for use with modern THREE.js )

Ahh I guess I wasn’t calling it on both the wall and the door – thank you! It works now :slight_smile:

1 Like