MD Package Technical & APi Documentation
MD_MeshProEditor
Namespace: MDPackage
Mesh Pro Editor offers a simple vertex editor and the component serves as a bridge for mesh modifiers in MD Package.
Users can edit high poly meshes in Unity Editor using the simple vertex editor that is GPU accelerated and low-poly, to medium-poly meshes at runtime by generating points as gameObjects on mesh vertices. The component tracks the initial mesh reference allowing the user to restore from backup snapshot.
Read more here (Online documentation slide)
Properties
// Does the current mesh editor contain mesh filter and a mesh reference?
public bool IsMeshEditorValid { get; }
// Buffer of working mesh vertices used to modify mesh reference's vertices. Returns an array reference of working vertices. Setting the array refreshes the entire mesh editor
public Vector3[] CurrentMeshWorkingVertices { get; set; }
// Current mesh name - setting a new mesh name updates the mesh reference's name
public string CurrentMeshName
// Returns a copy of mesh triangles. Returns null if mesh editor is not valid
public int[] GetMeshTrianglesCopyArray { get; }
// Returns true if the mesh backup exists
public bool HasMeshBackupSnapshot { get; }

// Create a new mesh reference for this mesh filter once this gameObject is duplicated/ copied?
public bool CreateNewReferenceAfterCopy { get; set; }
// Update the current mesh vertices (once generated) every frame automatically?
public bool UpdateMeshEveryFrame { get; set; }
// Recalculate normals by using the normals smoothing angle? This allows the user to customize the normals calculation based on normals angle
public bool RecalculateNormalsSmoothingAngle { get; set; }
public float SmoothingAngleValue { get; set; }

// Keep the generated gameObject points even when the vertex editor is not used?
public bool KeepGeneratedPoints { get; set; }
// Are the gameObject points generated?
public bool HasGameObjectPointsGenerated { get; }
// Array of generated gameObject points (might return null) - the array includes total number of vertices, including the shared ones
public Transform[] GeneratedGameObjectPoints { get; }
// Array of generated gameObject points (might return null) filtered - the array includes filtered points - vertices with the same local positions are grouped
public Transform[] GeneratedGameObjectPointsFiltered { get; }
Events
public event Action<MD_MeshProEditor> OnMeshEditorInitialized;
public event Action<MD_MeshProEditor> OnMeshEditorPointsGenerated;
public event Action<MD_MeshProEditor> OnMeshEditorPointsCleared;
public event Action<MD_MeshProEditor> OnMeshEditorSmoothed;
public event Action<MD_MeshProEditor> OnMeshEditorSubdivided;
Public Methods
// Mesh Core Methods

// Initialize the mesh editor with customized reference option
public MD_MeshProEditor MPE_Init(bool createNewMeshReference = true)
// Synchronize the mesh vertices with the working vertices array and recalculate mesh bounds and normals
public void MPE_RefreshCurrentMesh()
// Assign a new mesh reference for this mesh filter
public void MPE_UpdateMeshReference(Mesh newMeshReference)
// Reassign a new vertices array for the working vertices that control the mesh editor
public void MPE_UpdateCurrentMeshVertices(Vector3[] newVertexArray)
// Recalculate the current mesh normals and bounds
public void MPE_RecalculateNormalsAndBounds()
// Create a brand new mesh reference of this object - please note that this will remove all of its behaviours and children and will create a brand new gameObject as well
public void MPE_CreateNewReference()
// Combine current mesh with all of its submeshes. The current gameObject will keep untouched, only mesh will change
public void MPE_CombineMeshes()

// Mesh Backup Snapshot

// Create a backup snapshot of the current mesh. The snapshot will be stored as a 'backup mesh' for later use
public void MPE_CreateMeshBackup()
// Remove a mesh backup if there is any
public void MPE_RemoveMeshBackup()
// Restore the current mesh from the stored mesh backup (if there is any)
public void MPE_RestoreMeshFromBackup()

// Internal Mesh Modifiers

public void MPE_SmoothMesh(float intensity = 0.5f)
public void MPE_SubdivideMesh(SubdivisionLevel level)

// Mesh Editor where Points As GameObjects

// Generate gameObject points that will represent mesh vertices in the scene by customized settings
public void MPE_GenerateMeshEditorPointsAsGameObjects(bool bypassKeepGeneratedPoints, bool bypassVertexLimit,
   GameObject customPointGraphics = null, float customPointScale = 0.1f, Color? customPointColor = default, bool generateSphereColliders = false)
// Generate gameObject points that will represent mesh vertices in the scene by default, inspector settings
public void MPE_GenerateMeshEditorPointsAsGameObjects()
// Show/ hide the generated gameObject points that represent mesh vertices
public void MPE_ShowHideGeneratedMeshEditorPoints(bool show)
// Manually synchronize the mesh vertices with the generated gameObject points that represent vertices
public void MPE_SyncMeshWithGeneratedMeshEditorPoints()
// Clear/ destroy the currently generated vertex editor represented as gameObject points
public void MPE_ClearGeneratedMeshEditorPoints(bool bypassKeepGeneratedPoints = false)
Examples
The following paragraphs contain MeshProEditor used in a practical example. Generate mesh vertices as gameObject points through the MeshProEditor and modify these points at runtime.
using UnityEngine;
using MDPackage;

[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
public bool hideGeneratedPoints = true;

private MD_MeshProEditor meshProEditor;

private void Start()
 {
  // Add MPE to the current meshFilter gameObject
  meshProEditor = gameObject.AddComponent<MD_MeshProEditor>();
  // Create/ generate points on the mesh
  meshProEditor.MPE_GenerateMeshEditorPointsAsGameObjects();
  // Set the points active state
  meshProEditor.MPE_ShowHideGeneratedMeshEditorPoints(!hideGeneratedPoints);
  // Enable Smooth-angle normals recalculation for smoother results
  meshProEditor.RecalculateNormalsSmoothingAngle = true;
  // We will animate/keep the vertices during the playtime
  meshProEditor.KeepGeneratedPoints = true;
 }

private void Update()
 {
  // Check if the generated points exist
  if (meshProEditor.HasGameObjectPointsGenerated == false)
   return;
  // Now you can modify the generated points!
  foreach(Transform t in meshProEditor.GeneratedGameObjectPointsFiltered)
   t.localPosition += ((Mathf.Sin(Time.time * 1.5f) * 0.5f) * Mathf.Abs(t.localPosition.y)) * Time.deltaTime * Vector3.up;
 }
}