Skip to content
July 11, 2011 / Aurélien Ribon

Incoming application: Box2D Editor

Hello!

I’m currently working on an open-source tool that will allow developers to easily create complex body shapes to use in the Box2D engine (well, actually the output format can let it be used for any physics engine).

I made it because of my own needs, but I’m sure it can help many people around here.

Available soon, stay tuned ;-)

Advertisements

10 Comments

Leave a Comment
  1. Michalis / Jul 11 2011 16:14

    Impressive work! Seems very easy to use. Please include some kind of instructions along with the release :-)

  2. Aurélien Ribon / Jul 11 2011 16:19

    Thanks. Of course, the release will be accompanied with some extensive documentation, including a video tutorial.
    Currently, I’m polishing the java library that will be used to easily import shape definitions into people games and applications.

  3. Zenshark Studios / Jul 13 2011 03:43

    Very nice stuff. Tested it with a couple of my images, worked flawlessly. You mentioned that it would be open-source? I was just curious as to how you merged the ear-clipping algorithm with box2d polygons/fixtures.

    I have a pixel map, made in Paint.NET, that I read in with libgdx’s pixmap and through some annoying math determine the shape’s parts (like is this a cap or a t-joint or a 1-edged piece) and then end up with a list of vertices which I intended to use with box2d. However, I failed to notice that box2d only accepts concex polygons and was interested in seeing your implementation. Appreciate the help.

    Tamas

  4. Aurélien Ribon / Jul 13 2011 05:36

    Actually it will be part of the libgdx extensions, so you will be able to easily grab its source. I use the tesselation algorithm made by ewjordan from the official box2d forums. He made a processing applet and release the source:

    http://www.ewjordan.com/earClip/

    I just get the shape drawn by the user as an array of Vector2 and throw it to this algorithm to get a Vector2[][], representing the convex polygons.
    Then, all you have to do is to create a box2d Body and to iterate over those polygons. For each one, you create a new FixtureDef and call body.createFixture().

    Therefore, each set of convex polygon is a set of fixtures for a body. Thus the name of the importer: FixtureAtlas ;-)

  5. Zenshark Studios / Jul 13 2011 14:51

    Whoops. I looked into ewjordan’s code and it looks good. I’ll probably use that. It specifies that the vertices must be given in a CCW fashion. What would be the best way of ordering the vertices so that they are counterclockwise order?

    Appreciate the help

  6. Aurélien Ribon / Jul 13 2011 14:55

    Have a look at the following Polygon implementation, it contains a “isCCW()” method:
    http://introcs.cs.princeton.edu/java/35purple/Polygon.java.html

    I’ll implement that for the editor as well. Currently, the shape has to be defined in CCW order.

  7. Zenshark Studios / Jul 13 2011 15:19

    Unfortunately I do not have the luxury of putting my vertices in order :/ However I was hoping for something like this except for concave polygons

    http://compgeom.cs.uiuc.edu/~jeffe/teaching/373/notes/x05-convexhull.pdf

  8. Aurélien Ribon / Jul 13 2011 15:26

    If you cannot order your vertices, then you can only define a convex polygon from these vertices, with the methodology given in your article, and Box2D gladly accepts any convex polygon (with up to 8 vertices).

    You cannot get a unique concave polygon from an unordered vertex list, since there are multiple solutions. If you want anything concave, your only chance is to start with an ordered list.

    That’s why I made this tool :)

  9. Zenshark Studios / Jul 13 2011 15:40

    That’s unfortunate. Well, it would be possible though if I managed to my vertices via a better method? Say if I made my import algorithm had a strong preference for right turns and kept making those until it had no other choice. This way I should have all my box2d vertices in order from start to finish. Or would this not work as well?

  10. Zenshark Studios / Jul 13 2011 15:59

    edit: the game I’m creating atm is sort of like Assembler. That is, it is very blocky and all my shapes are essentially tiles glued together which certainly makes my job easier. I would like to combine these tiles into larger boxes so that I have the minimum number of boxes.

    Appreciate the help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s