From 471f5fcd9ef10d2ae427f7dbf98158db18e68c47 Mon Sep 17 00:00:00 2001 From: notargs Date: Mon, 13 Sep 2021 15:51:44 +0900 Subject: [PATCH] =?UTF-8?q?BuildBlendShape=E3=83=BBLoadGeometryAsync?= =?UTF-8?q?=E3=82=92=E3=83=AF=E3=83=BC=E3=82=AB=E3=83=BC=E3=82=B9=E3=83=AC?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=A7=E3=81=AE=E8=AA=AD=E3=81=BF=E8=BE=BC?= =?UTF-8?q?=E3=81=BF=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs | 2 +- .../Runtime/UniGLTF/IO/MeshIO/MeshImporter.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs index aaeefc50f..120d04bb2 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/ImporterContext.cs @@ -174,7 +174,7 @@ namespace UniGLTF var index = i; using (MeasureTime("ReadMesh")) { - var x = meshImporter.ReadMesh(GLTF, index, inverter); + var x = await awaitCaller.Run(() => meshImporter.ReadMesh(GLTF, index, inverter)); var y = await BuildMeshAsync(awaitCaller, MeasureTime, x, index); Meshes.Add(y); } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshImporter.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshImporter.cs index 21e9607c1..3e8f52268 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshImporter.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/MeshIO/MeshImporter.cs @@ -619,15 +619,22 @@ namespace UniGLTF return (mesh, recalculateTangents); } - static void BuildBlendShape(Mesh mesh, MeshContext meshContext, BlendShape blendShape, Vector3[] emptyVertices) + static async Task BuildBlendShapeAsync(IAwaitCaller awaitCaller, Mesh mesh, MeshContext meshContext, BlendShape blendShape, Vector3[] emptyVertices) { + Vector3[] positions = null; + Vector3[] normals = null; + await awaitCaller.Run(() => + { + positions = blendShape.Positions.ToArray(); + normals = blendShape.Normals.ToArray(); + }); if (blendShape.Positions.Count > 0) { if (blendShape.Positions.Count == mesh.vertexCount) { mesh.AddBlendShapeFrame(blendShape.Name, FRAME_WEIGHT, blendShape.Positions.ToArray(), - (meshContext.Normals.Count == mesh.vertexCount && blendShape.Normals.Count == blendShape.Positions.Count()) ? blendShape.Normals.ToArray() : null, + normals.Length == mesh.vertexCount && normals.Length == positions.Length ? normals : null, null ); } @@ -672,7 +679,7 @@ namespace UniGLTF var emptyVertices = new Vector3[mesh.vertexCount]; foreach (var blendShape in meshContext.BlendShapes) { - BuildBlendShape(mesh, meshContext, blendShape, emptyVertices); + await BuildBlendShapeAsync(awaitCaller, mesh, meshContext, blendShape, emptyVertices); } }