Cutting simple plane with a line (~2D)

Hey there!

I want to create a tool that can cut simple meshes (no depth in any of the meshes) in half by dragging a line with the mouse over a mesh.

[6627-cutting+illustration.png|6627]

I was thinking of raycasing on GetKeyUp, from mouseDown position to mouseUp position and vica versa to find the intersection points (5 and 6). And then rebuild the mesh using the new vertices into two meshes using the “normal” of the line to determine which mesh they belong to.

Im only looking for ideas here, some push in the right direction. Im not sure if this is even close to a good method and I’m a bit stuck.

Thanks for any help!

Well the easiest way is to use the Plane class and it’s Raycast function to get the two points on the plane of your mesh. Since you said all vartices lie in one plane you can take the first 3 points of the mesh to build the plane. Keep in mind that mesh vertices are in localspace and you have to use TransformPoint to get them into worldspace.

Of course it’s also possible to transform the rays into local space but that’s more mind challenging.

Once you have the two click points on your plane, you can use one of the 3d math functions in the wiki to calculate intersections with the border lines.

Keep in mind that a mesh is build up of triangles, so in your example above you have more intersection points :wink: two for each triangle.

So i would do it like this:

  • Get the cutting line with the above mentioned way.
  • iterate trough all triangles and test each edge for an intersection
  • if you have two intersections you can split the triangle into 1 triangle and one quad (so 3 triangles)

For edge-cases when a really small triangle would be created you could calculate the area of the triangle you’re going to create and drop those which are too small.

For cutting a square…

alt text

the weave is:

125
526
564
463

If you have never built mesh before, begin here ! →