@babylonjs/core 7.4.0 → 7.6.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 (235) hide show
  1. package/Audio/sound.js +3 -0
  2. package/Audio/sound.js.map +1 -1
  3. package/Buffers/storageBuffer.d.ts +2 -2
  4. package/Buffers/storageBuffer.js.map +1 -1
  5. package/Cameras/arcRotateCamera.js +3 -0
  6. package/Cameras/arcRotateCamera.js.map +1 -1
  7. package/Cameras/flyCamera.js +3 -0
  8. package/Cameras/flyCamera.js.map +1 -1
  9. package/Cameras/followCamera.js +4 -0
  10. package/Cameras/followCamera.js.map +1 -1
  11. package/Cameras/freeCamera.js +3 -0
  12. package/Cameras/freeCamera.js.map +1 -1
  13. package/Engines/Extensions/index.d.ts +0 -3
  14. package/Engines/Extensions/index.js +0 -3
  15. package/Engines/Extensions/index.js.map +1 -1
  16. package/Engines/WebGPU/Extensions/index.d.ts +0 -3
  17. package/Engines/WebGPU/Extensions/index.js +0 -3
  18. package/Engines/WebGPU/Extensions/index.js.map +1 -1
  19. package/Engines/abstractEngine.d.ts +11 -63
  20. package/Engines/abstractEngine.js +7 -7
  21. package/Engines/abstractEngine.js.map +1 -1
  22. package/Engines/nativeEngine.js +2 -2
  23. package/Engines/nativeEngine.js.map +1 -1
  24. package/Engines/thinEngine.d.ts +2 -2
  25. package/Engines/thinEngine.functions.d.ts +2 -10
  26. package/Engines/thinEngine.functions.js +1 -20
  27. package/Engines/thinEngine.functions.js.map +1 -1
  28. package/Engines/thinEngine.js +27 -11
  29. package/Engines/thinEngine.js.map +1 -1
  30. package/Engines/webgpuEngine.d.ts +54 -2
  31. package/Engines/webgpuEngine.js +147 -0
  32. package/Engines/webgpuEngine.js.map +1 -1
  33. package/Inputs/scene.inputManager.d.ts +1 -0
  34. package/Inputs/scene.inputManager.js +1 -0
  35. package/Inputs/scene.inputManager.js.map +1 -1
  36. package/Lights/directionalLight.js +3 -0
  37. package/Lights/directionalLight.js.map +1 -1
  38. package/Lights/hemisphericLight.js +3 -0
  39. package/Lights/hemisphericLight.js.map +1 -1
  40. package/Lights/pointLight.js +3 -0
  41. package/Lights/pointLight.js.map +1 -1
  42. package/Lights/spotLight.js +3 -0
  43. package/Lights/spotLight.js.map +1 -1
  44. package/Loading/Plugins/babylonFileLoader.js +25 -14
  45. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  46. package/Materials/Background/backgroundMaterial.js +1 -2
  47. package/Materials/Background/backgroundMaterial.js.map +1 -1
  48. package/Materials/GreasedLine/greasedLinePluginMaterial.js +7 -3
  49. package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
  50. package/Materials/Node/Blocks/Dual/clipPlanesBlock.d.ts +1 -1
  51. package/Materials/Node/Blocks/Dual/clipPlanesBlock.js.map +1 -1
  52. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +1 -1
  53. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  54. package/Materials/Node/Blocks/Dual/fogBlock.d.ts +1 -1
  55. package/Materials/Node/Blocks/Dual/fogBlock.js.map +1 -1
  56. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.d.ts +1 -1
  57. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  58. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +1 -1
  59. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  60. package/Materials/Node/Blocks/Dual/textureBlock.d.ts +1 -1
  61. package/Materials/Node/Blocks/Dual/textureBlock.js +5 -1
  62. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  63. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.d.ts +1 -1
  64. package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
  65. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.d.ts +1 -1
  66. package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
  67. package/Materials/Node/Blocks/Fragment/screenSizeBlock.d.ts +1 -1
  68. package/Materials/Node/Blocks/Fragment/screenSizeBlock.js.map +1 -1
  69. package/Materials/Node/Blocks/Fragment/shadowMapBlock.d.ts +1 -1
  70. package/Materials/Node/Blocks/Fragment/shadowMapBlock.js.map +1 -1
  71. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.d.ts +2 -1
  72. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js +1 -0
  73. package/Materials/Node/Blocks/Input/animatedInputBlockTypes.js.map +1 -1
  74. package/Materials/Node/Blocks/Input/inputBlock.d.ts +1 -1
  75. package/Materials/Node/Blocks/Input/inputBlock.js +16 -0
  76. package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
  77. package/Materials/Node/Blocks/PBR/anisotropyBlock.d.ts +1 -1
  78. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  79. package/Materials/Node/Blocks/PBR/clearCoatBlock.d.ts +1 -1
  80. package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
  81. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.d.ts +1 -1
  82. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  83. package/Materials/Node/Blocks/PBR/reflectionBlock.d.ts +1 -1
  84. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  85. package/Materials/Node/Blocks/PBR/refractionBlock.d.ts +1 -1
  86. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  87. package/Materials/Node/Blocks/Vertex/lightInformationBlock.d.ts +1 -1
  88. package/Materials/Node/Blocks/Vertex/lightInformationBlock.js.map +1 -1
  89. package/Materials/Node/Blocks/Vertex/vertexOutputBlock.d.ts +1 -1
  90. package/Materials/Node/Blocks/Vertex/vertexOutputBlock.js.map +1 -1
  91. package/Materials/Node/Blocks/baseMathBlock.js +2 -4
  92. package/Materials/Node/Blocks/baseMathBlock.js.map +1 -1
  93. package/Materials/Node/Blocks/modBlock.js +7 -1
  94. package/Materials/Node/Blocks/modBlock.js.map +1 -1
  95. package/Materials/Node/Blocks/triPlanarBlock.d.ts +1 -1
  96. package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
  97. package/Materials/Node/nodeMaterial.d.ts +2 -4
  98. package/Materials/Node/nodeMaterial.js +1 -3
  99. package/Materials/Node/nodeMaterial.js.map +1 -1
  100. package/Materials/Node/nodeMaterialBlockConnectionPoint.d.ts +34 -14
  101. package/Materials/Node/nodeMaterialBlockConnectionPoint.js +87 -9
  102. package/Materials/Node/nodeMaterialBlockConnectionPoint.js.map +1 -1
  103. package/Materials/Node/nodeMaterialBuildState.d.ts +1 -1
  104. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  105. package/Materials/PBR/pbrBaseMaterial.d.ts +1 -2
  106. package/Materials/PBR/pbrBaseMaterial.js +1 -2
  107. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  108. package/Materials/Textures/Loaders/ktxTextureLoader.js +1 -1
  109. package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
  110. package/Materials/Textures/htmlElementTexture.d.ts +0 -1
  111. package/Materials/Textures/htmlElementTexture.js +7 -2
  112. package/Materials/Textures/htmlElementTexture.js.map +1 -1
  113. package/Materials/Textures/videoTexture.js +4 -2
  114. package/Materials/Textures/videoTexture.js.map +1 -1
  115. package/Materials/effect.d.ts +4 -0
  116. package/Materials/effect.functions.d.ts +1 -1
  117. package/Materials/effect.functions.js +6 -4
  118. package/Materials/effect.functions.js.map +1 -1
  119. package/Materials/effect.js +1 -1
  120. package/Materials/effect.js.map +1 -1
  121. package/Materials/effect.webgl.functions.js +3 -3
  122. package/Materials/effect.webgl.functions.js.map +1 -1
  123. package/Materials/imageProcessingConfiguration.d.ts +5 -0
  124. package/Materials/imageProcessingConfiguration.defines.d.ts +2 -4
  125. package/Materials/imageProcessingConfiguration.defines.js +1 -2
  126. package/Materials/imageProcessingConfiguration.defines.js.map +1 -1
  127. package/Materials/imageProcessingConfiguration.js +26 -11
  128. package/Materials/imageProcessingConfiguration.js.map +1 -1
  129. package/Materials/materialPluginBase.js +3 -0
  130. package/Materials/materialPluginBase.js.map +1 -1
  131. package/Materials/meshDebugPluginMaterial.js +2 -2
  132. package/Materials/meshDebugPluginMaterial.js.map +1 -1
  133. package/Materials/shaderMaterial.js +18 -8
  134. package/Materials/shaderMaterial.js.map +1 -1
  135. package/Materials/standardMaterial.d.ts +1 -2
  136. package/Materials/standardMaterial.js +1 -2
  137. package/Materials/standardMaterial.js.map +1 -1
  138. package/Maths/math.color.d.ts +85 -82
  139. package/Maths/math.color.js +34 -27
  140. package/Maths/math.color.js.map +1 -1
  141. package/Maths/math.vector.d.ts +202 -202
  142. package/Maths/math.vector.js +133 -130
  143. package/Maths/math.vector.js.map +1 -1
  144. package/Maths/tensor.d.ts +44 -42
  145. package/Maths/tensor.js.map +1 -1
  146. package/Meshes/Compression/dracoCompression.d.ts +7 -0
  147. package/Meshes/Compression/dracoCompression.js +14 -0
  148. package/Meshes/Compression/dracoCompression.js.map +1 -1
  149. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js +6 -0
  150. package/Meshes/Node/nodeGeometryBlockConnectionPoint.js.map +1 -1
  151. package/Meshes/instancedMesh.js +3 -0
  152. package/Meshes/instancedMesh.js.map +1 -1
  153. package/Misc/dumpTools.js +11 -0
  154. package/Misc/dumpTools.js.map +1 -1
  155. package/Misc/fileTools.d.ts +9 -3
  156. package/Misc/fileTools.js +17 -14
  157. package/Misc/fileTools.js.map +1 -1
  158. package/Misc/greasedLineTools.js +7 -1
  159. package/Misc/greasedLineTools.js.map +1 -1
  160. package/Misc/sceneSerializer.js +9 -1
  161. package/Misc/sceneSerializer.js.map +1 -1
  162. package/Misc/textureTools.d.ts +2 -0
  163. package/Misc/textureTools.js +2 -0
  164. package/Misc/textureTools.js.map +1 -1
  165. package/Misc/tools.d.ts +5 -6
  166. package/Misc/tools.js +9 -9
  167. package/Misc/tools.js.map +1 -1
  168. package/Misc/typeStore.d.ts +4 -0
  169. package/Misc/typeStore.js +11 -0
  170. package/Misc/typeStore.js.map +1 -1
  171. package/NOTICE.md +8 -0
  172. package/Particles/baseParticleSystem.js +3 -0
  173. package/Particles/baseParticleSystem.js.map +1 -1
  174. package/Particles/computeShaderParticleSystem.d.ts +2 -2
  175. package/Particles/computeShaderParticleSystem.js.map +1 -1
  176. package/Physics/v1/Plugins/ammoJSPlugin.js +39 -10
  177. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  178. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +4 -0
  179. package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
  180. package/PostProcesses/imageProcessingPostProcess.js +14 -5
  181. package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
  182. package/Rendering/GlobalIllumination/giRSMManager.d.ts +6 -0
  183. package/Rendering/GlobalIllumination/giRSMManager.js +15 -1
  184. package/Rendering/GlobalIllumination/giRSMManager.js.map +1 -1
  185. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js +22 -20
  186. package/Rendering/fluidRenderer/fluidRenderingTargetRenderer.js.map +1 -1
  187. package/Rendering/renderingGroup.js +1 -1
  188. package/Rendering/renderingGroup.js.map +1 -1
  189. package/Shaders/ShadersInclude/imageProcessingFunctions.js +8 -5
  190. package/Shaders/ShadersInclude/imageProcessingFunctions.js.map +1 -1
  191. package/Shaders/ShadersInclude/screenSpaceRayTrace.js +8 -0
  192. package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
  193. package/Shaders/lod.fragment.d.ts +5 -0
  194. package/Shaders/lod.fragment.js +12 -0
  195. package/Shaders/lod.fragment.js.map +1 -0
  196. package/Shaders/lodCube.fragment.d.ts +5 -0
  197. package/Shaders/lodCube.fragment.js +30 -0
  198. package/Shaders/lodCube.fragment.js.map +1 -0
  199. package/Shaders/screenSpaceReflection2.fragment.js +7 -1
  200. package/Shaders/screenSpaceReflection2.fragment.js.map +1 -1
  201. package/Shaders/ssao2.fragment.js +1 -1
  202. package/Shaders/ssao2.fragment.js.map +1 -1
  203. package/XR/features/WebXRNearInteraction.d.ts +6 -0
  204. package/XR/features/WebXRNearInteraction.js +14 -2
  205. package/XR/features/WebXRNearInteraction.js.map +1 -1
  206. package/XR/webXRManagedOutputCanvas.d.ts +2 -0
  207. package/XR/webXRManagedOutputCanvas.js +14 -6
  208. package/XR/webXRManagedOutputCanvas.js.map +1 -1
  209. package/abstractScene.js +3 -0
  210. package/abstractScene.js.map +1 -1
  211. package/assets/glslang/glslang.js +113 -0
  212. package/assets/glslang/glslang.wasm +0 -0
  213. package/assets/twgsl/twgsl.js +53 -0
  214. package/assets/twgsl/twgsl.wasm +0 -0
  215. package/package.json +1 -1
  216. package/scene.js +3 -0
  217. package/scene.js.map +1 -1
  218. package/Engines/Extensions/engine.externalTexture.d.ts +0 -18
  219. package/Engines/Extensions/engine.externalTexture.js +0 -10
  220. package/Engines/Extensions/engine.externalTexture.js.map +0 -1
  221. package/Engines/Extensions/engine.storageBuffer.d.ts +0 -39
  222. package/Engines/Extensions/engine.storageBuffer.js +0 -16
  223. package/Engines/Extensions/engine.storageBuffer.js.map +0 -1
  224. package/Engines/Extensions/engine.textureSampler.d.ts +0 -12
  225. package/Engines/Extensions/engine.textureSampler.js +0 -6
  226. package/Engines/Extensions/engine.textureSampler.js.map +0 -1
  227. package/Engines/WebGPU/Extensions/engine.externalTexture.d.ts +0 -28
  228. package/Engines/WebGPU/Extensions/engine.externalTexture.js +0 -18
  229. package/Engines/WebGPU/Extensions/engine.externalTexture.js.map +0 -1
  230. package/Engines/WebGPU/Extensions/engine.storageBuffer.d.ts +0 -50
  231. package/Engines/WebGPU/Extensions/engine.storageBuffer.js +0 -88
  232. package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +0 -1
  233. package/Engines/WebGPU/Extensions/engine.textureSampler.d.ts +0 -22
  234. package/Engines/WebGPU/Extensions/engine.textureSampler.js +0 -9
  235. package/Engines/WebGPU/Extensions/engine.textureSampler.js.map +0 -1
