/// <summary> /// Initializes a new instance of the <c>Face3d</c> class. /// </summary> /// <param name="firstVertex">3d face <see cref="Vector3">first vertex</see>.</param> /// <param name="secondVertex">3d face <see cref="Vector3">second vertex</see>.</param> /// <param name="thirdVertex">3d face <see cref="Vector3">third vertex</see>.</param> /// <param name="fourthVertex">3d face <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.Visibles; }
/// <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) { if (face.VertexIndexes.Count == 1) { Point point = new Point { Layer = (Layer)this.Layer.Clone(), Linetype = (Linetype)this.Linetype.Clone(), Color = (AciColor)this.Color.Clone(), Lineweight = this.Lineweight, Transparency = (Transparency)this.Transparency.Clone(), LinetypeScale = this.LinetypeScale, Normal = this.Normal, Position = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1].Position, }; entities.Add(point); continue; } if (face.VertexIndexes.Count == 2) { Line line = new Line { Layer = (Layer)this.Layer.Clone(), Linetype = (Linetype)this.Linetype.Clone(), Color = (AciColor)this.Color.Clone(), Lineweight = this.Lineweight, Transparency = (Transparency)this.Transparency.Clone(), LinetypeScale = this.LinetypeScale, Normal = this.Normal, StartPoint = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1].Position, EndPoint = this.Vertexes[Math.Abs(face.VertexIndexes[1]) - 1].Position, }; entities.Add(line); continue; } Face3dEdgeFlags edgeVisibility = Face3dEdgeFlags.Visibles; 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.Count == 3 ? face.VertexIndexes[2] : face.VertexIndexes[3]; if (indexV1 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.First; } if (indexV2 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.Second; } if (indexV3 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.Third; } if (indexV4 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.Fourth; } Vector3 v1 = this.Vertexes[Math.Abs(indexV1) - 1].Position; Vector3 v2 = this.Vertexes[Math.Abs(indexV2) - 1].Position; Vector3 v3 = this.Vertexes[Math.Abs(indexV3) - 1].Position; Vector3 v4 = this.Vertexes[Math.Abs(indexV4) - 1].Position; Face3d face3d = new Face3d { Layer = (Layer)this.Layer.Clone(), Linetype = (Linetype)this.Linetype.Clone(), Color = (AciColor)this.Color.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); }
/// <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) { if (face.VertexIndexes.Length == 1) { Point point = new Point { Location = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1].Location, Color = this.Color, IsVisible = this.IsVisible, Layer = this.Layer, LineType = this.LineType, LineTypeScale = this.LineTypeScale, Lineweight = this.Lineweight, XData = this.XData }; entities.Add(point); continue; } if (face.VertexIndexes.Length == 2) { Line line = new Line { StartPoint = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1].Location, EndPoint = this.Vertexes[Math.Abs(face.VertexIndexes[1]) - 1].Location, Color = this.Color, IsVisible = this.IsVisible, Layer = this.Layer, LineType = this.LineType, LineTypeScale = this.LineTypeScale, Lineweight = this.Lineweight, XData = this.XData }; entities.Add(line); continue; } Face3dEdgeFlags edgeVisibility = Face3dEdgeFlags.Visibles; 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 face vertexes is three int indexV4 = face.VertexIndexes.Length == 3 ? face.VertexIndexes[2] : face.VertexIndexes[3]; if (indexV1 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.First; } if (indexV2 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.Second; } if (indexV3 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.Third; } if (indexV4 < 0) { edgeVisibility = edgeVisibility | Face3dEdgeFlags.Fourth; } Vector3 v1 = this.Vertexes[Math.Abs(indexV1) - 1].Location; Vector3 v2 = this.Vertexes[Math.Abs(indexV2) - 1].Location; Vector3 v3 = this.Vertexes[Math.Abs(indexV3) - 1].Location; Vector3 v4 = this.Vertexes[Math.Abs(indexV4) - 1].Location; Face3d face3d = new Face3d { FirstVertex = v1, SecondVertex = v2, ThirdVertex = v3, FourthVertex = v4, EdgeFlags = edgeVisibility, Color = this.Color, IsVisible = this.IsVisible, Layer = this.Layer, LineType = this.LineType, LineTypeScale = this.LineTypeScale, Lineweight = this.Lineweight, XData = this.XData }; entities.Add(face3d); } return(entities); }