Repository: moeru-ai/airi
File: packages/stage-ui/src/components/Scenes/Live2D/Model.vue (Vue)

Code before:
        fileName: motion.File,
      }))
    }).filter(Boolean)

    // Remove eye ball movements from idle motion group to prevent conflicts
    // This is too hacky
    // FIXME: it cannot blink if loading a model only have idle motion
    if (motionManager.groups.idle) {
      motionManager.motionGroups[motionManager.groups.idle]?.forEach((motion) => {
        motion._motionData.curves.forEach((curve: any) => {
        // TODO: After emotion mapper, stage editor, eye related parameters should be take cared to be dynamical instead of hardcoding
          if (curve.id === 'ParamEyeBallX' || curve.id === 'ParamEyeBallY') {
            curve.id = `_${curve.id}`
          }
        })
      })
    }

    // This is hacky too
    const hookedUpdate = motionManager.update as (model: CubismModel, now: number) => boolean
    motionManager.update = function (model: CubismModel, now: number) {
      lastUpdateTime.value = now

      hookedUpdate?.call(this, model, now)
      // Possibility 1: Only update eye focus when the model is idle
      // Possibility 2: For models having no motion groups, currentGroup will be undefined while groups can be { idle: ... }
      if (!motionManager.state.currentGroup || motionManager.state.currentGroup === motionManager.groups.idle) {
        idleEyeFocus.update(internalModel, now)

        // If the model has eye blink parameters
        if (internalModel.eyeBlink != null) {
        // For the part of the auto eye blink implementation in pixi-live2d-display
        //
        // this.emit("beforeMotionUpdate");
        // const motionUpdated = this.motionManager.update(this.coreModel, now);
        // this.emit("afterMotionUpdate");
        // model.saveParameters();
        // this.motionManager.expressionManager?.update(model, now);
        // if (!motionUpdated) {
        //   this.eyeBlink?.updateParameters(model, dt);
        // }
        //
        // https://github.com/guansss/pixi-live2d-display/blob/31317b37d5e22955a44d5b11f37f421e94a11269/src/cubism4/Cubism4InternalModel.ts#L202-L214
        //
        // If the this.motionManager.update returns true, as motion updated flag on,
        // the eye blink parameters will not be updated, in another hand, the auto eye blink is disabled
        //
        // Since we are hooking the motionManager.update method currently,
        // and previously a always `true` was returned, eye blink parameters were never updated.
        //
        // Thous we are here to manually update the eye blink parameters within this hooked method

Review comment (suggestion):
```suggestion
      // Possibility 2: For models having no motion groups, currentGroup will be undefined while groups can be { idle: ... }
```

Code after:
        fileName: motion.File,
      }))
    }).filter(Boolean)

    // Remove eye ball movements from idle motion group to prevent conflicts
    // This is too hacky
    // FIXME: it cannot blink if loading a model only have idle motion
    if (motionManager.groups.idle) {
      motionManager.motionGroups[motionManager.groups.idle]?.forEach((motion) => {
        motion._motionData.curves.forEach((curve: any) => {
        // TODO: After emotion mapper, stage editor, eye related parameters should be take cared to be dynamical instead of hardcoding
          if (curve.id === 'ParamEyeBallX' || curve.id === 'ParamEyeBallY') {
            curve.id = `_${curve.id}`
          }
        })
      })
    }

    // This is hacky too
    const hookedUpdate = motionManager.update as (model: CubismModel, now: number) => boolean
    motionManager.update = function (model: CubismModel, now: number) {
      lastUpdateTime.value = now

      hookedUpdate?.call(this, model, now)
      // Possibility 1: Only update eye focus when the model is idle
      // Possibility 2: For models having no mo`ti`on groups, currentGroup will be undefined while groups can be { idle: ... }
      if (!motionManager.state.currentGroup || motionManager.state.currentGroup === motionManager.groups.idle) {
        idleEyeFocus.update(internalModel, now)

        // If the model has eye blink parameters
        if (internalModel.eyeBlink != null) {
        // For the part of the auto eye blink implementation in pixi-live2d-display
        //
        // this.emit("beforeMotionUpdate");
        // const motionUpdated = this.motionManager.update(this.coreModel, now);
        // this.emit("afterMotionUpdate");
        // model.saveParameters();
        // this.motionManager.expressionManager?.update(model, now);
        // if (!motionUpdated) {
        //   this.eyeBlink?.updateParameters(model, dt);
        // }
        //
        // https://github.com/guansss/pixi-live2d-display/blob/31317b37d5e22955a44d5b11f37f421e94a11269/src/cubism4/Cubism4InternalModel.ts#L202-L214
        //
        // If the this.motionManager.update returns true, as motion updated flag on,
        // the eye blink parameters will not be updated, in another hand, the auto eye blink is disabled
        //
        // Since we are hooking the motionManager.update method currently,
        // and previously a always `true` was returned, eye blink parameters were never updated.
        //
        // Thous we are here to manually update the eye blink parameters within this hooked method