orillusion icon indicating copy to clipboard operation
orillusion copied to clipboard

[BUG]: InstancedMesh实例姿态显示错误

Open bestsamcn opened this issue 1 year ago • 1 comments

Bug描述

InstancedMesh.setMatrixAt 实例网格中实例姿态数据设置无法生效

Bug复现流程

通过以下步骤产生bug:

以下代码导致bug产生

orillusion\src\core\entities\InstancedMesh.ts

public setMatrixAt(index: number, matrix: Matrix4): this {
      let instance = this._instanceList[index];
      let prs: Vector3[] = matrix.decompose(Orientation3D.QUATERNION);
      let transform = instance.transform;

      //localRotQuat经过copy后,已经存在最新的x,y,z,w值
      transform.localRotQuat.copyFrom(prs[1]);

      //触发setter,但因x,y,z,w全等,导致Transform._localRot无法设置,最终旋转姿态错误(原始姿态)
      transform.localRotQuat = transform.localRotQuat;

      transform.localPosition.copyFrom(prs[0]);
      transform.localPosition = transform.localPosition;

      transform.localScale.copyFrom(prs[2]);
      transform.localScale = transform.localScale;
      return this;
  }

orillusion\src\components\Transform.ts

public set localRotQuat(value: Quaternion) {

    //此处为全等,返回false,无法进入代码块
    if (value.x != this._localRotQuat.x
        || value.y != this._localRotQuat.y
        || value.z != this._localRotQuat.z
        || value.w != this._localRotQuat.w) {
        this._localRotQuat.copyFrom(value);
        this._localRotQuat.getEulerAngles(this._localRot);

        WasmMatrix.setRotation(this.index, this._localRot.x, this._localRot.y, this._localRot.z);
        this.notifyLocalChange();
        this.onRotationChange?.();

        if (this.eventRotationChange) {
            this.eventDispatcher.dispatchEvent(this.eventRotationChange);
        }
    }
}

期待的结果

实例姿态正确

报错截图

错误: 错误

正确: 正确

测试引擎版本:

本地运行出错的Orillusion引擎版本0.7.2

本机系统 (请填写完整):

  • OS: win
  • Browser: chrome
  • Version: 113

本机配置

  • CPU: Intel I7 12700
  • Graphics Card: 3080ti

代码示例

其他信息

bestsamcn avatar Jul 03 '24 12:07 bestsamcn

我们会修复下setMatrixAt这个API,在下个版本会尝试修复这个问题~

感谢提出的问题!

orillusion-admin avatar Jul 16 '24 13:07 orillusion-admin