@combeenation/3d-viewer 12.4.1 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dist/lib-cjs/buildinfo.json +1 -1
  2. package/dist/lib-cjs/commonjs.tsconfig.tsbuildinfo +1 -1
  3. package/dist/lib-cjs/index.d.ts +63 -63
  4. package/dist/lib-cjs/index.js +81 -114
  5. package/dist/lib-cjs/index.js.map +1 -1
  6. package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.d.ts +10 -0
  7. package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js +124 -0
  8. package/dist/lib-cjs/internal/cbnCustomBabylonLoaderPlugin.js.map +1 -0
  9. package/dist/lib-cjs/internal/cloningHelper.d.ts +19 -0
  10. package/dist/lib-cjs/internal/cloningHelper.js +165 -0
  11. package/dist/lib-cjs/internal/cloningHelper.js.map +1 -0
  12. package/dist/lib-cjs/internal/deviceHelper.d.ts +9 -0
  13. package/dist/lib-cjs/{api/util → internal}/deviceHelper.js +6 -10
  14. package/dist/lib-cjs/internal/deviceHelper.js.map +1 -0
  15. package/dist/lib-cjs/internal/geometryHelper.d.ts +21 -0
  16. package/dist/lib-cjs/{api/util → internal}/geometryHelper.js +57 -24
  17. package/dist/lib-cjs/internal/geometryHelper.js.map +1 -0
  18. package/dist/lib-cjs/internal/metadataHelper.d.ts +26 -0
  19. package/dist/lib-cjs/internal/metadataHelper.js +51 -0
  20. package/dist/lib-cjs/internal/metadataHelper.js.map +1 -0
  21. package/dist/lib-cjs/internal/paintableHelper.d.ts +40 -0
  22. package/dist/lib-cjs/internal/paintableHelper.js +287 -0
  23. package/dist/lib-cjs/internal/paintableHelper.js.map +1 -0
  24. package/dist/lib-cjs/internal/tagsHelper.d.ts +12 -0
  25. package/dist/lib-cjs/internal/tagsHelper.js +38 -0
  26. package/dist/lib-cjs/internal/tagsHelper.js.map +1 -0
  27. package/dist/lib-cjs/manager/cameraManager.d.ts +51 -0
  28. package/dist/lib-cjs/manager/cameraManager.js +154 -0
  29. package/dist/lib-cjs/manager/cameraManager.js.map +1 -0
  30. package/dist/lib-cjs/manager/debugManager.d.ts +60 -0
  31. package/dist/lib-cjs/manager/debugManager.js +218 -0
  32. package/dist/lib-cjs/manager/debugManager.js.map +1 -0
  33. package/dist/lib-cjs/manager/eventManager.d.ts +52 -0
  34. package/dist/lib-cjs/manager/eventManager.js +72 -0
  35. package/dist/lib-cjs/manager/eventManager.js.map +1 -0
  36. package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.d.ts +29 -34
  37. package/dist/lib-cjs/{api/manager → manager}/gltfExportManager.js +99 -120
  38. package/dist/lib-cjs/manager/gltfExportManager.js.map +1 -0
  39. package/dist/lib-cjs/manager/materialManager.d.ts +35 -0
  40. package/dist/lib-cjs/manager/materialManager.js +126 -0
  41. package/dist/lib-cjs/manager/materialManager.js.map +1 -0
  42. package/dist/lib-cjs/manager/modelManager.d.ts +145 -0
  43. package/dist/lib-cjs/manager/modelManager.js +381 -0
  44. package/dist/lib-cjs/manager/modelManager.js.map +1 -0
  45. package/dist/lib-cjs/manager/parameterManager.d.ts +210 -0
  46. package/dist/lib-cjs/manager/parameterManager.js +515 -0
  47. package/dist/lib-cjs/manager/parameterManager.js.map +1 -0
  48. package/dist/lib-cjs/manager/sceneManager.d.ts +45 -0
  49. package/dist/lib-cjs/manager/sceneManager.js +65 -0
  50. package/dist/lib-cjs/manager/sceneManager.js.map +1 -0
  51. package/dist/lib-cjs/manager/screenshotManager.d.ts +36 -0
  52. package/dist/lib-cjs/manager/screenshotManager.js +40 -0
  53. package/dist/lib-cjs/manager/screenshotManager.js.map +1 -0
  54. package/dist/lib-cjs/manager/textureManager.d.ts +12 -0
  55. package/dist/lib-cjs/manager/textureManager.js +44 -0
  56. package/dist/lib-cjs/manager/textureManager.js.map +1 -0
  57. package/dist/lib-cjs/viewer.d.ts +117 -0
  58. package/dist/lib-cjs/viewer.js +222 -0
  59. package/dist/lib-cjs/viewer.js.map +1 -0
  60. package/dist/lib-cjs/{api/classes/viewerError.d.ts → viewerError.d.ts} +6 -1
  61. package/dist/lib-cjs/{api/classes/viewerError.js → viewerError.js} +6 -1
  62. package/dist/lib-cjs/viewerError.js.map +1 -0
  63. package/package.json +10 -11
  64. package/src/dev.ts +14 -37
  65. package/src/{types.d.ts → globalTypes.d.ts} +8 -18
  66. package/src/index.ts +79 -113
  67. package/src/internal/cbnCustomBabylonLoaderPlugin.ts +149 -0
  68. package/src/internal/cloningHelper.ts +225 -0
  69. package/src/internal/deviceHelper.ts +25 -0
  70. package/src/{api/util → internal}/geometryHelper.ts +63 -24
  71. package/src/internal/metadataHelper.ts +63 -0
  72. package/src/internal/paintableHelper.ts +310 -0
  73. package/src/internal/tagsHelper.ts +41 -0
  74. package/src/manager/cameraManager.ts +236 -0
  75. package/src/manager/debugManager.ts +245 -0
  76. package/src/manager/eventManager.ts +72 -0
  77. package/src/{api/manager → manager}/gltfExportManager.ts +132 -125
  78. package/src/manager/materialManager.ts +135 -0
  79. package/src/manager/modelManager.ts +456 -0
  80. package/src/manager/parameterManager.ts +652 -0
  81. package/src/manager/sceneManager.ts +101 -0
  82. package/src/manager/screenshotManager.ts +59 -0
  83. package/src/manager/textureManager.ts +32 -0
  84. package/src/viewer.ts +296 -0
  85. package/src/{api/classes/viewerError.ts → viewerError.ts} +6 -1
  86. package/dist/lib-cjs/api/classes/animationInterface.d.ts +0 -8
  87. package/dist/lib-cjs/api/classes/animationInterface.js +0 -3
  88. package/dist/lib-cjs/api/classes/animationInterface.js.map +0 -1
  89. package/dist/lib-cjs/api/classes/dottedPath.d.ts +0 -79
  90. package/dist/lib-cjs/api/classes/dottedPath.js +0 -167
  91. package/dist/lib-cjs/api/classes/dottedPath.js.map +0 -1
  92. package/dist/lib-cjs/api/classes/element.d.ts +0 -153
  93. package/dist/lib-cjs/api/classes/element.js +0 -703
  94. package/dist/lib-cjs/api/classes/element.js.map +0 -1
  95. package/dist/lib-cjs/api/classes/event.d.ts +0 -401
  96. package/dist/lib-cjs/api/classes/event.js +0 -425
  97. package/dist/lib-cjs/api/classes/event.js.map +0 -1
  98. package/dist/lib-cjs/api/classes/eventBroadcaster.d.ts +0 -26
  99. package/dist/lib-cjs/api/classes/eventBroadcaster.js +0 -50
  100. package/dist/lib-cjs/api/classes/eventBroadcaster.js.map +0 -1
  101. package/dist/lib-cjs/api/classes/fuzzyMap.d.ts +0 -7
  102. package/dist/lib-cjs/api/classes/fuzzyMap.js +0 -22
  103. package/dist/lib-cjs/api/classes/fuzzyMap.js.map +0 -1
  104. package/dist/lib-cjs/api/classes/parameter.d.ts +0 -410
  105. package/dist/lib-cjs/api/classes/parameter.js +0 -643
  106. package/dist/lib-cjs/api/classes/parameter.js.map +0 -1
  107. package/dist/lib-cjs/api/classes/parameterObservable.d.ts +0 -36
  108. package/dist/lib-cjs/api/classes/parameterObservable.js +0 -73
  109. package/dist/lib-cjs/api/classes/parameterObservable.js.map +0 -1
  110. package/dist/lib-cjs/api/classes/parameterizable.d.ts +0 -15
  111. package/dist/lib-cjs/api/classes/parameterizable.js +0 -103
  112. package/dist/lib-cjs/api/classes/parameterizable.js.map +0 -1
  113. package/dist/lib-cjs/api/classes/placementAnimation.d.ts +0 -45
  114. package/dist/lib-cjs/api/classes/placementAnimation.js +0 -177
  115. package/dist/lib-cjs/api/classes/placementAnimation.js.map +0 -1
  116. package/dist/lib-cjs/api/classes/variant.d.ts +0 -261
  117. package/dist/lib-cjs/api/classes/variant.js +0 -873
  118. package/dist/lib-cjs/api/classes/variant.js.map +0 -1
  119. package/dist/lib-cjs/api/classes/variantInstance.d.ts +0 -53
  120. package/dist/lib-cjs/api/classes/variantInstance.js +0 -126
  121. package/dist/lib-cjs/api/classes/variantInstance.js.map +0 -1
  122. package/dist/lib-cjs/api/classes/variantParameterizable.d.ts +0 -17
  123. package/dist/lib-cjs/api/classes/variantParameterizable.js +0 -87
  124. package/dist/lib-cjs/api/classes/variantParameterizable.js.map +0 -1
  125. package/dist/lib-cjs/api/classes/viewer.d.ts +0 -215
  126. package/dist/lib-cjs/api/classes/viewer.js +0 -709
  127. package/dist/lib-cjs/api/classes/viewer.js.map +0 -1
  128. package/dist/lib-cjs/api/classes/viewerError.js.map +0 -1
  129. package/dist/lib-cjs/api/classes/viewerLight.d.ts +0 -66
  130. package/dist/lib-cjs/api/classes/viewerLight.js +0 -345
  131. package/dist/lib-cjs/api/classes/viewerLight.js.map +0 -1
  132. package/dist/lib-cjs/api/internal/lensRendering.d.ts +0 -8
  133. package/dist/lib-cjs/api/internal/lensRendering.js +0 -12
  134. package/dist/lib-cjs/api/internal/lensRendering.js.map +0 -1
  135. package/dist/lib-cjs/api/internal/sceneSetup.d.ts +0 -13
  136. package/dist/lib-cjs/api/internal/sceneSetup.js +0 -228
  137. package/dist/lib-cjs/api/internal/sceneSetup.js.map +0 -1
  138. package/dist/lib-cjs/api/manager/animationManager.d.ts +0 -30
  139. package/dist/lib-cjs/api/manager/animationManager.js +0 -127
  140. package/dist/lib-cjs/api/manager/animationManager.js.map +0 -1
  141. package/dist/lib-cjs/api/manager/gltfExportManager.js.map +0 -1
  142. package/dist/lib-cjs/api/manager/sceneManager.d.ts +0 -33
  143. package/dist/lib-cjs/api/manager/sceneManager.js +0 -129
  144. package/dist/lib-cjs/api/manager/sceneManager.js.map +0 -1
  145. package/dist/lib-cjs/api/manager/tagManager.d.ts +0 -118
  146. package/dist/lib-cjs/api/manager/tagManager.js +0 -531
  147. package/dist/lib-cjs/api/manager/tagManager.js.map +0 -1
  148. package/dist/lib-cjs/api/manager/textureLoadManager.d.ts +0 -22
  149. package/dist/lib-cjs/api/manager/textureLoadManager.js +0 -108
  150. package/dist/lib-cjs/api/manager/textureLoadManager.js.map +0 -1
  151. package/dist/lib-cjs/api/manager/variantInstanceManager.d.ts +0 -106
  152. package/dist/lib-cjs/api/manager/variantInstanceManager.js +0 -291
  153. package/dist/lib-cjs/api/manager/variantInstanceManager.js.map +0 -1
  154. package/dist/lib-cjs/api/store/specStorage.d.ts +0 -32
  155. package/dist/lib-cjs/api/store/specStorage.js +0 -66
  156. package/dist/lib-cjs/api/store/specStorage.js.map +0 -1
  157. package/dist/lib-cjs/api/util/babylonHelper.d.ts +0 -238
  158. package/dist/lib-cjs/api/util/babylonHelper.js +0 -826
  159. package/dist/lib-cjs/api/util/babylonHelper.js.map +0 -1
  160. package/dist/lib-cjs/api/util/debugHelper.d.ts +0 -9
  161. package/dist/lib-cjs/api/util/debugHelper.js +0 -94
  162. package/dist/lib-cjs/api/util/debugHelper.js.map +0 -1
  163. package/dist/lib-cjs/api/util/deviceHelper.d.ts +0 -9
  164. package/dist/lib-cjs/api/util/deviceHelper.js.map +0 -1
  165. package/dist/lib-cjs/api/util/geometryHelper.d.ts +0 -17
  166. package/dist/lib-cjs/api/util/geometryHelper.js.map +0 -1
  167. package/dist/lib-cjs/api/util/globalTypes.d.ts +0 -490
  168. package/dist/lib-cjs/api/util/globalTypes.js +0 -2
  169. package/dist/lib-cjs/api/util/globalTypes.js.map +0 -1
  170. package/dist/lib-cjs/api/util/resourceHelper.d.ts +0 -58
  171. package/dist/lib-cjs/api/util/resourceHelper.js +0 -215
  172. package/dist/lib-cjs/api/util/resourceHelper.js.map +0 -1
  173. package/dist/lib-cjs/api/util/sceneLoaderHelper.d.ts +0 -58
  174. package/dist/lib-cjs/api/util/sceneLoaderHelper.js +0 -229
  175. package/dist/lib-cjs/api/util/sceneLoaderHelper.js.map +0 -1
  176. package/dist/lib-cjs/api/util/stringHelper.d.ts +0 -13
  177. package/dist/lib-cjs/api/util/stringHelper.js +0 -33
  178. package/dist/lib-cjs/api/util/stringHelper.js.map +0 -1
  179. package/dist/lib-cjs/api/util/structureHelper.d.ts +0 -9
  180. package/dist/lib-cjs/api/util/structureHelper.js +0 -58
  181. package/dist/lib-cjs/api/util/structureHelper.js.map +0 -1
  182. package/src/api/classes/animationInterface.ts +0 -10
  183. package/src/api/classes/dottedPath.ts +0 -181
  184. package/src/api/classes/element.ts +0 -766
  185. package/src/api/classes/event.ts +0 -457
  186. package/src/api/classes/eventBroadcaster.ts +0 -52
  187. package/src/api/classes/fuzzyMap.ts +0 -21
  188. package/src/api/classes/parameter.ts +0 -686
  189. package/src/api/classes/parameterObservable.ts +0 -73
  190. package/src/api/classes/parameterizable.ts +0 -87
  191. package/src/api/classes/placementAnimation.ts +0 -162
  192. package/src/api/classes/variant.ts +0 -965
  193. package/src/api/classes/variantInstance.ts +0 -123
  194. package/src/api/classes/variantParameterizable.ts +0 -83
  195. package/src/api/classes/viewer.ts +0 -751
  196. package/src/api/classes/viewerLight.ts +0 -335
  197. package/src/api/internal/debugViewer.ts +0 -90
  198. package/src/api/internal/lensRendering.ts +0 -9
  199. package/src/api/internal/sceneSetup.ts +0 -208
  200. package/src/api/manager/animationManager.ts +0 -143
  201. package/src/api/manager/sceneManager.ts +0 -134
  202. package/src/api/manager/tagManager.ts +0 -572
  203. package/src/api/manager/textureLoadManager.ts +0 -107
  204. package/src/api/manager/variantInstanceManager.ts +0 -306
  205. package/src/api/store/specStorage.ts +0 -68
  206. package/src/api/util/babylonHelper.ts +0 -915
  207. package/src/api/util/debugHelper.ts +0 -121
  208. package/src/api/util/deviceHelper.ts +0 -31
  209. package/src/api/util/globalTypes.ts +0 -566
  210. package/src/api/util/resourceHelper.ts +0 -201
  211. package/src/api/util/sceneLoaderHelper.ts +0 -247
  212. package/src/api/util/stringHelper.ts +0 -30
  213. package/src/api/util/structureHelper.ts +0 -62
