Page 1 of 2

Creating separate objects in RUBE

Posted: Sun Jun 21, 2015 6:10 pm
by nikoliazekter
This question is pretty similar to this one https://www.iforce2d.net/forums/viewtop ... f=6&p=1676 however it didn't answer my question quite well.

In a nutshell, I want to use RUBE to design my game entities. I need to create bodies for them and then import these bodies in my game as one object. For example, let's assume I created a tank and a machine gun which should be connected using Weld joint with this tank (machine gun can be on top of different vehicles, not just this particular tank). My main question is how I get these objects from RUBE scene and add them to my world. Also each entity can be spawned infinite number of times.

Also I have doubts if everything should be implemented in different scenes (one scene for each entity in my game) or maybe somehow combined scenes (for example, all weapons in one scene, all vehicles in another) or even in one big scene.

Re: Creating separate objects in RUBE

Posted: Mon Jun 22, 2015 11:50 am
by iforce2d
I would use a different RUBE scene for each thing that needs to have all its pieces moved together.

So each machine gun (or other weapon) would be in its own file. Position it so that the (0,0) position is where the weld joint anchor will go when it's mounted.

In the tank (or other vehicle) scene, you can make a dummy body to serve as the mount position for the machine gun. Place the dummy body at the position where the weld joint anchor will go on the vehicle.

Load the vehicle scene, get the position of the dummy body, then destroy it. Then load the weapon and move all bodies in the weapon scene, eg. as mentioned in viewtopic.php?f=6&t=379 (the distance to move will be the position where the dummy body was).

Then you can create the weld joint between one of the bodies of the vehicle, and one of the bodies of the weapon. You'll need to name those bodies or give them a custom property so you know which to use. You can pass the position of the dummy body to b2Body::GetLocalPoint(b2Vec2) for each body to find the local coordinates of the joint anchor.

Re: Creating separate objects in RUBE

Posted: Mon Jun 22, 2015 12:00 pm
by nikoliazekter
Do i need to load RUBE scene each time I want to spawn new machine gun in my game?

Re: Creating separate objects in RUBE

Posted: Tue Jun 23, 2015 6:09 am
by iforce2d
Yes

Re: Creating separate objects in RUBE

Posted: Tue Jun 23, 2015 11:16 am
by nikoliazekter
Hmm. Isn't loading json at run-time bad for performance? I would rather load everything at the beggining of level displaying some kind of splash screen and then use these scenes multiple times.

Re: Creating separate objects in RUBE

Posted: Tue Jun 23, 2015 2:38 pm
by iforce2d
If you want to load something and not use it immediately, you can set all the bodies to be inactive and don't render the sprites/textures. You could also do that if the entities will "die", so that you can just re-activate them instead of loading a scene again.

Re: Creating separate objects in RUBE

Posted: Wed Jun 24, 2015 9:53 am
by nikoliazekter
I'm using RubeLoader for libGDX. It has class RubeScene that holds all data https://github.com/tescott/RubeLoader/b ... Scene.java . I guess making deep copy of RubeScene should do the trick. I'll test it and write my results later.

Re: Creating separate objects in RUBE

Posted: Mon Jul 06, 2015 12:26 pm
by milos
This is something i'm currently doing. Basically i dont want to have rube scene, i just want to use rube to model my world objects, like obstacles etc, and add it dynamically to world where i want. I've ended up modifying b2Json to spawn object at position i want ( of course all objects had to be placed at 0,0 in rube). Bad thing is that there is not way to preload all obstacles, sort of. What im currently doing is preloading Json::Value for each obstacle and when needed i just pass it to b2Json to create it. It could be even better if b2Json loader doesn't require world at all and instead just using some data holder objects with preloaded body/fixture/joint properties and when needed just use that to create real bodies. This way you could preload all in background thread.

One thing also that is really missing is some kind of text notes/comments that could be added in editor. I have a lot objects in scene which i need to export in each file separately and it's a pain in the a** to keep track of object to file relation.

Re: Creating separate objects in RUBE

Posted: Fri Jul 24, 2015 6:25 pm
by rileyrg
Please keep posting any updates. This is almost exactly what I want with the addition of the ability to replicate rube objects for multiple "in game" objects. Alas one cant use the B2dJson loader as the JBox2d classes are incompatible with the LibGDX B2d wrappers. See the thread here https://www.iforce2d.net/forums/viewtopic.php?f=6&t=442

Re: Creating separate objects in RUBE

Posted: Sun Jul 26, 2015 4:12 pm
by nikoliazekter
I was very lazy recently and didn't spend much time on this problem. Something I got so far:
1. You should reuse JSON. It's very easy and it saves some time however it's rather small fraction of all time needed to load RUBE scene.
2.Very big amount of time is needed to parse JSON (profiler gives me more than 100 ms for one medium and one big scene.)
So the real problem is how to avoid parsing scene every time. Also deep copy isn't an option (at least in Java).