Jsfl scripts and polygon decomposition

jesses edited this page Nov 8, 2011 · 1 revision

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:

  1. See Adobe’s instructions for installing JSFL scripts
  2. Draw a shape within Flash, preferably with a tool that creates straight edges (the Pen Tool, for example).
  3. Select your entire shape.
  4. Run the “Polygon Decomposition” command.
  5. The decomposition will be printed to the output panel. Copy this for use in code.
  6. 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.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.