create-threenative 0.2.15 → 0.2.18
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/kit-mcp.md +10 -0
- package/agent-docs/kit-router.md +14 -0
- package/agent-docs/kit-stuck.md +7 -0
- package/agent-docs/references/assertion-reference.md +54 -110
- package/agent-docs/references/capability-reference.md +1740 -254
- package/agent-docs/references/conventions.md +299 -0
- package/agent-docs/references/kit-action-rpg.md +40 -0
- package/agent-docs/references/kit-adventure.md +40 -0
- package/agent-docs/references/kit-collectathon.md +38 -0
- package/agent-docs/references/kit-kart.md +31 -0
- package/agent-docs/references/kit-minimal.md +29 -0
- package/agent-docs/references/kit-platformer.md +34 -0
- package/agent-docs/references/kit-puzzle.md +22 -0
- package/agent-docs/references/kit-racing.md +26 -0
- package/agent-docs/references/kit-rain.md +31 -0
- package/agent-docs/references/kit-rts.md +34 -0
- package/agent-docs/references/kit-runner.md +32 -0
- package/agent-docs/references/kit-sailing.md +41 -0
- package/agent-docs/references/kit-shooter.md +33 -0
- package/agent-docs/references/kit-snow.md +33 -0
- package/agent-docs/references/kit-starter.md +55 -0
- package/agent-docs/references/kit-tower-defense.md +27 -0
- package/agent-docs/references/performance-basics.md +8 -4
- package/agent-docs/references/terrain-authoring.md +2 -1
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/prd-creator/SKILL.md +3 -2
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +84 -59
- package/agent-files/.claude/hooks/discovery-gate.mjs +125 -0
- package/agent-files/.claude/hooks/ponytail-context.mjs +1 -1
- package/agent-files/.claude/settings.json +25 -0
- package/agent-files/.codex/hooks.json +18 -1
- package/dist/index.d.ts +97 -6
- package/dist/index.js +899 -271
- package/dist/terrain-kit.d.ts +7 -0
- package/dist/terrain-kit.js +82 -0
- package/dist/threenative.js +114 -16
- package/dist/web-engine-ccd-ik-solver.js +127 -0
- package/dist/web-engine-gltf-loader.js +71 -20
- package/dist/web-engine-post-effects.js +39 -14
- package/dist/web-engine-runtime.js +10011 -4101
- package/package.json +15 -9
- package/template-assets/clearwater/README.md +1 -1
- package/template-assets/patches/manifest.json +18 -0
- package/template-assets/patches/three@0.187.0.patch +2004 -407
- package/template-assets/terrain/alpine/assets.json +12 -0
- package/template-assets/terrain/alpine/bake.mjs +6 -0
- package/template-assets/terrain/alpine/credits.json +164 -0
- package/template-assets/terrain/alpine/heightmap.r16 +0 -0
- package/template-assets/terrain/alpine/recipe.json +119 -0
- package/template-assets/terrain/alpine/surface.json +53 -0
- package/template-assets/terrain/coastal/assets.json +11 -0
- package/template-assets/terrain/coastal/bake.mjs +6 -0
- package/template-assets/terrain/coastal/credits.json +117 -0
- package/template-assets/terrain/coastal/heightmap.r16 +0 -0
- package/template-assets/terrain/coastal/recipe.json +113 -0
- package/template-assets/terrain/coastal/surface.json +41 -0
- package/template-assets/terrain/desert/assets.json +12 -0
- package/template-assets/terrain/desert/bake.mjs +6 -0
- package/template-assets/terrain/desert/credits.json +164 -0
- package/template-assets/terrain/desert/heightmap.r16 +0 -0
- package/template-assets/terrain/desert/recipe.json +108 -0
- package/template-assets/terrain/desert/surface.json +54 -0
- package/template-assets/terrain/forest/assets.json +65 -0
- package/template-assets/terrain/forest/bake.mjs +8 -0
- package/template-assets/terrain/forest/credits.json +225 -0
- package/template-assets/terrain/forest/heightmap.r16 +0 -0
- package/template-assets/terrain/forest/recipe.json +350 -0
- package/template-assets/terrain/forest/surface.json +79 -0
- package/template-assets/terrain/tundra/assets.json +12 -0
- package/template-assets/terrain/tundra/bake.mjs +6 -0
- package/template-assets/terrain/tundra/credits.json +164 -0
- package/template-assets/terrain/tundra/heightmap.r16 +0 -0
- package/template-assets/terrain/tundra/recipe.json +277 -0
- package/template-assets/terrain/tundra/surface.json +54 -0
- package/templates/action-rpg/AGENTS.md +103 -84
- package/templates/action-rpg/CLAUDE.md +103 -84
- package/templates/action-rpg/kit.json +1 -0
- package/templates/action-rpg/package.json +7 -7
- package/templates/action-rpg/playtests/spells.playtest.json +20 -0
- package/templates/action-rpg/src/game.ts +2 -1
- package/templates/action-rpg/src/render/atmosphere.ts +11 -16
- package/templates/action-rpg/src/render/backlightControls.ts +10 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
- package/templates/action-rpg/src/render/clouds.ts +13 -0
- package/templates/action-rpg/src/render/gpuSky.ts +4 -7
- package/templates/action-rpg/src/render/materialLighting.ts +5 -5
- package/templates/action-rpg/src/render/quality.ts +10 -33
- package/templates/action-rpg/src/scenes/Play.ts +30 -1
- package/templates/action-rpg/src/style.css +4 -0
- package/templates/action-rpg/src/ui/AbilityBar.tsx +1 -1
- package/templates/action-rpg/threenative.config.ts +0 -3
- package/templates/action-rpg/vite.config.ts +2 -0
- package/templates/adventure/AGENTS.md +92 -44
- package/templates/adventure/CLAUDE.md +92 -44
- package/templates/adventure/kit.json +5 -1
- package/templates/adventure/package.json +7 -7
- package/templates/adventure/src/game.ts +1 -1
- package/templates/adventure/src/style.css +4 -0
- package/templates/adventure/tsconfig.json +1 -1
- package/templates/adventure/vite.config.ts +2 -0
- package/templates/collectathon/AGENTS.md +93 -42
- package/templates/collectathon/CLAUDE.md +93 -42
- package/templates/collectathon/package.json +7 -7
- package/templates/collectathon/src/game.ts +1 -1
- package/templates/collectathon/src/level/Course.ts +55 -9
- package/templates/collectathon/src/level/terrain.ts +27 -6
- package/templates/collectathon/src/main.ts +1 -0
- package/templates/collectathon/src/render/foliage.ts +359 -98
- package/templates/collectathon/src/render/sky.ts +76 -12
- package/templates/collectathon/src/render/water.ts +32 -10
- package/templates/collectathon/src/scenes/Play.ts +18 -5
- package/templates/collectathon/src/style.css +4 -0
- package/templates/collectathon/tsconfig.json +1 -1
- package/templates/collectathon/vite.config.ts +2 -0
- package/templates/kart/AGENTS.md +87 -42
- package/templates/kart/CLAUDE.md +87 -42
- package/templates/kart/package.json +6 -6
- package/templates/kart/src/game.ts +1 -1
- package/templates/kart/src/main.ts +1 -0
- package/templates/kart/src/style.css +4 -0
- package/templates/kart/tsconfig.json +1 -1
- package/templates/kart/vite.config.ts +2 -0
- package/templates/minimal/AGENTS.md +105 -84
- package/templates/minimal/CLAUDE.md +105 -84
- package/templates/minimal/package.json +6 -6
- package/templates/minimal/playtests/stands-still.playtest.json +30 -0
- package/templates/minimal/src/game.ts +1 -1
- package/templates/minimal/src/render/atmosphere.ts +11 -16
- package/templates/minimal/src/render/backlightControls.ts +10 -0
- package/templates/minimal/src/render/backlightMaterial.ts +4 -4
- package/templates/minimal/src/render/camera.ts +13 -2
- package/templates/minimal/src/render/clouds.ts +13 -0
- package/templates/minimal/src/render/gpuSky.ts +4 -7
- package/templates/minimal/src/render/lighting.ts +4 -2
- package/templates/minimal/src/render/materialLighting.ts +5 -5
- package/templates/minimal/src/render/materials.ts +10 -0
- package/templates/minimal/src/render/quality.ts +7 -32
- package/templates/minimal/src/scenes/Play.ts +4 -1
- package/templates/minimal/vite.config.ts +7 -1
- package/templates/platformer/AGENTS.md +95 -46
- package/templates/platformer/CLAUDE.md +95 -46
- package/templates/platformer/index.html +1 -1
- package/templates/platformer/main.html +12 -0
- package/templates/platformer/package.json +7 -7
- package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
- package/templates/platformer/playtests/gamepad.playtest.json +30 -0
- package/templates/platformer/src/entities/Fox.ts +21 -6
- package/templates/platformer/src/game.ts +1 -1
- package/templates/platformer/src/main.ts +1 -0
- package/templates/platformer/src/render/backlightControls.ts +10 -0
- package/templates/platformer/src/render/backlightMaterial.ts +4 -4
- package/templates/platformer/src/render/materialLighting.ts +5 -5
- package/templates/platformer/src/render/quality.ts +7 -32
- package/templates/platformer/src/scenes/Play.ts +2 -1
- package/templates/platformer/src/style.css +4 -0
- package/templates/platformer/src/worker-page.ts +29 -0
- package/templates/platformer/src/worker.ts +5 -0
- package/templates/platformer/tsconfig.json +1 -1
- package/templates/platformer/vite.config.ts +4 -0
- package/templates/puzzle/AGENTS.md +97 -80
- package/templates/puzzle/CLAUDE.md +97 -80
- package/templates/puzzle/package.json +7 -7
- package/templates/puzzle/src/game.ts +1 -1
- package/templates/puzzle/src/render/backlightControls.ts +10 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
- package/templates/puzzle/src/render/materialLighting.ts +5 -5
- package/templates/puzzle/src/render/quality.ts +7 -32
- package/templates/puzzle/src/scenes/Play.ts +1 -1
- package/templates/puzzle/src/style.css +4 -0
- package/templates/puzzle/tsconfig.json +1 -1
- package/templates/puzzle/vite.config.ts +2 -0
- package/templates/racing/AGENTS.md +100 -82
- package/templates/racing/CLAUDE.md +100 -82
- package/templates/racing/package.json +7 -7
- package/templates/racing/src/game.ts +1 -1
- package/templates/racing/src/render/atmosphere.ts +11 -16
- package/templates/racing/src/render/backlightControls.ts +10 -0
- package/templates/racing/src/render/backlightMaterial.ts +4 -4
- package/templates/racing/src/render/clouds.ts +13 -0
- package/templates/racing/src/render/gpuSky.ts +4 -7
- package/templates/racing/src/render/materialLighting.ts +5 -5
- package/templates/racing/src/render/quality.ts +7 -32
- package/templates/racing/src/scenes/Race.ts +4 -1
- package/templates/racing/src/style.css +4 -0
- package/templates/racing/tsconfig.json +1 -1
- package/templates/racing/vite.config.ts +2 -0
- package/templates/rain/AGENTS.md +96 -84
- package/templates/rain/CLAUDE.md +96 -84
- package/templates/rain/native-playtests/lightning.playtest.json +85 -10
- package/templates/rain/package.json +6 -6
- package/templates/rain/playtests/reduced-motion.playtest.json +6 -0
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/src/scenes/Boot.ts +1 -0
- package/templates/rain/src/state.ts +7 -0
- package/templates/rain/src/ui/GameUi.tsx +7 -1
- package/templates/rain/vite.config.ts +6 -0
- package/templates/rts/AGENTS.md +100 -85
- package/templates/rts/CLAUDE.md +100 -85
- package/templates/rts/package.json +6 -6
- package/templates/rts/src/game.ts +1 -1
- package/templates/rts/src/render/backlightControls.ts +10 -0
- package/templates/rts/src/render/backlightMaterial.ts +4 -4
- package/templates/rts/src/render/materialLighting.ts +5 -5
- package/templates/rts/src/render/quality.ts +7 -31
- package/templates/rts/src/scenes/Play.ts +1 -1
- package/templates/rts/src/style.css +4 -0
- package/templates/rts/vite.config.ts +2 -0
- package/templates/runner/AGENTS.md +97 -80
- package/templates/runner/CLAUDE.md +97 -80
- package/templates/runner/package.json +7 -7
- package/templates/runner/playtests/performance.playtest.json +1 -1
- package/templates/runner/src/game.ts +1 -1
- package/templates/runner/src/render/atmosphere.ts +11 -16
- package/templates/runner/src/render/backlightControls.ts +10 -0
- package/templates/runner/src/render/backlightMaterial.ts +4 -4
- package/templates/runner/src/render/clouds.ts +13 -0
- package/templates/runner/src/render/gpuSky.ts +4 -7
- package/templates/runner/src/render/lighting.ts +53 -11
- package/templates/runner/src/render/materialLighting.ts +5 -5
- package/templates/runner/src/render/quality.ts +7 -32
- package/templates/runner/src/scenes/Run.ts +8 -4
- package/templates/runner/src/style.css +4 -0
- package/templates/runner/threenative.config.ts +0 -3
- package/templates/runner/tsconfig.json +1 -1
- package/templates/runner/vite.config.ts +2 -0
- package/templates/sailing/AGENTS.md +96 -79
- package/templates/sailing/CLAUDE.md +96 -79
- package/templates/sailing/package.json +7 -7
- package/templates/sailing/playtests/sails.playtest.json +1 -0
- package/templates/sailing/src/game.ts +1 -1
- package/templates/sailing/src/render/backlightControls.ts +10 -0
- package/templates/sailing/src/render/backlightMaterial.ts +4 -4
- package/templates/sailing/src/render/environmentSetup.ts +1 -1
- package/templates/sailing/src/render/materialLighting.ts +5 -5
- package/templates/sailing/src/render/quality.ts +7 -32
- package/templates/sailing/src/render/sky.ts +4 -0
- package/templates/sailing/src/style.css +5 -0
- package/templates/sailing/threenative.config.ts +0 -3
- package/templates/sailing/vite.config.ts +6 -0
- package/templates/shooter/AGENTS.md +97 -68
- package/templates/shooter/CLAUDE.md +97 -68
- package/templates/shooter/package.json +7 -7
- package/templates/shooter/src/game.ts +3 -2
- package/templates/shooter/src/render/atmosphere.ts +11 -16
- package/templates/shooter/src/render/backlightControls.ts +10 -0
- package/templates/shooter/src/render/backlightMaterial.ts +4 -4
- package/templates/shooter/src/render/clouds.ts +13 -0
- package/templates/shooter/src/render/gpuSky.ts +4 -7
- package/templates/shooter/src/render/materialLighting.ts +5 -5
- package/templates/shooter/src/render/quality.ts +10 -33
- package/templates/shooter/src/scenes/Play.ts +4 -1
- package/templates/shooter/src/style.css +4 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/AGENTS.md +95 -76
- package/templates/snow/CLAUDE.md +95 -76
- package/templates/snow/package.json +7 -7
- package/templates/snow/src/game.ts +1 -1
- package/templates/snow/src/render/backlightControls.ts +10 -0
- package/templates/snow/src/render/backlightMaterial.ts +4 -4
- package/templates/snow/src/render/materialLighting.ts +5 -5
- package/templates/snow/src/render/quality.ts +7 -32
- package/templates/snow/src/style.css +5 -0
- package/templates/snow/threenative.config.ts +0 -3
- package/templates/snow/vite.config.ts +6 -0
- package/templates/starter/AGENTS.md +109 -88
- package/templates/starter/CLAUDE.md +109 -88
- package/templates/starter/native-playtests/render-chain.playtest.json +24 -24
- package/templates/starter/native-playtests/smooth-motion.playtest.json +3 -3
- package/templates/starter/package.json +7 -7
- package/templates/starter/src/entities/Crate.ts +5 -2
- package/templates/starter/src/entities/Player.ts +10 -22
- package/templates/starter/src/game.ts +4 -3
- package/templates/starter/src/render/adaptiveQuality.ts +17 -0
- package/templates/starter/src/render/atmosphere.ts +11 -16
- package/templates/starter/src/render/backlightControls.ts +10 -0
- package/templates/starter/src/render/backlightMaterial.ts +4 -4
- package/templates/starter/src/render/clouds.ts +13 -0
- package/templates/starter/src/render/contactShadow.ts +1 -1
- package/templates/starter/src/render/gpuSky.ts +4 -7
- package/templates/starter/src/render/lighting.ts +54 -4
- package/templates/starter/src/render/materialLighting.ts +5 -5
- package/templates/starter/src/render/postprocessing.ts +11 -10
- package/templates/starter/src/render/quality.ts +14 -1
- package/templates/starter/src/render/temporalAA.ts +8 -7
- package/templates/starter/src/render/temporalAAFrame.ts +30 -9
- package/templates/starter/src/render/temporalAAResolve.ts +15 -1
- package/templates/starter/src/render/temporalClampRelease.ts +183 -0
- package/templates/starter/src/render/temporalHistoryResolve.ts +90 -0
- package/templates/starter/src/render/temporalMoire.ts +190 -0
- package/templates/starter/src/render/temporalResolve.ts +75 -16
- package/templates/starter/src/render/temporalResolveDepth.ts +2 -0
- package/templates/starter/src/scenes/Play.ts +53 -32
- package/templates/starter/src/state.ts +2 -0
- package/templates/starter/src/style.css +4 -0
- package/templates/starter/src/ui/Menu.tsx +5 -1
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/AGENTS.md +97 -81
- package/templates/tower-defense/CLAUDE.md +97 -81
- package/templates/tower-defense/package.json +7 -7
- package/templates/tower-defense/src/game.ts +1 -1
- package/templates/tower-defense/src/render/backlightControls.ts +10 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
- package/templates/tower-defense/src/render/materialLighting.ts +5 -5
- package/templates/tower-defense/src/render/quality.ts +7 -32
- package/templates/tower-defense/src/scenes/Battle.ts +1 -1
- package/templates/tower-defense/src/style.css +4 -0
- package/templates/tower-defense/tsconfig.json +1 -1
- package/templates/tower-defense/vite.config.ts +2 -0
- package/capabilities.json +0 -9197
- package/templates/AGENTS.md +0 -21
- package/templates/CLAUDE.md +0 -23
- package/templates/action-rpg/.codex/config.toml +0 -23
- package/templates/action-rpg/.cursor/mcp.json +0 -38
- package/templates/action-rpg/.gemini/settings.json +0 -38
- package/templates/action-rpg/.mcp.json +0 -38
- package/templates/action-rpg/.vscode/mcp.json +0 -43
- package/templates/action-rpg/.zed/settings.json +0 -43
- package/templates/action-rpg/opencode.json +0 -49
- package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
- package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
- package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
- package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
- package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
- package/templates/adventure/.codex/config.toml +0 -23
- package/templates/adventure/.cursor/mcp.json +0 -38
- package/templates/adventure/.gemini/settings.json +0 -38
- package/templates/adventure/.mcp.json +0 -38
- package/templates/adventure/.vscode/mcp.json +0 -43
- package/templates/adventure/.zed/settings.json +0 -43
- package/templates/adventure/opencode.json +0 -49
- package/templates/collectathon/.codex/config.toml +0 -23
- package/templates/collectathon/.cursor/mcp.json +0 -38
- package/templates/collectathon/.gemini/settings.json +0 -38
- package/templates/collectathon/.mcp.json +0 -38
- package/templates/collectathon/.vscode/mcp.json +0 -43
- package/templates/collectathon/.zed/settings.json +0 -43
- package/templates/collectathon/opencode.json +0 -49
- package/templates/kart/.codex/config.toml +0 -23
- package/templates/kart/.cursor/mcp.json +0 -38
- package/templates/kart/.gemini/settings.json +0 -38
- package/templates/kart/.mcp.json +0 -38
- package/templates/kart/.vscode/mcp.json +0 -43
- package/templates/kart/.zed/settings.json +0 -43
- package/templates/kart/opencode.json +0 -49
- package/templates/minimal/.codex/config.toml +0 -23
- package/templates/minimal/.cursor/mcp.json +0 -38
- package/templates/minimal/.gemini/settings.json +0 -38
- package/templates/minimal/.mcp.json +0 -38
- package/templates/minimal/.vscode/mcp.json +0 -43
- package/templates/minimal/.zed/settings.json +0 -43
- package/templates/minimal/opencode.json +0 -49
- package/templates/minimal/src/render/environmentContribution.ts +0 -188
- package/templates/minimal/src/render/environmentRadiance.ts +0 -36
- package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
- package/templates/minimal/src/render/environmentSampling.ts +0 -193
- package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
- package/templates/platformer/.codex/config.toml +0 -23
- package/templates/platformer/.cursor/mcp.json +0 -38
- package/templates/platformer/.gemini/settings.json +0 -38
- package/templates/platformer/.mcp.json +0 -38
- package/templates/platformer/.vscode/mcp.json +0 -43
- package/templates/platformer/.zed/settings.json +0 -43
- package/templates/platformer/opencode.json +0 -49
- package/templates/platformer/src/render/environmentContribution.ts +0 -188
- package/templates/platformer/src/render/environmentRadiance.ts +0 -36
- package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
- package/templates/platformer/src/render/environmentSampling.ts +0 -193
- package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
- package/templates/puzzle/.codex/config.toml +0 -23
- package/templates/puzzle/.cursor/mcp.json +0 -38
- package/templates/puzzle/.gemini/settings.json +0 -38
- package/templates/puzzle/.mcp.json +0 -38
- package/templates/puzzle/.vscode/mcp.json +0 -43
- package/templates/puzzle/.zed/settings.json +0 -43
- package/templates/puzzle/opencode.json +0 -49
- package/templates/puzzle/src/render/environmentContribution.ts +0 -188
- package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
- package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
- package/templates/puzzle/src/render/environmentSampling.ts +0 -193
- package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
- package/templates/racing/.codex/config.toml +0 -23
- package/templates/racing/.cursor/mcp.json +0 -38
- package/templates/racing/.gemini/settings.json +0 -38
- package/templates/racing/.mcp.json +0 -38
- package/templates/racing/.vscode/mcp.json +0 -43
- package/templates/racing/.zed/settings.json +0 -43
- package/templates/racing/opencode.json +0 -49
- package/templates/racing/src/render/environmentContribution.ts +0 -188
- package/templates/racing/src/render/environmentRadiance.ts +0 -36
- package/templates/racing/src/render/environmentSampleCache.ts +0 -43
- package/templates/racing/src/render/environmentSampling.ts +0 -193
- package/templates/racing/src/render/environmentSnapshot.ts +0 -53
- package/templates/rain/.codex/config.toml +0 -23
- package/templates/rain/.cursor/mcp.json +0 -38
- package/templates/rain/.gemini/settings.json +0 -38
- package/templates/rain/.mcp.json +0 -38
- package/templates/rain/.vscode/mcp.json +0 -43
- package/templates/rain/.zed/settings.json +0 -43
- package/templates/rain/opencode.json +0 -49
- package/templates/rts/.codex/config.toml +0 -23
- package/templates/rts/.cursor/mcp.json +0 -38
- package/templates/rts/.gemini/settings.json +0 -38
- package/templates/rts/.mcp.json +0 -38
- package/templates/rts/.vscode/mcp.json +0 -43
- package/templates/rts/.zed/settings.json +0 -43
- package/templates/rts/opencode.json +0 -49
- package/templates/rts/src/render/environmentContribution.ts +0 -188
- package/templates/rts/src/render/environmentRadiance.ts +0 -36
- package/templates/rts/src/render/environmentSampleCache.ts +0 -43
- package/templates/rts/src/render/environmentSampling.ts +0 -193
- package/templates/rts/src/render/environmentSnapshot.ts +0 -53
- package/templates/runner/.codex/config.toml +0 -23
- package/templates/runner/.cursor/mcp.json +0 -38
- package/templates/runner/.gemini/settings.json +0 -38
- package/templates/runner/.mcp.json +0 -38
- package/templates/runner/.vscode/mcp.json +0 -43
- package/templates/runner/.zed/settings.json +0 -43
- package/templates/runner/README.md +0 -43
- package/templates/runner/opencode.json +0 -49
- package/templates/runner/src/render/environmentContribution.ts +0 -188
- package/templates/runner/src/render/environmentRadiance.ts +0 -36
- package/templates/runner/src/render/environmentSampleCache.ts +0 -43
- package/templates/runner/src/render/environmentSampling.ts +0 -193
- package/templates/runner/src/render/environmentSnapshot.ts +0 -53
- package/templates/sailing/.codex/config.toml +0 -23
- package/templates/sailing/.cursor/mcp.json +0 -38
- package/templates/sailing/.gemini/settings.json +0 -38
- package/templates/sailing/.mcp.json +0 -38
- package/templates/sailing/.vscode/mcp.json +0 -43
- package/templates/sailing/.zed/settings.json +0 -43
- package/templates/sailing/README.md +0 -28
- package/templates/sailing/opencode.json +0 -49
- package/templates/sailing/src/render/environmentContribution.ts +0 -188
- package/templates/sailing/src/render/environmentRadiance.ts +0 -36
- package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
- package/templates/sailing/src/render/environmentSampling.ts +0 -193
- package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
- package/templates/shooter/.codex/config.toml +0 -23
- package/templates/shooter/.cursor/mcp.json +0 -38
- package/templates/shooter/.gemini/settings.json +0 -38
- package/templates/shooter/.mcp.json +0 -38
- package/templates/shooter/.vscode/mcp.json +0 -43
- package/templates/shooter/.zed/settings.json +0 -43
- package/templates/shooter/opencode.json +0 -49
- package/templates/shooter/src/render/environmentContribution.ts +0 -188
- package/templates/shooter/src/render/environmentRadiance.ts +0 -36
- package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
- package/templates/shooter/src/render/environmentSampling.ts +0 -193
- package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
- package/templates/snow/.codex/config.toml +0 -23
- package/templates/snow/.cursor/mcp.json +0 -38
- package/templates/snow/.gemini/settings.json +0 -38
- package/templates/snow/.mcp.json +0 -38
- package/templates/snow/.vscode/mcp.json +0 -43
- package/templates/snow/.zed/settings.json +0 -43
- package/templates/snow/README.md +0 -26
- package/templates/snow/opencode.json +0 -49
- package/templates/snow/src/render/environmentContribution.ts +0 -188
- package/templates/snow/src/render/environmentRadiance.ts +0 -36
- package/templates/snow/src/render/environmentSampleCache.ts +0 -43
- package/templates/snow/src/render/environmentSampling.ts +0 -193
- package/templates/snow/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/.codex/config.toml +0 -23
- package/templates/starter/.cursor/mcp.json +0 -38
- package/templates/starter/.gemini/settings.json +0 -38
- package/templates/starter/.mcp.json +0 -38
- package/templates/starter/.vscode/mcp.json +0 -43
- package/templates/starter/.zed/settings.json +0 -43
- package/templates/starter/opencode.json +0 -49
- package/templates/starter/src/render/environmentContribution.ts +0 -188
- package/templates/starter/src/render/environmentRadiance.ts +0 -36
- package/templates/starter/src/render/environmentSampleCache.ts +0 -43
- package/templates/starter/src/render/environmentSampling.ts +0 -193
- package/templates/starter/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/rendererGate.ts +0 -36
- package/templates/tower-defense/.codex/config.toml +0 -23
- package/templates/tower-defense/.cursor/mcp.json +0 -38
- package/templates/tower-defense/.gemini/settings.json +0 -38
- package/templates/tower-defense/.mcp.json +0 -38
- package/templates/tower-defense/.vscode/mcp.json +0 -43
- package/templates/tower-defense/.zed/settings.json +0 -43
- package/templates/tower-defense/README.md +0 -16
- package/templates/tower-defense/opencode.json +0 -49
- package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
- package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
- package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
- package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
- package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
|
@@ -130,15 +130,36 @@ export function buildTerrain(plan: ITerrainPlan): ITerrain {
|
|
|
130
130
|
const inside = (x: number, z: number): boolean =>
|
|
131
131
|
x >= minX && x <= maxX && z >= minZ && z <= maxZ;
|
|
132
132
|
const seaFloor = plan.seaLevel - 6.5;
|
|
133
|
+
// Each path segment with its bounding box, in path order: a segment whose box lies clearly
|
|
134
|
+
// farther than the nearest so far cannot be nearer, so its exact distance is never needed.
|
|
135
|
+
const segments = plan.paths.flatMap((path) =>
|
|
136
|
+
path.slice(1).map((b, i) => {
|
|
137
|
+
const a = path[i] as readonly [number, number];
|
|
138
|
+
return {
|
|
139
|
+
a,
|
|
140
|
+
b,
|
|
141
|
+
minX: Math.min(a[0], b[0]),
|
|
142
|
+
maxX: Math.max(a[0], b[0]),
|
|
143
|
+
minZ: Math.min(a[1], b[1]),
|
|
144
|
+
maxZ: Math.max(a[1], b[1]),
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
133
148
|
return {
|
|
134
149
|
field,
|
|
135
150
|
flatness: (x, z) => (inside(x, z) ? field.normalAt(x, z).y : 1),
|
|
136
151
|
ground: (x, z) => (inside(x, z) ? field.heightAt(x, z) : seaFloor),
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
152
|
+
// Planting asks this thousands of times a load. Same segments, same order, same minimum: a box
|
|
153
|
+
// skipped is more than a millionth farther than the nearest, past any rounding of its distance.
|
|
154
|
+
pathDistance: (x, z) => {
|
|
155
|
+
let nearest = Number.POSITIVE_INFINITY;
|
|
156
|
+
for (const segment of segments) {
|
|
157
|
+
const dx = Math.max(segment.minX - x, 0, x - segment.maxX);
|
|
158
|
+
const dz = Math.max(segment.minZ - z, 0, z - segment.maxZ);
|
|
159
|
+
if (dx * dx + dz * dz > nearest * nearest * 1.000001) continue;
|
|
160
|
+
nearest = Math.min(nearest, segmentDistance(x, z, segment.a, segment.b));
|
|
161
|
+
}
|
|
162
|
+
return nearest;
|
|
163
|
+
},
|
|
143
164
|
};
|
|
144
165
|
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
CylinderGeometry,
|
|
18
18
|
DataTexture,
|
|
19
19
|
DoubleSide,
|
|
20
|
+
Euler,
|
|
20
21
|
Group,
|
|
21
22
|
InstancedMesh,
|
|
22
23
|
LatheGeometry,
|
|
@@ -24,7 +25,6 @@ import {
|
|
|
24
25
|
type Material,
|
|
25
26
|
Matrix4,
|
|
26
27
|
Mesh,
|
|
27
|
-
Object3D,
|
|
28
28
|
OctahedronGeometry,
|
|
29
29
|
PlaneGeometry,
|
|
30
30
|
Quaternion,
|
|
@@ -83,28 +83,49 @@ export interface IPlantingSite {
|
|
|
83
83
|
readonly surfaces: ISurfaces;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
// Plain math, not a scratch Object3D: an engine object's position, scale, rotation and matrix each
|
|
87
|
+
// cross into the engine, five crossings an instance (~90 ms of a load); these stay in JavaScript.
|
|
87
88
|
// Yaw last: a placement leans or droops about X, then turns to face its way round Y.
|
|
88
|
-
|
|
89
|
+
const turn = new Euler(0, 0, 0, "YXZ");
|
|
90
|
+
const placed = {
|
|
91
|
+
at: new Vector3(),
|
|
92
|
+
matrix: new Matrix4(),
|
|
93
|
+
size: new Vector3(),
|
|
94
|
+
spin: new Quaternion(),
|
|
95
|
+
tint: new Color(),
|
|
96
|
+
};
|
|
89
97
|
|
|
98
|
+
/**
|
|
99
|
+
* A kind as one draw, from the flat placements the plan stores: nine floats each, and three a tint.
|
|
100
|
+
* Flat on purpose: a repeat run reads 35,000 placements out of the cache and floats straight into
|
|
101
|
+
* the instance array, where a tuple apiece would cost more than drawing the island again.
|
|
102
|
+
*/
|
|
90
103
|
function instanced(
|
|
91
104
|
geometry: BufferGeometry,
|
|
92
105
|
material: Material,
|
|
93
|
-
placements:
|
|
106
|
+
placements: Float64Array,
|
|
94
107
|
castShadow: boolean,
|
|
95
|
-
tints?:
|
|
108
|
+
tints?: Float64Array,
|
|
96
109
|
): InstancedMesh {
|
|
97
|
-
const
|
|
98
|
-
mesh
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
const count = Math.floor(placements.length / PLACEMENT_STRIDE);
|
|
111
|
+
const mesh = new InstancedMesh(geometry, material, Math.max(1, count));
|
|
112
|
+
mesh.count = count;
|
|
113
|
+
for (let i = 0; i < count; i += 1) {
|
|
114
|
+
const at = i * PLACEMENT_STRIDE;
|
|
115
|
+
placed.spin.setFromEuler(
|
|
116
|
+
turn.set(placements[at + 6] ?? 0, placements[at + 7] ?? 0, placements[at + 8] ?? 0, "YXZ"),
|
|
117
|
+
);
|
|
118
|
+
placed.matrix.compose(
|
|
119
|
+
placed.at.set(placements[at] ?? 0, placements[at + 1] ?? 0, placements[at + 2] ?? 0),
|
|
120
|
+
placed.spin,
|
|
121
|
+
placed.size.set(placements[at + 3] ?? 0, placements[at + 4] ?? 0, placements[at + 5] ?? 0),
|
|
122
|
+
);
|
|
123
|
+
mesh.setMatrixAt(i, placed.matrix);
|
|
124
|
+
if (tints === undefined) continue;
|
|
125
|
+
const tint = i * TINT_STRIDE;
|
|
126
|
+
placed.tint.setRGB(tints[tint] ?? 0, tints[tint + 1] ?? 0, tints[tint + 2] ?? 0);
|
|
127
|
+
mesh.setColorAt(i, placed.tint);
|
|
128
|
+
}
|
|
108
129
|
mesh.computeBoundingSphere();
|
|
109
130
|
mesh.castShadow = castShadow;
|
|
110
131
|
mesh.receiveShadow = true;
|
|
@@ -349,7 +370,7 @@ function branchMatrix(from: Vector3, to: Vector3, radius: number): Matrix4 {
|
|
|
349
370
|
}
|
|
350
371
|
|
|
351
372
|
/** Two wings hinged on the body's line, flapping on their own phase while the insect wanders. */
|
|
352
|
-
function butterflies(placements:
|
|
373
|
+
function butterflies(placements: Float64Array, tints: Float64Array): InstancedMesh {
|
|
353
374
|
const geometry = new BufferGeometry();
|
|
354
375
|
geometry.setAttribute(
|
|
355
376
|
"position",
|
|
@@ -414,10 +435,67 @@ export interface IMeadow {
|
|
|
414
435
|
readonly total: number;
|
|
415
436
|
}
|
|
416
437
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
438
|
+
/** Floats a placement, a matrix and a tint occupy: the strides the record and the meshes share. */
|
|
439
|
+
const PLACEMENT_STRIDE = 9;
|
|
440
|
+
const MATRIX_STRIDE = 16;
|
|
441
|
+
const TINT_STRIDE = 3;
|
|
442
|
+
|
|
443
|
+
/** One 12 m meadow cell: its centre and the tufts it draws, in draw order after the shuffle. */
|
|
444
|
+
export interface IPlantingCell {
|
|
445
|
+
/** Nine floats a tuft, and one tint a tuft, in the same order. */
|
|
446
|
+
readonly placements: Float64Array;
|
|
447
|
+
readonly tints: Float64Array;
|
|
448
|
+
readonly x: number;
|
|
449
|
+
readonly z: number;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Everything one run generates to plant the island, as the flat arrays `ctx.assets.memo` keeps:
|
|
454
|
+
* nine floats a placement, sixteen a matrix, three a tint, and the meadow's cells packed end to
|
|
455
|
+
* end. Flat because a repeat run reads some 35,000 placements back and hands them straight to the
|
|
456
|
+
* instance arrays, and a tuple apiece would cost more to rebuild than drawing the island again.
|
|
457
|
+
*/
|
|
458
|
+
export interface IPlantingRecord {
|
|
459
|
+
readonly birches: Float64Array;
|
|
460
|
+
readonly branches: Float64Array;
|
|
461
|
+
readonly cards: Float64Array;
|
|
462
|
+
/** The cell centres, two floats each, and the cells' placements and tints packed in cell order. */
|
|
463
|
+
readonly cellStarts: Float64Array;
|
|
464
|
+
readonly cellTints: Float64Array;
|
|
465
|
+
readonly cellValues: Float64Array;
|
|
466
|
+
readonly cellXZ: Float64Array;
|
|
467
|
+
readonly flyers: Float64Array;
|
|
468
|
+
/** The flower heads packed end to end, and where each colour's list starts, in placements. */
|
|
469
|
+
readonly headStarts: Float64Array;
|
|
470
|
+
readonly heads: Float64Array;
|
|
471
|
+
readonly pebbleTints: Float64Array;
|
|
472
|
+
readonly pebbles: Float64Array;
|
|
473
|
+
readonly stems: Float64Array;
|
|
474
|
+
readonly stoneTints: Float64Array;
|
|
475
|
+
readonly stones: Float64Array;
|
|
476
|
+
readonly tints: Float64Array;
|
|
477
|
+
readonly trunks: Float64Array;
|
|
478
|
+
/** The draws the meadow's blades made, in order, so a repeat run cuts the same blades. */
|
|
479
|
+
readonly tuftDraws: Float64Array;
|
|
480
|
+
readonly wingTints: Float64Array;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const PETALS = [C.petalRed, C.petalOrange, C.petalWhite, C.petalYellow, C.wingBlue] as const;
|
|
484
|
+
|
|
485
|
+
/** A draw source handing back `draws` in order: the meadow's blades, cut again from stored draws. */
|
|
486
|
+
function replayed(draws: Float64Array): () => number {
|
|
487
|
+
let at = 0;
|
|
488
|
+
return () => {
|
|
489
|
+
const value = draws[at];
|
|
490
|
+
if (value === undefined) throw new Error("the stored planting ran out of draws.");
|
|
491
|
+
at += 1;
|
|
492
|
+
return value;
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** The island's placements, drawn from `site.rng` in one fixed order. */
|
|
497
|
+
export function planPlanting(site: IPlantingSite): IPlantingRecord {
|
|
498
|
+
const { rng, bounds, clear, ground } = site;
|
|
421
499
|
const spin = () => rng() * Math.PI * 2;
|
|
422
500
|
const onLawn = (x: number, z: number) =>
|
|
423
501
|
site.lawns.some(([lx, lz, r]) => Math.hypot(x - lx, z - lz) < r + 0.4);
|
|
@@ -458,8 +536,6 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
458
536
|
for (const clump of clumps.slice(1))
|
|
459
537
|
branches.push(branchMatrix(fork, fork.clone().lerp(clump, 0.85), 0.09 * size));
|
|
460
538
|
}
|
|
461
|
-
const bark = texturedMaterial(surfaces, "bark", { normalScale: 1.6, roughness: 0.92 });
|
|
462
|
-
group.add(instanced(trunkGeometry(2, 0.12), bark, trunks, true));
|
|
463
539
|
|
|
464
540
|
// Birches: tall white trunks with a light, narrow crown of smaller cards up their top half.
|
|
465
541
|
const birches: Placement[] = [];
|
|
@@ -481,14 +557,6 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
481
557
|
for (const clump of clumps.slice(1))
|
|
482
558
|
branches.push(branchMatrix(fork, fork.clone().lerp(clump, 0.8), 0.045));
|
|
483
559
|
}
|
|
484
|
-
group.add(
|
|
485
|
-
instanced(
|
|
486
|
-
trunkGeometry(14, 0.05),
|
|
487
|
-
texturedMaterial(surfaces, "birch-bark", { roughness: 0.7 }),
|
|
488
|
-
birches,
|
|
489
|
-
true,
|
|
490
|
-
),
|
|
491
|
-
);
|
|
492
560
|
|
|
493
561
|
// Bushes: low clumps of the same leaves, and two hedge arcs of them near the rim.
|
|
494
562
|
const bush = (x: number, z: number, size: number): void => {
|
|
@@ -515,53 +583,14 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
515
583
|
}
|
|
516
584
|
}
|
|
517
585
|
|
|
518
|
-
// Every leaf card on the island is one draw: cut out of the cluster texture, both faces lit, the
|
|
519
|
-
// sun shining through the ones seen against it, and a slow flutter on each card's own phase.
|
|
520
|
-
const leafMaterial = new MeshStandardNodeMaterial({
|
|
521
|
-
alphaTest: 0.4,
|
|
522
|
-
map: leafTexture(),
|
|
523
|
-
roughness: 0.7,
|
|
524
|
-
side: DoubleSide,
|
|
525
|
-
});
|
|
526
|
-
const flutter = hash(instanceIndex).mul(6.28);
|
|
527
|
-
leafMaterial.positionNode = positionLocal.add(
|
|
528
|
-
vec3(
|
|
529
|
-
sin(time.mul(1.9).add(flutter)).mul(0.03),
|
|
530
|
-
sin(time.mul(2.6).add(flutter.mul(1.3))).mul(0.02),
|
|
531
|
-
0,
|
|
532
|
-
),
|
|
533
|
-
);
|
|
534
|
-
leafMaterial.twoSidedFoliage = true;
|
|
535
|
-
leafMaterial.subsurfaceColor = new Color(0.3, 0.46, 0.1);
|
|
536
|
-
const cards = new InstancedMesh(cardGeometry(), leafMaterial, leaves.cards.length);
|
|
537
|
-
leaves.cards.forEach((matrix, i) => {
|
|
538
|
-
cards.setMatrixAt(i, matrix);
|
|
539
|
-
cards.setColorAt(i, leaves.tints[i] as Color);
|
|
540
|
-
});
|
|
541
|
-
cards.computeBoundingSphere();
|
|
542
|
-
cards.castShadow = true;
|
|
543
|
-
cards.receiveShadow = true;
|
|
544
|
-
cards.name = "leaves";
|
|
545
|
-
group.add(cards);
|
|
546
|
-
const boughs = new InstancedMesh(
|
|
547
|
-
new CylinderGeometry(0.55, 1, 1, 6, 1, true).translate(0, 0.5, 0),
|
|
548
|
-
bark,
|
|
549
|
-
branches.length,
|
|
550
|
-
);
|
|
551
|
-
branches.forEach((matrix, i) => boughs.setMatrixAt(i, matrix));
|
|
552
|
-
boughs.computeBoundingSphere();
|
|
553
|
-
boughs.castShadow = true;
|
|
554
|
-
group.add(boughs);
|
|
555
|
-
|
|
556
586
|
// Flowers: clumps in the grass, thickest along the path's edges, one draw per colour, on stems
|
|
557
587
|
// that sway with it.
|
|
558
|
-
const
|
|
559
|
-
const heads: Placement[][] = petals.map(() => []);
|
|
588
|
+
const heads: Placement[][] = PETALS.map(() => []);
|
|
560
589
|
const stems: Placement[] = [];
|
|
561
590
|
for (let i = 0; i < 260; i += 1) {
|
|
562
591
|
const at = i % 3 === 0 ? spot(0.6, 1.6) : spot(0.6, 1.4);
|
|
563
592
|
if (at === undefined) continue;
|
|
564
|
-
const hue = heads[i %
|
|
593
|
+
const hue = heads[i % PETALS.length] ?? [];
|
|
565
594
|
const count = 6 + Math.floor(rng() * 9);
|
|
566
595
|
for (let f = 0; f < count; f += 1) {
|
|
567
596
|
const a = spin();
|
|
@@ -575,14 +604,6 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
575
604
|
hue.push([x, y + h, z, s, s, s, (rng() - 0.5) * 0.6, spin(), (rng() - 0.5) * 0.6]);
|
|
576
605
|
}
|
|
577
606
|
}
|
|
578
|
-
const stem = new CylinderGeometry(0.01, 0.012, 1, 3, 1, true).translate(0, 0.5, 0);
|
|
579
|
-
group.add(instanced(stem, lit(C.blade), stems, false));
|
|
580
|
-
const head = flowerGeometry();
|
|
581
|
-
petals.forEach((colour, i) => {
|
|
582
|
-
group.add(
|
|
583
|
-
instanced(head, lit(colour, { roughness: 0.6, vertexColors: true }), heads[i] ?? [], false),
|
|
584
|
-
);
|
|
585
|
-
});
|
|
586
607
|
|
|
587
608
|
// Butterflies over the flowers: orange, white and blue.
|
|
588
609
|
const flyers: Placement[] = [];
|
|
@@ -594,7 +615,6 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
594
615
|
flyers.push([at[0], ground(at[0], at[1]) + 0.7 + rng() * 0.6, at[1], 1, 1, 1, 0, spin(), 0]);
|
|
595
616
|
wingTints.push(new Color(wings[i % wings.length]));
|
|
596
617
|
}
|
|
597
|
-
group.add(butterflies(flyers, wingTints));
|
|
598
618
|
|
|
599
619
|
// Pebbles thick along the path, and a few stones in the grass, half sunk into the ground.
|
|
600
620
|
const pebbles: Placement[] = [];
|
|
@@ -624,22 +644,20 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
624
644
|
(onPath ? pebbles : stones).push(at);
|
|
625
645
|
(onPath ? pebbleTints : stoneTints).push(pebbleBase.clone().multiplyScalar(0.45 + rng() * 0.7));
|
|
626
646
|
}
|
|
627
|
-
const pebble = new OctahedronGeometry(1, 0);
|
|
628
|
-
const pebbleMaterial = lit(0xffffff, { flat: true });
|
|
629
|
-
// Too small to throw a shadow worth its draw.
|
|
630
|
-
const pathPebbles = instanced(pebble, pebbleMaterial, pebbles, false, pebbleTints);
|
|
631
|
-
pathPebbles.name = "path-pebbles";
|
|
632
|
-
const grassStones = instanced(pebble, pebbleMaterial, stones, true, stoneTints);
|
|
633
|
-
grassStones.name = "stones";
|
|
634
|
-
group.add(pathPebbles, grassStones);
|
|
635
647
|
|
|
636
648
|
// The meadow: grass tufts on a jittered 0.5 m grid over all the land and every drum's lawn, shorter
|
|
637
649
|
// on the mown routes and beside the path, one `InstancedMesh` per 12 m cell. Each cell is
|
|
638
650
|
// shuffled, so drawing a prefix of it thins it evenly: `update` draws every tuft within 10 m of
|
|
639
651
|
// the eye at every tier (the foreground is what hides the ground), then the tier's share, thinning
|
|
640
652
|
// to an eighth of it by 46 m, where the ground's own grass texture carries the field.
|
|
641
|
-
|
|
642
|
-
|
|
653
|
+
// The blades draw seven numbers each from this point in the stream; keep them, so a repeat run
|
|
654
|
+
// cuts the same blades without needing the stream at all.
|
|
655
|
+
const tuftDraws: number[] = [];
|
|
656
|
+
tuftGeometry(() => {
|
|
657
|
+
const draw = rng();
|
|
658
|
+
tuftDraws.push(draw);
|
|
659
|
+
return draw;
|
|
660
|
+
});
|
|
643
661
|
const cells = new Map<
|
|
644
662
|
string,
|
|
645
663
|
{ placements: Placement[]; tints: Color[]; x: number; z: number }
|
|
@@ -688,23 +706,261 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
688
706
|
}
|
|
689
707
|
}
|
|
690
708
|
}
|
|
691
|
-
const
|
|
692
|
-
[];
|
|
709
|
+
const planted: { placements: Placement[]; tints: Color[]; x: number; z: number }[] = [];
|
|
693
710
|
for (const { placements, tints, x, z } of cells.values()) {
|
|
694
711
|
for (let i = placements.length - 1; i > 0; i -= 1) {
|
|
695
712
|
const j = Math.floor(rng() * (i + 1));
|
|
696
713
|
[placements[i], placements[j]] = [placements[j] as Placement, placements[i] as Placement];
|
|
697
714
|
[tints[i], tints[j]] = [tints[j] as Color, tints[i] as Color];
|
|
698
715
|
}
|
|
699
|
-
|
|
716
|
+
planted.push({ placements, tints, x, z });
|
|
717
|
+
}
|
|
718
|
+
const headStarts = new Float64Array(heads.length + 1);
|
|
719
|
+
let headCount = 0;
|
|
720
|
+
heads.forEach((list, i) => {
|
|
721
|
+
headStarts[i] = headCount;
|
|
722
|
+
headCount += list.length;
|
|
723
|
+
});
|
|
724
|
+
headStarts[heads.length] = headCount;
|
|
725
|
+
const headValues = new Float64Array(headCount * PLACEMENT_STRIDE);
|
|
726
|
+
let headAt = 0;
|
|
727
|
+
for (const list of heads)
|
|
728
|
+
for (const item of list) {
|
|
729
|
+
headValues.set(item, headAt);
|
|
730
|
+
headAt += PLACEMENT_STRIDE;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
const cellStarts = new Float64Array(planted.length + 1);
|
|
734
|
+
const cellXZ = new Float64Array(planted.length * 2);
|
|
735
|
+
let cellCount = 0;
|
|
736
|
+
planted.forEach((cell, i) => {
|
|
737
|
+
cellStarts[i] = cellCount;
|
|
738
|
+
cellXZ[i * 2] = cell.x;
|
|
739
|
+
cellXZ[i * 2 + 1] = cell.z;
|
|
740
|
+
cellCount += cell.placements.length;
|
|
741
|
+
});
|
|
742
|
+
cellStarts[planted.length] = cellCount;
|
|
743
|
+
// One tint a tuft, in the same order, so a cell's tints start where its placements do.
|
|
744
|
+
const cellValues = new Float64Array(cellCount * PLACEMENT_STRIDE);
|
|
745
|
+
const cellTints = new Float64Array(cellCount * TINT_STRIDE);
|
|
746
|
+
let cellAt = 0;
|
|
747
|
+
let tintAt = 0;
|
|
748
|
+
for (const cell of planted) {
|
|
749
|
+
for (const item of cell.placements) {
|
|
750
|
+
cellValues.set(item, cellAt);
|
|
751
|
+
cellAt += PLACEMENT_STRIDE;
|
|
752
|
+
}
|
|
753
|
+
for (const tint of cell.tints) {
|
|
754
|
+
cellTints[tintAt] = tint.r;
|
|
755
|
+
cellTints[tintAt + 1] = tint.g;
|
|
756
|
+
cellTints[tintAt + 2] = tint.b;
|
|
757
|
+
tintAt += TINT_STRIDE;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
return {
|
|
762
|
+
birches: packedPlacements(birches),
|
|
763
|
+
branches: packedMatrices(branches),
|
|
764
|
+
cards: packedMatrices(leaves.cards),
|
|
765
|
+
cellStarts,
|
|
766
|
+
cellTints,
|
|
767
|
+
cellValues,
|
|
768
|
+
cellXZ,
|
|
769
|
+
flyers: packedPlacements(flyers),
|
|
770
|
+
headStarts,
|
|
771
|
+
heads: headValues,
|
|
772
|
+
pebbleTints: packedTints(pebbleTints),
|
|
773
|
+
pebbles: packedPlacements(pebbles),
|
|
774
|
+
stems: packedPlacements(stems),
|
|
775
|
+
stoneTints: packedTints(stoneTints),
|
|
776
|
+
stones: packedPlacements(stones),
|
|
777
|
+
tints: packedTints(leaves.tints),
|
|
778
|
+
trunks: packedPlacements(trunks),
|
|
779
|
+
tuftDraws: Float64Array.from(tuftDraws),
|
|
780
|
+
wingTints: packedTints(wingTints),
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function packedPlacements(items: readonly Placement[]): Float64Array {
|
|
785
|
+
const flat = new Float64Array(items.length * PLACEMENT_STRIDE);
|
|
786
|
+
items.forEach((item, i) => flat.set(item, i * PLACEMENT_STRIDE));
|
|
787
|
+
return flat;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
function packedMatrices(items: readonly Matrix4[]): Float64Array {
|
|
791
|
+
const flat = new Float64Array(items.length * MATRIX_STRIDE);
|
|
792
|
+
items.forEach((item, i) => flat.set(item.elements, i * MATRIX_STRIDE));
|
|
793
|
+
return flat;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function packedTints(items: readonly Color[]): Float64Array {
|
|
797
|
+
const flat = new Float64Array(items.length * TINT_STRIDE);
|
|
798
|
+
items.forEach((tint, i) => {
|
|
799
|
+
flat[i * TINT_STRIDE] = tint.r;
|
|
800
|
+
flat[i * TINT_STRIDE + 1] = tint.g;
|
|
801
|
+
flat[i * TINT_STRIDE + 2] = tint.b;
|
|
802
|
+
});
|
|
803
|
+
return flat;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/** `placed.matrix` filled from a stored 16-float matrix, so a card costs no Matrix4 of its own. */
|
|
807
|
+
function matrixAt(flat: Float64Array, index: number): Matrix4 {
|
|
808
|
+
const elements = placed.matrix.elements;
|
|
809
|
+
for (let k = 0; k < MATRIX_STRIDE; k += 1) elements[k] = flat[index * MATRIX_STRIDE + k] ?? 0;
|
|
810
|
+
return placed.matrix;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** `placed.tint` filled from a stored 3-float tint, for the same reason. */
|
|
814
|
+
function tintAt(flat: Float64Array, index: number): Color {
|
|
815
|
+
const at = index * TINT_STRIDE;
|
|
816
|
+
return placed.tint.setRGB(flat[at] ?? 0, flat[at + 1] ?? 0, flat[at + 2] ?? 0);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* A stored record before it becomes meshes: the memo is bytes off a disk, so a length that does not
|
|
821
|
+
* match throws instead of drawing half an island.
|
|
822
|
+
*/
|
|
823
|
+
export function checkedPlanting(record: IPlantingRecord): IPlantingRecord {
|
|
824
|
+
const placementAlike = [
|
|
825
|
+
record.birches,
|
|
826
|
+
record.flyers,
|
|
827
|
+
record.pebbles,
|
|
828
|
+
record.stems,
|
|
829
|
+
record.stones,
|
|
830
|
+
record.trunks,
|
|
831
|
+
];
|
|
832
|
+
const tintAlike = [record.pebbleTints, record.stoneTints, record.tints, record.wingTints];
|
|
833
|
+
const broken =
|
|
834
|
+
placementAlike.some((flat) => flat.length % PLACEMENT_STRIDE !== 0) ||
|
|
835
|
+
tintAlike.some((flat) => flat.length % TINT_STRIDE !== 0) ||
|
|
836
|
+
record.cards.length % MATRIX_STRIDE !== 0 ||
|
|
837
|
+
record.branches.length % MATRIX_STRIDE !== 0 ||
|
|
838
|
+
record.tints.length !== (record.cards.length / MATRIX_STRIDE) * TINT_STRIDE ||
|
|
839
|
+
record.headStarts.length !== PETALS.length + 1 ||
|
|
840
|
+
(record.headStarts[PETALS.length] ?? 0) * PLACEMENT_STRIDE !== record.heads.length ||
|
|
841
|
+
record.cellStarts.length !== record.cellXZ.length / 2 + 1 ||
|
|
842
|
+
(record.cellStarts[record.cellStarts.length - 1] ?? 0) * PLACEMENT_STRIDE !==
|
|
843
|
+
record.cellValues.length ||
|
|
844
|
+
record.cellTints.length !== (record.cellValues.length / PLACEMENT_STRIDE) * TINT_STRIDE ||
|
|
845
|
+
record.tuftDraws.length === 0;
|
|
846
|
+
if (broken) throw new Error("stored planting is malformed.");
|
|
847
|
+
return record;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** The island's meshes, from a record. `site` carries the textures and the tier's grass share. */
|
|
851
|
+
export function buildPlanting(
|
|
852
|
+
record: IPlantingRecord,
|
|
853
|
+
site: IPlantingSite,
|
|
854
|
+
): { group: Group; meadow: IMeadow } {
|
|
855
|
+
const { surfaces } = site;
|
|
856
|
+
const group = new Group();
|
|
857
|
+
group.name = "planting";
|
|
858
|
+
|
|
859
|
+
const bark = texturedMaterial(surfaces, "bark", { normalScale: 1.6, roughness: 0.92 });
|
|
860
|
+
group.add(instanced(trunkGeometry(2, 0.12), bark, record.trunks, true));
|
|
861
|
+
group.add(
|
|
862
|
+
instanced(
|
|
863
|
+
trunkGeometry(14, 0.05),
|
|
864
|
+
texturedMaterial(surfaces, "birch-bark", { roughness: 0.7 }),
|
|
865
|
+
record.birches,
|
|
866
|
+
true,
|
|
867
|
+
),
|
|
868
|
+
);
|
|
869
|
+
|
|
870
|
+
// Every leaf card on the island is one draw: cut out of the cluster texture, both faces lit, the
|
|
871
|
+
// sun shining through the ones seen against it, and a slow flutter on each card's own phase.
|
|
872
|
+
const leafMaterial = new MeshStandardNodeMaterial({
|
|
873
|
+
alphaTest: 0.4,
|
|
874
|
+
map: leafTexture(),
|
|
875
|
+
roughness: 0.7,
|
|
876
|
+
side: DoubleSide,
|
|
877
|
+
});
|
|
878
|
+
const flutter = hash(instanceIndex).mul(6.28);
|
|
879
|
+
leafMaterial.positionNode = positionLocal.add(
|
|
880
|
+
vec3(
|
|
881
|
+
sin(time.mul(1.9).add(flutter)).mul(0.03),
|
|
882
|
+
sin(time.mul(2.6).add(flutter.mul(1.3))).mul(0.02),
|
|
883
|
+
0,
|
|
884
|
+
),
|
|
885
|
+
);
|
|
886
|
+
leafMaterial.twoSidedFoliage = true;
|
|
887
|
+
leafMaterial.subsurfaceColor = new Color(0.3, 0.46, 0.1);
|
|
888
|
+
const cardCount = Math.floor(record.cards.length / MATRIX_STRIDE);
|
|
889
|
+
const cards = new InstancedMesh(cardGeometry(), leafMaterial, Math.max(1, cardCount));
|
|
890
|
+
cards.count = cardCount;
|
|
891
|
+
for (let i = 0; i < cardCount; i += 1) {
|
|
892
|
+
cards.setMatrixAt(i, matrixAt(record.cards, i));
|
|
893
|
+
cards.setColorAt(i, tintAt(record.tints, i));
|
|
894
|
+
}
|
|
895
|
+
cards.computeBoundingSphere();
|
|
896
|
+
cards.castShadow = true;
|
|
897
|
+
cards.receiveShadow = true;
|
|
898
|
+
cards.name = "leaves";
|
|
899
|
+
group.add(cards);
|
|
900
|
+
const boughCount = Math.floor(record.branches.length / MATRIX_STRIDE);
|
|
901
|
+
const boughs = new InstancedMesh(
|
|
902
|
+
new CylinderGeometry(0.55, 1, 1, 6, 1, true).translate(0, 0.5, 0),
|
|
903
|
+
bark,
|
|
904
|
+
Math.max(1, boughCount),
|
|
905
|
+
);
|
|
906
|
+
boughs.count = boughCount;
|
|
907
|
+
for (let i = 0; i < boughCount; i += 1) boughs.setMatrixAt(i, matrixAt(record.branches, i));
|
|
908
|
+
boughs.computeBoundingSphere();
|
|
909
|
+
boughs.castShadow = true;
|
|
910
|
+
group.add(boughs);
|
|
911
|
+
|
|
912
|
+
// Flowers: one draw per colour, on stems that sway with the grass.
|
|
913
|
+
const stem = new CylinderGeometry(0.01, 0.012, 1, 3, 1, true).translate(0, 0.5, 0);
|
|
914
|
+
group.add(instanced(stem, lit(C.blade), record.stems, false));
|
|
915
|
+
const head = flowerGeometry();
|
|
916
|
+
PETALS.forEach((colour, i) => {
|
|
917
|
+
const from = (record.headStarts[i] ?? 0) * PLACEMENT_STRIDE;
|
|
918
|
+
const to = (record.headStarts[i + 1] ?? 0) * PLACEMENT_STRIDE;
|
|
919
|
+
group.add(
|
|
920
|
+
instanced(
|
|
921
|
+
head,
|
|
922
|
+
lit(colour, { roughness: 0.6, vertexColors: true }),
|
|
923
|
+
record.heads.subarray(from, to),
|
|
924
|
+
false,
|
|
925
|
+
),
|
|
926
|
+
);
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
group.add(butterflies(record.flyers, record.wingTints));
|
|
930
|
+
|
|
931
|
+
const pebble = new OctahedronGeometry(1, 0);
|
|
932
|
+
const pebbleMaterial = lit(0xffffff, { flat: true });
|
|
933
|
+
// Too small to throw a shadow worth its draw.
|
|
934
|
+
const pathPebbles = instanced(pebble, pebbleMaterial, record.pebbles, false, record.pebbleTints);
|
|
935
|
+
pathPebbles.name = "path-pebbles";
|
|
936
|
+
const grassStones = instanced(pebble, pebbleMaterial, record.stones, true, record.stoneTints);
|
|
937
|
+
grassStones.name = "stones";
|
|
938
|
+
group.add(pathPebbles, grassStones);
|
|
939
|
+
|
|
940
|
+
// The meadow: one `InstancedMesh` a cell, each cell's tufts already shuffled, so drawing a prefix
|
|
941
|
+
// of it thins it evenly.
|
|
942
|
+
const tuft = tuftGeometry(replayed(record.tuftDraws));
|
|
943
|
+
const grass = grassMaterial();
|
|
944
|
+
const meadowCells: { mesh: InstancedMesh; all: number; share: number; x: number; z: number }[] =
|
|
945
|
+
[];
|
|
946
|
+
for (let cell = 0; cell + 1 < record.cellStarts.length; cell += 1) {
|
|
947
|
+
const first = record.cellStarts[cell] ?? 0;
|
|
948
|
+
const last = record.cellStarts[cell + 1] ?? 0;
|
|
949
|
+
const mesh = instanced(
|
|
950
|
+
tuft,
|
|
951
|
+
grass,
|
|
952
|
+
record.cellValues.subarray(first * PLACEMENT_STRIDE, last * PLACEMENT_STRIDE),
|
|
953
|
+
false,
|
|
954
|
+
record.cellTints.subarray(first * TINT_STRIDE, last * TINT_STRIDE),
|
|
955
|
+
);
|
|
700
956
|
mesh.name = "grass";
|
|
701
957
|
group.add(mesh);
|
|
702
958
|
meadowCells.push({
|
|
703
|
-
all:
|
|
959
|
+
all: last - first,
|
|
704
960
|
mesh,
|
|
705
|
-
share: Math.round(
|
|
706
|
-
x,
|
|
707
|
-
z,
|
|
961
|
+
share: Math.round((last - first) * site.grassShare),
|
|
962
|
+
x: record.cellXZ[cell * 2] ?? 0,
|
|
963
|
+
z: record.cellXZ[cell * 2 + 1] ?? 0,
|
|
708
964
|
});
|
|
709
965
|
}
|
|
710
966
|
let drawn = 0;
|
|
@@ -742,3 +998,8 @@ export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeado
|
|
|
742
998
|
}
|
|
743
999
|
return { group, meadow: meadowLod };
|
|
744
1000
|
}
|
|
1001
|
+
|
|
1002
|
+
/** One island, planned and built: the path a host with no memo takes. */
|
|
1003
|
+
export function plantIsland(site: IPlantingSite): { group: Group; meadow: IMeadow } {
|
|
1004
|
+
return buildPlanting(planPlanting(site), site);
|
|
1005
|
+
}
|