In short this library can easily create Box2D shapes of any complexity from render targets and attach them to Box2D bodies. Or you can use it for image tracing and path2d contours, each function is standalone. It also supports contour simplifying/loading/saving. Example included, enjoy!
Contour API:
◘ Contour.trace(render, [alpha])
creates contour from render by detecting pixels with matched alpha
'render' is RenderTarget instance
'alpha' is minimal alpha value to detect contour, 0..255, [default: 128]
returns contour as list of points where each point is in {x, y} format
◘ Contour.clean(contour, [dist])
reduces number of contour points by removing close ones
'contour' is list of points where each point is in {x, y} format
'dist' is maximal distance to detect redundant points, 0.., [default: 1]
returns cleaned contour
◘ Contour.shape(contour, [size])
converts contour into convex shapes suitable for Box2D
'contour' is list of points where each point is in {x, y} format
'size' is maximal number of shape vertices, 3..8, [default: 8]
returns list of shapes where each shape is list of {x, y} points
◘ Contour.apply(body, shapes, fixdef)
applies shapes and Box2D fixture definition to Box2D body
'body' is Box2D body
'shapes' list of shapes where each shape is list of {x, y} points
'fixdef' is fixture definition table (see b2.Body.createFixture)
returns nil since it modifies Box2D body
◘ Contour.path(contour)
creates svg path from contour to use with Path2D.setSvgPath
'contour' is list of points where each point is in {x, y} format
returns string
◘ Contour.save(contour, filename)
saves contour to file with json format
'contour' is list of points where each point is in {x, y} format
'filename' is full filename
returns nil since it performs file write operation
◘ Contour.load(filename)
loads contour from file with json format
'filename' is full filename
returns contour as list of points where each point is in {x, y} format
◘ Contour.print(contour|shapes)
prints contour or shapes in json format
returns nil
Download:
https://github.com/Nlcke/contour/archive/master.zip
Comments
◘ create something like Labyrinth game for Android
◘ http://giderosmobile.com/forum/discussion/589/polygon-decomposition-example
◘ make complex levels for platformers
◘ create outline effects for GUI elements
◘ let user draw an image on render target and then 'make it real'
◘ ???????
◘ PROFIT!
Likes: antix, MoKaLux