Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bestsamcn opened this issue Jul 3, 2024 · 1 comment
Open

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

bestsamcn opened this issue Jul 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@bestsamcn
Copy link

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 bestsamcn added the bug Something isn't working label Jul 3, 2024
@bestsamcn bestsamcn changed the title [BUG]: [BUG]: InstancedMesh实例姿态显示错误 Jul 3, 2024
@orillusion-admin
Copy link
Contributor

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

感谢提出的问题!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants