@babylonjs/viewer 7.37.1-alpha → 7.37.1

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