Editing physics shapes with ease

Hi,

I created a PhysicsEditor which is currently in beta state. It’s currently available for MacOS - Windows version will come soon.

Features:

  • Automated tracing

  • Direct output to corona

  • Full physics editing

  • 2 lines of code to add a shape

How to use:

Load definition file created with PhysicsEditor

local physicsData = (require "shapedefs").physicsData()  

Add body definition to the shape:

physics.addBody(obj, physicsData:get("myshape"))  

That’s all.

Here is the complete
example source code

Have fun trying it

Cheers
Andreas Löw

(author of TexturePacker)
[import]uid: 9611 topic_id: 6327 reply_id: 306327[/import]

Damn. I can’t edit the post. The field to select the forum is not available…

Here is the corrected link:

PhysicsEditor.de

[import]uid: 9611 topic_id: 6327 reply_id: 21853[/import]

good work, thanks! [import]uid: 6645 topic_id: 6327 reply_id: 21937[/import]

Looks very promising!

Nice to see direct support for Corona from the start too. [import]uid: 7356 topic_id: 6327 reply_id: 21942[/import]

looks handy, thanks [import]uid: 12108 topic_id: 6327 reply_id: 21956[/import]

Looks great. Would be good if we could add joints etc and build complex physics objects.

Hopefully this feature is on the todo list.

good work. [import]uid: 31718 topic_id: 6327 reply_id: 22073[/import]

I have already planned some kind of ragdoll editor. But this is step 2 :wink:

Currently I work on smaller improvements and collect needs and wishes from users. I also work on the windows release for it… [import]uid: 9611 topic_id: 6327 reply_id: 22124[/import]

See it in action right now:

http://www.youtube.com/watch?v=EZT1lrxVut4
[import]uid: 9611 topic_id: 6327 reply_id: 22802[/import]

Nice one - that is brilliant! [import]uid: 8271 topic_id: 6327 reply_id: 22905[/import]

As a happy TexturePacker owner I would probably buy this just for the auto-generation of complex body physics shapes. There’s one problem though, caused ironically by the fact that I use TexturePacker!

Basically, I create all my physics body images at 2X size for retina and then use TexturePacker to automatically create 2x and 1X spritesheets. But the “native” resolution of my app in Corona is standard 1X, so the shapes generated by PhysicsEditor are all 2X too big. I don’t have 1X images that aren’t embedded in a spritesheet, so for me to use PE and get the right size shapes I have to dig up the original 2X art and scale it down to 1X, and import THAT into PE to do the shape detection.

Ideally, I’d like a button or field somewhere in PE to allow me to scale the resulting shapes by whatever I want (in my case 50%).

[import]uid: 9422 topic_id: 6327 reply_id: 23108[/import]

Thanks so much was looking for this, will definitely make my game more accurate. [import]uid: 11465 topic_id: 6327 reply_id: 23123[/import]

@XenonBL: Right.

I can simply fix this. But scaling the shapes might change the physics behavior. I corona’s case this is a bit of a problem so.

I changed the exporter. Please copy the following data to your
/Applications/PhysicsEditor/Contents/Resources/exporters/corona folder.

They add a scaling factor you can use when requiring the file.

It also add the IsSensor feature to single polygons.

I just fixed it in the text editor and had not yet time to test it.
Please give me feedback if that works for you.

corona.lua:
[lua]-- This file is for use with Corona Game Edition

