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

[gizmo] fix camera LH/RH coord + fix instanced meshes update #8844

Merged
merged 4 commits into from
Sep 1, 2020
Merged

[gizmo] fix camera LH/RH coord + fix instanced meshes update #8844

merged 4 commits into from
Sep 1, 2020

Conversation

CedricGuillemet
Copy link
Contributor

fixes #8784 and this issue : https://forum.babylonjs.com/t/attaching-a-gizmo-to-a-camera-with-userighthandedsystem/13532
For instanced meshes, simple check in the update matrix code.
for LH/RH:
camera worldMatrix is computed as the inverse of the viewMatrix. So, when doing a loop with gizmos (worldmatrix editing-> viewMatrix computation -> worldMatrix as the inverse), a rotation on the Y axis happens each frame giving a nice flipping effect.
Now, when decomposing translation/scaling/rotation, I compute rotation on the Y axis as if the continuity of the worldmatrix is preserved.
Also fixed the camera gizmo display mesh that didn't take RightHand coordinates into account.

fix instanced meshes update with gizmo
Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! just added a small suggestion

}

if (camera.getScene().useRightHandedSystem) {
// avoid desync with RH matrix computation. Otherwise, rotation of PI around Y axis happens each frame resulting in axis flipped because worldMatrix is computed as inverse of viewMatrix.
Matrix.RotationY(Math.PI).multiplyToRef(worldMatrix, this._tempMatrix2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will create a new matrix on each frame. You can use the Temp matrix classes to calculate rotation to ref, or actually store a read-only class member with this rotation already set and reuse it whenever needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea! Thanks!

src/Gizmos/gizmo.ts Outdated Show resolved Hide resolved
@deltakosh deltakosh merged commit 985622f into BabylonJS:master Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using Gizmos With Instanced Mesh
4 participants