Esempio n. 1
0
    public void ProcessFaceExpressions(float[] blendshapeWeights)
    {
        bool mouthOpen      = false;
        bool smile          = false;
        bool eyeBrowsRaised = false;

        if (blendshapeWeights[MouthOpenBlendshapeIdx] > MouthOpenBlendshapeThreshold)
        {
            mouthOpen = true;
        }
        if (blendshapeWeights[SmileBlendshapeIdx] > SmileBlendshapeThreshold)
        {
            smile = true;
        }
        //this is negative as the blendshape actually lowers the eyebrows
        if (-blendshapeWeights[EyeBrowRaiseBlendshapeIdx] > EyeBrowRaiseBlendshapeThreshold)
        {
            eyeBrowsRaised = true;
        }

        for (int i = 0; i < MouthOpenActivations.Length; i++)
        {
            IAnimationTrigger trigger = MouthOpenActivations[i].GetComponent <IAnimationTrigger>();

            if (trigger == null)
            {
                continue;
            }
            if (mouthOpen)
            {
                trigger.AttributePresent();
            }
            else
            {
                trigger.AttributeNotPresent();
            }
        }

        for (int i = 0; i < SmileActivations.Length; i++)
        {
            IAnimationTrigger trigger = SmileActivations[i].GetComponent <IAnimationTrigger>();

            if (trigger == null)
            {
                continue;
            }
            if (smile)
            {
                trigger.AttributePresent();
            }
            else
            {
                trigger.AttributeNotPresent();
            }
        }

        for (int i = 0; i < EyeBrowsRaisedActivations.Length; i++)
        {
            IAnimationTrigger trigger = EyeBrowsRaisedActivations[i].GetComponent <IAnimationTrigger>();

            if (trigger == null)
            {
                continue;
            }
            if (eyeBrowsRaised)
            {
                trigger.AttributePresent();
            }
            else
            {
                trigger.AttributeNotPresent();
            }
        }

        if (debugMode && AttributeText != null)
        {
            //AttributeText.text = "Mouth open: " + mouthOpen.ToString() + ", val: " + blendshapeWeights[MouthOpenBlendshapeIdx].ToString("0.00") + "\n";
            //AttributeText.text += "Smile: " + smile.ToString() + ", val: " + blendshapeWeights[SmileBlendshapeIdx].ToString("0.00") + "\n";
            //AttributeText.text += "Eyebrows Raised: " + eyeBrowsRaised.ToString() + ", val: " + (-blendshapeWeights[EyeBrowRaiseBlendshapeIdx]).ToString("0.00") + "\n";
        }
    }
Esempio n. 2
0
        private void PopulateTab(int tabId)
        {
            populatingForm = true;
            IAnimationTrigger trigger = null;

            switch (tabId)
            {
            case 0:
                //What tab
                gpAnimationImage.Visible       = false;
                gpAnimationDrawing.Visible     = false;
                txtAnimationName.Text          = _animation.Name;
                cmbAnimationType.SelectedIndex = cmbAnimationType.Items.IndexOf(_animation.Type);
                if (_animation.Type == AnimationItemTypeEnum.Image)
                {
                    gpAnimationImage.Visible   = true;
                    txtAnimationImagePath.Text = ((AnimationImage)_animation).ImagePath ?? "";
                    try
                    {
                        var image = Image.FromFile(Path.Combine(baseFolder, txtAnimationImagePath.Text));
                        if (image != null)
                        {
                            ShowImage(image, pbAnimationImage);
                        }
                    }
                    catch { }
                }
                if (_animation.Type == AnimationItemTypeEnum.Drawing)
                {
                    gpAnimationDrawing.Visible = true;
                    if (((AnimationDrawing)_animation).PointMap == null)
                    {
                        ((AnimationDrawing)_animation).PointMap = new AnimationPoint[0];
                    }
                    cmbAnimationFillColor.SelectedIndex  = cmbAnimationFillColor.Items.IndexOf(((AnimationDrawing)_animation).FillColor.ToKnownColor());
                    cmbAnimationFillMethod.SelectedIndex = cmbAnimationFillMethod.Items.IndexOf(((AnimationDrawing)_animation).FillMethod);
                    dgAnimationPlotPoints.Rows.Clear();
                    foreach (var plotPoint in ((AnimationDrawing)_animation).PointMap)
                    {
                        dgAnimationPlotPoints.Rows.Add(new object[] { plotPoint.X, plotPoint.Y });
                    }
                }
                break;

            case 1:
                // When tab
                gdAnimationTriggers.Rows.Clear();
                if (_animation.Triggers != null)
                {
                    foreach (var t in _animation.Triggers)
                    {
                        trigger = (IAnimationTrigger)t;
                        gdAnimationTriggers.Rows.Add(new object[] { trigger.Name, trigger.Type });
                    }
                }
                break;

            case 2:
                // How tab
                lblAnimationHowNoTrigger.Visible = true;
                lblAnimationActions.Visible      = false;
                dgAnimationActions.Visible       = false;
                gpAnimationActionClip.Visible    = false;
                gpAnimationActionRotate.Visible  = false;
                gpAnimationActionMoveX.Visible   = false;
                if (gdAnimationTriggers.SelectedRows.Count == 1 && _animation.Triggers != null)
                {
                    trigger = (IAnimationTrigger)_animation.Triggers.FirstOrDefault(x => ((IAnimationTrigger)x).Name == gdAnimationTriggers.SelectedRows[0].Cells["Trigger"]?.Value?.ToString());
                    if (trigger != null)
                    {
                        lblAnimationActions.Visible      = true;
                        dgAnimationActions.Visible       = true;
                        lblAnimationHowNoTrigger.Visible = false;
                        dgAnimationActions.Rows.Clear();
                        if (trigger.Actions != null)
                        {
                            foreach (var action in trigger.Actions)
                            {
                                var rowIdx    = dgAnimationActions.Rows.Add();
                                var itemToSet = ((DataGridViewComboBoxCell)dgAnimationActions.Rows[rowIdx].Cells["ActionType"]).Items[((DataGridViewComboBoxCell)dgAnimationActions.Rows[rowIdx].Cells["ActionType"]).Items.IndexOf(((IAnimationAction)action).Type)];
                                ((DataGridViewComboBoxCell)dgAnimationActions.Rows[rowIdx].Cells["ActionType"]).Value = itemToSet;
                            }
                        }
                    }
                }
                break;
            }
            populatingForm = false;
        }