Birch-san / box2d-wasm

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

Convex shapes are not supported #43

Closed a6965921 closed 2 years ago

a6965921 commented 2 years ago

Convex shapes are not supported

const square = new b2PolygonShape(); var vArray = [new b2Vec2(0,-20),new b2Vec2(25,0),new b2Vec2(15,30),new b2Vec2(-15,30),new b2Vec2(-25,0)] square.Set(vArray, 4);

ziriax commented 2 years ago

That is by design, Box2D doesn't support that for you. You have to decompose the concave polygon into convex ones yourself.

I'm not an expert, but a Google search reveals the following:

See https://github.com/erincatto/Box2D/issues/513

See also https://stackoverflow.com/questions/41515307/box2d-why-not-concave-shapes

See also http://masc.cs.gmu.edu/wiki/Box2d

Or search on NPM for convex decomposition

a6965921 commented 2 years ago

Looking forward to your writing a demo

Birch-san commented 2 years ago

@Ziriax has helped sufficiently already.

box2d-wasm is a bindings library, with no goal of adding functionality to Box2D (which is in any case closed to contributions).