We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Textures onto 3D bezier and box/sphere primitives
Page Index Toggle Pages: 1
Textures onto 3D bezier and box/sphere primitives (Read 1524 times)
Textures onto 3D bezier and box/sphere primitives
Mar 3rd, 2009, 12:51pm
 
Hi All

I wonder if someone could help?
I wanted to map a jpg texture onto a version I have made of Ira Greenbergs flapping bird sketch (the one in the Processing examples).
I don't seem to be able to do it! Here is the code, can anyone help? I wanted to put a texture onto the box, another texture onto the larger sphere, and a texture on the bezier wings. I will make the two small sphere eyes a single colour.
Thanks!

Quote:
/**
* 3D Moth Creature
* by Will Pearson, grateful thanks to orignal sketch by Ira Greenberg.
*/

PImage img;
float ang = 0, ang2 = 0, ang4 = 0;
float pz = 0;
float flapSpeed = 0.25;
float boxX = 20;
float boxY = 80;
float boxZ = 30;

void setup(){
 size(640, 360, P3D);
 img = loadImage("mothbody.jpg");
 noStroke();
}

void draw(){
 background(0);
 lights();

 // Flight

 pz = sin(radians(ang4)) * 500;
 translate(mouseX, mouseY, -500+pz);
 rotateX(sin(radians(ang2)) * 120);
 rotateY(sin(radians(ang2)) * 50);
 rotateZ(sin(radians(ang2)) * 65);
 
 // Body
 beginShape();
 
  box(boxX, boxY, boxZ);
  endShape();

 // Left wing
 fill(204);
 pushMatrix();
 rotateY(sin(radians(ang)) * -20);
 beginShape();
 texture(img);
 bezier(boxX-20, boxY-20, boxZ-20, 80, -90, -75, -10, 60, -75, 100, 50, -20);
 endShape();
 
 //rect(-75, -50, 75, 100);
 popMatrix();

 // Right wing
 pushMatrix();
 rotateY(sin(radians(ang)) * 20);
 beginShape();
 texture(img);
 bezier(boxX-20, boxY-20, boxZ-20, 80, -90, 75, -10, 60, 75, 100, 50, 20);
 endShape();
 popMatrix();
 
 //head
 pushMatrix();
 translate(boxX-20, boxY-20, 0);
 sphere(22);
 popMatrix();
 
 //eyes
 pushMatrix();
 translate(boxX-20, boxY-2, 8);
 sphere(8);
 popMatrix();
 
 pushMatrix();
 translate(boxX-20, boxY-2, -8);
 sphere(8);
 popMatrix();
 
 // Wing flap
 ang += flapSpeed;
 if (ang > 3) {
   flapSpeed *= -1;
 }
 if (ang < -3) {
   flapSpeed *= -1;
 }

 // Increment angles
 ang2 += 0.01;
 ang4 += 0.75;
}
Re: Textures onto 3D bezier and box/sphere primiti
Reply #1 - Mar 5th, 2009, 4:40am
 
Two things:

1) bezier() already has its own beginShape() and endShape() pair, so there's no way to muscle in your texture().

2) bezier() ultimately calls bezierVertex(), which has no means of specifying texture u,v coordinates. You could either write your own version of bezierVertex (totally doable), or (here comes an ad) you could try my Patchy library, which does textured bicubic patches (including Bezier).
Re: Textures onto 3D bezier and box/sphere primiti
Reply #2 - Mar 5th, 2009, 1:42pm
 
Hi Jonathan,
That's ace help, thanks a lot, I will try Patchy,
best regards
Will
sevenspiral
Page Index Toggle Pages: 1