An Introductory Guide to Splitting Meshes

If you haven’t heard of DynamicMesh yet, check out this tweet!

Introduction

With DynamicMesh coming to Roblox, we will soon be able to read and modify the vertex data of mesh objects! So I figured now would be a great time to talk about something I remade recently. Introducing mesh splitting:

Splitting a Triangle

Lets get right into it! Triangles are usually the building blocks of meshes. So to begin, I needed to figure out how to split a single triangle. Here was a simple procedure I quickly drew out, the red line indicates a cut.

A triangle is made of three line segments. Iterating through the edges and using some algebra, we can calculate the two points that intersect a plane cut!

With the two intersections, the triangle can be split into three smaller triangles as shown in the above diagram.

Separating the two polygons will give us what we needed, a split triangle!

Splitting a Box

Moving on to the third dimension, here you can see I constructed a cube made of triangles. Using the same math as before, we can figure out which triangle to split, colored in blue. Yellow and red indicate non-intersecting triangles on the two sides of the plane, which will be grouped into separate models later.

Calculating the intersections of the triangles like before we can separate the mesh into two groups. Looks like its all coming together!

Here is how the box looks like when its filled. I render the mesh using Wedges since DynamicMesh hasn’t been released yet. But we have a problem, the interior of the cut is hollow. We can’t be having that!

Filling in the Cut

To cover it up, we can use the points we calculated to find the intersection of the mesh on the plane cut.

With this collection of edges, you will need to apply some CS to merge them. I recommend constructing a vertex graph and traversing a single cycle to calculate this polygon. Then we can fill in the polygon intersection using triangulation. Now we got something to perfectly cover up the hole!

Final Results

Wrapping it all together with a touch of welding and physics… tada! Mesh splitting!

Cutting an eggdog?

How about cutting a sphere brick, slowed down?

FAQ

Q: How are you reading the mesh data?
A: Since DynamicMesh are not out yet, there is no native way to grab a mesh’s vertex information. Alternatively, you can use CloneTrooper’s Mesh Parser.

Q: How are you rendering the mesh?
A: This is not performant compared to modifying meshes, but I have been using Wedge instances to replicate triangles in the mean time. Here is how they look like in a different color.

40 Likes

Awesome tutorial, I can’t imagine how realistic bullet hole effects people will be able to create with real time mesh creation.

5 Likes

:sob:

8 Likes

Could you open source the code into a repo? I would love to learn about how this was created.

2 Likes

Awesome stuff. I’ve seen a lot of your youtube videos but I think this is the first time I’ve seen you on the dev forum. Would love to see further explanations into how you make such incredible effects.

1 Like

Thanks for the introduction! At first I was not sure how to start with this but now I know the general idea. :sushi:

Good job on tutorial dinosaur

1 Like

No idea where I would implement it, but this is a very cool concept that I really want to recreate. It’s satisfying and looks way faster than CSG

Very good introduction, but I have no idea about how you fill cut. Can you tell me please, what method of triangulation you used?

He used wedges. Let’s say a triangle had vertices at (0,0,0), (0, 5, 0), and (0, 0, 5)

He would make a wedge at (0, 2.5, 2.5) and the size would be (0, 5, 5)

I know that he use wedges. I’m talking about converting cut with triangulation, because there’s a lot of methods and they are differ. When I tried to make filling cut, I got some problems with cuts like this ones:



While second one I resolved with separating that edges on 2+ polygons, I can’t resolve first issue, when there’s hole in polygon, because my method of separating checks polygons by their connections. So first case will be split into:

To fill advance shapes like concave polygons, I recommend implementing Ear Clipping triangulation. As for generating polygons with holes, you can use the boolean operator library that Egomoose ported over, PolyBool.

2 Likes

Any idea when said Roblox company may release said feature? :3

why not just using the negate operations to negate the part? why do all this?

Negate can split any part with no math required

use negate to split parts without needing any kind of math

CSG operations won’t work on meshes. We splitting MESHES, by getting their data, like vertices, edges and tris.
And soon Roblox will introduce DynamicMesh instance which will allow create meshes during run-time.

I see. If thats the case, good luck to all you mesh splitters. I’m sticking to parts.