Esempio n. 1
0
        /** The high-frequency routine to call 30+ times per second.
         *
         *      @param now the current time, in seconds.
         *      @param viseme_weights An array of current weights of the viseme blend shapes.
         *       Values will be updated according to the synthesis time.
         *       The size of this vector must be the same of the module static vector of visemes.
         *       Values will be clamped in the range [0,1].
         *      @returns None
         */
        public void update(float now, double[] viseme_weights)
        {
            if (viseme_weights.Length != VISEMES.Length)
            {
                throw new BlinkException("Viseme weight vector has wrong size."
                                         + " Expected " + VISEMES.Length + ", found " + viseme_weights.Length);
            }

            if (this.last_time == -1.0f)
            {
                this.last_time = now;
                return;
            }

            float delta_time = now - this.last_time;

            this.last_time = now;

            //
            //
            if (this.blink_status == BlinkStatus.WAITING)
            {
                if (now >= this.next_blink_time)
                {
                    this.blink_status = BlinkStatus.CLOSING;
                }
            }
            else if (this.blink_status == BlinkStatus.CLOSING)
            {
                float delta_close = EYE_CLOSE_SPEED * delta_time;
                this.current_weight += delta_close;
                if (this.current_weight >= 1.0f)
                {
                    this.current_weight = 1.0f;
                    this.blink_status   = BlinkStatus.OPENING;
                }
            }
            else if (this.blink_status == BlinkStatus.OPENING)
            {
                float delta_open = EYE_OPEN_SPEED * delta_time;
                this.current_weight -= delta_open;
                if (this.current_weight <= 0.0f)
                {
                    this.current_weight = 0.0f;
                    this.blink_status   = BlinkStatus.WAITING;
                    // Compute next closing time
                    float delay = MIN_DELAY + (MAX_DELAY - MIN_DELAY) * (float)random.NextDouble();

                    this.next_blink_time = now + delay;
                }
            }

            //
            // UPDATE THE WEIGHTS VECTOR
            for (int i = 0; i < VISEMES.Length; i++)
            {
                //string viseme = VISEMES[i];
                // update the weight
                viseme_weights[i] = this.current_weight;
            }
        }          // end update
