Namespace: MDPackage.Modifiers
Modify mesh vertices by surface height or fit mesh to any collider.
Great time saver while creating environmental decals!
Read more here (Online documentation slide)
Public Methods
public void MeshFit_ShowHidePoints(bool activation)
public void MeshFit_GeneratePoints()
public void MeshFit_ClearPoints()
public void MeshFit_BakeMesh()
public void MeshFit_UpdateMeshState()
public void MeshFit_RefreshSelectedPointsState()
Public Fields & Properties
public LayerMask allowedLayers = ~0;
public float meshFitterOffset = 0.03f;
public float meshFitterSurfaceDetection = 3;
public MeshFitterMode meshFitterType = MeshFitterMode.FitWholeMesh;
public bool meshFitterContinuousEffect = false;
public Transform[] generatedPoints { get; }
public GameObject[] selectedPoints;
Examples
The following paragraphs contain Mesh Fit modifier component used in a practical example - add and control Mesh Fit modifier on a specific gameObject.
using UnityEngine;
using MDPackage.Modifiers;
[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
private MDM_MeshFit fit;
private void Start()
{
fit = MD_ModifierBase.CreateModifier<MDM_MeshFit>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
fit.MeshFit_BakeMesh();
fit.MeshFit_GeneratePoints();
if (TryGetComponent<Collider>(out Collider c))
Object.Destroy(c);
}
}
Mesh Fit with selected points - selected points are received from checking the lowest position among the generated points.
using System.Collections.Generic;
using UnityEngine;
using MDPackage.Modifiers;
[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
private MDM_MeshFit fit;
private void Start()
{
fit = MD_ModifierBase.CreateModifier<MDM_MeshFit>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
fit.MeshFit_BakeMesh();
fit.MeshFit_GeneratePoints();
if (TryGetComponent<Collider>(out Collider c))
Object.Destroy(c);
fit.meshFitterType = MDM_MeshFit.MeshFitterMode.FitSpecificVertices;
List<GameObject> selPoints = new List<GameObject>();
foreach (var p in fit.generatedPoints)
{
if (p.localPosition.y <= -0.35f)
selPoints.Add(p.gameObject);
}
fit.selectedPoints = selPoints.ToArray();
fit.MeshFit_RefreshSelectedPointsState();
}
}