# Adding an .obj file

**URL:** <https://discourse.processing.org/t/adding-an-obj-file/45069>\
**Category:** Coding Questions\
**Created:** [September 20, 2024, 10:51pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069 "2024-09-20T22:51:39Z")\
**Posts on this page:** 9\
**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:** [September 20, 2024, 10:51pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/1 "2024-09-20T22:51:39Z")

</div>

Hi!

I made an .obj file in blender that I would like to animate via Processing.js but I keep getting the following error:

" at sketch\_3d\_obj\_interlaced\_loops.objAbstractShape(sketch\_3d\_obj\_interlaced\_loops.java:37)  
at sketch\_3d\_obj\_interlaced\_loops.draw(sketch\_3d\_obj\_interlaced\_loops.java:32)  
at processing.core.PApplet.handleDraw(PApplet.java:2094)  
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:840)  
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)  
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)  
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)  
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)  
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)  
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:782)  
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)  
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:453)  
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)  
at java.base/java.util.TimerThread.mainLoop(Timer.java:566)  
at java.base/java.util.TimerThread.run(Timer.java:516)  
The file “dalle\_2.obj” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.  
java.lang.NullPointerException: Cannot invoke “java.io.BufferedReader.readLine()” because “reader” is null  
at processing.core.PShapeOBJ.parseOBJ(PShapeOBJ.java:168)  
at processing.core.PShapeOBJ.(PShapeOBJ.java:40)  
at processing.core.PShapeOBJ.(PShapeOBJ.java:27)  
at processing.opengl.PGraphics3D.loadShapeImpl(PGraphics3D.java:128)  
at processing.opengl.PGraphicsOpenGL.loadShape(PGraphicsOpenGL.java:3383)  
at processing.core.PApplet.loadShape(PApplet.java:10899)  
at  
"

---

<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:** [September 20, 2024, 11:43pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/2 "2024-09-20T23:43:12Z")

</div>

Any way to see the source code which generates this error?

> [@asymmetric](#):
>
> The file “dalle\_2.obj” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

Could have something to do with this.

---

<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:** [September 21, 2024, 8:54pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/3 "2024-09-21T20:54:00Z")

</div>

Hi @svan !

Here is the source code and the file

```auto
PShape obj; // , obj2
PImage txtr;
float theta;

PGraphics canvas;

void setup(){
  size(1000,1000,P3D);
  txtr = loadImage("grid3.jpg");
}

void draw() {
  background(txtr);
  
  objAbstractShape();

void objAbstractShape(){
  obj = loadShape("dalle_2.obj");
  obj.setFill(color(255)); // Brigthens the texture
  obj.setTexture(txtr);
  
  pushMatrix();
  translate(width/2, height/2);
  shininess(5.0); 
  lights();
  rotateY(theta/2); //mouseY or (radians(frameCount));
  rotateX(theta/2); //mouseX or (radians(frameCount));
  rotateZ(theta/2);
  scale(70);
  shape(obj);
  popMatrix();
  
  theta+=.1; //.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:** [September 21, 2024, 9:01pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/4 "2024-09-21T21:01:48Z")

</div>

I’m now receiving the following message:

" The file “/Users/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*r/Desktop/3D Paintings/sketch\_3d\_obj\_/data/dalle\_.mtl” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

---

<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:** [September 21, 2024, 9:03pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/5 "2024-09-21T21:03:52Z")

</div>

![Screenshot 2024-09-21 at 2.03.25 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/5/b5294ba15c383e70374d8ceebfdffb096b2a061c.jpeg)

I have both file types in the folder though…

---

<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:** [September 21, 2024, 9:06pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/6 "2024-09-21T21:06:14Z")

</div>

Hello @asymmetric,

Your function needs to be outside of draw:

```auto
PShape obj;
float theta;

PGraphics canvas;

void setup()  
  {
  size(500, 500,P3D);
  
  // load and scale obj once in setup:
  obj = loadShape("untitled.obj");
  obj.setFill(color(255)); // Brigthens the texture 
  obj.scale(70);
  }

void draw() 
  {
  objAbstractShape();
  }

void objAbstractShape()
  {
  // Your code  
  }

```

The above worked in Processing 4.3 with an OBJ I created with Blender:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/0/7083c1de12ca7b30a9c24a491be285c3f1662f48.png)

---

<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:** [September 21, 2024, 9:09pm UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/7 "2024-09-21T21:09:21Z")

</div>

> [@glv](#):
>
> ```auto
> size(500, 500,P3D);
>   
> // load and scale obj once in setup:
> obj = loadShape("untitled.obj");
> obj.setFill(color(255)); // Brigthens the texture 
> obj.scale(70);
> }
> 
> ```

Thank you, @glv but I don’t understand what you changed? My function needs to be in setup?

---

<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:** [September 22, 2024, 2:07am UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/8 "2024-09-22T02:07:24Z")

</div>

This tutorial will explain where to write the function definition:

[![](https://img.youtube.com/vi/zBo2D3Myo6Q/hqdefault.jpg "7.2: Functions Basics - Processing Tutorial") ](https://www.youtube.com/watch?v=zBo2D3Myo6Q&t=419s)

I encourage you to watch the entire video.

Consider drawing a line between blocks of code (includes functions) to easily see these:

```auto
void setup()  
  {
  }
  
// **************************  

void draw() 
  {
  objAbstractShape();
  }
  
// **************************    

void objAbstractShape()
  {
  // Your code  
  }

```

I use my preferred indentation style to easily see blocks of code:  
_[Indentation style - Wikipedia](https://en.wikipedia.org/wiki/Indentation_style)_

`:)`

---

<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:** [September 22, 2024, 2:10am UTC](https://discourse.processing.org/t/adding-an-obj-file/45069/9 "2024-09-22T02:10:31Z")

</div>

Try loading both the shape and image from setup() with everything else in draw(). For example:

```auto
void setup() {
  size(1000, 1000, P3D);
  obj = loadShape("dalle_2.obj");
  txtr = loadImage("grid3.jpg");
}

```

Personally, I would do away with the objAbstractShape() function and I’m not sure you really need pushMatrix() and popMatrix() unless there is more to your project than is being shown.
