Skip to content

Commit c453607

Browse files
Merge pull request #10 from Live2D/develop
Update to Cubism 5 SDK for Java R1
2 parents 4f663fc + 6eafb99 commit c453607

11 files changed

+190
-49
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [5-r.1] - 2024-03-26
8+
9+
### Added
10+
11+
* Add type constraint to the generics type of `getRenderer` function in `CubismUserModel`.
12+
* Add function `modF()` to compute floating-point remainder in `CubismMath` class.
13+
14+
### Changed
15+
16+
* Change the default value of the flag for debugging from `true` to `false`.
17+
* Change to output log if the argument `motionQueueEntry` is `null` in the `updateFadeWeight()` function of the `ACubismMotion` class.
18+
19+
### Deprecated
20+
21+
* Deprecate the `fadeWeight` variable and the `getFadeWeight()` function of the `CubismExpressionMotion` class.
22+
* The `fadeWeight` variable of the `CubismExpressionMotion` class can cause problems.
23+
* Please use the `getFadeWeight()` function of the `CubismExpressionMotionManager` class with one argument from now on.
24+
* The `startMotion()` function of the `CubismMotionQueueManager` class with the unnecessary second argument `userTimeSeconds` is deprecated.
25+
* Please use the `startMotion()` function with one argument from now on.
26+
27+
### Fixed
28+
29+
* Fix a bug that caused incorrect weight values when expression motions were shared by multiple models.
30+
* Change the way fadeWeight is managed for expression motions.
31+
32+
733
## [5-r.1-beta.3] - 2024-01-18
834

935
### Added
@@ -154,6 +180,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
154180

155181
* New released!
156182

183+
[5-r.1]: https://github.com/Live2D/CubismJavaFramework/compare/5-r.1-beta.3...5-r.1
157184
[5-r.1-beta.3]: https://github.com/Live2D/CubismJavaFramework/compare/5-r.1-beta.2...5-r.1-beta.3
158185
[5-r.1-beta.2]: https://github.com/Live2D/CubismJavaFramework/compare/5-r.1-beta.1...5-r.1-beta.2
159186
[5-r.1-beta.1]: https://github.com/Live2D/CubismJavaFramework/compare/4-r.1...5-r.1-beta.1

README.ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ JSON パーサーやログ出力などのユーティリティ機能を提供し
9494

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

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

9999
### バグ
100100

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ There are many ways to contribute to the project: logging bugs, submitting pull
9494

9595
### Forking And Pull Requests
9696

97-
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.
97+
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.
9898

9999
### Bugs
100100

