@itwin/frontend-devtools 5.0.0-dev.32 → 5.0.0-dev.34
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/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 +2 -2
- 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.js +2 -2
- 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 +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 +12 -12
- 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/widgets/ToolSettingsTracker.js +1 -1
- 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 +2 -2
- 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.js +2 -2
- 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 +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 +12 -12
- 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/widgets/ToolSettingsTracker.js +1 -1
- package/lib/esm/widgets/ToolSettingsTracker.js.map +1 -1
- package/package.json +7 -7
|
@@ -73,6 +73,7 @@ export class ConvolutionEffect extends AddEffectTool {
|
|
|
73
73
|
* @beta
|
|
74
74
|
*/
|
|
75
75
|
export class GaussianBlurEffect extends ConvolutionEffect {
|
|
76
|
+
static { this.toolId = "GaussianBlurEffect"; }
|
|
76
77
|
get effectName() { return "blur"; }
|
|
77
78
|
get matrix() {
|
|
78
79
|
return [
|
|
@@ -82,11 +83,11 @@ export class GaussianBlurEffect extends ConvolutionEffect {
|
|
|
82
83
|
];
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
|
-
GaussianBlurEffect.toolId = "GaussianBlurEffect";
|
|
86
86
|
/** Adds a screen-space unsharpen effect to the selected Viewport.
|
|
87
87
|
* @beta
|
|
88
88
|
*/
|
|
89
89
|
export class UnsharpenEffect extends ConvolutionEffect {
|
|
90
|
+
static { this.toolId = "UnsharpenEffect"; }
|
|
90
91
|
get effectName() { return "unsharpen"; }
|
|
91
92
|
get matrix() {
|
|
92
93
|
return [
|
|
@@ -96,11 +97,11 @@ export class UnsharpenEffect extends ConvolutionEffect {
|
|
|
96
97
|
];
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
UnsharpenEffect.toolId = "UnsharpenEffect";
|
|
100
100
|
/** Adds a screen-space emboss effect to the selected Viewport.
|
|
101
101
|
* @beta
|
|
102
102
|
*/
|
|
103
103
|
export class EmbossEffect extends ConvolutionEffect {
|
|
104
|
+
static { this.toolId = "EmbossEffect"; }
|
|
104
105
|
get effectName() { return "emboss"; }
|
|
105
106
|
get matrix() {
|
|
106
107
|
return [
|
|
@@ -110,11 +111,11 @@ export class EmbossEffect extends ConvolutionEffect {
|
|
|
110
111
|
];
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
|
-
EmbossEffect.toolId = "EmbossEffect";
|
|
114
114
|
/** Adds a screen-space sharpen effect to the selected Viewport.
|
|
115
115
|
* @beta
|
|
116
116
|
*/
|
|
117
117
|
export class SharpenEffect extends ConvolutionEffect {
|
|
118
|
+
static { this.toolId = "SharpenEffect"; }
|
|
118
119
|
get effectName() { return "sharpen"; }
|
|
119
120
|
get matrix() {
|
|
120
121
|
return [
|
|
@@ -124,11 +125,11 @@ export class SharpenEffect extends ConvolutionEffect {
|
|
|
124
125
|
];
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
|
-
SharpenEffect.toolId = "SharpenEffect";
|
|
128
128
|
/** Adds a screen-space sharpness effect to the selected Viewport.
|
|
129
129
|
* @beta
|
|
130
130
|
*/
|
|
131
131
|
export class SharpnessEffect extends ConvolutionEffect {
|
|
132
|
+
static { this.toolId = "SharpnessEffect"; }
|
|
132
133
|
get effectName() { return "sharpness"; }
|
|
133
134
|
get matrix() {
|
|
134
135
|
return [
|
|
@@ -138,11 +139,11 @@ export class SharpnessEffect extends ConvolutionEffect {
|
|
|
138
139
|
];
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
|
-
SharpnessEffect.toolId = "SharpnessEffect";
|
|
142
142
|
/** Adds a screen-space edge-detection effect to the selected Viewport.
|
|
143
143
|
* @beta
|
|
144
144
|
*/
|
|
145
145
|
export class EdgeDetectionEffect extends ConvolutionEffect {
|
|
146
|
+
static { this.toolId = "EdgeDetectionEffect"; }
|
|
146
147
|
get effectName() { return "edgedetect"; }
|
|
147
148
|
get matrix() {
|
|
148
149
|
return [
|
|
@@ -152,5 +153,4 @@ export class EdgeDetectionEffect extends ConvolutionEffect {
|
|
|
152
153
|
];
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
|
-
EdgeDetectionEffect.toolId = "EdgeDetectionEffect";
|
|
156
156
|
//# sourceMappingURL=Convolution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Convolution.js","sourceRoot":"","sources":["../../../src/effects/Convolution.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAA4B,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;;GAGG;AACH,MAAM,OAAgB,iBAAkB,SAAQ,aAAa;IACpD,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAIlD,IAAc,wBAAwB,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAEzD,IAAc,MAAM;QAClB,OAAO;YACL,2FAA2F;YAC3F,MAAM,EAAE;;;UAGJ;YACJ,kFAAkF;YAClF,QAAQ,EAAE;;;;;;;;;;;;;;UAcN;SACL,CAAC;IACJ,CAAC;IAES,YAAY,CAAC,OAAiC;QACtD,iDAAiD;QACjD,OAAO,CAAC,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;QAEnD,wBAAwB;QACxB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,OAAO,CAAC,UAAU,CAAC;YACjB,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;gBACzB,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;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CAAC,EAAE,CAAC;YACR,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACT,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;;AAGH;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,iBAAiB;aAC7B,WAAM,GAAG,iBAAiB,CAAC;IAClD,IAAc,UAAU,KAAK,OAAO,WAAW,CAAC,CAAC,CAAC;IAClD,IAAc,MAAM;QAClB,OAAO;YACL,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YACR,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YACT,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;SACT,CAAC;IACJ,CAAC;;AAGH;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,iBAAiB;aACjC,WAAM,GAAG,qBAAqB,CAAC;IACtD,IAAc,UAAU,KAAK,OAAO,YAAY,CAAC,CAAC,CAAC;IACnD,IAAc,MAAM;QAClB,OAAO;YACL,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;YACR,CAAC,EAAE,CAAC,EAAE,CAAC;YACP,CAAC,EAAE,CAAC,EAAE,CAAC;SACR,CAAC;IACJ,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, UniformType, VaryingType } from \"@itwin/core-frontend\";\nimport { AddEffectTool } from \"./EffectTools\";\n\n/** Adds one of a collection of \"convolution kernels\" that alter a [Viewport]($frontend)'s image by blending neighboring pixels.\n * Based on https://webglfundamentals.org/webgl/lessons/webgl-image-processing-continued.html\n * @beta\n */\nexport abstract class ConvolutionEffect extends AddEffectTool {\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 0; }\n\n protected abstract get matrix(): number[];\n\n protected get textureCoordFromPosition() { return true; }\n\n protected get source() {\n return {\n // The vertex shader simply computes the texture coordinate for use in the fragment shader.\n vertex: `\n void effectMain(vec4 pos) {\n v_texCoord = textureCoordFromPosition(pos);\n }`,\n // The fragment shader samples the pixel and its neighbors and applies the kernel.\n fragment: `\n vec4 effectMain() {\n vec2 onePixel = vec2(1.0, 1.0) / u_textureSize;\n vec4 colorSum =\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2(-1, -1)) * u_kernel[0] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2( 0, -1)) * u_kernel[1] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2( 1, -1)) * u_kernel[2] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2(-1, 0)) * u_kernel[3] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2( 0, 0)) * u_kernel[4] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2( 1, 0)) * u_kernel[5] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2(-1, 1)) * u_kernel[6] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2( 0, 1)) * u_kernel[7] +\n TEXTURE(u_diffuse, v_texCoord + onePixel * vec2( 1, 1)) * u_kernel[8] ;\n return vec4((colorSum / u_kernelWeight).rgb, 1);\n }`,\n };\n }\n\n protected defineEffect(builder: ScreenSpaceEffectBuilder): void {\n // Define the varying for the texture coordinate.\n builder.addVarying(\"v_texCoord\", VaryingType.Vec2);\n\n // Hook up the uniforms.\n const matrix = this.matrix;\n builder.addUniform({\n name: \"u_textureSize\",\n type: UniformType.Vec2,\n bind: (uniform, context) => {\n const rect = context.viewport.viewRect;\n uniform.setUniform2fv([rect.width, rect.height]);\n },\n });\n builder.addUniformArray({\n name: \"u_kernel\",\n type: UniformType.Float,\n length: matrix.length,\n bind: (uniform) => uniform.setUniform1fv(matrix),\n });\n\n let weight = matrix.reduce((prev, curr) => prev + curr);\n if (weight <= 0)\n weight = 1;\n\n builder.addUniform({\n name: \"u_kernelWeight\",\n type: UniformType.Float,\n bind: (uniform) => uniform.setUniform1f(weight),\n });\n }\n}\n\n/** Adds a gaussian blur screen-space effect to the selected Viewport.\n * @beta\n */\nexport class GaussianBlurEffect extends ConvolutionEffect {\n public static override toolId = \"GaussianBlurEffect\";\n protected get effectName() { return \"blur\"; }\n protected get matrix() {\n return [\n 0.045, 0.122, 0.045,\n 0.122, 0.332, 0.122,\n 0.045, 0.122, 0.045,\n ];\n }\n}\n\n/** Adds a screen-space unsharpen effect to the selected Viewport.\n * @beta\n */\nexport class UnsharpenEffect extends ConvolutionEffect {\n public static override toolId = \"UnsharpenEffect\";\n protected get effectName() { return \"unsharpen\"; }\n protected get matrix() {\n return [\n -1, -1, -1,\n -1, 9, -1,\n -1, -1, -1,\n ];\n }\n}\n\n/** Adds a screen-space emboss effect to the selected Viewport.\n * @beta\n */\nexport class EmbossEffect extends ConvolutionEffect {\n public static override toolId = \"EmbossEffect\";\n protected get effectName() { return \"emboss\"; }\n protected get matrix() {\n return [\n -2, -1, 0,\n -1, 1, 1,\n 0, 1, 2,\n ];\n }\n}\n\n/** Adds a screen-space sharpen effect to the selected Viewport.\n * @beta\n */\nexport class SharpenEffect extends ConvolutionEffect {\n public static override toolId = \"SharpenEffect\";\n protected get effectName() { return \"sharpen\"; }\n protected get matrix() {\n return [\n 0, -1, 0,\n -1, 5, -1,\n 0, -1, 0,\n ];\n }\n}\n\n/** Adds a screen-space sharpness effect to the selected Viewport.\n * @beta\n */\nexport class SharpnessEffect extends ConvolutionEffect {\n public static override toolId = \"SharpnessEffect\";\n protected get effectName() { return \"sharpness\"; }\n protected get matrix() {\n return [\n 0, -1, 0,\n -1, 5, -1,\n 0, -1, 0,\n ];\n }\n}\n\n/** Adds a screen-space edge-detection effect to the selected Viewport.\n * @beta\n */\nexport class EdgeDetectionEffect extends ConvolutionEffect {\n public static override toolId = \"EdgeDetectionEffect\";\n protected get effectName() { return \"edgedetect\"; }\n protected get matrix() {\n return [\n -5, 0, 0,\n 0, 0, 0,\n 0, 0, 5,\n ];\n }\n}\n"]}
|
|
@@ -11,6 +11,7 @@ import { IModelApp, Tool, } from "@itwin/core-frontend";
|
|
|
11
11
|
* @beta
|
|
12
12
|
*/
|
|
13
13
|
export class AddEffectTool extends Tool {
|
|
14
|
+
static { this._registeredEffects = new Set(); }
|
|
14
15
|
async run() {
|
|
15
16
|
// Avoid conflicts with the names of other registered screen-space effects.
|
|
16
17
|
const name = `fdt ${this.effectName}`;
|
|
@@ -32,11 +33,11 @@ export class AddEffectTool extends Tool {
|
|
|
32
33
|
return true;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
|
-
AddEffectTool._registeredEffects = new Set();
|
|
36
36
|
/** Removes all screen-space effects from the selected viewport.
|
|
37
37
|
* @beta
|
|
38
38
|
*/
|
|
39
39
|
export class ClearEffectsTool extends Tool {
|
|
40
|
+
static { this.toolId = "ClearEffects"; }
|
|
40
41
|
static get minArgs() { return 0; }
|
|
41
42
|
static get maxArgs() { return 0; }
|
|
42
43
|
async run() {
|
|
@@ -44,7 +45,6 @@ export class ClearEffectsTool extends Tool {
|
|
|
44
45
|
return true;
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
ClearEffectsTool.toolId = "ClearEffects";
|
|
48
48
|
/** Requests that any viewport to which the specified effect has been applied redraw its contents.
|
|
49
49
|
* Used by tools like [[VignetteConfig]] to update the view after the effect parameters are modified.
|
|
50
50
|
* @beta
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EffectTools.js","sourceRoot":"","sources":["../../../src/effects/EffectTools.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,SAAS,EAAqD,IAAI,GACnE,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,OAAgB,aAAc,SAAQ,IAAI;
|
|
1
|
+
{"version":3,"file":"Effect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AAC,CAAC,CAAC;IAElC,KAAK,CAAC,GAAG;QACvB,SAAS,CAAC,WAAW,CAAC,YAAY,EAAE,wBAAwB,EAAE,CAAC;QAC/D,OAAO,IAAI,CAAC;IACd,CAAC;;AAGH;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IAC1D,KAAK,MAAM,EAAE,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QACvC,KAAK,MAAM,YAAY,IAAI,EAAE,CAAC,kBAAkB,EAAE,CAAC;YACjD,IAAI,YAAY,KAAK,UAAU,EAAE,CAAC;gBAChC,EAAE,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;AACH,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 {\n IModelApp, ScreenSpaceEffectBuilder, ScreenSpaceEffectSource, Tool,\n} from \"@itwin/core-frontend\";\n\n/** Adds a screen-space effect to the selected viewport.\n * @beta\n */\nexport abstract class AddEffectTool extends Tool {\n private static readonly _registeredEffects = new Set<string>();\n\n /** Name of effect as used in keyins like `fdt effect add`. Ideally one word. */\n protected abstract get effectName(): string;\n /** vertex, fragment, and optional sampleSourcePixel GLSL snippets. */\n protected abstract get source(): ScreenSpaceEffectSource;\n /** Whether the fragment shader should include built-in `textureCoordFromPosition` function. */\n protected abstract get textureCoordFromPosition(): boolean;\n /** Add uniforms, varyings, etc. */\n protected abstract defineEffect(builder: ScreenSpaceEffectBuilder): void;\n\n public override async run(): Promise<boolean> {\n // Avoid conflicts with the names of other registered screen-space effects.\n const name = `fdt ${this.effectName}`;\n if (!AddEffectTool._registeredEffects.has(name)) {\n // Register the effect.\n const builder = IModelApp.renderSystem.createScreenSpaceEffectBuilder({\n name,\n textureCoordFromPosition: this.textureCoordFromPosition,\n source: this.source,\n });\n\n assert(undefined !== builder);\n this.defineEffect(builder);\n builder.finish();\n\n AddEffectTool._registeredEffects.add(name);\n }\n\n const vp = IModelApp.viewManager.selectedView;\n if (vp)\n vp.addScreenSpaceEffect(name);\n\n return true;\n }\n}\n\n/** Removes all screen-space effects from the selected viewport.\n * @beta\n */\nexport class ClearEffectsTool extends Tool {\n public static override toolId = \"ClearEffects\";\n public static override get minArgs() { return 0; }\n public static override get maxArgs() { return 0; }\n\n public override async run(): Promise<boolean> {\n IModelApp.viewManager.selectedView?.removeScreenSpaceEffects();\n return true;\n }\n}\n\n/** Requests that any viewport to which the specified effect has been applied redraw its contents.\n * Used by tools like [[VignetteConfig]] to update the view after the effect parameters are modified.\n * @beta\n */\nexport function refreshViewportsForEffect(effectName: string): void {\n for (const vp of IModelApp.viewManager) {\n for (const vpEffectName of vp.screenSpaceEffects) {\n if (vpEffectName === effectName) {\n vp.requestRedraw();\n break;\n }\n }\n }\n}\n"]}
|
|
@@ -56,6 +56,7 @@ class ParticleEmitter {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
class ParticleSystem {
|
|
59
|
+
static { this.numEmissionsRange = Range1d.createXX(1, 5); }
|
|
59
60
|
constructor(texture, iModel, numEmissions) {
|
|
60
61
|
this._emitter = new ParticleEmitter();
|
|
61
62
|
this._particles = [];
|
|
@@ -148,11 +149,11 @@ class ParticleSystem {
|
|
|
148
149
|
IModelApp.viewManager.addDecorator(new ParticleSystem(texture, iModel, randomIntegerInRange(this.numEmissionsRange)));
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
|
-
ParticleSystem.numEmissionsRange = Range1d.createXX(1, 5);
|
|
152
152
|
/** This tool applies an explosion particle effect used for testing [ParticleCollectionBuilder]($frontend).
|
|
153
153
|
* @beta
|
|
154
154
|
*/
|
|
155
155
|
export class ExplosionEffect extends Tool {
|
|
156
|
+
static { this.toolId = "ExplosionEffect"; }
|
|
156
157
|
/** This method runs the tool, applying an explosion particle effect. */
|
|
157
158
|
async run() {
|
|
158
159
|
const vp = IModelApp.viewManager.selectedView;
|
|
@@ -161,5 +162,4 @@ export class ExplosionEffect extends Tool {
|
|
|
161
162
|
return true;
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
|
-
ExplosionEffect.toolId = "ExplosionEffect";
|
|
165
165
|
//# sourceMappingURL=Explosion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Explosion.js","sourceRoot":"","sources":["../../../src/effects/Explosion.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAiB,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EACY,WAAW,EAAa,mBAAmB,EAAE,SAAS,EAAoB,yBAAyB,EAAiB,IAAI,GAC1I,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAExG,6CAA6C;AAC7C,MAAM,QAAQ;IAcZ,IAAW,CAAC,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,IAAW,CAAC,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,IAAW,CAAC,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAE1C,YAAmB,QAAiB,EAAE,QAAkB,EAAE,QAAgB,EAAE,IAAY;QAbxF,sDAAsD;QAC/C,QAAG,GAAG,CAAC,CAAC;QAKf,yCAAyC;QAClC,iBAAY,GAAG,CAAC,CAAC;QAOtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ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AAqB,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAEM,iBAAiB,CAAC,EAAc;QACrC,OAAO,EAAE,KAAK,IAAI,CAAC,WAAW,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,IAAe;QAC/C,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,MAAwB;QACvD,yGAAyG;QACzG,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,GAAG,SAAS,CAAC,UAAU,gCAAgC,CAAC,CAAC;QACjG,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC;YACnD,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE;SAClE,CAAC,CAAC;QACH,IAAI,OAAO;YACT,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,oBAAoB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC1H,CAAC;;AA1Ga,gCAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,AAAzB,CAA0B;AA6G3D;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,IAAI;IAGvC,wEAAwE;IACxD,KAAK,CAAC,GAAG;QACvB,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE;YACJ,MAAM,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC;IACd,CAAC;;AATsB,sBAAM,GAAG,iBAAiB,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 { Id64String } from \"@itwin/core-bentley\";\nimport { Point3d, Range1d, Vector3d } from \"@itwin/core-geometry\";\nimport { RenderTexture, TextureTransparency } from \"@itwin/core-common\";\nimport {\n DecorateContext, GraphicType, HitDetail, imageElementFromUrl, IModelApp, IModelConnection, ParticleCollectionBuilder, ParticleProps, Tool,\n} from \"@itwin/core-frontend\";\nimport { randomFloat, randomFloatInRange, randomIntegerInRange, randomPositionInRange } from \"./Random\";\n\n/** Represents one particle in the system. */\nclass Particle implements ParticleProps {\n /** Current position in the particle system's local coordinate space. */\n public readonly position: Point3d;\n /** Current velocity in meters per second. */\n public readonly velocity: Vector3d;\n /** Current age in seconds, incremented each frame. */\n public age = 0;\n /** Maximum age in seconds. When `this.age` exceeds `this.lifetime`, the particle expires. */\n public readonly lifetime: number;\n /** Particle size in meters. */\n public size: number;\n /** Particle transparency in [0..255]. */\n public transparency = 0;\n\n public get x() { return this.position.x; }\n public get y() { return this.position.y; }\n public get z() { return this.position.z; }\n\n public constructor(position: Point3d, velocity: Vector3d, lifetime: number, size: number) {\n this.position = position;\n this.velocity = velocity;\n this.lifetime = lifetime;\n this.size = size;\n }\n\n public get isExpired() { return this.age >= this.lifetime; }\n}\n\n/** Emits particles in a sphere with its center at the origin.\n * Each particle is emitted from the center of the sphere with random velocity toward the surface of the sphere.\n */\nclass ParticleEmitter {\n /** Range from which each particle's initial speed in meters per second will be selected. */\n public readonly speedRange = Range1d.createXX(1, 2);\n /** Range from which each particle's lifetime in seconds will be selected. */\n public readonly lifetimeRange = Range1d.createXX(5, 10);\n /** Range from which each particle's size in meters will be selected. */\n public readonly sizeRange = Range1d.createXX(0.2, 1.0);\n /** Range from which the number of particles emitted will be selected. */\n public numParticlesRange = Range1d.createXX(1600, 2200);\n\n /** Emit an explosion of particles from the center of the sphere. */\n public emit(): Particle[] {\n const particles = [];\n const numParticles = randomIntegerInRange(this.numParticlesRange);\n for (let i = 0; i < numParticles; i++) {\n const velocity = new Vector3d(randomFloat(-1.0, 1.0), randomFloat(-1.0, 1.0), randomFloat(-1.0, 1.0));\n velocity.normalizeInPlace();\n velocity.scaleInPlace(randomFloatInRange(this.speedRange));\n\n const lifetime = randomFloatInRange(this.lifetimeRange);\n const size = randomFloatInRange(this.sizeRange);\n particles.push(new Particle(new Point3d(0, 0, 0), velocity, lifetime, size));\n }\n\n return particles;\n }\n}\n\nclass ParticleSystem {\n private readonly _origin: Point3d;\n private readonly _pickableId: Id64String;\n private readonly _emitter = new ParticleEmitter();\n private _numEmissions: number;\n private readonly _texture: RenderTexture;\n private _lastUpdateTime: number;\n private _particles: Particle[] = [];\n private readonly _scratchVector3d = new Vector3d();\n private _dispose?: VoidFunction;\n /** Acceleration in Z applied to particles, in meters per second squared. */\n public gravity = -3;\n\n public static numEmissionsRange = Range1d.createXX(1, 5);\n\n public constructor(texture: RenderTexture, iModel: IModelConnection, numEmissions: number) {\n this._texture = texture;\n this._pickableId = iModel.transientIds.getNext();\n this._numEmissions = numEmissions;\n this._lastUpdateTime = Date.now();\n\n this._origin = randomPositionInRange(iModel.projectExtents);\n\n this._dispose = iModel.onClose.addListener(() => this.dispose());\n }\n\n public dispose(): void {\n if (this._dispose) {\n this._dispose();\n this._dispose = undefined;\n }\n\n IModelApp.viewManager.dropDecorator(this);\n this._texture.dispose();\n }\n\n public update(): void {\n const now = Date.now();\n let deltaMillis = now - this._lastUpdateTime;\n deltaMillis = Math.min(100, deltaMillis);\n this._lastUpdateTime = now;\n\n let numParticles = this._particles.length;\n if (numParticles === 0) {\n this._numEmissions--;\n if (this._numEmissions < 0)\n this.dispose();\n else\n this._particles = this._emitter.emit();\n\n return;\n }\n\n const elapsedSeconds = deltaMillis / 1000;\n for (let i = 0; i < numParticles; i++) {\n const particle = this._particles[i];\n this.updateParticle(particle, elapsedSeconds);\n if (particle.isExpired) {\n this._particles[i] = this._particles[numParticles - 1];\n --i;\n --numParticles;\n }\n }\n\n this._particles.length = numParticles;\n }\n\n private updateParticle(particle: Particle, elapsedSeconds: number): void {\n const velocity = particle.velocity.clone(this._scratchVector3d);\n velocity.scale(elapsedSeconds, velocity);\n velocity.z += elapsedSeconds * this.gravity;\n particle.position.addInPlace(velocity);\n particle.transparency = 255 * (particle.age / particle.lifetime);\n\n particle.age += elapsedSeconds;\n }\n\n public decorate(context: DecorateContext): void {\n if (!context.viewport.view.isSpatialView())\n return;\n\n this.update();\n\n const builder = ParticleCollectionBuilder.create({\n viewport: context.viewport,\n texture: this._texture,\n size: (this._emitter.sizeRange.high - this._emitter.sizeRange.low) / 2,\n transparency: 0,\n origin: this._origin,\n pickableId: this._pickableId,\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.WorldDecoration, graphic);\n context.viewport.onRender.addOnce((vp) => vp.invalidateDecorations());\n }\n }\n\n public testDecorationHit(id: Id64String): boolean {\n return id === this._pickableId;\n }\n\n public async getDecorationToolTip(_hit: HitDetail): Promise<HTMLElement | string> {\n return \"Explosion effect\";\n }\n\n public static async addDecorator(iModel: IModelConnection): Promise<void> {\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_explosion.png`);\n const texture = IModelApp.renderSystem.createTexture({\n ownership: \"external\",\n image: { source: image, transparency: TextureTransparency.Mixed },\n });\n if (texture)\n IModelApp.viewManager.addDecorator(new ParticleSystem(texture, iModel, randomIntegerInRange(this.numEmissionsRange)));\n }\n}\n\n/** This tool applies an explosion particle effect used for testing [ParticleCollectionBuilder]($frontend).\n * @beta\n */\nexport class ExplosionEffect extends Tool {\n public static override toolId = \"ExplosionEffect\";\n\n /** This method runs the tool, applying an explosion particle effect. */\n public override async run(): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp)\n await ParticleSystem.addDecorator(vp.iModel);\n\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":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AC;IAEM,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,MAAwB;QACvD,yGAAyG;QACzG,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,GAAG,SAAS,CAAC,UAAU,gCAAgC,CAAC,CAAC;QACjG,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,aAAa,CAAC;YACnD,SAAS,EAAE,UAAU;YACrB,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,mBAAmB,CAAC,KAAK,EAAE;SAClE,CAAC,CAAC;QACH,IAAI,OAAO;YACT,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,oBAAoB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC1H,CAAC;;AAGH;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,IAAI;aAChB,WAAM,GAAG,iBAAiB,CAAC;IAElD,wEAAwE;IACxD,KAAK,CAAC,GAAG;QACvB,MAAM,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,YAAY,CAAC;QAC9C,IAAI,EAAE;YACJ,MAAM,cAAc,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QAE/C,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 { Id64String } from \"@itwin/core-bentley\";\nimport { Point3d, Range1d, Vector3d } from \"@itwin/core-geometry\";\nimport { RenderTexture, TextureTransparency } from \"@itwin/core-common\";\nimport {\n DecorateContext, GraphicType, HitDetail, imageElementFromUrl, IModelApp, IModelConnection, ParticleCollectionBuilder, ParticleProps, Tool,\n} from \"@itwin/core-frontend\";\nimport { randomFloat, randomFloatInRange, randomIntegerInRange, randomPositionInRange } from \"./Random\";\n\n/** Represents one particle in the system. */\nclass Particle implements ParticleProps {\n /** Current position in the particle system's local coordinate space. */\n public readonly position: Point3d;\n /** Current velocity in meters per second. */\n public readonly velocity: Vector3d;\n /** Current age in seconds, incremented each frame. */\n public age = 0;\n /** Maximum age in seconds. When `this.age` exceeds `this.lifetime`, the particle expires. */\n public readonly lifetime: number;\n /** Particle size in meters. */\n public size: number;\n /** Particle transparency in [0..255]. */\n public transparency = 0;\n\n public get x() { return this.position.x; }\n public get y() { return this.position.y; }\n public get z() { return this.position.z; }\n\n public constructor(position: Point3d, velocity: Vector3d, lifetime: number, size: number) {\n this.position = position;\n this.velocity = velocity;\n this.lifetime = lifetime;\n this.size = size;\n }\n\n public get isExpired() { return this.age >= this.lifetime; }\n}\n\n/** Emits particles in a sphere with its center at the origin.\n * Each particle is emitted from the center of the sphere with random velocity toward the surface of the sphere.\n */\nclass ParticleEmitter {\n /** Range from which each particle's initial speed in meters per second will be selected. */\n public readonly speedRange = Range1d.createXX(1, 2);\n /** Range from which each particle's lifetime in seconds will be selected. */\n public readonly lifetimeRange = Range1d.createXX(5, 10);\n /** Range from which each particle's size in meters will be selected. */\n public readonly sizeRange = Range1d.createXX(0.2, 1.0);\n /** Range from which the number of particles emitted will be selected. */\n public numParticlesRange = Range1d.createXX(1600, 2200);\n\n /** Emit an explosion of particles from the center of the sphere. */\n public emit(): Particle[] {\n const particles = [];\n const numParticles = randomIntegerInRange(this.numParticlesRange);\n for (let i = 0; i < numParticles; i++) {\n const velocity = new Vector3d(randomFloat(-1.0, 1.0), randomFloat(-1.0, 1.0), randomFloat(-1.0, 1.0));\n velocity.normalizeInPlace();\n velocity.scaleInPlace(randomFloatInRange(this.speedRange));\n\n const lifetime = randomFloatInRange(this.lifetimeRange);\n const size = randomFloatInRange(this.sizeRange);\n particles.push(new Particle(new Point3d(0, 0, 0), velocity, lifetime, size));\n }\n\n return particles;\n }\n}\n\nclass ParticleSystem {\n private readonly _origin: Point3d;\n private readonly _pickableId: Id64String;\n private readonly _emitter = new ParticleEmitter();\n private _numEmissions: number;\n private readonly _texture: RenderTexture;\n private _lastUpdateTime: number;\n private _particles: Particle[] = [];\n private readonly _scratchVector3d = new Vector3d();\n private _dispose?: VoidFunction;\n /** Acceleration in Z applied to particles, in meters per second squared. */\n public gravity = -3;\n\n public static numEmissionsRange = Range1d.createXX(1, 5);\n\n public constructor(texture: RenderTexture, iModel: IModelConnection, numEmissions: number) {\n this._texture = texture;\n this._pickableId = iModel.transientIds.getNext();\n this._numEmissions = numEmissions;\n this._lastUpdateTime = Date.now();\n\n this._origin = randomPositionInRange(iModel.projectExtents);\n\n this._dispose = iModel.onClose.addListener(() => this.dispose());\n }\n\n public dispose(): void {\n if (this._dispose) {\n this._dispose();\n this._dispose = undefined;\n }\n\n IModelApp.viewManager.dropDecorator(this);\n this._texture.dispose();\n }\n\n public update(): void {\n const now = Date.now();\n let deltaMillis = now - this._lastUpdateTime;\n deltaMillis = Math.min(100, deltaMillis);\n this._lastUpdateTime = now;\n\n let numParticles = this._particles.length;\n if (numParticles === 0) {\n this._numEmissions--;\n if (this._numEmissions < 0)\n this.dispose();\n else\n this._particles = this._emitter.emit();\n\n return;\n }\n\n const elapsedSeconds = deltaMillis / 1000;\n for (let i = 0; i < numParticles; i++) {\n const particle = this._particles[i];\n this.updateParticle(particle, elapsedSeconds);\n if (particle.isExpired) {\n this._particles[i] = this._particles[numParticles - 1];\n --i;\n --numParticles;\n }\n }\n\n this._particles.length = numParticles;\n }\n\n private updateParticle(particle: Particle, elapsedSeconds: number): void {\n const velocity = particle.velocity.clone(this._scratchVector3d);\n velocity.scale(elapsedSeconds, velocity);\n velocity.z += elapsedSeconds * this.gravity;\n particle.position.addInPlace(velocity);\n particle.transparency = 255 * (particle.age / particle.lifetime);\n\n particle.age += elapsedSeconds;\n }\n\n public decorate(context: DecorateContext): void {\n if (!context.viewport.view.isSpatialView())\n return;\n\n this.update();\n\n const builder = ParticleCollectionBuilder.create({\n viewport: context.viewport,\n texture: this._texture,\n size: (this._emitter.sizeRange.high - this._emitter.sizeRange.low) / 2,\n transparency: 0,\n origin: this._origin,\n pickableId: this._pickableId,\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.WorldDecoration, graphic);\n context.viewport.onRender.addOnce((vp) => vp.invalidateDecorations());\n }\n }\n\n public testDecorationHit(id: Id64String): boolean {\n return id === this._pickableId;\n }\n\n public async getDecorationToolTip(_hit: HitDetail): Promise<HTMLElement | string> {\n return \"Explosion effect\";\n }\n\n public static async addDecorator(iModel: IModelConnection): Promise<void> {\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_explosion.png`);\n const texture = IModelApp.renderSystem.createTexture({\n ownership: \"external\",\n image: { source: image, transparency: TextureTransparency.Mixed },\n });\n if (texture)\n IModelApp.viewManager.addDecorator(new ParticleSystem(texture, iModel, randomIntegerInRange(this.numEmissionsRange)));\n }\n}\n\n/** This tool applies an explosion particle effect used for testing [ParticleCollectionBuilder]($frontend).\n * @beta\n */\nexport class ExplosionEffect extends Tool {\n public static override toolId = \"ExplosionEffect\";\n\n /** This method runs the tool, applying an explosion particle effect. */\n public override async run(): Promise<boolean> {\n const vp = IModelApp.viewManager.selectedView;\n if (vp)\n await ParticleSystem.addDecorator(vp.iModel);\n\n return true;\n }\n}\n"]}
|
|
@@ -16,6 +16,7 @@ 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() {
|
|
@@ -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,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AAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACxE,CAAC,CAAC;QACH,OAAO,CAAC,UAAU,CAAC;YACjB,IAAI,EAAE,aAAa;YACnB,IAAI,EAAE,WAAW,CAAC,IAAI;YACtB,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACrE,CAAC,CAAC;IACL,CAAC;;AAGH;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,IAAI;aAChB,WAAM,GAAG,iBAAiB,CAAC;IAC3C,MAAM,KAAc,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3C,MAAM,KAAc,OAAO,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,6 +16,7 @@ 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() {
|
|
@@ -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,MAAM,OAAO,oBAAqB,SAAQ,aAAa;aAC9B,WAAM,GA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AK,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"]}
|
|
@@ -12,6 +12,7 @@ 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() {
|
|
@@ -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":"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;aAC1B,WAAM,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,WAAW,CAAC,IAAI,CAAC,CAAC;QACnD,OAAO,CAAC,UAAU,CAAC;YACjB,IAAI,EAAE,kBAAkB;YACxB,IAAI,EAAE,WAAW,CAAC,KAAK;YACvB,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC;SACrE,CAAC,CAAC;IACL,CAAC;;AAGH;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,IAAI;aACjB,WAAM,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;aAChE,eAAU,GAAG,GAAG,CAAC;IAEf,KAAK,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"]}
|
package/lib/esm/effects/Snow.js
CHANGED
|
@@ -138,6 +138,7 @@ export class SnowDecorator {
|
|
|
138
138
|
this._particles[i] = this.emit(false);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
+
static { this._decorators = new Map(); }
|
|
141
142
|
/** Toggle this decorator for the specified viewport.
|
|
142
143
|
* @param viewport The viewport to which the effect should be applied or removed.
|
|
143
144
|
* @param enable `true` to enable the effect, `false` to disable it, or `undefined` to toggle the current state.
|
|
@@ -160,12 +161,12 @@ export class SnowDecorator {
|
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
SnowDecorator._decorators = new Map();
|
|
164
164
|
/** Toggles a decorator that simulates snow using particle effects.
|
|
165
165
|
* @see [[SnowDecorator]] for the implementation of the decorator.
|
|
166
166
|
* @beta
|
|
167
167
|
*/
|
|
168
168
|
export class SnowEffect extends Tool {
|
|
169
|
+
static { this.toolId = "SnowEffect"; }
|
|
169
170
|
async run(enable) {
|
|
170
171
|
const vp = IModelApp.viewManager.selectedView;
|
|
171
172
|
if (vp)
|
|
@@ -179,5 +180,4 @@ export class SnowEffect extends Tool {
|
|
|
179
180
|
return true;
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
|
-
SnowEffect.toolId = "SnowEffect";
|
|
183
183
|
//# 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;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAiB,mBAAmB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AAI,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":["/*---------------------------------------------------------------------------------------------\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,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,CAA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W,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 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"]}
|