void DrawMultiSelect() { Handles.color = Color.blue; for (int i = 0; i < selectedKnots.Count; i++) { if (Handles.Button(spline.transform.TransformPoint(spline.GetKnot(selectedKnots[i]).position), Camera.current.transform.rotation, handleSize, handleSize, Handles.CircleHandleCap)) { SelectKnot(selectedKnots[i], true); } } Vector3 handlePos = Vector3.zero; if (Tools.pivotMode == PivotMode.Center) { for (int i = 0; i < selectedKnots.Count; i++) { handlePos += spline.GetKnot(selectedKnots[i]).position; } handlePos /= selectedKnots.Count; } else { handlePos = spline.GetKnot(activeKnot).position; } handlePos = spline.transform.TransformPoint(handlePos); Handles.PositionHandle(handlePos, Tools.handleRotation); }
public override object GetValue(NodePort port) { object o = base.GetValue(port); if (o != null) { return(o); } float resolution = 0; object obj = GetInputByFieldName("resolution").GetInputValue(); if (obj != null) { resolution = (float)obj; } else { resolution = this.resolution; } Bezier3DSpline spline; if (GetInputByFieldName("spline").TryGetInputValue(out spline)) { List <Vector2> points = new List <Vector2>(); for (int i = 0; i < spline.KnotCount; i++) { Vector3 pos = spline.GetKnot(i).position; points.Add(new Vector2(pos.x, pos.z)); Bezier3DCurve curve = spline.GetCurve(i); if (!curve.isLinear) { for (int k = 1; k < resolution; k++) { float t = (float)k / resolution; pos = curve.GetPoint(t); points.Add(new Vector2(pos.x, pos.z)); } } } int[] tris = Triangulate(points); List <Vector3> verts = points.Select(x => new Vector3(x.x, 0, x.y)).ToList(); List <Vector3> norms = points.Select(x => Vector3.up).ToList(); Mesh mesh = new Mesh(); mesh.vertices = verts.ToArray(); mesh.triangles = tris; mesh.normals = norms.ToArray(); List <Model> output = new List <Model>(); Material mat = GetInputByFieldName("material").GetInputValue() as Material; Material[] mats = new Material[] { mat }; output.Add(new Model(mesh, mats)); return(output); } return(null); }
override public void OnInspectorGUI() { Bezier3DSpline spline = target as Bezier3DSpline; ValidateSelected(); EditorGUILayout.LabelField("Spline settings"); EditorGUI.indentLevel = 1; EditorGUI.BeginChangeCheck(); int steps = spline.cacheDensity; steps = EditorGUILayout.DelayedIntField("Cache density", steps); if (EditorGUI.EndChangeCheck()) { spline.SetCacheDensity(steps); if (onUpdateSpline != null) { onUpdateSpline(spline); } } EditorGUI.BeginChangeCheck(); bool closed = spline.closed; closed = EditorGUILayout.Toggle(new GUIContent("Closed", "Generate an extra curve, connecting the final point to the first point."), closed); if (EditorGUI.EndChangeCheck()) { spline.SetClosed(closed); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } Rect position = EditorGUILayout.GetControlRect(false, 19f, EditorStyles.numberField); position.xMin += EditorGUIUtility.labelWidth; Rect flipRect = new Rect(position.x, position.y, position.width, position.height); if (GUI.Button(flipRect, new GUIContent("Flip", "Flip spline direction."))) { spline.Flip(); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.indentLevel = 0; EditorGUILayout.Space(); if (activeKnot != -1) { EditorGUILayout.LabelField("Selected point"); EditorGUI.indentLevel = 1; Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); position = EditorGUILayout.GetControlRect(false, 19f, EditorStyles.numberField); position.xMin += EditorGUIUtility.labelWidth; EditorGUI.BeginChangeCheck(); bool orientation = knot.orientation != null; Rect orientationRect = new Rect(position.x, position.y, position.height, position.height); orientation = GUI.Toggle(orientationRect, orientation, new GUIContent("O", "Orientation Anchor"), "Button"); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Toggle Bezier Orientation Anchor"); if (orientation) { knot.orientation = Quaternion.identity; } else { knot.orientation = null; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); bool auto = knot.auto != 0f; Rect autoRect = new Rect(position.x + position.height + 4, position.y, position.height, position.height); auto = GUI.Toggle(autoRect, auto, new GUIContent("A", "Auto Handles"), "Button"); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Toggle Bezier Auto Handles"); if (auto) { knot.auto = 0.33f; } else { knot.auto = 0f; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } if (orientation) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); Vector3 orientationEuler = knot.orientation.Value.eulerAngles; orientationEuler = EditorGUILayout.Vector3Field("Orientation", orientationEuler); if (EditorGUI.EndChangeCheck()) { knot.orientation = Quaternion.Euler(orientationEuler); spline.SetKnot(activeKnot, knot); SceneView.RepaintAll(); } } if (auto) { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); knot.position = EditorGUILayout.Vector3Field("Position", knot.position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Point"); spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); knot.auto = EditorGUILayout.FloatField("Distance", knot.auto); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Point"); spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } } else { EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); knot.position = EditorGUILayout.Vector3Field("Position", knot.position); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Point"); spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); knot.handleIn = EditorGUILayout.Vector3Field("Handle in", knot.handleIn); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Handle"); if (mirror) { knot.handleOut = -knot.handleIn; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } EditorGUI.BeginChangeCheck(); knot.handleOut = EditorGUILayout.Vector3Field("Handle out", knot.handleOut); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(spline, "Edit Bezier Handle"); if (mirror) { knot.handleIn = -knot.handleOut; } spline.SetKnot(activeKnot, knot); if (onUpdateSpline != null) { onUpdateSpline(spline); } SceneView.RepaintAll(); } } } }