@combeenation/3d-viewer 4.0.0-alpha7 → 4.0.0-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.
Files changed (57) hide show
  1. package/README.md +1 -0
  2. package/dist/lib-cjs/api/classes/element.d.ts +12 -16
  3. package/dist/lib-cjs/api/classes/element.js +125 -180
  4. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  5. package/dist/lib-cjs/api/classes/event.d.ts +1 -15
  6. package/dist/lib-cjs/api/classes/event.js +1 -15
  7. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  8. package/dist/lib-cjs/api/classes/parameter.d.ts +7 -101
  9. package/dist/lib-cjs/api/classes/parameter.js +21 -141
  10. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  11. package/dist/lib-cjs/api/classes/parameterObservable.js +36 -11
  12. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  13. package/dist/lib-cjs/api/classes/variant.d.ts +14 -48
  14. package/dist/lib-cjs/api/classes/variant.js +56 -315
  15. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  16. package/dist/lib-cjs/api/classes/variantInstance.d.ts +1 -5
  17. package/dist/lib-cjs/api/classes/variantInstance.js +0 -10
  18. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/viewer.d.ts +1 -0
  20. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  21. package/dist/lib-cjs/api/classes/viewerLight.js +27 -19
  22. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  23. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +1 -5
  24. package/dist/lib-cjs/api/internal/sceneSetup.js +71 -75
  25. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  26. package/dist/lib-cjs/api/util/babylonHelper.d.ts +4 -51
  27. package/dist/lib-cjs/api/util/babylonHelper.js +8 -141
  28. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  29. package/dist/lib-cjs/api/util/globalTypes.d.ts +11 -53
  30. package/dist/lib-cjs/api/util/resourceHelper.d.ts +8 -4
  31. package/dist/lib-cjs/api/util/resourceHelper.js +25 -59
  32. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  33. package/dist/lib-cjs/index.d.ts +22 -24
  34. package/dist/lib-cjs/index.js +38 -42
  35. package/dist/lib-cjs/index.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/api/classes/element.ts +112 -133
  38. package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +1 -12
  39. package/src/api/classes/event.ts +1 -16
  40. package/src/api/classes/parameter.ts +22 -153
  41. package/src/api/classes/parameterObservable.ts +31 -9
  42. package/src/api/classes/variant.ts +51 -184
  43. package/src/api/classes/variantInstance.ts +1 -8
  44. package/src/api/classes/viewer.ts +1 -0
  45. package/src/api/internal/sceneSetup.ts +109 -99
  46. package/src/api/util/babylonHelper.ts +9 -153
  47. package/src/api/util/globalTypes.ts +13 -64
  48. package/src/api/util/resourceHelper.ts +24 -26
  49. package/src/dev.ts +7 -5
  50. package/src/index.ts +23 -27
  51. package/src/pagesconfig.json +13 -8
  52. package/dist/lib-cjs/api/emitter.d.ts +0 -35
  53. package/dist/lib-cjs/api/emitter.js +0 -61
  54. package/dist/lib-cjs/api/emitter.js.map +0 -1
  55. package/src/api/classes/variantParameterizable.ts +0 -73
  56. package/src/api/classes/viewerLight.ts +0 -326
  57. package/src/api/util/stringHelper.ts +0 -26
@@ -1,6 +1,6 @@
1
1
  import { Color3 } from '@babylonjs/core/Maths/math.color';
2
2
  import { Vector3 } from '@babylonjs/core/Maths/math.vector';
3
- import { get, isEmpty, isNumber, isString } from 'lodash-es';
3
+ import { isNumber, isString } from 'lodash-es';
4
4
 
5
5
 
6
6
  /**
@@ -16,20 +16,19 @@ export class Parameter {
16
16
  private constructor() {}
17
17
 
18
18
  /**
19
- * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
20
- * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
19
+ * Mutates the visibility. Helper methods are {@link ElementParameterizable.show} and
20
+ * {@link ElementParameterizable.hide}. Getter and setter is {@link ElementParameterizable.visible}.
21
21
  *
22
22
  * Scopes:
23
23
  * * {@link Element}
24
24
  * * {@link Variant}
25
- * * {@link ViewerLight} Available for all light types
26
25
  *
27
26
  * @parser {@link parseBoolean}
28
27
  */
