Skip to content

Commit

Permalink
Update to Cubism 5 SDK for Native R1
Browse files Browse the repository at this point in the history
  • Loading branch information
wada-at-live2d-com committed Mar 26, 2024
1 parent bebb8e0 commit 3d9f82a
Show file tree
Hide file tree
Showing 34 changed files with 976 additions and 578 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ 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/).

## [5-r.1] - 2024-03-26

### Added

* Add function `ModF()` to compute floating-point remainder in `CubismMath` class.

### Changed

* Change the `Reset()` function of `CubismPose` class to public.
* Change some processes in the renderer to be handled as functions.
* Change to output log if the argument `MotionQueueEntry` is `NULL` in the `UpdateFadeWeight()` function of the `ACubismMotion` class.

### Deprecated

* Deprecate the `_fadeWeight` variable and the `GetFadeWeight()` function of the `CubismExpressionMotion` class.
* The `_fadeWeight` variable of the `CubismExpressionMotion` class can cause problems.
* Please use the `GetFadeWeight()` function of the `CubismExpressionMotionManager` class with one argument from now on.
* The `StartMotion()` function of the `CubismMotionQueueManager` class with the unnecessary third argument `userTimeSeconds` is deprecated.
* Please use the `StartMotion()` function with two arguments from now on.

### Fixed

* Fix a typo in `SetParameterValue()`.
* Fix an issue that the override keyword is not specified for some functions of classes inheriting from `CubismRenderer`.
* Fix operator overloading in the `CubismId` class from being private to public.
* Fix a bug that caused incorrect weight values when expression motions were shared by multiple models.
* Change the way fadeWeight is managed for expression motions.
* Fix shader build error when running nmake in Vulkan.

### Removed

* Remove `CubismSetupMaskedShaderUniforms`, `CubismNormalShaderUniforms`, `CubismMaskedShaderUniforms` and `CubismFragMaskedShaderUniforms` from Metal and merged them into `CubismMaskedShaderUniforms`.


## [5-r.1-beta.4] - 2024-01-25

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


[5-r.1]: https://github.com/Live2D/CubismNativeFramework/compare/5-r.1-beta.4...5-r.1
[5-r.1-beta.4]: https://github.com/Live2D/CubismNativeFramework/compare/5-r.1-beta.3...5-r.1-beta.4
[5-r.1-beta.3]: https://github.com/Live2D/CubismNativeFramework/compare/5-r.1-beta.2...5-r.1-beta.3
[5-r.1-beta.2]: https://github.com/Live2D/CubismNativeFramework/compare/5-r.1-beta.1...5-r.1-beta.2
Expand Down
2 changes: 1 addition & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ JSON パーサーやログ出力などのユーティリティ機能を提供し

### フォークとプルリクエスト

修正、改善、さらには新機能をもたらすかどうかにかかわらず、プルリクエストに感謝します。ただし、ラッパーは可能な限り軽量で浅くなるように設計されているため、バグ修正とメモリ/パフォーマンスの改善のみを行う必要があることに注意してください。メインリポジトリを可能な限りクリーンに保つために、必要に応じて個人用フォークと機能ブランチを作成してください。
修正、改善、さらには新機能をもたらすかどうかにかかわらず、プルリクエストに感謝します。メインリポジトリを可能な限りクリーンに保つために、必要に応じて個人用フォークと機能ブランチを作成してください。

### バグ

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ There are many ways to contribute to the project: logging bugs, submitting pull

### Forking And Pull Requests

We very much appreciate your pull requests, whether they bring fixes, improvements, or even new features. Note, however, that the wrapper is designed to be as lightweight and shallow as possible and should therefore only be subject to bug fixes and memory/performance improvements. To keep the main repository as clean as possible, create a personal fork and feature branches there as needed.
We very much appreciate your pull requests, whether they bring fixes, improvements, or even new features. To keep the main repository as clean as possible, create a personal fork and feature branches there as needed.

### Bugs

