Skip to content

Make Rapier instance available outside React/hooks #578

Open
@trepidacious

Description

@trepidacious

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions