diff --git a/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs b/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs
index 32952aead..eb4976284 100644
--- a/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs
+++ b/Assets/UniGLTF/Runtime/MeshUtility/BoneMeshEraser.cs
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
using UnityEngine;
-
+using VRMShaders;
namespace UniGLTF.MeshUtility
{
@@ -35,6 +36,13 @@ namespace UniGLTF.MeshUtility
}
}
+ ///
+ /// skip triangles that has weight for exclude, return valid triangle count
+ ///
+ ///
+ ///
+ ///
+ ///
static int ExcludeTriangles(int[] triangles, BoneWeight[] bws, int[] exclude)
{
int count = 0;
@@ -116,8 +124,28 @@ namespace UniGLTF.MeshUtility
return new ExcludeBoneIndex(b0, b1, b2, b3);
}
- public static Mesh CreateErasedMesh(Mesh src, int[] eraseBoneIndices)
+ ///
+ /// Erase triangles that has boneWeight for eraseBone
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static int[] GetExcludedIndices(int[] indices, BoneWeight[] boneWeights, int[] eraseBoneIndices)
{
+ var count = ExcludeTriangles(indices, boneWeights, eraseBoneIndices);
+ var dst = new int[count];
+ Array.Copy(indices, 0, dst, 0, count);
+ return dst;
+ }
+
+ public static async Task CreateErasedMeshAsync(Mesh src, int[] eraseBoneIndices, IAwaitCaller awaitCaller)
+ {
+ if (awaitCaller == null)
+ {
+ awaitCaller = new ImmediateCaller();
+ }
+
/*
Debug.LogFormat("{0} exclude: {1}",
src.name,
@@ -140,16 +168,20 @@ namespace UniGLTF.MeshUtility
mesh.subMeshCount = src.subMeshCount;
for (int i = 0; i < src.subMeshCount; ++i)
{
- var indices = src.GetIndices(i);
- var count = ExcludeTriangles(indices, mesh.boneWeights, eraseBoneIndices);
- var dst = new int[count];
- Array.Copy(indices, 0, dst, 0, count);
+ var dst = await awaitCaller.Run(() => GetExcludedIndices(src.GetIndices(i), mesh.boneWeights, eraseBoneIndices));
mesh.SetIndices(dst, MeshTopology.Triangles, i);
}
return mesh;
}
+ public static Mesh CreateErasedMesh(Mesh src, int[] eraseBoneIndices)
+ {
+ var task = CreateErasedMeshAsync(src, eraseBoneIndices, new ImmediateCaller());
+ task.Wait();
+ return task.Result;
+ }
+
public static IEnumerable Ancestor(this Transform t)
{
yield return t;