@combeenation/3d-viewer 4.0.0-beta4 → 4.0.1-alpha1

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 (106) hide show
  1. package/README.md +114 -112
  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 +130 -125
  7. package/dist/lib-cjs/api/classes/element.js +743 -682
  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 +326 -312
  12. package/dist/lib-cjs/api/classes/event.js +371 -357
  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 +259 -165
  17. package/dist/lib-cjs/api/classes/parameter.js +387 -267
  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 +101 -126
  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 +43 -38
  25. package/dist/lib-cjs/api/classes/placementAnimation.js +160 -138
  26. package/dist/lib-cjs/api/classes/placementAnimation.js.map +1 -1
  27. package/dist/lib-cjs/api/classes/variant.d.ts +234 -190
  28. package/dist/lib-cjs/api/classes/variant.js +1147 -873
  29. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  30. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
  31. package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
  32. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  33. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -17
  34. package/dist/lib-cjs/api/classes/variantParameterizable.js +92 -92
  35. package/dist/lib-cjs/api/classes/viewer.d.ts +131 -128
  36. package/dist/lib-cjs/api/classes/viewer.js +567 -486
  37. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  38. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -65
  39. package/dist/lib-cjs/api/classes/viewerLight.js +389 -322
  40. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -1
  41. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  42. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  43. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  44. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  45. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -6
  46. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
  47. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  48. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  49. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  50. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  51. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  52. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  53. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  54. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  55. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  56. package/dist/lib-cjs/api/util/babylonHelper.d.ts +175 -125
  57. package/dist/lib-cjs/api/util/babylonHelper.js +520 -368
  58. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  59. package/dist/lib-cjs/api/util/globalTypes.d.ts +333 -279
  60. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  61. package/dist/lib-cjs/api/util/resourceHelper.d.ts +53 -51
  62. package/dist/lib-cjs/api/util/resourceHelper.js +240 -243
  63. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  64. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -9
  65. package/dist/lib-cjs/api/util/stringHelper.js +25 -25
  66. package/dist/lib-cjs/buildinfo.json +3 -3
  67. package/dist/lib-cjs/index.d.ts +48 -46
  68. package/dist/lib-cjs/index.js +86 -82
  69. package/dist/lib-cjs/index.js.map +1 -1
  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 +644 -617
  74. package/src/api/classes/event.ts +370 -355
  75. package/src/api/classes/eventBroadcaster.ts +54 -54
  76. package/src/api/classes/parameter.ts +408 -277
  77. package/src/api/classes/parameterObservable.ts +99 -121
  78. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
  79. package/src/api/classes/placementAnimation.ts +157 -133
  80. package/src/api/classes/variant.ts +817 -670
  81. package/src/api/classes/variantInstance.ts +88 -81
  82. package/src/api/classes/variantParameterizable.ts +73 -0
  83. package/src/api/classes/viewer.ts +487 -421
  84. package/src/api/classes/viewerLight.ts +330 -0
  85. package/src/api/internal/debugViewer.ts +81 -81
  86. package/src/api/internal/lensRendering.ts +10 -10
  87. package/src/api/internal/sceneSetup.ts +194 -204
  88. package/src/api/manager/animationManager.ts +116 -116
  89. package/src/api/manager/sceneManager.ts +105 -105
  90. package/src/api/manager/variantInstanceManager.ts +236 -236
  91. package/src/api/store/specStorage.ts +53 -53
  92. package/src/api/util/babylonHelper.ts +555 -392
  93. package/src/api/util/globalTypes.ts +380 -319
  94. package/src/api/util/resourceHelper.ts +184 -187
  95. package/src/api/util/stringHelper.ts +26 -0
  96. package/src/buildinfo.json +2 -2
  97. package/src/commonjs.tsconfig.json +13 -13
  98. package/src/declaration.tsconfig.json +10 -10
  99. package/src/dev.ts +42 -46
  100. package/src/es6.tsconfig.json +13 -13
  101. package/src/index.ts +91 -87
  102. package/src/pagesconfig.json +61 -57
  103. package/src/tsconfig.json +43 -43
  104. package/src/tsconfig.types.json +9 -9
  105. package/src/types.d.ts +4 -4
  106. package/dist/webpack-stats.json +0 -0
