dimforge / rapier.js

Official JavaScript bindings for the Rapier physics engine.
https://rapier.rs
Apache License 2.0
426 stars 58 forks source link

How to create world in worker ? #212

Open Amir8212Dv opened 1 year ago

Amir8212Dv commented 1 year ago

I wanna create world in other CPU threads, by using Worker. But for some reason creating a world in other threads throws error. You can see the code and error in this image :

error

Is there any way i can create a new world in other threads ?

LeXXik commented 1 year ago

You need to compile the Wasm module manually on the main thread, then send the compiled module to the web worker and instantiate it there. Another way would be to fetch the library from the worker directly, then compile and instantiate. This is not really Rapier related question, so I'd suggest to google how to instantiate a Wasm in web workers (with or without bundlers).