Пример #1
0
        /// <summary>
        /// Add new expression to playing expressions.
        /// </summary>
        private void StartExpression()
        {
            // Fail silently...
            if (ExpressionsList == null || ExpressionsList.CubismExpressionObjects == null)
            {
                return;
            }

            // Backup expression.
            _lastExpressionIndex = CurrentExpressionIndex;

            // Set last expression end time
            if (_playingExpressions.Count > 0)
            {
                var playingExpression = _playingExpressions[_playingExpressions.Count - 1];
                playingExpression.ExpressionEndTime = playingExpression.ExpressionUserTime + playingExpression.FadeOutTime;
                _playingExpressions[_playingExpressions.Count - 1] = playingExpression;
            }

            // Fail silently...
            if (CurrentExpressionIndex < 0 || CurrentExpressionIndex >= ExpressionsList.CubismExpressionObjects.Length)
            {
                return;
            }

            var palyingExpression = CubismPlayingExpression.Create(_model, ExpressionsList.CubismExpressionObjects[CurrentExpressionIndex]);

            if (palyingExpression == null)
            {
                return;
            }

            // Add to PlayingExList.
            _playingExpressions.Add(palyingExpression);
        }
        /// <summary>
        /// Initialize expression data from <see cref="CubismExpressionData"/>.
        /// </summary>
        /// <param name="model">model.</param>
        /// <param name="expressionData">Source.</param>
        public static CubismPlayingExpression Create(CubismModel model, CubismExpressionData expressionData)
        {
            // Fail silently...
            if (model == null || expressionData == null)
            {
                return(null);
            }

            var ret = new CubismPlayingExpression();

            ret.Type = expressionData.Type;

            ret.FadeInTime = (expressionData.FadeInTime <= 0.0f)
                                ? 1.0f
                                : expressionData.FadeInTime;

            ret.FadeOutTime = (expressionData.FadeOutTime <= 0.0f)
                                ? 1.0f
                                : expressionData.FadeOutTime;

            ret.Weight             = 0.0f;
            ret.ExpressionUserTime = 0.0f;
            ret.ExpressionEndTime  = 0.0f;

            var parameterCount = expressionData.Parameters.Length;

            ret.Destinations = new CubismParameter[parameterCount];
            ret.Value        = new float[parameterCount];
            ret.Blend        = new CubismParameterBlendMode[parameterCount];

            for (var i = 0; i < parameterCount; ++i)
            {
                ret.Destinations[i] = model.Parameters.FindById(expressionData.Parameters[i].Id);
                ret.Value[i]        = expressionData.Parameters[i].Value;
                switch (expressionData.Parameters[i].Blend)
                {
                case "Add":
                    ret.Blend[i] = CubismParameterBlendMode.Additive;
                    break;

                case "Multiply":
                    ret.Blend[i] = CubismParameterBlendMode.Multiply;
                    break;

                case "Overwrite":
                    ret.Blend[i] = CubismParameterBlendMode.Override;
                    break;

                default:
                    ret.Blend[i] = CubismParameterBlendMode.Additive;
                    break;
                }
            }

            return(ret);
        }
        /// <summary>
        /// Initialize expression data from <see cref="CubismExpressionData"/>.
        /// </summary>
        /// <param name="model">model.</param>
        /// <param name="expressionData">Source.</param>
        public static CubismPlayingExpression Create(CubismModel model, CubismExpressionData expressionData)
        {
            // Fail silently...
            if (model == null || expressionData == null)
            {
                return(null);
            }

            var ret = new CubismPlayingExpression();

            ret.Type = expressionData.Type;

            ret.FadeInTime = (expressionData.FadeInTime < 0.0f)
                                ? 1.0f
                                : expressionData.FadeInTime;

            ret.FadeOutTime = (expressionData.FadeOutTime < 0.0f)
                                ? 1.0f
                                : expressionData.FadeOutTime;

            ret.Weight             = 0.0f;
            ret.ExpressionUserTime = 0.0f;
            ret.ExpressionEndTime  = 0.0f;

            var parameterCount = expressionData.Parameters.Length;

            ret.Destinations = new CubismParameter[parameterCount];
            ret.Value        = new float[parameterCount];
            ret.Blend        = new CubismParameterBlendMode[parameterCount];

            for (var i = 0; i < parameterCount; ++i)
            {
                ret.Destinations[i] = model.Parameters.FindById(expressionData.Parameters[i].Id);
                ret.Value[i]        = expressionData.Parameters[i].Value;
                ret.Blend[i]        = expressionData.Parameters[i].Blend;
            }

            return(ret);
        }