# Problem with .obj file (scale shape)

**URL:** <https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390>\
**Category:** Coding Questions\
**Created:** [December 4, 2023, 4:36pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390 "2023-12-04T16:36:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philippe1](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@Philippe1](https://discourse.processing.org/u/Philippe1)\
**Post date:** [December 4, 2023, 4:36pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/1 "2023-12-04T16:36:57Z")

</div>

Hello,  
Returning to Processing, which I haven’t used for several years, I have a problem importing a 3D shape made in Blender and saved as an .obj file.  
the image I get is in 2D.  
if I test the file with viewer Windows it is indeed in 3D and I can make it run on its own  
What can be the problem?  
thanks in advance

 ![image BLENDER](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/d/bddf21049bf8d8791e3452d7092b114b664b0087.jpeg)

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [December 4, 2023, 4:55pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/2 "2023-12-04T16:55:06Z")

</div>

Hi @Philippe1 ,

Would you please show your code, otherwise we only could guessing what’s wrong ?

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![Philippe1](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@Philippe1](https://discourse.processing.org/u/Philippe1)\
**Post date:** [December 4, 2023, 5:20pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/3 "2023-12-04T17:20:39Z")

</div>

PShape ball;

void setup(){  
size (500,500,P3D);  
ball = loadShape(“Ball.obj”);  
}

void draw(){  
background(20);  
pushMatrix();  
translate(width/2, height/2);  
shape(ball, 200, 200, 300,300);  
popMatrix();  
}

---

<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 4, 2023, 10:37pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/4 "2023-12-04T22:37:58Z")

</div>

Try adding lights, texture, and rotation.

---

<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 5, 2023, 6:10am UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/5 "2023-12-05T06:10:10Z")

</div>

Hello @Philippe1 ,

> [@Philippe1](#):
>
> shape(ball, 200, 200, 300,300);

This will only resize the width (x) and height (y).

You need to scale the x, y and z:

`ball.scale(100, 100, 100); //scale the x, y and z`

Example using the default cube in Blender:

```auto
void setup() 
  {
  size (500, 500, P3D);
  ball = loadShape("untitled.obj");
  ball.scale(100, 100, 100); //scale the x, y and z of the shape
  }

void draw() 
  {
  background(20);
  lights();
  translate(width/2, height/2);
  rotateY(frameCount*(TAU/360));
  shape(ball, 0, 0);
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/0/8/082b397e499ae2e9bc96f1890d6a2047f561666b.png)

Reference:

> **[shape() / Reference](https://processing.org/reference/shape_.html)**
>
> Draws shapes to the display window. Shapes must be in the sketch's "data" directory to load correctly. Select "Add file..." from the "Sketch" menu to add the shape. Processing currently works with SVG…

Another example:

> [@Rotate a PShape](https://discourse.processing.org/t/rotate-a-pshape/32859/3):
>
> Hello, Example: PShape obj; void setup() { size(500, 500, P3D); smooth(); background(0); obj = loadShape("rocket.obj"); obj.rotateZ(TAU/2); obj.translate(0, 100, 0); obj.scale(.8, .8, .8); } void draw() { background(0); translate(width/2, height/2); //pushMatrix(); // This: //rotateY(frameCount\*TAU/360); // Or this: obj.rotateY(TAU/360); shape(obj); //popMatrix(); } You can find the rocket here: [image] And here: [https://github.com/proc…](https://github.com/processing/processing-docs/tree/master/content/examples/Basics/Shape/LoadDisplayOBJ/data)

`:)`

---

<div class="post-metadata">

**Author:** ![Philippe1](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@Philippe1](https://discourse.processing.org/u/Philippe1)\
**Post date:** [December 6, 2023, 2:54pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/6 "2023-12-06T14:54:10Z")

</div>

Thanks for the “scale” indication, I didn’t understand how to use it in 3D. It works perfectly.  
Now, I would like to make my object grow over time.  
In the setup I put “x,y,z” variables and I thought I would increment them like for my rotation variables.  
The scale being in the setup this is not possible.  
So I put the scale in the draw it doesn’t work. How to do it, I can’t find the solution.  
Here is my code.

PShape ball;  
float a=0;  
float b=0;  
float x=8;  
float y=8;  
float z=8;  
float tx=2;  
float tz=2;

void setup(){  
size (500,500,P3D);  
ball = loadShape(“Ball.obj”);  
ball.scale(x,y,z);  
}

void draw(){  
background(20);  
lights();  
translate(width/tx, height/tz);  
a +=0.001;  
b +=0.002;  
tx -=0.0008;  
tz -=0.0005;  
rotateY(a);  
rotateZ(b);  
shape(ball, 0, 0);  
}

---

<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:** [December 6, 2023, 4:09pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/7 "2023-12-06T16:09:46Z")

</div>

> [@Philippe1](#):
>
> ball.scale(x,y,z);

This belongs into draw

Then say x+=0.01; and for the other two as well

y and z

---

<div class="post-metadata">

**Author:** ![Philippe1](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@Philippe1](https://discourse.processing.org/u/Philippe1)\
**Post date:** [December 6, 2023, 5:35pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/8 "2023-12-06T17:35:10Z")

</div>

precisely if I put “ball.scale(x,y,z)”, my object is not displayed. I only have the black background.

---

<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:** [December 6, 2023, 8:12pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/9 "2023-12-06T20:12:08Z")

</div>

Maybe it’s getting bigger too fast

Try smaller initial values and smaller adding

(Edit: ok, `ball.scale(x,y,z);` changes the ball matrix, so my idea `x+=0.01;` in draw() is wrong; instead define `float x=0.01;` before setup() to make for a slow growing - or see better answer below)

---

<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 7, 2023, 12:05am UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/10 "2023-12-07T00:05:38Z")

</div>

Hello @Philippe1,

This can be challenging so providing a working example:

```auto
PShape cube;
float x = 1;

