Realtime Cut

Warning

Note that this feature is in beta stage, therefore it is not stable and it can create artifacts on the newly created meshes.

MAGES gives you the ability to perform realitme cuts in meshes, by providing a Cuttable Mesh and a Cutter script. Additionally a CutAction is available for implementing this feature in an Action Form (see Cut Action for more details). A combination of these can achieve results like the following:

Simple Cut Performed on a Cube

Cuttable Mesh

The Cuttable Mesh script found in the Add Component > MAGES > Mesh Deformations > Cuttable Mesh menu enables realtime seperation of a mesh along a plane. It can be used in combination with the Cutter script or as a standalone by simply calling the

public bool Cut(Plane cutPlane, out Mesh positiveSide, out Mesh negativeSide, out GameObject final, bool handleMeshReconstruction = true)

method. Afterwards you can use

public bool UndoCut()

to undo the last cut. By attaching the script in a GameObject that containts a Renderer component you get the following options:

Cuttable Mesh Inspector

Property

Description

bool useWithSoftbodies

Only available when attached in a mesh beeing a Softbody, it enables/disables the cutting of the underlying softbody structure

string partPrefabPath

After a cut if handleMeshReconstruction is enabled the two meshes will be attached to the Renderer of the 2 new instances of the prefab found in this prefab path. Note that the prefab must be under the Resources folder.

bool autoGenerateColliders

After the cut should mesh colliders be generated and attached to the new cut parts?

float seperationDistance

By how much should the new parts after a cut be moved appart? Used mainly to make the cut visible by leaving a gap in the cut section.

bool destroyOriginalAfterCut

Should the original uncut gameobject be destroyed after a cut has been performed?

Cutter

The Cutter script, found in the Add Component > MAGES > Mesh Deformations > Cutter menu, is a simple example script showing how to use the CuttableMesh. It can be attached in a gameobject that you want to act as a knife splitting the mesh in two parts. In order for the Cutter, to work we must have a trigger collider in the knife at the position of the blade and a collider (trigger or not) in the gameobject having the CuttableMesh script attached to it. These colliders will be used in order to detect the moment the knife enters the Cuttable Mesh and the moment it exits. We keep track of 3 points, two points on enter and one point on exit, in order to define the cutPlane.

By attaching the Cutter script to a gameobject you get the following properties:

The cutter inspector, having two fields for selecting two points on the tool to act as a blade.

Property

Description

CutSegment cutSegmentLocal

Defines the two points that will be used to create the cutPlane. Adjust them to match your blade’s edges.

Note

Instead of manually setting the cutSegment’s points you can use the two handles that appear in the scene. Make sure you have the editor Gizmos option enabled. If the handles do not show, they may be on the same point as the default move handle for this gameobject. If that is the case, simply select the hand tool in the editor in order to hand the default move tool and make the handles visible.

The gizmos that appear in the scene for setting the CutSegment points