@babylonjs/core 7.42.0 → 7.44.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 (317) hide show
  1. package/Actions/actionEvent.d.ts +4 -4
  2. package/Animations/animation.js +1 -1
  3. package/Animations/animation.js.map +1 -1
  4. package/Buffers/bufferUtils.d.ts +8 -1
  5. package/Buffers/bufferUtils.js +15 -0
  6. package/Buffers/bufferUtils.js.map +1 -1
  7. package/Culling/Helper/boundingInfoHelper.d.ts +2 -9
  8. package/Culling/Helper/boundingInfoHelper.js +2 -9
  9. package/Culling/Helper/boundingInfoHelper.js.map +1 -1
  10. package/Culling/Helper/computeShaderBoundingHelper.js +3 -4
  11. package/Culling/Helper/computeShaderBoundingHelper.js.map +1 -1
  12. package/Culling/Helper/transformFeedbackBoundingHelper.js +27 -64
  13. package/Culling/Helper/transformFeedbackBoundingHelper.js.map +1 -1
  14. package/Engines/Extensions/engine.multiRender.js +3 -2
  15. package/Engines/Extensions/engine.multiRender.js.map +1 -1
  16. package/Engines/WebGPU/webgpuCacheRenderPipeline.d.ts +1 -0
  17. package/Engines/WebGPU/webgpuCacheRenderPipeline.js +5 -0
  18. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  19. package/Engines/WebGPU/webgpuTextureManager.js +6 -1
  20. package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
  21. package/Engines/abstractEngine.js +2 -2
  22. package/Engines/abstractEngine.js.map +1 -1
  23. package/Engines/engine.d.ts +5 -2
  24. package/FlowGraph/flowGraphConnection.d.ts +1 -1
  25. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.d.ts +64 -0
  26. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js +147 -0
  27. package/FrameGraph/Node/Blocks/Layers/glowLayerBlock.js.map +1 -0
  28. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.d.ts +42 -0
  29. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js +78 -0
  30. package/FrameGraph/Node/Blocks/PostProcesses/basePostProcessBlock.js.map +1 -0
  31. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.d.ts +3 -19
  32. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js +3 -49
  33. package/FrameGraph/Node/Blocks/PostProcesses/blackAndWhitePostProcessBlock.js.map +1 -1
  34. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.d.ts +3 -19
  35. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js +3 -49
  36. package/FrameGraph/Node/Blocks/PostProcesses/bloomPostProcessBlock.js.map +1 -1
  37. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.d.ts +3 -19
  38. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js +3 -49
  39. package/FrameGraph/Node/Blocks/PostProcesses/blurPostProcessBlock.js.map +1 -1
  40. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.d.ts +2 -17
  41. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js +3 -45
  42. package/FrameGraph/Node/Blocks/PostProcesses/circleOfConfusionPostProcessBlock.js.map +1 -1
  43. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.d.ts +2 -17
  44. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js +3 -44
  45. package/FrameGraph/Node/Blocks/PostProcesses/depthOfFieldPostProcessBlock.js.map +1 -1
  46. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.d.ts +3 -19
  47. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js +3 -49
  48. package/FrameGraph/Node/Blocks/PostProcesses/extractHighlightsPostProcessBlock.js.map +1 -1
  49. package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.d.ts +47 -0
  50. package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js +65 -0
  51. package/FrameGraph/Node/Blocks/PostProcesses/passPostProcessBlock.js.map +1 -0
  52. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js +0 -15
  53. package/FrameGraph/Node/Blocks/Rendering/baseObjectRendererBlock.js.map +1 -1
  54. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.d.ts +4 -0
  55. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js +9 -0
  56. package/FrameGraph/Node/Blocks/Rendering/baseShadowGeneratorBlock.js.map +1 -1
  57. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.d.ts +1 -6
  58. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js +0 -13
  59. package/FrameGraph/Node/Blocks/Rendering/csmShadowGeneratorBlock.js.map +1 -1
  60. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js +0 -1
  61. package/FrameGraph/Node/Blocks/Rendering/shadowGeneratorBlock.js.map +1 -1
  62. package/FrameGraph/Node/Blocks/index.d.ts +2 -0
  63. package/FrameGraph/Node/Blocks/index.js +2 -0
  64. package/FrameGraph/Node/Blocks/index.js.map +1 -1
  65. package/FrameGraph/Node/nodeRenderGraphBlock.js +17 -0
  66. package/FrameGraph/Node/nodeRenderGraphBlock.js.map +1 -1
  67. package/FrameGraph/Passes/renderPass.d.ts +0 -8
  68. package/FrameGraph/Passes/renderPass.js +0 -10
  69. package/FrameGraph/Passes/renderPass.js.map +1 -1
  70. package/FrameGraph/Tasks/Layers/glowLayerTask.d.ts +57 -0
  71. package/FrameGraph/Tasks/Layers/glowLayerTask.js +173 -0
  72. package/FrameGraph/Tasks/Layers/glowLayerTask.js.map +1 -0
  73. package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js +1 -1
  74. package/FrameGraph/Tasks/PostProcesses/bloomMergeTask.js.map +1 -1
  75. package/FrameGraph/Tasks/PostProcesses/bloomTask.js +7 -0
  76. package/FrameGraph/Tasks/PostProcesses/bloomTask.js.map +1 -1
  77. package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js +1 -1
  78. package/FrameGraph/Tasks/PostProcesses/circleOfConfusionTask.js.map +1 -1
  79. package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js +1 -1
  80. package/FrameGraph/Tasks/PostProcesses/depthOfFieldBlurTask.js.map +1 -1
  81. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js +5 -5
  82. package/FrameGraph/Tasks/PostProcesses/depthOfFieldMergeTask.js.map +1 -1
  83. package/FrameGraph/Tasks/PostProcesses/depthOfFieldTask.js +12 -4
  84. package/FrameGraph/Tasks/PostProcesses/depthOfFieldTask.js.map +1 -1
  85. package/FrameGraph/Tasks/PostProcesses/passTask.d.ts +29 -0
  86. package/FrameGraph/Tasks/PostProcesses/passTask.js +31 -0
  87. package/FrameGraph/Tasks/PostProcesses/passTask.js.map +1 -0
  88. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js +1 -1
  89. package/FrameGraph/Tasks/PostProcesses/postProcessTask.js.map +1 -1
  90. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +0 -8
  91. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +1 -17
  92. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
  93. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js +3 -0
  94. package/FrameGraph/Tasks/Rendering/geometryRendererTask.js.map +1 -1
  95. package/FrameGraph/Tasks/Rendering/objectRendererTask.d.ts +4 -6
  96. package/FrameGraph/Tasks/Rendering/objectRendererTask.js +20 -22
  97. package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
  98. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +7 -1
  99. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +21 -5
  100. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
  101. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js +4 -6
  102. package/FrameGraph/Tasks/Rendering/taaObjectRendererTask.js.map +1 -1
  103. package/FrameGraph/Tasks/Texture/copyToTextureTask.js +1 -1
  104. package/FrameGraph/Tasks/Texture/copyToTextureTask.js.map +1 -1
  105. package/FrameGraph/frameGraph.js +22 -11
  106. package/FrameGraph/frameGraph.js.map +1 -1
  107. package/FrameGraph/frameGraphRenderContext.d.ts +2 -1
  108. package/FrameGraph/frameGraphRenderContext.js +2 -1
  109. package/FrameGraph/frameGraphRenderContext.js.map +1 -1
  110. package/FrameGraph/frameGraphTask.d.ts +11 -1
  111. package/FrameGraph/frameGraphTask.js +8 -0
  112. package/FrameGraph/frameGraphTask.js.map +1 -1
  113. package/FrameGraph/frameGraphTextureManager.d.ts +9 -3
  114. package/FrameGraph/frameGraphTextureManager.js +10 -4
  115. package/FrameGraph/frameGraphTextureManager.js.map +1 -1
  116. package/FrameGraph/index.d.ts +2 -0
  117. package/FrameGraph/index.js +2 -0
  118. package/FrameGraph/index.js.map +1 -1
  119. package/Gizmos/planeRotationGizmo.js +10 -0
  120. package/Gizmos/planeRotationGizmo.js.map +1 -1
  121. package/Inputs/scene.inputManager.js +2 -2
  122. package/Inputs/scene.inputManager.js.map +1 -1
  123. package/Layers/effectLayer.d.ts +32 -33
  124. package/Layers/effectLayer.js +144 -530
  125. package/Layers/effectLayer.js.map +1 -1
  126. package/Layers/glowLayer.d.ts +14 -41
  127. package/Layers/glowLayer.js +92 -178
  128. package/Layers/glowLayer.js.map +1 -1
  129. package/Layers/highlightLayer.d.ts +0 -1
  130. package/Layers/highlightLayer.js +0 -1
  131. package/Layers/highlightLayer.js.map +1 -1
  132. package/Layers/index.d.ts +2 -0
  133. package/Layers/index.js +2 -0
  134. package/Layers/index.js.map +1 -1
  135. package/Layers/thinEffectLayer.d.ts +230 -0
  136. package/Layers/thinEffectLayer.js +734 -0
  137. package/Layers/thinEffectLayer.js.map +1 -0
  138. package/Layers/thinGlowLayer.d.ts +141 -0
  139. package/Layers/thinGlowLayer.js +292 -0
  140. package/Layers/thinGlowLayer.js.map +1 -0
  141. package/Lights/Shadows/shadowGenerator.js +40 -19
  142. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  143. package/Materials/GreasedLine/greasedLinePluginMaterial.d.ts +6 -2
  144. package/Materials/GreasedLine/greasedLinePluginMaterial.js +8 -2
  145. package/Materials/GreasedLine/greasedLinePluginMaterial.js.map +1 -1
  146. package/Materials/GreasedLine/greasedLinePluginMaterialShadersGLSL.js +17 -11
  147. package/Materials/GreasedLine/greasedLinePluginMaterialShadersGLSL.js.map +1 -1
  148. package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js +29 -15
  149. package/Materials/GreasedLine/greasedLinePluginMaterialShadersWGSL.js.map +1 -1
  150. package/Materials/GreasedLine/greasedLineSimpleMaterial.d.ts +1 -0
  151. package/Materials/GreasedLine/greasedLineSimpleMaterial.js +1 -0
  152. package/Materials/GreasedLine/greasedLineSimpleMaterial.js.map +1 -1
  153. package/Materials/Node/Blocks/Input/inputBlock.js +34 -2
  154. package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
  155. package/Materials/Node/Blocks/PBR/reflectionBlock.js +1 -3
  156. package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
  157. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js +3 -3
  158. package/Materials/Node/Blocks/PBR/subSurfaceBlock.js.map +1 -1
  159. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js +34 -24
  160. package/Materials/Node/Blocks/Vertex/morphTargetsBlock.js.map +1 -1
  161. package/Materials/Node/nodeMaterial.d.ts +14 -2
  162. package/Materials/Node/nodeMaterial.js +19 -5
  163. package/Materials/Node/nodeMaterial.js.map +1 -1
  164. package/Materials/PBR/pbrBaseMaterial.d.ts +5 -0
  165. package/Materials/PBR/pbrBaseMaterial.js +6 -0
  166. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  167. package/Materials/Textures/Filtering/hdrFiltering.js +1 -0
  168. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  169. package/Materials/Textures/Filtering/hdrIrradianceFiltering.d.ts +69 -0
  170. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js +187 -0
  171. package/Materials/Textures/Filtering/hdrIrradianceFiltering.js.map +1 -0
  172. package/Materials/Textures/hdrCubeTexture.d.ts +5 -1
  173. package/Materials/Textures/hdrCubeTexture.js +29 -3
  174. package/Materials/Textures/hdrCubeTexture.js.map +1 -1
  175. package/Materials/Textures/index.d.ts +4 -0
  176. package/Materials/Textures/index.js +4 -0
  177. package/Materials/Textures/index.js.map +1 -1
  178. package/Materials/Textures/renderTargetTexture.d.ts +12 -0
  179. package/Materials/Textures/renderTargetTexture.js +29 -8
  180. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  181. package/Materials/materialHelper.functions.d.ts +17 -1
  182. package/Materials/materialHelper.functions.js +76 -4
  183. package/Materials/materialHelper.functions.js.map +1 -1
  184. package/Materials/shaderMaterial.d.ts +5 -4
  185. package/Materials/shaderMaterial.js +28 -51
  186. package/Materials/shaderMaterial.js.map +1 -1
  187. package/Materials/standardMaterial.d.ts +6 -2
  188. package/Materials/standardMaterial.js +5 -2
  189. package/Materials/standardMaterial.js.map +1 -1
  190. package/Meshes/Builders/greasedLineBuilder.d.ts +1 -1
  191. package/Meshes/Builders/planeBuilder.js +2 -2
  192. package/Meshes/Builders/planeBuilder.js.map +1 -1
  193. package/Meshes/Compression/dracoCodec.d.ts +4 -4
  194. package/Meshes/Compression/dracoCodec.js.map +1 -1
  195. package/Meshes/Compression/dracoCompression.d.ts +1 -1
  196. package/Meshes/Compression/dracoCompression.js.map +1 -1
  197. package/Meshes/Compression/dracoCompressionWorker.d.ts +16 -30
  198. package/Meshes/Compression/dracoCompressionWorker.js +128 -22
  199. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
  200. package/Meshes/Compression/dracoDecoder.d.ts +4 -9
  201. package/Meshes/Compression/dracoDecoder.js +5 -5
  202. package/Meshes/Compression/dracoDecoder.js.map +1 -1
  203. package/Meshes/Compression/dracoDecoder.types.d.ts +52 -0
  204. package/Meshes/Compression/dracoDecoder.types.js +2 -0
  205. package/Meshes/Compression/dracoDecoder.types.js.map +1 -0
  206. package/Meshes/Compression/dracoEncoder.d.ts +91 -0
  207. package/Meshes/Compression/dracoEncoder.js +239 -0
  208. package/Meshes/Compression/dracoEncoder.js.map +1 -0
  209. package/Meshes/Compression/dracoEncoder.types.d.ts +82 -0
  210. package/Meshes/Compression/dracoEncoder.types.js +2 -0
  211. package/Meshes/Compression/dracoEncoder.types.js.map +1 -0
  212. package/Meshes/Compression/index.d.ts +1 -0
  213. package/Meshes/Compression/index.js +1 -0
  214. package/Meshes/Compression/index.js.map +1 -1
  215. package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +92 -2
  216. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +308 -32
  217. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  218. package/Meshes/GreasedLine/greasedLineBaseMesh.js +4 -1
  219. package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
  220. package/Meshes/GreasedLine/greasedLineRibbonMesh.js +1 -1
  221. package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
  222. package/Meshes/Node/Blocks/Textures/geometryTextureBlock.d.ts +1 -1
  223. package/Meshes/abstractMesh.d.ts +1 -2
  224. package/Meshes/abstractMesh.js +1 -2
  225. package/Meshes/abstractMesh.js.map +1 -1
  226. package/Meshes/linesMesh.js +2 -2
  227. package/Meshes/linesMesh.js.map +1 -1
  228. package/Meshes/mesh.d.ts +32 -5
  229. package/Meshes/mesh.js +56 -29
  230. package/Meshes/mesh.js.map +1 -1
  231. package/Meshes/subMesh.js +16 -3
  232. package/Meshes/subMesh.js.map +1 -1
  233. package/Meshes/transformNode.js +2 -0
  234. package/Meshes/transformNode.js.map +1 -1
  235. package/Misc/decorators.serialization.js +2 -0
  236. package/Misc/decorators.serialization.js.map +1 -1
  237. package/Misc/fileTools.js +14 -7
  238. package/Misc/fileTools.js.map +1 -1
  239. package/Misc/greasedLineTools.d.ts +1 -1
  240. package/Misc/logger.d.ts +2 -1
  241. package/Misc/logger.js +2 -1
  242. package/Misc/logger.js.map +1 -1
  243. package/Morph/morphTargetManager.d.ts +21 -0
  244. package/Morph/morphTargetManager.js +37 -2
  245. package/Morph/morphTargetManager.js.map +1 -1
  246. package/Particles/pointsCloudSystem.d.ts +3 -3
  247. package/Physics/v2/Plugins/havokPlugin.d.ts +2 -2
  248. package/PostProcesses/index.d.ts +1 -0
  249. package/PostProcesses/index.js +1 -0
  250. package/PostProcesses/index.js.map +1 -1
  251. package/PostProcesses/passPostProcess.d.ts +2 -3
  252. package/PostProcesses/passPostProcess.js +36 -48
  253. package/PostProcesses/passPostProcess.js.map +1 -1
  254. package/PostProcesses/thinPassPostProcess.d.ts +48 -0
  255. package/PostProcesses/thinPassPostProcess.js +113 -0
  256. package/PostProcesses/thinPassPostProcess.js.map +1 -0
  257. package/PostProcesses/volumetricLightScatteringPostProcess.js +15 -16
  258. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  259. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js +1 -1
  260. package/Rendering/IBLShadows/iblShadowsVoxelTracingPass.js.map +1 -1
  261. package/Rendering/depthRenderer.js +13 -15
  262. package/Rendering/depthRenderer.js.map +1 -1
  263. package/Rendering/geometryBufferRenderer.js +13 -15
  264. package/Rendering/geometryBufferRenderer.js.map +1 -1
  265. package/Rendering/iblCdfGenerator.d.ts +13 -5
  266. package/Rendering/iblCdfGenerator.js +67 -10
  267. package/Rendering/iblCdfGenerator.js.map +1 -1
  268. package/Rendering/objectRenderer.d.ts +9 -2
  269. package/Rendering/objectRenderer.js +44 -7
  270. package/Rendering/objectRenderer.js.map +1 -1
  271. package/Rendering/outlineRenderer.js +13 -15
  272. package/Rendering/outlineRenderer.js.map +1 -1
  273. package/Shaders/ShadersInclude/gaussianSplatting.js +6 -6
  274. package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -1
  275. package/Shaders/ShadersInclude/morphTargetsVertex.js +16 -4
  276. package/Shaders/ShadersInclude/morphTargetsVertex.js.map +1 -1
  277. package/Shaders/ShadersInclude/pbrBlockReflection.js +13 -8
  278. package/Shaders/ShadersInclude/pbrBlockReflection.js.map +1 -1
  279. package/Shaders/gaussianSplatting.vertex.js +2 -1
  280. package/Shaders/gaussianSplatting.vertex.js.map +1 -1
  281. package/Shaders/hdrIrradianceFiltering.fragment.d.ts +9 -0
  282. package/Shaders/hdrIrradianceFiltering.fragment.js +25 -0
  283. package/Shaders/hdrIrradianceFiltering.fragment.js.map +1 -0
  284. package/Shaders/hdrIrradianceFiltering.vertex.d.ts +5 -0
  285. package/Shaders/hdrIrradianceFiltering.vertex.js +15 -0
  286. package/Shaders/hdrIrradianceFiltering.vertex.js.map +1 -0
  287. package/Shaders/pbr.fragment.js +1 -3
  288. package/Shaders/pbr.fragment.js.map +1 -1
  289. package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js +17 -5
  290. package/ShadersWGSL/ShadersInclude/morphTargetsVertex.js.map +1 -1
  291. package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js +13 -8
  292. package/ShadersWGSL/ShadersInclude/pbrBlockReflection.js.map +1 -1
  293. package/ShadersWGSL/greasedLine.fragment.js +9 -3
  294. package/ShadersWGSL/greasedLine.fragment.js.map +1 -1
  295. package/ShadersWGSL/greasedLine.vertex.js +12 -2
  296. package/ShadersWGSL/greasedLine.vertex.js.map +1 -1
  297. package/ShadersWGSL/hdrIrradianceFiltering.fragment.d.ts +9 -0
  298. package/ShadersWGSL/hdrIrradianceFiltering.fragment.js +26 -0
  299. package/ShadersWGSL/hdrIrradianceFiltering.fragment.js.map +1 -0
  300. package/ShadersWGSL/hdrIrradianceFiltering.vertex.d.ts +5 -0
  301. package/ShadersWGSL/hdrIrradianceFiltering.vertex.js +16 -0
  302. package/ShadersWGSL/hdrIrradianceFiltering.vertex.js.map +1 -0
  303. package/ShadersWGSL/outline.fragment.js +1 -1
  304. package/ShadersWGSL/outline.fragment.js.map +1 -1
  305. package/ShadersWGSL/passCube.fragment.js +1 -1
  306. package/ShadersWGSL/passCube.fragment.js.map +1 -1
  307. package/ShadersWGSL/pbr.fragment.js +1 -3
  308. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  309. package/XR/features/WebXRDepthSensing.d.ts +24 -2
  310. package/XR/features/WebXRDepthSensing.js +320 -26
  311. package/XR/features/WebXRDepthSensing.js.map +1 -1
  312. package/assetContainer.d.ts +43 -0
  313. package/assetContainer.js +67 -0
  314. package/assetContainer.js.map +1 -1
  315. package/package.json +1 -1
  316. package/scene.js +19 -8
  317. package/scene.js.map +1 -1
