@charivo/render-live2d 0.2.6 → 0.2.7

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/renderer.js CHANGED
@@ -13599,7 +13599,39 @@ var LAppWavFileHandler = class {
13599
13599
  }
13600
13600
  };
13601
13601
 
13602
+ // src/cubism/pose-restore.ts
13603
+ var PoseRestore = class {
13604
+ constructor(durationSeconds) {
13605
+ this.durationSeconds = durationSeconds;
13606
+ }
13607
+ start = null;
13608
+ elapsedSeconds = 0;
13609
+ /** Forget the captured pose so the next {@link step} re-captures the current one. */
13610
+ reset() {
13611
+ this.start = null;
13612
+ }
13613
+ /** Advance the ease by `deltaSeconds` and write the interpolated values to `model`. */
13614
+ step(model, deltaSeconds) {
13615
+ const count = model.getParameterCount();
13616
+ if (!this.start || this.start.length !== count) {
13617
+ this.start = new Float32Array(count);
13618
+ for (let i = 0; i < count; i++) {
13619
+ this.start[i] = model.getParameterValueByIndex(i);
13620
+ }
13621
+ this.elapsedSeconds = 0;
13622
+ }
13623
+ this.elapsedSeconds += deltaSeconds;
13624
+ const t = this.durationSeconds > 0 ? Math.min(1, this.elapsedSeconds / this.durationSeconds) : 1;
13625
+ for (let i = 0; i < count; i++) {
13626
+ const start = this.start[i];
13627
+ const def = model.getParameterDefaultValue(i);
13628
+ model.setParameterValueByIndex(i, start + (def - start) * t);
13629
+ }
13630
+ }
13631
+ };
13632
+
13602
13633
  // src/cubism/lappmodel.ts
13634
+ var IDLE_RESTORE_SECONDS = 0.5;
13603
13635
  var LAppModel = class extends CubismUserModel {
13604
13636
  modelSetting = null;
13605
13637
  modelHomeDir = "";
@@ -13611,6 +13643,9 @@ var LAppModel = class extends CubismUserModel {
13611
13643
  ready = false;
13612
13644
  wavHandler = new LAppWavFileHandler();
13613
13645
  _userTimeSeconds = 0;
13646
+ // Eases parameters back to their defaults when a finished motion has no "Idle"
13647
+ // group to take over, so a one-shot gesture does not leave a residual pose.
13648
+ _poseRestore = new PoseRestore(IDLE_RESTORE_SECONDS);
13614
13649
  realtimeLipSyncRms = 0;
13615
13650
  useRealtimeLipSync = false;
13616
13651
  idParamAngleX = CubismFramework.getIdManager().getId(
@@ -13692,15 +13727,21 @@ var LAppModel = class extends CubismUserModel {
13692
13727
  let motionUpdated = false;
13693
13728
  this._model.loadParameters();
13694
13729
  if (this._motionManager.isFinished()) {
13695
- this.startRandomMotion(
13730
+ const idleHandle = this.startRandomMotion(
13696
13731
  MotionGroupIdle,
13697
13732
  PriorityIdle
13698
13733
  );
13734
+ if (idleHandle === InvalidMotionQueueEntryHandleValue) {
13735
+ this._poseRestore.step(this._model, deltaTimeSeconds);
13736
+ } else {
13737
+ this._poseRestore.reset();
13738
+ }
13699
13739
  } else {
13700
13740
  motionUpdated = this._motionManager.updateMotion(
13701
13741
  this._model,
13702
13742
  deltaTimeSeconds
13703
13743
  );
13744
+ this._poseRestore.reset();
13704
13745
  }
13705
13746
  this._model.saveParameters();
13706
13747
  if (!motionUpdated && this._eyeBlink) {