/// <summary> /// Creates a new Face3D that is a copy of the current instance. /// </summary> /// <returns>A new Face3D that is a copy of this instance.</returns> public override object Clone() { Face3D entity = new Face3D { //EntityObject properties 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, IsVisible = this.IsVisible, //Face3d properties FirstVertex = this.firstVertex, SecondVertex = this.secondVertex, ThirdVertex = this.thirdVertex, FourthVertex = this.fourthVertex, EdgeFlags = this.edgeFlags }; foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <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); }