@zephyr3d/scene 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (754) hide show
  1. package/dist/animation/animation.js +142 -31
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +186 -73
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +66 -10
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +40 -20
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/morphtarget.js +20 -38
  10. package/dist/animation/morphtarget.js.map +1 -1
  11. package/dist/animation/morphtrack.js +59 -22
  12. package/dist/animation/morphtrack.js.map +1 -1
  13. package/dist/animation/proptrack.js +186 -0
  14. package/dist/animation/proptrack.js.map +1 -0
  15. package/dist/animation/rotationtrack.js +28 -11
  16. package/dist/animation/rotationtrack.js.map +1 -1
  17. package/dist/animation/scaletrack.js +28 -11
  18. package/dist/animation/scaletrack.js.map +1 -1
  19. package/dist/animation/skeleton.js +238 -82
  20. package/dist/animation/skeleton.js.map +1 -1
  21. package/dist/animation/translationtrack.js +29 -11
  22. package/dist/animation/translationtrack.js.map +1 -1
  23. package/dist/app/api.js +52 -0
  24. package/dist/app/api.js.map +1 -0
  25. package/dist/app/app.js +165 -0
  26. package/dist/app/app.js.map +1 -0
  27. package/dist/app/engine.js +300 -0
  28. package/dist/app/engine.js.map +1 -0
  29. package/dist/app/inputmgr.js +351 -0
  30. package/dist/app/inputmgr.js.map +1 -0
  31. package/dist/app/runtimescript.js +62 -0
  32. package/dist/app/runtimescript.js.map +1 -0
  33. package/dist/app/screen.js +318 -0
  34. package/dist/app/screen.js.map +1 -0
  35. package/dist/app/scriptingsystem.js +224 -0
  36. package/dist/app/scriptingsystem.js.map +1 -0
  37. package/dist/app/scriptregistry.js +421 -0
  38. package/dist/app/scriptregistry.js.map +1 -0
  39. package/dist/asset/assetmanager.js +823 -321
  40. package/dist/asset/assetmanager.js.map +1 -1
  41. package/dist/asset/builtin.js +12 -48
  42. package/dist/asset/builtin.js.map +1 -1
  43. package/dist/asset/loaders/dds/dds.js +23 -95
  44. package/dist/asset/loaders/dds/dds.js.map +1 -1
  45. package/dist/asset/loaders/dds/dds_loader.js +9 -19
  46. package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
  47. package/dist/asset/loaders/gltf/gltf_loader.js +50 -48
  48. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  49. package/dist/asset/loaders/gltf/helpers.js +33 -16
  50. package/dist/asset/loaders/gltf/helpers.js.map +1 -1
  51. package/dist/asset/loaders/hdr/hdr.js +39 -27
  52. package/dist/asset/loaders/hdr/hdr.js.map +1 -1
  53. package/dist/asset/loaders/image/tga_Loader.js +15 -17
  54. package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
  55. package/dist/asset/loaders/image/webimage_loader.js +51 -50
  56. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  57. package/dist/asset/loaders/loader.js +2 -2
  58. package/dist/asset/loaders/loader.js.map +1 -1
  59. package/dist/asset/model.js +160 -6
  60. package/dist/asset/model.js.map +1 -1
  61. package/dist/blitter/bilateralblur.js +0 -1
  62. package/dist/blitter/bilateralblur.js.map +1 -1
  63. package/dist/blitter/blitter.js +28 -31
  64. package/dist/blitter/blitter.js.map +1 -1
  65. package/dist/blitter/box.js +0 -1
  66. package/dist/blitter/box.js.map +1 -1
  67. package/dist/blitter/copy.js.map +1 -1
  68. package/dist/blitter/gaussianblur.js +23 -23
  69. package/dist/blitter/gaussianblur.js.map +1 -1
  70. package/dist/camera/base.js +139 -34
  71. package/dist/camera/base.js.map +1 -1
  72. package/dist/camera/camera.js +760 -172
  73. package/dist/camera/camera.js.map +1 -1
  74. package/dist/camera/fps.js +21 -27
  75. package/dist/camera/fps.js.map +1 -1
  76. package/dist/camera/orbit.js +134 -59
  77. package/dist/camera/orbit.js.map +1 -1
  78. package/dist/camera/orthocamera.js +52 -21
  79. package/dist/camera/orthocamera.js.map +1 -1
  80. package/dist/camera/perspectivecamera.js +60 -34
  81. package/dist/camera/perspectivecamera.js.map +1 -1
  82. package/dist/index.d.ts +17031 -6901
  83. package/dist/index.js +60 -21
  84. package/dist/index.js.map +1 -1
  85. package/dist/material/blinn.js +5 -0
  86. package/dist/material/blinn.js.map +1 -1
  87. package/dist/material/grassmaterial.js +6 -1
  88. package/dist/material/grassmaterial.js.map +1 -1
  89. package/dist/material/lambert.js +6 -1
  90. package/dist/material/lambert.js.map +1 -1
  91. package/dist/material/material.js +356 -77
  92. package/dist/material/material.js.map +1 -1
  93. package/dist/material/meshmaterial.js +505 -162
  94. package/dist/material/meshmaterial.js.map +1 -1
  95. package/dist/material/mixins/albedocolor.js +5 -1
  96. package/dist/material/mixins/albedocolor.js.map +1 -1
  97. package/dist/material/mixins/foliage.js +3 -3
  98. package/dist/material/mixins/foliage.js.map +1 -1
  99. package/dist/material/mixins/lightmodel/blinnphong.js +18 -5
  100. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  101. package/dist/material/mixins/lightmodel/lambert.js +6 -6
  102. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  103. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +242 -0
  104. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -0
  105. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +52 -15
  106. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  107. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +27 -9
  108. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  109. package/dist/material/mixins/lit.js +19 -7
  110. package/dist/material/mixins/lit.js.map +1 -1
  111. package/dist/material/mixins/pbr/brdf.js +134 -0
  112. package/dist/material/mixins/pbr/brdf.js.map +1 -0
  113. package/dist/material/mixins/pbr/common.js +68 -85
  114. package/dist/material/mixins/pbr/common.js.map +1 -1
  115. package/dist/material/mixins/texture.js +101 -83
  116. package/dist/material/mixins/texture.js.map +1 -1
  117. package/dist/material/mixins/vertexcolor.js +6 -2
  118. package/dist/material/mixins/vertexcolor.js.map +1 -1
  119. package/dist/material/particle.js +272 -0
  120. package/dist/material/particle.js.map +1 -0
  121. package/dist/material/pbrblueprint.js +344 -0
  122. package/dist/material/pbrblueprint.js.map +1 -0
  123. package/dist/material/pbrmr.js +10 -0
  124. package/dist/material/pbrmr.js.map +1 -1
  125. package/dist/material/pbrsg.js +10 -0
  126. package/dist/material/pbrsg.js.map +1 -1
  127. package/dist/material/shader/helper.js +533 -316
  128. package/dist/material/shader/helper.js.map +1 -1
  129. package/dist/material/sprite.js +301 -0
  130. package/dist/material/sprite.js.map +1 -0
  131. package/dist/material/sprite3d.js +301 -0
  132. package/dist/material/sprite3d.js.map +1 -0
  133. package/dist/material/sprite3d_std.js +116 -0
  134. package/dist/material/sprite3d_std.js.map +1 -0
  135. package/dist/material/sprite3dblueprint.js +235 -0
  136. package/dist/material/sprite3dblueprint.js.map +1 -0
  137. package/dist/material/sprite_std.js +116 -0
  138. package/dist/material/sprite_std.js.map +1 -0
  139. package/dist/material/spriteblueprint.js +235 -0
  140. package/dist/material/spriteblueprint.js.map +1 -0
  141. package/dist/material/terrain-cm.js +606 -0
  142. package/dist/material/terrain-cm.js.map +1 -0
  143. package/dist/material/terrainmaterial.js +59 -54
  144. package/dist/material/terrainmaterial.js.map +1 -1
  145. package/dist/material/unlit.js +5 -0
  146. package/dist/material/unlit.js.map +1 -1
  147. package/dist/material/water.js +415 -0
  148. package/dist/material/water.js.map +1 -0
  149. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
  150. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
  151. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
  152. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
  153. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
  154. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
  155. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
  156. package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
  157. package/dist/node_modules/es-module-lexer/dist/lexer.js +5 -0
  158. package/dist/node_modules/es-module-lexer/dist/lexer.js.map +1 -0
  159. package/dist/posteffect/bloom.js +39 -54
  160. package/dist/posteffect/bloom.js.map +1 -1
  161. package/dist/posteffect/compositor.js +95 -128
  162. package/dist/posteffect/compositor.js.map +1 -1
  163. package/dist/posteffect/fxaa.js +10 -18
  164. package/dist/posteffect/fxaa.js.map +1 -1
  165. package/dist/posteffect/grayscale.js +9 -17
  166. package/dist/posteffect/grayscale.js.map +1 -1
  167. package/dist/posteffect/motionblur.js +105 -0
  168. package/dist/posteffect/motionblur.js.map +1 -0
  169. package/dist/posteffect/posteffect.js +66 -35
  170. package/dist/posteffect/posteffect.js.map +1 -1
  171. package/dist/posteffect/sao.js +13 -21
  172. package/dist/posteffect/sao.js.map +1 -1
  173. package/dist/posteffect/ssr.js +65 -103
  174. package/dist/posteffect/ssr.js.map +1 -1
  175. package/dist/posteffect/taa.js +175 -0
  176. package/dist/posteffect/taa.js.map +1 -0
  177. package/dist/posteffect/tonemap.js +12 -20
  178. package/dist/posteffect/tonemap.js.map +1 -1
  179. package/dist/render/abuffer_oit.js +38 -25
  180. package/dist/render/abuffer_oit.js.map +1 -1
  181. package/dist/render/clipmap.js +424 -106
  182. package/dist/render/clipmap.js.map +1 -1
  183. package/dist/render/cluster_light.js +11 -9
  184. package/dist/render/cluster_light.js.map +1 -1
  185. package/dist/render/cull_visitor.js +51 -13
  186. package/dist/render/cull_visitor.js.map +1 -1
  187. package/dist/render/depthpass.js +15 -7
  188. package/dist/render/depthpass.js.map +1 -1
  189. package/dist/render/drawable.js +15 -0
  190. package/dist/render/drawable.js.map +1 -0
  191. package/dist/render/drawable_mixin.js +121 -44
  192. package/dist/render/drawable_mixin.js.map +1 -1
  193. package/dist/render/envlight.js +86 -141
  194. package/dist/render/envlight.js.map +1 -1
  195. package/dist/render/fbm_wavegenerator.js +236 -0
  196. package/dist/render/fbm_wavegenerator.js.map +1 -0
  197. package/dist/render/fft_wavegenerator.js +131 -114
  198. package/dist/render/fft_wavegenerator.js.map +1 -1
  199. package/dist/render/fullscreenquad.js +2 -2
  200. package/dist/render/fullscreenquad.js.map +1 -1
  201. package/dist/render/gerstner_wavegenerator.js +100 -48
  202. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  203. package/dist/render/globalbindgroup_allocator.js +7 -3
  204. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  205. package/dist/render/hzb.js +7 -5
  206. package/dist/render/hzb.js.map +1 -1
  207. package/dist/render/lightpass.js +28 -27
  208. package/dist/render/lightpass.js.map +1 -1
  209. package/dist/render/objectcolorpass.js +6 -9
  210. package/dist/render/objectcolorpass.js.map +1 -1
  211. package/dist/render/primitive.js +213 -105
  212. package/dist/render/primitive.js.map +1 -1
  213. package/dist/render/render_queue.js +49 -24
  214. package/dist/render/render_queue.js.map +1 -1
  215. package/dist/render/renderbundle_wrapper.js +65 -15
  216. package/dist/render/renderbundle_wrapper.js.map +1 -1
  217. package/dist/render/renderer.js +324 -189
  218. package/dist/render/renderer.js.map +1 -1
  219. package/dist/render/renderpass.js +43 -84
  220. package/dist/render/renderpass.js.map +1 -1
  221. package/dist/render/rendertarget.js +5 -0
  222. package/dist/render/rendertarget.js.map +1 -0
  223. package/dist/render/screenrendertarget.js +56 -0
  224. package/dist/render/screenrendertarget.js.map +1 -0
  225. package/dist/render/shadowmap_pass.js +5 -6
  226. package/dist/render/shadowmap_pass.js.map +1 -1
  227. package/dist/render/sky.js +867 -542
  228. package/dist/render/sky.js.map +1 -1
  229. package/dist/render/weightedblended_oit.js +13 -15
  230. package/dist/render/weightedblended_oit.js.map +1 -1
  231. package/dist/scene/basesprite.js +296 -0
  232. package/dist/scene/basesprite.js.map +1 -0
  233. package/dist/scene/batchgroup.js +22 -7
  234. package/dist/scene/batchgroup.js.map +1 -1
  235. package/dist/scene/environment.js +78 -49
  236. package/dist/scene/environment.js.map +1 -1
  237. package/dist/scene/graph_node.js +2 -3
  238. package/dist/scene/graph_node.js.map +1 -1
  239. package/dist/scene/light.js +49 -92
  240. package/dist/scene/light.js.map +1 -1
  241. package/dist/scene/mesh.js +298 -89
  242. package/dist/scene/mesh.js.map +1 -1
  243. package/dist/scene/octree.js +371 -162
  244. package/dist/scene/octree.js.map +1 -1
  245. package/dist/scene/particlesys.js +687 -0
  246. package/dist/scene/particlesys.js.map +1 -0
  247. package/dist/scene/raycast_visitor.js +26 -13
  248. package/dist/scene/raycast_visitor.js.map +1 -1
  249. package/dist/scene/scene.js +312 -85
  250. package/dist/scene/scene.js.map +1 -1
  251. package/dist/scene/scene_node.js +663 -105
  252. package/dist/scene/scene_node.js.map +1 -1
  253. package/dist/scene/sprite.js +18 -0
  254. package/dist/scene/sprite.js.map +1 -0
  255. package/dist/scene/sprite3d.js +18 -0
  256. package/dist/scene/sprite3d.js.map +1 -0
  257. package/dist/scene/terrain/grass.js +48 -49
  258. package/dist/scene/terrain/grass.js.map +1 -1
  259. package/dist/scene/terrain/heightfield.js +46 -44
  260. package/dist/scene/terrain/heightfield.js.map +1 -1
  261. package/dist/scene/terrain/patch.js +20 -29
  262. package/dist/scene/terrain/patch.js.map +1 -1
  263. package/dist/scene/terrain/quadtree.js +58 -27
  264. package/dist/scene/terrain/quadtree.js.map +1 -1
  265. package/dist/scene/terrain/terrain.js +31 -45
  266. package/dist/scene/terrain/terrain.js.map +1 -1
  267. package/dist/scene/terrain-cm/grass.js +604 -0
  268. package/dist/scene/terrain-cm/grass.js.map +1 -0
  269. package/dist/scene/terrain-cm/grassmaterial.js +162 -0
  270. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -0
  271. package/dist/scene/terrain-cm/terrain-cm.js +550 -0
  272. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -0
  273. package/dist/scene/water.js +383 -0
  274. package/dist/scene/water.js.map +1 -0
  275. package/dist/shaders/atmosphere.js +945 -0
  276. package/dist/shaders/atmosphere.js.map +1 -0
  277. package/dist/shaders/fog.js +116 -0
  278. package/dist/shaders/fog.js.map +1 -0
  279. package/dist/shaders/misc.js.map +1 -1
  280. package/dist/shaders/noise.js +217 -8
  281. package/dist/shaders/noise.js.map +1 -1
  282. package/dist/shaders/pbr.js.map +1 -1
  283. package/dist/shaders/shadow.js +8 -8
  284. package/dist/shaders/shadow.js.map +1 -1
  285. package/dist/shaders/ssr.js +87 -39
  286. package/dist/shaders/ssr.js.map +1 -1
  287. package/dist/shaders/temporal.js +216 -0
  288. package/dist/shaders/temporal.js.map +1 -0
  289. package/dist/shaders/water.js +42 -20
  290. package/dist/shaders/water.js.map +1 -1
  291. package/dist/shadow/esm.js +32 -14
  292. package/dist/shadow/esm.js.map +1 -1
  293. package/dist/shadow/pcf_opt.js +12 -13
  294. package/dist/shadow/pcf_opt.js.map +1 -1
  295. package/dist/shadow/pcf_pd.js +12 -13
  296. package/dist/shadow/pcf_pd.js.map +1 -1
  297. package/dist/shadow/shader.js +40 -0
  298. package/dist/shadow/shader.js.map +1 -0
  299. package/dist/shadow/shadow_impl.js.map +1 -1
  300. package/dist/shadow/shadowmapper.js +73 -44
  301. package/dist/shadow/shadowmapper.js.map +1 -1
  302. package/dist/shadow/ssm.js +15 -16
  303. package/dist/shadow/ssm.js.map +1 -1
  304. package/dist/shadow/vsm.js +33 -16
  305. package/dist/shadow/vsm.js.map +1 -1
  306. package/dist/shapes/box.js +187 -83
  307. package/dist/shapes/box.js.map +1 -1
  308. package/dist/shapes/cylinder.js +101 -43
  309. package/dist/shapes/cylinder.js.map +1 -1
  310. package/dist/shapes/plane.js +70 -29
  311. package/dist/shapes/plane.js.map +1 -1
  312. package/dist/shapes/shape.js +121 -17
  313. package/dist/shapes/shape.js.map +1 -1
  314. package/dist/shapes/sphere.js +78 -44
  315. package/dist/shapes/sphere.js.map +1 -1
  316. package/dist/shapes/tetrahedron.js +255 -0
  317. package/dist/shapes/tetrahedron.js.map +1 -0
  318. package/dist/shapes/torus.js +76 -55
  319. package/dist/shapes/torus.js.map +1 -1
  320. package/dist/src/animation/animation.js +127 -0
  321. package/dist/src/animation/animation.js.map +1 -0
  322. package/dist/src/animation/animationset.js +255 -0
  323. package/dist/src/animation/animationset.js.map +1 -0
  324. package/dist/src/animation/animationtrack.js +34 -0
  325. package/dist/src/animation/animationtrack.js.map +1 -0
  326. package/dist/src/animation/eulerrotationtrack.js +52 -0
  327. package/dist/src/animation/eulerrotationtrack.js.map +1 -0
  328. package/dist/src/animation/morphtarget.js +93 -0
  329. package/dist/src/animation/morphtarget.js.map +1 -0
  330. package/dist/src/animation/morphtrack.js +70 -0
  331. package/dist/src/animation/morphtrack.js.map +1 -0
  332. package/dist/src/animation/proptrack.js +161 -0
  333. package/dist/src/animation/proptrack.js.map +1 -0
  334. package/dist/src/animation/rotationtrack.js +51 -0
  335. package/dist/src/animation/rotationtrack.js.map +1 -0
  336. package/dist/src/animation/scaletrack.js +50 -0
  337. package/dist/src/animation/scaletrack.js.map +1 -0
  338. package/dist/src/animation/skeleton.js +204 -0
  339. package/dist/src/animation/skeleton.js.map +1 -0
  340. package/dist/src/animation/translationtrack.js +50 -0
  341. package/dist/src/animation/translationtrack.js.map +1 -0
  342. package/dist/{app.js → src/app/app.js} +18 -40
  343. package/dist/src/app/app.js.map +1 -0
  344. package/dist/{input → src/app}/inputmgr.js +41 -16
  345. package/dist/src/app/inputmgr.js.map +1 -0
  346. package/dist/src/asset/assetmanager.js +404 -0
  347. package/dist/src/asset/assetmanager.js.map +1 -0
  348. package/dist/src/asset/builtin.js +337 -0
  349. package/dist/src/asset/builtin.js.map +1 -0
  350. package/dist/src/asset/loaders/dds/dds.js +470 -0
  351. package/dist/src/asset/loaders/dds/dds.js.map +1 -0
  352. package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
  353. package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
  354. package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
  355. package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
  356. package/dist/src/asset/loaders/gltf/helpers.js +327 -0
  357. package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
  358. package/dist/src/asset/loaders/hdr/hdr.js +180 -0
  359. package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
  360. package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
  361. package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
  362. package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
  363. package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
  364. package/dist/src/asset/loaders/loader.js +45 -0
  365. package/dist/src/asset/loaders/loader.js.map +1 -0
  366. package/dist/src/asset/model.js +414 -0
  367. package/dist/src/asset/model.js.map +1 -0
  368. package/dist/{blitter/depthlimitedgaussion.js → src/blitter/bilateralblur.js} +1 -2
  369. package/dist/src/blitter/bilateralblur.js.map +1 -0
  370. package/dist/src/blitter/blitter.js +390 -0
  371. package/dist/src/blitter/blitter.js.map +1 -0
  372. package/dist/src/blitter/box.js +118 -0
  373. package/dist/src/blitter/box.js.map +1 -0
  374. package/dist/src/blitter/copy.js +22 -0
  375. package/dist/src/blitter/copy.js.map +1 -0
  376. package/dist/src/blitter/gaussianblur.js +228 -0
  377. package/dist/src/blitter/gaussianblur.js.map +1 -0
  378. package/dist/src/camera/base.js +92 -0
  379. package/dist/src/camera/base.js.map +1 -0
  380. package/dist/src/camera/camera.js +1005 -0
  381. package/dist/src/camera/camera.js.map +1 -0
  382. package/dist/src/camera/fps.js +238 -0
  383. package/dist/src/camera/fps.js.map +1 -0
  384. package/dist/src/camera/orbit.js +245 -0
  385. package/dist/src/camera/orbit.js.map +1 -0
  386. package/dist/src/camera/orthocamera.js +167 -0
  387. package/dist/src/camera/orthocamera.js.map +1 -0
  388. package/dist/src/camera/perspectivecamera.js +141 -0
  389. package/dist/src/camera/perspectivecamera.js.map +1 -0
  390. package/dist/src/index.js +120 -0
  391. package/dist/src/index.js.map +1 -0
  392. package/dist/src/material/blinn.js +81 -0
  393. package/dist/src/material/blinn.js.map +1 -0
  394. package/dist/src/material/grassmaterial.js +113 -0
  395. package/dist/src/material/grassmaterial.js.map +1 -0
  396. package/dist/src/material/lambert.js +92 -0
  397. package/dist/src/material/lambert.js.map +1 -0
  398. package/dist/src/material/material.js +301 -0
  399. package/dist/src/material/material.js.map +1 -0
  400. package/dist/src/material/meshmaterial.js +704 -0
  401. package/dist/src/material/meshmaterial.js.map +1 -0
  402. package/dist/src/material/mixins/albedocolor.js +76 -0
  403. package/dist/src/material/mixins/albedocolor.js.map +1 -0
  404. package/dist/src/material/mixins/foliage.js +47 -0
  405. package/dist/src/material/mixins/foliage.js.map +1 -0
  406. package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
  407. package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
  408. package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
  409. package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
  410. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
  411. package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
  412. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
  413. package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
  414. package/dist/src/material/mixins/lit.js +476 -0
  415. package/dist/src/material/mixins/lit.js.map +1 -0
  416. package/dist/src/material/mixins/pbr/common.js +918 -0
  417. package/dist/src/material/mixins/pbr/common.js.map +1 -0
  418. package/dist/src/material/mixins/texture.js +172 -0
  419. package/dist/src/material/mixins/texture.js.map +1 -0
  420. package/dist/src/material/mixins/vertexcolor.js +56 -0
  421. package/dist/src/material/mixins/vertexcolor.js.map +1 -0
  422. package/dist/src/material/particle.js +178 -0
  423. package/dist/src/material/particle.js.map +1 -0
  424. package/dist/src/material/pbrmr.js +97 -0
  425. package/dist/src/material/pbrmr.js.map +1 -0
  426. package/dist/src/material/pbrsg.js +97 -0
  427. package/dist/src/material/pbrsg.js.map +1 -0
  428. package/dist/src/material/shader/helper.js +1209 -0
  429. package/dist/src/material/shader/helper.js.map +1 -0
  430. package/dist/src/material/terrain-cm.js +606 -0
  431. package/dist/src/material/terrain-cm.js.map +1 -0
  432. package/dist/src/material/terrainmaterial.js +375 -0
  433. package/dist/src/material/terrainmaterial.js.map +1 -0
  434. package/dist/src/material/unlit.js +41 -0
  435. package/dist/src/material/unlit.js.map +1 -0
  436. package/dist/src/material/water.js +417 -0
  437. package/dist/src/material/water.js.map +1 -0
  438. package/dist/src/posteffect/bloom.js +361 -0
  439. package/dist/src/posteffect/bloom.js.map +1 -0
  440. package/dist/src/posteffect/compositor.js +226 -0
  441. package/dist/src/posteffect/compositor.js.map +1 -0
  442. package/dist/src/posteffect/fxaa.js +273 -0
  443. package/dist/src/posteffect/fxaa.js.map +1 -0
  444. package/dist/src/posteffect/grayscale.js +69 -0
  445. package/dist/src/posteffect/grayscale.js.map +1 -0
  446. package/dist/src/posteffect/motionblur.js +96 -0
  447. package/dist/src/posteffect/motionblur.js.map +1 -0
  448. package/dist/src/posteffect/posteffect.js +126 -0
  449. package/dist/src/posteffect/posteffect.js.map +1 -0
  450. package/dist/src/posteffect/sao.js +324 -0
  451. package/dist/src/posteffect/sao.js.map +1 -0
  452. package/dist/src/posteffect/ssr.js +489 -0
  453. package/dist/src/posteffect/ssr.js.map +1 -0
  454. package/dist/src/posteffect/taa.js +172 -0
  455. package/dist/src/posteffect/taa.js.map +1 -0
  456. package/dist/src/posteffect/tonemap.js +94 -0
  457. package/dist/src/posteffect/tonemap.js.map +1 -0
  458. package/dist/src/render/abuffer_oit.js +361 -0
  459. package/dist/src/render/abuffer_oit.js.map +1 -0
  460. package/dist/src/render/clipmap.js +851 -0
  461. package/dist/src/render/clipmap.js.map +1 -0
  462. package/dist/src/render/cluster_light.js +333 -0
  463. package/dist/src/render/cluster_light.js.map +1 -0
  464. package/dist/src/render/cull_visitor.js +187 -0
  465. package/dist/src/render/cull_visitor.js.map +1 -0
  466. package/dist/src/render/depthpass.js +68 -0
  467. package/dist/src/render/depthpass.js.map +1 -0
  468. package/dist/src/render/drawable_mixin.js +227 -0
  469. package/dist/src/render/drawable_mixin.js.map +1 -0
  470. package/dist/src/render/envlight.js +463 -0
  471. package/dist/src/render/envlight.js.map +1 -0
  472. package/dist/src/render/fbm_wavegenerator.js +251 -0
  473. package/dist/src/render/fbm_wavegenerator.js.map +1 -0
  474. package/dist/src/render/fft_wavegenerator.js +1006 -0
  475. package/dist/src/render/fft_wavegenerator.js.map +1 -0
  476. package/dist/src/render/fullscreenquad.js +38 -0
  477. package/dist/src/render/fullscreenquad.js.map +1 -0
  478. package/dist/src/render/gerstner_wavegenerator.js +314 -0
  479. package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
  480. package/dist/src/render/globalbindgroup_allocator.js +60 -0
  481. package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
  482. package/dist/src/render/hzb.js +273 -0
  483. package/dist/src/render/hzb.js.map +1 -0
  484. package/dist/src/render/lightpass.js +172 -0
  485. package/dist/src/render/lightpass.js.map +1 -0
  486. package/dist/src/render/objectcolorpass.js +51 -0
  487. package/dist/src/render/objectcolorpass.js.map +1 -0
  488. package/dist/src/render/primitive.js +364 -0
  489. package/dist/src/render/primitive.js.map +1 -0
  490. package/dist/src/render/render_queue.js +467 -0
  491. package/dist/src/render/render_queue.js.map +1 -0
  492. package/dist/src/render/renderbundle_wrapper.js +152 -0
  493. package/dist/src/render/renderbundle_wrapper.js.map +1 -0
  494. package/dist/src/render/renderer.js +455 -0
  495. package/dist/src/render/renderer.js.map +1 -0
  496. package/dist/src/render/renderpass.js +200 -0
  497. package/dist/src/render/renderpass.js.map +1 -0
  498. package/dist/src/render/shadowmap_pass.js +56 -0
  499. package/dist/src/render/shadowmap_pass.js.map +1 -0
  500. package/dist/src/render/sky.js +1103 -0
  501. package/dist/src/render/sky.js.map +1 -0
  502. package/dist/src/render/weightedblended_oit.js +168 -0
  503. package/dist/src/render/weightedblended_oit.js.map +1 -0
  504. package/dist/src/scene/batchgroup.js +162 -0
  505. package/dist/src/scene/batchgroup.js.map +1 -0
  506. package/dist/src/scene/environment.js +209 -0
  507. package/dist/src/scene/environment.js.map +1 -0
  508. package/dist/src/scene/graph_node.js +72 -0
  509. package/dist/src/scene/graph_node.js.map +1 -0
  510. package/dist/src/scene/light.js +416 -0
  511. package/dist/src/scene/light.js.map +1 -0
  512. package/dist/src/scene/mesh.js +341 -0
  513. package/dist/src/scene/mesh.js.map +1 -0
  514. package/dist/src/scene/octree.js +649 -0
  515. package/dist/src/scene/octree.js.map +1 -0
  516. package/dist/src/scene/particlesys.js +738 -0
  517. package/dist/src/scene/particlesys.js.map +1 -0
  518. package/dist/src/scene/raycast_visitor.js +103 -0
  519. package/dist/src/scene/raycast_visitor.js.map +1 -0
  520. package/dist/src/scene/scene.js +284 -0
  521. package/dist/src/scene/scene.js.map +1 -0
  522. package/dist/src/scene/scene_node.js +732 -0
  523. package/dist/src/scene/scene_node.js.map +1 -0
  524. package/dist/src/scene/terrain/grass.js +278 -0
  525. package/dist/src/scene/terrain/grass.js.map +1 -0
  526. package/dist/src/scene/terrain/heightfield.js +475 -0
  527. package/dist/src/scene/terrain/heightfield.js.map +1 -0
  528. package/dist/src/scene/terrain/patch.js +530 -0
  529. package/dist/src/scene/terrain/patch.js.map +1 -0
  530. package/dist/src/scene/terrain/quadtree.js +461 -0
  531. package/dist/src/scene/terrain/quadtree.js.map +1 -0
  532. package/dist/src/scene/terrain/terrain.js +246 -0
  533. package/dist/src/scene/terrain/terrain.js.map +1 -0
  534. package/dist/src/scene/terrain-cm/grass.js +594 -0
  535. package/dist/src/scene/terrain-cm/grass.js.map +1 -0
  536. package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
  537. package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
  538. package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
  539. package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
  540. package/dist/src/scene/water.js +374 -0
  541. package/dist/src/scene/water.js.map +1 -0
  542. package/dist/src/shaders/atmosphere.js +957 -0
  543. package/dist/src/shaders/atmosphere.js.map +1 -0
  544. package/dist/src/shaders/fog.js +112 -0
  545. package/dist/src/shaders/fog.js.map +1 -0
  546. package/dist/src/shaders/misc.js +266 -0
  547. package/dist/src/shaders/misc.js.map +1 -0
  548. package/dist/src/shaders/noise.js +222 -0
  549. package/dist/src/shaders/noise.js.map +1 -0
  550. package/dist/src/shaders/pbr.js +51 -0
  551. package/dist/src/shaders/pbr.js.map +1 -0
  552. package/dist/src/shaders/shadow.js +636 -0
  553. package/dist/src/shaders/shadow.js.map +1 -0
  554. package/dist/src/shaders/ssr.js +490 -0
  555. package/dist/src/shaders/ssr.js.map +1 -0
  556. package/dist/src/shaders/temporal.js +215 -0
  557. package/dist/src/shaders/temporal.js.map +1 -0
  558. package/dist/src/shaders/water.js +756 -0
  559. package/dist/src/shaders/water.js.map +1 -0
  560. package/dist/src/shadow/esm.js +237 -0
  561. package/dist/src/shadow/esm.js.map +1 -0
  562. package/dist/src/shadow/pcf_opt.js +181 -0
  563. package/dist/src/shadow/pcf_opt.js.map +1 -0
  564. package/dist/src/shadow/pcf_pd.js +189 -0
  565. package/dist/src/shadow/pcf_pd.js.map +1 -0
  566. package/dist/src/shadow/shader.js +37 -0
  567. package/dist/src/shadow/shader.js.map +1 -0
  568. package/dist/src/shadow/shadow_impl.js +15 -0
  569. package/dist/src/shadow/shadow_impl.js.map +1 -0
  570. package/dist/src/shadow/shadowmapper.js +790 -0
  571. package/dist/src/shadow/shadowmapper.js.map +1 -0
  572. package/dist/src/shadow/ssm.js +159 -0
  573. package/dist/src/shadow/ssm.js.map +1 -0
  574. package/dist/src/shadow/vsm.js +297 -0
  575. package/dist/src/shadow/vsm.js.map +1 -0
  576. package/dist/src/shapes/box.js +386 -0
  577. package/dist/src/shapes/box.js.map +1 -0
  578. package/dist/src/shapes/cylinder.js +125 -0
  579. package/dist/src/shapes/cylinder.js.map +1 -0
  580. package/dist/src/shapes/plane.js +88 -0
  581. package/dist/src/shapes/plane.js.map +1 -0
  582. package/dist/src/shapes/shape.js +87 -0
  583. package/dist/src/shapes/shape.js.map +1 -0
  584. package/dist/src/shapes/sphere.js +114 -0
  585. package/dist/src/shapes/sphere.js.map +1 -0
  586. package/dist/src/shapes/tetrahedron.js +188 -0
  587. package/dist/src/shapes/tetrahedron.js.map +1 -0
  588. package/dist/src/shapes/torus.js +111 -0
  589. package/dist/src/shapes/torus.js.map +1 -0
  590. package/dist/src/utility/aabbtree.js +400 -0
  591. package/dist/src/utility/aabbtree.js.map +1 -0
  592. package/dist/src/utility/bounding_volume.js +29 -0
  593. package/dist/src/utility/bounding_volume.js.map +1 -0
  594. package/dist/src/utility/debug.js +28 -0
  595. package/dist/src/utility/debug.js.map +1 -0
  596. package/dist/src/utility/draco/decoder.js +116 -0
  597. package/dist/src/utility/draco/decoder.js.map +1 -0
  598. package/dist/src/utility/misc.js +105 -0
  599. package/dist/src/utility/misc.js.map +1 -0
  600. package/dist/src/utility/panorama.js +163 -0
  601. package/dist/src/utility/panorama.js.map +1 -0
  602. package/dist/src/utility/pmrem.js +354 -0
  603. package/dist/src/utility/pmrem.js.map +1 -0
  604. package/dist/src/utility/rendermipmap.js +115 -0
  605. package/dist/src/utility/rendermipmap.js.map +1 -0
  606. package/dist/src/utility/serialization/json.js +402 -0
  607. package/dist/src/utility/serialization/json.js.map +1 -0
  608. package/dist/src/utility/serialization/manager.js +623 -0
  609. package/dist/src/utility/serialization/manager.js.map +1 -0
  610. package/dist/src/utility/serialization/scene/animation.js +248 -0
  611. package/dist/src/utility/serialization/scene/animation.js.map +1 -0
  612. package/dist/src/utility/serialization/scene/batch.js +59 -0
  613. package/dist/src/utility/serialization/scene/batch.js.map +1 -0
  614. package/dist/src/utility/serialization/scene/camera.js +790 -0
  615. package/dist/src/utility/serialization/scene/camera.js.map +1 -0
  616. package/dist/src/utility/serialization/scene/common.js +222 -0
  617. package/dist/src/utility/serialization/scene/common.js.map +1 -0
  618. package/dist/src/utility/serialization/scene/light.js +575 -0
  619. package/dist/src/utility/serialization/scene/light.js.map +1 -0
  620. package/dist/src/utility/serialization/scene/material.js +1111 -0
  621. package/dist/src/utility/serialization/scene/material.js.map +1 -0
  622. package/dist/src/utility/serialization/scene/mesh.js +148 -0
  623. package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
  624. package/dist/src/utility/serialization/scene/misc.js +39 -0
  625. package/dist/src/utility/serialization/scene/misc.js.map +1 -0
  626. package/dist/src/utility/serialization/scene/node.js +451 -0
  627. package/dist/src/utility/serialization/scene/node.js.map +1 -0
  628. package/dist/src/utility/serialization/scene/particle.js +425 -0
  629. package/dist/src/utility/serialization/scene/particle.js.map +1 -0
  630. package/dist/src/utility/serialization/scene/primitive.js +692 -0
  631. package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
  632. package/dist/src/utility/serialization/scene/scene.js +704 -0
  633. package/dist/src/utility/serialization/scene/scene.js.map +1 -0
  634. package/dist/src/utility/serialization/scene/terrain.js +488 -0
  635. package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
  636. package/dist/src/utility/serialization/scene/water.js +465 -0
  637. package/dist/src/utility/serialization/scene/water.js.map +1 -0
  638. package/dist/src/utility/shprojector.js +297 -0
  639. package/dist/src/utility/shprojector.js.map +1 -0
  640. package/dist/{material/mixins → src/utility/textures}/ggxlut.js +1 -1
  641. package/dist/src/utility/textures/ggxlut.js.map +1 -0
  642. package/dist/src/utility/textures/gradientnoise.js +62 -0
  643. package/dist/src/utility/textures/gradientnoise.js.map +1 -0
  644. package/dist/src/utility/textures/randomnoise.js +41 -0
  645. package/dist/src/utility/textures/randomnoise.js.map +1 -0
  646. package/dist/src/values.js +162 -0
  647. package/dist/src/values.js.map +1 -0
  648. package/dist/utility/aabbtree.js +16 -6
  649. package/dist/utility/aabbtree.js.map +1 -1
  650. package/dist/utility/blueprint/common/constants.js +1325 -0
  651. package/dist/utility/blueprint/common/constants.js.map +1 -0
  652. package/dist/utility/blueprint/common/math.js +2507 -0
  653. package/dist/utility/blueprint/common/math.js.map +1 -0
  654. package/dist/utility/blueprint/common.js +7 -0
  655. package/dist/utility/blueprint/common.js.map +1 -0
  656. package/dist/utility/blueprint/material/common.js +7 -0
  657. package/dist/utility/blueprint/material/common.js.map +1 -0
  658. package/dist/utility/blueprint/material/func.js +525 -0
  659. package/dist/utility/blueprint/material/func.js.map +1 -0
  660. package/dist/utility/blueprint/material/inputs.js +1659 -0
  661. package/dist/utility/blueprint/material/inputs.js.map +1 -0
  662. package/dist/utility/blueprint/material/ir.js +1519 -0
  663. package/dist/utility/blueprint/material/ir.js.map +1 -0
  664. package/dist/utility/blueprint/material/pbr.js +450 -0
  665. package/dist/utility/blueprint/material/pbr.js.map +1 -0
  666. package/dist/utility/blueprint/material/texture.js +1116 -0
  667. package/dist/utility/blueprint/material/texture.js.map +1 -0
  668. package/dist/utility/blueprint/node.js +214 -0
  669. package/dist/utility/blueprint/node.js.map +1 -0
  670. package/dist/utility/bounding_volume.js +0 -1
  671. package/dist/utility/bounding_volume.js.map +1 -1
  672. package/dist/utility/debug.js +26 -0
  673. package/dist/utility/debug.js.map +1 -0
  674. package/dist/utility/draco/decoder.js +1 -1
  675. package/dist/utility/draco/decoder.js.map +1 -1
  676. package/dist/utility/misc.js +19 -7
  677. package/dist/utility/misc.js.map +1 -1
  678. package/dist/utility/panorama.js +8 -6
  679. package/dist/utility/panorama.js.map +1 -1
  680. package/dist/utility/pmrem.js +30 -18
  681. package/dist/utility/pmrem.js.map +1 -1
  682. package/dist/utility/rendermipmap.js +116 -0
  683. package/dist/utility/rendermipmap.js.map +1 -0
  684. package/dist/utility/serialization/blueprint/constants.js +255 -0
  685. package/dist/utility/serialization/blueprint/constants.js.map +1 -0
  686. package/dist/utility/serialization/blueprint/material/constants.js +203 -0
  687. package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
  688. package/dist/utility/serialization/blueprint/material/texture.js +165 -0
  689. package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
  690. package/dist/utility/serialization/json.js +406 -0
  691. package/dist/utility/serialization/json.js.map +1 -0
  692. package/dist/utility/serialization/manager.js +1243 -0
  693. package/dist/utility/serialization/manager.js.map +1 -0
  694. package/dist/utility/serialization/scene/animation.js +701 -0
  695. package/dist/utility/serialization/scene/animation.js.map +1 -0
  696. package/dist/utility/serialization/scene/batch.js +54 -0
  697. package/dist/utility/serialization/scene/batch.js.map +1 -0
  698. package/dist/utility/serialization/scene/camera.js +896 -0
  699. package/dist/utility/serialization/scene/camera.js.map +1 -0
  700. package/dist/utility/serialization/scene/common.js +298 -0
  701. package/dist/utility/serialization/scene/common.js.map +1 -0
  702. package/dist/utility/serialization/scene/light.js +591 -0
  703. package/dist/utility/serialization/scene/light.js.map +1 -0
  704. package/dist/utility/serialization/scene/material.js +1070 -0
  705. package/dist/utility/serialization/scene/material.js.map +1 -0
  706. package/dist/utility/serialization/scene/mesh.js +345 -0
  707. package/dist/utility/serialization/scene/mesh.js.map +1 -0
  708. package/dist/utility/serialization/scene/misc.js +40 -0
  709. package/dist/utility/serialization/scene/misc.js.map +1 -0
  710. package/dist/utility/serialization/scene/node.js +424 -0
  711. package/dist/utility/serialization/scene/node.js.map +1 -0
  712. package/dist/utility/serialization/scene/particle.js +427 -0
  713. package/dist/utility/serialization/scene/particle.js.map +1 -0
  714. package/dist/utility/serialization/scene/primitive.js +585 -0
  715. package/dist/utility/serialization/scene/primitive.js.map +1 -0
  716. package/dist/utility/serialization/scene/scene.js +764 -0
  717. package/dist/utility/serialization/scene/scene.js.map +1 -0
  718. package/dist/utility/serialization/scene/sprite.js +164 -0
  719. package/dist/utility/serialization/scene/sprite.js.map +1 -0
  720. package/dist/utility/serialization/scene/terrain.js +497 -0
  721. package/dist/utility/serialization/scene/terrain.js.map +1 -0
  722. package/dist/utility/serialization/scene/water.js +467 -0
  723. package/dist/utility/serialization/scene/water.js.map +1 -0
  724. package/dist/utility/serialization/types.js +6 -0
  725. package/dist/utility/serialization/types.js.map +1 -0
  726. package/dist/utility/shprojector.js +313 -0
  727. package/dist/utility/shprojector.js.map +1 -0
  728. package/dist/utility/textures/ggxlut.js +4 -5
  729. package/dist/utility/textures/ggxlut.js.map +1 -1
  730. package/dist/utility/textures/gradientnoise.js +2 -1
  731. package/dist/utility/textures/gradientnoise.js.map +1 -1
  732. package/dist/utility/textures/randomnoise.js +1 -0
  733. package/dist/utility/textures/randomnoise.js.map +1 -1
  734. package/dist/values.js +103 -16
  735. package/dist/values.js.map +1 -1
  736. package/package.json +80 -66
  737. package/dist/app.js.map +0 -1
  738. package/dist/blitter/depthlimitedgaussion.js.map +0 -1
  739. package/dist/input/inputmgr.js.map +0 -1
  740. package/dist/material/mixins/ggxlut.js.map +0 -1
  741. package/dist/posteffect/water.js +0 -508
  742. package/dist/posteffect/water.js.map +0 -1
  743. package/dist/render/oit.js +0 -16
  744. package/dist/render/oit.js.map +0 -1
  745. package/dist/render/scatteringlut.js +0 -634
  746. package/dist/render/scatteringlut.js.map +0 -1
  747. package/dist/render/watermesh.js +0 -193
  748. package/dist/render/watermesh.js.map +0 -1
  749. package/dist/render/wavegenerator.js +0 -8
  750. package/dist/render/wavegenerator.js.map +0 -1
  751. package/dist/scene/xform.js +0 -247
  752. package/dist/scene/xform.js.map +0 -1
  753. package/dist/utility/shprojection.js +0 -442
  754. package/dist/utility/shprojection.js.map +0 -1
