Saving file with joints.

Report problems here (or use the built-in feedback dialog in the editor)
Post Reply
aholla
Posts: 10
Joined: Fri Feb 22, 2013 4:18 pm

Saving file with joints.

Post by aholla »

Hi,

I'm trying to save my levels but when I reload the levels and try exporting again, I get lots of errors related to the joints.

If i open a file and without changing anything, click save as. When I compare the new file with the old file they have lots of changes.

The simulation run correct but the export is not. I suspect the body id number (something I cant edit or view in the editor) are not being matched correctly.

I have found a temporary solution and that is when I open the newly saved file, to copy and past the bodies with joints into another temporary open file, one at a time. Then delete them from my file and copy them back in from the temporary file.

I watched all your tutorial video and remember hearing about problems when copying joints but can remember which video this was.

I can send you an example if you would like to test my scene.

It is strange that the simulation runs the same but not the export.

I am using your example loader and occasionally get an error when creating the joint: "Index for bodyB is invalid: ";
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Saving file with joints.

Post by iforce2d »

Are you talking about .rube files or .json files? You should have no problem with .rube files, but .json files are not meant to be reloaded into the program for further editing.

Still, even the .json files should not cause problems like this. If you could give me a simple scene file, and the steps to reproduce the problem I'll take a look.
aholla
Posts: 10
Joined: Fri Feb 22, 2013 4:18 pm

Re: Saving file with joints.

Post by aholla »

Hi Iforce, thanks for the reply.

I wont be able to access the files untill monday but will post upload them then and post back.

I am using the .rube files. They work fin inside rube, the simulation runs fine. But if I save them, the data changes and the joints break. Will post again on monday with the files and some steps to reproduce.

Thanks,

Adam
aholla
Posts: 10
Joined: Fri Feb 22, 2013 4:18 pm

Re: Saving file with joints.

Post by aholla »

Hey iforce,

I have a file you can look at: https://dl.dropbox.com/u/698268/dev/rub ... ample.rube

1. If you open this file and export it as json, then close the file. Open again and export again under a different name, the two json files have slight changes.

2. If you open this file and save it an new file, the two saved rube files have lots of differences. If you export json from each both will be different.

Although this may just be an order thing in the json, in my javascript game, it ends up with some joints not being attached to bodies.

Then in my javascript file, i loop though all the bodies and then loop though all the joints using code from your example, e.g:

Code: Select all

 
var loadedBodies = [];
    if ( worldJso.hasOwnProperty('body') ) {
        for (var i = 0; i < worldJso.body.length; i++) {
            var bodyJso = worldJso.body[i];
            var body = loadBodyFromRUBE(bodyJso, world);
            if ( body )
                loadedBodies.push( body );
            else
                success = false;
        }
    }
    
    var loadedJoints = [];
    if ( worldJso.hasOwnProperty('joint') ) {
        for (var i = 0; i < worldJso.joint.length; i++) {
            var jointJso = worldJso.joint[i];
            var joint = loadJointFromRUBE(jointJso, world, loadedBodies);
            if ( joint )
                loadedJoints.push( joint );
            else
                success = false;
        }
    }
After this, when I querry bodies that should have joints, I get an error stating they don't have any joints...

Thanks for any help, as mentioned I currently have a solution but it is a bit of a pain.

Thanks,

Adam
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Saving file with joints.

Post by iforce2d »

1. I'm not seeing any changes in the two .json files. Just to make sure, you mean to open the .rube twice right? Opening an exported .json and re-exporting it is likely to cause many changes.

2. The two saved .rube files do have lots of differences, but none that I can see should cause any significant effects like missing joints. Mainly the ordering of joints is different, and some floating point rounding is different from the ascii parsing.

When you say 'query bodies that should have joints', how are you querying them?
aholla
Posts: 10
Joined: Fri Feb 22, 2013 4:18 pm

Re: Saving file with joints.

Post by aholla »

HI iforce,

thanks for taking to time to check this out. Yeah, whenever I reopen and export a level, it end up breaking, some of my bodies no longer have the joints they should. I thought the differences in the export or the rube file might help show this but perhaps it' s my game code that is the problem. This is what I am doing:

Code: Select all

createObjects = function () {
		this._objects = [];
		var loadedBodies = [];

		/*  CREATE THE BODIES */
		if ( this._currentLevelData.hasOwnProperty( 'body' ) ) {
			for ( var i = 0; i < this._currentLevelData.body.length; i++ ) {
				var bodyJson = this._currentLevelData.body[ i ];
				var body = Rube.loadBodyFromRUBE( bodyJson, this._world );
				loadedBodies.push( body );
			}
		}

		/*  CREATE THE JOINTS */
		if ( this._currentLevelData.hasOwnProperty( 'joint' ) ) {
			for ( var i = 0; i < this._currentLevelData.joint.length; i++ ) {
				var jointJson = this._currentLevelData.joint[ i ];
				var joint = Rube.loadJointFromRUBE( jointJson, this._world, loadedBodies );
			}
		};

		/* SET BODIES TO CLASSES */
		for ( var i = 0; i < loadedBodies.length; i++ ) {

			var body = loadedBodies[i];
			var image = null;

			switch ( body.name ) {

				case 'seesaw_auto_rotate':
					object = new Seesaw( body );
					break;

		// I have a whole list of objects here
			}
		}
		loadedBodies = [];
	};


(function ( ) {
	SeesawAutoRotate .prototype._body = null;

	function SeesawAutoRotate ( body ) {
		this._body = body;

		if ( this._body.GetJointList() ) {
			this._joint = this._body.GetJointList().joint;
			this._lowerAngle = this._joint.m_lowerAngle;
			this._upperAngle = this._joint.m_upperAngle;
		}
	}
}

When I run the 'SeesawAutoRotate' constructor, I get an error stating that "joint" does not exist. This is now what I expected, the body has a joint when in Rube but when it is parsed, it no longer has any joints. It is as though the joint has been lost or has been assigned to another body, I think the differences in the JSON export might be this, joints being assigned to different bodies.

Thanks for looking into this,

Adam
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Saving file with joints.

Post by iforce2d »

Just to make sure (again), are you reopening the .rube or the .json? You are not supposed to reopen the .json in the editor :)
aholla
Posts: 10
Joined: Fri Feb 22, 2013 4:18 pm

Re: Saving file with joints.

Post by aholla »

haha, yeah, my json files are exported elsewhere so no confusion.

It's hard to explain, I may have to make a video. I've just been trying to replicate the bug and it happened once but I could not figure out what it was.

The problem seems to occur when copying bodies with joints from one file to another, opening and closing the files. When I have pinned it down il post again but until then, dont worry abount it.
aholla
Posts: 10
Joined: Fri Feb 22, 2013 4:18 pm

Re: Saving file with joints.

Post by aholla »

Hey so it turns out it was my code... I was looping though all the bodies and added them to a loaded bodies array except I was excluding one of the bodies which I wanted to create later. This was then shifting all the body and joints around and messing things up.

Thanks for taking the time to look into this of should have know it would be my code. Thanks!
Post Reply