# STL 3D Model exported into OBJ file

**URL:** <https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293>\
**Category:** Coding Questions\
**Created:** [December 25, 2022, 3:24am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293 "2022-12-25T03:24:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 3:24am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/1 "2022-12-25T03:24:34Z")

</div>

Today I exported a .STL 3D model in blender to an .OBJ file. When I loaded the model into Processing.js it was black. I added lighting but it didn’t illuminate the model. Is there an alternative file to export that is better? What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 3:25am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/2 "2022-12-25T03:25:45Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/f/ef0bd4811580ddfd1df8d7042420ddf919cdfbbb.jpeg)

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [December 25, 2022, 3:50am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/3 "2022-12-25T03:50:47Z")

</div>

Pretty sure you need to export a material aswell, havent played much with 3d models and processing but i do remember the same issue when i did

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 4:28am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/4 "2022-12-25T04:28:49Z")

</div>

How do I export a material as well?

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [December 25, 2022, 4:50am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/5 "2022-12-25T04:50:30Z")

</div>

The option should be in blender, think its on by default so you should see it in the folder you exported the .obj file to, if not check the blender export window, on the right side scroll down until you see material options, if that is already on and you dont see a material in the folder you probably have to add a material in blender before exporting

---

<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:** [December 25, 2022, 6:08am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/6 "2022-12-25T06:08:15Z")

</div>

This forum thread may or may not be helpful:[https://discourse.processing.org/t/loadshape-cannot-find-obj-file-in-data-folder/37745/4](https://discourse.processing.org/t/loadshape-cannot-find-obj-file-in-data-folder/37745/4) . Also there is an example in _File/Examples/Basics/Shape/LoadDisplayOBJ_. Look in the data folder of this project and you will see the other files that are required:

![dataFolder](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/1/a/1aa3f16701c562e830236d05ab0937ff504b03e7.png)

**Path to examples on my system** :

 ![path](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/d/5d113a05320e986e5497dd3ac03c8f908fd3c247.png)

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [December 25, 2022, 9:28am UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/7 "2022-12-25T09:28:55Z")

</div>

Did you manage to get it working?

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 5:48pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/8 "2022-12-25T17:48:25Z")

</div>

I’m going to give your suggestion a try today! I’ll let you know if it works, @Mikey83 ! Thank you! Happy Holidays!

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 6:12pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/9 "2022-12-25T18:12:36Z")

</div>

I was able to add a material when exporting as well as the .mtl file to my sketch, but the model is still black…

```auto
PShape mobius;
PImage txtr;
float theta;

void setup(){
  size(1000,1000,P3D);
  txtr = loadImage("grid3.jpg");
  mobius = loadShape("ring.obj");
  mobius.setTexture(txtr);
}

void draw() {
  background(txtr);
  
  pushMatrix();
  translate(width/2, height/2);
  shininess(5.0); 
  lights();
  rotateY(mouseY);
  rotateX(mouseX);
  //rotateZ(theta/2);
  scale(90);
  shape(mobius);
  popMatrix();
  
  theta+=.01;
  
}

```

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 6:13pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/10 "2022-12-25T18:13:41Z")

</div>

![Screen Shot 2022-12-25 at 10.13.13 AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/f/0/f0879163430cbae877c4052f68f8bd3e4c4dbe9c.jpeg)

What am I doing wrong?

---

<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:** [December 25, 2022, 6:21pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/11 "2022-12-25T18:21:50Z")

</div>

Where’s the texture? It has to have a .png or some graphic to stick on your object and the .mtl file has to call for it.

Is that obj file that you downloaded free? If you don’t have an objection would you post the url so that others can try? It would also be nice to see the code in the .mtl file; it’s just a txt file if you haven’t looked inside yet.

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 7:03pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/12 "2022-12-25T19:03:31Z")

</div>

Yes, the 3d model is from Thingiverse! How do I upload the 3d model to this discussion?

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 7:09pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/13 "2022-12-25T19:09:54Z")

</div>

The grid .jpg files are the texture. Can I not use the .jpg’s for texture?

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 7:10pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/14 "2022-12-25T19:10:45Z")

</div>

I am open to sharing a link, but the only thing is that I may not be able to find it again! Let me try to find it…

---

<div class="post-metadata">

