pmndrs / drei

🥉 useful helpers for react-three-fiber
https://docs.pmnd.rs/drei
MIT License
8.27k stars 682 forks source link

Bug, with fix: Preload component #1950

Open JustinWomack opened 4 months ago

JustinWomack commented 4 months ago

Problem description:

Preload component uses a cube camera to render the scene in a useLayoutEffect in an attempt to increase performance as objects enter the frustum. This can interfere with existing cameras, and also does not eliminate choppiness as these objects are uploaded to the video card.

Relevant code:

Here is the code before, line 28:

 // Now compile the scene
  gl.compile(scene || dScene, camera || dCamera)
  // And for good measure, hit it with a cube camera
  const cubeRenderTarget = new WebGLCubeRenderTarget(128)
  const cubeCamera = new CubeCamera(0.01, 100000, cubeRenderTarget)
  cubeCamera.update(gl, (scene || dScene) as Scene)
  cubeRenderTarget.dispose()
  // Flips these objects back

Suggested solution:

  // Now compile the scene
  gl.render(scene || dScene, camera || dCamera)