Exemplo n.º 1
0
        public static bool Prefix(Wears __instance, GameObject obj)
        {
            Transform this_baseboneroot_transform = baseBoneRootField.GetValue(__instance) as Transform;

            DynamicBone[]         componentsInChildren  = obj.GetComponentsInChildren <DynamicBone>(true);
            DynamicBoneCollider[] componentsInChildren2 = this_baseboneroot_transform.GetComponentsInChildren <DynamicBoneCollider>(true);
            foreach (DynamicBone dynamicBone in componentsInChildren)
            {
                if (dynamicBone.m_Root == null)
                {
                    continue;
                }
                Transform transform = Transform_Utility.FindTransform(this_baseboneroot_transform, dynamicBone.m_Root.name);
                if (transform != null)
                {
                    dynamicBone.m_Root = transform;
                }
                else
                {
                    Transform try_the_wear_rootbone = obj.transform.Find("cf_J_Root");
                    transform = Transform_Utility.FindTransform(try_the_wear_rootbone, dynamicBone.m_Root.name);
                    if (transform != null)
                    {
                        dynamicBone.m_Root = transform;
                    }
                    else
                    {
                        try_the_wear_rootbone = obj.transform.Find("cm_J_Root");
                        transform             = Transform_Utility.FindTransform(try_the_wear_rootbone, dynamicBone.m_Root.name);
                        if (transform != null)
                        {
                            dynamicBone.m_Root = transform;
                        }
                        else
                        {
                            Debug.LogError("ダイナミックボーン付け替えに失敗:" + dynamicBone.m_Root.name);
                        }
                    }
                }
                dynamicBone.m_Colliders.Clear();
                foreach (DynamicBoneCollider item in componentsInChildren2)
                {
                    dynamicBone.m_Colliders.Add(item);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private static void create_N_O_root_if_not_found(ref Transform iter, Transform prefab_anim_root)
        {
            if (iter != null)
            {
                return;               //means N_O_root is already found prior to this, skip it.
            }
            bool              female = Transform_Utility.FindTransform(prefab_anim_root, "cf_J_Root") != null ? true : false;
            Transform         iter_from_anim_root  = null;
            Transform         parent_to_N_O_root   = null;
            List <Transform>  children_to_N_O_root = new List <Transform>();
            Queue <Transform> transform_BFS_queue  = new Queue <Transform>();

            for (int i = 0; i < prefab_anim_root.childCount; i++)
            {
                transform_BFS_queue.Enqueue(prefab_anim_root.GetChild(i));
            }
            while (transform_BFS_queue.Count > 0)
            {
                iter_from_anim_root = transform_BFS_queue.Dequeue();
                if (iter_from_anim_root.name.IndexOf("N_") == 0)
                {
                    GameObject new_N_O_root = new GameObject(female ? "cf_N_O_root" : "cm_N_O_root");
                    parent_to_N_O_root = iter_from_anim_root.parent;

                    for (int i = 0; i < parent_to_N_O_root.childCount; i++)
                    {
                        children_to_N_O_root.Add(parent_to_N_O_root.GetChild(i));
                    }

                    for (int i = 0; i < children_to_N_O_root.Count; i++)
                    {
                        children_to_N_O_root[i].SetParent(new_N_O_root.transform);
                    }

                    new_N_O_root.transform.SetParent(parent_to_N_O_root);
                    iter = new_N_O_root.transform;
                    break;
                }
                for (int i = 0; i < iter_from_anim_root.childCount; i++)
                {
                    transform_BFS_queue.Enqueue(iter_from_anim_root.GetChild(i));
                }
            }
        }
Exemplo n.º 3
0
        static public void SetupProbes(Human human)
        {
            Transform t;

            if (human.sex == Character.SEX.MALE)
            {
                t = Transform_Utility.FindTransform(human.body.AnimatedBoneRoot, "cm_J_Spine01");
            }
            else
            {
                t = Transform_Utility.FindTransform(human.body.AnimatedBoneRoot, "cf_J_Spine01");
            }
            Console.WriteLine("Setup probes on " + human.name + ", anchor name: " + t.name);
            foreach (var renderer in human.GetComponentsInChildren <Renderer>(true))
            {
                renderer.reflectionProbeUsage = ReflectionProbeUsage.BlendProbes;
                renderer.lightProbeUsage      = LightProbeUsage.BlendProbes;
                renderer.probeAnchor          = t;
            }
        }
Exemplo n.º 4
0
        public void AddBoneModifier(string bonename)
        {
            if (boneModifiers.ContainsKey(Animator.StringToHash(bonename)))
            {
                return;
            }
            var t = Transform_Utility.FindTransform(human.body.AnimatedBoneRoot, bonename);

            if (t != null)
            {
                var bone = new Bone(t);
                targetBones.Add(bone);
                BoneModifier boneModifer = new BoneModifier(bonename)
                {
                    Scale    = bone.transform.localScale,
                    Rotation = bone.transform.localEulerAngles,
                    Position = bone.transform.localPosition
                };
                originalBones.Add(bone.ID, boneModifer);
                boneModifiers.Add(bone.ID, new BoneModifier(bonename));
                Console.WriteLine(Name + " has a new bone to modify: " + bonename);
            }
        }
        private static void BFS_test(Transform human_animator_basebone, Transform wear_animator_basebone, string starting_humanbone_name, string starting_wearbone_name)
        {
            Transform iter_from_human_animator =
                Transform_Utility.FindTransform(human_animator_basebone, starting_humanbone_name);

            if (iter_from_human_animator == null)
            {
                return;
            }

            Transform         iter_from_wear_animator = null;
            Queue <Transform> bone_BFS_queue          = new Queue <Transform>();

            bone_BFS_queue.Enqueue(iter_from_human_animator);
            while (bone_BFS_queue.Count > 0)
            {
                iter_from_human_animator = bone_BFS_queue.Dequeue();
                if (iter_from_human_animator.name == "cf_J_Mune00_t_L")
                {
                    iter_from_human_animator = iter_from_human_animator.FindDescendant("cf_J_Mune00_s_L");
                }
                else if (iter_from_human_animator.name == "cf_J_Mune00_t_R")
                {
                    iter_from_human_animator = iter_from_human_animator.FindDescendant("cf_J_Mune00_s_R");
                }
                else if (iter_from_human_animator.name == iter_from_human_animator.parent.name ||
                         iter_from_human_animator.name == "cf_N_k" ||
                         iter_from_human_animator.name == "cm_N_k" ||
                         iter_from_human_animator.name == "N_move")
                {
                    continue;
                }
                //    NOTE: Somehow the PH p_cf_anim bone hierarchy is different from the clothings at Mune00 and Mune00_t
                //          but they should become the same again at Mune00_s_L/R
                // skipped: cf&cm_N_k, cf_J_Mune00>cf_J_Mune00 ; Also N_move -- I am assuming no one is stupid enough to
                //          add additional_bones under N_move. But I might be proved wrong...

                iter_from_wear_animator = Transform_Utility.FindTransform(wear_animator_basebone, iter_from_human_animator.name);

                if (iter_from_wear_animator != null)
                {
                    for (int i = 0; i < iter_from_wear_animator.childCount; i++)
                    {
                        Transform child = iter_from_wear_animator.GetChild(i);
                        // If we want to notice the additional bones in the clothings, that additional bone
                        // cannot have 0 child, since it would be useless anyway. This is avoiding a lot of HS clothings
                        // that seems to have "_end" leaf bones, and PH clothings seem to not have those.
                        if (child.childCount > 0 && iter_from_human_animator.Find(child.name) == null &&
                            child.name != iter_from_human_animator.parent.name) // make sure we don't have child / parent inversion.
                        {                                                       // so far the inversion we see are just cx_bone and cx_bone_s inversion, let's hope there aren't more.
                            Console.WriteLine(" -- additional bone: " + iter_from_human_animator.name + "/" + child.name);
                            Current_additional_rootbones_.Add(child.name);
                        }
                    }
                }
                for (int i = 0; i < iter_from_human_animator.childCount; i++)
                {
                    bone_BFS_queue.Enqueue(iter_from_human_animator.GetChild(i));
                }
            }
        }
        public static bool Prefix(ref Dictionary <string, Transform> bones, GameObject attachObj, bool includeInactive)
        {
            // TODO: Apparently BonesFramework can add bones to custom heads.
            //       This is something that I am pretty sure this procedure don't work.
            //       But if PH is going to support custom heads better one day, however slim possibility that is
            //       this will need to get another fix. I think it's best we separate the procedure that processes
            //       body bones and face bones. These 2 set of bones are separate in the main game code anyway.

            SkinnedMeshRenderer[] renderers = attachObj.GetComponentsInChildren <SkinnedMeshRenderer>(includeInactive);
            Transform             wear_animator_basebone  = attachObj.transform.parent;
            Transform             human_animator_basebone = null;
            bool skinned_face_acce = false;

            if (attachObj.name == "AcceParent")
            {
                skinned_face_acce = Transform_Utility.FindTransform(attachObj.transform, "cf_J_FaceRoot") != null ||
                                    Transform_Utility.FindTransform(attachObj.transform, "cm_J_FaceRoot") != null;
                //Note: This is really important here -- for Non-Head Skinned accessories, we still want to
                //      potentially process them for additional bones, however the attachObj here isn't N_O_root,
                //      it is already "AcceParent" which is one-level above the prefab animator.
                //      If we don't reset wear_animator_basebone here, all the following code will break.
                wear_animator_basebone = attachObj.transform.GetChild(0);
            }

            Current_additional_rootbones_.Clear();
            if (wear_animator_basebone.name != "cf_body_00" && wear_animator_basebone.name != "cf_body_mnpb" &&
                wear_animator_basebone.name != "cm_body_00" && wear_animator_basebone.name != "cm_body_mnpb" &&
                wear_animator_basebone.name != "N_silhouette" && skinned_face_acce == false)
            {
                // Skip when it is currently Body object that is loading and not Wears.
                // Also skip all Skinned Accessory that is attached to FaceRoot.

                human_animator_basebone = FindHumanAnimTransformFromWears(wear_animator_basebone);
                bool female = bones.ContainsKey("cf_J_Root") ? true : false;
                // WTF: Apparently Bonesframework's additional bones can appear under the J_Root tree AND ALSO N_O_Root tree.
                // This means we just can't assume.
                // This should be the cloth's animator root transform, so we just ListupBones with BOTH tree.
                // Also note, when this is a skinned acce, we want to limit it to AcceParent instead of Wears.
                // Otherwise AcceParent will be treated as an additional bone.

                while (wear_animator_basebone.parent.name != "Wears" && wear_animator_basebone.parent.name != "AcceParent")
                {
                    wear_animator_basebone = wear_animator_basebone.parent;
                }

                //Console.WriteLine(wear_animator_basebone.name + ": -- Checking J_Root tree --");
                BFS_test(human_animator_basebone, wear_animator_basebone, female ? "cf_J_Root" : "cm_J_Root", female ? "cf_J_Root" : "cm_J_Root");
                //Console.WriteLine(wear_animator_basebone.name + ": -- Checking N_O_root tree --");
                foreach (SkinnedMeshRenderer r in renderers)
                {
                    for (int i = 0; i < r.transform.childCount; i++)
                    {
                        string name = r.transform.GetChild(i).name;
                        BFS_test(human_animator_basebone, attachObj.transform, name, name);
                    }
                }
                // list up all bone names from the clothing animator base to make sure additional bones are among them.
                AttachBoneWeight_ListupBones.Invoke(null, new object[] { bones, wear_animator_basebone, includeInactive });
            }

            /* The original SetupRenderers */
            foreach (SkinnedMeshRenderer r in renderers)
            {
                AttachBoneWeight_SetupRenderer.Invoke(null, new object[] { bones, r });
            }
            /* End of the original SetupRenderers */

            if (human_animator_basebone == null || Current_additional_rootbones_.Count == 0)
            {
                return(false);
            }
            // if we found out that this is not the correct object to adjust the additional_bones
            // we just stop the procedure here.

            Transform[] all_children_of_wears_animator_root =
                wear_animator_basebone.GetComponentsInChildren <Transform>(includeInactive);
            foreach (Transform t in all_children_of_wears_animator_root)
            {
                if (Current_additional_rootbones_.Contains(t.name))
                {
                    Console.WriteLine("Trying to realign the local position of " + t.name);
                    Transform  parent     = human_animator_basebone.FindDescendant(t.parent.name);
                    Vector3    localPos   = t.localPosition;
                    Quaternion localRot   = t.localRotation;
                    Vector3    localScale = t.localScale;
                    t.SetParent(parent);
                    t.localPosition = localPos;
                    t.localRotation = localRot;
                    t.localScale    = localScale;
                }
            }
            return(false);
        }
Exemplo n.º 7
0
        internal static void SetupColliders(Transform root, Cloth cloth, out List <CapsuleCollider> newCapsules, out List <ClothSphereColliderPair> newSpheres)
        {
            newCapsules = new List <CapsuleCollider>();
            newSpheres  = new List <ClothSphereColliderPair>();
            foreach (var cc in cloth.capsuleColliders)
            {
                var newTransform = Transform_Utility.FindTransform(root, cc.transform.name);
                if (newTransform == null)
                {
                    if (cc.transform.parent == null)
                    {
                        continue;
                    }
                    newTransform = Transform_Utility.FindTransform(root, cc.transform.parent.name);
                    if (newTransform == null)
                    {
                        continue;
                    }
                }
                var newcc = Instantiate(cc, newTransform, false);
                Destroy(cc);
                newCapsules.Add(newcc);

                //cc.enabled = false;
                Console.WriteLine("Add new Capsule collider on: " + newcc.name);
            }
            foreach (var sc in cloth.sphereColliders)
            {
                if (sc.first != null)
                {
                    Console.WriteLine("1st sphereColliders: " + sc.first.transform.name);
                    var newTransform1 = Transform_Utility.FindTransform(root, sc.first.transform.name);
                    var newscp        = new ClothSphereColliderPair();
                    if (newTransform1 == null)
                    {
                        if (sc.first.transform.parent == null)
                        {
                            continue;
                        }
                        newTransform1 = Transform_Utility.FindTransform(root, sc.first.transform.parent.name);
                        if (newTransform1 == null)
                        {
                            continue;
                        }
                    }
                    newscp.first = Instantiate(sc.first, newTransform1, false);
                    Destroy(sc.first);
                    Console.WriteLine("Add new Sphere collider on: " + newscp.first.name);

                    if (sc.second != null)
                    {
                        Console.WriteLine("2nd sphereColliders: " + sc.second.transform.name);
                        var newTransform2 = Transform_Utility.FindTransform(root, sc.second.transform.name);
                        if (newTransform2 == null)
                        {
                            if (sc.second.transform.parent == null)
                            {
                                goto addnew;
                            }
                            newTransform2 = Transform_Utility.FindTransform(root, sc.second.transform.parent.name);
                            if (newTransform2 == null)
                            {
                                goto addnew;
                            }
                        }
                        newscp.second = Instantiate(sc.second, newTransform2, false);
                        Destroy(sc.second);
                        Console.WriteLine("Add new Sphere collider on: " + newscp.second.name);
                    }
addnew:
                    newSpheres.Add(newscp);
                }
            }
        }