Realtime Tear

Warning

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

MAGES gives you the ability to perform realitme surgical like tear in meshes, by providing a Tearable Mesh and a Tearer script. A combination of these cn achieve results like the following:

Simple Cut Performed on a Cube

Tearable Mesh

The Tearable Mesh script found in the Add Component > MAGES > Mesh Deformations > Tearable Mesh menu enables realtime surgical like tearing. It can be used with the Tearer script or as a standalone by simply calling the public void Tear(Vector3 pointA, Vector3 pointB, Vector3 direction, float width, float height) or the public void Tear(Plane leftFace, Plane rightFace, Plane bottomFace, Plane topFace, Plane frontFace, Plane backFace) method. These methods will remove a box-like section of mesh. The first method needs two points, the direction of the height of the box normalized, the width and the height of it. The second method needs 6 planes defining the 6 faces of a box with their normals facing inside the box.

By attaching the script in a GameObject that containts a Renderer component you get the following options:

Tearable Mesh added to a gameobject.

Property

Description

bool editFragmentScaleFactor

Used only when the public void Tear(Vector3 pointA, Vector3 pointB, Vector3 direction, float width, float height) method is called. To improve performance when this prperty is greater than 0 a selection sphere is created and instead of all the triangles, only the triangles inside it are checked for tear. Adjust it appropriately to the smaller value possible, while creating tears without artifacts.

useWithSoftbodies

Only available when the tearable mesh is attached to a softbody object. When enabled, the particle connections intersecting the tear box will be broken and the particles will not affect vertices in the oposite side of the box; The tear will be able to spread.

Tearer

The Tearer script, found in the Add Component > MAGES > Mesh Deformations > Tearer menu, is a simple example script showing how to use the TearableMesh. It can be attached in a gameobject that you want to act as a scalpel tearring the mesh. In order for the Tearer to work, we must have a trigger collider in the scalpel at the position of the blade and a collider (trigger or not) in the gameobject having the TearableMesh script attached to it. These colliders will be used in order to detect the moment the scalpel enters the Tearable Mesh and the moment it exits.

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

The tearer inspector.

Property

Description

public float width

The width of the tear, in worldspace.

public float tearPerformDistance

The distance of the sample points for creating the boxes, on the curve the movement of the tearer. Smaller values will create smoother curves, but decrease performance.

public float tearPerformAngleDegrees

If the angle in degrees created from the position of the tearer in relation to the old tear box is greater than this, a new tear box will be created. Smaller values will create smoother curves, but decrease performance.

public float weldTearSegments

Weld multiple tear boxes together in order to create a continuous curve?

public TearSegment tearSegment

Defines the two points that will be used for creating the tear boxes. Adjust them to match your blade’s edges.

Note

Instead of manually setting the tearSegment’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 TearSegment points