# Cutting / Splitting objects into two

Is there a way to cut an object into two? For example when I press the mouse at an object and move it to the end, the objects should be cut into two objects (two halfs). If so, how?

Hi @issabln, welcome to the Babylon forum!

Mesh slicing sounds like a fun math problem to solve, you can definitely find solutions implemented in other engines floating around the internet, Like this solver implemented in Unity3D.

Iād assume your algorithm would be:

1. Figure out your bisecting plane, and its positional and normal vectors (I suggest starting with either a perfectly horizontal or vertical plane).
2. Find the edges that intersect the plane, and use the intersection point to create your new vertices for the sliced meshes.
3. Recreate your ātopā and ābottomā meshes using the vertices on either side of the slicing plane

2 and 3 are probably a lot easier said than done here, but I hope this gives you a head start.

Or, you can always fake it with pre-sliced geometry that you substitute in, if your usecase allows it

1 Like

Do you need it to be dynamic? If not thereās tons of tools that you can use to swap out the model for any modeling suite, example: YouTube

1 Like

I have been looking into how to slice meshes in Babylon as well. Any pointers would be great ā¦,

Pinging @Deltakosh

you can even split a mesh in as many parts you want : Use the Solid Particle System - Babylon.js Documentation

2 Likes

thats exactly what Iām looking for, but I need it inside babylon.js

@issabln Looks like weāre in luck, Babylon does have constructive solid geometry support, hereās a simple mesh slicer I put together that uses CSG:

https://www.babylonjs-playground.com/#B2DP5I#7

3 Likes

Wow, thanks a lot, thatās great!!! Do You know whatās causing the cut parts to jump so weird sometimes and to fall through the ground?

I could not get work ā¦ when I click on sphere or plane ā¦ I donāt the plane sliced into tiles or prices

It works better with a box

SPS is one of babylonās best features.

1 Like

The jumping is due to me adding physics to the cut pieces, the physics impostor āmeshesā are probably overlapping on creation (and donāt really match up with the mesh), causing them to explosively decompress as they get out from inside each otherš.

@sebavan, @trevordev, either of you have any advice to fix that? The only alternative I could think of is to instead use mesh impostors and have my ground be a giant sphere

https://www.babylonjs-playground.com/#B2DP5I#9

But then, we lose the ability to collide with the other cut meshesā¦

1 Like

Does @issabln need physics?