//void OnSceneGUI() //{ //PathDeform pd = (PathDeform)target; //Display(pd); //} public override bool Inspector() { MegaPathDeform mod = (MegaPathDeform)target; EditorGUIUtility.LookLikeControls(); mod.percent = EditorGUILayout.FloatField("Percent", mod.percent); mod.stretch = EditorGUILayout.FloatField("Stretch", mod.stretch); mod.twist = EditorGUILayout.FloatField("Twist", mod.twist); mod.rotate = EditorGUILayout.FloatField("Rotate", mod.rotate); mod.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", mod.axis); mod.flip = EditorGUILayout.Toggle("Flip", mod.flip); mod.path = (MegaShape)EditorGUILayout.ObjectField("Path", mod.path, typeof(MegaShape), true); mod.animate = EditorGUILayout.Toggle("Animate", mod.animate); mod.speed = EditorGUILayout.FloatField("Speed", mod.speed); mod.drawpath = EditorGUILayout.Toggle("Draw Path", mod.drawpath); mod.tangent = EditorGUILayout.FloatField("Tangent", mod.tangent); mod.UseTwistCurve = EditorGUILayout.Toggle("Use Twist Curve", mod.UseTwistCurve); mod.twistCurve = EditorGUILayout.CurveField("Twist Curve", mod.twistCurve); mod.UseStretchCurve = EditorGUILayout.Toggle("Use Stretch Curve", mod.UseStretchCurve); mod.stretchCurve = EditorGUILayout.CurveField("Stretch Curve", mod.stretchCurve); mod.Up = EditorGUILayout.Vector3Field("Up", mod.Up); return(false); }
//void OnSceneGUI() //{ //PathDeform pd = (PathDeform)target; //Display(pd); //} public override bool Inspector() { MegaPathDeform mod = (MegaPathDeform)target; #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 EditorGUIUtility.LookLikeControls(); #endif mod.usedist = EditorGUILayout.Toggle("Use Distance", mod.usedist); if (mod.usedist) { mod.distance = EditorGUILayout.FloatField("Distance", mod.distance); } else { mod.percent = EditorGUILayout.FloatField("Percent", mod.percent); } //mod.percent = EditorGUILayout.FloatField("Percent", mod.percent); mod.stretch = EditorGUILayout.FloatField("Stretch", mod.stretch); mod.twist = EditorGUILayout.FloatField("Twist", mod.twist); mod.rotate = EditorGUILayout.FloatField("Rotate", mod.rotate); mod.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", mod.axis); mod.flip = EditorGUILayout.Toggle("Flip", mod.flip); mod.path = (MegaShape)EditorGUILayout.ObjectField("Path", mod.path, typeof(MegaShape), true); if (mod.path != null && mod.path.splines.Count > 1) { //shape.selcurve = EditorGUILayout.IntField("Curve", shape.selcurve); mod.curve = EditorGUILayout.IntSlider("Curve", mod.curve, 0, mod.path.splines.Count - 1); if (mod.curve < 0) { mod.curve = 0; } if (mod.curve > mod.path.splines.Count - 1) { mod.curve = mod.path.splines.Count - 1; } } mod.animate = EditorGUILayout.Toggle("Animate", mod.animate); mod.speed = EditorGUILayout.FloatField("Speed", mod.speed); mod.loopmode = (MegaLoopMode)EditorGUILayout.EnumPopup("Loop Mode", mod.loopmode); mod.drawpath = EditorGUILayout.Toggle("Draw Path", mod.drawpath); mod.tangent = EditorGUILayout.FloatField("Tangent", mod.tangent); mod.UseTwistCurve = EditorGUILayout.Toggle("Use Twist Curve", mod.UseTwistCurve); mod.twistCurve = EditorGUILayout.CurveField("Twist Curve", mod.twistCurve); mod.UseStretchCurve = EditorGUILayout.Toggle("Use Stretch Curve", mod.UseStretchCurve); mod.stretchCurve = EditorGUILayout.CurveField("Stretch Curve", mod.stretchCurve); mod.Up = EditorGUILayout.Vector3Field("Up", mod.Up); return(false); }
void Display(MegaPathDeform pd) { if (pd.path != null) { Matrix4x4 mat = pd.transform.localToWorldMatrix * pd.path.transform.localToWorldMatrix * pd.mat; for (int s = 0; s < pd.path.splines.Count; s++) { float ldist = pd.path.stepdist; if (ldist < 0.1f) { ldist = 0.1f; } float ds = pd.path.splines[s].length / (pd.path.splines[s].length / ldist); int c = 0; int k = -1; int lk = -1; Vector3 first = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref lk); for (float dist = ds; dist < pd.path.splines[s].length; dist += ds) { float alpha = dist / pd.path.splines[s].length; Vector3 pos = pd.path.splines[s].Interpolate(alpha, pd.path.normalizedInterp, ref k); if (k != lk) { for (lk = lk + 1; lk <= k; lk++) { Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pd.path.splines[s].knots[lk].p)); first = pd.path.splines[s].knots[lk].p; } } lk = k; Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); c++; first = pos; } if (pd.path.splines[s].closed) { Vector3 pos = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref k); Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); } } } }
void Display(MegaPathDeform pd) { if ( pd.path != null ) { Matrix4x4 mat = pd.transform.localToWorldMatrix * pd.path.transform.localToWorldMatrix * pd.mat; for ( int s = 0; s < pd.path.splines.Count; s++ ) { float ldist = pd.path.stepdist; if ( ldist < 0.1f ) ldist = 0.1f; float ds = pd.path.splines[s].length / (pd.path.splines[s].length / ldist); int c = 0; int k = -1; int lk = -1; Vector3 first = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref lk); for ( float dist = ds; dist < pd.path.splines[s].length; dist += ds ) { float alpha = dist / pd.path.splines[s].length; Vector3 pos = pd.path.splines[s].Interpolate(alpha, pd.path.normalizedInterp, ref k); if ( k != lk ) { for ( lk = lk + 1; lk <= k; lk++ ) { Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pd.path.splines[s].knots[lk].p)); first = pd.path.splines[s].knots[lk].p; } } lk = k; Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); c++; first = pos; } if ( pd.path.splines[s].closed ) { Vector3 pos = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref k); Handles.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); } } } }
// Mmm should be in gizmo code void Display(MegaPathDeform pd) { if (pd.path != null) { // Need to do a lookat on first point to get the direction pd.mat = Matrix4x4.identity; Vector3 p = pd.path.splines[0].knots[0].p; Vector3 p1 = pd.path.InterpCurve3D(0, 0.01f, pd.path.normalizedInterp); Vector3 up = Vector3.zero; switch (axis) { case MegaAxis.X: up = Vector3.left; break; case MegaAxis.Y: up = Vector3.back; break; case MegaAxis.Z: up = Vector3.up; break; } Quaternion lrot = Quaternion.identity; if (flip) { up = -up; } lrot = Quaternion.FromToRotation(p1 - p, up); pd.mat.SetTRS(Vector3.zero, lrot, Vector3.one); Matrix4x4 mat = pd.transform.localToWorldMatrix * pd.mat; for (int s = 0; s < pd.path.splines.Count; s++) { float ldist = pd.path.stepdist * 0.1f; if (ldist < 0.01f) { ldist = 0.01f; } float ds = pd.path.splines[s].length / (pd.path.splines[s].length / ldist); int c = 0; int k = -1; int lk = -1; Vector3 first = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref lk) - p; for (float dist = ds; dist < pd.path.splines[s].length; dist += ds) { float alpha = dist / pd.path.splines[s].length; Vector3 pos = pd.path.splines[s].Interpolate(alpha, pd.path.normalizedInterp, ref k) - p; if ((c & 1) == 1) { Gizmos.color = pd.path.col1; } else { Gizmos.color = pd.path.col2; } if (k != lk) { for (lk = lk + 1; lk <= k; lk++) { Gizmos.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pd.path.splines[s].knots[lk].p - p)); first = pd.path.splines[s].knots[lk].p - p; } } lk = k; Gizmos.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); c++; first = pos; } if ((c & 1) == 1) { Gizmos.color = pd.path.col1; } else { Gizmos.color = pd.path.col2; } if (pd.path.splines[s].closed) { Vector3 pos = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref k) - p; Gizmos.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); } } Vector3 p0 = pd.path.InterpCurve3D(0, (percent / 100.0f), pd.path.normalizedInterp) - p; p1 = pd.path.InterpCurve3D(0, (percent / 100.0f) + (tangent * 0.01f), pd.path.normalizedInterp) - p; Gizmos.color = Color.blue; Vector3 sz = new Vector3(pd.path.KnotSize * 0.01f, pd.path.KnotSize * 0.01f, pd.path.KnotSize * 0.01f); Gizmos.DrawCube(mat.MultiplyPoint(p0), sz); Gizmos.DrawCube(mat.MultiplyPoint(p1), sz); } }
// Mmm should be in gizmo code void Display(MegaPathDeform pd) { if ( pd.path != null ) { // Need to do a lookat on first point to get the direction pd.mat = Matrix4x4.identity; Vector3 p = pd.path.splines[curve].knots[0].p; Vector3 p1 = pd.path.InterpCurve3D(curve, 0.01f, pd.path.normalizedInterp); Vector3 up = Vector3.zero; switch ( axis ) { case MegaAxis.X: up = Vector3.left; break; case MegaAxis.Y: up = Vector3.back; break; case MegaAxis.Z: up = Vector3.up; break; } Quaternion lrot = Quaternion.identity; if ( flip ) up = -up; lrot = Quaternion.FromToRotation(p1 - p, up); pd.mat.SetTRS(Vector3.zero, lrot, Vector3.one); Matrix4x4 mat = pd.transform.localToWorldMatrix * pd.mat; for ( int s = 0; s < pd.path.splines.Count; s++ ) { float ldist = pd.path.stepdist * 0.1f; if ( ldist < 0.01f ) ldist = 0.01f; float ds = pd.path.splines[s].length / (pd.path.splines[s].length / ldist); int c = 0; int k = -1; int lk = -1; Vector3 first = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref lk) - p; for ( float dist = ds; dist < pd.path.splines[s].length; dist += ds ) { float alpha = dist / pd.path.splines[s].length; Vector3 pos = pd.path.splines[s].Interpolate(alpha, pd.path.normalizedInterp, ref k) - p; if ( (c & 1) == 1 ) Gizmos.color = pd.path.col1; else Gizmos.color = pd.path.col2; if ( k != lk ) { for ( lk = lk + 1; lk <= k; lk++ ) { Gizmos.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pd.path.splines[s].knots[lk].p - p)); first = pd.path.splines[s].knots[lk].p - p; } } lk = k; Gizmos.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); c++; first = pos; } if ( (c & 1) == 1 ) Gizmos.color = pd.path.col1; else Gizmos.color = pd.path.col2; if ( pd.path.splines[s].closed ) { Vector3 pos = pd.path.splines[s].Interpolate(0.0f, pd.path.normalizedInterp, ref k) - p; Gizmos.DrawLine(mat.MultiplyPoint(first), mat.MultiplyPoint(pos)); } } Vector3 p0 = pd.path.InterpCurve3D(curve, (percent / 100.0f), pd.path.normalizedInterp) - p; p1 = pd.path.InterpCurve3D(curve, (percent / 100.0f) + (tangent * 0.01f), pd.path.normalizedInterp) - p; Gizmos.color = Color.blue; Vector3 sz = new Vector3(pd.path.KnotSize * 0.01f, pd.path.KnotSize * 0.01f, pd.path.KnotSize * 0.01f); Gizmos.DrawCube(mat.MultiplyPoint(p0), sz); Gizmos.DrawCube(mat.MultiplyPoint(p1), sz); } }