create-threenative 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -3
- package/agent-docs/references/assertion-reference.md +40 -1
- package/agent-docs/references/build-profiles.md +126 -0
- package/agent-docs/references/capability-reference.md +1382 -65
- package/agent-docs/references/finding-assets.md +8 -1
- package/agent-docs/references/performance-basics.md +117 -0
- package/agent-docs/references/rigging-characters.md +51 -0
- package/agent-docs/references/sculpt-from-a-reference.md +1 -1
- package/agent-docs/references/trace-a-slow-frame.md +1 -1
- package/agent-docs/references/visual-baseline.md +8 -4
- package/agent-docs/references/webview-ui.md +3 -2
- package/agent-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
- package/agent-files/.agents/skills/ponytail/SKILL.md +68 -0
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +12 -4
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-context/SKILL.md +9 -1
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +26 -10
- package/agent-files/.agents/skills/threenative-playtest/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-ui/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-visuals/SKILL.md +4 -4
- package/agent-files/.claude/hooks/ponytail-context.mjs +51 -0
- package/agent-files/.claude/settings.json +38 -0
- package/agent-files/.codex/hooks.json +40 -0
- package/capabilities.json +1891 -101
- package/dist/index.d.ts +39 -1
- package/dist/index.js +480 -56
- package/dist/threenative.js +1247 -177
- package/package.json +6 -6
- package/template-assets/assets/mannequin-combat.glb +0 -0
- package/template-assets/assets/mannequin.glb +0 -0
- package/template-assets/assets/player-viewmodel.glb +0 -0
- package/template-assets/assets/sky.jpg +0 -0
- package/template-assets/clearwater/README.md +141 -0
- package/template-assets/clearwater/install.mjs +50 -0
- package/template-assets/clearwater/src/clearwater.ts +180 -0
- package/template-assets/clearwater/src/clearwaterDemo.ts +28 -0
- package/template-assets/clearwater/src/clearwaterLifetime.ts +28 -0
- package/{LICENSE → template-assets/clearwater/src/render/CLEARWATER-LICENSE.txt} +4 -1
- package/template-assets/clearwater/src/render/clearwater.ts +278 -0
- package/template-assets/clearwater/src/render/clearwaterCaustics.ts +138 -0
- package/template-assets/clearwater/src/render/clearwaterDemo.ts +65 -0
- package/template-assets/clearwater/src/render/clearwaterOptics.ts +33 -0
- package/template-assets/clearwater/src/render/clearwaterOptions.ts +177 -0
- package/template-assets/clearwater/src/render/clearwaterPass.ts +51 -0
- package/template-assets/patches/three@0.185.1.patch +2228 -105
- package/template-assets/worldEnvironment.ts +52 -1
- package/templates/action-rpg/AGENTS.md +43 -43
- package/templates/action-rpg/CLAUDE.md +43 -43
- package/templates/action-rpg/kit.json +1 -1
- package/templates/action-rpg/package.json +14 -8
- package/templates/action-rpg/playtests/combat.playtest.json +162 -23
- package/templates/action-rpg/playtests/performance.playtest.json +4 -3
- package/templates/action-rpg/playtests/survives.playtest.json +25 -8
- package/templates/action-rpg/src/conventions.ts +24 -18
- package/templates/action-rpg/src/entities/Enemy.ts +74 -24
- package/templates/action-rpg/src/entities/Fighter.ts +127 -0
- package/templates/action-rpg/src/entities/Player.ts +102 -32
- package/templates/action-rpg/src/game.ts +3 -3
- package/templates/action-rpg/src/render/camera.ts +18 -16
- package/templates/action-rpg/src/render/dungeon.ts +192 -0
- package/templates/action-rpg/src/render/lighting.ts +45 -28
- package/templates/action-rpg/src/render/loading.ts +4 -4
- package/templates/action-rpg/src/render/materials.ts +191 -47
- package/templates/action-rpg/src/render/palette.ts +14 -13
- package/templates/action-rpg/src/render/postprocessing.ts +12 -2
- package/templates/action-rpg/src/render/props.ts +117 -0
- package/templates/action-rpg/src/render/quality.ts +40 -82
- package/templates/action-rpg/src/render/sky.ts +36 -13
- package/templates/action-rpg/src/render/touch-controls.ts +1 -1
- package/templates/action-rpg/src/render/worldEnvironment.ts +52 -1
- package/templates/action-rpg/src/scenes/Play.ts +61 -39
- package/templates/action-rpg/src/style.css +9 -7
- package/templates/action-rpg/src/ui/AbilityBar.tsx +3 -1
- package/templates/action-rpg/src/ui/Hud.tsx +3 -3
- package/templates/action-rpg/threenative.config.ts +14 -1
- package/templates/action-rpg/vite.config.ts +4 -1
- package/templates/minimal/AGENTS.md +12 -12
- package/templates/minimal/CLAUDE.md +12 -12
- package/templates/minimal/package.json +13 -7
- package/templates/minimal/playtests/play.playtest.json +6 -5
- package/templates/minimal/playtests/sky.playtest.json +27 -0
- package/templates/minimal/src/conventions.ts +6 -3
- package/templates/minimal/src/entities/Player.ts +73 -27
- package/templates/minimal/src/main.ts +2 -3
- package/templates/minimal/src/render/camera.ts +22 -4
- package/templates/minimal/src/render/lighting.ts +24 -48
- package/templates/minimal/src/render/materials.ts +158 -13
- package/templates/minimal/src/render/palette.ts +10 -7
- package/templates/minimal/src/render/postprocessing.ts +12 -25
- package/templates/minimal/src/render/quality.ts +35 -69
- package/templates/minimal/src/render/sky.ts +35 -54
- package/templates/minimal/src/render/touch-controls.ts +1 -1
- package/templates/minimal/src/render/worldEnvironment.ts +52 -1
- package/templates/minimal/src/scenes/Play.ts +121 -111
- package/templates/minimal/src/state.ts +0 -4
- package/templates/minimal/src/style.css +0 -10
- package/templates/minimal/threenative.config.ts +15 -1
- package/templates/minimal/vite.config.ts +4 -1
- package/templates/platformer/AGENTS.md +18 -56
- package/templates/platformer/CLAUDE.md +18 -56
- package/templates/platformer/kit.json +2 -2
- package/templates/platformer/package.json +14 -10
- package/templates/platformer/playtests/buffer.playtest.json +15 -5
- package/templates/platformer/playtests/collect.playtest.json +8 -34
- package/templates/platformer/playtests/coyote.playtest.json +12 -34
- package/templates/platformer/playtests/damage.playtest.json +40 -15
- package/templates/platformer/playtests/hud.playtest.json +34 -0
- package/templates/platformer/playtests/move.playtest.json +24 -0
- package/templates/platformer/playtests/performance.playtest.json +24 -7
- package/templates/platformer/playtests/respawn.playtest.json +46 -11
- package/templates/platformer/playtests/stomp.playtest.json +49 -12
- package/templates/platformer/playtests/survives.playtest.json +3 -19
- package/templates/platformer/playtests/world.playtest.json +26 -0
- package/templates/platformer/src/entities/Fox.ts +273 -0
- package/templates/platformer/src/entities/Pickup.ts +43 -60
- package/templates/platformer/src/entities/Walker.ts +88 -0
- package/templates/platformer/src/game.ts +11 -8
- package/templates/platformer/src/level/Checkpoints.ts +29 -16
- package/templates/platformer/src/level/Stage.ts +469 -0
- package/templates/platformer/src/render/blocks.ts +94 -0
- package/templates/platformer/src/render/camera.ts +28 -3
- package/templates/platformer/src/render/fox.ts +196 -0
- package/templates/platformer/src/render/lighting.ts +42 -33
- package/templates/platformer/src/render/materials.ts +115 -5
- package/templates/platformer/src/render/palette.ts +68 -53
- package/templates/platformer/src/render/pickups.ts +142 -0
- package/templates/platformer/src/render/postprocessing.ts +12 -2
- package/templates/platformer/src/render/props.ts +147 -0
- package/templates/platformer/src/render/quality.ts +47 -99
- package/templates/platformer/src/render/scenery.ts +172 -0
- package/templates/platformer/src/render/sky.ts +120 -31
- package/templates/platformer/src/render/touch-controls.ts +5 -2
- package/templates/platformer/src/render/walkers.ts +96 -0
- package/templates/platformer/src/render/waterfall.ts +85 -0
- package/templates/platformer/src/render/worldEnvironment.ts +52 -1
- package/templates/platformer/src/scenes/Boot.ts +3 -4
- package/templates/platformer/src/scenes/Play.ts +362 -0
- package/templates/platformer/src/state.ts +16 -14
- package/templates/platformer/src/style.css +9 -8
- package/templates/platformer/src/ui/Hud.tsx +62 -29
- package/templates/platformer/src/ui/Menu.tsx +2 -2
- package/templates/platformer/threenative.config.ts +14 -1
- package/templates/platformer/vite.config.ts +4 -1
- package/templates/puzzle/AGENTS.md +21 -22
- package/templates/puzzle/CLAUDE.md +21 -22
- package/templates/puzzle/assets/native-proof.glb +0 -0
- package/templates/puzzle/assets/native-proof.png +0 -0
- package/templates/puzzle/kit.json +1 -1
- package/templates/puzzle/package.json +14 -8
- package/templates/puzzle/playtests/axis.playtest.json +20 -0
- package/templates/puzzle/playtests/blocked.playtest.json +73 -0
- package/templates/puzzle/playtests/caused.playtest.json +65 -0
- package/templates/puzzle/playtests/lit.playtest.json +74 -0
- package/templates/puzzle/playtests/performance.playtest.json +24 -7
- package/templates/{starter/playtests/respawn.playtest.json → puzzle/playtests/push.playtest.json} +24 -19
- package/templates/puzzle/playtests/replay.playtest.json +81 -0
- package/templates/puzzle/playtests/restart.playtest.json +108 -0
- package/templates/puzzle/playtests/seal.playtest.json +98 -0
- package/templates/puzzle/playtests/settle.playtest.json +100 -0
- package/templates/puzzle/playtests/survives.playtest.json +6 -29
- package/templates/{starter/playtests/hot-reload.playtest.json → puzzle/playtests/travel.playtest.json} +6 -5
- package/templates/puzzle/src/entities/Crate.ts +99 -42
- package/templates/puzzle/src/entities/Seal.ts +69 -0
- package/templates/puzzle/src/entities/Warden.ts +135 -0
- package/templates/puzzle/src/game.ts +15 -11
- package/templates/puzzle/src/render/camera.ts +66 -31
- package/templates/puzzle/src/render/crateShape.ts +70 -0
- package/templates/puzzle/src/render/lighting.ts +41 -41
- package/templates/puzzle/src/render/loading.ts +4 -4
- package/templates/puzzle/src/render/materials.ts +131 -27
- package/templates/puzzle/src/render/palette.ts +19 -29
- package/templates/puzzle/src/render/postprocessing.ts +15 -3
- package/templates/puzzle/src/render/quality.ts +71 -80
- package/templates/puzzle/src/render/shapes.ts +109 -108
- package/templates/puzzle/src/render/sky.ts +18 -10
- package/templates/puzzle/src/render/touch-controls.ts +8 -51
- package/templates/puzzle/src/render/vault.ts +315 -0
- package/templates/puzzle/src/render/warden.ts +46 -0
- package/templates/puzzle/src/render/worldEnvironment.ts +52 -1
- package/templates/puzzle/src/scenes/Play.ts +793 -0
- package/templates/puzzle/src/state.ts +55 -24
- package/templates/puzzle/src/style.css +7 -8
- package/templates/puzzle/src/ui/App.tsx +2 -2
- package/templates/puzzle/src/ui/Hud.tsx +92 -40
- package/templates/puzzle/src/ui/Menu.tsx +40 -2
- package/templates/puzzle/threenative.config.ts +14 -1
- package/templates/puzzle/vite.config.ts +4 -1
- package/templates/racing/AGENTS.md +20 -21
- package/templates/racing/CLAUDE.md +20 -21
- package/templates/racing/package.json +14 -8
- package/templates/racing/playtests/boost.playtest.json +33 -12
- package/templates/racing/playtests/outcome.playtest.json +32 -50
- package/templates/racing/playtests/performance.playtest.json +2 -1
- package/templates/racing/playtests/ranking.playtest.json +5 -14
- package/templates/racing/playtests/rescue.playtest.json +2 -2
- package/templates/racing/playtests/reverse.playtest.json +30 -8
- package/templates/racing/playtests/shortcut.playtest.json +54 -9
- package/templates/racing/playtests/touch-controls.playtest.json +32 -5
- package/templates/racing/src/entities/CarBody.ts +327 -0
- package/templates/racing/src/entities/LineDriver.ts +220 -0
- package/templates/racing/src/entities/RacingCar.ts +150 -89
- package/templates/racing/src/entities/Rival.ts +61 -24
- package/templates/racing/src/game.ts +5 -0
- package/templates/racing/src/render/camera.ts +49 -7
- package/templates/racing/src/render/lighting.ts +36 -37
- package/templates/racing/src/render/materials.ts +239 -19
- package/templates/racing/src/render/palette.ts +19 -21
- package/templates/racing/src/render/postprocessing.ts +12 -2
- package/templates/racing/src/render/quality.ts +43 -82
- package/templates/racing/src/render/shapes.ts +20 -6
- package/templates/racing/src/render/sky.ts +47 -39
- package/templates/racing/src/render/touch-controls.ts +1 -1
- package/templates/racing/src/render/worldEnvironment.ts +52 -1
- package/templates/racing/src/scenes/Race.ts +107 -54
- package/templates/racing/src/state.ts +2 -0
- package/templates/racing/src/track/Checkline.ts +22 -7
- package/templates/racing/src/track/Lap.ts +64 -36
- package/templates/racing/src/track/Ranking.ts +20 -11
- package/templates/racing/src/track/Track.ts +809 -361
- package/templates/racing/src/track/TrackSector.ts +40 -11
- package/templates/racing/src/track/circuit.ts +477 -0
- package/templates/racing/src/track/rescue.ts +16 -4
- package/templates/racing/threenative.config.ts +14 -1
- package/templates/racing/vite.config.ts +4 -1
- package/templates/rts/AGENTS.md +96 -0
- package/templates/rts/CLAUDE.md +98 -0
- package/templates/rts/kit.json +7 -0
- package/templates/{defense → rts}/package.json +14 -8
- package/templates/{defense → rts}/playtests/performance.playtest.json +28 -26
- package/templates/rts/playtests/rts-ai-attack.playtest.json +24 -0
- package/templates/rts/playtests/rts-attack.playtest.json +75 -0
- package/templates/rts/playtests/rts-build.playtest.json +68 -0
- package/templates/rts/playtests/rts-orders.playtest.json +150 -0
- package/templates/rts/playtests/rts-train.playtest.json +62 -0
- package/templates/rts/playtests/survives.playtest.json +58 -0
- package/templates/rts/public/favicon.svg +4 -0
- package/templates/rts/src/game.ts +64 -0
- package/templates/rts/src/orders.ts +22 -0
- package/templates/rts/src/render/army.ts +346 -0
- package/templates/rts/src/render/camera.ts +123 -0
- package/templates/rts/src/render/lighting.ts +61 -0
- package/templates/rts/src/render/loading.ts +33 -0
- package/templates/rts/src/render/materials.ts +152 -0
- package/templates/rts/src/render/models.ts +705 -0
- package/templates/rts/src/render/palette.ts +17 -0
- package/templates/rts/src/render/picking.ts +93 -0
- package/templates/{defense → rts}/src/render/postprocessing.ts +15 -3
- package/templates/rts/src/render/quality.ts +128 -0
- package/templates/rts/src/render/resources.ts +141 -0
- package/templates/rts/src/render/sky.ts +44 -0
- package/templates/rts/src/render/terrain.ts +116 -0
- package/templates/{defense → rts}/src/render/worldEnvironment.ts +52 -1
- package/templates/rts/src/scenes/Play.ts +650 -0
- package/templates/rts/src/sim/ai.ts +1140 -0
- package/templates/rts/src/sim/combat.ts +416 -0
- package/templates/rts/src/sim/construction.ts +374 -0
- package/templates/rts/src/sim/economy.ts +167 -0
- package/templates/rts/src/sim/game.ts +1082 -0
- package/templates/rts/src/sim/movement.ts +371 -0
- package/templates/rts/src/sim/nav.ts +276 -0
- package/templates/rts/src/sim/production.ts +180 -0
- package/templates/rts/src/sim/terrain.ts +170 -0
- package/templates/rts/src/sim/types.ts +647 -0
- package/templates/rts/src/sim/vision.ts +46 -0
- package/templates/rts/src/state.ts +100 -0
- package/templates/{defense → rts}/src/style.css +21 -8
- package/templates/rts/src/ui/App.tsx +21 -0
- package/templates/rts/src/ui/Commands.tsx +129 -0
- package/templates/rts/src/ui/GameUi.tsx +22 -0
- package/templates/rts/src/ui/Hud.tsx +165 -0
- package/templates/rts/src/ui/Minimap.tsx +84 -0
- package/templates/rts/tailwind.config.ts +2 -0
- package/templates/rts/threenative.config.ts +56 -0
- package/templates/rts/tsconfig.json +17 -0
- package/templates/{defense → rts}/vite.config.ts +4 -1
- package/templates/runner/AGENTS.md +8 -12
- package/templates/runner/CLAUDE.md +8 -12
- package/templates/runner/README.md +3 -3
- package/templates/runner/package.json +14 -8
- package/templates/runner/playtests/performance.playtest.json +2 -2
- package/templates/runner/src/conventions.ts +4 -3
- package/templates/runner/src/entities/Runner.ts +54 -7
- package/templates/runner/src/game.ts +2 -0
- package/templates/runner/src/render/camera.ts +4 -2
- package/templates/runner/src/render/dust.ts +5 -2
- package/templates/runner/src/render/lighting.ts +41 -45
- package/templates/runner/src/render/loading.ts +2 -2
- package/templates/runner/src/render/materials.ts +165 -25
- package/templates/runner/src/render/palette.ts +17 -28
- package/templates/runner/src/render/postprocessing.ts +12 -2
- package/templates/runner/src/render/quality.ts +42 -96
- package/templates/runner/src/render/shapes.ts +59 -37
- package/templates/runner/src/render/sky.ts +32 -41
- package/templates/runner/src/render/touch-controls.ts +1 -1
- package/templates/runner/src/render/worldEnvironment.ts +52 -1
- package/templates/runner/src/scenes/Run.ts +26 -6
- package/templates/runner/src/track.ts +6 -1
- package/templates/runner/threenative.config.ts +14 -1
- package/templates/runner/vite.config.ts +4 -1
- package/templates/sailing/AGENTS.md +14 -14
- package/templates/sailing/CLAUDE.md +14 -14
- package/templates/sailing/assets/ship.glb +0 -0
- package/templates/sailing/package.json +14 -8
- package/templates/sailing/playtests/float-after-the-run-ends.playtest.json +10 -6
- package/templates/sailing/playtests/sails.playtest.json +33 -0
- package/templates/sailing/playtests/win.playtest.json +156 -8
- package/templates/sailing/src/conventions.ts +29 -2
- package/templates/sailing/src/entities/Ship.ts +381 -57
- package/templates/sailing/src/game.ts +14 -0
- package/templates/sailing/src/render/camera.ts +63 -9
- package/templates/sailing/src/render/lighting.ts +49 -27
- package/templates/sailing/src/render/materials.ts +50 -15
- package/templates/sailing/src/render/ocean.ts +647 -60
- package/templates/sailing/src/render/palette.ts +16 -12
- package/templates/sailing/src/render/postprocessing.ts +12 -2
- package/templates/sailing/src/render/props.ts +316 -442
- package/templates/sailing/src/render/quality.ts +14 -4
- package/templates/sailing/src/render/sky.ts +116 -23
- package/templates/sailing/src/render/worldEnvironment.ts +52 -1
- package/templates/sailing/src/scenes/Boot.ts +21 -0
- package/templates/sailing/src/scenes/Sailing.ts +173 -39
- package/templates/sailing/src/state.ts +6 -0
- package/templates/sailing/src/ui/Hud.tsx +41 -9
- package/templates/sailing/threenative.config.ts +14 -1
- package/templates/sailing/vite.config.ts +4 -1
- package/templates/shooter/AGENTS.md +29 -44
- package/templates/shooter/CLAUDE.md +29 -44
- package/templates/shooter/index.html +1 -0
- package/templates/shooter/package.json +14 -8
- package/templates/shooter/playtests/aim-alignment.playtest.json +58 -0
- package/templates/shooter/playtests/breakable-shatters.playtest.json +62 -0
- package/templates/shooter/playtests/bullet-holes.playtest.json +56 -0
- package/templates/shooter/playtests/camera-tracks-body-vertically.playtest.json +61 -0
- package/templates/shooter/playtests/crouch-lowers-the-eye.playtest.json +41 -0
- package/templates/shooter/playtests/death-no-snap.playtest.json +77 -0
- package/templates/shooter/playtests/debug-ads.playtest.json +58 -0
- package/templates/shooter/playtests/debug-clear.playtest.json +383 -0
- package/templates/shooter/playtests/debug-endurance.playtest.json +61 -0
- package/templates/shooter/playtests/debug-fire.playtest.json +119 -0
- package/templates/shooter/playtests/debug-restart.playtest.json +24 -0
- package/templates/shooter/playtests/enemy-body-is-a-body.playtest.json +79 -0
- package/templates/shooter/playtests/enemy-death-settles.playtest.json +64 -0
- package/templates/shooter/playtests/enemy-flinches-when-hit.playtest.json +75 -0
- package/templates/shooter/playtests/enemy-foot-contact.playtest.json +41 -0
- package/templates/shooter/playtests/enemy-material-is-not-shared.playtest.json +59 -0
- package/templates/shooter/playtests/enemy-reaches-walkway.playtest.json +80 -0
- package/templates/shooter/playtests/enemy-rifle-grip.playtest.json +101 -0
- package/templates/shooter/playtests/enemy-scale.playtest.json +56 -0
- package/templates/shooter/playtests/enemy-stops-without-snapping.playtest.json +486 -0
- package/templates/shooter/playtests/enemy-stride-matches-speed.playtest.json +198 -0
- package/templates/shooter/playtests/enemy-stride-under-crouch.playtest.json +87 -0
- package/templates/shooter/playtests/enemy-uses-crouch-clips.playtest.json +74 -0
- package/templates/shooter/playtests/five-soldiers.playtest.json +83 -0
- package/templates/shooter/playtests/flash-retires.playtest.json +62 -0
- package/templates/shooter/playtests/headshot-hits-head.playtest.json +132 -0
- package/templates/shooter/playtests/hold-to-fire.playtest.json +45 -0
- package/templates/shooter/playtests/input-control.playtest.json +43 -98
- package/templates/shooter/playtests/minimap-state.playtest.json +75 -0
- package/templates/shooter/playtests/performance.playtest.json +62 -26
- package/templates/{starter/playtests/forward.playtest.json → shooter/playtests/round-clock.playtest.json} +11 -16
- package/templates/shooter/playtests/shot-tracks-crosshair.playtest.json +79 -0
- package/templates/shooter/playtests/survives.playtest.json +36 -30
- package/templates/shooter/playtests/walkway-reachable.playtest.json +67 -0
- package/templates/shooter/src/entities/Breakables.ts +412 -0
- package/templates/shooter/src/entities/Enemy.ts +2095 -0
- package/templates/shooter/src/entities/FpsPlayer.ts +283 -0
- package/templates/shooter/src/entities/Rifle.ts +442 -0
- package/templates/shooter/src/entities/Target.ts +199 -83
- package/templates/shooter/src/entities/TouchControls.ts +276 -0
- package/templates/shooter/src/game.ts +75 -41
- package/templates/shooter/src/main.ts +0 -1
- package/templates/shooter/src/postPhysics.ts +36 -0
- package/templates/shooter/src/render/camera.ts +78 -74
- package/templates/shooter/src/render/decals.ts +142 -82
- package/templates/shooter/src/render/facade.ts +1373 -0
- package/templates/shooter/src/render/gunfx.ts +704 -0
- package/templates/shooter/src/render/lighting.ts +52 -38
- package/templates/shooter/src/render/loading.ts +2 -2
- package/templates/shooter/src/render/materials.ts +100 -88
- package/templates/shooter/src/render/occlusion.ts +108 -0
- package/templates/shooter/src/render/palette.ts +10 -10
- package/templates/shooter/src/render/palm.ts +455 -0
- package/templates/shooter/src/render/pooled-billboards.ts +144 -0
- package/templates/shooter/src/render/postprocessing.ts +15 -3
- package/templates/shooter/src/render/quality.ts +40 -82
- package/templates/shooter/src/render/scale.ts +148 -15
- package/templates/shooter/src/render/shapes.ts +138 -613
- package/templates/shooter/src/render/sky.ts +35 -35
- package/templates/shooter/src/render/town-schematic.ts +120 -0
- package/templates/shooter/src/render/town.ts +986 -0
- package/templates/shooter/src/render/townMaterials.ts +160 -0
- package/templates/shooter/src/render/vehicles.ts +741 -0
- package/templates/shooter/src/render/worldEnvironment.ts +52 -1
- package/templates/shooter/src/scenes/Play.ts +727 -650
- package/templates/shooter/src/state.ts +26 -41
- package/templates/shooter/src/style.css +207 -11
- package/templates/shooter/src/surfaces.ts +131 -0
- package/templates/shooter/src/ui/App.tsx +9 -10
- package/templates/shooter/src/ui/Crosshair.tsx +25 -18
- package/templates/shooter/src/ui/GameUi.tsx +6 -9
- package/templates/shooter/src/ui/Hud.tsx +428 -39
- package/templates/shooter/src/ui/Minimap.tsx +164 -0
- package/templates/shooter/src/ui/TouchOverlay.tsx +54 -0
- package/templates/shooter/src/ui/main.tsx +2 -3
- package/templates/shooter/threenative.config.ts +14 -1
- package/templates/shooter/vite.config.ts +4 -1
- package/templates/starter/AGENTS.md +20 -20
- package/templates/starter/CLAUDE.md +20 -20
- package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
- package/templates/starter/package.json +15 -9
- package/templates/starter/playtests/play.playtest.json +2 -1
- package/templates/starter/playtests/{restart.playtest.json → production-readiness.playtest.json} +17 -12
- package/templates/starter/playtests/survives.playtest.json +1 -1
- package/templates/starter/src/conventions.ts +6 -3
- package/templates/starter/src/entities/Goal.ts +35 -42
- package/templates/starter/src/entities/Player.ts +99 -16
- package/templates/starter/src/render/arena.ts +131 -0
- package/templates/starter/src/render/lighting.ts +27 -44
- package/templates/starter/src/render/materials.ts +164 -35
- package/templates/starter/src/render/palette.ts +16 -16
- package/templates/starter/src/render/postprocessing.ts +6 -7
- package/templates/starter/src/render/quality.ts +43 -101
- package/templates/starter/src/render/shapes.ts +1 -1
- package/templates/starter/src/render/sky.ts +39 -45
- package/templates/starter/src/render/touch-controls.ts +3 -1
- package/templates/starter/src/render/worldEnvironment.ts +52 -1
- package/templates/starter/src/scenes/Play.ts +82 -81
- package/templates/starter/src/ui/Hud.tsx +2 -2
- package/templates/starter/src/ui/Menu.tsx +5 -1
- package/templates/starter/threenative.config.ts +14 -1
- package/templates/starter/vite.config.ts +4 -1
- package/templates/tower-defense/.codex/config.toml +19 -0
- package/templates/tower-defense/.cursor/mcp.json +32 -0
- package/templates/tower-defense/.gemini/settings.json +32 -0
- package/templates/tower-defense/.mcp.json +32 -0
- package/templates/tower-defense/.vscode/mcp.json +36 -0
- package/templates/tower-defense/.zed/settings.json +36 -0
- package/templates/{defense → tower-defense}/AGENTS.md +16 -14
- package/templates/{defense → tower-defense}/CLAUDE.md +16 -14
- package/templates/tower-defense/README.md +16 -0
- package/templates/tower-defense/index.html +12 -0
- package/templates/tower-defense/kit.json +7 -0
- package/templates/tower-defense/opencode.json +41 -0
- package/templates/tower-defense/package.json +56 -0
- package/templates/tower-defense/playtests/arsenal.playtest.json +214 -0
- package/templates/tower-defense/playtests/defeat.playtest.json +85 -0
- package/templates/tower-defense/playtests/look.playtest.json +130 -0
- package/templates/tower-defense/playtests/performance.playtest.json +77 -0
- package/templates/tower-defense/playtests/placement.playtest.json +115 -0
- package/templates/{defense → tower-defense}/playtests/pointer-placement.playtest.json +21 -49
- package/templates/tower-defense/playtests/strike.playtest.json +98 -0
- package/templates/tower-defense/playtests/survives.playtest.json +85 -0
- package/templates/tower-defense/playtests/target-priority.playtest.json +177 -0
- package/templates/tower-defense/playtests/upgrade-recycle.playtest.json +124 -0
- package/templates/tower-defense/playtests/victory.playtest.json +810 -0
- package/templates/tower-defense/src/balance.ts +187 -0
- package/templates/tower-defense/src/board/Board.ts +100 -0
- package/templates/tower-defense/src/board/Route.ts +84 -0
- package/templates/tower-defense/src/camera-rig.ts +62 -0
- package/templates/tower-defense/src/economy.ts +64 -0
- package/templates/tower-defense/src/effects/Effects.ts +284 -0
- package/templates/tower-defense/src/enemies/Enemy.ts +198 -0
- package/templates/tower-defense/src/game.ts +72 -0
- package/templates/tower-defense/src/intents.ts +21 -0
- package/templates/tower-defense/src/main.ts +15 -0
- package/templates/tower-defense/src/physics.ts +6 -0
- package/templates/tower-defense/src/render/camera.ts +38 -0
- package/templates/tower-defense/src/render/lighting.ts +42 -0
- package/templates/{defense → tower-defense}/src/render/loading.ts +3 -3
- package/templates/tower-defense/src/render/materials.ts +103 -0
- package/templates/tower-defense/src/render/palette.ts +58 -0
- package/templates/tower-defense/src/render/postprocessing.ts +46 -0
- package/templates/tower-defense/src/render/quality.ts +128 -0
- package/templates/tower-defense/src/render/shapes.ts +550 -0
- package/templates/tower-defense/src/render/sky.ts +27 -0
- package/templates/tower-defense/src/render/worldEnvironment.ts +809 -0
- package/templates/tower-defense/src/scenes/Battle.ts +539 -0
- package/templates/{shooter → tower-defense}/src/scenes/Boot.ts +3 -3
- package/templates/tower-defense/src/state.ts +88 -0
- package/templates/tower-defense/src/style.css +137 -0
- package/templates/tower-defense/src/towers/Tower.ts +230 -0
- package/templates/tower-defense/src/towers/targeting.ts +97 -0
- package/templates/tower-defense/src/ui/Hud.tsx +270 -0
- package/templates/tower-defense/src/ui/Menu.tsx +134 -0
- package/templates/tower-defense/src/ui/icons.tsx +54 -0
- package/templates/tower-defense/src/ui/main.tsx +14 -0
- package/templates/tower-defense/src/waves.ts +90 -0
- package/templates/{defense → tower-defense}/threenative.config.ts +14 -1
- package/templates/tower-defense/vite.config.ts +41 -0
- package/agent-files/.claude/skills/file-engine-bug/SKILL.md +0 -59
- package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
- package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -45
- package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
- package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -57
- package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -42
- package/agent-files/.claude/skills/threenative-playtest/SKILL.md +0 -44
- package/agent-files/.claude/skills/threenative-ui/SKILL.md +0 -20
- package/agent-files/.claude/skills/threenative-visuals/SKILL.md +0 -41
- package/agent-files/AGENT-ROLES.md +0 -26
- package/templates/action-rpg/src/render/shapes.ts +0 -269
- package/templates/action-rpg/src/render/types.ts +0 -3
- package/templates/action-rpg/src/scenes/Boot.ts +0 -12
- package/templates/defense/README.md +0 -10
- package/templates/defense/kit.json +0 -7
- package/templates/defense/playtests/leak.playtest.json +0 -23
- package/templates/defense/playtests/placement.playtest.json +0 -40
- package/templates/defense/playtests/scan.playtest.json +0 -20
- package/templates/defense/playtests/survive.playtest.json +0 -45
- package/templates/defense/playtests/survives.playtest.json +0 -36
- package/templates/defense/src/attackers/Attacker.ts +0 -120
- package/templates/defense/src/board/Route.ts +0 -94
- package/templates/defense/src/conventions.ts +0 -18
- package/templates/defense/src/economy.ts +0 -36
- package/templates/defense/src/entities/Player.ts +0 -52
- package/templates/defense/src/game.ts +0 -51
- package/templates/defense/src/physics.ts +0 -13
- package/templates/defense/src/placement/Buildable.ts +0 -49
- package/templates/defense/src/render/camera.ts +0 -16
- package/templates/defense/src/render/lighting.ts +0 -37
- package/templates/defense/src/render/materials.ts +0 -22
- package/templates/defense/src/render/palette.ts +0 -28
- package/templates/defense/src/render/quality.ts +0 -170
- package/templates/defense/src/render/shapes.ts +0 -246
- package/templates/defense/src/render/sky.ts +0 -45
- package/templates/defense/src/scenes/Boot.ts +0 -12
- package/templates/defense/src/scenes/Defense.ts +0 -231
- package/templates/defense/src/state.ts +0 -56
- package/templates/defense/src/towers/Tower.ts +0 -95
- package/templates/defense/src/towers/targeting.ts +0 -53
- package/templates/defense/src/ui/Hud.tsx +0 -62
- package/templates/defense/src/ui/Menu.tsx +0 -7
- package/templates/defense/src/waves.ts +0 -40
- package/templates/minimal/playtests/atmosphere.playtest.json +0 -32
- package/templates/minimal/src/render/hud.ts +0 -69
- package/templates/platformer/playtests/avoidance.playtest.json +0 -28
- package/templates/platformer/playtests/chase.playtest.json +0 -21
- package/templates/platformer/playtests/collision-layers.playtest.json +0 -36
- package/templates/platformer/playtests/oneway.playtest.json +0 -44
- package/templates/platformer/playtests/patrol.playtest.json +0 -13
- package/templates/platformer/playtests/physics.playtest.json +0 -14
- package/templates/platformer/playtests/stomp-rise.playtest.json +0 -55
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +0 -41
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +0 -52
- package/templates/platformer/src/conventions.ts +0 -18
- package/templates/platformer/src/entities/Character.ts +0 -286
- package/templates/platformer/src/entities/Chaser.ts +0 -118
- package/templates/platformer/src/entities/Patrol.ts +0 -93
- package/templates/platformer/src/level/Platform.ts +0 -46
- package/templates/platformer/src/render/rig.ts +0 -60
- package/templates/platformer/src/render/terrain.ts +0 -31
- package/templates/platformer/src/scenes/Level.ts +0 -241
- package/templates/puzzle/README.md +0 -43
- package/templates/puzzle/playtests/carry.playtest.json +0 -71
- package/templates/puzzle/playtests/swing.playtest.json +0 -38
- package/templates/puzzle/src/conventions.ts +0 -25
- package/templates/puzzle/src/entities/Ball.ts +0 -70
- package/templates/puzzle/src/entities/Gripper.ts +0 -69
- package/templates/puzzle/src/entities/Pendulum.ts +0 -89
- package/templates/puzzle/src/physics.ts +0 -19
- package/templates/puzzle/src/room.ts +0 -83
- package/templates/puzzle/src/scenes/Boot.ts +0 -12
- package/templates/puzzle/src/scenes/Puzzle.ts +0 -158
- package/templates/shooter/playtests/combat.playtest.json +0 -48
- package/templates/shooter/playtests/fail.playtest.json +0 -31
- package/templates/shooter/playtests/per-item.playtest.json +0 -59
- package/templates/shooter/playtests/shooter.playtest.json +0 -99
- package/templates/shooter/playtests/touch-controls.playtest.json +0 -42
- package/templates/shooter/playtests/weapon-cycle.playtest.json +0 -164
- package/templates/shooter/src/combat/damage.ts +0 -40
- package/templates/shooter/src/conventions.ts +0 -51
- package/templates/shooter/src/entities/Pickup.ts +0 -70
- package/templates/shooter/src/entities/Player.ts +0 -310
- package/templates/shooter/src/level/SpawnPoints.ts +0 -28
- package/templates/shooter/src/playtest-events.ts +0 -15
- package/templates/shooter/src/render/touch-controls.ts +0 -305
- package/templates/shooter/src/render/types.ts +0 -3
- package/templates/shooter/src/render/ui.css +0 -330
- package/templates/shooter/src/render/ui.ts +0 -75
- package/templates/shooter/src/render/vfx.ts +0 -215
- package/templates/shooter/src/ui/Menu.tsx +0 -41
- package/templates/shooter/src/waves.ts +0 -50
- package/templates/shooter/src/weapons/Hitscan.ts +0 -42
- package/templates/shooter/src/weapons/Projectile.ts +0 -92
- package/templates/shooter/src/weapons/Viewmodel.ts +0 -275
- package/templates/starter/playtests/assets.playtest.json +0 -65
- package/templates/starter/playtests/buffer.playtest.json +0 -79
- package/templates/starter/playtests/cloth.playtest.json +0 -113
- package/templates/starter/playtests/coyote.playtest.json +0 -87
- package/templates/starter/playtests/gameover.playtest.json +0 -66
- package/templates/starter/playtests/goal.playtest.json +0 -67
- package/templates/starter/playtests/look.playtest.json +0 -175
- package/templates/starter/playtests/models-baseline.png +0 -0
- package/templates/starter/playtests/models.playtest.json +0 -74
- package/templates/starter/playtests/monitoring.playtest.json +0 -72
- package/templates/starter/playtests/odometer.playtest.json +0 -54
- package/templates/starter/playtests/seed.playtest.json +0 -54
- package/templates/starter/playtests/textures-baseline.png +0 -0
- package/templates/starter/playtests/textures.playtest.json +0 -74
- package/templates/starter/playtests/touch-controls.playtest.json +0 -42
- package/templates/starter/playtests/zoom-pinch.playtest.json +0 -86
- package/templates/starter/playtests/zoom-wheel.playtest.json +0 -59
- package/templates/starter/src/render/coast.ts +0 -199
- package/templates/starter/src/render/hero.ts +0 -88
- package/templates/starter/src/render/implicitSurface.ts +0 -199
- package/templates/starter/src/render/kuwahara.ts +0 -174
- package/templates/starter/src/render/outline.ts +0 -141
- package/templates/starter/src/render/painterly.ts +0 -86
- package/templates/starter/src/render/rockRidge.ts +0 -198
- package/templates/starter/src/render/rockRidge.worker.ts +0 -77
- package/templates/starter/src/render/scenery.ts +0 -40
- package/templates/starter/src/render/textureLifetime.ts +0 -53
- package/templates/starter/src/render/water.ts +0 -38
- package/templates/starter/src/render/watercolor.ts +0 -85
- /package/templates/{starter → puzzle}/playtests/boot-failure.playtest.json +0 -0
- /package/templates/{starter → puzzle}/playtests/pause.playtest.json +0 -0
- /package/templates/{defense → rts}/.codex/config.toml +0 -0
- /package/templates/{defense → rts}/.cursor/mcp.json +0 -0
- /package/templates/{defense → rts}/.gemini/settings.json +0 -0
- /package/templates/{defense → rts}/.mcp.json +0 -0
- /package/templates/{defense → rts}/.vscode/mcp.json +0 -0
- /package/templates/{defense → rts}/.zed/settings.json +0 -0
- /package/templates/{defense → rts}/index.html +0 -0
- /package/templates/{defense → rts}/opencode.json +0 -0
- /package/templates/{defense → rts}/src/main.ts +0 -0
- /package/templates/{defense → rts}/src/ui/main.tsx +0 -0
- /package/templates/{defense → tower-defense}/public/favicon.svg +0 -0
- /package/templates/{defense → tower-defense}/src/playtest-events.ts +0 -0
- /package/templates/{defense → tower-defense}/src/ui/App.tsx +0 -0
- /package/templates/{defense → tower-defense}/src/ui/GameUi.tsx +0 -0
- /package/templates/{defense → tower-defense}/tailwind.config.ts +0 -0
- /package/templates/{defense → tower-defense}/tsconfig.json +0 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
// Date palms for the Bayview waterfront, built as real geometry.
|
|
2
|
+
//
|
|
3
|
+
// A palm is recognised entirely from its outline, so this file spends its
|
|
4
|
+
// vertices on the three things that outline is made of:
|
|
5
|
+
//
|
|
6
|
+
// 1. a slender trunk that LEANS — Mediterranean date palms never stand
|
|
7
|
+
// plumb — tapering 0.37 m at the root flare to 0.21 m under the crown,
|
|
8
|
+
// with stepped bark rings where old frond bases sheared off;
|
|
9
|
+
// 2. nine to thirteen pinnate fronds whose pitch rotates from upward at the
|
|
10
|
+
// base, through horizontal, to drooping well past it at the tip, each one
|
|
11
|
+
// a run of swept leaflets so the edge reads as a saw-tooth rather than a
|
|
12
|
+
// cut-out rectangle;
|
|
13
|
+
// 3. the crown junk under it: a skirt of dead brown fronds and two or three
|
|
14
|
+
// hanging date bunches, both cheap and both unmistakably palm.
|
|
15
|
+
//
|
|
16
|
+
// Everything is deterministic (`makeRandom`, never `Math.random`) so a replay
|
|
17
|
+
// renders the same tree twice, and the whole run of trees is drawn from three
|
|
18
|
+
// prototype geometries through `InstancedMesh` — a palm is a repeated prop, and
|
|
19
|
+
// generating fresh geometry per placement is how a prop budget disappears.
|
|
20
|
+
//
|
|
21
|
+
// Colour variation is baked into a vertex-colour attribute instead of extra
|
|
22
|
+
// materials: frond tips read sun-bleached, frond bases shaded, and the bark
|
|
23
|
+
// grooves darker, all inside one draw call per part. (CanvasTexture samples
|
|
24
|
+
// black under WebGPURenderer, so a painted gradient is not an option here.)
|
|
25
|
+
import {
|
|
26
|
+
BufferGeometry,
|
|
27
|
+
CatmullRomCurve3,
|
|
28
|
+
Float32BufferAttribute,
|
|
29
|
+
type Group,
|
|
30
|
+
InstancedMesh,
|
|
31
|
+
type Material,
|
|
32
|
+
Matrix4,
|
|
33
|
+
MeshStandardMaterial,
|
|
34
|
+
Quaternion,
|
|
35
|
+
SphereGeometry,
|
|
36
|
+
Vector3,
|
|
37
|
+
} from "three";
|
|
38
|
+
import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js";
|
|
39
|
+
import { worldGridUVs } from "./materials.js";
|
|
40
|
+
import { makeRandom } from "./shapes.js";
|
|
41
|
+
|
|
42
|
+
/** The two town materials a palm is allowed to ask for; the rest are derived. */
|
|
43
|
+
export type PalmMaterials = {
|
|
44
|
+
readonly palmTrunk: Material;
|
|
45
|
+
readonly frond: Material;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/** Ground position of one tree. */
|
|
49
|
+
export type PalmPlacement = readonly [number, number];
|
|
50
|
+
|
|
51
|
+
const TAU = Math.PI * 2;
|
|
52
|
+
const UP = new Vector3(0, 1, 0);
|
|
53
|
+
|
|
54
|
+
/** Trunk: 0.37 m across at the flare, 0.21 m under the crown. Half of that here. */
|
|
55
|
+
const TRUNK_BASE_RADIUS = 0.185;
|
|
56
|
+
const TRUNK_TOP_RADIUS = 0.105;
|
|
57
|
+
/** Bark steps along the trunk; three geometry rings each, so the step reads. */
|
|
58
|
+
const BARK_STEPS = 18;
|
|
59
|
+
const TRUNK_RINGS = BARK_STEPS * 3;
|
|
60
|
+
const TRUNK_RADIALS = 8;
|
|
61
|
+
/** Leaflets a side. The reference frond is a feather, not a serrated blade. */
|
|
62
|
+
const LEAFLETS_PER_SIDE = 20;
|
|
63
|
+
|
|
64
|
+
/** One geometry per material, all in the tree's local space with the root at y=0. */
|
|
65
|
+
type PalmParts = {
|
|
66
|
+
readonly trunk: BufferGeometry;
|
|
67
|
+
readonly live: BufferGeometry;
|
|
68
|
+
readonly dead: BufferGeometry;
|
|
69
|
+
readonly fruit: BufferGeometry;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** A frond, described the way it is drawn: an arch that keeps rotating downward. */
|
|
73
|
+
type FrondSpec = {
|
|
74
|
+
readonly length: number;
|
|
75
|
+
readonly width: number;
|
|
76
|
+
/** Pitch at the base, radians above horizontal. */
|
|
77
|
+
readonly rise: number;
|
|
78
|
+
/** Pitch at the tip. Below −0.2 or so the frond droops past horizontal. */
|
|
79
|
+
readonly droop: number;
|
|
80
|
+
readonly curl: number;
|
|
81
|
+
readonly segments: number;
|
|
82
|
+
readonly shade: readonly [number, number, number];
|
|
83
|
+
readonly tip: readonly [number, number, number];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function tint(
|
|
87
|
+
values: number[],
|
|
88
|
+
from: readonly [number, number, number],
|
|
89
|
+
to: readonly [number, number, number],
|
|
90
|
+
t: number,
|
|
91
|
+
gain: number,
|
|
92
|
+
): void {
|
|
93
|
+
values.push(
|
|
94
|
+
(from[0] + (to[0] - from[0]) * t) * gain,
|
|
95
|
+
(from[1] + (to[1] - from[1]) * t) * gain,
|
|
96
|
+
(from[2] + (to[2] - from[2]) * t) * gain,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function finish(positions: number[], colors: number[], indices: number[]): BufferGeometry {
|
|
101
|
+
const geometry = new BufferGeometry();
|
|
102
|
+
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
103
|
+
geometry.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
104
|
+
geometry.setIndex(indices);
|
|
105
|
+
return geometry;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A pinnate frond growing along +x from the origin.
|
|
110
|
+
*
|
|
111
|
+
* The rachis is a narrow ribbon; every segment then hangs one triangular
|
|
112
|
+
* leaflet off each side, swept toward the tip and folded down into a shallow V.
|
|
113
|
+
* Adjacent leaflets share the rachis edge, so the blade is continuous while its
|
|
114
|
+
* outer edge is a run of points — which is the whole reason to build it this
|
|
115
|
+
* way rather than as a quad.
|
|
116
|
+
*/
|
|
117
|
+
function frondGeometry(spec: FrondSpec, rng: () => number): BufferGeometry {
|
|
118
|
+
const { length, width, rise, droop, curl, segments, shade, tip } = spec;
|
|
119
|
+
const step = length / segments;
|
|
120
|
+
const spine: Vector3[] = [];
|
|
121
|
+
const walker = new Vector3(0, 0, 0);
|
|
122
|
+
for (let i = 0; i <= segments; i += 1) {
|
|
123
|
+
spine.push(walker.clone());
|
|
124
|
+
const along = (i + 0.5) / segments;
|
|
125
|
+
// The droop accelerates: a frond is stiff where it leaves the crown and
|
|
126
|
+
// limp at the tip, so the pitch is eased rather than lerped.
|
|
127
|
+
const pitch = rise + (droop - rise) * along ** 1.65;
|
|
128
|
+
walker.x += Math.cos(pitch) * step;
|
|
129
|
+
walker.y += Math.sin(pitch) * step;
|
|
130
|
+
walker.z += curl * along * step;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const positions: number[] = [];
|
|
134
|
+
const colors: number[] = [];
|
|
135
|
+
const indices: number[] = [];
|
|
136
|
+
const at = (i: number): Vector3 => spine[Math.min(i, spine.length - 1)] ?? walker;
|
|
137
|
+
const bladeWidth = (t: number): number =>
|
|
138
|
+
width * Math.max(0.05, Math.min(1, t / 0.2)) * (1 - t * 0.76);
|
|
139
|
+
const rachisWidth = (t: number): number => 0.05 * (1 - t * 0.62);
|
|
140
|
+
|
|
141
|
+
// Rachis ribbon.
|
|
142
|
+
for (let i = 0; i <= segments; i += 1) {
|
|
143
|
+
const t = i / segments;
|
|
144
|
+
const point = at(i);
|
|
145
|
+
const half = rachisWidth(t);
|
|
146
|
+
for (const side of [-1, 1]) {
|
|
147
|
+
positions.push(point.x, point.y + half * 0.2, point.z + half * side);
|
|
148
|
+
tint(colors, shade, tip, t, 0.92);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (let i = 0; i < segments; i += 1) {
|
|
152
|
+
const a = i * 2;
|
|
153
|
+
indices.push(a, a + 2, a + 1, a + 1, a + 2, a + 3);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Leaflets.
|
|
157
|
+
for (let i = 0; i < segments; i += 1) {
|
|
158
|
+
const t = i / segments;
|
|
159
|
+
const next = (i + 1) / segments;
|
|
160
|
+
const root = at(i);
|
|
161
|
+
const ahead = at(i + 1);
|
|
162
|
+
const span = bladeWidth((t + next) / 2) * (0.82 + rng() * 0.36);
|
|
163
|
+
for (const side of [-1, 1]) {
|
|
164
|
+
const base = positions.length / 3;
|
|
165
|
+
const inner = rachisWidth(t) * side;
|
|
166
|
+
const innerNext = rachisWidth(next) * side;
|
|
167
|
+
positions.push(root.x, root.y, root.z + inner);
|
|
168
|
+
tint(colors, shade, tip, t, 0.8);
|
|
169
|
+
positions.push(ahead.x, ahead.y, ahead.z + innerNext);
|
|
170
|
+
tint(colors, shade, tip, next, 0.86);
|
|
171
|
+
// Swept past the next node so leaflets overlap instead of leaving gaps,
|
|
172
|
+
// and folded down so the frond has a V section rather than a flat one.
|
|
173
|
+
const sweep = 1.45;
|
|
174
|
+
positions.push(
|
|
175
|
+
root.x + (ahead.x - root.x) * sweep,
|
|
176
|
+
root.y + (ahead.y - root.y) * sweep - span * 0.44,
|
|
177
|
+
root.z + (ahead.z - root.z) * sweep + span * side,
|
|
178
|
+
);
|
|
179
|
+
tint(colors, shade, tip, Math.min(1, next + 0.1), 1);
|
|
180
|
+
if (side < 0) indices.push(base, base + 1, base + 2);
|
|
181
|
+
else indices.push(base, base + 2, base + 1);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return finish(positions, colors, indices);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Leaning, ring-stepped trunk swept along a Catmull-Rom spine. */
|
|
189
|
+
function trunkGeometry(spine: CatmullRomCurve3): BufferGeometry {
|
|
190
|
+
const frames = spine.computeFrenetFrames(TRUNK_RINGS, false);
|
|
191
|
+
const positions: number[] = [];
|
|
192
|
+
const colors: number[] = [];
|
|
193
|
+
const indices: number[] = [];
|
|
194
|
+
const point = new Vector3();
|
|
195
|
+
// The scar phase is a function of height AND of which radial column you are
|
|
196
|
+
// on: neighbouring columns are offset half a step, which turns a stack of
|
|
197
|
+
// plain hoops into the diamond lattice of old frond bases a date palm
|
|
198
|
+
// actually wears. Radius and vertex colour both read this one function, so
|
|
199
|
+
// the relief and the shading agree instead of fighting.
|
|
200
|
+
const scarPhase = (t: number, column: number): number =>
|
|
201
|
+
(t * BARK_STEPS + (column % 2) * 0.5) % 1;
|
|
202
|
+
const radiusAt = (t: number, column: number): number => {
|
|
203
|
+
const taper = TRUNK_BASE_RADIUS + (TRUNK_TOP_RADIUS - TRUNK_BASE_RADIUS) * t ** 0.7;
|
|
204
|
+
const flare = 1 + 0.5 * Math.exp(-t * 15);
|
|
205
|
+
return taper * flare * (1 + 0.12 * (1 - scarPhase(t, column)));
|
|
206
|
+
};
|
|
207
|
+
for (let i = 0; i <= TRUNK_RINGS; i += 1) {
|
|
208
|
+
const t = i / TRUNK_RINGS;
|
|
209
|
+
spine.getPointAt(t, point);
|
|
210
|
+
const normal = frames.normals[i] ?? UP;
|
|
211
|
+
const binormal = frames.binormals[i] ?? UP;
|
|
212
|
+
for (let j = 0; j < TRUNK_RADIALS; j += 1) {
|
|
213
|
+
const angle = (j / TRUNK_RADIALS) * TAU;
|
|
214
|
+
const cos = Math.cos(angle);
|
|
215
|
+
const sin = Math.sin(angle);
|
|
216
|
+
const radius = radiusAt(t, j);
|
|
217
|
+
// The scar face catches the sun; the step under it reads dark.
|
|
218
|
+
const bark = 0.6 + 0.62 * (1 - scarPhase(t, j)) + t * 0.12;
|
|
219
|
+
positions.push(
|
|
220
|
+
point.x + radius * (cos * normal.x + sin * binormal.x),
|
|
221
|
+
point.y + radius * (cos * normal.y + sin * binormal.y),
|
|
222
|
+
point.z + radius * (cos * normal.z + sin * binormal.z),
|
|
223
|
+
);
|
|
224
|
+
colors.push(bark, bark, bark);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (let i = 0; i < TRUNK_RINGS; i += 1) {
|
|
228
|
+
for (let j = 0; j < TRUNK_RADIALS; j += 1) {
|
|
229
|
+
const a = i * TRUNK_RADIALS + j;
|
|
230
|
+
const b = i * TRUNK_RADIALS + ((j + 1) % TRUNK_RADIALS);
|
|
231
|
+
indices.push(a, a + TRUNK_RADIALS, b, b, a + TRUNK_RADIALS, b + TRUNK_RADIALS);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Cap the top so the crown never shows a hollow tube from below.
|
|
235
|
+
const cap = positions.length / 3;
|
|
236
|
+
spine.getPointAt(1, point);
|
|
237
|
+
positions.push(point.x, point.y, point.z);
|
|
238
|
+
colors.push(0.9, 0.9, 0.9);
|
|
239
|
+
const last = TRUNK_RINGS * TRUNK_RADIALS;
|
|
240
|
+
for (let j = 0; j < TRUNK_RADIALS; j += 1) {
|
|
241
|
+
indices.push(cap, last + j, last + ((j + 1) % TRUNK_RADIALS));
|
|
242
|
+
}
|
|
243
|
+
return finish(positions, colors, indices);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** A low-poly blob, used for the crown boss and the date bunches. */
|
|
247
|
+
function blob(radius: number, widthSegments: number, heightSegments: number): BufferGeometry {
|
|
248
|
+
const sphere = new SphereGeometry(radius, widthSegments, heightSegments);
|
|
249
|
+
sphere.deleteAttribute("uv");
|
|
250
|
+
sphere.deleteAttribute("normal");
|
|
251
|
+
const count = sphere.attributes.position?.count ?? 0;
|
|
252
|
+
const colors: number[] = [];
|
|
253
|
+
for (let i = 0; i < count; i += 1) colors.push(1, 1, 1);
|
|
254
|
+
sphere.setAttribute("color", new Float32BufferAttribute(colors, 3));
|
|
255
|
+
return sphere;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Place a geometry into the crown's frame: spin it, then stand it on the trunk. */
|
|
259
|
+
function placed(geometry: BufferGeometry, azimuth: number, crown: Matrix4): BufferGeometry {
|
|
260
|
+
const spin = new Matrix4().makeRotationY(azimuth);
|
|
261
|
+
return geometry.applyMatrix4(spin).applyMatrix4(crown);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* One prototype tree. `seed` picks its height, lean, frond count and every
|
|
266
|
+
* jitter inside it, so the same seed is byte-identical on every reload.
|
|
267
|
+
*/
|
|
268
|
+
function buildPalm(seed: number): PalmParts {
|
|
269
|
+
const rng = makeRandom(seed);
|
|
270
|
+
const height = 5.6 + rng() * 1.7;
|
|
271
|
+
const leanAngle = rng() * TAU;
|
|
272
|
+
const lean = 0.4 + rng() * 0.55;
|
|
273
|
+
const leanX = Math.cos(leanAngle) * lean;
|
|
274
|
+
const leanZ = Math.sin(leanAngle) * lean;
|
|
275
|
+
// A shallow S: the trunk kicks back before it leans out, which is what stops
|
|
276
|
+
// a "curved" trunk from reading as a bent pipe.
|
|
277
|
+
const spine = new CatmullRomCurve3([
|
|
278
|
+
new Vector3(0, -0.25, 0),
|
|
279
|
+
new Vector3(leanX * -0.14, height * 0.3, leanZ * -0.14),
|
|
280
|
+
new Vector3(leanX * 0.4, height * 0.68, leanZ * 0.4),
|
|
281
|
+
new Vector3(leanX, height, leanZ),
|
|
282
|
+
]);
|
|
283
|
+
|
|
284
|
+
const tangent = spine.getTangentAt(1).normalize();
|
|
285
|
+
const crown = new Matrix4().compose(
|
|
286
|
+
spine.getPointAt(1),
|
|
287
|
+
new Quaternion().setFromUnitVectors(UP, tangent),
|
|
288
|
+
new Vector3(1, 1, 1),
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
const trunk: BufferGeometry[] = [trunkGeometry(spine)];
|
|
292
|
+
// The crown boss: the fibrous knuckle every frond springs from. Without it
|
|
293
|
+
// the fronds visibly converge on a point and the crown floats.
|
|
294
|
+
const boss = blob(0.23, 8, 5);
|
|
295
|
+
boss.applyMatrix4(new Matrix4().makeScale(1, 0.72, 1));
|
|
296
|
+
trunk.push(placed(boss, 0, crown));
|
|
297
|
+
|
|
298
|
+
const live: BufferGeometry[] = [];
|
|
299
|
+
const fronds = 13 + Math.floor(rng() * 6);
|
|
300
|
+
for (let i = 0; i < fronds; i += 1) {
|
|
301
|
+
// Golden angle: an even fan looks stamped, and a random one clumps.
|
|
302
|
+
const azimuth = i * 2.39996 + rng() * 0.22;
|
|
303
|
+
const tier = i % 3;
|
|
304
|
+
// Value separation is what makes a crown read as foliage instead of as one
|
|
305
|
+
// green silhouette. The upright tier-0 fronds sit in each other's shade and
|
|
306
|
+
// stay deep green; the long tier-2 droopers take the sun and their tips
|
|
307
|
+
// bleach toward yellow. Red leads the bleach, blue lags — a flat brightness
|
|
308
|
+
// ramp would read as fog, not as sun damage. A per-frond jitter keeps
|
|
309
|
+
// neighbouring fronds from matching exactly.
|
|
310
|
+
const depth = tier === 0 ? 0.55 : tier === 1 ? 0.78 : 1.0;
|
|
311
|
+
const bleach = tier === 0 ? 0.98 : tier === 1 ? 1.14 : 1.34;
|
|
312
|
+
const jitter = 0.9 + rng() * 0.2;
|
|
313
|
+
const spec: FrondSpec = {
|
|
314
|
+
length: (tier === 0 ? 2.9 : tier === 1 ? 3.3 : 3.6) + rng() * 0.4,
|
|
315
|
+
width: 0.4 + rng() * 0.09,
|
|
316
|
+
rise: tier === 0 ? 0.95 : tier === 1 ? 0.55 : 0.2,
|
|
317
|
+
droop: tier === 0 ? -0.5 : tier === 1 ? -1.15 : -1.8,
|
|
318
|
+
curl: (rng() - 0.5) * 0.5,
|
|
319
|
+
// Twenty leaflets a side. Ten read as a coarse zigzag; the reference
|
|
320
|
+
// frond is a feather, and leaflet count is what separates the two.
|
|
321
|
+
segments: LEAFLETS_PER_SIDE,
|
|
322
|
+
shade: [0.58 * depth * jitter, 0.66 * depth * jitter, 0.44 * depth * jitter],
|
|
323
|
+
tip: [1.22 * bleach * jitter * 1.06, 1.16 * bleach * jitter, 0.78 * bleach * jitter * 0.88],
|
|
324
|
+
};
|
|
325
|
+
live.push(placed(frondGeometry(spec, rng), azimuth, crown));
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Dead fronds hang against the trunk under the live crown — the single
|
|
329
|
+
// cheapest detail that says "date palm" rather than "green thing on a pole".
|
|
330
|
+
const dead: BufferGeometry[] = [];
|
|
331
|
+
const skirt = new Matrix4().compose(
|
|
332
|
+
spine.getPointAt(0.985),
|
|
333
|
+
new Quaternion().setFromUnitVectors(UP, tangent),
|
|
334
|
+
new Vector3(1, 1, 1),
|
|
335
|
+
);
|
|
336
|
+
const deadCount = 4 + Math.floor(rng() * 3);
|
|
337
|
+
for (let i = 0; i < deadCount; i += 1) {
|
|
338
|
+
const spec: FrondSpec = {
|
|
339
|
+
length: 1.3 + rng() * 0.7,
|
|
340
|
+
width: 0.22 + rng() * 0.07,
|
|
341
|
+
rise: -0.25 - rng() * 0.3,
|
|
342
|
+
droop: -2.1 - rng() * 0.25,
|
|
343
|
+
curl: (rng() - 0.5) * 0.35,
|
|
344
|
+
segments: 8,
|
|
345
|
+
shade: [0.62, 0.55, 0.42],
|
|
346
|
+
tip: [1.05, 0.95, 0.7],
|
|
347
|
+
};
|
|
348
|
+
dead.push(placed(frondGeometry(spec, rng), i * 2.39996 + 0.8, skirt));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Date bunches: a stalk of four blobs sagging out of the crown.
|
|
352
|
+
const fruit: BufferGeometry[] = [];
|
|
353
|
+
const bunches = 2 + Math.floor(rng() * 2);
|
|
354
|
+
for (let i = 0; i < bunches; i += 1) {
|
|
355
|
+
for (let b = 0; b < 4; b += 1) {
|
|
356
|
+
const drop = b / 3;
|
|
357
|
+
const berry = blob(0.095 - drop * 0.03, 5, 3);
|
|
358
|
+
berry.applyMatrix4(
|
|
359
|
+
new Matrix4().makeTranslation(
|
|
360
|
+
0.42 + drop * 0.34,
|
|
361
|
+
-0.18 - drop * 0.5 - rng() * 0.08,
|
|
362
|
+
(rng() - 0.5) * 0.14,
|
|
363
|
+
),
|
|
364
|
+
);
|
|
365
|
+
fruit.push(placed(berry, i * 2.1 + 0.5 + rng() * 0.2, crown));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const merge = (parts: BufferGeometry[]): BufferGeometry => {
|
|
370
|
+
const merged = mergeGeometries(parts, false);
|
|
371
|
+
if (merged === null) throw new Error("Palm geometry failed to merge.");
|
|
372
|
+
merged.computeVertexNormals();
|
|
373
|
+
// One metre of grid, in the tree's own frame — the prototypes are authored at metre
|
|
374
|
+
// scale, so this is the same tile the walls and the street get.
|
|
375
|
+
return worldGridUVs(merged);
|
|
376
|
+
};
|
|
377
|
+
return { trunk: merge(trunk), live: merge(live), dead: merge(dead), fruit: merge(fruit) };
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* A recoloured copy of a town material.
|
|
382
|
+
*
|
|
383
|
+
* Dead fronds and dates want their own colour, and every part wants vertex
|
|
384
|
+
* colours switched on. These four belong in `townMaterials.ts` beside
|
|
385
|
+
* `palmTrunk` and `frond`; they are derived here so this file owns no
|
|
386
|
+
* material the town has not already declared.
|
|
387
|
+
*/
|
|
388
|
+
function derive(source: Material, hex: number | undefined): Material {
|
|
389
|
+
const clone = source.clone();
|
|
390
|
+
if (clone instanceof MeshStandardMaterial) {
|
|
391
|
+
clone.vertexColors = true;
|
|
392
|
+
if (hex !== undefined) clone.color.setHex(hex);
|
|
393
|
+
}
|
|
394
|
+
return clone;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Build every palm in the town.
|
|
399
|
+
*
|
|
400
|
+
* Three prototypes are generated once and drawn through one `InstancedMesh`
|
|
401
|
+
* per prototype per material — twelve draw calls for the whole run of trees,
|
|
402
|
+
* whatever the placement table grows to.
|
|
403
|
+
*/
|
|
404
|
+
export function addPalms(
|
|
405
|
+
group: Group,
|
|
406
|
+
materials: PalmMaterials,
|
|
407
|
+
places: readonly PalmPlacement[],
|
|
408
|
+
): void {
|
|
409
|
+
if (places.length === 0) return;
|
|
410
|
+
const trunkMaterial = derive(materials.palmTrunk, undefined);
|
|
411
|
+
const frondMaterial = derive(materials.frond, undefined);
|
|
412
|
+
const deadMaterial = derive(materials.frond, 0x8b7440);
|
|
413
|
+
const fruitMaterial = derive(materials.palmTrunk, 0x8a5520);
|
|
414
|
+
|
|
415
|
+
const prototypes = [buildPalm(1301), buildPalm(2707), buildPalm(4211)];
|
|
416
|
+
const buckets: Matrix4[][] = prototypes.map(() => []);
|
|
417
|
+
const rng = makeRandom(90210);
|
|
418
|
+
const quaternion = new Quaternion();
|
|
419
|
+
const one = new Vector3(1, 1, 1);
|
|
420
|
+
places.forEach(([x, z], index) => {
|
|
421
|
+
// Round-robin the prototypes so no one tree dominates a plaza; the yaw and
|
|
422
|
+
// the size below are what stop the repeat from reading as a repeat.
|
|
423
|
+
const which = index % prototypes.length;
|
|
424
|
+
const spin = rng() * TAU;
|
|
425
|
+
const size = 0.88 + rng() * 0.16;
|
|
426
|
+
buckets[which]?.push(
|
|
427
|
+
new Matrix4().compose(
|
|
428
|
+
new Vector3(x, 0, z),
|
|
429
|
+
quaternion.setFromAxisAngle(UP, spin),
|
|
430
|
+
one.clone().multiplyScalar(size),
|
|
431
|
+
),
|
|
432
|
+
);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
prototypes.forEach((parts, index) => {
|
|
436
|
+
const matrices = buckets[index];
|
|
437
|
+
if (matrices === undefined || matrices.length === 0) return;
|
|
438
|
+
const layers: readonly (readonly [BufferGeometry, Material, string])[] = [
|
|
439
|
+
[parts.trunk, trunkMaterial, "palm-trunk"],
|
|
440
|
+
[parts.live, frondMaterial, "palm-frond"],
|
|
441
|
+
[parts.dead, deadMaterial, "palm-frond-dead"],
|
|
442
|
+
[parts.fruit, fruitMaterial, "palm-dates"],
|
|
443
|
+
];
|
|
444
|
+
for (const [geometry, material, name] of layers) {
|
|
445
|
+
const mesh = new InstancedMesh(geometry, material, matrices.length);
|
|
446
|
+
mesh.name = name;
|
|
447
|
+
matrices.forEach((matrix, slot) => mesh.setMatrixAt(slot, matrix));
|
|
448
|
+
mesh.instanceMatrix.needsUpdate = true;
|
|
449
|
+
mesh.castShadow = true;
|
|
450
|
+
mesh.receiveShadow = true;
|
|
451
|
+
mesh.computeBoundingSphere();
|
|
452
|
+
group.add(mesh);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BufferGeometry,
|
|
3
|
+
Mesh,
|
|
4
|
+
type MeshBasicMaterial,
|
|
5
|
+
type Object3D,
|
|
6
|
+
PlaneGeometry,
|
|
7
|
+
Vector3,
|
|
8
|
+
} from "three";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* One pooled billboard-decay mechanism for the effects that are "a card that drifts,
|
|
12
|
+
* grows and fades": muzzle smoke here, enemy smoke in the scene. Pooling, lifetime,
|
|
13
|
+
* billboarding and dispatch live here once; texture, colour, size curve and timing come
|
|
14
|
+
* from each caller, so an effect can change its look completely without editing this
|
|
15
|
+
* file. Velocity-stretched sparks, tumbling chips and roll-driven flash cards are NOT
|
|
16
|
+
* this shape and stay in their own systems.
|
|
17
|
+
*
|
|
18
|
+
* Every member sits in the scene from construction at zero opacity — revealing a hidden
|
|
19
|
+
* mesh on first use makes WebGPU build its pipeline mid-frame, the once-per-session hitch.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export interface IPooledBillboardsOptions {
|
|
23
|
+
/** Slots in the pool; spawns over the count recycle the oldest. */
|
|
24
|
+
readonly count: number;
|
|
25
|
+
/** Card geometry. Default is a 1×1 plane scaled per spawn. */
|
|
26
|
+
readonly geometry?: BufferGeometry;
|
|
27
|
+
/** Cloned per slot; set the look on the prototype, never on a live clone. */
|
|
28
|
+
readonly materialPrototype: MeshBasicMaterial;
|
|
29
|
+
readonly renderOrder?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IBillboardSpawn {
|
|
33
|
+
readonly at: Vector3;
|
|
34
|
+
/** Seconds from spawn to retirement. */
|
|
35
|
+
readonly life: number;
|
|
36
|
+
/** World-space metres per second, held for the whole life. */
|
|
37
|
+
readonly drift: Vector3;
|
|
38
|
+
readonly scaleFrom: number;
|
|
39
|
+
readonly scaleTo: number;
|
|
40
|
+
/** Opacity at birth; decays linearly to zero. */
|
|
41
|
+
readonly opacity: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface ISlot {
|
|
45
|
+
drift: Vector3;
|
|
46
|
+
life: number;
|
|
47
|
+
life0: number;
|
|
48
|
+
mesh: Mesh;
|
|
49
|
+
opacity0: number;
|
|
50
|
+
scaleFrom: number;
|
|
51
|
+
scaleTo: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const scratchScale = new Vector3();
|
|
55
|
+
|
|
56
|
+
export class PooledBillboards {
|
|
57
|
+
readonly #slots: ISlot[];
|
|
58
|
+
#cursor = 0;
|
|
59
|
+
/** Dead slots stop being submitted once their pipeline exists. See `settle`. */
|
|
60
|
+
#settled = false;
|
|
61
|
+
|
|
62
|
+
constructor(
|
|
63
|
+
parent: Object3D,
|
|
64
|
+
{ count, geometry, materialPrototype, renderOrder }: IPooledBillboardsOptions,
|
|
65
|
+
) {
|
|
66
|
+
const card = geometry ?? new PlaneGeometry(1, 1);
|
|
67
|
+
this.#slots = Array.from({ length: count }, () => {
|
|
68
|
+
const mesh = new Mesh(card, materialPrototype.clone());
|
|
69
|
+
mesh.renderOrder = renderOrder ?? 0;
|
|
70
|
+
mesh.visible = true;
|
|
71
|
+
(mesh.material as MeshBasicMaterial).opacity = 0;
|
|
72
|
+
parent.add(mesh);
|
|
73
|
+
return {
|
|
74
|
+
drift: new Vector3(),
|
|
75
|
+
life: 0,
|
|
76
|
+
life0: 1,
|
|
77
|
+
mesh,
|
|
78
|
+
opacity0: 0,
|
|
79
|
+
scaleFrom: 1,
|
|
80
|
+
scaleTo: 1,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stop drawing the cards that are not alive.
|
|
87
|
+
*
|
|
88
|
+
* Same trade as the decal field: every slot is resident from frame one so its pipeline compiles
|
|
89
|
+
* during loading, and the cost is a draw call per dead card, every frame, forever. A phone pays
|
|
90
|
+
* for the call rather than the pixels, so parking an invisible quad is not free there the way it
|
|
91
|
+
* is on a desktop. Once compiled the pipeline is cached, so `spawn` re-showing a slot is free.
|
|
92
|
+
*/
|
|
93
|
+
settle(): void {
|
|
94
|
+
this.#settled = true;
|
|
95
|
+
for (const slot of this.#slots) {
|
|
96
|
+
if (slot.life <= 0) slot.mesh.visible = false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Birth one card on the next recycled slot. */
|
|
101
|
+
spawn({ at, life, drift, scaleFrom, scaleTo, opacity }: IBillboardSpawn): void {
|
|
102
|
+
const slot = this.#slots[this.#cursor % this.#slots.length];
|
|
103
|
+
this.#cursor += 1;
|
|
104
|
+
if (slot === undefined || life <= 0) return;
|
|
105
|
+
slot.life = life;
|
|
106
|
+
slot.life0 = life;
|
|
107
|
+
slot.drift.copy(drift);
|
|
108
|
+
slot.opacity0 = opacity;
|
|
109
|
+
slot.scaleFrom = scaleFrom;
|
|
110
|
+
slot.scaleTo = scaleTo;
|
|
111
|
+
slot.mesh.position.copy(at);
|
|
112
|
+
slot.mesh.scale.setScalar(scaleFrom);
|
|
113
|
+
slot.mesh.visible = true;
|
|
114
|
+
(slot.mesh.material as MeshBasicMaterial).opacity = opacity;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Advance every live card; `eye` is the point the billboards face. */
|
|
118
|
+
update(dt: number, eye: Vector3): void {
|
|
119
|
+
for (const slot of this.#slots) {
|
|
120
|
+
if (slot.life <= 0) continue;
|
|
121
|
+
slot.life -= dt;
|
|
122
|
+
const material = slot.mesh.material as MeshBasicMaterial;
|
|
123
|
+
if (slot.life <= 0) {
|
|
124
|
+
material.opacity = 0;
|
|
125
|
+
if (this.#settled) slot.mesh.visible = false;
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const age = 1 - slot.life / slot.life0;
|
|
129
|
+
slot.mesh.position.addScaledVector(slot.drift, dt);
|
|
130
|
+
slot.mesh.scale.copy(
|
|
131
|
+
scratchScale.setScalar(slot.scaleFrom + (slot.scaleTo - slot.scaleFrom) * age),
|
|
132
|
+
);
|
|
133
|
+
material.opacity = slot.opacity0 * (slot.life / slot.life0);
|
|
134
|
+
slot.mesh.lookAt(eye);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
dispose(): void {
|
|
139
|
+
for (const slot of this.#slots) {
|
|
140
|
+
slot.mesh.removeFromParent();
|
|
141
|
+
(slot.mesh.material as MeshBasicMaterial).dispose();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -22,13 +22,25 @@ export function setupPost(
|
|
|
22
22
|
environment: {
|
|
23
23
|
godraysLight?: DirectionalLight;
|
|
24
24
|
mobile?: boolean;
|
|
25
|
+
/** The renderer named a software adapter; this game's answer is its `low` tier. */
|
|
26
|
+
software?: boolean;
|
|
25
27
|
/** Forces a tier, ignoring `mobile`. An unknown name throws rather than falling back. */
|
|
26
28
|
tier?: QualityTier;
|
|
27
29
|
} = {},
|
|
28
30
|
): void {
|
|
29
|
-
const tier = resolveQualityTier({
|
|
31
|
+
const tier = resolveQualityTier({
|
|
32
|
+
mobile: environment.mobile,
|
|
33
|
+
software: environment.software,
|
|
34
|
+
tier: environment.tier,
|
|
35
|
+
});
|
|
30
36
|
const source = environment.tier === undefined ? "platform" : "override";
|
|
31
|
-
console.info(
|
|
37
|
+
console.info(
|
|
38
|
+
`TN_QUALITY_TIER ${tier} mobile=${environment.mobile === true} software=${
|
|
39
|
+
environment.software === true
|
|
40
|
+
} source=${source}`,
|
|
41
|
+
);
|
|
32
42
|
const world = new WorldEnvironment(qualityPreset(tier));
|
|
33
|
-
world.apply(renderer, scene, camera, {
|
|
43
|
+
world.apply(renderer, scene, camera, {
|
|
44
|
+
godraysLight: environment.godraysLight,
|
|
45
|
+
});
|
|
34
46
|
}
|