@combeenation/3d-viewer 4.0.0-alpha9 → 4.0.0-beta4

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 (105) hide show
  1. package/README.md +112 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +125 -130
  7. package/dist/lib-cjs/api/classes/element.js +682 -739
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  11. package/dist/lib-cjs/api/classes/event.d.ts +312 -326
  12. package/dist/lib-cjs/api/classes/event.js +357 -371
  13. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  15. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +165 -259
  17. package/dist/lib-cjs/api/classes/parameter.js +267 -387
  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 +126 -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 +149 -149
  24. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  25. package/dist/lib-cjs/api/classes/placementAnimation.js +138 -138
  26. package/dist/lib-cjs/api/classes/variant.d.ts +190 -224
  27. package/dist/lib-cjs/api/classes/variant.js +873 -1137
  28. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  29. package/dist/lib-cjs/api/classes/variantInstance.d.ts +41 -45
  30. package/dist/lib-cjs/api/classes/variantInstance.js +98 -108
  31. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  32. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  33. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  34. package/dist/lib-cjs/api/classes/viewer.d.ts +128 -131
  35. package/dist/lib-cjs/api/classes/viewer.js +486 -538
  36. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  37. package/dist/lib-cjs/api/classes/viewerLight.d.ts +65 -66
  38. package/dist/lib-cjs/api/classes/viewerLight.js +322 -389
  39. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  40. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  41. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  42. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  43. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  44. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +6 -10
  45. package/dist/lib-cjs/api/internal/sceneSetup.js +227 -231
  46. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  47. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  48. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  49. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  50. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  51. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  53. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  54. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  55. package/dist/lib-cjs/api/util/babylonHelper.d.ts +125 -175
  56. package/dist/lib-cjs/api/util/babylonHelper.js +368 -520
  57. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  58. package/dist/lib-cjs/api/util/globalTypes.d.ts +279 -321
  59. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  60. package/dist/lib-cjs/api/util/resourceHelper.d.ts +51 -26
  61. package/dist/lib-cjs/api/util/resourceHelper.js +243 -237
  62. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  63. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  64. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  65. package/dist/lib-cjs/buildinfo.json +3 -3
  66. package/dist/lib-cjs/index.d.ts +46 -48
  67. package/dist/lib-cjs/index.js +82 -86
  68. package/dist/lib-cjs/index.js.map +1 -1
  69. package/dist/webpack-stats.json +0 -0
  70. package/package.json +83 -83
  71. package/src/api/classes/animationInterface.ts +11 -11
  72. package/src/api/classes/dottedPath.ts +189 -189
  73. package/src/api/classes/element.ts +617 -635
  74. package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +78 -89
  75. package/src/api/classes/event.ts +355 -370
  76. package/src/api/classes/eventBroadcaster.ts +54 -54
  77. package/src/api/classes/parameter.ts +277 -408
  78. package/src/api/classes/parameterObservable.ts +121 -99
  79. package/src/api/classes/placementAnimation.ts +133 -133
  80. package/src/api/classes/variant.ts +670 -806
  81. package/src/api/classes/variantInstance.ts +81 -88
  82. package/src/api/classes/viewer.ts +421 -473
  83. package/src/api/internal/debugViewer.ts +81 -81
  84. package/src/api/internal/lensRendering.ts +10 -10
  85. package/src/api/internal/sceneSetup.ts +204 -194
  86. package/src/api/manager/animationManager.ts +116 -116
  87. package/src/api/manager/sceneManager.ts +105 -105
  88. package/src/api/manager/variantInstanceManager.ts +236 -236
  89. package/src/api/store/specStorage.ts +53 -53
  90. package/src/api/util/babylonHelper.ts +392 -553
  91. package/src/api/util/globalTypes.ts +318 -369
  92. package/src/api/util/resourceHelper.ts +187 -157
  93. package/src/buildinfo.json +2 -2
  94. package/src/commonjs.tsconfig.json +13 -13
  95. package/src/declaration.tsconfig.json +10 -10
  96. package/src/dev.ts +46 -44
  97. package/src/es6.tsconfig.json +13 -13
  98. package/src/index.ts +87 -91
  99. package/src/pagesconfig.json +57 -52
  100. package/src/tsconfig.json +43 -43
  101. package/src/tsconfig.types.json +9 -9
  102. package/src/types.d.ts +4 -4
  103. package/src/api/classes/variantParameterizable.ts +0 -73
  104. package/src/api/classes/viewerLight.ts +0 -330
  105. package/src/api/util/stringHelper.ts +0 -26
