From 5035dc1cbc9a17ef410a3340d9247ced566c75c1 Mon Sep 17 00:00:00 2001 From: LucasVanHooste Date: Mon, 24 May 2021 16:32:36 +0200 Subject: [PATCH] Fixed exception when splitting skinned meshes async in il2cpp. --- .../Scripts/Splitters/MeshSplitterSkinned.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Assets/DynamicMeshSplitting/Scripts/Splitters/MeshSplitterSkinned.cs b/Assets/DynamicMeshSplitting/Scripts/Splitters/MeshSplitterSkinned.cs index 4f4e79a..55a760c 100644 --- a/Assets/DynamicMeshSplitting/Scripts/Splitters/MeshSplitterSkinned.cs +++ b/Assets/DynamicMeshSplitting/Scripts/Splitters/MeshSplitterSkinned.cs @@ -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 /// /// Property to easily access which bones were cut after a split. /// @@ -132,8 +135,9 @@ 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++) @@ -141,6 +145,13 @@ protected void AllocateMemorySkinned(Transform meshTransform, SkinnedMeshRendere 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(originalBones.Length); bonesNeg = new List(originalBones.Length); @@ -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;