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,348 @@
|
|
|
1
|
+
// Generated for you. The one scene: a coast you can walk, and an atmosphere you can reshape.
|
|
2
|
+
import { type ICtx, Scene, type SceneFrame, alwaysRender, isMobile } from "@threenative/core";
|
|
3
|
+
import { type PerspectiveCamera, Vector3 } from "three";
|
|
4
|
+
import { STORM_AUDIO_ENTITY, createStormAudio } from "../audio/storm.js";
|
|
5
|
+
import { createCameraRig, setupCamera } from "../render/camera.js";
|
|
6
|
+
import { type IStormLightning, createStormLightning } from "../render/lightning.js";
|
|
7
|
+
import { createLoadingScreen } from "../render/loading.js";
|
|
8
|
+
import { type IStormPost, setupPost } from "../render/postprocessing.js";
|
|
9
|
+
import { type IStormRain, createStormRain } from "../render/rain.js";
|
|
10
|
+
import { createWeatherWorld } from "../render/world.js";
|
|
11
|
+
import {
|
|
12
|
+
AUTO_STRIKE_CLOUD,
|
|
13
|
+
type GameState,
|
|
14
|
+
MAX_STEP,
|
|
15
|
+
type SimStatus,
|
|
16
|
+
WEATHER_KEYS,
|
|
17
|
+
type Weather,
|
|
18
|
+
easeWeather,
|
|
19
|
+
flashAt,
|
|
20
|
+
intentPatch,
|
|
21
|
+
thunderDelay,
|
|
22
|
+
} from "../state.js";
|
|
23
|
+
|
|
24
|
+
export type WeatherCtx = ICtx<GameState>;
|
|
25
|
+
|
|
26
|
+
/** Seconds of weather the clock starts on, so the first frame is not the start of the storm. */
|
|
27
|
+
const START_TIME = 28;
|
|
28
|
+
/** The storm, this far in, is not waiting for the first automatic strike. */
|
|
29
|
+
const FIRST_STRIKE_DELAY = 9;
|
|
30
|
+
const STRIKE_MIN_GAP = 8;
|
|
31
|
+
const STRIKE_SPREAD = 16;
|
|
32
|
+
/** Below this gap the atmosphere is where it was aimed, and the status can say so. */
|
|
33
|
+
const SETTLED = 0.004;
|
|
34
|
+
/** Where a strike lands, in the game's own coordinates: out to sea, ahead of the coast. */
|
|
35
|
+
const STRIKE_SITE = { maxX: 49, minX: -45, nearZ: -250, spread: 220 } as const;
|
|
36
|
+
|
|
37
|
+
const STORM: Weather = {
|
|
38
|
+
cloud: 0.76,
|
|
39
|
+
exposure: 1.12,
|
|
40
|
+
fog: 0.4,
|
|
41
|
+
rain: 0.76,
|
|
42
|
+
wet: 1,
|
|
43
|
+
wind: 0.55,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export class Coast extends Scene<GameState> {
|
|
47
|
+
// Kept on the instance because `enter` builds them and `exit` is the only hook that runs when the
|
|
48
|
+
// scene goes away: a dropped handle is a shader chain and a geometry that never come back.
|
|
49
|
+
#rain: IStormRain | undefined;
|
|
50
|
+
#post: IStormPost | undefined;
|
|
51
|
+
#lightning: IStormLightning | undefined;
|
|
52
|
+
#measureClouds: (() => GameState["cloudPass"]) | undefined;
|
|
53
|
+
#curtainLifted: (() => boolean) | undefined;
|
|
54
|
+
|
|
55
|
+
static override readonly initialState: GameState = {
|
|
56
|
+
audioEnabled: false,
|
|
57
|
+
autoLightning: true,
|
|
58
|
+
cameraReset: false,
|
|
59
|
+
cinematic: false,
|
|
60
|
+
cloudPass: { height: 0, steps: 0, width: 0 },
|
|
61
|
+
droplets: true,
|
|
62
|
+
dropCount: 0,
|
|
63
|
+
elapsed: START_TIME,
|
|
64
|
+
flash: 0,
|
|
65
|
+
fps: 0,
|
|
66
|
+
frame: 0,
|
|
67
|
+
frozen: false,
|
|
68
|
+
heading: 0,
|
|
69
|
+
helpOpen: false,
|
|
70
|
+
muted: false,
|
|
71
|
+
paused: false,
|
|
72
|
+
lastStrike: { at: -1, delay: 0, metres: 0 },
|
|
73
|
+
loading: { progress: 0, ready: false },
|
|
74
|
+
pendingThunderAt: -1,
|
|
75
|
+
position: { x: 0, y: 0, z: 0 },
|
|
76
|
+
preset: "storm",
|
|
77
|
+
quality: "balanced",
|
|
78
|
+
safe: false,
|
|
79
|
+
status: "steady",
|
|
80
|
+
stepRequest: 0,
|
|
81
|
+
strikeRequested: false,
|
|
82
|
+
strikes: 0,
|
|
83
|
+
target: { ...STORM },
|
|
84
|
+
uiHidden: false,
|
|
85
|
+
uiReady: false,
|
|
86
|
+
weather: { ...STORM },
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
override load(ctx: WeatherCtx): void {
|
|
90
|
+
// Pick the study's actual cloud/reflection tier before its first render and before runner
|
|
91
|
+
// setup. The post chain's low tier alone does not change these authored passes.
|
|
92
|
+
const softwareRendering = ctx.renderer.softwareAdapter !== undefined;
|
|
93
|
+
ctx.state.set({
|
|
94
|
+
softwareRendering,
|
|
95
|
+
...(softwareRendering && ctx.state.getState().qualityExplicit !== true
|
|
96
|
+
? { quality: "performance" as const }
|
|
97
|
+
: {}),
|
|
98
|
+
});
|
|
99
|
+
ctx.state.flush();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
override enter(ctx: WeatherCtx): SceneFrame<GameState> {
|
|
103
|
+
const camera = ctx.camera as PerspectiveCamera;
|
|
104
|
+
setupCamera(camera);
|
|
105
|
+
const rig = createCameraRig(camera);
|
|
106
|
+
// The study's player is the fly camera, so that is the subject a playtest moves and measures.
|
|
107
|
+
ctx.entities.add("player", camera);
|
|
108
|
+
const loading = createLoadingScreen(ctx);
|
|
109
|
+
// The storm's noise volume is the same 64³ every run whatever the player does: it is seeded
|
|
110
|
+
// inside the render layer, because the sequence that fills it is the storm's appearance.
|
|
111
|
+
const world = createWeatherWorld(ctx.scene, camera);
|
|
112
|
+
// The world is one screen-sized quad at the origin, so the camera's own frustum would cull it
|
|
113
|
+
// the moment it looked along the coast. Marking it is how a game says "this is always drawn".
|
|
114
|
+
alwaysRender(world.quad);
|
|
115
|
+
// The rain is one instanced draw whose drops are projected by its own vertex stage, so its
|
|
116
|
+
// bounds say nothing about where they land and the same marker keeps it drawn at any heading.
|
|
117
|
+
const rain = createStormRain(ctx.scene, camera);
|
|
118
|
+
alwaysRender(rain.mesh);
|
|
119
|
+
// The bolt is drawn after the coast and depth-tested against it, so a strike behind the
|
|
120
|
+
// headland is hidden by it. Its quads are projected by its own vertex stage, like the rain.
|
|
121
|
+
const lightning = createStormLightning(ctx.scene, camera);
|
|
122
|
+
alwaysRender(lightning.mesh);
|
|
123
|
+
// Retained, not called and dropped: `update` is where the post pass learns this frame's time,
|
|
124
|
+
// exposure, rain and droplet toggle, and `uRes` is zero until it has run once.
|
|
125
|
+
const post = setupPost(ctx.renderer, ctx.scene, camera, {
|
|
126
|
+
mobile: isMobile(),
|
|
127
|
+
software: ctx.renderer.softwareAdapter !== undefined,
|
|
128
|
+
gpuClass: ctx.renderer.gpuClass?.class,
|
|
129
|
+
});
|
|
130
|
+
this.#rain = rain;
|
|
131
|
+
this.#post = post;
|
|
132
|
+
this.#lightning = lightning;
|
|
133
|
+
this.#measureClouds = world.clouds;
|
|
134
|
+
// `loading.ts` lifts its cover by making the canvas layer transparent again; that is the frame
|
|
135
|
+
// the world is on screen, so it is the frame the interface may appear on.
|
|
136
|
+
this.#curtainLifted = () => !ctx.canvasLayer.opaque;
|
|
137
|
+
// Registered, so the engine's registry disposes it with the game and `game.ts` can reach it by
|
|
138
|
+
// name for the two holds that arrive outside a frame (the pause intent and tab visibility).
|
|
139
|
+
const audio = ctx.entities.add(STORM_AUDIO_ENTITY, createStormAudio(ctx));
|
|
140
|
+
|
|
141
|
+
let weather: Weather = { ...STORM };
|
|
142
|
+
let elapsed = START_TIME;
|
|
143
|
+
let frame = 0;
|
|
144
|
+
let nextStrikeAt = START_TIME + FIRST_STRIKE_DELAY;
|
|
145
|
+
let strikeAt = -100;
|
|
146
|
+
let pendingThunderAt = -1;
|
|
147
|
+
let cinematic = false;
|
|
148
|
+
let safe = false;
|
|
149
|
+
let strikes = 0;
|
|
150
|
+
let lastStrike = { at: -1, delay: 0, metres: 0 };
|
|
151
|
+
// Where the bolt lands, and where it entered the cloud deck. The deck point is what the clouds
|
|
152
|
+
// glow around and what the coast is lit from; the ground point is what the thunder crosses.
|
|
153
|
+
// Out at sea, so a flash that lands before the first strike still lights open water.
|
|
154
|
+
const site = new Vector3(0, 0, -400);
|
|
155
|
+
const strikePoint = new Vector3(0, 180, -400);
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A strike is queued on the same clock as everything else, so the flash, the thunder and the
|
|
159
|
+
* distance it crossed cannot disagree with each other. Gated on the photosensitivity switch
|
|
160
|
+
* at the one door every path comes through, manual key and automatic alike.
|
|
161
|
+
*/
|
|
162
|
+
const strike = (): void => {
|
|
163
|
+
if (safe) return;
|
|
164
|
+
strikeAt = elapsed - 0.025;
|
|
165
|
+
site.set(
|
|
166
|
+
STRIKE_SITE.minX + ctx.random() * (STRIKE_SITE.maxX - STRIKE_SITE.minX),
|
|
167
|
+
0,
|
|
168
|
+
STRIKE_SITE.nearZ - ctx.random() * STRIKE_SITE.spread,
|
|
169
|
+
);
|
|
170
|
+
strikePoint.copy(lightning.strike(site, ctx.random));
|
|
171
|
+
const metres = rig.position.distanceTo(site);
|
|
172
|
+
const delay = thunderDelay(metres);
|
|
173
|
+
pendingThunderAt = elapsed + delay;
|
|
174
|
+
nextStrikeAt = elapsed + STRIKE_MIN_GAP + ctx.random() * STRIKE_SPREAD;
|
|
175
|
+
strikes += 1;
|
|
176
|
+
lastStrike = { at: elapsed, delay, metres };
|
|
177
|
+
// The thunder is queued on the same clock the flash is drawn against, by the same distance
|
|
178
|
+
// the delay came from, so what is heard cannot disagree with what was seen.
|
|
179
|
+
audio.queueStrike({ at: pendingThunderAt, metres });
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The keyboard shortcuts, through the same validated door the panel's controls use, so a key
|
|
184
|
+
* and a click cannot disagree about what photosensitivity mode or sound means.
|
|
185
|
+
*/
|
|
186
|
+
const readKeys = (frameCtx: WeatherCtx): void => {
|
|
187
|
+
const input = frameCtx.input;
|
|
188
|
+
const ui = frameCtx.state.getState();
|
|
189
|
+
let patch: Partial<GameState> = {};
|
|
190
|
+
if (input.justPressed("safe"))
|
|
191
|
+
patch = { ...patch, ...intentPatch("setSafe", !ui.safe, ui.target) };
|
|
192
|
+
if (input.justPressed("hideUi")) patch.uiHidden = !ui.uiHidden;
|
|
193
|
+
if (input.justPressed("sound")) {
|
|
194
|
+
const on = ui.audioEnabled && !ui.muted;
|
|
195
|
+
patch.audioEnabled = true;
|
|
196
|
+
patch.muted = on;
|
|
197
|
+
}
|
|
198
|
+
if (input.justPressed("pause")) {
|
|
199
|
+
patch.paused = !ui.paused;
|
|
200
|
+
audio.setSilenced(patch.paused);
|
|
201
|
+
}
|
|
202
|
+
if (Object.keys(patch).length > 0) frameCtx.state.set(patch);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/** Read the intent the UI sent between frames, before anything is derived from it. */
|
|
206
|
+
const readIntent = (frameCtx: WeatherCtx): GameState => {
|
|
207
|
+
readKeys(frameCtx);
|
|
208
|
+
const ui = frameCtx.state.getState();
|
|
209
|
+
// Both resets come through the same door, and each one is a fresh request: the flag is
|
|
210
|
+
// consumed and cleared below, never latched, so a second reset still lands.
|
|
211
|
+
const reset = ui.cameraReset || frameCtx.input.justPressed("resetCamera");
|
|
212
|
+
if (reset) {
|
|
213
|
+
rig.reset();
|
|
214
|
+
cinematic = false;
|
|
215
|
+
} else {
|
|
216
|
+
// Any real input hands the camera back: the orbit is a mode, not a cage.
|
|
217
|
+
cinematic = ui.cinematic && !rig.manual;
|
|
218
|
+
}
|
|
219
|
+
safe = ui.safe;
|
|
220
|
+
if (ui.strikeRequested || frameCtx.input.justPressed("strike")) strike();
|
|
221
|
+
return ui;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const advance = (ui: GameState, step: number): void => {
|
|
225
|
+
// A held simulation still draws, as the study's did: the look follows the panel at once
|
|
226
|
+
// instead of easing on a clock that is not running, and nothing else moves.
|
|
227
|
+
if (ui.paused || ui.frozen) weather = { ...ui.target };
|
|
228
|
+
if (step <= 0) return;
|
|
229
|
+
elapsed += step;
|
|
230
|
+
weather = easeWeather(weather, ui.target, step);
|
|
231
|
+
// The study's own gate: past its time, the first frame with real cloud cover strikes.
|
|
232
|
+
if (ui.autoLightning && elapsed > nextStrikeAt && weather.cloud > AUTO_STRIKE_CLOUD) strike();
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
return (frameCtx, dt) => {
|
|
236
|
+
const ui = readIntent(frameCtx);
|
|
237
|
+
// Pause holds the simulation the way the study's did — the frame is still drawn, so a drag
|
|
238
|
+
// still looks around — and `frozen` is the automation's stopped clock, which only an explicit
|
|
239
|
+
// `step` moves on. A step never runs while paused, exactly as the study's `step(dt)`.
|
|
240
|
+
const wall = ui.paused || ui.frozen ? 0 : Math.min(dt, MAX_STEP);
|
|
241
|
+
const step = wall + (ui.paused ? 0 : ui.stepRequest);
|
|
242
|
+
advance(ui, step);
|
|
243
|
+
|
|
244
|
+
const flash = safe ? 0 : flashAt(elapsed - strikeAt);
|
|
245
|
+
if (pendingThunderAt >= 0 && elapsed >= pendingThunderAt) pendingThunderAt = -1;
|
|
246
|
+
|
|
247
|
+
rig.update(wall, elapsed, frameCtx.input, cinematic);
|
|
248
|
+
// The rig only learns it is being driven once it has run, so the published flag is settled
|
|
249
|
+
// after it: a hand on the camera ends the orbit on the same frame it happened.
|
|
250
|
+
if (rig.manual) cinematic = false;
|
|
251
|
+
// Both passes read the weather this frame has just eased towards, not the target the UI
|
|
252
|
+
// asked for, so a drop and a lens bead are lit by the same air the coast is drawn with.
|
|
253
|
+
rain.update({ elapsed, flash, weather, quality: ui.quality });
|
|
254
|
+
lightning.update(flash);
|
|
255
|
+
post.update({
|
|
256
|
+
elapsed,
|
|
257
|
+
exposure: weather.exposure,
|
|
258
|
+
rain: weather.rain,
|
|
259
|
+
droplets: ui.droplets,
|
|
260
|
+
});
|
|
261
|
+
world.update({
|
|
262
|
+
elapsed,
|
|
263
|
+
flash,
|
|
264
|
+
quality: ui.quality,
|
|
265
|
+
strike: strikePoint,
|
|
266
|
+
weather,
|
|
267
|
+
});
|
|
268
|
+
loading.update();
|
|
269
|
+
frame += 1;
|
|
270
|
+
|
|
271
|
+
// Both request flags are consumed here, so the next request is a new one.
|
|
272
|
+
frameCtx.state.set({
|
|
273
|
+
cameraReset: false,
|
|
274
|
+
cinematic,
|
|
275
|
+
cloudPass: { ...frameCtx.state.getState().cloudPass, steps: world.clouds().steps },
|
|
276
|
+
dropCount: rain.instanceCount,
|
|
277
|
+
elapsed,
|
|
278
|
+
flash,
|
|
279
|
+
fps: frameCtx.fps,
|
|
280
|
+
frame,
|
|
281
|
+
heading: rig.heading,
|
|
282
|
+
lastStrike,
|
|
283
|
+
pendingThunderAt,
|
|
284
|
+
position: { x: rig.position.x, y: rig.position.y, z: rig.position.z },
|
|
285
|
+
safe,
|
|
286
|
+
stepRequest: 0,
|
|
287
|
+
strikeRequested: false,
|
|
288
|
+
strikes,
|
|
289
|
+
status: statusOf(ui.paused, flash, weather, ui.target),
|
|
290
|
+
weather,
|
|
291
|
+
});
|
|
292
|
+
frameCtx.state.flush();
|
|
293
|
+
// Last, so the mix is written from the frame that just ran rather than the one before it:
|
|
294
|
+
// `getState` already carries the patch above. The pause hold itself is an intent in
|
|
295
|
+
// `game.ts`, so the sound stops on the press rather than a frame later.
|
|
296
|
+
audio.update(frameCtx.state.getState());
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* The launch and the cloud target, published from the render hook rather than the simulation
|
|
302
|
+
* frame: a frame is drawn whether or not the clock moved (a paused or tick-driven run draws
|
|
303
|
+
* without simulating), the loading curtain must lift on the frame that shows the storm, and the
|
|
304
|
+
* cloud target is only resized by the render itself. "Ready" is the canvas loading screen in
|
|
305
|
+
* `src/render/loading.ts` having lifted, so the interface and the world appear together.
|
|
306
|
+
*/
|
|
307
|
+
override render(ctx: WeatherCtx): void {
|
|
308
|
+
const progress = ctx.startup.progress;
|
|
309
|
+
// The interface's curtain lifts with the engine's own loading screen, on the same frame.
|
|
310
|
+
const ready = this.#curtainLifted?.() ?? false;
|
|
311
|
+
const current = ctx.state.getState();
|
|
312
|
+
// Read after the frame was drawn, so it is the target the cloud pass really rendered into.
|
|
313
|
+
const clouds = this.#measureClouds?.() ?? current.cloudPass;
|
|
314
|
+
// Steps are the frame's own (set by the tier this frame simulated); the size is the render's.
|
|
315
|
+
const same =
|
|
316
|
+
current.loading.ready === ready &&
|
|
317
|
+
current.loading.progress === progress &&
|
|
318
|
+
current.cloudPass.width === clouds.width &&
|
|
319
|
+
current.cloudPass.height === clouds.height;
|
|
320
|
+
if (same) return;
|
|
321
|
+
ctx.state.set({
|
|
322
|
+
cloudPass: { ...current.cloudPass, height: clouds.height, width: clouds.width },
|
|
323
|
+
loading: { progress, ready },
|
|
324
|
+
});
|
|
325
|
+
ctx.state.flush();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** The scene is leaving: both passes were built here, so both are released here. */
|
|
329
|
+
override exit(): void {
|
|
330
|
+
this.#rain?.dispose();
|
|
331
|
+
this.#post?.dispose();
|
|
332
|
+
this.#lightning?.dispose();
|
|
333
|
+
this.#rain = undefined;
|
|
334
|
+
this.#post = undefined;
|
|
335
|
+
this.#lightning = undefined;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Derived from the frame that just ran, so the label cannot describe a frame that is over. */
|
|
340
|
+
function statusOf(paused: boolean, flash: number, weather: Weather, target: Weather): SimStatus {
|
|
341
|
+
if (paused) return "paused";
|
|
342
|
+
if (flash > 0.003) return "flashing";
|
|
343
|
+
return settled(weather, target) ? "steady" : "settling";
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function settled(current: Weather, target: Weather): boolean {
|
|
347
|
+
return WEATHER_KEYS.every((key) => Math.abs(current[key] - target[key]) < SETTLED);
|
|
348
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The weather simulation and the shape of everything the UI reads.
|
|
3
|
+
*
|
|
4
|
+
* This is game-owned maths on purpose: presets, the finite clamp at the API boundary, the
|
|
5
|
+
* exponential ease and the flash curve are the game's own rules, not a framework concept, so
|
|
6
|
+
* they live here rather than in a package.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const WEATHER_KEYS = ["rain", "cloud", "wind", "fog", "exposure", "wet"] as const;
|
|
10
|
+
|
|
11
|
+
export type WeatherKey = (typeof WEATHER_KEYS)[number];
|
|
12
|
+
|
|
13
|
+
export type Weather = Record<WeatherKey, number>;
|
|
14
|
+
|
|
15
|
+
export type PresetName = "drizzle" | "storm" | "supercell" | "clearing";
|
|
16
|
+
|
|
17
|
+
export type QualityName = "performance" | "balanced" | "high" | "ultra";
|
|
18
|
+
|
|
19
|
+
/** What the simulation is doing right now, derived — never a literal the UI can drift from. */
|
|
20
|
+
export type SimStatus = "steady" | "settling" | "flashing" | "paused";
|
|
21
|
+
|
|
22
|
+
export const PRESETS: Record<PresetName, Weather> = {
|
|
23
|
+
drizzle: { rain: 0.24, cloud: 0.48, wind: 0.2, fog: 0.2, exposure: 1.22, wet: 0.78 },
|
|
24
|
+
storm: { rain: 0.76, cloud: 0.76, wind: 0.55, fog: 0.4, exposure: 1.12, wet: 1 },
|
|
25
|
+
supercell: { rain: 1, cloud: 0.94, wind: 0.91, fog: 0.66, exposure: 1.04, wet: 1 },
|
|
26
|
+
clearing: { rain: 0.04, cloud: 0.32, wind: 0.14, fog: 0.14, exposure: 1.3, wet: 0.94 },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** A frame longer than this is a stall, and integrating it moves the weather in one visible jump. */
|
|
30
|
+
export const MAX_STEP = 0.08;
|
|
31
|
+
|
|
32
|
+
/** Seconds for the atmosphere to cover most of the gap to its target. */
|
|
33
|
+
export const EASE_TAU = 0.67;
|
|
34
|
+
|
|
35
|
+
/** Auto lightning waits for real cloud cover, so drizzle does not flash overhead. */
|
|
36
|
+
export const AUTO_STRIKE_CLOUD = 0.35;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Tab visibility, from the UI realm — the only place that knows whether the frame is still on
|
|
40
|
+
* screen, since `document` is a browser API and portable game code does not reach for one.
|
|
41
|
+
*
|
|
42
|
+
* It is answered at the intent door rather than validated into a state patch: nothing in the
|
|
43
|
+
* atmosphere changes when the tab is hidden, and the loop is stopped anyway, so no frame would ever
|
|
44
|
+
* read the field.
|
|
45
|
+
*/
|
|
46
|
+
export const VISIBILITY_INTENT = "setHidden";
|
|
47
|
+
|
|
48
|
+
const SPEED_OF_SOUND = 343;
|
|
49
|
+
|
|
50
|
+
const clamp = (value: number, min: number, max: number): number =>
|
|
51
|
+
Math.max(min, Math.min(max, value));
|
|
52
|
+
|
|
53
|
+
/** A preset by name, falling back to the storm. A copy, so a caller cannot edit the table. */
|
|
54
|
+
export function preset(name: PresetName): Weather {
|
|
55
|
+
return { ...(PRESETS[name] ?? PRESETS.storm) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The finite clamp at the API boundary: a key whose value is not a finite number keeps `base`,
|
|
60
|
+
* everything else is clamped into its range. Exposure is the one channel that is not 0..1.
|
|
61
|
+
*/
|
|
62
|
+
export function sanitizeWeather(
|
|
63
|
+
input: Partial<Record<WeatherKey, unknown>>,
|
|
64
|
+
base?: Weather,
|
|
65
|
+
): Weather {
|
|
66
|
+
const result = { ...(base ?? preset("storm")) };
|
|
67
|
+
for (const key of WEATHER_KEYS) {
|
|
68
|
+
const value = Number(input[key]);
|
|
69
|
+
if (input[key] === undefined || !Number.isFinite(value)) continue;
|
|
70
|
+
result[key] = key === "exposure" ? clamp(value, 0.3, 2) : clamp(value, 0, 1);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Exponential ease towards the target, independent of frame rate because `dt` is real seconds. */
|
|
76
|
+
export function easeWeather(current: Weather, target: Weather, dt: number): Weather {
|
|
77
|
+
const k = 1 - Math.exp(-dt / EASE_TAU);
|
|
78
|
+
const next = { ...current };
|
|
79
|
+
for (const key of WEATHER_KEYS) next[key] = current[key] + (target[key] - current[key]) * k;
|
|
80
|
+
return next;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Every UI toggle, and the state field each one actually writes. The intent name is the UI's
|
|
85
|
+
* vocabulary and the field is the game's, so the mapping lives in one table rather than as six
|
|
86
|
+
* spelled-out cases that can drift apart.
|
|
87
|
+
*/
|
|
88
|
+
export const TOGGLE_FIELDS = {
|
|
89
|
+
setAudioEnabled: "audioEnabled",
|
|
90
|
+
setAutoLightning: "autoLightning",
|
|
91
|
+
setCinematic: "cinematic",
|
|
92
|
+
setDroplets: "droplets",
|
|
93
|
+
setFrozen: "frozen",
|
|
94
|
+
setMuted: "muted",
|
|
95
|
+
setSafe: "safe",
|
|
96
|
+
} as const satisfies Record<string, keyof GameState>;
|
|
97
|
+
|
|
98
|
+
const QUALITIES: readonly QualityName[] = ["performance", "balanced", "high", "ultra"];
|
|
99
|
+
|
|
100
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
101
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A weather payload turned into a clamped target, or a throw. Every channel is checked before any
|
|
105
|
+
* is written, so a malformed payload leaves the atmosphere exactly where it was rather than
|
|
106
|
+
* half-moved, and only real finite numbers are accepted: a slider that emits `null` or `"0.5"` is
|
|
107
|
+
* a bug in the control, not a value to coerce.
|
|
108
|
+
*/
|
|
109
|
+
function weatherTarget(payload: unknown, base: Weather): Weather {
|
|
110
|
+
if (!isRecord(payload)) throw new Error("expected an object of weather channels");
|
|
111
|
+
const patch: Partial<Record<WeatherKey, number>> = {};
|
|
112
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
113
|
+
if (!(WEATHER_KEYS as readonly string[]).includes(key)) {
|
|
114
|
+
throw new Error(`${key} is not a weather channel`);
|
|
115
|
+
}
|
|
116
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
117
|
+
throw new Error(`${key} must be a finite number`);
|
|
118
|
+
}
|
|
119
|
+
patch[key as WeatherKey] = value;
|
|
120
|
+
}
|
|
121
|
+
return sanitizeWeather(patch, base);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The one door every UI intent comes through: intent name and payload in, the state patch the
|
|
126
|
+
* game applies out. It throws on a malformed payload and it takes the current target as an
|
|
127
|
+
* argument, so it is the whole rule set with no engine, no GPU and no module state — which is
|
|
128
|
+
* also what the automation API will call.
|
|
129
|
+
*/
|
|
130
|
+
export function intentPatch(
|
|
131
|
+
intent: string,
|
|
132
|
+
payload: unknown,
|
|
133
|
+
currentTarget: Weather,
|
|
134
|
+
): Partial<GameState> {
|
|
135
|
+
const toggle = Object.hasOwn(TOGGLE_FIELDS, intent)
|
|
136
|
+
? TOGGLE_FIELDS[intent as keyof typeof TOGGLE_FIELDS]
|
|
137
|
+
: undefined;
|
|
138
|
+
if (toggle !== undefined) {
|
|
139
|
+
if (typeof payload !== "boolean") throw new Error("expected a boolean payload");
|
|
140
|
+
// Photosensitivity mode also takes automatic lightning down, at the one door every caller
|
|
141
|
+
// uses: a reader who asked for no flashes must not get them from the sky on their own.
|
|
142
|
+
if (toggle === "safe" && payload) return { autoLightning: false, safe: true };
|
|
143
|
+
return { [toggle]: payload } as Partial<GameState>;
|
|
144
|
+
}
|
|
145
|
+
switch (intent) {
|
|
146
|
+
case "setPreset": {
|
|
147
|
+
// Own keys only: `in` would accept `toString` and hand back the storm's prototype.
|
|
148
|
+
if (typeof payload !== "string" || !Object.hasOwn(PRESETS, payload)) {
|
|
149
|
+
throw new Error("expected one of drizzle, storm, supercell, clearing");
|
|
150
|
+
}
|
|
151
|
+
const name = payload as PresetName;
|
|
152
|
+
return { preset: name, target: { ...PRESETS[name] } };
|
|
153
|
+
}
|
|
154
|
+
case "setQuality":
|
|
155
|
+
if (!QUALITIES.includes(payload as QualityName)) {
|
|
156
|
+
throw new Error("expected performance, balanced, high or ultra");
|
|
157
|
+
}
|
|
158
|
+
return { quality: payload as QualityName, qualityExplicit: true };
|
|
159
|
+
case "setWeather":
|
|
160
|
+
return { target: weatherTarget(payload, currentTarget) };
|
|
161
|
+
case "pause":
|
|
162
|
+
return { paused: true };
|
|
163
|
+
case "resume":
|
|
164
|
+
return { paused: false };
|
|
165
|
+
case "resetCamera":
|
|
166
|
+
// The scene owns the rig, so this is a request it acts on and clears.
|
|
167
|
+
return { cameraReset: true, cinematic: false };
|
|
168
|
+
case "strike":
|
|
169
|
+
// A request, not a value: the scene owns the clock the flash is measured against.
|
|
170
|
+
return { strikeRequested: true };
|
|
171
|
+
case "step":
|
|
172
|
+
// The automation's `step(dt)`: seconds of simulation for the next frame, clamped as the
|
|
173
|
+
// study clamped them. Consumed by that frame, and ignored while paused.
|
|
174
|
+
if (typeof payload !== "number" || !Number.isFinite(payload)) {
|
|
175
|
+
throw new Error("expected a finite number of seconds");
|
|
176
|
+
}
|
|
177
|
+
return { stepRequest: clamp(payload, 0, 60) };
|
|
178
|
+
case "hideUi":
|
|
179
|
+
return { uiHidden: true };
|
|
180
|
+
case "showUi":
|
|
181
|
+
return { uiHidden: false };
|
|
182
|
+
case "help":
|
|
183
|
+
return { helpOpen: true };
|
|
184
|
+
case "closeHelp":
|
|
185
|
+
return { helpOpen: false };
|
|
186
|
+
default:
|
|
187
|
+
throw new Error(`${intent} is not a rain intent`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** The four-peak flash envelope: one strike is a stutter, not one fade. */
|
|
192
|
+
export function flashAt(secondsSinceStrike: number): number {
|
|
193
|
+
if (secondsSinceStrike < 0 || secondsSinceStrike > 0.82) return 0;
|
|
194
|
+
return Math.min(
|
|
195
|
+
2.4,
|
|
196
|
+
1.6 * Math.exp(-secondsSinceStrike * 34) +
|
|
197
|
+
1.2 * Math.exp(-(((secondsSinceStrike - 0.105) / 0.016) ** 2)) +
|
|
198
|
+
1.7 * Math.exp(-(((secondsSinceStrike - 0.21) / 0.025) ** 2)) +
|
|
199
|
+
0.32 * Math.exp(-(((secondsSinceStrike - 0.38) / 0.09) ** 2)),
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Thunder arrives after the sound crosses the distance it was struck at. */
|
|
204
|
+
export function thunderDelay(metres: number): number {
|
|
205
|
+
return Math.max(0, Number.isFinite(metres) ? metres : 0) / SPEED_OF_SOUND;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type GameState = {
|
|
209
|
+
/** Where the atmosphere is now, which is what the scene actually drew. */
|
|
210
|
+
weather: Weather;
|
|
211
|
+
/** Where it is heading. The UI writes here; the simulation eases `weather` towards it. */
|
|
212
|
+
target: Weather;
|
|
213
|
+
preset: PresetName;
|
|
214
|
+
quality: QualityName;
|
|
215
|
+
/** A URL or player choice outranks the scene's first-frame default. */
|
|
216
|
+
qualityExplicit?: boolean;
|
|
217
|
+
/** Observed before scene entry; the UI must not infer an adapter from window width. */
|
|
218
|
+
softwareRendering?: boolean;
|
|
219
|
+
elapsed: number;
|
|
220
|
+
frame: number;
|
|
221
|
+
flash: number;
|
|
222
|
+
safe: boolean;
|
|
223
|
+
droplets: boolean;
|
|
224
|
+
autoLightning: boolean;
|
|
225
|
+
cinematic: boolean;
|
|
226
|
+
audioEnabled: boolean;
|
|
227
|
+
muted: boolean;
|
|
228
|
+
paused: boolean;
|
|
229
|
+
uiHidden: boolean;
|
|
230
|
+
helpOpen: boolean;
|
|
231
|
+
uiReady: boolean;
|
|
232
|
+
heading: number;
|
|
233
|
+
/** Where the fly camera stands, in metres, so a move is read back rather than assumed. */
|
|
234
|
+
position: { x: number; y: number; z: number };
|
|
235
|
+
fps: number;
|
|
236
|
+
/**
|
|
237
|
+
* Drops the renderer was actually asked to draw this frame — the rain geometry's own
|
|
238
|
+
* `instanceCount`, not the budget it was derived from, so the readout cannot report a number the
|
|
239
|
+
* GPU was never handed.
|
|
240
|
+
*/
|
|
241
|
+
dropCount: number;
|
|
242
|
+
/** Absolute simulation time thunder is due, or -1 when nothing is in the air. */
|
|
243
|
+
pendingThunderAt: number;
|
|
244
|
+
/** Strikes so far, manual and automatic, that got past the photosensitivity gate. */
|
|
245
|
+
strikes: number;
|
|
246
|
+
/** The last strike: simulation time, metres from the camera, and its thunder delay in seconds. */
|
|
247
|
+
lastStrike: { at: number; delay: number; metres: number };
|
|
248
|
+
/** The cloud target the renderer really drew last frame, and the march steps it ran. */
|
|
249
|
+
cloudPass: { width: number; height: number; steps: number };
|
|
250
|
+
/** The engine's launch: how far first-use compilation has got, and whether the frame is ready. */
|
|
251
|
+
loading: { progress: number; ready: boolean };
|
|
252
|
+
/** The automation's stopped clock: frames still draw, only `stepRequest` advances it. */
|
|
253
|
+
frozen: boolean;
|
|
254
|
+
/** Seconds the next frame simulates on top of its own, from `step(dt)`. Cleared once used. */
|
|
255
|
+
stepRequest: number;
|
|
256
|
+
status: SimStatus;
|
|
257
|
+
/** Set by the reset-camera intent, cleared by the frame that acted on it. */
|
|
258
|
+
cameraReset: boolean;
|
|
259
|
+
/** Set by the strike intent, cleared by the frame that struck. */
|
|
260
|
+
strikeRequested: boolean;
|
|
261
|
+
};
|