LensStudio:LensPreview
ModuleModule providing LensPreview, a headless preview that renders the open project's Lens without a panel or widgets.
Module providing LensPreview, a headless preview that renders the open project's Lens without a panel or widgets. Its value types, such as Config, Image, and the pause reasons, are in LensStudio:Preview.
Example
Render the project that is open in Lens Studio without a Preview panel and save one frame, for example as a thumbnail. Call this from a plugin after a project has loaded; the plugin needs the filesystem permission to save the image.
import { LensPreview } from 'LensStudio:LensPreview';
import { allImages } from 'LensStudio:Preview';
export async function saveLensThumbnail(pluginSystem: Editor.PluginSystem, file: Editor.Path): Promise<LensPreview> {
// The headless preview starts rendering the open project when constructed.
const preview = new LensPreview(pluginSystem);
preview.setViewport(new Editor.Size(360, 640));
// Feed the Lens one of the sample images bundled with Lens Studio.
const [sample] = await allImages();
if (!sample) throw new Error('No bundled sample images are available');
const config = preview.config; // a copy: assign it back to apply it
config.input = sample;
preview.config = config;
const image = await preview.tryScreenshot(20000);
image.save(file);
return preview;
}
Keep the returned preview while you need it, for example to capture again after the project changes. It is released once nothing references it, so hold a reference until every pending screenshot has settled.
Classes
| Class | Description |
|---|---|
| LensPreview | Headless preview that renders the project open in Lens Studio without a panel or widgets. It starts rendering when constructed and can capture screenshots, inspect the runtime scene, record traces, and exchange messages with the Lens; it is released when no longer referenced. |
| LensPreviewOptions | Options passed to the LensPreview constructor. |