MeshUtils

This class provides useful helper methods for 3D meshes. For example, you can easily slice your mesh into 2 parts!

Available methods

public static GameObject[] Slice(GameObject origin, Vector3 cutOrigin, Vector3 cutNormal)

This method slices given mesh into 2 parts, saving all physical characteristics and collider (if was presented on original gameobject).

cutOrigin is point where slice plane should pass (in local object's space, so Vector3.zero will be the center of object).

Example:

//Slice myself into 2 equal parts, vertically
MeshUtils.Slice(gameObject, Vector3.zero, Vector3.right);
Mesh was sliced into 2 parts

public static GameObject[] Fracture(GameObject origin, int fragmentsCount, FractureMode fractureMode)

This method fractures given object into certain count of fragments, with certain fracture mode.

Example:

//Fracture gameobject into 6 fragments with different angles of slicing
MeshUtils.Fracture(gameObject, 6, FractureMode.RandomAngles);
Mesh was fractured into 6 fragments

public static bool GetPlaneIntersectionPoint(Vector3 from, Vector3 to, Vector3 planeOrigin, Vector3 normal, out Vector3 result)

This method finds intersection point between given vector (set by from and to positions) and plane.

Example:

if (MeshUtils.GetPlaneIntersectionPoint(startPoint, 
    endPoint, planePos, planeNormal, out var foundPoint))
{
    Debug.Log($"Intersection found: {foundPoint}");
}

Last updated