@combeenation/3d-viewer 4.2.0 → 4.3.0-alpha1

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 (80) hide show
  1. package/README.md +2 -2
  2. package/dist/lib-cjs/api/classes/dottedPath.js +2 -5
  3. package/dist/lib-cjs/api/classes/dottedPath.js.map +1 -1
  4. package/dist/lib-cjs/api/classes/element.js +89 -66
  5. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  6. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  7. package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +1 -1
  8. package/dist/lib-cjs/api/classes/parameter.js +3 -2
  9. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  10. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  11. package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/placementAnimation.js +2 -2
  13. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  14. package/dist/lib-cjs/api/classes/variant.js +26 -19
  15. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  16. package/dist/lib-cjs/api/classes/variantInstance.js +19 -19
  17. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  18. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/viewer.d.ts +5 -0
  20. package/dist/lib-cjs/api/classes/viewer.js +32 -17
  21. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/viewerLight.js +24 -24
  23. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  24. package/dist/lib-cjs/api/internal/debugViewer.js +1 -2
  25. package/dist/lib-cjs/api/internal/debugViewer.js.map +1 -1
  26. package/dist/lib-cjs/api/internal/lensRendering.js.map +1 -1
  27. package/dist/lib-cjs/api/internal/sceneSetup.js +25 -22
  28. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  29. package/dist/lib-cjs/api/manager/animationManager.js +24 -15
  30. package/dist/lib-cjs/api/manager/animationManager.js.map +1 -1
  31. package/dist/lib-cjs/api/manager/sceneManager.js +3 -3
  32. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  33. package/dist/lib-cjs/api/manager/variantInstanceManager.js +10 -7
  34. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +1 -1
  35. package/dist/lib-cjs/api/store/specStorage.js.map +1 -1
  36. package/dist/lib-cjs/api/util/babylonHelper.d.ts +1 -1
  37. package/dist/lib-cjs/api/util/babylonHelper.js +12 -15
  38. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  39. package/dist/lib-cjs/api/util/globalTypes.d.ts +25 -24
  40. package/dist/lib-cjs/api/util/resourceHelper.js +3 -1
  41. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  42. package/dist/lib-cjs/api/util/stringHelper.d.ts +1 -1
  43. package/dist/lib-cjs/api/util/stringHelper.js +2 -2
  44. package/dist/lib-cjs/api/util/stringHelper.js.map +1 -1
  45. package/dist/lib-cjs/index.js.map +1 -1
  46. package/package.json +7 -3
  47. package/src/api/classes/animationInterface.ts +4 -6
  48. package/src/api/classes/dottedPath.ts +179 -187
  49. package/src/api/classes/element.ts +644 -621
  50. package/src/api/classes/event.ts +310 -313
  51. package/src/api/classes/eventBroadcaster.ts +47 -49
  52. package/src/api/classes/parameter.ts +394 -397
  53. package/src/api/classes/parameterObservable.ts +84 -83
  54. package/src/api/classes/parameterizable.ts +71 -73
  55. package/src/api/classes/placementAnimation.ts +130 -130
  56. package/src/api/classes/variant.ts +806 -778
  57. package/src/api/classes/variantInstance.ts +60 -52
  58. package/src/api/classes/variantParameterizable.ts +72 -67
  59. package/src/api/classes/viewer.ts +531 -489
  60. package/src/api/classes/viewerLight.ts +300 -300
  61. package/src/api/internal/debugViewer.ts +61 -53
  62. package/src/api/internal/lensRendering.ts +2 -3
  63. package/src/api/internal/sceneSetup.ts +144 -137
  64. package/src/api/manager/animationManager.ts +122 -97
  65. package/src/api/manager/sceneManager.ts +83 -86
  66. package/src/api/manager/variantInstanceManager.ts +234 -224
  67. package/src/api/store/specStorage.ts +48 -51
  68. package/src/api/util/babylonHelper.ts +329 -325
  69. package/src/api/util/globalTypes.ts +244 -245
  70. package/src/api/util/resourceHelper.ts +97 -109
  71. package/src/api/util/stringHelper.ts +13 -16
  72. package/src/buildinfo.json +2 -2
  73. package/src/commonjs.tsconfig.json +8 -11
  74. package/src/declaration.tsconfig.json +6 -8
  75. package/src/dev.ts +28 -28
  76. package/src/es6.tsconfig.json +8 -11
  77. package/src/index.ts +39 -39
  78. package/src/tsconfig.json +30 -41
  79. package/src/tsconfig.types.json +8 -9
  80. package/src/types.d.ts +0 -1
@@ -24,7 +24,6 @@ import { Parameter } from './parameter';
24
24
  import { Variant } from './variant';
25
25
  import { VariantInstance } from './variantInstance';
26
26
 
27
-
28
27
  /**
29
28
  * The main exposed object. This is the entry point into the application
30
29
  *
@@ -35,491 +34,534 @@ import { VariantInstance } from './variantInstance';
35
34
  * The class does nothing on its own and needs to {@link bootstrap}
36
35
  */
