@combeenation/3d-viewer 4.0.0-beta3 → 4.0.0

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 +3 -1
  2. package/dist/lib-cjs/api/classes/element.d.ts +14 -9
  3. package/dist/lib-cjs/api/classes/element.js +148 -87
  4. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  5. package/dist/lib-cjs/api/classes/event.d.ts +15 -1
  6. package/dist/lib-cjs/api/classes/event.js +15 -1
  7. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  8. package/dist/lib-cjs/api/classes/parameter.d.ts +101 -7
  9. package/dist/lib-cjs/api/classes/parameter.js +141 -21
  10. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  11. package/dist/lib-cjs/api/classes/parameterObservable.js +11 -36
  12. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  13. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +2 -2
  14. package/dist/lib-cjs/api/classes/placementAnimation.js +11 -0
  15. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  16. package/dist/lib-cjs/api/classes/variant.d.ts +48 -4
  17. package/dist/lib-cjs/api/classes/variant.js +320 -46
  18. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  19. package/dist/lib-cjs/api/classes/variantInstance.d.ts +5 -1
  20. package/dist/lib-cjs/api/classes/variantInstance.js +10 -0
  21. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  22. package/dist/lib-cjs/api/classes/viewer.d.ts +6 -3
  23. package/dist/lib-cjs/api/classes/viewer.js +140 -59
  24. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  25. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +5 -1
  26. package/dist/lib-cjs/api/internal/sceneSetup.js +75 -71
  27. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  28. package/dist/lib-cjs/api/util/babylonHelper.d.ts +54 -4
  29. package/dist/lib-cjs/api/util/babylonHelper.js +160 -8
  30. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  31. package/dist/lib-cjs/api/util/globalTypes.d.ts +62 -8
  32. package/dist/lib-cjs/api/util/resourceHelper.d.ts +13 -8
  33. package/dist/lib-cjs/api/util/resourceHelper.js +14 -14
  34. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  35. package/dist/lib-cjs/index.d.ts +24 -22
  36. package/dist/lib-cjs/index.js +42 -38
  37. package/dist/lib-cjs/index.js.map +1 -1
  38. package/package.json +5 -5
  39. package/src/api/classes/element.ts +118 -91
  40. package/src/api/classes/event.ts +16 -1
  41. package/src/api/classes/parameter.ts +153 -22
  42. package/src/api/classes/parameterObservable.ts +9 -31
  43. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +12 -1
  44. package/src/api/classes/placementAnimation.ts +10 -0
  45. package/src/api/classes/variant.ts +187 -40
  46. package/src/api/classes/variantInstance.ts +8 -1
  47. package/src/api/classes/variantParameterizable.ts +73 -0
  48. package/src/api/classes/viewer.ts +83 -17
  49. package/src/api/classes/viewerLight.ts +330 -0
  50. package/src/api/internal/sceneSetup.ts +99 -109
  51. package/src/api/util/babylonHelper.ts +173 -10
  52. package/src/api/util/globalTypes.ts +71 -10
  53. package/src/api/util/resourceHelper.ts +16 -16
  54. package/src/api/util/stringHelper.ts +26 -0
  55. package/src/dev.ts +3 -7
  56. package/src/index.ts +27 -23
  57. package/src/pagesconfig.json +4 -0
@@ -8,6 +8,7 @@ type VariantInstance = import("../classes/variantInstance").VariantInstance;
8
8
  */
9
9
  type VariantElement = import("../classes/element").Element;
10
10
  type DottedPath = import("../classes/dottedPath").DottedPath;
11
+ type ViewerLight = import("../classes/viewerLight").ViewerLight;
11
12
 
12
13
  // global accessible types imported from BabylonJS
13
14
  type Scene = import("@babylonjs/core/scene").Scene;
@@ -68,6 +69,10 @@ type Asset = {
68
69
  fileName: string | undefined
69
70
  };
70
71
 
