Esempio n. 1
0
        /// <summary>
        /// Convert a netDXF mesh to a Nucleus mesh
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static Mesh Convert(nDE.Mesh mesh)
        {
            var result = new Mesh();

            // Vertices:
            for (int i = 0; i < mesh.Vertexes.Count; i++)
            {
                result.AddVertex(Convert(mesh.Vertexes[i]));
            }
            // Faces:
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                result.AddFace(mesh.Faces[i]);
            }
            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// Convert a netDXF mesh to a Nucleus mesh
 /// </summary>
 /// <param name="mesh"></param>
 /// <returns></returns>
 public static Mesh Convert(nDE.Mesh mesh)
 {
     var result = new Mesh();
     // Vertices:
     for (int i = 0; i < mesh.Vertexes.Count; i++)
     {
         result.AddVertex(Convert(mesh.Vertexes[i]));
     }
     // Faces:
     for (int i = 0; i < mesh.Faces.Count; i++)
     {
         var indices = mesh.Faces[i];
         indices.AddToAll(-1); // Make zero-indexed
         result.AddFace(indices);
     }
     return result;
 }
Esempio n. 3
0
        /// <summary>
        /// Convert a .Nucleus mesh into a netDXF equivalent
        /// </summary>
        /// <param name="mesh"></param>
        /// <returns></returns>
        public static nDE.Mesh Convert(Mesh mesh)
        {
            mesh.Vertices.AssignVertexIndices(0);
            var vertices = new List <Vector3>(mesh.VertexCount);

            foreach (var vertex in mesh.Vertices)
            {
                vertices.Add(Convert(vertex.Position));
            }
            var faces = new List <int[]>(mesh.FaceCount);

            foreach (var face in mesh.Faces)
            {
                faces.Add(face.ToIndexArray());
            }
            var result = new nDE.Mesh(vertices, faces);

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new Mesh that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Mesh that is a copy of this instance.</returns>
        public override object Clone()
        {
            List<Vector3> copyVertexes = new List<Vector3>(this.vertexes.Count);
            List<int[]> copyFaces = new List<int[]>(this.faces.Count);
            List<MeshEdge> copyEdges = null;

            copyVertexes.AddRange(this.vertexes.ToArray());
            foreach (int[] face in this.faces)
            {
                int[] copyFace = new int[face.Length];
                face.CopyTo(copyFace, 0);
                copyFaces.Add(copyFace);
            }
            if (this.edges != null)
            {
                copyEdges = new List<MeshEdge>(this.edges.Count);
                foreach (MeshEdge meshEdge in this.edges)
                {
                    copyEdges.Add((MeshEdge) meshEdge.Clone());
                }
            }

            Mesh entity = new Mesh(copyVertexes, copyFaces, copyEdges)
            {
                //EntityObject properties
                Layer = (Layer)this.layer.Clone(),
                LineType = (LineType)this.lineType.Clone(),
                Color = (AciColor)this.color.Clone(),
                Lineweight = (Lineweight)this.lineweight.Clone(),
                Transparency = (Transparency)this.transparency.Clone(),
                LineTypeScale = this.lineTypeScale,
                Normal = this.normal,
                //Mesh properties
                SubdivisionLevel = this.subdivisionLevel
            };

            foreach (XData data in this.XData.Values)
                entity.XData.Add((XData)data.Clone());

            return entity;

        }
        private void WriteMesh(Mesh mesh)
        {
            this.chunk.Write(100, SubclassMarker.Mesh);

            this.chunk.Write(71, (short) 2);
            this.chunk.Write(72, (short) 0);

            this.chunk.Write(91, (int) mesh.SubdivisionLevel);

            //vertexes
            this.chunk.Write(92, mesh.Vertexes.Count);
            foreach (Vector3 vertex in mesh.Vertexes)
            {
                this.chunk.Write(10, vertex.X);
                this.chunk.Write(20, vertex.Y);
                this.chunk.Write(30, vertex.Z);
            }

            //faces
            int sizeFaceList = mesh.Faces.Count;
            foreach (int[] face in mesh.Faces)
            {
                sizeFaceList += face.Length;
            }
            this.chunk.Write(93, sizeFaceList);
            foreach (int[] face in mesh.Faces)
            {
                this.chunk.Write(90, face.Length);
                foreach (int index in face)
                {
                    this.chunk.Write(90, index);
                }
            }

            // the edges information is optional, and only really useful when it is required to assign creases values to edges
            if (mesh.Edges != null)
            {
                //edges
                this.chunk.Write(94, mesh.Edges.Count);
                foreach (MeshEdge edge in mesh.Edges)
                {
                    this.chunk.Write(90, edge.StartVertexIndex);
                    this.chunk.Write(90, edge.EndVertexIndex);
                }

                //creases
                this.chunk.Write(95, mesh.Edges.Count);
                foreach (MeshEdge edge in mesh.Edges)
                {
                    this.chunk.Write(140, edge.Crease);
                }
            }

            this.chunk.Write(90, 0);

            this.WriteXData(mesh.XData);
        }
Esempio n. 6
0
        private Mesh ReadMesh()
        {
            int subdivisionLevel = 0;
            List<Vector3> vertexes = null;
            List<int[]> faces = null;
            List<MeshEdge> edges = null;
            List<XData> xData = new List<XData>();

            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 91:
                        subdivisionLevel = this.chunk.ReadInt();
                        if (subdivisionLevel < 0 || subdivisionLevel > 255)
                            subdivisionLevel = 0;
                        this.chunk.Next();
                        break;
                    case 92:
                        int numVertexes = this.chunk.ReadInt();
                        this.chunk.Next();
                        vertexes = this.ReadMeshVertexes(numVertexes);
                        break;
                    case 93:
                        int sizeFaceList = this.chunk.ReadInt();
                        this.chunk.Next();
                        faces = this.ReadMeshFaces(sizeFaceList);
                        break;
                    case 94:
                        int numEdges = this.chunk.ReadInt();
                        this.chunk.Next();
                        edges = this.ReadMeshEdges(numEdges);
                        break;
                    case 95:
                        int numCrease = this.chunk.ReadInt();
                        this.chunk.Next();
                        if (edges == null)
                            throw new NullReferenceException("The edges list is not initialized.");
                        if (numCrease != edges.Count)
                            throw new Exception("The number of edge creases must be the same as the number of edges.");
                        this.ReadMeshEdgeCreases(edges);
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(this.GetApplicationRegistry(appId));
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new Exception("The extended data of an entity must start with the application registry code.");
                        this.chunk.Next();
                        break;
                }
            }
            Mesh entity = new Mesh(vertexes, faces, edges)
            {
                SubdivisionLevel = (byte) subdivisionLevel,
            };

            entity.XData.AddRange(xData);

            return entity;
        }