@@ -1,390 +1,323 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ViewerLight = void 0;
4
- var tslib_1 = require("tslib");
5
- var core_1 = require("@babylonjs/core");
6
- var hemisphericLight_1 = require("@babylonjs/core/Lights/hemisphericLight");
7
- var shadowLight_1 = require("@babylonjs/core/Lights/shadowLight");
8
- var shadowGenerator_1 = require("@babylonjs/core/Lights/Shadows/shadowGenerator");
9
- require("@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent");
10
- var math_vector_1 = require("@babylonjs/core/Maths/math.vector");
11
- var transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
12
- require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual");
13
- var lodash_es_1 = require("lodash-es");
14
- var babylonHelper_1 = require("./../util/babylonHelper");
15
- var dottedPath_1 = require("./dottedPath");
16
- var parameter_1 = require("./parameter");
17
- var variantParameterizable_1 = require("./variantParameterizable");
18
- /**
19
- * A {@link ViewerLight} of a {@link Variant}. Acts as a container for BabylonJS lights. Lives only in the context of a
20
- * {@link Variant}.
21
- */
22
- var ViewerLight = /** @class */ (function (_super) {
23
- tslib_1.__extends(ViewerLight, _super);
24
- /**
25
- * Constructor.
26
- */
27
- function ViewerLight(variant, name) {
28
- var _this = _super.call(this, variant, name) || this;
29
- _this.variant = variant;
30
- _this.name = name;
31
- _this.addParameterObservers();
32
- return _this;
33
- }
34
- /**
35
- * Creates a {@link ViewerLight} with given name.
36
- */
37
- ViewerLight.create = function (variant, name) {
38
- return tslib_1.__awaiter(this, void 0, void 0, function () {
39
- var viewerLight, _a;
40
- return tslib_1.__generator(this, function (_b) {
41
- switch (_b.label) {
42
- case 0:
43
- viewerLight = new ViewerLight(variant, name);
44
- _a = viewerLight;
45
- return [4 /*yield*/, viewerLight.createBabylonLightFromDefinition(viewerLight.definition)];
46
- case 1:
47
- _a._light = _b.sent();
48
- return [2 /*return*/, viewerLight];
49
- }
50
- });
51
- });
52
- };
53
- Object.defineProperty(ViewerLight.prototype, "light", {
54
- /**
55
- * The wrapped Light.
56
- */
57
- get: function () {
58
- if (!this._light) {
59
- throw new Error("Light for ViewerLight \"" + this.name + "\" has not been properly initialized.");
60
- }
61
- return this._light;
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
- Object.defineProperty(ViewerLight.prototype, "dottedPath", {
67
- /**
68
- * The {@link DottedPath} in the built tree of {@link ViewerLight}s.
69
- * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
70
- */
71
- get: function () {
72
- return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
73
- },
74
- enumerable: false,
75
- configurable: true
76
- });
77
- Object.defineProperty(ViewerLight.prototype, "id", {
78
- /**
79
- * The id representing a {@link DottedPath}.
80
- */
81
- get: function () {
82
- var dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
83
- dottedPath.shiftPart(); // remove root
84
- return dottedPath.path;
85
- },
86
- enumerable: false,
87
- configurable: true
88
- });
89
- Object.defineProperty(ViewerLight.prototype, "definition", {
90
- /**
91
- * The {@link LightDefinition} of the {@link ViewerLight}.
92
- */
93
- get: function () {
94
- var definition = this.variant.structureJson.lights[this.name];
95
- if (lodash_es_1.isString(definition)) {
96
- return {
97
- type: 'baked',
98
- path: definition
99
- };
100
- }
101
- return definition;
102
- },
103
- enumerable: false,
104
- configurable: true
105
- });
106
- Object.defineProperty(ViewerLight.prototype, "type", {
107
- /**
108
- * The type of the {@link ViewerLight}'s light.
109
- */
110
- get: function () {
111
- return this.light.constructor.name.replace(/light/i, '').toLowerCase();
112
- },
113
- enumerable: false,
114
- configurable: true
115
- });
116
- /**
117
- * @see {@link VariantParameterizable.commitParameters}
118
- * @emit {@link Event.VIEWER_LIGHT_PARAMETER_COMMITTED}
119
- */
120
- ViewerLight.prototype.commitParameters = function (parameters) {
121
- return tslib_1.__awaiter(this, void 0, void 0, function () {
122
- return tslib_1.__generator(this, function (_a) {
123
- return [2 /*return*/, _super.prototype.commitParameters.call(this, parameters)];
124
- });
125
- });
126
- };
127
- /**
128
- * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
129
- */
130
- ViewerLight.prototype.addParameterObservers = function () {
131
- var _this = this;
132
- this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
133
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
134
- var visible;
135
- return tslib_1.__generator(this, function (_a) {
136
- try {
137
- visible = parameter_1.Parameter.parseBoolean(newValue);
138
- }
139
- catch (e) {
140
- return [2 /*return*/];
141
- }
142
- if (visible === true) {
143
- babylonHelper_1.enableNodeWithParents(light.light);
144
- }
145
- else if (visible === false) {
146
- babylonHelper_1.disableNodeWithParents(light.light);
147
- }
148
- return [2 /*return*/];
149
- });
150
- }); }
151
- ]);
152
- this._parameterObservers.set(parameter_1.Parameter.INTENSITY, [
153
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
154
- return tslib_1.__generator(this, function (_a) {
155
- lodash_es_1.set(light.light, 'intensity', parameter_1.Parameter.parseNumber(newValue));
156
- return [2 /*return*/];
157
- });
158
- }); }
159
- ]);
160
- this._parameterObservers.set(parameter_1.Parameter.POSITION, [
161
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
162
- var rootNode;
163
- return tslib_1.__generator(this, function (_a) {
164
- rootNode = babylonHelper_1.getRootNode(light.light);
165
- if (rootNode instanceof transformNode_1.TransformNode) {
166
- babylonHelper_1.moveTransformNode(rootNode, parameter_1.Parameter.parseVector(newValue));
167
- }
168
- return [2 /*return*/];
169
- });
170
- }); }
171
- ]);
172
- this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
173
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
174
- var rootNode;
175
- return tslib_1.__generator(this, function (_a) {
176
- switch (_a.label) {
177
- case 0:
178
- if (!(parameter_1.Parameter.POSITION in light.inheritedParameters)) return [3 /*break*/, 2];
179
- return [4 /*yield*/, light.commitParameter(parameter_1.Parameter.POSITION, light.inheritedParameters[parameter_1.Parameter.POSITION])];
180
- case 1:
181
- _a.sent();
182
- _a.label = 2;
183
- case 2:
184
- rootNode = babylonHelper_1.getRootNode(light.light);
185
- if (rootNode instanceof transformNode_1.TransformNode) {
186
- babylonHelper_1.rotateTransformNode(rootNode, parameter_1.Parameter.parseRotation(newValue));
187
- }
188
- return [2 /*return*/];
189
- }
190
- });
191
- }); }
192
- ]);
193
- this._parameterObservers.set(parameter_1.Parameter.SCALING, [
194
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
195
- var rootNode;
196
- return tslib_1.__generator(this, function (_a) {
197
- rootNode = babylonHelper_1.getRootNode(light.light);
198
- if (rootNode instanceof transformNode_1.TransformNode) {
199
- rootNode.scaling = parameter_1.Parameter.parseScaling(newValue);
200
- }
201
- return [2 /*return*/];
202
- });
203
- }); }
204
- ]);
205
- this._parameterObservers.set(parameter_1.Parameter.DIRECTION, [
206
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
207
- return tslib_1.__generator(this, function (_a) {
208
- if ((light.light instanceof shadowLight_1.ShadowLight && !(light.light instanceof core_1.PointLight))
209
- || light.light instanceof hemisphericLight_1.HemisphericLight) {
210
- lodash_es_1.set(light.light, 'direction', parameter_1.Parameter.parseVector(newValue));
211
- }
212
- return [2 /*return*/];
213
- });
214
- }); }
215
- ]);
216
- this._parameterObservers.set(parameter_1.Parameter.ANGLE, [
217
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
218
- return tslib_1.__generator(this, function (_a) {
219
- if (light.light.getClassName() === 'SpotLight') {
220
- lodash_es_1.set(light.light, 'angle', parameter_1.Parameter.parseNumber(newValue));
221
- }
222
- return [2 /*return*/];
223
- });
224
- }); }
225
- ]);
226
- this._parameterObservers.set(parameter_1.Parameter.EXPONENT, [
227
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
228
- return tslib_1.__generator(this, function (_a) {
229
- if (light.light.getClassName() === 'SpotLight') {
230
- lodash_es_1.set(light.light, 'exponent', parameter_1.Parameter.parseNumber(newValue));
231
- }
232
- return [2 /*return*/];
233
- });
234
- }); }
235
- ]);
236
- this._parameterObservers.set(parameter_1.Parameter.DIFFUSE, [
237
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
238
- return tslib_1.__generator(this, function (_a) {
239
- lodash_es_1.set(light.light, 'diffuse', parameter_1.Parameter.parseColor(newValue));
240
- return [2 /*return*/];
241
- });
242
- }); }
243
- ]);
244
- this._parameterObservers.set(parameter_1.Parameter.SPECULAR, [
245
- function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
246
- return tslib_1.__generator(this, function (_a) {
247
- lodash_es_1.set(light.light, 'specular', parameter_1.Parameter.parseColor(newValue));
248
- return [2 /*return*/];
249
- });
250
- }); }
251
- ]);
252
- return this;
253
- };
254
- /**
255
- * @param definition
256
- * @protected
257
- */
258
- ViewerLight.prototype.createBabylonLightFromDefinition = function (definition) {
259
- return tslib_1.__awaiter(this, void 0, void 0, function () {
260
- var parameters, scene, lightId, babylonLight, _a, bakedLight, hemisphericLightModule, pointLightModule, directionalLightModule, spotLightModule, shadowGeneratorDefinition;
261
- return tslib_1.__generator(this, function (_b) {
262
- switch (_b.label) {
263
- case 0:
264
- parameters = parameter_1.Parameter.parseFromDeclarations(parameter_1.Parameter.declarations, this.inheritedParameters);
265
- scene = this.variant.viewer.scene;
266
- lightId = this.id;
267
- _a = definition.type;
268
- switch (_a) {
269
- case 'baked': return [3 /*break*/, 1];
270
- case 'hemispheric': return [3 /*break*/, 2];
271
- case 'point': return [3 /*break*/, 4];
272
- case 'directional': return [3 /*break*/, 6];
273
- case 'spot': return [3 /*break*/, 8];
274
- }
275
- return [3 /*break*/, 10];
276
- case 1:
277
- if (!definition['path']) {
278
- throw new Error("The light \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"path\".");
279
- }
280
- bakedLight = this.variant.inheritedLights.find(function (l) { return l.metadata.dottedPath.path === definition['path']; });
281
- if (bakedLight) {
282
- lightId = bakedLight.metadata.dottedPath.clone().unshiftPart(this.id).path;
283
- babylonLight = babylonHelper_1.cloneNodeWithParents(bakedLight);
284
- babylonLight.name = lightId;
285
- babylonLight.id = lightId;
286
- }
287
- else {
288
- throw new Error("No light found for path \"" + definition['path'] + "\" in ViewerLight \"" + lightId + "\".");
289
- }
290
- return [3 /*break*/, 11];
291
- case 2:
292
- if (!parameters['direction']) {
293
- throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
294
- }
295
- return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight'); })];
296
- case 3:
297
- hemisphericLightModule = _b.sent();
298
- babylonLight = new hemisphericLightModule.HemisphericLight(lightId, parameters['direction'], scene);
299
- return [3 /*break*/, 11];
300
- case 4: return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight'); })];
301
- case 5:
302
- pointLightModule = _b.sent();
303
- babylonLight = new pointLightModule.PointLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
304
- scene);
305
- return [3 /*break*/, 11];
306
- case 6:
307
- if (!parameters['direction']) {
308
- throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
309
- }
310
- return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight'); })];
311
- case 7:
312
- directionalLightModule = _b.sent();
313
- babylonLight = new directionalLightModule.DirectionalLight(lightId, parameters['direction'], scene);
314
- return [3 /*break*/, 11];
315
- case 8:
316
- if (!parameters['direction']) {
317
- throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
318
- }
319
- if (!parameters['angle']) {
320
- throw new Error("A ViewerLight of type \"" + definition.type + "\" needs an \"angle\".");
321
- }
322
- if (!parameters['exponent']) {
323
- throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs an \"exponent\".");
324
- }
325
- return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight'); })];
326
- case 9:
327
- spotLightModule = _b.sent();
328
- babylonLight = new spotLightModule.SpotLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
329
- parameters['direction'], parameters['angle'], parameters['exponent'], scene);
330
- return [3 /*break*/, 11];
331
- case 10: throw new Error("The type \"" + definition.type + "\" for ViewerLight \"" + lightId + "\" is not implemented (yet).");
332
- case 11:
333
- if (!babylonLight) {
334
- throw new Error("The Light for ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" could no be created " +
335
- "or found.");
336
- }
337
- if (!babylonLight.parent) {
338
- // Create pseudo parent since lights do not implement mutations like "rotation" by itself.
339
- babylonLight.parent = new transformNode_1.TransformNode('__light__', this.variant.viewer.scene, true);
340
- }
341
- babylonHelper_1.injectNodeMetadata(babylonLight.parent, {
342
- variant: this.variant,
343
- variantParameterizable: this
344
- });
345
- // disable/hide by default
346
- babylonHelper_1.disableNodeWithParents(babylonLight);
347
- shadowGeneratorDefinition = lodash_es_1.get(definition, 'shadowGenerator');
348
- if (!!lodash_es_1.isEmpty(shadowGeneratorDefinition)) return [3 /*break*/, 13];
349
- if (!(babylonLight instanceof shadowLight_1.ShadowLight)) {
350
- throw new Error("Using a ShadowGenerator with light type \"" + definition.type + "\" is not supported for " +
351
- ("\"" + lightId + "\". Use lights deriving from ShadowLight."));
352
- }
353
- return [4 /*yield*/, this.processShadowGenerator(babylonLight, shadowGeneratorDefinition)];
354
- case 12:
355
- _b.sent();
356
- _b.label = 13;
357
- case 13: return [2 /*return*/, babylonLight];
358
- }
359
- });
360
- });
361
- };
362
- ;
363
- /**
364
- * @param babylonLight
365
- * @param definition
366
- * @protected
367
- */
368
- ViewerLight.prototype.processShadowGenerator = function (babylonLight, definition) {
369
- return tslib_1.__awaiter(this, void 0, void 0, function () {
370
- var parameterDeclarations, parameterBag, parameters, shadowGenerator, parameter;
371
- return tslib_1.__generator(this, function (_a) {
372
- parameterDeclarations = {};
373
- parameterBag = definition;
374
- parameters = parameter_1.Parameter.parseFromDeclarations(parameterDeclarations, parameterBag);
375
- shadowGenerator = new shadowGenerator_1.ShadowGenerator(parameters['mapSize'], babylonLight);
376
- for (parameter in parameters) {
377
- if (parameter === 'mapSize') {
378
- continue;
379
- }
380
- lodash_es_1.set(shadowGenerator, parameter, lodash_es_1.get(parameters, parameter));
381
- }
382
- return [2 /*return*/, shadowGenerator];
383
- });
384
- });
385
- };
386
- ;
387
- return ViewerLight;
388
- }(variantParameterizable_1.VariantParameterizable));
389
- exports.ViewerLight = ViewerLight;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewerLight = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var shadowLight_1 = require("@babylonjs/core/Lights/shadowLight");
6
+ var shadowGenerator_1 = require("@babylonjs/core/Lights/Shadows/shadowGenerator");
7
+ require("@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent");
8
+ var babylonHelper_1 = require("./../util/babylonHelper");
9
+ var lodash_es_1 = require("lodash-es");
10
+ var dottedPath_1 = require("./dottedPath");
11
+ var parameter_1 = require("./parameter");
12
+ var variantParameterizable_1 = require("./variantParameterizable");
13
+ /**
14
+ * A {@link ViewerLight} of a {@link Variant}. Acts as a container for BabylonJS lights. Lives only in the context of a
15
+ * {@link Variant}.
16
+ */
17
+ var ViewerLight = /** @class */ (function (_super) {
18
+ tslib_1.__extends(ViewerLight, _super);
19
+ /**
20
+ * Constructor.
21
+ */
22
+ function ViewerLight(variant, name) {
23
+ var _this = _super.call(this, variant, name) || this;
24
+ _this.variant = variant;
25
+ _this.name = name;
26
+ _this.addParameterObservers();
27
+ return _this;
28
+ }
29
+ /**
30
+ * Creates a {@link ViewerLight} with given name.
31
+ */
32
+ ViewerLight.create = function (variant, name) {
33
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
34
+ var viewerLight, _a;
35
+ return tslib_1.__generator(this, function (_b) {
36
+ switch (_b.label) {
37
+ case 0:
38
+ viewerLight = new ViewerLight(variant, name);
39
+ _a = viewerLight;
40
+ return [4 /*yield*/, viewerLight.createBabylonLightFromDefinition(viewerLight.definition)];
41
+ case 1:
42
+ _a._light = _b.sent();
43
+ return [2 /*return*/, viewerLight];
44
+ }
45
+ });
46
+ });
47
+ };
48
+ Object.defineProperty(ViewerLight.prototype, "light", {
49
+ /**
50
+ * The wrapped Light.
51
+ */
52
+ get: function () {
53
+ if (!this._light) {
54
+ throw new Error("Light for ViewerLight \"" + this.name + "\" has not been properly initialized.");
55
+ }
56
+ return this._light;
57
+ },
58
+ enumerable: false,
59
+ configurable: true
60
+ });
61
+ Object.defineProperty(ViewerLight.prototype, "dottedPath", {
62
+ /**
63
+ * The {@link DottedPath} in the built tree of {@link ViewerLight}s.
64
+ * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
65
+ */
66
+ get: function () {
67
+ return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
68
+ },
69
+ enumerable: false,
70
+ configurable: true
71
+ });
72
+ Object.defineProperty(ViewerLight.prototype, "id", {
73
+ /**
74
+ * The id representing a {@link DottedPath}.
75
+ */
76
+ get: function () {
77
+ var dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
78
+ dottedPath.shiftPart(); // remove root
79
+ return dottedPath.path;
80
+ },
81
+ enumerable: false,
82
+ configurable: true
83
+ });
84
+ Object.defineProperty(ViewerLight.prototype, "definition", {
85
+ /**
86
+ * The {@link LightDefinition} of the {@link ViewerLight}.
87
+ */
88
+ get: function () {
89
+ var definition = this.variant.structureJson.lights[this.name];
90
+ if (lodash_es_1.isString(definition)) {
91
+ return {
92
+ type: 'baked',
93
+ path: definition
94
+ };
95
+ }
96
+ return definition;
97
+ },
98
+ enumerable: false,
99
+ configurable: true
100
+ });
101
+ Object.defineProperty(ViewerLight.prototype, "type", {
102
+ /**
103
+ * The type of the {@link ViewerLight}'s light.
104
+ */
105
+ get: function () {
106
+ return this.light.constructor.name.replace(/light/i, '').toLowerCase();
107
+ },
108
+ enumerable: false,
109
+ configurable: true
110
+ });
111
+ /**
112
+ * @see {@link VariantParameterizable.commitParameters}
113
+ * @emit {@link Event.VIEWER_LIGHT_PARAMETER_COMMITTED}
114
+ */
115
+ ViewerLight.prototype.commitParameters = function (parameters) {
116
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
117
+ return tslib_1.__generator(this, function (_a) {
118
+ return [2 /*return*/, _super.prototype.commitParameters.call(this, parameters)];
119
+ });
120
+ });
121
+ };
122
+ /**
123
+ * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
124
+ */
125
+ ViewerLight.prototype.addParameterObservers = function () {
126
+ this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
127
+ function (light, oldValue, newValue) {
128
+ var visible;
129
+ try {
130
+ visible = parameter_1.Parameter.parseBoolean(newValue);
131
+ }
132
+ catch (e) {
133
+ return;
134
+ }
135
+ if (visible === true) {
136
+ babylonHelper_1.enableNodeWithParents(light.light);
137
+ }
138
+ else if (visible === false) {
139
+ babylonHelper_1.disableNodeWithParents(light.light);
140
+ }
141
+ }
142
+ ]);
143
+ this._parameterObservers.set(parameter_1.Parameter.INTENSITY, [
144
+ function (light, oldValue, newValue) {
145
+ if (light.light instanceof shadowLight_1.ShadowLight) {
146
+ lodash_es_1.set(light.light, 'intensity', parameter_1.Parameter.parseNumber(newValue));
147
+ }
148
+ }
149
+ ]);
150
+ this._parameterObservers.set(parameter_1.Parameter.POSITION, [
151
+ function (light, oldValue, newValue) {
152
+ if (light.light instanceof shadowLight_1.ShadowLight) {
153
+ lodash_es_1.set(light.light, 'position', parameter_1.Parameter.parseVector(newValue));
154
+ }
155
+ }
156
+ ]);
157
+ this._parameterObservers.set(parameter_1.Parameter.DIRECTION, [
158
+ function (light, oldValue, newValue) {
159
+ if (light.light instanceof shadowLight_1.ShadowLight) {
160
+ lodash_es_1.set(light.light, 'direction', parameter_1.Parameter.parseVector(newValue));
161
+ }
162
+ }
163
+ ]);
164
+ this._parameterObservers.set(parameter_1.Parameter.ANGLE, [
165
+ function (light, oldValue, newValue) {
166
+ if (light.light.getClassName() === 'SpotLight') {
167
+ lodash_es_1.set(light.light, 'angle', parameter_1.Parameter.parseNumber(newValue));
168
+ }
169
+ }
170
+ ]);
171
+ this._parameterObservers.set(parameter_1.Parameter.EXPONENT, [
172
+ function (light, oldValue, newValue) {
173
+ if (light.light.getClassName() === 'SpotLight') {
174
+ lodash_es_1.set(light.light, 'exponent', parameter_1.Parameter.parseNumber(newValue));
175
+ }
176
+ }
177
+ ]);
178
+ this._parameterObservers.set(parameter_1.Parameter.DIFFUSE, [
179
+ function (light, oldValue, newValue) {
180
+ lodash_es_1.set(light.light, 'diffuse', parameter_1.Parameter.parseColor(newValue));
181
+ }
182
+ ]);
183
+ this._parameterObservers.set(parameter_1.Parameter.SPECULAR, [
184
+ function (light, oldValue, newValue) {
185
+ lodash_es_1.set(light.light, 'specular', parameter_1.Parameter.parseColor(newValue));
186
+ }
187
+ ]);
188
+ return this;
189
+ };
190
+ /**
191
+ * @param definition
192
+ * @protected
193
+ */
194
+ ViewerLight.prototype.createBabylonLightFromDefinition = function (definition) {
195
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
196
+ var parameters, scene, lightId, babylonLight, _a, bakedLight, hemisphericLightModule, pointLightModule, directionalLightModule, spotLightModule, shadowGeneratorDefinition;
197
+ return tslib_1.__generator(this, function (_b) {
198
+ switch (_b.label) {
199
+ case 0:
200
+ parameters = parameter_1.Parameter.parseFromDeclarations(parameter_1.Parameter.declarations, this.inheritedParameters);
201
+ scene = this.variant.viewer.scene;
202
+ lightId = this.id;
203
+ _a = definition.type;
204
+ switch (_a) {
205
+ case 'baked': return [3 /*break*/, 1];
206
+ case 'hemispheric': return [3 /*break*/, 2];
207
+ case 'point': return [3 /*break*/, 4];
208
+ case 'directional': return [3 /*break*/, 6];
209
+ case 'spot': return [3 /*break*/, 8];
210
+ }
211
+ return [3 /*break*/, 10];
212
+ case 1:
213
+ if (!definition['path']) {
214
+ throw new Error("The light \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"path\".");
215
+ }
216
+ bakedLight = this.variant.inheritedLights.find(function (l) { return l.metadata.dottedPath.path === definition['path']; });
217
+ if (bakedLight) {
218
+ lightId = bakedLight.metadata.dottedPath.clone().unshiftPart(this.id).path;
219
+ babylonLight = babylonHelper_1.cloneNodeWithParents(bakedLight);
220
+ babylonLight.name = lightId;
221
+ babylonLight.id = lightId;
222
+ }
223
+ else {
224
+ throw new Error("No light found for path \"" + definition['path'] + "\" in ViewerLight \"" + lightId + "\".");
225
+ }
226
+ return [3 /*break*/, 11];
227
+ case 2:
228
+ if (!parameters['direction']) {
229
+ throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
230
+ }
231
+ return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight'); })];
232
+ case 3:
233
+ hemisphericLightModule = _b.sent();
234
+ babylonLight = new hemisphericLightModule.HemisphericLight(lightId, parameters['direction'], scene);
235
+ return [3 /*break*/, 11];
236
+ case 4:
237
+ if (!parameters['position']) {
238
+ throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"position\".");
239
+ }
240
+ return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight'); })];
241
+ case 5:
242
+ pointLightModule = _b.sent();
243
+ babylonLight = new pointLightModule.PointLight(lightId, parameters['position'], scene);
244
+ return [3 /*break*/, 11];
245
+ case 6:
246
+ if (!parameters['direction']) {
247
+ throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
248
+ }
249
+ return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight'); })];
250
+ case 7:
251
+ directionalLightModule = _b.sent();
252
+ babylonLight = new directionalLightModule.DirectionalLight(lightId, parameters['direction'], scene);
253
+ return [3 /*break*/, 11];
254
+ case 8:
255
+ if (!parameters['position']) {
256
+ throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"position\".");
257
+ }
258
+ if (!parameters['direction']) {
259
+ throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
260
+ }
261
+ if (!parameters['angle']) {
262
+ throw new Error("A ViewerLight of type \"" + definition.type + "\" needs an \"angle\".");
263
+ }
264
+ if (!parameters['exponent']) {
265
+ throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs an \"exponent\".");
266
+ }
267
+ return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight'); })];
268
+ case 9:
269
+ spotLightModule = _b.sent();
270
+ babylonLight = new spotLightModule.SpotLight(lightId, parameters['position'], parameters['direction'], parameters['angle'], parameters['exponent'], scene);
271
+ return [3 /*break*/, 11];
272
+ case 10: throw new Error("The type \"" + definition.type + "\" for ViewerLight \"" + lightId + "\" is not implemented (yet).");
273
+ case 11:
274
+ if (!babylonLight) {
275
+ throw new Error("The Light for ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" could no be created " +
276
+ "or found.");
277
+ }
278
+ // disable/hide by default
279
+ babylonHelper_1.disableNodeWithParents(babylonLight);
280
+ shadowGeneratorDefinition = lodash_es_1.get(definition, 'shadowGenerator');
281
+ if (!!lodash_es_1.isEmpty(shadowGeneratorDefinition)) return [3 /*break*/, 13];
282
+ if (!(babylonLight instanceof shadowLight_1.ShadowLight)) {
283
+ throw new Error("Using a ShadowGenerator with light type \"" + definition.type + "\" is not supported for " +
284
+ ("\"" + lightId + "\". Use lights deriving from ShadowLight."));
285
+ }
286
+ return [4 /*yield*/, this.processShadowGenerator(babylonLight, shadowGeneratorDefinition)];
287
+ case 12:
288
+ _b.sent();
289
+ _b.label = 13;
290
+ case 13: return [2 /*return*/, babylonLight];
291
+ }
292
+ });
293
+ });
294
+ };
295
+ ;
296
+ /**
297
+ * @param babylonLight
298
+ * @param definition
299
+ * @protected
300
+ */
301
+ ViewerLight.prototype.processShadowGenerator = function (babylonLight, definition) {
302
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
303
+ var parameterDeclarations, parameterBag, parameters, shadowGenerator, parameter;
304
+ return tslib_1.__generator(this, function (_a) {
305
+ parameterDeclarations = {};
306
+ parameterBag = definition;
307
+ parameters = parameter_1.Parameter.parseFromDeclarations(parameterDeclarations, parameterBag);
308
+ shadowGenerator = new shadowGenerator_1.ShadowGenerator(parameters['mapSize'], babylonLight);
309
+ for (parameter in parameters) {
310
+ if (parameter === 'mapSize') {
311
+ continue;
312
+ }
313
+ lodash_es_1.set(shadowGenerator, parameter, lodash_es_1.get(parameters, parameter));
314
+ }
315
+ return [2 /*return*/, shadowGenerator];
316
+ });
317
+ });
318
+ };
319
+ ;
320
+ return ViewerLight;
321
+ }(variantParameterizable_1.VariantParameterizable));
322
+ exports.ViewerLight = ViewerLight;
390
323
  //# sourceMappingURL=viewerLight.js.map