Importing an external rube object

General discussion about the R.U.B.E editor
Post Reply
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Importing an external rube object

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Importing an external rube object

Post 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")
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Importing an external rube object

Post 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
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Importing an external rube object

Post 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?
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Importing an external rube object

Post 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.
rileyrg
Posts: 54
Joined: Sun Jul 19, 2015 11:42 am

Re: Importing an external rube object

Post 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
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Importing an external rube object

Post by iforce2d »

Excellent, thanks for the update!
Post Reply