Exemplo n.º 1
0
        public GltfMeshHolder Convert()
        {
            GltfMeshHolder meshHolder = new GltfMeshHolder(converter, doc);

            foreach (var primitive in mesh.Primitives)
            {
                Rhino.Geometry.Mesh rhinoMesh = GetMesh(primitive);

                if (rhinoMesh == null)
                {
                    continue;
                }

                rhinoMesh.Weld(0.01);

                rhinoMesh.Compact();

                if (!rhinoMesh.IsValidWithLog(out string log))
                {
                    Rhino.RhinoApp.WriteLine(log);
                }

                meshHolder.AddPrimitive(rhinoMesh, primitive.Material, mesh.Name);
            }

            return(meshHolder);
        }
Exemplo n.º 2
0
        public static Mesh ToPolygonMesh(this Rhino.Geometry.Mesh mesh)
        {
            // clean up input mesh
            mesh.Vertices.CombineIdentical(true, true);
            mesh.Vertices.CullUnused();
            mesh.UnifyNormals();
            mesh.Weld(Math.PI);

            var positions = mesh
                            .TopologyVertices
                            .Select(tv => new Vec3d(tv.X, tv.Y, tv.Z))
                            .ToList();

            var faces =
                mesh
                .GetNgonAndFacesEnumerable()
                .Select(
                    ngon => ngon.BoundaryVertexIndexList().Select(Convert.ToInt32));

            return(Mesh.CreateFromPositions(positions, faces));
        }