@shapediver/viewer.rendering-engine.rendering-engine-threejs 3.3.4 → 3.3.6

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 (71) hide show
  1. package/package.json +19 -20
  2. package/src/RenderingEngine.ts +0 -1336
  3. package/src/index.ts +0 -81
  4. package/src/injectors/Tag3dGeometryCreationInjector.ts +0 -154
  5. package/src/injectors/TextureUnifierInjector.ts +0 -214
  6. package/src/interfaces/ILoader.ts +0 -3
  7. package/src/interfaces/IPostProcessingEffectDefinitions.ts +0 -402
  8. package/src/interfaces/IRenderingEngine.ts +0 -48
  9. package/src/loaders/EnvironmentMapLoader.ts +0 -357
  10. package/src/loaders/GeometryLoader.ts +0 -585
  11. package/src/loaders/HTMLElementAnchorLoader.ts +0 -107
  12. package/src/loaders/LightLoader.ts +0 -171
  13. package/src/loaders/MaterialLoader.ts +0 -1413
  14. package/src/managers/CameraManager.ts +0 -178
  15. package/src/managers/EnvironmentGeometryManager.ts +0 -224
  16. package/src/managers/PostProcessingManager.ts +0 -1181
  17. package/src/managers/RenderingManager.ts +0 -657
  18. package/src/managers/SceneTracingManager.ts +0 -127
  19. package/src/managers/SceneTreeManager.ts +0 -576
  20. package/src/managers/postprocessing/GodRaysManager.ts +0 -52
  21. package/src/managers/postprocessing/OutlineManager.ts +0 -58
  22. package/src/managers/postprocessing/SSAARenderPass.ts +0 -339
  23. package/src/managers/postprocessing/SelectiveBloomManager.ts +0 -58
  24. package/src/managers/postprocessing/ao/ao/AOEffect.ts +0 -180
  25. package/src/managers/postprocessing/ao/ao/AOPass.ts +0 -128
  26. package/src/managers/postprocessing/ao/ao/shader/ao_compose.glsl +0 -17
  27. package/src/managers/postprocessing/ao/ao/shader/ao_compose.ts +0 -19
  28. package/src/managers/postprocessing/ao/hbao/HBAOEffect.ts +0 -41
  29. package/src/managers/postprocessing/ao/hbao/shader/hbao.glsl +0 -96
  30. package/src/managers/postprocessing/ao/hbao/shader/hbao.ts +0 -98
  31. package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.glsl +0 -92
  32. package/src/managers/postprocessing/ao/hbao/shader/hbao_utils.ts +0 -95
  33. package/src/managers/postprocessing/ao/poissionDenoise/PoissionDenoisePass.ts +0 -259
  34. package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.glsl +0 -125
  35. package/src/managers/postprocessing/ao/poissionDenoise/shader/poissionDenoise.ts +0 -127
  36. package/src/managers/postprocessing/ao/ssao/SSAOEffect.ts +0 -106
  37. package/src/managers/postprocessing/ao/ssao/shader/ssao.glsl +0 -128
  38. package/src/managers/postprocessing/ao/ssao/shader/ssao.ts +0 -130
  39. package/src/managers/postprocessing/ao/utils/shader/basic.glsl +0 -6
  40. package/src/managers/postprocessing/ao/utils/shader/basic.ts +0 -8
  41. package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.glsl +0 -36
  42. package/src/managers/postprocessing/ao/utils/shader/sampleBlueNoise.ts +0 -38
  43. package/src/managers/postprocessing/utils/CopyMaterial.ts +0 -130
  44. package/src/managers/postprocessing/utils/CopyShader.ts +0 -39
  45. package/src/managers/postprocessing/utils/FullScreenQuad.ts +0 -47
  46. package/src/managers/postprocessing/utils/NormalPass.ts +0 -222
  47. package/src/managers/postprocessing/utils/RenderPass.ts +0 -366
  48. package/src/materials/GemMaterial.ts +0 -268
  49. package/src/materials/MeshUnlitMaterialParameters.ts +0 -4
  50. package/src/materials/MultiPointsMaterial.ts +0 -646
  51. package/src/materials/SpecularGlossinessMaterial.ts +0 -182
  52. package/src/objects/SDBone.ts +0 -51
  53. package/src/objects/SDColor.ts +0 -54
  54. package/src/objects/SDData.ts +0 -44
  55. package/src/objects/SDObject.ts +0 -58
  56. package/src/shaders/PCSS.ts +0 -124
  57. package/src/shaders/gem.ts +0 -579
  58. package/src/shaders/gem_frag.glsl +0 -522
  59. package/src/shaders/gem_vert.glsl +0 -53
  60. package/src/shaders/multi_points.ts +0 -291
  61. package/src/shaders/multi_points_frag.glsl +0 -166
  62. package/src/shaders/multi_points_vert.glsl +0 -120
  63. package/src/styling/viewport-css.ts +0 -113
  64. package/src/styling/viewport.css +0 -111
  65. package/src/three/font.ts +0 -2
  66. package/src/three/geometries/TextGeometry.ts +0 -58
  67. package/src/three/loaders/FontLoader.ts +0 -205
  68. package/src/three/loaders/RGBELoader.ts +0 -496
  69. package/src/types/IThreejsData.ts +0 -16
  70. package/src/types/ThreejsData.ts +0 -43
  71. package/tsconfig.json +0 -20
