/// <summary> /// コアからDrawable情報を読み出す。 /// </summary> private void InitializeDrawables() { int drawable_count = CubismCore.CsmGetDrawableCount(ModelPtr); Drawables = new CubismDrawable[drawable_count]; // DrawableのID名リストを取得する string[] drawable_name_list = IntPtrToStringArray(CubismCore.CsmGetDrawableIds(ModelPtr), drawable_count); // テクスチャ番号を読み出す int[] texture_indexes = DrawableTextureIndexList; // 静的フラグを読み出す byte[] constant_flags = DrawableConstantFlagsList; // クリッピングマスクを読み出す int[] mask_counts = DrawableClippingMaskCountList; IntPtr[] mask_ptrs = DrawableClippingMaskPointerList; // Drawablesを構築する for (int index = 0; index < drawable_count; index++) { string name = drawable_name_list[index]; int texture_index = texture_indexes[index]; var flags = (CubismCore.ConstantDrawableFlags)constant_flags[index]; var masks = IntPtrToIntArray(mask_ptrs[index], mask_counts[index]); Drawables[index] = new CubismDrawable(index, name, texture_index, flags, masks); } }
/// <summary> /// キャンバスのサイズを取得する。 /// </summary> /// <returns>キャンバスの幅、高さ</returns> public (double width, double height) GetCanvasSize() { float[] size_in_pixels = new float[2]; float[] origin_in_pixels = new float[2]; CubismCore.CsmReadCanvasInfo(ModelPtr, size_in_pixels, origin_in_pixels, out float pixels_per_unit); return(size_in_pixels[0] / pixels_per_unit, size_in_pixels[1] / pixels_per_unit); }
/// <summary> /// コンストラクタ。 /// MocデータからMocを生成する。 /// </summary> /// <param name="moc_bytes"></param> public CubismMoc(byte[] moc_bytes) { // バッファを確保し、CsmAlignofMocで指定されたバイト数にアライメントする BufferPtr = Marshal.AllocCoTaskMem(moc_bytes.Length + CubismCore.CsmAlignofMoc - 1); IntPtr aligned_buffer = AlignPointer(BufferPtr, CubismCore.CsmAlignofMoc); // Mocを生成する Marshal.Copy(moc_bytes, 0, aligned_buffer, moc_bytes.Length); MocPtr = CubismCore.CsmReviveMocInPlace(aligned_buffer, moc_bytes.Length); if (MocPtr == IntPtr.Zero) { throw new ArgumentException(); } }
/// <summary> /// モデルを作成する。 /// </summary> /// <returns>作成されたモデル</returns> public CubismModel CreateModel() { // バッファを確保し、CsmAlignofModelで指定されたバイト数にアライメントする int size = CubismCore.CsmGetSizeofModel(MocPtr); IntPtr model_buffer_ptr = Marshal.AllocCoTaskMem(size + CubismCore.CsmAlignofModel - 1); IntPtr aligned_model_buffer_ptr = AlignPointer(model_buffer_ptr, CubismCore.CsmAlignofModel); IntPtr model_ptr = CubismCore.CsmInitializeModelInPlace(MocPtr, aligned_model_buffer_ptr, size); if (MocPtr == IntPtr.Zero) { return(null); } ModelCount++; return(new CubismModel(model_buffer_ptr, model_ptr)); }
/// <summary> /// モデルのパラメータを更新する。 /// </summary> public void Update() { // 現在のパラメータ設定値をコアに戻す Marshal.Copy(ParameterValues, 0, CubismCore.CsmGetParameterValues(ModelPtr), ParameterCount); Marshal.Copy(PartOpacities, 0, CubismCore.CsmGetPartOpacities(ModelPtr), PartCount); // 次のパラメータを計算する CubismCore.CsmUpdateModel(ModelPtr); // 新しいパラメータ設定値をコアから読み出す Marshal.Copy(CubismCore.CsmGetParameterValues(ModelPtr), ParameterValues, 0, ParameterCount); Marshal.Copy(CubismCore.CsmGetPartOpacities(ModelPtr), PartOpacities, 0, PartCount); // Drawableの情報をコアから読み出す UpdateDrawables(); // 動的フラグをクリアする CubismCore.CsmResetDrawableDynamicFlags(ModelPtr); }
/// <summary> /// コアからパーツ情報を読み出す。 /// </summary> private void InitializeParts() { int count = CubismCore.CsmGetPartCount(ModelPtr); if (count < 0) { throw new ArgumentOutOfRangeException(); } // パーツの不透明度を取得する PartOpacities = IntPtrToFloatArray(CubismCore.CsmGetPartOpacities(ModelPtr), count); // パーツIDを取得し、IDマネージャを作成する string[] id_name_list = IntPtrToStringArray(CubismCore.CsmGetPartIds(ModelPtr), count); PartManager = new CubismIdManager <CubismPart>(count); for (int index = 0; index < count; index++) { var id = new CubismPart(id_name_list[index], index, PartOpacities); PartManager.RegisterId(id); } }
/// <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); } }
/// <summary> /// Drawableの描画順リストを取得する。 /// </summary> /// <returns>Drawableの描画順リスト</returns> public int[] GetDrawableRenderOrders() { return(IntPtrToIntArray(CubismCore.CsmGetDrawableRenderOrders(ModelPtr), DrawableCount)); }