P3D Processing source code / help me

please format code with </> button * homework policy * asking questions

  1. How do I set the initial starting point position?

I want to set a location that starts as soon as the program is turned on.
Set where the graphics are visible.

  1. I want to decide the section that can be viewed with the camera.Is there a way to set it up?

I want the camera to be visible only in the (0,0,500,500) square area in the full screen.
How can it be implemented?

source code download :
https://cmail.daum.net/v2/mails/0000000000006JR/attachments/MjoxLjI6NDMxNDozMDc4Mzg4OmFwcGxpY2F0aW9uL3ppcDpiYXNlNjQ6aHBmSGJ1a0FPWTQzUkJQcEFCS3VUdw/download/sketch_3d_test.zip

import java.io.FileOutputStream;

import peasy.*;

PeasyCam camera;
PShape s;

void settings() {
size(1000, 1000,P3D);
PJOGL.setIcon(“icon.png”);
}

void setup() {

s = loadShape(“Untitled2.obj”);
camera = new PeasyCam(this, 200);

shapeMode(CENTER);

}

void draw() {
// background(255);
background(255);

shape(s, 0,0,500,500);

}

Hi,

The starting point position of what? The 3D model? If yes, you can just specify the coordinates when you display the shape with shape(s, x, y)

What do you mean by a “location that starts”? You want to animate the model?

Yes, you can take a look at the camera() function :

camera(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)
Sets the position of the camera through setting the eye position, the center of the scene, and which axis is facing upward.

Hope it helps :wink:

1 Like

@josephh

Thank you for answer.

  1. starting point position // can be solved with your advice.

  2. I want to decide the section that can be viewed with the camera
    -Details are shown in the picture.
    -Like the picture, is it possible to implement it?

import java.io.FileOutputStream;

import peasy.*;

PeasyCam camera;
PShape s;

void settings() {
size(1000, 1000,P3D);
PJOGL.setIcon(“icon.png”);
}

void setup() {

s = loadShape(“Untitled2.obj”);
camera = new PeasyCam(this, 200);
// camera(0,0,0,0,0,0,0,0,0);
// camera.setMinimumDistance(50);
// camera.setMaximumDistance(500);
// camera.setViewport(0,0,200,200);
// camera.lookAt(200,200,200);

shapeMode(CENTER);

}

void draw() {
// background(255);
background(255);
shape(s, 0,0,100,100);

}

1 Like

Yeah sure, you need to use a separate PGraphics object where you are going to display your model.

From the documentation :

Use this class if you need to draw into an off-screen graphics buffer. A PGraphics object can be constructed with the createGraphics() function. The beginDraw() and endDraw() methods (see above example) are necessary to set up the buffer and to finalize it. The fields and methods for this class are extensive.

Check out this simple example :

PGraphics pg;
float angle = 0;

void setup() {
  size(500, 500, P2D);
  pg = createGraphics(200, 200, P3D);
}

void draw() {
  pg.beginDraw();
  
  pg.background(255);
  pg.translate(pg.width / 2, pg.height / 2);
  pg.rotateX(angle);
  pg.rotateY(angle * 2);
  
  pg.box(50);
  
  pg.endDraw();
  
  image(pg, 0, 0); 
  
  angle += 0.02;
}

In order to have a 3D context for the PGraphics, you need to use P2D or P3D for the main window.

You use PGraphics the same way you use drawing commands in Processing but you need to prefix it with the name of the graphics instance (pg.drawingFunction(...))

p3d

1 Like

@josephh

There are two things I am curious about.

Q1) Can’t it be resolved with’PShape’ and’PeasyCam’?

Q2) Can’t I load’obj’ file with’PGraphics’?

import java.io.FileOutputStream;

import peasy.*;

PeasyCam camera;
PShape s;
PGraphics pg;

void settings() {
size(1000, 1000, P3D);
PJOGL.setIcon(“icon.png”);
}

void setup() {

pg = createGraphics(400, 400, P3D);
s = loadShape(“Untitled2.obj”);
camera = new PeasyCam(this, pg, 200);
camera.setViewport(0, 0, 400, 400);
shapeMode(CENTER);
// pg.beginDraw(); pg.endDraw();
}

void draw() {

background(255);

pg.beginDraw();
pg.background(255);
pg.lights();
//pg.translate(pg.width/2, pg.height/2 + 100, -200);
//pg.rotateX(PI);
//pg.rotateY(frameCount * 0.01f);
pg.shape(s);
pg.endDraw();
image(pg, 0,0,400, 400);

}

Is it correct to do something like the source code above?

Or is there another way?

1 Like

A PShape object is just a datatype for storing shapes (SVG or OBJ) and PeasyCam :

provides a dead-simple mouse-driven camera for Processing

(from the repo)

So those are not related to what you described earlier with your picture, you need to use a PGraphics object in order to draw on a separate buffer isolated from the rest of your sketch.

You only need to use your instance of PGraphics in order to display what you want. You can still use global methods in order to load your OBJ file. (like you did in the code above)

The above code looks correct so you are good to go! :wink: (remember that to format your code on the forum, you can use the </> button instead of the quote one)

1 Like

Dear josephh,

Thank you very much for your interest. What I want is simply to open the .obj file. And this is a method that works only in a defined area.

Thank you.

1 Like

When you look at the documentation of peasycam
you should find stuff to move the camera to a certain position

You can make a menu or have keys to manage different camera positions

But it’s not totally easy and I don’t know whether peasycam was made for this

1 Like