@babylonjs/viewer 7.28.0-alpha → 7.29.0

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