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