@combeenation/3d-viewer 5.1.2 → 5.2.0-alpha4

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