123456789101112131415161718192021222324252627282930313233343536 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using EasyButtons;
- public class MeshCombine : MonoBehaviour
- {
- public SkinnedMeshRenderer target;
- public Transform sourceRootBone;
- public Transform[] bones;
- [Button]
- void Recalculate(){
- target.rootBone = sourceRootBone;
- //target.bones = src.bones;
- Transform[] bonesT = new Transform[target.bones.Length];
- for(int i = 0; i < target.bones.Length; i++){
- Transform targetBone = target.bones[i];
- string targetBoneName = targetBone.name;
- foreach(Transform sourceBone in sourceRootBone.GetComponentsInChildren<Transform>()){
- if(targetBoneName == sourceBone.name){
- Debug.Log("Switching bone : " + targetBoneName );
- bonesT[i] = sourceBone;
- break;
- }
- }
- }
- target.bones= bonesT;
- bones= target.bones;
- target.sharedMesh.RecalculateNormals();
- target.sharedMesh.RecalculateBounds();
- }
- [Button]
- void GetSelfRenderer(){
- target = GetComponent<SkinnedMeshRenderer>();
- }
- }
|