72
+ type ElementDefinitions = {
73
+ [name: string]: ElementDefinition | string[]
74
+ };
75
+
71
76
  type ElementDefinition = {
72
77
  paths: PathDefinitions,
73
78
  traceables?: TraceableDefinitions,
@@ -92,9 +97,9 @@ type StructureJson = {
92
97
  glTF?: Asset | string,
93
98
  parameterDeclaration?: ParameterDeclarations,
94
99
  parameters?: ParameterBag,
95
- elements?: {
96
- [name: string]: ElementDefinition | string[]
97
- },
100
+ elements?: ElementDefinitions,
101
+ lights?: LightDefinitions,
102
+ grounds?: GroundDefinitions,
98
103
  /**
99
104
  * `variants` is a declarative description of 3D-model variations in the configurator. Each variant itself is a
100
105
  * {@link StructureJson} which must at least define a `name` in the key of the list and the properties `glTF` and
@@ -123,7 +128,7 @@ type StructureJson = {
123
128
  */
124
129
  variants?: {
125
130
  [id: string]: StructureJson,
126
- }
131
+ },
127
132
  };
128
133
 
129
134
  type SceneJson = {
@@ -144,8 +149,7 @@ type SceneJson = {
144
149
 
145
150
  type SceneDefinition = {
146
151
  globals: SceneGlobals,
147
- lights?: LightDefinitions,
148
- cameras?: CameraDefinitions
152
+ cameras?: CameraDefinitions,
149
153
  };
150
154
 
151
155
  type SceneGlobals = {
@@ -189,12 +193,29 @@ type SceneGlobals = {
189
193
  }
190
194
  };
191
195
 
196
+ /**
197
+ * {@link Viewer.screenshot} internally uses Babylons [ScreenshotTools.CreateScreenshotUsingRenderTarget](https://doc.babylonjs.com/typedoc/classes/babylon.screenshottools#createscreenshotusingrendertarget). \
198
+ * See this link for additional info about the properties.
199
+ */
192
200
  type ScreenshotSettings = {
201
+ /** Defaults to canvas width & height */
193
202
  size?: IScreenshotSize,
203
+ /**
204
+ * Default `image/png`
205
+ *
206
+ * **Info regarding JPEG:** \
207
+ * Use mimeType `image/jpeg` (**not** `image/jpg`) when creating jpeg's. \
208
+ * Also ensure that {@link Scene.clearColor | viewer.scene.clearColor} has an alpha value of `1` as jpeg's don't support
209
+ * transparency. Otherwise background will always be black for jpeg's.
210
+ */
194
211
  mimeType?: string,
212
+ /** Default `1` */
195
213
  samples?: number,
214
+ /** Default `false` */
196
215
  antialiasing?: boolean,
216
+ /** Default `screenshot.png` */
197
217
  fileName?: string,
218
+ /** Default `false` */
198
219
  renderSprites?: boolean
199
220
  };
200
221
 
@@ -210,11 +231,40 @@ type AutofocusSettings = {
210
231
  };
211
232
 
212
233
  type LightDefinitions = {
213
- [light: string]: LightDefinition
234
+ [name: string]: LightDefinition | string
214
235
  };
215
236
 
216
237
  type LightDefinition = {
217
- type: 'hemispheric' | 'point'
238
+ type: 'baked' | 'hemispheric' | 'point' | 'directional' | 'spot',
239
+ path?: string,
240
+ shadowGenerator?: ShadowGeneratorDefinition
241
+ };
242
+
243
+ type ShadowGeneratorDefinition = {
244
+ mapSize: number
245
+ [others: string]: any,
246
+ /**
247
+ * Further properties like `usePoissonSampling` are set directly on the ShadowGenerator object.
248
+ * [Shadows](https://doc.babylonjs.com/divingDeeper/lights/shadows)
249
+ */
250
+ };
251
+
252
+ type GroundDefinitions = {
253
+ [ground: string]: GroundDefinition
254
+ };
255
+
256
+ type GroundDefinition = {
257
+ type: 'baked' | 'ground' | 'heightmap',
258
+ meshId?: string,
259
+ url?: string,
260
+ width?: number,
261
+ height?: number,
262
+ subdivisions?: number,
263
+ receiveShadows?: boolean,
264
+ minHeight?: number,
265
+ maxHeight?: number,
266
+ alphaFilter?: number,
267
+ onReady?: any
218
268
  };
219
269
 
220
270
  type CameraDefinitions = {
@@ -258,7 +308,8 @@ type ParameterDeclarations = {
258
308
  };
259
309
 
260
310
  type ParameterDeclaration = {
261
- type: 'string' | 'boolean' | 'number' | 'color' | 'select' | 'vector',
311
+ type: 'string' | 'boolean' | 'number' | 'color' | 'select' | 'vector' | 'csl',
312
+ parser?: any,
262
313
  options?: ParameterValue[]
263
314
  };
264
315
 
@@ -268,6 +319,10 @@ type ParameterBag = {
268
319
  [name: string]: ParameterValue
269
320
  };
270
321
 
322
+ type ParsedParameterBag = {
323
+ [name: string]: any
324
+ };
325
+
271
326
  type DottedPathArgument = string | string[] | DottedPath;
272
327
 
273
328
  type ParameterObserver = (
@@ -299,6 +354,12 @@ type AnimationDefinitions = {
299
354
  * liking and simply copy the `ease` function shown at the bottom of the visualizer into the `ease` property of your
300
355
  * {@link AnimationDefinition}.
301
356
  *
357
+ * The `GSAPTWeenVars` are extended by the `shortestWay` property.\
358
+ * This property defines if the camera should move to the target position within the shortest possible distance.\
359
+ * If `shortestWay` is `false`, the camera moves the whole difference between the current camera position and the target position
360
+ * and that could be > 360, which can appear very unconvenient to the operator.\
361
+ * The default value of this flag is `true`.
362
+ *
302
363
  * Example usage in {@link SceneJson | SceneJson.animations}:
303
364
  *
304
365
  * ```js
@@ -316,4 +377,4 @@ type AnimationDefinitions = {
316
377
  * // ...
317
378
  * ```
318
379
  */
319
- type AnimationDefinition = GSAPTweenVars;
380
+ type AnimationDefinition = GSAPTweenVars & { shortestWay?: boolean }
@@ -1,5 +1,10 @@
1
1
  import { emitter, Event } from '../classes/event';
2
2
 
3
+ /**
4
+ * Sleeps for a certain amount of microseconds.
5
+ */
6
+ const sleep = ( ms: number ) => new Promise( resolve => window.setTimeout( resolve, ms ) );
7
+
3
8
  /**
4
9
  * Loads any kind of response from given path.
5
10
  * @emits {@link Event.LOADING_START}
@@ -56,16 +61,6 @@ const debounce = function( func: Function, wait: number, immediate: boolean = fa
56
61
  };
57
62
  };
58
63
 
59
- /**
60
- * Creates a random uuidv4.
61
- */
62
- const uuidv4 = function() {
63
- // @ts-ignore
64
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace( /[018]/g, c =>
65
- (c ^ crypto.getRandomValues( new Uint8Array( 1 ) )[0] & 15 >> c / 4).toString( 16 )
66
- );
67
- };
68
-
69
64
  /**
70
65
  * Merges multiple maps.
71
66
  */
@@ -80,8 +75,8 @@ const mergeMaps = function <TKey, TValue>( ...maps: Map<TKey, TValue>[] ): Map<T
80
75
  };
81
76
 
82
77
  /**
83
- * Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG
84
- * (eg: fonts, images) are already loaded and exchanged by their base64 representation.\
78
+ * Creates a HTML image element based on a SVG string, whereas all the embedded assets in the SVG (eg: fonts, images)
79
+ * are already loaded and exchanged by their base64 representation.\
85
80
  * There the output image can exist as "standalone" image and may be used for example as a paintable.
86
81
  *
87
82
  * !!CAUTION!!: The used functions within this code section are very well evaluated since most alternatives
@@ -107,12 +102,17 @@ const createImageFromSvg = async function( svgSrc: string ): Promise<HTMLImageEl
107
102
  * - https://bugs.webkit.org/show_bug.cgi?id=39059
108
103
  * - https://bugs.webkit.org/show_bug.cgi?id=219770
109
104
  *
110
- * It's not 100% ensured that the timeout solves the issue in any case, but there is no other way unfortunately.\
105
+ * It's not 100% ensured that the timeout solves the issue in every case, but there is no other way unfortunately.\
111
106
  * => Keep an eye on it in future projects
107
+ *
108
+ * @param imgSrc Theoretically every source is valid which is also supported by
109
+ * [HTMLImageElement.src](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/src).\
110
+ * Known exceptions are SVGs with embedded assets that are provided as object URL. See comments in
111
+ * {@link createImageFromSvg} for further details.
112
112
  */
113
- const createImageFromImgSrc = async function ( imgSrc: string ): Promise<HTMLImageElement> {
113
+ const createImageFromImgSrc = async function ( imgSrc: string ): Promise<HTMLImageElement> {
114
114
  let img = new Image();
115
-
115
+
116
116
  await new Promise(resolve => {
117
117
  img.onload = () => {
118
118
  setTimeout(resolve, 0);
@@ -175,10 +175,10 @@ const _fetchBase64AssetUrl = async function( assetUrl: string ): Promise<{ url:
175
175
  };
176
176
 
177
177
  export {
178
+ sleep,
178
179
  loadJson,
179
180
  loadText,
180
181
  debounce,
181
- uuidv4,
182
182
  mergeMaps,
183
183
  createImageFromSvg,
184
184
  createImageFromImgSrc
@@ -0,0 +1,26 @@
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
+ };
package/src/dev.ts CHANGED
@@ -4,10 +4,8 @@ import { set } from 'lodash-es';
4
4
 
5
5
  import { Emitter, Viewer } from '.';
6
6
 
7
- /**
8
- * (i) HERE YOU @TODO (1) ADJUST THE CURRENT DEMO YOU ARE WORKING ON.
9
- */
10
- import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/hulahoop/main';
7
+ import { createSpec, beforeBootstrap, afterBootstrap, createUIelements } from '../assets/index';
8
+
11
9
  const loadingElement = document.getElementById( 'loading' ) as HTMLDivElement;
12
10
 
13
11
  Emitter.on( Event.BOOTSTRAP_START, () => {
@@ -24,7 +22,7 @@ document.addEventListener('DOMContentLoaded', main );
24
22
  async function main() {
25
23
  const viewer = await bootstrapViewer();
26
24
  // "Export" for console testing...
27
- set( window, 'viewerInstance', viewer);
25
+ set( window, 'viewer', viewer);
28
26
  }
29
27
 
30
28
  async function bootstrapViewer() {
@@ -41,7 +39,5 @@ async function bootstrapViewer() {
41
39
  }
42
40
  await afterBootstrap( viewer );
43
41
  await createUIelements( viewer );
44
- console.info( ' --- UI Initialized ---');
45
-
46
42
  return viewer;
47
43
  }
package/src/index.ts CHANGED
@@ -1,40 +1,24 @@
1
1
  /// <reference path="api/util/globalTypes.ts" />
2
2
 
3
+ import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
3
4
  import { ArcRotateCamera } from '@babylonjs/core/Cameras/arcRotateCamera';
4
5
  import { Engine } from '@babylonjs/core/Engines/engine';
6
+ import { DirectionalLight } from '@babylonjs/core/Lights/directionalLight';
7
+ import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
5
8
  import { Material } from '@babylonjs/core/Materials/material';
6
9
  import { PBRMaterial } from '@babylonjs/core/Materials/PBR/pbrMaterial';
7
10
  import { StandardMaterial } from '@babylonjs/core/Materials/standardMaterial';
11
+ import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';
8
12
  import { DynamicTexture } from '@babylonjs/core/Materials/Textures/dynamicTexture';
13
+ import { Texture } from '@babylonjs/core/Materials/Textures/texture';
9
14
  import { Color3, Color4 } from '@babylonjs/core/Maths/math.color';
10
15
  import { Vector3 } from '@babylonjs/core/Maths/math.vector';
11
16
  import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
12
17
  import { InstancedMesh } from '@babylonjs/core/Meshes/instancedMesh';
13
18
  import { Mesh } from '@babylonjs/core/Meshes/mesh';
19
+ import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
14
20
  import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
15
21
  import { Node } from '@babylonjs/core/node';
16
- import { Scene } from '@babylonjs/core/scene';
17
- import { VariantInstance } from './api/classes/variantInstance';
18
- import { Viewer } from './api/classes/viewer';
19
- import { Event, emitter } from './api/classes/event';
20
- import { EventEmitter } from 'eventemitter3';
21
- import { Parameter } from './api/classes/parameter';
22
- import { CubeTexture } from '@babylonjs/core/Materials/Textures/cubeTexture';
23
- import { Animation as BabylonAnimation } from '@babylonjs/core/Animations/animation';
24
- import { MeshBuilder } from '@babylonjs/core/Meshes/meshBuilder';
25
- import { Texture } from '@babylonjs/core/Materials/Textures/texture';
26
- import { DirectionalLight } from '@babylonjs/core/Lights/directionalLight';
27
- import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
28
- import { Variant } from './api/classes/variant';
29
- import { ParameterObservable } from './api/classes/parameterObservable';
30
- import { ElementParameterizable } from './api/classes/elementParameterizable';
31
- import { Element } from './api/classes/element';
32
- import { VariantInstanceManager } from './api/manager/variantInstanceManager';
33
- import { AnimationManager } from './api/manager/animationManager';
34
- import { EventBroadcaster } from './api/classes/eventBroadcaster';
35
- import { SceneManager } from './api/manager/sceneManager';
36
- import { PlacementAnimation } from './api/classes/placementAnimation';
37
- import * as BabylonHelper from './api/util/babylonHelper';
38
22
 
39
23
  /**
40
24
  * Without explicitly importing the "BoundingBoxRenderer", we're getting "scene.getBoundingBoxRenderer is undefined"
@@ -42,6 +26,24 @@ import * as BabylonHelper from './api/util/babylonHelper';
42
26
  * version of the viewer (e.g. when pulling it from NPM etc.)...
43
27
  */
44
28
  import '@babylonjs/core/Rendering/boundingBoxRenderer';
29
+ import { Scene } from '@babylonjs/core/scene';
30
+ import { Parameterizable } from './api/classes/parameterizable';
31
+ import { VariantParameterizable } from './api/classes/variantParameterizable';
32
+ import { EventEmitter } from 'eventemitter3';
33
+ import { Element } from './api/classes/element';
34
+ import { emitter, Event } from './api/classes/event';
35
+ import { EventBroadcaster } from './api/classes/eventBroadcaster';
36
+ import { Parameter } from './api/classes/parameter';
37
+ import { ParameterObservable } from './api/classes/parameterObservable';
38
+ import { PlacementAnimation } from './api/classes/placementAnimation';
39
+ import { Variant } from './api/classes/variant';
40
+ import { VariantInstance } from './api/classes/variantInstance';
41
+ import { Viewer } from './api/classes/viewer';
42
+ import { ViewerLight } from './api/classes/viewerLight';
43
+ import { AnimationManager } from './api/manager/animationManager';
44
+ import { SceneManager } from './api/manager/sceneManager';
45
+ import { VariantInstanceManager } from './api/manager/variantInstanceManager';
46
+ import * as BabylonHelper from './api/util/babylonHelper';
45
47
 
46
48
  /**
47
49
  * Expose some frequently used babylon modules by our consumers.
@@ -52,7 +54,9 @@ export {
52
54
  VariantInstanceManager,
53
55
  Viewer,
54
56
  ParameterObservable,
55
- ElementParameterizable,
57
+ Parameterizable,
58
+ VariantParameterizable,
59
+ ViewerLight,
56
60
  emitter as Emitter,
57
61
  EventEmitter,
58
62
  Event,
@@ -38,6 +38,10 @@
38
38
  "title": "Parameters",
39
39
  "source": "./doc/documentation/Parameters.md"
40
40
  },
41
+ {
42
+ "title": "ViewerLights",
43
+ "source": "./doc/ViewerLights.md"
44
+ },
41
45
  {
42
46
  "title": "Paintables",
43
47
  "source": "./doc/documentation/Paintables.md"