– This file is automatically generated with PhysicsEdtior (http://www.physicseditor.de). Do not edit

– Usage example:
– local scaleFactor = 1.0
– local physicsData = (require “shapedefs”).physicsData(scaleFactor)
– local shape = display.newImage(“objectname.png”)
– physics.addBody( shape, physicsData:get(“objectname”) )

– copy unpack to local scope
local unpack = unpack

module(…)

function physicsData(s)
local physics = { data =
{ {% for body in bodies %}
{% if not forloop.first %}, {% endif %}
["{{body.name}}"] = {
{% for fixture in body.fixtures %}{% for polygon in fixture.polygons %}{% if not forloop.first %} ,{% endif %}
{
density = {{fixture.density}}, friction = {{fixture.friction}}, bounce = {{fixture.bounce}}, {% if fixture.isSensor %}isSensor=true, {% endif %}
filter = { categoryBits = {{fixture.filter_categoryBits}}, maskBits = {{fixture.filter_maskBits}} },
shape = { {% for point in polygon %} {% if not forloop.first %}, {% endif %} {{point.x*s}}, {{point.y*s}} {% endfor %} }
} {% endfor %} {% endfor %}
}
{% endfor %}
} }

function physics:get(name)
return unpack(self.data[name])
end

return physics;
end[/lua]

exporter.xml

\<exporter\> \<name\>corona-box2d\</name\> \<displayName\>Corona\</displayName\> \<description\>Exporter for Corona TM SDK, lua\</description\> \<version\>1.0\</version\> \<yAxisDirection\>down\</yAxisDirection\> \<physicsEngine\>box2d\</physicsEngine\> \<template\>corona.lua\</template\> \<fileExtension\>lua\</fileExtension\> \<anchorPoint\> \<enabled\>no\</enabled\> \</anchorPoint\> \<origin\> \<type\>fixed\</type\> \<relX\>0.5\</relX\> \<relY\>0.5\</relY\> \</origin\> \<body\> \</body\> \<global\> \</global\> \<body\> \</body\> \<fixture\> \<parameter\> \<name\>density\</name\> \<displayName\>Density\</displayName\> \<type\>float\</type\> \<min\>-1000\</min\> \<max\>1000\</max\> \<default\>2.0\</default\> \</parameter\> \<parameter\> \<name\>bounce\</name\> \<displayName\>Bounce\</displayName\> \<type\>float\</type\> \<min\>0\</min\> \<max\>1000\</max\> \<default\>0.0\</default\> \</parameter\> \<parameter\> \<name\>friction\</name\> \<displayName\>Friction\</displayName\> \<type\>float\</type\> \<min\>0\</min\> \<max\>1000\</max\> \<default\>0.0\</default\> \</parameter\> \<parameter\> \<name\>isSensor\</name\> \<displayName\>Is Sensor\</displayName\> \<description\>If set the physial \</description\> \<type\>bool\</type\> \<default\>false\</default\> \</parameter\> \</fixture\> \</exporter\> [import]uid: 9611 topic_id: 6327 reply_id: 23150[/import]

I updated those two files and got an error message popup when I tried to export the data:

Failed to write /…lua: Could not parse the remainder, *s from point.x*s, line 26, corona.lua, line 26, corona.lua, line 22, corona.lua, line 22, corona.lua, line 19, corona.lua
Also, just to be clear, due to the way my game works I’m not able to use the output lua file PE generates directly. I copy and paste the data from the shapes generated by PE into my own format. So if I understand correctly what you are doing with the scale factor I don’t think that will help in my particular case. I need the shape coordinates data itself to be the correct scale already. [import]uid: 9422 topic_id: 6327 reply_id: 23160[/import]

Sorry that it did not work. As I said - I was not yet able to test it.

What you can learn from the example above is that you can write you own expired with the exact file format that you need! You can create a custom exporter folder and set it in the preferences. In this you creae a folder mycorona and toss the files exporter.xml and the lua temlate.
Rename the exporter so it does not collide with the original corona exporter.

I’ll add scaling in the evening (about 10h). [import]uid: 9611 topic_id: 6327 reply_id: 23165[/import]

Sorry for the delay… I’ll get the new version running on weekend.

This will also add a windows version and direct import if sprites from TexturePacker.
I’ll also contain several improvements (mirror + rotate) and bug fixes…

I also added a bundle: TexturePacker + PhysicsEditor with a discount.

:wink: [import]uid: 9611 topic_id: 6327 reply_id: 23573[/import]

@yellowbanner: Would it not be better to contact physics editor’s support?
What do you think Andreas could do if you don’t even tell him your real name or order number???

He usually responds quite fast to emails. [import]uid: 39112 topic_id: 6327 reply_id: 23616[/import]

Edit to my post.

I got the key. It was mixed up in my inbox. Very good tool. [import]uid: 12455 topic_id: 6327 reply_id: 23613[/import]

Sorry to check so late. What was the problem? Seems to be solved :wink:
If you get problems with the order just write me a direct mail.
[import]uid: 9611 topic_id: 6327 reply_id: 23694[/import]

I uploaded a beta version for windows.
It looks fine on my test computer but I can’t test with corona on windows.

Please report any problems you encounter!

http://www.physicseditor.de/download/

[import]uid: 9611 topic_id: 6327 reply_id: 23738[/import]

Hi Andreas,

Great work!
I have just started trying out PhysicsEditor, and it looks like it will be a very useful tool.

I’ve found a couple of bugs:

  • When publishing for complex shapes, a comma is sometimes missing between some of the sub-bodies’ data in a complex body’s data.

  • When performing a “Delete point”, often an adjacent point is deleted instead. This happens in both the Windows and Mac versions. [import]uid: 35852 topic_id: 6327 reply_id: 23766[/import]