Serialized object displaced/different center

Started by Irony, July 03, 2013, 09:19:59 AM

Previous topic - Next topic

Irony

I used the mesh serializer plugin to convert my 3ds files.

.3ds looks like this:



.ser looks like this:


The red gun mounts are projected from child objects with identical relative positions in both cases.
Also, when playing the game and the camera is mounted at (0,0,0) looking forward, the guns are not firing symmetrical.

So it seems the ship model itself is slightly displaced or rather the center is calculated different, so relative positions change from 3ds.

btw, I'm calling world.buildAllObjects() in both cases.



Irony

Don't think so, but not sure... For some reason, I cannot access the server with my code at the moment.
Anyways, I adjust all models within blender so they have their origin at (0,0,0) - should I try to call setCenter(0,0,0) after calling build() ? (Can only try this after work)

EgonOlsen

No, not setCenter() but maybe setRotationPivot(). However, the ser-files contain the rotation pivot since some version. It might be that your plugin uses another version of jPCT to serialize them, so that the pivot isn't taken from the file but rebuild when calling build(). This might cause this offset somehow.

Irony

Ok, will try figuring that out when I get home. Thanks!

Irony

Tried a few things, nothing really worked, gonna postpone the problem and stick with 3ds for now.

Irony

Quote from: EgonOlsen on July 03, 2013, 11:03:17 AM
No, not setCenter() but maybe setRotationPivot(). However, the ser-files contain the rotation pivot since some version. It might be that your plugin uses another version of jPCT to serialize them, so that the pivot isn't taken from the file but rebuild when calling build(). This might cause this offset somehow.
Hi Egon, bringing this up once more, as my game is nearing completion and I still did not figure out a solution here.
Made sure to use the latest version of desktop JPCT to serialize, and I call setRotationPivot(SimpleVector.ORIGIN) after loading the 3DS into the serializer as well as after loading the .ser in my game. Still, the child objects are still at the same (wrong) positions. Kinda ran out of ideas now. Maybe you didn't..?

Irony

Okay, this is weird. I did cleartranslation and -rotation, and actually measured the positions with a tape :D
And what the heck, the child objects are actually in the same position whether 3ds or ser. But the ship itself moved!

EgonOlsen

Most important: Make sure that your app and the plugin are using the same version of jPCT/jPCT-AE. I'm not sure what the plugin itself does to the mesh, but the DeSerializer just writes and reads data. So one option would be to skip the plugin and serialize the file yourself. One other thing to keep in mind is that the 3ds version has rotation pivot and center set to the origin until you are calling build(). The deserialized version already has these values set to be able to speed up the build process. So if you are applying a translateMesh or a rotateMesh after loading the file, the results may differ. Try to set center and pivot to the origin right after loading the file and see if that changes something. Or, if you are already doing something like this for some reason, try if it helps if you don't.
If nothing else helps, post your code that does the loading...

Irony

Thank you Egon. It works now. The problem was that I used this code from somewhere on this site when loading the object.

QuoteObject3D o3d = new Object3D(0);
       Object3D temp = null;
       for (int i = 0; i < m.length; i++) {
           temp = m;
           temp.setCenter(SimpleVector.ORIGIN);
           temp.rotateX((float)(-Math.PI/2));
           temp.rotateMesh();
           temp.setRotationMatrix(new Matrix());
           o3d = Object3D.mergeObjects(o3d, temp);
       }

As all my objects are made of one mesh anyway, I rotate the meshes in Blender now, throw out the part above and just return what loadSerializedObject returns. Everything looks fine now. Thanks again!