Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to subtract geometry ? #866

Closed
ashawthing opened this issue Dec 7, 2011 · 6 comments
Closed

How to subtract geometry ? #866

ashawthing opened this issue Dec 7, 2011 · 6 comments
Labels

Comments

@ashawthing
Copy link

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

@ashawthing
Copy link
Author

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);

@mrdoob
Copy link
Owner

mrdoob commented Dec 31, 2011

You could also use this: link removed

Repository owner deleted a comment from Driver86 Feb 27, 2019
@lewibs-Powern
Copy link

@mrdoob Just a psa that link takes you to some other website now.

@LeviPesin
Copy link
Contributor

I think nowadays you can use https://github.com/gkjohnson/three-bvh-csg.

@Driver86
Copy link

Driver86 commented Jul 14, 2023

Repository owner deleted a comment from Driver86

Why?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 14, 2023

I've deleted the link from @mrdoob comment. Thanks for the heads-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants