@combeenation/3d-viewer 3.0.0-rc2 → 4.0.0-alpha6

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 (212) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +111 -111
  3. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  4. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  5. package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -0
  6. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  7. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  8. package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -0
  9. package/dist/lib-cjs/api/classes/element.d.ts +130 -125
  10. package/dist/lib-cjs/api/classes/element.js +752 -638
  11. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  13. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  14. package/dist/lib-cjs/api/classes/elementParameterizable.js.map +0 -0
  15. package/dist/lib-cjs/api/classes/event.d.ts +326 -312
  16. package/dist/lib-cjs/api/classes/event.js +371 -357
  17. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  18. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  19. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  20. package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -0
  21. package/dist/lib-cjs/api/classes/parameter.d.ts +259 -161
  22. package/dist/lib-cjs/api/classes/parameter.js +387 -261
  23. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  24. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  25. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -126
  26. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  27. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -0
  28. package/dist/lib-cjs/api/classes/parameterizable.js +150 -0
  29. package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -0
  30. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  31. package/dist/lib-cjs/api/classes/placementAnimation.js +138 -138
  32. package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -0
  33. package/dist/lib-cjs/api/classes/variant.d.ts +224 -176
  34. package/dist/lib-cjs/api/classes/variant.js +1126 -770
  35. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  36. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
  37. package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
  38. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  39. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -0
  40. package/dist/lib-cjs/api/classes/variantParameterizable.js +93 -0
  41. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -0
  42. package/dist/lib-cjs/api/classes/viewer.d.ts +127 -128
  43. package/dist/lib-cjs/api/classes/viewer.js +486 -486
  44. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  45. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -0
  46. package/dist/lib-cjs/api/classes/viewerLight.js +350 -0
  47. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -0
  48. package/dist/lib-cjs/api/emitter.d.ts +35 -0
  49. package/dist/lib-cjs/api/emitter.js +61 -0
  50. package/dist/lib-cjs/api/emitter.js.map +1 -0
  51. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  52. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  53. package/dist/lib-cjs/api/internal/debugViewer.js.map +0 -0
  54. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  55. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  56. package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -0
  57. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -6
  58. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
  59. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  60. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  61. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  62. package/dist/lib-cjs/api/manager/animationManager.js.map +0 -0
  63. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  64. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  65. package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -0
  66. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  67. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  68. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -0
  69. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  70. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  71. package/dist/lib-cjs/api/store/specStorage.js.map +0 -0
  72. package/dist/lib-cjs/api/util/babylonHelper.d.ts +160 -125
  73. package/dist/lib-cjs/api/util/babylonHelper.js +465 -368
  74. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  75. package/dist/lib-cjs/api/util/globalTypes.d.ts +321 -275
  76. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  77. package/dist/lib-cjs/api/util/globalTypes.js.map +0 -0
  78. package/dist/lib-cjs/api/util/resourceHelper.d.ts +26 -30
  79. package/dist/lib-cjs/api/util/resourceHelper.js +237 -247
  80. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  81. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -0
  82. package/dist/lib-cjs/api/util/stringHelper.js +26 -0
  83. package/dist/lib-cjs/api/util/stringHelper.js.map +1 -0
  84. package/dist/lib-cjs/buildinfo.json +3 -3
  85. package/dist/lib-cjs/index.d.ts +48 -46
  86. package/dist/lib-cjs/index.js +86 -82
  87. package/dist/lib-cjs/index.js.map +1 -1
  88. package/package.json +83 -83
  89. package/src/api/classes/animationInterface.ts +11 -11
  90. package/src/api/classes/dottedPath.ts +189 -189
  91. package/src/api/classes/element.ts +648 -606
  92. package/src/api/classes/event.ts +370 -355
  93. package/src/api/classes/eventBroadcaster.ts +54 -54
  94. package/src/api/classes/parameter.ts +408 -270
  95. package/src/api/classes/parameterObservable.ts +99 -121
  96. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
  97. package/src/api/classes/placementAnimation.ts +133 -133
  98. package/src/api/classes/variant.ts +799 -652
  99. package/src/api/classes/variantInstance.ts +88 -81
  100. package/src/api/classes/variantParameterizable.ts +73 -0
  101. package/src/api/classes/viewer.ts +420 -421
  102. package/src/api/classes/viewerLight.ts +295 -0
  103. package/src/api/internal/debugViewer.ts +81 -81
  104. package/src/api/internal/lensRendering.ts +10 -10
  105. package/src/api/internal/sceneSetup.ts +194 -204
  106. package/src/api/manager/animationManager.ts +116 -116
  107. package/src/api/manager/sceneManager.ts +105 -105
  108. package/src/api/manager/variantInstanceManager.ts +236 -236
  109. package/src/api/store/specStorage.ts +53 -53
  110. package/src/api/util/babylonHelper.ts +497 -392
  111. package/src/api/util/globalTypes.ts +369 -314
  112. package/src/api/util/resourceHelper.ts +157 -168
  113. package/src/api/util/stringHelper.ts +26 -0
  114. package/src/buildinfo.json +2 -2
  115. package/src/commonjs.tsconfig.json +13 -13
  116. package/src/declaration.tsconfig.json +10 -10
  117. package/src/dev.ts +45 -60
  118. package/src/es6.tsconfig.json +13 -13
  119. package/src/index.ts +91 -87
  120. package/src/pagesconfig.json +51 -47
  121. package/src/tsconfig.json +43 -43
  122. package/src/tsconfig.types.json +9 -9
  123. package/src/types.d.ts +4 -4
  124. package/src/assets/02_environment.env +0 -0
  125. package/src/assets/02_test_hdri_flipped.hdr +0 -0
  126. package/src/assets/07rDvxP2xTk.glb +0 -0
  127. package/src/assets/08L8DrdZt8y.glb +0 -0
  128. package/src/assets/CB-6250/main.js +0 -427
  129. package/src/assets/CB-6250/models/.gitkeep +0 -1
  130. package/src/assets/CB-6250/models/candle.glb +0 -0
  131. package/src/assets/CB-6250/models/lamp.glb +0 -0
  132. package/src/assets/CB-6250/models/molto-bido.glb +0 -0
  133. package/src/assets/CB-6250/models/mtron.glb +0 -0
  134. package/src/assets/CB-6250/models/mtron_split_geometry.glb +0 -0
  135. package/src/assets/CB-6250/models/mtron_split_material.glb +0 -0
  136. package/src/assets/KTM1290SA/AvatarAdv.glb +0 -0
  137. package/src/assets/KTM1290SA/ktm1290SA.ts +0 -77
  138. package/src/assets/KTM1290SA/scene.json +0 -16
  139. package/src/assets/_draft/main.js +0 -117
  140. package/src/assets/_draft/models/.gitkeep +0 -1
  141. package/src/assets/_draft/models/_demo.glb +0 -0
  142. package/src/assets/_draft/studio.env +0 -0
  143. package/src/assets/bike/CompleteBike_Optim_986K_01.glb +0 -0
  144. package/src/assets/bike/complete.json +0 -19
  145. package/src/assets/bike/index.json +0 -9
  146. package/src/assets/bike/setup.json +0 -11
  147. package/src/assets/ctrls-helper.ts +0 -89
  148. package/src/assets/cube/10 environment.env +0 -0
  149. package/src/assets/cube/bin_svg_logo_test.glb +0 -0
  150. package/src/assets/cube/cube.ts +0 -42
  151. package/src/assets/cube/cube_v2.glb +0 -0
  152. package/src/assets/cube/scene.ts +0 -83
  153. package/src/assets/cube/testCylinderUVs.glb +0 -0
  154. package/src/assets/environment.env +0 -0
  155. package/src/assets/hoferkerzen/hoferkerzen.glb +0 -0
  156. package/src/assets/hoferkerzen/index.json +0 -9
  157. package/src/assets/hoferkerzen/setup.json +0 -11
  158. package/src/assets/hoferkerzen/variant_kgl.json +0 -41
  159. package/src/assets/husqvarna-instanced-meshes/husqvarna.env +0 -0
  160. package/src/assets/husqvarna-instanced-meshes/husqvarna.glb +0 -0
  161. package/src/assets/husqvarna-instanced-meshes/main.ts +0 -108
  162. package/src/assets/index.html +0 -144
  163. package/src/assets/index.json +0 -9
  164. package/src/assets/linkeddups/example_2_instances.glb +0 -0
  165. package/src/assets/linkeddups/spec.ts +0 -32
  166. package/src/assets/molto-mova-multi-instance-shown-bug/main.ts +0 -106
  167. package/src/assets/molto-mova-multi-instance-shown-bug/molto-mova-rc82.glb +0 -0
  168. package/src/assets/molto-mova-multi-instance-shown-bug/molto-mova-volare.glb +0 -0
  169. package/src/assets/molto-mova-multi-instance-shown-bug/studio.env +0 -0
  170. package/src/assets/moltomova/10 environment.env +0 -0
  171. package/src/assets/moltomova/RC65.glb +0 -0
  172. package/src/assets/moltomova/RC82.glb +0 -0
  173. package/src/assets/moltomova/TPH67.glb +0 -0
  174. package/src/assets/moltomova/TPH82.glb +0 -0
  175. package/src/assets/moltomova/Volare.glb +0 -0
  176. package/src/assets/moltomova/moltomova-cl3d-spec-rc65.ts +0 -159
  177. package/src/assets/moltomova/moltomova-cl3d-spec-rc82.ts +0 -118
  178. package/src/assets/moltomova/moltomova-cl3d-spec-scene.ts +0 -57
  179. package/src/assets/moltomova/moltomova-cl3d-spec-tph67.ts +0 -199
  180. package/src/assets/moltomova/moltomova-cl3d-spec-tph82.ts +0 -173
  181. package/src/assets/moltomova/moltomova-cl3d-spec-volare65.ts +0 -173
  182. package/src/assets/moltomova/moltomova.ts +0 -175
  183. package/src/assets/mova.json +0 -18
  184. package/src/assets/mova_3_phase_rail.glb +0 -0
  185. package/src/assets/mova_3_phase_rail.json +0 -86
  186. package/src/assets/mova_recessed_luminaire.glb +0 -0
  187. package/src/assets/mova_recessed_luminaire.json +0 -81
  188. package/src/assets/nessie/gltf-test-no-material.gltf +0 -142
  189. package/src/assets/nessie/gltf-test-no-material_data.bin +0 -0
  190. package/src/assets/nessie/gltf-test-rotation.gltf +0 -142
  191. package/src/assets/nessie/gltf-test-rotation_data.bin +0 -0
  192. package/src/assets/nessie/gltf-test.gltf +0 -178
  193. package/src/assets/nessie/gltf-test_data.bin +0 -0
  194. package/src/assets/nessie/index.json +0 -9
  195. package/src/assets/nessie/nessie_basic.json +0 -24
  196. package/src/assets/nessie/setup.json +0 -12
  197. package/src/assets/scene.json +0 -64
  198. package/src/assets/setup.json +0 -25
  199. package/src/assets/small_cave_1k.hdr +0 -0
  200. package/src/assets/svgTo3D/09aJssVZrjk.env +0 -0
  201. package/src/assets/svgTo3D/09f0zfBQBWK.glb +0 -0
  202. package/src/assets/svgTo3D/9bae062709f8a7803769ba955cde3c4a.jpg +0 -0
  203. package/src/assets/svgTo3D/logo-cyledge.svg +0 -19
  204. package/src/assets/svgTo3D/spec.ts +0 -56
  205. package/src/assets/svgTo3D/svg_assets/09fmVjc59hQ.png +0 -0
  206. package/src/assets/svgTo3D/svg_assets/LDI2apCSOBg7S-QT7pb0EPOreec.woff2 +0 -0
  207. package/src/assets/svgTo3D/svg_assets/unineue_regular.woff2 +0 -0
  208. package/src/assets/svgTo3D/testCube.glb +0 -0
  209. package/src/assets/svgTo3D/testCube001.glb +0 -0
  210. package/src/assets/svgTo3D/testCubeSpec.ts +0 -49
  211. package/src/assets/textures/grass.png +0 -0
  212. package/src/assets/textures/seamless-grunge-scratched-texture.jpg +0 -0