@@ -1,686 +0,0 @@
1
- import { ViewerError, ViewerErrorIds } from './viewerError';
2
- import { Color3 } from '@babylonjs/core/Maths/math.color';
3
- import { Vector3 } from '@babylonjs/core/Maths/math.vector';
4
- import { capitalize, get, isEmpty, isNumber, isString } from 'lodash-es';
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
- * Constructor.
14
- */
15
- private constructor() {}
16
-
17
- /**
18
- * Mutates the visibility. Helper methods are {@link VariantParameterizable.show} and
19
- * {@link VariantParameterizable.hide}. Getter and setter is {@link VariantParameterizable.visible}.
20
- *
21
- * Scopes:
22
- * * {@link Element}
23
- * * {@link Variant}
24
- * * {@link ViewerLight} Available for all light types
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 VariantParameterizable.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 VariantParameterizable.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 VariantParameterizable.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 VariantParameterizable.position}.
121
- *
122
- * Scopes:
123
- * * {@link Element}
124
- * * {@link Variant}
125
- * * {@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)
126
- *
127
- * @parser {@link parseVector}
128
- */
129
- public static readonly POSITION = 'position';
130
-
131
- /**
132
- * Mutates the rotation relative to its origin rotation. Getter and setter is {@link VariantParameterizable.rotation}.
133
- *
134
- * Scopes:
135
- * * {@link Element}
136
- * * {@link Variant}
137
- *
138
- * @parser {@link parseRotation}
139
- */
140
- public static readonly ROTATION = 'rotation';
141
-
142
- /**
143
- * Mutates the color.
144
- *
145
- * Scopes:
146
- * * {@link Material} via {@link TagManager}
147
- *
148
- * @parser {@link parseColor}
149
- */
150
- public static readonly COLOR = 'color';
151
-
152
- /**
153
- * Mutates the metallic.
154
- *
155
- * Scopes:
156
- * * {@link Material} via {@link TagManager}
157
- *
158
- * @parser {@link parseNumber}
159
- */
160
- public static readonly METALLIC = 'metallic';
161
-
162
- /**
163
- * Paintables can be used to let the client/browser draw graphics on a 3d model by mutating the texture of a
164
- * material.\
165
- * For detailed information have a look at the [paintables](./../pages/documentation/Paintables.html) page.
166
- *
167
- * Also see {@link parsePaintable} for detailed information on which values you can pass to the `paintable`
168
- * parameter.
169
- *
170
- * Scopes:
171
- * * {@link Material} via {@link TagManager}
172
- *
173
- * @parser {@link parsePaintable}
174
- *
175
- */
176
- public static readonly PAINTABLE = 'paintable';
177
-
178
- /**
179
- * Mutates the roughness.
180
- *
181
- * Scopes:
182
- * * {@link Material} via {@link TagManager}
183
- *
184
- * @parser {@link parseNumber}
185
- */
186
- public static readonly ROUGHNESS = 'roughness';
187
-
188
- /**
189
- * Mutates whether a shadow should be casted or not.
190
- *
191
- * Scopes:
192
- * * {@link Element}
193
- * * {@link Variant}
194
- *
195
- * @parser {@link parseBoolean}
196
- */
197
- public static readonly CAST_SHADOW = 'castShadow';
198
-
199
- /**
200
- * Mutates from which lights a shadow should be casted.
201
- *
202
- * Scopes:
203
- * * {@link Element}
204
- * * {@link Variant}
205
- *
206
- * @parser {@link parseCommaSeparatedList}
207
- */
208
- public static readonly CAST_SHADOW_FROM_LIGHTS = 'castShadow.fromLights';
209
-
210
- /**
211
- * Mutates whether to receive shadows or not.
212
- *
213
- * Scopes:
214
- * * {@link Element}
215
- * * {@link Variant}
216
- *
217
- * @parser {@link parseBoolean}
218
- */
219
- public static readonly RECEIVE_SHADOWS = 'receiveShadows';
220
-
221
- /**
222
- * Mutates the intensity of Lights.
223
- *
224
- * Scopes:
225
- * * {@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)
226
- *
227
- * @parser {@link parseNumber}
228
- */
229
- public static readonly INTENSITY = 'intensity';
230
-
231
- /**
232
- * Mutates the direction of Lights.
233
- *
234
- * Scopes:
235
- * * {@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)
236
- *
237
- * @parser {@link parseNumber}
238
- */
239
- public static readonly DIRECTION = 'direction';
240
-
241
- /**
242
- * Mutates the angle of Lights.
243
- *
244
- * Scopes:
245
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#angle)
246
- *
247
- * @parser {@link parseNumber}
248
- */
249
- public static readonly ANGLE = 'angle';
250
-
251
- /**
252
- * Mutates the exponent of Lights.
253
- *
254
- * Scopes:
255
- * * {@link ViewerLight} Available for [SpotLight](https://doc.babylonjs.com/typedoc/classes/babylon.spotlight#exponent)
256
- *
257
- * @parser {@link parseNumber}
258
- */
259
- public static readonly EXPONENT = 'exponent';
260
-
261
- /**
262
- * Mutates the diffuse color of Lights.
263
- *
264
- * Scopes:
265
- * * {@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)
266
- *
267
- * @parser {@link parseNumber}
268
- */
269
- public static readonly DIFFUSE = 'diffuse';
270
-
271
- /**
272
- * Mutates the specular color of Lights.
273
- *
274
- * Scopes:
275
- * * {@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)
276
- *
277
- * @parser {@link parseNumber}
278
- */
279
- public static readonly SPECULAR = 'specular';
280
-
281
- /**
282
- * Sets the environment. See [BABYLON.Scene.environmentTexture](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#environmentTexture).
283
- *
284
- * Usually the URL to an `*.env` file.
285
- *
286
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
287
- *
288
- * Scopes:
289
- * * {@link SceneManager}
290
- *
291
- * @parser string
292
- */
293
- public static readonly ENVIRONMENT = 'environment';
294
-
295
- /**
296
- * Sets [BABYLON.Scene.clearColor](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#clearColor)
297
- *
298
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
299
- *
300
- * Scopes:
301
- * * {@link SceneManager}
302
- *
303
- * @parser {@link parseColor}
304
- */
305
- public static readonly ENVIRONMENT_COLOR = 'environment.color';
306
-
307
- /**
308
- * Rotates connected textures, i.e. IBL, reflection, background, ...
309
- * Rotation angle in degree.
310
- *
311
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
312
- *
313
- * Scopes:
314
- * * {@link SceneManager}
315
- *
316
- * @parser {@link parseNumber}
317
- */
318
- public static readonly ENVIRONMENT_ROTATION = 'environment.rotation';
319
-
320
- /**
321
- * Intensity of IBL. Defaults to 1, usually between 0 & 2.
322
- *
323
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
324
- *
325
- * Scopes:
326
- * * {@link SceneManager}
327
- *
328
- * @parser {@link parseNumber}
329
- */
330
- public static readonly ENVIRONMENT_INTENSITY = 'environment.intensity';
331
-
332
- /**
333
- * Background texture on a [PhotoDome](https://doc.babylonjs.com/divingDeeper/environment/360PhotoDome).
334
- * Just background, no IBL or reflection.
335
- *
336
- * Recommended format is `*.jpg`. HDR files are not supported as background but can be converted to `*.jpg` using
337
- * tools like Photoshop, Gimp or various free online converters.
338
- *
339
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
340
- *
341
- * Scopes:
342
- * * {@link SceneManager}
343
- *
344
- * @parser string
345
- */
346
- public static readonly ENVIRONMENT_BACKGROUND = 'environment.background';
347
-
348
- /**
349
- * If `true`, sets a `scene.environmentTexture` and creates a *BackgroundHelper* Node (via
350
- * [scene.createDefaultEnvironment](https://doc.babylonjs.com/typedoc/classes/BABYLON.Scene#createDefaultEnvironment))
351
- * with two subnodes/meshes:
352
- * - BackgroundPlane
353
- * - BackgroundSkybox
354
- *
355
- * The value of this parameter is ignored if {@link ENVIRONMENT_BACKGROUND} is also set.
356
- *
357
- * See [environment page](./../pages/documentation/Environment.html) for details on how to use this.
358
- *
359
- * Scopes:
360
- * * {@link SceneManager}
361
- *
362
- * @parser {@link parseBoolean}
363
- */
364
- public static readonly ENVIRONMENT_USEDEFAULT = 'environment.usedefault';
365
-
366
- /**
367
- * The {@link ParameterDeclarations} for all parameters in this class.
368
- */
369
- public static get declarations(): ParameterDeclarations {
370
- return {
371
- [Parameter.VISIBLE]: { type: 'boolean', parser: Parameter.parseBoolean },
372
- [Parameter.SCALING]: { type: 'number', parser: Parameter.parseNumber },
373
- [Parameter.POSITION]: { type: 'vector', parser: Parameter.parseVector },
374
- [Parameter.ROTATION]: { type: 'vector', parser: Parameter.parseVector },
375
- [Parameter.HIGHLIGHTED]: { type: 'boolean', parser: Parameter.parseBoolean },
376
- [Parameter.MATERIAL]: { type: 'string' },
377
- [Parameter.MATERIAL_COLOR]: { type: 'color', parser: Parameter.parseColor },
378
- [Parameter.MATERIAL_METALLNESS]: { type: 'number', parser: Parameter.parseNumber },
379
- [Parameter.MATERIAL_ROUGHNESS]: { type: 'number', parser: Parameter.parseNumber },
380
- [Parameter.HIGHLIGHT_ENABLED]: { type: 'boolean', parser: Parameter.parseBoolean },
381
- [Parameter.HIGHLIGHT_COLOR]: { type: 'color', parser: Parameter.parseColor },
382
- [Parameter.COLOR]: { type: 'color', parser: Parameter.parseColor },
383
- [Parameter.METALLIC]: { type: 'number', parser: Parameter.parseNumber },
384
- [Parameter.ROUGHNESS]: { type: 'number', parser: Parameter.parseNumber },
385
- [Parameter.PAINTABLE]: { type: 'paintable', parser: Parameter.parsePaintable },
386
- [Parameter.HIGHLIGHTED]: { type: 'boolean', parser: Parameter.parseBoolean },
387
- [Parameter.CAST_SHADOW]: { type: 'boolean', parser: Parameter.parseBoolean },
388
- [Parameter.CAST_SHADOW_FROM_LIGHTS]: { type: 'csl', parser: Parameter.parseCommaSeparatedList },
389
- [Parameter.RECEIVE_SHADOWS]: { type: 'boolean', parser: Parameter.parseBoolean },
390
- [Parameter.INTENSITY]: { type: 'number', parser: Parameter.parseNumber },
391
- [Parameter.DIRECTION]: { type: 'vector', parser: Parameter.parseVector },
392
- [Parameter.ANGLE]: { type: 'number', parser: Parameter.parseNumber },
393
- [Parameter.EXPONENT]: { type: 'number', parser: Parameter.parseNumber },
394
- [Parameter.DIFFUSE]: { type: 'color', parser: Parameter.parseColor },
395
- [Parameter.SPECULAR]: { type: 'color', parser: Parameter.parseColor },
396
- [Parameter.ENVIRONMENT]: { type: 'string' },
397
- [Parameter.ENVIRONMENT_COLOR]: { type: 'color', parser: Parameter.parseColor },
398
- [Parameter.ENVIRONMENT_ROTATION]: { type: 'number', parser: Parameter.parseNumber },
399
- [Parameter.ENVIRONMENT_INTENSITY]: { type: 'number', parser: Parameter.parseNumber },
400
- [Parameter.ENVIRONMENT_BACKGROUND]: { type: 'string' },
401
- [Parameter.ENVIRONMENT_USEDEFAULT]: { type: 'boolean', parser: Parameter.parseBoolean },
402
- };
403
- }
404
-
405
- /**
406
- * The default {@link ParameterValue}s returned as {@link ParameterBag} for a set of parameters in this class.
407
- */
408
- public static get defaultValues(): ParameterBag {
409
- return {
410
- [Parameter.SCALING]: '(1, 1, 1)',
411
- [Parameter.POSITION]: '(0, 0, 0)',
412
- [Parameter.ROTATION]: '(0, 0, 0)',
413
- };
414
- }
415
-
416
- /**
417
- * Gets the default {@link ParameterValue} for a given {@link Parameter} declared in this class.
418
- */
419
- public static getDefaultValue(parameter: string): ParameterValue {
420
- return Parameter.defaultValues[parameter];
421
- }
422
-
423
- /**
424
- * All parameters defined in this class.
425
- */
426
- public static get all() {
427
- const all: string[] = [];
428
- for (const parameter in Parameter) {
429
- const property = Object.getOwnPropertyDescriptor(Parameter, parameter);
430
- if (parameter.toUpperCase() === parameter && property && isString(property.value)) {
431
- all.push(property.value);
432
- }
433
- }
434
- return all;
435
- }
436
-
437
- /**
438
- * Asserts whether given parameter is declared and valid.
439
- */
440
- public static assertParameter(parameterDeclaration: ParameterDeclarations, parameter: string, value: ParameterValue) {
441
- if (!(parameter in parameterDeclaration)) {
442
- // This is a valid case since we are not able to check parameters that are not declared.
443
- // We just ignore parameters that are not declared.
444
- return;
445
- }
446
- const declaration = parameterDeclaration[parameter];
447
- const errorPrefix = `Invalid value for parameter "${parameter}" of type "${declaration.type}" given:`;
448
- if (declaration.parser) {
449
- try {
450
- declaration.parser(value);
451
- } catch (e: any) {
452
- throw new ViewerError({
453
- id: ViewerErrorIds.InvalidParameterValue,
454
- message: `${errorPrefix}\n${e.message}.\nGiven value: ${value}`,
455
- });
456
- }
457
- }
458
- switch (declaration.type) {
459
- case 'select':
460
- if (!declaration.options) {
461
- throw new ViewerError({
462
- id: ViewerErrorIds.UnknownParameterOption,
463
- message: `No options defined for parameter declaration "${parameter}" of type "${declaration.type}".`,
464
- });
465
- }
466
- if (declaration.options.indexOf(value) === -1) {
467
- throw Error(
468
- `${errorPrefix}\nValid values are: "${declaration.options.join('", "')}".\nGiven value: ${value}`
469
- );
470
- }
471
- break;
472
- }
473
- }
474
-
475
- /**
476
- * Parses given {@link ParameterBag} with given {@link ParameterDeclarations}.
477
- */
478
- public static parseFromDeclarations(
479
- declarations: ParameterDeclarations,
480
- parameterBag: ParameterBag
481
- ): ParsedParameterBag {
482
- const parameters: ParsedParameterBag = {};
483
- for (const parameter in parameterBag) {
484
- const value = get(parameterBag, parameter);
485
- parameters[parameter] = value;
486
- const declaration: ParameterDeclaration = declarations[parameter];
487
- if (declaration) {
488
- if (!isEmpty(value) && declaration.parser) {
489
- parameters[parameter] = declaration.parser(value);
490
- }
491
- }
492
- }
493
- return parameters;
494
- }
495
-
496
- /**
497
- * Parses a string of format `'(x,y,z)'` to a `Vector3`.
498
- */
499
- public static parseVector(value: ParameterValue): Vector3 {
500
- if (!isString(value)) {
501
- throw new Error(`Unable to convert "${value}" into a Vector: not a string.`);
502
- }
503
- let cleanedValue = value.split(' ').join('');
504
- if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
505
- cleanedValue = cleanedValue.substring(1, cleanedValue.length - 1);
506
- const [x, y, z] = cleanedValue.split(',').map(value => parseFloat(value));
507
- return new Vector3(x, y, z);
508
- } else {
509
- throw new Error(`Unable to parse "${value}" to a Vector: expected "(x,y,z)".`);
510
- }
511
- }
512
-
513
- /**
514
- * Stringifies a Vector3 to format `(x,y,z)`.
515
- */
516
- public static stringifyVector(value: Vector3): string {
517
- return `(${value.x},${value.y},${value.z})`;
518
- }
519
-
520
- /**
521
- * Parses a string of format `'(x,y,z)'` with angular degrees to a `Vector3` with rotation information in radians.
522
- */
523
- public static parseRotation(value: ParameterValue): Vector3 {
524
- const rotation = Parameter.parseVector(value);
525
- const deg2rad = function (deg: number) {
526
- return (deg * Math.PI) / 180;
527
- };
528
- return rotation.set(deg2rad(rotation.x), deg2rad(rotation.y), deg2rad(rotation.z));
529
- }
530
-
531
- /**
532
- * Parses a string of format `'(x,y,z)'` or a simple `number` to a `Vector3` for scaling.
533
- */
534
- public static parseScaling(value: ParameterValue): Vector3 {
535
- let scaling = new Vector3();
536
- if (isString(value)) {
537
- const cleanedFactor = value.split(' ').join('');
538
- if (cleanedFactor.startsWith('(') && cleanedFactor.endsWith(')')) {
539
- scaling = Parameter.parseVector(cleanedFactor);
540
- } else {
541
- const _factor = parseFloat(value);
542
- scaling = new Vector3(_factor, _factor, _factor);
543
- }
544
- } else if (isNumber(value)) {
545
- scaling = new Vector3(value, value, value);
546
- } else {
547
- throw new Error(`Unable to convert "${value}" to a Vector: expected "(x,y,z)".`);
548
- }
549
- return scaling;
550
- }
551
-
552
- /**
553
- * Parses a string of format `'#rrggbb'` or `'(r,g,b)'` to a `Color3`.
554
- */
555
- public static parseColor(value: ParameterValue): Color3 {
556
- const cleanedValue = value.toString().split(' ').join('');
557
- if (cleanedValue.startsWith('#')) {
558
- return Color3.FromHexString(value.toString());
559
- }
560
- if (cleanedValue.startsWith('(') && cleanedValue.endsWith(')')) {
561
- const rgb = cleanedValue.substring(1, cleanedValue.length - 1);
562
- const [r, g, b] = rgb.split(',').map(value => parseFloat(value));
563
- return Color3.FromInts(r, g, b);
564
- }
565
- const humanReadable = capitalize(cleanedValue);
566
- // disable lint for this rule as there is no smoother option for checking static class functions (eg Color.Red())
567
- // eslint-disable-next-line no-prototype-builtins
568
- if (Color3.hasOwnProperty(humanReadable)) {
569
- // @ts-ignore same as above
570
- return Color3[humanReadable]();
571
- }
572
- throw new Error(
573
- `Unable to parse "${value}" to a Color: expected "#rrggbb", "(r,g,b)" or any human readable property implemented in Color3.`
574
- );
575
- }
576
-
577
- /**
578
- * Parses a `boolean` string (`'true'`/`'1'` or `'false'`/`'0'`) or `number` (`1` or `0`) to a `boolean` or
579
- * `undefined`.
580
- */
581
- public static parseBoolean(value: ParameterValue): boolean {
582
- if (value.toString() === 'true' || value.toString() === '1') {
583
- return true;
584
- } else if (value.toString() === 'false' || value.toString() === '0') {
585
- return false;
586
- }
587
- throw new Error(`Unable to parse "${value}" to a boolean.`);
588
- }
589
-
590
- /**
591
- * Parses a number `string` to a `number`.
592
- */
593
- public static parseNumber(value: ParameterValue): number {
594
- return parseFloat(value.toString());
595
- }
596
-
597
- /**
598
- * Parses string defintion of a paintable into a paintable object.\
599
- * Here are some examples:
600
- * ```ts
601
- * // Default definition as JSON object:
602
- * '{ "src": "https://path.to/image.jpg", "uScale": 0.5 }'
603
- *
604
- * // Short hand definition, only contains source string:
605
- * 'https://path.to/image.jpg'
606
- *
607
- * // Full content, paintable texture is flipped in both directions
608
- * '{ "src": "https://path.to/image.jpg", "uScale": -1, "vScale": -1, "uOffset": 0, "vOffset": 0 }'
609
- *
610
- * // SVG content can be used directly:
611
- * '<svg>...</svg>'
612
- *
613
- * // SVG in src property works as well:
614
- * '{ "src": "<svg>...</svg>", "uScale": 0.5 }'
615
- * ```
616
- */
617
- public static parsePaintable(value: ParameterValue): PaintableValue {
618
- if (!isString(value)) {
619
- throw new Error(`Not a string.`);
620
- }
621
-
622
- const paintableValue: PaintableValue = { src: '' };
623
- let valObj: { [key: string]: any } | null = null;
624
-
625
- try {
626
- valObj = JSON.parse(value);
627
- } catch {
628
- // use string directly
629
- paintableValue.src = value;
630
-
631
- if (value.startsWith('{')) {
632
- // seems like the user tried to use a JSON string, as the input starts with {
633
- throw new Error(`Not a valid JSON string.`);
634
- }
635
- }
636
-
637
- if (valObj) {
638
- // input string is JSON, src attribute is required
639
- if (!valObj.src) {
640
- throw new Error(`Property "src" is missing.`);
641
- }
642
-
643
- if (!isString(valObj.src)) {
644
- throw new Error(`Property "src" is not a string.`);
645
- }
646
-
647
- // split src and options
648
- const { src, ...options } = valObj;
649
- paintableValue.src = src;
650
-
651
- // only forward valid paintable options
652
- const validOptionKeys = ['uScale', 'vScale', 'uOffset', 'vOffset'];
653
- const { validOptions, invalidKeys } = Object.entries(options).reduce(
654
- (accRes, [curKey, curValue]) => {
655
- const isValidKey = validOptionKeys.includes(curKey);
656
- if (isValidKey) {
657
- accRes.validOptions[curKey] = curValue;
658
- } else {
659
- accRes.invalidKeys.push(curKey);
660
- }
661
-
662
- return accRes;
663
- },
664
- { validOptions: {} as { [key: string]: any }, invalidKeys: [] as string[] }
665
- );
666
-
667
- if (invalidKeys.length) {
668
- console.warn('parsePaintable: invalid paintable options provided: ' + invalidKeys.toString());
669
- }
670
-
671
- paintableValue.options = validOptions;
672
- }
673
-
674
- return paintableValue;
675
- }
676
-
677
- /**
678
- * Parses a string with comma separated values to a list of strings.
679
- */
680
- public static parseCommaSeparatedList(value: ParameterValue): string[] {
681
- return value
682
- .toString()
683
- .split(',')
684
- .map(s => s.trim());
685
- }
686
- }