[Solved] Cut mesh using plane

I was wondering if it is possible to cut a mesh using a plane (I have position and normal). I have tried clipPlane and it works great, except it is for the whole scene.

Also looked into CSG but I need to make some volume for that? Worst come to worst I can create my own cuting function but was hoping for something built in.

Btw, this framework is awesome!

Edit: Embarassing but I found it in the docs.
For anyone else that comes here:
onBeforeRender set to your cutting plane (sphere is the mesh in this case but if you import using SceneLoader.ImportMesh you might need to cast (yourMesh as Mesh).onBeforeRenderObserveable).

Then onAfterRenderObservable you restore the clip plane (in this case null)

sphere.onBeforeRenderObservable.add(function() {
    scene.clipPlane = new BABYLON.Plane(1, 0, 0, 0);
});

sphere.onAfterRenderObservable.add(function() {
    scene.clipPlane = null;
});
4 Likes

Not embarrasing at all :slight_smile: and thanks a lot for sharing your findings!

2 Likes

Can I just say a HUGE thank you!

The fact that you asked a question, then came back and helped teach future people what you’ve learned. That is so epically awesome! Thank you for giving back to this community!

You rock!

1 Like