37
36
  export class Viewer extends EventBroadcaster {
38
-
39
- protected _scene: Scene | null = null;
40
-
41
- protected _animationManager: AnimationManager | null = null;
42
-
43
- protected _sceneManager: SceneManager | null = null;
44
-
45
- protected _variantInstances: VariantInstanceManager | null = null;
46
-
47
- static version = version;
48
-
49
- /**
50
- * Constructor
51
- */
52
- public constructor( public readonly canvas: HTMLCanvasElement, protected structureJson: string | StructureJson ) {
53
- super();
54
- }
55
-
56
- /**
57
- * Gets the BabylonJS Scene that is attached to the instance.
58
- *
59
- * @throws Error if the `scene` has not been initialized.
60
- */
61
- get scene(): Scene {
62
- if( !this._scene ) {
63
- throw new Error( `Scene has not been initialized.` );
64
- }
65
- return this._scene;
66
- }
67
-
68
- get sceneManager(): SceneManager {
69
- if( !this._sceneManager ) {
70
- throw new Error( `Environment has not been initialized.` );
71
- }
72
- return this._sceneManager;
73
- }
74
-
75
- /**
76
- * Gets the BabylonJS Engine that is attached to the viewer.
77
- */
78
- get engine(): Engine {
79
- return this.scene.getEngine();
80
- }
81
-
82
- /**
83
- * Gets the {@link VariantInstanceManager} attached to the viewer.
84
- *
85
- * @throws Error if the {@link VariantInstanceManager} has not been initialized.
86
- */
87
- get variantInstances(): VariantInstanceManager {
88
- if( !this._variantInstances ) {
89
- throw Error( `There is no variantInstanceManager.` );
90
- }
91
- return this._variantInstances;
92
- }
93
-
94
- /**
95
- * Gets the {@link AnimationManager} attached to the viewer.
96
- *
97
- * @throws Error if the {@link AnimationManager} has not been initialized.
98
- */
99
- get animationManager(): AnimationManager {
100
- if( !this._animationManager ) {
101
- throw new Error( `There is no animationManager instance.` );
102
- }
103
- return this._animationManager;
104
- }
105
-
106
- /**
107
- * Starts the application. This will
108
- * * load the given "index" JSON file
109
- * * setup the scene with the "scene" JSON file
110
- * * create an (optional) default setup with different variant settings
111
- * * sets up resizing by attaching a debounced version of {@link resize}
112
- *
113
- * @throws Error if any of the files is not found/valid
114
- *
115
- * @emits {@link Event.BOOTSTRAP_START}
116
- * @emits {@link Event.BOOTSTRAP_END}
117
- */
118
- public async bootstrap(): Promise<Viewer> {
119
- this.broadcastEvent( Event.BOOTSTRAP_START, this );
120
- let indexJson;
121
- if( isString( this.structureJson ) ) {
122
- indexJson = await loadJson<StructureJson>( this.structureJson );
123
- } else {
124
- indexJson = this.structureJson;
125
- }
126
- if( !indexJson.scene ) {
127
- throw new Error( `No "scene" property found for bootstrapping.` );
128
- }
129
- // fill spec store
130
- SpecStorage.createFromSpec( indexJson );
131
- // load scene
132
- if( isString( indexJson.scene ) ) {
133
- const sceneJson = await loadJson<SceneJson>( indexJson.scene );
134
- indexJson.scene = sceneJson;
135
- }
136
- this._scene = await this.initScene();
137
- // create instance manager
138
- const rootVariant = await Variant.create( '_', indexJson, this );
139
- this._variantInstances = await VariantInstanceManager.create( rootVariant );
140
- // create optional default instances
141
- if( indexJson.setup ) {
142
- if( isString( indexJson.setup ) ) {
143
- const setupJson = await loadJson<SetupJson>( indexJson.setup );
144
- indexJson.setup = setupJson;
145
- }
146
- await this.createVariantInstances();
147
- }
148
- // resize handler
149
- window.addEventListener( 'resize', debounce( this.resize.bind( this ), 100 ) );
150
- // wait until scene is completely ready
151
- await this.scene.whenReadyAsync();
152
- // event broadcasting
153
- this.broadcastEvent( Event.BOOTSTRAP_END, this );
154
- // render loop
155
- this.engine.runRenderLoop( () => {
156
- this.scene.render();
157
- } );
158
- return this;
159
- }
160
-
161
- // Disabled for now to decrease bundle size.
162
- // See https://github.com/Combeenation/3d-viewer/issues/37
163
- // /**
164
- // * Enables the BabylonJS DebugLayer. If you pass options, be sure to pass an Object of type `IInspectorOptions`.
165
- // */
166
- // public async enableDebugLayer(options?: any) {
167
- // // @ts-ignore
168
- // await import(/* webpackChunkName: "debug-inspector" */'@babylonjs/inspector');
169
- // await this.scene.debugLayer.show(options);
170
- // return this;
171
- // }
172
-
173
- /**
174
- * Destroys all registered {@link VariantInstance}s that are registered
175
- */
176
- public destroyVariantInstances(): Viewer {
177
- this.variantInstances.all.forEach( variantInstance => {
178
- this.variantInstances.destroy( variantInstance.name );
179
- } );
180
- return this;
181
- }
182
-
183
- /**
184
- * Trigger a resize event for the `Engine`
185
- */
186
- public resize(): Viewer {
187
- this.engine.resize();
188
- return this;
189
- }
190
-
191
- /**
192
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
193
- * {@link DottedPath}s.
194
- */
195
- public async getNode( variantInstanceName: string,
196
- elementDottedPath: DottedPathArgument,
197
- nodeDottedPath: DottedPathArgument ): Promise<TransformNode> {
198
- const variantInstance = await this.variantInstances.get(variantInstanceName);
199
- return variantInstance.getNode( elementDottedPath, nodeDottedPath );
200
- }
201
-
202
- /**
203
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
204
- * {@link DottedPath}s.
205
- */
206
- public async getMesh( variantInstanceName: string,
207
- elementDottedPath: DottedPathArgument,
208
- meshDottedPath: DottedPathArgument ): Promise<Mesh|null> {
209
- const variantInstance = await this.variantInstances.get(variantInstanceName);
210
- return variantInstance.getMesh( elementDottedPath, meshDottedPath );
211
- }
212
-
213
- /**
214
- * Switches the camera
215
- *
216
- * @emits {@link Event.CAMERA_SWITCHED}
217
- */
218
- public switchCamera( newCamera: string, reset: boolean = true ): Viewer {
219
- const camera = this.scene.getCameraByName( newCamera );
220
- if( camera ) {
221
- const activeCamera = this.scene.activeCamera;
222
- if( activeCamera ) {
223
- activeCamera.detachControl( this.engine.getRenderingCanvas()! );
224
- }
225
- if( reset ) {
226
- camera.restoreState();
227
- }
228
- this.scene.setActiveCameraByName( newCamera );
229
- camera.attachControl( this.engine.getRenderingCanvas()! );
230
- this.broadcastEvent( Event.CAMERA_SWITCHED, camera );
231
- } else {
232
- throw new Error( `Given camera "${newCamera}" not found.` );
233
- }
234
- // TODO: put traceable observers to new camera (@see element)
235
- return this;
236
- }
237
-
238
- /**
239
- * Moves or animates the active camera to given `placement`.
240
- */
241
- public async moveActiveCameraTo( placement: string | PlacementDefinition,
242
- animation?: string | AnimationDefinition ): Promise<AnimationInterface> {
243
- return this.animationManager.animateToPlacement( this.sceneManager.activeCamera, placement, animation );
244
- }
245
-
246
- /**
247
- * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
248
- */
249
- public screenshot( settings?: ScreenshotSettings ): Promise<string> {
250
- return new Promise( ( resolve, reject ) => {
251
- if( !this.engine ) {
252
- return reject( 'Engine is null' );
253
- }
254
- if( !this.scene ) {
255
- return reject( 'Scene is null' );
256
- }
257
- this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
258
- ScreenshotTools.CreateScreenshotUsingRenderTarget(
259
- this.engine,
260
- this.sceneManager.activeCamera,
261
- settings?.size ?? { width: this.canvas.clientWidth, height: this.canvas.clientHeight },
262
- resolve,
263
- settings?.mimeType ?? 'image/png',
264
- settings?.samples ?? 1,
265
- settings?.antialiasing ?? false,
266
- settings?.fileName ?? 'screenshot.png',
267
- settings?.renderSprites ?? false
268
- );
269
- } );
270
- }
271
-
272
- /**
273
- * Calculates the bounding box from all visible meshes on the scene.
274
- */
275
- public async calculateBoundingBox(): Promise<Mesh> {
276
- if( this.scene.meshes.length === 0 ) {
277
- throw new Error( 'There are currently no meshes on the scene.' );
278
- }
279
- this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
280
- const bbName = '__bounding_box__';
281
-
282
- const { max, min } = this.scene.meshes.filter( mesh => {
283
- const isEnabled = mesh.isEnabled();
284
- // ignore the existing bounding box mesh for calculating the current one
285
- const isNotBBoxMesh = bbName !== mesh.id;
286
- // ignore meshes with invalid bounding infos
287
- const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
288
- return isEnabled && isNotBBoxMesh && hasValidBBoxInfo;
289
- } ).reduce( ( accBBoxMinMax, curMesh, idx ) => {
290
- const bBox = curMesh.getBoundingInfo().boundingBox;
291
- // use the first entry in the array as default value and get the resulting maximum/minimum values
292
- const max = ( idx === 0 ) ? bBox.maximumWorld : Vector3.Maximize( accBBoxMinMax.max, bBox.maximumWorld )
293
- const min = ( idx === 0 ) ? bBox.minimumWorld : Vector3.Minimize( accBBoxMinMax.min, bBox.minimumWorld )
294
- return { max, min }
295
- }, { max: new Vector3(), min: new Vector3() } );
296
-
297
- let boundingBox = this.scene.getMeshByName( bbName ) as Mesh;
298
- if( !boundingBox ) {
299
- boundingBox = new Mesh( bbName, this.scene );
300
- }
301
- boundingBox.setBoundingInfo( new BoundingInfo( min, max ) );
302
- return boundingBox;
303
- }
304
-
305
- public async autofocusActiveCamera( settings?: AutofocusSettings ) {
306
- // first check some preconditions
307
- const activeCamera = this.scene.activeCamera;
308
- if ( !activeCamera ) {
309
- throw new Error("No active camera found when using autofocus feature.");
310
- }
311
- if ( !( activeCamera instanceof ArcRotateCamera ) ) {
312
- const cameraClsName = activeCamera.getClassName();
313
- throw new Error( `Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.` );
314
- }
315
-
316
- // get bounding box of all visible meshes, this is the base for the autofocus algorithm
317
- const boundingBox = await this.calculateBoundingBox();
318
-
319
- // focus the helper camera and set the calculated camera data to the real camera
320
- const helperCamera = this.getFocusedHelperCamera( boundingBox, settings )
321
- await this.applyFocusedHelperCameraData( activeCamera, helperCamera, settings )
322
-
323
- // remove the helper camera
324
- helperCamera.dispose();
325
- }
326
-
327
- /**
328
- * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
329
- * environment
330
- */
331
- public async reset(): Promise<Viewer> {
332
- await this.destroy();
333
- return this.bootstrap();
334
- }
335
-
336
- /**
337
- * Destroys
338
- *
339
- * * all {@link VariantInstance}s using {@link destroyVariantInstances}
340
- * * calling `dispose` on the `Engine` and `Scene`
341
- */
342
- public destroy(): Viewer {
343
- this.destroyVariantInstances();
344
- this.scene.dispose();
345
- SpecStorage.destroy();
346
- return this;
347
- }
348
-
349
- /**
350
- * Show coordinate system with given dimension (for debugging purpose).
351
- */
352
- public showWorldCoordinates( dimension: number ) {
353
- const scene = this.scene;
354
- const makeTextPlane = function( text: string, color: string, size: number ) {
355
- const dynamicTexture = new DynamicTexture( 'DynamicTexture', 50, scene, true );
356
- dynamicTexture.hasAlpha = true;
357
- dynamicTexture.drawText( text, 5, 40, 'bold 36px Arial', color, 'transparent', true );
358
- const plane = Mesh.CreatePlane( 'TextPlane', size, scene, true );
359
- plane.material = new StandardMaterial( 'TextPlaneMaterial', scene );
360
- plane.material.backFaceCulling = false;
361
- // @ts-ignore
362
- plane.material.specularColor = new Color3( 0, 0, 0 );
363
- // @ts-ignore
364
- plane.material.diffuseTexture = dynamicTexture;
365
- return plane;
366
- };
367
- const axisX = Mesh.CreateLines( 'axisX', [
368
- Vector3.Zero(),
369
- new Vector3( dimension, 0, 0 ),
370
- new Vector3( dimension * 0.95, 0.05 * dimension, 0 ),
371
- new Vector3( dimension, 0, 0 ),
372
- new Vector3( dimension * 0.95, -0.05 * dimension, 0 )
373
- ], scene );
374
- axisX.color = new Color3( 1, 0, 0 );
375
- const xChar = makeTextPlane( 'X', 'red', dimension / 10 );
376
- xChar.position = new Vector3( 0.9 * dimension, -0.05 * dimension, 0 );
377
- const axisY = Mesh.CreateLines( 'axisY', [
378
- Vector3.Zero(),
379
- new Vector3( 0, dimension, 0 ),
380
- new Vector3( -0.05 * dimension, dimension * 0.95, 0 ),
381
- new Vector3( 0, dimension, 0 ),
382
- new Vector3( 0.05 * dimension, dimension * 0.95, 0 )
383
- ], scene );
384
- axisY.color = new Color3( 0, 1, 0 );
385
- const yChar = makeTextPlane( 'Y', 'green', dimension / 10 );
386
- yChar.position = new Vector3( 0, 0.9 * dimension, -0.05 * dimension );
387
- const axisZ = Mesh.CreateLines( 'axisZ', [
388
- Vector3.Zero(),
389
- new Vector3( 0, 0, dimension ),
390
- new Vector3( 0, -0.05 * dimension, dimension * 0.95 ),
391
- new Vector3( 0, 0, dimension ),
392
- new Vector3( 0, 0.05 * dimension, dimension * 0.95 )
393
- ], scene );
394
- axisZ.color = new Color3( 0, 0, 1 );
395
- const zChar = makeTextPlane( 'Z', 'blue', dimension / 10 );
396
- zChar.position = new Vector3( 0, 0.05 * dimension, 0.9 * dimension );
397
- }
398
-
399
- /**
400
- * @emits {@link Event.SCENE_PROCESSING_START}
401
- * @emits {@link Event.SCENE_PROCESSING_END}
402
- */
403
- protected async initScene(): Promise<Scene> {
404
- const sceneJson = SpecStorage.get<SceneJson>( 'scene' );
405
- this.broadcastEvent( Event.SCENE_PROCESSING_START, sceneJson );
406
- const engine = new Engine(
407
- this.canvas as HTMLCanvasElement,
408
- sceneJson.engine?.antialiasing ?? false,
409
- sceneJson.engine?.options
410
- );
411
- const scene = await sceneSetup( engine, sceneJson );
412
- if( sceneJson.meshPicking ) {
413
- new HighlightLayer( 'default', scene );
414
- scene.onPointerPick = ( pointerEvent: PointerEvent, pickInfo: PickingInfo ) => {
415
- if( !pickInfo.hit ) {
416
- return;
417
- }
418
- const mesh = pickInfo.pickedMesh;
419
- this.broadcastEvent( Event.MESH_PICKED, mesh, mesh?.metadata.element, mesh?.metadata.variant );
420
- if( mesh?.metadata.element ) {
421
- this.broadcastEvent( Event.ELEMENT_PICKED, mesh.metadata.element );
422
- }
423
- if( mesh?.metadata.variant ) {
424
- if( mesh.metadata.variant.inheritedParameters[Parameter.HIGHLIGHT_ENABLED] ) {
425
- mesh.metadata.variant.toggleHighlight();
426
- }
427
- this.broadcastEvent( Event.VARIANT_PICKED, mesh.metadata.variant );
428
- }
429
- };
430
- }
431
- this._sceneManager = await SceneManager.create( scene );
432
- this._animationManager = await AnimationManager.create( scene );
433
- this.broadcastEvent( Event.SCENE_PROCESSING_END, scene );
434
- return scene;
435
- }
436
-
437
- /**
438
- * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
439
- */
440
- protected async createVariantInstances(): Promise<VariantInstance[]> {
441
- const setupJson = SpecStorage.get<SetupJson>( 'setup' );
442
- const instances = [];
443
- for( const instanceDefinition of setupJson.instances ) {
444
- if( instanceDefinition.lazy ) {
445
- this.variantInstances.register( instanceDefinition );
446
- continue;
447
- }
448
- instances.push( await this.variantInstances.create(
449
- instanceDefinition.variant,
450
- instanceDefinition.name,
451
- instanceDefinition.parameters
452
- ) );
453
- }
454
- return instances;
455
- }
456
-
457
- /**
458
- * Help function for focusing a helper camera exactly onto the given bounding box
459
- */
460
- private getFocusedHelperCamera(boundingBox: Mesh, settings?: AutofocusSettings): ArcRotateCamera {
461
- // use helper camera to get some default values and set the values of the real camera accordingly
462
- const helperCamera = new ArcRotateCamera(
463
- "__helper_camera__",
464
- 0, // camera angles will be overwritten after the target has been set
465
- 0,
466
- 0, // radius will be calculated, so we can set to 0 here
467
- Vector3.Zero(),
468
- this.scene
469
- );
470
- // this is required for automatically calculating the `lowerRadiusLimit`, so that we don't "dive" into meshes
471
- // see https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior
472
- helperCamera.useFramingBehavior = true;
473
-
474
- // `minZ` is the camera distance beyond which the mesh will be clipped
475
- // this should be very low, but can't be zero
476
- // a good value seems to be 1% of the bounding box size (= radius), whereas the value shouldn't go above 1, which is also the default value
477
- const radius = boundingBox.getBoundingInfo().boundingSphere.radius;
478
- helperCamera.minZ = Math.min(radius/100, 1);
479
-
480
- // set desired camera data, these won't be changed by the autofocus function!
481
- // default values should focus the element exactly from the front (= XY Plane)
482
- helperCamera.setTarget(boundingBox, true);
483
- helperCamera.alpha = ( settings?.alpha ?? - 90 ) * ( Math.PI / 180 );
484
- helperCamera.beta = ( settings?.beta ?? 90 ) * ( Math.PI / 180 );
485
-
486
- // finally zoom to the bounding box
487
- // also apply a zoom factor, this adjusts the borders around the model in the viewport
488
- helperCamera.zoomOnFactor = settings?.radiusFactor || 1;
489
- helperCamera.zoomOn( [boundingBox], true );
490
-
491
- return helperCamera;
492
- }
493
-
494
- /**
495
- * Help function for applying the relevant data of the focused helper camera to the real camera
496
- */
497
- private async applyFocusedHelperCameraData(activeCamera: ArcRotateCamera, helperCamera: ArcRotateCamera, settings?: AutofocusSettings) {
498
- // limits
499
- activeCamera.minZ = helperCamera.minZ;
500
- activeCamera.maxZ = helperCamera.maxZ;
501
- activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
502
- activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
503
-
504
- // additional settings
505
- if( settings?.adjustWheelPrecision !== false ) {
506
- activeCamera.wheelPrecision = helperCamera.wheelPrecision;
507
- }
508
- if( settings?.adjustPanningSensibility !== false ) {
509
- activeCamera.panningSensibility = helperCamera.panningSensibility;
510
- }
511
- if( settings?.adjustPinchPrecision !== false ) {
512
- activeCamera.pinchPrecision = helperCamera.pinchPrecision;
513
- }
514
-
515
- // finally move the camera
516
- // do this at last, so that all camera settings are already considered
517
- const newCameraPosition: PlacementDefinition = {
518
- alpha: helperCamera.alpha,
519
- beta: helperCamera.beta,
520
- radius: helperCamera.radius,
521
- target: helperCamera.target
522
- }
523
- await this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings?.animation)
524
- }
525
- }
37
+ protected _scene: Scene | null = null;
38
+
39
+ protected _animationManager: AnimationManager | null = null;
40
+
41
+ protected _sceneManager: SceneManager | null = null;
42
+
43
+ protected _variantInstances: VariantInstanceManager | null = null;
44
+
45
+ protected _deactivateMaterialCloning: boolean = false;
46
+
47
+ static version = version;
48
+
49
+ /**
50
+ * Constructor
51
+ */
52
+ public constructor(public readonly canvas: HTMLCanvasElement, protected structureJson: string | StructureJson) {
53
+ super();
54
+ }
55
+
56
+ /**
57
+ * Gets the BabylonJS Scene that is attached to the instance.
58
+ *
59
+ * @throws Error if the `scene` has not been initialized.
60
+ */
61
+ get scene(): Scene {
62
+ if (!this._scene) {
63
+ throw new Error(`Scene has not been initialized.`);
64
+ }
65
+ return this._scene;
66
+ }
67
+
68
+ get sceneManager(): SceneManager {
69
+ if (!this._sceneManager) {
70
+ throw new Error(`Environment has not been initialized.`);
71
+ }
72
+ return this._sceneManager;
73
+ }
74
+
75
+ /**
76
+ * Gets the BabylonJS Engine that is attached to the viewer.
77
+ */
78
+ get engine(): Engine {
79
+ return this.scene.getEngine();
80
+ }
81
+
82
+ /**
83
+ * Gets the {@link VariantInstanceManager} attached to the viewer.
84
+ *
85
+ * @throws Error if the {@link VariantInstanceManager} has not been initialized.
86
+ */
87
+ get variantInstances(): VariantInstanceManager {
88
+ if (!this._variantInstances) {
89
+ throw Error(`There is no variantInstanceManager.`);
90
+ }
91
+ return this._variantInstances;
92
+ }
93
+
94
+ /**
95
+ * Gets the {@link AnimationManager} attached to the viewer.
96
+ *
97
+ * @throws Error if the {@link AnimationManager} has not been initialized.
98
+ */
99
+ get animationManager(): AnimationManager {
100
+ if (!this._animationManager) {
101
+ throw new Error(`There is no animationManager instance.`);
102
+ }
103
+ return this._animationManager;
104
+ }
105
+
106
+ /**
107
+ * Gets the `deactivateMaterialCloning` flag, as defined in the spec
108
+ */
109
+ get deactivateMaterialCloning(): boolean {
110
+ return this._deactivateMaterialCloning;
111
+ }
112
+
113
+ /**
114
+ * Starts the application. This will
115
+ * * load the given "index" JSON file
116
+ * * setup the scene with the "scene" JSON file
117
+ * * create an (optional) default setup with different variant settings
118
+ * * sets up resizing by attaching a debounced version of {@link resize}
119
+ *
120
+ * @throws Error if any of the files is not found/valid
121
+ *
122
+ * @emits {@link Event.BOOTSTRAP_START}
123
+ * @emits {@link Event.BOOTSTRAP_END}
124
+ */
125
+ public async bootstrap(): Promise<Viewer> {
126
+ this.broadcastEvent(Event.BOOTSTRAP_START, this);
127
+ let indexJson;
128
+ if (isString(this.structureJson)) {
129
+ indexJson = await loadJson<StructureJson>(this.structureJson);
130
+ } else {
131
+ indexJson = this.structureJson;
132
+ }
133
+ if (!indexJson.scene) {
134
+ throw new Error(`No "scene" property found for bootstrapping.`);
135
+ }
136
+ // fill spec store
137
+ SpecStorage.createFromSpec(indexJson);
138
+ // load scene
139
+ if (isString(indexJson.scene)) {
140
+ const sceneJson = await loadJson<SceneJson>(indexJson.scene);
141
+ indexJson.scene = sceneJson;
142
+ }
143
+ this._scene = await this.initScene();
144
+ // create instance manager
145
+ const rootVariant = await Variant.create('_', indexJson, this);
146
+ this._variantInstances = await VariantInstanceManager.create(rootVariant);
147
+ // create optional default instances
148
+ if (indexJson.setup) {
149
+ if (isString(indexJson.setup)) {
150
+ const setupJson = await loadJson<SetupJson>(indexJson.setup);
151
+ indexJson.setup = setupJson;
152
+ }
153
+ await this.createVariantInstances();
154
+ }
155
+ // resize handler
156
+ window.addEventListener('resize', debounce(this.resize.bind(this), 100));
157
+ // wait until scene is completely ready
158
+ await this.scene.whenReadyAsync();
159
+ // event broadcasting
160
+ this.broadcastEvent(Event.BOOTSTRAP_END, this);
161
+ // render loop
162
+ this.engine.runRenderLoop(() => {
163
+ this.scene.render();
164
+ });
165
+ return this;
166
+ }
167
+
168
+ // Disabled for now to decrease bundle size.
169
+ // See https://github.com/Combeenation/3d-viewer/issues/37
170
+ // /**
171
+ // * Enables the BabylonJS DebugLayer. If you pass options, be sure to pass an Object of type `IInspectorOptions`.
172
+ // */
173
+ // public async enableDebugLayer(options?: any) {
174
+ // // @ts-ignore
175
+ // await import(/* webpackChunkName: "debug-inspector" */ '@babylonjs/inspector');
176
+ // await this.scene.debugLayer.show(options);
177
+ // return this;
178
+ // }
179
+
180
+ /**
181
+ * Destroys all registered {@link VariantInstance}s that are registered
182
+ */
183
+ public destroyVariantInstances(): Viewer {
184
+ this.variantInstances.all.forEach(variantInstance => {
185
+ this.variantInstances.destroy(variantInstance.name);
186
+ });
187
+ return this;
188
+ }
189
+
190
+ /**
191
+ * Trigger a resize event for the `Engine`
192
+ */
193
+ public resize(): Viewer {
194
+ this.engine.resize();
195
+ return this;
196
+ }
197
+
198
+ /**
199
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
200
+ * {@link DottedPath}s.
201
+ */
202
+ public async getNode(
203
+ variantInstanceName: string,
204
+ elementDottedPath: DottedPathArgument,
205
+ nodeDottedPath: DottedPathArgument
206
+ ): Promise<TransformNode> {
207
+ const variantInstance = await this.variantInstances.get(variantInstanceName);
208
+ return variantInstance.getNode(elementDottedPath, nodeDottedPath);
209
+ }
210
+
211
+ /**
212
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
213
+ * {@link DottedPath}s.
214
+ */
215
+ public async getMesh(
216
+ variantInstanceName: string,
217
+ elementDottedPath: DottedPathArgument,
218
+ meshDottedPath: DottedPathArgument
219
+ ): Promise<Mesh | null> {
220
+ const variantInstance = await this.variantInstances.get(variantInstanceName);
221
+ return variantInstance.getMesh(elementDottedPath, meshDottedPath);
222
+ }
223
+
224
+ /**
225
+ * Switches the camera
226
+ *
227
+ * @emits {@link Event.CAMERA_SWITCHED}
228
+ */
229
+ public switchCamera(newCamera: string, reset: boolean = true): Viewer {
230
+ const camera = this.scene.getCameraByName(newCamera);
231
+ if (camera) {
232
+ const activeCamera = this.scene.activeCamera;
233
+ if (activeCamera) {
234
+ activeCamera.detachControl(this.engine.getRenderingCanvas()!);
235
+ }
236
+ if (reset) {
237
+ camera.restoreState();
238
+ }
239
+ this.scene.setActiveCameraByName(newCamera);
240
+ camera.attachControl(this.engine.getRenderingCanvas()!);
241
+ this.broadcastEvent(Event.CAMERA_SWITCHED, camera);
242
+ } else {
243
+ throw new Error(`Given camera "${newCamera}" not found.`);
244
+ }
245
+ // TODO: put traceable observers to new camera (@see element)
246
+ return this;
247
+ }
248
+
249
+ /**
250
+ * Moves or animates the active camera to given `placement`.
251
+ */
252
+ public async moveActiveCameraTo(
253
+ placement: string | PlacementDefinition,
254
+ animation?: string | AnimationDefinition
255
+ ): Promise<AnimationInterface> {
256
+ return this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation);
257
+ }
258
+
259
+ /**
260
+ * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
261
+ */
262
+ public screenshot(settings?: ScreenshotSettings): Promise<string> {
263
+ return new Promise((resolve, reject) => {
264
+ if (!this.engine) {
265
+ return reject('Engine is null');
266
+ }
267
+ if (!this.scene) {
268
+ return reject('Scene is null');
269
+ }
270
+ this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
271
+ ScreenshotTools.CreateScreenshotUsingRenderTarget(
272
+ this.engine,
273
+ this.sceneManager.activeCamera,
274
+ settings?.size ?? { width: this.canvas.clientWidth, height: this.canvas.clientHeight },
275
+ resolve,
276
+ settings?.mimeType ?? 'image/png',
277
+ settings?.samples ?? 1,
278
+ settings?.antialiasing ?? false,
279
+ settings?.fileName ?? 'screenshot.png',
280
+ settings?.renderSprites ?? false
281
+ );
282
+ });
283
+ }
284
+
285
+ /**
286
+ * Calculates the bounding box from all visible meshes on the scene.
287
+ */
288
+ public async calculateBoundingBox(): Promise<Mesh> {
289
+ if (this.scene.meshes.length === 0) {
290
+ throw new Error('There are currently no meshes on the scene.');
291
+ }
292
+ this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
293
+ const bbName = '__bounding_box__';
294
+
295
+ const { max, min } = this.scene.meshes
296
+ .filter(mesh => {
297
+ const isEnabled = mesh.isEnabled();
298
+ // ignore the existing bounding box mesh for calculating the current one
299
+ const isNotBBoxMesh = bbName !== mesh.id;
300
+ // ignore meshes with invalid bounding infos
301
+ const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
302
+ return isEnabled && isNotBBoxMesh && hasValidBBoxInfo;
303
+ })
304
+ .reduce(
305
+ (accBBoxMinMax, curMesh, idx) => {
306
+ const bBox = curMesh.getBoundingInfo().boundingBox;
307
+ // use the first entry in the array as default value and get the resulting maximum/minimum values
308
+ const max = idx === 0 ? bBox.maximumWorld : Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
309
+ const min = idx === 0 ? bBox.minimumWorld : Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
310
+ return { max, min };
311
+ },
312
+ { max: new Vector3(), min: new Vector3() }
313
+ );
314
+
315
+ let boundingBox = this.scene.getMeshByName(bbName) as Mesh;
316
+ if (!boundingBox) {
317
+ boundingBox = new Mesh(bbName, this.scene);
318
+ }
319
+ boundingBox.setBoundingInfo(new BoundingInfo(min, max));
320
+ return boundingBox;
321
+ }
322
+
323
+ public async autofocusActiveCamera(settings?: AutofocusSettings) {
324
+ // first check some preconditions
325
+ const activeCamera = this.scene.activeCamera;
326
+ if (!activeCamera) {
327
+ throw new Error('No active camera found when using autofocus feature.');
328
+ }
329
+ if (!(activeCamera instanceof ArcRotateCamera)) {
330
+ const cameraClsName = activeCamera.getClassName();
331
+ throw new Error(`Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.`);
332
+ }
333
+
334
+ // get bounding box of all visible meshes, this is the base for the autofocus algorithm
335
+ const boundingBox = await this.calculateBoundingBox();
336
+
337
+ // focus the helper camera and set the calculated camera data to the real camera
338
+ const helperCamera = this.getFocusedHelperCamera(boundingBox, settings);
339
+ await this.applyFocusedHelperCameraData(activeCamera, helperCamera, settings);
340
+
341
+ // remove the helper camera
342
+ helperCamera.dispose();
343
+ }
344
+
345
+ /**
346
+ * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
347
+ * environment
348
+ */
349
+ public async reset(): Promise<Viewer> {
350
+ await this.destroy();
351
+ return this.bootstrap();
352
+ }
353
+
354
+ /**
355
+ * Destroys
356
+ *
357
+ * * all {@link VariantInstance}s using {@link destroyVariantInstances}
358
+ * * calling `dispose` on the `Engine` and `Scene`
359
+ */
360
+ public destroy(): Viewer {
361
+ this.destroyVariantInstances();
362
+ this.scene.dispose();
363
+ SpecStorage.destroy();
364
+ return this;
365
+ }
366
+
367
+ /**
368
+ * Show coordinate system with given dimension (for debugging purpose).
369
+ */
370
+ public showWorldCoordinates(dimension: number) {
371
+ const scene = this.scene;
372
+ const makeTextPlane = function (text: string, color: string, size: number) {
373
+ const dynamicTexture = new DynamicTexture('DynamicTexture', 50, scene, true);
374
+ dynamicTexture.hasAlpha = true;
375
+ dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
376
+ const plane = Mesh.CreatePlane('TextPlane', size, scene, true);
377
+ plane.material = new StandardMaterial('TextPlaneMaterial', scene);
378
+ plane.material.backFaceCulling = false;
379
+ // @ts-ignore
380
+ plane.material.specularColor = new Color3(0, 0, 0);
381
+ // @ts-ignore
382
+ plane.material.diffuseTexture = dynamicTexture;
383
+ return plane;
384
+ };
385
+ const axisX = Mesh.CreateLines(
386
+ 'axisX',
387
+ [
388
+ Vector3.Zero(),
389
+ new Vector3(dimension, 0, 0),
390
+ new Vector3(dimension * 0.95, 0.05 * dimension, 0),
391
+ new Vector3(dimension, 0, 0),
392
+ new Vector3(dimension * 0.95, -0.05 * dimension, 0),
393
+ ],
394
+ scene
395
+ );
396
+ axisX.color = new Color3(1, 0, 0);
397
+ const xChar = makeTextPlane('X', 'red', dimension / 10);
398
+ xChar.position = new Vector3(0.9 * dimension, -0.05 * dimension, 0);
399
+ const axisY = Mesh.CreateLines(
400
+ 'axisY',
401
+ [
402
+ Vector3.Zero(),
403
+ new Vector3(0, dimension, 0),
404
+ new Vector3(-0.05 * dimension, dimension * 0.95, 0),
405
+ new Vector3(0, dimension, 0),
406
+ new Vector3(0.05 * dimension, dimension * 0.95, 0),
407
+ ],
408
+ scene
409
+ );
410
+ axisY.color = new Color3(0, 1, 0);
411
+ const yChar = makeTextPlane('Y', 'green', dimension / 10);
412
+ yChar.position = new Vector3(0, 0.9 * dimension, -0.05 * dimension);
413
+ const axisZ = Mesh.CreateLines(
414
+ 'axisZ',
415
+ [
416
+ Vector3.Zero(),
417
+ new Vector3(0, 0, dimension),
418
+ new Vector3(0, -0.05 * dimension, dimension * 0.95),
419
+ new Vector3(0, 0, dimension),
420
+ new Vector3(0, 0.05 * dimension, dimension * 0.95),
421
+ ],
422
+ scene
423
+ );
424
+ axisZ.color = new Color3(0, 0, 1);
425
+ const zChar = makeTextPlane('Z', 'blue', dimension / 10);
426
+ zChar.position = new Vector3(0, 0.05 * dimension, 0.9 * dimension);
427
+ }
428
+
429
+ /**
430
+ * @emits {@link Event.SCENE_PROCESSING_START}
431
+ * @emits {@link Event.SCENE_PROCESSING_END}
432
+ */
433
+ protected async initScene(): Promise<Scene> {
434
+ const sceneJson = SpecStorage.get<SceneJson>('scene');
435
+ this.broadcastEvent(Event.SCENE_PROCESSING_START, sceneJson);
436
+ const engine = new Engine(
437
+ this.canvas as HTMLCanvasElement,
438
+ sceneJson.engine?.antialiasing ?? false,
439
+ sceneJson.engine?.options
440
+ );
441
+ const scene = await sceneSetup(engine, sceneJson);
442
+ if (sceneJson.meshPicking) {
443
+ new HighlightLayer('default', scene);
444
+ scene.onPointerPick = (pointerEvent: PointerEvent, pickInfo: PickingInfo) => {
445
+ if (!pickInfo.hit) {
446
+ return;
447
+ }
448
+ const mesh = pickInfo.pickedMesh;
449
+ this.broadcastEvent(Event.MESH_PICKED, mesh, mesh?.metadata.element, mesh?.metadata.variant);
450
+ if (mesh?.metadata.element) {
451
+ this.broadcastEvent(Event.ELEMENT_PICKED, mesh.metadata.element);
452
+ }
453
+ if (mesh?.metadata.variant) {
454
+ if (mesh.metadata.variant.inheritedParameters[Parameter.HIGHLIGHT_ENABLED]) {
455
+ mesh.metadata.variant.toggleHighlight();
456
+ }
457
+ this.broadcastEvent(Event.VARIANT_PICKED, mesh.metadata.variant);
458
+ }
459
+ };
460
+ }
461
+ this._sceneManager = await SceneManager.create(scene);
462
+ this._animationManager = await AnimationManager.create(scene);
463
+ this._deactivateMaterialCloning = !!sceneJson.deactivateMaterialCloning;
464
+ if (this._deactivateMaterialCloning) {
465
+ console.warn(
466
+ 'CAUTION: You are using the 3D viewers "Anti Material Clone" mode! This is an experimental feature ATM and can cause some serious side effects for your 3d viewer project.'
467
+ );
468
+ }
469
+ this.broadcastEvent(Event.SCENE_PROCESSING_END, scene);
470
+ return scene;
471
+ }
472
+
473
+ /**
474
+ * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
475
+ */
476
+ protected async createVariantInstances(): Promise<VariantInstance[]> {
477
+ const setupJson = SpecStorage.get<SetupJson>('setup');
478
+ const instances = [];
479
+ for (const instanceDefinition of setupJson.instances) {
480
+ if (instanceDefinition.lazy) {
481
+ this.variantInstances.register(instanceDefinition);
482
+ continue;
483
+ }
484
+ instances.push(
485
+ await this.variantInstances.create(
486
+ instanceDefinition.variant,
487
+ instanceDefinition.name,
488
+ instanceDefinition.parameters
489
+ )
490
+ );
491
+ }
492
+ return instances;
493
+ }
494
+
495
+ /**
496
+ * Help function for focusing a helper camera exactly onto the given bounding box
497
+ */
498
+ private getFocusedHelperCamera(boundingBox: Mesh, settings?: AutofocusSettings): ArcRotateCamera {
499
+ // use helper camera to get some default values and set the values of the real camera accordingly
500
+ const helperCamera = new ArcRotateCamera(
501
+ '__helper_camera__',
502
+ 0, // camera angles will be overwritten after the target has been set
503
+ 0,
504
+ 0, // radius will be calculated, so we can set to 0 here
505
+ Vector3.Zero(),
506
+ this.scene
507
+ );
508
+ // this is required for automatically calculating the `lowerRadiusLimit`, so that we don't "dive" into meshes
509
+ // see https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior
510
+ helperCamera.useFramingBehavior = true;
511
+
512
+ // `minZ` is the camera distance beyond which the mesh will be clipped
513
+ // this should be very low, but can't be zero
514
+ // a good value seems to be 1% of the bounding box size (= radius), whereas the value shouldn't go above 1, which is also the default value
515
+ const radius = boundingBox.getBoundingInfo().boundingSphere.radius;
516
+ helperCamera.minZ = Math.min(radius / 100, 1);
517
+
518
+ // set desired camera data, these won't be changed by the autofocus function!
519
+ // default values should focus the element exactly from the front (= XY Plane)
520
+ helperCamera.setTarget(boundingBox, true);
521
+ helperCamera.alpha = (settings?.alpha ?? -90) * (Math.PI / 180);
522
+ helperCamera.beta = (settings?.beta ?? 90) * (Math.PI / 180);
523
+
524
+ // finally zoom to the bounding box
525
+ // also apply a zoom factor, this adjusts the borders around the model in the viewport
526
+ helperCamera.zoomOnFactor = settings?.radiusFactor || 1;
527
+ helperCamera.zoomOn([boundingBox], true);
528
+
529
+ return helperCamera;
530
+ }
531
+
532
+ /**
533
+ * Help function for applying the relevant data of the focused helper camera to the real camera
534
+ */
535
+ private async applyFocusedHelperCameraData(
536
+ activeCamera: ArcRotateCamera,
537
+ helperCamera: ArcRotateCamera,
538
+ settings?: AutofocusSettings
539
+ ) {
540
+ // limits
541
+ activeCamera.minZ = helperCamera.minZ;
542
+ activeCamera.maxZ = helperCamera.maxZ;
543
+ activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
544
+ activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
545
+
546
+ // additional settings
547
+ if (settings?.adjustWheelPrecision !== false) {
548
+ activeCamera.wheelPrecision = helperCamera.wheelPrecision;
549
+ }
550
+ if (settings?.adjustPanningSensibility !== false) {
551
+ activeCamera.panningSensibility = helperCamera.panningSensibility;
552
+ }
553
+ if (settings?.adjustPinchPrecision !== false) {
554
+ activeCamera.pinchPrecision = helperCamera.pinchPrecision;
555
+ }
556
+
557
+ // finally move the camera
558
+ // do this at last, so that all camera settings are already considered
559
+ const newCameraPosition: PlacementDefinition = {
560
+ alpha: helperCamera.alpha,
561
+ beta: helperCamera.beta,
562
+ radius: helperCamera.radius,
563
+ target: helperCamera.target,
564
+ };
565
+ await this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings?.animation);
566
+ }
567
+ }