We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is driving me slightly mad... I have so far tried using a second applet to achieve the same but the results aren't great, as the second window has a border, can be dragged about etc. Whilst I would prefer the 3D "view" to just look like part of the rest of my 2D GUI.
I'm now trying to use a P3D offscreen buffer and then using image(), draw that to the 2D sketch... but I'm stuck with an error asking for size(). But I have no idea where/how I should be supplying this size() value, if I put it in settings() it applies to the main 2D sketch which I don't want. Can anyone help please?!
simple version code :
PGraphics p3d;
DBox myBox;
void settings() {
//size(400,400,P3D);
}
void setup() {
size(800, 800);
p3d = createGraphics(400, 400, P3D);
p3d.beginDraw();
p3d.noStroke();
myBox = new DBox();
p3d.background(128);
myBox.render(this.g);
p3d.endDraw();
}
void draw() {
background(100);
fill(255, 0, 0);
ellipse(400, 400, 650, 650);
image(p3d, 200, 200);
}
class DBox {
DBox() {
}
void render(PGraphics pg) {
pg.fill(0, 0, 255);
pg.box(40);
}
}
Answers
@mala
What is the exact error message? Is it associated with a line number?
I'm not seeing any errors or warnings when running the sketch above in Processing 3.3.
sorry the line :
size(400,400,P3D);
in settings should have been commented out. The problem i'm having is that if I leave size there (which gets rid off error of course) It is applying the size and P3D to the main 2D window to make it 3D, rather than to the "p3d" 3d graphics i'm wanting to create and draw on top of the 2D window.I get the feeling I'm asking the wrong questions here and have missed something fundamental. So here's a simple question, Is it actually possible to add 3D graphics on top of 2d base sketch without using a second Applet window and having all the issues that involves with borders and keeping it on top ?
My main (2D) sketch is a GUI with a large number of buttons, scroll boxes etc. All these elements are built from processing "primitives" and created in offscreen buffers which are only updated on mouse over/off/click etc...This all works really nicely.
The 3D view I want to add in the middle of this, has one main 3d shape ( an imported .obj) then 156 custom Pshapes( basically cube shapes) arranged over the imported obj. A picker system lets the user select any of these 156 "nodes" whilst navagating around the scene using a basic custom camera.....by itself all works nicely.
How do I get this 3D view nicely sat in the middle of main 2D GUI without having a floating second window with borders that disappears behind everything else whenever I click on a button in the 2D GUI ?
The only alternative I can think of is to have the main sketch window as 3D, draw my 3D parts just in the middle of this(whilst somehow constraining camera nav) Then use hint(DISABLE_DEPTH_TEST) draw all my 2D gui bits, before going back to 3D with hint(ENABLE_DEPTH_TEST).... Though I get the distinct feeling this is going to casue a lot of problems with my GUI 2D elements and the 3D picker system. :(
getGraphics().setVisible(false);
Does it work if you use P2D instead for the main window?
@Lord_of_Galaxy No it doesn't seem to work with P2D as main window, that I can see.
@GoToLoop Thanks for suggestion, at one point I though that should be possible in theory, but had no idea how to go about doing it. I may try that later.
What I've done for now is rearrange it all so it is a P3D sketch, as mentioned in my last post, disabling depth and drawing 2D GUI bits over the top. Initially it halved the frame rate, but after masking the 3D view area part, and setting up a "over3DView" function based on same area to restrict what gets refreshed and mouse input I mangaed to get the frame rate back up.
I'm going to move forward based on this approach, but will have to keep an eye on it as all the above is just the GUI and I have a load of stuff going on under the hood including a lot of time sensitive serial comms.
Previous post related: https://forum.processing.org/two/discussion/18419/opening-a-new-p3d-window-from-a-2d-main-window#latest
Kf
I did that, look here
but I agree it maybe will cause other errors...
https://github.com/Kango/Games/tree/master/TicTacToe_3D