@@ -1,199 +1,360 @@
1
- import { HttpRequest, isPowerOf2, nextPowerOf2 } from '@zephyr3d/base';
1
+ import { DWeakRef, ASSERT, base64ToUint8Array, Vector3, DRef, Vector4, VFSError, isPowerOf2, nextPowerOf2 } from '@zephyr3d/base';
2
2
  import { GLTFLoader } from './loaders/gltf/gltf_loader.js';
3
3
  import { WebImageLoader } from './loaders/image/webimage_loader.js';
4
4
  import { DDSLoader } from './loaders/dds/dds_loader.js';
5
5
  import { HDRLoader } from './loaders/hdr/hdr.js';
6
- import { SceneNode } from '../scene/scene_node.js';
7
- import { Mesh } from '../scene/mesh.js';
8
- import { AnimationClip } from '../animation/animation.js';
9
- import { AnimationSet } from '../animation/animationset.js';
10
- import { TranslationTrack } from '../animation/translationtrack.js';
11
- import { RotationTrack } from '../animation/rotationtrack.js';
12
- import '../animation/eulerrotationtrack.js';
13
- import { ScaleTrack } from '../animation/scaletrack.js';
14
- import { Skeleton } from '../animation/skeleton.js';
15
- import { Application } from '../app.js';
6
+ import { Primitive } from '../render/primitive.js';
16
7
  import '@zephyr3d/device';