Esempio n. 2
0
    protected override void onPartFixedUpdate()
    {
        core.onPartFixedUpdate();
        base.onPartFixedUpdate();

        if (eye == null)
        {
            eye = transform.Find("model/base/eye");
            if (eye == null)
            {
                return;
            }
        }
        if (cam == null)
        {
            cam = (FlightCamera)GameObject.FindObjectOfType(typeof(FlightCamera));
        }

        if (innereye == null)
        {
            eyelid    = new Transform[2];
            eyelidRot = new Quaternion[2];

            eyelid[0] = eye.Find("eyelid1");
            eyelid[1] = eye.Find("eyelid2");
            if (eyelid[0] != null)
            {
                eyelidRot[0] = eyelid[0].localRotation;
            }
            if (eyelid[1] != null)
            {
                eyelidRot[1] = eyelid[1].localRotation;
            }

            innereye = eye.Find("innereye");
            if (innereye != null)
            {
                innereyeRot = innereye.localRotation;
            }

            doors = new LandingLeg[] { null, null, null, null };
            if (vessel != null)
            {
                foreach (Part p in vessel.parts)
                {
                    if (p.name == "MultiMech.JebPod.Leg")
                    {
                        doors[0] = (LandingLeg)p;
                        for (int i = 0; i < Math.Min(3, p.symmetryCounterparts.Count); i++)
                        {
                            doors[i + 1] = (LandingLeg)p.symmetryCounterparts[i];
                        }
                    }
                }
            }
        }

        brainStress += core.stress * TimeWarp.fixedDeltaTime;
        brainStress -= brainStress * (((doors[0] == null) || (doors[0].legState == LandingLeg.LegStates.DEPLOYED)) ? brainStressReliefOpen : brainStressReliefClosed) * TimeWarp.fixedDeltaTime;

        if ((brainStress > brainStressMin) && ((doors[0] == null) || (doors[0].legState == LandingLeg.LegStates.DEPLOYED)))
        {
            brain[0].particleEmitter.maxEmission = brain[1].particleEmitter.maxEmission = (brainStress - brainStressMin) * 1000.0F;
            brain[0].particleEmitter.minEmission = brain[1].particleEmitter.minEmission = brain[0].particleEmitter.maxEmission / 2.0F;
            brain[0].particleEmitter.emit        = brain[1].particleEmitter.emit = true;
        }
        else
        {
            brain[0].particleEmitter.emit = brain[1].particleEmitter.emit = false;
        }

        if (brainStress >= brainStressMax)
        {
            foreach (LandingLeg door in doors)
            {
                if ((door != null) && (door.legState == LandingLeg.LegStates.RETRACTED))
                {
                    door.DeployOnActivate = true;
                    door.force_activate();
                }
            }
        }

        if (vessel.Landed || vessel.Splashed)
        {
            eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime);

            if ((eyelid[0] != null) && (eyelid[1] != null))
            {
                eyelid[0].localRotation = eyelidRot[0];
                eyelid[1].localRotation = eyelidRot[1];
            }
        }
        else
        {
            if (core.attitudeActive)
            {
                eye.rotation = Quaternion.RotateTowards(eye.rotation, core.attitudeGetReferenceRotation(core.attitudeReference) * core.attitudeTarget * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime);
            }
            else
            {
                if (brainStress < brainStressMin)
                {
                    eye.rotation = Quaternion.RotateTowards(eye.rotation, Quaternion.LookRotation((cam.transform.position - eye.position).normalized, cam.transform.up) * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime);
                }
                else
                {
                    eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime);
                }
            }

            if ((eyelid[0] == null) || (eyelid[1] == null) || (innereye == null))
            {
                return;
            }

            double eyeStressAngle = Math.Max(5, 27 - brainStress / 2);

            if ((blinkStatus == BlinkStatus.NONE) && (UnityEngine.Random.Range(0, 10.0F / TimeWarp.fixedDeltaTime) < (Time.time - blinkLast)))
            {
                blinkStatus   = BlinkStatus.CLOSING;
                blinkProgress = 0;
            }

            switch (blinkStatus)
            {
            case BlinkStatus.CLOSING:
                eyeStressAngle *= 1 - blinkProgress;
                blinkProgress   = Mathf.Clamp01(blinkProgress + TimeWarp.fixedDeltaTime * 10);
                if (blinkProgress >= 1)
                {
                    blinkStatus   = BlinkStatus.OPENING;
                    blinkProgress = 0;
                }
                break;

            case BlinkStatus.OPENING:
                eyeStressAngle *= blinkProgress;
                blinkProgress   = Mathf.Clamp01(blinkProgress + TimeWarp.fixedDeltaTime * 10);
                if (blinkProgress >= 1)
                {
                    blinkStatus = BlinkStatus.NONE;
                    blinkLast   = Time.time;
                }
                break;
            }

            eyelid[0].localRotation = eyelidRot[0] * Quaternion.AngleAxis((float)eyeStressAngle, -Vector3.right);
            eyelid[1].localRotation = eyelidRot[1] * Quaternion.AngleAxis((float)eyeStressAngle, Vector3.right);

            innereye.localRotation = innereyeRot * Quaternion.AngleAxis((Mathf.PingPong(Time.time, 0.05f) * 40 - 1) * Mathf.Sqrt(brainStress) / 10, Vector3.forward);
        }
    }