Expand Down
22 changes: 11 additions & 11 deletions src/Effect/CubismPose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ class CubismPose
*/
void UpdateParameters(CubismModel* model, csmFloat32 deltaTimeSeconds);

/**
* @brief 表示を初期化
*
* 表示を初期化する。
*
* @param[in] model 対象のモデル
*
* @note 不透明度の初期値が0でないパラメータは、不透明度を1に設定する。
*/
void Reset(CubismModel* model);

private:
/**
* @brief コンストラクタ
Expand All @@ -114,17 +125,6 @@ class CubismPose
*/
virtual ~CubismPose();

/**
* @brief 表示を初期化
*
* 表示を初期化する。
*
* @param[in] model 対象のモデル
*
* @note 不透明度の初期値が0でないパラメータは、不透明度を1に設定する。
*/
void Reset(CubismModel* model);

/**
* @brief パーツの不透明度をコピー
*
Expand Down
9 changes: 5 additions & 4 deletions src/Id/CubismId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ struct CubismId
*/
const csmString& GetString() const;

CubismId& operator=(const CubismId& c);

csmBool operator==(const CubismId& c) const;
csmBool operator!=(const CubismId& c) const;

private:
/**
* @brief コンストラクタ
Expand All @@ -54,10 +59,6 @@ struct CubismId
~CubismId();

CubismId(const CubismId& c);
CubismId& operator=(const CubismId& c);

csmBool operator==(const CubismId& c) const;
csmBool operator!=(const CubismId& c) const;

csmString _id; ///< ID名
};
Expand Down
24 changes: 24 additions & 0 deletions src/Math/CubismMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "CubismMath.hpp"
#include "Utils/CubismDebug.hpp"

namespace Live2D {namespace Cubism {namespace Framework {

Expand Down Expand Up @@ -189,4 +190,27 @@ csmFloat32 CubismMath::CardanoAlgorithmForBezier(csmFloat32 a, csmFloat32 b, csm
return RangeF(root1, 0.0f, 1.0f);
}

csmFloat32 CubismMath::ModF(csmFloat32 dividend, csmFloat32 divisor)
{
if (
!isfinite(dividend) ||
divisor == 0 ||
isnan(dividend) ||
isnan(divisor)
) {
CubismLogWarning("dividend: %f, divisor: %f ModF() returns 'NaN'.", dividend, divisor);
return NAN;
}

// 絶対値に変換する。
const csmFloat32 absDividend = CubismMath::AbsF(dividend);
const csmFloat32 absDivisor = CubismMath::AbsF(divisor);

// 絶対値で割り算する。
csmFloat32 result = absDividend - floorf(absDividend / absDivisor) * absDivisor;

// 符号を被除数のものに指定する。
return copysign(result, dividend);
}

}}}
9 changes: 9 additions & 0 deletions src/Math/CubismMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ class CubismMath
*/
static csmFloat32 CardanoAlgorithmForBezier(csmFloat32 a, csmFloat32 b, csmFloat32 c, csmFloat32 d);

/**
* @brief 浮動小数点の余りを求める。
*
* @param dividend 被除数(割られる値)
* @param divisor 除数(割る値)
* @returns 余り
*/
static csmFloat32 ModF(csmFloat32 dividend, csmFloat32 divisor);

