pmndrs/p2-es

Web workers

Closed this issue · 1 comments

You told in a different repo that you have made webworkers possible.

How did you make that possible? Do you have a link to the code?

I'm especially curious on how you'd solve the communication overhead

Hey @issy123, this repo has a very simple web workers example demonstrating how a transferable ArrayBuffer can be used to help with communication overhead.

https://pmndrs.github.io/p2-es/examples/canvas/worker
https://github.com/pmndrs/p2-es/blob/master/examples/canvas/worker.html

Also check out use-p2 and use-cannon. These are packages that are used with @react-three/fiber that run p2/cannon in a web worker.

These could both for sure have some improvements made around worker communication overhead, but they're very useable for scenes with less going on. These packages also use ArrayBuffers to help with overhead from transferring positions and angles/rotations on each frame. A more ideal implementation might make heavier use of SharedArrayBuffers?