3 using System.Collections.Generic;
14 void OnPostprocessModel(GameObject g)
19 void Process(GameObject g)
21 SkinnedMeshRenderer smr = g.GetComponentInChildren<SkinnedMeshRenderer>();
24 Debug.LogWarning(
"Unable to find Renderer" + smr.name);
29 List<Transform> boneTransforms = smr.bones.ToList();
32 boneTransforms.Sort(CompareTransform);
37 var remap =
new Dictionary<int, int>();
38 for (
int i = 0; i < smr.bones.Length; i++)
40 remap[i] = boneTransforms.IndexOf(smr.bones[i]);
44 BoneWeight[] bw = smr.sharedMesh.boneWeights;
45 for (
int i = 0; i < bw.Length; i++)
47 bw[i].boneIndex0 = remap[bw[i].boneIndex0];
48 bw[i].boneIndex1 = remap[bw[i].boneIndex1];
49 bw[i].boneIndex2 = remap[bw[i].boneIndex2];
50 bw[i].boneIndex3 = remap[bw[i].boneIndex3];
54 var bp =
new Matrix4x4[smr.sharedMesh.bindposes.Length];
55 for (
int i = 0; i < bp.Length; i++)
57 bp[remap[i]] = smr.sharedMesh.bindposes[i];
61 smr.bones = boneTransforms.ToArray();
62 smr.sharedMesh.boneWeights = bw;
63 smr.sharedMesh.bindposes = bp;
66 private static int CompareTransform(Transform A, Transform B)