It's possible to change between 2D and 3D while runing?

Hi there!!

I want to switch between 2D and 3D pressing a button, don’t know if that’s possible, someone knows?

I have my sketch running (processing 3, in android studio), and want to be able to change to 3D or go back to 2D, because when I run settings without P3D

  public void settings() {  size(displayWidth,displayHeight); }

It works fine, but when I put the P3D, the lanes and points (that I have without P3D) aren’t drawn as I want, but can’t quit the P3D because want to draw in 3D when I press a button.

Also don’t want to use P2D because it makes my fps to decrease from 42 to 12 fps, so would like to use not P3D and 3D when the button is pressed; other solution to my problem could be to fix the bad drawn lanes, here is a comparison of the both modes:

. . . . .not P3D. . . . and . . . . P3D
image

Sorry for the quality, I’m not good using Linux GIMP (miss paint) and the tablet from where I took the video to cut an image can’t or I don’t know how to make a screenshot.

Thanks :hugs:

1 Like

@GoToLoop thanks for the references, I can call other Sketches from AS and make calls from one sketch to other, but I prefer if is possible do it without call or make other sketch.

I mean, in my sketch (with all the data I have there), click a button and put the 3D mode (convert my rectangles to boxes, etc…), I think can do it making other sketch like you suggest, but really prefer in my main sketch.

By the way gonna try to improve the visualization of my 2D lanes in 3D and if I cant do that, I will make other sketch for the 3D mode, but if there is a way to toggle in the same sketch, its preferable

Thanks :grinning:

  • Even the oldest Processing 1 couldn’t change its renderer afterwards.
  • Each active PApplet got its renderer determined when it starts and can’t be changed later.
  • Therefore, if you need multiple renderers, you’re gonna need multiple PApplet instances as well.
  • Alternatively, you can use renderers P2D or P3D, and then have available PGraphics objects of renderers JAVA2D, P2D & P3D for that PApplet instance.
1 Like

Run the sketch as P3D and create an off-screen P2D buffer the same size. Do 2D drawing to the buffer then copy the buffer to the 3D display.

3 Likes

Uo @quark thanks :smiley: that’s the solution :heart: we cant change the renderer, but that allows me to draw in 2D, nice.

Finally just increasing de strokeWeight I reached a good way to use in my app (simply solution) :sweat_smile: by the moment gonna let it in this way, but if I will have issues in the future I will try your solution (I’m curious to see the fps with the createGraphics)

Thanks both :hugs::hugs:

See also:

Note that in the special case of using peasycam for 3D, peasycam also has its own built-in cam.beginHUD() / cam.endHUD() for drawing a 2D layer onto the scene.

1 Like