Applying a texture to a .obj shape in P3D

Hello,
I am trying to load in a model with a texture in processing. I managed to load in the shape itself, but even after applying a texture to it the model is just fully black.

I followed the setTexture() example with the globe but it doesn’t seem to work for me.

Here is how the code looks like:

PShape well;
PImage img;

void setup() {
  size(800, 800, P3D);
  lights();
  well = loadShape("Well.obj");
  img = loadImage("wellTexture.png");
  
}

void draw() {
  background(255);
  well.setTexture(img);
  textureMode(NORMAL);
}

Don’t you need shape(well); ?

I figured I’d only include the lines related to the textures but this is how it’s drawn

  pushMatrix();
  translate(width/2, height/2+150, 0);
  rotateX(PI+PI/8);
  rotateY(z);
  scale(100);
  stroke(255);
  shape(well, 0, 0);
  popMatrix();

This belongs in setup ()

lights () command must be at beginning of draw()
after background ()

Hello @Sayoregg

Example here:

:)

The following code runs without error on my system (I used an old .obj file from another project):

PShape well;
PImage img;

float z;

void setup() {
  size(800, 600, P3D);
  well = loadShape("well.obj");
  img = loadImage("well.png");
}

void draw() {
  background(255);
  lights();
  well.setTexture(img);
  translate(width/2, height/2 + 100, 0);
  rotateX(PI+PI/8);
  rotateY(z);
  scale(10);
  stroke(255);
  shape(well, 0, 0);
  z += 0.02;
}

Make sure that you enclose the .obj and .png files in a ‘data’ folder inside of your sketch folder.

Output: