create-threenative 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +283 -0
- package/dist/threenative.d.ts +6 -0
- package/dist/threenative.js +757 -0
- package/package.json +44 -0
- package/templates/action-rpg/.mcp.json +16 -0
- package/templates/action-rpg/AGENTS.md +40 -0
- package/templates/action-rpg/CLAUDE.md +42 -0
- package/templates/action-rpg/index.html +13 -0
- package/templates/action-rpg/kit.json +7 -0
- package/templates/action-rpg/package.json +47 -0
- package/templates/action-rpg/playtests/combat.playtest.json +61 -0
- package/templates/action-rpg/playtests/fail.playtest.json +21 -0
- package/templates/action-rpg/playtests/inventory.playtest.json +111 -0
- package/templates/action-rpg/playtests/progress.playtest.json +99 -0
- package/templates/action-rpg/playtests/survives.playtest.json +32 -0
- package/templates/action-rpg/playtests/win.playtest.json +30 -0
- package/templates/action-rpg/public/favicon.svg +5 -0
- package/templates/action-rpg/src/abilities/Ability.ts +45 -0
- package/templates/action-rpg/src/entities/Enemy.ts +143 -0
- package/templates/action-rpg/src/entities/Player.ts +83 -0
- package/templates/action-rpg/src/game.ts +40 -0
- package/templates/action-rpg/src/items/Inventory.ts +163 -0
- package/templates/action-rpg/src/loot/drops.ts +40 -0
- package/templates/action-rpg/src/main.ts +15 -0
- package/templates/action-rpg/src/physics.ts +40 -0
- package/templates/action-rpg/src/playtest-events.ts +15 -0
- package/templates/action-rpg/src/progress.ts +35 -0
- package/templates/action-rpg/src/render/camera.ts +26 -0
- package/templates/action-rpg/src/render/lighting.ts +30 -0
- package/templates/action-rpg/src/render/loading.ts +90 -0
- package/templates/action-rpg/src/render/materials.ts +40 -0
- package/templates/action-rpg/src/render/palette.ts +9 -0
- package/templates/action-rpg/src/render/postprocessing.ts +18 -0
- package/templates/action-rpg/src/render/shapes.ts +110 -0
- package/templates/action-rpg/src/render/sky.ts +18 -0
- package/templates/action-rpg/src/render/types.ts +3 -0
- package/templates/action-rpg/src/scenes/Boot.ts +12 -0
- package/templates/action-rpg/src/scenes/Play.ts +449 -0
- package/templates/action-rpg/src/state.ts +40 -0
- package/templates/action-rpg/src/stats/StatBlock.ts +57 -0
- package/templates/action-rpg/src/style.css +32 -0
- package/templates/action-rpg/src/ui/AbilityBar.tsx +28 -0
- package/templates/action-rpg/src/ui/App.tsx +21 -0
- package/templates/action-rpg/src/ui/CharacterPanel.tsx +31 -0
- package/templates/action-rpg/src/ui/Hud.tsx +29 -0
- package/templates/action-rpg/src/ui/InventoryPanel.tsx +37 -0
- package/templates/action-rpg/tailwind.config.ts +7 -0
- package/templates/action-rpg/threenative.config.ts +29 -0
- package/templates/action-rpg/tsconfig.json +17 -0
- package/templates/action-rpg/vite.config.ts +8 -0
- package/templates/defense/.mcp.json +16 -0
- package/templates/defense/AGENTS.md +53 -0
- package/templates/defense/CLAUDE.md +55 -0
- package/templates/defense/README.md +9 -0
- package/templates/defense/index.html +13 -0
- package/templates/defense/kit.json +7 -0
- package/templates/defense/package.json +46 -0
- package/templates/defense/playtests/leak.playtest.json +18 -0
- package/templates/defense/playtests/placement.playtest.json +40 -0
- package/templates/defense/playtests/scan.playtest.json +20 -0
- package/templates/defense/playtests/survive.playtest.json +26 -0
- package/templates/defense/playtests/survives.playtest.json +36 -0
- package/templates/defense/public/favicon.svg +5 -0
- package/templates/defense/src/attackers/Attacker.ts +104 -0
- package/templates/defense/src/board/Route.ts +80 -0
- package/templates/defense/src/economy.ts +36 -0
- package/templates/defense/src/entities/Player.ts +44 -0
- package/templates/defense/src/game.ts +30 -0
- package/templates/defense/src/main.ts +15 -0
- package/templates/defense/src/physics.ts +43 -0
- package/templates/defense/src/placement/Buildable.ts +49 -0
- package/templates/defense/src/playtest-events.ts +15 -0
- package/templates/defense/src/render/camera.ts +10 -0
- package/templates/defense/src/render/lighting.ts +32 -0
- package/templates/defense/src/render/loading.ts +89 -0
- package/templates/defense/src/render/materials.ts +13 -0
- package/templates/defense/src/render/palette.ts +21 -0
- package/templates/defense/src/render/postprocessing.ts +14 -0
- package/templates/defense/src/render/shapes.ts +89 -0
- package/templates/defense/src/render/sky.ts +45 -0
- package/templates/defense/src/scenes/Boot.ts +12 -0
- package/templates/defense/src/scenes/Defense.ts +165 -0
- package/templates/defense/src/state.ts +50 -0
- package/templates/defense/src/style.css +32 -0
- package/templates/defense/src/towers/Tower.ts +96 -0
- package/templates/defense/src/towers/targeting.ts +53 -0
- package/templates/defense/src/ui/App.tsx +17 -0
- package/templates/defense/src/ui/Hud.tsx +61 -0
- package/templates/defense/src/ui/Menu.tsx +7 -0
- package/templates/defense/src/waves.ts +40 -0
- package/templates/defense/tailwind.config.ts +1 -0
- package/templates/defense/threenative.config.ts +29 -0
- package/templates/defense/tsconfig.json +17 -0
- package/templates/defense/vite.config.ts +5 -0
- package/templates/minimal/.mcp.json +16 -0
- package/templates/minimal/AGENTS.md +400 -0
- package/templates/minimal/CLAUDE.md +402 -0
- package/templates/minimal/assets/.gitkeep +0 -0
- package/templates/minimal/index.html +14 -0
- package/templates/minimal/kit.json +7 -0
- package/templates/minimal/package.json +40 -0
- package/templates/minimal/playtests/play.playtest.json +32 -0
- package/templates/minimal/playtests/survives.playtest.json +32 -0
- package/templates/minimal/public/.gitkeep +0 -0
- package/templates/minimal/public/favicon.svg +4 -0
- package/templates/minimal/public/icon.png +0 -0
- package/templates/minimal/src/entities/Player.ts +66 -0
- package/templates/minimal/src/game.ts +28 -0
- package/templates/minimal/src/main.ts +17 -0
- package/templates/minimal/src/render/camera.ts +11 -0
- package/templates/minimal/src/render/hud.ts +53 -0
- package/templates/minimal/src/render/lighting.ts +46 -0
- package/templates/minimal/src/render/loading.ts +113 -0
- package/templates/minimal/src/render/materials.ts +16 -0
- package/templates/minimal/src/render/palette.ts +9 -0
- package/templates/minimal/src/render/postprocessing.ts +20 -0
- package/templates/minimal/src/render/sky.ts +41 -0
- package/templates/minimal/src/scenes/Boot.ts +5 -0
- package/templates/minimal/src/scenes/Play.ts +65 -0
- package/templates/minimal/src/state.ts +1 -0
- package/templates/minimal/src/style.css +41 -0
- package/templates/minimal/threenative.config.ts +32 -0
- package/templates/minimal/tsconfig.json +16 -0
- package/templates/minimal/vite.config.ts +3 -0
- package/templates/platformer/.mcp.json +16 -0
- package/templates/platformer/AGENTS.md +199 -0
- package/templates/platformer/CLAUDE.md +201 -0
- package/templates/platformer/assets/.gitkeep +0 -0
- package/templates/platformer/index.html +13 -0
- package/templates/platformer/kit.json +7 -0
- package/templates/platformer/package.json +50 -0
- package/templates/platformer/playtests/avoidance.playtest.json +23 -0
- package/templates/platformer/playtests/buffer.playtest.json +17 -0
- package/templates/platformer/playtests/chase.playtest.json +21 -0
- package/templates/platformer/playtests/collect.playtest.json +56 -0
- package/templates/platformer/playtests/collision-layers.playtest.json +36 -0
- package/templates/platformer/playtests/coyote.playtest.json +21 -0
- package/templates/platformer/playtests/damage.playtest.json +31 -0
- package/templates/platformer/playtests/dash.playtest.json +21 -0
- package/templates/platformer/playtests/jump.playtest.json +21 -0
- package/templates/platformer/playtests/oneway.playtest.json +17 -0
- package/templates/platformer/playtests/patrol.playtest.json +13 -0
- package/templates/platformer/playtests/performance.playtest.json +21 -0
- package/templates/platformer/playtests/physics.playtest.json +14 -0
- package/templates/platformer/playtests/respawn.playtest.json +31 -0
- package/templates/platformer/playtests/stomp-rise.playtest.json +41 -0
- package/templates/platformer/playtests/stomp.playtest.json +34 -0
- package/templates/platformer/playtests/survives.playtest.json +32 -0
- package/templates/platformer/playtests/terminal-loop-fail.playtest.json +29 -0
- package/templates/platformer/playtests/terminal-loop-win.playtest.json +52 -0
- package/templates/platformer/public/.gitkeep +0 -0
- package/templates/platformer/public/favicon.svg +4 -0
- package/templates/platformer/public/icon.png +0 -0
- package/templates/platformer/src/entities/Character.ts +218 -0
- package/templates/platformer/src/entities/Chaser.ts +118 -0
- package/templates/platformer/src/entities/Patrol.ts +88 -0
- package/templates/platformer/src/entities/Pickup.ts +72 -0
- package/templates/platformer/src/game.ts +27 -0
- package/templates/platformer/src/level/Checkpoints.ts +66 -0
- package/templates/platformer/src/level/Platform.ts +34 -0
- package/templates/platformer/src/main.ts +14 -0
- package/templates/platformer/src/playtest-events.ts +15 -0
- package/templates/platformer/src/render/camera.ts +8 -0
- package/templates/platformer/src/render/lighting.ts +38 -0
- package/templates/platformer/src/render/loading.ts +113 -0
- package/templates/platformer/src/render/materials.ts +11 -0
- package/templates/platformer/src/render/palette.ts +54 -0
- package/templates/platformer/src/render/postprocessing.ts +18 -0
- package/templates/platformer/src/render/rig.ts +60 -0
- package/templates/platformer/src/render/sky.ts +47 -0
- package/templates/platformer/src/render/terrain.ts +31 -0
- package/templates/platformer/src/render/touch-controls.ts +157 -0
- package/templates/platformer/src/render/touch-layout.ts +63 -0
- package/templates/platformer/src/scenes/Boot.ts +12 -0
- package/templates/platformer/src/scenes/Level.ts +176 -0
- package/templates/platformer/src/state.ts +23 -0
- package/templates/platformer/src/style.css +31 -0
- package/templates/platformer/src/ui/App.tsx +17 -0
- package/templates/platformer/src/ui/Hud.tsx +41 -0
- package/templates/platformer/src/ui/Menu.tsx +7 -0
- package/templates/platformer/tailwind.config.ts +2 -0
- package/templates/platformer/threenative.config.ts +32 -0
- package/templates/platformer/tsconfig.json +17 -0
- package/templates/platformer/vite.config.ts +5 -0
- package/templates/racing/.mcp.json +16 -0
- package/templates/racing/AGENTS.md +48 -0
- package/templates/racing/CLAUDE.md +50 -0
- package/templates/racing/index.html +13 -0
- package/templates/racing/kit.json +7 -0
- package/templates/racing/package.json +46 -0
- package/templates/racing/playtests/boost.playtest.json +45 -0
- package/templates/racing/playtests/outcome.playtest.json +78 -0
- package/templates/racing/playtests/ranking.playtest.json +37 -0
- package/templates/racing/playtests/rescue.playtest.json +28 -0
- package/templates/racing/playtests/reverse.playtest.json +37 -0
- package/templates/racing/playtests/shortcut.playtest.json +44 -0
- package/templates/racing/playtests/survives.playtest.json +32 -0
- package/templates/racing/public/favicon.svg +6 -0
- package/templates/racing/src/entities/RacingCar.ts +114 -0
- package/templates/racing/src/entities/Rival.ts +46 -0
- package/templates/racing/src/game.ts +29 -0
- package/templates/racing/src/kart/boost.ts +38 -0
- package/templates/racing/src/main.ts +15 -0
- package/templates/racing/src/playtest-events.ts +15 -0
- package/templates/racing/src/render/camera.ts +28 -0
- package/templates/racing/src/render/lighting.ts +32 -0
- package/templates/racing/src/render/loading.ts +58 -0
- package/templates/racing/src/render/materials.ts +15 -0
- package/templates/racing/src/render/palette.ts +30 -0
- package/templates/racing/src/render/postprocessing.ts +14 -0
- package/templates/racing/src/render/shapes.ts +37 -0
- package/templates/racing/src/render/sky.ts +45 -0
- package/templates/racing/src/scenes/Boot.ts +12 -0
- package/templates/racing/src/scenes/Race.ts +180 -0
- package/templates/racing/src/state.ts +35 -0
- package/templates/racing/src/style.css +32 -0
- package/templates/racing/src/track/Checkline.ts +19 -0
- package/templates/racing/src/track/Lap.ts +104 -0
- package/templates/racing/src/track/Ranking.ts +35 -0
- package/templates/racing/src/track/Track.ts +229 -0
- package/templates/racing/src/track/TrackSector.ts +77 -0
- package/templates/racing/src/track/rescue.ts +21 -0
- package/templates/racing/src/ui/App.tsx +17 -0
- package/templates/racing/src/ui/Hud.tsx +71 -0
- package/templates/racing/src/ui/Menu.tsx +7 -0
- package/templates/racing/tailwind.config.ts +2 -0
- package/templates/racing/threenative.config.ts +29 -0
- package/templates/racing/tsconfig.json +17 -0
- package/templates/racing/vite.config.ts +5 -0
- package/templates/shooter/.mcp.json +16 -0
- package/templates/shooter/AGENTS.md +69 -0
- package/templates/shooter/CLAUDE.md +71 -0
- package/templates/shooter/index.html +13 -0
- package/templates/shooter/kit.json +7 -0
- package/templates/shooter/package.json +46 -0
- package/templates/shooter/playtests/fail.playtest.json +30 -0
- package/templates/shooter/playtests/shooter.playtest.json +89 -0
- package/templates/shooter/playtests/survives.playtest.json +32 -0
- package/templates/shooter/public/favicon.svg +4 -0
- package/templates/shooter/src/combat/damage.ts +41 -0
- package/templates/shooter/src/entities/Pickup.ts +70 -0
- package/templates/shooter/src/entities/Player.ts +93 -0
- package/templates/shooter/src/entities/Target.ts +103 -0
- package/templates/shooter/src/game.ts +36 -0
- package/templates/shooter/src/level/SpawnPoints.ts +28 -0
- package/templates/shooter/src/main.ts +26 -0
- package/templates/shooter/src/physics.ts +49 -0
- package/templates/shooter/src/playtest-events.ts +15 -0
- package/templates/shooter/src/render/camera.ts +29 -0
- package/templates/shooter/src/render/lighting.ts +38 -0
- package/templates/shooter/src/render/loading.ts +86 -0
- package/templates/shooter/src/render/materials.ts +38 -0
- package/templates/shooter/src/render/palette.ts +9 -0
- package/templates/shooter/src/render/postprocessing.ts +19 -0
- package/templates/shooter/src/render/shapes.ts +194 -0
- package/templates/shooter/src/render/sky.ts +37 -0
- package/templates/shooter/src/render/types.ts +3 -0
- package/templates/shooter/src/render/ui.css +212 -0
- package/templates/shooter/src/render/ui.ts +59 -0
- package/templates/shooter/src/scenes/Boot.ts +12 -0
- package/templates/shooter/src/scenes/Play.ts +428 -0
- package/templates/shooter/src/state.ts +29 -0
- package/templates/shooter/src/ui/App.tsx +25 -0
- package/templates/shooter/src/ui/Hud.tsx +49 -0
- package/templates/shooter/src/ui/Menu.tsx +26 -0
- package/templates/shooter/src/waves.ts +50 -0
- package/templates/shooter/src/weapons/Hitscan.ts +43 -0
- package/templates/shooter/src/weapons/Projectile.ts +76 -0
- package/templates/shooter/tailwind.config.ts +5 -0
- package/templates/shooter/threenative.config.ts +29 -0
- package/templates/shooter/tsconfig.json +17 -0
- package/templates/shooter/vite.config.ts +8 -0
- package/templates/starter/.mcp.json +16 -0
- package/templates/starter/AGENTS.md +450 -0
- package/templates/starter/CLAUDE.md +452 -0
- package/templates/starter/assets/.gitkeep +0 -0
- package/templates/starter/index.html +13 -0
- package/templates/starter/kit.json +7 -0
- package/templates/starter/package.json +49 -0
- package/templates/starter/playtests/buffer.playtest.json +29 -0
- package/templates/starter/playtests/coyote.playtest.json +35 -0
- package/templates/starter/playtests/forward.playtest.json +15 -0
- package/templates/starter/playtests/hot-reload.playtest.json +28 -0
- package/templates/starter/playtests/look.playtest.json +43 -0
- package/templates/starter/playtests/monitoring.playtest.json +41 -0
- package/templates/starter/playtests/pause.playtest.json +33 -0
- package/templates/starter/playtests/play.playtest.json +16 -0
- package/templates/starter/playtests/respawn.playtest.json +28 -0
- package/templates/starter/playtests/restart.playtest.json +36 -0
- package/templates/starter/playtests/seed.playtest.json +18 -0
- package/templates/starter/playtests/survives.playtest.json +32 -0
- package/templates/starter/public/.gitkeep +0 -0
- package/templates/starter/public/favicon.svg +4 -0
- package/templates/starter/public/icon.png +0 -0
- package/templates/starter/public/native-proof.glb +0 -0
- package/templates/starter/public/native-proof.png +0 -0
- package/templates/starter/public/pickup.ogg +0 -0
- package/templates/starter/src/entities/Crate.ts +34 -0
- package/templates/starter/src/entities/Player.ts +80 -0
- package/templates/starter/src/game.ts +30 -0
- package/templates/starter/src/main.ts +15 -0
- package/templates/starter/src/render/camera.ts +57 -0
- package/templates/starter/src/render/lighting.ts +55 -0
- package/templates/starter/src/render/materials.ts +12 -0
- package/templates/starter/src/render/palette.ts +9 -0
- package/templates/starter/src/render/postprocessing.ts +18 -0
- package/templates/starter/src/render/shapes.ts +147 -0
- package/templates/starter/src/render/sky.ts +56 -0
- package/templates/starter/src/scenes/Play.ts +161 -0
- package/templates/starter/src/state.ts +10 -0
- package/templates/starter/src/style.css +45 -0
- package/templates/starter/src/ui/App.tsx +19 -0
- package/templates/starter/src/ui/Hud.tsx +37 -0
- package/templates/starter/src/ui/Menu.tsx +43 -0
- package/templates/starter/tailwind.config.ts +2 -0
- package/templates/starter/threenative.config.ts +31 -0
- package/templates/starter/tsconfig.json +17 -0
- package/templates/starter/vite.config.ts +8 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ICtx } from "@threenative/core";
|
|
2
|
+
import { CharacterBody3D, CollisionShape3D, type IPhysicsContext } from "@threenative/physics";
|
|
3
|
+
import { Group, Vector3 } from "three";
|
|
4
|
+
import { Boost } from "../kart/boost.js";
|
|
5
|
+
import { createMaterials } from "../render/materials.js";
|
|
6
|
+
import { vehicle } from "../render/shapes.js";
|
|
7
|
+
import type { GameState } from "../state.js";
|
|
8
|
+
|
|
9
|
+
type GameCtx = ICtx<GameState, IPhysicsContext>;
|
|
10
|
+
|
|
11
|
+
export const RACING_FEEL = {
|
|
12
|
+
acceleration: 9.5,
|
|
13
|
+
brake: 20,
|
|
14
|
+
drag: 2.6,
|
|
15
|
+
gravity: -24,
|
|
16
|
+
maxFallSpeed: 30,
|
|
17
|
+
maxSpeed: 9,
|
|
18
|
+
turnRate: 2.25,
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export class RacingCar {
|
|
22
|
+
readonly mesh = new Group();
|
|
23
|
+
readonly body: CharacterBody3D;
|
|
24
|
+
readonly forward = new Vector3(1, 0, 0);
|
|
25
|
+
readonly travelDirection = new Vector3(1, 0, 0);
|
|
26
|
+
readonly boost = new Boost();
|
|
27
|
+
#speed = 0;
|
|
28
|
+
#heading = 0;
|
|
29
|
+
#topSpeed = 0;
|
|
30
|
+
|
|
31
|
+
constructor(ctx: GameCtx, spawn: Vector3) {
|
|
32
|
+
this.mesh.position.copy(spawn);
|
|
33
|
+
this.mesh.castShadow = true;
|
|
34
|
+
this.mesh.add(vehicle(createMaterials()));
|
|
35
|
+
ctx.add(this.mesh);
|
|
36
|
+
this.body = new CharacterBody3D({
|
|
37
|
+
autostep: { maxHeight: 0.25, minWidth: 0.2 },
|
|
38
|
+
collisionLayer: 1,
|
|
39
|
+
collisionMask: 6,
|
|
40
|
+
gravity: RACING_FEEL.gravity,
|
|
41
|
+
maxFallSpeed: RACING_FEEL.maxFallSpeed,
|
|
42
|
+
object: this.mesh,
|
|
43
|
+
physics: ctx.physics,
|
|
44
|
+
shape: CollisionShape3D.box(2.7, 0.35, 1.6),
|
|
45
|
+
snapToGround: 0.25,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
update(ctx: GameCtx, dt: number): void {
|
|
50
|
+
this.boost.update(dt);
|
|
51
|
+
if (ctx.input.justPressed("boost")) this.boost.activate();
|
|
52
|
+
const move = ctx.input.vector("move");
|
|
53
|
+
const throttle = move.y;
|
|
54
|
+
const target =
|
|
55
|
+
throttle * RACING_FEEL.maxSpeed * (this.boost.active ? this.boost.multiplier : 1);
|
|
56
|
+
const rate =
|
|
57
|
+
Math.abs(target) > Math.abs(this.#speed) ? RACING_FEEL.acceleration : RACING_FEEL.drag;
|
|
58
|
+
this.#speed = approach(this.#speed, target, rate * dt);
|
|
59
|
+
if (ctx.input.pressed("brake")) this.#speed = approach(this.#speed, 0, RACING_FEEL.brake * dt);
|
|
60
|
+
const steering =
|
|
61
|
+
move.x * (Math.min(1, Math.abs(this.#speed) / RACING_FEEL.maxSpeed) * 0.65 + 0.35);
|
|
62
|
+
this.#heading += steering * RACING_FEEL.turnRate * dt * (this.#speed < 0 ? -1 : 1);
|
|
63
|
+
this.forward.set(Math.cos(this.#heading), 0, Math.sin(this.#heading));
|
|
64
|
+
this.travelDirection.copy(this.forward).multiplyScalar(this.#speed < -0.05 ? -1 : 1);
|
|
65
|
+
this.mesh.rotation.y = this.#heading;
|
|
66
|
+
this.body.velocity.x = this.forward.x * this.#speed;
|
|
67
|
+
this.body.velocity.z = this.forward.z * this.#speed;
|
|
68
|
+
this.body.moveAndSlide(dt);
|
|
69
|
+
this.#topSpeed = Math.max(this.#topSpeed, Math.abs(this.#speed));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setHeading(heading: Vector3): void {
|
|
73
|
+
const flat = heading.clone().setY(0);
|
|
74
|
+
if (flat.lengthSq() < 0.0001) return;
|
|
75
|
+
flat.normalize();
|
|
76
|
+
this.#heading = Math.atan2(flat.z, flat.x);
|
|
77
|
+
this.forward.copy(flat);
|
|
78
|
+
this.travelDirection.copy(flat);
|
|
79
|
+
this.mesh.rotation.y = this.#heading;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
speedAfterBoost(): number {
|
|
83
|
+
return this.boost.active ? 0 : Math.abs(this.#speed);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get speed(): number {
|
|
87
|
+
return Math.abs(this.#speed);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
get topSpeed(): number {
|
|
91
|
+
return this.#topSpeed;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
debug(): Record<string, unknown> {
|
|
95
|
+
return {
|
|
96
|
+
boostActive: this.boost.active,
|
|
97
|
+
heading: this.#heading,
|
|
98
|
+
position: this.mesh.position.toArray(),
|
|
99
|
+
speed: this.speed,
|
|
100
|
+
topSpeed: this.#topSpeed,
|
|
101
|
+
travelDirection: this.travelDirection.toArray(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
dispose(): void {
|
|
106
|
+
this.body.dispose();
|
|
107
|
+
this.mesh.removeFromParent();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function approach(current: number, target: number, delta: number): number {
|
|
112
|
+
const difference = target - current;
|
|
113
|
+
return Math.abs(difference) <= delta ? target : current + Math.sign(difference) * delta;
|
|
114
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PathFollow3D } from "@threenative/core";
|
|
2
|
+
import { Group, Vector3 } from "three";
|
|
3
|
+
import { createMaterials } from "../render/materials.js";
|
|
4
|
+
import { vehicle } from "../render/shapes.js";
|
|
5
|
+
|
|
6
|
+
export class Rival {
|
|
7
|
+
readonly mesh = new Group();
|
|
8
|
+
readonly travelDirection = new Vector3(1, 0, 0);
|
|
9
|
+
#distance: number;
|
|
10
|
+
#lap = 0;
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
private readonly route: PathFollow3D,
|
|
14
|
+
startDistance: number,
|
|
15
|
+
) {
|
|
16
|
+
this.#distance = startDistance;
|
|
17
|
+
const visual = vehicle(createMaterials());
|
|
18
|
+
visual.scale.setScalar(0.92);
|
|
19
|
+
this.mesh.add(visual);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
update(dt: number): void {
|
|
23
|
+
this.#distance += 7.6 * dt;
|
|
24
|
+
this.#lap = Math.floor(this.#distance / this.route.totalLength);
|
|
25
|
+
const sample = this.route.pointAt(this.#distance);
|
|
26
|
+
this.mesh.position.copy(sample.point).setY(0.48);
|
|
27
|
+
this.travelDirection.copy(sample.tangent);
|
|
28
|
+
this.mesh.rotation.y = Math.atan2(sample.tangent.z, sample.tangent.x);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get lap(): number {
|
|
32
|
+
return this.#lap;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get distance(): number {
|
|
36
|
+
return this.#distance;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
debug(): Record<string, unknown> {
|
|
40
|
+
return {
|
|
41
|
+
lap: this.#lap,
|
|
42
|
+
position: this.mesh.position.toArray(),
|
|
43
|
+
routeProgress: this.#distance,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { defineGame } from "@threenative/core";
|
|
2
|
+
import { playtest } from "@threenative/core/playtest";
|
|
3
|
+
import { type IPhysicsContext, rapier } from "@threenative/physics";
|
|
4
|
+
import config from "../threenative.config.js";
|
|
5
|
+
import { drainPlaytestEvents as events } from "./playtest-events.js";
|
|
6
|
+
import { Boot } from "./scenes/Boot.js";
|
|
7
|
+
import { Race } from "./scenes/Race.js";
|
|
8
|
+
import type { GameState } from "./state.js";
|
|
9
|
+
|
|
10
|
+
export default defineGame<GameState, IPhysicsContext>({
|
|
11
|
+
input: {
|
|
12
|
+
// The four directions of `input.vector("move")`. Declared rather than inherited from the
|
|
13
|
+
// default binding, so the axis every scene reads is visible where the game is defined.
|
|
14
|
+
move: {
|
|
15
|
+
down: ["ArrowDown", "KeyS"],
|
|
16
|
+
left: ["ArrowLeft", "KeyA"],
|
|
17
|
+
right: ["ArrowRight", "KeyD"],
|
|
18
|
+
up: ["ArrowUp", "KeyW"],
|
|
19
|
+
},
|
|
20
|
+
brake: { buttons: [1], keys: ["ShiftLeft", "ShiftRight"] },
|
|
21
|
+
boost: { buttons: [0], keys: ["Space"] },
|
|
22
|
+
restart: { keys: ["KeyR"] },
|
|
23
|
+
},
|
|
24
|
+
plugins: [rapier({ gravity: { x: 0, y: -24, z: 0 } }), playtest({ events })],
|
|
25
|
+
render: config.renderer,
|
|
26
|
+
scenes: { boot: Boot, race: Race },
|
|
27
|
+
seed: 90210,
|
|
28
|
+
start: "boot",
|
|
29
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class Boost {
|
|
2
|
+
readonly duration: number;
|
|
3
|
+
readonly multiplier: number;
|
|
4
|
+
#remaining = 0;
|
|
5
|
+
#uses = 0;
|
|
6
|
+
|
|
7
|
+
constructor(duration = 1.4, multiplier = 1.8) {
|
|
8
|
+
if (!(duration > 0) || !(multiplier > 1))
|
|
9
|
+
throw new Error("Boost duration must be positive and multiplier must exceed one.");
|
|
10
|
+
this.duration = duration;
|
|
11
|
+
this.multiplier = multiplier;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get active(): boolean {
|
|
15
|
+
return this.#remaining > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get remaining(): number {
|
|
19
|
+
return this.#remaining;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get uses(): number {
|
|
23
|
+
return this.#uses;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
activate(): boolean {
|
|
27
|
+
if (this.active) return false;
|
|
28
|
+
this.#remaining = this.duration;
|
|
29
|
+
this.#uses += 1;
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
update(dt: number): void {
|
|
34
|
+
if (!Number.isFinite(dt) || dt < 0)
|
|
35
|
+
throw new Error("Boost.update requires a finite time step.");
|
|
36
|
+
this.#remaining = Math.max(0, this.#remaining - dt);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { acceptHotUpdate } from "@threenative/core/hot";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import game from "./game.js";
|
|
5
|
+
import { App } from "./ui/App.js";
|
|
6
|
+
import "./style.css";
|
|
7
|
+
|
|
8
|
+
import.meta.hot?.accept();
|
|
9
|
+
acceptHotUpdate(game, import.meta.hot);
|
|
10
|
+
const root = document.getElementById("root");
|
|
11
|
+
if (root === null) throw new Error("Missing #root element.");
|
|
12
|
+
const appRoot = root as typeof root & { __threenativeRoot?: ReturnType<typeof createRoot> };
|
|
13
|
+
const reactRoot = appRoot.__threenativeRoot ?? createRoot(appRoot);
|
|
14
|
+
appRoot.__threenativeRoot = reactRoot;
|
|
15
|
+
reactRoot.render(createElement(App, { game }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type PlaytestEvent = {
|
|
2
|
+
readonly [key: string]: string | number;
|
|
3
|
+
readonly entity: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
const pendingEvents: PlaytestEvent[] = [];
|
|
8
|
+
|
|
9
|
+
export function emitPlaytestEvent(event: PlaytestEvent): void {
|
|
10
|
+
pendingEvents.push(event);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function drainPlaytestEvents(): PlaytestEvent[] {
|
|
14
|
+
return pendingEvents.splice(0);
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { MathUtils, type PerspectiveCamera, Vector3 } from "three";
|
|
2
|
+
|
|
3
|
+
export function setupCamera(camera: PerspectiveCamera): void {
|
|
4
|
+
camera.fov = 56;
|
|
5
|
+
camera.near = 0.1;
|
|
6
|
+
camera.far = 180;
|
|
7
|
+
camera.updateProjectionMatrix();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function chaseCamera(
|
|
11
|
+
camera: PerspectiveCamera,
|
|
12
|
+
target: Vector3,
|
|
13
|
+
heading: Vector3,
|
|
14
|
+
dt: number,
|
|
15
|
+
): void {
|
|
16
|
+
const behind = heading.clone().setY(0).normalize().multiplyScalar(-8.5);
|
|
17
|
+
const desired = target
|
|
18
|
+
.clone()
|
|
19
|
+
.add(behind)
|
|
20
|
+
.add(new Vector3(0, 5.8, 0));
|
|
21
|
+
if (dt >= 1) camera.position.copy(desired);
|
|
22
|
+
else camera.position.lerp(desired, 1 - Math.exp(-dt / 0.2));
|
|
23
|
+
camera.lookAt(target.x, target.y + 0.65, target.z);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function cameraRoll(camera: PerspectiveCamera, heading: Vector3): void {
|
|
27
|
+
camera.rotation.z = MathUtils.clamp(-heading.x * 0.018, -0.035, 0.035);
|
|
28
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AmbientLight,
|
|
3
|
+
DirectionalLight,
|
|
4
|
+
HemisphereLight,
|
|
5
|
+
PCFSoftShadowMap,
|
|
6
|
+
type Scene,
|
|
7
|
+
} from "three";
|
|
8
|
+
import { palette } from "./palette.js";
|
|
9
|
+
|
|
10
|
+
type ShadowRenderer = { shadowMap: { enabled: boolean; type: number } };
|
|
11
|
+
|
|
12
|
+
export function setupLighting(scene: Scene, renderer: ShadowRenderer): void {
|
|
13
|
+
renderer.shadowMap.enabled = true;
|
|
14
|
+
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
15
|
+
scene.add(new HemisphereLight(palette.skyLow, palette.shadow, 1.3));
|
|
16
|
+
const key = new DirectionalLight(palette.accent, 3.1);
|
|
17
|
+
key.position.set(-12, 18, -8);
|
|
18
|
+
key.castShadow = true;
|
|
19
|
+
key.shadow.mapSize.set(1024, 1024);
|
|
20
|
+
key.shadow.camera.near = 0.5;
|
|
21
|
+
key.shadow.camera.far = 90;
|
|
22
|
+
key.shadow.camera.left = -45;
|
|
23
|
+
key.shadow.camera.right = 45;
|
|
24
|
+
key.shadow.camera.top = 45;
|
|
25
|
+
key.shadow.camera.bottom = -45;
|
|
26
|
+
key.shadow.normalBias = 0.04;
|
|
27
|
+
scene.add(key);
|
|
28
|
+
const rim = new DirectionalLight(palette.skyLow, 1.15);
|
|
29
|
+
rim.position.set(14, 6, 20);
|
|
30
|
+
scene.add(rim);
|
|
31
|
+
scene.add(new AmbientLight(palette.shadow, 0.22));
|
|
32
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Color, Mesh, MeshBasicMaterial, type OrthographicCamera, PlaneGeometry } from "three";
|
|
2
|
+
|
|
3
|
+
type LoadingContext = {
|
|
4
|
+
readonly canvasLayer: {
|
|
5
|
+
readonly camera: OrthographicCamera;
|
|
6
|
+
readonly scene: { add(...objects: Mesh[]): void; remove(object: Mesh): void };
|
|
7
|
+
opaque: boolean;
|
|
8
|
+
};
|
|
9
|
+
readonly startup: { readonly progress: number; whenReady(): Promise<void> };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function createLoadingScreen(ctx: LoadingContext): { update(): void } {
|
|
13
|
+
const layer = ctx.canvasLayer;
|
|
14
|
+
const backdrop = new Mesh(
|
|
15
|
+
new PlaneGeometry(1, 1),
|
|
16
|
+
new MeshBasicMaterial({ color: new Color(0x07111d) }),
|
|
17
|
+
);
|
|
18
|
+
const track = new Mesh(
|
|
19
|
+
new PlaneGeometry(1, 1),
|
|
20
|
+
new MeshBasicMaterial({ color: new Color(0x16324a) }),
|
|
21
|
+
);
|
|
22
|
+
const fill = new Mesh(
|
|
23
|
+
new PlaneGeometry(1, 1),
|
|
24
|
+
new MeshBasicMaterial({ color: new Color(0xffcf4a) }),
|
|
25
|
+
);
|
|
26
|
+
layer.scene.add(backdrop, track, fill);
|
|
27
|
+
layer.opaque = true;
|
|
28
|
+
let done = false;
|
|
29
|
+
const layout = (): void => {
|
|
30
|
+
const width = layer.camera.right - layer.camera.left;
|
|
31
|
+
const height = layer.camera.top - layer.camera.bottom;
|
|
32
|
+
backdrop.scale.set(width, height, 1);
|
|
33
|
+
track.scale.set(width * 0.5, height * 0.012, 1);
|
|
34
|
+
track.position.set(0, -height * 0.05, 0);
|
|
35
|
+
fill.position.set(-width * 0.25, -height * 0.05, 0);
|
|
36
|
+
};
|
|
37
|
+
layout();
|
|
38
|
+
void ctx.startup.whenReady().then(() => {
|
|
39
|
+
done = true;
|
|
40
|
+
layer.opaque = false;
|
|
41
|
+
for (const mesh of [backdrop, track, fill]) {
|
|
42
|
+
mesh.removeFromParent();
|
|
43
|
+
mesh.geometry.dispose();
|
|
44
|
+
(mesh.material as MeshBasicMaterial).dispose();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
update(): void {
|
|
49
|
+
if (done) return;
|
|
50
|
+
layout();
|
|
51
|
+
const progress = Math.max(0, Math.min(1, ctx.startup.progress));
|
|
52
|
+
const width = layer.camera.right - layer.camera.left;
|
|
53
|
+
const fillWidth = Math.max(width * 0.002, width * 0.5 * progress);
|
|
54
|
+
fill.scale.set(fillWidth, (layer.camera.top - layer.camera.bottom) * 0.012, 1);
|
|
55
|
+
fill.position.x = -width * 0.25 + fillWidth / 2;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MeshStandardMaterial } from "three";
|
|
2
|
+
import { palette, toon } from "./palette.js";
|
|
3
|
+
|
|
4
|
+
export function createMaterials() {
|
|
5
|
+
return {
|
|
6
|
+
boost: toon(palette.accent, 0.4),
|
|
7
|
+
curb: toon(0xf3f0dc, 0.55),
|
|
8
|
+
field: toon(palette.field, 0.95),
|
|
9
|
+
road: toon(palette.road, 0.9),
|
|
10
|
+
shadow: new MeshStandardMaterial({ color: palette.shadow, roughness: 1 }),
|
|
11
|
+
tire: new MeshStandardMaterial({ color: 0x111820, roughness: 0.92 }),
|
|
12
|
+
vehicle: toon(0xd95050, 0.38),
|
|
13
|
+
glass: new MeshStandardMaterial({ color: 0x9ee7f2, roughness: 0.18, metalness: 0.25 }),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BoxGeometry, Group, Mesh, MeshStandardMaterial } from "three";
|
|
2
|
+
|
|
3
|
+
export const palette = {
|
|
4
|
+
skyHigh: 0x102d56,
|
|
5
|
+
skyLow: 0x78b8c8,
|
|
6
|
+
road: 0x202936,
|
|
7
|
+
field: 0x173a35,
|
|
8
|
+
accent: 0xffcf4a,
|
|
9
|
+
shadow: 0x07111d,
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
const materials = new Map<string, MeshStandardMaterial>();
|
|
13
|
+
|
|
14
|
+
export function toon(color: number, roughness = 0.72): MeshStandardMaterial {
|
|
15
|
+
const key = `${color}:${roughness}`;
|
|
16
|
+
const cached = materials.get(key);
|
|
17
|
+
if (cached !== undefined) return cached;
|
|
18
|
+
const material = new MeshStandardMaterial({ color, roughness, metalness: 0.05 });
|
|
19
|
+
materials.set(key, material);
|
|
20
|
+
return material;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function curbBlock(width: number, height: number, depth: number, color: number): Group {
|
|
24
|
+
const group = new Group();
|
|
25
|
+
const mesh = new Mesh(new BoxGeometry(width, height, depth), toon(color, 0.55));
|
|
26
|
+
mesh.castShadow = true;
|
|
27
|
+
mesh.receiveShadow = true;
|
|
28
|
+
group.add(mesh);
|
|
29
|
+
return group;
|
|
30
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ACESFilmicToneMapping, type Camera, type Scene } from "three";
|
|
2
|
+
import { bloom } from "three/addons/tsl/display/BloomNode.js";
|
|
3
|
+
import { pass } from "three/tsl";
|
|
4
|
+
|
|
5
|
+
type OutputRenderer = { kind: string; raw: unknown; setOutputNode(node: unknown): void };
|
|
6
|
+
|
|
7
|
+
export function setupPost(renderer: OutputRenderer, scene: Scene, camera: Camera): void {
|
|
8
|
+
const raw = renderer.raw as { toneMapping?: number; toneMappingExposure?: number };
|
|
9
|
+
raw.toneMapping = ACESFilmicToneMapping;
|
|
10
|
+
raw.toneMappingExposure = 1.18;
|
|
11
|
+
if (renderer.kind !== "webgpu") return;
|
|
12
|
+
const color = pass(scene, camera).getTextureNode();
|
|
13
|
+
renderer.setOutputNode(color.add(bloom(color, 0.35, 0.5, 0.2)));
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BoxGeometry, CylinderGeometry, Group, type Material, Mesh } from "three";
|
|
2
|
+
|
|
3
|
+
export function vehicle(
|
|
4
|
+
materials: ReturnType<typeof import("./materials.js").createMaterials>,
|
|
5
|
+
): Group {
|
|
6
|
+
const root = new Group();
|
|
7
|
+
const chassis = new Mesh(new BoxGeometry(2.7, 0.38, 1.6), materials.vehicle);
|
|
8
|
+
chassis.position.y = 0.35;
|
|
9
|
+
chassis.castShadow = true;
|
|
10
|
+
const nose = new Mesh(new BoxGeometry(0.75, 0.2, 1.15), materials.vehicle);
|
|
11
|
+
nose.position.set(1.02, 0.52, 0);
|
|
12
|
+
nose.castShadow = true;
|
|
13
|
+
const cabin = new Mesh(new BoxGeometry(0.9, 0.42, 1.05), materials.glass);
|
|
14
|
+
cabin.position.set(-0.18, 0.68, 0);
|
|
15
|
+
cabin.castShadow = true;
|
|
16
|
+
root.add(chassis, nose, cabin);
|
|
17
|
+
for (const x of [-0.82, 0.82]) {
|
|
18
|
+
for (const z of [-0.86, 0.86]) {
|
|
19
|
+
const wheel = new Mesh(new CylinderGeometry(0.28, 0.28, 0.18, 12), materials.tire);
|
|
20
|
+
wheel.rotation.x = Math.PI / 2;
|
|
21
|
+
wheel.position.set(x, 0.2, z);
|
|
22
|
+
wheel.castShadow = true;
|
|
23
|
+
root.add(wheel);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return root;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function flag(material: Material): Group {
|
|
30
|
+
const root = new Group();
|
|
31
|
+
const pole = new Mesh(new CylinderGeometry(0.035, 0.035, 1.8, 8), material);
|
|
32
|
+
pole.position.y = 0.9;
|
|
33
|
+
const cloth = new Mesh(new BoxGeometry(0.65, 0.28, 0.04), material);
|
|
34
|
+
cloth.position.set(0.3, 1.55, 0);
|
|
35
|
+
root.add(pole, cloth);
|
|
36
|
+
return root;
|
|
37
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BackSide,
|
|
3
|
+
BufferAttribute,
|
|
4
|
+
Color,
|
|
5
|
+
Fog,
|
|
6
|
+
MathUtils,
|
|
7
|
+
Mesh,
|
|
8
|
+
MeshBasicMaterial,
|
|
9
|
+
type Scene,
|
|
10
|
+
SphereGeometry,
|
|
11
|
+
} from "three";
|
|
12
|
+
import { palette } from "./palette.js";
|
|
13
|
+
|
|
14
|
+
export function setupSky(scene: Scene): void {
|
|
15
|
+
const top = new Color(palette.skyHigh);
|
|
16
|
+
const bottom = new Color(palette.skyLow);
|
|
17
|
+
scene.background = top;
|
|
18
|
+
scene.fog = new Fog(bottom, 36, 150);
|
|
19
|
+
|
|
20
|
+
// A vertical gradient, not a flat fill. This dome used to be one solid colour, and a blind score
|
|
21
|
+
// of the first frame read it as exactly that: the sky sampled CEE6EA byte-identical at four
|
|
22
|
+
// different heights.
|
|
23
|
+
// Sky is most of the frame, so a flat one costs more than anything else here. Edit or delete
|
|
24
|
+
// this — it is your file.
|
|
25
|
+
const radius = 120;
|
|
26
|
+
const geometry = new SphereGeometry(radius, 24, 12);
|
|
27
|
+
const positions = geometry.getAttribute("position");
|
|
28
|
+
const colors = new Float32Array(positions.count * 3);
|
|
29
|
+
const color = new Color();
|
|
30
|
+
for (let index = 0; index < positions.count; index += 1) {
|
|
31
|
+
const height = MathUtils.clamp((positions.getY(index) / radius + 0.2) / 0.65, 0, 1);
|
|
32
|
+
color.copy(bottom).lerp(top, height);
|
|
33
|
+
colors.set([color.r, color.g, color.b], index * 3);
|
|
34
|
+
}
|
|
35
|
+
geometry.setAttribute("color", new BufferAttribute(colors, 3));
|
|
36
|
+
|
|
37
|
+
const dome = new Mesh(
|
|
38
|
+
geometry,
|
|
39
|
+
// `fog: false` because the dome is the horizon; fogging it collapses the gradient above back
|
|
40
|
+
// into the single wash this replaced.
|
|
41
|
+
new MeshBasicMaterial({ fog: false, side: BackSide, toneMapped: false, vertexColors: true }),
|
|
42
|
+
);
|
|
43
|
+
dome.frustumCulled = false;
|
|
44
|
+
scene.add(dome);
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Scene } from "@threenative/core";
|
|
2
|
+
import type { GameState } from "../state.js";
|
|
3
|
+
import { Race } from "./Race.js";
|
|
4
|
+
import type { GameCtx } from "./Race.js";
|
|
5
|
+
|
|
6
|
+
export class Boot extends Scene<GameState, GameCtx["physics"]> {
|
|
7
|
+
static override readonly initialState = Race.initialState;
|
|
8
|
+
|
|
9
|
+
override enter(ctx: GameCtx): void {
|
|
10
|
+
void ctx.goto("race");
|
|
11
|
+
}
|
|
12
|
+
}
|