@combeenation/3d-viewer 4.0.0-beta5 → 4.0.0-rc1

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 (95) hide show
  1. package/README.md +114 -114
  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 +130 -130
  7. package/dist/lib-cjs/api/classes/element.js +743 -743
  8. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  9. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  10. package/dist/lib-cjs/api/classes/event.d.ts +326 -326
  11. package/dist/lib-cjs/api/classes/event.js +371 -371
  12. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  13. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  14. package/dist/lib-cjs/api/classes/parameter.d.ts +259 -259
  15. package/dist/lib-cjs/api/classes/parameter.js +387 -387
  16. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  17. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -101
  18. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  19. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  20. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  21. package/dist/lib-cjs/api/classes/placementAnimation.js +149 -149
  22. package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
  23. package/dist/lib-cjs/api/classes/variant.js +1147 -1147
  24. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
  25. package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
  26. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  27. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  28. package/dist/lib-cjs/api/classes/viewer.d.ts +131 -131
  29. package/dist/lib-cjs/api/classes/viewer.js +567 -560
  30. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  31. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
  32. package/dist/lib-cjs/api/classes/viewerLight.js +389 -389
  33. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  34. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  35. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  36. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  37. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -10
  38. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -231
  39. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  40. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  41. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  42. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  43. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  44. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  45. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  46. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  47. package/dist/lib-cjs/api/util/babylonHelper.d.ts +175 -175
  48. package/dist/lib-cjs/api/util/babylonHelper.js +520 -520
  49. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  50. package/dist/lib-cjs/api/util/globalTypes.d.ts +333 -333
  51. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  52. package/dist/lib-cjs/api/util/resourceHelper.d.ts +53 -53
  53. package/dist/lib-cjs/api/util/resourceHelper.js +240 -240
  54. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  55. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  56. package/dist/lib-cjs/buildinfo.json +3 -3
  57. package/dist/lib-cjs/index.d.ts +48 -48
  58. package/dist/lib-cjs/index.js +86 -86
  59. package/dist/webpack-stats.json +0 -0
  60. package/package.json +83 -83
  61. package/src/api/classes/animationInterface.ts +11 -11
  62. package/src/api/classes/dottedPath.ts +189 -189
  63. package/src/api/classes/element.ts +644 -644
  64. package/src/api/classes/event.ts +370 -370
  65. package/src/api/classes/eventBroadcaster.ts +54 -54
  66. package/src/api/classes/parameter.ts +408 -408
  67. package/src/api/classes/parameterObservable.ts +99 -99
  68. package/src/api/classes/parameterizable.ts +89 -89
  69. package/src/api/classes/placementAnimation.ts +143 -143
  70. package/src/api/classes/variant.ts +817 -817
  71. package/src/api/classes/variantInstance.ts +88 -88
  72. package/src/api/classes/variantParameterizable.ts +73 -73
  73. package/src/api/classes/viewer.ts +487 -478
  74. package/src/api/classes/viewerLight.ts +330 -330
  75. package/src/api/internal/debugViewer.ts +81 -81
  76. package/src/api/internal/lensRendering.ts +10 -10
  77. package/src/api/internal/sceneSetup.ts +193 -193
  78. package/src/api/manager/animationManager.ts +116 -116
  79. package/src/api/manager/sceneManager.ts +105 -105
  80. package/src/api/manager/variantInstanceManager.ts +236 -236
  81. package/src/api/store/specStorage.ts +53 -53
  82. package/src/api/util/babylonHelper.ts +555 -553
  83. package/src/api/util/globalTypes.ts +379 -379
  84. package/src/api/util/resourceHelper.ts +184 -184
  85. package/src/api/util/stringHelper.ts +25 -25
  86. package/src/buildinfo.json +2 -2
  87. package/src/commonjs.tsconfig.json +13 -13
  88. package/src/declaration.tsconfig.json +10 -10
  89. package/src/dev.ts +42 -42
  90. package/src/es6.tsconfig.json +13 -13
  91. package/src/index.ts +91 -91
  92. package/src/pagesconfig.json +61 -61
  93. package/src/tsconfig.json +43 -43
  94. package/src/tsconfig.types.json +9 -9
  95. package/src/types.d.ts +4 -4
@@ -1,390 +1,390 @@
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 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;
390
390
  //# sourceMappingURL=viewerLight.js.map