public static void BuildRenderMesh(Transform parent, FunctionLineScript.LinePoints[] points, Material material, Color vectorColor) { Mesh m = new Mesh(); int tindex = 0; List <CylinderScript.Quad> qlist = new List <CylinderScript.Quad>(); for (int y = 0; y < points.Length - 1; y++) { for (int x = 0; x < points[y].Points.Length - 1; x++) { Vector3 tl = points[y].Points[x]; Vector3 tr = points[y].Points[x + 1]; Vector3 bl = points[y + 1].Points[x]; Vector3 br = points[y + 1].Points[x + 1]; CylinderScript.Quad q = CylinderScript.Quad.Build(tl, tr, bl, br, vectorColor, tindex); qlist.Add(q); tindex += 4; } } Vector3[] verts = new Vector3[qlist.Count * 4]; Vector3[] norms = new Vector3[qlist.Count * 4]; Color[] colors = new Color[qlist.Count * 4]; int[] tris = new int[qlist.Count * 6]; for (int z = 0; z < qlist.Count; z++) { qlist[z].Vertices.CopyTo(verts, z * 4); qlist[z].Normals.CopyTo(norms, z * 4); qlist[z].Colors.CopyTo(colors, z * 4); qlist[z].TriangleIndices.CopyTo(tris, z * 6); } m.vertices = verts; m.normals = norms; m.colors = colors; m.triangles = tris; m.RecalculateNormals(); m.RecalculateTangents(); m = FunctionLineScript.NormalSolver.RecalculateNormals(m, 75f); FunctionLineScript.CreateChildObject(parent, "Curve_0_Surface", m, material); //return m; }
void BuildMesh() { MajorLinePoints = new FunctionLineScript.LinePoints[1]; MajorLinePoints[0] = new FunctionLineScript.LinePoints(); float halfLength = AxisLength / 2f; MajorLinePoints[0].ArrowAtStart = true; MajorLinePoints[0].ArrowAtEnd = true; MajorLinePoints[0].ArrowLength = MajorAxisArrowLength; MajorLinePoints[0].ArrowRadius = MajorAxisArrowRadius; MajorLinePoints[0].Points = new Vector3[] { halfLength *AxisDirection, -1f *halfLength *AxisDirection }; FunctionLineScript.BuildMesh(this.transform, MajorLinePoints, MajorAxisMaterial, MajorAxisRadius, 32, 64, Color.white); MinorLinePoints = new FunctionLineScript.LinePoints[AxisSteps + 1]; OppositeMinorLinePoints = new FunctionLineScript.LinePoints[AxisSteps + 1]; for (int u = 0; u < AxisSteps + 1; u++) { float axisPoint = (float)u / (float)AxisSteps * AxisLength - halfLength; float minPoint = 0f / (float)AxisSteps * AxisLength - halfLength; float maxPoint = AxisLength - halfLength; Vector3 point1 = (axisPoint * AxisDirection) + (minPoint * OppositeAxisDirection); Vector3 point2 = (axisPoint * AxisDirection) + (maxPoint * OppositeAxisDirection); Vector3 opoint1 = (axisPoint * OppositeAxisDirection) + (minPoint * AxisDirection); Vector3 opoint2 = (axisPoint * OppositeAxisDirection) + (maxPoint * AxisDirection); MinorLinePoints[u] = new FunctionLineScript.LinePoints(); OppositeMinorLinePoints[u] = new FunctionLineScript.LinePoints(); MinorLinePoints[u].Points = new Vector3[] { point1, point2 }; OppositeMinorLinePoints[u].Points = new Vector3[] { opoint1, opoint2 }; } FunctionLineScript.BuildMesh(this.transform, MinorLinePoints, MinorAxisMaterial, MinorAxisRadius, 16, 32, Color.white); FunctionLineScript.BuildMesh(this.transform, OppositeMinorLinePoints, MinorAxisMaterial, MinorAxisRadius, 16, 32, Color.white); }