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

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?

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

Hi! Welcome to the forum!

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

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?

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?)

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

1 Like

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

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)

//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);
}

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?

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
I know this is not intuitive but perhaps you can start with the example in the doc.


// ---------------------------------------------------------------------------
// 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 

Hello,

In reponse to this,

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.

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

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.

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

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

2 Likes

Hi @Chubbulus ,

Welcome to the forum! :slight_smile:

Have you tried using the SAITO .obj loader library?
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