From b1bd5e49497f8c6dbf4c1e9878976b1e79995625 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Sat, 30 Jun 2018 00:30:23 -0400 Subject: [PATCH] large mesh handling --- platform/fMesh.cs | 3 +++ util/UnityUtil.cs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/platform/fMesh.cs b/platform/fMesh.cs index 4c32936..82e4428 100644 --- a/platform/fMesh.cs +++ b/platform/fMesh.cs @@ -40,6 +40,9 @@ public fMesh(int[] triangles, DMesh3 source, int[] source_vertices, bool bCopyNo Mesh m = new Mesh(); m.vertices = vertices; + + if (NV > 65000 || triangles.Length/3 > 65000) + m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; m.triangles = triangles; if (bCopyNormals && source.HasVertexNormals) { diff --git a/util/UnityUtil.cs b/util/UnityUtil.cs index f0c7cb1..e6cf784 100644 --- a/util/UnityUtil.cs +++ b/util/UnityUtil.cs @@ -468,7 +468,7 @@ public static UnityEngine.Mesh SimpleMeshToUnityMesh(SimpleMesh m, bool bSwapLef - public static fMesh DMeshToUnityMesh(DMesh3 m, bool bSwapLeftRight, bool bAllowLargeMeshes = false) + public static fMesh DMeshToUnityMesh(DMesh3 m, bool bSwapLeftRight, bool bAllowLargeMeshes = false, bool bRecalcNormalsIfMissing = true) { if (bSwapLeftRight) throw new Exception("[RMSNOTE] I think this conversion is wrong, see MeshTransforms.SwapLeftRight. Just want to know if this code is ever hit."); @@ -514,8 +514,9 @@ public static fMesh DMeshToUnityMesh(DMesh3 m, bool bSwapLeftRight, bool bAllowL unityMesh.triangles = triangles; } - if (m.HasVertexNormals == false) + if (m.HasVertexNormals == false && bRecalcNormalsIfMissing) { unityMesh.RecalculateNormals(); + } return new fMesh(unityMesh); }