Skip to content

Commit

Permalink
Update to Cubism 4 SDK for Native R6
Browse files Browse the repository at this point in the history
  • Loading branch information
wada-at-live2d-com committed Feb 21, 2023
1 parent 541c6f5 commit ba896da
Show file tree
Hide file tree
Showing 19 changed files with 1,668 additions and 826 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).


## [4-r.6] - 2023-02-21

### Added

* Add API to allow users to configure culling.
* The number of render textures used can now be increased arbitrarily.
* The maximum number of masks when using multiple render textures has been increased to "number of render textures * 32".

### Fixed

* Fix a bug that models with culling were not rendered correctly in Metal.
* Fix a bug that caused some masks to be rendered incorrectly when using 17 or more masks in DirectX systems.

### Removed

* Remove unnecessary variable `modelToWorldF` in renderer.


## [4-r.5.1] - 2022-09-15

### Fixed
Expand Down Expand Up @@ -226,6 +244,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* Fix invalid expressions of `CubismCdiJson`.


[4-r.6]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5.1...4-r.6
[4-r.5.1]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5...4-r.5.1
[4-r.5]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5-beta.5...4-r.5
[4-r.5-beta.5]: https://github.com/Live2D/CubismNativeFramework/compare/4-r.5-beta.4.1...4-r.5-beta.5
Expand Down
51 changes: 45 additions & 6 deletions src/Model/CubismModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CubismModel::CubismModel(Core::csmModel* model)
, _partOpacities(NULL)
, _isOverwrittenModelMultiplyColors(false)
, _isOverwrittenModelScreenColors(false)
, _isOverwrittenCullings(false)
{ }

CubismModel::~CubismModel()
Expand Down Expand Up @@ -395,6 +396,7 @@ void CubismModel::Initialize()
_drawableIds.PrepareCapacity(drawableCount);
_userMultiplyColors.PrepareCapacity(drawableCount);
_userScreenColors.PrepareCapacity(drawableCount);
_userCullings.PrepareCapacity(drawableCount);

// 乗算色
Rendering::CubismRenderer::CubismTextureColor multiplyColor;
Expand All @@ -416,11 +418,18 @@ void CubismModel::Initialize()
userScreenColor.IsOverwritten = false;
userScreenColor.Color = screenColor;

// カリング設定
DrawableCullingData userCulling;
userCulling.IsOverwritten = false;
userCulling.IsCulling = 0;


for (csmInt32 i = 0; i < drawableCount; ++i)
{
_drawableIds.PushBack(CubismFramework::GetIdManager()->GetId(drawableIds[i]));
_userMultiplyColors.PushBack(userMultiplyColor);
_userScreenColors.PushBack(userScreenColor);
_userCullings.PushBack(userCulling);
}
}
}
Expand Down Expand Up @@ -513,12 +522,6 @@ csmInt32 CubismModel::GetDrawableParentPartIndex(csmUint32 drawableIndex) const
return Core::csmGetDrawableParentPartIndices(_model)[drawableIndex];
}

csmInt32 CubismModel::GetDrawableCulling(csmInt32 drawableIndex) const
{
const Core::csmFlags* constantFlags = Core::csmGetDrawableConstantFlags(_model);
return !IsBitSet(constantFlags[drawableIndex], Core::csmIsDoubleSided);
}

