@combeenation/3d-viewer 5.2.0-alpha5 → 6.1.0-beta1

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 (191) hide show
  1. package/README.md +111 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
  6. package/dist/lib-cjs/api/classes/element.d.ts +149 -149
  7. package/dist/lib-cjs/api/classes/element.js +669 -669
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/event.d.ts +342 -326
  10. package/dist/lib-cjs/api/classes/event.js +365 -349
  11. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  13. package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
  14. package/dist/lib-cjs/api/classes/parameter.d.ts +339 -339
  15. package/dist/lib-cjs/api/classes/parameter.js +464 -464
  16. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  17. package/dist/lib-cjs/api/classes/parameterObservable.js +97 -97
  18. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  19. package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
  20. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
  21. package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
  22. package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
  23. package/dist/lib-cjs/api/classes/variant.js +836 -836
  24. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  25. package/dist/lib-cjs/api/classes/variantInstance.d.ts +44 -44
  26. package/dist/lib-cjs/api/classes/variantInstance.js +105 -105
  27. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  28. package/dist/lib-cjs/api/classes/variantParameterizable.js +88 -88
  29. package/dist/lib-cjs/api/classes/viewer.d.ts +187 -189
  30. package/dist/lib-cjs/api/classes/viewer.js +594 -594
  31. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  32. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  33. package/dist/lib-cjs/api/classes/viewerLight.js +348 -348
  34. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  35. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  36. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -13
  37. package/dist/lib-cjs/api/internal/sceneSetup.js +226 -226
  38. package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
  39. package/dist/lib-cjs/api/manager/animationManager.js +126 -126
  40. package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +78 -65
  41. package/dist/lib-cjs/api/manager/gltfExportManager.js +241 -197
  42. package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
  43. package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -31
  44. package/dist/lib-cjs/api/manager/sceneManager.js +130 -127
  45. package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
  46. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -0
  47. package/dist/lib-cjs/api/manager/textureLoadManager.js +98 -0
  48. package/dist/lib-cjs/api/manager/textureLoadManager.js.map +1 -0
  49. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
  50. package/dist/lib-cjs/api/manager/variantInstanceManager.js +260 -260
  51. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  52. package/dist/lib-cjs/api/store/specStorage.js +50 -50
  53. package/dist/lib-cjs/api/util/babylonHelper.d.ts +183 -174
  54. package/dist/lib-cjs/api/util/babylonHelper.js +596 -585
  55. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  56. package/dist/lib-cjs/api/util/globalTypes.d.ts +383 -370
  57. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  58. package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
  59. package/dist/lib-cjs/api/util/resourceHelper.js +203 -203
  60. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +42 -35
  61. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +139 -139
  62. package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +1 -1
  63. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  64. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  65. package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
  66. package/dist/lib-cjs/api/util/structureHelper.js +48 -48
  67. package/dist/lib-cjs/buildinfo.json +3 -3
  68. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  69. package/dist/lib-cjs/index.d.ts +51 -51
  70. package/dist/lib-cjs/index.js +110 -110
  71. package/dist/webpack-stats.json +0 -0
  72. package/package.json +79 -79
  73. package/src/api/classes/animationInterface.ts +10 -10
  74. package/src/api/classes/dottedPath.ts +181 -181
  75. package/src/api/classes/element.ts +717 -717
  76. package/src/api/classes/event.ts +385 -367
  77. package/src/api/classes/eventBroadcaster.ts +52 -52
  78. package/src/api/classes/parameter.ts +497 -497
  79. package/src/api/classes/parameterObservable.ts +100 -100
  80. package/src/api/classes/parameterizable.ts +87 -87
  81. package/src/api/classes/placementAnimation.ts +162 -162
  82. package/src/api/classes/variant.ts +904 -904
  83. package/src/api/classes/variantInstance.ts +97 -97
  84. package/src/api/classes/variantParameterizable.ts +85 -85
  85. package/src/api/classes/viewer.ts +672 -670
  86. package/src/api/classes/viewerLight.ts +339 -339
  87. package/src/api/internal/debugViewer.ts +90 -90
  88. package/src/api/internal/lensRendering.ts +9 -9
  89. package/src/api/internal/sceneSetup.ts +205 -205
  90. package/src/api/manager/animationManager.ts +143 -143
  91. package/src/api/manager/gltfExportManager.ts +236 -192
  92. package/src/api/manager/sceneManager.ts +132 -127
  93. package/src/api/manager/textureLoadManager.ts +95 -0
  94. package/src/api/manager/variantInstanceManager.ts +265 -265
  95. package/src/api/store/specStorage.ts +51 -51
  96. package/src/api/util/babylonHelper.ts +658 -645
  97. package/src/api/util/globalTypes.ts +432 -417
  98. package/src/api/util/resourceHelper.ts +191 -191
  99. package/src/api/util/sceneLoaderHelper.ts +137 -144
  100. package/src/api/util/stringHelper.ts +23 -23
  101. package/src/api/util/structureHelper.ts +49 -49
  102. package/src/buildinfo.json +3 -3
  103. package/src/dev.ts +61 -61
  104. package/src/index.ts +96 -96
  105. package/src/types.d.ts +28 -28
  106. package/dist/lib-es6/api/classes/animationInterface.d.ts +0 -8
  107. package/dist/lib-es6/api/classes/animationInterface.js +0 -2
  108. package/dist/lib-es6/api/classes/animationInterface.js.map +0 -1
  109. package/dist/lib-es6/api/classes/dottedPath.d.ts +0 -79
  110. package/dist/lib-es6/api/classes/dottedPath.js +0 -163
  111. package/dist/lib-es6/api/classes/dottedPath.js.map +0 -1
  112. package/dist/lib-es6/api/classes/element.d.ts +0 -149
  113. package/dist/lib-es6/api/classes/element.js +0 -666
  114. package/dist/lib-es6/api/classes/element.js.map +0 -1
  115. package/dist/lib-es6/api/classes/event.d.ts +0 -326
  116. package/dist/lib-es6/api/classes/event.js +0 -346
  117. package/dist/lib-es6/api/classes/event.js.map +0 -1
  118. package/dist/lib-es6/api/classes/eventBroadcaster.d.ts +0 -26
  119. package/dist/lib-es6/api/classes/eventBroadcaster.js +0 -43
  120. package/dist/lib-es6/api/classes/eventBroadcaster.js.map +0 -1
  121. package/dist/lib-es6/api/classes/parameter.d.ts +0 -339
  122. package/dist/lib-es6/api/classes/parameter.js +0 -461
  123. package/dist/lib-es6/api/classes/parameter.js.map +0 -1
  124. package/dist/lib-es6/api/classes/parameterObservable.d.ts +0 -36
  125. package/dist/lib-es6/api/classes/parameterObservable.js +0 -94
  126. package/dist/lib-es6/api/classes/parameterObservable.js.map +0 -1
  127. package/dist/lib-es6/api/classes/parameterizable.d.ts +0 -15
  128. package/dist/lib-es6/api/classes/parameterizable.js +0 -99
  129. package/dist/lib-es6/api/classes/parameterizable.js.map +0 -1
  130. package/dist/lib-es6/api/classes/placementAnimation.d.ts +0 -45
  131. package/dist/lib-es6/api/classes/placementAnimation.js +0 -173
  132. package/dist/lib-es6/api/classes/placementAnimation.js.map +0 -1
  133. package/dist/lib-es6/api/classes/variant.d.ts +0 -234
  134. package/dist/lib-es6/api/classes/variant.js +0 -833
  135. package/dist/lib-es6/api/classes/variant.js.map +0 -1
  136. package/dist/lib-es6/api/classes/variantInstance.d.ts +0 -44
  137. package/dist/lib-es6/api/classes/variantInstance.js +0 -102
  138. package/dist/lib-es6/api/classes/variantInstance.js.map +0 -1
  139. package/dist/lib-es6/api/classes/variantParameterizable.d.ts +0 -17
  140. package/dist/lib-es6/api/classes/variantParameterizable.js +0 -85
  141. package/dist/lib-es6/api/classes/variantParameterizable.js.map +0 -1
  142. package/dist/lib-es6/api/classes/viewer.d.ts +0 -189
  143. package/dist/lib-es6/api/classes/viewer.js +0 -588
  144. package/dist/lib-es6/api/classes/viewer.js.map +0 -1
  145. package/dist/lib-es6/api/classes/viewerLight.d.ts +0 -66
  146. package/dist/lib-es6/api/classes/viewerLight.js +0 -322
  147. package/dist/lib-es6/api/classes/viewerLight.js.map +0 -1
  148. package/dist/lib-es6/api/internal/lensRendering.d.ts +0 -8
  149. package/dist/lib-es6/api/internal/lensRendering.js +0 -9
  150. package/dist/lib-es6/api/internal/lensRendering.js.map +0 -1
  151. package/dist/lib-es6/api/internal/sceneSetup.d.ts +0 -13
  152. package/dist/lib-es6/api/internal/sceneSetup.js +0 -199
  153. package/dist/lib-es6/api/internal/sceneSetup.js.map +0 -1
  154. package/dist/lib-es6/api/manager/animationManager.d.ts +0 -30
  155. package/dist/lib-es6/api/manager/animationManager.js +0 -123
  156. package/dist/lib-es6/api/manager/animationManager.js.map +0 -1
  157. package/dist/lib-es6/api/manager/gltfExportManager.d.ts +0 -65
  158. package/dist/lib-es6/api/manager/gltfExportManager.js +0 -194
  159. package/dist/lib-es6/api/manager/gltfExportManager.js.map +0 -1
  160. package/dist/lib-es6/api/manager/sceneManager.d.ts +0 -31
  161. package/dist/lib-es6/api/manager/sceneManager.js +0 -124
  162. package/dist/lib-es6/api/manager/sceneManager.js.map +0 -1
  163. package/dist/lib-es6/api/manager/variantInstanceManager.d.ts +0 -92
  164. package/dist/lib-es6/api/manager/variantInstanceManager.js +0 -257
  165. package/dist/lib-es6/api/manager/variantInstanceManager.js.map +0 -1
  166. package/dist/lib-es6/api/store/specStorage.d.ts +0 -24
  167. package/dist/lib-es6/api/store/specStorage.js +0 -47
  168. package/dist/lib-es6/api/store/specStorage.js.map +0 -1
  169. package/dist/lib-es6/api/util/babylonHelper.d.ts +0 -174
  170. package/dist/lib-es6/api/util/babylonHelper.js +0 -556
  171. package/dist/lib-es6/api/util/babylonHelper.js.map +0 -1
  172. package/dist/lib-es6/api/util/globalTypes.d.ts +0 -370
  173. package/dist/lib-es6/api/util/globalTypes.js +0 -2
  174. package/dist/lib-es6/api/util/globalTypes.js.map +0 -1
  175. package/dist/lib-es6/api/util/resourceHelper.d.ts +0 -58
  176. package/dist/lib-es6/api/util/resourceHelper.js +0 -194
  177. package/dist/lib-es6/api/util/resourceHelper.js.map +0 -1
  178. package/dist/lib-es6/api/util/sceneLoaderHelper.d.ts +0 -35
  179. package/dist/lib-es6/api/util/sceneLoaderHelper.js +0 -130
  180. package/dist/lib-es6/api/util/sceneLoaderHelper.js.map +0 -1
  181. package/dist/lib-es6/api/util/stringHelper.d.ts +0 -9
  182. package/dist/lib-es6/api/util/stringHelper.js +0 -22
  183. package/dist/lib-es6/api/util/stringHelper.js.map +0 -1
  184. package/dist/lib-es6/api/util/structureHelper.d.ts +0 -9
  185. package/dist/lib-es6/api/util/structureHelper.js +0 -46
  186. package/dist/lib-es6/api/util/structureHelper.js.map +0 -1
  187. package/dist/lib-es6/buildinfo.json +0 -3
  188. package/dist/lib-es6/es6.tsconfig.tsbuildinfo +0 -1
  189. package/dist/lib-es6/index.d.ts +0 -51
  190. package/dist/lib-es6/index.js +0 -49
  191. package/dist/lib-es6/index.js.map +0 -1
