Ejemplo n.º 1
0
        public void AddDanConstraints(BaseUnityPlugin plugin)
        {
            if (danEntryTarget == null || danEndTarget == null || collisionAgent == null)
            {
                return;
            }

            if (danEntryConstraint != null && danEntryConstraint.GetValue(1) != null)
            {
                var parentTransform = collisionAgent.GetComponentsInChildren <Transform>().Where(x => x.name == danEntryConstraint.GetValue(1) as string).FirstOrDefault();

                if (parentTransform != null)
                {
                    danEntryConstraint.SetValue(parentTransform, 1);
                    danEntryConstraint.SetValue(danEntryTarget, 2);
                    plugin.GetType().GetMethod("AddConstraint", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(plugin, danEntryConstraint);
                }
            }

            if (danEndConstraint != null && danEndConstraint.GetValue(1) != null)
            {
                var parentTransform = collisionAgent.GetComponentsInChildren <Transform>().Where(x => x.name == danEndConstraint.GetValue(1) as string).FirstOrDefault();

                if (parentTransform != null)
                {
                    danEndConstraint.SetValue(parentTransform, 1);
                    danEndConstraint.SetValue(danEndTarget, 2);
                    plugin.GetType().GetMethod("AddConstraint", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(plugin, danEndConstraint);
                }
            }
        }
Ejemplo n.º 2
0
        public static void SetPoVCharacter(ChaControl character)
        {
            if (povCharacter == character)
            {
                return;
            }

            if (povCharacter != null)
            {
                povUpperNeck.localRotation = Quaternion.identity;
                povLowerNeck.localRotation = Quaternion.identity;
                povHead.localRotation      = Quaternion.identity;
                eyeOffset = Vector3.zero;

                if (normalHeadScale != null)
                {
                    povCharacter.objHeadBone.transform.localScale = normalHeadScale;
                }
            }

            povCharacter = character;
            if (povCharacter == null)
            {
                return;
            }

            povUpperNeck    = povCharacter.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(upperNeckBone)).FirstOrDefault();
            povLowerNeck    = povCharacter.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(lowerNeckBone)).FirstOrDefault();
            povHead         = povCharacter.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(headBone)).FirstOrDefault();
            normalHeadScale = povCharacter.objHeadBone.transform.localScale;

            CalculateEyesOffset();
            AdjustPoVHeadScale();
            CheckHSceneHeadLock();
        }
Ejemplo n.º 3
0
        private void Initialize(ChaControl character, DanOptions options)
        {
            ClearDanAgent();

            if (character == null)
            {
                return;
            }

            m_danOptions   = options;
            m_danCharacter = character;

            Transform        danTop        = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.DanTop));
            List <Transform> danTransforms = new List <Transform>();

            foreach (var boneName in BoneNames.DanBones)
            {
                Transform danBone = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(boneName));
                if (danBone != null)
                {
                    danTransforms.Add(danBone);
                }
            }

            if (danTop == null || danTransforms.Count < 2)
            {
                return;
            }

            if (danTransforms.Count == BoneNames.DanBones.Count)
            {
                m_bpDanPointsFound = true;
            }

            m_danPoints             = new DanPoints(danTransforms, danTop);
            m_danPointsFound        = true;
            m_baseDanLength         = DefaultDanLength * m_danPoints.GetDanLossyScale();
            m_baseSectionHalfLength = m_baseDanLength / (2 * (m_danPoints.danPoints.Count - 1));

            for (int danPoint = 1; danPoint < m_danPoints.danPoints.Count; danPoint++)
            {
                m_danColliders.Add(InitializeCollider(m_danPoints.danPoints[danPoint - 1].transform, m_danOptions.danRadius * m_danPoints.danPoints[danPoint].defaultLossyScale.x, ((m_baseSectionHalfLength + m_danOptions.danHeadLength) * 2),
                                                      DynamicBoneCollider.Direction.Z, m_danOptions.danVerticalCenter, m_baseSectionHalfLength));
            }

#if !HS2_STUDIO && !AI_STUDIO
            UpdateFingerColliders(m_danOptions.fingerRadius, m_danOptions.fingerLength);
#endif

            Console.WriteLine("Dan Found " + m_danPointsFound);
            Console.WriteLine("BP Dan Found " + m_bpDanPointsFound);
        }
