MD Package Technical & APi Documentation
MDM_SculptingLite :: MD_ModifierBase
Namespace: MDPackage.Modifiers
A lite version of a complete sculpting solution for mesh renderers in Unity editor / at runtime.
Visit link for pro version.
Read more here (Online documentation slide)
Properties
// IMDThreading implementation

// Use multithreading feature for this modifier?
public bool ThreadUseMultithreading { get; set; }
// Is multithreading in Unity-editor supported?
public bool ThreadEditorThreadSupported { get; }
// Is a task finished for this thread?
public bool ThreadIsDone { get; }
// Sleep time for a thread in ms
public int ThreadSleep { get; set; }

// > Properties - Sculpting base settings & target platform

public bool IsMobilePlatform { get; set; }
public bool IsVRPlatform { get; set; }

public bool RecalculateNormalsOnRelease { get; set; }
public bool RecalculateMeshColliderOnRelease { get; set; }

// > Properties - Sculpting history

public bool RecordHistory { get; set; }
public int MaxHistoryRecords { get; set; }
public List<HistoryRecords> SculptingHistoryRecords { get; }

// > Properties - Sculpting brush settings

public bool UseBrushProjection { get; set; }
public GameObject BrushProjection { get; set; }
public float BrushSize { get; set; }
public float BrushIntensity { get; set; }
public BrushStatus BrushStatusOverride { get; set; }
public SculptingMode CurrentSculptingMode { get; set; }
public CustomDirObjDirection DirectionTowardsObjectType { get; set; }
public GameObject CustomDirectionObjectRef { get; set; }
public Vector3 CustomSculptingDirection { get; set; }

// > Properties - Sculpting limitations

public bool UseHeightLimitations { get; set; }
public Vector2 HeightLimitations { get; set; }
public bool UseDistanceLimitations { get; set; }
public float DistanceLimitations { get; set; }

public InterpolationType CurrentInterpolationType { get; set; }

// > Properties - Input handling & its features

public bool UseInputHookups { get; set; }
public bool UseInputFeature_Raise { get; set; }
public bool UseInputFeature_Lower { get; set; }
public bool UseInputFeature_Revert { get; set; }
public bool UseInputFeature_Noise { get; set; }
public NoiseTypes CurrentNoiseType { get; set; }
public bool UseInputFeature_Smooth { get; set; }
public SmoothingType CurrentSmoothingType { get; set; }
public float SmoothingFilterLaplacianIntensity { get; set; }
public bool UseInputFeature_Stylize { get; set; }
public float StylizeIntensity { get; set; }

// Use this input hookup for cursor/touch world screen position
public Vector3 InputHook_CursorScreenPosition { get; set; }

public bool InputHook_Lower { get; set; }
public bool InputHook_Raise { get; set; }
public bool InputHook_Revert { get; set; }
public bool InputHook_Noise { get; set; }
public bool InputHook_Smooth { get; set; }
public bool InputHook_Stylize { get; set; }

public bool InputHook_GenericNonPCButton { get; set; }

// > Properties - Sculpting raycasting

public LayerMask CurrentSculptingLayerMask { get; set; }
public bool SculptingOriginIsCursor { get; set; }
public Transform SculptingOriginObject { get; set; }

public Camera MainCameraCache { get; set; }
Public Methods
// Core Methods

// Sculpt current mesh by the specified parameters
public void Sculpting_DoSculpting(Vector3 worldPosition, Vector3 directionLocal, float radius, float intensity, BrushStatus brushState)
// Refresh mesh collider at runtime on the current mesh
public void Sculpting_RefreshMeshCollider()

// Input Controls

// Capture & record any button control UP/has been released to update mesh collider, recalculate bounds/normals and pause thread (if possible)
public void Sculpting_RecordControlUp()
// Capture & record any button control DOWN/has been pressed to record history and resume thread (if possible)
public void Sculpting_RecordControlDown()

// History Management

// Record current vertex positions to the history
public void Sculpting_RecordHistory()
// Make a step forward/backward in the history by the specified 'jumpToRecord' index. Use '-1' for a default value = jump to the latest history record
public void Sculpting_Undo(int jumpToRecordIndex)
// Default undo method - make a step backward from the last element
public void Sculpting_Undo()

