@babylonjs/viewer 7.22.0-alpha → 7.22.0

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 (198) hide show
  1. package/configuration/configuration.d.ts +107 -0
  2. package/configuration/configuration.js +16 -0
  3. package/configuration/configuration.js.map +1 -0
  4. package/configuration/configurationCompatibility.d.ts +8 -0
  5. package/configuration/configurationCompatibility.js +66 -0
  6. package/configuration/configurationCompatibility.js.map +1 -0
  7. package/configuration/configurationContainer.d.ts +10 -0
  8. package/configuration/configurationContainer.js +10 -0
  9. package/configuration/configurationContainer.js.map +1 -0
  10. package/configuration/globals.d.ts +6 -0
  11. package/configuration/globals.js +18 -0
  12. package/configuration/globals.js.map +1 -0
  13. package/configuration/index.d.ts +2 -0
  14. package/configuration/index.js +4 -0
  15. package/configuration/index.js.map +1 -0
  16. package/configuration/interfaces/cameraConfiguration.d.ts +31 -0
  17. package/configuration/interfaces/cameraConfiguration.js +2 -0
  18. package/configuration/interfaces/cameraConfiguration.js.map +1 -0
  19. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -0
  20. package/configuration/interfaces/colorGradingConfiguration.js +2 -0
  21. package/configuration/interfaces/colorGradingConfiguration.js.map +1 -0
  22. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -0
  23. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +2 -0
  24. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -0
  25. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -0
  26. package/configuration/interfaces/environmentMapConfiguration.js +2 -0
  27. package/configuration/interfaces/environmentMapConfiguration.js.map +1 -0
  28. package/configuration/interfaces/groundConfiguration.d.ts +24 -0
  29. package/configuration/interfaces/groundConfiguration.js +2 -0
  30. package/configuration/interfaces/groundConfiguration.js.map +1 -0
  31. package/configuration/interfaces/imageProcessingConfiguration.d.ts +45 -0
  32. package/configuration/interfaces/imageProcessingConfiguration.js +2 -0
  33. package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -0
  34. package/configuration/interfaces/index.d.ts +15 -0
  35. package/configuration/interfaces/index.js +16 -0
  36. package/configuration/interfaces/index.js.map +1 -0
  37. package/configuration/interfaces/lightConfiguration.d.ts +60 -0
  38. package/configuration/interfaces/lightConfiguration.js +2 -0
  39. package/configuration/interfaces/lightConfiguration.js.map +1 -0
  40. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -0
  41. package/configuration/interfaces/modelAnimationConfiguration.js +2 -0
  42. package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -0
  43. package/configuration/interfaces/modelConfiguration.d.ts +65 -0
  44. package/configuration/interfaces/modelConfiguration.js +2 -0
  45. package/configuration/interfaces/modelConfiguration.js.map +1 -0
  46. package/configuration/interfaces/observersConfiguration.d.ts +5 -0
  47. package/configuration/interfaces/observersConfiguration.js +2 -0
  48. package/configuration/interfaces/observersConfiguration.js.map +1 -0
  49. package/configuration/interfaces/sceneConfiguration.d.ts +48 -0
  50. package/configuration/interfaces/sceneConfiguration.js +2 -0
  51. package/configuration/interfaces/sceneConfiguration.js.map +1 -0
  52. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -0
  53. package/configuration/interfaces/sceneOptimizerConfiguration.js +2 -0
  54. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -0
  55. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -0
  56. package/configuration/interfaces/skyboxConfiguration.js +2 -0
  57. package/configuration/interfaces/skyboxConfiguration.js.map +1 -0
  58. package/configuration/interfaces/templateConfiguration.d.ts +67 -0
  59. package/configuration/interfaces/templateConfiguration.js +2 -0
  60. package/configuration/interfaces/templateConfiguration.js.map +1 -0
  61. package/configuration/interfaces/vrConfiguration.d.ts +16 -0
  62. package/configuration/interfaces/vrConfiguration.js +2 -0
  63. package/configuration/interfaces/vrConfiguration.js.map +1 -0
  64. package/configuration/loader.d.ts +4 -0
  65. package/configuration/loader.js +17 -0
  66. package/configuration/loader.js.map +1 -0
  67. package/configuration/mappers.d.ts +43 -0
  68. package/configuration/mappers.js +192 -0
  69. package/configuration/mappers.js.map +1 -0
  70. package/configuration/renderOnlyLoader.d.ts +33 -0
  71. package/configuration/renderOnlyLoader.js +162 -0
  72. package/configuration/renderOnlyLoader.js.map +1 -0
  73. package/configuration/types/default.d.ts +6 -0
  74. package/configuration/types/default.js +121 -0
  75. package/configuration/types/default.js.map +1 -0
  76. package/configuration/types/environmentMap.d.ts +5 -0
  77. package/configuration/types/environmentMap.js +14 -0
  78. package/configuration/types/environmentMap.js.map +1 -0
  79. package/configuration/types/extended.d.ts +6 -0
  80. package/configuration/types/extended.js +317 -0
  81. package/configuration/types/extended.js.map +1 -0
  82. package/configuration/types/index.d.ts +14 -0
  83. package/configuration/types/index.js +51 -0
  84. package/configuration/types/index.js.map +1 -0
  85. package/configuration/types/minimal.d.ts +6 -0
  86. package/configuration/types/minimal.js +43 -0
  87. package/configuration/types/minimal.js.map +1 -0
  88. package/configuration/types/renderOnlyDefault.d.ts +30 -0
  89. package/configuration/types/renderOnlyDefault.js +31 -0
  90. package/configuration/types/renderOnlyDefault.js.map +1 -0
  91. package/configuration/types/shadowLight.d.ts +9 -0
  92. package/configuration/types/shadowLight.js +64 -0
  93. package/configuration/types/shadowLight.js.map +1 -0
  94. package/helper/index.d.ts +29 -0
  95. package/helper/index.js +66 -0
  96. package/helper/index.js.map +1 -0
  97. package/index.d.ts +30 -0
  98. package/index.js +46 -0
  99. package/index.js.map +1 -0
  100. package/initializer.d.ts +11 -0
  101. package/initializer.js +35 -0
  102. package/initializer.js.map +1 -0
  103. package/interfaces.d.ts +5 -0
  104. package/interfaces.js +7 -0
  105. package/interfaces.js.map +1 -0
  106. package/labs/environmentSerializer.d.ts +126 -0
  107. package/labs/environmentSerializer.js +191 -0
  108. package/labs/environmentSerializer.js.map +1 -0
  109. package/labs/texture.d.ts +183 -0
  110. package/labs/texture.js +351 -0
  111. package/labs/texture.js.map +1 -0
  112. package/labs/viewerLabs.d.ts +51 -0
  113. package/labs/viewerLabs.js +134 -0
  114. package/labs/viewerLabs.js.map +1 -0
  115. package/loader/modelLoader.d.ts +56 -0
  116. package/loader/modelLoader.js +199 -0
  117. package/loader/modelLoader.js.map +1 -0
  118. package/loader/plugins/applyMaterialConfig.d.ts +12 -0
  119. package/loader/plugins/applyMaterialConfig.js +16 -0
  120. package/loader/plugins/applyMaterialConfig.js.map +1 -0
  121. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -0
  122. package/loader/plugins/extendedMaterialLoaderPlugin.js +16 -0
  123. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -0
  124. package/loader/plugins/index.d.ts +19 -0
  125. package/loader/plugins/index.js +44 -0
  126. package/loader/plugins/index.js.map +1 -0
  127. package/loader/plugins/loaderPlugin.d.ts +24 -0
  128. package/loader/plugins/loaderPlugin.js +2 -0
  129. package/loader/plugins/loaderPlugin.js.map +1 -0
  130. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -0
  131. package/loader/plugins/msftLodLoaderPlugin.js +21 -0
  132. package/loader/plugins/msftLodLoaderPlugin.js.map +1 -0
  133. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -0
  134. package/loader/plugins/telemetryLoaderPlugin.js +36 -0
  135. package/loader/plugins/telemetryLoaderPlugin.js.map +1 -0
  136. package/managers/observablesManager.d.ts +66 -0
  137. package/managers/observablesManager.js +35 -0
  138. package/managers/observablesManager.js.map +1 -0
  139. package/managers/sceneManager.d.ts +245 -0
  140. package/managers/sceneManager.js +1375 -0
  141. package/managers/sceneManager.js.map +1 -0
  142. package/managers/telemetryManager.d.ts +78 -0
  143. package/managers/telemetryManager.js +117 -0
  144. package/managers/telemetryManager.js.map +1 -0
  145. package/model/modelAnimation.d.ts +215 -0
  146. package/model/modelAnimation.js +237 -0
  147. package/model/modelAnimation.js.map +1 -0
  148. package/model/viewerModel.d.ts +233 -0
  149. package/model/viewerModel.js +673 -0
  150. package/model/viewerModel.js.map +1 -0
  151. package/optimizer/custom/extended.d.ts +13 -0
  152. package/optimizer/custom/extended.js +101 -0
  153. package/optimizer/custom/extended.js.map +1 -0
  154. package/optimizer/custom/index.d.ts +9 -0
  155. package/optimizer/custom/index.js +26 -0
  156. package/optimizer/custom/index.js.map +1 -0
  157. package/package.json +29 -16
  158. package/readme.md +21 -35
  159. package/renderOnlyIndex.d.ts +11 -0
  160. package/renderOnlyIndex.js +18 -0
  161. package/renderOnlyIndex.js.map +1 -0
  162. package/templating/eventManager.d.ts +35 -0
  163. package/templating/eventManager.js +66 -0
  164. package/templating/eventManager.js.map +1 -0
  165. package/templating/plugins/hdButtonPlugin.d.ts +9 -0
  166. package/templating/plugins/hdButtonPlugin.js +21 -0
  167. package/templating/plugins/hdButtonPlugin.js.map +1 -0
  168. package/templating/plugins/printButton.d.ts +9 -0
  169. package/templating/plugins/printButton.js +40 -0
  170. package/templating/plugins/printButton.js.map +1 -0
  171. package/templating/templateManager.d.ts +197 -0
  172. package/templating/templateManager.js +561 -0
  173. package/templating/templateManager.js.map +1 -0
  174. package/templating/viewerTemplatePlugin.d.ts +21 -0
  175. package/templating/viewerTemplatePlugin.js +69 -0
  176. package/templating/viewerTemplatePlugin.js.map +1 -0
  177. package/viewer/defaultViewer.d.ts +130 -0
  178. package/viewer/defaultViewer.js +675 -0
  179. package/viewer/defaultViewer.js.map +1 -0
  180. package/viewer/renderOnlyViewer.d.ts +9 -0
  181. package/viewer/renderOnlyViewer.js +46 -0
  182. package/viewer/renderOnlyViewer.js.map +1 -0
  183. package/viewer/viewer.d.ts +258 -0
  184. package/viewer/viewer.js +783 -0
  185. package/viewer/viewer.js.map +1 -0
  186. package/viewer/viewerManager.d.ts +58 -0
  187. package/viewer/viewerManager.js +91 -0
  188. package/viewer/viewerManager.js.map +1 -0
  189. package/viewer/viewerWithTemplate.d.ts +9 -0
  190. package/viewer/viewerWithTemplate.js +20 -0
  191. package/viewer/viewerWithTemplate.js.map +1 -0
  192. package/dist/babylon-viewer.esm.js +0 -116321
  193. package/dist/babylon-viewer.esm.js.map +0 -1
  194. package/dist/babylon-viewer.esm.min.js +0 -2
  195. package/dist/babylon-viewer.esm.min.js.map +0 -1
  196. package/lib/index.d.ts +0 -132
  197. package/lib/index.js +0 -369
  198. package/lib/index.js.map +0 -1
