@combeenation/3d-viewer 12.4.1 → 12.4.3
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 +9 -9
- package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
- package/dist/lib-cjs/api/classes/animationInterface.js +2 -2
- package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
- package/dist/lib-cjs/api/classes/dottedPath.js +166 -166
- package/dist/lib-cjs/api/classes/element.d.ts +153 -153
- package/dist/lib-cjs/api/classes/element.js +702 -702
- package/dist/lib-cjs/api/classes/event.d.ts +401 -401
- package/dist/lib-cjs/api/classes/event.js +424 -424
- package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
- package/dist/lib-cjs/api/classes/eventBroadcaster.js +49 -49
- package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +7 -7
- package/dist/lib-cjs/api/classes/fuzzyMap.js +21 -21
- package/dist/lib-cjs/api/classes/parameter.d.ts +410 -410
- package/dist/lib-cjs/api/classes/parameter.js +642 -642
- package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
- package/dist/lib-cjs/api/classes/parameterObservable.js +72 -72
- package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
- package/dist/lib-cjs/api/classes/parameterizable.js +102 -102
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +45 -45
- package/dist/lib-cjs/api/classes/placementAnimation.js +176 -176
- package/dist/lib-cjs/api/classes/variant.d.ts +261 -261
- package/dist/lib-cjs/api/classes/variant.js +872 -872
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +53 -53
- package/dist/lib-cjs/api/classes/variantInstance.js +125 -125
- package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
- package/dist/lib-cjs/api/classes/variantParameterizable.js +86 -86
- package/dist/lib-cjs/api/classes/viewer.d.ts +215 -215
- package/dist/lib-cjs/api/classes/viewer.js +708 -708
- package/dist/lib-cjs/api/classes/viewerError.d.ts +43 -43
- package/dist/lib-cjs/api/classes/viewerError.js +55 -55
- package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -66
- package/dist/lib-cjs/api/classes/viewerLight.js +344 -344
- 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 -13
- package/dist/lib-cjs/api/internal/sceneSetup.js +227 -227
- package/dist/lib-cjs/api/manager/animationManager.d.ts +30 -30
- package/dist/lib-cjs/api/manager/animationManager.js +126 -126
- package/dist/lib-cjs/api/manager/gltfExportManager.d.ts +80 -80
- package/dist/lib-cjs/api/manager/gltfExportManager.js +300 -299
- package/dist/lib-cjs/api/manager/gltfExportManager.js.map +1 -1
- package/dist/lib-cjs/api/manager/sceneManager.d.ts +33 -33
- package/dist/lib-cjs/api/manager/sceneManager.js +128 -128
- package/dist/lib-cjs/api/manager/tagManager.d.ts +118 -118
- package/dist/lib-cjs/api/manager/tagManager.js +530 -530
- package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +22 -22
- package/dist/lib-cjs/api/manager/textureLoadManager.js +107 -107
- package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +106 -106
- package/dist/lib-cjs/api/manager/variantInstanceManager.js +290 -290
- package/dist/lib-cjs/api/store/specStorage.d.ts +32 -32
- package/dist/lib-cjs/api/store/specStorage.js +65 -65
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +238 -238
- package/dist/lib-cjs/api/util/babylonHelper.js +825 -825
- package/dist/lib-cjs/api/util/debugHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/debugHelper.js +93 -93
- package/dist/lib-cjs/api/util/deviceHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/deviceHelper.js +28 -28
- package/dist/lib-cjs/api/util/geometryHelper.d.ts +17 -17
- package/dist/lib-cjs/api/util/geometryHelper.js +112 -112
- package/dist/lib-cjs/api/util/globalTypes.d.ts +490 -490
- package/dist/lib-cjs/api/util/globalTypes.js +1 -1
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +58 -58
- package/dist/lib-cjs/api/util/resourceHelper.js +214 -214
- package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +58 -58
- package/dist/lib-cjs/api/util/sceneLoaderHelper.js +228 -228
- package/dist/lib-cjs/api/util/stringHelper.d.ts +13 -13
- package/dist/lib-cjs/api/util/stringHelper.js +32 -32
- package/dist/lib-cjs/api/util/structureHelper.d.ts +9 -9
- package/dist/lib-cjs/api/util/structureHelper.js +57 -57
- package/dist/lib-cjs/buildinfo.json +3 -3
- package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
- package/dist/lib-cjs/index.d.ts +63 -63
- package/dist/lib-cjs/index.js +128 -128
- package/package.json +93 -92
- package/src/api/classes/animationInterface.ts +10 -10
- package/src/api/classes/dottedPath.ts +181 -181
- package/src/api/classes/element.ts +766 -766
- package/src/api/classes/event.ts +457 -457
- package/src/api/classes/eventBroadcaster.ts +52 -52
- package/src/api/classes/fuzzyMap.ts +21 -21
- package/src/api/classes/parameter.ts +686 -686
- package/src/api/classes/parameterObservable.ts +73 -73
- package/src/api/classes/parameterizable.ts +87 -87
- package/src/api/classes/placementAnimation.ts +162 -162
- package/src/api/classes/variant.ts +965 -965
- package/src/api/classes/variantInstance.ts +123 -123
- package/src/api/classes/variantParameterizable.ts +83 -83
- package/src/api/classes/viewer.ts +751 -751
- package/src/api/classes/viewerError.ts +63 -63
- package/src/api/classes/viewerLight.ts +335 -335
- package/src/api/internal/debugViewer.ts +90 -90
- package/src/api/internal/lensRendering.ts +9 -9
- package/src/api/internal/sceneSetup.ts +208 -208
- package/src/api/manager/animationManager.ts +143 -143
- package/src/api/manager/gltfExportManager.ts +337 -334
- package/src/api/manager/sceneManager.ts +134 -134
- package/src/api/manager/tagManager.ts +572 -572
- package/src/api/manager/textureLoadManager.ts +107 -107
- package/src/api/manager/variantInstanceManager.ts +306 -306
- package/src/api/store/specStorage.ts +68 -68
- package/src/api/util/babylonHelper.ts +915 -915
- package/src/api/util/debugHelper.ts +121 -121
- package/src/api/util/deviceHelper.ts +31 -31
- package/src/api/util/geometryHelper.ts +142 -142
- package/src/api/util/globalTypes.ts +566 -566
- package/src/api/util/resourceHelper.ts +201 -201
- package/src/api/util/sceneLoaderHelper.ts +247 -247
- package/src/api/util/stringHelper.ts +30 -30
- package/src/api/util/structureHelper.ts +62 -62
- package/src/buildinfo.json +3 -3
- package/src/dev.ts +70 -70
- package/src/index.ts +116 -116
- package/src/types.d.ts +49 -49
|
@@ -1,345 +1,345 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.ViewerLight = void 0;
|
|
36
|
-
const babylonHelper_1 = require("./../util/babylonHelper");
|
|
37
|
-
const dottedPath_1 = require("./dottedPath");
|
|
38
|
-
const parameter_1 = require("./parameter");
|
|
39
|
-
const variantParameterizable_1 = require("./variantParameterizable");
|
|
40
|
-
const shadowGenerator_1 = require("@babylonjs/core/Lights/Shadows/shadowGenerator");
|
|
41
|
-
require("@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent");
|
|
42
|
-
const hemisphericLight_1 = require("@babylonjs/core/Lights/hemisphericLight");
|
|
43
|
-
const pointLight_1 = require("@babylonjs/core/Lights/pointLight");
|
|
44
|
-
const shadowLight_1 = require("@babylonjs/core/Lights/shadowLight");
|
|
45
|
-
const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
|
|
46
|
-
const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
|
|
47
|
-
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual");
|
|
48
|
-
const lodash_es_1 = require("lodash-es");
|
|
49
|
-
/**
|
|
50
|
-
* A {@link ViewerLight} of a {@link Variant}. Acts as a container for Babylon.js lights. Lives only in the context of a
|
|
51
|
-
* {@link Variant}.
|
|
52
|
-
*/
|
|
53
|
-
class ViewerLight extends variantParameterizable_1.VariantParameterizable {
|
|
54
|
-
/**
|
|
55
|
-
* Constructor.
|
|
56
|
-
*/
|
|
57
|
-
constructor(variant, name) {
|
|
58
|
-
super(variant, name);
|
|
59
|
-
this.variant = variant;
|
|
60
|
-
this.name = name;
|
|
61
|
-
this.addParameterObservers();
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Creates a {@link ViewerLight} with given name.
|
|
65
|
-
*/
|
|
66
|
-
static create(variant, name) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const viewerLight = new ViewerLight(variant, name);
|
|
69
|
-
viewerLight._light = yield viewerLight.createBabylonLightFromDefinition(viewerLight.definition);
|
|
70
|
-
return viewerLight;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* The wrapped Light.
|
|
75
|
-
*/
|
|
76
|
-
get light() {
|
|
77
|
-
if (!this._light) {
|
|
78
|
-
throw new Error(`Light for ViewerLight "${this.name}" has not been properly initialized.`);
|
|
79
|
-
}
|
|
80
|
-
return this._light;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* The {@link DottedPath} in the built tree of {@link ViewerLight}s.
|
|
84
|
-
* E.g. "_.top-1.sub-2.sub-sub-3.el-1"
|
|
85
|
-
*/
|
|
86
|
-
get dottedPath() {
|
|
87
|
-
return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* The id representing a {@link DottedPath}.
|
|
91
|
-
*/
|
|
92
|
-
get id() {
|
|
93
|
-
const dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
|
|
94
|
-
dottedPath.shiftPart(); // remove root
|
|
95
|
-
return dottedPath.path;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The {@link LightDefinition} of the {@link ViewerLight}.
|
|
99
|
-
*/
|
|
100
|
-
get definition() {
|
|
101
|
-
const definition = this.variant.structureJson.lights[this.name];
|
|
102
|
-
if ((0, lodash_es_1.isString)(definition)) {
|
|
103
|
-
return {
|
|
104
|
-
type: 'baked',
|
|
105
|
-
path: definition,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return definition;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The type of the {@link ViewerLight}'s light.
|
|
112
|
-
*/
|
|
113
|
-
get type() {
|
|
114
|
-
return this.light.constructor.name.replace(/light/i, '').toLowerCase();
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @see {@link VariantParameterizable.commitParameters}
|
|
118
|
-
* @emit {@link Event.VIEWER_LIGHT_PARAMETER_COMMITTED}
|
|
119
|
-
*/
|
|
120
|
-
commitParameters(parameters) {
|
|
121
|
-
const _super = Object.create(null, {
|
|
122
|
-
commitParameters: { get: () => super.commitParameters }
|
|
123
|
-
});
|
|
124
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
return _super.commitParameters.call(this, parameters);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
|
|
130
|
-
*/
|
|
131
|
-
addParameterObservers() {
|
|
132
|
-
this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
|
|
133
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
-
let visible;
|
|
135
|
-
try {
|
|
136
|
-
visible = parameter_1.Parameter.parseBoolean(newValue);
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (visible === true) {
|
|
142
|
-
(0, babylonHelper_1.enableNodeWithParents)(light.light);
|
|
143
|
-
}
|
|
144
|
-
else if (visible === false) {
|
|
145
|
-
(0, babylonHelper_1.disableNodeWithParents)(light.light);
|
|
146
|
-
}
|
|
147
|
-
}),
|
|
148
|
-
]);
|
|
149
|
-
this._parameterObservers.set(parameter_1.Parameter.INTENSITY, [
|
|
150
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
(0, lodash_es_1.set)(light.light, 'intensity', parameter_1.Parameter.parseNumber(newValue));
|
|
152
|
-
}),
|
|
153
|
-
]);
|
|
154
|
-
this._parameterObservers.set(parameter_1.Parameter.SCALING, [
|
|
155
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
157
|
-
const rootNode = (0, babylonHelper_1.getRootNode)(light.light);
|
|
158
|
-
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
159
|
-
(0, babylonHelper_1.transformTransformNode)(rootNode, {
|
|
160
|
-
scaling: parameter_1.Parameter.parseScaling(newValue),
|
|
161
|
-
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
162
|
-
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
}),
|
|
166
|
-
]);
|
|
167
|
-
this._parameterObservers.set(parameter_1.Parameter.POSITION, [
|
|
168
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
170
|
-
const rootNode = (0, babylonHelper_1.getRootNode)(light.light);
|
|
171
|
-
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
172
|
-
(0, babylonHelper_1.transformTransformNode)(rootNode, {
|
|
173
|
-
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
174
|
-
position: parameter_1.Parameter.parseVector(newValue),
|
|
175
|
-
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}),
|
|
179
|
-
]);
|
|
180
|
-
this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
|
|
181
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
182
|
-
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
183
|
-
const rootNode = (0, babylonHelper_1.getRootNode)(light.light);
|
|
184
|
-
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
185
|
-
(0, babylonHelper_1.transformTransformNode)(rootNode, {
|
|
186
|
-
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
187
|
-
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
188
|
-
rotation: parameter_1.Parameter.parseRotation(newValue),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
}),
|
|
192
|
-
]);
|
|
193
|
-
this._parameterObservers.set(parameter_1.Parameter.DIRECTION, [
|
|
194
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
195
|
-
if ((light.light instanceof shadowLight_1.ShadowLight && !(light.light instanceof pointLight_1.PointLight)) ||
|
|
196
|
-
light.light instanceof hemisphericLight_1.HemisphericLight) {
|
|
197
|
-
(0, lodash_es_1.set)(light.light, 'direction', parameter_1.Parameter.parseVector(newValue));
|
|
198
|
-
}
|
|
199
|
-
}),
|
|
200
|
-
]);
|
|
201
|
-
this._parameterObservers.set(parameter_1.Parameter.ANGLE, [
|
|
202
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
if (light.light.getClassName() === 'SpotLight') {
|
|
204
|
-
(0, lodash_es_1.set)(light.light, 'angle', parameter_1.Parameter.parseNumber(newValue));
|
|
205
|
-
}
|
|
206
|
-
}),
|
|
207
|
-
]);
|
|
208
|
-
this._parameterObservers.set(parameter_1.Parameter.EXPONENT, [
|
|
209
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
-
if (light.light.getClassName() === 'SpotLight') {
|
|
211
|
-
(0, lodash_es_1.set)(light.light, 'exponent', parameter_1.Parameter.parseNumber(newValue));
|
|
212
|
-
}
|
|
213
|
-
}),
|
|
214
|
-
]);
|
|
215
|
-
this._parameterObservers.set(parameter_1.Parameter.DIFFUSE, [
|
|
216
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
(0, lodash_es_1.set)(light.light, 'diffuse', parameter_1.Parameter.parseColor(newValue));
|
|
218
|
-
}),
|
|
219
|
-
]);
|
|
220
|
-
this._parameterObservers.set(parameter_1.Parameter.SPECULAR, [
|
|
221
|
-
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
(0, lodash_es_1.set)(light.light, 'specular', parameter_1.Parameter.parseColor(newValue));
|
|
223
|
-
}),
|
|
224
|
-
]);
|
|
225
|
-
return this;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* @param definition
|
|
229
|
-
* @protected
|
|
230
|
-
*/
|
|
231
|
-
createBabylonLightFromDefinition(definition) {
|
|
232
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
const parameters = parameter_1.Parameter.parseFromDeclarations(parameter_1.Parameter.declarations, this.inheritedParameters);
|
|
234
|
-
const scene = this.variant.viewer.scene;
|
|
235
|
-
let lightId = this.id;
|
|
236
|
-
let babylonLight;
|
|
237
|
-
switch (definition.type) {
|
|
238
|
-
case 'baked': {
|
|
239
|
-
if (!definition['path']) {
|
|
240
|
-
throw new Error(`The light "${lightId}" of type "${definition.type}" needs a "path".`);
|
|
241
|
-
}
|
|
242
|
-
const bakedLight = this.variant.inheritedLights.find(l => l.metadata.dottedPath.path === definition['path']);
|
|
243
|
-
if (bakedLight) {
|
|
244
|
-
lightId = bakedLight.metadata.dottedPath.clone().unshiftPart(this.id).path;
|
|
245
|
-
babylonLight = (0, babylonHelper_1.cloneNodeWithParents)(bakedLight);
|
|
246
|
-
babylonLight.name = lightId;
|
|
247
|
-
babylonLight.id = lightId;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
throw new Error(`No light found for path "${definition['path']}" in ViewerLight "${lightId}".`);
|
|
251
|
-
}
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
case 'hemispheric': {
|
|
255
|
-
if (!parameters['direction']) {
|
|
256
|
-
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".`);
|
|
257
|
-
}
|
|
258
|
-
const hemisphericLightModule = yield Promise.resolve().then(() => __importStar(require(
|
|
259
|
-
/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight')));
|
|
260
|
-
babylonLight = new hemisphericLightModule.HemisphericLight(lightId, parameters['direction'], scene);
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
case 'point': {
|
|
264
|
-
const pointLightModule = yield Promise.resolve().then(() => __importStar(require(
|
|
265
|
-
/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight')));
|
|
266
|
-
babylonLight = new pointLightModule.PointLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
267
|
-
scene);
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
case 'directional': {
|
|
271
|
-
if (!parameters['direction']) {
|
|
272
|
-
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".`);
|
|
273
|
-
}
|
|
274
|
-
const directionalLightModule = yield Promise.resolve().then(() => __importStar(require(
|
|
275
|
-
/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight')));
|
|
276
|
-
babylonLight = new directionalLightModule.DirectionalLight(lightId, parameters['direction'], scene);
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
case 'spot': {
|
|
280
|
-
if (!parameters['direction']) {
|
|
281
|
-
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".`);
|
|
282
|
-
}
|
|
283
|
-
if (!parameters['angle']) {
|
|
284
|
-
throw new Error(`A ViewerLight of type "${definition.type}" needs an "angle".`);
|
|
285
|
-
}
|
|
286
|
-
if (!parameters['exponent']) {
|
|
287
|
-
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs an "exponent".`);
|
|
288
|
-
}
|
|
289
|
-
const spotLightModule = yield Promise.resolve().then(() => __importStar(require(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight')));
|
|
290
|
-
babylonLight = new spotLightModule.SpotLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
291
|
-
parameters['direction'], parameters['angle'], parameters['exponent'], scene);
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
default:
|
|
295
|
-
throw new Error(`The type "${definition.type}" for ViewerLight "${lightId}" is not implemented (yet).`);
|
|
296
|
-
}
|
|
297
|
-
if (!babylonLight) {
|
|
298
|
-
throw new Error(`The Light for ViewerLight "${lightId}" of type "${definition.type}" could no be created ` + `or found.`);
|
|
299
|
-
}
|
|
300
|
-
if (!babylonLight.parent) {
|
|
301
|
-
// Create pseudo parent since lights do not implement mutations like "rotation" by itself.
|
|
302
|
-
babylonLight.parent = new transformNode_1.TransformNode('__light__', this.variant.viewer.scene, true);
|
|
303
|
-
}
|
|
304
|
-
(0, babylonHelper_1.injectMetadata)(babylonLight.parent, {
|
|
305
|
-
variant: this.variant,
|
|
306
|
-
variantParameterizable: this,
|
|
307
|
-
});
|
|
308
|
-
// disable/hide by default
|
|
309
|
-
(0, babylonHelper_1.disableNodeWithParents)(babylonLight);
|
|
310
|
-
// process shadow generator
|
|
311
|
-
const shadowGeneratorDefinition = (0, lodash_es_1.get)(definition, 'shadowGenerator');
|
|
312
|
-
if (!(0, lodash_es_1.isEmpty)(shadowGeneratorDefinition)) {
|
|
313
|
-
if (!(babylonLight instanceof shadowLight_1.ShadowLight)) {
|
|
314
|
-
throw new Error(`Using a ShadowGenerator with light type "${definition.type}" is not supported for ` +
|
|
315
|
-
`"${lightId}". Use lights deriving from ShadowLight.`);
|
|
316
|
-
}
|
|
317
|
-
yield this.processShadowGenerator(babylonLight, shadowGeneratorDefinition);
|
|
318
|
-
}
|
|
319
|
-
return babylonLight;
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* @param babylonLight
|
|
324
|
-
* @param definition
|
|
325
|
-
* @protected
|
|
326
|
-
*/
|
|
327
|
-
processShadowGenerator(babylonLight, definition) {
|
|
328
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
-
const parameterDeclarations = {};
|
|
330
|
-
// define declarations here if needed in future
|
|
331
|
-
const parameterBag = definition;
|
|
332
|
-
const parameters = parameter_1.Parameter.parseFromDeclarations(parameterDeclarations, parameterBag);
|
|
333
|
-
const shadowGenerator = new shadowGenerator_1.ShadowGenerator(parameters['mapSize'], babylonLight);
|
|
334
|
-
for (const parameter in parameters) {
|
|
335
|
-
if (parameter === 'mapSize') {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
(0, lodash_es_1.set)(shadowGenerator, parameter, (0, lodash_es_1.get)(parameters, parameter));
|
|
339
|
-
}
|
|
340
|
-
return shadowGenerator;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
exports.ViewerLight = ViewerLight;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.ViewerLight = void 0;
|
|
36
|
+
const babylonHelper_1 = require("./../util/babylonHelper");
|
|
37
|
+
const dottedPath_1 = require("./dottedPath");
|
|
38
|
+
const parameter_1 = require("./parameter");
|
|
39
|
+
const variantParameterizable_1 = require("./variantParameterizable");
|
|
40
|
+
const shadowGenerator_1 = require("@babylonjs/core/Lights/Shadows/shadowGenerator");
|
|
41
|
+
require("@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent");
|
|
42
|
+
const hemisphericLight_1 = require("@babylonjs/core/Lights/hemisphericLight");
|
|
43
|
+
const pointLight_1 = require("@babylonjs/core/Lights/pointLight");
|
|
44
|
+
const shadowLight_1 = require("@babylonjs/core/Lights/shadowLight");
|
|
45
|
+
const math_vector_1 = require("@babylonjs/core/Maths/math.vector");
|
|
46
|
+
const transformNode_1 = require("@babylonjs/core/Meshes/transformNode");
|
|
47
|
+
require("@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual");
|
|
48
|
+
const lodash_es_1 = require("lodash-es");
|
|
49
|
+
/**
|
|
50
|
+
* A {@link ViewerLight} of a {@link Variant}. Acts as a container for Babylon.js lights. Lives only in the context of a
|
|
51
|
+
* {@link Variant}.
|
|
52
|
+
*/
|
|
53
|
+
class ViewerLight extends variantParameterizable_1.VariantParameterizable {
|
|
54
|
+
/**
|
|
55
|
+
* Constructor.
|
|
56
|
+
*/
|
|
57
|
+
constructor(variant, name) {
|
|
58
|
+
super(variant, name);
|
|
59
|
+
this.variant = variant;
|
|
60
|
+
this.name = name;
|
|
61
|
+
this.addParameterObservers();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates a {@link ViewerLight} with given name.
|
|
65
|
+
*/
|
|
66
|
+
static create(variant, name) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const viewerLight = new ViewerLight(variant, name);
|
|
69
|
+
viewerLight._light = yield viewerLight.createBabylonLightFromDefinition(viewerLight.definition);
|
|
70
|
+
return viewerLight;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The wrapped Light.
|
|
75
|
+
*/
|
|
76
|
+
get light() {
|
|
77
|
+
if (!this._light) {
|
|
78
|
+
throw new Error(`Light for ViewerLight "${this.name}" has not been properly initialized.`);
|
|
79
|
+
}
|
|
80
|
+
return this._light;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The {@link DottedPath} in the built tree of {@link ViewerLight}s.
|
|
84
|
+
* E.g. "_.top-1.sub-2.sub-sub-3.el-1"
|
|
85
|
+
*/
|
|
86
|
+
get dottedPath() {
|
|
87
|
+
return dottedPath_1.DottedPath.create(this.variant.dottedPath).addPart(this.name);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The id representing a {@link DottedPath}.
|
|
91
|
+
*/
|
|
92
|
+
get id() {
|
|
93
|
+
const dottedPath = dottedPath_1.DottedPath.create(this.dottedPath);
|
|
94
|
+
dottedPath.shiftPart(); // remove root
|
|
95
|
+
return dottedPath.path;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The {@link LightDefinition} of the {@link ViewerLight}.
|
|
99
|
+
*/
|
|
100
|
+
get definition() {
|
|
101
|
+
const definition = this.variant.structureJson.lights[this.name];
|
|
102
|
+
if ((0, lodash_es_1.isString)(definition)) {
|
|
103
|
+
return {
|
|
104
|
+
type: 'baked',
|
|
105
|
+
path: definition,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return definition;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The type of the {@link ViewerLight}'s light.
|
|
112
|
+
*/
|
|
113
|
+
get type() {
|
|
114
|
+
return this.light.constructor.name.replace(/light/i, '').toLowerCase();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @see {@link VariantParameterizable.commitParameters}
|
|
118
|
+
* @emit {@link Event.VIEWER_LIGHT_PARAMETER_COMMITTED}
|
|
119
|
+
*/
|
|
120
|
+
commitParameters(parameters) {
|
|
121
|
+
const _super = Object.create(null, {
|
|
122
|
+
commitParameters: { get: () => super.commitParameters }
|
|
123
|
+
});
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
return _super.commitParameters.call(this, parameters);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
|
|
130
|
+
*/
|
|
131
|
+
addParameterObservers() {
|
|
132
|
+
this._parameterObservers.set(parameter_1.Parameter.VISIBLE, [
|
|
133
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
let visible;
|
|
135
|
+
try {
|
|
136
|
+
visible = parameter_1.Parameter.parseBoolean(newValue);
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (visible === true) {
|
|
142
|
+
(0, babylonHelper_1.enableNodeWithParents)(light.light);
|
|
143
|
+
}
|
|
144
|
+
else if (visible === false) {
|
|
145
|
+
(0, babylonHelper_1.disableNodeWithParents)(light.light);
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
]);
|
|
149
|
+
this._parameterObservers.set(parameter_1.Parameter.INTENSITY, [
|
|
150
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
(0, lodash_es_1.set)(light.light, 'intensity', parameter_1.Parameter.parseNumber(newValue));
|
|
152
|
+
}),
|
|
153
|
+
]);
|
|
154
|
+
this._parameterObservers.set(parameter_1.Parameter.SCALING, [
|
|
155
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
157
|
+
const rootNode = (0, babylonHelper_1.getRootNode)(light.light);
|
|
158
|
+
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
159
|
+
(0, babylonHelper_1.transformTransformNode)(rootNode, {
|
|
160
|
+
scaling: parameter_1.Parameter.parseScaling(newValue),
|
|
161
|
+
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
162
|
+
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
]);
|
|
167
|
+
this._parameterObservers.set(parameter_1.Parameter.POSITION, [
|
|
168
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
170
|
+
const rootNode = (0, babylonHelper_1.getRootNode)(light.light);
|
|
171
|
+
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
172
|
+
(0, babylonHelper_1.transformTransformNode)(rootNode, {
|
|
173
|
+
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
174
|
+
position: parameter_1.Parameter.parseVector(newValue),
|
|
175
|
+
rotation: parameter_1.Parameter.parseRotation(light.inheritedParameters[parameter_1.Parameter.ROTATION] || '(0, 0, 0)'),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
]);
|
|
180
|
+
this._parameterObservers.set(parameter_1.Parameter.ROTATION, [
|
|
181
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
// we have to deal just with root nodes here due to relative impacts in a node tree
|
|
183
|
+
const rootNode = (0, babylonHelper_1.getRootNode)(light.light);
|
|
184
|
+
if (rootNode instanceof transformNode_1.TransformNode) {
|
|
185
|
+
(0, babylonHelper_1.transformTransformNode)(rootNode, {
|
|
186
|
+
scaling: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.SCALING] || '(1, 1, 1)'),
|
|
187
|
+
position: parameter_1.Parameter.parseVector(light.inheritedParameters[parameter_1.Parameter.POSITION] || '(0, 0, 0)'),
|
|
188
|
+
rotation: parameter_1.Parameter.parseRotation(newValue),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}),
|
|
192
|
+
]);
|
|
193
|
+
this._parameterObservers.set(parameter_1.Parameter.DIRECTION, [
|
|
194
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
if ((light.light instanceof shadowLight_1.ShadowLight && !(light.light instanceof pointLight_1.PointLight)) ||
|
|
196
|
+
light.light instanceof hemisphericLight_1.HemisphericLight) {
|
|
197
|
+
(0, lodash_es_1.set)(light.light, 'direction', parameter_1.Parameter.parseVector(newValue));
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
]);
|
|
201
|
+
this._parameterObservers.set(parameter_1.Parameter.ANGLE, [
|
|
202
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
if (light.light.getClassName() === 'SpotLight') {
|
|
204
|
+
(0, lodash_es_1.set)(light.light, 'angle', parameter_1.Parameter.parseNumber(newValue));
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
]);
|
|
208
|
+
this._parameterObservers.set(parameter_1.Parameter.EXPONENT, [
|
|
209
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
if (light.light.getClassName() === 'SpotLight') {
|
|
211
|
+
(0, lodash_es_1.set)(light.light, 'exponent', parameter_1.Parameter.parseNumber(newValue));
|
|
212
|
+
}
|
|
213
|
+
}),
|
|
214
|
+
]);
|
|
215
|
+
this._parameterObservers.set(parameter_1.Parameter.DIFFUSE, [
|
|
216
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
(0, lodash_es_1.set)(light.light, 'diffuse', parameter_1.Parameter.parseColor(newValue));
|
|
218
|
+
}),
|
|
219
|
+
]);
|
|
220
|
+
this._parameterObservers.set(parameter_1.Parameter.SPECULAR, [
|
|
221
|
+
(light, oldValue, newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
(0, lodash_es_1.set)(light.light, 'specular', parameter_1.Parameter.parseColor(newValue));
|
|
223
|
+
}),
|
|
224
|
+
]);
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @param definition
|
|
229
|
+
* @protected
|
|
230
|
+
*/
|
|
231
|
+
createBabylonLightFromDefinition(definition) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const parameters = parameter_1.Parameter.parseFromDeclarations(parameter_1.Parameter.declarations, this.inheritedParameters);
|
|
234
|
+
const scene = this.variant.viewer.scene;
|
|
235
|
+
let lightId = this.id;
|
|
236
|
+
let babylonLight;
|
|
237
|
+
switch (definition.type) {
|
|
238
|
+
case 'baked': {
|
|
239
|
+
if (!definition['path']) {
|
|
240
|
+
throw new Error(`The light "${lightId}" of type "${definition.type}" needs a "path".`);
|
|
241
|
+
}
|
|
242
|
+
const bakedLight = this.variant.inheritedLights.find(l => l.metadata.dottedPath.path === definition['path']);
|
|
243
|
+
if (bakedLight) {
|
|
244
|
+
lightId = bakedLight.metadata.dottedPath.clone().unshiftPart(this.id).path;
|
|
245
|
+
babylonLight = (0, babylonHelper_1.cloneNodeWithParents)(bakedLight);
|
|
246
|
+
babylonLight.name = lightId;
|
|
247
|
+
babylonLight.id = lightId;
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
throw new Error(`No light found for path "${definition['path']}" in ViewerLight "${lightId}".`);
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case 'hemispheric': {
|
|
255
|
+
if (!parameters['direction']) {
|
|
256
|
+
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".`);
|
|
257
|
+
}
|
|
258
|
+
const hemisphericLightModule = yield Promise.resolve().then(() => __importStar(require(
|
|
259
|
+
/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight')));
|
|
260
|
+
babylonLight = new hemisphericLightModule.HemisphericLight(lightId, parameters['direction'], scene);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
case 'point': {
|
|
264
|
+
const pointLightModule = yield Promise.resolve().then(() => __importStar(require(
|
|
265
|
+
/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight')));
|
|
266
|
+
babylonLight = new pointLightModule.PointLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
267
|
+
scene);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case 'directional': {
|
|
271
|
+
if (!parameters['direction']) {
|
|
272
|
+
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".`);
|
|
273
|
+
}
|
|
274
|
+
const directionalLightModule = yield Promise.resolve().then(() => __importStar(require(
|
|
275
|
+
/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight')));
|
|
276
|
+
babylonLight = new directionalLightModule.DirectionalLight(lightId, parameters['direction'], scene);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case 'spot': {
|
|
280
|
+
if (!parameters['direction']) {
|
|
281
|
+
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".`);
|
|
282
|
+
}
|
|
283
|
+
if (!parameters['angle']) {
|
|
284
|
+
throw new Error(`A ViewerLight of type "${definition.type}" needs an "angle".`);
|
|
285
|
+
}
|
|
286
|
+
if (!parameters['exponent']) {
|
|
287
|
+
throw new Error(`The ViewerLight "${lightId}" of type "${definition.type}" needs an "exponent".`);
|
|
288
|
+
}
|
|
289
|
+
const spotLightModule = yield Promise.resolve().then(() => __importStar(require(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight')));
|
|
290
|
+
babylonLight = new spotLightModule.SpotLight(lightId, math_vector_1.Vector3.Zero(), // position is set via parent TransformNode
|
|
291
|
+
parameters['direction'], parameters['angle'], parameters['exponent'], scene);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
default:
|
|
295
|
+
throw new Error(`The type "${definition.type}" for ViewerLight "${lightId}" is not implemented (yet).`);
|
|
296
|
+
}
|
|
297
|
+
if (!babylonLight) {
|
|
298
|
+
throw new Error(`The Light for ViewerLight "${lightId}" of type "${definition.type}" could no be created ` + `or found.`);
|
|
299
|
+
}
|
|
300
|
+
if (!babylonLight.parent) {
|
|
301
|
+
// Create pseudo parent since lights do not implement mutations like "rotation" by itself.
|
|
302
|
+
babylonLight.parent = new transformNode_1.TransformNode('__light__', this.variant.viewer.scene, true);
|
|
303
|
+
}
|
|
304
|
+
(0, babylonHelper_1.injectMetadata)(babylonLight.parent, {
|
|
305
|
+
variant: this.variant,
|
|
306
|
+
variantParameterizable: this,
|
|
307
|
+
});
|
|
308
|
+
// disable/hide by default
|
|
309
|
+
(0, babylonHelper_1.disableNodeWithParents)(babylonLight);
|
|
310
|
+
// process shadow generator
|
|
311
|
+
const shadowGeneratorDefinition = (0, lodash_es_1.get)(definition, 'shadowGenerator');
|
|
312
|
+
if (!(0, lodash_es_1.isEmpty)(shadowGeneratorDefinition)) {
|
|
313
|
+
if (!(babylonLight instanceof shadowLight_1.ShadowLight)) {
|
|
314
|
+
throw new Error(`Using a ShadowGenerator with light type "${definition.type}" is not supported for ` +
|
|
315
|
+
`"${lightId}". Use lights deriving from ShadowLight.`);
|
|
316
|
+
}
|
|
317
|
+
yield this.processShadowGenerator(babylonLight, shadowGeneratorDefinition);
|
|
318
|
+
}
|
|
319
|
+
return babylonLight;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* @param babylonLight
|
|
324
|
+
* @param definition
|
|
325
|
+
* @protected
|
|
326
|
+
*/
|
|
327
|
+
processShadowGenerator(babylonLight, definition) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const parameterDeclarations = {};
|
|
330
|
+
// define declarations here if needed in future
|
|
331
|
+
const parameterBag = definition;
|
|
332
|
+
const parameters = parameter_1.Parameter.parseFromDeclarations(parameterDeclarations, parameterBag);
|
|
333
|
+
const shadowGenerator = new shadowGenerator_1.ShadowGenerator(parameters['mapSize'], babylonLight);
|
|
334
|
+
for (const parameter in parameters) {
|
|
335
|
+
if (parameter === 'mapSize') {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
(0, lodash_es_1.set)(shadowGenerator, parameter, (0, lodash_es_1.get)(parameters, parameter));
|
|
339
|
+
}
|
|
340
|
+
return shadowGenerator;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
exports.ViewerLight = ViewerLight;
|
|
345
345
|
//# sourceMappingURL=viewerLight.js.map
|