Ejemplo n.º 4
0
        public static void RotatePlayerTowardsCharacter(ChaControl character)
        {
            if (!povEnabled || povFocus != Player || povCharacter == null)
            {
                return;
            }

            PlayerActor player = Map.Instance.Player;

            if (player == null)
            {
                return;
            }

            Console.WriteLine($"RotatePlayerTowardsCharacter {character.name}");

            if (!player.isActiveAndEnabled)
            {
                player.enabled = true;
            }

            Vector3 playerPosition = player.Position;
            Vector3 agentPosition  = character.objBodyBone.transform.position;

            Vector2 playerForward = new Vector2(player.Forward.x, player.Forward.z);
            Vector2 turnVector    = new Vector2(agentPosition.x - playerPosition.x, agentPosition.z - playerPosition.z);

            bodyWorldYaw = player.Rotation.eulerAngles.y - Vector2.SignedAngle(playerForward, turnVector);
            var leftEye  = player.ChaControl.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(leftEyePupil)).FirstOrDefault();
            var rightEye = player.ChaControl.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(rightEyePupil)).FirstOrDefault();

            povHead.localRotation = povLowerNeck.localRotation = povUpperNeck.localRotation = Quaternion.identity;
            Vector3 playerEyePosition  = Vector3.Lerp(leftEye.position, rightEye.position, 0.5f);
            Vector3 playerLookPosition = character.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(lowerNeckBone)).FirstOrDefault().position;

            cameraLocalPitch          = Tools.GetHeadPitch(playerEyePosition, playerLookPosition);
            headLocalPitch            = cameraLocalPitch * AI_PovX.HeadMaxPitch.Value / (AI_PovX.EyeMaxPitch.Value + AI_PovX.HeadMaxPitch.Value);
            eyeLocalPitch             = cameraLocalPitch - headLocalPitch;
            eyeLocalYaw               = headLocalYaw = cameraLocalYaw = 0;
            cameraWorldYaw            = povHead.eulerAngles.y;
            playerBodyRotationReached = false;

            leftEye  = character.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(leftEyePupil)).FirstOrDefault();
            rightEye = character.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(rightEyePupil)).FirstOrDefault();

            Vector3 characterEyePosition  = Vector3.Lerp(leftEye.position, rightEye.position, 0.5f);
            Vector3 characterLookPosition = playerEyePosition;

            RotateCharacterHead(character, Tools.GetHeadPitch(characterEyePosition, characterLookPosition));
        }
Ejemplo n.º 5
0
        private void Awake()
        {
            female = GetComponent <ChaControl>();
            ReloadBlendValues();
            Transform transform = female.GetComponentsInChildren <Transform>().ToList <Transform>().Where <Transform>(x => x.name == "o_tang").FirstOrDefault <Transform>();

            if (transform == null)
            {
                Console.WriteLine("No tang founded.");
                Destroy(this);
            }
            else
            {
                tang          = transform.gameObject;
                siru          = gameObject.AddComponent <Siru>();
                siru.female   = female;
                siru.cyu      = this;
                tangRenderer  = siru.tangRenderer = tang.GetComponent <SkinnedMeshRenderer>();
                kissEyeTarget = GameObject.CreatePrimitive(PrimitiveType.Cube);
                kissEyeTarget.SetActive(false);
                kissEyeTarget.AddComponent <DragMove>();
                kissEyeTarget.transform.localScale = Vector3.one * 0.05f;
                kissEyeTarget.transform.SetParent(female.objHead.transform);
                kissEyeTarget.transform.localPosition = new Vector3(0.0f, 0.0f, 0.5f);
                camera  = Resources.FindObjectsOfTypeAll <SteamVR_Camera>().FirstOrDefault <SteamVR_Camera>().GetComponent <Camera>().gameObject;
                myMouth = new GameObject("MyMouth");
                myMouth.transform.SetParent(camera.transform);
                myMouth.transform.localPosition = new Vector3(0.0f, -CyuLoaderVR.MouthOffset.Value, 0.0f);
                siru.siruTarget = myMouth;
                kissNeckTarget  = new GameObject("KissNeckTarget");
                kissNeckTarget.transform.SetParent(camera.transform, false);
                kissNeckTarget.transform.localPosition = new Vector3(0.0f, CyuLoaderVR.KissNeckAngle.Value, -0.5f);
            }
        }
