lights and Shapes3D library

GLVGLV
edited November 2017 in Library Questions

lights() adds light to the opposite side expected on the tubes I create with shapes3D. The box and sphere have the expected light.

If I add scale(-1, 1, 1); to the tubes, the light appears correct except for the end caps (you must observe each end cap to see this).

Can someone please help with this? @quark

lagers.org.uk/s3d4p/index.html

// Requires the Shapes3D library.

import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;

Tube tube02;
Tube tube01;

float angleX, angleY, angleZ;

void setup() 
  {
  size(1000, 1000, P3D);

  tube01 = new Tube(this, 4, 50);
  tube01.setSize(50, 50, 50, 50, 400);
  tube01.fill(color(255, 255, 0));
//  tube01.fill(#FFFF00, S3D.BOTH_CAP);
  tube01.drawMode(S3D.SOLID);
  tube01.visible(false, S3D.BOTH_CAP);

  tube02 = new Tube(this, 4, 50);
  tube02.setSize(50, 50, 50, 50, 400);
  tube02.fill(color(255, 255, 0));
  tube02.fill(#FFFF00, S3D.BOTH_CAP);
  tube02.drawMode(S3D.SOLID);
  tube02.visible(true, S3D.BOTH_CAP);
  }

void draw() 
  {
  background(0);    
  //  scale(1, 1, 1);
  translate(width/2, height/2);
  //  lights();
  ambientLight(128, 128, 128);                  //default
  //  directionalLight(128, 128, 128, 0, 0, -1);    //default
  directionalLight(128, 128, 128, -1, 0, 0);    //custom
  lightFalloff(1, 0, 0);                        //default 
  lightSpecular(0, 0, 0);                       //default

//  translate(width/2, height/2);

  pushMatrix();  
  noStroke();
  strokeWeight(0);
  fill(color(255, 255, 0));
  angleX += PI/1000;
  angleY += PI/1000;
  angleZ += PI/1000;
  rotateX(angleX);
  rotateY(angleY);
  rotateZ(angleZ);

  pushMatrix();
  translate(-300,0, 0);
  fill(255, 255, 0);
  sphere(50); 
  popMatrix();

  pushMatrix();
  translate(300, 0, 0);
  fill(255, 255, 0);
  box(100, 400, 100);  
  popMatrix();

  pushMatrix();
  translate(100, 0, 0);
//  scale(-1, 1, 1);
  tube01.draw();
  popMatrix();

  pushMatrix();
  translate(-100, 0, 0);
//  scale(-1, 1, 1);
  tube02.draw();
  popMatrix(); 
  popMatrix();
  } 

Answers

  • Answer ✓

    In your sketch you are using the Tube class from Shapes3D to create 2 tubes and then using Processing's sphere and box methods to create those shapes.

    I believe the difference in shading is caused because Shapes3D and Processing are calculating the surface normals differently. In Shapes3D calculates all surface normals as if they were pointing out-of-the-shape point and I suspect (but can't be sure) that Processing calculates them as if they were pointing inwards.

    Since the Shapes3D library provides the Ellipsoid and Box classes I suggest you use those instead of Processing's offerings.

    Hope this helps :)

    Final point if you need to get my attention on this forum simply include @quark somewhere in you discussion. You don't need to use the comments page on my website. Using the @ symbol in front of the user name will send a notification email to that member.

  • @quark Thank you! It helps and explains what I was seeing.

  • Your welcome. :)

Sign In or Register to comment.