1
votes

I am trying to rotate an OBJ from maya around an axis in Maya. It works just fine with a sphere, but with my own object - it is following an orbit. Maybe I don't understand the shape(parameters).

PShape s;
float theta = 0;

void setup() {
  size(500, 500, P3D);
  shapeMode(CENTER);
  s = loadShape("obj2.obj");
}

void draw() {
  background(32);
  lights();
  float z = 0;
  pushMatrix();
  translate(0,height*1/4);
  rotateY(theta);
  theta += .01;
  scale(4.0);
  box(100);
  //shape(s, 0,0);
  popMatrix();
}

here is the object: https://drive.google.com/open?id=0B3ddDpsAjuqPYUR6RHd0OFBfVU0

2

2 Answers

1
votes

Take out this line of code:

shapeMode(CENTER);

For some reason, this line of code is causing the offset you're seeing. I'm not sure exactly why this causes the offset, but getting rid of it seems to fix your problem.

There is a good simple example of loading and displaying a 3d shape in the examples that come with the Processing editor. Just go to File > Examples and then go to Basics > Shape > LoadDisplayOBJ.

0
votes

Kevin is right, part of the problem is shapeMode(CENTER). Additionally you may want to double check if the mesh is centered in your editor. I've imported your mesh in Blender, and although there is a difference in scale, the origin of your geometry was not at 0,0,0

Here's a tweaked version of your .obj and .mtl exported from Blender after manually translating the mesh so it's closer to the center:

PShape s;
float theta = 0;

void setup() {
  size(500, 500, P3D);
  s = loadShape("coral.obj");
}

void draw() {
  background(32);
  lights();
  float z = 0;
  pushMatrix();
  translate(width * .5,height* .5);
  rotateY(theta);
  theta += .01;
  scale(50.0);
  shape(s, 0,0);
  popMatrix();
}

centred .obj

Additionally you can manually compute the mesh bounding box and centroid to orbit around that position, or look a library that provides this functionality.