Esempio n. 1
0
 public override void Setup(float startTime)
 {
     hospitalRoom.separateHalves(SceneThree.MAX_SPLIT);
     speechBubble = new SpeechBubble(camera, hospitalRoom.guyCenterPoint);
     mouthMovement = new MouthAnimator(startTime, leftMouth, rightMouth);
     wiggler = new Wiggler(startTime, timeLength, new[] {speechBubble.centerPivot()});
 }
Esempio n. 2
0
 public override void Setup(float startTime)
 {
     hospitalRoom.separateHalves(SceneThree.MAX_SPLIT);
     speechBubble  = new SpeechBubble(camera, hospitalRoom.guyCenterPoint);
     mouthMovement = new MouthAnimator(startTime, leftMouth, rightMouth);
     wiggler       = new Wiggler(startTime, timeLength, new[] { speechBubble.centerPivot() });
 }
Esempio n. 3
0
    void Start()
    {
        characterBaseImage = GetComponent <Image>();
        mouthAnimator      = GetComponentInChildren <MouthAnimator>();
        eyesAnimator       = GetComponentInChildren <EyesAnimator>();

        characterBaseImage.enabled = false;
        mouthAnimator.gameObject.SetActive(false);
        eyesAnimator.gameObject.SetActive(false);
    }
Esempio n. 4
0
    public override void Setup(float startTime)
    {
        endScene();

        bigHeadProp.Setup();

        mouthLeft.visible(true);
        mouthRight.visible(true);
        mouthLeft.setWorldPosition(-28.0f, -56f, -5f);
        mouthRight.setWorldPosition(10f, -56f, -5f);

        mouthAnimator = new MouthAnimator(startTime, mouthLeft, mouthRight);
    }
Esempio n. 5
0
    public override void Setup(float startTime)
    {
        endScene();

        bigHeadProp.Setup();

        mouthLeft.visible(true);
        mouthRight.visible(true);
        mouthLeft.setWorldPosition(-28.0f, -56f, -5f);
        mouthRight.setWorldPosition(10f, -56f, -5f);

        mouthAnimator = new MouthAnimator(startTime, mouthLeft, mouthRight);
    }
Esempio n. 6
0
    public override void Setup(float startTime)
    {
        bigHeadProp.Setup();
        faceRightParent = bigHeadProp.faceRight.createPivotOnTopLeftCorner();

        mouthLeft.setWorldPosition(-29.5f, -56f, -5f);

        mouthRight.gameObject.transform.parent = faceRightParent.transform;
        mouthRight.setWorldPosition(10f, -56f, -5f);

        mouthLeft.visible(true);
        mouthRight.visible(true);

        mouthAnimator = new MouthAnimator(startTime, mouthLeft, mouthRight);

        var pivot = bigHeadProp.faceRight.createPivotOnTopLeftCorner();

        mouthRight.transform.parent = pivot.transform;
        wiggler = new Wiggler(startTime, timeLength, new[] { pivot });
    }
Esempio n. 7
0
    // Called by Unity.
    void Update()
    {
        if (_activeAudioSource == null)
        {
            return;
        }

        // FFT with Blackman window.
        _activeAudioSource.GetSpectrumData(_samplesRaw, 0, _windowType);

        float oneMinusSmoothing = 1 - Smoothing;

        for (int i = 0; i < (int)_sampleCount; i++)
        {
            // Smoothing with previous frequency data.
            _lastSamples[i] = Smoothing * _lastSamples2[i] + oneMinusSmoothing * _lastSamples[i];
            _samplesRaw[i]  = Smoothing * _lastSamples[i] + oneMinusSmoothing * _samplesRaw[i];

            // Compute Y[k] in dB, should be between -25dB and -160db for properly scaled speech signals.
            _samples[i] = 20 * Mathf.Log10(_samplesRaw[i]);

            // Map range to interval [-0.5, 0.5]
            _samples[i] = SensitivityThreshold + (_samples[i] + 20) / 140f;

            // Copy old samples for smoothing.
            _lastSamples2[i] = _lastSamples[i];
            _lastSamples[i]  = _samplesRaw[i];
        }

        // Calculate energy for each bin.
        for (int i = 0; i < _binEnergy.Length - 1; i++)
        {
            int   indexStart = _frequencyDataIndices[i];
            int   indexEnd   = _frequencyDataIndices[i + 1];
            float binLength  = indexEnd - indexStart;

            for (int j = indexStart; j < indexEnd; j++)
            {
                _binEnergy[i] += _samples[j] > 0 ? _samples[j] : 0;
            }

            _binEnergy[i] /= binLength;
        }

        // Calculate blend shape weight from bin energy.
        // Note: These equations have been slightly altered. See comments below for original equations.

        // Kiss shape.
        if (_binEnergy[1] >= 0.2f)
        {
            _blendKissShape = Mathf.Clamp01(1 - 3 * _binEnergy[2]);
            // _blendKissShape = Mathf.Clamp01(1 - 2 * _binEnergy[2]);
        }
        else
        {
            _blendKissShape = Mathf.Clamp01((1 - 3 * _binEnergy[2]) * 5 * _binEnergy[1]);
            // _blendKissShape = Mathf.Clamp01((1 - 2 * _binEnergy[2]) * 5 * _binEnergy[1]);
        }

        // Lips closed shape.
        _blendLipsPressedShape = Mathf.Clamp01(3f * _binEnergy[3] + 2 * _binEnergy[2]);
        // _blendLipsPressedShape = Mathf.Clamp01(3f * _binEnergy[3]);

        // Mouth open shape
        _blendMouthOpenShape = Mathf.Clamp01(0.8f * (_binEnergy[1] - _binEnergy[3]) + _binEnergy[2]);
        //_blendMouthOpenShape = Mathf.Clamp01(0.8f * (_binEnergy[1] - _binEnergy[3]));

        // Default mouth shape.
        _blendLipsClosedShape = Mathf.Clamp01(1 - _blendKissShape - _blendLipsPressedShape - _blendMouthOpenShape);

        // Set calculated weights in animator.
        MouthAnimator.SetFloat("closed", _blendLipsClosedShape);
        MouthAnimator.SetFloat("open", _blendMouthOpenShape);
        MouthAnimator.SetFloat("kiss", _blendKissShape);
        MouthAnimator.SetFloat("pressed", _blendLipsPressedShape);

        // Visualize energy in each bin for debugging.
        if (_visualizeBinEnergy)
        {
            for (int i = 0; i < _binEnergyVisualization.Length; i++)
            {
                _binEnergyVisualization[i] = new string('|', (int)(_binEnergy[i] * 64));
            }
        }
    }