public IEnumerator OffsetSpine(Global.BodyOffset type, float strength = 100.0f, int frames = Setting.bodyOffsetBlend)
    {
        float previous = offset;
        float next;

        if (type == Global.BodyOffset.FORWARD)
        {
            next = Setting.bodyLeanExtreme * strength / 100.0f;
        }
        else if (type == Global.BodyOffset.BACKWARD)
        {
            next = Setting.bodyLeanExtreme * strength / 100.0f;
        }
        else
        {
            next = 0.0f;
        }

        for (int i = 0; i <= frames; i++)
        {
            yield return(null);

            float currentVal = Mathf.Lerp(previous, next, (float)i / (float)frames);
            offset = currentVal;
        }
    }
Exemple #2
0
    public IEnumerator OffsetMain(Global.BodyOffset type, float strength = 100.0f, int frames = Setting.bodyOffsetBlend)
    {
        // store previous value
        lHandPre     = effector.leftHandOffset;
        rHandPre     = effector.rightHandOffset;
        lShoulderPre = effector.leftHandOffset;
        rShoulderPre = effector.leftHandOffset;

        // determine the next value based on offset type and strength
        if (type == Global.BodyOffset.BACKWARD)
        {
            lHandNext     = lHandBackward * strength / 100.0f;
            rHandNext     = rHandBackward * strength / 100.0f;
            lShoulderNext = lShoulderBackward * strength / 100.0f;
            rShoulderNext = rShoulderBackward * strength / 100.0f;
        }
        else if (type == Global.BodyOffset.FORWARD)
        {
            lHandNext     = lHandForward * strength / 100.0f;
            rHandNext     = rHandForward * strength / 100.0f;
            lShoulderNext = lShoulderForward * strength / 100.0f;
            rShoulderNext = rShoulderForward * strength / 100.0f;
        }
        else
        {
            lHandNext     = new Vector3(0.0f, 0.0f, 0.0f);
            rHandNext     = new Vector3(0.0f, 0.0f, 0.0f);
            lShoulderNext = new Vector3(0.0f, 0.0f, 0.0f);
            rShoulderNext = new Vector3(0.0f, 0.0f, 0.0f);
        }

        for (int i = 0; i <= frames; i++)
        {
            yield return(null);

            Vector3 lHandCurrent     = Vector3.Lerp(lHandPre, lHandNext, (float)i / (float)frames);
            Vector3 rHandCurrent     = Vector3.Lerp(rHandPre, rHandNext, (float)i / (float)frames);
            Vector3 lShoulderCurrent = Vector3.Lerp(lShoulderPre, lShoulderNext, (float)i / (float)frames);
            Vector3 rShoulderCurrent = Vector3.Lerp(rShoulderPre, rShoulderNext, (float)i / (float)frames);
            effector.leftHandOffset.Set(lHandCurrent.x, lHandCurrent.y, lHandCurrent.z);
            effector.rightHandOffset.Set(rHandCurrent.x, rHandCurrent.y, rHandCurrent.z);
            effector.leftShoulderOffset.Set(lShoulderCurrent.x, lShoulderCurrent.y, lShoulderCurrent.z);
            effector.rightShoulderOffset.Set(rShoulderCurrent.x, rShoulderCurrent.y, rShoulderCurrent.z);
        }
    }
 public void CharacterOffset(Global.BodyOffset type, int strength)
 {
     StartCoroutine(spineOffsetCtrl.OffsetSpine(type, strength));
     StartCoroutine(mainOffsetCtrl.OffsetMain(type, strength));
 }
    // Trigger event based on event name and event attribute+value
    private void TriggerEvent(string eventName)
    {
        if (eventName == "gesture")
        {
            float  speed = 1.0f, blend = 0.15f;
            int    strength = 100;
            string type     = "neutral";

            // Required
            int poseIndex = int.Parse(root.ChildNodes.Item(action).Attributes["pose"].Value);
            // Optional
            if (root.ChildNodes.Item(action).Attributes["speed"] != null)
            {
                speed = float.Parse(root.ChildNodes.Item(action).Attributes["speed"].Value);
            }
            if (root.ChildNodes.Item(action).Attributes["blend"] != null)
            {
                blend = float.Parse(root.ChildNodes.Item(action).Attributes["blend"].Value);
            }
            if (root.ChildNodes.Item(action).Attributes["offset"] != null)
            {
                type = root.ChildNodes.Item(action).Attributes["offset"].Value;
            }
            if (root.ChildNodes.Item(action).Attributes["strength"] != null)
            {
                strength = int.Parse(root.ChildNodes.Item(action).Attributes["strength"].Value);
            }

            //
            Global.BodyOffset offsetType = Global.BodyOffset.NEUTRAL;
            if (type == "forward")
            {
                offsetType = Global.BodyOffset.FORWARD;
            }
            else if (type == "backward")
            {
                offsetType = Global.BodyOffset.BACKWARD;
            }
            else if (type == "inward")
            {
                offsetType = Global.BodyOffset.INWARD;
            }
            else if (type == "outward")
            {
                offsetType = Global.BodyOffset.OUTWARD;
            }

            currentEvent.ChangePose(poseIndex, speed, blend);
            currentEvent.CharacterOffset(offsetType, strength);
        }

        if (eventName == "facial")
        {
            int strength = 100;

            // Required
            string emotion = root.ChildNodes.Item(action).Attributes["emotion"].Value;
            // Optional
            if (root.ChildNodes.Item(action).Attributes["strength"] != null)
            {
                strength = int.Parse(root.ChildNodes.Item(action).Attributes["strength"].Value);
            }

            //
            Global.Emotion emotionType = Global.Emotion.CONTENT;
            if (emotion == "angry")
            {
                emotionType = Global.Emotion.ANGRY;
            }
            else if (emotion == "bored")
            {
                emotionType = Global.Emotion.BORED;
            }
            else if (emotion == "content")
            {
                emotionType = Global.Emotion.CONTENT;
            }
            else if (emotion == "happy")
            {
                emotionType = Global.Emotion.HAPPY;
            }

            currentEvent.SetExpression(emotionType, strength);
        }

        if (eventName == "hand")
        {
            // Required
            string side  = root.ChildNodes.Item(action).Attributes["side"].Value;
            string shape = root.ChildNodes.Item(action).Attributes["shape"].Value;

            //
            Global.Side sideType = Global.Side.BOTH;
            if (side == "L")
            {
                sideType = Global.Side.LEFT;
            }
            else if (side == "R")
            {
                sideType = Global.Side.RIGHT;
            }

            Global.HandPose handType = Global.HandPose.RELAX;
            if (shape == "relax")
            {
                handType = Global.HandPose.RELAX;
            }
            else if (shape == "palm")
            {
                handType = Global.HandPose.PALM;
            }
            else if (shape == "fist")
            {
                handType = Global.HandPose.FIST;
            }

            currentEvent.SetHandShape(sideType, handType);
        }

        if (eventName == "foot")
        {
            // Required
            string status = root.ChildNodes.Item(action).Attributes["status"].Value;
            //
            if (status == "lock")
            {
                currentEvent.LockFoot(true);
            }
            else
            {
                currentEvent.LockFoot(false);
            }
        }

        if (eventName == "request")
        {
            string message = "";
            // Optional
            if (root.ChildNodes.Item(action).Attributes["message"] != null)
            {
                message = root.ChildNodes.Item(action).Attributes["message"].Value;
            }

            currentEvent.CheckSignal();
        }

        if (eventName == "slide")
        {
            int step = 1;
            // Required
            string direction = root.ChildNodes.Item(action).Attributes["direction"].Value;
            // Optional
            if (root.ChildNodes.Item(action).Attributes["step"] != null)
            {
                step = int.Parse(root.ChildNodes.Item(action).Attributes["step"].Value);
            }

            //
            Global.Direction directionType = Global.Direction.NEXT;
            if (direction == "back")
            {
                directionType = Global.Direction.BACK;
            }

            currentEvent.ChangeSlide(directionType, step);
            currentEvent.ChangeAudio(directionType, step);
        }
    }