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); }
void DrawSelectedSplitters() { Handles.color = Color.white; //Start add if (!spline.closed && activeKnot == 0) { Bezier3DCurve curve = spline.GetCurve(0); Vector3 a = spline.transform.TransformPoint(curve.a), b = spline.transform.TransformDirection(curve.b.normalized) * 2f; float handleScale = HandleUtility.GetHandleSize(a); b *= handleScale; Handles.DrawDottedLine(a, a - b, 3f); if (Handles.Button(a - b, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); spline.InsertKnot(0, new Bezier3DSpline.Knot(curve.a - (curve.b.normalized * handleScale * 2), Vector3.zero, curve.b.normalized * 0.5f, knot.auto, knot.orientation)); if (onUpdateSpline != null) { onUpdateSpline(spline); } } } //End add if (!spline.closed && activeKnot == spline.CurveCount) { Bezier3DCurve curve = spline.GetCurve(spline.CurveCount - 1); Vector3 c = spline.transform.TransformDirection(curve.c.normalized) * 2f, d = spline.transform.TransformPoint(curve.d); float handleScale = HandleUtility.GetHandleSize(d); c *= handleScale; Handles.DrawDottedLine(d, d - c, 3f); if (Handles.Button(d - c, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); spline.AddKnot(new Bezier3DSpline.Knot(curve.d - (curve.c.normalized * handleScale * 2), curve.c.normalized * 0.5f, Vector3.zero, knot.auto, knot.orientation)); SelectKnot(spline.CurveCount, false); if (onUpdateSpline != null) { onUpdateSpline(spline); } } } // Prev split if (spline.closed || activeKnot != 0) { Bezier3DCurve curve = spline.GetCurve(activeKnot == 0 ? spline.CurveCount - 1 : activeKnot - 1); Vector3 centerLocal = curve.GetPoint(curve.Dist2Time(curve.length * 0.5f)); Vector3 center = spline.transform.TransformPoint(centerLocal); Vector3 a = curve.a + curve.b; Vector3 b = curve.c + curve.d; Vector3 ab = (b - a) * 0.3f; float handleScale = HandleUtility.GetHandleSize(center); if (Handles.Button(center, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); Bezier3DSpline.Knot knot = spline.GetKnot(activeKnot); spline.InsertKnot(activeKnot == 0 ? spline.CurveCount : activeKnot, new Bezier3DSpline.Knot(centerLocal, -ab, ab, knot.auto, knot.orientation)); if (activeKnot == 0) { SelectKnot(spline.CurveCount - 1, false); } if (onUpdateSpline != null) { onUpdateSpline(spline); } } } // Next split if (activeKnot != spline.CurveCount) { Bezier3DCurve curve = spline.GetCurve(activeKnot); Vector3 centerLocal = curve.GetPoint(curve.Dist2Time(curve.length * 0.5f)); Vector3 center = spline.transform.TransformPoint(centerLocal); Vector3 a = curve.a + curve.b; Vector3 b = curve.c + curve.d; Vector3 ab = (b - a) * 0.3f; float handleScale = HandleUtility.GetHandleSize(center); if (Handles.Button(center, Camera.current.transform.rotation, handleScale * handleSize * 0.4f, handleScale * handleSize * 0.4f, Handles.DotHandleCap)) { Undo.RecordObject(spline, "Add Bezier Point"); spline.InsertKnot(activeKnot + 1, new Bezier3DSpline.Knot(centerLocal, -ab, ab)); SelectKnot(activeKnot + 1, false); if (onUpdateSpline != null) { onUpdateSpline(spline); } } } }