Importing an external rube object
Importing an external rube object
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
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.
eg. you could try getBodyByPathAndName("LittleGuy", "guy")
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);
Re: Importing an external rube object
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
https://github.com/rileyrg/b2dJson
Re: Importing an external rube object
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?

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
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
Just for completion this is now merged into my libgdx loader. And works fine.
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
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);
https://github.com/rileyrg/b2dJson
Re: Importing an external rube object
Excellent, thanks for the update!