Author Topic: Serialized object displaced/different center  (Read 3714 times)

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Serialized object displaced/different center
« on: July 03, 2013, 09:19:59 am »
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.

« Last Edit: July 03, 2013, 09:32:55 am by Irony »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Serialized object displaced/different center
« Reply #1 on: July 03, 2013, 10:33:57 am »

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: Serialized object displaced/different center
« Reply #2 on: July 03, 2013, 10:57:43 am »
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)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Serialized object displaced/different center
« Reply #3 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.

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: Serialized object displaced/different center
« Reply #4 on: July 03, 2013, 11:05:49 am »
Ok, will try figuring that out when I get home. Thanks!

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: Serialized object displaced/different center
« Reply #5 on: July 03, 2013, 08:48:52 pm »
Tried a few things, nothing really worked, gonna postpone the problem and stick with 3ds for now.

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: Serialized object displaced/different center
« Reply #6 on: January 19, 2014, 12:12:06 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..?

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: Serialized object displaced/different center
« Reply #7 on: January 19, 2014, 12:36:20 am »
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!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Serialized object displaced/different center
« Reply #8 on: January 19, 2014, 10:37:08 am »
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...

Offline Irony

  • long
  • ***
  • Posts: 151
    • View Profile
Re: Serialized object displaced/different center
« Reply #9 on: January 19, 2014, 01:48:07 pm »
Thank you Egon. It works now. The problem was that I used this code from somewhere on this site when loading the object.

Quote
       Object3D 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!