Author Topic: Rotation of asymmetrical 3ds object problem  (Read 6243 times)

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Rotation of asymmetrical 3ds object problem
« on: February 02, 2012, 06:24:32 am »
As a different approach to constructing my maze I decided I'd make the corridor pieces and slot them in place depending on the map array.

So an area like this:
11111
00X00
11011
Would have a junction model at the X and suitably rotated corridor objects at the 0s (and nothing at the 1s)

However when doing this, for some reason whenever I rotate my asymmetrical junction models (basically just being one wall) they shift about and don't rotate around their origin.

Here is the model relative to the origin in Deled:

(The dark blue lines showing the X and Z axes and their intersection being the origin in all 3 axes.)

(I export the model as .x and import into Milkshape3D to export as .3ds (after mirroring in the Y axis) )

When I put the model into the actual game I get these kind of results:


(The horizontal polygon is merely there to show the offset and because I tried testing it by making vertices on symmetrical sides of the origin (to no avail of course))

And it's even more obscure when I've rotated a quarter turn. :S

I've tried omitting the build method or the compile and strip method. I've tried manually calculating the rotation pivot and the object center (neither of which changed anything)

So I'm kind of stuck now...

I simply can't do what seems an almost trivial task. xD

All the code affecting any one object in the game set up:
Code: [Select]
blocks[bindex]=wallDummy.cloneObject();
blocks[bindex].setTexture(wallTex);
blocks[bindex].rotateY(-(float)Math.PI/2); // Or some other angle if it's a different junction block
blocks[bindex].setSpecularLighting(true);
blocks[bindex].translate(i*20,0,j*20);
blocks[bindex].setRenderHook(genericNormalMapping);
blocks[bindex].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
blocks[bindex].compileAndStrip();
world.addObject(blocks[bindex]);
bindex++;

And wallDummy is retrieved like this:
Code: [Select]
type="3ds";
path="wall";
wallDummy=Object3D.mergeAll(Loader.load3DS("res/"+type+"/"+path+"/"+path+".3ds",0.125f));
wallDummy.build();
tm.addTexture(path+"Tex",new Texture("res/"+type+"/"+path+"/"+path+".png"));
tm.addTexture(path+"TexN",new Texture("res/"+type+"/"+path+"/"+path+"N.png"));
wallTex=new TextureInfo(tm.getTextureID(path+"Tex"));
wallTex.add(tm.getTextureID(path+"TexN"),TextureInfo.MODE_MODULATE);
« Last Edit: February 02, 2012, 06:31:50 am by Cowbox »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #1 on: February 02, 2012, 08:21:37 am »
What does the actual rotation pivot should be? (0,0,0)? The pivot is calculated by build(). If you want to reset it, do something like

Code: [Select]
obj.build();
obj.compile();
obj.setRotationPivot(x,y,z);

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Rotation of asymmetrical 3ds object problem
« Reply #2 on: February 02, 2012, 11:36:03 am »
Well I did try something along those lines, with no success.

All I actually wanted was to just use the original model's pivot. i.e. not calling build at all - and this still didn't fix it. :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #3 on: February 02, 2012, 12:19:26 pm »
You are not supposed to omit build(). If you are using compiled objects (which you do, because you are using shaders), you even can't. If you do, the engine will call it for you.

If you want the pivot taken from the file (in case of 3ds), have a look here: http://www.jpct.net/doc/com/threed/jpct/Config.html#useRotationPivotFrom3DS

If it's another format, just do what i posted with the correct pivot.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Rotation of asymmetrical 3ds object problem
« Reply #4 on: February 02, 2012, 01:33:56 pm »
Dang, I saw that useRotationPivotFrom3DS and thought "Aha! That's exactly what I'm looking for."

After setting it to be true though, nothing has changed. D:

What's going wrong. :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #5 on: February 02, 2012, 03:18:06 pm »
You'll find the pivot that it reads from the file (if any) in the log output. Does it match your expectations and if it does, is it still the same when rendering the objects?

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Rotation of asymmetrical 3ds object problem
« Reply #6 on: February 07, 2012, 01:43:14 pm »
Right, I'm back. I got a bit distracted for a few days.

I tried looking for the pivot in the log output and couldn't see anything.

This problem is really starting to annoy me now because it basically means I can't actually do anything in this engine anymore.

We switched to .obj because we thought it was a problem with .3ds but exactly the same problem is occurring.

Here is a screenshot showing the centre of rotation on a corner object I'm trying to use in Deled:


And here are 4 of them stacked on top of each other (at 0,-10,0; 0,-20,0; 0,-30,0; and 0,-40,0; at rotations 0 degrees, 90 degrees, 180 degrees and 270 degrees respectively):

As you can see, the 4 objects are not rotating around the pivot point shown in Deled. (Those back 2 squares should be horizontally aligned.)

What do I do now D:?
« Last Edit: February 07, 2012, 01:49:46 pm by Cowbox »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #7 on: February 07, 2012, 02:12:33 pm »
I fail to see the exact problem here...either you already know the pivot, then set it after calling build(). If you don't know it, try to load it from the 3ds. If it has been exported to the file and Config.useRotationPivotFrom3DS=true, the log will say so. If there's no log output, then there's no pivot in the file. OBJ doesn't have a pivot anyway, so there's no point in moving to OBJ to solve this...it all boils down to this: jPCT can't get the correct pivot out of thin air. So it's either part of the file (3ds only) or you have to set it by hand (if the automated calculation doesn't fit).

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Rotation of asymmetrical 3ds object problem
« Reply #8 on: February 07, 2012, 02:42:46 pm »
The problem is that the objects are not rotating around 0,0,0 once they've been loaded into jPCT.

