@babylonjs/core 7.23.1 → 7.25.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 (295) hide show
  1. package/Animations/animation.js +3 -3
  2. package/Animations/animation.js.map +1 -1
  3. package/Audio/sound.js +15 -7
  4. package/Audio/sound.js.map +1 -1
  5. package/Behaviors/Meshes/followBehavior.js +3 -3
  6. package/Behaviors/Meshes/followBehavior.js.map +1 -1
  7. package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js +2 -2
  8. package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js.map +1 -1
  9. package/Compute/computeEffect.js +4 -4
  10. package/Compute/computeEffect.js.map +1 -1
  11. package/Engines/Extensions/engine.prefilteredCubeTexture.js +2 -3
  12. package/Engines/Extensions/engine.prefilteredCubeTexture.js.map +1 -1
  13. package/Engines/Processors/Expressions/shaderDefineExpression.js +1 -1
  14. package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
  15. package/Engines/WebGPU/webgpuHardwareTexture.js +2 -2
  16. package/Engines/WebGPU/webgpuHardwareTexture.js.map +1 -1
  17. package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js +2 -2
  18. package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js.map +1 -1
  19. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +12 -10
  20. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
  21. package/Engines/WebGPU/webgpuTextureHelper.js +2 -2
  22. package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
  23. package/Engines/abstractEngine.js +2 -2
  24. package/Engines/abstractEngine.js.map +1 -1
  25. package/Engines/engineCapabilities.d.ts +2 -0
  26. package/Engines/engineCapabilities.js.map +1 -1
  27. package/Engines/nativeEngine.js +3 -2
  28. package/Engines/nativeEngine.js.map +1 -1
  29. package/Engines/nullEngine.js +1 -0
  30. package/Engines/nullEngine.js.map +1 -1
  31. package/Engines/thinEngine.js +2 -0
  32. package/Engines/thinEngine.js.map +1 -1
  33. package/Engines/webgpuEngine.js +1 -0
  34. package/Engines/webgpuEngine.js.map +1 -1
  35. package/LensFlares/lensFlareSystem.js +2 -2
  36. package/LensFlares/lensFlareSystem.js.map +1 -1
  37. package/Loading/sceneLoader.js +3 -3
  38. package/Loading/sceneLoader.js.map +1 -1
  39. package/Materials/Node/Blocks/Dual/lightBlock.js +17 -8
  40. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  41. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +2 -2
  42. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  43. package/Materials/Node/Blocks/PBR/reflectionBlock.js +1 -2
  44. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  45. package/Materials/Node/Blocks/PBR/refractionBlock.js +1 -2
  46. package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
  47. package/Materials/Node/Blocks/colorMergerBlock.js +1 -1
  48. package/Materials/Node/Blocks/colorMergerBlock.js.map +1 -1
  49. package/Materials/Node/Blocks/vectorMergerBlock.js +1 -1
  50. package/Materials/Node/Blocks/vectorMergerBlock.js.map +1 -1
  51. package/Materials/PBR/pbrBaseMaterial.js +1 -2
  52. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  53. package/Materials/PBR/pbrSubSurfaceConfiguration.js +1 -2
  54. package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
  55. package/Materials/Textures/Filtering/hdrFiltering.d.ts +0 -2
  56. package/Materials/Textures/Filtering/hdrFiltering.js +12 -4
  57. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  58. package/Materials/Textures/Loaders/textureLoaderManager.d.ts +14 -1
  59. package/Materials/Textures/Loaders/textureLoaderManager.js +50 -21
  60. package/Materials/Textures/Loaders/textureLoaderManager.js.map +1 -1
  61. package/Materials/Textures/Procedurals/proceduralTexture.d.ts +15 -1
  62. package/Materials/Textures/Procedurals/proceduralTexture.js +24 -1
  63. package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
  64. package/Materials/Textures/index.d.ts +6 -0
  65. package/Materials/Textures/index.js +8 -0
  66. package/Materials/Textures/index.js.map +1 -1
  67. package/Materials/Textures/texture.js +2 -2
  68. package/Materials/Textures/texture.js.map +1 -1
  69. package/Materials/effect.functions.js +4 -4
  70. package/Materials/effect.functions.js.map +1 -1
  71. package/Maths/math.color.js +6 -7
  72. package/Maths/math.color.js.map +1 -1
  73. package/Maths/math.path.js +5 -5
  74. package/Maths/math.path.js.map +1 -1
  75. package/Maths/math.scalar.d.ts +33 -191
  76. package/Maths/math.scalar.functions.d.ts +147 -0
  77. package/Maths/math.scalar.functions.js +247 -0
  78. package/Maths/math.scalar.functions.js.map +1 -1
  79. package/Maths/math.scalar.js +15 -303
  80. package/Maths/math.scalar.js.map +1 -1
  81. package/Meshes/Builders/decalBuilder.js +3 -3
  82. package/Meshes/Builders/decalBuilder.js.map +1 -1
  83. package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +8 -1
  84. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +30 -13
  85. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  86. package/Meshes/Node/Blocks/conditionBlock.js +2 -2
  87. package/Meshes/Node/Blocks/conditionBlock.js.map +1 -1
  88. package/Meshes/Node/Blocks/geometryOptimizeBlock.js +4 -4
  89. package/Meshes/Node/Blocks/geometryOptimizeBlock.js.map +1 -1
  90. package/Meshes/Node/Blocks/noiseBlock.js +3 -3
  91. package/Meshes/Node/Blocks/noiseBlock.js.map +1 -1
  92. package/Meshes/geodesicMesh.js +3 -3
  93. package/Meshes/geodesicMesh.js.map +1 -1
  94. package/Meshes/trailMesh.js +4 -4
  95. package/Meshes/trailMesh.js.map +1 -1
  96. package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js +7 -7
  97. package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js.map +1 -1
  98. package/Misc/PerformanceViewer/performanceViewerCollector.js +2 -1
  99. package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
  100. package/Misc/basis.js +2 -3
  101. package/Misc/basis.js.map +1 -1
  102. package/Misc/dds.js +9 -9
  103. package/Misc/dds.js.map +1 -1
  104. package/Misc/dumpTools.js +2 -2
  105. package/Misc/dumpTools.js.map +1 -1
  106. package/Misc/environmentTextureTools.js +4 -4
  107. package/Misc/environmentTextureTools.js.map +1 -1
  108. package/Misc/reflector.js +3 -3
  109. package/Misc/reflector.js.map +1 -1
  110. package/Misc/screenshotTools.d.ts +2 -1
  111. package/Misc/screenshotTools.js +3 -2
  112. package/Misc/screenshotTools.js.map +1 -1
  113. package/Misc/tools.d.ts +6 -3
  114. package/Misc/tools.js +5 -3
  115. package/Misc/tools.js.map +1 -1
  116. package/Particles/EmitterTypes/coneParticleEmitter.js +10 -10
  117. package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
  118. package/Particles/EmitterTypes/cylinderParticleEmitter.js +9 -9
  119. package/Particles/EmitterTypes/cylinderParticleEmitter.js.map +1 -1
  120. package/Particles/EmitterTypes/hemisphericParticleEmitter.js +7 -7
  121. package/Particles/EmitterTypes/hemisphericParticleEmitter.js.map +1 -1
  122. package/Particles/EmitterTypes/meshParticleEmitter.js +4 -4
  123. package/Particles/EmitterTypes/meshParticleEmitter.js.map +1 -1
  124. package/Particles/EmitterTypes/pointParticleEmitter.js +4 -4
  125. package/Particles/EmitterTypes/pointParticleEmitter.js.map +1 -1
  126. package/Particles/EmitterTypes/sphereParticleEmitter.js +10 -10
  127. package/Particles/EmitterTypes/sphereParticleEmitter.js.map +1 -1
  128. package/Particles/gpuParticleSystem.js +2 -2
  129. package/Particles/gpuParticleSystem.js.map +1 -1
  130. package/Particles/pointsCloudSystem.js +8 -8
  131. package/Particles/pointsCloudSystem.js.map +1 -1
  132. package/Physics/v1/Plugins/ammoJSPlugin.js +2 -2
  133. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  134. package/Physics/v2/physicsAggregate.js +2 -2
  135. package/Physics/v2/physicsAggregate.js.map +1 -1
  136. package/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline.js +2 -2
  137. package/PostProcesses/RenderPipeline/Pipelines/lensRenderingPipeline.js.map +1 -1
  138. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -2
  139. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  140. package/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline.js +4 -4
  141. package/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline.js.map +1 -1
  142. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js +2 -2
  143. package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
  144. package/PostProcesses/RenderPipeline/postProcessRenderPipeline.d.ts +4 -0
  145. package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js +6 -0
  146. package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
  147. package/PostProcesses/postProcess.d.ts +4 -0
  148. package/PostProcesses/postProcess.js +1 -0
  149. package/PostProcesses/postProcess.js.map +1 -1
  150. package/Rendering/IBLShadows/iblShadowsAccumulationPass.d.ts +0 -2
  151. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js +46 -3
  152. package/Rendering/IBLShadows/iblShadowsAccumulationPass.js.map +1 -1
  153. package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.d.ts +0 -5
  154. package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js +33 -5
  155. package/Rendering/IBLShadows/iblShadowsImportanceSamplingRenderer.js.map +1 -1
  156. package/Rendering/IBLShadows/iblShadowsRenderPipeline.d.ts +8 -3
  157. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +56 -18
  158. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
  159. package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.d.ts +0 -2
  160. package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js +20 -2
  161. package/Rendering/IBLShadows/iblShadowsSpatialBlurPass.js.map +1 -1
  162. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.d.ts +2 -14
  163. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js +108 -36
  164. package/Rendering/IBLShadows/iblShadowsVoxelRenderer.js.map +1 -1
  165. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.d.ts +0 -2
  166. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +23 -11
  167. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
  168. package/Rendering/depthPeelingRenderer.d.ts +7 -3
  169. package/Rendering/depthPeelingRenderer.js +38 -3
  170. package/Rendering/depthPeelingRenderer.js.map +1 -1
  171. package/Rendering/index.d.ts +44 -0
  172. package/Rendering/index.js +46 -0
  173. package/Rendering/index.js.map +1 -1
  174. package/Shaders/iblCombineVoxelGrids.fragment.d.ts +5 -0
  175. package/Shaders/{combineVoxelGrids.fragment.js → iblCombineVoxelGrids.fragment.js} +3 -3
  176. package/Shaders/iblCombineVoxelGrids.fragment.js.map +1 -0
  177. package/Shaders/iblGenerateVoxelMip.fragment.d.ts +5 -0
  178. package/Shaders/{generateVoxelMip.fragment.js → iblGenerateVoxelMip.fragment.js} +3 -3
  179. package/Shaders/iblGenerateVoxelMip.fragment.js.map +1 -0
  180. package/Shaders/iblShadowVoxelTracing.fragment.js +18 -10
  181. package/Shaders/iblShadowVoxelTracing.fragment.js.map +1 -1
  182. package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js +2 -1
  183. package/Shaders/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -1
  184. package/Shaders/{voxelGrid.fragment.d.ts → iblVoxelGrid.fragment.d.ts} +1 -1
  185. package/Shaders/{voxelGrid.fragment.js → iblVoxelGrid.fragment.js} +3 -3
  186. package/Shaders/iblVoxelGrid.fragment.js.map +1 -0
  187. package/Shaders/{voxelSlabDebug.fragment.d.ts → iblVoxelGrid.vertex.d.ts} +1 -1
  188. package/Shaders/{voxelGrid.vertex.js → iblVoxelGrid.vertex.js} +8 -4
  189. package/Shaders/iblVoxelGrid.vertex.js.map +1 -0
  190. package/Shaders/iblVoxelGrid2dArrayDebug.fragment.d.ts +5 -0
  191. package/Shaders/{voxelGrid2dArrayDebug.fragment.js → iblVoxelGrid2dArrayDebug.fragment.js} +3 -3
  192. package/Shaders/iblVoxelGrid2dArrayDebug.fragment.js.map +1 -0
  193. package/Shaders/iblVoxelGrid3dDebug.fragment.d.ts +5 -0
  194. package/Shaders/{voxelGrid3dDebug.fragment.js → iblVoxelGrid3dDebug.fragment.js} +3 -3
  195. package/Shaders/iblVoxelGrid3dDebug.fragment.js.map +1 -0
  196. package/Shaders/{combineVoxelGrids.fragment.d.ts → iblVoxelSlabDebug.fragment.d.ts} +1 -1
  197. package/Shaders/{voxelSlabDebug.fragment.js → iblVoxelSlabDebug.fragment.js} +3 -3
  198. package/Shaders/iblVoxelSlabDebug.fragment.js.map +1 -0
  199. package/Shaders/iblVoxelSlabDebug.vertex.d.ts +5 -0
  200. package/Shaders/{voxelSlabDebug.vertex.js → iblVoxelSlabDebug.vertex.js} +3 -3
  201. package/Shaders/iblVoxelSlabDebug.vertex.js.map +1 -0
  202. package/ShadersWGSL/ShadersInclude/lightFragment.js +7 -7
  203. package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
  204. package/ShadersWGSL/copyTexture3DLayerToTexture.fragment.d.ts +5 -0
  205. package/ShadersWGSL/copyTexture3DLayerToTexture.fragment.js +10 -0
  206. package/ShadersWGSL/copyTexture3DLayerToTexture.fragment.js.map +1 -0
  207. package/ShadersWGSL/default.fragment.js +4 -0
  208. package/ShadersWGSL/default.fragment.js.map +1 -1
  209. package/ShadersWGSL/hdrFiltering.fragment.d.ts +9 -0
  210. package/ShadersWGSL/hdrFiltering.fragment.js +18 -0
  211. package/ShadersWGSL/hdrFiltering.fragment.js.map +1 -0
  212. package/ShadersWGSL/hdrFiltering.vertex.d.ts +5 -0
  213. package/ShadersWGSL/hdrFiltering.vertex.js +16 -0
  214. package/ShadersWGSL/hdrFiltering.vertex.js.map +1 -0
  215. package/ShadersWGSL/iblCombineVoxelGrids.fragment.d.ts +5 -0
  216. package/ShadersWGSL/iblCombineVoxelGrids.fragment.js +10 -0
  217. package/ShadersWGSL/iblCombineVoxelGrids.fragment.js.map +1 -0
  218. package/ShadersWGSL/iblGenerateVoxelMip.fragment.d.ts +5 -0
  219. package/ShadersWGSL/iblGenerateVoxelMip.fragment.js +26 -0
  220. package/ShadersWGSL/iblGenerateVoxelMip.fragment.js.map +1 -0
  221. package/ShadersWGSL/iblShadowAccumulation.fragment.d.ts +5 -0
  222. package/ShadersWGSL/iblShadowAccumulation.fragment.js +24 -0
  223. package/ShadersWGSL/iblShadowAccumulation.fragment.js.map +1 -0
  224. package/ShadersWGSL/iblShadowDebug.fragment.d.ts +5 -0
  225. package/ShadersWGSL/iblShadowDebug.fragment.js +16 -0
  226. package/ShadersWGSL/iblShadowDebug.fragment.js.map +1 -0
  227. package/ShadersWGSL/iblShadowGBufferDebug.fragment.d.ts +5 -0
  228. package/ShadersWGSL/iblShadowGBufferDebug.fragment.js +17 -0
  229. package/ShadersWGSL/iblShadowGBufferDebug.fragment.js.map +1 -0
  230. package/ShadersWGSL/iblShadowSpatialBlur.fragment.d.ts +5 -0
  231. package/ShadersWGSL/iblShadowSpatialBlur.fragment.js +20 -0
  232. package/ShadersWGSL/iblShadowSpatialBlur.fragment.js.map +1 -0
  233. package/ShadersWGSL/iblShadowVoxelTracing.fragment.d.ts +5 -0
  234. package/ShadersWGSL/iblShadowVoxelTracing.fragment.js +163 -0
  235. package/ShadersWGSL/iblShadowVoxelTracing.fragment.js.map +1 -0
  236. package/ShadersWGSL/iblShadowsCdfx.fragment.d.ts +5 -0
  237. package/ShadersWGSL/iblShadowsCdfx.fragment.js +12 -0
  238. package/ShadersWGSL/iblShadowsCdfx.fragment.js.map +1 -0
  239. package/ShadersWGSL/iblShadowsCdfy.fragment.d.ts +5 -0
  240. package/ShadersWGSL/iblShadowsCdfy.fragment.js +33 -0
  241. package/ShadersWGSL/iblShadowsCdfy.fragment.js.map +1 -0
  242. package/ShadersWGSL/iblShadowsCombine.fragment.d.ts +5 -0
  243. package/ShadersWGSL/iblShadowsCombine.fragment.js +10 -0
  244. package/ShadersWGSL/iblShadowsCombine.fragment.js.map +1 -0
  245. package/ShadersWGSL/iblShadowsIcdfx.fragment.d.ts +5 -0
  246. package/ShadersWGSL/iblShadowsIcdfx.fragment.js +18 -0
  247. package/ShadersWGSL/iblShadowsIcdfx.fragment.js.map +1 -0
  248. package/ShadersWGSL/iblShadowsIcdfy.fragment.d.ts +5 -0
  249. package/ShadersWGSL/iblShadowsIcdfy.fragment.js +17 -0
  250. package/ShadersWGSL/iblShadowsIcdfy.fragment.js.map +1 -0
  251. package/ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment.d.ts +5 -0
  252. package/ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment.js +41 -0
  253. package/ShadersWGSL/iblShadowsImportanceSamplingDebug.fragment.js.map +1 -0
  254. package/{Shaders/voxelGrid3dDebug.fragment.d.ts → ShadersWGSL/iblVoxelGrid.fragment.d.ts} +1 -1
  255. package/ShadersWGSL/iblVoxelGrid.fragment.js +15 -0
  256. package/ShadersWGSL/iblVoxelGrid.fragment.js.map +1 -0
  257. package/ShadersWGSL/iblVoxelGrid.vertex.d.ts +5 -0
  258. package/ShadersWGSL/iblVoxelGrid.vertex.js +14 -0
  259. package/ShadersWGSL/iblVoxelGrid.vertex.js.map +1 -0
  260. package/ShadersWGSL/iblVoxelGrid2dArrayDebug.fragment.d.ts +5 -0
  261. package/ShadersWGSL/iblVoxelGrid2dArrayDebug.fragment.js +10 -0
  262. package/ShadersWGSL/iblVoxelGrid2dArrayDebug.fragment.js.map +1 -0
  263. package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.d.ts +5 -0
  264. package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.js +22 -0
  265. package/ShadersWGSL/iblVoxelGrid3dDebug.fragment.js.map +1 -0
  266. package/ShadersWGSL/iblVoxelSlabDebug.fragment.d.ts +5 -0
  267. package/ShadersWGSL/iblVoxelSlabDebug.fragment.js +12 -0
  268. package/ShadersWGSL/iblVoxelSlabDebug.fragment.js.map +1 -0
  269. package/ShadersWGSL/iblVoxelSlabDebug.vertex.d.ts +5 -0
  270. package/ShadersWGSL/iblVoxelSlabDebug.vertex.js +10 -0
  271. package/ShadersWGSL/iblVoxelSlabDebug.vertex.js.map +1 -0
  272. package/{Shaders/generateVoxelMip.fragment.d.ts → ShadersWGSL/oitBackBlend.fragment.d.ts} +1 -1
  273. package/ShadersWGSL/oitBackBlend.fragment.js +11 -0
  274. package/ShadersWGSL/oitBackBlend.fragment.js.map +1 -0
  275. package/{Shaders/voxelGrid.vertex.d.ts → ShadersWGSL/oitFinal.fragment.d.ts} +1 -1
  276. package/ShadersWGSL/oitFinal.fragment.js +14 -0
  277. package/ShadersWGSL/oitFinal.fragment.js.map +1 -0
  278. package/ShadersWGSL/pbr.fragment.js +17 -8
  279. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  280. package/{Shaders/voxelSlabDebug.vertex.d.ts → ShadersWGSL/procedural.vertex.d.ts} +1 -1
  281. package/ShadersWGSL/procedural.vertex.js +16 -0
  282. package/ShadersWGSL/procedural.vertex.js.map +1 -0
  283. package/XR/features/WebXRHandTracking.d.ts +5 -0
  284. package/XR/features/WebXRHandTracking.js +34 -12
  285. package/XR/features/WebXRHandTracking.js.map +1 -1
  286. package/package.json +2 -2
  287. package/Shaders/combineVoxelGrids.fragment.js.map +0 -1
  288. package/Shaders/generateVoxelMip.fragment.js.map +0 -1
  289. package/Shaders/voxelGrid.fragment.js.map +0 -1
  290. package/Shaders/voxelGrid.vertex.js.map +0 -1
  291. package/Shaders/voxelGrid2dArrayDebug.fragment.d.ts +0 -5
  292. package/Shaders/voxelGrid2dArrayDebug.fragment.js.map +0 -1
  293. package/Shaders/voxelGrid3dDebug.fragment.js.map +0 -1
  294. package/Shaders/voxelSlabDebug.fragment.js.map +0 -1
  295. package/Shaders/voxelSlabDebug.vertex.js.map +0 -1
