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
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js TSL — edit or delete it freely.
|
|
2
|
+
//
|
|
3
|
+
// The race's feedback: white smoke off a sliding rear tyre, and the blue sparks a nitro burn
|
|
4
|
+
// throws out of the exhausts. Two pooled emitters cover both. The nitro flame itself is a mesh on
|
|
5
|
+
// the car (`shapes.ts`): a puff stays where it was born, so a flame of particles would lay a
|
|
6
|
+
// dotted row of lights down the road behind every burn.
|
|
7
|
+
// `GPUParticles3D` (built in `scenes/Race.ts`) owns the slots, the dispatch, the birth stamps and
|
|
8
|
+
// the culling. Every look choice is this file's: life, drag, gravity, size, colour, blend and
|
|
9
|
+
// sprite mask. A burst passes its shape as the request's `direction`: x is the outward speed,
|
|
10
|
+
// y the upward speed, and z the radius it starts in.
|
|
11
|
+
import {
|
|
12
|
+
Fn,
|
|
13
|
+
If,
|
|
14
|
+
abs,
|
|
15
|
+
cos,
|
|
16
|
+
exp,
|
|
17
|
+
float,
|
|
18
|
+
hash,
|
|
19
|
+
instanceIndex,
|
|
20
|
+
mix,
|
|
21
|
+
sin,
|
|
22
|
+
smoothstep,
|
|
23
|
+
step,
|
|
24
|
+
time,
|
|
25
|
+
uint,
|
|
26
|
+
uv,
|
|
27
|
+
varying,
|
|
28
|
+
vec3,
|
|
29
|
+
vec4,
|
|
30
|
+
} from "three/tsl";
|
|
31
|
+
import {
|
|
32
|
+
AdditiveBlending,
|
|
33
|
+
type ComputeNode,
|
|
34
|
+
type Node,
|
|
35
|
+
NormalBlending,
|
|
36
|
+
SpriteNodeMaterial,
|
|
37
|
+
type StorageBufferNode,
|
|
38
|
+
type UniformNode,
|
|
39
|
+
type Vector3,
|
|
40
|
+
} from "three/webgpu";
|
|
41
|
+
|
|
42
|
+
export interface IEffectBuffers {
|
|
43
|
+
readonly positions: StorageBufferNode<"vec3">;
|
|
44
|
+
readonly velocities: StorageBufferNode<"vec3">;
|
|
45
|
+
readonly births: StorageBufferNode<"float">;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IEffectRequest {
|
|
49
|
+
readonly first: UniformNode<"uint", number>;
|
|
50
|
+
readonly count: UniformNode<"uint", number>;
|
|
51
|
+
readonly origin: UniformNode<"vec3", Vector3>;
|
|
52
|
+
readonly direction: UniformNode<"vec3", Vector3>;
|
|
53
|
+
readonly seed: UniformNode<"float", number>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IEffectOptions {
|
|
57
|
+
readonly amount: number;
|
|
58
|
+
readonly lifetime: number;
|
|
59
|
+
readonly material: SpriteNodeMaterial;
|
|
60
|
+
readonly spawn: (buffers: IEffectBuffers, request: IEffectRequest) => ComputeNode;
|
|
61
|
+
readonly process: (
|
|
62
|
+
buffers: IEffectBuffers,
|
|
63
|
+
runtime: { readonly time: Node<"float">; readonly delta: Node<"float"> },
|
|
64
|
+
) => ComputeNode;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface IRecipe {
|
|
68
|
+
readonly amount: number;
|
|
69
|
+
/** Seconds a particle lives. */
|
|
70
|
+
readonly life: number;
|
|
71
|
+
/** Fraction of speed lost per second, as an exponential rate. */
|
|
72
|
+
readonly drag: number;
|
|
73
|
+
/** Metres per second squared on y: negative falls, positive rises like warm dust. */
|
|
74
|
+
readonly gravity: number;
|
|
75
|
+
/** Sprite size in metres at birth and at death. */
|
|
76
|
+
readonly size: readonly [number, number];
|
|
77
|
+
/** Linear colour at birth and at death. */
|
|
78
|
+
readonly colour: readonly [readonly [number, number, number], readonly [number, number, number]];
|
|
79
|
+
readonly opacity: number;
|
|
80
|
+
readonly additive: boolean;
|
|
81
|
+
readonly mask: "puff" | "star";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const TAU = Math.PI * 2;
|
|
85
|
+
|
|
86
|
+
/** A soft round puff, or a four-point star with a soft core: no texture, no download. */
|
|
87
|
+
function sprite(mask: IRecipe["mask"]) {
|
|
88
|
+
const point = uv().sub(0.5);
|
|
89
|
+
const round = float(1).sub(smoothstep(0.05, 0.5, point.length()));
|
|
90
|
+
if (mask === "puff") return round.mul(round);
|
|
91
|
+
const ray = float(1)
|
|
92
|
+
.sub(smoothstep(0.02, 0.07, abs(point.x)))
|
|
93
|
+
.max(float(1).sub(smoothstep(0.02, 0.07, abs(point.y))))
|
|
94
|
+
.mul(float(1).sub(smoothstep(0.1, 0.5, point.length())));
|
|
95
|
+
return round.mul(round).max(ray);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function emitter(recipe: IRecipe): IEffectOptions {
|
|
99
|
+
const material = new SpriteNodeMaterial({
|
|
100
|
+
blending: recipe.additive ? AdditiveBlending : NormalBlending,
|
|
101
|
+
depthWrite: false,
|
|
102
|
+
transparent: true,
|
|
103
|
+
});
|
|
104
|
+
// The quad's empty corners write nothing to the depth and normal buffers, so AO skips them.
|
|
105
|
+
material.alphaTest = 0.02;
|
|
106
|
+
const [birth, death] = recipe.colour;
|
|
107
|
+
// The material reads the birth stamp the engine writes, so it binds once the buffer exists.
|
|
108
|
+
const bind = (born: Node<"float">): void => {
|
|
109
|
+
const age = time.sub(born);
|
|
110
|
+
const alive = varying(step(0, age).mul(step(age, recipe.life)));
|
|
111
|
+
const phase = varying(age.div(recipe.life).clamp(0, 1));
|
|
112
|
+
const jitter = hash(instanceIndex.add(7)).mul(0.6).add(0.7);
|
|
113
|
+
material.scaleNode = mix(float(recipe.size[0]), float(recipe.size[1]), phase)
|
|
114
|
+
.mul(jitter)
|
|
115
|
+
.mul(alive);
|
|
116
|
+
material.colorNode = vec4(
|
|
117
|
+
mix(vec3(...birth), vec3(...death), phase),
|
|
118
|
+
sprite(recipe.mask)
|
|
119
|
+
.mul(float(1).sub(smoothstep(0.55, 1, phase)))
|
|
120
|
+
.mul(recipe.opacity)
|
|
121
|
+
.mul(alive),
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
const spawn = (
|
|
125
|
+
{ positions, velocities, births }: IEffectBuffers,
|
|
126
|
+
request: IEffectRequest,
|
|
127
|
+
): ComputeNode => {
|
|
128
|
+
bind(births.toAttribute());
|
|
129
|
+
return Fn(() => {
|
|
130
|
+
If(instanceIndex.lessThan(request.count), () => {
|
|
131
|
+
const slot = request.first.add(instanceIndex).mod(uint(recipe.amount));
|
|
132
|
+
const key = instanceIndex.add(request.seed.mul(977).toUint());
|
|
133
|
+
const r = (salt: number) => hash(key.add(salt));
|
|
134
|
+
const angle = r(1).mul(TAU);
|
|
135
|
+
const radius = r(2).sqrt().mul(request.direction.z);
|
|
136
|
+
const out = request.direction.x.mul(r(3).mul(0.6).add(0.5));
|
|
137
|
+
positions
|
|
138
|
+
.element(slot)
|
|
139
|
+
.assign(
|
|
140
|
+
request.origin.add(
|
|
141
|
+
vec3(cos(angle).mul(radius), r(4).mul(0.12), sin(angle).mul(radius)),
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
velocities
|
|
145
|
+
.element(slot)
|
|
146
|
+
.assign(
|
|
147
|
+
vec3(
|
|
148
|
+
cos(angle).mul(out),
|
|
149
|
+
request.direction.y.mul(r(5).mul(0.8).add(0.6)),
|
|
150
|
+
sin(angle).mul(out),
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
})().compute(recipe.amount);
|
|
155
|
+
};
|
|
156
|
+
const process = (
|
|
157
|
+
{ positions, velocities, births }: IEffectBuffers,
|
|
158
|
+
runtime: { readonly time: Node<"float">; readonly delta: Node<"float"> },
|
|
159
|
+
): ComputeNode =>
|
|
160
|
+
Fn(() => {
|
|
161
|
+
const age = runtime.time.sub(births.element(instanceIndex));
|
|
162
|
+
If(age.greaterThanEqual(0).and(age.lessThan(recipe.life)), () => {
|
|
163
|
+
const velocity = velocities
|
|
164
|
+
.element(instanceIndex)
|
|
165
|
+
.mul(exp(float(-recipe.drag).mul(runtime.delta)))
|
|
166
|
+
.add(vec3(0, recipe.gravity, 0).mul(runtime.delta));
|
|
167
|
+
velocities.element(instanceIndex).assign(velocity);
|
|
168
|
+
positions.element(instanceIndex).addAssign(velocity.mul(runtime.delta));
|
|
169
|
+
});
|
|
170
|
+
})().compute(recipe.amount);
|
|
171
|
+
return { amount: recipe.amount, lifetime: recipe.life, material, process, spawn };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Tyre smoke: near-white, slow, rising and spreading for over a second, so a held drift trails a
|
|
176
|
+
* cloud the width of the road rather than a row of puffs.
|
|
177
|
+
*/
|
|
178
|
+
export function smokeEffect(): IEffectOptions {
|
|
179
|
+
return emitter({
|
|
180
|
+
additive: false,
|
|
181
|
+
amount: 2048,
|
|
182
|
+
colour: [
|
|
183
|
+
[0.82, 0.82, 0.84],
|
|
184
|
+
[0.93, 0.93, 0.94],
|
|
185
|
+
],
|
|
186
|
+
drag: 2.4,
|
|
187
|
+
gravity: 1.1,
|
|
188
|
+
life: 1.25,
|
|
189
|
+
mask: "puff",
|
|
190
|
+
// The chase camera flies through this cloud, so a puff that grows to 2.6 m and sits at 0.4
|
|
191
|
+
// alpha covered the road — and the skid marks it was laid over — from a metre away. Thinner
|
|
192
|
+
// and smaller, the trail reads as a cloud behind the car rather than as a smear on the lens.
|
|
193
|
+
opacity: 0.3,
|
|
194
|
+
size: [0.5, 2.0],
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Nitro sparks: additive blue, and short. The colours run well above 1 because auto exposure meters
|
|
200
|
+
* a sunlit circuit: at 1.5 they vanish against the road.
|
|
201
|
+
*
|
|
202
|
+
* Its life was a third of a second, which at 80 km/h is seven metres of trail: two dotted ribbons
|
|
203
|
+
* laid down the road behind the car rather than a flame at its exhausts. A plume is what the road
|
|
204
|
+
* speed cannot stretch, so the burst is now denser and a seventh of a second long, it leaves
|
|
205
|
+
* slowly, its drag is high enough that it stops where it was born, and its size falls from a third
|
|
206
|
+
* of a metre to eight centimetres — thick at the nozzle, thin at the tip. The birth size is wider
|
|
207
|
+
* than the 0.5 m a burst is laid down per tick at 110 km/h, or the plume is a dotted line.
|
|
208
|
+
*/
|
|
209
|
+
export function nitroEffect(): IEffectOptions {
|
|
210
|
+
return emitter({
|
|
211
|
+
additive: true,
|
|
212
|
+
amount: 512,
|
|
213
|
+
colour: [
|
|
214
|
+
[0.5, 1.6, 6],
|
|
215
|
+
[0.08, 0.3, 2.4],
|
|
216
|
+
],
|
|
217
|
+
drag: 6,
|
|
218
|
+
gravity: 0,
|
|
219
|
+
life: 0.11,
|
|
220
|
+
mask: "star",
|
|
221
|
+
opacity: 1,
|
|
222
|
+
size: [0.55, 0.08],
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The emitters `scenes/Race.ts` builds, by the name a burst picks one with. */
|
|
227
|
+
export const EFFECTS = {
|
|
228
|
+
nitro: nitroEffect,
|
|
229
|
+
smoke: smokeEffect,
|
|
230
|
+
} as const;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Every burst the game fires, by name: its emitter, how many particles and the request's
|
|
234
|
+
* `direction` (outward speed, upward speed, start radius). Tune the feel here, not in `scenes/Race.ts`.
|
|
235
|
+
*/
|
|
236
|
+
export const BURSTS = {
|
|
237
|
+
/** A sliding or locked rear tyre, once every other tick a wheel. */
|
|
238
|
+
smoke: { emitter: "smoke", count: 2, shape: [0.7, 0.9, 0.2] },
|
|
239
|
+
/** Each exhaust, every tick of a nitro burn: three a tick keeps a short plume solid. */
|
|
240
|
+
nitro: { emitter: "nitro", count: 3, shape: [1.2, 0.35, 0.05] },
|
|
241
|
+
} as const satisfies Record<
|
|
242
|
+
string,
|
|
243
|
+
{ emitter: keyof typeof EFFECTS; count: number; shape: readonly [number, number, number] }
|
|
244
|
+
>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// Generated for you. Scene-owned material assignments; no engine appearance hooks.
|
|
2
|
-
import type { Camera, DirectionalLight, Object3D, Scene, Texture } from "three";
|
|
3
|
-
import type { IBacklightControls } from "./backlightMaterial.js";
|
|
4
1
|
import {
|
|
5
2
|
type IEnvironmentMeasurement,
|
|
6
3
|
measureEnvironment,
|
|
7
4
|
reportEnvironmentContribution,
|
|
8
|
-
} from "
|
|
5
|
+
} from "@threenative/core/render/environment";
|
|
9
6
|
import {
|
|
10
7
|
type IEnvironmentSourceSnapshot,
|
|
11
8
|
captureEnvironmentSnapshot,
|
|
12
9
|
environmentSnapshotCurrent,
|
|
13
|
-
} from "
|
|
10
|
+
} from "@threenative/core/render/environment";
|
|
11
|
+
// Generated for you. Scene-owned material assignments; no engine appearance hooks.
|
|
12
|
+
import type { Camera, DirectionalLight, Object3D, Scene, Texture } from "three";
|
|
13
|
+
import type { IBacklightControls } from "./backlightMaterial.js";
|
|
14
14
|
import { type ILightingConvention, createLightingConvention } from "./lighting.js";
|
|
15
15
|
import { createMaterialAssignments } from "./materialAssignments.js";
|
|
16
16
|
import { type IMaterialLightingEnvironment, materialLightingEnabled } from "./quality.js";
|
|
@@ -8,13 +8,18 @@
|
|
|
8
8
|
// built from bytes rather than shipped as files, so they cost nothing to load and run the same in
|
|
9
9
|
// the browser and in the native host.
|
|
10
10
|
import {
|
|
11
|
+
AdditiveBlending,
|
|
11
12
|
type BufferGeometry,
|
|
13
|
+
Color,
|
|
12
14
|
DataTexture,
|
|
13
15
|
Float32BufferAttribute,
|
|
14
16
|
LinearMipmapLinearFilter,
|
|
17
|
+
MathUtils,
|
|
18
|
+
MeshBasicMaterial,
|
|
15
19
|
MeshStandardMaterial,
|
|
16
20
|
RepeatWrapping,
|
|
17
21
|
SRGBColorSpace,
|
|
22
|
+
type Texture,
|
|
18
23
|
Vector2,
|
|
19
24
|
Vector3,
|
|
20
25
|
} from "three";
|
|
@@ -31,7 +36,7 @@ function noise(x: number, y: number, seed: number): number {
|
|
|
31
36
|
/** Smoothstep, so the rubber band has a soft edge instead of a stripe painted across the road. */
|
|
32
37
|
function falloff(value: number, edge: number): number {
|
|
33
38
|
const t = Math.min(Math.max((Math.abs(value) - edge) / 0.28, 0), 1);
|
|
34
|
-
return t
|
|
39
|
+
return MathUtils.smoothstep(t, 0, 1);
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
function rgbaTexture(
|
|
@@ -121,8 +126,8 @@ function grainNormalTexture(size = 128): DataTexture {
|
|
|
121
126
|
const y0 = Math.floor(v);
|
|
122
127
|
const fx = u - x0;
|
|
123
128
|
const fy = v - y0;
|
|
124
|
-
const sx = fx
|
|
125
|
-
const sy = fy
|
|
129
|
+
const sx = MathUtils.smoothstep(fx, 0, 1);
|
|
130
|
+
const sy = MathUtils.smoothstep(fy, 0, 1);
|
|
126
131
|
const at = (i: number, j: number): number =>
|
|
127
132
|
values[(((j % count) + count) % count) * count + (((i % count) + count) % count)] ?? 0;
|
|
128
133
|
const top = at(x0, y0) + (at(x0 + 1, y0) - at(x0, y0)) * sx;
|
|
@@ -181,7 +186,14 @@ export function worldGridUVs<T extends BufferGeometry>(geometry: T): T {
|
|
|
181
186
|
return geometry;
|
|
182
187
|
}
|
|
183
188
|
|
|
184
|
-
|
|
189
|
+
/** The PBR maps a game supplies for the ground; the generated turf is the fallback. */
|
|
190
|
+
export interface IGrassMaps {
|
|
191
|
+
readonly color: Texture;
|
|
192
|
+
readonly normal: Texture;
|
|
193
|
+
readonly roughness: Texture;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function createMaterials(grass?: IGrassMaps) {
|
|
185
197
|
return {
|
|
186
198
|
/** Boost chevrons and the start lights' housing. */
|
|
187
199
|
boost: toon(palette.accent, 0.4),
|
|
@@ -203,10 +215,11 @@ export function createMaterials() {
|
|
|
203
215
|
}),
|
|
204
216
|
/** The infield and everything beyond the run-off. */
|
|
205
217
|
grass: new MeshStandardMaterial({
|
|
206
|
-
map: turf,
|
|
207
|
-
normalMap: grain,
|
|
208
|
-
normalScale: new Vector2(0.35, 0.35),
|
|
209
|
-
|
|
218
|
+
map: grass?.color ?? turf,
|
|
219
|
+
normalMap: grass?.normal ?? grain,
|
|
220
|
+
normalScale: grass === undefined ? new Vector2(0.35, 0.35) : new Vector2(0.6, 0.6),
|
|
221
|
+
roughnessMap: grass?.roughness,
|
|
222
|
+
roughness: grass === undefined ? 0.95 : 1,
|
|
210
223
|
metalness: 0,
|
|
211
224
|
}),
|
|
212
225
|
/** The paved run-off past the white line, and the pit lane. */
|
|
@@ -245,6 +258,13 @@ export function createMaterials() {
|
|
|
245
258
|
/** Kept as an alias so a game that already referred to the old slot still compiles. */
|
|
246
259
|
vehicle: new MeshStandardMaterial({ color: 0xd93a3a, metalness: 0.18, roughness: 0.3 }),
|
|
247
260
|
rivalBody: new MeshStandardMaterial({ color: palette.accent, metalness: 0.18, roughness: 0.3 }),
|
|
261
|
+
/**
|
|
262
|
+
* The field's liveries, pole first. The pole car keeps the accent, because it is the car to
|
|
263
|
+
* beat; the rest are paint a driver tells apart at a glance, none of them the player's red.
|
|
264
|
+
*/
|
|
265
|
+
rivalLiveries: [palette.accent, 0xf0b429, 0xeceae2, 0x2f8f5b, 0x23262c].map(
|
|
266
|
+
(color) => new MeshStandardMaterial({ color, metalness: 0.18, roughness: 0.3 }),
|
|
267
|
+
),
|
|
248
268
|
glass: new MeshStandardMaterial({
|
|
249
269
|
color: 0x3f5a70,
|
|
250
270
|
metalness: 0.55,
|
|
@@ -275,6 +295,21 @@ export function createMaterials() {
|
|
|
275
295
|
roughness: 0.34,
|
|
276
296
|
}),
|
|
277
297
|
|
|
298
|
+
// The nitro flame: additive and far above 1, so it stays blue-white against a sunlit road
|
|
299
|
+
// and the bloom stage has something to catch. The core is the hotter, shorter cone inside.
|
|
300
|
+
flame: new MeshBasicMaterial({
|
|
301
|
+
blending: AdditiveBlending,
|
|
302
|
+
color: new Color(0.35, 1.5, 7),
|
|
303
|
+
depthWrite: false,
|
|
304
|
+
transparent: true,
|
|
305
|
+
}),
|
|
306
|
+
flameCore: new MeshBasicMaterial({
|
|
307
|
+
blending: AdditiveBlending,
|
|
308
|
+
color: new Color(5, 6, 8),
|
|
309
|
+
depthWrite: false,
|
|
310
|
+
transparent: true,
|
|
311
|
+
}),
|
|
312
|
+
|
|
278
313
|
/** Trackside furniture that is instanced, so it takes a flat value rather than a mapped grid. */
|
|
279
314
|
crowd: toon(0x6f7681, 0.9),
|
|
280
315
|
trunk: toon(0x5b4a3c, 0.9),
|
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
qualityTiers,
|
|
36
36
|
} from "@threenative/core";
|
|
37
37
|
export type { QualityTier } from "@threenative/core";
|
|
38
|
-
import type { QualityTier } from "@threenative/core";
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* The three names this game's look comes in.
|
|
@@ -69,34 +68,10 @@ export function qualityPreset(tier: string): IWorldEnvironmentOptions {
|
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
/** First admitted material lane: high desktop hardware WebGPU in the browser only. */
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
export function materialLightingEnabled(
|
|
80
|
-
tier: QualityTier,
|
|
81
|
-
environment: IMaterialLightingEnvironment,
|
|
82
|
-
): boolean {
|
|
83
|
-
return (
|
|
84
|
-
tier === "high" &&
|
|
85
|
-
environment.web &&
|
|
86
|
-
environment.rendererKind === "webgpu" &&
|
|
87
|
-
environment.mobile !== true &&
|
|
88
|
-
environment.software !== true &&
|
|
89
|
-
environment.webglFallback !== true
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** A WebGPURenderer wrapper may run an ordinary WebGL fallback backend. */
|
|
94
|
-
export function isWebGLFallbackRenderer(renderer: unknown): boolean {
|
|
95
|
-
if (renderer === null || typeof renderer !== "object") return false;
|
|
96
|
-
const backend = Reflect.get(renderer, "backend");
|
|
97
|
-
return (
|
|
98
|
-
backend !== null &&
|
|
99
|
-
typeof backend === "object" &&
|
|
100
|
-
Reflect.get(backend, "isWebGLBackend") === true
|
|
101
|
-
);
|
|
102
|
-
}
|
|
71
|
+
// The material lane's admission rule and the WebGL-fallback probe are the engine's: twelve kits
|
|
72
|
+
// held a copy each, so a fix to one left eleven admitting what it refused.
|
|
73
|
+
export {
|
|
74
|
+
type IMaterialLightingEnvironment,
|
|
75
|
+
isWebGLFallbackRenderer,
|
|
76
|
+
materialLightingEnabled,
|
|
77
|
+
} from "@threenative/core/render/environment";
|
|
@@ -269,6 +269,18 @@ function wheel(materials: Materials, radius: number): Group {
|
|
|
269
269
|
// flare in `CAR_STATIONS` — 0.86 half-width over the rear axle against 0.72 at the doors — is the
|
|
270
270
|
// arch, and it costs no geometry at all.
|
|
271
271
|
|
|
272
|
+
/** Where each exhaust ends, in the car's own metres: behind the tail, either side of centre. */
|
|
273
|
+
export const EXHAUST = { x: -2.1, y: 0.33, z: 0.3 } as const;
|
|
274
|
+
|
|
275
|
+
/** A cone with its base at the origin and its tip `length` down -x: the way a flame leaves a car. */
|
|
276
|
+
function flameCone(radius: number, length: number): BufferGeometry {
|
|
277
|
+
return new ConeGeometry(radius, length, 12, 1, true)
|
|
278
|
+
.rotateZ(Math.PI / 2)
|
|
279
|
+
.translate(-length / 2, 0, 0);
|
|
280
|
+
}
|
|
281
|
+
const FLAME_OUTER = flameCone(0.13, 1.5);
|
|
282
|
+
const FLAME_CORE = flameCone(0.07, 0.85);
|
|
283
|
+
|
|
272
284
|
export function vehicle(materials: Materials): Group {
|
|
273
285
|
const root = new Group();
|
|
274
286
|
const shell = new RigidAssembly();
|
|
@@ -369,6 +381,14 @@ export function vehicle(materials: Materials): Group {
|
|
|
369
381
|
shell.add(bonnet);
|
|
370
382
|
}
|
|
371
383
|
|
|
384
|
+
// Twin exhausts under the tail bar: where the nitro flame comes out, so it has a source.
|
|
385
|
+
for (const side of [-1, 1] as const) {
|
|
386
|
+
const pipe = part(new CylinderGeometry(0.075, 0.085, 0.22, 12), materials.alloy);
|
|
387
|
+
pipe.rotation.z = Math.PI / 2;
|
|
388
|
+
pipe.position.set(EXHAUST.x + 0.08, EXHAUST.y, side * EXHAUST.z);
|
|
389
|
+
shell.add(pipe);
|
|
390
|
+
}
|
|
391
|
+
|
|
372
392
|
// A tail light bar across the full width. The tail is where the wing, the diffuser and the body
|
|
373
393
|
// all meet, and without one bright horizontal the eye finds nothing to hold there — which
|
|
374
394
|
// matters more than any other detail, because the chase camera looks at this face all game.
|
|
@@ -411,6 +431,23 @@ export function vehicle(materials: Materials): Group {
|
|
|
411
431
|
const body = new Group();
|
|
412
432
|
body.name = "body";
|
|
413
433
|
shell.attachTo(body);
|
|
434
|
+
// The nitro flame: an outer cone and a hotter core behind each exhaust, hidden until a burn.
|
|
435
|
+
// It rides on the body, so it leans with it, and `CarBody` stretches it along -x as it flickers.
|
|
436
|
+
const flame = new Group();
|
|
437
|
+
flame.name = "nitro-flame";
|
|
438
|
+
flame.visible = false;
|
|
439
|
+
for (const side of [-1, 1] as const) {
|
|
440
|
+
const outer = new Mesh(FLAME_OUTER, materials.flame);
|
|
441
|
+
outer.position.set(EXHAUST.x, EXHAUST.y, side * EXHAUST.z);
|
|
442
|
+
const core = new Mesh(FLAME_CORE, materials.flameCore);
|
|
443
|
+
core.position.copy(outer.position);
|
|
444
|
+
for (const cone of [outer, core]) {
|
|
445
|
+
cone.castShadow = false;
|
|
446
|
+
cone.frustumCulled = false;
|
|
447
|
+
flame.add(cone);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
body.add(flame);
|
|
414
451
|
root.add(body);
|
|
415
452
|
return root;
|
|
416
453
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js — edit or delete it freely.
|
|
2
|
+
// ThreeNative does not read this file.
|
|
3
|
+
//
|
|
4
|
+
// Skid marks: a dark rubber strip behind each rear tyre in a slide or under a locked brake, one
|
|
5
|
+
// segment per mark in an instanced ring, so the oldest mark is reused when the ring is full. One
|
|
6
|
+
// draw call for the whole field.
|
|
7
|
+
import { Color, InstancedMesh, MeshStandardMaterial, Object3D, PlaneGeometry } from "three";
|
|
8
|
+
|
|
9
|
+
/** The tarmac and the tyre, as `materials.ts` paints them. */
|
|
10
|
+
const ROAD = 0x4a4a4a;
|
|
11
|
+
const TYRE = 0x1a1d22;
|
|
12
|
+
|
|
13
|
+
export class SkidMarks {
|
|
14
|
+
readonly #mesh: InstancedMesh;
|
|
15
|
+
readonly #dummy = new Object3D();
|
|
16
|
+
#next = 0;
|
|
17
|
+
/** Where each tyre's trail ends, by the key the race lays it under. */
|
|
18
|
+
readonly #ends = new Map<string, { x: number; y: number; z: number }>();
|
|
19
|
+
laid = 0;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
group: Object3D,
|
|
23
|
+
readonly capacity = 6000,
|
|
24
|
+
) {
|
|
25
|
+
// Opaque rubber, most of the way from the tarmac to the tyre: see-through strips darkened
|
|
26
|
+
// wherever two trails crossed or two segments met, and a line read as a brick pattern.
|
|
27
|
+
const material = new MeshStandardMaterial({
|
|
28
|
+
color: new Color(ROAD).lerp(new Color(TYRE), 0.72),
|
|
29
|
+
polygonOffset: true,
|
|
30
|
+
polygonOffsetFactor: -2,
|
|
31
|
+
roughness: 0.9,
|
|
32
|
+
});
|
|
33
|
+
// One metre long, scaled to each segment, so a trail's segments meet end to end. 0.34 m wide:
|
|
34
|
+
// a racing tyre's tread is a third of a metre, and at 0.26 the strip read as a seam in the
|
|
35
|
+
// tarmac from the chase camera rather than as rubber.
|
|
36
|
+
this.#mesh = new InstancedMesh(
|
|
37
|
+
new PlaneGeometry(0.34, 1).rotateX(-Math.PI / 2),
|
|
38
|
+
material,
|
|
39
|
+
capacity,
|
|
40
|
+
);
|
|
41
|
+
// A fixed count, with the unused dashes at zero scale: the ring only rewrites matrices, so the
|
|
42
|
+
// draw never changes size while the race runs.
|
|
43
|
+
const hidden = new Object3D();
|
|
44
|
+
hidden.scale.setScalar(0);
|
|
45
|
+
hidden.updateMatrix();
|
|
46
|
+
for (let i = 0; i < capacity; i += 1) this.#mesh.setMatrixAt(i, hidden.matrix);
|
|
47
|
+
this.#mesh.name = "skid-marks";
|
|
48
|
+
this.#mesh.frustumCulled = false;
|
|
49
|
+
this.#mesh.receiveShadow = true;
|
|
50
|
+
group.add(this.#mesh);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A mark from where this tyre's trail ends up to its contact point, so the trail is one strip
|
|
55
|
+
* whose segments meet end to end: a trail joined by nearness alone jumped to the next tyre and laid a zigzag.
|
|
56
|
+
* A trail end more than 4 m away starts a new trail (a car on nitro covers 0.4 m between
|
|
57
|
+
* two marks), and a new trail lays nothing yet.
|
|
58
|
+
*/
|
|
59
|
+
lay(trail: string, x: number, y: number, z: number): void {
|
|
60
|
+
const from = this.#ends.get(trail);
|
|
61
|
+
const gap =
|
|
62
|
+
from === undefined ? Number.POSITIVE_INFINITY : (x - from.x) ** 2 + (z - from.z) ** 2;
|
|
63
|
+
if (from === undefined || gap > 4 * 4) {
|
|
64
|
+
this.#ends.set(trail, { x, y, z });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
// Half a metre a segment: 6 000 of them is three kilometres of rubber before the ring reuses.
|
|
68
|
+
if (gap < 0.5 * 0.5) return;
|
|
69
|
+
const d = this.#dummy;
|
|
70
|
+
// Pitched along the road, not flat: a level segment on a slope sinks one half under the
|
|
71
|
+
// asphalt, and the trail reads as dashes.
|
|
72
|
+
d.position.set((x + from.x) / 2, (y + from.y) / 2 + 0.03, (z + from.z) / 2);
|
|
73
|
+
d.lookAt(x, y + 0.03, z);
|
|
74
|
+
d.scale.set(1, 1, Math.hypot(Math.sqrt(gap), y - from.y));
|
|
75
|
+
from.x = x;
|
|
76
|
+
from.y = y;
|
|
77
|
+
from.z = z;
|
|
78
|
+
d.updateMatrix();
|
|
79
|
+
this.#mesh.setMatrixAt(this.#next, d.matrix);
|
|
80
|
+
this.#next = (this.#next + 1) % this.capacity;
|
|
81
|
+
this.#mesh.instanceMatrix.needsUpdate = true;
|
|
82
|
+
this.laid += 1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -15,6 +15,9 @@ const MOVE_RADIUS = 72;
|
|
|
15
15
|
const BUTTON_RADIUS = 58;
|
|
16
16
|
const EDGE = 36;
|
|
17
17
|
|
|
18
|
+
/** The knob's next point: `update` runs every frame, so it uses one instance. */
|
|
19
|
+
const knobPosition = new Vector2();
|
|
20
|
+
|
|
18
21
|
export interface ITouchPointer {
|
|
19
22
|
readonly position: Vector2;
|
|
20
23
|
}
|
|
@@ -66,7 +69,6 @@ export class TouchControls {
|
|
|
66
69
|
brakePressed: false,
|
|
67
70
|
move: new Vector2(),
|
|
68
71
|
};
|
|
69
|
-
#wasBoost = false;
|
|
70
72
|
#wasBrake = false;
|
|
71
73
|
#moveAnchor = new Vector2();
|
|
72
74
|
#resting = new Vector2();
|
|
@@ -122,18 +124,16 @@ export class TouchControls {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
const center = this.#hasMoveAnchor ? this.#moveAnchor : this.#resting;
|
|
125
|
-
|
|
126
|
-
this.#
|
|
127
|
-
|
|
128
|
-
center.x + this.#input.move.x * MOVE_RADIUS,
|
|
129
|
-
center.y - this.#input.move.y * MOVE_RADIUS,
|
|
130
|
-
),
|
|
127
|
+
knobPosition.set(
|
|
128
|
+
center.x + this.#input.move.x * MOVE_RADIUS,
|
|
129
|
+
center.y - this.#input.move.y * MOVE_RADIUS,
|
|
131
130
|
);
|
|
131
|
+
place(this.#moveKnob, knobPosition);
|
|
132
132
|
this.#boost.material = boost ? this.#activeMaterial : this.#idleMaterial;
|
|
133
133
|
this.#brake.material = brake ? this.#activeMaterial : this.#idleMaterial;
|
|
134
|
-
|
|
134
|
+
// Held, not an edge: nitro burns while the button is down.
|
|
135
|
+
this.#input.boostPressed = boost;
|
|
135
136
|
this.#input.brakePressed = brake;
|
|
136
|
-
this.#wasBoost = boost;
|
|
137
137
|
this.#wasBrake = brake;
|
|
138
138
|
this.#layout(size);
|
|
139
139
|
return this.#input;
|
|
@@ -141,7 +141,7 @@ export class TouchControls {
|
|
|
141
141
|
|
|
142
142
|
debug(): Record<string, unknown> {
|
|
143
143
|
return {
|
|
144
|
-
boost: this.#
|
|
144
|
+
boost: this.#input.boostPressed,
|
|
145
145
|
brake: this.#wasBrake,
|
|
146
146
|
move: this.#input.move.toArray(),
|
|
147
147
|
};
|