P3D Processing source code / help me

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