private:
/**
*@brief privateコンストラクタ
Expand Down
4 changes: 2 additions & 2 deletions src/Model/CubismModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ csmFloat32 CubismModel::GetParameterValue(CubismIdHandle parameterId)
return GetParameterValue(parameterIndex);
}

void CubismModel::SetParameterValue(CubismIdHandle parameteId, csmFloat32 value, csmFloat32 weight)
void CubismModel::SetParameterValue(CubismIdHandle parameterId, csmFloat32 value, csmFloat32 weight)
{
const csmInt32 index = GetParameterIndex(parameteId);
const csmInt32 index = GetParameterIndex(parameterId);
SetParameterValue(index, value, weight);
}

Expand Down
45 changes: 30 additions & 15 deletions src/Motion/ACubismMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,7 @@ void ACubismMotion::UpdateParameters(CubismModel* model, CubismMotionQueueEntry*
return;
}

if (!motionQueueEntry->IsStarted())
{
motionQueueEntry->IsStarted(true);
motionQueueEntry->SetStartTime(userTimeSeconds - _offsetSeconds); //モーションの開始時刻を記録
motionQueueEntry->SetFadeInStartTime(userTimeSeconds); //フェードインの開始時刻

const csmFloat32 duration = GetDuration();

if (motionQueueEntry->GetEndTime() < 0)
{
//開始していないうちに終了設定している場合がある。
motionQueueEntry->SetEndTime( (duration <= 0) ? -1 : motionQueueEntry->GetStartTime() + duration );
//duration == -1 の場合はループする
}
}
SetupMotionQueueEntry(motionQueueEntry, userTimeSeconds);

csmFloat32 fadeWeight = UpdateFadeWeight(motionQueueEntry, userTimeSeconds);

Expand All @@ -68,8 +54,37 @@ void ACubismMotion::UpdateParameters(CubismModel* model, CubismMotionQueueEntry*
}
}

void ACubismMotion::SetupMotionQueueEntry(CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds)
{
if (!motionQueueEntry->IsAvailable() || motionQueueEntry->IsFinished()) {
return;
}

if (motionQueueEntry->IsStarted()) {
return;
}

motionQueueEntry->IsStarted(true);
motionQueueEntry->SetStartTime(userTimeSeconds - _offsetSeconds); //モーションの開始時刻を記録
motionQueueEntry->SetFadeInStartTime(userTimeSeconds); //フェードインの開始時刻

const csmFloat32 duration = GetDuration();

if (motionQueueEntry->GetEndTime() < 0)
{
//開始していないうちに終了設定している場合がある。
motionQueueEntry->SetEndTime((duration <= 0) ? -1 : motionQueueEntry->GetStartTime() + duration);
//duration == -1 の場合はループする
}
}

csmFloat32 ACubismMotion::UpdateFadeWeight(CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds)
{
if (motionQueueEntry == NULL)
{
CubismLogError("motionQueueEntry is null.");
}

csmFloat32 fadeWeight = _weight; //現在の値と掛け合わせる割合

//---- フェードイン・アウトの処理 ----
Expand Down
33 changes: 20 additions & 13 deletions src/Motion/ACubismMotion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class ACubismMotion
*/
void UpdateParameters(CubismModel* model, CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds);

/**
* モーションの再生を開始するためのセットアップを行う。
*
* @param motionQueueEntry CubismMotionQueueManagerによって管理されるモーション
* @param userTimeSeconds 総再生時間(秒)
*/
void SetupMotionQueueEntry(CubismMotionQueueEntry* motionQueueEntry, csmFloat32 userTimeSeconds);

/**
* @brief フェードイン
*
Expand Down Expand Up @@ -235,19 +243,6 @@ class ACubismMotion
*/
virtual CubismIdHandle GetModelOpacityId(csmInt32 index);

protected:
/**
*
* @brief 指定時間の透明度の値を返す
*
* @param[in] motionTimeSeconds 現在の再生時間[秒]
*
* @return success:モーションの当該時間におけるOpacityの値
*
* @note 更新後の値を取るにはUpdateParameters() の後に呼び出す。
*/
virtual csmFloat32 GetModelOpacityValue() const;

/**
* @brief モデルのウェイト更新
*
Expand All @@ -271,6 +266,18 @@ class ACubismMotion
*/
virtual ~ACubismMotion();

/**
*
* @brief 指定時間の透明度の値を返す
*
* @param[in] motionTimeSeconds 現在の再生時間[秒]
*
* @return success:モーションの当該時間におけるOpacityの値
*
* @note 更新後の値を取るにはUpdateParameters() の後に呼び出す。
*/
virtual csmFloat32 GetModelOpacityValue() const;

/**
* @brief モデルのパラメータの更新の実行
*
Expand Down
Loading

0 comments on commit 3d9f82a

Please sign in to comment.