How can I change the position of my CSG object before subtraction?

I want the CSG-operation to be executed with the new position and rotation of the meshes, but they are ignored. the CSG-result always shows up at zero-point.
I’ve added the two meshes to the scene to make it obvious where I want the CSG-operation to take place.

grafik


        var cubeGeometry2 = new THREE.CubeGeometry( 200, 400, 100, 1, 1, 1 );
        var cubeMesh2 = new THREE.Mesh( cubeGeometry2 );   
        cubeMesh2.position.set( 130, 900, 0);  // the ThreeBSP ignores this
        //cubeMesh2.rotation.set(new THREE.Vector3( 0, 600, 0)); 
        var cubeBSP2 = new ThreeBSP( cubeMesh2 );
     
        //scene.add( cubeMesh2 );

        var cubeGeometry3 = new THREE.CubeGeometry( 100, 300, 100, 1, 1, 1 );
        var cubeMesh3 = new THREE.Mesh( cubeGeometry3 );
        var cubeBSP3 = new ThreeBSP( cubeMesh3 );
        cubeMesh3.position.set( 0, 900, 0);
        scene.add( cubeMesh3 );
        var material = new THREE.MeshBasicMaterial({
            color: 0x1266bb,
            vertexColors: THREE.FaceColors
        });

        var newBSP = cubeBSP2.subtract( cubeBSP3 ); 
        var newMesh = newBSP.toMesh( material );
        newMesh.position.set( 0, 200, 0);
        scene.add( newMesh );


Try to call cubeMesh2.updateMatrixWorld() after this line.

2 Likes

It didn’t work with with the CSG plugin I used for this example

Now I switched to this one

which supports positioning after updateMatrixWorld()

1 Like