# Applying a texture to a .obj shape in P3D

**URL:** <https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225>\
**Category:** Coding Questions\
**Created:** [November 16, 2023, 2:24pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225 "2023-11-16T14:24:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sayoregg](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@Sayoregg](https://discourse.processing.org/u/Sayoregg)\
**Post date:** [November 16, 2023, 2:24pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225/1 "2023-11-16T14:24:15Z")

</div>

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:

```auto
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);
}

```

 ![image_2023-11-16_152104938](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/3/339ad148d24447c27774c4630721cddc2968f5ed.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 16, 2023, 2:29pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225/2 "2023-11-16T14:29:57Z")

</div>

Don’t you need shape(well); ?

---

<div class="post-metadata">

**Author:** ![Sayoregg](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@Sayoregg](https://discourse.processing.org/u/Sayoregg)\
**Post date:** [November 16, 2023, 2:34pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225/3 "2023-11-16T14:34:45Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 16, 2023, 2:51pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225/4 "2023-11-16T14:51:50Z")

</div>

> [@Sayoregg](#):
>
> ```auto
> well.setTexture(img);
> textureMode(NORMAL);
> 
> ```

This belongs in setup ()

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [November 16, 2023, 3:04pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225/5 "2023-11-16T15:04:12Z")

</div>

Hello @Sayoregg

Example here:

> [@STL 3D Model exported into OBJ file](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/25):
>
> Works fine with Processing 4.1.1: Be careful with names… I used txt and you had txtr in your examples. It may be as simple as that… scrutinize your code. moebius.obj data to copy to moebius.obj file : 
> 
> > **Click to Open!**
> >
> > # Blender 3.3.2 # www.blender.org o moebius v 0.121339 -10.000000 -4.125570 v 0.121337 -10.000000 -24.125566 v 7.972092 -9.224739 -23.661596 v 2.093474 -10.719337 -4.603580 v 15.496721 -8.397884 -20.761618 v 4.356159 -11.378731 -4.421417 v 21.926605 -7.524071 -15.59919…

`:)`

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [November 16, 2023, 5:06pm UTC](https://discourse.processing.org/t/applying-a-texture-to-a-obj-shape-in-p3d/43225/6 "2023-11-16T17:06:44Z")

</div>

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

```auto
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:**

 ![texture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/a/ea51607fffa8bd3a48fc37ab114411d0746a0298.png)
