@babylonjs/viewer 7.36.0 → 7.37.0-alpha

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 (599) hide show
  1. package/assets/photoStudio.env +0 -0
  2. package/dist/babylon-viewer.esm.js +2 -0
  3. package/dist/babylon-viewer.esm.js.map +1 -0
  4. package/dist/babylon-viewer.esm.min.js +2 -0
  5. package/dist/babylon-viewer.esm.min.js.map +1 -0
  6. package/dist/chunks/EXT_lights_image_based-B3i_v86N.esm.js +171 -0
  7. package/dist/chunks/EXT_lights_image_based-B3i_v86N.esm.js.map +1 -0
  8. package/dist/chunks/EXT_lights_image_based-F9_9oKGw.esm.min.js +2 -0
  9. package/dist/chunks/EXT_lights_image_based-F9_9oKGw.esm.min.js.map +1 -0
  10. package/dist/chunks/EXT_mesh_gpu_instancing-BUGJNTuv.esm.js +86 -0
  11. package/dist/chunks/EXT_mesh_gpu_instancing-BUGJNTuv.esm.js.map +1 -0
  12. package/dist/chunks/EXT_mesh_gpu_instancing-ouu-sC4v.esm.min.js +2 -0
  13. package/dist/chunks/EXT_mesh_gpu_instancing-ouu-sC4v.esm.min.js.map +1 -0
  14. package/dist/chunks/EXT_meshopt_compression-BoFlIVIo.esm.js +134 -0
  15. package/dist/chunks/EXT_meshopt_compression-BoFlIVIo.esm.js.map +1 -0
  16. package/dist/chunks/EXT_meshopt_compression-CBHVR9-g.esm.min.js +2 -0
  17. package/dist/chunks/EXT_meshopt_compression-CBHVR9-g.esm.min.js.map +1 -0
  18. package/dist/chunks/EXT_texture_avif-BiDJEaYr.esm.js +44 -0
  19. package/dist/chunks/EXT_texture_avif-BiDJEaYr.esm.js.map +1 -0
  20. package/dist/chunks/EXT_texture_avif-CpcKIP2U.esm.min.js +2 -0
  21. package/dist/chunks/EXT_texture_avif-CpcKIP2U.esm.min.js.map +1 -0
  22. package/dist/chunks/EXT_texture_webp-9-weZ5t9.esm.js +43 -0
  23. package/dist/chunks/EXT_texture_webp-9-weZ5t9.esm.js.map +1 -0
  24. package/dist/chunks/EXT_texture_webp-BEzvwccL.esm.min.js +2 -0
  25. package/dist/chunks/EXT_texture_webp-BEzvwccL.esm.min.js.map +1 -0
  26. package/dist/chunks/ExtrasAsMetadata-2fKDjP-P.esm.min.js +2 -0
  27. package/dist/chunks/ExtrasAsMetadata-2fKDjP-P.esm.min.js.map +1 -0
  28. package/dist/chunks/ExtrasAsMetadata-DGBpP5kO.esm.js +64 -0
  29. package/dist/chunks/ExtrasAsMetadata-DGBpP5kO.esm.js.map +1 -0
  30. package/dist/chunks/KHR_animation_pointer-BGUym5aA.esm.min.js +2 -0
  31. package/dist/chunks/KHR_animation_pointer-BGUym5aA.esm.min.js.map +1 -0
  32. package/dist/chunks/KHR_animation_pointer-Bs26S___.esm.js +343 -0
  33. package/dist/chunks/KHR_animation_pointer-Bs26S___.esm.js.map +1 -0
  34. package/dist/chunks/KHR_draco_mesh_compression-BgmSGmi8.esm.min.js +2 -0
  35. package/dist/chunks/KHR_draco_mesh_compression-BgmSGmi8.esm.min.js.map +1 -0
  36. package/dist/chunks/KHR_draco_mesh_compression-sPxRDkD2.esm.js +617 -0
  37. package/dist/chunks/KHR_draco_mesh_compression-sPxRDkD2.esm.js.map +1 -0
  38. package/dist/chunks/KHR_interactivity-DDWPhJ-6.esm.js +4033 -0
  39. package/dist/chunks/KHR_interactivity-DDWPhJ-6.esm.js.map +1 -0
  40. package/dist/chunks/KHR_interactivity-DE92WJwh.esm.min.js +2 -0
  41. package/dist/chunks/KHR_interactivity-DE92WJwh.esm.min.js.map +1 -0
  42. package/dist/chunks/KHR_lights_punctual-C_akUY-5.esm.js +1253 -0
  43. package/dist/chunks/KHR_lights_punctual-C_akUY-5.esm.js.map +1 -0
  44. package/dist/chunks/KHR_lights_punctual-D-NJr9sx.esm.min.js +2 -0
  45. package/dist/chunks/KHR_lights_punctual-D-NJr9sx.esm.min.js.map +1 -0
  46. package/dist/chunks/KHR_materials_anisotropy-DuBZh7v4.esm.js +65 -0
  47. package/dist/chunks/KHR_materials_anisotropy-DuBZh7v4.esm.js.map +1 -0
  48. package/dist/chunks/KHR_materials_anisotropy-XJzw4SB7.esm.min.js +2 -0
  49. package/dist/chunks/KHR_materials_anisotropy-XJzw4SB7.esm.min.js.map +1 -0
  50. package/dist/chunks/KHR_materials_clearcoat-BjeqEjMn.esm.min.js +2 -0
  51. package/dist/chunks/KHR_materials_clearcoat-BjeqEjMn.esm.min.js.map +1 -0
  52. package/dist/chunks/KHR_materials_clearcoat-C_mF7kgI.esm.js +96 -0
  53. package/dist/chunks/KHR_materials_clearcoat-C_mF7kgI.esm.js.map +1 -0
  54. package/dist/chunks/KHR_materials_diffuse_transmission-B5xJ8gLo.esm.min.js +2 -0
  55. package/dist/chunks/KHR_materials_diffuse_transmission-B5xJ8gLo.esm.min.js.map +1 -0
  56. package/dist/chunks/KHR_materials_diffuse_transmission-BvtuXbx8.esm.js +97 -0
  57. package/dist/chunks/KHR_materials_diffuse_transmission-BvtuXbx8.esm.js.map +1 -0
  58. package/dist/chunks/KHR_materials_dispersion-DceW_6jg.esm.min.js +2 -0
  59. package/dist/chunks/KHR_materials_dispersion-DceW_6jg.esm.min.js.map +1 -0
  60. package/dist/chunks/KHR_materials_dispersion-DnMdHuwS.esm.js +62 -0
  61. package/dist/chunks/KHR_materials_dispersion-DnMdHuwS.esm.js.map +1 -0
  62. package/dist/chunks/KHR_materials_emissive_strength-BJxrDXxa.esm.js +55 -0
  63. package/dist/chunks/KHR_materials_emissive_strength-BJxrDXxa.esm.js.map +1 -0
  64. package/dist/chunks/KHR_materials_emissive_strength-T7Ioofbj.esm.min.js +2 -0
  65. package/dist/chunks/KHR_materials_emissive_strength-T7Ioofbj.esm.min.js.map +1 -0
  66. package/dist/chunks/KHR_materials_ior-BebDlrzl.esm.js +64 -0
  67. package/dist/chunks/KHR_materials_ior-BebDlrzl.esm.js.map +1 -0
  68. package/dist/chunks/KHR_materials_ior-BiXD3wbo.esm.min.js +2 -0
  69. package/dist/chunks/KHR_materials_ior-BiXD3wbo.esm.min.js.map +1 -0
  70. package/dist/chunks/KHR_materials_iridescence-BG0uvS2K.esm.min.js +2 -0
  71. package/dist/chunks/KHR_materials_iridescence-BG0uvS2K.esm.min.js.map +1 -0
  72. package/dist/chunks/KHR_materials_iridescence-DQz8GQbO.esm.js +72 -0
  73. package/dist/chunks/KHR_materials_iridescence-DQz8GQbO.esm.js.map +1 -0
  74. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-B3r0Mafb.esm.js +81 -0
  75. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-B3r0Mafb.esm.js.map +1 -0
  76. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-_lN5X8jS.esm.min.js +2 -0
  77. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-_lN5X8jS.esm.min.js.map +1 -0
  78. package/dist/chunks/KHR_materials_sheen-BtnO_FAS.esm.min.js +2 -0
  79. package/dist/chunks/KHR_materials_sheen-BtnO_FAS.esm.min.js.map +1 -0
  80. package/dist/chunks/KHR_materials_sheen-Ca0m-FCR.esm.js +85 -0
  81. package/dist/chunks/KHR_materials_sheen-Ca0m-FCR.esm.js.map +1 -0
  82. package/dist/chunks/KHR_materials_specular-Coku-eWK.esm.js +75 -0
  83. package/dist/chunks/KHR_materials_specular-Coku-eWK.esm.js.map +1 -0
  84. package/dist/chunks/KHR_materials_specular-DV0Eoetb.esm.min.js +2 -0
  85. package/dist/chunks/KHR_materials_specular-DV0Eoetb.esm.min.js.map +1 -0
  86. package/dist/chunks/KHR_materials_transmission-Ca9E-UZ-.esm.min.js +2 -0
  87. package/dist/chunks/KHR_materials_transmission-Ca9E-UZ-.esm.min.js.map +1 -0
  88. package/dist/chunks/KHR_materials_transmission-CuudPQVC.esm.js +307 -0
  89. package/dist/chunks/KHR_materials_transmission-CuudPQVC.esm.js.map +1 -0
  90. package/dist/chunks/KHR_materials_unlit-BAGBsUkU.esm.min.js +2 -0
  91. package/dist/chunks/KHR_materials_unlit-BAGBsUkU.esm.min.js.map +1 -0
  92. package/dist/chunks/KHR_materials_unlit-Buu1Z1HL.esm.js +74 -0
  93. package/dist/chunks/KHR_materials_unlit-Buu1Z1HL.esm.js.map +1 -0
  94. package/dist/chunks/KHR_materials_variants-CMcKgGG2.esm.min.js +2 -0
  95. package/dist/chunks/KHR_materials_variants-CMcKgGG2.esm.min.js.map +1 -0
  96. package/dist/chunks/KHR_materials_variants-DFu4FrrH.esm.js +238 -0
  97. package/dist/chunks/KHR_materials_variants-DFu4FrrH.esm.js.map +1 -0
  98. package/dist/chunks/KHR_materials_volume-CQMEAbf4.esm.js +87 -0
  99. package/dist/chunks/KHR_materials_volume-CQMEAbf4.esm.js.map +1 -0
  100. package/dist/chunks/KHR_materials_volume-ClGrFvKp.esm.min.js +2 -0
  101. package/dist/chunks/KHR_materials_volume-ClGrFvKp.esm.min.js.map +1 -0
  102. package/dist/chunks/KHR_mesh_quantization-Cbejp093.esm.js +26 -0
  103. package/dist/chunks/KHR_mesh_quantization-Cbejp093.esm.js.map +1 -0
  104. package/dist/chunks/KHR_mesh_quantization-DRPaTiWR.esm.min.js +2 -0
  105. package/dist/chunks/KHR_mesh_quantization-DRPaTiWR.esm.min.js.map +1 -0
  106. package/dist/chunks/KHR_node_visibility-BjfB0zna.esm.js +46 -0
  107. package/dist/chunks/KHR_node_visibility-BjfB0zna.esm.js.map +1 -0
  108. package/dist/chunks/KHR_node_visibility-CBw8B38Q.esm.min.js +2 -0
  109. package/dist/chunks/KHR_node_visibility-CBw8B38Q.esm.min.js.map +1 -0
  110. package/dist/chunks/KHR_texture_basisu-DBjIO7B4.esm.js +43 -0
  111. package/dist/chunks/KHR_texture_basisu-DBjIO7B4.esm.js.map +1 -0
  112. package/dist/chunks/KHR_texture_basisu-DKylW8Yx.esm.min.js +2 -0
  113. package/dist/chunks/KHR_texture_basisu-DKylW8Yx.esm.min.js.map +1 -0
  114. package/dist/chunks/KHR_texture_transform-D6mg2ZiK.esm.js +63 -0
  115. package/dist/chunks/KHR_texture_transform-D6mg2ZiK.esm.js.map +1 -0
  116. package/dist/chunks/KHR_texture_transform-htHBWqOc.esm.min.js +2 -0
  117. package/dist/chunks/KHR_texture_transform-htHBWqOc.esm.min.js.map +1 -0
  118. package/dist/chunks/KHR_xmp_json_ld-CvW3Ai8F.esm.js +51 -0
  119. package/dist/chunks/KHR_xmp_json_ld-CvW3Ai8F.esm.js.map +1 -0
  120. package/dist/chunks/KHR_xmp_json_ld-uYsLxYOz.esm.min.js +2 -0
  121. package/dist/chunks/KHR_xmp_json_ld-uYsLxYOz.esm.min.js.map +1 -0
  122. package/dist/chunks/MSFT_audio_emitter-DTJWk2eV.esm.min.js +2 -0
  123. package/dist/chunks/MSFT_audio_emitter-DTJWk2eV.esm.min.js.map +1 -0
  124. package/dist/chunks/MSFT_audio_emitter-oPM3iu4F.esm.js +2207 -0
  125. package/dist/chunks/MSFT_audio_emitter-oPM3iu4F.esm.js.map +1 -0
  126. package/dist/chunks/MSFT_lod-CuSynNTS.esm.js +337 -0
  127. package/dist/chunks/MSFT_lod-CuSynNTS.esm.js.map +1 -0
  128. package/dist/chunks/MSFT_lod-PjlomwUl.esm.min.js +2 -0
  129. package/dist/chunks/MSFT_lod-PjlomwUl.esm.min.js.map +1 -0
  130. package/dist/chunks/MSFT_minecraftMesh-BRBTW8ta.esm.min.js +2 -0
  131. package/dist/chunks/MSFT_minecraftMesh-BRBTW8ta.esm.min.js.map +1 -0
  132. package/dist/chunks/MSFT_minecraftMesh-DDlu3iRW.esm.js +46 -0
  133. package/dist/chunks/MSFT_minecraftMesh-DDlu3iRW.esm.js.map +1 -0
  134. package/dist/chunks/MSFT_sRGBFactors-BIOzrPxY.esm.min.js +2 -0
  135. package/dist/chunks/MSFT_sRGBFactors-BIOzrPxY.esm.min.js.map +1 -0
  136. package/dist/chunks/MSFT_sRGBFactors-CspQlvZh.esm.js +47 -0
  137. package/dist/chunks/MSFT_sRGBFactors-CspQlvZh.esm.js.map +1 -0
  138. package/dist/chunks/animationGroup-CL3Oz5Z0.esm.min.js +2 -0
  139. package/dist/chunks/animationGroup-CL3Oz5Z0.esm.min.js.map +1 -0
  140. package/dist/chunks/animationGroup-DRKiD9h6.esm.js +2482 -0
  141. package/dist/chunks/animationGroup-DRKiD9h6.esm.js.map +1 -0
  142. package/dist/chunks/assetContainer-D_8hiZKA.esm.js +1720 -0
  143. package/dist/chunks/assetContainer-D_8hiZKA.esm.js.map +1 -0
  144. package/dist/chunks/assetContainer-FA9ojI1I.esm.min.js +2 -0
  145. package/dist/chunks/assetContainer-FA9ojI1I.esm.min.js.map +1 -0
  146. package/dist/chunks/audioEngine-C-sKz5RP.esm.min.js +2 -0
  147. package/dist/chunks/audioEngine-C-sKz5RP.esm.min.js.map +1 -0
  148. package/dist/chunks/audioEngine-CvJDx4Q8.esm.js +305 -0
  149. package/dist/chunks/audioEngine-CvJDx4Q8.esm.js.map +1 -0
  150. package/dist/chunks/bakedVertexAnimation-BsPKKHjr.esm.min.js +2 -0
  151. package/dist/chunks/bakedVertexAnimation-BsPKKHjr.esm.min.js.map +1 -0
  152. package/dist/chunks/bakedVertexAnimation-DulpQEBV.esm.js +114 -0
  153. package/dist/chunks/bakedVertexAnimation-DulpQEBV.esm.js.map +1 -0
  154. package/dist/chunks/basisTextureLoader-B_r12OUF.esm.min.js +2 -0
  155. package/dist/chunks/basisTextureLoader-B_r12OUF.esm.min.js.map +1 -0
  156. package/dist/chunks/basisTextureLoader-Drw-ZVC0.esm.js +600 -0
  157. package/dist/chunks/basisTextureLoader-Drw-ZVC0.esm.js.map +1 -0
  158. package/dist/chunks/dds-BXiJypJ7.esm.js +540 -0
  159. package/dist/chunks/dds-BXiJypJ7.esm.js.map +1 -0
  160. package/dist/chunks/dds-C6ZHg-Bp.esm.min.js +2 -0
  161. package/dist/chunks/dds-C6ZHg-Bp.esm.min.js.map +1 -0
  162. package/dist/chunks/ddsTextureLoader-DgfGb80Z.esm.js +88 -0
  163. package/dist/chunks/ddsTextureLoader-DgfGb80Z.esm.js.map +1 -0
  164. package/dist/chunks/ddsTextureLoader-bPQ4ZVv4.esm.min.js +2 -0
  165. package/dist/chunks/ddsTextureLoader-bPQ4ZVv4.esm.min.js.map +1 -0
  166. package/dist/chunks/decalFragment-BpOnZOVp.esm.js +18 -0
  167. package/dist/chunks/decalFragment-BpOnZOVp.esm.js.map +1 -0
  168. package/dist/chunks/decalFragment-DbkDUo1S.esm.min.js +2 -0
  169. package/dist/chunks/decalFragment-DbkDUo1S.esm.min.js.map +1 -0
  170. package/dist/chunks/default.fragment-Crru0QNN.esm.min.js +2 -0
  171. package/dist/chunks/default.fragment-Crru0QNN.esm.min.js.map +1 -0
  172. package/dist/chunks/default.fragment-CxCyfbls.esm.js +433 -0
  173. package/dist/chunks/default.fragment-CxCyfbls.esm.js.map +1 -0
  174. package/dist/chunks/default.fragment-DA6kjpAQ.esm.min.js +2 -0
  175. package/dist/chunks/default.fragment-DA6kjpAQ.esm.min.js.map +1 -0
  176. package/dist/chunks/default.fragment-DWYF0Ivm.esm.js +497 -0
  177. package/dist/chunks/default.fragment-DWYF0Ivm.esm.js.map +1 -0
  178. package/dist/chunks/default.vertex-Bpzr6sJq.esm.min.js +2 -0
  179. package/dist/chunks/default.vertex-Bpzr6sJq.esm.min.js.map +1 -0
  180. package/dist/chunks/default.vertex-C5owo_r2.esm.js +181 -0
  181. package/dist/chunks/default.vertex-C5owo_r2.esm.js.map +1 -0
  182. package/dist/chunks/default.vertex-ClbZq87W.esm.min.js +2 -0
  183. package/dist/chunks/default.vertex-ClbZq87W.esm.min.js.map +1 -0
  184. package/dist/chunks/default.vertex-DvfVsBbt.esm.js +201 -0
  185. package/dist/chunks/default.vertex-DvfVsBbt.esm.js.map +1 -0
  186. package/dist/chunks/defaultUboDeclaration-BCpFsRl0.esm.js +13 -0
  187. package/dist/chunks/defaultUboDeclaration-BCpFsRl0.esm.js.map +1 -0
  188. package/dist/chunks/defaultUboDeclaration-BkPkSkeR.esm.min.js +2 -0
  189. package/dist/chunks/defaultUboDeclaration-BkPkSkeR.esm.min.js.map +1 -0
  190. package/dist/chunks/defaultUboDeclaration-CBkzLqUL.esm.js +15 -0
  191. package/dist/chunks/defaultUboDeclaration-CBkzLqUL.esm.js.map +1 -0
  192. package/dist/chunks/defaultUboDeclaration-DM6YTmmJ.esm.min.js +2 -0
  193. package/dist/chunks/defaultUboDeclaration-DM6YTmmJ.esm.min.js.map +1 -0
  194. package/dist/chunks/drawWrapper.functions-CKg3_9x4.esm.js +11 -0
  195. package/dist/chunks/drawWrapper.functions-CKg3_9x4.esm.js.map +1 -0
  196. package/dist/chunks/drawWrapper.functions-ng7lvueZ.esm.min.js +2 -0
  197. package/dist/chunks/drawWrapper.functions-ng7lvueZ.esm.min.js.map +1 -0
  198. package/dist/chunks/dumpTools-DEE0JNhe.esm.js +200 -0
  199. package/dist/chunks/dumpTools-DEE0JNhe.esm.js.map +1 -0
  200. package/dist/chunks/dumpTools-Dq65RGnm.esm.min.js +2 -0
  201. package/dist/chunks/dumpTools-Dq65RGnm.esm.min.js.map +1 -0
  202. package/dist/chunks/engine-CeL5Q4lw.esm.js +2220 -0
  203. package/dist/chunks/engine-CeL5Q4lw.esm.js.map +1 -0
  204. package/dist/chunks/engine-DT2G_lds.esm.min.js +2 -0
  205. package/dist/chunks/engine-DT2G_lds.esm.min.js.map +1 -0
  206. package/dist/chunks/engine.common-C9H9gh9W.esm.js +1162 -0
  207. package/dist/chunks/engine.common-C9H9gh9W.esm.js.map +1 -0
  208. package/dist/chunks/engine.common-CdhJvxwm.esm.min.js +2 -0
  209. package/dist/chunks/engine.common-CdhJvxwm.esm.min.js.map +1 -0
  210. package/dist/chunks/envTextureLoader-74tnifoT.esm.js +64 -0
  211. package/dist/chunks/envTextureLoader-74tnifoT.esm.js.map +1 -0
  212. package/dist/chunks/envTextureLoader-Dl937sIO.esm.min.js +2 -0
  213. package/dist/chunks/envTextureLoader-Dl937sIO.esm.min.js.map +1 -0
  214. package/dist/chunks/environmentTextureTools-ClEgwgya.esm.js +382 -0
  215. package/dist/chunks/environmentTextureTools-ClEgwgya.esm.js.map +1 -0
  216. package/dist/chunks/environmentTextureTools-DURIVP9U.esm.min.js +2 -0
  217. package/dist/chunks/environmentTextureTools-DURIVP9U.esm.min.js.map +1 -0
  218. package/dist/chunks/exrTextureLoader-BGXbJGBe.esm.js +1682 -0
  219. package/dist/chunks/exrTextureLoader-BGXbJGBe.esm.js.map +1 -0
  220. package/dist/chunks/exrTextureLoader-ZRs_EAQa.esm.min.js +2 -0
  221. package/dist/chunks/exrTextureLoader-ZRs_EAQa.esm.min.js.map +1 -0
  222. package/dist/chunks/fogFragment-BFKmSOC6.esm.js +102 -0
  223. package/dist/chunks/fogFragment-BFKmSOC6.esm.js.map +1 -0
  224. package/dist/chunks/fogFragment-BPVmPyK6.esm.js +101 -0
  225. package/dist/chunks/fogFragment-BPVmPyK6.esm.js.map +1 -0
  226. package/dist/chunks/fogFragment-DfLgusf7.esm.min.js +2 -0
  227. package/dist/chunks/fogFragment-DfLgusf7.esm.min.js.map +1 -0
  228. package/dist/chunks/fogFragment-uKmBf3r6.esm.min.js +2 -0
  229. package/dist/chunks/fogFragment-uKmBf3r6.esm.min.js.map +1 -0
  230. package/dist/chunks/fresnelFunction-69xZoG8U.esm.min.js +2 -0
  231. package/dist/chunks/fresnelFunction-69xZoG8U.esm.min.js.map +1 -0
  232. package/dist/chunks/fresnelFunction-piF4l7eF.esm.js +12 -0
  233. package/dist/chunks/fresnelFunction-piF4l7eF.esm.js.map +1 -0
  234. package/dist/chunks/glTFLoader-C1ef0xPc.esm.min.js +2 -0
  235. package/dist/chunks/glTFLoader-C1ef0xPc.esm.min.js.map +1 -0
  236. package/dist/chunks/glTFLoader-UTdbOHEt.esm.js +7606 -0
  237. package/dist/chunks/glTFLoader-UTdbOHEt.esm.js.map +1 -0
  238. package/dist/chunks/glTFLoaderAnimation-CapCmtyI.esm.js +77 -0
  239. package/dist/chunks/glTFLoaderAnimation-CapCmtyI.esm.js.map +1 -0
  240. package/dist/chunks/glTFLoaderAnimation-D31eUw-v.esm.min.js +2 -0
  241. package/dist/chunks/glTFLoaderAnimation-D31eUw-v.esm.min.js.map +1 -0
  242. package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js +2 -0
  243. package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js.map +1 -0
  244. package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js +67 -0
  245. package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js.map +1 -0
  246. package/dist/chunks/harmonicsFunctions-BOh29Gl-.esm.min.js +2 -0
  247. package/dist/chunks/harmonicsFunctions-BOh29Gl-.esm.min.js.map +1 -0
  248. package/dist/chunks/harmonicsFunctions-CPE4kiHw.esm.js +35 -0
  249. package/dist/chunks/harmonicsFunctions-CPE4kiHw.esm.js.map +1 -0
  250. package/dist/chunks/harmonicsFunctions-RPeiDmS4.esm.js +34 -0
  251. package/dist/chunks/harmonicsFunctions-RPeiDmS4.esm.js.map +1 -0
  252. package/dist/chunks/harmonicsFunctions-rQv4s0QP.esm.min.js +2 -0
  253. package/dist/chunks/harmonicsFunctions-rQv4s0QP.esm.min.js.map +1 -0
  254. package/dist/chunks/hdrTextureLoader-Dd17jp9W.esm.min.js +2 -0
  255. package/dist/chunks/hdrTextureLoader-Dd17jp9W.esm.min.js.map +1 -0
  256. package/dist/chunks/hdrTextureLoader-DsR_wESy.esm.js +252 -0
  257. package/dist/chunks/hdrTextureLoader-DsR_wESy.esm.js.map +1 -0
  258. package/dist/chunks/helperFunctions-Ce53D1y-.esm.min.js +2 -0
  259. package/dist/chunks/helperFunctions-Ce53D1y-.esm.min.js.map +1 -0
  260. package/dist/chunks/helperFunctions-D2c1ru49.esm.js +80 -0
  261. package/dist/chunks/helperFunctions-D2c1ru49.esm.js.map +1 -0
  262. package/dist/chunks/helperFunctions-VmMN0Mna.esm.js +108 -0
  263. package/dist/chunks/helperFunctions-VmMN0Mna.esm.js.map +1 -0
  264. package/dist/chunks/helperFunctions-zdjEtnRv.esm.min.js +2 -0
  265. package/dist/chunks/helperFunctions-zdjEtnRv.esm.min.js.map +1 -0
  266. package/dist/chunks/index-DBm7fzXf.esm.js +74321 -0
  267. package/dist/chunks/index-DBm7fzXf.esm.js.map +1 -0
  268. package/dist/chunks/index-jZFAQQur.esm.min.js +57 -0
  269. package/dist/chunks/index-jZFAQQur.esm.min.js.map +1 -0
  270. package/dist/chunks/ktxTextureLoader-9vfBC6UL.esm.js +814 -0
  271. package/dist/chunks/ktxTextureLoader-9vfBC6UL.esm.js.map +1 -0
  272. package/dist/chunks/ktxTextureLoader-B7knlkAj.esm.min.js +2 -0
  273. package/dist/chunks/ktxTextureLoader-B7knlkAj.esm.min.js.map +1 -0
  274. package/dist/chunks/logDepthDeclaration-BftGsCo7.esm.js +11 -0
  275. package/dist/chunks/logDepthDeclaration-BftGsCo7.esm.js.map +1 -0
  276. package/dist/chunks/logDepthDeclaration-Bm8zN8U1.esm.js +35 -0
  277. package/dist/chunks/logDepthDeclaration-Bm8zN8U1.esm.js.map +1 -0
  278. package/dist/chunks/logDepthDeclaration-D73_rPEp.esm.min.js +2 -0
  279. package/dist/chunks/logDepthDeclaration-D73_rPEp.esm.min.js.map +1 -0
  280. package/dist/chunks/logDepthDeclaration-Dine9EAs.esm.min.js +2 -0
  281. package/dist/chunks/logDepthDeclaration-Dine9EAs.esm.min.js.map +1 -0
  282. package/dist/chunks/logDepthVertex-3p3eoh78.esm.min.js +2 -0
  283. package/dist/chunks/logDepthVertex-3p3eoh78.esm.min.js.map +1 -0
  284. package/dist/chunks/logDepthVertex-CQfs32P9.esm.js +77 -0
  285. package/dist/chunks/logDepthVertex-CQfs32P9.esm.js.map +1 -0
  286. package/dist/chunks/logDepthVertex-Dr2Pw6AH.esm.js +77 -0
  287. package/dist/chunks/logDepthVertex-Dr2Pw6AH.esm.js.map +1 -0
  288. package/dist/chunks/logDepthVertex-Duy4jBoh.esm.min.js +2 -0
  289. package/dist/chunks/logDepthVertex-Duy4jBoh.esm.min.js.map +1 -0
  290. package/dist/chunks/mainUVVaryingDeclaration-63j_hdLk.esm.min.js +2 -0
  291. package/dist/chunks/mainUVVaryingDeclaration-63j_hdLk.esm.min.js.map +1 -0
  292. package/dist/chunks/mainUVVaryingDeclaration-BYMyGmMe.esm.js +11 -0
  293. package/dist/chunks/mainUVVaryingDeclaration-BYMyGmMe.esm.js.map +1 -0
  294. package/dist/chunks/mainUVVaryingDeclaration-D1G2R6CM.esm.min.js +2 -0
  295. package/dist/chunks/mainUVVaryingDeclaration-D1G2R6CM.esm.min.js.map +1 -0
  296. package/dist/chunks/mainUVVaryingDeclaration-DmvpmbUk.esm.js +11 -0
  297. package/dist/chunks/mainUVVaryingDeclaration-DmvpmbUk.esm.js.map +1 -0
  298. package/dist/chunks/meshUboDeclaration-BJv8KmAx.esm.min.js +2 -0
  299. package/dist/chunks/meshUboDeclaration-BJv8KmAx.esm.min.js.map +1 -0
  300. package/dist/chunks/meshUboDeclaration-yc1dSO0t.esm.js +24 -0
  301. package/dist/chunks/meshUboDeclaration-yc1dSO0t.esm.js.map +1 -0
  302. package/dist/chunks/objFileLoader-BMu0qrzr.esm.js +1338 -0
  303. package/dist/chunks/objFileLoader-BMu0qrzr.esm.js.map +1 -0
  304. package/dist/chunks/objFileLoader-i02qqOmW.esm.min.js +2 -0
  305. package/dist/chunks/objFileLoader-i02qqOmW.esm.min.js.map +1 -0
  306. package/dist/chunks/oitFragment-CH-SMl3Y.esm.js +1051 -0
  307. package/dist/chunks/oitFragment-CH-SMl3Y.esm.js.map +1 -0
  308. package/dist/chunks/oitFragment-Dv1eSAch.esm.min.js +2 -0
  309. package/dist/chunks/oitFragment-Dv1eSAch.esm.min.js.map +1 -0
  310. package/dist/chunks/oitFragment-Dy4y_3Q1.esm.min.js +2 -0
  311. package/dist/chunks/oitFragment-Dy4y_3Q1.esm.min.js.map +1 -0
  312. package/dist/chunks/oitFragment-gO2AJPMS.esm.js +1210 -0
  313. package/dist/chunks/oitFragment-gO2AJPMS.esm.js.map +1 -0
  314. package/dist/chunks/pass.fragment-3MBFymab.esm.js +15 -0
  315. package/dist/chunks/pass.fragment-3MBFymab.esm.js.map +1 -0
  316. package/dist/chunks/pass.fragment-9DV47zDM.esm.min.js +2 -0
  317. package/dist/chunks/pass.fragment-9DV47zDM.esm.min.js.map +1 -0
  318. package/dist/chunks/pass.fragment-CjPVw0cM.esm.js +15 -0
  319. package/dist/chunks/pass.fragment-CjPVw0cM.esm.js.map +1 -0
  320. package/dist/chunks/pass.fragment-DniCNtXz.esm.min.js +2 -0
  321. package/dist/chunks/pass.fragment-DniCNtXz.esm.min.js.map +1 -0
  322. package/dist/chunks/pbr.fragment-BfcLIVzL.esm.js +3218 -0
  323. package/dist/chunks/pbr.fragment-BfcLIVzL.esm.js.map +1 -0
  324. package/dist/chunks/pbr.fragment-C3w-Umr6.esm.js +3165 -0
  325. package/dist/chunks/pbr.fragment-C3w-Umr6.esm.js.map +1 -0
  326. package/dist/chunks/pbr.fragment-COVEAvqz.esm.min.js +2 -0
  327. package/dist/chunks/pbr.fragment-COVEAvqz.esm.min.js.map +1 -0
  328. package/dist/chunks/pbr.fragment-CYaflBNP.esm.min.js +2 -0
  329. package/dist/chunks/pbr.fragment-CYaflBNP.esm.min.js.map +1 -0
  330. package/dist/chunks/pbr.vertex-Bplm1RvR.esm.min.js +2 -0
  331. package/dist/chunks/pbr.vertex-Bplm1RvR.esm.min.js.map +1 -0
  332. package/dist/chunks/pbr.vertex-CJ6LxTam.esm.min.js +2 -0
  333. package/dist/chunks/pbr.vertex-CJ6LxTam.esm.min.js.map +1 -0
  334. package/dist/chunks/pbr.vertex-aEZZaJVy.esm.js +214 -0
  335. package/dist/chunks/pbr.vertex-aEZZaJVy.esm.js.map +1 -0
  336. package/dist/chunks/pbr.vertex-yjDKBRFi.esm.js +338 -0
  337. package/dist/chunks/pbr.vertex-yjDKBRFi.esm.js.map +1 -0
  338. package/dist/chunks/postprocess.vertex-DkSqDp_B.esm.js +20 -0
  339. package/dist/chunks/postprocess.vertex-DkSqDp_B.esm.js.map +1 -0
  340. package/dist/chunks/postprocess.vertex-jcsw-UdE.esm.min.js +2 -0
  341. package/dist/chunks/postprocess.vertex-jcsw-UdE.esm.min.js.map +1 -0
  342. package/dist/chunks/rawTexture-CYKKtww2.esm.min.js +2 -0
  343. package/dist/chunks/rawTexture-CYKKtww2.esm.min.js.map +1 -0
  344. package/dist/chunks/rawTexture-Dincgc4_.esm.js +191 -0
  345. package/dist/chunks/rawTexture-Dincgc4_.esm.js.map +1 -0
  346. package/dist/chunks/rgbdDecode.fragment-B1L0EyYQ.esm.js +17 -0
  347. package/dist/chunks/rgbdDecode.fragment-B1L0EyYQ.esm.js.map +1 -0
  348. package/dist/chunks/rgbdDecode.fragment-Bf3XkJ56.esm.js +17 -0
  349. package/dist/chunks/rgbdDecode.fragment-Bf3XkJ56.esm.js.map +1 -0
  350. package/dist/chunks/rgbdDecode.fragment-DehfVUqU.esm.min.js +2 -0
  351. package/dist/chunks/rgbdDecode.fragment-DehfVUqU.esm.min.js.map +1 -0
  352. package/dist/chunks/rgbdDecode.fragment-ObclIREU.esm.min.js +2 -0
  353. package/dist/chunks/rgbdDecode.fragment-ObclIREU.esm.min.js.map +1 -0
  354. package/dist/chunks/rgbdEncode.fragment-BUFNbMJl.esm.js +17 -0
  355. package/dist/chunks/rgbdEncode.fragment-BUFNbMJl.esm.js.map +1 -0
  356. package/dist/chunks/rgbdEncode.fragment-C5eGI_F7.esm.min.js +2 -0
  357. package/dist/chunks/rgbdEncode.fragment-C5eGI_F7.esm.min.js.map +1 -0
  358. package/dist/chunks/rgbdEncode.fragment-Cv2rZN9H.esm.js +17 -0
  359. package/dist/chunks/rgbdEncode.fragment-Cv2rZN9H.esm.js.map +1 -0
  360. package/dist/chunks/rgbdEncode.fragment-a2UFva1K.esm.min.js +2 -0
  361. package/dist/chunks/rgbdEncode.fragment-a2UFva1K.esm.min.js.map +1 -0
  362. package/dist/chunks/splatFileLoader-Ci35-grq.esm.js +3948 -0
  363. package/dist/chunks/splatFileLoader-Ci35-grq.esm.js.map +1 -0
  364. package/dist/chunks/splatFileLoader-D6TovORe.esm.min.js +2 -0
  365. package/dist/chunks/splatFileLoader-D6TovORe.esm.min.js.map +1 -0
  366. package/dist/chunks/standardMaterial-CWe_HbM8.esm.js +1805 -0
  367. package/dist/chunks/standardMaterial-CWe_HbM8.esm.js.map +1 -0
  368. package/dist/chunks/standardMaterial-S43MSA6g.esm.min.js +2 -0
  369. package/dist/chunks/standardMaterial-S43MSA6g.esm.min.js.map +1 -0
  370. package/dist/chunks/stlFileLoader-BKWCF44z.esm.min.js +2 -0
  371. package/dist/chunks/stlFileLoader-BKWCF44z.esm.min.js.map +1 -0
  372. package/dist/chunks/stlFileLoader-yX9YZMTi.esm.js +238 -0
  373. package/dist/chunks/stlFileLoader-yX9YZMTi.esm.js.map +1 -0
  374. package/dist/chunks/tgaTextureLoader-Cplo6n3C.esm.min.js +2 -0
  375. package/dist/chunks/tgaTextureLoader-Cplo6n3C.esm.min.js.map +1 -0
  376. package/dist/chunks/tgaTextureLoader-Ih4TItIE.esm.js +349 -0
  377. package/dist/chunks/tgaTextureLoader-Ih4TItIE.esm.js.map +1 -0
  378. package/dist/chunks/thinEngine-CxcDG6-R.esm.min.js +2 -0
  379. package/dist/chunks/thinEngine-CxcDG6-R.esm.min.js.map +1 -0
  380. package/dist/chunks/thinEngine-vHy0Qu0Z.esm.js +3842 -0
  381. package/dist/chunks/thinEngine-vHy0Qu0Z.esm.js.map +1 -0
  382. package/dist/chunks/thinInstanceMesh-CfVH9qgD.esm.js +314 -0
  383. package/dist/chunks/thinInstanceMesh-CfVH9qgD.esm.js.map +1 -0
  384. package/dist/chunks/thinInstanceMesh-DsyDWStO.esm.min.js +2 -0
  385. package/dist/chunks/thinInstanceMesh-DsyDWStO.esm.min.js.map +1 -0
  386. package/dist/chunks/vertexColorMixing-BTsACspH.esm.min.js +2 -0
  387. package/dist/chunks/vertexColorMixing-BTsACspH.esm.min.js.map +1 -0
  388. package/dist/chunks/vertexColorMixing-C7lCJCs9.esm.js +412 -0
  389. package/dist/chunks/vertexColorMixing-C7lCJCs9.esm.js.map +1 -0
  390. package/dist/chunks/vertexColorMixing-CtbEZ5C1.esm.js +522 -0
  391. package/dist/chunks/vertexColorMixing-CtbEZ5C1.esm.js.map +1 -0
  392. package/dist/chunks/vertexColorMixing-mccpwG_C.esm.min.js +2 -0
  393. package/dist/chunks/vertexColorMixing-mccpwG_C.esm.min.js.map +1 -0
  394. package/dist/chunks/webgpuEngine-B8X6Ca_-.esm.min.js +2 -0
  395. package/dist/chunks/webgpuEngine-B8X6Ca_-.esm.min.js.map +1 -0
  396. package/dist/chunks/webgpuEngine-BnnNyU1U.esm.js +11533 -0
  397. package/dist/chunks/webgpuEngine-BnnNyU1U.esm.js.map +1 -0
  398. package/dist/chunks/workerPool-BUOov2K1.esm.js +122 -0
  399. package/dist/chunks/workerPool-BUOov2K1.esm.js.map +1 -0
  400. package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js +2 -0
  401. package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js.map +1 -0
  402. package/docs/ViewerDefault.jpg +0 -0
  403. package/docs/ViewerParts.jpg +0 -0
  404. package/docs/ViewerSlots.jpg +0 -0
  405. package/docs/ViewerStyled.jpg +0 -0
  406. package/lib/index.d.ts +534 -0
  407. package/lib/index.js +1939 -0
  408. package/lib/index.js.map +1 -0
  409. package/package.json +18 -27
  410. package/readme.md +145 -21
  411. package/configuration/configuration.d.ts +0 -107
  412. package/configuration/configuration.js +0 -16
  413. package/configuration/configuration.js.map +0 -1
  414. package/configuration/configurationCompatibility.d.ts +0 -8
  415. package/configuration/configurationCompatibility.js +0 -66
  416. package/configuration/configurationCompatibility.js.map +0 -1
  417. package/configuration/configurationContainer.d.ts +0 -10
  418. package/configuration/configurationContainer.js +0 -10
  419. package/configuration/configurationContainer.js.map +0 -1
  420. package/configuration/globals.d.ts +0 -6
  421. package/configuration/globals.js +0 -18
  422. package/configuration/globals.js.map +0 -1
  423. package/configuration/index.d.ts +0 -2
  424. package/configuration/index.js +0 -4
  425. package/configuration/index.js.map +0 -1
  426. package/configuration/interfaces/cameraConfiguration.d.ts +0 -31
  427. package/configuration/interfaces/cameraConfiguration.js +0 -2
  428. package/configuration/interfaces/cameraConfiguration.js.map +0 -1
  429. package/configuration/interfaces/colorGradingConfiguration.d.ts +0 -81
  430. package/configuration/interfaces/colorGradingConfiguration.js +0 -2
  431. package/configuration/interfaces/colorGradingConfiguration.js.map +0 -1
  432. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +0 -20
  433. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +0 -2
  434. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +0 -1
  435. package/configuration/interfaces/environmentMapConfiguration.d.ts +0 -22
  436. package/configuration/interfaces/environmentMapConfiguration.js +0 -2
  437. package/configuration/interfaces/environmentMapConfiguration.js.map +0 -1
  438. package/configuration/interfaces/groundConfiguration.d.ts +0 -24
  439. package/configuration/interfaces/groundConfiguration.js +0 -2
  440. package/configuration/interfaces/groundConfiguration.js.map +0 -1
  441. package/configuration/interfaces/imageProcessingConfiguration.d.ts +0 -45
  442. package/configuration/interfaces/imageProcessingConfiguration.js +0 -2
  443. package/configuration/interfaces/imageProcessingConfiguration.js.map +0 -1
  444. package/configuration/interfaces/index.d.ts +0 -15
  445. package/configuration/interfaces/index.js +0 -16
  446. package/configuration/interfaces/index.js.map +0 -1
  447. package/configuration/interfaces/lightConfiguration.d.ts +0 -60
  448. package/configuration/interfaces/lightConfiguration.js +0 -2
  449. package/configuration/interfaces/lightConfiguration.js.map +0 -1
  450. package/configuration/interfaces/modelAnimationConfiguration.d.ts +0 -26
  451. package/configuration/interfaces/modelAnimationConfiguration.js +0 -2
  452. package/configuration/interfaces/modelAnimationConfiguration.js.map +0 -1
  453. package/configuration/interfaces/modelConfiguration.d.ts +0 -65
  454. package/configuration/interfaces/modelConfiguration.js +0 -2
  455. package/configuration/interfaces/modelConfiguration.js.map +0 -1
  456. package/configuration/interfaces/observersConfiguration.d.ts +0 -5
  457. package/configuration/interfaces/observersConfiguration.js +0 -2
  458. package/configuration/interfaces/observersConfiguration.js.map +0 -1
  459. package/configuration/interfaces/sceneConfiguration.d.ts +0 -48
  460. package/configuration/interfaces/sceneConfiguration.js +0 -2
  461. package/configuration/interfaces/sceneConfiguration.js.map +0 -1
  462. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +0 -23
  463. package/configuration/interfaces/sceneOptimizerConfiguration.js +0 -2
  464. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +0 -1
  465. package/configuration/interfaces/skyboxConfiguration.d.ts +0 -21
  466. package/configuration/interfaces/skyboxConfiguration.js +0 -2
  467. package/configuration/interfaces/skyboxConfiguration.js.map +0 -1
  468. package/configuration/interfaces/templateConfiguration.d.ts +0 -67
  469. package/configuration/interfaces/templateConfiguration.js +0 -2
  470. package/configuration/interfaces/templateConfiguration.js.map +0 -1
  471. package/configuration/interfaces/vrConfiguration.d.ts +0 -16
  472. package/configuration/interfaces/vrConfiguration.js +0 -2
  473. package/configuration/interfaces/vrConfiguration.js.map +0 -1
  474. package/configuration/loader.d.ts +0 -4
  475. package/configuration/loader.js +0 -17
  476. package/configuration/loader.js.map +0 -1
  477. package/configuration/mappers.d.ts +0 -43
  478. package/configuration/mappers.js +0 -193
  479. package/configuration/mappers.js.map +0 -1
  480. package/configuration/renderOnlyLoader.d.ts +0 -33
  481. package/configuration/renderOnlyLoader.js +0 -162
  482. package/configuration/renderOnlyLoader.js.map +0 -1
  483. package/configuration/types/default.d.ts +0 -6
  484. package/configuration/types/default.js +0 -121
  485. package/configuration/types/default.js.map +0 -1
  486. package/configuration/types/environmentMap.d.ts +0 -5
  487. package/configuration/types/environmentMap.js +0 -14
  488. package/configuration/types/environmentMap.js.map +0 -1
  489. package/configuration/types/extended.d.ts +0 -6
  490. package/configuration/types/extended.js +0 -317
  491. package/configuration/types/extended.js.map +0 -1
  492. package/configuration/types/index.d.ts +0 -14
  493. package/configuration/types/index.js +0 -51
  494. package/configuration/types/index.js.map +0 -1
  495. package/configuration/types/minimal.d.ts +0 -6
  496. package/configuration/types/minimal.js +0 -43
  497. package/configuration/types/minimal.js.map +0 -1
  498. package/configuration/types/renderOnlyDefault.d.ts +0 -30
  499. package/configuration/types/renderOnlyDefault.js +0 -31
  500. package/configuration/types/renderOnlyDefault.js.map +0 -1
  501. package/configuration/types/shadowLight.d.ts +0 -9
  502. package/configuration/types/shadowLight.js +0 -64
  503. package/configuration/types/shadowLight.js.map +0 -1
  504. package/helper/index.d.ts +0 -29
  505. package/helper/index.js +0 -66
  506. package/helper/index.js.map +0 -1
  507. package/index.d.ts +0 -30
  508. package/index.js +0 -46
  509. package/index.js.map +0 -1
  510. package/initializer.d.ts +0 -11
  511. package/initializer.js +0 -35
  512. package/initializer.js.map +0 -1
  513. package/interfaces.d.ts +0 -5
  514. package/interfaces.js +0 -7
  515. package/interfaces.js.map +0 -1
  516. package/labs/environmentSerializer.d.ts +0 -126
  517. package/labs/environmentSerializer.js +0 -191
  518. package/labs/environmentSerializer.js.map +0 -1
  519. package/labs/texture.d.ts +0 -183
  520. package/labs/texture.js +0 -351
  521. package/labs/texture.js.map +0 -1
  522. package/labs/viewerLabs.d.ts +0 -51
  523. package/labs/viewerLabs.js +0 -134
  524. package/labs/viewerLabs.js.map +0 -1
  525. package/loader/modelLoader.d.ts +0 -56
  526. package/loader/modelLoader.js +0 -202
  527. package/loader/modelLoader.js.map +0 -1
  528. package/loader/plugins/applyMaterialConfig.d.ts +0 -12
  529. package/loader/plugins/applyMaterialConfig.js +0 -16
  530. package/loader/plugins/applyMaterialConfig.js.map +0 -1
  531. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +0 -9
  532. package/loader/plugins/extendedMaterialLoaderPlugin.js +0 -16
  533. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +0 -1
  534. package/loader/plugins/index.d.ts +0 -19
  535. package/loader/plugins/index.js +0 -44
  536. package/loader/plugins/index.js.map +0 -1
  537. package/loader/plugins/loaderPlugin.d.ts +0 -24
  538. package/loader/plugins/loaderPlugin.js +0 -2
  539. package/loader/plugins/loaderPlugin.js.map +0 -1
  540. package/loader/plugins/msftLodLoaderPlugin.d.ts +0 -12
  541. package/loader/plugins/msftLodLoaderPlugin.js +0 -21
  542. package/loader/plugins/msftLodLoaderPlugin.js.map +0 -1
  543. package/loader/plugins/telemetryLoaderPlugin.d.ts +0 -12
  544. package/loader/plugins/telemetryLoaderPlugin.js +0 -36
  545. package/loader/plugins/telemetryLoaderPlugin.js.map +0 -1
  546. package/managers/observablesManager.d.ts +0 -66
  547. package/managers/observablesManager.js +0 -35
  548. package/managers/observablesManager.js.map +0 -1
  549. package/managers/sceneManager.d.ts +0 -245
  550. package/managers/sceneManager.js +0 -1375
  551. package/managers/sceneManager.js.map +0 -1
  552. package/managers/telemetryManager.d.ts +0 -78
  553. package/managers/telemetryManager.js +0 -117
  554. package/managers/telemetryManager.js.map +0 -1
  555. package/model/modelAnimation.d.ts +0 -215
  556. package/model/modelAnimation.js +0 -237
  557. package/model/modelAnimation.js.map +0 -1
  558. package/model/viewerModel.d.ts +0 -233
  559. package/model/viewerModel.js +0 -673
  560. package/model/viewerModel.js.map +0 -1
  561. package/optimizer/custom/extended.d.ts +0 -13
  562. package/optimizer/custom/extended.js +0 -101
  563. package/optimizer/custom/extended.js.map +0 -1
  564. package/optimizer/custom/index.d.ts +0 -9
  565. package/optimizer/custom/index.js +0 -26
  566. package/optimizer/custom/index.js.map +0 -1
  567. package/renderOnlyIndex.d.ts +0 -11
  568. package/renderOnlyIndex.js +0 -18
  569. package/renderOnlyIndex.js.map +0 -1
  570. package/templating/eventManager.d.ts +0 -35
  571. package/templating/eventManager.js +0 -66
  572. package/templating/eventManager.js.map +0 -1
  573. package/templating/plugins/hdButtonPlugin.d.ts +0 -9
  574. package/templating/plugins/hdButtonPlugin.js +0 -22
  575. package/templating/plugins/hdButtonPlugin.js.map +0 -1
  576. package/templating/plugins/printButton.d.ts +0 -9
  577. package/templating/plugins/printButton.js +0 -41
  578. package/templating/plugins/printButton.js.map +0 -1
  579. package/templating/templateManager.d.ts +0 -197
  580. package/templating/templateManager.js +0 -561
  581. package/templating/templateManager.js.map +0 -1
  582. package/templating/viewerTemplatePlugin.d.ts +0 -21
  583. package/templating/viewerTemplatePlugin.js +0 -69
  584. package/templating/viewerTemplatePlugin.js.map +0 -1
  585. package/viewer/defaultViewer.d.ts +0 -130
  586. package/viewer/defaultViewer.js +0 -672
  587. package/viewer/defaultViewer.js.map +0 -1
  588. package/viewer/renderOnlyViewer.d.ts +0 -9
  589. package/viewer/renderOnlyViewer.js +0 -46
  590. package/viewer/renderOnlyViewer.js.map +0 -1
  591. package/viewer/viewer.d.ts +0 -258
  592. package/viewer/viewer.js +0 -783
  593. package/viewer/viewer.js.map +0 -1
  594. package/viewer/viewerManager.d.ts +0 -58
  595. package/viewer/viewerManager.js +0 -91
  596. package/viewer/viewerManager.js.map +0 -1
  597. package/viewer/viewerWithTemplate.d.ts +0 -9
  598. package/viewer/viewerWithTemplate.js +0 -20
  599. package/viewer/viewerWithTemplate.js.map +0 -1
