@thunderclap-engine/engine 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +390 -0
- package/LICENSE +21 -0
- package/README.md +333 -2
- package/dist/analytics/analytics.d.ts +80 -0
- package/dist/analytics/analytics.js +129 -0
- package/dist/analytics/index.d.ts +1 -0
- package/dist/analytics/index.js +1 -0
- package/dist/anim/aim.d.ts +43 -0
- package/dist/anim/aim.js +157 -0
- package/dist/anim/clip.d.ts +98 -0
- package/dist/anim/clip.js +282 -0
- package/dist/anim/compress.d.ts +65 -0
- package/dist/anim/compress.js +339 -0
- package/dist/anim/foot-ik.d.ts +74 -0
- package/dist/anim/foot-ik.js +241 -0
- package/dist/anim/graph.d.ts +153 -0
- package/dist/anim/graph.js +532 -0
- package/dist/anim/ik.d.ts +105 -0
- package/dist/anim/ik.js +435 -0
- package/dist/anim/index.d.ts +36 -0
- package/dist/anim/index.js +21 -0
- package/dist/anim/match.d.ts +66 -0
- package/dist/anim/match.js +153 -0
- package/dist/anim/mixer.d.ts +113 -0
- package/dist/anim/mixer.js +314 -0
- package/dist/anim/morph.d.ts +41 -0
- package/dist/anim/morph.js +94 -0
- package/dist/anim/pose.d.ts +74 -0
- package/dist/anim/pose.js +254 -0
- package/dist/anim/quat.d.ts +44 -0
- package/dist/anim/quat.js +187 -0
- package/dist/anim/retarget.d.ts +97 -0
- package/dist/anim/retarget.js +366 -0
- package/dist/anim/root-motion.d.ts +44 -0
- package/dist/anim/root-motion.js +224 -0
- package/dist/anim/skin-pose.d.ts +39 -0
- package/dist/anim/skin-pose.js +53 -0
- package/dist/anim/socket.d.ts +47 -0
- package/dist/anim/socket.js +84 -0
- package/dist/anim/spring-chain.d.ts +73 -0
- package/dist/anim/spring-chain.js +294 -0
- package/dist/assets/atlas.d.ts +90 -0
- package/dist/assets/atlas.js +212 -0
- package/dist/assets/baked.d.ts +33 -0
- package/dist/assets/baked.js +38 -0
- package/dist/assets/bundle.d.ts +88 -0
- package/dist/assets/bundle.js +464 -0
- package/dist/assets/cache.d.ts +56 -0
- package/dist/assets/cache.js +123 -0
- package/dist/assets/gltf-load.d.ts +252 -0
- package/dist/assets/gltf-load.js +661 -0
- package/dist/assets/gltf-skin.d.ts +36 -0
- package/dist/assets/gltf-skin.js +109 -0
- package/dist/assets/gltf.d.ts +706 -0
- package/dist/assets/gltf.js +1376 -0
- package/dist/assets/index.d.ts +20 -0
- package/dist/assets/index.js +10 -0
- package/dist/assets/ktx2.d.ts +71 -0
- package/dist/assets/ktx2.js +213 -0
- package/dist/assets/manifest.d.ts +79 -0
- package/dist/assets/manifest.js +7 -0
- package/dist/assets/meshopt.d.ts +23 -0
- package/dist/assets/meshopt.js +403 -0
- package/dist/audio/audio.d.ts +733 -0
- package/dist/audio/audio.js +2013 -0
- package/dist/audio/dsp.d.ts +61 -0
- package/dist/audio/dsp.js +159 -0
- package/dist/audio/duck.d.ts +44 -0
- package/dist/audio/duck.js +101 -0
- package/dist/audio/envelope.d.ts +53 -0
- package/dist/audio/envelope.js +106 -0
- package/dist/audio/index.d.ts +13 -0
- package/dist/audio/index.js +14 -0
- package/dist/audio/music.d.ts +113 -0
- package/dist/audio/music.js +548 -0
- package/dist/audio/occlusion.d.ts +55 -0
- package/dist/audio/occlusion.js +61 -0
- package/dist/audio/persist.d.ts +23 -0
- package/dist/audio/persist.js +27 -0
- package/dist/audio/recipes.d.ts +55 -0
- package/dist/audio/recipes.js +227 -0
- package/dist/audio/send.d.ts +41 -0
- package/dist/audio/send.js +118 -0
- package/dist/audio/sprites.d.ts +59 -0
- package/dist/audio/sprites.js +43 -0
- package/dist/audio/synth.d.ts +103 -0
- package/dist/audio/synth.js +197 -0
- package/dist/audio/variations.d.ts +25 -0
- package/dist/audio/variations.js +55 -0
- package/dist/audio/zones.d.ts +100 -0
- package/dist/audio/zones.js +167 -0
- package/dist/core/detached-surface.d.ts +44 -0
- package/dist/core/detached-surface.js +104 -0
- package/dist/core/events.d.ts +24 -0
- package/dist/core/events.js +43 -0
- package/dist/core/game.d.ts +409 -0
- package/dist/core/game.js +530 -0
- package/dist/core/hash.d.ts +24 -0
- package/dist/core/hash.js +49 -0
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.js +9 -0
- package/dist/core/loop.d.ts +113 -0
- package/dist/core/loop.js +185 -0
- package/dist/core/math.d.ts +58 -0
- package/dist/core/math.js +210 -0
- package/dist/core/noise.d.ts +40 -0
- package/dist/core/noise.js +247 -0
- package/dist/core/pool.d.ts +42 -0
- package/dist/core/pool.js +85 -0
- package/dist/core/random.d.ts +61 -0
- package/dist/core/random.js +199 -0
- package/dist/core/scene.d.ts +79 -0
- package/dist/core/scene.js +195 -0
- package/dist/core/timer.d.ts +66 -0
- package/dist/core/timer.js +286 -0
- package/dist/fx/billboard-wgsl.d.ts +29 -0
- package/dist/fx/billboard-wgsl.js +158 -0
- package/dist/fx/billboard.d.ts +249 -0
- package/dist/fx/billboard.js +702 -0
- package/dist/fx/debug-draw.d.ts +127 -0
- package/dist/fx/debug-draw.js +523 -0
- package/dist/fx/debug-wgsl.d.ts +7 -0
- package/dist/fx/debug-wgsl.js +32 -0
- package/dist/fx/decals-wgsl.d.ts +15 -0
- package/dist/fx/decals-wgsl.js +173 -0
- package/dist/fx/decals.d.ts +216 -0
- package/dist/fx/decals.js +607 -0
- package/dist/fx/effect.d.ts +129 -0
- package/dist/fx/effect.js +349 -0
- package/dist/fx/effects/hit-spark.json +48 -0
- package/dist/fx/effects/index.d.ts +8 -0
- package/dist/fx/effects/index.js +9 -0
- package/dist/fx/effects/magic-aura.json +47 -0
- package/dist/fx/effects/smoke-puff.json +34 -0
- package/dist/fx/emit-surface.d.ts +40 -0
- package/dist/fx/emit-surface.js +124 -0
- package/dist/fx/flicker.d.ts +30 -0
- package/dist/fx/flicker.js +42 -0
- package/dist/fx/index.d.ts +31 -0
- package/dist/fx/index.js +20 -0
- package/dist/fx/particles-wgsl.d.ts +57 -0
- package/dist/fx/particles-wgsl.js +828 -0
- package/dist/fx/particles.d.ts +566 -0
- package/dist/fx/particles.js +1533 -0
- package/dist/fx/random.d.ts +15 -0
- package/dist/fx/random.js +20 -0
- package/dist/fx/sky-wgsl.d.ts +23 -0
- package/dist/fx/sky-wgsl.js +127 -0
- package/dist/fx/sky.d.ts +96 -0
- package/dist/fx/sky.js +175 -0
- package/dist/fx/text-atlas.d.ts +143 -0
- package/dist/fx/text-atlas.js +327 -0
- package/dist/fx/trail-wgsl.d.ts +11 -0
- package/dist/fx/trail-wgsl.js +42 -0
- package/dist/fx/trail.d.ts +194 -0
- package/dist/fx/trail.js +555 -0
- package/dist/fx/water-wgsl.d.ts +34 -0
- package/dist/fx/water-wgsl.js +197 -0
- package/dist/fx/water.d.ts +176 -0
- package/dist/fx/water.js +371 -0
- package/dist/geom/collide/bvh.d.ts +151 -0
- package/dist/geom/collide/bvh.js +493 -0
- package/dist/geom/collide/debug.d.ts +14 -0
- package/dist/geom/collide/debug.js +74 -0
- package/dist/geom/collide/grid.d.ts +26 -0
- package/dist/geom/collide/grid.js +91 -0
- package/dist/geom/collide/index.d.ts +8 -0
- package/dist/geom/collide/index.js +8 -0
- package/dist/geom/collide/queries.d.ts +70 -0
- package/dist/geom/collide/queries.js +583 -0
- package/dist/geom/collide/serialize.d.ts +14 -0
- package/dist/geom/collide/serialize.js +145 -0
- package/dist/geom/collide/shapes.d.ts +161 -0
- package/dist/geom/collide/shapes.js +686 -0
- package/dist/geom/collide/slide.d.ts +66 -0
- package/dist/geom/collide/slide.js +375 -0
- package/dist/geom/collide/tile-slide.d.ts +88 -0
- package/dist/geom/collide/tile-slide.js +255 -0
- package/dist/geom/geometry.d.ts +95 -0
- package/dist/geom/geometry.js +322 -0
- package/dist/geom/heightfield.d.ts +72 -0
- package/dist/geom/heightfield.js +295 -0
- package/dist/geom/hull.d.ts +27 -0
- package/dist/geom/hull.js +279 -0
- package/dist/geom/index.d.ts +35 -0
- package/dist/geom/index.js +23 -0
- package/dist/geom/iso.d.ts +74 -0
- package/dist/geom/iso.js +89 -0
- package/dist/geom/lod.d.ts +29 -0
- package/dist/geom/lod.js +27 -0
- package/dist/geom/ops.d.ts +47 -0
- package/dist/geom/ops.js +285 -0
- package/dist/geom/primitives.d.ts +97 -0
- package/dist/geom/primitives.js +359 -0
- package/dist/geom/shapes.d.ts +43 -0
- package/dist/geom/shapes.js +88 -0
- package/dist/geom/simplify.d.ts +38 -0
- package/dist/geom/simplify.js +519 -0
- package/dist/geom/split.d.ts +37 -0
- package/dist/geom/split.js +413 -0
- package/dist/geom/sweep.d.ts +83 -0
- package/dist/geom/sweep.js +534 -0
- package/dist/geom/tangents.d.ts +16 -0
- package/dist/geom/tangents.js +124 -0
- package/dist/geom/triangulate.d.ts +19 -0
- package/dist/geom/triangulate.js +147 -0
- package/dist/host/default.d.ts +10 -0
- package/dist/host/default.js +10 -0
- package/dist/host/index.d.ts +4 -0
- package/dist/host/index.js +3 -0
- package/dist/host/types.d.ts +144 -0
- package/dist/host/types.js +1 -0
- package/dist/host/web-links.d.ts +38 -0
- package/dist/host/web-links.js +110 -0
- package/dist/host/web.d.ts +30 -0
- package/dist/host/web.js +216 -0
- package/dist/host/xr.d.ts +24 -0
- package/dist/host/xr.js +59 -0
- package/dist/i18n/i18n.d.ts +59 -0
- package/dist/i18n/i18n.js +241 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/message.d.ts +72 -0
- package/dist/i18n/message.js +369 -0
- package/dist/i18n/negotiate.d.ts +17 -0
- package/dist/i18n/negotiate.js +58 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/input/bindings.d.ts +31 -0
- package/dist/input/bindings.js +141 -0
- package/dist/input/clock.d.ts +44 -0
- package/dist/input/clock.js +49 -0
- package/dist/input/follow.d.ts +133 -0
- package/dist/input/follow.js +218 -0
- package/dist/input/gestures.d.ts +281 -0
- package/dist/input/gestures.js +662 -0
- package/dist/input/glyphs.d.ts +35 -0
- package/dist/input/glyphs.js +216 -0
- package/dist/input/gyro.d.ts +85 -0
- package/dist/input/gyro.js +140 -0
- package/dist/input/index.d.ts +19 -0
- package/dist/input/index.js +16 -0
- package/dist/input/input.d.ts +543 -0
- package/dist/input/input.js +1492 -0
- package/dist/input/look.d.ts +327 -0
- package/dist/input/look.js +681 -0
- package/dist/input/magnify.d.ts +177 -0
- package/dist/input/magnify.js +131 -0
- package/dist/input/pointer-dispatch.d.ts +138 -0
- package/dist/input/pointer-dispatch.js +180 -0
- package/dist/input/pointer-router.d.ts +204 -0
- package/dist/input/pointer-router.js +533 -0
- package/dist/input/pointer-sources.d.ts +164 -0
- package/dist/input/pointer-sources.js +306 -0
- package/dist/input/rays.d.ts +138 -0
- package/dist/input/rays.js +615 -0
- package/dist/input/record.d.ts +209 -0
- package/dist/input/record.js +601 -0
- package/dist/input/touch-zones.d.ts +147 -0
- package/dist/input/touch-zones.js +300 -0
- package/dist/input/types.d.ts +158 -0
- package/dist/input/types.js +1 -0
- package/dist/input/xr-source.d.ts +53 -0
- package/dist/input/xr-source.js +164 -0
- package/dist/nav/astar.d.ts +45 -0
- package/dist/nav/astar.js +182 -0
- package/dist/nav/corridor.d.ts +40 -0
- package/dist/nav/corridor.js +95 -0
- package/dist/nav/crowd.d.ts +94 -0
- package/dist/nav/crowd.js +624 -0
- package/dist/nav/flow.d.ts +61 -0
- package/dist/nav/flow.js +193 -0
- package/dist/nav/grid.d.ts +108 -0
- package/dist/nav/grid.js +210 -0
- package/dist/nav/heap.d.ts +22 -0
- package/dist/nav/heap.js +92 -0
- package/dist/nav/index.d.ts +37 -0
- package/dist/nav/index.js +19 -0
- package/dist/nav/mesh/areas.d.ts +44 -0
- package/dist/nav/mesh/areas.js +98 -0
- package/dist/nav/mesh/bake-options.d.ts +33 -0
- package/dist/nav/mesh/bake-options.js +76 -0
- package/dist/nav/mesh/contour.d.ts +22 -0
- package/dist/nav/mesh/contour.js +323 -0
- package/dist/nav/mesh/flow3.d.ts +35 -0
- package/dist/nav/mesh/flow3.js +229 -0
- package/dist/nav/mesh/links.d.ts +38 -0
- package/dist/nav/mesh/links.js +72 -0
- package/dist/nav/mesh/mesh-path.d.ts +152 -0
- package/dist/nav/mesh/mesh-path.js +643 -0
- package/dist/nav/mesh/mesh-reach.d.ts +78 -0
- package/dist/nav/mesh/mesh-reach.js +450 -0
- package/dist/nav/mesh/navmesh.d.ts +117 -0
- package/dist/nav/mesh/navmesh.js +647 -0
- package/dist/nav/mesh/polymesh.d.ts +24 -0
- package/dist/nav/mesh/polymesh.js +384 -0
- package/dist/nav/mesh/regions.d.ts +12 -0
- package/dist/nav/mesh/regions.js +367 -0
- package/dist/nav/mesh/serialize.d.ts +13 -0
- package/dist/nav/mesh/serialize.js +197 -0
- package/dist/nav/mesh/voxelize.d.ts +111 -0
- package/dist/nav/mesh/voxelize.js +552 -0
- package/dist/nav/obstacles.d.ts +75 -0
- package/dist/nav/obstacles.js +294 -0
- package/dist/nav/path.d.ts +59 -0
- package/dist/nav/path.js +177 -0
- package/dist/nav/query-queue.d.ts +46 -0
- package/dist/nav/query-queue.js +308 -0
- package/dist/nav/reach.d.ts +53 -0
- package/dist/nav/reach.js +148 -0
- package/dist/nav/steer.d.ts +36 -0
- package/dist/nav/steer.js +78 -0
- package/dist/platform/boot.d.ts +28 -0
- package/dist/platform/boot.js +43 -0
- package/dist/platform/device-mode.d.ts +40 -0
- package/dist/platform/device-mode.js +104 -0
- package/dist/platform/device.d.ts +31 -0
- package/dist/platform/device.js +91 -0
- package/dist/platform/environment.d.ts +42 -0
- package/dist/platform/environment.js +82 -0
- package/dist/platform/gpu.d.ts +40 -0
- package/dist/platform/gpu.js +57 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/letterbox.d.ts +43 -0
- package/dist/platform/letterbox.js +57 -0
- package/dist/platform/links.d.ts +20 -0
- package/dist/platform/links.js +43 -0
- package/dist/platform/screens.d.ts +36 -0
- package/dist/platform/screens.js +138 -0
- package/dist/platform/surface.d.ts +72 -0
- package/dist/platform/surface.js +157 -0
- package/dist/platform/xr-fake.d.ts +168 -0
- package/dist/platform/xr-fake.js +434 -0
- package/dist/platform/xr-surface.d.ts +120 -0
- package/dist/platform/xr-surface.js +214 -0
- package/dist/platform/xr-types.d.ts +262 -0
- package/dist/post/ao.d.ts +12 -0
- package/dist/post/ao.js +136 -0
- package/dist/post/blend.d.ts +27 -0
- package/dist/post/blend.js +129 -0
- package/dist/post/depth-pass.d.ts +43 -0
- package/dist/post/depth-pass.js +118 -0
- package/dist/post/dof.d.ts +1 -0
- package/dist/post/dof.js +66 -0
- package/dist/post/exposure.d.ts +80 -0
- package/dist/post/exposure.js +322 -0
- package/dist/post/index.d.ts +12 -0
- package/dist/post/index.js +11 -0
- package/dist/post/lens-dirt.d.ts +13 -0
- package/dist/post/lens-dirt.js +91 -0
- package/dist/post/lut.d.ts +19 -0
- package/dist/post/lut.js +50 -0
- package/dist/post/motion-blur.d.ts +9 -0
- package/dist/post/motion-blur.js +78 -0
- package/dist/post/post-stack.d.ts +302 -0
- package/dist/post/post-stack.js +1137 -0
- package/dist/post/settings.d.ts +485 -0
- package/dist/post/settings.js +416 -0
- package/dist/post/shaders.d.ts +25 -0
- package/dist/post/shaders.js +410 -0
- package/dist/post/ssr.d.ts +16 -0
- package/dist/post/ssr.js +155 -0
- package/dist/post/taa.d.ts +74 -0
- package/dist/post/taa.js +235 -0
- package/dist/post/white-balance.d.ts +25 -0
- package/dist/post/white-balance.js +98 -0
- package/dist/render/bindings.d.ts +98 -0
- package/dist/render/bindings.js +281 -0
- package/dist/render/blend.d.ts +13 -0
- package/dist/render/blend.js +26 -0
- package/dist/render/camera-2d.d.ts +72 -0
- package/dist/render/camera-2d.js +92 -0
- package/dist/render/camera.d.ts +302 -0
- package/dist/render/camera.js +671 -0
- package/dist/render/color.d.ts +16 -0
- package/dist/render/color.js +41 -0
- package/dist/render/compressed.d.ts +104 -0
- package/dist/render/compressed.js +248 -0
- package/dist/render/diagnostics.d.ts +15 -0
- package/dist/render/diagnostics.js +43 -0
- package/dist/render/dynamic-resolution.d.ts +70 -0
- package/dist/render/dynamic-resolution.js +126 -0
- package/dist/render/fake-gpu.d.ts +204 -0
- package/dist/render/fake-gpu.js +426 -0
- package/dist/render/flipbook.d.ts +56 -0
- package/dist/render/flipbook.js +87 -0
- package/dist/render/frame.d.ts +278 -0
- package/dist/render/frame.js +174 -0
- package/dist/render/fullscreen.d.ts +54 -0
- package/dist/render/fullscreen.js +91 -0
- package/dist/render/gpu-timer.d.ts +73 -0
- package/dist/render/gpu-timer.js +186 -0
- package/dist/render/index.d.ts +53 -0
- package/dist/render/index.js +29 -0
- package/dist/render/instance-list.d.ts +185 -0
- package/dist/render/instance-list.js +547 -0
- package/dist/render/lights.d.ts +181 -0
- package/dist/render/lights.js +233 -0
- package/dist/render/lod.d.ts +54 -0
- package/dist/render/lod.js +52 -0
- package/dist/render/material.d.ts +165 -0
- package/dist/render/material.js +292 -0
- package/dist/render/mesh.d.ts +284 -0
- package/dist/render/mesh.js +472 -0
- package/dist/render/mipmap.d.ts +16 -0
- package/dist/render/mipmap.js +121 -0
- package/dist/render/parallax.d.ts +50 -0
- package/dist/render/parallax.js +47 -0
- package/dist/render/pbr-wgsl.d.ts +31 -0
- package/dist/render/pbr-wgsl.js +119 -0
- package/dist/render/ping-pong.d.ts +42 -0
- package/dist/render/ping-pong.js +74 -0
- package/dist/render/renderer.d.ts +741 -0
- package/dist/render/renderer.js +2486 -0
- package/dist/render/scene-pipelines.d.ts +44 -0
- package/dist/render/scene-pipelines.js +92 -0
- package/dist/render/scene-target.d.ts +170 -0
- package/dist/render/scene-target.js +450 -0
- package/dist/render/shadow.d.ts +74 -0
- package/dist/render/shadow.js +208 -0
- package/dist/render/skin.d.ts +112 -0
- package/dist/render/skin.js +240 -0
- package/dist/render/snapshot.d.ts +36 -0
- package/dist/render/snapshot.js +34 -0
- package/dist/render/standard.d.ts +162 -0
- package/dist/render/standard.js +263 -0
- package/dist/render/texture.d.ts +142 -0
- package/dist/render/texture.js +228 -0
- package/dist/render/tile-layer.d.ts +110 -0
- package/dist/render/tile-layer.js +304 -0
- package/dist/render/transform.d.ts +115 -0
- package/dist/render/transform.js +318 -0
- package/dist/render/wgsl.d.ts +131 -0
- package/dist/render/wgsl.js +528 -0
- package/dist/save/codec.d.ts +49 -0
- package/dist/save/codec.js +169 -0
- package/dist/save/index.d.ts +8 -0
- package/dist/save/index.js +8 -0
- package/dist/save/journal.d.ts +24 -0
- package/dist/save/journal.js +102 -0
- package/dist/save/migrate.d.ts +15 -0
- package/dist/save/migrate.js +37 -0
- package/dist/save/schema.d.ts +72 -0
- package/dist/save/schema.js +154 -0
- package/dist/save/settings.d.ts +28 -0
- package/dist/save/settings.js +59 -0
- package/dist/save/slots.d.ts +56 -0
- package/dist/save/slots.js +200 -0
- package/dist/save/storage.d.ts +35 -0
- package/dist/save/storage.js +62 -0
- package/dist/save/store.d.ts +114 -0
- package/dist/save/store.js +269 -0
- package/dist/testing/fake-host.d.ts +103 -0
- package/dist/testing/fake-host.js +163 -0
- package/dist/testing/fixed-clock.d.ts +25 -0
- package/dist/testing/fixed-clock.js +30 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/test-game.d.ts +76 -0
- package/dist/testing/test-game.js +92 -0
- package/dist/tween/ease.d.ts +77 -0
- package/dist/tween/ease.js +192 -0
- package/dist/tween/index.d.ts +8 -0
- package/dist/tween/index.js +7 -0
- package/dist/tween/timeline.d.ts +78 -0
- package/dist/tween/timeline.js +269 -0
- package/dist/tween/tween.d.ts +168 -0
- package/dist/tween/tween.js +320 -0
- package/dist/ui/anchor.d.ts +206 -0
- package/dist/ui/anchor.js +307 -0
- package/dist/ui/caption.d.ts +122 -0
- package/dist/ui/caption.js +286 -0
- package/dist/ui/cursor.d.ts +105 -0
- package/dist/ui/cursor.js +261 -0
- package/dist/ui/dom.d.ts +30 -0
- package/dist/ui/dom.js +92 -0
- package/dist/ui/floats.d.ts +86 -0
- package/dist/ui/floats.js +260 -0
- package/dist/ui/hud.d.ts +198 -0
- package/dist/ui/hud.js +431 -0
- package/dist/ui/index.d.ts +37 -0
- package/dist/ui/index.js +34 -0
- package/dist/ui/inventory-card.d.ts +52 -0
- package/dist/ui/inventory-card.js +173 -0
- package/dist/ui/inventory-context.d.ts +29 -0
- package/dist/ui/inventory-context.js +125 -0
- package/dist/ui/inventory-drag.d.ts +63 -0
- package/dist/ui/inventory-drag.js +394 -0
- package/dist/ui/inventory-grid.d.ts +66 -0
- package/dist/ui/inventory-grid.js +625 -0
- package/dist/ui/inventory-radial.d.ts +39 -0
- package/dist/ui/inventory-radial.js +168 -0
- package/dist/ui/inventory.d.ts +128 -0
- package/dist/ui/inventory.js +154 -0
- package/dist/ui/layout.d.ts +356 -0
- package/dist/ui/layout.js +856 -0
- package/dist/ui/link.d.ts +64 -0
- package/dist/ui/link.js +155 -0
- package/dist/ui/loading.d.ts +40 -0
- package/dist/ui/loading.js +157 -0
- package/dist/ui/loupe.d.ts +74 -0
- package/dist/ui/loupe.js +164 -0
- package/dist/ui/menu-nav.d.ts +33 -0
- package/dist/ui/menu-nav.js +28 -0
- package/dist/ui/minimap-canvas.d.ts +145 -0
- package/dist/ui/minimap-canvas.js +460 -0
- package/dist/ui/notify.d.ts +40 -0
- package/dist/ui/notify.js +141 -0
- package/dist/ui/orb.d.ts +53 -0
- package/dist/ui/orb.js +304 -0
- package/dist/ui/overlay.d.ts +213 -0
- package/dist/ui/overlay.js +394 -0
- package/dist/ui/padnav.d.ts +53 -0
- package/dist/ui/padnav.js +146 -0
- package/dist/ui/perf.d.ts +130 -0
- package/dist/ui/perf.js +329 -0
- package/dist/ui/rotate-card.d.ts +54 -0
- package/dist/ui/rotate-card.js +97 -0
- package/dist/ui/stack.d.ts +128 -0
- package/dist/ui/stack.js +312 -0
- package/dist/ui/styles.d.ts +13 -0
- package/dist/ui/styles.js +200 -0
- package/dist/ui/text-scale.d.ts +67 -0
- package/dist/ui/text-scale.js +102 -0
- package/dist/ui/theme.d.ts +70 -0
- package/dist/ui/theme.js +98 -0
- package/dist/ui/toast.d.ts +23 -0
- package/dist/ui/toast.js +46 -0
- package/dist/ui/tooltip.d.ts +89 -0
- package/dist/ui/tooltip.js +333 -0
- package/dist/ui/widgets-2.d.ts +134 -0
- package/dist/ui/widgets-2.js +399 -0
- package/dist/ui/widgets-3.d.ts +91 -0
- package/dist/ui/widgets-3.js +212 -0
- package/dist/ui/widgets.d.ts +34 -0
- package/dist/ui/widgets.js +50 -0
- package/dist/ui/world-panel/index.d.ts +5 -0
- package/dist/ui/world-panel/index.js +5 -0
- package/dist/ui/world-panel/layout.d.ts +38 -0
- package/dist/ui/world-panel/layout.js +68 -0
- package/dist/ui/world-panel/paint.d.ts +96 -0
- package/dist/ui/world-panel/paint.js +136 -0
- package/dist/ui/world-panel/panel.d.ts +235 -0
- package/dist/ui/world-panel/panel.js +762 -0
- package/dist/ui/world-panel/wgsl.d.ts +10 -0
- package/dist/ui/world-panel/wgsl.js +52 -0
- package/dist/ui/world-panel/widgets.d.ts +207 -0
- package/dist/ui/world-panel/widgets.js +569 -0
- package/dist/voxel/chunks.d.ts +77 -0
- package/dist/voxel/chunks.js +149 -0
- package/dist/voxel/grid.d.ts +84 -0
- package/dist/voxel/grid.js +223 -0
- package/dist/voxel/index.d.ts +22 -0
- package/dist/voxel/index.js +7 -0
- package/dist/voxel/mesher-worker.d.ts +14 -0
- package/dist/voxel/mesher-worker.js +47 -0
- package/dist/voxel/mesher.d.ts +73 -0
- package/dist/voxel/mesher.js +306 -0
- package/dist/voxel/ray.d.ts +32 -0
- package/dist/voxel/ray.js +73 -0
- package/dist/voxel/wgsl.d.ts +16 -0
- package/dist/voxel/wgsl.js +28 -0
- package/dist/voxel/worker-client.d.ts +79 -0
- package/dist/voxel/worker-client.js +122 -0
- package/package.json +177 -3
package/dist/fx/water.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { plane } from '../geom/index.js';
|
|
2
|
+
import { VERTEX_LAYOUT_3D } from '../render/mesh.js';
|
|
3
|
+
import { auxSuffix, ScenePipelineCache, sceneVariant } from '../render/scene-pipelines.js';
|
|
4
|
+
import { createShaderModule } from '../render/wgsl.js';
|
|
5
|
+
import { WATER_DEPTH_COPY_WGSL, WATER_MAX_WAVES, WATER_WGSL } from './water-wgsl.js';
|
|
6
|
+
/** Floats in the water's params block: 5 vec4 + `WATER_MAX_WAVES` vec4 (144 bytes). */
|
|
7
|
+
export const WATER_PARAMS_FLOATS = 20 + WATER_MAX_WAVES * 4;
|
|
8
|
+
const DEPTH_COPY_FORMAT = 'depth32float';
|
|
9
|
+
const DEFAULT_SHALLOW = [0.1, 0.45, 0.45];
|
|
10
|
+
const DEFAULT_DEEP = [0.01, 0.07, 0.14];
|
|
11
|
+
const DEFAULT_FOAM_COLOR = [0.9, 0.95, 0.97];
|
|
12
|
+
const DEFAULT_WAVES = () => [
|
|
13
|
+
{ scale: 0.35, speed: 0.6, amplitude: 0.25, direction: [1, 0.3] },
|
|
14
|
+
{ scale: 0.9, speed: 0.9, amplitude: 0.12, direction: [-0.4, 1] },
|
|
15
|
+
];
|
|
16
|
+
const PREMULTIPLIED = {
|
|
17
|
+
color: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' },
|
|
18
|
+
alpha: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' },
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* An animated water surface: a plane from `geom`'s `plane` whose shader sums scrolling
|
|
22
|
+
* analytic wave layers for the normal (and the height when `displace` > 0), lerps a depth-tinted
|
|
23
|
+
* refraction colour towards a sky reflection by Fresnel, adds the sun's GGX highlight (also to
|
|
24
|
+
* the emissive target), fades to transparent at the shoreline and foams where the water is
|
|
25
|
+
* shallower than `foam.width`. `frame.drawable(water, order)` draws it after opaque geometry
|
|
26
|
+
* (drawables sort as blended); `update(dt)` advances the waves.
|
|
27
|
+
*
|
|
28
|
+
* Every field is live; `prepare` packs them into one `WATER_PARAMS_FLOATS` params block per
|
|
29
|
+
* frame. The sun, its colour and the fog colour (the horizon of the reflection) come from
|
|
30
|
+
* `frame.lights`; `Sky` present or not.
|
|
31
|
+
*
|
|
32
|
+
* Depth: under a depth camera the water tests and writes depth (`less-equal`), so particles and
|
|
33
|
+
* trails sort against it, and `prepare` copies the scene depth (`depthTarget ?? renderer.target`,
|
|
34
|
+
* its `SceneTarget.depth`) into its own `depth32float` texture for the depth fade, the shoreline
|
|
35
|
+
* alpha and the foam. The copy runs before this frame's scene pass, so it holds what the target
|
|
36
|
+
* held then: the previous frame's depth (which includes this water's own surface, read as "no
|
|
37
|
+
* information": deep, no foam) or that of an earlier `renderer.render` call this frame. For a
|
|
38
|
+
* shoreline, draw the water on its own layer in a second view of the same camera, after the
|
|
39
|
+
* opaque view (`harness/water.ts` does). Without a depth camera there is no copy: the surface is
|
|
40
|
+
* deep everywhere, foam off, and the pipeline has no depth state.
|
|
41
|
+
*/
|
|
42
|
+
export class Water {
|
|
43
|
+
/** Surface height (y) above `origin`. Live. */
|
|
44
|
+
level;
|
|
45
|
+
/** World position of the plane's centre (`WaterOptions.origin`). Fixed. */
|
|
46
|
+
origin = new Float32Array(3);
|
|
47
|
+
/** Linear RGB where the water is shallow. Live. */
|
|
48
|
+
shallowColor = new Float32Array(3);
|
|
49
|
+
/** Linear RGB at full depth. Live. */
|
|
50
|
+
deepColor = new Float32Array(3);
|
|
51
|
+
/** World units of water depth to full `deepColor`. Live. */
|
|
52
|
+
depthFade;
|
|
53
|
+
/** Reflection strength, 0..1. Live. */
|
|
54
|
+
fresnel;
|
|
55
|
+
/** Roughness of the sun highlight. Live. */
|
|
56
|
+
roughness;
|
|
57
|
+
/** Wave layers; the first `WATER_MAX_WAVES` are uploaded. Live (replace or mutate). */
|
|
58
|
+
waves;
|
|
59
|
+
/** Foam settings, or null for none. Live (replace or mutate). */
|
|
60
|
+
foam;
|
|
61
|
+
/** Vertex height amplitude. Live. */
|
|
62
|
+
displace;
|
|
63
|
+
/** Alpha away from the shoreline. Live. */
|
|
64
|
+
opacity;
|
|
65
|
+
/** Where the scene depth is copied from; null for `renderer.target`. Live. */
|
|
66
|
+
depthTarget;
|
|
67
|
+
/** See `WaterOptions.readsDepth`. Live. */
|
|
68
|
+
readsDepth;
|
|
69
|
+
/** Seconds `update` has advanced; the waves' clock. */
|
|
70
|
+
time = 0;
|
|
71
|
+
/** The plane, owned; drawn through this drawable's own pipeline. */
|
|
72
|
+
mesh;
|
|
73
|
+
renderer;
|
|
74
|
+
device;
|
|
75
|
+
params;
|
|
76
|
+
paramsBuffer;
|
|
77
|
+
layout;
|
|
78
|
+
dummy;
|
|
79
|
+
dummyGroup;
|
|
80
|
+
desc;
|
|
81
|
+
/**
|
|
82
|
+
* Pipelines per depth format (null: none; a depth one writes depth) × the view target's aux
|
|
83
|
+
* key, built on first use from `renderer.sceneTargets` (ws/render-10).
|
|
84
|
+
*/
|
|
85
|
+
pipelines = new ScenePipelineCache();
|
|
86
|
+
copyLayout;
|
|
87
|
+
copyPipeline;
|
|
88
|
+
copyAtt;
|
|
89
|
+
copyPass;
|
|
90
|
+
copy = null;
|
|
91
|
+
copyGroup = null;
|
|
92
|
+
src = null;
|
|
93
|
+
srcGroup = null;
|
|
94
|
+
/** The depth copy ran this frame (`draw` binds it and the shader reads it). */
|
|
95
|
+
depthOn = false;
|
|
96
|
+
/** The renderer's `depthCopy` view the hook group was made for (`readsDepth`). */
|
|
97
|
+
hookView = null;
|
|
98
|
+
hookGroup = null;
|
|
99
|
+
/** The group `draw` binds: own copy, the renderer's copy, or the 1×1 stand-in. */
|
|
100
|
+
depthGroup = null;
|
|
101
|
+
constructor(renderer, opts = {}) {
|
|
102
|
+
const device = renderer.device;
|
|
103
|
+
this.renderer = renderer;
|
|
104
|
+
this.device = device;
|
|
105
|
+
this.level = opts.level ?? 0;
|
|
106
|
+
set3(this.shallowColor, opts.shallowColor ?? DEFAULT_SHALLOW);
|
|
107
|
+
set3(this.deepColor, opts.deepColor ?? DEFAULT_DEEP);
|
|
108
|
+
this.depthFade = opts.depthFade ?? 4;
|
|
109
|
+
this.fresnel = opts.fresnel ?? 0.6;
|
|
110
|
+
this.roughness = opts.roughness ?? 0.08;
|
|
111
|
+
this.waves = opts.waves ?? DEFAULT_WAVES();
|
|
112
|
+
const foam = opts.foam;
|
|
113
|
+
this.foam =
|
|
114
|
+
foam === null
|
|
115
|
+
? null
|
|
116
|
+
: { width: foam?.width ?? 0.4, color: foam?.color ?? DEFAULT_FOAM_COLOR };
|
|
117
|
+
this.displace = opts.displace ?? 0;
|
|
118
|
+
this.opacity = opts.opacity ?? 0.85;
|
|
119
|
+
this.depthTarget = opts.depthTarget ?? null;
|
|
120
|
+
this.readsDepth = opts.readsDepth ?? false;
|
|
121
|
+
if (opts.origin)
|
|
122
|
+
set3(this.origin, opts.origin);
|
|
123
|
+
const geometry = plane({ size: opts.size ?? 100, segments: opts.segments ?? 1 });
|
|
124
|
+
const ox = this.origin[0];
|
|
125
|
+
const oz = this.origin[2];
|
|
126
|
+
if (ox !== 0 || oz !== 0) {
|
|
127
|
+
const v = geometry.vertices;
|
|
128
|
+
const stride = geometry.layout.floats;
|
|
129
|
+
for (let i = 0; i < v.length; i += stride) {
|
|
130
|
+
v[i] = v[i] + ox;
|
|
131
|
+
v[i + 2] = v[i + 2] + oz;
|
|
132
|
+
}
|
|
133
|
+
geometry.bounds.center[0] += ox;
|
|
134
|
+
geometry.bounds.center[2] += oz;
|
|
135
|
+
}
|
|
136
|
+
this.mesh = renderer.createMesh({ ...geometry, label: 'water' });
|
|
137
|
+
this.params = new Float32Array(WATER_PARAMS_FLOATS);
|
|
138
|
+
this.paramsBuffer = device.createBuffer({
|
|
139
|
+
label: 'water-params',
|
|
140
|
+
size: this.params.byteLength,
|
|
141
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
|
|
142
|
+
});
|
|
143
|
+
this.layout = device.createBindGroupLayout({
|
|
144
|
+
label: 'water-layout',
|
|
145
|
+
entries: [
|
|
146
|
+
{ binding: 0, visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT, buffer: {} },
|
|
147
|
+
{ binding: 1, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: 'depth' } },
|
|
148
|
+
],
|
|
149
|
+
});
|
|
150
|
+
this.dummy = device.createTexture({
|
|
151
|
+
label: 'water-depth-none',
|
|
152
|
+
size: [1, 1],
|
|
153
|
+
format: DEPTH_COPY_FORMAT,
|
|
154
|
+
usage: GPUTextureUsage.TEXTURE_BINDING,
|
|
155
|
+
});
|
|
156
|
+
this.dummyGroup = this.makeGroup('water', this.dummy.createView());
|
|
157
|
+
const module = createShaderModule(device, WATER_WGSL, 'water');
|
|
158
|
+
this.desc = {
|
|
159
|
+
label: 'water',
|
|
160
|
+
layout: device.createPipelineLayout({
|
|
161
|
+
bindGroupLayouts: [renderer.globalsLayout, this.layout],
|
|
162
|
+
}),
|
|
163
|
+
vertex: { module, entryPoint: 'vs', buffers: [VERTEX_LAYOUT_3D.buffer] },
|
|
164
|
+
fragment: {
|
|
165
|
+
module,
|
|
166
|
+
entryPoint: 'fs',
|
|
167
|
+
targets: renderer.sceneTargets(PREMULTIPLIED),
|
|
168
|
+
},
|
|
169
|
+
primitive: { topology: 'triangle-list', cullMode: 'none' },
|
|
170
|
+
};
|
|
171
|
+
this.pipelines.set(null, renderer.target.auxKey, device.createRenderPipeline(this.desc));
|
|
172
|
+
this.copyLayout = device.createBindGroupLayout({
|
|
173
|
+
label: 'water-depth-copy-layout',
|
|
174
|
+
entries: [
|
|
175
|
+
{ binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: { sampleType: 'depth' } },
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
const copyModule = createShaderModule(device, WATER_DEPTH_COPY_WGSL, 'water-depth-copy');
|
|
179
|
+
this.copyPipeline = device.createRenderPipeline({
|
|
180
|
+
label: 'water-depth-copy',
|
|
181
|
+
layout: device.createPipelineLayout({ bindGroupLayouts: [this.copyLayout] }),
|
|
182
|
+
vertex: { module: copyModule, entryPoint: 'vs' },
|
|
183
|
+
fragment: { module: copyModule, entryPoint: 'fs', targets: [] },
|
|
184
|
+
primitive: { topology: 'triangle-list' },
|
|
185
|
+
depthStencil: { format: DEPTH_COPY_FORMAT, depthWriteEnabled: true, depthCompare: 'always' },
|
|
186
|
+
});
|
|
187
|
+
this.copyAtt = {
|
|
188
|
+
view: undefined,
|
|
189
|
+
depthClearValue: 1,
|
|
190
|
+
depthLoadOp: 'clear',
|
|
191
|
+
depthStoreOp: 'store',
|
|
192
|
+
};
|
|
193
|
+
this.copyPass = {
|
|
194
|
+
label: 'water-depth-copy',
|
|
195
|
+
colorAttachments: [],
|
|
196
|
+
depthStencilAttachment: this.copyAtt,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** Advance the waves' clock. */
|
|
200
|
+
update(dt) {
|
|
201
|
+
this.time += dt;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Copy the scene depth (under a depth camera) and pack the live fields into the params block
|
|
205
|
+
* (`WATER_PARAMS_FLOATS` floats: shallow rgb + opacity, deep rgb + depthFade, fresnel,
|
|
206
|
+
* roughness, displace, level, foam rgb + width, time, wave count, depth copy on, 0, then
|
|
207
|
+
* scale, speed, amplitude, direction angle per wave). Called by the renderer once per frame.
|
|
208
|
+
* No allocation in steady state.
|
|
209
|
+
*/
|
|
210
|
+
prepare(encoder, frame) {
|
|
211
|
+
// With `readsDepth` the renderer's hook (`afterOpaque`) supplies this frame's depth.
|
|
212
|
+
this.depthOn = this.readsDepth ? false : this.copyDepth(encoder, frame);
|
|
213
|
+
this.depthGroup = this.depthOn ? this.copyGroup : null;
|
|
214
|
+
const p = this.params;
|
|
215
|
+
p[0] = this.shallowColor[0];
|
|
216
|
+
p[1] = this.shallowColor[1];
|
|
217
|
+
p[2] = this.shallowColor[2];
|
|
218
|
+
p[3] = this.opacity;
|
|
219
|
+
p[4] = this.deepColor[0];
|
|
220
|
+
p[5] = this.deepColor[1];
|
|
221
|
+
p[6] = this.deepColor[2];
|
|
222
|
+
p[7] = this.depthFade;
|
|
223
|
+
p[8] = this.fresnel;
|
|
224
|
+
p[9] = this.roughness;
|
|
225
|
+
p[10] = this.displace;
|
|
226
|
+
p[11] = this.level;
|
|
227
|
+
const foam = this.foam;
|
|
228
|
+
p[12] = foam ? (foam.color[0] ?? 0) : 0;
|
|
229
|
+
p[13] = foam ? (foam.color[1] ?? 0) : 0;
|
|
230
|
+
p[14] = foam ? (foam.color[2] ?? 0) : 0;
|
|
231
|
+
p[15] = foam ? foam.width : 0;
|
|
232
|
+
const count = Math.min(this.waves.length, WATER_MAX_WAVES);
|
|
233
|
+
p[16] = this.time;
|
|
234
|
+
p[17] = count;
|
|
235
|
+
p[18] = this.depthOn ? 1 : 0;
|
|
236
|
+
p[19] = this.origin[1];
|
|
237
|
+
for (let i = 0; i < WATER_MAX_WAVES; i++) {
|
|
238
|
+
const o = 20 + i * 4;
|
|
239
|
+
const w = i < count ? this.waves[i] : null;
|
|
240
|
+
p[o] = w ? w.scale : 0;
|
|
241
|
+
p[o + 1] = w ? w.speed : 0;
|
|
242
|
+
p[o + 2] = w ? w.amplitude : 0;
|
|
243
|
+
p[o + 3] = w ? Math.atan2(w.direction[1], w.direction[0]) : 0;
|
|
244
|
+
}
|
|
245
|
+
this.device.queue.writeBuffer(this.paramsBuffer, 0, p);
|
|
246
|
+
}
|
|
247
|
+
/** Draw inside the scene pass: the plane, a depth-writing pipeline when the frame has depth. */
|
|
248
|
+
draw(pass, frame) {
|
|
249
|
+
const mesh = this.mesh;
|
|
250
|
+
if (mesh.indexCount <= 0)
|
|
251
|
+
return;
|
|
252
|
+
const fmt = frame?.depthFormat ?? null;
|
|
253
|
+
pass.setPipeline(this.pipelineFor(fmt, frame ? frame.auxKey : this.renderer.target.auxKey));
|
|
254
|
+
pass.setBindGroup(1, this.depthGroup ?? this.dummyGroup);
|
|
255
|
+
pass.setVertexBuffer(0, mesh.vertexBuffer);
|
|
256
|
+
pass.setIndexBuffer(mesh.indexBuffer, mesh.indexFormat);
|
|
257
|
+
pass.drawIndexed(mesh.indexCount);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The renderer's depth hook (`readsDepth`): bind this frame's opaque depth copy and flip the
|
|
261
|
+
* shader's depth flag on (a 4-byte write; `queue.writeBuffer` lands before the frame's
|
|
262
|
+
* commands run). A new bind group only when the copy texture changed (resize).
|
|
263
|
+
*/
|
|
264
|
+
afterOpaque(_encoder, view) {
|
|
265
|
+
if (view.depthView !== this.hookView) {
|
|
266
|
+
this.hookView = view.depthView;
|
|
267
|
+
this.hookGroup = this.makeGroup('water-hook', view.depthView);
|
|
268
|
+
}
|
|
269
|
+
this.depthOn = true;
|
|
270
|
+
this.depthGroup = this.hookGroup;
|
|
271
|
+
const p = this.params;
|
|
272
|
+
p[18] = 1;
|
|
273
|
+
this.device.queue.writeBuffer(this.paramsBuffer, 18 * 4, p.buffer, 18 * 4, 4);
|
|
274
|
+
}
|
|
275
|
+
copyDepth(encoder, frame) {
|
|
276
|
+
if (!frame?.depthFormat)
|
|
277
|
+
return false;
|
|
278
|
+
const src = (this.depthTarget ?? this.renderer.target).depth;
|
|
279
|
+
if (!src)
|
|
280
|
+
return false;
|
|
281
|
+
const device = this.device;
|
|
282
|
+
if (!this.copy || this.copy.width !== src.width || this.copy.height !== src.height) {
|
|
283
|
+
this.copy?.destroy();
|
|
284
|
+
this.copy = device.createTexture({
|
|
285
|
+
label: 'water-depth',
|
|
286
|
+
size: [src.width, src.height],
|
|
287
|
+
format: DEPTH_COPY_FORMAT,
|
|
288
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING,
|
|
289
|
+
});
|
|
290
|
+
const view = this.copy.createView();
|
|
291
|
+
this.copyAtt.view = view;
|
|
292
|
+
this.copyGroup = this.makeGroup('water-soft', view);
|
|
293
|
+
}
|
|
294
|
+
if (this.src !== src) {
|
|
295
|
+
this.src = src;
|
|
296
|
+
this.srcGroup = device.createBindGroup({
|
|
297
|
+
label: 'water-depth-copy',
|
|
298
|
+
layout: this.copyLayout,
|
|
299
|
+
entries: [{ binding: 0, resource: src.view }],
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
const pass = encoder.beginRenderPass(this.copyPass);
|
|
303
|
+
pass.setPipeline(this.copyPipeline);
|
|
304
|
+
pass.setBindGroup(0, this.srcGroup);
|
|
305
|
+
pass.draw(3);
|
|
306
|
+
pass.end();
|
|
307
|
+
return true;
|
|
308
|
+
}
|
|
309
|
+
makeGroup(label, depth) {
|
|
310
|
+
return this.device.createBindGroup({
|
|
311
|
+
label,
|
|
312
|
+
layout: this.layout,
|
|
313
|
+
entries: [
|
|
314
|
+
{ binding: 0, resource: { buffer: this.paramsBuffer } },
|
|
315
|
+
{ binding: 1, resource: depth },
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
pipelineFor(format, aux) {
|
|
320
|
+
const p = this.pipelines.get(format, aux);
|
|
321
|
+
if (p)
|
|
322
|
+
return p;
|
|
323
|
+
return this.pipelines.set(format, aux, this.device.createRenderPipeline(sceneVariant(this.desc, this.renderer.sceneTargets(PREMULTIPLIED, aux), `water${format ? `:${format}` : ''}${auxSuffix(aux)}`, format ? { format, depthWriteEnabled: true, depthCompare: 'less-equal' } : undefined)));
|
|
324
|
+
}
|
|
325
|
+
destroy() {
|
|
326
|
+
this.paramsBuffer.destroy();
|
|
327
|
+
this.dummy.destroy();
|
|
328
|
+
this.copy?.destroy();
|
|
329
|
+
this.copy = null;
|
|
330
|
+
this.mesh.destroy();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* One wave layer's value and gradient at field point (`px`, `py`): the shader's `water_wave`.
|
|
335
|
+
* Writes `[value, d/dx, d/dy]` into `out`.
|
|
336
|
+
*/
|
|
337
|
+
function wave(px, py, out) {
|
|
338
|
+
const a = px + 0.6 * Math.sin(1.3 * py);
|
|
339
|
+
const b = 0.8 * py + 0.5 * Math.sin(0.9 * px);
|
|
340
|
+
const sa = Math.sin(a);
|
|
341
|
+
const ca = Math.cos(a);
|
|
342
|
+
const sb = Math.sin(b);
|
|
343
|
+
const cb = Math.cos(b);
|
|
344
|
+
out[0] = sa * cb;
|
|
345
|
+
out[1] = ca * cb - sa * sb * 0.45 * Math.cos(0.9 * px);
|
|
346
|
+
out[2] = ca * cb * 0.78 * Math.cos(1.3 * py) - sa * sb * 0.8;
|
|
347
|
+
}
|
|
348
|
+
const waveOut = [0, 0, 0];
|
|
349
|
+
/**
|
|
350
|
+
* The surface height at world (`x`, `z`) at time `t` (default `water.time`): the origin's y
|
|
351
|
+
* plus `level` plus `displace` times the summed wave layers, the formula the vertex shader
|
|
352
|
+
* runs. Pure; no allocation. With `displace` 0 it is `origin[1] + level`.
|
|
353
|
+
*/
|
|
354
|
+
export function waterHeight(water, x, z, t = water.time) {
|
|
355
|
+
let h = 0;
|
|
356
|
+
const n = Math.min(water.waves.length, WATER_MAX_WAVES);
|
|
357
|
+
for (let i = 0; i < n; i++) {
|
|
358
|
+
const w = water.waves[i];
|
|
359
|
+
const angle = Math.atan2(w.direction[1], w.direction[0]);
|
|
360
|
+
const dx = Math.cos(angle);
|
|
361
|
+
const dz = Math.sin(angle);
|
|
362
|
+
wave(x * w.scale + dx * t * w.speed, z * w.scale + dz * t * w.speed, waveOut);
|
|
363
|
+
h += w.amplitude * waveOut[0];
|
|
364
|
+
}
|
|
365
|
+
return water.origin[1] + water.level + water.displace * h;
|
|
366
|
+
}
|
|
367
|
+
function set3(out, v) {
|
|
368
|
+
out[0] = v[0] ?? 0;
|
|
369
|
+
out[1] = v[1] ?? 0;
|
|
370
|
+
out[2] = v[2] ?? 0;
|
|
371
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The static collider: every source's triangles flattened into one world-space `Float32Array`
|
|
3
|
+
* (nine floats per triangle) under a bounding-volume hierarchy, built once by median split along
|
|
4
|
+
* the widest centroid axis. Each source owns a contiguous block of triangles and of nodes, so a
|
|
5
|
+
* moving platform refits its own sub-tree and the small top-level tree over the sources, never
|
|
6
|
+
* the rest. Queries (`queries.ts`) walk the flat node arrays with a shared stack; nothing here
|
|
7
|
+
* allocates after the build.
|
|
8
|
+
*
|
|
9
|
+
* Node layout, index `i`: `nodeMin`/`nodeMax` at `3i`; `nodeLeaf[i]` 1 for a leaf; for a leaf
|
|
10
|
+
* `nodeA[i]` is the first triangle and `nodeB[i]` the count, for an inner node they are the two
|
|
11
|
+
* children. A removed or empty source keeps an empty root box (min +∞, max −∞) that no query
|
|
12
|
+
* enters.
|
|
13
|
+
*/
|
|
14
|
+
import type { Geometry } from '../geometry.js';
|
|
15
|
+
import type { Heightfield } from '../heightfield.js';
|
|
16
|
+
import { type GridSource } from './grid.js';
|
|
17
|
+
/** A 3×4 row-major matrix (`Transform.world`, 12 floats) or a 4×4 column-major one (16 floats). */
|
|
18
|
+
export type ColliderTransform = ArrayLike<number>;
|
|
19
|
+
/** What every triangle-set source shares: its placement, layer and user data. */
|
|
20
|
+
interface TriangleSourceBase {
|
|
21
|
+
transform?: ColliderTransform;
|
|
22
|
+
/** Collision layer, a bit index 0..31 (`layerMask` tests `1 << layer`). Default 0. */
|
|
23
|
+
layer?: number;
|
|
24
|
+
/** Handed back on every hit of this source; not serialised. */
|
|
25
|
+
userData?: unknown;
|
|
26
|
+
}
|
|
27
|
+
/** A `Geometry` (any layout whose first three floats per vertex are the position), placed. */
|
|
28
|
+
export interface GeometryMeshSource extends TriangleSourceBase {
|
|
29
|
+
geometry: Geometry;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Bare triangles (ws/geom-3): `positions` is x, y, z per vertex (3 floats, no other lanes) and
|
|
33
|
+
* `indices` three per triangle, as a bake input or a hand-built proxy holds them. Builds and
|
|
34
|
+
* refits exactly as a `{ geometry }` source does.
|
|
35
|
+
*/
|
|
36
|
+
export interface PositionsSource extends TriangleSourceBase {
|
|
37
|
+
positions: Float32Array;
|
|
38
|
+
indices: Uint16Array | Uint32Array;
|
|
39
|
+
}
|
|
40
|
+
/** A triangle set: a `Geometry` or positions-only triangles, optionally placed. */
|
|
41
|
+
export type GeometrySource = GeometryMeshSource | PositionsSource;
|
|
42
|
+
/** A heightfield, one quad (two triangles) per cell, in its own world placement. */
|
|
43
|
+
export interface HeightfieldSource {
|
|
44
|
+
heightfield: Heightfield;
|
|
45
|
+
layer?: number;
|
|
46
|
+
userData?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/** A 2D tile grid: each solid cell is a box in xz (see `grid.ts`). */
|
|
49
|
+
export interface TileGridSource {
|
|
50
|
+
grid: GridSource;
|
|
51
|
+
layer?: number;
|
|
52
|
+
userData?: unknown;
|
|
53
|
+
}
|
|
54
|
+
export type ColliderSource = GeometrySource | HeightfieldSource | TileGridSource;
|
|
55
|
+
export interface StaticColliderOptions {
|
|
56
|
+
/** Most triangles per BVH leaf. Default 4. */
|
|
57
|
+
leafSize?: number;
|
|
58
|
+
}
|
|
59
|
+
/** The kinds a source can be, as stored (and serialised): geometry 0, heightfield 1, grid 2. */
|
|
60
|
+
export type SourceKind = 0 | 1 | 2;
|
|
61
|
+
export declare const SOURCE_GEOMETRY = 0;
|
|
62
|
+
export declare const SOURCE_HEIGHTFIELD = 1;
|
|
63
|
+
export declare const SOURCE_GRID = 2;
|
|
64
|
+
/** One source's record inside the collider. */
|
|
65
|
+
export interface SourceRecord {
|
|
66
|
+
kind: SourceKind;
|
|
67
|
+
/** First triangle and count in `tris`. */
|
|
68
|
+
start: number;
|
|
69
|
+
count: number;
|
|
70
|
+
/** The source's root node, and its node block `[nodeStart, nodeEnd)`. */
|
|
71
|
+
root: number;
|
|
72
|
+
nodeStart: number;
|
|
73
|
+
nodeEnd: number;
|
|
74
|
+
layer: number;
|
|
75
|
+
removed: boolean;
|
|
76
|
+
/** Geometry sources keep their untransformed triangles (nine floats each) for `refit`. */
|
|
77
|
+
local: Float32Array | null;
|
|
78
|
+
userData: unknown;
|
|
79
|
+
}
|
|
80
|
+
export interface ColliderBounds {
|
|
81
|
+
min: [number, number, number];
|
|
82
|
+
max: [number, number, number];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A world of static triangles under a BVH. Build with `createStaticCollider`, query with
|
|
86
|
+
* `raycast`, `overlap`, `sweep` and `slide`, ship with `exportCollider`.
|
|
87
|
+
*/
|
|
88
|
+
export declare class StaticCollider {
|
|
89
|
+
/** World-space triangles, nine floats each, in BVH leaf order. */
|
|
90
|
+
readonly tris: Float32Array;
|
|
91
|
+
/** The source index of each triangle. */
|
|
92
|
+
readonly triSource: Uint32Array;
|
|
93
|
+
readonly nodeMin: Float32Array;
|
|
94
|
+
readonly nodeMax: Float32Array;
|
|
95
|
+
readonly nodeLeaf: Uint8Array;
|
|
96
|
+
readonly nodeA: Int32Array;
|
|
97
|
+
readonly nodeB: Int32Array;
|
|
98
|
+
/** The root node index. */
|
|
99
|
+
readonly root: number;
|
|
100
|
+
/** Top-level nodes over the sources occupy `[0, topCount)` (0 when there is one source). */
|
|
101
|
+
readonly topCount: number;
|
|
102
|
+
readonly sources: SourceRecord[];
|
|
103
|
+
readonly leafSize: number;
|
|
104
|
+
/** The union of every live source, kept current by `refit` and `remove`. */
|
|
105
|
+
readonly bounds: ColliderBounds;
|
|
106
|
+
constructor(parts: {
|
|
107
|
+
tris: Float32Array;
|
|
108
|
+
triSource: Uint32Array;
|
|
109
|
+
nodeMin: Float32Array;
|
|
110
|
+
nodeMax: Float32Array;
|
|
111
|
+
nodeLeaf: Uint8Array;
|
|
112
|
+
nodeA: Int32Array;
|
|
113
|
+
nodeB: Int32Array;
|
|
114
|
+
root: number;
|
|
115
|
+
topCount: number;
|
|
116
|
+
sources: SourceRecord[];
|
|
117
|
+
leafSize: number;
|
|
118
|
+
});
|
|
119
|
+
/** Triangles in the live (not removed) sources. */
|
|
120
|
+
get triangleCount(): number;
|
|
121
|
+
/** Number of sources, removed ones included (indices stay stable). */
|
|
122
|
+
get sourceCount(): number;
|
|
123
|
+
/** The `userData` of a source (-1 or out of range gives `undefined`). */
|
|
124
|
+
userData(source: number): unknown;
|
|
125
|
+
/**
|
|
126
|
+
* Moves a geometry source to `transform` (a 3×4 `Transform.world` or a 4×4 column-major
|
|
127
|
+
* matrix): rewrites its world triangles from the local copy, refits its leaves and inner nodes
|
|
128
|
+
* bottom-up, then the top-level nodes. Nothing is rebuilt; a tree whose leaves have drifted far
|
|
129
|
+
* apart only gets looser. Throws for a heightfield or grid source.
|
|
130
|
+
*/
|
|
131
|
+
refit(sourceIndex: number, transform: ColliderTransform): void;
|
|
132
|
+
/** Drops a source from every query (its root box becomes empty). Indices do not shift. */
|
|
133
|
+
remove(sourceIndex: number): void;
|
|
134
|
+
/** Recomputes the nodes of one block from its leaves up (children always follow parents). */
|
|
135
|
+
private refitBlock;
|
|
136
|
+
private refitTop;
|
|
137
|
+
private updateBounds;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Writes `m × (x, y, z, 1)` into `out` at `o`. `m` is a 3×4 row-major matrix (12 floats, as
|
|
141
|
+
* `Transform.world`) or a 4×4 column-major one (16 floats, as `Camera.view`). Anything else throws.
|
|
142
|
+
*/
|
|
143
|
+
export declare function applyTransform(m: ColliderTransform, x: number, y: number, z: number, out: Float32Array, o: number): void;
|
|
144
|
+
/**
|
|
145
|
+
* Builds a `StaticCollider` over `sources`. Every source becomes a block of triangles (world
|
|
146
|
+
* space) and a BVH sub-tree (median split on the widest centroid axis, leaves of at most
|
|
147
|
+
* `leafSize` triangles, default 4); a top-level tree over the sources' roots joins them.
|
|
148
|
+
* Build-time allocation only; queries then allocate nothing.
|
|
149
|
+
*/
|
|
150
|
+
export declare function createStaticCollider(sources: ColliderSource[], opts?: StaticColliderOptions): StaticCollider;
|
|
151
|
+
export {};
|