void setup() 
  {
  size (500, 500, P3D);
  cube = loadShape("cube.obj");
  println(cube.getWidth(), cube.getHeight(), cube.getDepth()); // 2x2x2 for cube
  delay(1000);
  }

void draw() 
  {
  background(0);
  lights();
  translate(width/2, height/2, -100);
  rotateX(PI/4);
  rotateY(PI/4);
  cube.resetMatrix(); // cube is now back to original size
  if (x>100) x = 1;
  println(x);
  cube.scale(x);
  x=x+0.25;
  println(cube.getWidth(), cube.getHeight(), cube.getDepth());
  cube.setFill(color(255, 255, 0));
  shape(cube);
  }

```

cube.obj:

```auto
# Blender v3.4.1 OBJ File: ''
# www.blender.org
# mtllib untitled.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.125000 0.750000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1/1/1 5/2/1 7/3/1 3/4/1
f 4/5/2 3/4/2 7/6/2 8/7/2
f 8/8/3 7/9/3 5/10/3 6/11/3
f 6/12/4 2/13/4 4/5/4 8/14/4
f 2/13/5 1/1/5 3/4/5 4/5/5
f 6/11/6 5/10/6 1/1/6 2/13/6

```

I am scaling equally for each axis so _scale(x, y, x)_ can be _scale(s)_ where `s=x=y=z`.

The size of the shape with each cycle of draw will keep scaling (multiplying) the last size and will increase exponentially.

_cube.resetMatrix()_ restores original size of shape and gives you some control over scaling with each cycle of _draw()._

Try removing/commenting _cube.resetMatrix()_ and see what happens!

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

Have fun!

`:)`

---

<div class="post-metadata">

**Author:** ![Philippe1](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@Philippe1](https://discourse.processing.org/u/Philippe1)\
**Post date:** [December 7, 2023, 5:49pm UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/11 "2023-12-07T17:49:17Z")

</div>

Thank you glv  
indeed it works, just need two clarifications.  
why the “delay” in the setep and why in the draw the line “if (x\>100) x = 1”  
On the other hand, how can I map my object with a jpg image?  
than you

---

<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 8, 2023, 11:10am UTC](https://discourse.processing.org/t/problem-with-obj-file-scale-shape/43390/12 "2023-12-08T11:10:30Z")

</div>

Hello @Philippe1,

> [@Philippe1](#):
>
> why the “delay” in the setep and why in the draw the line “if (x\>100) x = 1”

Experiment with by _commenting out code_ to see what happens.  
You should also look up the references to understand what it does.

> [@Philippe1](#):
>
> On the other hand, how can I map my object with a jpg image?

Explore the resources and experiment away!

PShape tutorial:

> **[PShape](https://processing.org/tutorials/pshape/)**
>
> How to use the PShape class in Processing.

References:

> **[PShape / Reference](https://processing.org/reference/PShape.html)**
>
> Datatype for storing shapes. Before a shape is used, it must be loaded with the loadShape() or created with the createShape(). The shape() function is used to draw the shape to th…

`:)`
