pmndrs / drei

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

Grid - Follow Camera does not work anymore when the grid rotation is changed #1366

Open TeoAvignon opened 1 year ago

TeoAvignon commented 1 year ago

Problem description:

When adding a rotation value in the grid props, the followCamera props is not working the same as when rotation is not defined.

Relevant code:

Here is the codesandbox of the reproduction based on your demo for the grid

Suggested solution:

the following line should take into account the orientation applied:

https://github.com/pmndrs/drei/blob/589b10422d37a0af5387b0479d52cf79771d9ee7/src/core/Grid.tsx#L69

For instance, when a rotation of : new Euler(Math.PI / 2, 0, 0); is applied, the current behavior would work with the following:


     pos.z -= (cameraPosition.y * followCamera);```

A first implementation could be to have the possibility to chose the grid direction between 'xy','xz' or 'yz'.
A second implementation could alow any rotation.

It could be done by using a uniform that store the current grid rotation.
STINGNAILS commented 1 year ago

PR1527 should fix exactly this