Esempio n. 7
0
        private static void MeshEntity()
        {
            DxfDocument dxf = new DxfDocument();

            // construct a simple cube (see the AutoCad documentation for more information about creating meshes)

            // the mesh data is always defined at level 0 (no subdivision)
            // 8 vertices
            List<Vector3> vertexes = new List<Vector3>
                                            {
                                                new Vector3(-5, -5, -5),
                                                new Vector3(5, -5, -5),
                                                new Vector3(5, 5, -5),
                                                new Vector3(-5, 5, -5),
                                                new Vector3(-5, -5, 5),
                                                new Vector3(5, -5, 5),
                                                new Vector3(5, 5, 5),
                                                new Vector3(-5, 5, 5)
                                            };

            //6 faces
            List<int[]> faces = new List<int[]>
                                                {
                                                    new[] {0, 3, 2, 1},
                                                    new[] {0, 1, 5, 4},
                                                    new[] {1, 2, 6, 5},
                                                    new[] {2, 3, 7, 6},
                                                    new[] {0, 4, 7, 3},
                                                    new[] {4, 5, 6, 7}
                                                };

            

            // the list of edges is optional and only really needed when applying creases values to them
            // crease negative values will sharpen the edge independently of the subdivision level. Any negative crease value will be reseted as -1.
            // by default edge creases are set to 0.0 (no edge sharpening)
            List<MeshEdge> edges = new List<MeshEdge>
            {
                new MeshEdge(0, 1),
                new MeshEdge(1, 2),
                new MeshEdge(2, 3),
                new MeshEdge(3, 0),
                new MeshEdge(4, 5, -1.0),
                new MeshEdge(5, 6, -1.0),
                new MeshEdge(6, 7, -1.0),
                new MeshEdge(7, 4, -1.0),
                new MeshEdge(0, 4),
                new MeshEdge(1, 5),
                new MeshEdge(2, 6),
                new MeshEdge(3, 7)

            };
            Mesh mesh = new Mesh(vertexes, faces, edges);
            mesh.SubdivisionLevel = 3;

            ApplicationRegistry newAppReg = dxf.ApplicationRegistries.Add(new ApplicationRegistry("netDxf"));

            XData xdata = new XData(newAppReg);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "xdata string sample"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 50000));
            mesh.XData.Add(xdata);

            dxf.AddEntity(mesh);

            dxf.Save("mesh.dxf");

            dxf = DxfDocument.Load("mesh.dxf");

        }