@combeenation/3d-viewer 14.0.0 → 14.0.1-rc1

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 (65) hide show
  1. package/README.md +9 -9
  2. package/dist/lib-cjs/buildinfo.json +3 -3
  3. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  4. package/dist/lib-cjs/index.d.ts +62 -62
  5. package/dist/lib-cjs/index.js +94 -94
  6. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.d.ts +10 -10
  7. package/dist/lib-cjs/internal/cbn-custom-babylon-loader-plugin.js +131 -131
  8. package/dist/lib-cjs/internal/cloning-helper.d.ts +19 -19
  9. package/dist/lib-cjs/internal/cloning-helper.js +163 -163
  10. package/dist/lib-cjs/internal/device-helper.d.ts +9 -9
  11. package/dist/lib-cjs/internal/device-helper.js +24 -24
  12. package/dist/lib-cjs/internal/geometry-helper.d.ts +21 -21
  13. package/dist/lib-cjs/internal/geometry-helper.js +145 -145
  14. package/dist/lib-cjs/internal/metadata-helper.d.ts +26 -26
  15. package/dist/lib-cjs/internal/metadata-helper.js +50 -50
  16. package/dist/lib-cjs/internal/paintable-helper.d.ts +40 -40
  17. package/dist/lib-cjs/internal/paintable-helper.js +286 -286
  18. package/dist/lib-cjs/internal/tags-helper.d.ts +12 -12
  19. package/dist/lib-cjs/internal/tags-helper.js +37 -37
  20. package/dist/lib-cjs/manager/camera-manager.d.ts +110 -110
  21. package/dist/lib-cjs/manager/camera-manager.js +206 -206
  22. package/dist/lib-cjs/manager/debug-manager.d.ts +60 -60
  23. package/dist/lib-cjs/manager/debug-manager.js +217 -217
  24. package/dist/lib-cjs/manager/event-manager.d.ts +52 -52
  25. package/dist/lib-cjs/manager/event-manager.js +71 -71
  26. package/dist/lib-cjs/manager/gltf-export-manager.d.ts +84 -75
  27. package/dist/lib-cjs/manager/gltf-export-manager.js +290 -278
  28. package/dist/lib-cjs/manager/gltf-export-manager.js.map +1 -1
  29. package/dist/lib-cjs/manager/material-manager.d.ts +35 -35
  30. package/dist/lib-cjs/manager/material-manager.js +125 -125
  31. package/dist/lib-cjs/manager/model-manager.d.ts +145 -145
  32. package/dist/lib-cjs/manager/model-manager.js +382 -382
  33. package/dist/lib-cjs/manager/parameter-manager.d.ts +210 -210
  34. package/dist/lib-cjs/manager/parameter-manager.js +514 -514
  35. package/dist/lib-cjs/manager/scene-manager.d.ts +45 -45
  36. package/dist/lib-cjs/manager/scene-manager.js +64 -64
  37. package/dist/lib-cjs/manager/texture-manager.d.ts +12 -12
  38. package/dist/lib-cjs/manager/texture-manager.js +43 -43
  39. package/dist/lib-cjs/viewer-error.d.ts +48 -48
  40. package/dist/lib-cjs/viewer-error.js +60 -60
  41. package/dist/lib-cjs/viewer.d.ts +115 -115
  42. package/dist/lib-cjs/viewer.js +217 -217
  43. package/package.json +91 -91
  44. package/src/buildinfo.json +3 -3
  45. package/src/dev.ts +47 -47
  46. package/src/global-types.d.ts +39 -39
  47. package/src/index.ts +81 -81
  48. package/src/internal/cbn-custom-babylon-loader-plugin.ts +159 -159
  49. package/src/internal/cloning-helper.ts +225 -225
  50. package/src/internal/device-helper.ts +25 -25
  51. package/src/internal/geometry-helper.ts +181 -181
  52. package/src/internal/metadata-helper.ts +63 -63
  53. package/src/internal/paintable-helper.ts +310 -310
  54. package/src/internal/tags-helper.ts +41 -41
  55. package/src/manager/camera-manager.ts +365 -365
  56. package/src/manager/debug-manager.ts +245 -245
  57. package/src/manager/event-manager.ts +72 -72
  58. package/src/manager/gltf-export-manager.ts +357 -341
  59. package/src/manager/material-manager.ts +135 -135
  60. package/src/manager/model-manager.ts +458 -458
  61. package/src/manager/parameter-manager.ts +652 -652
  62. package/src/manager/scene-manager.ts +101 -101
  63. package/src/manager/texture-manager.ts +32 -32
  64. package/src/viewer-error.ts +68 -68
  65. package/src/viewer.ts +290 -290