Achieving this seems to be the most difficult task on the planet as it doesn't work in .3ds with or without the Config.useRotationPivotFrom3DS method or for .obj.

I also don't really understand how one is supposed to set the pivot manually as it would surely be relative to 0,0,0 and setting the pivot to be 0,0,0 therefore seems like it'd already be the default values.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #9 on: February 07, 2012, 05:33:04 pm »
Achieving this seems to be the most difficult task on the planet as it doesn't work in .3ds with or without the Config.useRotationPivotFrom3DS method or for .obj.

I also don't really understand how one is supposed to set the pivot manually as it would surely be relative to 0,0,0 and setting the pivot to be 0,0,0 therefore seems like it'd already be the default values.
No, it's drop dead simple and i already posted how to do it:

  • call build()
  • set the rotation pivot to (0,0,0)

That all there is to do. If it still doesn't rotate right, you can verify that the pivot is correct by getting it from the Object3D and if it is, but rotation still isn't what you want, then (0,0,0) isn't the pivot that you actually want. A little bit of trial-and-error should help to find the actual pivot that does the trick. There is no default of (0,0,0) or at least not after calling build(), which resets the pivot to the one calculated based on the geometry.
Others are successfully using the option to get the pivot from the file and if that doesn't work, then maybe the exporter you are using simply doesn't export it!? I can check the file if you want to see if it's actually in there.

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Rotation of asymmetrical 3ds object problem
« Reply #10 on: February 07, 2012, 07:51:17 pm »
Well I can't say I didn't see that coming.

Doing build() then setRotationPivot(new SimpleVector(0,0,0)) changes absolutely nothing and everything's still rotating about a completely random point. (I've tried this on both .3ds and .obj being exported from Cinema4D and Deled, both programs can find the pivot point/0,0,0 fine.)

The annoying thing about the point jPCT is getting is that it isn't even being calculated properly based on the vertices available.

I've got models that essentially end up with cube shaped bounding boxes and yet their rotation point is like some kind of half measurement: it's not the real centre of the cube.

Why is this so difficult... xD All I want to do is rotate everything around 0,0,0 like every other 3D engine/program I've ever encountered does.
« Last Edit: February 07, 2012, 08:08:28 pm by Cowbox »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #11 on: February 07, 2012, 08:41:46 pm »
It isn't difficult! IF you set (0,0,0) as rotation pivot, it WILL rotate around (0,0,0). It's a simple matrix operation...it's really that simple. If the result isn't what you expect, then either (0,0,0) isn't the point you really want or your exporter translates the mesh somehow (or you do...). Or you are thinking in some completely different space...when i talk about a rotation around (0,0,0), i'm always talking about object space, not about world or camera space. Do we agree here?

If YES, then please do:

  • call build()
  • call setRotationPivot(0,0,0)
  • post the result that getRotationPivot() gives you IN the actual render loop

If NOT, then...we've talked about totally different things and i've no idea what you want to do...


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #12 on: February 07, 2012, 08:44:06 pm »
BTW: Could you please post the mesh that you are using?

Offline Cowbox

  • int
  • **
  • Posts: 58
  • >:D
    • View Profile
    • Soharix
Re: Rotation of asymmetrical 3ds object problem
« Reply #13 on: February 08, 2012, 09:47:02 am »
Ah yeah, there's the problem, clear as day.

I've got the following code:
Code: [Select]
String type="obj";
String path="corner";
wall1=Object3D.mergeAll(Loader.loadOBJ("res/"+type+"/"+path+"/"+path+"."+type,"",0.125f));
wall1.build();
wall1.setRotationPivot(new SimpleVector(0,0,0));
wall1.translate(0,-10,0);
world.addObject(wall1);

Yet when I use:
Code: [Select]
System.out.println(wall1.getRotationPivot());in the main loop, I get:
(5.0,0.0,5.0)

How is this managing to happen D:?

Here is the corner model I'm using (with a cube bounding box around 0,0,0 in our modelling programs):
http://www.soharix.homestead.com/java/corner.obj - This was exported by my modeller from Cinema4D I believe
Here is a very similar object that I made myself in Deled:
http://www.soharix.homestead.com/java/corner.3ds

Extra:

Nothing changes if I add the line wall1.setCenter(new SimpleVector(0,0,0));

And perhaps what's more concerning is that nothing changes if I try this:
Code: [Select]
wall1.setCenter(new SimpleVector(-5,0,-5));
wall1.setRotationPivot(new SimpleVector(-5,0,-5));
The pivot still turns out at 5,0,5. D:
« Last Edit: February 08, 2012, 09:54:31 am by Cowbox »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Rotation of asymmetrical 3ds object problem
« Reply #14 on: February 08, 2012, 10:10:14 am »
Check if you are calling build() on the object itself or on clones of it after setting the pivot as this will reset the pivot. setCenter() has no effect on the rotation pivot btw.