Ejemplo n.º 6
0
        public static void RemoveCollidersFromCoordinate(ChaControl character)
        {
            var dynamicBones = character.GetComponentsInChildren <DynamicBone>(true);

            if (dynamicBones == null)
            {
                return;
            }

            foreach (var dynamicBone in dynamicBones)
            {
                if (dynamicBone == null ||
                    dynamicBone.m_Colliders == null ||
                    (dynamicBone.name != null && (dynamicBone.name.Contains("V****a") || dynamicBone.name.Contains("cm_J_dan"))))
                {
                    continue;
                }

                for (int collider = 0; collider < dynamicBone.m_Colliders.Count; collider++)
                {
                    if (dynamicBone.m_Colliders[collider] != null &&
                        dynamicBone.m_Colliders[collider].name != null &&
                        (dynamicBone.m_Colliders[collider].name.Contains("V****a") || dynamicBone.m_Colliders[collider].name.Contains("cm_J_dan")))
                    {
                        dynamicBone.m_Colliders.RemoveAt(collider);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static Transform GetTransformOfChaControl(ChaControl chaControl, string transformName)
        {
            Transform transform = null;

            if (chaControl == null)
            {
                return(transform);
            }

            var transforms = chaControl.GetComponentsInChildren <Transform>().Where(x => x.name != null && x.name.Equals(transformName));

            if (transforms.Count() == 0)
            {
                return(transform);
            }

            for (int transformIndex = transforms.Count() - 1; transformIndex >= 0; transformIndex--)
            {
                transform = transforms.ElementAt(transformIndex);
                if (transform == null || chaControl != transform.GetComponentInParent <ChaControl>())
                {
                    continue;
                }

                return(transform);
            }

            return(transform);
        }
Ejemplo n.º 8
0
        internal static void RemoveCollidersFromCoordinate(ChaControl character)
        {
            var dynamicBones = character.GetComponentsInChildren <DynamicBone>(true);

            if (dynamicBones == null)
            {
                return;
            }

            foreach (var dynamicBone in dynamicBones)
            {
                if (dynamicBone == null || dynamicBone.name == null || dynamicBone.m_Colliders == null)
                {
                    continue;
                }

                bool bpBone = dynamicBone.name.Contains("V****a") || dynamicBone.name.Contains("Belly") || dynamicBone.name.Contains("Ana");
                for (int collider = dynamicBone.m_Colliders.Count - 1; collider >= 0; collider--)
                {
                    if (dynamicBone.m_Colliders[collider] == null || dynamicBone.m_Colliders[collider].name == null)
                    {
                        continue;
                    }

                    bool bpCollider = dynamicBone.m_Colliders[collider].name.Contains("cm_J_vdan") || dynamicBone.m_Colliders[collider].name.Contains("cm_J_dan");
                    if (bpBone == bpCollider)
                    {
                        continue;
                    }

                    dynamicBone.m_Colliders.RemoveAt(collider);
                }
            }
        }
Ejemplo n.º 9
0
        public static List <DynamicBoneCollider> GetCollidersOfChaControl(ChaControl chaControl, List <string> colliderNames)
        {
            List <DynamicBoneCollider> colliderList = new List <DynamicBoneCollider>();

            if (chaControl == null)
            {
                return(colliderList);
            }

            var colliders = chaControl.GetComponentsInChildren <DynamicBoneCollider>().Where(x => x.name != null && colliderNames.Contains(x.name));

            if (colliders.Count() == 0)
            {
                return(colliderList);
            }

            foreach (var collider in colliders)
            {
                if (chaControl != collider.GetComponentInParent <ChaControl>())
                {
                    continue;
                }

                colliderList.Add(collider);
            }

            return(colliderList);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Search all SMR's for a matchtching key
        /// </summary>
        internal static SkinnedMeshRenderer GetMeshRenderer(ChaControl chaControl, string renderKey)
        {
            var renderers = chaControl.GetComponentsInChildren <SkinnedMeshRenderer>(true);//Even search inactive renderers
            var renderer  = renderers.FirstOrDefault(x => (KeyFromNameAndVerts(x)) == renderKey);

            return(renderer);
        }
Ejemplo n.º 11
0
        internal void AddTamaColliders(ChaControl target, bool midSectionOnly = true)
        {
            if (!m_bpTamaFound)
            {
                return;
            }

            foreach (DynamicBoneCollider dynamicBoneCollider in target.GetComponentsInChildren <DynamicBoneCollider>())
            {
                if (dynamicBoneCollider == null ||
                    (midSectionOnly && !BoneNames.MidSectionColliders.Contains(dynamicBoneCollider.name)) ||
                    !BoneNames.BodyColliders.Contains(dynamicBoneCollider.name))
                {
                    continue;
                }

                foreach (var tamaBone in m_tamaBones)
                {
                    if (tamaBone == null)
                    {
                        continue;
                    }

                    tamaBone.m_Colliders.Add(dynamicBoneCollider);
                }
            }
        }
Ejemplo n.º 12
0
        internal static void SetBPBoneWeights(ChaControl character, float weight)
        {
            var dynamicBones = character.GetComponentsInChildren <DynamicBone>(true);

            if (dynamicBones == null)
            {
                return;
            }

            foreach (var dynamicBone in dynamicBones)
            {
                if (dynamicBone == null ||
                    dynamicBone.m_Root == null ||
                    dynamicBone.name == null ||
                    character != dynamicBone.GetComponentInParent <ChaControl>())
                {
                    continue;
                }

                if (dynamicBone.name.Contains(BoneNames.BPBone) || dynamicBone.name.Contains(BoneNames.BellyBone))
                {
                    dynamicBone.SetWeight(weight);
                }
            }
        }
Ejemplo n.º 13
0
        public static DynamicBone GetDynamicBoneOfChaControl(ChaControl chaControl, string dynamicBoneName)
        {
            DynamicBone dynamicBone = null;

            if (chaControl == null)
            {
                return(dynamicBone);
            }

            var dynamicBones = chaControl.GetComponentsInChildren <DynamicBone>().Where(x => x.name != null && x.name.Equals(dynamicBoneName));

            if (dynamicBones.Count() == 0)
            {
                return(dynamicBone);
            }

            for (int boneIndex = dynamicBones.Count() - 1; boneIndex >= 0; boneIndex--)
            {
                dynamicBone = dynamicBones.ElementAt(boneIndex);
                if (dynamicBone != null && chaControl == dynamicBone.GetComponentInParent <ChaControl>())
                {
                    return(dynamicBone);
                }
            }

            return(dynamicBone);
        }
Ejemplo n.º 14
0
        public void LoadCharacterTransforms(ChaControl character)
        {
            allLimbsFound = false;

            for (var offset = 0; offset < offsetTransforms.Length; offset++)
            {
                offsetTransforms[offset] = character.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(offsetTransformNames[offset])).FirstOrDefault();
                if (offsetTransforms[offset] == null)
                {
                    return;
                }
            }

            for (var offset = (int)BodyPart.LeftHand; offset < hintTransformNames.Length; offset++)
            {
                hintTransforms[offset] = character.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(hintTransformNames[offset])).FirstOrDefault();
                if (hintTransforms[offset] == null)
                {
                    return;
                }
            }

            for (var offset = (int)BodyPart.LeftHand; offset < offsetTransforms.Length; offset++)
            {
                baseData[offset] = character.GetComponentsInChildren <Correct.BaseData>().Where(x => x.name.Contains(offsetTransformNames[offset])).FirstOrDefault();
                if (baseData[offset] == null)
                {
                    return;
                }

                if (baseData[offset].bone != null)
                {
                    lastBasePosition[offset] = baseData[offset].bone.position;
                    lastBaseRotation[offset] = baseData[offset].bone.eulerAngles;
                }
                else
                {
                    lastBasePosition[offset] = Vector3.zero;
                    lastBaseRotation[offset] = Vector3.zero;
                }
            }

            mouthTransform = character.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(mouthTransformName)).FirstOrDefault();
            hipTransform   = character.GetComponentsInChildren <Transform>().Where(x => x.name.Contains(hipTransformName)).FirstOrDefault();

            allLimbsFound = true;
        }
Ejemplo n.º 15
0
        internal void UpdateFingerColliders(float fingerRadius, float fingerLength)
        {
            if (!m_danPointsFound)
            {
                return;
            }

            Transform index  = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.IndexFinger));
            Transform middle = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.MiddleFinger));
            Transform ring   = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.RingFinger));

            m_indexCollider  = InitializeCollider(index, fingerRadius, fingerLength);
            m_middleCollider = InitializeCollider(middle, fingerRadius, fingerLength);
            m_ringCollider   = InitializeCollider(ring, fingerRadius, fingerLength);

            m_danOptions.fingerRadius = fingerRadius;
            m_danOptions.fingerLength = fingerLength;
        }
