From eb84bb298d2b95aec7b2ae12cbf25ac64f25379a Mon Sep 17 00:00:00 2001 From: tylermurphy534 Date: Sun, 6 Nov 2022 15:12:42 -0500 Subject: move to self host --- .../Assets/ReassignBoneWeigthsToNewMesh.cs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 VRCSDK3AvatarsQuestLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs (limited to 'VRCSDK3AvatarsQuestLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs') diff --git a/VRCSDK3AvatarsQuestLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs b/VRCSDK3AvatarsQuestLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs new file mode 100644 index 00000000..70baa835 --- /dev/null +++ b/VRCSDK3AvatarsQuestLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +[ExecuteInEditMode] +public class ReassignBoneWeigthsToNewMesh : MonoBehaviour +{ + public Transform newArmature; + public string rootBoneName = "Hips"; + public bool PressToReassign; + + void Update() + { + if (PressToReassign) + Reassign(); + PressToReassign = false; + } + + // [ContextMenu("Reassign Bones")] + public void Reassign() + { + if (newArmature == null) + { + Debug.Log("No new armature assigned"); + return; + } + + if (newArmature.Find(rootBoneName) == null) + { + Debug.Log("Root bone not found"); + return; + } + + Debug.Log("Reassingning bones"); + SkinnedMeshRenderer rend = gameObject.GetComponent(); + Transform[] bones = rend.bones; + + rend.rootBone = newArmature.Find(rootBoneName); + + Transform[] children = newArmature.GetComponentsInChildren(); + + for (int i = 0; i < bones.Length; i++) + for (int a = 0; a < children.Length; a++) + if (bones[i].name == children[a].name) + { + bones[i] = children[a]; + break; + } + + rend.bones = bones; + } + +} \ No newline at end of file -- cgit v1.2.3-freya