private byte[] GetVerticesBytes(Rhino.Geometry.Collections.MeshVertexList vertices, out Point3d min, out Point3d max) { var vtxMin = new Point3d() { X = Double.PositiveInfinity, Y = Double.PositiveInfinity, Z = Double.PositiveInfinity }; var vtxMax = new Point3d() { X = Double.NegativeInfinity, Y = Double.NegativeInfinity, Z = Double.NegativeInfinity }; //Preallocate to reduce time spent on allocations List <float> floats = new List <float>(vertices.Count * 3); foreach (Point3d vertex in vertices) { floats.AddRange(new float[] { (float)vertex.X, (float)vertex.Y, (float)vertex.Z }); vtxMin.X = Math.Min(vtxMin.X, vertex.X); vtxMax.X = Math.Max(vtxMax.X, vertex.X); vtxMin.Y = Math.Min(vtxMin.Y, vertex.Y); vtxMax.Y = Math.Max(vtxMax.Y, vertex.Y); vtxMin.Z = Math.Min(vtxMin.Z, vertex.Z); vtxMax.Z = Math.Max(vtxMax.Z, vertex.Z); } min = vtxMin; max = vtxMax; IEnumerable <byte> bytesEnumerable = floats.SelectMany(value => BitConverter.GetBytes(value)); return(bytesEnumerable.ToArray()); }
glTFLoader.Schema.Buffer CreateVerticesBuffer(Rhino.Geometry.Collections.MeshVertexList vertices, out Point3d min, out Point3d max) { byte[] bytes = GetVerticesBytes(vertices, out min, out max); return(new glTFLoader.Schema.Buffer() { Uri = Constants.TextBufferHeader + Convert.ToBase64String(bytes), ByteLength = bytes.Length, }); }
public Point3d pos(Rhino.Geometry.Collections.MeshVertexList vs) { List <Point3d> ps = new List <Point3d>(); for (int i = 0; i < vs.Count; i++) { ps.Add((Point3d)vs[i]); } return(pos(ps)); }
//private PolyMesh MeshConnector(List<Circle> Circles, List<int> Values, ref List<Point3d> LargeCircleDivision, ref List<Point3d> MiddleCircleDivision, ref List<Point3d> SmallCircleDivision) { // Circle item; // int num = 0; // do { // Circle circle = Circles[num]; // circle.Reverse(); // Circles[num] = circle; // num = checked(num + 1); // } // while (num <= 1); // PolyMesh polyMesh = new PolyMesh(); // PolyMesh polyMesh1 = new PolyMesh(); // List<Point3d> point3ds = new List<Point3d>(); // List<Point3d> point3ds1 = new List<Point3d>(); // List<Point3d> point3ds2 = new List<Point3d>(); // int item1 = Values[0]; // for (int i = 0; i <= item1; i = checked(i + 1)) { // PolyVertexList vertices = polyMesh.Vertices; // item = Circles[0]; // vertices.Add(item.PointAt((double)i / (double)Values[0] * 3.14159265358979 * 2)); // if (i < Values[0]) { // item = Circles[0]; // point3ds2.Add(item.PointAt((double)i / (double)Values[0] * 3.14159265358979 * 2)); // } // } // int num1 = Values[0]; // for (int j = 0; j <= num1; j = checked(j + 1)) { // PolyVertexList polyVertexList = polyMesh.Vertices; // item = Circles[2]; // polyVertexList.Add(item.PointAt((double)j / (double)Values[0] * 3.14159265358979)); // } // int item2 = checked(Values[0] - 1); // for (int k = 0; k <= item2; k = checked(k + 1)) { // polyMesh.Faces.Add((IEnumerable<int>)(new int[] { k, checked(checked(k + Values[0]) + 1), checked(checked(k + Values[0]) + 2), checked(k + 1) })); // } // int num2 = Values[1]; // for (int l = 0; l <= num2; l = checked(l + 1)) { // PolyVertexList vertices1 = polyMesh1.Vertices; // item = Circles[1]; // vertices1.Add(item.PointAt((double)l / (double)Values[1] * 3.14159265358979 * 2)); // if (l < Values[1]) { // item = Circles[1]; // point3ds1.Add(item.PointAt((double)l / (double)Values[1] * 3.14159265358979 * 2)); // } // } // int item3 = Values[1]; // for (int m = 0; m <= item3; m = checked(m + 1)) { // PolyVertexList polyVertexList1 = polyMesh1.Vertices; // item = Circles[2]; // polyVertexList1.Add(item.PointAt((double)m / (double)Values[1] * 3.14159265358979 + 3.14159265358979)); // } // int num3 = checked(Values[0] - 1); // for (int n = 0; n <= num3; n = checked(n + 1)) { // item = Circles[2]; // point3ds.Add(item.PointAt((double)n / (double)Values[0] * 3.14159265358979)); // } // int item4 = checked(Values[1] - 1); // for (int o = 0; o <= item4; o = checked(o + 1)) { // item = Circles[2]; // point3ds.Add(item.PointAt((double)o / (double)Values[1] * 3.14159265358979 + 3.14159265358979)); // } // int num4 = checked(Values[1] - 1); // for (int p = 0; p <= num4; p = checked(p + 1)) { // polyMesh1.Faces.Add((IEnumerable<int>)(new int[] { p, checked(checked(p + Values[1]) + 1), checked(checked(p + Values[1]) + 2), checked(p + 1) })); // } // polyMesh.Append(polyMesh1); // LargeCircleDivision = point3ds; // MiddleCircleDivision = point3ds1; // SmallCircleDivision = point3ds2; // return polyMesh; //} private Mesh MeshConnector(List <Circle> Circles, List <int> Values, ref List <Point3d> LargeCircleDivision, ref List <Point3d> MiddleCircleDivision, ref List <Point3d> SmallCircleDivision) { Circle item; int num = 0; do { Circle circle = Circles[num]; circle.Reverse(); Circles[num] = circle; num = checked (num + 1); }while (num <= 1); Mesh polyMesh = new Mesh(); Mesh polyMesh1 = new Mesh(); List <Point3d> point3ds = new List <Point3d>(); List <Point3d> point3ds1 = new List <Point3d>(); List <Point3d> point3ds2 = new List <Point3d>(); int item1 = Values[0]; for (int i = 0; i <= item1; i = checked (i + 1)) { Rhino.Geometry.Collections.MeshVertexList vertices = polyMesh.Vertices; item = Circles[0]; vertices.Add(item.PointAt((double)i / (double)Values[0] * 3.14159265358979 * 2)); if (i < Values[0]) { item = Circles[0]; point3ds2.Add(item.PointAt((double)i / (double)Values[0] * 3.14159265358979 * 2)); } } int num1 = Values[0]; for (int j = 0; j <= num1; j = checked (j + 1)) { Rhino.Geometry.Collections.MeshVertexList polyVertexList = polyMesh.Vertices; item = Circles[2]; polyVertexList.Add(item.PointAt((double)j / (double)Values[0] * 3.14159265358979)); } int item2 = checked (Values[0] - 1); for (int k = 0; k <= item2; k = checked (k + 1)) { polyMesh.AddFace((IEnumerable <int>)(new int[] { k, checked (checked (k + Values[0]) + 1), checked (checked (k + Values[0]) + 2), checked (k + 1) })); } int num2 = Values[1]; for (int l = 0; l <= num2; l = checked (l + 1)) { Rhino.Geometry.Collections.MeshVertexList vertices1 = polyMesh1.Vertices; item = Circles[1]; vertices1.Add(item.PointAt((double)l / (double)Values[1] * 3.14159265358979 * 2)); if (l < Values[1]) { item = Circles[1]; point3ds1.Add(item.PointAt((double)l / (double)Values[1] * 3.14159265358979 * 2)); } } int item3 = Values[1]; for (int m = 0; m <= item3; m = checked (m + 1)) { Rhino.Geometry.Collections.MeshVertexList polyVertexList1 = polyMesh1.Vertices; item = Circles[2]; polyVertexList1.Add(item.PointAt((double)m / (double)Values[1] * 3.14159265358979 + 3.14159265358979)); } int num3 = checked (Values[0] - 1); for (int n = 0; n <= num3; n = checked (n + 1)) { item = Circles[2]; point3ds.Add(item.PointAt((double)n / (double)Values[0] * 3.14159265358979)); } int item4 = checked (Values[1] - 1); for (int o = 0; o <= item4; o = checked (o + 1)) { item = Circles[2]; point3ds.Add(item.PointAt((double)o / (double)Values[1] * 3.14159265358979 + 3.14159265358979)); } int num4 = checked (Values[1] - 1); for (int p = 0; p <= num4; p = checked (p + 1)) { polyMesh1.AddFace((IEnumerable <int>)(new int[] { p, checked (checked (p + Values[1]) + 1), checked (checked (p + Values[1]) + 2), checked (p + 1) })); } polyMesh.Append(polyMesh1); LargeCircleDivision = point3ds; MiddleCircleDivision = point3ds1; SmallCircleDivision = point3ds2; return(polyMesh); }