/// <summary> /// Remaps the bone structure from a given Transform, returning a new array of bones. /// </summary> /// <returns>An array of bone Transforms</returns> /// <param name="reference_geometry_bones">Reference geometry bones.</param> /// <param name="destination_bones">Destination bones.</param> public static Transform[] RemapBones(Transform[] reference_geometry_bones, Transform reference_root_bone, BoneUtility.BoneMap destination_bones, Transform destination_root_bone) { for (int i = 0; i < reference_geometry_bones.Length; i++) { BoneUtility.cleanAllBoneNames(reference_geometry_bones[i]); } var new_bones = new Transform[reference_geometry_bones.Length]; for (var index = 0; index < reference_geometry_bones.Length; index++) { new_bones[index] = DictionaryExtensions.Find(destination_bones, reference_geometry_bones[index].name); } return(new_bones); }
/// <summary> /// Attachs the costume_item to the given CIbody figure. /// </summary> /// <returns>The GameObject costume_item</returns> /// <param name="costume_item">Costume item.</param> /// <param name="figure_bone_map">Figure bone map.</param> /// <param name="figure">Figure.</param> /// <param name="root_bone">Root bone.</param> /// <remarks>Unneccesary return of parameter GameObject as both are the same GameObject</remarks> public static GameObject AttachCostumeItemToFigure(GameObject costume_item, BoneUtility.BoneMap figure_bone_map, CIbody figure, Transform root_bone) { // add to figure costume_item.transform.parent = figure.transform; // does not need "costume_item = " as BindGeometryToTransform alters the costume_item GameObject anyway costume_item = BindGeometryToTransform(costume_item, figure.transform); // need figure bones for targeting // BoneMap body_bones = new BoneMap(transform); // go through each coremesh and rebind bones n what not CoreMesh[] meshes = costume_item.GetComponentsInChildren <CoreMesh> (true); foreach (CoreMesh mesh in meshes) { if (mesh.meshType == MESH_TYPE.PROP) { continue; } /* * if(mesh.skinnedMeshRenderer.rootBone.name != "hip") * { * Transform[] bones = mesh.skinnedMeshRenderer.bones; * foreach(Transform bone in bones) * { * if(bone.name == "hip") * { * UnityEngine.Debug.Log("Re-assigned hip bone as root"); * mesh.skinnedMeshRenderer.rootBone = bone; * break; * } * } * } */ mesh.skinnedMeshRenderer.bones = BoneUtility.RemapBones(mesh.skinnedMeshRenderer.bones, mesh.skinnedMeshRenderer.rootBone, figure_bone_map, root_bone); //UnityEngine.Debug.Log("Remapped: " + mesh.name + " bones: " + mesh.skinnedMeshRenderer.bones.Length + " root: " + mesh.skinnedMeshRenderer.rootBone.name); mesh.skinnedMeshRenderer.rootBone = root_bone; } return(costume_item); }
/// <summary> /// Return a string array of all bone names for this model /// </summary> /// <returns>The string array</returns> public string[] getAllBonesNames() { return(BoneUtility.getAllBonesNames(this.BoneMap)); }