29
28
  public static readonly VISIBLE = 'visible';
30
29
 
31
30
  /**
32
- * Stretches or compresses some meshes. Getter and setter is {@link VariantParameterizable.scaling}.
31
+ * Stretches or compresses some meshes. Getter and setter is {@link ElementParameterizable.scaling}.
33
32
  *
34
33
  * Scopes:
35
34
  * * {@link Element}
@@ -40,7 +39,7 @@ export class Parameter {
40
39
  public static readonly SCALING = 'scaling';
41
40
 
42
41
  /**
43
- * Mutates the material. Getter and setter is {@link VariantParameterizable.material}. The value of this parameter
42
+ * Mutates the material. Getter and setter is {@link ElementParameterizable.material}. The value of this parameter
44
43
  * represents the ID of a baked-in glTF or custom created material in the {@link Variant} tree.
45
44
  *
46
45
  * Scopes:
@@ -107,7 +106,7 @@ export class Parameter {
107
106
  public static readonly HIGHLIGHT_COLOR = 'highlight.color';
108
107
 
109
108
  /**
110
- * Mutates the highlighted state. Getter and setter is {@link VariantParameterizable.highlighted}.
109
+ * Mutates the highlighted state. Getter and setter is {@link ElementParameterizable.highlighted}.
111
110
  *
112
111
  * Scopes:
113
112
  * * {@link Element}
@@ -118,19 +117,18 @@ export class Parameter {
118
117
  public static readonly HIGHLIGHTED = 'highlighted';
119
118
 
120
119
  /**
121
- * Mutates the position relative to its origin position. Getter and setter is {@link VariantParameterizable.position}.
120
+ * Mutates the position relative to its origin position. Getter and setter is {@link ElementParameterizable.position}.
122
121
  *
123
122
  * Scopes:
124
123
  * * {@link Element}
125
124
  * * {@link Variant}
126
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#position), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#position), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#position)
127
125
  *
128
126
  * @parser {@link parseVector}
129
127
  */
130
128
  public static readonly POSITION = 'position';
131
129
 
132
130
  /**
133
- * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
131
+ * Mutates the rotation relative to its origin rotation. Getter and setter is {@link ElementParameterizable.rotation}.
134
132
  *
135
133
  * Scopes:
136
134
  * * {@link Element}
@@ -140,126 +138,24 @@ export class Parameter {
140
138
  */
141
139
  public static readonly ROTATION = 'rotation';
142
140
 
143
- /**
144
- * Mutates whether a shadow should be casted or not.
145
- *
146
- * Scopes:
147
- * * {@link Element}
148
- * * {@link Variant}
149
- *
150
- * @parser {@link parseBoolean}
151
- */
152
- public static readonly CAST_SHADOW = 'castShadow';
153
-
154
- /**
155
- * Mutates from which lights a shadow should be casted.
156
- *
157
- * Scopes:
158
- * * {@link Element}
159
- * * {@link Variant}
160
- *
161
- * @parser {@link parseCommaSeparatedList}
162
- */
163
- public static readonly CAST_SHADOW_FROM_LIGHTS = 'castShadow.fromLights';
164
-
165
- /**
166
- * Mutates whether to receive shadows or not.
167
- *
168
- * Scopes:
169
- * * {@link Element}
170
- * * {@link Variant}
171
- *
172
- * @parser {@link parseBoolean}
173
- */
174
- public static readonly RECEIVE_SHADOWS = 'receiveShadows';
175
-
176
- /**
177
- * Mutates the intensity of Lights.
178
- *
179
- * Scopes:
180
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#intensity), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#intensity), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#intensity), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#intensity)
181
- *
182
- * @parser {@link parseNumber}
183
- */
184
- public static readonly INTENSITY = 'intensity';
185
-
186
- /**
187
- * Mutates the direction of Lights.
188
- *
189
- * Scopes:
190
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#direction), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#direction), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#direction), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#direction)
191
- *
192
- * @parser {@link parseNumber}
193
- */
194
- public static readonly DIRECTION = 'direction';
195
-
196
- /**
197
- * Mutates the angle of Lights.
198
- *
199
- * Scopes:
200
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#angle)
201
- *
202
- * @parser {@link parseNumber}
203
- */
204
- public static readonly ANGLE = 'angle';
205
-
206
- /**
207
- * Mutates the exponent of Lights.
208
- *
209
- * Scopes:
210
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#exponent)
211
- *
212
- * @parser {@link parseNumber}
213
- */
214
- public static readonly EXPONENT = 'exponent';
215
-
216
- /**
217
- * Mutates the diffuse color of Lights.
218
- *
219
- * Scopes:
220
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#diffuse), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#diffuse), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#diffuse), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#diffuse)
221
- *
222
- * @parser {@link parseNumber}
223
- */
224
- public static readonly DIFFUSE = 'diffuse';
225
-
226
- /**
227
- * Mutates the specular color of Lights.
228
- *
229
- * Scopes:
230
- * * {@link ViewerLight} Available for [PointLight](https://doc.babylonjs.com/typedoc/classes/babylon.pointlight#specular), [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#specular), [DirectionalLight](https://doc.babylonjs.com/typedoc/classes/babylon.directionallight#specular), [HemisphericLight](https://doc.babylonjs.com/typedoc/classes/babylon.hemisphericlight#specular)
231
- *
232
- * @parser {@link parseNumber}
233
- */
234
- public static readonly SPECULAR = 'specular';
235
-
236
141
  /**
237
142
  * The {@link ParameterDeclarations} for all parameters in this class.
238
143
  */
