create-threenative 0.2.10 → 0.2.12
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/agent-docs/references/assertion-reference.md +109 -3
- package/agent-docs/references/auto-exposure.md +28 -45
- package/agent-docs/references/build-profiles.md +1 -1
- package/agent-docs/references/capability-reference.md +527 -44
- package/agent-docs/references/debug-surface.md +64 -0
- package/agent-docs/references/finding-assets.md +11 -12
- package/agent-docs/references/performance-basics.md +19 -0
- package/agent-docs/references/trace-a-slow-frame.md +21 -0
- package/agent-docs/references/visual-baseline.md +23 -4
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/prd-creator/SKILL.md +17 -6
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +87 -23
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +12 -11
- package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
- package/agent-files/scripts/reference.mjs +9 -4
- package/capabilities.json +739 -50
- package/dist/index.d.ts +40 -6
- package/dist/index.js +227 -34
- package/dist/quality.d.ts +12 -0
- package/dist/quality.js +166747 -0
- package/dist/threenative.js +60 -44
- package/dist/web-engine-gltf-loader.js +2 -0
- package/dist/web-engine-mesh-bvh-webgpu.js +1 -1
- package/dist/web-engine-mesh-bvh.js +7 -0
- package/dist/web-engine-post-effects.js +645 -19
- package/dist/web-engine-runtime.js +3528 -343
- package/package.json +19 -9
- package/template-assets/assets/bay-PROVENANCE.md +21 -0
- package/template-assets/assets/bay-ground.webp +0 -0
- package/template-assets/assets/bay-metal.webp +0 -0
- package/template-assets/assets/bay-pavement-normal.webp +0 -0
- package/template-assets/assets/bay-pavement.webp +0 -0
- package/template-assets/assets/bay-plaster-normal.webp +0 -0
- package/template-assets/assets/bay-plaster.webp +0 -0
- package/template-assets/assets/bay-wood-normal.webp +0 -0
- package/template-assets/assets/bay-wood.webp +0 -0
- package/template-assets/assets/tex-PROVENANCE.md +25 -0
- package/template-assets/assets/tex-bark-normal.webp +0 -0
- package/template-assets/assets/tex-bark.webp +0 -0
- package/template-assets/assets/tex-birch-bark.webp +0 -0
- package/template-assets/assets/tex-grass.webp +0 -0
- package/template-assets/assets/tex-planks-normal.webp +0 -0
- package/template-assets/assets/tex-planks.webp +0 -0
- package/template-assets/assets/tex-rock-normal.webp +0 -0
- package/template-assets/assets/tex-rock.webp +0 -0
- package/template-assets/assets/tex-roof-tiles-normal.webp +0 -0
- package/template-assets/assets/tex-roof-tiles.webp +0 -0
- package/template-assets/assets/tex-sand-normal.webp +0 -0
- package/template-assets/assets/tex-sand.webp +0 -0
- package/template-assets/assets/tex-stone-wall-normal.webp +0 -0
- package/template-assets/assets/tex-stone-wall.webp +0 -0
- package/template-assets/kitExposure.ts +20 -0
- package/template-assets/patches/three@0.185.1.patch +481 -272
- package/template-assets/quality/biome.json +7 -0
- package/template-assets/quality/eslint.config.js +3 -0
- package/template-assets/realistic-ocean/README.md +113 -0
- package/template-assets/realistic-ocean/install.mjs +56 -0
- package/template-assets/realistic-ocean/src/realisticOcean.ts +151 -0
- package/template-assets/realistic-ocean/src/realisticOceanLifetime.ts +29 -0
- package/template-assets/realistic-ocean/src/render/REALISTIC-OCEAN-LICENSE.txt +25 -0
- package/template-assets/realistic-ocean/src/render/realisticSea.ts +642 -0
- package/template-assets/realistic-ocean/src/render/realisticSeaMaps.ts +311 -0
- package/template-assets/realistic-ocean/src/render/realisticSpectrum.ts +289 -0
- package/templates/AGENTS.md +21 -0
- package/templates/CLAUDE.md +23 -0
- package/templates/action-rpg/.codex/config.toml +6 -2
- package/templates/action-rpg/.cursor/mcp.json +8 -2
- package/templates/action-rpg/.gemini/settings.json +8 -2
- package/templates/action-rpg/.mcp.json +8 -2
- package/templates/action-rpg/.vscode/mcp.json +9 -2
- package/templates/action-rpg/.zed/settings.json +9 -2
- package/templates/action-rpg/AGENTS.md +11 -11
- package/templates/action-rpg/CLAUDE.md +11 -11
- package/templates/action-rpg/opencode.json +10 -2
- package/templates/action-rpg/package.json +15 -10
- package/templates/action-rpg/playtests/combat.playtest.json +6 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +22 -0
- package/templates/action-rpg/playtests/performance.playtest.json +1 -1
- package/templates/action-rpg/playtests/roll.playtest.json +112 -0
- package/templates/action-rpg/playtests/swing.playtest.json +55 -0
- package/templates/action-rpg/playtests/win.playtest.json +4 -4
- package/templates/action-rpg/src/entities/Fighter.ts +44 -4
- package/templates/action-rpg/src/entities/Player.ts +64 -12
- package/templates/action-rpg/src/render/atmosphere.ts +444 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +49 -18
- package/templates/action-rpg/src/render/clouds.ts +605 -0
- package/templates/action-rpg/src/render/dungeon.ts +8 -6
- package/templates/action-rpg/src/render/exposure.ts +11 -109
- package/templates/action-rpg/src/render/gpuSky.ts +752 -0
- package/templates/action-rpg/src/render/lighting.ts +27 -4
- package/templates/action-rpg/src/render/materialLighting.ts +2 -11
- package/templates/action-rpg/src/render/palette.ts +1 -0
- package/templates/action-rpg/src/render/postprocessing.ts +4 -4
- package/templates/action-rpg/src/render/props.ts +10 -8
- package/templates/action-rpg/src/render/quality.ts +56 -108
- package/templates/action-rpg/src/render/sky.ts +74 -1
- package/templates/action-rpg/src/scenes/Play.ts +16 -12
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +7 -2
- package/templates/action-rpg/src/ui/Hud.tsx +5 -7
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +14 -14
- package/templates/action-rpg/threenative.config.ts +3 -0
- package/templates/adventure/.codex/config.toml +23 -0
- package/templates/adventure/.cursor/mcp.json +38 -0
- package/templates/adventure/.gemini/settings.json +38 -0
- package/templates/adventure/.mcp.json +38 -0
- package/templates/adventure/.vscode/mcp.json +43 -0
- package/templates/adventure/.zed/settings.json +43 -0
- package/templates/adventure/AGENTS.md +60 -0
- package/templates/adventure/CLAUDE.md +62 -0
- package/templates/adventure/index.html +14 -0
- package/templates/adventure/kit.json +8 -0
- package/templates/adventure/native-playtests/survives.playtest.json +52 -0
- package/templates/adventure/opencode.json +49 -0
- package/templates/adventure/package.json +65 -0
- package/templates/adventure/playtests/boss.playtest.json +406 -0
- package/templates/adventure/playtests/combat.playtest.json +342 -0
- package/templates/adventure/playtests/controls.playtest.json +142 -0
- package/templates/adventure/playtests/explore.playtest.json +45 -0
- package/templates/adventure/playtests/flicker.playtest.json +206 -0
- package/templates/adventure/playtests/hearts.playtest.json +171 -0
- package/templates/adventure/playtests/lockon.playtest.json +256 -0
- package/templates/adventure/playtests/look.playtest.json +72 -0
- package/templates/adventure/playtests/move-hollow.playtest.json +106 -0
- package/templates/adventure/playtests/move.playtest.json +84 -0
- package/templates/adventure/playtests/performance.playtest.json +55 -0
- package/templates/adventure/playtests/puzzle.playtest.json +250 -0
- package/templates/adventure/playtests/stride.playtest.json +67 -0
- package/templates/adventure/playtests/survives.playtest.json +171 -0
- package/templates/adventure/playtests/thornback.playtest.json +267 -0
- package/templates/adventure/public/favicon.svg +4 -0
- package/templates/adventure/src/entities/Block.ts +114 -0
- package/templates/adventure/src/entities/Chest.ts +69 -0
- package/templates/adventure/src/entities/Door.ts +81 -0
- package/templates/adventure/src/entities/Dummy.ts +69 -0
- package/templates/adventure/src/entities/Flicker.ts +239 -0
- package/templates/adventure/src/entities/Hero.ts +561 -0
- package/templates/adventure/src/entities/LockOn.ts +180 -0
- package/templates/adventure/src/entities/Mossling.ts +249 -0
- package/templates/adventure/src/entities/Switch.ts +49 -0
- package/templates/adventure/src/entities/Thornback.ts +238 -0
- package/templates/adventure/src/entities/Warden.ts +196 -0
- package/templates/adventure/src/game.ts +65 -0
- package/templates/adventure/src/interact.ts +63 -0
- package/templates/adventure/src/level/Hollow.ts +240 -0
- package/templates/adventure/src/level/Vale.ts +383 -0
- package/templates/adventure/src/main.ts +18 -0
- package/templates/adventure/src/render/camera.ts +416 -0
- package/templates/adventure/src/render/creatures.ts +405 -0
- package/templates/adventure/src/render/effects.ts +333 -0
- package/templates/adventure/src/render/foliage.ts +1072 -0
- package/templates/adventure/src/render/hero.ts +1447 -0
- package/templates/adventure/src/render/kitExposure.ts +20 -0
- package/templates/adventure/src/render/lighting.ts +74 -0
- package/templates/adventure/src/render/loading.ts +332 -0
- package/templates/adventure/src/render/materials.ts +179 -0
- package/templates/adventure/src/render/palette.ts +137 -0
- package/templates/adventure/src/render/postprocessing.ts +70 -0
- package/templates/adventure/src/render/props.ts +383 -0
- package/templates/adventure/src/render/quality.ts +46 -0
- package/templates/adventure/src/render/sky.ts +271 -0
- package/templates/adventure/src/render/surface.ts +259 -0
- package/templates/adventure/src/render/touch-controls.ts +137 -0
- package/templates/adventure/src/scenes/Play.ts +959 -0
- package/templates/adventure/src/state.ts +113 -0
- package/templates/adventure/src/style.css +98 -0
- package/templates/adventure/src/ui/App.tsx +22 -0
- package/templates/adventure/src/ui/GameUi.tsx +20 -0
- package/templates/adventure/src/ui/Hud.tsx +70 -0
- package/templates/adventure/src/ui/Menu.tsx +15 -0
- package/templates/adventure/src/ui/main.tsx +14 -0
- package/templates/adventure/tailwind.config.ts +2 -0
- package/templates/adventure/threenative.config.ts +62 -0
- package/templates/adventure/tsconfig.json +17 -0
- package/templates/adventure/vite.config.ts +49 -0
- package/templates/collectathon/.codex/config.toml +23 -0
- package/templates/collectathon/.cursor/mcp.json +38 -0
- package/templates/collectathon/.gemini/settings.json +38 -0
- package/templates/collectathon/.mcp.json +38 -0
- package/templates/collectathon/.vscode/mcp.json +43 -0
- package/templates/collectathon/.zed/settings.json +43 -0
- package/templates/collectathon/AGENTS.md +58 -0
- package/templates/collectathon/CLAUDE.md +60 -0
- package/templates/collectathon/index.html +14 -0
- package/templates/collectathon/kit.json +8 -0
- package/templates/collectathon/native-playtests/survives.playtest.json +52 -0
- package/templates/collectathon/opencode.json +49 -0
- package/templates/collectathon/package.json +65 -0
- package/templates/collectathon/playtests/acrobatics.playtest.json +238 -0
- package/templates/collectathon/playtests/camera.playtest.json +80 -0
- package/templates/collectathon/playtests/clipped-probe.playtest.json +101 -0
- package/templates/collectathon/playtests/collect.playtest.json +196 -0
- package/templates/collectathon/playtests/combat.playtest.json +246 -0
- package/templates/collectathon/playtests/double-tap-air.playtest.json +198 -0
- package/templates/collectathon/playtests/double-tap.playtest.json +136 -0
- package/templates/collectathon/playtests/effects.playtest.json +124 -0
- package/templates/collectathon/playtests/enemies.playtest.json +295 -0
- package/templates/collectathon/playtests/explore.playtest.json +45 -0
- package/templates/collectathon/playtests/hop-reach.playtest.json +117 -0
- package/templates/collectathon/playtests/jump-chain.playtest.json +274 -0
- package/templates/collectathon/playtests/ledge-angle.playtest.json +107 -0
- package/templates/collectathon/playtests/ledge-too-high.playtest.json +115 -0
- package/templates/collectathon/playtests/ledge.playtest.json +100 -0
- package/templates/collectathon/playtests/look.playtest.json +64 -0
- package/templates/collectathon/playtests/performance.playtest.json +55 -0
- package/templates/collectathon/playtests/stride.playtest.json +111 -0
- package/templates/collectathon/playtests/survives.playtest.json +123 -0
- package/templates/collectathon/playtests/telegraphs.playtest.json +132 -0
- package/templates/collectathon/playtests/thornback.playtest.json +157 -0
- package/templates/collectathon/playtests/wall-kick.playtest.json +206 -0
- package/templates/collectathon/playtests/win.playtest.json +166 -0
- package/templates/collectathon/public/favicon.svg +4 -0
- package/templates/collectathon/src/entities/Hero.ts +915 -0
- package/templates/collectathon/src/entities/Pickup.ts +63 -0
- package/templates/collectathon/src/entities/Walker.ts +248 -0
- package/templates/collectathon/src/game.ts +51 -0
- package/templates/collectathon/src/level/Course.ts +590 -0
- package/templates/collectathon/src/level/terrain.ts +144 -0
- package/templates/collectathon/src/main.ts +14 -0
- package/templates/collectathon/src/playtest-events.ts +15 -0
- package/templates/collectathon/src/render/camera.ts +163 -0
- package/templates/collectathon/src/render/castle.ts +408 -0
- package/templates/collectathon/src/render/effects.ts +284 -0
- package/templates/collectathon/src/render/foliage.ts +744 -0
- package/templates/collectathon/src/render/ground.ts +139 -0
- package/templates/collectathon/src/render/hero.ts +452 -0
- package/templates/collectathon/src/render/kitExposure.ts +20 -0
- package/templates/collectathon/src/render/lighting.ts +65 -0
- package/templates/collectathon/src/render/loading.ts +332 -0
- package/templates/collectathon/src/render/materials.ts +196 -0
- package/templates/collectathon/src/render/palette.ts +82 -0
- package/templates/collectathon/src/render/postprocessing.ts +79 -0
- package/templates/collectathon/src/render/props.ts +218 -0
- package/templates/collectathon/src/render/quality.ts +54 -0
- package/templates/collectathon/src/render/sky.ts +262 -0
- package/templates/collectathon/src/render/surface.ts +269 -0
- package/templates/collectathon/src/render/touch-controls.ts +179 -0
- package/templates/collectathon/src/render/touch-layout.ts +48 -0
- package/templates/collectathon/src/render/water.ts +191 -0
- package/templates/collectathon/src/scenes/Play.ts +481 -0
- package/templates/collectathon/src/state.ts +38 -0
- package/templates/collectathon/src/style.css +106 -0
- package/templates/collectathon/src/ui/App.tsx +22 -0
- package/templates/collectathon/src/ui/GameUi.tsx +20 -0
- package/templates/collectathon/src/ui/Hud.tsx +77 -0
- package/templates/collectathon/src/ui/Menu.tsx +13 -0
- package/templates/collectathon/src/ui/main.tsx +14 -0
- package/templates/collectathon/tailwind.config.ts +2 -0
- package/templates/collectathon/threenative.config.ts +62 -0
- package/templates/collectathon/tsconfig.json +17 -0
- package/templates/collectathon/vite.config.ts +49 -0
- package/templates/kart/.codex/config.toml +23 -0
- package/templates/kart/.cursor/mcp.json +38 -0
- package/templates/kart/.gemini/settings.json +38 -0
- package/templates/kart/.mcp.json +38 -0
- package/templates/kart/.vscode/mcp.json +43 -0
- package/templates/kart/.zed/settings.json +43 -0
- package/templates/kart/AGENTS.md +58 -0
- package/templates/kart/CLAUDE.md +60 -0
- package/templates/kart/index.html +14 -0
- package/templates/kart/kit.json +8 -0
- package/templates/kart/native-playtests/survives.playtest.json +65 -0
- package/templates/kart/opencode.json +49 -0
- package/templates/kart/package.json +64 -0
- package/templates/kart/playtests/drift.playtest.json +226 -0
- package/templates/kart/playtests/explore.playtest.json +45 -0
- package/templates/kart/playtests/hit-stays-above-road.playtest.json +92 -0
- package/templates/kart/playtests/item-key.playtest.json +108 -0
- package/templates/kart/playtests/items.playtest.json +143 -0
- package/templates/kart/playtests/lap-times.playtest.json +138 -0
- package/templates/kart/playtests/laps.playtest.json +149 -0
- package/templates/kart/playtests/performance.playtest.json +57 -0
- package/templates/kart/playtests/race.playtest.json +294 -0
- package/templates/kart/playtests/restart.playtest.json +87 -0
- package/templates/kart/playtests/rocket-start.playtest.json +56 -0
- package/templates/kart/playtests/smooth-drive.playtest.json +101 -0
- package/templates/kart/playtests/surfaces.playtest.json +113 -0
- package/templates/kart/playtests/survives.playtest.json +116 -0
- package/templates/kart/playtests/wall.playtest.json +118 -0
- package/templates/kart/public/favicon.svg +4 -0
- package/templates/kart/src/entities/Driver.ts +123 -0
- package/templates/kart/src/entities/Items.ts +194 -0
- package/templates/kart/src/entities/Kart.ts +517 -0
- package/templates/kart/src/game.ts +45 -0
- package/templates/kart/src/main.ts +14 -0
- package/templates/kart/src/playtest-events.ts +15 -0
- package/templates/kart/src/render/camera.ts +83 -0
- package/templates/kart/src/render/course.ts +579 -0
- package/templates/kart/src/render/effects.ts +266 -0
- package/templates/kart/src/render/items.ts +163 -0
- package/templates/kart/src/render/kart.ts +256 -0
- package/templates/kart/src/render/kitExposure.ts +20 -0
- package/templates/kart/src/render/lighting.ts +58 -0
- package/templates/kart/src/render/loading.ts +332 -0
- package/templates/kart/src/render/materials.ts +119 -0
- package/templates/kart/src/render/palette.ts +74 -0
- package/templates/kart/src/render/postprocessing.ts +79 -0
- package/templates/kart/src/render/quality.ts +54 -0
- package/templates/kart/src/render/skids.ts +86 -0
- package/templates/kart/src/render/sky.ts +105 -0
- package/templates/kart/src/render/touch-controls.ts +168 -0
- package/templates/kart/src/render/touch-layout.ts +48 -0
- package/templates/kart/src/scenes/Race.ts +850 -0
- package/templates/kart/src/state.ts +53 -0
- package/templates/kart/src/style.css +106 -0
- package/templates/kart/src/track/Course.ts +276 -0
- package/templates/kart/src/track/Race.ts +133 -0
- package/templates/kart/src/ui/App.tsx +21 -0
- package/templates/kart/src/ui/GameUi.tsx +20 -0
- package/templates/kart/src/ui/Hud.tsx +172 -0
- package/templates/kart/src/ui/Menu.tsx +13 -0
- package/templates/kart/src/ui/main.tsx +14 -0
- package/templates/kart/tailwind.config.ts +2 -0
- package/templates/kart/threenative.config.ts +62 -0
- package/templates/kart/tsconfig.json +17 -0
- package/templates/kart/vite.config.ts +49 -0
- package/templates/minimal/.codex/config.toml +6 -2
- package/templates/minimal/.cursor/mcp.json +8 -2
- package/templates/minimal/.gemini/settings.json +8 -2
- package/templates/minimal/.mcp.json +8 -2
- package/templates/minimal/.vscode/mcp.json +9 -2
- package/templates/minimal/.zed/settings.json +9 -2
- package/templates/minimal/AGENTS.md +11 -13
- package/templates/minimal/CLAUDE.md +11 -13
- package/templates/minimal/opencode.json +10 -2
- package/templates/minimal/package.json +14 -9
- package/templates/minimal/playtests/camera-wall.playtest.json +36 -0
- package/templates/minimal/playtests/jump.playtest.json +45 -0
- package/templates/minimal/playtests/play.playtest.json +1 -1
- package/templates/minimal/src/game.ts +2 -0
- package/templates/minimal/src/render/atmosphere.ts +444 -0
- package/templates/minimal/src/render/backlightMaterial.ts +49 -18
- package/templates/minimal/src/render/camera.ts +35 -4
- package/templates/minimal/src/render/clouds.ts +605 -0
- package/templates/minimal/src/render/exposure.ts +7 -111
- package/templates/minimal/src/render/gpuSky.ts +752 -0
- package/templates/minimal/src/render/lighting.ts +26 -4
- package/templates/minimal/src/render/materialLighting.ts +2 -10
- package/templates/minimal/src/render/postprocessing.ts +4 -4
- package/templates/minimal/src/render/quality.ts +10 -116
- package/templates/minimal/src/render/sky.ts +73 -1
- package/templates/minimal/src/scenes/Play.ts +18 -7
- package/templates/platformer/.codex/config.toml +6 -2
- package/templates/platformer/.cursor/mcp.json +8 -2
- package/templates/platformer/.gemini/settings.json +8 -2
- package/templates/platformer/.mcp.json +8 -2
- package/templates/platformer/.vscode/mcp.json +9 -2
- package/templates/platformer/.zed/settings.json +9 -2
- package/templates/platformer/AGENTS.md +13 -9
- package/templates/platformer/CLAUDE.md +13 -9
- package/templates/platformer/opencode.json +10 -2
- package/templates/platformer/package.json +15 -10
- package/templates/platformer/playtests/dash-jump.playtest.json +34 -0
- package/templates/platformer/playtests/finish.playtest.json +58 -0
- package/templates/platformer/playtests/idle.playtest.json +44 -0
- package/templates/platformer/playtests/performance.playtest.json +1 -1
- package/templates/platformer/src/entities/Fox.ts +19 -6
- package/templates/platformer/src/game.ts +1 -0
- package/templates/platformer/src/level/Stage.ts +4 -1
- package/templates/platformer/src/render/backlightMaterial.ts +49 -18
- package/templates/platformer/src/render/camera.ts +30 -1
- package/templates/platformer/src/render/exposure.ts +6 -111
- package/templates/platformer/src/render/fox.ts +5 -2
- package/templates/platformer/src/render/kitExposure.ts +20 -0
- package/templates/platformer/src/render/materialLighting.ts +2 -11
- package/templates/platformer/src/render/postprocessing.ts +4 -4
- package/templates/platformer/src/render/props.ts +1 -2
- package/templates/platformer/src/render/quality.ts +10 -118
- package/templates/platformer/src/scenes/Play.ts +31 -15
- package/templates/platformer/src/ui/Menu.tsx +1 -1
- package/templates/puzzle/.codex/config.toml +6 -2
- package/templates/puzzle/.cursor/mcp.json +8 -2
- package/templates/puzzle/.gemini/settings.json +8 -2
- package/templates/puzzle/.mcp.json +8 -2
- package/templates/puzzle/.vscode/mcp.json +9 -2
- package/templates/puzzle/.zed/settings.json +9 -2
- package/templates/puzzle/AGENTS.md +14 -17
- package/templates/puzzle/CLAUDE.md +14 -17
- package/templates/puzzle/opencode.json +10 -2
- package/templates/puzzle/package.json +15 -10
- package/templates/puzzle/playtests/performance.playtest.json +1 -1
- package/templates/puzzle/playtests/replay-keeps-progress.playtest.json +78 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +49 -18
- package/templates/puzzle/src/render/exposure.ts +11 -109
- package/templates/puzzle/src/render/lighting.ts +3 -3
- package/templates/puzzle/src/render/materialLighting.ts +2 -11
- package/templates/puzzle/src/render/palette.ts +1 -1
- package/templates/puzzle/src/render/postprocessing.ts +4 -4
- package/templates/puzzle/src/render/quality.ts +44 -153
- package/templates/puzzle/src/render/vault.ts +18 -6
- package/templates/puzzle/src/scenes/Play.ts +6 -1
- package/templates/puzzle/src/ui/Hud.tsx +8 -43
- package/templates/racing/.codex/config.toml +6 -2
- package/templates/racing/.cursor/mcp.json +8 -2
- package/templates/racing/.gemini/settings.json +8 -2
- package/templates/racing/.mcp.json +8 -2
- package/templates/racing/.vscode/mcp.json +9 -2
- package/templates/racing/.zed/settings.json +9 -2
- package/templates/racing/AGENTS.md +10 -12
- package/templates/racing/CLAUDE.md +10 -12
- package/templates/racing/opencode.json +10 -2
- package/templates/racing/package.json +15 -10
- package/templates/racing/playtests/brake.playtest.json +54 -0
- package/templates/racing/playtests/outcome.playtest.json +19 -0
- package/templates/racing/playtests/performance.playtest.json +1 -1
- package/templates/racing/playtests/stopped-car-is-not-rescued.playtest.json +59 -0
- package/templates/racing/src/entities/RacingCar.ts +12 -3
- package/templates/racing/src/entities/Rival.ts +11 -2
- package/templates/racing/src/render/atmosphere.ts +444 -0
- package/templates/racing/src/render/backlightMaterial.ts +49 -18
- package/templates/racing/src/render/clouds.ts +605 -0
- package/templates/racing/src/render/exposure.ts +6 -111
- package/templates/racing/src/render/gpuSky.ts +752 -0
- package/templates/racing/src/render/kitExposure.ts +20 -0
- package/templates/racing/src/render/lighting.ts +26 -4
- package/templates/racing/src/render/materialLighting.ts +2 -11
- package/templates/racing/src/render/materials.ts +2 -1
- package/templates/racing/src/render/postprocessing.ts +4 -4
- package/templates/racing/src/render/quality.ts +27 -115
- package/templates/racing/src/render/sky.ts +72 -1
- package/templates/racing/src/scenes/Race.ts +9 -7
- package/templates/racing/src/track/TrackSector.ts +5 -2
- package/templates/racing/src/ui/Hud.tsx +12 -7
- package/templates/rain/.codex/config.toml +6 -2
- package/templates/rain/.cursor/mcp.json +8 -2
- package/templates/rain/.gemini/settings.json +8 -2
- package/templates/rain/.mcp.json +8 -2
- package/templates/rain/.vscode/mcp.json +9 -2
- package/templates/rain/.zed/settings.json +9 -2
- package/templates/rain/AGENTS.md +12 -12
- package/templates/rain/CLAUDE.md +12 -12
- package/templates/rain/opencode.json +10 -2
- package/templates/rain/package.json +14 -9
- package/templates/rain/playtests/performance.playtest.json +1 -1
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/src/render/bloom-shader.ts +1 -1
- package/templates/rain/src/render/clouds-shader.ts +2 -2
- package/templates/rain/src/render/clouds.ts +2 -1
- package/templates/rain/src/render/exposure.ts +11 -109
- package/templates/rain/src/render/post-shader.ts +7 -11
- package/templates/rain/src/render/postprocessing.ts +8 -24
- package/templates/rain/src/render/quality.ts +44 -98
- package/templates/rain/src/render/world-shader.ts +281 -97
- package/templates/rain/src/render/world.ts +82 -2
- package/templates/rain/src/style.css +1 -1
- package/templates/rain/src/ui/GameUi.tsx +6 -2
- package/templates/rain/src/ui/Hud.tsx +1 -1
- package/templates/rain/tools/generate-shaders.mjs +2 -2
- package/templates/rain/tools/tempest-post.frag +4 -6
- package/templates/rain/tools/tempest-world.frag +80 -12
- package/templates/rts/.codex/config.toml +6 -2
- package/templates/rts/.cursor/mcp.json +8 -2
- package/templates/rts/.gemini/settings.json +8 -2
- package/templates/rts/.mcp.json +8 -2
- package/templates/rts/.vscode/mcp.json +9 -2
- package/templates/rts/.zed/settings.json +9 -2
- package/templates/rts/AGENTS.md +15 -16
- package/templates/rts/CLAUDE.md +15 -16
- package/templates/rts/opencode.json +10 -2
- package/templates/rts/package.json +14 -9
- package/templates/rts/playtests/performance.playtest.json +1 -1
- package/templates/rts/playtests/rts-attack.playtest.json +5 -0
- package/templates/rts/playtests/rts-build.playtest.json +20 -1
- package/templates/rts/playtests/rts-orders.playtest.json +1 -1
- package/templates/rts/playtests/rts-pause.playtest.json +112 -0
- package/templates/rts/playtests/rts-train.playtest.json +1 -1
- package/templates/rts/playtests/rts-zoom.playtest.json +81 -0
- package/templates/rts/src/game.ts +29 -7
- package/templates/rts/src/render/army.ts +181 -49
- package/templates/rts/src/render/backlightMaterial.ts +49 -18
- package/templates/rts/src/render/environment.ts +276 -0
- package/templates/rts/src/render/exposure.ts +3 -65
- package/templates/rts/src/render/ground.ts +478 -0
- package/templates/rts/src/render/lighting.ts +62 -11
- package/templates/rts/src/render/materialLighting.ts +2 -11
- package/templates/rts/src/render/materials.ts +47 -118
- package/templates/rts/src/render/palette.ts +30 -13
- package/templates/rts/src/render/picking.ts +18 -0
- package/templates/rts/src/render/postprocessing.ts +4 -4
- package/templates/rts/src/render/quality.ts +64 -85
- package/templates/rts/src/render/resources.ts +21 -22
- package/templates/rts/src/render/sky.ts +9 -12
- package/templates/rts/src/render/terrain.ts +36 -11
- package/templates/rts/src/scenes/Play.ts +373 -38
- package/templates/rts/src/sim/ai.ts +0 -11
- package/templates/rts/src/state.ts +46 -0
- package/templates/rts/src/style.css +1543 -0
- package/templates/rts/src/ui/Commands.tsx +204 -107
- package/templates/rts/src/ui/GameUi.tsx +12 -5
- package/templates/rts/src/ui/Hud.tsx +611 -116
- package/templates/rts/src/ui/Minimap.tsx +103 -37
- package/templates/rts/src/ui/icons.tsx +116 -0
- package/templates/rts/src/ui/labels.ts +73 -0
- package/templates/rts/src/ui/minimapPoint.ts +30 -0
- package/templates/rts/threenative.config.ts +1 -1
- package/templates/runner/.codex/config.toml +6 -2
- package/templates/runner/.cursor/mcp.json +8 -2
- package/templates/runner/.gemini/settings.json +8 -2
- package/templates/runner/.mcp.json +8 -2
- package/templates/runner/.vscode/mcp.json +9 -2
- package/templates/runner/.zed/settings.json +9 -2
- package/templates/runner/AGENTS.md +12 -12
- package/templates/runner/CLAUDE.md +12 -12
- package/templates/runner/opencode.json +10 -2
- package/templates/runner/package.json +15 -10
- package/templates/runner/playtests/near-miss.playtest.json +48 -0
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/playtests/stride.playtest.json +27 -0
- package/templates/runner/playtests/survives.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +3 -1
- package/templates/runner/src/entities/Runner.ts +11 -5
- package/templates/runner/src/render/atmosphere.ts +444 -0
- package/templates/runner/src/render/backlightMaterial.ts +49 -18
- package/templates/runner/src/render/clouds.ts +605 -0
- package/templates/runner/src/render/exposure.ts +6 -111
- package/templates/runner/src/render/gpuSky.ts +752 -0
- package/templates/runner/src/render/kitExposure.ts +20 -0
- package/templates/runner/src/render/lighting.ts +26 -4
- package/templates/runner/src/render/materialLighting.ts +2 -11
- package/templates/runner/src/render/postprocessing.ts +4 -4
- package/templates/runner/src/render/quality.ts +26 -114
- package/templates/runner/src/render/sky.ts +73 -1
- package/templates/runner/src/scenes/Run.ts +19 -15
- package/templates/runner/src/track.ts +12 -3
- package/templates/sailing/.codex/config.toml +6 -2
- package/templates/sailing/.cursor/mcp.json +8 -2
- package/templates/sailing/.gemini/settings.json +8 -2
- package/templates/sailing/.mcp.json +8 -2
- package/templates/sailing/.vscode/mcp.json +9 -2
- package/templates/sailing/.zed/settings.json +9 -2
- package/templates/sailing/AGENTS.md +10 -11
- package/templates/sailing/CLAUDE.md +10 -11
- package/templates/sailing/opencode.json +10 -2
- package/templates/sailing/package.json +15 -10
- package/templates/sailing/playtests/fail.playtest.json +46 -5
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +7 -0
- package/templates/sailing/playtests/performance.playtest.json +1 -1
- package/templates/sailing/src/game.ts +1 -0
- package/templates/sailing/src/render/backlightMaterial.ts +49 -18
- package/templates/sailing/src/render/exposure.ts +6 -111
- package/templates/sailing/src/render/kitExposure.ts +20 -0
- package/templates/sailing/src/render/materialLighting.ts +2 -11
- package/templates/sailing/src/render/ocean.ts +0 -1
- package/templates/sailing/src/render/postprocessing.ts +4 -4
- package/templates/sailing/src/render/quality.ts +31 -138
- package/templates/sailing/src/scenes/Sailing.ts +12 -4
- package/templates/sailing/src/ui/Hud.tsx +6 -2
- package/templates/sailing/src/ui/Menu.tsx +1 -1
- package/templates/shooter/.codex/config.toml +6 -2
- package/templates/shooter/.cursor/mcp.json +8 -2
- package/templates/shooter/.gemini/settings.json +8 -2
- package/templates/shooter/.mcp.json +8 -2
- package/templates/shooter/.vscode/mcp.json +9 -2
- package/templates/shooter/.zed/settings.json +9 -2
- package/templates/shooter/AGENTS.md +13 -12
- package/templates/shooter/CLAUDE.md +13 -12
- package/templates/shooter/index.html +1 -1
- package/templates/shooter/main.html +13 -0
- package/templates/shooter/opencode.json +10 -2
- package/templates/shooter/package.json +15 -10
- package/templates/shooter/playtests/breakable-shatters.playtest.json +6 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +6 -0
- package/templates/shooter/playtests/hands-authored-rate.playtest.json +54 -0
- package/templates/shooter/playtests/movement-eases.playtest.json +53 -0
- package/templates/shooter/playtests/performance.playtest.json +3 -3
- package/templates/shooter/playtests/stairs-smooth-the-eye.playtest.json +56 -0
- package/templates/shooter/playtests/weapon-sharp-while-turning.playtest.json +206 -0
- package/templates/shooter/src/entities/Breakables.ts +34 -10
- package/templates/shooter/src/entities/Enemy.ts +176 -54
- package/templates/shooter/src/entities/FpsPlayer.ts +55 -16
- package/templates/shooter/src/entities/Rifle.ts +83 -9
- package/templates/shooter/src/entities/movement.ts +96 -0
- package/templates/shooter/src/render/atmosphere.ts +444 -0
- package/templates/shooter/src/render/backlightMaterial.ts +49 -18
- package/templates/shooter/src/render/camera.ts +3 -1
- package/templates/shooter/src/render/clouds.ts +605 -0
- package/templates/shooter/src/render/exposure.ts +10 -109
- package/templates/shooter/src/render/facade.ts +26 -68
- package/templates/shooter/src/render/gpuSky.ts +752 -0
- package/templates/shooter/src/render/lighting.ts +27 -4
- package/templates/shooter/src/render/materialAssignments.ts +9 -1
- package/templates/shooter/src/render/materialLighting.ts +2 -11
- package/templates/shooter/src/render/occlusion.ts +13 -4
- package/templates/shooter/src/render/palette.ts +1 -0
- package/templates/shooter/src/render/postprocessing.ts +4 -4
- package/templates/shooter/src/render/quality.ts +50 -108
- package/templates/shooter/src/render/scale.ts +0 -11
- package/templates/shooter/src/render/sky.ts +103 -2
- package/templates/shooter/src/render/surface.ts +140 -0
- package/templates/shooter/src/render/town.ts +3 -6
- package/templates/shooter/src/render/townMaterials.ts +95 -42
- package/templates/shooter/src/render/vehicles.ts +2 -0
- package/templates/shooter/src/scenes/Play.ts +83 -23
- package/templates/shooter/src/ui/Hud.tsx +268 -193
- package/templates/shooter/src/worker-page.ts +29 -0
- package/templates/shooter/src/worker.ts +5 -0
- package/templates/shooter/threenative.config.ts +3 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/.codex/config.toml +6 -2
- package/templates/snow/.cursor/mcp.json +8 -2
- package/templates/snow/.gemini/settings.json +8 -2
- package/templates/snow/.mcp.json +8 -2
- package/templates/snow/.vscode/mcp.json +9 -2
- package/templates/snow/.zed/settings.json +9 -2
- package/templates/snow/AGENTS.md +12 -10
- package/templates/snow/CLAUDE.md +12 -10
- package/templates/snow/opencode.json +10 -2
- package/templates/snow/package.json +15 -10
- package/templates/snow/playtests/performance.playtest.json +1 -1
- package/templates/snow/src/render/backlightMaterial.ts +49 -18
- package/templates/snow/src/render/exposure.ts +17 -106
- package/templates/snow/src/render/materialLighting.ts +2 -11
- package/templates/snow/src/render/postprocessing.ts +11 -5
- package/templates/snow/src/render/quality.ts +46 -126
- package/templates/snow/src/render/snowSurface.ts +32 -15
- package/templates/snow/src/scenes/Snow.ts +2 -1
- package/templates/starter/.codex/config.toml +6 -2
- package/templates/starter/.cursor/mcp.json +8 -2
- package/templates/starter/.gemini/settings.json +8 -2
- package/templates/starter/.mcp.json +8 -2
- package/templates/starter/.vscode/mcp.json +9 -2
- package/templates/starter/.zed/settings.json +9 -2
- package/templates/starter/AGENTS.md +18 -14
- package/templates/starter/CLAUDE.md +18 -14
- package/templates/starter/index.html +1 -1
- package/templates/starter/main.html +12 -0
- package/templates/starter/native-playtests/react-hud.playtest.json +1 -0
- package/templates/starter/native-playtests/render-chain.playtest.json +34 -21
- package/templates/starter/opencode.json +10 -2
- package/templates/starter/package.json +15 -10
- package/templates/starter/playtests/play.playtest.json +22 -2
- package/templates/starter/playtests/production-readiness.playtest.json +14 -0
- package/templates/starter/src/entities/Crate.ts +19 -1
- package/templates/starter/src/render/arena.ts +2 -2
- package/templates/starter/src/render/atmosphere.ts +444 -0
- package/templates/starter/src/render/backlightMaterial.ts +49 -18
- package/templates/starter/src/render/camera.ts +28 -0
- package/templates/starter/src/render/clouds.ts +605 -0
- package/templates/starter/src/render/contactShadow.ts +50 -0
- package/templates/starter/src/render/exposure.ts +9 -111
- package/templates/starter/src/render/gpuSky.ts +752 -0
- package/templates/starter/src/render/grade.ts +1 -1
- package/templates/starter/src/render/lighting.ts +34 -6
- package/templates/starter/src/render/materialLighting.ts +2 -11
- package/templates/starter/src/render/postprocessing.ts +27 -14
- package/templates/starter/src/render/quality.ts +18 -147
- package/templates/starter/src/render/sky.ts +90 -40
- package/templates/starter/src/render/temporalAA.ts +1 -1
- package/templates/starter/src/render/temporalAAStage.ts +1 -1
- package/templates/starter/src/render/temporalCurrentFootprint.ts +0 -1
- package/templates/starter/src/render/temporalDetailStage.ts +106 -0
- package/templates/starter/src/render/temporalRejectionCounter.ts +2 -2
- package/templates/starter/src/render/volumetricFogCamera.ts +32 -0
- package/templates/starter/src/render/volumetricFogOptions.ts +7 -0
- package/templates/starter/src/render/volumetricFogTransport.ts +27 -19
- package/templates/starter/src/render/volumetricFogVolume.ts +31 -7
- package/templates/starter/src/scenes/Play.ts +11 -8
- package/templates/starter/src/ui/Hud.tsx +1 -1
- package/templates/starter/src/worker-page.ts +29 -0
- package/templates/starter/src/worker.ts +5 -0
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/.codex/config.toml +6 -2
- package/templates/tower-defense/.cursor/mcp.json +8 -2
- package/templates/tower-defense/.gemini/settings.json +8 -2
- package/templates/tower-defense/.mcp.json +8 -2
- package/templates/tower-defense/.vscode/mcp.json +9 -2
- package/templates/tower-defense/.zed/settings.json +9 -2
- package/templates/tower-defense/AGENTS.md +10 -12
- package/templates/tower-defense/CLAUDE.md +10 -12
- package/templates/tower-defense/opencode.json +10 -2
- package/templates/tower-defense/package.json +15 -10
- package/templates/tower-defense/playtests/chill-tint.playtest.json +387 -0
- package/templates/tower-defense/playtests/performance.playtest.json +1 -1
- package/templates/tower-defense/src/enemies/Enemy.ts +9 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +49 -18
- package/templates/tower-defense/src/render/exposure.ts +11 -109
- package/templates/tower-defense/src/render/lighting.ts +4 -2
- package/templates/tower-defense/src/render/materialLighting.ts +2 -11
- package/templates/tower-defense/src/render/postprocessing.ts +4 -4
- package/templates/tower-defense/src/render/quality.ts +10 -116
- package/templates/tower-defense/src/render/sky.ts +2 -2
- package/templates/tower-defense/src/scenes/Battle.ts +4 -0
- package/template-assets/autoExposure.ts +0 -225
- package/template-assets/exposureGraph.ts +0 -178
- package/template-assets/exposureReadback.ts +0 -79
- package/template-assets/worldEnvironment.ts +0 -1212
- package/templates/action-rpg/src/render/autoExposure.ts +0 -225
- package/templates/action-rpg/src/render/exposureGraph.ts +0 -178
- package/templates/action-rpg/src/render/exposureReadback.ts +0 -79
- package/templates/action-rpg/src/render/worldEnvironment.ts +0 -1212
- package/templates/minimal/src/render/autoExposure.ts +0 -225
- package/templates/minimal/src/render/exposureGraph.ts +0 -178
- package/templates/minimal/src/render/exposureReadback.ts +0 -79
- package/templates/minimal/src/render/worldEnvironment.ts +0 -1212
- package/templates/platformer/src/render/autoExposure.ts +0 -225
- package/templates/platformer/src/render/exposureGraph.ts +0 -178
- package/templates/platformer/src/render/exposureReadback.ts +0 -79
- package/templates/platformer/src/render/worldEnvironment.ts +0 -1212
- package/templates/puzzle/src/render/autoExposure.ts +0 -225
- package/templates/puzzle/src/render/exposureGraph.ts +0 -178
- package/templates/puzzle/src/render/exposureReadback.ts +0 -79
- package/templates/puzzle/src/render/worldEnvironment.ts +0 -1212
- package/templates/racing/src/render/autoExposure.ts +0 -225
- package/templates/racing/src/render/exposureGraph.ts +0 -178
- package/templates/racing/src/render/exposureReadback.ts +0 -79
- package/templates/racing/src/render/worldEnvironment.ts +0 -1212
- package/templates/rain/src/render/autoExposure.ts +0 -225
- package/templates/rain/src/render/exposureGraph.ts +0 -178
- package/templates/rain/src/render/exposureReadback.ts +0 -79
- package/templates/rain/src/render/worldEnvironment.ts +0 -1212
- package/templates/rts/src/render/autoExposure.ts +0 -225
- package/templates/rts/src/render/exposureGraph.ts +0 -178
- package/templates/rts/src/render/exposureReadback.ts +0 -79
- package/templates/rts/src/render/worldEnvironment.ts +0 -1212
- package/templates/runner/src/render/autoExposure.ts +0 -225
- package/templates/runner/src/render/exposureGraph.ts +0 -178
- package/templates/runner/src/render/exposureReadback.ts +0 -79
- package/templates/runner/src/render/worldEnvironment.ts +0 -1212
- package/templates/sailing/src/render/autoExposure.ts +0 -225
- package/templates/sailing/src/render/exposureGraph.ts +0 -178
- package/templates/sailing/src/render/exposureReadback.ts +0 -79
- package/templates/sailing/src/render/worldEnvironment.ts +0 -1212
- package/templates/shooter/src/render/autoExposure.ts +0 -225
- package/templates/shooter/src/render/exposureGraph.ts +0 -178
- package/templates/shooter/src/render/exposureReadback.ts +0 -79
- package/templates/shooter/src/render/worldEnvironment.ts +0 -1212
- package/templates/snow/src/render/autoExposure.ts +0 -225
- package/templates/snow/src/render/exposureGraph.ts +0 -178
- package/templates/snow/src/render/exposureReadback.ts +0 -79
- package/templates/snow/src/render/worldEnvironment.ts +0 -1212
- package/templates/starter/src/render/autoExposure.ts +0 -225
- package/templates/starter/src/render/exposureGraph.ts +0 -178
- package/templates/starter/src/render/exposureReadback.ts +0 -79
- package/templates/starter/src/render/worldEnvironment.ts +0 -1212
- package/templates/tower-defense/src/render/autoExposure.ts +0 -225
- package/templates/tower-defense/src/render/exposureGraph.ts +0 -178
- package/templates/tower-defense/src/render/exposureReadback.ts +0 -79
- package/templates/tower-defense/src/render/worldEnvironment.ts +0 -1212
|
@@ -0,0 +1,1072 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js — edit or delete it freely.
|
|
2
|
+
//
|
|
3
|
+
// The vale's planting and its floor, an old misty forest built in code. Giant gnarled trees (a
|
|
4
|
+
// twisted trunk with ridged bark, thick roots and limbs, moss on every upward face) under broad
|
|
5
|
+
// crowns of leaf clumps that sway; far trees in a lighter cut; big lobed broadleaf plants, ferns,
|
|
6
|
+
// purple and pink flowers and grass tufts; mossy boulders; an irregular flagstone path; a stream;
|
|
7
|
+
// mushrooms and logs; ivy and vines on the cliff. Every kind is one `InstancedMesh`, so a forest
|
|
8
|
+
// costs a few dozen draws and no light of its own. Nothing here is solid: `level/Vale.ts` decides
|
|
9
|
+
// what blocks, and its height function is the floor everything here stands on.
|
|
10
|
+
//
|
|
11
|
+
// The floor is two vertex-coloured grids over that height function: a fine one where Wren walks
|
|
12
|
+
// (it is also her collider) and a coarse one for the hills. Soil, moss and leaf litter, rock where
|
|
13
|
+
// the slope passes the walk limit, dark soil under the path, a wet stream bed, contact shade.
|
|
14
|
+
import {
|
|
15
|
+
BufferAttribute,
|
|
16
|
+
BufferGeometry,
|
|
17
|
+
CatmullRomCurve3,
|
|
18
|
+
CircleGeometry,
|
|
19
|
+
Color,
|
|
20
|
+
ConeGeometry,
|
|
21
|
+
CylinderGeometry,
|
|
22
|
+
DoubleSide,
|
|
23
|
+
Group,
|
|
24
|
+
IcosahedronGeometry,
|
|
25
|
+
InstancedMesh,
|
|
26
|
+
type Material,
|
|
27
|
+
Mesh,
|
|
28
|
+
Object3D,
|
|
29
|
+
OctahedronGeometry,
|
|
30
|
+
SphereGeometry,
|
|
31
|
+
TubeGeometry,
|
|
32
|
+
Vector3,
|
|
33
|
+
} from "three";
|
|
34
|
+
import {
|
|
35
|
+
cameraPosition,
|
|
36
|
+
cos,
|
|
37
|
+
hash,
|
|
38
|
+
instanceIndex,
|
|
39
|
+
positionLocal,
|
|
40
|
+
positionWorld,
|
|
41
|
+
sin,
|
|
42
|
+
step,
|
|
43
|
+
time,
|
|
44
|
+
vec3,
|
|
45
|
+
} from "three/tsl";
|
|
46
|
+
import { MeshStandardNodeMaterial } from "three/webgpu";
|
|
47
|
+
import { lit } from "./materials.js";
|
|
48
|
+
import { C, palette } from "./palette.js";
|
|
49
|
+
import { SUN_DIRECTION, sunShafts } from "./sky.js";
|
|
50
|
+
import { groundSurface, surfaced } from "./surface.js";
|
|
51
|
+
|
|
52
|
+
/** Where the sun shafts meet the floor, x, z and radius: down the path ahead and between giants. */
|
|
53
|
+
const SHAFTS = [
|
|
54
|
+
[-2.5, -1, 0.7],
|
|
55
|
+
[2.8, -6, 0.9],
|
|
56
|
+
[-5.5, -8.5, 0.6],
|
|
57
|
+
[1.2, -11.5, 0.8],
|
|
58
|
+
[7.5, -1.5, 0.7],
|
|
59
|
+
[-8.5, 0.5, 0.9],
|
|
60
|
+
[9, -9, 0.6],
|
|
61
|
+
[-2.8, 3.5, 0.5],
|
|
62
|
+
[-10, -11, 0.8],
|
|
63
|
+
] as const;
|
|
64
|
+
|
|
65
|
+
/** x, y, z, scale x, y, z, rotation x, y, z. */
|
|
66
|
+
type Placement = readonly [number, number, number, number, number, number, number, number, number];
|
|
67
|
+
|
|
68
|
+
/** Where the vale may be planted, and what already stands in it. */
|
|
69
|
+
export interface IValeSite {
|
|
70
|
+
readonly rng: () => number;
|
|
71
|
+
/** The clearing's walkable box, x from -half to half, z from north to south. */
|
|
72
|
+
readonly clearing: { readonly half: number; readonly north: number; readonly south: number };
|
|
73
|
+
/** The ground's height at (x, z): everything here stands on it. */
|
|
74
|
+
height(x: number, z: number): number;
|
|
75
|
+
/** The path's centre line: x at a given z. */
|
|
76
|
+
pathX(z: number): number;
|
|
77
|
+
/** Whether a plant this wide may stand at (x, z) inside the clearing: off the play spaces. */
|
|
78
|
+
clear(x: number, z: number, width: number): boolean;
|
|
79
|
+
/** The stream: its centre line, its water level and the distance to it. */
|
|
80
|
+
readonly stream: {
|
|
81
|
+
readonly points: readonly (readonly [number, number])[];
|
|
82
|
+
readonly water: number;
|
|
83
|
+
distance(x: number, z: number): number;
|
|
84
|
+
};
|
|
85
|
+
/** Trees: x, z, scale, kind. */
|
|
86
|
+
readonly trees: readonly (readonly [number, number, number, "giant" | "far"])[];
|
|
87
|
+
/** Ivy and vines: wall faces as x, y, z of the face's centre, its width, height and yaw. */
|
|
88
|
+
readonly walls: readonly (readonly [number, number, number, number, number, number])[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const dummy = new Object3D();
|
|
92
|
+
dummy.rotation.order = "YXZ";
|
|
93
|
+
|
|
94
|
+
export function instanced(
|
|
95
|
+
geometry: BufferGeometry,
|
|
96
|
+
material: Material,
|
|
97
|
+
placements: readonly Placement[],
|
|
98
|
+
castShadow: boolean,
|
|
99
|
+
): InstancedMesh {
|
|
100
|
+
const mesh = new InstancedMesh(geometry, material, Math.max(1, placements.length));
|
|
101
|
+
mesh.count = placements.length;
|
|
102
|
+
placements.forEach(([x, y, z, sx, sy, sz, rx, ry, rz], i) => {
|
|
103
|
+
dummy.position.set(x, y, z);
|
|
104
|
+
dummy.scale.set(sx, sy, sz);
|
|
105
|
+
dummy.rotation.set(rx, ry, rz);
|
|
106
|
+
dummy.updateMatrix();
|
|
107
|
+
mesh.setMatrixAt(i, dummy.matrix);
|
|
108
|
+
});
|
|
109
|
+
mesh.castShadow = castShadow;
|
|
110
|
+
mesh.receiveShadow = true;
|
|
111
|
+
return mesh;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Gives a geometry one flat vertex colour. */
|
|
115
|
+
function paint(geometry: BufferGeometry, color: number): BufferGeometry {
|
|
116
|
+
const g = geometry.index === null ? geometry : geometry.toNonIndexed();
|
|
117
|
+
const n = g.attributes.position?.count ?? 0;
|
|
118
|
+
const tint = new Color(color);
|
|
119
|
+
const colour = new Float32Array(n * 3);
|
|
120
|
+
for (let i = 0; i < n; i += 1) colour.set([tint.r, tint.g, tint.b], i * 3);
|
|
121
|
+
g.setAttribute("color", new BufferAttribute(colour, 3));
|
|
122
|
+
return g;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** One geometry from coloured parts (each with a `color` attribute): a plant is one draw. */
|
|
126
|
+
function mergeAll(parts: readonly BufferGeometry[]): BufferGeometry {
|
|
127
|
+
const flat = parts.map((g) => (g.index === null ? g : g.toNonIndexed()));
|
|
128
|
+
const count = flat.reduce((sum, g) => sum + (g.attributes.position?.count ?? 0), 0);
|
|
129
|
+
const withUv = flat.every((g) => g.attributes.uv !== undefined);
|
|
130
|
+
const position = new Float32Array(count * 3);
|
|
131
|
+
const normal = new Float32Array(count * 3);
|
|
132
|
+
const colour = new Float32Array(count * 3);
|
|
133
|
+
const uv = new Float32Array(count * 2);
|
|
134
|
+
let at = 0;
|
|
135
|
+
for (const g of flat) {
|
|
136
|
+
if (g.attributes.normal === undefined) g.computeVertexNormals();
|
|
137
|
+
position.set(g.attributes.position?.array ?? [], at * 3);
|
|
138
|
+
normal.set(g.attributes.normal?.array ?? [], at * 3);
|
|
139
|
+
colour.set(g.attributes.color?.array ?? [], at * 3);
|
|
140
|
+
if (withUv) uv.set(g.attributes.uv?.array ?? [], at * 2);
|
|
141
|
+
at += g.attributes.position?.count ?? 0;
|
|
142
|
+
}
|
|
143
|
+
const merged = new BufferGeometry();
|
|
144
|
+
merged.setAttribute("position", new BufferAttribute(position, 3));
|
|
145
|
+
merged.setAttribute("normal", new BufferAttribute(normal, 3));
|
|
146
|
+
merged.setAttribute("color", new BufferAttribute(colour, 3));
|
|
147
|
+
if (withUv) merged.setAttribute("uv", new BufferAttribute(uv, 2));
|
|
148
|
+
return merged;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Parts with one flat colour each, merged. */
|
|
152
|
+
function merge(parts: readonly (readonly [BufferGeometry, number])[]): BufferGeometry {
|
|
153
|
+
return mergeAll(parts.map(([g, color]) => paint(g, color)));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A lit plant material whose vertices above y = 0 sway with the wind, each instance on its own phase.
|
|
158
|
+
* `time` is seconds: the sway takes about 7 s one way and 10 s the other, a breeze, not a gale.
|
|
159
|
+
*/
|
|
160
|
+
function swaying(amount: number, vertexColors = true, color = 0xffffff): MeshStandardNodeMaterial {
|
|
161
|
+
const material = new MeshStandardNodeMaterial({
|
|
162
|
+
color,
|
|
163
|
+
roughness: 0.8,
|
|
164
|
+
side: DoubleSide,
|
|
165
|
+
vertexColors,
|
|
166
|
+
});
|
|
167
|
+
const phase = hash(instanceIndex).mul(6.28);
|
|
168
|
+
const height = positionLocal.y.max(0);
|
|
169
|
+
const bend = height.mul(height).mul(amount * 0.4);
|
|
170
|
+
material.positionNode = positionLocal.add(
|
|
171
|
+
vec3(
|
|
172
|
+
sin(time.mul(0.9).add(phase)).mul(bend),
|
|
173
|
+
0,
|
|
174
|
+
sin(time.mul(0.63).add(phase.mul(1.7)))
|
|
175
|
+
.mul(bend)
|
|
176
|
+
.mul(0.6),
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
// A plant the camera has pushed into is cut away within a metre and a half of the lens, so a
|
|
180
|
+
// leaf never fills the frame; its shadow stays.
|
|
181
|
+
material.alphaTest = 0.5;
|
|
182
|
+
material.opacityNode = step(1.5, positionWorld.distance(cameraPosition));
|
|
183
|
+
return material;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** A crown's leaf clumps: the whole clump rocks over 10 to 20 s in the wind, the far side of it more. */
|
|
187
|
+
function canopyMaterial(): MeshStandardNodeMaterial {
|
|
188
|
+
const material = new MeshStandardNodeMaterial({
|
|
189
|
+
roughness: 0.75,
|
|
190
|
+
side: DoubleSide,
|
|
191
|
+
vertexColors: true,
|
|
192
|
+
});
|
|
193
|
+
const phase = hash(instanceIndex).mul(6.28);
|
|
194
|
+
const reach = positionLocal.length().mul(0.006);
|
|
195
|
+
material.positionNode = positionLocal.add(
|
|
196
|
+
vec3(
|
|
197
|
+
sin(time.mul(0.45).add(phase)),
|
|
198
|
+
sin(time.mul(0.6).add(phase.mul(2))).mul(0.4),
|
|
199
|
+
cos(time.mul(0.32).add(phase)),
|
|
200
|
+
).mul(reach),
|
|
201
|
+
);
|
|
202
|
+
return material;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** A fan of thin cones leaning out from the root: grass blades or fern fronds. */
|
|
206
|
+
function fan(
|
|
207
|
+
blades: number,
|
|
208
|
+
radius: number,
|
|
209
|
+
length: number,
|
|
210
|
+
lean: number,
|
|
211
|
+
color: number,
|
|
212
|
+
flatten = 1,
|
|
213
|
+
): BufferGeometry {
|
|
214
|
+
return merge(
|
|
215
|
+
Array.from({ length: blades }, (_, i) => {
|
|
216
|
+
const yaw = (i / blades) * Math.PI * 2 + i * 0.7;
|
|
217
|
+
const blade = new ConeGeometry(radius, length * (0.75 + ((i * 37) % 10) / 40), 3)
|
|
218
|
+
.translate(0, length / 2, 0)
|
|
219
|
+
.scale(1, 1, flatten)
|
|
220
|
+
.rotateX(lean * (0.7 + ((i * 13) % 5) / 10))
|
|
221
|
+
.rotateY(yaw);
|
|
222
|
+
return [blade, color] as const;
|
|
223
|
+
}),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** The outline of a broad leaf, across (x) and along (y), base at the origin, tip at y = 1. */
|
|
228
|
+
const LEAF_OUTLINE: readonly (readonly [number, number])[] = [
|
|
229
|
+
[0, 0],
|
|
230
|
+
[-0.3, 0.14],
|
|
231
|
+
[-0.46, 0.36],
|
|
232
|
+
[-0.4, 0.6],
|
|
233
|
+
[-0.2, 0.84],
|
|
234
|
+
[0, 1],
|
|
235
|
+
[0.2, 0.84],
|
|
236
|
+
[0.4, 0.6],
|
|
237
|
+
[0.46, 0.36],
|
|
238
|
+
[0.3, 0.14],
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
/** One broad leaf, `length` long, cupped along its midrib, base colour fading to `tip`. */
|
|
242
|
+
function leaf(length: number, width: number, base: Color, tip: Color, cup = 0.12): BufferGeometry {
|
|
243
|
+
const centre: readonly [number, number] = [0, 0.45];
|
|
244
|
+
const position: number[] = [];
|
|
245
|
+
const colour: number[] = [];
|
|
246
|
+
const vertex = (x: number, y: number): void => {
|
|
247
|
+
position.push(x * width, y * length, -cup * length * (x * 2) ** 2);
|
|
248
|
+
const c = base.clone().lerp(tip, y);
|
|
249
|
+
colour.push(c.r, c.g, c.b);
|
|
250
|
+
};
|
|
251
|
+
for (let i = 0; i < LEAF_OUTLINE.length; i += 1) {
|
|
252
|
+
const a = LEAF_OUTLINE[i] ?? [0, 0];
|
|
253
|
+
const b = LEAF_OUTLINE[(i + 1) % LEAF_OUTLINE.length] ?? [0, 0];
|
|
254
|
+
vertex(centre[0], centre[1]);
|
|
255
|
+
vertex(a[0], a[1]);
|
|
256
|
+
vertex(b[0], b[1]);
|
|
257
|
+
}
|
|
258
|
+
const g = new BufferGeometry();
|
|
259
|
+
g.setAttribute("position", new BufferAttribute(new Float32Array(position), 3));
|
|
260
|
+
g.setAttribute("color", new BufferAttribute(new Float32Array(colour), 3));
|
|
261
|
+
g.computeVertexNormals();
|
|
262
|
+
return g;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* A clump of broad leaves round its centre, facing out and up, in two greens: a piece of crown.
|
|
267
|
+
* `leaves` sets the cost: a near crown wants 14, a far one 6 bigger ones.
|
|
268
|
+
*/
|
|
269
|
+
function leafClump(leaves: number, leafLength: number, rng: () => number): BufferGeometry {
|
|
270
|
+
const deep = new Color(C.leafDeep);
|
|
271
|
+
const sun = new Color(C.leafSun);
|
|
272
|
+
const holder = new Object3D();
|
|
273
|
+
const parts: BufferGeometry[] = [];
|
|
274
|
+
for (let i = 0; i < leaves; i += 1) {
|
|
275
|
+
// Out from the centre, biased up: the crown's top catches the light.
|
|
276
|
+
const u = rng() * 2 - 1 + 0.35;
|
|
277
|
+
const a = rng() * Math.PI * 2;
|
|
278
|
+
const r = Math.sqrt(Math.max(0, 1 - Math.min(1, u) ** 2));
|
|
279
|
+
const out = new Vector3(Math.cos(a) * r, Math.min(1, u), Math.sin(a) * r).normalize();
|
|
280
|
+
holder.position.copy(out).multiplyScalar(0.35 + rng() * 0.7);
|
|
281
|
+
holder.lookAt(
|
|
282
|
+
holder.position
|
|
283
|
+
.clone()
|
|
284
|
+
.add(out)
|
|
285
|
+
.add(new Vector3(0, 0.6, 0)),
|
|
286
|
+
);
|
|
287
|
+
holder.rotateZ(rng() * Math.PI * 2);
|
|
288
|
+
holder.updateMatrix();
|
|
289
|
+
const light = 0.25 + 0.75 * (out.y * 0.5 + 0.5) * rng();
|
|
290
|
+
const tint = deep.clone().lerp(sun, light);
|
|
291
|
+
const g = leaf(
|
|
292
|
+
leafLength * (0.8 + rng() * 0.4),
|
|
293
|
+
leafLength * 0.75,
|
|
294
|
+
deep.clone().lerp(tint, 0.5),
|
|
295
|
+
tint,
|
|
296
|
+
);
|
|
297
|
+
g.translate(0, -leafLength * 0.4, 0);
|
|
298
|
+
parts.push(g.applyMatrix4(holder.matrix));
|
|
299
|
+
}
|
|
300
|
+
return mergeAll(parts);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** A tube along `points` whose radius follows `radius(t)`, with twisted ridges: bark, root or limb. */
|
|
304
|
+
function limb(
|
|
305
|
+
points: readonly Vector3[],
|
|
306
|
+
radius: (t: number) => number,
|
|
307
|
+
segments: number,
|
|
308
|
+
sides: number,
|
|
309
|
+
ridges: number,
|
|
310
|
+
): BufferGeometry {
|
|
311
|
+
const curve = new CatmullRomCurve3([...points]);
|
|
312
|
+
const tube = new TubeGeometry(curve, segments, 1, sides, false);
|
|
313
|
+
const position = tube.attributes.position;
|
|
314
|
+
if (position === undefined) throw new Error("limb: the tube has no positions.");
|
|
315
|
+
const centre = new Vector3();
|
|
316
|
+
const p = new Vector3();
|
|
317
|
+
for (let i = 0; i <= segments; i += 1) {
|
|
318
|
+
const t = i / segments;
|
|
319
|
+
curve.getPointAt(t, centre);
|
|
320
|
+
for (let j = 0; j <= sides; j += 1) {
|
|
321
|
+
const k = i * (sides + 1) + j;
|
|
322
|
+
const angle = (j / sides) * Math.PI * 2;
|
|
323
|
+
const ridge =
|
|
324
|
+
1 + ridges * (0.6 * Math.sin(angle * 3 + t * 9) + 0.4 * Math.sin(angle * 5 - t * 14));
|
|
325
|
+
p.fromBufferAttribute(position, k)
|
|
326
|
+
.sub(centre)
|
|
327
|
+
.multiplyScalar(radius(t) * ridge)
|
|
328
|
+
.add(centre);
|
|
329
|
+
position.setXYZ(k, p.x, p.y, p.z);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
tube.computeVertexNormals();
|
|
333
|
+
return tube;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Colours bark by its normal: moss on every face that looks up, bark below, darker at the foot. */
|
|
337
|
+
export function mossBark(geometry: BufferGeometry, moss: number): BufferGeometry {
|
|
338
|
+
const g = geometry.index === null ? geometry : geometry.toNonIndexed();
|
|
339
|
+
g.computeVertexNormals();
|
|
340
|
+
const normal = g.attributes.normal;
|
|
341
|
+
const position = g.attributes.position;
|
|
342
|
+
if (normal === undefined || position === undefined) return g;
|
|
343
|
+
const bark = new Color(C.bark);
|
|
344
|
+
const deep = new Color(C.barkDeep);
|
|
345
|
+
const green = new Color(C.forestMoss);
|
|
346
|
+
const bright = new Color(C.mossBright);
|
|
347
|
+
const colour = new Float32Array(position.count * 3);
|
|
348
|
+
const c = new Color();
|
|
349
|
+
for (let i = 0; i < position.count; i += 1) {
|
|
350
|
+
const ny = normal.getY(i);
|
|
351
|
+
const y = position.getY(i);
|
|
352
|
+
const grain = 0.5 + 0.5 * Math.sin(position.getX(i) * 7.1 + y * 3.3 + position.getZ(i) * 5.7);
|
|
353
|
+
c.copy(deep).lerp(bark, 0.4 + 0.6 * grain);
|
|
354
|
+
const onTop = Math.min(1, Math.max(0, (ny - 0.15) / 0.5));
|
|
355
|
+
const atFoot = Math.max(0, 1 - y / 2.2);
|
|
356
|
+
c.lerp(
|
|
357
|
+
green.clone().lerp(bright, grain * 0.6),
|
|
358
|
+
Math.min(1, onTop * moss + atFoot * 0.5 * moss),
|
|
359
|
+
);
|
|
360
|
+
colour.set([c.r, c.g, c.b], i * 3);
|
|
361
|
+
}
|
|
362
|
+
g.setAttribute("color", new BufferAttribute(colour, 3));
|
|
363
|
+
return g;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
interface ITreeModel {
|
|
367
|
+
readonly wood: BufferGeometry;
|
|
368
|
+
/** Crown clump centres, in the tree's own space, with a clump scale each. */
|
|
369
|
+
readonly crown: readonly (readonly [number, number, number, number])[];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* One gnarled tree, about 9 m tall at scale 1: a leaning, twisting trunk with flared ridged bark,
|
|
374
|
+
* `roots` thick roots that arc out and dive into the soil, and `limbs` limbs ending in crown
|
|
375
|
+
* clumps. `rich` adds rings and sides for a tree near the path.
|
|
376
|
+
*/
|
|
377
|
+
function gnarledTree(rng: () => number, roots: number, limbs: number, rich: boolean): ITreeModel {
|
|
378
|
+
const height = 5.6 + rng() * 1.4;
|
|
379
|
+
const lean = new Vector3(rng() - 0.5, 0, rng() - 0.5).multiplyScalar(1.6);
|
|
380
|
+
const spine: Vector3[] = [];
|
|
381
|
+
for (let i = 0; i <= 5; i += 1) {
|
|
382
|
+
const t = i / 5;
|
|
383
|
+
spine.push(
|
|
384
|
+
new Vector3(
|
|
385
|
+
lean.x * t * t + Math.sin(t * 4 + rng()) * 0.35,
|
|
386
|
+
-0.4 + t * height,
|
|
387
|
+
lean.z * t * t + Math.cos(t * 3.4 + rng()) * 0.35,
|
|
388
|
+
),
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
const trunkRadius = (t: number): number =>
|
|
392
|
+
0.42 + 0.5 * (1 - t) ** 3 + 0.55 * Math.max(0, 0.12 - t) * 8;
|
|
393
|
+
const parts = [limb(spine, trunkRadius, rich ? 14 : 8, rich ? 10 : 6, rich ? 0.16 : 0.1)];
|
|
394
|
+
const at = (t: number): Vector3 => new CatmullRomCurve3(spine).getPointAt(t);
|
|
395
|
+
for (let i = 0; i < roots; i += 1) {
|
|
396
|
+
const a = (i / roots) * Math.PI * 2 + rng() * 0.6;
|
|
397
|
+
const reach = 1.8 + rng() * 1.4;
|
|
398
|
+
const out = new Vector3(Math.cos(a), 0, Math.sin(a));
|
|
399
|
+
const root = [
|
|
400
|
+
new Vector3(0, 0.9 + rng() * 0.5, 0).addScaledVector(out, 0.2),
|
|
401
|
+
new Vector3(0, 0.5, 0).addScaledVector(out, reach * 0.35),
|
|
402
|
+
new Vector3(0, 0.2 + rng() * 0.15, 0).addScaledVector(out, reach * 0.7),
|
|
403
|
+
new Vector3(0, -0.35, 0).addScaledVector(out, reach),
|
|
404
|
+
];
|
|
405
|
+
parts.push(limb(root, (t) => 0.42 * (1 - t) ** 1.3 + 0.05, rich ? 7 : 4, rich ? 6 : 4, 0.08));
|
|
406
|
+
}
|
|
407
|
+
const crown: [number, number, number, number][] = [];
|
|
408
|
+
const top = at(1);
|
|
409
|
+
crown.push([top.x, top.y + 0.6, top.z, 1.9]);
|
|
410
|
+
for (let i = 0; i < limbs; i += 1) {
|
|
411
|
+
const t = 0.38 + (i / limbs) * 0.45;
|
|
412
|
+
const from = at(t);
|
|
413
|
+
const a = (i / limbs) * Math.PI * 2 + rng() * 0.8;
|
|
414
|
+
const reach = 2.4 + rng() * 2;
|
|
415
|
+
const out = new Vector3(Math.cos(a), 0, Math.sin(a));
|
|
416
|
+
const end = from
|
|
417
|
+
.clone()
|
|
418
|
+
.addScaledVector(out, reach)
|
|
419
|
+
.add(new Vector3(0, 1.2 + rng() * 1.6, 0));
|
|
420
|
+
const kink = from
|
|
421
|
+
.clone()
|
|
422
|
+
.addScaledVector(out, reach * 0.45)
|
|
423
|
+
.add(new Vector3(0, 0.2 + rng() * 0.6, 0));
|
|
424
|
+
parts.push(
|
|
425
|
+
limb([from, kink, end], (u) => 0.24 * (1 - u) + 0.06, rich ? 6 : 4, rich ? 5 : 4, 0.06),
|
|
426
|
+
);
|
|
427
|
+
crown.push([end.x, end.y + 0.3, end.z, 1.4 + rng() * 0.6]);
|
|
428
|
+
crown.push([kink.x + out.x * 0.4, kink.y + 0.9, kink.z + out.z * 0.4, 1 + rng() * 0.4]);
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
crown,
|
|
432
|
+
wood: mossBark(mergeAll(parts.map((g) => paint(g, 0xffffff))), rich ? 0.9 : 0.6),
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Rotation x and z (in a YXZ euler with yaw `yaw`) that stand an object on a slope of normal `n`. */
|
|
437
|
+
function tiltTo(n: Vector3, yaw: number): [number, number] {
|
|
438
|
+
const c = Math.cos(yaw);
|
|
439
|
+
const s = Math.sin(yaw);
|
|
440
|
+
const lx = n.x * c - n.z * s;
|
|
441
|
+
const lz = n.x * s + n.z * c;
|
|
442
|
+
return [Math.atan2(lz, n.y), Math.asin(Math.max(-1, Math.min(1, -lx)))];
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Plants the clearing and the hills round it. Returns the group, the contact-shade spots and the path. */
|
|
446
|
+
export function plantVale(site: IValeSite): {
|
|
447
|
+
readonly group: Group;
|
|
448
|
+
readonly shade: readonly (readonly [number, number, number])[];
|
|
449
|
+
readonly path: { readonly stones: number; readonly cover: number };
|
|
450
|
+
} {
|
|
451
|
+
const { rng, clearing, clear, height } = site;
|
|
452
|
+
const group = new Group();
|
|
453
|
+
group.name = "planting";
|
|
454
|
+
const spin = (): number => rng() * Math.PI * 2;
|
|
455
|
+
const shade: [number, number, number][] = [];
|
|
456
|
+
const P = (x: number, y: number, z: number, s: number, sy = s, yaw = spin()): Placement => [
|
|
457
|
+
x,
|
|
458
|
+
height(x, z) + y,
|
|
459
|
+
z,
|
|
460
|
+
s,
|
|
461
|
+
sy,
|
|
462
|
+
s,
|
|
463
|
+
0,
|
|
464
|
+
yaw,
|
|
465
|
+
0,
|
|
466
|
+
];
|
|
467
|
+
const normalAt = (x: number, z: number): Vector3 =>
|
|
468
|
+
new Vector3(
|
|
469
|
+
height(x - 0.3, z) - height(x + 0.3, z),
|
|
470
|
+
0.6,
|
|
471
|
+
height(x, z - 0.3) - height(x, z + 0.3),
|
|
472
|
+
).normalize();
|
|
473
|
+
|
|
474
|
+
// ------------------------------------------------------------------------------ old trees
|
|
475
|
+
// Three giant cuts and two far cuts; every tree is one of them, scaled and turned.
|
|
476
|
+
const giants = [0, 1, 2].map(() => gnarledTree(rng, 6, 5, true));
|
|
477
|
+
const fars = [0, 1].map(() => gnarledTree(rng, 3, 2, false));
|
|
478
|
+
const wood = { far: fars.map((): Placement[] => []), giant: giants.map((): Placement[] => []) };
|
|
479
|
+
const nearClumps: Placement[] = [];
|
|
480
|
+
const farClumps: Placement[] = [];
|
|
481
|
+
site.trees.forEach(([x, z, s, kind], i) => {
|
|
482
|
+
const models = kind === "giant" ? giants : fars;
|
|
483
|
+
const which = i % models.length;
|
|
484
|
+
const model = models[which];
|
|
485
|
+
if (model === undefined) return;
|
|
486
|
+
const yaw = spin();
|
|
487
|
+
const y = height(x, z);
|
|
488
|
+
(kind === "giant" ? wood.giant : wood.far)[which]?.push([x, y, z, s, s, s, 0, yaw, 0]);
|
|
489
|
+
shade.push([x, z, 1.8 * s]);
|
|
490
|
+
const c = Math.cos(yaw);
|
|
491
|
+
const sn = Math.sin(yaw);
|
|
492
|
+
for (const [cx, cy, cz, cs] of model.crown) {
|
|
493
|
+
// The clump centre turned with the tree: three's Y rotation, x' = x c + z s, z' = -x s + z c.
|
|
494
|
+
const k = cs * s * (0.9 + rng() * 0.25);
|
|
495
|
+
(kind === "giant" ? nearClumps : farClumps).push([
|
|
496
|
+
x + (cx * c + cz * sn) * s,
|
|
497
|
+
y + cy * s,
|
|
498
|
+
z + (-cx * sn + cz * c) * s,
|
|
499
|
+
k,
|
|
500
|
+
k * 0.8,
|
|
501
|
+
k,
|
|
502
|
+
rng() * 0.4,
|
|
503
|
+
spin(),
|
|
504
|
+
rng() * 0.4,
|
|
505
|
+
]);
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
const bark = surfaced(0xffffff, "bark", { vertexColors: true });
|
|
509
|
+
giants.forEach((model, i) => {
|
|
510
|
+
const trunks = instanced(model.wood, bark, wood.giant[i] ?? [], true);
|
|
511
|
+
// The collider is the trunk; the roots and limbs it does not cover are drawn. The camera arm
|
|
512
|
+
// tests the drawn shape, so the lens never ends up inside a root.
|
|
513
|
+
trunks.userData.lens = true;
|
|
514
|
+
group.add(trunks);
|
|
515
|
+
});
|
|
516
|
+
// The far rings stand outside the sun's shadow window: they cast nothing.
|
|
517
|
+
fars.forEach((model, i) => {
|
|
518
|
+
group.add(instanced(model.wood, bark, wood.far[i] ?? [], false));
|
|
519
|
+
});
|
|
520
|
+
const canopy = canopyMaterial();
|
|
521
|
+
group.add(
|
|
522
|
+
// The crowns cast nothing: the canopy's shade (below) dapples the floor for far fewer triangles.
|
|
523
|
+
instanced(leafClump(14, 0.75, rng), canopy, nearClumps, false),
|
|
524
|
+
instanced(leafClump(6, 1.2, rng), canopy, farClumps, false),
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
// Undergrowth inside the clearing, mostly along the banks and round the trees; the path, the
|
|
528
|
+
// spawn yard and the fights stay open. `edge` picks a spot within `band` metres of a wall.
|
|
529
|
+
const inside = (band: number, width: number): [number, number] | undefined => {
|
|
530
|
+
for (let tries = 0; tries < 10; tries += 1) {
|
|
531
|
+
const side = rng();
|
|
532
|
+
const d = rng() * band;
|
|
533
|
+
const along = rng();
|
|
534
|
+
const x =
|
|
535
|
+
side < 0.35
|
|
536
|
+
? -clearing.half + d
|
|
537
|
+
: side < 0.7
|
|
538
|
+
? clearing.half - d
|
|
539
|
+
: -clearing.half + along * clearing.half * 2;
|
|
540
|
+
const z =
|
|
541
|
+
side < 0.7
|
|
542
|
+
? clearing.north + along * (clearing.south - clearing.north)
|
|
543
|
+
: side < 0.85
|
|
544
|
+
? clearing.north + d
|
|
545
|
+
: clearing.south - d;
|
|
546
|
+
if (clear(x, z, width) && site.stream.distance(x, z) > 2) return [x, z];
|
|
547
|
+
}
|
|
548
|
+
return undefined;
|
|
549
|
+
};
|
|
550
|
+
const anywhere = (width: number): [number, number] | undefined => {
|
|
551
|
+
for (let tries = 0; tries < 10; tries += 1) {
|
|
552
|
+
const x = (rng() * 2 - 1) * clearing.half;
|
|
553
|
+
const z = clearing.north + rng() * (clearing.south - clearing.north);
|
|
554
|
+
if (clear(x, z, width) && site.stream.distance(x, z) > 1.6) return [x, z];
|
|
555
|
+
}
|
|
556
|
+
return undefined;
|
|
557
|
+
};
|
|
558
|
+
/** Along the path's edges, just off the stones: where the reference's foreground plants grow. */
|
|
559
|
+
const verge = (width: number): [number, number] | undefined => {
|
|
560
|
+
for (let tries = 0; tries < 10; tries += 1) {
|
|
561
|
+
const z = clearing.north + 2 + rng() * (clearing.south - clearing.north - 2);
|
|
562
|
+
const x = site.pathX(z) + (rng() < 0.5 ? -1 : 1) * (2.3 + rng() * 2.5);
|
|
563
|
+
if (clear(x, z, width) && site.stream.distance(x, z) > 1.6) return [x, z];
|
|
564
|
+
}
|
|
565
|
+
return undefined;
|
|
566
|
+
};
|
|
567
|
+
// And the hills outside the walls, out to `reach`, where nothing needs to stay open.
|
|
568
|
+
const outside = (reach: number): [number, number] => {
|
|
569
|
+
const angle = spin();
|
|
570
|
+
const r = 23 + rng() * reach;
|
|
571
|
+
return [Math.cos(angle) * r, Math.sin(angle) * r * 0.9 - 2];
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// Big lobed broadleaf plants: six cupped leaves raised round a crown, dark at the heart.
|
|
575
|
+
const broad = new Color(C.broadleaf);
|
|
576
|
+
const broadTip = new Color(C.leafSun);
|
|
577
|
+
const broadleaf = mergeAll(
|
|
578
|
+
Array.from({ length: 6 }, (_, i) =>
|
|
579
|
+
leaf(
|
|
580
|
+
0.62 + (i % 3) * 0.1,
|
|
581
|
+
0.62,
|
|
582
|
+
broad.clone().multiplyScalar(0.7),
|
|
583
|
+
broad.clone().lerp(broadTip, 0.35),
|
|
584
|
+
0.18,
|
|
585
|
+
)
|
|
586
|
+
.rotateX(-1.15 - (i % 2) * 0.22)
|
|
587
|
+
.rotateY((i / 6) * Math.PI * 2 + i * 0.3),
|
|
588
|
+
),
|
|
589
|
+
);
|
|
590
|
+
const broadPlants: Placement[] = [];
|
|
591
|
+
for (let i = 0; i < 90; i += 1) {
|
|
592
|
+
const spot = i < 40 ? verge(1.2) : i < 75 ? inside(5, 1.2) : outside(8);
|
|
593
|
+
if (spot === undefined) continue;
|
|
594
|
+
const s = 0.75 + rng() * 0.7;
|
|
595
|
+
broadPlants.push(P(spot[0], 0, spot[1], s, s * (0.8 + rng() * 0.3)));
|
|
596
|
+
}
|
|
597
|
+
group.add(instanced(broadleaf, swaying(0.05), broadPlants, true));
|
|
598
|
+
|
|
599
|
+
const ferns: Placement[] = [];
|
|
600
|
+
for (let i = 0; i < 130; i += 1) {
|
|
601
|
+
const spot = i < 40 ? verge(0.8) : i < 105 ? inside(5, 0.8) : outside(10);
|
|
602
|
+
if (spot !== undefined) ferns.push(P(spot[0], 0, spot[1], 0.8 + rng() * 0.7));
|
|
603
|
+
}
|
|
604
|
+
group.add(instanced(fan(8, 0.11, 0.95, 1.0, C.fern, 0.25), swaying(0.1), ferns, false));
|
|
605
|
+
|
|
606
|
+
// Flower clusters: five star heads on thin stems, one colour per cluster; violet and pink most.
|
|
607
|
+
const cluster = (head: number): BufferGeometry =>
|
|
608
|
+
merge(
|
|
609
|
+
Array.from({ length: 5 }, (_, i) => {
|
|
610
|
+
const a = i * 1.3;
|
|
611
|
+
const r = 0.08 + (i % 3) * 0.07;
|
|
612
|
+
const h = 0.24 + (i % 2) * 0.12;
|
|
613
|
+
return [
|
|
614
|
+
[
|
|
615
|
+
new CylinderGeometry(0.008, 0.01, h, 3, 1, true).translate(
|
|
616
|
+
Math.cos(a) * r,
|
|
617
|
+
h / 2,
|
|
618
|
+
Math.sin(a) * r,
|
|
619
|
+
),
|
|
620
|
+
C.grassDark,
|
|
621
|
+
],
|
|
622
|
+
[
|
|
623
|
+
new CircleGeometry(0.045, 5)
|
|
624
|
+
.rotateX(-Math.PI / 2)
|
|
625
|
+
.translate(Math.cos(a) * r, h, Math.sin(a) * r),
|
|
626
|
+
head,
|
|
627
|
+
],
|
|
628
|
+
] as const;
|
|
629
|
+
}).flat(),
|
|
630
|
+
);
|
|
631
|
+
for (const [head, count] of [
|
|
632
|
+
[C.flowerViolet, 70],
|
|
633
|
+
[C.flowerPink, 55],
|
|
634
|
+
[C.flowerWhite, 18],
|
|
635
|
+
] as const) {
|
|
636
|
+
const placements: Placement[] = [];
|
|
637
|
+
for (let i = 0; i < count; i += 1) {
|
|
638
|
+
const spot = i < count * 0.45 ? verge(0.5) : anywhere(0.5);
|
|
639
|
+
if (spot !== undefined) placements.push(P(spot[0], 0, spot[1], 1 + rng() * 0.6));
|
|
640
|
+
}
|
|
641
|
+
group.add(instanced(cluster(head), swaying(0.25), placements, false));
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// Grass tufts in the open spaces off the path, where the canopy lets light in.
|
|
645
|
+
const tufts: Placement[] = [];
|
|
646
|
+
for (let i = 0; i < 340; i += 1) {
|
|
647
|
+
// Half of them fringe the path, where the cobbles meet the moss.
|
|
648
|
+
const z = clearing.north + rng() * (clearing.south - clearing.north);
|
|
649
|
+
const x =
|
|
650
|
+
i % 2 === 0
|
|
651
|
+
? site.pathX(z) + (rng() < 0.5 ? -1 : 1) * (1.75 + rng() * 1.4)
|
|
652
|
+
: (rng() * 2 - 1) * clearing.half;
|
|
653
|
+
if (Math.abs(x - site.pathX(z)) < 1.7 || site.stream.distance(x, z) < 1.4) continue;
|
|
654
|
+
tufts.push(P(x, 0, z, 0.7 + rng() * 0.9, 0.6 + rng() * 0.9));
|
|
655
|
+
}
|
|
656
|
+
group.add(instanced(fan(4, 0.04, 0.42, 0.4, C.grassTip), swaying(0.6), tufts, false));
|
|
657
|
+
|
|
658
|
+
// Mushrooms in rings under the giants, fallen logs, and mossy boulders.
|
|
659
|
+
const mushrooms: Placement[] = [];
|
|
660
|
+
for (const [x, z, s, kind] of site.trees) {
|
|
661
|
+
if (kind !== "giant") continue;
|
|
662
|
+
for (let i = 0; i < 5; i += 1) {
|
|
663
|
+
const a = spin();
|
|
664
|
+
const r = (1.3 + rng() * 1.2) * s;
|
|
665
|
+
mushrooms.push(P(x + Math.cos(a) * r, 0, z + Math.sin(a) * r, 0.7 + rng() * 0.7));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
group.add(
|
|
669
|
+
instanced(
|
|
670
|
+
merge([
|
|
671
|
+
[new CylinderGeometry(0.035, 0.045, 0.16, 6).translate(0, 0.08, 0), C.mushroomStem],
|
|
672
|
+
[
|
|
673
|
+
new SphereGeometry(0.11, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2).translate(0, 0.15, 0),
|
|
674
|
+
C.mushroomCap,
|
|
675
|
+
],
|
|
676
|
+
[new CylinderGeometry(0.025, 0.035, 0.1, 6).translate(0.12, 0.05, 0.05), C.mushroomStem],
|
|
677
|
+
[
|
|
678
|
+
new SphereGeometry(0.07, 8, 5, 0, Math.PI * 2, 0, Math.PI / 2).translate(
|
|
679
|
+
0.12,
|
|
680
|
+
0.09,
|
|
681
|
+
0.05,
|
|
682
|
+
),
|
|
683
|
+
C.mushroomCap,
|
|
684
|
+
],
|
|
685
|
+
]),
|
|
686
|
+
lit(0xffffff, { vertexColors: true }),
|
|
687
|
+
mushrooms,
|
|
688
|
+
false,
|
|
689
|
+
),
|
|
690
|
+
);
|
|
691
|
+
const logs: Placement[] = [];
|
|
692
|
+
for (let i = 0; i < 6; i += 1) {
|
|
693
|
+
const spot = i < 3 ? inside(4, 3) : outside(10);
|
|
694
|
+
if (spot === undefined) continue;
|
|
695
|
+
logs.push(P(spot[0], 0.05, spot[1], 1, 1));
|
|
696
|
+
shade.push([spot[0], spot[1], 1.3]);
|
|
697
|
+
}
|
|
698
|
+
group.add(
|
|
699
|
+
instanced(
|
|
700
|
+
mossBark(
|
|
701
|
+
mergeAll([
|
|
702
|
+
paint(
|
|
703
|
+
new CylinderGeometry(0.3, 0.34, 3, 9, 4).rotateX(Math.PI / 2).translate(0, 0.28, 0),
|
|
704
|
+
0xffffff,
|
|
705
|
+
),
|
|
706
|
+
]),
|
|
707
|
+
1,
|
|
708
|
+
),
|
|
709
|
+
surfaced(0xffffff, "bark", { vertexColors: true }),
|
|
710
|
+
logs,
|
|
711
|
+
true,
|
|
712
|
+
),
|
|
713
|
+
);
|
|
714
|
+
|
|
715
|
+
// Boulders: lumpy, grained stone with moss on every face that looks up. Some sit at the banks'
|
|
716
|
+
// feet, some crown the outcrops, a few line the stream.
|
|
717
|
+
const boulder = (() => {
|
|
718
|
+
const g = new IcosahedronGeometry(1, 1).toNonIndexed();
|
|
719
|
+
const position = g.attributes.position;
|
|
720
|
+
if (position !== undefined) {
|
|
721
|
+
const v = new Vector3();
|
|
722
|
+
for (let i = 0; i < position.count; i += 1) {
|
|
723
|
+
v.fromBufferAttribute(position, i);
|
|
724
|
+
const bump =
|
|
725
|
+
1 + 0.16 * Math.sin(v.x * 4.1 + v.y * 2.3) + 0.1 * Math.sin(v.z * 5.3 - v.x * 3.1);
|
|
726
|
+
v.multiplyScalar(bump);
|
|
727
|
+
position.setXYZ(i, v.x, v.y * 0.8, v.z);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
g.computeVertexNormals();
|
|
731
|
+
const normal = g.attributes.normal;
|
|
732
|
+
const colour = new Float32Array((position?.count ?? 0) * 3);
|
|
733
|
+
const rock = new Color(C.rock);
|
|
734
|
+
const moss = new Color(C.forestMoss);
|
|
735
|
+
const c = new Color();
|
|
736
|
+
for (let i = 0; i < (position?.count ?? 0); i += 1) {
|
|
737
|
+
const up = Math.min(1, Math.max(0, ((normal?.getY(i) ?? 0) - 0.25) / 0.45));
|
|
738
|
+
c.copy(rock).lerp(moss, up * 0.92);
|
|
739
|
+
colour.set([c.r, c.g, c.b], i * 3);
|
|
740
|
+
}
|
|
741
|
+
g.setAttribute("color", new BufferAttribute(colour, 3));
|
|
742
|
+
// Planar uvs for the stone grain.
|
|
743
|
+
const uv = new Float32Array((position?.count ?? 0) * 2);
|
|
744
|
+
for (let i = 0; i < (position?.count ?? 0); i += 1)
|
|
745
|
+
uv.set(
|
|
746
|
+
[
|
|
747
|
+
(position?.getX(i) ?? 0) * 0.8,
|
|
748
|
+
(position?.getY(i) ?? 0) * 0.8 + (position?.getZ(i) ?? 0) * 0.5,
|
|
749
|
+
],
|
|
750
|
+
i * 2,
|
|
751
|
+
);
|
|
752
|
+
g.setAttribute("uv", new BufferAttribute(uv, 2));
|
|
753
|
+
return g;
|
|
754
|
+
})();
|
|
755
|
+
const rocks: Placement[] = [];
|
|
756
|
+
const rockAt = (x: number, z: number, s: number): void => {
|
|
757
|
+
const yaw = spin();
|
|
758
|
+
const [rx, rz] = tiltTo(normalAt(x, z), yaw);
|
|
759
|
+
rocks.push([
|
|
760
|
+
x,
|
|
761
|
+
height(x, z) + s * 0.15,
|
|
762
|
+
z,
|
|
763
|
+
s * (1 + rng() * 0.4),
|
|
764
|
+
s * (0.6 + rng() * 0.3),
|
|
765
|
+
s,
|
|
766
|
+
rx,
|
|
767
|
+
yaw,
|
|
768
|
+
rz,
|
|
769
|
+
]);
|
|
770
|
+
shade.push([x, z, 1.1 * s]);
|
|
771
|
+
};
|
|
772
|
+
for (let i = 0; i < 40; i += 1) {
|
|
773
|
+
const spot = i < 26 ? inside(4, 1.5) : outside(14);
|
|
774
|
+
if (spot !== undefined) rockAt(spot[0], spot[1], 0.5 + rng() * 1.1);
|
|
775
|
+
}
|
|
776
|
+
for (const [x, z] of site.stream.points)
|
|
777
|
+
for (let i = 0; i < 3; i += 1)
|
|
778
|
+
rockAt(x + (rng() - 0.5) * 3, z + (rng() - 0.5) * 3, 0.3 + rng() * 0.4);
|
|
779
|
+
const stone = surfaced(0xffffff, "rock", { vertexColors: true });
|
|
780
|
+
const boulders = instanced(boulder, stone, rocks, true);
|
|
781
|
+
boulders.userData.lens = true;
|
|
782
|
+
group.add(boulders);
|
|
783
|
+
|
|
784
|
+
// The path: rounded cobbles, two to four across, a few centimetres proud of the dark soil and
|
|
785
|
+
// its moss, each tipped to the slope it lies on.
|
|
786
|
+
const slab = (() => {
|
|
787
|
+
const g = new SphereGeometry(1, 9, 3, 0, Math.PI * 2, 0, Math.PI / 2);
|
|
788
|
+
const position = g.attributes.position;
|
|
789
|
+
if (position !== undefined) {
|
|
790
|
+
for (let i = 0; i < position.count; i += 1) {
|
|
791
|
+
const x = position.getX(i);
|
|
792
|
+
const z = position.getZ(i);
|
|
793
|
+
const a = Math.atan2(z, x);
|
|
794
|
+
const k = 1 + 0.16 * Math.sin(a * 3 + 1.1) + 0.1 * Math.sin(a * 5 + 0.4);
|
|
795
|
+
// A flat-topped dome: the crown is broad, the edge rolls down into the soil.
|
|
796
|
+
const y = Math.min(1, position.getY(i) * 1.6) * 0.11;
|
|
797
|
+
position.setXYZ(i, x * k, y, z * k);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
g.computeVertexNormals();
|
|
801
|
+
const uv = new Float32Array((position?.count ?? 0) * 2);
|
|
802
|
+
for (let i = 0; i < (position?.count ?? 0); i += 1)
|
|
803
|
+
uv.set([(position?.getX(i) ?? 0) * 0.6, (position?.getZ(i) ?? 0) * 0.6], i * 2);
|
|
804
|
+
g.setAttribute("uv", new BufferAttribute(uv, 2));
|
|
805
|
+
return g;
|
|
806
|
+
})();
|
|
807
|
+
const slabs: [Placement[], Placement[]] = [[], []];
|
|
808
|
+
const laid: [number, number, number][] = [];
|
|
809
|
+
for (let z = clearing.south - 0.4; z > clearing.north - 0.4; z -= 0.62 + rng() * 0.1) {
|
|
810
|
+
const across = rng() < 0.5 ? [-0.75, -0.25, 0.25, 0.75] : [-0.62, 0, 0.62];
|
|
811
|
+
for (const offset of across) {
|
|
812
|
+
if (rng() < 0.1) continue;
|
|
813
|
+
const x = site.pathX(z) + offset + (rng() - 0.5) * 0.2;
|
|
814
|
+
const sz = z + (rng() - 0.5) * 0.14;
|
|
815
|
+
const r = (across.length === 4 ? 0.23 : 0.28) + rng() * 0.06;
|
|
816
|
+
const yaw = spin();
|
|
817
|
+
const [rx, rz] = tiltTo(normalAt(x, sz), yaw);
|
|
818
|
+
(rng() < 0.5 ? slabs[0] : slabs[1]).push([
|
|
819
|
+
x,
|
|
820
|
+
height(x, sz) - 0.05,
|
|
821
|
+
sz,
|
|
822
|
+
r * (1 + rng() * 0.25),
|
|
823
|
+
0.7 + rng() * 0.6,
|
|
824
|
+
r,
|
|
825
|
+
rx,
|
|
826
|
+
yaw,
|
|
827
|
+
rz,
|
|
828
|
+
]);
|
|
829
|
+
laid.push([x, sz, r]);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
group.add(
|
|
833
|
+
instanced(slab, surfaced(C.flagstoneDark, "rock", { roughness: 0.9 }), slabs[0], false),
|
|
834
|
+
instanced(slab, surfaced(C.flagstone2, "rock", { roughness: 0.9 }), slabs[1], false),
|
|
835
|
+
);
|
|
836
|
+
// How much of the path's centre line a slab covers: the playtest's proof the path is laid.
|
|
837
|
+
let covered = 0;
|
|
838
|
+
let samples = 0;
|
|
839
|
+
for (let z = clearing.south - 1; z > clearing.north; z -= 0.25) {
|
|
840
|
+
samples += 1;
|
|
841
|
+
const x = site.pathX(z);
|
|
842
|
+
if (laid.some(([sx, sz, r]) => Math.hypot(x - sx, z - sz) < r)) covered += 1;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// The stream's water: a dark, smooth ribbon down its bed, which the reflections pick up.
|
|
846
|
+
const water = (() => {
|
|
847
|
+
const position: number[] = [];
|
|
848
|
+
const points = site.stream.points;
|
|
849
|
+
for (let i = 1; i < points.length; i += 1) {
|
|
850
|
+
const [ax, az] = points[i - 1] ?? [0, 0];
|
|
851
|
+
const [bx, bz] = points[i] ?? [0, 0];
|
|
852
|
+
const len = Math.hypot(bx - ax, bz - az);
|
|
853
|
+
const nx = (-(bz - az) / len) * 1.9;
|
|
854
|
+
const nz = ((bx - ax) / len) * 1.9;
|
|
855
|
+
const y = site.stream.water;
|
|
856
|
+
position.push(ax - nx, y, az - nz, bx - nx, y, bz - nz, bx + nx, y, bz + nz);
|
|
857
|
+
position.push(ax - nx, y, az - nz, bx + nx, y, bz + nz, ax + nx, y, az + nz);
|
|
858
|
+
}
|
|
859
|
+
const g = new BufferGeometry();
|
|
860
|
+
g.setAttribute("position", new BufferAttribute(new Float32Array(position), 3));
|
|
861
|
+
g.computeVertexNormals();
|
|
862
|
+
return new Mesh(g, lit(C.water, { doubleSided: true, roughness: 0.08 }));
|
|
863
|
+
})();
|
|
864
|
+
water.receiveShadow = true;
|
|
865
|
+
group.add(water);
|
|
866
|
+
|
|
867
|
+
// Ivy clumps on the cliff faces and the ruin, and vines hanging from their tops.
|
|
868
|
+
const ivy: Placement[] = [];
|
|
869
|
+
const vines: Placement[] = [];
|
|
870
|
+
for (const [x, y, z, w, h, yaw] of site.walls) {
|
|
871
|
+
const across = (u: number): [number, number] => [
|
|
872
|
+
x + Math.cos(yaw) * (u - 0.5) * w,
|
|
873
|
+
z - Math.sin(yaw) * (u - 0.5) * w,
|
|
874
|
+
];
|
|
875
|
+
const patches = Math.max(1, Math.round(w * 0.3));
|
|
876
|
+
for (let i = 0; i < patches; i += 1) {
|
|
877
|
+
const u = (i + 0.2 + rng() * 0.6) / patches;
|
|
878
|
+
for (let k = 0; k < 7; k += 1) {
|
|
879
|
+
const [cx, cz] = across(u + (rng() - 0.5) * (1.6 / w));
|
|
880
|
+
const drop = k < 4 ? rng() * 0.6 : 0.6 + rng() * h * 0.45;
|
|
881
|
+
const s = (k < 4 ? 0.45 : 0.3) + rng() * 0.25;
|
|
882
|
+
ivy.push([cx, y + h / 2 - drop, cz, s * 1.5, s, s * 0.3, 0, yaw, rng()]);
|
|
883
|
+
}
|
|
884
|
+
for (let k = 0; k < 4; k += 1) {
|
|
885
|
+
const [vx, vz] = across(u + (rng() - 0.5) * (1.4 / w));
|
|
886
|
+
vines.push([vx, y + h / 2, vz, 1, 0.8 + rng() * h * 0.7, 1, 0, yaw, 0]);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
group.add(
|
|
891
|
+
instanced(new IcosahedronGeometry(1, 0), lit(C.ivy, { flat: true }), ivy, false),
|
|
892
|
+
instanced(
|
|
893
|
+
merge([
|
|
894
|
+
[new CylinderGeometry(0.03, 0.03, 1, 4, 1, true).translate(0, -0.5, 0), C.ivy],
|
|
895
|
+
[new OctahedronGeometry(0.09, 0).translate(0.05, -0.35, 0.02), C.leaf],
|
|
896
|
+
[new OctahedronGeometry(0.08, 0).translate(-0.05, -0.7, 0.02), C.leaf],
|
|
897
|
+
]),
|
|
898
|
+
lit(0xffffff, { flat: true, vertexColors: true }),
|
|
899
|
+
vines,
|
|
900
|
+
false,
|
|
901
|
+
),
|
|
902
|
+
);
|
|
903
|
+
// The canopy's shade: leaf-sized pentagons high over the clearing that only cast shadow, so the
|
|
904
|
+
// floor is dappled. Its gaps sit where the sun shafts come down, so each shaft lands in light.
|
|
905
|
+
const canopyY = 10;
|
|
906
|
+
const gaps = SHAFTS.map(([x, z, r]) => {
|
|
907
|
+
const t = (canopyY - height(x, z)) / SUN_DIRECTION.y;
|
|
908
|
+
return [x + SUN_DIRECTION.x * t, z + SUN_DIRECTION.z * t, r * 1.5] as const;
|
|
909
|
+
});
|
|
910
|
+
const discs: BufferGeometry[] = [];
|
|
911
|
+
for (let i = 0; i < 1600; i += 1) {
|
|
912
|
+
const x = (rng() * 2 - 1) * 30 - 6;
|
|
913
|
+
const z = -30 + rng() * 52;
|
|
914
|
+
const r = 0.7 + rng() * 0.75;
|
|
915
|
+
if (gaps.some(([gx, gz, gr]) => Math.hypot(x - gx, z - gz) < gr + r * 0.5)) continue;
|
|
916
|
+
if (Math.sin(x * 0.7) * Math.cos(z * 0.6) + Math.sin(x * 0.23 + z * 0.31) > 1.65) continue;
|
|
917
|
+
discs.push(
|
|
918
|
+
new CircleGeometry(r, 5)
|
|
919
|
+
.rotateX(-Math.PI / 2)
|
|
920
|
+
.scale(1, 1, 0.6 + rng() * 0.6)
|
|
921
|
+
.rotateY(spin())
|
|
922
|
+
.translate(x, canopyY + rng() * 2.5, z),
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
const shadeMaterial = new MeshStandardNodeMaterial({
|
|
926
|
+
colorWrite: false,
|
|
927
|
+
depthWrite: false,
|
|
928
|
+
side: DoubleSide,
|
|
929
|
+
});
|
|
930
|
+
const canopyShade = new Mesh(mergeAll(discs), shadeMaterial);
|
|
931
|
+
canopyShade.name = "canopy-shade";
|
|
932
|
+
canopyShade.castShadow = true;
|
|
933
|
+
group.add(canopyShade, sunShafts(SHAFTS, height));
|
|
934
|
+
return {
|
|
935
|
+
group,
|
|
936
|
+
path: { cover: samples === 0 ? 0 : covered / samples, stones: laid.length },
|
|
937
|
+
shade,
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** A grid of the height function from x0..x1, z0..z1 at `step`; `skip` drops a cell. */
|
|
942
|
+
function heightGrid(
|
|
943
|
+
site: IValeSite,
|
|
944
|
+
x0: number,
|
|
945
|
+
x1: number,
|
|
946
|
+
z0: number,
|
|
947
|
+
z1: number,
|
|
948
|
+
step: number,
|
|
949
|
+
lower: (x: number, z: number) => number,
|
|
950
|
+
skip?: (x: number, z: number) => boolean,
|
|
951
|
+
): BufferGeometry {
|
|
952
|
+
const nx = Math.round((x1 - x0) / step);
|
|
953
|
+
const nz = Math.round((z1 - z0) / step);
|
|
954
|
+
const position = new Float32Array((nx + 1) * (nz + 1) * 3);
|
|
955
|
+
const uv = new Float32Array((nx + 1) * (nz + 1) * 2);
|
|
956
|
+
for (let j = 0; j <= nz; j += 1) {
|
|
957
|
+
for (let i = 0; i <= nx; i += 1) {
|
|
958
|
+
const x = x0 + i * step;
|
|
959
|
+
const z = z0 + j * step;
|
|
960
|
+
const k = j * (nx + 1) + i;
|
|
961
|
+
position.set([x, site.height(x, z) - lower(x, z), z], k * 3);
|
|
962
|
+
uv.set([x * 0.3, z * 0.3], k * 2);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const index: number[] = [];
|
|
966
|
+
for (let j = 0; j < nz; j += 1) {
|
|
967
|
+
for (let i = 0; i < nx; i += 1) {
|
|
968
|
+
if (skip?.(x0 + (i + 0.5) * step, z0 + (j + 0.5) * step) === true) continue;
|
|
969
|
+
const a = j * (nx + 1) + i;
|
|
970
|
+
const b = a + 1;
|
|
971
|
+
const c = a + nx + 1;
|
|
972
|
+
const d = c + 1;
|
|
973
|
+
index.push(a, c, b, b, c, d);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const g = new BufferGeometry();
|
|
977
|
+
g.setAttribute("position", new BufferAttribute(position, 3));
|
|
978
|
+
g.setAttribute("uv", new BufferAttribute(uv, 2));
|
|
979
|
+
g.setIndex(index);
|
|
980
|
+
g.computeVertexNormals();
|
|
981
|
+
return g;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** The fine floor's extent: the clearing, its banks and the cave tunnel. */
|
|
985
|
+
const INNER = { x0: -26.25, x1: 26.25, z0: -30, z1: 22.5, step: 0.75 };
|
|
986
|
+
|
|
987
|
+
/**
|
|
988
|
+
* The vale's floor: a fine grid where Wren walks (`inner`, also her collider) and a coarse one for
|
|
989
|
+
* the hills (`outer`), both over the height function. Soil, moss and litter; rock past the walk
|
|
990
|
+
* limit; dark soil under the path; a wet stream bed; contact shade under trunks, rocks and logs.
|
|
991
|
+
*/
|
|
992
|
+
export function valeGround(
|
|
993
|
+
site: IValeSite,
|
|
994
|
+
shade: readonly (readonly [number, number, number])[],
|
|
995
|
+
): { readonly inner: Mesh; readonly outer: Mesh } {
|
|
996
|
+
const swatch = (hex: number): Color => new Color(hex);
|
|
997
|
+
const soil = swatch(C.soil);
|
|
998
|
+
const litter = swatch(C.litter);
|
|
999
|
+
const moss = swatch(C.forestMoss);
|
|
1000
|
+
const mossBright = swatch(C.mossBright);
|
|
1001
|
+
const meadow = swatch(palette.grass);
|
|
1002
|
+
const rock = swatch(C.cliff);
|
|
1003
|
+
const wet = swatch(C.soilWet);
|
|
1004
|
+
const c = new Color();
|
|
1005
|
+
const wave = (x: number, z: number, f: number): number =>
|
|
1006
|
+
0.5 + 0.25 * (Math.sin(x * f + z * f * 0.55) + Math.sin(z * f * 1.4 - x * f * 0.37 + 1.3));
|
|
1007
|
+
const smooth = (a: number, b: number, t: number): number => {
|
|
1008
|
+
const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
|
|
1009
|
+
return u * u * (3 - 2 * u);
|
|
1010
|
+
};
|
|
1011
|
+
const paintGround = (geometry: BufferGeometry): void => {
|
|
1012
|
+
const position = geometry.attributes.position;
|
|
1013
|
+
const normal = geometry.attributes.normal;
|
|
1014
|
+
if (position === undefined || normal === undefined)
|
|
1015
|
+
throw new Error("valeGround: no positions.");
|
|
1016
|
+
const colour = new Float32Array(position.count * 3);
|
|
1017
|
+
for (let i = 0; i < position.count; i += 1) {
|
|
1018
|
+
const x = position.getX(i);
|
|
1019
|
+
const z = position.getZ(i);
|
|
1020
|
+
// Moss and soil in patches, a lighter meadow green where the canopy opens, litter round trees.
|
|
1021
|
+
c.copy(soil).lerp(moss, 0.35 + 0.55 * smooth(0.35, 0.75, wave(x + 40, z - 17, 0.27)));
|
|
1022
|
+
c.lerp(mossBright, smooth(0.6, 0.85, wave(x - 3, z + 5, 0.45)) * 0.5);
|
|
1023
|
+
c.lerp(meadow, smooth(0.66, 0.82, wave(x * 0.7, z * 0.7 + 9, 0.21)) * 0.3);
|
|
1024
|
+
let nearTree = 0;
|
|
1025
|
+
for (const [tx, tz, ts] of site.trees) {
|
|
1026
|
+
const d = Math.hypot(x - tx, z - tz);
|
|
1027
|
+
if (d < 5 * ts) nearTree = Math.max(nearTree, 1 - smooth(1.4 * ts, 4.5 * ts, d));
|
|
1028
|
+
}
|
|
1029
|
+
c.lerp(litter, nearTree * 0.6 * (0.6 + 0.4 * wave(x, z, 0.9)));
|
|
1030
|
+
// Dark soil under the path, the flagstones on top of it.
|
|
1031
|
+
const off = Math.abs(x - site.pathX(z)) + (wave(x, z, 1.3) - 0.5) * 0.5;
|
|
1032
|
+
if (z > site.clearing.north - 9 && z < site.clearing.south + 1)
|
|
1033
|
+
c.lerp(soil, (1 - smooth(1.2, 1.9, off)) * 0.85);
|
|
1034
|
+
// Rock wherever the ground is steeper than Wren can climb (45°), moss on its gentler shoulders.
|
|
1035
|
+
const up = normal.getY(i);
|
|
1036
|
+
c.lerp(rock, smooth(0.8, 0.68, up));
|
|
1037
|
+
// The stream bed: wet and dark.
|
|
1038
|
+
c.lerp(wet, 1 - smooth(1.2, 2.6, site.stream.distance(x, z)));
|
|
1039
|
+
// Contact shade: under every trunk, rock and log.
|
|
1040
|
+
let light = 1;
|
|
1041
|
+
for (const [sx, sz, sr] of shade) {
|
|
1042
|
+
const d = Math.hypot(x - sx, z - sz);
|
|
1043
|
+
if (d < sr * 1.7) light *= 1 - 0.4 * (1 - smooth(sr * 0.5, sr * 1.7, d));
|
|
1044
|
+
}
|
|
1045
|
+
c.multiplyScalar(light);
|
|
1046
|
+
colour.set([c.r, c.g, c.b], i * 3);
|
|
1047
|
+
}
|
|
1048
|
+
geometry.setAttribute("color", new BufferAttribute(colour, 3));
|
|
1049
|
+
};
|
|
1050
|
+
const material = groundSurface();
|
|
1051
|
+
const inner = heightGrid(site, INNER.x0, INNER.x1, INNER.z0, INNER.z1, INNER.step, () => 0);
|
|
1052
|
+
paintGround(inner);
|
|
1053
|
+
// The coarse hills skip what the fine grid covers, and dip a little under its rim so the two
|
|
1054
|
+
// never fight where they overlap.
|
|
1055
|
+
const outer = heightGrid(
|
|
1056
|
+
site,
|
|
1057
|
+
-72,
|
|
1058
|
+
72,
|
|
1059
|
+
-72,
|
|
1060
|
+
72,
|
|
1061
|
+
4,
|
|
1062
|
+
(x, z) =>
|
|
1063
|
+
x > INNER.x0 - 4 && x < INNER.x1 + 4 && z > INNER.z0 - 4 && z < INNER.z1 + 4 ? 0.25 : 0,
|
|
1064
|
+
(x, z) => x > INNER.x0 + 2 && x < INNER.x1 - 2 && z > INNER.z0 + 2 && z < INNER.z1 - 2,
|
|
1065
|
+
);
|
|
1066
|
+
paintGround(outer);
|
|
1067
|
+
const meshes = { inner: new Mesh(inner, material), outer: new Mesh(outer, material) };
|
|
1068
|
+
meshes.inner.receiveShadow = true;
|
|
1069
|
+
meshes.outer.receiveShadow = true;
|
|
1070
|
+
meshes.inner.name = "vale-floor";
|
|
1071
|
+
return meshes;
|
|
1072
|
+
}
|