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

Support for Rapier 2D #113

Open
Tracked by #92
verekia opened this issue Sep 29, 2022 · 4 comments
Open
Tracked by #92

Support for Rapier 2D #113

verekia opened this issue Sep 29, 2022 · 4 comments
Labels
question Further information is requested

Comments

@verekia
Copy link

verekia commented Sep 29, 2022

It would be nice to have an option to use Rapider 2D instead of 3D for applications that only need 2D physics, even if they use 3D graphics (think RTS, MOBA games, or 2D platformers with 3D graphics...). The WASM file is 1MB instead of 1.4MB. I suppose <Physics> would need some props to configure the axes to use, and to project onto.

@hmans
Copy link
Contributor

hmans commented Sep 29, 2022

Yes please!

Some important background information: Rapier itself explicitly publishes its 2D and 3D engines as separate packages. I would suggest that the same would need to happen for glue libraries like this one. @wiledal -- this is already a monorepo -- could a path forward for this involve setting up a separate @react-three/rapier2d package, as well as a @react-three/rapier-common package that includes all the common bits (API, world stepping, collision handling, etc)?

@verekia
Copy link
Author

verekia commented Sep 30, 2022

And while we're at it, if we're going to have multiple packages, would it make sense to also offer the WASM builds as an alternative to the -compat packages? That reduces the package size too, at the cost of more complicated setups / broken HMR.

For reference, with rapier 0.9.0 I'm getting these sizes on disk:
rapier2d (WASM): 1MB
rapier2d-compat (JS): 1.5MB
rapier3d (WASM): 1.4MB
rapier3d-compat (JS): 1.9MB

@wiledal wiledal added the question Further information is requested label Sep 30, 2022
@wiledal
Copy link
Member

wiledal commented Sep 30, 2022

I fear the effort required to pull this off would be quite immense. And if it's just to save 0.4MB, I personally don't see it as a big enough win?

You can easily lock one translation axis on your objects to obtain the effect of 2d physics, but of course you'd miss out on potential performance benefits. Then again, Rapier is pretty fast, so unless you're simulating thousands of objects, or targeting very slow machines, I'm not sure you'd notice a difference.

Regarding allowing the use of the WASM version, that would actually be preferred for sure since it's smaller, but during my initial prototyping I was unable to get that working at all and I never returned to it 😅

@hmans
Copy link
Contributor

hmans commented Sep 30, 2022

I think the WASM bundling topic should live in a separate issue, and we're not doing us any favors with mixing up the two here. @verekia, can you set one up please, and can we shift the discussion around it there?

Regarding the 2D support, I understand that it'd be difficult to retrofit this into the current codebase. I just want to note that 2D physics and 3D physics are entirely different domains (with different sets of collider shapes, etc.), which is one of the reasons why Rapier 2D and 3D themselves are separate packages. Approximating 2D physics by disabling translations/rotations will work for some games (I do it in my own game), but using 3D physics that way is not the same thing as 2D physics.

I think having a glue library for Rapier 2D would be great, and I think if both would come from the same source, offering the same APIs (like Rapier 2D and 3D both do, too), would be fantastic.

Having said that, this isn't critically important today, but if there is a chance that this will be considered at some point in the future, it would definitely get my vote (and involvement.) It would be hugely preferable to having an entirely separate project for Rapier 2D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants