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/dist/cubism.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 _csmVector = class _csmVector {
45
44
  /**
46
45
  * 引数付きコンストラクタ
@@ -2760,7 +2759,7 @@ const config = {
2760
2759
  preserveExpressionOnMotion: true,
2761
2760
  cubism: CubismFrameworkConfig
2762
2761
  };
2763
- const VERSION = "1.2.1";
2762
+ const VERSION = "1.3.0";
2764
2763
  const logger = {
2765
2764
  log(tag, ...messages) {
2766
2765
  if (config.logLevel <= config.LOG_LEVEL_VERBOSE) {
@@ -3479,7 +3478,64 @@ class MotionState {
3479
3478
  }
3480
3479
  const TAG$2 = "SoundManager";
3481
3480
  const VOLUME = 0.5;
3482
- sound.disableAutoPause = true;
3481
+ const SOUND_ALIAS_PREFIX = "live2d-sound-";
3482
+ let soundId = 0;
3483
+ let pixiSoundPromise;
3484
+ const configuredLibraries = /* @__PURE__ */ new WeakSet();
3485
+ function configureSoundLibrary(library) {
3486
+ if (!configuredLibraries.has(library)) {
3487
+ try {
3488
+ library.disableAutoPause = true;
3489
+ } catch (e) {
3490
+ logger.warn(TAG$2, "Failed to disable @pixi/sound auto pause.", e);
3491
+ }
3492
+ configuredLibraries.add(library);
3493
+ }
3494
+ return library;
3495
+ }
3496
+ function getGlobalSoundLibrary() {
3497
+ return typeof PIXI !== "undefined" ? PIXI == null ? void 0 : PIXI.sound : void 0;
3498
+ }
3499
+ function resolveSoundLibrary() {
3500
+ return __async(this, null, function* () {
3501
+ const globalLibrary = getGlobalSoundLibrary();
3502
+ if (globalLibrary) {
3503
+ return configureSoundLibrary(globalLibrary);
3504
+ }
3505
+ pixiSoundPromise != null ? pixiSoundPromise : pixiSoundPromise = import("@pixi/sound").then(({ sound }) => configureSoundLibrary(sound)).catch((e) => {
3506
+ logger.warn(
3507
+ TAG$2,
3508
+ "@pixi/sound is not available. Load pixi-sound.js before using motion sounds, speak(), or lip sync.",
3509
+ e
3510
+ );
3511
+ return null;
3512
+ });
3513
+ return pixiSoundPromise;
3514
+ });
3515
+ }
3516
+ function removeSound(library, alias) {
3517
+ try {
3518
+ library.remove(alias);
3519
+ } catch (e) {
3520
+ logger.warn(TAG$2, `Failed to remove sound "${alias}".`, e);
3521
+ }
3522
+ }
3523
+ function destroySound(audio) {
3524
+ try {
3525
+ audio.destroy();
3526
+ } catch (e) {
3527
+ logger.warn(TAG$2, "Failed to destroy audio.", e);
3528
+ }
3529
+ }
3530
+ function getAudioBuffer(audio) {
3531
+ const media = audio.media;
3532
+ const buffer = media.buffer;
3533
+ if (!buffer || typeof buffer !== "object") {
3534
+ return void 0;
3535
+ }
3536
+ const candidate = buffer;
3537
+ return typeof candidate.getChannelData === "function" ? buffer : void 0;
3538
+ }
3483
3539
  class SoundManager {
3484
3540
  /**
3485
3541
  * Global volume that applies to all the sounds.
@@ -3500,22 +3556,47 @@ class SoundManager {
3500
3556
  */
3501
3557
  static add(file, onError) {
3502
3558
  return __async(this, null, function* () {
3559
+ let library = null;
3560
+ let alias;
3503
3561
  try {
3562
+ library = yield resolveSoundLibrary();
3563
+ if (!library) {
3564
+ throw new Error("@pixi/sound is not available");
3565
+ }
3566
+ alias = `${SOUND_ALIAS_PREFIX}${soundId++}`;
3567
+ const soundLibrary = library;
3568
+ const soundAlias = alias;
3504
3569
  const task = new Promise((resolve, reject) => {
3505
- const audio = Sound.from({
3570
+ const audio2 = soundLibrary.add(soundAlias, {
3506
3571
  url: file,
3507
3572
  volume: this._volume,
3508
3573
  preload: true,
3509
- loaded: () => {
3510
- if (!(audio.media instanceof webaudio.WebAudioMedia)) {
3574
+ loaded: (error, loadedAudio) => {
3575
+ if (error) {
3576
+ reject(error);
3577
+ return;
3578
+ }
3579
+ const sound = loadedAudio != null ? loadedAudio : audio2;
3580
+ if (!sound) {
3581
+ reject(new Error(`Error: ${file} failed to load`));
3582
+ return;
3583
+ }
3584
+ if (!getAudioBuffer(sound)) {
3511
3585
  reject(new Error(`Error: ${file} is not WebAudioMedia`));
3586
+ return;
3512
3587
  }
3513
- resolve(audio);
3588
+ resolve(sound);
3514
3589
  }
3515
3590
  });
3516
3591
  });
3517
- return yield task;
3592
+ const audio = yield task;
3593
+ this.aliases.set(audio, { alias: soundAlias, library: soundLibrary });
3594
+ this.audios.push(audio);
3595
+ return audio;
3518
3596
  } catch (e) {
3597
+ if (library && alias) {
3598
+ removeSound(library, alias);
3599
+ }
3519
3600
  logger.warn(TAG$2, `Error occurred on "${file}"`, e);
3520
3601
  onError == null ? void 0 : onError(e);
3521
3602
  return null;
@@ -3532,14 +3613,18 @@ class SoundManager {
3532
3613
  singleInstance: true,
3533
3614
  complete: () => {
3534
3615
  onFinish == null ? void 0 : onFinish();
3535
- audio.destroy();
3616
+ this.dispose(audio);
3536
3617
  }
3537
3618
  });
3538
3619
  }
3539
3620
  static addAnalyzer(audio, context) {
3540
- const media = audio.media;
3621
+ const buffer = getAudioBuffer(audio);
3622
+ if (!buffer) {
3623
+ logger.warn(TAG$2, "Cannot create audio analyzer because WebAudio media is unavailable.");
3624
+ return void 0;
3625
+ }
3541
3626
  const source = context.createBufferSource();
3542
- source.buffer = media.buffer;
3627
+ source.buffer = buffer;
3543
3628
  const analyser = context.createAnalyser();
3544
3629
  analyser.fftSize = config.fftSize;
3545
3630
  analyser.minDecibels = -90;
@@ -3577,7 +3662,18 @@ class SoundManager {
3577
3662
  * @param audio - An audio element.
3578
3663
  */
3579
3664
  static dispose(audio) {
3580
- audio.pause();
3665
+ try {
3666
+ audio.pause();
3667
+ } catch (e) {
3668
+ logger.warn(TAG$2, "Failed to pause audio.", e);
3669
+ }
3670
+ const managedSound = this.aliases.get(audio);
3671
+ if (managedSound) {
3672
+ removeSound(managedSound.library, managedSound.alias);
3673
+ this.aliases.delete(audio);
3674
+ } else {
3675
+ destroySound(audio);
3676
+ }
3581
3677
  remove(this.audios, audio);
3582
3678
  }
3583
3679
  /**
@@ -3601,6 +3697,7 @@ class SoundManager {
3601
3697
  __publicField(SoundManager, "audios", []);
3602
3698
  __publicField(SoundManager, "analysers", []);
3603
3699
  __publicField(SoundManager, "contexts", []);
3700
+ __publicField(SoundManager, "aliases", /* @__PURE__ */ new WeakMap());
3604
3701
  __publicField(SoundManager, "_volume", VOLUME);
3605
3702
  var MotionPreloadStrategy = /* @__PURE__ */ ((MotionPreloadStrategy2) => {
3606
3703
  MotionPreloadStrategy2["ALL"] = "ALL";
@@ -3785,7 +3882,7 @@ class MotionManager extends EventEmitter {
3785
3882
  * @returns Promise that resolves with true if the sound is playing, false otherwise.
3786
3883
  */
3787
3884
  speak(_0) {
3788
- return __async(this, arguments, function* (sound2, {
3885
+ return __async(this, arguments, function* (sound, {
3789
3886
  volume = VOLUME,
3790
3887
  expression,
3791
3888
  resetExpression = true,
@@ -3802,16 +3899,16 @@ class MotionManager extends EventEmitter {
3802
3899
  }
3803
3900
  }
3804
3901
  let soundURL;
3805
- const isBase64Content = sound2 && sound2.startsWith("data:");
3806
- if (sound2 && !isBase64Content) {
3902
+ const isBase64Content = sound && sound.startsWith("data:");
3903
+ if (sound && !isBase64Content) {
3807
3904
  const A = document.createElement("a");
3808
- A.href = sound2;
3809
- sound2 = A.href;
3810
- soundURL = sound2;
3905
+ A.href = sound;
3906
+ sound = A.href;
3907
+ soundURL = sound;
3811
3908
  } else {
3812
3909
  soundURL = "data:audio/";
3813
3910
  }
3814
- const file = sound2;
3911
+ const file = sound;
3815
3912
  if (file) {
3816
3913
  try {
3817
3914
  audio = yield SoundManager.add(file, (e, that = this) => {
@@ -3822,6 +3919,9 @@ class MotionManager extends EventEmitter {
3822
3919
  }
3823
3920
  that.currentAudio = void 0;
3824
3921
  });
3922
+ if (!audio) {
3923
+ return false;
3924
+ }
3825
3925
  this.initializeAudio(audio, volume);
3826
3926
  } catch (e) {
3827
3927
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
@@ -3871,17 +3971,19 @@ class MotionManager extends EventEmitter {
3871
3971
  * @param onFinish - Callback when playback finishes.
3872
3972
  * @param onError - Callback when playback errors.
3873
3973
  * @param ignoreParamIds - The ids to be ignored.
3974
+ * @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
3874
3975
  * @return Promise that resolves with true if the motion is successfully started, false otherwise.
3875
3976
  */
3876
3977
  startMotion(_0, _1) {
3877
3978
  return __async(this, arguments, function* (group, index, priority = MotionPriority.NORMAL, {
3878
- sound: sound2 = void 0,
3979
+ sound = void 0,
3879
3980
  volume = VOLUME,
3880
3981
  expression = void 0,
3881
3982
  resetExpression = true,
3882
3983
  onFinish,
3883
3984
  onError,
3884
- ignoreParamIds = []
3985
+ ignoreParamIds = [],
3986
+ loop = void 0
3885
3987
  } = {}) {
3886
3988
  if (this.destroyed) {
3887
3989
  return false;
@@ -3903,12 +4005,12 @@ class MotionManager extends EventEmitter {
3903
4005
  }
3904
4006
  let audio;
3905
4007
  let soundURL;
3906
- const isBase64Content = sound2 && sound2.startsWith("data:");
3907
- if (sound2 && !isBase64Content) {
4008
+ const isBase64Content = sound && sound.startsWith("data:");
4009
+ if (sound && !isBase64Content) {
3908
4010
  const A = document.createElement("a");
3909
- A.href = sound2;
3910
- sound2 = A.href;
3911
- soundURL = sound2;
4011
+ A.href = sound;
4012
+ sound = A.href;
4013
+ soundURL = sound;
3912
4014
  } else {
3913
4015
  soundURL = this.getSoundFile(definition);
3914
4016
  if (soundURL) {
@@ -3926,7 +4028,9 @@ class MotionManager extends EventEmitter {
3926
4028
  }
3927
4029
  that.currentAudio = void 0;
3928
4030
  });
3929
- this.initializeAudio(audio, volume);
4031
+ if (audio) {
4032
+ this.initializeAudio(audio, volume);
4033
+ }
3930
4034
  } catch (e) {
3931
4035
  logger.warn(this.tag, "Failed to create audio", soundURL, e);
3932
4036
  }
@@ -3964,7 +4068,7 @@ class MotionManager extends EventEmitter {
3964
4068
  }
3965
4069
  this.playing = true;
3966
4070
  if (motion) {
3967
- this._startMotion(motion, void 0, ignoreParamIds);
4071
+ this._startMotion(motion, void 0, ignoreParamIds, loop);
3968
4072
  }
3969
4073
  return true;
3970
4074
  });
@@ -3980,16 +4084,18 @@ class MotionManager extends EventEmitter {
3980
4084
  * @param crossOrigin - Cross origin setting.
3981
4085
  * @param onFinish - Callback when playback finishes.
3982
4086
  * @param onError - Callback when playback errors.
4087
+ * @param loop - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
3983
4088
  * @return Promise that resolves with true if the motion is successfully started, false otherwise.
3984
4089
  */
3985
4090
  startRandomMotion(_0, _1) {
3986
4091
  return __async(this, arguments, function* (group, priority, {
3987
- sound: sound2,
4092
+ sound,
3988
4093
  volume = VOLUME,
3989
4094
  expression,
3990
4095
  resetExpression = true,
3991
4096
  onFinish,
3992
- onError
4097
+ onError,
4098
+ loop = void 0
3993
4099
  } = {}) {
3994
4100
  var _a, _b;
3995
4101
  if (this.destroyed) {
@@ -4007,12 +4113,13 @@ class MotionManager extends EventEmitter {
4007
4113
  if (availableIndices.length) {
4008
4114
  const index = availableIndices[Math.floor(Math.random() * availableIndices.length)];
4009
4115
  return this.startMotion(group, index, priority, {
4010
- sound: sound2,
4116
+ sound,
4011
4117
  volume,
4012
4118
  expression,
4013
4119
  resetExpression,
4014
4120
  onFinish,
4015
- onError
4121
+ onError,
4122
+ loop
4016
4123
  });
4017
4124
  }
4018
4125
  }
@@ -4131,6 +4238,118 @@ class MotionManager extends EventEmitter {
4131
4238
  return definition;
4132
4239
  }
4133
4240
  }
4241
+ function setScale(matrix, scale) {
4242
+ matrix.a = scale;
4243
+ matrix.b = 0;
4244
+ matrix.c = 0;
4245
+ matrix.d = scale;
4246
+ }
4247
+ function getLayoutEntries(rawLayout) {
4248
+ const entries = [];
4249
+ for (const [key, value] of Object.entries(rawLayout)) {
4250
+ if (typeof value !== "number") {
4251
+ continue;
4252
+ }
4253
+ entries.push([key, value]);
4254
+ }
4255
+ return entries;
4256
+ }
4257
+ function setupLayoutMatrix(matrix, originalWidth, originalHeight, rawLayout) {
4258
+ var _a, _b;
4259
+ const layout = __spreadValues({
4260
+ width: LOGICAL_WIDTH,
4261
+ height: LOGICAL_HEIGHT
4262
+ }, rawLayout);
4263
+ const layoutWidth = (_a = layout.width) != null ? _a : LOGICAL_WIDTH;
4264
+ const layoutHeight = (_b = layout.height) != null ? _b : LOGICAL_HEIGHT;
4265
+ matrix.identity();
4266
+ matrix.scale(layoutWidth / LOGICAL_WIDTH, layoutHeight / LOGICAL_HEIGHT);
4267
+ const width = originalWidth * matrix.a;
4268
+ const height = originalHeight * matrix.d;
4269
+ 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;
4270
+ 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;
4271
+ matrix.translate(width * offsetX, -height * offsetY);
4272
+ return {
4273
+ width,
4274
+ height
4275
+ };
4276
+ }
4277
+ function getCubismLayoutWidth(state, aspect) {
4278
+ return LOGICAL_HEIGHT * aspect * state.scale;
4279
+ }
4280
+ function getCubismLayoutHeight(state) {
4281
+ return LOGICAL_HEIGHT * state.scale;
4282
+ }
4283
+ function setCubismWidth(state, aspect, width) {
4284
+ state.scale = width / (LOGICAL_HEIGHT * aspect);
4285
+ }
4286
+ function setCubismHeight(state, height) {
4287
+ state.scale = height / LOGICAL_HEIGHT;
4288
+ }
4289
+ function setCubismX(state, x) {
4290
+ state.x = x;
4291
+ }
4292
+ function setCubismY(state, y) {
4293
+ state.y = y;
4294
+ }
4295
+ function centerCubismX(state, aspect, x) {
4296
+ setCubismX(state, x - getCubismLayoutWidth(state, aspect) / 2);
4297
+ }
4298
+ function centerCubismY(state, y) {
4299
+ setCubismY(state, y - getCubismLayoutHeight(state) / 2);
4300
+ }
4301
+ function rightCubism(state, aspect, x) {
4302
+ setCubismX(state, x - getCubismLayoutWidth(state, aspect));
4303
+ }
4304
+ function bottomCubism(state, y) {
4305
+ setCubismY(state, y - getCubismLayoutHeight(state));
4306
+ }
4307
+ function setupCubismLayoutMatrix(matrix, originalWidth, originalHeight, rawLayout) {
4308
+ if (originalWidth <= 0 || originalHeight <= 0) {
4309
+ matrix.identity();
4310
+ return { width: 0, height: 0 };
4311
+ }
4312
+ const entries = getLayoutEntries(rawLayout);
4313
+ const aspect = originalWidth / originalHeight;
4314
+ const state = { scale: 1, x: 0, y: 0 };
4315
+ for (const [key, value] of entries) {
4316
+ if (key === "width") {
4317
+ setCubismWidth(state, aspect, value);
4318
+ } else if (key === "height") {
4319
+ setCubismHeight(state, value);
4320
+ }
4321
+ }
4322
+ for (const [key, value] of entries) {
4323
+ if (key === "x") {
4324
+ setCubismX(state, value);
4325
+ } else if (key === "y") {
4326
+ setCubismY(state, value);
4327
+ } else if (key === "centerX") {
4328
+ centerCubismX(state, aspect, value);
4329
+ } else if (key === "centerY") {
4330
+ centerCubismY(state, value);
4331
+ } else if (key === "top") {
4332
+ setCubismY(state, value);
4333
+ } else if (key === "bottom") {
4334
+ bottomCubism(state, value);
4335
+ } else if (key === "left") {
4336
+ setCubismX(state, value);
4337
+ } else if (key === "right") {
4338
+ rightCubism(state, aspect, value);
4339
+ }
4340
+ }
4341
+ const pixelsPerLogicalUnit = originalHeight / LOGICAL_HEIGHT;
4342
+ const defaultLogicalHalfWidth = LOGICAL_HEIGHT * aspect / 2;
4343
+ const defaultLogicalHalfHeight = LOGICAL_HEIGHT / 2;
4344
+ matrix.identity();
4345
+ setScale(matrix, state.scale);
4346
+ matrix.tx = pixelsPerLogicalUnit * (state.x + defaultLogicalHalfWidth) - originalWidth * state.scale / 2;
4347
+ matrix.ty = pixelsPerLogicalUnit * (defaultLogicalHalfHeight - state.y) - originalHeight * state.scale / 2;
4348
+ return {
4349
+ width: originalWidth * state.scale,
4350
+ height: originalHeight * state.scale
4351
+ };
4352
+ }
4134
4353
  function normalizeHitAreaDefs(raw, resolveIndex) {
4135
4354
  if (!Array.isArray(raw)) {
4136
4355
  return [];
@@ -4220,19 +4439,14 @@ class InternalModel extends EventEmitter {
4220
4439
  const size = this.getSize();
4221
4440
  self.originalWidth = size[0];
4222
4441
  self.originalHeight = size[1];
4223
- const layout = Object.assign(
4224
- {
4225
- width: LOGICAL_WIDTH,
4226
- height: LOGICAL_HEIGHT
4227
- },
4442
+ const bounds = setupLayoutMatrix(
4443
+ this.localTransform,
4444
+ this.originalWidth,
4445
+ this.originalHeight,
4228
4446
  this.getLayout()
4229
4447
  );
4230
- this.localTransform.scale(layout.width / LOGICAL_WIDTH, layout.height / LOGICAL_HEIGHT);
4231
- self.width = this.originalWidth * this.localTransform.a;
4232
- self.height = this.originalHeight * this.localTransform.d;
4233
- 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;
4234
- 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;
4235
- this.localTransform.translate(this.width * offsetX, -this.height * offsetY);
4448
+ self.width = bounds.width;
4449
+ self.height = bounds.height;
4236
4450
  }
4237
4451
  /**
4238
4452
  * Sets up the hit areas by their definitions in settings.
@@ -5748,34 +5962,38 @@ class Live2DModel extends Container {
5748
5962
  * @param [options.resetExpression=true] - Reset the expression to default after the motion is finished.
5749
5963
  * @param [options.onFinish] - Callback function when speaking completes.
5750
5964
  * @param [options.onError] - Callback function when an error occurs.
5965
+ * @param [options.loop] - Whether the motion should loop. Overrides Cubism 3/4/5 motion JSON loop metadata when specified.
5751
5966
  * @return Promise that resolves with true if the motion is successfully started, with false otherwise.
5752
5967
  */
5753
5968
  motion(_0, _1, _2) {
5754
5969
  return __async(this, arguments, function* (group, index, priority, {
5755
- sound: sound2 = void 0,
5970
+ sound = void 0,
5756
5971
  volume = VOLUME,
5757
5972
  expression = void 0,
5758
5973
  resetExpression = true,
5759
5974
  onFinish,
5760
- onError
5975
+ onError,
5976
+ loop = void 0
5761
5977
  } = {}) {
5762
5978
  if (index === void 0) {
5763
5979
  return this.internalModel.motionManager.startRandomMotion(group, priority, {
5764
- sound: sound2,
5980
+ sound,
5765
5981
  volume,
5766
5982
  expression,
5767
5983
  resetExpression,
5768
5984
  onFinish,
5769
- onError
5985
+ onError,
5986
+ loop
5770
5987
  });
5771
5988
  } else {
5772
5989
  return this.internalModel.motionManager.startMotion(group, index, priority, {
5773
- sound: sound2,
5990
+ sound,
5774
5991
  volume,
5775
5992
  expression,
5776
5993
  resetExpression,
5777
5994
  onFinish,
5778
- onError
5995
+ onError,
5996
+ loop
5779
5997
  });
5780
5998
  }
5781
5999
  });
@@ -5853,14 +6071,14 @@ class Live2DModel extends Container {
5853
6071
  * @param [options.onError] - Callback function when an error occurs.
5854
6072
  * @returns Promise that resolves with true if the sound is playing, false if it's not.
5855
6073
  */
5856
- speak(sound2, {
6074
+ speak(sound, {
5857
6075
  volume = VOLUME,
5858
6076
  expression,
5859
6077
  resetExpression = true,
5860
6078
  onFinish,
5861
6079
  onError
5862
6080
  } = {}) {
5863
- return this.internalModel.motionManager.speak(sound2, {
6081
+ return this.internalModel.motionManager.speak(sound, {
5864
6082
  volume,
5865
6083
  expression,
5866
6084
  resetExpression,
@@ -8634,8 +8852,9 @@ class CubismMotionManager extends MotionManager {
8634
8852
  isFinished() {
8635
8853
  return this.queueManager.isFinished();
8636
8854
  }
8637
- _startMotion(motion, onFinish, ignoreParamIds) {
8855
+ _startMotion(motion, onFinish, ignoreParamIds, loop) {
8638
8856
  motion.setFinishedMotionHandler(onFinish);
8857
+ motion.setLoop(loop != null ? loop : motion._motionData.loop);
8639
8858
  if (ignoreParamIds && ignoreParamIds.length > 0) {
8640
8859
  const curves = motion._motionData.curves;
8641
8860
  const filtered = createCurveContainer$1(curves);
@@ -8669,6 +8888,7 @@ class CubismMotionManager extends MotionManager {
8669
8888
  shouldCheckMotionConsistency
8670
8889
  );
8671
8890
  const json = new CubismMotionJson(data, data.byteLength);
8891
+ motion.setLoop(json.isMotionLoop());
8672
8892
  const defaultFadingDuration = (group === this.groups.idle ? config.idleMotionFadingDuration : config.motionFadingDuration) / 1e3;
8673
8893
  if (json.getMotionFadeInTime() === void 0) {
8674
8894
  motion.setFadeInTime(
@@ -8896,8 +9116,9 @@ class CubismParallelMotionManager extends ParallelMotionManager {
8896
9116
  isFinished() {
8897
9117
  return this.queueManager.isFinished();
8898
9118
  }
8899
- _startMotion(motion, onFinish, ignoreParamIds) {
9119
+ _startMotion(motion, onFinish, ignoreParamIds, loop) {
8900
9120
  motion.setFinishedMotionHandler(onFinish);
9121
+ motion.setLoop(loop != null ? loop : motion._motionData.loop);
8901
9122
  if (ignoreParamIds && ignoreParamIds.length > 0) {
8902
9123
  const curves = motion._motionData.curves;
8903
9124
  const filtered = createCurveContainer(curves);
@@ -11357,6 +11578,30 @@ const HIGH_PRECISION_MASK_MAX_MASKS_PER_DRAWABLE_THRESHOLD = 3;
11357
11578
  const HIGH_PRECISION_MASK_MASKED_VERTEX_THRESHOLD = 4096;
11358
11579
  const HIGH_PRECISION_MASK_VERTEX_RATIO_THRESHOLD = 0.5;
11359
11580
  const HIGH_PRECISION_MASK_VERTEX_RATIO_DRAWABLE_THRESHOLD = 24;
11581
+ const layoutKeyMap = {
11582
+ CenterX: "centerX",
11583
+ centerX: "centerX",
11584
+ center_x: "centerX",
11585
+ CenterY: "centerY",
11586
+ centerY: "centerY",
11587
+ center_y: "centerY",
11588
+ X: "x",
11589
+ x: "x",
11590
+ Y: "y",
11591
+ y: "y",
11592
+ Width: "width",
11593
+ width: "width",
11594
+ Height: "height",
11595
+ height: "height",
11596
+ Top: "top",
11597
+ top: "top",
11598
+ Bottom: "bottom",
11599
+ bottom: "bottom",
11600
+ Left: "left",
11601
+ left: "left",
11602
+ Right: "right",
11603
+ right: "right"
11604
+ };
11360
11605
  function getRequiredMaskRenderTextureCount(model) {
11361
11606
  var _a;
11362
11607
  if (!model.isUsingMasking()) {
@@ -11477,7 +11722,7 @@ class CubismInternalModel extends InternalModel {
11477
11722
  var _a;
11478
11723
  super.init();
11479
11724
  const eyeBlinkParameters = this.settings.getEyeBlinkParameters();
11480
- if (eyeBlinkParameters.length) {
11725
+ if (this.options.eyeBlink !== false && eyeBlinkParameters.length) {
11481
11726
  const parameterIds = new csmVector();
11482
11727
  for (const parameter of eyeBlinkParameters) {
11483
11728
  parameterIds.pushBack(this.idManager.getId(parameter));
@@ -11539,16 +11784,29 @@ class CubismInternalModel extends InternalModel {
11539
11784
  const settingsLayout = this.settings.layout;
11540
11785
  if (settingsLayout) {
11541
11786
  for (const [key, value] of Object.entries(settingsLayout)) {
11542
- const commonKey = key.charAt(0).toLowerCase() + key.slice(1);
11543
- layout[commonKey] = value;
11787
+ const commonKey = layoutKeyMap[key];
11788
+ if (commonKey && typeof value === "number") {
11789
+ layout[commonKey] = value;
11790
+ }
11544
11791
  }
11545
11792
  }
11546
11793
  return layout;
11547
11794
  }
11548
11795
  setupLayout() {
11549
- super.setupLayout();
11550
- this.pixelsPerUnit = this.coreModel.getModel().canvasinfo.PixelsPerUnit;
11551
- this.modelTransform.scale(this.pixelsPerUnit, this.pixelsPerUnit).translate(this.originalWidth / 2, this.originalHeight / 2);
11796
+ const self = this;
11797
+ const size = this.getSize();
11798
+ self.originalWidth = size[0];
11799
+ self.originalHeight = size[1];
11800
+ self.pixelsPerUnit = this.coreModel.getModel().canvasinfo.PixelsPerUnit;
11801
+ const bounds = setupCubismLayoutMatrix(
11802
+ this.localTransform,
11803
+ this.originalWidth,
11804
+ this.originalHeight,
11805
+ this.getLayout()
11806
+ );
11807
+ self.width = bounds.width;
11808
+ self.height = bounds.height;
11809
+ this.modelTransform.identity().scale(this.pixelsPerUnit, this.pixelsPerUnit).translate(this.originalWidth / 2, this.originalHeight / 2);
11552
11810
  }
11553
11811
  updateWebGLContext(gl, glContextID) {
11554
11812
  this.renderer.firstDraw = true;
@@ -12480,18 +12738,26 @@ class CubismModelSettings extends ModelSettings {
12480
12738
  parameters.push(id.getString().s);
12481
12739
  }
12482
12740
  }
12483
- } else if (Array.isArray(this.json.Groups)) {
12741
+ } else {
12742
+ let hasEyeBlinkGroup = false;
12484
12743
  const groups = this.json.Groups;
12485
- for (const group of groups) {
12486
- if ((group == null ? void 0 : group.Name) !== "EyeBlink" || !Array.isArray(group.Ids)) continue;
12487
- for (const entry of group.Ids) {
12488
- if (typeof entry === "string") {
12489
- parameters.push(entry);
12490
- } else if (entry == null ? void 0 : entry.Id) {
12491
- parameters.push(entry.Id);
12744
+ if (Array.isArray(groups)) {
12745
+ for (const group of groups) {
12746
+ if ((group == null ? void 0 : group.Name) !== "EyeBlink") continue;
12747
+ hasEyeBlinkGroup = true;
12748
+ if (!Array.isArray(group.Ids)) continue;
12749
+ for (const entry of group.Ids) {
12750
+ if (typeof entry === "string") {
12751
+ parameters.push(entry);
12752
+ } else if (entry == null ? void 0 : entry.Id) {
12753
+ parameters.push(entry.Id);
12754
+ }
12492
12755
  }
12493
12756
  }
12494
12757
  }
12758
+ if (hasEyeBlinkGroup) {
12759
+ return parameters;
12760
+ }
12495
12761
  }
12496
12762
  return parameters.length ? parameters : [...defaultEyeBlinkParameters];
12497
12763
  }