javascriptthree.jsthreejs-editor

ThreeJS: Subtract object B from object A


I have an object A. Object A is a 3D object (a scan of a cavity).

I have an object B. Object B is a simple plane. It passes though the centre of Object A.

I would like to split Object A into two separate objects using the plane. Is there a way to subtract objects in threejs? enter image description here


Solution

  • So, three.js does not do constructive geometry by itself. Some packages will help you achieve that, for example, three-csg-ts. their docs explain how to use that package, so you should go through them.

    You should note, though, that deps.dev* rated it at 4.7 on their scorecard**, so if that's a concern for you, you should check their analysis and decide for yourself (though it looks harmless to me)



    Full disclosure, I do work in a supply-chain security team in the industry, but I have no relation to deps.dev nor do I get any benefit from recommending them. this is a free, fantastic and important open-source tool that I believe should be more used