@combeenation/3d-viewer 4.0.0-beta1 → 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.
- package/README.md +1 -0
- package/dist/lib-cjs/api/classes/element.d.ts +12 -16
- package/dist/lib-cjs/api/classes/element.js +129 -194
- package/dist/lib-cjs/api/classes/element.js.map +1 -1
- package/dist/lib-cjs/api/classes/event.d.ts +1 -15
- package/dist/lib-cjs/api/classes/event.js +1 -15
- package/dist/lib-cjs/api/classes/event.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameter.d.ts +7 -101
- package/dist/lib-cjs/api/classes/parameter.js +21 -141
- package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
- package/dist/lib-cjs/api/classes/parameterObservable.js +36 -11
- package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
- package/dist/lib-cjs/api/classes/placementAnimation.d.ts +2 -2
- package/dist/lib-cjs/api/classes/placementAnimation.js +0 -11
- package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
- package/dist/lib-cjs/api/classes/variant.d.ts +14 -48
- package/dist/lib-cjs/api/classes/variant.js +56 -320
- package/dist/lib-cjs/api/classes/variant.js.map +1 -1
- package/dist/lib-cjs/api/classes/variantInstance.d.ts +1 -5
- package/dist/lib-cjs/api/classes/variantInstance.js +0 -10
- package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
- package/dist/lib-cjs/api/classes/viewer.d.ts +3 -6
- package/dist/lib-cjs/api/classes/viewer.js +59 -133
- package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
- package/dist/lib-cjs/api/internal/sceneSetup.d.ts +1 -5
- package/dist/lib-cjs/api/internal/sceneSetup.js +71 -75
- package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
- package/dist/lib-cjs/api/util/babylonHelper.d.ts +4 -54
- package/dist/lib-cjs/api/util/babylonHelper.js +8 -160
- package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
- package/dist/lib-cjs/api/util/globalTypes.d.ts +12 -62
- package/dist/lib-cjs/api/util/resourceHelper.d.ts +8 -8
- package/dist/lib-cjs/api/util/resourceHelper.js +24 -63
- package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
- package/dist/lib-cjs/index.d.ts +22 -24
- package/dist/lib-cjs/index.js +38 -42
- package/dist/lib-cjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/classes/element.ts +117 -146
- package/src/api/classes/{parameterizable.ts → elementParameterizable.ts} +1 -12
- package/src/api/classes/event.ts +1 -16
- package/src/api/classes/parameter.ts +22 -153
- package/src/api/classes/parameterObservable.ts +31 -9
- package/src/api/classes/placementAnimation.ts +0 -10
- package/src/api/classes/variant.ts +51 -187
- package/src/api/classes/variantInstance.ts +1 -8
- package/src/api/classes/viewer.ts +11 -68
- package/src/api/internal/sceneSetup.ts +109 -99
- package/src/api/util/babylonHelper.ts +10 -171
- package/src/api/util/globalTypes.ts +14 -71
- package/src/api/util/resourceHelper.ts +23 -31
- package/src/dev.ts +6 -2
- package/src/index.ts +23 -27
- package/src/pagesconfig.json +13 -8
- package/src/api/classes/variantParameterizable.ts +0 -73
- package/src/api/classes/viewerLight.ts +0 -330
- 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 {
|
|
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
|
|
20
|
-
* {@link
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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 {
|
|
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}"` +
|
|
@@ -88,11 +88,6 @@ export class PlacementAnimation implements AnimationInterface {
|
|
|
88
88
|
position = Parameter.parseVector( position );
|
|
89
89
|
this._placementDefinition.position = position;
|
|
90
90
|
}
|
|
91
|
-
let shortestWay = true;
|
|
92
|
-
if( this._animationDefinition.shortestWay !== undefined ) {
|
|
93
|
-
shortestWay = Parameter.parseBoolean( this._animationDefinition.shortestWay );
|
|
94
|
-
this._animationDefinition.shortestWay = shortestWay;
|
|
95
|
-
}
|
|
96
91
|
if( this.mutable instanceof ArcRotateCamera ) {
|
|
97
92
|
// parse the target
|
|
98
93
|
if( isString( this._placementDefinition.target ) ) {
|
|
@@ -110,11 +105,6 @@ export class PlacementAnimation implements AnimationInterface {
|
|
|
110
105
|
} );
|
|
111
106
|
delete this._placementDefinition.position;
|
|
112
107
|
ghostCam.dispose();
|
|
113
|
-
} else if( shortestWay && this._placementDefinition.alpha ) {
|
|
114
|
-
// transform the target's alpha value into the same turn as the current camera position to avoid movements > 360 degrees
|
|
115
|
-
const alphaGap = this.mutable.alpha - this._placementDefinition.alpha;
|
|
116
|
-
const cntTurns = Math.round(alphaGap / (2 * Math.PI));
|
|
117
|
-
this._placementDefinition.alpha += (2 * Math.PI * cntTurns);
|
|
118
108
|
}
|
|
119
109
|
}
|
|
120
110
|
}
|