@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
@@ -1,270 +1,408 @@
1
- import { Color3 } from '@babylonjs/core/Maths/math.color';
2
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
3
- import { isNumber, isString } from 'lodash-es';
4
-
5
-
6
- /**
7
- * This `Parameter` class defines all parameters that can be consumed and committed by a {@link ParameterObservable}.
8
- * Use {@link ParameterObservable.addParameterObserver} or {@link ParameterObservable.commitParameters} to either add or
9
- * commit parameters on your observable objects.
10
- */
11
- export class Parameter {
12
-
13
- /**
14
- * Constructor.
15
- */
16
- private constructor() {}
17
-
18
- /**
19
- * Mutates the visibility. Helper methods are {@link ElementParameterizable.show} and
20
- * {@link ElementParameterizable.hide}. Getter and setter is {@link ElementParameterizable.visible}.
21
- *
22
- * Scopes:
23
- * * {@link Element}
24
- * * {@link Variant}
25
- *
26
- * @parser {@link parseBoolean}
27
- */
28
- public static readonly VISIBLE = 'visible';
29
-
30
- /**
31
- * Stretches or compresses some meshes. Getter and setter is {@link ElementParameterizable.scaling}.
32
- *
33
- * Scopes:
34
- * * {@link Element}
35
- * * {@link Variant}
36
- *
37
- * @parser {@link parseScaling}
38
- */
39
- public static readonly SCALING = 'scaling';
40
-
41
- /**
42
- * Mutates the material. Getter and setter is {@link ElementParameterizable.material}. The value of this parameter
43
- * represents the ID of a baked-in glTF or custom created material in the {@link Variant} tree.
44
- *
45
- * Scopes:
46
- * * {@link Element}
47
- * * {@link Variant}
48
- *
49
- * @parser string
50
- */
51
- public static readonly MATERIAL = 'material';
52
-
53
- /**
54
- * Mutates the material color.
55
- *
56
- * Scopes:
57
- * * {@link Element}
58
- * * {@link Variant}
59
- *
60
- * @parser {@link parseColor}
61
- */
62
- public static readonly MATERIAL_COLOR = 'material.color';
63
-
64
- /**
65
- * Mutates the material metallness.
66
- *
67
- * Scopes:
68
- * * {@link Element}
69
- * * {@link Variant}
70
- *
71
- * @parser {@link parseNumber}
72
- */
73
- public static readonly MATERIAL_METALLNESS = 'material.metallness';
74
-
75
- /**
76
- * Mutates the material roughness.
77
- *
78
- * Scopes:
79
- * * {@link Element}
80
- * * {@link Variant}
81
- *
82
- * @parser {@link parseNumber}
83
- */
84
- public static readonly MATERIAL_ROUGHNESS = 'material.roughness';
85
-
86
- /**
87
- * Mutates whether a highlight layer should be enabled.
88
- *
89
- * Scopes:
90
- * * {@link Element}
91
- * * {@link Variant}
92
- *
93
- * @parser {@link parseBoolean}
94
- */
95
- public static readonly HIGHLIGHT_ENABLED = 'highlight.enabled';
96
-
97
- /**
98
- * Changes the highlight color.
99
- *
100
- * Scopes:
101
- * * {@link Element}
102
- * * {@link Variant}
103
- *
104
- * @parser {@link parseColor}
105
- */
106
- public static readonly HIGHLIGHT_COLOR = 'highlight.color';
107
-
108
- /**
109
- * Mutates the highlighted state. Getter and setter is {@link ElementParameterizable.highlighted}.
110
- *
111
- * Scopes:
112
- * * {@link Element}
113
- * * {@link Variant}
114
- *
115
- * @parser {@link parseBoolean}
116
- */
117
- public static readonly HIGHLIGHTED = 'highlighted';
118
-
119
- /**
120
- * Mutates the position relative to its origin position. Getter and setter is {@link ElementParameterizable.position}.
121
- *
122
- * Scopes:
123
- * * {@link Element}
124
- * * {@link Variant}
125
- *
126
- * @parser {@link parseVector}
127
- */
128
- public static readonly POSITION = 'position';
129
-
130
- /**
131
- * Mutates the rotation relative to its origin rotation. Getter and setter is {@link ElementParameterizable.rotation}.
132
- *
133
- * Scopes:
134
- * * {@link Element}
135
- * * {@link Variant}
136
- *
137
- * @parser {@link parseRotation}
138
- */
139
- public static readonly ROTATION = 'rotation';
140
-
141
- /**
142
- * The {@link ParameterDeclarations} for all parameters in this class.
143
- */
144
- public static get declarations(): ParameterDeclarations {
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;
159
- }
160
-
161
- /**
162
- * Gets the {@link ParameterDeclaration} for a given {@link Parameter} declared in this class.
163
- */
164
- public static getDeclaration(parameter: string): ParameterDeclaration {
165
- return Parameter.declarations[parameter];
166
- }
167
-
168
- /**
169
- * All parameters defined in this class.
170
- */
171
- public static get all() {
172
- const all: string[] = [];
173
- for( const parameter in Parameter ) {
174
- const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
175
- if( parameter.toUpperCase() === parameter && property && isString( property.value ) ) {
176
- all.push( property.value );
177
- }
178
- }
179
- return all;
180
- }
181
-
182
- /**
183
- * Parses a string of format `'(x,y,z)'` to a `Vector3`.
184
- */
185
- public static parseVector( value: ParameterValue ): Vector3 {
186
- if( !isString( value ) ) {
187
- throw new Error( `Unable to convert "${value}" into a Vector: not a string.` );
188
- }
189
- let cleanedValue = value.split( ' ' ).join( '' );
190
- if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
191
- cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
192
- let [x, y, z] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
193
- return new Vector3( x, y, z );
194
- } else {
195
- throw new Error( `Unable to parse "${value}" to a Vector: expected "(x,y,z)".` );
196
- }
197
- }
198
-
199
- /**
200
- * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
201
- */
202
- public static parseRotation( value: ParameterValue ): Vector3 {
203
- const rotation = Parameter.parseVector( value );
204
- const deg2rad = function( deg: number ) {
205
- return deg * Math.PI / 180;
206
- };
207
- return rotation.set(
208
- deg2rad( rotation.x ),
209
- deg2rad( rotation.y ),
210
- deg2rad( rotation.z )
211
- );
212
- }
213
-
214
- /**
215
- * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
216
- */
217
- public static parseScaling( value: ParameterValue ): Vector3 {
218
- let scaling = new Vector3();
219
- if( isString( value ) ) {
220
- const cleanedFactor = value.split( ' ' ).join( '' );
221
- if( cleanedFactor.startsWith( '(' ) && cleanedFactor.endsWith( ')' ) ) {
222
- scaling = Parameter.parseVector( cleanedFactor );
223
- } else {
224
- const _factor = parseFloat( value );
225
- scaling = new Vector3( _factor, _factor, _factor );
226
- }
227
- } else if( isNumber( value ) ) {
228
- scaling = new Vector3( value, value, value );
229
- } else {
230
- throw new Error( `Unable to convert "${value}" to a Vector: expected "(x,y,z)".` );
231
- }
232
- return scaling;
233
- }
234
-
235
- /**
236
- * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
237
- */
238
- public static parseColor( value: ParameterValue ): Color3 {
239
- let cleanedValue = value.toString().split( ' ' ).join( '' );
240
- if( cleanedValue.startsWith( '#' ) ) {
241
- return Color3.FromHexString( value.toString() );
242
- }
243
- if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
244
- cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
245
- let [r, g, b] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
246
- return Color3.FromInts( r, g, b );
247
- }
248
- throw new Error( `Unable to parse "${value}" to a Color: expected "#rrggbb" or "(r,g,b)".` );
249
- }
250
-
251
- /**
252
- * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or `undefined`.
253
- */
254
- public static parseBoolean( value: ParameterValue ): boolean {
255
- if( value.toString() === 'true' || value.toString() === '1' ) {
256
- return true;
257
- } else if( value.toString() === 'false' || value.toString() === '0' ) {
258
- return false;
259
- }
260
- throw new Error( `Unable to parse "${value}" to a boolean.` );
261
- }
262
-
263
- /**
264
- * Parses a number `string` to a `number`.
265
- */
266
- public static parseNumber( value: ParameterValue ): number {
267
- return parseFloat( value.toString() );
268
- }
269
-
270
- }
1
+ import { Color3 } from '@babylonjs/core/Maths/math.color';
2
+ import { Vector3 } from '@babylonjs/core/Maths/math.vector';
3
+ import { get, isEmpty, isNumber, isString } from 'lodash-es';
4
+
5
+
6
+ /**
7
+ * This `Parameter` class defines all parameters that can be consumed and committed by a {@link ParameterObservable}.
8
+ * Use {@link ParameterObservable.addParameterObserver} or {@link ParameterObservable.commitParameters} to either add or
9
+ * commit parameters on your observable objects.
10
+ */
11
+ export class Parameter {
12
+
13
+ /**
14
+ * Constructor.
15
+ */
16
+ private constructor() {}
17
+
18
+ /**
19
+ * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
20
+ * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
21
+ *
22
+ * Scopes:
23
+ * * {@link Element}
24
+ * * {@link Variant}
25
+ * * {@link ViewerLight} Available for all light types
26
+ *
27
+ * @parser {@link parseBoolean}
28
+ */
29
+ public static readonly VISIBLE = 'visible';
30
+
31
+ /**
32
+ * Stretches or compresses some meshes. Getter and setter is {@link VariantParameterizable.scaling}.
33
+ *
34
+ * Scopes:
35
+ * * {@link Element}
36
+ * * {@link Variant}
37
+ *
38
+ * @parser {@link parseScaling}
39
+ */
40
+ public static readonly SCALING = 'scaling';
41
+
42
+ /**
43
+ * Mutates the material. Getter and setter is {@link VariantParameterizable.material}. The value of this parameter
44
+ * represents the ID of a baked-in glTF or custom created material in the {@link Variant} tree.
45
+ *
46
+ * Scopes:
47
+ * * {@link Element}
48
+ * * {@link Variant}
49
+ *
50
+ * @parser string
51
+ */
52
+ public static readonly MATERIAL = 'material';
53
+
54
+ /**
55
+ * Mutates the material color.
56
+ *
57
+ * Scopes:
58
+ * * {@link Element}
59
+ * * {@link Variant}
60
+ *
61
+ * @parser {@link parseColor}
62
+ */
63
+ public static readonly MATERIAL_COLOR = 'material.color';
64
+
65
+ /**
66
+ * Mutates the material metallness.
67
+ *
68
+ * Scopes:
69
+ * * {@link Element}
70
+ * * {@link Variant}
71
+ *
72
+ * @parser {@link parseNumber}
73
+ */
74
+ public static readonly MATERIAL_METALLNESS = 'material.metallness';
75
+
76
+ /**
77
+ * Mutates the material roughness.
78
+ *
79
+ * Scopes:
80
+ * * {@link Element}
81
+ * * {@link Variant}
82
+ *
83
+ * @parser {@link parseNumber}
84
+ */
85
+ public static readonly MATERIAL_ROUGHNESS = 'material.roughness';
86
+
87
+ /**
88
+ * Mutates whether a highlight layer should be enabled.
89
+ *
90
+ * Scopes:
91
+ * * {@link Element}
92
+ * * {@link Variant}
93
+ *
94
+ * @parser {@link parseBoolean}
95
+ */
96
+ public static readonly HIGHLIGHT_ENABLED = 'highlight.enabled';
97
+
98
+ /**
99
+ * Changes the highlight color.
100
+ *
101
+ * Scopes:
102
+ * * {@link Element}
103
+ * * {@link Variant}
104
+ *
105
+ * @parser {@link parseColor}
106
+ */
107
+ public static readonly HIGHLIGHT_COLOR = 'highlight.color';
108
+
109
+ /**
110
+ * Mutates the highlighted state. Getter and setter is {@link VariantParameterizable.highlighted}.
111
+ *
112
+ * Scopes:
113
+ * * {@link Element}
114
+ * * {@link Variant}
115
+ *
116
+ * @parser {@link parseBoolean}
117
+ */
118
+ public static readonly HIGHLIGHTED = 'highlighted';
119
+
120
+ /**
121
+ * Mutates the position relative to its origin position. Getter and setter is {@link VariantParameterizable.position}.
122
+ *
123
+ * Scopes:
124
+ * * {@link Element}
125
+ * * {@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
+ *
128
+ * @parser {@link parseVector}
129
+ */
130
+ public static readonly POSITION = 'position';
131
+
132
+ /**
133
+ * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
134
+ *
135
+ * Scopes:
136
+ * * {@link Element}
137
+ * * {@link Variant}
138
+ *
139
+ * @parser {@link parseRotation}
140
+ */
141
+ public static readonly ROTATION = 'rotation';
142
+
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
+ /**
237
+ * The {@link ParameterDeclarations} for all parameters in this class.
238
+ */
239
+ public static get declarations(): ParameterDeclarations {
240
+ const declarations: ParameterDeclarations = {};
241
+ declarations[Parameter.VISIBLE] = { type: 'boolean', parser: Parameter.parseBoolean };
242
+ declarations[Parameter.SCALING] = { type: 'number', parser: Parameter.parseNumber };
243
+ declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
244
+ declarations[Parameter.MATERIAL] = { type: 'string' };
245
+ declarations[Parameter.MATERIAL_COLOR] = { type: 'color', parser: Parameter.parseColor };
246
+ declarations[Parameter.MATERIAL_METALLNESS] = { type: 'number', parser: Parameter.parseNumber };
247
+ declarations[Parameter.MATERIAL_ROUGHNESS] = { type: 'number', parser: Parameter.parseNumber };
248
+ declarations[Parameter.HIGHLIGHT_ENABLED] = { type: 'boolean', parser: Parameter.parseBoolean };
249
+ declarations[Parameter.HIGHLIGHT_COLOR] = { type: 'color', parser: Parameter.parseColor };
250
+ declarations[Parameter.HIGHLIGHTED] = { type: 'boolean', parser: Parameter.parseBoolean };
251
+ declarations[Parameter.POSITION] = { type: 'vector', parser: Parameter.parseVector };
252
+ declarations[Parameter.ROTATION] = { type: 'vector', parser: Parameter.parseVector };
253
+ declarations[Parameter.CAST_SHADOW] = { type: 'boolean', parser: Parameter.parseBoolean };
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;
263
+ }
264
+
265
+ /**
266
+ * Gets the {@link ParameterDeclaration} for a given {@link Parameter} declared in this class.
267
+ */
268
+ public static getDeclaration(parameter: string): ParameterDeclaration {
269
+ return Parameter.declarations[parameter];
270
+ }
271
+
272
+ /**
273
+ * All parameters defined in this class.
274
+ */
275
+ public static get all() {
276
+ const all: string[] = [];
277
+ for( const parameter in Parameter ) {
278
+ const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
279
+ if( parameter.toUpperCase() === parameter && property && isString( property.value ) ) {
280
+ all.push( property.value );
281
+ }
282
+ }
283
+ return all;
284
+ }
285
+
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
+ /**
305
+ * Parses a string of format `'(x,y,z)'` to a `Vector3`.
306
+ */
307
+ public static parseVector( value: ParameterValue ): Vector3 {
308
+ if( !isString( value ) ) {
309
+ throw new Error( `Unable to convert "${value}" into a Vector: not a string.` );
310
+ }
311
+ let cleanedValue = value.split( ' ' ).join( '' );
312
+ if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
313
+ cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
314
+ let [x, y, z] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
315
+ return new Vector3( x, y, z );
316
+ } else {
317
+ throw new Error( `Unable to parse "${value}" to a Vector: expected "(x,y,z)".` );
318
+ }
319
+ }
320
+
321
+ /**
322
+ * Stringifies a Vector3 to format `(x,y,z)`.
323
+ */
324
+ public static stringifyVector( value: Vector3 ): string {
325
+ return `(${value.x},${value.y},${value.z})`;
326
+ }
327
+
328
+ /**
329
+ * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
330
+ */
331
+ public static parseRotation( value: ParameterValue ): Vector3 {
332
+ const rotation = Parameter.parseVector( value );
333
+ const deg2rad = function( deg: number ) {
334
+ return deg * Math.PI / 180;
335
+ };
336
+ return rotation.set(
337
+ deg2rad( rotation.x ),
338
+ deg2rad( rotation.y ),
339
+ deg2rad( rotation.z )
340
+ );
341
+ }
342
+
343
+ /**
344
+ * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
345
+ */
346
+ public static parseScaling( value: ParameterValue ): Vector3 {
347
+ let scaling = new Vector3();
348
+ if( isString( value ) ) {
349
+ const cleanedFactor = value.split( ' ' ).join( '' );
350
+ if( cleanedFactor.startsWith( '(' ) && cleanedFactor.endsWith( ')' ) ) {
351
+ scaling = Parameter.parseVector( cleanedFactor );
352
+ } else {
353
+ const _factor = parseFloat( value );
354
+ scaling = new Vector3( _factor, _factor, _factor );
355
+ }
356
+ } else if( isNumber( value ) ) {
357
+ scaling = new Vector3( value, value, value );
358
+ } else {
359
+ throw new Error( `Unable to convert "${value}" to a Vector: expected "(x,y,z)".` );
360
+ }
361
+ return scaling;
362
+ }
363
+
364
+ /**
365
+ * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
366
+ */
367
+ public static parseColor( value: ParameterValue ): Color3 {
368
+ let cleanedValue = value.toString().split( ' ' ).join( '' );
369
+ if( cleanedValue.startsWith( '#' ) ) {
370
+ return Color3.FromHexString( value.toString() );
371
+ }
372
+ if( cleanedValue.startsWith( '(' ) && cleanedValue.endsWith( ')' ) ) {
373
+ cleanedValue = cleanedValue.substring( 1, cleanedValue.length - 1 );
374
+ let [r, g, b] = cleanedValue.split( ',' ).map( value => parseFloat( value ) );
375
+ return Color3.FromInts( r, g, b );
376
+ }
377
+ throw new Error( `Unable to parse "${value}" to a Color: expected "#rrggbb" or "(r,g,b)".` );
378
+ }
379
+
380
+ /**
381
+ * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or `undefined`.
382
+ */
383
+ public static parseBoolean( value: ParameterValue ): boolean {
384
+ if( value.toString() === 'true' || value.toString() === '1' ) {
385
+ return true;
386
+ } else if( value.toString() === 'false' || value.toString() === '0' ) {
387
+ return false;
388
+ }
389
+ throw new Error( `Unable to parse "${value}" to a boolean.` );
390
+ }
391
+
392
+ /**
393
+ * Parses a number `string` to a `number`.
394
+ */
395
+ public static parseNumber( value: ParameterValue ): number {
396
+ return parseFloat( value.toString() );
397
+ }
398
+
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
+ }