microsoft / HoloJS

Provides a framework for creating holographic apps using JavaScript and WebGL.
MIT License
1.19k stars 114 forks source link

Camera's children are not visible anymore #87

Closed Reda-S closed 7 years ago

Reda-S commented 7 years ago

We had a "cursor" attached to the camera that was showing just fine until yesterday's master's merge. I think it's related to the frustum culling issue.

sjando commented 7 years ago

Is this using three.js? Could be getting culled if it's closer than the near plane. You could try overriding this behavior and see if it shows again:

cursor.frustumCulled = false;

Reda-S commented 7 years ago

Yes using three,.js, and setting frustumCulled to false was the first thing that I have tried, but it didn't work. The second thing that I have tried was moving the cursor over the z axes, assuming it was a problem of being outside the near and the far plane, no luck either, any other ideas?

sjando commented 7 years ago

I see what you mean. I think this is an issue with ANGLE, although they work with auto-stereo rendering the view/projection matrices it spits out aren't quite correct for calculations script-side (e.g. frustum culling, scene graph).

In the meantime a script-side workaround would be to create a duplicate THREE.Camera (or any other Object3D) and set it's position per frame as follows:

let matrix = new THREE.Matrix4().getInverse(new THREE.Matrix4().fromArray(window.getViewMatrix()).multiply(new THREE.Matrix4().makeScale(-1, 1, 1))); matrix.decompose(duplicate.position, duplicate.quaternion, duplicate.scale);

Use the main camera to render but add cursor and other children to this duplicate (and add the duplicate to the scene). Ideally you'd set the projection matrix on the duplicate and use it for frustum culling as well (but still not rendering). three.js isn't really set up to allow this though, so probably leave frustum culling off for now. Also use the duplicate for any raycasting calculations.

Almost-Done commented 7 years ago

Thank you @sjando for the fix. I merged the ANGLE fix and updated the submodule/binaries in HoloJS.

Is the proposed workaround still needed?

sjando commented 7 years ago

@Almost-Done nope, everything working as expected now based on my testing.

Reda-S commented 7 years ago

@sjando the culling is working fine and the camera children are showing as expected. Thanks.