/// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="id">パラメータID</param>
 /// <param name="offset">波のオフセット</param>
 /// <param name="peak">波の高さ</param>
 /// <param name="cycle">波の周期</param>
 /// <param name="weight">パラメータへの重み</param>
 public CubismBreathParameter(CubismParameter parameter, double offset, double peak, double cycle, double weight)
 {
     Parameter = parameter;
     Offset    = offset;
     Peak      = peak;
     Cycle     = cycle;
     Weight    = weight;
 }
Пример #2
0
        /// <summary>
        /// コアからパラメータ情報を読み出す。
        /// </summary>
        private void InitializeParameters()
        {
            int count = CubismCore.CsmGetParameterCount(ModelPtr);

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            // パラメータの現在値、最大値、最小値、デフォルト値を取得する
            ParameterValues = IntPtrToFloatArray(CubismCore.CsmGetParameterValues(ModelPtr), count);
            var maximum_values = IntPtrToFloatArray(CubismCore.CsmGetParameterMaximumValues(ModelPtr), count);
            var minimum_values = IntPtrToFloatArray(CubismCore.CsmGetParameterMinimumValues(ModelPtr), count);
            var default_values = IntPtrToFloatArray(CubismCore.CsmGetParameterDefaultValues(ModelPtr), count);

            // パラメータIDを取得し、IDマネージャを作成する
            string[] id_name_list = IntPtrToStringArray(CubismCore.CsmGetParameterIds(ModelPtr), count);
            ParameterManager = new CubismIdManager <CubismParameter>(count);
            for (int index = 0; index < count; index++)
            {
                var id = new CubismParameter(id_name_list[index], index, minimum_values[index], maximum_values[index], default_values[index], ParameterValues);
                ParameterManager.RegisterId(id);
            }
        }