Ejemplo n.º 16
0
            private static bool ChaControl_ChangeAccessoryParent_Prefix(ChaControl __instance, int slotNo, string parentStr, ref bool __result)
            {
                if (slotNo >= __instance.objAccessory.Length)
                {
                    __result = false;
                    return(false);
                }

                GameObject gameObject = __instance.objAccessory[slotNo];

                if (gameObject == null)
                {
                    __result = false;
                    return(false);
                }
                if (parentStr == "none")
                {
                    gameObject.transform.SetParent(null, worldPositionStays: false);
                    __result = true;
                    return(false);
                }
                ListInfoBase listInfoBase = __instance.infoAccessory[slotNo];

                if (listInfoBase != null)
                {
                    listInfoBase = gameObject.GetComponent <ListInfoComponent>().data;
                }
                if (listInfoBase.GetInfo(ChaListDefine.KeyType.Parent) == "0")
                {
                    __result = false;
                    return(false);
                }
                try
                {
                    /*
                     * ChaReference.RefObjKey key = (ChaReference.RefObjKey) Enum.Parse(typeof(ChaReference.RefObjKey), parentStr);
                     * GameObject referenceInfo = __instance.GetReferenceInfo(key);
                     */
                    GameObject referenceInfo = __instance.GetComponentsInChildren <Transform>(true).FirstOrDefault(x => x.name == parentStr)?.gameObject;
                    if (referenceInfo == null)
                    {
                        __result = false;
                        return(false);
                    }
                    gameObject.transform.SetParent(referenceInfo.transform, worldPositionStays: false);
                    __instance.nowCoordinate.accessory.parts[slotNo].parentKey   = parentStr;
                    __instance.nowCoordinate.accessory.parts[slotNo].partsOfHead = ChaAccessoryDefine.CheckPartsOfHead(parentStr);
                }
                catch (ArgumentException)
                {
                    __result = false;
                    return(false);
                }
                __result = true;
                return(false);
            }
