using UnityEngine; public class MegaFFDWarp : MegaWarp { public float KnotSize = 0.1f; public bool inVol; public Vector3[] pt = new Vector3[64]; [HideInInspector] public float EPSILON = 0.001f; [HideInInspector] public Vector3 lsize = Vector3.one; [HideInInspector] public Vector3 bsize = default(Vector3); [HideInInspector] public Vector3 bcenter = default(Vector3); public float hw; public float hh; public float hl; public virtual int GridSize() { return 1; } public virtual int GridIndex(int i, int j, int k) { return 0; } public override string GetHelpURL() { return "?page_id=199"; } public Vector3 LatticeSize() { bsize.x = Width; bsize.y = Height; bsize.z = Length; Vector3 result = bsize; if (result.x == 0f) { result.x = 0.001f; } if (result.y == 0f) { result.y = 0.001f; } if (result.z == 0f) { result.z = 0.001f; } return result; } public void Init() { lsize = LatticeSize(); int num = GridSize(); float num2 = (float)num - 1f; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { for (int k = 0; k < num; k++) { int num3 = GridIndex(i, j, k); pt[num3].x = (float)i / num2; pt[num3].y = (float)j / num2; pt[num3].z = (float)k / num2; } } } } public override bool Prepare(float decay) { if (bsize.x != Width || bsize.y != Height || bsize.z != Length) { Init(); } Vector3 s = LatticeSize(); for (int i = 0; i < 3; i++) { if (s[i] == 0f) { s[i] = 1f; } else { s[i] = 1f / s[i]; } } tm = base.transform.worldToLocalMatrix; Vector3 trans = MegaMatrix.GetTrans(ref tm); MegaMatrix.SetTrans(ref tm, trans - -bsize * 0.5f); MegaMatrix.Scale(ref tm, s, false); invtm = tm.inverse; totaldecay = Decay + decay; if (totaldecay < 0f) { totaldecay = 0f; } hw = Width * 0.5f; hh = Height * 0.5f; hl = Length * 0.5f; return true; } public Vector3 GetPoint(int i) { Vector3 a = pt[i]; a.x -= 0.5f; a.y -= 0.5f; a.z -= 0.5f; return Vector3.Scale(a, lsize) + bcenter; } public Vector3 GetPoint(int i, int j, int k) { Vector3 a = pt[GridIndex(i, j, k)]; a.x -= 0.5f; a.y -= 0.5f; a.z -= 0.5f; return Vector3.Scale(a, lsize) + bcenter; } public void SetPoint(int i, int j, int k, Vector3 pos) { Vector3 lpos = base.transform.worldToLocalMatrix.MultiplyPoint(pos); SetPointLocal(i, j, k, lpos); } public void SetPointLocal(int i, int j, int k, Vector3 lpos) { Vector3 vector = lsize; Vector3 b = lsize; b.x = 1f / vector.x; b.y = 1f / vector.y; b.z = 1f / vector.z; lpos -= bcenter; Vector3 vector2 = Vector3.Scale(lpos, b); vector2.x += 0.5f; vector2.y += 0.5f; vector2.z += 0.5f; pt[GridIndex(i, j, k)] = vector2; } public void SetPoint(int index, Vector3 pos) { Vector3 lpos = base.transform.worldToLocalMatrix.MultiplyPoint(pos); SetPointLocal(index, lpos); } public void SetPointLocal(int index, Vector3 lpos) { Vector3 vector = lsize; Vector3 b = lsize; b.x = 1f / vector.x; b.y = 1f / vector.y; b.z = 1f / vector.z; lpos -= bcenter; Vector3 vector2 = Vector3.Scale(lpos, b); vector2.x += 0.5f; vector2.y += 0.5f; vector2.z += 0.5f; pt[index] = vector2; } public void MovePoint(int x, int y, int z, Vector3 localmove) { Vector3 point = GetPoint(x, y, z); point += localmove; SetPointLocal(x, y, z, point); } private void Reset() { } private static MegaFFDWarp Create(GameObject go, int type) { if (type == 0) { return go.AddComponent(); } return null; } public override void DrawGizmo(Color col) { } }