Skip to content

Commit

Permalink
Fixed exception when splitting skinned meshes async in il2cpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasVanHooste committed May 24, 2021
1 parent 43bf642 commit 5035dc1
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public class MeshSplitterSkinned : MeshSplitterBase

protected Transform rootBone;
protected Transform[] originalBones;
#if ENABLE_MONO
protected Vector4[] bonesMatrixRows;

#else
protected Matrix4x4[] bonesLocalToWorldMatrices;
#endif
/// <summary>
/// Property to easily access which bones were cut after a split.
/// </summary>
Expand Down Expand Up @@ -132,15 +135,23 @@ protected void AllocateMemorySkinned(Transform meshTransform, SkinnedMeshRendere
{
originalBones = skinnedMeshRenderer.bones;
rootBone = skinnedMeshRenderer.rootBone;
bonesMatrixRows = new Vector4[originalBones.Length * 4];

#if ENABLE_MONO
bonesMatrixRows = new Vector4[originalBones.Length * 4];
for (int i = 0, counter = 0; i < originalBones.Length; i++)
{
for (int j = 0; j < 4; j++, counter++)
{
bonesMatrixRows[counter] = originalBones[i].localToWorldMatrix.GetRow(j);
}
}
#else
bonesLocalToWorldMatrices = new Matrix4x4[originalBones.Length];
for (int i = 0; i < originalBones.Length; i++)
{
bonesLocalToWorldMatrices[i] = originalBones[i].localToWorldMatrix;
}
#endif

bonesPos = new List<int>(originalBones.Length);
bonesNeg = new List<int>(originalBones.Length);
Expand Down Expand Up @@ -210,7 +221,7 @@ private Matrix4x4[] GetBoneToWorldMatrices()
#else
for (int i = 0; i < boneCount; i++)
{
boneToWorldMatrices[i] = originalBones[i].localToWorldMatrix * originalBindPoses[i];
boneToWorldMatrices[i] = bonesLocalToWorldMatrices[i] * originalBindPoses[i];
}
#endif
return boneToWorldMatrices;
Expand Down

0 comments on commit 5035dc1

Please sign in to comment.