Skip to content

Commit 4f663fc

Browse files
Merge pull request #9 from Live2D/develop
Update to Cubism 5 SDK for Java R1 beta3
2 parents 5349541 + fa02ff6 commit 4f663fc

13 files changed

Lines changed: 96 additions & 47 deletions

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ 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-beta.3] - 2024-01-18
8+
9+
### Added
10+
11+
* Add exception catching and error logging handling when an exception is thrown while loading a JSON file.
12+
13+
### Changed
14+
15+
* Change the compile and target SDK version of Android OS to 14.0 (API 34).
16+
* Upgrade the version of Android Gradle Plugin from 8.0.2 to 8.1.1.
17+
* Upgrade the version of Gradle from 8.1.1 to 8.2.
18+
* Change the minimum version of Android Studio to Hedgehog(2023.1.1).
19+
* Change the visibility of the `CubismPhysicsInternal` and `CubismPhysicsJson` classes to `public`.
20+
21+
### Fixed
22+
23+
* Fix an issue where models with a specific number of masks could not be drawn correctly.
24+
* Replace deprecated notation in `build.gradle`.
25+
26+
727
## [5-r.1-beta.2] - 2023-09-28
828

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

135155
* New released!
136156

157+
[5-r.1-beta.3]: https://github.com/Live2D/CubismJavaFramework/compare/5-r.1-beta.2...5-r.1-beta.3
137158
[5-r.1-beta.2]: https://github.com/Live2D/CubismJavaFramework/compare/5-r.1-beta.1...5-r.1-beta.2
138159
[5-r.1-beta.1]: https://github.com/Live2D/CubismJavaFramework/compare/4-r.1...5-r.1-beta.1
139160
[4-r.1]: https://github.com/Live2D/CubismJavaFramework/compare/4-r.1-beta.4...4-r.1

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:8.0.2'
8+
classpath 'com.android.tools.build:gradle:8.1.1'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files

