create-threenative 0.2.17 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent-docs/kit-mcp.md +1 -1
- package/agent-docs/kit-router.md +1 -1
- package/agent-docs/references/assertion-reference.md +54 -110
- package/agent-docs/references/capability-reference.md +790 -24
- package/agent-docs/references/conventions.md +28 -0
- package/agent-docs/references/kit-racing.md +4 -2
- package/agent-docs/references/performance-basics.md +10 -5
- package/agent-docs/references/terrain-authoring.md +21 -7
- package/agent-files/.agents/skills/ponytail/SKILL.md +1 -1
- package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
- package/agent-files/.agents/skills/threenative-capabilities/SKILL.md +7 -4
- package/agent-files/.claude/hooks/discovery-gate.mjs +2 -2
- package/dist/index.d.ts +97 -6
- package/dist/index.js +1040 -529
- package/dist/quality.d.ts +5 -1
- package/dist/quality.js +75 -6
- package/dist/terrain-kit.js +1 -1
- package/dist/threenative.js +98 -17
- package/dist/web-engine-ccd-ik-solver.js +127 -0
- package/dist/web-engine-gltf-loader.js +52 -14
- package/dist/web-engine-post-effects.js +11 -10
- package/dist/web-engine-runtime.js +3638 -361
- package/package.json +8 -7
- package/template-assets/assets/floor-fern-0.glb +0 -0
- package/template-assets/assets/floor-litter-0.glb +0 -0
- package/template-assets/assets/floor-log-0.glb +0 -0
- package/template-assets/assets/floor-log-1.glb +0 -0
- package/template-assets/assets/floor-stump-0.glb +0 -0
- package/template-assets/assets/floor-twig-0.glb +0 -0
- package/template-assets/clearwater/README.md +1 -1
- package/template-assets/patches/manifest.json +18 -0
- package/template-assets/quality/eslint.config.js +1 -1
- package/templates/action-rpg/AGENTS.md +8 -4
- package/templates/action-rpg/CLAUDE.md +8 -4
- package/templates/action-rpg/package.json +7 -7
- package/templates/action-rpg/src/game.ts +1 -1
- package/templates/action-rpg/src/loot/drops.ts +3 -7
- package/templates/action-rpg/src/render/atmosphere.ts +6 -0
- package/templates/action-rpg/src/render/backlightControls.ts +10 -0
- package/templates/action-rpg/src/render/backlightMaterial.ts +4 -4
- package/templates/action-rpg/src/render/camera.ts +2 -2
- package/templates/action-rpg/src/render/clouds.ts +16 -1
- package/templates/action-rpg/src/render/materialLighting.ts +5 -5
- package/templates/action-rpg/src/render/materials.ts +3 -2
- package/templates/action-rpg/src/render/quality.ts +7 -32
- package/templates/action-rpg/src/render/touch-controls.ts +7 -6
- package/templates/action-rpg/src/scenes/Play.ts +5 -16
- package/templates/action-rpg/src/style.css +4 -0
- package/templates/action-rpg/vite.config.ts +2 -0
- package/templates/adventure/AGENTS.md +10 -5
- package/templates/adventure/CLAUDE.md +10 -5
- package/templates/adventure/kit.json +5 -1
- package/templates/adventure/native-playtests/survives.playtest.json +12 -0
- package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
- package/templates/adventure/package.json +7 -7
- package/templates/adventure/playtests/grass.playtest.json +61 -0
- package/templates/adventure/playtests/performance.playtest.json +1 -1
- package/templates/adventure/playtests/survives.playtest.json +2 -2
- package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
- package/templates/adventure/src/entities/LockOn.ts +42 -4
- package/templates/adventure/src/entities/Warden.ts +4 -1
- package/templates/adventure/src/game.ts +1 -1
- package/templates/adventure/src/level/Vale.ts +241 -16
- package/templates/adventure/src/render/camera.ts +2 -2
- package/templates/adventure/src/render/foliage.ts +64 -20
- package/templates/adventure/src/render/grass.ts +325 -0
- package/templates/adventure/src/render/materials.ts +3 -2
- package/templates/adventure/src/render/palette.ts +3 -0
- package/templates/adventure/src/render/touch-controls.ts +4 -1
- package/templates/adventure/src/scenes/Play.ts +96 -1
- package/templates/adventure/src/style.css +4 -0
- package/templates/adventure/tsconfig.json +1 -1
- package/templates/adventure/vite.config.ts +2 -0
- package/templates/collectathon/AGENTS.md +7 -2
- package/templates/collectathon/CLAUDE.md +7 -2
- package/templates/collectathon/package.json +7 -7
- package/templates/collectathon/src/game.ts +1 -1
- package/templates/collectathon/src/level/Course.ts +55 -14
- package/templates/collectathon/src/level/terrain.ts +29 -7
- package/templates/collectathon/src/main.ts +1 -0
- package/templates/collectathon/src/render/camera.ts +2 -2
- package/templates/collectathon/src/render/foliage.ts +359 -98
- package/templates/collectathon/src/render/ground.ts +4 -4
- package/templates/collectathon/src/render/hero.ts +1 -1
- package/templates/collectathon/src/render/materials.ts +0 -1
- package/templates/collectathon/src/render/sky.ts +80 -15
- package/templates/collectathon/src/render/water.ts +32 -10
- package/templates/collectathon/src/scenes/Play.ts +18 -5
- package/templates/collectathon/src/style.css +4 -0
- package/templates/collectathon/tsconfig.json +1 -1
- package/templates/collectathon/vite.config.ts +2 -0
- package/templates/kart/AGENTS.md +7 -2
- package/templates/kart/CLAUDE.md +7 -2
- package/templates/kart/package.json +6 -6
- package/templates/kart/src/entities/Kart.ts +2 -1
- package/templates/kart/src/game.ts +1 -1
- package/templates/kart/src/main.ts +1 -0
- package/templates/kart/src/render/course.ts +2 -1
- package/templates/kart/src/style.css +4 -0
- package/templates/kart/src/track/Course.ts +3 -1
- package/templates/kart/tsconfig.json +1 -1
- package/templates/kart/vite.config.ts +2 -0
- package/templates/minimal/AGENTS.md +8 -3
- package/templates/minimal/CLAUDE.md +8 -3
- package/templates/minimal/package.json +6 -6
- package/templates/minimal/playtests/stands-still.playtest.json +30 -0
- package/templates/minimal/src/game.ts +1 -1
- package/templates/minimal/src/render/atmosphere.ts +6 -0
- package/templates/minimal/src/render/backlightControls.ts +10 -0
- package/templates/minimal/src/render/backlightMaterial.ts +4 -4
- package/templates/minimal/src/render/camera.ts +14 -3
- package/templates/minimal/src/render/clouds.ts +16 -1
- package/templates/minimal/src/render/lighting.ts +4 -2
- package/templates/minimal/src/render/materialLighting.ts +5 -5
- package/templates/minimal/src/render/materials.ts +13 -2
- package/templates/minimal/src/render/quality.ts +7 -32
- package/templates/minimal/src/render/touch-controls.ts +7 -6
- package/templates/minimal/src/scenes/Play.ts +4 -1
- package/templates/minimal/vite.config.ts +7 -1
- package/templates/platformer/AGENTS.md +9 -4
- package/templates/platformer/CLAUDE.md +9 -4
- package/templates/platformer/index.html +1 -1
- package/templates/platformer/main.html +12 -0
- package/templates/platformer/package.json +7 -7
- package/templates/platformer/playtests/collect.playtest.json +4 -1
- package/templates/platformer/playtests/gamepad-idle.playtest.json +21 -0
- package/templates/platformer/playtests/gamepad.playtest.json +30 -0
- package/templates/platformer/src/entities/Fox.ts +21 -6
- package/templates/platformer/src/game.ts +1 -1
- package/templates/platformer/src/level/Stage.ts +2 -6
- package/templates/platformer/src/main.ts +1 -0
- package/templates/platformer/src/render/backlightControls.ts +10 -0
- package/templates/platformer/src/render/backlightMaterial.ts +4 -4
- package/templates/platformer/src/render/materialLighting.ts +5 -5
- package/templates/platformer/src/render/quality.ts +7 -32
- package/templates/platformer/src/scenes/Play.ts +4 -2
- package/templates/platformer/src/style.css +4 -0
- package/templates/platformer/src/worker-page.ts +29 -0
- package/templates/platformer/src/worker.ts +5 -0
- package/templates/platformer/tsconfig.json +1 -1
- package/templates/platformer/vite.config.ts +4 -0
- package/templates/puzzle/AGENTS.md +7 -2
- package/templates/puzzle/CLAUDE.md +7 -2
- package/templates/puzzle/package.json +7 -7
- package/templates/puzzle/src/entities/Warden.ts +3 -3
- package/templates/puzzle/src/game.ts +1 -1
- package/templates/puzzle/src/render/backlightControls.ts +10 -0
- package/templates/puzzle/src/render/backlightMaterial.ts +4 -4
- package/templates/puzzle/src/render/camera.ts +2 -2
- package/templates/puzzle/src/render/materialLighting.ts +5 -5
- package/templates/puzzle/src/render/quality.ts +7 -32
- package/templates/puzzle/src/render/touch-controls.ts +7 -6
- package/templates/puzzle/src/scenes/Play.ts +1 -1
- package/templates/puzzle/src/style.css +4 -0
- package/templates/puzzle/tsconfig.json +1 -1
- package/templates/puzzle/vite.config.ts +2 -0
- package/templates/racing/AGENTS.md +9 -4
- package/templates/racing/CLAUDE.md +9 -4
- package/templates/racing/CREDITS.md +29 -0
- package/templates/racing/assets/engine-loop.wav +0 -0
- package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
- package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
- package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
- package/templates/racing/assets/nitro-burst.wav +0 -0
- package/templates/racing/assets/tyre-squeal.wav +0 -0
- package/templates/racing/package.json +7 -7
- package/templates/racing/playtests/drift-natural.playtest.json +68 -0
- package/templates/racing/playtests/drift.playtest.json +100 -0
- package/templates/racing/playtests/hud.playtest.json +117 -0
- package/templates/racing/playtests/launch-pose.playtest.json +34 -0
- package/templates/racing/playtests/nitro.playtest.json +158 -0
- package/templates/racing/playtests/outcome.playtest.json +4 -4
- package/templates/racing/playtests/performance.playtest.json +1 -1
- package/templates/racing/playtests/steady-camera.playtest.json +88 -0
- package/templates/racing/src/audio/engine.ts +138 -0
- package/templates/racing/src/entities/CarBody.ts +83 -10
- package/templates/racing/src/entities/Drift.ts +243 -0
- package/templates/racing/src/entities/LineDriver.ts +2 -2
- package/templates/racing/src/entities/Nitro.ts +72 -0
- package/templates/racing/src/entities/RacingCar.ts +86 -21
- package/templates/racing/src/entities/Rival.ts +35 -21
- package/templates/racing/src/game.ts +7 -1
- package/templates/racing/src/gauges.ts +74 -0
- package/templates/racing/src/render/atmosphere.ts +6 -0
- package/templates/racing/src/render/backlightControls.ts +10 -0
- package/templates/racing/src/render/backlightMaterial.ts +4 -4
- package/templates/racing/src/render/camera.ts +29 -4
- package/templates/racing/src/render/clouds.ts +16 -1
- package/templates/racing/src/render/effects.ts +244 -0
- package/templates/racing/src/render/materialLighting.ts +5 -5
- package/templates/racing/src/render/materials.ts +43 -8
- package/templates/racing/src/render/quality.ts +7 -32
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/skids.ts +84 -0
- package/templates/racing/src/render/touch-controls.ts +10 -10
- package/templates/racing/src/scenes/Race.ts +281 -26
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +7 -0
- package/templates/racing/src/track/Track.ts +132 -58
- package/templates/racing/src/track/TrackSector.ts +19 -1
- package/templates/racing/src/track/circuit.ts +21 -15
- package/templates/racing/src/ui/GameUi.tsx +0 -2
- package/templates/racing/src/ui/Hud.tsx +417 -50
- package/templates/racing/threenative.config.ts +15 -0
- package/templates/racing/tools/make-racing-audio.mjs +388 -0
- package/templates/racing/tsconfig.json +1 -1
- package/templates/racing/vite.config.ts +2 -0
- package/templates/rain/AGENTS.md +6 -2
- package/templates/rain/CLAUDE.md +6 -2
- package/templates/rain/package.json +6 -6
- package/templates/rain/src/game.ts +1 -1
- package/templates/rain/src/render/noise-volume.ts +2 -1
- package/templates/rain/src/state.ts +3 -1
- package/templates/rain/src/ui/GameUi.tsx +1 -1
- package/templates/rain/src/ui/automation.ts +10 -8
- package/templates/rain/src/ui/tempest.ts +3 -4
- package/templates/rain/vite.config.ts +6 -0
- package/templates/rts/AGENTS.md +6 -2
- package/templates/rts/CLAUDE.md +6 -2
- package/templates/rts/package.json +6 -6
- package/templates/rts/src/game.ts +1 -1
- package/templates/rts/src/render/backlightControls.ts +10 -0
- package/templates/rts/src/render/backlightMaterial.ts +4 -4
- package/templates/rts/src/render/materialLighting.ts +5 -5
- package/templates/rts/src/render/quality.ts +7 -31
- package/templates/rts/src/scenes/Play.ts +1 -1
- package/templates/rts/src/sim/terrain.ts +1 -0
- package/templates/rts/src/sim/types.ts +1 -0
- package/templates/rts/src/style.css +4 -0
- package/templates/rts/vite.config.ts +2 -0
- package/templates/runner/AGENTS.md +7 -2
- package/templates/runner/CLAUDE.md +7 -2
- package/templates/runner/package.json +7 -7
- package/templates/runner/src/game.ts +1 -1
- package/templates/runner/src/render/atmosphere.ts +6 -0
- package/templates/runner/src/render/backlightControls.ts +10 -0
- package/templates/runner/src/render/backlightMaterial.ts +4 -4
- package/templates/runner/src/render/clouds.ts +16 -1
- package/templates/runner/src/render/materialLighting.ts +5 -5
- package/templates/runner/src/render/materials.ts +3 -2
- package/templates/runner/src/render/quality.ts +7 -32
- package/templates/runner/src/render/touch-controls.ts +7 -6
- package/templates/runner/src/scenes/Run.ts +8 -10
- package/templates/runner/src/style.css +4 -0
- package/templates/runner/tsconfig.json +1 -1
- package/templates/runner/vite.config.ts +2 -0
- package/templates/sailing/AGENTS.md +7 -2
- package/templates/sailing/CLAUDE.md +7 -2
- package/templates/sailing/package.json +7 -7
- package/templates/sailing/src/game.ts +1 -1
- package/templates/sailing/src/render/backlightControls.ts +10 -0
- package/templates/sailing/src/render/backlightMaterial.ts +4 -4
- package/templates/sailing/src/render/environmentSetup.ts +1 -1
- package/templates/sailing/src/render/materialLighting.ts +5 -5
- package/templates/sailing/src/render/quality.ts +7 -32
- package/templates/sailing/src/render/touch-controls.ts +7 -6
- package/templates/sailing/src/style.css +5 -0
- package/templates/sailing/vite.config.ts +6 -0
- package/templates/shooter/AGENTS.md +6 -2
- package/templates/shooter/CLAUDE.md +6 -2
- package/templates/shooter/package.json +7 -7
- package/templates/shooter/src/game.ts +3 -2
- package/templates/shooter/src/render/atmosphere.ts +6 -0
- package/templates/shooter/src/render/backlightControls.ts +10 -0
- package/templates/shooter/src/render/backlightMaterial.ts +4 -4
- package/templates/shooter/src/render/clouds.ts +16 -1
- package/templates/shooter/src/render/materialLighting.ts +5 -5
- package/templates/shooter/src/render/quality.ts +7 -32
- package/templates/shooter/src/scenes/Play.ts +4 -1
- package/templates/shooter/src/style.css +4 -0
- package/templates/shooter/vite.config.ts +2 -0
- package/templates/snow/AGENTS.md +7 -2
- package/templates/snow/CLAUDE.md +7 -2
- package/templates/snow/package.json +7 -7
- package/templates/snow/src/entities/Explorer.ts +6 -12
- package/templates/snow/src/game.ts +1 -1
- package/templates/snow/src/render/backlightControls.ts +10 -0
- package/templates/snow/src/render/backlightMaterial.ts +4 -4
- package/templates/snow/src/render/bootPrint.ts +3 -1
- package/templates/snow/src/render/camera.ts +3 -2
- package/templates/snow/src/render/materialLighting.ts +5 -5
- package/templates/snow/src/render/quality.ts +7 -32
- package/templates/snow/src/render/scenery.ts +3 -3
- package/templates/snow/src/render/touch-controls.ts +7 -6
- package/templates/snow/src/render/weather.ts +3 -5
- package/templates/snow/src/style.css +5 -0
- package/templates/snow/src/terrain.ts +2 -1
- package/templates/snow/vite.config.ts +6 -0
- package/templates/starter/AGENTS.md +8 -3
- package/templates/starter/CLAUDE.md +8 -3
- package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
- package/templates/starter/package.json +7 -7
- package/templates/starter/src/entities/Crate.ts +5 -2
- package/templates/starter/src/entities/Player.ts +10 -2
- package/templates/starter/src/game.ts +4 -3
- package/templates/starter/src/render/adaptiveQuality.ts +17 -0
- package/templates/starter/src/render/atmosphere.ts +6 -0
- package/templates/starter/src/render/backlightControls.ts +10 -0
- package/templates/starter/src/render/backlightMaterial.ts +4 -4
- package/templates/starter/src/render/camera.ts +2 -2
- package/templates/starter/src/render/clouds.ts +16 -1
- package/templates/starter/src/render/contactShadow.ts +1 -1
- package/templates/starter/src/render/materialLighting.ts +5 -5
- package/templates/starter/src/render/materials.ts +3 -2
- package/templates/starter/src/render/postprocessing.ts +11 -10
- package/templates/starter/src/render/quality.ts +14 -1
- package/templates/starter/src/render/touch-controls.ts +7 -6
- package/templates/starter/src/scenes/Play.ts +13 -17
- package/templates/starter/src/state.ts +2 -0
- package/templates/starter/src/style.css +4 -0
- package/templates/starter/src/ui/Menu.tsx +5 -1
- package/templates/starter/vite.config.ts +2 -0
- package/templates/tower-defense/AGENTS.md +7 -2
- package/templates/tower-defense/CLAUDE.md +7 -2
- package/templates/tower-defense/package.json +7 -7
- package/templates/tower-defense/src/game.ts +1 -1
- package/templates/tower-defense/src/render/backlightControls.ts +10 -0
- package/templates/tower-defense/src/render/backlightMaterial.ts +4 -4
- package/templates/tower-defense/src/render/materialLighting.ts +5 -5
- package/templates/tower-defense/src/render/quality.ts +7 -32
- package/templates/tower-defense/src/render/shapes.ts +1 -2
- package/templates/tower-defense/src/scenes/Battle.ts +4 -9
- package/templates/tower-defense/src/style.css +4 -0
- package/templates/tower-defense/tsconfig.json +1 -1
- package/templates/tower-defense/vite.config.ts +2 -0
- package/templates/action-rpg/src/render/environmentContribution.ts +0 -188
- package/templates/action-rpg/src/render/environmentRadiance.ts +0 -36
- package/templates/action-rpg/src/render/environmentSampleCache.ts +0 -43
- package/templates/action-rpg/src/render/environmentSampling.ts +0 -193
- package/templates/action-rpg/src/render/environmentSnapshot.ts +0 -53
- package/templates/minimal/src/render/environmentContribution.ts +0 -188
- package/templates/minimal/src/render/environmentRadiance.ts +0 -36
- package/templates/minimal/src/render/environmentSampleCache.ts +0 -43
- package/templates/minimal/src/render/environmentSampling.ts +0 -193
- package/templates/minimal/src/render/environmentSnapshot.ts +0 -53
- package/templates/platformer/src/render/environmentContribution.ts +0 -188
- package/templates/platformer/src/render/environmentRadiance.ts +0 -36
- package/templates/platformer/src/render/environmentSampleCache.ts +0 -43
- package/templates/platformer/src/render/environmentSampling.ts +0 -193
- package/templates/platformer/src/render/environmentSnapshot.ts +0 -53
- package/templates/puzzle/src/render/environmentContribution.ts +0 -188
- package/templates/puzzle/src/render/environmentRadiance.ts +0 -36
- package/templates/puzzle/src/render/environmentSampleCache.ts +0 -43
- package/templates/puzzle/src/render/environmentSampling.ts +0 -193
- package/templates/puzzle/src/render/environmentSnapshot.ts +0 -53
- package/templates/racing/src/render/environmentContribution.ts +0 -188
- package/templates/racing/src/render/environmentRadiance.ts +0 -36
- package/templates/racing/src/render/environmentSampleCache.ts +0 -43
- package/templates/racing/src/render/environmentSampling.ts +0 -193
- package/templates/racing/src/render/environmentSnapshot.ts +0 -53
- package/templates/racing/src/ui/Menu.tsx +0 -7
- package/templates/rts/src/render/environmentContribution.ts +0 -188
- package/templates/rts/src/render/environmentRadiance.ts +0 -36
- package/templates/rts/src/render/environmentSampleCache.ts +0 -43
- package/templates/rts/src/render/environmentSampling.ts +0 -193
- package/templates/rts/src/render/environmentSnapshot.ts +0 -53
- package/templates/runner/src/render/environmentContribution.ts +0 -188
- package/templates/runner/src/render/environmentRadiance.ts +0 -36
- package/templates/runner/src/render/environmentSampleCache.ts +0 -43
- package/templates/runner/src/render/environmentSampling.ts +0 -193
- package/templates/runner/src/render/environmentSnapshot.ts +0 -53
- package/templates/sailing/src/render/environmentContribution.ts +0 -188
- package/templates/sailing/src/render/environmentRadiance.ts +0 -36
- package/templates/sailing/src/render/environmentSampleCache.ts +0 -43
- package/templates/sailing/src/render/environmentSampling.ts +0 -193
- package/templates/sailing/src/render/environmentSnapshot.ts +0 -53
- package/templates/shooter/src/render/environmentContribution.ts +0 -188
- package/templates/shooter/src/render/environmentRadiance.ts +0 -36
- package/templates/shooter/src/render/environmentSampleCache.ts +0 -43
- package/templates/shooter/src/render/environmentSampling.ts +0 -193
- package/templates/shooter/src/render/environmentSnapshot.ts +0 -53
- package/templates/snow/src/render/environmentContribution.ts +0 -188
- package/templates/snow/src/render/environmentRadiance.ts +0 -36
- package/templates/snow/src/render/environmentSampleCache.ts +0 -43
- package/templates/snow/src/render/environmentSampling.ts +0 -193
- package/templates/snow/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/environmentContribution.ts +0 -188
- package/templates/starter/src/render/environmentRadiance.ts +0 -36
- package/templates/starter/src/render/environmentSampleCache.ts +0 -43
- package/templates/starter/src/render/environmentSampling.ts +0 -193
- package/templates/starter/src/render/environmentSnapshot.ts +0 -53
- package/templates/starter/src/render/rendererGate.ts +0 -36
- package/templates/tower-defense/src/render/environmentContribution.ts +0 -188
- package/templates/tower-defense/src/render/environmentRadiance.ts +0 -36
- package/templates/tower-defense/src/render/environmentSampleCache.ts +0 -43
- package/templates/tower-defense/src/render/environmentSampling.ts +0 -193
- package/templates/tower-defense/src/render/environmentSnapshot.ts +0 -53
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
GPUParticles3D,
|
|
2
3
|
Scene,
|
|
3
4
|
type SceneFrame,
|
|
4
5
|
afterPhysics,
|
|
@@ -6,23 +7,37 @@ import {
|
|
|
6
7
|
isMobile,
|
|
7
8
|
isTouchscreenAvailable,
|
|
8
9
|
} from "@threenative/core";
|
|
10
|
+
import { type IEnvironmentSample, sampleEnvironment } from "@threenative/core/render/environment";
|
|
9
11
|
import type { IPhysicsContext } from "@threenative/physics";
|
|
10
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
MathUtils,
|
|
14
|
+
type Object3D,
|
|
15
|
+
type PerspectiveCamera,
|
|
16
|
+
RepeatWrapping,
|
|
17
|
+
type Texture,
|
|
18
|
+
Vector3,
|
|
19
|
+
} from "three";
|
|
20
|
+
import { EngineAudio } from "../audio/engine.js";
|
|
11
21
|
import { type CarCtx, FEEL } from "../entities/CarBody.js";
|
|
12
22
|
import { RacingCar } from "../entities/RacingCar.js";
|
|
13
|
-
import { Rival } from "../entities/Rival.js";
|
|
23
|
+
import { RIVALS, Rival } from "../entities/Rival.js";
|
|
24
|
+
import { Gauges } from "../gauges.js";
|
|
14
25
|
import { emitPlaytestEvent } from "../playtest-events.js";
|
|
15
|
-
import { cameraBank, chaseCamera, setupCamera } from "../render/camera.js";
|
|
16
|
-
import {
|
|
26
|
+
import { BASE_FOV, cameraBank, chaseCamera, setupCamera } from "../render/camera.js";
|
|
27
|
+
import { cloudTextures, primeCloudTextures } from "../render/clouds.js";
|
|
28
|
+
import { BURSTS, EFFECTS } from "../render/effects.js";
|
|
17
29
|
import { setupLighting } from "../render/lighting.js";
|
|
18
30
|
import { createLoadingScreen } from "../render/loading.js";
|
|
19
31
|
import { createMaterialLighting } from "../render/materialLighting.js";
|
|
32
|
+
import type { IGrassMaps } from "../render/materials.js";
|
|
20
33
|
import { setupPost } from "../render/postprocessing.js";
|
|
21
34
|
import {
|
|
22
35
|
type QualityTier,
|
|
23
36
|
isWebGLFallbackRenderer,
|
|
24
37
|
materialLightingEnabled,
|
|
25
38
|
} from "../render/quality.js";
|
|
39
|
+
import { EXHAUST } from "../render/shapes.js";
|
|
40
|
+
import { SkidMarks } from "../render/skids.js";
|
|
26
41
|
import { SKY_OPTIONS, SUN_DIRECTION, setupSky } from "../render/sky.js";
|
|
27
42
|
import { TouchControls } from "../render/touch-controls.js";
|
|
28
43
|
import { type GameState, type RaceStatus, resolveRaceStatus } from "../state.js";
|
|
@@ -35,15 +50,16 @@ import {
|
|
|
35
50
|
gridPosition,
|
|
36
51
|
intersectRay,
|
|
37
52
|
roadRayProbe,
|
|
53
|
+
terrainHeight,
|
|
38
54
|
} from "../track/Track.js";
|
|
39
55
|
import { TrackSector } from "../track/TrackSector.js";
|
|
40
|
-
import { CIRCUIT,
|
|
56
|
+
import { CIRCUIT, PLAYER_SLOT, gridSlot } from "../track/circuit.js";
|
|
41
57
|
|
|
42
58
|
export type GameCtx = CarCtx;
|
|
43
59
|
|
|
44
60
|
/** The player starts on the second grid slot, one ride height above the tarmac. */
|
|
45
|
-
const SPAWN = gridPosition(
|
|
46
|
-
SPAWN.y = CIRCUIT.at(
|
|
61
|
+
const SPAWN = gridPosition(PLAYER_SLOT, new Vector3());
|
|
62
|
+
SPAWN.y = CIRCUIT.at(gridSlot(PLAYER_SLOT).distance, CIRCUIT.createSample()).point.y + 0.22;
|
|
47
63
|
/**
|
|
48
64
|
* The race is three laps of 55-60 s, so a time limit under four minutes is a limit nobody reaches
|
|
49
65
|
* and one that only fires on a car that has already been rescued four times.
|
|
@@ -58,6 +74,55 @@ function playerRanking(ranked: readonly IRankedRacer[]): IRankedRacer | undefine
|
|
|
58
74
|
return undefined;
|
|
59
75
|
}
|
|
60
76
|
|
|
77
|
+
const DEG = 180 / Math.PI;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The shake meter: the worst tick-to-tick step of the camera's bank and of the body's lean, and
|
|
81
|
+
* the worst second difference of the camera's yaw. A steady turn has a steady yaw rate, so its
|
|
82
|
+
* second difference is near zero; a camera that twitches from tick to tick does not.
|
|
83
|
+
*/
|
|
84
|
+
function createShakeMeter() {
|
|
85
|
+
let roll = 0;
|
|
86
|
+
let yaw = 0;
|
|
87
|
+
let yawRate = 0;
|
|
88
|
+
let lean = 0;
|
|
89
|
+
let samples = 0;
|
|
90
|
+
const dir = new Vector3();
|
|
91
|
+
const right = new Vector3();
|
|
92
|
+
const meter = {
|
|
93
|
+
cameraRollStep: 0,
|
|
94
|
+
cameraYawJerk: 0,
|
|
95
|
+
leanRollStep: 0,
|
|
96
|
+
/** The body's roll and pitch this tick, in degrees: + rolls toward the right, + lifts the nose. */
|
|
97
|
+
leanRoll: 0,
|
|
98
|
+
leanPitch: 0,
|
|
99
|
+
/** A camera cut is not a shake: the next two samples rebuild the history. */
|
|
100
|
+
reset(): void {
|
|
101
|
+
samples = 0;
|
|
102
|
+
},
|
|
103
|
+
sample(camera: PerspectiveCamera, body: Object3D): void {
|
|
104
|
+
camera.getWorldDirection(dir);
|
|
105
|
+
right.setFromMatrixColumn(camera.matrixWorld, 0);
|
|
106
|
+
const nextYaw = Math.atan2(dir.z, dir.x);
|
|
107
|
+
const rate = Math.atan2(Math.sin(nextYaw - yaw), Math.cos(nextYaw - yaw));
|
|
108
|
+
const nextRoll = Math.asin(MathUtils.clamp(right.y, -1, 1));
|
|
109
|
+
if (samples >= 2) {
|
|
110
|
+
meter.cameraRollStep = Math.max(meter.cameraRollStep, Math.abs(nextRoll - roll) * DEG);
|
|
111
|
+
meter.cameraYawJerk = Math.max(meter.cameraYawJerk, Math.abs(rate - yawRate) * DEG);
|
|
112
|
+
meter.leanRollStep = Math.max(meter.leanRollStep, Math.abs(body.rotation.x - lean) * DEG);
|
|
113
|
+
}
|
|
114
|
+
samples += 1;
|
|
115
|
+
roll = nextRoll;
|
|
116
|
+
yaw = nextYaw;
|
|
117
|
+
yawRate = rate;
|
|
118
|
+
lean = body.rotation.x;
|
|
119
|
+
meter.leanRoll = body.rotation.x * DEG;
|
|
120
|
+
meter.leanPitch = body.rotation.z * DEG;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
return meter;
|
|
124
|
+
}
|
|
125
|
+
|
|
61
126
|
function quantize(value: number, scale: number): number {
|
|
62
127
|
return Math.round(value * scale) / scale;
|
|
63
128
|
}
|
|
@@ -70,11 +135,30 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
70
135
|
boostActive: false,
|
|
71
136
|
boostPeakSpeed: 0,
|
|
72
137
|
boostUses: 0,
|
|
138
|
+
drifting: false,
|
|
139
|
+
driftAngle: 0,
|
|
140
|
+
driftScore: 0,
|
|
141
|
+
driftsBanked: 0,
|
|
142
|
+
driftSpins: 0,
|
|
143
|
+
nitro: 1,
|
|
144
|
+
nitroActive: false,
|
|
145
|
+
nitroDriftGain: 0,
|
|
146
|
+
gear: 1,
|
|
147
|
+
rpm: 0,
|
|
148
|
+
driftLast: 0,
|
|
149
|
+
driftPopup: 0,
|
|
150
|
+
fov: BASE_FOV,
|
|
151
|
+
fovPeak: BASE_FOV,
|
|
152
|
+
engineRate: 0,
|
|
73
153
|
completedLaps: 0,
|
|
74
154
|
elapsed: 0,
|
|
75
155
|
lastOnRoad: [SPAWN.x, SPAWN.y, SPAWN.z],
|
|
76
156
|
place: 1,
|
|
157
|
+
racers: RIVALS.length + 1,
|
|
77
158
|
position: "P1",
|
|
159
|
+
bestLap: 0,
|
|
160
|
+
lastLap: 0,
|
|
161
|
+
rankings: [],
|
|
78
162
|
raceStatus: "RACING",
|
|
79
163
|
rescueHeading: 0,
|
|
80
164
|
// Before any rescue, both errors are the worst they could be: the car is facing the wrong way
|
|
@@ -94,6 +178,7 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
94
178
|
};
|
|
95
179
|
|
|
96
180
|
#sky: Texture | undefined;
|
|
181
|
+
#grass: IGrassMaps | undefined;
|
|
97
182
|
|
|
98
183
|
/**
|
|
99
184
|
* The sky photograph, **awaited** before the scene enters.
|
|
@@ -110,15 +195,19 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
110
195
|
#environmentSample: IEnvironmentSample | undefined;
|
|
111
196
|
#materialLighting: ReturnType<typeof createMaterialLighting> | undefined;
|
|
112
197
|
#lightingGeneration = 0;
|
|
198
|
+
#audio: EngineAudio | undefined;
|
|
113
199
|
|
|
114
200
|
override async load(ctx: GameCtx): Promise<void> {
|
|
115
201
|
const generation = ++this.#lightingGeneration;
|
|
116
202
|
// Only the photo-sky override reads the photograph; the atmosphere sky is computed.
|
|
117
203
|
const texture = SKY_OPTIONS.sky === "photo" ? await ctx.assets.texture("sky.jpg") : undefined;
|
|
204
|
+
this.#grass = await loadGrassTextures(ctx);
|
|
118
205
|
if (generation !== this.#lightingGeneration) return;
|
|
119
206
|
this.#sky = texture;
|
|
120
207
|
const scene = ctx.scene;
|
|
121
208
|
if (scene === undefined) return;
|
|
209
|
+
// The cloud noise is the same every run of this build: generate it once, then read it back.
|
|
210
|
+
primeCloudTextures(await ctx.assets.memo("clouds", () => cloudTextures()));
|
|
122
211
|
setupSky(scene, texture, ctx.renderer.softwareAdapter !== undefined);
|
|
123
212
|
// The measurement is not awaited: it reads the GPU back and must not hold the first frame.
|
|
124
213
|
void this.#sampleSky(ctx, scene, generation);
|
|
@@ -190,15 +279,18 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
190
279
|
const touchControls = showTouchControls
|
|
191
280
|
? ctx.entities.add("touch-controls", new TouchControls(camera))
|
|
192
281
|
: undefined;
|
|
193
|
-
const track = buildTrack(ctx);
|
|
194
|
-
const car = new RacingCar(ctx, SPAWN, gridHeading(
|
|
195
|
-
//
|
|
196
|
-
//
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
282
|
+
const track = buildTrack(ctx, this.#grass);
|
|
283
|
+
const car = new RacingCar(ctx, SPAWN, gridHeading(PLAYER_SLOT));
|
|
284
|
+
// Display only, both of them: the rev counter's needle and the engine note it pitches. Neither
|
|
285
|
+
// touches the chassis, so a wrong needle is a wrong gauge and never a wrong lap.
|
|
286
|
+
const gauges = new Gauges();
|
|
287
|
+
this.#audio = new EngineAudio(camera, (name) => ctx.assets.audio(name));
|
|
288
|
+
// The field, each car on its own grid slot projected onto the circuit it drives. The pole car
|
|
289
|
+
// is the entity `rival`, the car to beat; the others are `rival-2` to `rival-5`.
|
|
290
|
+
const rivals = RIVALS.map((_, index) => new Rival(ctx, index));
|
|
200
291
|
ctx.entities.add("player", car);
|
|
201
|
-
|
|
292
|
+
for (const [index, rival] of rivals.entries())
|
|
293
|
+
ctx.entities.add(index === 0 ? "rival" : `rival-${index + 1}`, rival);
|
|
202
294
|
// The sun's aim as three reads it: the target's world matrix, which only a scene traversal refreshes.
|
|
203
295
|
ctx.entities.add("sun", {
|
|
204
296
|
get targetGap(): number {
|
|
@@ -211,19 +303,38 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
211
303
|
// `travelDirection` is the car's **measured** velocity, not the heading it was asked for: a
|
|
212
304
|
// car that is sliding through a corner is travelling somewhere other than where it points, and
|
|
213
305
|
// a lap counted on the intent is a lap counted on a wish.
|
|
306
|
+
// Lap times read the same race clock the HUD's timer publishes.
|
|
307
|
+
let elapsed = 0;
|
|
308
|
+
let bestLap = 0;
|
|
309
|
+
let lastLap = 0;
|
|
310
|
+
let lapStartedAt = 0;
|
|
214
311
|
const lap = new Lap(
|
|
215
312
|
{ body: car.body.body, forward: car.travelDirection },
|
|
216
313
|
track.gates,
|
|
217
314
|
TOTAL_LAPS,
|
|
218
|
-
(completed) =>
|
|
315
|
+
(completed) => {
|
|
316
|
+
lastLap = elapsed - lapStartedAt;
|
|
317
|
+
lapStartedAt = elapsed;
|
|
318
|
+
if (bestLap === 0 || lastLap < bestLap) bestLap = lastLap;
|
|
319
|
+
emitPlaytestEvent({ entity: "player", lap: completed, name: "lap-completed" });
|
|
320
|
+
},
|
|
219
321
|
);
|
|
220
322
|
const playerRankingInput = { id: "player", lap: lap.completed, position: car.body.position };
|
|
221
|
-
const
|
|
222
|
-
|
|
323
|
+
const rivalRankingInputs = rivals.map((rival, index) => ({
|
|
324
|
+
id: index === 0 ? "rival" : `rival-${index + 1}`,
|
|
325
|
+
lap: rival.lap,
|
|
326
|
+
position: rival.mesh.position,
|
|
327
|
+
}));
|
|
328
|
+
const rankingInputs = [playerRankingInput, ...rivalRankingInputs];
|
|
223
329
|
const rankingBuffer: IRankedRacerScratch[] = [];
|
|
224
330
|
const rankRace = () => {
|
|
225
331
|
playerRankingInput.lap = lap.completed;
|
|
226
|
-
|
|
332
|
+
// Indexed loop, not `.entries()`: this runs every frame and the runtime-cost gate holds the
|
|
333
|
+
// scene to zero per-frame iterator allocations.
|
|
334
|
+
for (let index = 0; index < rivalRankingInputs.length; index += 1) {
|
|
335
|
+
const input = rivalRankingInputs[index];
|
|
336
|
+
if (input !== undefined) input.lap = rivals[index]?.lap ?? 0;
|
|
337
|
+
}
|
|
227
338
|
return rankRacers(CIRCUIT, rankingInputs, undefined, rankingBuffer);
|
|
228
339
|
};
|
|
229
340
|
const initialRanked = rankRace();
|
|
@@ -233,6 +344,12 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
233
344
|
const sector = new TrackSector({
|
|
234
345
|
route: CIRCUIT,
|
|
235
346
|
intersectRay: intersectRay(ctx.physics, fallbackProbe),
|
|
347
|
+
// The grass is a heightfield collider now; this stays as the last-resort net for a car that
|
|
348
|
+
// leaves the world another way (a jump over the armco, or a future gap). The rescue fires the
|
|
349
|
+
// tick the car is clearly below the surface it should be standing on.
|
|
350
|
+
groundAt: terrainHeight,
|
|
351
|
+
// A metre below the drawn ground is not a crest or a berm, it is a car with no world under it.
|
|
352
|
+
fallDepth: 1.2,
|
|
236
353
|
});
|
|
237
354
|
track.boostArea.on("bodyEntered", (body) => {
|
|
238
355
|
if (body === car.body.body) {
|
|
@@ -241,7 +358,6 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
241
358
|
}
|
|
242
359
|
});
|
|
243
360
|
car.boost.update(0);
|
|
244
|
-
let elapsed = 0;
|
|
245
361
|
let status: RaceStatus = "RACING";
|
|
246
362
|
let rescues = 0;
|
|
247
363
|
// Before any rescue, both are the worst they can be: a car facing the wrong way, a whole lap
|
|
@@ -253,6 +369,9 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
253
369
|
let place = initialPlayer.place;
|
|
254
370
|
let positionLabel = `P${place}`;
|
|
255
371
|
const lastOnRoad: [number, number, number] = [SPAWN.x, SPAWN.y, SPAWN.z];
|
|
372
|
+
// A rescue or the autopilot's rejoin teleports the car, so the camera cuts to it instead of
|
|
373
|
+
// flying across the circuit.
|
|
374
|
+
let teleports = car.body.teleports;
|
|
256
375
|
const observedPosition = SPAWN.clone();
|
|
257
376
|
sector.update(SPAWN, car.forward, 0, 0);
|
|
258
377
|
chaseCamera(camera, car.body.position, car.forward, 1, undefined);
|
|
@@ -266,7 +385,8 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
266
385
|
dt,
|
|
267
386
|
touchControls?.update(frameCtx.input.raw.pointers, frameCtx.viewport.size),
|
|
268
387
|
);
|
|
269
|
-
|
|
388
|
+
for (let index = 0; index < rivals.length; index += 1) rivals[index]?.update(dt);
|
|
389
|
+
gauges.update(car.speed, dt);
|
|
270
390
|
sector.update(car.body.position, car.forward, dt, car.speed, car.driving);
|
|
271
391
|
if (sector.rescue(car)) {
|
|
272
392
|
rescues += 1;
|
|
@@ -281,6 +401,68 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
281
401
|
};
|
|
282
402
|
|
|
283
403
|
const statePatch: Partial<GameState> = {};
|
|
404
|
+
const shake = ctx.entities.add("camera-rig", createShakeMeter());
|
|
405
|
+
|
|
406
|
+
// Effects: two pooled emitters and one instanced ring of skid marks, every look parameter in
|
|
407
|
+
// `render/effects.ts` and `render/skids.ts`.
|
|
408
|
+
const make = (name: keyof typeof EFFECTS): GPUParticles3D => {
|
|
409
|
+
const emitter = ctx.add(new GPUParticles3D(EFFECTS[name]()));
|
|
410
|
+
emitter.name = `effects-${name}`;
|
|
411
|
+
return emitter;
|
|
412
|
+
};
|
|
413
|
+
const emitters = { nitro: make("nitro"), smoke: make("smoke") };
|
|
414
|
+
const burstOrigin = { x: 0, y: 0, z: 0 };
|
|
415
|
+
const burstShape = { x: 0, y: 0, z: 0 };
|
|
416
|
+
const burst = (kind: keyof typeof BURSTS, at: Vector3): void => {
|
|
417
|
+
const { count, emitter, shape } = BURSTS[kind];
|
|
418
|
+
burstOrigin.x = at.x;
|
|
419
|
+
burstOrigin.y = at.y;
|
|
420
|
+
burstOrigin.z = at.z;
|
|
421
|
+
burstShape.x = shape[0];
|
|
422
|
+
burstShape.y = shape[1];
|
|
423
|
+
burstShape.z = shape[2];
|
|
424
|
+
emitters[emitter].emitParticle({ count, direction: burstShape, origin: burstOrigin });
|
|
425
|
+
};
|
|
426
|
+
const skids = new SkidMarks(ctx.scene);
|
|
427
|
+
// What the effects did, for a scenario: ticks a tyre smoked, ticks the flame burned.
|
|
428
|
+
const effects = ctx.entities.add("effects", {
|
|
429
|
+
flameTicks: 0,
|
|
430
|
+
skidMarks: 0,
|
|
431
|
+
smokeTicks: 0,
|
|
432
|
+
});
|
|
433
|
+
const REAR_WHEELS = [2, 3] as const;
|
|
434
|
+
const rearRadius = car.body.body.wheels[2]?.wheelRadius ?? 0.37;
|
|
435
|
+
const contact = new Vector3();
|
|
436
|
+
let effectTick = 0;
|
|
437
|
+
const emitEffects = (): void => {
|
|
438
|
+
effectTick += 1;
|
|
439
|
+
if (car.skidding) {
|
|
440
|
+
let smoked = false;
|
|
441
|
+
for (const index of REAR_WHEELS) {
|
|
442
|
+
const wheel = car.body.wheels[index];
|
|
443
|
+
if (wheel === undefined || !car.body.body.wheelContact(index)) continue;
|
|
444
|
+
wheel.getWorldPosition(contact);
|
|
445
|
+
contact.y -= rearRadius;
|
|
446
|
+
skids.lay(index === 2 ? "rear-a" : "rear-b", contact.x, contact.y, contact.z);
|
|
447
|
+
// Alternate tyres, one burst a tick: a puff a tick a wheel is a wall, not smoke.
|
|
448
|
+
if ((effectTick + index) % 2 === 0) {
|
|
449
|
+
contact.y += 0.12;
|
|
450
|
+
burst("smoke", contact);
|
|
451
|
+
smoked = true;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
if (smoked) effects.smokeTicks += 1;
|
|
455
|
+
effects.skidMarks = skids.laid;
|
|
456
|
+
}
|
|
457
|
+
if (car.nitro.engaged) {
|
|
458
|
+
effects.flameTicks += 1;
|
|
459
|
+
for (const side of [-1, 1]) {
|
|
460
|
+
contact.set(EXHAUST.x - 0.5, EXHAUST.y, side * EXHAUST.z);
|
|
461
|
+
car.body.lean.localToWorld(contact);
|
|
462
|
+
burst("nitro", contact);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
284
466
|
|
|
285
467
|
// The suspension and the camera both read the **solved** chassis, so they run in the
|
|
286
468
|
// afterPhysics phase rather than in the scene frame: a wheel's spin angle and a car's velocity
|
|
@@ -289,14 +471,43 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
289
471
|
// The sun's shadow camera follows the car. It used to be a fixed 30 m box around the origin,
|
|
290
472
|
// which on an 830 m circuit put every shadow on the grass and left the car's own shadow — the
|
|
291
473
|
// speed cue a driver actually reads — somewhere else entirely.
|
|
474
|
+
// The lens's own reading: the nitro kick is measured on the camera, not restated from a
|
|
475
|
+
// constant, so a camera that stops widening fails the scenario that promises it does.
|
|
476
|
+
let fov = BASE_FOV;
|
|
477
|
+
let fovPeak = BASE_FOV;
|
|
478
|
+
|
|
292
479
|
afterPhysics(ctx, (dt) => {
|
|
293
|
-
car.body.settleVisuals();
|
|
294
|
-
|
|
480
|
+
car.body.settleVisuals(car.nitro.engaged, dt);
|
|
481
|
+
for (let index = 0; index < rivals.length; index += 1) rivals[index]?.car.settleVisuals();
|
|
482
|
+
if (status === "RACING") emitEffects();
|
|
295
483
|
lighting.key.target.position.copy(car.body.position);
|
|
296
484
|
lighting.key.position.copy(car.body.position).addScaledVector(SUN_DIRECTION, 90);
|
|
297
485
|
const solved = car.body.body.linearVelocity;
|
|
298
|
-
|
|
486
|
+
const cut = car.body.teleports !== teleports;
|
|
487
|
+
teleports = car.body.teleports;
|
|
488
|
+
chaseCamera(
|
|
489
|
+
camera,
|
|
490
|
+
car.body.position,
|
|
491
|
+
car.travelDirection,
|
|
492
|
+
cut ? 1 : dt,
|
|
493
|
+
solved,
|
|
494
|
+
car.boosting,
|
|
495
|
+
);
|
|
299
496
|
camera.rotateZ(cameraBank(car.lateralLoad, FEEL.lateral));
|
|
497
|
+
fov = camera.fov;
|
|
498
|
+
fovPeak = Math.max(fovPeak, fov);
|
|
499
|
+
this.#audio?.update({
|
|
500
|
+
running: status === "RACING",
|
|
501
|
+
rpm: gauges.rpm,
|
|
502
|
+
driftAngle: car.drift.angle,
|
|
503
|
+
sliding: car.skidding,
|
|
504
|
+
nitroActive: car.nitro.engaged,
|
|
505
|
+
});
|
|
506
|
+
if (cut) {
|
|
507
|
+
ctx.resetInterpolation(camera);
|
|
508
|
+
shake.reset();
|
|
509
|
+
}
|
|
510
|
+
shake.sample(camera, car.body.lean);
|
|
300
511
|
});
|
|
301
512
|
|
|
302
513
|
// Collect only after the loaded character and scene receivers are attached.
|
|
@@ -331,7 +542,7 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
331
542
|
const ranked = rankRace();
|
|
332
543
|
const player = playerRanking(ranked);
|
|
333
544
|
if (player === undefined) throw new Error("Race ranking lost the player.");
|
|
334
|
-
sameDistanceRanking = ranked[0]?.id === "
|
|
545
|
+
sameDistanceRanking = ranked[0]?.id === "player" ? "lap-behind" : "lap-ahead";
|
|
335
546
|
status = resolveRaceStatus(status, lap.completed, TOTAL_LAPS, player.place);
|
|
336
547
|
if (player.place !== place) {
|
|
337
548
|
place = player.place;
|
|
@@ -345,9 +556,27 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
345
556
|
statePatch.autopilot = car.autopilotEngaged;
|
|
346
557
|
statePatch.boostActive = car.boosting;
|
|
347
558
|
statePatch.boostPeakSpeed = boostPeakSpeed;
|
|
348
|
-
statePatch.boostUses = car.boost.uses;
|
|
559
|
+
statePatch.boostUses = car.boost.uses + car.nitro.uses;
|
|
560
|
+
statePatch.drifting = car.drift.drifting;
|
|
561
|
+
statePatch.driftAngle = quantize(car.drift.angle, 1000);
|
|
562
|
+
statePatch.driftScore = Math.round(car.drift.score);
|
|
563
|
+
statePatch.driftsBanked = car.drift.banked;
|
|
564
|
+
statePatch.driftSpins = car.drift.spins;
|
|
565
|
+
statePatch.nitro = quantize(car.nitro.tank, 1000);
|
|
566
|
+
statePatch.nitroActive = car.nitro.engaged;
|
|
567
|
+
statePatch.nitroDriftGain = quantize(car.nitro.driftGain, 1000);
|
|
568
|
+
statePatch.gear = gauges.gear;
|
|
569
|
+
statePatch.rpm = quantize(gauges.rpm, 1000);
|
|
570
|
+
statePatch.driftLast = Math.round(car.drift.lastBanked);
|
|
571
|
+
statePatch.driftPopup = quantize(car.drift.popup, 100);
|
|
572
|
+
statePatch.fov = quantize(fov, 100);
|
|
573
|
+
statePatch.fovPeak = quantize(fovPeak, 100);
|
|
574
|
+
statePatch.engineRate = quantize(this.#audio?.rate ?? 0, 1000);
|
|
349
575
|
statePatch.completedLaps = lap.completed;
|
|
350
576
|
statePatch.elapsed = elapsed;
|
|
577
|
+
statePatch.bestLap = bestLap;
|
|
578
|
+
statePatch.lastLap = lastLap;
|
|
579
|
+
statePatch.rankings = ranked;
|
|
351
580
|
statePatch.lastOnRoad = lastOnRoad;
|
|
352
581
|
statePatch.place = player.place;
|
|
353
582
|
statePatch.position = positionLabel;
|
|
@@ -368,6 +597,8 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
368
597
|
}
|
|
369
598
|
|
|
370
599
|
override exit(ctx: GameCtx): void {
|
|
600
|
+
this.#audio?.dispose();
|
|
601
|
+
this.#audio = undefined;
|
|
371
602
|
this.#materialLighting?.dispose();
|
|
372
603
|
this.#materialLighting = undefined;
|
|
373
604
|
this.#post?.dispose();
|
|
@@ -377,3 +608,27 @@ export class Race extends Scene<GameState, IPhysicsContext> {
|
|
|
377
608
|
super.exit(ctx);
|
|
378
609
|
}
|
|
379
610
|
}
|
|
611
|
+
|
|
612
|
+
/** The real ground PBR set (Poly Haven/ambientCG Grass004, CC0), configured for the 9 m ground UVs. */
|
|
613
|
+
async function loadGrassTextures(ctx: GameCtx): Promise<IGrassMaps> {
|
|
614
|
+
const [color, normal, roughness] = await Promise.all([
|
|
615
|
+
ctx.assets.texture("grass/Grass004_color.jpg", {
|
|
616
|
+
anisotropy: 8,
|
|
617
|
+
repeat: 6.43,
|
|
618
|
+
wrap: RepeatWrapping,
|
|
619
|
+
}),
|
|
620
|
+
ctx.assets.texture("grass/Grass004_normal.jpg", {
|
|
621
|
+
anisotropy: 8,
|
|
622
|
+
data: true,
|
|
623
|
+
repeat: 6.43,
|
|
624
|
+
wrap: RepeatWrapping,
|
|
625
|
+
}),
|
|
626
|
+
ctx.assets.texture("grass/Grass004_roughness.jpg", {
|
|
627
|
+
anisotropy: 8,
|
|
628
|
+
data: true,
|
|
629
|
+
repeat: 6.43,
|
|
630
|
+
wrap: RepeatWrapping,
|
|
631
|
+
}),
|
|
632
|
+
]);
|
|
633
|
+
return { color, normal, roughness };
|
|
634
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { IRankedRacer } from "./track/Ranking.js";
|
|
2
|
+
|
|
1
3
|
export type RaceStatus = "DNF" | "RACING" | "WON";
|
|
2
4
|
|
|
3
5
|
export function resolveRaceStatus(
|
|
@@ -21,10 +23,43 @@ export type GameState = {
|
|
|
21
23
|
boostPeakSpeed: number;
|
|
22
24
|
speedAfterBoost: number;
|
|
23
25
|
boostUses: number;
|
|
26
|
+
/** The handbrake drift: in a scored slide, its slip angle in radians, and the banked score. */
|
|
27
|
+
drifting: boolean;
|
|
28
|
+
driftAngle: number;
|
|
29
|
+
driftScore: number;
|
|
30
|
+
driftsBanked: number;
|
|
31
|
+
driftSpins: number;
|
|
32
|
+
/** The nitro tank, 0 to 1, and whether it is burning. */
|
|
33
|
+
nitro: number;
|
|
34
|
+
nitroActive: boolean;
|
|
35
|
+
/** Tank the drift path filled this race, which is what "drifting refills faster" is measured on. */
|
|
36
|
+
nitroDriftGain: number;
|
|
37
|
+
/** The gearbox: the gear engaged and the needle, 0 to 1 of that gear's band. Display only. */
|
|
38
|
+
gear: number;
|
|
39
|
+
rpm: number;
|
|
40
|
+
/** The last banked drift's score, which the HUD pops up for a moment after each one. */
|
|
41
|
+
driftLast: number;
|
|
42
|
+
/**
|
|
43
|
+
* Seconds that popup still shows, in game time: the drift owns the clock, so a pause freezes the
|
|
44
|
+
* popup instead of ageing it while the car is standing still.
|
|
45
|
+
*/
|
|
46
|
+
driftPopup: number;
|
|
47
|
+
/** The camera's lens: its reading now, and the widest it has been — the nitro kick, measured. */
|
|
48
|
+
fov: number;
|
|
49
|
+
fovPeak: number;
|
|
50
|
+
/** The engine loop's playback rate: the sound follows the revs where the runtime allows it. */
|
|
51
|
+
engineRate: number;
|
|
24
52
|
completedLaps: number;
|
|
25
53
|
elapsed: number;
|
|
54
|
+
/** Best and last completed lap, in seconds; 0 until the first lap is banked. */
|
|
55
|
+
bestLap: number;
|
|
56
|
+
lastLap: number;
|
|
57
|
+
/** The field as ranked this frame, player included: the HUD's live leaderboard. */
|
|
58
|
+
rankings: readonly IRankedRacer[];
|
|
26
59
|
lastOnRoad: [number, number, number];
|
|
27
60
|
place: number;
|
|
61
|
+
/** Cars in the race, the player included: the HUD's "P3 / 6". */
|
|
62
|
+
racers: number;
|
|
28
63
|
position: string;
|
|
29
64
|
raceStatus: RaceStatus;
|
|
30
65
|
rescueHeading: number;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
@source "../index.html";
|
|
4
4
|
@source "./";
|
|
5
|
+
/* `src/render/` is shader and material source: a word in its comments ("blur", "filter",
|
|
6
|
+
"table") became a real utility rule, which is what made a clean HUD look like a native-css
|
|
7
|
+
profile failure. Tailwind scans what it is told to scan. */
|
|
8
|
+
@source not "./render";
|
|
5
9
|
|
|
6
10
|
@theme {
|
|
7
11
|
--color-ink: #07111d;
|
|
@@ -12,7 +16,10 @@
|
|
|
12
16
|
--color-danger: #ff6c6c;
|
|
13
17
|
--color-text: #c2d6df;
|
|
14
18
|
--color-muted: #6b8c9b;
|
|
19
|
+
--color-cyan: #38d7e7;
|
|
15
20
|
--font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
21
|
+
--font-racing: "Arial Narrow", "Roboto Condensed", "Liberation Sans Narrow", "Helvetica Neue",
|
|
22
|
+
sans-serif;
|
|
16
23
|
}
|
|
17
24
|
|
|
18
25
|
html,
|