public static Shape Rectangle(Vector3D size) { Shape s = new Shape(); Mesh m = s.CreateConvex(); Face f = m.CreateFace(4); Vector3D halfsize = size*0.5; f.Vertices[0].Pos = new Point3D(-halfsize.X, -halfsize.Y, 0); f.Vertices[1].Pos = new Point3D(-halfsize.X, halfsize.Y, 0); f.Vertices[2].Pos = new Point3D( halfsize.X, halfsize.Y, 0); f.Vertices[3].Pos = new Point3D( halfsize.X, -halfsize.Y, 0); return s; }
public static Shape Rectangle(Vector3D size) { Shape s = new Shape(); Mesh m = s.CreateConvex(); Face f = m.CreateFace(4); Vector3D halfsize = size * 0.5; f.Vertices[0].Pos = new Point3D(-halfsize.X, -halfsize.Y, 0); f.Vertices[1].Pos = new Point3D(-halfsize.X, halfsize.Y, 0); f.Vertices[2].Pos = new Point3D(halfsize.X, halfsize.Y, 0); f.Vertices[3].Pos = new Point3D(halfsize.X, -halfsize.Y, 0); return(s); }
public void Clip2d(Mesh clip_mesh, List <Mesh> outside) { Mesh new_mesh = Shape.CreateConvex(); foreach (Edge clip_edge in clip_mesh.Edges) { Point3D raystart = clip_edge.Vertices[0].Pos; Vector3D raydir = clip_edge.Direction; Split2d(raystart, raydir, ESplitMode.KEEP_INSIDE, new_mesh); if (new_mesh.Faces.Count != 0) { } } }
public Shape Copy() { //create a new shape and copy the vertices Shape shape = new Shape(); foreach (Vertex v in Vertices) { Vertex copy = shape.CreateVertex(); copy.Pos = v.Pos; } //put new vertices in a quick look up table Vertex[] newverts = shape.Vertices.ToArray(); //go over each convex foreach (Mesh c in Convexes) { //create a new convex in the new shape Mesh convexcopy = shape.CreateConvex(); //copy edges foreach (Edge e in c.Edges) { //create the edge and use look up table to build new vertex list Edge edgecopy = convexcopy.CreateEdge(); edgecopy.Vertices = e.Vertices.Select(a => newverts[a.Idx]).ToArray(); //add this edge to each of the vertices it uses foreach (Vertex v in edgecopy.Vertices) v.OwnerEdges.Add(edgecopy); } //build look up table for the edges Edge[] newedges = convexcopy.Edges.ToArray(); //copy faces foreach (Face f in c.Faces) { //create the face and use look up tables to build new vertex/edge list Face facecopy = convexcopy.CreateFace(); facecopy.Vertices = f.Vertices.Select(a => newverts[a.Idx]).ToList(); facecopy.Edges = f.Edges.Select(a => newedges[a.Idx]).ToList(); //add this face to each of the vertices it uses foreach (Vertex v in facecopy.Vertices) v.OwnerFaces.Add(facecopy); //add this face to each of the edges it uses foreach (Edge e in facecopy.Edges) e.OwnerFaces.Add(facecopy); } } return shape; }
public Shape Copy() { //create a new shape and copy the vertices Shape shape = new Shape(); foreach (Vertex v in Vertices) { Vertex copy = shape.CreateVertex(); copy.Pos = v.Pos; } //put new vertices in a quick look up table Vertex[] newverts = shape.Vertices.ToArray(); //go over each convex foreach (Mesh c in Convexes) { //create a new convex in the new shape Mesh convexcopy = shape.CreateConvex(); //copy edges foreach (Edge e in c.Edges) { //create the edge and use look up table to build new vertex list Edge edgecopy = convexcopy.CreateEdge(); edgecopy.Vertices = e.Vertices.Select(a => newverts[a.Idx]).ToArray(); //add this edge to each of the vertices it uses foreach (Vertex v in edgecopy.Vertices) { v.OwnerEdges.Add(edgecopy); } } //build look up table for the edges Edge[] newedges = convexcopy.Edges.ToArray(); //copy faces foreach (Face f in c.Faces) { //create the face and use look up tables to build new vertex/edge list Face facecopy = convexcopy.CreateFace(); facecopy.Vertices = f.Vertices.Select(a => newverts[a.Idx]).ToList(); facecopy.Edges = f.Edges.Select(a => newedges[a.Idx]).ToList(); //add this face to each of the vertices it uses foreach (Vertex v in facecopy.Vertices) { v.OwnerFaces.Add(facecopy); } //add this face to each of the edges it uses foreach (Edge e in facecopy.Edges) { e.OwnerFaces.Add(facecopy); } } } return(shape); }