Page 1 of 1

Improvement in CPP SCENE EXPORT

Posted: Sat Feb 15, 2014 9:47 pm
by fisher
Hello,

I think about improvement for option: File->Export Scene->Save as source code.

Exporting scene to *.cpp file is quite nice, however, objects are exported in their own scope, that is, between "{}". I know that this was the easiest way to generate objects tree, but each object has the same name, for example:

Code: Select all

b2BodyDef bd;
b2FixtureDef fd;
etc..

However, if you want to find something or extract any object, you can't really say where your object is looking at cpp code.

But, in RUBE each object has a NAME property.

Why not include this NAME (and other properties) in object's scope? For example as a comment:

Code: Select all

{
    //name: small_box
    b2BodyDef bd;
    bd.type = b2BodyType(2);
    ....
}
or even better, as some kind of mapping name->object:

Code: Select all

{
    b2BodyDef bd;
    bd.type = b2BodyType(2);
    ....

    bodies["small_box"] = &bd;
}
or advanced version with property table:

Code: Select all

{
    b2BodyDef bd;
    bd.type = b2BodyType(2);
    ....

    ObjectProperties *objProp = new ObjectProperties();
    objProp.name = "small_box"
    
    bodies["small_box"] = objProp;
}
Is it possible to make such improvement?

Re: Improvement in CPP SCENE EXPORT

Posted: Mon Feb 17, 2014 12:12 am
by iforce2d
The cpp export uses the b2World::Dump function of Box2D directly, and was added mostly as an afterthought. It remains there just in case it could be handy for some situations like quickly getting a simple scene running without the overhead of setting up a loader fully. I would not encourage using it for anything more than that. Come to think of it, I would not really encourage using it at all. viewtopic.php?f=6&t=95

The C++ loader can be set up by adding a few files to your project, and will give you easy access to the full data available in the scene. In the "sampleLoaders" folder that comes with the trial download, you should find a bunch of examples that are done in C++, for example box2d-testbed-(C++) or SFML-(C++). Look for the 'rubestuff' folder in these, and add the contents of that to your project. Then you can start using the loader as described here: http://www.iforce2d.net/b2djson/