239
144
  public static get declarations(): ParameterDeclarations {
240
- const declarations: ParameterDeclarations = {};
241
- declarations[Parameter.VISIBLE] = { type: 'boolean', parser: Parameter.parseBoolean };
242
- declarations[Parameter.SCALING] = { type: 'number', parser: Parameter.parseNumber };
243
- declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
244
- declarations[Parameter.MATERIAL] = { type: 'string' };
245
- declarations[Parameter.MATERIAL_COLOR] = { type: 'color', parser: Parameter.parseColor };
246
- declarations[Parameter.MATERIAL_METALLNESS] = { type: 'number', parser: Parameter.parseNumber };
247
- declarations[Parameter.MATERIAL_ROUGHNESS] = { type: 'number', parser: Parameter.parseNumber };
248
- declarations[Parameter.HIGHLIGHT_ENABLED] = { type: 'boolean', parser: Parameter.parseBoolean };
249
- declarations[Parameter.HIGHLIGHT_COLOR] = { type: 'color', parser: Parameter.parseColor };
250
- declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
251
- declarations[Parameter.POSITION] = { type: 'vector', parser: Parameter.parseVector };
252
- declarations[Parameter.ROTATION] = { type: 'vector', parser: Parameter.parseVector };
253
- declarations[Parameter.CAST_SHADOW] = { type: 'boolean', parser: Parameter.parseBoolean };
254
- declarations[Parameter.CAST_SHADOW_FROM_LIGHTS] = { type: 'csl', parser: Parameter.parseCommaSeparatedList };
255
- declarations[Parameter.RECEIVE_SHADOWS] = { type: 'boolean', parser: Parameter.parseBoolean };
256
- declarations[Parameter.INTENSITY] = { type: 'number', parser: Parameter.parseNumber };
257
- declarations[Parameter.DIRECTION] = { type: 'vector', parser: Parameter.parseVector };
258
- declarations[Parameter.ANGLE] = { type: 'number', parser: Parameter.parseNumber };
259
- declarations[Parameter.EXPONENT] = { type: 'number', parser: Parameter.parseNumber };
260
- declarations[Parameter.DIFFUSE] = { type: 'color', parser: Parameter.parseColor };
261
- declarations[Parameter.SPECULAR] = { type: 'color', parser: Parameter.parseColor };
262
- return declarations;
145
+ const declaration: ParameterDeclarations = {};
146
+ declaration[Parameter.VISIBLE] = { type: 'boolean' };
147
+ declaration[Parameter.SCALING] = { type: 'number' };
148
+ declaration[Parameter.HIGHLIGHTED] = { type: 'boolean' };
149
+ declaration[Parameter.MATERIAL] = { type: 'string' };
150
+ declaration[Parameter.MATERIAL_COLOR] = { type: 'color' };
151
+ declaration[Parameter.MATERIAL_METALLNESS] = { type: 'number' };
152
+ declaration[Parameter.MATERIAL_ROUGHNESS] = { type: 'number' };
153
+ declaration[Parameter.HIGHLIGHT_ENABLED] = { type: 'boolean' };
154
+ declaration[Parameter.HIGHLIGHT_COLOR] = { type: 'color' };
155
+ declaration[Parameter.HIGHLIGHTED] = { type: 'boolean' };
156
+ declaration[Parameter.POSITION] = { type: 'vector' };
157
+ declaration[Parameter.ROTATION] = { type: 'vector' };
158
+ return declaration;
263
159
  }
