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