Ejemplo n.º 17
0
 internal void ClearColliders()
 {
     foreach (DynamicBone dynamicBone in m_collisionCharacter.GetComponentsInChildren <DynamicBone>())
     {
         if (dynamicBone.name.Contains(BoneNames.BPBone))
         {
             dynamicBone.m_Colliders.Clear();
         }
     }
 }
Ejemplo n.º 18
0
 internal void ClearColliders()
 {
     foreach (DynamicBone dynamicBone in m_collisionCharacter.GetComponentsInChildren <DynamicBone>())
     {
         if ((dynamicBone.name.Contains(BoneNames.BPBone) || dynamicBone.name.Contains(BoneNames.BellyBone)) &&
             m_collisionCharacter == dynamicBone.GetComponentInParent <ChaControl>())
         {
             dynamicBone.m_Colliders.Clear();
         }
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Needed a standard way to pull bones from ChaControl obj
        /// </summary>
        internal static Transform GetBone(ChaControl chaControl, string boneName)
        {
            if (chaControl == null)
            {
                return(null);
            }
            if (boneName.Contains("."))
            {
                return(null);
            }

            return(chaControl.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name == boneName));
        }
Ejemplo n.º 20
0
        // Return the offset of the eyes in the head's object space.
        public static Vector3 GetEyesOffset(ChaControl chaCtrl)
        {
            Transform head = chaCtrl.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(Controller.headBone)).FirstOrDefault();

            Transform[] eyes = new Transform[2];
            eyes[0] = chaCtrl.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(Controller.leftEyePupil)).FirstOrDefault();
            eyes[1] = chaCtrl.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(Controller.rightEyePupil)).FirstOrDefault();

            if (HS2_PovX.CameraPoVLocation.Value == HS2_PovX.CameraLocation.LeftEye)
            {
                return(GetEyesOffsetInternal(head, eyes[0]));
            }
            else if (HS2_PovX.CameraPoVLocation.Value == HS2_PovX.CameraLocation.RightEye)
            {
                return(GetEyesOffsetInternal(head, eyes[1]));
            }

            return(Vector3.Lerp(
                       GetEyesOffsetInternal(head, eyes[0]),
                       GetEyesOffsetInternal(head, eyes[1]),
                       0.5f));
        }
Ejemplo n.º 21
0
 internal void RemoveDanColliders(ChaControl target)
 {
     foreach (var danCollider in m_danColliders)
     {
         foreach (DynamicBone dynamicBone in target.GetComponentsInChildren <DynamicBone>())
         {
             if (danCollider != null && dynamicBone.name.Contains(BoneNames.BPBone))
             {
                 dynamicBone.m_Colliders.Remove(danCollider);
             }
         }
     }
 }
