ThreePipe
    Preparing search index...

    Class ViewOverridesPlugin

    ViewOverridesPlugin shows the scene with one debug material for every mesh, or with other lights or another environment map, without changing the scene. For an editor's view menu: check the normals, the UVs or the material assignment, or see a model in other lighting.

    Material views (setMaterial): unlit (base color and maps, no lights), linear depth (fitted to the models), view-space normals, world-space normals, material ID (one color per material) and UV (U red, V green, for the UV set uvChannel; magenta where a mesh has no such set).

    Fat lines (LineSegments2, Line2, MeshLine with a LineMaterial) keep their line shader, so their width, dashes and world units do not change: the unlit view draws them with their own material (a fat line is unlit), the depth view with the depth ramp of the meshes (the same range), the material ID view in the colour of their material, the normal views in a neutral grey (the colour of a zero normal: a line has no surface normal) and the UV view in magenta (a line has no UV set). A line material with allowOverride false keeps its own material in every view, as other materials.

    Widgets (helpers, gizmos and their icons: an object with isWidget or assetType 'widget', and its children) keep their own materials in every view: the views show the scene, and a widget drawn with a debug material shows as a rectangle (an icon quad) or in the colour of the view (its lines).

    Lighting presets (setLighting, lightingPresets): 'lights-' replace the scene lights (and by default the environment, see lightsKeepEnvironment) with preset lights; 'env-' replace them with another environment map, loaded once and cached. The 'env' presets are 1k HDR files on samples.threepipe.org: studios, interiors and outdoor scenes from Poly Haven (CC0), the gem environment of webgi (gem_2) and one spot light in the dark (spot1Lux of the three.js examples).

    A material view and a lighting preset are exclusive: choosing one turns the other off (the debug materials are unlit, so lights do not change them).

    Everything is applied only while the viewer renders (preRender to postRender): the override material of the main render pass, the hidden scene lights, the override environment, the line materials of the fat lines (forcedOverrideMaterial of the line object, or allowOverride false on the line material in the unlit view) and the materials of the widgets (allowOverride false). Outside a render the scene and the render pass are as the user left them, so an export, the scene UI and the light toggles see the real scene. Turning an override off, disabling the plugin or removing it shows the scene as before. The state is not saved with the viewer config.

    const overrides = viewer.addPluginSync(ViewOverridesPlugin)
    overrides.addEventListener('change', updateMenu)
    overrides.setMaterial('normal')
    await overrides.setLighting('env-studio')
    overrides.clear()

    Hierarchy (View Summary)

    Index
    _dirty: boolean = false
    _viewer?: ThreeViewer
    _viewerListeners: PartialRecord<IViewerEventTypes, (e: IViewerEvent) => void> = {}
    constructor: typeof AViewerPluginSync & typeof AViewerPlugin
    isViewerPluginSync: true = ...
    lightingPresets: ViewOverrideLightingPreset[] = ...

    The lighting presets, for a menu. Change a url, or add a preset, before its first use.

    lightsRoot: Group2<IObject3DEventMap, undefined, undefined> = ...

    Holds the preset lights, in the scene root (not in the model root), so they are not selectable or exported. Visible only during a render with a lighting preset on.

    materialTypes: readonly ViewOverrideMaterialItem[] = ...

    The material views, for a menu

    serializeWithViewer: boolean = false
    uiConfig: UiObjectConfig = ...
    OldPluginType?: string
    PluginType: "ViewOverridesPlugin" = 'ViewOverridesPlugin'
    • get lightsKeepEnvironment(): boolean

      False (default): the 'lights' presets also turn off the environment map, so the image shows only the preset lights. True: the scene environment stays on with the preset lights. A change applies at once to the 'lights' preset that is on (no effect on the 'env' presets, which replace the environment).

      Returns boolean

    • set lightsKeepEnvironment(keep: boolean): void

      Parameters

      • keep: boolean

      Returns void

    • Light the scene with a preset from lightingPresets: a 'lights' preset replaces the scene lights (and the environment, unless lightsKeepEnvironment) with its lights, an 'env' preset replaces them with its environment map (loaded on the first use, then cached). Null restores the scene lighting. Turns off a material view.

      While an environment map loads, loading is the key and the view does not change. When it does not load, the view stays as it was. Resolves when the preset is applied, when the map does not load, or when another call replaced it.

      Parameters

      • key: string | null

      Returns Promise<void>