Convert outline to component shapes

Hi, does anyone have a routine to convert a polygon (as perhaps generated by the graphics.newOutline() function) into smaller shapes (such that might be passed into the physics.addBody function’s shape parameter)?

Thanks,

Matt

Hi Matt,

This module from the Corona Code Exchange works brilliantly for me. It basically converts any polygon (including one with concave bends) into Box2D-compatible multi-element shapes.

http://code.coronalabs.com/code/create-complex-non-convex-bodies

Brent

I regularly get an error:
“An error has occured in the creation of the non-convex body shape”
I realise this is because my outline is not great but it is good enough to produce a usable polygon. Also, the library appears to have a size or length check for extremely large values and I think it is this which is throwing it off. No idea why.
Do you know what the caveats are with the use of the library? I’m thinking maybe the number of points needs to divide by 3 or something?

Hi Matt,

What is outputting the error, the 3rd-party library or Corona? I don’t know in-depth how the library works and what restrictions it may have, except that it has not failed me in usage so far. Then again, I don’t push it to the extreme with any more than (say) 8 elements to any physics body.

Brent

Hi Matt,

This module from the Corona Code Exchange works brilliantly for me. It basically converts any polygon (including one with concave bends) into Box2D-compatible multi-element shapes.

http://code.coronalabs.com/code/create-complex-non-convex-bodies

Brent

I regularly get an error:
“An error has occured in the creation of the non-convex body shape”
I realise this is because my outline is not great but it is good enough to produce a usable polygon. Also, the library appears to have a size or length check for extremely large values and I think it is this which is throwing it off. No idea why.
Do you know what the caveats are with the use of the library? I’m thinking maybe the number of points needs to divide by 3 or something?

Hi Matt,

What is outputting the error, the 3rd-party library or Corona? I don’t know in-depth how the library works and what restrictions it may have, except that it has not failed me in usage so far. Then again, I don’t push it to the extreme with any more than (say) 8 elements to any physics body.

Brent