Displaying world/accessing loaded from b2djson in Processing

Hi, I've just started using b2djson to load a world designed in RUBE and saved to json format.

Newbie question, how to display the world object?

Also, how to access objects in the world?

Thanks in advance!

Code: Select all

[code][/code]


Code: Select all


import shiffman.box2d.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.contacts.*;

// import the iforce2d libraries
import org.iforce2d.*;

Box2DProcessing box2d;

void setup() {
  size(640, 360);
  smooth();

  box2d = new Box2DProcessing(this);
  box2d.createWorld();
  org.iforce2d.Jb2dJson json = new org.iforce2d.Jb2dJson() ;

  StringBuilder errorMsg = new StringBuilder();
  World world = json.readFromFile("bike.json  ", errorMsg);

  println(world);
  println(errorMsg);
}

void draw() {
  background(255);

  box2d.step();
}
This seems more like a processing question than a Box2D question. Do you know how to draw a box, or some lines etc, in processing?
The easiest way to get started would probably be to make a 'debug draw' implementation for processing. You can read about how debug draw works in the Box2D manual http://www.box2d.org/manual.html and also here: http://www.iforce2d.net/b2dtut/debug-draw

To access objects in the world you could loop over all bodies as shown in the Box2D manual (search for "Exploring the World")

To get specific bodies that you named in your RUBE scene, you can use the getBodyByName() or getBodiesByName() functions as explained on the main b2dJson page: http://www.iforce2d.net/b2djson/
Same goes for fixtures, joints, and images.
It might help to have a look at the source for b2dJson as well as there are some functions that were added after writing the main page that are not mentioned on it. https://github.com/iforce2d/b2dJson/blo ... dJson.java

Original thread: https://box2d.org/forum/viewtopic.php?t=9974