Thank you guys. But it seems that calling scale(-1, 1, 1)
before lights()
does not solve the issue. The code by glv still depends on the additional directionalLight
.
Actually, what I originally wanted to do was to mirror flip an object, not the axis (sorry the topic title was eventually incorrect). In the following example, I have a half teapot object as a PShape. I want to show the other half together in the same scene. As you can see by switching the camera position, the half made by scale(-1, 1, 1)
appears as if it’s under a different lighting environment. I understood that this is caused because surface normals are flipped as you suggested.
Adding another directional light makes the normal flipped surfaces visible. But it also affects the rendering of the original half, so I’d like to avoid it.
So the corrected question would be: What is the correct way to make a mirror flipped object from a PShape and show it in the same scene? The teapot is just an example here. I know I can get a model of the whole teapot.
// curl -OL https://www.dropbox.com/s/u46rapjoqrf32xk/half_teapot.obj
PShape model;
boolean add_opposite_directional_light = false;
int camera_pos = 0;
void setup() {
size(1024, 768, P3D);
model = loadShape("half_teapot.obj");
model.scale(2000);
}
void draw() {
background(0);
lights();
if (add_opposite_directional_light) {
directionalLight(128, 128, 128, 0, 0, 1);
}
translate(width/2, height/2);
switch(camera_pos) {
case 0:
camera(0, -height/5, height, 0, 0, 0, 0, 1, 0);
break;
case 1:
camera(height, -height/5, height, 0, 0, 0, 0, 1, 0);
break;
case 2:
camera(height, -height/5, -height, 0, 0, 0, 0, 1, 0);
break;
}
push();
stroke(#ff0000);
line(0, 0, 0, 200, 0, 0);
stroke(#00ff00);
line(0, 0, 0, 0, 200, 0);
stroke(#0000ff);
line(0, 0, 0, 0, 0, 200);
stroke(#999999);
pop();
push();
translate(-200, 0, 0);
// draw left half
rotateY(PI);
rotateX(PI/2);
shape(model);
pop();
push();
translate(200, 0, 0);
// draw right half
scale(1, 1, -1);
rotateY(PI);
rotateX(PI/2);
shape(model);
pop();
}
void keyPressed() {
switch (key) {
case 'l':
add_opposite_directional_light = !add_opposite_directional_light;
break;
case 'c':
camera_pos = (camera_pos + 1) % 3;
break;
}
}