We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I've created a rotating 3D pyramid as a createShape(GROUP) and applied a texture to each side but they display as a solid color instead of the image. The code seems to be correct in comparison to working examples online but I must have something wrong. Any assistance is greatly appreciated.
PImage img;
PShape pyramid,side1,side2,side3,side4,base;
void setup()
{
size(940, 540, P3D);
colorMode(HSB);
background(0);
textureMode(NORMAL);
img = loadImage("galaxy.jpg");
pyramid = createShape(GROUP);
side1 = createShape();
side1.setTexture(img);
side1.beginShape();
side1.vertex(-100, -100, -100);
side1.vertex( 100, -100, -100);
side1.vertex( 0, 0, 100);
side1.endShape(CLOSE);
side2 = createShape();
side2.setTexture(img);
side2.beginShape();
side2.vertex( 100, -100, -100);
side2.vertex( 100, 100, -100);
side2.vertex( 0, 0, 100);
side2.endShape(CLOSE);
side3 = createShape();
side3.setTexture(img);
side3.beginShape();
side3.vertex( 100, 100, -100);
side3.vertex(-100, 100, -100);
side3.vertex( 0, 0, 100);
side3.endShape(CLOSE);
side4 = createShape();
side4.setTexture(img);
side4.beginShape();
side4.vertex(-100, 100, -100);
side4.vertex(-100, -100, -100);
side4.vertex( 0, 0, 100);
side4.endShape(CLOSE);
base = createShape();
base.setTexture(img);
base.beginShape();
base.vertex(-100,-100,-100);
base.vertex(100,-100,-100);
base.vertex(100,100,-100);
base.vertex(-100,100,-100);
base.endShape(CLOSE);
pyramid.addChild(side1);
pyramid.addChild(side2);
pyramid.addChild(side3);
pyramid.addChild(side4);
pyramid.addChild(base);
}
void draw()
{
background(0);
noStroke();
translate(width/2, height/2, 150);
rotateX(speedMod*(frameCount*PI/200));
shape(pyramid);
}
}
Answers
Brainstorming --
You aren't using any texture coords in your vertex calls, I think you need the 5 argument version.
For texture() you need u v coords but for PShapes you're supposed to be able to use setTexture without them. It's the main reason I did them as PShapes. I'll see if I can get it working with texture()
@CodeSloth
Try this
Kf
Citation needed...