package/src/viewer.ts CHANGED
@@ -1,290 +1,290 @@
1
- import buildInfo from './buildinfo.json';
2
- import * as Index from './index';
3
- import {
4
- BoundingInfo,
5
- CameraManager,
6
- DebugManager,
7
- DefaultSceneSettings,
8
- Engine,
9
- EngineOptions,
10
- EventManager,
11
- GltfExportManager,
12
- MaterialManager,
13
- ModelManager,
14
- ParameterManager,
15
- ParameterSubject,
16
- Scene,
17
- SceneManager,
18
- TextureManager,
19
- TransformNode,
20
- Vector3,
21
- } from './index';
22
- import { registerCustomCbnBabylonLoaderPlugin } from './internal/cbn-custom-babylon-loader-plugin';
23
- import { getIsScaledDownDevice } from './internal/device-helper';
24
- import { isNodeExcluded } from './internal/geometry-helper';
25
- import { cloneDeep, merge } from 'lodash-es';
26
-
27
- /**
28
- * Use this to define geometry to be excluded from autofocus, GLB export, etc.
29
- */
30
- export type ExcludedGeometry = TransformNode | ParameterSubject;
31
- export type ExcludedGeometryList = ExcludedGeometry[];
32
-
33
- export type LimitTextureSizeConfig = {
34
- size: 512 | 1024;
35
- devices: 'iPhone' | 'all';
36
- };
37
-
38
- export type ViewerSettings = {
39
- antialiasing: boolean;
40
- engineOptions: EngineOptions;
41
- /**
42
- * Important for visual quality on iOS devices, this setting will set the hardware scaling proportional to the devices
43
- * pixel ratio
44
- */
45
- adaptToDeviceRatio: boolean;
46
- /**
47
- * Possibility to limit the size of textures when getting loaded by the engine.\
48
- * Activating this feature potentially saves a lot of memory and can be used to avoid crashes when loading expensive
49
- * models on weaker devices.\
50
- * In praxis this has been an issue with iPhones a lot, therefore it's possible to activate this feature for iPhones
51
- * only as well.
52
- */
53
- limitTextureSize: LimitTextureSizeConfig | false;
54
- /**
55
- * See this forum entry for description of parallel shader compilition effect:
56
- * https://forum.babylonjs.com/t/scene-flickering-when-turning-off-light/48733.\
57
- * Parallel shading compilition generally improves the speed of material compilition and helps when switching
58
- * materials while objects are moving (eg: animations).\
59
- * Deactivating parallel shading compilition is benefitial when switching lights and materials in static scenarios.\
60
- * It's activated by default due to compatibility reasons but can be overwritten with this flag.
61
- */
62
- useParallelShaderCompile: boolean;
63
- };
64
-
65
- /**
66
- * This is the entry point into the application.\
67
- * Create an instance to set up the viewer on your canvas.
68
- * ```js
69
- * const canvas = document.getElementById('babylon-canvas');
70
- * const viewer = Viewer(canvas, viewerSettings, defaultSceneSettings);
71
- * ```
72
- * Use "manager" sub classes for interacting with the Babylon.js engine.
73
- * (e.g. `modelManager` for loading models into the scene)
74
- */
75
- export class Viewer {
76
- static readonly version = buildInfo.version;
77
-
78
- // NOTE: "non-null assertion operator" is used since these variables are not initialized in the constructor itself
79
- // but in a help function (`_init`) inside the constructor
80
- protected _scene!: Scene;
81
-
82
- protected _cameraManager!: CameraManager;
83
- protected _debugManager!: DebugManager;
84
- protected _eventManager!: EventManager;
85
- protected _gltfExportManager!: GltfExportManager;
86
- protected _materialManager!: MaterialManager;
87
- protected _modelManager!: ModelManager;
88
- protected _parameterManager!: ParameterManager;
89
- protected _sceneManager!: SceneManager;
90
- protected _textureManager!: TextureManager;
91
-
92
- // default viewer settings
93
- // will be overwritten in the viewer constructor
94
- protected _viewerSettings: ViewerSettings = {
95
- antialiasing: true,
96
- engineOptions: {
97
- preserveDrawingBuffer: true,
98
- stencil: true,
99
- xrCompatible: false,
100
- },
101
- adaptToDeviceRatio: true,
102
- limitTextureSize: {
103
- devices: 'iPhone',
104
- size: 1024,
105
- },
106
- useParallelShaderCompile: true,
107
- };
108
-
109
- protected _isRenderLoopPaused: boolean = false;
110
-
111
- get scene(): Scene {
112
- return this._scene;
113
- }
114
- get engine(): Engine {
115
- return this.scene.getEngine();
116
- }
117
- get cameraManager(): CameraManager {
118
- return this._cameraManager;
119
- }
120
- get debugManager(): DebugManager {
121
- return this._debugManager;
122
- }
123
- get eventManager(): EventManager {
124
- return this._eventManager;
125
- }
126
- get gltfExportManager(): GltfExportManager {
127
- return this._gltfExportManager;
128
- }
129
- get materialManager(): MaterialManager {
130
- return this._materialManager;
131
- }
132
- get modelManager(): ModelManager {
133
- return this._modelManager;
134
- }
135
- get parameterManager(): ParameterManager {
136
- return this._parameterManager;
137
- }
138
- /** @internal */
139
- get sceneManager(): SceneManager {
140
- return this._sceneManager;
141
- }
142
- /** @internal */
143
- get textureManager(): TextureManager {
144
- return this._textureManager;
145
- }
146
- get viewerSettings(): ViewerSettings {
147
- return this._viewerSettings;
148
- }
149
-
150
- /**
151
- * Returns all modules which are exported by the viewers index file.\
152
- * Needed by the [Combeenation viewer control](https://docs.combeenation.com/docs/3d-viewer-control) in situations where the viewer is injected from external code.\
153
- * See [Combeenation docs](https://docs.combeenation.com/docs/3d-viewer-control-with-custom-js) for more details.
154
- */
155
- public static getAllViewerModules(): typeof Index {
156
- return Index;
157
- }
158
-
159
- /**
160
- * @param viewerSettings Can be overwritten to tweak settings for the Babylon.js engine or viewer internal
161
- * functionalities like "texture downscaling mode"
162
- * @param defaultSceneSettings Can be overwritten to tweak settings for the automatically create Babylon.js scene.\
163
- * This scene contains a camera and an environment per default.
164
- */
165
- public constructor(
166
- public readonly canvas: HTMLCanvasElement,
167
- viewerSettings?: DeepPartial<ViewerSettings>,
168
- defaultSceneSettings?: DeepPartial<DefaultSceneSettings>
169
- ) {
170
- merge(this._viewerSettings, viewerSettings);
171
- this._init(defaultSceneSettings);
172
- }
173
-
174
- /**
175
- * Pause rendering can be usefull when doing internal scene processings that should not be visible to the user,
176
- * e.g. cloning meshes for gltf export
177
- */
178
- public pauseRendering(): void {
179
- this._isRenderLoopPaused = true;
180
- }
181
-
182
- /**
183
- * Resume render loop when paused by {@link pauseRendering} function
184
- */
185
- public resumeRendering(): void {
186
- this._isRenderLoopPaused = false;
187
- }
188
-
189
- /**
190
- * Destroys this viewer instance and disposes Babylon.js engine and all scene content
191
- */
192
- public destroy(): void {
193
- this.eventManager.removeAllListeners();
194
- this.engine.dispose();
195
- }
196
-
197
- /**
198
- * Calculates size of the current scene.\
199
- * Only takes meshes into considerations that:
200
- * - are visible
201
- * - are not excluded by "excludeGeometry" parameter
202
- * - do not have an infinite distance (like sky boxes)
203
- */
204
- public calculateBoundingInfo(excludeGeometry?: ExcludedGeometryList): BoundingInfo {
205
- // CB-6062: workaround for BoundingBox not respecting render loop
206
- this.scene.render();
207
-
208
- const { max, min } = this.scene.meshes
209
- .filter(mesh => {
210
- const isEnabled = mesh.isEnabled();
211
- // ignore meshes with invalid bounding infos
212
- const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
213
- // ignore meshes with infinite distance, typically these are sky boxes
214
- const hasInfiniteDistance = mesh.infiniteDistance;
215
- // ignore excluded meshes
216
- const isExcluded = excludeGeometry ? isNodeExcluded(mesh, excludeGeometry) : false;
217
- return isEnabled && hasValidBBoxInfo && !hasInfiniteDistance && !isExcluded;
218
- })
219
- .reduce(
220
- (accBBoxMinMax, curMesh, idx) => {
221
- curMesh.refreshBoundingInfo(true, true);
222
- const bBox = curMesh.getBoundingInfo().boundingBox;
223
- // use the first entry in the array as default value and get the resulting maximum/minimum values
224
- const max = idx === 0 ? bBox.maximumWorld : Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
225
- const min = idx === 0 ? bBox.minimumWorld : Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
226
- return { max, min };
227
- },
228
- { max: new Vector3(), min: new Vector3() }
229
- );
230
-
231
- const boundingInfo = new BoundingInfo(min, max);
232
- return boundingInfo;
233
- }
234
-
235
- /**
236
- * Set up viewer (engine and scene) and initialize all managers
237
- */
238
- protected _init(defaultSceneSettings?: DeepPartial<DefaultSceneSettings>): void {
239
- // we use a custom plugin for ".babylon" files to be able to lazy load materials that were cropped by the CBN
240
- // asset manager
241
- registerCustomCbnBabylonLoaderPlugin();
242
-
243
- const engine = new Engine(
244
- this.canvas,
245
- this._viewerSettings.antialiasing,
246
- cloneDeep(this._viewerSettings.engineOptions),
247
- this._viewerSettings.adaptToDeviceRatio
248
- );
249
-
250
- const isScaledDownDevice = getIsScaledDownDevice(this._viewerSettings.limitTextureSize);
251
- if (this._viewerSettings.limitTextureSize && isScaledDownDevice) {
252
- engine.getCaps().maxTextureSize = this._viewerSettings.limitTextureSize.size;
253
- }
254
-
255
- if (this._viewerSettings.useParallelShaderCompile === false) {
256
- engine.getCaps().parallelShaderCompile = undefined;
257
- }
258
-
259
- this._scene = new Scene(engine);
260
-
261
- // NOTE: order of manage seems to be a bit counter intuitive as it's sorted alphabetically
262
- // semantically one would start with scene manager, etc...
263
- // still this is a good test as the order of manager constructors should not matter
264
- this._cameraManager = new CameraManager(this);
265
- this._debugManager = new DebugManager(this);
266
- this._eventManager = new EventManager(this);
267
- this._gltfExportManager = new GltfExportManager(this);
268
- this._materialManager = new MaterialManager(this);
269
- this._modelManager = new ModelManager(this);
270
- this._parameterManager = new ParameterManager(this);
271
- this._sceneManager = new SceneManager(this, defaultSceneSettings);
272
- this._textureManager = new TextureManager(this);
273
-
274
- // creates black cube
275
- // this model is not based on an URL and can be targeted by the Combeenation backend as fallback model
276
- this._modelManager.createFallbackModel();
277
-
278
- // NOTE: ATM creating the default scene required, as otherwise no camera would be available and the first render
279
- // call would already throw
280
- this._sceneManager.applyDefaultSettingsToScene();
281
-
282
- this._debugManager.registerAutofocusStartListener();
283
-
284
- engine.runRenderLoop(() => {
285
- if (!this._isRenderLoopPaused) {
286
- this.scene.render();
287
- }
288
- });
289
- }
290
- }
1
+ import buildInfo from './buildinfo.json';
2
+ import * as Index from './index';
3
+ import {
4
+ BoundingInfo,
5
+ CameraManager,
6
+ DebugManager,
7
+ DefaultSceneSettings,
8
+ Engine,
9
+ EngineOptions,
10
+ EventManager,
11
+ GltfExportManager,
12
+ MaterialManager,
13
+ ModelManager,
14
+ ParameterManager,
15
+ ParameterSubject,
16
+ Scene,
17
+ SceneManager,
18
+ TextureManager,
19
+ TransformNode,
20
+ Vector3,
21
+ } from './index';
22
+ import { registerCustomCbnBabylonLoaderPlugin } from './internal/cbn-custom-babylon-loader-plugin';
23
+ import { getIsScaledDownDevice } from './internal/device-helper';
24
+ import { isNodeExcluded } from './internal/geometry-helper';
25
+ import { cloneDeep, merge } from 'lodash-es';
26
+
27
+ /**
28
+ * Use this to define geometry to be excluded from autofocus, GLB export, etc.
29
+ */
30
+ export type ExcludedGeometry = TransformNode | ParameterSubject;
31
+ export type ExcludedGeometryList = ExcludedGeometry[];
32
+
33
+ export type LimitTextureSizeConfig = {
34
+ size: 512 | 1024;
35
+ devices: 'iPhone' | 'all';
36
+ };
37
+
38
+ export type ViewerSettings = {
39
+ antialiasing: boolean;
40
+ engineOptions: EngineOptions;
41
+ /**
42
+ * Important for visual quality on iOS devices, this setting will set the hardware scaling proportional to the devices
43
+ * pixel ratio
44
+ */
45
+ adaptToDeviceRatio: boolean;
46
+ /**
47
+ * Possibility to limit the size of textures when getting loaded by the engine.\
48
+ * Activating this feature potentially saves a lot of memory and can be used to avoid crashes when loading expensive
49
+ * models on weaker devices.\
50
+ * In praxis this has been an issue with iPhones a lot, therefore it's possible to activate this feature for iPhones
51
+ * only as well.
52
+ */
53
+ limitTextureSize: LimitTextureSizeConfig | false;
54
+ /**
55
+ * See this forum entry for description of parallel shader compilition effect:
56
+ * https://forum.babylonjs.com/t/scene-flickering-when-turning-off-light/48733.\
57
+ * Parallel shading compilition generally improves the speed of material compilition and helps when switching
58
+ * materials while objects are moving (eg: animations).\
59
+ * Deactivating parallel shading compilition is benefitial when switching lights and materials in static scenarios.\
60
+ * It's activated by default due to compatibility reasons but can be overwritten with this flag.
61
+ */
62
+ useParallelShaderCompile: boolean;
63
+ };
64
+
65
+ /**
66
+ * This is the entry point into the application.\
67
+ * Create an instance to set up the viewer on your canvas.
68
+ * ```js
69
+ * const canvas = document.getElementById('babylon-canvas');
70
+ * const viewer = Viewer(canvas, viewerSettings, defaultSceneSettings);
71
+ * ```
72
+ * Use "manager" sub classes for interacting with the Babylon.js engine.
73
+ * (e.g. `modelManager` for loading models into the scene)
74
+ */
75
+ export class Viewer {
76
+ static readonly version = buildInfo.version;
77
+
78
+ // NOTE: "non-null assertion operator" is used since these variables are not initialized in the constructor itself
79
+ // but in a help function (`_init`) inside the constructor
80
+ protected _scene!: Scene;
81
+
82
+ protected _cameraManager!: CameraManager;
83
+ protected _debugManager!: DebugManager;
84
+ protected _eventManager!: EventManager;
85
+ protected _gltfExportManager!: GltfExportManager;
86
+ protected _materialManager!: MaterialManager;
87
+ protected _modelManager!: ModelManager;
88
+ protected _parameterManager!: ParameterManager;
89
+ protected _sceneManager!: SceneManager;
90
+ protected _textureManager!: TextureManager;
91
+
92
+ // default viewer settings
93
+ // will be overwritten in the viewer constructor
94
+ protected _viewerSettings: ViewerSettings = {
95
+ antialiasing: true,
96
+ engineOptions: {
97
+ preserveDrawingBuffer: true,
98
+ stencil: true,
99
+ xrCompatible: false,
100
+ },
101
+ adaptToDeviceRatio: true,
102
+ limitTextureSize: {
103
+ devices: 'iPhone',
104
+ size: 1024,
105
+ },
106
+ useParallelShaderCompile: true,
107
+ };
108
+
109
+ protected _isRenderLoopPaused: boolean = false;
110
+
111
+ get scene(): Scene {
112
+ return this._scene;
113
+ }
114
+ get engine(): Engine {
115
+ return this.scene.getEngine();
116
+ }
117
+ get cameraManager(): CameraManager {
118
+ return this._cameraManager;
119
+ }
120
+ get debugManager(): DebugManager {
121
+ return this._debugManager;
122
+ }
123
+ get eventManager(): EventManager {
124
+ return this._eventManager;
125
+ }
126
+ get gltfExportManager(): GltfExportManager {
127
+ return this._gltfExportManager;
128
+ }
129
+ get materialManager(): MaterialManager {
130
+ return this._materialManager;
131
+ }
132
+ get modelManager(): ModelManager {
133
+ return this._modelManager;
134
+ }
135
+ get parameterManager(): ParameterManager {
136
+ return this._parameterManager;
137
+ }
138
+ /** @internal */
139
+ get sceneManager(): SceneManager {
140
+ return this._sceneManager;
141
+ }
142
+ /** @internal */
143
+ get textureManager(): TextureManager {
144
+ return this._textureManager;
145
+ }
146
+ get viewerSettings(): ViewerSettings {
147
+ return this._viewerSettings;
148
+ }
149
+
150
+ /**
151
+ * Returns all modules which are exported by the viewers index file.\
152
+ * Needed by the [Combeenation viewer control](https://docs.combeenation.com/docs/3d-viewer-control) in situations where the viewer is injected from external code.\
153
+ * See [Combeenation docs](https://docs.combeenation.com/docs/3d-viewer-control-with-custom-js) for more details.
154
+ */
155
+ public static getAllViewerModules(): typeof Index {
156
+ return Index;
157
+ }
158
+
159
+ /**
160
+ * @param viewerSettings Can be overwritten to tweak settings for the Babylon.js engine or viewer internal
161
+ * functionalities like "texture downscaling mode"
162
+ * @param defaultSceneSettings Can be overwritten to tweak settings for the automatically create Babylon.js scene.\
163
+ * This scene contains a camera and an environment per default.
164
+ */
165
+ public constructor(
166
+ public readonly canvas: HTMLCanvasElement,
167
+ viewerSettings?: DeepPartial<ViewerSettings>,
168
+ defaultSceneSettings?: DeepPartial<DefaultSceneSettings>
169
+ ) {
170
+ merge(this._viewerSettings, viewerSettings);
171
+ this._init(defaultSceneSettings);
172
+ }
173
+
174
+ /**
175
+ * Pause rendering can be usefull when doing internal scene processings that should not be visible to the user,
176
+ * e.g. cloning meshes for gltf export
177
+ */
178
+ public pauseRendering(): void {
179
+ this._isRenderLoopPaused = true;
180
+ }
181
+
182
+ /**
183
+ * Resume render loop when paused by {@link pauseRendering} function
184
+ */
185
+ public resumeRendering(): void {
186
+ this._isRenderLoopPaused = false;
187
+ }
188
+
189
+ /**
190
+ * Destroys this viewer instance and disposes Babylon.js engine and all scene content
191
+ */
192
+ public destroy(): void {
193
+ this.eventManager.removeAllListeners();
194
+ this.engine.dispose();
195
+ }
196
+
197
+ /**
198
+ * Calculates size of the current scene.\
199
+ * Only takes meshes into considerations that:
200
+ * - are visible
201
+ * - are not excluded by "excludeGeometry" parameter
202
+ * - do not have an infinite distance (like sky boxes)
203
+ */
204
+ public calculateBoundingInfo(excludeGeometry?: ExcludedGeometryList): BoundingInfo {
205
+ // CB-6062: workaround for BoundingBox not respecting render loop
206
+ this.scene.render();
207
+
208
+ const { max, min } = this.scene.meshes
209
+ .filter(mesh => {
210
+ const isEnabled = mesh.isEnabled();
211
+ // ignore meshes with invalid bounding infos
212
+ const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
213
+ // ignore meshes with infinite distance, typically these are sky boxes
214
+ const hasInfiniteDistance = mesh.infiniteDistance;
215
+ // ignore excluded meshes
216
+ const isExcluded = excludeGeometry ? isNodeExcluded(mesh, excludeGeometry) : false;
217
+ return isEnabled && hasValidBBoxInfo && !hasInfiniteDistance && !isExcluded;
218
+ })
219
+ .reduce(
220
+ (accBBoxMinMax, curMesh, idx) => {
221
+ curMesh.refreshBoundingInfo(true, true);
222
+ const bBox = curMesh.getBoundingInfo().boundingBox;
223
+ // use the first entry in the array as default value and get the resulting maximum/minimum values
224
+ const max = idx === 0 ? bBox.maximumWorld : Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
225
+ const min = idx === 0 ? bBox.minimumWorld : Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
226
+ return { max, min };
227
+ },
228
+ { max: new Vector3(), min: new Vector3() }
229
+ );
230
+
231
+ const boundingInfo = new BoundingInfo(min, max);
232
+ return boundingInfo;
233
+ }
234
+
235
+ /**
236
+ * Set up viewer (engine and scene) and initialize all managers
237
+ */
238
+ protected _init(defaultSceneSettings?: DeepPartial<DefaultSceneSettings>): void {
239
+ // we use a custom plugin for ".babylon" files to be able to lazy load materials that were cropped by the CBN
240
+ // asset manager
241
+ registerCustomCbnBabylonLoaderPlugin();
242
+
243
+ const engine = new Engine(
244
+ this.canvas,
245
+ this._viewerSettings.antialiasing,
246
+ cloneDeep(this._viewerSettings.engineOptions),
247
+ this._viewerSettings.adaptToDeviceRatio
248
+ );
249
+
250
+ const isScaledDownDevice = getIsScaledDownDevice(this._viewerSettings.limitTextureSize);
251
+ if (this._viewerSettings.limitTextureSize && isScaledDownDevice) {
252
+ engine.getCaps().maxTextureSize = this._viewerSettings.limitTextureSize.size;
253
+ }
254
+
255
+ if (this._viewerSettings.useParallelShaderCompile === false) {
256
+ engine.getCaps().parallelShaderCompile = undefined;
257
+ }
258
+
259
+ this._scene = new Scene(engine);
260
+
261
+ // NOTE: order of manage seems to be a bit counter intuitive as it's sorted alphabetically
262
+ // semantically one would start with scene manager, etc...
263
+ // still this is a good test as the order of manager constructors should not matter
264
+ this._cameraManager = new CameraManager(this);
265
+ this._debugManager = new DebugManager(this);
266
+ this._eventManager = new EventManager(this);
267
+ this._gltfExportManager = new GltfExportManager(this);
268
+ this._materialManager = new MaterialManager(this);
269
+ this._modelManager = new ModelManager(this);
270
+ this._parameterManager = new ParameterManager(this);
271
+ this._sceneManager = new SceneManager(this, defaultSceneSettings);
272
+ this._textureManager = new TextureManager(this);
273
+
274
+ // creates black cube
275
+ // this model is not based on an URL and can be targeted by the Combeenation backend as fallback model
276
+ this._modelManager.createFallbackModel();
277
+
278
+ // NOTE: ATM creating the default scene required, as otherwise no camera would be available and the first render
279
+ // call would already throw
280
+ this._sceneManager.applyDefaultSettingsToScene();
281
+
282
+ this._debugManager.registerAutofocusStartListener();
283
+
284
+ engine.runRenderLoop(() => {
285
+ if (!this._isRenderLoopPaused) {
286
+ this.scene.render();
287
+ }
288
+ });
289
+ }
290
+ }