Namespace: MDPackage.Modifiers
Simple and straight-two-sided mesh cut solution with custom cut settings and events.
Read more here (Online documentation slide)
Properties
public MDM_MeshCut_Cutter CutterSource { get; set; }
public int BufferContainerSize { get; set; }
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; }
public bool AddSeparationOffset { get; set; }
public float SeparationOffsetValue { get; set; }
public bool AddMeshColliderAfterCut { get; set; }
public bool AutomaticallyCut { get; set; }
public float AutomaticallyCutDelayFrequency { get; set; }
public IReadOnlyCollection<MeshCutChunk> CreatedMeshCutChunks { get; }
public MeshCollider MyMeshCollider { get; }
Events
public event Action<List<Transform>> OnMeshCut;
public UnityEvent OnMeshCutUnityEvent;
Public Methods
public void MeshCut_Cut()
public void MeshCut_Cut(MDM_MeshCut_Cutter cutterInput)
public void MeshCut_Cut(Vector3 position, Vector3 normal)
public void MeshCut_Cut(Vector3 position, Vector3 normal, List<(MeshFilter f, MeshCollider c)> availableMeshes)
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;
public class SampleScript : MonoBehaviour
{
[SerializeField] private Camera mainCam;
[SerializeField] private MeshFilter[] targetObjectsToCut;
private MDM_MeshCut[] targetMeshCutters;
private void Start()
{
if (targetObjectsToCut == null || targetObjectsToCut.Length == 0)
return;
targetMeshCutters = new MDM_MeshCut[targetObjectsToCut.Length];
for (int i = 0; i < targetObjectsToCut.Length; i++)
{
var obj = targetObjectsToCut[i];
if (obj == null) continue;
var cut = targetMeshCutters[i] = MD_ModifierBase.CreateModifier<MDM_MeshCut>(obj.gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
cut.AddSeparationOffset = true;
cut.AddMeshColliderAfterCut = true;
cut.MeshCut_RefreshMeshCollider();
}
}
private void Update()
{
if (!mainCam)
return;
if (Input.GetKeyDown(KeyCode.Space))
foreach (MDM_MeshCut mc in targetMeshCutters)
mc.MDModifier_SubdivideMesh();
if (Input.GetKeyDown(KeyCode.S))
foreach (MDM_MeshCut mc in targetMeshCutters)
mc.MDModifier_SmoothMesh();
if (Input.GetMouseButtonDown(0))
{
Ray r = mainCam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(r, out RaycastHit h))
{
foreach (MDM_MeshCut mc in targetMeshCutters)
{
mc.MeshCut_Cut(h.point, Vector3.right);
}
}
}
}
}