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 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 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 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 override void PostCopy(MegaModifier src) { MegaFFD ffd = (MegaFFD)src; pt = new Vector3[64]; for (int c = 0; c < 64; c++) { pt[c] = ffd.pt[c]; } }
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; } }
void Update() { if (!Enabled) { return; } if (!ffd) { ffd = GetComponent <MegaFFD>(); } if (GetRecord()) { GetPoints(); } else { SetPoints(); } }
static public GameObject DoCopyObjects(GameObject from) { MegaModifyObject fromMod = from.GetComponent <MegaModifyObject>(); GameObject to; if (fromMod) { to = CopyMesh(from, fromMod); } else { to = CopyMesh(from); } //CopyObject.CopyFromTo(from, to); //return to; //MegaModifier[] desmods = to.GetComponents<MegaModifier>(); //for ( int i = 0; i < desmods.Length; i++ ) //{ // GameObject.DestroyImmediate(desmods[i]); //} //MegaModifyObject mo = to.GetComponent<MegaModifyObject>(); //if ( mo ) //{ //GameObject.DestroyImmediate(mo); MegaModifyObject mo = to.AddComponent <MegaModifyObject>(); CopyModObj(fromMod, mo); //} MegaModifier[] mods = from.GetComponents <MegaModifier>(); for (int i = 0; i < mods.Length; i++) { Component com = CopyComponent(mods[i], to); //Type tp = com.GetType(); #if false if (tp.IsSubclassOf(typeof(MegaMorphBase))) { MegaMorphBase mor = (MegaMorphBase)com; // Need to rebuild the morphchan List <MegaMorphChan> chans = new List <MegaMorphChan>(); for (int c = 0; c < mor.chanBank.Count; c++) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chans.Add(chan); } mor.chanBank = chans; } #endif #if false if (tp.IsSubclassOf(typeof(MegaFFD))) { MegaFFD ffd = (MegaFFD)com; MegaFFD srcffd = (MegaFFD)mods[i]; ffd.pt = new Vector3[64]; for (int c = 0; c < 64; c++) { ffd.pt[c] = srcffd.pt[c]; } } #endif // TODO: Add method to modifiers so can deal with any special cases if (com) { MegaModifier mod = (MegaModifier)com; mod.PostCopy(mods[i]); } } if (mo) { //mod.ReStart1(false); //for ( int i = 0; i < mods.Length; i++ ) // mods[i].SetModMesh(mod.cachedMesh); mo.MeshUpdated(); } to.name = from.name + " - Copy"; return(to); }
void ShowGUI(MegaModifier mod) { switch (mod.ModName()) { case "Bend": { MegaBend bmod = (MegaBend)mod; bmod.angle = AngleSlider("Angle", bmod.angle, 2.0f); bmod.dir = AngleSlider("Direction", bmod.dir, 1.0f); bmod.axis = (MegaAxis)XYZ("Axis", (int)bmod.axis); bmod.doRegion = GUILayout.Toggle(bmod.doRegion, "DoRegion"); if (bmod.doRegion) { bmod.from = Slider("From", bmod.from, -40.0f, 0.0f); bmod.to = Slider("To", bmod.to, 0.0f, 40.0f); } } break; case "Hump": MegaHump hmod = (MegaHump)mod; Vector3 size = mod.bbox.Size(); float sz = size.magnitude * 4.0f; hmod.amount = ProSlider("Amount", hmod.amount, -2.0f, 2.0f, sz); //objsize); hmod.cycles = Slider("Cycles", hmod.cycles, 0.0f, 20.0f); hmod.phase = Slider("Phase", hmod.phase, 0.0f, 10.0f); hmod.axis = (MegaAxis)XYZ("Axis", (int)hmod.axis); hmod.animate = GUILayout.Toggle(hmod.animate, "Animate"); if (hmod.animate) { hmod.speed = Slider("Speed", hmod.speed, -10.0f, 10.0f); } break; case "Twist": { MegaTwist tmod = (MegaTwist)mod; tmod.angle = AngleSlider("Angle", tmod.angle, 2.0f); tmod.Bias = Slider("Bias", tmod.Bias, -40.0f, 40.0f); tmod.axis = (MegaAxis)XYZ("Axis", (int)tmod.axis); tmod.doRegion = GUILayout.Toggle(tmod.doRegion, "DoRegion"); if (tmod.doRegion) { tmod.from = Slider("From", tmod.from, -40.0f, 0.0f); tmod.to = Slider("To", tmod.to, 0.0f, 40.0f); } } break; case "Taper": { MegaTaper tmod = (MegaTaper)mod; tmod.amount = Slider("Amount", tmod.amount, -10.0f, 10.0f); tmod.axis = (MegaAxis)XYZ("Axis", (int)tmod.axis); tmod.EAxis = (MegaEffectAxis)EAxisXYZ("EffectAxis", (int)tmod.EAxis); tmod.dir = AngleSlider("Direction", tmod.dir, 1.0f); tmod.crv = Slider("Curve", tmod.crv, -10.0f, 10.0f); tmod.sym = GUILayout.Toggle(tmod.sym, "Symmetry"); tmod.doRegion = GUILayout.Toggle(tmod.doRegion, "Limit Effect"); if (tmod.doRegion) { tmod.from = ProSlider("From", tmod.from, 0.0f, 1.0f, objsize); tmod.to = ProSlider("To", tmod.to, 0.0f, 1.0f, objsize); } } break; case "FFD3x3x3": MegaFFD fmod = (MegaFFD)mod; for (int i = 0; i < 27; i++) { string name = "p" + i; fmod.pt[i] = ProSlider(name, ref fmod.pt[i], -2.0f, 2.0f, objsize); } break; case "Noise": MegaNoise nmod = (MegaNoise)mod; nmod.Scale = Slider("Scale", nmod.Scale, 0.0f, 10.0f); nmod.Freq = Slider("Freq", nmod.Freq, 0.0f, 30.0f); nmod.Phase = Slider("Phase", nmod.Phase, 0.0f, 10.0f); nmod.Strength = ProSlider("Strength", ref nmod.Strength, 0.0f, 1.0f, objsize); nmod.Animate = GUILayout.Toggle(nmod.Animate, "Animate"); nmod.Fractal = GUILayout.Toggle(nmod.Fractal, "Fractal"); if (nmod.Fractal) { nmod.Rough = Slider("Rough", nmod.Rough, 0.0f, 1.0f); nmod.Iterations = Slider("Iterations", nmod.Iterations, 0.0f, 10.0f); } break; case "Ripple": MegaRipple rmod = (MegaRipple)mod; rmod.animate = GUILayout.Toggle(rmod.animate, "Animate"); if (rmod.animate) { rmod.Speed = Slider("Speed", rmod.Speed, -4.0f, 4.0f); } rmod.amp = ProSlider("Amp", rmod.amp, -1.0f, 1.0f, objsize); rmod.amp2 = ProSlider("Amp2", rmod.amp2, -1.0f, 1.0f, objsize); rmod.flex = Slider("Flex", rmod.flex, -10.0f, 10.0f); rmod.wave = Slider("Wave", rmod.wave, -25.0f, 25.0f); rmod.phase = Slider("Phase", rmod.phase, -100.0f, 100.0f); rmod.Decay = Slider("decay", rmod.Decay, 0.0f, 500.0f); break; case "Wave": MegaWave wmod = (MegaWave)mod; wmod.animate = GUILayout.Toggle(wmod.animate, "Animate"); if (wmod.animate) { wmod.Speed = Slider("Speed", wmod.Speed, -4.0f, 4.0f); } wmod.amp = ProSlider("Amp", wmod.amp, -1.0f, 1.0f, objsize * 0.75f); wmod.amp2 = ProSlider("Amp2", wmod.amp2, -1.0f, 1.0f, objsize * 0.75f); wmod.flex = Slider("Flex", wmod.flex, -10.0f, 10.0f); wmod.wave = Slider("Wave", wmod.wave, -100.0f, 100.0f); wmod.phase = Slider("Phase", wmod.phase, -100.0f, 100.0f); wmod.Decay = Slider("decay", wmod.Decay, 0.0f, 50.0f); wmod.dir = Slider("Direction", wmod.dir, 0.0f, 90.0f); break; case "Stretch": { MegaStretch smod = (MegaStretch)mod; smod.amount = Slider("Amount", smod.amount, -4.0f, 4.0f); smod.amplify = Slider("Amplify", smod.amplify, -2.0f, 2.0f); smod.axis = (MegaAxis)XYZ("Axis", (int)smod.axis); } break; case "Bubble": { MegaBubble bmod = (MegaBubble)mod; bmod.radius = ProSlider("Radius", bmod.radius, -1.0f, 4.0f, objsize); bmod.falloff = ProSlider("Falloff", bmod.falloff, -1.0f, 1.0f, objsize); } break; case "Spherify": { MegaSpherify smod = (MegaSpherify)mod; smod.percent = Slider("Percent", smod.percent, 0.0f, 100.0f); } break; case "Skew": { MegaSkew smod = (MegaSkew)mod; smod.amount = ProSlider("Amount", smod.amount, -2.0f, 2.0f, objsize); smod.dir = AngleSlider("Dir", smod.dir, 1.0f); smod.axis = (MegaAxis)XYZ("Axis", (int)smod.axis); } break; case "Melt": MegaMelt mmod = (MegaMelt)mod; mmod.Amount = Slider("Amount ", mmod.Amount, 0.0f, 100.0f); mmod.Spread = Slider("Spread", mmod.Spread, 0.0f, 100.0f); InitMatList(); GUILayout.Label("Solidity"); mmod.MaterialType = (MegaMeltMat)GUILayout.SelectionGrid((int)mmod.MaterialType, MatList, 2, "toggle"); if (mmod.MaterialType == MegaMeltMat.Custom) { mmod.Solidity = Slider("Custom", mmod.Solidity, 0.0f, 10.0f); } mmod.axis = (MegaAxis)XYZ("Axis", (int)mmod.axis); mmod.FlipAxis = GUILayout.Toggle(mmod.FlipAxis, "Flip Axis"); break; } }
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(); } } }
void Start() { ffd = GetComponent <MegaFFD>(); GetPoints(); }
void Update() { if ( !Enabled ) return; if ( !ffd ) ffd = GetComponent<MegaFFD>(); if ( GetRecord() ) GetPoints(); else SetPoints(); }
void Start() { ffd = GetComponent<MegaFFD>(); GetPoints(); }