pmndrs / react-three-jolt

⚡ Jolt physics in React
https://react-three-jolt.pmnd.rs/
MIT License
95 stars 5 forks source link

Raw Global, remove or rename? #35

Open DennisSmolek opened 7 months ago

DennisSmolek commented 7 months ago

Because of Suspense/Async initiation issues with Jolt @isaac-mason's original library created a global object called Raw and accessing it was done with Raw.module

The jolt demos don't have to do this because they wait for the JoltInit promise before doing anything, and by then Jolt is correctly established on the Window as a global. So instead of new Raw.module.Vec3() for example, they do new Jolt.Vec3()

  1. I'm not even sure it's possible to do the Jolt item as a global. I've not seen other libraries pull this off.
  2. With recent physics component system issues, we are likely going to need a global object we can access for singleton purposes.

If we decide to/have to keep it, should we continue to call it 'Raw.module` or would a semantic name be better?

isaac-mason commented 7 months ago

I wouldn't call the Raw object we have a "global" in the same sense as the window.Jolt global in the jolt demos.

The Raw object we currently have would maybe be better described as an exported "singleton" object.

For context - earlier the jolt build didn't use emscripten MODULARIZE, emscripten set window.Jolt. When we swapped to MODULARIZE, to avoid changing all the demos I added back an assignment to window.Jolt 😄

Assigning to window / globalThis in a demo is fine, but it's not a good idea to do this in a library.

isaac-mason commented 7 months ago

Maybe a better name could be JoltModule or something?

But as discussed on discord - there's other ways we could pass around the jolt emscripten module. They would require a bit of refactoring though.

DennisSmolek commented 7 months ago

Maybe a better name could be JoltModule or something?

I think I like this better than Raw

But as discussed on discord - there's other ways we could pass around the jolt emscripten module. They would require a bit of refactoring though.

The problem with that is it breaks all utility functions. Any function that touches Jolt would need to be passed the Jolt interface. All functions would have to become methods of a class.

So we'd init everything like PhysicsSystem.utils = new Utils(JoltWasm) or whatever. then call utils.vec3.three(position)