Exemple #1
0
        /// <summary>
        /// Return a string array of all bone names in a given boneMap
        /// </summary>
        /// <returns>The array of bone names.</returns>
        /// <param name="bone_map">Bone map.</param>
        public static string[] getAllBonesNames(BoneUtility.BoneMap bone_map)
        {
            string[] result = new string[bone_map.Keys.Count];
            bone_map.Keys.CopyTo(result, 0);

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Returns a bone Transform from a given bone name.
        /// </summary>
        /// <returns>The bone's Transform or null if not found.</returns>
        /// <param name="name">The string name of the bone.</param>
        public Transform GetBoneByName(string name)
        {
            Transform target_bone = null;

            this.BoneMap.TryGetValue(name, out target_bone);

            // this is a hack to fix the new issue where on imprt the bone service bonemap is bad <----------- this hack is because of adding csboneserivce on the wrong import method callback - should be OnPostProcessModel
            // this could mess things up at runtime
            if (target_bone == null)
            {
                _boneMap = new BoneUtility.BoneMap(transform);
                this.BoneMap.TryGetValue(name, out target_bone);
            }

            return(target_bone);
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        /// <summary>
        /// Attaches a clone of the costume item to given CIbody figure.
        /// Send the GameObject of a costumeItem here, and we'll clone it, bind it and return the result
        /// </summary>
        /// <returns>The cloned GameObject of the costume_item</returns>
        /// <param name="costume_item">Costume_item.</param>
        /// <param name="figure">Figure.</param>
        public static GameObject CloneAndAttachCostumeItemToFigure(GameObject costume_item, BoneUtility.BoneMap figure_bone_map, CIbody figure, Transform root_bone)
        {
            // instatiate copy
            GameObject clone = GameObject.Instantiate(costume_item);

            clone.name = costume_item.name;

            // use the basic Attachment method
            GeometryTransferUtility.AttachCostumeItemToFigure(clone, figure_bone_map, figure, root_bone);

            // return the cloned costume_item GameObject
            return(clone);
        }
Exemple #5
0
        /// <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);
        }