mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-09 04:19:42 -05:00
Merge pull request #1219 from notargs/feature/optimize_mesh_loading
BuildBlendShape・LoadGeometryAsyncをワーカースレッドでの読み込みに対応
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user