ThreePipe
    Preparing search index...

    Class MaterialPreviewPlugin

    Makes material previews for an inspector: request a preview on every material change, and the plugin renders it in the viewer's next preFrame, at most maxPerFrame per frame. Its settings are in its UI (Material Previews).

    • The previews render offscreen with MaterialPreviewGenerator.renderToCanvas, with the viewer's environment map and tone mapping (materialPreviewOptionsFromViewer), so the colours match the viewport. The canvas is not changed: a preview does not call viewer.setDirty() and does not restart the progressive rendering.
    • While a material changes continuously, its preview renders at most once every dragInterval ms, and the last change renders too. A change is continuous when its materialUpdate has last: false (uiconfig sends it while a slider moves), or when it comes less than dragInterval ms after the previous change and has no last (an animation or a material transition changes the material in every frame). Other changes, and a change with last: true (the release of a slider), render in the next frame. See https://threepipe.org/notes/frame-updates.html
    • Requests for the same material, shape, geometry and size share one render.
    • Previews are cached by material uuid, shape, geometry, size and the material's change counter (and the viewer's environment and tone mapping), so a request for an unchanged material returns the cached preview in the next frame, without a render.
    const previews = viewer.addPluginSync(MaterialPreviewPlugin)
    let handle: MaterialPreviewHandle | undefined
    function showPreview(material: IMaterial) {
    handle?.cancel()
    handle = previews.request(material, {shape: 'sphere'}, p => img.src = p.toDataURL())
    }
    material.addEventListener('materialUpdate', () => showPreview(material))

    Hierarchy (View Summary)

    Index
    _dirty: boolean = false
    _viewer?: ThreeViewer
    _viewerListeners: PartialRecord<IViewerEventTypes, (e: IViewerEvent) => void> = {}
    constructor: typeof AViewerPluginSync & typeof AViewerPlugin
    dragInterval: number = 32

    While a material changes continuously (a drag, an animation, a transition), the minimum time in ms between two previews of the material. Other changes render in the next frame. 0: one preview per frame.

    enabled: boolean = true

    While it is disabled, requests wait and nothing renders.

    ignoreChange: (e: MaterialChangeEvent) => boolean = ...

    A change of a material that does not change its look: it does not count as a change, so the cached previews stay and no preview renders. Default: a rename (change or key 'name', or the name field of the material's UI). Set a function to skip other changes, from the change and key of setDirty.

    isViewerPluginSync: true = ...
    maxCacheSize: number = 32

    Number of previews kept in the cache (the least recently used is removed first).

    maxPerFrame: number = 1

    Maximum number of previews rendered in one frame. Cached previews do not count.

    now: () => number = ...

    Clock in ms, for dragInterval.

    serializeWithViewer: boolean = false

    The previews are made on request; their settings are not saved with the viewer.

    size: number = 256

    Default size of the previews in pixels.

    uiConfig?: UiObjectConfig<any, string, any> = undefined
    OldPluginType?: string
    PluginType: "MaterialPreviewPlugin" = 'MaterialPreviewPlugin'