framework/src/main/java/com/live2d/sdk/cubism/framework/CubismFrameworkConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public int getId() {
4848
/**
4949
* Cubism SDKにおけるデバッグ機能の有効状態。trueなら有効。
5050
*/
51-
public static final boolean CSM_DEBUG = true;
51+
public static final boolean CSM_DEBUG = false;
5252

5353
/**
5454
* ログ出力設定。<br>

framework/src/main/java/com/live2d/sdk/cubism/framework/math/CubismMath.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
package com.live2d.sdk.cubism.framework.math;
99

10+
import com.live2d.sdk.cubism.framework.utils.CubismDebug;
11+
1012
/**
1113
* Utility class used for numerical calculations, etc.
1214
*/
@@ -256,6 +258,27 @@ public static float cardanoAlgorithmForBezier(float a, float b, float c, float d
256258
return rangeF(root1, 0.0f, 1.0f);
257259
}
258260

261+
/**
262+
* 浮動小数点の余りを求める。
263+
*
264+
* @param dividend 被除数(割られる値)
265+
* @param divisor 除数(割る値)
266+
* @return 余り
267+
*/
268+
public static float modF(float dividend, float divisor) {
269+
if (
270+
Float.isInfinite(dividend)
271+
|| Float.compare(divisor, 0.0f) == 0
272+
|| Float.isNaN(dividend)
273+
|| Float.isNaN(divisor)
274+
) {
275+
CubismDebug.cubismLogWarning("dividend: %f, divisor: %f ModF() returns 'NaN'.", dividend, divisor);
276+
return Float.NaN;
277+
}
278+
279+
return dividend % divisor;
280+
}
281+
259282
/**
260283
* private constructor.
261284
* (Prevent instantiation.)

framework/src/main/java/com/live2d/sdk/cubism/framework/model/CubismUserModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public CubismModel getModel() {
249249
* @param <T> renderer type to use
250250
* @return renderer instance
251251
*/
252-
public <T> T getRenderer() {
252+
public <T extends CubismRenderer> T getRenderer() {
253253
return (T) renderer;
254254
}
255255

framework/src/main/java/com/live2d/sdk/cubism/framework/motion/ACubismMotion.java

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.live2d.sdk.cubism.framework.id.CubismId;
1111
import com.live2d.sdk.cubism.framework.math.CubismMath;
1212
import com.live2d.sdk.cubism.framework.model.CubismModel;
13+
import com.live2d.sdk.cubism.framework.utils.CubismDebug;
1314

1415
import java.util.ArrayList;
1516
import java.util.Collections;
@@ -36,25 +37,7 @@ public void updateParameters(
3637
return;
3738
}
3839

39-
if (!motionQueueEntry.isStarted()) {
40-
motionQueueEntry.isStarted(true);
41-
42-
// Record the start time of the motion.
43-
motionQueueEntry.setStartTime(userTimeSeconds - offsetSeconds);
44-
// Record the start time of fade-in
45-
motionQueueEntry.setFadeInStartTime(userTimeSeconds);
46-
47-
final float duration = getDuration();
48-
49-
// Deal with the case where the status is set "end" before it has started.
50-
if (motionQueueEntry.getEndTime() < 0) {
51-
// If duration == -1, loop motion.
52-
float endTime = (duration <= 0)
53-
? -1
54-
: motionQueueEntry.getStartTime() + duration;
55-
motionQueueEntry.setEndTime(endTime);
56-
}
57-
}
40+
setupMotionQueueEntry(motionQueueEntry, userTimeSeconds);
5841

5942
float fadeWeight = updateFadeWeight(motionQueueEntry, userTimeSeconds);
6043

@@ -68,6 +51,43 @@ public void updateParameters(
6851
}
6952
}
7053

54+
/**
55+
* モーションの再生を開始するためのセットアップを行う。
56+
*
57+
* @param motionQueueEntry CubismMotionQueueManagerによって管理されるモーション
58+
* @param userTimeSeconds 総再生時間(秒)
59+
*/
60+
public void setupMotionQueueEntry(
61+
CubismMotionQueueEntry motionQueueEntry,
62+
final float userTimeSeconds
63+
) {
64+
if (!motionQueueEntry.isAvailable() || motionQueueEntry.isFinished()) {
65+
return;
66+
}
67+
68+
if (motionQueueEntry.isStarted()) {
69+
return;
70+
}
71+
72+
motionQueueEntry.isStarted(true);
73+
74+
// Record the start time of the motion.
75+
motionQueueEntry.setStartTime(userTimeSeconds - offsetSeconds);
76+
// Record the start time of fade-in
77+
motionQueueEntry.setFadeInStartTime(userTimeSeconds);
78+
79+
final float duration = getDuration();
80+
81+
// Deal with the case where the status is set "end" before it has started.
82+
if (motionQueueEntry.getEndTime() < 0) {
83+
// If duration == -1, loop motion.
84+
float endTime = (duration <= 0)
85+
? -1
86+
: motionQueueEntry.getStartTime() + duration;
87+
motionQueueEntry.setEndTime(endTime);
88+
}
89+
}
90+
7191
/**
7292
* モーションフェードのウェイト値を更新する。
7393
*
@@ -76,6 +96,10 @@ public void updateParameters(
7696
* @return 更新されたウェイト値
7797
*/
7898
public float updateFadeWeight(CubismMotionQueueEntry motionQueueEntry, float userTimeSeconds) {
99+
if(motionQueueEntry == null) {
100+
CubismDebug.cubismLogError("motionQueueEntry is null.");
101+
}
102+
79103
float fadeWeight = weight; // 現在の値と掛け合わせる割合
80104

81105
// ---- フェードイン・アウトの処理 ----

framework/src/main/java/com/live2d/sdk/cubism/framework/motion/CubismExpressionMotion.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,36 +107,27 @@ public static CubismExpressionMotion create(byte[] buffer) {
107107
* @param motionQueueEntry CubismMotionQueueManagerで管理されているモーション
108108
* @param expressionParameterValues モデルに適用する各パラメータの値
109109
* @param expressionIndex 表情のインデックス
110+
* @param fadeWeight 表情のウェイト
110111
*/
111112
public void calculateExpressionParameters(
112113
CubismModel model,
113114
float userTimeSeconds,
114115
CubismMotionQueueEntry motionQueueEntry,
115116
List<CubismExpressionMotionManager.ExpressionParameterValue> expressionParameterValues,
116-
int expressionIndex
117+
int expressionIndex,
118+
float fadeWeight
117119
) {
118-
if (!motionQueueEntry.isAvailable()) {
120+
if(motionQueueEntry == null || expressionParameterValues == null) {
119121
return;
120122
}
121123

122-
if (!motionQueueEntry.isStarted()) {
123-
motionQueueEntry.isStarted(true);
124-
motionQueueEntry.setStartTime(userTimeSeconds - offsetSeconds); // モーションの開始時刻を記録
125-
motionQueueEntry.setFadeInStartTime(userTimeSeconds); // フェードインの開始時刻
126-
127-
final float duration = getDuration();
128-
129-
if (motionQueueEntry.getEndTime() < 0.0f) {
130-
// 開始していないうちに終了設定している場合がある。
131-
float endTime = duration <= 0.0f
132-
? -1
133-
: motionQueueEntry.getStartTime() + duration;
134-
motionQueueEntry.setEndTime(endTime);
135-
// duration == -1 の場合はループする。
136-
}
124+
if (!motionQueueEntry.isAvailable()) {
125+
return;
137126
}
138127

139-
fadeWeight = updateFadeWeight(motionQueueEntry, userTimeSeconds);
128+
// CubismExpressionMotion.fadeWeight は廃止予定です。
129+
// 互換性のために処理は残りますが、実際には使用しておりません。
130+
this.fadeWeight = updateFadeWeight(motionQueueEntry, userTimeSeconds);
140131

141132
// モデルに適用する値を計算
142133
for (int i = 0; i < expressionParameterValues.size(); i++) {
@@ -166,9 +157,9 @@ public void calculateExpressionParameters(
166157
expParamValue.multiplyValue = DEFAULT_MULTIPLY_VALUE;
167158
expParamValue.overwriteValue = currentParameterValue;
168159
} else {
169-
expParamValue.additiveValue = calculateValue(expParamValue.additiveValue, DEFAULT_ADDITIVE_VALUE);
170-
expParamValue.multiplyValue = calculateValue(expParamValue.multiplyValue, DEFAULT_MULTIPLY_VALUE);
171-
expParamValue.overwriteValue = calculateValue(expParamValue.overwriteValue, currentParameterValue);
160+
expParamValue.additiveValue = calculateValue(expParamValue.additiveValue, DEFAULT_ADDITIVE_VALUE, fadeWeight);
161+
expParamValue.multiplyValue = calculateValue(expParamValue.multiplyValue, DEFAULT_MULTIPLY_VALUE, fadeWeight);
162+
expParamValue.overwriteValue = calculateValue(expParamValue.overwriteValue, currentParameterValue, fadeWeight);
172163
}
173164
continue;
174165
}
@@ -218,11 +209,17 @@ public List<ExpressionParameter> getExpressionParameters() {
218209
return parameters;
219210
}
220211

212+
221213
/**
222214
* 現在の表情のフェードのウェイト値を取得する。
223215
*
224216
* @return 表情のフェードのウェイト値
217+
*
218+
* @deprecated CubismExpressionMotion.fadeWeightが削除予定のため非推奨。
219+
* CubismExpressionMotionManager.getFadeWeight(int index) を使用してください。
220+
* @see CubismExpressionMotionManager#getFadeWeight(int index)
225221
*/
222+
@Deprecated
226223
public float getFadeWeight() {
227224
return fadeWeight;
228225
}
@@ -338,7 +335,7 @@ private enum ExpressionKey {
338335
*
339336
* @return 計算されたブレンド値
340337
*/
341-
private float calculateValue(float source, float destination) {
338+
private float calculateValue(float source, float destination, float fadeWeight) {
342339
return (source * (1.0f - fadeWeight)) + (destination * fadeWeight);
343340
}
344341

@@ -349,6 +346,9 @@ private float calculateValue(float source, float destination) {
349346

350347
/**
351348
* 表情の現在のウェイト
349+
*
350+
* @deprecated 不具合を引き起こす要因となるため非推奨。
352351
*/
352+
@Deprecated
353353
private float fadeWeight;
354354
}

framework/src/main/java/com/live2d/sdk/cubism/framework/motion/CubismExpressionMotionManager.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ public int getReservePriority() {
5454
return reservePriority;
5555
}
5656

57+
/**
58+
* 現在の表情のフェードのウェイト値を取得する。
59+
*
60+
* @param index 取得する表情モーションのインデックス
61+
*
62+
* @return 表情のフェードのウェイト値
63+
*
64+
* @throws IllegalArgumentException if an argument is an invalid value.
65+
*/
66+
public float getFadeWeight(int index) {
67+
if(fadeWeights.isEmpty()) {
68+
throw new IllegalArgumentException("No motion during playback.");
69+
}
70+
71+
if(fadeWeights.size() <= index || index < 0) {
72+
throw new IllegalArgumentException("The index is an invalid value.");
73+
}
74+
75+
return fadeWeights.get(index);
76+
}
77+
5778
/**
5879
* 予約中の表情モーションの優先度を設定する。
5980
*
@@ -76,7 +97,9 @@ public int startMotionPriority(ACubismMotion motion, int priority) {
7697
}
7798
currentPriority = priority; // 再生中モーションの優先度を設定
7899

79-
return startMotion(motion, userTimeSeconds);
100+
fadeWeights.add(0.0f);
101+
102+
return startMotion(motion);
80103
}
81104

82105
/**
@@ -148,12 +171,15 @@ public boolean updateMotion(CubismModel model, float deltaTimeSeconds) {
148171
}
149172

150173
// ------ 値を計算する ------
174+
expressionMotion.setupMotionQueueEntry(motionQueueEntry, userTimeSeconds);
175+
fadeWeights.set(expressionIndex, expressionMotion.updateFadeWeight(motionQueueEntry, userTimeSeconds));
151176
expressionMotion.calculateExpressionParameters(
152177
model,
153178
userTimeSeconds,
154179
motionQueueEntry,
155180
expressionParameterValues,
156-
expressionIndex
181+
expressionIndex,
182+
fadeWeights.get(expressionIndex)
157183
);
158184

159185
final float easingSine = expressionMotion.getFadeInTime() == 0.0f
@@ -175,11 +201,14 @@ public boolean updateMotion(CubismModel model, float deltaTimeSeconds) {
175201
if (motions.size() > 1) {
176202
CubismExpressionMotion expressionMotion = (CubismExpressionMotion) motions.get(motions.size() - 1).getCubismMotion();
177203

178-
if (expressionMotion.getFadeWeight() >= 1.0f) {
204+
float latestFadeWeight = fadeWeights.get(fadeWeights.size() - 1);
205+
if (latestFadeWeight >= 1.0f) {
179206
// 配列の最後の要素は削除しない
180207
for (int i = motions.size() - 2; i >= 0; i--) {
181208
// forでremoveすることはできない。nullをセットしておいて後で削除する。
182209
motions.set(i, null);
210+
211+
fadeWeights.remove(i);
183212
}
184213
motions.removeAll(nullSet);
185214
}
@@ -222,4 +251,9 @@ public boolean updateMotion(CubismModel model, float deltaTimeSeconds) {
222251
* 表情モーションファイルを別スレッドで読み込むときの機能。
223252
*/
224253
private int reservePriority;
254+
255+
/**
256+
* 再生中の表情モーションのウェイトのリスト
257+
*/
258+
private final List<Float> fadeWeights = new ArrayList<>();
225259
}

framework/src/main/java/com/live2d/sdk/cubism/framework/motion/CubismMotionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public int startMotionPriority(ACubismMotion motion, int priority) {
3030
// Set priority of the motion during playback.
3131
currentPriority = priority;
3232

33-
return startMotion(motion, userTimeSeconds);
33+
return startMotion(motion);
3434
}
3535

3636
/**

0 commit comments

Comments
 (0)