@babylonjs/core 7.43.0 → 7.44.1

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 (341) hide show
  1. package/Actions/actionEvent.d.ts +4 -4
  2. package/Buffers/bufferUtils.d.ts +8 -1
  3. package/Buffers/bufferUtils.js +15 -0
  4. package/Buffers/bufferUtils.js.map +1 -1
  5. package/Culling/Helper/boundingInfoHelper.d.ts +2 -9
  6. package/Culling/Helper/boundingInfoHelper.js +2 -9
  7. package/Culling/Helper/boundingInfoHelper.js.map +1 -1
  8. package/Debug/debugLayer.d.ts +4 -0
  9. package/Debug/debugLayer.js +9 -0
  10. package/Debug/debugLayer.js.map +1 -1
  11. package/Engines/Extensions/engine.renderTarget.js +2 -4
  12. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  13. package/Engines/WebGPU/Extensions/engine.renderTarget.js +2 -4
  14. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  15. package/Engines/abstractEngine.d.ts +19 -1
  16. package/Engines/abstractEngine.js +48 -9
  17. package/Engines/abstractEngine.js.map +1 -1
  18. package/Engines/engine.d.ts +6 -3
  19. package/Engines/engine.js +2 -20
  20. package/Engines/engine.js.map +1 -1
  21. package/Engines/renderTargetWrapper.js +2 -2
  22. package/Engines/renderTargetWrapper.js.map +1 -1
  23. package/Engines/thinEngine.js +1 -5
  24. package/Engines/thinEngine.js.map +1 -1
  25. package/Engines/webgpuEngine.js +1 -0
  26. package/Engines/webgpuEngine.js.map +1 -1
  27. package/FlowGraph/flowGraphConnection.d.ts +1 -1
  28. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.d.ts +16 -12
  29. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js +63 -27
  30. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js.map +1 -1
  31. package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.d.ts +72 -0
  32. package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.js +197 -0
  33. package/FrameGraph/Node/Blocks/Layers/highlightLayerBlock.js.map +1 -0
  34. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +42 -0
  35. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js +78 -0
  36. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -0
  37. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.d.ts +3 -19
  38. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js +3 -49
  39. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js.map +1 -1
  40. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.d.ts +3 -19
  41. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js +3 -49
  42. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js.map +1 -1
  43. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.d.ts +3 -19
  44. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js +3 -49
  45. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js.map +1 -1
  46. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.d.ts +2 -17
  47. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js +3 -45
  48. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js.map +1 -1
  49. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.d.ts +2 -17
  50. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js +3 -44
  51. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js.map +1 -1
  52. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.d.ts +3 -19
  53. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js +3 -49
  54. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js.map +1 -1
  55. package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.d.ts +47 -0
  56. package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js +65 -0
  57. package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js.map +1 -0
  58. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.d.ts +4 -0
  59. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +9 -0
  60. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
  61. package/FrameGraph/Node/Blocks/index.d.ts +2 -0
  62. package/FrameGraph/Node/Blocks/index.js +2 -0
  63. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  64. package/FrameGraph/Node/Types/nodeRenderGraphTypes.d.ts +4 -2
  65. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js +2 -0
  66. package/FrameGraph/Node/Types/nodeRenderGraphTypes.js.map +1 -1
  67. package/FrameGraph/Node/nodeRenderGraph.d.ts +3 -2
  68. package/FrameGraph/Node/nodeRenderGraph.js +4 -3
  69. package/FrameGraph/Node/nodeRenderGraph.js.map +1 -1
  70. package/FrameGraph/Node/nodeRenderGraphBlock.js +4 -4
  71. package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
  72. package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.d.ts +8 -0
  73. package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.js +10 -0
  74. package/FrameGraph/Node/nodeRenderGraphBlockConnectionPoint.js.map +1 -1
  75. package/FrameGraph/Node/nodeRenderGraphConnectionPointCustomObject.d.ts +21 -0
  76. package/FrameGraph/Node/nodeRenderGraphConnectionPointCustomObject.js +31 -0
  77. package/FrameGraph/Node/nodeRenderGraphConnectionPointCustomObject.js.map +1 -0
  78. package/FrameGraph/Passes/pass.d.ts +1 -0
  79. package/FrameGraph/Passes/pass.js +4 -1
  80. package/FrameGraph/Passes/pass.js.map +1 -1
  81. package/FrameGraph/Tasks/Layers/baseLayerTask.d.ts +81 -0
  82. package/FrameGraph/Tasks/Layers/baseLayerTask.js +304 -0
  83. package/FrameGraph/Tasks/Layers/baseLayerTask.js.map +1 -0
  84. package/FrameGraph/Tasks/Layers/glowLayerTask.d.ts +3 -40
  85. package/FrameGraph/Tasks/Layers/glowLayerTask.js +4 -158
  86. package/FrameGraph/Tasks/Layers/glowLayerTask.js.map +1 -1
  87. package/FrameGraph/Tasks/Layers/highlightLayerTask.d.ts +21 -0
  88. package/FrameGraph/Tasks/Layers/highlightLayerTask.js +32 -0
  89. package/FrameGraph/Tasks/Layers/highlightLayerTask.js.map +1 -0
  90. package/FrameGraph/Tasks/Misc/executeTask.d.ts +2 -2
  91. package/FrameGraph/Tasks/Misc/executeTask.js +1 -0
  92. package/FrameGraph/Tasks/Misc/executeTask.js.map +1 -1
  93. package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js +1 -1
  94. package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js.map +1 -1
  95. package/FrameGraph/Tasks/PostProcesses/bloomTask.js +1 -1
  96. package/FrameGraph/Tasks/PostProcesses/bloomTask.js.map +1 -1
  97. package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js +5 -4
  98. package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js.map +1 -1
  99. package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js +5 -4
  100. package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js.map +1 -1
  101. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +2 -4
  102. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
  103. package/FrameGraph/Tasks/PostProcesses/passTask.d.ts +29 -0
  104. package/FrameGraph/Tasks/PostProcesses/passTask.js +31 -0
  105. package/FrameGraph/Tasks/PostProcesses/passTask.js.map +1 -0
  106. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +4 -2
  107. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
  108. package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +2 -2
  109. package/FrameGraph/Tasks/Rendering/objectRendererTask.js +1 -0
  110. package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
  111. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.d.ts +2 -2
  112. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +1 -0
  113. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
  114. package/FrameGraph/Tasks/Texture/clearTextureTask.d.ts +2 -2
  115. package/FrameGraph/Tasks/Texture/clearTextureTask.js +1 -0
  116. package/FrameGraph/Tasks/Texture/clearTextureTask.js.map +1 -1
  117. package/FrameGraph/Tasks/Texture/copyToTextureTask.js +1 -1
  118. package/FrameGraph/Tasks/Texture/copyToTextureTask.js.map +1 -1
  119. package/FrameGraph/frameGraph.d.ts +8 -2
  120. package/FrameGraph/frameGraph.js +31 -5
  121. package/FrameGraph/frameGraph.js.map +1 -1
  122. package/FrameGraph/frameGraphRenderContext.d.ts +10 -0
  123. package/FrameGraph/frameGraphRenderContext.js +14 -0
  124. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  125. package/FrameGraph/frameGraphTask.d.ts +3 -2
  126. package/FrameGraph/frameGraphTask.js +12 -2
  127. package/FrameGraph/frameGraphTask.js.map +1 -1
  128. package/FrameGraph/frameGraphTextureManager.d.ts +1 -1
  129. package/FrameGraph/frameGraphTypes.d.ts +4 -0
  130. package/FrameGraph/frameGraphTypes.js.map +1 -1
  131. package/FrameGraph/index.d.ts +2 -0
  132. package/FrameGraph/index.js +2 -0
  133. package/FrameGraph/index.js.map +1 -1
  134. package/Gizmos/planeRotationGizmo.js +10 -0
  135. package/Gizmos/planeRotationGizmo.js.map +1 -1
  136. package/Helpers/environmentHelper.js +7 -6
  137. package/Helpers/environmentHelper.js.map +1 -1
  138. package/Inputs/scene.inputManager.js +2 -2
  139. package/Inputs/scene.inputManager.js.map +1 -1
  140. package/Layers/effectLayer.d.ts +1 -1
  141. package/Layers/effectLayer.js.map +1 -1
  142. package/Layers/glowLayer.d.ts +2 -14
  143. package/Layers/glowLayer.js +34 -36
  144. package/Layers/glowLayer.js.map +1 -1
  145. package/Layers/highlightLayer.d.ts +13 -74
  146. package/Layers/highlightLayer.js +123 -309
  147. package/Layers/highlightLayer.js.map +1 -1
  148. package/Layers/index.d.ts +1 -0
  149. package/Layers/index.js +1 -0
  150. package/Layers/index.js.map +1 -1
  151. package/Layers/thinEffectLayer.d.ts +55 -2
  152. package/Layers/thinEffectLayer.js +66 -0
  153. package/Layers/thinEffectLayer.js.map +1 -1
  154. package/Layers/thinGlowLayer.d.ts +3 -6
  155. package/Layers/thinGlowLayer.js +4 -1
  156. package/Layers/thinGlowLayer.js.map +1 -1
  157. package/Layers/thinHighlightLayer.d.ts +197 -0
  158. package/Layers/thinHighlightLayer.js +417 -0
  159. package/Layers/thinHighlightLayer.js.map +1 -0
  160. package/Materials/GreasedLine/greasedLinePluginMaterial.d.ts +6 -2
  161. package/Materials/GreasedLine/greasedLinePluginMaterial.js +8 -2
  162. package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
  163. package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js +11 -3
  164. package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js.map +1 -1
  165. package/Materials/GreasedLine/greasedLineSimpleMaterial.d.ts +1 -0
  166. package/Materials/GreasedLine/greasedLineSimpleMaterial.js +1 -0
  167. package/Materials/GreasedLine/greasedLineSimpleMaterial.js.map +1 -1
  168. package/Materials/Node/Blocks/PBR/reflectionBlock.js +1 -3
  169. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  170. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +3 -3
  171. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
  172. package/Materials/Node/nodeMaterial.d.ts +4 -2
  173. package/Materials/Node/nodeMaterial.js +9 -6
  174. package/Materials/Node/nodeMaterial.js.map +1 -1
  175. package/Materials/PBR/pbrBaseMaterial.js +1 -0
  176. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  177. package/Materials/Textures/Filtering/hdrFiltering.js +1 -0
  178. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  179. package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +69 -0
  180. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +187 -0
  181. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -0
  182. package/Materials/Textures/hdrCubeTexture.d.ts +5 -1
  183. package/Materials/Textures/hdrCubeTexture.js +29 -3
  184. package/Materials/Textures/hdrCubeTexture.js.map +1 -1
  185. package/Materials/Textures/index.d.ts +4 -0
  186. package/Materials/Textures/index.js +4 -0
  187. package/Materials/Textures/index.js.map +1 -1
  188. package/Materials/effect.d.ts +5 -0
  189. package/Materials/effect.js +15 -0
  190. package/Materials/effect.js.map +1 -1
  191. package/Materials/standardMaterial.d.ts +1 -2
  192. package/Materials/standardMaterial.js +0 -2
  193. package/Materials/standardMaterial.js.map +1 -1
  194. package/Meshes/Builders/planeBuilder.js +2 -2
  195. package/Meshes/Builders/planeBuilder.js.map +1 -1
  196. package/Meshes/Compression/dracoCodec.d.ts +4 -4
  197. package/Meshes/Compression/dracoCodec.js.map +1 -1
  198. package/Meshes/Compression/dracoCompression.d.ts +5 -3
  199. package/Meshes/Compression/dracoCompression.js +24 -11
  200. package/Meshes/Compression/dracoCompression.js.map +1 -1
  201. package/Meshes/Compression/dracoCompressionWorker.d.ts +16 -30
  202. package/Meshes/Compression/dracoCompressionWorker.js +128 -22
  203. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
  204. package/Meshes/Compression/dracoDecoder.d.ts +4 -9
  205. package/Meshes/Compression/dracoDecoder.js +5 -5
  206. package/Meshes/Compression/dracoDecoder.js.map +1 -1
  207. package/Meshes/Compression/dracoDecoder.types.d.ts +52 -0
  208. package/Meshes/Compression/dracoDecoder.types.js +2 -0
  209. package/Meshes/Compression/dracoDecoder.types.js.map +1 -0
  210. package/Meshes/Compression/dracoEncoder.d.ts +95 -0
  211. package/Meshes/Compression/dracoEncoder.js +245 -0
  212. package/Meshes/Compression/dracoEncoder.js.map +1 -0
  213. package/Meshes/Compression/dracoEncoder.types.d.ts +82 -0
  214. package/Meshes/Compression/dracoEncoder.types.js +2 -0
  215. package/Meshes/Compression/dracoEncoder.types.js.map +1 -0
  216. package/Meshes/Compression/index.d.ts +1 -0
  217. package/Meshes/Compression/index.js +1 -0
  218. package/Meshes/Compression/index.js.map +1 -1
  219. package/Meshes/Compression/meshoptCompression.js +17 -2
  220. package/Meshes/Compression/meshoptCompression.js.map +1 -1
  221. package/Meshes/Compression/test/integration/draco.test.d.ts +1 -0
  222. package/Meshes/Compression/test/integration/draco.test.js +30 -0
  223. package/Meshes/Compression/test/integration/draco.test.js.map +1 -0
  224. package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +92 -2
  225. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +286 -10
  226. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  227. package/Meshes/GreasedLine/greasedLineBaseMesh.js +4 -2
  228. package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
  229. package/Meshes/GreasedLine/greasedLineRibbonMesh.js +1 -1
  230. package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
  231. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +1 -1
  232. package/Meshes/csg.js +4 -0
  233. package/Meshes/csg.js.map +1 -1
  234. package/Meshes/mesh.d.ts +2 -2
  235. package/Meshes/transformNode.d.ts +4 -1
  236. package/Meshes/transformNode.js +6 -1
  237. package/Meshes/transformNode.js.map +1 -1
  238. package/Misc/copyTextureToTexture.js +1 -1
  239. package/Misc/copyTextureToTexture.js.map +1 -1
  240. package/Misc/decorators.serialization.js +2 -0
  241. package/Misc/decorators.serialization.js.map +1 -1
  242. package/Misc/greasedLineTools.d.ts +1 -1
  243. package/Misc/logger.d.ts +2 -1
  244. package/Misc/logger.js +2 -1
  245. package/Misc/logger.js.map +1 -1
  246. package/Misc/screenshotTools.js +58 -5
  247. package/Misc/screenshotTools.js.map +1 -1
  248. package/Misc/tools.d.ts +21 -1
  249. package/Misc/tools.js +33 -0
  250. package/Misc/tools.js.map +1 -1
  251. package/Morph/morphTargetManager.d.ts +1 -0
  252. package/Morph/morphTargetManager.js +6 -1
  253. package/Morph/morphTargetManager.js.map +1 -1
  254. package/Particles/particleHelper.js +2 -1
  255. package/Particles/particleHelper.js.map +1 -1
  256. package/Particles/particleSystemSet.d.ts +1 -0
  257. package/Particles/particleSystemSet.js +1 -0
  258. package/Particles/particleSystemSet.js.map +1 -1
  259. package/Particles/pointsCloudSystem.d.ts +3 -3
  260. package/Particles/webgl2ParticleSystem.d.ts +1 -1
  261. package/Particles/webgl2ParticleSystem.js +1 -2
  262. package/Particles/webgl2ParticleSystem.js.map +1 -1
  263. package/Physics/v2/Plugins/havokPlugin.d.ts +2 -2
  264. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -1
  265. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  266. package/PostProcesses/index.d.ts +1 -0
  267. package/PostProcesses/index.js +1 -0
  268. package/PostProcesses/index.js.map +1 -1
  269. package/PostProcesses/passPostProcess.d.ts +2 -3
  270. package/PostProcesses/passPostProcess.js +36 -48
  271. package/PostProcesses/passPostProcess.js.map +1 -1
  272. package/PostProcesses/thinPassPostProcess.d.ts +48 -0
  273. package/PostProcesses/thinPassPostProcess.js +113 -0
  274. package/PostProcesses/thinPassPostProcess.js.map +1 -0
  275. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +1 -1
  276. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
  277. package/Rendering/depthRenderer.js +1 -1
  278. package/Rendering/depthRenderer.js.map +1 -1
  279. package/Rendering/iblCdfGenerator.d.ts +13 -5
  280. package/Rendering/iblCdfGenerator.js +67 -10
  281. package/Rendering/iblCdfGenerator.js.map +1 -1
  282. package/Rendering/objectRenderer.d.ts +5 -3
  283. package/Rendering/objectRenderer.js +5 -3
  284. package/Rendering/objectRenderer.js.map +1 -1
  285. package/Rendering/renderingManager.d.ts +4 -0
  286. package/Rendering/renderingManager.js +1 -0
  287. package/Rendering/renderingManager.js.map +1 -1
  288. package/Shaders/ShadersInclude/gaussianSplatting.js +6 -6
  289. package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
  290. package/Shaders/ShadersInclude/intersectionFunctions.d.ts +5 -0
  291. package/Shaders/ShadersInclude/intersectionFunctions.js +14 -0
  292. package/Shaders/ShadersInclude/intersectionFunctions.js.map +1 -0
  293. package/Shaders/ShadersInclude/pbrBlockReflection.js +13 -8
  294. package/Shaders/ShadersInclude/pbrBlockReflection.js.map +1 -1
  295. package/Shaders/background.fragment.d.ts +1 -0
  296. package/Shaders/background.fragment.js +3 -5
  297. package/Shaders/background.fragment.js.map +1 -1
  298. package/Shaders/gaussianSplatting.vertex.js +2 -1
  299. package/Shaders/gaussianSplatting.vertex.js.map +1 -1
  300. package/Shaders/hdrIrradianceFiltering.fragment.d.ts +9 -0
  301. package/Shaders/hdrIrradianceFiltering.fragment.js +25 -0
  302. package/Shaders/hdrIrradianceFiltering.fragment.js.map +1 -0
  303. package/Shaders/hdrIrradianceFiltering.vertex.d.ts +5 -0
  304. package/Shaders/hdrIrradianceFiltering.vertex.js +15 -0
  305. package/Shaders/hdrIrradianceFiltering.vertex.js.map +1 -0
  306. package/Shaders/pbr.fragment.js +1 -3
  307. package/Shaders/pbr.fragment.js.map +1 -1
  308. package/ShadersWGSL/ShadersInclude/intersectionFunctions.d.ts +5 -0
  309. package/ShadersWGSL/ShadersInclude/intersectionFunctions.js +14 -0
  310. package/ShadersWGSL/ShadersInclude/intersectionFunctions.js.map +1 -0
  311. package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js +13 -8
  312. package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js.map +1 -1
  313. package/ShadersWGSL/background.fragment.d.ts +1 -0
  314. package/ShadersWGSL/background.fragment.js +3 -5
  315. package/ShadersWGSL/background.fragment.js.map +1 -1
  316. package/ShadersWGSL/greasedLine.fragment.js +9 -3
  317. package/ShadersWGSL/greasedLine.fragment.js.map +1 -1
  318. package/ShadersWGSL/greasedLine.vertex.js +12 -2
  319. package/ShadersWGSL/greasedLine.vertex.js.map +1 -1
  320. package/ShadersWGSL/hdrIrradianceFiltering.fragment.d.ts +9 -0
  321. package/ShadersWGSL/hdrIrradianceFiltering.fragment.js +26 -0
  322. package/ShadersWGSL/hdrIrradianceFiltering.fragment.js.map +1 -0
  323. package/ShadersWGSL/hdrIrradianceFiltering.vertex.d.ts +5 -0
  324. package/ShadersWGSL/hdrIrradianceFiltering.vertex.js +16 -0
  325. package/ShadersWGSL/hdrIrradianceFiltering.vertex.js.map +1 -0
  326. package/ShadersWGSL/outline.fragment.js +1 -1
  327. package/ShadersWGSL/outline.fragment.js.map +1 -1
  328. package/ShadersWGSL/passCube.fragment.js +1 -1
  329. package/ShadersWGSL/passCube.fragment.js.map +1 -1
  330. package/ShadersWGSL/pbr.fragment.js +1 -3
  331. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  332. package/XR/features/WebXRDepthSensing.d.ts +24 -2
  333. package/XR/features/WebXRDepthSensing.js +320 -26
  334. package/XR/features/WebXRDepthSensing.js.map +1 -1
  335. package/XR/features/WebXRHandTracking.js +8 -7
  336. package/XR/features/WebXRHandTracking.js.map +1 -1
  337. package/package.json +1 -1
  338. package/scene.js +9 -5
  339. package/scene.js.map +1 -1
  340. package/types.d.ts +4 -0
  341. package/types.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"dracoC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AO,CAAC,CAAC;YAC7C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACjD,MAAM,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,MAAM,SAAS,GAAG,CAAC,KAA4B,EAAE,EAAE;YAC/C,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC/B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrB,MAAM,CAAC,WAAW,CAAC;gBACf,EAAE,EAAE,MAAM;gBACV,OAAO,EAAE;oBACL,GAAG,EAAE,SAAS;iBACjB;aACJ,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,iDAAiD;YACjD,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,OAAO,EAAE;oBACL,GAAG,EAAE,SAAS;oBACd,UAAU,EAAE,KAAK;iBACpB;aACJ,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\nexport interface AttributeData {\r\n kind: string;\r\n data: ArrayBufferView;\r\n size: number;\r\n byteOffset: number;\r\n byteStride: number;\r\n normalized: boolean;\r\n}\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\ninterface DecodeMeshDoneMessage {\r\n id: \"decodeMeshDone\";\r\n totalVertices: number;\r\n}\r\n\r\ninterface IndicesMessage {\r\n id: \"indices\";\r\n data: Uint16Array | Uint32Array;\r\n}\r\n\r\ninterface AttributeMessage extends AttributeData {\r\n id: \"attribute\";\r\n}\r\nexport type Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: Message, transfer?: any[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function decodeMesh(\r\n decoderModule: any /*DecoderModule*/,\r\n data: Int8Array,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder() as Decoder;\r\n\r\n buffer = new decoderModule.DecoderBuffer() as DecoderBuffer;\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh as Mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud as PointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributes) {\r\n for (const kind in attributes) {\r\n const id = attributes[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: { [kind: string]: number } = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function workerFunction(): void {\r\n let decoderPromise: PromiseLike<any> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n const decoder = message.decoder;\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n }\r\n const initDecoderObject = decoder.wasmBinary ? { wasmBinary: decoder.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = decodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param decoderWasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, decoderWasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n if (!decoderWasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n decoder: {\r\n url: moduleUrl,\r\n },\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = decoderWasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n decoder: {\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n },\r\n [clone]\r\n );\r\n }\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,MAAe,CAAC,oBAAoB,EACpC,UAAsC,EACtC,OAA4C,EAC5C,OAA6B;IAE7B,MAAM,aAAa,GAAG,MAAuB,CAAC;IAC9C,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,WAAW,GAA0B,IAAI,CAAC;IAC9C,IAAI,IAAI,GAAmB,IAAI,CAAC;IAChC,IAAI,mBAAmB,GAA6B,IAAI,CAAC;IACzD,MAAM,YAAY,GAA2B,EAAE,CAAC,CAAC,kCAAkC;IAEnF,8DAA8D;IAC9D,MAAM,iBAAiB,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC;IAC7E,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACzE,CAAC;IAED,8GAA8G;IAC9G,8GAA8G;IAC9G,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,sDAAsD;QACtD,MAAM,qBAAqB,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC;QACrF,OAAO,GAAG,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,qBAAqB,CAAC,CAAC;QACjG,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,qBA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;QAEF,MAAM,SAAS,GAAG,CAAC,KAAoC,EAAE,EAAE;YACvD,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC/B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,2CAA2C;QAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,CAAC,WAAW,CAAC;gBACf,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;aACjB,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,iDAAiD;YACjD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACN,CAAC;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { EncoderMessage, IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from \"./dracoEncoder.types\";\r\nimport type { DecoderMessage } from \"./dracoDecoder.types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status, DecoderModule, EncoderModule, MeshBuilder, Encoder, DracoInt8Array } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoEncoderModule: (props: { wasmBinary?: ArrayBuffer }) => Promise<EncoderModule>;\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: InitDoneMessage | DecoderMessage | EncoderMessage, transfer?: ArrayBufferLike[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function EncodeMesh(\r\n module: unknown /** EncoderModule */,\r\n attributes: Array<IDracoAttributeData>,\r\n indices: Nullable<Uint16Array | Uint32Array>,\r\n options: IDracoEncoderOptions\r\n): Nullable<IDracoEncodedMeshData> {\r\n const encoderModule = module as EncoderModule;\r\n let encoder: Nullable<Encoder> = null;\r\n let meshBuilder: Nullable<MeshBuilder> = null;\r\n let mesh: Nullable<Mesh> = null;\r\n let encodedNativeBuffer: Nullable<DracoInt8Array> = null;\r\n const attributeIDs: Record<string, number> = {}; // Babylon kind -> Draco unique id\r\n\r\n // Double-check that at least a position attribute is provided\r\n const positionAttribute = attributes.find((a) => a.dracoName === \"POSITION\");\r\n if (!positionAttribute) {\r\n throw new Error(\"Position attribute is required for Draco encoding\");\r\n }\r\n\r\n // If no indices are provided, assume mesh is unindexed. Let's generate them, since Draco meshes require them.\r\n // TODO: This may be the POINT_CLOUD case, but need to investigate. Should work for now-- just less efficient.\r\n if (!indices) {\r\n // Assume position attribute is the largest attribute.\r\n const positionVerticesCount = positionAttribute.data.length / positionAttribute.size;\r\n indices = new (positionVerticesCount > 65535 ? Uint32Array : Uint16Array)(positionVerticesCount);\r\n for (let i = 0; i < positionVerticesCount; i++) {\r\n indices[i] = i;\r\n }\r\n }\r\n\r\n try {\r\n encoder = new encoderModule.Encoder();\r\n meshBuilder = new encoderModule.MeshBuilder();\r\n mesh = new encoderModule.Mesh();\r\n\r\n // Add the faces\r\n meshBuilder.AddFacesToMesh(mesh, indices.length / 3, indices);\r\n\r\n // Add the attributes\r\n for (const attribute of attributes) {\r\n const verticesCount = attribute.data.length / attribute.size;\r\n attributeIDs[attribute.kind] = meshBuilder.AddFloatAttribute(mesh, encoderModule[attribute.dracoName], verticesCount, attribute.size, attribute.data);\r\n if (options.quantizationBits && options.quantizationBits[attribute.dracoName]) {\r\n encoder.SetAttributeQuantization(encoderModule[attribute.dracoName], options.quantizationBits[attribute.dracoName]);\r\n }\r\n }\r\n\r\n // Set the options\r\n if (options.method) {\r\n encoder.SetEncodingMethod(encoderModule[options.method]);\r\n }\r\n if (options.encodeSpeed !== undefined && options.decodeSpeed !== undefined) {\r\n encoder.SetSpeedOptions(options.encodeSpeed, options.decodeSpeed);\r\n }\r\n\r\n // Encode to native buffer\r\n encodedNativeBuffer = new encoderModule.DracoInt8Array() as DracoInt8Array;\r\n const encodedLength = encoder.EncodeMeshToDracoBuffer(mesh, encodedNativeBuffer);\r\n if (encodedLength <= 0) {\r\n throw new Error(\"Draco encoding failed.\");\r\n }\r\n\r\n // Copy the native buffer data to worker heap\r\n const encodedData = new Int8Array(encodedLength);\r\n for (let i = 0; i < encodedLength; i++) {\r\n encodedData[i] = encodedNativeBuffer.GetValue(i);\r\n }\r\n\r\n return { data: encodedData, attributeIDs: attributeIDs };\r\n } finally {\r\n if (mesh) {\r\n encoderModule.destroy(mesh);\r\n }\r\n if (meshBuilder) {\r\n encoderModule.destroy(meshBuilder);\r\n }\r\n if (encoder) {\r\n encoderModule.destroy(encoder);\r\n }\r\n if (encodedNativeBuffer) {\r\n encoderModule.destroy(encodedNativeBuffer);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function EncoderWorkerFunction(): void {\r\n let encoderPromise: PromiseLike<EncoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initEncoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n encoderPromise = DracoEncoderModule(initEncoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"encodeMesh\": {\r\n if (!encoderPromise) {\r\n throw new Error(\"Draco encoder module is not available\");\r\n }\r\n encoderPromise.then((encoder) => {\r\n const result = EncodeMesh(encoder, message.attributes, message.indices, message.options);\r\n postMessage({ id: \"encodeMeshDone\", encodedMeshData: result }, result ? [result.data.buffer] : undefined);\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function DecodeMesh(\r\n module: unknown /** DecoderModule */,\r\n data: Int8Array,\r\n attributeIDs: Record<string, number> | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n const decoderModule = module as DecoderModule;\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder();\r\n\r\n buffer = new decoderModule.DecoderBuffer();\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh as Mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud as PointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any /** Attribute */) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n // this cast seems to be needed because of an issue with typescript, as all constructors do have the ptr and numValues arguments.\r\n const data = new (info.typedArrayConstructor as Float32ArrayConstructor)(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributeIDs) {\r\n for (const kind in attributeIDs) {\r\n const id = attributeIDs[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: Record<string, number> = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function DecoderWorkerFunction(): void {\r\n let decoderPromise: PromiseLike<DecoderModule> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (message.url) {\r\n importScripts(message.url);\r\n }\r\n const initDecoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = DecodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n// For backwards compatibility\r\nexport { DecoderWorkerFunction as workerFunction };\r\n\r\n/**\r\n * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param wasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, wasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<InitDoneMessage>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // Load with either JS-only or WASM version\r\n if (!wasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n url: moduleUrl,\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = wasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n [clone]\r\n );\r\n }\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