264
160
 
265
161
  /**
@@ -283,24 +179,6 @@ export class Parameter {
283
179
  return all;
284
180
  }
285
181
 
286
- /**
287
- * Parses given {@link ParameterBag} with given {@link ParameterDeclarations}.
288
- */
289
- public static parseFromDeclarations( declarations: ParameterDeclarations, parameterBag: ParameterBag ): ParsedParameterBag {
290
- const parameters: ParsedParameterBag = {};
291
- for( const parameter in parameterBag ) {
292
- const value = get( parameterBag, parameter );
293
- parameters[parameter] = value;
294
- const declaration: ParameterDeclaration = declarations[parameter];
295
- if( declaration ) {
296
- if( !isEmpty( value ) && declaration.parser ) {
297
- parameters[parameter] = declaration.parser( value );
298
- }
299
- }
300
- }
301
- return parameters;
302
- }
303
-
304
182
  /**
305
183
  * Parses a string of format `'(x,y,z)'` to a `Vector3`.
306
184
  */
@@ -396,13 +274,4 @@ export class Parameter {
396
274
  return parseFloat( value.toString() );
397
275
  }
398
276
 
399
- /**
400
- * Parses a string with comma separated values to a list of strings.
401
- */
402
- public static parseCommaSeparatedList( value: ParameterValue ): string[] {
403
- return value.toString()
404
- .split( ',' )
405
- .map( s => s.trim() );
406
- }
407
-
408
277
  }
@@ -1,5 +1,6 @@
1
1
  import { merge } from 'lodash-es';
2
- import { uuidv4 } from '../util/stringHelper';
2
+ import { Parameter } from '../classes/parameter';
3
+ import { uuidv4 } from '../util/resourceHelper';
3
4
  import { EventBroadcaster } from './eventBroadcaster';
4
5
 
