Nphysics on the web - calling nphysics from JavaScript

Hi,

I have been writing a browser-based 3d game in TypeScript using Three JS as my rendering engine. I’ve been trying to settle on a physics solution for the game and came across nphysics, and it interests me very much as it can be compiled down to WASM.

I would like to initialize and call nphyiscs functions from my JavaScript code (as opposed to the examples where the client code is written purely in Rust). Would I need to write my own wrapper/bindings in Rust and expose via #[js_export] as explained in the stdweb README, or are all the nphysics functions exposed out of the box?

Do you see this as a viable approach? Any tips and pointers would be much appreciated!

Thanks

Hi!

I’ve never attempted this myself, but I believe you will need to write some Rust wrapper for the features you need and expose via #[js_export] as you suggest.

Also note you could use wasm-bindgen instead of stdweb (by enabling the use-wasm-bindgen feature of nphysics) and follow the wasm-bindgen doc.

But, yeah, in both cases you will likely need to write some wrappers to get something usable from the JS side.