Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <c>Face3D</c> class.
 /// </summary>
 /// <param name="firstVertex">Face3D <see cref="Vector3">first vertex</see>.</param>
 /// <param name="secondVertex">Face3D <see cref="Vector3">second vertex</see>.</param>
 /// <param name="thirdVertex">Face3D <see cref="Vector3">third vertex</see>.</param>
 /// <param name="fourthVertex">Face3D <see cref="Vector3">fourth vertex</see>.</param>
 public Face3D(Vector3 firstVertex, Vector3 secondVertex, Vector3 thirdVertex, Vector3 fourthVertex)
     : base(EntityType.Face3D, DxfObjectCode.Face3d)
 {
     this.firstVertex  = firstVertex;
     this.secondVertex = secondVertex;
     this.thirdVertex  = thirdVertex;
     this.fourthVertex = fourthVertex;
     this.edgeFlags    = Face3DEdgeFlags.None;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Decompose the actual polyface mesh faces in <see cref="Point">points</see> (one vertex polyface mesh face),
        /// <see cref="Line">lines</see> (two vertexes polyface mesh face) and <see cref="Face3D">3d faces</see> (three or four vertexes polyface mesh face).
        /// </summary>
        /// <returns>A list of <see cref="Face3D">3d faces</see> that made up the polyface mesh.</returns>
        public List <EntityObject> Explode()
        {
            List <EntityObject> entities = new List <EntityObject>();

            foreach (PolyfaceMeshFace face in this.faces)
            {
                AciColor faceColor = face.Color == null ? this.Color : face.Color;
                Layer    faceLayer = face.Layer == null ? this.Layer : face.Layer;

                if (face.VertexIndexes.Length == 1)
                {
                    Point point = new Point
                    {
                        Layer         = (Layer)faceLayer.Clone(),
                        Linetype      = (Linetype)this.Linetype.Clone(),
                        Color         = (AciColor)faceColor.Clone(),
                        Lineweight    = this.Lineweight,
                        Transparency  = (Transparency)this.Transparency.Clone(),
                        LinetypeScale = this.LinetypeScale,
                        Normal        = this.Normal,
                        Position      = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1],
                    };
                    entities.Add(point);
                    continue;
                }
                if (face.VertexIndexes.Length == 2)
                {
                    Line line = new Line
                    {
                        Layer         = (Layer)faceLayer.Clone(),
                        Linetype      = (Linetype)this.Linetype.Clone(),
                        Color         = (AciColor)faceColor.Clone(),
                        Lineweight    = this.Lineweight,
                        Transparency  = (Transparency)this.Transparency.Clone(),
                        LinetypeScale = this.LinetypeScale,
                        Normal        = this.Normal,
                        StartPoint    = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1],
                        EndPoint      = this.Vertexes[Math.Abs(face.VertexIndexes[1]) - 1],
                    };
                    entities.Add(line);
                    continue;
                }

                Face3DEdgeFlags edgeVisibility = Face3DEdgeFlags.None;

                short indexV1 = face.VertexIndexes[0];
                short indexV2 = face.VertexIndexes[1];
                short indexV3 = face.VertexIndexes[2];
                // Polyface mesh faces are made of 3 or 4 vertexes, we will repeat the third vertex if the number of face vertexes is three
                int indexV4 = face.VertexIndexes.Length == 3 ? face.VertexIndexes[2] : face.VertexIndexes[3];

                if (indexV1 < 0)
                {
                    edgeVisibility |= Face3DEdgeFlags.First;
                }

                if (indexV2 < 0)
                {
                    edgeVisibility |= Face3DEdgeFlags.Second;
                }

                if (indexV3 < 0)
                {
                    edgeVisibility |= Face3DEdgeFlags.Third;
                }

                if (indexV4 < 0)
                {
                    edgeVisibility |= Face3DEdgeFlags.Fourth;
                }

                Vector3 v1 = this.Vertexes[Math.Abs(indexV1) - 1];
                Vector3 v2 = this.Vertexes[Math.Abs(indexV2) - 1];
                Vector3 v3 = this.Vertexes[Math.Abs(indexV3) - 1];
                Vector3 v4 = this.Vertexes[Math.Abs(indexV4) - 1];

                Face3D face3D = new Face3D
                {
                    Layer         = (Layer)faceLayer.Clone(),
                    Linetype      = (Linetype)this.Linetype.Clone(),
                    Color         = (AciColor)faceColor.Clone(),
                    Lineweight    = this.Lineweight,
                    Transparency  = (Transparency)this.Transparency.Clone(),
                    LinetypeScale = this.LinetypeScale,
                    Normal        = this.Normal,
                    FirstVertex   = v1,
                    SecondVertex  = v2,
                    ThirdVertex   = v3,
                    FourthVertex  = v4,
                    EdgeFlags     = edgeVisibility,
                };

                entities.Add(face3D);
            }

            return(entities);
        }