@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
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import { INSTANCE_PARAM_FLOATS, writeInstanceParams, } from './frame.js';
|
|
2
|
+
import { isMeshLod } from './lod.js';
|
|
3
|
+
import { INSTANCE_FLOATS, INSTANCE_STRIDE } from './material.js';
|
|
4
|
+
import { MATRIX3X4_FLOATS, Transform } from './transform.js';
|
|
5
|
+
const NO_PARAMS = Object.freeze({});
|
|
6
|
+
/**
|
|
7
|
+
* A retained list of up to `capacity` instances of one mesh and material, drawn with
|
|
8
|
+
* `frame.list(list)`; made by `renderer.createInstanceList`. Instances are set and removed by
|
|
9
|
+
* index (`set`, `remove`: swap-remove) and live in the list's own GPU vertex buffer, in the
|
|
10
|
+
* engine instance format: a frame uploads only the index range touched since the last one, so
|
|
11
|
+
* an unchanged list costs nothing on the CPU and no `writeBuffer`. `matrices` (12 floats per
|
|
12
|
+
* instance, 3×4 row-major) and `params` (`INSTANCE_PARAM_FLOATS` each) are the CPU copies; code
|
|
13
|
+
* that writes them directly calls `touch(i)` so the range uploads.
|
|
14
|
+
*
|
|
15
|
+
* The list is culled as one unit by `bounds`, a world-space sphere: computed from the mesh's
|
|
16
|
+
* bounds through every instance (the centre of their box, the radius to the farthest one plus
|
|
17
|
+
* its scaled mesh radius) whenever instances changed, or fixed by `setBounds`. A mesh without
|
|
18
|
+
* bounds (`radius` Infinity) gives a list that is never culled.
|
|
19
|
+
*/
|
|
20
|
+
export class InstanceList {
|
|
21
|
+
material;
|
|
22
|
+
capacity;
|
|
23
|
+
matrices;
|
|
24
|
+
params;
|
|
25
|
+
/** Layer mask of the whole list (`camera.layers`); default 1. */
|
|
26
|
+
layerBits = 1;
|
|
27
|
+
/** Sort key (`InstanceParams.order`); default 0. */
|
|
28
|
+
order = 0;
|
|
29
|
+
/** Draw into the sun's shadow map; default: the mesh is not 2D. */
|
|
30
|
+
castShadow;
|
|
31
|
+
/**
|
|
32
|
+
* The GPU vertex buffer the instances live in (`capacity` × `INSTANCE_STRIDE` bytes). A LOD
|
|
33
|
+
* list (`lod`) never writes it (ws/render-9): its instances reach the GPU in the frame's
|
|
34
|
+
* per-level copy.
|
|
35
|
+
*/
|
|
36
|
+
buffer;
|
|
37
|
+
/**
|
|
38
|
+
* With `velocity` (ws/render-4): the previous frame's matrices (12 floats per instance) and
|
|
39
|
+
* the vertex buffer (48 bytes per instance, slot 2) a material writing a velocity attachment
|
|
40
|
+
* reads them from; null otherwise. A slot `set` this frame keeps what it held before as
|
|
41
|
+
* previous; one left alone settles to its current matrix at the next flush (no motion).
|
|
42
|
+
* A LOD list (`lod`) keeps `prevMatrices` but has no `prevBuffer` and uploads none
|
|
43
|
+
* (ws/render-8): the renderer copies its previous matrices into its shared lane.
|
|
44
|
+
*/
|
|
45
|
+
prevMatrices;
|
|
46
|
+
prevBuffer;
|
|
47
|
+
/** Keeps a previous-matrix lane (`createInstanceList(..., { velocity: true })`). */
|
|
48
|
+
velocity;
|
|
49
|
+
_count = 0;
|
|
50
|
+
_bounds = null;
|
|
51
|
+
fixedBounds = false;
|
|
52
|
+
boundsDirty = false;
|
|
53
|
+
/** Instance range `[dirtyLo, dirtyHi)` to upload; empty when `dirtyLo >= dirtyHi`. */
|
|
54
|
+
dirtyLo = 0;
|
|
55
|
+
dirtyHi = 0;
|
|
56
|
+
/** Interleaved staging for the upload, in the instance format. */
|
|
57
|
+
data;
|
|
58
|
+
center = [0, 0, 0];
|
|
59
|
+
/** With velocity: the flush each slot was last captured in (0: never); `flushes` counts them. */
|
|
60
|
+
stamp;
|
|
61
|
+
flushes = 1;
|
|
62
|
+
/** With velocity: the range dirty at the last flush, settled (prev := current) at the next. */
|
|
63
|
+
settleLo = 0;
|
|
64
|
+
settleHi = 0;
|
|
65
|
+
/** Live instances at the last flush. */
|
|
66
|
+
lastCount = 0;
|
|
67
|
+
/** Per-slot keys (`setKey`; NaN: none), made on the first `setKey`. */
|
|
68
|
+
keys = null;
|
|
69
|
+
/**
|
|
70
|
+
* Key → slot hash tables (open addressing, `tableMask + 1` entries): `tableSlots[t]` -1 is
|
|
71
|
+
* empty. `cur` is the one the last flush filled; the other is refilled at the next.
|
|
72
|
+
*/
|
|
73
|
+
tableKeys = null;
|
|
74
|
+
tableSlots = null;
|
|
75
|
+
tableMask = 0;
|
|
76
|
+
cur = 0;
|
|
77
|
+
/** With velocity and keys: each slot's matrix at the last flush. */
|
|
78
|
+
lastMatrices = null;
|
|
79
|
+
_previousIndex = null;
|
|
80
|
+
/** The list's mesh: the one it was made with, or the first level of its `lod`. */
|
|
81
|
+
mesh;
|
|
82
|
+
/**
|
|
83
|
+
* The LOD chain the list was made with (ws/render-6), else null. Each instance then picks a
|
|
84
|
+
* level per view, and `frame.list` copies the instances into the frame's upload bucketed by
|
|
85
|
+
* level rather than drawing from `buffer`; with `velocity` its `prevMatrices` travel with
|
|
86
|
+
* the copy into the renderer's shared lane (ws/render-7), so it has no `prevBuffer`.
|
|
87
|
+
*/
|
|
88
|
+
lod;
|
|
89
|
+
constructor(device, mesh, material, capacity, opts = {}) {
|
|
90
|
+
this.material = material;
|
|
91
|
+
this.capacity = capacity;
|
|
92
|
+
if (!(capacity >= 1))
|
|
93
|
+
throw new Error(`InstanceList: capacity ${capacity}`);
|
|
94
|
+
if (isMeshLod(mesh)) {
|
|
95
|
+
const first = mesh.meshes[0];
|
|
96
|
+
if (!first)
|
|
97
|
+
throw new Error('InstanceList: MeshLod has no meshes');
|
|
98
|
+
this.lod = mesh;
|
|
99
|
+
this.mesh = first;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.lod = null;
|
|
103
|
+
this.mesh = mesh;
|
|
104
|
+
}
|
|
105
|
+
this.matrices = new Float32Array(capacity * MATRIX3X4_FLOATS);
|
|
106
|
+
this.params = new Float32Array(capacity * INSTANCE_PARAM_FLOATS);
|
|
107
|
+
this.data = new Float32Array(capacity * INSTANCE_FLOATS);
|
|
108
|
+
this.buffer = device.createBuffer({
|
|
109
|
+
label: 'instance-list',
|
|
110
|
+
size: capacity * INSTANCE_STRIDE,
|
|
111
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
112
|
+
});
|
|
113
|
+
this.velocity = opts.velocity === true;
|
|
114
|
+
if (this.velocity) {
|
|
115
|
+
this.prevMatrices = new Float32Array(capacity * MATRIX3X4_FLOATS);
|
|
116
|
+
// A LOD list's previous matrices travel with its per-frame copy (ws/render-8): no buffer.
|
|
117
|
+
this.prevBuffer = this.lod
|
|
118
|
+
? null
|
|
119
|
+
: device.createBuffer({
|
|
120
|
+
label: 'instance-list-prev',
|
|
121
|
+
size: capacity * MATRIX3X4_FLOATS * 4,
|
|
122
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
123
|
+
});
|
|
124
|
+
this.stamp = new Uint32Array(capacity);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
this.prevMatrices = null;
|
|
128
|
+
this.prevBuffer = null;
|
|
129
|
+
this.stamp = new Uint32Array(0);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** Live instances (the first `count` slots). */
|
|
133
|
+
get count() {
|
|
134
|
+
return this._count;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The world sphere the list is culled by: `setBounds`'s, or the one computed from the
|
|
138
|
+
* instances (refreshed by the next `frame.list` after a change, or by `flush`); null for a
|
|
139
|
+
* mesh without bounds.
|
|
140
|
+
*/
|
|
141
|
+
get bounds() {
|
|
142
|
+
if (this.boundsDirty)
|
|
143
|
+
this.computeBounds();
|
|
144
|
+
return this._bounds;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* True once any instance has a key (`setKey`, ws/render-7): the list then matches each
|
|
148
|
+
* instance to last frame's by key (keyless slots by index) at every flush, for its LOD
|
|
149
|
+
* level memory and its velocity history.
|
|
150
|
+
*/
|
|
151
|
+
get keyed() {
|
|
152
|
+
return this.keys !== null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Flushes so far (`flush`, once per `frame.list`). `previousIndex` maps the instances of
|
|
156
|
+
* flush `flushCount` onto those of flush `flushCount - 1`.
|
|
157
|
+
*/
|
|
158
|
+
get flushCount() {
|
|
159
|
+
return this.flushes - 1;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* With keys (`keyed`), after each flush: per live instance, the index it held at the
|
|
163
|
+
* previous flush (matched by key, a keyless slot by its own index), or -1 for an instance
|
|
164
|
+
* that was not there (a new key, or an index past last flush's count). Null until keyed.
|
|
165
|
+
*/
|
|
166
|
+
get previousIndex() {
|
|
167
|
+
return this._previousIndex;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Give instance `i` (0..count-1) a stable `key` (ws/render-7): a finite number, an entity
|
|
171
|
+
* id, unique in the list (on duplicates the last slot wins). The instance's LOD level
|
|
172
|
+
* memory and velocity history then follow the key, not the index, so removing or
|
|
173
|
+
* reordering instances (`remove`'s swap, a `clear` and refill in another order) changes no
|
|
174
|
+
* other instance's level and no other instance's motion. `null` clears it. The key stays
|
|
175
|
+
* with the slot through `set` and moves with `remove`; a slot appended by `set` starts
|
|
176
|
+
* without one. Chain it after `set`: `list.set(i, t).setKey(i, id)`.
|
|
177
|
+
*/
|
|
178
|
+
setKey(i, key) {
|
|
179
|
+
if (i < 0 || i >= this._count)
|
|
180
|
+
throw new Error(`InstanceList.setKey: index ${i} of ${this._count}`);
|
|
181
|
+
if (key !== null && !Number.isFinite(key))
|
|
182
|
+
throw new Error(`InstanceList.setKey: key ${key} is not a finite number`);
|
|
183
|
+
if (key === null && !this.keys)
|
|
184
|
+
return this;
|
|
185
|
+
this.ensureKeys()[i] = key ?? Number.NaN;
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
/** Instance `i`'s key (`setKey`), or null for none. */
|
|
189
|
+
keyOf(i) {
|
|
190
|
+
const k = this.keys ? this.keys[i] : Number.NaN;
|
|
191
|
+
return i < this._count && !Number.isNaN(k) ? k : null;
|
|
192
|
+
}
|
|
193
|
+
/** True when the next `frame.list` has something to upload. */
|
|
194
|
+
get dirty() {
|
|
195
|
+
return this.dirtyLo < this.dirtyHi;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Place instance `i` (0..count; `count` appends) by a `Transform` or a 3×4 row-major matrix
|
|
199
|
+
* (12 floats, read from `offset`), with `params` (`InstanceParams`; omitted: the defaults).
|
|
200
|
+
* `size` is the transform's scale.xy, or the matrix's x and y column lengths.
|
|
201
|
+
*/
|
|
202
|
+
set(i, m, params = NO_PARAMS, offset = 0) {
|
|
203
|
+
if (i < 0 || i > this._count)
|
|
204
|
+
throw new Error(`InstanceList.set: index ${i} of ${this._count}`);
|
|
205
|
+
if (i === this.capacity)
|
|
206
|
+
throw new Error(`InstanceList.set: full (capacity ${this.capacity})`);
|
|
207
|
+
if (i === this._count) {
|
|
208
|
+
this._count++;
|
|
209
|
+
if (this.keys)
|
|
210
|
+
this.keys[i] = Number.NaN;
|
|
211
|
+
}
|
|
212
|
+
const mats = this.matrices;
|
|
213
|
+
const o = i * MATRIX3X4_FLOATS;
|
|
214
|
+
if (this.velocity)
|
|
215
|
+
this.capture(i, o);
|
|
216
|
+
let sx;
|
|
217
|
+
let sy;
|
|
218
|
+
if (m instanceof Transform) {
|
|
219
|
+
mats.set(m.world, o);
|
|
220
|
+
sx = m.scale.x;
|
|
221
|
+
sy = m.scale.y;
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
for (let k = 0; k < MATRIX3X4_FLOATS; k++)
|
|
225
|
+
mats[o + k] = m[offset + k];
|
|
226
|
+
sx = Math.hypot(mats[o], mats[o + 4], mats[o + 8]);
|
|
227
|
+
sy = Math.hypot(mats[o + 1], mats[o + 5], mats[o + 9]);
|
|
228
|
+
}
|
|
229
|
+
writeInstanceParams(this.params, i * INSTANCE_PARAM_FLOATS, params, sx, sy);
|
|
230
|
+
this.touch(i);
|
|
231
|
+
return this;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Remove instance `i`: the last instance moves into its slot (swap-remove). Returns the index
|
|
235
|
+
* that moved (the old last), or -1 when `i` was the last. Callers keeping indices update
|
|
236
|
+
* the moved one.
|
|
237
|
+
*/
|
|
238
|
+
remove(i) {
|
|
239
|
+
if (i < 0 || i >= this._count)
|
|
240
|
+
throw new Error(`InstanceList.remove: index ${i} of ${this._count}`);
|
|
241
|
+
const last = --this._count;
|
|
242
|
+
this.boundsDirty = !this.fixedBounds;
|
|
243
|
+
if (i === last)
|
|
244
|
+
return -1;
|
|
245
|
+
const mats = this.matrices;
|
|
246
|
+
const prm = this.params;
|
|
247
|
+
if (this.keys)
|
|
248
|
+
this.keys[i] = this.keys[last];
|
|
249
|
+
mats.copyWithin(i * MATRIX3X4_FLOATS, last * MATRIX3X4_FLOATS, (last + 1) * MATRIX3X4_FLOATS);
|
|
250
|
+
if (this.velocity) {
|
|
251
|
+
// The moved instance keeps its own history.
|
|
252
|
+
this.prevMatrices.copyWithin(i * MATRIX3X4_FLOATS, last * MATRIX3X4_FLOATS, (last + 1) * MATRIX3X4_FLOATS);
|
|
253
|
+
this.stamp[i] = this.stamp[last];
|
|
254
|
+
}
|
|
255
|
+
prm.copyWithin(i * INSTANCE_PARAM_FLOATS, last * INSTANCE_PARAM_FLOATS, (last + 1) * INSTANCE_PARAM_FLOATS);
|
|
256
|
+
this.touch(i);
|
|
257
|
+
return last;
|
|
258
|
+
}
|
|
259
|
+
/** Drop every instance (nothing to upload: the next `set`s mark their own range). */
|
|
260
|
+
clear() {
|
|
261
|
+
this._count = 0;
|
|
262
|
+
this.dirtyLo = this.dirtyHi = 0;
|
|
263
|
+
this.boundsDirty = !this.fixedBounds;
|
|
264
|
+
}
|
|
265
|
+
/** Mark instance `i` changed (after writing `matrices` / `params` directly). */
|
|
266
|
+
touch(i) {
|
|
267
|
+
if (this.dirtyLo >= this.dirtyHi) {
|
|
268
|
+
this.dirtyLo = i;
|
|
269
|
+
this.dirtyHi = i + 1;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
if (i < this.dirtyLo)
|
|
273
|
+
this.dirtyLo = i;
|
|
274
|
+
if (i + 1 > this.dirtyHi)
|
|
275
|
+
this.dirtyHi = i + 1;
|
|
276
|
+
}
|
|
277
|
+
this.boundsDirty = !this.fixedBounds;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Fix the cull sphere (world space, copied), or pass null to go back to the automatic one.
|
|
281
|
+
*/
|
|
282
|
+
setBounds(bounds) {
|
|
283
|
+
if (bounds) {
|
|
284
|
+
this.fixedBounds = true;
|
|
285
|
+
this.boundsDirty = false;
|
|
286
|
+
const c = this.center;
|
|
287
|
+
c[0] = bounds.center[0];
|
|
288
|
+
c[1] = bounds.center[1];
|
|
289
|
+
c[2] = bounds.center[2];
|
|
290
|
+
this._bounds = { center: c, radius: bounds.radius };
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.fixedBounds = false;
|
|
294
|
+
this.boundsDirty = true;
|
|
295
|
+
}
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Upload the changed range to `buffer` (one `writeBuffer`, or none when nothing changed) and
|
|
300
|
+
* refresh the automatic bounds. The renderer calls it from `frame.list`; no allocation. A LOD
|
|
301
|
+
* list uploads nothing: `frame.list` copies its instances into the frame's upload per level.
|
|
302
|
+
*/
|
|
303
|
+
flush(queue) {
|
|
304
|
+
if (this.boundsDirty)
|
|
305
|
+
this.computeBounds();
|
|
306
|
+
const lo = this.dirtyLo;
|
|
307
|
+
const hi = Math.min(this.dirtyHi, this._count);
|
|
308
|
+
this.dirtyLo = this.dirtyHi = 0;
|
|
309
|
+
if (this.keys)
|
|
310
|
+
this.matchKeys();
|
|
311
|
+
if (this.velocity)
|
|
312
|
+
this.flushPrevious(queue, lo, hi);
|
|
313
|
+
this.lastCount = this._count;
|
|
314
|
+
this.flushes++;
|
|
315
|
+
// A LOD list is drawn from the frame's per-level copy, never from `buffer` (ws/render-9).
|
|
316
|
+
if (lo >= hi || this.lod)
|
|
317
|
+
return;
|
|
318
|
+
const d = this.data;
|
|
319
|
+
const mats = this.matrices;
|
|
320
|
+
const prm = this.params;
|
|
321
|
+
for (let i = lo; i < hi; i++) {
|
|
322
|
+
const to = i * INSTANCE_FLOATS;
|
|
323
|
+
const mo = i * MATRIX3X4_FLOATS;
|
|
324
|
+
for (let k = 0; k < MATRIX3X4_FLOATS; k++)
|
|
325
|
+
d[to + k] = mats[mo + k];
|
|
326
|
+
const po = i * INSTANCE_PARAM_FLOATS;
|
|
327
|
+
for (let k = 0; k < INSTANCE_PARAM_FLOATS; k++)
|
|
328
|
+
d[to + MATRIX3X4_FLOATS + k] = prm[po + k];
|
|
329
|
+
}
|
|
330
|
+
queue.writeBuffer(this.buffer, lo * INSTANCE_STRIDE, d.buffer, lo * INSTANCE_STRIDE, (hi - lo) * INSTANCE_STRIDE);
|
|
331
|
+
}
|
|
332
|
+
destroy() {
|
|
333
|
+
this.buffer.destroy();
|
|
334
|
+
this.prevBuffer?.destroy();
|
|
335
|
+
this._count = 0;
|
|
336
|
+
}
|
|
337
|
+
/** With velocity: the first `set` of a slot in a frame keeps its current matrix as previous. */
|
|
338
|
+
capture(i, o) {
|
|
339
|
+
// A slot never flushed has no history: `flushPrevious` settles it from its first matrix.
|
|
340
|
+
if (this.stamp[i] === this.flushes || this.stamp[i] === 0)
|
|
341
|
+
return;
|
|
342
|
+
this.stamp[i] = this.flushes;
|
|
343
|
+
const prev = this.prevMatrices;
|
|
344
|
+
const cur = this.matrices;
|
|
345
|
+
for (let k = 0; k < MATRIX3X4_FLOATS; k++)
|
|
346
|
+
prev[o + k] = cur[o + k];
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Settle the slots dirty last flush but untouched this one (previous := current), give a
|
|
350
|
+
* brand-new instance its current matrix as previous, and upload the previous lane over the
|
|
351
|
+
* union of both ranges.
|
|
352
|
+
*/
|
|
353
|
+
flushPrevious(queue, lo, hi) {
|
|
354
|
+
const prev = this.prevMatrices;
|
|
355
|
+
const cur = this.matrices;
|
|
356
|
+
const sLo = this.settleLo;
|
|
357
|
+
const sHi = Math.min(this.settleHi, this._count);
|
|
358
|
+
const now = this.flushes;
|
|
359
|
+
// Slots that died since the last flush lose their history: one appended there later is new.
|
|
360
|
+
for (let i = this._count; i < this.lastCount; i++)
|
|
361
|
+
this.stamp[i] = 0;
|
|
362
|
+
for (let i = sLo; i < sHi; i++) {
|
|
363
|
+
if (this.stamp[i] === now)
|
|
364
|
+
continue;
|
|
365
|
+
const o = i * MATRIX3X4_FLOATS;
|
|
366
|
+
for (let k = 0; k < MATRIX3X4_FLOATS; k++)
|
|
367
|
+
prev[o + k] = cur[o + k];
|
|
368
|
+
}
|
|
369
|
+
for (let i = lo; i < hi; i++) {
|
|
370
|
+
// Never flushed (a new slot) or touched directly without `set`: no history → settle.
|
|
371
|
+
const o = i * MATRIX3X4_FLOATS;
|
|
372
|
+
if (this.stamp[i] !== now) {
|
|
373
|
+
for (let k = 0; k < MATRIX3X4_FLOATS; k++)
|
|
374
|
+
prev[o + k] = cur[o + k];
|
|
375
|
+
this.stamp[i] = now;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
this.settleLo = lo;
|
|
379
|
+
this.settleHi = hi;
|
|
380
|
+
let uLo = sLo < sHi ? (lo < hi ? Math.min(lo, sLo) : sLo) : lo;
|
|
381
|
+
let uHi = sLo < sHi ? (lo < hi ? Math.max(hi, sHi) : sHi) : hi;
|
|
382
|
+
if (this.keys) {
|
|
383
|
+
// Keyed slots take the matrix their key held at the last flush (none: no motion);
|
|
384
|
+
// keyless ones keep the index history above. The whole live range uploads.
|
|
385
|
+
const keys = this.keys;
|
|
386
|
+
const pi = this._previousIndex;
|
|
387
|
+
const n = this._count;
|
|
388
|
+
let last = this.lastMatrices;
|
|
389
|
+
if (!last)
|
|
390
|
+
last = this.lastMatrices = new Float32Array(this.capacity * MATRIX3X4_FLOATS);
|
|
391
|
+
for (let i = 0; i < n; i++) {
|
|
392
|
+
const k = keys[i];
|
|
393
|
+
if (Number.isNaN(k))
|
|
394
|
+
continue;
|
|
395
|
+
const j = pi[i];
|
|
396
|
+
const o = i * MATRIX3X4_FLOATS;
|
|
397
|
+
const src = j >= 0 ? last : cur;
|
|
398
|
+
const so = j >= 0 ? j * MATRIX3X4_FLOATS : o;
|
|
399
|
+
for (let f = 0; f < MATRIX3X4_FLOATS; f++)
|
|
400
|
+
prev[o + f] = src[so + f];
|
|
401
|
+
this.stamp[i] = now;
|
|
402
|
+
}
|
|
403
|
+
last.set(cur.subarray(0, n * MATRIX3X4_FLOATS));
|
|
404
|
+
uLo = 0;
|
|
405
|
+
uHi = n;
|
|
406
|
+
}
|
|
407
|
+
if (uLo >= uHi || !this.prevBuffer)
|
|
408
|
+
return;
|
|
409
|
+
const bytes = MATRIX3X4_FLOATS * 4;
|
|
410
|
+
queue.writeBuffer(this.prevBuffer, uLo * bytes, prev.buffer, uLo * bytes, (uHi - uLo) * bytes);
|
|
411
|
+
}
|
|
412
|
+
ensureKeys() {
|
|
413
|
+
let keys = this.keys;
|
|
414
|
+
if (keys)
|
|
415
|
+
return keys;
|
|
416
|
+
keys = this.keys = new Float64Array(this.capacity).fill(Number.NaN);
|
|
417
|
+
let size = 16;
|
|
418
|
+
while (size < this.capacity * 2)
|
|
419
|
+
size *= 2;
|
|
420
|
+
this.tableMask = size - 1;
|
|
421
|
+
this.tableKeys = [new Float64Array(size), new Float64Array(size)];
|
|
422
|
+
this.tableSlots = [new Int32Array(size).fill(-1), new Int32Array(size).fill(-1)];
|
|
423
|
+
this._previousIndex = new Int32Array(this.capacity);
|
|
424
|
+
return keys;
|
|
425
|
+
}
|
|
426
|
+
/** Hash table start index of `k`. */
|
|
427
|
+
hashOf(k) {
|
|
428
|
+
const lo = k | 0;
|
|
429
|
+
const hi = (k / 4294967296) | 0;
|
|
430
|
+
let h = Math.imul(lo ^ Math.imul(hi, 0x85ebca6b), 0x9e3779b1);
|
|
431
|
+
h ^= h >>> 15;
|
|
432
|
+
return h & this.tableMask;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Fill `previousIndex` from the table of the last flush (keyed slots by key, keyless by
|
|
436
|
+
* index), then refill the other table with this flush's keys and make it current. No
|
|
437
|
+
* allocation.
|
|
438
|
+
*/
|
|
439
|
+
matchKeys() {
|
|
440
|
+
const keys = this.keys;
|
|
441
|
+
const pi = this._previousIndex;
|
|
442
|
+
const mask = this.tableMask;
|
|
443
|
+
const lastK = this.tableKeys[this.cur];
|
|
444
|
+
const lastS = this.tableSlots[this.cur];
|
|
445
|
+
const n = this._count;
|
|
446
|
+
const lastCount = this.lastCount;
|
|
447
|
+
for (let i = 0; i < n; i++) {
|
|
448
|
+
const k = keys[i];
|
|
449
|
+
if (Number.isNaN(k)) {
|
|
450
|
+
pi[i] = i < lastCount ? i : -1;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
let t = this.hashOf(k);
|
|
454
|
+
let j = -1;
|
|
455
|
+
for (;;) {
|
|
456
|
+
const s = lastS[t];
|
|
457
|
+
if (s < 0)
|
|
458
|
+
break;
|
|
459
|
+
if (lastK[t] === k) {
|
|
460
|
+
j = s;
|
|
461
|
+
break;
|
|
462
|
+
}
|
|
463
|
+
t = (t + 1) & mask;
|
|
464
|
+
}
|
|
465
|
+
pi[i] = j;
|
|
466
|
+
}
|
|
467
|
+
const next = 1 - this.cur;
|
|
468
|
+
const nk = this.tableKeys[next];
|
|
469
|
+
const ns = this.tableSlots[next];
|
|
470
|
+
ns.fill(-1);
|
|
471
|
+
for (let i = 0; i < n; i++) {
|
|
472
|
+
const k = keys[i];
|
|
473
|
+
if (Number.isNaN(k))
|
|
474
|
+
continue;
|
|
475
|
+
let t = this.hashOf(k);
|
|
476
|
+
for (;;) {
|
|
477
|
+
const s = ns[t];
|
|
478
|
+
if (s < 0 || nk[t] === k)
|
|
479
|
+
break;
|
|
480
|
+
t = (t + 1) & mask;
|
|
481
|
+
}
|
|
482
|
+
nk[t] = k;
|
|
483
|
+
ns[t] = i;
|
|
484
|
+
}
|
|
485
|
+
this.cur = next;
|
|
486
|
+
}
|
|
487
|
+
/** The automatic sphere: `mesh.bounds` through every live instance. */
|
|
488
|
+
computeBounds() {
|
|
489
|
+
this.boundsDirty = false;
|
|
490
|
+
const mb = this.mesh.bounds;
|
|
491
|
+
const n = this._count;
|
|
492
|
+
if (mb.radius === Number.POSITIVE_INFINITY || n === 0) {
|
|
493
|
+
this._bounds = null;
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
const m = this.matrices;
|
|
497
|
+
const cx = mb.center[0];
|
|
498
|
+
const cy = mb.center[1];
|
|
499
|
+
const cz = mb.center[2];
|
|
500
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
501
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
502
|
+
let minZ = Number.POSITIVE_INFINITY;
|
|
503
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
504
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
505
|
+
let maxZ = Number.NEGATIVE_INFINITY;
|
|
506
|
+
for (let i = 0; i < n; i++) {
|
|
507
|
+
const o = i * MATRIX3X4_FLOATS;
|
|
508
|
+
const x = m[o] * cx + m[o + 1] * cy + m[o + 2] * cz + m[o + 3];
|
|
509
|
+
const y = m[o + 4] * cx + m[o + 5] * cy + m[o + 6] * cz + m[o + 7];
|
|
510
|
+
const z = m[o + 8] * cx + m[o + 9] * cy + m[o + 10] * cz + m[o + 11];
|
|
511
|
+
if (x < minX)
|
|
512
|
+
minX = x;
|
|
513
|
+
if (x > maxX)
|
|
514
|
+
maxX = x;
|
|
515
|
+
if (y < minY)
|
|
516
|
+
minY = y;
|
|
517
|
+
if (y > maxY)
|
|
518
|
+
maxY = y;
|
|
519
|
+
if (z < minZ)
|
|
520
|
+
minZ = z;
|
|
521
|
+
if (z > maxZ)
|
|
522
|
+
maxZ = z;
|
|
523
|
+
}
|
|
524
|
+
const c = this.center;
|
|
525
|
+
c[0] = (minX + maxX) / 2;
|
|
526
|
+
c[1] = (minY + maxY) / 2;
|
|
527
|
+
c[2] = (minZ + maxZ) / 2;
|
|
528
|
+
let r2 = 0;
|
|
529
|
+
for (let i = 0; i < n; i++) {
|
|
530
|
+
const o = i * MATRIX3X4_FLOATS;
|
|
531
|
+
const x = m[o] * cx + m[o + 1] * cy + m[o + 2] * cz + m[o + 3] - c[0];
|
|
532
|
+
const y = m[o + 4] * cx + m[o + 5] * cy + m[o + 6] * cz + m[o + 7] - c[1];
|
|
533
|
+
const z = m[o + 8] * cx + m[o + 9] * cy + m[o + 10] * cz + m[o + 11] - c[2];
|
|
534
|
+
const s0 = m[o] * m[o] + m[o + 4] * m[o + 4] + m[o + 8] * m[o + 8];
|
|
535
|
+
const s1 = m[o + 1] * m[o + 1] + m[o + 5] * m[o + 5] + m[o + 9] * m[o + 9];
|
|
536
|
+
const s2 = m[o + 2] * m[o + 2] + m[o + 6] * m[o + 6] + m[o + 10] * m[o + 10];
|
|
537
|
+
const d = Math.sqrt(x * x + y * y + z * z) + mb.radius * Math.sqrt(Math.max(s0, s1, s2));
|
|
538
|
+
if (d > r2)
|
|
539
|
+
r2 = d;
|
|
540
|
+
}
|
|
541
|
+
const b = this._bounds;
|
|
542
|
+
if (b && b.center === c)
|
|
543
|
+
b.radius = r2;
|
|
544
|
+
else
|
|
545
|
+
this._bounds = { center: c, radius: r2 };
|
|
546
|
+
}
|
|
547
|
+
}
|