public override void OnInspectorGUI() { MegaFFDAnimate ffd = (MegaFFDAnimate)target; #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020 EditorGUIUtility.LookLikeControls(); #endif ffd.Enabled = EditorGUILayout.Toggle("Enabled", ffd.Enabled); ffd.SetRecord(EditorGUILayout.Toggle("Record", ffd.GetRecord())); MegaFFD mod = ffd.GetFFD(); showpoints = EditorGUILayout.Foldout(showpoints, "Points"); if (mod && showpoints) { int size = mod.GridSize(); size = size * size * size; for (int i = 0; i < size; i++) { ffd.SetPoint(i, EditorGUILayout.Vector3Field("p" + i, ffd.GetPoint(i))); } } //if ( AnimationUtility.InAnimationMode() ) // ffd.SetRecord(true); //else // ffd.SetRecord(false); if (GUI.changed) { EditorUtility.SetDirty(target); } }
public void DrawGizmos(MegaFFD ffd, Matrix4x4 tm) { Handles.color = Color.red; int pc = ffd.GridSize(); for ( int i = 0; i < pc; i++ ) { for ( int j = 0; j < pc; j++ ) { for ( int k = 0; k < pc; k++ ) { pp3[0] = tm.MultiplyPoint(ffd.GetPoint(i, j, k) + ffd.bcenter); if ( i < pc - 1 ) { pp3[1] = tm.MultiplyPoint(ffd.GetPoint(i + 1, j, k) + ffd.bcenter); Handles.DrawLine(pp3[0], pp3[1]); } if ( j < pc - 1 ) { pp3[1] = tm.MultiplyPoint(ffd.GetPoint(i, j + 1, k) + ffd.bcenter); Handles.DrawLine(pp3[0], pp3[1]); } if ( k < pc - 1 ) { pp3[1] = tm.MultiplyPoint(ffd.GetPoint(i, j, k + 1) + ffd.bcenter); Handles.DrawLine(pp3[0], pp3[1]); } } } } }
public override bool Inspector() { MegaFFD mod = (MegaFFD)target; EditorGUIUtility.LookLikeControls(); mod.KnotSize = EditorGUILayout.FloatField("Knot Size", mod.KnotSize); mod.inVol = EditorGUILayout.Toggle("In Vol", mod.inVol); handles = EditorGUILayout.Toggle("Handles", handles); handleSize = EditorGUILayout.Slider("Size", handleSize, 0.0f, 1.0f); mirrorX = EditorGUILayout.Toggle("Mirror X", mirrorX); mirrorY = EditorGUILayout.Toggle("Mirror Y", mirrorY); mirrorZ = EditorGUILayout.Toggle("Mirror Z", mirrorZ); showpoints = EditorGUILayout.Foldout(showpoints, "Points"); if (showpoints) { int gs = mod.GridSize(); //int num = gs * gs * gs; for (int x = 0; x < gs; x++) { for (int y = 0; y < gs; y++) { for (int z = 0; z < gs; z++) { int i = (x * gs * gs) + (y * gs) + z; mod.pt[i] = EditorGUILayout.Vector3Field("p[" + x + "," + y + "," + z + "]", mod.pt[i]); } } } } return(false); }
public void DrawGizmos(MegaFFD ffd, Matrix4x4 tm) { Handles.color = Color.red; int pc = ffd.GridSize(); for (int i = 0; i < pc; i++) { for (int j = 0; j < pc; j++) { for (int k = 0; k < pc; k++) { pp3[0] = tm.MultiplyPoint(ffd.GetPoint(i, j, k) + ffd.bcenter); if (i < pc - 1) { pp3[1] = tm.MultiplyPoint(ffd.GetPoint(i + 1, j, k) + ffd.bcenter); Handles.DrawLine(pp3[0], pp3[1]); } if (j < pc - 1) { pp3[1] = tm.MultiplyPoint(ffd.GetPoint(i, j + 1, k) + ffd.bcenter); Handles.DrawLine(pp3[0], pp3[1]); } if (k < pc - 1) { pp3[1] = tm.MultiplyPoint(ffd.GetPoint(i, j, k + 1) + ffd.bcenter); Handles.DrawLine(pp3[0], pp3[1]); } } } } }
public override void DrawSceneGUI() { MegaFFD ffd = (MegaFFD)target; if (ffd.DisplayGizmo) { MegaModifiers context = ffd.GetComponent <MegaModifiers>(); Vector3 size = ffd.lsize; Vector3 osize = ffd.lsize; osize.x = 1.0f / size.x; osize.y = 1.0f / size.y; osize.z = 1.0f / size.z; Matrix4x4 tm1 = Matrix4x4.identity; Quaternion rot = Quaternion.Euler(ffd.gizmoRot); tm1.SetTRS(-(ffd.gizmoPos + ffd.Offset), rot, Vector3.one); if (context != null && context.sourceObj != null) { Handles.matrix = context.sourceObj.transform.localToWorldMatrix * tm1; } else { Handles.matrix = ffd.transform.localToWorldMatrix * tm1; } DrawGizmos(ffd, Handles.matrix); Handles.color = Color.yellow; int pc = ffd.GridSize(); pc = pc * pc * pc; for (int i = 0; i < pc; i++) { Vector3 p = ffd.GetPoint(i) + ffd.bcenter; //pm = Handles.PositionHandle(p, Quaternion.identity); pm = Handles.FreeMoveHandle(p, Quaternion.identity, ffd.KnotSize * 0.1f, Vector3.zero, Handles.CircleCap); pm -= ffd.bcenter; p = Vector3.Scale(pm, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[i] = p; } Handles.matrix = Matrix4x4.identity; } }
public override void DrawSceneGUI() { MegaFFD ffd = (MegaFFD)target; bool snapshot = false; if (ffd.DisplayGizmo) { MegaModifiers context = ffd.GetComponent <MegaModifiers>(); if (context && context.DrawGizmos) { Vector3 size = ffd.lsize; Vector3 osize = ffd.lsize; osize.x = 1.0f / size.x; osize.y = 1.0f / size.y; osize.z = 1.0f / size.z; Matrix4x4 tm1 = Matrix4x4.identity; Quaternion rot = Quaternion.Euler(ffd.gizmoRot); tm1.SetTRS(-(ffd.gizmoPos + ffd.Offset), rot, Vector3.one); Matrix4x4 tm = Matrix4x4.identity; Handles.matrix = Matrix4x4.identity; if (context != null && context.sourceObj != null) { tm = context.sourceObj.transform.localToWorldMatrix * tm1; } else { tm = ffd.transform.localToWorldMatrix * tm1; } DrawGizmos(ffd, tm); //Handles.matrix); Handles.color = Color.yellow; #if false int pc = ffd.GridSize(); pc = pc * pc * pc; for (int i = 0; i < pc; i++) { Vector3 p = ffd.GetPoint(i); // + ffd.bcenter; //pm = Handles.PositionHandle(p, Quaternion.identity); pm = Handles.FreeMoveHandle(p, Quaternion.identity, ffd.KnotSize * 0.1f, Vector3.zero, Handles.CircleCap); pm -= ffd.bcenter; p = Vector3.Scale(pm, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[i] = p; } #endif int gs = ffd.GridSize(); //int i = 0; Vector3 ttp = Vector3.zero; for (int z = 0; z < gs; z++) { for (int y = 0; y < gs; y++) { for (int x = 0; x < gs; x++) { int index = ffd.GridIndex(x, y, z); //Vector3 p = ffd.GetPoint(i); // + ffd.bcenter; Vector3 lp = ffd.GetPoint(index); Vector3 p = lp; //tm.MultiplyPoint(lp); //ffdi); // + ffd.bcenter; Vector3 tp = tm.MultiplyPoint(p); if (handles) { ttp = Handles.PositionHandle(tp, Quaternion.identity); //pm = tm.inverse.MultiplyPoint(Handles.PositionHandle(tm.MultiplyPoint(p), Quaternion.identity)); //pm = PositionHandle(p, Quaternion.identity, handleSize, ffd.gizCol1.a); } else { ttp = Handles.FreeMoveHandle(tp, Quaternion.identity, ffd.KnotSize * 0.1f, Vector3.zero, Handles.CircleCap); } if (ttp != tp) { if (!snapshot) { MegaUndo.SetSnapshotTarget(ffd, "FFD Lattice Move"); snapshot = true; } } pm = tm.inverse.MultiplyPoint(ttp); Vector3 delta = pm - p; //pm = lp + delta; //ffd.SetPoint(x, y, z, pm); pm -= ffd.bcenter; p = Vector3.Scale(pm, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[index] = p; if (mirrorX) { int y1 = y - (gs - 1); if (y1 < 0) { y1 = -y1; } if (y != y1) { Vector3 p1 = ffd.GetPoint(ffd.GridIndex(x, y1, z)); // + ffd.bcenter; delta.y = -delta.y; p1 += delta; p1 -= ffd.bcenter; p = Vector3.Scale(p1, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[ffd.GridIndex(x, y1, z)] = p; } } if (mirrorY) { int z1 = z - (gs - 1); if (z1 < 0) { z1 = -z1; } if (z != z1) { Vector3 p1 = ffd.GetPoint(ffd.GridIndex(x, y, z1)); // + ffd.bcenter; delta.z = -delta.z; p1 += delta; p1 -= ffd.bcenter; p = Vector3.Scale(p1, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[ffd.GridIndex(x, y, z1)] = p; } } if (mirrorZ) { int x1 = x - (gs - 1); if (x1 < 0) { x1 = -x1; } if (x != x1) { Vector3 p1 = ffd.GetPoint(ffd.GridIndex(x1, y, z)); // + ffd.bcenter; delta.x = -delta.x; p1 += delta; p1 -= ffd.bcenter; p = Vector3.Scale(p1, osize); p.x += 0.5f; p.y += 0.5f; p.z += 0.5f; ffd.pt[ffd.GridIndex(x1, y, z)] = p; } } } } } Handles.matrix = Matrix4x4.identity; if (GUI.changed && snapshot) { MegaUndo.CreateSnapshot(); MegaUndo.RegisterSnapshot(); } MegaUndo.ClearSnapshotTarget(); } } }
public void GetPoints() { if (ffd) { p00 = ffd.pt[0]; p01 = ffd.pt[1]; p02 = ffd.pt[2]; p03 = ffd.pt[3]; p04 = ffd.pt[4]; p05 = ffd.pt[5]; p06 = ffd.pt[6]; p07 = ffd.pt[7]; if (ffd.GridSize() > 2) { p08 = ffd.pt[8]; p09 = ffd.pt[9]; p10 = ffd.pt[10]; p11 = ffd.pt[11]; p12 = ffd.pt[12]; p13 = ffd.pt[13]; p14 = ffd.pt[14]; p15 = ffd.pt[15]; p16 = ffd.pt[16]; p17 = ffd.pt[17]; p18 = ffd.pt[18]; p19 = ffd.pt[19]; p20 = ffd.pt[20]; p21 = ffd.pt[21]; p22 = ffd.pt[22]; p23 = ffd.pt[23]; p24 = ffd.pt[24]; p25 = ffd.pt[25]; p26 = ffd.pt[26]; if (ffd.GridSize() > 3) { p27 = ffd.pt[27]; p28 = ffd.pt[28]; p29 = ffd.pt[29]; p30 = ffd.pt[30]; p31 = ffd.pt[31]; p32 = ffd.pt[32]; p33 = ffd.pt[33]; p34 = ffd.pt[34]; p35 = ffd.pt[35]; p36 = ffd.pt[36]; p37 = ffd.pt[37]; p38 = ffd.pt[38]; p39 = ffd.pt[39]; p40 = ffd.pt[40]; p41 = ffd.pt[41]; p42 = ffd.pt[42]; p43 = ffd.pt[43]; p44 = ffd.pt[44]; p45 = ffd.pt[45]; p46 = ffd.pt[46]; p47 = ffd.pt[47]; p48 = ffd.pt[48]; p49 = ffd.pt[49]; p50 = ffd.pt[50]; p51 = ffd.pt[51]; p52 = ffd.pt[52]; p53 = ffd.pt[53]; p54 = ffd.pt[54]; p55 = ffd.pt[55]; p56 = ffd.pt[56]; p57 = ffd.pt[57]; p58 = ffd.pt[58]; p59 = ffd.pt[59]; p60 = ffd.pt[60]; p61 = ffd.pt[61]; p62 = ffd.pt[62]; p63 = ffd.pt[63]; } } } }