41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using EasyButtons;
|
|
public class BulkMeshBoneSwapper : MonoBehaviour
|
|
{
|
|
public Transform srcRootBone;
|
|
|
|
[Button]
|
|
void Recalculate()
|
|
{
|
|
SkinnedMeshRenderer[] meshes = GetComponentsInChildren<SkinnedMeshRenderer>();
|
|
for (int x = 0; x < meshes.Length; x++)
|
|
{
|
|
if(meshes[x]==null){Debug.Log("Ignoring null object : " + meshes[x].name);continue;}
|
|
|
|
// meshes[x].rootBone = srcRootBone;
|
|
//target.bones = src.bones;
|
|
Transform[] bonesT = new Transform[meshes[x].bones.Length];
|
|
for (int i = 0; i < meshes[x].bones.Length; i++)
|
|
{
|
|
Transform targetBone = meshes[x].bones[i];
|
|
if(targetBone==null){continue;}
|
|
string targetBoneName = targetBone.name;
|
|
foreach (Transform sourceBone in srcRootBone.GetComponentsInChildren<Transform>())
|
|
{
|
|
if (targetBoneName == sourceBone.name)
|
|
{
|
|
Debug.Log("Switching bone : " + targetBoneName);
|
|
bonesT[i] = sourceBone;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
meshes[x].bones = bonesT;
|
|
if(meshes[x].sharedMesh==null){Debug.Log("Ignoring null mesh : " + meshes[x].name);continue;}
|
|
//meshes[x].sharedMesh.RecalculateNormals();
|
|
//meshes[x].sharedMesh.RecalculateBounds();
|
|
}
|
|
}
|
|
} |