コード例 #1
0
        public static Rhino.Geometry.Mesh ConvertToRhinoMesh(g3.DMesh3 largeMesh)
        {
            var mesh = new g3.DMesh3();

            mesh.CompactCopy(largeMesh);

            Rhino.Geometry.Mesh ret = new Rhino.Geometry.Mesh();

            foreach (var p in mesh.Vertices())
            {
                ret.Vertices.Add(new Rhino.Geometry.Point3d(p.x, p.y, p.z));
            }

            ret.Normals.Count = ret.Vertices.Count;

            for (int i = 0; i < ret.Vertices.Count; i++)
            {
                var n = mesh.GetVertexNormal(i);
                ret.Normals[i] = new Rhino.Geometry.Vector3f(n.x, n.y, n.z);
            }


            foreach (var f in mesh.Triangles())
            {
                if (f.a >= 0 && f.a < ret.Vertices.Count &&
                    f.b >= 0 && f.b < ret.Vertices.Count &&
                    f.c >= 0 && f.c < ret.Vertices.Count)
                {
                    ret.Faces.AddFace(new Rhino.Geometry.MeshFace(f.a, f.b, f.c));
                }
                else
                {
                    Rhino.RhinoApp.WriteLine("Error Triangle:" + f.a + "," + f.b + ",", +f.c);
                }
            }

            ret.Normals.ComputeNormals();

            return(ret);
        }