Ejemplo n.º 22
0
        private static void FixHairAccessories(ChaControl chaControl)
        {
            try
            {
                if (chaControl?.chaFile?.custom?.hair.parts[0] == null)
                {
                    return;
                }

                Texture2D texHairGloss = (Texture2D)AccessTools.Property(typeof(ChaControl), "texHairGloss").GetValue(chaControl, null);
                foreach (ChaCustomHairComponent x in chaControl.GetComponentsInChildren <ChaCustomHairComponent>(true))
                {
                    Color baseColor    = chaControl.chaFile.custom.hair.parts[0].baseColor;
                    Color endColor     = chaControl.chaFile.custom.hair.parts[0].endColor;
                    Color startColor   = chaControl.chaFile.custom.hair.parts[0].startColor;
                    Color outlineColor = chaControl.chaFile.custom.hair.parts[0].outlineColor;

                    foreach (Renderer y in x.rendHair)
                    {
                        Material material = y.material;

                        if (material.HasProperty("_Color") && MatchColor.Value)
                        {
                            material.SetColor("_Color", baseColor);
                        }

                        if (material.HasProperty("_Color2") && MatchColor.Value)
                        {
                            material.SetColor("_Color2", startColor);
                        }

                        if (material.HasProperty("_Color3") && MatchColor.Value)
                        {
                            material.SetColor("_Color3", endColor);
                        }

                        if (material.HasProperty(ChaShader._HairGloss) && MatchGloss.Value)
                        {
                            material.SetTexture(ChaShader._HairGloss, texHairGloss);
                        }

                        if (material.HasProperty(ChaShader._LineColor) && MatchOutlineColor.Value)
                        {
                            material.SetColor(ChaShader._LineColor, outlineColor);
                        }
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 23
0
        public static void SetTargetCharacter(ChaControl character)
        {
            if (targetCharacter == character)
            {
                return;
            }

            targetCharacter = character;
            if (targetCharacter == null)
            {
                return;
            }

            lockTarget = targetCharacter.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(lockBone)).FirstOrDefault();
        }
Ejemplo n.º 24
0
        public static void RotateCharacterHead(ChaControl character, float rotationX)
        {
            if (!povEnabled)
            {
                return;
            }

            Console.WriteLine($"RotateCharacterHead {character.name} {rotationX}");

            agentHead = character.GetComponentsInChildren <Transform>().Where(x => x.name.Equals(headBone)).FirstOrDefault();

            if (agentHead == null)
            {
                return;
            }

            agentHeadTargetRotation  = new Vector3(rotationX, 0, 0);
            agentHeadRotationReached = false;
        }
Ejemplo n.º 25
0
        public void InitializeDanAgent()
        {
            ClearDanAgent();

            danEntryTarget = ChaControl.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Equals("k_f_dan_entry"));
            danEndTarget   = ChaControl.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Equals("k_f_dan_end"));

            if (danEntryTarget == null || danEndTarget == null)
            {
                return;
            }

            if (danOptions == null)
            {
                danOptions = new DanOptions(DefaultColliderVertical, DefaultColliderRadius, DefaultColliderLength, DefaultLengthSquish, DefaultGirthSquish, DefaultSquishThreshold);
            }

            danAgent        = new DanAgent(ChaControl, danOptions);
            danTargetsValid = true;
        }
Ejemplo n.º 26
0
        internal static List <DynamicBoneCollider> GetCharacterAnaItemColliders(ChaControl character, string animation)
        {
            var itemList = new List <DynamicBoneCollider>();

            if (character == null || anaItemColliderInfo == null)
            {
                return(itemList);
            }

            foreach (var boneInfo in anaItemColliderInfo)
            {
                if (!boneInfo.animationNames.Contains(animation))
                {
                    continue;
                }

                foreach (var boneName in boneInfo.itemBones)
                {
                    var bones = character.GetComponentsInChildren <Transform>().Where(bone => bone.name.Equals(boneName));
                    if (bones == null || bones.Count() == 0)
                    {
                        break;
                    }

                    foreach (var bone in bones)
                    {
                        float radiusScale = Tools.ComputeRadiusScale(bone, boneInfo.direction);
                        float heightScale = Tools.ComputeHeightScale(bone, boneInfo.direction);

                        var collider = Tools.InitializeCollider(bone, boneInfo.colliderRadius * radiusScale, boneInfo.colliderHeight * heightScale, Vector3.zero, boneInfo.direction);
                        itemList.Add(collider);
                    }
                }
            }

            return(itemList);
        }
Ejemplo n.º 27
0
        private void InitializeDan()
        {
            List <Transform> danTransforms = new List <Transform>();

            foreach (var boneName in BoneNames.DanBones)
            {
                Transform danBone = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(boneName));
                if (danBone != null)
                {
                    danTransforms.Add(danBone);
                }
            }

            Transform tamaTop = m_danCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.TamaTop));

            if (tamaTop == null || danTransforms.Count < 2)
            {
                return;
            }

            if (danTransforms.Count == BoneNames.DanBones.Count)
            {
                m_bpDanPointsFound = true;
            }

            m_danPoints      = new DanPoints(danTransforms, tamaTop);
            m_danPointsFound = true;

            m_baseDanLength         = DefaultDanLength * m_danPoints.GetDanLossyScale();
            m_baseSectionHalfLength = m_baseDanLength / (2 * (m_danPoints.danPoints.Count - 1));

            for (int danPoint = 1; danPoint < m_danPoints.danPoints.Count; danPoint++)
            {
                m_danColliders.Add(InitializeCollider(m_danPoints.danPoints[danPoint - 1].transform, m_danOptions.danRadius * m_danPoints.danPoints[danPoint].defaultLossyScale.x, ((m_baseSectionHalfLength + m_danOptions.danHeadLength) * 2),
                                                      new Vector3(0, m_danOptions.danVerticalCenter, m_baseSectionHalfLength), DynamicBoneCollider.Direction.Z));
            }
        }
