MD Package Technical & APi Documentation
MDM_MeshFit :: MD_ModifierBase
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
// Show/ Hide renderers of the generated points (if exist)
public void MeshFit_ShowHidePoints(bool activation)
// Generate gameObject points on the mesh
public void MeshFit_GeneratePoints()
// Clear points on the mesh (if possible)
public void MeshFit_ClearPoints()
// Reset mesh matrix transform (set scale to 1 and keep the shape)
public void MeshFit_BakeMesh()
// Update current mesh state (if UpdateEveryFrame is disabled)
public void MeshFit_UpdateMeshState()
// Refresh currently selected points state. Once the selected points are assigned, this will separate selected and unselected points
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; // FitWholeMesh, FitSpecificVertices
public bool meshFitterContinuousEffect = false;

public Transform[] generatedPoints { get; } // Filtered points
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()
 {
  // Add/Create a Mesh Fit modifier to this object right after start
  fit = MD_ModifierBase.CreateModifier<MDM_MeshFit>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
  // Reset object's transform (keep the current scale and reset the matrix to 1)
  fit.MeshFit_BakeMesh();
  // Generate points on start and start moving with the object...
  fit.MeshFit_GeneratePoints();
  // Destroy any collider that this object may contain
  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()
 {
  // Add/Create a Mesh Fit modifier to this object right after start
  fit = MD_ModifierBase.CreateModifier<MDM_MeshFit>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
  // Reset object's transform (keep the current scale and reset the matrix to 1)
  fit.MeshFit_BakeMesh();
  // Generate points on start
  fit.MeshFit_GeneratePoints();
  // Destroy any collider that this object may contain
  if (TryGetComponent<Collider>(out Collider c))
   Object.Destroy(c);
  // Set the fitter type
  fit.meshFitterType = MDM_MeshFit.MeshFitterMode.FitSpecificVertices;
  List<GameObject> selPoints = new List<GameObject>();
  // Generate and assign specific points that will control specific mesh vertices
  foreach (var p in fit.generatedPoints)
  {
   if (p.localPosition.y <= -0.35f) // Or any other type of condition... Works just fine with regular cube
    selPoints.Add(p.gameObject);
  }
  // Assign the selected points
  fit.selectedPoints = selPoints.ToArray();
  fit.MeshFit_RefreshSelectedPointsState();
 }
}