untitled-pixi-live2d-engine 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/dist/cubism-legacy.es.js +170 -49
- package/dist/cubism-legacy.js +172 -50
- package/dist/cubism-legacy.min.js +1 -1
- package/dist/cubism.es.js +186 -57
- package/dist/cubism.js +188 -58
- package/dist/cubism.min.js +1 -1
- package/dist/index.es.js +191 -60
- package/dist/index.js +193 -61
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +56 -29
package/README.md
CHANGED
|
@@ -47,12 +47,13 @@ Complex models (many masked drawables, high vertex density, etc.) can produce vi
|
|
|
47
47
|
|
|
48
48
|
- **Parallel playback**: drive multiple motion groups simultaneously, useful for independent upper/lower body animations
|
|
49
49
|
- **Last-frame freeze**: hold a motion on its final frame, useful for pose switching or static illustrations
|
|
50
|
+
- **Loop override**: set `loop` per parallel motion item to override Cubism 3/4/5 motion JSON loop metadata
|
|
50
51
|
|
|
51
52
|
```ts
|
|
52
53
|
// Parallel playback
|
|
53
54
|
model.parallelMotion([
|
|
54
55
|
{ group: 'upper_body', index: 0 },
|
|
55
|
-
{ group: 'lower_body', index: 1 }
|
|
56
|
+
{ group: 'lower_body', index: 1, loop: true }
|
|
56
57
|
])
|
|
57
58
|
|
|
58
59
|
// Last-frame freeze
|
|
@@ -107,6 +108,16 @@ import { Live2DModel } from 'untitled-pixi-live2d-engine/cubism'
|
|
|
107
108
|
<script src="https://cdn.jsdelivr.net/npm/untitled-pixi-live2d-engine/dist/index.min.js"></script>
|
|
108
109
|
```
|
|
109
110
|
|
|
111
|
+
`@pixi/sound` is optional. Load it before this package only when using motion sounds, `model.speak()`, or lip sync:
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<script src="https://cdn.jsdelivr.net/npm/pixi.js@8/dist/pixi.min.js"></script>
|
|
115
|
+
<script src="https://cdn.jsdelivr.net/npm/@pixi/sound@6/dist/pixi-sound.js"></script>
|
|
116
|
+
<script src="https://cdn.jsdelivr.net/npm/untitled-pixi-live2d-engine/dist/index.min.js"></script>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
If your app does not use audio features, you can omit `pixi-sound.js`.
|
|
120
|
+
|
|
110
121
|
## Cubism Runtime
|
|
111
122
|
|
|
112
123
|
Live2D models are split into two categories by Cubism architecture, each requiring a different external runtime:
|
|
@@ -174,7 +185,7 @@ model.motion('group', index)
|
|
|
174
185
|
```ts
|
|
175
186
|
model.parallelMotion([
|
|
176
187
|
{ group: group1, index: index1 },
|
|
177
|
-
{ group: group2, index: index2 }
|
|
188
|
+
{ group: group2, index: index2, loop: true }
|
|
178
189
|
])
|
|
179
190
|
```
|
|
180
191
|
|
package/dist/cubism-legacy.es.js
CHANGED
|
@@ -40,7 +40,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
42
|
import { EventEmitter, Matrix, loadTextures, Assets, Ticker, Transform, Point, Bounds, ExtensionType, Container, ObservablePoint, WebGLRenderer, DOMAdapter, Texture, CanvasSource } from "pixi.js";
|
|
43
|
-
import { sound, Sound, webaudio } from "@pixi/sound";
|
|
44
43
|
const LOGICAL_WIDTH = 2;
|
|
45
44
|
const LOGICAL_HEIGHT = 2;
|
|
46
45
|
const CSM_LOG_LEVEL_VERBOSE = 0;
|
|
@@ -106,7 +105,7 @@ const config = {
|
|
|
106
105
|
preserveExpressionOnMotion: true,
|
|
107
106
|
cubism: CubismFrameworkConfig
|
|
108
107
|
};
|
|
109
|
-
const VERSION = "1.
|
|
108
|
+
const VERSION = "1.3.1";
|
|
110
109
|
const logger = {
|
|
111
110
|
log(tag, ...messages) {
|
|
112
111
|
if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
|
|
@@ -825,7 +824,64 @@ class MotionState {
|
|
|
825
824
|
}
|
|
826
825
|
const TAG$2 = "SoundManager";
|
|
827
826
|
const VOLUME = 0.5;
|
|
828
|
-
|
|
827
|
+
const SOUND_ALIAS_PREFIX = "live2d-sound-";
|
|
828
|
+
let soundId = 0;
|
|
829
|
+
let pixiSoundPromise;
|
|
830
|
+
const configuredLibraries = /* @__PURE__ */ new WeakSet();
|
|
831
|
+
function configureSoundLibrary(library) {
|
|
832
|
+
if (!configuredLibraries.has(library)) {
|
|
833
|
+
try {
|
|
834
|
+
library.disableAutoPause = true;
|
|
835
|
+
} catch (e) {
|
|
836
|
+
logger.warn(TAG$2, "Failed to disable @pixi/sound auto pause.", e);
|
|
837
|
+
}
|
|
838
|
+
configuredLibraries.add(library);
|
|
839
|
+
}
|
|
840
|
+
return library;
|
|
841
|
+
}
|
|
842
|
+
function getGlobalSoundLibrary() {
|
|
843
|
+
return typeof PIXI !== "undefined" ? PIXI == null ? void 0 : PIXI.sound : void 0;
|
|
844
|
+
}
|
|
845
|
+
function resolveSoundLibrary() {
|
|
846
|
+
return __async(this, null, function* () {
|
|
847
|
+
const globalLibrary = getGlobalSoundLibrary();
|
|
848
|
+
if (globalLibrary) {
|
|
849
|
+
return configureSoundLibrary(globalLibrary);
|
|
850
|
+
}
|
|
851
|
+
pixiSoundPromise != null ? pixiSoundPromise : pixiSoundPromise = import("@pixi/sound").then(({ sound }) => configureSoundLibrary(sound)).catch((e) => {
|
|
852
|
+
logger.warn(
|
|
853
|
+
TAG$2,
|
|
854
|
+
"@pixi/sound is not available. Load pixi-sound.js before using motion sounds, speak(), or lip sync.",
|
|
855
|
+
e
|
|
856
|
+
);
|
|
857
|
+
return null;
|
|
858
|
+
});
|
|
859
|
+
return pixiSoundPromise;
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
function removeSound(library, alias) {
|
|
863
|
+
try {
|
|
864
|
+
library.remove(alias);
|
|
865
|
+
} catch (e) {
|
|
866
|
+
logger.warn(TAG$2, `Failed to remove sound "${alias}".`, e);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
function destroySound(audio) {
|
|
870
|
+
try {
|
|
871
|
+
audio.destroy();
|
|
872
|
+
} catch (e) {
|
|
873
|
+
logger.warn(TAG$2, "Failed to destroy audio.", e);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
function getAudioBuffer(audio) {
|
|
877
|
+
const media = audio.media;
|
|
878
|
+
const buffer = media.buffer;
|
|
879
|
+
if (!buffer || typeof buffer !== "object") {
|
|
880
|
+
return void 0;
|
|
881
|
+
}
|
|
882
|
+
const candidate = buffer;
|
|
883
|
+
return typeof candidate.getChannelData === "function" ? buffer : void 0;
|
|
884
|
+
}
|
|
829
885
|
class SoundManager {
|
|
830
886
|
/**
|
|
831
887
|
* Global volume that applies to all the sounds.
|
|
@@ -846,22 +902,47 @@ class SoundManager {
|
|
|
846
902
|
*/
|
|
847
903
|
static add(file, onError) {
|
|
848
904
|
return __async(this, null, function* () {
|
|
905
|
+
let library = null;
|
|
906
|
+
let alias;
|
|
849
907
|
try {
|
|
908
|
+
library = yield resolveSoundLibrary();
|
|
909
|
+
if (!library) {
|
|
910
|
+
throw new Error("@pixi/sound is not available");
|
|
911
|
+
}
|
|
912
|
+
alias = `${SOUND_ALIAS_PREFIX}${soundId++}`;
|
|
913
|
+
const soundLibrary = library;
|
|
914
|
+
const soundAlias = alias;
|
|
850
915
|
const task = new Promise((resolve, reject) => {
|
|
851
|
-
const
|
|
916
|
+
const audio2 = soundLibrary.add(soundAlias, {
|
|
852
917
|
url: file,
|
|
853
918
|
volume: this._volume,
|
|
854
919
|
preload: true,
|
|
855
|
-
loaded: () => {
|
|
856
|
-
if (
|
|
920
|
+
loaded: (error, loadedAudio) => {
|
|
921
|
+
if (error) {
|
|
922
|
+
reject(error);
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
const sound = loadedAudio != null ? loadedAudio : audio2;
|
|
926
|
+
if (!sound) {
|
|
927
|
+
reject(new Error(`Error: ${file} failed to load`));
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
if (!getAudioBuffer(sound)) {
|
|
857
931
|
reject(new Error(`Error: ${file} is not WebAudioMedia`));
|
|
932
|
+
return;
|
|
858
933
|
}
|
|
859
|
-
resolve(
|
|
934
|
+
resolve(sound);
|
|
860
935
|
}
|
|
861
936
|
});
|
|
862
937
|
});
|
|
863
|
-
|
|
938
|
+
const audio = yield task;
|
|
939
|
+
this.aliases.set(audio, { alias: soundAlias, library: soundLibrary });
|
|
940
|
+
this.audios.push(audio);
|
|
941
|
+
return audio;
|
|
864
942
|
} catch (e) {
|
|
943
|
+
if (library && alias) {
|
|
944
|
+
removeSound(library, alias);
|
|
945
|
+
}
|
|
865
946
|
logger.warn(TAG$2, `Error occurred on "${file}"`, e);
|
|
866
947
|
onError == null ? void 0 : onError(e);
|
|
867
948
|
return null;
|
|
@@ -878,14 +959,18 @@ class SoundManager {
|
|
|
878
959
|
singleInstance: true,
|
|
879
960
|
complete: () => {
|
|
880
961
|
onFinish == null ? void 0 : onFinish();
|
|
881
|
-
|
|
962
|
+
this.dispose(audio);
|
|
882
963
|
}
|
|
883
964
|
});
|
|
884
965
|
}
|
|
885
966
|
static addAnalyzer(audio, context) {
|
|
886
|
-
const
|
|
967
|
+
const buffer = getAudioBuffer(audio);
|
|
968
|
+
if (!buffer) {
|
|
969
|
+
logger.warn(TAG$2, "Cannot create audio analyzer because WebAudio media is unavailable.");
|
|
970
|
+
return void 0;
|
|
971
|
+
}
|
|
887
972
|
const source = context.createBufferSource();
|
|
888
|
-
source.buffer =
|
|
973
|
+
source.buffer = buffer;
|
|
889
974
|
const analyser = context.createAnalyser();
|
|
890
975
|
analyser.fftSize = config.fftSize;
|
|
891
976
|
analyser.minDecibels = -90;
|
|
@@ -923,7 +1008,18 @@ class SoundManager {
|
|
|
923
1008
|
* @param audio - An audio element.
|
|
924
1009
|
*/
|
|
925
1010
|
static dispose(audio) {
|
|
926
|
-
|
|
1011
|
+
try {
|
|
1012
|
+
audio.pause();
|
|
1013
|
+
} catch (e) {
|
|
1014
|
+
logger.warn(TAG$2, "Failed to pause audio.", e);
|
|
1015
|
+
}
|
|
1016
|
+
const managedSound = this.aliases.get(audio);
|
|
1017
|
+
if (managedSound) {
|
|
1018
|
+
removeSound(managedSound.library, managedSound.alias);
|
|
1019
|
+
this.aliases.delete(audio);
|
|
1020
|
+
} else {
|
|
1021
|
+
destroySound(audio);
|
|
1022
|
+
}
|
|
927
1023
|
remove(this.audios, audio);
|
|
928
1024
|
}
|
|
929
1025
|
/**
|
|
@@ -947,6 +1043,7 @@ class SoundManager {
|
|
|
947
1043
|
__publicField(SoundManager, "audios", []);
|
|
948
1044
|
__publicField(SoundManager, "analysers", []);
|
|
949
1045
|
__publicField(SoundManager, "contexts", []);
|
|
1046
|
+
__publicField(SoundManager, "aliases", /* @__PURE__ */ new WeakMap());
|
|
950
1047
|
__publicField(SoundManager, "_volume", VOLUME);
|
|
951
1048
|
var MotionPreloadStrategy = /* @__PURE__ */ ((MotionPreloadStrategy2) => {
|
|
952
1049
|
MotionPreloadStrategy2["ALL"] = "ALL";
|
|
@@ -1131,7 +1228,7 @@ class MotionManager extends EventEmitter {
|
|
|
1131
1228
|
* @returns Promise that resolves with true if the sound is playing, false otherwise.
|
|
1132
1229
|
*/
|
|
1133
1230
|
speak(_0) {
|
|
1134
|
-
return __async(this, arguments, function* (
|
|
1231
|
+
return __async(this, arguments, function* (sound, {
|
|
1135
1232
|
volume = VOLUME,
|
|
1136
1233
|
expression,
|
|
1137
1234
|
resetExpression = true,
|
|
@@ -1148,16 +1245,16 @@ class MotionManager extends EventEmitter {
|
|
|
1148
1245
|
}
|
|
1149
1246
|
}
|
|
1150
1247
|
let soundURL;
|
|
1151
|
-
const isBase64Content =
|
|
1152
|
-
if (
|
|
1248
|
+
const isBase64Content = sound && sound.startsWith("data:");
|
|
1249
|
+
if (sound && !isBase64Content) {
|
|
1153
1250
|
const A = document.createElement("a");
|
|
1154
|
-
A.href =
|
|
1155
|
-
|
|
1156
|
-
soundURL =
|
|
1251
|
+
A.href = sound;
|
|
1252
|
+
sound = A.href;
|
|
1253
|
+
soundURL = sound;
|
|
1157
1254
|
} else {
|
|
1158
1255
|
soundURL = "data:audio/";
|
|
1159
1256
|
}
|
|
1160
|
-
const file =
|
|
1257
|
+
const file = sound;
|
|
1161
1258
|
if (file) {
|
|
1162
1259
|
try {
|
|
1163
1260
|
audio = yield SoundManager.add(file, (e, that = this) => {
|
|
@@ -1168,6 +1265,9 @@ class MotionManager extends EventEmitter {
|
|
|
1168
1265
|
}
|
|
1169
1266
|
that.currentAudio = void 0;
|
|
1170
1267
|
});
|
|
1268
|
+
if (!audio) {
|
|
1269
|
+
return false;
|
|
1270
|
+
}
|
|
1171
1271
|
this.initializeAudio(audio, volume);
|
|
1172
1272
|
} catch (e) {
|
|
1173
1273
|
logger.warn(this.tag, "Failed to create audio", soundURL, e);
|
|
@@ -1217,17 +1317,19 @@ class MotionManager extends EventEmitter {
|
|
|
1217
1317
|
* @param onFinish - Callback when playback finishes.
|
|
1218
1318
|
* @param onError - Callback when playback errors.
|
|
1219
1319
|
* @param ignoreParamIds - The ids to be ignored.
|
|
1320
|
+
* @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
|
|
1220
1321
|
* @return Promise that resolves with true if the motion is successfully started, false otherwise.
|
|
1221
1322
|
*/
|
|
1222
1323
|
startMotion(_0, _1) {
|
|
1223
1324
|
return __async(this, arguments, function* (group, index, priority = MotionPriority.NORMAL, {
|
|
1224
|
-
sound
|
|
1325
|
+
sound = void 0,
|
|
1225
1326
|
volume = VOLUME,
|
|
1226
1327
|
expression = void 0,
|
|
1227
1328
|
resetExpression = true,
|
|
1228
1329
|
onFinish,
|
|
1229
1330
|
onError,
|
|
1230
|
-
ignoreParamIds = []
|
|
1331
|
+
ignoreParamIds = [],
|
|
1332
|
+
loop = void 0
|
|
1231
1333
|
} = {}) {
|
|
1232
1334
|
if (this.destroyed) {
|
|
1233
1335
|
return false;
|
|
@@ -1249,12 +1351,12 @@ class MotionManager extends EventEmitter {
|
|
|
1249
1351
|
}
|
|
1250
1352
|
let audio;
|
|
1251
1353
|
let soundURL;
|
|
1252
|
-
const isBase64Content =
|
|
1253
|
-
if (
|
|
1354
|
+
const isBase64Content = sound && sound.startsWith("data:");
|
|
1355
|
+
if (sound && !isBase64Content) {
|
|
1254
1356
|
const A = document.createElement("a");
|
|
1255
|
-
A.href =
|
|
1256
|
-
|
|
1257
|
-
soundURL =
|
|
1357
|
+
A.href = sound;
|
|
1358
|
+
sound = A.href;
|
|
1359
|
+
soundURL = sound;
|
|
1258
1360
|
} else {
|
|
1259
1361
|
soundURL = this.getSoundFile(definition);
|
|
1260
1362
|
if (soundURL) {
|
|
@@ -1272,7 +1374,9 @@ class MotionManager extends EventEmitter {
|
|
|
1272
1374
|
}
|
|
1273
1375
|
that.currentAudio = void 0;
|
|
1274
1376
|
});
|
|
1275
|
-
|
|
1377
|
+
if (audio) {
|
|
1378
|
+
this.initializeAudio(audio, volume);
|
|
1379
|
+
}
|
|
1276
1380
|
} catch (e) {
|
|
1277
1381
|
logger.warn(this.tag, "Failed to create audio", soundURL, e);
|
|
1278
1382
|
}
|
|
@@ -1310,7 +1414,7 @@ class MotionManager extends EventEmitter {
|
|
|
1310
1414
|
}
|
|
1311
1415
|
this.playing = true;
|
|
1312
1416
|
if (motion) {
|
|
1313
|
-
this._startMotion(motion, void 0, ignoreParamIds);
|
|
1417
|
+
this._startMotion(motion, void 0, ignoreParamIds, loop);
|
|
1314
1418
|
}
|
|
1315
1419
|
return true;
|
|
1316
1420
|
});
|
|
@@ -1326,16 +1430,18 @@ class MotionManager extends EventEmitter {
|
|
|
1326
1430
|
* @param crossOrigin - Cross origin setting.
|
|
1327
1431
|
* @param onFinish - Callback when playback finishes.
|
|
1328
1432
|
* @param onError - Callback when playback errors.
|
|
1433
|
+
* @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
|
|
1329
1434
|
* @return Promise that resolves with true if the motion is successfully started, false otherwise.
|
|
1330
1435
|
*/
|
|
1331
1436
|
startRandomMotion(_0, _1) {
|
|
1332
1437
|
return __async(this, arguments, function* (group, priority, {
|
|
1333
|
-
sound
|
|
1438
|
+
sound,
|
|
1334
1439
|
volume = VOLUME,
|
|
1335
1440
|
expression,
|
|
1336
1441
|
resetExpression = true,
|
|
1337
1442
|
onFinish,
|
|
1338
|
-
onError
|
|
1443
|
+
onError,
|
|
1444
|
+
loop = void 0
|
|
1339
1445
|
} = {}) {
|
|
1340
1446
|
var _a, _b;
|
|
1341
1447
|
if (this.destroyed) {
|
|
@@ -1353,12 +1459,13 @@ class MotionManager extends EventEmitter {
|
|
|
1353
1459
|
if (availableIndices.length) {
|
|
1354
1460
|
const index = availableIndices[Math.floor(Math.random() * availableIndices.length)];
|
|
1355
1461
|
return this.startMotion(group, index, priority, {
|
|
1356
|
-
sound
|
|
1462
|
+
sound,
|
|
1357
1463
|
volume,
|
|
1358
1464
|
expression,
|
|
1359
1465
|
resetExpression,
|
|
1360
1466
|
onFinish,
|
|
1361
|
-
onError
|
|
1467
|
+
onError,
|
|
1468
|
+
loop
|
|
1362
1469
|
});
|
|
1363
1470
|
}
|
|
1364
1471
|
}
|
|
@@ -3109,34 +3216,38 @@ class Live2DModel extends Container {
|
|
|
3109
3216
|
* @param [options.resetExpression=true] - Reset the expression to default after the motion is finished.
|
|
3110
3217
|
* @param [options.onFinish] - Callback function when speaking completes.
|
|
3111
3218
|
* @param [options.onError] - Callback function when an error occurs.
|
|
3219
|
+
* @param [options.loop] - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
|
|
3112
3220
|
* @return Promise that resolves with true if the motion is successfully started, with false otherwise.
|
|
3113
3221
|
*/
|
|
3114
3222
|
motion(_0, _1, _2) {
|
|
3115
3223
|
return __async(this, arguments, function* (group, index, priority, {
|
|
3116
|
-
sound
|
|
3224
|
+
sound = void 0,
|
|
3117
3225
|
volume = VOLUME,
|
|
3118
3226
|
expression = void 0,
|
|
3119
3227
|
resetExpression = true,
|
|
3120
3228
|
onFinish,
|
|
3121
|
-
onError
|
|
3229
|
+
onError,
|
|
3230
|
+
loop = void 0
|
|
3122
3231
|
} = {}) {
|
|
3123
3232
|
if (index === void 0) {
|
|
3124
3233
|
return this.internalModel.motionManager.startRandomMotion(group, priority, {
|
|
3125
|
-
sound
|
|
3234
|
+
sound,
|
|
3126
3235
|
volume,
|
|
3127
3236
|
expression,
|
|
3128
3237
|
resetExpression,
|
|
3129
3238
|
onFinish,
|
|
3130
|
-
onError
|
|
3239
|
+
onError,
|
|
3240
|
+
loop
|
|
3131
3241
|
});
|
|
3132
3242
|
} else {
|
|
3133
3243
|
return this.internalModel.motionManager.startMotion(group, index, priority, {
|
|
3134
|
-
sound
|
|
3244
|
+
sound,
|
|
3135
3245
|
volume,
|
|
3136
3246
|
expression,
|
|
3137
3247
|
resetExpression,
|
|
3138
3248
|
onFinish,
|
|
3139
|
-
onError
|
|
3249
|
+
onError,
|
|
3250
|
+
loop
|
|
3140
3251
|
});
|
|
3141
3252
|
}
|
|
3142
3253
|
});
|
|
@@ -3154,13 +3265,18 @@ class Live2DModel extends Container {
|
|
|
3154
3265
|
* group: The motion group,
|
|
3155
3266
|
* index: Index in the motion group,
|
|
3156
3267
|
* priority: The priority to be applied. (0: No priority, 1: IDLE, 2:NORMAL, 3:FORCE) (default: 2)
|
|
3268
|
+
* ignoreParamIds: The ids to be ignored,
|
|
3269
|
+
* loop: Whether the motion should loop.
|
|
3157
3270
|
* @return Promise that resolves with a list, indicates the motion is successfully started, with false otherwise.
|
|
3158
3271
|
*/
|
|
3159
3272
|
parallelMotion(motionList) {
|
|
3160
3273
|
return __async(this, null, function* () {
|
|
3161
3274
|
this.internalModel.extendParallelMotionManager(motionList.length);
|
|
3162
3275
|
const result = motionList.map(
|
|
3163
|
-
(m, idx) => this.internalModel.parallelMotionManager[idx].startMotion(m.group, m.index, m.priority
|
|
3276
|
+
(m, idx) => this.internalModel.parallelMotionManager[idx].startMotion(m.group, m.index, m.priority, {
|
|
3277
|
+
ignoreParamIds: m.ignoreParamIds,
|
|
3278
|
+
loop: m.loop
|
|
3279
|
+
})
|
|
3164
3280
|
);
|
|
3165
3281
|
const flags = [];
|
|
3166
3282
|
for (const r of result) {
|
|
@@ -3214,14 +3330,14 @@ class Live2DModel extends Container {
|
|
|
3214
3330
|
* @param [options.onError] - Callback function when an error occurs.
|
|
3215
3331
|
* @returns Promise that resolves with true if the sound is playing, false if it's not.
|
|
3216
3332
|
*/
|
|
3217
|
-
speak(
|
|
3333
|
+
speak(sound, {
|
|
3218
3334
|
volume = VOLUME,
|
|
3219
3335
|
expression,
|
|
3220
3336
|
resetExpression = true,
|
|
3221
3337
|
onFinish,
|
|
3222
3338
|
onError
|
|
3223
3339
|
} = {}) {
|
|
3224
|
-
return this.internalModel.motionManager.speak(
|
|
3340
|
+
return this.internalModel.motionManager.speak(sound, {
|
|
3225
3341
|
volume,
|
|
3226
3342
|
expression,
|
|
3227
3343
|
resetExpression,
|
|
@@ -3548,7 +3664,7 @@ class CubismLegacyMotionManager extends MotionManager {
|
|
|
3548
3664
|
getSoundFile(definition) {
|
|
3549
3665
|
return definition.sound;
|
|
3550
3666
|
}
|
|
3551
|
-
_startMotion(motion, onFinish, ignoreParamIds) {
|
|
3667
|
+
_startMotion(motion, onFinish, ignoreParamIds, _loop) {
|
|
3552
3668
|
motion.onFinishHandler = onFinish;
|
|
3553
3669
|
if (ignoreParamIds && ignoreParamIds.length > 0) {
|
|
3554
3670
|
motion.motions = motion.motions.filter((item) => {
|
|
@@ -3624,11 +3740,13 @@ class ParallelMotionManager extends EventEmitter {
|
|
|
3624
3740
|
* @param index - Index in the motion group.
|
|
3625
3741
|
* @param priority - The priority to be applied. default: 2 (NORMAL)
|
|
3626
3742
|
* @param ignoreParamIds - The ids to be ignored.
|
|
3743
|
+
* @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
|
|
3627
3744
|
* @return Promise that resolves with true if the motion is successfully started, with false otherwise.
|
|
3628
3745
|
*/
|
|
3629
3746
|
startMotion(_0, _1) {
|
|
3630
|
-
return __async(this, arguments, function* (group, index, priority = MotionPriority.NORMAL,
|
|
3747
|
+
return __async(this, arguments, function* (group, index, priority = MotionPriority.NORMAL, options = {}) {
|
|
3631
3748
|
var _a;
|
|
3749
|
+
const { ignoreParamIds = [], loop } = Array.isArray(options) ? { ignoreParamIds: options, loop: void 0 } : options;
|
|
3632
3750
|
if (!this.state.reserve(group, index, priority)) {
|
|
3633
3751
|
return false;
|
|
3634
3752
|
}
|
|
@@ -3643,7 +3761,7 @@ class ParallelMotionManager extends EventEmitter {
|
|
|
3643
3761
|
logger.log(this.tag, "Start motion:", this.getMotionName(definition));
|
|
3644
3762
|
this.emit("motionStart", group, index, void 0);
|
|
3645
3763
|
this.playing = true;
|
|
3646
|
-
this._startMotion(motion, void 0, ignoreParamIds);
|
|
3764
|
+
this._startMotion(motion, void 0, ignoreParamIds, loop);
|
|
3647
3765
|
return true;
|
|
3648
3766
|
});
|
|
3649
3767
|
}
|
|
@@ -3651,10 +3769,11 @@ class ParallelMotionManager extends EventEmitter {
|
|
|
3651
3769
|
* Starts a random Motion as given priority.
|
|
3652
3770
|
* @param group - The motion group.
|
|
3653
3771
|
* @param priority - The priority to be applied. (default: 1 `IDLE`)
|
|
3772
|
+
* @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
|
|
3654
3773
|
* @return Promise that resolves with true if the motion is successfully started, with false otherwise.
|
|
3655
3774
|
*/
|
|
3656
|
-
startRandomMotion(
|
|
3657
|
-
return __async(this,
|
|
3775
|
+
startRandomMotion(_0, _1) {
|
|
3776
|
+
return __async(this, arguments, function* (group, priority, { loop = void 0 } = {}) {
|
|
3658
3777
|
var _a;
|
|
3659
3778
|
const groupDefs = this.manager.definitions[group];
|
|
3660
3779
|
if (groupDefs == null ? void 0 : groupDefs.length) {
|
|
@@ -3667,7 +3786,7 @@ class ParallelMotionManager extends EventEmitter {
|
|
|
3667
3786
|
}
|
|
3668
3787
|
if (availableIndices.length) {
|
|
3669
3788
|
const index = availableIndices[Math.floor(Math.random() * availableIndices.length)];
|
|
3670
|
-
return this.startMotion(group, index, priority);
|
|
3789
|
+
return this.startMotion(group, index, priority, { loop });
|
|
3671
3790
|
}
|
|
3672
3791
|
}
|
|
3673
3792
|
return false;
|
|
@@ -3717,7 +3836,7 @@ class CubismLegacyParallelMotionManager extends ParallelMotionManager {
|
|
|
3717
3836
|
getMotionName(definition) {
|
|
3718
3837
|
return definition.file;
|
|
3719
3838
|
}
|
|
3720
|
-
_startMotion(motion, onFinish, ignoreParamIds) {
|
|
3839
|
+
_startMotion(motion, onFinish, ignoreParamIds, _loop) {
|
|
3721
3840
|
motion.onFinishHandler = onFinish;
|
|
3722
3841
|
if (ignoreParamIds && ignoreParamIds.length > 0) {
|
|
3723
3842
|
motion.motions = motion.motions.filter((item) => {
|
|
@@ -3878,7 +3997,9 @@ class CubismLegacyInternalModel extends InternalModel {
|
|
|
3878
3997
|
}
|
|
3879
3998
|
this.motionManager = new CubismLegacyMotionManager(this);
|
|
3880
3999
|
this.parallelMotionManager = [];
|
|
3881
|
-
this.eyeBlink
|
|
4000
|
+
if (this.options.eyeBlink !== false) {
|
|
4001
|
+
this.eyeBlink = new Live2DEyeBlink(coreModel);
|
|
4002
|
+
}
|
|
3882
4003
|
this.eyeballXParamIndex = coreModel.getParamIndex("PARAM_EYE_BALL_X");
|
|
3883
4004
|
this.eyeballYParamIndex = coreModel.getParamIndex("PARAM_EYE_BALL_Y");
|
|
3884
4005
|
this.angleXParamIndex = coreModel.getParamIndex("PARAM_ANGLE_X");
|