Via the GUI there is copy+paste, then delete the original. I suppose a button to select the body of a fixture would be handy too, like how the body of an image can be changed. But I guess you are mainly talking scripts right? In that case no, there is no simple function to do that. I am not sure why you would need a separate scene to do this, but I can show you one way it could be done using the jsonEncode(dictionary) function that was added in the last update.
I didn't make a big deal out of this function since there is no corresponding jsonDecode function yet, and it is not likely to be commonly used apart from by 133t scripters like yourself and the folks who requested it. It lets you create a structure of 'associative arrays' with the Angelscript 'dictionary' type, and then convert this to a JSON string which can be given to RUBE functions like addBody, addFixture etc.
This lets you create things in a very similar way to how you would when programming everything manually... not exactly in line with the goal of a graphical editor, but handy as a fallback
Here is an example of how you would create a fixture definition, and then use that to add a fixture to a body:
Code: Select all
//vertices for shape
vec2[] vs;
vs.insertLast( mv(-0.5,-0.5) );
vs.insertLast( mv( 0.5,-0.5) );
vs.insertLast( mv( 0.5, 0.5) );
//fixture def
dictionary fd;
fd.set("density",1);
fd.set("friction",0.5);
fd.set("vertices", vs);
//shape def
dictionary sd;
sd.set("type","polygon");
//fixtures can have multiple shapes, so need an array
//use references so we can alter the shape properties later
dictionary@[] ss;
ss.insertLast(@sd);
fd.set("shapes",ss);
//add the fixture to selected body
sb()[0].addFixture(-1, jsonEncode(fd) );
Internally RUBE does duplicating and copy+paste etc by passing around JSON strings, so it would not be too much work to add a second version, eg. jsonEncode(fixture) that returns the JSON string of a given fixture, body etc. which would allow much simpler direct copying like you're talking about. However, that would not be nearly as useful as a function that returns a dictionary representation of an item, so that individual parts of it could be easily modified. Here is what I would ideally like to be able to do:
Code: Select all
fixture f = sf()[0];
dictionary fd = makeDictionary( f );
fd.set("friction", 0.5);
sb()[0].addFixture(-1, jsonEncode(fd) );
I've attached a scene with a sample usage of the jsonEncode function. Run the script to create some bodies with varying shape types, restitution etc. Incidentally, the use of @ in these examples is not really necessary, but it allows you to modify parts of the structure after adding them, instead of merely assigning by value. For example, continuing on from the first code block above, you could do this:
Code: Select all
sd.set("type", "loop");
sb()[0].addFixture(-1, jsonEncode(fd) );
...to change just the shape type and create another fixture with all other properties the same.