summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
commiteb84bb298d2b95aec7b2ae12cbf25ac64f25379a (patch)
treeefd616a157df06ab661c6d56651853431ac6b08b /VRCSDK3AvatarsLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs
downloadunityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.gz
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.bz2
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.zip
move to self host
Diffstat (limited to 'VRCSDK3AvatarsLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs')
-rw-r--r--VRCSDK3AvatarsLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/VRCSDK3AvatarsLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs b/VRCSDK3AvatarsLegacy/Assets/ReassignBoneWeigthsToNewMesh.cs
new file mode 100644
index 00000000..70baa835
--- /dev/null
+++ b/VRCSDK3AvatarsLegacy/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<SkinnedMeshRenderer>();
+ Transform[] bones = rend.bones;
+
+ rend.rootBone = newArmature.Find(rootBoneName);
+
+ Transform[] children = newArmature.GetComponentsInChildren<Transform>();
+
+ 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