@@ -3,7 +3,7 @@ import { Mesh } from "../Meshes/mesh.js";
3
3
  import { Vector3 } from "../Maths/math.vector.js";
4
4
  import { VertexBuffer } from "../Buffers/buffer.js";
5
5
  import { VertexData } from "../Meshes/mesh.vertexData.js";
6
- import { Scalar } from "../Maths/math.scalar.js";
6
+ import { Lerp } from "../Maths/math.scalar.functions.js";
7
7
  Mesh._TrailMeshParser = (parsedMesh, scene) => {
8
8
  return TrailMesh.Parse(parsedMesh, scene);
9
9
  };
@@ -129,16 +129,16 @@ export class TrailMesh extends Mesh {
129
129
  if (positions && normals) {
130
130
  if (this._doNotTaper) {
131
131
  for (let i = index; i < positions.length; i++) {
132
- positions[i - index] = Scalar.Lerp(positions[i - index], positions[i], this._segments / this._length);
132
+ positions[i - index] = Lerp(positions[i - index], positions[i], this._segments / this._length);
133
133
  }
134
134
  }
135
135
  else {
136
136
  for (let i = index; i < positions.length; i++) {
137
- positions[i - index] = Scalar.Lerp(positions[i - index], positions[i], this._segments / this._length) - (normals[i] / this._length) * this.diameter;
137
+ positions[i - index] = Lerp(positions[i - index], positions[i], this._segments / this._length) - (normals[i] / this._length) * this.diameter;
138
138
  }
139
139
  }
140
140
  for (let i = index; i < normals.length; i++) {
141
- normals[i - index] = Scalar.Lerp(normals[i - index], normals[i], this._segments / this._length);
141
+ normals[i - index] = Lerp(normals[i - index], normals[i], this._segments / this._length);
142
142
  }
143
143
  this._updateSectionVectors();
144
144
  const l = positions.length - 3 * (this._sectionPolygonPointsCount + 1);
@@ -1 +1 @@
1
- {"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/trailMesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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,IAAI,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1F,CAAC;IAED;;;OAGG;IACa,SAAS,CAAC,mBAAwB;QAC9C,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QAErC,mBAAmB,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAU,KAAK,CAAC,UAAe,EAAE,KAAY;QACtD,MAAM,SAAS,GAAG,KAAK,CAAC,eAAe,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,wBAAwB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAE1H,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,yCAAyC,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;SACvF;QAED,MAAM,OAAO,GAAG;YACZ,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,UAAU,CAAC,SAAS;YACrD,MAAM,EAAE,UAAU,CAAC,OAAO;YAC1B,QAAQ,EAAE,UAAU,CAAC,SAAS;YAC9B,QAAQ,EAAE,UAAU,CAAC,0BAA0B;YAC/C,UAAU,EAAE,UAAU,CAAC,WAAW;YAClC,SAAS,EAAE,UAAU,CAAC,UAAU;SACnC,CAAC;QACF,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;CACJ","sourcesContent":["import { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\nMesh._TrailMeshParser = (parsedMesh: any, scene: Scene) => {\r\n return TrailMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Options to be used when creating a trail mesh\r\n */\r\nexport interface ITrailMeshOptions {\r\n /**\r\n * diameter of trailing mesh (default: 1)\r\n */\r\n diameter?: number;\r\n /**\r\n * length of trailing mesh (default: 60)\r\n */\r\n length?: number;\r\n /**\r\n * segments of trailing mesh (default: length)\r\n */\r\n segments?: number;\r\n /**\r\n * sections of trailing mesh (default: 4)\r\n */\r\n sections?: number;\r\n /**\r\n * tapers the trailing mesh (default: false)\r\n */\r\n doNotTaper?: boolean;\r\n /**\r\n * automatically start trailing mesh. (default: true)\r\n */\r\n autoStart?: boolean;\r\n}\r\n\r\n/**\r\n * Class used to create a trail following a mesh\r\n */\r\nexport class TrailMesh extends Mesh {\r\n /**\r\n * The diameter of the trail, i.e. the width of the ribbon.\r\n */\r\n public diameter: number;\r\n\r\n private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _doNotTaper: boolean;\r\n private _length: number;\r\n private _segments: number;\r\n private _sectionPolygonPointsCount: number = 4;\r\n private _sectionVectors: Array<Vector3>;\r\n private _sectionNormalVectors: Array<Vector3>;\r\n private _beforeRenderObserver: Nullable<Observer<Scene>>;\r\n\r\n /**\r\n * Constructor\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param diameter Diameter of trailing mesh. Default is 1.\r\n * @param length Length of trailing mesh. Default is 60.\r\n * @param autoStart Automatically start trailing mesh. Default true.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameter?: number, length?: number, autoStart?: boolean);\r\n\r\n /**\r\n * Constructor\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param options defines the options used to create the mesh.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, options?: ITrailMeshOptions);\r\n\r\n /** @internal */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameterOrOptions?: number | ITrailMeshOptions, length: number = 60, autoStart: boolean = true) {\r\n super(name, scene);\r\n\r\n this._running = false;\r\n this._generator = generator;\r\n\r\n if (typeof diameterOrOptions === \"object\" && diameterOrOptions !== null) {\r\n this.diameter = diameterOrOptions.diameter || 1;\r\n this._length = diameterOrOptions.length || 60;\r\n this._segments = diameterOrOptions.segments ? (diameterOrOptions.segments > this._length ? this._length : diameterOrOptions.segments) : this._length;\r\n this._sectionPolygonPointsCount = diameterOrOptions.sections || 4;\r\n this._doNotTaper = diameterOrOptions.doNotTaper || false;\r\n this._autoStart = diameterOrOptions.autoStart || true;\r\n } else {\r\n this.diameter = diameterOrOptions || 1;\r\n this._length = length;\r\n this._segments = this._length;\r\n this._doNotTaper = false;\r\n this._autoStart = autoStart;\r\n }\r\n\r\n this._sectionVectors = [];\r\n this._sectionNormalVectors = [];\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i] = Vector3.Zero();\r\n this._sectionNormalVectors[i] = Vector3.Zero();\r\n }\r\n this._createMesh();\r\n }\r\n\r\n /**\r\n * \"TrailMesh\"\r\n * @returns \"TrailMesh\"\r\n */\r\n public override getClassName(): string {\r\n return \"TrailMesh\";\r\n }\r\n\r\n private _createMesh(): void {\r\n const data: VertexData = new VertexData();\r\n const positions: Array<number> = [];\r\n const normals: Array<number> = [];\r\n const indices: Array<number> = [];\r\n const uvs: Array<number> = [];\r\n let meshCenter = Vector3.Zero();\r\n if (this._generator instanceof AbstractMesh && this._generator.hasBoundingInfo) {\r\n meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;\r\n } else {\r\n meshCenter = this._generator.absolutePosition;\r\n }\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(i / this._sectionPolygonPointsCount, 0);\r\n }\r\n for (let i: number = 1; i <= this._segments; i++) {\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n const angle = j !== this._sectionPolygonPointsCount ? j * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(j / this._sectionPolygonPointsCount, i / this._segments);\r\n }\r\n const l: number = positions.length / 3 - 2 * (this._sectionPolygonPointsCount + 1);\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount, l + j + this._sectionPolygonPointsCount + 1);\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount + 1, l + j + 1);\r\n }\r\n }\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n data.positions = positions;\r\n data.normals = normals;\r\n data.indices = indices;\r\n data.uvs = uvs;\r\n data.applyToMesh(this, true);\r\n if (this._autoStart) {\r\n this.start();\r\n }\r\n }\r\n\r\n private _updateSectionVectors(): void {\r\n const wm = this._generator.getWorldMatrix();\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n this._sectionVectors[i].copyFromFloats(Math.cos(angle) * this.diameter, Math.sin(angle) * this.diameter, 0);\r\n this._sectionNormalVectors[i].copyFromFloats(Math.cos(angle), Math.sin(angle), 0);\r\n Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);\r\n Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);\r\n }\r\n }\r\n\r\n /**\r\n * Start trailing mesh.\r\n */\r\n public start(): void {\r\n if (!this._running) {\r\n this._running = true;\r\n this._beforeRenderObserver = this.getScene().onBeforeRenderObservable.add(() => {\r\n this.update();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop trailing mesh.\r\n */\r\n public stop(): void {\r\n if (this._beforeRenderObserver && this._running) {\r\n this._running = false;\r\n this.getScene().onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Update trailing mesh geometry.\r\n */\r\n public update(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const index = 3 * (this._sectionPolygonPointsCount + 1);\r\n if (positions && normals) {\r\n if (this._doNotTaper) {\r\n for (let i: number = index; i < positions.length; i++) {\r\n positions[i - index] = Scalar.Lerp(positions[i - index], positions[i], this._segments / this._length);\r\n }\r\n } else {\r\n for (let i: number = index; i < positions.length; i++) {\r\n positions[i - index] = Scalar.Lerp(positions[i - index], positions[i], this._segments / this._length) - (normals[i] / this._length) * this.diameter;\r\n }\r\n }\r\n for (let i: number = index; i < normals.length; i++) {\r\n normals[i - index] = Scalar.Lerp(normals[i - index], normals[i], this._segments / this._length);\r\n }\r\n this._updateSectionVectors();\r\n const l: number = positions.length - 3 * (this._sectionPolygonPointsCount + 1);\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n positions[l + 3 * i] = this._sectionVectors[i].x;\r\n positions[l + 3 * i + 1] = this._sectionVectors[i].y;\r\n positions[l + 3 * i + 2] = this._sectionVectors[i].z;\r\n normals[l + 3 * i] = this._sectionNormalVectors[i].x;\r\n normals[l + 3 * i + 1] = this._sectionNormalVectors[i].y;\r\n normals[l + 3 * i + 2] = this._sectionNormalVectors[i].z;\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Reset trailing mesh geometry.\r\n */\r\n public reset(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n if (positions && normals) {\r\n this._updateSectionVectors();\r\n for (let i: number = 0; i <= this._segments; i++) {\r\n const l: number = 3 * i * (this._sectionPolygonPointsCount + 1);\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n positions[l + 3 * j] = this._sectionVectors[j].x;\r\n positions[l + 3 * j + 1] = this._sectionVectors[j].y;\r\n positions[l + 3 * j + 2] = this._sectionVectors[j].z;\r\n normals[l + 3 * j] = this._sectionNormalVectors[j].x;\r\n normals[l + 3 * j + 1] = this._sectionNormalVectors[j].y;\r\n normals[l + 3 * j + 2] = this._sectionNormalVectors[j].z;\r\n }\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a new TrailMesh object.\r\n * @param name is a string, the name given to the new mesh\r\n * @param newGenerator use new generator object for cloned trail mesh\r\n * @returns a new mesh\r\n */\r\n public override clone(name: string = \"\", newGenerator: TransformNode): TrailMesh {\r\n const options = {\r\n diameter: this.diameter,\r\n length: this._length,\r\n segments: this._segments,\r\n sections: this._sectionPolygonPointsCount,\r\n doNotTaper: this._doNotTaper,\r\n autoStart: this._autoStart,\r\n };\r\n return new TrailMesh(name, newGenerator ?? this._generator, this.getScene(), options);\r\n }\r\n\r\n /**\r\n * Serializes this trail mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public override serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n\r\n serializationObject.generatorId = this._generator.id;\r\n }\r\n\r\n /**\r\n * Parses a serialized trail mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the trail mesh in\r\n * @returns the created trail mesh\r\n */\r\n public static override Parse(parsedMesh: any, scene: Scene): TrailMesh {\r\n const generator = scene.getLastMeshById(parsedMesh.generatorId) ?? scene.getLastTransformNodeById(parsedMesh.generatorId);\r\n\r\n if (!generator) {\r\n throw new Error(\"TrailMesh: generator not found with ID \" + parsedMesh.generatorId);\r\n }\r\n\r\n const options = {\r\n diameter: parsedMesh.diameter ?? parsedMesh._diameter,\r\n length: parsedMesh._length,\r\n segments: parsedMesh._segments,\r\n sections: parsedMesh._sectionPolygonPointsCount,\r\n doNotTaper: parsedMesh._doNotTaper,\r\n autoStart: parsedMesh._autoStart,\r\n };\r\n return new TrailMesh(parsedMesh.name, generator, scene, options);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/trailMesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAItC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAC;AAGtD,IAAI,CAAC,gBAAgB,GAAG,CAAC,UAAe,EAAE,KAAY,EAAE,EAAE;IACtD,OAAO,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC,CAAC;AAgCF;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,IAAI;IAqC/B,gBAAgB;IAChB,YAAY,IAAY,EAAE,SAAwB,EAAE,KAAa,EAAE,iBAA8C,EAAE,SAAiB,EAAE,EAAE,YAAqB,IAAI;QAC7J,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QA3Bf,+BAA0B,GAAW,CAAC,CAAC;QA6B3C,IAAI,CAAC,QAAQ,G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U,EAAE,UAAU,CAAC,WAAW;YAClC,SAAS,EAAE,UAAU,CAAC,UAAU;SACnC,CAAC;QACF,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;CACJ","sourcesContent":["import { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport { Lerp } from \"../Maths/math.scalar.functions\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\nMesh._TrailMeshParser = (parsedMesh: any, scene: Scene) => {\r\n return TrailMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Options to be used when creating a trail mesh\r\n */\r\nexport interface ITrailMeshOptions {\r\n /**\r\n * diameter of trailing mesh (default: 1)\r\n */\r\n diameter?: number;\r\n /**\r\n * length of trailing mesh (default: 60)\r\n */\r\n length?: number;\r\n /**\r\n * segments of trailing mesh (default: length)\r\n */\r\n segments?: number;\r\n /**\r\n * sections of trailing mesh (default: 4)\r\n */\r\n sections?: number;\r\n /**\r\n * tapers the trailing mesh (default: false)\r\n */\r\n doNotTaper?: boolean;\r\n /**\r\n * automatically start trailing mesh. (default: true)\r\n */\r\n autoStart?: boolean;\r\n}\r\n\r\n/**\r\n * Class used to create a trail following a mesh\r\n */\r\nexport class TrailMesh extends Mesh {\r\n /**\r\n * The diameter of the trail, i.e. the width of the ribbon.\r\n */\r\n public diameter: number;\r\n\r\n private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _doNotTaper: boolean;\r\n private _length: number;\r\n private _segments: number;\r\n private _sectionPolygonPointsCount: number = 4;\r\n private _sectionVectors: Array<Vector3>;\r\n private _sectionNormalVectors: Array<Vector3>;\r\n private _beforeRenderObserver: Nullable<Observer<Scene>>;\r\n\r\n /**\r\n * Constructor\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param diameter Diameter of trailing mesh. Default is 1.\r\n * @param length Length of trailing mesh. Default is 60.\r\n * @param autoStart Automatically start trailing mesh. Default true.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameter?: number, length?: number, autoStart?: boolean);\r\n\r\n /**\r\n * Constructor\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param options defines the options used to create the mesh.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, options?: ITrailMeshOptions);\r\n\r\n /** @internal */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameterOrOptions?: number | ITrailMeshOptions, length: number = 60, autoStart: boolean = true) {\r\n super(name, scene);\r\n\r\n this._running = false;\r\n this._generator = generator;\r\n\r\n if (typeof diameterOrOptions === \"object\" && diameterOrOptions !== null) {\r\n this.diameter = diameterOrOptions.diameter || 1;\r\n this._length = diameterOrOptions.length || 60;\r\n this._segments = diameterOrOptions.segments ? (diameterOrOptions.segments > this._length ? this._length : diameterOrOptions.segments) : this._length;\r\n this._sectionPolygonPointsCount = diameterOrOptions.sections || 4;\r\n this._doNotTaper = diameterOrOptions.doNotTaper || false;\r\n this._autoStart = diameterOrOptions.autoStart || true;\r\n } else {\r\n this.diameter = diameterOrOptions || 1;\r\n this._length = length;\r\n this._segments = this._length;\r\n this._doNotTaper = false;\r\n this._autoStart = autoStart;\r\n }\r\n\r\n this._sectionVectors = [];\r\n this._sectionNormalVectors = [];\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i] = Vector3.Zero();\r\n this._sectionNormalVectors[i] = Vector3.Zero();\r\n }\r\n this._createMesh();\r\n }\r\n\r\n /**\r\n * \"TrailMesh\"\r\n * @returns \"TrailMesh\"\r\n */\r\n public override getClassName(): string {\r\n return \"TrailMesh\";\r\n }\r\n\r\n private _createMesh(): void {\r\n const data: VertexData = new VertexData();\r\n const positions: Array<number> = [];\r\n const normals: Array<number> = [];\r\n const indices: Array<number> = [];\r\n const uvs: Array<number> = [];\r\n let meshCenter = Vector3.Zero();\r\n if (this._generator instanceof AbstractMesh && this._generator.hasBoundingInfo) {\r\n meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;\r\n } else {\r\n meshCenter = this._generator.absolutePosition;\r\n }\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(i / this._sectionPolygonPointsCount, 0);\r\n }\r\n for (let i: number = 1; i <= this._segments; i++) {\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n const angle = j !== this._sectionPolygonPointsCount ? j * alpha : 0;\r\n positions.push(meshCenter.x + Math.cos(angle) * this.diameter, meshCenter.y + Math.sin(angle) * this.diameter, meshCenter.z);\r\n uvs.push(j / this._sectionPolygonPointsCount, i / this._segments);\r\n }\r\n const l: number = positions.length / 3 - 2 * (this._sectionPolygonPointsCount + 1);\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount, l + j + this._sectionPolygonPointsCount + 1);\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount + 1, l + j + 1);\r\n }\r\n }\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n data.positions = positions;\r\n data.normals = normals;\r\n data.indices = indices;\r\n data.uvs = uvs;\r\n data.applyToMesh(this, true);\r\n if (this._autoStart) {\r\n this.start();\r\n }\r\n }\r\n\r\n private _updateSectionVectors(): void {\r\n const wm = this._generator.getWorldMatrix();\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n const angle = i !== this._sectionPolygonPointsCount ? i * alpha : 0;\r\n this._sectionVectors[i].copyFromFloats(Math.cos(angle) * this.diameter, Math.sin(angle) * this.diameter, 0);\r\n this._sectionNormalVectors[i].copyFromFloats(Math.cos(angle), Math.sin(angle), 0);\r\n Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);\r\n Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);\r\n }\r\n }\r\n\r\n /**\r\n * Start trailing mesh.\r\n */\r\n public start(): void {\r\n if (!this._running) {\r\n this._running = true;\r\n this._beforeRenderObserver = this.getScene().onBeforeRenderObservable.add(() => {\r\n this.update();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop trailing mesh.\r\n */\r\n public stop(): void {\r\n if (this._beforeRenderObserver && this._running) {\r\n this._running = false;\r\n this.getScene().onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Update trailing mesh geometry.\r\n */\r\n public update(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const index = 3 * (this._sectionPolygonPointsCount + 1);\r\n if (positions && normals) {\r\n if (this._doNotTaper) {\r\n for (let i: number = index; i < positions.length; i++) {\r\n positions[i - index] = Lerp(positions[i - index], positions[i], this._segments / this._length);\r\n }\r\n } else {\r\n for (let i: number = index; i < positions.length; i++) {\r\n positions[i - index] = Lerp(positions[i - index], positions[i], this._segments / this._length) - (normals[i] / this._length) * this.diameter;\r\n }\r\n }\r\n for (let i: number = index; i < normals.length; i++) {\r\n normals[i - index] = Lerp(normals[i - index], normals[i], this._segments / this._length);\r\n }\r\n this._updateSectionVectors();\r\n const l: number = positions.length - 3 * (this._sectionPolygonPointsCount + 1);\r\n for (let i: number = 0; i <= this._sectionPolygonPointsCount; i++) {\r\n positions[l + 3 * i] = this._sectionVectors[i].x;\r\n positions[l + 3 * i + 1] = this._sectionVectors[i].y;\r\n positions[l + 3 * i + 2] = this._sectionVectors[i].z;\r\n normals[l + 3 * i] = this._sectionNormalVectors[i].x;\r\n normals[l + 3 * i + 1] = this._sectionNormalVectors[i].y;\r\n normals[l + 3 * i + 2] = this._sectionNormalVectors[i].z;\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Reset trailing mesh geometry.\r\n */\r\n public reset(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n if (positions && normals) {\r\n this._updateSectionVectors();\r\n for (let i: number = 0; i <= this._segments; i++) {\r\n const l: number = 3 * i * (this._sectionPolygonPointsCount + 1);\r\n for (let j: number = 0; j <= this._sectionPolygonPointsCount; j++) {\r\n positions[l + 3 * j] = this._sectionVectors[j].x;\r\n positions[l + 3 * j + 1] = this._sectionVectors[j].y;\r\n positions[l + 3 * j + 2] = this._sectionVectors[j].z;\r\n normals[l + 3 * j] = this._sectionNormalVectors[j].x;\r\n normals[l + 3 * j + 1] = this._sectionNormalVectors[j].y;\r\n normals[l + 3 * j + 2] = this._sectionNormalVectors[j].z;\r\n }\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a new TrailMesh object.\r\n * @param name is a string, the name given to the new mesh\r\n * @param newGenerator use new generator object for cloned trail mesh\r\n * @returns a new mesh\r\n */\r\n public override clone(name: string = \"\", newGenerator: TransformNode): TrailMesh {\r\n const options = {\r\n diameter: this.diameter,\r\n length: this._length,\r\n segments: this._segments,\r\n sections: this._sectionPolygonPointsCount,\r\n doNotTaper: this._doNotTaper,\r\n autoStart: this._autoStart,\r\n };\r\n return new TrailMesh(name, newGenerator ?? this._generator, this.getScene(), options);\r\n }\r\n\r\n /**\r\n * Serializes this trail mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public override serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n\r\n serializationObject.generatorId = this._generator.id;\r\n }\r\n\r\n /**\r\n * Parses a serialized trail mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the trail mesh in\r\n * @returns the created trail mesh\r\n */\r\n public static override Parse(parsedMesh: any, scene: Scene): TrailMesh {\r\n const generator = scene.getLastMeshById(parsedMesh.generatorId) ?? scene.getLastTransformNodeById(parsedMesh.generatorId);\r\n\r\n if (!generator) {\r\n throw new Error(\"TrailMesh: generator not found with ID \" + parsedMesh.generatorId);\r\n }\r\n\r\n const options = {\r\n diameter: parsedMesh.diameter ?? parsedMesh._diameter,\r\n length: parsedMesh._length,\r\n segments: parsedMesh._segments,\r\n sections: parsedMesh._sectionPolygonPointsCount,\r\n doNotTaper: parsedMesh._doNotTaper,\r\n autoStart: parsedMesh._autoStart,\r\n };\r\n return new TrailMesh(parsedMesh.name, generator, scene, options);\r\n }\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Vector3 } from "../../Maths/math.vector.js";
2
- import { Scalar } from "../../Maths/math.scalar.js";
2
+ import { Clamp } from "../../Maths/math.scalar.functions.js";
3
3
  import { SphericalPolynomial, SphericalHarmonics } from "../../Maths/sphericalPolynomial.js";
4
4
 
5
5
  import { ToLinearSpace } from "../../Maths/math.constants.js";
@@ -135,9 +135,9 @@ export class CubeMapToSphericalPolynomialTools {
135
135
  }
136
136
  // Handle Gamma space textures.
137
137
  if (cubeInfo.gammaSpace) {
138
- r = Math.pow(Scalar.Clamp(r), ToLinearSpace);
139
- g = Math.pow(Scalar.Clamp(g), ToLinearSpace);
140
- b = Math.pow(Scalar.Clamp(b), ToLinearSpace);
138
+ r = Math.pow(Clamp(r), ToLinearSpace);
139
+ g = Math.pow(Clamp(g), ToLinearSpace);
140
+ b = Math.pow(Clamp(b), ToLinearSpace);
141
141
  }
142
142
  // Prevent to explode in case of really high dynamic ranges.
143
143
  // sh 3 would not be enough to accurately represent it.
@@ -152,9 +152,9 @@ export class CubeMapToSphericalPolynomialTools {
152
152
  }
153
153
  }
154
154
  else {
155
- r = Scalar.Clamp(r, 0, max);
156
- g = Scalar.Clamp(g, 0, max);
157
- b = Scalar.Clamp(b, 0, max);
155
+ r = Clamp(r, 0, max);
156
+ g = Clamp(g, 0, max);
157
+ b = Clamp(b, 0, max);
158
158
  }
159
159
  const color = new Color3(r, g, b);
160
160
  sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);
@@ -1 +1 @@
1
- {"version":3,"file":"cubemapToSphericalPolynomial.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/HighDynamicRange/cubemapToSphericalPolynomial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAG1F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,MAAM,mBAAmB;IAMrB,YAAmB,IAAY,EAAE,kBAA2B,EAAE,iBAA0B,EAAE,iBAA0B;QAChH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,iBAAiB,GAAG,iBA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AAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/F,IAAI,mBAAmB,CAAC,MAAM,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACnG,IAAI,mBAAmB,CAAC,OAAO,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnG,IAAI,mBAAmB,CAAC,MAAM,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY;CACrH,CAAC;AAEF,gBAAgB;AACF,gDAAc,GAAG,IAAI,CAAC;AACpC,gBAAgB;AACF,yDAAuB,GAAG,KAAK,CAAC","sourcesContent":["import { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { SphericalPolynomial, SphericalHarmonics } from \"../../Maths/sphericalPolynomial\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { ToLinearSpace } from \"../../Maths/math.constants\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\n\r\nclass FileFaceOrientation {\r\n public name: string;\r\n public worldAxisForNormal: Vector3; // the world axis corresponding to the normal to the face\r\n public worldAxisForFileX: Vector3; // the world axis corresponding to texture right x-axis in file\r\n public worldAxisForFileY: Vector3; // the world axis corresponding to texture down y-axis in file\r\n\r\n public constructor(name: string, worldAxisForNormal: Vector3, worldAxisForFileX: Vector3, worldAxisForFileY: Vector3) {\r\n this.name = name;\r\n this.worldAxisForNormal = worldAxisForNormal;\r\n this.worldAxisForFileX = worldAxisForFileX;\r\n this.worldAxisForFileY = worldAxisForFileY;\r\n }\r\n}\r\n\r\n/**\r\n * Helper class dealing with the extraction of spherical polynomial dataArray\r\n * from a cube map.\r\n */\r\nexport class CubeMapToSphericalPolynomialTools {\r\n private static _FileFaces: FileFaceOrientation[] = [\r\n new FileFaceOrientation(\"right\", new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)), // +X east\r\n new FileFaceOrientation(\"left\", new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, -1, 0)), // -X west\r\n new FileFaceOrientation(\"up\", new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)), // +Y north\r\n new FileFaceOrientation(\"down\", new Vector3(0, -1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1)), // -Y south\r\n new FileFaceOrientation(\"front\", new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0)), // +Z top\r\n new FileFaceOrientation(\"back\", new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0)), // -Z bottom\r\n ];\r\n\r\n /** @internal */\r\n public static MAX_HDRI_VALUE = 4096;\r\n /** @internal */\r\n public static PRESERVE_CLAMPED_COLORS = false;\r\n\r\n /**\r\n * Converts a texture to the according Spherical Polynomial data.\r\n * This extracts the first 3 orders only as they are the only one used in the lighting.\r\n *\r\n * @param texture The texture to extract the information from.\r\n * @returns The Spherical Polynomial data.\r\n */\r\n public static ConvertCubeMapTextureToSphericalPolynomial(texture: BaseTexture): Nullable<Promise<SphericalPolynomial>> {\r\n if (!texture.isCube) {\r\n // Only supports cube Textures currently.\r\n return null;\r\n }\r\n\r\n texture.getScene()?.getEngine().flushFramebuffer();\r\n\r\n const size = texture.getSize().width;\r\n const rightPromise = texture.readPixels(0, undefined, undefined, false);\r\n const leftPromise = texture.readPixels(1, undefined, undefined, false);\r\n\r\n let upPromise: Nullable<Promise<ArrayBufferView>>;\r\n let downPromise: Nullable<Promise<ArrayBufferView>>;\r\n if (texture.isRenderTarget) {\r\n upPromise = texture.readPixels(3, undefined, undefined, false);\r\n downPromise = texture.readPixels(2, undefined, undefined, false);\r\n } else {\r\n upPromise = texture.readPixels(2, undefined, undefined, false);\r\n downPromise = texture.readPixels(3, undefined, undefined, false);\r\n }\r\n\r\n const frontPromise = texture.readPixels(4, undefined, undefined, false);\r\n const backPromise = texture.readPixels(5, undefined, undefined, false);\r\n\r\n const gammaSpace = texture.gammaSpace;\r\n // Always read as RGBA.\r\n const format = Constants.TEXTUREFORMAT_RGBA;\r\n let type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n if (texture.textureType == Constants.TEXTURETYPE_FLOAT || texture.textureType == Constants.TEXTURETYPE_HALF_FLOAT) {\r\n type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n Promise.all([leftPromise, rightPromise, upPromise, downPromise, frontPromise, backPromise]).then(([left, right, up, down, front, back]) => {\r\n const cubeInfo: CubeMapInfo = {\r\n size,\r\n right,\r\n left,\r\n up,\r\n down,\r\n front,\r\n back,\r\n format,\r\n type,\r\n gammaSpace,\r\n };\r\n\r\n resolve(this.ConvertCubeMapToSphericalPolynomial(cubeInfo));\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Compute the area on the unit sphere of the rectangle defined by (x,y) and the origin\r\n * See https://www.rorydriscoll.com/2012/01/15/cubemap-texel-solid-angle/\r\n * @param x\r\n * @param y\r\n * @returns the area\r\n */\r\n private static _AreaElement(x: number, y: number): number {\r\n return Math.atan2(x * y, Math.sqrt(x * x + y * y + 1));\r\n }\r\n\r\n /**\r\n * Converts a cubemap to the according Spherical Polynomial data.\r\n * This extracts the first 3 orders only as they are the only one used in the lighting.\r\n *\r\n * @param cubeInfo The Cube map to extract the information from.\r\n * @returns The Spherical Polynomial data.\r\n */\r\n public static ConvertCubeMapToSphericalPolynomial(cubeInfo: CubeMapInfo): SphericalPolynomial {\r\n const sphericalHarmonics = new SphericalHarmonics();\r\n let totalSolidAngle = 0.0;\r\n\r\n // The (u,v) range is [-1,+1], so the distance between each texel is 2/Size.\r\n const du = 2.0 / cubeInfo.size;\r\n const dv = du;\r\n\r\n const halfTexel = 0.5 * du;\r\n\r\n // The (u,v) of the first texel is half a texel from the corner (-1,-1).\r\n const minUV = halfTexel - 1.0;\r\n\r\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\r\n const fileFace = this._FileFaces[faceIndex];\r\n const dataArray = (<any>cubeInfo)[fileFace.name];\r\n let v = minUV;\r\n\r\n // TODO: we could perform the summation directly into a SphericalPolynomial (SP), which is more efficient than SphericalHarmonic (SH).\r\n // This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.\r\n // Because SP is still linear, so summation is fine in that basis.\r\n const stride = cubeInfo.format === Constants.TEXTUREFORMAT_RGBA ? 4 : 3;\r\n for (let y = 0; y < cubeInfo.size; y++) {\r\n let u = minUV;\r\n\r\n for (let x = 0; x < cubeInfo.size; x++) {\r\n // World direction (not normalised)\r\n const worldDirection = fileFace.worldAxisForFileX.scale(u).add(fileFace.worldAxisForFileY.scale(v)).add(fileFace.worldAxisForNormal);\r\n worldDirection.normalize();\r\n\r\n const deltaSolidAngle =\r\n this._AreaElement(u - halfTexel, v - halfTexel) -\r\n this._AreaElement(u - halfTexel, v + halfTexel) -\r\n this._AreaElement(u + halfTexel, v - halfTexel) +\r\n this._AreaElement(u + halfTexel, v + halfTexel);\r\n\r\n let r = dataArray[y * cubeInfo.size * stride + x * stride + 0];\r\n let g = dataArray[y * cubeInfo.size * stride + x * stride + 1];\r\n let b = dataArray[y * cubeInfo.size * stride + x * stride + 2];\r\n\r\n // Prevent NaN harmonics with extreme HDRI data.\r\n if (isNaN(r)) {\r\n r = 0;\r\n }\r\n if (isNaN(g)) {\r\n g = 0;\r\n }\r\n if (isNaN(b)) {\r\n b = 0;\r\n }\r\n\r\n // Handle Integer types.\r\n if (cubeInfo.type === Constants.TEXTURETYPE_UNSIGNED_INT) {\r\n r /= 255;\r\n g /= 255;\r\n b /= 255;\r\n }\r\n\r\n // Handle Gamma space textures.\r\n if (cubeInfo.gammaSpace) {\r\n r = Math.pow(Scalar.Clamp(r), ToLinearSpace);\r\n g = Math.pow(Scalar.Clamp(g), ToLinearSpace);\r\n b = Math.pow(Scalar.Clamp(b), ToLinearSpace);\r\n }\r\n\r\n // Prevent to explode in case of really high dynamic ranges.\r\n // sh 3 would not be enough to accurately represent it.\r\n const max = this.MAX_HDRI_VALUE;\r\n if (this.PRESERVE_CLAMPED_COLORS) {\r\n const currentMax = Math.max(r, g, b);\r\n if (currentMax > max) {\r\n const factor = max / currentMax;\r\n r *= factor;\r\n g *= factor;\r\n b *= factor;\r\n }\r\n } else {\r\n r = Scalar.Clamp(r, 0, max);\r\n g = Scalar.Clamp(g, 0, max);\r\n b = Scalar.Clamp(b, 0, max);\r\n }\r\n\r\n const color = new Color3(r, g, b);\r\n\r\n sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);\r\n\r\n totalSolidAngle += deltaSolidAngle;\r\n\r\n u += du;\r\n }\r\n\r\n v += dv;\r\n }\r\n }\r\n\r\n // Solid angle for entire sphere is 4*pi\r\n const sphereSolidAngle = 4.0 * Math.PI;\r\n\r\n // Adjust the solid angle to allow for how many faces we processed.\r\n const facesProcessed = 6.0;\r\n const expectedSolidAngle = (sphereSolidAngle * facesProcessed) / 6.0;\r\n\r\n // Adjust the harmonics so that the accumulated solid angle matches the expected solid angle.\r\n // This is needed because the numerical integration over the cube uses a\r\n // small angle approximation of solid angle for each texel (see deltaSolidAngle),\r\n // and also to compensate for accumulative error due to float precision in the summation.\r\n const correctionFactor = expectedSolidAngle / totalSolidAngle;\r\n sphericalHarmonics.scaleInPlace(correctionFactor);\r\n\r\n sphericalHarmonics.convertIncidentRadianceToIrradiance();\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n\r\n return SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"cubemapToSphericalPolynomial.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/HighDynamicRange/cubemapToSphericalPolynomial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAG1F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,MAAM,mBAAmB;IAMrB,YAAmB,IAAY,EAAE,kBAA2B,EAAE,iBAA0B,EAAE,iBAA0B;QAChH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,OAAO,iCAAiC;IAe1C;;;;;;OAMG;IACI,MAAM,CAAC,0CAA0C,CAAC,OAAoB;QACzE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YACjB,yCAAyC;YACzC,OAAO,IAAI,CAAC;SACf;QAED,OAAO,CAAC,QAAQ,EAAE,EA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,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnG,IAAI,mBAAmB,CAAC,MAAM,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY;CACrH,CAAC;AAEF,gBAAgB;AACF,gDAAc,GAAG,IAAI,CAAC;AACpC,gBAAgB;AACF,yDAAuB,GAAG,KAAK,CAAC","sourcesContent":["import { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Clamp } from \"../../Maths/math.scalar.functions\";\r\nimport { SphericalPolynomial, SphericalHarmonics } from \"../../Maths/sphericalPolynomial\";\r\nimport type { BaseTexture } from \"../../Materials/Textures/baseTexture\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { Constants } from \"../../Engines/constants\";\r\nimport type { CubeMapInfo } from \"./panoramaToCubemap\";\r\nimport { ToLinearSpace } from \"../../Maths/math.constants\";\r\nimport { Color3 } from \"../../Maths/math.color\";\r\n\r\nclass FileFaceOrientation {\r\n public name: string;\r\n public worldAxisForNormal: Vector3; // the world axis corresponding to the normal to the face\r\n public worldAxisForFileX: Vector3; // the world axis corresponding to texture right x-axis in file\r\n public worldAxisForFileY: Vector3; // the world axis corresponding to texture down y-axis in file\r\n\r\n public constructor(name: string, worldAxisForNormal: Vector3, worldAxisForFileX: Vector3, worldAxisForFileY: Vector3) {\r\n this.name = name;\r\n this.worldAxisForNormal = worldAxisForNormal;\r\n this.worldAxisForFileX = worldAxisForFileX;\r\n this.worldAxisForFileY = worldAxisForFileY;\r\n }\r\n}\r\n\r\n/**\r\n * Helper class dealing with the extraction of spherical polynomial dataArray\r\n * from a cube map.\r\n */\r\nexport class CubeMapToSphericalPolynomialTools {\r\n private static _FileFaces: FileFaceOrientation[] = [\r\n new FileFaceOrientation(\"right\", new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector3(0, -1, 0)), // +X east\r\n new FileFaceOrientation(\"left\", new Vector3(-1, 0, 0), new Vector3(0, 0, 1), new Vector3(0, -1, 0)), // -X west\r\n new FileFaceOrientation(\"up\", new Vector3(0, 1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)), // +Y north\r\n new FileFaceOrientation(\"down\", new Vector3(0, -1, 0), new Vector3(1, 0, 0), new Vector3(0, 0, -1)), // -Y south\r\n new FileFaceOrientation(\"front\", new Vector3(0, 0, 1), new Vector3(1, 0, 0), new Vector3(0, -1, 0)), // +Z top\r\n new FileFaceOrientation(\"back\", new Vector3(0, 0, -1), new Vector3(-1, 0, 0), new Vector3(0, -1, 0)), // -Z bottom\r\n ];\r\n\r\n /** @internal */\r\n public static MAX_HDRI_VALUE = 4096;\r\n /** @internal */\r\n public static PRESERVE_CLAMPED_COLORS = false;\r\n\r\n /**\r\n * Converts a texture to the according Spherical Polynomial data.\r\n * This extracts the first 3 orders only as they are the only one used in the lighting.\r\n *\r\n * @param texture The texture to extract the information from.\r\n * @returns The Spherical Polynomial data.\r\n */\r\n public static ConvertCubeMapTextureToSphericalPolynomial(texture: BaseTexture): Nullable<Promise<SphericalPolynomial>> {\r\n if (!texture.isCube) {\r\n // Only supports cube Textures currently.\r\n return null;\r\n }\r\n\r\n texture.getScene()?.getEngine().flushFramebuffer();\r\n\r\n const size = texture.getSize().width;\r\n const rightPromise = texture.readPixels(0, undefined, undefined, false);\r\n const leftPromise = texture.readPixels(1, undefined, undefined, false);\r\n\r\n let upPromise: Nullable<Promise<ArrayBufferView>>;\r\n let downPromise: Nullable<Promise<ArrayBufferView>>;\r\n if (texture.isRenderTarget) {\r\n upPromise = texture.readPixels(3, undefined, undefined, false);\r\n downPromise = texture.readPixels(2, undefined, undefined, false);\r\n } else {\r\n upPromise = texture.readPixels(2, undefined, undefined, false);\r\n downPromise = texture.readPixels(3, undefined, undefined, false);\r\n }\r\n\r\n const frontPromise = texture.readPixels(4, undefined, undefined, false);\r\n const backPromise = texture.readPixels(5, undefined, undefined, false);\r\n\r\n const gammaSpace = texture.gammaSpace;\r\n // Always read as RGBA.\r\n const format = Constants.TEXTUREFORMAT_RGBA;\r\n let type = Constants.TEXTURETYPE_UNSIGNED_INT;\r\n if (texture.textureType == Constants.TEXTURETYPE_FLOAT || texture.textureType == Constants.TEXTURETYPE_HALF_FLOAT) {\r\n type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n return new Promise((resolve) => {\r\n Promise.all([leftPromise, rightPromise, upPromise, downPromise, frontPromise, backPromise]).then(([left, right, up, down, front, back]) => {\r\n const cubeInfo: CubeMapInfo = {\r\n size,\r\n right,\r\n left,\r\n up,\r\n down,\r\n front,\r\n back,\r\n format,\r\n type,\r\n gammaSpace,\r\n };\r\n\r\n resolve(this.ConvertCubeMapToSphericalPolynomial(cubeInfo));\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Compute the area on the unit sphere of the rectangle defined by (x,y) and the origin\r\n * See https://www.rorydriscoll.com/2012/01/15/cubemap-texel-solid-angle/\r\n * @param x\r\n * @param y\r\n * @returns the area\r\n */\r\n private static _AreaElement(x: number, y: number): number {\r\n return Math.atan2(x * y, Math.sqrt(x * x + y * y + 1));\r\n }\r\n\r\n /**\r\n * Converts a cubemap to the according Spherical Polynomial data.\r\n * This extracts the first 3 orders only as they are the only one used in the lighting.\r\n *\r\n * @param cubeInfo The Cube map to extract the information from.\r\n * @returns The Spherical Polynomial data.\r\n */\r\n public static ConvertCubeMapToSphericalPolynomial(cubeInfo: CubeMapInfo): SphericalPolynomial {\r\n const sphericalHarmonics = new SphericalHarmonics();\r\n let totalSolidAngle = 0.0;\r\n\r\n // The (u,v) range is [-1,+1], so the distance between each texel is 2/Size.\r\n const du = 2.0 / cubeInfo.size;\r\n const dv = du;\r\n\r\n const halfTexel = 0.5 * du;\r\n\r\n // The (u,v) of the first texel is half a texel from the corner (-1,-1).\r\n const minUV = halfTexel - 1.0;\r\n\r\n for (let faceIndex = 0; faceIndex < 6; faceIndex++) {\r\n const fileFace = this._FileFaces[faceIndex];\r\n const dataArray = (<any>cubeInfo)[fileFace.name];\r\n let v = minUV;\r\n\r\n // TODO: we could perform the summation directly into a SphericalPolynomial (SP), which is more efficient than SphericalHarmonic (SH).\r\n // This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.\r\n // Because SP is still linear, so summation is fine in that basis.\r\n const stride = cubeInfo.format === Constants.TEXTUREFORMAT_RGBA ? 4 : 3;\r\n for (let y = 0; y < cubeInfo.size; y++) {\r\n let u = minUV;\r\n\r\n for (let x = 0; x < cubeInfo.size; x++) {\r\n // World direction (not normalised)\r\n const worldDirection = fileFace.worldAxisForFileX.scale(u).add(fileFace.worldAxisForFileY.scale(v)).add(fileFace.worldAxisForNormal);\r\n worldDirection.normalize();\r\n\r\n const deltaSolidAngle =\r\n this._AreaElement(u - halfTexel, v - halfTexel) -\r\n this._AreaElement(u - halfTexel, v + halfTexel) -\r\n this._AreaElement(u + halfTexel, v - halfTexel) +\r\n this._AreaElement(u + halfTexel, v + halfTexel);\r\n\r\n let r = dataArray[y * cubeInfo.size * stride + x * stride + 0];\r\n let g = dataArray[y * cubeInfo.size * stride + x * stride + 1];\r\n let b = dataArray[y * cubeInfo.size * stride + x * stride + 2];\r\n\r\n // Prevent NaN harmonics with extreme HDRI data.\r\n if (isNaN(r)) {\r\n r = 0;\r\n }\r\n if (isNaN(g)) {\r\n g = 0;\r\n }\r\n if (isNaN(b)) {\r\n b = 0;\r\n }\r\n\r\n // Handle Integer types.\r\n if (cubeInfo.type === Constants.TEXTURETYPE_UNSIGNED_INT) {\r\n r /= 255;\r\n g /= 255;\r\n b /= 255;\r\n }\r\n\r\n // Handle Gamma space textures.\r\n if (cubeInfo.gammaSpace) {\r\n r = Math.pow(Clamp(r), ToLinearSpace);\r\n g = Math.pow(Clamp(g), ToLinearSpace);\r\n b = Math.pow(Clamp(b), ToLinearSpace);\r\n }\r\n\r\n // Prevent to explode in case of really high dynamic ranges.\r\n // sh 3 would not be enough to accurately represent it.\r\n const max = this.MAX_HDRI_VALUE;\r\n if (this.PRESERVE_CLAMPED_COLORS) {\r\n const currentMax = Math.max(r, g, b);\r\n if (currentMax > max) {\r\n const factor = max / currentMax;\r\n r *= factor;\r\n g *= factor;\r\n b *= factor;\r\n }\r\n } else {\r\n r = Clamp(r, 0, max);\r\n g = Clamp(g, 0, max);\r\n b = Clamp(b, 0, max);\r\n }\r\n\r\n const color = new Color3(r, g, b);\r\n\r\n sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);\r\n\r\n totalSolidAngle += deltaSolidAngle;\r\n\r\n u += du;\r\n }\r\n\r\n v += dv;\r\n }\r\n }\r\n\r\n // Solid angle for entire sphere is 4*pi\r\n const sphereSolidAngle = 4.0 * Math.PI;\r\n\r\n // Adjust the solid angle to allow for how many faces we processed.\r\n const facesProcessed = 6.0;\r\n const expectedSolidAngle = (sphereSolidAngle * facesProcessed) / 6.0;\r\n\r\n // Adjust the harmonics so that the accumulated solid angle matches the expected solid angle.\r\n // This is needed because the numerical integration over the cube uses a\r\n // small angle approximation of solid angle for each texel (see deltaSolidAngle),\r\n // and also to compensate for accumulative error due to float precision in the summation.\r\n const correctionFactor = expectedSolidAngle / totalSolidAngle;\r\n sphericalHarmonics.scaleInPlace(correctionFactor);\r\n\r\n sphericalHarmonics.convertIncidentRadianceToIrradiance();\r\n sphericalHarmonics.convertIrradianceToLambertianRadiance();\r\n\r\n return SphericalPolynomial.FromHarmonics(sphericalHarmonics);\r\n }\r\n}\r\n"]}
@@ -199,7 +199,8 @@ export class PerformanceViewerCollector {
199
199
  let hex = "#";
200
200
  for (let i = 0; i < NumberOfBitsInHexcode; i += 8) {
201
201
  const octet = (hash >> i) & 0xff;
202
- hex += (HexPadding + octet.toString(16)).substr(-2);
202
+ const toStr = HexPadding + octet.toString(16);
203
+ hex += toStr.substring(toStr.length - 2);
203
204
  }
204
205
  return hex;
205
206
  }
@@ -1 +1 @@
1
- {"version":3,"file":"performanceViewerCollector.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/PerformanceViewer/performanceViewerCollector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,8DAA8D;AAC9D,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,kEAAkE;AAClE,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,2DAA2D;AAC3D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,uDAAuD;AACvD,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,wFAAwF;AACxF,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAoBlC;;;GAGG;AACH,MAAM,OAAO,0BAA0B;IAuBnC;;OAEG;IACI,MAAM,KAAK,eAAe;QAC7B,OAAO,CAAC,CAAC;IACb,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,oBAAoB;QAClC,OAAO,CAAC,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,YACY,MAAa,EACrB,yBAAiE;QADzD,WAAM,GAAN,MAAM,CAAO;QAuJzB;;;WAGG;QACK,wBAAmB,GAAG,GAAG,EAAE;YAC/B,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC;YAC9D,M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AAC,MAAM,CAAC,uBAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC7E,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC7E,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,QAAS,GAAG,IAAI,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import type { Scene } from \"../../scene\";\r\nimport type { IPerfCustomEvent, IPerfDatasets, IPerfMetadata } from \"../interfaces/iPerfViewer\";\r\nimport { EventState, Observable } from \"../observable\";\r\nimport { PrecisionDate } from \"../precisionDate\";\r\nimport { Tools } from \"../tools\";\r\nimport { DynamicFloat32Array } from \"./dynamicFloat32Array\";\r\nimport type { IPerfViewerCollectionStrategy, PerfStrategyInitialization } from \"./performanceViewerCollectionStrategies\";\r\n\r\n// the initial size of our array, should be a multiple of two!\r\nconst InitialArraySize = 1800;\r\n\r\n// three octets in a hexcode. #[AA][BB][CC], i.e. 24 bits of data.\r\nconst NumberOfBitsInHexcode = 24;\r\n\r\n// Allows single numeral hex numbers to be appended by a 0.\r\nconst HexPadding = \"0\";\r\n\r\n// header for the timestamp column\r\nconst TimestampColHeader = \"timestamp\";\r\n\r\n// header for the numPoints column\r\nconst NumPointsColHeader = \"numPoints\";\r\n\r\n// regex to capture all carriage returns in the string.\r\nconst CarriageReturnRegex = /\\r/g;\r\n\r\n// string to use as separator when exporting extra information along with the dataset id\r\nconst ExportedDataSeparator = \"@\";\r\n\r\n/**\r\n * Callback strategy and optional category for data collection\r\n */\r\ninterface IPerformanceViewerStrategyParameter {\r\n /**\r\n * The strategy for collecting data. Available strategies are located on the PerfCollectionStrategy class\r\n */\r\n strategyCallback: PerfStrategyInitialization;\r\n /**\r\n * Category for displaying this strategy on the viewer. Can be undefined or an empty string, in which case the strategy will be displayed on top\r\n */\r\n category?: string;\r\n /**\r\n * Starts hidden\r\n */\r\n hidden?: boolean;\r\n}\r\n\r\n/**\r\n * The collector class handles the collection and storage of data into the appropriate array.\r\n * The collector also handles notifying any observers of any updates.\r\n */\r\nexport class PerformanceViewerCollector {\r\n private _datasetMeta: Map<string, IPerfMetadata>;\r\n private _strategies: Map<string, IPerfViewerCollectionStrategy>;\r\n private _startingTimestamp: number;\r\n private _hasLoadedData: boolean;\r\n private _isStarted: boolean;\r\n private readonly _customEventObservable: Observable<IPerfCustomEvent>;\r\n private readonly _eventRestoreSet: Set<string>;\r\n\r\n /**\r\n * Datastructure containing the collected datasets. Warning: you should not modify the values in here, data will be of the form [timestamp, numberOfPoints, value1, value2..., timestamp, etc...]\r\n */\r\n public readonly datasets: IPerfDatasets;\r\n /**\r\n * An observable you can attach to get deltas in the dataset. Subscribing to this will increase memory consumption slightly, and may hurt performance due to increased garbage collection needed.\r\n * Updates of slices will be of the form [timestamp, numberOfPoints, value1, value2...].\r\n */\r\n public readonly datasetObservable: Observable<number[]>;\r\n /**\r\n * An observable you can attach to get the most updated map of metadatas.\r\n */\r\n public readonly metadataObservable: Observable<Map<string, IPerfMetadata>>;\r\n\r\n /**\r\n * The offset for when actual data values start appearing inside a slice.\r\n */\r\n public static get SliceDataOffset() {\r\n return 2;\r\n }\r\n\r\n /**\r\n * The offset for the value of the number of points inside a slice.\r\n */\r\n public static get NumberOfPointsOffset() {\r\n return 1;\r\n }\r\n\r\n /**\r\n * Handles the creation of a performance viewer collector.\r\n * @param _scene the scene to collect on.\r\n * @param _enabledStrategyCallbacks the list of data to collect with callbacks for initialization purposes.\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n _enabledStrategyCallbacks?: IPerformanceViewerStrategyParameter[]\r\n ) {\r\n this.datasets = {\r\n ids: [],\r\n data: new DynamicFloat32Array(InitialArraySize),\r\n startingIndices: new DynamicFloat32Array(InitialArraySize),\r\n };\r\n this._strategies = new Map<string, IPerfViewerCollectionStrategy>();\r\n this._datasetMeta = new Map<string, IPerfMetadata>();\r\n this._eventRestoreSet = new Set();\r\n this._customEventObservable = new Observable();\r\n this.datasetObservable = new Observable();\r\n this.metadataObservable = new Observable((observer) => observer.callback(this._datasetMeta, new EventState(0)));\r\n if (_enabledStrategyCallbacks) {\r\n this.addCollectionStrategies(..._enabledStrategyCallbacks);\r\n }\r\n }\r\n\r\n /**\r\n * Registers a custom string event which will be callable via sendEvent. This method returns an event object which will contain the id of the event.\r\n * The user can set a value optionally, which will be used in the sendEvent method. If the value is set, we will record this value at the end of each frame,\r\n * if not we will increment our counter and record the value of the counter at the end of each frame. The value recorded is 0 if no sendEvent method is called, within a frame.\r\n * @param name The name of the event to register\r\n * @param forceUpdate if the code should force add an event, and replace the last one.\r\n * @param category the category for that event\r\n * @returns The event registered, used in sendEvent\r\n */\r\n public registerEvent(name: string, forceUpdate?: boolean, category?: string): IPerfCustomEvent | undefined {\r\n if (this._strategies.has(name) && !forceUpdate) {\r\n return;\r\n }\r\n\r\n if (this._strategies.has(name) && forceUpdate) {\r\n this._strategies.get(name)?.dispose();\r\n this._strategies.delete(name);\r\n }\r\n\r\n const strategy: PerfStrategyInitialization = (scene) => {\r\n let counter: number = 0;\r\n let value: number = 0;\r\n\r\n const afterRenderObserver = scene.onAfterRenderObservable.add(() => {\r\n value = counter;\r\n counter = 0;\r\n });\r\n\r\n const stringObserver = this._customEventObservable.add((eventVal) => {\r\n if (name !== eventVal.name) {\r\n return;\r\n }\r\n\r\n if (eventVal.value !== undefined) {\r\n counter = eventVal.value;\r\n } else {\r\n counter++;\r\n }\r\n });\r\n\r\n return {\r\n id: name,\r\n getData: () => value,\r\n dispose: () => {\r\n scene.onAfterRenderObservable.remove(afterRenderObserver);\r\n this._customEventObservable.remove(stringObserver);\r\n },\r\n };\r\n };\r\n const event: IPerfCustomEvent = {\r\n name,\r\n };\r\n\r\n this._eventRestoreSet.add(name);\r\n this.addCollectionStrategies({ strategyCallback: strategy, category });\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Lets the perf collector handle an event, occurences or event value depending on if the event.value params is set.\r\n * @param event the event to handle an occurence for\r\n */\r\n public sendEvent(event: IPerfCustomEvent) {\r\n this._customEventObservable.notifyObservers(event);\r\n }\r\n\r\n /**\r\n * This event restores all custom string events if necessary.\r\n */\r\n private _restoreStringEvents() {\r\n if (this._eventRestoreSet.size !== this._customEventObservable.observers.length) {\r\n this._eventRestoreSet.forEach((event) => {\r\n this.registerEvent(event, true);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * This method adds additional collection strategies for data collection purposes.\r\n * @param strategyCallbacks the list of data to collect with callbacks.\r\n */\r\n public addCollectionStrategies(...strategyCallbacks: IPerformanceViewerStrategyParameter[]) {\r\n // eslint-disable-next-line prefer-const\r\n for (let { strategyCallback, category, hidden } of strategyCallbacks) {\r\n const strategy = strategyCallback(this._scene);\r\n if (this._strategies.has(strategy.id)) {\r\n strategy.dispose();\r\n continue;\r\n }\r\n\r\n this.datasets.ids.push(strategy.id);\r\n\r\n if (category) {\r\n category = category.replace(new RegExp(ExportedDataSeparator, \"g\"), \"\");\r\n }\r\n\r\n this._datasetMeta.set(strategy.id, {\r\n color: this._getHexColorFromId(strategy.id),\r\n category,\r\n hidden,\r\n });\r\n\r\n this._strategies.set(strategy.id, strategy);\r\n }\r\n\r\n this.metadataObservable.notifyObservers(this._datasetMeta);\r\n }\r\n\r\n /**\r\n * Gets a 6 character hexcode representing the colour from a passed in string.\r\n * @param id the string to get a hex code for.\r\n * @returns a hexcode hashed from the id.\r\n */\r\n private _getHexColorFromId(id: string) {\r\n // this first bit is just a known way of hashing a string.\r\n let hash = 0;\r\n for (let i = 0; i < id.length; i++) {\r\n // (hash << 5) - hash is the same as hash * 31\r\n hash = id.charCodeAt(i) + ((hash << 5) - hash);\r\n }\r\n\r\n // then we build the string octet by octet.\r\n let hex = \"#\";\r\n for (let i = 0; i < NumberOfBitsInHexcode; i += 8) {\r\n const octet = (hash >> i) & 0xff;\r\n hex += (HexPadding + octet.toString(16)).substr(-2);\r\n }\r\n\r\n return hex;\r\n }\r\n\r\n /**\r\n * Collects data for every dataset by using the appropriate strategy. This is called every frame.\r\n * This method will then notify all observers with the latest slice.\r\n */\r\n private _collectDataAtFrame = () => {\r\n const timestamp = PrecisionDate.Now - this._startingTimestamp;\r\n const numPoints = this.datasets.ids.length;\r\n\r\n // add the starting index for the slice\r\n const numberOfIndices = this.datasets.startingIndices.itemLength;\r\n let startingIndex = 0;\r\n\r\n if (numberOfIndices > 0) {\r\n const previousStartingIndex = this.datasets.startingIndices.at(numberOfIndices - 1);\r\n startingIndex =\r\n previousStartingIndex + this.datasets.data.at(previousStartingIndex + PerformanceViewerCollector.NumberOfPointsOffset) + PerformanceViewerCollector.SliceDataOffset;\r\n }\r\n\r\n this.datasets.startingIndices.push(startingIndex);\r\n\r\n // add the first 2 items in our slice.\r\n this.datasets.data.push(timestamp);\r\n this.datasets.data.push(numPoints);\r\n\r\n // add the values inside the slice.\r\n this.datasets.ids.forEach((id: string) => {\r\n const strategy = this._strategies.get(id);\r\n\r\n if (!strategy) {\r\n return;\r\n }\r\n\r\n this.datasets.data.push(strategy.getData());\r\n });\r\n\r\n if (this.datasetObservable.hasObservers()) {\r\n const slice: number[] = [timestamp, numPoints];\r\n\r\n for (let i = 0; i < numPoints; i++) {\r\n slice.push(this.datasets.data.at(startingIndex + PerformanceViewerCollector.SliceDataOffset + i));\r\n }\r\n\r\n this.datasetObservable.notifyObservers(slice);\r\n }\r\n };\r\n\r\n /**\r\n * Collects and then sends the latest slice to any observers by using the appropriate strategy when the user wants.\r\n * The slice will be of the form [timestamp, numberOfPoints, value1, value2...]\r\n * This method does not add onto the collected data accessible via the datasets variable.\r\n */\r\n public getCurrentSlice() {\r\n const timestamp = PrecisionDate.Now - this._startingTimestamp;\r\n const numPoints = this.datasets.ids.length;\r\n const slice: number[] = [timestamp, numPoints];\r\n\r\n // add the values inside the slice.\r\n this.datasets.ids.forEach((id: string) => {\r\n const strategy = this._strategies.get(id);\r\n\r\n if (!strategy) {\r\n return;\r\n }\r\n\r\n if (this.datasetObservable.hasObservers()) {\r\n slice.push(strategy.getData());\r\n }\r\n });\r\n\r\n if (this.datasetObservable.hasObservers()) {\r\n this.datasetObservable.notifyObservers(slice);\r\n }\r\n }\r\n\r\n /**\r\n * Updates a property for a dataset's metadata with the value provided.\r\n * @param id the id of the dataset which needs its metadata updated.\r\n * @param prop the property to update.\r\n * @param value the value to update the property with.\r\n */\r\n public updateMetadata<T extends keyof IPerfMetadata>(id: string, prop: T, value: IPerfMetadata[T]) {\r\n const meta = this._datasetMeta.get(id);\r\n\r\n if (!meta) {\r\n return;\r\n }\r\n\r\n meta[prop] = value;\r\n\r\n this.metadataObservable.notifyObservers(this._datasetMeta);\r\n }\r\n\r\n /**\r\n * Completely clear, data, ids, and strategies saved to this performance collector.\r\n * @param preserveStringEventsRestore if it should preserve the string events, by default will clear string events registered when called.\r\n */\r\n public clear(preserveStringEventsRestore?: boolean) {\r\n this.datasets.data = new DynamicFloat32Array(InitialArraySize);\r\n this.datasets.ids.length = 0;\r\n this.datasets.startingIndices = new DynamicFloat32Array(InitialArraySize);\r\n this._datasetMeta.clear();\r\n this._strategies.forEach((strategy) => strategy.dispose());\r\n this._strategies.clear();\r\n\r\n if (!preserveStringEventsRestore) {\r\n this._eventRestoreSet.clear();\r\n }\r\n this._hasLoadedData = false;\r\n }\r\n\r\n /**\r\n * Accessor which lets the caller know if the performance collector has data loaded from a file or not!\r\n * Call clear() to reset this value.\r\n * @returns true if the data is loaded from a file, false otherwise.\r\n */\r\n public get hasLoadedData(): boolean {\r\n return this._hasLoadedData;\r\n }\r\n\r\n /**\r\n * Given a string containing file data, this function parses the file data into the datasets object.\r\n * It returns a boolean to indicate if this object was successfully loaded with the data.\r\n * @param data string content representing the file data.\r\n * @param keepDatasetMeta if it should use reuse the existing dataset metadata\r\n * @returns true if the data was successfully loaded, false otherwise.\r\n */\r\n public loadFromFileData(data: string, keepDatasetMeta?: boolean): boolean {\r\n const lines = data\r\n .replace(CarriageReturnRegex, \"\")\r\n .split(\"\\n\")\r\n .map((line) => line.split(\",\").filter((s) => s.length > 0))\r\n .filter((line) => line.length > 0);\r\n const timestampIndex = 0;\r\n const numPointsIndex = PerformanceViewerCollector.NumberOfPointsOffset;\r\n if (lines.length < 2) {\r\n return false;\r\n }\r\n\r\n const parsedDatasets: IPerfDatasets = {\r\n ids: [],\r\n data: new DynamicFloat32Array(InitialArraySize),\r\n startingIndices: new DynamicFloat32Array(InitialArraySize),\r\n };\r\n\r\n // parse first line separately to populate ids!\r\n const [firstLine, ...dataLines] = lines;\r\n // make sure we have the correct beginning headers\r\n if (firstLine.length < 2 || firstLine[timestampIndex] !== TimestampColHeader || firstLine[numPointsIndex] !== NumPointsColHeader) {\r\n return false;\r\n }\r\n\r\n const idCategoryMap: Map<string, string> = new Map<string, string>();\r\n\r\n // populate the ids.\r\n for (let i = PerformanceViewerCollector.SliceDataOffset; i < firstLine.length; i++) {\r\n const [id, category] = firstLine[i].split(ExportedDataSeparator);\r\n parsedDatasets.ids.push(id);\r\n idCategoryMap.set(id, category);\r\n }\r\n\r\n let startingIndex = 0;\r\n for (const line of dataLines) {\r\n if (line.length < 2) {\r\n return false;\r\n }\r\n\r\n const timestamp = parseFloat(line[timestampIndex]);\r\n const numPoints = parseInt(line[numPointsIndex]);\r\n\r\n if (isNaN(numPoints) || isNaN(timestamp)) {\r\n return false;\r\n }\r\n\r\n parsedDatasets.data.push(timestamp);\r\n parsedDatasets.data.push(numPoints);\r\n\r\n if (numPoints + PerformanceViewerCollector.SliceDataOffset !== line.length) {\r\n return false;\r\n }\r\n\r\n for (let i = PerformanceViewerCollector.SliceDataOffset; i < line.length; i++) {\r\n const val = parseFloat(line[i]);\r\n if (isNaN(val)) {\r\n return false;\r\n }\r\n parsedDatasets.data.push(val);\r\n }\r\n\r\n parsedDatasets.startingIndices.push(startingIndex);\r\n startingIndex += line.length;\r\n }\r\n\r\n this.datasets.ids = parsedDatasets.ids;\r\n this.datasets.data = parsedDatasets.data;\r\n this.datasets.startingIndices = parsedDatasets.startingIndices;\r\n if (!keepDatasetMeta) {\r\n this._datasetMeta.clear();\r\n }\r\n this._strategies.forEach((strategy) => strategy.dispose());\r\n this._strategies.clear();\r\n\r\n // populate metadata.\r\n if (!keepDatasetMeta) {\r\n for (const id of this.datasets.ids) {\r\n const category = idCategoryMap.get(id);\r\n\r\n this._datasetMeta.set(id, { category, color: this._getHexColorFromId(id) });\r\n }\r\n }\r\n this.metadataObservable.notifyObservers(this._datasetMeta);\r\n this._hasLoadedData = true;\r\n return true;\r\n }\r\n\r\n /**\r\n * Exports the datasets inside of the collector to a csv.\r\n */\r\n public exportDataToCsv() {\r\n let csvContent = \"\";\r\n // create the header line.\r\n csvContent += `${TimestampColHeader},${NumPointsColHeader}`;\r\n for (let i = 0; i < this.datasets.ids.length; i++) {\r\n csvContent += `,${this.datasets.ids[i]}`;\r\n if (this._datasetMeta) {\r\n const meta = this._datasetMeta.get(this.datasets.ids[i]);\r\n if (meta?.category) {\r\n csvContent += `${ExportedDataSeparator}${meta.category}`;\r\n }\r\n }\r\n }\r\n csvContent += \"\\n\";\r\n // create the data lines\r\n for (let i = 0; i < this.datasets.startingIndices.itemLength; i++) {\r\n const startingIndex = this.datasets.startingIndices.at(i);\r\n const timestamp = this.datasets.data.at(startingIndex);\r\n const numPoints = this.datasets.data.at(startingIndex + PerformanceViewerCollector.NumberOfPointsOffset);\r\n\r\n csvContent += `${timestamp},${numPoints}`;\r\n\r\n for (let offset = 0; offset < numPoints; offset++) {\r\n csvContent += `,${this.datasets.data.at(startingIndex + PerformanceViewerCollector.SliceDataOffset + offset)}`;\r\n }\r\n\r\n // add extra commas.\r\n for (let diff = 0; diff < this.datasets.ids.length - numPoints; diff++) {\r\n csvContent += \",\";\r\n }\r\n\r\n csvContent += \"\\n\";\r\n }\r\n\r\n const fileName = `${new Date().toISOString()}-perfdata.csv`;\r\n Tools.Download(new Blob([csvContent], { type: \"text/csv\" }), fileName);\r\n }\r\n /**\r\n * Starts the realtime collection of data.\r\n * @param shouldPreserve optional boolean param, if set will preserve the dataset between calls of start.\r\n */\r\n public start(shouldPreserve?: boolean) {\r\n if (!shouldPreserve) {\r\n this.datasets.data = new DynamicFloat32Array(InitialArraySize);\r\n this.datasets.startingIndices = new DynamicFloat32Array(InitialArraySize);\r\n this._startingTimestamp = PrecisionDate.Now;\r\n } else if (this._startingTimestamp === undefined) {\r\n this._startingTimestamp = PrecisionDate.Now;\r\n }\r\n this._scene.onAfterRenderObservable.add(this._collectDataAtFrame);\r\n this._restoreStringEvents();\r\n this._isStarted = true;\r\n }\r\n\r\n /**\r\n * Stops the collection of data.\r\n */\r\n public stop() {\r\n this._scene.onAfterRenderObservable.removeCallback(this._collectDataAtFrame);\r\n this._isStarted = false;\r\n }\r\n\r\n /**\r\n * Returns if the perf collector has been started or not.\r\n */\r\n public get isStarted(): boolean {\r\n return this._isStarted;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this._scene.onAfterRenderObservable.removeCallback(this._collectDataAtFrame);\r\n this._datasetMeta.clear();\r\n this._strategies.forEach((strategy) => {\r\n strategy.dispose();\r\n });\r\n this.datasetObservable.clear();\r\n this.metadataObservable.clear();\r\n this._isStarted = false;\r\n (<any>this.datasets) = null;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"performanceViewerCollector.js","sourceRoot":"","sources":["../../../../../dev/core/src/Misc/PerformanceViewer/performanceViewerCollector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,8DAA8D;AAC9D,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,kEAAkE;AAClE,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,2DAA2D;AAC3D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAEvC,uDAAuD;AACvD,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,wFAAwF;AACxF,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAoBlC;;;GAGG;AACH,MAAM,OAAO,0BAA0B;IAuBnC;;OAEG;IACI,MAAM,KAAK,eAAe;QAC7B,OAAO,CAAC,CAAC;IACb,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,oBAAoB;QAClC,OAAO,CAAC,CAAC;IACb,CAAC;IAED;;;;OAIG;IACH,YACY,MAAa,EACrB,yBAAiE;QADzD,WAAM,GAAN,MAAM,CAAO;QAwJzB;;;WAGG;QACK,wBAAmB,GAAG,GAAG,EAAE;YAC/B,MAAM,SAAS,GAAG,aAAa,CAAC,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC;YAC9D,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC;YAE3C,uCAAuC;YACvC,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,UAAU,CAA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AAK,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC7E,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAClC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,QAAS,GAAG,IAAI,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import type { Scene } from \"../../scene\";\r\nimport type { IPerfCustomEvent, IPerfDatasets, IPerfMetadata } from \"../interfaces/iPerfViewer\";\r\nimport { EventState, Observable } from \"../observable\";\r\nimport { PrecisionDate } from \"../precisionDate\";\r\nimport { Tools } from \"../tools\";\r\nimport { DynamicFloat32Array } from \"./dynamicFloat32Array\";\r\nimport type { IPerfViewerCollectionStrategy, PerfStrategyInitialization } from \"./performanceViewerCollectionStrategies\";\r\n\r\n// the initial size of our array, should be a multiple of two!\r\nconst InitialArraySize = 1800;\r\n\r\n// three octets in a hexcode. #[AA][BB][CC], i.e. 24 bits of data.\r\nconst NumberOfBitsInHexcode = 24;\r\n\r\n// Allows single numeral hex numbers to be appended by a 0.\r\nconst HexPadding = \"0\";\r\n\r\n// header for the timestamp column\r\nconst TimestampColHeader = \"timestamp\";\r\n\r\n// header for the numPoints column\r\nconst NumPointsColHeader = \"numPoints\";\r\n\r\n// regex to capture all carriage returns in the string.\r\nconst CarriageReturnRegex = /\\r/g;\r\n\r\n// string to use as separator when exporting extra information along with the dataset id\r\nconst ExportedDataSeparator = \"@\";\r\n\r\n/**\r\n * Callback strategy and optional category for data collection\r\n */\r\ninterface IPerformanceViewerStrategyParameter {\r\n /**\r\n * The strategy for collecting data. Available strategies are located on the PerfCollectionStrategy class\r\n */\r\n strategyCallback: PerfStrategyInitialization;\r\n /**\r\n * Category for displaying this strategy on the viewer. Can be undefined or an empty string, in which case the strategy will be displayed on top\r\n */\r\n category?: string;\r\n /**\r\n * Starts hidden\r\n */\r\n hidden?: boolean;\r\n}\r\n\r\n/**\r\n * The collector class handles the collection and storage of data into the appropriate array.\r\n * The collector also handles notifying any observers of any updates.\r\n */\r\nexport class PerformanceViewerCollector {\r\n private _datasetMeta: Map<string, IPerfMetadata>;\r\n private _strategies: Map<string, IPerfViewerCollectionStrategy>;\r\n private _startingTimestamp: number;\r\n private _hasLoadedData: boolean;\r\n private _isStarted: boolean;\r\n private readonly _customEventObservable: Observable<IPerfCustomEvent>;\r\n private readonly _eventRestoreSet: Set<string>;\r\n\r\n /**\r\n * Datastructure containing the collected datasets. Warning: you should not modify the values in here, data will be of the form [timestamp, numberOfPoints, value1, value2..., timestamp, etc...]\r\n */\r\n public readonly datasets: IPerfDatasets;\r\n /**\r\n * An observable you can attach to get deltas in the dataset. Subscribing to this will increase memory consumption slightly, and may hurt performance due to increased garbage collection needed.\r\n * Updates of slices will be of the form [timestamp, numberOfPoints, value1, value2...].\r\n */\r\n public readonly datasetObservable: Observable<number[]>;\r\n /**\r\n * An observable you can attach to get the most updated map of metadatas.\r\n */\r\n public readonly metadataObservable: Observable<Map<string, IPerfMetadata>>;\r\n\r\n /**\r\n * The offset for when actual data values start appearing inside a slice.\r\n */\r\n public static get SliceDataOffset() {\r\n return 2;\r\n }\r\n\r\n /**\r\n * The offset for the value of the number of points inside a slice.\r\n */\r\n public static get NumberOfPointsOffset() {\r\n return 1;\r\n }\r\n\r\n /**\r\n * Handles the creation of a performance viewer collector.\r\n * @param _scene the scene to collect on.\r\n * @param _enabledStrategyCallbacks the list of data to collect with callbacks for initialization purposes.\r\n */\r\n constructor(\r\n private _scene: Scene,\r\n _enabledStrategyCallbacks?: IPerformanceViewerStrategyParameter[]\r\n ) {\r\n this.datasets = {\r\n ids: [],\r\n data: new DynamicFloat32Array(InitialArraySize),\r\n startingIndices: new DynamicFloat32Array(InitialArraySize),\r\n };\r\n this._strategies = new Map<string, IPerfViewerCollectionStrategy>();\r\n this._datasetMeta = new Map<string, IPerfMetadata>();\r\n this._eventRestoreSet = new Set();\r\n this._customEventObservable = new Observable();\r\n this.datasetObservable = new Observable();\r\n this.metadataObservable = new Observable((observer) => observer.callback(this._datasetMeta, new EventState(0)));\r\n if (_enabledStrategyCallbacks) {\r\n this.addCollectionStrategies(..._enabledStrategyCallbacks);\r\n }\r\n }\r\n\r\n /**\r\n * Registers a custom string event which will be callable via sendEvent. This method returns an event object which will contain the id of the event.\r\n * The user can set a value optionally, which will be used in the sendEvent method. If the value is set, we will record this value at the end of each frame,\r\n * if not we will increment our counter and record the value of the counter at the end of each frame. The value recorded is 0 if no sendEvent method is called, within a frame.\r\n * @param name The name of the event to register\r\n * @param forceUpdate if the code should force add an event, and replace the last one.\r\n * @param category the category for that event\r\n * @returns The event registered, used in sendEvent\r\n */\r\n public registerEvent(name: string, forceUpdate?: boolean, category?: string): IPerfCustomEvent | undefined {\r\n if (this._strategies.has(name) && !forceUpdate) {\r\n return;\r\n }\r\n\r\n if (this._strategies.has(name) && forceUpdate) {\r\n this._strategies.get(name)?.dispose();\r\n this._strategies.delete(name);\r\n }\r\n\r\n const strategy: PerfStrategyInitialization = (scene) => {\r\n let counter: number = 0;\r\n let value: number = 0;\r\n\r\n const afterRenderObserver = scene.onAfterRenderObservable.add(() => {\r\n value = counter;\r\n counter = 0;\r\n });\r\n\r\n const stringObserver = this._customEventObservable.add((eventVal) => {\r\n if (name !== eventVal.name) {\r\n return;\r\n }\r\n\r\n if (eventVal.value !== undefined) {\r\n counter = eventVal.value;\r\n } else {\r\n counter++;\r\n }\r\n });\r\n\r\n return {\r\n id: name,\r\n getData: () => value,\r\n dispose: () => {\r\n scene.onAfterRenderObservable.remove(afterRenderObserver);\r\n this._customEventObservable.remove(stringObserver);\r\n },\r\n };\r\n };\r\n const event: IPerfCustomEvent = {\r\n name,\r\n };\r\n\r\n this._eventRestoreSet.add(name);\r\n this.addCollectionStrategies({ strategyCallback: strategy, category });\r\n\r\n return event;\r\n }\r\n\r\n /**\r\n * Lets the perf collector handle an event, occurences or event value depending on if the event.value params is set.\r\n * @param event the event to handle an occurence for\r\n */\r\n public sendEvent(event: IPerfCustomEvent) {\r\n this._customEventObservable.notifyObservers(event);\r\n }\r\n\r\n /**\r\n * This event restores all custom string events if necessary.\r\n */\r\n private _restoreStringEvents() {\r\n if (this._eventRestoreSet.size !== this._customEventObservable.observers.length) {\r\n this._eventRestoreSet.forEach((event) => {\r\n this.registerEvent(event, true);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * This method adds additional collection strategies for data collection purposes.\r\n * @param strategyCallbacks the list of data to collect with callbacks.\r\n */\r\n public addCollectionStrategies(...strategyCallbacks: IPerformanceViewerStrategyParameter[]) {\r\n // eslint-disable-next-line prefer-const\r\n for (let { strategyCallback, category, hidden } of strategyCallbacks) {\r\n const strategy = strategyCallback(this._scene);\r\n if (this._strategies.has(strategy.id)) {\r\n strategy.dispose();\r\n continue;\r\n }\r\n\r\n this.datasets.ids.push(strategy.id);\r\n\r\n if (category) {\r\n category = category.replace(new RegExp(ExportedDataSeparator, \"g\"), \"\");\r\n }\r\n\r\n this._datasetMeta.set(strategy.id, {\r\n color: this._getHexColorFromId(strategy.id),\r\n category,\r\n hidden,\r\n });\r\n\r\n this._strategies.set(strategy.id, strategy);\r\n }\r\n\r\n this.metadataObservable.notifyObservers(this._datasetMeta);\r\n }\r\n\r\n /**\r\n * Gets a 6 character hexcode representing the colour from a passed in string.\r\n * @param id the string to get a hex code for.\r\n * @returns a hexcode hashed from the id.\r\n */\r\n private _getHexColorFromId(id: string) {\r\n // this first bit is just a known way of hashing a string.\r\n let hash = 0;\r\n for (let i = 0; i < id.length; i++) {\r\n // (hash << 5) - hash is the same as hash * 31\r\n hash = id.charCodeAt(i) + ((hash << 5) - hash);\r\n }\r\n\r\n // then we build the string octet by octet.\r\n let hex = \"#\";\r\n for (let i = 0; i < NumberOfBitsInHexcode; i += 8) {\r\n const octet = (hash >> i) & 0xff;\r\n const toStr = HexPadding + octet.toString(16);\r\n hex += toStr.substring(toStr.length - 2);\r\n }\r\n\r\n return hex;\r\n }\r\n\r\n /**\r\n * Collects data for every dataset by using the appropriate strategy. This is called every frame.\r\n * This method will then notify all observers with the latest slice.\r\n */\r\n private _collectDataAtFrame = () => {\r\n const timestamp = PrecisionDate.Now - this._startingTimestamp;\r\n const numPoints = this.datasets.ids.length;\r\n\r\n // add the starting index for the slice\r\n const numberOfIndices = this.datasets.startingIndices.itemLength;\r\n let startingIndex = 0;\r\n\r\n if (numberOfIndices > 0) {\r\n const previousStartingIndex = this.datasets.startingIndices.at(numberOfIndices - 1);\r\n startingIndex =\r\n previousStartingIndex + this.datasets.data.at(previousStartingIndex + PerformanceViewerCollector.NumberOfPointsOffset) + PerformanceViewerCollector.SliceDataOffset;\r\n }\r\n\r\n this.datasets.startingIndices.push(startingIndex);\r\n\r\n // add the first 2 items in our slice.\r\n this.datasets.data.push(timestamp);\r\n this.datasets.data.push(numPoints);\r\n\r\n // add the values inside the slice.\r\n this.datasets.ids.forEach((id: string) => {\r\n const strategy = this._strategies.get(id);\r\n\r\n if (!strategy) {\r\n return;\r\n }\r\n\r\n this.datasets.data.push(strategy.getData());\r\n });\r\n\r\n if (this.datasetObservable.hasObservers()) {\r\n const slice: number[] = [timestamp, numPoints];\r\n\r\n for (let i = 0; i < numPoints; i++) {\r\n slice.push(this.datasets.data.at(startingIndex + PerformanceViewerCollector.SliceDataOffset + i));\r\n }\r\n\r\n this.datasetObservable.notifyObservers(slice);\r\n }\r\n };\r\n\r\n /**\r\n * Collects and then sends the latest slice to any observers by using the appropriate strategy when the user wants.\r\n * The slice will be of the form [timestamp, numberOfPoints, value1, value2...]\r\n * This method does not add onto the collected data accessible via the datasets variable.\r\n */\r\n public getCurrentSlice() {\r\n const timestamp = PrecisionDate.Now - this._startingTimestamp;\r\n const numPoints = this.datasets.ids.length;\r\n const slice: number[] = [timestamp, numPoints];\r\n\r\n // add the values inside the slice.\r\n this.datasets.ids.forEach((id: string) => {\r\n const strategy = this._strategies.get(id);\r\n\r\n if (!strategy) {\r\n return;\r\n }\r\n\r\n if (this.datasetObservable.hasObservers()) {\r\n slice.push(strategy.getData());\r\n }\r\n });\r\n\r\n if (this.datasetObservable.hasObservers()) {\r\n this.datasetObservable.notifyObservers(slice);\r\n }\r\n }\r\n\r\n /**\r\n * Updates a property for a dataset's metadata with the value provided.\r\n * @param id the id of the dataset which needs its metadata updated.\r\n * @param prop the property to update.\r\n * @param value the value to update the property with.\r\n */\r\n public updateMetadata<T extends keyof IPerfMetadata>(id: string, prop: T, value: IPerfMetadata[T]) {\r\n const meta = this._datasetMeta.get(id);\r\n\r\n if (!meta) {\r\n return;\r\n }\r\n\r\n meta[prop] = value;\r\n\r\n this.metadataObservable.notifyObservers(this._datasetMeta);\r\n }\r\n\r\n /**\r\n * Completely clear, data, ids, and strategies saved to this performance collector.\r\n * @param preserveStringEventsRestore if it should preserve the string events, by default will clear string events registered when called.\r\n */\r\n public clear(preserveStringEventsRestore?: boolean) {\r\n this.datasets.data = new DynamicFloat32Array(InitialArraySize);\r\n this.datasets.ids.length = 0;\r\n this.datasets.startingIndices = new DynamicFloat32Array(InitialArraySize);\r\n this._datasetMeta.clear();\r\n this._strategies.forEach((strategy) => strategy.dispose());\r\n this._strategies.clear();\r\n\r\n if (!preserveStringEventsRestore) {\r\n this._eventRestoreSet.clear();\r\n }\r\n this._hasLoadedData = false;\r\n }\r\n\r\n /**\r\n * Accessor which lets the caller know if the performance collector has data loaded from a file or not!\r\n * Call clear() to reset this value.\r\n * @returns true if the data is loaded from a file, false otherwise.\r\n */\r\n public get hasLoadedData(): boolean {\r\n return this._hasLoadedData;\r\n }\r\n\r\n /**\r\n * Given a string containing file data, this function parses the file data into the datasets object.\r\n * It returns a boolean to indicate if this object was successfully loaded with the data.\r\n * @param data string content representing the file data.\r\n * @param keepDatasetMeta if it should use reuse the existing dataset metadata\r\n * @returns true if the data was successfully loaded, false otherwise.\r\n */\r\n public loadFromFileData(data: string, keepDatasetMeta?: boolean): boolean {\r\n const lines = data\r\n .replace(CarriageReturnRegex, \"\")\r\n .split(\"\\n\")\r\n .map((line) => line.split(\",\").filter((s) => s.length > 0))\r\n .filter((line) => line.length > 0);\r\n const timestampIndex = 0;\r\n const numPointsIndex = PerformanceViewerCollector.NumberOfPointsOffset;\r\n if (lines.length < 2) {\r\n return false;\r\n }\r\n\r\n const parsedDatasets: IPerfDatasets = {\r\n ids: [],\r\n data: new DynamicFloat32Array(InitialArraySize),\r\n startingIndices: new DynamicFloat32Array(InitialArraySize),\r\n };\r\n\r\n // parse first line separately to populate ids!\r\n const [firstLine, ...dataLines] = lines;\r\n // make sure we have the correct beginning headers\r\n if (firstLine.length < 2 || firstLine[timestampIndex] !== TimestampColHeader || firstLine[numPointsIndex] !== NumPointsColHeader) {\r\n return false;\r\n }\r\n\r\n const idCategoryMap: Map<string, string> = new Map<string, string>();\r\n\r\n // populate the ids.\r\n for (let i = PerformanceViewerCollector.SliceDataOffset; i < firstLine.length; i++) {\r\n const [id, category] = firstLine[i].split(ExportedDataSeparator);\r\n parsedDatasets.ids.push(id);\r\n idCategoryMap.set(id, category);\r\n }\r\n\r\n let startingIndex = 0;\r\n for (const line of dataLines) {\r\n if (line.length < 2) {\r\n return false;\r\n }\r\n\r\n const timestamp = parseFloat(line[timestampIndex]);\r\n const numPoints = parseInt(line[numPointsIndex]);\r\n\r\n if (isNaN(numPoints) || isNaN(timestamp)) {\r\n return false;\r\n }\r\n\r\n parsedDatasets.data.push(timestamp);\r\n parsedDatasets.data.push(numPoints);\r\n\r\n if (numPoints + PerformanceViewerCollector.SliceDataOffset !== line.length) {\r\n return false;\r\n }\r\n\r\n for (let i = PerformanceViewerCollector.SliceDataOffset; i < line.length; i++) {\r\n const val = parseFloat(line[i]);\r\n if (isNaN(val)) {\r\n return false;\r\n }\r\n parsedDatasets.data.push(val);\r\n }\r\n\r\n parsedDatasets.startingIndices.push(startingIndex);\r\n startingIndex += line.length;\r\n }\r\n\r\n this.datasets.ids = parsedDatasets.ids;\r\n this.datasets.data = parsedDatasets.data;\r\n this.datasets.startingIndices = parsedDatasets.startingIndices;\r\n if (!keepDatasetMeta) {\r\n this._datasetMeta.clear();\r\n }\r\n this._strategies.forEach((strategy) => strategy.dispose());\r\n this._strategies.clear();\r\n\r\n // populate metadata.\r\n if (!keepDatasetMeta) {\r\n for (const id of this.datasets.ids) {\r\n const category = idCategoryMap.get(id);\r\n\r\n this._datasetMeta.set(id, { category, color: this._getHexColorFromId(id) });\r\n }\r\n }\r\n this.metadataObservable.notifyObservers(this._datasetMeta);\r\n this._hasLoadedData = true;\r\n return true;\r\n }\r\n\r\n /**\r\n * Exports the datasets inside of the collector to a csv.\r\n */\r\n public exportDataToCsv() {\r\n let csvContent = \"\";\r\n // create the header line.\r\n csvContent += `${TimestampColHeader},${NumPointsColHeader}`;\r\n for (let i = 0; i < this.datasets.ids.length; i++) {\r\n csvContent += `,${this.datasets.ids[i]}`;\r\n if (this._datasetMeta) {\r\n const meta = this._datasetMeta.get(this.datasets.ids[i]);\r\n if (meta?.category) {\r\n csvContent += `${ExportedDataSeparator}${meta.category}`;\r\n }\r\n }\r\n }\r\n csvContent += \"\\n\";\r\n // create the data lines\r\n for (let i = 0; i < this.datasets.startingIndices.itemLength; i++) {\r\n const startingIndex = this.datasets.startingIndices.at(i);\r\n const timestamp = this.datasets.data.at(startingIndex);\r\n const numPoints = this.datasets.data.at(startingIndex + PerformanceViewerCollector.NumberOfPointsOffset);\r\n\r\n csvContent += `${timestamp},${numPoints}`;\r\n\r\n for (let offset = 0; offset < numPoints; offset++) {\r\n csvContent += `,${this.datasets.data.at(startingIndex + PerformanceViewerCollector.SliceDataOffset + offset)}`;\r\n }\r\n\r\n // add extra commas.\r\n for (let diff = 0; diff < this.datasets.ids.length - numPoints; diff++) {\r\n csvContent += \",\";\r\n }\r\n\r\n csvContent += \"\\n\";\r\n }\r\n\r\n const fileName = `${new Date().toISOString()}-perfdata.csv`;\r\n Tools.Download(new Blob([csvContent], { type: \"text/csv\" }), fileName);\r\n }\r\n /**\r\n * Starts the realtime collection of data.\r\n * @param shouldPreserve optional boolean param, if set will preserve the dataset between calls of start.\r\n */\r\n public start(shouldPreserve?: boolean) {\r\n if (!shouldPreserve) {\r\n this.datasets.data = new DynamicFloat32Array(InitialArraySize);\r\n this.datasets.startingIndices = new DynamicFloat32Array(InitialArraySize);\r\n this._startingTimestamp = PrecisionDate.Now;\r\n } else if (this._startingTimestamp === undefined) {\r\n this._startingTimestamp = PrecisionDate.Now;\r\n }\r\n this._scene.onAfterRenderObservable.add(this._collectDataAtFrame);\r\n this._restoreStringEvents();\r\n this._isStarted = true;\r\n }\r\n\r\n /**\r\n * Stops the collection of data.\r\n */\r\n public stop() {\r\n this._scene.onAfterRenderObservable.removeCallback(this._collectDataAtFrame);\r\n this._isStarted = false;\r\n }\r\n\r\n /**\r\n * Returns if the perf collector has been started or not.\r\n */\r\n public get isStarted(): boolean {\r\n return this._isStarted;\r\n }\r\n\r\n /**\r\n * Disposes of the object\r\n */\r\n public dispose() {\r\n this._scene.onAfterRenderObservable.removeCallback(this._collectDataAtFrame);\r\n this._datasetMeta.clear();\r\n this._strategies.forEach((strategy) => {\r\n strategy.dispose();\r\n });\r\n this.datasetObservable.clear();\r\n this.metadataObservable.clear();\r\n this._isStarted = false;\r\n (<any>this.datasets) = null;\r\n }\r\n}\r\n"]}
package/Misc/basis.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Tools } from "./tools.js";
2
2
  import { Texture } from "../Materials/Textures/texture.js";
3
3
  import { InternalTexture } from "../Materials/Textures/internalTexture.js";
4
- import { Scalar } from "../Maths/math.scalar.js";
5
4
 
6
5
  import { initializeWebWorker, workerFunction } from "./basisWorker.js";
7
6
  /**
@@ -188,7 +187,7 @@ export const LoadTextureFromTranscodeResult = (texture, transcodeResult) => {
188
187
  // No compatable compressed format found, fallback to RGB
189
188
  texture.type = 10;
190
189
  texture.format = 4;
191
- if (engine._features.basisNeedsPOT && (Scalar.Log2(rootImage.width) % 1 !== 0 || Scalar.Log2(rootImage.height) % 1 !== 0)) {
190
+ if (engine._features.basisNeedsPOT && (Math.log2(rootImage.width) % 1 !== 0 || Math.log2(rootImage.height) % 1 !== 0)) {
192
191
  // Create non power of two texture
193
192
  const source = new InternalTexture(engine, 2 /* InternalTextureSource.Temp */);
