Birch-san / box2d-wasm

Box2D physics engine compiled to WebAssembly. Supports TypeScript and ES modules.
273 stars 21 forks source link

Is box2d wasm better than matterjs #45

Closed a6965921 closed 2 years ago

a6965921 commented 2 years ago

Is box2d wasm better than matterjs I use matterjs FPS is very low

Birch-san commented 2 years ago

I'm not familiar with matter.js, but:

https://github.com/liabru/matter-js/issues/608

the result is not good enough
There are many rect-boxes are overlap .

certainly, when I play with matter.js demos: it's very easy to make objects intersect. I think Box2D is more accurate.

as for performance: I expect box2d-wasm and box2d.js to be faster than matter.js, because of access to better memory-management techniques. box2d-wasm/box2d.js are written in C++; most of the work executes in WebAssembly/asm.js. objects allocated by the engine are not reference-counted; you don't incur garbage collection costs. moreover, they're allocated with a custom block allocator, which reduces memory fragmentation and keeps the heap small (reducing memory costs and improving locality of reference).

as for features: Box2D has more types of joints:
https://github.com/liabru/matter-js/issues/472

it sounds like matter.js approximates circles:
https://github.com/liabru/matter-js/issues/615

box2d-wasm's liquidfun-wasm release adds the fluid simulation and soft-body capabilities from Google liquidfun. demo here. liquidfun has very bespoke memory management, introducing a slab allocator and stack allocator too. I think it would handle large numbers of particles far better than matter.js.

box2d-wasm also provides comprehensive TypeScript typings. it looks like matter.js uses best-effort JSDoc typings, or types contributed separately via DefinitelyTyped.