@@ -1,1336 +0,0 @@
1
- import * as THREE from 'three';
2
- import { adaptShaders, MaterialLoader } from './loaders/MaterialLoader';
3
- import { AnimationEngine } from '@shapediver/viewer.rendering-engine.animation-engine';
4
- import { CameraManager } from './managers/CameraManager';
5
- import { CanvasEngine, ICanvas } from '@shapediver/viewer.rendering-engine.canvas-engine';
6
- import { EnvironmentGeometryManager } from './managers/EnvironmentGeometryManager';
7
- import { EnvironmentMapLoader } from './loaders/EnvironmentMapLoader';
8
- import { GeometryLoader } from './loaders/GeometryLoader';
9
- import { HTMLElementAnchorLoader } from './loaders/HTMLElementAnchorLoader';
10
- import { IntersectionEngine } from '@shapediver/viewer.rendering-engine.intersection-engine';
11
- import { IRenderingEngineThreeJS } from './interfaces/IRenderingEngine';
12
- import { ITree, ITreeNode, Tree } from '@shapediver/viewer.shared.node-tree';
13
- import { LightEngine } from '@shapediver/viewer.rendering-engine.light-engine';
14
- import { LightLoader } from './loaders/LightLoader';
15
- import { PostProcessingManager } from './managers/PostProcessingManager';
16
- import { quat, vec2, vec3 } from 'gl-matrix';
17
- import { RenderingManager } from './managers/RenderingManager';
18
- import { SceneTracingManager } from './managers/SceneTracingManager';
19
- import { SceneTreeManager } from './managers/SceneTreeManager';
20
- import { SDColor } from './objects/SDColor';
21
- import {
22
- CameraEngine,
23
- } from '@shapediver/viewer.rendering-engine.camera-engine';
24
- import {
25
- BUSY_MODE_DISPLAY,
26
- FLAG_TYPE,
27
- SPINNER_POSITIONING,
28
- RENDERER_TYPE,
29
- TEXTURE_ENCODING,
30
- TONE_MAPPING,
31
- VISIBILITY_MODE,
32
- } from '@shapediver/viewer.rendering-engine.rendering-engine';
33
- import {
34
- Converter,
35
- DomEventEngine,
36
- EventEngine,
37
- EVENTTYPE,
38
- EVENTTYPE_VIEWPORT,
39
- Logger,
40
- SESSION_SETTINGS_MODE,
41
- SettingsEngine,
42
- ShapeDiverViewerArError,
43
- StateEngine,
44
- SystemInfo,
45
- UuidGenerator,
46
- } from '@shapediver/viewer.shared.services';
47
- import {
48
- ISDTFOverviewData,
49
- ISDTFAttributeVisualizationData,
50
- ISDTFOverview,
51
- ISDTFItemData,
52
- SDTFOverviewData,
53
- ITaskEvent,
54
- TASK_TYPE,
55
- IAnimationData,
56
- IGeometryData,
57
- Color,
58
- IViewportEvent,
59
- MaterialStandardData,
60
- MaterialPointData,
61
- MaterialBasicLineData,
62
- IViewportSettingsSections,
63
- } from '@shapediver/viewer.shared.types';
64
- import { css } from './styling/viewport-css';
65
-
66
- export class RenderingEngine implements IRenderingEngineThreeJS {
67
- // #region Properties (75)
68
-
69
- readonly #defaultLogo: string = 'https://viewer.shapediver.com/v3/graphics/logo_animated_breath.svg';
70
- readonly #defaultLogoStatic: string = 'https://viewer.shapediver.com/v3/graphics/logo.png';
71
- readonly #defaultSpinner: string = 'https://viewer.shapediver.com/v3/graphics/spinner_ripple.svg';
72
- private readonly _animationEngine: AnimationEngine = AnimationEngine.instance;
73
- // constructor properties
74
- private readonly _branding: {
75
- logo: string | null,
76
- backgroundColor: string,
77
- busyModeSpinner: string,
78
- busyModeDisplay: BUSY_MODE_DISPLAY,
79
- spinnerPositioning: SPINNER_POSITIONING
80
- };
81
- // engines
82
- private readonly _cameraEngine: CameraEngine;
83
- private readonly _cameraManager: CameraManager;
84
- // viewer essentials
85
- private readonly _canvas: ICanvas;
86
- private readonly _canvasEngine: CanvasEngine = CanvasEngine.instance;
87
- private readonly _colorCache: SDColor[] = [];
88
- // utils
89
- private readonly _converter: Converter = Converter.instance;
90
- private readonly _domEventEngine: DomEventEngine;
91
- private readonly _environmentGeometryManager: EnvironmentGeometryManager;
92
- // loaders
93
- private readonly _environmentMapLoader: EnvironmentMapLoader;
94
- private readonly _eventEngine: EventEngine = EventEngine.instance;
95
- private readonly _geometryLoader: GeometryLoader;
96
- private readonly _htmlElementAnchorLoader: HTMLElementAnchorLoader;
97
- private readonly _id: string;
98
- private readonly _intersectionManager: IntersectionEngine = IntersectionEngine.instance;
99
- private readonly _lightEngine: LightEngine;
100
- private readonly _lightLoader: LightLoader;
101
- private readonly _logger: Logger = Logger.instance;
102
- private readonly _materialLoader: MaterialLoader;
103
- private readonly _postProcessingManager: PostProcessingManager;
104
- private readonly _renderingManager: RenderingManager;
105
- private readonly _sceneTracingManager: SceneTracingManager;
106
- private readonly _sceneTreeManager: SceneTreeManager;
107
- private readonly _stateEngine: StateEngine = StateEngine.instance;
108
- private readonly _systemInfo: SystemInfo = SystemInfo.instance;
109
- private readonly _tree: ITree = Tree.instance;
110
- private readonly _uuidGenerator: UuidGenerator = UuidGenerator.instance;
111
- private readonly _visibility: VISIBILITY_MODE;
112
-
113
- #animations: {
114
- [key: string]: IAnimationData
115
- } = {};
116
- #flags: { [key: string]: string[] } = {
117
- [FLAG_TYPE.CAMERA_FREEZE]: [],
118
- [FLAG_TYPE.CONTINUOUS_RENDERING]: [],
119
- [FLAG_TYPE.CONTINUOUS_SHADOW_MAP_UPDATE]: [],
120
- };
121
- // settings
122
- private _arRotation: vec3 = vec3.create();
123
- private _arScale: vec3 = vec3.fromValues(1, 1, 1);
124
- private _arTranslation: vec3 = vec3.create();
125
- private _automaticColorAdjustment: boolean = true;
126
- private _automaticResizing: boolean = true;
127
- private _beautyRenderBlendingDuration: number = 1500;
128
- private _beautyRenderDelay: number = 50;
129
- private _busy: boolean = false;
130
- private _busyModeDisplay: BUSY_MODE_DISPLAY = BUSY_MODE_DISPLAY.SPINNER;
131
- private _clearAlpha: number = 1.0;
132
- private _clearColor: Color = '#ffffff';
133
- // viewer global vars
134
- private _closed: boolean = false;
135
- private _enableAR: boolean = true;
136
- private _environmentMap: string | string[] = 'null';
137
- private _environmentMapAsBackground: boolean = false;
138
- private _environmentMapBlurriness: number = 0;
139
- private _environmentMapForUnlitMaterials: boolean = false;
140
- private _environmentMapIntensity: number = 1;
141
- private _environmentMapResolution: string = '1024';
142
- private _environmentMapRotation: quat = quat.create();
143
- private _gridVisibility: boolean = true;
144
- private _groundPlaneShadowVisibility: boolean = false;
145
- private _groundPlaneVisibility: boolean = true;
146
- private _lights: boolean = true;
147
- private _logoDivElement: HTMLDivElement;
148
- private _maximumRenderingSize: { width: number; height: number } = this._systemInfo.isMobile ? { width: 1280, height: 720 } : { width: 1920, height: 1080 };
149
- private _pause: boolean = false;
150
- private _postRenderingCallback?: ((renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera) => void) | undefined;
151
- private _preRenderingCallback?: ((renderer: THREE.WebGLRenderer) => void) | undefined;
152
- private _renderer: THREE.WebGLRenderer;
153
- private _sessionSettingsId?: string;
154
- private _sessionSettingsMode: SESSION_SETTINGS_MODE;
155
- private _settingsEngine?: SettingsEngine;
156
- private _shadows: boolean = true;
157
- private _show: boolean = false;
158
- private _showStatistics: boolean = false;
159
- private _softShadows: boolean = true;
160
- private _spinnerDivElement: HTMLDivElement;
161
- private _type: RENDERER_TYPE = RENDERER_TYPE.STANDARD;
162
- private _visualizeAttributes: ((overview: ISDTFOverview, itemData?: ISDTFItemData) => ISDTFAttributeVisualizationData) | undefined;
163
-
164
- // #endregion Properties (75)
165
-
166
- // #region Constructors (1)
167
-
168
- constructor(properties?: {
169
- canvas?: HTMLCanvasElement,
170
- id?: string,
171
- branding?: {
172
- logo?: string | null,
173
- backgroundColor?: string,
174
- busyModeSpinner?: string,
175
- busyModeDisplay?: BUSY_MODE_DISPLAY,
176
- spinnerPositioning?: SPINNER_POSITIONING
177
- },
178
- sessionSettingsId?: string,
179
- sessionSettingsMode?: SESSION_SETTINGS_MODE,
180
- visibility?: VISIBILITY_MODE,
181
- }) {
182
- // THREE object has default Y, we change that (although it doesn't work everywhere)
183
- THREE.Object3D.DEFAULT_UP = new THREE.Vector3(0, 0, 1);
184
- THREE.ColorManagement.enabled = false;
185
-
186
- // adapt some of the three.js shaders according to our needs
187
- adaptShaders();
188
-
189
- // add css to the document
190
- const style = document.createElement('style');
191
- style.innerHTML = css;
192
- document.head.appendChild(style);
193
-
194
- const prop = Object.assign({}, properties);
195
- const branding = Object.assign({}, prop.branding);
196
-
197
- // setting some of the provided properties
198
- this._id = prop.id || (UuidGenerator.instance).create();
199
- this._visibility = prop.visibility || VISIBILITY_MODE.SESSION;
200
- this._sessionSettingsMode = prop.sessionSettingsMode || SESSION_SETTINGS_MODE.FIRST;
201
- this._sessionSettingsId = prop.sessionSettingsId;
202
- this._branding = {
203
- logo: branding.logo === undefined ? this.#defaultLogo : branding.logo,
204
- backgroundColor: branding.backgroundColor || '#393a45FF',
205
- busyModeSpinner: branding.busyModeSpinner === undefined ? this.#defaultSpinner : branding.busyModeSpinner,
206
- busyModeDisplay: branding.busyModeDisplay || BUSY_MODE_DISPLAY.SPINNER,
207
- spinnerPositioning: branding.spinnerPositioning || SPINNER_POSITIONING.BOTTOM_RIGHT
208
- };
209
-
210
- // creation of viewer essentials
211
- this._canvas = this._canvasEngine.getCanvas(this._canvasEngine.createCanvasObject(prop.canvas));
212
-
213
- // creation of the engines (all singleton engines were created already)
214
- this._domEventEngine = new DomEventEngine(this._canvas.canvasElement);
215
- this._cameraEngine = new CameraEngine(this);
216
- this._lightEngine = new LightEngine(this);
217
-
218
- // creation of the managers (all singleton engines were created already)
219
- this._cameraManager = new CameraManager(this);
220
- this._environmentGeometryManager = new EnvironmentGeometryManager(this);
221
- this._sceneTracingManager = new SceneTracingManager(this);
222
- this._sceneTreeManager = new SceneTreeManager(this);
223
- this._renderingManager = new RenderingManager(this);
224
- this._postProcessingManager = new PostProcessingManager(this);
225
-
226
- // loaders
227
- this._environmentMapLoader = new EnvironmentMapLoader(this);
228
- this._materialLoader = new MaterialLoader(this);
229
- this._geometryLoader = new GeometryLoader(this);
230
- this._htmlElementAnchorLoader = new HTMLElementAnchorLoader(this);
231
- this._lightLoader = new LightLoader(this);
232
-
233
- // start the creation and initialization process
234
- this._renderer = this.renderingManager.createRenderer(this._canvas.canvasElement);
235
- this._spinnerDivElement = this.renderingManager.addSpinner(this._canvas.canvasElement, this._branding);
236
- this._logoDivElement = this.renderingManager.addLogo(this._canvas.canvasElement, this._branding);
237
-
238
- // creation of the managers (all singleton engines were created already)
239
- this._cameraManager.init();
240
- this._environmentGeometryManager.init();
241
- this._sceneTracingManager.init();
242
- this._sceneTreeManager.init();
243
- this._renderingManager.init();
244
- this._postProcessingManager.init();
245
-
246
- // loaders
247
- this._environmentMapLoader.init();
248
- this._materialLoader.init();
249
- this._geometryLoader.init();
250
- this._htmlElementAnchorLoader.init();
251
- this._lightLoader.init();
252
- }
253
-
254
- // #endregion Constructors (1)
255
-
256
- // #region Public Getters And Setters (133)
257
-
258
- public get arRotation(): vec3 {
259
- return this._arRotation;
260
- }
261
-
262
- public set arRotation(value: vec3) {
263
- this._arRotation = value;
264
- }
265
-
266
- public get arScale(): vec3 {
267
- return this._arScale;
268
- }
269
-
270
- public set arScale(value: vec3) {
271
- this._arScale = value;
272
- }
273
-
274
- public get arTranslation(): vec3 {
275
- return this._arTranslation;
276
- }
277
-
278
- public set arTranslation(value: vec3) {
279
- this._arTranslation = value;
280
- }
281
-
282
- public get automaticColorAdjustment(): boolean {
283
- return this._automaticColorAdjustment;
284
- }
285
-
286
- public set automaticColorAdjustment(value: boolean) {
287
- if (this._automaticColorAdjustment === value) return;
288
- this._automaticColorAdjustment = value;
289
- this._colorCache.forEach(c => c.colorCorrection(value));
290
- this._materialLoader.assignColorCorrection(value);
291
- }
292
-
293
- public get automaticResizing(): boolean {
294
- return this._automaticResizing;
295
- }
296
-
297
- public set automaticResizing(value: boolean) {
298
- this._automaticResizing = value;
299
- }
300
-
301
- public get beautyRenderBlendingDuration(): number {
302
- return this._beautyRenderBlendingDuration;
303
- }
304
-
305
- public set beautyRenderBlendingDuration(value: number) {
306
- this._beautyRenderBlendingDuration = value;
307
- }
308
-
309
- public get beautyRenderDelay(): number {
310
- return this._beautyRenderDelay;
311
- }
312
-
313
- public set beautyRenderDelay(value: number) {
314
- this._beautyRenderDelay = value;
315
- }
316
-
317
- public get branding(): {
318
- logo: string | null;
319
- backgroundColor: string;
320
- busyModeSpinner: string;
321
- busyModeDisplay: BUSY_MODE_DISPLAY;
322
- spinnerPositioning: SPINNER_POSITIONING
323
- } {
324
- return this._branding;
325
- }
326
-
327
- public get busy(): boolean {
328
- return this._busy;
329
- }
330
-
331
- public set busy(value: boolean) {
332
- this._busy = value;
333
- }
334
-
335
- public get busyModeDisplay(): BUSY_MODE_DISPLAY {
336
- return this._busyModeDisplay;
337
- }
338
-
339
- public set busyModeDisplay(value: BUSY_MODE_DISPLAY) {
340
- this._busyModeDisplay = value;
341
- }
342
-
343
- public get camera(): THREE.Camera {
344
- return this._cameraManager.camera;
345
- }
346
-
347
- public get cameraEngine(): CameraEngine {
348
- return this._cameraEngine;
349
- }
350
-
351
- public get cameraManager(): CameraManager {
352
- return this._cameraManager;
353
- }
354
-
355
- public get canvas(): HTMLCanvasElement {
356
- return this._canvas.canvasElement;
357
- }
358
-
359
- public get canvasEngine(): CanvasEngine {
360
- return this._canvasEngine;
361
- }
362
-
363
- public get clearAlpha(): number {
364
- return this._clearAlpha;
365
- }
366
-
367
- public set clearAlpha(value: number) {
368
- this._clearAlpha = value;
369
- }
370
-
371
- public get clearColor(): Color {
372
- return this._clearColor;
373
- }
374
-
375
- public set clearColor(value: Color) {
376
- this._clearColor = value;
377
- }
378
-
379
- public get closed(): boolean {
380
- return this._closed;
381
- }
382
-
383
- public get colorCache(): SDColor[] {
384
- return this._colorCache;
385
- }
386
-
387
- public get continuousRendering(): boolean {
388
- return this._renderingManager.continuousRendering;
389
- }
390
-
391
- public set continuousRendering(value: boolean) {
392
- this._renderingManager.continuousRendering = value;
393
- }
394
-
395
- public get continuousShadowMapUpdate(): boolean {
396
- return this._renderingManager.continuousShadowMapUpdate;
397
- }
398
-
399
- public set continuousShadowMapUpdate(value: boolean) {
400
- this._renderingManager.continuousShadowMapUpdate = value;
401
- }
402
-
403
- public get defaultLineMaterial(): MaterialBasicLineData {
404
- return this.materialLoader.defaultLineMaterialData;
405
- }
406
-
407
- public set defaultLineMaterial(value: MaterialBasicLineData) {
408
- this.materialLoader.defaultLineMaterialData = value;
409
- }
410
-
411
- public get defaultMaterial(): MaterialStandardData {
412
- return this.materialLoader.defaultMaterialData;
413
- }
414
-
415
- public set defaultMaterial(value: MaterialStandardData) {
416
- this.materialLoader.defaultMaterialData = value;
417
- }
418
-
419
- public get defaultMaterialColor(): Color {
420
- return this.materialLoader.defaultMaterialData.color;
421
- }
422
-
423
- public set defaultMaterialColor(value: Color) {
424
- this.materialLoader.defaultMaterialData.color = value;
425
- this.materialLoader.assignDefaultMaterial();
426
- this.materialLoader.defaultLineMaterialData.color = value;
427
- this.materialLoader.assignDefaultLineMaterial();
428
- this.materialLoader.defaultPointMaterialData.color = value;
429
- this.materialLoader.assignDefaultPointMaterial();
430
- }
431
-
432
- public get defaultPointMaterial(): MaterialPointData {
433
- return this.materialLoader.defaultPointMaterialData;
434
- }
435
-
436
- public set defaultPointMaterial(value: MaterialPointData) {
437
- this.materialLoader.defaultPointMaterialData = value;
438
- }
439
-
440
- public get domEventEngine(): DomEventEngine {
441
- return this._domEventEngine;
442
- }
443
-
444
- public get enableAR(): boolean {
445
- return this._enableAR;
446
- }
447
-
448
- public set enableAR(value: boolean) {
449
- this._enableAR = value;
450
- }
451
-
452
- public get environmentMap(): string | string[] {
453
- return this._environmentMap;
454
- }
455
-
456
- public set environmentMap(value: string | string[]) {
457
- this._environmentMap = value;
458
- this._environmentMapLoader.load(this.environmentMap);
459
- }
460
-
461
- public get environmentMapAsBackground(): boolean {
462
- return this._environmentMapAsBackground;
463
- }
464
-
465
- public set environmentMapAsBackground(value: boolean) {
466
- this._environmentMapAsBackground = value;
467
- }
468
-
469
- public get environmentMapBlurriness(): number {
470
- return this._environmentMapBlurriness;
471
- }
472
-
473
- public set environmentMapBlurriness(value: number) {
474
- this._environmentMapBlurriness = value;
475
- this._sceneTreeManager.scene.backgroundBlurriness = this._environmentMapBlurriness;
476
- }
477
-
478
- public get environmentMapForUnlitMaterials(): boolean {
479
- return this._environmentMapForUnlitMaterials;
480
- }
481
-
482
- public set environmentMapForUnlitMaterials(value: boolean) {
483
- this._environmentMapForUnlitMaterials = value;
484
- this._materialLoader.assignEnvironmentMapForUnlitMaterials(value);
485
- }
486
-
487
- public get environmentMapIntensity(): number {
488
- return this._environmentMapIntensity;
489
- }
490
-
491
- public set environmentMapIntensity(value: number) {
492
- this._environmentMapIntensity = value;
493
- this._sceneTreeManager.scene.backgroundIntensity = value;
494
- this._materialLoader.assignEnvironmentMapIntensity(value);
495
- }
496
-
497
- public get environmentMapLoader(): EnvironmentMapLoader {
498
- return this._environmentMapLoader;
499
- }
500
-
501
- public get environmentMapResolution(): string {
502
- return this._environmentMapResolution;
503
- }
504
-
505
- public set environmentMapResolution(value: string) {
506
- this._environmentMapResolution = value;
507
- this._environmentMapLoader.load(this.environmentMap);
508
- }
509
-
510
- public get environmentMapRotation(): quat {
511
- return this._environmentMapRotation;
512
- }
513
-
514
- public set environmentMapRotation(value: quat) {
515
- this._environmentMapRotation = value;
516
- this._materialLoader.assignEnvironmentMapRotation(value);
517
- }
518
-
519
- public get eventEngine(): EventEngine {
520
- return this._eventEngine;
521
- }
522
-
523
- public get geometryLoader(): GeometryLoader {
524
- return this._geometryLoader;
525
- }
526
-
527
- public get gridColor(): Color {
528
- return this._environmentGeometryManager.gridColor;
529
- }
530
-
531
- public set gridColor(value: Color) {
532
- this._environmentGeometryManager.gridColor = value;
533
- }
534
-
535
- public get gridVisibility(): boolean {
536
- return this._gridVisibility;
537
- }
538
-
539
- public set gridVisibility(value: boolean) {
540
- if (this._environmentGeometryManager.grid) this._environmentGeometryManager.grid.visible = value;
541
- this._gridVisibility = value;
542
- }
543
-
544
- public get groundPlaneColor(): Color {
545
- return this._environmentGeometryManager.groundPlaneColor;
546
- }
547
-
548
- public set groundPlaneColor(value: Color) {
549
- this._environmentGeometryManager.groundPlaneColor = value;
550
- }
551
-
552
- public get groundPlaneShadowColor(): Color {
553
- return this._environmentGeometryManager.groundPlaneShadowColor;
554
- }
555
-
556
- public set groundPlaneShadowColor(value: Color) {
557
- this._environmentGeometryManager.groundPlaneShadowColor = value;
558
- }
559
-
560
- public get groundPlaneShadowVisibility(): boolean {
561
- return this._groundPlaneShadowVisibility;
562
- }
563
-
564
- public set groundPlaneShadowVisibility(value: boolean) {
565
- if (this._environmentGeometryManager.groundPlaneShadow) this._environmentGeometryManager.groundPlaneShadow.visible = value;
566
- this._groundPlaneShadowVisibility = value;
567
- }
568
-
569
- public get groundPlaneVisibility(): boolean {
570
- return this._groundPlaneVisibility;
571
- }
572
-
573
- public set groundPlaneVisibility(value: boolean) {
574
- if (this._environmentGeometryManager.groundPlane) this._environmentGeometryManager.groundPlane.visible = value;
575
- this._groundPlaneVisibility = value;
576
- }
577
-
578
- public get htmlElementAnchorLoader(): HTMLElementAnchorLoader {
579
- return this._htmlElementAnchorLoader;
580
- }
581
-
582
- public get id(): string {
583
- return this._id;
584
- }
585
-
586
- public get lightEngine(): LightEngine {
587
- return this._lightEngine;
588
- }
589
-
590
- public get lightLoader(): LightLoader {
591
- return this._lightLoader;
592
- }
593
-
594
- public get lightScene(): string {
595
- return this.lightEngine.lightScene ? this.lightEngine.lightScene.id : '';
596
- }
597
-
598
- public get lightSceneId(): string {
599
- return this.lightEngine.lightScene ? this.lightEngine.lightScene.id : '';
600
- }
601
-
602
- public get lights(): boolean {
603
- return this._lights;
604
- }
605
-
606
- public set lights(value: boolean) {
607
- this._lights = value;
608
- }
609
-
610
- public get logoDivElement(): HTMLDivElement {
611
- return this._logoDivElement;
612
- }
613
-
614
- public get materialLoader(): MaterialLoader {
615
- return this._materialLoader;
616
- }
617
-
618
- public get maximumRenderingSize(): {
619
- width: number,
620
- height: number
621
- } {
622
- return this._maximumRenderingSize;
623
- }
624
-
625
- public set maximumRenderingSize(value: {
626
- width: number,
627
- height: number
628
- }) {
629
- this._maximumRenderingSize = value;
630
- }
631
-
632
- public get minimalRendering(): boolean {
633
- return this.renderingManager.minimalRendering;
634
- }
635
-
636
- public get outputEncoding(): TEXTURE_ENCODING {
637
- switch (this._renderer.outputColorSpace) {
638
- case (THREE.SRGBColorSpace):
639
- return TEXTURE_ENCODING.SRGB;
640
- case (THREE.LinearSRGBColorSpace):
641
- default:
642
- return TEXTURE_ENCODING.LINEAR;
643
- }
644
- }
645
-
646
- public set outputEncoding(value: TEXTURE_ENCODING) {
647
- switch (value) {
648
- case (TEXTURE_ENCODING.SRGB):
649
- this._renderer.outputColorSpace = THREE.SRGBColorSpace;
650
- break;
651
- case (TEXTURE_ENCODING.LINEAR):
652
- default:
653
- this._renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
654
- break;
655
- }
656
- }
657
-
658
- public get pause(): boolean {
659
- return this._pause;
660
- }
661
-
662
- public set pause(value: boolean) {
663
- this._pause = value;
664
- }
665
-
666
- public get physicallyCorrectLights(): boolean {
667
- return !this._renderer.useLegacyLights;
668
- }
669
-
670
- public set physicallyCorrectLights(value: boolean) {
671
- this._renderer.useLegacyLights = !value;
672
- }
673
-
674
- public get pointSize(): number {
675
- return this.materialLoader.defaultPointMaterialData.size || 1;
676
- }
677
-
678
- public set pointSize(value: number) {
679
- this.materialLoader.defaultPointMaterialData.size = value;
680
- this.materialLoader.assignDefaultPointMaterial();
681
- }
682
-
683
- public get postProcessingManager(): PostProcessingManager {
684
- return this._postProcessingManager;
685
- }
686
-
687
- public get postRenderingCallback(): ((renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera) => void) | undefined {
688
- return this._postRenderingCallback;
689
- }
690
-
691
- public set postRenderingCallback(value: ((renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera) => void) | undefined) {
692
- this._postRenderingCallback = value;
693
- }
694
-
695
- public get preRenderingCallback(): ((renderer: THREE.WebGLRenderer) => void) | undefined {
696
- return this._preRenderingCallback;
697
- }
698
-
699
- public set preRenderingCallback(value: ((renderer: THREE.WebGLRenderer) => void) | undefined) {
700
- this._preRenderingCallback = value;
701
- }
702
-
703
- public get renderer(): THREE.WebGLRenderer {
704
- return this._renderer;
705
- }
706
-
707
- public get renderingManager(): RenderingManager {
708
- return this._renderingManager;
709
- }
710
-
711
- public get scene(): THREE.Scene {
712
- return this._sceneTreeManager.scene;
713
- }
714
-
715
- public get sceneTracingManager(): SceneTracingManager {
716
- return this._sceneTracingManager;
717
- }
718
-
719
- public get sceneTreeManager(): SceneTreeManager {
720
- return this._sceneTreeManager;
721
- }
722
-
723
- public get sessionSettingsId(): string | undefined {
724
- return this._sessionSettingsId;
725
- }
726
-
727
- public set sessionSettingsId(value: string | undefined) {
728
- this._sessionSettingsId = value;
729
- }
730
-
731
- public get sessionSettingsMode(): SESSION_SETTINGS_MODE {
732
- return this._sessionSettingsMode;
733
- }
734
-
735
- public set sessionSettingsMode(value: SESSION_SETTINGS_MODE) {
736
- this._sessionSettingsMode = value;
737
- }
738
-
739
- public get settingsEngine(): SettingsEngine | undefined {
740
- return this._settingsEngine;
741
- }
742
-
743
- public set settingsEngine(value: SettingsEngine | undefined) {
744
- this._settingsEngine = value;
745
- }
746
-
747
- public get shadows(): boolean {
748
- return this._shadows;
749
- }
750
-
751
- public set shadows(value: boolean) {
752
- this._shadows = value;
753
- }
754
-
755
- public get show(): boolean {
756
- return this._show;
757
- }
758
-
759
- public set show(value: boolean) {
760
- this._show = value;
761
- }
762
-
763
- public get showStatistics(): boolean {
764
- return this._showStatistics;
765
- }
766
-
767
- public set showStatistics(value: boolean) {
768
- this._showStatistics = value;
769
- }
770
-
771
- public get softShadows(): boolean {
772
- return this._softShadows;
773
- }
774
-
775
- public set softShadows(value: boolean) {
776
- this._softShadows = value;
777
- }
778
-
779
- public get spinnerDivElement(): HTMLDivElement {
780
- return this._spinnerDivElement;
781
- }
782
-
783
- public get stateEngine(): StateEngine {
784
- return this._stateEngine;
785
- }
786
-
787
- public get textureEncoding(): TEXTURE_ENCODING {
788
- switch (this.materialLoader.textureEncoding) {
789
- case (THREE.SRGBColorSpace):
790
- return TEXTURE_ENCODING.SRGB;
791
- case (THREE.LinearSRGBColorSpace):
792
- default:
793
- return TEXTURE_ENCODING.LINEAR;
794
- }
795
- }
796
-
797
- public set textureEncoding(value: TEXTURE_ENCODING) {
798
- switch (value) {
799
- case (TEXTURE_ENCODING.SRGB):
800
- this.environmentMapLoader.textureEncoding = THREE.SRGBColorSpace;
801
- this.materialLoader.textureEncoding = THREE.SRGBColorSpace;
802
- break;
803
- case (TEXTURE_ENCODING.LINEAR):
804
- default:
805
- this.environmentMapLoader.textureEncoding = THREE.LinearSRGBColorSpace;
806
- this.materialLoader.textureEncoding = THREE.LinearSRGBColorSpace;
807
- }
808
- }
809
-
810
- public get toneMapping(): TONE_MAPPING {
811
- switch (this._renderer.toneMapping) {
812
- case (THREE.LinearToneMapping):
813
- return TONE_MAPPING.LINEAR;
814
- case (THREE.ReinhardToneMapping):
815
- return TONE_MAPPING.REINHARD;
816
- case (THREE.CineonToneMapping):
817
- return TONE_MAPPING.CINEON;
818
- case (THREE.ACESFilmicToneMapping):
819
- return TONE_MAPPING.ACES_FILMIC;
820
- case (THREE.NoToneMapping):
821
- default:
822
- return TONE_MAPPING.NONE;
823
- }
824
- }
825
-
826
- public set toneMapping(value: TONE_MAPPING) {
827
- switch (value) {
828
- case (TONE_MAPPING.LINEAR):
829
- this._renderer.toneMapping = THREE.LinearToneMapping;
830
- break;
831
- case (TONE_MAPPING.REINHARD):
832
- this._renderer.toneMapping = THREE.ReinhardToneMapping;
833
- break;
834
- case (TONE_MAPPING.CINEON):
835
- this._renderer.toneMapping = THREE.CineonToneMapping;
836
- break;
837
- case (TONE_MAPPING.ACES_FILMIC):
838
- this._renderer.toneMapping = THREE.ACESFilmicToneMapping;
839
- break;
840
- case (TONE_MAPPING.NONE):
841
- default:
842
- this._renderer.toneMapping = THREE.NoToneMapping;
843
- }
844
- this.materialLoader.updateMaterials();
845
- }
846
-
847
- public get toneMappingExposure(): number {
848
- return this._renderer.toneMappingExposure;
849
- }
850
-
851
- public set toneMappingExposure(value: number) {
852
- this._renderer.toneMappingExposure = value;
853
- }
854
-
855
- public get type(): RENDERER_TYPE {
856
- return this._type;
857
- }
858
-
859
- public set type(value: RENDERER_TYPE) {
860
- this._type = value;
861
- }
862
-
863
- public get usingSwiftShader(): boolean {
864
- return this.renderingManager.usingSwiftShader;
865
- }
866
-
867
- public get visibility(): VISIBILITY_MODE {
868
- return this._visibility;
869
- }
870
-
871
- public get visualizeAttributes(): ((overview: ISDTFOverview, itemData?: ISDTFItemData) => ISDTFAttributeVisualizationData) | undefined {
872
- return this._visualizeAttributes;
873
- }
874
-
875
- public set visualizeAttributes(value: ((overview: ISDTFOverview, itemData?: ISDTFItemData) => ISDTFAttributeVisualizationData) | undefined) {
876
- this._visualizeAttributes = value;
877
- }
878
-
879
- // #endregion Public Getters And Setters (133)
880
-
881
- // #region Public Methods (25)
882
-
883
- public addFlag(flag: FLAG_TYPE): string {
884
- const token = this._uuidGenerator.create();
885
- if (flag === FLAG_TYPE.BUSY_MODE) {
886
- this.stateEngine.viewportEngines[this.id]?.busy.push(token);
887
- } else {
888
- this.#flags[flag].push(token);
889
- }
890
- this.evaluateFlagState();
891
- return token;
892
- }
893
-
894
- public async applySettings(
895
- sections: IViewportSettingsSections = {
896
- ar: true,
897
- scene: true,
898
- camera: true,
899
- light: true,
900
- environment: true,
901
- general: true,
902
- postprocessing: true
903
- },
904
- settingsEngine?: SettingsEngine,
905
- updateViewport: boolean = true
906
- ): Promise<void> {
907
- settingsEngine = settingsEngine || this._settingsEngine;
908
- if (!settingsEngine) return;
909
-
910
- if (sections.environment) {
911
- // as the environment map is the only thing that needs time to load, load it first
912
- await new Promise<void>((resolve, reject) => {
913
- this._stateEngine.viewportEngines[this.id]?.environmentMapLoaded.then(() => {
914
- try {
915
- if (!settingsEngine) return;
916
- this.environmentMapAsBackground = settingsEngine.environment.mapAsBackground;
917
- this.clearAlpha = settingsEngine.environment.clearAlpha;
918
- this.clearColor = this._converter.toHexColor(settingsEngine.environment.clearColor);
919
- this.environmentMapRotation = [settingsEngine.environment.rotation.x, settingsEngine.environment.rotation.y, settingsEngine.environment.rotation.z, settingsEngine.environment.rotation.w];
920
- this.environmentMapBlurriness = settingsEngine.environment.blurriness;
921
- this.environmentMapIntensity = settingsEngine.environment.intensity;
922
- this.applySyncSettings(sections, settingsEngine, updateViewport);
923
-
924
- this._eventEngine.emitEvent(EVENTTYPE_VIEWPORT.VIEWPORT_SETTINGS_LOADED, <IViewportEvent>{ viewportId: this.id });
925
- resolve();
926
- } catch (e) {
927
- reject(e);
928
- }
929
- }).catch(e => reject(e));
930
-
931
- // set it like this to not trigger the loading
932
- this.environmentMap = settingsEngine!.environment.map;
933
- });
934
- } else {
935
- this.applySyncSettings(sections, settingsEngine, updateViewport);
936
- this._eventEngine.emitEvent(EVENTTYPE_VIEWPORT.VIEWPORT_SETTINGS_LOADED, <IViewportEvent>{ viewportId: this.id });
937
- }
938
- }
939
-
940
- public assignSettingsEngine(settingsEngine: SettingsEngine): void {
941
- this._settingsEngine = settingsEngine;
942
- }
943
-
944
- public async close(): Promise<void> {
945
- this._closed = true;
946
- this._lightEngine.close();
947
- this._renderer.clear(true, true, true);
948
- this._renderer.dispose();
949
- this._domEventEngine.removeAllDomEventListener();
950
- this._domEventEngine.dispose();
951
- this._canvas.canvasElement.parentElement?.removeChild(this._logoDivElement);
952
- this._canvas.canvasElement.parentElement?.removeChild(this._spinnerDivElement);
953
- this._canvas.canvasElement.parentNode?.removeChild(this._htmlElementAnchorLoader.parentDiv);
954
- this._canvas.reset();
955
- }
956
-
957
- public continueRendering(): void {
958
- this._pause = false;
959
- }
960
-
961
- public convert3Dto2D(p: vec3): { container: vec2; client: vec2; page: vec2; hidden: boolean; } {
962
- return this.sceneTracingManager.convert3Dto2D(p);
963
- }
964
-
965
- public createSDTFOverview(node: ITreeNode): ISDTFOverview {
966
- const out: ISDTFOverviewData = new SDTFOverviewData({});
967
- for (let i = 0, len = node.data.length; i < len; i++)
968
- if (node.data[i] instanceof SDTFOverviewData)
969
- out.merge(<ISDTFOverviewData>node.data[i]);
970
-
971
- for (let i = 0, len = node.children.length; i < len; i++)
972
- out.merge(new SDTFOverviewData(this.createSDTFOverview(node.children[i])));
973
-
974
- return out.overview;
975
- }
976
-
977
- public createThreeJsColor(color: Color): THREE.Color {
978
- const sdColor = new SDColor(this._converter.toThreeJsColorInput(color), color);
979
- sdColor.colorCorrection(this.automaticColorAdjustment);
980
- this._colorCache.push(sdColor);
981
- return sdColor;
982
- }
983
-
984
- public displayErrorMessage(message: string) {
985
- for (let i = 0; i < this.logoDivElement.children.length; i++)
986
- (<HTMLElement>this.logoDivElement.children[i]).style.visibility = 'hidden';
987
-
988
- const d = <HTMLDivElement>document.createElement('div');
989
- d.classList.add('sdv-error-message-container');
990
- this.logoDivElement.appendChild(d);
991
-
992
- const p = <HTMLParagraphElement>document.createElement('p');
993
- p.textContent = message;
994
- p.classList.add('sdv-error-message');
995
- p.style.color = this.logoDivElement.style.backgroundColor;
996
- d.appendChild(p);
997
- }
998
-
999
- public evaluateFlagState() {
1000
- // busy
1001
- {
1002
- const currentBusyState = this.busy;
1003
- if (this.stateEngine.viewportEngines[this.id] && this.stateEngine.viewportEngines[this.id]!.busy.length > 0) {
1004
- if (!currentBusyState) {
1005
- this.busy = true;
1006
- this._renderingManager.render();
1007
- this._eventEngine.emitEvent(EVENTTYPE.VIEWPORT.BUSY_MODE_ON, { viewportId: this.id });
1008
- }
1009
- } else {
1010
- if (currentBusyState) {
1011
- this.busy = false;
1012
- this._renderingManager.render();
1013
- this._eventEngine.emitEvent(EVENTTYPE.VIEWPORT.BUSY_MODE_OFF, { viewportId: this.id });
1014
- }
1015
- }
1016
- }
1017
-
1018
- // camera freeze
1019
- {
1020
- if (this.#flags[FLAG_TYPE.CAMERA_FREEZE].length > 0) {
1021
- this.cameraEngine.deactivateCameraEvents();
1022
- } else {
1023
- this.cameraEngine.activateCameraEvents();
1024
- }
1025
- }
1026
-
1027
- // continuous rendering
1028
- {
1029
- const currentContinuousRenderingState = this.continuousRendering;
1030
- if (this.#flags[FLAG_TYPE.CONTINUOUS_RENDERING].length > 0) {
1031
- if (!currentContinuousRenderingState) {
1032
- this.continuousRendering = true;
1033
- this._renderingManager.render();
1034
- }
1035
- } else {
1036
- if (currentContinuousRenderingState) {
1037
- this.continuousRendering = false;
1038
- }
1039
- }
1040
- }
1041
-
1042
- // continuous shadow map update
1043
- {
1044
- const currentShadowMapUpdateState = this.continuousShadowMapUpdate;
1045
- if (this.#flags[FLAG_TYPE.CONTINUOUS_SHADOW_MAP_UPDATE].length > 0) {
1046
- if (!currentShadowMapUpdateState) {
1047
- this.continuousShadowMapUpdate = true;
1048
- this._renderingManager.render();
1049
- }
1050
- } else {
1051
- if (currentShadowMapUpdateState) {
1052
- this.continuousShadowMapUpdate = false;
1053
- }
1054
- }
1055
- }
1056
- }
1057
-
1058
- public getEnvironmentMapImageUrl() {
1059
- return this._environmentMapLoader.getEnvironmentMapImageUrl(this.environmentMap);
1060
- }
1061
-
1062
- public getScreenshot(type?: string, encoderOptions?: number): string {
1063
- return this._renderingManager.getScreenshot(type, encoderOptions);
1064
- }
1065
-
1066
- public isMobileDeviceWithoutBrowserARSupport(): boolean {
1067
- // has to be a mobile device (duh)
1068
- if (this._systemInfo.isIOS === false && this._systemInfo.isAndroid === false)
1069
- return false;
1070
-
1071
- // no Firefox on Android
1072
- if (this._systemInfo.isAndroid === true && this._systemInfo.isFirefox === true)
1073
- return true;
1074
-
1075
- // no Instagram on iOS
1076
- if (this._systemInfo.isIOS === true && this._systemInfo.isInstagram === true)
1077
- return true;
1078
-
1079
- return false;
1080
- }
1081
-
1082
- public pauseRendering(): void {
1083
- this._pause = true;
1084
- }
1085
-
1086
- public pointerEventToRay(event: PointerEvent): { origin: vec3, direction: vec3 } {
1087
- return this._sceneTracingManager.pointerEventToRay(event);
1088
- }
1089
-
1090
- public raytraceScene(origin: vec3, direction: vec3): { distance: number, node: ITreeNode, data?: IGeometryData; }[] {
1091
- const intersect = this._intersectionManager.intersect({ origin, direction }, this.id);
1092
- return intersect.map(i => {
1093
- return {
1094
- distance: i.distance,
1095
- node: i.node,
1096
- data: i.geometryData
1097
- };
1098
- });
1099
- }
1100
-
1101
- public removeFlag(token: string): boolean {
1102
- let success = false;
1103
- const Flags = Object.values(FLAG_TYPE);
1104
- for (const f of Flags) {
1105
- if (f === FLAG_TYPE.BUSY_MODE) {
1106
- if (this.stateEngine.viewportEngines[this.id] && this.stateEngine.viewportEngines[this.id]!.busy.includes(token)) {
1107
- this.stateEngine.viewportEngines[this.id]!.busy.splice(this.stateEngine.viewportEngines[this.id]!.busy.indexOf(token), 1);
1108
- success = true;
1109
- break;
1110
- }
1111
- } else {
1112
- if (this.#flags[f].includes(token)) {
1113
- this.#flags[f].splice(this.#flags[f].indexOf(token), 1);
1114
- success = true;
1115
- break;
1116
- }
1117
- }
1118
- }
1119
- this.evaluateFlagState();
1120
- return success;
1121
- }
1122
-
1123
- public reset() {
1124
- this._stateEngine.viewportEngines[this.id]?.settingsAssigned.reset();
1125
- this._stateEngine.viewportEngines[this.id]?.boundingBoxCreated.reset();
1126
- this._stateEngine.viewportEngines[this.id]?.environmentMapLoaded.reset();
1127
-
1128
- this._stateEngine.viewportEngines[this.id]?.boundingBoxCreated.then(() => {
1129
- this._environmentGeometryManager.changeSceneExtents(this._sceneTreeManager.boundingBox);
1130
- });
1131
- }
1132
-
1133
- public resize(width: number, height: number): void {
1134
- this._renderingManager.resize(width, height);
1135
- this._renderingManager.render();
1136
- }
1137
-
1138
- public saveSettings(settingsEngine?: SettingsEngine) {
1139
- settingsEngine = settingsEngine || this._settingsEngine;
1140
- if (!settingsEngine) return;
1141
-
1142
- (<LightEngine>this.lightEngine).saveSettings(settingsEngine);
1143
- (<CameraEngine>this.cameraEngine).saveSettings(settingsEngine);
1144
- (<PostProcessingManager>this.postProcessingManager).saveSettings(settingsEngine);
1145
-
1146
- settingsEngine.ar.enable = this.enableAR;
1147
-
1148
- settingsEngine.environment.mapResolution = this.environmentMapResolution;
1149
- settingsEngine.environment.map = Array.isArray(this.environmentMap) ? JSON.stringify(this.environmentMap) : this.environmentMap;
1150
- settingsEngine.environment.mapAsBackground = this.environmentMapAsBackground;
1151
- settingsEngine.environment.clearAlpha = this.clearAlpha;
1152
- settingsEngine.environment.clearColor = this._converter.toHexColor(this.clearColor);
1153
- settingsEngine.environment.rotation = { x: this.environmentMapRotation[0], y: this.environmentMapRotation[1], z: this.environmentMapRotation[2], w: this.environmentMapRotation[3] };
1154
- settingsEngine.environment.blurriness = this.environmentMapBlurriness;
1155
- settingsEngine.environment.intensity = this.environmentMapIntensity;
1156
-
1157
- settingsEngine.environmentGeometry.gridVisibility = this.gridVisibility;
1158
- settingsEngine.environmentGeometry.groundPlaneVisibility = this.groundPlaneVisibility;
1159
- settingsEngine.environmentGeometry.groundPlaneShadowVisibility = this.groundPlaneShadowVisibility;
1160
- settingsEngine.environmentGeometry.gridColor = this._converter.toHexColor(this.gridColor);
1161
- settingsEngine.environmentGeometry.groundPlaneColor = this._converter.toHexColor(this.groundPlaneColor);
1162
- settingsEngine.environmentGeometry.groundPlaneShadowColor = this._converter.toHexColor(this.groundPlaneShadowColor);
1163
-
1164
- settingsEngine.general.pointSize = this.pointSize;
1165
- settingsEngine.general.transformation.rotation = { x: this.arRotation[0], y: this.arRotation[1], z: this.arRotation[2] };
1166
- settingsEngine.general.transformation.translation = { x: this.arTranslation[0], y: this.arTranslation[1], z: this.arTranslation[2] };
1167
- settingsEngine.general.transformation.scale = { x: this.arScale[0], y: this.arScale[1], z: this.arScale[2] };
1168
- settingsEngine.general.defaultMaterialColor = this._converter.toHexColor(this.defaultMaterialColor);
1169
-
1170
- settingsEngine.rendering.automaticColorAdjustment = this.automaticColorAdjustment;
1171
- settingsEngine.rendering.lights = this.lights;
1172
- settingsEngine.rendering.outputEncoding = this.outputEncoding;
1173
- settingsEngine.rendering.physicallyCorrectLights = this.physicallyCorrectLights;
1174
- settingsEngine.rendering.textureEncoding = this.textureEncoding;
1175
- settingsEngine.rendering.toneMapping = this.toneMapping;
1176
- settingsEngine.rendering.toneMappingExposure = this.toneMappingExposure;
1177
- settingsEngine.rendering.beautyRenderBlendingDuration = this.beautyRenderBlendingDuration;
1178
- settingsEngine.rendering.beautyRenderDelay = this.beautyRenderDelay;
1179
- settingsEngine.rendering.shadows = this.shadows;
1180
- settingsEngine.rendering.softShadows = this.softShadows;
1181
- }
1182
-
1183
- public start() {
1184
- this._renderingManager.start();
1185
-
1186
- this._stateEngine.viewportEngines[this.id]?.boundingBoxCreated.then(() => {
1187
- this._environmentGeometryManager.changeSceneExtents(this._sceneTreeManager.boundingBox);
1188
- });
1189
-
1190
- if (this._sessionSettingsMode === SESSION_SETTINGS_MODE.NONE) {
1191
- this.environmentMap = 'photo_studio';
1192
- }
1193
- }
1194
-
1195
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1196
- public update(id: string): void {
1197
- if (this.closed) return;
1198
- this._sceneTreeManager.updateSceneTree(this._tree.root);
1199
- this._renderingManager.updateShadowMap();
1200
- this._animationEngine.updateAnimationData();
1201
- this._renderingManager.render();
1202
- this._eventEngine.emitEvent(EVENTTYPE_VIEWPORT.VIEWPORT_UPDATED, <IViewportEvent>{ viewportId: this.id });
1203
- }
1204
-
1205
- public updateEnvironmentGeometry(): void {
1206
- this._environmentGeometryManager.updateEnvironmentGeometryPosition();
1207
- }
1208
-
1209
- public async viewInAR(file: string, options: { arScale?: 'auto' | 'fixed', arPlacement?: 'floor' | 'wall', xrEnvironment?: boolean } = { arScale: 'auto', arPlacement: 'floor', xrEnvironment: false }): Promise<void> {
1210
- const eventId = this._uuidGenerator.create();
1211
- const event: ITaskEvent = { type: TASK_TYPE.AR_LOADING, id: eventId, progress: 0, status: 'Loading AR scene' };
1212
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_START, event);
1213
-
1214
- // if this is not a supported device, throw an error
1215
- if (this.viewableInAR() === false) {
1216
- const event: ITaskEvent = { type: TASK_TYPE.AR_LOADING, id: eventId, progress: 1, status: 'Stopped AR loading due to an error' };
1217
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, event);
1218
- throw new ShapeDiverViewerArError('Api.viewInAR: The device or browser is not supported for this functionality, please call "viewableInAR" for more information.');
1219
- }
1220
-
1221
- const arScale = options.arScale !== 'auto' ? 'fixed' : 'auto';
1222
- // const arPlacement = options.arPlacement !== 'wall' ? 'floor' : 'wall';
1223
- // const xrEnvironment = options.xrEnvironment !== true ? false : true;
1224
-
1225
- // let arEnvironment = '';
1226
- // const envMapUrl = this.getEnvironmentMapImageUrl();
1227
- // if (envMapUrl !== '') {
1228
- // if (envMapUrl.endsWith('.hdr')) {
1229
- // arEnvironment = 'skybox-image=' + envMapUrl;
1230
- // } else {
1231
- // arEnvironment = 'environment-image=' + envMapUrl;
1232
- // }
1233
- // }
1234
-
1235
- if (this._systemInfo.isIOS) {
1236
- // create the link and click it
1237
- const a = document.createElement('a');
1238
- a.href = file + (arScale === 'fixed' ? '.usdz_allowsContentScaling=0' : '.usdz');
1239
- a.rel = 'ar';
1240
- const img = document.createElement('img');
1241
- img.src = this.#defaultLogoStatic;
1242
- a.appendChild(img);
1243
- a.click();
1244
- } else {
1245
- const a = document.createElement('a');
1246
- a.href = `intent://arvr.google.com/scene-viewer/1.0?resizable=${arScale === 'fixed' ? 'false' : 'true'}&file=${file}&mode=ar_only#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`;
1247
- a.click();
1248
- }
1249
-
1250
- const event2: ITaskEvent = { type: TASK_TYPE.AR_LOADING, id: eventId, progress: 1, status: 'Done loading AR scene, launching AR' };
1251
- this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, event2);
1252
- }
1253
-
1254
- public viewableInAR(): boolean {
1255
- // has to be a mobile device (duh)
1256
- if (this._systemInfo.isIOS === false && this._systemInfo.isAndroid === false)
1257
- return false;
1258
-
1259
- // no Firefox on Android
1260
- if (this._systemInfo.isAndroid === true && this._systemInfo.isFirefox === true)
1261
- return false;
1262
-
1263
- // no Firefox on iOS
1264
- if (this._systemInfo.isIOS === true && this._systemInfo.isFirefox === true)
1265
- return false;
1266
-
1267
- // no Instagram on iOS
1268
- if (this._systemInfo.isIOS === true && this._systemInfo.isInstagram === true)
1269
- return false;
1270
-
1271
- return true;
1272
- }
1273
-
1274
- // #endregion Public Methods (25)
1275
-
1276
- // #region Private Methods (1)
1277
-
1278
- private applySyncSettings(sections: IViewportSettingsSections = {
1279
- ar: true,
1280
- scene: true,
1281
- camera: true,
1282
- light: true,
1283
- environment: true,
1284
- general: true,
1285
- postprocessing: true
1286
- },
1287
- settingsEngine?: SettingsEngine,
1288
- updateViewport: boolean = true) {
1289
- settingsEngine = settingsEngine || this._settingsEngine;
1290
- if (!settingsEngine) return;
1291
-
1292
- if (sections.ar) {
1293
- this.enableAR = settingsEngine.ar.enable;
1294
- this.arScale = [settingsEngine.general.transformation.scale.x, settingsEngine.general.transformation.scale.y, settingsEngine.general.transformation.scale.z];
1295
- this.arTranslation = [settingsEngine.general.transformation.translation.x, settingsEngine.general.transformation.translation.y, settingsEngine.general.transformation.translation.z];
1296
- this.arRotation = [settingsEngine.general.transformation.rotation.x, settingsEngine.general.transformation.rotation.y, settingsEngine.general.transformation.rotation.z];
1297
- }
1298
-
1299
- if (sections.scene) {
1300
- this.gridColor = settingsEngine.environmentGeometry.gridColor;
1301
- this.gridVisibility = settingsEngine.environmentGeometry.gridVisibility;
1302
- this.groundPlaneColor = settingsEngine.environmentGeometry.groundPlaneColor;
1303
- this.groundPlaneVisibility = settingsEngine.environmentGeometry.groundPlaneVisibility;
1304
- this.groundPlaneShadowColor = settingsEngine.environmentGeometry.groundPlaneShadowColor;
1305
- this.groundPlaneShadowVisibility = settingsEngine.environmentGeometry.groundPlaneShadowVisibility;
1306
-
1307
- this.shadows = settingsEngine.rendering.shadows;
1308
- this.softShadows = settingsEngine.rendering.softShadows;
1309
- this.lights = settingsEngine.rendering.lights;
1310
-
1311
- this.automaticColorAdjustment = settingsEngine.rendering.automaticColorAdjustment;
1312
- this.textureEncoding = <TEXTURE_ENCODING>settingsEngine.rendering.textureEncoding;
1313
- this.outputEncoding = <TEXTURE_ENCODING>settingsEngine.rendering.outputEncoding;
1314
- this.physicallyCorrectLights = settingsEngine.rendering.physicallyCorrectLights;
1315
- this.toneMapping = <TONE_MAPPING>settingsEngine.rendering.toneMapping;
1316
- this.toneMappingExposure = settingsEngine.rendering.toneMappingExposure;
1317
- }
1318
-
1319
- if (sections.general) {
1320
- this.defaultMaterialColor = settingsEngine.general.defaultMaterialColor;
1321
- this.pointSize = settingsEngine.general.pointSize;
1322
- }
1323
-
1324
- if (sections.light) (<LightEngine>this.lightEngine).applySettings(settingsEngine);
1325
- if (sections.camera) (<CameraEngine>this.cameraEngine).applySettings(settingsEngine);
1326
- if (sections.postprocessing) (<PostProcessingManager>this.postProcessingManager).applySettings(settingsEngine);
1327
-
1328
- // call adjust camera to load the three.js camera objects
1329
- this.cameraManager.adjustCamera(1);
1330
-
1331
- this._stateEngine.viewportEngines[this.id]?.settingsAssigned.resolve(true);
1332
- if (updateViewport) this.update('RenderingEngine.applySyncSettings');
1333
- }
1334
-
1335
- // #endregion Private Methods (1)
1336
- }