Author Topic: Way to rotate loaded model permanently  (Read 2706 times)

Offline bLAZY

  • byte
  • *
  • Posts: 18
    • View Profile
Way to rotate loaded model permanently
« on: January 31, 2012, 11:26:00 pm »
Hi,

I load md2 model and it's rotated at start around Y-axis by 180 degrees. My game is taht object goes into the screen and should see its back but now I see front. Is here some way to rotate this object during loading?


EDIT:

I found solution a little bit too late.

Code: [Select]
object.rotateY((float) Math.PI);
object.rotateMesh();
object.clearRotation();

Sorry for cluttering.
« Last Edit: January 31, 2012, 11:34:08 pm by bLAZY »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Way to rotate loaded model permanently
« Reply #1 on: January 31, 2012, 11:32:24 pm »
You can do:

Code: [Select]
// Load your object here, then do...
obj.rotate?(<whatever>);
obj.rotateMesh();
obj.clearRotation();

Offline bLAZY

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Way to rotate loaded model permanently
« Reply #2 on: January 31, 2012, 11:37:24 pm »
Egon always first :) I wasted two hours to adjust my code and it doesn't worked until I saw that solution. jPCT has always what I need.
Thanks.

Offline HammerNL

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Way to rotate loaded model permanently
« Reply #3 on: April 08, 2013, 04:56:16 pm »
I'm doing (almost) the same thing, but somehow rotateMesh() does not make the rotation permanent in my case.

I'm loading a 3DS model using Loader.load3DS(). Like bLAZY I also need to permanently rotate the object. My object consists of more than 1 object, so I'm wrapping them in a dummyObject first, which then is rotated:

Code: [Select]
Object3D[] puppetParts  = Loader.load3DS(stream,.1f);
Object3D puppet = Object3D.createDummyObj();
for (Object3D part: puppetParts)
  puppet.addChild(part);
puppet.rotateZ(-PI/2); // make puppet face positive X axis
puppet.rotateMesh(); // should make rotation permanent
puppet.clearRotation(); // but this rotates my puppet back!?
world.addObjects(puppetParts);

What am I doing wrong?

Thanks!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Way to rotate loaded model permanently
« Reply #4 on: April 08, 2013, 07:18:32 pm »
It doesn't work that way. rotateMesh makes rotations permanent to the mesh of the object to which it is being applied. Applying it to a dummy mesh makes it permanent to that mesh, which makes no sense. You have to rotate each part and call rotateMesh on all of them.

Offline HammerNL

  • byte
  • *
  • Posts: 15
    • View Profile
Re: Way to rotate loaded model permanently
« Reply #5 on: April 08, 2013, 08:28:02 pm »
You do react fast, fantastic!

I was afraid of that, but simply rotating the encapsulating dummyObject seems a lot easier. All sub-objects then rotate in one go around the same axis, which works nicely. So the sub-objects do get rotated.

I've also tried calling rotateMesh() on each of the sub-parts, but that has no effect.

I'm sure there is a good explanation, but I simply don't see it. In my head, all the objects are correctly presented on the view, and I simply want that view to be the default.

I will try rotating all the sub-objects one by one around the same axis, and I'm sure that will work. Wouldn't it make sense if my approach would also work?

Thanks