create-threenative 0.2.6 → 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 +2 -2
- package/agent-docs/references/build-profiles.md +126 -0
- package/agent-docs/references/capability-reference.md +431 -20
- package/agent-docs/references/performance-basics.md +8 -5
- 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-files/.agents/skills/file-engine-bug/SKILL.md +15 -4
- package/agent-files/.agents/skills/threenative-assets/SKILL.md +5 -5
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-context/SKILL.md +1 -1
- package/agent-files/.agents/skills/threenative-performance/SKILL.md +3 -3
- 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/capabilities.json +555 -21
- package/dist/index.d.ts +30 -1
- package/dist/index.js +294 -55
- package/dist/threenative.js +714 -154
- 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 +2101 -138
- package/template-assets/worldEnvironment.ts +52 -1
- package/templates/action-rpg/AGENTS.md +42 -42
- package/templates/action-rpg/CLAUDE.md +42 -42
- package/templates/action-rpg/kit.json +1 -1
- package/templates/action-rpg/package.json +13 -7
- 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 +10 -10
- package/templates/minimal/CLAUDE.md +10 -10
- package/templates/minimal/package.json +12 -6
- 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 +14 -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 +13 -9
- 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 +19 -20
- package/templates/puzzle/CLAUDE.md +19 -20
- 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 +13 -7
- 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 +19 -20
- package/templates/racing/CLAUDE.md +19 -20
- package/templates/racing/package.json +13 -7
- 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 +13 -7
- 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 +6 -10
- package/templates/runner/CLAUDE.md +6 -10
- package/templates/runner/README.md +3 -3
- package/templates/runner/package.json +13 -7
- 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 +12 -12
- package/templates/sailing/CLAUDE.md +12 -12
- package/templates/sailing/assets/ship.glb +0 -0
- package/templates/sailing/package.json +13 -7
- 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 +27 -42
- package/templates/shooter/CLAUDE.md +27 -42
- package/templates/shooter/index.html +1 -0
- package/templates/shooter/package.json +13 -7
- 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 +17 -17
- package/templates/starter/CLAUDE.md +17 -17
- package/templates/starter/native-playtests/render-chain.playtest.json +13 -45
- package/templates/starter/package.json +13 -7
- package/templates/starter/playtests/play.playtest.json +2 -1
- 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/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 +14 -12
- package/templates/{defense → tower-defense}/CLAUDE.md +14 -12
- 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/ponytail/SKILL.md +0 -68
- package/agent-files/.claude/skills/prd-creator/SKILL.md +0 -40
- package/agent-files/.claude/skills/threenative-assets/SKILL.md +0 -53
- package/agent-files/.claude/skills/threenative-capabilities/SKILL.md +0 -27
- package/agent-files/.claude/skills/threenative-context/SKILL.md +0 -65
- package/agent-files/.claude/skills/threenative-performance/SKILL.md +0 -58
- 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/restart.playtest.json +0 -91
- 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,741 @@
|
|
|
1
|
+
// The two vehicles Bayview needs and no CC0 catalogue has: the yellow panel
|
|
2
|
+
// van parked in T MAIN and the open fishing boat moored at the B-site pier.
|
|
3
|
+
//
|
|
4
|
+
// ## Why these are written rather than downloaded
|
|
5
|
+
//
|
|
6
|
+
// Poly Haven's entire Watercraft category is four colonial sailing ships
|
|
7
|
+
// (69k-184k triangles) plus three buoys — a galleon at a modern industrial pier
|
|
8
|
+
// is worse than an empty berth. Its whole road-vehicle catalogue is one car
|
|
9
|
+
// under a dust cover, which reads as an abandoned garage, not a working street.
|
|
10
|
+
// ambientCG's 3D catalogue is 34 items and they are all food. So both props are
|
|
11
|
+
// sculpted here from `shapes.ts` primitives against the reference frames.
|
|
12
|
+
//
|
|
13
|
+
// ## Constraints this file respects
|
|
14
|
+
//
|
|
15
|
+
// * `CanvasTexture` samples BLACK under `WebGPURenderer`. Nothing here paints
|
|
16
|
+
// a canvas; every surface is a flat-coloured `MeshStandardMaterial` derived
|
|
17
|
+
// by cloning one the town already owns, and the variety comes from having
|
|
18
|
+
// eight of them rather than from a bitmap.
|
|
19
|
+
// * `flatShading` is never set, because `roundedBox` welds its seams so
|
|
20
|
+
// normals interpolate across them and the two fight.
|
|
21
|
+
// * Every geometry is built ONCE per prop and merged per material, so the van
|
|
22
|
+
// costs eight draw calls and the boat seven however many are placed.
|
|
23
|
+
// * The van is a solid: one simple box collider on the BODY only. Mirrors,
|
|
24
|
+
// bumpers and the number plate are outside it on purpose — a player must
|
|
25
|
+
// never snag on a wing mirror. The boat floats past the playable deck and
|
|
26
|
+
// carries no collider at all.
|
|
27
|
+
//
|
|
28
|
+
// ## The boat's idle
|
|
29
|
+
//
|
|
30
|
+
// A hull sitting perfectly still on the sea reads as welded to the water plane,
|
|
31
|
+
// so the boat heaves, rolls and pitches on three incommensurate sine periods.
|
|
32
|
+
// That is a continuous idle, which `ctx.tween` is the wrong tool for (tween is
|
|
33
|
+
// for things that start, run once and finish) — and this file is handed no
|
|
34
|
+
// frame callback, so the boat drives itself by overriding `updateMatrixWorld`,
|
|
35
|
+
// which the renderer already calls on the whole graph every frame.
|
|
36
|
+
import {
|
|
37
|
+
BoxGeometry,
|
|
38
|
+
BufferGeometry,
|
|
39
|
+
CylinderGeometry,
|
|
40
|
+
DoubleSide,
|
|
41
|
+
Euler,
|
|
42
|
+
Float32BufferAttribute,
|
|
43
|
+
Group,
|
|
44
|
+
type Material,
|
|
45
|
+
MathUtils,
|
|
46
|
+
Matrix4,
|
|
47
|
+
Mesh,
|
|
48
|
+
MeshStandardMaterial,
|
|
49
|
+
Object3D,
|
|
50
|
+
Quaternion,
|
|
51
|
+
TorusGeometry,
|
|
52
|
+
Vector3,
|
|
53
|
+
} from "three";
|
|
54
|
+
import { mergeGeometries } from "three/addons/utils/BufferGeometryUtils.js";
|
|
55
|
+
import { worldGridUVs } from "./materials.js";
|
|
56
|
+
import { roundedBox } from "./shapes.js";
|
|
57
|
+
import type { TownMaterials } from "./townMaterials.js";
|
|
58
|
+
|
|
59
|
+
/** Structurally identical to `TownCollider`; declared here to avoid a cycle. */
|
|
60
|
+
export type PropCollider = {
|
|
61
|
+
readonly min: readonly [number, number, number];
|
|
62
|
+
readonly max: readonly [number, number, number];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type VanPlacement = {
|
|
66
|
+
readonly x: number;
|
|
67
|
+
readonly z: number;
|
|
68
|
+
/** Yaw in radians; the van's nose is local +x, so −π/2 points it at +z. */
|
|
69
|
+
readonly yaw: number;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type BoatPlacement = {
|
|
73
|
+
readonly x: number;
|
|
74
|
+
readonly z: number;
|
|
75
|
+
readonly yaw: number;
|
|
76
|
+
/** World Y of the sea surface the hull floats on. */
|
|
77
|
+
readonly waterY: number;
|
|
78
|
+
/** Optional pier post to run a painter line to, as [x, y, z]. */
|
|
79
|
+
readonly moorTo?: readonly [number, number, number];
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Batching: one merged mesh per material, per prop
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
const ONE = new Vector3(1, 1, 1);
|
|
87
|
+
|
|
88
|
+
/** A transform for a part, authored in the prop's own local frame. */
|
|
89
|
+
function place(x: number, y: number, z: number, rx = 0, ry = 0, rz = 0): Matrix4 {
|
|
90
|
+
return new Matrix4().compose(
|
|
91
|
+
new Vector3(x, y, z),
|
|
92
|
+
new Quaternion().setFromEuler(new Euler(rx, ry, rz)),
|
|
93
|
+
ONE,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Merging demands identical attribute sets and the sources disagree —
|
|
99
|
+
* `roundedBox` deletes its UVs, the lofted hull strips never had any. Bring
|
|
100
|
+
* everything to one shape before it enters a bucket; the zero UVs are harmless
|
|
101
|
+
* because no material in this file reads a map.
|
|
102
|
+
*/
|
|
103
|
+
function normalised(source: BufferGeometry): BufferGeometry {
|
|
104
|
+
const geometry = source.clone();
|
|
105
|
+
if (!geometry.hasAttribute("uv")) {
|
|
106
|
+
const count = geometry.getAttribute("position").count;
|
|
107
|
+
geometry.setAttribute("uv", new Float32BufferAttribute(new Float32Array(count * 2), 2));
|
|
108
|
+
}
|
|
109
|
+
return geometry.index === null ? geometry : geometry.toNonIndexed();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class PartBatch {
|
|
113
|
+
readonly #buckets = new Map<Material, BufferGeometry[]>();
|
|
114
|
+
|
|
115
|
+
add(material: Material, geometry: BufferGeometry, matrix?: Matrix4): void {
|
|
116
|
+
const part = normalised(geometry);
|
|
117
|
+
if (matrix !== undefined) part.applyMatrix4(matrix);
|
|
118
|
+
const bucket = this.#buckets.get(material);
|
|
119
|
+
if (bucket === undefined) this.#buckets.set(material, [part]);
|
|
120
|
+
else bucket.push(part);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Mirror a part to the other side of the hull / the other flank of the van. */
|
|
124
|
+
addMirrored(material: Material, geometry: BufferGeometry, matrix: Matrix4): void {
|
|
125
|
+
this.add(material, geometry, matrix);
|
|
126
|
+
this.add(material, geometry, new Matrix4().makeScale(1, 1, -1).multiply(matrix));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
flush(group: Group, name: string, castShadow: boolean): Mesh[] {
|
|
130
|
+
const meshes: Mesh[] = [];
|
|
131
|
+
for (const [material, geometries] of this.#buckets) {
|
|
132
|
+
if (geometries.length === 0) continue;
|
|
133
|
+
// World-projected grid: the parts are already placed in the prop's own space, so this
|
|
134
|
+
// is one metre per tile on the van's flank exactly as it is on the wall behind it.
|
|
135
|
+
const geometry = worldGridUVs(mergeGeometries(geometries, false));
|
|
136
|
+
for (const source of geometries) source.dispose();
|
|
137
|
+
const mesh = new Mesh(geometry, material);
|
|
138
|
+
mesh.name = name;
|
|
139
|
+
mesh.castShadow = castShadow;
|
|
140
|
+
mesh.receiveShadow = true;
|
|
141
|
+
group.add(mesh);
|
|
142
|
+
meshes.push(mesh);
|
|
143
|
+
}
|
|
144
|
+
this.#buckets.clear();
|
|
145
|
+
return meshes;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
// Derived materials
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Painted steel, glass, rubber and varnished timber, all cloned off surfaces
|
|
155
|
+
* the town already owns so tone mapping and lighting stay consistent with it.
|
|
156
|
+
*
|
|
157
|
+
* These live here rather than in `townMaterials.ts` deliberately: that file
|
|
158
|
+
* builds every surface from a triplanar node graph whose tint is baked into the
|
|
159
|
+
* shader, so a `.clone()` of one cannot be re-coloured from this side. The
|
|
160
|
+
* plain `steel` material is the one honest base to derive flat paint from.
|
|
161
|
+
*/
|
|
162
|
+
type VehicleMaterials = {
|
|
163
|
+
readonly paint: Material;
|
|
164
|
+
readonly paintShade: Material;
|
|
165
|
+
readonly glass: Material;
|
|
166
|
+
readonly rubber: Material;
|
|
167
|
+
readonly trimDark: Material;
|
|
168
|
+
readonly trimGrey: Material;
|
|
169
|
+
readonly chrome: Material;
|
|
170
|
+
readonly lens: Material;
|
|
171
|
+
readonly pale: Material;
|
|
172
|
+
readonly hullWhite: Material;
|
|
173
|
+
readonly hullDark: Material;
|
|
174
|
+
readonly interior: Material;
|
|
175
|
+
readonly rope: Material;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** Clone a town material and repaint it, falling back if it is not a standard one. */
|
|
179
|
+
function tint(
|
|
180
|
+
source: Material,
|
|
181
|
+
colour: number,
|
|
182
|
+
roughness: number,
|
|
183
|
+
metalness: number,
|
|
184
|
+
doubleSided = false,
|
|
185
|
+
): MeshStandardMaterial {
|
|
186
|
+
const clone = source.clone();
|
|
187
|
+
const material =
|
|
188
|
+
clone instanceof MeshStandardMaterial
|
|
189
|
+
? clone
|
|
190
|
+
: new MeshStandardMaterial({ color: colour, roughness, metalness });
|
|
191
|
+
if (material !== clone) clone.dispose();
|
|
192
|
+
material.color.setHex(colour);
|
|
193
|
+
material.roughness = roughness;
|
|
194
|
+
material.metalness = metalness;
|
|
195
|
+
// The lofted hull is an open shell seen from inside and out. DoubleSide keeps
|
|
196
|
+
// it solid from every angle and lets the shader flip the normal on backfaces,
|
|
197
|
+
// so a wrong-handed strip can never come out lit inside-out.
|
|
198
|
+
if (doubleSided) material.side = DoubleSide;
|
|
199
|
+
return material;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const CACHE = new WeakMap<TownMaterials, VehicleMaterials>();
|
|
203
|
+
|
|
204
|
+
function vehicleMaterials(town: TownMaterials): VehicleMaterials {
|
|
205
|
+
const cached = CACHE.get(town);
|
|
206
|
+
if (cached !== undefined) return cached;
|
|
207
|
+
const steel = town.steel;
|
|
208
|
+
const made: VehicleMaterials = {
|
|
209
|
+
// Reference paint is a warm ochre yellow gone slightly chalky in the sun,
|
|
210
|
+
// not a saturated taxi yellow.
|
|
211
|
+
paint: tint(steel, 0xd2a343, 0.46, 0.2),
|
|
212
|
+
paintShade: tint(steel, 0xb08733, 0.52, 0.18),
|
|
213
|
+
glass: tint(steel, 0x171b20, 0.12, 0.16),
|
|
214
|
+
rubber: tint(steel, 0x1a1a1a, 0.94, 0.0),
|
|
215
|
+
trimDark: tint(steel, 0x33363a, 0.62, 0.24),
|
|
216
|
+
trimGrey: tint(steel, 0x8c8c88, 0.62, 0.2),
|
|
217
|
+
chrome: tint(steel, 0xc7cbd0, 0.26, 0.86),
|
|
218
|
+
lens: tint(steel, 0xd5802b, 0.3, 0.12),
|
|
219
|
+
pale: tint(steel, 0xdedad2, 0.44, 0.1),
|
|
220
|
+
hullWhite: tint(steel, 0xdcd6c9, 0.74, 0.02, true),
|
|
221
|
+
hullDark: tint(steel, 0x2f3338, 0.66, 0.06, true),
|
|
222
|
+
interior: tint(steel, 0xa5a598, 0.86, 0.02, true),
|
|
223
|
+
rope: tint(steel, 0xb5a381, 0.95, 0.0),
|
|
224
|
+
};
|
|
225
|
+
CACHE.set(town, made);
|
|
226
|
+
return made;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// The van
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Every dimension the silhouette depends on, in metres. A van is recognised
|
|
235
|
+
* from its outline, and the give-aways are the flat slab side, the tall boxy
|
|
236
|
+
* rear and a roof at 2.2 m — just above a 1.78 m soldier's head.
|
|
237
|
+
*/
|
|
238
|
+
const VAN = {
|
|
239
|
+
nose: 2.18,
|
|
240
|
+
tail: -2.18,
|
|
241
|
+
bumper: 2.3,
|
|
242
|
+
half: 0.95,
|
|
243
|
+
sill: 0.6,
|
|
244
|
+
waist: 1.02,
|
|
245
|
+
roof: 2.2,
|
|
246
|
+
bonnetTop: 1.3,
|
|
247
|
+
cabFront: 1.72,
|
|
248
|
+
frontAxle: 1.42,
|
|
249
|
+
rearAxle: -1.48,
|
|
250
|
+
tyreRadius: 0.33,
|
|
251
|
+
tyreWidth: 0.21,
|
|
252
|
+
track: 0.8,
|
|
253
|
+
archRadius: 0.48,
|
|
254
|
+
archCentre: 0.58,
|
|
255
|
+
/** Half-width including the wing mirrors — outside the collider on purpose. */
|
|
256
|
+
halfWithMirrors: 1.14,
|
|
257
|
+
} as const;
|
|
258
|
+
|
|
259
|
+
function vanParts(batch: PartBatch, m: VehicleMaterials): void {
|
|
260
|
+
const sideZ = VAN.half + 0.008;
|
|
261
|
+
|
|
262
|
+
// Upper body: one slab from the tail to the windscreen base, carrying the
|
|
263
|
+
// roof. Radius 0.10 — real body panels are all softly radiused, and a sharp
|
|
264
|
+
// box here is the single thing that makes a vehicle read as Minecraft.
|
|
265
|
+
batch.add(
|
|
266
|
+
m.paint,
|
|
267
|
+
roundedBox(VAN.cabFront - VAN.tail, VAN.roof - VAN.waist, VAN.half * 2, 0.1),
|
|
268
|
+
place((VAN.tail + VAN.cabFront) / 2, (VAN.waist + VAN.roof) / 2, 0),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
// Sill band, broken into three so the wheel arches are real gaps in the slab
|
|
272
|
+
// side rather than a decal over it.
|
|
273
|
+
const archFront: readonly [number, number] = [
|
|
274
|
+
VAN.frontAxle - VAN.archRadius,
|
|
275
|
+
VAN.frontAxle + VAN.archRadius,
|
|
276
|
+
];
|
|
277
|
+
const archRear: readonly [number, number] = [
|
|
278
|
+
VAN.rearAxle - VAN.archRadius,
|
|
279
|
+
VAN.rearAxle + VAN.archRadius,
|
|
280
|
+
];
|
|
281
|
+
const sills: readonly (readonly [number, number])[] = [
|
|
282
|
+
[VAN.tail, archRear[0]],
|
|
283
|
+
[archRear[1], archFront[0]],
|
|
284
|
+
[archFront[1], VAN.nose],
|
|
285
|
+
];
|
|
286
|
+
for (const [x0, x1] of sills) {
|
|
287
|
+
batch.add(
|
|
288
|
+
m.paint,
|
|
289
|
+
roundedBox(x1 - x0, VAN.waist - VAN.sill, VAN.half * 2, 0.06),
|
|
290
|
+
place((x0 + x1) / 2, (VAN.sill + VAN.waist) / 2, 0),
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Short bonnet ahead of the windscreen, topping out well below the roof.
|
|
295
|
+
batch.add(
|
|
296
|
+
m.paint,
|
|
297
|
+
roundedBox(VAN.nose - VAN.cabFront, VAN.bonnetTop - VAN.waist, 1.86, 0.08),
|
|
298
|
+
place((VAN.cabFront + VAN.nose) / 2, (VAN.waist + VAN.bonnetTop) / 2, 0),
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
// Dark chassis mass behind the wheels: this is what you see through the arch
|
|
302
|
+
// gaps, and it is what gives the van a shadow to sit in rather than on.
|
|
303
|
+
batch.add(m.trimDark, new BoxGeometry(4.1, 0.74, 1.48), place(0, 0.65, 0));
|
|
304
|
+
|
|
305
|
+
// Running gear: one tyre and one hub geometry, reused at four transforms.
|
|
306
|
+
const tyre = new CylinderGeometry(VAN.tyreRadius, VAN.tyreRadius, VAN.tyreWidth, 16);
|
|
307
|
+
const hub = new CylinderGeometry(0.195, 0.195, 0.04, 12);
|
|
308
|
+
const arch = new TorusGeometry(VAN.archRadius, 0.042, 5, 14, Math.PI);
|
|
309
|
+
for (const axle of [VAN.frontAxle, VAN.rearAxle]) {
|
|
310
|
+
batch.addMirrored(m.rubber, tyre, place(axle, VAN.tyreRadius, VAN.track, Math.PI / 2));
|
|
311
|
+
batch.addMirrored(m.trimGrey, hub, place(axle, VAN.tyreRadius, 0.912, Math.PI / 2));
|
|
312
|
+
// Flared arch lip: the outline break that stops the side reading as a slab.
|
|
313
|
+
batch.addMirrored(m.paint, arch, place(axle, VAN.archCentre, VAN.half + 0.005));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Glazing: dark plates proud of the body, the same trick the town's doors and
|
|
317
|
+
// shutters use. The windscreen is raked 11° so its head sits back under the
|
|
318
|
+
// roof header and its base overhangs the bonnet.
|
|
319
|
+
batch.add(m.glass, new BoxGeometry(0.05, 0.76, 1.74), place(1.79, 1.74, 0, 0, 0, 0.2));
|
|
320
|
+
batch.add(m.trimDark, new BoxGeometry(0.2, 0.12, 1.8), place(1.86, 1.34, 0));
|
|
321
|
+
batch.addMirrored(m.glass, new BoxGeometry(0.84, 0.56, 0.04), place(1.2, 1.76, sideZ));
|
|
322
|
+
batch.addMirrored(m.glass, new BoxGeometry(0.6, 0.42, 0.04), place(0.21, 1.78, sideZ));
|
|
323
|
+
batch.addMirrored(m.glass, new BoxGeometry(0.04, 0.4, 0.62), place(-2.19, 1.82, 0.38));
|
|
324
|
+
|
|
325
|
+
// Creases: the shoulder swage under the glass line and a dark rub strip over
|
|
326
|
+
// the sill. Two long horizontals are most of what says "panel van" in profile.
|
|
327
|
+
batch.addMirrored(
|
|
328
|
+
m.paintShade,
|
|
329
|
+
new BoxGeometry(3.86, 0.05, 0.02),
|
|
330
|
+
place(-0.23, 1.46, sideZ + 0.004),
|
|
331
|
+
);
|
|
332
|
+
batch.addMirrored(
|
|
333
|
+
m.trimDark,
|
|
334
|
+
new BoxGeometry(3.86, 0.08, 0.03),
|
|
335
|
+
place(-0.23, 1.18, sideZ + 0.006),
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
// Sliding door: leading and trailing shut lines plus the upper track it rides.
|
|
339
|
+
for (const x of [-0.32, 0.74]) {
|
|
340
|
+
batch.addMirrored(
|
|
341
|
+
m.trimDark,
|
|
342
|
+
new BoxGeometry(0.035, 1.14, 0.025),
|
|
343
|
+
place(x, 1.61, sideZ + 0.006),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
batch.addMirrored(
|
|
347
|
+
m.trimDark,
|
|
348
|
+
new BoxGeometry(1.85, 0.05, 0.025),
|
|
349
|
+
place(0.12, 2.06, sideZ + 0.006),
|
|
350
|
+
);
|
|
351
|
+
batch.addMirrored(
|
|
352
|
+
m.trimDark,
|
|
353
|
+
new BoxGeometry(3.86, 0.05, 0.055),
|
|
354
|
+
place(-0.23, 2.14, VAN.half - 0.005),
|
|
355
|
+
);
|
|
356
|
+
for (const x of [0.8, -0.24]) {
|
|
357
|
+
batch.addMirrored(m.chrome, new BoxGeometry(0.03, 0.05, 0.14), place(x, 1.36, sideZ + 0.01));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Twin rear doors: a vertical split down the tail and two hinges per leaf.
|
|
361
|
+
batch.add(m.trimDark, new BoxGeometry(0.03, 1.14, 0.04), place(-2.19, 1.61, 0));
|
|
362
|
+
for (const y of [1.18, 2.02]) {
|
|
363
|
+
batch.addMirrored(m.trimDark, new BoxGeometry(0.06, 0.08, 0.1), place(-2.2, y, 0.84));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Face: recessed grille, rectangular lamps, amber indicators, low bumper,
|
|
367
|
+
// number plate. None of it is in the collider.
|
|
368
|
+
batch.add(m.trimDark, new BoxGeometry(0.05, 0.28, 1.1), place(2.185, 1.06, 0));
|
|
369
|
+
const slat = new BoxGeometry(0.06, 0.022, 1.04);
|
|
370
|
+
for (const y of [0.97, 1.04, 1.11, 1.18]) batch.add(m.chrome, slat, place(2.2, y, 0));
|
|
371
|
+
batch.addMirrored(m.pale, new BoxGeometry(0.05, 0.18, 0.3), place(2.19, 1.1, 0.7));
|
|
372
|
+
batch.addMirrored(m.lens, new BoxGeometry(0.05, 0.12, 0.11), place(2.19, 1.1, 0.865));
|
|
373
|
+
const bumper = roundedBox(0.14, 0.22, 1.88, 0.05);
|
|
374
|
+
batch.add(m.trimGrey, bumper, place(2.23, 0.6, 0));
|
|
375
|
+
batch.add(m.trimGrey, bumper, place(-2.23, 0.6, 0));
|
|
376
|
+
const plate = new BoxGeometry(0.03, 0.11, 0.5);
|
|
377
|
+
batch.add(m.pale, plate, place(2.305, 0.62, 0));
|
|
378
|
+
batch.add(m.pale, plate, place(-2.305, 0.62, 0));
|
|
379
|
+
|
|
380
|
+
// Wing mirrors on stalks. They stand outside the collider so nobody snags on
|
|
381
|
+
// one, and they are the thing that breaks the roof-to-bonnet line.
|
|
382
|
+
batch.addMirrored(
|
|
383
|
+
m.trimDark,
|
|
384
|
+
new CylinderGeometry(0.022, 0.022, 0.14, 6),
|
|
385
|
+
place(1.6, 1.74, 0.99, Math.PI / 2),
|
|
386
|
+
);
|
|
387
|
+
batch.addMirrored(m.trimDark, new BoxGeometry(0.05, 0.24, 0.12), place(1.62, 1.76, 1.08));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Place a van. Returns its collider: one axis-aligned box around the BODY, not
|
|
392
|
+
* around the mirrors or the bumpers — a bullet stops on the van and a player
|
|
393
|
+
* can hide behind it, but nothing sticks out of the shape they can feel.
|
|
394
|
+
*/
|
|
395
|
+
export function addVan(
|
|
396
|
+
group: Group,
|
|
397
|
+
hittable: Mesh[],
|
|
398
|
+
materials: TownMaterials,
|
|
399
|
+
at: VanPlacement,
|
|
400
|
+
): PropCollider {
|
|
401
|
+
const m = vehicleMaterials(materials);
|
|
402
|
+
const van = new Group();
|
|
403
|
+
van.name = "van";
|
|
404
|
+
const batch = new PartBatch();
|
|
405
|
+
vanParts(batch, m);
|
|
406
|
+
hittable.push(...batch.flush(van, "van", true));
|
|
407
|
+
van.position.set(at.x, 0, at.z);
|
|
408
|
+
van.rotation.y = at.yaw;
|
|
409
|
+
group.add(van);
|
|
410
|
+
|
|
411
|
+
const cos = Math.abs(Math.cos(at.yaw));
|
|
412
|
+
const sin = Math.abs(Math.sin(at.yaw));
|
|
413
|
+
const halfX = (VAN.bumper - VAN.tail) / 2;
|
|
414
|
+
const spanX = halfX * cos + VAN.half * sin;
|
|
415
|
+
const spanZ = halfX * sin + VAN.half * cos;
|
|
416
|
+
return {
|
|
417
|
+
min: [at.x - spanX, 0, at.z - spanZ],
|
|
418
|
+
max: [at.x + spanX, VAN.roof, at.z + spanZ],
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Footprint a placement table can be audited against without building anything. */
|
|
423
|
+
export function vanFootprint(at: VanPlacement): {
|
|
424
|
+
readonly minX: number;
|
|
425
|
+
readonly maxX: number;
|
|
426
|
+
readonly minZ: number;
|
|
427
|
+
readonly maxZ: number;
|
|
428
|
+
} {
|
|
429
|
+
const cos = Math.abs(Math.cos(at.yaw));
|
|
430
|
+
const sin = Math.abs(Math.sin(at.yaw));
|
|
431
|
+
const halfX = (VAN.bumper - VAN.tail) / 2;
|
|
432
|
+
const spanX = halfX * cos + VAN.halfWithMirrors * sin;
|
|
433
|
+
const spanZ = halfX * sin + VAN.halfWithMirrors * cos;
|
|
434
|
+
return { minX: at.x - spanX, maxX: at.x + spanX, minZ: at.z - spanZ, maxZ: at.z + spanZ };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// ---------------------------------------------------------------------------
|
|
438
|
+
// The fishing boat
|
|
439
|
+
// ---------------------------------------------------------------------------
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* A hull is a loft, not a box. Six plank courses are stacked between a rockered
|
|
443
|
+
* keel line and a sheer line that rises hard at the bow and again at the
|
|
444
|
+
* transom; each course keeps one radius over its whole height, so the step out
|
|
445
|
+
* to the next course is a real lapstrake ledge that catches the sun. That step
|
|
446
|
+
* is the clinker read, and it is why the courses are not blended smooth.
|
|
447
|
+
*/
|
|
448
|
+
const BOAT = {
|
|
449
|
+
halfLength: 2.25,
|
|
450
|
+
halfBeam: 0.8,
|
|
451
|
+
sheer: 0.46,
|
|
452
|
+
keel: -0.42,
|
|
453
|
+
stations: 22,
|
|
454
|
+
/** Aft cut: the hull stops short of the point and a transom board closes it. */
|
|
455
|
+
stern: -0.97,
|
|
456
|
+
} as const;
|
|
457
|
+
|
|
458
|
+
/** Fraction of the depth each course boundary sits at, keel (0) to sheer (1). */
|
|
459
|
+
const COURSE_Y = [0, 0.16, 0.34, 0.52, 0.7, 0.87, 1] as const;
|
|
460
|
+
/** Fraction of the beam each course boundary carries; the hull tucks to the keel. */
|
|
461
|
+
const COURSE_W = [0.1, 0.4, 0.66, 0.83, 0.93, 0.985, 1] as const;
|
|
462
|
+
|
|
463
|
+
const tableAt = (table: readonly number[], index: number): number => table[index] ?? 0;
|
|
464
|
+
|
|
465
|
+
/** Plan-form half-beam at station `u` ∈ [−1, 1]; +1 is the bow. */
|
|
466
|
+
function halfBeamAt(u: number): number {
|
|
467
|
+
if (u >= 0) return BOAT.halfBeam * Math.max(0, 1 - u * u * u) ** 0.55;
|
|
468
|
+
return BOAT.halfBeam * (1 - 0.3 * Math.min(1, -u) ** 2.6);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** Sheer line: higher at bow and stern than amidships. */
|
|
472
|
+
function sheerAt(u: number): number {
|
|
473
|
+
return BOAT.sheer + 0.24 * Math.max(0, u) ** 2.4 + 0.14 * Math.max(0, -u) ** 2.6;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/** Keel line, with rocker lifting both ends clear of the water. */
|
|
477
|
+
function keelAt(u: number): number {
|
|
478
|
+
return BOAT.keel + 0.34 * Math.abs(u) ** 2.8;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const courseY = (u: number, k: number): number =>
|
|
482
|
+
keelAt(u) + tableAt(COURSE_Y, k) * (sheerAt(u) - keelAt(u));
|
|
483
|
+
const courseR = (u: number, k: number): number => halfBeamAt(u) * tableAt(COURSE_W, k);
|
|
484
|
+
|
|
485
|
+
/** Station parameters from the transom to the stem, bow-dense so the point is clean. */
|
|
486
|
+
function stations(): number[] {
|
|
487
|
+
const out: number[] = [];
|
|
488
|
+
for (let index = 0; index <= BOAT.stations; index += 1) {
|
|
489
|
+
out.push(BOAT.stern + (1 - BOAT.stern) * (index / BOAT.stations));
|
|
490
|
+
}
|
|
491
|
+
return out;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* An indexed quad grid over rows × columns of points. `flip` reverses the
|
|
496
|
+
* winding for the port side, whose mirrored coordinates reverse handedness.
|
|
497
|
+
*/
|
|
498
|
+
function grid(rows: readonly (readonly Vector3[])[], flip: boolean): BufferGeometry {
|
|
499
|
+
const first = rows[0];
|
|
500
|
+
const cols = first === undefined ? 0 : first.length;
|
|
501
|
+
const positions: number[] = [];
|
|
502
|
+
const indices: number[] = [];
|
|
503
|
+
for (const row of rows) {
|
|
504
|
+
for (const point of row) positions.push(point.x, point.y, point.z);
|
|
505
|
+
}
|
|
506
|
+
for (let r = 0; r + 1 < rows.length; r += 1) {
|
|
507
|
+
for (let c = 0; c + 1 < cols; c += 1) {
|
|
508
|
+
const a = r * cols + c;
|
|
509
|
+
const b = r * cols + c + 1;
|
|
510
|
+
const d = (r + 1) * cols + c;
|
|
511
|
+
const e = (r + 1) * cols + c + 1;
|
|
512
|
+
if (flip) indices.push(a, d, b, b, d, e);
|
|
513
|
+
else indices.push(a, b, d, b, e, d);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
const geometry = new BufferGeometry();
|
|
517
|
+
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
|
518
|
+
geometry.setIndex(indices);
|
|
519
|
+
geometry.computeVertexNormals();
|
|
520
|
+
return geometry;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function hullParts(batch: PartBatch, m: VehicleMaterials): void {
|
|
524
|
+
const us = stations();
|
|
525
|
+
const x = (u: number): number => u * BOAT.halfLength;
|
|
526
|
+
// Dark antifouling on the courses that meet the water, white topsides above,
|
|
527
|
+
// one varnished sheer strake under the cap rail.
|
|
528
|
+
const skin = [m.hullDark, m.hullDark, m.hullDark, m.hullWhite, m.hullWhite, m.interior];
|
|
529
|
+
|
|
530
|
+
for (let k = 0; k < 6; k += 1) {
|
|
531
|
+
const material = skin[k] ?? m.hullWhite;
|
|
532
|
+
for (const side of [1, -1]) {
|
|
533
|
+
const flip = side < 0;
|
|
534
|
+
// Plank face: one radius over the whole course height.
|
|
535
|
+
batch.add(
|
|
536
|
+
material,
|
|
537
|
+
grid(
|
|
538
|
+
[
|
|
539
|
+
us.map((u) => new Vector3(x(u), courseY(u, k), side * courseR(u, k + 1))),
|
|
540
|
+
us.map((u) => new Vector3(x(u), courseY(u, k + 1), side * courseR(u, k + 1))),
|
|
541
|
+
],
|
|
542
|
+
flip,
|
|
543
|
+
),
|
|
544
|
+
);
|
|
545
|
+
// The lap: a horizontal ledge stepping out to this course from the last.
|
|
546
|
+
batch.add(
|
|
547
|
+
material,
|
|
548
|
+
grid(
|
|
549
|
+
[
|
|
550
|
+
us.map((u) => new Vector3(x(u), courseY(u, k), side * courseR(u, k))),
|
|
551
|
+
us.map((u) => new Vector3(x(u), courseY(u, k), side * courseR(u, k + 1))),
|
|
552
|
+
],
|
|
553
|
+
!flip,
|
|
554
|
+
),
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// Keel panel closing the bottom between the two garboard courses.
|
|
560
|
+
batch.add(
|
|
561
|
+
m.hullDark,
|
|
562
|
+
grid(
|
|
563
|
+
[
|
|
564
|
+
us.map((u) => new Vector3(x(u), courseY(u, 0), -courseR(u, 0))),
|
|
565
|
+
us.map((u) => new Vector3(x(u), courseY(u, 0), courseR(u, 0))),
|
|
566
|
+
],
|
|
567
|
+
false,
|
|
568
|
+
),
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
// Transom: a flat board across the aft section outline, raked slightly aft.
|
|
572
|
+
const aft = BOAT.stern;
|
|
573
|
+
batch.add(
|
|
574
|
+
m.hullWhite,
|
|
575
|
+
grid(
|
|
576
|
+
COURSE_Y.map((_, k) => [
|
|
577
|
+
new Vector3(x(aft) - 0.05, courseY(aft, k), -courseR(aft, k)),
|
|
578
|
+
new Vector3(x(aft) - 0.05, courseY(aft, k), courseR(aft, k)),
|
|
579
|
+
]),
|
|
580
|
+
false,
|
|
581
|
+
),
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
// Pale interior liner from the floor to just under the rail, wound inward so
|
|
585
|
+
// looking down from the pier shows a boat with an inside, not a shell.
|
|
586
|
+
const floor = (u: number): number => courseY(u, 2) + 0.02;
|
|
587
|
+
for (const side of [1, -1]) {
|
|
588
|
+
batch.add(
|
|
589
|
+
m.interior,
|
|
590
|
+
grid(
|
|
591
|
+
[
|
|
592
|
+
us.map((u) => new Vector3(x(u), floor(u), side * courseR(u, 3) * 0.96)),
|
|
593
|
+
us.map((u) => new Vector3(x(u), sheerAt(u) - 0.03, side * courseR(u, 6) * 0.95)),
|
|
594
|
+
],
|
|
595
|
+
side > 0,
|
|
596
|
+
),
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
batch.add(
|
|
600
|
+
m.interior,
|
|
601
|
+
grid(
|
|
602
|
+
[
|
|
603
|
+
us.map((u) => new Vector3(x(u), floor(u), -courseR(u, 3) * 0.96)),
|
|
604
|
+
us.map((u) => new Vector3(x(u), floor(u), courseR(u, 3) * 0.96)),
|
|
605
|
+
],
|
|
606
|
+
true,
|
|
607
|
+
),
|
|
608
|
+
);
|
|
609
|
+
|
|
610
|
+
// Varnished cap rail following the sheer all round: a top ribbon plus an
|
|
611
|
+
// outer and an inner face, so it reads as a real capping from any angle.
|
|
612
|
+
for (const side of [1, -1]) {
|
|
613
|
+
const flip = side < 0;
|
|
614
|
+
const outer = (u: number): number => side * (courseR(u, 6) + 0.035);
|
|
615
|
+
const inner = (u: number): number => side * (courseR(u, 6) - 0.075);
|
|
616
|
+
const top = (u: number): number => sheerAt(u) + 0.03;
|
|
617
|
+
batch.add(
|
|
618
|
+
m.hullWhite,
|
|
619
|
+
grid(
|
|
620
|
+
[
|
|
621
|
+
us.map((u) => new Vector3(x(u), top(u), inner(u))),
|
|
622
|
+
us.map((u) => new Vector3(x(u), top(u), outer(u))),
|
|
623
|
+
],
|
|
624
|
+
!flip,
|
|
625
|
+
),
|
|
626
|
+
);
|
|
627
|
+
batch.add(
|
|
628
|
+
m.hullWhite,
|
|
629
|
+
grid(
|
|
630
|
+
[
|
|
631
|
+
us.map((u) => new Vector3(x(u), top(u) - 0.09, outer(u))),
|
|
632
|
+
us.map((u) => new Vector3(x(u), top(u), outer(u))),
|
|
633
|
+
],
|
|
634
|
+
flip,
|
|
635
|
+
),
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function boatDressing(batch: PartBatch, m: VehicleMaterials, timber: Material): void {
|
|
641
|
+
const x = (u: number): number => u * BOAT.halfLength;
|
|
642
|
+
|
|
643
|
+
// Stem post: covers the point where the courses converge, and gives the bow
|
|
644
|
+
// the vertical accent the reference has above the sheer.
|
|
645
|
+
batch.add(m.hullWhite, roundedBox(0.12, 0.46, 0.1, 0.04), place(2.13, 0.62, 0, 0, 0, -0.16));
|
|
646
|
+
|
|
647
|
+
// Three thwarts sunk below the gunwale, each with a knee at either end.
|
|
648
|
+
const knee = new BoxGeometry(0.16, 0.14, 0.05);
|
|
649
|
+
for (const u of [0.42, 0, -0.46]) {
|
|
650
|
+
const beam = halfBeamAt(u) * 1.92;
|
|
651
|
+
const y = sheerAt(u) - 0.15;
|
|
652
|
+
batch.add(timber, new BoxGeometry(0.26, 0.05, beam), place(x(u), y, 0));
|
|
653
|
+
batch.addMirrored(timber, knee, place(x(u), y - 0.08, beam / 2 - 0.06));
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Two oars stowed diagonally, looms over the gunwale, blades across the bow.
|
|
657
|
+
const loom = new CylinderGeometry(0.026, 0.032, 2.2, 7);
|
|
658
|
+
const blade = new BoxGeometry(0.5, 0.02, 0.13);
|
|
659
|
+
for (const side of [1, -1]) {
|
|
660
|
+
const lean = side * 0.14;
|
|
661
|
+
batch.add(timber, loom, place(-0.35, 0.24, side * 0.4, 0, lean, -Math.PI / 2));
|
|
662
|
+
batch.add(timber, blade, place(0.9, 0.25, side * 0.24, 0, lean, 0));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// A coil of mooring line forward and two fish crates aft.
|
|
666
|
+
batch.add(m.rope, new TorusGeometry(0.15, 0.042, 5, 14), place(1.35, -0.03, 0.12, Math.PI / 2));
|
|
667
|
+
const crate = roundedBox(0.44, 0.28, 0.3, 0.03);
|
|
668
|
+
batch.add(timber, crate, place(-1.28, 0.02, 0.24, 0, 0.18, 0));
|
|
669
|
+
batch.add(timber, crate, place(-1.36, 0.02, -0.22, 0, -0.1, 0));
|
|
670
|
+
|
|
671
|
+
// Small clamp-on outboard hanging off the transom, its leg under the water.
|
|
672
|
+
batch.add(m.trimDark, roundedBox(0.26, 0.3, 0.24, 0.05), place(-2.34, 0.36, 0));
|
|
673
|
+
batch.add(m.trimDark, new BoxGeometry(0.1, 0.6, 0.08), place(-2.36, -0.03, 0));
|
|
674
|
+
batch.add(
|
|
675
|
+
m.trimGrey,
|
|
676
|
+
new CylinderGeometry(0.02, 0.02, 0.42, 6),
|
|
677
|
+
place(-2.16, 0.36, 0.16, 0, 0, Math.PI / 2 - 0.25),
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* One shared clock for every hull afloat. `THREE.Clock` is deprecated and
|
|
683
|
+
* `performance` is browser-only, so this is the same guarded `now()` three
|
|
684
|
+
* itself uses — which keeps the boat working on the DOM-less native target.
|
|
685
|
+
*/
|
|
686
|
+
const NOW = typeof performance === "undefined" ? Date : performance;
|
|
687
|
+
const SEA_EPOCH = NOW.now();
|
|
688
|
+
const seaSeconds = (): number => (NOW.now() - SEA_EPOCH) / 1000;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Heave, roll and pitch on three periods that never line up, so the loop never
|
|
692
|
+
* becomes visible. Driven from `updateMatrixWorld` because this file is handed
|
|
693
|
+
* no frame callback and the renderer already walks the graph every frame; the
|
|
694
|
+
* motion is continuous, which is exactly what `ctx.tween` is NOT for.
|
|
695
|
+
*/
|
|
696
|
+
function driftOnTheSwell(boat: Group, baseY: number, phase: number): void {
|
|
697
|
+
boat.updateMatrixWorld = (force?: boolean): void => {
|
|
698
|
+
const t = seaSeconds() + phase;
|
|
699
|
+
boat.position.y = baseY + Math.sin(t * 2.64) * 0.035;
|
|
700
|
+
boat.rotation.x = Math.sin(t * 1.95) * 0.037;
|
|
701
|
+
boat.rotation.z = Math.sin(t * 1.44) * 0.021;
|
|
702
|
+
Object3D.prototype.updateMatrixWorld.call(boat, force);
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Place a moored fishing boat. No collider: it floats past the playable deck,
|
|
708
|
+
* and a bullet or a footstep must never meet it.
|
|
709
|
+
*/
|
|
710
|
+
export function addFishingBoat(group: Group, materials: TownMaterials, at: BoatPlacement): Group {
|
|
711
|
+
const m = vehicleMaterials(materials);
|
|
712
|
+
const boat = new Group();
|
|
713
|
+
boat.name = "fishing-boat";
|
|
714
|
+
const batch = new PartBatch();
|
|
715
|
+
hullParts(batch, m);
|
|
716
|
+
boatDressing(batch, m, materials.deckWood);
|
|
717
|
+
batch.flush(boat, "boat", true);
|
|
718
|
+
boat.position.set(at.x, at.waterY, at.z);
|
|
719
|
+
boat.rotation.y = at.yaw;
|
|
720
|
+
group.add(boat);
|
|
721
|
+
driftOnTheSwell(boat, at.waterY, at.x * 0.31 + at.z * 0.17);
|
|
722
|
+
|
|
723
|
+
// Painter line from the stem to a pier post, drawn in world space so its
|
|
724
|
+
// fixed end stays put while the hull moves under it.
|
|
725
|
+
const post = at.moorTo;
|
|
726
|
+
if (post !== undefined) {
|
|
727
|
+
const stem = new Vector3(2.1, 0.45, 0)
|
|
728
|
+
.applyEuler(new Euler(0, at.yaw, 0))
|
|
729
|
+
.add(new Vector3(at.x, at.waterY, at.z));
|
|
730
|
+
const target = new Vector3(post[0], post[1], post[2]);
|
|
731
|
+
const span = target.clone().sub(stem);
|
|
732
|
+
const rope = new Mesh(new CylinderGeometry(0.022, 0.022, span.length(), 5), m.rope);
|
|
733
|
+
rope.name = "boat-painter";
|
|
734
|
+
rope.position.copy(stem).add(span.clone().multiplyScalar(0.5));
|
|
735
|
+
rope.quaternion.setFromUnitVectors(new Vector3(0, 1, 0), span.clone().normalize());
|
|
736
|
+
// A little sag: rope is not a tensioned cable.
|
|
737
|
+
rope.position.y -= MathUtils.clamp(span.length() * 0.06, 0, 0.12);
|
|
738
|
+
group.add(rope);
|
|
739
|
+
}
|
|
740
|
+
return boat;
|
|
741
|
+
}
|