Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Proof of concept conversion of 3rd party box2d editor json output to lua — Gideros Forum

Proof of concept conversion of 3rd party box2d editor json output to lua

ndossndoss Guru
edited February 2012 in General questions
I made a small example of using the json output of the R.U.B.E. box2d editor (http://www.iforce2d.net/b2deditor/) to create and display a box2d world. It uses the JSON4Lua library (JSON4Lua library: http://json.luaforge.net/) to read the json output and convert it to a lua table. Some ugly lua code that I wrote (with help from atilim -- thanks!) then converts the lua table to a box2d world.

The code & simple gideros project can be found at: https://bitbucket.org/ndoss/gideros_playground

One question I have about the box2d implementation in gideros -- is there a way to interact with the box2d elements if using b2.DebugDraw?
+1 -1 (+3 / -0 )Share on Facebook

Comments

  • atilimatilim Maintainer
    That's really really great! :) I've just run the example you provided but I want to play more. (Also, I haven't heard R.U.B.E. before)

    To interact with the box2d elements, you can follow these steps:
    1. Get the fixtures under the mouse/touch by using b2.World:queryAABB function. Creating a small AABB (e.g. with size 0.001) around mouse coordinate is enough:

    2. If you get a fixture, get the body from the fixture and create a mouse joint:
      local x = event.x
      local y = event.y
      local fixtures = world:queryAABB(x - 0.001, y - 0.001, x + 0.001, y + 0.001)
      if #fixtures > 0 then
        local body = fixtures[1]:getBody()
        -- create mouse fixture here
      end
    3. on mouse up event, if there is a mouse fixture, destroy it.

    Elastic Joints example shows creating and destroying mouse fixture.

    (Also there is an open source project by @Stoffe that converts paths and positions in Inkscape to Lua tables: http://www.giderosmobile.com/forum/discussion/130/box2d-editor#Item_6)
  • Thanks again, that works!
  • Hi ndoss, could you help me with your project?
    Could you post a tutorial or a more detailed read me file, for getting it to work?

  • What are you having trouble with?

    After downloading the code in bitbucket, all you have to do to run the demo is to load the project file with GiderosStudio and run it through the GiderosPlayer.
  • Oh it's so simple... I don't found the download link :) thanks for the help. That's amassing, it's works like a charm.
  • The proof-of-concept code doesn't seem to handle box2d "chains", so I'm getting this error:

    createBox2dWorld.lua:34: shape must exist in fixture definition table

    Ndoss, would you have an updated version (before I start hacking the code)?
  • No,I haven't done anything with this in a long while
  • jdbcjdbc Member
    edited July 2013
    I have seen some R.U.B.E samples uses b2djson for C++ projects (http://www.iforce2d.net/b2djson/).

    If Gideros box2d API is similar to original box2d API, the challenge will be port b2djson to Gideros lua code.

    A plugin will be more difficult because it will need access to native C++ box2d API

Sign In or Register to comment.