@@ -0,0 +1,673 @@
1
+ import { Observable } from "@babylonjs/core/Misc/observable.js";
2
+ import "@babylonjs/core/Misc/observable.extensions.js";
3
+ import { AnimationGroup } from "@babylonjs/core/Animations/animationGroup.js";
4
+ import { Animation, CircleEase, BackEase, BounceEase, CubicEase, ElasticEase, ExponentialEase, PowerEase, QuadraticEase, QuarticEase, QuinticEase, SineEase, } from "@babylonjs/core/Animations/index.js";
5
+ import { Quaternion, Vector3 } from "@babylonjs/core/Maths/math.vector.js";
6
+ import { Tags } from "@babylonjs/core/Misc/tags.js";
7
+ import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
8
+ import { MultiMaterial } from "@babylonjs/core/Materials/multiMaterial.js";
9
+ import { Tools } from "@babylonjs/core/Misc/tools.js";
10
+ import { GroupModelAnimation, AnimationPlayMode, EasingFunction, AnimationState } from "./modelAnimation.js";
11
+ import { deepmerge, extendClassWithConfig } from "../helper/index.js";
12
+ import { TransformNode } from "@babylonjs/core/Meshes/transformNode.js";
13
+ import { Mesh } from "@babylonjs/core/Meshes/mesh.js";
14
+ /**
15
+ * The current state of the model
16
+ */
17
+ export var ModelState;
18
+ (function (ModelState) {
19
+ ModelState[ModelState["INIT"] = 0] = "INIT";
20
+ ModelState[ModelState["LOADING"] = 1] = "LOADING";
21
+ ModelState[ModelState["LOADED"] = 2] = "LOADED";
22
+ ModelState[ModelState["ENTRY"] = 3] = "ENTRY";
23
+ ModelState[ModelState["ENTRYDONE"] = 4] = "ENTRYDONE";
24
+ ModelState[ModelState["COMPLETE"] = 5] = "COMPLETE";
25
+ ModelState[ModelState["CANCELED"] = 6] = "CANCELED";
26
+ ModelState[ModelState["ERROR"] = 7] = "ERROR";
27
+ })(ModelState || (ModelState = {}));
28
+ /**
29
+ * The viewer model is a container for all assets representing a sngle loaded model.
30
+ */
31
+ var ViewerModel = /** @class */ (function () {
32
+ function ViewerModel(_observablesManager, modelConfiguration, _configurationContainer) {
33
+ var _this = this;
34
+ this._observablesManager = _observablesManager;
35
+ this._configurationContainer = _configurationContainer;
36
+ /**
37
+ * the list of meshes that are a part of this model
38
+ */
39
+ this._meshes = [];
40
+ /**
41
+ * ParticleSystems connected to this model
42
+ */
43
+ this.particleSystems = [];
44
+ /**
45
+ * Skeletons defined in this model
46
+ */
47
+ this.skeletons = [];
48
+ this._loaderDone = false;
49
+ this._animatables = [];
50
+ this._frameRate = 60;
51
+ this._shadowsRenderedAfterLoad = false;
52
+ this.onLoadedObservable = new Observable();
53
+ this.onLoadErrorObservable = new Observable();
54
+ this.onLoadProgressObservable = new Observable();
55
+ this.onCompleteObservable = new Observable();
56
+ this.onAfterConfigure = new Observable();
57
+ this.state = ModelState.INIT;
58
+ var scene = this._configurationContainer && this._configurationContainer.scene;
59
+ this.rootMesh = new Mesh("modelRootMesh", scene);
60
+ this._pivotMesh = new TransformNode("pivotMesh", scene);
61
+ this._pivotMesh.parent = this.rootMesh;
62
+ // rotate 180, gltf fun
63
+ this._pivotMesh.rotation.y += Math.PI;
64
+ this._scaleTransition = new Animation("scaleAnimation", "scaling", this._frameRate, Animation.ANIMATIONTYPE_VECTOR3, Animation.ANIMATIONLOOPMODE_CONSTANT);
65
+ this._animations = [];
66
+ //create a copy of the configuration to make sure it doesn't change even after it is changed in the viewer
67
+ this._modelConfiguration = deepmerge((this._configurationContainer && this._configurationContainer.configuration.model) || {}, modelConfiguration);
68
+ if (this._observablesManager) {
69
+ this._observablesManager.onModelAddedObservable.notifyObservers(this);
70
+ }
71
+ if (this._modelConfiguration.entryAnimation) {
72
+ this.rootMesh.setEnabled(false);
73
+ }
74
+ this.onLoadedObservable.add(function () {
75
+ _this.updateConfiguration(_this._modelConfiguration);
76
+ if (_this._observablesManager) {
77
+ _this._observablesManager.onModelLoadedObservable.notifyObservers(_this);
78
+ }
79
+ _this._initAnimations();
80
+ });
81
+ this.onCompleteObservable.add(function () {
82
+ _this.state = ModelState.COMPLETE;
83
+ });
84
+ }
85
+ Object.defineProperty(ViewerModel.prototype, "shadowsRenderedAfterLoad", {
86
+ get: function () {
87
+ return this._shadowsRenderedAfterLoad;
88
+ },
89
+ set: function (rendered) {
90
+ if (!rendered) {
91
+ throw new Error("can only be enabled");
92
+ }
93
+ else {
94
+ this._shadowsRenderedAfterLoad = rendered;
95
+ }
96
+ },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
100
+ ViewerModel.prototype.getViewerId = function () {
101
+ return this._configurationContainer && this._configurationContainer.viewerId;
102
+ };
103
+ Object.defineProperty(ViewerModel.prototype, "enabled", {
104
+ /**
105
+ * Is this model enabled?
106
+ */
107
+ get: function () {
108
+ return this.rootMesh.isEnabled();
109
+ },
110
+ /**
111
+ * Set whether this model is enabled or not.
112
+ */
113
+ set: function (enable) {
114
+ this.rootMesh.setEnabled(enable);
115
+ },
116
+ enumerable: false,
117
+ configurable: true
118
+ });
119
+ Object.defineProperty(ViewerModel.prototype, "loaderDone", {
120
+ set: function (done) {
121
+ this._loaderDone = done;
122
+ this._checkCompleteState();
123
+ },
124
+ enumerable: false,
125
+ configurable: true
126
+ });
127
+ ViewerModel.prototype._checkCompleteState = function () {
128
+ if (this._loaderDone && this.state === ModelState.ENTRYDONE) {
129
+ this._modelComplete();
130
+ }
131
+ };
132
+ /**
133
+ * Add a mesh to this model.
134
+ * Any mesh that has no parent will be provided with the root mesh as its new parent.
135
+ *
136
+ * @param mesh the new mesh to add
137
+ * @param triggerLoaded should this mesh trigger the onLoaded observable. Used when adding meshes manually.
138
+ * @returns a promise that will resolve when the model is done loading
139
+ */
140
+ ViewerModel.prototype.addMesh = function (mesh, triggerLoaded) {
141
+ if (!mesh.parent) {
142
+ mesh.parent = this._pivotMesh;
143
+ }
144
+ if (mesh.getClassName() !== "InstancedMesh") {
145
+ mesh.receiveShadows = !!this.configuration.receiveShadows;
146
+ }
147
+ this._meshes.push(mesh);
148
+ if (triggerLoaded) {
149
+ return this.onLoadedObservable.notifyObserversWithPromise(this);
150
+ }
151
+ return Promise.resolve(this);
152
+ };
153
+ Object.defineProperty(ViewerModel.prototype, "meshes", {
154
+ /**
155
+ * get the list of meshes (excluding the root mesh)
156
+ */
157
+ get: function () {
158
+ return this._meshes;
159
+ },
160
+ enumerable: false,
161
+ configurable: true
162
+ });
163
+ Object.defineProperty(ViewerModel.prototype, "configuration", {
164
+ /**
165
+ * Get the model's configuration
166
+ */
167
+ get: function () {
168
+ return this._modelConfiguration;
169
+ },
170
+ /**
171
+ * (Re-)set the model's entire configuration
172
+ * @param newConfiguration the new configuration to replace the new one
173
+ */
174
+ set: function (newConfiguration) {
175
+ this._modelConfiguration = newConfiguration;
176
+ this._configureModel();
177
+ },
178
+ enumerable: false,
179
+ configurable: true
180
+ });
181
+ /**
182
+ * Update the current configuration with new values.
183
+ * Configuration will not be overwritten, but merged with the new configuration.
184
+ * Priority is to the new configuration
185
+ * @param newConfiguration the configuration to be merged into the current configuration;
186
+ */
187
+ ViewerModel.prototype.updateConfiguration = function (newConfiguration) {
188
+ this._modelConfiguration = deepmerge(this._modelConfiguration, newConfiguration);
189
+ this._configureModel();
190
+ };
191
+ ViewerModel.prototype._initAnimations = function () {
192
+ var _this = this;
193
+ // check if this is not a gltf loader and init the animations
194
+ if (this.skeletons.length) {
195
+ this.skeletons.forEach(function (skeleton, idx) {
196
+ var ag = new AnimationGroup("animation-" + idx, _this._configurationContainer && _this._configurationContainer.scene);
197
+ var add = false;
198
+ skeleton.getAnimatables().forEach(function (a) {
199
+ if (a.animations && a.animations[0]) {
200
+ ag.addTargetedAnimation(a.animations[0], a);
201
+ add = true;
202
+ }
203
+ });
204
+ if (add) {
205
+ _this.addAnimationGroup(ag);
206
+ }
207
+ });
208
+ }
209
+ var completeCallback = function () { };
210
+ if (this._modelConfiguration.animation) {
211
+ if (this._modelConfiguration.animation.playOnce) {
212
+ this._animations.forEach(function (a) {
213
+ a.playMode = AnimationPlayMode.ONCE;
214
+ });
215
+ }
216
+ if (this._modelConfiguration.animation.autoStart && this._animations.length) {
217
+ var animationName_1 = this._modelConfiguration.animation.autoStart === true ? this._animations[0].name : this._modelConfiguration.animation.autoStart;
218
+ completeCallback = function () {
219
+ _this.playAnimation(animationName_1);
220
+ };
221
+ }
222
+ }
223
+ this._enterScene(completeCallback);
224
+ };
225
+ /**
226
+ * Animates the model from the current position to the default position
227
+ * @param completeCallback A function to call when the animation has completed
228
+ */
229
+ ViewerModel.prototype._enterScene = function (completeCallback) {
230
+ var _this = this;
231
+ var scene = this.rootMesh.getScene();
232
+ var previousValue = scene.animationPropertiesOverride.enableBlending;
233
+ var callback = function () {
234
+ _this.state = ModelState.ENTRYDONE;
235
+ scene.animationPropertiesOverride.enableBlending = previousValue;
236
+ _this._checkCompleteState();
237
+ if (completeCallback) {
238
+ completeCallback();
239
+ }
240
+ };
241
+ if (!this._entryAnimation) {
242
+ callback();
243
+ return;
244
+ }
245
+ this.rootMesh.setEnabled(true);
246
+ // disable blending for the sake of the entry animation;
247
+ scene.animationPropertiesOverride.enableBlending = false;
248
+ this._applyAnimation(this._entryAnimation, true, callback);
249
+ };
250
+ // /**
251
+ // * Animates the model from the current position to the exit-screen position
252
+ // * @param completeCallback A function to call when the animation has completed
253
+ // */
254
+ // private _exitScene(completeCallback: () => void): void {
255
+ // if (!this._exitAnimation) {
256
+ // completeCallback();
257
+ // return;
258
+ // }
259
+ // this._applyAnimation(this._exitAnimation, false, completeCallback);
260
+ // }
261
+ ViewerModel.prototype._modelComplete = function () {
262
+ var _this = this;
263
+ //reapply material defines to be sure:
264
+ var meshes = this._pivotMesh.getChildMeshes(false);
265
+ meshes
266
+ .filter(function (m) { return m.material; })
267
+ .forEach(function (mesh) {
268
+ _this._applyModelMaterialConfiguration(mesh.material);
269
+ });
270
+ this.state = ModelState.COMPLETE;
271
+ this.onCompleteObservable.notifyObservers(this);
272
+ };
273
+ /**
274
+ * Add a new animation group to this model.
275
+ * @param animationGroup the new animation group to be added
276
+ */
277
+ ViewerModel.prototype.addAnimationGroup = function (animationGroup) {
278
+ this._animations.push(new GroupModelAnimation(animationGroup));
279
+ };
280
+ /**
281
+ * Get the ModelAnimation array
282
+ * @returns the array of ModelAnimations
283
+ */
284
+ ViewerModel.prototype.getAnimations = function () {
285
+ return this._animations;
286
+ };
287
+ /**
288
+ * Get the animations' names. Using the names you can play a specific animation.
289
+ * @returns the array of ModelAnimations
290
+ */
291
+ ViewerModel.prototype.getAnimationNames = function () {
292
+ return this._animations.map(function (a) { return a.name; });
293
+ };
294
+ /**
295
+ * Get an animation by the provided name. Used mainly when playing n animation.
296
+ * @param name the name of the animation to find
297
+ * @returns the ModelAnimation object
298
+ */
299
+ ViewerModel.prototype._getAnimationByName = function (name) {
300
+ // can't use .find, noe available on IE
301
+ var filtered = this._animations.filter(function (a) { return a.name === name.trim(); });
302
+ if (filtered.length >= 1) {
303
+ return filtered[0];
304
+ }
305
+ else {
306
+ return null;
307
+ }
308
+ };
309
+ /**
310
+ * Choose an initialized animation using its name and start playing it
311
+ * @param name the name of the animation to play
312
+ * @returns The model aniamtion to be played.
313
+ */
314
+ ViewerModel.prototype.playAnimation = function (name) {
315
+ var animation = this.setCurrentAnimationByName(name);
316
+ if (animation) {
317
+ animation.start();
318
+ }
319
+ return animation;
320
+ };
321
+ ViewerModel.prototype.setCurrentAnimationByName = function (name) {
322
+ var animation = this._getAnimationByName(name.trim());
323
+ if (animation) {
324
+ if (this.currentAnimation && this.currentAnimation.state !== AnimationState.STOPPED) {
325
+ this.currentAnimation.stop();
326
+ }
327
+ this.currentAnimation = animation;
328
+ return animation;
329
+ }
330
+ else {
331
+ throw new Error("animation not found - " + name);
332
+ }
333
+ };
334
+ ViewerModel.prototype._configureModel = function () {
335
+ var _this = this;
336
+ // this can be changed to the meshes that have rootMesh a parent without breaking anything.
337
+ var meshesWithNoParent = [this.rootMesh]; //this._meshes.filter(m => m.parent === this.rootMesh);
338
+ var updateMeshesWithNoParent = function (variable, value, param) {
339
+ meshesWithNoParent.forEach(function (mesh) {
340
+ if (param) {
341
+ mesh[variable][param] = value;
342
+ }
343
+ else {
344
+ mesh[variable] = value;
345
+ }
346
+ });
347
+ };
348
+ var updateXYZ = function (variable, configValues) {
349
+ if (configValues.x !== undefined) {
350
+ updateMeshesWithNoParent(variable, configValues.x, "x");
351
+ }
352
+ if (configValues.y !== undefined) {
353
+ updateMeshesWithNoParent(variable, configValues.y, "y");
354
+ }
355
+ if (configValues.z !== undefined) {
356
+ updateMeshesWithNoParent(variable, configValues.z, "z");
357
+ }
358
+ if (configValues.w !== undefined) {
359
+ updateMeshesWithNoParent(variable, configValues.w, "w");
360
+ }
361
+ };
362
+ if (this._modelConfiguration.normalize) {
363
+ var center = false;
364
+ var unitSize = false;
365
+ var parentIndex = void 0;
366
+ if (this._modelConfiguration.normalize === true) {
367
+ center = true;
368
+ unitSize = true;
369
+ }
370
+ else {
371
+ center = !!this._modelConfiguration.normalize.center;
372
+ unitSize = !!this._modelConfiguration.normalize.unitSize;
373
+ parentIndex = this._modelConfiguration.normalize.parentIndex;
374
+ }
375
+ var meshesToNormalize = [];
376
+ if (parentIndex !== undefined) {
377
+ meshesToNormalize.push(this._meshes[parentIndex]);
378
+ }
379
+ else {
380
+ meshesToNormalize = this._pivotMesh.getChildMeshes(true).length === 1 ? [this._pivotMesh] : meshesWithNoParent;
381
+ }
382
+ if (unitSize) {
383
+ meshesToNormalize.forEach(function (mesh) {
384
+ mesh.normalizeToUnitCube(true);
385
+ mesh.computeWorldMatrix(true);
386
+ });
387
+ }
388
+ if (center) {
389
+ meshesToNormalize.forEach(function (mesh) {
390
+ var boundingInfo = mesh.getHierarchyBoundingVectors(true);
391
+ var sizeVec = boundingInfo.max.subtract(boundingInfo.min);
392
+ var halfSizeVec = sizeVec.scale(0.5);
393
+ var center = boundingInfo.min.add(halfSizeVec);
394
+ mesh.position = center.scale(-1);
395
+ mesh.position.y += halfSizeVec.y;
396
+ // Recompute Info.
397
+ mesh.computeWorldMatrix(true);
398
+ });
399
+ }
400
+ }
401
+ else {
402
+ // if centered, should be done here
403
+ }
404
+ // position?
405
+ if (this._modelConfiguration.position) {
406
+ updateXYZ("position", this._modelConfiguration.position);
407
+ }
408
+ if (this._modelConfiguration.rotation) {
409
+ //quaternion?
410
+ if (this._modelConfiguration.rotation.w) {
411
+ meshesWithNoParent.forEach(function (mesh) {
412
+ if (!mesh.rotationQuaternion) {
413
+ mesh.rotationQuaternion = new Quaternion();
414
+ }
415
+ });
416
+ updateXYZ("rotationQuaternion", this._modelConfiguration.rotation);
417
+ }
418
+ else {
419
+ updateXYZ("rotation", this._modelConfiguration.rotation);
420
+ }
421
+ }
422
+ if (this._modelConfiguration.rotationOffsetAxis) {
423
+ var rotationAxis_1 = new Vector3(this._modelConfiguration.rotationOffsetAxis.x, this._modelConfiguration.rotationOffsetAxis.y, this._modelConfiguration.rotationOffsetAxis.z);
424
+ meshesWithNoParent.forEach(function (m) {
425
+ if (_this._modelConfiguration.rotationOffsetAngle) {
426
+ m.rotate(rotationAxis_1, _this._modelConfiguration.rotationOffsetAngle);
427
+ }
428
+ });
429
+ }
430
+ if (this._modelConfiguration.scaling) {
431
+ updateXYZ("scaling", this._modelConfiguration.scaling);
432
+ }
433
+ if (this._modelConfiguration.castShadow) {
434
+ this._meshes.forEach(function (mesh) {
435
+ Tags.AddTagsTo(mesh, "castShadow");
436
+ });
437
+ }
438
+ var meshes = this._pivotMesh.getChildMeshes(false);
439
+ meshes
440
+ .filter(function (m) { return m.material; })
441
+ .forEach(function (mesh) {
442
+ _this._applyModelMaterialConfiguration(mesh.material);
443
+ });
444
+ if (this._modelConfiguration.entryAnimation) {
445
+ this._entryAnimation = this._modelAnimationConfigurationToObject(this._modelConfiguration.entryAnimation);
446
+ }
447
+ // if (this._modelConfiguration.exitAnimation) {
448
+ // this._exitAnimation = this._modelAnimationConfigurationToObject(this._modelConfiguration.exitAnimation);
449
+ // }
450
+ this.onAfterConfigure.notifyObservers(this);
451
+ };
452
+ ViewerModel.prototype._modelAnimationConfigurationToObject = function (animConfig) {
453
+ var anim = {
454
+ time: 0.5,
455
+ };
456
+ if (animConfig.scaling) {
457
+ anim.scaling = Vector3.Zero();
458
+ }
459
+ if (animConfig.easingFunction !== undefined) {
460
+ anim.easingFunction = animConfig.easingFunction;
461
+ }
462
+ if (animConfig.easingMode !== undefined) {
463
+ anim.easingMode = animConfig.easingMode;
464
+ }
465
+ extendClassWithConfig(anim, animConfig);
466
+ return anim;
467
+ };
468
+ /**
469
+ * Apply a material configuration to a material
470
+ * @param material Material to apply configuration to
471
+ * @internal
472
+ */
473
+ ViewerModel.prototype._applyModelMaterialConfiguration = function (material) {
474
+ if (!this._modelConfiguration.material) {
475
+ return;
476
+ }
477
+ extendClassWithConfig(material, this._modelConfiguration.material);
478
+ if (material instanceof PBRMaterial) {
479
+ if (this._modelConfiguration.material.directIntensity !== undefined) {
480
+ material.directIntensity = this._modelConfiguration.material.directIntensity;
481
+ }
482
+ if (this._modelConfiguration.material.emissiveIntensity !== undefined) {
483
+ material.emissiveIntensity = this._modelConfiguration.material.emissiveIntensity;
484
+ }
485
+ if (this._modelConfiguration.material.environmentIntensity !== undefined) {
486
+ material.environmentIntensity = this._modelConfiguration.material.environmentIntensity;
487
+ }
488
+ if (this._modelConfiguration.material.directEnabled !== undefined) {
489
+ material.disableLighting = !this._modelConfiguration.material.directEnabled;
490
+ }
491
+ if (this._configurationContainer && this._configurationContainer.reflectionColor) {
492
+ material.reflectionColor = this._configurationContainer.reflectionColor.clone();
493
+ }
494
+ }
495
+ else if (material instanceof MultiMaterial) {
496
+ for (var i = 0; i < material.subMaterials.length; i++) {
497
+ var subMaterial = material.subMaterials[i];
498
+ if (subMaterial) {
499
+ this._applyModelMaterialConfiguration(subMaterial);
500
+ }
501
+ }
502
+ }
503
+ };
504
+ /**
505
+ * Start entry/exit animation given an animation configuration
506
+ * @param animationConfiguration Entry/Exit animation configuration
507
+ * @param isEntry Pass true if the animation is an entry animation
508
+ * @param completeCallback Callback to execute when the animation completes
509
+ */
510
+ ViewerModel.prototype._applyAnimation = function (animationConfiguration, isEntry, completeCallback) {
511
+ var animations = [];
512
+ //scale
513
+ if (animationConfiguration.scaling) {
514
+ var scaleStart = isEntry ? animationConfiguration.scaling : new Vector3(1, 1, 1);
515
+ var scaleEnd = isEntry ? new Vector3(1, 1, 1) : animationConfiguration.scaling;
516
+ if (!scaleStart.equals(scaleEnd)) {
517
+ this.rootMesh.scaling = scaleStart;
518
+ this._setLinearKeys(this._scaleTransition, this.rootMesh.scaling, scaleEnd, animationConfiguration.time);
519
+ animations.push(this._scaleTransition);
520
+ }
521
+ }
522
+ //Start the animation(s)
523
+ this.transitionTo(animations, animationConfiguration.time, this._createEasingFunction(animationConfiguration.easingFunction), animationConfiguration.easingMode, function () {
524
+ if (completeCallback) {
525
+ completeCallback();
526
+ }
527
+ });
528
+ };
529
+ /**
530
+ * Begin @animations with the specified @easingFunction
531
+ * @param animations The BABYLON Animations to begin
532
+ * @param duration of transition, in seconds
533
+ * @param easingFunction An easing function to apply
534
+ * @param easingMode A easing mode to apply to the easingFunction
535
+ * @param onAnimationEnd Call back trigger at the end of the animation.
536
+ */
537
+ ViewerModel.prototype.transitionTo = function (animations, duration, easingFunction, easingMode, // BABYLON.EasingFunction.EASINGMODE_EASEINOUT,
538
+ onAnimationEnd) {
539
+ if (easingMode === void 0) { easingMode = 2; }
540
+ if (easingFunction) {
541
+ for (var _i = 0, animations_1 = animations; _i < animations_1.length; _i++) {
542
+ var animation = animations_1[_i];
543
+ easingFunction.setEasingMode(easingMode);
544
+ animation.setEasingFunction(easingFunction);
545
+ }
546
+ }
547
+ //Stop any current animations before starting the new one - merging not yet supported.
548
+ this.stopAllAnimations();
549
+ this.rootMesh.animations = animations;
550
+ if (this.rootMesh.getScene().beginAnimation !== undefined) {
551
+ var animatable = this.rootMesh.getScene().beginAnimation(this.rootMesh, 0, this._frameRate * duration, false, 1, function () {
552
+ if (onAnimationEnd) {
553
+ onAnimationEnd();
554
+ }
555
+ });
556
+ this._animatables.push(animatable);
557
+ }
558
+ };
559
+ /**
560
+ * Sets key values on an Animation from first to last frame.
561
+ * @param animation The Babylon animation object to set keys on
562
+ * @param startValue The value of the first key
563
+ * @param endValue The value of the last key
564
+ * @param duration The duration of the animation, used to determine the end frame
565
+ */
566
+ ViewerModel.prototype._setLinearKeys = function (animation, startValue, endValue, duration) {
567
+ animation.setKeys([
568
+ {
569
+ frame: 0,
570
+ value: startValue,
571
+ },
572
+ {
573
+ frame: this._frameRate * duration,
574
+ value: endValue,
575
+ },
576
+ ]);
577
+ };
578
+ /**
579
+ * Creates and returns a Babylon easing funtion object based on a string representing the Easing function
580
+ * @param easingFunctionID The enum of the easing funtion to create
581
+ * @returns The newly created Babylon easing function object
582
+ */
583
+ ViewerModel.prototype._createEasingFunction = function (easingFunctionID) {
584
+ var easingFunction;
585
+ switch (easingFunctionID) {
586
+ case EasingFunction.CircleEase:
587
+ easingFunction = new CircleEase();
588
+ break;
589
+ case EasingFunction.BackEase:
590
+ easingFunction = new BackEase(0.3);
591
+ break;
592
+ case EasingFunction.BounceEase:
593
+ easingFunction = new BounceEase();
594
+ break;
595
+ case EasingFunction.CubicEase:
596
+ easingFunction = new CubicEase();
597
+ break;
598
+ case EasingFunction.ElasticEase:
599
+ easingFunction = new ElasticEase();
600
+ break;
601
+ case EasingFunction.ExponentialEase:
602
+ easingFunction = new ExponentialEase();
603
+ break;
604
+ case EasingFunction.PowerEase:
605
+ easingFunction = new PowerEase();
606
+ break;
607
+ case EasingFunction.QuadraticEase:
608
+ easingFunction = new QuadraticEase();
609
+ break;
610
+ case EasingFunction.QuarticEase:
611
+ easingFunction = new QuarticEase();
612
+ break;
613
+ case EasingFunction.QuinticEase:
614
+ easingFunction = new QuinticEase();
615
+ break;
616
+ case EasingFunction.SineEase:
617
+ easingFunction = new SineEase();
618
+ break;
619
+ default:
620
+ Tools.Log("No ease function found");
621
+ break;
622
+ }
623
+ return easingFunction;
624
+ };
625
+ /**
626
+ * Stops and removes all animations that have been applied to the model
627
+ */
628
+ ViewerModel.prototype.stopAllAnimations = function () {
629
+ if (this.rootMesh) {
630
+ this.rootMesh.animations = [];
631
+ }
632
+ if (this.currentAnimation) {
633
+ this.currentAnimation.stop();
634
+ }
635
+ while (this._animatables.length) {
636
+ this._animatables[0].onAnimationEnd = null;
637
+ this._animatables[0].stop();
638
+ this._animatables.shift();
639
+ }
640
+ };
641
+ /**
642
+ * Will remove this model from the viewer (but NOT dispose it).
643
+ */
644
+ ViewerModel.prototype.remove = function () {
645
+ this.stopAllAnimations();
646
+ if (this._observablesManager) {
647
+ this._observablesManager.onModelRemovedObservable.notifyObservers(this);
648
+ }
649
+ };
650
+ /**
651
+ * Dispose this model, including all of its associated assets.
652
+ */
653
+ ViewerModel.prototype.dispose = function () {
654
+ this.remove();
655
+ this.onAfterConfigure.clear();
656
+ this.onLoadedObservable.clear();
657
+ this.onLoadErrorObservable.clear();
658
+ this.onLoadProgressObservable.clear();
659
+ if (this.loader && this.loader.name === "gltf") {
660
+ this.loader.dispose();
661
+ }
662
+ this.particleSystems.forEach(function (ps) { return ps.dispose(); });
663
+ this.particleSystems.length = 0;
664
+ this.skeletons.forEach(function (s) { return s.dispose(); });
665
+ this.skeletons.length = 0;
666
+ this._animations.forEach(function (ag) { return ag.dispose(); });
667
+ this._animations.length = 0;
668
+ this.rootMesh.dispose(false, true);
669
+ };
670
+ return ViewerModel;
671
+ }());
672
+ export { ViewerModel };
673
+ //# sourceMappingURL=viewerModel.js.map