**Author:** ![asymmetric](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/asymmetric/32/16577_2.png) [@asymmetric](https://discourse.processing.org/u/asymmetric)\
**Post date:** [December 25, 2022, 7:12pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/15 "2022-12-25T19:12:36Z")

</div>

The model has been deleted by the creator, but I can email you my files?

---

<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:** [December 25, 2022, 7:25pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/16 "2022-12-25T19:25:05Z")

</div>

`Can I not use the .jpg’s for texture`

Likely can but the .mtl file has to have it listed as a source. The original object should have had an accompanying graphic file ideally.

---

<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:** [December 25, 2022, 7:28pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/17 "2022-12-25T19:28:50Z")

</div>

I just downloaded a turtle object from Thingiverse and there is a .png file but no .mtl file. Where did you get the .mtl file for your project?

We need to see both the .obj file and the .mtl files. They may both be opened with TextEdit on a Mac. Copy/paste the code here so we can see the contents of each. Usually the .obj file lists the name of the .mtl file on the first line, eg _mtllib something.mtl_ and the .mtl file lists the graphic file to be used. It works best if all three files, ie .mtl, .obj, and .png files are downloaded together. I did find that it is possible in some cases to add a custom .png if one is not included (some .pngs couldn’t be added). Sometimes it was possible to modify the _File/Examples/Basics/Shape/LoadDisplayOBJ_ .mtl file and use it if one was not included with the .obj download, but it didn’t always work.

---

<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:** [December 26, 2022, 1:31pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/18 "2022-12-26T13:31:19Z")

</div>

Hello @asymmetric,

I was able to import an STL with Blender and export it to an OBJ with UVs and texture it in Processing as follows:

Steps:

- OS and Software:  
Windows 10 Pro  
Processing 4.1.1  
Blender 3.3.2 LTS

- _Mobius.stl_ from:  
[Mobius Surface by qvist - Thingiverse](https://www.thingiverse.com/thing:238498)

- Open Blender and import _Mobius.stl_

- Change from _Object Mode_ to _Edit Mode_

- Select _UV \> Cube Projection_ (you can try other selections later)

- Export _Wavefront (.obj)_ to any name of your choosing.

- ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/5/c505cff091398587c7c34e4cb02223ac2d8417fe.png)

- Add files to your Processing sketch

- Processing code:

```auto
// Texture
mobius = loadShape("untitled_cube.obj"); 
txt = loadImage("frog.png"); // Add your own image here
mobius.setTexture(txt);

```

```auto
// Fill with color
mobius = loadShape("untitled_cube.obj");
mobius.setFill(color(255, 255, 0));

```

And voila!

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/f/6f68c18d0ef0a8f90c0b11ee047e6ae81c07ccf6.jpeg)

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

There is a bit of a learning curve to all of this.  
Enjoy the journey!

References:

> <https://github.com/processing/processing/issues/4378>
>
> A texture cannot be applied to PShapes created by loading a \*.obj file. SetTextu…re() does work for shapes created by other means, however. Here is some example code, where I load in a model, and create a sphere, and apply the same texture to both. In this case, only the sphere has a texture.
> 
> \`\`\`
> PShape model;
> PShape globey;
> PImage pizza;
> 
> void setup() {
> size(500, 500, P3D);
> pizza = loadImage("pizza.jpg"); // load the texture
> model = loadShape("mammoth.obj");
> model.setTexture(pizza); //this does not work, the model is just black
> globey = createShape(SPHERE, 1000);
> globey.setTexture(pizza); //this DOES work. The sphere has a texture from pizza.jpg
> globey.setStroke(false);
> }
> 
> void draw() {
> lights();
> directionalLight(51, 102, 126, -1, 0, 0);
> directionalLight(255, 0, 100, 1, 0, 0);
> scale(.1);
> shape(globey);
> shape(model);
> }
> \`\`\`
> 
> !\[image\](https://cloud.githubusercontent.com/assets/6827480/14128140/15aae202-f5ec-11e5-89b7-7044ad1729b0.png)

> [@asymmetric](#):
>
> Processing.js

If this is a Processing.js issue I can’t help with that.

See comments here about Processing.js:

> **[Processing.js](https://happycoding.io/tutorials/processing/processing-js)**
>
> Embed your sketch in a webpage.

> **[GitHub - processing-js/processing-js: A port of the Processing visualization...](https://github.com/processing-js/processing-js)**
>
> A port of the Processing visualization language to JavaScript. - GitHub - processing-js/processing-js: A port of the Processing visualization language to JavaScript.

`:)`

---

<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:** [December 26, 2022, 3:23pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/19 "2022-12-26T15:23:31Z")

</div>

Is Blender freeware?

---

<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:** [December 26, 2022, 3:28pm UTC](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293/20 "2022-12-26T15:28:40Z")

</div>

> **[License — blender.org](https://www.blender.org/about/license/)**
>
> Home of the Blender project - Free and Open 3D Creation Software

`:)`

[Next page](https://discourse.processing.org/t/stl-3d-model-exported-into-obj-file/40293.md?page=2)
