@combeenation/3d-viewer 3.0.0-rc2 → 4.0.0-alpha6

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 (212) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +111 -111
  3. package/dist/lib-cjs/api/classes/animationInterface.d.ts +8 -8
  4. package/dist/lib-cjs/api/classes/animationInterface.js +1 -1
  5. package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -0
  6. package/dist/lib-cjs/api/classes/dottedPath.d.ts +79 -79
  7. package/dist/lib-cjs/api/classes/dottedPath.js +190 -190
  8. package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -0
  9. package/dist/lib-cjs/api/classes/element.d.ts +130 -125
  10. package/dist/lib-cjs/api/classes/element.js +752 -638
  11. package/dist/lib-cjs/api/classes/element.js.map +1 -1
  12. package/dist/lib-cjs/api/classes/elementParameterizable.d.ts +14 -14
  13. package/dist/lib-cjs/api/classes/elementParameterizable.js +134 -134
  14. package/dist/lib-cjs/api/classes/elementParameterizable.js.map +0 -0
  15. package/dist/lib-cjs/api/classes/event.d.ts +326 -312
  16. package/dist/lib-cjs/api/classes/event.js +371 -357
  17. package/dist/lib-cjs/api/classes/event.js.map +1 -1
  18. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +26 -26
  19. package/dist/lib-cjs/api/classes/eventBroadcaster.js +53 -53
  20. package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -0
  21. package/dist/lib-cjs/api/classes/parameter.d.ts +259 -161
  22. package/dist/lib-cjs/api/classes/parameter.js +387 -261
  23. package/dist/lib-cjs/api/classes/parameter.js.map +1 -1
  24. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +36 -36
  25. package/dist/lib-cjs/api/classes/parameterObservable.js +101 -126
  26. package/dist/lib-cjs/api/classes/parameterObservable.js.map +1 -1
  27. package/dist/lib-cjs/api/classes/parameterizable.d.ts +15 -0
  28. package/dist/lib-cjs/api/classes/parameterizable.js +150 -0
  29. package/dist/lib-cjs/api/classes/parameterizable.js.map +1 -0
  30. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +38 -38
  31. package/dist/lib-cjs/api/classes/placementAnimation.js +138 -138
  32. package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -0
  33. package/dist/lib-cjs/api/classes/variant.d.ts +224 -176
  34. package/dist/lib-cjs/api/classes/variant.js +1126 -770
  35. package/dist/lib-cjs/api/classes/variant.js.map +1 -1
  36. package/dist/lib-cjs/api/classes/variantInstance.d.ts +45 -41
  37. package/dist/lib-cjs/api/classes/variantInstance.js +108 -98
  38. package/dist/lib-cjs/api/classes/variantInstance.js.map +1 -1
  39. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +17 -0
  40. package/dist/lib-cjs/api/classes/variantParameterizable.js +93 -0
  41. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +1 -0
  42. package/dist/lib-cjs/api/classes/viewer.d.ts +127 -128
  43. package/dist/lib-cjs/api/classes/viewer.js +486 -486
  44. package/dist/lib-cjs/api/classes/viewer.js.map +1 -1
  45. package/dist/lib-cjs/api/classes/viewerLight.d.ts +66 -0
  46. package/dist/lib-cjs/api/classes/viewerLight.js +350 -0
  47. package/dist/lib-cjs/api/classes/viewerLight.js.map +1 -0
  48. package/dist/lib-cjs/api/emitter.d.ts +35 -0
  49. package/dist/lib-cjs/api/emitter.js +61 -0
  50. package/dist/lib-cjs/api/emitter.js.map +1 -0
  51. package/dist/lib-cjs/api/internal/debugViewer.d.ts +13 -13
  52. package/dist/lib-cjs/api/internal/debugViewer.js +87 -87
  53. package/dist/lib-cjs/api/internal/debugViewer.js.map +0 -0
  54. package/dist/lib-cjs/api/internal/lensRendering.d.ts +8 -8
  55. package/dist/lib-cjs/api/internal/lensRendering.js +11 -11
  56. package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -0
  57. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +10 -6
  58. package/dist/lib-cjs/api/internal/sceneSetup.js +231 -227
  59. package/dist/lib-cjs/api/internal/sceneSetup.js.map +1 -1
  60. package/dist/lib-cjs/api/manager/animationManager.d.ts +29 -29
  61. package/dist/lib-cjs/api/manager/animationManager.js +121 -121
  62. package/dist/lib-cjs/api/manager/animationManager.js.map +0 -0
  63. package/dist/lib-cjs/api/manager/sceneManager.d.ts +32 -32
  64. package/dist/lib-cjs/api/manager/sceneManager.js +132 -132
  65. package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -0
  66. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +90 -90
  67. package/dist/lib-cjs/api/manager/variantInstanceManager.js +321 -321
  68. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -0
  69. package/dist/lib-cjs/api/store/specStorage.d.ts +24 -24
  70. package/dist/lib-cjs/api/store/specStorage.js +51 -51
  71. package/dist/lib-cjs/api/store/specStorage.js.map +0 -0
  72. package/dist/lib-cjs/api/util/babylonHelper.d.ts +160 -125
  73. package/dist/lib-cjs/api/util/babylonHelper.js +465 -368
  74. package/dist/lib-cjs/api/util/babylonHelper.js.map +1 -1
  75. package/dist/lib-cjs/api/util/globalTypes.d.ts +321 -275
  76. package/dist/lib-cjs/api/util/globalTypes.js +1 -1
  77. package/dist/lib-cjs/api/util/globalTypes.js.map +0 -0
  78. package/dist/lib-cjs/api/util/resourceHelper.d.ts +26 -30
  79. package/dist/lib-cjs/api/util/resourceHelper.js +237 -247
  80. package/dist/lib-cjs/api/util/resourceHelper.js.map +1 -1
  81. package/dist/lib-cjs/api/util/stringHelper.d.ts +9 -0
  82. package/dist/lib-cjs/api/util/stringHelper.js +26 -0
  83. package/dist/lib-cjs/api/util/stringHelper.js.map +1 -0
  84. package/dist/lib-cjs/buildinfo.json +3 -3
  85. package/dist/lib-cjs/index.d.ts +48 -46
  86. package/dist/lib-cjs/index.js +86 -82
  87. package/dist/lib-cjs/index.js.map +1 -1
  88. package/package.json +83 -83
  89. package/src/api/classes/animationInterface.ts +11 -11
  90. package/src/api/classes/dottedPath.ts +189 -189
  91. package/src/api/classes/element.ts +648 -606
  92. package/src/api/classes/event.ts +370 -355
  93. package/src/api/classes/eventBroadcaster.ts +54 -54
  94. package/src/api/classes/parameter.ts +408 -270
  95. package/src/api/classes/parameterObservable.ts +99 -121
  96. package/src/api/classes/{elementParameterizable.ts → parameterizable.ts} +89 -78
  97. package/src/api/classes/placementAnimation.ts +133 -133
  98. package/src/api/classes/variant.ts +799 -652
  99. package/src/api/classes/variantInstance.ts +88 -81
  100. package/src/api/classes/variantParameterizable.ts +73 -0
  101. package/src/api/classes/viewer.ts +420 -421
  102. package/src/api/classes/viewerLight.ts +295 -0
  103. package/src/api/internal/debugViewer.ts +81 -81
  104. package/src/api/internal/lensRendering.ts +10 -10
  105. package/src/api/internal/sceneSetup.ts +194 -204
  106. package/src/api/manager/animationManager.ts +116 -116
  107. package/src/api/manager/sceneManager.ts +105 -105
  108. package/src/api/manager/variantInstanceManager.ts +236 -236
  109. package/src/api/store/specStorage.ts +53 -53
  110. package/src/api/util/babylonHelper.ts +497 -392
  111. package/src/api/util/globalTypes.ts +369 -314
  112. package/src/api/util/resourceHelper.ts +157 -168
  113. package/src/api/util/stringHelper.ts +26 -0
  114. package/src/buildinfo.json +2 -2
  115. package/src/commonjs.tsconfig.json +13 -13
  116. package/src/declaration.tsconfig.json +10 -10
  117. package/src/dev.ts +45 -60
  118. package/src/es6.tsconfig.json +13 -13
  119. package/src/index.ts +91 -87
  120. package/src/pagesconfig.json +51 -47
  121. package/src/tsconfig.json +43 -43
  122. package/src/tsconfig.types.json +9 -9
  123. package/src/types.d.ts +4 -4
  124. package/src/assets/02_environment.env +0 -0
  125. package/src/assets/02_test_hdri_flipped.hdr +0 -0
  126. package/src/assets/07rDvxP2xTk.glb +0 -0
  127. package/src/assets/08L8DrdZt8y.glb +0 -0
  128. package/src/assets/CB-6250/main.js +0 -427
  129. package/src/assets/CB-6250/models/.gitkeep +0 -1
  130. package/src/assets/CB-6250/models/candle.glb +0 -0
  131. package/src/assets/CB-6250/models/lamp.glb +0 -0
  132. package/src/assets/CB-6250/models/molto-bido.glb +0 -0
  133. package/src/assets/CB-6250/models/mtron.glb +0 -0
  134. package/src/assets/CB-6250/models/mtron_split_geometry.glb +0 -0
  135. package/src/assets/CB-6250/models/mtron_split_material.glb +0 -0
  136. package/src/assets/KTM1290SA/AvatarAdv.glb +0 -0
  137. package/src/assets/KTM1290SA/ktm1290SA.ts +0 -77
  138. package/src/assets/KTM1290SA/scene.json +0 -16
  139. package/src/assets/_draft/main.js +0 -117
  140. package/src/assets/_draft/models/.gitkeep +0 -1
  141. package/src/assets/_draft/models/_demo.glb +0 -0
  142. package/src/assets/_draft/studio.env +0 -0
  143. package/src/assets/bike/CompleteBike_Optim_986K_01.glb +0 -0
  144. package/src/assets/bike/complete.json +0 -19
  145. package/src/assets/bike/index.json +0 -9
  146. package/src/assets/bike/setup.json +0 -11
  147. package/src/assets/ctrls-helper.ts +0 -89
  148. package/src/assets/cube/10 environment.env +0 -0
  149. package/src/assets/cube/bin_svg_logo_test.glb +0 -0
  150. package/src/assets/cube/cube.ts +0 -42
  151. package/src/assets/cube/cube_v2.glb +0 -0
  152. package/src/assets/cube/scene.ts +0 -83
  153. package/src/assets/cube/testCylinderUVs.glb +0 -0
  154. package/src/assets/environment.env +0 -0
  155. package/src/assets/hoferkerzen/hoferkerzen.glb +0 -0
  156. package/src/assets/hoferkerzen/index.json +0 -9
  157. package/src/assets/hoferkerzen/setup.json +0 -11
  158. package/src/assets/hoferkerzen/variant_kgl.json +0 -41
  159. package/src/assets/husqvarna-instanced-meshes/husqvarna.env +0 -0
  160. package/src/assets/husqvarna-instanced-meshes/husqvarna.glb +0 -0
  161. package/src/assets/husqvarna-instanced-meshes/main.ts +0 -108
  162. package/src/assets/index.html +0 -144
  163. package/src/assets/index.json +0 -9
  164. package/src/assets/linkeddups/example_2_instances.glb +0 -0
  165. package/src/assets/linkeddups/spec.ts +0 -32
  166. package/src/assets/molto-mova-multi-instance-shown-bug/main.ts +0 -106
  167. package/src/assets/molto-mova-multi-instance-shown-bug/molto-mova-rc82.glb +0 -0
  168. package/src/assets/molto-mova-multi-instance-shown-bug/molto-mova-volare.glb +0 -0
  169. package/src/assets/molto-mova-multi-instance-shown-bug/studio.env +0 -0
  170. package/src/assets/moltomova/10 environment.env +0 -0
  171. package/src/assets/moltomova/RC65.glb +0 -0
  172. package/src/assets/moltomova/RC82.glb +0 -0
  173. package/src/assets/moltomova/TPH67.glb +0 -0
  174. package/src/assets/moltomova/TPH82.glb +0 -0
  175. package/src/assets/moltomova/Volare.glb +0 -0
  176. package/src/assets/moltomova/moltomova-cl3d-spec-rc65.ts +0 -159
  177. package/src/assets/moltomova/moltomova-cl3d-spec-rc82.ts +0 -118
  178. package/src/assets/moltomova/moltomova-cl3d-spec-scene.ts +0 -57
  179. package/src/assets/moltomova/moltomova-cl3d-spec-tph67.ts +0 -199
  180. package/src/assets/moltomova/moltomova-cl3d-spec-tph82.ts +0 -173
  181. package/src/assets/moltomova/moltomova-cl3d-spec-volare65.ts +0 -173
  182. package/src/assets/moltomova/moltomova.ts +0 -175
  183. package/src/assets/mova.json +0 -18
  184. package/src/assets/mova_3_phase_rail.glb +0 -0
  185. package/src/assets/mova_3_phase_rail.json +0 -86
  186. package/src/assets/mova_recessed_luminaire.glb +0 -0
  187. package/src/assets/mova_recessed_luminaire.json +0 -81
  188. package/src/assets/nessie/gltf-test-no-material.gltf +0 -142
  189. package/src/assets/nessie/gltf-test-no-material_data.bin +0 -0
  190. package/src/assets/nessie/gltf-test-rotation.gltf +0 -142
  191. package/src/assets/nessie/gltf-test-rotation_data.bin +0 -0
  192. package/src/assets/nessie/gltf-test.gltf +0 -178
  193. package/src/assets/nessie/gltf-test_data.bin +0 -0
  194. package/src/assets/nessie/index.json +0 -9
  195. package/src/assets/nessie/nessie_basic.json +0 -24
  196. package/src/assets/nessie/setup.json +0 -12
  197. package/src/assets/scene.json +0 -64
  198. package/src/assets/setup.json +0 -25
  199. package/src/assets/small_cave_1k.hdr +0 -0
  200. package/src/assets/svgTo3D/09aJssVZrjk.env +0 -0
  201. package/src/assets/svgTo3D/09f0zfBQBWK.glb +0 -0
  202. package/src/assets/svgTo3D/9bae062709f8a7803769ba955cde3c4a.jpg +0 -0
  203. package/src/assets/svgTo3D/logo-cyledge.svg +0 -19
  204. package/src/assets/svgTo3D/spec.ts +0 -56
  205. package/src/assets/svgTo3D/svg_assets/09fmVjc59hQ.png +0 -0
  206. package/src/assets/svgTo3D/svg_assets/LDI2apCSOBg7S-QT7pb0EPOreec.woff2 +0 -0
  207. package/src/assets/svgTo3D/svg_assets/unineue_regular.woff2 +0 -0
  208. package/src/assets/svgTo3D/testCube.glb +0 -0
  209. package/src/assets/svgTo3D/testCube001.glb +0 -0
  210. package/src/assets/svgTo3D/testCubeSpec.ts +0 -49
  211. package/src/assets/textures/grass.png +0 -0
  212. package/src/assets/textures/seamless-grunge-scratched-texture.jpg +0 -0
