-
Notifications
You must be signed in to change notification settings - Fork 63
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
Does react-three-rapier support RN app? #383
Comments
The issue could be that WebAssembly isn't supported in React Native? I'm not familiar with it enough to know if that's the case though. |
From a brief search, it seems that React Native for ios and android doesn't support WASM out of the box. Some people have found workarounds though. Some people mention using webassemblyjs (though I can't imagine performance being good), and others say they mounted a webview in the RN app (webviews would support WASM). This was referenced: https://www.npmjs.com/package/react-native-react-bridge If you get something working, please share! 🙂 |
This also looks interesting - https://github.com/cawfree/react-native-webassembly |
iOS does not support JIT under the browser ban (WebKit has special permissions), but pending March 2024 EU legislation this can change. In the meantime, no such implementation exists for WebAssembly even for Android, but it should be possible if Apple cedes ground here. |
@lsxBread did you find a solution to make it work ? Or did you use something else ? |
I hit the same error quite recently. Does anyone have some tips/examples on how to use this package with React Native? |
I actually found a fix for this. This is what I did to make it work in if (Platform.OS !== 'web') {
// Polyfill WebAssembly for the Rapier physics engine
// https://github.com/pmndrs/react-three-rapier/issues/383
const WebAssembly = require('polywasm').WebAssembly;
globalThis.WebAssembly = WebAssembly;
} I couldn't believe it, but it actually worked 😄 |
@itsyoboieltr thanks for sharing 🙏 would you mind sharing a demo / video? I'm curious to see what the performance is like. |
The thing I am currently working on is not really computationally intense so I see no difference native vs browser. Do you have any ideas what/how should I benchmark? I can make a quick demo |
@itsyoboieltr I was firstly just curious whether a basic simulation with a few physics bodies runs ok. Hearing that you don't see a difference between browser and native for your scene is interesting! Looking at polywasm I see it works by translating wasm functions to javascript - which sounds like it would be very slow. For some potentially easy comparisons, you could grab the source code of some react-three-rapier examples, e.g.
|
I just tried it in a bare React Native project. The polyfill trick makes the app build, but when I try the basic usage code sample from the react-three /rapier GitHub I get errors. The basic usage code : import { Box, Torus } from "@react-three/drei";
import { Canvas } from "@react-three/fiber";
import { Physics, RigidBody, CuboidCollider } from "@react-three/rapier";
import React, { Suspense } from 'react'
const MyComponent = () => {
return (
<Canvas>
<Suspense>
<Physics debug>
<RigidBody colliders={"hull"} restitution={2}>
<Torus />
</RigidBody>
<CuboidCollider position={[0, -2, 0]} args={[20, 0.5, 20]} />
</Physics>
</Suspense>
</Canvas>
);
}; The errors :
What i'm using :
|
I generally wouldn't expect this to work or ever be performant. I too was pulling my hair out trying to get things to work with expo/rn but besides the 3d stuff the views were just UI and that works just as good in ionic with way less nightmares. |
Hi, I am trying to use this lib together with @react-three/fiber & @react-three/drei in the Expo project
"expo": "47.0.13"
"react-native": "0.70.5"
That's the demo in the docs I followed:
It works all good in browser but get below error when run it as the RN app in iOS:
Seems it doesn't expose an
native
module like fiber & drei does which could support RN. I don't really find any RN related stuff in the docs, so try to confirm that does rapier support RN app OR I miss some config to make it runnable?Thanks
The text was updated successfully, but these errors were encountered: