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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +112 -111
  2. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  3. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  4. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  5. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  6. package/dist/lib-cjs/api/classes/element.d.ts +125 -130
  7. package/dist/lib-cjs/api/classes/element.js +682 -739
  8. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  9. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  10. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  11. package/dist/lib-cjs/api/classes/event.d.ts +312 -326
  12. package/dist/lib-cjs/api/classes/event.js +357 -371
  13. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  14. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  15. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  16. package/dist/lib-cjs/api/classes/parameter.d.ts +165 -259
  17. package/dist/lib-cjs/api/classes/parameter.js +267 -387
  18. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  20. package/dist/lib-cjs/api/classes/parameterObservable.js +126 -101
  21. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -15
  23. package/dist/lib-cjs/api/classes/parameterizable.js +149 -149
  24. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  25. package/dist/lib-cjs/api/classes/placementAnimation.js +138 -138
  26. package/dist/lib-cjs/api/classes/variant.d.ts +190 -224
  27. package/dist/lib-cjs/api/classes/variant.js +873 -1137
  28. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  29. package/dist/lib-cjs/api/classes/variantInstance.d.ts +41 -45
  30. package/dist/lib-cjs/api/classes/variantInstance.js +98 -108
  31. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  32. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  33. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  34. package/dist/lib-cjs/api/classes/viewer.d.ts +128 -131
  35. package/dist/lib-cjs/api/classes/viewer.js +486 -538
  36. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  37. package/dist/lib-cjs/api/classes/viewerLight.d.ts +65 -66
  38. package/dist/lib-cjs/api/classes/viewerLight.js +322 -389
  39. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  40. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  41. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  42. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  43. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  44. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +6 -10
  45. package/dist/lib-cjs/api/internal/sceneSetup.js +227 -231
  46. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  47. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  48. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  49. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  50. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  51. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  53. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  54. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  55. package/dist/lib-cjs/api/util/babylonHelper.d.ts +125 -175
  56. package/dist/lib-cjs/api/util/babylonHelper.js +368 -520
  57. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  58. package/dist/lib-cjs/api/util/globalTypes.d.ts +279 -321
  59. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  60. package/dist/lib-cjs/api/util/resourceHelper.d.ts +51 -26
  61. package/dist/lib-cjs/api/util/resourceHelper.js +243 -237
  62. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  63. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  64. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  65. package/dist/lib-cjs/buildinfo.json +3 -3
  66. package/dist/lib-cjs/index.d.ts +46 -48
  67. package/dist/lib-cjs/index.js +82 -86
  68. package/dist/lib-cjs/index.js.map +1 -1
  69. package/dist/webpack-stats.json +0 -0
  70. package/package.json +83 -83
  71. package/src/api/classes/animationInterface.ts +11 -11
  72. package/src/api/classes/dottedPath.ts +189 -189
  73. package/src/api/classes/element.ts +617 -635
  74. package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +78 -89
  75. package/src/api/classes/event.ts +355 -370
  76. package/src/api/classes/eventBroadcaster.ts +54 -54
  77. package/src/api/classes/parameter.ts +277 -408
  78. package/src/api/classes/parameterObservable.ts +121 -99
  79. package/src/api/classes/placementAnimation.ts +133 -133
  80. package/src/api/classes/variant.ts +670 -806
  81. package/src/api/classes/variantInstance.ts +81 -88
  82. package/src/api/classes/viewer.ts +421 -473
  83. package/src/api/internal/debugViewer.ts +81 -81
  84. package/src/api/internal/lensRendering.ts +10 -10
  85. package/src/api/internal/sceneSetup.ts +204 -194
  86. package/src/api/manager/animationManager.ts +116 -116
  87. package/src/api/manager/sceneManager.ts +105 -105
  88. package/src/api/manager/variantInstanceManager.ts +236 -236
  89. package/src/api/store/specStorage.ts +53 -53
  90. package/src/api/util/babylonHelper.ts +392 -553
  91. package/src/api/util/globalTypes.ts +318 -369
  92. package/src/api/util/resourceHelper.ts +187 -157
  93. package/src/buildinfo.json +2 -2
  94. package/src/commonjs.tsconfig.json +13 -13
  95. package/src/declaration.tsconfig.json +10 -10
  96. package/src/dev.ts +46 -44
  97. package/src/es6.tsconfig.json +13 -13
  98. package/src/index.ts +87 -91
  99. package/src/pagesconfig.json +57 -52
  100. package/src/tsconfig.json +43 -43
  101. package/src/tsconfig.types.json +9 -9
  102. package/src/types.d.ts +4 -4
  103. package/src/api/classes/variantParameterizable.ts +0 -73
  104. package/src/api/classes/viewerLight.ts +0 -330
  105. package/src/api/util/stringHelper.ts +0 -26
@@ -1,330 +0,0 @@
1
- import { PointLight } from '@babylonjs/core';
2
- import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
3
- import { Light } from '@babylonjs/core/Lights/light';
4
- import { ShadowLight } from '@babylonjs/core/Lights/shadowLight';
5
- import { ShadowGenerator } from '@babylonjs/core/Lights/Shadows/shadowGenerator';
6
- import '@babylonjs/core/Lights/Shadows/shadowGeneratorSceneComponent';
7
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
8
- import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
9
- import '@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual';
10
- import { get, isEmpty, isString, set } from 'lodash-es';
11
- import {
12
- cloneNodeWithParents,
13
- disableNodeWithParents,
14
- enableNodeWithParents,
15
- getRootNode,
16
- injectNodeMetadata,
17
- moveTransformNode,
18
- rotateTransformNode
19
- } from './../util/babylonHelper';
20
- import { DottedPath } from './dottedPath';
21
- import { Parameter } from './parameter';
22
- import { Variant } from './variant';
23
- import { VariantParameterizable } from './variantParameterizable';
24
-
25
- /**
26
- * A {@link ViewerLight} of a {@link Variant}. Acts as a container for BabylonJS lights. Lives only in the context of a
27
- * {@link Variant}.
28
- */
29
- export class ViewerLight extends VariantParameterizable {
30
-
31
- protected _light: Light | undefined;
32
-
33
- /**
34
- * Constructor.
35
- */
36
- protected constructor( public readonly variant: Variant,
37
- public readonly name: string ) {
38
- super( variant, name );
39
- this.addParameterObservers();
40
- }
41
-
42
- /**
43
- * Creates a {@link ViewerLight} with given name.
44
- */
45
- public static async create( variant: Variant, name: string ): Promise<ViewerLight> {
46
- const viewerLight = new ViewerLight( variant, name );
47
- viewerLight._light = await viewerLight.createBabylonLightFromDefinition( viewerLight.definition );
48
- return viewerLight;
49
- }
50
-
51
- /**
52
- * The wrapped Light.
53
- */
54
- get light(): Light {
55
- if( !this._light ) {
56
- throw new Error( `Light for ViewerLight "${this.name}" has not been properly initialized.` );
57
- }
58
- return this._light!;
59
- }
60
-
61
- /**
62
- * The {@link DottedPath} in the built tree of {@link ViewerLight}s.
63
- * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
64
- */
65
- get dottedPath(): DottedPath {
66
- return DottedPath.create( this.variant.dottedPath ).addPart( this.name );
67
- }
68
-
69
- /**
70
- * The id representing a {@link DottedPath}.
71
- */
72
- get id(): string {
73
- const dottedPath = DottedPath.create( this.dottedPath );
74
- dottedPath.shiftPart(); // remove root
75
- return dottedPath.path;
76
- }
77
-
78
- /**
79
- * The {@link LightDefinition} of the {@link ViewerLight}.
80
- */
81
- get definition(): LightDefinition {
82
- const definition = this.variant.structureJson.lights![this.name];
83
- if( isString( definition ) ) {
84
- return {
85
- type: 'baked',
86
- path: definition
87
- } as LightDefinition;
88
- }
89
- return definition as LightDefinition;
90
- }
91
-
92
- /**
93
- * The type of the {@link ViewerLight}'s light.
94
- */
95
- get type(): string {
96
- return this.light.constructor.name.replace( /light/i, '' ).toLowerCase();
97
- }
98
-
99
- /**
100
- * @see {@link VariantParameterizable.commitParameters}
101
- * @emit {@link Event.VIEWER_LIGHT_PARAMETER_COMMITTED}
102
- */
103
- public async commitParameters( parameters?: ParameterBag ): Promise<VariantParameterizable> {
104
- return super.commitParameters( parameters );
105
- }
106
-
107
- /**
108
- * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
109
- */
110
- protected addParameterObservers(): ViewerLight {
111
- this._parameterObservers.set( Parameter.VISIBLE, [
112
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
113
- let visible;
114
- try {
115
- visible = Parameter.parseBoolean( newValue );
116
- } catch( e ) {
117
- return;
118
- }
119
- if( visible === true ) {
120
- enableNodeWithParents( light.light );
121
- } else if( visible === false ) {
122
- disableNodeWithParents( light.light );
123
- }
124
- }
125
- ] );
126
- this._parameterObservers.set( Parameter.INTENSITY, [
127
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
128
- set( light.light, 'intensity', Parameter.parseNumber( newValue ) );
129
- }
130
- ] );
131
- this._parameterObservers.set( Parameter.POSITION, [
132
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
133
- // we have to deal just with root nodes here due to relative impacts in a node tree
134
- const rootNode = getRootNode( light.light );
135
- if( rootNode instanceof TransformNode ) {
136
- moveTransformNode( rootNode, Parameter.parseVector( newValue ) );
137
- }
138
- }
139
- ] );
140
- this._parameterObservers.set( Parameter.ROTATION, [
141
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
142
- // The current implementation (rotating around coordinates 0,0,0) implicitly mutates the position of a node.
143
- // Since a user expects the rotation after the positioning, we have to manually fire the position observers.
144
- // Without calling these observers, the pivot and the position of a node is initially the same before rotating,
145
- // so there is no rotation happening at all.
146
- if( Parameter.POSITION in light.inheritedParameters ) {
147
- await light.commitParameter( Parameter.POSITION, light.inheritedParameters[Parameter.POSITION] );
148
- }
149
- // we have to deal just with root nodes here due to relative impacts in a node tree
150
- const rootNode = getRootNode( light.light );
151
- if( rootNode instanceof TransformNode ) {
152
- rotateTransformNode( rootNode, Parameter.parseRotation( newValue ) );
153
- }
154
- }
155
- ] );
156
- this._parameterObservers.set( Parameter.SCALING, [
157
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
158
- // we have to deal just with root nodes here due to relative impacts in a node tree
159
- const rootNode = getRootNode( light.light );
160
- if( rootNode instanceof TransformNode ) {
161
- rootNode.scaling = Parameter.parseScaling( newValue );
162
- }
163
- }
164
- ] );
165
- this._parameterObservers.set( Parameter.DIRECTION, [
166
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
167
- if(
168
- (light.light instanceof ShadowLight && !(light.light instanceof PointLight))
169
- || light.light instanceof HemisphericLight
170
- ) {
171
- set( light.light, 'direction', Parameter.parseVector( newValue ) );
172
- }
173
- }
174
- ] );
175
- this._parameterObservers.set( Parameter.ANGLE, [
176
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
177
- if( light.light.getClassName() === 'SpotLight' ) {
178
- set( light.light, 'angle', Parameter.parseNumber( newValue ) );
179
- }
180
- }
181
- ] );
182
- this._parameterObservers.set( Parameter.EXPONENT, [
183
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
184
- if( light.light.getClassName() === 'SpotLight' ) {
185
- set( light.light, 'exponent', Parameter.parseNumber( newValue ) );
186
- }
187
- }
188
- ] );
189
- this._parameterObservers.set( Parameter.DIFFUSE, [
190
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
191
- set( light.light, 'diffuse', Parameter.parseColor( newValue ) );
192
- }
193
- ] );
194
- this._parameterObservers.set( Parameter.SPECULAR, [
195
- async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
196
- set( light.light, 'specular', Parameter.parseColor( newValue ) );
197
- }
198
- ] );
199
- return this;
200
- }
201
-
202
- /**
203
- * @param definition
204
- * @protected
205
- */
206
- protected async createBabylonLightFromDefinition( definition: LightDefinition ): Promise<Light> {
207
- const parameters = Parameter.parseFromDeclarations( Parameter.declarations, this.inheritedParameters );
208
- const scene = this.variant.viewer.scene;
209
- let lightId = this.id;
210
- let babylonLight;
211
- switch( definition.type ) {
212
- case 'baked':
213
- if( !definition['path'] ) {
214
- throw new Error( `The light "${lightId}" of type "${definition.type}" needs a "path".` );
215
- }
216
- const bakedLight = this.variant.inheritedLights.find( l => l.metadata.dottedPath.path === definition['path'] );
217
- if( bakedLight ) {
218
- lightId = bakedLight.metadata.dottedPath.clone().unshiftPart( this.id ).path;
219
- babylonLight = cloneNodeWithParents( bakedLight ) as Light;
220
- babylonLight!.name = lightId;
221
- babylonLight!.id = lightId;
222
- } else {
223
- throw new Error( `No light found for path "${definition['path']}" in ViewerLight "${lightId}".` );
224
- }
225
- break;
226
- case 'hemispheric':
227
- if( !parameters['direction'] ) {
228
- throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".` );
229
- }
230
- // @ts-ignore
231
- const hemisphericLightModule = await import(/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight');
232
- babylonLight = new hemisphericLightModule.HemisphericLight(
233
- lightId,
234
- parameters['direction'],
235
- scene
236
- );
237
- break;
238
- case 'point':
239
- // @ts-ignore
240
- const pointLightModule = await import(/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight');
241
- babylonLight = new pointLightModule.PointLight(
242
- lightId,
243
- Vector3.Zero(), // position is set via parent TransformNode
244
- scene
245
- );
246
- break;
247
- case 'directional':
248
- if( !parameters['direction'] ) {
249
- throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".` );
250
- }
251
- // @ts-ignore
252
- const directionalLightModule = await import(/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight');
253
- babylonLight = new directionalLightModule.DirectionalLight(
254
- lightId,
255
- parameters['direction'],
256
- scene
257
- );
258
- break;
259
- case 'spot':
260
- if( !parameters['direction'] ) {
261
- throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".` );
262
- }
263
- if( !parameters['angle'] ) {
264
- throw new Error( `A ViewerLight of type "${definition.type}" needs an "angle".` );
265
- }
266
- if( !parameters['exponent'] ) {
267
- throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs an "exponent".` );
268
- }
269
- // @ts-ignore
270
- const spotLightModule = await import(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight');
271
- babylonLight = new spotLightModule.SpotLight(
272
- lightId,
273
- Vector3.Zero(), // position is set via parent TransformNode
274
- parameters['direction'],
275
- parameters['angle'],
276
- parameters['exponent'],
277
- scene
278
- );
279
- break;
280
- default:
281
- throw new Error( `The type "${definition.type}" for ViewerLight "${lightId}" is not implemented (yet).` );
282
- }
283
- if( !babylonLight ) {
284
- throw new Error( `The Light for ViewerLight "${lightId}" of type "${definition.type}" could no be created ` +
285
- `or found.` );
286
- }
287
- if( !babylonLight.parent ) {
288
- // Create pseudo parent since lights do not implement mutations like "rotation" by itself.
289
- babylonLight.parent = new TransformNode( '__light__', this.variant.viewer.scene, true );
290
- }
291
- injectNodeMetadata( babylonLight.parent, {
292
- variant: this.variant,
293
- variantParameterizable: this
294
- } );
295
- // disable/hide by default
296
- disableNodeWithParents( babylonLight );
297
- // process shadow generator
298
- const shadowGeneratorDefinition = get( definition, 'shadowGenerator' ) as ShadowGeneratorDefinition;
299
- if( !isEmpty( shadowGeneratorDefinition ) ) {
300
- if( !(babylonLight instanceof ShadowLight) ) {
301
- throw new Error( `Using a ShadowGenerator with light type "${definition.type}" is not supported for ` +
302
- `"${lightId}". Use lights deriving from ShadowLight.` );
303
- }
304
- await this.processShadowGenerator( babylonLight, shadowGeneratorDefinition );
305
- }
306
- return babylonLight;
307
- };
308
-
309
- /**
310
- * @param babylonLight
311
- * @param definition
312
- * @protected
313
- */
314
- protected async processShadowGenerator( babylonLight: ShadowLight,
315
- definition: ShadowGeneratorDefinition ): Promise<ShadowGenerator> {
316
- const parameterDeclarations: ParameterDeclarations = {};
317
- // define declarations here if needed in future
318
- const parameterBag = definition as {} as ParameterBag;
319
- const parameters = Parameter.parseFromDeclarations( parameterDeclarations, parameterBag );
320
- const shadowGenerator = new ShadowGenerator( parameters['mapSize'], babylonLight );
321
- for( const parameter in parameters ) {
322
- if( parameter === 'mapSize' ) {
323
- continue;
324
- }
325
- set( shadowGenerator, parameter, get( parameters, parameter ) );
326
- }
327
- return shadowGenerator;
328
- };
329
-
330
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Creates a random uuidv4.
3
- */
4
- const uuidv4 = function() {
5
- // @ts-ignore
6
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace( /[018]/g, c =>
7
- (c ^ crypto.getRandomValues( new Uint8Array( 1 ) )[0] & 15 >> c / 4).toString( 16 )
8
- );
9
- };
10
-
11
- /**
12
- * Converts a string from camel case to snake case.
13
- */
14
- const camelToSnakeCase = function( str: string ): string {
15
- return str
16
- .replace( /([A-Z])/g, " $1" )
17
- .trim()
18
- .split( ' ' )
19
- .join('_')
20
- .toLowerCase();
21
- };
22
-
23
- export {
24
- uuidv4,
25
- camelToSnakeCase,
26
- };