How can I 3d rotate a shape while using size(P2D)?

Hi!

I designed a 3D sign using PSHAPE on a P3D environment.

The problem is I want to use it in a mixed 2D/3D environment

/* 
displaying text or 2d graphics on a 3d canvas is a pain.
But we can cast a 3d canvas inside a 2d canvas.
*/

size(1000,1000,P2D);
/* .... */
PGraphics canvas3d=createGraphics(1000,1000,P2D);

As main renderer (size) is 2d, I can’t rotateX my shape.
Is there a way for me to access the 3d renderer inside PGraphics to rotate the shape there?
Can I do canvas3d.shape(myshape.rotateX(HALF_PI))?

Yours,

José.

below is an example

BUT it might be easier to use #9 from 25 life-saving tips for Processing | Amnon P5 - Experiments with Processing by Amnon Owed

Example

here I used canvas3d=createGraphics(500, 500, P3D); not P2D

(the Sketch itself is P2D of course)

/* 
 displaying text or 2d graphics on a 3d canvas is a pain.
 But we can cast a 3d canvas inside a 2d canvas.
 */


PGraphics canvas3d;
float a1=0.77;

void setup() {
  size(1000, 1000, P2D);
  /* .... */
  canvas3d=createGraphics(500, 500, P3D);
}

void draw() {
  background(0); 


  canvas3d.beginDraw();
  canvas3d.background(100);
  canvas3d.lights();
  canvas3d.translate(canvas3d.width/2, canvas3d.height/2); 
  canvas3d.rotateX(a1);

  canvas3d.stroke(255);
  canvas3d.fill(255, 0, 0);
  canvas3d.box(22); 
  a1+=0.014;
  canvas3d.line(20, 20, 100, 100);
  canvas3d.endDraw();

  image(canvas3d, 9, 30);
  text("Yes", 669, 30);
}
//

Hi, Chris. Thank for your solution.
But I don’t want to rotate the cancas, only the PShape.

At least with Scale, the results from:

myshape.resize(newsize);
camera....
Rotate...
Scale...
pushMatrix();
Translate ...
shape(myshape);
PopMatrix();

And:

;
camera....
Rotate...
Scale...
pushMatrix();
Translate ...
scale...
shape(myshape);
PopMatrix();

Are different.

I am creating the shape in a position from a map. That is the reason I can’t rotate the shape before other scales or rotations take place.

ahah I just posted the same answer a minute ago! :wink:

1 Like

I can’t help you with that. Maybe we mean two different things.

I don’t rotate the canvas, I rotate the cube / shape on the canvas; you can change the rotation and implement scale

1 Like