Esempio n. 3
0
    protected override void onPartFixedUpdate()
    {
        core.onPartFixedUpdate();
        base.onPartFixedUpdate();

        if (eye == null)
        {
            eye = transform.Find("model/base/eye");
            if (eye == null)
            {
                return;
            }
        }
        if (cam == null)
        {
            cam = (FlightCamera)GameObject.FindObjectOfType(typeof(FlightCamera));
        }

        if (innereye == null)
        {
            eyelid = new Transform[2];
            eyelidRot = new Quaternion[2];

            eyelid[0] = eye.Find("eyelid1");
            eyelid[1] = eye.Find("eyelid2");
            if (eyelid[0] != null)
            {
                eyelidRot[0] = eyelid[0].localRotation;
            }
            if (eyelid[1] != null)
            {
                eyelidRot[1] = eyelid[1].localRotation;
            }

            innereye = eye.Find("innereye");
            if (innereye != null)
            {
                innereyeRot = innereye.localRotation;
            }

            doors = new LandingLeg[] { null, null, null, null };
            if (vessel != null)
            {
                foreach (Part p in vessel.parts)
                {
                    if (p.name == "MultiMech.JebPod.Leg")
                    {
                        doors[0] = (LandingLeg)p;
                        for (int i = 0; i < Math.Min(3, p.symmetryCounterparts.Count); i++)
                        {
                            doors[i + 1] = (LandingLeg)p.symmetryCounterparts[i];
                        }
                    }
                }
            }
        }

        brainStress += core.stress * TimeWarp.fixedDeltaTime;
        brainStress -= brainStress * (((doors[0] == null) || (doors[0].legState == LandingLeg.LegStates.DEPLOYED)) ? brainStressReliefOpen : brainStressReliefClosed) * TimeWarp.fixedDeltaTime;

        if ((brainStress > brainStressMin) && (doors[0] == null) || (doors[0].legState == LandingLeg.LegStates.DEPLOYED))
        {
            brain[0].particleEmitter.maxEmission = brain[1].particleEmitter.maxEmission = (brainStress - brainStressMin) * 1000.0F;
            brain[0].particleEmitter.minEmission = brain[1].particleEmitter.minEmission = brain[0].particleEmitter.maxEmission / 2.0F;
            brain[0].particleEmitter.emit = brain[1].particleEmitter.emit = true;
        }
        else
        {
            brain[0].particleEmitter.emit = brain[1].particleEmitter.emit = false;
        }

        if (brainStress >= brainStressMax)
        {
            foreach (LandingLeg door in doors)
            {
                if ((door != null) && (door.legState == LandingLeg.LegStates.RETRACTED))
                {
                    door.DeployOnActivate = true;
                    door.force_activate();
                }
            }
        }

        if (vessel.Landed || vessel.Splashed)
        {
            eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime);

            if ((eyelid[0] != null) && (eyelid[1] != null))
            {
                eyelid[0].localRotation = eyelidRot[0];
                eyelid[1].localRotation = eyelidRot[1];
            }
        }
        else
        {
            if (core.attitudeActive)
            {
                eye.rotation = Quaternion.RotateTowards(eye.rotation, core.attitudeGetReferenceRotation(core.attitudeReference) * core.attitudeTarget * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime);
            }
            else
            {
                if (brainStress < brainStressMin)
                {
                    eye.rotation = Quaternion.RotateTowards(eye.rotation, Quaternion.LookRotation((cam.transform.position - eye.position).normalized, cam.transform.up) * Quaternion.Euler(90, 0, 0), 360 * TimeWarp.fixedDeltaTime);
                }
                else
                {
                    eye.localRotation = Quaternion.RotateTowards(eye.localRotation, Quaternion.identity, 360 * TimeWarp.fixedDeltaTime);
                }
            }

            if ((eyelid[0] == null) || (eyelid[1] == null) || (innereye == null))
            {
                return;
            }

            double eyeStressAngle = Math.Max(5, 27 - brainStress / 2);

            if ((blinkStatus == BlinkStatus.NONE) && (UnityEngine.Random.Range(0, 10.0F / TimeWarp.fixedDeltaTime) < (Time.time - blinkLast)))
            {
                blinkStatus = BlinkStatus.CLOSING;
                blinkProgress = 0;
            }

            switch (blinkStatus)
            {
                case BlinkStatus.CLOSING:
                    eyeStressAngle *= 1 - blinkProgress;
                    blinkProgress = Mathf.Clamp01(blinkProgress + TimeWarp.fixedDeltaTime * 10);
                    if (blinkProgress >= 1)
                    {
                        blinkStatus = BlinkStatus.OPENING;
                        blinkProgress = 0;
                    }
                    break;
                case BlinkStatus.OPENING:
                    eyeStressAngle *= blinkProgress;
                    blinkProgress = Mathf.Clamp01(blinkProgress + TimeWarp.fixedDeltaTime * 10);
                    if (blinkProgress >= 1)
                    {
                        blinkStatus = BlinkStatus.NONE;
                        blinkLast = Time.time;
                    }
                    break;
            }

            eyelid[0].localRotation = eyelidRot[0] * Quaternion.AngleAxis((float)eyeStressAngle, -Vector3.right);
            eyelid[1].localRotation = eyelidRot[1] * Quaternion.AngleAxis((float)eyeStressAngle, Vector3.right);

            innereye.localRotation = innereyeRot * Quaternion.AngleAxis((Mathf.PingPong(Time.time, 0.05f) * 40 - 1) * Mathf.Sqrt(brainStress) / 10, Vector3.forward);
        }
    }