Three.js: How to subtract geometry ?

Created on 7 Dec 2011  ·  2Comments  ·  Source: mrdoob/three.js

Is there any way to subtract geometries?

I have an outline of a building and the outline of an inner courtyard. I've extruded the outline of the building by the height to create a solid for the building but I now need to remove he courtyard form the middle.

Thanks

Question

Most helpful comment

All 2 comments

I've worked out the answer - not sure if it's the best way but it works.

I add the outer geometry clockwise and then the bits to remove anti-clockwise to a path before converting to a shape to extrude.

        var path = new THREE.Path();
        // outer clockwise
        path.moveTo(-10, 10);
        path.lineTo(10, 10);
        path.lineTo(10, -10);
        path.lineTo(-10, -10);
        path.lineTo(-10, 10);
        // inner anti-clockwise
        path.moveTo(-5, 5);
        path.lineTo(-5, -5);
        path.lineTo(-2, -5);
        path.lineTo(-2, 5);
        path.lineTo(-5, 5);
        // inner anti-clockwise
        path.moveTo(2, 5);
        path.lineTo(2, -5);
        path.lineTo(5, -5);
        path.lineTo(5, 5);
        path.lineTo(2, 5);

        var height = 20;
        var shapes = path.toShapes();
        var solid = new THREE.ExtrudeGeometry(shapes, { amount: height, bevelEnabled: false });
        var mesh = new THREE.Mesh(solid, materials['building']);
        mesh.position.y = height;
        mesh.rotation.x = 90 * Math.PI * 2 / 360;
        scene.add(mesh);
Was this page helpful?
0 / 5 - 0 ratings