8
+ import { getEngine, getDevice } from '../app/api.js';
17
9
  import { CopyBlitter } from '../blitter/copy.js';
18
- import { getSheenLutLoader, getTestCubemapLoader } from './builtin.js';
19
- import { BUILTIN_ASSET_TEXTURE_SHEEN_LUT, BUILTIN_ASSET_TEST_CUBEMAP, MAX_MORPH_TARGETS } from '../values.js';
10
+ import { getSheenLutLoader } from './builtin.js';
11
+ import { BUILTIN_ASSET_TEXTURE_SHEEN_LUT } from '../values.js';
20
12
  import { TGALoader } from './loaders/image/tga_Loader.js';
21
- import { MorphTargetTrack } from '../animation/morphtrack.js';
22
- import { processMorphData } from '../animation/morphtarget.js';
13
+ import '../material/shader/helper.js';
14
+ import '../material/lambert.js';
15
+ import '../material/blinn.js';
16
+ import '../material/unlit.js';
17
+ import '../material/particle.js';
18
+ import { Material } from '../material/material.js';
19
+ import '../material/meshmaterial.js';
20
+ import '../material/grassmaterial.js';
21
+ import '../material/terrain-cm.js';
22
+ import '../material/pbrmr.js';
23
+ import '../material/pbrsg.js';
24
+ import { PBRBluePrintMaterial } from '../material/pbrblueprint.js';
25
+ import '../material/sprite.js';
26
+ import '../material/sprite_std.js';
27
+ import { SpriteBlueprintMaterial } from '../material/spriteblueprint.js';
28
+ import { BoundingBox } from '../utility/bounding_volume.js';
29
+ import { MaterialBlueprintIR } from '../utility/blueprint/material/ir.js';
30
+ import '../render/renderer.js';
31
+ import '../render/sky.js';
32
+ import '../render/clipmap.js';
33
+ import '../shaders/atmosphere.js';
23
34
 