csmBool CubismModel::GetDrawableDynamicFlagIsVisible(csmInt32 drawableIndex) const
{
const Core::csmFlags* dynamicFlags = Core::csmGetDrawableDynamicFlags(_model);
Expand Down Expand Up @@ -712,6 +715,42 @@ void CubismModel::SetOverwriteFlagForDrawableScreenColors(csmUint32 drawableInde
_userScreenColors[drawableIndex].IsOverwritten = value;
}

csmInt32 CubismModel::GetDrawableCulling(csmInt32 drawableIndex) const
{
if (GetOverwriteFlagForModelCullings() || GetOverwriteFlagForDrawableCullings(drawableIndex))
{
return _userCullings[drawableIndex].IsCulling;
}

const Core::csmFlags* constantFlags = Core::csmGetDrawableConstantFlags(_model);
return !IsBitSet(constantFlags[drawableIndex], Core::csmIsDoubleSided);
}

void CubismModel::SetDrawableCulling(csmInt32 drawableIndex, csmInt32 isCulling)
{
_userCullings[drawableIndex].IsCulling = isCulling;
}

csmBool CubismModel::GetOverwriteFlagForModelCullings() const
{
return _isOverwrittenCullings;
}

void CubismModel::SetOverwriteFlagForModelCullings(csmBool value)
{
_isOverwrittenCullings = value;
}

csmBool CubismModel::GetOverwriteFlagForDrawableCullings(csmInt32 drawableIndex) const
{
return _userCullings[drawableIndex].IsOverwritten;
}

void CubismModel::SetOverwriteFlagForDrawableCullings(csmUint32 drawableIndex, csmBool value)
{
_userCullings[drawableIndex].IsOverwritten = value;
}

Core::csmModel* CubismModel::GetModel() const
{
return _model;
Expand Down
84 changes: 74 additions & 10 deletions src/Model/CubismModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,35 @@ class CubismModel

}; // DrawableColorData

/**
* @brief テクスチャのカリング設定を管理するための構造体
*/
struct DrawableCullingData
{
/**
* @brief コンストラクタ
*/
DrawableCullingData()
: IsOverwritten(false)
, IsCulling(0) {};

/**
* @brief コンストラクタ
*/
DrawableCullingData(csmBool isOverwritten, csmInt32 isCulling)
: IsOverwritten(isOverwritten)
, IsCulling(isCulling) {};

/**
* @brief デストラクタ
*/
virtual ~DrawableCullingData() {};

csmBool IsOverwritten;
csmInt32 IsCulling;

}; // DrawableCullingData

/**
* @brief モデルのパラメータの更新
*
Expand Down Expand Up @@ -473,16 +502,6 @@ class CubismModel
*/
csmInt32 GetDrawableParentPartIndex(csmUint32 drawableIndex) const;

/**
* @brief Drawableのカリング情報の取得
*
* Drawableのカリング情報を取得する。
*
* @param[in] drawableIndex Drawableのインデックス
* @return Drawableのカリング情報
*/
csmInt32 GetDrawableCulling(csmInt32 drawableIndex) const;

/**
* @brief Drawableのブレンドモードの取得
*
Expand Down Expand Up @@ -710,6 +729,49 @@ class CubismModel
*/
void SetOverwriteFlagForDrawableScreenColors(csmUint32 drawableIndex, csmBool value);

/**
* @brief Drawableのカリング情報の取得
*
* Drawableのカリング情報を取得する。
*
* @param[in] drawableIndex Drawableのインデックス
* @return Drawableのカリング情報
*/
csmInt32 GetDrawableCulling(csmInt32 drawableIndex) const;

/**
* @brief Drawableのカリング情報を設定する
*/
void SetDrawableCulling(csmInt32 drawableIndex, csmInt32 isCulling);

/**
* @brief SDKからモデル全体のカリング設定を上書きするか。
*
* @retval true -> SDK上のカリング設定を使用
* @retval false -> モデルのカリング設定を使用
*/
csmBool GetOverwriteFlagForModelCullings() const;

/**
* @brief SDKからモデル全体のカリング設定を上書きするかをセットする
* SDK上のカリング設定を使うならtrue、モデルのカリング設定を使うならfalse
*/
void SetOverwriteFlagForModelCullings(csmBool value);

/**
* @brief SDKからdrawableのカリング設定を上書きするか。
*
* @retval true -> SDK上のカリング設定を使用
* @retval false -> モデルのカリング設定を使用
*/
csmBool GetOverwriteFlagForDrawableCullings(csmInt32 drawableIndex) const;

/**
* @brief SDKからdrawableのカリング設定を上書きするかをセットする
* SDK上のカリング設定を使うならtrue、モデルのカリング設定を使うならfalse
*/
void SetOverwriteFlagForDrawableCullings(csmUint32 drawableIndex, csmBool value);

Core::csmModel* GetModel() const;

private:
Expand Down Expand Up @@ -761,8 +823,10 @@ class CubismModel
csmVector<CubismIdHandle> _drawableIds;
csmVector<DrawableColorData> _userScreenColors; ///< 乗算色の配列
csmVector<DrawableColorData> _userMultiplyColors; ///< スクリーン色の配列
csmVector<DrawableCullingData> _userCullings; ///< カリング設定の配列
csmBool _isOverwrittenModelMultiplyColors; ///< 乗算色を全て上書きするか?
csmBool _isOverwrittenModelScreenColors; ///< スクリーン色を全て上書きするか?
csmBool _isOverwrittenCullings; ///< モデルのカリング設定をすべて上書きするか?
};

}}}
4 changes: 2 additions & 2 deletions src/Model/CubismUserModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ CubismModel* CubismUserModel::GetModel() const
return _model;
}

void CubismUserModel::CreateRenderer()
void CubismUserModel::CreateRenderer(csmInt32 maskBufferCount)
{
if (_renderer)
{
DeleteRenderer();
}
_renderer = Rendering::CubismRenderer::Create();

_renderer->Initialize(_model);
_renderer->Initialize(_model, maskBufferCount);
}

void CubismUserModel::DeleteRenderer()
Expand Down
2 changes: 1 addition & 1 deletion src/Model/CubismUserModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class CubismUserModel
* レンダラを生成して初期化を実行する。
*
*/
void CreateRenderer();
void CreateRenderer(csmInt32 maskBufferCount = 1);

/**
* @brief レンダラの解放
Expand Down
Loading

0 comments on commit ba896da

Please sign in to comment.