Merge pull request #1219 from notargs/feature/optimize_mesh_loading

BuildBlendShape・LoadGeometryAsyncをワーカースレッドでの読み込みに対応
This commit is contained in:
ousttrue
2021-09-13 16:48:24 +09:00
committed by GitHub
2 changed files with 11 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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);
}
}