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