static public UnityEngine.Mesh ToHost(this Rhino.Geometry.Mesh _mesh) { var result = new UnityEngine.Mesh(); using (var mesh = _mesh.DuplicateMesh()) { mesh.Faces.ConvertQuadsToTriangles(); result.SetVertices(mesh.Vertices.ToHost()); result.SetNormals(mesh.Normals.ToHost()); int i = 0; int[] indices = new int[mesh.Faces.Count * 3]; foreach (var face in mesh.Faces) { indices[i++] = (face.C); indices[i++] = (face.B); indices[i++] = (face.A); } result.SetIndices(indices, MeshTopology.Triangles, 0); } return(result); }
static public UnityEngine.Mesh ToHost(this Rhino.Geometry.Mesh _mesh) { var result = new UnityEngine.Mesh(); if (_mesh.Vertices.Count > 65535) { result.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; } using (var mesh = _mesh.DuplicateMesh()) { mesh.Faces.ConvertQuadsToTriangles(); result.SetVertices(mesh.Vertices.ToHost()); result.SetNormals(mesh.Normals.ToHost()); result.SetUVs(0, mesh.TextureCoordinates.ToHost()); int i = 0; int[] indices = new int[mesh.Faces.Count * 3]; foreach (var face in mesh.Faces) { indices[i++] = (face.C); indices[i++] = (face.B); indices[i++] = (face.A); } result.SetColors(mesh.VertexColors.ToHost()); result.SetIndices(indices, MeshTopology.Triangles, 0); } result.RecalculateBounds(); result.RecalculateNormals(); result.RecalculateTangents(); return(result); }
static public UnityEngine.Mesh ToHost(this Rhino.Geometry.Mesh _mesh) { var result = new UnityEngine.Mesh(); result.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; using (var mesh = _mesh.DuplicateMesh()) { mesh.Faces.ConvertQuadsToTriangles(); result.SetVertices(mesh.Vertices.ToHost()); result.SetNormals(mesh.Normals.ToHost()); var colors = mesh.VertexColors.Select(col => new Color(col.R / 255.0f, col.G / 255.0f, col.B / 255.0f)).ToArray(); result.SetColors(colors); int i = 0; int[] indices = new int[mesh.Faces.Count * 3]; foreach (var face in mesh.Faces) { indices[i++] = (face.C); indices[i++] = (face.B); indices[i++] = (face.A); } result.SetIndices(indices, MeshTopology.Triangles, 0); } return(result); }
/// <summary> /// make a deep copy of the mesh /// </summary> /// <returns></returns> public IMesh DuplicateMesh() { return(new RhinoMesh(mesh.DuplicateMesh())); }