framework/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
android {
66
namespace = "com.live2d.sdk.cubism.framework"
7-
compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
7+
compileSdk PROP_COMPILE_SDK_VERSION.toInteger()
88

99
defaultConfig {
1010
minSdkVersion PROP_MIN_SDK_VERSION

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ protected CubismMotion loadMotion(
327327
byte[] buffer,
328328
IFinishedMotionCallback onFinishedMotionHandler
329329
) {
330-
return CubismMotion.create(buffer, onFinishedMotionHandler);
330+
try {
331+
return CubismMotion.create(buffer, onFinishedMotionHandler);
332+
} catch (Exception e) {
333+
cubismLogError("Failed to loadMotion(). %s", e.getMessage());
334+
return null;
335+
}
331336
}
332337

333338
/**
@@ -337,7 +342,7 @@ protected CubismMotion loadMotion(
337342
* @return motion class
338343
*/
339344
protected CubismMotion loadMotion(byte[] buffer) {
340-
return CubismMotion.create(buffer, null);
345+
return loadMotion(buffer, null);
341346
}
342347

343348
/**
@@ -347,7 +352,12 @@ protected CubismMotion loadMotion(byte[] buffer) {
347352
* @return motion class
348353
*/
349354
protected CubismExpressionMotion loadExpression(final byte[] buffer) {
350-
return CubismExpressionMotion.create(buffer);
355+
try {
356+
return CubismExpressionMotion.create(buffer);
357+
} catch (Exception e) {
358+
cubismLogError("Failed to loadExpressionMotion(). %s", e.getMessage());
359+
return null;
360+
}
351361
}
352362

353363
/**
@@ -356,7 +366,11 @@ protected CubismExpressionMotion loadExpression(final byte[] buffer) {
356366
* @param buffer a buffer where pose3.json is loaded.
357367
*/
358368
protected void loadPose(final byte[] buffer) {
359-
pose = CubismPose.create(buffer);
369+
try {
370+
pose = CubismPose.create(buffer);
371+
} catch (Exception e) {
372+
cubismLogError("Failed to loadPose(). %s", e.getMessage());
373+
}
360374
}
361375

362376
/**
@@ -365,7 +379,11 @@ protected void loadPose(final byte[] buffer) {
365379
* @param buffer a buffer where physics3.json is loaded.
366380
*/
367381
protected void loadPhysics(final byte[] buffer) {
368-
physics = CubismPhysics.create(buffer);
382+
try {
383+
physics = CubismPhysics.create(buffer);
384+
} catch (Exception e) {
385+
cubismLogError("Failed to loadPhysics(). %s", e.getMessage());
386+
}
369387
}
370388

371389
/**
@@ -374,7 +392,11 @@ protected void loadPhysics(final byte[] buffer) {
374392
* @param buffer a buffer where userdata3.json is loaded.
375393
*/
376394
protected void loadUserData(final byte[] buffer) {
377-
modelUserData = CubismModelUserData.create(buffer);
395+
try {
396+
modelUserData = CubismModelUserData.create(buffer);
397+
} catch (Exception e) {
398+
cubismLogError("Failed to loadUserData(). %s", e.getMessage());
399+
}
378400
}
379401

380402
/**

framework/src/main/java/com/live2d/sdk/cubism/framework/physics/CubismPhysicsInternal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Internal data of CubismPhysics.
1818
*/
19-
class CubismPhysicsInternal {
19+
public class CubismPhysicsInternal {
2020
/**
2121
* Types of physics operations to be applied.
2222
*/

framework/src/main/java/com/live2d/sdk/cubism/framework/physics/CubismPhysicsJson.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* A manager of physics3.json.
1717
*/
18-
class CubismPhysicsJson {
18+
public class CubismPhysicsJson {
1919
/**
2020
* Constructor
2121
*

framework/src/main/java/com/live2d/sdk/cubism/framework/rendering/ACubismClippingContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void addClippedDrawable(int drawableIndex) {
102102
/**
103103
* RGBAのいずれのチャンネルにこのクリップを配置するか(0:R, 1:G, 2:B, 3:A)
104104
*/
105-
public int layoutChannelNo;
105+
public int layoutChannelIndex;
106106

107107
/**
108108
* マスク用チャンネルのどの領域にマスクを入れるか(View座標-1..1, UVは0..1に直す)

framework/src/main/java/com/live2d/sdk/cubism/framework/rendering/ACubismClippingManager.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void setupLayoutBounds(int usingClipCount) {
257257
for (int index = 0; index < clippingContextListForMask.size(); index++) {
258258
T_ClippingContext cc = clippingContextListForMask.get(index);
259259

260-
cc.layoutChannelNo = 0; // どうせ毎回消すので固定で良い
260+
cc.layoutChannelIndex = 0; // どうせ毎回消すので固定で良い
261261
cc.layoutBounds.setX(0.0f);
262262
cc.layoutBounds.setY(0.0f);
263263
cc.layoutBounds.setWidth(1.0f);
@@ -272,25 +272,31 @@ public void setupLayoutBounds(int usingClipCount) {
272272

273273
// ひとつのRenderTextureを極力いっぱいに使ってマスクをレイアウトする。
274274
// マスクグループの数が4以下ならRGBA各チャンネルに1つずつマスクを配置し、5以上6以下ならRGBAを2,2,1,1と配置する。
275-
int countPerSheetDiv = usingClipCount / renderTextureCount; // レンダーテクスチャ1枚あたり何枚割り当てるか
276-
int countPerSheetMod = usingClipCount % renderTextureCount; // この番号のレンダーテクスチャまでに1つずつ配分する。
275+
// NOTE: 1枚に割り当てるマスクの分割数を取りたいため、小数点は切り上げる。
276+
final int countPerSheetDiv = (usingClipCount + renderTextureCount - 1) / renderTextureCount; // レンダーテクスチャ1枚あたり何枚割り当てるか
277+
final int reduceLayoutTextureCount = usingClipCount % renderTextureCount; // レイアウトの数を1枚減らすレンダーテクスチャの数(この数だけのレンダーテクスチャが対象)。
277278

278279
// RGBAを順番に使っていく。
279-
final int div = countPerSheetDiv / COLOR_CHANNEL_COUNT; // 1チャンネルに配置する基本のマスク個数
280-
final int mod = countPerSheetDiv % COLOR_CHANNEL_COUNT; // 余り、この番号のチャンネルまでに1つずつ配分する
280+
final int divCount = countPerSheetDiv / COLOR_CHANNEL_COUNT; // 1チャンネルに配置する基本のマスク個数
281+
final int modCount = countPerSheetDiv % COLOR_CHANNEL_COUNT; // 余り、この番号のチャンネルまでに1つずつ配分する(インデックスではない)
281282

282283
// RGBAそれぞれのチャンネルを用意していく(0:R , 1:G , 2:B, 3:A, )
283284
int curClipIndex = 0; // 順番に設定していく
284285

285-
for (int renderTextureNo = 0; renderTextureNo < renderTextureCount; renderTextureNo++) {
286-
for (int channelNo = 0; channelNo < COLOR_CHANNEL_COUNT; channelNo++) {
286+
for (int renderTextureIndex = 0; renderTextureIndex < renderTextureCount; renderTextureIndex++) {
287+
for (int channelIndex = 0; channelIndex < COLOR_CHANNEL_COUNT; channelIndex++) {
287288
// このチャンネルにレイアウトする数
288-
int layoutCount = div + (channelNo < mod ? 1 : 0);
289+
// NOTE: レイアウト数 = 1チャンネルに配置する基本のマスク + 余りのマスクを置くチャンネルなら1つ追加
290+
int layoutCount = divCount + (channelIndex < modCount ? 1 : 0);
289291

290-
// このレンダーテクスチャにまだ割り当てられていなければ追加する
291-
final int checkChannelNo = mod + 1 >= COLOR_CHANNEL_COUNT ? 0 : mod + 1;
292-
if (layoutCount < layoutCountMaxValue && channelNo == checkChannelNo) {
293-
layoutCount += renderTextureNo < countPerSheetMod ? 1 : 0;
292+
// レイアウトの数を1枚減らす場合にそれを行うチャンネルを決定
293+
// divが0の時は正常なインデックスの範囲になるように調整
294+
final int checkChannelIndex = modCount + (divCount < 1 ? -1 : 0);
295+
296+
// 今回が対象のチャンネルかつ、レイアウトの数を1枚減らすレンダーテクスチャが存在する場合
297+
if (channelIndex == checkChannelIndex && reduceLayoutTextureCount > 0) {
298+
// 現在のレンダーテクスチャが、対象のレンダーテクスチャであればレイアウトの数を1枚減らす。
299+
layoutCount -= !(renderTextureIndex < reduceLayoutTextureCount) ? 1 : 0;
294300
}
295301

296302
// 分割方法を決定する。
@@ -299,21 +305,21 @@ public void setupLayoutBounds(int usingClipCount) {
299305
} else if (layoutCount == 1) {
300306
// 全てをそのまま使う。
301307
T_ClippingContext cc = clippingContextListForMask.get(curClipIndex++);
302-
cc.layoutChannelNo = channelNo;
308+
cc.layoutChannelIndex = channelIndex;
303309
csmRectF bounds = cc.layoutBounds;
304310

305311
bounds.setX(0.0f);
306312
bounds.setY(0.0f);
307313
bounds.setWidth(1.0f);
308314
bounds.setHeight(1.0f);
309315

310-
cc.bufferIndex = renderTextureNo;
316+
cc.bufferIndex = renderTextureIndex;
311317
} else if (layoutCount == 2) {
312318
for (int i = 0; i < layoutCount; i++) {
313319
final int xpos = i % 2;
314320

315321
T_ClippingContext cc = clippingContextListForMask.get(curClipIndex++);
316-
cc.layoutChannelNo = channelNo;
322+
cc.layoutChannelIndex = channelIndex;
317323
csmRectF bounds = cc.layoutBounds;
318324

319325
// UVを2つに分解して使う
@@ -322,7 +328,7 @@ public void setupLayoutBounds(int usingClipCount) {
322328
bounds.setWidth(0.5f);
323329
bounds.setHeight(1.0f);
324330

325-
cc.bufferIndex = renderTextureNo;
331+
cc.bufferIndex = renderTextureIndex;
326332
}
327333
} else if (layoutCount <= 4) {
328334
// 4分割して使う
@@ -331,15 +337,15 @@ public void setupLayoutBounds(int usingClipCount) {
331337
final int ypos = i / 2;
332338

333339
T_ClippingContext cc = clippingContextListForMask.get(curClipIndex++);
334-
cc.layoutChannelNo = channelNo;
340+
cc.layoutChannelIndex = channelIndex;
335341
csmRectF bounds = cc.layoutBounds;
336342

337343
bounds.setX(xpos * 0.5f);
338344
bounds.setY(ypos * 0.5f);
339345
bounds.setWidth(0.5f);
340346
bounds.setHeight(0.5f);
341347

342-
cc.bufferIndex = renderTextureNo;
348+
cc.bufferIndex = renderTextureIndex;
343349
}
344350
} else if (layoutCount <= layoutCountMaxValue) {
345351
// 9分割して使う
@@ -348,15 +354,15 @@ public void setupLayoutBounds(int usingClipCount) {
348354
final int ypos = i / 3;
349355

350356
T_ClippingContext cc = clippingContextListForMask.get(curClipIndex++);
351-
cc.layoutChannelNo = channelNo;
357+
cc.layoutChannelIndex = channelIndex;
352358
csmRectF bounds = cc.layoutBounds;
353359

354360
bounds.setX(xpos / 3.0f);
355361
bounds.setY(ypos / 3.0f);
356362
bounds.setWidth(1.0f / 3.0f);
357363
bounds.setHeight(1.0f / 3.0f);
358364

359-
cc.bufferIndex = renderTextureNo;
365+
cc.bufferIndex = renderTextureIndex;
360366
}
361367
}
362368
// マスクの制限枚数を超えた場合の処理
@@ -376,7 +382,7 @@ public void setupLayoutBounds(int usingClipCount) {
376382
// もちろん描画結果はろくなことにならない。
377383
for (int i = 0; i < layoutCount; i++) {
378384
T_ClippingContext cc = clippingContextListForMask.get(curClipIndex++);
379-
cc.layoutChannelNo = 0;
385+
cc.layoutChannelIndex = 0;
380386

381387
csmRectF bounds = cc.layoutBounds;
382388
bounds.setX(0.0f);
@@ -407,8 +413,8 @@ public int getRenderTextureCount() {
407413
}
408414

409415
@Override
410-
public CubismRenderer.CubismTextureColor getChannelFlagAsColor(int channelNo) {
411-
return channelColors.get(channelNo);
416+
public CubismRenderer.CubismTextureColor getChannelFlagAsColor(int channelIndex) {
417+
return channelColors.get(channelIndex);
412418
}
413419

414420
/**

framework/src/main/java/com/live2d/sdk/cubism/framework/rendering/ICubismClippingManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void createMatrixForMask(
9696
/**
9797
* カラーチャンネル(RGBA)のフラグを取得する。
9898
*
99-
* @param channelNo カラーチャンネル(RGBA)の番号(0:R, 1:G, 2:B, 3:A)
99+
* @param channelIndex カラーチャンネル(RGBA)の番号(0:R, 1:G, 2:B, 3:A)
100100
* @return カラーチャンネルのフラグ
101101
*/
102-
CubismRenderer.CubismTextureColor getChannelFlagAsColor(int channelNo);
102+
CubismRenderer.CubismTextureColor getChannelFlagAsColor(int channelIndex);
103103
}

framework/src/main/java/com/live2d/sdk/cubism/framework/rendering/android/CubismRendererAndroid.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ public void close() {
123123
/**
124124
* Bind processing of OpenGL textures.
125125
*
126-
* @param modelTextureNo number of the model texture to set
127-
* @param glTextureNo number of the OpenGL texture to bind
126+
* @param modelTextureIndex number of the model texture to set
127+
* @param glTextureIndex number of the OpenGL texture to bind
128128
*/
129-
public void bindTexture(int modelTextureNo, int glTextureNo) {
130-
textures.put(modelTextureNo, glTextureNo);
129+
public void bindTexture(int modelTextureIndex, int glTextureIndex) {
130+
textures.put(modelTextureIndex, glTextureIndex);
131131
areTexturesChanged = true;
132132
}
133133

0 commit comments

Comments
 (0)