[tool] Physics Body Editor *NEW 2.9.1*

Any community contributions to libgdx go here! Some may get included in the core API when permission is granted.

[tool] Physics Body Editor *NEW 2.9.1*

Postby Obli » Tue Jul 12, 2011 6:13 pm


I wrote an application that lets you easily create complex collision shapes by hand.
I made it because I needed such tool to quickly build some complex bodies for my games.

  • Automatically decomposes concave shapes into convex polygons,
  • Automatically traces your images if needed,
  • Supports multiple outlines for a single body,
  • Supports polygon and circle shapes,
  • Reference point location can be changed,
  • Visual configurable grid with snap-to-grid option,
  • Built-in collision tester! Throw balls at your body to test it,
  • Loader provided for LibGDX game framework,
  • Simple export format (JSON), to let you create your own loader for any framework in any language.

Q: Why should I use it ?
A: Because you cannot use concave polygons in the Box2D engine, and thus you need to infer multiple convex polygons from your shape to make it work. Want to do this in your head?

About the loader: I made a loader implementation for LibGDX, it is shipped within the application zip file. It reads your saved files and create all the fixtures for your bodies from them. However, feel free to implement your own loader if you need.

Download link

Project page: http://code.google.com/p/box2d-editor/
The project features downloads for the editor, the libgdx implementation of FixtureAtlas and an executable demo of the FixtureAtlas utilization.

Help and tutorials

There is a complete manual with tutorials, videos and code snippets to help you with everything:
http://www.aurelienribon.com/blog/proje ... dy-editor/





In-game usage of the shapes:
Last edited by Obli on Fri Apr 27, 2012 10:30 am, edited 11 times in total.
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [beta] Box2D Editor + FixtureAtlas

Postby Obli » Tue Jul 12, 2011 6:16 pm

Of course, since it's a beta test, I would love to hear about all the crashes, breaks, halts or anything that happens, with a guide to reproduce the error. Thanks !
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [beta] Box2D Editor + FixtureAtlas

Postby AnotherOne1 » Tue Jul 12, 2011 6:50 pm

Awesome addition! I've been getting quite sick of writing script files for vertices by hand :D

Now that you've written FixtureAtlas maybe someone will expand it to work with this:

I know someone was looking for it a while ago on here...
Posts: 35
Joined: Mon Jul 11, 2011 4:48 pm

Re: [beta] Box2D Editor + FixtureAtlas

Postby geno » Tue Jul 12, 2011 7:29 pm

I toyed a bit around with your editor and everything worked flawlessly so far.
This is really awesome! :D
Posts: 7
Joined: Mon Jun 27, 2011 10:06 pm

Re: [beta] Box2D Editor + FixtureAtlas

Postby Obli » Fri Jul 15, 2011 12:21 pm

Thanks for the enthusiastic words :)

I'll soon make an update to include the following features:

  • Add an auto-trace option to outline an image, based on its alpha channel (I found a nice article about it).
  • (easy) Add support for CW polygons. For now, the tools only supports CCW polygons.
  • (easy) Manage convex polygons with more than 8 vertices by splitting them, since the box2d engine does not support them.

Once done, and if I don't get error reports, the tool will be included in the libgdx extension branch (if mario validates).
Stay tuned ;)
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [beta] Box2D Editor + FixtureAtlas

Postby Obli » Wed Jul 20, 2011 2:57 pm

New MAJOR update !

+ Added multi-shape support. A body can be composed of detached parts.
+ Added shittons of help buttons
+ Generated convex polygons with more than 8 vertices are now supported
+ Shapes can now be defined both clockwise and counterclockwise

Screenshot (click to enlarge):

Multi-shape support gave me some headaches, but it should be fully supported.
I don't think I'll implement contour auto-tracing before the 1.0 release.

Note: previous exported files are no more compatible with the new editor and the new FixtureAtlas (yeah, that's why it's beta). However, I promise I won't break the compatibility again !

If no one find bugs, and if Mario agree, I'll release it with its source code as revision 1.0 in the libgdx contribution branch.

Download links are the same as before:
Box2D Editor [beta]: http://goo.gl/eCTSo
Box2D FixtureAtlas [beta]: http://goo.gl/IEnxz
Box2D FixtureAtlas test executable: http://goo.gl/Pqq6s
Box2D FixtureAtlas test apk: http://goo.gl/P1c0O
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [beta] Box2D Editor + FixtureAtlas

Postby daniel.weck » Wed Jul 20, 2011 9:19 pm

Obli wrote:I don't think I'll implement contour auto-tracing before the 1.0 release.

Salut Aurelien,

feel free to use this code (I use it to generate my Box2D "sprites" the first time my Android app launches, further launches fetch the cached data for outlines and associated tessallated polygons):



Cheers, Dan
Posts: 57
Joined: Mon Mar 21, 2011 8:18 am

Re: [beta] Box2D Editor + FixtureAtlas

Postby Obli » Thu Jul 21, 2011 5:01 am

Awesome ! That will be incredible additions ! Thanks a ton.
I discovered the Farseer project in the meantime, and they have other terrific tools, like a clipper with union, intersection and difference of polygons. Might add that support too maybe.
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France

Re: [beta] Box2D Editor + FixtureAtlas

Postby sparrow » Sun Jul 24, 2011 6:47 am

Really like this, at least conceptually :-). I get the following exception when I run
Exception in thread "LWJGL Canvas" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.reflect.InvocationTargetException
at com.badlogic.gdx.backends.lwjgl.LwjglCanvas$3.run(LwjglCanvas.java:171)
Caused by: java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1042)
at com.badlogic.gdx.backends.lwjgl.LwjglCanvas$3.run(LwjglCanvas.java:169)
Caused by: java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
at java.awt.EventQueue.invokeAndWait(EventQueue.java:1025)
at org.lwjgl.opengl.LinuxDisplay.edtSetCanvasFocus(LinuxDisplay.java:915)
at org.lwjgl.opengl.LinuxDisplay.setFocused(LinuxDisplay.java:905)
at org.lwjgl.opengl.LinuxDisplay.processEvents(LinuxDisplay.java:762)
at org.lwjgl.opengl.LinuxDisplay.update(LinuxDisplay.java:797)
at org.lwjgl.opengl.Display.processMessages(Display.java:634)
at org.lwjgl.opengl.Display.update(Display.java:692)
at org.lwjgl.opengl.Display.update(Display.java:662)
at com.badlogic.gdx.backends.lwjgl.LwjglCanvas$2.run(LwjglCanvas.java:160)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
This is on Ubuntu.

Any idea what the problem is here?
Posts: 13
Joined: Tue Jun 07, 2011 2:26 am

Re: [beta] Box2D Editor + FixtureAtlas

Postby Obli » Sun Jul 24, 2011 9:46 am

It seems that linux, awt and lwjgl are not good friends when put together. The error arised in another tool I made too.
I'll install a virtual linux machine and try to debug that. Thanks for reporting.

Nevertheless, can you give me some additional information ?
- Ubuntu 32b or 64b ?
- Java runtime 32b or 64b ?

Thanks !
Posts: 616
Joined: Mon Jan 10, 2011 6:18 pm
Location: Bordeaux, France


Return to Libgdx Contributions

Who is online

Users browsing this forum: No registered users and 1 guest