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