// Sculpting Further Methods

// Change brush status by index value
// None, Raise, Lower, Revert, Noise, Smooth, Stylize
public void Sculpting_ChangeBrushStatus(int stateIndex)
// Change sculpting mode by index value
// VerticesDirection (vertices normal dir), BrushDirection (brush hit normal), CustomDirection (custom vector property), CustomDirectionObject (custom object reference forward vector), InternalScriptDirection (internal custom direction via script)
public void Sculpting_ChangeSculptingMode(int modeIndex)
Examples
The following paragraphs contain SculptingLite modifier used in a practical example - create a sculpting editor at runtime.
Hence the custom input handling. You can adapt your own input system.
using UnityEngine;
using MDPackage.Modifiers;

[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
private MDM_SculptingLite sculpting;

private void Start()
 {
  // Add/create a sculptingLite modifier to this object
  sculpting = gameObject.AddComponent<MDM_SculptingLite>();
  // Use normals smoothing angle for smoother results
  sculpting.MbUseNormalSmoothingAngle = true;
  // Update collider
  sculpting.Sculpting_RefreshMeshCollider();
  // Choose the following sculpting input features
  sculpting.UseInputHookups = true;
  sculpting.UseInputFeature_Raise = true;
  sculpting.UseInputFeature_Lower = true;
  sculpting.UseInputFeature_Revert = true;
  // Set brush base settings
  sculpting.BrushIntensity = 0.5f;
  sculpting.BrushSize = 1f;
 }

// Handle input - adapt your own input system
private void Update()
 {
  if (sculpting == null)
   return;

  // Only PC-mouse
  sculpting.InputHook_CursorScreenPosition = Input.mousePosition;
  sculpting.InputHook_Raise = Input.GetKey(KeyCode.Mouse0);
  sculpting.InputHook_Lower = Input.GetKey(KeyCode.Mouse1);
  sculpting.InputHook_Revert = Input.GetKey(KeyCode.Mouse2);
 }
}
The following paragraphs contain SculptingLite modifier used in a practical example - create a custom sculpting raycast at runtime.
using UnityEngine;
using MDPackage.Modifiers;

[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
private MDM_SculptingLite sculpting;

// Cache camera!
 [SerializeField] private Camera mainCam;
 [Space]
 [SerializeField, Min(0)] private float brushSize = 0.35f;
 [SerializeField] private float brushIntensity = 0.1f;

private void Start()
 {
  // Add/create a sculptingLite modifier to this object
  sculpting = gameObject.AddComponent<MDM_SculptingLite>();
  // Disable input by default as we are going to use a 'custom sculpting'
  sculpting.UseInputHookups = false;
  // Update collider
  sculpting.Sculpting_RefreshMeshCollider();
 }

private void Update()
 {
  if (sculpting == null || mainCam == null)
   return;

  // Create a raycast from camera
  Ray r = mainCam.ScreenPointToRay(Input.mousePosition);
  if (Physics.Raycast(r, out RaycastHit h, 1000))
  {
   // If the raycast hits the sculpting object, process the sculpting
   if (h.collider && h.collider.gameObject == sculpting.gameObject)
   {
    // Set any brush status - Raise/Lower/Revert/Smooth...
    MDM_SculptingLite.BrushStatus status = MDM_SculptingLite.BrushStatus.None;
    if (Input.GetMouseButton(0))
     status = MDM_SculptingLite.BrushStatus.Raise;
    else if (Input.GetMouseButton(1))
     status = MDM_SculptingLite.BrushStatus.Lower;

    // This is required to call to refresh the mesh collider and recalculate bounds/normals
    if (status == MDM_SculptingLite.BrushStatus.None)
     sculpting.Sculpting_RecordControlUp();
    else
     sculpting.Sculpting_RecordControlDown();

    // Process custom sculpting on hit point, hit normal direction, custom brush size and intens, finally a sculpting brush status
    sculpting.Sculpting_DoSculpting(h.point, h.normal, brushSize, -brushIntensity, status);
   }
   else
    sculpting.Sculpting_RecordControlUp();
  }
  else
   sculpting.Sculpting_RecordControlUp();
 }
}