24
35
  /**
25
- * The asset manager
36
+ * Centralized asset manager for loading and caching resources.
37
+ *
38
+ * Responsibilities:
39
+ * - Abstracts resource loading via VFS (text/json/binary).
40
+ * - Dispatches texture/model loading to registered loaders by MIME type.
41
+ * - Caches results and uses weak references to allow GPU resources to be GC'd when unused.
42
+ * - Harmonizes cross-backend constraints (e.g., WebGL non-power-of-two rules and sRGB handling).
43
+ * - Provides access to built-in textures with device-restore handlers.
44
+ *
45
+ * Threading/async model:
46
+ * - All I/O is async; repeated calls are coalesced via internal promise caches keyed by URL or hash.
47
+ *
26
48
  * @public
27
49
  */ class AssetManager {
28
50
  /** @internal */ static _builtinTextures = {};
29
51
  /** @internal */ static _builtinTextureLoaders = {
30
- [BUILTIN_ASSET_TEXTURE_SHEEN_LUT]: getSheenLutLoader(64),
31
- [BUILTIN_ASSET_TEST_CUBEMAP]: getTestCubemapLoader()
52
+ [BUILTIN_ASSET_TEXTURE_SHEEN_LUT]: getSheenLutLoader(64)
32
53
  };
33
- /** @internal */ _httpRequest;
34
- /** @internal */ _textureLoaders;
35
- /** @internal */ _modelLoaders;
54
+ /** @internal */ static _textureLoaders = [
55
+ new WebImageLoader(),
56
+ new DDSLoader(),
57
+ new HDRLoader(),
58
+ new TGALoader()
59
+ ];
60
+ /** @internal */ static _modelLoaders = [
61
+ new GLTFLoader()
62
+ ];
36
63
  /** @internal */ _textures;
37
64
  /** @internal */ _models;
38
65
  /** @internal */ _binaryDatas;
39
66
  /** @internal */ _textDatas;
67
+ /** @internal */ _bluePrints;
68
+ /** @internal */ _materials;
69
+ /** @internal */ _primitives;
70
+ /** @internal */ _skeletons;
71
+ /** @internal */ _jsonDatas;
72
+ /** @internal */ _resourceManager;
40
73
  /**
41
74
  * Creates an instance of AssetManager
42
- */ constructor(){
43
- this._httpRequest = new HttpRequest();
44
- this._textureLoaders = [
45
- new WebImageLoader(),
46
- new DDSLoader(),
47
- new HDRLoader(),
48
- new TGALoader()
49
- ];
50
- this._modelLoaders = [
51
- new GLTFLoader()
52
- ];
75
+ */ constructor(resourceManager){
76
+ this._resourceManager = resourceManager ?? getEngine().resourceManager;
53
77
  this._textures = {};
54
78
  this._models = {};
79
+ this._materials = {};
80
+ this._primitives = {};
81
+ this._skeletons = {};
82
+ this._bluePrints = {};
55
83
  this._binaryDatas = {};
56
84
  this._textDatas = {};
85
+ this._jsonDatas = {};
57
86
  }
58
87
  /**
59
- * HttpRequest instance of the asset manager
60
- */ get httpRequest() {
61
- return this._httpRequest;
88
+ * VFS used to read resources (files, URLs, virtual mounts).
89
+ */ get vfs() {
90
+ return this._resourceManager.VFS;
62
91
  }
63
92
  /**
64
- * Removes all cached assets
93
+ * Clear cached references and promises.
94
+ *
95
+ * - Disposes any DWeakRef holders maintained by this manager.
96
+ * - Empties internal maps for textures, models, and raw data (text/json/binary).
97
+ * - Does not forcibly dispose GPU resources; it only clears references so they can be GC'd
98
+ * if no other owners are holding them.
65
99
  */ clearCache() {
66
- this._textures = {};
67
- this._models = {};
68
- this._binaryDatas = {};
69
- this._textDatas = {};
70
- }
71
- /**
72
- * Remove and dispose all cached assets
73
- */ purgeCache() {
74
- for(const k in this._textures){
75
- this._textures[k].then((tex)=>tex?.dispose()).catch((err)=>{});
100
+ for(const k in Object.keys(this._textures)){
101
+ const v = this._textures[k];
102
+ if (v instanceof DWeakRef) {
103
+ v.dispose();
104
+ }
76
105
  }
77
106
  this._textures = {};
107
+ for(const k in Object.keys(this._models)){
108
+ const v = this._models[k];
109
+ if (v instanceof DWeakRef) {
110
+ v.dispose();
111
+ }
112
+ }
78
113
  this._models = {};
114
+ for(const k in Object.keys(this._materials)){
115
+ const v = this._materials[k];
116
+ if (v instanceof DWeakRef) {
117
+ v.dispose();
118
+ }
119
+ }
120
+ this._materials = {};
121
+ for(const k in Object.keys(this._primitives)){
122
+ const v = this._primitives[k];
123
+ if (v instanceof DWeakRef) {
124
+ v.dispose();
125
+ }
126
+ }
127
+ this._primitives = {};
128
+ for(const k in Object.keys(this._skeletons)){
129
+ const v = this._skeletons[k];
130
+ if (v instanceof DWeakRef) {
131
+ v.dispose();
132
+ }
133
+ }
134
+ this._skeletons = {};
79
135
  this._binaryDatas = {};
80
136
  this._textDatas = {};
137
+ this._jsonDatas = {};
81
138
  }
82
139
  /**
83
- * Adds a texture loader to the asset manager
140
+ * Register a texture loader (highest priority first).
84
141
  *
85
- * @remarks
86
- * TODO: this should be a static method
142
+ * Note: This is a static registry shared by all AssetManager instances.
87
143
  *
88
- * @param loader - The texture loader to be added
89
- */ addTextureLoader(loader) {
144
+ * @param loader - A concrete texture loader implementation.
145
+ */ static addTextureLoader(loader) {
90
146
  if (loader) {
91
147
  this._textureLoaders.unshift(loader);
92
148
  }
93
149
  }
94
150
  /**
95
- * Adds a model loader to the asset manager
151
+ * Register a model loader (highest priority first).
96
152
  *
97
- * @remarks
98
- * TODO: this should be a static method
153
+ * Note: This is a static registry shared by all AssetManager instances.
99
154
  *
100
- * @param loader - The model loader to be added
101
- */ addModelLoader(loader) {
155
+ * @param loader - A concrete model loader implementation.
156
+ */ static addModelLoader(loader) {
102
157
  if (loader) {
103
158
  this._modelLoaders.unshift(loader);
104
159
  }
105
160
  }
106
161
  /**
107
- * Fetches a text resource from a given URL
108
- * @param url - The URL from where to fetch the resource
109
- * @param postProcess - A function that will be involved when the text data was loaded.
110
- *
111
- * @remarks
112
- * If a text data has already been loaded, the function will ignore the
113
- * postProcess parameter and directly return the text loaded previously.
114
- * To load the same text with different postProcess parameters,
115
- * use different AssetManager instances separately.
116
- *
117
- * @returns The fetched text
118
- */ async fetchTextData(url, postProcess) {
119
- let P = this._textDatas[url];
162
+ * Fetch a UTF-8 text resource via VFS.
163
+ *
164
+ * - Results are cached per resolved URL (via HttpRequest.urlResolver if provided; otherwise the raw URL).
165
+ * - If cached, any provided postProcess is ignored for subsequent calls; create a separate AssetManager
166
+ * if you need different post-processing of the same URL.
167
+ *
168
+ * @param url - Resource URL or VFS path.
169
+ * @param postProcess - Optional transformation applied to the loaded text.
170
+ * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
171
+ * @returns A promise that resolves to the loaded (and optionally processed) text.
172
+ */ async fetchTextData(url, postProcess, httpRequest, VFSs) {
173
+ const hash = httpRequest?.urlResolver?.(url) ?? url;
174
+ let P = this._textDatas[hash];
175
+ if (!P) {
176
+ P = this.loadTextData(url, postProcess, VFSs);
177
+ this._textDatas[hash] = P;
178
+ }
179
+ return P;
180
+ }
181
+ /**
182
+ * Fetch a JSON resource via VFS.
183
+ *
184
+ * - Parses as JSON after text load.
185
+ * - Cached per resolved URL. Post-process is applied only on the first load for a given cache key.
186
+ *
187
+ * @param url - Resource URL or VFS path.
188
+ * @param postProcess - Optional transformation applied to the parsed JSON object.
189
+ * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
190
+ * @returns A promise that resolves to the loaded (and optionally processed) JSON value.
191
+ */ async fetchJsonData(url, postProcess, httpRequest, VFSs) {
192
+ const hash = httpRequest?.urlResolver?.(url) ?? url;
193
+ let P = this._jsonDatas[hash];
120
194
  if (!P) {
121
- P = this.loadTextData(url, postProcess);
122
- this._textDatas[url] = P;
195
+ P = this.loadJsonData(url, postProcess, VFSs);
196
+ this._jsonDatas[hash] = P;
123
197
  }
124
198
  return P;
125
199
  }
126
200
  /**
127
- * Fetches a binary resource from a given URL
128
- * @param url - The URL from where to fetch the resource
129
- * @param postProcess - A function that will be involved when the binary data was loaded.
130
- *
131
- * @remarks
132
- * If a binary data has already been loaded, the function will ignore the
133
- * postProcess parameter and directly return the data loaded previously.
134
- * To load the same data with different postProcess parameters,
135
- * use different AssetManager instances separately.
136
- *
137
- * @returns Binary data as ArrayBuffer
138
- */ async fetchBinaryData(url, postProcess) {
139
- let P = this._binaryDatas[url];
201
+ * Fetch a binary resource via VFS.
202
+ *
203
+ * - Cached per resolved URL. Post-process is applied only on first load for a given key.
204
+ *
205
+ * @param url - Resource URL or VFS path.
206
+ * @param postProcess - Optional transformation applied to the loaded ArrayBuffer.
207
+ * @param httpRequest - Optional HttpRequest for custom URL resolution/headers.
208
+ * @returns A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
209
+ */ async fetchBinaryData(url, postProcess, httpRequest, VFSs) {
210
+ const hash = httpRequest?.urlResolver?.(url) ?? url;
211
+ let P = this._binaryDatas[hash];
140
212
  if (!P) {
141
- P = this.loadBinaryData(url, postProcess);
142
- this._binaryDatas[url] = P;
213
+ P = this.loadBinaryData(url, postProcess, VFSs);
214
+ this._binaryDatas[hash] = P;
143
215
  }
144
216
  return P;
145
217
  }
218
+ async fetchBluePrint(url, VFSs) {
219
+ const hash = url;
220
+ let P = this._bluePrints[hash];
221
+ if (!P) {
222
+ P = this.loadBluePrint(url, VFSs);
223
+ this._bluePrints[hash] = P;
224
+ }
225
+ return P;
226
+ }
227
+ /**
228
+ * Fetch a material resource.
229
+ *
230
+ * @typeParam T - Expected concrete material type.
231
+ * @param url - Resource URL or VFS path.
232
+ * @returns A promise that resolves to the loaded material.
233
+ */ async fetchMaterial(url, VFSs) {
234
+ const hash = url;
235
+ let P = this._materials[hash];
236
+ if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
237
+ return P.get();
238
+ } else if (!P || P instanceof DWeakRef) {
239
+ P = this.loadMaterial(url, false, VFSs);
240
+ this._materials[hash] = P;
241
+ }
242
+ const material = await P;
243
+ if (this._materials[hash] instanceof Promise) {
244
+ this._materials[hash] = new DWeakRef(material);
245
+ }
246
+ return material;
247
+ }
146
248
  /**
147
- * Fetches a texture resource from a given URL
148
- * @param url - The URL from where to fetch the resource
149
- * @param options - Options for texture fetching
150
- * @returns The fetched texture
151
- */ async fetchTexture(url, options) {
249
+ * Fetch a primitive resource.
250
+ *
251
+ * @typeParam T - Expected concrete primitive type.
252
+ * @param url - Resource URL or VFS path.
253
+ * @returns A promise that resolves to the loaded primitive.
254
+ */ async fetchPrimitive(url, VFSs) {
255
+ const hash = url;
256
+ let P = this._primitives[hash];
257
+ if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
258
+ return P.get();
259
+ } else if (!P || P instanceof DWeakRef) {
260
+ P = this.loadPrimitive(url, VFSs);
261
+ this._primitives[hash] = P;
262
+ }
263
+ const primitive = await P;
264
+ if (this._primitives[hash] instanceof Promise) {
265
+ this._primitives[hash] = new DWeakRef(primitive);
266
+ }
267
+ return primitive;
268
+ }
269
+ /**
270
+ * Fetch a texture resource via registered loaders.
271
+ *
272
+ * - Chooses loader by explicit MIME type or by VFS file extension inference.
273
+ * - Deduplicates in-flight requests and caches ready textures.
274
+ * - If `options.texture` is provided, the asset will be uploaded/blitted into that texture.
275
+ * - On WebGL backends, enforces constraints by repacking non-power-of-two or sRGB textures.
276
+ *
277
+ * @typeParam T - Expected concrete texture type.
278
+ * @param url - Resource URL or VFS path.
279
+ * @param options - Texture fetching options (color space, sampler, target texture).
280
+ * @param httpRequest - Optional HttpRequest (not used for binary read but may supply URL resolver for hashing).
281
+ * @returns A promise that resolves to the loaded texture.
282
+ */ async fetchTexture(url, options, VFSs) {
152
283
  if (options?.texture) {
153
- return this.loadTexture(url, options.mimeType ?? null, !options.linearColorSpace, options.samplerOptions, options.texture);
284
+ return this.loadTexture(url, options.mimeType ?? null, !options.linearColorSpace, options.samplerOptions, options.texture, VFSs);
154
285
  } else {
155
286
  const hash = this.getHash('2d', url, options);
156
287
  let P = this._textures[hash];
157
- if (!P) {
158
- P = this.loadTexture(url, options?.mimeType ?? null, !options?.linearColorSpace, options?.samplerOptions);
288
+ if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
289
+ return P.get();
290
+ } else if (!P || P instanceof DWeakRef) {
291
+ P = this.loadTexture(url, options?.mimeType ?? null, !options?.linearColorSpace, options?.samplerOptions, null, VFSs);
159
292
  this._textures[hash] = P;
160
- } else {
161
- const tex = await P;
162
- if (tex.disposed) {
163
- await tex.reload();
164
- return tex;
165
- }
166
293
  }
167
- return P;
294
+ const tex = await P;
295
+ if (this._textures[hash] instanceof Promise) {
296
+ this._textures[hash] = new DWeakRef(tex);
297
+ }
298
+ return tex;
168
299
  }
169
300
  }
170
- /** @internal */ async fetchModelData(scene, url, options) {
171
- let P = this._models[url];
172
- if (!P) {
173
- P = this.loadModel(url, options);
174
- this._models[url] = P;
301
+ /**
302
+ * Fetch a model resource via registered model loaders (data only).
303
+ *
304
+ * - Returns a SharedModel which can create scene nodes in any Scene.
305
+ * - Uses DWeakRef to cache and allow model data to be reclaimed if unused.
306
+ *
307
+ * @param url - Model URL or VFS path.
308
+ * @param options - Model loader options (MIME override, Draco, instancing hint, post-process).
309
+ * @returns A promise that resolves to the SharedModel.
310
+ * @internal
311
+ */ async fetchModelData(url, options, VFSs) {
312
+ const hash = url;
313
+ let P = this._models[hash];
314
+ if (P instanceof DWeakRef && P.get() && !P.get().disposed) {
315
+ return P.get();
316
+ } else if (!P || P instanceof DWeakRef) {
317
+ P = this.loadModel(url, options, VFSs);
318
+ this._models[hash] = P;
175
319
  }
176
- return P;
320
+ const sharedModel = await P;
321
+ if (this._models[hash] instanceof Promise) {
322
+ this._models[hash] = new DWeakRef(sharedModel);
323
+ }
324
+ return sharedModel;
177
325
  }
178
326
  /**
179
- * Fetches a model resource from a given URL and adds it to a scene
180
- * @param scene - The scene to which the model node belongs
181
- * @param url - The URL from where to fetch the resource
182
- * @param options - Options for model fetching
183
- *
184
- * @remarks
185
- * If a model has already been loaded, the function will ignore the
186
- * postProcess parameter and directly return the model loaded previously.
187
- * To load the same model with different postProcess parameters,
188
- * use different AssetManager instances separately.
189
- *
190
- * @returns The created model node
191
- */ async fetchModel(scene, url, options) {
192
- const sharedModel = await this.fetchModelData(scene, url, options);
193
- return this.createSceneNode(scene, sharedModel, !!options?.enableInstancing);
194
- }
195
- /** @internal */ async loadTextData(url, postProcess) {
196
- let text = await this._httpRequest.requestText(url);
327
+ * Fetch a model resource and instantiate it under a scene.
328
+ *
329
+ * - Loads or retrieves a cached SharedModel, then creates a SceneNode hierarchy.
330
+ * - Returns both the created group node and any associated AnimationSet.
331
+ *
332
+ * @param scene - Scene into which the model node will be created.
333
+ * @param url - Model URL or VFS path.
334
+ * @param options - Model loader options and instancing hint.
335
+ * @param httpRequest - Optional HttpRequest (unused for binary read; present for API symmetry).
336
+ * @returns A promise with the created node group and animation set info.
337
+ */ async fetchModel(scene, url, options, VFSs) {
338
+ const sharedModel = await this.fetchModelData(url, options, VFSs);
339
+ const node = sharedModel.createSceneNode(scene, !!options?.enableInstancing);
340
+ return {
341
+ group: node,
342
+ animationSet: node.animationSet
343
+ };
344
+ }
345
+ /**
346
+ * Load a text resource via VFS and optionally post-process it.
347
+ *
348
+ * - Does not use or modify the internal cache; use fetchTextData for cached loads.
349
+ *
350
+ * @param url - Resource URL or VFS path.
351
+ * @param postProcess - Optional transformation applied to the text.
352
+ * @returns A promise that resolves to the loaded (and optionally processed) text.
353
+ * @internal
354
+ */ async loadTextData(url, postProcess, VFSs) {
355
+ let text = await this.readFileFromVFSs(url, {
356
+ encoding: 'utf8'
357
+ }, VFSs);
197
358
  if (postProcess) {
198
359
  try {
199
360
  text = postProcess(text);
@@ -203,86 +364,437 @@ import { processMorphData } from '../animation/morphtarget.js';
203
364
  }
204
365
  return text;
205
366
  }
206
- /** @internal */ async loadBinaryData(url, postProcess) {
207
- let data = await this._httpRequest.requestArrayBuffer(url);
367
+ /**
368
+ * Load a JSON resource via VFS and optionally post-process it.
369
+ *
370
+ * - Does not use or modify the internal cache; use fetchJsonData for cached loads.
371
+ *
372
+ * @param url - Resource URL or VFS path.
373
+ * @param postProcess - Optional transformation applied to the parsed JSON.
374
+ * @returns A promise that resolves to the loaded (and optionally processed) JSON.
375
+ * @internal
376
+ */ async loadJsonData(url, postProcess, VFSs) {
377
+ let json = JSON.parse(await this.readFileFromVFSs(url, {
378
+ encoding: 'utf8'
379
+ }, VFSs));
208
380
  if (postProcess) {
209
381
  try {
210
- data = postProcess(data);
382
+ json = postProcess(json);
211
383
  } catch (err) {
212
- throw new Error(`Load binary data post process failed: ${err}`);
384
+ throw new Error(`Load json data post process failed: ${err}`);
213
385
  }
214
386
  }
215
- return data;
387
+ return json;
216
388
  }
217
- /** @internal */ async loadTexture(url, mimeType, srgb, samplerOptions, texture) {
218
- const data = await this._httpRequest.requestArrayBuffer(url);
219
- let ext = '';
220
- let filename = '';
221
- const dataUriMatchResult = url.match(/^data:([^;]+)/);
222
- if (dataUriMatchResult) {
223
- mimeType = mimeType || dataUriMatchResult[1];
224
- } else {
225
- filename = new URL(url, new URL(location.href).origin).pathname.split('/').filter((val)=>!!val).slice(-1)[0];
226
- const p = filename ? filename.lastIndexOf('.') : -1;
227
- ext = p >= 0 ? filename.substring(p).toLowerCase() : null;
228
- if (!mimeType) {
229
- if (ext === '.jpg' || ext === '.jpeg') {
230
- mimeType = 'image/jpg';
231
- } else if (ext === '.png') {
232
- mimeType = 'image/png';
389
+ /**
390
+ * Load a binary resource via VFS and optionally post-process it.
391
+ *
392
+ * - Does not use or modify the internal cache; use fetchBinaryData for cached loads.
393
+ *
394
+ * @param url - Resource URL or VFS path.
395
+ * @param postProcess - Optional transformation applied to the ArrayBuffer.
396
+ * @returns A promise that resolves to the loaded (and optionally processed) ArrayBuffer.
397
+ * @internal
398
+ */ async loadBinaryData(url, postProcess, VFSs) {
399
+ try {
400
+ let data = await this.readFileFromVFSs(url, {
401
+ encoding: 'binary'
402
+ }, VFSs);
403
+ if (postProcess) {
404
+ data = postProcess(data);
405
+ }
406
+ return data;
407
+ } catch (err) {
408
+ console.error(`Load binary data failed: ${err}`);
409
+ return null;
410
+ }
411
+ }
412
+ async loadPrimitive(url, VFSs) {
413
+ try {
414
+ const data = await this.readFileFromVFSs(url, {
415
+ encoding: 'utf8'
416
+ }, VFSs);
417
+ const content = JSON.parse(data);
418
+ ASSERT(content.type === 'Primitive' || content.type === 'Default', `Unsupported primitive type: ${content.type}`);
419
+ if (content.type === 'Primitive') {
420
+ const data = content.data;
421
+ const primitive = new Primitive();
422
+ for(const k in data.vertices){
423
+ const v = data.vertices[k];
424
+ const vertexData = base64ToUint8Array(v.data);
425
+ primitive.createAndSetVertexBuffer(v.format, vertexData);
426
+ }
427
+ if (data.indices) {
428
+ const indexData = base64ToUint8Array(data.indices);
429
+ const indices = data.indexType === 'u16' ? new Uint16Array(indexData.buffer) : data.indexType === 'u32' ? new Uint32Array(indexData.buffer) : null;
430
+ if (!indices) {
431
+ console.error(`Invalid index type in primitive data: ${data.indexType}`);
432
+ return null;
433
+ }
434
+ primitive.createAndSetIndexBuffer(indices);
233
435
  }
436
+ primitive.primitiveType = data.type;
437
+ primitive.indexCount = data.indexCount;
438
+ primitive.setBoundingVolume(new BoundingBox(new Vector3(data.boxMin[0], data.boxMin[1], data.boxMin[2]), new Vector3(data.boxMax[0], data.boxMax[1], data.boxMax[2])));
439
+ return primitive;
440
+ } else {
441
+ const obj = await this._resourceManager.deserializeObject(null, content.data);
442
+ if (!(obj instanceof Primitive)) {
443
+ if (typeof obj.dispose === 'function') {
444
+ obj.dispose();
445
+ }
446
+ return null;
447
+ }
448
+ return obj;
234
449
  }
450
+ } catch (err) {
451
+ console.error(`Load primitive failed: ${err}`);
452
+ return null;
235
453
  }
236
- for (const loader of this._textureLoaders){
237
- if ((!ext || !loader.supportExtension(ext)) && (!mimeType || !loader.supportMIMEType(mimeType))) {
238
- continue;
454
+ }
455
+ async reloadBluePrintMaterials(filter) {
456
+ const promises = [];
457
+ const paths = [];
458
+ for (const k of Object.keys(this._materials)){
459
+ const m = this._materials[k];
460
+ if (m instanceof Promise) {
461
+ promises.push(m);
462
+ paths.push(k);
463
+ } else if (m instanceof DWeakRef && !!m.get()) {
464
+ promises.push(Promise.resolve(m.get()));
465
+ paths.push(k);
466
+ }
467
+ }
468
+ const materials = await Promise.all(promises);
469
+ for(let i = 0; i < materials.length; i++){
470
+ const m = materials[i];
471
+ if (m instanceof PBRBluePrintMaterial && (!filter || filter(m))) {
472
+ const data = await this.loadBluePrintMaterialData(paths[i], true);
473
+ if (data) {
474
+ m.fragmentIR = data.irFragment;
475
+ m.vertexIR = data.irVertex;
476
+ m.uniformValues = data.uniformValues;
477
+ m.uniformTextures = data.uniformTextures;
478
+ }
239
479
  }
240
- const tex = await this.doLoadTexture(loader, filename, mimeType, data, !!srgb, samplerOptions, texture);
241
- tex.name = filename;
242
- if (url.match(/^blob:/)) {
243
- tex.restoreHandler = async (tex)=>{
244
- await this.doLoadTexture(loader, filename, mimeType, data, !!srgb, samplerOptions, tex);
245
- };
480
+ }
481
+ }
482
+ async loadBluePrintMaterialData(url, reload, VFSs) {
483
+ try {
484
+ let irData;
485
+ if (typeof url === 'string') {
486
+ const data = await this.readFileFromVFSs(url, {
487
+ encoding: 'utf8'
488
+ }, VFSs);
489
+ const content = JSON.parse(data);
490
+ ASSERT(content.type === 'PBRBluePrintMaterial' || content.type === 'SpriteBluePrintMaterial', `Unsupported material type: ${content.type}`);
491
+ irData = content.data;
246
492
  } else {
247
- const so = samplerOptions ? null : {
248
- ...samplerOptions
249
- };
250
- tex.restoreHandler = async (tex)=>{
251
- await this.loadTexture(url, mimeType, srgb, so, tex);
252
- };
493
+ irData = url;
494
+ }
495
+ const ir = reload ? await this.loadBluePrint(irData.IR, VFSs) : await this.fetchBluePrint(irData.IR, VFSs);
496
+ const uniformValues = irData.uniformValues.map((v)=>({
497
+ ...v,
498
+ finalValue: v.value.length === 1 ? v.value[0] : new Float32Array(v.value)
499
+ }));
500
+ const uniformTextures = [];
501
+ const textures = irData.uniformTextures;
502
+ for (const v of textures){
503
+ const tex = await this.fetchTexture(v.texture, {
504
+ linearColorSpace: !v.sRGB
505
+ }, VFSs);
506
+ uniformTextures.push({
507
+ ...v,
508
+ finalTexture: new DRef(tex),
509
+ finalSampler: getDevice().createSampler({
510
+ addressU: v.wrapS,
511
+ addressV: v.wrapT,
512
+ minFilter: v.minFilter,
513
+ magFilter: v.magFilter,
514
+ mipFilter: v.mipFilter
515
+ }),
516
+ params: tex ? new Vector4(tex.width, tex.height, tex.depth, tex.mipLevelCount) : Vector4.zero()
517
+ });
518
+ }
519
+ return {
520
+ irFragment: ir?.['fragment'] ?? null,
521
+ irVertex: ir?.['vertex'] ?? null,
522
+ uniformValues,
523
+ uniformTextures
524
+ };
525
+ } catch (err) {
526
+ console.error(`Load material failed: ${err}`);
527
+ return null;
528
+ }
529
+ }
530
+ /**
531
+ * Load a material.
532
+ *
533
+ * - Does not use or modify the internal cache; use fetchMaterial for cached loads.
534
+ *
535
+ * @param url - Resource URL or VFS path.
536
+ * @returns A promise that resolves to the loaded material.
537
+ * @internal
538
+ */ async loadMaterial(url, reload, VFSs) {
539
+ try {
540
+ const data = await this.readFileFromVFSs(url, {
541
+ encoding: 'utf8'
542
+ }, VFSs);
543
+ const content = JSON.parse(data);
544
+ ASSERT(content.type === 'PBRBluePrintMaterial' || content.type === 'SpriteBluePrintMaterial' || content.type === 'Default', `Unsupported material type: ${content.type}`);
545
+ let mat;
546
+ if (content.type === 'PBRBluePrintMaterial') {
547
+ const data = await this.loadBluePrintMaterialData(content.data, reload, VFSs);
548
+ mat = new PBRBluePrintMaterial(data.irFragment, data.irVertex, data.uniformValues, data.uniformTextures);
549
+ } else if (content.type === 'SpriteBluePrintMaterial') {
550
+ const data = await this.loadBluePrintMaterialData(content.data, reload, VFSs);
551
+ mat = new SpriteBlueprintMaterial(data.irFragment, data.uniformValues, data.uniformTextures);
552
+ } else {
553
+ const obj = await this._resourceManager.deserializeObject(null, content.data);
554
+ if (!(obj instanceof Material)) {
555
+ if (typeof obj.dispose === 'function') {
556
+ obj.dispose();
557
+ }
558
+ return null;
559
+ }
560
+ return obj;
561
+ }
562
+ if (mat && content.props) {
563
+ await this._resourceManager.deserializeObjectProps(mat, content.props);
564
+ }
565
+ return mat;
566
+ } catch (err) {
567
+ console.error(`Load material failed: ${err}`);
568
+ return null;
569
+ }
570
+ }
571
+ rebuildGraphStructure(nodes, links) {
572
+ const gs = {
573
+ outgoing: {},
574
+ incoming: {}
575
+ };
576
+ // Initialize adjacency lists
577
+ for(const nodeId in nodes){
578
+ gs.outgoing[nodeId] = [];
579
+ gs.incoming[nodeId] = [];
580
+ }
581
+ // Fill with links
582
+ for (const link of links){
583
+ const outConnection = {
584
+ targetNodeId: link.endNodeId,
585
+ startSlotId: link.startSlotId,
586
+ endSlotId: link.endSlotId
587
+ };
588
+ const inConnection = {
589
+ targetNodeId: link.startNodeId,
590
+ startSlotId: link.startSlotId,
591
+ endSlotId: link.endSlotId
592
+ };
593
+ gs.outgoing[link.startNodeId]?.push(outConnection);
594
+ gs.incoming[link.endNodeId]?.push(inConnection);
595
+ }
596
+ return gs;
597
+ }
598
+ collectReachableBackward(gs, nodes, roots) {
599
+ const reachable = new Set();
600
+ const q = [];
601
+ for (const r of roots){
602
+ if (nodes[r]) {
603
+ reachable.add(r);
604
+ q.push(r);
605
+ }
606
+ }
607
+ while(q.length > 0){
608
+ const u = q.shift();
609
+ const ins = gs.incoming[u] || [];
610
+ for (const conn of ins){
611
+ const v = conn.targetNodeId; // 前驱
612
+ if (!reachable.has(v)) {
613
+ reachable.add(v);
614
+ q.push(v);
615
+ }
616
+ }
617
+ }
618
+ return reachable;
619
+ }
620
+ getReverseTopologicalOrderFromRoots(gs, nodes, roots) {
621
+ if (!roots || roots.length === 0) {
622
+ return {
623
+ order: [],
624
+ levels: []
625
+ };
626
+ }
627
+ const sub = this.collectReachableBackward(gs, nodes, roots);
628
+ if (sub.size === 0) {
629
+ return {
630
+ order: [],
631
+ levels: []
632
+ };
633
+ }
634
+ const outDegree = new Map();
635
+ for (const id of sub){
636
+ const outs = (gs.outgoing[id] || []).filter((c)=>sub.has(c.targetNodeId));
637
+ outDegree.set(id, outs.length);
638
+ }
639
+ let currentLevel = Array.from(outDegree.entries()).filter(([, deg])=>deg === 0).map(([id])=>id);
640
+ const result = [];
641
+ const levels = [];
642
+ while(currentLevel.length > 0){
643
+ levels.push([
644
+ ...currentLevel
645
+ ]);
646
+ result.push(...currentLevel);
647
+ const nextLevel = [];
648
+ for (const u of currentLevel){
649
+ const ins = gs.incoming[u] || [];
650
+ for (const conn of ins){
651
+ const v = conn.targetNodeId; // 前驱
652
+ if (!sub.has(v)) {
653
+ continue;
654
+ }
655
+ const deg = outDegree.get(v) - 1;
656
+ outDegree.set(v, deg);
657
+ if (deg === 0) {
658
+ nextLevel.push(v);
659
+ }
660
+ }
661
+ }
662
+ currentLevel = nextLevel;
663
+ }
664
+ if (result.length !== sub.size) {
665
+ console.warn('Subgraph contains cycles (from given roots).');
666
+ return null;
667
+ }
668
+ return {
669
+ order: result,
670
+ levels
671
+ };
672
+ }
673
+ createBluePrintDAG(nodeMap, roots, links) {
674
+ const gs = this.rebuildGraphStructure(nodeMap, links);
675
+ for(const k in gs.incoming){
676
+ const node = nodeMap[k];
677
+ for (const conn of gs.incoming[k]){
678
+ const input = node.inputs.find((input)=>input.id === conn.endSlotId);
679
+ input.inputNode = nodeMap[conn.targetNodeId];
680
+ input.inputId = conn.startSlotId;
681
+ }
682
+ }
683
+ return {
684
+ graph: gs,
685
+ nodeMap,
686
+ roots,
687
+ order: this.getReverseTopologicalOrderFromRoots(gs, nodeMap, roots).order.reverse()
688
+ };
689
+ }
690
+ invalidateBluePrint(path) {
691
+ delete this._bluePrints[path];
692
+ }
693
+ async loadBluePrint(path, VFSs) {
694
+ try {
695
+ const content = await this.readFileFromVFSs(path, {
696
+ encoding: 'utf8'
697
+ }, VFSs);
698
+ const bp = JSON.parse(content);
699
+ ASSERT(bp.type === 'PBRMaterial' || bp.type === 'SpriteMaterial' || bp.type === 'MaterialFunction', `Unsupported blueprint type: ${bp.type}`);
700
+ const states = bp.state;
701
+ const result = {};
702
+ for (const k of Object.keys(states)){
703
+ const roots = [];
704
+ const nodeMap = {};
705
+ const state = states[k];
706
+ for (const node of state.nodes){
707
+ const impl = await this._resourceManager.deserializeObject(null, node.node);
708
+ nodeMap[node.id] = impl;
709
+ if (impl.outputs.length === 0) {
710
+ roots.push(node.id);
711
+ }
712
+ }
713
+ const dag = await this.createBluePrintDAG(nodeMap, roots, state.links);
714
+ result[k] = new MaterialBlueprintIR(dag, path, state);
715
+ }
716
+ return result;
717
+ } catch (err) {
718
+ const msg = `Load material failed: ${err}`;
719
+ console.error(msg);
720
+ return null;
721
+ }
722
+ }
723
+ /**
724
+ * Load a texture directly from an ArrayBuffer or typed array.
725
+ *
726
+ * - Chooses an appropriate loader based on the provided MIME type.
727
+ * - Can upload into an existing texture if `texture` is specified.
728
+ *
729
+ * @typeParam T - Expected concrete texture type.
730
+ * @param arrayBuffer - Raw texture data buffer.
731
+ * @param mimeType - MIME type of the texture (must be supported by a registered loader).
732
+ * @param srgb - If true, treat image as sRGB; otherwise linear.
733
+ * @param samplerOptions - Optional sampler options passed to the loader path.
734
+ * @param texture - Optional destination texture to populate.
735
+ * @returns A promise that resolves to the created or populated texture.
736
+ */ async loadTextureFromBuffer(arrayBuffer, mimeType, srgb, samplerOptions, texture) {
737
+ for (const loader of AssetManager._textureLoaders){
738
+ if (!loader.supportMIMEType(mimeType)) {
739
+ continue;
740
+ }
741
+ const tex = await this.doLoadTexture(loader, mimeType, arrayBuffer, !!srgb, samplerOptions, texture);
742
+ return tex;
743
+ }
744
+ throw new Error(`Can not find loader for MIME type '${mimeType}'`);
745
+ }
746
+ /**
747
+ * Load a texture via VFS by URL and MIME type.
748
+ *
749
+ * - Uses the first loader that supports the inferred or provided MIME type.
750
+ * - On WebGL, may repack textures (resample to power-of-two, convert formats) to meet backend constraints.
751
+ * - If `texture` is provided, the source is blitted into it, possibly resizing or changing sampling accordingly.
752
+ *
753
+ * @param url - Texture URL or VFS path.
754
+ * @param mimeType - Optional explicit MIME type; otherwise inferred by VFS.
755
+ * @param srgb - If true, treat image as sRGB; otherwise linear.
756
+ * @param samplerOptions - Optional sampler options for loader or blit path.
757
+ * @param texture - Optional destination texture to populate.
758
+ * @returns A promise that resolves to the created or populated texture.
759
+ * @internal
760
+ */ async loadTexture(url, mimeType, srgb, samplerOptions, texture, VFSs) {
761
+ const data = await this.readFileFromVFSs(url, {
762
+ encoding: 'binary'
763
+ }, VFSs);
764
+ mimeType = mimeType ?? this.vfs.guessMIMEType(url);
765
+ for (const loader of AssetManager._textureLoaders){
766
+ if (!loader.supportMIMEType(mimeType)) {
767
+ continue;
768
+ }
769
+ const tex = await this.doLoadTexture(loader, mimeType, data, !!srgb, samplerOptions, texture);
770
+ if (tex) {
771
+ tex.name = this.vfs.basename(url);
253
772
  }
254
773
  return tex;
255
774
  }
256
775
  throw new Error(`Can not find loader for asset ${url}`);
257
776
  }
258
- /** @internal */ async doLoadTexture(loader, url, mimeType, data, srgb, samplerOptions, texture) {
259
- const device = Application.instance.device;
777
+ /**
778
+ * Internal routine that executes the texture load using a specific loader and applies
779
+ * backend-specific compatibility steps (e.g., WebGL NPOT/sRGB rules).
780
+ *
781
+ * @param loader - Concrete loader to use for decoding/creation.
782
+ * @param mimeType - Texture MIME type.
783
+ * @param data - Raw binary data.
784
+ * @param srgb - If true, treat image as sRGB; otherwise linear.
785
+ * @param samplerOptions - Optional sampler options.
786
+ * @param texture - Optional destination texture to populate.
787
+ * @returns A promise that resolves to the created or populated texture.
788
+ * @internal
789
+ */ async doLoadTexture(loader, mimeType, data, srgb, samplerOptions, texture) {
790
+ const device = getDevice();
260
791
  if (device.type !== 'webgl') {
261
- return await loader.load(this, url, mimeType, data, srgb, samplerOptions, texture);
792
+ return await loader.load(mimeType, data, srgb, samplerOptions, texture);
262
793
  } else {
263
- let tex = await loader.load(this, url, mimeType, data, srgb, samplerOptions);
264
- if (texture) {
265
- const magFilter = tex.width !== texture.width || tex.height !== texture.height ? 'linear' : 'nearest';
266
- const minFilter = magFilter;
267
- const mipFilter = 'none';
268
- const sampler = device.createSampler({
269
- addressU: 'clamp',
270
- addressV: 'clamp',
271
- magFilter,
272
- minFilter,
273
- mipFilter
274
- });
275
- const blitter = new CopyBlitter();
276
- blitter.blit(tex, texture, sampler);
277
- tex = texture;
278
- } else {
279
- const po2_w = isPowerOf2(tex.width);
280
- const po2_h = isPowerOf2(tex.height);
281
- const srgb = tex.isSRGBFormat();
282
- if (srgb || !po2_w || !po2_h) {
283
- const newWidth = po2_w ? tex.width : nextPowerOf2(tex.width);
284
- const newHeight = po2_h ? tex.height : nextPowerOf2(tex.height);
285
- const magFilter = newWidth !== tex.width || newHeight !== tex.height ? 'linear' : 'nearest';
794
+ let tex = await loader.load(mimeType, data, srgb, samplerOptions);
795
+ if (tex) {
796
+ if (texture) {
797
+ const magFilter = tex.width !== texture.width || tex.height !== texture.height ? 'linear' : 'nearest';
286
798
  const minFilter = magFilter;
287
799
  const mipFilter = 'none';
288
800
  const sampler = device.createSampler({
@@ -292,27 +804,65 @@ import { processMorphData } from '../animation/morphtarget.js';
292
804
  minFilter,
293
805
  mipFilter
294
806
  });
295
- const destFormat = srgb ? 'rgba8unorm' : tex.format;
296
807
  const blitter = new CopyBlitter();
297
- const newTexture = tex.isTexture2D() ? device.createTexture2D(destFormat, newWidth, newHeight) : device.createCubeTexture(destFormat, newWidth);
298
- blitter.blit(tex, newTexture, sampler);
299
- tex.dispose();
300
- tex = newTexture;
808
+ blitter.blit(tex, texture, sampler);
809
+ tex = texture;
810
+ } else {
811
+ const po2_w = isPowerOf2(tex.width);
812
+ const po2_h = isPowerOf2(tex.height);
813
+ const srgb = tex.isSRGBFormat();
814
+ if (srgb || !po2_w || !po2_h) {
815
+ const newWidth = po2_w ? tex.width : nextPowerOf2(tex.width);
816
+ const newHeight = po2_h ? tex.height : nextPowerOf2(tex.height);
817
+ const magFilter = newWidth !== tex.width || newHeight !== tex.height ? 'linear' : 'nearest';
818
+ const minFilter = magFilter;
819
+ const mipFilter = 'none';
820
+ const sampler = device.createSampler({
821
+ addressU: 'clamp',
822
+ addressV: 'clamp',
823
+ magFilter,
824
+ minFilter,
825
+ mipFilter
826
+ });
827
+ const destFormat = srgb ? 'rgba8unorm' : tex.format;
828
+ const blitter = new CopyBlitter();
829
+ const newTexture = tex.isTexture2D() ? device.createTexture2D(destFormat, newWidth, newHeight) : device.createCubeTexture(destFormat, newWidth);
830
+ blitter.blit(tex, newTexture, sampler);
831
+ tex.dispose();
832
+ tex = newTexture;
833
+ }
301
834
  }
302
835
  }
303
836
  return tex;
304
837
  }
305
838
  }
306
- /** @internal */ async loadModel(url, options) {
307
- const data = await this.httpRequest.requestBlob(url);
308
- const filename = new URL(url, new URL(location.href).origin).pathname.split('/').filter((val)=>!!val).slice(-1)[0];
309
- const p = filename ? filename.lastIndexOf('.') : -1;
310
- const ext = p >= 0 ? filename.substring(p) : null;
311
- for (const loader of this._modelLoaders){
312
- if (!loader.supportExtension(ext) && !loader.supportMIMEType(options?.mimeType || data.type)) {
839
+ /**
840
+ * Load a model via registered model loaders.
841
+ *
842
+ * - Selects loader by MIME type (explicit or inferred).
843
+ * - Optionally applies a post-process transform to the SharedModel.
844
+ * - Sets the model's name from the source filename for convenience.
845
+ *
846
+ * @param url - Model URL or VFS path.
847
+ * @param options - Model load options (MIME override, Draco module, post-process hook).
848
+ * @returns A promise that resolves to the loaded SharedModel.
849
+ * @internal
850
+ */ async loadModel(url, options, VFSs) {
851
+ const arrayBuffer = await this.readFileFromVFSs(url, {
852
+ encoding: 'binary'
853
+ }, VFSs);
854
+ const mimeType = options?.mimeType || this.vfs.guessMIMEType(url);
855
+ const data = new Blob([
856
+ arrayBuffer
857
+ ], {
858
+ type: mimeType
859
+ });
860
+ const filename = this.vfs.basename(url);
861
+ for (const loader of AssetManager._modelLoaders){
862
+ if (!loader.supportMIMEType(mimeType)) {
313
863
  continue;
314
864
  }
315
- let model = await loader.load(this, url, options?.mimeType || data.type, data, options?.dracoDecoderModule);
865
+ let model = await loader.load(this, url, options?.mimeType || data.type, data, options?.dracoDecoderModule, VFSs);
316
866
  if (!model) {
317
867
  throw new Error(`Load asset failed: ${url}`);
318
868
  }
@@ -329,10 +879,17 @@ import { processMorphData } from '../animation/morphtarget.js';
329
879
  throw new Error(`Can not find loader for asset ${url}`);
330
880
  }
331
881
  /**
332
- * Fetches a built-in texture
333
- * @param name - Name of the built-in texture
334
- * @returns The built-in texture
335
- */ async fetchBuiltinTexture(name, texture) {
882
+ * Fetch a built-in texture synchronously by name.
883
+ *
884
+ * - If this built-in was not created yet, the registered loader is invoked.
885
+ * - Registers a device restore handler so the texture can be re-initialized after device loss.
886
+ * - If an existing texture is provided, the loader uploads into it.
887
+ *
888
+ * @typeParam T - Expected concrete texture type.
889
+ * @param name - Built-in texture identifier.
890
+ * @param texture - Optional destination texture to populate.
891
+ * @returns The built-in texture (created or populated).
892
+ */ fetchBuiltinTexture(name, texture) {
336
893
  const loader = AssetManager._builtinTextureLoaders[name];
337
894
  if (!loader) {
338
895
  throw new Error(`Unknown builtin texture name: ${name}`);
@@ -340,136 +897,81 @@ import { processMorphData } from '../animation/morphtarget.js';
340
897
  if (texture) {
341
898
  return loader(this, texture);
342
899
  } else {
343
- let P = AssetManager._builtinTextures[name];
344
- if (!P) {
345
- P = loader(this);
346
- AssetManager._builtinTextures[name] = P;
900
+ texture = AssetManager._builtinTextures[name];
901
+ if (!texture) {
902
+ texture = loader(this);
903
+ AssetManager._builtinTextures[name] = texture;
347
904
  }
348
- const tex = await P;
349
- tex.restoreHandler = async (tex)=>{
350
- await loader(this, tex);
905
+ texture.restoreHandler = (tex)=>{
906
+ loader(this, tex);
351
907
  };
352
- return tex;
908
+ return texture;
353
909
  }
354
910
  }
355
- /** @internal */ createSceneNode(scene, model, instancing) {
356
- const group = new SceneNode(scene);
357
- group.name = model.name;
358
- let animationSet = new AnimationSet(scene, group);
359
- for(let i = 0; i < model.scenes.length; i++){
360
- const assetScene = model.scenes[i];
361
- const skeletonMeshMap = new Map();
362
- const nodeMap = new Map();
363
- for(let k = 0; k < assetScene.rootNodes.length; k++){
364
- this.setAssetNodeToSceneNode(scene, group, model, assetScene.rootNodes[k], skeletonMeshMap, nodeMap, instancing);
365
- }
366
- for (const animationData of model.animations){
367
- const animation = new AnimationClip(animationData.name);
368
- for (const track of animationData.tracks){
369
- if (track.type === 'translation') {
370
- animation.addTrack(nodeMap.get(track.node), new TranslationTrack(track.interpolator));
371
- } else if (track.type === 'scale') {
372
- animation.addTrack(nodeMap.get(track.node), new ScaleTrack(track.interpolator));
373
- } else if (track.type === 'rotation') {
374
- animation.addTrack(nodeMap.get(track.node), new RotationTrack(track.interpolator));
375
- } else if (track.type === 'weights') {
376
- for (const m of track.node.mesh.subMeshes){
377
- if (track.interpolator.stride > MAX_MORPH_TARGETS) {
378
- console.error(`Morph target too large: ${track.interpolator.stride}, the maximum is ${MAX_MORPH_TARGETS}`);
379
- } else {
380
- const morphTrack = new MorphTargetTrack(track, m);
381
- animation.addTrack(m.mesh, morphTrack);
382
- }
383
- }
384
- } else {
385
- console.error(`Invalid animation track type: ${track.type}`);
386
- }
387
- }
388
- if (animation.tracks.size === 0) {
389
- continue;
390
- }
391
- animationSet.add(animation);
392
- for (const sk of animationData.skeletons){
393
- const nodes = skeletonMeshMap.get(sk);
394
- if (nodes) {
395
- if (!nodes.skeleton) {
396
- nodes.skeleton = new Skeleton(sk.joints.map((val)=>nodeMap.get(val)), sk.inverseBindMatrices, sk.bindPoseMatrices, nodes.mesh, nodes.bounding);
397
- }
398
- animation.addSkeleton(nodes.skeleton);
399
- }
400
- }
401
- }
402
- }
403
- if (animationSet.numAnimations === 0) {
404
- animationSet.dispose();
405
- animationSet = null;
406
- }
407
- return {
408
- group,
409
- animationSet
410
- };
411
- }
412
911
  /**
413
- * Sets the loader for a given builtin-texture
414
- * @param name - Name of the builtin texture
415
- * @param loader - Loader for the builtin texture
912
+ * Override or unregister the loader for a named built-in texture.
913
+ *
914
+ * - Passing a valid loader function sets/overrides the creation path.
915
+ * - Passing `undefined` removes the loader mapping for the given name.
916
+ *
917
+ * @param name - Built-in texture identifier.
918
+ * @param loader - Factory that creates the built-in texture using the provided AssetManager.
416
919
  */ static setBuiltinTextureLoader(name, loader) {
417
920
  if (loader) {
418
921
  this._builtinTextureLoaders[name] = loader;
419
922
  } else {
420
- this._builtinTextureLoaders[name] = undefined;
421
- }
422
- }
423
- /** @internal */ setAssetNodeToSceneNode(scene, parent, model, assetNode, skeletonMeshMap, nodeMap, instancing) {
424
- const node = new SceneNode(scene);
425
- nodeMap.set(assetNode, node);
426
- node.name = `${assetNode.name}`;
427
- node.position.set(assetNode.position);
428
- node.rotation.set(assetNode.rotation);
429
- node.scale.set(assetNode.scaling);
430
- if (assetNode.mesh) {
431
- const meshData = assetNode.mesh;
432
- const skeleton = assetNode.skeleton;
433
- for (const subMesh of meshData.subMeshes){
434
- for (const instance of assetNode.instances){
435
- const meshNode = new Mesh(scene);
436
- meshNode.position = instance.t;
437
- meshNode.scale = instance.s;
438
- meshNode.rotation = instance.r;
439
- meshNode.name = subMesh.name;
440
- meshNode.clipTestEnabled = true;
441
- meshNode.showState = 'inherit';
442
- meshNode.primitive = subMesh.primitive;
443
- meshNode.material = instancing ? subMesh.material.createInstance() : subMesh.material;
444
- meshNode.reparent(node);
445
- subMesh.mesh = meshNode;
446
- processMorphData(subMesh, meshData.morphWeights);
447
- if (skeleton) {
448
- if (!skeletonMeshMap.has(skeleton)) {
449
- skeletonMeshMap.set(skeleton, {
450
- mesh: [
451
- meshNode
452
- ],
453
- bounding: [
454
- subMesh
455
- ]
456
- });
457
- } else {
458
- skeletonMeshMap.get(skeleton).mesh.push(meshNode);
459
- skeletonMeshMap.get(skeleton).bounding.push(subMesh);
460
- }
461
- }
462
- }
463
- }
464
- }
465
- node.reparent(parent);
466
- for (const child of assetNode.children){
467
- this.setAssetNodeToSceneNode(scene, node, model, child, skeletonMeshMap, nodeMap, instancing);
923
+ delete this._builtinTextureLoaders[name];
468
924
  }
469
925
  }
470
- getHash(type, url, options) {
926
+ /**
927
+ * Compute a cache key for texture requests.
928
+ *
929
+ * Includes texture type tag, URL, and color space choice to avoid cross-color-space cache collisions.
930
+ *
931
+ * @typeParam T - Texture type parameter (not used for runtime behavior; helps preserve generic intent).
932
+ * @param type - Logical texture type tag (e.g., '2d', 'cube').
933
+ * @param url - Resource URL or VFS path.
934
+ * @param options - Texture fetch options to incorporate into the key.
935
+ * @returns A string cache key combining type, URL, and color space choice.
936
+ * @internal
937
+ */ getHash(type, url, options) {
471
938
  return `${type}:${url}:${!options?.linearColorSpace}`;
472
939
  }
940
+ /**
941
+ * Try reading from file from a list of VFSs
942
+ *
943
+ * @param path - File path
944
+ * @param options - Read options
945
+ * @param vfsList - VFS list
946
+ * @returns File content
947
+ *
948
+ * @internal
949
+ */ async readFileFromVFSs(path, options, vfsList) {
950
+ vfsList = vfsList ?? [
951
+ this.vfs
952
+ ];
953
+ for (const vfs of vfsList){
954
+ try {
955
+ return await vfs.readFile(path, options);
956
+ } catch {}
957
+ }
958
+ throw new VFSError(`File does not exist: ${path}`, 'ENOENT', path);
959
+ }
960
+ /**
961
+ * Write file to a list of VFSs
962
+ *
963
+ * @param path - File path
964
+ * @param data - Data to write
965
+ * @param options - Write options
966
+ * @param vfsList - Which VFSs will be written to
967
+ */ async writeFileToVFSs(path, data, options, vfsList) {
968
+ vfsList = vfsList ?? [
969
+ this.vfs
970
+ ];
971
+ for (const vfs of vfsList){
972
+ await vfs.writeFile(path, data, options);
973
+ }
974
+ }
473
975
  }
474
976
 
475
977
  export { AssetManager };