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

Inaccurate viewport sizes within in a scene rendered using RenderTexture material #2077

Open
thismarioperez opened this issue Aug 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@thismarioperez
Copy link

  • three version: 0.167.1
  • @react-three/fiber version: 8.17.5
  • @react-three/drei version: 9.111.3
  • node version: 20 LTS
  • npm (or yarn) version: yarn 1.22.22

Problem description:

This bug concerns using a mesh that displays an image as a texture on a plane geometry, and is scaled using the useAspect hook. The mesh is composed as part of a scene that is rendered within a RenderTexture material. On first render, things look fine, but if you attach camera controls to the top level scene, zoom out with the mouse wheel, then resize the screen, the custom mesh scale suddenly jumps up in size. It's my understanding that the useAspect hook should use the camera within the nested scene to calculate viewport sizes. Investigating the useAspect hook, I found that it’s internally using the useThree hook to access the current viewport sizes and make calculations accordingly. Logging out the viewport sizes from within the mesh component shows that the sizes drastically jump up while resizing the window.

Relevant code:

Codepen demonstrating the bug

Zoom out with the scroll wheel, then resize the preview window, and read the console. You should see that the logged viewport sizes drastically jump up. Additionally, you should notice the mesh will visually scale up outside of the bounds of the current screen.

6c3233fa0c58c012390156f67f81a4c34bec0d00

Suggested solution:

Correct me if I'm wrong, but I thought that the useAspect and viewport sizes should use the camera in the RenderTexture scene to calculate values.

@thismarioperez thismarioperez added the bug Something isn't working label Aug 28, 2024
@thismarioperez
Copy link
Author

Additional video demonstrating the unexpected behavior

Screen.Recording.2024-08-28.at.1.10.38.PM.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant