# loadShape() Displaying my .obj file flat rather than as a 3D model? Any help?

**URL:** <https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [May 3, 2021, 7:56pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824 "2021-05-03T19:56:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chubbulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chubbulus/32/13049_2.png) [@Chubbulus](https://discourse.processing.org/u/Chubbulus)\
**Post date:** [May 3, 2021, 7:56pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/1 "2021-05-03T19:56:50Z")

</div>

Hi. I’m new to Processing, having to use it for some University work. My current coursework required me to render in a 3D Model with Processing, but when I use loadShape() and add shape(modelname, integer, integer, integer, integer) to my code, the result is a flattened version of my model and none of the integers really seem to help this? Is there a way to fix this issue?

Oh, I’m also using this in conjunction with PeasyCam interactive camera. Could that be causing issues?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7bec5d368a451513ce6c27bc729313db80e19712.png)

---

<div class="post-metadata">

**Author:** ![Chubbulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chubbulus/32/13049_2.png) [@Chubbulus](https://discourse.processing.org/u/Chubbulus)\
**Post date:** [May 3, 2021, 8:06pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/2 "2021-05-03T20:06:01Z")

</div>

For anyone wondering, I made the model in Blender and exported it as a .obj file

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

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [May 3, 2021, 8:08pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/3 "2021-05-03T20:08:37Z")

</div>

Hi! Welcome to the forum!

First, show us the code 🙂 And what happens if you use shape function with only one argument (model) or with three (model, x, y) ?

---

<div class="post-metadata">

**Author:** ![Chubbulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chubbulus/32/13049_2.png) [@Chubbulus](https://discourse.processing.org/u/Chubbulus)\
**Post date:** [May 3, 2021, 8:11pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/4 "2021-05-03T20:11:55Z")

</div>

Hi,  
Using the shape function with only 1 or 3 arguments leads to the model simply not displaying at all.

This is the code that performs the current actions and leaves the model flat. I seem to only be able to control the position with the first 2 integer arguments and then the width and length with the last 2?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/088688a2e6691966b4f9fdba2244efb09aaa5818.png)

---

<div class="post-metadata">

**Author:** ![Chubbulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chubbulus/32/13049_2.png) [@Chubbulus](https://discourse.processing.org/u/Chubbulus)\
**Post date:** [May 3, 2021, 8:19pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/5 "2021-05-03T20:19:42Z")

</div>

Also, as can be seen here, the model is still very slightly 3D, with some sections popping out from others (almost as if the height is set to something like 4 when it should be like 500?)

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b531908608f32953541bbc9fe999251199cc94a5.png)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 3, 2021, 8:21pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/6 "2021-05-03T20:21:02Z")

</div>

@micuat  
hi add the link how to format the code i think you made mini video about it

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [May 3, 2021, 8:37pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/7 "2021-05-03T20:37:11Z")

</div>

thanks. Instead of image could you post the code as text for the reference? You can use `</>` button to format

[https://www.khm.de/~n.hieda/discourse-code.mp4](https://www.khm.de/~n.hieda/discourse-code.mp4)

The problem is that `shape` only scales in x and y axes. You set those parameters to “stretch” to these directions but z remains the same. Instead, you should use `shape` with one argument (obj) and use `scale(x, y, z)` before calling `shape` to stretch in 3 axes (most likely you want to use the same values for x, y, z, which would be around 300-500 given your code)

---

<div class="post-metadata">

**Author:** ![Chubbulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chubbulus/32/13049_2.png) [@Chubbulus](https://discourse.processing.org/u/Chubbulus)\
**Post date:** [May 3, 2021, 8:56pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/8 "2021-05-03T20:56:49Z")

</div>

```auto
//Imports the sound library to allow sounds to be played
//Imports Peasy, a library used to create interactive cameras.
import processing.sound.*;
import peasy.*;

//Creates a variable to store data for the sound played in the background as well as
//an interactive camera.
SoundFile music;
PeasyCam camera;

//Creates a variable that will load the object from the data folder in the setup void
//Creates a variable used to store the model textures.
PShape rwing;
PImage texture;

//This integer will be used to determine the speed at which the model should spin.
int s;

//Anything in this void runs before the screen is drawn for the first time
void setup()
{
  //P3D allows the code to create a 3D Environment
  size(1920,1080,P3D);
  
  //Creating a new interactive camera and sets its maximum and minimum zoom levels.
  camera = new PeasyCam(this, 100);
  camera.setMinimumDistance(400);
  camera.setMaximumDistance(3000);
  
  //Loads the music and ensures that it starts playing.
  music = new SoundFile(this, "music.wav");
  music.play();
  
  //Loads the rwing model I made in Blender and stores it in variable "rwing"
  rwing = loadShape("starwingShip.obj");
}

void draw()
{
  background(204);
  shape(rwing, 0, 0, 380, 500);
}

```

---

<div class="post-metadata">

**Author:** ![Chubbulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chubbulus/32/13049_2.png) [@Chubbulus](https://discourse.processing.org/u/Chubbulus)\
**Post date:** [May 3, 2021, 9:10pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/9 "2021-05-03T21:10:35Z")

</div>

The suggestion about using scale(x, y, z) worked to display the model with correct height, however it seems to have folded the model in half?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/20d3f32a0e8725d50ee184d33615ecdcef83d898.png)

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [May 3, 2021, 9:50pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/10 "2021-05-03T21:50:50Z")

</div>

Do you want to post the updated code?

It’s hard to tell from that image. When you rotate it, is it always the part close to the camera (or behind) is gone? Or is the specific part of the model gone?

If former I think the clipping plane is the issue. You need to set near clipping plane shorter or far plane further  
[https://processing.org/reference/perspective\_.html](https://processing.org/reference/perspective_.html)  
I know this is not intuitive but perhaps you can start with the example in the doc.

---

<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:** [May 4, 2021, 5:05am UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/11 "2021-05-04T05:05:23Z")

</div>

```auto

// ---------------------------------------------------------------------------
// Tools

void avoidClipping() {
  // avoid clipping (at camera): 
  // https : // 
  // forum.processing.org/two/discussion/4128/quick-q-how-close-is-too-close-why-when-do-3d-objects-disappear
  perspective(PI/3.0, (float) width/height, 1, 1000000);
}//func 

```

---

<div class="post-metadata">

**Author:** ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)\
**Post date:** [May 4, 2021, 6:59am UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/12 "2021-05-04T06:59:08Z")

</div>

Hello,

In reponse to this,

> [@Chubbulus](#):
>
> however it seems to have folded the model in half?

All sorts can go wrong when you transfer from one 3D environment to another - vertex winding, scale, normals, etc. Never heard of folding in half though. In Blender, the world up axis is positive Z, (0.0, 0.0, 1.0). In Processing, the world up axis is negative Y (0.0, -1.0, 0.0). Make sure your model isn’t upside down. Add some lights to your Processing sketch, then make sure it isn’t inside-out like a sock.

Problems are easier to fix in Blender than Processing, so go back to Blender, make sure your faces are properly oriented. They will be blue if they’re right; red if they’re flipped wrong way 'round.

 ![faceOrientation](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5f9f4021673c2857d354289cb1944d2412ac852f.png)

If any faces are red, you can fix them by going into edit mode (press `Tab`), then going to `Mesh > Normals > Flip`.

 ![flipFace](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b67a33a8d445253215fe1d87004139d22be0232a.jpeg)

Normals and a face’s vertex winding are two separate, but related concepts, so the menu organization is a bit whack. But whatever.

The quickest way to fix your normals is to let Blender do it for you with `Shade Smooth` or `Shade Flat` while you’re in object mode.

 ![shadeSmoothOrFlat](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/234881b4bfa66ad71ec6b520dac950d4eeb6690e.jpeg)

When you export the .obj, double check the export settings, particularly the Transform section (press `N` to toggle the settings on and off).

 ![exportSettings](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9e3a7d54e325f973093ae00e0a3e3890e8bd0b1d.png)

I forget what will work best for transfer to Processing. If nothing here works, you may have to rotate or scale by -1 (always double check face orientation and recalculate normals after doing the latter).

Hope that helps.  
Jeremy

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [May 4, 2021, 12:25pm UTC](https://discourse.processing.org/t/loadshape-displaying-my-obj-file-flat-rather-than-as-a-3d-model-any-help/29824/13 "2021-05-04T12:25:58Z")

</div>

Hi @Chubbulus ,

Welcome to the forum! 🙂

Have you tried using the SAITO .obj loader library?  
[https://code.google.com/archive/p/saitoobjloader/](https://code.google.com/archive/p/saitoobjloader/)

I use it to render some 3D models that I have used in Processing.  
Maybe it will help…

Best regards