194
193
  texture._invertVScale = texture.invertY;
@@ -227,7 +226,7 @@ export const LoadTextureFromTranscodeResult = (texture, transcodeResult) => {
227
226
  transcodeResult.fileInfo.images[i].levels.forEach((level, index) => {
228
227
  engine._uploadCompressedDataToTextureDirectly(texture, format, level.width, level.height, level.transcodedPixels, i, index);
229
228
  });
230
- if (engine._features.basisNeedsPOT && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)) {
229
+ if (engine._features.basisNeedsPOT && (Math.log2(texture.width) % 1 !== 0 || Math.log2(texture.height) % 1 !== 0)) {
231
230
  Tools.Warn("Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.");
232
231
  texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;
233
232
  texture._cachedWrapV = Texture.CLAMP_ADDRESSMODE;
package/Misc/basis.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"basis.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/basis.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,E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C;;;;;OAKG;IACH,cAAc;IAEd;;;;OAIG;IACH,8BAA8B;CACjC,CAAC;AAEF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,aAAa,EAAE;IAC7C,GAAG,EAAE;QACD,OAAO,iBAAiB,CAAC,WAAW,CAAC;IACzC,CAAC;IACD,GAAG,EAAE,UAAsB,KAAa;QACpC,iBAAiB,CAAC,WAAW,GAAG,KAAK,CAAC;IAC1C,CAAC;CACJ,CAAC,CAAC;AAEH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,eAAe,EAAE;IAC/C,GAAG,EAAE;QACD,OAAO,iBAAiB,CAAC,aAAa,CAAC;IAC3C,CAAC;IACD,GAAG,EAAE,UAAsB,KAAa;QACpC,iBAAiB,CAAC,aAAa,GAAG,KAAK,CAAC;IAC5C,CAAC;CACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../types\";\r\nimport { Tools } from \"./tools\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { Scalar } from \"../Maths/math.scalar\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { initializeWebWorker, workerFunction } from \"./basisWorker\";\r\n\r\n/**\r\n * Info about the .basis files\r\n */\r\nexport class BasisFileInfo {\r\n /**\r\n * If the file has alpha\r\n */\r\n public hasAlpha: boolean;\r\n /**\r\n * Info about each image of the basis file\r\n */\r\n public images: Array<{ levels: Array<{ width: number; height: number; transcodedPixels: ArrayBufferView }> }>;\r\n}\r\n\r\n/**\r\n * Result of transcoding a basis file\r\n */\r\nclass TranscodeResult {\r\n /**\r\n * Info about the .basis file\r\n */\r\n public fileInfo: BasisFileInfo;\r\n /**\r\n * Format to use when loading the file\r\n */\r\n public format: number;\r\n}\r\n\r\n/**\r\n * Configuration options for the Basis transcoder\r\n */\r\nexport class BasisTranscodeConfiguration {\r\n /**\r\n * Supported compression formats used to determine the supported output format of the transcoder\r\n */\r\n supportedCompressionFormats?: {\r\n /**\r\n * etc1 compression format\r\n */\r\n etc1?: boolean;\r\n /**\r\n * s3tc compression format\r\n */\r\n s3tc?: boolean;\r\n /**\r\n * pvrtc compression format\r\n */\r\n pvrtc?: boolean;\r\n /**\r\n * etc2 compression format\r\n */\r\n etc2?: boolean;\r\n /**\r\n * astc compression format\r\n */\r\n astc?: boolean;\r\n /**\r\n * bc7 compression format\r\n */\r\n bc7?: boolean;\r\n };\r\n /**\r\n * If mipmap levels should be loaded for transcoded images (Default: true)\r\n */\r\n loadMipmapLevels?: boolean;\r\n /**\r\n * Index of a single image to load (Default: all images)\r\n */\r\n loadSingleImage?: number;\r\n}\r\n\r\n/**\r\n * @internal\r\n * Enum of basis transcoder formats\r\n */\r\nenum BASIS_FORMATS {\r\n cTFETC1 = 0,\r\n cTFETC2 = 1,\r\n cTFBC1 = 2,\r\n cTFBC3 = 3,\r\n cTFBC4 = 4,\r\n cTFBC5 = 5,\r\n cTFBC7 = 6,\r\n cTFPVRTC1_4_RGB = 8,\r\n cTFPVRTC1_4_RGBA = 9,\r\n cTFASTC_4x4 = 10,\r\n cTFATC_RGB = 11,\r\n cTFATC_RGBA_INTERPOLATED_ALPHA = 12,\r\n cTFRGBA32 = 13,\r\n cTFRGB565 = 14,\r\n cTFBGR565 = 15,\r\n cTFRGBA4444 = 16,\r\n cTFFXT1_RGB = 17,\r\n cTFPVRTC2_4_RGB = 18,\r\n cTFPVRTC2_4_RGBA = 19,\r\n cTFETC2_EAC_R11 = 20,\r\n cTFETC2_EAC_RG11 = 21,\r\n}\r\n\r\n/**\r\n * Used to load .Basis files\r\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\r\n */\r\nexport const BasisToolsOptions = {\r\n /**\r\n * URL to use when loading the basis transcoder\r\n */\r\n JSModuleURL: `${Tools._DefaultCdnUrl}/basisTranscoder/1/basis_transcoder.js`,\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n WasmModuleURL: `${Tools._DefaultCdnUrl}/basisTranscoder/1/basis_transcoder.wasm`,\r\n};\r\n\r\n/**\r\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\r\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\r\n * @param engine\r\n * @returns internal format corresponding to the Basis format\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport const GetInternalFormatFromBasisFormat = (basisFormat: number, engine: Engine) => {\r\n let format;\r\n switch (basisFormat) {\r\n case BASIS_FORMATS.cTFETC1:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL;\r\n break;\r\n case BASIS_FORMATS.cTFBC1:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1;\r\n break;\r\n case BASIS_FORMATS.cTFBC4:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5;\r\n break;\r\n case BASIS_FORMATS.cTFASTC_4x4:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4;\r\n break;\r\n case BASIS_FORMATS.cTFETC2:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC;\r\n break;\r\n case BASIS_FORMATS.cTFBC7:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM;\r\n break;\r\n }\r\n\r\n if (format === undefined) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"The chosen Basis transcoder format is not currently supported\";\r\n }\r\n\r\n return format;\r\n};\r\n\r\nlet _WorkerPromise: Nullable<Promise<Worker>> = null;\r\nlet _Worker: Nullable<Worker> = null;\r\nlet _actionId = 0;\r\nconst _IgnoreSupportedFormats = false;\r\nconst _CreateWorkerAsync = () => {\r\n if (!_WorkerPromise) {\r\n _WorkerPromise = new Promise((res, reject) => {\r\n if (_Worker) {\r\n res(_Worker);\r\n } else {\r\n Tools.LoadFileAsync(Tools.GetBabylonScriptURL(BasisToolsOptions.WasmModuleURL))\r\n .then((wasmBinary) => {\r\n if (typeof URL !== \"function\") {\r\n return reject(\"Basis transcoder requires an environment with a URL constructor\");\r\n }\r\n const workerBlobUrl = URL.createObjectURL(new Blob([`(${workerFunction})()`], { type: \"application/javascript\" }));\r\n _Worker = new Worker(workerBlobUrl);\r\n initializeWebWorker(_Worker, wasmBinary, BasisToolsOptions.JSModuleURL).then(res, reject);\r\n })\r\n .catch(reject);\r\n }\r\n });\r\n }\r\n return _WorkerPromise;\r\n};\r\n\r\n/**\r\n * Set the worker to use for transcoding\r\n * @param worker The worker that will be used for transcoding\r\n */\r\nexport const SetBasisTranscoderWorker = (worker: Worker) => {\r\n _Worker = worker;\r\n};\r\n\r\n/**\r\n * Transcodes a loaded image file to compressed pixel data\r\n * @param data image data to transcode\r\n * @param config configuration options for the transcoding\r\n * @returns a promise resulting in the transcoded image\r\n */\r\nexport const TranscodeAsync = (data: ArrayBuffer | ArrayBufferView, config: BasisTranscodeConfiguration): Promise<TranscodeResult> => {\r\n const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;\r\n\r\n return new Promise((res, rej) => {\r\n _CreateWorkerAsync().then(\r\n () => {\r\n const actionId = _actionId++;\r\n const messageHandler = (msg: any) => {\r\n if (msg.data.action === \"transcode\" && msg.data.id === actionId) {\r\n _Worker!.removeEventListener(\"message\", messageHandler);\r\n if (!msg.data.success) {\r\n rej(\"Transcode is not supported on this device\");\r\n } else {\r\n res(msg.data);\r\n }\r\n }\r\n };\r\n _Worker!.addEventListener(\"message\", messageHandler);\r\n\r\n const dataViewCopy = new Uint8Array(dataView.byteLength);\r\n dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));\r\n _Worker!.postMessage({ action: \"transcode\", id: actionId, imageData: dataViewCopy, config: config, ignoreSupportedFormats: _IgnoreSupportedFormats }, [\r\n dataViewCopy.buffer,\r\n ]);\r\n },\r\n (error) => {\r\n rej(error);\r\n }\r\n );\r\n });\r\n};\r\n\r\n/**\r\n * Binds a texture according to its underlying target.\r\n * @param texture texture to bind\r\n * @param engine the engine to bind the texture in\r\n */\r\nconst BindTexture = (texture: InternalTexture, engine: Engine): void => {\r\n let target: GLenum = engine._gl?.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = engine._gl?.TEXTURE_CUBE_MAP;\r\n }\r\n\r\n engine._bindTextureDirectly(target, texture, true);\r\n};\r\n\r\n/**\r\n * Loads a texture from the transcode result\r\n * @param texture texture load to\r\n * @param transcodeResult the result of transcoding the basis file to load from\r\n */\r\nexport const LoadTextureFromTranscodeResult = (texture: InternalTexture, transcodeResult: TranscodeResult) => {\r\n const engine = texture.getEngine() as Engine;\r\n for (let i = 0; i < transcodeResult.fileInfo.images.length; i++) {\r\n const rootImage = transcodeResult.fileInfo.images[i].levels[0];\r\n texture._invertVScale = texture.invertY;\r\n if (transcodeResult.format === -1 || transcodeResult.format === BASIS_FORMATS.cTFRGB565) {\r\n // No compatable compressed format found, fallback to RGB\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n texture.format = Constants.TEXTUREFORMAT_RGB;\r\n\r\n if (engine._features.basisNeedsPOT && (Scalar.Log2(rootImage.width) % 1 !== 0 || Scalar.Log2(rootImage.height) % 1 !== 0)) {\r\n // Create non power of two texture\r\n const source = new InternalTexture(engine, InternalTextureSource.Temp);\r\n\r\n texture._invertVScale = texture.invertY;\r\n source.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n source.format = Constants.TEXTUREFORMAT_RGB;\r\n // Fallback requires aligned width/height\r\n source.width = (rootImage.width + 3) & ~3;\r\n source.height = (rootImage.height + 3) & ~3;\r\n BindTexture(source, engine);\r\n engine._uploadDataToTextureDirectly(source, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, Constants.TEXTUREFORMAT_RGB, true);\r\n\r\n // Resize to power of two\r\n engine._rescaleTexture(source, texture, engine.scenes[0], engine._getInternalFormat(Constants.TEXTUREFORMAT_RGB), () => {\r\n engine._releaseTexture(source);\r\n BindTexture(texture, engine);\r\n });\r\n } else {\r\n // Fallback is already inverted\r\n texture._invertVScale = !texture.invertY;\r\n\r\n // Upload directly\r\n texture.width = (rootImage.width + 3) & ~3;\r\n texture.height = (rootImage.height + 3) & ~3;\r\n texture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR;\r\n BindTexture(texture, engine);\r\n engine._uploadDataToTextureDirectly(texture, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, Constants.TEXTUREFORMAT_RGB, true);\r\n }\r\n } else {\r\n texture.width = rootImage.width;\r\n texture.height = rootImage.height;\r\n texture.generateMipMaps = transcodeResult.fileInfo.images[i].levels.length > 1;\r\n\r\n const format = BasisTools.GetInternalFormatFromBasisFormat(transcodeResult.format!, engine);\r\n texture.format = format;\r\n\r\n BindTexture(texture, engine);\r\n\r\n // Upload all mip levels in the file\r\n transcodeResult.fileInfo.images[i].levels.forEach((level: any, index: number) => {\r\n engine._uploadCompressedDataToTextureDirectly(texture, format, level.width, level.height, level.transcodedPixels, i, index);\r\n });\r\n\r\n if (engine._features.basisNeedsPOT && (Scalar.Log2(texture.width) % 1 !== 0 || Scalar.Log2(texture.height) % 1 !== 0)) {\r\n Tools.Warn(\r\n \"Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.\"\r\n );\r\n texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture._cachedWrapV = Texture.CLAMP_ADDRESSMODE;\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Used to load .Basis files\r\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\r\n */\r\nexport const BasisTools = {\r\n /**\r\n * URL to use when loading the basis transcoder\r\n */\r\n JSModuleURL: BasisToolsOptions.JSModuleURL,\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n WasmModuleURL: BasisToolsOptions.WasmModuleURL,\r\n\r\n /**\r\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\r\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\r\n * @returns internal format corresponding to the Basis format\r\n */\r\n GetInternalFormatFromBasisFormat,\r\n\r\n /**\r\n * Transcodes a loaded image file to compressed pixel data\r\n * @param data image data to transcode\r\n * @param config configuration options for the transcoding\r\n * @returns a promise resulting in the transcoded image\r\n */\r\n TranscodeAsync,\r\n\r\n /**\r\n * Loads a texture from the transcode result\r\n * @param texture texture load to\r\n * @param transcodeResult the result of transcoding the basis file to load from\r\n */\r\n LoadTextureFromTranscodeResult,\r\n};\r\n\r\nObject.defineProperty(BasisTools, \"JSModuleURL\", {\r\n get: function (this: null) {\r\n return BasisToolsOptions.JSModuleURL;\r\n },\r\n set: function (this: null, value: string) {\r\n BasisToolsOptions.JSModuleURL = value;\r\n },\r\n});\r\n\r\nObject.defineProperty(BasisTools, \"WasmModuleURL\", {\r\n get: function (this: null) {\r\n return BasisToolsOptions.WasmModuleURL;\r\n },\r\n set: function (this: null, value: string) {\r\n BasisToolsOptions.WasmModuleURL = value;\r\n },\r\n});\r\n"]}
1
+ {"version":3,"file":"basis.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/basis.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,eAAe,EAAyB,MAAM,uCAAuC,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE;;GAEG;AACH,MAAM,OAAO,aAAa;CASzB;AAED;;GAEG;AACH,MAAM,eAAe;CASpB;AAED;;GAEG;AACH,MAAM,OAAO,2BAA2B;CAsCvC;AAED;;;GAGG;AACH,IAAK,aAsBJ;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AAC;IAC3C,CAAC;IACD,GAAG,EAAE,UAAsB,KAAa;QACpC,iBAAiB,CAAC,aAAa,GAAG,KAAK,CAAC;IAC5C,CAAC;CACJ,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"../types\";\r\nimport { Tools } from \"./tools\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { InternalTexture, InternalTextureSource } from \"../Materials/Textures/internalTexture\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport type { Engine } from \"../Engines/engine\";\r\nimport { initializeWebWorker, workerFunction } from \"./basisWorker\";\r\n\r\n/**\r\n * Info about the .basis files\r\n */\r\nexport class BasisFileInfo {\r\n /**\r\n * If the file has alpha\r\n */\r\n public hasAlpha: boolean;\r\n /**\r\n * Info about each image of the basis file\r\n */\r\n public images: Array<{ levels: Array<{ width: number; height: number; transcodedPixels: ArrayBufferView }> }>;\r\n}\r\n\r\n/**\r\n * Result of transcoding a basis file\r\n */\r\nclass TranscodeResult {\r\n /**\r\n * Info about the .basis file\r\n */\r\n public fileInfo: BasisFileInfo;\r\n /**\r\n * Format to use when loading the file\r\n */\r\n public format: number;\r\n}\r\n\r\n/**\r\n * Configuration options for the Basis transcoder\r\n */\r\nexport class BasisTranscodeConfiguration {\r\n /**\r\n * Supported compression formats used to determine the supported output format of the transcoder\r\n */\r\n supportedCompressionFormats?: {\r\n /**\r\n * etc1 compression format\r\n */\r\n etc1?: boolean;\r\n /**\r\n * s3tc compression format\r\n */\r\n s3tc?: boolean;\r\n /**\r\n * pvrtc compression format\r\n */\r\n pvrtc?: boolean;\r\n /**\r\n * etc2 compression format\r\n */\r\n etc2?: boolean;\r\n /**\r\n * astc compression format\r\n */\r\n astc?: boolean;\r\n /**\r\n * bc7 compression format\r\n */\r\n bc7?: boolean;\r\n };\r\n /**\r\n * If mipmap levels should be loaded for transcoded images (Default: true)\r\n */\r\n loadMipmapLevels?: boolean;\r\n /**\r\n * Index of a single image to load (Default: all images)\r\n */\r\n loadSingleImage?: number;\r\n}\r\n\r\n/**\r\n * @internal\r\n * Enum of basis transcoder formats\r\n */\r\nenum BASIS_FORMATS {\r\n cTFETC1 = 0,\r\n cTFETC2 = 1,\r\n cTFBC1 = 2,\r\n cTFBC3 = 3,\r\n cTFBC4 = 4,\r\n cTFBC5 = 5,\r\n cTFBC7 = 6,\r\n cTFPVRTC1_4_RGB = 8,\r\n cTFPVRTC1_4_RGBA = 9,\r\n cTFASTC_4x4 = 10,\r\n cTFATC_RGB = 11,\r\n cTFATC_RGBA_INTERPOLATED_ALPHA = 12,\r\n cTFRGBA32 = 13,\r\n cTFRGB565 = 14,\r\n cTFBGR565 = 15,\r\n cTFRGBA4444 = 16,\r\n cTFFXT1_RGB = 17,\r\n cTFPVRTC2_4_RGB = 18,\r\n cTFPVRTC2_4_RGBA = 19,\r\n cTFETC2_EAC_R11 = 20,\r\n cTFETC2_EAC_RG11 = 21,\r\n}\r\n\r\n/**\r\n * Used to load .Basis files\r\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\r\n */\r\nexport const BasisToolsOptions = {\r\n /**\r\n * URL to use when loading the basis transcoder\r\n */\r\n JSModuleURL: `${Tools._DefaultCdnUrl}/basisTranscoder/1/basis_transcoder.js`,\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n WasmModuleURL: `${Tools._DefaultCdnUrl}/basisTranscoder/1/basis_transcoder.wasm`,\r\n};\r\n\r\n/**\r\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\r\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\r\n * @param engine\r\n * @returns internal format corresponding to the Basis format\r\n */\r\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\r\nexport const GetInternalFormatFromBasisFormat = (basisFormat: number, engine: Engine) => {\r\n let format;\r\n switch (basisFormat) {\r\n case BASIS_FORMATS.cTFETC1:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGB_ETC1_WEBGL;\r\n break;\r\n case BASIS_FORMATS.cTFBC1:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGB_S3TC_DXT1;\r\n break;\r\n case BASIS_FORMATS.cTFBC4:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_S3TC_DXT5;\r\n break;\r\n case BASIS_FORMATS.cTFASTC_4x4:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_ASTC_4x4;\r\n break;\r\n case BASIS_FORMATS.cTFETC2:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA8_ETC2_EAC;\r\n break;\r\n case BASIS_FORMATS.cTFBC7:\r\n format = Constants.TEXTUREFORMAT_COMPRESSED_RGBA_BPTC_UNORM;\r\n break;\r\n }\r\n\r\n if (format === undefined) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw \"The chosen Basis transcoder format is not currently supported\";\r\n }\r\n\r\n return format;\r\n};\r\n\r\nlet _WorkerPromise: Nullable<Promise<Worker>> = null;\r\nlet _Worker: Nullable<Worker> = null;\r\nlet _actionId = 0;\r\nconst _IgnoreSupportedFormats = false;\r\nconst _CreateWorkerAsync = () => {\r\n if (!_WorkerPromise) {\r\n _WorkerPromise = new Promise((res, reject) => {\r\n if (_Worker) {\r\n res(_Worker);\r\n } else {\r\n Tools.LoadFileAsync(Tools.GetBabylonScriptURL(BasisToolsOptions.WasmModuleURL))\r\n .then((wasmBinary) => {\r\n if (typeof URL !== \"function\") {\r\n return reject(\"Basis transcoder requires an environment with a URL constructor\");\r\n }\r\n const workerBlobUrl = URL.createObjectURL(new Blob([`(${workerFunction})()`], { type: \"application/javascript\" }));\r\n _Worker = new Worker(workerBlobUrl);\r\n initializeWebWorker(_Worker, wasmBinary, BasisToolsOptions.JSModuleURL).then(res, reject);\r\n })\r\n .catch(reject);\r\n }\r\n });\r\n }\r\n return _WorkerPromise;\r\n};\r\n\r\n/**\r\n * Set the worker to use for transcoding\r\n * @param worker The worker that will be used for transcoding\r\n */\r\nexport const SetBasisTranscoderWorker = (worker: Worker) => {\r\n _Worker = worker;\r\n};\r\n\r\n/**\r\n * Transcodes a loaded image file to compressed pixel data\r\n * @param data image data to transcode\r\n * @param config configuration options for the transcoding\r\n * @returns a promise resulting in the transcoded image\r\n */\r\nexport const TranscodeAsync = (data: ArrayBuffer | ArrayBufferView, config: BasisTranscodeConfiguration): Promise<TranscodeResult> => {\r\n const dataView = data instanceof ArrayBuffer ? new Uint8Array(data) : data;\r\n\r\n return new Promise((res, rej) => {\r\n _CreateWorkerAsync().then(\r\n () => {\r\n const actionId = _actionId++;\r\n const messageHandler = (msg: any) => {\r\n if (msg.data.action === \"transcode\" && msg.data.id === actionId) {\r\n _Worker!.removeEventListener(\"message\", messageHandler);\r\n if (!msg.data.success) {\r\n rej(\"Transcode is not supported on this device\");\r\n } else {\r\n res(msg.data);\r\n }\r\n }\r\n };\r\n _Worker!.addEventListener(\"message\", messageHandler);\r\n\r\n const dataViewCopy = new Uint8Array(dataView.byteLength);\r\n dataViewCopy.set(new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));\r\n _Worker!.postMessage({ action: \"transcode\", id: actionId, imageData: dataViewCopy, config: config, ignoreSupportedFormats: _IgnoreSupportedFormats }, [\r\n dataViewCopy.buffer,\r\n ]);\r\n },\r\n (error) => {\r\n rej(error);\r\n }\r\n );\r\n });\r\n};\r\n\r\n/**\r\n * Binds a texture according to its underlying target.\r\n * @param texture texture to bind\r\n * @param engine the engine to bind the texture in\r\n */\r\nconst BindTexture = (texture: InternalTexture, engine: Engine): void => {\r\n let target: GLenum = engine._gl?.TEXTURE_2D;\r\n if (texture.isCube) {\r\n target = engine._gl?.TEXTURE_CUBE_MAP;\r\n }\r\n\r\n engine._bindTextureDirectly(target, texture, true);\r\n};\r\n\r\n/**\r\n * Loads a texture from the transcode result\r\n * @param texture texture load to\r\n * @param transcodeResult the result of transcoding the basis file to load from\r\n */\r\nexport const LoadTextureFromTranscodeResult = (texture: InternalTexture, transcodeResult: TranscodeResult) => {\r\n const engine = texture.getEngine() as Engine;\r\n for (let i = 0; i < transcodeResult.fileInfo.images.length; i++) {\r\n const rootImage = transcodeResult.fileInfo.images[i].levels[0];\r\n texture._invertVScale = texture.invertY;\r\n if (transcodeResult.format === -1 || transcodeResult.format === BASIS_FORMATS.cTFRGB565) {\r\n // No compatable compressed format found, fallback to RGB\r\n texture.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n texture.format = Constants.TEXTUREFORMAT_RGB;\r\n\r\n if (engine._features.basisNeedsPOT && (Math.log2(rootImage.width) % 1 !== 0 || Math.log2(rootImage.height) % 1 !== 0)) {\r\n // Create non power of two texture\r\n const source = new InternalTexture(engine, InternalTextureSource.Temp);\r\n\r\n texture._invertVScale = texture.invertY;\r\n source.type = Constants.TEXTURETYPE_UNSIGNED_SHORT_5_6_5;\r\n source.format = Constants.TEXTUREFORMAT_RGB;\r\n // Fallback requires aligned width/height\r\n source.width = (rootImage.width + 3) & ~3;\r\n source.height = (rootImage.height + 3) & ~3;\r\n BindTexture(source, engine);\r\n engine._uploadDataToTextureDirectly(source, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, Constants.TEXTUREFORMAT_RGB, true);\r\n\r\n // Resize to power of two\r\n engine._rescaleTexture(source, texture, engine.scenes[0], engine._getInternalFormat(Constants.TEXTUREFORMAT_RGB), () => {\r\n engine._releaseTexture(source);\r\n BindTexture(texture, engine);\r\n });\r\n } else {\r\n // Fallback is already inverted\r\n texture._invertVScale = !texture.invertY;\r\n\r\n // Upload directly\r\n texture.width = (rootImage.width + 3) & ~3;\r\n texture.height = (rootImage.height + 3) & ~3;\r\n texture.samplingMode = Constants.TEXTURE_LINEAR_LINEAR;\r\n BindTexture(texture, engine);\r\n engine._uploadDataToTextureDirectly(texture, new Uint16Array(rootImage.transcodedPixels.buffer), i, 0, Constants.TEXTUREFORMAT_RGB, true);\r\n }\r\n } else {\r\n texture.width = rootImage.width;\r\n texture.height = rootImage.height;\r\n texture.generateMipMaps = transcodeResult.fileInfo.images[i].levels.length > 1;\r\n\r\n const format = BasisTools.GetInternalFormatFromBasisFormat(transcodeResult.format!, engine);\r\n texture.format = format;\r\n\r\n BindTexture(texture, engine);\r\n\r\n // Upload all mip levels in the file\r\n transcodeResult.fileInfo.images[i].levels.forEach((level: any, index: number) => {\r\n engine._uploadCompressedDataToTextureDirectly(texture, format, level.width, level.height, level.transcodedPixels, i, index);\r\n });\r\n\r\n if (engine._features.basisNeedsPOT && (Math.log2(texture.width) % 1 !== 0 || Math.log2(texture.height) % 1 !== 0)) {\r\n Tools.Warn(\r\n \"Loaded .basis texture width and height are not a power of two. Texture wrapping will be set to Texture.CLAMP_ADDRESSMODE as other modes are not supported with non power of two dimensions in webGL 1.\"\r\n );\r\n texture._cachedWrapU = Texture.CLAMP_ADDRESSMODE;\r\n texture._cachedWrapV = Texture.CLAMP_ADDRESSMODE;\r\n }\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * Used to load .Basis files\r\n * See https://github.com/BinomialLLC/basis_universal/tree/master/webgl\r\n */\r\nexport const BasisTools = {\r\n /**\r\n * URL to use when loading the basis transcoder\r\n */\r\n JSModuleURL: BasisToolsOptions.JSModuleURL,\r\n /**\r\n * URL to use when loading the wasm module for the transcoder\r\n */\r\n WasmModuleURL: BasisToolsOptions.WasmModuleURL,\r\n\r\n /**\r\n * Get the internal format to be passed to texImage2D corresponding to the .basis format value\r\n * @param basisFormat format chosen from GetSupportedTranscodeFormat\r\n * @returns internal format corresponding to the Basis format\r\n */\r\n GetInternalFormatFromBasisFormat,\r\n\r\n /**\r\n * Transcodes a loaded image file to compressed pixel data\r\n * @param data image data to transcode\r\n * @param config configuration options for the transcoding\r\n * @returns a promise resulting in the transcoded image\r\n */\r\n TranscodeAsync,\r\n\r\n /**\r\n * Loads a texture from the transcode result\r\n * @param texture texture load to\r\n * @param transcodeResult the result of transcoding the basis file to load from\r\n */\r\n LoadTextureFromTranscodeResult,\r\n};\r\n\r\nObject.defineProperty(BasisTools, \"JSModuleURL\", {\r\n get: function (this: null) {\r\n return BasisToolsOptions.JSModuleURL;\r\n },\r\n set: function (this: null, value: string) {\r\n BasisToolsOptions.JSModuleURL = value;\r\n },\r\n});\r\n\r\nObject.defineProperty(BasisTools, \"WasmModuleURL\", {\r\n get: function (this: null) {\r\n return BasisToolsOptions.WasmModuleURL;\r\n },\r\n set: function (this: null, value: string) {\r\n BasisToolsOptions.WasmModuleURL = value;\r\n },\r\n});\r\n"]}