5
6
  export abstract class ParameterObservable extends EventBroadcaster {
@@ -74,16 +75,37 @@ export abstract class ParameterObservable extends EventBroadcaster {
74
75
  return;
75
76
  }
76
77
  const declaration = parameterDeclaration[parameter];
77
- const genericError = `"${value}" is not a valid value for parameter "${parameter}" of type. ` +
78
+ const genericError = `"${value}" is not a valid value for parameter "${parameter}" of type ` +
78
79
  `"${declaration.type}" for ${this.constructor.name} "${this.id}".`;
79
- if( declaration.parser ) {
80
- try {
81
- declaration.parser( value );
82
- } catch( e ) {
83
- throw Error( genericError + e.message );
84
- }
85
- }
86
80
  switch( declaration.type ) {
81
+ case 'boolean':
82
+ try {
83
+ Parameter.parseBoolean( value );
84
+ } catch( e ) {
85
+ throw Error( genericError );
86
+ }
87
+ break;
88
+ case 'number':
89
+ try {
90
+ Parameter.parseNumber( value );
91
+ } catch( e ) {
92
+ throw Error( genericError );
93
+ }
94
+ break;
95
+ case 'color':
96
+ try {
97
+ Parameter.parseColor( value );
98
+ } catch( e ) {
99
+ throw Error( genericError + ` It must be hex with leading "#" or of format "(r,g,b)".` );
100
+ }
101
+ break;
102
+ case 'vector':
103
+ try {
104
+ Parameter.parseVector( value );
105
+ } catch( e ) {
106
+ throw Error( genericError + ` It must be of format "(x,y,z)".` );
107
+ }
108
+ break;
87
109
  case 'select':
88
110
  if( !declaration.options ) {
89
111
  throw Error( `No options defined for parameter declaration "${parameter}"` +
@@ -1,5 +1,4 @@
1
1
  import { AssetContainer } from '@babylonjs/core/assetContainer';
2
- import { Light } from '@babylonjs/core/Lights/light';
3
2
  import '@babylonjs/core/Loading/Plugins/babylonFileLoader';
4
3
  import { SceneLoader } from '@babylonjs/core/Loading/sceneLoader';
5
4
  import { Material } from '@babylonjs/core/Materials/material';
@@ -8,30 +7,40 @@ import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
8
7
  import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_draco_mesh_compression';
9
8
  import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_transform';
10
9
  import '@babylonjs/loaders/glTF/2.0/glTFLoader';
11
- import { cloneDeep, concat, get, isEmpty, isEqual, isString, merge, set } from 'lodash-es';
12
- import { deactivateTransformNode, getDottedPathForNode, injectNodeMetadata } from '../util/babylonHelper';
10
+ import { cloneDeep, concat, isEmpty, isEqual, isString, merge } from 'lodash-es';
11
+ import {
12
+ deactivateTransformNode,
13
+ getDottedPathForTransformNode,
14
+ injectTransformNodeMetadata
15
+ } from '../util/babylonHelper';
13
16
  import { loadJson, mergeMaps } from '../util/resourceHelper';
14
17
  import { DottedPath } from './dottedPath';
15
18
  import { Element } from './element';
19
+ import { ElementParameterizable } from './elementParameterizable';
16
20
  import { Event } from './event';
17
21
  import { Parameter } from './parameter';
18
- import { Parameterizable } from './parameterizable';
19
- import { ParameterObservable } from './parameterObservable';
20
- import { VariantParameterizable } from './variantParameterizable';
21
22
  import { Viewer } from './viewer';
22
- import { ViewerLight } from './viewerLight';
23
+
24
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_texture_basisu';
25
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_clearcoat';
26
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_sheen';
27
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_ior';
28
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness';
29
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_specular';
30
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_translucency';
31
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_transmission';
32
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_unlit';
33
+ import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_materials_variants';
23
34
 
24
35
  /**
25
36
  * A concrete "Variant". Most of these are handled by either the {@link Viewer} or {@link VariantInstance}.
26
37
  */
27
- export class Variant extends Parameterizable {
38
+ export class Variant extends ElementParameterizable {
28
39
 
29
40
  public assetContainer: AssetContainer;
30
41
 
31
42
  public readonly elements: Element[] = [];
32
43
 
33
- public readonly viewerLights: ViewerLight[] = [];
34
-
35
44
  public structureJson: StructureJson;
36
45
 
37
46
  protected _dottedNodes: Map<DottedPath, TransformNode> | undefined;
@@ -166,13 +175,6 @@ export class Variant extends Parameterizable {
166
175
  return rootNodes;
167
176
  }
168
177
 
169
- /**
170
- * The {@link ViewerLight}s of the {@link Variant}.
171
- */
172
- get lights(): Light[] {
173
- return this.assetContainer.lights;
174
- }
175
-
176
178
  /**
177
179
  * All TransformNodes of the {@link Variant} mapped flat with a {@link DottedPath}.
178
180
  */
@@ -206,17 +208,6 @@ export class Variant extends Parameterizable {
206
208
  return concat( elements, this.elements );
207
209
  }
208
210
 
209
- /**
210
- * All {@link ViewerLight}s inherited from this {@link Variant}'s parents.
211
- */
212
- get inheritedViewerLights(): ViewerLight[] {
213
- let viewerLights: ViewerLight[] = [];
214
- this.ancestors.forEach( ancestor => {
215
- viewerLights = concat( viewerLights, ancestor.viewerLights );
216
- } );
217
- return concat( viewerLights, this.viewerLights );
218
- }
219
-
220
211
  /**
221
212
  * All TransformNodes inherited from this {@link Variant}'s parents.
222
213
  */
@@ -239,17 +230,6 @@ export class Variant extends Parameterizable {
239
230
  return dottedNodes;
240
231
  }
241
232
 
242
- /**
243
- * All Lights inherited from this {@link Variant}'s parents.
244
- */
245
- get inheritedLights(): Light[] {
246
- let lights: Light[] = [];
247
- this.ancestors.forEach( ancestor => {
248
- lights = concat( lights, ancestor.lights );
249
- } );
250
- return concat( lights, this.lights );
251
- }
252
-
253
233
  /**
254
234
  * The {@link ParameterDeclarations} inherited from this {@link Variant}'s parents.
255
235
  */
@@ -357,33 +337,6 @@ export class Variant extends Parameterizable {
357
337
  return element;
358
338
  }
359
339
 
360
- /**
361
- * Gets the desired {@link ViewerLight} of the current {@link Variant} relative to its {@link DottedPath}.
362
- * Uses the mechanism of {@link getDescendant} to resolve the appropriate variant in tree.
363
- */
364
- public async getViewerLight( dottedPath: DottedPathArgument ): Promise<ViewerLight> {
365
- const _dottedPath = DottedPath.create( dottedPath );
366
- const viewerLightName = _dottedPath.popPart();
367
- let variant: Variant = this;
368
- if( _dottedPath.parts.length > 0 ) {
369
- variant = await this.getDescendant( _dottedPath );
370
- }
371
- if( variant.inheritedViewerLights.length === 0 ) {
372
- throw new Error( `No viewerLights for variant "${variant.id}" found. ` +
373
- `Either none are defined or they are not initialized (are you operating on the appropriate living?).` );
374
- }
375
- let viewerLight;
376
- variant.inheritedViewerLights.forEach( _viewerLight => {
377
- if( _viewerLight.name === viewerLightName ) {
378
- viewerLight = _viewerLight;
379
- }
380
- } );
381
- if( !viewerLight ) {
382
- throw new Error( `ViewerLight with name "${viewerLightName}" does not exist for variant "${variant.id}".` );
383
- }
384
- return viewerLight;
385
- }
386
-
387
340
  /**
388
341
  * A proxy for directly getting a Node from an {@link Element} by its {@link DottedPath}s.
389
342
  */
@@ -430,8 +383,7 @@ export class Variant extends Parameterizable {
430
383
  parent?._children.set( variant.name, variant );
431
384
  variant.assetContainer = this.assetContainer;
432
385
  variant.parameterObservers = cloneDeep( this.parameterObservers );
433
- await variant.createElements();
434
- await variant.createViewerLights();
386
+ variant.createElements();
435
387
  variant.addParameterObservers();
436
388
  await variant.bootstrapParameters( parameters );
437
389
  this.broadcastEvent( Event.VARIANT_CREATED, variant );
@@ -537,10 +489,31 @@ export class Variant extends Parameterizable {
537
489
  this.broadcastEvent(Event.VARIANT_PARAMETER_BAG_COMMITTED, this, oldParameters, newParameters);
538
490
 
539
491
  // commit parameters to elements
540
- await this.commitParametersToElements( newParameters );
541
-
542
- // commit parameters to lights
543
- await this.commitParametersToViewerLights( newParameters );
492
+ const elementPromises: Promise<Element>[] = this.elements.map( element => {
493
+ let _elementDefinition = JSON.stringify( this._structureJson.elements![element.name] );
494
+ const elementParameters: ParameterBag = {};
495
+ for( const parameter in newParameters ) {
496
+ if( DottedPath.create( parameter ).firstPart !== element.name ) {
497
+ continue;
498
+ }
499
+ // we got an element parameter
500
+ let newParameterValue = newParameters[parameter];
501
+ const elementParameter = parameter.replace( `${element.name}.`, '' );
502
+ // If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
503
+ // an exception for visibility to avoid overloading already applied element parameters with element parameters
504
+ // defined in the variant spec ("dotted parameters").
505
+ // @see https://github.com/Combeenation/3d-viewer/issues/44
506
+ if( elementParameter === Parameter.VISIBLE && newParameters[Parameter.VISIBLE] === false ) {
507
+ newParameterValue = false;
508
+ }
509
+ elementParameters[elementParameter] = newParameterValue;
510
+ const search = new RegExp( `\\$\\{${elementParameter}\\}`, 'g' );
511
+ _elementDefinition = _elementDefinition.replace( search, newParameterValue.toString() );
512
+ }
513
+ this.structureJson.elements![this.name] = JSON.parse( _elementDefinition );
514
+ return element.commitParameters( elementParameters );
515
+ } );
516
+ await Promise.all( elementPromises );
544
517
 
545
518
  // propagate parameters to parent
546
519
  if( this.parent ) {
@@ -589,17 +562,7 @@ export class Variant extends Parameterizable {
589
562
  const nodes = this.assetContainer.getNodes().filter( n => n instanceof TransformNode ) as TransformNode[];
590
563
  nodes.forEach( node => {
591
564
  deactivateTransformNode( node, false );
592
- injectNodeMetadata( node, { dottedPath: getDottedPathForNode( node ) }, false );
593
- } );
594
- this.assetContainer.lights.forEach( light => {
595
- light.setEnabled( false );
596
- injectNodeMetadata( light, { dottedPath: getDottedPathForNode( light ) }, false );
597
- this.viewer.scene.addLight( light );
598
- } );
599
- this.assetContainer.cameras.forEach( camera => {
600
- camera.setEnabled( false );
601
- injectNodeMetadata( camera, { dottedPath: getDottedPathForNode( camera ) }, false );
602
- this.viewer.scene.addCamera( camera );
565
+ injectTransformNodeMetadata( node, { dottedPath: getDottedPathForTransformNode( node ) }, false );
603
566
  } );
604
567
  this.broadcastEvent( Event.ASSET_LOADING_END, this );
605
568
  resolve( this );
@@ -610,82 +573,15 @@ export class Variant extends Parameterizable {
610
573
  } );
611
574
  }
612
575
 
613
- /**
614
- * Commits given parameters to all {@link Element}s.
615
- */
616
- protected async commitParametersToElements( parameters: ParameterBag ) {
617
- await Promise.all( this.elements.map(
618
- element => this.commitParametersToVariantParameterizable(parameters, element, 'elements')
619
- ) );
620
- }
621
-
622
- /**
623
- * Commits given parameters to all {@link ViewerLight}s.
624
- */
625
- protected async commitParametersToViewerLights( parameters: ParameterBag ) {
626
- await Promise.all( this.viewerLights.map(
627
- viewerLight => this.commitParametersToVariantParameterizable(parameters, viewerLight, 'lights')
628
- ) );
629
- }
630
-
631
- /**
632
- * Commits given parameters to a {@link VariantParameterizable} and updates the according definition with given
633
- * key in the {@link StructureJson}. The `definitionKey` "elements" for example will update the definition in
634
- * `this.structureJson.elements`.
635
- */
636
- protected async commitParametersToVariantParameterizable( parameters: ParameterBag,
637
- parameterizable: VariantParameterizable,
638
- definitionKey: string ): Promise<ParameterObservable> {
639
- const initialDefinition = get( this._structureJson, definitionKey )[parameterizable.name];
640
- let initialDefinitionStr = JSON.stringify( initialDefinition );
641
- const _parameters: ParameterBag = {};
642
- for( const parameter in parameters ) {
643
- const dpp = DottedPath.create( parameter );
644
- if( dpp.shiftPart() !== parameterizable.name ) {
645
- continue;
646
- }
647
- // we got a parameterizable ("element") parameter
648
- let parameterValue = parameters[parameter];
649
- const parameterizableParameter = dpp.path;
650
- // If the variant is explicitly hidden, we must not override the visibility with element parameters. We need
651
- // an exception for visibility to avoid overloading already applied element parameters with element parameters
652
- // defined in the variant spec ("dotted parameters").
653
- // @see https://github.com/Combeenation/3d-viewer/issues/44
654
- if( parameterizableParameter === Parameter.VISIBLE && parameters[Parameter.VISIBLE] === false ) {
655
- parameterValue = false;
656
- }
657
- _parameters[parameterizableParameter] = parameterValue;
658
- const search = new RegExp( `\\$\\{${parameterizableParameter}\\}`, 'g' );
659
- initialDefinitionStr = initialDefinitionStr.replace( search, parameterValue.toString() );
660
- }
661
- const definition = get( this.structureJson, definitionKey );
662
- definition[this.name] = JSON.parse( initialDefinitionStr );
663
- set( this.structureJson, definitionKey, definition );
664
- return await parameterizable.commitParameters( _parameters );
665
- }
666
-
667
576
  /**
668
577
  * Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
669
578
  */
670
- protected async commitParameterToElements( parameter: string, value: ParameterValue ): Promise<Variant> {
579
+ protected async commitParameterToElements( parameter: string, value: ParameterValue ) {
671
580
  const promises = [];
672
581
  for( const element of this.elements ) {
673
582
  promises.push( element.commitParameter( parameter, value ) );
674
583
  }
675
584
  await Promise.all( promises );
676
- return this;
677
- }
678
-
679
- /**
680
- * Commits given {@link Parameter} to the {@link Variant}'s {@link Element}s.
681
- */
682
- protected async commitParameterToViewerLights( parameter: string, value: ParameterValue ): Promise<Variant> {
683
- const promises = [];
684
- for( const viewerLight of this.viewerLights ) {
685
- promises.push( viewerLight.commitParameter( parameter, value ) );
686
- }
687
- await Promise.all( promises );
688
- return this;
689
585
  }
690
586
 
691
587
  /**
@@ -695,13 +591,11 @@ export class Variant extends Parameterizable {
695
591
  this._parameterObservers.set( Parameter.VISIBLE, [
696
592
  async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
697
593
  await variant.commitParameterToElements( Parameter.VISIBLE, newValue );
698
- await variant.commitParameterToViewerLights( Parameter.VISIBLE, newValue );
699
594
  }
700
595
  ] );
701
596
  this._parameterObservers.set( Parameter.SCALING, [
702
597
  async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
703
598
  await variant.commitParameterToElements( Parameter.SCALING, newValue );
704
- await variant.commitParameterToViewerLights( Parameter.SCALING, newValue );
705
599
  }
706
600
  ] );
707
601
  this._parameterObservers.set( Parameter.MATERIAL, [
@@ -737,28 +631,11 @@ export class Variant extends Parameterizable {
737
631
  this._parameterObservers.set( Parameter.POSITION, [
738
632
  async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
739
633
  await variant.commitParameterToElements( Parameter.POSITION, newValue );
740
- await variant.commitParameterToViewerLights( Parameter.POSITION, newValue );
741
634
  }
742
635
  ] );
743
636
  this._parameterObservers.set( Parameter.ROTATION, [
744
637
  async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
745
638
  await variant.commitParameterToElements( Parameter.ROTATION, newValue );
746
- await variant.commitParameterToViewerLights( Parameter.ROTATION, newValue );
747
- }
748
- ] );
749
- this._parameterObservers.set( Parameter.CAST_SHADOW, [
750
- async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
751
- await variant.commitParameterToElements( Parameter.CAST_SHADOW, newValue );
752
- }
753
- ] );
754
- this._parameterObservers.set( Parameter.CAST_SHADOW_FROM_LIGHTS, [
755
- async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
756
- await variant.commitParameterToElements( Parameter.CAST_SHADOW_FROM_LIGHTS, newValue );
757
- }
758
- ] );
759
- this._parameterObservers.set( Parameter.RECEIVE_SHADOWS, [
760
- async ( variant: Variant, oldValue: ParameterValue, newValue: ParameterValue ) => {
761
- await variant.commitParameterToElements( Parameter.RECEIVE_SHADOWS, newValue );
762
639
  }
763
640
  ] );
764
641
  return this;
@@ -767,30 +644,20 @@ export class Variant extends Parameterizable {
767
644
  /**
768
645
  * Creates {@link Element}s and clones nodes into them.
769
646
  */
770
- protected async createElements(): Promise<Variant> {
771
- for( const name in this.structureJson.elements || {} ) {
772
- this.elements.push( await Element.create( this, name ) );
647
+ protected createElements(): Variant {
648
+ for( const elementName in this.structureJson.elements || {} ) {
649
+ this.elements.push( new Element( this, elementName ) );
773
650
  }
774
651
  // inject node meta to all inherited elements
775
652
  // we do this to inject the deepest and most concrete variant information to all cloned nodes in the tree
776
653
  this.inheritedElements.forEach( element => {
777
654
  element.nodes.forEach( node => {
778
- injectNodeMetadata( node, { variant: this, element: element } );
655
+ injectTransformNodeMetadata( node, { variant: this, element: element } );
779
656
  } );
780
657
  } );
781
658
  return this;
782
659
  }
783
660
 
784
- /**
785
- * Creates {@link ViewerLight}s.
786
- */
787
- protected async createViewerLights(): Promise<Variant> {
788
- for( const name in this.structureJson.lights || {} ) {
789
- this.viewerLights.push( await ViewerLight.create( this, name ) );
790
- }
791
- return this;
792
- }
793
-
794
661
  /**
795
662
  * Bootstrapping for parameters. It sets the `parametersInitialized` to true for all ancestors.
796
663
  */