Esempio n. 1
0
        public static CubismExpressionData CreateInstance(CubismExpressionData expressionData, CubismExp3Json json)
        {
            expressionData.Type        = json.Type;
            expressionData.FadeInTime  = json.FadeInTime;
            expressionData.FadeOutTime = json.FadeOutTime;
            expressionData.Parameters  = new SerializableExpressionParameter[json.Parameters.Length];

            for (var i = 0; i < json.Parameters.Length; ++i)
            {
                expressionData.Parameters[i].Id    = json.Parameters[i].Id;
                expressionData.Parameters[i].Value = json.Parameters[i].Value;

                switch (json.Parameters[i].Blend)
                {
                case "Add":
                    expressionData.Parameters[i].Blend = CubismParameterBlendMode.Additive;
                    break;

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

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

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

            return(expressionData);
        }
        /// <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);
        }