Ejemplo n.º 28
0
        private void Initialize(ChaControl character, CollisionOptions options)
        {
            m_collisionOptions = options;

            List <CollisionPoint> frontCollisionPoints = new List <CollisionPoint>();
            List <CollisionPoint> backCollisionPoints  = new List <CollisionPoint>();

            m_collisionPointsFound = false;

            if (character == null)
            {
                return;
            }

            m_collisionCharacter = character;

            m_kokanBone = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.KokanBone));
            if (m_kokanBone == null)
            {
                return;
            }

            for (int index = 0; index < options.frontCollisionInfo.Count; index++)
            {
                Transform frontCollisionPoint = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(options.frontCollisionInfo[index].name));
                frontCollisionPoints.Add(new CollisionPoint(frontCollisionPoint, options.frontCollisionInfo[index]));
            }
            for (int index = 0; index < options.backCollisonInfo.Count; index++)
            {
                Transform backCollisionPoint = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(options.backCollisonInfo[index].name));
                backCollisionPoints.Add(new CollisionPoint(backCollisionPoint, options.backCollisonInfo[index]));
            }

            m_bpKokanTarget = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Equals(LookTargets.BPKokanTarget));
            if (m_bpKokanTarget != null)
            {
                frontCollisionPoints[0].transform = m_bpKokanTarget;
                frontCollisionPoints[0].info.name = LookTargets.BPKokanTarget;
            }

            m_innerTarget     = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Equals(LookTargets.InnerTarget));
            m_innerHeadTarget = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(LookTargets.InnerHeadTarget));

            if (frontCollisionPoints.Count == options.frontCollisionInfo.Count &&
                backCollisionPoints.Count == options.backCollisonInfo.Count &&
                m_innerTarget != null && m_innerHeadTarget != null)
            {
                m_collisionPointsFound = true;
                m_collisionPoints      = new CollisionPoints(frontCollisionPoints, backCollisionPoints);
            }

            Debug.Log($"constrainPointsFound {m_collisionPointsFound}");

            m_kokanDynamicBones = new List <DynamicBone>();
            foreach (DynamicBone dynamicBone in m_collisionCharacter.GetComponentsInChildren <DynamicBone>())
            {
                if (dynamicBone == null || dynamicBone.m_Root == null || dynamicBone.name == null || !dynamicBone.name.Contains(BoneNames.BPBone))
                {
                    continue;
                }

                dynamicBone.m_Colliders.Clear();
                m_kokanDynamicBones.Add(dynamicBone);
            }
        }
