@babylonjs/viewer 7.31.1-alpha → 7.31.2

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