public static Polyline[] ExportRhinoPolylines(ITurtleMesh ngons) { var polylines = new Polyline[ngons.FaceCount]; for (int i = 0; i < ngons.FaceCount; i++) { var f = ngons.FaceAt(i); Polyline p = new Polyline(f.EdgesVerticesCount + 1); for (int j = 0; j < f.EdgesVerticesCount; j++) { var v = ngons.VertexAt(f[j]); p.Add(v.X, v.Y, v.Z); } var closure = ngons.VertexAt(f[0]); p.Add(closure.X, closure.Y, closure.Z); polylines[i] = p; } return(polylines); }
public static Polyline[] ExportRhinoPolylines(ITurtleMesh ngons) { var polylines = new Polyline[ngons.FaceCount]; for (int i = 0; i < ngons.FaceCount; i++) { var f = ngons.FaceAt(i); Polyline p = new Polyline(f.EdgesVerticesCount + 1); for (int j = 0; j < f.EdgesVerticesCount; j++) { var v = ngons.VertexAt(f[j]); p.Add(v.X, v.Y, v.Z); } var closure = ngons.VertexAt(f[0]); p.Add(closure.X, closure.Y, closure.Z); polylines[i] = p; } return polylines; }
public TurtleMesh(ITurtleMesh other) { if (other == null) throw new ArgumentNullException("other"); for (int i = 0; i < other.VertexCount; i++) { AddVertex(new TurtleVertex(other.VertexAt(i))); } for (int i = 0; i < other.FaceCount; i++) { AddFace(new TurtleFace(other.FaceAt(i))); } }
public TurtleMesh(ITurtleMesh other) { if (other == null) { throw new ArgumentNullException("other"); } for (int i = 0; i < other.VertexCount; i++) { AddVertex(new TurtleVertex(other.VertexAt(i))); } for (int i = 0; i < other.FaceCount; i++) { AddFace(new TurtleFace(other.FaceAt(i))); } }
public static TurtleMesh ExportFaceAt(ITurtleMesh m, int index) { var nm = new TurtleMesh(); var f = m.FaceAt(index); var nf = new TurtleFace(f.EdgesVerticesCount); for (int i = 0; i < f.EdgesVerticesCount; i++) { nm.AddVertex(new TurtleVertex(m.VertexAt(f[i]))); nf.Add(i); } nm.AddFace(nf); return(nm); }
public static TurtleMesh ExportFaceAt(ITurtleMesh m, int index) { var nm = new TurtleMesh(); var f = m.FaceAt(index); var nf = new TurtleFace(f.EdgesVerticesCount); for (int i = 0; i < f.EdgesVerticesCount; i++) { nm.AddVertex(new TurtleVertex(m.VertexAt(f[i]))); nf.Add(i); } nm.AddFace(nf); return nm; }
public static ITurtleVertex ComputeFaceVertexAvarage(ITurtleMesh t, int faceIndex) { var f = t.FaceAt(faceIndex); double x = 0, y = 0, z = 0; for (int i = 0; i < f.EdgesVerticesCount; i++) { var v = t.VertexAt(f[i]); x += v.X; y += v.Y; z += v.Z; } double inv = 1.0 / f.EdgesVerticesCount; return(new TurtleVertex( (float)(x * inv), (float)(y * inv), (float)(z * inv))); }
public static Mesh ExportTriangolatedRhinoMesh(ITurtleMesh ngons) { Mesh mesh = new Mesh(); var vs = mesh.Vertices; for (int i = 0; i < ngons.VertexCount; i++) { var v = ngons.VertexAt(i); vs.Add(v.X, v.Y, v.Z); } var fs = mesh.Faces; for (int i = 0; i < ngons.FaceCount; i++) { var f = ngons.FaceAt(i); switch (f.EdgesVerticesCount) { case 3: fs.AddFace(f[0], f[1], f[2]); break; case 4: fs.AddFace(f[0], f[1], f[2], f[3]); break; default: if (f.EdgesVerticesCount > 2) { var av = SpacialAnalysis.ComputeFaceVertexAvarage(ngons, i); int newIndex = vs.Count; vs.Add(av.X, av.Y, av.Z); for (int j = 0; j < f.EdgesVerticesCount; j++) { fs.AddFace(f[j], f[(j + 1) % f.EdgesVerticesCount], newIndex); } } break; } } return(mesh); }
public void AppendOther(ITurtleMesh other) { int s = _vertices.Count; for (int i = 0; i < other.VertexCount; i++) { _vertices.Add(new TurtleVertex(other.VertexAt(i))); } for (int i = 0; i < other.FaceCount; i++) { var of = other.FaceAt(i); var nf = new TurtleFace(of.EdgesVerticesCount); for (int j = 0; j < of.EdgesVerticesCount; j++) { nf.Add(of[j] + s); } _faces.Add(nf); } }
public static Mesh ExportTriangolatedRhinoMesh(ITurtleMesh ngons) { Mesh mesh = new Mesh(); var vs = mesh.Vertices; for (int i = 0; i < ngons.VertexCount; i++) { var v = ngons.VertexAt(i); vs.Add(v.X, v.Y, v.Z); } var fs = mesh.Faces; for (int i = 0; i < ngons.FaceCount; i++) { var f = ngons.FaceAt(i); switch (f.EdgesVerticesCount) { case 3: fs.AddFace(f[0], f[1], f[2]); break; case 4: fs.AddFace(f[0], f[1], f[2], f[3]); break; default: if(f.EdgesVerticesCount > 2) { var av = SpacialAnalysis.ComputeFaceVertexAvarage(ngons, i); int newIndex = vs.Count; vs.Add(av.X, av.Y, av.Z); for (int j = 0; j < f.EdgesVerticesCount; j++) { fs.AddFace(f[j], f[(j + 1) % f.EdgesVerticesCount], newIndex); } } break; } } return mesh; }
public static void ComputeBoundingBox(ITurtleMesh m, out ITurtleVertex min, out ITurtleVertex max) { var minV = new TurtleVertex(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); var maxV = new TurtleVertex(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); for (int i = 0; i < m.VertexCount; i++) { var v = m.VertexAt(i); if (minV.X > v.X) { minV.X = v.X; } if (minV.Y > v.Y) { minV.Y = v.Y; } if (minV.Z > v.Z) { minV.Z = v.Z; } if (maxV.X < v.X) { maxV.X = v.X; } if (maxV.Y < v.Y) { maxV.Y = v.Y; } if (maxV.Z < v.Z) { maxV.Z = v.Z; } } min = minV; max = maxV; }
public static void Write(ITurtleMesh mesh, TextWriter sw) { sw.WriteLine("# OBJ file written by TurtleMesh"); var ci = System.Globalization.CultureInfo.InvariantCulture; sw.WriteLine("# " + mesh.VertexCount.ToString(ci) + " vertices"); for (int i = 0; i < mesh.VertexCount; i++) { var v = mesh.VertexAt(i); sw.Write("v "); sw.Write(v.X.ToString("r", ci)); sw.Write(" "); sw.Write(v.Y.ToString("r", ci)); sw.Write(" "); sw.WriteLine(v.Z.ToString("r", ci)); } sw.WriteLine("# " + mesh.FaceCount.ToString(ci) + " faces"); for (int i = 0; i < mesh.FaceCount; i++) { var f = mesh.FaceAt(i); sw.Write("f"); for (int j = 0; j < f.EdgesVerticesCount; j++) { sw.Write(" "); sw.Write((f[j] + 1).ToString(ci)); } sw.WriteLine(); } sw.WriteLine("# end of OBJ file"); sw.Flush(); sw.Close(); }
public void AppendOther(ITurtleMesh other) { int s = _vertices.Count; for (int i = 0; i < other.VertexCount; i++) _vertices.Add(new TurtleVertex(other.VertexAt(i))); for (int i = 0; i < other.FaceCount; i++) { var of = other.FaceAt(i); var nf = new TurtleFace(of.EdgesVerticesCount); for(int j=0; j<of.EdgesVerticesCount; j++) { nf.Add(of[j] + s); } _faces.Add(nf); } }