3D window in 2D sketch

edited April 2016 in How To...

Hey! I'm trying to create a 3D window in a 2D animation. I don't know how to make this work... Any ideas? I'm using the proscene library to make the 3d part of the animation...

Tagged:

Answers

  • I dont know exactly what you mean. It used to be possible to draw over 3d regardless of z depth by using the hint function but the hint function does not appear to be working right now i have no idea.

  • Just a question to gmellocmr.

    Is the topic To newcomers in this forum: read attentively these instructions not visible when you come to the forum?

    Should it stand up more? I made it sticky and top-most topic, but apparently lot of newcomers miss it, just posting in the first / default category (apparently, not much people read the category descriptions...).

    Anyway, moving this topic from Using Processing to How To...

  • I'm terribly sorry, PhiLho... Yes, the topic is visible and doesn't need to stand up more. I don't know about the others newcomers, but i guess i didn't read very carefully the intructions, even with the title saying "read attentively"... Thanks for pointing it out and sorry again =(

    About my question... It's like the examples page from the processing website. If my PApplet is the page, then the little window with the animation it would be like a 3d PGraphic or something.

  • I didn't write the above to make you feel bad, it was just genuine concern, since you are not the only one missing the instructions. But thanks for the feedback. :-)

    And the PGraphics and P2D renderer do not play well topic might be relevant to your problem.

  • If you use P2D as the sketch's renderer, then you cannot do any 3D rendering in the main window. However, if you want to somehow a 3D scene into a 2D drawing, you could create a PGraphics offscreen surface using P3D as its renderer and then compose it into the main 2D surface as an image:

    PGraphics pg;
    
    void setup() {
      size(400, 400, P2D);
      pg = createGraphics(100, 100, P3D);   
    }
    
    void draw() {
      pg.beginDraw();
      pg.background(157);
      pg.lights();
      pg.translate(50, 50);
      pg.rotateY(frameCount * 0.01);
      pg.box(20);
      pg.endDraw();  
    
      background(0);
      image(pg, mouseX, mouseY);
    }
    

    Is this what you have in mind?

  • Yes, exactily codeanticode, thanks!
    But my problem is using the ProScene library in this 3D PGraphic...

  • You can attach a Scene object from ProScene to a PGraphics3D offscreen surface:

    import remixlab.proscene.*;
    
    Scene scene;
    PGraphics3D canvas;
    
    void setup() {
      size(640, 360, P2D);
    
      canvas = (PGraphics3D)createGraphics(width, height, P3D);
      scene = new Scene(this, canvas);  
    }
    
    void draw() {  
      canvas.beginDraw();
      scene.beginDraw();
      canvas.background(0);
      canvas.fill(204, 102, 0);
      canvas.box(20, 30, 50);
      scene.endDraw();
      canvas.endDraw();
    
      image(canvas, 0, 0, width/2, height/2);
      image(canvas, width/2, 0, width/2, height/2);
      image(canvas, 0, height/2, width/2, height/2);
      image(canvas, width/2, height/2, width/2, height/2);  
    }
    

    Notice that in addition to the PGraphics' beginDraw()/endDraw() calls, you also need to enclose the offscreen rendering code between Scene.beginDraw() and Scene.endDraw().

  • Thank you codeanticode! This solved my problem =)

Sign In or Register to comment.