@@ -0,0 +1,295 @@
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 '@babylonjs/loaders/glTF/2.0/Extensions/KHR_lights_punctual';
8
+ import { get, isEmpty, isString, set } from 'lodash-es';
9
+ import {
10
+ cloneNodeWithParents,
11
+ disableNodeWithParents,
12
+ enableNodeWithParents,
13
+ getRootNode
14
+ } from './../util/babylonHelper';
15
+ import { DottedPath } from './dottedPath';
16
+ import { Parameter } from './parameter';
17
+ import { Variant } from './variant';
18
+ import { VariantParameterizable } from './variantParameterizable';
19
+
20
+ /**
21
+ * A {@link ViewerLight} of a {@link Variant}. Acts as a container for BabylonJS lights. Lives only in the context of a
22
+ * {@link Variant}.
23
+ */
24
+ export class ViewerLight extends VariantParameterizable {
25
+
26
+ protected _light: Light | undefined;
27
+
28
+ /**
29
+ * Constructor.
30
+ */
31
+ protected constructor( public readonly variant: Variant,
32
+ public readonly name: string ) {
33
+ super( variant, name );
34
+ this.addParameterObservers();
35
+ }
36
+
37
+ /**
38
+ * Creates a {@link ViewerLight} with given name.
39
+ */
40
+ public static async create( variant: Variant, name: string ): Promise<ViewerLight> {
41
+ const viewerLight = new ViewerLight( variant, name );
42
+ viewerLight._light = await viewerLight.createBabylonLightFromDefinition( viewerLight.definition );
43
+ return viewerLight;
44
+ }
45
+
46
+ /**
47
+ * The wrapped Light.
48
+ */
49
+ get light(): Light {
50
+ if( !this._light ) {
51
+ throw new Error( `Light for ViewerLight "${this.name}" has not been properly initialized.` );
52
+ }
53
+ return this._light!;
54
+ }
55
+
56
+ /**
57
+ * The {@link DottedPath} in the built tree of {@link ViewerLight}s.
58
+ * E.g. "_.top-1.sub-2.sub-sub-3.el-1"
59
+ */
60
+ get dottedPath(): DottedPath {
61
+ return DottedPath.create( this.variant.dottedPath ).addPart( this.name );
62
+ }
63
+
64
+ /**
65
+ * The id representing a {@link DottedPath}.
66
+ */
67
+ get id(): string {
68
+ const dottedPath = DottedPath.create( this.dottedPath );
69
+ dottedPath.shiftPart(); // remove root
70
+ return dottedPath.path;
71
+ }
72
+
73
+ /**
74
+ * The {@link LightDefinition} of the {@link ViewerLight}.
75
+ */
76
+ get definition(): LightDefinition {
77
+ const definition = this.variant.structureJson.lights![this.name];
78
+ if( isString( definition ) ) {
79
+ return {
80
+ type: 'baked',
81
+ path: definition
82
+ } as LightDefinition;
83
+ }
84
+ return definition as LightDefinition;
85
+ }
86
+
87
+ /**
88
+ * The type of the {@link ViewerLight}'s light.
89
+ */
90
+ get type(): string {
91
+ return this.light.constructor.name.replace( /light/i, '' ).toLowerCase();
92
+ }
93
+
94
+ /**
95
+ * @see {@link VariantParameterizable.commitParameters}
96
+ * @emit {@link Event.VIEWER_LIGHT_PARAMETER_COMMITTED}
97
+ */
98
+ public async commitParameters( parameters?: ParameterBag ): Promise<VariantParameterizable> {
99
+ return super.commitParameters( parameters );
100
+ }
101
+
102
+ /**
103
+ * Adds the default {@link ParameterObserver}s which are called every time {@link commitParameters} is called.
104
+ */
105
+ protected addParameterObservers(): ViewerLight {
106
+ this._parameterObservers.set( Parameter.VISIBLE, [
107
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
108
+ let visible;
109
+ try {
110
+ visible = Parameter.parseBoolean( newValue );
111
+ } catch( e ) {
112
+ return;
113
+ }
114
+ if( visible === true ) {
115
+ enableNodeWithParents( light.light );
116
+ } else if( visible === false ) {
117
+ disableNodeWithParents( light.light );
118
+ }
119
+ }
120
+ ] );
121
+ this._parameterObservers.set( Parameter.INTENSITY, [
122
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
123
+ set( light.light, 'intensity', Parameter.parseNumber( newValue ) );
124
+ }
125
+ ] );
126
+ this._parameterObservers.set( Parameter.POSITION, [
127
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
128
+ const rootNode = getRootNode( light.light );
129
+ set( rootNode, 'position', Parameter.parseVector( newValue ) );
130
+ }
131
+ ] );
132
+ this._parameterObservers.set( Parameter.DIRECTION, [
133
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
134
+ if(
135
+ (light.light instanceof ShadowLight && !(light.light instanceof PointLight))
136
+ || light.light instanceof HemisphericLight
137
+ ) {
138
+ set( light.light, 'direction', Parameter.parseVector( newValue ) );
139
+ }
140
+ }
141
+ ] );
142
+ this._parameterObservers.set( Parameter.ANGLE, [
143
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
144
+ if( light.light.getClassName() === 'SpotLight' ) {
145
+ set( light.light, 'angle', Parameter.parseNumber( newValue ) );
146
+ }
147
+ }
148
+ ] );
149
+ this._parameterObservers.set( Parameter.EXPONENT, [
150
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
151
+ if( light.light.getClassName() === 'SpotLight' ) {
152
+ set( light.light, 'exponent', Parameter.parseNumber( newValue ) );
153
+ }
154
+ }
155
+ ] );
156
+ this._parameterObservers.set( Parameter.DIFFUSE, [
157
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
158
+ set( light.light, 'diffuse', Parameter.parseColor( newValue ) );
159
+ }
160
+ ] );
161
+ this._parameterObservers.set( Parameter.SPECULAR, [
162
+ async ( light: ViewerLight, oldValue: ParameterValue, newValue: ParameterValue ) => {
163
+ set( light.light, 'specular', Parameter.parseColor( newValue ) );
164
+ }
165
+ ] );
166
+ return this;
167
+ }
168
+
169
+ /**
170
+ * @param definition
171
+ * @protected
172
+ */
173
+ protected async createBabylonLightFromDefinition( definition: LightDefinition ): Promise<Light> {
174
+ const parameters = Parameter.parseFromDeclarations( Parameter.declarations, this.inheritedParameters );
175
+ const scene = this.variant.viewer.scene;
176
+ let lightId = this.id;
177
+ let babylonLight;
178
+ switch( definition.type ) {
179
+ case 'baked':
180
+ if( !definition['path'] ) {
181
+ throw new Error( `The light "${lightId}" of type "${definition.type}" needs a "path".` );
182
+ }
183
+ const bakedLight = this.variant.inheritedLights.find( l => l.metadata.dottedPath.path === definition['path'] );
184
+ if( bakedLight ) {
185
+ lightId = bakedLight.metadata.dottedPath.clone().unshiftPart( this.id ).path;
186
+ babylonLight = cloneNodeWithParents( bakedLight ) as Light;
187
+ babylonLight!.name = lightId;
188
+ babylonLight!.id = lightId;
189
+ } else {
190
+ throw new Error( `No light found for path "${definition['path']}" in ViewerLight "${lightId}".` );
191
+ }
192
+ break;
193
+ case 'hemispheric':
194
+ if( !parameters['direction'] ) {
195
+ throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".` );
196
+ }
197
+ // @ts-ignore
198
+ const hemisphericLightModule = await import(/* webpackChunkName: "hemispheric-light" */ '@babylonjs/core/Lights/hemisphericLight');
199
+ babylonLight = new hemisphericLightModule.HemisphericLight(
200
+ lightId,
201
+ parameters['direction'],
202
+ scene
203
+ );
204
+ break;
205
+ case 'point':
206
+ if( !parameters['position'] ) {
207
+ throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "position".` );
208
+ }
209
+ // @ts-ignore
210
+ const pointLightModule = await import(/* webpackChunkName: "point-light" */ '@babylonjs/core/Lights/pointLight');
211
+ babylonLight = new pointLightModule.PointLight(
212
+ lightId,
213
+ parameters['position'],
214
+ scene
215
+ );
216
+ break;
217
+ case 'directional':
218
+ if( !parameters['direction'] ) {
219
+ throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".` );
220
+ }
221
+ // @ts-ignore
222
+ const directionalLightModule = await import(/* webpackChunkName: "directional-light" */ '@babylonjs/core/Lights/directionalLight');
223
+ babylonLight = new directionalLightModule.DirectionalLight(
224
+ lightId,
225
+ parameters['direction'],
226
+ scene
227
+ );
228
+ break;
229
+ case 'spot':
230
+ if( !parameters['position'] ) {
231
+ throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "position".` );
232
+ }
233
+ if( !parameters['direction'] ) {
234
+ throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs a "direction".` );
235
+ }
236
+ if( !parameters['angle'] ) {
237
+ throw new Error( `A ViewerLight of type "${definition.type}" needs an "angle".` );
238
+ }
239
+ if( !parameters['exponent'] ) {
240
+ throw new Error( `The ViewerLight "${lightId}" of type "${definition.type}" needs an "exponent".` );
241
+ }
242
+ // @ts-ignore
243
+ const spotLightModule = await import(/* webpackChunkName: "spot-light" */ '@babylonjs/core/Lights/spotLight');
244
+ babylonLight = new spotLightModule.SpotLight(
245
+ lightId,
246
+ parameters['position'],
247
+ parameters['direction'],
248
+ parameters['angle'],
249
+ parameters['exponent'],
250
+ scene
251
+ );
252
+ break;
253
+ default:
254
+ throw new Error( `The type "${definition.type}" for ViewerLight "${lightId}" is not implemented (yet).` );
255
+ }
256
+ if( !babylonLight ) {
257
+ throw new Error( `The Light for ViewerLight "${lightId}" of type "${definition.type}" could no be created ` +
258
+ `or found.` );
259
+ }
260
+ // disable/hide by default
261
+ disableNodeWithParents( babylonLight );
262
+ // process shadow generator
263
+ const shadowGeneratorDefinition = get( definition, 'shadowGenerator' ) as ShadowGeneratorDefinition;
264
+ if( !isEmpty( shadowGeneratorDefinition ) ) {
265
+ if( !(babylonLight instanceof ShadowLight) ) {
266
+ throw new Error( `Using a ShadowGenerator with light type "${definition.type}" is not supported for ` +
267
+ `"${lightId}". Use lights deriving from ShadowLight.` );
268
+ }
269
+ await this.processShadowGenerator( babylonLight, shadowGeneratorDefinition );
270
+ }
271
+ return babylonLight;
272
+ };
273
+
274
+ /**
275
+ * @param babylonLight
276
+ * @param definition
277
+ * @protected
278
+ */
279
+ protected async processShadowGenerator( babylonLight: ShadowLight,
280
+ definition: ShadowGeneratorDefinition ): Promise<ShadowGenerator> {
281
+ const parameterDeclarations: ParameterDeclarations = {};
282
+ // define declarations here if needed in future
283
+ const parameterBag = definition as {} as ParameterBag;
284
+ const parameters = Parameter.parseFromDeclarations( parameterDeclarations, parameterBag );
285
+ const shadowGenerator = new ShadowGenerator( parameters['mapSize'], babylonLight );
286
+ for( const parameter in parameters ) {
287
+ if( parameter === 'mapSize' ) {
288
+ continue;
289
+ }
290
+ set( shadowGenerator, parameter, get( parameters, parameter ) );
291
+ }
292
+ return shadowGenerator;
293
+ };
294
+
295
+ }
@@ -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 };