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?
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?)
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);
}
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.
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.
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).