@@ -3,12 +3,7 @@ import { Geometry } from "../geometry";
3
3
  import type { BoundingInfo } from "../../Culling/boundingInfo";
4
4
  import type { Scene } from "../../scene";
5
5
  import type { Nullable } from "../../types";
6
- import type { AttributeData } from "./dracoCompressionWorker";
7
- export interface MeshData {
8
- indices?: Uint16Array | Uint32Array;
9
- attributes: Array<AttributeData>;
10
- totalVertices: number;
11
- }
6
+ import type { MeshData } from "./dracoDecoder.types";
12
7
  /**
13
8
  * @experimental This class is an experimental version of `DracoCompression` and is subject to change.
14
9
  *
@@ -16,7 +11,7 @@ export interface MeshData {
16
11
  *
17
12
  * This class wraps the Draco decoder module.
18
13
  *
19
- * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.
14
+ * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.
20
15
  *
21
16
  * To update the configuration, use the following code:
22
17
  * ```javascript
@@ -62,8 +57,8 @@ export declare class DracoDecoder extends DracoCodec {
62
57
  */
63
58
  static ResetDefault(skipDispose?: boolean): void;
64
59
  protected _isModuleAvailable(): boolean;
65
- protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: any): Promise<{
66
- module: any; /** DecoderModule */
60
+ protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{
61
+ module: unknown; /** DecoderModule */
67
62
  }>;
68
63
  protected _getWorkerContent(): string;
69
64
  /**
@@ -3,7 +3,7 @@ import { Tools } from "../../Misc/tools.js";
3
3
  import { Geometry } from "../geometry.js";
4
4
  import { VertexBuffer } from "../buffer.js";
5
5
  import { Logger } from "../../Misc/logger.js";
6
- import { decodeMesh, workerFunction } from "./dracoCompressionWorker.js";
6
+ import { DecodeMesh, DecoderWorkerFunction } from "./dracoCompressionWorker.js";
7
7
  /**
8
8
  * @experimental This class is an experimental version of `DracoCompression` and is subject to change.
9
9
  *
@@ -11,7 +11,7 @@ import { decodeMesh, workerFunction } from "./dracoCompressionWorker.js";
11
11
  *
12
12
  * This class wraps the Draco decoder module.
13
13
  *
14
- * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.
14
+ * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.
15
15
  *
16
16
  * To update the configuration, use the following code:
17
17
  * ```javascript
@@ -62,12 +62,12 @@ export class DracoDecoder extends DracoCodec {
62
62
  _isModuleAvailable() {
63
63
  return typeof DracoDecoderModule !== "undefined";
64
64
  }
65
- async _createModuleAsync(wasmBinary, jsModule) {
65
+ async _createModuleAsync(wasmBinary, jsModule /** DracoDecoderModule */) {
66
66
  const module = await (jsModule || DracoDecoderModule)({ wasmBinary });
67
67
  return { module };
68
68
  }
