예제 #1
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);
        }
예제 #2
0
파일: Shape.cs 프로젝트: wibble82/mmbot
        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;
        }
예제 #3
0
        //public Point3D Centre { get { return MathUtils.Centre(Vertices.Select(a => a.Pos)); } }
        //public Point3D Min { get { return MathUtils.Min(Vertices.Select(a => a.Pos)); } }
        //public Point3D Max { get { return MathUtils.Max(Vertices.Select(a => a.Pos)); } }

        public Vertex CreateVertex()
        {
            Vertex v = Shape.CreateVertex();

            return(v);
        }