Draw 3D tubes

Hello,

I am looking for some help to draw a bunch of 3D tubes with curvatures.

Basically, for each tube I have a set of 3D points (x,y,z) that I want to connect over z, and then generate a tube by giving a certain radius r.

Since I am a newbie in openFrameworks, I have no idea where to start from. I already tried to draw 3D spheres one after the other (and very close to each other), but when I enable light and material, the light reflects on each sphere separately and the discontinuities are highlighted.

Is there any solution to this?

Check out this older post:
http://forum.openframeworks.cc/t/render-worm-body-tube/3383/0

Awesome! Good starting point.

Thanks a lot.

I managed to draw something, but by using a slightly different approach.

When I apply ofLight and ofMaterial, basically not much happens. I do not obtain any reflection. Everything looks flat. Is there something I am missing?

My goal is to obtain a nice metal reflection, so that I can see the depth.

You probably have to add normals to your mesh. Try adding an ofSphere() in there to see if the lighting is working.

Yes the sphere does have reflection.

But I have no clue how to add normals. Is it hard job?

You should be able to get the normal by subtracting the base pos on the spline from the vertex. The order of the subtraction might need to be reversed.

  
ofVec3f normal = (cur + pos) - pos;  
normal.normalize();  
mesh.addNormal( normal );  

Amazing! It works! Many thanks for the help.

Just one thing. Is there a tutorial/book/something I can use to learn these things. I can’t keep on asking basic stuff on forums. The tutorials and examples available on the website are not enough.

You can purchase some computer graphics books, but the topic is vast and there are many options and the techniques constantly change. I learn the most by looking at examples by other people who put it up on github. :slight_smile:

Or by digging through the core of OF.

Well! I played a bit with the lights and they work fine except for a little strange thing.

The orientation defined in setup()

  
  
light.setOrientation( ofVec3f(0,90,-45) );  
  

is different to that defined during run time

  
  
case 'l':  
bLight = !bLight;  
if (bLight) light.setOrientation( ofVec3f(0,90,-45) );  
else light.setOrientation( ofVec3f(90,0,-45) );  
break;  
  

Basically, when I run the code, the light comes from the top-right. As soon as I press “l”, it swaps between bottom-left to bottom-right. Why does this:

  
  
light.setOrientation( ofVec3f(0,90,-45) );  
  

behave different from this?

  
  
if (bLight) light.setOrientation( ofVec3f(0,90,-45) );  
  

Maybe try printout out what you are setting the orientation to after you set it, to make sure the bool is what you think it is.

  
bLight = !bLight;    
if (bLight) light.setOrientation( ofVec3f(0,90,-45) );    
else light.setOrientation( ofVec3f(90,0,-45) );   
cout << light.getOrientationEuler() << endl;  
  

hey, how did you draw these? any code