-
Notifications
You must be signed in to change notification settings - Fork 55
Jsfl scripts and polygon decomposition
There are several .jsfl files provded with this project:
- Decompose Polygon.jsfl
- Clear Outline.jsfl
- Set Component Property.jsfl
- Trace Edges.jsfl
“Decompose Polygon” will extract vertex information from shapes drawn within Flash and decompose those shapes into covex polygons that can be used with Box2d.
Usage:
- See Adobe’s instructions for installing JSFL scripts
- Draw a shape within Flash, preferably with a tool that creates straight edges (the Pen Tool, for example).
- Select your entire shape.
- Run the “Polygon Decomposition” command.
- The decomposition will be printed to the output panel. Copy this for use in code.
- Run the “Clear Outline” command to clear the outline from the stage.
This is an example of what the script will generate in the output panel:
selection length: 1 selected element[object Shape] element type: shape ARRAY STRUCTURE: [polygons][verticies][x,y] [[[0, -80], [10.5, -24], [-29, -14.75], [-60, -60]], [[10.5, -24], [80, -20], [0, 20], [-60, 0], [-29, -14.75]], [[-40, 100], [-60, 0], [0, 20]], [[60, 80], [0, 20], [80, -20]]]
The vertices can then be fed into a shape definition function. For example, this code (within a BodyShape instance) will create the shape on the timeline:
shape(polys, [[[0, -80], [10.5, -24], [-29, -14.75], [-60, -60]], [[10.5, -24], [80, -20], [0, 20], [-60, 0], [-29, -14.75]], [[-40, 100], [-60, 0], [0, 20]], [[60, 80], [0, 20], [80, -20]]])
Other scripts:
“Trace Edges” will output the points raw, with no decomposition. Useful for creating edge chains that do not need to be decomposed.
“Component Property” is for setting a property on multiple components at the same time. With several components selected, running the script will prompt you for the property name and value.