Пример #3
0
        /// <summary>
        /// アセットを読み込む。
        /// </summary>
        /// <param name="model_file_path">読み込むmodel3.jsonへのファイルパス</param>
        /// <param name="reader">ファイルからデータを読み込むのに使うデリゲート</param>
        /// <returns>trueなら読み込みが成功したことを示す。</returns>
        public CubismAsset(string model_file_path, CubismFileLoader reader)
        {
            string base_dir      = Path.GetDirectoryName(model_file_path);
            var    model_setting = CubismModelSettingJson.Create(reader(model_file_path));

            // mocファイルを読み込み、CubismModelを作成する
            using (Stream stream = reader(Path.Combine(base_dir, model_setting.FileReferences.Moc)))
            {
                byte[] stream_bytes = new byte[stream.Length];
                stream.Read(stream_bytes, 0, (int)stream.Length);
                Moc = new CubismMoc(stream_bytes);
            }
            Model = Moc.CreateModel();

            // パラメータIDグループを読み込む
            // (まばたきやリップシンクに紐づいたパラメータIDのリスト)
            ParameterGroups = new Dictionary <string, CubismParameter[]>();
            if (model_setting.Groups != null)
            {
                foreach (var group in model_setting.Groups)
                {
                    if (group.Target == "Parameter")
                    {
                        // 重複除去のためにHashSetに読み込む
                        var id_names = new HashSet <string>(group.Ids);
                        var ids      = new CubismParameter[id_names.Count];
                        int index    = 0;
                        foreach (var id_name in id_names)
                        {
                            ids[index] = Model.GetParameter(id_name);
                            index++;
                        }
                        ParameterGroups.Add(group.Name, ids);
                    }
                }
            }
            Model.SaveParameters();

            // 呼吸を設定する
            //EyeBlinkController = new CubismEyeBlink(ParameterGroups["EyeBlink"]);
            //BreathController = new CubismBreath();
            //BreathController.SetParameter(new CubismBreathParameter(Model.GetParameter("ParamAngleX"), 0.0, 15.0, 6.5345, 0.5));
            //BreathController.SetParameter(new CubismBreathParameter(Model.GetParameter("ParamAngleY"), 0.0, 8.0, 3.5345, 0.5));
            //BreathController.SetParameter(new CubismBreathParameter(Model.GetParameter("ParamAngleZ"), 0.0, 10.0, 5.5345, 0.5));
            //BreathController.SetParameter(new CubismBreathParameter(Model.GetParameter("ParamBodyAngleX"), 0.0, 4.0, 15.5345, 0.5));
            //BreathController.SetParameter(new CubismBreathParameter(Model.GetParameter("ParamBreath"), 0.5, 0.5, 3.2345, 0.5));

            // モーションを読み込む
            MotionGroups = new Dictionary <string, ICubismMotion[]>();
            if (model_setting.FileReferences.Motions != null)
            {
                foreach (var item in model_setting.FileReferences.Motions)
                {
                    var group_name        = item.Key;
                    var motion_group_item = item.Value;
                    var motion_group      = new List <ICubismMotion>();
                    foreach (var motion_item in motion_group_item)
                    {
                        using (Stream stream = reader(Path.Combine(base_dir, motion_item.File)))
                        {
                            var motion = LoadMotion(stream, motion_item);
                            if (motion != null)
                            {
                                motion_group.Add(motion);
                            }
                        }
                    }
                    MotionGroups.Add(group_name, motion_group.ToArray());
                }
            }

            // 表情モーションを読み込む
            Expressions = new Dictionary <string, ICubismMotion>();
            if (model_setting.FileReferences.Expressions != null)
            {
                foreach (var expression_item in model_setting.FileReferences.Expressions)
                {
                    ICubismMotion expression;
                    using (Stream stream = reader(Path.Combine(base_dir, expression_item.File)))
                    {
                        expression = new CubismExpressionMotion(stream, Model);
                    }
                    if (expression != null)
                    {
                        Expressions.Add(expression_item.Name, expression);
                    }
                }
            }

            // ユーザーデータを読み込む
            UserData = new CubismUserData();
            if (string.IsNullOrEmpty(model_setting.FileReferences.UserData) == false)
            {
                using (Stream stream = reader(Path.Combine(base_dir, model_setting.FileReferences.UserData)))
                {
                    UserData = new CubismUserData(stream);
                }
            }

            // ヒットエリアを読み込む
            HitAreas = new Dictionary <string, CubismDrawable>();
            if (model_setting.HitAreas != null)
            {
                foreach (var hit_area in model_setting.HitAreas)
                {
                    CubismDrawable drawable = Model.GetDrawable(hit_area.Id);
                    if (drawable != null)
                    {
                        HitAreas.Add(hit_area.Name, drawable);
                    }
                }
            }

            // テクスチャを読み込む
            TextureByteArrays = new byte[model_setting.FileReferences.Textures.Length][];
            for (int index = 0; index < TextureByteArrays.Length; index++)
            {
                string path = Path.Combine(base_dir, model_setting.FileReferences.Textures[index]);
                using (Stream stream = reader(path))
                {
                    byte[] buffer = new byte[stream.Length];
                    stream.Read(buffer, 0, buffer.Length);
                    TextureByteArrays[index] = buffer;
                }
            }

            // 物理演算データを読み込む
            // To do.

            // ポーズを読み込む
            if (string.IsNullOrEmpty(model_setting.FileReferences.Pose) == false)
            {
                using (Stream stream = reader(Path.Combine(base_dir, model_setting.FileReferences.Pose)))
                {
                    PoseController = new CubismPose(stream, Model);
                }
            }

            // モデル行列を計算する
            var(canvas_width, canvas_height) = Model.GetCanvasSize();
            ModelMatrix = new CubismModelMatrix(canvas_width, canvas_height);
            ModelMatrix.SetupFromLayout(model_setting.Layout);

            // モーションマネージャーを初期化する
            BaseMotionManager       = new CubismMotionManager();
            ExpressionMotionManager = new CubismMotionManager();
            EffectMotionManager     = new CubismMotionManager();
        }