@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.
- package/dist/animation/animation.js +142 -31
- package/dist/animation/animation.js.map +1 -1
- package/dist/animation/animationset.js +186 -73
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/animationtrack.js +66 -10
- package/dist/animation/animationtrack.js.map +1 -1
- package/dist/animation/eulerrotationtrack.js +40 -20
- package/dist/animation/eulerrotationtrack.js.map +1 -1
- package/dist/animation/morphtarget.js +20 -38
- package/dist/animation/morphtarget.js.map +1 -1
- package/dist/animation/morphtrack.js +59 -22
- package/dist/animation/morphtrack.js.map +1 -1
- package/dist/animation/proptrack.js +186 -0
- package/dist/animation/proptrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +28 -11
- package/dist/animation/rotationtrack.js.map +1 -1
- package/dist/animation/scaletrack.js +28 -11
- package/dist/animation/scaletrack.js.map +1 -1
- package/dist/animation/skeleton.js +238 -82
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/translationtrack.js +29 -11
- package/dist/animation/translationtrack.js.map +1 -1
- package/dist/app/api.js +52 -0
- package/dist/app/api.js.map +1 -0
- package/dist/app/app.js +165 -0
- package/dist/app/app.js.map +1 -0
- package/dist/app/engine.js +300 -0
- package/dist/app/engine.js.map +1 -0
- package/dist/app/inputmgr.js +351 -0
- package/dist/app/inputmgr.js.map +1 -0
- package/dist/app/runtimescript.js +62 -0
- package/dist/app/runtimescript.js.map +1 -0
- package/dist/app/screen.js +318 -0
- package/dist/app/screen.js.map +1 -0
- package/dist/app/scriptingsystem.js +224 -0
- package/dist/app/scriptingsystem.js.map +1 -0
- package/dist/app/scriptregistry.js +421 -0
- package/dist/app/scriptregistry.js.map +1 -0
- package/dist/asset/assetmanager.js +823 -321
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/builtin.js +12 -48
- package/dist/asset/builtin.js.map +1 -1
- package/dist/asset/loaders/dds/dds.js +23 -95
- package/dist/asset/loaders/dds/dds.js.map +1 -1
- package/dist/asset/loaders/dds/dds_loader.js +9 -19
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +50 -48
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/gltf/helpers.js +33 -16
- package/dist/asset/loaders/gltf/helpers.js.map +1 -1
- package/dist/asset/loaders/hdr/hdr.js +39 -27
- package/dist/asset/loaders/hdr/hdr.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +15 -17
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -1
- package/dist/asset/loaders/image/webimage_loader.js +51 -50
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
- package/dist/asset/loaders/loader.js +2 -2
- package/dist/asset/loaders/loader.js.map +1 -1
- package/dist/asset/model.js +160 -6
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/bilateralblur.js +0 -1
- package/dist/blitter/bilateralblur.js.map +1 -1
- package/dist/blitter/blitter.js +28 -31
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/blitter/box.js +0 -1
- package/dist/blitter/box.js.map +1 -1
- package/dist/blitter/copy.js.map +1 -1
- package/dist/blitter/gaussianblur.js +23 -23
- package/dist/blitter/gaussianblur.js.map +1 -1
- package/dist/camera/base.js +139 -34
- package/dist/camera/base.js.map +1 -1
- package/dist/camera/camera.js +760 -172
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/fps.js +21 -27
- package/dist/camera/fps.js.map +1 -1
- package/dist/camera/orbit.js +134 -59
- package/dist/camera/orbit.js.map +1 -1
- package/dist/camera/orthocamera.js +52 -21
- package/dist/camera/orthocamera.js.map +1 -1
- package/dist/camera/perspectivecamera.js +60 -34
- package/dist/camera/perspectivecamera.js.map +1 -1
- package/dist/index.d.ts +17031 -6901
- package/dist/index.js +60 -21
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +5 -0
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/grassmaterial.js +6 -1
- package/dist/material/grassmaterial.js.map +1 -1
- package/dist/material/lambert.js +6 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +356 -77
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +505 -162
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +5 -1
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/foliage.js +3 -3
- package/dist/material/mixins/foliage.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +18 -5
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +6 -6
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +242 -0
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -0
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +52 -15
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +27 -9
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +19 -7
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/brdf.js +134 -0
- package/dist/material/mixins/pbr/brdf.js.map +1 -0
- package/dist/material/mixins/pbr/common.js +68 -85
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +101 -83
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +6 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/particle.js +272 -0
- package/dist/material/particle.js.map +1 -0
- package/dist/material/pbrblueprint.js +344 -0
- package/dist/material/pbrblueprint.js.map +1 -0
- package/dist/material/pbrmr.js +10 -0
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +10 -0
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +533 -316
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/sprite.js +301 -0
- package/dist/material/sprite.js.map +1 -0
- package/dist/material/sprite3d.js +301 -0
- package/dist/material/sprite3d.js.map +1 -0
- package/dist/material/sprite3d_std.js +116 -0
- package/dist/material/sprite3d_std.js.map +1 -0
- package/dist/material/sprite3dblueprint.js +235 -0
- package/dist/material/sprite3dblueprint.js.map +1 -0
- package/dist/material/sprite_std.js +116 -0
- package/dist/material/sprite_std.js.map +1 -0
- package/dist/material/spriteblueprint.js +235 -0
- package/dist/material/spriteblueprint.js.map +1 -0
- package/dist/material/terrain-cm.js +606 -0
- package/dist/material/terrain-cm.js.map +1 -0
- package/dist/material/terrainmaterial.js +59 -54
- package/dist/material/terrainmaterial.js.map +1 -1
- package/dist/material/unlit.js +5 -0
- package/dist/material/unlit.js.map +1 -1
- package/dist/material/water.js +415 -0
- package/dist/material/water.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +38 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +10 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +127 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +1 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +263 -0
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +1 -0
- package/dist/node_modules/es-module-lexer/dist/lexer.js +5 -0
- package/dist/node_modules/es-module-lexer/dist/lexer.js.map +1 -0
- package/dist/posteffect/bloom.js +39 -54
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +95 -128
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/fxaa.js +10 -18
- package/dist/posteffect/fxaa.js.map +1 -1
- package/dist/posteffect/grayscale.js +9 -17
- package/dist/posteffect/grayscale.js.map +1 -1
- package/dist/posteffect/motionblur.js +105 -0
- package/dist/posteffect/motionblur.js.map +1 -0
- package/dist/posteffect/posteffect.js +66 -35
- package/dist/posteffect/posteffect.js.map +1 -1
- package/dist/posteffect/sao.js +13 -21
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/ssr.js +65 -103
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/taa.js +175 -0
- package/dist/posteffect/taa.js.map +1 -0
- package/dist/posteffect/tonemap.js +12 -20
- package/dist/posteffect/tonemap.js.map +1 -1
- package/dist/render/abuffer_oit.js +38 -25
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/clipmap.js +424 -106
- package/dist/render/clipmap.js.map +1 -1
- package/dist/render/cluster_light.js +11 -9
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/cull_visitor.js +51 -13
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +15 -7
- package/dist/render/depthpass.js.map +1 -1
- package/dist/render/drawable.js +15 -0
- package/dist/render/drawable.js.map +1 -0
- package/dist/render/drawable_mixin.js +121 -44
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +86 -141
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +236 -0
- package/dist/render/fbm_wavegenerator.js.map +1 -0
- package/dist/render/fft_wavegenerator.js +131 -114
- package/dist/render/fft_wavegenerator.js.map +1 -1
- package/dist/render/fullscreenquad.js +2 -2
- package/dist/render/fullscreenquad.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +100 -48
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +7 -3
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/hzb.js +7 -5
- package/dist/render/hzb.js.map +1 -1
- package/dist/render/lightpass.js +28 -27
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +6 -9
- package/dist/render/objectcolorpass.js.map +1 -1
- package/dist/render/primitive.js +213 -105
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +49 -24
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderbundle_wrapper.js +65 -15
- package/dist/render/renderbundle_wrapper.js.map +1 -1
- package/dist/render/renderer.js +324 -189
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +43 -84
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/rendertarget.js +5 -0
- package/dist/render/rendertarget.js.map +1 -0
- package/dist/render/screenrendertarget.js +56 -0
- package/dist/render/screenrendertarget.js.map +1 -0
- package/dist/render/shadowmap_pass.js +5 -6
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +867 -542
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +13 -15
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +296 -0
- package/dist/scene/basesprite.js.map +1 -0
- package/dist/scene/batchgroup.js +22 -7
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +78 -49
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +2 -3
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/light.js +49 -92
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +298 -89
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +371 -162
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/particlesys.js +687 -0
- package/dist/scene/particlesys.js.map +1 -0
- package/dist/scene/raycast_visitor.js +26 -13
- package/dist/scene/raycast_visitor.js.map +1 -1
- package/dist/scene/scene.js +312 -85
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +663 -105
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/sprite.js +18 -0
- package/dist/scene/sprite.js.map +1 -0
- package/dist/scene/sprite3d.js +18 -0
- package/dist/scene/sprite3d.js.map +1 -0
- package/dist/scene/terrain/grass.js +48 -49
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/heightfield.js +46 -44
- package/dist/scene/terrain/heightfield.js.map +1 -1
- package/dist/scene/terrain/patch.js +20 -29
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +58 -27
- package/dist/scene/terrain/quadtree.js.map +1 -1
- package/dist/scene/terrain/terrain.js +31 -45
- package/dist/scene/terrain/terrain.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +604 -0
- package/dist/scene/terrain-cm/grass.js.map +1 -0
- package/dist/scene/terrain-cm/grassmaterial.js +162 -0
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -0
- package/dist/scene/terrain-cm/terrain-cm.js +550 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -0
- package/dist/scene/water.js +383 -0
- package/dist/scene/water.js.map +1 -0
- package/dist/shaders/atmosphere.js +945 -0
- package/dist/shaders/atmosphere.js.map +1 -0
- package/dist/shaders/fog.js +116 -0
- package/dist/shaders/fog.js.map +1 -0
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +217 -8
- package/dist/shaders/noise.js.map +1 -1
- package/dist/shaders/pbr.js.map +1 -1
- package/dist/shaders/shadow.js +8 -8
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/ssr.js +87 -39
- package/dist/shaders/ssr.js.map +1 -1
- package/dist/shaders/temporal.js +216 -0
- package/dist/shaders/temporal.js.map +1 -0
- package/dist/shaders/water.js +42 -20
- package/dist/shaders/water.js.map +1 -1
- package/dist/shadow/esm.js +32 -14
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +12 -13
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +12 -13
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +40 -0
- package/dist/shadow/shader.js.map +1 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +73 -44
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +15 -16
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +33 -16
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/shapes/box.js +187 -83
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/cylinder.js +101 -43
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/plane.js +70 -29
- package/dist/shapes/plane.js.map +1 -1
- package/dist/shapes/shape.js +121 -17
- package/dist/shapes/shape.js.map +1 -1
- package/dist/shapes/sphere.js +78 -44
- package/dist/shapes/sphere.js.map +1 -1
- package/dist/shapes/tetrahedron.js +255 -0
- package/dist/shapes/tetrahedron.js.map +1 -0
- package/dist/shapes/torus.js +76 -55
- package/dist/shapes/torus.js.map +1 -1
- package/dist/src/animation/animation.js +127 -0
- package/dist/src/animation/animation.js.map +1 -0
- package/dist/src/animation/animationset.js +255 -0
- package/dist/src/animation/animationset.js.map +1 -0
- package/dist/src/animation/animationtrack.js +34 -0
- package/dist/src/animation/animationtrack.js.map +1 -0
- package/dist/src/animation/eulerrotationtrack.js +52 -0
- package/dist/src/animation/eulerrotationtrack.js.map +1 -0
- package/dist/src/animation/morphtarget.js +93 -0
- package/dist/src/animation/morphtarget.js.map +1 -0
- package/dist/src/animation/morphtrack.js +70 -0
- package/dist/src/animation/morphtrack.js.map +1 -0
- package/dist/src/animation/proptrack.js +161 -0
- package/dist/src/animation/proptrack.js.map +1 -0
- package/dist/src/animation/rotationtrack.js +51 -0
- package/dist/src/animation/rotationtrack.js.map +1 -0
- package/dist/src/animation/scaletrack.js +50 -0
- package/dist/src/animation/scaletrack.js.map +1 -0
- package/dist/src/animation/skeleton.js +204 -0
- package/dist/src/animation/skeleton.js.map +1 -0
- package/dist/src/animation/translationtrack.js +50 -0
- package/dist/src/animation/translationtrack.js.map +1 -0
- package/dist/{app.js → src/app/app.js} +18 -40
- package/dist/src/app/app.js.map +1 -0
- package/dist/{input → src/app}/inputmgr.js +41 -16
- package/dist/src/app/inputmgr.js.map +1 -0
- package/dist/src/asset/assetmanager.js +404 -0
- package/dist/src/asset/assetmanager.js.map +1 -0
- package/dist/src/asset/builtin.js +337 -0
- package/dist/src/asset/builtin.js.map +1 -0
- package/dist/src/asset/loaders/dds/dds.js +470 -0
- package/dist/src/asset/loaders/dds/dds.js.map +1 -0
- package/dist/src/asset/loaders/dds/dds_loader.js +28 -0
- package/dist/src/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/src/asset/loaders/gltf/gltf_loader.js +1265 -0
- package/dist/src/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/src/asset/loaders/gltf/helpers.js +327 -0
- package/dist/src/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/src/asset/loaders/hdr/hdr.js +180 -0
- package/dist/src/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/src/asset/loaders/image/tga_Loader.js +116 -0
- package/dist/src/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/src/asset/loaders/image/webimage_loader.js +63 -0
- package/dist/src/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/src/asset/loaders/loader.js +45 -0
- package/dist/src/asset/loaders/loader.js.map +1 -0
- package/dist/src/asset/model.js +414 -0
- package/dist/src/asset/model.js.map +1 -0
- package/dist/{blitter/depthlimitedgaussion.js → src/blitter/bilateralblur.js} +1 -2
- package/dist/src/blitter/bilateralblur.js.map +1 -0
- package/dist/src/blitter/blitter.js +390 -0
- package/dist/src/blitter/blitter.js.map +1 -0
- package/dist/src/blitter/box.js +118 -0
- package/dist/src/blitter/box.js.map +1 -0
- package/dist/src/blitter/copy.js +22 -0
- package/dist/src/blitter/copy.js.map +1 -0
- package/dist/src/blitter/gaussianblur.js +228 -0
- package/dist/src/blitter/gaussianblur.js.map +1 -0
- package/dist/src/camera/base.js +92 -0
- package/dist/src/camera/base.js.map +1 -0
- package/dist/src/camera/camera.js +1005 -0
- package/dist/src/camera/camera.js.map +1 -0
- package/dist/src/camera/fps.js +238 -0
- package/dist/src/camera/fps.js.map +1 -0
- package/dist/src/camera/orbit.js +245 -0
- package/dist/src/camera/orbit.js.map +1 -0
- package/dist/src/camera/orthocamera.js +167 -0
- package/dist/src/camera/orthocamera.js.map +1 -0
- package/dist/src/camera/perspectivecamera.js +141 -0
- package/dist/src/camera/perspectivecamera.js.map +1 -0
- package/dist/src/index.js +120 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/material/blinn.js +81 -0
- package/dist/src/material/blinn.js.map +1 -0
- package/dist/src/material/grassmaterial.js +113 -0
- package/dist/src/material/grassmaterial.js.map +1 -0
- package/dist/src/material/lambert.js +92 -0
- package/dist/src/material/lambert.js.map +1 -0
- package/dist/src/material/material.js +301 -0
- package/dist/src/material/material.js.map +1 -0
- package/dist/src/material/meshmaterial.js +704 -0
- package/dist/src/material/meshmaterial.js.map +1 -0
- package/dist/src/material/mixins/albedocolor.js +76 -0
- package/dist/src/material/mixins/albedocolor.js.map +1 -0
- package/dist/src/material/mixins/foliage.js +47 -0
- package/dist/src/material/mixins/foliage.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/blinnphong.js +112 -0
- package/dist/src/material/mixins/lightmodel/blinnphong.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/lambert.js +58 -0
- package/dist/src/material/mixins/lightmodel/lambert.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +178 -0
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +139 -0
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
- package/dist/src/material/mixins/lit.js +476 -0
- package/dist/src/material/mixins/lit.js.map +1 -0
- package/dist/src/material/mixins/pbr/common.js +918 -0
- package/dist/src/material/mixins/pbr/common.js.map +1 -0
- package/dist/src/material/mixins/texture.js +172 -0
- package/dist/src/material/mixins/texture.js.map +1 -0
- package/dist/src/material/mixins/vertexcolor.js +56 -0
- package/dist/src/material/mixins/vertexcolor.js.map +1 -0
- package/dist/src/material/particle.js +178 -0
- package/dist/src/material/particle.js.map +1 -0
- package/dist/src/material/pbrmr.js +97 -0
- package/dist/src/material/pbrmr.js.map +1 -0
- package/dist/src/material/pbrsg.js +97 -0
- package/dist/src/material/pbrsg.js.map +1 -0
- package/dist/src/material/shader/helper.js +1209 -0
- package/dist/src/material/shader/helper.js.map +1 -0
- package/dist/src/material/terrain-cm.js +606 -0
- package/dist/src/material/terrain-cm.js.map +1 -0
- package/dist/src/material/terrainmaterial.js +375 -0
- package/dist/src/material/terrainmaterial.js.map +1 -0
- package/dist/src/material/unlit.js +41 -0
- package/dist/src/material/unlit.js.map +1 -0
- package/dist/src/material/water.js +417 -0
- package/dist/src/material/water.js.map +1 -0
- package/dist/src/posteffect/bloom.js +361 -0
- package/dist/src/posteffect/bloom.js.map +1 -0
- package/dist/src/posteffect/compositor.js +226 -0
- package/dist/src/posteffect/compositor.js.map +1 -0
- package/dist/src/posteffect/fxaa.js +273 -0
- package/dist/src/posteffect/fxaa.js.map +1 -0
- package/dist/src/posteffect/grayscale.js +69 -0
- package/dist/src/posteffect/grayscale.js.map +1 -0
- package/dist/src/posteffect/motionblur.js +96 -0
- package/dist/src/posteffect/motionblur.js.map +1 -0
- package/dist/src/posteffect/posteffect.js +126 -0
- package/dist/src/posteffect/posteffect.js.map +1 -0
- package/dist/src/posteffect/sao.js +324 -0
- package/dist/src/posteffect/sao.js.map +1 -0
- package/dist/src/posteffect/ssr.js +489 -0
- package/dist/src/posteffect/ssr.js.map +1 -0
- package/dist/src/posteffect/taa.js +172 -0
- package/dist/src/posteffect/taa.js.map +1 -0
- package/dist/src/posteffect/tonemap.js +94 -0
- package/dist/src/posteffect/tonemap.js.map +1 -0
- package/dist/src/render/abuffer_oit.js +361 -0
- package/dist/src/render/abuffer_oit.js.map +1 -0
- package/dist/src/render/clipmap.js +851 -0
- package/dist/src/render/clipmap.js.map +1 -0
- package/dist/src/render/cluster_light.js +333 -0
- package/dist/src/render/cluster_light.js.map +1 -0
- package/dist/src/render/cull_visitor.js +187 -0
- package/dist/src/render/cull_visitor.js.map +1 -0
- package/dist/src/render/depthpass.js +68 -0
- package/dist/src/render/depthpass.js.map +1 -0
- package/dist/src/render/drawable_mixin.js +227 -0
- package/dist/src/render/drawable_mixin.js.map +1 -0
- package/dist/src/render/envlight.js +463 -0
- package/dist/src/render/envlight.js.map +1 -0
- package/dist/src/render/fbm_wavegenerator.js +251 -0
- package/dist/src/render/fbm_wavegenerator.js.map +1 -0
- package/dist/src/render/fft_wavegenerator.js +1006 -0
- package/dist/src/render/fft_wavegenerator.js.map +1 -0
- package/dist/src/render/fullscreenquad.js +38 -0
- package/dist/src/render/fullscreenquad.js.map +1 -0
- package/dist/src/render/gerstner_wavegenerator.js +314 -0
- package/dist/src/render/gerstner_wavegenerator.js.map +1 -0
- package/dist/src/render/globalbindgroup_allocator.js +60 -0
- package/dist/src/render/globalbindgroup_allocator.js.map +1 -0
- package/dist/src/render/hzb.js +273 -0
- package/dist/src/render/hzb.js.map +1 -0
- package/dist/src/render/lightpass.js +172 -0
- package/dist/src/render/lightpass.js.map +1 -0
- package/dist/src/render/objectcolorpass.js +51 -0
- package/dist/src/render/objectcolorpass.js.map +1 -0
- package/dist/src/render/primitive.js +364 -0
- package/dist/src/render/primitive.js.map +1 -0
- package/dist/src/render/render_queue.js +467 -0
- package/dist/src/render/render_queue.js.map +1 -0
- package/dist/src/render/renderbundle_wrapper.js +152 -0
- package/dist/src/render/renderbundle_wrapper.js.map +1 -0
- package/dist/src/render/renderer.js +455 -0
- package/dist/src/render/renderer.js.map +1 -0
- package/dist/src/render/renderpass.js +200 -0
- package/dist/src/render/renderpass.js.map +1 -0
- package/dist/src/render/shadowmap_pass.js +56 -0
- package/dist/src/render/shadowmap_pass.js.map +1 -0
- package/dist/src/render/sky.js +1103 -0
- package/dist/src/render/sky.js.map +1 -0
- package/dist/src/render/weightedblended_oit.js +168 -0
- package/dist/src/render/weightedblended_oit.js.map +1 -0
- package/dist/src/scene/batchgroup.js +162 -0
- package/dist/src/scene/batchgroup.js.map +1 -0
- package/dist/src/scene/environment.js +209 -0
- package/dist/src/scene/environment.js.map +1 -0
- package/dist/src/scene/graph_node.js +72 -0
- package/dist/src/scene/graph_node.js.map +1 -0
- package/dist/src/scene/light.js +416 -0
- package/dist/src/scene/light.js.map +1 -0
- package/dist/src/scene/mesh.js +341 -0
- package/dist/src/scene/mesh.js.map +1 -0
- package/dist/src/scene/octree.js +649 -0
- package/dist/src/scene/octree.js.map +1 -0
- package/dist/src/scene/particlesys.js +738 -0
- package/dist/src/scene/particlesys.js.map +1 -0
- package/dist/src/scene/raycast_visitor.js +103 -0
- package/dist/src/scene/raycast_visitor.js.map +1 -0
- package/dist/src/scene/scene.js +284 -0
- package/dist/src/scene/scene.js.map +1 -0
- package/dist/src/scene/scene_node.js +732 -0
- package/dist/src/scene/scene_node.js.map +1 -0
- package/dist/src/scene/terrain/grass.js +278 -0
- package/dist/src/scene/terrain/grass.js.map +1 -0
- package/dist/src/scene/terrain/heightfield.js +475 -0
- package/dist/src/scene/terrain/heightfield.js.map +1 -0
- package/dist/src/scene/terrain/patch.js +530 -0
- package/dist/src/scene/terrain/patch.js.map +1 -0
- package/dist/src/scene/terrain/quadtree.js +461 -0
- package/dist/src/scene/terrain/quadtree.js.map +1 -0
- package/dist/src/scene/terrain/terrain.js +246 -0
- package/dist/src/scene/terrain/terrain.js.map +1 -0
- package/dist/src/scene/terrain-cm/grass.js +594 -0
- package/dist/src/scene/terrain-cm/grass.js.map +1 -0
- package/dist/src/scene/terrain-cm/grassmaterial.js +159 -0
- package/dist/src/scene/terrain-cm/grassmaterial.js.map +1 -0
- package/dist/src/scene/terrain-cm/terrain-cm.js +538 -0
- package/dist/src/scene/terrain-cm/terrain-cm.js.map +1 -0
- package/dist/src/scene/water.js +374 -0
- package/dist/src/scene/water.js.map +1 -0
- package/dist/src/shaders/atmosphere.js +957 -0
- package/dist/src/shaders/atmosphere.js.map +1 -0
- package/dist/src/shaders/fog.js +112 -0
- package/dist/src/shaders/fog.js.map +1 -0
- package/dist/src/shaders/misc.js +266 -0
- package/dist/src/shaders/misc.js.map +1 -0
- package/dist/src/shaders/noise.js +222 -0
- package/dist/src/shaders/noise.js.map +1 -0
- package/dist/src/shaders/pbr.js +51 -0
- package/dist/src/shaders/pbr.js.map +1 -0
- package/dist/src/shaders/shadow.js +636 -0
- package/dist/src/shaders/shadow.js.map +1 -0
- package/dist/src/shaders/ssr.js +490 -0
- package/dist/src/shaders/ssr.js.map +1 -0
- package/dist/src/shaders/temporal.js +215 -0
- package/dist/src/shaders/temporal.js.map +1 -0
- package/dist/src/shaders/water.js +756 -0
- package/dist/src/shaders/water.js.map +1 -0
- package/dist/src/shadow/esm.js +237 -0
- package/dist/src/shadow/esm.js.map +1 -0
- package/dist/src/shadow/pcf_opt.js +181 -0
- package/dist/src/shadow/pcf_opt.js.map +1 -0
- package/dist/src/shadow/pcf_pd.js +189 -0
- package/dist/src/shadow/pcf_pd.js.map +1 -0
- package/dist/src/shadow/shader.js +37 -0
- package/dist/src/shadow/shader.js.map +1 -0
- package/dist/src/shadow/shadow_impl.js +15 -0
- package/dist/src/shadow/shadow_impl.js.map +1 -0
- package/dist/src/shadow/shadowmapper.js +790 -0
- package/dist/src/shadow/shadowmapper.js.map +1 -0
- package/dist/src/shadow/ssm.js +159 -0
- package/dist/src/shadow/ssm.js.map +1 -0
- package/dist/src/shadow/vsm.js +297 -0
- package/dist/src/shadow/vsm.js.map +1 -0
- package/dist/src/shapes/box.js +386 -0
- package/dist/src/shapes/box.js.map +1 -0
- package/dist/src/shapes/cylinder.js +125 -0
- package/dist/src/shapes/cylinder.js.map +1 -0
- package/dist/src/shapes/plane.js +88 -0
- package/dist/src/shapes/plane.js.map +1 -0
- package/dist/src/shapes/shape.js +87 -0
- package/dist/src/shapes/shape.js.map +1 -0
- package/dist/src/shapes/sphere.js +114 -0
- package/dist/src/shapes/sphere.js.map +1 -0
- package/dist/src/shapes/tetrahedron.js +188 -0
- package/dist/src/shapes/tetrahedron.js.map +1 -0
- package/dist/src/shapes/torus.js +111 -0
- package/dist/src/shapes/torus.js.map +1 -0
- package/dist/src/utility/aabbtree.js +400 -0
- package/dist/src/utility/aabbtree.js.map +1 -0
- package/dist/src/utility/bounding_volume.js +29 -0
- package/dist/src/utility/bounding_volume.js.map +1 -0
- package/dist/src/utility/debug.js +28 -0
- package/dist/src/utility/debug.js.map +1 -0
- package/dist/src/utility/draco/decoder.js +116 -0
- package/dist/src/utility/draco/decoder.js.map +1 -0
- package/dist/src/utility/misc.js +105 -0
- package/dist/src/utility/misc.js.map +1 -0
- package/dist/src/utility/panorama.js +163 -0
- package/dist/src/utility/panorama.js.map +1 -0
- package/dist/src/utility/pmrem.js +354 -0
- package/dist/src/utility/pmrem.js.map +1 -0
- package/dist/src/utility/rendermipmap.js +115 -0
- package/dist/src/utility/rendermipmap.js.map +1 -0
- package/dist/src/utility/serialization/json.js +402 -0
- package/dist/src/utility/serialization/json.js.map +1 -0
- package/dist/src/utility/serialization/manager.js +623 -0
- package/dist/src/utility/serialization/manager.js.map +1 -0
- package/dist/src/utility/serialization/scene/animation.js +248 -0
- package/dist/src/utility/serialization/scene/animation.js.map +1 -0
- package/dist/src/utility/serialization/scene/batch.js +59 -0
- package/dist/src/utility/serialization/scene/batch.js.map +1 -0
- package/dist/src/utility/serialization/scene/camera.js +790 -0
- package/dist/src/utility/serialization/scene/camera.js.map +1 -0
- package/dist/src/utility/serialization/scene/common.js +222 -0
- package/dist/src/utility/serialization/scene/common.js.map +1 -0
- package/dist/src/utility/serialization/scene/light.js +575 -0
- package/dist/src/utility/serialization/scene/light.js.map +1 -0
- package/dist/src/utility/serialization/scene/material.js +1111 -0
- package/dist/src/utility/serialization/scene/material.js.map +1 -0
- package/dist/src/utility/serialization/scene/mesh.js +148 -0
- package/dist/src/utility/serialization/scene/mesh.js.map +1 -0
- package/dist/src/utility/serialization/scene/misc.js +39 -0
- package/dist/src/utility/serialization/scene/misc.js.map +1 -0
- package/dist/src/utility/serialization/scene/node.js +451 -0
- package/dist/src/utility/serialization/scene/node.js.map +1 -0
- package/dist/src/utility/serialization/scene/particle.js +425 -0
- package/dist/src/utility/serialization/scene/particle.js.map +1 -0
- package/dist/src/utility/serialization/scene/primitive.js +692 -0
- package/dist/src/utility/serialization/scene/primitive.js.map +1 -0
- package/dist/src/utility/serialization/scene/scene.js +704 -0
- package/dist/src/utility/serialization/scene/scene.js.map +1 -0
- package/dist/src/utility/serialization/scene/terrain.js +488 -0
- package/dist/src/utility/serialization/scene/terrain.js.map +1 -0
- package/dist/src/utility/serialization/scene/water.js +465 -0
- package/dist/src/utility/serialization/scene/water.js.map +1 -0
- package/dist/src/utility/shprojector.js +297 -0
- package/dist/src/utility/shprojector.js.map +1 -0
- package/dist/{material/mixins → src/utility/textures}/ggxlut.js +1 -1
- package/dist/src/utility/textures/ggxlut.js.map +1 -0
- package/dist/src/utility/textures/gradientnoise.js +62 -0
- package/dist/src/utility/textures/gradientnoise.js.map +1 -0
- package/dist/src/utility/textures/randomnoise.js +41 -0
- package/dist/src/utility/textures/randomnoise.js.map +1 -0
- package/dist/src/values.js +162 -0
- package/dist/src/values.js.map +1 -0
- package/dist/utility/aabbtree.js +16 -6
- package/dist/utility/aabbtree.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +1325 -0
- package/dist/utility/blueprint/common/constants.js.map +1 -0
- package/dist/utility/blueprint/common/math.js +2507 -0
- package/dist/utility/blueprint/common/math.js.map +1 -0
- package/dist/utility/blueprint/common.js +7 -0
- package/dist/utility/blueprint/common.js.map +1 -0
- package/dist/utility/blueprint/material/common.js +7 -0
- package/dist/utility/blueprint/material/common.js.map +1 -0
- package/dist/utility/blueprint/material/func.js +525 -0
- package/dist/utility/blueprint/material/func.js.map +1 -0
- package/dist/utility/blueprint/material/inputs.js +1659 -0
- package/dist/utility/blueprint/material/inputs.js.map +1 -0
- package/dist/utility/blueprint/material/ir.js +1519 -0
- package/dist/utility/blueprint/material/ir.js.map +1 -0
- package/dist/utility/blueprint/material/pbr.js +450 -0
- package/dist/utility/blueprint/material/pbr.js.map +1 -0
- package/dist/utility/blueprint/material/texture.js +1116 -0
- package/dist/utility/blueprint/material/texture.js.map +1 -0
- package/dist/utility/blueprint/node.js +214 -0
- package/dist/utility/blueprint/node.js.map +1 -0
- package/dist/utility/bounding_volume.js +0 -1
- package/dist/utility/bounding_volume.js.map +1 -1
- package/dist/utility/debug.js +26 -0
- package/dist/utility/debug.js.map +1 -0
- package/dist/utility/draco/decoder.js +1 -1
- package/dist/utility/draco/decoder.js.map +1 -1
- package/dist/utility/misc.js +19 -7
- package/dist/utility/misc.js.map +1 -1
- package/dist/utility/panorama.js +8 -6
- package/dist/utility/panorama.js.map +1 -1
- package/dist/utility/pmrem.js +30 -18
- package/dist/utility/pmrem.js.map +1 -1
- package/dist/utility/rendermipmap.js +116 -0
- package/dist/utility/rendermipmap.js.map +1 -0
- package/dist/utility/serialization/blueprint/constants.js +255 -0
- package/dist/utility/serialization/blueprint/constants.js.map +1 -0
- package/dist/utility/serialization/blueprint/material/constants.js +203 -0
- package/dist/utility/serialization/blueprint/material/constants.js.map +1 -0
- package/dist/utility/serialization/blueprint/material/texture.js +165 -0
- package/dist/utility/serialization/blueprint/material/texture.js.map +1 -0
- package/dist/utility/serialization/json.js +406 -0
- package/dist/utility/serialization/json.js.map +1 -0
- package/dist/utility/serialization/manager.js +1243 -0
- package/dist/utility/serialization/manager.js.map +1 -0
- package/dist/utility/serialization/scene/animation.js +701 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -0
- package/dist/utility/serialization/scene/batch.js +54 -0
- package/dist/utility/serialization/scene/batch.js.map +1 -0
- package/dist/utility/serialization/scene/camera.js +896 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -0
- package/dist/utility/serialization/scene/common.js +298 -0
- package/dist/utility/serialization/scene/common.js.map +1 -0
- package/dist/utility/serialization/scene/light.js +591 -0
- package/dist/utility/serialization/scene/light.js.map +1 -0
- package/dist/utility/serialization/scene/material.js +1070 -0
- package/dist/utility/serialization/scene/material.js.map +1 -0
- package/dist/utility/serialization/scene/mesh.js +345 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -0
- package/dist/utility/serialization/scene/misc.js +40 -0
- package/dist/utility/serialization/scene/misc.js.map +1 -0
- package/dist/utility/serialization/scene/node.js +424 -0
- package/dist/utility/serialization/scene/node.js.map +1 -0
- package/dist/utility/serialization/scene/particle.js +427 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -0
- package/dist/utility/serialization/scene/primitive.js +585 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -0
- package/dist/utility/serialization/scene/scene.js +764 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -0
- package/dist/utility/serialization/scene/sprite.js +164 -0
- package/dist/utility/serialization/scene/sprite.js.map +1 -0
- package/dist/utility/serialization/scene/terrain.js +497 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -0
- package/dist/utility/serialization/scene/water.js +467 -0
- package/dist/utility/serialization/scene/water.js.map +1 -0
- package/dist/utility/serialization/types.js +6 -0
- package/dist/utility/serialization/types.js.map +1 -0
- package/dist/utility/shprojector.js +313 -0
- package/dist/utility/shprojector.js.map +1 -0
- package/dist/utility/textures/ggxlut.js +4 -5
- package/dist/utility/textures/ggxlut.js.map +1 -1
- package/dist/utility/textures/gradientnoise.js +2 -1
- package/dist/utility/textures/gradientnoise.js.map +1 -1
- package/dist/utility/textures/randomnoise.js +1 -0
- package/dist/utility/textures/randomnoise.js.map +1 -1
- package/dist/values.js +103 -16
- package/dist/values.js.map +1 -1
- package/package.json +80 -66
- package/dist/app.js.map +0 -1
- package/dist/blitter/depthlimitedgaussion.js.map +0 -1
- package/dist/input/inputmgr.js.map +0 -1
- package/dist/material/mixins/ggxlut.js.map +0 -1
- package/dist/posteffect/water.js +0 -508
- package/dist/posteffect/water.js.map +0 -1
- package/dist/render/oit.js +0 -16
- package/dist/render/oit.js.map +0 -1
- package/dist/render/scatteringlut.js +0 -634
- package/dist/render/scatteringlut.js.map +0 -1
- package/dist/render/watermesh.js +0 -193
- package/dist/render/watermesh.js.map +0 -1
- package/dist/render/wavegenerator.js +0 -8
- package/dist/render/wavegenerator.js.map +0 -1
- package/dist/scene/xform.js +0 -247
- package/dist/scene/xform.js.map +0 -1
- package/dist/utility/shprojection.js +0 -442
- package/dist/utility/shprojection.js.map +0 -1
|
@@ -1,199 +1,360 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
|
19
|
-
import { BUILTIN_ASSET_TEXTURE_SHEEN_LUT
|
|
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
|
|
22
|
-
import
|
|
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
|
-
*
|
|
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 */
|
|
34
|
-
|
|
35
|
-
|
|
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.
|
|
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
|
-
*
|
|
60
|
-
*/ get
|
|
61
|
-
return this.
|
|
88
|
+
* VFS used to read resources (files, URLs, virtual mounts).
|
|
89
|
+
*/ get vfs() {
|
|
90
|
+
return this._resourceManager.VFS;
|
|
62
91
|
}
|
|
63
92
|
/**
|
|
64
|
-
*
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
*
|
|
140
|
+
* Register a texture loader (highest priority first).
|
|
84
141
|
*
|
|
85
|
-
*
|
|
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 -
|
|
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
|
-
*
|
|
151
|
+
* Register a model loader (highest priority first).
|
|
96
152
|
*
|
|
97
|
-
*
|
|
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 -
|
|
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
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
let P = this._textDatas[
|
|
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.
|
|
122
|
-
this.
|
|
195
|
+
P = this.loadJsonData(url, postProcess, VFSs);
|
|
196
|
+
this._jsonDatas[hash] = P;
|
|
123
197
|
}
|
|
124
198
|
return P;
|
|
125
199
|
}
|
|
126
200
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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[
|
|
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
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
150
|
-
* @
|
|
151
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* @
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
/**
|
|
207
|
-
|
|
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
|
-
|
|
382
|
+
json = postProcess(json);
|
|
211
383
|
} catch (err) {
|
|
212
|
-
throw new Error(`Load
|
|
384
|
+
throw new Error(`Load json data post process failed: ${err}`);
|
|
213
385
|
}
|
|
214
386
|
}
|
|
215
|
-
return
|
|
387
|
+
return json;
|
|
216
388
|
}
|
|
217
|
-
/**
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
/**
|
|
259
|
-
|
|
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(
|
|
792
|
+
return await loader.load(mimeType, data, srgb, samplerOptions, texture);
|
|
262
793
|
} else {
|
|
263
|
-
let tex = await loader.load(
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
/**
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
|
|
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
|
-
|
|
344
|
-
if (!
|
|
345
|
-
|
|
346
|
-
AssetManager._builtinTextures[name] =
|
|
900
|
+
texture = AssetManager._builtinTextures[name];
|
|
901
|
+
if (!texture) {
|
|
902
|
+
texture = loader(this);
|
|
903
|
+
AssetManager._builtinTextures[name] = texture;
|
|
347
904
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
await loader(this, tex);
|
|
905
|
+
texture.restoreHandler = (tex)=>{
|
|
906
|
+
loader(this, tex);
|
|
351
907
|
};
|
|
352
|
-
return
|
|
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
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
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]
|
|
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
|
-
|
|
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 };
|