@@ -1,422 +1,421 @@
1
- import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
2
- import { PickingInfo } from '@babylonjs/core/Collisions/pickingInfo';
3
- import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';
4
- import { Engine } from '@babylonjs/core/Engines/engine';
5
- import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer';
6
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
7
- import { Mesh } from '@babylonjs/core/Meshes/mesh';
8
- import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
9
- import { ScreenshotTools } from '@babylonjs/core/Misc/screenshotTools';
10
- import { Scene } from '@babylonjs/core/scene';
11
- import { isString } from 'lodash-es';
12
- import { version } from '../../buildinfo.json';
13
- import { sceneSetup } from '../internal/sceneSetup';
14
- import { AnimationManager } from '../manager/animationManager';
15
- import { SceneManager } from '../manager/sceneManager';
16
- import { VariantInstanceManager } from '../manager/variantInstanceManager';
17
- import { SpecStorage } from '../store/specStorage';
18
- import { debounce, loadJson } from '../util/resourceHelper';
19
- import { Event } from './event';
20
- import { EventBroadcaster } from './eventBroadcaster';
21
- import { Parameter } from './parameter';
22
- import { Variant } from './variant';
23
- import { VariantInstance } from './variantInstance';
24
-
25
-
26
- /**
27
- * The main exposed object. This is the entry point into the application
28
- *
29
- * ```js
30
- * const canvas = document.getElementById( 'babylon-canvas' );
31
- * const viewer = Viewer( canvas, '/path/to/index.json' );
32
- * ```
33
- * The class does nothing on its own and needs to {@link bootstrap}
34
- */
35
- export class Viewer extends EventBroadcaster {
36
-
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
- static version = version;
46
-
47
- /**
48
- * Constructor
49
- */
50
- public constructor( public readonly canvas: HTMLCanvasElement, protected structureJson: string | StructureJson ) {
51
- super();
52
- }
53
-
54
- /**
55
- * Gets the BabylonJS Scene that is attached to the instance.
56
- *
57
- * @throws Error if the `scene` has not been initialized.
58
- */
59
- get scene(): Scene {
60
- if( !this._scene ) {
61
- throw new Error( `Scene has not been initialized.` );
62
- }
63
- return this._scene;
64
- }
65
-
66
- get sceneManager(): SceneManager {
67
- if( !this._sceneManager ) {
68
- throw new Error( `Environment has not been initialized.` );
69
- }
70
- return this._sceneManager;
71
- }
72
-
73
- /**
74
- * Gets the BabylonJS Engine that is attached to the viewer.
75
- */
76
- get engine(): Engine {
77
- return this.scene.getEngine();
78
- }
79
-
80
- /**
81
- * Gets the {@link VariantInstanceManager} attached to the viewer.
82
- *
83
- * @throws Error if the {@link VariantInstanceManager} has not been initialized.
84
- */
85
- get variantInstances(): VariantInstanceManager {
86
- if( !this._variantInstances ) {
87
- throw Error( `There is no variantInstanceManager.` );
88
- }
89
- return this._variantInstances;
90
- }
91
-
92
- /**
93
- * Gets the {@link AnimationManager} attached to the viewer.
94
- *
95
- * @throws Error if the {@link AnimationManager} has not been initialized.
96
- */
97
- get animationManager(): AnimationManager {
98
- if( !this._animationManager ) {
99
- throw new Error( `There is no animationManager instance.` );
100
- }
101
- return this._animationManager;
102
- }
103
-
104
- /**
105
- * Starts the application. This will
106
- * * load the given "index" JSON file
107
- * * setup the scene with the "scene" JSON file
108
- * * create an (optional) default setup with different variant settings
109
- * * sets up resizing by attaching a debounced version of {@link resize}
110
- *
111
- * @throws Error if any of the files is not found/valid
112
- *
113
- * @emits {@link Event.BOOTSTRAP_START}
114
- * @emits {@link Event.BOOTSTRAP_END}
115
- */
116
- public async bootstrap(): Promise<Viewer> {
117
- this.broadcastEvent( Event.BOOTSTRAP_START, this );
118
- let indexJson;
119
- if( isString( this.structureJson ) ) {
120
- indexJson = await loadJson<StructureJson>( this.structureJson );
121
- } else {
122
- indexJson = this.structureJson;
123
- }
124
- if( !indexJson.scene ) {
125
- throw new Error( `No "scene" property found for bootstrapping.` );
126
- }
127
- // fill spec store
128
- SpecStorage.createFromSpec( indexJson );
129
- // load scene
130
- if( isString( indexJson.scene ) ) {
131
- const sceneJson = await loadJson<SceneJson>( indexJson.scene );
132
- indexJson.scene = sceneJson;
133
- }
134
- this._scene = await this.initScene();
135
- // create instance manager
136
- const rootVariant = await Variant.create( '_', indexJson, this );
137
- this._variantInstances = await VariantInstanceManager.create( rootVariant );
138
- // create optional default instances
139
- if( indexJson.setup ) {
140
- if( isString( indexJson.setup ) ) {
141
- const setupJson = await loadJson<SetupJson>( indexJson.setup );
142
- indexJson.setup = setupJson;
143
- }
144
- await this.createVariantInstances();
145
- }
146
- // resize handler
147
- window.addEventListener( 'resize', debounce( this.resize.bind( this ), 100 ) );
148
- // event broadcasting
149
- this.broadcastEvent( Event.BOOTSTRAP_END, this );
150
- return this;
151
- }
152
-
153
- // Disabled for now to decrease bundle size.
154
- // See https://github.com/Combeenation/3d-viewer/issues/37
155
- // /**
156
- // * Enables the BabylonJS DebugLayer. If you pass options, be sure to pass an Object of type `IInspectorOptions`.
157
- // */
158
- // public async enableDebugLayer(options?: any) {
159
- // // @ts-ignore
160
- // await import(/* webpackChunkName: "debug-inspector" */'@babylonjs/inspector');
161
- // await this.scene.debugLayer.show(options);
162
- // return this;
163
- // }
164
-
165
- /**
166
- * Destroys all registered {@link VariantInstance}s that are registered
167
- */
168
- public destroyVariantInstances(): Viewer {
169
- this.variantInstances.all.forEach( variantInstance => {
170
- this.variantInstances.destroy( variantInstance.name );
171
- } );
172
- return this;
173
- }
174
-
175
- /**
176
- * Trigger a resize event for the `Engine`
177
- */
178
- public resize(): Viewer {
179
- this.engine.resize();
180
- return this;
181
- }
182
-
183
- /**
184
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
185
- * {@link DottedPath}s.
186
- */
187
- public async getNode( variantInstanceName: string,
188
- elementDottedPath: DottedPathArgument,
189
- nodeDottedPath: DottedPathArgument ): Promise<TransformNode> {
190
- const variantInstance = await this.variantInstances.get(variantInstanceName);
191
- return variantInstance.getNode( elementDottedPath, nodeDottedPath );
192
- }
193
-
194
- /**
195
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
196
- * {@link DottedPath}s.
197
- */
198
- public async getMesh( variantInstanceName: string,
199
- elementDottedPath: DottedPathArgument,
200
- meshDottedPath: DottedPathArgument ): Promise<Mesh|null> {
201
- const variantInstance = await this.variantInstances.get(variantInstanceName);
202
- return variantInstance.getMesh( elementDottedPath, meshDottedPath );
203
- }
204
-
205
- /**
206
- * Switches the camera
207
- *
208
- * @emits {@link Event.CAMERA_SWITCHED}
209
- */
210
- public switchCamera( newCamera: string, reset: boolean = true ): Viewer {
211
- const camera = this.scene.getCameraByName( newCamera );
212
- if( camera ) {
213
- const activeCamera = this.scene.activeCamera;
214
- if( activeCamera ) {
215
- activeCamera.detachControl( this.engine.getRenderingCanvas()! );
216
- }
217
- if( reset ) {
218
- camera.restoreState();
219
- }
220
- this.scene.setActiveCameraByName( newCamera );
221
- camera.attachControl( this.engine.getRenderingCanvas()! );
222
- this.broadcastEvent( Event.CAMERA_SWITCHED, camera );
223
- } else {
224
- throw new Error( `Given camera "${newCamera}" not found.` );
225
- }
226
- // TODO: put traceable observers to new camera (@see element)
227
- return this;
228
- }
229
-
230
- /**
231
- * Moves or animates the active camera to given `placement`.
232
- */
233
- public async moveActiveCameraTo( placement: string | PlacementDefinition,
234
- animation?: string | AnimationDefinition ): Promise<AnimationInterface> {
235
- return this.animationManager.animateToPlacement( this.sceneManager.activeCamera, placement, animation );
236
- }
237
-
238
- /**
239
- * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
240
- */
241
- public screenshot( settings?: ScreenshotSettings ): Promise<string> {
242
- return new Promise( ( resolve, reject ) => {
243
- if( !this.engine ) {
244
- return reject( 'Engine is null' );
245
- }
246
- if( !this.scene ) {
247
- return reject( 'Scene is null' );
248
- }
249
- this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
250
- ScreenshotTools.CreateScreenshotUsingRenderTarget(
251
- this.engine,
252
- this.sceneManager.activeCamera,
253
- settings?.size ?? { width: this.canvas.clientWidth, height: this.canvas.clientHeight },
254
- resolve,
255
- settings?.mimeType ?? 'image/png',
256
- settings?.samples ?? 1,
257
- settings?.antialiasing ?? false,
258
- settings?.fileName ?? 'screenshot.png',
259
- settings?.renderSprites ?? false
260
- );
261
- } );
262
- }
263
-
264
- /**
265
- * Calculates the bounding box from all visible meshes on the scene.
266
- */
267
- public calculateBoundingBox(): Mesh {
268
- if( this.scene.meshes.length === 0 ) {
269
- throw new Error( 'There are currently no meshes on the scene.' );
270
- }
271
- let max = new Vector3( 0, 0, 0 );
272
- let min = new Vector3( 0, 0, 0 );
273
- this.scene.meshes.filter( mesh => mesh.isVisible ).forEach( mesh => {
274
- max = Vector3.Maximize( max, mesh.getBoundingInfo().boundingBox.maximumWorld );
275
- min = Vector3.Minimize( min, mesh.getBoundingInfo().boundingBox.minimumWorld );
276
- } );
277
- let boundingBox = this.scene.getMeshByName( '__bounding_box__' ) as Mesh;
278
- if( !boundingBox ) {
279
- boundingBox = new Mesh( '__bounding_box__', this.scene );
280
- }
281
- boundingBox.setBoundingInfo( new BoundingInfo( min, max ) );
282
- //boundingBox.showBoundingBox = true;
283
- return boundingBox;
284
- }
285
-
286
- /**
287
- * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning.
288
- */
289
- public autofocusActiveCamera( settings?: AutofocusSettings ) {
290
- const activeCamera = this.scene.activeCamera;
291
- if( !activeCamera ) {
292
- throw new Error( 'No active camera found when using autofocus feature.' );
293
- }
294
- if( activeCamera instanceof ArcRotateCamera ) {
295
- // calculate some values
296
- const boundingBox = this.calculateBoundingBox();
297
- const size = boundingBox.getBoundingInfo().maximum.subtract( boundingBox.getBoundingInfo().minimum );
298
- let radius = size.length() * (settings?.radiusFactor ?? 1.5);
299
- if( !isFinite( radius ) ) {
300
- radius = 1;
301
- }
302
- // use helper camera to get some default values
303
- const helperCamera = new ArcRotateCamera(
304
- '__helper_camera__',
305
- Math.PI / -2,
306
- Math.PI / 2,
307
- radius,
308
- Vector3.Zero(),
309
- this.scene
310
- );
311
- helperCamera.useFramingBehavior = true;
312
- helperCamera.setTarget( boundingBox );
313
- // translate values from helper to active camera
314
- activeCamera.setTarget( Mesh.Center( [boundingBox] ) );
315
- activeCamera.alpha = helperCamera.alpha;
316
- activeCamera.beta = helperCamera.beta;
317
- activeCamera.minZ = helperCamera.minZ;
318
- activeCamera.maxZ = helperCamera.maxZ;
319
- activeCamera.radius = helperCamera.radius;
320
- activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
321
- activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
322
- if( settings?.adjustWheelPrecision !== false ) {
323
- activeCamera.wheelPrecision = helperCamera.wheelPrecision;
324
- }
325
- if( settings?.adjustPanningSensibility !== false ) {
326
- activeCamera.panningSensibility = helperCamera.panningSensibility;
327
- }
328
- if( settings?.adjustPinchPrecision !== false ) {
329
- activeCamera.pinchPrecision = helperCamera.pinchPrecision;
330
- }
331
- // remove the helper camera
332
- helperCamera.dispose();
333
- } else {
334
- const cameraClsName = activeCamera.getClassName();
335
- throw new Error( `Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.` );
336
- }
337
- }
338
-
339
- /**
340
- * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
341
- * environment
342
- */
343
- public async reset(): Promise<Viewer> {
344
- await this.destroy();
345
- return this.bootstrap();
346
- }
347
-
348
- /**
349
- * Destroys
350
- *
351
- * * all {@link VariantInstance}s using {@link destroyVariantInstances}
352
- * * calling `dispose` on the `Engine` and `Scene`
353
- */
354
- public destroy(): Viewer {
355
- this.destroyVariantInstances();
356
- this.scene.dispose();
357
- SpecStorage.destroy();
358
- return this;
359
- }
360
-
361
- /**
362
- * @emits {@link Event.SCENE_PROCESSING_START}
363
- * @emits {@link Event.SCENE_PROCESSING_END}
364
- */
365
- protected async initScene(): Promise<Scene> {
366
- const sceneJson = SpecStorage.get<SceneJson>( 'scene' );
367
- this.broadcastEvent( Event.SCENE_PROCESSING_START, sceneJson );
368
- const engine = new Engine(
369
- this.canvas as HTMLCanvasElement,
370
- sceneJson.engine?.antialiasing ?? false,
371
- sceneJson.engine?.options
372
- );
373
- const scene = await sceneSetup( engine, sceneJson );
374
- if( sceneJson.meshPicking ) {
375
- new HighlightLayer( 'default', scene );
376
- scene.onPointerPick = ( pointerEvent: PointerEvent, pickInfo: PickingInfo ) => {
377
- if( !pickInfo.hit ) {
378
- return;
379
- }
380
- const mesh = pickInfo.pickedMesh;
381
- this.broadcastEvent( Event.MESH_PICKED, mesh, mesh?.metadata.element, mesh?.metadata.variant );
382
- if( mesh?.metadata.element ) {
383
- this.broadcastEvent( Event.ELEMENT_PICKED, mesh.metadata.element );
384
- }
385
- if( mesh?.metadata.variant ) {
386
- if( mesh.metadata.variant.inheritedParameters[Parameter.HIGHLIGHT_ENABLED] ) {
387
- mesh.metadata.variant.toggleHighlight();
388
- }
389
- this.broadcastEvent( Event.VARIANT_PICKED, mesh.metadata.variant );
390
- }
391
- };
392
- }
393
- this._sceneManager = await SceneManager.create( scene );
394
- this._animationManager = await AnimationManager.create( scene );
395
- this.broadcastEvent( Event.SCENE_PROCESSING_END, scene );
396
- engine.runRenderLoop( () => {
397
- scene.render();
398
- } );
399
- return scene;
400
- }
401
-
402
- /**
403
- * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
404
- */
405
- protected async createVariantInstances(): Promise<VariantInstance[]> {
406
- const setupJson = SpecStorage.get<SetupJson>( 'setup' );
407
- const instances = [];
408
- for( const instanceDefinition of setupJson.instances ) {
409
- if( instanceDefinition.lazy ) {
410
- this.variantInstances.register( instanceDefinition );
411
- continue;
412
- }
413
- instances.push( await this.variantInstances.create(
414
- instanceDefinition.variant,
415
- instanceDefinition.name,
416
- instanceDefinition.parameters
417
- ) );
418
- }
419
- return instances;
420
- }
421
-
1
+ import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
2
+ import { PickingInfo } from '@babylonjs/core/Collisions/pickingInfo';
3
+ import { BoundingInfo } from '@babylonjs/core/Culling/boundingInfo';
4
+ import { Engine } from '@babylonjs/core/Engines/engine';
5
+ import { HighlightLayer } from '@babylonjs/core/Layers/highlightLayer';
6
+ import { Vector3 } from '@babylonjs/core/Maths/math.vector';
7
+ import { Mesh } from '@babylonjs/core/Meshes/mesh';
8
+ import { ScreenshotTools } from '@babylonjs/core/Misc/screenshotTools';
9
+ import { Scene } from '@babylonjs/core/scene';
10
+ import { isString } from 'lodash-es';
11
+ import { version } from '../../buildinfo.json';
12
+ import { sceneSetup } from '../internal/sceneSetup';
13
+ import { AnimationManager } from '../manager/animationManager';
14
+ import { SceneManager } from '../manager/sceneManager';
15
+ import { VariantInstanceManager } from '../manager/variantInstanceManager';
16
+ import { SpecStorage } from '../store/specStorage';
17
+ import { debounce, loadJson } from '../util/resourceHelper';
18
+ import { Event } from './event';
19
+ import { EventBroadcaster } from './eventBroadcaster';
20
+ import { Parameter } from './parameter';
21
+ import { Variant } from './variant';
22
+ import { VariantInstance } from './variantInstance';
23
+
24
+
25
+ /**
26
+ * The main exposed object. This is the entry point into the application
27
+ *
28
+ * ```js
29
+ * const canvas = document.getElementById( 'babylon-canvas' );
30
+ * const viewer = Viewer( canvas, '/path/to/index.json' );
31
+ * ```
32
+ * The class does nothing on its own and needs to {@link bootstrap}
33
+ */
34
+ export class Viewer extends EventBroadcaster {
35
+
36
+ protected _scene: Scene | null = null;
37
+
38
+ protected _animationManager: AnimationManager | null = null;
39
+
40
+ protected _sceneManager: SceneManager | null = null;
41
+
42
+ protected _variantInstances: VariantInstanceManager | null = null;
43
+
44
+ static version = version;
45
+
46
+ /**
47
+ * Constructor
48
+ */
49
+ public constructor( public readonly canvas: HTMLCanvasElement, protected structureJson: string | StructureJson ) {
50
+ super();
51
+ }
52
+
53
+ /**
54
+ * Gets the BabylonJS Scene that is attached to the instance.
55
+ *
56
+ * @throws Error if the `scene` has not been initialized.
57
+ */
58
+ get scene(): Scene {
59
+ if( !this._scene ) {
60
+ throw new Error( `Scene has not been initialized.` );
61
+ }
62
+ return this._scene;
63
+ }
64
+
65
+ get sceneManager(): SceneManager {
66
+ if( !this._sceneManager ) {
67
+ throw new Error( `Environment has not been initialized.` );
68
+ }
69
+ return this._sceneManager;
70
+ }
71
+
72
+ /**
73
+ * Gets the BabylonJS Engine that is attached to the viewer.
74
+ */
75
+ get engine(): Engine {
76
+ return this.scene.getEngine();
77
+ }
78
+
79
+ /**
80
+ * Gets the {@link VariantInstanceManager} attached to the viewer.
81
+ *
82
+ * @throws Error if the {@link VariantInstanceManager} has not been initialized.
83
+ */
84
+ get variantInstances(): VariantInstanceManager {
85
+ if( !this._variantInstances ) {
86
+ throw Error( `There is no variantInstanceManager.` );
87
+ }
88
+ return this._variantInstances;
89
+ }
90
+
91
+ /**
92
+ * Gets the {@link AnimationManager} attached to the viewer.
93
+ *
94
+ * @throws Error if the {@link AnimationManager} has not been initialized.
95
+ */
96
+ get animationManager(): AnimationManager {
97
+ if( !this._animationManager ) {
98
+ throw new Error( `There is no animationManager instance.` );
99
+ }
100
+ return this._animationManager;
101
+ }
102
+
103
+ /**
104
+ * Starts the application. This will
105
+ * * load the given "index" JSON file
106
+ * * setup the scene with the "scene" JSON file
107
+ * * create an (optional) default setup with different variant settings
108
+ * * sets up resizing by attaching a debounced version of {@link resize}
109
+ *
110
+ * @throws Error if any of the files is not found/valid
111
+ *
112
+ * @emits {@link Event.BOOTSTRAP_START}
113
+ * @emits {@link Event.BOOTSTRAP_END}
114
+ */
115
+ public async bootstrap(): Promise<Viewer> {
116
+ this.broadcastEvent( Event.BOOTSTRAP_START, this );
117
+ let indexJson;
118
+ if( isString( this.structureJson ) ) {
119
+ indexJson = await loadJson<StructureJson>( this.structureJson );
120
+ } else {
121
+ indexJson = this.structureJson;
122
+ }
123
+ if( !indexJson.scene ) {
124
+ throw new Error( `No "scene" property found for bootstrapping.` );
125
+ }
126
+ // fill spec store
127
+ SpecStorage.createFromSpec( indexJson );
128
+ // load scene
129
+ if( isString( indexJson.scene ) ) {
130
+ const sceneJson = await loadJson<SceneJson>( indexJson.scene );
131
+ indexJson.scene = sceneJson;
132
+ }
133
+ this._scene = await this.initScene();
134
+ // create instance manager
135
+ const rootVariant = await Variant.create( '_', indexJson, this );
136
+ this._variantInstances = await VariantInstanceManager.create( rootVariant );
137
+ // create optional default instances
138
+ if( indexJson.setup ) {
139
+ if( isString( indexJson.setup ) ) {
140
+ const setupJson = await loadJson<SetupJson>( indexJson.setup );
141
+ indexJson.setup = setupJson;
142
+ }
143
+ await this.createVariantInstances();
144
+ }
145
+ // resize handler
146
+ window.addEventListener( 'resize', debounce( this.resize.bind( this ), 100 ) );
147
+ // event broadcasting
148
+ this.broadcastEvent( Event.BOOTSTRAP_END, this );
149
+ return this;
150
+ }
151
+
152
+ // Disabled for now to decrease bundle size.
153
+ // See https://github.com/Combeenation/3d-viewer/issues/37
154
+ // /**
155
+ // * Enables the BabylonJS DebugLayer. If you pass options, be sure to pass an Object of type `IInspectorOptions`.
156
+ // */
157
+ // public async enableDebugLayer(options?: any) {
158
+ // // @ts-ignore
159
+ // await import(/* webpackChunkName: "debug-inspector" */'@babylonjs/inspector');
160
+ // await this.scene.debugLayer.show(options);
161
+ // return this;
162
+ // }
163
+
164
+ /**
165
+ * Destroys all registered {@link VariantInstance}s that are registered
166
+ */
167
+ public destroyVariantInstances(): Viewer {
168
+ this.variantInstances.all.forEach( variantInstance => {
169
+ this.variantInstances.destroy( variantInstance.name );
170
+ } );
171
+ return this;
172
+ }
173
+
174
+ /**
175
+ * Trigger a resize event for the `Engine`
176
+ */
177
+ public resize(): Viewer {
178
+ this.engine.resize();
179
+ return this;
180
+ }
181
+
182
+ /**
183
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
184
+ * {@link DottedPath}s.
185
+ */
186
+ public async getNode( variantInstanceName: string,
187
+ elementDottedPath: DottedPathArgument,
188
+ nodeDottedPath: DottedPathArgument ): Promise<TransformNode> {
189
+ const variantInstance = await this.variantInstances.get(variantInstanceName);
190
+ return variantInstance.getNode( elementDottedPath, nodeDottedPath );
191
+ }
192
+
193
+ /**
194
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
195
+ * {@link DottedPath}s.
196
+ */
197
+ public async getMesh( variantInstanceName: string,
198
+ elementDottedPath: DottedPathArgument,
199
+ meshDottedPath: DottedPathArgument ): Promise<Mesh|null> {
200
+ const variantInstance = await this.variantInstances.get(variantInstanceName);
201
+ return variantInstance.getMesh( elementDottedPath, meshDottedPath );
202
+ }
203
+
204
+ /**
205
+ * Switches the camera
206
+ *
207
+ * @emits {@link Event.CAMERA_SWITCHED}
208
+ */
209
+ public switchCamera( newCamera: string, reset: boolean = true ): Viewer {
210
+ const camera = this.scene.getCameraByName( newCamera );
211
+ if( camera ) {
212
+ const activeCamera = this.scene.activeCamera;
213
+ if( activeCamera ) {
214
+ activeCamera.detachControl( this.engine.getRenderingCanvas()! );
215
+ }
216
+ if( reset ) {
217
+ camera.restoreState();
218
+ }
219
+ this.scene.setActiveCameraByName( newCamera );
220
+ camera.attachControl( this.engine.getRenderingCanvas()! );
221
+ this.broadcastEvent( Event.CAMERA_SWITCHED, camera );
222
+ } else {
223
+ throw new Error( `Given camera "${newCamera}" not found.` );
224
+ }
225
+ // TODO: put traceable observers to new camera (@see element)
226
+ return this;
227
+ }
228
+
229
+ /**
230
+ * Moves or animates the active camera to given `placement`.
231
+ */
232
+ public async moveActiveCameraTo( placement: string | PlacementDefinition,
233
+ animation?: string | AnimationDefinition ): Promise<AnimationInterface> {
234
+ return this.animationManager.animateToPlacement( this.sceneManager.activeCamera, placement, animation );
235
+ }
236
+
237
+ /**
238
+ * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
239
+ */
240
+ public screenshot( settings?: ScreenshotSettings ): Promise<string> {
241
+ return new Promise( ( resolve, reject ) => {
242
+ if( !this.engine ) {
243
+ return reject( 'Engine is null' );
244
+ }
245
+ if( !this.scene ) {
246
+ return reject( 'Scene is null' );
247
+ }
248
+ this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
249
+ ScreenshotTools.CreateScreenshotUsingRenderTarget(
250
+ this.engine,
251
+ this.sceneManager.activeCamera,
252
+ settings?.size ?? { width: this.canvas.clientWidth, height: this.canvas.clientHeight },
253
+ resolve,
254
+ settings?.mimeType ?? 'image/png',
255
+ settings?.samples ?? 1,
256
+ settings?.antialiasing ?? false,
257
+ settings?.fileName ?? 'screenshot.png',
258
+ settings?.renderSprites ?? false
259
+ );
260
+ } );
261
+ }
262
+
263
+ /**
264
+ * Calculates the bounding box from all visible meshes on the scene.
265
+ */
266
+ public calculateBoundingBox(): Mesh {
267
+ if( this.scene.meshes.length === 0 ) {
268
+ throw new Error( 'There are currently no meshes on the scene.' );
269
+ }
270
+ let max = new Vector3( 0, 0, 0 );
271
+ let min = new Vector3( 0, 0, 0 );
272
+ this.scene.meshes.filter( mesh => mesh.isVisible ).forEach( mesh => {
273
+ max = Vector3.Maximize( max, mesh.getBoundingInfo().boundingBox.maximumWorld );
274
+ min = Vector3.Minimize( min, mesh.getBoundingInfo().boundingBox.minimumWorld );
275
+ } );
276
+ let boundingBox = this.scene.getMeshByName( '__bounding_box__' ) as Mesh;
277
+ if( !boundingBox ) {
278
+ boundingBox = new Mesh( '__bounding_box__', this.scene );
279
+ }
280
+ boundingBox.setBoundingInfo( new BoundingInfo( min, max ) );
281
+ //boundingBox.showBoundingBox = true;
282
+ return boundingBox;
283
+ }
284
+
285
+ /**
286
+ * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning.
287
+ */
288
+ public autofocusActiveCamera( settings?: AutofocusSettings ) {
289
+ const activeCamera = this.scene.activeCamera;
290
+ if( !activeCamera ) {
291
+ throw new Error( 'No active camera found when using autofocus feature.' );
292
+ }
293
+ if( activeCamera instanceof ArcRotateCamera ) {
294
+ // calculate some values
295
+ const boundingBox = this.calculateBoundingBox();
296
+ const size = boundingBox.getBoundingInfo().maximum.subtract( boundingBox.getBoundingInfo().minimum );
297
+ let radius = size.length() * (settings?.radiusFactor ?? 1.5);
298
+ if( !isFinite( radius ) ) {
299
+ radius = 1;
300
+ }
301
+ // use helper camera to get some default values
302
+ const helperCamera = new ArcRotateCamera(
303
+ '__helper_camera__',
304
+ Math.PI / -2,
305
+ Math.PI / 2,
306
+ radius,
307
+ Vector3.Zero(),
308
+ this.scene
309
+ );
310
+ helperCamera.useFramingBehavior = true;
311
+ helperCamera.setTarget( boundingBox );
312
+ // translate values from helper to active camera
313
+ activeCamera.setTarget( Mesh.Center( [boundingBox] ) );
314
+ activeCamera.alpha = helperCamera.alpha;
315
+ activeCamera.beta = helperCamera.beta;
316
+ activeCamera.minZ = helperCamera.minZ;
317
+ activeCamera.maxZ = helperCamera.maxZ;
318
+ activeCamera.radius = helperCamera.radius;
319
+ activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
320
+ activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
321
+ if( settings?.adjustWheelPrecision !== false ) {
322
+ activeCamera.wheelPrecision = helperCamera.wheelPrecision;
323
+ }
324
+ if( settings?.adjustPanningSensibility !== false ) {
325
+ activeCamera.panningSensibility = helperCamera.panningSensibility;
326
+ }
327
+ if( settings?.adjustPinchPrecision !== false ) {
328
+ activeCamera.pinchPrecision = helperCamera.pinchPrecision;
329
+ }
330
+ // remove the helper camera
331
+ helperCamera.dispose();
332
+ } else {
333
+ const cameraClsName = activeCamera.getClassName();
334
+ throw new Error( `Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.` );
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
340
+ * environment
341
+ */
342
+ public async reset(): Promise<Viewer> {
343
+ await this.destroy();
344
+ return this.bootstrap();
345
+ }
346
+
347
+ /**
348
+ * Destroys
349
+ *
350
+ * * all {@link VariantInstance}s using {@link destroyVariantInstances}
351
+ * * calling `dispose` on the `Engine` and `Scene`
352
+ */
353
+ public destroy(): Viewer {
354
+ this.destroyVariantInstances();
355
+ this.scene.dispose();
356
+ SpecStorage.destroy();
357
+ return this;
358
+ }
359
+
360
+ /**
361
+ * @emits {@link Event.SCENE_PROCESSING_START}
362
+ * @emits {@link Event.SCENE_PROCESSING_END}
363
+ */
364
+ protected async initScene(): Promise<Scene> {
365
+ const sceneJson = SpecStorage.get<SceneJson>( 'scene' );
366
+ this.broadcastEvent( Event.SCENE_PROCESSING_START, sceneJson );
367
+ const engine = new Engine(
368
+ this.canvas as HTMLCanvasElement,
369
+ sceneJson.engine?.antialiasing ?? false,
370
+ sceneJson.engine?.options
371
+ );
372
+ const scene = await sceneSetup( engine, sceneJson );
373
+ if( sceneJson.meshPicking ) {
374
+ new HighlightLayer( 'default', scene );
375
+ scene.onPointerPick = ( pointerEvent: PointerEvent, pickInfo: PickingInfo ) => {
376
+ if( !pickInfo.hit ) {
377
+ return;
378
+ }
379
+ const mesh = pickInfo.pickedMesh;
380
+ this.broadcastEvent( Event.MESH_PICKED, mesh, mesh?.metadata.element, mesh?.metadata.variant );
381
+ if( mesh?.metadata.element ) {
382
+ this.broadcastEvent( Event.ELEMENT_PICKED, mesh.metadata.element );
383
+ }
384
+ if( mesh?.metadata.variant ) {
385
+ if( mesh.metadata.variant.inheritedParameters[Parameter.HIGHLIGHT_ENABLED] ) {
386
+ mesh.metadata.variant.toggleHighlight();
387
+ }
388
+ this.broadcastEvent( Event.VARIANT_PICKED, mesh.metadata.variant );
389
+ }
390
+ };
391
+ }
392
+ this._sceneManager = await SceneManager.create( scene );
393
+ this._animationManager = await AnimationManager.create( scene );
394
+ this.broadcastEvent( Event.SCENE_PROCESSING_END, scene );
395
+ engine.runRenderLoop( () => {
396
+ scene.render();
397
+ } );
398
+ return scene;
399
+ }
400
+
401
+ /**
402
+ * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
403
+ */
404
+ protected async createVariantInstances(): Promise<VariantInstance[]> {
405
+ const setupJson = SpecStorage.get<SetupJson>( 'setup' );
406
+ const instances = [];
407
+ for( const instanceDefinition of setupJson.instances ) {
408
+ if( instanceDefinition.lazy ) {
409
+ this.variantInstances.register( instanceDefinition );
410
+ continue;
411
+ }
412
+ instances.push( await this.variantInstances.create(
413
+ instanceDefinition.variant,
414
+ instanceDefinition.name,
415
+ instanceDefinition.parameters
416
+ ) );
417
+ }
418
+ return instances;
419
+ }
420
+
422
421
  }