@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.16.7 → 3.16.9

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.
Files changed (181) hide show
  1. package/dist/RenderingEngine.d.ts +294 -294
  2. package/dist/RenderingEngine.js +987 -977
  3. package/dist/RenderingEngine.js.map +1 -1
  4. package/dist/index.d.ts +16 -16
  5. package/dist/index.js +57 -57
  6. package/dist/injectors/TextureUnifierInjector.d.ts +13 -13
  7. package/dist/injectors/TextureUnifierInjector.js +181 -171
  8. package/dist/injectors/TextureUnifierInjector.js.map +1 -1
  9. package/dist/interfaces/ILoader.d.ts +3 -3
  10. package/dist/interfaces/ILoader.js +2 -2
  11. package/dist/interfaces/IRenderingEngine.d.ts +45 -45
  12. package/dist/interfaces/IRenderingEngine.js +2 -2
  13. package/dist/loaders/EnvironmentMapLoader.d.ts +119 -119
  14. package/dist/loaders/EnvironmentMapLoader.js +512 -502
  15. package/dist/loaders/EnvironmentMapLoader.js.map +1 -1
  16. package/dist/loaders/GeometryLoader.d.ts +39 -39
  17. package/dist/loaders/GeometryLoader.d.ts.map +1 -1
  18. package/dist/loaders/GeometryLoader.js +603 -593
  19. package/dist/loaders/GeometryLoader.js.map +1 -1
  20. package/dist/loaders/HTMLElementAnchorLoader.d.ts +15 -15
  21. package/dist/loaders/HTMLElementAnchorLoader.js +98 -98
  22. package/dist/loaders/HTMLElementAnchorLoader.js.map +1 -1
  23. package/dist/loaders/LightLoader.d.ts +19 -19
  24. package/dist/loaders/LightLoader.js +197 -187
  25. package/dist/loaders/LightLoader.js.map +1 -1
  26. package/dist/loaders/MaterialLoader.d.ts +115 -115
  27. package/dist/loaders/MaterialLoader.d.ts.map +1 -1
  28. package/dist/loaders/MaterialLoader.js +1612 -1602
  29. package/dist/loaders/MaterialLoader.js.map +1 -1
  30. package/dist/managers/ARManager.d.ts +17 -17
  31. package/dist/managers/ARManager.js +128 -128
  32. package/dist/managers/ARManager.js.map +1 -1
  33. package/dist/managers/CameraManager.d.ts +19 -19
  34. package/dist/managers/CameraManager.js +244 -234
  35. package/dist/managers/CameraManager.js.map +1 -1
  36. package/dist/managers/EnvironmentGeometryManager.d.ts +32 -32
  37. package/dist/managers/EnvironmentGeometryManager.js +114 -114
  38. package/dist/managers/EnvironmentGeometryManager.js.map +1 -1
  39. package/dist/managers/FlagManager.d.ts +19 -19
  40. package/dist/managers/FlagManager.js +143 -143
  41. package/dist/managers/FlagManager.js.map +1 -1
  42. package/dist/managers/PostProcessingManager.d.ts +1019 -1019
  43. package/dist/managers/PostProcessingManager.js +1306 -1296
  44. package/dist/managers/PostProcessingManager.js.map +1 -1
  45. package/dist/managers/RenderingManager.d.ts +84 -84
  46. package/dist/managers/RenderingManager.d.ts.map +1 -1
  47. package/dist/managers/RenderingManager.js +679 -669
  48. package/dist/managers/RenderingManager.js.map +1 -1
  49. package/dist/managers/SceneTracingManager.d.ts +28 -28
  50. package/dist/managers/SceneTracingManager.js +160 -150
  51. package/dist/managers/SceneTracingManager.js.map +1 -1
  52. package/dist/managers/SceneTreeManager.d.ts +81 -81
  53. package/dist/managers/SceneTreeManager.d.ts.map +1 -1
  54. package/dist/managers/SceneTreeManager.js +500 -490
  55. package/dist/managers/SceneTreeManager.js.map +1 -1
  56. package/dist/managers/SettingsManager.d.ts +28 -28
  57. package/dist/managers/SettingsManager.js +284 -284
  58. package/dist/managers/SettingsManager.js.map +1 -1
  59. package/dist/managers/environmentGeometry/ContactShadow.d.ts +42 -42
  60. package/dist/managers/environmentGeometry/ContactShadow.js +295 -285
  61. package/dist/managers/environmentGeometry/ContactShadow.js.map +1 -1
  62. package/dist/managers/environmentGeometry/Grid.d.ts +20 -20
  63. package/dist/managers/environmentGeometry/Grid.js +110 -100
  64. package/dist/managers/environmentGeometry/Grid.js.map +1 -1
  65. package/dist/managers/environmentGeometry/GroundPlane.d.ts +21 -21
  66. package/dist/managers/environmentGeometry/GroundPlane.js +105 -95
  67. package/dist/managers/environmentGeometry/GroundPlane.js.map +1 -1
  68. package/dist/managers/environmentGeometry/GroundPlaneShadow.d.ts +21 -21
  69. package/dist/managers/environmentGeometry/GroundPlaneShadow.js +96 -86
  70. package/dist/managers/environmentGeometry/GroundPlaneShadow.js.map +1 -1
  71. package/dist/managers/environmentGeometry/IEnvironmentGeometry.d.ts +8 -8
  72. package/dist/managers/environmentGeometry/IEnvironmentGeometry.js +2 -2
  73. package/dist/managers/postprocessing/GodRaysManager.d.ts +12 -12
  74. package/dist/managers/postprocessing/GodRaysManager.js +73 -63
  75. package/dist/managers/postprocessing/GodRaysManager.js.map +1 -1
  76. package/dist/managers/postprocessing/OutlineManager.d.ts +15 -15
  77. package/dist/managers/postprocessing/OutlineManager.js +86 -76
  78. package/dist/managers/postprocessing/OutlineManager.js.map +1 -1
  79. package/dist/managers/postprocessing/SSAARenderPass.d.ts +53 -53
  80. package/dist/managers/postprocessing/SSAARenderPass.js +281 -281
  81. package/dist/managers/postprocessing/SSAARenderPass.js.map +1 -1
  82. package/dist/managers/postprocessing/SelectiveBloomManager.d.ts +14 -14
  83. package/dist/managers/postprocessing/SelectiveBloomManager.js +76 -66
  84. package/dist/managers/postprocessing/SelectiveBloomManager.js.map +1 -1
  85. package/dist/managers/postprocessing/ao/ao/AOEffect.d.ts +46 -46
  86. package/dist/managers/postprocessing/ao/ao/AOEffect.js +142 -142
  87. package/dist/managers/postprocessing/ao/ao/AOEffect.js.map +1 -1
  88. package/dist/managers/postprocessing/ao/ao/AOPass.d.ts +12 -12
  89. package/dist/managers/postprocessing/ao/ao/AOPass.js +108 -108
  90. package/dist/managers/postprocessing/ao/ao/AOPass.js.map +1 -1
  91. package/dist/managers/postprocessing/ao/ao/shader/ao_compose.d.ts +1 -1
  92. package/dist/managers/postprocessing/ao/ao/shader/ao_compose.js +4 -4
  93. package/dist/managers/postprocessing/ao/ao/shader/ao_utils.d.ts +1 -1
  94. package/dist/managers/postprocessing/ao/ao/shader/ao_utils.js +4 -4
  95. package/dist/managers/postprocessing/ao/hbao/HBAOEffect.d.ts +14 -14
  96. package/dist/managers/postprocessing/ao/hbao/HBAOEffect.js +24 -24
  97. package/dist/managers/postprocessing/ao/hbao/shader/hbao.d.ts +1 -1
  98. package/dist/managers/postprocessing/ao/hbao/shader/hbao.js +4 -4
  99. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.d.ts +33 -33
  100. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js +211 -211
  101. package/dist/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.js.map +1 -1
  102. package/dist/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.d.ts +1 -1
  103. package/dist/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.js +4 -4
  104. package/dist/managers/postprocessing/ao/ssao/SSAOEffect.d.ts +14 -14
  105. package/dist/managers/postprocessing/ao/ssao/SSAOEffect.js +82 -82
  106. package/dist/managers/postprocessing/ao/ssao/SSAOEffect.js.map +1 -1
  107. package/dist/managers/postprocessing/ao/ssao/shader/ssao.d.ts +1 -1
  108. package/dist/managers/postprocessing/ao/ssao/shader/ssao.js +4 -4
  109. package/dist/managers/postprocessing/ao/utils/shader/basic.d.ts +1 -1
  110. package/dist/managers/postprocessing/ao/utils/shader/basic.js +4 -4
  111. package/dist/managers/postprocessing/ao/utils/shader/sampleBlueNoise.d.ts +1 -1
  112. package/dist/managers/postprocessing/ao/utils/shader/sampleBlueNoise.js +4 -4
  113. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.d.ts +165 -165
  114. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.js +299 -299
  115. package/dist/managers/postprocessing/effects/tone-mapping/ToneMappingEffect.js.map +1 -1
  116. package/dist/managers/postprocessing/effects/tone-mapping/tone-mapping.d.ts +1 -1
  117. package/dist/managers/postprocessing/effects/tone-mapping/tone-mapping.js +4 -4
  118. package/dist/managers/postprocessing/utils/CopyMaterial.d.ts +37 -37
  119. package/dist/managers/postprocessing/utils/CopyMaterial.js +69 -69
  120. package/dist/managers/postprocessing/utils/CopyShader.d.ts +13 -13
  121. package/dist/managers/postprocessing/utils/CopyShader.js +12 -12
  122. package/dist/managers/postprocessing/utils/FullScreenQuad.d.ts +9 -9
  123. package/dist/managers/postprocessing/utils/FullScreenQuad.js +28 -28
  124. package/dist/managers/postprocessing/utils/NormalPass.d.ts +87 -87
  125. package/dist/managers/postprocessing/utils/NormalPass.js +156 -156
  126. package/dist/managers/postprocessing/utils/NormalPass.js.map +1 -1
  127. package/dist/managers/postprocessing/utils/RenderPass.d.ts +114 -114
  128. package/dist/managers/postprocessing/utils/RenderPass.js +259 -259
  129. package/dist/managers/postprocessing/utils/RenderPass.js.map +1 -1
  130. package/dist/managers/sceneTree/SDTFUtils.d.ts +6 -6
  131. package/dist/managers/sceneTree/SDTFUtils.d.ts.map +1 -1
  132. package/dist/managers/sceneTree/SDTFUtils.js +50 -50
  133. package/dist/managers/sceneTree/SDTFUtils.js.map +1 -1
  134. package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts +7 -7
  135. package/dist/managers/sceneTree/SceenTreeManagerUtils.d.ts.map +1 -1
  136. package/dist/managers/sceneTree/SceenTreeManagerUtils.js +175 -165
  137. package/dist/managers/sceneTree/SceenTreeManagerUtils.js.map +1 -1
  138. package/dist/managers/sceneTree/ThreeJsDataUtils.d.ts +6 -6
  139. package/dist/managers/sceneTree/ThreeJsDataUtils.d.ts.map +1 -1
  140. package/dist/managers/sceneTree/ThreeJsDataUtils.js +80 -70
  141. package/dist/managers/sceneTree/ThreeJsDataUtils.js.map +1 -1
  142. package/dist/materials/GemMaterial.d.ts +37 -37
  143. package/dist/materials/GemMaterial.js +262 -252
  144. package/dist/materials/GemMaterial.js.map +1 -1
  145. package/dist/materials/MeshUnlitMaterialParameters.d.ts +3 -3
  146. package/dist/materials/MeshUnlitMaterialParameters.js +2 -2
  147. package/dist/materials/MultiPointsMaterial.d.ts +93 -93
  148. package/dist/materials/MultiPointsMaterial.js +577 -567
  149. package/dist/materials/MultiPointsMaterial.js.map +1 -1
  150. package/dist/materials/SpecularGlossinessMaterial.d.ts +13 -13
  151. package/dist/materials/SpecularGlossinessMaterial.js +171 -161
  152. package/dist/materials/SpecularGlossinessMaterial.js.map +1 -1
  153. package/dist/objects/SDColor.d.ts +16 -16
  154. package/dist/objects/SDColor.js +52 -52
  155. package/dist/objects/SDColor.js.map +1 -1
  156. package/dist/objects/SDObject.d.ts +27 -27
  157. package/dist/objects/SDObject.js +112 -102
  158. package/dist/objects/SDObject.js.map +1 -1
  159. package/dist/shaders/PCSS.d.ts +2 -2
  160. package/dist/shaders/PCSS.js +5 -5
  161. package/dist/shaders/gem.d.ts +2 -2
  162. package/dist/shaders/gem.js +5 -5
  163. package/dist/shaders/multi_points.d.ts +2 -2
  164. package/dist/shaders/multi_points.js +5 -5
  165. package/dist/styling/viewport-css.d.ts +1 -1
  166. package/dist/styling/viewport-css.js +4 -4
  167. package/dist/three/CSS2DRenderer.d.ts +31 -31
  168. package/dist/three/CSS2DRenderer.d.ts.map +1 -1
  169. package/dist/three/CSS2DRenderer.js +152 -152
  170. package/dist/three/CSS2DRenderer.js.map +1 -1
  171. package/dist/three/geometries/TextGeometry.d.ts +21 -21
  172. package/dist/three/geometries/TextGeometry.js +45 -45
  173. package/dist/three/geometries/TextGeometry.js.map +1 -1
  174. package/dist/three/loaders/RGBELoader.d.ts +23 -23
  175. package/dist/three/loaders/RGBELoader.js +311 -311
  176. package/dist/three/loaders/RGBELoader.js.map +1 -1
  177. package/dist/types/IThreejsData.d.ts +6 -6
  178. package/dist/types/IThreejsData.js +2 -2
  179. package/dist/types/ThreejsData.d.ts +10 -10
  180. package/dist/types/ThreejsData.js +41 -41
  181. package/package.json +18 -18