@@ -104,7 +104,7 @@ export interface GreasedLineMeshBuilderOptions extends GreasedLineMeshOptions {
104
104
  * @param scene scene or null to use the last scene
105
105
  * @returns StandardMaterial or PBRMaterial with the @see GreasedLinePluginMaterial attached to it
106
106
  */
107
- export declare function CreateGreasedLineMaterial(name: string, options: GreasedLineMaterialOptions, scene: Nullable<Scene>): PBRMaterial | GreasedLineSimpleMaterial | StandardMaterial;
107
+ export declare function CreateGreasedLineMaterial(name: string, options: GreasedLineMaterialOptions, scene: Nullable<Scene>): StandardMaterial | PBRMaterial | GreasedLineSimpleMaterial;
108
108
  /**
109
109
  * Creates a GreasedLine mesh
110
110
  * @param name name of the mesh
@@ -17,8 +17,8 @@ export function CreatePlaneVertexData(options) {
17
17
  const positions = [];
18
18
  const normals = [];
19
19
  const uvs = [];
20
- const width = options.width || options.size || 1;
21
- const height = options.height || options.size || 1;
20
+ const width = options.width !== undefined ? options.width : options.size !== undefined ? options.size : 1;
21
+ const height = options.height !== undefined ? options.height : options.size !== undefined ? options.size : 1;
22
22
  const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
23
23
  // Vertices
24
24
  const halfWidth = width / 2.0;
@@ -1 +1 @@
1
- {"version":3,"file":"planeBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/planeBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA4H;IAC9J,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,MAAM,OAAO,GAAG,EAAE,CAAC;IACnB,MAAM,GAAG,GAAG,EAAE,CAAC;IAEf,MAAM,KAAK,GAAW,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;IACzD,MAAM,MAAM,GAAW,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;IAC3D,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,IAAI,UAAU,CAAC,WAAW,CAAC;IAE9G,WAAW;IACX,MAAM,SAAS,GAAG,KAAK,GAAG,GAAG,CAAC;IAC9B,MAAM,UAAU,GAAG,MAAM,GAAG,GAAG,CAAC;IAEhC,SAAS,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACzB,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAErD,SAAS,CAAC,IAAI,CAA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AAmB,EAAE,eAAwB,EAAQ,EAAE;IACjH,MAAM,OAAO,GAAG;QACZ,IAAI;QACJ,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,IAAI;QACZ,eAAe;QACf,SAAS;KACZ,CAAC;IAEF,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["import type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a Plane\r\n * @param options an object used to set the following optional parameters for the plane, required but can be empty\r\n * * size sets the width and height of the plane to the value of size, optional default 1\r\n * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @returns the VertexData of the box\r\n */\r\nexport function CreatePlaneVertexData(options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 }): VertexData {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n const width: number = options.width || options.size || 1;\r\n const height: number = options.height || options.size || 1;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // Vertices\r\n const halfWidth = width / 2.0;\r\n const halfHeight = height / 2.0;\r\n\r\n positions.push(-halfWidth, -halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(0.0, useOpenGLOrientationForUV ? 1.0 : 0.0);\r\n\r\n positions.push(halfWidth, -halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(1.0, useOpenGLOrientationForUV ? 1.0 : 0.0);\r\n\r\n positions.push(halfWidth, halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(1.0, useOpenGLOrientationForUV ? 0.0 : 1.0);\r\n\r\n positions.push(-halfWidth, halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(0.0, useOpenGLOrientationForUV ? 0.0 : 1.0);\r\n\r\n // Indices\r\n indices.push(0);\r\n indices.push(1);\r\n indices.push(2);\r\n\r\n indices.push(0);\r\n indices.push(2);\r\n indices.push(3);\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a plane mesh\r\n * * The parameter `size` sets the size (float) of both sides of the plane at once (default 1)\r\n * * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value of `size`)\r\n * * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the plane mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#plane\r\n */\r\nexport function CreatePlane(\r\n name: string,\r\n options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4; updatable?: boolean; sourcePlane?: Plane } = {},\r\n scene: Nullable<Scene> = null\r\n): Mesh {\r\n const plane = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n plane._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreatePlaneVertexData(options);\r\n\r\n vertexData.applyToMesh(plane, options.updatable);\r\n\r\n if (options.sourcePlane) {\r\n plane.translate(options.sourcePlane.normal, -options.sourcePlane.d);\r\n plane.setDirection(options.sourcePlane.normal.scale(-1));\r\n }\r\n\r\n return plane;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const PlaneBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreatePlane,\r\n};\r\n\r\nVertexData.CreatePlane = CreatePlaneVertexData;\r\nMesh.CreatePlane = (name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n size,\r\n width: size,\r\n height: size,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreatePlane(name, options, scene);\r\n};\r\n"]}
1
+ {"version":3,"file":"planeBuilder.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Builders/planeBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CA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IAAI;QACZ,eAAe;QACf,SAAS;KACZ,CAAC;IAEF,OAAO,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC,CAAC","sourcesContent":["import type { Scene } from \"../../scene\";\r\nimport type { Vector4 } from \"../../Maths/math.vector\";\r\nimport { Mesh } from \"../mesh\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions\";\r\n\r\n/**\r\n * Creates the VertexData for a Plane\r\n * @param options an object used to set the following optional parameters for the plane, required but can be empty\r\n * * size sets the width and height of the plane to the value of size, optional default 1\r\n * * width sets the width (x direction) of the plane, overwrites the width set by size, optional, default size\r\n * * height sets the height (y direction) of the plane, overwrites the height set by size, optional, default size\r\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\r\n * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)\r\n * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)\r\n * @returns the VertexData of the box\r\n */\r\nexport function CreatePlaneVertexData(options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4 }): VertexData {\r\n const indices = [];\r\n const positions = [];\r\n const normals = [];\r\n const uvs = [];\r\n\r\n const width: number = options.width !== undefined ? options.width : options.size !== undefined ? options.size : 1;\r\n const height: number = options.height !== undefined ? options.height : options.size !== undefined ? options.size : 1;\r\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\r\n\r\n // Vertices\r\n const halfWidth = width / 2.0;\r\n const halfHeight = height / 2.0;\r\n\r\n positions.push(-halfWidth, -halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(0.0, useOpenGLOrientationForUV ? 1.0 : 0.0);\r\n\r\n positions.push(halfWidth, -halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(1.0, useOpenGLOrientationForUV ? 1.0 : 0.0);\r\n\r\n positions.push(halfWidth, halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(1.0, useOpenGLOrientationForUV ? 0.0 : 1.0);\r\n\r\n positions.push(-halfWidth, halfHeight, 0);\r\n normals.push(0, 0, -1.0);\r\n uvs.push(0.0, useOpenGLOrientationForUV ? 0.0 : 1.0);\r\n\r\n // Indices\r\n indices.push(0);\r\n indices.push(1);\r\n indices.push(2);\r\n\r\n indices.push(0);\r\n indices.push(2);\r\n indices.push(3);\r\n\r\n // Sides\r\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\r\n\r\n // Result\r\n const vertexData = new VertexData();\r\n\r\n vertexData.indices = indices;\r\n vertexData.positions = positions;\r\n vertexData.normals = normals;\r\n vertexData.uvs = uvs;\r\n\r\n return vertexData;\r\n}\r\n\r\n/**\r\n * Creates a plane mesh\r\n * * The parameter `size` sets the size (float) of both sides of the plane at once (default 1)\r\n * * You can set some different plane dimensions by using the parameters `width` and `height` (both by default have the same value of `size`)\r\n * * The parameter `sourcePlane` is a Plane instance. It builds a mesh plane from a Math plane\r\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\r\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\r\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created\r\n * @param name defines the name of the mesh\r\n * @param options defines the options used to create the mesh\r\n * @param scene defines the hosting scene\r\n * @returns the plane mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#plane\r\n */\r\nexport function CreatePlane(\r\n name: string,\r\n options: { size?: number; width?: number; height?: number; sideOrientation?: number; frontUVs?: Vector4; backUVs?: Vector4; updatable?: boolean; sourcePlane?: Plane } = {},\r\n scene: Nullable<Scene> = null\r\n): Mesh {\r\n const plane = new Mesh(name, scene);\r\n\r\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\r\n plane._originalBuilderSideOrientation = options.sideOrientation;\r\n\r\n const vertexData = CreatePlaneVertexData(options);\r\n\r\n vertexData.applyToMesh(plane, options.updatable);\r\n\r\n if (options.sourcePlane) {\r\n plane.translate(options.sourcePlane.normal, -options.sourcePlane.d);\r\n plane.setDirection(options.sourcePlane.normal.scale(-1));\r\n }\r\n\r\n return plane;\r\n}\r\n\r\n/**\r\n * Class containing static functions to help procedurally build meshes\r\n * @deprecated use the function directly from the module\r\n */\r\nexport const PlaneBuilder = {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n CreatePlane,\r\n};\r\n\r\nVertexData.CreatePlane = CreatePlaneVertexData;\r\nMesh.CreatePlane = (name: string, size: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh => {\r\n const options = {\r\n size,\r\n width: size,\r\n height: size,\r\n sideOrientation,\r\n updatable,\r\n };\r\n\r\n return CreatePlane(name, options, scene);\r\n};\r\n"]}
@@ -33,7 +33,7 @@ export interface IDracoCodecConfiguration {
33
33
  /**
34
34
  * The codec module if already available.
35
35
  */
36
- jsModule?: any;
36
+ jsModule?: unknown;
37
37
  }
38
38
  /**
39
39
  * @internal
@@ -50,7 +50,7 @@ export declare function _IsConfigurationAvailable(config: IDracoCodecConfigurati
50
50
  export declare abstract class DracoCodec implements IDisposable {
51
51
  protected _workerPoolPromise?: Promise<WorkerPool>;
52
52
  protected _modulePromise?: Promise<{
53
- module: any; /** DecoderModule | EncoderModule */
53
+ module: unknown; /** DecoderModule | EncoderModule */
54
54
  }>;
