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

Object3D.getWorld*() with cameras do not work when WebXR is presenting. #18448

Closed
omgitsraven opened this issue Jan 21, 2020 · 2 comments · Fixed by #19085
Closed

Object3D.getWorld*() with cameras do not work when WebXR is presenting. #18448

omgitsraven opened this issue Jan 21, 2020 · 2 comments · Fixed by #19085
Labels

Comments

@omgitsraven
Copy link
Contributor

Description of the problem

If an object has an onBeforeRender function which calls getWorldPosition on the camera argument, and the user is in VR, then that object (and any rendered after it) will stick to the user's face, as though the VR camera jumped to the origin mid-render.

Example: https://ravenworks.ca/temp/threeOBRcamerabug/

Three.js version

r112 (and some earlier, though I'm not sure exactly where it broke; this used to work in 2017, but it doesn't now.)

Browser

my demo only runs in Chrome because of Three dropping WebVR support, but the same bug happens in Firefox if using A-Frame (that's how I discovered the bug)

OS

only tried on Windows 10

Hardware Requirements (graphics card, VR Device, ...)

Oculus Rift

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 22, 2020

There is an unfortunate dependency when using Object3D.getWorldPosition() in this context. This method enforces a recomputation of the local and world matrices which will produce a wrong result since these matrices are actually set by WebXRManager. Since position, rotation and scale are not set (they are in fact out-of-sync), a recomputation produces wrong results (um, I'm having a déjà vu here).

You can avoid this problem by doing this in your onBeforeRender() callback:

cameraWorldPosition.setFromMatrixPosition( camera.matrixWorld );

or by setting camera.matrixAutoUpdate to false in your app. However, if you do this, you have to manually call Object3D.updateMatrix() by yourself whenever you transform the camera via position, rotation and scale.

Besides, avoid to create an instance of Vector3 every time onBeforeRender() is executed. Declare cameraWorldPosition once and reuse it.

@omgitsraven
Copy link
Contributor Author

Ahh, thank you for the workaround!

(And yeah, I just put that Vector3 there so the demo would be as brief as possible…)

@Mugen87 Mugen87 changed the title using getWorldPosition on camera inside onBeforeRender during VR breaks rendering Object3d.getWorld*() methods do not work when WebXR is presenting. Jan 23, 2020
@Mugen87 Mugen87 changed the title Object3d.getWorld*() methods do not work when WebXR is presenting. Object3d.getWorld*( camera ) do not work when WebXR is presenting. Jan 23, 2020
@Mugen87 Mugen87 changed the title Object3d.getWorld*( camera ) do not work when WebXR is presenting. Object3D.getWorld*( camera ) do not work when WebXR is presenting. Jan 23, 2020
@Mugen87 Mugen87 changed the title Object3D.getWorld*( camera ) do not work when WebXR is presenting. Object3D.getWorld*() with cameras do not work when WebXR is presenting. Jan 23, 2020
@Mugen87 Mugen87 added the Bug label Feb 24, 2020
KallynGowdy added a commit to KallynGowdy/casualos that referenced this issue Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants