UNPKG

@itwin/frontend-devtools

Version:

Debug menu and supporting UI widgets

112 lines 5.28 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 Tools */ import { Vector3d } from "@itwin/core-geometry"; import { RenderSchedule } from "@itwin/core-common"; import { IModelApp, Tool } from "@itwin/core-frontend"; var FadeMode; (function (FadeMode) { FadeMode[FadeMode["X"] = 0] = "X"; FadeMode[FadeMode["Y"] = 1] = "Y"; FadeMode[FadeMode["Z"] = 2] = "Z"; FadeMode[FadeMode["Transparent"] = 3] = "Transparent"; })(FadeMode || (FadeMode = {})); /** This tool applies a transition in X, Y, Z, or transparency. * @beta */ export class RealityTransitionTool extends Tool { static get minArgs() { return 0; } static get maxArgs() { return 1; } static toolId = "RealityTransition"; /** This method runs the tool, applying a transition in X, Y, Z, or transparency. * @param fadeMode whether to apply the transition in X, Y, Z, or transparency */ async run(fadeMode = FadeMode.X) { const vp = IModelApp.viewManager.selectedView; if (undefined === vp) return true; const displayStyle = vp.displayStyle; const view = vp.view; const timeNow = Date.now(), timeEnd = timeNow + 1000.0 * 60.0 * 60.0; const range = vp.iModel.projectExtents; const directions = [Vector3d.create(1, 0, 0), Vector3d.create(0, 1, 0), Vector3d.create(0, 0, 1)]; const modelInTimeline = { modelId: "", elementTimelines: [] }; const modelOutTimeline = { modelId: "", elementTimelines: [] }; switch (fadeMode) { case FadeMode.Transparent: { const fadeInTimeline = new Array(); fadeInTimeline.push({ time: timeNow, interpolation: 2, value: 100.0 }); fadeInTimeline.push({ time: timeEnd, interpolation: 2, value: 0.0 }); const fadeOutTimeline = new Array(); fadeOutTimeline.push({ time: timeNow, interpolation: 2, value: 0.0 }); fadeOutTimeline.push({ time: timeEnd, interpolation: 2, value: 100.0 }); modelInTimeline.visibilityTimeline = fadeInTimeline; modelOutTimeline.visibilityTimeline = fadeOutTimeline; break; } default: { const direction = directions[fadeMode - FadeMode.X]; const clipInTimeline = new Array(); clipInTimeline.push({ time: timeNow, interpolation: 2, value: { position: [range.low.x, range.low.y, range.low.z], direction: [direction.x, direction.y, direction.z] } }); clipInTimeline.push({ time: timeEnd, interpolation: 2, value: { position: [range.high.x, range.high.y, range.high.z], direction: [direction.x, direction.y, direction.z] } }); const clipOutTimeline = new Array(); clipOutTimeline.push({ time: timeNow, interpolation: 2, value: { position: [range.low.x, range.low.y, range.low.z], direction: [-direction.x, -direction.y, -direction.z] } }); clipOutTimeline.push({ time: timeEnd, interpolation: 2, value: { position: [range.high.x, range.high.y, range.high.z], direction: [-direction.x, -direction.y, -direction.z] } }); modelInTimeline.cuttingPlaneTimeline = clipInTimeline; modelOutTimeline.cuttingPlaneTimeline = clipOutTimeline; break; } } const scriptProps = []; view.forEachModel((model) => { scriptProps.push({ ...(model.jsonProperties.tilesetUrl ? modelOutTimeline : modelInTimeline), modelId: model.id, }); }); displayStyle.forEachRealityModel((model) => { const modelId = model.treeRef?.treeOwner.tileTree?.modelId; if (modelId) { scriptProps.push({ ...modelOutTimeline, modelId, realityModelUrl: model.url, }); } }); const script = RenderSchedule.Script.fromJSON(scriptProps); if (script) { displayStyle.scheduleScript = script; vp.timePoint = script.duration.low; } return true; } /** Executes this tool's run method. * @param args the first entry of this array contains either "x", "y", "z", or "transparent", indicating the type of transition to apply. * @see [[run]] */ async parseAndRun(...args) { const transitionNames = [ "x", "y", "z", "transparent", ]; let fade = FadeMode.X; if (0 !== args.length) { const arg = args[0].toLowerCase(); for (let i = 0; i < transitionNames.length; i++) { if (arg === transitionNames[i]) { fade = i; break; } } } return this.run(fade); } } //# sourceMappingURL=RealityTransitionTool.js.map