@combeenation/3d-viewer 5.0.1 → 5.0.3-beta2
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.
- package/README.md +111 -114
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +187 -187
- package/dist/lib-cjs/api/classes/element.d.ts +139 -139
- package/dist/lib-cjs/api/classes/element.js +794 -794
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js +135 -0
- package/dist/lib-cjs/api/classes/elementParameterizable.js.map +1 -0
- package/dist/lib-cjs/api/classes/event.d.ts +326 -326
- package/dist/lib-cjs/api/classes/event.js +371 -371
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
- package/dist/lib-cjs/api/classes/parameter.d.ts +316 -259
- package/dist/lib-cjs/api/classes/parameter.js +451 -388
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +101 -101
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +44 -44
- package/dist/lib-cjs/api/classes/placementAnimation.js +163 -163
- package/dist/lib-cjs/api/classes/variant.d.ts +234 -234
- package/dist/lib-cjs/api/classes/variant.js +1154 -1154
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -45
- package/dist/lib-cjs/api/classes/variantInstance.js +108 -108
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +99 -99
- package/dist/lib-cjs/api/classes/viewer.d.ts +177 -175
- package/dist/lib-cjs/api/classes/viewer.js +717 -701
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +392 -392
- package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
- package/dist/lib-cjs/api/internal/debugViewer.js +86 -86
- package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
- package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +13 -10
- package/dist/lib-cjs/api/internal/sceneSetup.js +238 -234
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
- package/dist/lib-cjs/api/manager/animationManager.js +130 -130
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +65 -65
- package/dist/lib-cjs/api/manager/gltfExportManager.js +223 -222
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +31 -32
- package/dist/lib-cjs/api/manager/sceneManager.js +153 -132
- package/dist/lib-cjs/api/manager/sceneManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +92 -92
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +335 -335
- package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
- package/dist/lib-cjs/api/store/specStorage.js +51 -51
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +174 -166
- package/dist/lib-cjs/api/util/babylonHelper.js +575 -497
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +366 -356
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -53
- package/dist/lib-cjs/api/util/resourceHelper.js +257 -242
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/stringHelper.js +25 -25
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +48 -44
- package/dist/lib-cjs/api/util/structureHelper.js.map +1 -1
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/index.d.ts +49 -49
- package/dist/lib-cjs/index.js +89 -89
- package/dist/webpack-stats.json +0 -0
- package/package.json +87 -87
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +690 -692
- package/src/api/classes/event.ts +367 -367
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/parameter.ts +474 -405
- package/src/api/classes/parameterObservable.ts +100 -100
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +160 -160
- package/src/api/classes/variant.ts +845 -845
- package/src/api/classes/variantInstance.ts +97 -97
- package/src/api/classes/variantParameterizable.ts +85 -85
- package/src/api/classes/viewer.ts +650 -624
- package/src/api/classes/viewerLight.ts +334 -334
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +10 -10
- package/src/api/internal/sceneSetup.ts +204 -201
- package/src/api/manager/animationManager.ts +142 -142
- package/src/api/manager/gltfExportManager.ts +191 -191
- package/src/api/manager/sceneManager.ts +128 -102
- package/src/api/manager/variantInstanceManager.ts +265 -265
- package/src/api/store/specStorage.ts +51 -51
- package/src/api/util/babylonHelper.ts +628 -538
- package/src/api/util/globalTypes.ts +413 -402
- package/src/api/util/resourceHelper.ts +189 -173
- package/src/api/util/stringHelper.ts +23 -23
- package/src/api/util/structureHelper.ts +49 -43
- package/src/buildinfo.json +3 -3
- package/src/commonjs.tsconfig.json +10 -10
- package/src/declaration.tsconfig.json +8 -8
- package/src/dev.ts +42 -42
- package/src/es6.tsconfig.json +10 -10
- package/src/index.ts +94 -94
- package/src/pagesconfig.json +77 -73
- package/src/tsconfig.json +32 -32
- package/src/tsconfig.types.json +9 -9
- package/src/types.d.ts +3 -3
|
@@ -1,393 +1,393 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ViewerLight = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var pointLight_1 = require("@babylonjs/core/Lights/pointLight");
|
|
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.SCALING, [
|
|
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.transformTransformNode(rootNode, {
|
|
167
|
-
scaling: parameter_1.Parameter.parseScaling(newValue),
|
|
168
|
-
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
169
|
-
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
return [2 /*return*/];
|
|
173
|
-
});
|
|
174
|
-
}); },
|
|
175
|
-
]);
|
|
176
|
-
this._parameterObservers.set(parameter_1.Parameter.POSITION, [
|
|
177
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
178
|
-
var rootNode;
|
|
179
|
-
return tslib_1.__generator(this, function (_a) {
|
|
180
|
-
rootNode = babylonHelper_1.getRootNode(light.light);
|
|
181
|
-
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
182
|
-
babylonHelper_1.transformTransformNode(rootNode, {
|
|
183
|
-
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
184
|
-
position: parameter_1.Parameter.parseVector(newValue),
|
|
185
|
-
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
return [2 /*return*/];
|
|
189
|
-
});
|
|
190
|
-
}); },
|
|
191
|
-
]);
|
|
192
|
-
this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
|
|
193
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
194
|
-
var rootNode;
|
|
195
|
-
return tslib_1.__generator(this, function (_a) {
|
|
196
|
-
rootNode = babylonHelper_1.getRootNode(light.light);
|
|
197
|
-
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
198
|
-
babylonHelper_1.transformTransformNode(rootNode, {
|
|
199
|
-
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
200
|
-
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
201
|
-
rotation: parameter_1.Parameter.parseRotation(newValue),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
return [2 /*return*/];
|
|
205
|
-
});
|
|
206
|
-
}); },
|
|
207
|
-
]);
|
|
208
|
-
this._parameterObservers.set(parameter_1.Parameter.DIRECTION, [
|
|
209
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
210
|
-
return tslib_1.__generator(this, function (_a) {
|
|
211
|
-
if ((light.light instanceof shadowLight_1.ShadowLight && !(light.light instanceof pointLight_1.PointLight)) ||
|
|
212
|
-
light.light instanceof hemisphericLight_1.HemisphericLight) {
|
|
213
|
-
lodash_es_1.set(light.light, 'direction', parameter_1.Parameter.parseVector(newValue));
|
|
214
|
-
}
|
|
215
|
-
return [2 /*return*/];
|
|
216
|
-
});
|
|
217
|
-
}); },
|
|
218
|
-
]);
|
|
219
|
-
this._parameterObservers.set(parameter_1.Parameter.ANGLE, [
|
|
220
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
221
|
-
return tslib_1.__generator(this, function (_a) {
|
|
222
|
-
if (light.light.getClassName() === 'SpotLight') {
|
|
223
|
-
lodash_es_1.set(light.light, 'angle', parameter_1.Parameter.parseNumber(newValue));
|
|
224
|
-
}
|
|
225
|
-
return [2 /*return*/];
|
|
226
|
-
});
|
|
227
|
-
}); },
|
|
228
|
-
]);
|
|
229
|
-
this._parameterObservers.set(parameter_1.Parameter.EXPONENT, [
|
|
230
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
231
|
-
return tslib_1.__generator(this, function (_a) {
|
|
232
|
-
if (light.light.getClassName() === 'SpotLight') {
|
|
233
|
-
lodash_es_1.set(light.light, 'exponent', parameter_1.Parameter.parseNumber(newValue));
|
|
234
|
-
}
|
|
235
|
-
return [2 /*return*/];
|
|
236
|
-
});
|
|
237
|
-
}); },
|
|
238
|
-
]);
|
|
239
|
-
this._parameterObservers.set(parameter_1.Parameter.DIFFUSE, [
|
|
240
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
241
|
-
return tslib_1.__generator(this, function (_a) {
|
|
242
|
-
lodash_es_1.set(light.light, 'diffuse', parameter_1.Parameter.parseColor(newValue));
|
|
243
|
-
return [2 /*return*/];
|
|
244
|
-
});
|
|
245
|
-
}); },
|
|
246
|
-
]);
|
|
247
|
-
this._parameterObservers.set(parameter_1.Parameter.SPECULAR, [
|
|
248
|
-
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
249
|
-
return tslib_1.__generator(this, function (_a) {
|
|
250
|
-
lodash_es_1.set(light.light, 'specular', parameter_1.Parameter.parseColor(newValue));
|
|
251
|
-
return [2 /*return*/];
|
|
252
|
-
});
|
|
253
|
-
}); },
|
|
254
|
-
]);
|
|
255
|
-
return this;
|
|
256
|
-
};
|
|
257
|
-
/**
|
|
258
|
-
* @param definition
|
|
259
|
-
* @protected
|
|
260
|
-
*/
|
|
261
|
-
ViewerLight.prototype.createBabylonLightFromDefinition = function (definition) {
|
|
262
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
263
|
-
var parameters, scene, lightId, babylonLight, _a, bakedLight, hemisphericLightModule, pointLightModule, directionalLightModule, spotLightModule, shadowGeneratorDefinition;
|
|
264
|
-
return tslib_1.__generator(this, function (_b) {
|
|
265
|
-
switch (_b.label) {
|
|
266
|
-
case 0:
|
|
267
|
-
parameters = parameter_1.Parameter.parseFromDeclarations(parameter_1.Parameter.declarations, this.inheritedParameters);
|
|
268
|
-
scene = this.variant.viewer.scene;
|
|
269
|
-
lightId = this.id;
|
|
270
|
-
_a = definition.type;
|
|
271
|
-
switch (_a) {
|
|
272
|
-
case 'baked': return [3 /*break*/, 1];
|
|
273
|
-
case 'hemispheric': return [3 /*break*/, 2];
|
|
274
|
-
case 'point': return [3 /*break*/, 4];
|
|
275
|
-
case 'directional': return [3 /*break*/, 6];
|
|
276
|
-
case 'spot': return [3 /*break*/, 8];
|
|
277
|
-
}
|
|
278
|
-
return [3 /*break*/, 10];
|
|
279
|
-
case 1:
|
|
280
|
-
if (!definition['path']) {
|
|
281
|
-
throw new Error("The light \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"path\".");
|
|
282
|
-
}
|
|
283
|
-
bakedLight = this.variant.inheritedLights.find(function (l) { return l.metadata.dottedPath.path === definition['path']; });
|
|
284
|
-
if (bakedLight) {
|
|
285
|
-
lightId = bakedLight.metadata.dottedPath.clone().unshiftPart(this.id).path;
|
|
286
|
-
babylonLight = babylonHelper_1.cloneNodeWithParents(bakedLight);
|
|
287
|
-
babylonLight.name = lightId;
|
|
288
|
-
babylonLight.id = lightId;
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
throw new Error("No light found for path \"" + definition['path'] + "\" in ViewerLight \"" + lightId + "\".");
|
|
292
|
-
}
|
|
293
|
-
return [3 /*break*/, 11];
|
|
294
|
-
case 2:
|
|
295
|
-
if (!parameters['direction']) {
|
|
296
|
-
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
|
|
297
|
-
}
|
|
298
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require(
|
|
299
|
-
/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight'); })];
|
|
300
|
-
case 3:
|
|
301
|
-
hemisphericLightModule = _b.sent();
|
|
302
|
-
babylonLight = new hemisphericLightModule.HemisphericLight(lightId, parameters['direction'], scene);
|
|
303
|
-
return [3 /*break*/, 11];
|
|
304
|
-
case 4: return [4 /*yield*/, Promise.resolve().then(function () { return require(
|
|
305
|
-
/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight'); })];
|
|
306
|
-
case 5:
|
|
307
|
-
pointLightModule = _b.sent();
|
|
308
|
-
babylonLight = new pointLightModule.PointLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
309
|
-
scene);
|
|
310
|
-
return [3 /*break*/, 11];
|
|
311
|
-
case 6:
|
|
312
|
-
if (!parameters['direction']) {
|
|
313
|
-
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
|
|
314
|
-
}
|
|
315
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require(
|
|
316
|
-
/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight'); })];
|
|
317
|
-
case 7:
|
|
318
|
-
directionalLightModule = _b.sent();
|
|
319
|
-
babylonLight = new directionalLightModule.DirectionalLight(lightId, parameters['direction'], scene);
|
|
320
|
-
return [3 /*break*/, 11];
|
|
321
|
-
case 8:
|
|
322
|
-
if (!parameters['direction']) {
|
|
323
|
-
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
|
|
324
|
-
}
|
|
325
|
-
if (!parameters['angle']) {
|
|
326
|
-
throw new Error("A ViewerLight of type \"" + definition.type + "\" needs an \"angle\".");
|
|
327
|
-
}
|
|
328
|
-
if (!parameters['exponent']) {
|
|
329
|
-
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs an \"exponent\".");
|
|
330
|
-
}
|
|
331
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight'); })];
|
|
332
|
-
case 9:
|
|
333
|
-
spotLightModule = _b.sent();
|
|
334
|
-
babylonLight = new spotLightModule.SpotLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
335
|
-
parameters['direction'], parameters['angle'], parameters['exponent'], scene);
|
|
336
|
-
return [3 /*break*/, 11];
|
|
337
|
-
case 10: throw new Error("The type \"" + definition.type + "\" for ViewerLight \"" + lightId + "\" is not implemented (yet).");
|
|
338
|
-
case 11:
|
|
339
|
-
if (!babylonLight) {
|
|
340
|
-
throw new Error("The Light for ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" could no be created " + "or found.");
|
|
341
|
-
}
|
|
342
|
-
if (!babylonLight.parent) {
|
|
343
|
-
// Create pseudo parent since lights do not implement mutations like "rotation" by itself.
|
|
344
|
-
babylonLight.parent = new transformNode_1.TransformNode('__light__', this.variant.viewer.scene, true);
|
|
345
|
-
}
|
|
346
|
-
babylonHelper_1.injectNodeMetadata(babylonLight.parent, {
|
|
347
|
-
variant: this.variant,
|
|
348
|
-
variantParameterizable: this,
|
|
349
|
-
});
|
|
350
|
-
// disable/hide by default
|
|
351
|
-
babylonHelper_1.disableNodeWithParents(babylonLight);
|
|
352
|
-
shadowGeneratorDefinition = lodash_es_1.get(definition, 'shadowGenerator');
|
|
353
|
-
if (!!lodash_es_1.isEmpty(shadowGeneratorDefinition)) return [3 /*break*/, 13];
|
|
354
|
-
if (!(babylonLight instanceof shadowLight_1.ShadowLight)) {
|
|
355
|
-
throw new Error("Using a ShadowGenerator with light type \"" + definition.type + "\" is not supported for " +
|
|
356
|
-
("\"" + lightId + "\". Use lights deriving from ShadowLight."));
|
|
357
|
-
}
|
|
358
|
-
return [4 /*yield*/, this.processShadowGenerator(babylonLight, shadowGeneratorDefinition)];
|
|
359
|
-
case 12:
|
|
360
|
-
_b.sent();
|
|
361
|
-
_b.label = 13;
|
|
362
|
-
case 13: return [2 /*return*/, babylonLight];
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
};
|
|
367
|
-
/**
|
|
368
|
-
* @param babylonLight
|
|
369
|
-
* @param definition
|
|
370
|
-
* @protected
|
|
371
|
-
*/
|
|
372
|
-
ViewerLight.prototype.processShadowGenerator = function (babylonLight, definition) {
|
|
373
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
374
|
-
var parameterDeclarations, parameterBag, parameters, shadowGenerator, parameter;
|
|
375
|
-
return tslib_1.__generator(this, function (_a) {
|
|
376
|
-
parameterDeclarations = {};
|
|
377
|
-
parameterBag = definition;
|
|
378
|
-
parameters = parameter_1.Parameter.parseFromDeclarations(parameterDeclarations, parameterBag);
|
|
379
|
-
shadowGenerator = new shadowGenerator_1.ShadowGenerator(parameters['mapSize'], babylonLight);
|
|
380
|
-
for (parameter in parameters) {
|
|
381
|
-
if (parameter === 'mapSize') {
|
|
382
|
-
continue;
|
|
383
|
-
}
|
|
384
|
-
lodash_es_1.set(shadowGenerator, parameter, lodash_es_1.get(parameters, parameter));
|
|
385
|
-
}
|
|
386
|
-
return [2 /*return*/, shadowGenerator];
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
return ViewerLight;
|
|
391
|
-
}(variantParameterizable_1.VariantParameterizable));
|
|
392
|
-
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 pointLight_1 = require("@babylonjs/core/Lights/pointLight");
|
|
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.SCALING, [
|
|
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.transformTransformNode(rootNode, {
|
|
167
|
+
scaling: parameter_1.Parameter.parseScaling(newValue),
|
|
168
|
+
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
169
|
+
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return [2 /*return*/];
|
|
173
|
+
});
|
|
174
|
+
}); },
|
|
175
|
+
]);
|
|
176
|
+
this._parameterObservers.set(parameter_1.Parameter.POSITION, [
|
|
177
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
178
|
+
var rootNode;
|
|
179
|
+
return tslib_1.__generator(this, function (_a) {
|
|
180
|
+
rootNode = babylonHelper_1.getRootNode(light.light);
|
|
181
|
+
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
182
|
+
babylonHelper_1.transformTransformNode(rootNode, {
|
|
183
|
+
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
184
|
+
position: parameter_1.Parameter.parseVector(newValue),
|
|
185
|
+
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return [2 /*return*/];
|
|
189
|
+
});
|
|
190
|
+
}); },
|
|
191
|
+
]);
|
|
192
|
+
this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
|
|
193
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
194
|
+
var rootNode;
|
|
195
|
+
return tslib_1.__generator(this, function (_a) {
|
|
196
|
+
rootNode = babylonHelper_1.getRootNode(light.light);
|
|
197
|
+
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
198
|
+
babylonHelper_1.transformTransformNode(rootNode, {
|
|
199
|
+
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
200
|
+
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
201
|
+
rotation: parameter_1.Parameter.parseRotation(newValue),
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return [2 /*return*/];
|
|
205
|
+
});
|
|
206
|
+
}); },
|
|
207
|
+
]);
|
|
208
|
+
this._parameterObservers.set(parameter_1.Parameter.DIRECTION, [
|
|
209
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
210
|
+
return tslib_1.__generator(this, function (_a) {
|
|
211
|
+
if ((light.light instanceof shadowLight_1.ShadowLight && !(light.light instanceof pointLight_1.PointLight)) ||
|
|
212
|
+
light.light instanceof hemisphericLight_1.HemisphericLight) {
|
|
213
|
+
lodash_es_1.set(light.light, 'direction', parameter_1.Parameter.parseVector(newValue));
|
|
214
|
+
}
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
});
|
|
217
|
+
}); },
|
|
218
|
+
]);
|
|
219
|
+
this._parameterObservers.set(parameter_1.Parameter.ANGLE, [
|
|
220
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
221
|
+
return tslib_1.__generator(this, function (_a) {
|
|
222
|
+
if (light.light.getClassName() === 'SpotLight') {
|
|
223
|
+
lodash_es_1.set(light.light, 'angle', parameter_1.Parameter.parseNumber(newValue));
|
|
224
|
+
}
|
|
225
|
+
return [2 /*return*/];
|
|
226
|
+
});
|
|
227
|
+
}); },
|
|
228
|
+
]);
|
|
229
|
+
this._parameterObservers.set(parameter_1.Parameter.EXPONENT, [
|
|
230
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
231
|
+
return tslib_1.__generator(this, function (_a) {
|
|
232
|
+
if (light.light.getClassName() === 'SpotLight') {
|
|
233
|
+
lodash_es_1.set(light.light, 'exponent', parameter_1.Parameter.parseNumber(newValue));
|
|
234
|
+
}
|
|
235
|
+
return [2 /*return*/];
|
|
236
|
+
});
|
|
237
|
+
}); },
|
|
238
|
+
]);
|
|
239
|
+
this._parameterObservers.set(parameter_1.Parameter.DIFFUSE, [
|
|
240
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
241
|
+
return tslib_1.__generator(this, function (_a) {
|
|
242
|
+
lodash_es_1.set(light.light, 'diffuse', parameter_1.Parameter.parseColor(newValue));
|
|
243
|
+
return [2 /*return*/];
|
|
244
|
+
});
|
|
245
|
+
}); },
|
|
246
|
+
]);
|
|
247
|
+
this._parameterObservers.set(parameter_1.Parameter.SPECULAR, [
|
|
248
|
+
function (light, oldValue, newValue) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
249
|
+
return tslib_1.__generator(this, function (_a) {
|
|
250
|
+
lodash_es_1.set(light.light, 'specular', parameter_1.Parameter.parseColor(newValue));
|
|
251
|
+
return [2 /*return*/];
|
|
252
|
+
});
|
|
253
|
+
}); },
|
|
254
|
+
]);
|
|
255
|
+
return this;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* @param definition
|
|
259
|
+
* @protected
|
|
260
|
+
*/
|
|
261
|
+
ViewerLight.prototype.createBabylonLightFromDefinition = function (definition) {
|
|
262
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
263
|
+
var parameters, scene, lightId, babylonLight, _a, bakedLight, hemisphericLightModule, pointLightModule, directionalLightModule, spotLightModule, shadowGeneratorDefinition;
|
|
264
|
+
return tslib_1.__generator(this, function (_b) {
|
|
265
|
+
switch (_b.label) {
|
|
266
|
+
case 0:
|
|
267
|
+
parameters = parameter_1.Parameter.parseFromDeclarations(parameter_1.Parameter.declarations, this.inheritedParameters);
|
|
268
|
+
scene = this.variant.viewer.scene;
|
|
269
|
+
lightId = this.id;
|
|
270
|
+
_a = definition.type;
|
|
271
|
+
switch (_a) {
|
|
272
|
+
case 'baked': return [3 /*break*/, 1];
|
|
273
|
+
case 'hemispheric': return [3 /*break*/, 2];
|
|
274
|
+
case 'point': return [3 /*break*/, 4];
|
|
275
|
+
case 'directional': return [3 /*break*/, 6];
|
|
276
|
+
case 'spot': return [3 /*break*/, 8];
|
|
277
|
+
}
|
|
278
|
+
return [3 /*break*/, 10];
|
|
279
|
+
case 1:
|
|
280
|
+
if (!definition['path']) {
|
|
281
|
+
throw new Error("The light \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"path\".");
|
|
282
|
+
}
|
|
283
|
+
bakedLight = this.variant.inheritedLights.find(function (l) { return l.metadata.dottedPath.path === definition['path']; });
|
|
284
|
+
if (bakedLight) {
|
|
285
|
+
lightId = bakedLight.metadata.dottedPath.clone().unshiftPart(this.id).path;
|
|
286
|
+
babylonLight = babylonHelper_1.cloneNodeWithParents(bakedLight);
|
|
287
|
+
babylonLight.name = lightId;
|
|
288
|
+
babylonLight.id = lightId;
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
throw new Error("No light found for path \"" + definition['path'] + "\" in ViewerLight \"" + lightId + "\".");
|
|
292
|
+
}
|
|
293
|
+
return [3 /*break*/, 11];
|
|
294
|
+
case 2:
|
|
295
|
+
if (!parameters['direction']) {
|
|
296
|
+
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
|
|
297
|
+
}
|
|
298
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return require(
|
|
299
|
+
/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight'); })];
|
|
300
|
+
case 3:
|
|
301
|
+
hemisphericLightModule = _b.sent();
|
|
302
|
+
babylonLight = new hemisphericLightModule.HemisphericLight(lightId, parameters['direction'], scene);
|
|
303
|
+
return [3 /*break*/, 11];
|
|
304
|
+
case 4: return [4 /*yield*/, Promise.resolve().then(function () { return require(
|
|
305
|
+
/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight'); })];
|
|
306
|
+
case 5:
|
|
307
|
+
pointLightModule = _b.sent();
|
|
308
|
+
babylonLight = new pointLightModule.PointLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
309
|
+
scene);
|
|
310
|
+
return [3 /*break*/, 11];
|
|
311
|
+
case 6:
|
|
312
|
+
if (!parameters['direction']) {
|
|
313
|
+
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
|
|
314
|
+
}
|
|
315
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return require(
|
|
316
|
+
/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight'); })];
|
|
317
|
+
case 7:
|
|
318
|
+
directionalLightModule = _b.sent();
|
|
319
|
+
babylonLight = new directionalLightModule.DirectionalLight(lightId, parameters['direction'], scene);
|
|
320
|
+
return [3 /*break*/, 11];
|
|
321
|
+
case 8:
|
|
322
|
+
if (!parameters['direction']) {
|
|
323
|
+
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs a \"direction\".");
|
|
324
|
+
}
|
|
325
|
+
if (!parameters['angle']) {
|
|
326
|
+
throw new Error("A ViewerLight of type \"" + definition.type + "\" needs an \"angle\".");
|
|
327
|
+
}
|
|
328
|
+
if (!parameters['exponent']) {
|
|
329
|
+
throw new Error("The ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" needs an \"exponent\".");
|
|
330
|
+
}
|
|
331
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return require(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight'); })];
|
|
332
|
+
case 9:
|
|
333
|
+
spotLightModule = _b.sent();
|
|
334
|
+
babylonLight = new spotLightModule.SpotLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
335
|
+
parameters['direction'], parameters['angle'], parameters['exponent'], scene);
|
|
336
|
+
return [3 /*break*/, 11];
|
|
337
|
+
case 10: throw new Error("The type \"" + definition.type + "\" for ViewerLight \"" + lightId + "\" is not implemented (yet).");
|
|
338
|
+
case 11:
|
|
339
|
+
if (!babylonLight) {
|
|
340
|
+
throw new Error("The Light for ViewerLight \"" + lightId + "\" of type \"" + definition.type + "\" could no be created " + "or found.");
|
|
341
|
+
}
|
|
342
|
+
if (!babylonLight.parent) {
|
|
343
|
+
// Create pseudo parent since lights do not implement mutations like "rotation" by itself.
|
|
344
|
+
babylonLight.parent = new transformNode_1.TransformNode('__light__', this.variant.viewer.scene, true);
|
|
345
|
+
}
|
|
346
|
+
babylonHelper_1.injectNodeMetadata(babylonLight.parent, {
|
|
347
|
+
variant: this.variant,
|
|
348
|
+
variantParameterizable: this,
|
|
349
|
+
});
|
|
350
|
+
// disable/hide by default
|
|
351
|
+
babylonHelper_1.disableNodeWithParents(babylonLight);
|
|
352
|
+
shadowGeneratorDefinition = lodash_es_1.get(definition, 'shadowGenerator');
|
|
353
|
+
if (!!lodash_es_1.isEmpty(shadowGeneratorDefinition)) return [3 /*break*/, 13];
|
|
354
|
+
if (!(babylonLight instanceof shadowLight_1.ShadowLight)) {
|
|
355
|
+
throw new Error("Using a ShadowGenerator with light type \"" + definition.type + "\" is not supported for " +
|
|
356
|
+
("\"" + lightId + "\". Use lights deriving from ShadowLight."));
|
|
357
|
+
}
|
|
358
|
+
return [4 /*yield*/, this.processShadowGenerator(babylonLight, shadowGeneratorDefinition)];
|
|
359
|
+
case 12:
|
|
360
|
+
_b.sent();
|
|
361
|
+
_b.label = 13;
|
|
362
|
+
case 13: return [2 /*return*/, babylonLight];
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* @param babylonLight
|
|
369
|
+
* @param definition
|
|
370
|
+
* @protected
|
|
371
|
+
*/
|
|
372
|
+
ViewerLight.prototype.processShadowGenerator = function (babylonLight, definition) {
|
|
373
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
374
|
+
var parameterDeclarations, parameterBag, parameters, shadowGenerator, parameter;
|
|
375
|
+
return tslib_1.__generator(this, function (_a) {
|
|
376
|
+
parameterDeclarations = {};
|
|
377
|
+
parameterBag = definition;
|
|
378
|
+
parameters = parameter_1.Parameter.parseFromDeclarations(parameterDeclarations, parameterBag);
|
|
379
|
+
shadowGenerator = new shadowGenerator_1.ShadowGenerator(parameters['mapSize'], babylonLight);
|
|
380
|
+
for (parameter in parameters) {
|
|
381
|
+
if (parameter === 'mapSize') {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
lodash_es_1.set(shadowGenerator, parameter, lodash_es_1.get(parameters, parameter));
|
|
385
|
+
}
|
|
386
|
+
return [2 /*return*/, shadowGenerator];
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
return ViewerLight;
|
|
391
|
+
}(variantParameterizable_1.VariantParameterizable));
|
|
392
|
+
exports.ViewerLight = ViewerLight;
|
|
393
393
|
//# sourceMappingURL=viewerLight.js.map
|