UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

68 lines 2.74 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ClearEffectsTool = exports.AddEffectTool = void 0; exports.refreshViewportsForEffect = refreshViewportsForEffect; const core_bentley_1 = require("@itwin/core-bentley"); const core_frontend_1 = require("@itwin/core-frontend"); /** Adds a screen-space effect to the selected viewport. * @beta */ class AddEffectTool extends core_frontend_1.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 = core_frontend_1.IModelApp.renderSystem.createScreenSpaceEffectBuilder({ name, textureCoordFromPosition: this.textureCoordFromPosition, source: this.source, }); (0, core_bentley_1.assert)(undefined !== builder); this.defineEffect(builder); builder.finish(); AddEffectTool._registeredEffects.add(name); } const vp = core_frontend_1.IModelApp.viewManager.selectedView; if (vp) vp.addScreenSpaceEffect(name); return true; } } exports.AddEffectTool = AddEffectTool; /** Removes all screen-space effects from the selected viewport. * @beta */ class ClearEffectsTool extends core_frontend_1.Tool { static toolId = "ClearEffects"; static get minArgs() { return 0; } static get maxArgs() { return 0; } async run() { core_frontend_1.IModelApp.viewManager.selectedView?.removeScreenSpaceEffects(); return true; } } exports.ClearEffectsTool = ClearEffectsTool; /** 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 */ function refreshViewportsForEffect(effectName) { for (const vp of core_frontend_1.IModelApp.viewManager) { for (const vpEffectName of vp.screenSpaceEffects) { if (vpEffectName === effectName) { vp.requestRedraw(); break; } } } } //# sourceMappingURL=EffectTools.js.map