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,11 @@
|
|
|
1
|
+
// Generated for you. Camera framing is yours to edit.
|
|
2
|
+
import type { PerspectiveCamera } from "three";
|
|
3
|
+
|
|
4
|
+
export function setupCamera(camera: PerspectiveCamera): void {
|
|
5
|
+
camera.fov = 54;
|
|
6
|
+
camera.near = 0.1;
|
|
7
|
+
camera.far = 100;
|
|
8
|
+
camera.position.set(0, 3, 9);
|
|
9
|
+
camera.lookAt(0, 1, 0);
|
|
10
|
+
camera.updateProjectionMatrix();
|
|
11
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { InstancedMesh, MathUtils, Matrix4, MeshBasicMaterial, PlaneGeometry } from "three";
|
|
2
|
+
import type { PerspectiveCamera } from "three";
|
|
3
|
+
import { palette } from "./palette.js";
|
|
4
|
+
|
|
5
|
+
const CHARS = "0123456789:ACEHIMNORST";
|
|
6
|
+
const GLYPHS =
|
|
7
|
+
"7e33ae63f 3884210c4 7c21fc21f 7e10f421f 4210fc631 7e10f843 7e31f843 8422221f 7e31fc63f 7e10fc63f 8401080 4631fc62e 7c210843f 7c217843f 4631fc631 7c842109f 4631ad771 4631cd671 3a318c62e 45257c62f 7e10f843f 10842109f"
|
|
8
|
+
.split(" ")
|
|
9
|
+
.map((hex) => BigInt(`0x${hex}`));
|
|
10
|
+
|
|
11
|
+
export function createHud(camera: PerspectiveCamera, primaryLabel: string, counterLabel: string) {
|
|
12
|
+
const material = new MeshBasicMaterial({
|
|
13
|
+
color: palette.player,
|
|
14
|
+
depthTest: false,
|
|
15
|
+
depthWrite: false,
|
|
16
|
+
});
|
|
17
|
+
const root = new InstancedMesh(new PlaneGeometry(0.82, 0.82), material, 2_048);
|
|
18
|
+
const matrix = new Matrix4();
|
|
19
|
+
root.frustumCulled = false;
|
|
20
|
+
root.renderOrder = 10_000;
|
|
21
|
+
camera.add(root);
|
|
22
|
+
return {
|
|
23
|
+
glyphs: 0,
|
|
24
|
+
update(values: { counter: number; primary: number; seconds: number }): void {
|
|
25
|
+
const minutes = String(Math.floor(values.seconds / 60)).padStart(2, "0");
|
|
26
|
+
const seconds = String(Math.floor(values.seconds % 60)).padStart(2, "0");
|
|
27
|
+
const text = `${primaryLabel} ${Math.max(0, Math.round(values.primary))}\n${counterLabel} ${Math.max(0, Math.round(values.counter))}\nTIME ${minutes}:${seconds}`;
|
|
28
|
+
let instance = 0;
|
|
29
|
+
for (const [y, line] of text.split("\n").entries()) {
|
|
30
|
+
for (let x = 0; x < line.length; x += 1) {
|
|
31
|
+
const glyph = GLYPHS[CHARS.indexOf(line[x] ?? " ")];
|
|
32
|
+
if (glyph === undefined) continue;
|
|
33
|
+
for (let pixel = 0; pixel < 35; pixel += 1) {
|
|
34
|
+
if ((glyph & (1n << BigInt(pixel))) === 0n) continue;
|
|
35
|
+
matrix.makeTranslation(x * 6 + (pixel % 5), -y * 10 - Math.floor(pixel / 5), 0);
|
|
36
|
+
root.setMatrixAt(instance, matrix);
|
|
37
|
+
instance += 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
root.count = this.glyphs = instance;
|
|
42
|
+
root.instanceMatrix.needsUpdate = true;
|
|
43
|
+
const height = 2 * Math.tan(MathUtils.degToRad(camera.fov / 2));
|
|
44
|
+
root.position.set(-height * camera.aspect * 0.46, height * 0.42, -1);
|
|
45
|
+
root.scale.setScalar(height / 160);
|
|
46
|
+
},
|
|
47
|
+
dispose(): void {
|
|
48
|
+
root.removeFromParent();
|
|
49
|
+
root.geometry.dispose();
|
|
50
|
+
material.dispose();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js — edit or delete it freely.
|
|
2
|
+
// ThreeNative does not read this file.
|
|
3
|
+
//
|
|
4
|
+
// Key, bounce, rim, ambient. The rim is the one people forget: without a cool
|
|
5
|
+
// back light, silhouettes read as flat cut-outs against the background.
|
|
6
|
+
import {
|
|
7
|
+
AmbientLight,
|
|
8
|
+
DirectionalLight,
|
|
9
|
+
HemisphereLight,
|
|
10
|
+
PCFSoftShadowMap,
|
|
11
|
+
type Scene,
|
|
12
|
+
} from "three";
|
|
13
|
+
import { palette } from "./palette.js";
|
|
14
|
+
|
|
15
|
+
type ShadowRenderer = { shadowMap: { enabled: boolean; type: number } };
|
|
16
|
+
|
|
17
|
+
export function setupLighting(scene: Scene, renderer: ShadowRenderer): void {
|
|
18
|
+
renderer.shadowMap.enabled = true;
|
|
19
|
+
renderer.shadowMap.type = PCFSoftShadowMap;
|
|
20
|
+
|
|
21
|
+
scene.add(new HemisphereLight(palette.skyHigh, palette.shadow, 1.6));
|
|
22
|
+
|
|
23
|
+
const key = new DirectionalLight(palette.accent, 3);
|
|
24
|
+
key.position.set(4, 7, 3);
|
|
25
|
+
key.castShadow = true;
|
|
26
|
+
// 1024² keeps the default shadow pass at one quarter of a 2048² map's
|
|
27
|
+
// texel storage and fill work. The small generated scene fits this 12-unit
|
|
28
|
+
// extent; widen it when the playable area grows, accepting softer shadows.
|
|
29
|
+
key.shadow.mapSize.set(1024, 1024);
|
|
30
|
+
key.shadow.camera.near = 0.5;
|
|
31
|
+
key.shadow.camera.far = 60;
|
|
32
|
+
const extent = 12;
|
|
33
|
+
key.shadow.camera.left = -extent;
|
|
34
|
+
key.shadow.camera.right = extent;
|
|
35
|
+
key.shadow.camera.top = extent;
|
|
36
|
+
key.shadow.camera.bottom = -extent;
|
|
37
|
+
key.shadow.bias = -0.0008;
|
|
38
|
+
key.shadow.normalBias = 0.03;
|
|
39
|
+
scene.add(key);
|
|
40
|
+
|
|
41
|
+
const rim = new DirectionalLight(palette.player, 0.75);
|
|
42
|
+
rim.position.set(-5, 3, -6);
|
|
43
|
+
scene.add(rim);
|
|
44
|
+
|
|
45
|
+
scene.add(new AmbientLight(palette.shadow, 0.28));
|
|
46
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Camera,
|
|
3
|
+
Mesh,
|
|
4
|
+
MeshBasicMaterial,
|
|
5
|
+
type OrthographicCamera,
|
|
6
|
+
PlaneGeometry,
|
|
7
|
+
type Scene,
|
|
8
|
+
} from "three";
|
|
9
|
+
import { palette } from "./palette.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* What the framework hands a loading screen. Structural on purpose: nothing under `src/render/`
|
|
13
|
+
* imports the framework, and `ctx` already satisfies this shape.
|
|
14
|
+
*/
|
|
15
|
+
export interface LoadingHost {
|
|
16
|
+
readonly camera: Camera;
|
|
17
|
+
readonly scene: Scene;
|
|
18
|
+
readonly canvasLayer: {
|
|
19
|
+
readonly camera: OrthographicCamera;
|
|
20
|
+
readonly scene: Scene;
|
|
21
|
+
opaque: boolean;
|
|
22
|
+
};
|
|
23
|
+
readonly renderer: { compileAsync(scene: Scene, camera: Camera): Promise<void> };
|
|
24
|
+
readonly startup: { readonly progress: number; whenReady(): Promise<void> };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Draws the loading screen in the framework's pixel-sized canvas layer. Colours, layout, and the
|
|
29
|
+
* shape of the bar live here in generated source, so they remain the game's to change or delete.
|
|
30
|
+
*/
|
|
31
|
+
export function createLoadingScreen(host: LoadingHost) {
|
|
32
|
+
const layer = host.canvasLayer;
|
|
33
|
+
const camera = layer.camera;
|
|
34
|
+
const cover = (color: number, renderOrder: number) => {
|
|
35
|
+
const mesh = new Mesh(
|
|
36
|
+
new PlaneGeometry(1, 1),
|
|
37
|
+
new MeshBasicMaterial({ color, depthTest: false, depthWrite: false }),
|
|
38
|
+
);
|
|
39
|
+
mesh.frustumCulled = false;
|
|
40
|
+
mesh.renderOrder = renderOrder;
|
|
41
|
+
layer.scene.add(mesh);
|
|
42
|
+
return mesh;
|
|
43
|
+
};
|
|
44
|
+
const backdrop = cover(palette.skyLow, 0);
|
|
45
|
+
const track = cover(palette.skyHigh, 1);
|
|
46
|
+
const fill = cover(palette.accent, 2);
|
|
47
|
+
const parts = [backdrop, track, fill];
|
|
48
|
+
layer.opaque = true;
|
|
49
|
+
|
|
50
|
+
let width = 0;
|
|
51
|
+
let height = 0;
|
|
52
|
+
let lastProgress = 0;
|
|
53
|
+
|
|
54
|
+
const layout = (): void => {
|
|
55
|
+
const nextWidth = camera.right - camera.left;
|
|
56
|
+
const nextHeight = camera.top - camera.bottom;
|
|
57
|
+
width = Number.isFinite(nextWidth) && nextWidth > 0 ? nextWidth : 1;
|
|
58
|
+
height = Number.isFinite(nextHeight) && nextHeight > 0 ? nextHeight : 1;
|
|
59
|
+
backdrop.scale.set(width, height, 1);
|
|
60
|
+
track.scale.set(width * 0.5, height * 0.012, 1);
|
|
61
|
+
track.position.set(0, -height * 0.05, 0);
|
|
62
|
+
fill.position.set(0, -height * 0.05, 0);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const setProgress = (progress: number): void => {
|
|
66
|
+
// `Math.max(0, Math.min(1, NaN))` is NaN, so non-finite progress means no progress.
|
|
67
|
+
lastProgress = Number.isFinite(progress) ? Math.max(0, Math.min(1, progress)) : 0;
|
|
68
|
+
const full = width * 0.5;
|
|
69
|
+
const barWidth = Math.max(full * 0.002, full * lastProgress);
|
|
70
|
+
fill.scale.set(barWidth, height * 0.012, 1);
|
|
71
|
+
fill.position.x = -full / 2 + barWidth / 2;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
let laidOutWidth = camera.right - camera.left;
|
|
75
|
+
let laidOutHeight = camera.top - camera.bottom;
|
|
76
|
+
layout();
|
|
77
|
+
setProgress(0);
|
|
78
|
+
|
|
79
|
+
let done = false;
|
|
80
|
+
const finish = (): void => {
|
|
81
|
+
if (done) return;
|
|
82
|
+
done = true;
|
|
83
|
+
for (const mesh of parts) {
|
|
84
|
+
mesh.removeFromParent();
|
|
85
|
+
mesh.geometry.dispose();
|
|
86
|
+
mesh.material.dispose();
|
|
87
|
+
}
|
|
88
|
+
layer.opaque = false;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
void (async () => {
|
|
92
|
+
await host.startup.whenReady();
|
|
93
|
+
// Compile the collapsed world's pipelines while the opaque canvas layer still covers it.
|
|
94
|
+
await host.renderer.compileAsync(host.scene, host.camera).catch(() => undefined);
|
|
95
|
+
finish();
|
|
96
|
+
})();
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
update(): void {
|
|
100
|
+
if (done) return;
|
|
101
|
+
const nextWidth = camera.right - camera.left;
|
|
102
|
+
const nextHeight = camera.top - camera.bottom;
|
|
103
|
+
if (nextWidth !== laidOutWidth || nextHeight !== laidOutHeight) {
|
|
104
|
+
laidOutWidth = nextWidth;
|
|
105
|
+
laidOutHeight = nextHeight;
|
|
106
|
+
layout();
|
|
107
|
+
setProgress(lastProgress);
|
|
108
|
+
}
|
|
109
|
+
setProgress(host.startup.progress);
|
|
110
|
+
},
|
|
111
|
+
finish,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js — edit or delete it freely.
|
|
2
|
+
// ThreeNative does not read this file.
|
|
3
|
+
import { MeshStandardMaterial } from "three";
|
|
4
|
+
import { palette } from "./palette.js";
|
|
5
|
+
|
|
6
|
+
export const floorMaterial = new MeshStandardMaterial({
|
|
7
|
+
color: palette.floor,
|
|
8
|
+
roughness: 0.78,
|
|
9
|
+
metalness: 0.12,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const defaultMaterial = new MeshStandardMaterial({
|
|
13
|
+
color: palette.player,
|
|
14
|
+
roughness: 0.52,
|
|
15
|
+
metalness: 0.08,
|
|
16
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js — edit or delete it freely.
|
|
2
|
+
// ThreeNative does not read this file.
|
|
3
|
+
import { ACESFilmicToneMapping, type Camera, type Scene } from "three";
|
|
4
|
+
import { bloom } from "three/addons/tsl/display/BloomNode.js";
|
|
5
|
+
import { pass } from "three/tsl";
|
|
6
|
+
|
|
7
|
+
type OutputRenderer = {
|
|
8
|
+
kind: string;
|
|
9
|
+
raw: unknown;
|
|
10
|
+
setOutputNode(node: unknown): void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function setupPost(renderer: OutputRenderer, scene: Scene, camera: Camera): void {
|
|
14
|
+
const raw = renderer.raw as { toneMapping?: number; toneMappingExposure?: number };
|
|
15
|
+
raw.toneMapping = ACESFilmicToneMapping;
|
|
16
|
+
raw.toneMappingExposure = 1.15;
|
|
17
|
+
if (renderer.kind !== "webgpu") return;
|
|
18
|
+
const colour = pass(scene, camera).getTextureNode();
|
|
19
|
+
renderer.setOutputNode(colour.add(bloom(colour, 0.5, 0.5, 0.2)));
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Generated for you. The fog colour comes from the same palette as the sky.
|
|
2
|
+
import {
|
|
3
|
+
BackSide,
|
|
4
|
+
BufferAttribute,
|
|
5
|
+
Color,
|
|
6
|
+
Fog,
|
|
7
|
+
MathUtils,
|
|
8
|
+
Mesh,
|
|
9
|
+
MeshBasicMaterial,
|
|
10
|
+
type Scene,
|
|
11
|
+
SphereGeometry,
|
|
12
|
+
} from "three";
|
|
13
|
+
import { palette } from "./palette.js";
|
|
14
|
+
|
|
15
|
+
export function setupSky(scene: Scene): void {
|
|
16
|
+
const top = new Color(palette.skyHigh);
|
|
17
|
+
const bottom = new Color(palette.skyLow);
|
|
18
|
+
const radius = 90;
|
|
19
|
+
const geometry = new SphereGeometry(radius, 24, 12);
|
|
20
|
+
const positions = geometry.getAttribute("position");
|
|
21
|
+
const colors = new Float32Array(positions.count * 3);
|
|
22
|
+
const color = new Color();
|
|
23
|
+
for (let index = 0; index < positions.count; index += 1) {
|
|
24
|
+
const height = MathUtils.clamp((positions.getY(index) / radius + 0.2) / 0.65, 0, 1);
|
|
25
|
+
color.copy(bottom).lerp(top, height);
|
|
26
|
+
colors.set([color.r, color.g, color.b], index * 3);
|
|
27
|
+
}
|
|
28
|
+
geometry.setAttribute("color", new BufferAttribute(colors, 3));
|
|
29
|
+
const dome = new Mesh(
|
|
30
|
+
geometry,
|
|
31
|
+
new MeshBasicMaterial({ fog: false, side: BackSide, toneMapped: false, vertexColors: true }),
|
|
32
|
+
);
|
|
33
|
+
// The dome is authored at the origin and never moves; freeze only this
|
|
34
|
+
// known-static render object, leaving gameplay transforms under user control.
|
|
35
|
+
dome.updateMatrix();
|
|
36
|
+
dome.matrixAutoUpdate = false;
|
|
37
|
+
dome.frustumCulled = false;
|
|
38
|
+
scene.background = top;
|
|
39
|
+
scene.fog = new Fog(bottom, 18, 80);
|
|
40
|
+
scene.add(dome);
|
|
41
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type ICtx, Scene, type SceneFrame } from "@threenative/core";
|
|
2
|
+
import { Area3D, CollisionShape3D, type IPhysicsContext, RigidBody3D } from "@threenative/physics";
|
|
3
|
+
import { BoxGeometry, Mesh, type PerspectiveCamera } from "three";
|
|
4
|
+
import { Player } from "../entities/Player.js";
|
|
5
|
+
import { setupCamera } from "../render/camera.js";
|
|
6
|
+
import { createHud } from "../render/hud.js";
|
|
7
|
+
import { setupLighting } from "../render/lighting.js";
|
|
8
|
+
import { createLoadingScreen } from "../render/loading.js";
|
|
9
|
+
import { floorMaterial } from "../render/materials.js";
|
|
10
|
+
import { setupPost } from "../render/postprocessing.js";
|
|
11
|
+
import { setupSky } from "../render/sky.js";
|
|
12
|
+
import type { GameState } from "../state.js";
|
|
13
|
+
|
|
14
|
+
export type GameCtx = ICtx<GameState, IPhysicsContext>;
|
|
15
|
+
|
|
16
|
+
export class Play extends Scene<GameState, IPhysicsContext> {
|
|
17
|
+
static override readonly initialState: GameState = { playerX: -2, score: 0 };
|
|
18
|
+
|
|
19
|
+
override enter(ctx: GameCtx): SceneFrame<GameState, IPhysicsContext> {
|
|
20
|
+
setupSky(ctx.scene);
|
|
21
|
+
setupLighting(ctx.scene, ctx.renderer.raw as Parameters<typeof setupLighting>[1]);
|
|
22
|
+
setupPost(ctx.renderer, ctx.scene, ctx.camera);
|
|
23
|
+
setupCamera(ctx.camera as PerspectiveCamera);
|
|
24
|
+
const loading = createLoadingScreen(ctx);
|
|
25
|
+
ctx.add(ctx.camera);
|
|
26
|
+
const hud = ctx.entities.add(
|
|
27
|
+
"hud",
|
|
28
|
+
createHud(ctx.camera as PerspectiveCamera, "SCORE", "ITEMS"),
|
|
29
|
+
);
|
|
30
|
+
const floor = new Mesh(new BoxGeometry(10, 0.2, 4), floorMaterial);
|
|
31
|
+
floor.position.y = -0.1;
|
|
32
|
+
floor.receiveShadow = true;
|
|
33
|
+
ctx.add(floor);
|
|
34
|
+
new RigidBody3D({
|
|
35
|
+
object: floor,
|
|
36
|
+
physics: ctx.physics,
|
|
37
|
+
shape: CollisionShape3D.fromMesh(floor),
|
|
38
|
+
type: "fixed",
|
|
39
|
+
});
|
|
40
|
+
const player = new Player(ctx);
|
|
41
|
+
ctx.entities.add("player", player);
|
|
42
|
+
const pickup = new Area3D({
|
|
43
|
+
physics: ctx.physics,
|
|
44
|
+
position: { x: 1.5, y: 0.5, z: 0 },
|
|
45
|
+
shape: CollisionShape3D.box(1, 1, 1),
|
|
46
|
+
});
|
|
47
|
+
pickup.on("bodyEntered", (body) => {
|
|
48
|
+
if (body === player.body) ctx.state.set((state) => ({ score: state.score + 1 }));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
let elapsed = 0;
|
|
52
|
+
return (frameCtx, dt) => {
|
|
53
|
+
loading.update();
|
|
54
|
+
player.update(frameCtx, dt);
|
|
55
|
+
elapsed += dt;
|
|
56
|
+
const state = frameCtx.state.getState();
|
|
57
|
+
hud.update({
|
|
58
|
+
counter: Math.abs(player.mesh.position.x) * 10,
|
|
59
|
+
primary: state.score,
|
|
60
|
+
seconds: elapsed,
|
|
61
|
+
});
|
|
62
|
+
frameCtx.state.set({ playerX: player.mesh.position.x });
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GameState = { playerX: number; score: number };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color: #d9f5ff;
|
|
3
|
+
background: #061018;
|
|
4
|
+
font-family: ui-monospace, monospace;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
body {
|
|
8
|
+
margin: 0;
|
|
9
|
+
min-width: 320px;
|
|
10
|
+
overflow: hidden;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* #app is the canvas host handed to defineGame({ container }). Pinning it to
|
|
15
|
+
* the viewport and giving the canvas an explicit layer keeps the renderer
|
|
16
|
+
* behind the HUD. A canvas with no positioning takes part in normal flow, so a
|
|
17
|
+
* full-height wrapper above it pushes it below the fold — the page looks black
|
|
18
|
+
* and nothing reports an error.
|
|
19
|
+
*/
|
|
20
|
+
#app {
|
|
21
|
+
position: fixed;
|
|
22
|
+
inset: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#app canvas {
|
|
26
|
+
display: block;
|
|
27
|
+
z-index: 0;
|
|
28
|
+
width: 100%;
|
|
29
|
+
height: 100%;
|
|
30
|
+
touch-action: none;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#hud {
|
|
34
|
+
position: fixed;
|
|
35
|
+
top: 1rem;
|
|
36
|
+
left: 1rem;
|
|
37
|
+
z-index: 1;
|
|
38
|
+
padding: 0.5rem 0.75rem;
|
|
39
|
+
background: rgb(6 16 24 / 80%);
|
|
40
|
+
border: 1px solid #2b728e;
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IThreeNativeConfig } from "@threenative/core";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
app: {
|
|
5
|
+
id: "com.threenative.__PROJECT_ID__",
|
|
6
|
+
name: "__PROJECT_NAME__",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
build: 1,
|
|
9
|
+
icon: "public/icon.png",
|
|
10
|
+
},
|
|
11
|
+
display: {
|
|
12
|
+
orientation: "landscape", // Mobile viewport orientation.
|
|
13
|
+
fullscreen: true, // Keep the game surface edge to edge.
|
|
14
|
+
keepScreenOn: true, // Do not dim during a play session.
|
|
15
|
+
},
|
|
16
|
+
window: {
|
|
17
|
+
title: "__PROJECT_NAME__", // Desktop window title.
|
|
18
|
+
width: 1280,
|
|
19
|
+
height: 720,
|
|
20
|
+
resizable: true,
|
|
21
|
+
},
|
|
22
|
+
loading: {
|
|
23
|
+
// Read by src/render/loading.ts, which is your file. Delete that file to drop the screen.
|
|
24
|
+
backdropColor: "#0d1b2a",
|
|
25
|
+
trackColor: "#274060",
|
|
26
|
+
progressColor: "#8fd694",
|
|
27
|
+
showProgressBar: true,
|
|
28
|
+
// image: "public/logo.png", // drawn centred above the bar
|
|
29
|
+
},
|
|
30
|
+
nativeEntry: "src/game.ts",
|
|
31
|
+
renderer: { preferWebGPU: true }, // Use WebGPU when the host exposes it.
|
|
32
|
+
} satisfies IThreeNativeConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"types": ["vite/client"],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"isolatedModules": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts", "tests/**/*.ts", "*.ts"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mcpServers": {
|
|
3
|
+
"threenative-assets": {
|
|
4
|
+
"command": "node",
|
|
5
|
+
"args": ["./node_modules/threenative-asset-mcp/dist/index.js"],
|
|
6
|
+
"env": {
|
|
7
|
+
"ASSET_DOWNLOAD_DIR": "./public/assets",
|
|
8
|
+
"AUDIO_DOWNLOAD_DIR": "./public/audio"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"threenative-sculpt": {
|
|
12
|
+
"command": "node",
|
|
13
|
+
"args": ["./node_modules/threenative-sculpt-mcp/dist/server.js"]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|