Page 1 of 1

Importing an external rube object

Posted: Sat Apr 23, 2016 7:05 am
by rileyrg
When I add an object the rube editor correctly shows it in my scene. It has a name attribute. Now I want to reuse one body externalised and used as an imported object multiple times in a single scene. how? eg I have "guy" which is an body with a few fixtures in guy.rube. The body is called guy in that guy.rube. In my scene I import guy twice and scale it differently.. LittleGuy and BigGuy for example in the object name field. I'm missing how to get a body ref to the correct bodies since both are called Guy for the purposes of getBodiesByName.

Re: Importing an external rube object

Posted: Sun Apr 24, 2016 1:15 am
by iforce2d
These functions have been added to the C++ loader to deal with finding objects by 'path'. The 'path' will be the names of the object(s) the body is included from, separated by forward slashes. In your case it should be 'LittleGuy' or 'BigGuy'. Check the output .json to be sure.

Code: Select all

    int getBodiesByPath(std::string path, std::vector<b2Body*>& bodies);
    int getFixturesByPath(std::string path, std::vector<b2Fixture*>& fixtures);
    int getJointsByPath(std::string path, std::vector<b2Joint*>& joints);
    int getImagesByPath(std::string path, std::vector<b2dJsonImage*>& images);

    b2Body* getBodyByPathAndName(std::string path, std::string name);
    b2Fixture* getFixtureByPathAndName(std::string path, std::string name);
    b2Joint* getJointByPathAndName(std::string path, std::string name);
    b2dJsonImage* getImageByPathAndName(std::string path, std::string name);

    std::string getBodyPath(b2Body* body);
    std::string getFixturePath(b2Fixture* fixture);
    std::string getJointPath(b2Joint* joint);
    std::string getImagePath(b2dJsonImage* img);
eg. you could try getBodyByPathAndName("LittleGuy", "guy")

Re: Importing an external rube object

Posted: Mon Apr 25, 2016 10:42 am
by rileyrg
C++ loader? I'm using the json java loader that I ported over to libgdx. Am I confused? (ie what do I need to do to get this functionality)
https://github.com/rileyrg/b2dJson

Re: Importing an external rube object

Posted: Wed Apr 27, 2016 3:12 am
by iforce2d
ok, good to know :) I had not added the equivalent functions to the Java code.

I just added them to the github source now, but since it's mostly a copy+paste of the same code for dealing with names (both are just a string property) I have committed without compiling to check. Let me know if there are any problems.

Since you've already ported something to libGDX, you might be interested to look at the changes rather than getting the whole files afresh: https://github.com/iforce2d/b2dJson/com ... 85d26b353c

By the way, what was involved in porting this to use for libGDX?

Re: Importing an external rube object

Posted: Thu Aug 04, 2016 4:37 am
by rileyrg
Was a case of finding compatible collection classes in the main and using them. Libgdx has its own suite of collections that reduce / eliminate garbage collection . That said I was a complete java noob bsck when and possibly there was a way to use it having altered nothing. Just getting back into my project now.

Re: Importing an external rube object

Posted: Fri Aug 05, 2016 12:41 pm
by rileyrg
Just for completion this is now merged into my libgdx loader. And works fine.

Code: Select all

       Body importedBee = b2dm.json.getBodyByPathAndName("bee1","beezy");
		GameBody ib = new GameBody(importedBee);
		importedBee = b2dm.json.getBodyByPathAndName("bee2","beezy");
		ib = new GameBody(importedBee);
Where bee1 and bee2 are the emebdded scene objects/names and "beezy" is the body in that scene. Very nice.

https://github.com/rileyrg/b2dJson

Re: Importing an external rube object

Posted: Sat Aug 06, 2016 1:36 am
by iforce2d
Excellent, thanks for the update!