Ejemplo n.º 29
0
        private void Initialize(ChaControl character, CollisionOptions options)
        {
            m_collisionOptions = options;

            List <CollisionPoint> frontCollisionPoints = new List <CollisionPoint>();
            List <CollisionPoint> backCollisionPoints  = new List <CollisionPoint>();

            m_collisionPointsFound = false;

            if (character == null)
            {
                return;
            }

            m_collisionCharacter = character;

            m_kokanBone = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(BoneNames.KokanBone));
            if (m_kokanBone == null)
            {
                return;
            }

            for (int index = 0; index < options.frontCollisionInfo.Count; index++)
            {
                Transform frontCollisionPoint = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(options.frontCollisionInfo[index].name));
                frontCollisionPoints.Add(new CollisionPoint(frontCollisionPoint, options.frontCollisionInfo[index]));
            }
            for (int index = 0; index < options.backCollisonInfo.Count; index++)
            {
                Transform backCollisionPoint = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(options.backCollisonInfo[index].name));
                backCollisionPoints.Add(new CollisionPoint(backCollisionPoint, options.backCollisonInfo[index]));
            }

            m_bpKokanTarget = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Equals(LookTargets.BPKokanTarget));
            if (m_bpKokanTarget != null)
            {
                Console.WriteLine("BP Target Found " + m_bpKokanTarget.name);
                frontCollisionPoints[0].transform = m_bpKokanTarget;
                frontCollisionPoints[0].info.name = LookTargets.BPKokanTarget;
            }

            m_innerTarget     = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Equals(LookTargets.InnerTarget));
            m_innerHeadTarget = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(LookTargets.InnerHeadTarget));

            if (frontCollisionPoints.Count == options.frontCollisionInfo.Count && backCollisionPoints.Count == options.backCollisonInfo.Count)
            {
                m_collisionPointsFound = true;
                m_collisionPoints      = new CollisionPoints(frontCollisionPoints, backCollisionPoints);
            }

            Console.WriteLine("constrainPointsFound " + m_collisionPointsFound);

            m_kokanDynamicBones = new List <DynamicBone>();
            foreach (DynamicBone dynamicBone in m_collisionCharacter.GetComponentsInChildren <DynamicBone>())
            {
                if (!dynamicBone.name.Contains(BoneNames.BPBone))
                {
                    continue;
                }

                dynamicBone.m_Colliders.Clear();

                if (dynamicBone == null || dynamicBone.m_Root == null)
                {
                    continue;
                }

                if (!BoneNames.uncensorBoneList.TryGetValue(dynamicBone.m_Root.name, out UncensorDynamicBone dynamicBoneValues))
                {
                    continue;
                }

                if (dynamicBoneValues.direction == UncensorDynamicBone.DynamicBoneDirection.Z)
                {
                    dynamicBone.m_Radius *= m_kokanBone.lossyScale.z;
                }
                else if (dynamicBoneValues.direction == UncensorDynamicBone.DynamicBoneDirection.Z)
                {
                    dynamicBone.m_Radius *= m_kokanBone.lossyScale.x;
                }
                else
                {
                    dynamicBone.m_Radius *= (m_kokanBone.lossyScale.x + m_kokanBone.lossyScale.z) / 2;
                }

#if HS2 || AIS
                dynamicBone.UpdateParameters();
#endif
                m_kokanDynamicBones.Add(dynamicBone);

                if (!m_collisionOptions.useBoundingColliders || dynamicBoneValues.selfColliderName == null)
                {
                    continue;
                }

                DynamicBoneCollider selfCollider = m_collisionCharacter.GetComponentsInChildren <DynamicBoneCollider>().FirstOrDefault(x => x.name != null && x.name.Contains(dynamicBoneValues.selfColliderName));
                if (selfCollider == null)
                {
                    Transform colliderTransform = m_collisionCharacter.GetComponentsInChildren <Transform>().FirstOrDefault(x => x.name != null && x.name.Contains(dynamicBoneValues.selfColliderName));
                    if (colliderTransform == null)
                    {
                        continue;
                    }

                    selfCollider             = colliderTransform.gameObject.AddComponent(typeof(DynamicBoneCollider)) as DynamicBoneCollider;
                    selfCollider.m_Bound     = DynamicBoneCollider.Bound.Inside;
                    selfCollider.m_Direction = DynamicBoneCollider.Direction.Y;

                    if (dynamicBoneValues.direction == UncensorDynamicBone.DynamicBoneDirection.Z)
                    {
                        selfCollider.m_Height = dynamicBoneValues.selfColliderHeight * m_kokanBone.lossyScale.z;
                        selfCollider.m_Radius = dynamicBoneValues.selfColliderRadius * m_kokanBone.lossyScale.z;
                    }
                    else if (dynamicBoneValues.direction == UncensorDynamicBone.DynamicBoneDirection.X)
                    {
                        selfCollider.m_Height = dynamicBoneValues.selfColliderHeight * m_kokanBone.lossyScale.x;
                        selfCollider.m_Radius = dynamicBoneValues.selfColliderRadius * m_kokanBone.lossyScale.x;
                    }
                    else
                    {
                        selfCollider.m_Height = dynamicBoneValues.selfColliderHeight * (m_kokanBone.lossyScale.x + m_kokanBone.lossyScale.z) / 2;
                        selfCollider.m_Radius = dynamicBoneValues.selfColliderRadius * (m_kokanBone.lossyScale.x + m_kokanBone.lossyScale.z) / 2;
                    }
                }

                dynamicBone.m_Colliders.Add(selfCollider);
            }
        }
Ejemplo n.º 30
0
            public void SetState(bool isVisible)
            {
                if (_lastState == isVisible)
                {
                    return;
                }
                if (Scene.Instance.IsNowLoadingFade)
                {
                    return;
                }

                _lastState = isVisible;

                foreach (var bone in _chara.GetComponentsInChildren <MonoBehaviour>(true))
                {
                    if (!bone)
                    {
                        continue;
                    }

                    // Setting bone.enabled to false breaks it so we have to hack around by setting Root to null which effectively disables the bones
                    switch (bone)
                    {
                    case DynamicBone x:
                        if (isVisible)
                        {
                            if (x.m_Root == null && _originalroots.TryGetValue(x, out var r))
                            {
                                x.m_Root = r;
                            }
                        }
                        else
                        {
                            if (x.m_Root != null)
                            {
                                _originalroots[x] = x.m_Root;
                                x.m_Root          = null;
                            }
                        }

                        break;

                    case DynamicBone_Ver01 x:
                        if (isVisible)
                        {
                            if (x.m_Root == null && _originalroots.TryGetValue(x, out var r))
                            {
                                x.m_Root = r;
                            }
                        }
                        else
                        {
                            if (x.m_Root != null)
                            {
                                _originalroots[x] = x.m_Root;
                                x.m_Root          = null;
                            }
                        }
                        break;

                    case DynamicBone_Ver02 x:
                        if (isVisible)
                        {
                            if (x.Root == null && _originalroots.TryGetValue(x, out var r))
                            {
                                x.Root = r;
                            }
                        }
                        else
                        {
                            if (x.Root != null)
                            {
                                _originalroots[x] = x.Root;
                                x.Root            = null;
                            }
                        }
                        break;
                    }
                }
            }