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