create-threenative 0.2.7 → 0.2.9
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/README.md +3 -1
- package/agent-docs/references/assertion-reference.md +87 -35
- package/agent-docs/references/auto-exposure.md +57 -0
- package/agent-docs/references/capability-reference.md +1306 -62
- package/agent-docs/references/debug-surface.md +6 -0
- package/agent-docs/references/finding-assets.md +46 -10
- package/agent-docs/references/performance-basics.md +5 -4
- package/agent-docs/references/terrain-authoring.md +140 -0
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +2 -1
- package/capabilities.json +1505 -79
- package/dist/index.d.ts +28 -3
- package/dist/index.js +402 -167
- package/dist/threenative.js +989 -237
- package/dist/web-engine-buffer-geometry-utils.js +281 -0
- package/dist/web-engine-decal-geometry.js +184 -0
- package/dist/web-engine-gltf-loader.js +196 -0
- package/dist/web-engine-hdr-loader.js +190 -0
- package/dist/web-engine-lut-cube-loader.js +122 -0
- package/dist/web-engine-mesh-bvh-webgpu.js +29 -0
- package/dist/web-engine-mesh-bvh.js +32 -0
- package/dist/web-engine-post-effects.js +168 -0
- package/dist/web-engine-runtime.js +42506 -0
- package/package.json +11 -8
- package/template-assets/autoExposure.ts +225 -0
- package/template-assets/exposure.ts +111 -0
- package/template-assets/exposureGraph.ts +178 -0
- package/template-assets/exposureReadback.ts +79 -0
- package/template-assets/patches/@tailwindcss__node@4.3.3.patch +22 -0
- package/template-assets/patches/three@0.185.1.patch +6594 -700
- package/template-assets/patches/vite@8.2.0.patch +422 -0
- package/template-assets/worldEnvironment.ts +433 -30
- package/templates/action-rpg/AGENTS.md +11 -10
- package/templates/action-rpg/CLAUDE.md +11 -10
- package/templates/action-rpg/package.json +11 -9
- package/templates/action-rpg/playtests/performance.playtest.json +7 -1
- package/templates/action-rpg/src/progress.ts +0 -4
- package/templates/action-rpg/src/render/autoExposure.ts +225 -0
- package/templates/action-rpg/src/render/backlightControls.ts +66 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +147 -0
- package/templates/action-rpg/src/render/environmentContribution.ts +188 -0
- package/templates/action-rpg/src/render/environmentRadiance.ts +36 -0
- package/templates/action-rpg/src/render/environmentSampleCache.ts +43 -0
- package/templates/action-rpg/src/render/environmentSampling.ts +193 -0
- package/templates/action-rpg/src/render/environmentSnapshot.ts +53 -0
- package/templates/action-rpg/src/render/exposure.ts +111 -0
- package/templates/action-rpg/src/render/exposureGraph.ts +178 -0
- package/templates/action-rpg/src/render/exposureReadback.ts +79 -0
- package/templates/action-rpg/src/render/heightFog.ts +118 -0
- package/templates/action-rpg/src/render/lighting.ts +26 -1
- package/templates/action-rpg/src/render/materialAssignments.ts +160 -0
- package/templates/action-rpg/src/render/materialLighting.ts +155 -0
- package/templates/action-rpg/src/render/postprocessing.ts +17 -2
- package/templates/action-rpg/src/render/quality.ts +61 -2
- package/templates/action-rpg/src/render/sky.ts +21 -1
- package/templates/action-rpg/src/render/vfx.ts +133 -58
- package/templates/action-rpg/src/render/worldEnvironment.ts +433 -30
- package/templates/action-rpg/src/scenes/Play.ts +81 -16
- package/templates/action-rpg/threenative.config.ts +3 -0
- package/templates/action-rpg/vite.config.ts +10 -2
- package/templates/minimal/AGENTS.md +9 -10
- package/templates/minimal/CLAUDE.md +9 -10
- package/templates/minimal/package.json +9 -8
- package/templates/minimal/playtests/play.playtest.json +7 -1
- package/templates/minimal/playtests/sky.playtest.json +10 -1
- package/templates/minimal/src/render/autoExposure.ts +225 -0
- package/templates/minimal/src/render/backlightControls.ts +66 -0
- package/templates/minimal/src/render/backlightMaterial.ts +147 -0
- package/templates/minimal/src/render/environmentContribution.ts +188 -0
- package/templates/minimal/src/render/environmentRadiance.ts +36 -0
- package/templates/minimal/src/render/environmentSampleCache.ts +43 -0
- package/templates/minimal/src/render/environmentSampling.ts +193 -0
- package/templates/minimal/src/render/environmentSnapshot.ts +53 -0
- package/templates/minimal/src/render/exposure.ts +111 -0
- package/templates/minimal/src/render/exposureGraph.ts +178 -0
- package/templates/minimal/src/render/exposureReadback.ts +79 -0
- package/templates/minimal/src/render/heightFog.ts +118 -0
- package/templates/minimal/src/render/lighting.ts +25 -1
- package/templates/minimal/src/render/materialAssignments.ts +102 -0
- package/templates/minimal/src/render/materialLighting.ts +146 -0
- package/templates/minimal/src/render/postprocessing.ts +16 -2
- package/templates/minimal/src/render/quality.ts +60 -2
- package/templates/minimal/src/render/sky.ts +21 -1
- package/templates/minimal/src/render/worldEnvironment.ts +433 -30
- package/templates/minimal/src/scenes/Play.ts +50 -1
- package/templates/minimal/vite.config.ts +10 -2
- package/templates/platformer/AGENTS.md +7 -5
- package/templates/platformer/CLAUDE.md +7 -5
- package/templates/platformer/package.json +11 -9
- package/templates/platformer/playtests/performance.playtest.json +7 -1
- package/templates/platformer/src/render/autoExposure.ts +225 -0
- package/templates/platformer/src/render/backlightControls.ts +66 -0
- package/templates/platformer/src/render/backlightMaterial.ts +147 -0
- package/templates/platformer/src/render/environmentContribution.ts +188 -0
- package/templates/platformer/src/render/environmentRadiance.ts +36 -0
- package/templates/platformer/src/render/environmentSampleCache.ts +43 -0
- package/templates/platformer/src/render/environmentSampling.ts +193 -0
- package/templates/platformer/src/render/environmentSnapshot.ts +53 -0
- package/templates/platformer/src/render/exposure.ts +111 -0
- package/templates/platformer/src/render/exposureGraph.ts +178 -0
- package/templates/platformer/src/render/exposureReadback.ts +79 -0
- package/templates/platformer/src/render/heightFog.ts +118 -0
- package/templates/platformer/src/render/lighting.ts +26 -1
- package/templates/platformer/src/render/materialAssignments.ts +160 -0
- package/templates/platformer/src/render/materialLighting.ts +155 -0
- package/templates/platformer/src/render/materials.ts +7 -2
- package/templates/platformer/src/render/palette.ts +3 -3
- package/templates/platformer/src/render/postprocessing.ts +17 -2
- package/templates/platformer/src/render/quality.ts +61 -2
- package/templates/platformer/src/render/sky.ts +72 -23
- package/templates/platformer/src/render/skyEnvironment.ts +50 -0
- package/templates/platformer/src/render/worldEnvironment.ts +433 -30
- package/templates/platformer/src/scenes/Play.ts +70 -6
- package/templates/platformer/vite.config.ts +10 -2
- package/templates/puzzle/AGENTS.md +10 -9
- package/templates/puzzle/CLAUDE.md +10 -9
- package/templates/puzzle/package.json +11 -9
- package/templates/puzzle/playtests/boot-failure.playtest.json +2 -2
- package/templates/puzzle/playtests/lit.playtest.json +7 -1
- package/templates/puzzle/playtests/performance.playtest.json +7 -1
- package/templates/puzzle/src/render/autoExposure.ts +225 -0
- package/templates/puzzle/src/render/backlightControls.ts +66 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +147 -0
- package/templates/puzzle/src/render/environmentContribution.ts +188 -0
- package/templates/puzzle/src/render/environmentRadiance.ts +36 -0
- package/templates/puzzle/src/render/environmentSampleCache.ts +43 -0
- package/templates/puzzle/src/render/environmentSampling.ts +193 -0
- package/templates/puzzle/src/render/environmentSnapshot.ts +53 -0
- package/templates/puzzle/src/render/exposure.ts +111 -0
- package/templates/puzzle/src/render/exposureGraph.ts +178 -0
- package/templates/puzzle/src/render/exposureReadback.ts +79 -0
- package/templates/puzzle/src/render/heightFog.ts +118 -0
- package/templates/puzzle/src/render/lighting.ts +33 -1
- package/templates/puzzle/src/render/materialAssignments.ts +160 -0
- package/templates/puzzle/src/render/materialLighting.ts +155 -0
- package/templates/puzzle/src/render/materials.ts +1 -1
- package/templates/puzzle/src/render/postprocessing.ts +8 -2
- package/templates/puzzle/src/render/quality.ts +62 -1
- package/templates/puzzle/src/render/sky.ts +20 -1
- package/templates/puzzle/src/render/worldEnvironment.ts +433 -30
- package/templates/puzzle/src/scenes/Play.ts +51 -2
- package/templates/puzzle/vite.config.ts +10 -2
- package/templates/racing/AGENTS.md +8 -7
- package/templates/racing/CLAUDE.md +8 -7
- package/templates/racing/package.json +11 -9
- package/templates/racing/playtests/performance.playtest.json +7 -1
- package/templates/racing/playtests/survives.playtest.json +6 -0
- package/templates/racing/src/render/autoExposure.ts +225 -0
- package/templates/racing/src/render/backlightControls.ts +66 -0
- package/templates/racing/src/render/backlightMaterial.ts +147 -0
- package/templates/racing/src/render/environmentContribution.ts +188 -0
- package/templates/racing/src/render/environmentRadiance.ts +36 -0
- package/templates/racing/src/render/environmentSampleCache.ts +43 -0
- package/templates/racing/src/render/environmentSampling.ts +193 -0
- package/templates/racing/src/render/environmentSnapshot.ts +53 -0
- package/templates/racing/src/render/exposure.ts +111 -0
- package/templates/racing/src/render/exposureGraph.ts +178 -0
- package/templates/racing/src/render/exposureReadback.ts +79 -0
- package/templates/racing/src/render/heightFog.ts +118 -0
- package/templates/racing/src/render/lighting.ts +29 -1
- package/templates/racing/src/render/materialAssignments.ts +160 -0
- package/templates/racing/src/render/materialLighting.ts +155 -0
- package/templates/racing/src/render/palette.ts +1 -10
- package/templates/racing/src/render/postprocessing.ts +17 -2
- package/templates/racing/src/render/quality.ts +61 -2
- package/templates/racing/src/render/shapes.ts +0 -25
- package/templates/racing/src/render/sky.ts +21 -1
- package/templates/racing/src/render/worldEnvironment.ts +433 -30
- package/templates/racing/src/scenes/Race.ts +91 -3
- package/templates/racing/src/track/circuit.ts +0 -9
- package/templates/racing/vite.config.ts +10 -2
- package/templates/rain/.codex/config.toml +19 -0
- package/templates/rain/.cursor/mcp.json +32 -0
- package/templates/rain/.gemini/settings.json +32 -0
- package/templates/rain/.mcp.json +32 -0
- package/templates/rain/.vscode/mcp.json +36 -0
- package/templates/rain/.zed/settings.json +36 -0
- package/templates/rain/AGENTS.md +95 -0
- package/templates/rain/CLAUDE.md +97 -0
- package/templates/rain/assets/rain-loop.wav +0 -0
- package/templates/rain/assets/thunder.wav +0 -0
- package/templates/rain/assets/wind-loop.wav +0 -0
- package/templates/rain/index.html +18 -0
- package/templates/rain/kit.json +7 -0
- package/templates/rain/native-playtests/boot.playtest.json +23 -0
- package/templates/rain/native-playtests/lightning.playtest.json +173 -0
- package/templates/rain/opencode.json +41 -0
- package/templates/rain/package.json +59 -0
- package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
- package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
- package/templates/rain/playtests/automation.playtest.json +133 -0
- package/templates/rain/playtests/cinematic.playtest.json +59 -0
- package/templates/rain/playtests/flash.playtest.json +27 -0
- package/templates/rain/playtests/fly.playtest.json +54 -0
- package/templates/rain/playtests/lightning.playtest.json +220 -0
- package/templates/rain/playtests/loading.playtest.json +57 -0
- package/templates/rain/playtests/paused.playtest.json +59 -0
- package/templates/rain/playtests/performance.playtest.json +32 -0
- package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
- package/templates/rain/playtests/simulation.playtest.json +20 -0
- package/templates/rain/playtests/storm.playtest.json +150 -0
- package/templates/rain/playtests/survives.playtest.json +58 -0
- package/templates/rain/playtests/tiers.playtest.json +194 -0
- package/templates/rain/playtests/weather.playtest.json +77 -0
- package/templates/rain/public/favicon.svg +5 -0
- package/templates/rain/src/audio/storm.ts +314 -0
- package/templates/rain/src/game.ts +81 -0
- package/templates/rain/src/main.ts +15 -0
- package/templates/rain/src/render/autoExposure.ts +225 -0
- package/templates/rain/src/render/bloom-shader.ts +65 -0
- package/templates/rain/src/render/camera.ts +160 -0
- package/templates/rain/src/render/clouds-shader.ts +242 -0
- package/templates/rain/src/render/clouds.ts +142 -0
- package/templates/rain/src/render/exposure.ts +111 -0
- package/templates/rain/src/render/exposureGraph.ts +178 -0
- package/templates/rain/src/render/exposureReadback.ts +79 -0
- package/templates/rain/src/render/lighting.ts +39 -0
- package/templates/rain/src/render/lightning.ts +360 -0
- package/templates/rain/src/render/loading.ts +327 -0
- package/templates/rain/src/render/materials.ts +19 -0
- package/templates/rain/src/render/noise-volume.ts +159 -0
- package/templates/rain/src/render/palette.ts +18 -0
- package/templates/rain/src/render/post-shader.ts +178 -0
- package/templates/rain/src/render/postprocessing.ts +229 -0
- package/templates/rain/src/render/quality.ts +161 -0
- package/templates/rain/src/render/rain.ts +299 -0
- package/templates/rain/src/render/sky.ts +28 -0
- package/templates/rain/src/render/world-shader.ts +680 -0
- package/templates/rain/src/render/world.ts +146 -0
- package/templates/rain/src/render/worldEnvironment.ts +1212 -0
- package/templates/rain/src/scenes/Boot.ts +348 -0
- package/templates/rain/src/state.ts +261 -0
- package/templates/rain/src/style.css +1160 -0
- package/templates/rain/src/ui/App.tsx +29 -0
- package/templates/rain/src/ui/GameUi.tsx +187 -0
- package/templates/rain/src/ui/Hud.tsx +327 -0
- package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
- package/templates/rain/src/ui/Menu.tsx +370 -0
- package/templates/rain/src/ui/automation.ts +60 -0
- package/templates/rain/src/ui/main.tsx +7 -0
- package/templates/rain/src/ui/tempest.ts +149 -0
- package/templates/rain/tailwind.config.ts +2 -0
- package/templates/rain/threenative.config.ts +66 -0
- package/templates/rain/tools/generate-shaders.mjs +656 -0
- package/templates/rain/tools/make-storm-audio.mjs +387 -0
- package/templates/rain/tools/storm-dsp.mjs +177 -0
- package/templates/rain/tools/tempest-bloom.frag +10 -0
- package/templates/rain/tools/tempest-clouds.frag +86 -0
- package/templates/rain/tools/tempest-post.frag +47 -0
- package/templates/rain/tools/tempest-world.frag +210 -0
- package/templates/rain/tools/verify-noise-volume.mjs +61 -0
- package/templates/rain/tsconfig.json +17 -0
- package/templates/rain/vite.config.ts +45 -0
- package/templates/rts/AGENTS.md +10 -11
- package/templates/rts/CLAUDE.md +10 -11
- package/templates/rts/package.json +10 -8
- package/templates/rts/playtests/performance.playtest.json +7 -1
- package/templates/rts/playtests/rts-ai-attack.playtest.json +10 -1
- package/templates/rts/playtests/rts-attack.playtest.json +10 -1
- package/templates/rts/playtests/rts-build.playtest.json +10 -1
- package/templates/rts/playtests/rts-orders.playtest.json +7 -1
- package/templates/rts/playtests/rts-train.playtest.json +10 -1
- package/templates/rts/src/render/army.ts +10 -2
- package/templates/rts/src/render/autoExposure.ts +225 -0
- package/templates/rts/src/render/backlightControls.ts +66 -0
- package/templates/rts/src/render/backlightMaterial.ts +147 -0
- package/templates/rts/src/render/environmentContribution.ts +188 -0
- package/templates/rts/src/render/environmentRadiance.ts +36 -0
- package/templates/rts/src/render/environmentSampleCache.ts +43 -0
- package/templates/rts/src/render/environmentSampling.ts +193 -0
- package/templates/rts/src/render/environmentSnapshot.ts +53 -0
- package/templates/rts/src/render/exposure.ts +111 -0
- package/templates/rts/src/render/exposureGraph.ts +178 -0
- package/templates/rts/src/render/exposureReadback.ts +79 -0
- package/templates/rts/src/render/heightFog.ts +118 -0
- package/templates/rts/src/render/lighting.ts +26 -1
- package/templates/rts/src/render/materialAssignments.ts +160 -0
- package/templates/rts/src/render/materialLighting.ts +155 -0
- package/templates/rts/src/render/postprocessing.ts +8 -2
- package/templates/rts/src/render/quality.ts +61 -2
- package/templates/rts/src/render/sky.ts +21 -1
- package/templates/rts/src/render/worldEnvironment.ts +433 -30
- package/templates/rts/src/scenes/Play.ts +54 -3
- package/templates/rts/src/sim/ai.ts +0 -1
- package/templates/rts/src/sim/terrain.ts +0 -4
- package/templates/rts/vite.config.ts +10 -2
- package/templates/runner/AGENTS.md +10 -8
- package/templates/runner/CLAUDE.md +10 -8
- package/templates/runner/package.json +11 -9
- package/templates/runner/playtests/performance.playtest.json +10 -1
- package/templates/runner/src/physics.ts +0 -1
- package/templates/runner/src/render/autoExposure.ts +225 -0
- package/templates/runner/src/render/backlightControls.ts +66 -0
- package/templates/runner/src/render/backlightMaterial.ts +147 -0
- package/templates/runner/src/render/environmentContribution.ts +188 -0
- package/templates/runner/src/render/environmentRadiance.ts +36 -0
- package/templates/runner/src/render/environmentSampleCache.ts +43 -0
- package/templates/runner/src/render/environmentSampling.ts +193 -0
- package/templates/runner/src/render/environmentSnapshot.ts +53 -0
- package/templates/runner/src/render/exposure.ts +111 -0
- package/templates/runner/src/render/exposureGraph.ts +178 -0
- package/templates/runner/src/render/exposureReadback.ts +79 -0
- package/templates/runner/src/render/heightFog.ts +118 -0
- package/templates/runner/src/render/lighting.ts +26 -1
- package/templates/runner/src/render/materialAssignments.ts +160 -0
- package/templates/runner/src/render/materialLighting.ts +155 -0
- package/templates/runner/src/render/postprocessing.ts +17 -2
- package/templates/runner/src/render/quality.ts +61 -2
- package/templates/runner/src/render/sky.ts +21 -1
- package/templates/runner/src/render/worldEnvironment.ts +433 -30
- package/templates/runner/src/scenes/Run.ts +67 -2
- package/templates/runner/threenative.config.ts +3 -0
- package/templates/runner/vite.config.ts +10 -2
- package/templates/sailing/AGENTS.md +14 -13
- package/templates/sailing/CLAUDE.md +14 -13
- package/templates/sailing/native-playtests/survives.playtest.json +7 -0
- package/templates/sailing/package.json +11 -9
- package/templates/sailing/playtests/live/render-motion.playtest.json +30 -0
- package/templates/sailing/src/entities/Ship.ts +38 -18
- package/templates/sailing/src/render/autoExposure.ts +225 -0
- package/templates/sailing/src/render/backlightControls.ts +66 -0
- package/templates/sailing/src/render/backlightMaterial.ts +147 -0
- package/templates/sailing/src/render/camera.ts +12 -4
- package/templates/sailing/src/render/environmentContribution.ts +188 -0
- package/templates/sailing/src/render/environmentRadiance.ts +36 -0
- package/templates/sailing/src/render/environmentSampleCache.ts +43 -0
- package/templates/sailing/src/render/environmentSampling.ts +193 -0
- package/templates/sailing/src/render/environmentSetup.ts +24 -0
- package/templates/sailing/src/render/environmentSnapshot.ts +53 -0
- package/templates/sailing/src/render/exposure.ts +111 -0
- package/templates/sailing/src/render/exposureGraph.ts +178 -0
- package/templates/sailing/src/render/exposureReadback.ts +79 -0
- package/templates/sailing/src/render/heightFog.ts +118 -0
- package/templates/sailing/src/render/lighting.ts +26 -1
- package/templates/sailing/src/render/materialAssignments.ts +160 -0
- package/templates/sailing/src/render/materialLighting.ts +155 -0
- package/templates/sailing/src/render/ocean.ts +71 -53
- package/templates/sailing/src/render/postprocessing.ts +16 -2
- package/templates/sailing/src/render/props.ts +0 -45
- package/templates/sailing/src/render/quality.ts +61 -1
- package/templates/sailing/src/render/sky.ts +21 -1
- package/templates/sailing/src/render/worldEnvironment.ts +433 -30
- package/templates/sailing/src/scenes/Boot.ts +12 -1
- package/templates/sailing/src/scenes/Sailing.ts +87 -2
- package/templates/sailing/src/scenes/ocean-readiness.ts +68 -0
- package/templates/sailing/threenative.config.ts +3 -0
- package/templates/sailing/vite.config.ts +10 -2
- package/templates/shooter/AGENTS.md +8 -6
- package/templates/shooter/CLAUDE.md +8 -6
- package/templates/shooter/package.json +11 -9
- package/templates/shooter/playtests/performance.playtest.json +7 -1
- package/templates/shooter/src/entities/Enemy.ts +0 -15
- package/templates/shooter/src/entities/Rifle.ts +38 -1
- package/templates/shooter/src/render/autoExposure.ts +225 -0
- package/templates/shooter/src/render/backlightControls.ts +66 -0
- package/templates/shooter/src/render/backlightMaterial.ts +147 -0
- package/templates/shooter/src/render/camera.ts +1 -12
- package/templates/shooter/src/render/decals.ts +299 -5
- package/templates/shooter/src/render/environmentContribution.ts +188 -0
- package/templates/shooter/src/render/environmentRadiance.ts +36 -0
- package/templates/shooter/src/render/environmentSampleCache.ts +43 -0
- package/templates/shooter/src/render/environmentSampling.ts +193 -0
- package/templates/shooter/src/render/environmentSnapshot.ts +53 -0
- package/templates/shooter/src/render/exposure.ts +111 -0
- package/templates/shooter/src/render/exposureGraph.ts +178 -0
- package/templates/shooter/src/render/exposureReadback.ts +79 -0
- package/templates/shooter/src/render/gunfx.ts +0 -1
- package/templates/shooter/src/render/heightFog.ts +118 -0
- package/templates/shooter/src/render/lighting.ts +26 -1
- package/templates/shooter/src/render/materialAssignments.ts +160 -0
- package/templates/shooter/src/render/materialLighting.ts +155 -0
- package/templates/shooter/src/render/postprocessing.ts +17 -2
- package/templates/shooter/src/render/quality.ts +61 -2
- package/templates/shooter/src/render/scale.ts +2 -93
- package/templates/shooter/src/render/sky.ts +21 -1
- package/templates/shooter/src/render/vehicles.ts +0 -17
- package/templates/shooter/src/render/worldEnvironment.ts +433 -30
- package/templates/shooter/src/scenes/Play.ts +64 -2
- package/templates/shooter/vite.config.ts +10 -2
- package/templates/snow/.codex/config.toml +19 -0
- package/templates/snow/.cursor/mcp.json +32 -0
- package/templates/snow/.gemini/settings.json +32 -0
- package/templates/snow/.mcp.json +32 -0
- package/templates/snow/.vscode/mcp.json +36 -0
- package/templates/snow/.zed/settings.json +36 -0
- package/templates/snow/AGENTS.md +90 -0
- package/templates/snow/CLAUDE.md +92 -0
- package/templates/snow/README.md +26 -0
- package/templates/snow/assets/crunch.wav +0 -0
- package/templates/snow/assets/wind.wav +0 -0
- package/templates/snow/index.html +12 -0
- package/templates/snow/kit.json +7 -0
- package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
- package/templates/snow/native-playtests/survives.playtest.json +47 -0
- package/templates/snow/opencode.json +41 -0
- package/templates/snow/package.json +60 -0
- package/templates/snow/playtests/footsteps.playtest.json +95 -0
- package/templates/snow/playtests/performance.playtest.json +36 -0
- package/templates/snow/playtests/snow-physics.playtest.json +154 -0
- package/templates/snow/playtests/survives.playtest.json +56 -0
- package/templates/snow/playtests/touch-controls.playtest.json +71 -0
- package/templates/snow/playtests/weather.playtest.json +119 -0
- package/templates/snow/public/favicon.svg +5 -0
- package/templates/snow/src/audio.ts +58 -0
- package/templates/snow/src/commands.ts +8 -0
- package/templates/snow/src/entities/Explorer.ts +279 -0
- package/templates/snow/src/game.ts +69 -0
- package/templates/snow/src/main.ts +15 -0
- package/templates/snow/src/render/autoExposure.ts +225 -0
- package/templates/snow/src/render/backlightControls.ts +66 -0
- package/templates/snow/src/render/backlightMaterial.ts +147 -0
- package/templates/snow/src/render/bootPrint.ts +50 -0
- package/templates/snow/src/render/camera.ts +84 -0
- package/templates/snow/src/render/environmentContribution.ts +188 -0
- package/templates/snow/src/render/environmentRadiance.ts +36 -0
- package/templates/snow/src/render/environmentSampleCache.ts +43 -0
- package/templates/snow/src/render/environmentSampling.ts +193 -0
- package/templates/snow/src/render/environmentSnapshot.ts +53 -0
- package/templates/snow/src/render/explorer.ts +321 -0
- package/templates/snow/src/render/exposure.ts +111 -0
- package/templates/snow/src/render/exposureGraph.ts +178 -0
- package/templates/snow/src/render/exposureReadback.ts +79 -0
- package/templates/snow/src/render/heightFog.ts +118 -0
- package/templates/snow/src/render/lighting.ts +82 -0
- package/templates/snow/src/render/loading.ts +325 -0
- package/templates/snow/src/render/materialAssignments.ts +160 -0
- package/templates/snow/src/render/materialLighting.ts +155 -0
- package/templates/snow/src/render/materials.ts +36 -0
- package/templates/snow/src/render/palette.ts +17 -0
- package/templates/snow/src/render/postprocessing.ts +58 -0
- package/templates/snow/src/render/props.ts +42 -0
- package/templates/snow/src/render/quality.ts +193 -0
- package/templates/snow/src/render/scenery.ts +244 -0
- package/templates/snow/src/render/sky.ts +76 -0
- package/templates/snow/src/render/snowSurface.ts +259 -0
- package/templates/snow/src/render/touch-controls.ts +143 -0
- package/templates/snow/src/render/weather.ts +279 -0
- package/templates/snow/src/render/worldEnvironment.ts +1212 -0
- package/templates/snow/src/scenes/Boot.ts +12 -0
- package/templates/snow/src/scenes/Snow.ts +663 -0
- package/templates/snow/src/state.ts +46 -0
- package/templates/snow/src/style.css +143 -0
- package/templates/snow/src/terrain.ts +64 -0
- package/templates/snow/src/ui/App.tsx +15 -0
- package/templates/snow/src/ui/Controls.tsx +322 -0
- package/templates/snow/src/ui/GameUi.tsx +354 -0
- package/templates/snow/src/ui/icons.tsx +54 -0
- package/templates/snow/src/ui/main.tsx +7 -0
- package/templates/snow/tailwind.config.ts +2 -0
- package/templates/snow/threenative.config.ts +54 -0
- package/templates/snow/tsconfig.json +17 -0
- package/templates/snow/vite.config.ts +45 -0
- package/templates/starter/AGENTS.md +11 -16
- package/templates/starter/CLAUDE.md +11 -16
- package/templates/starter/native-playtests/react-hud.playtest.json +1 -1
- package/templates/starter/native-playtests/render-chain.playtest.json +51 -8
- package/templates/starter/native-playtests/smooth-motion.playtest.json +64 -0
- package/templates/starter/package.json +11 -9
- package/templates/starter/playtests/live/smooth-motion.playtest.json +63 -0
- package/templates/starter/playtests/movement.playtest.json +192 -0
- package/templates/starter/playtests/play.playtest.json +18 -2
- package/templates/starter/playtests/production-readiness.playtest.json +1 -1
- package/templates/starter/public/grade.cube +735 -0
- package/templates/starter/src/entities/Crate.ts +4 -0
- package/templates/starter/src/entities/Player.ts +79 -18
- package/templates/starter/src/game.ts +1 -0
- package/templates/starter/src/render/adaptiveQuality.ts +28 -41
- package/templates/starter/src/render/autoExposure.ts +225 -0
- package/templates/starter/src/render/backlightControls.ts +66 -0
- package/templates/starter/src/render/backlightMaterial.ts +147 -0
- package/templates/starter/src/render/environmentContribution.ts +188 -0
- package/templates/starter/src/render/environmentRadiance.ts +36 -0
- package/templates/starter/src/render/environmentSampleCache.ts +43 -0
- package/templates/starter/src/render/environmentSampling.ts +193 -0
- package/templates/starter/src/render/environmentSnapshot.ts +53 -0
- package/templates/starter/src/render/exposure.ts +111 -0
- package/templates/starter/src/render/exposureGraph.ts +178 -0
- package/templates/starter/src/render/exposureReadback.ts +79 -0
- package/templates/starter/src/render/grade.ts +157 -0
- package/templates/starter/src/render/heightFog.ts +118 -0
- package/templates/starter/src/render/lighting.ts +26 -1
- package/templates/starter/src/render/materialAssignments.ts +160 -0
- package/templates/starter/src/render/materialLighting.ts +155 -0
- package/templates/starter/src/render/postprocessing.ts +84 -4
- package/templates/starter/src/render/quality.ts +80 -8
- package/templates/starter/src/render/qualityPolicy.ts +54 -0
- package/templates/starter/src/render/rendererGate.ts +36 -0
- package/templates/starter/src/render/sky.ts +23 -1
- package/templates/starter/src/render/temporalAA.ts +197 -0
- package/templates/starter/src/render/temporalAAFrame.ts +179 -0
- package/templates/starter/src/render/temporalAAHooks.ts +101 -0
- package/templates/starter/src/render/temporalAAInput.ts +56 -0
- package/templates/starter/src/render/temporalAAResolve.ts +65 -0
- package/templates/starter/src/render/temporalAAStage.ts +76 -0
- package/templates/starter/src/render/temporalCurrentArea.ts +31 -0
- package/templates/starter/src/render/temporalCurrentFootprint.ts +198 -0
- package/templates/starter/src/render/temporalCurrentFootprintMath.ts +41 -0
- package/templates/starter/src/render/temporalCurrentProducer.ts +161 -0
- package/templates/starter/src/render/temporalCurrentReplay.ts +160 -0
- package/templates/starter/src/render/temporalCurrentSelection.ts +89 -0
- package/templates/starter/src/render/temporalCurrentVisibility.ts +170 -0
- package/templates/starter/src/render/temporalDepthSamples.ts +34 -0
- package/templates/starter/src/render/temporalRejectionCounter.ts +179 -0
- package/templates/starter/src/render/temporalResolve.ts +139 -0
- package/templates/starter/src/render/temporalResolveDepth.ts +193 -0
- package/templates/starter/src/render/temporalResolveMath.ts +196 -0
- package/templates/starter/src/render/volumetricFog.ts +124 -0
- package/templates/starter/src/render/volumetricFogOptions.ts +96 -0
- package/templates/starter/src/render/volumetricFogTransport.ts +176 -0
- package/templates/starter/src/render/volumetricFogVolume.ts +139 -0
- package/templates/starter/src/render/worldEnvironment.ts +433 -30
- package/templates/starter/src/scenes/Play.ts +110 -1
- package/templates/starter/src/state.ts +1 -0
- package/templates/starter/src/ui/Hud.tsx +1 -1
- package/templates/starter/src/ui/Menu.tsx +1 -1
- package/templates/starter/tools/make-grade-lut.mjs +101 -0
- package/templates/starter/vite.config.ts +10 -2
- package/templates/tower-defense/AGENTS.md +10 -9
- package/templates/tower-defense/CLAUDE.md +10 -9
- package/templates/tower-defense/package.json +11 -9
- package/templates/tower-defense/playtests/performance.playtest.json +7 -1
- package/templates/tower-defense/src/render/autoExposure.ts +225 -0
- package/templates/tower-defense/src/render/backlightControls.ts +66 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +147 -0
- package/templates/tower-defense/src/render/environmentContribution.ts +188 -0
- package/templates/tower-defense/src/render/environmentRadiance.ts +36 -0
- package/templates/tower-defense/src/render/environmentSampleCache.ts +43 -0
- package/templates/tower-defense/src/render/environmentSampling.ts +193 -0
- package/templates/tower-defense/src/render/environmentSnapshot.ts +53 -0
- package/templates/tower-defense/src/render/exposure.ts +111 -0
- package/templates/tower-defense/src/render/exposureGraph.ts +178 -0
- package/templates/tower-defense/src/render/exposureReadback.ts +79 -0
- package/templates/tower-defense/src/render/lighting.ts +33 -1
- package/templates/tower-defense/src/render/materialAssignments.ts +160 -0
- package/templates/tower-defense/src/render/materialLighting.ts +155 -0
- package/templates/tower-defense/src/render/postprocessing.ts +8 -2
- package/templates/tower-defense/src/render/quality.ts +61 -2
- package/templates/tower-defense/src/render/shapes.ts +0 -3
- package/templates/tower-defense/src/render/worldEnvironment.ts +433 -30
- package/templates/tower-defense/src/scenes/Battle.ts +65 -2
- package/templates/tower-defense/vite.config.ts +10 -2
- package/templates/minimal/src/scenes/Boot.ts +0 -5
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Scene } from "@threenative/core";
|
|
2
|
+
import type { IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import type { GameState } from "../state.js";
|
|
4
|
+
import { Snow } from "./Snow.js";
|
|
5
|
+
|
|
6
|
+
export class Boot extends Scene<GameState, IPhysicsContext> {
|
|
7
|
+
static override readonly initialState = Snow.initialState;
|
|
8
|
+
|
|
9
|
+
override enter(ctx: Parameters<Snow["enter"]>[0]): void {
|
|
10
|
+
void ctx.goto("snow");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GPUParticles3D,
|
|
3
|
+
type ICtx,
|
|
4
|
+
Scene,
|
|
5
|
+
type SceneFrame,
|
|
6
|
+
getPlatform,
|
|
7
|
+
isMobile,
|
|
8
|
+
isTouchscreenAvailable,
|
|
9
|
+
} from "@threenative/core";
|
|
10
|
+
import type { SnowField } from "@threenative/core/world";
|
|
11
|
+
import {
|
|
12
|
+
CollisionShape3D,
|
|
13
|
+
type IPhysicsContext,
|
|
14
|
+
RigidBody3D,
|
|
15
|
+
attachSnowPhysics,
|
|
16
|
+
} from "@threenative/physics";
|
|
17
|
+
import type { Object3D, PerspectiveCamera } from "three";
|
|
18
|
+
import { SnowAudio } from "../audio.js";
|
|
19
|
+
import { type Command, commands } from "../commands.js";
|
|
20
|
+
import { Explorer, type IFootstep, STANCE } from "../entities/Explorer.js";
|
|
21
|
+
import { BOOT_AREA, bootPrint } from "../render/bootPrint.js";
|
|
22
|
+
import { OrbitFollow, setupCamera } from "../render/camera.js";
|
|
23
|
+
import { setupLighting } from "../render/lighting.js";
|
|
24
|
+
import { createLoadingScreen } from "../render/loading.js";
|
|
25
|
+
import { createMaterialLighting } from "../render/materialLighting.js";
|
|
26
|
+
import { createMaterials } from "../render/materials.js";
|
|
27
|
+
import { setupPost } from "../render/postprocessing.js";
|
|
28
|
+
import { createBall, createCrate, createLog } from "../render/props.js";
|
|
29
|
+
import { isWebGLFallbackRenderer, materialLightingEnabled } from "../render/quality.js";
|
|
30
|
+
import { createScenery } from "../render/scenery.js";
|
|
31
|
+
import { setupSky } from "../render/sky.js";
|
|
32
|
+
import { createSnowSurface } from "../render/snowSurface.js";
|
|
33
|
+
import { TouchControls } from "../render/touch-controls.js";
|
|
34
|
+
import { createWeather } from "../render/weather.js";
|
|
35
|
+
import { type CameraView, type GameState, PROBE_COLUMNS, PROBE_ROWS } from "../state.js";
|
|
36
|
+
import {
|
|
37
|
+
EXPLORER_LAYER,
|
|
38
|
+
FIELD_SIZE,
|
|
39
|
+
SNOW_LAYER,
|
|
40
|
+
WALK_LAYER,
|
|
41
|
+
createSnowfield,
|
|
42
|
+
walkSurface,
|
|
43
|
+
} from "../terrain.js";
|
|
44
|
+
|
|
45
|
+
export type GameCtx = ICtx<GameState, IPhysicsContext>;
|
|
46
|
+
|
|
47
|
+
const BALL_RADIUS = 0.25;
|
|
48
|
+
const BALL_MASS = 10;
|
|
49
|
+
/** Newton-seconds a push gives the ball: 2.4 m/s on a 10 kg ball, enough to carve on uphill. */
|
|
50
|
+
const KICK = 24;
|
|
51
|
+
const CRATE = { x: 0.5, y: 0.3, z: 0.4 } as const;
|
|
52
|
+
const LOG = { halfHeight: 0.35, radius: 0.14 } as const;
|
|
53
|
+
/** Where the explorer walks while auto-explore is on. */
|
|
54
|
+
const ROUTE: ReadonlyArray<readonly [number, number]> = [
|
|
55
|
+
[0.5, -5],
|
|
56
|
+
[-4, -8],
|
|
57
|
+
[-7, -3],
|
|
58
|
+
[-5, 4],
|
|
59
|
+
[0, 7],
|
|
60
|
+
[5, 3],
|
|
61
|
+
[3, -2],
|
|
62
|
+
];
|
|
63
|
+
const VIEWS: readonly CameraView[] = ["follow", "surface", "overhead"];
|
|
64
|
+
/** Seconds between snowfall refills; recovery is rate-based, so this only sets the cadence. */
|
|
65
|
+
const REFILL_INTERVAL = 0.5;
|
|
66
|
+
|
|
67
|
+
/** One dynamic body that sits in the snow, with what a playtest needs to read back about it. */
|
|
68
|
+
function placeBody(
|
|
69
|
+
ctx: GameCtx,
|
|
70
|
+
snow: SnowField,
|
|
71
|
+
body: RigidBody3D,
|
|
72
|
+
at: { readonly x: number; readonly z: number },
|
|
73
|
+
lift: number,
|
|
74
|
+
): void {
|
|
75
|
+
const half = FIELD_SIZE / 2 - 1;
|
|
76
|
+
const x = Math.max(-half, Math.min(half, at.x));
|
|
77
|
+
const z = Math.max(-half, Math.min(half, at.z));
|
|
78
|
+
const y = snow.heightAt(x, z) + lift;
|
|
79
|
+
ctx.physics.simulation.setBodyTransform(body.body.id, { x, y, z });
|
|
80
|
+
body.linearVelocity = { x: 0, y: 0, z: 0 };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class Snow extends Scene<GameState, IPhysicsContext> {
|
|
84
|
+
#materialLighting: ReturnType<typeof createMaterialLighting> | undefined;
|
|
85
|
+
#post: ReturnType<typeof setupPost> | undefined;
|
|
86
|
+
static override readonly initialState: GameState = {
|
|
87
|
+
autoExplore: true,
|
|
88
|
+
ballGap: 0,
|
|
89
|
+
ballLoad: 0,
|
|
90
|
+
ballSink: 0,
|
|
91
|
+
blizzard: false,
|
|
92
|
+
compaction: false,
|
|
93
|
+
contacts: 0,
|
|
94
|
+
depth: 0.28,
|
|
95
|
+
fallSpeed: 0.55,
|
|
96
|
+
hardness: 0.22,
|
|
97
|
+
lastSink: 0,
|
|
98
|
+
muted: true,
|
|
99
|
+
paused: false,
|
|
100
|
+
probe: [],
|
|
101
|
+
recovery: 120,
|
|
102
|
+
snowfall: 0.58,
|
|
103
|
+
speed: 0,
|
|
104
|
+
storm: 0,
|
|
105
|
+
toast: "",
|
|
106
|
+
toastId: 0,
|
|
107
|
+
uiReady: false,
|
|
108
|
+
view: "follow",
|
|
109
|
+
wind: 0.4,
|
|
110
|
+
windNow: 0.4,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
override enter(ctx: GameCtx): SceneFrame<GameState, IPhysicsContext> {
|
|
114
|
+
const initial = ctx.state.getState();
|
|
115
|
+
const mobile = isMobile();
|
|
116
|
+
const stormSky = setupSky(ctx.scene);
|
|
117
|
+
const lights = setupLighting(
|
|
118
|
+
ctx.scene,
|
|
119
|
+
ctx.renderer.raw as Parameters<typeof setupLighting>[1],
|
|
120
|
+
);
|
|
121
|
+
const materialEnvironment = {
|
|
122
|
+
web: getPlatform().runtime === "web",
|
|
123
|
+
rendererKind: ctx.renderer.kind,
|
|
124
|
+
webglFallback: isWebGLFallbackRenderer(ctx.renderer.raw),
|
|
125
|
+
mobile: isMobile(),
|
|
126
|
+
software: ctx.renderer.softwareAdapter !== undefined,
|
|
127
|
+
};
|
|
128
|
+
this.#post = setupPost(ctx.renderer, ctx.scene, ctx.camera, {
|
|
129
|
+
onTierChanged: (tier) =>
|
|
130
|
+
this.#materialLighting?.setEnabled(materialLightingEnabled(tier, materialEnvironment)),
|
|
131
|
+
mobile,
|
|
132
|
+
software: ctx.renderer.softwareAdapter !== undefined,
|
|
133
|
+
gpuClass: ctx.renderer.gpuClass?.class,
|
|
134
|
+
});
|
|
135
|
+
const loading = createLoadingScreen(ctx);
|
|
136
|
+
const camera = ctx.camera as PerspectiveCamera;
|
|
137
|
+
setupCamera(camera);
|
|
138
|
+
ctx.add(camera);
|
|
139
|
+
const orbit = new OrbitFollow();
|
|
140
|
+
const touchControls =
|
|
141
|
+
mobile && isTouchscreenAvailable()
|
|
142
|
+
? ctx.entities.add("touch-controls", new TouchControls(camera))
|
|
143
|
+
: undefined;
|
|
144
|
+
|
|
145
|
+
const materials = createMaterials();
|
|
146
|
+
const snow = createSnowfield(initial.depth, initial.hardness);
|
|
147
|
+
const startDepth = snow.depth;
|
|
148
|
+
const surface = createSnowSurface(snow);
|
|
149
|
+
ctx.add(surface.mesh);
|
|
150
|
+
ctx.add(surface.outskirts);
|
|
151
|
+
const scenery = createScenery(materials, snow.depth);
|
|
152
|
+
ctx.add(scenery.root);
|
|
153
|
+
|
|
154
|
+
// Trees and rocks stop the explorer and the ball; the field's edge is a fence nobody sees.
|
|
155
|
+
for (const obstacle of scenery.obstacles) {
|
|
156
|
+
if (Math.abs(obstacle.x) > FIELD_SIZE / 2 + 2 || Math.abs(obstacle.z) > FIELD_SIZE / 2 + 2)
|
|
157
|
+
continue;
|
|
158
|
+
new RigidBody3D({
|
|
159
|
+
physics: ctx.physics,
|
|
160
|
+
position: { x: obstacle.x, y: obstacle.height / 2, z: obstacle.z },
|
|
161
|
+
shape: CollisionShape3D.capsule(
|
|
162
|
+
Math.max(0, obstacle.height / 2 - obstacle.radius),
|
|
163
|
+
obstacle.radius,
|
|
164
|
+
),
|
|
165
|
+
type: "fixed",
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const half = FIELD_SIZE / 2;
|
|
169
|
+
for (const [x, z, width, depth] of [
|
|
170
|
+
[0, -half - 0.5, FIELD_SIZE + 2, 1],
|
|
171
|
+
[0, half + 0.5, FIELD_SIZE + 2, 1],
|
|
172
|
+
[-half - 0.5, 0, 1, FIELD_SIZE + 2],
|
|
173
|
+
[half + 0.5, 0, 1, FIELD_SIZE + 2],
|
|
174
|
+
] as const)
|
|
175
|
+
new RigidBody3D({
|
|
176
|
+
physics: ctx.physics,
|
|
177
|
+
position: { x, y: 1, z },
|
|
178
|
+
shape: CollisionShape3D.box(width, 6, depth),
|
|
179
|
+
type: "fixed",
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// The snow binding owns the surface collider and presses solved contacts into the field.
|
|
183
|
+
const snowPhysics = attachSnowPhysics({
|
|
184
|
+
collisionLayer: SNOW_LAYER,
|
|
185
|
+
physics: ctx.physics,
|
|
186
|
+
snow,
|
|
187
|
+
});
|
|
188
|
+
// The explorer walks on a coarse copy of the ground plus fresh snow; only it collides with it.
|
|
189
|
+
const walk = (depth: number) => {
|
|
190
|
+
const field = walkSurface(depth);
|
|
191
|
+
return new RigidBody3D({
|
|
192
|
+
collisionLayer: WALK_LAYER,
|
|
193
|
+
collisionMask: EXPLORER_LAYER,
|
|
194
|
+
physics: ctx.physics,
|
|
195
|
+
position: { x: 0, y: 0, z: 0 },
|
|
196
|
+
shape: CollisionShape3D.heightfield(field.rows, field.columns, field.toColliderHeights(), {
|
|
197
|
+
x: FIELD_SIZE,
|
|
198
|
+
y: 1,
|
|
199
|
+
z: FIELD_SIZE,
|
|
200
|
+
}),
|
|
201
|
+
type: "fixed",
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
let walkBody = walk(snow.depth);
|
|
205
|
+
|
|
206
|
+
const ballObject = createBall(materials, BALL_RADIUS);
|
|
207
|
+
ballObject.position.set(2.2, snow.heightAt(2.2, -2) + BALL_RADIUS + 0.05, -2);
|
|
208
|
+
const ball = new RigidBody3D({
|
|
209
|
+
mass: BALL_MASS,
|
|
210
|
+
object: ballObject,
|
|
211
|
+
physics: ctx.physics,
|
|
212
|
+
shape: CollisionShape3D.sphere(BALL_RADIUS),
|
|
213
|
+
});
|
|
214
|
+
ctx.add(ballObject);
|
|
215
|
+
const crateObject = createCrate(materials, CRATE);
|
|
216
|
+
crateObject.position.set(-2.6, snow.heightAt(-2.6, -2.4) + CRATE.y / 2 + 0.05, -2.4);
|
|
217
|
+
crateObject.rotation.y = 0.5;
|
|
218
|
+
const crate = new RigidBody3D({
|
|
219
|
+
mass: 25,
|
|
220
|
+
object: crateObject,
|
|
221
|
+
physics: ctx.physics,
|
|
222
|
+
shape: CollisionShape3D.box(CRATE.x, CRATE.y, CRATE.z),
|
|
223
|
+
});
|
|
224
|
+
ctx.add(crateObject);
|
|
225
|
+
const logObject = createLog(materials, LOG.halfHeight, LOG.radius);
|
|
226
|
+
logObject.position.set(-1.6, snow.heightAt(-1.6, 2.8) + LOG.radius + 0.05, 2.8);
|
|
227
|
+
logObject.rotation.set(Math.PI / 2, 0, 0.6);
|
|
228
|
+
const log = new RigidBody3D({
|
|
229
|
+
mass: 20,
|
|
230
|
+
object: logObject,
|
|
231
|
+
physics: ctx.physics,
|
|
232
|
+
shape: CollisionShape3D.capsule(LOG.halfHeight, LOG.radius),
|
|
233
|
+
});
|
|
234
|
+
ctx.add(logObject);
|
|
235
|
+
for (const body of [ball, crate, log]) snowPhysics.add(body);
|
|
236
|
+
|
|
237
|
+
const weather = createWeather({
|
|
238
|
+
flakes: mobile ? 6_000 : 16_000,
|
|
239
|
+
particles: (options) => new GPUParticles3D(options),
|
|
240
|
+
});
|
|
241
|
+
ctx.add(weather.snowfall);
|
|
242
|
+
for (const burst of weather.bursts) ctx.add(burst);
|
|
243
|
+
const audio = new SnowAudio(camera, (name) => ctx.assets.audio(name));
|
|
244
|
+
ctx.entities.add("audio", audio.bus);
|
|
245
|
+
|
|
246
|
+
const recentSteps: IFootstep[] = [];
|
|
247
|
+
let lastStep: IFootstep = {
|
|
248
|
+
angle: Math.PI,
|
|
249
|
+
penetration: 0,
|
|
250
|
+
side: 1,
|
|
251
|
+
speed: 0,
|
|
252
|
+
x: 0,
|
|
253
|
+
y: 0,
|
|
254
|
+
z: 2,
|
|
255
|
+
};
|
|
256
|
+
const explorer = new Explorer(ctx.physics, snow, materials, { x: 0, z: 0 }, (step) => {
|
|
257
|
+
if (step.penetration <= 0) return;
|
|
258
|
+
lastStep = step;
|
|
259
|
+
recentSteps.push(step);
|
|
260
|
+
if (recentSteps.length > 8) recentSteps.shift();
|
|
261
|
+
weather.burst(step, step.penetration);
|
|
262
|
+
audio.footstep(step);
|
|
263
|
+
});
|
|
264
|
+
ctx.add(explorer.model.root);
|
|
265
|
+
// A short arrival trail, so the snow's memory is the first thing on screen.
|
|
266
|
+
for (let index = 0; index < 14; index += 1) {
|
|
267
|
+
const z = 6.4 - index * 0.46;
|
|
268
|
+
const x = 0.35 * Math.sin(z * 0.7) + (index % 2 ? -STANCE : STANCE);
|
|
269
|
+
const angle = Math.PI + Math.cos(z * 0.7) * 0.2;
|
|
270
|
+
const penetration = snow.stamp({
|
|
271
|
+
area: BOOT_AREA,
|
|
272
|
+
footprint: bootPrint,
|
|
273
|
+
load: 80 * 9.81,
|
|
274
|
+
rotation: angle,
|
|
275
|
+
x,
|
|
276
|
+
z,
|
|
277
|
+
});
|
|
278
|
+
lastStep = { angle, penetration, side: index % 2 ? -1 : 1, speed: 0, x, y: 0, z };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ---- what a playtest reads back ----
|
|
282
|
+
const telemetry = {
|
|
283
|
+
airborneLoads: 0,
|
|
284
|
+
dropped: false,
|
|
285
|
+
kickedAt: undefined as { x: number; z: number } | undefined,
|
|
286
|
+
path: [] as Array<{ x: number; z: number }>,
|
|
287
|
+
turned: 0,
|
|
288
|
+
/** Ground the ball's centre covered since the kick, step by step. */
|
|
289
|
+
rolled: 0,
|
|
290
|
+
/** Farthest the ball got from where it was kicked. */
|
|
291
|
+
reach: 0,
|
|
292
|
+
lastRotation: { w: 1, x: 0, y: 0, z: 0 },
|
|
293
|
+
lastPosition: { x: 0, y: 0, z: 0 },
|
|
294
|
+
lastClearance: 0,
|
|
295
|
+
};
|
|
296
|
+
// Read the solver's own pose: the drawn ball is synced from it later in the frame, and one
|
|
297
|
+
// step stale is ten centimetres at the speed a dropped ball lands.
|
|
298
|
+
const solvedBall = () =>
|
|
299
|
+
ctx.physics.simulation.readBodyTransform?.(ball.body.id) ?? {
|
|
300
|
+
position: ballObject.position,
|
|
301
|
+
rotation: ballObject.quaternion,
|
|
302
|
+
};
|
|
303
|
+
const ballState = () => {
|
|
304
|
+
const p = solvedBall().position;
|
|
305
|
+
const inside = Math.abs(p.x) < half && Math.abs(p.z) < half;
|
|
306
|
+
const ground = inside ? snow.heightAt(p.x, p.z) : 0;
|
|
307
|
+
// Clearance is the closest the sphere's underside comes to the snow anywhere beneath it,
|
|
308
|
+
// not just under its centre: a ball rolling over the lip of its crater is touching the rim
|
|
309
|
+
// while its centre stands well above the crater floor.
|
|
310
|
+
let clearance = Number.POSITIVE_INFINITY;
|
|
311
|
+
for (const ring of [0, 0.5, 0.85]) {
|
|
312
|
+
for (let step = 0; step < (ring === 0 ? 1 : 8); step += 1) {
|
|
313
|
+
const angle = (step / 8) * Math.PI * 2;
|
|
314
|
+
const x = clampToField(p.x + Math.cos(angle) * ring * BALL_RADIUS);
|
|
315
|
+
const z = clampToField(p.z + Math.sin(angle) * ring * BALL_RADIUS);
|
|
316
|
+
const underside = p.y - Math.sqrt(1 - ring * ring) * BALL_RADIUS;
|
|
317
|
+
clearance = Math.min(clearance, underside - snow.heightAt(x, z));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
clearance,
|
|
322
|
+
gap: p.y - BALL_RADIUS - ground,
|
|
323
|
+
sink: inside ? snow.sample(p.x, p.z).indent : 0,
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
ctx.entities.add("ball", {
|
|
327
|
+
object: ballObject,
|
|
328
|
+
debug: () => {
|
|
329
|
+
const { clearance, gap, sink } = ballState();
|
|
330
|
+
const kick = telemetry.kickedAt;
|
|
331
|
+
const p = ballObject.position;
|
|
332
|
+
const travelled = kick === undefined ? 0 : Math.hypot(p.x - kick.x, p.z - kick.z);
|
|
333
|
+
// Every recorded point of the path since the kick must sit in pressed snow.
|
|
334
|
+
let trackGaps = 0;
|
|
335
|
+
for (const point of telemetry.path)
|
|
336
|
+
if (snow.sample(point.x, point.z).indent < 0.004) trackGaps += 1;
|
|
337
|
+
return {
|
|
338
|
+
airborne: clearance > 0.05,
|
|
339
|
+
clearance,
|
|
340
|
+
airborneLoads: telemetry.airborneLoads,
|
|
341
|
+
dropped: telemetry.dropped,
|
|
342
|
+
gap,
|
|
343
|
+
kicked: kick !== undefined,
|
|
344
|
+
load: snowPhysics.loadOf(ball),
|
|
345
|
+
position: [p.x, p.y, p.z],
|
|
346
|
+
// Turn times radius over the distance actually covered: 1 is rolling without slipping.
|
|
347
|
+
reach: telemetry.reach,
|
|
348
|
+
rollRatio:
|
|
349
|
+
telemetry.rolled > 0.05 ? (telemetry.turned * BALL_RADIUS) / telemetry.rolled : 0,
|
|
350
|
+
settled: Math.abs(gap) <= 0.02 && sink > 0.02,
|
|
351
|
+
sink,
|
|
352
|
+
trackGaps,
|
|
353
|
+
trackSamples: telemetry.path.length,
|
|
354
|
+
travelled,
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
const pressedUnder = (object: Object3D) => {
|
|
359
|
+
const p = object.position;
|
|
360
|
+
return Math.abs(p.x) < half && Math.abs(p.z) < half ? snow.sample(p.x, p.z).indent : 0;
|
|
361
|
+
};
|
|
362
|
+
ctx.entities.add("crate", {
|
|
363
|
+
object: crateObject,
|
|
364
|
+
debug: () => ({ load: snowPhysics.loadOf(crate), sink: pressedUnder(crateObject) }),
|
|
365
|
+
});
|
|
366
|
+
ctx.entities.add("log", {
|
|
367
|
+
object: logObject,
|
|
368
|
+
debug: () => ({ load: snowPhysics.loadOf(log), sink: pressedUnder(logObject) }),
|
|
369
|
+
});
|
|
370
|
+
ctx.entities.add("player", explorer);
|
|
371
|
+
// The first print of the arrival trail: nothing walks back over it unless steered there.
|
|
372
|
+
const trailStart = { x: 0.35 * Math.sin(6.4 * 0.7) + STANCE, z: 6.4 };
|
|
373
|
+
ctx.entities.add("snow", {
|
|
374
|
+
debug: () => ({
|
|
375
|
+
trailPressed: snow.sample(trailStart.x, trailStart.z).indent > 0.01,
|
|
376
|
+
...snowPhysics.observe(),
|
|
377
|
+
activeCells: snow.activeCells,
|
|
378
|
+
depth: snow.depth,
|
|
379
|
+
memoryBytes: snow.memoryBytes,
|
|
380
|
+
pendingRows: surface.pendingRows,
|
|
381
|
+
renderError: surface.renderError(),
|
|
382
|
+
steps: snow.steps,
|
|
383
|
+
}),
|
|
384
|
+
});
|
|
385
|
+
ctx.entities.add("weather", { debug: () => ({ storm: weather.storm, wind: weather.wind }) });
|
|
386
|
+
|
|
387
|
+
// The surface view frames the newest print far enough from the explorer to be seen past them.
|
|
388
|
+
const surfaceTarget = () => {
|
|
389
|
+
const print =
|
|
390
|
+
[...recentSteps]
|
|
391
|
+
.reverse()
|
|
392
|
+
.find(
|
|
393
|
+
(step) => Math.hypot(step.x - explorer.position.x, step.z - explorer.position.z) > 1.2,
|
|
394
|
+
) ?? lastStep;
|
|
395
|
+
return {
|
|
396
|
+
x: print.x,
|
|
397
|
+
y: snow.heightAt(clampToField(print.x), clampToField(print.z)) + 0.12,
|
|
398
|
+
z: print.z,
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
// ---- verbs: one function per action, shared by keys and the HUD ----
|
|
402
|
+
let toastId = 0;
|
|
403
|
+
let toast = "";
|
|
404
|
+
const say = (message: string) => {
|
|
405
|
+
toast = message;
|
|
406
|
+
toastId += 1;
|
|
407
|
+
};
|
|
408
|
+
let view = 0;
|
|
409
|
+
// The scene owns this; state only mirrors it, so a key and the panel never race the bridge.
|
|
410
|
+
let autoExplore = initial.autoExplore;
|
|
411
|
+
let blizzard = initial.blizzard;
|
|
412
|
+
const act = (command: Command): void => {
|
|
413
|
+
const state = ctx.state.getState();
|
|
414
|
+
if (command === "reset") {
|
|
415
|
+
snow.reset();
|
|
416
|
+
placeBody(ctx, snow, ball, { x: 2.2, z: -2 }, BALL_RADIUS + 0.02);
|
|
417
|
+
placeBody(ctx, snow, crate, { x: -2.6, z: -2.4 }, CRATE.y / 2 + 0.02);
|
|
418
|
+
placeBody(ctx, snow, log, { x: -1.6, z: 2.8 }, LOG.radius + 0.02);
|
|
419
|
+
telemetry.kickedAt = undefined;
|
|
420
|
+
telemetry.path.length = 0;
|
|
421
|
+
lastStep = { ...lastStep, penetration: 0 };
|
|
422
|
+
say("A fresh blanket of snow. All footprints cleared.");
|
|
423
|
+
} else if (command === "drop") {
|
|
424
|
+
const ahead = {
|
|
425
|
+
x: explorer.position.x + Math.sin(explorer.heading) * 1.8,
|
|
426
|
+
z: explorer.position.z + Math.cos(explorer.heading) * 1.8,
|
|
427
|
+
};
|
|
428
|
+
placeBody(ctx, snow, ball, ahead, 1.6);
|
|
429
|
+
telemetry.dropped = true;
|
|
430
|
+
telemetry.airborneLoads = 0;
|
|
431
|
+
telemetry.kickedAt = undefined;
|
|
432
|
+
telemetry.path.length = 0;
|
|
433
|
+
say("Ball dropped. Watch it settle into the snow.");
|
|
434
|
+
} else if (command === "kick") {
|
|
435
|
+
const p = ballObject.position;
|
|
436
|
+
let dx = p.x - explorer.position.x;
|
|
437
|
+
let dz = p.z - explorer.position.z;
|
|
438
|
+
const length = Math.hypot(dx, dz) || 1;
|
|
439
|
+
dx /= length;
|
|
440
|
+
dz /= length;
|
|
441
|
+
// A kick lifts as well as pushes: a dropped ball can sit ten centimetres down in its own
|
|
442
|
+
// crater, and a purely sideways shove only rolls it up the wall and back in.
|
|
443
|
+
ball.applyImpulse({ x: dx * KICK, y: KICK * 0.4, z: dz * KICK });
|
|
444
|
+
telemetry.kickedAt = { x: p.x, z: p.z };
|
|
445
|
+
telemetry.path.length = 0;
|
|
446
|
+
telemetry.turned = 0;
|
|
447
|
+
telemetry.rolled = 0;
|
|
448
|
+
telemetry.reach = 0;
|
|
449
|
+
say("Ball pushed. It rolls through the powder and carves its own track.");
|
|
450
|
+
} else if (command === "view") {
|
|
451
|
+
view = (view + 1) % VIEWS.length;
|
|
452
|
+
ctx.state.set({ view: VIEWS[view] });
|
|
453
|
+
if (VIEWS[view] === "surface") {
|
|
454
|
+
// Look back at the print from beyond it, so the explorer is never between.
|
|
455
|
+
const print = surfaceTarget();
|
|
456
|
+
orbit.yaw = Math.atan2(print.x - explorer.position.x, print.z - explorer.position.z);
|
|
457
|
+
}
|
|
458
|
+
} else if (command === "auto") {
|
|
459
|
+
autoExplore = !autoExplore;
|
|
460
|
+
say(autoExplore ? "Auto-explore on." : "You are in control. Hold Shift to run.");
|
|
461
|
+
} else if (command === "blizzard") {
|
|
462
|
+
blizzard = !blizzard;
|
|
463
|
+
say(
|
|
464
|
+
blizzard
|
|
465
|
+
? "Blizzard building — wind and visibility are changing."
|
|
466
|
+
: "Returning to soft snowfall.",
|
|
467
|
+
);
|
|
468
|
+
} else if (command === "mute") {
|
|
469
|
+
audio.setMuted(!audio.muted);
|
|
470
|
+
ctx.state.set({ muted: audio.muted });
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
let refill = 0;
|
|
475
|
+
ctx.afterPhysics((dt) => {
|
|
476
|
+
// Solve → (this) consume contacts once, deform, refill → collider installed before the next
|
|
477
|
+
// step. The renderer collects what changed and draws it before the frame.
|
|
478
|
+
surface.collect();
|
|
479
|
+
refill += dt;
|
|
480
|
+
if (refill >= REFILL_INTERVAL) {
|
|
481
|
+
const state = ctx.state.getState();
|
|
482
|
+
const deposition = ((2 + 18 * weather.storm) * state.snowfall * state.recovery) / 3_600_000;
|
|
483
|
+
snow.recover(refill, deposition, weather.wind * weather.storm);
|
|
484
|
+
refill = 0;
|
|
485
|
+
surface.collect();
|
|
486
|
+
}
|
|
487
|
+
snowPhysics.step(dt);
|
|
488
|
+
// Ball telemetry: a load while the ball was clearly above the snow for the whole step — at
|
|
489
|
+
// its start and at its end — would be a contact nothing touched. A step that lands or
|
|
490
|
+
// kicks off legitimately touches at one end of it.
|
|
491
|
+
const clearance = ballState().clearance;
|
|
492
|
+
if (Math.min(clearance, telemetry.lastClearance) > 0.05 && snowPhysics.loadOf(ball) > 0)
|
|
493
|
+
telemetry.airborneLoads += 1;
|
|
494
|
+
telemetry.lastClearance = clearance;
|
|
495
|
+
const solved = solvedBall();
|
|
496
|
+
const rotation = solved.rotation;
|
|
497
|
+
const previous = telemetry.lastRotation;
|
|
498
|
+
const dot = Math.min(
|
|
499
|
+
1,
|
|
500
|
+
Math.abs(
|
|
501
|
+
previous.x * rotation.x +
|
|
502
|
+
previous.y * rotation.y +
|
|
503
|
+
previous.z * rotation.z +
|
|
504
|
+
previous.w * rotation.w,
|
|
505
|
+
),
|
|
506
|
+
);
|
|
507
|
+
const p = solved.position;
|
|
508
|
+
const moved = telemetry.lastPosition;
|
|
509
|
+
if (telemetry.kickedAt !== undefined) {
|
|
510
|
+
telemetry.turned += 2 * Math.acos(dot);
|
|
511
|
+
telemetry.rolled += Math.hypot(p.x - moved.x, p.z - moved.z);
|
|
512
|
+
telemetry.reach = Math.max(
|
|
513
|
+
telemetry.reach,
|
|
514
|
+
Math.hypot(p.x - telemetry.kickedAt.x, p.z - telemetry.kickedAt.z),
|
|
515
|
+
);
|
|
516
|
+
// Only where the ball is on the snow: a hop off the crater lip presses nothing beneath it.
|
|
517
|
+
const last = telemetry.path[telemetry.path.length - 1];
|
|
518
|
+
if (
|
|
519
|
+
clearance <= 0.01 &&
|
|
520
|
+
(last === undefined || Math.hypot(p.x - last.x, p.z - last.z) > 0.1)
|
|
521
|
+
)
|
|
522
|
+
telemetry.path.push({ x: p.x, z: p.z });
|
|
523
|
+
}
|
|
524
|
+
telemetry.lastRotation = { w: rotation.w, x: rotation.x, y: rotation.y, z: rotation.z };
|
|
525
|
+
telemetry.lastPosition = { x: p.x, y: p.y, z: p.z };
|
|
526
|
+
});
|
|
527
|
+
ctx.beforeRender(() => surface.refresh());
|
|
528
|
+
|
|
529
|
+
let waypoint = 0;
|
|
530
|
+
let pointer: { x: number; y: number } | undefined;
|
|
531
|
+
this.#materialLighting = ctx.entities.add(
|
|
532
|
+
"material-lighting",
|
|
533
|
+
createMaterialLighting(ctx.scene, ctx.camera, lights.sun, {
|
|
534
|
+
...materialEnvironment,
|
|
535
|
+
enabled: materialLightingEnabled(this.#post.tier, materialEnvironment),
|
|
536
|
+
}),
|
|
537
|
+
);
|
|
538
|
+
return (frameCtx, dt) => {
|
|
539
|
+
loading.update();
|
|
540
|
+
const input = frameCtx.input;
|
|
541
|
+
for (const command of commands.splice(0)) act(command);
|
|
542
|
+
for (const name of ["reset", "drop", "kick", "view", "auto", "blizzard", "mute"] as const)
|
|
543
|
+
if (input.justPressed(name)) act(name);
|
|
544
|
+
if (input.justPressed("compaction"))
|
|
545
|
+
frameCtx.state.set({ compaction: !frameCtx.state.getState().compaction });
|
|
546
|
+
|
|
547
|
+
const state = frameCtx.state.getState();
|
|
548
|
+
if (state.depth !== snow.depth) {
|
|
549
|
+
snow.setDepth(state.depth);
|
|
550
|
+
walkBody.dispose();
|
|
551
|
+
walkBody = walk(snow.depth);
|
|
552
|
+
surface.outskirts.position.y = snow.depth - startDepth;
|
|
553
|
+
}
|
|
554
|
+
snow.hardness = state.hardness;
|
|
555
|
+
surface.setCompactionView(state.compaction);
|
|
556
|
+
|
|
557
|
+
// Steering: the stick or the keys take over from auto-explore.
|
|
558
|
+
const stick = touchControls?.update(input.raw.pointers, frameCtx.viewport.size).move;
|
|
559
|
+
const keys = input.vector("move");
|
|
560
|
+
const sideways = keys.x + (stick?.x ?? 0);
|
|
561
|
+
const forward = keys.y + (stick?.y ?? 0);
|
|
562
|
+
if (autoExplore && Math.hypot(sideways, forward) > 0.1) {
|
|
563
|
+
autoExplore = false;
|
|
564
|
+
say(
|
|
565
|
+
touchControls === undefined
|
|
566
|
+
? "You are in control. Hold Shift to run."
|
|
567
|
+
: "You are in control.",
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
let move: { x: number; z: number };
|
|
571
|
+
if (autoExplore) {
|
|
572
|
+
const [tx, tz] = ROUTE[waypoint] ?? [0, 0];
|
|
573
|
+
const dx = tx - explorer.position.x;
|
|
574
|
+
const dz = tz - explorer.position.z;
|
|
575
|
+
const distance = Math.hypot(dx, dz);
|
|
576
|
+
if (distance < 0.85) waypoint = (waypoint + 1) % ROUTE.length;
|
|
577
|
+
move = { x: dx / Math.max(0.01, distance), z: dz / Math.max(0.01, distance) };
|
|
578
|
+
} else {
|
|
579
|
+
const yaw = orbit.yaw;
|
|
580
|
+
move = {
|
|
581
|
+
x: Math.cos(yaw) * sideways - Math.sin(yaw) * forward,
|
|
582
|
+
z: -Math.sin(yaw) * sideways - Math.cos(yaw) * forward,
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
explorer.update(dt, move, input.pressed("run"), state.hardness);
|
|
586
|
+
|
|
587
|
+
weather.update(
|
|
588
|
+
dt,
|
|
589
|
+
explorer.position,
|
|
590
|
+
frameCtx.viewport.size.height / (2 * Math.tan((camera.fov * Math.PI) / 360)),
|
|
591
|
+
{ ...state, blizzard },
|
|
592
|
+
);
|
|
593
|
+
lights.update(explorer.position, weather.storm);
|
|
594
|
+
stormSky(weather.storm);
|
|
595
|
+
surface.setStorm(weather.storm);
|
|
596
|
+
audio.update(weather.wind, weather.storm);
|
|
597
|
+
|
|
598
|
+
// Camera: drag to orbit (desktop), scroll or pinch to zoom.
|
|
599
|
+
const raw = input.raw.pointer;
|
|
600
|
+
if (touchControls === undefined && raw.down) {
|
|
601
|
+
if (pointer !== undefined)
|
|
602
|
+
orbit.drag(raw.position.x - pointer.x, raw.position.y - pointer.y);
|
|
603
|
+
pointer = { x: raw.position.x, y: raw.position.y };
|
|
604
|
+
} else pointer = undefined;
|
|
605
|
+
orbit.zoom(input.axis("zoom") * 16);
|
|
606
|
+
orbit.setView(state.view);
|
|
607
|
+
const target =
|
|
608
|
+
state.view === "surface"
|
|
609
|
+
? surfaceTarget()
|
|
610
|
+
: {
|
|
611
|
+
x: explorer.position.x,
|
|
612
|
+
y: explorer.position.y + (state.view === "overhead" ? 0.25 : 0.8),
|
|
613
|
+
z: explorer.position.z,
|
|
614
|
+
};
|
|
615
|
+
orbit.update(camera, target, (x, z) => snow.heightAt(clampToField(x), clampToField(z)), dt);
|
|
616
|
+
|
|
617
|
+
const { gap, sink } = ballState();
|
|
618
|
+
frameCtx.state.set({
|
|
619
|
+
autoExplore,
|
|
620
|
+
blizzard,
|
|
621
|
+
ballGap: gap,
|
|
622
|
+
ballLoad: snowPhysics.loadOf(ball),
|
|
623
|
+
ballSink: sink,
|
|
624
|
+
contacts: snow.steps,
|
|
625
|
+
lastSink: lastStep.penetration,
|
|
626
|
+
muted: audio.muted,
|
|
627
|
+
probe: probeAround(snow, lastStep),
|
|
628
|
+
speed: explorer.speed,
|
|
629
|
+
storm: weather.storm,
|
|
630
|
+
toast,
|
|
631
|
+
toastId,
|
|
632
|
+
windNow: weather.wind,
|
|
633
|
+
});
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
override exit(): void {
|
|
637
|
+
this.#materialLighting?.dispose();
|
|
638
|
+
this.#materialLighting = undefined;
|
|
639
|
+
this.#post?.dispose();
|
|
640
|
+
this.#post = undefined;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
function clampToField(value: number): number {
|
|
645
|
+
const half = FIELD_SIZE / 2 - 1e-3;
|
|
646
|
+
return Math.max(-half, Math.min(half, value));
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** The indentation under the last footprint, in the boot's own frame, for the HUD's probe. */
|
|
650
|
+
function probeAround(snow: SnowField, step: IFootstep): number[] {
|
|
651
|
+
const values: number[] = [];
|
|
652
|
+
const cos = Math.cos(step.angle);
|
|
653
|
+
const sin = Math.sin(step.angle);
|
|
654
|
+
for (let row = 0; row < PROBE_ROWS; row += 1) {
|
|
655
|
+
for (let column = 0; column < PROBE_COLUMNS; column += 1) {
|
|
656
|
+
const u = (column / (PROBE_COLUMNS - 1) - 0.5) * 0.56;
|
|
657
|
+
const v = (0.5 - row / (PROBE_ROWS - 1)) * 0.75;
|
|
658
|
+
const sample = snow.sample(step.x + u * cos + v * sin, step.z - u * sin + v * cos);
|
|
659
|
+
values.push(Math.round((sample.indent - sample.bank) * 1000) / 1000);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
return values;
|
|
663
|
+
}
|