@@ -0,0 +1,330 @@
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,82 +1,82 @@
1
- /**
2
- * @internal
3
- */
4
- import { Scene } from '@babylonjs/core/scene';
5
- import { VariantInstance } from '../classes/variantInstance';
6
- import { Viewer } from '../classes/viewer';
7
- import { Event } from '../classes/event';
8
-
9
- export class DebugViewer extends Viewer {
10
-
11
- constructor( canvas: HTMLCanvasElement, data: string | StructureJson ) {
12
- super( canvas, data );
13
- }
14
-
15
- public async bootstrap(): Promise<Viewer> {
16
- for( const event of Event.all ) {
17
- this.eventEmitter.addListener( event, ( ...args ) => console.debug( `Emitting ${event}`, ...args ) );
18
- }
19
- for( const event of [
20
- Event.VARIANT_INSTANCE_DESTROYED,
21
- Event.VARIANT_INSTANCE_CREATED,
22
- Event.VARIANT_INSTANCE_CLONED,
23
- Event.VARIANT_PARAMETER_COMMITTED
24
- ] ) {
25
- this.eventEmitter.addListener( event, this.instanceDebugger.bind( this ) );
26
- }
27
- return super.bootstrap();
28
- }
29
-
30
- protected async initScene(): Promise<Scene> {
31
- const scene = await super.initScene();
32
-
33
- scene.getEngine().runRenderLoop( () => {
34
- this.fpsDebugger();
35
- } );
36
-
37
- return scene;
38
- }
39
-
40
- protected instanceDebugger( instance: VariantInstance ) {
41
- const instances: string[] = [];
42
- this.variantInstances.all.forEach( variantInstance => {
43
- instances.push( `${variantInstance.name}${variantInstance.variant.visible ? '' : ' [hidden]'}${variantInstance.variant.highlighted ? ' [highlighted]' : ''}` );
44
- } );
45
- let debugContainer = document.getElementById( 'cyledge-combeenation-3d-viewer-instance-debugger' );
46
- if( !debugContainer ) {
47
- debugContainer = document.createElement( 'pre' );
48
- debugContainer.setAttribute( 'id', 'cyledge-combeenation-3d-viewer-instance-debugger' );
49
- debugContainer.setAttribute( 'style', `
50
- background: #454545;
51
- color: #fff;
52
- position: absolute;
53
- bottom: 0;
54
- right: 0;
55
- padding: 10px;
56
- margin: 0;
57
- ` );
58
- document.body.appendChild( debugContainer );
59
- }
60
- debugContainer.innerHTML = JSON.stringify( instances, null, 2 );
61
- };
62
-
63
- protected fpsDebugger() {
64
- let debugContainer = document.getElementById( 'cyledge-combeenation-3d-viewer-fps-debugger' );
65
- if( !debugContainer ) {
66
- debugContainer = document.createElement( 'pre' );
67
- debugContainer.setAttribute( 'id', 'cyledge-combeenation-3d-viewer-fps-debugger' );
68
- debugContainer.setAttribute( 'style', `
69
- background: #454545;
70
- color: #fff;
71
- position: absolute;
72
- bottom: 0;
73
- left: 0;
74
- padding: 10px;
75
- margin: 0;
76
- ` );
77
- document.body.appendChild( debugContainer );
78
- }
79
- debugContainer.innerHTML = `${this.engine.getFps().toFixed( 2 )} fps`;
80
- }
81
-
1
+ /**
2
+ * @internal
3
+ */
4
+ import { Scene } from '@babylonjs/core/scene';
5
+ import { VariantInstance } from '../classes/variantInstance';
6
+ import { Viewer } from '../classes/viewer';
7
+ import { Event } from '../classes/event';
8
+
9
+ export class DebugViewer extends Viewer {
10
+
11
+ constructor( canvas: HTMLCanvasElement, data: string | StructureJson ) {
12
+ super( canvas, data );
13
+ }
14
+
15
+ public async bootstrap(): Promise<Viewer> {
16
+ for( const event of Event.all ) {
17
+ this.eventEmitter.addListener( event, ( ...args ) => console.debug( `Emitting ${event}`, ...args ) );
18
+ }
19
+ for( const event of [
20
+ Event.VARIANT_INSTANCE_DESTROYED,
21
+ Event.VARIANT_INSTANCE_CREATED,
22
+ Event.VARIANT_INSTANCE_CLONED,
23
+ Event.VARIANT_PARAMETER_COMMITTED
24
+ ] ) {
25
+ this.eventEmitter.addListener( event, this.instanceDebugger.bind( this ) );
26
+ }
27
+ return super.bootstrap();
28
+ }
29
+
30
+ protected async initScene(): Promise<Scene> {
31
+ const scene = await super.initScene();
32
+
33
+ scene.getEngine().runRenderLoop( () => {
34
+ this.fpsDebugger();
35
+ } );
36
+
37
+ return scene;
38
+ }
39
+
40
+ protected instanceDebugger( instance: VariantInstance ) {
41
+ const instances: string[] = [];
42
+ this.variantInstances.all.forEach( variantInstance => {
43
+ instances.push( `${variantInstance.name}${variantInstance.variant.visible ? '' : ' [hidden]'}${variantInstance.variant.highlighted ? ' [highlighted]' : ''}` );
44
+ } );
45
+ let debugContainer = document.getElementById( 'cyledge-combeenation-3d-viewer-instance-debugger' );
46
+ if( !debugContainer ) {
47
+ debugContainer = document.createElement( 'pre' );
48
+ debugContainer.setAttribute( 'id', 'cyledge-combeenation-3d-viewer-instance-debugger' );
49
+ debugContainer.setAttribute( 'style', `
50
+ background: #454545;
51
+ color: #fff;
52
+ position: absolute;
53
+ bottom: 0;
54
+ right: 0;
55
+ padding: 10px;
56
+ margin: 0;
57
+ ` );
58
+ document.body.appendChild( debugContainer );
59
+ }
60
+ debugContainer.innerHTML = JSON.stringify( instances, null, 2 );
61
+ };
62
+
63
+ protected fpsDebugger() {
64
+ let debugContainer = document.getElementById( 'cyledge-combeenation-3d-viewer-fps-debugger' );
65
+ if( !debugContainer ) {
66
+ debugContainer = document.createElement( 'pre' );
67
+ debugContainer.setAttribute( 'id', 'cyledge-combeenation-3d-viewer-fps-debugger' );
68
+ debugContainer.setAttribute( 'style', `
69
+ background: #454545;
70
+ color: #fff;
71
+ position: absolute;
72
+ bottom: 0;
73
+ left: 0;
74
+ padding: 10px;
75
+ margin: 0;
76
+ ` );
77
+ document.body.appendChild( debugContainer );
78
+ }
79
+ debugContainer.innerHTML = `${this.engine.getFps().toFixed( 2 )} fps`;
80
+ }
81
+
82
82
  }
@@ -1,11 +1,11 @@
1
- /**
2
- * Group the required LensRendering dependencies into a single file to allow a single "import"
3
- *
4
- * @internal
5
- */
6
-
7
- import '@babylonjs/core/Rendering/depthRendererSceneComponent';
8
- import { LensRenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline';
9
-
10
-
1
+ /**
2
+ * Group the required LensRendering dependencies into a single file to allow a single "import"
3
+ *
4
+ * @internal
5
+ */
6
+
7
+ import '@babylonjs/core/Rendering/depthRendererSceneComponent';
8
+ import { LensRenderingPipeline } from '@babylonjs/core/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline';
9
+
10
+
11
11
  export { LensRenderingPipeline };