Opening a new P3D window from a 2d main window

edited April 2017 in Library Questions

The main part of my sketch is a control window with 4 tabs all consisting of CP5 sliders and buttons, I also have a separate 3D view window using Proscene which the user interacts with. Each of these elements I have working on thier own, i.e. if I just have a sketch with the (2D) Control window all works fine, If I have a sketch with just the 3D view interactive view then that works fine.

The problem is combining the two, I can't seem to find the correct way to "start up" the second window which is the P3D window. Are there any simple examples anywhere that show this sort of multi window mixed 2d and 3d setup ? I have tried to follow the ControlP5Frame example, whilst that kind of works in that it draws my controls, none of the functions connected to those controls continue to work. Sure I'm missing something very basic here :)

Answers

  • You should be able to simply create another class that extends PApplet and contains your 3D sketch. Then call the PApplet.runSketch() function with an instance of that class. Something like this:

    void setup() {
      size(100, 100);
    }
    
    void draw() {
      background(0);
      ellipse(50, 50, 10, 10);
    }
    
    void mousePressed() {
      println("Creating second sketch...");
      String[] args = {"TwoFrameTest"};
      SecondApplet sa = new SecondApplet();
      PApplet.runSketch(args, sa);
      println("Done.");
    }
    
    public class SecondApplet extends PApplet {
    
      public void settings() {
        size(200, 200, P3D);
      }
      public void draw() {
        background(255);
        translate(width/2, height/2);
        sphere(50);
      }
    }
    
  • edited October 2016

    Thanks GoToLoop, this had been sending me round the bend! I found the answer here If I had phrased my search better, probably would have found it on my own! Simple answer was nest my 3D shape class into the "second Applet" so it didn't throw an error. Thanks again, you've saved me some hair

  • Well I'm back to this again 8-|

    I can make creating a second Applet kinda work but it's leading me into other problems. This second window includes a "picker" based on this But not using Peasy.

    • The main object of this 3D scene involves loading a .obj from file, but for some reason it seems I can't load the obj into this class/secondApplet ? error says obj is missing or inaccessable, but will load into a main/first window.

    • How do you get an undecorated, always on top second window now frame has gone?... I have tried a few suggestions on the forum but can't get them to work with the openGL used in the picker.

  • Answer ✓

    ... involves loading a ".obj" from file, ...

    https://forum.Processing.org/two/discussions/tagged/--sketch-path

  • Thanks GoToLoop that's one of the list

Sign In or Register to comment.