69
69
  _getWorkerContent() {
70
- return `${decodeMesh}(${workerFunction})()`;
70
+ return `${DecodeMesh}(${DecoderWorkerFunction})()`;
71
71
  }
72
72
  /**
73
73
  * Creates a new Draco decoder.
@@ -147,7 +147,7 @@ export class DracoDecoder extends DracoCodec {
147
147
  return this._modulePromise.then((decoder) => {
148
148
  let resultIndices = null;
149
149
  const resultAttributes = [];
150
- const numPoints = decodeMesh(decoder.module, dataView, attributes, (indices) => {
150
+ const numPoints = DecodeMesh(decoder.module, dataView, attributes, (indices) => {
151
151
  resultIndices = indices;
152
152
  }, (kind, data, size, byteOffset, byteStride, normalized) => {
153
153
  resultAttributes.push({
@@ -1 +1 @@
1
- {"version":3,"file":"dracoDecoder.js","sourceRoot":"","sources":["../../../../../dev/core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AAC,2BAA2B,GAAG,IAAI,CAAC;QAChD,CAAC;QACD,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACnB,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;YAC1C,QAAQ,CAAC,iBAAiB,CACtB,IAAI,YAAY,CACZ,KAAK,CAAC,SAAS,EAAE,EACjB,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,KAAK,EACL,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,IAAI,EACd,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,IAAI,CACP,EACD,QAAQ,CAAC,aAAa,CACzB,CAAC;QACN,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;;AA1PD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;IAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;IAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;CAC/D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { DracoDecoderModule } from \"draco3dgltf\";\r\nimport { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { decodeMesh, workerFunction } from \"./dracoCompressionWorker\";\r\nimport type { AttributeData, Message } from \"./dracoCompressionWorker\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\nexport interface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\n/**\r\n * @experimental This class is an experimental version of `DracoCompression` and is subject to change.\r\n *\r\n * Draco Decoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco decoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoDecoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoDecoder.DefaultAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoDecoder object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoDecoder.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n */\r\nexport class DracoDecoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoDecoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the decoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoDecoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoDecoder> = null;\r\n /**\r\n * Default instance for the DracoDecoder.\r\n */\r\n public static get Default(): DracoDecoder {\r\n DracoDecoder._Default ??= new DracoDecoder();\r\n return DracoDecoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoDecoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoDecoder._Default) {\r\n if (!skipDispose) {\r\n DracoDecoder._Default.dispose();\r\n }\r\n DracoDecoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoDecoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: any): Promise<{ module: any /** DecoderModule */ }> {\r\n const module = await ((jsModule as DracoDecoderModule) || DracoDecoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${decodeMesh}(${workerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco decoder.\r\n * @param configuration Optional override of the configuration for the DracoDecoder. If not provided, defaults to {@link DracoDecoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoDecoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView of the compressed Draco data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView of the Draco compressed data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean },\r\n boundingInfo: Nullable<BoundingInfo>\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (boundingInfo) {\r\n geometry._boundingInfo = boundingInfo;\r\n geometry.useBoundingInfoFromGeometry = true;\r\n }\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoDecoder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAiC,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW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1C,QAAQ,CAAC,iBAAiB,CACtB,IAAI,YAAY,CACZ,KAAK,CAAC,SAAS,EAAE,EACjB,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,KAAK,EACL,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,IAAI,EACd,SAAS,EACT,SAAS,CAAC,UAAU,EACpB,IAAI,CACP,EACD,QAAQ,CAAC,aAAa,CACzB,CAAC;QACN,CAAC;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;;AA1PD;;;;;;GAMG;AACW,iCAAoB,GAA6B;IAC3D,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;IAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;IAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;CAC/D,CAAC;AASe,qBAAQ,GAA2B,IAAI,CAAC","sourcesContent":["import { DracoDecoderModule } from \"draco3dgltf\";\r\nimport { _IsConfigurationAvailable, DracoCodec, type IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport { DecodeMesh, DecoderWorkerFunction } from \"./dracoCompressionWorker\";\r\nimport type { AttributeData, MeshData, DecoderMessage } from \"./dracoDecoder.types\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\n/**\r\n * @experimental This class is an experimental version of `DracoCompression` and is subject to change.\r\n *\r\n * Draco Decoder (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco decoder module.\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the Babylon.js cdn https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoDecoder.DefaultConfiguration = {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoDecoder.DefaultAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoDecoder object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoDecoder.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n */\r\nexport class DracoDecoder extends DracoCodec {\r\n /**\r\n * Default configuration for the DracoDecoder. Defaults to the following:\r\n * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.\r\n * - wasmUrl: `\"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"`\r\n * - wasmBinaryUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"`\r\n * - fallbackUrl: `\"https://cdn.babylonjs.com/draco_decoder_gltf.js\"`\r\n */\r\n public static DefaultConfiguration: IDracoCodecConfiguration = {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n };\r\n\r\n /**\r\n * Returns true if the decoder's `DefaultConfiguration` is available.\r\n */\r\n public static get DefaultAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoDecoder.DefaultConfiguration);\r\n }\r\n\r\n protected static _Default: Nullable<DracoDecoder> = null;\r\n /**\r\n * Default instance for the DracoDecoder.\r\n */\r\n public static get Default(): DracoDecoder {\r\n DracoDecoder._Default ??= new DracoDecoder();\r\n return DracoDecoder._Default;\r\n }\r\n\r\n /**\r\n * Reset the default DracoDecoder object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoDecoder._Default) {\r\n if (!skipDispose) {\r\n DracoDecoder._Default.dispose();\r\n }\r\n DracoDecoder._Default = null;\r\n }\r\n }\r\n\r\n protected override _isModuleAvailable(): boolean {\r\n return typeof DracoDecoderModule !== \"undefined\";\r\n }\r\n\r\n protected override async _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule */): Promise<{ module: unknown /** DecoderModule */ }> {\r\n const module = await ((jsModule as DracoDecoderModule) || DracoDecoderModule)({ wasmBinary });\r\n return { module };\r\n }\r\n\r\n protected override _getWorkerContent(): string {\r\n return `${DecodeMesh}(${DecoderWorkerFunction})()`;\r\n }\r\n\r\n /**\r\n * Creates a new Draco decoder.\r\n * @param configuration Optional override of the configuration for the DracoDecoder. If not provided, defaults to {@link DracoDecoder.DefaultConfiguration}.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration = DracoDecoder.DefaultConfiguration) {\r\n super(configuration);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView of the compressed Draco data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<DecoderMessage>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._modulePromise) {\r\n return this._modulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = DecodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView of the Draco compressed data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean },\r\n boundingInfo: Nullable<BoundingInfo>\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (boundingInfo) {\r\n geometry._boundingInfo = boundingInfo;\r\n geometry.useBoundingInfoFromGeometry = true;\r\n }\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Decoded Draco mesh data.
3
+ */
4
+ export interface MeshData {
5
+ /**
6
+ * The indices of the mesh. Point clouds will not have indices.
7
+ */
8
+ indices?: Uint16Array | Uint32Array;
9
+ /**
10
+ * The attributes of the mesh.
11
+ */
12
+ attributes: Array<AttributeData>;
13
+ /**
14
+ * The total number of vertices in the mesh.
15
+ */
16
+ totalVertices: number;
17
+ }
18
+ /**
19
+ * @internal
20
+ */
21
+ export interface AttributeData {
22
+ kind: string;
23
+ data: ArrayBufferView;
24
+ size: number;
25
+ byteOffset: number;
26
+ byteStride: number;
27
+ normalized: boolean;
28
+ }
29
+ /**
30
+ * @internal
31
+ */
32
+ export interface DecodeMeshDoneMessage {
33
+ id: "decodeMeshDone";
34
+ totalVertices: number;
35
+ }
36
+ /**
37
+ * @internal
38
+ */
39
+ export interface IndicesMessage {
40
+ id: "indices";
41
+ data: Uint16Array | Uint32Array;
42
+ }
43
+ /**
44
+ * @internal
45
+ */
46
+ export interface AttributeMessage extends AttributeData {
47
+ id: "attribute";
48
+ }
49
+ /**
50
+ * @internal
51
+ */
52
+ export type DecoderMessage = DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=dracoDecoder.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dracoDecoder.types.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoDecoder.types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Decoded Draco mesh data.\n */\nexport interface MeshData {\n /**\n * The indices of the mesh. Point clouds will not have indices.\n */\n indices?: Uint16Array | Uint32Array;\n /**\n * The attributes of the mesh.\n */\n attributes: Array<AttributeData>;\n /**\n * The total number of vertices in the mesh.\n */\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface AttributeData {\n kind: string;\n data: ArrayBufferView;\n size: number;\n byteOffset: number;\n byteStride: number;\n normalized: boolean;\n}\n\n/**\n * @internal\n */\nexport interface DecodeMeshDoneMessage {\n id: \"decodeMeshDone\";\n totalVertices: number;\n}\n\n/**\n * @internal\n */\nexport interface IndicesMessage {\n id: \"indices\";\n data: Uint16Array | Uint32Array;\n}\n\n/**\n * @internal\n */\nexport interface AttributeMessage extends AttributeData {\n id: \"attribute\";\n}\n\n/**\n * @internal\n */\nexport type DecoderMessage = DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\n"]}
@@ -0,0 +1,95 @@
1
+ import { DracoCodec, type IDracoCodecConfiguration } from "./dracoCodec";
2
+ import type { IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from "./dracoEncoder.types";
3
+ import type { Nullable } from "../../types";
4
+ import { Mesh } from "../mesh";
5
+ import type { Geometry } from "../geometry";
6
+ /**
7
+ * @experimental This class is subject to change.
8
+ *
9
+ * Draco Encoder (https://google.github.io/draco/)
10
+ *
11
+ * This class wraps the Draco encoder module.
12
+ *
13
+ * By default, the configuration points to a copy of the Draco encoder files from the Babylon.js cdn https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js.
14
+ *
15
+ * To update the configuration, use the following code:
16
+ * ```javascript
17
+ * DracoEncoder.DefaultConfiguration = {
18
+ * wasmUrl: "<url to the WebAssembly library>",
19
+ * wasmBinaryUrl: "<url to the WebAssembly binary>",
20
+ * fallbackUrl: "<url to the fallback JavaScript library>",
21
+ * };
22
+ * ```
23
+ *
24
+ * Draco has two versions, one for WebAssembly and one for JavaScript. The encoder configuration can be set to only support WebAssembly or only support the JavaScript version.
25
+ * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.
26
+ * Use `DracoEncoder.DefaultAvailable` to determine if the encoder configuration is available for the current context.
27
+ *
28
+ * To encode Draco compressed data, get the default DracoEncoder object and call encodeMeshAsync:
29
+ * ```javascript
30
+ * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);
31
+ * ```
32
+ *
33
+ * Currently, DracoEncoder only encodes to meshes. Encoding to point clouds is not yet supported.
34
+ *
35
+ * Only position, normal, color, and UV attributes are supported natively by the encoder. All other attributes are treated as generic. This means that,
36
+ * when decoding these generic attributes later, additional information about their original Babylon types will be needed to interpret the data correctly.
37
+ * You can use the return value of `encodeMeshAsync` to source this information, specifically the `attributes` field. E.g.,
38
+ * ```javascript
39
+ * var dracoData = await DracoEncoder.Default.encodeMeshAsync(mesh);
40
+ * var meshData = await DracoDecoder.Default.decodeMeshToMeshDataAsync(dracoData.data, dracoData.attributes);
41
+ * ```
42
+ *
43
+ * By default, DracoEncoder will encode all available attributes of the mesh. To exclude specific attributes, use the following code:
44
+ * ```javascript
45
+ * var options = { excludedAttributes: [VertexBuffer.MatricesIndicesKind, VertexBuffer.MatricesWeightsKind] };
46
+ * var dracoData = await DracoDecoder.Default.encodeMeshAsync(mesh, options);
47
+ * ```
48
+ */
49
+ export declare class DracoEncoder extends DracoCodec {
50
+ /**
51
+ * Default configuration for the DracoEncoder. Defaults to the following:
52
+ * - numWorkers: 50% of the available logical processors, capped to 4. If no logical processors are available, defaults to 1.
53
+ * - wasmUrl: `"https://cdn.babylonjs.com/draco_encoder_wasm_wrapper.js"`
54
+ * - wasmBinaryUrl: `"https://cdn.babylonjs.com/draco_encoder.wasm"`
55
+ * - fallbackUrl: `"https://cdn.babylonjs.com/draco_encoder.js"`
56
+ */
57
+ static DefaultConfiguration: IDracoCodecConfiguration;
58
+ /**
59
+ * Returns true if the encoder's `DefaultConfiguration` is available.
60
+ */
61
+ static get DefaultAvailable(): boolean;
62
+ protected static _Default: Nullable<DracoEncoder>;
63
+ /**
64
+ * Default instance for the DracoEncoder.
65
+ */
66
+ static get Default(): DracoEncoder;
67
+ /**
68
+ * Reset the default DracoEncoder object to null and disposing the removed default instance.
69
+ * Note that if the workerPool is a member of the static DefaultConfiguration object it is recommended not to run dispose,
70
+ * unless the static worker pool is no longer needed.
71
+ * @param skipDispose set to true to not dispose the removed default instance
72
+ */
73
+ static ResetDefault(skipDispose?: boolean): void;
74
+ protected _isModuleAvailable(): boolean;
75
+ protected _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoEncoderModule */): Promise<{
76
+ module: unknown; /** EncoderModule */
77
+ }>;
78
+ protected _getWorkerContent(): string;
79
+ /**
80
+ * Creates a new Draco encoder.
81
+ * @param configuration Optional override of the configuration for the DracoEncoder. If not provided, defaults to {@link DracoEncoder.DefaultConfiguration}.
82
+ */
83
+ constructor(configuration?: IDracoCodecConfiguration);
84
+ /**
85
+ * @internal
86
+ */
87
+ _encodeAsync(attributes: Array<IDracoAttributeData>, indices: Nullable<Uint16Array | Uint32Array>, options?: IDracoEncoderOptions): Promise<Nullable<IDracoEncodedMeshData>>;
88
+ /**
89
+ * Encodes a mesh or geometry into a Draco-encoded mesh data.
90
+ * @param input the mesh or geometry to encode
91
+ * @param options options for the encoding
92
+ * @returns a promise that resolves to the newly-encoded data
93
+ */
94
+ encodeMeshAsync(input: Mesh | Geometry, options?: IDracoEncoderOptions): Promise<Nullable<IDracoEncodedMeshData>>;
95
+ }