UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

62 lines 2.36 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Effects */ import { assert } from "@itwin/core-bentley"; import { IModelApp, Tool, } from "@itwin/core-frontend"; /** Adds a screen-space effect to the selected viewport. * @beta */ export class AddEffectTool extends Tool { static _registeredEffects = new Set(); async run() { // Avoid conflicts with the names of other registered screen-space effects. const name = `fdt ${this.effectName}`; if (!AddEffectTool._registeredEffects.has(name)) { // Register the effect. const builder = IModelApp.renderSystem.createScreenSpaceEffectBuilder({ name, textureCoordFromPosition: this.textureCoordFromPosition, source: this.source, }); assert(undefined !== builder); this.defineEffect(builder); builder.finish(); AddEffectTool._registeredEffects.add(name); } const vp = IModelApp.viewManager.selectedView; if (vp) vp.addScreenSpaceEffect(name); return true; } } /** Removes all screen-space effects from the selected viewport. * @beta */ export class ClearEffectsTool extends Tool { static toolId = "ClearEffects"; static get minArgs() { return 0; } static get maxArgs() { return 0; } async run() { IModelApp.viewManager.selectedView?.removeScreenSpaceEffects(); return true; } } /** Requests that any viewport to which the specified effect has been applied redraw its contents. * Used by tools like [[VignetteConfig]] to update the view after the effect parameters are modified. * @beta */ export function refreshViewportsForEffect(effectName) { for (const vp of IModelApp.viewManager) { for (const vpEffectName of vp.screenSpaceEffects) { if (vpEffectName === effectName) { vp.requestRedraw(); break; } } } } //# sourceMappingURL=EffectTools.js.map