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

Make Rapier instance available outside React/hooks #578

Open
trepidacious opened this issue Dec 17, 2023 · 1 comment
Open

Make Rapier instance available outside React/hooks #578

trepidacious opened this issue Dec 17, 2023 · 1 comment
Labels
enhancement New feature or request v2

Comments

@trepidacious
Copy link

It would be useful to be able to use the "raw" instance of the imported RAPIER library outside React (i.e. not within a Physics context, without use of hooks). My specific use case is to pre-run a simulation of dice rolling so I can play it back in react-three-fiber with meshes rotated to guarantee landing with a pre-determined face upwards). It seems much easier to do this as a plain function rather than dragging in Canvas etc. when I don't want to display anything during the pre-run.

Looking at this rapier PR, it seems to be critical to only call RAPIER.init() once. My understanding is this will already be done by react-three-rapier if it has been used, however I don't think I can rely on this in my case, since my code may run before react-three-rapier is used.

Would it be possible to use a similar system to the code in the rapier PR to make a rapierInit() method available to call from wherever it's needed? This would return a promise, completing immediately if rapier is already inited. Then this could be called from react-three-fiber instead of directly initing rapier, but also from any other code that wants to use it?

If the PR was merged in rapier this would obviously then be unnecessary, but it looks like it's not likely to be.

@wiledal wiledal added enhancement New feature or request v2 labels Jan 5, 2024
@wiledal
Copy link
Member

wiledal commented Jan 5, 2024

I've been thinking about a v2 where the rapier instance is completely controlled by the user initializing the instance.

<Physics rapier={yourRapierInstance}>
  ...
</Physics>

This would also solve usage of the non-compat version of Rapier, since the user will provide the library themselves!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2
Projects
None yet
Development

No branches or pull requests

2 participants