Ejemplo n.º 1
0
        private void CreateTriangleFace(List <Edge> existingEdges, Shape subdivided, Face face)
        {
            List <Point> points = face.AllPoints;
            Point        a      = points[0].Successor;
            Point        b      = points[1].Successor;
            Point        c      = points[2].Successor;

            //for a triangle face (a,b,c):
            //   (a, edge_pointab, face_pointabc, edge_pointca)
            //   (b, edge_pointbc, face_pointabc, edge_pointab)
            //   (c, edge_pointca, face_pointabc, edge_pointbc)
            Point facePoint = face.FacePoint;

            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, a, face.Edges[0].EdgePoint, face.Edges[2].EdgePoint));
            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, b, face.Edges[1].EdgePoint, face.Edges[0].EdgePoint));
            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, c, face.Edges[2].EdgePoint, face.Edges[1].EdgePoint));
            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, face.Edges[0].EdgePoint, face.Edges[1].EdgePoint, face.Edges[2].EdgePoint));

            SubdivisionUtilities.VerifyThatThereAreNoEdgeDuplicates(existingEdges);
        }
        public Shape BuildBox(double x, double y, double z)
        {
            Shape shape = new Shape();

            Point[,,] points = CreateBoxPoints(x, y, z);
            List <Edge> edges = new List <Edge>();

            // Using OGRE which uses counter clockwise winding / anti clickwise winding. Our faces are thus CCW.
            // http://www.ogre3d.org/docs/api/html/classOgre_1_1ManualObject.html
            // This is important for determining frontfacing and backfacing faces.
            // Get it wrong and faces become invisible and the manifold is broken.
            shape.AddFace(SubdivisionUtilities.CreateFaceF(edges, points[0, 0, 0], points[1, 0, 0], points[1, 0, 1], points[0, 0, 1]));
            shape.AddFace(SubdivisionUtilities.CreateFaceR(edges, points[0, 1, 0], points[1, 1, 0], points[1, 1, 1], points[0, 1, 1]));

            shape.AddFace(SubdivisionUtilities.CreateFaceF(edges, points[0, 0, 0], points[0, 1, 0], points[1, 1, 0], points[1, 0, 0]));
            shape.AddFace(SubdivisionUtilities.CreateFaceR(edges, points[0, 0, 1], points[0, 1, 1], points[1, 1, 1], points[1, 0, 1]));

            shape.AddFace(SubdivisionUtilities.CreateFaceR(edges, points[0, 0, 0], points[0, 1, 0], points[0, 1, 1], points[0, 0, 1]));
            shape.AddFace(SubdivisionUtilities.CreateFaceR(edges, points[1, 0, 0], points[1, 0, 1], points[1, 1, 1], points[1, 1, 0]));
            return(shape);
        }
Ejemplo n.º 3
0
        private void CreateFaces(Shape shape, Shape subdivided)
        {
            List <Face> faces         = shape.Faces;
            List <Edge> existingEdges = new List <Edge>();

            foreach (Face face in faces)
            {
                if (face.AllPoints.Count() == 3)
                {
                    CreateTriangleFace(existingEdges, subdivided, face);
                }
                else if (face.AllPoints.Count() == 4)
                {
                    CreateQuadFace(existingEdges, subdivided, face);
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unhandled facetype (point count={0})!", face.AllPoints.Count()));
                }
            }
            SubdivisionUtilities.VerifyThatThereAreNoEdgeDuplicates(existingEdges);
        }
Ejemplo n.º 4
0
        private void CreateQuadFace(List <Edge> existingEdges, Shape subdivided, Face face)
        {
            //                  0 1 2 -> 3
            //for a quad face (a,b,c,d):
            //   (a, edge_pointab, face_pointabcd, edge_pointda)
            //   (b, edge_pointbc, face_pointabcd, edge_pointab)
            //   (c, edge_pointcd, face_pointabcd, edge_pointbc)
            //   (d, edge_pointda, face_pointabcd, edge_pointcd)
            List <Point> points = face.AllPoints;
            Point        a      = points[0].Successor;
            Point        b      = points[1].Successor;
            Point        c      = points[2].Successor;
            Point        d      = points[3].Successor;

            Point facePoint = face.FacePoint;

            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, a, face.Edges[0].EdgePoint, facePoint, face.Edges[3].EdgePoint));
            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, b, face.Edges[1].EdgePoint, facePoint, face.Edges[0].EdgePoint));
            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, c, face.Edges[2].EdgePoint, facePoint, face.Edges[1].EdgePoint));
            subdivided.Faces.Add(SubdivisionUtilities.CreateFaceF(existingEdges, d, face.Edges[3].EdgePoint, facePoint, face.Edges[2].EdgePoint));

            SubdivisionUtilities.VerifyThatThereAreNoEdgeDuplicates(existingEdges);
        }