@@ -1,595 +1,595 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Viewer = void 0;
16
- const buildinfo_json_1 = __importDefault(require("../../buildinfo.json"));
17
- const sceneSetup_1 = require("../internal/sceneSetup");
18
- const animationManager_1 = require("../manager/animationManager");
19
- const gltfExportManager_1 = require("../manager/gltfExportManager");
20
- const sceneManager_1 = require("../manager/sceneManager");
21
- const variantInstanceManager_1 = require("../manager/variantInstanceManager");
22
- const specStorage_1 = require("../store/specStorage");
23
- const babylonHelper_1 = require("../util/babylonHelper");
24
- const resourceHelper_1 = require("../util/resourceHelper");
25
- const sceneLoaderHelper_1 = require("../util/sceneLoaderHelper");
26
- const structureHelper_1 = require("../util/structureHelper");
27
- const event_1 = require("./event");
28
- const eventBroadcaster_1 = require("./eventBroadcaster");
29
- const parameter_1 = require("./parameter");
30
- const variant_1 = require("./variant");
31
- const arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
32
- const boundingInfo_1 = require("@babylonjs/core/Culling/boundingInfo");
33
- const debugLayer_1 = require("@babylonjs/core/Debug/debugLayer");
34
- const engine_1 = require("@babylonjs/core/Engines/engine");
35
- const highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
36
- const sceneLoader_1 = require("@babylonjs/core/Loading/sceneLoader");
37
- const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
38
- const standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
39
- const math_color_1 = require("@babylonjs/core/Maths/math.color");
40
- const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
41
- const mesh_1 = require("@babylonjs/core/Meshes/mesh");
42
- const screenshotTools_1 = require("@babylonjs/core/Misc/screenshotTools");
43
- const webXRSessionManager_1 = require("@babylonjs/core/XR/webXRSessionManager");
44
- const lodash_es_1 = require("lodash-es");
45
- /**
46
- * The main exposed object. This is the entry point into the application
47
- *
48
- * ```js
49
- * const canvas = document.getElementById( 'babylon-canvas' );
50
- * const viewer = Viewer( canvas, '/path/to/index.json' );
51
- * ```
52
- * The class does nothing on its own and needs to {@link bootstrap}
53
- */
54
- class Viewer extends eventBroadcaster_1.EventBroadcaster {
55
- /**
56
- * Constructor
57
- */
58
- constructor(canvas, structureJson) {
59
- super();
60
- this.canvas = canvas;
61
- this.structureJson = structureJson;
62
- this._scene = null;
63
- this._animationManager = null;
64
- this._sceneManager = null;
65
- this._gltfExportManager = null;
66
- this._variantInstances = null;
67
- // default value is `true` ATM for compatibility reasons
68
- // in the future material cloning should be the edge case
69
- this._cloneMaterialsOnMutation = true;
70
- this._isRenderLoopPaused = false;
71
- this._inspectorLoaded = false;
72
- }
73
- /**
74
- * Gets the BabylonJS Scene that is attached to the instance.
75
- *
76
- * @throws Error if the `scene` has not been initialized.
77
- */
78
- get scene() {
79
- if (!this._scene) {
80
- throw new Error(`Scene has not been initialized.`);
81
- }
82
- return this._scene;
83
- }
84
- /**
85
- * Gets the {@link SceneManager} attached to the viewer.
86
- *
87
- * @throws Error if the {@link SceneManager} has not been initialized.
88
- */
89
- get sceneManager() {
90
- if (!this._sceneManager) {
91
- throw new Error(`SceneManager has not been initialized.`);
92
- }
93
- return this._sceneManager;
94
- }
95
- /**
96
- * Gets the {@link GltfExportManager} attached to the viewer.
97
- *
98
- * @throws Error if the {@link GltfExportManager} has not been initialized.
99
- */
100
- get gltfExportManager() {
101
- if (!this._gltfExportManager) {
102
- throw new Error(`GltfExportManager has not been initialized.`);
103
- }
104
- return this._gltfExportManager;
105
- }
106
- /**
107
- * Gets the BabylonJS Engine that is attached to the viewer.
108
- */
109
- get engine() {
110
- return this.scene.getEngine();
111
- }
112
- /**
113
- * Gets the {@link VariantInstanceManager} attached to the viewer.
114
- *
115
- * @throws Error if the {@link VariantInstanceManager} has not been initialized.
116
- */
117
- get variantInstances() {
118
- if (!this._variantInstances) {
119
- throw Error(`There is no variantInstanceManager.`);
120
- }
121
- return this._variantInstances;
122
- }
123
- /**
124
- * Gets the {@link AnimationManager} attached to the viewer.
125
- *
126
- * @throws Error if the {@link AnimationManager} has not been initialized.
127
- */
128
- get animationManager() {
129
- if (!this._animationManager) {
130
- throw new Error(`There is no animationManager instance.`);
131
- }
132
- return this._animationManager;
133
- }
134
- /**
135
- * Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
136
- */
137
- get cloneMaterialsOnMutation() {
138
- return this._cloneMaterialsOnMutation;
139
- }
140
- /**
141
- * Starts the application. This will
142
- * * load the given "index" JSON file
143
- * * setup the scene with the "scene" JSON file
144
- * * create an (optional) default setup with different variant settings
145
- * * sets up resizing by attaching a debounced version of {@link resize}
146
- *
147
- * @throws Error if any of the files is not found/valid
148
- *
149
- * @emits {@link Event.BOOTSTRAP_START}
150
- * @emits {@link Event.BOOTSTRAP_END}
151
- */
152
- bootstrap() {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- this.broadcastEvent(event_1.Event.BOOTSTRAP_START, this);
155
- let indexJson;
156
- if ((0, lodash_es_1.isString)(this.structureJson)) {
157
- indexJson = yield (0, resourceHelper_1.loadJson)(this.structureJson);
158
- }
159
- else {
160
- indexJson = this.structureJson;
161
- }
162
- if (!indexJson.scene) {
163
- throw new Error(`No "scene" property found for bootstrapping.`);
164
- }
165
- // fill spec store
166
- specStorage_1.SpecStorage.createFromSpec(indexJson);
167
- this.initCbnBabylonLoaderPlugin();
168
- // load scene
169
- if ((0, lodash_es_1.isString)(indexJson.scene)) {
170
- const sceneJson = yield (0, resourceHelper_1.loadJson)(indexJson.scene);
171
- indexJson.scene = sceneJson;
172
- }
173
- this._scene = yield this.initScene();
174
- // create instance manager
175
- const rootVariant = yield variant_1.Variant.create('_', indexJson, this);
176
- this._variantInstances = yield variantInstanceManager_1.VariantInstanceManager.create(rootVariant);
177
- // create optional default instances
178
- if (indexJson.setup) {
179
- if ((0, lodash_es_1.isString)(indexJson.setup)) {
180
- const setupJson = yield (0, resourceHelper_1.loadJson)(indexJson.setup);
181
- indexJson.setup = setupJson;
182
- }
183
- yield this.createVariantInstances();
184
- }
185
- // create gltf export manager
186
- this._gltfExportManager = yield gltfExportManager_1.GltfExportManager.create(this);
187
- // resize handler
188
- window.addEventListener('resize', (0, resourceHelper_1.debounce)(this.resize.bind(this), 100));
189
- // wait until scene is completely ready
190
- yield this.scene.whenReadyAsync();
191
- // event broadcasting
192
- this.broadcastEvent(event_1.Event.BOOTSTRAP_END, this);
193
- // render loop
194
- this.engine.runRenderLoop(() => {
195
- if (!this._isRenderLoopPaused)
196
- this.scene.render();
197
- });
198
- return this;
199
- });
200
- }
201
- /**
202
- * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
203
- * Due to the additional size of the inspector, the CDN version is used instead of shipping the required code with
204
- * the viewer.\
205
- * This means that the code will be downloaded only when needed and calling `enableDebugLayer` can take a little while
206
- * depending on your internet connection etc.
207
- */
208
- enableDebugLayer(options) {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- if (!this._inspectorLoaded) {
211
- // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
212
- yield (0, resourceHelper_1.loadJavascript)('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js');
213
- debugLayer_1.DebugLayer.InspectorURL =
214
- 'https://cdn.jsdelivr.net/npm/babylonjs-inspector@5.6.0/babylon.inspector.bundle.max.min.js';
215
- this._inspectorLoaded = true;
216
- }
217
- yield this.scene.debugLayer.show(options);
218
- });
219
- }
220
- /**
221
- * Destroys all registered {@link VariantInstance}s that are registered
222
- */
223
- destroyVariantInstances() {
224
- this.variantInstances.all.forEach(variantInstance => {
225
- this.variantInstances.destroy(variantInstance.name);
226
- });
227
- return this;
228
- }
229
- /**
230
- * Trigger a resize event for the `Engine`
231
- */
232
- resize() {
233
- this.engine.resize();
234
- return this;
235
- }
236
- /**
237
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
238
- * {@link DottedPath}s.
239
- */
240
- getNode(variantInstanceName, elementDottedPath, nodeDottedPath) {
241
- return __awaiter(this, void 0, void 0, function* () {
242
- const variantInstance = yield this.variantInstances.get(variantInstanceName);
243
- return variantInstance.getNode(elementDottedPath, nodeDottedPath);
244
- });
245
- }
246
- /**
247
- * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
248
- * {@link DottedPath}s.
249
- */
250
- getMesh(variantInstanceName, elementDottedPath, meshDottedPath) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- const variantInstance = yield this.variantInstances.get(variantInstanceName);
253
- return variantInstance.getMesh(elementDottedPath, meshDottedPath);
254
- });
255
- }
256
- /**
257
- * Switches the camera
258
- *
259
- * @emits {@link Event.CAMERA_SWITCHED}
260
- */
261
- switchCamera(newCamera, reset = true) {
262
- const camera = this.scene.getCameraByName(newCamera);
263
- if (camera) {
264
- const activeCamera = this.scene.activeCamera;
265
- if (activeCamera) {
266
- activeCamera.detachControl(this.engine.getRenderingCanvas());
267
- }
268
- if (reset) {
269
- camera.restoreState();
270
- }
271
- this.scene.setActiveCameraByName(newCamera);
272
- camera.attachControl(this.engine.getRenderingCanvas());
273
- this.broadcastEvent(event_1.Event.CAMERA_SWITCHED, camera);
274
- }
275
- else {
276
- throw new Error(`Given camera "${newCamera}" not found.`);
277
- }
278
- // TODO: put traceable observers to new camera (@see element)
279
- return this;
280
- }
281
- /**
282
- * Moves or animates the active camera to given `placement`.
283
- */
284
- moveActiveCameraTo(placement, animation) {
285
- return __awaiter(this, void 0, void 0, function* () {
286
- return this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation);
287
- });
288
- }
289
- /**
290
- * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
291
- */
292
- screenshot(settings) {
293
- return new Promise((resolve, reject) => {
294
- var _a, _b, _c, _d, _e, _f;
295
- if (!this.engine) {
296
- return reject('Engine is null');
297
- }
298
- if (!this.scene) {
299
- return reject('Scene is null');
300
- }
301
- this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
302
- screenshotTools_1.ScreenshotTools.CreateScreenshotUsingRenderTarget(this.engine, this.sceneManager.activeCamera, (_a = settings === null || settings === void 0 ? void 0 : settings.size) !== null && _a !== void 0 ? _a : { width: this.canvas.clientWidth, height: this.canvas.clientHeight }, resolve, (_b = settings === null || settings === void 0 ? void 0 : settings.mimeType) !== null && _b !== void 0 ? _b : 'image/png', (_c = settings === null || settings === void 0 ? void 0 : settings.samples) !== null && _c !== void 0 ? _c : 1, (_d = settings === null || settings === void 0 ? void 0 : settings.antialiasing) !== null && _d !== void 0 ? _d : false, (_e = settings === null || settings === void 0 ? void 0 : settings.fileName) !== null && _e !== void 0 ? _e : 'screenshot.png', (_f = settings === null || settings === void 0 ? void 0 : settings.renderSprites) !== null && _f !== void 0 ? _f : false);
303
- });
304
- }
305
- /**
306
- * Checks whether the browser is capable of handling XR.
307
- */
308
- isBrowserARCapable() {
309
- return __awaiter(this, void 0, void 0, function* () {
310
- return yield webXRSessionManager_1.WebXRSessionManager.IsSessionSupportedAsync('immersive-ar');
311
- });
312
- }
313
- /**
314
- * Calculates the bounding box from all visible meshes on the scene.
315
- */
316
- calculateBoundingBox(excludeGeometry) {
317
- return __awaiter(this, void 0, void 0, function* () {
318
- if (this.scene.meshes.length === 0) {
319
- throw new Error('There are currently no meshes on the scene.');
320
- }
321
- this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
322
- const bbName = '__bounding_box__';
323
- const { max, min } = this.scene.meshes
324
- .filter(mesh => {
325
- const isEnabled = mesh.isEnabled();
326
- // ignore the existing bounding box mesh for calculating the current one
327
- const isNotBBoxMesh = bbName !== mesh.id;
328
- // ignore meshes with invalid bounding infos
329
- const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
330
- // ignore excluded meshes
331
- const isExcluded = excludeGeometry ? (0, structureHelper_1.isMeshIncludedInExclusionList)(mesh, excludeGeometry) : false;
332
- return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !isExcluded;
333
- })
334
- .reduce((accBBoxMinMax, curMesh, idx) => {
335
- const bBox = curMesh.getBoundingInfo().boundingBox;
336
- // use the first entry in the array as default value and get the resulting maximum/minimum values
337
- const max = idx === 0 ? bBox.maximumWorld : math_vector_1.Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
338
- const min = idx === 0 ? bBox.minimumWorld : math_vector_1.Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
339
- return { max, min };
340
- }, { max: new math_vector_1.Vector3(), min: new math_vector_1.Vector3() });
341
- let boundingBox = this.scene.getMeshByName(bbName);
342
- if (!boundingBox) {
343
- boundingBox = new mesh_1.Mesh(bbName, this.scene);
344
- }
345
- boundingBox.setBoundingInfo(new boundingInfo_1.BoundingInfo(min, max));
346
- return boundingBox;
347
- });
348
- }
349
- /**
350
- * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
351
- */
352
- autofocusActiveCamera(settings) {
353
- var _a;
354
- return __awaiter(this, void 0, void 0, function* () {
355
- // first check some preconditions
356
- const activeCamera = this.scene.activeCamera;
357
- if (!activeCamera) {
358
- throw new Error('No active camera found when using autofocus feature.');
359
- }
360
- if (!(activeCamera instanceof arcRotateCamera_1.ArcRotateCamera)) {
361
- const cameraClsName = activeCamera.getClassName();
362
- throw new Error(`Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.`);
363
- }
364
- let exclude = (settings === null || settings === void 0 ? void 0 : settings.exclude) || [];
365
- // Exclude shown photo dome or environment helper from bounding box calculation
366
- const photoDome = this.scene.getNodeByName(babylonHelper_1.backgroundDomeName);
367
- const photoDomeMeshes = photoDome === null || photoDome === void 0 ? void 0 : photoDome.getChildMeshes();
368
- if (photoDomeMeshes === null || photoDomeMeshes === void 0 ? void 0 : photoDomeMeshes.length) {
369
- exclude = [...exclude, ...photoDomeMeshes];
370
- }
371
- const envHelper = (_a = this.scene.metadata) === null || _a === void 0 ? void 0 : _a[babylonHelper_1.envHelperMetadataName];
372
- if (envHelper === null || envHelper === void 0 ? void 0 : envHelper.rootMesh) {
373
- exclude = [...exclude, envHelper.rootMesh];
374
- }
375
- // get bounding box of all visible meshes, this is the base for the autofocus algorithm
376
- const boundingBox = yield this.calculateBoundingBox(exclude);
377
- // focus the helper camera and set the calculated camera data to the real camera
378
- const helperCamera = this.getFocusedHelperCamera(boundingBox, settings);
379
- yield this.applyFocusedHelperCameraData(activeCamera, helperCamera, settings);
380
- // remove the helper camera
381
- helperCamera.dispose();
382
- });
383
- }
384
- /**
385
- * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
386
- * environment
387
- */
388
- reset() {
389
- return __awaiter(this, void 0, void 0, function* () {
390
- yield this.destroy();
391
- return this.bootstrap();
392
- });
393
- }
394
- /**
395
- * Destroys
396
- *
397
- * * all {@link VariantInstance}s using {@link destroyVariantInstances}
398
- * * calling `dispose` on the `Engine` and `Scene`
399
- */
400
- destroy() {
401
- this.destroyVariantInstances();
402
- this.scene.dispose();
403
- specStorage_1.SpecStorage.destroy();
404
- return this;
405
- }
406
- /**
407
- * Show coordinate system with given dimension (for debugging purpose).
408
- */
409
- showWorldCoordinates(dimension) {
410
- const scene = this.scene;
411
- const makeTextPlane = function (text, color, size) {
412
- const dynamicTexture = new dynamicTexture_1.DynamicTexture('DynamicTexture', 50, scene, true);
413
- dynamicTexture.hasAlpha = true;
414
- dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
415
- const plane = mesh_1.Mesh.CreatePlane('TextPlane', size, scene, true);
416
- plane.material = new standardMaterial_1.StandardMaterial('TextPlaneMaterial', scene);
417
- plane.material.backFaceCulling = false;
418
- plane.material.specularColor = new math_color_1.Color3(0, 0, 0);
419
- plane.material.diffuseTexture = dynamicTexture;
420
- return plane;
421
- };
422
- const axisX = mesh_1.Mesh.CreateLines('axisX', [
423
- math_vector_1.Vector3.Zero(),
424
- new math_vector_1.Vector3(dimension, 0, 0),
425
- new math_vector_1.Vector3(dimension * 0.95, 0.05 * dimension, 0),
426
- new math_vector_1.Vector3(dimension, 0, 0),
427
- new math_vector_1.Vector3(dimension * 0.95, -0.05 * dimension, 0),
428
- ], scene, false);
429
- axisX.color = new math_color_1.Color3(1, 0, 0);
430
- const xChar = makeTextPlane('X', 'red', dimension / 10);
431
- xChar.position = new math_vector_1.Vector3(0.9 * dimension, -0.05 * dimension, 0);
432
- const axisY = mesh_1.Mesh.CreateLines('axisY', [
433
- math_vector_1.Vector3.Zero(),
434
- new math_vector_1.Vector3(0, dimension, 0),
435
- new math_vector_1.Vector3(-0.05 * dimension, dimension * 0.95, 0),
436
- new math_vector_1.Vector3(0, dimension, 0),
437
- new math_vector_1.Vector3(0.05 * dimension, dimension * 0.95, 0),
438
- ], scene, false);
439
- axisY.color = new math_color_1.Color3(0, 1, 0);
440
- const yChar = makeTextPlane('Y', 'green', dimension / 10);
441
- yChar.position = new math_vector_1.Vector3(0, 0.9 * dimension, -0.05 * dimension);
442
- const axisZ = mesh_1.Mesh.CreateLines('axisZ', [
443
- math_vector_1.Vector3.Zero(),
444
- new math_vector_1.Vector3(0, 0, dimension),
445
- new math_vector_1.Vector3(0, -0.05 * dimension, dimension * 0.95),
446
- new math_vector_1.Vector3(0, 0, dimension),
447
- new math_vector_1.Vector3(0, 0.05 * dimension, dimension * 0.95),
448
- ], scene, false);
449
- axisZ.color = new math_color_1.Color3(0, 0, 1);
450
- const zChar = makeTextPlane('Z', 'blue', dimension / 10);
451
- zChar.position = new math_vector_1.Vector3(0, 0.05 * dimension, 0.9 * dimension);
452
- }
453
- /**
454
- * Pause render loop.
455
- */
456
- pauseRendering() {
457
- this._isRenderLoopPaused = true;
458
- }
459
- /**
460
- * Resume render loop when paused.
461
- */
462
- resumeRendering() {
463
- this._isRenderLoopPaused = false;
464
- }
465
- /**
466
- * @emits {@link Event.SCENE_PROCESSING_START}
467
- * @emits {@link Event.SCENE_PROCESSING_END}
468
- */
469
- initScene() {
470
- var _a, _b, _c;
471
- return __awaiter(this, void 0, void 0, function* () {
472
- const sceneJson = specStorage_1.SpecStorage.get('scene');
473
- this.broadcastEvent(event_1.Event.SCENE_PROCESSING_START, sceneJson);
474
- const engine = new engine_1.Engine(this.canvas, (_b = (_a = sceneJson.engine) === null || _a === void 0 ? void 0 : _a.antialiasing) !== null && _b !== void 0 ? _b : false, (_c = sceneJson.engine) === null || _c === void 0 ? void 0 : _c.options);
475
- const scene = yield (0, sceneSetup_1.sceneSetup)(engine, sceneJson);
476
- if (sceneJson.meshPicking) {
477
- new highlightLayer_1.HighlightLayer('default', scene);
478
- scene.onPointerPick = (pointerEvent, pickInfo) => {
479
- if (!pickInfo.hit) {
480
- return;
481
- }
482
- const mesh = pickInfo.pickedMesh;
483
- this.broadcastEvent(event_1.Event.MESH_PICKED, mesh, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant);
484
- if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element) {
485
- this.broadcastEvent(event_1.Event.ELEMENT_PICKED, mesh.metadata.element);
486
- }
487
- if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant) {
488
- if (mesh.metadata.variant.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
489
- mesh.metadata.variant.toggleHighlight();
490
- }
491
- this.broadcastEvent(event_1.Event.VARIANT_PICKED, mesh.metadata.variant);
492
- }
493
- };
494
- }
495
- this._sceneManager = yield sceneManager_1.SceneManager.create(scene);
496
- this._animationManager = yield animationManager_1.AnimationManager.create(scene);
497
- if (sceneJson.cloneMaterialsOnMutation !== undefined) {
498
- this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
499
- }
500
- this.broadcastEvent(event_1.Event.SCENE_PROCESSING_END, scene);
501
- return scene;
502
- });
503
- }
504
- /**
505
- * Register custom file loader for babylon files which adds "missing-material" metadata to meshes which reference
506
- * materials that are not present in the `materials` section of the given babylon file.
507
- *
508
- * Required for babylon files & materials loaded from "Combeenation configurator assets".
509
- */
510
- initCbnBabylonLoaderPlugin() {
511
- const previousLoaderPlugin = sceneLoader_1.SceneLoader.GetPluginForExtension('babylon');
512
- const customLoaderPlugin = (0, sceneLoaderHelper_1.getCustomCbnBabylonLoaderPlugin)(previousLoaderPlugin);
513
- sceneLoader_1.SceneLoader.RegisterPlugin(customLoaderPlugin);
514
- }
515
- /**
516
- * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
517
- */
518
- createVariantInstances() {
519
- return __awaiter(this, void 0, void 0, function* () {
520
- const setupJson = specStorage_1.SpecStorage.get('setup');
521
- const instances = [];
522
- for (const instanceDefinition of setupJson.instances) {
523
- if (instanceDefinition.lazy) {
524
- this.variantInstances.register(instanceDefinition);
525
- continue;
526
- }
527
- instances.push(yield this.variantInstances.create(instanceDefinition.variant, instanceDefinition.name, instanceDefinition.parameters));
528
- }
529
- return instances;
530
- });
531
- }
532
- /**
533
- * Help function for focusing a helper camera exactly onto the given bounding box
534
- */
535
- getFocusedHelperCamera(boundingBox, settings) {
536
- var _a, _b;
537
- // use helper camera to get some default values and set the values of the real camera accordingly
538
- const helperCamera = new arcRotateCamera_1.ArcRotateCamera('__helper_camera__', 0, // camera angles will be overwritten after the target has been set
539
- 0, 0, // radius will be calculated, so we can set to 0 here
540
- math_vector_1.Vector3.Zero(), this.scene);
541
- // this is required for automatically calculating the `lowerRadiusLimit`, so that we don't "dive" into meshes
542
- // see https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior
543
- helperCamera.useFramingBehavior = true;
544
- // `minZ` is the camera distance beyond which the mesh will be clipped
545
- // this should be very low, but can't be zero
546
- // a good value seems to be 1% of the bounding box size (= radius), whereas the value shouldn't go above 1, which is
547
- // also the default value
548
- const radius = boundingBox.getBoundingInfo().boundingSphere.radius;
549
- helperCamera.minZ = Math.min(radius / 100, 1);
550
- // set desired camera data, these won't be changed by the autofocus function!
551
- // default values should focus the element exactly from the front (= XY Plane)
552
- helperCamera.setTarget(boundingBox, true);
553
- helperCamera.alpha = ((_a = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _a !== void 0 ? _a : -90) * (Math.PI / 180);
554
- helperCamera.beta = ((_b = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _b !== void 0 ? _b : 90) * (Math.PI / 180);
555
- // finally zoom to the bounding box
556
- // also apply a zoom factor, this adjusts the borders around the model in the viewport
557
- helperCamera.zoomOnFactor = (settings === null || settings === void 0 ? void 0 : settings.radiusFactor) || 1;
558
- helperCamera.zoomOn([boundingBox], true);
559
- return helperCamera;
560
- }
561
- /**
562
- * Help function for applying the relevant data of the focused helper camera to the real camera
563
- */
564
- applyFocusedHelperCameraData(activeCamera, helperCamera, settings) {
565
- return __awaiter(this, void 0, void 0, function* () {
566
- // limits
567
- activeCamera.minZ = helperCamera.minZ;
568
- activeCamera.maxZ = helperCamera.maxZ;
569
- activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
570
- activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
571
- // additional settings
572
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
573
- activeCamera.wheelPrecision = helperCamera.wheelPrecision;
574
- }
575
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
576
- activeCamera.panningSensibility = helperCamera.panningSensibility;
577
- }
578
- if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
579
- activeCamera.pinchPrecision = helperCamera.pinchPrecision;
580
- }
581
- // finally move the camera
582
- // do this at last, so that all camera settings are already considered
583
- const newCameraPosition = {
584
- alpha: helperCamera.alpha,
585
- beta: helperCamera.beta,
586
- radius: helperCamera.radius,
587
- target: helperCamera.target,
588
- };
589
- yield this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.animation);
590
- });
591
- }
592
- }
593
- exports.Viewer = Viewer;
594
- Viewer.version = buildinfo_json_1.default;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Viewer = void 0;
16
+ const buildinfo_json_1 = __importDefault(require("../../buildinfo.json"));
17
+ const sceneSetup_1 = require("../internal/sceneSetup");
18
+ const animationManager_1 = require("../manager/animationManager");
19
+ const gltfExportManager_1 = require("../manager/gltfExportManager");
20
+ const sceneManager_1 = require("../manager/sceneManager");
21
+ const variantInstanceManager_1 = require("../manager/variantInstanceManager");
22
+ const specStorage_1 = require("../store/specStorage");
23
+ const babylonHelper_1 = require("../util/babylonHelper");
24
+ const resourceHelper_1 = require("../util/resourceHelper");
25
+ const sceneLoaderHelper_1 = require("../util/sceneLoaderHelper");
26
+ const structureHelper_1 = require("../util/structureHelper");
27
+ const event_1 = require("./event");
28
+ const eventBroadcaster_1 = require("./eventBroadcaster");
29
+ const parameter_1 = require("./parameter");
30
+ const variant_1 = require("./variant");
31
+ const arcRotateCamera_1 = require("@babylonjs/core/Cameras/arcRotateCamera");
32
+ const boundingInfo_1 = require("@babylonjs/core/Culling/boundingInfo");
33
+ const debugLayer_1 = require("@babylonjs/core/Debug/debugLayer");
34
+ const engine_1 = require("@babylonjs/core/Engines/engine");
35
+ const highlightLayer_1 = require("@babylonjs/core/Layers/highlightLayer");
36
+ const sceneLoader_1 = require("@babylonjs/core/Loading/sceneLoader");
37
+ const dynamicTexture_1 = require("@babylonjs/core/Materials/Textures/dynamicTexture");
38
+ const standardMaterial_1 = require("@babylonjs/core/Materials/standardMaterial");
39
+ const math_color_1 = require("@babylonjs/core/Maths/math.color");
40
+ const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
41
+ const mesh_1 = require("@babylonjs/core/Meshes/mesh");
42
+ const screenshotTools_1 = require("@babylonjs/core/Misc/screenshotTools");
43
+ const webXRSessionManager_1 = require("@babylonjs/core/XR/webXRSessionManager");
44
+ const lodash_es_1 = require("lodash-es");
45
+ /**
46
+ * The main exposed object. This is the entry point into the application
47
+ *
48
+ * ```js
49
+ * const canvas = document.getElementById( 'babylon-canvas' );
50
+ * const viewer = Viewer( canvas, '/path/to/index.json' );
51
+ * ```
52
+ * The class does nothing on its own and needs to {@link bootstrap}
53
+ */
54
+ class Viewer extends eventBroadcaster_1.EventBroadcaster {
55
+ /**
56
+ * Constructor
57
+ */
58
+ constructor(canvas, structureJson) {
59
+ super();
60
+ this.canvas = canvas;
61
+ this.structureJson = structureJson;
62
+ this._scene = null;
63
+ this._animationManager = null;
64
+ this._sceneManager = null;
65
+ this._gltfExportManager = null;
66
+ this._variantInstances = null;
67
+ // default value is `true` ATM for compatibility reasons
68
+ // in the future material cloning should be the edge case
69
+ this._cloneMaterialsOnMutation = true;
70
+ this._isRenderLoopPaused = false;
71
+ this._inspectorLoaded = false;
72
+ }
73
+ /**
74
+ * Gets the BabylonJS Scene that is attached to the instance.
75
+ *
76
+ * @throws Error if the `scene` has not been initialized.
77
+ */
78
+ get scene() {
79
+ if (!this._scene) {
80
+ throw new Error(`Scene has not been initialized.`);
81
+ }
82
+ return this._scene;
83
+ }
84
+ /**
85
+ * Gets the {@link SceneManager} attached to the viewer.
86
+ *
87
+ * @throws Error if the {@link SceneManager} has not been initialized.
88
+ */
89
+ get sceneManager() {
90
+ if (!this._sceneManager) {
91
+ throw new Error(`SceneManager has not been initialized.`);
92
+ }
93
+ return this._sceneManager;
94
+ }
95
+ /**
96
+ * Gets the {@link GltfExportManager} attached to the viewer.
97
+ *
98
+ * @throws Error if the {@link GltfExportManager} has not been initialized.
99
+ */
100
+ get gltfExportManager() {
101
+ if (!this._gltfExportManager) {
102
+ throw new Error(`GltfExportManager has not been initialized.`);
103
+ }
104
+ return this._gltfExportManager;
105
+ }
106
+ /**
107
+ * Gets the BabylonJS Engine that is attached to the viewer.
108
+ */
109
+ get engine() {
110
+ return this.scene.getEngine();
111
+ }
112
+ /**
113
+ * Gets the {@link VariantInstanceManager} attached to the viewer.
114
+ *
115
+ * @throws Error if the {@link VariantInstanceManager} has not been initialized.
116
+ */
117
+ get variantInstances() {
118
+ if (!this._variantInstances) {
119
+ throw Error(`There is no variantInstanceManager.`);
120
+ }
121
+ return this._variantInstances;
122
+ }
123
+ /**
124
+ * Gets the {@link AnimationManager} attached to the viewer.
125
+ *
126
+ * @throws Error if the {@link AnimationManager} has not been initialized.
127
+ */
128
+ get animationManager() {
129
+ if (!this._animationManager) {
130
+ throw new Error(`There is no animationManager instance.`);
131
+ }
132
+ return this._animationManager;
133
+ }
134
+ /**
135
+ * Gets the `cloneMaterialsOnMutation` flag, as defined in the spec
136
+ */
137
+ get cloneMaterialsOnMutation() {
138
+ return this._cloneMaterialsOnMutation;
139
+ }
140
+ /**
141
+ * Starts the application. This will
142
+ * * load the given "index" JSON file
143
+ * * setup the scene with the "scene" JSON file
144
+ * * create an (optional) default setup with different variant settings
145
+ * * sets up resizing by attaching a debounced version of {@link resize}
146
+ *
147
+ * @throws Error if any of the files is not found/valid
148
+ *
149
+ * @emits {@link Event.BOOTSTRAP_START}
150
+ * @emits {@link Event.BOOTSTRAP_END}
151
+ */
152
+ bootstrap() {
153
+ return __awaiter(this, void 0, void 0, function* () {
154
+ this.broadcastEvent(event_1.Event.BOOTSTRAP_START, this);
155
+ let indexJson;
156
+ if ((0, lodash_es_1.isString)(this.structureJson)) {
157
+ indexJson = yield (0, resourceHelper_1.loadJson)(this.structureJson);
158
+ }
159
+ else {
160
+ indexJson = this.structureJson;
161
+ }
162
+ if (!indexJson.scene) {
163
+ throw new Error(`No "scene" property found for bootstrapping.`);
164
+ }
165
+ // fill spec store
166
+ specStorage_1.SpecStorage.createFromSpec(indexJson);
167
+ this.initCbnBabylonLoaderPlugin();
168
+ // load scene
169
+ if ((0, lodash_es_1.isString)(indexJson.scene)) {
170
+ const sceneJson = yield (0, resourceHelper_1.loadJson)(indexJson.scene);
171
+ indexJson.scene = sceneJson;
172
+ }
173
+ this._scene = yield this.initScene();
174
+ // create instance manager
175
+ const rootVariant = yield variant_1.Variant.create('_', indexJson, this);
176
+ this._variantInstances = yield variantInstanceManager_1.VariantInstanceManager.create(rootVariant);
177
+ // create optional default instances
178
+ if (indexJson.setup) {
179
+ if ((0, lodash_es_1.isString)(indexJson.setup)) {
180
+ const setupJson = yield (0, resourceHelper_1.loadJson)(indexJson.setup);
181
+ indexJson.setup = setupJson;
182
+ }
183
+ yield this.createVariantInstances();
184
+ }
185
+ // create gltf export manager
186
+ this._gltfExportManager = yield gltfExportManager_1.GltfExportManager.create(this);
187
+ // resize handler
188
+ window.addEventListener('resize', (0, resourceHelper_1.debounce)(this.resize.bind(this), 100));
189
+ // wait until scene is completely ready
190
+ yield this.scene.whenReadyAsync();
191
+ // event broadcasting
192
+ this.broadcastEvent(event_1.Event.BOOTSTRAP_END, this);
193
+ // render loop
194
+ this.engine.runRenderLoop(() => {
195
+ if (!this._isRenderLoopPaused)
196
+ this.scene.render();
197
+ });
198
+ return this;
199
+ });
200
+ }
201
+ /**
202
+ * Enables the BabylonJS [Inspector](https://doc.babylonjs.com/toolsAndResources/tools/inspector).\
203
+ * Due to the additional size of the inspector, the CDN version is used instead of shipping the required code with
204
+ * the viewer.\
205
+ * This means that the code will be downloaded only when needed and calling `enableDebugLayer` can take a little while
206
+ * depending on your internet connection etc.
207
+ */
208
+ enableDebugLayer(options) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ if (!this._inspectorLoaded) {
211
+ // CDN version of inspector requires the BabylonJS core to be available as CDN module as well
212
+ yield (0, resourceHelper_1.loadJavascript)('https://cdn.jsdelivr.net/npm/babylonjs@5.6.0/babylon.min.js');
213
+ debugLayer_1.DebugLayer.InspectorURL =
214
+ 'https://cdn.jsdelivr.net/npm/babylonjs-inspector@5.6.0/babylon.inspector.bundle.max.min.js';
215
+ this._inspectorLoaded = true;
216
+ }
217
+ yield this.scene.debugLayer.show(options);
218
+ });
219
+ }
220
+ /**
221
+ * Destroys all registered {@link VariantInstance}s that are registered
222
+ */
223
+ destroyVariantInstances() {
224
+ this.variantInstances.all.forEach(variantInstance => {
225
+ this.variantInstances.destroy(variantInstance.name);
226
+ });
227
+ return this;
228
+ }
229
+ /**
230
+ * Trigger a resize event for the `Engine`
231
+ */
232
+ resize() {
233
+ this.engine.resize();
234
+ return this;
235
+ }
236
+ /**
237
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
238
+ * {@link DottedPath}s.
239
+ */
240
+ getNode(variantInstanceName, elementDottedPath, nodeDottedPath) {
241
+ return __awaiter(this, void 0, void 0, function* () {
242
+ const variantInstance = yield this.variantInstances.get(variantInstanceName);
243
+ return variantInstance.getNode(elementDottedPath, nodeDottedPath);
244
+ });
245
+ }
246
+ /**
247
+ * A convenience method for directly getting a Node from a {@link VariantInstance} and an {@link Element} by its
248
+ * {@link DottedPath}s.
249
+ */
250
+ getMesh(variantInstanceName, elementDottedPath, meshDottedPath) {
251
+ return __awaiter(this, void 0, void 0, function* () {
252
+ const variantInstance = yield this.variantInstances.get(variantInstanceName);
253
+ return variantInstance.getMesh(elementDottedPath, meshDottedPath);
254
+ });
255
+ }
256
+ /**
257
+ * Switches the camera
258
+ *
259
+ * @emits {@link Event.CAMERA_SWITCHED}
260
+ */
261
+ switchCamera(newCamera, reset = true) {
262
+ const camera = this.scene.getCameraByName(newCamera);
263
+ if (camera) {
264
+ const activeCamera = this.scene.activeCamera;
265
+ if (activeCamera) {
266
+ activeCamera.detachControl(this.engine.getRenderingCanvas());
267
+ }
268
+ if (reset) {
269
+ camera.restoreState();
270
+ }
271
+ this.scene.setActiveCameraByName(newCamera);
272
+ camera.attachControl(this.engine.getRenderingCanvas());
273
+ this.broadcastEvent(event_1.Event.CAMERA_SWITCHED, camera);
274
+ }
275
+ else {
276
+ throw new Error(`Given camera "${newCamera}" not found.`);
277
+ }
278
+ // TODO: put traceable observers to new camera (@see element)
279
+ return this;
280
+ }
281
+ /**
282
+ * Moves or animates the active camera to given `placement`.
283
+ */
284
+ moveActiveCameraTo(placement, animation) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ return this.animationManager.animateToPlacement(this.sceneManager.activeCamera, placement, animation);
287
+ });
288
+ }
289
+ /**
290
+ * Takes a sceenshot the the current scene. The result is a string containing a base64 encoded image
291
+ */
292
+ screenshot(settings) {
293
+ return new Promise((resolve, reject) => {
294
+ var _a, _b, _c, _d, _e, _f;
295
+ if (!this.engine) {
296
+ return reject('Engine is null');
297
+ }
298
+ if (!this.scene) {
299
+ return reject('Scene is null');
300
+ }
301
+ this.scene.render(); // in combination with a render target, we need to refresh the scene manually to get the latest view
302
+ screenshotTools_1.ScreenshotTools.CreateScreenshotUsingRenderTarget(this.engine, this.sceneManager.activeCamera, (_a = settings === null || settings === void 0 ? void 0 : settings.size) !== null && _a !== void 0 ? _a : { width: this.canvas.clientWidth, height: this.canvas.clientHeight }, resolve, (_b = settings === null || settings === void 0 ? void 0 : settings.mimeType) !== null && _b !== void 0 ? _b : 'image/png', (_c = settings === null || settings === void 0 ? void 0 : settings.samples) !== null && _c !== void 0 ? _c : 1, (_d = settings === null || settings === void 0 ? void 0 : settings.antialiasing) !== null && _d !== void 0 ? _d : false, (_e = settings === null || settings === void 0 ? void 0 : settings.fileName) !== null && _e !== void 0 ? _e : 'screenshot.png', (_f = settings === null || settings === void 0 ? void 0 : settings.renderSprites) !== null && _f !== void 0 ? _f : false);
303
+ });
304
+ }
305
+ /**
306
+ * Checks whether the browser is capable of handling XR.
307
+ */
308
+ isBrowserARCapable() {
309
+ return __awaiter(this, void 0, void 0, function* () {
310
+ return yield webXRSessionManager_1.WebXRSessionManager.IsSessionSupportedAsync('immersive-ar');
311
+ });
312
+ }
313
+ /**
314
+ * Calculates the bounding box from all visible meshes on the scene.
315
+ */
316
+ calculateBoundingBox(excludeGeometry) {
317
+ return __awaiter(this, void 0, void 0, function* () {
318
+ if (this.scene.meshes.length === 0) {
319
+ throw new Error('There are currently no meshes on the scene.');
320
+ }
321
+ this.scene.render(); // CB-6062: workaround for BoundingBox not respecting render loop
322
+ const bbName = '__bounding_box__';
323
+ const { max, min } = this.scene.meshes
324
+ .filter(mesh => {
325
+ const isEnabled = mesh.isEnabled();
326
+ // ignore the existing bounding box mesh for calculating the current one
327
+ const isNotBBoxMesh = bbName !== mesh.id;
328
+ // ignore meshes with invalid bounding infos
329
+ const hasValidBBoxInfo = mesh.getBoundingInfo().boundingSphere.radius > 0;
330
+ // ignore excluded meshes
331
+ const isExcluded = excludeGeometry ? (0, structureHelper_1.isMeshIncludedInExclusionList)(mesh, excludeGeometry) : false;
332
+ return isEnabled && isNotBBoxMesh && hasValidBBoxInfo && !isExcluded;
333
+ })
334
+ .reduce((accBBoxMinMax, curMesh, idx) => {
335
+ const bBox = curMesh.getBoundingInfo().boundingBox;
336
+ // use the first entry in the array as default value and get the resulting maximum/minimum values
337
+ const max = idx === 0 ? bBox.maximumWorld : math_vector_1.Vector3.Maximize(accBBoxMinMax.max, bBox.maximumWorld);
338
+ const min = idx === 0 ? bBox.minimumWorld : math_vector_1.Vector3.Minimize(accBBoxMinMax.min, bBox.minimumWorld);
339
+ return { max, min };
340
+ }, { max: new math_vector_1.Vector3(), min: new math_vector_1.Vector3() });
341
+ let boundingBox = this.scene.getMeshByName(bbName);
342
+ if (!boundingBox) {
343
+ boundingBox = new mesh_1.Mesh(bbName, this.scene);
344
+ }
345
+ boundingBox.setBoundingInfo(new boundingInfo_1.BoundingInfo(min, max));
346
+ return boundingBox;
347
+ });
348
+ }
349
+ /**
350
+ * Focuses the camera to see every visible mesh in scene and tries to optimize wheel precision and panning
351
+ */
352
+ autofocusActiveCamera(settings) {
353
+ var _a;
354
+ return __awaiter(this, void 0, void 0, function* () {
355
+ // first check some preconditions
356
+ const activeCamera = this.scene.activeCamera;
357
+ if (!activeCamera) {
358
+ throw new Error('No active camera found when using autofocus feature.');
359
+ }
360
+ if (!(activeCamera instanceof arcRotateCamera_1.ArcRotateCamera)) {
361
+ const cameraClsName = activeCamera.getClassName();
362
+ throw new Error(`Camera of type "${cameraClsName}" is not implemented yet to use autofocus feature.`);
363
+ }
364
+ let exclude = (settings === null || settings === void 0 ? void 0 : settings.exclude) || [];
365
+ // Exclude shown photo dome or environment helper from bounding box calculation
366
+ const photoDome = this.scene.getNodeByName(babylonHelper_1.backgroundDomeName);
367
+ const photoDomeMeshes = photoDome === null || photoDome === void 0 ? void 0 : photoDome.getChildMeshes();
368
+ if (photoDomeMeshes === null || photoDomeMeshes === void 0 ? void 0 : photoDomeMeshes.length) {
369
+ exclude = [...exclude, ...photoDomeMeshes];
370
+ }
371
+ const envHelper = (_a = this.scene.metadata) === null || _a === void 0 ? void 0 : _a[babylonHelper_1.envHelperMetadataName];
372
+ if (envHelper === null || envHelper === void 0 ? void 0 : envHelper.rootMesh) {
373
+ exclude = [...exclude, envHelper.rootMesh];
374
+ }
375
+ // get bounding box of all visible meshes, this is the base for the autofocus algorithm
376
+ const boundingBox = yield this.calculateBoundingBox(exclude);
377
+ // focus the helper camera and set the calculated camera data to the real camera
378
+ const helperCamera = this.getFocusedHelperCamera(boundingBox, settings);
379
+ yield this.applyFocusedHelperCameraData(activeCamera, helperCamera, settings);
380
+ // remove the helper camera
381
+ helperCamera.dispose();
382
+ });
383
+ }
384
+ /**
385
+ * Resets everything by calling {@link destroy} to clear all references and {@link bootstrap} to setup a clean
386
+ * environment
387
+ */
388
+ reset() {
389
+ return __awaiter(this, void 0, void 0, function* () {
390
+ yield this.destroy();
391
+ return this.bootstrap();
392
+ });
393
+ }
394
+ /**
395
+ * Destroys
396
+ *
397
+ * * all {@link VariantInstance}s using {@link destroyVariantInstances}
398
+ * * calling `dispose` on the `Engine` and `Scene`
399
+ */
400
+ destroy() {
401
+ this.destroyVariantInstances();
402
+ this.scene.dispose();
403
+ specStorage_1.SpecStorage.destroy();
404
+ return this;
405
+ }
406
+ /**
407
+ * Show coordinate system with given dimension (for debugging purpose).
408
+ */
409
+ showWorldCoordinates(dimension) {
410
+ const scene = this.scene;
411
+ const makeTextPlane = function (text, color, size) {
412
+ const dynamicTexture = new dynamicTexture_1.DynamicTexture('DynamicTexture', 50, scene, true);
413
+ dynamicTexture.hasAlpha = true;
414
+ dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
415
+ const plane = mesh_1.Mesh.CreatePlane('TextPlane', size, scene, true);
416
+ plane.material = new standardMaterial_1.StandardMaterial('TextPlaneMaterial', scene);
417
+ plane.material.backFaceCulling = false;
418
+ plane.material.specularColor = new math_color_1.Color3(0, 0, 0);
419
+ plane.material.diffuseTexture = dynamicTexture;
420
+ return plane;
421
+ };
422
+ const axisX = mesh_1.Mesh.CreateLines('axisX', [
423
+ math_vector_1.Vector3.Zero(),
424
+ new math_vector_1.Vector3(dimension, 0, 0),
425
+ new math_vector_1.Vector3(dimension * 0.95, 0.05 * dimension, 0),
426
+ new math_vector_1.Vector3(dimension, 0, 0),
427
+ new math_vector_1.Vector3(dimension * 0.95, -0.05 * dimension, 0),
428
+ ], scene, false);
429
+ axisX.color = new math_color_1.Color3(1, 0, 0);
430
+ const xChar = makeTextPlane('X', 'red', dimension / 10);
431
+ xChar.position = new math_vector_1.Vector3(0.9 * dimension, -0.05 * dimension, 0);
432
+ const axisY = mesh_1.Mesh.CreateLines('axisY', [
433
+ math_vector_1.Vector3.Zero(),
434
+ new math_vector_1.Vector3(0, dimension, 0),
435
+ new math_vector_1.Vector3(-0.05 * dimension, dimension * 0.95, 0),
436
+ new math_vector_1.Vector3(0, dimension, 0),
437
+ new math_vector_1.Vector3(0.05 * dimension, dimension * 0.95, 0),
438
+ ], scene, false);
439
+ axisY.color = new math_color_1.Color3(0, 1, 0);
440
+ const yChar = makeTextPlane('Y', 'green', dimension / 10);
441
+ yChar.position = new math_vector_1.Vector3(0, 0.9 * dimension, -0.05 * dimension);
442
+ const axisZ = mesh_1.Mesh.CreateLines('axisZ', [
443
+ math_vector_1.Vector3.Zero(),
444
+ new math_vector_1.Vector3(0, 0, dimension),
445
+ new math_vector_1.Vector3(0, -0.05 * dimension, dimension * 0.95),
446
+ new math_vector_1.Vector3(0, 0, dimension),
447
+ new math_vector_1.Vector3(0, 0.05 * dimension, dimension * 0.95),
448
+ ], scene, false);
449
+ axisZ.color = new math_color_1.Color3(0, 0, 1);
450
+ const zChar = makeTextPlane('Z', 'blue', dimension / 10);
451
+ zChar.position = new math_vector_1.Vector3(0, 0.05 * dimension, 0.9 * dimension);
452
+ }
453
+ /**
454
+ * Pause render loop.
455
+ */
456
+ pauseRendering() {
457
+ this._isRenderLoopPaused = true;
458
+ }
459
+ /**
460
+ * Resume render loop when paused.
461
+ */
462
+ resumeRendering() {
463
+ this._isRenderLoopPaused = false;
464
+ }
465
+ /**
466
+ * @emits {@link Event.SCENE_PROCESSING_START}
467
+ * @emits {@link Event.SCENE_PROCESSING_END}
468
+ */
469
+ initScene() {
470
+ var _a, _b, _c;
471
+ return __awaiter(this, void 0, void 0, function* () {
472
+ const sceneJson = specStorage_1.SpecStorage.get('scene');
473
+ this.broadcastEvent(event_1.Event.SCENE_PROCESSING_START, sceneJson);
474
+ const engine = new engine_1.Engine(this.canvas, (_b = (_a = sceneJson.engine) === null || _a === void 0 ? void 0 : _a.antialiasing) !== null && _b !== void 0 ? _b : false, (_c = sceneJson.engine) === null || _c === void 0 ? void 0 : _c.options);
475
+ const scene = yield (0, sceneSetup_1.sceneSetup)(engine, sceneJson);
476
+ if (sceneJson.meshPicking) {
477
+ new highlightLayer_1.HighlightLayer('default', scene);
478
+ scene.onPointerPick = (pointerEvent, pickInfo) => {
479
+ if (!pickInfo.hit) {
480
+ return;
481
+ }
482
+ const mesh = pickInfo.pickedMesh;
483
+ this.broadcastEvent(event_1.Event.MESH_PICKED, mesh, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element, mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant);
484
+ if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.element) {
485
+ this.broadcastEvent(event_1.Event.ELEMENT_PICKED, mesh.metadata.element);
486
+ }
487
+ if (mesh === null || mesh === void 0 ? void 0 : mesh.metadata.variant) {
488
+ if (mesh.metadata.variant.inheritedParameters[parameter_1.Parameter.HIGHLIGHT_ENABLED]) {
489
+ mesh.metadata.variant.toggleHighlight();
490
+ }
491
+ this.broadcastEvent(event_1.Event.VARIANT_PICKED, mesh.metadata.variant);
492
+ }
493
+ };
494
+ }
495
+ this._sceneManager = yield sceneManager_1.SceneManager.create(scene);
496
+ this._animationManager = yield animationManager_1.AnimationManager.create(scene);
497
+ if (sceneJson.cloneMaterialsOnMutation !== undefined) {
498
+ this._cloneMaterialsOnMutation = sceneJson.cloneMaterialsOnMutation;
499
+ }
500
+ this.broadcastEvent(event_1.Event.SCENE_PROCESSING_END, scene);
501
+ return scene;
502
+ });
503
+ }
504
+ /**
505
+ * Register custom file loader for babylon files which adds "missing-material" metadata to meshes which reference
506
+ * materials that are not present in the `materials` section of the given babylon file.
507
+ *
508
+ * Required for babylon files & materials loaded from "Combeenation configurator assets".
509
+ */
510
+ initCbnBabylonLoaderPlugin() {
511
+ const previousLoaderPlugin = sceneLoader_1.SceneLoader.GetPluginForExtension('babylon');
512
+ const customLoaderPlugin = (0, sceneLoaderHelper_1.getCustomCbnBabylonLoaderPlugin)(previousLoaderPlugin);
513
+ sceneLoader_1.SceneLoader.RegisterPlugin(customLoaderPlugin);
514
+ }
515
+ /**
516
+ * Batch creation of multiple {@link VariantInstance} objects with a {@link SetupJson} object passed
517
+ */
518
+ createVariantInstances() {
519
+ return __awaiter(this, void 0, void 0, function* () {
520
+ const setupJson = specStorage_1.SpecStorage.get('setup');
521
+ const instances = [];
522
+ for (const instanceDefinition of setupJson.instances) {
523
+ if (instanceDefinition.lazy) {
524
+ this.variantInstances.register(instanceDefinition);
525
+ continue;
526
+ }
527
+ instances.push(yield this.variantInstances.create(instanceDefinition.variant, instanceDefinition.name, instanceDefinition.parameters));
528
+ }
529
+ return instances;
530
+ });
531
+ }
532
+ /**
533
+ * Help function for focusing a helper camera exactly onto the given bounding box
534
+ */
535
+ getFocusedHelperCamera(boundingBox, settings) {
536
+ var _a, _b;
537
+ // use helper camera to get some default values and set the values of the real camera accordingly
538
+ const helperCamera = new arcRotateCamera_1.ArcRotateCamera('__helper_camera__', 0, // camera angles will be overwritten after the target has been set
539
+ 0, 0, // radius will be calculated, so we can set to 0 here
540
+ math_vector_1.Vector3.Zero(), this.scene);
541
+ // this is required for automatically calculating the `lowerRadiusLimit`, so that we don't "dive" into meshes
542
+ // see https://doc.babylonjs.com/divingDeeper/behaviors/cameraBehaviors#framing-behavior
543
+ helperCamera.useFramingBehavior = true;
544
+ // `minZ` is the camera distance beyond which the mesh will be clipped
545
+ // this should be very low, but can't be zero
546
+ // a good value seems to be 1% of the bounding box size (= radius), whereas the value shouldn't go above 1, which is
547
+ // also the default value
548
+ const radius = boundingBox.getBoundingInfo().boundingSphere.radius;
549
+ helperCamera.minZ = Math.min(radius / 100, 1);
550
+ // set desired camera data, these won't be changed by the autofocus function!
551
+ // default values should focus the element exactly from the front (= XY Plane)
552
+ helperCamera.setTarget(boundingBox, true);
553
+ helperCamera.alpha = ((_a = settings === null || settings === void 0 ? void 0 : settings.alpha) !== null && _a !== void 0 ? _a : -90) * (Math.PI / 180);
554
+ helperCamera.beta = ((_b = settings === null || settings === void 0 ? void 0 : settings.beta) !== null && _b !== void 0 ? _b : 90) * (Math.PI / 180);
555
+ // finally zoom to the bounding box
556
+ // also apply a zoom factor, this adjusts the borders around the model in the viewport
557
+ helperCamera.zoomOnFactor = (settings === null || settings === void 0 ? void 0 : settings.radiusFactor) || 1;
558
+ helperCamera.zoomOn([boundingBox], true);
559
+ return helperCamera;
560
+ }
561
+ /**
562
+ * Help function for applying the relevant data of the focused helper camera to the real camera
563
+ */
564
+ applyFocusedHelperCameraData(activeCamera, helperCamera, settings) {
565
+ return __awaiter(this, void 0, void 0, function* () {
566
+ // limits
567
+ activeCamera.minZ = helperCamera.minZ;
568
+ activeCamera.maxZ = helperCamera.maxZ;
569
+ activeCamera.lowerRadiusLimit = helperCamera.lowerRadiusLimit;
570
+ activeCamera.upperRadiusLimit = helperCamera.upperRadiusLimit;
571
+ // additional settings
572
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustWheelPrecision) !== false) {
573
+ activeCamera.wheelPrecision = helperCamera.wheelPrecision;
574
+ }
575
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPanningSensibility) !== false) {
576
+ activeCamera.panningSensibility = helperCamera.panningSensibility;
577
+ }
578
+ if ((settings === null || settings === void 0 ? void 0 : settings.adjustPinchPrecision) !== false) {
579
+ activeCamera.pinchPrecision = helperCamera.pinchPrecision;
580
+ }
581
+ // finally move the camera
582
+ // do this at last, so that all camera settings are already considered
583
+ const newCameraPosition = {
584
+ alpha: helperCamera.alpha,
585
+ beta: helperCamera.beta,
586
+ radius: helperCamera.radius,
587
+ target: helperCamera.target,
588
+ };
589
+ yield this.animationManager.animateToPlacement(activeCamera, newCameraPosition, settings === null || settings === void 0 ? void 0 : settings.animation);
590
+ });
591
+ }
592
+ }
593
+ exports.Viewer = Viewer;
594
+ Viewer.version = buildinfo_json_1.default.version;
595
595
  //# sourceMappingURL=viewer.js.map