untitled-pixi-live2d-engine 1.2.1 → 1.3.0
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 +10 -0
- package/dist/cubism-legacy.es.js +182 -54
- package/dist/cubism-legacy.js +184 -55
- package/dist/cubism-legacy.min.js +1 -1
- package/dist/cubism.es.js +333 -67
- package/dist/cubism.js +335 -68
- package/dist/cubism.min.js +1 -1
- package/dist/index.es.js +338 -70
- package/dist/index.js +340 -71
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +51 -41
package/dist/index.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.0";
|
|
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
|
}
|
|
@@ -1477,6 +1584,118 @@ class MotionManager extends EventEmitter {
|
|
|
1477
1584
|
return definition;
|
|
1478
1585
|
}
|
|
1479
1586
|
}
|
|
1587
|
+
function setScale(matrix, scale) {
|
|
1588
|
+
matrix.a = scale;
|
|
1589
|
+
matrix.b = 0;
|
|
1590
|
+
matrix.c = 0;
|
|
1591
|
+
matrix.d = scale;
|
|
1592
|
+
}
|
|
1593
|
+
function getLayoutEntries(rawLayout) {
|
|
1594
|
+
const entries = [];
|
|
1595
|
+
for (const [key, value] of Object.entries(rawLayout)) {
|
|
1596
|
+
if (typeof value !== "number") {
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
entries.push([key, value]);
|
|
1600
|
+
}
|
|
1601
|
+
return entries;
|
|
1602
|
+
}
|
|
1603
|
+
function setupLayoutMatrix(matrix, originalWidth, originalHeight, rawLayout) {
|
|
1604
|
+
var _a, _b;
|
|
1605
|
+
const layout = __spreadValues({
|
|
1606
|
+
width: LOGICAL_WIDTH,
|
|
1607
|
+
height: LOGICAL_HEIGHT
|
|
1608
|
+
}, rawLayout);
|
|
1609
|
+
const layoutWidth = (_a = layout.width) != null ? _a : LOGICAL_WIDTH;
|
|
1610
|
+
const layoutHeight = (_b = layout.height) != null ? _b : LOGICAL_HEIGHT;
|
|
1611
|
+
matrix.identity();
|
|
1612
|
+
matrix.scale(layoutWidth / LOGICAL_WIDTH, layoutHeight / LOGICAL_HEIGHT);
|
|
1613
|
+
const width = originalWidth * matrix.a;
|
|
1614
|
+
const height = originalHeight * matrix.d;
|
|
1615
|
+
const offsetX = layout.x !== void 0 && layout.x - layoutWidth / 2 || layout.centerX !== void 0 && layout.centerX || layout.left !== void 0 && layout.left - layoutWidth / 2 || layout.right !== void 0 && layout.right + layoutWidth / 2 || 0;
|
|
1616
|
+
const offsetY = layout.y !== void 0 && layout.y - layoutHeight / 2 || layout.centerY !== void 0 && layout.centerY || layout.top !== void 0 && layout.top - layoutHeight / 2 || layout.bottom !== void 0 && layout.bottom + layoutHeight / 2 || 0;
|
|
1617
|
+
matrix.translate(width * offsetX, -height * offsetY);
|
|
1618
|
+
return {
|
|
1619
|
+
width,
|
|
1620
|
+
height
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
function getCubismLayoutWidth(state, aspect) {
|
|
1624
|
+
return LOGICAL_HEIGHT * aspect * state.scale;
|
|
1625
|
+
}
|
|
1626
|
+
function getCubismLayoutHeight(state) {
|
|
1627
|
+
return LOGICAL_HEIGHT * state.scale;
|
|
1628
|
+
}
|
|
1629
|
+
function setCubismWidth(state, aspect, width) {
|
|
1630
|
+
state.scale = width / (LOGICAL_HEIGHT * aspect);
|
|
1631
|
+
}
|
|
1632
|
+
function setCubismHeight(state, height) {
|
|
1633
|
+
state.scale = height / LOGICAL_HEIGHT;
|
|
1634
|
+
}
|
|
1635
|
+
function setCubismX(state, x) {
|
|
1636
|
+
state.x = x;
|
|
1637
|
+
}
|
|
1638
|
+
function setCubismY(state, y) {
|
|
1639
|
+
state.y = y;
|
|
1640
|
+
}
|
|
1641
|
+
function centerCubismX(state, aspect, x) {
|
|
1642
|
+
setCubismX(state, x - getCubismLayoutWidth(state, aspect) / 2);
|
|
1643
|
+
}
|
|
1644
|
+
function centerCubismY(state, y) {
|
|
1645
|
+
setCubismY(state, y - getCubismLayoutHeight(state) / 2);
|
|
1646
|
+
}
|
|
1647
|
+
function rightCubism(state, aspect, x) {
|
|
1648
|
+
setCubismX(state, x - getCubismLayoutWidth(state, aspect));
|
|
1649
|
+
}
|
|
1650
|
+
function bottomCubism(state, y) {
|
|
1651
|
+
setCubismY(state, y - getCubismLayoutHeight(state));
|
|
1652
|
+
}
|
|
1653
|
+
function setupCubismLayoutMatrix(matrix, originalWidth, originalHeight, rawLayout) {
|
|
1654
|
+
if (originalWidth <= 0 || originalHeight <= 0) {
|
|
1655
|
+
matrix.identity();
|
|
1656
|
+
return { width: 0, height: 0 };
|
|
1657
|
+
}
|
|
1658
|
+
const entries = getLayoutEntries(rawLayout);
|
|
1659
|
+
const aspect = originalWidth / originalHeight;
|
|
1660
|
+
const state = { scale: 1, x: 0, y: 0 };
|
|
1661
|
+
for (const [key, value] of entries) {
|
|
1662
|
+
if (key === "width") {
|
|
1663
|
+
setCubismWidth(state, aspect, value);
|
|
1664
|
+
} else if (key === "height") {
|
|
1665
|
+
setCubismHeight(state, value);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
for (const [key, value] of entries) {
|
|
1669
|
+
if (key === "x") {
|
|
1670
|
+
setCubismX(state, value);
|
|
1671
|
+
} else if (key === "y") {
|
|
1672
|
+
setCubismY(state, value);
|
|
1673
|
+
} else if (key === "centerX") {
|
|
1674
|
+
centerCubismX(state, aspect, value);
|
|
1675
|
+
} else if (key === "centerY") {
|
|
1676
|
+
centerCubismY(state, value);
|
|
1677
|
+
} else if (key === "top") {
|
|
1678
|
+
setCubismY(state, value);
|
|
1679
|
+
} else if (key === "bottom") {
|
|
1680
|
+
bottomCubism(state, value);
|
|
1681
|
+
} else if (key === "left") {
|
|
1682
|
+
setCubismX(state, value);
|
|
1683
|
+
} else if (key === "right") {
|
|
1684
|
+
rightCubism(state, aspect, value);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
const pixelsPerLogicalUnit = originalHeight / LOGICAL_HEIGHT;
|
|
1688
|
+
const defaultLogicalHalfWidth = LOGICAL_HEIGHT * aspect / 2;
|
|
1689
|
+
const defaultLogicalHalfHeight = LOGICAL_HEIGHT / 2;
|
|
1690
|
+
matrix.identity();
|
|
1691
|
+
setScale(matrix, state.scale);
|
|
1692
|
+
matrix.tx = pixelsPerLogicalUnit * (state.x + defaultLogicalHalfWidth) - originalWidth * state.scale / 2;
|
|
1693
|
+
matrix.ty = pixelsPerLogicalUnit * (defaultLogicalHalfHeight - state.y) - originalHeight * state.scale / 2;
|
|
1694
|
+
return {
|
|
1695
|
+
width: originalWidth * state.scale,
|
|
1696
|
+
height: originalHeight * state.scale
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1480
1699
|
function normalizeHitAreaDefs(raw, resolveIndex) {
|
|
1481
1700
|
if (!Array.isArray(raw)) {
|
|
1482
1701
|
return [];
|
|
@@ -1566,19 +1785,14 @@ class InternalModel extends EventEmitter {
|
|
|
1566
1785
|
const size = this.getSize();
|
|
1567
1786
|
self.originalWidth = size[0];
|
|
1568
1787
|
self.originalHeight = size[1];
|
|
1569
|
-
const
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
},
|
|
1788
|
+
const bounds = setupLayoutMatrix(
|
|
1789
|
+
this.localTransform,
|
|
1790
|
+
this.originalWidth,
|
|
1791
|
+
this.originalHeight,
|
|
1574
1792
|
this.getLayout()
|
|
1575
1793
|
);
|
|
1576
|
-
|
|
1577
|
-
self.
|
|
1578
|
-
self.height = this.originalHeight * this.localTransform.d;
|
|
1579
|
-
const offsetX = layout.x !== void 0 && layout.x - layout.width / 2 || layout.centerX !== void 0 && layout.centerX || layout.left !== void 0 && layout.left - layout.width / 2 || layout.right !== void 0 && layout.right + layout.width / 2 || 0;
|
|
1580
|
-
const offsetY = layout.y !== void 0 && layout.y - layout.height / 2 || layout.centerY !== void 0 && layout.centerY || layout.top !== void 0 && layout.top - layout.height / 2 || layout.bottom !== void 0 && layout.bottom + layout.height / 2 || 0;
|
|
1581
|
-
this.localTransform.translate(this.width * offsetX, -this.height * offsetY);
|
|
1794
|
+
self.width = bounds.width;
|
|
1795
|
+
self.height = bounds.height;
|
|
1582
1796
|
}
|
|
1583
1797
|
/**
|
|
1584
1798
|
* Sets up the hit areas by their definitions in settings.
|
|
@@ -3094,34 +3308,38 @@ class Live2DModel extends Container {
|
|
|
3094
3308
|
* @param [options.resetExpression=true] - Reset the expression to default after the motion is finished.
|
|
3095
3309
|
* @param [options.onFinish] - Callback function when speaking completes.
|
|
3096
3310
|
* @param [options.onError] - Callback function when an error occurs.
|
|
3311
|
+
* @param [options.loop] - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
|
|
3097
3312
|
* @return Promise that resolves with true if the motion is successfully started, with false otherwise.
|
|
3098
3313
|
*/
|
|
3099
3314
|
motion(_0, _1, _2) {
|
|
3100
3315
|
return __async(this, arguments, function* (group, index, priority, {
|
|
3101
|
-
sound
|
|
3316
|
+
sound = void 0,
|
|
3102
3317
|
volume = VOLUME,
|
|
3103
3318
|
expression = void 0,
|
|
3104
3319
|
resetExpression = true,
|
|
3105
3320
|
onFinish,
|
|
3106
|
-
onError
|
|
3321
|
+
onError,
|
|
3322
|
+
loop = void 0
|
|
3107
3323
|
} = {}) {
|
|
3108
3324
|
if (index === void 0) {
|
|
3109
3325
|
return this.internalModel.motionManager.startRandomMotion(group, priority, {
|
|
3110
|
-
sound
|
|
3326
|
+
sound,
|
|
3111
3327
|
volume,
|
|
3112
3328
|
expression,
|
|
3113
3329
|
resetExpression,
|
|
3114
3330
|
onFinish,
|
|
3115
|
-
onError
|
|
3331
|
+
onError,
|
|
3332
|
+
loop
|
|
3116
3333
|
});
|
|
3117
3334
|
} else {
|
|
3118
3335
|
return this.internalModel.motionManager.startMotion(group, index, priority, {
|
|
3119
|
-
sound
|
|
3336
|
+
sound,
|
|
3120
3337
|
volume,
|
|
3121
3338
|
expression,
|
|
3122
3339
|
resetExpression,
|
|
3123
3340
|
onFinish,
|
|
3124
|
-
onError
|
|
3341
|
+
onError,
|
|
3342
|
+
loop
|
|
3125
3343
|
});
|
|
3126
3344
|
}
|
|
3127
3345
|
});
|
|
@@ -3199,14 +3417,14 @@ class Live2DModel extends Container {
|
|
|
3199
3417
|
* @param [options.onError] - Callback function when an error occurs.
|
|
3200
3418
|
* @returns Promise that resolves with true if the sound is playing, false if it's not.
|
|
3201
3419
|
*/
|
|
3202
|
-
speak(
|
|
3420
|
+
speak(sound, {
|
|
3203
3421
|
volume = VOLUME,
|
|
3204
3422
|
expression,
|
|
3205
3423
|
resetExpression = true,
|
|
3206
3424
|
onFinish,
|
|
3207
3425
|
onError
|
|
3208
3426
|
} = {}) {
|
|
3209
|
-
return this.internalModel.motionManager.speak(
|
|
3427
|
+
return this.internalModel.motionManager.speak(sound, {
|
|
3210
3428
|
volume,
|
|
3211
3429
|
expression,
|
|
3212
3430
|
resetExpression,
|
|
@@ -3533,7 +3751,7 @@ class CubismLegacyMotionManager extends MotionManager {
|
|
|
3533
3751
|
getSoundFile(definition) {
|
|
3534
3752
|
return definition.sound;
|
|
3535
3753
|
}
|
|
3536
|
-
_startMotion(motion, onFinish, ignoreParamIds) {
|
|
3754
|
+
_startMotion(motion, onFinish, ignoreParamIds, _loop) {
|
|
3537
3755
|
motion.onFinishHandler = onFinish;
|
|
3538
3756
|
if (ignoreParamIds && ignoreParamIds.length > 0) {
|
|
3539
3757
|
motion.motions = motion.motions.filter((item) => {
|
|
@@ -3702,7 +3920,7 @@ class CubismLegacyParallelMotionManager extends ParallelMotionManager {
|
|
|
3702
3920
|
getMotionName(definition) {
|
|
3703
3921
|
return definition.file;
|
|
3704
3922
|
}
|
|
3705
|
-
_startMotion(motion, onFinish, ignoreParamIds) {
|
|
3923
|
+
_startMotion(motion, onFinish, ignoreParamIds, _loop) {
|
|
3706
3924
|
motion.onFinishHandler = onFinish;
|
|
3707
3925
|
if (ignoreParamIds && ignoreParamIds.length > 0) {
|
|
3708
3926
|
motion.motions = motion.motions.filter((item) => {
|
|
@@ -3863,7 +4081,9 @@ class CubismLegacyInternalModel extends InternalModel {
|
|
|
3863
4081
|
}
|
|
3864
4082
|
this.motionManager = new CubismLegacyMotionManager(this);
|
|
3865
4083
|
this.parallelMotionManager = [];
|
|
3866
|
-
this.eyeBlink
|
|
4084
|
+
if (this.options.eyeBlink !== false) {
|
|
4085
|
+
this.eyeBlink = new Live2DEyeBlink(coreModel);
|
|
4086
|
+
}
|
|
3867
4087
|
this.eyeballXParamIndex = coreModel.getParamIndex("PARAM_EYE_BALL_X");
|
|
3868
4088
|
this.eyeballYParamIndex = coreModel.getParamIndex("PARAM_EYE_BALL_Y");
|
|
3869
4089
|
this.angleXParamIndex = coreModel.getParamIndex("PARAM_ANGLE_X");
|
|
@@ -9550,8 +9770,9 @@ class CubismMotionManager extends MotionManager {
|
|
|
9550
9770
|
isFinished() {
|
|
9551
9771
|
return this.queueManager.isFinished();
|
|
9552
9772
|
}
|
|
9553
|
-
_startMotion(motion, onFinish, ignoreParamIds) {
|
|
9773
|
+
_startMotion(motion, onFinish, ignoreParamIds, loop) {
|
|
9554
9774
|
motion.setFinishedMotionHandler(onFinish);
|
|
9775
|
+
motion.setLoop(loop != null ? loop : motion._motionData.loop);
|
|
9555
9776
|
if (ignoreParamIds && ignoreParamIds.length > 0) {
|
|
9556
9777
|
const curves = motion._motionData.curves;
|
|
9557
9778
|
const filtered = createCurveContainer$1(curves);
|
|
@@ -9585,6 +9806,7 @@ class CubismMotionManager extends MotionManager {
|
|
|
9585
9806
|
shouldCheckMotionConsistency
|
|
9586
9807
|
);
|
|
9587
9808
|
const json = new CubismMotionJson(data, data.byteLength);
|
|
9809
|
+
motion.setLoop(json.isMotionLoop());
|
|
9588
9810
|
const defaultFadingDuration = (group === this.groups.idle ? config.idleMotionFadingDuration : config.motionFadingDuration) / 1e3;
|
|
9589
9811
|
if (json.getMotionFadeInTime() === void 0) {
|
|
9590
9812
|
motion.setFadeInTime(
|
|
@@ -9693,8 +9915,9 @@ class CubismParallelMotionManager extends ParallelMotionManager {
|
|
|
9693
9915
|
isFinished() {
|
|
9694
9916
|
return this.queueManager.isFinished();
|
|
9695
9917
|
}
|
|
9696
|
-
_startMotion(motion, onFinish, ignoreParamIds) {
|
|
9918
|
+
_startMotion(motion, onFinish, ignoreParamIds, loop) {
|
|
9697
9919
|
motion.setFinishedMotionHandler(onFinish);
|
|
9920
|
+
motion.setLoop(loop != null ? loop : motion._motionData.loop);
|
|
9698
9921
|
if (ignoreParamIds && ignoreParamIds.length > 0) {
|
|
9699
9922
|
const curves = motion._motionData.curves;
|
|
9700
9923
|
const filtered = createCurveContainer(curves);
|
|
@@ -12154,6 +12377,30 @@ const HIGH_PRECISION_MASK_MAX_MASKS_PER_DRAWABLE_THRESHOLD = 3;
|
|
|
12154
12377
|
const HIGH_PRECISION_MASK_MASKED_VERTEX_THRESHOLD = 4096;
|
|
12155
12378
|
const HIGH_PRECISION_MASK_VERTEX_RATIO_THRESHOLD = 0.5;
|
|
12156
12379
|
const HIGH_PRECISION_MASK_VERTEX_RATIO_DRAWABLE_THRESHOLD = 24;
|
|
12380
|
+
const layoutKeyMap = {
|
|
12381
|
+
CenterX: "centerX",
|
|
12382
|
+
centerX: "centerX",
|
|
12383
|
+
center_x: "centerX",
|
|
12384
|
+
CenterY: "centerY",
|
|
12385
|
+
centerY: "centerY",
|
|
12386
|
+
center_y: "centerY",
|
|
12387
|
+
X: "x",
|
|
12388
|
+
x: "x",
|
|
12389
|
+
Y: "y",
|
|
12390
|
+
y: "y",
|
|
12391
|
+
Width: "width",
|
|
12392
|
+
width: "width",
|
|
12393
|
+
Height: "height",
|
|
12394
|
+
height: "height",
|
|
12395
|
+
Top: "top",
|
|
12396
|
+
top: "top",
|
|
12397
|
+
Bottom: "bottom",
|
|
12398
|
+
bottom: "bottom",
|
|
12399
|
+
Left: "left",
|
|
12400
|
+
left: "left",
|
|
12401
|
+
Right: "right",
|
|
12402
|
+
right: "right"
|
|
12403
|
+
};
|
|
12157
12404
|
function getRequiredMaskRenderTextureCount(model) {
|
|
12158
12405
|
var _a;
|
|
12159
12406
|
if (!model.isUsingMasking()) {
|
|
@@ -12274,7 +12521,7 @@ class CubismInternalModel extends InternalModel {
|
|
|
12274
12521
|
var _a;
|
|
12275
12522
|
super.init();
|
|
12276
12523
|
const eyeBlinkParameters = this.settings.getEyeBlinkParameters();
|
|
12277
|
-
if (eyeBlinkParameters.length) {
|
|
12524
|
+
if (this.options.eyeBlink !== false && eyeBlinkParameters.length) {
|
|
12278
12525
|
const parameterIds = new csmVector();
|
|
12279
12526
|
for (const parameter of eyeBlinkParameters) {
|
|
12280
12527
|
parameterIds.pushBack(this.idManager.getId(parameter));
|
|
@@ -12336,16 +12583,29 @@ class CubismInternalModel extends InternalModel {
|
|
|
12336
12583
|
const settingsLayout = this.settings.layout;
|
|
12337
12584
|
if (settingsLayout) {
|
|
12338
12585
|
for (const [key, value] of Object.entries(settingsLayout)) {
|
|
12339
|
-
const commonKey = key
|
|
12340
|
-
|
|
12586
|
+
const commonKey = layoutKeyMap[key];
|
|
12587
|
+
if (commonKey && typeof value === "number") {
|
|
12588
|
+
layout[commonKey] = value;
|
|
12589
|
+
}
|
|
12341
12590
|
}
|
|
12342
12591
|
}
|
|
12343
12592
|
return layout;
|
|
12344
12593
|
}
|
|
12345
12594
|
setupLayout() {
|
|
12346
|
-
|
|
12347
|
-
|
|
12348
|
-
|
|
12595
|
+
const self = this;
|
|
12596
|
+
const size = this.getSize();
|
|
12597
|
+
self.originalWidth = size[0];
|
|
12598
|
+
self.originalHeight = size[1];
|
|
12599
|
+
self.pixelsPerUnit = this.coreModel.getModel().canvasinfo.PixelsPerUnit;
|
|
12600
|
+
const bounds = setupCubismLayoutMatrix(
|
|
12601
|
+
this.localTransform,
|
|
12602
|
+
this.originalWidth,
|
|
12603
|
+
this.originalHeight,
|
|
12604
|
+
this.getLayout()
|
|
12605
|
+
);
|
|
12606
|
+
self.width = bounds.width;
|
|
12607
|
+
self.height = bounds.height;
|
|
12608
|
+
this.modelTransform.identity().scale(this.pixelsPerUnit, this.pixelsPerUnit).translate(this.originalWidth / 2, this.originalHeight / 2);
|
|
12349
12609
|
}
|
|
12350
12610
|
updateWebGLContext(gl, glContextID) {
|
|
12351
12611
|
this.renderer.firstDraw = true;
|
|
@@ -13277,18 +13537,26 @@ class CubismModelSettings extends ModelSettings {
|
|
|
13277
13537
|
parameters.push(id.getString().s);
|
|
13278
13538
|
}
|
|
13279
13539
|
}
|
|
13280
|
-
} else
|
|
13540
|
+
} else {
|
|
13541
|
+
let hasEyeBlinkGroup = false;
|
|
13281
13542
|
const groups = this.json.Groups;
|
|
13282
|
-
|
|
13283
|
-
|
|
13284
|
-
|
|
13285
|
-
|
|
13286
|
-
|
|
13287
|
-
|
|
13288
|
-
|
|
13543
|
+
if (Array.isArray(groups)) {
|
|
13544
|
+
for (const group of groups) {
|
|
13545
|
+
if ((group == null ? void 0 : group.Name) !== "EyeBlink") continue;
|
|
13546
|
+
hasEyeBlinkGroup = true;
|
|
13547
|
+
if (!Array.isArray(group.Ids)) continue;
|
|
13548
|
+
for (const entry of group.Ids) {
|
|
13549
|
+
if (typeof entry === "string") {
|
|
13550
|
+
parameters.push(entry);
|
|
13551
|
+
} else if (entry == null ? void 0 : entry.Id) {
|
|
13552
|
+
parameters.push(entry.Id);
|
|
13553
|
+
}
|
|
13289
13554
|
}
|
|
13290
13555
|
}
|
|
13291
13556
|
}
|
|
13557
|
+
if (hasEyeBlinkGroup) {
|
|
13558
|
+
return parameters;
|
|
13559
|
+
}
|
|
13292
13560
|
}
|
|
13293
13561
|
return parameters.length ? parameters : [...defaultEyeBlinkParameters];
|
|
13294
13562
|
}
|