MD Package Technical & APi Documentation
MDM_MeshCut :: MD_ModifierBase
Namespace: MDPackage.Modifiers
Simple and straight-two-sided mesh cut solution with custom cut settings and events.
Read more here (Online documentation slide)
Properties
// Main reference for mesh cutting
public MDM_MeshCut_Cutter CutterSource { get; set; }

// Buffer that holds a size of a cut container - the higher, the more chunks can be processed on larger meshes
public int BufferContainerSize { get; set; }

// Rigidbody Settings

public bool AddRigidbodyAfterCut { get; set; }
public float RigidbodyDefaultMass { get; set; }
public float RigidbodySeparationForce { get; set; }
public float RigidbodyAngularDrag { get; set; }
public float RigidbodyLinearDrag { get; set; }

// Primitive Separation

public bool AddSeparationOffset { get; set; }
public float SeparationOffsetValue { get; set; }

public bool AddMeshColliderAfterCut { get; set; }

// If enabled, the script will check for the potential cut sources in specific interval
public bool AutomaticallyCut { get; set; }
// Cut check interval frequency in seconds
public float AutomaticallyCutDelayFrequency { get; set; }

// Readonly collection of cut mesh chunks
public IReadOnlyCollection<MeshCutChunk> CreatedMeshCutChunks { get; }

public MeshCollider MyMeshCollider { get; }
Events
// Invoked when the mesh has been cut - contains a list of cut mesh chunks
public event Action<List<Transform>> OnMeshCut;
public UnityEvent OnMeshCutUnityEvent;
Public Methods
// Call this method to process the cut feature with properly assigned cutter source reference
public void MeshCut_Cut()
// Process mesh cut with required cutter input
public void MeshCut_Cut(MDM_MeshCut_Cutter cutterInput)
// Process mesh cut with required point-location & normal vector. Related just for this mesh and its chunks
public void MeshCut_Cut(Vector3 position, Vector3 normal)
// Process mesh cut with required point-location, normal vector & available meshes to process. Available meshes can be any meshes that might be related to this cutting object
public void MeshCut_Cut(Vector3 position, Vector3 normal, List<(MeshFilter f, MeshCollider c)> availableMeshes)
// Refresh mesh collider to all created chunks (if possible)
public void MeshCut_RefreshMeshCollider()
Examples
The following paragraphs contain Mesh Cut modifier used in a practical example - cut specific meshes with raycast at runtime.
using UnityEngine;
using MDPackage.Modifiers;

// Sample script for Mesh Cut modifier - cut a mesh with custom raycast - apply this script to any empty object and assign gameObjects you would like to cut
public class SampleScript : MonoBehaviour
{
// Cache main camera in the inspector!
 [SerializeField] private Camera mainCam;
// Assign single or multiple gameObjects with MeshFilter
 [SerializeField] private MeshFilter[] targetObjectsToCut;

private MDM_MeshCut[] targetMeshCutters;

private void Start()
 {
  if (targetObjectsToCut == null || targetObjectsToCut.Length == 0)
   return;
  targetMeshCutters = new MDM_MeshCut[targetObjectsToCut.Length];
  // Add/Create a Mesh Cut modifier to each object right after start
  for (int i = 0; i < targetObjectsToCut.Length; i++)
  {
   var obj = targetObjectsToCut[i];
   if (obj == null) continue;
   // Add a Mesh Cut modifier to all the assigned gameObjects with MeshFilter
   var cut = targetMeshCutters[i] = MD_ModifierBase.CreateModifier<MDM_MeshCut>(obj.gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
   // Add separation offset if desired
   cut.AddSeparationOffset = true;
   cut.AddMeshColliderAfterCut = true;
   // Refresh mesh collider for raycast detection
   cut.MeshCut_RefreshMeshCollider();
  }
 }

private void Update()
 {
  // Main camera must be initialized
  if (!mainCam)
   return;

  // Additional extensions for meshes
  // If Space is pressed, subdivide meshes if possible
  if (Input.GetKeyDown(KeyCode.Space))
   foreach (MDM_MeshCut mc in targetMeshCutters)
    mc.MDModifier_SubdivideMesh();
  // If S is pressed, smooth meshes
  if (Input.GetKeyDown(KeyCode.S))
   foreach (MDM_MeshCut mc in targetMeshCutters)
    mc.MDModifier_SmoothMesh();

  if (Input.GetMouseButtonDown(0))
  {
   // Create raycast from camera to the cursor position
   Ray r = mainCam.ScreenPointToRay(Input.mousePosition);
   // Checking for potential hit - if the hit collider equals any of the cutters, the hit mesh will be cut
   if (Physics.Raycast(r, out RaycastHit h))
   {
    foreach (MDM_MeshCut mc in targetMeshCutters)
    {
     // Params: Hit point and cutting normal direction
     mc.MeshCut_Cut(h.point, Vector3.right);
    }
   }
  }
 }
}