Knobs in 3D are largely the same as knobs in 2D, which you can find details of here: Knobs, Control Panels and In-Viewer Controls. However, there are some extra considerations when writing a 3D knob:
You can easily check whether the Viewer is in 3D mode through the ViewerContext:
void draw_handles(DD::Image::ViewerContext* ctx) {
if (ctx->viewer_mode() != VIEWER_2D) {
// draw the handle.
}
}
NUKE’s 3D Viewer does a series of rendering passes to draw the final image, so your handle drawing code may be invoked up to three times:
You can tell what the current render pass is by checking the result of ViewerContext::event():
Event | Current Render Pass |
---|---|
DRAW_OPAQUE | Drawing solid objects. If your handle should appear to be part of the scene, just like regular geometry, this is when you should draw it. |
DRAW_LINES | Wireframe pass. This is where most handles are drawn. |
DRAW_STIPPLED | Hidden line pass. In this pass, we’re drawing lines which would normally be hidden behind geometry. The line style is changed to stippled and the OpenGL depth test function is inverted. Draw here if you want parts of your handle that would otherwise be obscured to show up. |
There are other values that event() can return besides those above; you should make sure you aren’t drawing for any of those.
For example:
void draw_handles(DD::Image::ViewerContext* ctx) {
if (ctx->viewer_mode() == VIEWER_2D)
return;
if (ctx->event() == DRAW_LINES || ctx->event() == DRAW_STIPPLED) {
// draw the handle.
}
}