예제 #1
0
        public Edge CreateEdge()
        {
            Edge e = OwnerMesh.CreateEdge();

            AddEdge(e);
            return(e);
        }
예제 #2
0
파일: Edge.cs 프로젝트: wibble82/mmbot
        public Edge Split(double split_param)
        {
            //calculate position of new vertex
            Point3D p0     = Vertices[0].Pos;
            Point3D p1     = Vertices[1].Pos;
            Point3D splitp = p0 + (p1 - p0) * split_param;

            //create the new vertex and set it up
            Vertex first_vertex = Vertices[0];
            Vertex last_vertex  = Vertices[1];
            Vertex new_vertex   = OwnerMesh.CreateVertex();

            new_vertex.Pos = splitp;                        //it's at the split point

            //create new edge
            Edge new_edge = OwnerMesh.CreateEdge();

            //link new vert/edge into owning faces
            foreach (Face f in OwnerFaces)
            {
                f.AddVertex(new_vertex);
                f.InsertEdge(new_edge, this);
            }

            //fix up the new edges
            SetVertex(0, first_vertex);
            SetVertex(1, new_vertex);
            new_edge.SetVertex(0, new_vertex);
            new_edge.SetVertex(1, last_vertex);

            return(new_edge);
        }
예제 #3
0
        public void TransferFaceTo(Face f, Mesh mesh)
        {
            if (mesh.Shape != Shape)
            {
                throw new System.ApplicationException("Can not transfer faces between shapes");
            }

            //transfer the face
            Faces.Remove(f);
            mesh.Faces.Add(f);
            f.OwnerMesh = mesh;

            //go over each edge in the face and copy it over
            for (int edgeidx = 0; edgeidx < f.Edges.Count; edgeidx++)
            {
                //get the edge and remove the face from it
                Edge e = f.Edges[edgeidx];
                e.OwnerFaces.Remove(f);

                //create a new edge and replace it
                Edge newedge = mesh.CreateEdge();
                newedge.OwnerFaces.Add(f);
                f.Edges[edgeidx] = newedge;

                //set the 2 vertex references
                newedge.SetVertex(0, e.Vertices[0]);
                newedge.SetVertex(1, e.Vertices[1]);
            }
        }
예제 #4
0
파일: Mesh.cs 프로젝트: wibble82/mmbot
        public void TransferFaceTo(Face f, Mesh mesh)
        {
            if (mesh.Shape != Shape)
                throw new System.ApplicationException("Can not transfer faces between shapes");

            //transfer the face
            Faces.Remove(f);
            mesh.Faces.Add(f);
            f.OwnerMesh = mesh;

            //go over each edge in the face and copy it over
            for(int edgeidx = 0; edgeidx < f.Edges.Count; edgeidx++)
            {
                //get the edge and remove the face from it
                Edge e = f.Edges[edgeidx];
                e.OwnerFaces.Remove(f);

                //create a new edge and replace it
                Edge newedge = mesh.CreateEdge();
                newedge.OwnerFaces.Add(f);
                f.Edges[edgeidx] = newedge;

                //set the 2 vertex references
                newedge.SetVertex(0, e.Vertices[0]);
                newedge.SetVertex(1, e.Vertices[1]);
            }
        }
예제 #5
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);
        }