@itwin/frontend-devtools 5.0.0-dev.8 → 5.0.0-dev.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -1
- package/lib/cjs/FrontEndDevTools.js +1 -1
- package/lib/cjs/FrontEndDevTools.js.map +1 -1
- package/lib/cjs/effects/Convolution.js +6 -6
- package/lib/cjs/effects/Convolution.js.map +1 -1
- package/lib/cjs/effects/EffectTools.js +2 -2
- package/lib/cjs/effects/EffectTools.js.map +1 -1
- package/lib/cjs/effects/Explosion.js +37 -25
- package/lib/cjs/effects/Explosion.js.map +1 -1
- package/lib/cjs/effects/FlipImage.js +2 -2
- package/lib/cjs/effects/FlipImage.js.map +1 -1
- package/lib/cjs/effects/LensDistortion.js +4 -4
- package/lib/cjs/effects/LensDistortion.js.map +1 -1
- package/lib/cjs/effects/Saturation.js +4 -4
- package/lib/cjs/effects/Saturation.js.map +1 -1
- package/lib/cjs/effects/Snow.d.ts +1 -1
- package/lib/cjs/effects/Snow.d.ts.map +1 -1
- package/lib/cjs/effects/Snow.js +19 -8
- package/lib/cjs/effects/Snow.js.map +1 -1
- package/lib/cjs/effects/Vignette.js +12 -12
- package/lib/cjs/effects/Vignette.js.map +1 -1
- package/lib/cjs/tools/AnimationIntervalTool.js +1 -1
- package/lib/cjs/tools/AnimationIntervalTool.js.map +1 -1
- package/lib/cjs/tools/ChangeUnitsTool.js +1 -1
- package/lib/cjs/tools/ChangeUnitsTool.js.map +1 -1
- package/lib/cjs/tools/ClipTools.js +6 -8
- package/lib/cjs/tools/ClipTools.js.map +1 -1
- package/lib/cjs/tools/DisplayStyleTools.js +21 -25
- package/lib/cjs/tools/DisplayStyleTools.js.map +1 -1
- package/lib/cjs/tools/EmphasizeElementsTool.js +7 -13
- package/lib/cjs/tools/EmphasizeElementsTool.js.map +1 -1
- package/lib/cjs/tools/FrustumDecoration.js +28 -9
- package/lib/cjs/tools/FrustumDecoration.js.map +1 -1
- package/lib/cjs/tools/InspectElementTool.js +7 -6
- package/lib/cjs/tools/InspectElementTool.js.map +1 -1
- package/lib/cjs/tools/MapLayerTool.js +24 -20
- package/lib/cjs/tools/MapLayerTool.js.map +1 -1
- package/lib/cjs/tools/MeasureTileLoadTime.js +4 -1
- package/lib/cjs/tools/MeasureTileLoadTime.js.map +1 -1
- package/lib/cjs/tools/ModelAppearanceTools.js +9 -9
- package/lib/cjs/tools/ModelAppearanceTools.js.map +1 -1
- package/lib/cjs/tools/PlanProjectionTools.js +8 -15
- package/lib/cjs/tools/PlanProjectionTools.js.map +1 -1
- package/lib/cjs/tools/PlanarMaskTools.js +21 -26
- package/lib/cjs/tools/PlanarMaskTools.js.map +1 -1
- package/lib/cjs/tools/ProjectExtents.js +6 -3
- package/lib/cjs/tools/ProjectExtents.js.map +1 -1
- package/lib/cjs/tools/RealityModelTools.js +10 -10
- package/lib/cjs/tools/RealityModelTools.js.map +1 -1
- package/lib/cjs/tools/RealityTransitionTool.js +1 -1
- package/lib/cjs/tools/RealityTransitionTool.js.map +1 -1
- package/lib/cjs/tools/RenderSystemTools.js +4 -3
- package/lib/cjs/tools/RenderSystemTools.js.map +1 -1
- package/lib/cjs/tools/RenderTargetTools.d.ts +1 -1
- package/lib/cjs/tools/RenderTargetTools.d.ts.map +1 -1
- package/lib/cjs/tools/RenderTargetTools.js +15 -20
- package/lib/cjs/tools/RenderTargetTools.js.map +1 -1
- package/lib/cjs/tools/ReportWebGLCompatibilityTool.js +1 -1
- package/lib/cjs/tools/ReportWebGLCompatibilityTool.js.map +1 -1
- package/lib/cjs/tools/SavedViews.js +4 -7
- package/lib/cjs/tools/SavedViews.js.map +1 -1
- package/lib/cjs/tools/ScheduleScriptTools.d.ts.map +1 -1
- package/lib/cjs/tools/ScheduleScriptTools.js +11 -12
- package/lib/cjs/tools/ScheduleScriptTools.js.map +1 -1
- package/lib/cjs/tools/SelectionTools.js +4 -6
- package/lib/cjs/tools/SelectionTools.js.map +1 -1
- package/lib/cjs/tools/SetGpuMemoryLimitTool.js +1 -1
- package/lib/cjs/tools/SetGpuMemoryLimitTool.js.map +1 -1
- package/lib/cjs/tools/SourceAspectIdTools.js +2 -2
- package/lib/cjs/tools/SourceAspectIdTools.js.map +1 -1
- package/lib/cjs/tools/TileRequestDecoration.js +6 -3
- package/lib/cjs/tools/TileRequestDecoration.js.map +1 -1
- package/lib/cjs/tools/TileTreeBoundsDecoration.d.ts.map +1 -1
- package/lib/cjs/tools/TileTreeBoundsDecoration.js +8 -4
- package/lib/cjs/tools/TileTreeBoundsDecoration.js.map +1 -1
- package/lib/cjs/tools/ToolTipProvider.js +2 -1
- package/lib/cjs/tools/ToolTipProvider.js.map +1 -1
- package/lib/cjs/tools/ViewportTools.js +22 -19
- package/lib/cjs/tools/ViewportTools.js.map +1 -1
- package/lib/cjs/widgets/DiagnosticsPanel.d.ts +1 -1
- package/lib/cjs/widgets/DiagnosticsPanel.d.ts.map +1 -1
- package/lib/cjs/widgets/DiagnosticsPanel.js +11 -1
- package/lib/cjs/widgets/DiagnosticsPanel.js.map +1 -1
- package/lib/cjs/widgets/FpsTracker.d.ts +1 -1
- package/lib/cjs/widgets/FpsTracker.d.ts.map +1 -1
- package/lib/cjs/widgets/FpsTracker.js +5 -1
- package/lib/cjs/widgets/FpsTracker.js.map +1 -1
- package/lib/cjs/widgets/GpuProfiler.d.ts +1 -1
- package/lib/cjs/widgets/GpuProfiler.d.ts.map +1 -1
- package/lib/cjs/widgets/GpuProfiler.js +89 -82
- package/lib/cjs/widgets/GpuProfiler.js.map +1 -1
- package/lib/cjs/widgets/KeyinField.js +8 -1
- package/lib/cjs/widgets/KeyinField.js.map +1 -1
- package/lib/cjs/widgets/MemoryTracker.d.ts +1 -1
- package/lib/cjs/widgets/MemoryTracker.d.ts.map +1 -1
- package/lib/cjs/widgets/MemoryTracker.js +16 -4
- package/lib/cjs/widgets/MemoryTracker.js.map +1 -1
- package/lib/cjs/widgets/RenderCommandBreakdown.d.ts +1 -1
- package/lib/cjs/widgets/RenderCommandBreakdown.d.ts.map +1 -1
- package/lib/cjs/widgets/RenderCommandBreakdown.js +6 -2
- package/lib/cjs/widgets/RenderCommandBreakdown.js.map +1 -1
- package/lib/cjs/widgets/TileMemoryBreakdown.d.ts +1 -1
- package/lib/cjs/widgets/TileMemoryBreakdown.d.ts.map +1 -1
- package/lib/cjs/widgets/TileMemoryBreakdown.js +10 -8
- package/lib/cjs/widgets/TileMemoryBreakdown.js.map +1 -1
- package/lib/cjs/widgets/TileStatisticsTracker.d.ts +1 -1
- package/lib/cjs/widgets/TileStatisticsTracker.d.ts.map +1 -1
- package/lib/cjs/widgets/TileStatisticsTracker.js +5 -2
- package/lib/cjs/widgets/TileStatisticsTracker.js.map +1 -1
- package/lib/cjs/widgets/ToolSettingsTracker.d.ts +1 -1
- package/lib/cjs/widgets/ToolSettingsTracker.d.ts.map +1 -1
- package/lib/cjs/widgets/ToolSettingsTracker.js +2 -2
- package/lib/cjs/widgets/ToolSettingsTracker.js.map +1 -1
- package/lib/esm/FrontEndDevTools.js +1 -1
- package/lib/esm/FrontEndDevTools.js.map +1 -1
- package/lib/esm/effects/Convolution.js +6 -6
- package/lib/esm/effects/Convolution.js.map +1 -1
- package/lib/esm/effects/EffectTools.js +2 -2
- package/lib/esm/effects/EffectTools.js.map +1 -1
- package/lib/esm/effects/Explosion.js +37 -25
- package/lib/esm/effects/Explosion.js.map +1 -1
- package/lib/esm/effects/FlipImage.js +2 -2
- package/lib/esm/effects/FlipImage.js.map +1 -1
- package/lib/esm/effects/LensDistortion.js +4 -4
- package/lib/esm/effects/LensDistortion.js.map +1 -1
- package/lib/esm/effects/Saturation.js +4 -4
- package/lib/esm/effects/Saturation.js.map +1 -1
- package/lib/esm/effects/Snow.d.ts +1 -1
- package/lib/esm/effects/Snow.d.ts.map +1 -1
- package/lib/esm/effects/Snow.js +19 -8
- package/lib/esm/effects/Snow.js.map +1 -1
- package/lib/esm/effects/Vignette.js +12 -12
- package/lib/esm/effects/Vignette.js.map +1 -1
- package/lib/esm/tools/AnimationIntervalTool.js +1 -1
- package/lib/esm/tools/AnimationIntervalTool.js.map +1 -1
- package/lib/esm/tools/ChangeUnitsTool.js +1 -1
- package/lib/esm/tools/ChangeUnitsTool.js.map +1 -1
- package/lib/esm/tools/ClipTools.js +6 -8
- package/lib/esm/tools/ClipTools.js.map +1 -1
- package/lib/esm/tools/DisplayStyleTools.js +21 -25
- package/lib/esm/tools/DisplayStyleTools.js.map +1 -1
- package/lib/esm/tools/EmphasizeElementsTool.js +7 -13
- package/lib/esm/tools/EmphasizeElementsTool.js.map +1 -1
- package/lib/esm/tools/FrustumDecoration.js +28 -9
- package/lib/esm/tools/FrustumDecoration.js.map +1 -1
- package/lib/esm/tools/InspectElementTool.js +7 -6
- package/lib/esm/tools/InspectElementTool.js.map +1 -1
- package/lib/esm/tools/MapLayerTool.js +24 -20
- package/lib/esm/tools/MapLayerTool.js.map +1 -1
- package/lib/esm/tools/MeasureTileLoadTime.js +4 -1
- package/lib/esm/tools/MeasureTileLoadTime.js.map +1 -1
- package/lib/esm/tools/ModelAppearanceTools.js +9 -9
- package/lib/esm/tools/ModelAppearanceTools.js.map +1 -1
- package/lib/esm/tools/PlanProjectionTools.js +8 -15
- package/lib/esm/tools/PlanProjectionTools.js.map +1 -1
- package/lib/esm/tools/PlanarMaskTools.js +21 -26
- package/lib/esm/tools/PlanarMaskTools.js.map +1 -1
- package/lib/esm/tools/ProjectExtents.js +6 -3
- package/lib/esm/tools/ProjectExtents.js.map +1 -1
- package/lib/esm/tools/RealityModelTools.js +10 -10
- package/lib/esm/tools/RealityModelTools.js.map +1 -1
- package/lib/esm/tools/RealityTransitionTool.js +1 -1
- package/lib/esm/tools/RealityTransitionTool.js.map +1 -1
- package/lib/esm/tools/RenderSystemTools.js +4 -3
- package/lib/esm/tools/RenderSystemTools.js.map +1 -1
- package/lib/esm/tools/RenderTargetTools.d.ts +1 -1
- package/lib/esm/tools/RenderTargetTools.d.ts.map +1 -1
- package/lib/esm/tools/RenderTargetTools.js +15 -20
- package/lib/esm/tools/RenderTargetTools.js.map +1 -1
- package/lib/esm/tools/ReportWebGLCompatibilityTool.js +1 -1
- package/lib/esm/tools/ReportWebGLCompatibilityTool.js.map +1 -1
- package/lib/esm/tools/SavedViews.js +4 -7
- package/lib/esm/tools/SavedViews.js.map +1 -1
- package/lib/esm/tools/ScheduleScriptTools.d.ts.map +1 -1
- package/lib/esm/tools/ScheduleScriptTools.js +11 -12
- package/lib/esm/tools/ScheduleScriptTools.js.map +1 -1
- package/lib/esm/tools/SelectionTools.js +4 -6
- package/lib/esm/tools/SelectionTools.js.map +1 -1
- package/lib/esm/tools/SetGpuMemoryLimitTool.js +1 -1
- package/lib/esm/tools/SetGpuMemoryLimitTool.js.map +1 -1
- package/lib/esm/tools/SourceAspectIdTools.js +2 -2
- package/lib/esm/tools/SourceAspectIdTools.js.map +1 -1
- package/lib/esm/tools/TileRequestDecoration.js +6 -3
- package/lib/esm/tools/TileRequestDecoration.js.map +1 -1
- package/lib/esm/tools/TileTreeBoundsDecoration.d.ts.map +1 -1
- package/lib/esm/tools/TileTreeBoundsDecoration.js +8 -4
- package/lib/esm/tools/TileTreeBoundsDecoration.js.map +1 -1
- package/lib/esm/tools/ToolTipProvider.js +2 -1
- package/lib/esm/tools/ToolTipProvider.js.map +1 -1
- package/lib/esm/tools/ViewportTools.js +22 -19
- package/lib/esm/tools/ViewportTools.js.map +1 -1
- package/lib/esm/widgets/DiagnosticsPanel.d.ts +1 -1
- package/lib/esm/widgets/DiagnosticsPanel.d.ts.map +1 -1
- package/lib/esm/widgets/DiagnosticsPanel.js +11 -1
- package/lib/esm/widgets/DiagnosticsPanel.js.map +1 -1
- package/lib/esm/widgets/FpsTracker.d.ts +1 -1
- package/lib/esm/widgets/FpsTracker.d.ts.map +1 -1
- package/lib/esm/widgets/FpsTracker.js +5 -1
- package/lib/esm/widgets/FpsTracker.js.map +1 -1
- package/lib/esm/widgets/GpuProfiler.d.ts +1 -1
- package/lib/esm/widgets/GpuProfiler.d.ts.map +1 -1
- package/lib/esm/widgets/GpuProfiler.js +89 -82
- package/lib/esm/widgets/GpuProfiler.js.map +1 -1
- package/lib/esm/widgets/KeyinField.js +8 -1
- package/lib/esm/widgets/KeyinField.js.map +1 -1
- package/lib/esm/widgets/MemoryTracker.d.ts +1 -1
- package/lib/esm/widgets/MemoryTracker.d.ts.map +1 -1
- package/lib/esm/widgets/MemoryTracker.js +16 -4
- package/lib/esm/widgets/MemoryTracker.js.map +1 -1
- package/lib/esm/widgets/RenderCommandBreakdown.d.ts +1 -1
- package/lib/esm/widgets/RenderCommandBreakdown.d.ts.map +1 -1
- package/lib/esm/widgets/RenderCommandBreakdown.js +6 -2
- package/lib/esm/widgets/RenderCommandBreakdown.js.map +1 -1
- package/lib/esm/widgets/TileMemoryBreakdown.d.ts +1 -1
- package/lib/esm/widgets/TileMemoryBreakdown.d.ts.map +1 -1
- package/lib/esm/widgets/TileMemoryBreakdown.js +10 -8
- package/lib/esm/widgets/TileMemoryBreakdown.js.map +1 -1
- package/lib/esm/widgets/TileStatisticsTracker.d.ts +1 -1
- package/lib/esm/widgets/TileStatisticsTracker.d.ts.map +1 -1
- package/lib/esm/widgets/TileStatisticsTracker.js +5 -2
- package/lib/esm/widgets/TileStatisticsTracker.js.map +1 -1
- package/lib/esm/widgets/ToolSettingsTracker.d.ts +1 -1
- package/lib/esm/widgets/ToolSettingsTracker.d.ts.map +1 -1
- package/lib/esm/widgets/ToolSettingsTracker.js +2 -2
- package/lib/esm/widgets/ToolSettingsTracker.js.map +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensDistortion.js","sourceRoot":"","sources":["../../../src/effects/LensDistortion.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,wDAAgG;AAChG,+CAAyE;AACzE,kDAA+C;AAE/C;;;;;GAKG;AACH,MAAa,oBAAqB,SA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AG,CAAC;IAErB,KAAK,CAAC,GAAG,CAAC,QAAiB,EAAE,KAAc;QACzD,oBAAoB,CAAC,QAAQ,GAAG,QAAQ,IAAI,GAAG,CAAC;QAChD,oBAAoB,CAAC,gBAAgB,GAAG,KAAK,IAAI,GAAG,CAAC;QACrD,IAAA,uCAAyB,EAAC,oBAAoB,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,CAAC;;AAlBH,oDAmBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport { ScreenSpaceEffectBuilder, Tool, UniformType, VaryingType } from \"@itwin/core-frontend\";\nimport { AddEffectTool, refreshViewportsForEffect } from \"./EffectTools\";\nimport { parseArgs } from \"../tools/parseArgs\";\n\n/** Adds a screen-space effect to the selected [[Viewport]] to simulate the lens distortion produced by real-world cameras with very wide fields of view.\n * Based on https://www.decarpentier.nl/lens-distortion\n * The effect is improved considerably by enabling anti-aliasing (e.g., via [RenderSystem.Options.antialiasSamples]($frontend) at startup, or using the `fdt aasamples` key-in`).\n * @note Because this effect applies a non-linear transform to each pixel, operations like snapping to geometry will not work properly. Element locate will work however - @see [ScreenSpaceEffectSource.sampleSourcePixel]($frontend).\n * @beta\n */\nexport class LensDistortionEffect extends AddEffectTool {\n public static override toolId = \"LensDistortionEffect\";\n\n protected get effectName() { return \"lensdistortion\"; }\n protected get textureCoordFromPosition() { return true; }\n\n protected get source() {\n return {\n vertex: `\n void effectMain(vec4 position) {\n vec2 uv = textureCoordFromPosition(position);\n float scaledHeight = strength * height;\n float cylAspectRatio = aspectRatio * cylindricalRatio;\n float aspectDiagSq = aspectRatio * aspectRatio + 1.0;\n float diagSq = scaledHeight * scaledHeight * aspectDiagSq;\n vec2 signedUV = (2.0 * uv + vec2(-1.0, -1.0));\n\n float z = 0.5 * sqrt(diagSq + 1.0) + 0.5;\n float ny = (z - 1.0) / (cylAspectRatio * cylAspectRatio + 1.0);\n\n vUVDot = sqrt(ny) * vec2(cylAspectRatio, 1.0) * signedUV;\n vUV = vec3(0.5, 0.5, 1.0) * z + vec3(-0.5, -0.5, 0.0);\n vUV.xy += uv;\n }`,\n // We simply shift pixels - we don't alter their colors.\n fragment: `\n vec4 effectMain() {\n return sampleSourcePixel();\n }`,\n // Because we're moving pixels around, we must tell the render system where the source pixel was originally located - otherwise\n // element locate will not work correctly.\n sampleSourcePixel: `\n vec3 uv = dot(vUVDot, vUVDot) * vec3(-0.5, -0.5, -1.0) + vUV;\n return TEXTURE_PROJ(u_diffuse, uv);\n `,\n };\n }\n\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\n // Lens distortion is only applicable to views with the camera enabled.\n builder.shouldApply = (context) => context.viewport.isCameraOn;\n\n builder.addVarying(\"vUV\", VaryingType.Vec3);\n builder.addVarying(\"vUVDot\", VaryingType.Vec2);\n\n builder.addUniform({\n name: \"strength\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(LensDistortionConfig.strength),\n });\n builder.addUniform({\n name: \"cylindricalRatio\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(LensDistortionConfig.cylindricalRatio),\n });\n builder.addUniform({\n name: \"aspectRatio\",\n type: UniformType.Float,\n bind: (uniform, context) => uniform.setUniform1f(context.viewport.viewRect.aspect),\n });\n builder.addUniform({\n name: \"height\",\n type: UniformType.Float,\n bind: (uniform, context) => {\n assert(context.viewport.view.is3d() && context.viewport.view.isCameraOn);\n const fov = context.viewport.view.camera.lens.radians;\n const height = Math.tan(fov / 2) / context.viewport.viewRect.aspect;\n uniform.setUniform1f(height);\n },\n });\n }\n}\n\n/** Configures the [[LensDistortionEffect]].\n * @beta\n */\nexport class LensDistortionConfig extends Tool {\n public static override toolId = \"LensDistortionConfig\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 2; }\n\n public static strength = 0.5;\n public static cylindricalRatio = 0.5;\n\n public override async run(strength?: number, ratio?: number): Promise<boolean> {\n LensDistortionConfig.strength = strength ?? 0.5;\n LensDistortionConfig.cylindricalRatio = ratio ?? 0.5;\n refreshViewportsForEffect(\"fdt lensdistortion\");\n return true;\n }\n\n public override async parseAndRun(...input: string[]): Promise<boolean> {\n const args = parseArgs(input);\n return this.run(args.getFloat(\"s\"), args.getFloat(\"r\"));\n }\n}\n"]}
|
|
@@ -15,6 +15,7 @@ const EffectTools_1 = require("./EffectTools");
|
|
|
15
15
|
* @beta
|
|
16
16
|
*/
|
|
17
17
|
class SaturationEffect extends EffectTools_1.AddEffectTool {
|
|
18
|
+
static toolId = "SaturationEffect";
|
|
18
19
|
get effectName() { return "Saturation"; }
|
|
19
20
|
get textureCoordFromPosition() { return true; }
|
|
20
21
|
get source() {
|
|
@@ -62,13 +63,15 @@ class SaturationEffect extends EffectTools_1.AddEffectTool {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
exports.SaturationEffect = SaturationEffect;
|
|
65
|
-
SaturationEffect.toolId = "SaturationEffect";
|
|
66
66
|
/** Configures the [[SaturationEffect]].
|
|
67
67
|
* @beta
|
|
68
68
|
*/
|
|
69
69
|
class SaturationConfig extends core_frontend_1.Tool {
|
|
70
|
+
static toolId = "SaturationConfig";
|
|
70
71
|
static get minArgs() { return 0; }
|
|
71
72
|
static get maxArgs() { return 1; }
|
|
73
|
+
/** Multiplier applied to the saturation of each color in the source image. */
|
|
74
|
+
static multiplier = 2.0;
|
|
72
75
|
async run(multiplier) {
|
|
73
76
|
SaturationConfig.multiplier = multiplier ?? 2.0;
|
|
74
77
|
(0, EffectTools_1.refreshViewportsForEffect)("fdt Saturation");
|
|
@@ -80,7 +83,4 @@ class SaturationConfig extends core_frontend_1.Tool {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
exports.SaturationConfig = SaturationConfig;
|
|
83
|
-
SaturationConfig.toolId = "SaturationConfig";
|
|
84
|
-
/** Multiplier applied to the saturation of each color in the source image. */
|
|
85
|
-
SaturationConfig.multiplier = 2.0;
|
|
86
86
|
//# sourceMappingURL=Saturation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Saturation.js","sourceRoot":"","sources":["../../../src/effects/Saturation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAgG;AAChG,kDAA+C;AAC/C,+CAAyE;AAEzE;;GAEG;AACH,MAAa,gBAAiB,SAAQ,2BAAa;
|
|
1
|
+
{"version":3,"file":"Saturation.js","sourceRoot":"","sources":["../../../src/effects/Saturation.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAgG;AAChG,kDAA+C;AAC/C,+CAAyE;AAEzE;;GAEG;AACH,MAAa,gBAAiB,SAAQ,2BAAa;IAC1C,MAAM,CAAU,MAAM,GAAG,kBAAkB,CAAC;IAEnD,IAAc,UAAU,KAAK,OAAO,YAAY,CAAC,CAAC,CAAC;IACnD,IAAc,wBAAwB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD,IAAc,MAAM;QAClB,sIAAsI;QACtI,OAAO;YACL,qEAAqE;YACrE,MAAM,EAAE;;;UAGJ;YACJ,2FAA2F;YAC3F,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;UAuBN;SACL,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,OAAiC;QACtD,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,2BAAW,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,UAAU,CAAC;YACjB,IAAI,EAAE,kBAAkB;YACxB,IAAI,EAAE,2BAAW,CAAC,KAAK;YACvB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC;SACrE,CAAC,CAAC;IACL,CAAC;;AAjDH,4CAkDC;AAED;;GAEG;AACH,MAAa,gBAAiB,SAAQ,oBAAI;IACjC,MAAM,CAAU,MAAM,GAAG,kBAAkB,CAAC;IAC5C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAElD,8EAA8E;IACvE,MAAM,CAAC,UAAU,GAAG,GAAG,CAAC;IAEf,KAAK,CAAC,GAAG,CAAC,UAAmB;QAC3C,gBAAgB,CAAC,UAAU,GAAG,UAAU,IAAI,GAAG,CAAC;QAChD,IAAA,uCAAyB,EAAC,gBAAgB,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;;AAjBH,4CAkBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { ScreenSpaceEffectBuilder, Tool, UniformType, VaryingType } from \"@itwin/core-frontend\";\nimport { parseArgs } from \"../tools/parseArgs\";\nimport { AddEffectTool, refreshViewportsForEffect } from \"./EffectTools\";\n\n/** Adjusts the saturation of colors in a viewport.\n * @beta\n */\nexport class SaturationEffect extends AddEffectTool {\n public static override toolId = \"SaturationEffect\";\n\n protected get effectName() { return \"Saturation\"; }\n protected get textureCoordFromPosition() { return true; }\n\n protected get source() {\n // rgb <-> hsl conversion routines from https://gamedev.stackexchange.com/questions/59797/glsl-shader-change-hue-saturation-brightness\n return {\n // Vertex shader simply computes texture coordinate for source pixel.\n vertex: `\n void effectMain(vec4 pos) {\n v_texCoord = textureCoordFromPosition(pos);\n }`,\n // Fragment shader converts color to HSV, adjusts the saturation, and converts back to RGB.\n fragment: `\n vec3 rgb2hsv(vec3 c) {\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n }\n\n vec3 hsv2rgb(vec3 c) {\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n }\n\n vec4 effectMain() {\n vec4 color = TEXTURE(u_diffuse, v_texCoord);\n color.rgb = rgb2hsv(color.rgb);\n color.rgb.y = color.rgb.y * u_saturationMult;\n color.rgb = hsv2rgb(color.rgb);\n return color;\n }`,\n };\n }\n\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\n builder.addVarying(\"v_texCoord\", VaryingType.Vec2);\n builder.addUniform({\n name: \"u_saturationMult\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(SaturationConfig.multiplier),\n });\n }\n}\n\n/** Configures the [[SaturationEffect]].\n * @beta\n */\nexport class SaturationConfig extends Tool {\n public static override toolId = \"SaturationConfig\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n /** Multiplier applied to the saturation of each color in the source image. */\n public static multiplier = 2.0;\n\n public override async run(multiplier?: number): Promise<boolean> {\n SaturationConfig.multiplier = multiplier ?? 2.0;\n refreshViewportsForEffect(\"fdt Saturation\");\n return true;\n }\n\n public override async parseAndRun(...input: string[]): Promise<boolean> {\n const args = parseArgs(input);\n return this.run(args.getFloat(\"s\"));\n }\n}\n\n"]}
|
|
@@ -41,7 +41,7 @@ export declare class SnowDecorator implements Decorator {
|
|
|
41
41
|
/** The viewport being decorated. */
|
|
42
42
|
readonly viewport: Viewport;
|
|
43
43
|
/** Invoked when this decorator is to be destroyed. */
|
|
44
|
-
readonly dispose: VoidFunction;
|
|
44
|
+
readonly [Symbol.dispose]: VoidFunction;
|
|
45
45
|
/** The initial width and height of the viewport, from which we randomly select each particle's initial position. */
|
|
46
46
|
private readonly _dimensions;
|
|
47
47
|
/** The list of particles being drawn. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snow.d.ts","sourceRoot":"","sources":["../../../src/effects/Snow.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAW,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,EACL,eAAe,EAAE,SAAS,EAA0E,aAAa,EAAE,IAAI,EAAE,QAAQ,EAClI,MAAM,sBAAsB,CAAC;AAI9B;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,oDAAoD;IACpD,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IAEV,8CAA8C;IAC9C,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,sKAAsK;IACtK,YAAY,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,SAAS,EAAE,OAAO,CA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,EAAE,QAAQ,CAAC;IACnC,sDAAsD;IACtD,SAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;IAC/C,oHAAoH;IACpH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,yCAAyC;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAAC,CAAgB;IACjC,sEAAsE;IACtE,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IAErC,OAAO;IAuCA,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IA0B/C,8DAA8D;IACvD,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI;IAQnD,sDAAsD;IACtD,OAAO,CAAC,IAAI;IAaZ,OAAO,CAAC,eAAe;IA4CvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAEzE;;;OAGG;WACiB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAmBhF;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,IAAI;IAClC,OAAuB,MAAM,SAAgB;IAEvB,GAAG,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAQvC,WAAW,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAOvE"}
|
package/lib/cjs/effects/Snow.js
CHANGED
|
@@ -29,9 +29,20 @@ const defaultSnowParams = {
|
|
|
29
29
|
* @beta
|
|
30
30
|
*/
|
|
31
31
|
class SnowDecorator {
|
|
32
|
+
/** The viewport being decorated. */
|
|
33
|
+
viewport;
|
|
34
|
+
/** Invoked when this decorator is to be destroyed. */
|
|
35
|
+
[Symbol.dispose];
|
|
36
|
+
/** The initial width and height of the viewport, from which we randomly select each particle's initial position. */
|
|
37
|
+
_dimensions;
|
|
38
|
+
/** The list of particles being drawn. */
|
|
39
|
+
_particles = [];
|
|
40
|
+
/** The image to display for each particle. */
|
|
41
|
+
_texture;
|
|
42
|
+
/** The last time `updateParticles()` was invoked, in milliseconds. */
|
|
43
|
+
_lastUpdateTime;
|
|
44
|
+
_params;
|
|
32
45
|
constructor(viewport, texture) {
|
|
33
|
-
/** The list of particles being drawn. */
|
|
34
|
-
this._particles = [];
|
|
35
46
|
this._params = { ...defaultSnowParams };
|
|
36
47
|
this.viewport = viewport;
|
|
37
48
|
this._dimensions = new core_geometry_1.Point2d(viewport.viewRect.width, viewport.viewRect.height);
|
|
@@ -44,13 +55,13 @@ class SnowDecorator {
|
|
|
44
55
|
// Transfer ownership of the texture to the new decorator.
|
|
45
56
|
const tex = this._texture;
|
|
46
57
|
this._texture = undefined;
|
|
47
|
-
this.dispose();
|
|
58
|
+
this[Symbol.dispose]();
|
|
48
59
|
new SnowDecorator(viewport, tex);
|
|
49
60
|
});
|
|
50
61
|
// When the viewport is destroyed, dispose of this decorator too.
|
|
51
|
-
const removeOnDispose = viewport.onDisposed.addListener(() => this.dispose());
|
|
62
|
+
const removeOnDispose = viewport.onDisposed.addListener(() => this[Symbol.dispose]());
|
|
52
63
|
const removeDecorator = core_frontend_1.IModelApp.viewManager.addDecorator(this);
|
|
53
|
-
this.dispose = () => {
|
|
64
|
+
this[Symbol.dispose] = () => {
|
|
54
65
|
removeDecorator();
|
|
55
66
|
removeOnRender();
|
|
56
67
|
removeOnDispose();
|
|
@@ -141,6 +152,7 @@ class SnowDecorator {
|
|
|
141
152
|
this._particles[i] = this.emit(false);
|
|
142
153
|
}
|
|
143
154
|
}
|
|
155
|
+
static _decorators = new Map();
|
|
144
156
|
/** Toggle this decorator for the specified viewport.
|
|
145
157
|
* @param viewport The viewport to which the effect should be applied or removed.
|
|
146
158
|
* @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.
|
|
@@ -150,7 +162,7 @@ class SnowDecorator {
|
|
|
150
162
|
if (undefined === enable)
|
|
151
163
|
enable = undefined === decorator;
|
|
152
164
|
if (undefined !== decorator && !enable)
|
|
153
|
-
decorator.dispose();
|
|
165
|
+
decorator[Symbol.dispose]();
|
|
154
166
|
else if (undefined === decorator && enable) {
|
|
155
167
|
// Create a texture to use for the particles.
|
|
156
168
|
// Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.
|
|
@@ -164,12 +176,12 @@ class SnowDecorator {
|
|
|
164
176
|
}
|
|
165
177
|
}
|
|
166
178
|
exports.SnowDecorator = SnowDecorator;
|
|
167
|
-
SnowDecorator._decorators = new Map();
|
|
168
179
|
/** Toggles a decorator that simulates snow using particle effects.
|
|
169
180
|
* @see [[SnowDecorator]] for the implementation of the decorator.
|
|
170
181
|
* @beta
|
|
171
182
|
*/
|
|
172
183
|
class SnowEffect extends core_frontend_1.Tool {
|
|
184
|
+
static toolId = "SnowEffect";
|
|
173
185
|
async run(enable) {
|
|
174
186
|
const vp = core_frontend_1.IModelApp.viewManager.selectedView;
|
|
175
187
|
if (vp)
|
|
@@ -184,5 +196,4 @@ class SnowEffect extends core_frontend_1.Tool {
|
|
|
184
196
|
}
|
|
185
197
|
}
|
|
186
198
|
exports.SnowEffect = SnowEffect;
|
|
187
|
-
SnowEffect.toolId = "SnowEffect";
|
|
188
199
|
//# sourceMappingURL=Snow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snow.js","sourceRoot":"","sources":["../../../src/effects/Snow.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA8C;AAC9C,wDAA2E;AAC3E,oDAAwE;AACxE,wDAE8B;AAC9B,sDAAmD;AACnD,qCAAsD;AAkCtD,+EAA+E;AAC/E,MAAM,iBAAiB,GAAe;IACpC,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,uBAAO,CAAC,QAAQ,CAAC,CAAC,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C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AAjBH,gCAkBC;AAjBwB,iBAAM,GAAG,YAAY,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { dispose } from \"@itwin/core-bentley\";\nimport { Point2d, Range1d, Range2d, Vector2d } from \"@itwin/core-geometry\";\nimport { RenderTexture, TextureTransparency } from \"@itwin/core-common\";\nimport {\n DecorateContext, Decorator, GraphicType, imageElementFromUrl, IModelApp, ParticleCollectionBuilder, ParticleProps, Tool, Viewport,\n} from \"@itwin/core-frontend\";\nimport { parseToggle } from \"../tools/parseToggle\";\nimport { randomFloat, randomInteger } from \"./Random\";\n\n/** Represents one particle displayed by a [[SnowDecorator]].\n * Particle positions are in [CoordSystem.View]($frontend).\n * @beta\n */\nexport interface SnowParticle extends ParticleProps {\n /** Make x, y, and z from ParticleProps writable. */\n x: number;\n y: number;\n z: number;\n\n /** Current velocity, in pixels per second. */\n velocity: Vector2d;\n}\n\n/** Parameters controlling how a [[SnowDecorator]] works.\n * @beta\n */\nexport interface SnowParams {\n /** The number of snow particles to produce. This could alternatively be expressed as a density so that small viewports would not be more crowded than larger ones. */\n numParticles: number;\n /** Range from which to randomly select each particle's size, in pixels. */\n sizeRange: Range1d;\n /** Range from which to randomly select each particle's transparency. */\n transparencyRange: Range1d;\n /** Range from which to randomly select each particle's initial velocity, in pixels per second. */\n velocityRange: Range2d;\n /** Range from which to randomly select an acceleration to apply to each particle's velocity each frame, in pixels per second squared, to simulate wind. */\n accelerationRange: Range2d;\n /** Wind velocity in pixels per second in X. */\n windVelocity: number;\n}\n\n/** The default snow effect parameters used by newly-created SnowDecorators. */\nconst defaultSnowParams: SnowParams = {\n numParticles: 2000,\n sizeRange: Range1d.createXX(3, 22),\n transparencyRange: Range1d.createXX(0, 50),\n velocityRange: new Range2d(-30, 50, 30, 130),\n accelerationRange: new Range2d(-1, -0.25, 1, 0.25),\n windVelocity: 0,\n};\n\n/** Simulates snowfall in a [Viewport]($frontend) using particle effects.\n * @see [[SnowEffect]] for a [Tool]($frontend) that toggles this decorator.\n * @see [ParticleCollectionBuilder]($frontend) for defining custom particle effects.\n * @beta\n */\nexport class SnowDecorator implements Decorator {\n /** The viewport being decorated. */\n public readonly viewport: Viewport;\n /** Invoked when this decorator is to be destroyed. */\n public readonly dispose: VoidFunction;\n /** The initial width and height of the viewport, from which we randomly select each particle's initial position. */\n private readonly _dimensions: Point2d;\n /** The list of particles being drawn. */\n private readonly _particles: SnowParticle[] = [];\n /** The image to display for each particle. */\n private _texture?: RenderTexture;\n /** The last time `updateParticles()` was invoked, in milliseconds. */\n private _lastUpdateTime: number;\n private readonly _params: SnowParams;\n\n private constructor(viewport: Viewport, texture: RenderTexture | undefined) {\n this._params = { ...defaultSnowParams };\n this.viewport = viewport;\n this._dimensions = new Point2d(viewport.viewRect.width, viewport.viewRect.height);\n this._lastUpdateTime = Date.now();\n this._texture = texture;\n\n // Tell the viewport to re-render the decorations every frame so that the snow particles animate smoothly.\n const removeOnRender = viewport.onRender.addListener(() => viewport.invalidateDecorations());\n\n // When the viewport is resized, replace this decorator with a new one to match the new dimensions.\n const removeOnResized = viewport.onResized.addListener(() => {\n // Transfer ownership of the texture to the new decorator.\n const tex = this._texture;\n this._texture = undefined;\n this.dispose();\n new SnowDecorator(viewport, tex);\n });\n\n // When the viewport is destroyed, dispose of this decorator too.\n const removeOnDispose = viewport.onDisposed.addListener(() => this.dispose());\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\n\n this.dispose = () => {\n removeDecorator();\n removeOnRender();\n removeOnDispose();\n removeOnResized();\n this._texture = dispose(this._texture);\n SnowDecorator._decorators.delete(viewport);\n };\n\n SnowDecorator._decorators.set(viewport, this);\n\n // Initialize the particles.\n for (let i = 0; i < this._params.numParticles; i++)\n this._particles.push(this.emit(true));\n }\n\n public decorate(context: DecorateContext): void {\n if (context.viewport !== this.viewport || !this._texture)\n return;\n\n // Update the particles.\n const now = Date.now();\n const deltaMillis = now - this._lastUpdateTime;\n this._lastUpdateTime = now;\n this.updateParticles(deltaMillis / 1000);\n\n // Create particle graphics.\n const builder = ParticleCollectionBuilder.create({\n viewport: this.viewport,\n isViewCoords: true,\n texture: this._texture,\n size: (this._params.sizeRange.high - this._params.sizeRange.low) / 2,\n });\n\n for (const particle of this._particles)\n builder.addParticle(particle);\n\n const graphic = builder.finish();\n if (graphic)\n context.addDecoration(GraphicType.ViewOverlay, graphic);\n }\n\n /** Change some of the parameters affecting this decorator. */\n public configure(params: Partial<SnowParams>): void {\n for (const key of Object.keys(params)) {\n const val = (params as any)[key];\n if (undefined !== val)\n (this._params as any)[key] = val;\n }\n }\n\n /** Emit a new particle with randomized properties. */\n private emit(randomizeHeight: boolean): SnowParticle {\n return {\n x: randomInteger(0, this._dimensions.x),\n y: randomizeHeight ? randomInteger(0, this._dimensions.y) : 0,\n z: 0,\n size: randomInteger(this._params.sizeRange.low, this._params.sizeRange.high),\n transparency: randomInteger(this._params.transparencyRange.low, this._params.transparencyRange.high),\n velocity: new Vector2d(randomFloat(this._params.velocityRange.low.x, this._params.velocityRange.high.x),\n randomFloat(this._params.velocityRange.low.y, this._params.velocityRange.high.y)),\n };\n }\n\n // Update the positions and velocities of all the particles based on the amount of time that has passed since the last update.\n private updateParticles(elapsedSeconds: number): void {\n // Determine if someone changed the desired number of particles.\n const particleDiscrepancy = this._params.numParticles - this._particles.length;\n if (particleDiscrepancy > 0) {\n // Birth new particles up to the new maximum.\n for (let i = 0; i < particleDiscrepancy; i++)\n this._particles.push(this.emit(true));\n } else {\n // Destroy extra particles.\n this._particles.length = this._params.numParticles;\n }\n\n const acceleration = new Vector2d();\n const velocity = new Vector2d();\n for (let i = 0; i < this._particles.length; i++) {\n // Apply some acceleration to produce random drift.\n const particle = this._particles[i];\n acceleration.set(randomFloat(this._params.accelerationRange.low.x, this._params.accelerationRange.high.x),\n randomFloat(this._params.accelerationRange.low.y, this._params.accelerationRange.high.y));\n\n acceleration.scale(elapsedSeconds, acceleration);\n particle.velocity.plus(acceleration, particle.velocity);\n\n // Apply velocity.\n particle.velocity.clone(velocity);\n velocity.scale(elapsedSeconds, velocity);\n particle.x += velocity.x;\n particle.y += velocity.y;\n\n // Apply wind\n particle.x += this._params.windVelocity * elapsedSeconds;\n\n // Particles that travel beyond the viewport's left or right edges wrap around to the other side.\n if (particle.x < 0)\n particle.x = this._dimensions.x - 1;\n else if (particle.x >= this._dimensions.x)\n particle.x = 0;\n\n // Particles that travel beyond the viewport's bottom or top edges are replaced by newborn particles.\n if (particle.y < 0 || particle.y >= this._dimensions.y)\n this._particles[i] = this.emit(false);\n }\n }\n\n private static readonly _decorators = new Map<Viewport, SnowDecorator>();\n\n /** Toggle this decorator for the specified viewport.\n * @param viewport The viewport to which the effect should be applied or removed.\n * @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.\n */\n public static async toggle(viewport: Viewport, enable?: boolean): Promise<void> {\n const decorator = this._decorators.get(viewport);\n if (undefined === enable)\n enable = undefined === decorator;\n\n if (undefined !== decorator && !enable)\n decorator.dispose();\n else if (undefined === decorator && enable) {\n // Create a texture to use for the particles.\n // Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.\n const image = await imageElementFromUrl(`${IModelApp.publicPath}sprites/particle_snow.png`);\n const texture = IModelApp.renderSystem.createTexture({\n ownership: \"external\",\n image: { source: image, transparency: TextureTransparency.Mixed },\n });\n\n new SnowDecorator(viewport, texture);\n }\n }\n}\n\n/** Toggles a decorator that simulates snow using particle effects.\n * @see [[SnowDecorator]] for the implementation of the decorator.\n * @beta\n */\nexport class SnowEffect extends Tool {\n public static override toolId = \"SnowEffect\";\n\n public override async run(enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp)\n await SnowDecorator.toggle(vp, enable);\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Snow.js","sourceRoot":"","sources":["../../../src/effects/Snow.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA8C;AAC9C,wDAA2E;AAC3E,oDAAwE;AACxE,wDAE8B;AAC9B,sDAAmD;AACnD,qCAAsD;AAkCtD,+EAA+E;AAC/E,MAAM,iBAAiB,GAAe;IACpC,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,uBAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;IAClC,iBAAiB,EAAE,uBAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1C,aAAa,EAAE,IAAI,uBAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC;IAC5C,iBAAiB,EAAE,IAAI,uBAAO,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC;IAClD,YAAY,EAAE,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAa,aAAa;IACxB,oCAAoC;IACpB,QAAQ,CAAW;IACnC,sDAAsD;IACtC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAe;IAC/C,oHAAoH;IACnG,WAAW,CAAU;IACtC,yCAAyC;IACxB,UAAU,GAAmB,EAAE,CAAC;IACjD,8CAA8C;IACtC,QAAQ,CAAiB;IACj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AC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AAjBH,gCAkBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { dispose } from \"@itwin/core-bentley\";\nimport { Point2d, Range1d, Range2d, Vector2d } from \"@itwin/core-geometry\";\nimport { RenderTexture, TextureTransparency } from \"@itwin/core-common\";\nimport {\n DecorateContext, Decorator, GraphicType, imageElementFromUrl, IModelApp, ParticleCollectionBuilder, ParticleProps, Tool, Viewport,\n} from \"@itwin/core-frontend\";\nimport { parseToggle } from \"../tools/parseToggle\";\nimport { randomFloat, randomInteger } from \"./Random\";\n\n/** Represents one particle displayed by a [[SnowDecorator]].\n * Particle positions are in [CoordSystem.View]($frontend).\n * @beta\n */\nexport interface SnowParticle extends ParticleProps {\n /** Make x, y, and z from ParticleProps writable. */\n x: number;\n y: number;\n z: number;\n\n /** Current velocity, in pixels per second. */\n velocity: Vector2d;\n}\n\n/** Parameters controlling how a [[SnowDecorator]] works.\n * @beta\n */\nexport interface SnowParams {\n /** The number of snow particles to produce. This could alternatively be expressed as a density so that small viewports would not be more crowded than larger ones. */\n numParticles: number;\n /** Range from which to randomly select each particle's size, in pixels. */\n sizeRange: Range1d;\n /** Range from which to randomly select each particle's transparency. */\n transparencyRange: Range1d;\n /** Range from which to randomly select each particle's initial velocity, in pixels per second. */\n velocityRange: Range2d;\n /** Range from which to randomly select an acceleration to apply to each particle's velocity each frame, in pixels per second squared, to simulate wind. */\n accelerationRange: Range2d;\n /** Wind velocity in pixels per second in X. */\n windVelocity: number;\n}\n\n/** The default snow effect parameters used by newly-created SnowDecorators. */\nconst defaultSnowParams: SnowParams = {\n numParticles: 2000,\n sizeRange: Range1d.createXX(3, 22),\n transparencyRange: Range1d.createXX(0, 50),\n velocityRange: new Range2d(-30, 50, 30, 130),\n accelerationRange: new Range2d(-1, -0.25, 1, 0.25),\n windVelocity: 0,\n};\n\n/** Simulates snowfall in a [Viewport]($frontend) using particle effects.\n * @see [[SnowEffect]] for a [Tool]($frontend) that toggles this decorator.\n * @see [ParticleCollectionBuilder]($frontend) for defining custom particle effects.\n * @beta\n */\nexport class SnowDecorator implements Decorator {\n /** The viewport being decorated. */\n public readonly viewport: Viewport;\n /** Invoked when this decorator is to be destroyed. */\n public readonly [Symbol.dispose]: VoidFunction;\n /** The initial width and height of the viewport, from which we randomly select each particle's initial position. */\n private readonly _dimensions: Point2d;\n /** The list of particles being drawn. */\n private readonly _particles: SnowParticle[] = [];\n /** The image to display for each particle. */\n private _texture?: RenderTexture;\n /** The last time `updateParticles()` was invoked, in milliseconds. */\n private _lastUpdateTime: number;\n private readonly _params: SnowParams;\n\n private constructor(viewport: Viewport, texture: RenderTexture | undefined) {\n this._params = { ...defaultSnowParams };\n this.viewport = viewport;\n this._dimensions = new Point2d(viewport.viewRect.width, viewport.viewRect.height);\n this._lastUpdateTime = Date.now();\n this._texture = texture;\n\n // Tell the viewport to re-render the decorations every frame so that the snow particles animate smoothly.\n const removeOnRender = viewport.onRender.addListener(() => viewport.invalidateDecorations());\n\n // When the viewport is resized, replace this decorator with a new one to match the new dimensions.\n const removeOnResized = viewport.onResized.addListener(() => {\n // Transfer ownership of the texture to the new decorator.\n const tex = this._texture;\n this._texture = undefined;\n this[Symbol.dispose]();\n new SnowDecorator(viewport, tex);\n });\n\n // When the viewport is destroyed, dispose of this decorator too.\n const removeOnDispose = viewport.onDisposed.addListener(() => this[Symbol.dispose]());\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\n\n this[Symbol.dispose] = () => {\n removeDecorator();\n removeOnRender();\n removeOnDispose();\n removeOnResized();\n this._texture = dispose(this._texture);\n SnowDecorator._decorators.delete(viewport);\n };\n\n SnowDecorator._decorators.set(viewport, this);\n\n // Initialize the particles.\n for (let i = 0; i < this._params.numParticles; i++)\n this._particles.push(this.emit(true));\n }\n\n public decorate(context: DecorateContext): void {\n if (context.viewport !== this.viewport || !this._texture)\n return;\n\n // Update the particles.\n const now = Date.now();\n const deltaMillis = now - this._lastUpdateTime;\n this._lastUpdateTime = now;\n this.updateParticles(deltaMillis / 1000);\n\n // Create particle graphics.\n const builder = ParticleCollectionBuilder.create({\n viewport: this.viewport,\n isViewCoords: true,\n texture: this._texture,\n size: (this._params.sizeRange.high - this._params.sizeRange.low) / 2,\n });\n\n for (const particle of this._particles)\n builder.addParticle(particle);\n\n const graphic = builder.finish();\n if (graphic)\n context.addDecoration(GraphicType.ViewOverlay, graphic);\n }\n\n /** Change some of the parameters affecting this decorator. */\n public configure(params: Partial<SnowParams>): void {\n for (const key of Object.keys(params)) {\n const val = (params as any)[key];\n if (undefined !== val)\n (this._params as any)[key] = val;\n }\n }\n\n /** Emit a new particle with randomized properties. */\n private emit(randomizeHeight: boolean): SnowParticle {\n return {\n x: randomInteger(0, this._dimensions.x),\n y: randomizeHeight ? randomInteger(0, this._dimensions.y) : 0,\n z: 0,\n size: randomInteger(this._params.sizeRange.low, this._params.sizeRange.high),\n transparency: randomInteger(this._params.transparencyRange.low, this._params.transparencyRange.high),\n velocity: new Vector2d(randomFloat(this._params.velocityRange.low.x, this._params.velocityRange.high.x),\n randomFloat(this._params.velocityRange.low.y, this._params.velocityRange.high.y)),\n };\n }\n\n // Update the positions and velocities of all the particles based on the amount of time that has passed since the last update.\n private updateParticles(elapsedSeconds: number): void {\n // Determine if someone changed the desired number of particles.\n const particleDiscrepancy = this._params.numParticles - this._particles.length;\n if (particleDiscrepancy > 0) {\n // Birth new particles up to the new maximum.\n for (let i = 0; i < particleDiscrepancy; i++)\n this._particles.push(this.emit(true));\n } else {\n // Destroy extra particles.\n this._particles.length = this._params.numParticles;\n }\n\n const acceleration = new Vector2d();\n const velocity = new Vector2d();\n for (let i = 0; i < this._particles.length; i++) {\n // Apply some acceleration to produce random drift.\n const particle = this._particles[i];\n acceleration.set(randomFloat(this._params.accelerationRange.low.x, this._params.accelerationRange.high.x),\n randomFloat(this._params.accelerationRange.low.y, this._params.accelerationRange.high.y));\n\n acceleration.scale(elapsedSeconds, acceleration);\n particle.velocity.plus(acceleration, particle.velocity);\n\n // Apply velocity.\n particle.velocity.clone(velocity);\n velocity.scale(elapsedSeconds, velocity);\n particle.x += velocity.x;\n particle.y += velocity.y;\n\n // Apply wind\n particle.x += this._params.windVelocity * elapsedSeconds;\n\n // Particles that travel beyond the viewport's left or right edges wrap around to the other side.\n if (particle.x < 0)\n particle.x = this._dimensions.x - 1;\n else if (particle.x >= this._dimensions.x)\n particle.x = 0;\n\n // Particles that travel beyond the viewport's bottom or top edges are replaced by newborn particles.\n if (particle.y < 0 || particle.y >= this._dimensions.y)\n this._particles[i] = this.emit(false);\n }\n }\n\n private static readonly _decorators = new Map<Viewport, SnowDecorator>();\n\n /** Toggle this decorator for the specified viewport.\n * @param viewport The viewport to which the effect should be applied or removed.\n * @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.\n */\n public static async toggle(viewport: Viewport, enable?: boolean): Promise<void> {\n const decorator = this._decorators.get(viewport);\n if (undefined === enable)\n enable = undefined === decorator;\n\n if (undefined !== decorator && !enable)\n decorator[Symbol.dispose]();\n else if (undefined === decorator && enable) {\n // Create a texture to use for the particles.\n // Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.\n const image = await imageElementFromUrl(`${IModelApp.publicPath}sprites/particle_snow.png`);\n const texture = IModelApp.renderSystem.createTexture({\n ownership: \"external\",\n image: { source: image, transparency: TextureTransparency.Mixed },\n });\n\n new SnowDecorator(viewport, texture);\n }\n }\n}\n\n/** Toggles a decorator that simulates snow using particle effects.\n * @see [[SnowDecorator]] for the implementation of the decorator.\n * @beta\n */\nexport class SnowEffect extends Tool {\n public static override toolId = \"SnowEffect\";\n\n public override async run(enable?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp)\n await SnowDecorator.toggle(vp, enable);\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n"]}
|
|
@@ -16,6 +16,7 @@ const EffectTools_1 = require("./EffectTools");
|
|
|
16
16
|
* @beta
|
|
17
17
|
*/
|
|
18
18
|
class VignetteEffect extends EffectTools_1.AddEffectTool {
|
|
19
|
+
static toolId = "VignetteEffect";
|
|
19
20
|
get effectName() { return "Vignette"; }
|
|
20
21
|
get textureCoordFromPosition() { return true; }
|
|
21
22
|
get source() {
|
|
@@ -73,13 +74,23 @@ class VignetteEffect extends EffectTools_1.AddEffectTool {
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
exports.VignetteEffect = VignetteEffect;
|
|
76
|
-
VignetteEffect.toolId = "VignetteEffect";
|
|
77
77
|
/** Configures the [[VignetteEffect]].
|
|
78
78
|
* @beta
|
|
79
79
|
*/
|
|
80
80
|
class VignetteConfig extends core_frontend_1.Tool {
|
|
81
|
+
static toolId = "VignetteConfig";
|
|
81
82
|
static get minArgs() { return 0; }
|
|
82
83
|
static get maxArgs() { return 4; }
|
|
84
|
+
/** Size of the vignette in the form (width/2, height/2). e.g., to make the vignette start fading in halfway between the center and edges of
|
|
85
|
+
* UV space, use (0.25, 0.25).
|
|
86
|
+
*/
|
|
87
|
+
static size = new Float32Array([0.25, 0.25]);
|
|
88
|
+
/** How round the vignette will be, from 0.0 (perfectly rectangular) to 1.0 (perfectly round). */
|
|
89
|
+
static roundness = 1.0;
|
|
90
|
+
/** How quickly the vignette fades in. The vignette starts fading in at the edge of the values provided by `size` and will be
|
|
91
|
+
* fully faded in at (size.x + smoothness, size.y * smoothness). A value of 0.0 produces a hard edge.
|
|
92
|
+
*/
|
|
93
|
+
static smoothness = 0.5;
|
|
83
94
|
async run(width, height, roundness, smoothness) {
|
|
84
95
|
const config = VignetteConfig;
|
|
85
96
|
config.size[0] = width ?? config.size[0];
|
|
@@ -95,15 +106,4 @@ class VignetteConfig extends core_frontend_1.Tool {
|
|
|
95
106
|
}
|
|
96
107
|
}
|
|
97
108
|
exports.VignetteConfig = VignetteConfig;
|
|
98
|
-
VignetteConfig.toolId = "VignetteConfig";
|
|
99
|
-
/** Size of the vignette in the form (width/2, height/2). e.g., to make the vignette start fading in halfway between the center and edges of
|
|
100
|
-
* UV space, use (0.25, 0.25).
|
|
101
|
-
*/
|
|
102
|
-
VignetteConfig.size = new Float32Array([0.25, 0.25]);
|
|
103
|
-
/** How round the vignette will be, from 0.0 (perfectly rectangular) to 1.0 (perfectly round). */
|
|
104
|
-
VignetteConfig.roundness = 1.0;
|
|
105
|
-
/** How quickly the vignette fades in. The vignette starts fading in at the edge of the values provided by `size` and will be
|
|
106
|
-
* fully faded in at (size.x + smoothness, size.y * smoothness). A value of 0.0 produces a hard edge.
|
|
107
|
-
*/
|
|
108
|
-
VignetteConfig.smoothness = 0.5;
|
|
109
109
|
//# sourceMappingURL=Vignette.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vignette.js","sourceRoot":"","sources":["../../../src/effects/Vignette.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAgG;AAChG,kDAA+C;AAC/C,+CAAyE;AAEzE;;;GAGG;AACH,MAAa,cAAe,SAAQ,2BAAa;
|
|
1
|
+
{"version":3,"file":"Vignette.js","sourceRoot":"","sources":["../../../src/effects/Vignette.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,wDAAgG;AAChG,kDAA+C;AAC/C,+CAAyE;AAEzE;;;GAGG;AACH,MAAa,cAAe,SAAQ,2BAAa;IACxC,MAAM,CAAU,MAAM,GAAG,gBAAgB,CAAC;IAEjD,IAAc,UAAU,KAAK,OAAO,UAAU,CAAC,CAAC,CAAC;IACjD,IAAc,wBAAwB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD,IAAc,MAAM;QAClB,O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AEG;IACI,MAAM,CAAC,UAAU,GAAG,GAAG,CAAC;IAEf,KAAK,CAAC,GAAG,CAAC,KAAc,EAAE,MAAe,EAAE,SAAkB,EAAE,UAAmB;QAChG,MAAM,MAAM,GAAG,cAAc,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,SAAS,GAAG,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC;QACjD,MAAM,CAAC,UAAU,GAAG,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC;QAEpD,IAAA,uCAAyB,EAAC,cAAc,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAClG,CAAC;;AAhCH,wCAiCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Effects\n */\n\nimport { ScreenSpaceEffectBuilder, Tool, UniformType, VaryingType } from \"@itwin/core-frontend\";\nimport { parseArgs } from \"../tools/parseArgs\";\nimport { AddEffectTool, refreshViewportsForEffect } from \"./EffectTools\";\n\n/** Applies a [vignette](https://en.wikipedia.org/wiki/Vignetting) effect to the viewport.\n * From https://github.com/TyLindberg/glsl-vignette/blob/master/advanced.glsl.\n * @beta\n */\nexport class VignetteEffect extends AddEffectTool {\n public static override toolId = \"VignetteEffect\";\n\n protected get effectName() { return \"Vignette\"; }\n protected get textureCoordFromPosition() { return true; }\n\n protected get source() {\n return {\n vertex: `\n void effectMain(vec4 pos) {\n v_texCoord = textureCoordFromPosition(pos);\n }\n `,\n fragment: `\n float sdSquare(vec2 point, float width) {\n vec2 d = abs(point) - width;\n return min(max(d.x,d.y),0.0) + length(max(d,0.0));\n }\n\n float vignette(vec2 uv, vec2 size, float roundness, float smoothness) {\n // Center UVs\n uv -= 0.5;\n\n // Shift UVs based on the larger of width or height\n float minWidth = min(size.x, size.y);\n uv.x = sign(uv.x) * clamp(abs(uv.x) - abs(minWidth - size.x), 0.0, 1.0);\n uv.y = sign(uv.y) * clamp(abs(uv.y) - abs(minWidth - size.y), 0.0, 1.0);\n\n // Signed distance calculation\n float boxSize = minWidth * (1.0 - roundness);\n float dist = sdSquare(uv, boxSize) - (minWidth * roundness);\n\n return 1.0 - smoothstep(0.0, smoothness, dist);\n }\n\n vec4 effectMain() {\n return TEXTURE(u_diffuse, v_texCoord) * vignette(v_texCoord, u_size, u_roundness, u_smoothness);\n }\n `,\n };\n }\n\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\n builder.addVarying(\"v_texCoord\", VaryingType.Vec2);\n builder.addUniform({\n name: \"u_size\",\n type: UniformType.Vec2,\n bind: (uniform) => uniform.setUniform2fv(VignetteConfig.size),\n });\n builder.addUniform({\n name: \"u_roundness\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(VignetteConfig.roundness),\n });\n builder.addUniform({\n name: \"u_smoothness\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(VignetteConfig.smoothness),\n });\n }\n}\n\n/** Configures the [[VignetteEffect]].\n * @beta\n */\nexport class VignetteConfig extends Tool {\n public static override toolId = \"VignetteConfig\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 4; }\n\n /** Size of the vignette in the form (width/2, height/2). e.g., to make the vignette start fading in halfway between the center and edges of\n * UV space, use (0.25, 0.25).\n */\n public static readonly size = new Float32Array([0.25, 0.25]);\n\n /** How round the vignette will be, from 0.0 (perfectly rectangular) to 1.0 (perfectly round). */\n public static roundness = 1.0;\n\n /** How quickly the vignette fades in. The vignette starts fading in at the edge of the values provided by `size` and will be\n * fully faded in at (size.x + smoothness, size.y * smoothness). A value of 0.0 produces a hard edge.\n */\n public static smoothness = 0.5;\n\n public override async run(width?: number, height?: number, roundness?: number, smoothness?: number): Promise<boolean> {\n const config = VignetteConfig;\n config.size[0] = width ?? config.size[0];\n config.size[1] = height ?? config.size[1];\n config.roundness = roundness ?? config.roundness;\n config.smoothness = smoothness ?? config.smoothness;\n\n refreshViewportsForEffect(\"fdt Vignette\");\n return true;\n }\n\n public override async parseAndRun(...input: string[]): Promise<boolean> {\n const args = parseArgs(input);\n return this.run(args.getFloat(\"w\"), args.getFloat(\"h\"), args.getFloat(\"r\"), args.getFloat(\"s\"));\n }\n}\n"]}
|
|
@@ -14,6 +14,7 @@ const core_frontend_1 = require("@itwin/core-frontend");
|
|
|
14
14
|
* @beta
|
|
15
15
|
*/
|
|
16
16
|
class AnimationIntervalTool extends core_frontend_1.Tool {
|
|
17
|
+
static toolId = "AnimationInterval";
|
|
17
18
|
static get minArgs() { return 1; }
|
|
18
19
|
static get maxArgs() { return 1; }
|
|
19
20
|
async run(interval) {
|
|
@@ -27,5 +28,4 @@ class AnimationIntervalTool extends core_frontend_1.Tool {
|
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
exports.AnimationIntervalTool = AnimationIntervalTool;
|
|
30
|
-
AnimationIntervalTool.toolId = "AnimationInterval";
|
|
31
31
|
//# sourceMappingURL=AnimationIntervalTool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimationIntervalTool.js","sourceRoot":"","sources":["../../../src/tools/AnimationIntervalTool.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,sDAAiD;AACjD,wDAAuD;AAEvD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,oBAAI;
|
|
1
|
+
{"version":3,"file":"AnimationIntervalTool.js","sourceRoot":"","sources":["../../../src/tools/AnimationIntervalTool.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,sDAAiD;AACjD,wDAAuD;AAEvD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,oBAAI;IACtC,MAAM,CAAU,MAAM,GAAG,mBAAmB,CAAC;IAC7C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAElC,KAAK,CAAC,GAAG,CAAC,QAAqB;QAC7C,yBAAS,CAAC,iBAAiB,GAAG,QAAQ,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,yBAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACzF,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;;AAdH,sDAeC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport { BeDuration } from \"@itwin/core-bentley\";\nimport { IModelApp, Tool } from \"@itwin/core-frontend\";\n\n/** Changes the [IModelApp.animationInterval]($frontend). Specify the interval in integer milliseconds; or pass any string not parseable as an integer to disable the animation interval callback.\n * @beta\n */\nexport class AnimationIntervalTool extends Tool {\n public static override toolId = \"AnimationInterval\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 1; }\n\n public override async run(interval?: BeDuration): Promise<boolean> {\n IModelApp.animationInterval = interval;\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const millis = Number.parseInt(args[0], 10);\n const interval = !Number.isNaN(millis) ? BeDuration.fromMilliseconds(millis) : undefined;\n return this.run(interval);\n }\n}\n"]}
|
|
@@ -16,6 +16,7 @@ const parseToggle_1 = require("./parseToggle");
|
|
|
16
16
|
* @beta
|
|
17
17
|
*/
|
|
18
18
|
class ChangeUnitsTool extends core_frontend_1.Tool {
|
|
19
|
+
static toolId = "ChangeUnits";
|
|
19
20
|
static get minArgs() { return 0; }
|
|
20
21
|
static get maxArgs() { return 1; }
|
|
21
22
|
// support boolean for backwards compatibility
|
|
@@ -38,5 +39,4 @@ class ChangeUnitsTool extends core_frontend_1.Tool {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
exports.ChangeUnitsTool = ChangeUnitsTool;
|
|
41
|
-
ChangeUnitsTool.toolId = "ChangeUnits";
|
|
42
42
|
//# sourceMappingURL=ChangeUnitsTool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChangeUnitsTool.js","sourceRoot":"","sources":["../../../src/tools/ChangeUnitsTool.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,wDAAuD;AACvD,+CAA4C;AAE5C,sBAAsB;AAEtB;;;GAGG;AACH,MAAa,eAAgB,SAAQ,oBAAI;
|
|
1
|
+
{"version":3,"file":"ChangeUnitsTool.js","sourceRoot":"","sources":["../../../src/tools/ChangeUnitsTool.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,wDAAuD;AACvD,+CAA4C;AAE5C,sBAAsB;AAEtB;;;GAGG;AACH,MAAa,eAAgB,SAAQ,oBAAI;IAChC,MAAM,CAAU,MAAM,GAAG,aAAa,CAAC;IACvC,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAElD,8CAA8C;IAC9B,KAAK,CAAC,GAAG,CAAC,SAAmB;QAC3C,MAAM,IAAI,GAAG,yBAAS,CAAC,iBAAiB,CAAC;QAEzC,kEAAkE;QAClE,MAAM,WAAW,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,KAAK,QAAQ,CAAC;QAC9F,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;QAEvD,IAAI,UAAU,KAAK,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACzC,MAAM,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;YAC3C,MAAM,yBAAS,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,IAAA,yBAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;;AA3BH,0CA4BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport { IModelApp, Tool } from \"@itwin/core-frontend\";\nimport { parseToggle } from \"./parseToggle\";\n\n// CSpell: ignore fmtr\n\n/** Controls whether quantities are formatted using imperial or metric units.\n * Such formatting is used in many places; one example is the output of the MeasureTool.\n * @beta\n */\nexport class ChangeUnitsTool extends Tool {\n public static override toolId = \"ChangeUnits\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n // support boolean for backwards compatibility\n public override async run(useMetric?: boolean): Promise<boolean> {\n const fmtr = IModelApp.quantityFormatter;\n\n // if no arg then toggle to metric from any non-metric unit system\n const useImperial = undefined !== useMetric ? !useMetric : fmtr.activeUnitSystem === \"metric\";\n const unitSystem = useImperial ? \"imperial\" : \"metric\";\n\n if (unitSystem !== fmtr.activeUnitSystem) {\n await fmtr.setActiveUnitSystem(unitSystem);\n await IModelApp.toolAdmin.startDefaultTool();\n }\n\n return true;\n }\n\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n"]}
|
|
@@ -29,6 +29,7 @@ const DisplayStyleTools_1 = require("./DisplayStyleTools");
|
|
|
29
29
|
* @beta
|
|
30
30
|
*/
|
|
31
31
|
class ClipColorTool extends core_frontend_1.Tool {
|
|
32
|
+
static toolId = "ClipColorTool";
|
|
32
33
|
static get minArgs() { return 1; }
|
|
33
34
|
static get maxArgs() { return 2; }
|
|
34
35
|
_clearClipColors() {
|
|
@@ -74,7 +75,6 @@ class ClipColorTool extends core_frontend_1.Tool {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
exports.ClipColorTool = ClipColorTool;
|
|
77
|
-
ClipColorTool.toolId = "ClipColorTool";
|
|
78
78
|
/** This tool specifies or un-specifies a color and width to use for pixels within the specified width of a clip plane.
|
|
79
79
|
* Arguments can be:
|
|
80
80
|
* - off
|
|
@@ -92,6 +92,7 @@ ClipColorTool.toolId = "ClipColorTool";
|
|
|
92
92
|
* @beta
|
|
93
93
|
*/
|
|
94
94
|
class ClipIntersectionTool extends core_frontend_1.Tool {
|
|
95
|
+
static toolId = "ClipIntersectionTool";
|
|
95
96
|
static get minArgs() { return 0; }
|
|
96
97
|
static get maxArgs() { return 4; }
|
|
97
98
|
_toggleIntersectionStyle(toggle) {
|
|
@@ -162,11 +163,11 @@ class ClipIntersectionTool extends core_frontend_1.Tool {
|
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
165
|
exports.ClipIntersectionTool = ClipIntersectionTool;
|
|
165
|
-
ClipIntersectionTool.toolId = "ClipIntersectionTool";
|
|
166
166
|
/** Controls a view state's view details' flag for producing cut geometry for a clip style.
|
|
167
167
|
* @beta
|
|
168
168
|
*/
|
|
169
169
|
class ToggleSectionCutTool extends core_frontend_1.Tool {
|
|
170
|
+
static toolId = "ToggleSectionCut";
|
|
170
171
|
static get minArgs() { return 0; }
|
|
171
172
|
static get maxArgs() { return 1; }
|
|
172
173
|
/** This method runs the tool, controlling a view state's view details' flag for producing cut geometry for a clip style.
|
|
@@ -199,17 +200,15 @@ class ToggleSectionCutTool extends core_frontend_1.Tool {
|
|
|
199
200
|
}
|
|
200
201
|
}
|
|
201
202
|
exports.ToggleSectionCutTool = ToggleSectionCutTool;
|
|
202
|
-
ToggleSectionCutTool.toolId = "ToggleSectionCut";
|
|
203
203
|
/** Simple tool that toggles a hard-coded clip style overriding various aspects of the cut geometry appearance.
|
|
204
204
|
* @beta
|
|
205
205
|
*/
|
|
206
206
|
class TestClipStyleTool extends DisplayStyleTools_1.DisplayStyleTool {
|
|
207
|
-
|
|
208
|
-
super(...arguments);
|
|
209
|
-
this._useStyle = false;
|
|
210
|
-
}
|
|
207
|
+
static toolId = "TestClipStyle";
|
|
211
208
|
static get maxArgs() { return 2; }
|
|
212
209
|
static get minArgs() { return 1; }
|
|
210
|
+
_useStyle = false;
|
|
211
|
+
_style;
|
|
213
212
|
get require3d() { return true; }
|
|
214
213
|
async parse(args) {
|
|
215
214
|
this._useStyle = (0, parseBoolean_1.parseBoolean)(args[0]) ?? false;
|
|
@@ -251,5 +250,4 @@ class TestClipStyleTool extends DisplayStyleTools_1.DisplayStyleTool {
|
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
exports.TestClipStyleTool = TestClipStyleTool;
|
|
254
|
-
TestClipStyleTool.toolId = "TestClipStyle";
|
|
255
253
|
//# sourceMappingURL=ClipTools.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClipTools.js","sourceRoot":"","sources":["../../../src/tools/ClipTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,oDAE4B;AAC5B,wDAAiE;AACjE,+CAA4C;AAC5C,iDAA8C;AAC9C,2DAAuD;AAEvD;;;;;;;;;;;;;;GAcG;AACH,MAAa,aAAc,SAAQ,oBAAI;IAE9B,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAE1C,gBAAgB;QACtB,MAAM,EAAE,GAAG,yBAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;YAChE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC;YACnD,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,GAAG,uBAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAEO,YAAY,CAAC,MAAc,EAAE,KAAqC;QACxE,MAAM,EAAE,GAAG,yBAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE,EAAE,CAAC;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;4BACvB,OAAO,EAAE,wBAAU,CAAC,KAAK;4BACzB,KAAK,EAAE,CAAC;yBACT;qBACF;iBACF,CAAC;QACN,CAAC;QAED,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,GAAG,uBAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC/D,EAAE,CAAC,oBAAoB,EAAE,CAAC;QAC1B,EAAE,CAAC,iCAAiC,EAAE,CAAC;QAEvC,OAAO,IAAI,CAAC;IACd,CAAC;;AAlDH,8CAmDC;AAlDwB,wBAAM,GAAG,eAAe,AAAlB,CAAmB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport {\n ClipIntersectionStyle, ClipStyle, ClipStyleProps, ColorByName, ColorDef, CutStyleProps, LinePixels, RenderMode, RgbColor,\n} from \"@itwin/core-common\";\nimport { IModelApp, Tool, Viewport } from \"@itwin/core-frontend\";\nimport { parseToggle } from \"./parseToggle\";\nimport { parseBoolean } from \"./parseBoolean\";\nimport { DisplayStyleTool } from \"./DisplayStyleTools\";\n\n/** This tool specifies or un-specifies a clip color to use for pixels inside or outside the clip region.\n * Arguments can be:\n * - clear\n * - inside <color string> | clear\n * - outside <color string> | clear\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @see [ColorDef]\n * @beta\n */\nexport class ClipColorTool extends Tool {\n public static override toolId = \"ClipColorTool\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 2; }\n\n private _clearClipColors() {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n props.insideColor = props.outsideColor = undefined;\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n private setClipColor(colStr: string, which: \"insideColor\" | \"outsideColor\") {\n const vp = IModelApp.viewManager.selectedView;\n if (vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n props[which] = colStr === \"clear\" ? undefined : RgbColor.fromColorDef(ColorDef.fromString(colStr));\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n /** This runs the tool using the given arguments, specifying or unspecifying a clip color to use for pixels inside or outside the clip region.\n * Arguments can be:\n * - clear\n * - inside <color string> | clear\n * - outside <color string> | clear\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @beta\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n if (1 === args.length) {\n if (args[0] === \"clear\")\n this._clearClipColors();\n\n return true;\n }\n\n const which = args[0];\n if (which === \"inside\" || which === \"outside\")\n this.setClipColor(args[1], \"inside\" === which ? \"insideColor\" : \"outsideColor\");\n\n return true;\n }\n}\n\n/** This tool specifies or un-specifies a color and width to use for pixels within the specified width of a clip plane.\n * Arguments can be:\n * - off\n * - default\n * - color <color string>\n * - width <number>\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @see [ColorDef]\n * @beta\n */\nexport class ClipIntersectionTool extends Tool {\n public static override toolId = \"ClipIntersectionTool\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 4; }\n\n private _toggleIntersectionStyle(toggle: boolean) {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n props.colorizeIntersection = toggle;\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n private _defaultClipIntersection() {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n if (!props.intersectionStyle) {\n props.intersectionStyle = ClipIntersectionStyle.defaults;\n } else {\n props.intersectionStyle.color = RgbColor.fromColorDef(ColorDef.white);\n props.intersectionStyle.width = 1;\n }\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n private setClipIntersection(colStr: string, width: number) {\n const vp = IModelApp.viewManager.selectedView;\n if (vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n\n if (!props.intersectionStyle) {\n props.intersectionStyle = ClipIntersectionStyle.defaults;\n }\n if (colStr) {\n props.intersectionStyle.color = RgbColor.fromColorDef(ColorDef.fromString(colStr));\n }\n if (width) {\n props.intersectionStyle.width = width;\n }\n\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n /** This runs the tool using the given arguments, specifying or unspecifying a color and width to use for pixels within the specified width of a clip plane.\n * Arguments can be:\n * - off\n * - default\n * - color <color string>\n * - width <number>\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @beta\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n if (args[0] === \"off\") {\n this._toggleIntersectionStyle(false);\n return true;\n }\n\n this._toggleIntersectionStyle(true);\n if (args[0] === \"default\") {\n this._defaultClipIntersection();\n return true;\n }\n\n args[0] === \"color\" ? this.setClipIntersection(args[1], +args[3]) : this.setClipIntersection(args[3], +args[1]);\n return true;\n }\n}\n\n/** Controls a view state's view details' flag for producing cut geometry for a clip style.\n * @beta\n */\nexport class ToggleSectionCutTool extends Tool {\n public static override toolId = \"ToggleSectionCut\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, controlling a view state's view details' flag for producing cut geometry for a clip style.\n * @param produceCutGeometry whether to produce cut geometry\n */\n public override async run(produceCutGeometry?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp) {\n const style = vp.view.displayStyle.settings.clipStyle;\n produceCutGeometry = produceCutGeometry ?? !style.produceCutGeometry;\n if (produceCutGeometry !== style.produceCutGeometry) {\n const json = {\n ...vp.view.displayStyle.settings.clipStyle.toJSON(),\n produceCutGeometry,\n };\n\n vp.view.displayStyle.settings.clipStyle = ClipStyle.fromJSON(json);\n vp.invalidateScene();\n }\n }\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `produceCutGeometry`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n\n/** Simple tool that toggles a hard-coded clip style overriding various aspects of the cut geometry appearance.\n * @beta\n */\nexport class TestClipStyleTool extends DisplayStyleTool {\n public static override toolId = \"TestClipStyle\";\n public static override get maxArgs() { return 2; }\n public static override get minArgs() { return 1; }\n\n private _useStyle = false;\n private _style?: CutStyleProps;\n\n protected override get require3d() { return true; }\n\n protected async parse(args: string[]): Promise<boolean> {\n this._useStyle = parseBoolean(args[0]) ?? false;\n if (this._useStyle && args.length > 1)\n this._style = JSON.parse(args[1]);\n return true;\n }\n\n protected async execute(vp: Viewport) {\n const props: ClipStyleProps = { produceCutGeometry: true };\n if (this._useStyle) {\n if (this._style)\n props.cutStyle = this._style;\n else\n props.cutStyle = {\n viewflags: {\n renderMode: RenderMode.SmoothShade,\n visibleEdges: true,\n hiddenEdges: false,\n },\n appearance: {\n rgb: { r: 0xff, g: 0x7f, b: 0 },\n transparency: 0.5,\n nonLocatable: true,\n },\n hiddenLine: {\n visible: {\n ovrColor: true,\n color: ColorByName.blue,\n pattern: LinePixels.Solid,\n width: 3,\n },\n },\n };\n }\n\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n vp.invalidateRenderPlan();\n vp.setFeatureOverrideProviderChanged();\n\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ClipTools.js","sourceRoot":"","sources":["../../../src/tools/ClipTools.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,oDAE4B;AAC5B,wDAAiE;AACjE,+CAA4C;AAC5C,iDAA8C;AAC9C,2DAAuD;AAEvD;;;;;;;;;;;;;;GAcG;AACH,MAAa,aAAc,SAAQ,oBAAI;IAC9B,MAAM,CAAU,MAAM,GAAG,eAAe,CAAC;IACzC,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAE1C,gBAAgB;QACtB,MAAM,EAAE,GAAG,yBAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;YACrB,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC;YAChE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC;YACnD,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,GAAG,uBAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAEO,YAAY,CAAC,MAAc,EAAE,KAAqC;QACxE,MAAM,EAAE,GAAG,yBAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE,EAAE,CAAC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AW,CAAC,IAAI;4BACvB,OAAO,EAAE,wBAAU,CAAC,KAAK;4BACzB,KAAK,EAAE,CAAC;yBACT;qBACF;iBACF,CAAC;QACN,CAAC;QAED,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,SAAS,GAAG,uBAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC/D,EAAE,CAAC,oBAAoB,EAAE,CAAC;QAC1B,EAAE,CAAC,iCAAiC,EAAE,CAAC;QAEvC,OAAO,IAAI,CAAC;IACd,CAAC;;AAlDH,8CAmDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @packageDocumentation\n * @module Tools\n */\n\nimport {\n ClipIntersectionStyle, ClipStyle, ClipStyleProps, ColorByName, ColorDef, CutStyleProps, LinePixels, RenderMode, RgbColor,\n} from \"@itwin/core-common\";\nimport { IModelApp, Tool, Viewport } from \"@itwin/core-frontend\";\nimport { parseToggle } from \"./parseToggle\";\nimport { parseBoolean } from \"./parseBoolean\";\nimport { DisplayStyleTool } from \"./DisplayStyleTools\";\n\n/** This tool specifies or un-specifies a clip color to use for pixels inside or outside the clip region.\n * Arguments can be:\n * - clear\n * - inside <color string> | clear\n * - outside <color string> | clear\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @see [ColorDef]\n * @beta\n */\nexport class ClipColorTool extends Tool {\n public static override toolId = \"ClipColorTool\";\n public static override get minArgs() { return 1; }\n public static override get maxArgs() { return 2; }\n\n private _clearClipColors() {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n props.insideColor = props.outsideColor = undefined;\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n private setClipColor(colStr: string, which: \"insideColor\" | \"outsideColor\") {\n const vp = IModelApp.viewManager.selectedView;\n if (vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n props[which] = colStr === \"clear\" ? undefined : RgbColor.fromColorDef(ColorDef.fromString(colStr));\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n /** This runs the tool using the given arguments, specifying or unspecifying a clip color to use for pixels inside or outside the clip region.\n * Arguments can be:\n * - clear\n * - inside <color string> | clear\n * - outside <color string> | clear\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @beta\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n if (1 === args.length) {\n if (args[0] === \"clear\")\n this._clearClipColors();\n\n return true;\n }\n\n const which = args[0];\n if (which === \"inside\" || which === \"outside\")\n this.setClipColor(args[1], \"inside\" === which ? \"insideColor\" : \"outsideColor\");\n\n return true;\n }\n}\n\n/** This tool specifies or un-specifies a color and width to use for pixels within the specified width of a clip plane.\n * Arguments can be:\n * - off\n * - default\n * - color <color string>\n * - width <number>\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @see [ColorDef]\n * @beta\n */\nexport class ClipIntersectionTool extends Tool {\n public static override toolId = \"ClipIntersectionTool\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 4; }\n\n private _toggleIntersectionStyle(toggle: boolean) {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n props.colorizeIntersection = toggle;\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n private _defaultClipIntersection() {\n const vp = IModelApp.viewManager.selectedView;\n if (undefined !== vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n if (!props.intersectionStyle) {\n props.intersectionStyle = ClipIntersectionStyle.defaults;\n } else {\n props.intersectionStyle.color = RgbColor.fromColorDef(ColorDef.white);\n props.intersectionStyle.width = 1;\n }\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n private setClipIntersection(colStr: string, width: number) {\n const vp = IModelApp.viewManager.selectedView;\n if (vp) {\n const props = vp.displayStyle.settings.clipStyle.toJSON() ?? {};\n\n if (!props.intersectionStyle) {\n props.intersectionStyle = ClipIntersectionStyle.defaults;\n }\n if (colStr) {\n props.intersectionStyle.color = RgbColor.fromColorDef(ColorDef.fromString(colStr));\n }\n if (width) {\n props.intersectionStyle.width = width;\n }\n\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n }\n }\n\n /** This runs the tool using the given arguments, specifying or unspecifying a color and width to use for pixels within the specified width of a clip plane.\n * Arguments can be:\n * - off\n * - default\n * - color <color string>\n * - width <number>\n * <color string> must be in one of the following forms:\n * \"rgb(255,0,0)\"\n * \"rgba(255,0,0,255)\"\n * \"rgb(100%,0%,0%)\"\n * \"hsl(120,50%,50%)\"\n * \"#rrbbgg\"\n * \"blanchedAlmond\" (see possible values from [[ColorByName]]). Case insensitive.\n * @beta\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n if (args[0] === \"off\") {\n this._toggleIntersectionStyle(false);\n return true;\n }\n\n this._toggleIntersectionStyle(true);\n if (args[0] === \"default\") {\n this._defaultClipIntersection();\n return true;\n }\n\n args[0] === \"color\" ? this.setClipIntersection(args[1], +args[3]) : this.setClipIntersection(args[3], +args[1]);\n return true;\n }\n}\n\n/** Controls a view state's view details' flag for producing cut geometry for a clip style.\n * @beta\n */\nexport class ToggleSectionCutTool extends Tool {\n public static override toolId = \"ToggleSectionCut\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 1; }\n\n /** This method runs the tool, controlling a view state's view details' flag for producing cut geometry for a clip style.\n * @param produceCutGeometry whether to produce cut geometry\n */\n public override async run(produceCutGeometry?: boolean): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp) {\n const style = vp.view.displayStyle.settings.clipStyle;\n produceCutGeometry = produceCutGeometry ?? !style.produceCutGeometry;\n if (produceCutGeometry !== style.produceCutGeometry) {\n const json = {\n ...vp.view.displayStyle.settings.clipStyle.toJSON(),\n produceCutGeometry,\n };\n\n vp.view.displayStyle.settings.clipStyle = ClipStyle.fromJSON(json);\n vp.invalidateScene();\n }\n }\n\n return true;\n }\n\n /** Executes this tool's run method with args[0] containing `produceCutGeometry`.\n * @see [[run]]\n */\n public override async parseAndRun(...args: string[]): Promise<boolean> {\n const enable = parseToggle(args[0]);\n if (typeof enable !== \"string\")\n await this.run(enable);\n\n return true;\n }\n}\n\n/** Simple tool that toggles a hard-coded clip style overriding various aspects of the cut geometry appearance.\n * @beta\n */\nexport class TestClipStyleTool extends DisplayStyleTool {\n public static override toolId = \"TestClipStyle\";\n public static override get maxArgs() { return 2; }\n public static override get minArgs() { return 1; }\n\n private _useStyle = false;\n private _style?: CutStyleProps;\n\n protected override get require3d() { return true; }\n\n protected async parse(args: string[]): Promise<boolean> {\n this._useStyle = parseBoolean(args[0]) ?? false;\n if (this._useStyle && args.length > 1)\n this._style = JSON.parse(args[1]);\n return true;\n }\n\n protected async execute(vp: Viewport) {\n const props: ClipStyleProps = { produceCutGeometry: true };\n if (this._useStyle) {\n if (this._style)\n props.cutStyle = this._style;\n else\n props.cutStyle = {\n viewflags: {\n renderMode: RenderMode.SmoothShade,\n visibleEdges: true,\n hiddenEdges: false,\n },\n appearance: {\n rgb: { r: 0xff, g: 0x7f, b: 0 },\n transparency: 0.5,\n nonLocatable: true,\n },\n hiddenLine: {\n visible: {\n ovrColor: true,\n color: ColorByName.blue,\n pattern: LinePixels.Solid,\n width: 3,\n },\n },\n };\n }\n\n vp.displayStyle.settings.clipStyle = ClipStyle.fromJSON(props);\n vp.invalidateRenderPlan();\n vp.setFeatureOverrideProviderChanged();\n\n return true;\n }\n}\n"]}
|