@@ -1,1297 +1,1307 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.PostProcessingManager = void 0;
36
- const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
37
- const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
38
- const gl_matrix_1 = require("gl-matrix");
39
- const postprocessing_1 = require("postprocessing");
40
- const THREE = __importStar(require("three"));
41
- const HBAOEffect_1 = require("./postprocessing/ao/hbao/HBAOEffect");
42
- const PoissionDenoisePass_1 = require("./postprocessing/ao/poissionDenoise/PoissionDenoisePass");
43
- const SSAOEffect_1 = require("./postprocessing/ao/ssao/SSAOEffect");
44
- const ToneMappingEffect_1 = require("./postprocessing/effects/tone-mapping/ToneMappingEffect");
45
- const GodRaysManager_1 = require("./postprocessing/GodRaysManager");
46
- const OutlineManager_1 = require("./postprocessing/OutlineManager");
47
- const SelectiveBloomManager_1 = require("./postprocessing/SelectiveBloomManager");
48
- const SSAARenderPass_1 = require("./postprocessing/SSAARenderPass");
49
- class PostProcessingManager {
50
- // #endregion Properties (23)
51
- // #region Constructors (1)
52
- constructor(_renderingEngine) {
53
- this._renderingEngine = _renderingEngine;
54
- // #region Properties (23)
55
- this._converter = viewer_shared_services_1.Converter.instance;
56
- this._eventEngine = viewer_shared_services_1.EventEngine.instance;
57
- this._systemInfo = viewer_shared_services_1.SystemInfo.instance;
58
- this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
59
- this._antiAliasingTechnique = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA;
60
- this._antiAliasingTechniqueMobile = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.FXAA;
61
- this._currentCameraId = "";
62
- this._effectDefinitions = [];
63
- this._effectPasses = [];
64
- this._effects = [];
65
- this._enablePostProcessingOnMobile = true;
66
- this._godRaysManagers = {};
67
- this._initialized = false;
68
- this._manualPostProcessing = false;
69
- this._outlineManagers = {};
70
- this._sceneExtents = 0;
71
- this._selectiveBloomManagers = {};
72
- this._suspendEffectPassUpdate = false;
73
- this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
74
- const viewerEvent = e;
75
- if (viewerEvent.viewportId === this._renderingEngine.id) {
76
- this._sceneExtents = gl_matrix_1.vec3.distance(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max);
77
- this.changeEffectPass();
78
- }
79
- });
80
- }
81
- // #endregion Constructors (1)
82
- // #region Public Getters And Setters (16)
83
- get antiAliasingTechnique() {
84
- return this._antiAliasingTechnique;
85
- }
86
- set antiAliasingTechnique(value) {
87
- this._antiAliasingTechnique = value;
88
- this.changeEffectPass();
89
- }
90
- get antiAliasingTechniqueMobile() {
91
- return this._antiAliasingTechniqueMobile;
92
- }
93
- set antiAliasingTechniqueMobile(value) {
94
- this._antiAliasingTechniqueMobile = value;
95
- // we don't allow SSAA on mobile devices anymore as it is too slow
96
- if (this._antiAliasingTechniqueMobile === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SSAA)
97
- this._antiAliasingTechniqueMobile = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA;
98
- this.changeEffectPass();
99
- }
100
- get effectComposer() {
101
- return this._composer;
102
- }
103
- get effects() {
104
- return this._effects;
105
- }
106
- get enablePostProcessingOnMobile() {
107
- return this._enablePostProcessingOnMobile;
108
- }
109
- set enablePostProcessingOnMobile(value) {
110
- this._enablePostProcessingOnMobile = value;
111
- }
112
- get godRaysManagers() {
113
- return this._godRaysManagers;
114
- }
115
- get initialized() {
116
- return this._initialized;
117
- }
118
- get manualPostProcessing() {
119
- return this._manualPostProcessing;
120
- }
121
- set manualPostProcessing(value) {
122
- this._manualPostProcessing = value;
123
- if (this._composer && this._manualPostProcessing === true)
124
- this._composer.removeAllPasses();
125
- }
126
- get outlineManagers() {
127
- return this._outlineManagers;
128
- }
129
- get selectiveBloomManagers() {
130
- return this._selectiveBloomManagers;
131
- }
132
- get ssaaSampleLevel() {
133
- return this._ssaaRenderPass ? this._ssaaRenderPass.sampleLevel : 2;
134
- }
135
- set ssaaSampleLevel(value) {
136
- if (this._ssaaRenderPass)
137
- this._ssaaRenderPass.sampleLevel = value;
138
- }
139
- // #endregion Public Getters And Setters (16)
140
- // #region Public Methods (13)
141
- addEffect(definition, t) {
142
- const token = t || this._uuidGenerator.create();
143
- this._effectDefinitions.push({ token, definition });
144
- switch (definition.type) {
145
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
146
- if (!this._godRaysManagers[token])
147
- this._godRaysManagers[token] = new GodRaysManager_1.GodRaysManager(this._renderingEngine);
148
- break;
149
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE:
150
- if (!this._outlineManagers[token])
151
- this._outlineManagers[token] = new OutlineManager_1.OutlineManager(this._renderingEngine);
152
- break;
153
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
154
- if (!this._selectiveBloomManagers[token])
155
- this._selectiveBloomManagers[token] =
156
- new SelectiveBloomManager_1.SelectiveBloomManager(this._renderingEngine);
157
- break;
158
- default:
159
- }
160
- this.changeEffectPass();
161
- return token;
162
- }
163
- applySettings(settingsEngine) {
164
- this._suspendEffectPassUpdate = true;
165
- this.antiAliasingTechnique = settingsEngine.settings.postprocessing
166
- .antiAliasingTechnique;
167
- this.antiAliasingTechniqueMobile = settingsEngine.settings
168
- .postprocessing
169
- .antiAliasingTechniqueMobile;
170
- // we don't allow SSAA on mobile devices anymore as it is too slow
171
- if (this._antiAliasingTechniqueMobile === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SSAA)
172
- this._antiAliasingTechniqueMobile = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA;
173
- this.enablePostProcessingOnMobile =
174
- settingsEngine.settings.postprocessing.enablePostProcessingOnMobile;
175
- this.ssaaSampleLevel =
176
- settingsEngine.settings.postprocessing.ssaaSampleLevel;
177
- this._effectDefinitions = [];
178
- const effects = settingsEngine.settings.postprocessing.effects;
179
- for (let i = 0; i < effects.length; i++) {
180
- const token = this._uuidGenerator.create();
181
- this._effectDefinitions.push({
182
- token,
183
- definition: {
184
- type: effects[i].type,
185
- properties: effects[i].properties,
186
- },
187
- });
188
- }
189
- this._suspendEffectPassUpdate = false;
190
- this.changeEffectPass();
191
- }
192
- changeEffectPass() {
193
- var _a;
194
- if (!this._composer)
195
- return;
196
- if (this._suspendEffectPassUpdate === true)
197
- return;
198
- if (this._systemInfo.isMobile === true &&
199
- this._enablePostProcessingOnMobile === false)
200
- return;
201
- if (this._manualPostProcessing)
202
- return;
203
- for (let i = 0; i < this._composer.passes.length; i++)
204
- this._composer.passes[i].dispose();
205
- this._composer.removeAllPasses();
206
- const antiAliasingTechnique = this._systemInfo.isMobile === true
207
- ? this._antiAliasingTechniqueMobile
208
- : this._antiAliasingTechnique;
209
- if (antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SSAA) {
210
- this.addPassToEffectComposer(this._ssaaRenderPass);
211
- }
212
- else {
213
- this.addPassToEffectComposer(this._renderPass);
214
- }
215
- // remove the effects where the tokens are not in the effectDefinitions
216
- this._effects.forEach((e) => {
217
- // Clear selection layer bits from meshes before disposing,
218
- // otherwise stale layer bits remain on meshes and get picked up
219
- // when layers are reused by newly created effects.
220
- if (e.effect instanceof postprocessing_1.OutlineEffect)
221
- e.effect.selection.clear();
222
- e.effect.dispose();
223
- });
224
- this._effects = [];
225
- for (let i = 0; i < this._effectDefinitions.length; i++) {
226
- switch (this._effectDefinitions[i].definition.type) {
227
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM:
228
- {
229
- const definition = this
230
- ._effectDefinitions[i]
231
- .definition;
232
- const properties = definition.properties || {};
233
- this._effects.push({
234
- token: this._effectDefinitions[i].token,
235
- effect: new postprocessing_1.BloomEffect({
236
- blendFunction: properties.blendFunction,
237
- luminanceThreshold: properties.luminanceThreshold,
238
- luminanceSmoothing: properties.luminanceSmoothing,
239
- mipmapBlur: properties.mipmapBlur,
240
- intensity: properties.intensity,
241
- kernelSize: properties.kernelSize,
242
- }),
243
- });
244
- }
245
- break;
246
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
247
- {
248
- const definition = this._effectDefinitions[i]
249
- .definition;
250
- const properties = definition.properties || {};
251
- const offsetArray = properties.offset !== undefined
252
- ? Array.isArray(properties.offset)
253
- ? properties.offset
254
- : [
255
- properties.offset.x,
256
- properties.offset.y,
257
- ]
258
- : undefined;
259
- this._effects.push({
260
- token: this._effectDefinitions[i].token,
261
- effect: new postprocessing_1.ChromaticAberrationEffect({
262
- blendFunction: properties.blendFunction,
263
- offset: offsetArray
264
- ? new THREE.Vector2(...offsetArray)
265
- : undefined,
266
- radialModulation: properties.radialModulation !== undefined
267
- ? properties.radialModulation
268
- : false,
269
- modulationOffset: properties.modulationOffset !== undefined
270
- ? properties.modulationOffset
271
- : 0.15,
272
- }),
273
- });
274
- }
275
- break;
276
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
277
- {
278
- const definition = this
279
- ._effectDefinitions[i]
280
- .definition;
281
- const properties = definition.properties || {};
282
- const depthOfFieldEffect = new postprocessing_1.DepthOfFieldEffect(this._renderingEngine.camera, {
283
- blendFunction: properties.blendFunction,
284
- focusDistance: properties.focusDistance !== undefined
285
- ? properties.focusDistance
286
- : 0,
287
- focusRange: properties.focusRange !== undefined
288
- ? properties.focusRange
289
- : 0.01,
290
- bokehScale: properties.bokehScale !== undefined
291
- ? properties.bokehScale
292
- : 5,
293
- resolutionScale: 1,
294
- });
295
- depthOfFieldEffect.resolution.height = 1080;
296
- depthOfFieldEffect.blurPass.kernelSize =
297
- postprocessing_1.KernelSize.HUGE;
298
- this._effects.push({
299
- token: this._effectDefinitions[i].token,
300
- effect: depthOfFieldEffect,
301
- });
302
- }
303
- break;
304
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
305
- {
306
- const definition = this
307
- ._effectDefinitions[i]
308
- .definition;
309
- const properties = definition.properties || {};
310
- this._effects.push({
311
- token: this._effectDefinitions[i].token,
312
- effect: new postprocessing_1.DotScreenEffect({
313
- blendFunction: properties.blendFunction,
314
- scale: properties.scale,
315
- angle: properties.angle,
316
- }),
317
- });
318
- }
319
- break;
320
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
321
- {
322
- const definition = this
323
- ._effectDefinitions[i]
324
- .definition;
325
- const properties = definition.properties || {};
326
- const godRaysEffect = new postprocessing_1.GodRaysEffect(this._renderingEngine.camera, new THREE.Mesh(), {
327
- blendFunction: properties.blendFunction,
328
- density: properties.density,
329
- decay: properties.decay,
330
- weight: properties.weight,
331
- exposure: properties.exposure,
332
- clampMax: properties.clampMax,
333
- kernelSize: properties.kernelSize,
334
- blur: properties.blur,
335
- });
336
- this._effects.push({
337
- token: this._effectDefinitions[i].token,
338
- effect: godRaysEffect,
339
- });
340
- this._godRaysManagers[this._effectDefinitions[i].token].setEffect(godRaysEffect);
341
- }
342
- break;
343
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID:
344
- {
345
- const definition = this
346
- ._effectDefinitions[i]
347
- .definition;
348
- const properties = definition.properties || {};
349
- this._effects.push({
350
- token: this._effectDefinitions[i].token,
351
- effect: new postprocessing_1.GridEffect({
352
- blendFunction: properties.blendFunction !== undefined
353
- ? properties.blendFunction
354
- : postprocessing_1.BlendFunction.MULTIPLY,
355
- scale: properties.scale,
356
- }),
357
- });
358
- }
359
- break;
360
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO:
361
- {
362
- // we currently do not support devices with WebGL 1: https://shapediver.atlassian.net/browse/SS-7069
363
- if (this._renderingEngine.renderer.capabilities
364
- .isWebGL2 === false)
365
- break;
366
- const definition = this
367
- ._effectDefinitions[i]
368
- .definition;
369
- const properties = definition.properties || {};
370
- // we adjust the scene size slightly to make the factor fit our requirements
371
- // with this adjusted factor, a distance value of 1 fits well as a default
372
- const sceneSizeFactor = this._sceneExtents / 10.0;
373
- const hbaoEffect = new HBAOEffect_1.HBAOEffect(this._composer, this._renderingEngine.camera, this._renderingEngine.scene, {
374
- resolutionScale: properties.resolutionScale !== undefined
375
- ? properties.resolutionScale
376
- : 1,
377
- spp: properties.spp !== undefined
378
- ? properties.spp
379
- : 16,
380
- distance: properties.distance !== undefined
381
- ? properties.distance * sceneSizeFactor
382
- : sceneSizeFactor,
383
- distancePower: properties.distanceIntensity !== undefined
384
- ? properties.distanceIntensity
385
- : 1,
386
- power: properties.intensity !== undefined
387
- ? properties.intensity
388
- : 2.5,
389
- bias: properties.bias !== undefined
390
- ? properties.bias
391
- : 10,
392
- thickness: properties.thickness !== undefined
393
- ? properties.thickness
394
- : 0.5,
395
- color: properties.color !== undefined
396
- ? new THREE.Color(this._converter
397
- .toHexColor(properties.color)
398
- .substring(0, 7))
399
- : new THREE.Color("black"),
400
- iterations: properties.iterations !== undefined
401
- ? properties.iterations
402
- : 1,
403
- radius: properties.radius !== undefined
404
- ? properties.radius
405
- : 12,
406
- rings: properties.rings !== undefined
407
- ? properties.rings
408
- : 11,
409
- lumaPhi: properties.lumaPhi !== undefined
410
- ? properties.lumaPhi
411
- : 10,
412
- depthPhi: properties.depthPhi !== undefined
413
- ? properties.depthPhi
414
- : 2,
415
- normalPhi: properties.normalPhi !== undefined
416
- ? properties.normalPhi
417
- : 3.25,
418
- samples: properties.samples !== undefined
419
- ? properties.samples
420
- : 16,
421
- });
422
- this._effects.push({
423
- token: this._effectDefinitions[i].token,
424
- effect: hbaoEffect,
425
- });
426
- }
427
- break;
428
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
429
- {
430
- const definition = this
431
- ._effectDefinitions[i]
432
- .definition;
433
- const properties = definition.properties || {};
434
- this._effects.push({
435
- token: this._effectDefinitions[i].token,
436
- effect: new postprocessing_1.HueSaturationEffect({
437
- blendFunction: properties.blendFunction,
438
- hue: properties.hue,
439
- saturation: properties.saturation,
440
- }),
441
- });
442
- }
443
- break;
444
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE:
445
- {
446
- const definition = this
447
- ._effectDefinitions[i]
448
- .definition;
449
- const properties = definition.properties || {};
450
- this._effects.push({
451
- token: this._effectDefinitions[i].token,
452
- effect: new postprocessing_1.NoiseEffect({
453
- blendFunction: properties.blendFunction,
454
- premultiply: properties.premultiply,
455
- }),
456
- });
457
- }
458
- break;
459
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE:
460
- {
461
- const definition = this
462
- ._effectDefinitions[i]
463
- .definition;
464
- const properties = definition.properties || {};
465
- const outlineEffect = new postprocessing_1.OutlineEffect(this._renderingEngine.scene, this._renderingEngine.camera, {
466
- blendFunction: properties.blendFunction !== undefined
467
- ? properties.blendFunction
468
- : postprocessing_1.BlendFunction.SCREEN,
469
- edgeStrength: properties.edgeStrength,
470
- pulseSpeed: properties.pulseSpeed,
471
- visibleEdgeColor: (new THREE.Color(this._converter
472
- .toHexColor(properties.visibleEdgeColor)
473
- .substring(0, 7))),
474
- hiddenEdgeColor: (new THREE.Color(this._converter
475
- .toHexColor(properties.hiddenEdgeColor)
476
- .substring(0, 7))),
477
- kernelSize: properties.kernelSize,
478
- blur: properties.blur,
479
- xRay: properties.xRay,
480
- multisampling: properties.multisampling,
481
- });
482
- // if there are multiple outline effects
483
- // we have to get the first unused selection layer
484
- // starting from 10 (1-9 are reserved)
485
- let layer = 10;
486
- while (Object.values(this._effects)
487
- .filter((e) => e.effect instanceof postprocessing_1.OutlineEffect)
488
- .some((o) => o.effect.selection
489
- .layer === layer)) {
490
- layer++;
491
- }
492
- outlineEffect.selection.layer = layer;
493
- this._effects.push({
494
- token: this._effectDefinitions[i].token,
495
- effect: outlineEffect,
496
- });
497
- this._outlineManagers[this._effectDefinitions[i].token].setEffect(outlineEffect);
498
- }
499
- break;
500
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION:
501
- {
502
- const definition = this
503
- ._effectDefinitions[i]
504
- .definition;
505
- const properties = definition.properties || {};
506
- this._effects.push({
507
- token: this._effectDefinitions[i].token,
508
- effect: new postprocessing_1.PixelationEffect(properties.granularity),
509
- });
510
- }
511
- break;
512
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO:
513
- {
514
- // we currently do not support devices with WebGL 1: https://shapediver.atlassian.net/browse/SS-7069
515
- if (this._renderingEngine.renderer.capabilities
516
- .isWebGL2 === false)
517
- break;
518
- const definition = this
519
- ._effectDefinitions[i]
520
- .definition;
521
- const properties = definition.properties || {};
522
- // we adjust the scene size slightly to make the factor fit our requirements
523
- // with this adjusted factor, a distance value of 1 fits well as a default
524
- const sceneSizeFactor = this._sceneExtents / 50.0;
525
- const ssaoEffect = new SSAOEffect_1.SSAOEffect(this._composer, this._renderingEngine.camera, this._renderingEngine.scene, {
526
- resolutionScale: properties.resolutionScale !== undefined
527
- ? properties.resolutionScale
528
- : 1,
529
- spp: properties.spp !== undefined
530
- ? properties.spp
531
- : 16,
532
- distance: properties.distance !== undefined
533
- ? properties.distance * sceneSizeFactor
534
- : sceneSizeFactor,
535
- distancePower: properties.distanceIntensity !== undefined
536
- ? properties.distanceIntensity
537
- : 1,
538
- power: properties.intensity !== undefined
539
- ? properties.intensity
540
- : 2.5,
541
- color: properties.color !== undefined
542
- ? new THREE.Color(this._converter
543
- .toHexColor(properties.color)
544
- .substring(0, 7))
545
- : new THREE.Color("black"),
546
- iterations: properties.iterations !== undefined
547
- ? properties.iterations
548
- : 1,
549
- radius: properties.radius !== undefined
550
- ? properties.radius
551
- : 12,
552
- rings: properties.rings !== undefined
553
- ? properties.rings
554
- : 11,
555
- lumaPhi: properties.lumaPhi !== undefined
556
- ? properties.lumaPhi
557
- : 10,
558
- depthPhi: properties.depthPhi !== undefined
559
- ? properties.depthPhi
560
- : 2,
561
- normalPhi: properties.normalPhi !== undefined
562
- ? properties.normalPhi
563
- : 3.25,
564
- samples: properties.samples !== undefined
565
- ? properties.samples
566
- : 16,
567
- });
568
- this._effects.push({
569
- token: this._effectDefinitions[i].token,
570
- effect: ssaoEffect,
571
- });
572
- }
573
- break;
574
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE:
575
- {
576
- const definition = this
577
- ._effectDefinitions[i]
578
- .definition;
579
- const properties = definition.properties || {};
580
- this._effects.push({
581
- token: this._effectDefinitions[i].token,
582
- effect: new postprocessing_1.ScanlineEffect({
583
- blendFunction: properties.blendFunction,
584
- density: properties.density,
585
- }),
586
- });
587
- }
588
- break;
589
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
590
- {
591
- const definition = this
592
- ._effectDefinitions[i]
593
- .definition;
594
- const properties = definition.properties || {};
595
- const selectiveBloomEffect = new postprocessing_1.SelectiveBloomEffect(this._renderingEngine.scene, this._renderingEngine.camera, {
596
- blendFunction: properties.blendFunction,
597
- mipmapBlur: properties.mipmapBlur,
598
- luminanceThreshold: properties.luminanceThreshold,
599
- luminanceSmoothing: properties.luminanceSmoothing,
600
- intensity: properties.intensity,
601
- kernelSize: properties.kernelSize,
602
- });
603
- selectiveBloomEffect.ignoreBackground =
604
- properties.ignoreBackground !== undefined
605
- ? properties.ignoreBackground
606
- : true;
607
- this._effects.push({
608
- token: this._effectDefinitions[i].token,
609
- effect: selectiveBloomEffect,
610
- });
611
- this._selectiveBloomManagers[this._effectDefinitions[i].token].setEffect(selectiveBloomEffect);
612
- }
613
- break;
614
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA:
615
- {
616
- const definition = this
617
- ._effectDefinitions[i]
618
- .definition;
619
- const properties = definition.properties || {};
620
- this._effects.push({
621
- token: this._effectDefinitions[i].token,
622
- effect: new postprocessing_1.SepiaEffect({
623
- blendFunction: properties.blendFunction,
624
- }),
625
- });
626
- }
627
- break;
628
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
629
- {
630
- const definition = this
631
- ._effectDefinitions[i]
632
- .definition;
633
- const properties = definition.properties || {};
634
- this._effects.push({
635
- token: this._effectDefinitions[i].token,
636
- effect: new postprocessing_1.TiltShiftEffect({
637
- blendFunction: properties.blendFunction,
638
- offset: properties.offset,
639
- rotation: properties.rotation,
640
- focusArea: properties.focusArea,
641
- feather: properties.feather,
642
- kernelSize: properties.kernelSize,
643
- }),
644
- });
645
- }
646
- break;
647
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
648
- {
649
- const definition = this
650
- ._effectDefinitions[i]
651
- .definition;
652
- const properties = definition.properties || {};
653
- this._effects.push({
654
- token: this._effectDefinitions[i].token,
655
- effect: new postprocessing_1.VignetteEffect({
656
- blendFunction: properties.blendFunction,
657
- technique: properties.technique,
658
- offset: properties.offset,
659
- darkness: properties.darkness,
660
- }),
661
- });
662
- }
663
- break;
664
- default:
665
- }
666
- }
667
- // sort effects by order in effectDefinitions
668
- this._effects.sort((a, b) => this._effectDefinitions.indexOf(this._effectDefinitions.find((e) => e.token === a.token)) -
669
- this._effectDefinitions.indexOf(this._effectDefinitions.find((e) => e.token === b.token)));
670
- const effectArray = this._effects.map((v) => v.effect);
671
- if (antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.FXAA) {
672
- effectArray.unshift(this._fxaaEffect);
673
- }
674
- else if (antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA) {
675
- effectArray.unshift(this._smaaEffect);
676
- }
677
- this._effectPasses = [];
678
- /**
679
- * For every 3 effects we add another effects pass.
680
- * We split it like this to avoid issues with maximum number of textures in one pass.
681
- *
682
- * Note that this could be refined in the future to count the number of textures used by the effects
683
- * instead of just counting the number of effects and compare them to the maximum number of textures
684
- * supported by the device, but for now this is a good enough solution.
685
- **/
686
- for (let i = 0; i < this._effects.length; i += 5) {
687
- const effectsForPass = this._effects.slice(i, i + 5);
688
- const effectPass = new postprocessing_1.EffectPass(this._renderingEngine.camera, ...effectsForPass.map((v) => v.effect));
689
- (_a = this._effectPasses) === null || _a === void 0 ? void 0 : _a.push(effectPass);
690
- this.addPassToEffectComposer(effectPass);
691
- }
692
- // for the AO effects we need to add a separate AA pass at the end that anti-aliases the AO effect
693
- if (this._effectDefinitions.find((e) => e.definition.type === viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO ||
694
- e.definition.type === viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO)) {
695
- // respect the AA choice if one of the effects was selected, use SMAA otherwise
696
- this.addPassToEffectComposer(new postprocessing_1.EffectPass(this._renderingEngine.camera, antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.FXAA
697
- ? this._fxaaEffect
698
- : this._smaaEffect));
699
- }
700
- if (this._renderingEngine.toneMapping !== viewer_shared_types_1.TONE_MAPPING.NONE) {
701
- const mode = (() => {
702
- switch (this._renderingEngine.toneMapping) {
703
- case viewer_shared_types_1.TONE_MAPPING.ACES_FILMIC:
704
- return postprocessing_1.ToneMappingMode.ACES_FILMIC;
705
- case viewer_shared_types_1.TONE_MAPPING.CINEON:
706
- return postprocessing_1.ToneMappingMode.OPTIMIZED_CINEON;
707
- case viewer_shared_types_1.TONE_MAPPING.REINHARD:
708
- return postprocessing_1.ToneMappingMode.REINHARD;
709
- default:
710
- return postprocessing_1.ToneMappingMode.LINEAR;
711
- }
712
- })();
713
- this._toneMappingEffect = new ToneMappingEffect_1.ToneMappingEffect({ mode });
714
- const effectPass = new postprocessing_1.EffectPass(this._renderingEngine.camera, this._toneMappingEffect);
715
- this.addPassToEffectComposer(effectPass);
716
- }
717
- // if there is at least one outline effect, with a pulse speed > 0, we need to enable continuous rendering
718
- if (this._effectDefinitions.find((e) => {
719
- var _a;
720
- return e.definition.type === viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE &&
721
- (((_a = e.definition.properties) === null || _a === void 0 ? void 0 : _a.pulseSpeed) || 0) > 0;
722
- })) {
723
- if (this._continuousRenderingToken === undefined)
724
- this._continuousRenderingToken = this._renderingEngine.addFlag(viewer_shared_types_1.FLAG_TYPE.CONTINUOUS_RENDERING);
725
- }
726
- else if (this._continuousRenderingToken !== undefined) {
727
- this._renderingEngine.removeFlag(this._continuousRenderingToken);
728
- this._continuousRenderingToken = undefined;
729
- }
730
- }
731
- getDefaultEffectProperties(type) {
732
- switch (type) {
733
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM:
734
- return {
735
- blendFunction: postprocessing_1.BlendFunction.ADD,
736
- intensity: 1.0,
737
- kernelSize: postprocessing_1.KernelSize.LARGE,
738
- luminanceSmoothing: 0.025,
739
- luminanceThreshold: 0.9,
740
- mipmapBlur: false,
741
- };
742
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
743
- return {
744
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
745
- modulationOffset: 0.15,
746
- offset: { x: 0.001, y: 0.0005 },
747
- radialModulation: false,
748
- };
749
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
750
- return {
751
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
752
- bokehScale: 5.0,
753
- focusDistance: 0.0,
754
- focusRange: 0.01,
755
- };
756
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
757
- return {
758
- angle: 1.57,
759
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
760
- scale: 1.0,
761
- };
762
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
763
- return {
764
- blendFunction: postprocessing_1.BlendFunction.SCREEN,
765
- blur: true,
766
- clampMax: 1.0,
767
- decay: 0.9,
768
- density: 0.96,
769
- exposure: 0.6,
770
- kernelSize: postprocessing_1.KernelSize.SMALL,
771
- weight: 0.4,
772
- };
773
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID:
774
- return {
775
- blendFunction: postprocessing_1.BlendFunction.MULTIPLY,
776
- scale: 1.0,
777
- };
778
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO:
779
- return {
780
- resolutionScale: 1,
781
- spp: 16,
782
- distance: 1,
783
- distanceIntensity: 1,
784
- intensity: 2.5,
785
- color: "#000000",
786
- bias: 10,
787
- thickness: 0.5,
788
- iterations: 1,
789
- radius: 12,
790
- rings: 11,
791
- lumaPhi: 10,
792
- depthPhi: 2,
793
- normalPhi: 3.25,
794
- samples: 16,
795
- };
796
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
797
- return {
798
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
799
- hue: 0.0,
800
- saturation: 0.0,
801
- };
802
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE:
803
- return {
804
- blendFunction: postprocessing_1.BlendFunction.SCREEN,
805
- premultiply: false,
806
- };
807
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE:
808
- return {
809
- blendFunction: postprocessing_1.BlendFunction.SCREEN,
810
- blur: false,
811
- edgeStrength: 1.0,
812
- hiddenEdgeColor: "#22090a",
813
- kernelSize: postprocessing_1.KernelSize.VERY_SMALL,
814
- multisampling: 0,
815
- pulseSpeed: 0.0,
816
- resolution: 480,
817
- visibleEdgeColor: "#ffffff",
818
- xRay: true,
819
- };
820
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION:
821
- return {
822
- granularity: 30.0,
823
- };
824
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO:
825
- return {
826
- resolutionScale: 1,
827
- spp: 16,
828
- distance: 1,
829
- distanceIntensity: 1,
830
- intensity: 2.5,
831
- color: "#000000",
832
- iterations: 1,
833
- radius: 12,
834
- rings: 11,
835
- lumaPhi: 10,
836
- depthPhi: 2,
837
- normalPhi: 3.25,
838
- samples: 16,
839
- };
840
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE:
841
- return {
842
- blendFunction: postprocessing_1.BlendFunction.OVERLAY,
843
- density: 1.25,
844
- };
845
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
846
- return {
847
- blendFunction: postprocessing_1.BlendFunction.ADD,
848
- intensity: 1.0,
849
- kernelSize: postprocessing_1.KernelSize.LARGE,
850
- luminanceSmoothing: 0.025,
851
- luminanceThreshold: 0.9,
852
- mipmapBlur: false,
853
- ignoreBackground: true,
854
- };
855
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA:
856
- return {
857
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
858
- };
859
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
860
- return {
861
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
862
- feather: 0.3,
863
- focusArea: 0.4,
864
- kernelSize: postprocessing_1.KernelSize.MEDIUM,
865
- offset: 0.0,
866
- rotation: 0.0,
867
- };
868
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
869
- return {
870
- blendFunction: postprocessing_1.BlendFunction.NORMAL,
871
- darkness: 0.5,
872
- offset: 0.5,
873
- technique: postprocessing_1.VignetteTechnique.DEFAULT,
874
- };
875
- default:
876
- return {};
877
- }
878
- }
879
- initialize() {
880
- return __awaiter(this, void 0, void 0, function* () {
881
- if (this._initialized)
882
- return;
883
- // wait for the blue noise texture to be loaded before initializing the composer
884
- yield PoissionDenoisePass_1.PoissionDenoisePass.loadBlueNoiseTexture();
885
- yield new Promise((resolve) => setTimeout(resolve, 0));
886
- this._initialized = true;
887
- return;
888
- });
889
- }
890
- getEffect(token) {
891
- return this._effects.find((e) => e.token === token).effect;
892
- }
893
- getEffectTokens() {
894
- return Object.assign({}, ...this._effectDefinitions.map((e) => ({
895
- [e.token]: e.definition.type,
896
- })));
897
- }
898
- getPostProcessingEffectsArray() {
899
- const effects = [];
900
- for (let i = 0; i < this._effectDefinitions.length; i++) {
901
- switch (this._effectDefinitions[i].definition.type) {
902
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM:
903
- {
904
- const definition = this
905
- ._effectDefinitions[i]
906
- .definition;
907
- const properties = definition.properties || {};
908
- effects.push({
909
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM,
910
- token: this._effectDefinitions[i].token,
911
- properties: {
912
- blendFunction: properties.blendFunction,
913
- luminanceThreshold: properties.luminanceThreshold,
914
- luminanceSmoothing: properties.luminanceSmoothing,
915
- mipmapBlur: properties.mipmapBlur,
916
- intensity: properties.intensity,
917
- kernelSize: properties.kernelSize,
918
- },
919
- });
920
- }
921
- break;
922
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
923
- {
924
- const definition = this._effectDefinitions[i]
925
- .definition;
926
- const properties = definition.properties || {};
927
- effects.push({
928
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION,
929
- token: this._effectDefinitions[i].token,
930
- properties: {
931
- blendFunction: properties.blendFunction,
932
- offset: properties.offset
933
- ? Array.isArray(properties.offset)
934
- ? {
935
- x: properties.offset[0],
936
- y: properties.offset[1],
937
- }
938
- : properties.offset
939
- : undefined,
940
- radialModulation: properties.radialModulation,
941
- modulationOffset: properties.modulationOffset,
942
- },
943
- });
944
- }
945
- break;
946
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
947
- {
948
- const definition = this
949
- ._effectDefinitions[i]
950
- .definition;
951
- const properties = definition.properties || {};
952
- effects.push({
953
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD,
954
- token: this._effectDefinitions[i].token,
955
- properties: {
956
- blendFunction: properties.blendFunction,
957
- focusDistance: properties.focusDistance,
958
- focusRange: properties.focusRange,
959
- bokehScale: properties.bokehScale,
960
- },
961
- });
962
- }
963
- break;
964
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
965
- {
966
- const definition = this
967
- ._effectDefinitions[i]
968
- .definition;
969
- const properties = definition.properties || {};
970
- effects.push({
971
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN,
972
- token: this._effectDefinitions[i].token,
973
- properties: {
974
- blendFunction: properties.blendFunction,
975
- scale: properties.scale,
976
- angle: properties.angle,
977
- },
978
- });
979
- }
980
- break;
981
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID:
982
- {
983
- const definition = this
984
- ._effectDefinitions[i]
985
- .definition;
986
- const properties = definition.properties || {};
987
- effects.push({
988
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID,
989
- token: this._effectDefinitions[i].token,
990
- properties: {
991
- blendFunction: properties.blendFunction,
992
- scale: properties.scale,
993
- },
994
- });
995
- }
996
- break;
997
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO:
998
- {
999
- const definition = this
1000
- ._effectDefinitions[i]
1001
- .definition;
1002
- const properties = definition.properties || {};
1003
- effects.push({
1004
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO,
1005
- token: this._effectDefinitions[i].token,
1006
- properties: {
1007
- resolutionScale: properties.resolutionScale,
1008
- spp: properties.spp,
1009
- distance: properties.distance,
1010
- distanceIntensity: properties.distanceIntensity,
1011
- intensity: properties.intensity,
1012
- bias: properties.bias,
1013
- thickness: properties.thickness,
1014
- color: properties.color !== undefined
1015
- ? this._converter.toHexColor(properties.color)
1016
- : undefined,
1017
- iterations: properties.iterations,
1018
- radius: properties.radius,
1019
- rings: properties.rings,
1020
- lumaPhi: properties.lumaPhi,
1021
- depthPhi: properties.depthPhi,
1022
- normalPhi: properties.normalPhi,
1023
- samples: properties.samples,
1024
- },
1025
- });
1026
- }
1027
- break;
1028
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
1029
- {
1030
- const definition = this
1031
- ._effectDefinitions[i]
1032
- .definition;
1033
- const properties = definition.properties || {};
1034
- effects.push({
1035
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION,
1036
- token: this._effectDefinitions[i].token,
1037
- properties: {
1038
- blendFunction: properties.blendFunction,
1039
- hue: properties.hue,
1040
- saturation: properties.saturation,
1041
- },
1042
- });
1043
- }
1044
- break;
1045
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE:
1046
- {
1047
- const definition = this
1048
- ._effectDefinitions[i]
1049
- .definition;
1050
- const properties = definition.properties || {};
1051
- effects.push({
1052
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE,
1053
- token: this._effectDefinitions[i].token,
1054
- properties: {
1055
- blendFunction: properties.blendFunction,
1056
- premultiply: properties.premultiply,
1057
- },
1058
- });
1059
- }
1060
- break;
1061
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION:
1062
- {
1063
- const definition = this
1064
- ._effectDefinitions[i]
1065
- .definition;
1066
- const properties = definition.properties || {};
1067
- effects.push({
1068
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION,
1069
- token: this._effectDefinitions[i].token,
1070
- properties: {
1071
- granularity: properties.granularity,
1072
- },
1073
- });
1074
- }
1075
- break;
1076
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO:
1077
- {
1078
- const definition = this
1079
- ._effectDefinitions[i]
1080
- .definition;
1081
- const properties = definition.properties || {};
1082
- effects.push({
1083
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO,
1084
- token: this._effectDefinitions[i].token,
1085
- properties: {
1086
- resolutionScale: properties.resolutionScale,
1087
- spp: properties.spp,
1088
- distance: properties.distance,
1089
- distanceIntensity: properties.distanceIntensity,
1090
- intensity: properties.intensity,
1091
- color: properties.color !== undefined
1092
- ? this._converter.toHexColor(properties.color)
1093
- : undefined,
1094
- iterations: properties.iterations,
1095
- radius: properties.radius,
1096
- rings: properties.rings,
1097
- lumaPhi: properties.lumaPhi,
1098
- depthPhi: properties.depthPhi,
1099
- normalPhi: properties.normalPhi,
1100
- samples: properties.samples,
1101
- },
1102
- });
1103
- }
1104
- break;
1105
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE:
1106
- {
1107
- const definition = this
1108
- ._effectDefinitions[i]
1109
- .definition;
1110
- const properties = definition.properties || {};
1111
- effects.push({
1112
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE,
1113
- token: this._effectDefinitions[i].token,
1114
- properties: {
1115
- blendFunction: properties.blendFunction,
1116
- density: properties.density,
1117
- },
1118
- });
1119
- }
1120
- break;
1121
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA:
1122
- {
1123
- const definition = this
1124
- ._effectDefinitions[i]
1125
- .definition;
1126
- const properties = definition.properties || {};
1127
- effects.push({
1128
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA,
1129
- token: this._effectDefinitions[i].token,
1130
- properties: {
1131
- blendFunction: properties.blendFunction,
1132
- },
1133
- });
1134
- }
1135
- break;
1136
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
1137
- {
1138
- const definition = this
1139
- ._effectDefinitions[i]
1140
- .definition;
1141
- const properties = definition.properties || {};
1142
- effects.push({
1143
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT,
1144
- token: this._effectDefinitions[i].token,
1145
- properties: {
1146
- blendFunction: properties.blendFunction,
1147
- offset: properties.offset,
1148
- rotation: properties.rotation,
1149
- focusArea: properties.focusArea,
1150
- feather: properties.feather,
1151
- kernelSize: properties.kernelSize,
1152
- },
1153
- });
1154
- }
1155
- break;
1156
- case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
1157
- {
1158
- const definition = this
1159
- ._effectDefinitions[i]
1160
- .definition;
1161
- const properties = definition.properties || {};
1162
- effects.push({
1163
- type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE,
1164
- token: this._effectDefinitions[i].token,
1165
- properties: {
1166
- blendFunction: properties.blendFunction,
1167
- technique: properties.technique,
1168
- offset: properties.offset,
1169
- darkness: properties.darkness,
1170
- },
1171
- });
1172
- }
1173
- break;
1174
- default:
1175
- }
1176
- }
1177
- return effects;
1178
- }
1179
- init() {
1180
- postprocessing_1.OverrideMaterialManager.workaroundEnabled = true;
1181
- const initComposer = () => {
1182
- this._composer = new postprocessing_1.EffectComposer(this._renderingEngine.renderer);
1183
- // EffectComposer disables autoClear, we enable/disable this in the postprocessing render loop
1184
- this._renderingEngine.renderer.autoClear = true;
1185
- // create anti-aliasing effects and passes
1186
- this._fxaaEffect = new postprocessing_1.FXAAEffect();
1187
- this._smaaEffect = new postprocessing_1.SMAAEffect({ preset: postprocessing_1.SMAAPreset.ULTRA });
1188
- this._renderPass = new postprocessing_1.RenderPass(this._renderingEngine.scene, this._renderingEngine.camera);
1189
- this._ssaaRenderPass = new SSAARenderPass_1.SSAARenderPass(this._renderingEngine.scene, this._renderingEngine.camera);
1190
- };
1191
- if (this._sceneExtents === 0) {
1192
- const token = this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => __awaiter(this, void 0, void 0, function* () {
1193
- const viewerEvent = e;
1194
- if (viewerEvent.viewportId === this._renderingEngine.id) {
1195
- if (gl_matrix_1.vec3.distance(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max) > 0) {
1196
- initComposer();
1197
- this.changeEffectPass();
1198
- this._eventEngine.removeListener(token);
1199
- }
1200
- }
1201
- }));
1202
- }
1203
- else {
1204
- initComposer();
1205
- }
1206
- }
1207
- removeEffect(token) {
1208
- const effectToRemove = this._effectDefinitions.find((e) => e.token === token);
1209
- if (effectToRemove)
1210
- this._effectDefinitions.splice(this._effectDefinitions.indexOf(effectToRemove), 1);
1211
- if (this._godRaysManagers[token])
1212
- delete this._godRaysManagers[token];
1213
- if (this._outlineManagers[token]) {
1214
- this._outlineManagers[token].clearSelection();
1215
- delete this._outlineManagers[token];
1216
- }
1217
- if (this._selectiveBloomManagers[token]) {
1218
- this._selectiveBloomManagers[token].clearSelection();
1219
- delete this._selectiveBloomManagers[token];
1220
- }
1221
- this.changeEffectPass();
1222
- return true;
1223
- }
1224
- render(deltaTime, camera) {
1225
- if (!this._composer)
1226
- return;
1227
- const cameraId = `${camera.id}_${camera.type}${camera.type === "PerspectiveCamera" ? "" : "_" + camera.up.toArray().toString()}`;
1228
- if (cameraId !== this._currentCameraId) {
1229
- this._currentCameraId = cameraId;
1230
- this.changeEffectPass();
1231
- }
1232
- const currentToneMapping = this._renderingEngine.renderer.toneMapping;
1233
- const currentClearColor = this._renderingEngine.renderer.getClearColor(new THREE.Color());
1234
- const convertedClearColor = currentClearColor
1235
- .clone()
1236
- .convertSRGBToLinear();
1237
- this._renderingEngine.renderer.toneMapping = THREE.NoToneMapping;
1238
- this._renderingEngine.renderer.setClearColor(convertedClearColor);
1239
- this._renderingEngine.renderer.setClearAlpha(this._renderingEngine.clearAlpha);
1240
- this._renderingEngine.renderer.autoClear = false;
1241
- this._composer.setMainCamera(camera);
1242
- this._composer.render();
1243
- this._renderingEngine.renderer.toneMapping = currentToneMapping;
1244
- this._renderingEngine.renderer.autoClear = true;
1245
- this._renderingEngine.renderer.setClearColor(currentClearColor);
1246
- }
1247
- resize(width, height) {
1248
- var _a;
1249
- if (!this._composer)
1250
- return;
1251
- this.effects.forEach((e) => {
1252
- if (e.effect.setSize)
1253
- e.effect.setSize(width, height);
1254
- });
1255
- this._renderPass.setSize(width, height);
1256
- this._ssaaRenderPass.setSize(width, height);
1257
- (_a = this._effectPasses) === null || _a === void 0 ? void 0 : _a.forEach((pass) => pass.setSize(width, height));
1258
- this._composer.setSize(width, height);
1259
- }
1260
- saveSettings(settingsEngine) {
1261
- settingsEngine.settings.postprocessing.antiAliasingTechnique =
1262
- this.antiAliasingTechnique;
1263
- settingsEngine.settings.postprocessing.antiAliasingTechniqueMobile =
1264
- this.antiAliasingTechniqueMobile;
1265
- settingsEngine.settings.postprocessing.enablePostProcessingOnMobile =
1266
- this.enablePostProcessingOnMobile;
1267
- settingsEngine.settings.postprocessing.ssaaSampleLevel =
1268
- this.ssaaSampleLevel;
1269
- const effects = this.getPostProcessingEffectsArray();
1270
- // delete the tokens as we don't want to save them
1271
- effects.forEach((e) => delete e.token);
1272
- settingsEngine.settings.postprocessing.effects = effects;
1273
- }
1274
- updateEffect(token, definition) {
1275
- const effectDefinition = this._effectDefinitions.find((e) => e.token === token);
1276
- if (!effectDefinition)
1277
- return;
1278
- this.removeEffect(token);
1279
- this.addEffect(definition, token);
1280
- }
1281
- // #endregion Public Methods (13)
1282
- // #region Private Methods (1)
1283
- addPassToEffectComposer(pass) {
1284
- if (this._composer) {
1285
- try {
1286
- this._composer.addPass(pass);
1287
- }
1288
- catch (e) {
1289
- // in this case a WebGL error is thrown, when the WebGL context is lost
1290
- // as we already throw an error in the rendering engine, we can ignore this error here
1291
- // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes
1292
- }
1293
- }
1294
- }
1295
- }
1296
- exports.PostProcessingManager = PostProcessingManager;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.PostProcessingManager = void 0;
46
+ const viewer_shared_services_1 = require("@shapediver/viewer.shared.services");
47
+ const viewer_shared_types_1 = require("@shapediver/viewer.shared.types");
48
+ const gl_matrix_1 = require("gl-matrix");
49
+ const postprocessing_1 = require("postprocessing");
50
+ const THREE = __importStar(require("three"));
51
+ const HBAOEffect_1 = require("./postprocessing/ao/hbao/HBAOEffect");
52
+ const PoissionDenoisePass_1 = require("./postprocessing/ao/poissionDenoise/PoissionDenoisePass");
53
+ const SSAOEffect_1 = require("./postprocessing/ao/ssao/SSAOEffect");
54
+ const ToneMappingEffect_1 = require("./postprocessing/effects/tone-mapping/ToneMappingEffect");
55
+ const GodRaysManager_1 = require("./postprocessing/GodRaysManager");
56
+ const OutlineManager_1 = require("./postprocessing/OutlineManager");
57
+ const SelectiveBloomManager_1 = require("./postprocessing/SelectiveBloomManager");
58
+ const SSAARenderPass_1 = require("./postprocessing/SSAARenderPass");
59
+ class PostProcessingManager {
60
+ // #endregion Properties (23)
61
+ // #region Constructors (1)
62
+ constructor(_renderingEngine) {
63
+ this._renderingEngine = _renderingEngine;
64
+ // #region Properties (23)
65
+ this._converter = viewer_shared_services_1.Converter.instance;
66
+ this._eventEngine = viewer_shared_services_1.EventEngine.instance;
67
+ this._systemInfo = viewer_shared_services_1.SystemInfo.instance;
68
+ this._uuidGenerator = viewer_shared_services_1.UuidGenerator.instance;
69
+ this._antiAliasingTechnique = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA;
70
+ this._antiAliasingTechniqueMobile = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.FXAA;
71
+ this._currentCameraId = "";
72
+ this._effectDefinitions = [];
73
+ this._effectPasses = [];
74
+ this._effects = [];
75
+ this._enablePostProcessingOnMobile = true;
76
+ this._godRaysManagers = {};
77
+ this._initialized = false;
78
+ this._manualPostProcessing = false;
79
+ this._outlineManagers = {};
80
+ this._sceneExtents = 0;
81
+ this._selectiveBloomManagers = {};
82
+ this._suspendEffectPassUpdate = false;
83
+ this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => {
84
+ const viewerEvent = e;
85
+ if (viewerEvent.viewportId === this._renderingEngine.id) {
86
+ this._sceneExtents = gl_matrix_1.vec3.distance(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max);
87
+ this.changeEffectPass();
88
+ }
89
+ });
90
+ }
91
+ // #endregion Constructors (1)
92
+ // #region Public Getters And Setters (16)
93
+ get antiAliasingTechnique() {
94
+ return this._antiAliasingTechnique;
95
+ }
96
+ set antiAliasingTechnique(value) {
97
+ this._antiAliasingTechnique = value;
98
+ this.changeEffectPass();
99
+ }
100
+ get antiAliasingTechniqueMobile() {
101
+ return this._antiAliasingTechniqueMobile;
102
+ }
103
+ set antiAliasingTechniqueMobile(value) {
104
+ this._antiAliasingTechniqueMobile = value;
105
+ // we don't allow SSAA on mobile devices anymore as it is too slow
106
+ if (this._antiAliasingTechniqueMobile === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SSAA)
107
+ this._antiAliasingTechniqueMobile = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA;
108
+ this.changeEffectPass();
109
+ }
110
+ get effectComposer() {
111
+ return this._composer;
112
+ }
113
+ get effects() {
114
+ return this._effects;
115
+ }
116
+ get enablePostProcessingOnMobile() {
117
+ return this._enablePostProcessingOnMobile;
118
+ }
119
+ set enablePostProcessingOnMobile(value) {
120
+ this._enablePostProcessingOnMobile = value;
121
+ }
122
+ get godRaysManagers() {
123
+ return this._godRaysManagers;
124
+ }
125
+ get initialized() {
126
+ return this._initialized;
127
+ }
128
+ get manualPostProcessing() {
129
+ return this._manualPostProcessing;
130
+ }
131
+ set manualPostProcessing(value) {
132
+ this._manualPostProcessing = value;
133
+ if (this._composer && this._manualPostProcessing === true)
134
+ this._composer.removeAllPasses();
135
+ }
136
+ get outlineManagers() {
137
+ return this._outlineManagers;
138
+ }
139
+ get selectiveBloomManagers() {
140
+ return this._selectiveBloomManagers;
141
+ }
142
+ get ssaaSampleLevel() {
143
+ return this._ssaaRenderPass ? this._ssaaRenderPass.sampleLevel : 2;
144
+ }
145
+ set ssaaSampleLevel(value) {
146
+ if (this._ssaaRenderPass)
147
+ this._ssaaRenderPass.sampleLevel = value;
148
+ }
149
+ // #endregion Public Getters And Setters (16)
150
+ // #region Public Methods (13)
151
+ addEffect(definition, t) {
152
+ const token = t || this._uuidGenerator.create();
153
+ this._effectDefinitions.push({ token, definition });
154
+ switch (definition.type) {
155
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
156
+ if (!this._godRaysManagers[token])
157
+ this._godRaysManagers[token] = new GodRaysManager_1.GodRaysManager(this._renderingEngine);
158
+ break;
159
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE:
160
+ if (!this._outlineManagers[token])
161
+ this._outlineManagers[token] = new OutlineManager_1.OutlineManager(this._renderingEngine);
162
+ break;
163
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
164
+ if (!this._selectiveBloomManagers[token])
165
+ this._selectiveBloomManagers[token] =
166
+ new SelectiveBloomManager_1.SelectiveBloomManager(this._renderingEngine);
167
+ break;
168
+ default:
169
+ }
170
+ this.changeEffectPass();
171
+ return token;
172
+ }
173
+ applySettings(settingsEngine) {
174
+ this._suspendEffectPassUpdate = true;
175
+ this.antiAliasingTechnique = settingsEngine.settings.postprocessing
176
+ .antiAliasingTechnique;
177
+ this.antiAliasingTechniqueMobile = settingsEngine.settings
178
+ .postprocessing
179
+ .antiAliasingTechniqueMobile;
180
+ // we don't allow SSAA on mobile devices anymore as it is too slow
181
+ if (this._antiAliasingTechniqueMobile === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SSAA)
182
+ this._antiAliasingTechniqueMobile = viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA;
183
+ this.enablePostProcessingOnMobile =
184
+ settingsEngine.settings.postprocessing.enablePostProcessingOnMobile;
185
+ this.ssaaSampleLevel =
186
+ settingsEngine.settings.postprocessing.ssaaSampleLevel;
187
+ this._effectDefinitions = [];
188
+ const effects = settingsEngine.settings.postprocessing.effects;
189
+ for (let i = 0; i < effects.length; i++) {
190
+ const token = this._uuidGenerator.create();
191
+ this._effectDefinitions.push({
192
+ token,
193
+ definition: {
194
+ type: effects[i].type,
195
+ properties: effects[i].properties,
196
+ },
197
+ });
198
+ }
199
+ this._suspendEffectPassUpdate = false;
200
+ this.changeEffectPass();
201
+ }
202
+ changeEffectPass() {
203
+ var _a;
204
+ if (!this._composer)
205
+ return;
206
+ if (this._suspendEffectPassUpdate === true)
207
+ return;
208
+ if (this._systemInfo.isMobile === true &&
209
+ this._enablePostProcessingOnMobile === false)
210
+ return;
211
+ if (this._manualPostProcessing)
212
+ return;
213
+ for (let i = 0; i < this._composer.passes.length; i++)
214
+ this._composer.passes[i].dispose();
215
+ this._composer.removeAllPasses();
216
+ const antiAliasingTechnique = this._systemInfo.isMobile === true
217
+ ? this._antiAliasingTechniqueMobile
218
+ : this._antiAliasingTechnique;
219
+ if (antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SSAA) {
220
+ this.addPassToEffectComposer(this._ssaaRenderPass);
221
+ }
222
+ else {
223
+ this.addPassToEffectComposer(this._renderPass);
224
+ }
225
+ // remove the effects where the tokens are not in the effectDefinitions
226
+ this._effects.forEach((e) => {
227
+ // Clear selection layer bits from meshes before disposing,
228
+ // otherwise stale layer bits remain on meshes and get picked up
229
+ // when layers are reused by newly created effects.
230
+ if (e.effect instanceof postprocessing_1.OutlineEffect)
231
+ e.effect.selection.clear();
232
+ e.effect.dispose();
233
+ });
234
+ this._effects = [];
235
+ for (let i = 0; i < this._effectDefinitions.length; i++) {
236
+ switch (this._effectDefinitions[i].definition.type) {
237
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM:
238
+ {
239
+ const definition = this
240
+ ._effectDefinitions[i]
241
+ .definition;
242
+ const properties = definition.properties || {};
243
+ this._effects.push({
244
+ token: this._effectDefinitions[i].token,
245
+ effect: new postprocessing_1.BloomEffect({
246
+ blendFunction: properties.blendFunction,
247
+ luminanceThreshold: properties.luminanceThreshold,
248
+ luminanceSmoothing: properties.luminanceSmoothing,
249
+ mipmapBlur: properties.mipmapBlur,
250
+ intensity: properties.intensity,
251
+ kernelSize: properties.kernelSize,
252
+ }),
253
+ });
254
+ }
255
+ break;
256
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
257
+ {
258
+ const definition = this._effectDefinitions[i]
259
+ .definition;
260
+ const properties = definition.properties || {};
261
+ const offsetArray = properties.offset !== undefined
262
+ ? Array.isArray(properties.offset)
263
+ ? properties.offset
264
+ : [
265
+ properties.offset.x,
266
+ properties.offset.y,
267
+ ]
268
+ : undefined;
269
+ this._effects.push({
270
+ token: this._effectDefinitions[i].token,
271
+ effect: new postprocessing_1.ChromaticAberrationEffect({
272
+ blendFunction: properties.blendFunction,
273
+ offset: offsetArray
274
+ ? new THREE.Vector2(...offsetArray)
275
+ : undefined,
276
+ radialModulation: properties.radialModulation !== undefined
277
+ ? properties.radialModulation
278
+ : false,
279
+ modulationOffset: properties.modulationOffset !== undefined
280
+ ? properties.modulationOffset
281
+ : 0.15,
282
+ }),
283
+ });
284
+ }
285
+ break;
286
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
287
+ {
288
+ const definition = this
289
+ ._effectDefinitions[i]
290
+ .definition;
291
+ const properties = definition.properties || {};
292
+ const depthOfFieldEffect = new postprocessing_1.DepthOfFieldEffect(this._renderingEngine.camera, {
293
+ blendFunction: properties.blendFunction,
294
+ focusDistance: properties.focusDistance !== undefined
295
+ ? properties.focusDistance
296
+ : 0,
297
+ focusRange: properties.focusRange !== undefined
298
+ ? properties.focusRange
299
+ : 0.01,
300
+ bokehScale: properties.bokehScale !== undefined
301
+ ? properties.bokehScale
302
+ : 5,
303
+ resolutionScale: 1,
304
+ });
305
+ depthOfFieldEffect.resolution.height = 1080;
306
+ depthOfFieldEffect.blurPass.kernelSize =
307
+ postprocessing_1.KernelSize.HUGE;
308
+ this._effects.push({
309
+ token: this._effectDefinitions[i].token,
310
+ effect: depthOfFieldEffect,
311
+ });
312
+ }
313
+ break;
314
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
315
+ {
316
+ const definition = this
317
+ ._effectDefinitions[i]
318
+ .definition;
319
+ const properties = definition.properties || {};
320
+ this._effects.push({
321
+ token: this._effectDefinitions[i].token,
322
+ effect: new postprocessing_1.DotScreenEffect({
323
+ blendFunction: properties.blendFunction,
324
+ scale: properties.scale,
325
+ angle: properties.angle,
326
+ }),
327
+ });
328
+ }
329
+ break;
330
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
331
+ {
332
+ const definition = this
333
+ ._effectDefinitions[i]
334
+ .definition;
335
+ const properties = definition.properties || {};
336
+ const godRaysEffect = new postprocessing_1.GodRaysEffect(this._renderingEngine.camera, new THREE.Mesh(), {
337
+ blendFunction: properties.blendFunction,
338
+ density: properties.density,
339
+ decay: properties.decay,
340
+ weight: properties.weight,
341
+ exposure: properties.exposure,
342
+ clampMax: properties.clampMax,
343
+ kernelSize: properties.kernelSize,
344
+ blur: properties.blur,
345
+ });
346
+ this._effects.push({
347
+ token: this._effectDefinitions[i].token,
348
+ effect: godRaysEffect,
349
+ });
350
+ this._godRaysManagers[this._effectDefinitions[i].token].setEffect(godRaysEffect);
351
+ }
352
+ break;
353
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID:
354
+ {
355
+ const definition = this
356
+ ._effectDefinitions[i]
357
+ .definition;
358
+ const properties = definition.properties || {};
359
+ this._effects.push({
360
+ token: this._effectDefinitions[i].token,
361
+ effect: new postprocessing_1.GridEffect({
362
+ blendFunction: properties.blendFunction !== undefined
363
+ ? properties.blendFunction
364
+ : postprocessing_1.BlendFunction.MULTIPLY,
365
+ scale: properties.scale,
366
+ }),
367
+ });
368
+ }
369
+ break;
370
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO:
371
+ {
372
+ // we currently do not support devices with WebGL 1: https://shapediver.atlassian.net/browse/SS-7069
373
+ if (this._renderingEngine.renderer.capabilities
374
+ .isWebGL2 === false)
375
+ break;
376
+ const definition = this
377
+ ._effectDefinitions[i]
378
+ .definition;
379
+ const properties = definition.properties || {};
380
+ // we adjust the scene size slightly to make the factor fit our requirements
381
+ // with this adjusted factor, a distance value of 1 fits well as a default
382
+ const sceneSizeFactor = this._sceneExtents / 10.0;
383
+ const hbaoEffect = new HBAOEffect_1.HBAOEffect(this._composer, this._renderingEngine.camera, this._renderingEngine.scene, {
384
+ resolutionScale: properties.resolutionScale !== undefined
385
+ ? properties.resolutionScale
386
+ : 1,
387
+ spp: properties.spp !== undefined
388
+ ? properties.spp
389
+ : 16,
390
+ distance: properties.distance !== undefined
391
+ ? properties.distance * sceneSizeFactor
392
+ : sceneSizeFactor,
393
+ distancePower: properties.distanceIntensity !== undefined
394
+ ? properties.distanceIntensity
395
+ : 1,
396
+ power: properties.intensity !== undefined
397
+ ? properties.intensity
398
+ : 2.5,
399
+ bias: properties.bias !== undefined
400
+ ? properties.bias
401
+ : 10,
402
+ thickness: properties.thickness !== undefined
403
+ ? properties.thickness
404
+ : 0.5,
405
+ color: properties.color !== undefined
406
+ ? new THREE.Color(this._converter
407
+ .toHexColor(properties.color)
408
+ .substring(0, 7))
409
+ : new THREE.Color("black"),
410
+ iterations: properties.iterations !== undefined
411
+ ? properties.iterations
412
+ : 1,
413
+ radius: properties.radius !== undefined
414
+ ? properties.radius
415
+ : 12,
416
+ rings: properties.rings !== undefined
417
+ ? properties.rings
418
+ : 11,
419
+ lumaPhi: properties.lumaPhi !== undefined
420
+ ? properties.lumaPhi
421
+ : 10,
422
+ depthPhi: properties.depthPhi !== undefined
423
+ ? properties.depthPhi
424
+ : 2,
425
+ normalPhi: properties.normalPhi !== undefined
426
+ ? properties.normalPhi
427
+ : 3.25,
428
+ samples: properties.samples !== undefined
429
+ ? properties.samples
430
+ : 16,
431
+ });
432
+ this._effects.push({
433
+ token: this._effectDefinitions[i].token,
434
+ effect: hbaoEffect,
435
+ });
436
+ }
437
+ break;
438
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
439
+ {
440
+ const definition = this
441
+ ._effectDefinitions[i]
442
+ .definition;
443
+ const properties = definition.properties || {};
444
+ this._effects.push({
445
+ token: this._effectDefinitions[i].token,
446
+ effect: new postprocessing_1.HueSaturationEffect({
447
+ blendFunction: properties.blendFunction,
448
+ hue: properties.hue,
449
+ saturation: properties.saturation,
450
+ }),
451
+ });
452
+ }
453
+ break;
454
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE:
455
+ {
456
+ const definition = this
457
+ ._effectDefinitions[i]
458
+ .definition;
459
+ const properties = definition.properties || {};
460
+ this._effects.push({
461
+ token: this._effectDefinitions[i].token,
462
+ effect: new postprocessing_1.NoiseEffect({
463
+ blendFunction: properties.blendFunction,
464
+ premultiply: properties.premultiply,
465
+ }),
466
+ });
467
+ }
468
+ break;
469
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE:
470
+ {
471
+ const definition = this
472
+ ._effectDefinitions[i]
473
+ .definition;
474
+ const properties = definition.properties || {};
475
+ const outlineEffect = new postprocessing_1.OutlineEffect(this._renderingEngine.scene, this._renderingEngine.camera, {
476
+ blendFunction: properties.blendFunction !== undefined
477
+ ? properties.blendFunction
478
+ : postprocessing_1.BlendFunction.SCREEN,
479
+ edgeStrength: properties.edgeStrength,
480
+ pulseSpeed: properties.pulseSpeed,
481
+ visibleEdgeColor: (new THREE.Color(this._converter
482
+ .toHexColor(properties.visibleEdgeColor)
483
+ .substring(0, 7))),
484
+ hiddenEdgeColor: (new THREE.Color(this._converter
485
+ .toHexColor(properties.hiddenEdgeColor)
486
+ .substring(0, 7))),
487
+ kernelSize: properties.kernelSize,
488
+ blur: properties.blur,
489
+ xRay: properties.xRay,
490
+ multisampling: properties.multisampling,
491
+ });
492
+ // if there are multiple outline effects
493
+ // we have to get the first unused selection layer
494
+ // starting from 10 (1-9 are reserved)
495
+ let layer = 10;
496
+ while (Object.values(this._effects)
497
+ .filter((e) => e.effect instanceof postprocessing_1.OutlineEffect)
498
+ .some((o) => o.effect.selection
499
+ .layer === layer)) {
500
+ layer++;
501
+ }
502
+ outlineEffect.selection.layer = layer;
503
+ this._effects.push({
504
+ token: this._effectDefinitions[i].token,
505
+ effect: outlineEffect,
506
+ });
507
+ this._outlineManagers[this._effectDefinitions[i].token].setEffect(outlineEffect);
508
+ }
509
+ break;
510
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION:
511
+ {
512
+ const definition = this
513
+ ._effectDefinitions[i]
514
+ .definition;
515
+ const properties = definition.properties || {};
516
+ this._effects.push({
517
+ token: this._effectDefinitions[i].token,
518
+ effect: new postprocessing_1.PixelationEffect(properties.granularity),
519
+ });
520
+ }
521
+ break;
522
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO:
523
+ {
524
+ // we currently do not support devices with WebGL 1: https://shapediver.atlassian.net/browse/SS-7069
525
+ if (this._renderingEngine.renderer.capabilities
526
+ .isWebGL2 === false)
527
+ break;
528
+ const definition = this
529
+ ._effectDefinitions[i]
530
+ .definition;
531
+ const properties = definition.properties || {};
532
+ // we adjust the scene size slightly to make the factor fit our requirements
533
+ // with this adjusted factor, a distance value of 1 fits well as a default
534
+ const sceneSizeFactor = this._sceneExtents / 50.0;
535
+ const ssaoEffect = new SSAOEffect_1.SSAOEffect(this._composer, this._renderingEngine.camera, this._renderingEngine.scene, {
536
+ resolutionScale: properties.resolutionScale !== undefined
537
+ ? properties.resolutionScale
538
+ : 1,
539
+ spp: properties.spp !== undefined
540
+ ? properties.spp
541
+ : 16,
542
+ distance: properties.distance !== undefined
543
+ ? properties.distance * sceneSizeFactor
544
+ : sceneSizeFactor,
545
+ distancePower: properties.distanceIntensity !== undefined
546
+ ? properties.distanceIntensity
547
+ : 1,
548
+ power: properties.intensity !== undefined
549
+ ? properties.intensity
550
+ : 2.5,
551
+ color: properties.color !== undefined
552
+ ? new THREE.Color(this._converter
553
+ .toHexColor(properties.color)
554
+ .substring(0, 7))
555
+ : new THREE.Color("black"),
556
+ iterations: properties.iterations !== undefined
557
+ ? properties.iterations
558
+ : 1,
559
+ radius: properties.radius !== undefined
560
+ ? properties.radius
561
+ : 12,
562
+ rings: properties.rings !== undefined
563
+ ? properties.rings
564
+ : 11,
565
+ lumaPhi: properties.lumaPhi !== undefined
566
+ ? properties.lumaPhi
567
+ : 10,
568
+ depthPhi: properties.depthPhi !== undefined
569
+ ? properties.depthPhi
570
+ : 2,
571
+ normalPhi: properties.normalPhi !== undefined
572
+ ? properties.normalPhi
573
+ : 3.25,
574
+ samples: properties.samples !== undefined
575
+ ? properties.samples
576
+ : 16,
577
+ });
578
+ this._effects.push({
579
+ token: this._effectDefinitions[i].token,
580
+ effect: ssaoEffect,
581
+ });
582
+ }
583
+ break;
584
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE:
585
+ {
586
+ const definition = this
587
+ ._effectDefinitions[i]
588
+ .definition;
589
+ const properties = definition.properties || {};
590
+ this._effects.push({
591
+ token: this._effectDefinitions[i].token,
592
+ effect: new postprocessing_1.ScanlineEffect({
593
+ blendFunction: properties.blendFunction,
594
+ density: properties.density,
595
+ }),
596
+ });
597
+ }
598
+ break;
599
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
600
+ {
601
+ const definition = this
602
+ ._effectDefinitions[i]
603
+ .definition;
604
+ const properties = definition.properties || {};
605
+ const selectiveBloomEffect = new postprocessing_1.SelectiveBloomEffect(this._renderingEngine.scene, this._renderingEngine.camera, {
606
+ blendFunction: properties.blendFunction,
607
+ mipmapBlur: properties.mipmapBlur,
608
+ luminanceThreshold: properties.luminanceThreshold,
609
+ luminanceSmoothing: properties.luminanceSmoothing,
610
+ intensity: properties.intensity,
611
+ kernelSize: properties.kernelSize,
612
+ });
613
+ selectiveBloomEffect.ignoreBackground =
614
+ properties.ignoreBackground !== undefined
615
+ ? properties.ignoreBackground
616
+ : true;
617
+ this._effects.push({
618
+ token: this._effectDefinitions[i].token,
619
+ effect: selectiveBloomEffect,
620
+ });
621
+ this._selectiveBloomManagers[this._effectDefinitions[i].token].setEffect(selectiveBloomEffect);
622
+ }
623
+ break;
624
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA:
625
+ {
626
+ const definition = this
627
+ ._effectDefinitions[i]
628
+ .definition;
629
+ const properties = definition.properties || {};
630
+ this._effects.push({
631
+ token: this._effectDefinitions[i].token,
632
+ effect: new postprocessing_1.SepiaEffect({
633
+ blendFunction: properties.blendFunction,
634
+ }),
635
+ });
636
+ }
637
+ break;
638
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
639
+ {
640
+ const definition = this
641
+ ._effectDefinitions[i]
642
+ .definition;
643
+ const properties = definition.properties || {};
644
+ this._effects.push({
645
+ token: this._effectDefinitions[i].token,
646
+ effect: new postprocessing_1.TiltShiftEffect({
647
+ blendFunction: properties.blendFunction,
648
+ offset: properties.offset,
649
+ rotation: properties.rotation,
650
+ focusArea: properties.focusArea,
651
+ feather: properties.feather,
652
+ kernelSize: properties.kernelSize,
653
+ }),
654
+ });
655
+ }
656
+ break;
657
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
658
+ {
659
+ const definition = this
660
+ ._effectDefinitions[i]
661
+ .definition;
662
+ const properties = definition.properties || {};
663
+ this._effects.push({
664
+ token: this._effectDefinitions[i].token,
665
+ effect: new postprocessing_1.VignetteEffect({
666
+ blendFunction: properties.blendFunction,
667
+ technique: properties.technique,
668
+ offset: properties.offset,
669
+ darkness: properties.darkness,
670
+ }),
671
+ });
672
+ }
673
+ break;
674
+ default:
675
+ }
676
+ }
677
+ // sort effects by order in effectDefinitions
678
+ this._effects.sort((a, b) => this._effectDefinitions.indexOf(this._effectDefinitions.find((e) => e.token === a.token)) -
679
+ this._effectDefinitions.indexOf(this._effectDefinitions.find((e) => e.token === b.token)));
680
+ const effectArray = this._effects.map((v) => v.effect);
681
+ if (antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.FXAA) {
682
+ effectArray.unshift(this._fxaaEffect);
683
+ }
684
+ else if (antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.SMAA) {
685
+ effectArray.unshift(this._smaaEffect);
686
+ }
687
+ this._effectPasses = [];
688
+ /**
689
+ * For every 3 effects we add another effects pass.
690
+ * We split it like this to avoid issues with maximum number of textures in one pass.
691
+ *
692
+ * Note that this could be refined in the future to count the number of textures used by the effects
693
+ * instead of just counting the number of effects and compare them to the maximum number of textures
694
+ * supported by the device, but for now this is a good enough solution.
695
+ **/
696
+ for (let i = 0; i < this._effects.length; i += 5) {
697
+ const effectsForPass = this._effects.slice(i, i + 5);
698
+ const effectPass = new postprocessing_1.EffectPass(this._renderingEngine.camera, ...effectsForPass.map((v) => v.effect));
699
+ (_a = this._effectPasses) === null || _a === void 0 ? void 0 : _a.push(effectPass);
700
+ this.addPassToEffectComposer(effectPass);
701
+ }
702
+ // for the AO effects we need to add a separate AA pass at the end that anti-aliases the AO effect
703
+ if (this._effectDefinitions.find((e) => e.definition.type === viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO ||
704
+ e.definition.type === viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO)) {
705
+ // respect the AA choice if one of the effects was selected, use SMAA otherwise
706
+ this.addPassToEffectComposer(new postprocessing_1.EffectPass(this._renderingEngine.camera, antiAliasingTechnique === viewer_shared_types_1.ANTI_ALIASING_TECHNIQUE.FXAA
707
+ ? this._fxaaEffect
708
+ : this._smaaEffect));
709
+ }
710
+ if (this._renderingEngine.toneMapping !== viewer_shared_types_1.TONE_MAPPING.NONE) {
711
+ const mode = (() => {
712
+ switch (this._renderingEngine.toneMapping) {
713
+ case viewer_shared_types_1.TONE_MAPPING.ACES_FILMIC:
714
+ return postprocessing_1.ToneMappingMode.ACES_FILMIC;
715
+ case viewer_shared_types_1.TONE_MAPPING.CINEON:
716
+ return postprocessing_1.ToneMappingMode.OPTIMIZED_CINEON;
717
+ case viewer_shared_types_1.TONE_MAPPING.REINHARD:
718
+ return postprocessing_1.ToneMappingMode.REINHARD;
719
+ default:
720
+ return postprocessing_1.ToneMappingMode.LINEAR;
721
+ }
722
+ })();
723
+ this._toneMappingEffect = new ToneMappingEffect_1.ToneMappingEffect({ mode });
724
+ const effectPass = new postprocessing_1.EffectPass(this._renderingEngine.camera, this._toneMappingEffect);
725
+ this.addPassToEffectComposer(effectPass);
726
+ }
727
+ // if there is at least one outline effect, with a pulse speed > 0, we need to enable continuous rendering
728
+ if (this._effectDefinitions.find((e) => {
729
+ var _a;
730
+ return e.definition.type === viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE &&
731
+ (((_a = e.definition.properties) === null || _a === void 0 ? void 0 : _a.pulseSpeed) || 0) > 0;
732
+ })) {
733
+ if (this._continuousRenderingToken === undefined)
734
+ this._continuousRenderingToken = this._renderingEngine.addFlag(viewer_shared_types_1.FLAG_TYPE.CONTINUOUS_RENDERING);
735
+ }
736
+ else if (this._continuousRenderingToken !== undefined) {
737
+ this._renderingEngine.removeFlag(this._continuousRenderingToken);
738
+ this._continuousRenderingToken = undefined;
739
+ }
740
+ }
741
+ getDefaultEffectProperties(type) {
742
+ switch (type) {
743
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM:
744
+ return {
745
+ blendFunction: postprocessing_1.BlendFunction.ADD,
746
+ intensity: 1.0,
747
+ kernelSize: postprocessing_1.KernelSize.LARGE,
748
+ luminanceSmoothing: 0.025,
749
+ luminanceThreshold: 0.9,
750
+ mipmapBlur: false,
751
+ };
752
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
753
+ return {
754
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
755
+ modulationOffset: 0.15,
756
+ offset: { x: 0.001, y: 0.0005 },
757
+ radialModulation: false,
758
+ };
759
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
760
+ return {
761
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
762
+ bokehScale: 5.0,
763
+ focusDistance: 0.0,
764
+ focusRange: 0.01,
765
+ };
766
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
767
+ return {
768
+ angle: 1.57,
769
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
770
+ scale: 1.0,
771
+ };
772
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GOD_RAYS:
773
+ return {
774
+ blendFunction: postprocessing_1.BlendFunction.SCREEN,
775
+ blur: true,
776
+ clampMax: 1.0,
777
+ decay: 0.9,
778
+ density: 0.96,
779
+ exposure: 0.6,
780
+ kernelSize: postprocessing_1.KernelSize.SMALL,
781
+ weight: 0.4,
782
+ };
783
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID:
784
+ return {
785
+ blendFunction: postprocessing_1.BlendFunction.MULTIPLY,
786
+ scale: 1.0,
787
+ };
788
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO:
789
+ return {
790
+ resolutionScale: 1,
791
+ spp: 16,
792
+ distance: 1,
793
+ distanceIntensity: 1,
794
+ intensity: 2.5,
795
+ color: "#000000",
796
+ bias: 10,
797
+ thickness: 0.5,
798
+ iterations: 1,
799
+ radius: 12,
800
+ rings: 11,
801
+ lumaPhi: 10,
802
+ depthPhi: 2,
803
+ normalPhi: 3.25,
804
+ samples: 16,
805
+ };
806
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
807
+ return {
808
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
809
+ hue: 0.0,
810
+ saturation: 0.0,
811
+ };
812
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE:
813
+ return {
814
+ blendFunction: postprocessing_1.BlendFunction.SCREEN,
815
+ premultiply: false,
816
+ };
817
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.OUTLINE:
818
+ return {
819
+ blendFunction: postprocessing_1.BlendFunction.SCREEN,
820
+ blur: false,
821
+ edgeStrength: 1.0,
822
+ hiddenEdgeColor: "#22090a",
823
+ kernelSize: postprocessing_1.KernelSize.VERY_SMALL,
824
+ multisampling: 0,
825
+ pulseSpeed: 0.0,
826
+ resolution: 480,
827
+ visibleEdgeColor: "#ffffff",
828
+ xRay: true,
829
+ };
830
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION:
831
+ return {
832
+ granularity: 30.0,
833
+ };
834
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO:
835
+ return {
836
+ resolutionScale: 1,
837
+ spp: 16,
838
+ distance: 1,
839
+ distanceIntensity: 1,
840
+ intensity: 2.5,
841
+ color: "#000000",
842
+ iterations: 1,
843
+ radius: 12,
844
+ rings: 11,
845
+ lumaPhi: 10,
846
+ depthPhi: 2,
847
+ normalPhi: 3.25,
848
+ samples: 16,
849
+ };
850
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE:
851
+ return {
852
+ blendFunction: postprocessing_1.BlendFunction.OVERLAY,
853
+ density: 1.25,
854
+ };
855
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SELECTIVE_BLOOM:
856
+ return {
857
+ blendFunction: postprocessing_1.BlendFunction.ADD,
858
+ intensity: 1.0,
859
+ kernelSize: postprocessing_1.KernelSize.LARGE,
860
+ luminanceSmoothing: 0.025,
861
+ luminanceThreshold: 0.9,
862
+ mipmapBlur: false,
863
+ ignoreBackground: true,
864
+ };
865
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA:
866
+ return {
867
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
868
+ };
869
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
870
+ return {
871
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
872
+ feather: 0.3,
873
+ focusArea: 0.4,
874
+ kernelSize: postprocessing_1.KernelSize.MEDIUM,
875
+ offset: 0.0,
876
+ rotation: 0.0,
877
+ };
878
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
879
+ return {
880
+ blendFunction: postprocessing_1.BlendFunction.NORMAL,
881
+ darkness: 0.5,
882
+ offset: 0.5,
883
+ technique: postprocessing_1.VignetteTechnique.DEFAULT,
884
+ };
885
+ default:
886
+ return {};
887
+ }
888
+ }
889
+ initialize() {
890
+ return __awaiter(this, void 0, void 0, function* () {
891
+ if (this._initialized)
892
+ return;
893
+ // wait for the blue noise texture to be loaded before initializing the composer
894
+ yield PoissionDenoisePass_1.PoissionDenoisePass.loadBlueNoiseTexture();
895
+ yield new Promise((resolve) => setTimeout(resolve, 0));
896
+ this._initialized = true;
897
+ return;
898
+ });
899
+ }
900
+ getEffect(token) {
901
+ return this._effects.find((e) => e.token === token).effect;
902
+ }
903
+ getEffectTokens() {
904
+ return Object.assign({}, ...this._effectDefinitions.map((e) => ({
905
+ [e.token]: e.definition.type,
906
+ })));
907
+ }
908
+ getPostProcessingEffectsArray() {
909
+ const effects = [];
910
+ for (let i = 0; i < this._effectDefinitions.length; i++) {
911
+ switch (this._effectDefinitions[i].definition.type) {
912
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM:
913
+ {
914
+ const definition = this
915
+ ._effectDefinitions[i]
916
+ .definition;
917
+ const properties = definition.properties || {};
918
+ effects.push({
919
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.BLOOM,
920
+ token: this._effectDefinitions[i].token,
921
+ properties: {
922
+ blendFunction: properties.blendFunction,
923
+ luminanceThreshold: properties.luminanceThreshold,
924
+ luminanceSmoothing: properties.luminanceSmoothing,
925
+ mipmapBlur: properties.mipmapBlur,
926
+ intensity: properties.intensity,
927
+ kernelSize: properties.kernelSize,
928
+ },
929
+ });
930
+ }
931
+ break;
932
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION:
933
+ {
934
+ const definition = this._effectDefinitions[i]
935
+ .definition;
936
+ const properties = definition.properties || {};
937
+ effects.push({
938
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.CHROMATIC_ABERRATION,
939
+ token: this._effectDefinitions[i].token,
940
+ properties: {
941
+ blendFunction: properties.blendFunction,
942
+ offset: properties.offset
943
+ ? Array.isArray(properties.offset)
944
+ ? {
945
+ x: properties.offset[0],
946
+ y: properties.offset[1],
947
+ }
948
+ : properties.offset
949
+ : undefined,
950
+ radialModulation: properties.radialModulation,
951
+ modulationOffset: properties.modulationOffset,
952
+ },
953
+ });
954
+ }
955
+ break;
956
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD:
957
+ {
958
+ const definition = this
959
+ ._effectDefinitions[i]
960
+ .definition;
961
+ const properties = definition.properties || {};
962
+ effects.push({
963
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DEPTH_OF_FIELD,
964
+ token: this._effectDefinitions[i].token,
965
+ properties: {
966
+ blendFunction: properties.blendFunction,
967
+ focusDistance: properties.focusDistance,
968
+ focusRange: properties.focusRange,
969
+ bokehScale: properties.bokehScale,
970
+ },
971
+ });
972
+ }
973
+ break;
974
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN:
975
+ {
976
+ const definition = this
977
+ ._effectDefinitions[i]
978
+ .definition;
979
+ const properties = definition.properties || {};
980
+ effects.push({
981
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.DOT_SCREEN,
982
+ token: this._effectDefinitions[i].token,
983
+ properties: {
984
+ blendFunction: properties.blendFunction,
985
+ scale: properties.scale,
986
+ angle: properties.angle,
987
+ },
988
+ });
989
+ }
990
+ break;
991
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID:
992
+ {
993
+ const definition = this
994
+ ._effectDefinitions[i]
995
+ .definition;
996
+ const properties = definition.properties || {};
997
+ effects.push({
998
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.GRID,
999
+ token: this._effectDefinitions[i].token,
1000
+ properties: {
1001
+ blendFunction: properties.blendFunction,
1002
+ scale: properties.scale,
1003
+ },
1004
+ });
1005
+ }
1006
+ break;
1007
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO:
1008
+ {
1009
+ const definition = this
1010
+ ._effectDefinitions[i]
1011
+ .definition;
1012
+ const properties = definition.properties || {};
1013
+ effects.push({
1014
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HBAO,
1015
+ token: this._effectDefinitions[i].token,
1016
+ properties: {
1017
+ resolutionScale: properties.resolutionScale,
1018
+ spp: properties.spp,
1019
+ distance: properties.distance,
1020
+ distanceIntensity: properties.distanceIntensity,
1021
+ intensity: properties.intensity,
1022
+ bias: properties.bias,
1023
+ thickness: properties.thickness,
1024
+ color: properties.color !== undefined
1025
+ ? this._converter.toHexColor(properties.color)
1026
+ : undefined,
1027
+ iterations: properties.iterations,
1028
+ radius: properties.radius,
1029
+ rings: properties.rings,
1030
+ lumaPhi: properties.lumaPhi,
1031
+ depthPhi: properties.depthPhi,
1032
+ normalPhi: properties.normalPhi,
1033
+ samples: properties.samples,
1034
+ },
1035
+ });
1036
+ }
1037
+ break;
1038
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION:
1039
+ {
1040
+ const definition = this
1041
+ ._effectDefinitions[i]
1042
+ .definition;
1043
+ const properties = definition.properties || {};
1044
+ effects.push({
1045
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.HUE_SATURATION,
1046
+ token: this._effectDefinitions[i].token,
1047
+ properties: {
1048
+ blendFunction: properties.blendFunction,
1049
+ hue: properties.hue,
1050
+ saturation: properties.saturation,
1051
+ },
1052
+ });
1053
+ }
1054
+ break;
1055
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE:
1056
+ {
1057
+ const definition = this
1058
+ ._effectDefinitions[i]
1059
+ .definition;
1060
+ const properties = definition.properties || {};
1061
+ effects.push({
1062
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.NOISE,
1063
+ token: this._effectDefinitions[i].token,
1064
+ properties: {
1065
+ blendFunction: properties.blendFunction,
1066
+ premultiply: properties.premultiply,
1067
+ },
1068
+ });
1069
+ }
1070
+ break;
1071
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION:
1072
+ {
1073
+ const definition = this
1074
+ ._effectDefinitions[i]
1075
+ .definition;
1076
+ const properties = definition.properties || {};
1077
+ effects.push({
1078
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.PIXELATION,
1079
+ token: this._effectDefinitions[i].token,
1080
+ properties: {
1081
+ granularity: properties.granularity,
1082
+ },
1083
+ });
1084
+ }
1085
+ break;
1086
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO:
1087
+ {
1088
+ const definition = this
1089
+ ._effectDefinitions[i]
1090
+ .definition;
1091
+ const properties = definition.properties || {};
1092
+ effects.push({
1093
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SSAO,
1094
+ token: this._effectDefinitions[i].token,
1095
+ properties: {
1096
+ resolutionScale: properties.resolutionScale,
1097
+ spp: properties.spp,
1098
+ distance: properties.distance,
1099
+ distanceIntensity: properties.distanceIntensity,
1100
+ intensity: properties.intensity,
1101
+ color: properties.color !== undefined
1102
+ ? this._converter.toHexColor(properties.color)
1103
+ : undefined,
1104
+ iterations: properties.iterations,
1105
+ radius: properties.radius,
1106
+ rings: properties.rings,
1107
+ lumaPhi: properties.lumaPhi,
1108
+ depthPhi: properties.depthPhi,
1109
+ normalPhi: properties.normalPhi,
1110
+ samples: properties.samples,
1111
+ },
1112
+ });
1113
+ }
1114
+ break;
1115
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE:
1116
+ {
1117
+ const definition = this
1118
+ ._effectDefinitions[i]
1119
+ .definition;
1120
+ const properties = definition.properties || {};
1121
+ effects.push({
1122
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SCANLINE,
1123
+ token: this._effectDefinitions[i].token,
1124
+ properties: {
1125
+ blendFunction: properties.blendFunction,
1126
+ density: properties.density,
1127
+ },
1128
+ });
1129
+ }
1130
+ break;
1131
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA:
1132
+ {
1133
+ const definition = this
1134
+ ._effectDefinitions[i]
1135
+ .definition;
1136
+ const properties = definition.properties || {};
1137
+ effects.push({
1138
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.SEPIA,
1139
+ token: this._effectDefinitions[i].token,
1140
+ properties: {
1141
+ blendFunction: properties.blendFunction,
1142
+ },
1143
+ });
1144
+ }
1145
+ break;
1146
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT:
1147
+ {
1148
+ const definition = this
1149
+ ._effectDefinitions[i]
1150
+ .definition;
1151
+ const properties = definition.properties || {};
1152
+ effects.push({
1153
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.TILT_SHIFT,
1154
+ token: this._effectDefinitions[i].token,
1155
+ properties: {
1156
+ blendFunction: properties.blendFunction,
1157
+ offset: properties.offset,
1158
+ rotation: properties.rotation,
1159
+ focusArea: properties.focusArea,
1160
+ feather: properties.feather,
1161
+ kernelSize: properties.kernelSize,
1162
+ },
1163
+ });
1164
+ }
1165
+ break;
1166
+ case viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE:
1167
+ {
1168
+ const definition = this
1169
+ ._effectDefinitions[i]
1170
+ .definition;
1171
+ const properties = definition.properties || {};
1172
+ effects.push({
1173
+ type: viewer_shared_types_1.POST_PROCESSING_EFFECT_TYPE.VIGNETTE,
1174
+ token: this._effectDefinitions[i].token,
1175
+ properties: {
1176
+ blendFunction: properties.blendFunction,
1177
+ technique: properties.technique,
1178
+ offset: properties.offset,
1179
+ darkness: properties.darkness,
1180
+ },
1181
+ });
1182
+ }
1183
+ break;
1184
+ default:
1185
+ }
1186
+ }
1187
+ return effects;
1188
+ }
1189
+ init() {
1190
+ postprocessing_1.OverrideMaterialManager.workaroundEnabled = true;
1191
+ const initComposer = () => {
1192
+ this._composer = new postprocessing_1.EffectComposer(this._renderingEngine.renderer);
1193
+ // EffectComposer disables autoClear, we enable/disable this in the postprocessing render loop
1194
+ this._renderingEngine.renderer.autoClear = true;
1195
+ // create anti-aliasing effects and passes
1196
+ this._fxaaEffect = new postprocessing_1.FXAAEffect();
1197
+ this._smaaEffect = new postprocessing_1.SMAAEffect({ preset: postprocessing_1.SMAAPreset.ULTRA });
1198
+ this._renderPass = new postprocessing_1.RenderPass(this._renderingEngine.scene, this._renderingEngine.camera);
1199
+ this._ssaaRenderPass = new SSAARenderPass_1.SSAARenderPass(this._renderingEngine.scene, this._renderingEngine.camera);
1200
+ };
1201
+ if (this._sceneExtents === 0) {
1202
+ const token = this._eventEngine.addListener(viewer_shared_services_1.EVENTTYPE.SCENE.SCENE_BOUNDING_BOX_CHANGE, (e) => __awaiter(this, void 0, void 0, function* () {
1203
+ const viewerEvent = e;
1204
+ if (viewerEvent.viewportId === this._renderingEngine.id) {
1205
+ if (gl_matrix_1.vec3.distance(viewerEvent.boundingBox.min, viewerEvent.boundingBox.max) > 0) {
1206
+ initComposer();
1207
+ this.changeEffectPass();
1208
+ this._eventEngine.removeListener(token);
1209
+ }
1210
+ }
1211
+ }));
1212
+ }
1213
+ else {
1214
+ initComposer();
1215
+ }
1216
+ }
1217
+ removeEffect(token) {
1218
+ const effectToRemove = this._effectDefinitions.find((e) => e.token === token);
1219
+ if (effectToRemove)
1220
+ this._effectDefinitions.splice(this._effectDefinitions.indexOf(effectToRemove), 1);
1221
+ if (this._godRaysManagers[token])
1222
+ delete this._godRaysManagers[token];
1223
+ if (this._outlineManagers[token]) {
1224
+ this._outlineManagers[token].clearSelection();
1225
+ delete this._outlineManagers[token];
1226
+ }
1227
+ if (this._selectiveBloomManagers[token]) {
1228
+ this._selectiveBloomManagers[token].clearSelection();
1229
+ delete this._selectiveBloomManagers[token];
1230
+ }
1231
+ this.changeEffectPass();
1232
+ return true;
1233
+ }
1234
+ render(deltaTime, camera) {
1235
+ if (!this._composer)
1236
+ return;
1237
+ const cameraId = `${camera.id}_${camera.type}${camera.type === "PerspectiveCamera" ? "" : "_" + camera.up.toArray().toString()}`;
1238
+ if (cameraId !== this._currentCameraId) {
1239
+ this._currentCameraId = cameraId;
1240
+ this.changeEffectPass();
1241
+ }
1242
+ const currentToneMapping = this._renderingEngine.renderer.toneMapping;
1243
+ const currentClearColor = this._renderingEngine.renderer.getClearColor(new THREE.Color());
1244
+ const convertedClearColor = currentClearColor
1245
+ .clone()
1246
+ .convertSRGBToLinear();
1247
+ this._renderingEngine.renderer.toneMapping = THREE.NoToneMapping;
1248
+ this._renderingEngine.renderer.setClearColor(convertedClearColor);
1249
+ this._renderingEngine.renderer.setClearAlpha(this._renderingEngine.clearAlpha);
1250
+ this._renderingEngine.renderer.autoClear = false;
1251
+ this._composer.setMainCamera(camera);
1252
+ this._composer.render();
1253
+ this._renderingEngine.renderer.toneMapping = currentToneMapping;
1254
+ this._renderingEngine.renderer.autoClear = true;
1255
+ this._renderingEngine.renderer.setClearColor(currentClearColor);
1256
+ }
1257
+ resize(width, height) {
1258
+ var _a;
1259
+ if (!this._composer)
1260
+ return;
1261
+ this.effects.forEach((e) => {
1262
+ if (e.effect.setSize)
1263
+ e.effect.setSize(width, height);
1264
+ });
1265
+ this._renderPass.setSize(width, height);
1266
+ this._ssaaRenderPass.setSize(width, height);
1267
+ (_a = this._effectPasses) === null || _a === void 0 ? void 0 : _a.forEach((pass) => pass.setSize(width, height));
1268
+ this._composer.setSize(width, height);
1269
+ }
1270
+ saveSettings(settingsEngine) {
1271
+ settingsEngine.settings.postprocessing.antiAliasingTechnique =
1272
+ this.antiAliasingTechnique;
1273
+ settingsEngine.settings.postprocessing.antiAliasingTechniqueMobile =
1274
+ this.antiAliasingTechniqueMobile;
1275
+ settingsEngine.settings.postprocessing.enablePostProcessingOnMobile =
1276
+ this.enablePostProcessingOnMobile;
1277
+ settingsEngine.settings.postprocessing.ssaaSampleLevel =
1278
+ this.ssaaSampleLevel;
1279
+ const effects = this.getPostProcessingEffectsArray();
1280
+ // delete the tokens as we don't want to save them
1281
+ effects.forEach((e) => delete e.token);
1282
+ settingsEngine.settings.postprocessing.effects = effects;
1283
+ }
1284
+ updateEffect(token, definition) {
1285
+ const effectDefinition = this._effectDefinitions.find((e) => e.token === token);
1286
+ if (!effectDefinition)
1287
+ return;
1288
+ this.removeEffect(token);
1289
+ this.addEffect(definition, token);
1290
+ }
1291
+ // #endregion Public Methods (13)
1292
+ // #region Private Methods (1)
1293
+ addPassToEffectComposer(pass) {
1294
+ if (this._composer) {
1295
+ try {
1296
+ this._composer.addPass(pass);
1297
+ }
1298
+ catch (e) {
1299
+ // in this case a WebGL error is thrown, when the WebGL context is lost
1300
+ // as we already throw an error in the rendering engine, we can ignore this error here
1301
+ // https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes
1302
+ }
1303
+ }
1304
+ }
1305
+ }
1306
+ exports.PostProcessingManager = PostProcessingManager;
1297
1307
  //# sourceMappingURL=PostProcessingManager.js.map