@@ -0,0 +1,3948 @@
1
+ import { i as ShaderStore, R as RegisterClass, z as PushMaterial, J as PrepareDefinesForMisc, K as PrepareDefinesForFrameBoundValues, N as PrepareDefinesForAttributes, Q as PrepareAttributesForInstances, W as PrepareUniformsAndSamplersList, X as addClipPlaneUniforms, Y as Camera, Z as bindClipPlane, _ as BindFogParameters, $ as BindLogDepth, a0 as SerializationHelper, a1 as MaterialDefines, V as VertexBuffer, a2 as functions, a3 as HighestCommonFactor, M as Mesh, a4 as Matrix, v as Vector3, x as VertexData, a5 as SubMesh, a6 as TmpVectors, L as Logger, a7 as runCoroutineAsync, T as Tools, a8 as ToHalfFloat, C as Constants, a9 as runCoroutineSync, u as Vector2, aa as createYieldingScheduler, m as Color4, ab as Quaternion, ac as BuildArray, ad as Epsilon, ae as IntersectionInfo, E as EngineStore, af as PickingInfo, ag as _ImportHelper, ah as Scene, s as Color3, ai as Vector4, aj as RandomRange, B as BaseTexture, ak as SPLATFileLoaderMetadata, y as registerSceneLoaderPlugin } from './index-DBm7fzXf.esm.js';
2
+ import './fogFragment-BFKmSOC6.esm.js';
3
+ import './logDepthDeclaration-Bm8zN8U1.esm.js';
4
+ import './logDepthVertex-Dr2Pw6AH.esm.js';
5
+ import './fogFragment-BPVmPyK6.esm.js';
6
+ import './logDepthDeclaration-BftGsCo7.esm.js';
7
+ import './meshUboDeclaration-yc1dSO0t.esm.js';
8
+ import './logDepthVertex-CQfs32P9.esm.js';
9
+ import { R as RawTexture } from './rawTexture-Dincgc4_.esm.js';
10
+ import './thinInstanceMesh-CfVH9qgD.esm.js';
11
+ import { A as AssetContainer } from './assetContainer-D_8hiZKA.esm.js';
12
+ import { S as StandardMaterial } from './standardMaterial-CWe_HbM8.esm.js';
13
+
14
+ // Do not edit.
15
+ const name$9 = "gaussianSplattingFragmentDeclaration";
16
+ const shader$9 = `vec4 gaussianColor(vec4 inColor)
17
+ {float A=-dot(vPosition,vPosition);if (A<-4.0) discard;float B=exp(A)*inColor.a;
18
+ #include<logDepthFragment>
19
+ vec3 color=inColor.rgb;
20
+ #ifdef FOG
21
+ #include<fogFragment>
22
+ #endif
23
+ return vec4(color,B);}
24
+ `;
25
+ // Sideeffect
26
+ ShaderStore.IncludesShadersStore[name$9] = shader$9;
27
+
28
+ // Do not edit.
29
+ const name$8 = "gaussianSplattingPixelShader";
30
+ const shader$8 = `#include<clipPlaneFragmentDeclaration>
31
+ #include<logDepthDeclaration>
32
+ #include<fogFragmentDeclaration>
33
+ varying vec4 vColor;varying vec2 vPosition;
34
+ #include<gaussianSplattingFragmentDeclaration>
35
+ void main () {
36
+ #include<clipPlaneFragment>
37
+ gl_FragColor=gaussianColor(vColor);}
38
+ `;
39
+ // Sideeffect
40
+ ShaderStore.ShadersStore[name$8] = shader$8;
41
+ /** @internal */
42
+ const gaussianSplattingPixelShader = { name: name$8, shader: shader$8 };
43
+
44
+ var gaussianSplatting_fragment$1 = /*#__PURE__*/Object.freeze({
45
+ __proto__: null,
46
+ gaussianSplattingPixelShader: gaussianSplattingPixelShader
47
+ });
48
+
49
+ // Do not edit.
50
+ const name$7 = "gaussianSplattingVertexDeclaration";
51
+ const shader$7 = `attribute vec2 position;uniform mat4 view;uniform mat4 projection;uniform mat4 world;`;
52
+ // Sideeffect
53
+ ShaderStore.IncludesShadersStore[name$7] = shader$7;
54
+
55
+ // Do not edit.
56
+ const name$6 = "gaussianSplattingUboDeclaration";
57
+ const shader$6 = `#include<sceneUboDeclaration>
58
+ #include<meshUboDeclaration>
59
+ attribute vec2 position;`;
60
+ // Sideeffect
61
+ ShaderStore.IncludesShadersStore[name$6] = shader$6;
62
+
63
+ // Do not edit.
64
+ const name$5 = "gaussianSplatting";
65
+ const shader$5 = `#if !defined(WEBGL2) && !defined(WEBGPU) && !defined(NATIVE)
66
+ mat3 transpose(mat3 matrix) {return mat3(matrix[0][0],matrix[1][0],matrix[2][0],
67
+ matrix[0][1],matrix[1][1],matrix[2][1],
68
+ matrix[0][2],matrix[1][2],matrix[2][2]);}
69
+ #endif
70
+ vec2 getDataUV(float index,vec2 textureSize) {float y=floor(index/textureSize.x);float x=index-y*textureSize.x;return vec2((x+0.5)/textureSize.x,(y+0.5)/textureSize.y);}
71
+ struct Splat {vec4 center;vec4 color;vec4 covA;vec4 covB;};Splat readSplat(float splatIndex)
72
+ {Splat splat;vec2 splatUV=getDataUV(splatIndex,dataTextureSize);splat.center=texture2D(centersTexture,splatUV);splat.color=texture2D(colorsTexture,splatUV);splat.covA=texture2D(covariancesATexture,splatUV)*splat.center.w;splat.covB=texture2D(covariancesBTexture,splatUV)*splat.center.w;return splat;}
73
+ vec4 gaussianSplatting(vec2 meshPos,vec3 worldPos,vec2 scale,vec3 covA,vec3 covB,mat4 worldMatrix,mat4 viewMatrix,mat4 projectionMatrix)
74
+ {mat4 modelView=viewMatrix*worldMatrix;vec4 camspace=viewMatrix*vec4(worldPos,1.);vec4 pos2d=projectionMatrix*camspace;float bounds=1.2*pos2d.w;if (pos2d.z<-pos2d.w || pos2d.x<-bounds || pos2d.x>bounds
75
+ || pos2d.y<-bounds || pos2d.y>bounds) {return vec4(0.0,0.0,2.0,1.0);}
76
+ mat3 Vrk=mat3(
77
+ covA.x,covA.y,covA.z,
78
+ covA.y,covB.x,covB.y,
79
+ covA.z,covB.y,covB.z
80
+ );mat3 J=mat3(
81
+ focal.x/camspace.z,0.,-(focal.x*camspace.x)/(camspace.z*camspace.z),
82
+ 0.,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),
83
+ 0.,0.,0.
84
+ );mat3 invy=mat3(1,0,0,0,-1,0,0,0,1);mat3 T=invy*transpose(mat3(modelView))*J;mat3 cov2d=transpose(T)*Vrk*T;float mid=(cov2d[0][0]+cov2d[1][1])/2.0;float radius=length(vec2((cov2d[0][0]-cov2d[1][1])/2.0,cov2d[0][1]));float lambda1=mid+radius,lambda2=mid-radius;if (lambda2<0.0)
85
+ {return vec4(0.0,0.0,2.0,1.0);}
86
+ vec2 diagonalVector=normalize(vec2(cov2d[0][1],lambda1-cov2d[0][0]));vec2 majorAxis=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;vec2 minorAxis=min(sqrt(2.0*lambda2),1024.0)*vec2(diagonalVector.y,-diagonalVector.x);vec2 vCenter=vec2(pos2d);return vec4(
87
+ vCenter
88
+ + ((meshPos.x*majorAxis
89
+ + meshPos.y*minorAxis)*invViewport*pos2d.w)*scale,pos2d.zw);}`;
90
+ // Sideeffect
91
+ ShaderStore.IncludesShadersStore[name$5] = shader$5;
92
+
93
+ // Do not edit.
94
+ const name$4 = "gaussianSplattingVertexShader";
95
+ const shader$4 = `#include<__decl__gaussianSplattingVertex>
96
+ #ifdef LOGARITHMICDEPTH
97
+ #extension GL_EXT_frag_depth : enable
98
+ #endif
99
+ #include<clipPlaneVertexDeclaration>
100
+ #include<fogVertexDeclaration>
101
+ #include<logDepthDeclaration>
102
+ attribute float splatIndex;uniform vec2 invViewport;uniform vec2 dataTextureSize;uniform vec2 focal;uniform sampler2D covariancesATexture;uniform sampler2D covariancesBTexture;uniform sampler2D centersTexture;uniform sampler2D colorsTexture;varying vec4 vColor;varying vec2 vPosition;
103
+ #include<gaussianSplatting>
104
+ void main () {Splat splat=readSplat(splatIndex);vec3 covA=splat.covA.xyz;vec3 covB=vec3(splat.covA.w,splat.covB.xy);vec4 worldPos=world*vec4(splat.center.xyz,1.0);vColor=splat.color;vPosition=position;gl_Position=gaussianSplatting(position,worldPos.xyz,vec2(1.,1.),covA,covB,world,view,projection);
105
+ #include<clipPlaneVertex>
106
+ #include<fogVertex>
107
+ #include<logDepthVertex>
108
+ }
109
+ `;
110
+ // Sideeffect
111
+ ShaderStore.ShadersStore[name$4] = shader$4;
112
+ /** @internal */
113
+ const gaussianSplattingVertexShader = { name: name$4, shader: shader$4 };
114
+
115
+ var gaussianSplatting_vertex$1 = /*#__PURE__*/Object.freeze({
116
+ __proto__: null,
117
+ gaussianSplattingVertexShader: gaussianSplattingVertexShader
118
+ });
119
+
120
+ // Do not edit.
121
+ const name$3 = "gaussianSplattingFragmentDeclaration";
122
+ const shader$3 = `fn gaussianColor(inColor: vec4f,inPosition: vec2f)->vec4f
123
+ {var A : f32=-dot(inPosition,inPosition);if (A>-4.0)
124
+ {var B: f32=exp(A)*inColor.a;
125
+ #include<logDepthFragment>
126
+ var color: vec3f=inColor.rgb;
127
+ #ifdef FOG
128
+ #include<fogFragment>
129
+ #endif
130
+ return vec4f(color,B);} else {return vec4f(0.0);}}
131
+ `;
132
+ // Sideeffect
133
+ ShaderStore.IncludesShadersStoreWGSL[name$3] = shader$3;
134
+
135
+ // Do not edit.
136
+ const name$2 = "gaussianSplattingPixelShader";
137
+ const shader$2 = `#include<clipPlaneFragmentDeclaration>
138
+ #include<logDepthDeclaration>
139
+ #include<fogFragmentDeclaration>
140
+ varying vColor: vec4f;varying vPosition: vec2f;
141
+ #include<gaussianSplattingFragmentDeclaration>
142
+ @fragment
143
+ fn main(input: FragmentInputs)->FragmentOutputs {
144
+ #include<clipPlaneFragment>
145
+ fragmentOutputs.color=gaussianColor(input.vColor,input.vPosition);}
146
+ `;
147
+ // Sideeffect
148
+ ShaderStore.ShadersStoreWGSL[name$2] = shader$2;
149
+ /** @internal */
150
+ const gaussianSplattingPixelShaderWGSL = { name: name$2, shader: shader$2 };
151
+
152
+ var gaussianSplatting_fragment = /*#__PURE__*/Object.freeze({
153
+ __proto__: null,
154
+ gaussianSplattingPixelShaderWGSL: gaussianSplattingPixelShaderWGSL
155
+ });
156
+
157
+ // Do not edit.
158
+ const name$1 = "gaussianSplatting";
159
+ const shader$1 = `fn getDataUV(index: f32,dataTextureSize: vec2f)->vec2<f32> {let y: f32=floor(index/dataTextureSize.x);let x: f32=index-y*dataTextureSize.x;return vec2f((x+0.5),(y+0.5));}
160
+ struct Splat {center: vec4f,
161
+ color: vec4f,
162
+ covA: vec4f,
163
+ covB: vec4f,};fn readSplat(splatIndex: f32,dataTextureSize: vec2f)->Splat {var splat: Splat;let splatUV=getDataUV(splatIndex,dataTextureSize);let splatUVi32=vec2<i32>(i32(splatUV.x),i32(splatUV.y));splat.center=textureLoad(centersTexture,splatUVi32,0);splat.color=textureLoad(colorsTexture,splatUVi32,0);splat.covA=textureLoad(covariancesATexture,splatUVi32,0)*splat.center.w;splat.covB=textureLoad(covariancesBTexture,splatUVi32,0)*splat.center.w;return splat;}
164
+ fn gaussianSplatting(
165
+ meshPos: vec2<f32>,
166
+ worldPos: vec3<f32>,
167
+ scale: vec2<f32>,
168
+ covA: vec3<f32>,
169
+ covB: vec3<f32>,
170
+ worldMatrix: mat4x4<f32>,
171
+ viewMatrix: mat4x4<f32>,
172
+ projectionMatrix: mat4x4<f32>,
173
+ focal: vec2f,
174
+ invViewport: vec2f
175
+ )->vec4f {let modelView=viewMatrix*worldMatrix;let camspace=viewMatrix*vec4f(worldPos,1.0);let pos2d=projectionMatrix*camspace;let bounds=1.2*pos2d.w;if (pos2d.z<0. || pos2d.x<-bounds || pos2d.x>bounds || pos2d.y<-bounds || pos2d.y>bounds) {return vec4f(0.0,0.0,2.0,1.0);}
176
+ let Vrk=mat3x3<f32>(
177
+ covA.x,covA.y,covA.z,
178
+ covA.y,covB.x,covB.y,
179
+ covA.z,covB.y,covB.z
180
+ );let J=mat3x3<f32>(
181
+ focal.x/camspace.z,0.0,-(focal.x*camspace.x)/(camspace.z*camspace.z),
182
+ 0.0,focal.y/camspace.z,-(focal.y*camspace.y)/(camspace.z*camspace.z),
183
+ 0.0,0.0,0.0
184
+ );let invy=mat3x3<f32>(
185
+ 1.0,0.0,0.0,
186
+ 0.0,-1.0,0.0,
187
+ 0.0,0.0,1.0
188
+ );let T=invy*transpose(mat3x3<f32>(
189
+ modelView[0].xyz,
190
+ modelView[1].xyz,
191
+ modelView[2].xyz))*J;let cov2d=transpose(T)*Vrk*T;let mid=(cov2d[0][0]+cov2d[1][1])/2.0;let radius=length(vec2<f32>((cov2d[0][0]-cov2d[1][1])/2.0,cov2d[0][1]));let lambda1=mid+radius;let lambda2=mid-radius;if (lambda2<0.0) {return vec4f(0.0,0.0,2.0,1.0);}
192
+ let diagonalVector=normalize(vec2<f32>(cov2d[0][1],lambda1-cov2d[0][0]));let majorAxis=min(sqrt(2.0*lambda1),1024.0)*diagonalVector;let minorAxis=min(sqrt(2.0*lambda2),1024.0)*vec2<f32>(diagonalVector.y,-diagonalVector.x);let vCenter=vec2<f32>(pos2d.x,pos2d.y);return vec4f(
193
+ vCenter+((meshPos.x*majorAxis+meshPos.y*minorAxis)*invViewport*pos2d.w)*scale,
194
+ pos2d.z,
195
+ pos2d.w
196
+ );}
197
+ `;
198
+ // Sideeffect
199
+ ShaderStore.IncludesShadersStoreWGSL[name$1] = shader$1;
200
+
201
+ // Do not edit.
202
+ const name = "gaussianSplattingVertexShader";
203
+ const shader = `#include<sceneUboDeclaration>
204
+ #include<meshUboDeclaration>
205
+ #include<clipPlaneVertexDeclaration>
206
+ #include<fogVertexDeclaration>
207
+ #include<logDepthDeclaration>
208
+ attribute splatIndex: f32;attribute position: vec2f;uniform invViewport: vec2f;uniform dataTextureSize: vec2f;uniform focal: vec2f;var covariancesATexture: texture_2d<f32>;var covariancesBTexture: texture_2d<f32>;var centersTexture: texture_2d<f32>;var colorsTexture: texture_2d<f32>;varying vColor: vec4f;varying vPosition: vec2f;
209
+ #include<gaussianSplatting>
210
+ @vertex
211
+ fn main(input : VertexInputs)->FragmentInputs {var splat: Splat=readSplat(input.splatIndex,uniforms.dataTextureSize);var covA: vec3f=splat.covA.xyz;var covB: vec3f=vec3f(splat.covA.w,splat.covB.xy);let worldPos: vec4f=mesh.world*vec4f(splat.center.xyz,1.0);vertexOutputs.vColor=splat.color;vertexOutputs.vPosition=input.position;vertexOutputs.position=gaussianSplatting(input.position,worldPos.xyz,vec2f(1.0,1.0),covA,covB,mesh.world,scene.view,scene.projection,uniforms.focal,uniforms.invViewport);
212
+ #include<clipPlaneVertex>
213
+ #include<fogVertex>
214
+ #include<logDepthVertex>
215
+ }
216
+ `;
217
+ // Sideeffect
218
+ ShaderStore.ShadersStoreWGSL[name] = shader;
219
+ /** @internal */
220
+ const gaussianSplattingVertexShaderWGSL = { name, shader };
221
+
222
+ var gaussianSplatting_vertex = /*#__PURE__*/Object.freeze({
223
+ __proto__: null,
224
+ gaussianSplattingVertexShaderWGSL: gaussianSplattingVertexShaderWGSL
225
+ });
226
+
227
+ /**
228
+ * @internal
229
+ */
230
+ class GaussianSplattingMaterialDefines extends MaterialDefines {
231
+ /**
232
+ * Constructor of the defines.
233
+ */
234
+ constructor() {
235
+ super();
236
+ this.FOG = false;
237
+ this.THIN_INSTANCES = true;
238
+ this.LOGARITHMICDEPTH = false;
239
+ this.CLIPPLANE = false;
240
+ this.CLIPPLANE2 = false;
241
+ this.CLIPPLANE3 = false;
242
+ this.CLIPPLANE4 = false;
243
+ this.CLIPPLANE5 = false;
244
+ this.CLIPPLANE6 = false;
245
+ this.rebuild();
246
+ }
247
+ }
248
+ /**
249
+ * GaussianSplattingMaterial material used to render Gaussian Splatting
250
+ * @experimental
251
+ */
252
+ class GaussianSplattingMaterial extends PushMaterial {
253
+ /**
254
+ * Instantiates a Gaussian Splatting Material in the given scene
255
+ * @param name The friendly name of the material
256
+ * @param scene The scene to add the material to
257
+ */
258
+ constructor(name, scene) {
259
+ super(name, scene);
260
+ this.backFaceCulling = false;
261
+ }
262
+ /**
263
+ * Gets a boolean indicating that current material needs to register RTT
264
+ */
265
+ get hasRenderTargetTextures() {
266
+ return false;
267
+ }
268
+ /**
269
+ * Specifies whether or not this material should be rendered in alpha test mode.
270
+ * @returns false
271
+ */
272
+ needAlphaTesting() {
273
+ return false;
274
+ }
275
+ /**
276
+ * Specifies whether or not this material should be rendered in alpha blend mode.
277
+ * @returns true
278
+ */
279
+ needAlphaBlending() {
280
+ return true;
281
+ }
282
+ /**
283
+ * Checks whether the material is ready to be rendered for a given mesh.
284
+ * @param mesh The mesh to render
285
+ * @param subMesh The submesh to check against
286
+ * @returns true if all the dependencies are ready (Textures, Effects...)
287
+ */
288
+ isReadyForSubMesh(mesh, subMesh) {
289
+ const useInstances = true;
290
+ const drawWrapper = subMesh._drawWrapper;
291
+ if (drawWrapper.effect && this.isFrozen) {
292
+ if (drawWrapper._wasPreviouslyReady && drawWrapper._wasPreviouslyUsingInstances === useInstances) {
293
+ return true;
294
+ }
295
+ }
296
+ if (!subMesh.materialDefines) {
297
+ subMesh.materialDefines = new GaussianSplattingMaterialDefines();
298
+ }
299
+ const scene = this.getScene();
300
+ const defines = subMesh.materialDefines;
301
+ if (this._isReadyForSubMesh(subMesh)) {
302
+ return true;
303
+ }
304
+ const engine = scene.getEngine();
305
+ // Misc.
306
+ PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, false, defines);
307
+ // Values that need to be evaluated on every frame
308
+ PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances, null, true);
309
+ // Attribs
310
+ PrepareDefinesForAttributes(mesh, defines, false, false);
311
+ // Get correct effect
312
+ if (defines.isDirty) {
313
+ defines.markAsProcessed();
314
+ scene.resetCachedMaterial();
315
+ //Attributes
316
+ const attribs = [VertexBuffer.PositionKind, "splatIndex"];
317
+ PrepareAttributesForInstances(attribs, defines);
318
+ const uniforms = ["world", "view", "projection", "vFogInfos", "vFogColor", "logarithmicDepthConstant", "invViewport", "dataTextureSize", "focal"];
319
+ const samplers = ["covariancesATexture", "covariancesBTexture", "centersTexture", "colorsTexture"];
320
+ const uniformBuffers = ["Scene", "Mesh"];
321
+ PrepareUniformsAndSamplersList({
322
+ uniformsNames: uniforms,
323
+ uniformBuffersNames: uniformBuffers,
324
+ samplers: samplers,
325
+ defines: defines,
326
+ });
327
+ addClipPlaneUniforms(uniforms);
328
+ const join = defines.toString();
329
+ const effect = scene.getEngine().createEffect("gaussianSplatting", {
330
+ attributes: attribs,
331
+ uniformsNames: uniforms,
332
+ uniformBuffersNames: uniformBuffers,
333
+ samplers: samplers,
334
+ defines: join,
335
+ onCompiled: this.onCompiled,
336
+ onError: this.onError,
337
+ indexParameters: {},
338
+ shaderLanguage: this._shaderLanguage,
339
+ extraInitializationsAsync: async () => {
340
+ if (this._shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
341
+ await Promise.all([Promise.resolve().then(function () { return gaussianSplatting_fragment; }), Promise.resolve().then(function () { return gaussianSplatting_vertex; })]);
342
+ }
343
+ else {
344
+ await Promise.all([Promise.resolve().then(function () { return gaussianSplatting_fragment$1; }), Promise.resolve().then(function () { return gaussianSplatting_vertex$1; })]);
345
+ }
346
+ },
347
+ }, engine);
348
+ subMesh.setEffect(effect, defines, this._materialContext);
349
+ }
350
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
351
+ return false;
352
+ }
353
+ defines._renderId = scene.getRenderId();
354
+ drawWrapper._wasPreviouslyReady = true;
355
+ drawWrapper._wasPreviouslyUsingInstances = useInstances;
356
+ return true;
357
+ }
358
+ /**
359
+ * Bind material effect for a specific Gaussian Splatting mesh
360
+ * @param mesh Gaussian splatting mesh
361
+ * @param effect Splatting material or node material
362
+ * @param scene scene that contains mesh and camera used for rendering
363
+ */
364
+ static BindEffect(mesh, effect, scene) {
365
+ const engine = scene.getEngine();
366
+ const camera = scene.activeCamera;
367
+ const renderWidth = engine.getRenderWidth();
368
+ const renderHeight = engine.getRenderHeight();
369
+ // check if rigcamera, get number of rigs
370
+ const numberOfRigs = camera?.rigParent?.rigCameras.length || 1;
371
+ effect.setFloat2("invViewport", 1 / (renderWidth / numberOfRigs), 1 / renderHeight);
372
+ let focal = 1000;
373
+ if (camera) {
374
+ /*
375
+ more explicit version:
376
+ const t = camera.getProjectionMatrix().m[5];
377
+ const FovY = Math.atan(1.0 / t) * 2.0;
378
+ focal = renderHeight / 2.0 / Math.tan(FovY / 2.0);
379
+ Using a shorter version here to not have tan(atan) and 2.0 factor
380
+ */
381
+ const t = camera.getProjectionMatrix().m[5];
382
+ if (camera.fovMode == Camera.FOVMODE_VERTICAL_FIXED) {
383
+ focal = (renderHeight * t) / 2.0;
384
+ }
385
+ else {
386
+ focal = (renderWidth * t) / 2.0;
387
+ }
388
+ }
389
+ effect.setFloat2("focal", focal, focal);
390
+ const gsMesh = mesh;
391
+ if (gsMesh.covariancesATexture) {
392
+ const textureSize = gsMesh.covariancesATexture.getSize();
393
+ effect.setFloat2("dataTextureSize", textureSize.width, textureSize.height);
394
+ effect.setTexture("covariancesATexture", gsMesh.covariancesATexture);
395
+ effect.setTexture("covariancesBTexture", gsMesh.covariancesBTexture);
396
+ effect.setTexture("centersTexture", gsMesh.centersTexture);
397
+ effect.setTexture("colorsTexture", gsMesh.colorsTexture);
398
+ }
399
+ }
400
+ /**
401
+ * Binds the submesh to this material by preparing the effect and shader to draw
402
+ * @param world defines the world transformation matrix
403
+ * @param mesh defines the mesh containing the submesh
404
+ * @param subMesh defines the submesh to bind the material to
405
+ */
406
+ bindForSubMesh(world, mesh, subMesh) {
407
+ const scene = this.getScene();
408
+ const defines = subMesh.materialDefines;
409
+ if (!defines) {
410
+ return;
411
+ }
412
+ const effect = subMesh.effect;
413
+ if (!effect) {
414
+ return;
415
+ }
416
+ this._activeEffect = effect;
417
+ // Matrices Mesh.
418
+ mesh.getMeshUniformBuffer().bindToEffect(effect, "Mesh");
419
+ mesh.transferToEffect(world);
420
+ // Bind data
421
+ const mustRebind = this._mustRebind(scene, effect, subMesh, mesh.visibility);
422
+ if (mustRebind) {
423
+ this.bindView(effect);
424
+ this.bindViewProjection(effect);
425
+ GaussianSplattingMaterial.BindEffect(mesh, this._activeEffect, scene);
426
+ // Clip plane
427
+ bindClipPlane(effect, this, scene);
428
+ }
429
+ else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {
430
+ this._needToBindSceneUbo = true;
431
+ }
432
+ // Fog
433
+ BindFogParameters(scene, mesh, effect);
434
+ // Log. depth
435
+ if (this.useLogarithmicDepth) {
436
+ BindLogDepth(defines, effect, scene);
437
+ }
438
+ this._afterBind(mesh, this._activeEffect, subMesh);
439
+ }
440
+ /**
441
+ * Clones the material.
442
+ * @param name The cloned name.
443
+ * @returns The cloned material.
444
+ */
445
+ clone(name) {
446
+ return SerializationHelper.Clone(() => new GaussianSplattingMaterial(name, this.getScene()), this);
447
+ }
448
+ /**
449
+ * Serializes the current material to its JSON representation.
450
+ * @returns The JSON representation.
451
+ */
452
+ serialize() {
453
+ const serializationObject = super.serialize();
454
+ serializationObject.customType = "BABYLON.GaussianSplattingMaterial";
455
+ return serializationObject;
456
+ }
457
+ /**
458
+ * Gets the class name of the material
459
+ * @returns "GaussianSplattingMaterial"
460
+ */
461
+ getClassName() {
462
+ return "GaussianSplattingMaterial";
463
+ }
464
+ /**
465
+ * Parse a JSON input to create back a Gaussian Splatting material.
466
+ * @param source The JSON data to parse
467
+ * @param scene The scene to create the parsed material in
468
+ * @param rootUrl The root url of the assets the material depends upon
469
+ * @returns the instantiated GaussianSplattingMaterial.
470
+ */
471
+ static Parse(source, scene, rootUrl) {
472
+ return SerializationHelper.Parse(() => new GaussianSplattingMaterial(source.name, scene), source, scene, rootUrl);
473
+ }
474
+ }
475
+ RegisterClass("BABYLON.GaussianSplattingMaterial", GaussianSplattingMaterial);
476
+
477
+ const HCF = HighestCommonFactor;
478
+ /**
479
+ * Scalar computation library
480
+ * @deprecated Please use the scalar functions
481
+ */
482
+ /* eslint-disable @typescript-eslint/naming-convention */
483
+ const Scalar = {
484
+ ...functions,
485
+ /**
486
+ * Two pi constants convenient for computation.
487
+ */
488
+ TwoPi: Math.PI * 2,
489
+ /**
490
+ * Returns -1 if value is negative and +1 is value is positive.
491
+ * @param value the value
492
+ * @returns the value itself if it's equal to zero.
493
+ */
494
+ Sign: Math.sign,
495
+ /**
496
+ * the log2 of value.
497
+ * @param value the value to compute log2 of
498
+ * @returns the log2 of value.
499
+ */
500
+ Log2: Math.log2,
501
+ /**
502
+ * Returns the highest common factor of two integers.
503
+ * @param a first parameter
504
+ * @param b second parameter
505
+ * @returns HCF of a and b
506
+ */
507
+ HCF,
508
+ };
509
+ /* eslint-enable @typescript-eslint/naming-convention */
510
+
511
+ // @internal
512
+ const unpackUnorm = (value, bits) => {
513
+ const t = (1 << bits) - 1;
514
+ return (value & t) / t;
515
+ };
516
+ // @internal
517
+ const unpack111011 = (value, result) => {
518
+ result.x = unpackUnorm(value >>> 21, 11);
519
+ result.y = unpackUnorm(value >>> 11, 10);
520
+ result.z = unpackUnorm(value, 11);
521
+ };
522
+ // @internal
523
+ const unpack8888 = (value, result) => {
524
+ result[0] = unpackUnorm(value >>> 24, 8) * 255;
525
+ result[1] = unpackUnorm(value >>> 16, 8) * 255;
526
+ result[2] = unpackUnorm(value >>> 8, 8) * 255;
527
+ result[3] = unpackUnorm(value, 8) * 255;
528
+ };
529
+ // @internal
530
+ // unpack quaternion with 2,10,10,10 format (largest element, 3x10bit element)
531
+ const unpackRot = (value, result) => {
532
+ const norm = 1.0 / (Math.sqrt(2) * 0.5);
533
+ const a = (unpackUnorm(value >>> 20, 10) - 0.5) * norm;
534
+ const b = (unpackUnorm(value >>> 10, 10) - 0.5) * norm;
535
+ const c = (unpackUnorm(value, 10) - 0.5) * norm;
536
+ const m = Math.sqrt(1.0 - (a * a + b * b + c * c));
537
+ switch (value >>> 30) {
538
+ case 0:
539
+ result.set(m, a, b, c);
540
+ break;
541
+ case 1:
542
+ result.set(a, m, b, c);
543
+ break;
544
+ case 2:
545
+ result.set(a, b, m, c);
546
+ break;
547
+ case 3:
548
+ result.set(a, b, c, m);
549
+ break;
550
+ }
551
+ };
552
+ /**
553
+ * Representation of the types
554
+ */
555
+ var PLYType;
556
+ (function (PLYType) {
557
+ PLYType[PLYType["FLOAT"] = 0] = "FLOAT";
558
+ PLYType[PLYType["INT"] = 1] = "INT";
559
+ PLYType[PLYType["UINT"] = 2] = "UINT";
560
+ PLYType[PLYType["DOUBLE"] = 3] = "DOUBLE";
561
+ PLYType[PLYType["UCHAR"] = 4] = "UCHAR";
562
+ PLYType[PLYType["UNDEFINED"] = 5] = "UNDEFINED";
563
+ })(PLYType || (PLYType = {}));
564
+ /**
565
+ * Usage types of the PLY values
566
+ */
567
+ var PLYValue;
568
+ (function (PLYValue) {
569
+ PLYValue[PLYValue["MIN_X"] = 0] = "MIN_X";
570
+ PLYValue[PLYValue["MIN_Y"] = 1] = "MIN_Y";
571
+ PLYValue[PLYValue["MIN_Z"] = 2] = "MIN_Z";
572
+ PLYValue[PLYValue["MAX_X"] = 3] = "MAX_X";
573
+ PLYValue[PLYValue["MAX_Y"] = 4] = "MAX_Y";
574
+ PLYValue[PLYValue["MAX_Z"] = 5] = "MAX_Z";
575
+ PLYValue[PLYValue["MIN_SCALE_X"] = 6] = "MIN_SCALE_X";
576
+ PLYValue[PLYValue["MIN_SCALE_Y"] = 7] = "MIN_SCALE_Y";
577
+ PLYValue[PLYValue["MIN_SCALE_Z"] = 8] = "MIN_SCALE_Z";
578
+ PLYValue[PLYValue["MAX_SCALE_X"] = 9] = "MAX_SCALE_X";
579
+ PLYValue[PLYValue["MAX_SCALE_Y"] = 10] = "MAX_SCALE_Y";
580
+ PLYValue[PLYValue["MAX_SCALE_Z"] = 11] = "MAX_SCALE_Z";
581
+ PLYValue[PLYValue["PACKED_POSITION"] = 12] = "PACKED_POSITION";
582
+ PLYValue[PLYValue["PACKED_ROTATION"] = 13] = "PACKED_ROTATION";
583
+ PLYValue[PLYValue["PACKED_SCALE"] = 14] = "PACKED_SCALE";
584
+ PLYValue[PLYValue["PACKED_COLOR"] = 15] = "PACKED_COLOR";
585
+ PLYValue[PLYValue["X"] = 16] = "X";
586
+ PLYValue[PLYValue["Y"] = 17] = "Y";
587
+ PLYValue[PLYValue["Z"] = 18] = "Z";
588
+ PLYValue[PLYValue["SCALE_0"] = 19] = "SCALE_0";
589
+ PLYValue[PLYValue["SCALE_1"] = 20] = "SCALE_1";
590
+ PLYValue[PLYValue["SCALE_2"] = 21] = "SCALE_2";
591
+ PLYValue[PLYValue["DIFFUSE_RED"] = 22] = "DIFFUSE_RED";
592
+ PLYValue[PLYValue["DIFFUSE_GREEN"] = 23] = "DIFFUSE_GREEN";
593
+ PLYValue[PLYValue["DIFFUSE_BLUE"] = 24] = "DIFFUSE_BLUE";
594
+ PLYValue[PLYValue["OPACITY"] = 25] = "OPACITY";
595
+ PLYValue[PLYValue["F_DC_0"] = 26] = "F_DC_0";
596
+ PLYValue[PLYValue["F_DC_1"] = 27] = "F_DC_1";
597
+ PLYValue[PLYValue["F_DC_2"] = 28] = "F_DC_2";
598
+ PLYValue[PLYValue["F_DC_3"] = 29] = "F_DC_3";
599
+ PLYValue[PLYValue["ROT_0"] = 30] = "ROT_0";
600
+ PLYValue[PLYValue["ROT_1"] = 31] = "ROT_1";
601
+ PLYValue[PLYValue["ROT_2"] = 32] = "ROT_2";
602
+ PLYValue[PLYValue["ROT_3"] = 33] = "ROT_3";
603
+ PLYValue[PLYValue["UNDEFINED"] = 34] = "UNDEFINED";
604
+ })(PLYValue || (PLYValue = {}));
605
+ /**
606
+ * Class used to render a gaussian splatting mesh
607
+ */
608
+ class GaussianSplattingMesh extends Mesh {
609
+ /**
610
+ * Gets the covariancesA texture
611
+ */
612
+ get covariancesATexture() {
613
+ return this._covariancesATexture;
614
+ }
615
+ /**
616
+ * Gets the covariancesB texture
617
+ */
618
+ get covariancesBTexture() {
619
+ return this._covariancesBTexture;
620
+ }
621
+ /**
622
+ * Gets the centers texture
623
+ */
624
+ get centersTexture() {
625
+ return this._centersTexture;
626
+ }
627
+ /**
628
+ * Gets the colors texture
629
+ */
630
+ get colorsTexture() {
631
+ return this._colorsTexture;
632
+ }
633
+ /**
634
+ * set rendering material
635
+ */
636
+ set material(value) {
637
+ this._material = value;
638
+ this._material.backFaceCulling = true;
639
+ this._material.cullBackFaces = false;
640
+ value.resetDrawCache();
641
+ }
642
+ /**
643
+ * get rendering material
644
+ */
645
+ get material() {
646
+ return this._material;
647
+ }
648
+ /**
649
+ * Creates a new gaussian splatting mesh
650
+ * @param name defines the name of the mesh
651
+ * @param url defines the url to load from (optional)
652
+ * @param scene defines the hosting scene (optional)
653
+ * @param keepInRam keep datas in ram for editing purpose
654
+ */
655
+ constructor(name, url = null, scene = null, keepInRam = false) {
656
+ super(name, scene);
657
+ this._vertexCount = 0;
658
+ this._worker = null;
659
+ this._frameIdLastUpdate = -1;
660
+ this._modelViewMatrix = Matrix.Identity();
661
+ this._canPostToWorker = true;
662
+ this._readyToDisplay = false;
663
+ this._covariancesATexture = null;
664
+ this._covariancesBTexture = null;
665
+ this._centersTexture = null;
666
+ this._colorsTexture = null;
667
+ this._splatPositions = null;
668
+ this._splatIndex = null;
669
+ //@ts-expect-error
670
+ this._covariancesA = null;
671
+ //@ts-expect-error
672
+ this._covariancesB = null;
673
+ //@ts-expect-error
674
+ this._colors = null;
675
+ this._keepInRam = false;
676
+ this._delayedTextureUpdate = null;
677
+ this._oldDirection = new Vector3();
678
+ this._useRGBACovariants = false;
679
+ this._material = null;
680
+ this._tmpCovariances = [0, 0, 0, 0, 0, 0];
681
+ this._sortIsDirty = false;
682
+ const vertexData = new VertexData();
683
+ // Use an intanced quad or triangle. Triangle might be a bit faster because of less shader invocation but I didn't see any difference.
684
+ // Keeping both and use triangle for now.
685
+ // for quad, use following lines
686
+ //vertexData.positions = [-2, -2, 0, 2, -2, 0, 2, 2, 0, -2, 2, 0];
687
+ //vertexData.indices = [0, 1, 2, 0, 2, 3];
688
+ vertexData.positions = [-3, -2, 0, 3, -2, 0, 0, 4, 0];
689
+ vertexData.indices = [0, 1, 2];
690
+ vertexData.applyToMesh(this);
691
+ this.subMeshes = [];
692
+ // for quad, use following line
693
+ //new SubMesh(0, 0, 4, 0, 6, this);
694
+ new SubMesh(0, 0, 3, 0, 3, this);
695
+ this.setEnabled(false);
696
+ // webGL2 and webGPU support for RG texture with float16 is fine. not webGL1
697
+ this._useRGBACovariants = !this.getEngine().isWebGPU && this.getEngine().version === 1.0;
698
+ this._keepInRam = keepInRam;
699
+ if (url) {
700
+ this.loadFileAsync(url);
701
+ }
702
+ this._material = new GaussianSplattingMaterial(this.name + "_material", this._scene);
703
+ }
704
+ /**
705
+ * Returns the class name
706
+ * @returns "GaussianSplattingMesh"
707
+ */
708
+ getClassName() {
709
+ return "GaussianSplattingMesh";
710
+ }
711
+ /**
712
+ * Returns the total number of vertices (splats) within the mesh
713
+ * @returns the total number of vertices
714
+ */
715
+ getTotalVertices() {
716
+ return this._vertexCount;
717
+ }
718
+ /**
719
+ * Is this node ready to be used/rendered
720
+ * @param completeCheck defines if a complete check (including materials and lights) has to be done (false by default)
721
+ * @returns true when ready
722
+ */
723
+ isReady(completeCheck = false) {
724
+ if (!super.isReady(completeCheck, true)) {
725
+ return false;
726
+ }
727
+ if (!this._readyToDisplay) {
728
+ // mesh is ready when worker has done at least 1 sorting
729
+ this._postToWorker(true);
730
+ return false;
731
+ }
732
+ return true;
733
+ }
734
+ /** @internal */
735
+ _postToWorker(forced = false) {
736
+ const frameId = this.getScene().getFrameId();
737
+ if ((forced || frameId !== this._frameIdLastUpdate) && this._worker && this._scene.activeCamera && this._canPostToWorker) {
738
+ const cameraMatrix = this._scene.activeCamera.getViewMatrix();
739
+ this.getWorldMatrix().multiplyToRef(cameraMatrix, this._modelViewMatrix);
740
+ cameraMatrix.invertToRef(TmpVectors.Matrix[0]);
741
+ this.getWorldMatrix().multiplyToRef(TmpVectors.Matrix[0], TmpVectors.Matrix[1]);
742
+ Vector3.TransformNormalToRef(Vector3.Forward(this._scene.useRightHandedSystem), TmpVectors.Matrix[1], TmpVectors.Vector3[2]);
743
+ TmpVectors.Vector3[2].normalize();
744
+ const dot = Vector3.Dot(TmpVectors.Vector3[2], this._oldDirection);
745
+ if (forced || Math.abs(dot - 1) >= 0.01) {
746
+ this._oldDirection.copyFrom(TmpVectors.Vector3[2]);
747
+ this._frameIdLastUpdate = frameId;
748
+ this._canPostToWorker = false;
749
+ this._worker.postMessage({ view: this._modelViewMatrix.m, depthMix: this._depthMix, useRightHandedSystem: this._scene.useRightHandedSystem }, [
750
+ this._depthMix.buffer,
751
+ ]);
752
+ }
753
+ }
754
+ }
755
+ /**
756
+ * Triggers the draw call for the mesh. Usually, you don't need to call this method by your own because the mesh rendering is handled by the scene rendering manager
757
+ * @param subMesh defines the subMesh to render
758
+ * @param enableAlphaMode defines if alpha mode can be changed
759
+ * @param effectiveMeshReplacement defines an optional mesh used to provide info for the rendering
760
+ * @returns the current mesh
761
+ */
762
+ render(subMesh, enableAlphaMode, effectiveMeshReplacement) {
763
+ this._postToWorker();
764
+ return super.render(subMesh, enableAlphaMode, effectiveMeshReplacement);
765
+ }
766
+ static _TypeNameToEnum(name) {
767
+ switch (name) {
768
+ case "float":
769
+ return 0 /* PLYType.FLOAT */;
770
+ case "int":
771
+ return 1 /* PLYType.INT */;
772
+ case "uint":
773
+ return 2 /* PLYType.UINT */;
774
+ case "double":
775
+ return 3 /* PLYType.DOUBLE */;
776
+ case "uchar":
777
+ return 4 /* PLYType.UCHAR */;
778
+ }
779
+ return 5 /* PLYType.UNDEFINED */;
780
+ }
781
+ static _ValueNameToEnum(name) {
782
+ switch (name) {
783
+ case "min_x":
784
+ return 0 /* PLYValue.MIN_X */;
785
+ case "min_y":
786
+ return 1 /* PLYValue.MIN_Y */;
787
+ case "min_z":
788
+ return 2 /* PLYValue.MIN_Z */;
789
+ case "max_x":
790
+ return 3 /* PLYValue.MAX_X */;
791
+ case "max_y":
792
+ return 4 /* PLYValue.MAX_Y */;
793
+ case "max_z":
794
+ return 5 /* PLYValue.MAX_Z */;
795
+ case "min_scale_x":
796
+ return 6 /* PLYValue.MIN_SCALE_X */;
797
+ case "min_scale_y":
798
+ return 7 /* PLYValue.MIN_SCALE_Y */;
799
+ case "min_scale_z":
800
+ return 8 /* PLYValue.MIN_SCALE_Z */;
801
+ case "max_scale_x":
802
+ return 9 /* PLYValue.MAX_SCALE_X */;
803
+ case "max_scale_y":
804
+ return 10 /* PLYValue.MAX_SCALE_Y */;
805
+ case "max_scale_z":
806
+ return 11 /* PLYValue.MAX_SCALE_Z */;
807
+ case "packed_position":
808
+ return 12 /* PLYValue.PACKED_POSITION */;
809
+ case "packed_rotation":
810
+ return 13 /* PLYValue.PACKED_ROTATION */;
811
+ case "packed_scale":
812
+ return 14 /* PLYValue.PACKED_SCALE */;
813
+ case "packed_color":
814
+ return 15 /* PLYValue.PACKED_COLOR */;
815
+ case "x":
816
+ return 16 /* PLYValue.X */;
817
+ case "y":
818
+ return 17 /* PLYValue.Y */;
819
+ case "z":
820
+ return 18 /* PLYValue.Z */;
821
+ case "scale_0":
822
+ return 19 /* PLYValue.SCALE_0 */;
823
+ case "scale_1":
824
+ return 20 /* PLYValue.SCALE_1 */;
825
+ case "scale_2":
826
+ return 21 /* PLYValue.SCALE_2 */;
827
+ case "diffuse_red":
828
+ case "red":
829
+ return 22 /* PLYValue.DIFFUSE_RED */;
830
+ case "diffuse_green":
831
+ case "green":
832
+ return 23 /* PLYValue.DIFFUSE_GREEN */;
833
+ case "diffuse_blue":
834
+ case "blue":
835
+ return 24 /* PLYValue.DIFFUSE_BLUE */;
836
+ case "f_dc_0":
837
+ return 26 /* PLYValue.F_DC_0 */;
838
+ case "f_dc_1":
839
+ return 27 /* PLYValue.F_DC_1 */;
840
+ case "f_dc_2":
841
+ return 28 /* PLYValue.F_DC_2 */;
842
+ case "f_dc_3":
843
+ return 29 /* PLYValue.F_DC_3 */;
844
+ case "opacity":
845
+ return 25 /* PLYValue.OPACITY */;
846
+ case "rot_0":
847
+ return 30 /* PLYValue.ROT_0 */;
848
+ case "rot_1":
849
+ return 31 /* PLYValue.ROT_1 */;
850
+ case "rot_2":
851
+ return 32 /* PLYValue.ROT_2 */;
852
+ case "rot_3":
853
+ return 33 /* PLYValue.ROT_3 */;
854
+ }
855
+ return 34 /* PLYValue.UNDEFINED */;
856
+ }
857
+ /**
858
+ * Parse a PLY file header and returns metas infos on splats and chunks
859
+ * @param data the loaded buffer
860
+ * @returns a PLYHeader
861
+ */
862
+ static ParseHeader(data) {
863
+ const ubuf = new Uint8Array(data);
864
+ const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));
865
+ const headerEnd = "end_header\n";
866
+ const headerEndIndex = header.indexOf(headerEnd);
867
+ if (headerEndIndex < 0 || !header) {
868
+ // standard splat
869
+ return null;
870
+ }
871
+ const vertexCount = parseInt(/element vertex (\d+)\n/.exec(header)[1]);
872
+ const chunkElement = /element chunk (\d+)\n/.exec(header);
873
+ let chunkCount = 0;
874
+ if (chunkElement) {
875
+ chunkCount = parseInt(chunkElement[1]);
876
+ }
877
+ let rowVertexOffset = 0;
878
+ let rowChunkOffset = 0;
879
+ const offsets = {
880
+ double: 8,
881
+ int: 4,
882
+ uint: 4,
883
+ float: 4,
884
+ short: 2,
885
+ ushort: 2,
886
+ uchar: 1,
887
+ list: 0,
888
+ };
889
+ let ElementMode;
890
+ (function (ElementMode) {
891
+ ElementMode[ElementMode["Vertex"] = 0] = "Vertex";
892
+ ElementMode[ElementMode["Chunk"] = 1] = "Chunk";
893
+ })(ElementMode || (ElementMode = {}));
894
+ let chunkMode = 1 /* ElementMode.Chunk */;
895
+ const vertexProperties = [];
896
+ const chunkProperties = [];
897
+ const filtered = header.slice(0, headerEndIndex).split("\n");
898
+ for (const prop of filtered) {
899
+ if (prop.startsWith("property ")) {
900
+ const [, typeName, name] = prop.split(" ");
901
+ const value = GaussianSplattingMesh._ValueNameToEnum(name);
902
+ const type = GaussianSplattingMesh._TypeNameToEnum(typeName);
903
+ if (chunkMode == 1 /* ElementMode.Chunk */) {
904
+ chunkProperties.push({ value, type, offset: rowChunkOffset });
905
+ rowChunkOffset += offsets[typeName];
906
+ }
907
+ else if (chunkMode == 0 /* ElementMode.Vertex */) {
908
+ vertexProperties.push({ value, type, offset: rowVertexOffset });
909
+ rowVertexOffset += offsets[typeName];
910
+ }
911
+ if (!offsets[typeName]) {
912
+ Logger.Warn(`Unsupported property type: ${typeName}.`);
913
+ }
914
+ }
915
+ else if (prop.startsWith("element ")) {
916
+ const [, type] = prop.split(" ");
917
+ if (type == "chunk") {
918
+ chunkMode = 1 /* ElementMode.Chunk */;
919
+ }
920
+ else if (type == "vertex") {
921
+ chunkMode = 0 /* ElementMode.Vertex */;
922
+ }
923
+ }
924
+ }
925
+ const dataView = new DataView(data, headerEndIndex + headerEnd.length);
926
+ const buffer = new ArrayBuffer(GaussianSplattingMesh._RowOutputLength * vertexCount);
927
+ return {
928
+ vertexCount: vertexCount,
929
+ chunkCount: chunkCount,
930
+ rowVertexLength: rowVertexOffset,
931
+ rowChunkLength: rowChunkOffset,
932
+ vertexProperties: vertexProperties,
933
+ chunkProperties: chunkProperties,
934
+ dataView: dataView,
935
+ buffer: buffer,
936
+ };
937
+ }
938
+ static _GetCompressedChunks(header, offset) {
939
+ if (!header.chunkCount) {
940
+ return null;
941
+ }
942
+ const dataView = header.dataView;
943
+ const compressedChunks = new Array(header.chunkCount);
944
+ for (let i = 0; i < header.chunkCount; i++) {
945
+ const currentChunk = { min: new Vector3(), max: new Vector3(), minScale: new Vector3(), maxScale: new Vector3() };
946
+ compressedChunks[i] = currentChunk;
947
+ for (let propertyIndex = 0; propertyIndex < header.chunkProperties.length; propertyIndex++) {
948
+ const property = header.chunkProperties[propertyIndex];
949
+ let value;
950
+ switch (property.type) {
951
+ case 0 /* PLYType.FLOAT */:
952
+ value = dataView.getFloat32(property.offset + offset.value, true);
953
+ break;
954
+ default:
955
+ continue;
956
+ }
957
+ switch (property.value) {
958
+ case 0 /* PLYValue.MIN_X */:
959
+ currentChunk.min.x = value;
960
+ break;
961
+ case 1 /* PLYValue.MIN_Y */:
962
+ currentChunk.min.y = value;
963
+ break;
964
+ case 2 /* PLYValue.MIN_Z */:
965
+ currentChunk.min.z = value;
966
+ break;
967
+ case 3 /* PLYValue.MAX_X */:
968
+ currentChunk.max.x = value;
969
+ break;
970
+ case 4 /* PLYValue.MAX_Y */:
971
+ currentChunk.max.y = value;
972
+ break;
973
+ case 5 /* PLYValue.MAX_Z */:
974
+ currentChunk.max.z = value;
975
+ break;
976
+ case 6 /* PLYValue.MIN_SCALE_X */:
977
+ currentChunk.minScale.x = value;
978
+ break;
979
+ case 7 /* PLYValue.MIN_SCALE_Y */:
980
+ currentChunk.minScale.y = value;
981
+ break;
982
+ case 8 /* PLYValue.MIN_SCALE_Z */:
983
+ currentChunk.minScale.z = value;
984
+ break;
985
+ case 9 /* PLYValue.MAX_SCALE_X */:
986
+ currentChunk.maxScale.x = value;
987
+ break;
988
+ case 10 /* PLYValue.MAX_SCALE_Y */:
989
+ currentChunk.maxScale.y = value;
990
+ break;
991
+ case 11 /* PLYValue.MAX_SCALE_Z */:
992
+ currentChunk.maxScale.z = value;
993
+ break;
994
+ }
995
+ }
996
+ offset.value += header.rowChunkLength;
997
+ }
998
+ return compressedChunks;
999
+ }
1000
+ static _GetSplat(header, index, compressedChunks, offset) {
1001
+ const q = TmpVectors.Quaternion[0];
1002
+ const temp3 = TmpVectors.Vector3[0];
1003
+ const rowOutputLength = GaussianSplattingMesh._RowOutputLength;
1004
+ const buffer = header.buffer;
1005
+ const dataView = header.dataView;
1006
+ const position = new Float32Array(buffer, index * rowOutputLength, 3);
1007
+ const scale = new Float32Array(buffer, index * rowOutputLength + 12, 3);
1008
+ const rgba = new Uint8ClampedArray(buffer, index * rowOutputLength + 24, 4);
1009
+ const rot = new Uint8ClampedArray(buffer, index * rowOutputLength + 28, 4);
1010
+ const chunkIndex = index >> 8;
1011
+ let r0 = 255;
1012
+ let r1 = 0;
1013
+ let r2 = 0;
1014
+ let r3 = 0;
1015
+ for (let propertyIndex = 0; propertyIndex < header.vertexProperties.length; propertyIndex++) {
1016
+ const property = header.vertexProperties[propertyIndex];
1017
+ let value;
1018
+ switch (property.type) {
1019
+ case 0 /* PLYType.FLOAT */:
1020
+ value = dataView.getFloat32(offset.value + property.offset, true);
1021
+ break;
1022
+ case 1 /* PLYType.INT */:
1023
+ value = dataView.getInt32(offset.value + property.offset, true);
1024
+ break;
1025
+ case 2 /* PLYType.UINT */:
1026
+ value = dataView.getUint32(offset.value + property.offset, true);
1027
+ break;
1028
+ case 3 /* PLYType.DOUBLE */:
1029
+ value = dataView.getFloat64(offset.value + property.offset, true);
1030
+ break;
1031
+ case 4 /* PLYType.UCHAR */:
1032
+ value = dataView.getUint8(offset.value + property.offset);
1033
+ break;
1034
+ default:
1035
+ continue;
1036
+ }
1037
+ switch (property.value) {
1038
+ case 12 /* PLYValue.PACKED_POSITION */:
1039
+ {
1040
+ const compressedChunk = compressedChunks[chunkIndex];
1041
+ unpack111011(value, temp3);
1042
+ position[0] = Scalar.Lerp(compressedChunk.min.x, compressedChunk.max.x, temp3.x);
1043
+ position[1] = -Scalar.Lerp(compressedChunk.min.y, compressedChunk.max.y, temp3.y);
1044
+ position[2] = Scalar.Lerp(compressedChunk.min.z, compressedChunk.max.z, temp3.z);
1045
+ }
1046
+ break;
1047
+ case 13 /* PLYValue.PACKED_ROTATION */:
1048
+ {
1049
+ unpackRot(value, q);
1050
+ r0 = q.w;
1051
+ r1 = q.z;
1052
+ r2 = q.y;
1053
+ r3 = q.x;
1054
+ }
1055
+ break;
1056
+ case 14 /* PLYValue.PACKED_SCALE */:
1057
+ {
1058
+ const compressedChunk = compressedChunks[chunkIndex];
1059
+ unpack111011(value, temp3);
1060
+ scale[0] = Math.exp(Scalar.Lerp(compressedChunk.minScale.x, compressedChunk.maxScale.x, temp3.x));
1061
+ scale[1] = Math.exp(Scalar.Lerp(compressedChunk.minScale.y, compressedChunk.maxScale.y, temp3.y));
1062
+ scale[2] = Math.exp(Scalar.Lerp(compressedChunk.minScale.z, compressedChunk.maxScale.z, temp3.z));
1063
+ }
1064
+ break;
1065
+ case 15 /* PLYValue.PACKED_COLOR */:
1066
+ unpack8888(value, rgba);
1067
+ break;
1068
+ case 16 /* PLYValue.X */:
1069
+ position[0] = value;
1070
+ break;
1071
+ case 17 /* PLYValue.Y */:
1072
+ position[1] = value;
1073
+ break;
1074
+ case 18 /* PLYValue.Z */:
1075
+ position[2] = value;
1076
+ break;
1077
+ case 19 /* PLYValue.SCALE_0 */:
1078
+ scale[0] = Math.exp(value);
1079
+ break;
1080
+ case 20 /* PLYValue.SCALE_1 */:
1081
+ scale[1] = Math.exp(value);
1082
+ break;
1083
+ case 21 /* PLYValue.SCALE_2 */:
1084
+ scale[2] = Math.exp(value);
1085
+ break;
1086
+ case 22 /* PLYValue.DIFFUSE_RED */:
1087
+ rgba[0] = value;
1088
+ break;
1089
+ case 23 /* PLYValue.DIFFUSE_GREEN */:
1090
+ rgba[1] = value;
1091
+ break;
1092
+ case 24 /* PLYValue.DIFFUSE_BLUE */:
1093
+ rgba[2] = value;
1094
+ break;
1095
+ case 26 /* PLYValue.F_DC_0 */:
1096
+ rgba[0] = (0.5 + GaussianSplattingMesh._SH_C0 * value) * 255;
1097
+ break;
1098
+ case 27 /* PLYValue.F_DC_1 */:
1099
+ rgba[1] = (0.5 + GaussianSplattingMesh._SH_C0 * value) * 255;
1100
+ break;
1101
+ case 28 /* PLYValue.F_DC_2 */:
1102
+ rgba[2] = (0.5 + GaussianSplattingMesh._SH_C0 * value) * 255;
1103
+ break;
1104
+ case 29 /* PLYValue.F_DC_3 */:
1105
+ rgba[3] = (0.5 + GaussianSplattingMesh._SH_C0 * value) * 255;
1106
+ break;
1107
+ case 25 /* PLYValue.OPACITY */:
1108
+ rgba[3] = (1 / (1 + Math.exp(-value))) * 255;
1109
+ break;
1110
+ case 30 /* PLYValue.ROT_0 */:
1111
+ r0 = value;
1112
+ break;
1113
+ case 31 /* PLYValue.ROT_1 */:
1114
+ r1 = value;
1115
+ break;
1116
+ case 32 /* PLYValue.ROT_2 */:
1117
+ r2 = value;
1118
+ break;
1119
+ case 33 /* PLYValue.ROT_3 */:
1120
+ r3 = value;
1121
+ break;
1122
+ }
1123
+ }
1124
+ q.set(r1, r2, r3, r0);
1125
+ q.normalize();
1126
+ rot[0] = q.w * 128 + 128;
1127
+ rot[1] = q.x * 128 + 128;
1128
+ rot[2] = q.y * 128 + 128;
1129
+ rot[3] = q.z * 128 + 128;
1130
+ offset.value += header.rowVertexLength;
1131
+ }
1132
+ /**
1133
+ * Converts a .ply data array buffer to splat
1134
+ * if data array buffer is not ply, returns the original buffer
1135
+ * @param data the .ply data to load
1136
+ * @param useCoroutine use coroutine and yield
1137
+ * @returns the loaded splat buffer
1138
+ */
1139
+ static *ConvertPLYToSplat(data, useCoroutine = false) {
1140
+ const header = GaussianSplattingMesh.ParseHeader(data);
1141
+ if (!header) {
1142
+ return data;
1143
+ }
1144
+ const offset = { value: 0 };
1145
+ const compressedChunks = GaussianSplattingMesh._GetCompressedChunks(header, offset);
1146
+ for (let i = 0; i < header.vertexCount; i++) {
1147
+ GaussianSplattingMesh._GetSplat(header, i, compressedChunks, offset);
1148
+ if (i % GaussianSplattingMesh._PlyConversionBatchSize === 0 && useCoroutine) {
1149
+ yield;
1150
+ }
1151
+ }
1152
+ return header.buffer;
1153
+ }
1154
+ /**
1155
+ * Converts a .ply data array buffer to splat
1156
+ * if data array buffer is not ply, returns the original buffer
1157
+ * @param data the .ply data to load
1158
+ * @returns the loaded splat buffer
1159
+ */
1160
+ static async ConvertPLYToSplatAsync(data) {
1161
+ return runCoroutineAsync(GaussianSplattingMesh.ConvertPLYToSplat(data, true), createYieldingScheduler());
1162
+ }
1163
+ /**
1164
+ * Loads a .splat Gaussian Splatting array buffer asynchronously
1165
+ * @param data arraybuffer containing splat file
1166
+ * @returns a promise that resolves when the operation is complete
1167
+ */
1168
+ loadDataAsync(data) {
1169
+ return this.updateDataAsync(data);
1170
+ }
1171
+ /**
1172
+ * Loads a .splat Gaussian or .ply Splatting file asynchronously
1173
+ * @param url path to the splat file to load
1174
+ * @returns a promise that resolves when the operation is complete
1175
+ * @deprecated Please use SceneLoader.ImportMeshAsync instead
1176
+ */
1177
+ loadFileAsync(url) {
1178
+ return Tools.LoadFileAsync(url, true).then(async (plyBuffer) => {
1179
+ GaussianSplattingMesh.ConvertPLYToSplatAsync(plyBuffer).then((splatsData) => {
1180
+ this.updateDataAsync(splatsData);
1181
+ });
1182
+ });
1183
+ }
1184
+ /**
1185
+ * Releases resources associated with this mesh.
1186
+ * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
1187
+ */
1188
+ dispose(doNotRecurse) {
1189
+ this._covariancesATexture?.dispose();
1190
+ this._covariancesBTexture?.dispose();
1191
+ this._centersTexture?.dispose();
1192
+ this._colorsTexture?.dispose();
1193
+ this._covariancesATexture = null;
1194
+ this._covariancesBTexture = null;
1195
+ this._centersTexture = null;
1196
+ this._colorsTexture = null;
1197
+ this._worker?.terminate();
1198
+ this._worker = null;
1199
+ super.dispose(doNotRecurse, true);
1200
+ }
1201
+ _copyTextures(source) {
1202
+ this._covariancesATexture = source.covariancesATexture?.clone();
1203
+ this._covariancesBTexture = source.covariancesBTexture?.clone();
1204
+ this._centersTexture = source.centersTexture?.clone();
1205
+ this._colorsTexture = source.colorsTexture?.clone();
1206
+ }
1207
+ /**
1208
+ * Returns a new Mesh object generated from the current mesh properties.
1209
+ * @param name is a string, the name given to the new mesh
1210
+ * @returns a new Gaussian Splatting Mesh
1211
+ */
1212
+ clone(name = "") {
1213
+ const newGS = new GaussianSplattingMesh(name, undefined, this.getScene());
1214
+ newGS._copySource(this);
1215
+ newGS.makeGeometryUnique();
1216
+ newGS._vertexCount = this._vertexCount;
1217
+ newGS._copyTextures(this);
1218
+ newGS._modelViewMatrix = Matrix.Identity();
1219
+ newGS._splatPositions = this._splatPositions;
1220
+ newGS._readyToDisplay = false;
1221
+ newGS._instanciateWorker();
1222
+ const binfo = this.getBoundingInfo();
1223
+ newGS.getBoundingInfo().reConstruct(binfo.minimum, binfo.maximum, this.getWorldMatrix());
1224
+ newGS.forcedInstanceCount = newGS._vertexCount;
1225
+ newGS.setEnabled(true);
1226
+ return newGS;
1227
+ }
1228
+ _makeSplat(sourceIndex, destinationIndex, fBuffer, uBuffer, covA, covB, colorArray, minimum, maximum) {
1229
+ const matrixRotation = TmpVectors.Matrix[0];
1230
+ const matrixScale = TmpVectors.Matrix[1];
1231
+ const quaternion = TmpVectors.Quaternion[0];
1232
+ const covBSItemSize = this._useRGBACovariants ? 4 : 2;
1233
+ const x = fBuffer[8 * sourceIndex + 0];
1234
+ const y = -fBuffer[8 * sourceIndex + 1];
1235
+ const z = fBuffer[8 * sourceIndex + 2];
1236
+ this._splatPositions[4 * sourceIndex + 0] = x;
1237
+ this._splatPositions[4 * sourceIndex + 1] = y;
1238
+ this._splatPositions[4 * sourceIndex + 2] = z;
1239
+ minimum.minimizeInPlaceFromFloats(x, y, z);
1240
+ maximum.maximizeInPlaceFromFloats(x, y, z);
1241
+ quaternion.set((uBuffer[32 * sourceIndex + 28 + 1] - 128) / 128, (uBuffer[32 * sourceIndex + 28 + 2] - 128) / 128, (uBuffer[32 * sourceIndex + 28 + 3] - 128) / 128, -(uBuffer[32 * sourceIndex + 28 + 0] - 128) / 128);
1242
+ quaternion.toRotationMatrix(matrixRotation);
1243
+ Matrix.ScalingToRef(fBuffer[8 * sourceIndex + 3 + 0] * 2, fBuffer[8 * sourceIndex + 3 + 1] * 2, fBuffer[8 * sourceIndex + 3 + 2] * 2, matrixScale);
1244
+ const M = matrixRotation.multiplyToRef(matrixScale, TmpVectors.Matrix[0]).m;
1245
+ const covariances = this._tmpCovariances;
1246
+ covariances[0] = M[0] * M[0] + M[1] * M[1] + M[2] * M[2];
1247
+ covariances[1] = M[0] * M[4] + M[1] * M[5] + M[2] * M[6];
1248
+ covariances[2] = M[0] * M[8] + M[1] * M[9] + M[2] * M[10];
1249
+ covariances[3] = M[4] * M[4] + M[5] * M[5] + M[6] * M[6];
1250
+ covariances[4] = M[4] * M[8] + M[5] * M[9] + M[6] * M[10];
1251
+ covariances[5] = M[8] * M[8] + M[9] * M[9] + M[10] * M[10];
1252
+ // normalize covA, covB
1253
+ let factor = -10000;
1254
+ for (let covIndex = 0; covIndex < 6; covIndex++) {
1255
+ factor = Math.max(factor, Math.abs(covariances[covIndex]));
1256
+ }
1257
+ this._splatPositions[4 * sourceIndex + 3] = factor;
1258
+ const transform = factor;
1259
+ covA[destinationIndex * 4 + 0] = ToHalfFloat(covariances[0] / transform);
1260
+ covA[destinationIndex * 4 + 1] = ToHalfFloat(covariances[1] / transform);
1261
+ covA[destinationIndex * 4 + 2] = ToHalfFloat(covariances[2] / transform);
1262
+ covA[destinationIndex * 4 + 3] = ToHalfFloat(covariances[3] / transform);
1263
+ covB[destinationIndex * covBSItemSize + 0] = ToHalfFloat(covariances[4] / transform);
1264
+ covB[destinationIndex * covBSItemSize + 1] = ToHalfFloat(covariances[5] / transform);
1265
+ // colors
1266
+ colorArray[destinationIndex * 4 + 0] = uBuffer[32 * sourceIndex + 24 + 0];
1267
+ colorArray[destinationIndex * 4 + 1] = uBuffer[32 * sourceIndex + 24 + 1];
1268
+ colorArray[destinationIndex * 4 + 2] = uBuffer[32 * sourceIndex + 24 + 2];
1269
+ colorArray[destinationIndex * 4 + 3] = uBuffer[32 * sourceIndex + 24 + 3];
1270
+ }
1271
+ _updateTextures(covA, covB, colorArray) {
1272
+ const textureSize = this._getTextureSize(this._vertexCount);
1273
+ // Update the textures
1274
+ const createTextureFromData = (data, width, height, format) => {
1275
+ return new RawTexture(data, width, height, format, this._scene, false, false, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, Constants.TEXTURETYPE_FLOAT);
1276
+ };
1277
+ const createTextureFromDataU8 = (data, width, height, format) => {
1278
+ return new RawTexture(data, width, height, format, this._scene, false, false, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, Constants.TEXTURETYPE_UNSIGNED_BYTE);
1279
+ };
1280
+ const createTextureFromDataF16 = (data, width, height, format) => {
1281
+ return new RawTexture(data, width, height, format, this._scene, false, false, Constants.TEXTURE_BILINEAR_SAMPLINGMODE, Constants.TEXTURETYPE_HALF_FLOAT);
1282
+ };
1283
+ if (this._keepInRam) {
1284
+ this._covariancesA = covA;
1285
+ this._covariancesB = covB;
1286
+ this._colors = colorArray;
1287
+ }
1288
+ if (this._covariancesATexture) {
1289
+ this._delayedTextureUpdate = { covA: covA, covB: covB, colors: colorArray, centers: this._splatPositions };
1290
+ const positions = Float32Array.from(this._splatPositions);
1291
+ const vertexCount = this._vertexCount;
1292
+ this._worker.postMessage({ positions, vertexCount }, [positions.buffer]);
1293
+ this._postToWorker(true);
1294
+ }
1295
+ else {
1296
+ this._covariancesATexture = createTextureFromDataF16(covA, textureSize.x, textureSize.y, Constants.TEXTUREFORMAT_RGBA);
1297
+ this._covariancesBTexture = createTextureFromDataF16(covB, textureSize.x, textureSize.y, this._useRGBACovariants ? Constants.TEXTUREFORMAT_RGBA : Constants.TEXTUREFORMAT_RG);
1298
+ this._centersTexture = createTextureFromData(this._splatPositions, textureSize.x, textureSize.y, Constants.TEXTUREFORMAT_RGBA);
1299
+ this._colorsTexture = createTextureFromDataU8(colorArray, textureSize.x, textureSize.y, Constants.TEXTUREFORMAT_RGBA);
1300
+ this._instanciateWorker();
1301
+ }
1302
+ }
1303
+ *_updateData(data, isAsync) {
1304
+ // if a covariance texture is present, then it's not a creation but an update
1305
+ if (!this._covariancesATexture) {
1306
+ this._readyToDisplay = false;
1307
+ }
1308
+ // Parse the data
1309
+ const uBuffer = new Uint8Array(data);
1310
+ const fBuffer = new Float32Array(uBuffer.buffer);
1311
+ const vertexCount = uBuffer.length / GaussianSplattingMesh._RowOutputLength;
1312
+ if (vertexCount != this._vertexCount) {
1313
+ this._updateSplatIndexBuffer(vertexCount);
1314
+ }
1315
+ this._vertexCount = vertexCount;
1316
+ const textureSize = this._getTextureSize(vertexCount);
1317
+ const textureLength = textureSize.x * textureSize.y;
1318
+ const lineCountUpdate = GaussianSplattingMesh.ProgressiveUpdateAmount ?? textureSize.y;
1319
+ const textureLengthPerUpdate = textureSize.x * lineCountUpdate;
1320
+ this._splatPositions = new Float32Array(4 * textureLength);
1321
+ const covA = new Uint16Array(textureLength * 4);
1322
+ const covB = new Uint16Array((this._useRGBACovariants ? 4 : 2) * textureLength);
1323
+ const colorArray = new Uint8Array(textureLength * 4);
1324
+ const minimum = new Vector3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
1325
+ const maximum = new Vector3(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
1326
+ if (GaussianSplattingMesh.ProgressiveUpdateAmount) {
1327
+ // create textures with not filled-yet array, then update directly portions of it
1328
+ this._updateTextures(covA, covB, colorArray);
1329
+ this.setEnabled(true);
1330
+ const partCount = Math.ceil(textureSize.y / lineCountUpdate);
1331
+ for (let partIndex = 0; partIndex < partCount; partIndex++) {
1332
+ const updateLine = partIndex * lineCountUpdate;
1333
+ const splatIndexBase = updateLine * textureSize.x;
1334
+ for (let i = 0; i < textureLengthPerUpdate; i++) {
1335
+ this._makeSplat(splatIndexBase + i, splatIndexBase + i, fBuffer, uBuffer, covA, covB, colorArray, minimum, maximum);
1336
+ }
1337
+ this._updateSubTextures(this._splatPositions, covA, covB, colorArray, updateLine, Math.min(lineCountUpdate, textureSize.y - updateLine));
1338
+ // Update the binfo
1339
+ this.getBoundingInfo().reConstruct(minimum, maximum, this.getWorldMatrix());
1340
+ if (isAsync) {
1341
+ yield;
1342
+ }
1343
+ }
1344
+ // sort will be dirty here as just finished filled positions will not be sorted
1345
+ const positions = Float32Array.from(this._splatPositions);
1346
+ const vertexCount = this._vertexCount;
1347
+ this._worker.postMessage({ positions, vertexCount }, [positions.buffer]);
1348
+ this._sortIsDirty = true;
1349
+ }
1350
+ else {
1351
+ for (let i = 0; i < vertexCount; i++) {
1352
+ this._makeSplat(i, i, fBuffer, uBuffer, covA, covB, colorArray, minimum, maximum);
1353
+ if (isAsync && i % GaussianSplattingMesh._SplatBatchSize === 0) {
1354
+ yield;
1355
+ }
1356
+ }
1357
+ // textures
1358
+ this._updateTextures(covA, covB, colorArray);
1359
+ // Update the binfo
1360
+ this.getBoundingInfo().reConstruct(minimum, maximum, this.getWorldMatrix());
1361
+ this.setEnabled(true);
1362
+ }
1363
+ this._postToWorker(true);
1364
+ }
1365
+ /**
1366
+ * Update asynchronously the buffer
1367
+ * @param data array buffer containing center, color, orientation and scale of splats
1368
+ * @returns a promise
1369
+ */
1370
+ async updateDataAsync(data) {
1371
+ return runCoroutineAsync(this._updateData(data, true), createYieldingScheduler());
1372
+ }
1373
+ /**
1374
+ * @experimental
1375
+ * Update data from GS (position, orientation, color, scaling)
1376
+ * @param data array that contain all the datas
1377
+ */
1378
+ updateData(data) {
1379
+ runCoroutineSync(this._updateData(data, false));
1380
+ }
1381
+ // in case size is different
1382
+ _updateSplatIndexBuffer(vertexCount) {
1383
+ if (!this._splatIndex || vertexCount > this._splatIndex.length) {
1384
+ this._splatIndex = new Float32Array(vertexCount);
1385
+ this.thinInstanceSetBuffer("splatIndex", this._splatIndex, 1, false);
1386
+ }
1387
+ this.forcedInstanceCount = vertexCount;
1388
+ }
1389
+ _updateSubTextures(centers, covA, covB, colors, lineStart, lineCount) {
1390
+ const updateTextureFromData = (texture, data, width, lineStart, lineCount) => {
1391
+ this.getEngine().updateTextureData(texture.getInternalTexture(), data, 0, lineStart, width, lineCount, 0, 0, false);
1392
+ };
1393
+ const updateTextureFromDataU8 = (texture, data, width, lineStart, lineCount) => {
1394
+ this.getEngine().updateTextureData(texture.getInternalTexture(), data, 0, lineStart, width, lineCount, 0, 0, false);
1395
+ };
1396
+ const updateTextureFromDataF16 = (texture, data, width, lineStart, lineCount) => {
1397
+ this.getEngine().updateTextureData(texture.getInternalTexture(), data, 0, lineStart, width, lineCount, 0, 0, false);
1398
+ };
1399
+ const textureSize = this._getTextureSize(this._vertexCount);
1400
+ const covBSItemSize = this._useRGBACovariants ? 4 : 2;
1401
+ const texelStart = lineStart * textureSize.x;
1402
+ const texelCount = lineCount * textureSize.x;
1403
+ const covAView = new Uint16Array(covA.buffer, texelStart * 4 * Uint16Array.BYTES_PER_ELEMENT, texelCount * 4);
1404
+ const covBView = new Uint16Array(covB.buffer, texelStart * covBSItemSize * Uint16Array.BYTES_PER_ELEMENT, texelCount * covBSItemSize);
1405
+ const colorsView = new Uint8Array(colors.buffer, texelStart * 4, texelCount * 4);
1406
+ const centersView = new Float32Array(centers.buffer, texelStart * 4 * Float32Array.BYTES_PER_ELEMENT, texelCount * 4);
1407
+ updateTextureFromDataF16(this._covariancesATexture, covAView, textureSize.x, lineStart, lineCount);
1408
+ updateTextureFromDataF16(this._covariancesBTexture, covBView, textureSize.x, lineStart, lineCount);
1409
+ updateTextureFromData(this._centersTexture, centersView, textureSize.x, lineStart, lineCount);
1410
+ updateTextureFromDataU8(this._colorsTexture, colorsView, textureSize.x, lineStart, lineCount);
1411
+ }
1412
+ _instanciateWorker() {
1413
+ if (!this._vertexCount) {
1414
+ return;
1415
+ }
1416
+ this._updateSplatIndexBuffer(this._vertexCount);
1417
+ // Start the worker thread
1418
+ this._worker?.terminate();
1419
+ this._worker = new Worker(URL.createObjectURL(new Blob(["(", GaussianSplattingMesh._CreateWorker.toString(), ")(self)"], {
1420
+ type: "application/javascript",
1421
+ })));
1422
+ this._depthMix = new BigInt64Array(this._vertexCount);
1423
+ const positions = Float32Array.from(this._splatPositions);
1424
+ const vertexCount = this._vertexCount;
1425
+ this._worker.postMessage({ positions, vertexCount }, [positions.buffer]);
1426
+ this._worker.onmessage = (e) => {
1427
+ this._depthMix = e.data.depthMix;
1428
+ const indexMix = new Uint32Array(e.data.depthMix.buffer);
1429
+ if (this._splatIndex) {
1430
+ for (let j = 0; j < this._vertexCount; j++) {
1431
+ this._splatIndex[j] = indexMix[2 * j];
1432
+ }
1433
+ }
1434
+ if (this._delayedTextureUpdate) {
1435
+ const textureSize = this._getTextureSize(vertexCount);
1436
+ this._updateSubTextures(this._delayedTextureUpdate.centers, this._delayedTextureUpdate.covA, this._delayedTextureUpdate.covB, this._delayedTextureUpdate.colors, 0, textureSize.y);
1437
+ this._delayedTextureUpdate = null;
1438
+ }
1439
+ this.thinInstanceBufferUpdated("splatIndex");
1440
+ this._canPostToWorker = true;
1441
+ this._readyToDisplay = true;
1442
+ // sort is dirty when GS is visible for progressive update with a this message arriving but positions were partially filled
1443
+ // another update needs to be kicked. The kick can't happen just when the position buffer is ready because _canPostToWorker might be false.
1444
+ if (this._sortIsDirty) {
1445
+ this._postToWorker(true);
1446
+ this._sortIsDirty = false;
1447
+ }
1448
+ };
1449
+ }
1450
+ _getTextureSize(length) {
1451
+ const engine = this._scene.getEngine();
1452
+ const width = engine.getCaps().maxTextureSize;
1453
+ let height = 1;
1454
+ if (engine.version === 1 && !engine.isWebGPU) {
1455
+ while (width * height < length) {
1456
+ height *= 2;
1457
+ }
1458
+ }
1459
+ else {
1460
+ height = Math.ceil(length / width);
1461
+ }
1462
+ if (height > width) {
1463
+ Logger.Error("GaussianSplatting texture size: (" + width + ", " + height + "), maxTextureSize: " + width);
1464
+ height = width;
1465
+ }
1466
+ return new Vector2(width, height);
1467
+ }
1468
+ }
1469
+ GaussianSplattingMesh._RowOutputLength = 3 * 4 + 3 * 4 + 4 + 4; // Vector3 position, Vector3 scale, 1 u8 quaternion, 1 color with alpha
1470
+ GaussianSplattingMesh._SH_C0 = 0.28209479177387814;
1471
+ // batch size between 2 yield calls. This value is a tradeoff between updates overhead and framerate hiccups
1472
+ // This step is faster the PLY conversion. So batch size can be bigger
1473
+ GaussianSplattingMesh._SplatBatchSize = 327680;
1474
+ // batch size between 2 yield calls during the PLY to splat conversion.
1475
+ GaussianSplattingMesh._PlyConversionBatchSize = 32768;
1476
+ /**
1477
+ * Set the number of batch (a batch is 16384 splats) after which a display update is performed
1478
+ * A value of 0 (default) means display update will not happens before splat is ready.
1479
+ */
1480
+ GaussianSplattingMesh.ProgressiveUpdateAmount = 0;
1481
+ GaussianSplattingMesh._CreateWorker = function (self) {
1482
+ let vertexCount = 0;
1483
+ let positions;
1484
+ let depthMix;
1485
+ let indices;
1486
+ let floatMix;
1487
+ self.onmessage = (e) => {
1488
+ // updated on init
1489
+ if (e.data.positions) {
1490
+ positions = e.data.positions;
1491
+ vertexCount = e.data.vertexCount;
1492
+ }
1493
+ // udpate on view changed
1494
+ else {
1495
+ const viewProj = e.data.view;
1496
+ if (!positions || !viewProj) {
1497
+ // Sanity check, it shouldn't happen!
1498
+ throw new Error("positions or view is not defined!");
1499
+ }
1500
+ depthMix = e.data.depthMix;
1501
+ indices = new Uint32Array(depthMix.buffer);
1502
+ floatMix = new Float32Array(depthMix.buffer);
1503
+ // Sort
1504
+ for (let j = 0; j < vertexCount; j++) {
1505
+ indices[2 * j] = j;
1506
+ }
1507
+ let depthFactor = -1;
1508
+ if (e.data.useRightHandedSystem) {
1509
+ depthFactor = 1;
1510
+ }
1511
+ for (let j = 0; j < vertexCount; j++) {
1512
+ floatMix[2 * j + 1] = 10000 + (viewProj[2] * positions[4 * j + 0] + viewProj[6] * positions[4 * j + 1] + viewProj[10] * positions[4 * j + 2]) * depthFactor;
1513
+ }
1514
+ depthMix.sort();
1515
+ self.postMessage({ depthMix }, [depthMix.buffer]);
1516
+ }
1517
+ };
1518
+ };
1519
+
1520
+ /**
1521
+ * Represents one particle of a points cloud system.
1522
+ */
1523
+ class CloudPoint {
1524
+ /**
1525
+ * Creates a Point Cloud object.
1526
+ * Don't create particles manually, use instead the PCS internal tools like _addParticle()
1527
+ * @param particleIndex (integer) is the particle index in the PCS pool. It's also the particle identifier.
1528
+ * @param group (PointsGroup) is the group the particle belongs to
1529
+ * @param groupId (integer) is the group identifier in the PCS.
1530
+ * @param idxInGroup (integer) is the index of the particle in the current point group (ex: the 10th point of addPoints(30))
1531
+ * @param pcs defines the PCS it is associated to
1532
+ */
1533
+ constructor(particleIndex, group, groupId, idxInGroup, pcs) {
1534
+ /**
1535
+ * particle global index
1536
+ */
1537
+ this.idx = 0;
1538
+ /**
1539
+ * The color of the particle
1540
+ */
1541
+ this.color = new Color4(1.0, 1.0, 1.0, 1.0);
1542
+ /**
1543
+ * The world space position of the particle.
1544
+ */
1545
+ this.position = Vector3.Zero();
1546
+ /**
1547
+ * The world space rotation of the particle. (Not use if rotationQuaternion is set)
1548
+ */
1549
+ this.rotation = Vector3.Zero();
1550
+ /**
1551
+ * The uv of the particle.
1552
+ */
1553
+ this.uv = new Vector2(0.0, 0.0);
1554
+ /**
1555
+ * The current speed of the particle.
1556
+ */
1557
+ this.velocity = Vector3.Zero();
1558
+ /**
1559
+ * The pivot point in the particle local space.
1560
+ */
1561
+ this.pivot = Vector3.Zero();
1562
+ /**
1563
+ * Must the particle be translated from its pivot point in its local space ?
1564
+ * In this case, the pivot point is set at the origin of the particle local space and the particle is translated.
1565
+ * Default : false
1566
+ */
1567
+ this.translateFromPivot = false;
1568
+ /**
1569
+ * Index of this particle in the global "positions" array (Internal use)
1570
+ * @internal
1571
+ */
1572
+ this._pos = 0;
1573
+ /**
1574
+ * @internal Index of this particle in the global "indices" array (Internal use)
1575
+ */
1576
+ this._ind = 0;
1577
+ /**
1578
+ * Group id of this particle
1579
+ */
1580
+ this.groupId = 0;
1581
+ /**
1582
+ * Index of the particle in its group id (Internal use)
1583
+ */
1584
+ this.idxInGroup = 0;
1585
+ /**
1586
+ * @internal Still set as invisible in order to skip useless computations (Internal use)
1587
+ */
1588
+ this._stillInvisible = false;
1589
+ /**
1590
+ * @internal Last computed particle rotation matrix
1591
+ */
1592
+ this._rotationMatrix = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
1593
+ /**
1594
+ * Parent particle Id, if any.
1595
+ * Default null.
1596
+ */
1597
+ this.parentId = null;
1598
+ /**
1599
+ * @internal Internal global position in the PCS.
1600
+ */
1601
+ this._globalPosition = Vector3.Zero();
1602
+ this.idx = particleIndex;
1603
+ this._group = group;
1604
+ this.groupId = groupId;
1605
+ this.idxInGroup = idxInGroup;
1606
+ this._pcs = pcs;
1607
+ }
1608
+ /**
1609
+ * get point size
1610
+ */
1611
+ get size() {
1612
+ return this.size;
1613
+ }
1614
+ /**
1615
+ * Set point size
1616
+ */
1617
+ set size(scale) {
1618
+ this.size = scale;
1619
+ }
1620
+ /**
1621
+ * Legacy support, changed quaternion to rotationQuaternion
1622
+ */
1623
+ get quaternion() {
1624
+ return this.rotationQuaternion;
1625
+ }
1626
+ /**
1627
+ * Legacy support, changed quaternion to rotationQuaternion
1628
+ */
1629
+ set quaternion(q) {
1630
+ this.rotationQuaternion = q;
1631
+ }
1632
+ /**
1633
+ * Returns a boolean. True if the particle intersects a mesh, else false
1634
+ * The intersection is computed on the particle position and Axis Aligned Bounding Box (AABB) or Sphere
1635
+ * @param target is the object (point or mesh) what the intersection is computed against
1636
+ * @param isSphere is boolean flag when false (default) bounding box of mesh is used, when true the bounding sphere is used
1637
+ * @returns true if it intersects
1638
+ */
1639
+ intersectsMesh(target, isSphere) {
1640
+ if (!target.hasBoundingInfo) {
1641
+ return false;
1642
+ }
1643
+ if (!this._pcs.mesh) {
1644
+ throw new Error("Point Cloud System doesnt contain the Mesh");
1645
+ }
1646
+ if (isSphere) {
1647
+ return target.getBoundingInfo().boundingSphere.intersectsPoint(this.position.add(this._pcs.mesh.position));
1648
+ }
1649
+ const bbox = target.getBoundingInfo().boundingBox;
1650
+ const maxX = bbox.maximumWorld.x;
1651
+ const minX = bbox.minimumWorld.x;
1652
+ const maxY = bbox.maximumWorld.y;
1653
+ const minY = bbox.minimumWorld.y;
1654
+ const maxZ = bbox.maximumWorld.z;
1655
+ const minZ = bbox.minimumWorld.z;
1656
+ const x = this.position.x + this._pcs.mesh.position.x;
1657
+ const y = this.position.y + this._pcs.mesh.position.y;
1658
+ const z = this.position.z + this._pcs.mesh.position.z;
1659
+ return minX <= x && x <= maxX && minY <= y && y <= maxY && minZ <= z && z <= maxZ;
1660
+ }
1661
+ /**
1662
+ * get the rotation matrix of the particle
1663
+ * @internal
1664
+ */
1665
+ getRotationMatrix(m) {
1666
+ let quaternion;
1667
+ if (this.rotationQuaternion) {
1668
+ quaternion = this.rotationQuaternion;
1669
+ }
1670
+ else {
1671
+ quaternion = TmpVectors.Quaternion[0];
1672
+ const rotation = this.rotation;
1673
+ Quaternion.RotationYawPitchRollToRef(rotation.y, rotation.x, rotation.z, quaternion);
1674
+ }
1675
+ quaternion.toRotationMatrix(m);
1676
+ }
1677
+ }
1678
+ /**
1679
+ * Represents a group of points in a points cloud system
1680
+ * * PCS internal tool, don't use it manually.
1681
+ */
1682
+ class PointsGroup {
1683
+ /**
1684
+ * Get or set the groupId
1685
+ * @deprecated Please use groupId instead
1686
+ */
1687
+ get groupID() {
1688
+ return this.groupId;
1689
+ }
1690
+ set groupID(groupID) {
1691
+ this.groupId = groupID;
1692
+ }
1693
+ /**
1694
+ * Creates a points group object. This is an internal reference to produce particles for the PCS.
1695
+ * PCS internal tool, don't use it manually.
1696
+ * @internal
1697
+ */
1698
+ constructor(id, posFunction) {
1699
+ this.groupId = id;
1700
+ this._positionFunction = posFunction;
1701
+ }
1702
+ }
1703
+
1704
+ /**
1705
+ * Class representing a ray with position and direction
1706
+ */
1707
+ class Ray {
1708
+ /**
1709
+ * Creates a new ray
1710
+ * @param origin origin point
1711
+ * @param direction direction
1712
+ * @param length length of the ray
1713
+ * @param epsilon The epsilon value to use when calculating the ray/triangle intersection (default: 0)
1714
+ */
1715
+ constructor(
1716
+ /** origin point */
1717
+ origin,
1718
+ /** direction */
1719
+ direction,
1720
+ /** [Number.MAX_VALUE] length of the ray */
1721
+ length = Number.MAX_VALUE,
1722
+ /** [Epsilon] The epsilon value to use when calculating the ray/triangle intersection (default: Epsilon from math constants) */
1723
+ epsilon = Epsilon) {
1724
+ this.origin = origin;
1725
+ this.direction = direction;
1726
+ this.length = length;
1727
+ this.epsilon = epsilon;
1728
+ }
1729
+ // Methods
1730
+ /**
1731
+ * Clone the current ray
1732
+ * @returns a new ray
1733
+ */
1734
+ clone() {
1735
+ return new Ray(this.origin.clone(), this.direction.clone(), this.length);
1736
+ }
1737
+ /**
1738
+ * Checks if the ray intersects a box
1739
+ * This does not account for the ray length by design to improve perfs.
1740
+ * @param minimum bound of the box
1741
+ * @param maximum bound of the box
1742
+ * @param intersectionTreshold extra extend to be added to the box in all direction
1743
+ * @returns if the box was hit
1744
+ */
1745
+ intersectsBoxMinMax(minimum, maximum, intersectionTreshold = 0) {
1746
+ const newMinimum = Ray._TmpVector3[0].copyFromFloats(minimum.x - intersectionTreshold, minimum.y - intersectionTreshold, minimum.z - intersectionTreshold);
1747
+ const newMaximum = Ray._TmpVector3[1].copyFromFloats(maximum.x + intersectionTreshold, maximum.y + intersectionTreshold, maximum.z + intersectionTreshold);
1748
+ let d = 0.0;
1749
+ let maxValue = Number.MAX_VALUE;
1750
+ let inv;
1751
+ let min;
1752
+ let max;
1753
+ let temp;
1754
+ if (Math.abs(this.direction.x) < 0.0000001) {
1755
+ if (this.origin.x < newMinimum.x || this.origin.x > newMaximum.x) {
1756
+ return false;
1757
+ }
1758
+ }
1759
+ else {
1760
+ inv = 1.0 / this.direction.x;
1761
+ min = (newMinimum.x - this.origin.x) * inv;
1762
+ max = (newMaximum.x - this.origin.x) * inv;
1763
+ if (max === -Infinity) {
1764
+ max = Infinity;
1765
+ }
1766
+ if (min > max) {
1767
+ temp = min;
1768
+ min = max;
1769
+ max = temp;
1770
+ }
1771
+ d = Math.max(min, d);
1772
+ maxValue = Math.min(max, maxValue);
1773
+ if (d > maxValue) {
1774
+ return false;
1775
+ }
1776
+ }
1777
+ if (Math.abs(this.direction.y) < 0.0000001) {
1778
+ if (this.origin.y < newMinimum.y || this.origin.y > newMaximum.y) {
1779
+ return false;
1780
+ }
1781
+ }
1782
+ else {
1783
+ inv = 1.0 / this.direction.y;
1784
+ min = (newMinimum.y - this.origin.y) * inv;
1785
+ max = (newMaximum.y - this.origin.y) * inv;
1786
+ if (max === -Infinity) {
1787
+ max = Infinity;
1788
+ }
1789
+ if (min > max) {
1790
+ temp = min;
1791
+ min = max;
1792
+ max = temp;
1793
+ }
1794
+ d = Math.max(min, d);
1795
+ maxValue = Math.min(max, maxValue);
1796
+ if (d > maxValue) {
1797
+ return false;
1798
+ }
1799
+ }
1800
+ if (Math.abs(this.direction.z) < 0.0000001) {
1801
+ if (this.origin.z < newMinimum.z || this.origin.z > newMaximum.z) {
1802
+ return false;
1803
+ }
1804
+ }
1805
+ else {
1806
+ inv = 1.0 / this.direction.z;
1807
+ min = (newMinimum.z - this.origin.z) * inv;
1808
+ max = (newMaximum.z - this.origin.z) * inv;
1809
+ if (max === -Infinity) {
1810
+ max = Infinity;
1811
+ }
1812
+ if (min > max) {
1813
+ temp = min;
1814
+ min = max;
1815
+ max = temp;
1816
+ }
1817
+ d = Math.max(min, d);
1818
+ maxValue = Math.min(max, maxValue);
1819
+ if (d > maxValue) {
1820
+ return false;
1821
+ }
1822
+ }
1823
+ return true;
1824
+ }
1825
+ /**
1826
+ * Checks if the ray intersects a box
1827
+ * This does not account for the ray lenght by design to improve perfs.
1828
+ * @param box the bounding box to check
1829
+ * @param intersectionTreshold extra extend to be added to the BoundingBox in all direction
1830
+ * @returns if the box was hit
1831
+ */
1832
+ intersectsBox(box, intersectionTreshold = 0) {
1833
+ return this.intersectsBoxMinMax(box.minimum, box.maximum, intersectionTreshold);
1834
+ }
1835
+ /**
1836
+ * If the ray hits a sphere
1837
+ * @param sphere the bounding sphere to check
1838
+ * @param intersectionTreshold extra extend to be added to the BoundingSphere in all direction
1839
+ * @returns true if it hits the sphere
1840
+ */
1841
+ intersectsSphere(sphere, intersectionTreshold = 0) {
1842
+ const x = sphere.center.x - this.origin.x;
1843
+ const y = sphere.center.y - this.origin.y;
1844
+ const z = sphere.center.z - this.origin.z;
1845
+ const pyth = x * x + y * y + z * z;
1846
+ const radius = sphere.radius + intersectionTreshold;
1847
+ const rr = radius * radius;
1848
+ if (pyth <= rr) {
1849
+ return true;
1850
+ }
1851
+ const dot = x * this.direction.x + y * this.direction.y + z * this.direction.z;
1852
+ if (dot < 0.0) {
1853
+ return false;
1854
+ }
1855
+ const temp = pyth - dot * dot;
1856
+ return temp <= rr;
1857
+ }
1858
+ /**
1859
+ * If the ray hits a triange
1860
+ * @param vertex0 triangle vertex
1861
+ * @param vertex1 triangle vertex
1862
+ * @param vertex2 triangle vertex
1863
+ * @returns intersection information if hit
1864
+ */
1865
+ intersectsTriangle(vertex0, vertex1, vertex2) {
1866
+ const edge1 = Ray._TmpVector3[0];
1867
+ const edge2 = Ray._TmpVector3[1];
1868
+ const pvec = Ray._TmpVector3[2];
1869
+ const tvec = Ray._TmpVector3[3];
1870
+ const qvec = Ray._TmpVector3[4];
1871
+ vertex1.subtractToRef(vertex0, edge1);
1872
+ vertex2.subtractToRef(vertex0, edge2);
1873
+ Vector3.CrossToRef(this.direction, edge2, pvec);
1874
+ const det = Vector3.Dot(edge1, pvec);
1875
+ if (det === 0) {
1876
+ return null;
1877
+ }
1878
+ const invdet = 1 / det;
1879
+ this.origin.subtractToRef(vertex0, tvec);
1880
+ const bv = Vector3.Dot(tvec, pvec) * invdet;
1881
+ if (bv < -this.epsilon || bv > 1.0 + this.epsilon) {
1882
+ return null;
1883
+ }
1884
+ Vector3.CrossToRef(tvec, edge1, qvec);
1885
+ const bw = Vector3.Dot(this.direction, qvec) * invdet;
1886
+ if (bw < -this.epsilon || bv + bw > 1.0 + this.epsilon) {
1887
+ return null;
1888
+ }
1889
+ //check if the distance is longer than the predefined length.
1890
+ const distance = Vector3.Dot(edge2, qvec) * invdet;
1891
+ if (distance > this.length) {
1892
+ return null;
1893
+ }
1894
+ return new IntersectionInfo(1 - bv - bw, bv, distance);
1895
+ }
1896
+ /**
1897
+ * Checks if ray intersects a plane
1898
+ * @param plane the plane to check
1899
+ * @returns the distance away it was hit
1900
+ */
1901
+ intersectsPlane(plane) {
1902
+ let distance;
1903
+ const result1 = Vector3.Dot(plane.normal, this.direction);
1904
+ if (Math.abs(result1) < 9.99999997475243e-7) {
1905
+ return null;
1906
+ }
1907
+ else {
1908
+ const result2 = Vector3.Dot(plane.normal, this.origin);
1909
+ distance = (-plane.d - result2) / result1;
1910
+ if (distance < 0.0) {
1911
+ if (distance < -9.99999997475243e-7) {
1912
+ return null;
1913
+ }
1914
+ else {
1915
+ return 0;
1916
+ }
1917
+ }
1918
+ return distance;
1919
+ }
1920
+ }
1921
+ /**
1922
+ * Calculate the intercept of a ray on a given axis
1923
+ * @param axis to check 'x' | 'y' | 'z'
1924
+ * @param offset from axis interception (i.e. an offset of 1y is intercepted above ground)
1925
+ * @returns a vector containing the coordinates where 'axis' is equal to zero (else offset), or null if there is no intercept.
1926
+ */
1927
+ intersectsAxis(axis, offset = 0) {
1928
+ switch (axis) {
1929
+ case "y": {
1930
+ const t = (this.origin.y - offset) / this.direction.y;
1931
+ if (t > 0) {
1932
+ return null;
1933
+ }
1934
+ return new Vector3(this.origin.x + this.direction.x * -t, offset, this.origin.z + this.direction.z * -t);
1935
+ }
1936
+ case "x": {
1937
+ const t = (this.origin.x - offset) / this.direction.x;
1938
+ if (t > 0) {
1939
+ return null;
1940
+ }
1941
+ return new Vector3(offset, this.origin.y + this.direction.y * -t, this.origin.z + this.direction.z * -t);
1942
+ }
1943
+ case "z": {
1944
+ const t = (this.origin.z - offset) / this.direction.z;
1945
+ if (t > 0) {
1946
+ return null;
1947
+ }
1948
+ return new Vector3(this.origin.x + this.direction.x * -t, this.origin.y + this.direction.y * -t, offset);
1949
+ }
1950
+ default:
1951
+ return null;
1952
+ }
1953
+ }
1954
+ /**
1955
+ * Checks if ray intersects a mesh. The ray is defined in WORLD space. A mesh triangle can be picked both from its front and back sides,
1956
+ * irrespective of orientation.
1957
+ * @param mesh the mesh to check
1958
+ * @param fastCheck defines if the first intersection will be used (and not the closest)
1959
+ * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
1960
+ * @param onlyBoundingInfo defines a boolean indicating if picking should only happen using bounding info (false by default)
1961
+ * @param worldToUse defines the world matrix to use to get the world coordinate of the intersection point
1962
+ * @param skipBoundingInfo a boolean indicating if we should skip the bounding info check
1963
+ * @returns picking info of the intersection
1964
+ */
1965
+ intersectsMesh(mesh, fastCheck, trianglePredicate, onlyBoundingInfo = false, worldToUse, skipBoundingInfo = false) {
1966
+ const tm = TmpVectors.Matrix[0];
1967
+ mesh.getWorldMatrix().invertToRef(tm);
1968
+ if (this._tmpRay) {
1969
+ Ray.TransformToRef(this, tm, this._tmpRay);
1970
+ }
1971
+ else {
1972
+ this._tmpRay = Ray.Transform(this, tm);
1973
+ }
1974
+ return mesh.intersects(this._tmpRay, fastCheck, trianglePredicate, onlyBoundingInfo, worldToUse, skipBoundingInfo);
1975
+ }
1976
+ /**
1977
+ * Checks if ray intersects a mesh
1978
+ * @param meshes the meshes to check
1979
+ * @param fastCheck defines if the first intersection will be used (and not the closest)
1980
+ * @param results array to store result in
1981
+ * @returns Array of picking infos
1982
+ */
1983
+ intersectsMeshes(meshes, fastCheck, results) {
1984
+ if (results) {
1985
+ results.length = 0;
1986
+ }
1987
+ else {
1988
+ results = [];
1989
+ }
1990
+ for (let i = 0; i < meshes.length; i++) {
1991
+ const pickInfo = this.intersectsMesh(meshes[i], fastCheck);
1992
+ if (pickInfo.hit) {
1993
+ results.push(pickInfo);
1994
+ }
1995
+ }
1996
+ results.sort(this._comparePickingInfo);
1997
+ return results;
1998
+ }
1999
+ _comparePickingInfo(pickingInfoA, pickingInfoB) {
2000
+ if (pickingInfoA.distance < pickingInfoB.distance) {
2001
+ return -1;
2002
+ }
2003
+ else if (pickingInfoA.distance > pickingInfoB.distance) {
2004
+ return 1;
2005
+ }
2006
+ else {
2007
+ return 0;
2008
+ }
2009
+ }
2010
+ /**
2011
+ * Intersection test between the ray and a given segment within a given tolerance (threshold)
2012
+ * @param sega the first point of the segment to test the intersection against
2013
+ * @param segb the second point of the segment to test the intersection against
2014
+ * @param threshold the tolerance margin, if the ray doesn't intersect the segment but is close to the given threshold, the intersection is successful
2015
+ * @returns the distance from the ray origin to the intersection point if there's intersection, or -1 if there's no intersection
2016
+ */
2017
+ intersectionSegment(sega, segb, threshold) {
2018
+ const o = this.origin;
2019
+ const u = TmpVectors.Vector3[0];
2020
+ const rsegb = TmpVectors.Vector3[1];
2021
+ const v = TmpVectors.Vector3[2];
2022
+ const w = TmpVectors.Vector3[3];
2023
+ segb.subtractToRef(sega, u);
2024
+ this.direction.scaleToRef(Ray._Rayl, v);
2025
+ o.addToRef(v, rsegb);
2026
+ sega.subtractToRef(o, w);
2027
+ const a = Vector3.Dot(u, u); // always >= 0
2028
+ const b = Vector3.Dot(u, v);
2029
+ const c = Vector3.Dot(v, v); // always >= 0
2030
+ const d = Vector3.Dot(u, w);
2031
+ const e = Vector3.Dot(v, w);
2032
+ const D = a * c - b * b; // always >= 0
2033
+ let sN, sD = D; // sc = sN / sD, default sD = D >= 0
2034
+ let tN, tD = D; // tc = tN / tD, default tD = D >= 0
2035
+ // compute the line parameters of the two closest points
2036
+ if (D < Ray._Smallnum) {
2037
+ // the lines are almost parallel
2038
+ sN = 0.0; // force using point P0 on segment S1
2039
+ sD = 1.0; // to prevent possible division by 0.0 later
2040
+ tN = e;
2041
+ tD = c;
2042
+ }
2043
+ else {
2044
+ // get the closest points on the infinite lines
2045
+ sN = b * e - c * d;
2046
+ tN = a * e - b * d;
2047
+ if (sN < 0.0) {
2048
+ // sc < 0 => the s=0 edge is visible
2049
+ sN = 0.0;
2050
+ tN = e;
2051
+ tD = c;
2052
+ }
2053
+ else if (sN > sD) {
2054
+ // sc > 1 => the s=1 edge is visible
2055
+ sN = sD;
2056
+ tN = e + b;
2057
+ tD = c;
2058
+ }
2059
+ }
2060
+ if (tN < 0.0) {
2061
+ // tc < 0 => the t=0 edge is visible
2062
+ tN = 0.0;
2063
+ // recompute sc for this edge
2064
+ if (-d < 0.0) {
2065
+ sN = 0.0;
2066
+ }
2067
+ else if (-d > a) {
2068
+ sN = sD;
2069
+ }
2070
+ else {
2071
+ sN = -d;
2072
+ sD = a;
2073
+ }
2074
+ }
2075
+ else if (tN > tD) {
2076
+ // tc > 1 => the t=1 edge is visible
2077
+ tN = tD;
2078
+ // recompute sc for this edge
2079
+ if (-d + b < 0.0) {
2080
+ sN = 0;
2081
+ }
2082
+ else if (-d + b > a) {
2083
+ sN = sD;
2084
+ }
2085
+ else {
2086
+ sN = -d + b;
2087
+ sD = a;
2088
+ }
2089
+ }
2090
+ // finally do the division to get sc and tc
2091
+ const sc = Math.abs(sN) < Ray._Smallnum ? 0.0 : sN / sD;
2092
+ const tc = Math.abs(tN) < Ray._Smallnum ? 0.0 : tN / tD;
2093
+ // get the difference of the two closest points
2094
+ const qtc = TmpVectors.Vector3[4];
2095
+ v.scaleToRef(tc, qtc);
2096
+ const qsc = TmpVectors.Vector3[5];
2097
+ u.scaleToRef(sc, qsc);
2098
+ qsc.addInPlace(w);
2099
+ const dP = TmpVectors.Vector3[6];
2100
+ qsc.subtractToRef(qtc, dP); // = S1(sc) - S2(tc)
2101
+ const isIntersected = tc > 0 && tc <= this.length && dP.lengthSquared() < threshold * threshold; // return intersection result
2102
+ if (isIntersected) {
2103
+ return qsc.length();
2104
+ }
2105
+ return -1;
2106
+ }
2107
+ /**
2108
+ * Update the ray from viewport position
2109
+ * @param x position
2110
+ * @param y y position
2111
+ * @param viewportWidth viewport width
2112
+ * @param viewportHeight viewport height
2113
+ * @param world world matrix
2114
+ * @param view view matrix
2115
+ * @param projection projection matrix
2116
+ * @param enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)
2117
+ * @returns this ray updated
2118
+ */
2119
+ update(x, y, viewportWidth, viewportHeight, world, view, projection, enableDistantPicking = false) {
2120
+ if (enableDistantPicking) {
2121
+ // With world matrices having great values (like 8000000000 on 1 or more scaling or position axis),
2122
+ // multiplying view/projection/world and doing invert will result in loss of float precision in the matrix.
2123
+ // One way to fix it is to compute the ray with world at identity then transform the ray in object space.
2124
+ // This is slower (2 matrix inverts instead of 1) but precision is preserved.
2125
+ // This is hidden behind `EnableDistantPicking` flag (default is false)
2126
+ if (!Ray._RayDistant) {
2127
+ Ray._RayDistant = Ray.Zero();
2128
+ }
2129
+ Ray._RayDistant.unprojectRayToRef(x, y, viewportWidth, viewportHeight, Matrix.IdentityReadOnly, view, projection);
2130
+ const tm = TmpVectors.Matrix[0];
2131
+ world.invertToRef(tm);
2132
+ Ray.TransformToRef(Ray._RayDistant, tm, this);
2133
+ }
2134
+ else {
2135
+ this.unprojectRayToRef(x, y, viewportWidth, viewportHeight, world, view, projection);
2136
+ }
2137
+ return this;
2138
+ }
2139
+ // Statics
2140
+ /**
2141
+ * Creates a ray with origin and direction of 0,0,0
2142
+ * @returns the new ray
2143
+ */
2144
+ static Zero() {
2145
+ return new Ray(Vector3.Zero(), Vector3.Zero());
2146
+ }
2147
+ /**
2148
+ * Creates a new ray from screen space and viewport
2149
+ * @param x position
2150
+ * @param y y position
2151
+ * @param viewportWidth viewport width
2152
+ * @param viewportHeight viewport height
2153
+ * @param world world matrix
2154
+ * @param view view matrix
2155
+ * @param projection projection matrix
2156
+ * @returns new ray
2157
+ */
2158
+ static CreateNew(x, y, viewportWidth, viewportHeight, world, view, projection) {
2159
+ const result = Ray.Zero();
2160
+ return result.update(x, y, viewportWidth, viewportHeight, world, view, projection);
2161
+ }
2162
+ /**
2163
+ * Function will create a new transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be
2164
+ * transformed to the given world matrix.
2165
+ * @param origin The origin point
2166
+ * @param end The end point
2167
+ * @param world a matrix to transform the ray to. Default is the identity matrix.
2168
+ * @returns the new ray
2169
+ */
2170
+ static CreateNewFromTo(origin, end, world = Matrix.IdentityReadOnly) {
2171
+ const result = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
2172
+ return Ray.CreateFromToToRef(origin, end, result, world);
2173
+ }
2174
+ /**
2175
+ * Function will update a transformed ray starting from origin and ending at the end point. Ray's length will be set, and ray will be
2176
+ * transformed to the given world matrix.
2177
+ * @param origin The origin point
2178
+ * @param end The end point
2179
+ * @param result the object to store the result
2180
+ * @param world a matrix to transform the ray to. Default is the identity matrix.
2181
+ * @returns the ref ray
2182
+ */
2183
+ static CreateFromToToRef(origin, end, result, world = Matrix.IdentityReadOnly) {
2184
+ result.origin.copyFrom(origin);
2185
+ const direction = end.subtractToRef(origin, result.direction);
2186
+ const length = Math.sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
2187
+ result.length = length;
2188
+ result.direction.normalize();
2189
+ return Ray.TransformToRef(result, world, result);
2190
+ }
2191
+ /**
2192
+ * Transforms a ray by a matrix
2193
+ * @param ray ray to transform
2194
+ * @param matrix matrix to apply
2195
+ * @returns the resulting new ray
2196
+ */
2197
+ static Transform(ray, matrix) {
2198
+ const result = new Ray(new Vector3(0, 0, 0), new Vector3(0, 0, 0));
2199
+ Ray.TransformToRef(ray, matrix, result);
2200
+ return result;
2201
+ }
2202
+ /**
2203
+ * Transforms a ray by a matrix
2204
+ * @param ray ray to transform
2205
+ * @param matrix matrix to apply
2206
+ * @param result ray to store result in
2207
+ * @returns the updated result ray
2208
+ */
2209
+ static TransformToRef(ray, matrix, result) {
2210
+ Vector3.TransformCoordinatesToRef(ray.origin, matrix, result.origin);
2211
+ Vector3.TransformNormalToRef(ray.direction, matrix, result.direction);
2212
+ result.length = ray.length;
2213
+ result.epsilon = ray.epsilon;
2214
+ const dir = result.direction;
2215
+ const len = dir.length();
2216
+ if (!(len === 0 || len === 1)) {
2217
+ const num = 1.0 / len;
2218
+ dir.x *= num;
2219
+ dir.y *= num;
2220
+ dir.z *= num;
2221
+ result.length *= len;
2222
+ }
2223
+ return result;
2224
+ }
2225
+ /**
2226
+ * Unproject a ray from screen space to object space
2227
+ * @param sourceX defines the screen space x coordinate to use
2228
+ * @param sourceY defines the screen space y coordinate to use
2229
+ * @param viewportWidth defines the current width of the viewport
2230
+ * @param viewportHeight defines the current height of the viewport
2231
+ * @param world defines the world matrix to use (can be set to Identity to go to world space)
2232
+ * @param view defines the view matrix to use
2233
+ * @param projection defines the projection matrix to use
2234
+ */
2235
+ unprojectRayToRef(sourceX, sourceY, viewportWidth, viewportHeight, world, view, projection) {
2236
+ const matrix = TmpVectors.Matrix[0];
2237
+ world.multiplyToRef(view, matrix);
2238
+ matrix.multiplyToRef(projection, matrix);
2239
+ matrix.invert();
2240
+ const engine = EngineStore.LastCreatedEngine;
2241
+ const nearScreenSource = TmpVectors.Vector3[0];
2242
+ nearScreenSource.x = (sourceX / viewportWidth) * 2 - 1;
2243
+ nearScreenSource.y = -((sourceY / viewportHeight) * 2 - 1);
2244
+ nearScreenSource.z = engine?.useReverseDepthBuffer ? 1 : engine?.isNDCHalfZRange ? 0 : -1;
2245
+ // far Z need to be close but < to 1 or camera projection matrix with maxZ = 0 will NaN
2246
+ const farScreenSource = TmpVectors.Vector3[1].copyFromFloats(nearScreenSource.x, nearScreenSource.y, 1.0 - 1e-8);
2247
+ const nearVec3 = TmpVectors.Vector3[2];
2248
+ const farVec3 = TmpVectors.Vector3[3];
2249
+ Vector3._UnprojectFromInvertedMatrixToRef(nearScreenSource, matrix, nearVec3);
2250
+ Vector3._UnprojectFromInvertedMatrixToRef(farScreenSource, matrix, farVec3);
2251
+ this.origin.copyFrom(nearVec3);
2252
+ farVec3.subtractToRef(nearVec3, this.direction);
2253
+ this.direction.normalize();
2254
+ }
2255
+ }
2256
+ Ray._TmpVector3 = BuildArray(6, Vector3.Zero);
2257
+ Ray._RayDistant = Ray.Zero();
2258
+ Ray._Smallnum = 0.00000001;
2259
+ Ray._Rayl = 10e8;
2260
+ /**
2261
+ * Creates a ray that can be used to pick in the scene
2262
+ * @param scene defines the scene to use for the picking
2263
+ * @param x defines the x coordinate of the origin (on-screen)
2264
+ * @param y defines the y coordinate of the origin (on-screen)
2265
+ * @param world defines the world matrix to use if you want to pick in object space (instead of world space)
2266
+ * @param camera defines the camera to use for the picking
2267
+ * @param cameraViewSpace defines if picking will be done in view space (false by default)
2268
+ * @returns a Ray
2269
+ */
2270
+ function CreatePickingRay(scene, x, y, world, camera, cameraViewSpace = false) {
2271
+ const result = Ray.Zero();
2272
+ CreatePickingRayToRef(scene, x, y, world, result, camera, cameraViewSpace);
2273
+ return result;
2274
+ }
2275
+ /**
2276
+ * Creates a ray that can be used to pick in the scene
2277
+ * @param scene defines the scene to use for the picking
2278
+ * @param x defines the x coordinate of the origin (on-screen)
2279
+ * @param y defines the y coordinate of the origin (on-screen)
2280
+ * @param world defines the world matrix to use if you want to pick in object space (instead of world space)
2281
+ * @param result defines the ray where to store the picking ray
2282
+ * @param camera defines the camera to use for the picking
2283
+ * @param cameraViewSpace defines if picking will be done in view space (false by default)
2284
+ * @param enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)
2285
+ * @returns the current scene
2286
+ */
2287
+ function CreatePickingRayToRef(scene, x, y, world, result, camera, cameraViewSpace = false, enableDistantPicking = false) {
2288
+ const engine = scene.getEngine();
2289
+ if (!camera && !(camera = scene.activeCamera)) {
2290
+ return scene;
2291
+ }
2292
+ const cameraViewport = camera.viewport;
2293
+ const renderHeight = engine.getRenderHeight();
2294
+ const { x: vx, y: vy, width, height } = cameraViewport.toGlobal(engine.getRenderWidth(), renderHeight);
2295
+ // Moving coordinates to local viewport world
2296
+ const levelInv = 1 / engine.getHardwareScalingLevel();
2297
+ x = x * levelInv - vx;
2298
+ y = y * levelInv - (renderHeight - vy - height);
2299
+ result.update(x, y, width, height, world ? world : Matrix.IdentityReadOnly, cameraViewSpace ? Matrix.IdentityReadOnly : camera.getViewMatrix(), camera.getProjectionMatrix(), enableDistantPicking);
2300
+ return scene;
2301
+ }
2302
+ /**
2303
+ * Creates a ray that can be used to pick in the scene
2304
+ * @param scene defines the scene to use for the picking
2305
+ * @param x defines the x coordinate of the origin (on-screen)
2306
+ * @param y defines the y coordinate of the origin (on-screen)
2307
+ * @param camera defines the camera to use for the picking
2308
+ * @returns a Ray
2309
+ */
2310
+ function CreatePickingRayInCameraSpace(scene, x, y, camera) {
2311
+ const result = Ray.Zero();
2312
+ CreatePickingRayInCameraSpaceToRef(scene, x, y, result, camera);
2313
+ return result;
2314
+ }
2315
+ /**
2316
+ * Creates a ray that can be used to pick in the scene
2317
+ * @param scene defines the scene to use for the picking
2318
+ * @param x defines the x coordinate of the origin (on-screen)
2319
+ * @param y defines the y coordinate of the origin (on-screen)
2320
+ * @param result defines the ray where to store the picking ray
2321
+ * @param camera defines the camera to use for the picking
2322
+ * @returns the current scene
2323
+ */
2324
+ function CreatePickingRayInCameraSpaceToRef(scene, x, y, result, camera) {
2325
+ if (!PickingInfo) {
2326
+ return scene;
2327
+ }
2328
+ const engine = scene.getEngine();
2329
+ if (!camera && !(camera = scene.activeCamera)) {
2330
+ throw new Error("Active camera not set");
2331
+ }
2332
+ const cameraViewport = camera.viewport;
2333
+ const renderHeight = engine.getRenderHeight();
2334
+ const { x: vx, y: vy, width, height } = cameraViewport.toGlobal(engine.getRenderWidth(), renderHeight);
2335
+ const identity = Matrix.Identity();
2336
+ // Moving coordinates to local viewport world
2337
+ const levelInv = 1 / engine.getHardwareScalingLevel();
2338
+ x = x * levelInv - vx;
2339
+ y = y * levelInv - (renderHeight - vy - height);
2340
+ result.update(x, y, width, height, identity, identity, camera.getProjectionMatrix());
2341
+ return scene;
2342
+ }
2343
+ function InternalPickForMesh(pickingInfo, rayFunction, mesh, world, fastCheck, onlyBoundingInfo, trianglePredicate, skipBoundingInfo) {
2344
+ const ray = rayFunction(world, mesh.enableDistantPicking);
2345
+ const result = mesh.intersects(ray, fastCheck, trianglePredicate, onlyBoundingInfo, world, skipBoundingInfo);
2346
+ if (!result || !result.hit) {
2347
+ return null;
2348
+ }
2349
+ if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance) {
2350
+ return null;
2351
+ }
2352
+ return result;
2353
+ }
2354
+ function InternalPick(scene, rayFunction, predicate, fastCheck, onlyBoundingInfo, trianglePredicate) {
2355
+ let pickingInfo = null;
2356
+ const computeWorldMatrixForCamera = !!(scene.activeCameras && scene.activeCameras.length > 1 && scene.cameraToUseForPointers !== scene.activeCamera);
2357
+ const currentCamera = scene.cameraToUseForPointers || scene.activeCamera;
2358
+ const picker = InternalPickForMesh;
2359
+ for (let meshIndex = 0; meshIndex < scene.meshes.length; meshIndex++) {
2360
+ const mesh = scene.meshes[meshIndex];
2361
+ if (predicate) {
2362
+ if (!predicate(mesh, -1)) {
2363
+ continue;
2364
+ }
2365
+ }
2366
+ else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
2367
+ continue;
2368
+ }
2369
+ const forceCompute = computeWorldMatrixForCamera && mesh.isWorldMatrixCameraDependent();
2370
+ const world = mesh.computeWorldMatrix(forceCompute, currentCamera);
2371
+ if (mesh.hasThinInstances && mesh.thinInstanceEnablePicking) {
2372
+ // first check if the ray intersects the whole bounding box/sphere of the mesh
2373
+ const result = picker(pickingInfo, rayFunction, mesh, world, true, true, trianglePredicate);
2374
+ if (result) {
2375
+ if (onlyBoundingInfo) {
2376
+ // the user only asked for a bounding info check so we can return
2377
+ return result;
2378
+ }
2379
+ const tmpMatrix = TmpVectors.Matrix[1];
2380
+ const thinMatrices = mesh.thinInstanceGetWorldMatrices();
2381
+ for (let index = 0; index < thinMatrices.length; index++) {
2382
+ if (predicate && !predicate(mesh, index)) {
2383
+ continue;
2384
+ }
2385
+ const thinMatrix = thinMatrices[index];
2386
+ thinMatrix.multiplyToRef(world, tmpMatrix);
2387
+ const result = picker(pickingInfo, rayFunction, mesh, tmpMatrix, fastCheck, onlyBoundingInfo, trianglePredicate, true);
2388
+ if (result) {
2389
+ pickingInfo = result;
2390
+ pickingInfo.thinInstanceIndex = index;
2391
+ if (fastCheck) {
2392
+ return pickingInfo;
2393
+ }
2394
+ }
2395
+ }
2396
+ }
2397
+ }
2398
+ else {
2399
+ const result = picker(pickingInfo, rayFunction, mesh, world, fastCheck, onlyBoundingInfo, trianglePredicate);
2400
+ if (result) {
2401
+ pickingInfo = result;
2402
+ if (fastCheck) {
2403
+ return pickingInfo;
2404
+ }
2405
+ }
2406
+ }
2407
+ }
2408
+ return pickingInfo || new PickingInfo();
2409
+ }
2410
+ function InternalMultiPick(scene, rayFunction, predicate, trianglePredicate) {
2411
+ if (!PickingInfo) {
2412
+ return null;
2413
+ }
2414
+ const pickingInfos = [];
2415
+ const computeWorldMatrixForCamera = !!(scene.activeCameras && scene.activeCameras.length > 1 && scene.cameraToUseForPointers !== scene.activeCamera);
2416
+ const currentCamera = scene.cameraToUseForPointers || scene.activeCamera;
2417
+ const picker = InternalPickForMesh;
2418
+ for (let meshIndex = 0; meshIndex < scene.meshes.length; meshIndex++) {
2419
+ const mesh = scene.meshes[meshIndex];
2420
+ if (predicate) {
2421
+ if (!predicate(mesh, -1)) {
2422
+ continue;
2423
+ }
2424
+ }
2425
+ else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
2426
+ continue;
2427
+ }
2428
+ const forceCompute = computeWorldMatrixForCamera && mesh.isWorldMatrixCameraDependent();
2429
+ const world = mesh.computeWorldMatrix(forceCompute, currentCamera);
2430
+ if (mesh.hasThinInstances && mesh.thinInstanceEnablePicking) {
2431
+ const result = picker(null, rayFunction, mesh, world, true, true, trianglePredicate);
2432
+ if (result) {
2433
+ const tmpMatrix = TmpVectors.Matrix[1];
2434
+ const thinMatrices = mesh.thinInstanceGetWorldMatrices();
2435
+ for (let index = 0; index < thinMatrices.length; index++) {
2436
+ if (predicate && !predicate(mesh, index)) {
2437
+ continue;
2438
+ }
2439
+ const thinMatrix = thinMatrices[index];
2440
+ thinMatrix.multiplyToRef(world, tmpMatrix);
2441
+ const result = picker(null, rayFunction, mesh, tmpMatrix, false, false, trianglePredicate, true);
2442
+ if (result) {
2443
+ result.thinInstanceIndex = index;
2444
+ pickingInfos.push(result);
2445
+ }
2446
+ }
2447
+ }
2448
+ }
2449
+ else {
2450
+ const result = picker(null, rayFunction, mesh, world, false, false, trianglePredicate);
2451
+ if (result) {
2452
+ pickingInfos.push(result);
2453
+ }
2454
+ }
2455
+ }
2456
+ return pickingInfos;
2457
+ }
2458
+ /** Launch a ray to try to pick a mesh in the scene using only bounding information of the main mesh (not using submeshes)
2459
+ * @param scene defines the scene to use for the picking
2460
+ * @param x position on screen
2461
+ * @param y position on screen
2462
+ * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true. thinInstanceIndex is -1 when the mesh is non-instanced
2463
+ * @param fastCheck defines if the first intersection will be used (and not the closest)
2464
+ * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
2465
+ * @returns a PickingInfo (Please note that some info will not be set like distance, bv, bu and everything that cannot be capture by only using bounding infos)
2466
+ */
2467
+ function PickWithBoundingInfo(scene, x, y, predicate, fastCheck, camera) {
2468
+ if (!PickingInfo) {
2469
+ return null;
2470
+ }
2471
+ const result = InternalPick(scene, (world) => {
2472
+ if (!scene._tempPickingRay) {
2473
+ scene._tempPickingRay = Ray.Zero();
2474
+ }
2475
+ CreatePickingRayToRef(scene, x, y, world, scene._tempPickingRay, camera || null);
2476
+ return scene._tempPickingRay;
2477
+ }, predicate, fastCheck, true);
2478
+ if (result) {
2479
+ result.ray = CreatePickingRay(scene, x, y, Matrix.Identity(), camera || null);
2480
+ }
2481
+ return result;
2482
+ }
2483
+ /** Launch a ray to try to pick a mesh in the scene
2484
+ * @param scene defines the scene to use for the picking
2485
+ * @param x position on screen
2486
+ * @param y position on screen
2487
+ * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true. thinInstanceIndex is -1 when the mesh is non-instanced
2488
+ * @param fastCheck defines if the first intersection will be used (and not the closest)
2489
+ * @param camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
2490
+ * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
2491
+ * @param _enableDistantPicking defines if picking should handle large values for mesh position/scaling (false by default)
2492
+ * @returns a PickingInfo
2493
+ */
2494
+ function Pick(scene, x, y, predicate, fastCheck, camera, trianglePredicate, _enableDistantPicking = false) {
2495
+ const result = InternalPick(scene, (world, enableDistantPicking) => {
2496
+ if (!scene._tempPickingRay) {
2497
+ scene._tempPickingRay = Ray.Zero();
2498
+ }
2499
+ CreatePickingRayToRef(scene, x, y, world, scene._tempPickingRay, camera || null, false, enableDistantPicking);
2500
+ return scene._tempPickingRay;
2501
+ }, predicate, fastCheck, false, trianglePredicate);
2502
+ if (result) {
2503
+ result.ray = CreatePickingRay(scene, x, y, Matrix.Identity(), camera || null);
2504
+ }
2505
+ return result;
2506
+ }
2507
+ /**
2508
+ * Use the given ray to pick a mesh in the scene. A mesh triangle can be picked both from its front and back sides,
2509
+ * irrespective of orientation.
2510
+ * @param scene defines the scene to use for the picking
2511
+ * @param ray The ray to use to pick meshes
2512
+ * @param predicate Predicate function used to determine eligible meshes. Can be set to null. In this case, a mesh must have isPickable set to true. thinInstanceIndex is -1 when the mesh is non-instanced
2513
+ * @param fastCheck defines if the first intersection will be used (and not the closest)
2514
+ * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
2515
+ * @returns a PickingInfo
2516
+ */
2517
+ function PickWithRay(scene, ray, predicate, fastCheck, trianglePredicate) {
2518
+ const result = InternalPick(scene, (world) => {
2519
+ if (!scene._pickWithRayInverseMatrix) {
2520
+ scene._pickWithRayInverseMatrix = Matrix.Identity();
2521
+ }
2522
+ world.invertToRef(scene._pickWithRayInverseMatrix);
2523
+ if (!scene._cachedRayForTransform) {
2524
+ scene._cachedRayForTransform = Ray.Zero();
2525
+ }
2526
+ Ray.TransformToRef(ray, scene._pickWithRayInverseMatrix, scene._cachedRayForTransform);
2527
+ return scene._cachedRayForTransform;
2528
+ }, predicate, fastCheck, false, trianglePredicate);
2529
+ if (result) {
2530
+ result.ray = ray;
2531
+ }
2532
+ return result;
2533
+ }
2534
+ /**
2535
+ * Launch a ray to try to pick a mesh in the scene. A mesh triangle can be picked both from its front and back sides,
2536
+ * irrespective of orientation.
2537
+ * @param scene defines the scene to use for the picking
2538
+ * @param x X position on screen
2539
+ * @param y Y position on screen
2540
+ * @param predicate Predicate function used to determine eligible meshes and instances. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true. thinInstanceIndex is -1 when the mesh is non-instanced
2541
+ * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
2542
+ * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
2543
+ * @returns an array of PickingInfo
2544
+ */
2545
+ function MultiPick(scene, x, y, predicate, camera, trianglePredicate) {
2546
+ return InternalMultiPick(scene, (world) => CreatePickingRay(scene, x, y, world, camera || null), predicate, trianglePredicate);
2547
+ }
2548
+ /**
2549
+ * Launch a ray to try to pick a mesh in the scene
2550
+ * @param scene defines the scene to use for the picking
2551
+ * @param ray Ray to use
2552
+ * @param predicate Predicate function used to determine eligible meshes and instances. Can be set to null. In this case, a mesh must be enabled, visible and with isPickable set to true. thinInstanceIndex is -1 when the mesh is non-instanced
2553
+ * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
2554
+ * @returns an array of PickingInfo
2555
+ */
2556
+ function MultiPickWithRay(scene, ray, predicate, trianglePredicate) {
2557
+ return InternalMultiPick(scene, (world) => {
2558
+ if (!scene._pickWithRayInverseMatrix) {
2559
+ scene._pickWithRayInverseMatrix = Matrix.Identity();
2560
+ }
2561
+ world.invertToRef(scene._pickWithRayInverseMatrix);
2562
+ if (!scene._cachedRayForTransform) {
2563
+ scene._cachedRayForTransform = Ray.Zero();
2564
+ }
2565
+ Ray.TransformToRef(ray, scene._pickWithRayInverseMatrix, scene._cachedRayForTransform);
2566
+ return scene._cachedRayForTransform;
2567
+ }, predicate, trianglePredicate);
2568
+ }
2569
+ /**
2570
+ * Gets a ray in the forward direction from the camera.
2571
+ * @param camera Defines the camera to use to get the ray from
2572
+ * @param refRay the ray to (re)use when setting the values
2573
+ * @param length Defines the length of the ray to create
2574
+ * @param transform Defines the transform to apply to the ray, by default the world matrx is used to create a workd space ray
2575
+ * @param origin Defines the start point of the ray which defaults to the camera position
2576
+ * @returns the forward ray
2577
+ */
2578
+ function GetForwardRayToRef(camera, refRay, length = 100, transform, origin) {
2579
+ if (!transform) {
2580
+ transform = camera.getWorldMatrix();
2581
+ }
2582
+ refRay.length = length;
2583
+ if (origin) {
2584
+ refRay.origin.copyFrom(origin);
2585
+ }
2586
+ else {
2587
+ refRay.origin.copyFrom(camera.position);
2588
+ }
2589
+ const forward = TmpVectors.Vector3[2];
2590
+ forward.set(0, 0, camera._scene.useRightHandedSystem ? -1 : 1);
2591
+ const worldForward = TmpVectors.Vector3[3];
2592
+ Vector3.TransformNormalToRef(forward, transform, worldForward);
2593
+ Vector3.NormalizeToRef(worldForward, refRay.direction);
2594
+ return refRay;
2595
+ }
2596
+ /**
2597
+ * Initialize the minimal interdependecies between the Ray and Scene and Camera
2598
+ * @param sceneClass defines the scene prototype to use
2599
+ * @param cameraClass defines the camera prototype to use
2600
+ */
2601
+ function AddRayExtensions(sceneClass, cameraClass) {
2602
+ if (cameraClass) {
2603
+ cameraClass.prototype.getForwardRay = function (length = 100, transform, origin) {
2604
+ return GetForwardRayToRef(this, new Ray(Vector3.Zero(), Vector3.Zero(), length), length, transform, origin);
2605
+ };
2606
+ cameraClass.prototype.getForwardRayToRef = function (refRay, length = 100, transform, origin) {
2607
+ return GetForwardRayToRef(this, refRay, length, transform, origin);
2608
+ };
2609
+ }
2610
+ if (!sceneClass) {
2611
+ return;
2612
+ }
2613
+ _ImportHelper._IsPickingAvailable = true;
2614
+ sceneClass.prototype.createPickingRay = function (x, y, world, camera, cameraViewSpace = false) {
2615
+ return CreatePickingRay(this, x, y, world, camera, cameraViewSpace);
2616
+ };
2617
+ }
2618
+
2619
+ // Picking
2620
+ AddRayExtensions(Scene, Camera);
2621
+ Scene.prototype.createPickingRayToRef = function (x, y, world, result, camera, cameraViewSpace = false, enableDistantPicking = false) {
2622
+ return CreatePickingRayToRef(this, x, y, world, result, camera, cameraViewSpace, enableDistantPicking);
2623
+ };
2624
+ Scene.prototype.createPickingRayInCameraSpace = function (x, y, camera) {
2625
+ return CreatePickingRayInCameraSpace(this, x, y, camera);
2626
+ };
2627
+ Scene.prototype.createPickingRayInCameraSpaceToRef = function (x, y, result, camera) {
2628
+ return CreatePickingRayInCameraSpaceToRef(this, x, y, result, camera);
2629
+ };
2630
+ Scene.prototype.pickWithBoundingInfo = function (x, y, predicate, fastCheck, camera) {
2631
+ return PickWithBoundingInfo(this, x, y, predicate, fastCheck, camera);
2632
+ };
2633
+ Scene.prototype.pick = function (x, y, predicate, fastCheck, camera, trianglePredicate, _enableDistantPicking = false) {
2634
+ return Pick(this, x, y, predicate, fastCheck, camera, trianglePredicate, _enableDistantPicking);
2635
+ };
2636
+ Scene.prototype.pickWithRay = function (ray, predicate, fastCheck, trianglePredicate) {
2637
+ return PickWithRay(this, ray, predicate, fastCheck, trianglePredicate);
2638
+ };
2639
+ Scene.prototype.multiPick = function (x, y, predicate, camera, trianglePredicate) {
2640
+ return MultiPick(this, x, y, predicate, camera, trianglePredicate);
2641
+ };
2642
+ Scene.prototype.multiPickWithRay = function (ray, predicate, trianglePredicate) {
2643
+ return MultiPickWithRay(this, ray, predicate, trianglePredicate);
2644
+ };
2645
+
2646
+ /** Defines the 4 color options */
2647
+ var PointColor;
2648
+ (function (PointColor) {
2649
+ /** color value */
2650
+ PointColor[PointColor["Color"] = 2] = "Color";
2651
+ /** uv value */
2652
+ PointColor[PointColor["UV"] = 1] = "UV";
2653
+ /** random value */
2654
+ PointColor[PointColor["Random"] = 0] = "Random";
2655
+ /** stated value */
2656
+ PointColor[PointColor["Stated"] = 3] = "Stated";
2657
+ })(PointColor || (PointColor = {}));
2658
+ /**
2659
+ * The PointCloudSystem (PCS) is a single updatable mesh. The points corresponding to the vertices of this big mesh.
2660
+ * As it is just a mesh, the PointCloudSystem has all the same properties as any other BJS mesh : not more, not less. It can be scaled, rotated, translated, enlighted, textured, moved, etc.
2661
+
2662
+ * The PointCloudSystem is also a particle system, with each point being a particle. It provides some methods to manage the particles.
2663
+ * However it is behavior agnostic. This means it has no emitter, no particle physics, no particle recycler. You have to implement your own behavior.
2664
+ *
2665
+ * Full documentation here : TO BE ENTERED
2666
+ */
2667
+ class PointsCloudSystem {
2668
+ /**
2669
+ * Gets the particle positions computed by the Point Cloud System
2670
+ */
2671
+ get positions() {
2672
+ return this._positions32;
2673
+ }
2674
+ /**
2675
+ * Gets the particle colors computed by the Point Cloud System
2676
+ */
2677
+ get colors() {
2678
+ return this._colors32;
2679
+ }
2680
+ /**
2681
+ * Gets the particle uvs computed by the Point Cloud System
2682
+ */
2683
+ get uvs() {
2684
+ return this._uvs32;
2685
+ }
2686
+ /**
2687
+ * Creates a PCS (Points Cloud System) object
2688
+ * @param name (String) is the PCS name, this will be the underlying mesh name
2689
+ * @param pointSize (number) is the size for each point. Has no effect on a WebGPU engine.
2690
+ * @param scene (Scene) is the scene in which the PCS is added
2691
+ * @param options defines the options of the PCS e.g.
2692
+ * * updatable (optional boolean, default true) : if the PCS must be updatable or immutable
2693
+ */
2694
+ constructor(name, pointSize, scene, options) {
2695
+ /**
2696
+ * The PCS array of cloud point objects. Just access each particle as with any classic array.
2697
+ * Example : var p = SPS.particles[i];
2698
+ */
2699
+ this.particles = new Array();
2700
+ /**
2701
+ * The PCS total number of particles. Read only. Use PCS.counter instead if you need to set your own value.
2702
+ */
2703
+ this.nbParticles = 0;
2704
+ /**
2705
+ * This a counter for your own usage. It's not set by any SPS functions.
2706
+ */
2707
+ this.counter = 0;
2708
+ /**
2709
+ * This empty object is intended to store some PCS specific or temporary values in order to lower the Garbage Collector activity.
2710
+ * Please read :
2711
+ */
2712
+ this.vars = {};
2713
+ this._promises = [];
2714
+ this._positions = new Array();
2715
+ this._indices = new Array();
2716
+ this._normals = new Array();
2717
+ this._colors = new Array();
2718
+ this._uvs = new Array();
2719
+ this._updatable = true;
2720
+ this._isVisibilityBoxLocked = false;
2721
+ this._alwaysVisible = false;
2722
+ this._groups = new Array(); //start indices for each group of particles
2723
+ this._groupCounter = 0;
2724
+ this._computeParticleColor = true;
2725
+ this._computeParticleTexture = true;
2726
+ this._computeParticleRotation = true;
2727
+ this._computeBoundingBox = false;
2728
+ this._isReady = false;
2729
+ this.name = name;
2730
+ this._size = pointSize;
2731
+ this._scene = scene || EngineStore.LastCreatedScene;
2732
+ if (options && options.updatable !== undefined) {
2733
+ this._updatable = options.updatable;
2734
+ }
2735
+ else {
2736
+ this._updatable = true;
2737
+ }
2738
+ }
2739
+ /**
2740
+ * Builds the PCS underlying mesh. Returns a standard Mesh.
2741
+ * If no points were added to the PCS, the returned mesh is just a single point.
2742
+ * @param material The material to use to render the mesh. If not provided, will create a default one
2743
+ * @returns a promise for the created mesh
2744
+ */
2745
+ buildMeshAsync(material) {
2746
+ return Promise.all(this._promises).then(() => {
2747
+ this._isReady = true;
2748
+ return this._buildMesh(material);
2749
+ });
2750
+ }
2751
+ /**
2752
+ * @internal
2753
+ */
2754
+ _buildMesh(material) {
2755
+ if (this.nbParticles === 0) {
2756
+ this.addPoints(1);
2757
+ }
2758
+ this._positions32 = new Float32Array(this._positions);
2759
+ this._uvs32 = new Float32Array(this._uvs);
2760
+ this._colors32 = new Float32Array(this._colors);
2761
+ const vertexData = new VertexData();
2762
+ vertexData.set(this._positions32, VertexBuffer.PositionKind);
2763
+ if (this._uvs32.length > 0) {
2764
+ vertexData.set(this._uvs32, VertexBuffer.UVKind);
2765
+ }
2766
+ let ec = 0; //emissive color value 0 for UVs, 1 for color
2767
+ if (this._colors32.length > 0) {
2768
+ ec = 1;
2769
+ vertexData.set(this._colors32, VertexBuffer.ColorKind);
2770
+ }
2771
+ const mesh = new Mesh(this.name, this._scene);
2772
+ vertexData.applyToMesh(mesh, this._updatable);
2773
+ this.mesh = mesh;
2774
+ // free memory
2775
+ this._positions = null;
2776
+ this._uvs = null;
2777
+ this._colors = null;
2778
+ if (!this._updatable) {
2779
+ this.particles.length = 0;
2780
+ }
2781
+ let mat = material;
2782
+ if (!mat) {
2783
+ mat = new StandardMaterial("point cloud material", this._scene);
2784
+ mat.emissiveColor = new Color3(ec, ec, ec);
2785
+ mat.disableLighting = true;
2786
+ mat.pointsCloud = true;
2787
+ mat.pointSize = this._size;
2788
+ }
2789
+ mesh.material = mat;
2790
+ return new Promise((resolve) => resolve(mesh));
2791
+ }
2792
+ // adds a new particle object in the particles array
2793
+ _addParticle(idx, group, groupId, idxInGroup) {
2794
+ const cp = new CloudPoint(idx, group, groupId, idxInGroup, this);
2795
+ this.particles.push(cp);
2796
+ return cp;
2797
+ }
2798
+ _randomUnitVector(particle) {
2799
+ particle.position = new Vector3(Math.random(), Math.random(), Math.random());
2800
+ particle.color = new Color4(1, 1, 1, 1);
2801
+ }
2802
+ _getColorIndicesForCoord(pointsGroup, x, y, width) {
2803
+ const imageData = pointsGroup._groupImageData;
2804
+ const color = y * (width * 4) + x * 4;
2805
+ const colorIndices = [color, color + 1, color + 2, color + 3];
2806
+ const redIndex = colorIndices[0];
2807
+ const greenIndex = colorIndices[1];
2808
+ const blueIndex = colorIndices[2];
2809
+ const alphaIndex = colorIndices[3];
2810
+ const redForCoord = imageData[redIndex];
2811
+ const greenForCoord = imageData[greenIndex];
2812
+ const blueForCoord = imageData[blueIndex];
2813
+ const alphaForCoord = imageData[alphaIndex];
2814
+ return new Color4(redForCoord / 255, greenForCoord / 255, blueForCoord / 255, alphaForCoord);
2815
+ }
2816
+ _setPointsColorOrUV(mesh, pointsGroup, isVolume, colorFromTexture, hasTexture, color, range, uvSetIndex) {
2817
+ uvSetIndex = uvSetIndex ?? 0;
2818
+ if (isVolume) {
2819
+ mesh.updateFacetData();
2820
+ }
2821
+ const boundInfo = mesh.getBoundingInfo();
2822
+ const diameter = 2 * boundInfo.boundingSphere.radius;
2823
+ let meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);
2824
+ const meshInd = mesh.getIndices();
2825
+ const meshUV = mesh.getVerticesData(VertexBuffer.UVKind + (uvSetIndex ? uvSetIndex + 1 : ""));
2826
+ const meshCol = mesh.getVerticesData(VertexBuffer.ColorKind);
2827
+ const place = Vector3.Zero();
2828
+ mesh.computeWorldMatrix();
2829
+ const meshMatrix = mesh.getWorldMatrix();
2830
+ if (!meshMatrix.isIdentity()) {
2831
+ meshPos = meshPos.slice(0);
2832
+ for (let p = 0; p < meshPos.length / 3; p++) {
2833
+ Vector3.TransformCoordinatesFromFloatsToRef(meshPos[3 * p], meshPos[3 * p + 1], meshPos[3 * p + 2], meshMatrix, place);
2834
+ meshPos[3 * p] = place.x;
2835
+ meshPos[3 * p + 1] = place.y;
2836
+ meshPos[3 * p + 2] = place.z;
2837
+ }
2838
+ }
2839
+ let idxPoints = 0;
2840
+ let id0 = 0;
2841
+ let id1 = 0;
2842
+ let id2 = 0;
2843
+ let v0X = 0;
2844
+ let v0Y = 0;
2845
+ let v0Z = 0;
2846
+ let v1X = 0;
2847
+ let v1Y = 0;
2848
+ let v1Z = 0;
2849
+ let v2X = 0;
2850
+ let v2Y = 0;
2851
+ let v2Z = 0;
2852
+ const vertex0 = Vector3.Zero();
2853
+ const vertex1 = Vector3.Zero();
2854
+ const vertex2 = Vector3.Zero();
2855
+ const vec0 = Vector3.Zero();
2856
+ const vec1 = Vector3.Zero();
2857
+ let uv0X = 0;
2858
+ let uv0Y = 0;
2859
+ let uv1X = 0;
2860
+ let uv1Y = 0;
2861
+ let uv2X = 0;
2862
+ let uv2Y = 0;
2863
+ const uv0 = Vector2.Zero();
2864
+ const uv1 = Vector2.Zero();
2865
+ const uv2 = Vector2.Zero();
2866
+ const uvec0 = Vector2.Zero();
2867
+ const uvec1 = Vector2.Zero();
2868
+ let col0X = 0;
2869
+ let col0Y = 0;
2870
+ let col0Z = 0;
2871
+ let col0A = 0;
2872
+ let col1X = 0;
2873
+ let col1Y = 0;
2874
+ let col1Z = 0;
2875
+ let col1A = 0;
2876
+ let col2X = 0;
2877
+ let col2Y = 0;
2878
+ let col2Z = 0;
2879
+ let col2A = 0;
2880
+ const col0 = Vector4.Zero();
2881
+ const col1 = Vector4.Zero();
2882
+ const col2 = Vector4.Zero();
2883
+ const colvec0 = Vector4.Zero();
2884
+ const colvec1 = Vector4.Zero();
2885
+ let lamda = 0;
2886
+ let mu = 0;
2887
+ range = range ? range : 0;
2888
+ let facetPoint;
2889
+ let uvPoint;
2890
+ let colPoint = new Vector4(0, 0, 0, 0);
2891
+ let norm = Vector3.Zero();
2892
+ let tang = Vector3.Zero();
2893
+ let biNorm = Vector3.Zero();
2894
+ let angle = 0;
2895
+ let facetPlaneVec = Vector3.Zero();
2896
+ let gap = 0;
2897
+ let distance = 0;
2898
+ const ray = new Ray(Vector3.Zero(), new Vector3(1, 0, 0));
2899
+ let pickInfo;
2900
+ let direction = Vector3.Zero();
2901
+ for (let index = 0; index < meshInd.length / 3; index++) {
2902
+ id0 = meshInd[3 * index];
2903
+ id1 = meshInd[3 * index + 1];
2904
+ id2 = meshInd[3 * index + 2];
2905
+ v0X = meshPos[3 * id0];
2906
+ v0Y = meshPos[3 * id0 + 1];
2907
+ v0Z = meshPos[3 * id0 + 2];
2908
+ v1X = meshPos[3 * id1];
2909
+ v1Y = meshPos[3 * id1 + 1];
2910
+ v1Z = meshPos[3 * id1 + 2];
2911
+ v2X = meshPos[3 * id2];
2912
+ v2Y = meshPos[3 * id2 + 1];
2913
+ v2Z = meshPos[3 * id2 + 2];
2914
+ vertex0.set(v0X, v0Y, v0Z);
2915
+ vertex1.set(v1X, v1Y, v1Z);
2916
+ vertex2.set(v2X, v2Y, v2Z);
2917
+ vertex1.subtractToRef(vertex0, vec0);
2918
+ vertex2.subtractToRef(vertex1, vec1);
2919
+ if (meshUV) {
2920
+ uv0X = meshUV[2 * id0];
2921
+ uv0Y = meshUV[2 * id0 + 1];
2922
+ uv1X = meshUV[2 * id1];
2923
+ uv1Y = meshUV[2 * id1 + 1];
2924
+ uv2X = meshUV[2 * id2];
2925
+ uv2Y = meshUV[2 * id2 + 1];
2926
+ uv0.set(uv0X, uv0Y);
2927
+ uv1.set(uv1X, uv1Y);
2928
+ uv2.set(uv2X, uv2Y);
2929
+ uv1.subtractToRef(uv0, uvec0);
2930
+ uv2.subtractToRef(uv1, uvec1);
2931
+ }
2932
+ if (meshCol && colorFromTexture) {
2933
+ col0X = meshCol[4 * id0];
2934
+ col0Y = meshCol[4 * id0 + 1];
2935
+ col0Z = meshCol[4 * id0 + 2];
2936
+ col0A = meshCol[4 * id0 + 3];
2937
+ col1X = meshCol[4 * id1];
2938
+ col1Y = meshCol[4 * id1 + 1];
2939
+ col1Z = meshCol[4 * id1 + 2];
2940
+ col1A = meshCol[4 * id1 + 3];
2941
+ col2X = meshCol[4 * id2];
2942
+ col2Y = meshCol[4 * id2 + 1];
2943
+ col2Z = meshCol[4 * id2 + 2];
2944
+ col2A = meshCol[4 * id2 + 3];
2945
+ col0.set(col0X, col0Y, col0Z, col0A);
2946
+ col1.set(col1X, col1Y, col1Z, col1A);
2947
+ col2.set(col2X, col2Y, col2Z, col2A);
2948
+ col1.subtractToRef(col0, colvec0);
2949
+ col2.subtractToRef(col1, colvec1);
2950
+ }
2951
+ let width;
2952
+ let height;
2953
+ let deltaS;
2954
+ let deltaV;
2955
+ let h;
2956
+ let s;
2957
+ let v;
2958
+ let hsvCol;
2959
+ const statedColor = new Color3(0, 0, 0);
2960
+ const colPoint3 = new Color3(0, 0, 0);
2961
+ let pointColors;
2962
+ let particle;
2963
+ for (let i = 0; i < pointsGroup._groupDensity[index]; i++) {
2964
+ idxPoints = this.particles.length;
2965
+ this._addParticle(idxPoints, pointsGroup, this._groupCounter, index + i);
2966
+ particle = this.particles[idxPoints];
2967
+ //form a point inside the facet v0, v1, v2;
2968
+ lamda = Math.sqrt(RandomRange(0, 1));
2969
+ mu = RandomRange(0, 1);
2970
+ facetPoint = vertex0.add(vec0.scale(lamda)).add(vec1.scale(lamda * mu));
2971
+ if (isVolume) {
2972
+ norm = mesh.getFacetNormal(index).normalize().scale(-1);
2973
+ tang = vec0.clone().normalize();
2974
+ biNorm = Vector3.Cross(norm, tang);
2975
+ angle = RandomRange(0, 2 * Math.PI);
2976
+ facetPlaneVec = tang.scale(Math.cos(angle)).add(biNorm.scale(Math.sin(angle)));
2977
+ angle = RandomRange(0.1, Math.PI / 2);
2978
+ direction = facetPlaneVec.scale(Math.cos(angle)).add(norm.scale(Math.sin(angle)));
2979
+ ray.origin = facetPoint.add(direction.scale(0.00001));
2980
+ ray.direction = direction;
2981
+ ray.length = diameter;
2982
+ pickInfo = ray.intersectsMesh(mesh);
2983
+ if (pickInfo.hit) {
2984
+ distance = pickInfo.pickedPoint.subtract(facetPoint).length();
2985
+ gap = RandomRange(0, 1) * distance;
2986
+ facetPoint.addInPlace(direction.scale(gap));
2987
+ }
2988
+ }
2989
+ particle.position = facetPoint.clone();
2990
+ this._positions.push(particle.position.x, particle.position.y, particle.position.z);
2991
+ if (colorFromTexture !== undefined) {
2992
+ if (meshUV) {
2993
+ uvPoint = uv0.add(uvec0.scale(lamda)).add(uvec1.scale(lamda * mu));
2994
+ if (colorFromTexture) {
2995
+ //Set particle color to texture color
2996
+ if (hasTexture && pointsGroup._groupImageData !== null) {
2997
+ width = pointsGroup._groupImgWidth;
2998
+ height = pointsGroup._groupImgHeight;
2999
+ pointColors = this._getColorIndicesForCoord(pointsGroup, Math.round(uvPoint.x * width), Math.round(uvPoint.y * height), width);
3000
+ particle.color = pointColors;
3001
+ this._colors.push(pointColors.r, pointColors.g, pointColors.b, pointColors.a);
3002
+ }
3003
+ else {
3004
+ if (meshCol) {
3005
+ //failure in texture and colors available
3006
+ colPoint = col0.add(colvec0.scale(lamda)).add(colvec1.scale(lamda * mu));
3007
+ particle.color = new Color4(colPoint.x, colPoint.y, colPoint.z, colPoint.w);
3008
+ this._colors.push(colPoint.x, colPoint.y, colPoint.z, colPoint.w);
3009
+ }
3010
+ else {
3011
+ colPoint = col0.set(Math.random(), Math.random(), Math.random(), 1);
3012
+ particle.color = new Color4(colPoint.x, colPoint.y, colPoint.z, colPoint.w);
3013
+ this._colors.push(colPoint.x, colPoint.y, colPoint.z, colPoint.w);
3014
+ }
3015
+ }
3016
+ }
3017
+ else {
3018
+ //Set particle uv based on a mesh uv
3019
+ particle.uv = uvPoint.clone();
3020
+ this._uvs.push(particle.uv.x, particle.uv.y);
3021
+ }
3022
+ }
3023
+ }
3024
+ else {
3025
+ if (color) {
3026
+ statedColor.set(color.r, color.g, color.b);
3027
+ deltaS = RandomRange(-range, range);
3028
+ deltaV = RandomRange(-range, range);
3029
+ hsvCol = statedColor.toHSV();
3030
+ h = hsvCol.r;
3031
+ s = hsvCol.g + deltaS;
3032
+ v = hsvCol.b + deltaV;
3033
+ if (s < 0) {
3034
+ s = 0;
3035
+ }
3036
+ if (s > 1) {
3037
+ s = 1;
3038
+ }
3039
+ if (v < 0) {
3040
+ v = 0;
3041
+ }
3042
+ if (v > 1) {
3043
+ v = 1;
3044
+ }
3045
+ Color3.HSVtoRGBToRef(h, s, v, colPoint3);
3046
+ colPoint.set(colPoint3.r, colPoint3.g, colPoint3.b, 1);
3047
+ }
3048
+ else {
3049
+ colPoint = col0.set(Math.random(), Math.random(), Math.random(), 1);
3050
+ }
3051
+ particle.color = new Color4(colPoint.x, colPoint.y, colPoint.z, colPoint.w);
3052
+ this._colors.push(colPoint.x, colPoint.y, colPoint.z, colPoint.w);
3053
+ }
3054
+ }
3055
+ }
3056
+ }
3057
+ // stores mesh texture in dynamic texture for color pixel retrieval
3058
+ // when pointColor type is color for surface points
3059
+ _colorFromTexture(mesh, pointsGroup, isVolume) {
3060
+ if (mesh.material === null) {
3061
+ Logger.Warn(mesh.name + "has no material.");
3062
+ pointsGroup._groupImageData = null;
3063
+ this._setPointsColorOrUV(mesh, pointsGroup, isVolume, true, false);
3064
+ return;
3065
+ }
3066
+ const mat = mesh.material;
3067
+ const textureList = mat.getActiveTextures();
3068
+ if (textureList.length === 0) {
3069
+ Logger.Warn(mesh.name + "has no usable texture.");
3070
+ pointsGroup._groupImageData = null;
3071
+ this._setPointsColorOrUV(mesh, pointsGroup, isVolume, true, false);
3072
+ return;
3073
+ }
3074
+ const clone = mesh.clone();
3075
+ clone.setEnabled(false);
3076
+ this._promises.push(new Promise((resolve) => {
3077
+ BaseTexture.WhenAllReady(textureList, () => {
3078
+ let n = pointsGroup._textureNb;
3079
+ if (n < 0) {
3080
+ n = 0;
3081
+ }
3082
+ if (n > textureList.length - 1) {
3083
+ n = textureList.length - 1;
3084
+ }
3085
+ const finalize = () => {
3086
+ pointsGroup._groupImgWidth = textureList[n].getSize().width;
3087
+ pointsGroup._groupImgHeight = textureList[n].getSize().height;
3088
+ this._setPointsColorOrUV(clone, pointsGroup, isVolume, true, true, undefined, undefined, textureList[n].coordinatesIndex);
3089
+ clone.dispose();
3090
+ resolve();
3091
+ };
3092
+ pointsGroup._groupImageData = null;
3093
+ const dataPromise = textureList[n].readPixels();
3094
+ if (!dataPromise) {
3095
+ finalize();
3096
+ }
3097
+ else {
3098
+ dataPromise.then((data) => {
3099
+ pointsGroup._groupImageData = data;
3100
+ finalize();
3101
+ });
3102
+ }
3103
+ });
3104
+ }));
3105
+ }
3106
+ // calculates the point density per facet of a mesh for surface points
3107
+ _calculateDensity(nbPoints, positions, indices) {
3108
+ let id0;
3109
+ let id1;
3110
+ let id2;
3111
+ let v0X;
3112
+ let v0Y;
3113
+ let v0Z;
3114
+ let v1X;
3115
+ let v1Y;
3116
+ let v1Z;
3117
+ let v2X;
3118
+ let v2Y;
3119
+ let v2Z;
3120
+ const vertex0 = Vector3.Zero();
3121
+ const vertex1 = Vector3.Zero();
3122
+ const vertex2 = Vector3.Zero();
3123
+ const vec0 = Vector3.Zero();
3124
+ const vec1 = Vector3.Zero();
3125
+ const normal = Vector3.Zero();
3126
+ let area;
3127
+ const cumulativeAreas = [];
3128
+ let surfaceArea = 0;
3129
+ const nbFacets = indices.length / 3;
3130
+ //surface area
3131
+ for (let index = 0; index < nbFacets; index++) {
3132
+ id0 = indices[3 * index];
3133
+ id1 = indices[3 * index + 1];
3134
+ id2 = indices[3 * index + 2];
3135
+ v0X = positions[3 * id0];
3136
+ v0Y = positions[3 * id0 + 1];
3137
+ v0Z = positions[3 * id0 + 2];
3138
+ v1X = positions[3 * id1];
3139
+ v1Y = positions[3 * id1 + 1];
3140
+ v1Z = positions[3 * id1 + 2];
3141
+ v2X = positions[3 * id2];
3142
+ v2Y = positions[3 * id2 + 1];
3143
+ v2Z = positions[3 * id2 + 2];
3144
+ vertex0.set(v0X, v0Y, v0Z);
3145
+ vertex1.set(v1X, v1Y, v1Z);
3146
+ vertex2.set(v2X, v2Y, v2Z);
3147
+ vertex1.subtractToRef(vertex0, vec0);
3148
+ vertex2.subtractToRef(vertex1, vec1);
3149
+ Vector3.CrossToRef(vec0, vec1, normal);
3150
+ area = 0.5 * normal.length();
3151
+ surfaceArea += area;
3152
+ cumulativeAreas[index] = surfaceArea;
3153
+ }
3154
+ const density = new Array(nbFacets);
3155
+ let remainingPoints = nbPoints;
3156
+ for (let index = nbFacets - 1; index > 0; index--) {
3157
+ const cumulativeArea = cumulativeAreas[index];
3158
+ if (cumulativeArea === 0) {
3159
+ // avoiding division by 0 upon degenerate triangles
3160
+ density[index] = 0;
3161
+ }
3162
+ else {
3163
+ const area = cumulativeArea - cumulativeAreas[index - 1];
3164
+ const facetPointsWithFraction = (area / cumulativeArea) * remainingPoints;
3165
+ const floored = Math.floor(facetPointsWithFraction);
3166
+ const fraction = facetPointsWithFraction - floored;
3167
+ const extraPoint = Number(Math.random() < fraction);
3168
+ const facetPoints = floored + extraPoint;
3169
+ density[index] = facetPoints;
3170
+ remainingPoints -= facetPoints;
3171
+ }
3172
+ }
3173
+ density[0] = remainingPoints;
3174
+ return density;
3175
+ }
3176
+ /**
3177
+ * Adds points to the PCS in random positions within a unit sphere
3178
+ * @param nb (positive integer) the number of particles to be created from this model
3179
+ * @param pointFunction is an optional javascript function to be called for each particle on PCS creation
3180
+ * @returns the number of groups in the system
3181
+ */
3182
+ addPoints(nb, pointFunction = this._randomUnitVector) {
3183
+ const pointsGroup = new PointsGroup(this._groupCounter, pointFunction);
3184
+ let cp;
3185
+ // particles
3186
+ let idx = this.nbParticles;
3187
+ for (let i = 0; i < nb; i++) {
3188
+ cp = this._addParticle(idx, pointsGroup, this._groupCounter, i);
3189
+ if (pointsGroup && pointsGroup._positionFunction) {
3190
+ pointsGroup._positionFunction(cp, idx, i);
3191
+ }
3192
+ this._positions.push(cp.position.x, cp.position.y, cp.position.z);
3193
+ if (cp.color) {
3194
+ this._colors.push(cp.color.r, cp.color.g, cp.color.b, cp.color.a);
3195
+ }
3196
+ if (cp.uv) {
3197
+ this._uvs.push(cp.uv.x, cp.uv.y);
3198
+ }
3199
+ idx++;
3200
+ }
3201
+ this.nbParticles += nb;
3202
+ this._groupCounter++;
3203
+ return this._groupCounter;
3204
+ }
3205
+ /**
3206
+ * Adds points to the PCS from the surface of the model shape
3207
+ * @param mesh is any Mesh object that will be used as a surface model for the points
3208
+ * @param nb (positive integer) the number of particles to be created from this model
3209
+ * @param colorWith determines whether a point is colored using color (default), uv, random, stated or none (invisible)
3210
+ * @param color (color4) to be used when colorWith is stated or color (number) when used to specify texture position
3211
+ * @param range (number from 0 to 1) to determine the variation in shape and tone for a stated color
3212
+ * @returns the number of groups in the system
3213
+ */
3214
+ addSurfacePoints(mesh, nb, colorWith, color, range) {
3215
+ let colored = colorWith ? colorWith : 0 /* PointColor.Random */;
3216
+ if (isNaN(colored) || colored < 0 || colored > 3) {
3217
+ colored = 0 /* PointColor.Random */;
3218
+ }
3219
+ const meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);
3220
+ const meshInd = mesh.getIndices();
3221
+ this._groups.push(this._groupCounter);
3222
+ const pointsGroup = new PointsGroup(this._groupCounter, null);
3223
+ pointsGroup._groupDensity = this._calculateDensity(nb, meshPos, meshInd);
3224
+ if (colored === 2 /* PointColor.Color */) {
3225
+ pointsGroup._textureNb = color ? color : 0;
3226
+ }
3227
+ else {
3228
+ color = color ? color : new Color4(1, 1, 1, 1);
3229
+ }
3230
+ switch (colored) {
3231
+ case 2 /* PointColor.Color */:
3232
+ this._colorFromTexture(mesh, pointsGroup, false);
3233
+ break;
3234
+ case 1 /* PointColor.UV */:
3235
+ this._setPointsColorOrUV(mesh, pointsGroup, false, false, false);
3236
+ break;
3237
+ case 0 /* PointColor.Random */:
3238
+ this._setPointsColorOrUV(mesh, pointsGroup, false);
3239
+ break;
3240
+ case 3 /* PointColor.Stated */:
3241
+ this._setPointsColorOrUV(mesh, pointsGroup, false, undefined, undefined, color, range);
3242
+ break;
3243
+ }
3244
+ this.nbParticles += nb;
3245
+ this._groupCounter++;
3246
+ return this._groupCounter - 1;
3247
+ }
3248
+ /**
3249
+ * Adds points to the PCS inside the model shape
3250
+ * @param mesh is any Mesh object that will be used as a surface model for the points
3251
+ * @param nb (positive integer) the number of particles to be created from this model
3252
+ * @param colorWith determines whether a point is colored using color (default), uv, random, stated or none (invisible)
3253
+ * @param color (color4) to be used when colorWith is stated or color (number) when used to specify texture position
3254
+ * @param range (number from 0 to 1) to determine the variation in shape and tone for a stated color
3255
+ * @returns the number of groups in the system
3256
+ */
3257
+ addVolumePoints(mesh, nb, colorWith, color, range) {
3258
+ let colored = colorWith ? colorWith : 0 /* PointColor.Random */;
3259
+ if (isNaN(colored) || colored < 0 || colored > 3) {
3260
+ colored = 0 /* PointColor.Random */;
3261
+ }
3262
+ const meshPos = mesh.getVerticesData(VertexBuffer.PositionKind);
3263
+ const meshInd = mesh.getIndices();
3264
+ this._groups.push(this._groupCounter);
3265
+ const pointsGroup = new PointsGroup(this._groupCounter, null);
3266
+ pointsGroup._groupDensity = this._calculateDensity(nb, meshPos, meshInd);
3267
+ if (colored === 2 /* PointColor.Color */) {
3268
+ pointsGroup._textureNb = color ? color : 0;
3269
+ }
3270
+ else {
3271
+ color = color ? color : new Color4(1, 1, 1, 1);
3272
+ }
3273
+ switch (colored) {
3274
+ case 2 /* PointColor.Color */:
3275
+ this._colorFromTexture(mesh, pointsGroup, true);
3276
+ break;
3277
+ case 1 /* PointColor.UV */:
3278
+ this._setPointsColorOrUV(mesh, pointsGroup, true, false, false);
3279
+ break;
3280
+ case 0 /* PointColor.Random */:
3281
+ this._setPointsColorOrUV(mesh, pointsGroup, true);
3282
+ break;
3283
+ case 3 /* PointColor.Stated */:
3284
+ this._setPointsColorOrUV(mesh, pointsGroup, true, undefined, undefined, color, range);
3285
+ break;
3286
+ }
3287
+ this.nbParticles += nb;
3288
+ this._groupCounter++;
3289
+ return this._groupCounter - 1;
3290
+ }
3291
+ /**
3292
+ * Sets all the particles : this method actually really updates the mesh according to the particle positions, rotations, colors, textures, etc.
3293
+ * This method calls `updateParticle()` for each particle of the SPS.
3294
+ * For an animated SPS, it is usually called within the render loop.
3295
+ * @param start The particle index in the particle array where to start to compute the particle property values _(default 0)_
3296
+ * @param end The particle index in the particle array where to stop to compute the particle property values _(default nbParticle - 1)_
3297
+ * @param update If the mesh must be finally updated on this call after all the particle computations _(default true)_
3298
+ * @returns the PCS.
3299
+ */
3300
+ setParticles(start = 0, end = this.nbParticles - 1, update = true) {
3301
+ if (!this._updatable || !this._isReady) {
3302
+ return this;
3303
+ }
3304
+ // custom beforeUpdate
3305
+ this.beforeUpdateParticles(start, end, update);
3306
+ const rotMatrix = TmpVectors.Matrix[0];
3307
+ const mesh = this.mesh;
3308
+ const colors32 = this._colors32;
3309
+ const positions32 = this._positions32;
3310
+ const uvs32 = this._uvs32;
3311
+ const tempVectors = TmpVectors.Vector3;
3312
+ const camAxisX = tempVectors[5].copyFromFloats(1.0, 0.0, 0.0);
3313
+ const camAxisY = tempVectors[6].copyFromFloats(0.0, 1.0, 0.0);
3314
+ const camAxisZ = tempVectors[7].copyFromFloats(0.0, 0.0, 1.0);
3315
+ const minimum = tempVectors[8].setAll(Number.MAX_VALUE);
3316
+ const maximum = tempVectors[9].setAll(-Number.MAX_VALUE);
3317
+ Matrix.IdentityToRef(rotMatrix);
3318
+ let idx = 0; // current index of the particle
3319
+ if (this.mesh?.isFacetDataEnabled) {
3320
+ this._computeBoundingBox = true;
3321
+ }
3322
+ end = end >= this.nbParticles ? this.nbParticles - 1 : end;
3323
+ if (this._computeBoundingBox) {
3324
+ if (start != 0 || end != this.nbParticles - 1) {
3325
+ // only some particles are updated, then use the current existing BBox basis. Note : it can only increase.
3326
+ const boundingInfo = this.mesh?.getBoundingInfo();
3327
+ if (boundingInfo) {
3328
+ minimum.copyFrom(boundingInfo.minimum);
3329
+ maximum.copyFrom(boundingInfo.maximum);
3330
+ }
3331
+ }
3332
+ }
3333
+ idx = 0; // particle index
3334
+ let pindex = 0; //index in positions array
3335
+ let cindex = 0; //index in color array
3336
+ let uindex = 0; //index in uv array
3337
+ // particle loop
3338
+ for (let p = start; p <= end; p++) {
3339
+ const particle = this.particles[p];
3340
+ idx = particle.idx;
3341
+ pindex = 3 * idx;
3342
+ cindex = 4 * idx;
3343
+ uindex = 2 * idx;
3344
+ // call to custom user function to update the particle properties
3345
+ this.updateParticle(particle);
3346
+ const particleRotationMatrix = particle._rotationMatrix;
3347
+ const particlePosition = particle.position;
3348
+ const particleGlobalPosition = particle._globalPosition;
3349
+ if (this._computeParticleRotation) {
3350
+ particle.getRotationMatrix(rotMatrix);
3351
+ }
3352
+ const particleHasParent = particle.parentId !== null;
3353
+ if (particleHasParent) {
3354
+ const parent = this.particles[particle.parentId];
3355
+ const parentRotationMatrix = parent._rotationMatrix;
3356
+ const parentGlobalPosition = parent._globalPosition;
3357
+ const rotatedY = particlePosition.x * parentRotationMatrix[1] + particlePosition.y * parentRotationMatrix[4] + particlePosition.z * parentRotationMatrix[7];
3358
+ const rotatedX = particlePosition.x * parentRotationMatrix[0] + particlePosition.y * parentRotationMatrix[3] + particlePosition.z * parentRotationMatrix[6];
3359
+ const rotatedZ = particlePosition.x * parentRotationMatrix[2] + particlePosition.y * parentRotationMatrix[5] + particlePosition.z * parentRotationMatrix[8];
3360
+ particleGlobalPosition.x = parentGlobalPosition.x + rotatedX;
3361
+ particleGlobalPosition.y = parentGlobalPosition.y + rotatedY;
3362
+ particleGlobalPosition.z = parentGlobalPosition.z + rotatedZ;
3363
+ if (this._computeParticleRotation) {
3364
+ const rotMatrixValues = rotMatrix.m;
3365
+ particleRotationMatrix[0] =
3366
+ rotMatrixValues[0] * parentRotationMatrix[0] + rotMatrixValues[1] * parentRotationMatrix[3] + rotMatrixValues[2] * parentRotationMatrix[6];
3367
+ particleRotationMatrix[1] =
3368
+ rotMatrixValues[0] * parentRotationMatrix[1] + rotMatrixValues[1] * parentRotationMatrix[4] + rotMatrixValues[2] * parentRotationMatrix[7];
3369
+ particleRotationMatrix[2] =
3370
+ rotMatrixValues[0] * parentRotationMatrix[2] + rotMatrixValues[1] * parentRotationMatrix[5] + rotMatrixValues[2] * parentRotationMatrix[8];
3371
+ particleRotationMatrix[3] =
3372
+ rotMatrixValues[4] * parentRotationMatrix[0] + rotMatrixValues[5] * parentRotationMatrix[3] + rotMatrixValues[6] * parentRotationMatrix[6];
3373
+ particleRotationMatrix[4] =
3374
+ rotMatrixValues[4] * parentRotationMatrix[1] + rotMatrixValues[5] * parentRotationMatrix[4] + rotMatrixValues[6] * parentRotationMatrix[7];
3375
+ particleRotationMatrix[5] =
3376
+ rotMatrixValues[4] * parentRotationMatrix[2] + rotMatrixValues[5] * parentRotationMatrix[5] + rotMatrixValues[6] * parentRotationMatrix[8];
3377
+ particleRotationMatrix[6] =
3378
+ rotMatrixValues[8] * parentRotationMatrix[0] + rotMatrixValues[9] * parentRotationMatrix[3] + rotMatrixValues[10] * parentRotationMatrix[6];
3379
+ particleRotationMatrix[7] =
3380
+ rotMatrixValues[8] * parentRotationMatrix[1] + rotMatrixValues[9] * parentRotationMatrix[4] + rotMatrixValues[10] * parentRotationMatrix[7];
3381
+ particleRotationMatrix[8] =
3382
+ rotMatrixValues[8] * parentRotationMatrix[2] + rotMatrixValues[9] * parentRotationMatrix[5] + rotMatrixValues[10] * parentRotationMatrix[8];
3383
+ }
3384
+ }
3385
+ else {
3386
+ particleGlobalPosition.x = 0;
3387
+ particleGlobalPosition.y = 0;
3388
+ particleGlobalPosition.z = 0;
3389
+ if (this._computeParticleRotation) {
3390
+ const rotMatrixValues = rotMatrix.m;
3391
+ particleRotationMatrix[0] = rotMatrixValues[0];
3392
+ particleRotationMatrix[1] = rotMatrixValues[1];
3393
+ particleRotationMatrix[2] = rotMatrixValues[2];
3394
+ particleRotationMatrix[3] = rotMatrixValues[4];
3395
+ particleRotationMatrix[4] = rotMatrixValues[5];
3396
+ particleRotationMatrix[5] = rotMatrixValues[6];
3397
+ particleRotationMatrix[6] = rotMatrixValues[8];
3398
+ particleRotationMatrix[7] = rotMatrixValues[9];
3399
+ particleRotationMatrix[8] = rotMatrixValues[10];
3400
+ }
3401
+ }
3402
+ const pivotBackTranslation = tempVectors[11];
3403
+ if (particle.translateFromPivot) {
3404
+ pivotBackTranslation.setAll(0.0);
3405
+ }
3406
+ else {
3407
+ pivotBackTranslation.copyFrom(particle.pivot);
3408
+ }
3409
+ // positions
3410
+ const tmpVertex = tempVectors[0];
3411
+ tmpVertex.copyFrom(particle.position);
3412
+ const vertexX = tmpVertex.x - particle.pivot.x;
3413
+ const vertexY = tmpVertex.y - particle.pivot.y;
3414
+ const vertexZ = tmpVertex.z - particle.pivot.z;
3415
+ let rotatedX = vertexX * particleRotationMatrix[0] + vertexY * particleRotationMatrix[3] + vertexZ * particleRotationMatrix[6];
3416
+ let rotatedY = vertexX * particleRotationMatrix[1] + vertexY * particleRotationMatrix[4] + vertexZ * particleRotationMatrix[7];
3417
+ let rotatedZ = vertexX * particleRotationMatrix[2] + vertexY * particleRotationMatrix[5] + vertexZ * particleRotationMatrix[8];
3418
+ rotatedX += pivotBackTranslation.x;
3419
+ rotatedY += pivotBackTranslation.y;
3420
+ rotatedZ += pivotBackTranslation.z;
3421
+ const px = (positions32[pindex] = particleGlobalPosition.x + camAxisX.x * rotatedX + camAxisY.x * rotatedY + camAxisZ.x * rotatedZ);
3422
+ const py = (positions32[pindex + 1] = particleGlobalPosition.y + camAxisX.y * rotatedX + camAxisY.y * rotatedY + camAxisZ.y * rotatedZ);
3423
+ const pz = (positions32[pindex + 2] = particleGlobalPosition.z + camAxisX.z * rotatedX + camAxisY.z * rotatedY + camAxisZ.z * rotatedZ);
3424
+ if (this._computeBoundingBox) {
3425
+ minimum.minimizeInPlaceFromFloats(px, py, pz);
3426
+ maximum.maximizeInPlaceFromFloats(px, py, pz);
3427
+ }
3428
+ if (this._computeParticleColor && particle.color) {
3429
+ const color = particle.color;
3430
+ const colors32 = this._colors32;
3431
+ colors32[cindex] = color.r;
3432
+ colors32[cindex + 1] = color.g;
3433
+ colors32[cindex + 2] = color.b;
3434
+ colors32[cindex + 3] = color.a;
3435
+ }
3436
+ if (this._computeParticleTexture && particle.uv) {
3437
+ const uv = particle.uv;
3438
+ const uvs32 = this._uvs32;
3439
+ uvs32[uindex] = uv.x;
3440
+ uvs32[uindex + 1] = uv.y;
3441
+ }
3442
+ }
3443
+ // if the VBO must be updated
3444
+ if (mesh) {
3445
+ if (update) {
3446
+ if (this._computeParticleColor) {
3447
+ mesh.updateVerticesData(VertexBuffer.ColorKind, colors32, false, false);
3448
+ }
3449
+ if (this._computeParticleTexture) {
3450
+ mesh.updateVerticesData(VertexBuffer.UVKind, uvs32, false, false);
3451
+ }
3452
+ mesh.updateVerticesData(VertexBuffer.PositionKind, positions32, false, false);
3453
+ }
3454
+ if (this._computeBoundingBox) {
3455
+ if (mesh.hasBoundingInfo) {
3456
+ mesh.getBoundingInfo().reConstruct(minimum, maximum, mesh._worldMatrix);
3457
+ }
3458
+ else {
3459
+ mesh.buildBoundingInfo(minimum, maximum, mesh._worldMatrix);
3460
+ }
3461
+ }
3462
+ }
3463
+ this.afterUpdateParticles(start, end, update);
3464
+ return this;
3465
+ }
3466
+ /**
3467
+ * Disposes the PCS.
3468
+ */
3469
+ dispose() {
3470
+ this.mesh?.dispose();
3471
+ this.vars = null;
3472
+ // drop references to internal big arrays for the GC
3473
+ this._positions = null;
3474
+ this._indices = null;
3475
+ this._normals = null;
3476
+ this._uvs = null;
3477
+ this._colors = null;
3478
+ this._indices32 = null;
3479
+ this._positions32 = null;
3480
+ this._uvs32 = null;
3481
+ this._colors32 = null;
3482
+ }
3483
+ /**
3484
+ * Visibility helper : Recomputes the visible size according to the mesh bounding box
3485
+ * doc :
3486
+ * @returns the PCS.
3487
+ */
3488
+ refreshVisibleSize() {
3489
+ if (!this._isVisibilityBoxLocked) {
3490
+ this.mesh?.refreshBoundingInfo();
3491
+ }
3492
+ return this;
3493
+ }
3494
+ /**
3495
+ * Visibility helper : Sets the size of a visibility box, this sets the underlying mesh bounding box.
3496
+ * @param size the size (float) of the visibility box
3497
+ * note : this doesn't lock the PCS mesh bounding box.
3498
+ * doc :
3499
+ */
3500
+ setVisibilityBox(size) {
3501
+ if (!this.mesh) {
3502
+ return;
3503
+ }
3504
+ const vis = size / 2;
3505
+ this.mesh.buildBoundingInfo(new Vector3(-vis, -vis, -vis), new Vector3(vis, vis, vis));
3506
+ }
3507
+ /**
3508
+ * Gets whether the PCS is always visible or not
3509
+ * doc :
3510
+ */
3511
+ get isAlwaysVisible() {
3512
+ return this._alwaysVisible;
3513
+ }
3514
+ /**
3515
+ * Sets the PCS as always visible or not
3516
+ * doc :
3517
+ */
3518
+ set isAlwaysVisible(val) {
3519
+ if (!this.mesh) {
3520
+ return;
3521
+ }
3522
+ this._alwaysVisible = val;
3523
+ this.mesh.alwaysSelectAsActiveMesh = val;
3524
+ }
3525
+ /**
3526
+ * Tells to `setParticles()` to compute the particle rotations or not
3527
+ * Default value : false. The PCS is faster when it's set to false
3528
+ * Note : particle rotations are only applied to parent particles
3529
+ * Note : the particle rotations aren't stored values, so setting `computeParticleRotation` to false will prevents the particle to rotate
3530
+ */
3531
+ set computeParticleRotation(val) {
3532
+ this._computeParticleRotation = val;
3533
+ }
3534
+ /**
3535
+ * Tells to `setParticles()` to compute the particle colors or not.
3536
+ * Default value : true. The PCS is faster when it's set to false.
3537
+ * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
3538
+ */
3539
+ set computeParticleColor(val) {
3540
+ this._computeParticleColor = val;
3541
+ }
3542
+ set computeParticleTexture(val) {
3543
+ this._computeParticleTexture = val;
3544
+ }
3545
+ /**
3546
+ * Gets if `setParticles()` computes the particle colors or not.
3547
+ * Default value : false. The PCS is faster when it's set to false.
3548
+ * Note : the particle colors are stored values, so setting `computeParticleColor` to false will keep yet the last colors set.
3549
+ */
3550
+ get computeParticleColor() {
3551
+ return this._computeParticleColor;
3552
+ }
3553
+ /**
3554
+ * Gets if `setParticles()` computes the particle textures or not.
3555
+ * Default value : false. The PCS is faster when it's set to false.
3556
+ * Note : the particle textures are stored values, so setting `computeParticleTexture` to false will keep yet the last colors set.
3557
+ */
3558
+ get computeParticleTexture() {
3559
+ return this._computeParticleTexture;
3560
+ }
3561
+ /**
3562
+ * Tells to `setParticles()` to compute or not the mesh bounding box when computing the particle positions.
3563
+ */
3564
+ set computeBoundingBox(val) {
3565
+ this._computeBoundingBox = val;
3566
+ }
3567
+ /**
3568
+ * Gets if `setParticles()` computes or not the mesh bounding box when computing the particle positions.
3569
+ */
3570
+ get computeBoundingBox() {
3571
+ return this._computeBoundingBox;
3572
+ }
3573
+ // =======================================================================
3574
+ // Particle behavior logic
3575
+ // these following methods may be overwritten by users to fit their needs
3576
+ /**
3577
+ * This function does nothing. It may be overwritten to set all the particle first values.
3578
+ * The PCS doesn't call this function, you may have to call it by your own.
3579
+ * doc :
3580
+ */
3581
+ initParticles() { }
3582
+ /**
3583
+ * This function does nothing. It may be overwritten to recycle a particle
3584
+ * The PCS doesn't call this function, you can to call it
3585
+ * doc :
3586
+ * @param particle The particle to recycle
3587
+ * @returns the recycled particle
3588
+ */
3589
+ recycleParticle(particle) {
3590
+ return particle;
3591
+ }
3592
+ /**
3593
+ * Updates a particle : this function should be overwritten by the user.
3594
+ * It is called on each particle by `setParticles()`. This is the place to code each particle behavior.
3595
+ * doc :
3596
+ * @example : just set a particle position or velocity and recycle conditions
3597
+ * @param particle The particle to update
3598
+ * @returns the updated particle
3599
+ */
3600
+ updateParticle(particle) {
3601
+ return particle;
3602
+ }
3603
+ /**
3604
+ * This will be called before any other treatment by `setParticles()` and will be passed three parameters.
3605
+ * This does nothing and may be overwritten by the user.
3606
+ * @param start the particle index in the particle array where to start to iterate, same than the value passed to setParticle()
3607
+ * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
3608
+ * @param update the boolean update value actually passed to setParticles()
3609
+ */
3610
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3611
+ beforeUpdateParticles(start, stop, update) { }
3612
+ /**
3613
+ * This will be called by `setParticles()` after all the other treatments and just before the actual mesh update.
3614
+ * This will be passed three parameters.
3615
+ * This does nothing and may be overwritten by the user.
3616
+ * @param start the particle index in the particle array where to start to iterate, same than the value passed to setParticle()
3617
+ * @param stop the particle index in the particle array where to stop to iterate, same than the value passed to setParticle()
3618
+ * @param update the boolean update value actually passed to setParticles()
3619
+ */
3620
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3621
+ afterUpdateParticles(start, stop, update) { }
3622
+ }
3623
+
3624
+ /**
3625
+ * Indicator of the parsed ply buffer. A standard ready to use splat or an array of positions for a point cloud
3626
+ */
3627
+ var Mode;
3628
+ (function (Mode) {
3629
+ Mode[Mode["Splat"] = 0] = "Splat";
3630
+ Mode[Mode["PointCloud"] = 1] = "PointCloud";
3631
+ Mode[Mode["Mesh"] = 2] = "Mesh";
3632
+ })(Mode || (Mode = {}));
3633
+ /**
3634
+ * @experimental
3635
+ * SPLAT file type loader.
3636
+ * This is a babylon scene loader plugin.
3637
+ */
3638
+ class SPLATFileLoader {
3639
+ /**
3640
+ * Creates loader for gaussian splatting files
3641
+ * @param loadingOptions options for loading and parsing splat and PLY files.
3642
+ */
3643
+ constructor(loadingOptions = SPLATFileLoader._DefaultLoadingOptions) {
3644
+ /**
3645
+ * Defines the name of the plugin.
3646
+ */
3647
+ this.name = SPLATFileLoaderMetadata.name;
3648
+ this._assetContainer = null;
3649
+ /**
3650
+ * Defines the extensions the splat loader is able to load.
3651
+ * force data to come in as an ArrayBuffer
3652
+ */
3653
+ this.extensions = SPLATFileLoaderMetadata.extensions;
3654
+ this._loadingOptions = loadingOptions;
3655
+ }
3656
+ /** @internal */
3657
+ createPlugin(options) {
3658
+ return new SPLATFileLoader(options[SPLATFileLoaderMetadata.name]);
3659
+ }
3660
+ /**
3661
+ * Imports from the loaded gaussian splatting data and adds them to the scene
3662
+ * @param meshesNames a string or array of strings of the mesh names that should be loaded from the file
3663
+ * @param scene the scene the meshes should be added to
3664
+ * @param data the gaussian splatting data to load
3665
+ * @param rootUrl root url to load from
3666
+ * @param onProgress callback called while file is loading
3667
+ * @param fileName Defines the name of the file to load
3668
+ * @returns a promise containing the loaded meshes, particles, skeletons and animations
3669
+ */
3670
+ async importMeshAsync(meshesNames, scene, data, rootUrl, onProgress, fileName) {
3671
+ return this._parse(meshesNames, scene, data, rootUrl).then((meshes) => {
3672
+ return {
3673
+ meshes: meshes,
3674
+ particleSystems: [],
3675
+ skeletons: [],
3676
+ animationGroups: [],
3677
+ transformNodes: [],
3678
+ geometries: [],
3679
+ lights: [],
3680
+ spriteManagers: [],
3681
+ };
3682
+ });
3683
+ }
3684
+ static _BuildPointCloud(pointcloud, data) {
3685
+ if (!data.byteLength) {
3686
+ return false;
3687
+ }
3688
+ const uBuffer = new Uint8Array(data);
3689
+ const fBuffer = new Float32Array(data);
3690
+ // parsed array contains room for position(3floats), normal(3floats), color (4b), quantized quaternion (4b)
3691
+ const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
3692
+ const vertexCount = uBuffer.length / rowLength;
3693
+ const pointcloudfunc = function (particle, i) {
3694
+ const x = fBuffer[8 * i + 0];
3695
+ const y = fBuffer[8 * i + 1];
3696
+ const z = fBuffer[8 * i + 2];
3697
+ particle.position = new Vector3(x, y, z);
3698
+ const r = uBuffer[rowLength * i + 24 + 0] / 255;
3699
+ const g = uBuffer[rowLength * i + 24 + 1] / 255;
3700
+ const b = uBuffer[rowLength * i + 24 + 2] / 255;
3701
+ particle.color = new Color4(r, g, b, 1);
3702
+ };
3703
+ pointcloud.addPoints(vertexCount, pointcloudfunc);
3704
+ return true;
3705
+ }
3706
+ static _BuildMesh(scene, parsedPLY) {
3707
+ const mesh = new Mesh("PLYMesh", scene);
3708
+ const uBuffer = new Uint8Array(parsedPLY.data);
3709
+ const fBuffer = new Float32Array(parsedPLY.data);
3710
+ const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
3711
+ const vertexCount = uBuffer.length / rowLength;
3712
+ const positions = [];
3713
+ const vertexData = new VertexData();
3714
+ for (let i = 0; i < vertexCount; i++) {
3715
+ const x = fBuffer[8 * i + 0];
3716
+ const y = fBuffer[8 * i + 1];
3717
+ const z = fBuffer[8 * i + 2];
3718
+ positions.push(x, y, z);
3719
+ }
3720
+ if (parsedPLY.hasVertexColors) {
3721
+ const colors = new Float32Array(vertexCount * 4);
3722
+ for (let i = 0; i < vertexCount; i++) {
3723
+ const r = uBuffer[rowLength * i + 24 + 0] / 255;
3724
+ const g = uBuffer[rowLength * i + 24 + 1] / 255;
3725
+ const b = uBuffer[rowLength * i + 24 + 2] / 255;
3726
+ colors[i * 4 + 0] = r;
3727
+ colors[i * 4 + 1] = g;
3728
+ colors[i * 4 + 2] = b;
3729
+ colors[i * 4 + 3] = 1;
3730
+ }
3731
+ vertexData.colors = colors;
3732
+ }
3733
+ vertexData.positions = positions;
3734
+ vertexData.indices = parsedPLY.faces;
3735
+ vertexData.applyToMesh(mesh);
3736
+ return mesh;
3737
+ }
3738
+ _parse(meshesNames, scene, data, rootUrl) {
3739
+ return SPLATFileLoader._ConvertPLYToSplat(data).then(async (parsedPLY) => {
3740
+ const babylonMeshesArray = []; //The mesh for babylon
3741
+ switch (parsedPLY.mode) {
3742
+ case 0 /* Mode.Splat */:
3743
+ {
3744
+ const gaussianSplatting = new GaussianSplattingMesh("GaussianSplatting", null, scene, this._loadingOptions.keepInRam);
3745
+ gaussianSplatting._parentContainer = this._assetContainer;
3746
+ babylonMeshesArray.push(gaussianSplatting);
3747
+ await gaussianSplatting.updateDataAsync(parsedPLY.data);
3748
+ }
3749
+ break;
3750
+ case 1 /* Mode.PointCloud */:
3751
+ {
3752
+ const pointcloud = new PointsCloudSystem("PointCloud", 1, scene);
3753
+ if (SPLATFileLoader._BuildPointCloud(pointcloud, parsedPLY.data)) {
3754
+ return Promise.all([pointcloud.buildMeshAsync()]).then((mesh) => {
3755
+ babylonMeshesArray.push(mesh[0]);
3756
+ return babylonMeshesArray;
3757
+ });
3758
+ }
3759
+ else {
3760
+ pointcloud.dispose();
3761
+ }
3762
+ }
3763
+ break;
3764
+ case 2 /* Mode.Mesh */:
3765
+ {
3766
+ if (parsedPLY.faces) {
3767
+ babylonMeshesArray.push(SPLATFileLoader._BuildMesh(scene, parsedPLY));
3768
+ }
3769
+ else {
3770
+ throw new Error("PLY mesh doesn't contain face informations.");
3771
+ }
3772
+ }
3773
+ break;
3774
+ default:
3775
+ throw new Error("Unsupported Splat mode");
3776
+ }
3777
+ return new Promise((resolve) => {
3778
+ resolve(babylonMeshesArray);
3779
+ });
3780
+ });
3781
+ }
3782
+ /**
3783
+ * Load into an asset container.
3784
+ * @param scene The scene to load into
3785
+ * @param data The data to import
3786
+ * @param rootUrl The root url for scene and resources
3787
+ * @returns The loaded asset container
3788
+ */
3789
+ loadAssetContainerAsync(scene, data, rootUrl) {
3790
+ const container = new AssetContainer(scene);
3791
+ this._assetContainer = container;
3792
+ return this.importMeshAsync(null, scene, data, rootUrl)
3793
+ .then((result) => {
3794
+ result.meshes.forEach((mesh) => container.meshes.push(mesh));
3795
+ // mesh material will be null before 1st rendered frame.
3796
+ this._assetContainer = null;
3797
+ return container;
3798
+ })
3799
+ .catch((ex) => {
3800
+ this._assetContainer = null;
3801
+ throw ex;
3802
+ });
3803
+ }
3804
+ /**
3805
+ * Imports all objects from the loaded OBJ data and adds them to the scene
3806
+ * @param scene the scene the objects should be added to
3807
+ * @param data the OBJ data to load
3808
+ * @param rootUrl root url to load from
3809
+ * @returns a promise which completes when objects have been loaded to the scene
3810
+ */
3811
+ loadAsync(scene, data, rootUrl) {
3812
+ //Get the 3D model
3813
+ return this.importMeshAsync(null, scene, data, rootUrl).then(() => {
3814
+ // return void
3815
+ });
3816
+ }
3817
+ /**
3818
+ * Code from https://github.com/dylanebert/gsplat.js/blob/main/src/loaders/PLYLoader.ts Under MIT license
3819
+ * Converts a .ply data array buffer to splat
3820
+ * if data array buffer is not ply, returns the original buffer
3821
+ * @param data the .ply data to load
3822
+ * @returns the loaded splat buffer
3823
+ */
3824
+ static _ConvertPLYToSplat(data) {
3825
+ const ubuf = new Uint8Array(data);
3826
+ const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));
3827
+ const headerEnd = "end_header\n";
3828
+ const headerEndIndex = header.indexOf(headerEnd);
3829
+ if (headerEndIndex < 0 || !header) {
3830
+ // standard splat
3831
+ return new Promise((resolve) => {
3832
+ resolve({ mode: 0 /* Mode.Splat */, data: data });
3833
+ });
3834
+ }
3835
+ const vertexCount = parseInt(/element vertex (\d+)\n/.exec(header)[1]);
3836
+ const faceElement = /element face (\d+)\n/.exec(header);
3837
+ let faceCount = 0;
3838
+ if (faceElement) {
3839
+ faceCount = parseInt(faceElement[1]);
3840
+ }
3841
+ const chunkElement = /element chunk (\d+)\n/.exec(header);
3842
+ let chunkCount = 0;
3843
+ if (chunkElement) {
3844
+ chunkCount = parseInt(chunkElement[1]);
3845
+ }
3846
+ let rowVertexOffset = 0;
3847
+ let rowChunkOffset = 0;
3848
+ const offsets = {
3849
+ double: 8,
3850
+ int: 4,
3851
+ uint: 4,
3852
+ float: 4,
3853
+ short: 2,
3854
+ ushort: 2,
3855
+ uchar: 1,
3856
+ list: 0,
3857
+ };
3858
+ let ElementMode;
3859
+ (function (ElementMode) {
3860
+ ElementMode[ElementMode["Vertex"] = 0] = "Vertex";
3861
+ ElementMode[ElementMode["Chunk"] = 1] = "Chunk";
3862
+ })(ElementMode || (ElementMode = {}));
3863
+ let chunkMode = 1 /* ElementMode.Chunk */;
3864
+ const vertexProperties = [];
3865
+ const filtered = header.slice(0, headerEndIndex).split("\n");
3866
+ for (const prop of filtered) {
3867
+ if (prop.startsWith("property ")) {
3868
+ const [, type, name] = prop.split(" ");
3869
+ if (chunkMode == 1 /* ElementMode.Chunk */) {
3870
+ rowChunkOffset += offsets[type];
3871
+ }
3872
+ else if (chunkMode == 0 /* ElementMode.Vertex */) {
3873
+ vertexProperties.push({ name, type, offset: rowVertexOffset });
3874
+ rowVertexOffset += offsets[type];
3875
+ }
3876
+ if (!offsets[type]) {
3877
+ Logger.Warn(`Unsupported property type: ${type}.`);
3878
+ }
3879
+ }
3880
+ else if (prop.startsWith("element ")) {
3881
+ const [, type] = prop.split(" ");
3882
+ if (type == "chunk") {
3883
+ chunkMode = 1 /* ElementMode.Chunk */;
3884
+ }
3885
+ else if (type == "vertex") {
3886
+ chunkMode = 0 /* ElementMode.Vertex */;
3887
+ }
3888
+ }
3889
+ }
3890
+ const rowVertexLength = rowVertexOffset;
3891
+ const rowChunkLength = rowChunkOffset;
3892
+ return GaussianSplattingMesh.ConvertPLYToSplatAsync(data).then((buffer) => {
3893
+ const dataView = new DataView(data, headerEndIndex + headerEnd.length);
3894
+ let offset = rowChunkLength * chunkCount + rowVertexLength * vertexCount;
3895
+ // faces
3896
+ const faces = [];
3897
+ if (faceCount) {
3898
+ for (let i = 0; i < faceCount; i++) {
3899
+ const faceVertexCount = dataView.getUint8(offset);
3900
+ if (faceVertexCount != 3) {
3901
+ continue; // only support triangles
3902
+ }
3903
+ offset += 1;
3904
+ for (let j = 0; j < faceVertexCount; j++) {
3905
+ const vertexIndex = dataView.getUint32(offset + (2 - j) * 4, true); // change face winding
3906
+ faces.push(vertexIndex);
3907
+ }
3908
+ offset += 12;
3909
+ }
3910
+ }
3911
+ // early exit for chunked/quantized ply
3912
+ if (chunkCount) {
3913
+ return new Promise((resolve) => {
3914
+ resolve({ mode: 0 /* Mode.Splat */, data: buffer, faces: faces, hasVertexColors: false });
3915
+ });
3916
+ }
3917
+ // count available properties. if all necessary are present then it's a splat. Otherwise, it's a point cloud
3918
+ // if faces are found, then it's a standard mesh
3919
+ let propertyCount = 0;
3920
+ let propertyColorCount = 0;
3921
+ const splatProperties = ["x", "y", "z", "scale_0", "scale_1", "scale_2", "opacity", "rot_0", "rot_1", "rot_2", "rot_3"];
3922
+ const splatColorProperties = ["red", "green", "blue", "f_dc_0", "f_dc_1", "f_dc_2"];
3923
+ for (let propertyIndex = 0; propertyIndex < vertexProperties.length; propertyIndex++) {
3924
+ const property = vertexProperties[propertyIndex];
3925
+ if (splatProperties.includes(property.name)) {
3926
+ propertyCount++;
3927
+ }
3928
+ if (splatColorProperties.includes(property.name)) {
3929
+ propertyColorCount++;
3930
+ }
3931
+ }
3932
+ const hasMandatoryProperties = propertyCount == splatProperties.length && propertyColorCount == 3;
3933
+ const currentMode = faceCount ? 2 /* Mode.Mesh */ : hasMandatoryProperties ? 0 /* Mode.Splat */ : 1 /* Mode.PointCloud */;
3934
+ // parsed ready ready to be used as a splat
3935
+ return new Promise((resolve) => {
3936
+ resolve({ mode: currentMode, data: buffer, faces: faces, hasVertexColors: !!propertyColorCount });
3937
+ });
3938
+ });
3939
+ }
3940
+ }
3941
+ SPLATFileLoader._DefaultLoadingOptions = {
3942
+ keepInRam: false,
3943
+ };
3944
+ // Add this loader into the register plugin
3945
+ registerSceneLoaderPlugin(new SPLATFileLoader());
3946
+
3947
+ export { SPLATFileLoader };
3948
+ //# sourceMappingURL=splatFileLoader-Ci35-grq.esm.js.map