Convert PhysicsEditor bodies, or other sets of vectors, to Codea bodies/set of vec2 objects

I thought I might share this super simple script I made that lets you convert anything into a Codea body or vec2 object. Here’s what you do:

  1. Generate your code:
    • PhysicsEditor: Create your body, make sure the anchor is in the middle of the body, export the code in plain text, and copy the sets of numbers under “Hull polygon”.
    • Anything else: You can use anything that has sets of numbers, separated by anything, as long as there is an even amount. Simply copy that set of numbers.
  2. Go to my script here:
  3. Run the script
  4. Paste the set of numbers
  5. Select your scale - There are some things you can do with this option. I like my objects in UV coordinates, or at a certain size, so simply leave the field blank if you want it the size defined in the numbers, or put a number for the size you want the object to be, so for UV coordinates, put 1.
  6. Copy the code - Simply select all the vec2s that the console returned (without the quotes), and paste that wherever you like.
    So, for example, here’s what I’ve done with my app:

    I hope this can help you a bit with your physics apps.
    P.S. I have been able to achieve making physics bodies from SVGs, as long as there isn’t any curves.
    P.P.S. Feel free to fool with the script to suit your needs. If you do, I’d love it if you shared it here.

Updated code to fix some decimal bugs.

Very nice! BTW, it looks like one of your cows ate a crowbar, lol. :stuck_out_tongue:

@Slashin8r - Thanks. My new StackIt version will be full of Easter eggs. It also gets better… Let’s see: Space Invader eating a plank, etc.

Where is “PhysicsEditor” located?

@aciolino -
Btw, you don’t have to use Physics Editor

You know, I recall seeing this thing before a few months ago. It’s a neat idea, tracing the outline of 2D images for a physics body.

I wrote code to create vectors for an image

@aciolino, @Ignatz - To clarify, Ignatz code is for inputing an image and generating a set of points from it. My code is much simpler, yet more flexible for using 3rd party tools. My code will filter out all the numbers in a string and, if there is an even number, put them in vec2s. This allows you to use any tool to create shapes, wether it’s a vector drawing tool, PhysicsEditor app, or anything else.