package/Maths/tensor.d.ts CHANGED
@@ -10,13 +10,14 @@ export type TensorValue = number[] | TensorValue[];
10
10
  /**
11
11
  * Extracts the value type of a Tensor
12
12
  */
13
- export type ValueOfTensor<T = unknown> = T extends Tensor<infer V> ? V : TensorValue;
13
+ export type ValueOfTensor<T = unknown> = T extends Tensor<infer V, any> ? V : TensorValue;
14
14
  type TensorNumberArray<V extends TensorValue> = Length<Dimension<V>> extends 2 ? Tuple<number, 16> : V;
15
+ export type TensorLike<T> = T extends Tensor<TensorValue, infer I> ? I : never;
15
16
  /**
16
17
  * Describes a mathematical tensor.
17
18
  * @see https://wikipedia.org/wiki/Tensor
18
19
  */
19
- export interface Tensor<V extends TensorValue = TensorValue> {
20
+ export interface Tensor<V extends TensorValue, I> {
20
21
  /**
21
22
  * An array of the size of each dimension.
22
23
  * For example, [3] for a Vector3 and [4,4] for a Matrix
@@ -64,7 +65,7 @@ export interface Tensor<V extends TensorValue = TensorValue> {
64
65
  * @param source defines the source instance
65
66
  * @returns the current updated instance
66
67
  */
67
- copyFrom(source: DeepImmutable<this>): this;
68
+ copyFrom(source: DeepImmutable<I>): this;
68
69
  /**
69
70
  * Sets the instance coordinates with the given floats
70
71
  * @returns the current updated instance
@@ -85,20 +86,20 @@ export interface Tensor<V extends TensorValue = TensorValue> {
85
86
  * @param other defines the other instance
86
87
  * @returns a new instance set with the addition of the current instance and the given one coordinates
87
88
  */
88
- add(other: DeepImmutable<this>): this;
89
+ add(other: DeepImmutable<I>): Tensor<V, I>;
89
90
  /**
90
91
  * Sets the "result" coordinates with the addition of the current instance and the given one coordinates
91
92
  * @param other defines the other instance
92
93
  * @param result defines the target instance
93
94
  * @returns result input
94
95
  */
95
- addToRef(other: DeepImmutable<this>, result: this): this;
96
+ addToRef<R extends I>(other: DeepImmutable<I>, result: R): R;
96
97
  /**
97
98
  * Set the instance coordinates by adding the given instance coordinates
98
99
  * @param other defines the other instance
99
100
  * @returns the current updated instance
100
101
  */
101
- addInPlace(other: DeepImmutable<this>): this;
102
+ addInPlace(other: DeepImmutable<I>): this;
102
103
  /**
103
104
  * Adds the given coordinates to the current instance
104
105
  * @param floats the floats to add
@@ -110,82 +111,82 @@ export interface Tensor<V extends TensorValue = TensorValue> {
110
111
  * @param other defines the other instance
111
112
  * @returns a new instance
112
113
  */
113
- subtract(other: DeepImmutable<this>): this;
114
+ subtract(other: DeepImmutable<I>): Tensor<V, I>;
114
115
  /**
115
116
  * Sets the "result" coordinates with the subtraction of the other's coordinates from the current coordinates.
116
117
  * @param other defines the other instance
117
118
  * @param result defines the target instance
118
119
  * @returns result input
119
120
  */
120
- subtractToRef(other: DeepImmutable<this>, result: this): this;
121
+ subtractToRef<R extends I>(other: DeepImmutable<I>, result: R): R;
121
122
  /**
122
123
  * Sets the current instance coordinates by subtracting from it the given one coordinates
123
124
  * @param other defines the other instance
124
125
  * @returns the current updated instance
125
126
  */
126
- subtractInPlace(other: DeepImmutable<this>): this;
127
+ subtractInPlace(other: DeepImmutable<I>): this;
127
128
  /**
128
129
  * Returns a new instance set with the subtraction of the given floats from the current instance coordinates
129
130
  * @param floats the coordinates to subtract
130
131
  * @returns the resulting instance
131
132
  */
132
- subtractFromFloats(...floats: TensorNumberArray<V>): this;
133
+ subtractFromFloats(...floats: TensorNumberArray<V>): Tensor<V, I>;
133
134
  /**
134
135
  * Subtracts the given floats from the current instance coordinates and set the given instance "result" with this result
135
136
  * Note: Implementation uses array magic so types may be confusing.
136
137
  * @param args the coordinates to subtract with the last element as the result
137
138
  * @returns the result
138
139
  */
139
- subtractFromFloatsToRef(...args: [...TensorNumberArray<V>, this]): this;
140
+ subtractFromFloatsToRef<R extends I>(...args: [...TensorNumberArray<V>, R]): R;
140
141
  /**
141
142
  * Returns a new instance set with the multiplication of the current instance and the given one coordinates
142
143
  * @param other defines the other instance
143
144
  * @returns a new instance
144
145
  */
145
- multiply(other: DeepImmutable<this>): this;
146
+ multiply(other: DeepImmutable<I>): Tensor<V, I>;
146
147
  /**
147
148
  * Sets "result" coordinates with the multiplication of the current instance and the given one coordinates
148
149
  * @param other defines the other instance
149
150
  * @param result defines the target instance
150
151
  * @returns result input
151
152
  */
152
- multiplyToRef(other: DeepImmutable<this>, result: this): this;
153
+ multiplyToRef<R extends I>(other: DeepImmutable<I>, result: R): R;
153
154
  /**
154
155
  * Multiplies in place the current instance coordinates by the given ones
155
156
  * @param other defines the other instance
156
157
  * @returns the current updated instance
157
158
  */
158
- multiplyInPlace(other: DeepImmutable<this>): this;
159
+ multiplyInPlace(other: DeepImmutable<I>): this;
159
160
  /**
160
161
  * Gets a new instance set with the instance coordinates multiplied by the given floats
161
162
  * @returns a new instance
162
163
  */
163
- multiplyByFloats(...floats: TensorNumberArray<V>): this;
164
+ multiplyByFloats(...floats: TensorNumberArray<V>): Tensor<V, I>;
164
165
  /**
165
166
  * Returns a new instance set with the instance coordinates divided by the given one coordinates
166
167
  * @param other defines the other instance
167
168
  * @returns a new instance
168
169
  */
169
- divide(other: DeepImmutable<this>): this;
170
+ divide(other: DeepImmutable<I>): Tensor<V, I>;
170
171
  /**
171
172
  * Sets the "result" coordinates with the instance coordinates divided by the given one coordinates
172
173
  * @param other defines the other instance
173
174
  * @param result defines the target instance
174
175
  * @returns result input
175
176
  */
176
- divideToRef(other: DeepImmutable<this>, result: this): this;
177
+ divideToRef<R extends I>(other: DeepImmutable<I>, result: R): R;
177
178
  /**
178
179
  * Divides the current instance coordinates by the given ones
179
180
  * @param other defines the other instance
180
181
  * @returns the current updated instance
181
182
  */
182
- divideInPlace(other: DeepImmutable<this>): this;
183
+ divideInPlace(other: DeepImmutable<I>): this;
183
184
  /**
184
185
  * Updates the current instance with the minmal coordinate values between its and the given instance ones.
185
186
  * @param other defines the other instance
186
187
  * @returns this current updated instance
187
188
  */
188
- minimizeInPlace(other: DeepImmutable<this>): this;
189
+ minimizeInPlace(other: DeepImmutable<I>): this;
189
190
  /**
190
191
  * Updates the current instance with the minmal coordinate values between its and the given floats.
191
192
  * @param floats defines the floats to compare against
@@ -197,7 +198,7 @@ export interface Tensor<V extends TensorValue = TensorValue> {
197
198
  * @param other defines the other instance
198
199
  * @returns this current updated instance
199
200
  */
200
- maximizeInPlace(other: DeepImmutable<this>): this;
201
+ maximizeInPlace(other: DeepImmutable<I>): this;
201
202
  /**
202
203
  * Updates the current instance with the maximal coordinate values between its and the given floats.
203
204
  * @param floats defines the floats to compare against
@@ -208,7 +209,7 @@ export interface Tensor<V extends TensorValue = TensorValue> {
208
209
  * Gets a new instance with current instance negated coordinates
209
210
  * @returns a new instance
210
211
  */
211
- negate(): this;
212
+ negate(): Tensor<V, I>;
212
213
  /**
213
214
  * Negate this instance in place
214
215
  * @returns this
@@ -219,7 +220,7 @@ export interface Tensor<V extends TensorValue = TensorValue> {
219
220
  * @param result defines the instance object where to store the result
220
221
  * @returns the result
221
222
  */
222
- negateToRef(result: this): this;
223
+ negateToRef<R extends I>(result: R): R;
223
224
  /**
224
225
  * Multiply the instance coordinates by
225
226
  * @param scale defines the scaling factor
@@ -231,34 +232,34 @@ export interface Tensor<V extends TensorValue = TensorValue> {
231
232
  * @param scale defines the scaling factor
232
233
  * @returns a new instance
233
234
  */
234
- scale(scale: number): this;
235
+ scale(scale: number): Tensor<V, I>;
235
236
  /**
236
237
  * Scale the current instance values by a factor to a given instance
237
238
  * @param scale defines the scale factor
238
239
  * @param result defines the instance object where to store the result
239
240
  * @returns result input
240
241
  */
241
- scaleToRef(scale: number, result: this): this;
242
+ scaleToRef<R extends I>(scale: number, result: R): R;
242
243
  /**
243
244
  * Scale the current instance values by a factor and add the result to a given instance
244
245
  * @param scale defines the scale factor
245
246
  * @param result defines the instance object where to store the result
246
247
  * @returns result input
247
248
  */
248
- scaleAndAddToRef(scale: number, result: this): this;
249
+ scaleAndAddToRef<R extends I>(scale: number, result: R): R;
249
250
  /**
250
251
  * Gets a boolean if two instances are equals
251
252
  * @param other defines the other instance
252
253
  * @returns true if the given instance coordinates strictly equal the current instance ones
253
254
  */
254
- equals(other: DeepImmutable<this>): boolean;
255
+ equals(other: DeepImmutable<I>): boolean;
255
256
  /**
256
257
  * Gets a boolean if two instances are equals (using an epsilon value)
257
258
  * @param other defines the other instance
258
259
  * @param epsilon defines the minimal distance to consider equality
259
260
  * @returns true if the given instance coordinates are close to the current ones by a distance of epsilon.
260
261
  */
261
- equalsWithEpsilon(other: DeepImmutable<this>, epsilon?: number): boolean;
262
+ equalsWithEpsilon(other: DeepImmutable<I>, epsilon?: number): boolean;
262
263
  /**
263
264
  * Returns true if the current Vectoe coordinates equals the given floats
264
265
  * @param floats defines the coordinates to compare against
@@ -270,35 +271,36 @@ export interface Tensor<V extends TensorValue = TensorValue> {
270
271
  * eg (1.2, 2.31) returns (1, 2)
271
272
  * @returns a new instance
272
273
  */
273
- floor(): this;
274
+ floor(): Tensor<V, I>;
274
275
  /**
275
276
  * Gets the current instance's floored values and stores them in result
276
277
  * @param result the instance to store the result in
277
278
  * @returns the result instance
278
279
  */
279
- floorToRef(result: this): this;
280
+ floorToRef<R extends I>(result: R): R;
280
281
  /**
281
282
  * Gets a new instance from current instance fractional values
282
283
  * eg (1.2, 2.31) returns (0.2, 0.31)
283
284
  * @returns a new instance
284
285
  */
285
- fract(): this;
286
+ fract(): Tensor<V, I>;
286
287
  /**
287
288
  * Gets the current instance's fractional values and stores them in result
288
289
  * @param result the instance to store the result in
289
290
  * @returns the result instance
290
291
  */
291
- fractToRef(result: this): this;
292
+ fractToRef<R extends I>(result: R): R;
292
293
  /**
293
294
  * Gets a new instance copied from the instance
294
295
  * @returns a new instance
295
296
  */
296
- clone(): this;
297
+ clone(): Tensor<V, I>;
297
298
  }
298
299
  /**
299
300
  * Static side of Tensor
301
+ * @see Tensor
300
302
  */
301
- export interface TensorStatic<T extends Tensor<any[]>> {
303
+ export interface TensorStatic<T extends Tensor<any[], _I>, _I = TensorLike<T>> {
302
304
  /**
303
305
  * Creates a new instance from the given coordinates
304
306
  */
@@ -348,42 +350,42 @@ export interface TensorStatic<T extends Tensor<any[]>> {
348
350
  * @param right defines second instance
349
351
  * @returns the dot product (float)
350
352
  */
351
- Dot(left: DeepImmutable<T>, right: DeepImmutable<T>): number;
353
+ Dot(left: DeepImmutable<_I>, right: DeepImmutable<_I>): number;
352
354
  /**
353
355
  * Gets a new instance set with the minimal coordinate values from the "left" and "right" instances
354
356
  * @param left defines 1st instance
355
357
  * @param right defines 2nd instance
356
358
  * @returns a new instance
357
359
  */
358
- Minimize(left: DeepImmutable<T>, right: DeepImmutable<T>): T;
360
+ Minimize(left: DeepImmutable<_I>, right: DeepImmutable<_I>): T;
359
361
  /**
360
362
  * Gets a new instance set with the maximal coordinate values from the "left" and "right" instances
361
363
  * @param left defines 1st instance
362
364
  * @param right defines 2nd instance
363
365
  * @returns a new instance
364
366
  */
365
- Maximize(left: DeepImmutable<T>, right: DeepImmutable<T>): T;
367
+ Maximize(left: DeepImmutable<_I>, right: DeepImmutable<_I>): T;
366
368
  /**
367
369
  * Gets the distance between the instances "value1" and "value2"
368
370
  * @param value1 defines first instance
369
371
  * @param value2 defines second instance
370
372
  * @returns the distance between instances
371
373
  */
372
- Distance(value1: DeepImmutable<T>, value2: DeepImmutable<T>): number;
374
+ Distance(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>): number;
373
375
  /**
374
376
  * Returns the squared distance between the instances "value1" and "value2"
375
377
  * @param value1 defines first instance
376
378
  * @param value2 defines second instance
377
379
  * @returns the squared distance between instances
378
380
  */
379
- DistanceSquared(value1: DeepImmutable<T>, value2: DeepImmutable<T>): number;
381
+ DistanceSquared(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>): number;
380
382
  /**
381
383
  * Gets a new instance located at the center of the instances "value1" and "value2"
382
384
  * @param value1 defines first instance
383
385
  * @param value2 defines second instance
384
386
  * @returns a new instance
385
387
  */
386
- Center(value1: DeepImmutable<T>, value2: DeepImmutable<T>): T;
388
+ Center(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>): T;
387
389
  /**
388
390
  * Gets the center of the instances "value1" and "value2" and stores the result in the instance "ref"
389
391
  * @param value1 defines first instance
@@ -391,7 +393,7 @@ export interface TensorStatic<T extends Tensor<any[]>> {
391
393
  * @param ref defines third instance
392
394
  * @returns ref
393
395
  */
394
- CenterToRef(value1: DeepImmutable<T>, value2: DeepImmutable<T>, ref: T): T;
396
+ CenterToRef(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>, ref: T): T;
395
397
  /**
396
398
  * Returns a new instance set with same the coordinates than "value" ones if the instance "value" is in the square defined by "min" and "max".
397
399
  * If a coordinate of "value" is lower than "min" coordinates, the returned instance is given this "min" coordinate.
@@ -401,7 +403,7 @@ export interface TensorStatic<T extends Tensor<any[]>> {
401
403
  * @param max defines the upper limit
402
404
  * @returns a new instance
403
405
  */
404
- Clamp(value: DeepImmutable<T>, min: DeepImmutable<T>, max: DeepImmutable<T>): T;
406
+ Clamp(value: DeepImmutable<_I>, min: DeepImmutable<_I>, max: DeepImmutable<_I>): T;
405
407
  /**
406
408
  * Returns a new instance set with same the coordinates than "value" ones if the instance "value" is in the square defined by "min" and "max".
407
409
  * If a coordinate of "value" is lower than "min" coordinates, the returned instance is given this "min" coordinate.
@@ -412,6 +414,6 @@ export interface TensorStatic<T extends Tensor<any[]>> {
412
414
  * @param result defines the instance where to store the result
413
415
  * @returns the updated result instance
414
416
  */
415
- ClampToRef(value: DeepImmutable<T>, min: DeepImmutable<T>, max: DeepImmutable<T>, result: T): T;
417
+ ClampToRef(value: DeepImmutable<_I>, min: DeepImmutable<_I>, max: DeepImmutable<_I>, result: T): T;
416
418
  }
417
419
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"tensor.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/tensor.ts"],"names":[],"mappings":";AAoeA,wDAAwD","sourcesContent":["import type { DeepImmutable, Flatten, FloatArray, Length, Tuple } from \"../types\";\r\n/**\r\n * Computes the tensor dimension of a multi-dimensional array\r\n */\r\nexport type Dimension<T> = T extends Array<infer U> ? [Length<T>, ...Dimension<U>] : T extends readonly [infer U, ...infer R] ? [Length<T>, ...Dimension<U>] : [];\r\n\r\n/**\r\n * Possible values for a Tensor\r\n */\r\nexport type TensorValue = number[] | TensorValue[];\r\n\r\n/**\r\n * Extracts the value type of a Tensor\r\n */\r\nexport type ValueOfTensor<T = unknown> = T extends Tensor<infer V> ? V : TensorValue;\r\n\r\ntype TensorNumberArray<V extends TensorValue> = Length<Dimension<V>> extends 2 ? Tuple<number, 16> : V;\r\n\r\n/**\r\n * Describes a mathematical tensor.\r\n * @see https://wikipedia.org/wiki/Tensor\r\n */\r\nexport interface Tensor<V extends TensorValue = TensorValue> {\r\n /**\r\n * An array of the size of each dimension.\r\n * For example, [3] for a Vector3 and [4,4] for a Matrix\r\n * @remarks\r\n * This is to allow implementations with using a getter\r\n */\r\n readonly dimension: Readonly<Dimension<V>>;\r\n\r\n /**\r\n * The rank of the tensor. This is the same as the length of the tensor's dimension array.\r\n * @remarks\r\n * This is to allow implementations with using a getter\r\n */\r\n readonly rank: number;\r\n\r\n /**\r\n * Gets class name\r\n * @returns the class name\r\n */\r\n\r\n getClassName(): string;\r\n\r\n /**\r\n * Gets current instance hash code\r\n * @returns the instance hash code as a number\r\n */\r\n getHashCode(): number;\r\n\r\n /**\r\n * Sets the instance coordinates in the given array from the given index.\r\n * @param array defines the source array\r\n * @param index defines the offset in source array\r\n * @returns the current instance\r\n */\r\n toArray(array: FloatArray, index?: number): this;\r\n\r\n /**\r\n * Update the current instance from an array\r\n * @param array defines the destination array\r\n * @param index defines the offset in the destination array\r\n * @returns the current instance\r\n */\r\n fromArray(array: DeepImmutable<FloatArray>, index?: number): this;\r\n\r\n /**\r\n * Copy the current instance to an array\r\n * @returns a new array with the instance coordinates.\r\n */\r\n asArray(): TensorNumberArray<V>;\r\n\r\n /**\r\n * Sets the current instance coordinates with the given source coordinates\r\n * @param source defines the source instance\r\n * @returns the current updated instance\r\n */\r\n copyFrom(source: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Sets the instance coordinates with the given floats\r\n * @returns the current updated instance\r\n */\r\n\r\n copyFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Sets the instance coordinates with the given floats\r\n * @returns the current updated instance\r\n */\r\n set(...values: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Sets the instance coordinates to the given value\r\n * @returns the current updated instance\r\n */\r\n setAll(value: number): this;\r\n\r\n /**\r\n * Add another instance with the current one\r\n * @param other defines the other instance\r\n * @returns a new instance set with the addition of the current instance and the given one coordinates\r\n */\r\n add(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the addition of the current instance and the given one coordinates\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n addToRef(other: DeepImmutable<this>, result: this): this;\r\n\r\n /**\r\n * Set the instance coordinates by adding the given instance coordinates\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n addInPlace(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Adds the given coordinates to the current instance\r\n * @param floats the floats to add\r\n * @returns the current updated instance\r\n */\r\n addInPlaceFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Returns a new instance set with the subtracted coordinates of other's coordinates from the current coordinates.\r\n * @param other defines the other instance\r\n * @returns a new instance\r\n */\r\n subtract(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the subtraction of the other's coordinates from the current coordinates.\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n subtractToRef(other: DeepImmutable<this>, result: this): this;\r\n\r\n /**\r\n * Sets the current instance coordinates by subtracting from it the given one coordinates\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n subtractInPlace(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Returns a new instance set with the subtraction of the given floats from the current instance coordinates\r\n * @param floats the coordinates to subtract\r\n * @returns the resulting instance\r\n */\r\n subtractFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Subtracts the given floats from the current instance coordinates and set the given instance \"result\" with this result\r\n * Note: Implementation uses array magic so types may be confusing.\r\n * @param args the coordinates to subtract with the last element as the result\r\n * @returns the result\r\n */\r\n subtractFromFloatsToRef(...args: [...TensorNumberArray<V>, this]): this;\r\n\r\n /**\r\n * Returns a new instance set with the multiplication of the current instance and the given one coordinates\r\n * @param other defines the other instance\r\n * @returns a new instance\r\n */\r\n multiply(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Sets \"result\" coordinates with the multiplication of the current instance and the given one coordinates\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n multiplyToRef(other: DeepImmutable<this>, result: this): this;\r\n\r\n /**\r\n * Multiplies in place the current instance coordinates by the given ones\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n multiplyInPlace(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Gets a new instance set with the instance coordinates multiplied by the given floats\r\n * @returns a new instance\r\n */\r\n multiplyByFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Returns a new instance set with the instance coordinates divided by the given one coordinates\r\n * @param other defines the other instance\r\n * @returns a new instance\r\n */\r\n divide(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the instance coordinates divided by the given one coordinates\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n divideToRef(other: DeepImmutable<this>, result: this): this;\r\n\r\n /**\r\n * Divides the current instance coordinates by the given ones\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n divideInPlace(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Updates the current instance with the minmal coordinate values between its and the given instance ones.\r\n * @param other defines the other instance\r\n * @returns this current updated instance\r\n */\r\n minimizeInPlace(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Updates the current instance with the minmal coordinate values between its and the given floats.\r\n * @param floats defines the floats to compare against\r\n * @returns this current updated instance\r\n */\r\n minimizeInPlaceFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Updates the current instance with the maximal coordinate values between its and the given instance ones.\r\n * @param other defines the other instance\r\n * @returns this current updated instance\r\n */\r\n maximizeInPlace(other: DeepImmutable<this>): this;\r\n\r\n /**\r\n * Updates the current instance with the maximal coordinate values between its and the given floats.\r\n * @param floats defines the floats to compare against\r\n * @returns this current updated instance\r\n */\r\n maximizeInPlaceFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Gets a new instance with current instance negated coordinates\r\n * @returns a new instance\r\n */\r\n negate(): this;\r\n\r\n /**\r\n * Negate this instance in place\r\n * @returns this\r\n */\r\n negateInPlace(): this;\r\n\r\n /**\r\n * Negate the current instance and stores the result in the given instance \"result\" coordinates\r\n * @param result defines the instance object where to store the result\r\n * @returns the result\r\n */\r\n negateToRef(result: this): this;\r\n\r\n /**\r\n * Multiply the instance coordinates by\r\n * @param scale defines the scaling factor\r\n * @returns the current updated instance\r\n */\r\n scaleInPlace(scale: number): this;\r\n\r\n /**\r\n * Returns a new instance scaled by \"scale\" from the current instance\r\n * @param scale defines the scaling factor\r\n * @returns a new instance\r\n */\r\n scale(scale: number): this;\r\n\r\n /**\r\n * Scale the current instance values by a factor to a given instance\r\n * @param scale defines the scale factor\r\n * @param result defines the instance object where to store the result\r\n * @returns result input\r\n */\r\n scaleToRef(scale: number, result: this): this;\r\n\r\n /**\r\n * Scale the current instance values by a factor and add the result to a given instance\r\n * @param scale defines the scale factor\r\n * @param result defines the instance object where to store the result\r\n * @returns result input\r\n */\r\n scaleAndAddToRef(scale: number, result: this): this;\r\n\r\n /**\r\n * Gets a boolean if two instances are equals\r\n * @param other defines the other instance\r\n * @returns true if the given instance coordinates strictly equal the current instance ones\r\n */\r\n equals(other: DeepImmutable<this>): boolean;\r\n\r\n /**\r\n * Gets a boolean if two instances are equals (using an epsilon value)\r\n * @param other defines the other instance\r\n * @param epsilon defines the minimal distance to consider equality\r\n * @returns true if the given instance coordinates are close to the current ones by a distance of epsilon.\r\n */\r\n equalsWithEpsilon(other: DeepImmutable<this>, epsilon?: number): boolean;\r\n\r\n /**\r\n * Returns true if the current Vectoe coordinates equals the given floats\r\n * @param floats defines the coordinates to compare against\r\n * @returns true if both instances are equal\r\n */\r\n equalsToFloats(...floats: TensorNumberArray<V>): boolean;\r\n\r\n /**\r\n * Gets a new instance from current instance floored values\r\n * eg (1.2, 2.31) returns (1, 2)\r\n * @returns a new instance\r\n */\r\n floor(): this;\r\n\r\n /**\r\n * Gets the current instance's floored values and stores them in result\r\n * @param result the instance to store the result in\r\n * @returns the result instance\r\n */\r\n floorToRef(result: this): this;\r\n\r\n /**\r\n * Gets a new instance from current instance fractional values\r\n * eg (1.2, 2.31) returns (0.2, 0.31)\r\n * @returns a new instance\r\n */\r\n fract(): this;\r\n\r\n /**\r\n * Gets the current instance's fractional values and stores them in result\r\n * @param result the instance to store the result in\r\n * @returns the result instance\r\n */\r\n fractToRef(result: this): this;\r\n\r\n /**\r\n * Gets a new instance copied from the instance\r\n * @returns a new instance\r\n */\r\n clone(): this;\r\n}\r\n\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\n/**\r\n * Static side of Tensor\r\n */\r\nexport interface TensorStatic<T extends Tensor<any[]>> {\r\n /**\r\n * Creates a new instance from the given coordinates\r\n */\r\n new (...coords: Flatten<ValueOfTensor<T>>): T;\r\n\r\n /**\r\n * So [[static]].prototype has typings, instead of just any\r\n */\r\n prototype: T;\r\n\r\n /**\r\n * Returns a new instance with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @returns a instance with random values between min and max\r\n */\r\n Random(min?: number, max?: number): T;\r\n\r\n /**\r\n * Returns a new instance with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @param result the result to store the random values in\r\n * @returns the updated result instance\r\n */\r\n RandomToRef(min: number | undefined, max: number | undefined, result: T): T;\r\n\r\n /**\r\n * Gets a new instance from the given index element of the given array\r\n * @param array defines the data source\r\n * @param offset defines the offset in the data source\r\n * @returns a new instance\r\n */\r\n FromArray(array: DeepImmutable<FloatArray>, offset?: number): T;\r\n\r\n /**\r\n * Sets \"result\" from the given index element of the given array\r\n * @param array defines the data source\r\n * @param offset defines the offset in the data source\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n FromArrayToRef(array: DeepImmutable<FloatArray>, offset: number, result: T): T;\r\n\r\n /**\r\n * Sets the given instance \"result\" with the given floats.\r\n * @param args defines the coordinates of the source with the last paramater being the result\r\n */\r\n FromFloatsToRef(...args: [...Flatten<ValueOfTensor<T>>, T]): T;\r\n\r\n /**\r\n * Gets the dot product of the instance \"left\" and the instance \"right\"\r\n * @param left defines first instance\r\n * @param right defines second instance\r\n * @returns the dot product (float)\r\n */\r\n Dot(left: DeepImmutable<T>, right: DeepImmutable<T>): number;\r\n\r\n /**\r\n * Gets a new instance set with the minimal coordinate values from the \"left\" and \"right\" instances\r\n * @param left defines 1st instance\r\n * @param right defines 2nd instance\r\n * @returns a new instance\r\n */\r\n Minimize(left: DeepImmutable<T>, right: DeepImmutable<T>): T;\r\n\r\n /**\r\n * Gets a new instance set with the maximal coordinate values from the \"left\" and \"right\" instances\r\n * @param left defines 1st instance\r\n * @param right defines 2nd instance\r\n * @returns a new instance\r\n */\r\n Maximize(left: DeepImmutable<T>, right: DeepImmutable<T>): T;\r\n\r\n /**\r\n * Gets the distance between the instances \"value1\" and \"value2\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @returns the distance between instances\r\n */\r\n Distance(value1: DeepImmutable<T>, value2: DeepImmutable<T>): number;\r\n\r\n /**\r\n * Returns the squared distance between the instances \"value1\" and \"value2\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @returns the squared distance between instances\r\n */\r\n DistanceSquared(value1: DeepImmutable<T>, value2: DeepImmutable<T>): number;\r\n\r\n /**\r\n * Gets a new instance located at the center of the instances \"value1\" and \"value2\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @returns a new instance\r\n */\r\n Center(value1: DeepImmutable<T>, value2: DeepImmutable<T>): T;\r\n\r\n /**\r\n * Gets the center of the instances \"value1\" and \"value2\" and stores the result in the instance \"ref\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @param ref defines third instance\r\n * @returns ref\r\n */\r\n CenterToRef(value1: DeepImmutable<T>, value2: DeepImmutable<T>, ref: T): T;\r\n\r\n /**\r\n * Returns a new instance set with same the coordinates than \"value\" ones if the instance \"value\" is in the square defined by \"min\" and \"max\".\r\n * If a coordinate of \"value\" is lower than \"min\" coordinates, the returned instance is given this \"min\" coordinate.\r\n * If a coordinate of \"value\" is greater than \"max\" coordinates, the returned instance is given this \"max\" coordinate\r\n * @param value defines the value to clamp\r\n * @param min defines the lower limit\r\n * @param max defines the upper limit\r\n * @returns a new instance\r\n */\r\n Clamp(value: DeepImmutable<T>, min: DeepImmutable<T>, max: DeepImmutable<T>): T;\r\n\r\n /**\r\n * Returns a new instance set with same the coordinates than \"value\" ones if the instance \"value\" is in the square defined by \"min\" and \"max\".\r\n * If a coordinate of \"value\" is lower than \"min\" coordinates, the returned instance is given this \"min\" coordinate.\r\n * If a coordinate of \"value\" is greater than \"max\" coordinates, the returned instance is given this \"max\" coordinate\r\n * @param value defines the value to clamp\r\n * @param min defines the lower limit\r\n * @param max defines the upper limit\r\n * @param result defines the instance where to store the result\r\n * @returns the updated result instance\r\n */\r\n ClampToRef(value: DeepImmutable<T>, min: DeepImmutable<T>, max: DeepImmutable<T>, result: T): T;\r\n}\r\n/* eslint-enable @typescript-eslint/naming-convention */\r\n"]}
1
+ {"version":3,"file":"tensor.js","sourceRoot":"","sources":["../../../../dev/core/src/Maths/tensor.ts"],"names":[],"mappings":";AAueA,wDAAwD","sourcesContent":["import type { DeepImmutable, Flatten, FloatArray, Length, Tuple } from \"../types\";\r\n/**\r\n * Computes the tensor dimension of a multi-dimensional array\r\n */\r\nexport type Dimension<T> = T extends Array<infer U> ? [Length<T>, ...Dimension<U>] : T extends readonly [infer U, ...infer R] ? [Length<T>, ...Dimension<U>] : [];\r\n\r\n/**\r\n * Possible values for a Tensor\r\n */\r\nexport type TensorValue = number[] | TensorValue[];\r\n\r\n/**\r\n * Extracts the value type of a Tensor\r\n */\r\nexport type ValueOfTensor<T = unknown> = T extends Tensor<infer V, any> ? V : TensorValue;\r\n\r\ntype TensorNumberArray<V extends TensorValue> = Length<Dimension<V>> extends 2 ? Tuple<number, 16> : V;\r\n\r\nexport type TensorLike<T> = T extends Tensor<TensorValue, infer I> ? I : never;\r\n\r\n/**\r\n * Describes a mathematical tensor.\r\n * @see https://wikipedia.org/wiki/Tensor\r\n */\r\nexport interface Tensor<V extends TensorValue, I> {\r\n /**\r\n * An array of the size of each dimension.\r\n * For example, [3] for a Vector3 and [4,4] for a Matrix\r\n * @remarks\r\n * This is to allow implementations with using a getter\r\n */\r\n readonly dimension: Readonly<Dimension<V>>;\r\n\r\n /**\r\n * The rank of the tensor. This is the same as the length of the tensor's dimension array.\r\n * @remarks\r\n * This is to allow implementations with using a getter\r\n */\r\n readonly rank: number;\r\n\r\n /**\r\n * Gets class name\r\n * @returns the class name\r\n */\r\n\r\n getClassName(): string;\r\n\r\n /**\r\n * Gets current instance hash code\r\n * @returns the instance hash code as a number\r\n */\r\n getHashCode(): number;\r\n\r\n /**\r\n * Sets the instance coordinates in the given array from the given index.\r\n * @param array defines the source array\r\n * @param index defines the offset in source array\r\n * @returns the current instance\r\n */\r\n toArray(array: FloatArray, index?: number): this;\r\n\r\n /**\r\n * Update the current instance from an array\r\n * @param array defines the destination array\r\n * @param index defines the offset in the destination array\r\n * @returns the current instance\r\n */\r\n fromArray(array: DeepImmutable<FloatArray>, index?: number): this;\r\n\r\n /**\r\n * Copy the current instance to an array\r\n * @returns a new array with the instance coordinates.\r\n */\r\n asArray(): TensorNumberArray<V>;\r\n\r\n /**\r\n * Sets the current instance coordinates with the given source coordinates\r\n * @param source defines the source instance\r\n * @returns the current updated instance\r\n */\r\n copyFrom(source: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Sets the instance coordinates with the given floats\r\n * @returns the current updated instance\r\n */\r\n\r\n copyFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Sets the instance coordinates with the given floats\r\n * @returns the current updated instance\r\n */\r\n set(...values: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Sets the instance coordinates to the given value\r\n * @returns the current updated instance\r\n */\r\n setAll(value: number): this;\r\n\r\n /**\r\n * Add another instance with the current one\r\n * @param other defines the other instance\r\n * @returns a new instance set with the addition of the current instance and the given one coordinates\r\n */\r\n add(other: DeepImmutable<I>): Tensor<V, I>;\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the addition of the current instance and the given one coordinates\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n addToRef<R extends I>(other: DeepImmutable<I>, result: R): R;\r\n\r\n /**\r\n * Set the instance coordinates by adding the given instance coordinates\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n addInPlace(other: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Adds the given coordinates to the current instance\r\n * @param floats the floats to add\r\n * @returns the current updated instance\r\n */\r\n addInPlaceFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Returns a new instance set with the subtracted coordinates of other's coordinates from the current coordinates.\r\n * @param other defines the other instance\r\n * @returns a new instance\r\n */\r\n subtract(other: DeepImmutable<I>): Tensor<V, I>;\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the subtraction of the other's coordinates from the current coordinates.\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n subtractToRef<R extends I>(other: DeepImmutable<I>, result: R): R;\r\n\r\n /**\r\n * Sets the current instance coordinates by subtracting from it the given one coordinates\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n subtractInPlace(other: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Returns a new instance set with the subtraction of the given floats from the current instance coordinates\r\n * @param floats the coordinates to subtract\r\n * @returns the resulting instance\r\n */\r\n subtractFromFloats(...floats: TensorNumberArray<V>): Tensor<V, I>;\r\n\r\n /**\r\n * Subtracts the given floats from the current instance coordinates and set the given instance \"result\" with this result\r\n * Note: Implementation uses array magic so types may be confusing.\r\n * @param args the coordinates to subtract with the last element as the result\r\n * @returns the result\r\n */\r\n subtractFromFloatsToRef<R extends I>(...args: [...TensorNumberArray<V>, R]): R;\r\n\r\n /**\r\n * Returns a new instance set with the multiplication of the current instance and the given one coordinates\r\n * @param other defines the other instance\r\n * @returns a new instance\r\n */\r\n multiply(other: DeepImmutable<I>): Tensor<V, I>;\r\n\r\n /**\r\n * Sets \"result\" coordinates with the multiplication of the current instance and the given one coordinates\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n multiplyToRef<R extends I>(other: DeepImmutable<I>, result: R): R;\r\n\r\n /**\r\n * Multiplies in place the current instance coordinates by the given ones\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n multiplyInPlace(other: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Gets a new instance set with the instance coordinates multiplied by the given floats\r\n * @returns a new instance\r\n */\r\n multiplyByFloats(...floats: TensorNumberArray<V>): Tensor<V, I>;\r\n\r\n /**\r\n * Returns a new instance set with the instance coordinates divided by the given one coordinates\r\n * @param other defines the other instance\r\n * @returns a new instance\r\n */\r\n divide(other: DeepImmutable<I>): Tensor<V, I>;\r\n\r\n /**\r\n * Sets the \"result\" coordinates with the instance coordinates divided by the given one coordinates\r\n * @param other defines the other instance\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n divideToRef<R extends I>(other: DeepImmutable<I>, result: R): R;\r\n\r\n /**\r\n * Divides the current instance coordinates by the given ones\r\n * @param other defines the other instance\r\n * @returns the current updated instance\r\n */\r\n divideInPlace(other: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Updates the current instance with the minmal coordinate values between its and the given instance ones.\r\n * @param other defines the other instance\r\n * @returns this current updated instance\r\n */\r\n minimizeInPlace(other: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Updates the current instance with the minmal coordinate values between its and the given floats.\r\n * @param floats defines the floats to compare against\r\n * @returns this current updated instance\r\n */\r\n minimizeInPlaceFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Updates the current instance with the maximal coordinate values between its and the given instance ones.\r\n * @param other defines the other instance\r\n * @returns this current updated instance\r\n */\r\n maximizeInPlace(other: DeepImmutable<I>): this;\r\n\r\n /**\r\n * Updates the current instance with the maximal coordinate values between its and the given floats.\r\n * @param floats defines the floats to compare against\r\n * @returns this current updated instance\r\n */\r\n maximizeInPlaceFromFloats(...floats: TensorNumberArray<V>): this;\r\n\r\n /**\r\n * Gets a new instance with current instance negated coordinates\r\n * @returns a new instance\r\n */\r\n negate(): Tensor<V, I>;\r\n\r\n /**\r\n * Negate this instance in place\r\n * @returns this\r\n */\r\n negateInPlace(): this;\r\n\r\n /**\r\n * Negate the current instance and stores the result in the given instance \"result\" coordinates\r\n * @param result defines the instance object where to store the result\r\n * @returns the result\r\n */\r\n negateToRef<R extends I>(result: R): R;\r\n\r\n /**\r\n * Multiply the instance coordinates by\r\n * @param scale defines the scaling factor\r\n * @returns the current updated instance\r\n */\r\n scaleInPlace(scale: number): this;\r\n\r\n /**\r\n * Returns a new instance scaled by \"scale\" from the current instance\r\n * @param scale defines the scaling factor\r\n * @returns a new instance\r\n */\r\n scale(scale: number): Tensor<V, I>;\r\n\r\n /**\r\n * Scale the current instance values by a factor to a given instance\r\n * @param scale defines the scale factor\r\n * @param result defines the instance object where to store the result\r\n * @returns result input\r\n */\r\n scaleToRef<R extends I>(scale: number, result: R): R;\r\n\r\n /**\r\n * Scale the current instance values by a factor and add the result to a given instance\r\n * @param scale defines the scale factor\r\n * @param result defines the instance object where to store the result\r\n * @returns result input\r\n */\r\n scaleAndAddToRef<R extends I>(scale: number, result: R): R;\r\n\r\n /**\r\n * Gets a boolean if two instances are equals\r\n * @param other defines the other instance\r\n * @returns true if the given instance coordinates strictly equal the current instance ones\r\n */\r\n equals(other: DeepImmutable<I>): boolean;\r\n\r\n /**\r\n * Gets a boolean if two instances are equals (using an epsilon value)\r\n * @param other defines the other instance\r\n * @param epsilon defines the minimal distance to consider equality\r\n * @returns true if the given instance coordinates are close to the current ones by a distance of epsilon.\r\n */\r\n equalsWithEpsilon(other: DeepImmutable<I>, epsilon?: number): boolean;\r\n\r\n /**\r\n * Returns true if the current Vectoe coordinates equals the given floats\r\n * @param floats defines the coordinates to compare against\r\n * @returns true if both instances are equal\r\n */\r\n equalsToFloats(...floats: TensorNumberArray<V>): boolean;\r\n\r\n /**\r\n * Gets a new instance from current instance floored values\r\n * eg (1.2, 2.31) returns (1, 2)\r\n * @returns a new instance\r\n */\r\n floor(): Tensor<V, I>;\r\n\r\n /**\r\n * Gets the current instance's floored values and stores them in result\r\n * @param result the instance to store the result in\r\n * @returns the result instance\r\n */\r\n floorToRef<R extends I>(result: R): R;\r\n\r\n /**\r\n * Gets a new instance from current instance fractional values\r\n * eg (1.2, 2.31) returns (0.2, 0.31)\r\n * @returns a new instance\r\n */\r\n fract(): Tensor<V, I>;\r\n\r\n /**\r\n * Gets the current instance's fractional values and stores them in result\r\n * @param result the instance to store the result in\r\n * @returns the result instance\r\n */\r\n fractToRef<R extends I>(result: R): R;\r\n\r\n /**\r\n * Gets a new instance copied from the instance\r\n * @returns a new instance\r\n */\r\n clone(): Tensor<V, I>;\r\n}\r\n\r\n/* eslint-disable @typescript-eslint/naming-convention */\r\n/**\r\n * Static side of Tensor\r\n * @see Tensor\r\n */\r\nexport interface TensorStatic<T extends Tensor<any[], _I>, _I = TensorLike<T>> {\r\n /**\r\n * Creates a new instance from the given coordinates\r\n */\r\n new (...coords: Flatten<ValueOfTensor<T>>): T;\r\n\r\n /**\r\n * So [[static]].prototype has typings, instead of just any\r\n */\r\n prototype: T;\r\n\r\n /**\r\n * Returns a new instance with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @returns a instance with random values between min and max\r\n */\r\n Random(min?: number, max?: number): T;\r\n\r\n /**\r\n * Returns a new instance with random values between min and max\r\n * @param min the minimum random value\r\n * @param max the maximum random value\r\n * @param result the result to store the random values in\r\n * @returns the updated result instance\r\n */\r\n RandomToRef(min: number | undefined, max: number | undefined, result: T): T;\r\n\r\n /**\r\n * Gets a new instance from the given index element of the given array\r\n * @param array defines the data source\r\n * @param offset defines the offset in the data source\r\n * @returns a new instance\r\n */\r\n FromArray(array: DeepImmutable<FloatArray>, offset?: number): T;\r\n\r\n /**\r\n * Sets \"result\" from the given index element of the given array\r\n * @param array defines the data source\r\n * @param offset defines the offset in the data source\r\n * @param result defines the target instance\r\n * @returns result input\r\n */\r\n FromArrayToRef(array: DeepImmutable<FloatArray>, offset: number, result: T): T;\r\n\r\n /**\r\n * Sets the given instance \"result\" with the given floats.\r\n * @param args defines the coordinates of the source with the last paramater being the result\r\n */\r\n FromFloatsToRef(...args: [...Flatten<ValueOfTensor<T>>, T]): T;\r\n\r\n /**\r\n * Gets the dot product of the instance \"left\" and the instance \"right\"\r\n * @param left defines first instance\r\n * @param right defines second instance\r\n * @returns the dot product (float)\r\n */\r\n Dot(left: DeepImmutable<_I>, right: DeepImmutable<_I>): number;\r\n\r\n /**\r\n * Gets a new instance set with the minimal coordinate values from the \"left\" and \"right\" instances\r\n * @param left defines 1st instance\r\n * @param right defines 2nd instance\r\n * @returns a new instance\r\n */\r\n Minimize(left: DeepImmutable<_I>, right: DeepImmutable<_I>): T;\r\n\r\n /**\r\n * Gets a new instance set with the maximal coordinate values from the \"left\" and \"right\" instances\r\n * @param left defines 1st instance\r\n * @param right defines 2nd instance\r\n * @returns a new instance\r\n */\r\n Maximize(left: DeepImmutable<_I>, right: DeepImmutable<_I>): T;\r\n\r\n /**\r\n * Gets the distance between the instances \"value1\" and \"value2\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @returns the distance between instances\r\n */\r\n Distance(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>): number;\r\n\r\n /**\r\n * Returns the squared distance between the instances \"value1\" and \"value2\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @returns the squared distance between instances\r\n */\r\n DistanceSquared(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>): number;\r\n\r\n /**\r\n * Gets a new instance located at the center of the instances \"value1\" and \"value2\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @returns a new instance\r\n */\r\n Center(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>): T;\r\n\r\n /**\r\n * Gets the center of the instances \"value1\" and \"value2\" and stores the result in the instance \"ref\"\r\n * @param value1 defines first instance\r\n * @param value2 defines second instance\r\n * @param ref defines third instance\r\n * @returns ref\r\n */\r\n CenterToRef(value1: DeepImmutable<_I>, value2: DeepImmutable<_I>, ref: T): T;\r\n\r\n /**\r\n * Returns a new instance set with same the coordinates than \"value\" ones if the instance \"value\" is in the square defined by \"min\" and \"max\".\r\n * If a coordinate of \"value\" is lower than \"min\" coordinates, the returned instance is given this \"min\" coordinate.\r\n * If a coordinate of \"value\" is greater than \"max\" coordinates, the returned instance is given this \"max\" coordinate\r\n * @param value defines the value to clamp\r\n * @param min defines the lower limit\r\n * @param max defines the upper limit\r\n * @returns a new instance\r\n */\r\n Clamp(value: DeepImmutable<_I>, min: DeepImmutable<_I>, max: DeepImmutable<_I>): T;\r\n\r\n /**\r\n * Returns a new instance set with same the coordinates than \"value\" ones if the instance \"value\" is in the square defined by \"min\" and \"max\".\r\n * If a coordinate of \"value\" is lower than \"min\" coordinates, the returned instance is given this \"min\" coordinate.\r\n * If a coordinate of \"value\" is greater than \"max\" coordinates, the returned instance is given this \"max\" coordinate\r\n * @param value defines the value to clamp\r\n * @param min defines the lower limit\r\n * @param max defines the upper limit\r\n * @param result defines the instance where to store the result\r\n * @returns the updated result instance\r\n */\r\n ClampToRef(value: DeepImmutable<_I>, min: DeepImmutable<_I>, max: DeepImmutable<_I>, result: T): T;\r\n}\r\n/* eslint-enable @typescript-eslint/naming-convention */\r\n"]}
@@ -121,6 +121,13 @@ export declare class DracoCompression implements IDisposable {
121
121
  * Default instance for the draco compression object.
122
122
  */
123
123
  static get Default(): DracoCompression;
124
+ /**
125
+ * Reset the default draco compression object to null and disposing the removed default instance.
126
+ * Note that if the workerPool is a member of the static Configuration object it is recommended not to run dispose,
127
+ * unless the static worker pool is no longer needed.
128
+ * @param skipDispose set to true to not dispose the removed default instance
129
+ */
130
+ static ResetDefault(skipDispose?: boolean): void;
124
131
  /**
125
132
  * Constructor
126
133
  * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.
@@ -72,6 +72,20 @@ export class DracoCompression {
72
72
  }
73
73
  return DracoCompression._Default;
74
74
  }
75
+ /**
76
+ * Reset the default draco compression object to null and disposing the removed default instance.
77
+ * Note that if the workerPool is a member of the static Configuration object it is recommended not to run dispose,
78
+ * unless the static worker pool is no longer needed.
79
+ * @param skipDispose set to true to not dispose the removed default instance
80
+ */
81
+ static ResetDefault(skipDispose) {
82
+ if (DracoCompression._Default) {
83
+ if (!skipDispose) {
84
+ DracoCompression._Default.dispose();
85
+ }
86
+ DracoCompression._Default = null;
87
+ }
88
+ }
75
89
  /**
76
90
  * Constructor
77
91
  * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO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AAU,EAAE;YACzC,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CACvC,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EACxC,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,aAAa,CACzB,CAAC;YAEF,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AAvVD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer, jsModule?: DracoDecoderModule): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n (jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n /**\r\n * Optional worker pool to use for async decoding instead of creating a new worker pool.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The decoder module if already available.\r\n */\r\n jsModule?: any /* DecoderModule */;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (decoder.workerPool || (typeof numWorkers === \"object\" && numWorkers.workerPool)) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(decoder.workerPool || (numWorkers as IDracoCompressionOptions).workerPool!);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === \"object\" && numWorkers.wasmBinary);\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);\r\n // code maintained here for back-compat with no changes\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n if (useWorkers) {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (typeof DracoDecoderModule === \"undefined\") {\r\n if (!decoder.jsModule) {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n }\r\n }\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer, decoder.jsModule);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAoC,cAAc,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAY7H,SAAS,kBAAkB,CAAC,UAAwB,EAAE,QAA6B;IAC/E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,CAAC,QAAQ,IAAI,kBAAkB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC7D,OAAO,CAAC,EA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AAC,UAAU,EACpB,QAAQ,CAAC,aAAa,CACzB,CAAC;YAEF,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AAtWD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer, jsModule?: DracoDecoderModule): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n (jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n /**\r\n * Optional worker pool to use for async decoding instead of creating a new worker pool.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The decoder module if already available.\r\n */\r\n jsModule?: any /* DecoderModule */;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Reset the default draco compression object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static Configuration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoCompression._Default) {\r\n if (!skipDispose) {\r\n DracoCompression._Default.dispose();\r\n }\r\n DracoCompression._Default = null;\r\n }\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (decoder.workerPool || (typeof numWorkers === \"object\" && numWorkers.workerPool)) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(decoder.workerPool || (numWorkers as IDracoCompressionOptions).workerPool!);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === \"object\" && numWorkers.wasmBinary);\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);\r\n // code maintained here for back-compat with no changes\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n if (useWorkers) {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (typeof DracoDecoderModule === \"undefined\") {\r\n if (!decoder.jsModule) {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n }\r\n }\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer, decoder.jsModule);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
@@ -329,6 +329,12 @@ export class NodeGeometryConnectionPoint {
329
329
  serializationObject.inputName = this.name;
330
330
  serializationObject.targetBlockId = this.connectedPoint.ownerBlock.uniqueId;
331
331
  serializationObject.targetConnectionName = this.connectedPoint.name;
332
+ serializationObject.isExposedOnFrame = true;
333
+ serializationObject.exposedPortPosition = this.exposedPortPosition;
334
+ }
335
+ if (this.isExposedOnFrame || this.exposedPortPosition >= 0) {
336
+ serializationObject.isExposedOnFrame = true;
337
+ serializationObject.exposedPortPosition = this.exposedPortPosition;
332
338
  }
333
339
  return serializationObject;
334
340
  }