ebeaufay / threedtiles

3DTiles viewer for three.js
MIT License
270 stars 32 forks source link

Flickering issue #21

Closed ebeaufay closed 1 year ago

ebeaufay commented 1 year ago

Flickering issue when using a false orthographic view where a perspective camera is used with a very small field of view and dynamic near-far planes

FOV 0.32°

   const distanceToCamera = intersection.distanceTo(camera.position);
      const far = distanceToCamera + 2000;

      const near = Math.max(0.1, distanceToCamera - 2000);
      state.camera.near = near;
      state.camera.far = far;
      state.camera.updateProjectionMatrix();
      console.log("near", near, "far", far);

the threejs view is overlayed on a mapBox canvas

https://youtu.be/wAx7-Fz4Fx0

ebeaufay commented 1 year ago

For future reference, the Frustum is calculated based on the camera's projectionMatrix and matrixWorldInverse

if you modify camera parameters, calling camera#updateProjectionMatrix is not sufficient because the matrixWorldInverse is not re-calculated.

you can either make sure that the OGC3DTile#update is called in the render loop, before the camera params are updated or you can re-calculate the camera's matrixWorldInverse manually when changing the camera parameters