Texture on hexagon

Hallo I am new in this forum and just started with processing. I would like to paint my 3d hexagon with an image (texture). How can I place a texture on a hexagon? The jpg it self is a rectangular format and I would like to show only the painted hexagon area of the jpg on the surface of the 3D shape. (maybe this is not the best way to channge the layout, surface of the 3d shape but comes into my mind watching the processing tutorials. I would like to change later on the picture based on user interface)
Thank you for any help.
The “3D hexagon”:
beginShape();
for(int i=0;i<6;i++){
float angle = i * 2 * PI / 6;
vertex(0 + 300cos(angle),0 + 300sin(angle), -80);
} endShape(CLOSE);
for(int i=0;i<6;i++){
beginShape();
float angle = i * 2 * PI / 6;
vertex(0 + 300cos(angle),0 + 300sin(angle), -80);
vertex(0 + 300cos(angle),0 + 300sin(angle), 80);
angle = (i+1) * 2 * PI / 6;
vertex(0 + 300cos(angle),0 + 300sin(angle), 80);
vertex(0 + 300cos(angle),0 + 300sin(angle), -80);
endShape(CLOSE);
}
beginShape();
for(int i=0;i<6;i++){
float angle = i * 2 * PI / 6;
vertex(0 + 300cos(angle),0 + 300sin(angle), 80);
} endShape(CLOSE);–>

Hey Theodar u can try to use textureMode() in processing to map an image around the surface check out this reference` if u want to know more

I did something similar in the past.
I don’t think texture works on hexagon shape.
You have maybe to split your hexagon in 6 triangles, cut your texture. And apply it with something like :
textureMode(NORMAL); texture(img); vertex(10, 20, 0, 0.5);

just to note that vertex can take up to 5 arguments, and the last 2 are for the uv coordinates on the texture:
https://processing.org/reference/vertex_.html

Since there’s no complete code I’m lazy to try it on my own (and please use </> button to format the code), but as @matheplica says I’m not sure if the tessellation works in this case (maybe it does). If the mapped image is distorted, you can start the beginShape in TRIANGLE_FAN mode starting with the center and this would generate nice triangles I suppose:
https://processing.org/reference/beginShape_.html

1 Like