@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,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `slideTiles`: a 2D box moved against a tile grid, the platformer case. Axis-separated: each
|
|
3
|
+
* sub-step (at most half a tile) moves x then y and pushes the box out of what it entered.
|
|
4
|
+
* Solid tiles block from every side; one-way tiles only hold a box falling onto them from above;
|
|
5
|
+
* moving platforms (`movers`) are solid boxes that also carry what stands on them.
|
|
6
|
+
*
|
|
7
|
+
* Screen convention: y grows downward, so `+dy` falls, "ground" is below (`y + h`) and a
|
|
8
|
+
* ceiling above (`y`). A `GridSource` maps its column `x` and row `z` to tile `(cx, cy)`, its
|
|
9
|
+
* `origin` `[x, z]` to the world x, y of tile (0, 0). Pure arithmetic: no allocation per call.
|
|
10
|
+
*/
|
|
11
|
+
import { gridSolid } from './grid.js';
|
|
12
|
+
export const TILE_EMPTY = 0;
|
|
13
|
+
export const TILE_SOLID = 1;
|
|
14
|
+
/** Holds only from above: a box rising or moving sideways passes through. */
|
|
15
|
+
export const TILE_ONE_WAY = 2;
|
|
16
|
+
export function createTileSlideResult() {
|
|
17
|
+
return {
|
|
18
|
+
x: 0,
|
|
19
|
+
y: 0,
|
|
20
|
+
dx: 0,
|
|
21
|
+
dy: 0,
|
|
22
|
+
onGround: false,
|
|
23
|
+
hitCeiling: false,
|
|
24
|
+
hitWall: false,
|
|
25
|
+
riding: -1,
|
|
26
|
+
carried: { dx: 0, dy: 0 },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Queue `mover`'s motion this tick into `result.carried`, for the next `slideTiles` with that
|
|
31
|
+
* result to apply first. Call it with the platform the box rode last tick
|
|
32
|
+
* (`movers[result.riding]`), after the platforms move and before the box does. Returns `result`.
|
|
33
|
+
*/
|
|
34
|
+
export function carryBy(result, mover) {
|
|
35
|
+
result.carried.dx += mover.dx;
|
|
36
|
+
result.carried.dy += mover.dy;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
const EPS = 0.001;
|
|
40
|
+
// The query being run: module scratch so the helpers take no closures (no allocation per call).
|
|
41
|
+
let grid = null;
|
|
42
|
+
let size = 1;
|
|
43
|
+
let ox = 0;
|
|
44
|
+
let oy = 0;
|
|
45
|
+
let oneWay = true;
|
|
46
|
+
const NO_MOVERS = [];
|
|
47
|
+
const NO_OPTIONS = {};
|
|
48
|
+
let movers = NO_MOVERS;
|
|
49
|
+
function kind(cx, cy) {
|
|
50
|
+
const g = grid;
|
|
51
|
+
if ('solidAt' in g)
|
|
52
|
+
return g.solidAt(cx, cy);
|
|
53
|
+
return gridSolid(g, cx, cy) ? TILE_SOLID : TILE_EMPTY;
|
|
54
|
+
}
|
|
55
|
+
function overlaps(r, w, h, m) {
|
|
56
|
+
return r.x < m.x + m.w && r.x + w > m.x && r.y < m.y + m.h && r.y + h > m.y;
|
|
57
|
+
}
|
|
58
|
+
/** A solid tile anywhere in the box at (x, y)? */
|
|
59
|
+
function blockedAt(x, y, w, h) {
|
|
60
|
+
const c0 = Math.floor((x + EPS - ox) / size);
|
|
61
|
+
const c1 = Math.floor((x + w - EPS - ox) / size);
|
|
62
|
+
const r0 = Math.floor((y + EPS - oy) / size);
|
|
63
|
+
const r1 = Math.floor((y + h - EPS - oy) / size);
|
|
64
|
+
for (let r = r0; r <= r1; r++)
|
|
65
|
+
for (let c = c0; c <= c1; c++)
|
|
66
|
+
if (kind(c, r) === TILE_SOLID)
|
|
67
|
+
return true;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
/** Push the box out of a solid column it entered moving `dir` along x. True on a hit. */
|
|
71
|
+
function resolveX(r, w, h, dir, stepUp, grounded) {
|
|
72
|
+
if (dir === 0)
|
|
73
|
+
return false;
|
|
74
|
+
let hit = false;
|
|
75
|
+
const top = Math.floor((r.y + EPS - oy) / size);
|
|
76
|
+
const bottom = Math.floor((r.y + h - EPS - oy) / size);
|
|
77
|
+
const col = dir > 0 ? Math.floor((r.x + w - EPS - ox) / size) : Math.floor((r.x + EPS - ox) / size);
|
|
78
|
+
let highest = Number.POSITIVE_INFINITY;
|
|
79
|
+
for (let row = top; row <= bottom; row++) {
|
|
80
|
+
if (kind(col, row) === TILE_SOLID) {
|
|
81
|
+
highest = row;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (highest !== Number.POSITIVE_INFINITY) {
|
|
86
|
+
// A ledge low enough to step onto, with room above it?
|
|
87
|
+
const rise = r.y + h - (oy + highest * size);
|
|
88
|
+
if (grounded && stepUp > 0 && rise <= stepUp + EPS && !blockedAt(r.x, r.y - rise, w, h)) {
|
|
89
|
+
r.y -= rise;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
r.x = dir > 0 ? ox + col * size - w : ox + (col + 1) * size;
|
|
93
|
+
hit = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (let i = 0; i < movers.length; i++) {
|
|
97
|
+
const m = movers[i];
|
|
98
|
+
if (!overlaps(r, w, h, m))
|
|
99
|
+
continue;
|
|
100
|
+
// Only a clearly sideways overlap is a wall (standing on top is not).
|
|
101
|
+
if (Math.min(r.y + h - m.y, m.y + m.h - r.y) <= 2 * EPS)
|
|
102
|
+
continue;
|
|
103
|
+
r.x = dir > 0 ? m.x - w : m.x + m.w;
|
|
104
|
+
hit = true;
|
|
105
|
+
}
|
|
106
|
+
return hit;
|
|
107
|
+
}
|
|
108
|
+
function resolveY(r, w, h, dir) {
|
|
109
|
+
if (dir === 0)
|
|
110
|
+
return;
|
|
111
|
+
const left = Math.floor((r.x + EPS - ox) / size);
|
|
112
|
+
const right = Math.floor((r.x + w - EPS - ox) / size);
|
|
113
|
+
if (dir > 0) {
|
|
114
|
+
const row = Math.floor((r.y + h - EPS - oy) / size);
|
|
115
|
+
const rowTop = oy + row * size;
|
|
116
|
+
const prevBottom = r.y + h - dir;
|
|
117
|
+
for (let c = left; c <= right; c++) {
|
|
118
|
+
const k = kind(c, row);
|
|
119
|
+
if (k === TILE_SOLID || (oneWay && k === TILE_ONE_WAY && prevBottom <= rowTop + EPS)) {
|
|
120
|
+
r.y = rowTop - h;
|
|
121
|
+
r.onGround = true;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (let i = 0; i < movers.length; i++) {
|
|
126
|
+
const m = movers[i];
|
|
127
|
+
if (!overlaps(r, w, h, m))
|
|
128
|
+
continue;
|
|
129
|
+
// Land when the feet were at or above the platform's top before this step (its previous
|
|
130
|
+
// top, as it is moving too).
|
|
131
|
+
if (prevBottom <= m.y - m.dy + EPS) {
|
|
132
|
+
r.y = m.y - h;
|
|
133
|
+
r.onGround = true;
|
|
134
|
+
r.riding = i;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const row = Math.floor((r.y + EPS - oy) / size);
|
|
140
|
+
for (let c = left; c <= right; c++) {
|
|
141
|
+
if (kind(c, row) === TILE_SOLID) {
|
|
142
|
+
r.y = oy + (row + 1) * size;
|
|
143
|
+
r.hitCeiling = true;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
for (let i = 0; i < movers.length; i++) {
|
|
148
|
+
const m = movers[i];
|
|
149
|
+
if (!overlaps(r, w, h, m))
|
|
150
|
+
continue;
|
|
151
|
+
if (r.y < m.y + m.h && r.y > m.y) {
|
|
152
|
+
r.y = m.y + m.h;
|
|
153
|
+
r.hitCeiling = true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** At rest vertically: anything right under the feet? */
|
|
159
|
+
function probeGround(r, w, h) {
|
|
160
|
+
const feet = r.y + h;
|
|
161
|
+
const row = Math.floor((feet + EPS - oy) / size);
|
|
162
|
+
if (Math.abs(oy + row * size - feet) <= EPS) {
|
|
163
|
+
const left = Math.floor((r.x + EPS - ox) / size);
|
|
164
|
+
const right = Math.floor((r.x + w - EPS - ox) / size);
|
|
165
|
+
for (let c = left; c <= right; c++) {
|
|
166
|
+
const k = kind(c, row);
|
|
167
|
+
if (k === TILE_SOLID || (oneWay && k === TILE_ONE_WAY)) {
|
|
168
|
+
r.onGround = true;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
for (let i = 0; i < movers.length; i++) {
|
|
174
|
+
const m = movers[i];
|
|
175
|
+
if (Math.abs(m.y - feet) <= EPS && r.x < m.x + m.w && r.x + w > m.x) {
|
|
176
|
+
r.onGround = true;
|
|
177
|
+
r.riding = i;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Move `box` by `(dx, dy)` against `tiles` (a `GridSource` or a `TileQuery`), writing where it
|
|
183
|
+
* ended and what it touched into `out` (returned). A carry queued in `out.carried` (`carryBy`)
|
|
184
|
+
* is applied first and cleared. The box is never moved more than half a tile per sub-step, so
|
|
185
|
+
* it cannot tunnel; a box sliding along a floor or wall of separate tiles never catches on their
|
|
186
|
+
* seams (each axis only tests the tiles ahead of its leading edge, inset by a small epsilon).
|
|
187
|
+
* `box` itself is not changed: copy `out.x`, `out.y` back.
|
|
188
|
+
*/
|
|
189
|
+
export function slideTiles(tiles, box, dx, dy, out, opts = NO_OPTIONS) {
|
|
190
|
+
grid = tiles;
|
|
191
|
+
size = tiles.cellSize;
|
|
192
|
+
if (!(size > 0))
|
|
193
|
+
throw new Error(`collide: slideTiles needs a positive cellSize, got ${size}`);
|
|
194
|
+
ox = tiles.origin?.[0] ?? 0;
|
|
195
|
+
oy = tiles.origin?.[1] ?? 0;
|
|
196
|
+
oneWay = opts.oneWay ?? true;
|
|
197
|
+
movers = opts.movers ?? NO_MOVERS;
|
|
198
|
+
const stepUp = opts.stepUp ?? 0;
|
|
199
|
+
const { w, h } = box;
|
|
200
|
+
const wasGrounded = out.onGround;
|
|
201
|
+
out.x = box.x;
|
|
202
|
+
out.y = box.y;
|
|
203
|
+
out.onGround = false;
|
|
204
|
+
out.hitCeiling = false;
|
|
205
|
+
out.hitWall = false;
|
|
206
|
+
out.riding = -1;
|
|
207
|
+
// The carry: moves with the platform, still blocked by walls (the platform itself skipped by
|
|
208
|
+
// standing on it, as `resolveX` ignores a top contact).
|
|
209
|
+
const cx = out.carried.dx;
|
|
210
|
+
const cy = out.carried.dy;
|
|
211
|
+
out.carried.dx = 0;
|
|
212
|
+
out.carried.dy = 0;
|
|
213
|
+
if (cx !== 0 || cy !== 0) {
|
|
214
|
+
out.x += cx;
|
|
215
|
+
out.y += cy;
|
|
216
|
+
resolveX(out, w, h, cx, 0, false);
|
|
217
|
+
if (cy < 0) {
|
|
218
|
+
// Lifted: a ceiling stops it.
|
|
219
|
+
const r = Math.floor((out.y + EPS - oy) / size);
|
|
220
|
+
const l = Math.floor((out.x + EPS - ox) / size);
|
|
221
|
+
const rr = Math.floor((out.x + w - EPS - ox) / size);
|
|
222
|
+
for (let c = l; c <= rr; c++) {
|
|
223
|
+
if (kind(c, r) === TILE_SOLID) {
|
|
224
|
+
out.y = oy + (r + 1) * size;
|
|
225
|
+
out.hitCeiling = true;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const steps = Math.max(1, Math.ceil(Math.max(Math.abs(dx), Math.abs(dy)) / (size / 2)));
|
|
232
|
+
const sx = dx / steps;
|
|
233
|
+
const sy = dy / steps;
|
|
234
|
+
let grounded = wasGrounded || cx !== 0 || cy !== 0;
|
|
235
|
+
for (let i = 0; i < steps; i++) {
|
|
236
|
+
if (sx !== 0 && !out.hitWall) {
|
|
237
|
+
out.x += sx;
|
|
238
|
+
if (resolveX(out, w, h, sx, stepUp, grounded))
|
|
239
|
+
out.hitWall = true;
|
|
240
|
+
}
|
|
241
|
+
if (sy !== 0 && !(out.onGround && sy > 0) && !(out.hitCeiling && sy < 0)) {
|
|
242
|
+
out.y += sy;
|
|
243
|
+
resolveY(out, w, h, sy);
|
|
244
|
+
if (out.onGround)
|
|
245
|
+
grounded = true;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (!out.onGround && dy >= 0)
|
|
249
|
+
probeGround(out, w, h);
|
|
250
|
+
out.dx = out.x - box.x;
|
|
251
|
+
out.dy = out.y - box.y;
|
|
252
|
+
grid = null;
|
|
253
|
+
movers = NO_MOVERS;
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Geometry`: vertices and indices in the engine's 3D vertex layout, with a bounding sphere.
|
|
3
|
+
* A `Geometry` is a `MeshDesc`, so `renderer.createMesh(geometry)` takes it as-is.
|
|
4
|
+
*
|
|
5
|
+
* Pure arithmetic over flat typed arrays; the only `render/` dependency is types and the layout
|
|
6
|
+
* constant. Builders size their arrays up front, so nothing grows while writing; indices are
|
|
7
|
+
* `Uint16Array` while every vertex index fits (vertex count ≤ 65535) and `Uint32Array` past that.
|
|
8
|
+
*/
|
|
9
|
+
import { type MeshBounds, type VertexLayout } from '../render/mesh.js';
|
|
10
|
+
/** `[r, g, b, a]`, 0..1. */
|
|
11
|
+
export type Rgba = [number, number, number, number];
|
|
12
|
+
/**
|
|
13
|
+
* Indexed triangles in `layout` (`VERTEX_LAYOUT_3D` from every builder: xyz, normal xyz, uv,
|
|
14
|
+
* rgba = 12 floats), with a bounding sphere. Structurally a `MeshDesc`.
|
|
15
|
+
*/
|
|
16
|
+
export interface Geometry {
|
|
17
|
+
vertices: Float32Array;
|
|
18
|
+
indices: Uint16Array | Uint32Array;
|
|
19
|
+
/** Bounding sphere: the centre of the positions' box, the radius the farthest vertex from it. */
|
|
20
|
+
bounds: MeshBounds;
|
|
21
|
+
layout: VertexLayout;
|
|
22
|
+
}
|
|
23
|
+
/** Options every builder shares. */
|
|
24
|
+
export interface GeometryOptions {
|
|
25
|
+
/** Vertex colour of every vertex. Default white `[1, 1, 1, 1]`. */
|
|
26
|
+
color?: Rgba;
|
|
27
|
+
/** Multiplies every uv: one number for both axes or `[u, v]`. Default 1. */
|
|
28
|
+
uvScale?: number | [number, number];
|
|
29
|
+
}
|
|
30
|
+
/** Vertices above which a geometry's indices are `Uint32Array` (`0xffff` is the last uint16). */
|
|
31
|
+
export declare const UINT16_MAX_VERTICES = 65535;
|
|
32
|
+
/** Floats per vertex in every builder's output (`VERTEX_LAYOUT_3D.floats`). */
|
|
33
|
+
export declare const GEOMETRY_FLOATS: number;
|
|
34
|
+
/**
|
|
35
|
+
* A deep copy of `g`: new `vertices`, `indices` (the same array type) and `bounds`; the `layout`
|
|
36
|
+
* (compared by identity) is shared. Every lane is copied as it is, so the copy can go to
|
|
37
|
+
* `transformGeometry` or any in-place operation and leave `g` alone.
|
|
38
|
+
*/
|
|
39
|
+
export declare function cloneGeometry(g: Geometry): Geometry;
|
|
40
|
+
/** The index array type for `vertexCount` vertices. */
|
|
41
|
+
export declare function createIndices(vertexCount: number, indexCount: number): Uint16Array | Uint32Array;
|
|
42
|
+
/**
|
|
43
|
+
* Sequential writer the builders share: `vertices` and `indices` are sized at construction and
|
|
44
|
+
* filled by `vertex(...)` and `tri(...)`/`quad(...)`; `finish()` checks the counts and computes the
|
|
45
|
+
* bounds. Colour and uv scale come from the options.
|
|
46
|
+
*/
|
|
47
|
+
export declare class GeometryWriter {
|
|
48
|
+
readonly vertices: Float32Array;
|
|
49
|
+
readonly indices: Uint16Array | Uint32Array;
|
|
50
|
+
/** Vertices written so far (the index the next `vertex` gets). */
|
|
51
|
+
count: number;
|
|
52
|
+
private i;
|
|
53
|
+
private readonly r;
|
|
54
|
+
private readonly g;
|
|
55
|
+
private readonly b;
|
|
56
|
+
private readonly a;
|
|
57
|
+
private readonly us;
|
|
58
|
+
private readonly vs;
|
|
59
|
+
constructor(vertexCount: number, indexCount: number, opts?: GeometryOptions);
|
|
60
|
+
/** Append one vertex; returns its index. The normal is stored as given (normalise first). */
|
|
61
|
+
vertex(x: number, y: number, z: number, nx: number, ny: number, nz: number, u: number, v: number): number;
|
|
62
|
+
/** Append one triangle (counter-clockwise seen from the front). */
|
|
63
|
+
tri(a: number, b: number, c: number): void;
|
|
64
|
+
/** Append a quad `a b c d` (counter-clockwise) as two triangles. */
|
|
65
|
+
quad(a: number, b: number, c: number, d: number): void;
|
|
66
|
+
/** The finished geometry; throws if a count does not match what was reserved. */
|
|
67
|
+
finish(): Geometry;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Bounding sphere of the positions in `vertices` (xyz first, `floats` per vertex; the 3D layout's
|
|
71
|
+
* 12 by default): the centre of their axis-aligned box and the distance to the farthest one, the
|
|
72
|
+
* same rule `Mesh` uses for `autoBounds`. Writes `out` when given.
|
|
73
|
+
*/
|
|
74
|
+
export declare function computeBounds(vertices: Float32Array, floats?: number, out?: MeshBounds): MeshBounds;
|
|
75
|
+
/**
|
|
76
|
+
* One geometry from several: vertices concatenated, indices offset by the vertices before them,
|
|
77
|
+
* promoted to `Uint32Array` when the total passes 65535 vertices, bounds recomputed (for any
|
|
78
|
+
* layout with an xyz position at float 0; any other is left unbounded). Every input must share
|
|
79
|
+
* one layout (the first's); the inputs are left untouched. No inputs give an empty geometry in
|
|
80
|
+
* `VERTEX_LAYOUT_3D`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function mergeGeometry(...parts: Geometry[]): Geometry;
|
|
83
|
+
/**
|
|
84
|
+
* Transform `g` in place by a 3×4 row-major world matrix (`Transform.world`,
|
|
85
|
+
* `MATRIX3X4_FLOATS`): positions by the full matrix, normals by the inverse transpose of its
|
|
86
|
+
* 3×3 part (so non-uniform scale keeps them perpendicular), renormalised. The bounds are
|
|
87
|
+
* recomputed. Returns `g`. A singular 3×3 (a zero scale) leaves the normals as they were. The
|
|
88
|
+
* geometry is in any layout whose position is an xyz at float 0 (`VERTEX_LAYOUT_3D`,
|
|
89
|
+
* `VERTEX_LAYOUT_3D_TANGENT`, `VERTEX_LAYOUT_SKINNED` or a custom layout on the same locations);
|
|
90
|
+
* the normal (`@location(10)`) and tangent (`@location(13)`) lanes are found from the layout. A
|
|
91
|
+
* tangent's xyz is rotated by the 3×3 part (renormalised) and its w (handedness) is kept,
|
|
92
|
+
* flipped when the matrix mirrors (negative determinant) so the bitangent stays
|
|
93
|
+
* `w · cross(n, t)`. Other lanes are left as they are.
|
|
94
|
+
*/
|
|
95
|
+
export declare function transformGeometry(g: Geometry, world: ArrayLike<number>): Geometry;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Geometry`: vertices and indices in the engine's 3D vertex layout, with a bounding sphere.
|
|
3
|
+
* A `Geometry` is a `MeshDesc`, so `renderer.createMesh(geometry)` takes it as-is.
|
|
4
|
+
*
|
|
5
|
+
* Pure arithmetic over flat typed arrays; the only `render/` dependency is types and the layout
|
|
6
|
+
* constant. Builders size their arrays up front, so nothing grows while writing; indices are
|
|
7
|
+
* `Uint16Array` while every vertex index fits (vertex count ≤ 65535) and `Uint32Array` past that.
|
|
8
|
+
*/
|
|
9
|
+
import { VERTEX_LAYOUT_3D } from '../render/mesh.js';
|
|
10
|
+
/** Vertices above which a geometry's indices are `Uint32Array` (`0xffff` is the last uint16). */
|
|
11
|
+
export const UINT16_MAX_VERTICES = 0xffff;
|
|
12
|
+
/** Floats per vertex in every builder's output (`VERTEX_LAYOUT_3D.floats`). */
|
|
13
|
+
export const GEOMETRY_FLOATS = VERTEX_LAYOUT_3D.floats;
|
|
14
|
+
const LANES = new WeakMap();
|
|
15
|
+
function lanesOf(layout) {
|
|
16
|
+
let lanes = LANES.get(layout);
|
|
17
|
+
if (lanes)
|
|
18
|
+
return lanes;
|
|
19
|
+
lanes = { position: -1, normal: -1, tangent: -1 };
|
|
20
|
+
for (const a of layout.buffer?.attributes ?? []) {
|
|
21
|
+
const at = a.offset / 4;
|
|
22
|
+
if (a.shaderLocation === 0 && a.format === 'float32x3')
|
|
23
|
+
lanes.position = at;
|
|
24
|
+
else if (a.shaderLocation === 10 && a.format === 'float32x3')
|
|
25
|
+
lanes.normal = at;
|
|
26
|
+
else if (a.shaderLocation === 13 && a.format === 'float32x4')
|
|
27
|
+
lanes.tangent = at;
|
|
28
|
+
}
|
|
29
|
+
LANES.set(layout, lanes);
|
|
30
|
+
return lanes;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Layouts whose vertices start with an xyz position: the 3D, tangent and skinned layouts, or a
|
|
34
|
+
* custom one built on the same locations.
|
|
35
|
+
*/
|
|
36
|
+
function hasPositions(layout) {
|
|
37
|
+
return lanesOf(layout).position === 0;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A deep copy of `g`: new `vertices`, `indices` (the same array type) and `bounds`; the `layout`
|
|
41
|
+
* (compared by identity) is shared. Every lane is copied as it is, so the copy can go to
|
|
42
|
+
* `transformGeometry` or any in-place operation and leave `g` alone.
|
|
43
|
+
*/
|
|
44
|
+
export function cloneGeometry(g) {
|
|
45
|
+
const c = g.bounds.center;
|
|
46
|
+
return {
|
|
47
|
+
vertices: g.vertices.slice(),
|
|
48
|
+
indices: g.indices.slice(),
|
|
49
|
+
bounds: { center: [c[0], c[1], c[2]], radius: g.bounds.radius },
|
|
50
|
+
layout: g.layout,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** The index array type for `vertexCount` vertices. */
|
|
54
|
+
export function createIndices(vertexCount, indexCount) {
|
|
55
|
+
return vertexCount > UINT16_MAX_VERTICES
|
|
56
|
+
? new Uint32Array(indexCount)
|
|
57
|
+
: new Uint16Array(indexCount);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Sequential writer the builders share: `vertices` and `indices` are sized at construction and
|
|
61
|
+
* filled by `vertex(...)` and `tri(...)`/`quad(...)`; `finish()` checks the counts and computes the
|
|
62
|
+
* bounds. Colour and uv scale come from the options.
|
|
63
|
+
*/
|
|
64
|
+
export class GeometryWriter {
|
|
65
|
+
vertices;
|
|
66
|
+
indices;
|
|
67
|
+
/** Vertices written so far (the index the next `vertex` gets). */
|
|
68
|
+
count = 0;
|
|
69
|
+
i = 0;
|
|
70
|
+
r;
|
|
71
|
+
g;
|
|
72
|
+
b;
|
|
73
|
+
a;
|
|
74
|
+
us;
|
|
75
|
+
vs;
|
|
76
|
+
constructor(vertexCount, indexCount, opts = {}) {
|
|
77
|
+
this.vertices = new Float32Array(vertexCount * GEOMETRY_FLOATS);
|
|
78
|
+
this.indices = createIndices(vertexCount, indexCount);
|
|
79
|
+
const c = opts.color ?? WHITE;
|
|
80
|
+
this.r = c[0];
|
|
81
|
+
this.g = c[1];
|
|
82
|
+
this.b = c[2];
|
|
83
|
+
this.a = c[3];
|
|
84
|
+
const s = opts.uvScale ?? 1;
|
|
85
|
+
this.us = typeof s === 'number' ? s : s[0];
|
|
86
|
+
this.vs = typeof s === 'number' ? s : s[1];
|
|
87
|
+
}
|
|
88
|
+
/** Append one vertex; returns its index. The normal is stored as given (normalise first). */
|
|
89
|
+
vertex(x, y, z, nx, ny, nz, u, v) {
|
|
90
|
+
const o = this.count * GEOMETRY_FLOATS;
|
|
91
|
+
const out = this.vertices;
|
|
92
|
+
out[o] = x;
|
|
93
|
+
out[o + 1] = y;
|
|
94
|
+
out[o + 2] = z;
|
|
95
|
+
out[o + 3] = nx;
|
|
96
|
+
out[o + 4] = ny;
|
|
97
|
+
out[o + 5] = nz;
|
|
98
|
+
out[o + 6] = u * this.us;
|
|
99
|
+
out[o + 7] = v * this.vs;
|
|
100
|
+
out[o + 8] = this.r;
|
|
101
|
+
out[o + 9] = this.g;
|
|
102
|
+
out[o + 10] = this.b;
|
|
103
|
+
out[o + 11] = this.a;
|
|
104
|
+
return this.count++;
|
|
105
|
+
}
|
|
106
|
+
/** Append one triangle (counter-clockwise seen from the front). */
|
|
107
|
+
tri(a, b, c) {
|
|
108
|
+
const out = this.indices;
|
|
109
|
+
out[this.i++] = a;
|
|
110
|
+
out[this.i++] = b;
|
|
111
|
+
out[this.i++] = c;
|
|
112
|
+
}
|
|
113
|
+
/** Append a quad `a b c d` (counter-clockwise) as two triangles. */
|
|
114
|
+
quad(a, b, c, d) {
|
|
115
|
+
this.tri(a, b, c);
|
|
116
|
+
this.tri(a, c, d);
|
|
117
|
+
}
|
|
118
|
+
/** The finished geometry; throws if a count does not match what was reserved. */
|
|
119
|
+
finish() {
|
|
120
|
+
if (this.count * GEOMETRY_FLOATS !== this.vertices.length) {
|
|
121
|
+
throw new Error(`geom: wrote ${this.count} of ${this.vertices.length / GEOMETRY_FLOATS} vertices`);
|
|
122
|
+
}
|
|
123
|
+
if (this.i !== this.indices.length) {
|
|
124
|
+
throw new Error(`geom: wrote ${this.i} of ${this.indices.length} indices`);
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
vertices: this.vertices,
|
|
128
|
+
indices: this.indices,
|
|
129
|
+
bounds: computeBounds(this.vertices),
|
|
130
|
+
layout: VERTEX_LAYOUT_3D,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const WHITE = [1, 1, 1, 1];
|
|
135
|
+
/**
|
|
136
|
+
* Bounding sphere of the positions in `vertices` (xyz first, `floats` per vertex; the 3D layout's
|
|
137
|
+
* 12 by default): the centre of their axis-aligned box and the distance to the farthest one, the
|
|
138
|
+
* same rule `Mesh` uses for `autoBounds`. Writes `out` when given.
|
|
139
|
+
*/
|
|
140
|
+
export function computeBounds(vertices, floats = GEOMETRY_FLOATS, out = { center: [0, 0, 0], radius: 0 }) {
|
|
141
|
+
const n = vertices.length;
|
|
142
|
+
if (n === 0) {
|
|
143
|
+
out.center[0] = out.center[1] = out.center[2] = 0;
|
|
144
|
+
out.radius = 0;
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
let minX = Number.POSITIVE_INFINITY;
|
|
148
|
+
let minY = Number.POSITIVE_INFINITY;
|
|
149
|
+
let minZ = Number.POSITIVE_INFINITY;
|
|
150
|
+
let maxX = Number.NEGATIVE_INFINITY;
|
|
151
|
+
let maxY = Number.NEGATIVE_INFINITY;
|
|
152
|
+
let maxZ = Number.NEGATIVE_INFINITY;
|
|
153
|
+
for (let o = 0; o < n; o += floats) {
|
|
154
|
+
const x = vertices[o];
|
|
155
|
+
const y = vertices[o + 1];
|
|
156
|
+
const z = vertices[o + 2];
|
|
157
|
+
if (x < minX)
|
|
158
|
+
minX = x;
|
|
159
|
+
if (x > maxX)
|
|
160
|
+
maxX = x;
|
|
161
|
+
if (y < minY)
|
|
162
|
+
minY = y;
|
|
163
|
+
if (y > maxY)
|
|
164
|
+
maxY = y;
|
|
165
|
+
if (z < minZ)
|
|
166
|
+
minZ = z;
|
|
167
|
+
if (z > maxZ)
|
|
168
|
+
maxZ = z;
|
|
169
|
+
}
|
|
170
|
+
const cx = (minX + maxX) / 2;
|
|
171
|
+
const cy = (minY + maxY) / 2;
|
|
172
|
+
const cz = (minZ + maxZ) / 2;
|
|
173
|
+
let r2 = 0;
|
|
174
|
+
for (let o = 0; o < n; o += floats) {
|
|
175
|
+
const dx = vertices[o] - cx;
|
|
176
|
+
const dy = vertices[o + 1] - cy;
|
|
177
|
+
const dz = vertices[o + 2] - cz;
|
|
178
|
+
const d = dx * dx + dy * dy + dz * dz;
|
|
179
|
+
if (d > r2)
|
|
180
|
+
r2 = d;
|
|
181
|
+
}
|
|
182
|
+
out.center[0] = cx;
|
|
183
|
+
out.center[1] = cy;
|
|
184
|
+
out.center[2] = cz;
|
|
185
|
+
out.radius = Math.sqrt(r2);
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* One geometry from several: vertices concatenated, indices offset by the vertices before them,
|
|
190
|
+
* promoted to `Uint32Array` when the total passes 65535 vertices, bounds recomputed (for any
|
|
191
|
+
* layout with an xyz position at float 0; any other is left unbounded). Every input must share
|
|
192
|
+
* one layout (the first's); the inputs are left untouched. No inputs give an empty geometry in
|
|
193
|
+
* `VERTEX_LAYOUT_3D`.
|
|
194
|
+
*/
|
|
195
|
+
export function mergeGeometry(...parts) {
|
|
196
|
+
const layout = parts[0]?.layout ?? VERTEX_LAYOUT_3D;
|
|
197
|
+
const floats = layout.floats;
|
|
198
|
+
let vTotal = 0;
|
|
199
|
+
let iTotal = 0;
|
|
200
|
+
for (const p of parts) {
|
|
201
|
+
if (p.layout !== layout) {
|
|
202
|
+
throw new Error(`geom: mergeGeometry mixes layouts '${layout.name}' and '${p.layout.name}'`);
|
|
203
|
+
}
|
|
204
|
+
vTotal += p.vertices.length / floats;
|
|
205
|
+
iTotal += p.indices.length;
|
|
206
|
+
}
|
|
207
|
+
const vertices = new Float32Array(vTotal * floats);
|
|
208
|
+
const indices = createIndices(vTotal, iTotal);
|
|
209
|
+
let vo = 0;
|
|
210
|
+
let io = 0;
|
|
211
|
+
let base = 0;
|
|
212
|
+
for (const p of parts) {
|
|
213
|
+
vertices.set(p.vertices, vo);
|
|
214
|
+
vo += p.vertices.length;
|
|
215
|
+
const src = p.indices;
|
|
216
|
+
for (let k = 0; k < src.length; k++)
|
|
217
|
+
indices[io + k] = src[k] + base;
|
|
218
|
+
io += src.length;
|
|
219
|
+
base += p.vertices.length / floats;
|
|
220
|
+
}
|
|
221
|
+
// Only layouts with an xyz position at float 0 can be bounded; any other is left unbounded
|
|
222
|
+
// (never culled).
|
|
223
|
+
const bounds = hasPositions(layout)
|
|
224
|
+
? computeBounds(vertices, floats)
|
|
225
|
+
: { center: [0, 0, 0], radius: Number.POSITIVE_INFINITY };
|
|
226
|
+
return { vertices, indices, bounds, layout };
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Transform `g` in place by a 3×4 row-major world matrix (`Transform.world`,
|
|
230
|
+
* `MATRIX3X4_FLOATS`): positions by the full matrix, normals by the inverse transpose of its
|
|
231
|
+
* 3×3 part (so non-uniform scale keeps them perpendicular), renormalised. The bounds are
|
|
232
|
+
* recomputed. Returns `g`. A singular 3×3 (a zero scale) leaves the normals as they were. The
|
|
233
|
+
* geometry is in any layout whose position is an xyz at float 0 (`VERTEX_LAYOUT_3D`,
|
|
234
|
+
* `VERTEX_LAYOUT_3D_TANGENT`, `VERTEX_LAYOUT_SKINNED` or a custom layout on the same locations);
|
|
235
|
+
* the normal (`@location(10)`) and tangent (`@location(13)`) lanes are found from the layout. A
|
|
236
|
+
* tangent's xyz is rotated by the 3×3 part (renormalised) and its w (handedness) is kept,
|
|
237
|
+
* flipped when the matrix mirrors (negative determinant) so the bitangent stays
|
|
238
|
+
* `w · cross(n, t)`. Other lanes are left as they are.
|
|
239
|
+
*/
|
|
240
|
+
export function transformGeometry(g, world) {
|
|
241
|
+
if (!hasPositions(g.layout)) {
|
|
242
|
+
throw new Error(`geom: transformGeometry needs an xyz position at float 0 (VERTEX_LAYOUT_3D or VERTEX_LAYOUT_3D_TANGENT), got '${g.layout.name}'`);
|
|
243
|
+
}
|
|
244
|
+
const floats = g.layout.floats;
|
|
245
|
+
const lanes = lanesOf(g.layout);
|
|
246
|
+
const tangents = lanes.tangent >= 0;
|
|
247
|
+
const to = lanes.tangent;
|
|
248
|
+
const no = lanes.normal;
|
|
249
|
+
const m00 = world[0];
|
|
250
|
+
const m01 = world[1];
|
|
251
|
+
const m02 = world[2];
|
|
252
|
+
const tx = world[3];
|
|
253
|
+
const m10 = world[4];
|
|
254
|
+
const m11 = world[5];
|
|
255
|
+
const m12 = world[6];
|
|
256
|
+
const ty = world[7];
|
|
257
|
+
const m20 = world[8];
|
|
258
|
+
const m21 = world[9];
|
|
259
|
+
const m22 = world[10];
|
|
260
|
+
const tz = world[11];
|
|
261
|
+
// Inverse transpose of the 3×3: cofactors / det, laid out transposed.
|
|
262
|
+
const c00 = m11 * m22 - m12 * m21;
|
|
263
|
+
const c01 = m12 * m20 - m10 * m22;
|
|
264
|
+
const c02 = m10 * m21 - m11 * m20;
|
|
265
|
+
const c10 = m02 * m21 - m01 * m22;
|
|
266
|
+
const c11 = m00 * m22 - m02 * m20;
|
|
267
|
+
const c12 = m01 * m20 - m00 * m21;
|
|
268
|
+
const c20 = m01 * m12 - m02 * m11;
|
|
269
|
+
const c21 = m02 * m10 - m00 * m12;
|
|
270
|
+
const c22 = m00 * m11 - m01 * m10;
|
|
271
|
+
const det = m00 * c00 + m01 * c01 + m02 * c02;
|
|
272
|
+
const singular = Math.abs(det) < 1e-20;
|
|
273
|
+
const v = g.vertices;
|
|
274
|
+
for (let o = 0; o < v.length; o += floats) {
|
|
275
|
+
const x = v[o];
|
|
276
|
+
const y = v[o + 1];
|
|
277
|
+
const z = v[o + 2];
|
|
278
|
+
v[o] = m00 * x + m01 * y + m02 * z + tx;
|
|
279
|
+
v[o + 1] = m10 * x + m11 * y + m12 * z + ty;
|
|
280
|
+
v[o + 2] = m20 * x + m21 * y + m22 * z + tz;
|
|
281
|
+
if (tangents) {
|
|
282
|
+
const t = o + to;
|
|
283
|
+
const ux = v[t];
|
|
284
|
+
const uy = v[t + 1];
|
|
285
|
+
const uz = v[t + 2];
|
|
286
|
+
const wx = m00 * ux + m01 * uy + m02 * uz;
|
|
287
|
+
const wy = m10 * ux + m11 * uy + m12 * uz;
|
|
288
|
+
const wz = m20 * ux + m21 * uy + m22 * uz;
|
|
289
|
+
const tl = Math.hypot(wx, wy, wz);
|
|
290
|
+
if (tl > 0) {
|
|
291
|
+
v[t] = wx / tl;
|
|
292
|
+
v[t + 1] = wy / tl;
|
|
293
|
+
v[t + 2] = wz / tl;
|
|
294
|
+
}
|
|
295
|
+
if (det < 0)
|
|
296
|
+
v[t + 3] = -v[t + 3];
|
|
297
|
+
}
|
|
298
|
+
if (singular || no < 0)
|
|
299
|
+
continue;
|
|
300
|
+
const n = o + no;
|
|
301
|
+
const nx = v[n];
|
|
302
|
+
const ny = v[n + 1];
|
|
303
|
+
const nz = v[n + 2];
|
|
304
|
+
// n' = (M^-1)^T n = cofactor matrix · n (the 1/det cancels in the normalisation, up to sign).
|
|
305
|
+
let rx = c00 * nx + c01 * ny + c02 * nz;
|
|
306
|
+
let ry = c10 * nx + c11 * ny + c12 * nz;
|
|
307
|
+
let rz = c20 * nx + c21 * ny + c22 * nz;
|
|
308
|
+
if (det < 0) {
|
|
309
|
+
rx = -rx;
|
|
310
|
+
ry = -ry;
|
|
311
|
+
rz = -rz;
|
|
312
|
+
}
|
|
313
|
+
const len = Math.hypot(rx, ry, rz);
|
|
314
|
+
if (len > 0) {
|
|
315
|
+
v[n] = rx / len;
|
|
316
|
+
v[n + 1] = ry / len;
|
|
317
|
+
v[n + 2] = rz / len;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
computeBounds(v, floats, g.bounds);
|
|
321
|
+
return g;
|
|
322
|
+
}
|