Preview FunctionsAvailability LightWave 6.0 The Preview Functions global is the plug-in API for LightWave's VIPER (Versatile Interactive Preview Render) window. VIPER allows users to preview the effects of shader, environment, volumetric, pixel filter and image filter plug-ins. It uses image buffers from the most recent test render to generate a reduced-size rendering of the scene, and it can composite this with your plug-in's output while the user changes your parameters. The previewer is an extension of your plug-in's interface. The API supplies functions that let you subscribe (install), set the context (tell VIPER that your interface is the active one), open the VIPER window, give VIPER your rendering callbacks, and get the prerendered image and information about the camera. This is a low-level API, and you may never need to use it. Beginning with LightWave 7.0, VIPER can preview your plug-in automatically, without your intervention. It switches contexts transparently and calls your regular handler callbacks to render the preview. The rendering of the preview occurs whenever you call the Instance Update global. Global Call LWPreviewFuncs *pvf; pvf = global( LWPREVIEWFUNCS_GLOBAL, GFUSE_TRANSIENT ); The global function returns a pointer to an LWPreviewFuncs. typedef struct st_LWPreviewFuncs { PvContextID (*subscribe) (char *title, void *userData, closeFunc *); void (*unsubscribe)(PvContextID); void (*open) (PvContextID); void (*close) (void); int (*isOpen) (void); void (*setContext) (PvContextID); void (*setClick) (PvContextID, ClickFunc *); void (*setRender) (PvContextID, void *renderData, InitFunc *, CleanupFunc *, EvaluateFunc *); void (*setOptions) (PvContextID, char **list, OptionsFunc *, int selection); void (*startRender)(PvContextID); void (*stopRender) (PvContextID); void (*getPixel) (PvSample *pixel); LWImageID (*getBitmap) (int *width, int *height); LWItemID (*getCamera) (double pos[3], double rot[3], double *zoomFactor); void (*getView) (int *width, int *height, double *pixelAspect); void (*setPreset) (PvContextID, presetFunc *); } LWPreviewFuncs;
Pixel Sample The getPixel function and the click and evaluate callbacks store information about a pixel in a PvSample. typedef struct st_PvSample { int x, y; float rgbaz[5]; LWMicropol mp; } PvSample;
Callbacks The previewer uses callbacks both for rendering and to allow your plug-in to respond to user actions. Interface typedef int clickFunc(int count, void *userData, PvSample *pixel); typedef void optionsFunc(int option, void *userData); typedef void presetFunc(void *userData, LWImageID image); typedef void closeFunc(void *userData); The click callback tells you that the user has clicked on the preview image and gives you information about the pixel. The options callback is called when the user has selected an option from the custom Options pop-up on the preview window. The first argument is an index into the array of strings you passed to setOptions. The close callback is called when the user closes the preview window. The preset callback tells you that the user wants to add a preset to the shelf for your plug-in's settings. The image is the same one returned by getBitmap. Use the Shelf Functions global to add the preset. The user data for all of these is the pointer you passed to subscribe. Rendering typedef int initFunc(void *renderData, int manual); typedef void cleanupFunc(void *renderData); typedef int evaluateFunc(void *renderData, int w, int h, PvSample *pixel); Your preview init function should perform the same kinds of operations that your handler init and newTime callbacks perform, and your preview cleanup is analogous to your handler cleanup. The second argument to the init callback is TRUE if the user explicitly requested the render (by clicking on a button in the previewer's window). The evaluate callback receives the width and height of the preview image and a PvSample for the pixel to be evaluated. Your evaluate writes new values in the rgbaz field of the PvSample. The PvSample's LWMicropol is read-only (writing to it has no effect). History The setPreset function was added in LightWave 7.0, but LWPREVIEWFUNCS_GLOBAL was not incremented. Before calling setPreset, you can use the Product Info global to determine whether you're running in a version of LightWave prior to 7.0. |