Hi Mandelbrot,
Hmm, I wonder if creating a second graphics renderer with createGraphics would simplify things? This second P3D
renderer could deal with the 3D elements in the sketch like the shuttle. The main renderer could then sandwich it between background and foreground elements (title menus, GUI/HUD). The technique is explained in more depth in the tutorial “Render Techniques.”
I tried to keep the following sample simple while respecting the complexity of your code. There was an error on line 38 because bg(0);
was called without the function bg
being defined, so I can’t say I got the full effect.
The teapot.obj file I used is from this Github gist.
PGraphics3D scene3d;
PShape teapot;
void setup() {
size(512, 256, P3D);
textAlign(CENTER, CENTER);
textSize(20.0);
scene3d = (PGraphics3D)createGraphics(width, height, P3D);
teapot = loadShape("teapot.obj").getTessellation();
float s = min(width, height) * 0.2;
teapot.scale(s, -s, s); /* Flip model upside-down*/
}
void draw() {
// Background elements.
background(0.0, 0.0, 127.0);
fill(255.0);
text("BACKGROUND", width * 0.175, height * 0.5);
draw3DScene();
// After updating the 3d render, it can be displayed in
// the main renderer with image or texture.
image(scene3d, 0.0, 0.0, width, height);
// Foreground elements.
fill(127.0, 0.0, 0.0);
ellipse(width * 0.75, height * 0.75, 150.0, 150.0);
fill(255.0);
text("FOREGROUND", width * 0.75, height * 0.75);
}
void draw3DScene() {
float t = frameCount * 0.01;
scene3d.beginDraw();
scene3d.clear();
scene3d.camera(
0.0, 0.0, scene3d.height * 0.86602,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
scene3d.directionalLight(
255.0, 255.0, 255.0,
0.0, -0.8, 0.6);
// Translate and rotate both text label and teapot.
scene3d.pushMatrix();
scene3d.translate(cos(t) * 100.0, 0.0);
scene3d.rotateY(t);
scene3d.shape(teapot);
// Turn lights off for text.
scene3d.noLights();
scene3d.fill(255.0);
scene3d.text("LABEL", -teapot.getWidth(), 0.0);
scene3d.popMatrix();
scene3d.endDraw();
scene3d.flush();
}
I just used ellipses, solid colors and text - but the idea should work with textures.