55
55
  /**
56
56
  * Checks if the default codec JS module is in scope.
@@ -59,8 +59,8 @@ export declare abstract class DracoCodec implements IDisposable {
59
59
  /**
60
60
  * Creates the JS Module for the corresponding wasm.
61
61
  */
62
- protected abstract _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: any): Promise<{
63
- module: any; /** DecoderModule | EncoderModule */
62
+ protected abstract _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: unknown /** DracoDecoderModule | DracoEncoderModule */): Promise<{
63
+ module: unknown; /** DecoderModule | EncoderModule */
64
64
  }>;
65
65
  /**
66
66
  * Returns the worker content.
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCodec.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AA4C/D;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACjC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC;QAClE,OAAO,CAAC,CAAC;IACb,CAAC;IAED,+DAA+D;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,mBAAmB,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAgC;IACtE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,OAAO,WAAW,KAAK,QAAQ,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;IACpI,6BAA6B;AACjC,CAAC;AAED;;;GAGG;AACH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AAC;YAC1B,MAAM,IAAI,CAAC,kBAAkB,CAAC;YAC9B,OAAO;QACX,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,cAAc,CAAC;YAC1B,OAAO;QACX,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;gBACxC,UAAU,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC;QAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { WorkerPool } from \"../../Misc/workerPool\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport { initializeWebWorker } from \"./dracoCompressionWorker\";\r\n\r\n/**\r\n * Configuration for using a Draco codec.\r\n */\r\nexport interface IDracoCodecConfiguration {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n\r\n /**\r\n * Optional worker pool to use for async encoding/decoding.\r\n * If provided, the worker pool will be used as is: no Draco scripts will be loaded, and numWorkers will be ignored.\r\n */\r\n workerPool?: WorkerPool;\r\n\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The codec module if already available.\r\n */\r\n jsModule?: any /* DracoDecoderModule | DracoEncoderModule */;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _IsConfigurationAvailable(config: IDracoCodecConfiguration): boolean {\r\n return !!((config.wasmUrl && (config.wasmBinary || config.wasmBinaryUrl) && typeof WebAssembly === \"object\") || config.fallbackUrl);\r\n // TODO: Account for jsModule\r\n}\r\n\r\n/**\r\n * Base class for a Draco codec.\r\n * @internal\r\n */\r\nexport abstract class DracoCodec implements IDisposable {\r\n protected _workerPoolPromise?: Promise<WorkerPool>;\r\n protected _modulePromise?: Promise<{ module: any /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Checks if the default codec JS module is in scope.\r\n */\r\n protected abstract _isModuleAvailable(): boolean;\r\n\r\n /**\r\n * Creates the JS Module for the corresponding wasm.\r\n */\r\n protected abstract _createModuleAsync(wasmBinary?: ArrayBuffer, jsModule?: any): Promise<{ module: any /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Returns the worker content.\r\n */\r\n protected abstract _getWorkerContent(): string;\r\n\r\n /**\r\n * Constructor\r\n * @param configuration The configuration for the DracoCodec instance.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration) {\r\n // check if the codec binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (configuration.workerPool) {\r\n // Set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(configuration.workerPool);\r\n return;\r\n }\r\n\r\n // to avoid making big changes to the code here, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = configuration.wasmBinary;\r\n const numberOfWorkers = configuration.numWorkers ?? _GetDefaultNumWorkers();\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || !configuration.jsModule;\r\n // code maintained here for back-compat with no changes\r\n\r\n const codecInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n configuration.wasmUrl && configuration.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided\r\n ? Promise.resolve(wasmBinaryProvided)\r\n : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(configuration.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n // If using workers, initialize a worker pool with either the wasm or url?\r\n if (useWorkers) {\r\n this._workerPoolPromise = codecInfo.wasmBinaryPromise.then((wasmBinary) => {\r\n const workerContent = this._getWorkerContent();\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, wasmBinary, codecInfo.url);\r\n });\r\n });\r\n } else {\r\n this._modulePromise = codecInfo.wasmBinaryPromise.then(async (wasmBinary) => {\r\n if (!this._isModuleAvailable()) {\r\n if (!configuration.jsModule) {\r\n if (!codecInfo.url) {\r\n throw new Error(\"Draco codec module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(codecInfo.url);\r\n }\r\n }\r\n return this._createModuleAsync(wasmBinary as ArrayBuffer, configuration.jsModule);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure the draco codec is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._modulePromise) {\r\n await this._modulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._modulePromise;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCodec.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AA4C/D;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACjC,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC;QAClE,OAAO,CAAC,CAAC;IACb,CAAC;IAED,+DAA+D;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,mBAAmB,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAgC;IACtE,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,OAAO,WAAW,KAAK,QAAQ,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,CAAC;IACpI,6BAA6B;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAgB,UAAU;IAsB5B;;;OAGG;IACH,YAAY,aAAuC;QAC/C,yDAAyD;QACzD,8G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IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,MAAM,IAAI,CAAC,cAAc,CAAC;YAC1B,OAAO;QACX,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;gBACxC,UAAU,CAAC,OAAO,EAAE,CAAC;YACzB,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,IAAI,CAAC,kBAAkB,CAAC;QAC/B,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { WorkerPool } from \"../../Misc/workerPool\";\r\nimport type { IDisposable } from \"../../scene\";\r\nimport { initializeWebWorker } from \"./dracoCompressionWorker\";\r\n\r\n/**\r\n * Configuration for using a Draco codec.\r\n */\r\nexport interface IDracoCodecConfiguration {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n\r\n /**\r\n * Optional worker pool to use for async encoding/decoding.\r\n * If provided, the worker pool will be used as is: no Draco scripts will be loaded, and numWorkers will be ignored.\r\n */\r\n workerPool?: WorkerPool;\r\n\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The codec module if already available.\r\n */\r\n jsModule?: unknown /* DracoDecoderModule | DracoEncoderModule */;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function _IsConfigurationAvailable(config: IDracoCodecConfiguration): boolean {\r\n return !!((config.wasmUrl && (config.wasmBinary || config.wasmBinaryUrl) && typeof WebAssembly === \"object\") || config.fallbackUrl);\r\n // TODO: Account for jsModule\r\n}\r\n\r\n/**\r\n * Base class for a Draco codec.\r\n * @internal\r\n */\r\nexport abstract class DracoCodec implements IDisposable {\r\n protected _workerPoolPromise?: Promise<WorkerPool>;\r\n protected _modulePromise?: Promise<{ module: unknown /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Checks if the default codec JS module is in scope.\r\n */\r\n protected abstract _isModuleAvailable(): boolean;\r\n\r\n /**\r\n * Creates the JS Module for the corresponding wasm.\r\n */\r\n protected abstract _createModuleAsync(\r\n wasmBinary?: ArrayBuffer,\r\n jsModule?: unknown /** DracoDecoderModule | DracoEncoderModule */\r\n ): Promise<{ module: unknown /** DecoderModule | EncoderModule */ }>;\r\n\r\n /**\r\n * Returns the worker content.\r\n */\r\n protected abstract _getWorkerContent(): string;\r\n\r\n /**\r\n * Constructor\r\n * @param configuration The configuration for the DracoCodec instance.\r\n */\r\n constructor(configuration: IDracoCodecConfiguration) {\r\n // check if the codec binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (configuration.workerPool) {\r\n // Set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(configuration.workerPool);\r\n return;\r\n }\r\n\r\n // to avoid making big changes to the code here, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = configuration.wasmBinary;\r\n const numberOfWorkers = configuration.numWorkers ?? _GetDefaultNumWorkers();\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || !configuration.jsModule;\r\n // code maintained here for back-compat with no changes\r\n\r\n const codecInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n configuration.wasmUrl && configuration.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided\r\n ? Promise.resolve(wasmBinaryProvided)\r\n : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(configuration.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(configuration.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n // If using workers, initialize a worker pool with either the wasm or url?\r\n if (useWorkers) {\r\n this._workerPoolPromise = codecInfo.wasmBinaryPromise.then((wasmBinary) => {\r\n const workerContent = this._getWorkerContent();\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, wasmBinary, codecInfo.url);\r\n });\r\n });\r\n } else {\r\n this._modulePromise = codecInfo.wasmBinaryPromise.then(async (wasmBinary) => {\r\n if (!this._isModuleAvailable()) {\r\n if (!configuration.jsModule) {\r\n if (!codecInfo.url) {\r\n throw new Error(\"Draco codec module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(codecInfo.url);\r\n }\r\n }\r\n return this._createModuleAsync(wasmBinary as ArrayBuffer, configuration.jsModule);\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure the draco codec is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._modulePromise) {\r\n await this._modulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._modulePromise;\r\n }\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { IDracoCodecConfiguration } from "./dracoCodec";
2
- import type { MeshData } from "./dracoDecoder";
2
+ import type { MeshData } from "./dracoDecoder.types";
3
3
  import { VertexData } from "../mesh.vertexData";
4
4
  import type { Nullable } from "../../types.js";
5
5
  import type { Geometry } from "../geometry";
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAqBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,gBAAgB;IAWzB;;OAEG;IACI,MAAM,KAAK,gBAAgB;QAC9B,OAAO,yBAAyB,CAAC,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC7E,CAAC;IAQD;;OAEG;IACI,MAAM,KAAK,OAAO;QACrB,gBAAgB,CAAC,QAAQ,KAAzB,gBAAgB,CAAC,QAAQ,GAAK,IAAI,gBAAgB,EAAE,EAAC;QACrD,OAAO,gBAAgB,CAAC,QAAQ,CAAC;IACrC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAA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\"./dracoCodec\";\r\nimport type { IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { DracoDecoder } from \"./dracoDecoder\";\r\nimport type { MeshData } from \"./dracoDecoder\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Geometry } from \"../geometry\";\r\nimport type { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: IDracoCodecConfiguration;\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions extends Pick<IDracoCodecConfiguration, \"numWorkers\" | \"wasmBinary\" | \"workerPool\"> {}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression {\r\n private _decoder: DracoDecoder;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = { decoder: { ...DracoDecoder.DefaultConfiguration } }; // Use copy\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoCompression.Configuration.decoder);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = _GetDefaultNumWorkers();\r\n\r\n protected static _Default: Nullable<DracoCompression> = null;\r\n /**\r\n * Default instance for the DracoCompression.\r\n */\r\n public static get Default(): DracoCompression {\r\n DracoCompression._Default ??= new DracoCompression();\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Reset the default draco compression object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static Configuration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoCompression._Default) {\r\n if (!skipDispose) {\r\n DracoCompression._Default.dispose();\r\n }\r\n DracoCompression._Default = null;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new DracoCompression object.\r\n * @param numWorkersOrOptions Overrides for the Configuration. Either:\r\n * - The number of workers for async operations or a config object. Specify `0` to disable web workers and run synchronously in the current context.\r\n * - An options object\r\n */\r\n constructor(numWorkersOrOptions: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const configuration =\r\n typeof numWorkersOrOptions === \"number\"\r\n ? { ...DracoCompression.Configuration.decoder, numWorkers: numWorkersOrOptions }\r\n : { ...DracoCompression.Configuration.decoder, ...numWorkersOrOptions };\r\n this._decoder = new DracoDecoder(configuration);\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n this._decoder.dispose();\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n return this._decoder.whenReadyAsync();\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n return this._decoder.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n return this._decoder.decodeMeshToGeometryAsync(name, scene, data, attributes);\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 return this._decoder._decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride, boundingInfo);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this._decoder.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAqBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,gB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,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AA3ID;;;;;GAKG;AACW,8BAAa,GAAmC,EAAE,OAAO,EAAE,EAAE,GAAG,YAAY,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC,WAAW;AAShI;;GAEG;AACW,kCAAiB,GAAG,qBAAqB,EAAE,CAAC;AAEzC,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["import { _GetDefaultNumWorkers, _IsConfigurationAvailable } from \"./dracoCodec\";\r\nimport type { IDracoCodecConfiguration } from \"./dracoCodec\";\r\nimport { DracoDecoder } from \"./dracoDecoder\";\r\nimport type { MeshData } from \"./dracoDecoder.types\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Geometry } from \"../geometry\";\r\nimport type { BoundingInfo } from \"../../Culling/boundingInfo\";\r\nimport type { Scene } from \"../../scene\";\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: IDracoCodecConfiguration;\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions extends Pick<IDracoCodecConfiguration, \"numWorkers\" | \"wasmBinary\" | \"workerPool\"> {}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression {\r\n private _decoder: DracoDecoder;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = { decoder: { ...DracoDecoder.DefaultConfiguration } }; // Use copy\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n return _IsConfigurationAvailable(DracoCompression.Configuration.decoder);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = _GetDefaultNumWorkers();\r\n\r\n protected static _Default: Nullable<DracoCompression> = null;\r\n /**\r\n * Default instance for the DracoCompression.\r\n */\r\n public static get Default(): DracoCompression {\r\n DracoCompression._Default ??= new DracoCompression();\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Reset the default draco compression object to null and disposing the removed default instance.\r\n * Note that if the workerPool is a member of the static Configuration object it is recommended not to run dispose,\r\n * unless the static worker pool is no longer needed.\r\n * @param skipDispose set to true to not dispose the removed default instance\r\n */\r\n public static ResetDefault(skipDispose?: boolean): void {\r\n if (DracoCompression._Default) {\r\n if (!skipDispose) {\r\n DracoCompression._Default.dispose();\r\n }\r\n DracoCompression._Default = null;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new DracoCompression object.\r\n * @param numWorkersOrOptions Overrides for the Configuration. Either:\r\n * - The number of workers for async operations or a config object. Specify `0` to disable web workers and run synchronously in the current context.\r\n * - An options object\r\n */\r\n constructor(numWorkersOrOptions: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const configuration =\r\n typeof numWorkersOrOptions === \"number\"\r\n ? { ...DracoCompression.Configuration.decoder, numWorkers: numWorkersOrOptions }\r\n : { ...DracoCompression.Configuration.decoder, ...numWorkersOrOptions };\r\n this._decoder = new DracoDecoder(configuration);\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n this._decoder.dispose();\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n return this._decoder.whenReadyAsync();\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n return this._decoder.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n return this._decoder.decodeMeshToGeometryAsync(name, scene, data, attributes);\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 return this._decoder._decodeMeshToGeometryForGltfAsync(name, scene, data, attributes, gltfNormalizedOverride, boundingInfo);\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this._decoder.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
@@ -1,43 +1,29 @@
1
- export interface AttributeData {
2
- kind: string;
3
- data: ArrayBufferView;
4
- size: number;
5
- byteOffset: number;
6
- byteStride: number;
7
- normalized: boolean;
8
- }
9
- interface InitDoneMessage {
10
- id: "initDone";
11
- }
12
- interface DecodeMeshDoneMessage {
13
- id: "decodeMeshDone";
14
- totalVertices: number;
15
- }
16
- interface IndicesMessage {
17
- id: "indices";
18
- data: Uint16Array | Uint32Array;
19
- }
20
- interface AttributeMessage extends AttributeData {
21
- id: "attribute";
22
- }
23
- export type Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;
1
+ import type { Nullable } from "../../types.js";
2
+ import type { IDracoAttributeData, IDracoEncodedMeshData, IDracoEncoderOptions } from "./dracoEncoder.types";
24
3
  /**
25
4
  * @internal
26
5
  */
27
- export declare function decodeMesh(decoderModule: any, data: Int8Array, attributes: {
28
- [kind: string]: number;
29
- } | undefined, onIndicesData: (indices: Uint16Array | Uint32Array) => void, onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void): number;
6
+ export declare function EncodeMesh(module: unknown /** EncoderModule */, attributes: Array<IDracoAttributeData>, indices: Nullable<Uint16Array | Uint32Array>, options: IDracoEncoderOptions): Nullable<IDracoEncodedMeshData>;
30
7
  /**
31
8
  * The worker function that gets converted to a blob url to pass into a worker.
32
9
  * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
33
10
  */
34
- export declare function workerFunction(): void;
11
+ export declare function EncoderWorkerFunction(): void;
12
+ /**
13
+ * @internal
14
+ */
15
+ export declare function DecodeMesh(module: unknown /** DecoderModule */, data: Int8Array, attributeIDs: Record<string, number> | undefined, onIndicesData: (indices: Uint16Array | Uint32Array) => void, onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void): number;
16
+ /**
17
+ * The worker function that gets converted to a blob url to pass into a worker.
18
+ * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
19
+ */
20
+ export declare function DecoderWorkerFunction(): void;
21
+ export { DecoderWorkerFunction as workerFunction };
35
22
  /**
36
23
  * Initializes a worker that was created for the draco agent pool
37
24
  * @param worker The worker to initialize
38
- * @param decoderWasmBinary The wasm binary to load into the worker
25
+ * @param wasmBinary The wasm binary to load into the worker
39
26
  * @param moduleUrl The url to the draco decoder module (optional)
40
27
  * @returns A promise that resolves when the worker is initialized
41
28
  */
42
- export declare function initializeWebWorker(worker: Worker, decoderWasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker>;
43
- export {};
29
+ export declare function initializeWebWorker(worker: Worker, wasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker>;
@@ -1,7 +1,114 @@
1
1
  /**
2
2
  * @internal
3
3
  */
4
- export function decodeMesh(decoderModule /*DecoderModule*/, data, attributes, onIndicesData, onAttributeData) {
4
+ export function EncodeMesh(module /** EncoderModule */, attributes, indices, options) {
5
+ const encoderModule = module;
6
+ let encoder = null;
7
+ let meshBuilder = null;
8
+ let mesh = null;
9
+ let encodedNativeBuffer = null;
10
+ const attributeIDs = {}; // Babylon kind -> Draco unique id
11
+ // Double-check that at least a position attribute is provided
12
+ const positionAttribute = attributes.find((a) => a.babylonAttribute === "position");
13
+ if (!positionAttribute) {
14
+ throw new Error("Position attribute is required for Draco encoding");
15
+ }
16
+ // If no indices are provided, assume mesh is unindexed. Let's generate them, since Draco meshes require them.
17
+ // TODO: This may be the POINT_CLOUD case, but need to investigate. Should work for now-- just less efficient.
18
+ if (!indices) {
19
+ // Assume position attribute is the largest attribute.
20
+ const positionVerticesCount = positionAttribute.data.length / positionAttribute.size;
21
+ indices = new (positionVerticesCount > 65535 ? Uint32Array : Uint16Array)(positionVerticesCount);
22
+ for (let i = 0; i < positionVerticesCount; i++) {
23
+ indices[i] = i;
24
+ }
25
+ }
26
+ try {
27
+ encoder = new encoderModule.Encoder();
28
+ meshBuilder = new encoderModule.MeshBuilder();
29
+ mesh = new encoderModule.Mesh();
30
+ // Add the faces
31
+ meshBuilder.AddFacesToMesh(mesh, indices.length / 3, indices);
32
+ // Add the attributes
33
+ for (const attribute of attributes) {
34
+ const verticesCount = attribute.data.length / attribute.size;
35
+ attributeIDs[attribute.babylonAttribute] = meshBuilder.AddFloatAttribute(mesh, encoderModule[attribute.dracoAttribute], verticesCount, attribute.size, attribute.data);
36
+ if (options.quantizationBits && options.quantizationBits[attribute.dracoAttribute]) {
37
+ encoder.SetAttributeQuantization(encoderModule[attribute.dracoAttribute], options.quantizationBits[attribute.dracoAttribute]);
38
+ }
39
+ }
40
+ // Set the options
41
+ if (options.method) {
42
+ encoder.SetEncodingMethod(encoderModule[options.method]);
43
+ }
44
+ if (options.encodeSpeed !== undefined && options.decodeSpeed !== undefined) {
45
+ encoder.SetSpeedOptions(options.encodeSpeed, options.decodeSpeed);
46
+ }
47
+ // Encode to native buffer
48
+ encodedNativeBuffer = new encoderModule.DracoInt8Array();
49
+ const encodedLength = encoder.EncodeMeshToDracoBuffer(mesh, encodedNativeBuffer);
50
+ if (encodedLength <= 0) {
51
+ throw new Error("Draco encoding failed.");
52
+ }
53
+ // Copy the native buffer data to worker heap
54
+ const encodedData = new Int8Array(encodedLength);
55
+ for (let i = 0; i < encodedLength; i++) {
56
+ encodedData[i] = encodedNativeBuffer.GetValue(i);
57
+ }
58
+ return { data: encodedData, attributeIDs: attributeIDs };
59
+ }
60
+ finally {
61
+ if (mesh) {
62
+ encoderModule.destroy(mesh);
63
+ }
64
+ if (meshBuilder) {
65
+ encoderModule.destroy(meshBuilder);
66
+ }
67
+ if (encoder) {
68
+ encoderModule.destroy(encoder);
69
+ }
70
+ if (encodedNativeBuffer) {
71
+ encoderModule.destroy(encodedNativeBuffer);
72
+ }
73
+ }
74
+ }
75
+ /**
76
+ * The worker function that gets converted to a blob url to pass into a worker.
77
+ * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
78
+ */
79
+ export function EncoderWorkerFunction() {
80
+ let encoderPromise;
81
+ onmessage = (event) => {
82
+ const message = event.data;
83
+ switch (message.id) {
84
+ case "init": {
85
+ // if URL is provided then load the script. Otherwise expect the script to be loaded already
86
+ if (message.url) {
87
+ importScripts(message.url);
88
+ }
89
+ const initEncoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};
90
+ encoderPromise = DracoEncoderModule(initEncoderObject);
91
+ postMessage({ id: "initDone" });
92
+ break;
93
+ }
94
+ case "encodeMesh": {
95
+ if (!encoderPromise) {
96
+ throw new Error("Draco encoder module is not available");
97
+ }
98
+ encoderPromise.then((encoder) => {
99
+ const result = EncodeMesh(encoder, message.attributes, message.indices, message.options);
100
+ postMessage({ id: "encodeMeshDone", encodedMeshData: result }, result ? [result.data.buffer] : undefined);
101
+ });
102
+ break;
103
+ }
104
+ }
105
+ };
106
+ }
107
+ /**
108
+ * @internal
109
+ */
110
+ export function DecodeMesh(module /** DecoderModule */, data, attributeIDs, onIndicesData, onAttributeData) {
111
+ const decoderModule = module;
5
112
  let decoder = null;
6
113
  let buffer = null;
7
114
  let geometry = null;
@@ -48,7 +155,7 @@ export function decodeMesh(decoderModule /*DecoderModule*/, data, attributes, on
48
155
  }
49
156
  }
50
157
  const numPoints = geometry.num_points();
51
- const processAttribute = (decoder, geometry, kind, attribute) => {
158
+ const processAttribute = (decoder, geometry, kind, attribute /** Attribute */) => {
52
159
  const dataType = attribute.data_type();
53
160
  const numComponents = attribute.num_components();
54
161
  const normalized = attribute.normalized();
@@ -72,6 +179,7 @@ export function decodeMesh(decoderModule /*DecoderModule*/, data, attributes, on
72
179
  const ptr = decoderModule._malloc(byteLength);
73
180
  try {
74
181
  decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);
182
+ // this cast seems to be needed because of an issue with typescript, as all constructors do have the ptr and numValues arguments.
75
183
  const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);
76
184
  onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);
77
185
  }
@@ -79,9 +187,9 @@ export function decodeMesh(decoderModule /*DecoderModule*/, data, attributes, on
79
187
  decoderModule._free(ptr);
80
188
  }
81
189
  };
82
- if (attributes) {
83
- for (const kind in attributes) {
84
- const id = attributes[kind];
190
+ if (attributeIDs) {
191
+ for (const kind in attributeIDs) {
192
+ const id = attributeIDs[kind];
85
193
  const attribute = decoder.GetAttributeByUniqueId(geometry, id);
86
194
  processAttribute(decoder, geometry, kind, attribute);
87
195
  }
@@ -119,18 +227,17 @@ export function decodeMesh(decoderModule /*DecoderModule*/, data, attributes, on
119
227
  * The worker function that gets converted to a blob url to pass into a worker.
120
228
  * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.
121
229
  */
122
- export function workerFunction() {
230
+ export function DecoderWorkerFunction() {
123
231
  let decoderPromise;
124
232
  onmessage = (event) => {
125
233
  const message = event.data;
126
234
  switch (message.id) {
127
235
  case "init": {
128
- const decoder = message.decoder;
129
236
  // if URL is provided then load the script. Otherwise expect the script to be loaded already
130
- if (decoder.url) {
131
- importScripts(decoder.url);
237
+ if (message.url) {
238
+ importScripts(message.url);
132
239
  }
133
- const initDecoderObject = decoder.wasmBinary ? { wasmBinary: decoder.wasmBinary } : {};
240
+ const initDecoderObject = message.wasmBinary ? { wasmBinary: message.wasmBinary } : {};
134
241
  decoderPromise = DracoDecoderModule(initDecoderObject);
135
242
  postMessage({ id: "initDone" });
136
243
  break;
@@ -140,7 +247,7 @@ export function workerFunction() {
140
247
  throw new Error("Draco decoder module is not available");
141
248
  }
142
249
  decoderPromise.then((decoder) => {
143
- const numPoints = decodeMesh(decoder, message.dataView, message.attributes, (indices) => {
250
+ const numPoints = DecodeMesh(decoder, message.dataView, message.attributes, (indices) => {
144
251
  postMessage({ id: "indices", data: indices }, [indices.buffer]);
145
252
  }, (kind, data, size, offset, stride, normalized) => {
146
253
  postMessage({ id: "attribute", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);
@@ -152,14 +259,16 @@ export function workerFunction() {
152
259
  }
153
260
  };
154
261
  }
262
+ // For backwards compatibility
263
+ export { DecoderWorkerFunction as workerFunction };
155
264
  /**
156
265
  * Initializes a worker that was created for the draco agent pool
157
266
  * @param worker The worker to initialize
158
- * @param decoderWasmBinary The wasm binary to load into the worker
267
+ * @param wasmBinary The wasm binary to load into the worker
159
268
  * @param moduleUrl The url to the draco decoder module (optional)
160
269
  * @returns A promise that resolves when the worker is initialized
161
270
  */
162
- export function initializeWebWorker(worker, decoderWasmBinary, moduleUrl) {
271
+ export function initializeWebWorker(worker, wasmBinary, moduleUrl) {
163
272
  return new Promise((resolve, reject) => {
164
273
  const onError = (error) => {
165
274
  worker.removeEventListener("error", onError);
@@ -175,23 +284,20 @@ export function initializeWebWorker(worker, decoderWasmBinary, moduleUrl) {
175
284
  };
176
285
  worker.addEventListener("error", onError);
177
286
  worker.addEventListener("message", onMessage);
178
- if (!decoderWasmBinary) {
287
+ // Load with either JS-only or WASM version
288
+ if (!wasmBinary) {
179
289
  worker.postMessage({
180
290
  id: "init",
181
- decoder: {
182
- url: moduleUrl,
183
- },
291
+ url: moduleUrl,
184
292
  });
185
293
  }
186
294
  else {
187
295
  // clone the array buffer to make it transferable
188
- const clone = decoderWasmBinary.slice(0);
296
+ const clone = wasmBinary.slice(0);
189
297
  worker.postMessage({
190
298
  id: "init",
191
- decoder: {
192
- url: moduleUrl,
193
- wasmBinary: clone,
194
- },
299
+ url: moduleUrl,
300
+ wasmBinary: clone,
195
301
  }, [clone]);
196
302
  }
197
303
  // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,aAAkB,CAAC,iBAAiB,EACpC,IAAe,EACf,UAAkD,EAClD,aAA2D,EAC3D,eAAiI;IAEjI,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,MAAM,GAA4B,IAAI,CAAC;IAC3C,IAAI,QAAQ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E,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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C;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.babylonAttribute === \"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.babylonAttribute] = meshBuilder.AddFloatAttribute(mesh, encoderModule[attribute.dracoAttribute], verticesCount, attribute.size, attribute.data);\r\n if (options.quantizationBits && options.quantizationBits[attribute.dracoAttribute]) {\r\n encoder.SetAttributeQuantization(encoderModule[attribute.dracoAttribute], options.quantizationBits[attribute.dracoAttribute]);\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"]}