@itwin/frontend-devtools 5.0.0-dev.5 → 5.0.0-dev.50
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 +36 -1
- package/lib/cjs/ClipboardUtilities.js.map +1 -1
- package/lib/cjs/FrontEndDevTools.js +1 -1
- package/lib/cjs/FrontEndDevTools.js.map +1 -1
- package/lib/cjs/effects/Convolution.js +23 -23
- 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 +6 -6
- package/lib/cjs/effects/Explosion.js.map +1 -1
- package/lib/cjs/effects/FlipImage.js +22 -22
- package/lib/cjs/effects/FlipImage.js.map +1 -1
- package/lib/cjs/effects/LensDistortion.js +25 -25
- package/lib/cjs/effects/LensDistortion.js.map +1 -1
- package/lib/cjs/effects/Random.js.map +1 -1
- package/lib/cjs/effects/Saturation.js +30 -30
- 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 +7 -6
- package/lib/cjs/effects/Snow.js.map +1 -1
- package/lib/cjs/effects/Vignette.js +41 -41
- package/lib/cjs/effects/Vignette.js.map +1 -1
- package/lib/cjs/frontend-devtools.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 +4 -4
- package/lib/cjs/tools/ClipTools.js.map +1 -1
- package/lib/cjs/tools/DisplayStyleTools.js +10 -10
- package/lib/cjs/tools/DisplayStyleTools.js.map +1 -1
- package/lib/cjs/tools/EmphasizeElementsTool.js +5 -5
- package/lib/cjs/tools/EmphasizeElementsTool.js.map +1 -1
- package/lib/cjs/tools/FrustumDecoration.js +3 -3
- package/lib/cjs/tools/FrustumDecoration.js.map +1 -1
- package/lib/cjs/tools/InspectElementTool.js +1 -1
- package/lib/cjs/tools/InspectElementTool.js.map +1 -1
- package/lib/cjs/tools/MapLayerTool.js +20 -20
- package/lib/cjs/tools/MapLayerTool.js.map +1 -1
- package/lib/cjs/tools/MeasureTileLoadTime.js +1 -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 +3 -3
- package/lib/cjs/tools/PlanProjectionTools.js.map +1 -1
- package/lib/cjs/tools/PlanarMaskTools.js +13 -13
- package/lib/cjs/tools/PlanarMaskTools.js.map +1 -1
- package/lib/cjs/tools/ProjectExtents.js +1 -1
- 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 +3 -3
- package/lib/cjs/tools/RenderSystemTools.js.map +1 -1
- package/lib/cjs/tools/RenderTargetTools.js +11 -11
- 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 +3 -3
- package/lib/cjs/tools/SavedViews.js.map +1 -1
- package/lib/cjs/tools/ScheduleScriptTools.js +3 -3
- package/lib/cjs/tools/ScheduleScriptTools.js.map +1 -1
- package/lib/cjs/tools/SelectionTools.js +2 -2
- 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 +1 -1
- package/lib/cjs/tools/TileRequestDecoration.js.map +1 -1
- package/lib/cjs/tools/TileTreeBoundsDecoration.js +1 -1
- package/lib/cjs/tools/TileTreeBoundsDecoration.js.map +1 -1
- package/lib/cjs/tools/ToolTipProvider.js +1 -1
- package/lib/cjs/tools/ToolTipProvider.js.map +1 -1
- package/lib/cjs/tools/ViewportTools.js +19 -19
- package/lib/cjs/tools/ViewportTools.js.map +1 -1
- package/lib/cjs/tools/parseArgs.js.map +1 -1
- package/lib/cjs/tools/parseBoolean.js.map +1 -1
- package/lib/cjs/tools/parseToggle.js.map +1 -1
- package/lib/cjs/ui/Button.js.map +1 -1
- package/lib/cjs/ui/CheckBox.js.map +1 -1
- package/lib/cjs/ui/ColorInput.js.map +1 -1
- package/lib/cjs/ui/ComboBox.js.map +1 -1
- package/lib/cjs/ui/DataList.js.map +1 -1
- package/lib/cjs/ui/NestedMenu.js.map +1 -1
- package/lib/cjs/ui/NumericInput.js.map +1 -1
- package/lib/cjs/ui/RadioBox.js.map +1 -1
- package/lib/cjs/ui/Slider.js.map +1 -1
- package/lib/cjs/ui/TextBox.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 +1 -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 +1 -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 +1 -1
- package/lib/cjs/widgets/GpuProfiler.js.map +1 -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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/ClipboardUtilities.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 +23 -23
- 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 +6 -6
- package/lib/esm/effects/Explosion.js.map +1 -1
- package/lib/esm/effects/FlipImage.js +22 -22
- package/lib/esm/effects/FlipImage.js.map +1 -1
- package/lib/esm/effects/LensDistortion.js +25 -25
- package/lib/esm/effects/LensDistortion.js.map +1 -1
- package/lib/esm/effects/Random.js.map +1 -1
- package/lib/esm/effects/Saturation.js +30 -30
- 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 +7 -6
- package/lib/esm/effects/Snow.js.map +1 -1
- package/lib/esm/effects/Vignette.js +41 -41
- package/lib/esm/effects/Vignette.js.map +1 -1
- package/lib/esm/frontend-devtools.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 +4 -4
- package/lib/esm/tools/ClipTools.js.map +1 -1
- package/lib/esm/tools/DisplayStyleTools.js +10 -10
- package/lib/esm/tools/DisplayStyleTools.js.map +1 -1
- package/lib/esm/tools/EmphasizeElementsTool.js +5 -5
- package/lib/esm/tools/EmphasizeElementsTool.js.map +1 -1
- package/lib/esm/tools/FrustumDecoration.js +3 -3
- package/lib/esm/tools/FrustumDecoration.js.map +1 -1
- package/lib/esm/tools/InspectElementTool.js +1 -1
- package/lib/esm/tools/InspectElementTool.js.map +1 -1
- package/lib/esm/tools/MapLayerTool.js +20 -20
- package/lib/esm/tools/MapLayerTool.js.map +1 -1
- package/lib/esm/tools/MeasureTileLoadTime.js +1 -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 +3 -3
- package/lib/esm/tools/PlanProjectionTools.js.map +1 -1
- package/lib/esm/tools/PlanarMaskTools.js +13 -13
- package/lib/esm/tools/PlanarMaskTools.js.map +1 -1
- package/lib/esm/tools/ProjectExtents.js +1 -1
- 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 +3 -3
- package/lib/esm/tools/RenderSystemTools.js.map +1 -1
- package/lib/esm/tools/RenderTargetTools.js +11 -11
- 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 +3 -3
- package/lib/esm/tools/SavedViews.js.map +1 -1
- package/lib/esm/tools/ScheduleScriptTools.js +3 -3
- package/lib/esm/tools/ScheduleScriptTools.js.map +1 -1
- package/lib/esm/tools/SelectionTools.js +2 -2
- 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 +1 -1
- package/lib/esm/tools/TileRequestDecoration.js.map +1 -1
- package/lib/esm/tools/TileTreeBoundsDecoration.js +1 -1
- package/lib/esm/tools/TileTreeBoundsDecoration.js.map +1 -1
- package/lib/esm/tools/ToolTipProvider.js +1 -1
- package/lib/esm/tools/ToolTipProvider.js.map +1 -1
- package/lib/esm/tools/ViewportTools.js +19 -19
- package/lib/esm/tools/ViewportTools.js.map +1 -1
- package/lib/esm/tools/parseArgs.js.map +1 -1
- package/lib/esm/tools/parseBoolean.js.map +1 -1
- package/lib/esm/tools/parseToggle.js.map +1 -1
- package/lib/esm/ui/Button.js.map +1 -1
- package/lib/esm/ui/CheckBox.js.map +1 -1
- package/lib/esm/ui/ColorInput.js.map +1 -1
- package/lib/esm/ui/ComboBox.js.map +1 -1
- package/lib/esm/ui/DataList.js.map +1 -1
- package/lib/esm/ui/NestedMenu.js.map +1 -1
- package/lib/esm/ui/NumericInput.js.map +1 -1
- package/lib/esm/ui/RadioBox.js.map +1 -1
- package/lib/esm/ui/Slider.js.map +1 -1
- package/lib/esm/ui/TextBox.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 +1 -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 +1 -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 +1 -1
- package/lib/esm/widgets/GpuProfiler.js.map +1 -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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/lib/public/locales/en/FrontendDevTools.json +494 -494
- package/package.json +8 -8
|
@@ -16,33 +16,34 @@ let flipColor = false;
|
|
|
16
16
|
* @beta
|
|
17
17
|
*/
|
|
18
18
|
export class FlipImageEffect extends AddEffectTool {
|
|
19
|
+
static { this.toolId = "FlipImageEffect"; }
|
|
19
20
|
get effectName() { return "flip"; }
|
|
20
21
|
get textureCoordFromPosition() { return true; }
|
|
21
22
|
get source() {
|
|
22
23
|
return {
|
|
23
24
|
// Compute texture coordinate for use in fragment shader.
|
|
24
|
-
vertex: `
|
|
25
|
-
void effectMain(vec4 pos) {
|
|
26
|
-
vec2 uv = textureCoordFromPosition(pos);
|
|
27
|
-
if (u_flipHorizontal)
|
|
28
|
-
uv.x = 1.0 - uv.x;
|
|
29
|
-
|
|
30
|
-
if (u_flipVertical)
|
|
31
|
-
uv.y = 1.0 - uv.y;
|
|
32
|
-
|
|
33
|
-
v_uv = uv;
|
|
25
|
+
vertex: `
|
|
26
|
+
void effectMain(vec4 pos) {
|
|
27
|
+
vec2 uv = textureCoordFromPosition(pos);
|
|
28
|
+
if (u_flipHorizontal)
|
|
29
|
+
uv.x = 1.0 - uv.x;
|
|
30
|
+
|
|
31
|
+
if (u_flipVertical)
|
|
32
|
+
uv.y = 1.0 - uv.y;
|
|
33
|
+
|
|
34
|
+
v_uv = uv;
|
|
34
35
|
}`,
|
|
35
36
|
// Sample the original image to flip on x and/or y axis, then invert its color.
|
|
36
|
-
fragment: `
|
|
37
|
-
vec4 effectMain() {
|
|
38
|
-
vec4 color = sampleSourcePixel();
|
|
39
|
-
if (u_flipColor) {
|
|
40
|
-
color.r = 1.0 - color.r;
|
|
41
|
-
color.g = 1.0 - color.g;
|
|
42
|
-
color.b = 1.0 - color.b;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return color;
|
|
37
|
+
fragment: `
|
|
38
|
+
vec4 effectMain() {
|
|
39
|
+
vec4 color = sampleSourcePixel();
|
|
40
|
+
if (u_flipColor) {
|
|
41
|
+
color.r = 1.0 - color.r;
|
|
42
|
+
color.g = 1.0 - color.g;
|
|
43
|
+
color.b = 1.0 - color.b;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return color;
|
|
46
47
|
}`,
|
|
47
48
|
// Because we're moving pixels around, we must tell the render system where the source pixel was originally located - otherwise
|
|
48
49
|
// element locate will not work correctly.
|
|
@@ -72,11 +73,11 @@ export class FlipImageEffect extends AddEffectTool {
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
|
-
FlipImageEffect.toolId = "FlipImageEffect";
|
|
76
76
|
/** Configure the [[FlipImageEffect]].
|
|
77
77
|
* @beta
|
|
78
78
|
*/
|
|
79
79
|
export class FlipImageConfig extends Tool {
|
|
80
|
+
static { this.toolId = "FlipImageConfig"; }
|
|
80
81
|
static get minArgs() { return 0; }
|
|
81
82
|
static get maxArgs() { return 3; }
|
|
82
83
|
async run(horizontal, vertical, color) {
|
|
@@ -91,5 +92,4 @@ export class FlipImageConfig extends Tool {
|
|
|
91
92
|
return this.run(args.getBoolean("h"), args.getBoolean("v"), args.getBoolean("c"));
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
|
-
FlipImageConfig.toolId = "FlipImageConfig";
|
|
95
95
|
//# sourceMappingURL=FlipImage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlipImage.js","sourceRoot":"","sources":["../../../src/effects/FlipImage.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAEzE,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"FlipImage.js","sourceRoot":"","sources":["../../../src/effects/FlipImage.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAEzE,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,IAAI,SAAS,GAAG,KAAK,CAAC;AAEtB;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,aAAa;aACzB,WAAM,GAAG,iBAAiB,CAAC;IAElD,IAAc,UAAU,KAAK,OAAO,MAAM,CAAC,CAAC,CAAC;IAC7C,IAAc,wBAAwB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD,IAAc,MAAM;QAClB,OAAO;YACL,yDAAyD;YACzD,MAAM,EAAE;;;;;;;;;;UAUJ;YACJ,+EAA+E;YAC/E,QAAQ,EAAE;;;;;;;;;;UAUN;YACJ,+HAA+H;YAC/H,0CAA0C;YAC1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AO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAElC,KAAK,CAAC,GAAG,CAAC,UAAoB,EAAE,QAAkB,EAAE,KAAe;QACjF,cAAc,GAAG,CAAC,CAAC,UAAU,CAAC;QAC9B,YAAY,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC1B,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC;QAEpB,yBAAyB,CAAC,UAAU,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IACpF,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 { ScreenSpaceEffectBuilder, Tool, UniformType, VaryingType } from \"@itwin/core-frontend\";\nimport { parseArgs } from \"../tools/parseArgs\";\nimport { AddEffectTool, refreshViewportsForEffect } from \"./EffectTools\";\n\nlet flipHorizontal = false;\nlet flipVertical = false;\nlet flipColor = false;\n\n/** An extremely simple and mostly useless effect intended to demonstrate the basics of creating a screen-space effect.\n * It flips the Viewport's image on the x and/or y axis, and/or inverts the color of each pixel.\n * @beta\n */\nexport class FlipImageEffect extends AddEffectTool {\n public static override toolId = \"FlipImageEffect\";\n\n protected get effectName() { return \"flip\"; }\n protected get textureCoordFromPosition() { return true; }\n\n protected get source() {\n return {\n // Compute texture coordinate for use in fragment shader.\n vertex: `\n void effectMain(vec4 pos) {\n vec2 uv = textureCoordFromPosition(pos);\n if (u_flipHorizontal)\n uv.x = 1.0 - uv.x;\n\n if (u_flipVertical)\n uv.y = 1.0 - uv.y;\n\n v_uv = uv;\n }`,\n // Sample the original image to flip on x and/or y axis, then invert its color.\n fragment: `\n vec4 effectMain() {\n vec4 color = sampleSourcePixel();\n if (u_flipColor) {\n color.r = 1.0 - color.r;\n color.g = 1.0 - color.g;\n color.b = 1.0 - color.b;\n }\n\n return color;\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: \"return TEXTURE(u_diffuse, v_uv);\",\n };\n }\n\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\n // Don't bother applying the effect if nothing is to be flipped.\n builder.shouldApply = (_context) => flipHorizontal || flipVertical || flipColor;\n\n // Define the varying for the texture coordinate.\n builder.addVarying(\"v_uv\", VaryingType.Vec2);\n\n // Hook up the uniforms.\n builder.addUniform({\n name: \"u_flipHorizontal\",\n type: UniformType.Bool,\n bind: (uniform, _context) => uniform.setUniform1i(flipHorizontal ? 1 : 0),\n });\n builder.addUniform({\n name: \"u_flipVertical\",\n type: UniformType.Bool,\n bind: (uniform, _context) => uniform.setUniform1i(flipVertical ? 1 : 0),\n });\n builder.addUniform({\n name: \"u_flipColor\",\n type: UniformType.Bool,\n bind: (uniform, _context) => uniform.setUniform1i(flipColor ? 1 : 0),\n });\n }\n}\n\n/** Configure the [[FlipImageEffect]].\n * @beta\n */\nexport class FlipImageConfig extends Tool {\n public static override toolId = \"FlipImageConfig\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 3; }\n\n public override async run(horizontal?: boolean, vertical?: boolean, color?: boolean): Promise<boolean> {\n flipHorizontal = !!horizontal;\n flipVertical = !!vertical;\n flipColor = !!color;\n\n refreshViewportsForEffect(\"fdt flip\");\n return true;\n }\n\n public override async parseAndRun(...input: string[]): Promise<boolean> {\n const args = parseArgs(input);\n return this.run(args.getBoolean(\"h\"), args.getBoolean(\"v\"), args.getBoolean(\"c\"));\n }\n}\n"]}
|
|
@@ -16,36 +16,37 @@ import { parseArgs } from "../tools/parseArgs";
|
|
|
16
16
|
* @beta
|
|
17
17
|
*/
|
|
18
18
|
export class LensDistortionEffect extends AddEffectTool {
|
|
19
|
+
static { this.toolId = "LensDistortionEffect"; }
|
|
19
20
|
get effectName() { return "lensdistortion"; }
|
|
20
21
|
get textureCoordFromPosition() { return true; }
|
|
21
22
|
get source() {
|
|
22
23
|
return {
|
|
23
|
-
vertex: `
|
|
24
|
-
void effectMain(vec4 position) {
|
|
25
|
-
vec2 uv = textureCoordFromPosition(position);
|
|
26
|
-
float scaledHeight = strength * height;
|
|
27
|
-
float cylAspectRatio = aspectRatio * cylindricalRatio;
|
|
28
|
-
float aspectDiagSq = aspectRatio * aspectRatio + 1.0;
|
|
29
|
-
float diagSq = scaledHeight * scaledHeight * aspectDiagSq;
|
|
30
|
-
vec2 signedUV = (2.0 * uv + vec2(-1.0, -1.0));
|
|
31
|
-
|
|
32
|
-
float z = 0.5 * sqrt(diagSq + 1.0) + 0.5;
|
|
33
|
-
float ny = (z - 1.0) / (cylAspectRatio * cylAspectRatio + 1.0);
|
|
34
|
-
|
|
35
|
-
vUVDot = sqrt(ny) * vec2(cylAspectRatio, 1.0) * signedUV;
|
|
36
|
-
vUV = vec3(0.5, 0.5, 1.0) * z + vec3(-0.5, -0.5, 0.0);
|
|
37
|
-
vUV.xy += uv;
|
|
24
|
+
vertex: `
|
|
25
|
+
void effectMain(vec4 position) {
|
|
26
|
+
vec2 uv = textureCoordFromPosition(position);
|
|
27
|
+
float scaledHeight = strength * height;
|
|
28
|
+
float cylAspectRatio = aspectRatio * cylindricalRatio;
|
|
29
|
+
float aspectDiagSq = aspectRatio * aspectRatio + 1.0;
|
|
30
|
+
float diagSq = scaledHeight * scaledHeight * aspectDiagSq;
|
|
31
|
+
vec2 signedUV = (2.0 * uv + vec2(-1.0, -1.0));
|
|
32
|
+
|
|
33
|
+
float z = 0.5 * sqrt(diagSq + 1.0) + 0.5;
|
|
34
|
+
float ny = (z - 1.0) / (cylAspectRatio * cylAspectRatio + 1.0);
|
|
35
|
+
|
|
36
|
+
vUVDot = sqrt(ny) * vec2(cylAspectRatio, 1.0) * signedUV;
|
|
37
|
+
vUV = vec3(0.5, 0.5, 1.0) * z + vec3(-0.5, -0.5, 0.0);
|
|
38
|
+
vUV.xy += uv;
|
|
38
39
|
}`,
|
|
39
40
|
// We simply shift pixels - we don't alter their colors.
|
|
40
|
-
fragment: `
|
|
41
|
-
vec4 effectMain() {
|
|
42
|
-
return sampleSourcePixel();
|
|
41
|
+
fragment: `
|
|
42
|
+
vec4 effectMain() {
|
|
43
|
+
return sampleSourcePixel();
|
|
43
44
|
}`,
|
|
44
45
|
// Because we're moving pixels around, we must tell the render system where the source pixel was originally located - otherwise
|
|
45
46
|
// element locate will not work correctly.
|
|
46
|
-
sampleSourcePixel: `
|
|
47
|
-
vec3 uv = dot(vUVDot, vUVDot) * vec3(-0.5, -0.5, -1.0) + vUV;
|
|
48
|
-
return TEXTURE_PROJ(u_diffuse, uv);
|
|
47
|
+
sampleSourcePixel: `
|
|
48
|
+
vec3 uv = dot(vUVDot, vUVDot) * vec3(-0.5, -0.5, -1.0) + vUV;
|
|
49
|
+
return TEXTURE_PROJ(u_diffuse, uv);
|
|
49
50
|
`,
|
|
50
51
|
};
|
|
51
52
|
}
|
|
@@ -81,13 +82,15 @@ export class LensDistortionEffect extends AddEffectTool {
|
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
|
-
LensDistortionEffect.toolId = "LensDistortionEffect";
|
|
85
85
|
/** Configures the [[LensDistortionEffect]].
|
|
86
86
|
* @beta
|
|
87
87
|
*/
|
|
88
88
|
export class LensDistortionConfig extends Tool {
|
|
89
|
+
static { this.toolId = "LensDistortionConfig"; }
|
|
89
90
|
static get minArgs() { return 0; }
|
|
90
91
|
static get maxArgs() { return 2; }
|
|
92
|
+
static { this.strength = 0.5; }
|
|
93
|
+
static { this.cylindricalRatio = 0.5; }
|
|
91
94
|
async run(strength, ratio) {
|
|
92
95
|
LensDistortionConfig.strength = strength ?? 0.5;
|
|
93
96
|
LensDistortionConfig.cylindricalRatio = ratio ?? 0.5;
|
|
@@ -99,7 +102,4 @@ export class LensDistortionConfig extends Tool {
|
|
|
99
102
|
return this.run(args.getFloat("s"), args.getFloat("r"));
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
|
-
LensDistortionConfig.toolId = "LensDistortionConfig";
|
|
103
|
-
LensDistortionConfig.strength = 0.5;
|
|
104
|
-
LensDistortionConfig.cylindricalRatio = 0.5;
|
|
105
105
|
//# sourceMappingURL=LensDistortion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LensDistortion.js","sourceRoot":"","sources":["../../../src/effects/LensDistortion.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"LensDistortion.js","sourceRoot":"","sources":["../../../src/effects/LensDistortion.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;;;GAKG;AACH,M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AG,KAAe;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,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","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Random.js","sourceRoot":"","sources":["../../../src/effects/Random.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAoB,MAAM,sBAAsB,CAAC;AAEjE;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,GAAW;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;AAC9E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAClD,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\
|
|
1
|
+
{"version":3,"file":"Random.js","sourceRoot":"","sources":["../../../src/effects/Random.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAoB,MAAM,sBAAsB,CAAC;AAEjE;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW,EAAE,GAAW;IACpD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;AAC9E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAClD,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,MAAM,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC9B,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 { Point3d, Range1d, Range3d } from \"@itwin/core-geometry\";\n\n/** Generate integer in [min, max].\n * @beta\n */\nexport function randomInteger(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n\n/** Generate random integer in [range.low, range.high].\n * @beta\n */\nexport function randomIntegerInRange(range: Range1d): number {\n return Math.floor(Math.random() * (range.high - range.low + 1)) + range.low;\n}\n\n/** Generate random floating-point number in [min, max).\n * @beta\n */\nexport function randomFloat(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/** Generate random floating-point number in [range.low, range.high).\n * @beta\n */\nexport function randomFloatInRange(range: Range1d): number {\n return randomFloat(range.low, range.high);\n}\n\n/** Generate a random position in the specified range.\n * @beta\n */\nexport function randomPositionInRange(range: Range3d): Point3d {\n const x = randomFloat(range.low.x, range.high.x);\n const y = randomFloat(range.low.y, range.high.y);\n const z = randomFloat(range.low.z, range.high.z);\n return new Point3d(x, y, z);\n}\n"]}
|
|
@@ -12,40 +12,41 @@ import { AddEffectTool, refreshViewportsForEffect } from "./EffectTools";
|
|
|
12
12
|
* @beta
|
|
13
13
|
*/
|
|
14
14
|
export class SaturationEffect extends AddEffectTool {
|
|
15
|
+
static { this.toolId = "SaturationEffect"; }
|
|
15
16
|
get effectName() { return "Saturation"; }
|
|
16
17
|
get textureCoordFromPosition() { return true; }
|
|
17
18
|
get source() {
|
|
18
19
|
// rgb <-> hsl conversion routines from https://gamedev.stackexchange.com/questions/59797/glsl-shader-change-hue-saturation-brightness
|
|
19
20
|
return {
|
|
20
21
|
// Vertex shader simply computes texture coordinate for source pixel.
|
|
21
|
-
vertex: `
|
|
22
|
-
void effectMain(vec4 pos) {
|
|
23
|
-
v_texCoord = textureCoordFromPosition(pos);
|
|
22
|
+
vertex: `
|
|
23
|
+
void effectMain(vec4 pos) {
|
|
24
|
+
v_texCoord = textureCoordFromPosition(pos);
|
|
24
25
|
}`,
|
|
25
26
|
// Fragment shader converts color to HSV, adjusts the saturation, and converts back to RGB.
|
|
26
|
-
fragment: `
|
|
27
|
-
vec3 rgb2hsv(vec3 c) {
|
|
28
|
-
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
29
|
-
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
|
30
|
-
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
|
31
|
-
|
|
32
|
-
float d = q.x - min(q.w, q.y);
|
|
33
|
-
float e = 1.0e-10;
|
|
34
|
-
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
vec3 hsv2rgb(vec3 c) {
|
|
38
|
-
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
39
|
-
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
40
|
-
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
vec4 effectMain() {
|
|
44
|
-
vec4 color = TEXTURE(u_diffuse, v_texCoord);
|
|
45
|
-
color.rgb = rgb2hsv(color.rgb);
|
|
46
|
-
color.rgb.y = color.rgb.y * u_saturationMult;
|
|
47
|
-
color.rgb = hsv2rgb(color.rgb);
|
|
48
|
-
return color;
|
|
27
|
+
fragment: `
|
|
28
|
+
vec3 rgb2hsv(vec3 c) {
|
|
29
|
+
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
30
|
+
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
|
31
|
+
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
|
32
|
+
|
|
33
|
+
float d = q.x - min(q.w, q.y);
|
|
34
|
+
float e = 1.0e-10;
|
|
35
|
+
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
vec3 hsv2rgb(vec3 c) {
|
|
39
|
+
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
40
|
+
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
41
|
+
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
vec4 effectMain() {
|
|
45
|
+
vec4 color = TEXTURE(u_diffuse, v_texCoord);
|
|
46
|
+
color.rgb = rgb2hsv(color.rgb);
|
|
47
|
+
color.rgb.y = color.rgb.y * u_saturationMult;
|
|
48
|
+
color.rgb = hsv2rgb(color.rgb);
|
|
49
|
+
return color;
|
|
49
50
|
}`,
|
|
50
51
|
};
|
|
51
52
|
}
|
|
@@ -58,13 +59,15 @@ export class SaturationEffect extends AddEffectTool {
|
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
|
-
SaturationEffect.toolId = "SaturationEffect";
|
|
62
62
|
/** Configures the [[SaturationEffect]].
|
|
63
63
|
* @beta
|
|
64
64
|
*/
|
|
65
65
|
export class SaturationConfig extends Tool {
|
|
66
|
+
static { this.toolId = "SaturationConfig"; }
|
|
66
67
|
static get minArgs() { return 0; }
|
|
67
68
|
static get maxArgs() { return 1; }
|
|
69
|
+
/** Multiplier applied to the saturation of each color in the source image. */
|
|
70
|
+
static { this.multiplier = 2.0; }
|
|
68
71
|
async run(multiplier) {
|
|
69
72
|
SaturationConfig.multiplier = multiplier ?? 2.0;
|
|
70
73
|
refreshViewportsForEffect("fdt Saturation");
|
|
@@ -75,7 +78,4 @@ export class SaturationConfig extends Tool {
|
|
|
75
78
|
return this.run(args.getFloat("s"));
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
SaturationConfig.toolId = "SaturationConfig";
|
|
79
|
-
/** Multiplier applied to the saturation of each color in the source image. */
|
|
80
|
-
SaturationConfig.multiplier = 2.0;
|
|
81
81
|
//# 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,OAAO,EAA4B,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAEzE;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"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AAK,CAAC,GAAG,CAAC,UAAmB;QAC3C,gBAAgB,CAAC,UAAU,GAAG,UAAU,IAAI,GAAG,CAAC;QAChD,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,KAAe;QAClD,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,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 { 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,CAAC;IACnB,wEAAwE;IACxE,iBAAiB,EAAE,OAAO,CAAC;IAC3B,kGAAkG;IAClG,aAAa,EAAE,OAAO,CAAC;IACvB,2JAA2J;IAC3J,iBAAiB,EAAE,OAAO,CAAC;IAC3B,+CAA+C;IAC/C,YAAY,EAAE,MAAM,CAAC;CACtB;AAYD;;;;GAIG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C,oCAAoC;IACpC,SAAgB,QAAQ,EAAE,QAAQ,CAAC;IACnC,sDAAsD;IACtD,SAAgB,OAAO,EAAE,YAAY,CAAC;
|
|
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,E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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/esm/effects/Snow.js
CHANGED
|
@@ -26,6 +26,7 @@ const defaultSnowParams = {
|
|
|
26
26
|
* @beta
|
|
27
27
|
*/
|
|
28
28
|
export class SnowDecorator {
|
|
29
|
+
static { Symbol.dispose; }
|
|
29
30
|
constructor(viewport, texture) {
|
|
30
31
|
/** The list of particles being drawn. */
|
|
31
32
|
this._particles = [];
|
|
@@ -41,13 +42,13 @@ export class SnowDecorator {
|
|
|
41
42
|
// Transfer ownership of the texture to the new decorator.
|
|
42
43
|
const tex = this._texture;
|
|
43
44
|
this._texture = undefined;
|
|
44
|
-
this.dispose();
|
|
45
|
+
this[Symbol.dispose]();
|
|
45
46
|
new SnowDecorator(viewport, tex);
|
|
46
47
|
});
|
|
47
48
|
// When the viewport is destroyed, dispose of this decorator too.
|
|
48
|
-
const removeOnDispose = viewport.onDisposed.addListener(() => this.dispose());
|
|
49
|
+
const removeOnDispose = viewport.onDisposed.addListener(() => this[Symbol.dispose]());
|
|
49
50
|
const removeDecorator = IModelApp.viewManager.addDecorator(this);
|
|
50
|
-
this.dispose = () => {
|
|
51
|
+
this[Symbol.dispose] = () => {
|
|
51
52
|
removeDecorator();
|
|
52
53
|
removeOnRender();
|
|
53
54
|
removeOnDispose();
|
|
@@ -138,6 +139,7 @@ export class SnowDecorator {
|
|
|
138
139
|
this._particles[i] = this.emit(false);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
142
|
+
static { this._decorators = new Map(); }
|
|
141
143
|
/** Toggle this decorator for the specified viewport.
|
|
142
144
|
* @param viewport The viewport to which the effect should be applied or removed.
|
|
143
145
|
* @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.
|
|
@@ -147,7 +149,7 @@ export class SnowDecorator {
|
|
|
147
149
|
if (undefined === enable)
|
|
148
150
|
enable = undefined === decorator;
|
|
149
151
|
if (undefined !== decorator && !enable)
|
|
150
|
-
decorator.dispose();
|
|
152
|
+
decorator[Symbol.dispose]();
|
|
151
153
|
else if (undefined === decorator && enable) {
|
|
152
154
|
// Create a texture to use for the particles.
|
|
153
155
|
// Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.
|
|
@@ -160,12 +162,12 @@ export class SnowDecorator {
|
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
164
|
}
|
|
163
|
-
SnowDecorator._decorators = new Map();
|
|
164
165
|
/** Toggles a decorator that simulates snow using particle effects.
|
|
165
166
|
* @see [[SnowDecorator]] for the implementation of the decorator.
|
|
166
167
|
* @beta
|
|
167
168
|
*/
|
|
168
169
|
export class SnowEffect extends Tool {
|
|
170
|
+
static { this.toolId = "SnowEffect"; }
|
|
169
171
|
async run(enable) {
|
|
170
172
|
const vp = IModelApp.viewManager.selectedView;
|
|
171
173
|
if (vp)
|
|
@@ -179,5 +181,4 @@ export class SnowEffect extends Tool {
|
|
|
179
181
|
return true;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
|
-
SnowEffect.toolId = "SnowEffect";
|
|
183
184
|
//# 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,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC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AAC,CAAC;YAEH,IAAI,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;;AAxBuB,yBAAW,GAAG,IAAI,GAAG,EAA2B,AAArC,CAAsC;AA2B3E;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,IAAI;IAGlB,KAAK,CAAC,GAAG,CAAC,MAAgB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE;YACJ,MAAM,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAEzC,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,WAAW,CAAC,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;;AAhBsB,iBAAM,GAAG,YAAY,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Effects\r\n */\r\n\r\nimport { dispose } from \"@itwin/core-bentley\";\r\nimport { Point2d, Range1d, Range2d, Vector2d } from \"@itwin/core-geometry\";\r\nimport { RenderTexture, TextureTransparency } from \"@itwin/core-common\";\r\nimport {\r\n DecorateContext, Decorator, GraphicType, imageElementFromUrl, IModelApp, ParticleCollectionBuilder, ParticleProps, Tool, Viewport,\r\n} from \"@itwin/core-frontend\";\r\nimport { parseToggle } from \"../tools/parseToggle\";\r\nimport { randomFloat, randomInteger } from \"./Random\";\r\n\r\n/** Represents one particle displayed by a [[SnowDecorator]].\r\n * Particle positions are in [CoordSystem.View]($frontend).\r\n * @beta\r\n */\r\nexport interface SnowParticle extends ParticleProps {\r\n /** Make x, y, and z from ParticleProps writable. */\r\n x: number;\r\n y: number;\r\n z: number;\r\n\r\n /** Current velocity, in pixels per second. */\r\n velocity: Vector2d;\r\n}\r\n\r\n/** Parameters controlling how a [[SnowDecorator]] works.\r\n * @beta\r\n */\r\nexport interface SnowParams {\r\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. */\r\n numParticles: number;\r\n /** Range from which to randomly select each particle's size, in pixels. */\r\n sizeRange: Range1d;\r\n /** Range from which to randomly select each particle's transparency. */\r\n transparencyRange: Range1d;\r\n /** Range from which to randomly select each particle's initial velocity, in pixels per second. */\r\n velocityRange: Range2d;\r\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. */\r\n accelerationRange: Range2d;\r\n /** Wind velocity in pixels per second in X. */\r\n windVelocity: number;\r\n}\r\n\r\n/** The default snow effect parameters used by newly-created SnowDecorators. */\r\nconst defaultSnowParams: SnowParams = {\r\n numParticles: 2000,\r\n sizeRange: Range1d.createXX(3, 22),\r\n transparencyRange: Range1d.createXX(0, 50),\r\n velocityRange: new Range2d(-30, 50, 30, 130),\r\n accelerationRange: new Range2d(-1, -0.25, 1, 0.25),\r\n windVelocity: 0,\r\n};\r\n\r\n/** Simulates snowfall in a [Viewport]($frontend) using particle effects.\r\n * @see [[SnowEffect]] for a [Tool]($frontend) that toggles this decorator.\r\n * @see [ParticleCollectionBuilder]($frontend) for defining custom particle effects.\r\n * @beta\r\n */\r\nexport class SnowDecorator implements Decorator {\r\n /** The viewport being decorated. */\r\n public readonly viewport: Viewport;\r\n /** Invoked when this decorator is to be destroyed. */\r\n public readonly dispose: VoidFunction;\r\n /** The initial width and height of the viewport, from which we randomly select each particle's initial position. */\r\n private readonly _dimensions: Point2d;\r\n /** The list of particles being drawn. */\r\n private readonly _particles: SnowParticle[] = [];\r\n /** The image to display for each particle. */\r\n private _texture?: RenderTexture;\r\n /** The last time `updateParticles()` was invoked, in milliseconds. */\r\n private _lastUpdateTime: number;\r\n private readonly _params: SnowParams;\r\n\r\n private constructor(viewport: Viewport, texture: RenderTexture | undefined) {\r\n this._params = { ...defaultSnowParams };\r\n this.viewport = viewport;\r\n this._dimensions = new Point2d(viewport.viewRect.width, viewport.viewRect.height);\r\n this._lastUpdateTime = Date.now();\r\n this._texture = texture;\r\n\r\n // Tell the viewport to re-render the decorations every frame so that the snow particles animate smoothly.\r\n const removeOnRender = viewport.onRender.addListener(() => viewport.invalidateDecorations());\r\n\r\n // When the viewport is resized, replace this decorator with a new one to match the new dimensions.\r\n const removeOnResized = viewport.onResized.addListener(() => {\r\n // Transfer ownership of the texture to the new decorator.\r\n const tex = this._texture;\r\n this._texture = undefined;\r\n this.dispose();\r\n new SnowDecorator(viewport, tex);\r\n });\r\n\r\n // When the viewport is destroyed, dispose of this decorator too.\r\n const removeOnDispose = viewport.onDisposed.addListener(() => this.dispose());\r\n const removeDecorator = IModelApp.viewManager.addDecorator(this);\r\n\r\n this.dispose = () => {\r\n removeDecorator();\r\n removeOnRender();\r\n removeOnDispose();\r\n removeOnResized();\r\n this._texture = dispose(this._texture);\r\n SnowDecorator._decorators.delete(viewport);\r\n };\r\n\r\n SnowDecorator._decorators.set(viewport, this);\r\n\r\n // Initialize the particles.\r\n for (let i = 0; i < this._params.numParticles; i++)\r\n this._particles.push(this.emit(true));\r\n }\r\n\r\n public decorate(context: DecorateContext): void {\r\n if (context.viewport !== this.viewport || !this._texture)\r\n return;\r\n\r\n // Update the particles.\r\n const now = Date.now();\r\n const deltaMillis = now - this._lastUpdateTime;\r\n this._lastUpdateTime = now;\r\n this.updateParticles(deltaMillis / 1000);\r\n\r\n // Create particle graphics.\r\n const builder = ParticleCollectionBuilder.create({\r\n viewport: this.viewport,\r\n isViewCoords: true,\r\n texture: this._texture,\r\n size: (this._params.sizeRange.high - this._params.sizeRange.low) / 2,\r\n });\r\n\r\n for (const particle of this._particles)\r\n builder.addParticle(particle);\r\n\r\n const graphic = builder.finish();\r\n if (graphic)\r\n context.addDecoration(GraphicType.ViewOverlay, graphic);\r\n }\r\n\r\n /** Change some of the parameters affecting this decorator. */\r\n public configure(params: Partial<SnowParams>): void {\r\n for (const key of Object.keys(params)) {\r\n const val = (params as any)[key];\r\n if (undefined !== val)\r\n (this._params as any)[key] = val;\r\n }\r\n }\r\n\r\n /** Emit a new particle with randomized properties. */\r\n private emit(randomizeHeight: boolean): SnowParticle {\r\n return {\r\n x: randomInteger(0, this._dimensions.x),\r\n y: randomizeHeight ? randomInteger(0, this._dimensions.y) : 0,\r\n z: 0,\r\n size: randomInteger(this._params.sizeRange.low, this._params.sizeRange.high),\r\n transparency: randomInteger(this._params.transparencyRange.low, this._params.transparencyRange.high),\r\n velocity: new Vector2d(randomFloat(this._params.velocityRange.low.x, this._params.velocityRange.high.x),\r\n randomFloat(this._params.velocityRange.low.y, this._params.velocityRange.high.y)),\r\n };\r\n }\r\n\r\n // Update the positions and velocities of all the particles based on the amount of time that has passed since the last update.\r\n private updateParticles(elapsedSeconds: number): void {\r\n // Determine if someone changed the desired number of particles.\r\n const particleDiscrepancy = this._params.numParticles - this._particles.length;\r\n if (particleDiscrepancy > 0) {\r\n // Birth new particles up to the new maximum.\r\n for (let i = 0; i < particleDiscrepancy; i++)\r\n this._particles.push(this.emit(true));\r\n } else {\r\n // Destroy extra particles.\r\n this._particles.length = this._params.numParticles;\r\n }\r\n\r\n const acceleration = new Vector2d();\r\n const velocity = new Vector2d();\r\n for (let i = 0; i < this._particles.length; i++) {\r\n // Apply some acceleration to produce random drift.\r\n const particle = this._particles[i];\r\n acceleration.set(randomFloat(this._params.accelerationRange.low.x, this._params.accelerationRange.high.x),\r\n randomFloat(this._params.accelerationRange.low.y, this._params.accelerationRange.high.y));\r\n\r\n acceleration.scale(elapsedSeconds, acceleration);\r\n particle.velocity.plus(acceleration, particle.velocity);\r\n\r\n // Apply velocity.\r\n particle.velocity.clone(velocity);\r\n velocity.scale(elapsedSeconds, velocity);\r\n particle.x += velocity.x;\r\n particle.y += velocity.y;\r\n\r\n // Apply wind\r\n particle.x += this._params.windVelocity * elapsedSeconds;\r\n\r\n // Particles that travel beyond the viewport's left or right edges wrap around to the other side.\r\n if (particle.x < 0)\r\n particle.x = this._dimensions.x - 1;\r\n else if (particle.x >= this._dimensions.x)\r\n particle.x = 0;\r\n\r\n // Particles that travel beyond the viewport's bottom or top edges are replaced by newborn particles.\r\n if (particle.y < 0 || particle.y >= this._dimensions.y)\r\n this._particles[i] = this.emit(false);\r\n }\r\n }\r\n\r\n private static readonly _decorators = new Map<Viewport, SnowDecorator>();\r\n\r\n /** Toggle this decorator for the specified viewport.\r\n * @param viewport The viewport to which the effect should be applied or removed.\r\n * @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.\r\n */\r\n public static async toggle(viewport: Viewport, enable?: boolean): Promise<void> {\r\n const decorator = this._decorators.get(viewport);\r\n if (undefined === enable)\r\n enable = undefined === decorator;\r\n\r\n if (undefined !== decorator && !enable)\r\n decorator.dispose();\r\n else if (undefined === decorator && enable) {\r\n // Create a texture to use for the particles.\r\n // Note: the decorator takes ownership of the texture, and disposes of it when the decorator is disposed.\r\n const image = await imageElementFromUrl(`${IModelApp.publicPath}sprites/particle_snow.png`);\r\n const texture = IModelApp.renderSystem.createTexture({\r\n ownership: \"external\",\r\n image: { source: image, transparency: TextureTransparency.Mixed },\r\n });\r\n\r\n new SnowDecorator(viewport, texture);\r\n }\r\n }\r\n}\r\n\r\n/** Toggles a decorator that simulates snow using particle effects.\r\n * @see [[SnowDecorator]] for the implementation of the decorator.\r\n * @beta\r\n */\r\nexport class SnowEffect extends Tool {\r\n public static override toolId = \"SnowEffect\";\r\n\r\n public override async run(enable?: boolean): Promise<boolean> {\r\n const vp = IModelApp.viewManager.selectedView;\r\n if (vp)\r\n await SnowDecorator.toggle(vp, enable);\r\n\r\n return true;\r\n }\r\n\r\n public override async parseAndRun(...args: string[]): Promise<boolean> {\r\n const enable = parseToggle(args[0]);\r\n if (typeof enable !== \"string\")\r\n await this.run(enable);\r\n\r\n return true;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"Snow.js","sourceRoot":"","sources":["../../../src/effects/Snow.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAiB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EACuB,WAAW,EAAE,mBAAmB,EAAE,SAAS,EAAE,yBAAyB,EAAiB,IAAI,GACxH,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAkCtD,+EAA+E;AAC/E,MAAM,iBAAiB,GAAe;IACpC,YAAY,EAAE,IAAI;IAClB,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;IAClC,iBAAiB,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1C,aAAa,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC;IAC5C,iBAAiB,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC;IAClD,YAAY,EAAE,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AACH,MAAM,OAAO,aAAa;aAIP,MAAM,CAAC,OAAO;IAW/B,YAAoB,QAAkB,EAAE,OAAkC;QAR1E,yCAAyC;QACxB,eAAU,GAAmB,EAAE,CAAC;QAQ/C,IAAI,CAAC,OA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IAAI,CAAC,MAAM;YACpC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;aACzB,IAAI,SAAS,KAAK,SAAS,IAAI,MAAM,EAAE,CAAC;YAC3C,6CAA6C;YAC7C,yGAAyG;YACzG,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,GAAG,SAAS,CAAC,UAAU,2BAA2B,CAAC,CAAC;YAC5F,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC;gBACnD,SAAS,EAAE,UAAU;gBACrB,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE;aAClE,CAAC,CAAC;YAEH,IAAI,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;;AAGH;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,IAAI;aACX,WAAM,GAAG,YAAY,CAAC;IAE7B,KAAK,CAAC,GAAG,CAAC,MAAgB;QACxC,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE;YACJ,MAAM,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAEzC,OAAO,IAAI,CAAC;IACd,CAAC;IAEe,KAAK,CAAC,WAAW,CAAC,GAAG,IAAc;QACjD,MAAM,MAAM,GAAG,WAAW,CAAC,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","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"]}
|