Namespace: MDPackage.Modifiers
(FreeFormDeformer) Deform mesh by the specific weight values that correspond to the specific weight nodes.
Read more here (Online documentation slide)
Public Methods
public void FFD_RefreshFFDGrid()
public void FFD_ClearFFDGrid()
public List<Transform> FFD_GetNodes()
public bool FFD_NodesContain(Transform node)
Public Fields and Properties
public FFDType ffdType = FFDType.ffd2x2x2;
public FFDShape ffdShape = FFDShape.Sphere;
public GameObject ffdCustomShape;
public float ffdNodeSize = 0.25f;
[Range(0.0f, 1.0f)] public float ffdOffset = 0.2f;
public float ffdOffsetMultiplier = 1.0f;
[Range(2,12)] public int ffdCustomCount = 2;
[Range(0,1)] public float weight = 0.5f;
public float threshold = 0.15f;
public float density = 1.35f;
public float bias = 1.0f;
public float multiplier = 1.0f;
public float distanceLimitation = Mathf.Infinity;
public Transform NodeRoot { get; }
Examples
The following paragraphs contain FFD modifier used in a practical example - interaction with FFD grid at runtime. Drag/drop generated nodes at runtime.
using UnityEngine;
using MDPackage.Modifiers;
[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
public Camera mainCam;
private MDM_FFD ffd;
private Transform selectedNode;
private float depth;
private void Start()
{
ffd = MD_ModifierBase.CreateModifier<MDM_FFD>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
ffd.useNormalSmoothingAngle = true;
ffd.FFD_RefreshFFDGrid();
}
private void Update()
{
if (!mainCam)
return;
if (Input.GetKeyDown(KeyCode.Space))
ffd.MDModifier_SubdivideMesh();
if (Input.GetKeyDown(KeyCode.S))
ffd.MDModifier_SmoothMesh();
if (Input.GetKeyDown(KeyCode.R))
ffd.MDModifier_RestoreMesh();
if (Input.GetMouseButtonDown(0))
{
Ray r = mainCam.ScreenPointToRay(Input.mousePosition);
bool hit = Physics.Raycast(r, out RaycastHit h) && h.transform && ffd.FFD_NodesContain(h.transform);
if (hit)
{
selectedNode = h.transform;
depth = mainCam.WorldToScreenPoint(selectedNode.position).z;
}
}
if (!selectedNode)
return;
if (Input.GetMouseButton(0))
{
Vector3 mouse = Input.mousePosition;
mouse.z = depth;
Vector3 wp = mainCam.ScreenToWorldPoint(mouse);
selectedNode.position = wp;
}
else if (Input.GetMouseButtonUp(0))
selectedNode = null;
}
}