create-threenative 0.2.18 → 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.
Files changed (183) hide show
  1. package/agent-docs/references/capability-reference.md +212 -4
  2. package/agent-docs/references/kit-racing.md +4 -2
  3. package/agent-docs/references/performance-basics.md +2 -1
  4. package/agent-docs/references/terrain-authoring.md +21 -7
  5. package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
  6. package/dist/index.js +255 -236
  7. package/dist/quality.d.ts +5 -1
  8. package/dist/quality.js +75 -6
  9. package/dist/terrain-kit.js +1 -1
  10. package/dist/threenative.js +6 -4
  11. package/dist/web-engine-post-effects.js +6 -0
  12. package/dist/web-engine-runtime.js +211 -36
  13. package/package.json +6 -6
  14. package/template-assets/assets/floor-fern-0.glb +0 -0
  15. package/template-assets/assets/floor-litter-0.glb +0 -0
  16. package/template-assets/assets/floor-log-0.glb +0 -0
  17. package/template-assets/assets/floor-log-1.glb +0 -0
  18. package/template-assets/assets/floor-stump-0.glb +0 -0
  19. package/template-assets/assets/floor-twig-0.glb +0 -0
  20. package/template-assets/quality/eslint.config.js +1 -1
  21. package/templates/action-rpg/package.json +7 -7
  22. package/templates/action-rpg/src/loot/drops.ts +3 -7
  23. package/templates/action-rpg/src/render/camera.ts +2 -2
  24. package/templates/action-rpg/src/render/clouds.ts +3 -1
  25. package/templates/action-rpg/src/render/materials.ts +3 -2
  26. package/templates/action-rpg/src/render/touch-controls.ts +7 -6
  27. package/templates/action-rpg/src/scenes/Play.ts +1 -15
  28. package/templates/adventure/AGENTS.md +3 -3
  29. package/templates/adventure/CLAUDE.md +3 -3
  30. package/templates/adventure/native-playtests/survives.playtest.json +12 -0
  31. package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
  32. package/templates/adventure/package.json +7 -7
  33. package/templates/adventure/playtests/grass.playtest.json +61 -0
  34. package/templates/adventure/playtests/performance.playtest.json +1 -1
  35. package/templates/adventure/playtests/survives.playtest.json +2 -2
  36. package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
  37. package/templates/adventure/src/entities/LockOn.ts +42 -4
  38. package/templates/adventure/src/entities/Warden.ts +4 -1
  39. package/templates/adventure/src/level/Vale.ts +241 -16
  40. package/templates/adventure/src/render/camera.ts +2 -2
  41. package/templates/adventure/src/render/foliage.ts +64 -20
  42. package/templates/adventure/src/render/grass.ts +325 -0
  43. package/templates/adventure/src/render/materials.ts +3 -2
  44. package/templates/adventure/src/render/palette.ts +3 -0
  45. package/templates/adventure/src/render/touch-controls.ts +4 -1
  46. package/templates/adventure/src/scenes/Play.ts +96 -1
  47. package/templates/collectathon/package.json +7 -7
  48. package/templates/collectathon/src/level/Course.ts +2 -7
  49. package/templates/collectathon/src/level/terrain.ts +2 -1
  50. package/templates/collectathon/src/render/camera.ts +2 -2
  51. package/templates/collectathon/src/render/ground.ts +4 -4
  52. package/templates/collectathon/src/render/hero.ts +1 -1
  53. package/templates/collectathon/src/render/materials.ts +0 -1
  54. package/templates/collectathon/src/render/sky.ts +4 -3
  55. package/templates/kart/package.json +6 -6
  56. package/templates/kart/src/entities/Kart.ts +2 -1
  57. package/templates/kart/src/render/course.ts +2 -1
  58. package/templates/kart/src/track/Course.ts +3 -1
  59. package/templates/minimal/package.json +6 -6
  60. package/templates/minimal/src/render/camera.ts +2 -2
  61. package/templates/minimal/src/render/clouds.ts +3 -1
  62. package/templates/minimal/src/render/materials.ts +3 -2
  63. package/templates/minimal/src/render/touch-controls.ts +7 -6
  64. package/templates/platformer/package.json +7 -7
  65. package/templates/platformer/playtests/collect.playtest.json +4 -1
  66. package/templates/platformer/src/level/Stage.ts +2 -6
  67. package/templates/platformer/src/scenes/Play.ts +2 -1
  68. package/templates/puzzle/package.json +7 -7
  69. package/templates/puzzle/src/entities/Warden.ts +3 -3
  70. package/templates/puzzle/src/render/camera.ts +2 -2
  71. package/templates/puzzle/src/render/touch-controls.ts +7 -6
  72. package/templates/racing/AGENTS.md +2 -2
  73. package/templates/racing/CLAUDE.md +2 -2
  74. package/templates/racing/CREDITS.md +29 -0
  75. package/templates/racing/assets/engine-loop.wav +0 -0
  76. package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
  77. package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
  78. package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
  79. package/templates/racing/assets/nitro-burst.wav +0 -0
  80. package/templates/racing/assets/tyre-squeal.wav +0 -0
  81. package/templates/racing/package.json +7 -7
  82. package/templates/racing/playtests/drift-natural.playtest.json +68 -0
  83. package/templates/racing/playtests/drift.playtest.json +100 -0
  84. package/templates/racing/playtests/hud.playtest.json +117 -0
  85. package/templates/racing/playtests/launch-pose.playtest.json +34 -0
  86. package/templates/racing/playtests/nitro.playtest.json +158 -0
  87. package/templates/racing/playtests/outcome.playtest.json +4 -4
  88. package/templates/racing/playtests/performance.playtest.json +1 -1
  89. package/templates/racing/playtests/steady-camera.playtest.json +88 -0
  90. package/templates/racing/src/audio/engine.ts +138 -0
  91. package/templates/racing/src/entities/CarBody.ts +83 -10
  92. package/templates/racing/src/entities/Drift.ts +243 -0
  93. package/templates/racing/src/entities/LineDriver.ts +2 -2
  94. package/templates/racing/src/entities/Nitro.ts +72 -0
  95. package/templates/racing/src/entities/RacingCar.ts +86 -21
  96. package/templates/racing/src/entities/Rival.ts +35 -21
  97. package/templates/racing/src/game.ts +6 -0
  98. package/templates/racing/src/gauges.ts +74 -0
  99. package/templates/racing/src/render/camera.ts +29 -4
  100. package/templates/racing/src/render/clouds.ts +3 -1
  101. package/templates/racing/src/render/effects.ts +244 -0
  102. package/templates/racing/src/render/materials.ts +43 -8
  103. package/templates/racing/src/render/shapes.ts +37 -0
  104. package/templates/racing/src/render/skids.ts +84 -0
  105. package/templates/racing/src/render/touch-controls.ts +10 -10
  106. package/templates/racing/src/scenes/Race.ts +277 -25
  107. package/templates/racing/src/state.ts +35 -0
  108. package/templates/racing/src/style.css +3 -0
  109. package/templates/racing/src/track/Track.ts +132 -58
  110. package/templates/racing/src/track/TrackSector.ts +19 -1
  111. package/templates/racing/src/track/circuit.ts +21 -15
  112. package/templates/racing/src/ui/GameUi.tsx +0 -2
  113. package/templates/racing/src/ui/Hud.tsx +417 -50
  114. package/templates/racing/threenative.config.ts +15 -0
  115. package/templates/racing/tools/make-racing-audio.mjs +388 -0
  116. package/templates/rain/package.json +6 -6
  117. package/templates/rain/src/render/noise-volume.ts +2 -1
  118. package/templates/rain/src/state.ts +3 -1
  119. package/templates/rain/src/ui/GameUi.tsx +1 -1
  120. package/templates/rain/src/ui/automation.ts +10 -8
  121. package/templates/rain/src/ui/tempest.ts +3 -4
  122. package/templates/rts/package.json +6 -6
  123. package/templates/rts/src/sim/terrain.ts +1 -0
  124. package/templates/rts/src/sim/types.ts +1 -0
  125. package/templates/runner/package.json +7 -7
  126. package/templates/runner/src/render/clouds.ts +3 -1
  127. package/templates/runner/src/render/materials.ts +3 -2
  128. package/templates/runner/src/render/touch-controls.ts +7 -6
  129. package/templates/runner/src/scenes/Run.ts +4 -9
  130. package/templates/sailing/package.json +7 -7
  131. package/templates/sailing/src/render/touch-controls.ts +7 -6
  132. package/templates/shooter/package.json +7 -7
  133. package/templates/shooter/src/render/clouds.ts +3 -1
  134. package/templates/snow/package.json +7 -7
  135. package/templates/snow/src/entities/Explorer.ts +6 -12
  136. package/templates/snow/src/render/bootPrint.ts +3 -1
  137. package/templates/snow/src/render/camera.ts +3 -2
  138. package/templates/snow/src/render/scenery.ts +3 -3
  139. package/templates/snow/src/render/touch-controls.ts +7 -6
  140. package/templates/snow/src/render/weather.ts +3 -5
  141. package/templates/snow/src/terrain.ts +2 -1
  142. package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
  143. package/templates/starter/package.json +7 -7
  144. package/templates/starter/src/entities/Player.ts +10 -2
  145. package/templates/starter/src/render/camera.ts +2 -2
  146. package/templates/starter/src/render/clouds.ts +3 -1
  147. package/templates/starter/src/render/materials.ts +3 -2
  148. package/templates/starter/src/render/touch-controls.ts +7 -6
  149. package/templates/starter/src/scenes/Play.ts +1 -14
  150. package/templates/tower-defense/package.json +7 -7
  151. package/templates/tower-defense/src/render/shapes.ts +1 -2
  152. package/templates/tower-defense/src/scenes/Battle.ts +3 -8
  153. package/template-assets/terrain/alpine/assets.json +0 -12
  154. package/template-assets/terrain/alpine/bake.mjs +0 -6
  155. package/template-assets/terrain/alpine/credits.json +0 -164
  156. package/template-assets/terrain/alpine/heightmap.r16 +0 -0
  157. package/template-assets/terrain/alpine/recipe.json +0 -119
  158. package/template-assets/terrain/alpine/surface.json +0 -53
  159. package/template-assets/terrain/coastal/assets.json +0 -11
  160. package/template-assets/terrain/coastal/bake.mjs +0 -6
  161. package/template-assets/terrain/coastal/credits.json +0 -117
  162. package/template-assets/terrain/coastal/heightmap.r16 +0 -0
  163. package/template-assets/terrain/coastal/recipe.json +0 -113
  164. package/template-assets/terrain/coastal/surface.json +0 -41
  165. package/template-assets/terrain/desert/assets.json +0 -12
  166. package/template-assets/terrain/desert/bake.mjs +0 -6
  167. package/template-assets/terrain/desert/credits.json +0 -164
  168. package/template-assets/terrain/desert/heightmap.r16 +0 -0
  169. package/template-assets/terrain/desert/recipe.json +0 -108
  170. package/template-assets/terrain/desert/surface.json +0 -54
  171. package/template-assets/terrain/forest/assets.json +0 -65
  172. package/template-assets/terrain/forest/bake.mjs +0 -8
  173. package/template-assets/terrain/forest/credits.json +0 -225
  174. package/template-assets/terrain/forest/heightmap.r16 +0 -0
  175. package/template-assets/terrain/forest/recipe.json +0 -350
  176. package/template-assets/terrain/forest/surface.json +0 -79
  177. package/template-assets/terrain/tundra/assets.json +0 -12
  178. package/template-assets/terrain/tundra/bake.mjs +0 -6
  179. package/template-assets/terrain/tundra/credits.json +0 -164
  180. package/template-assets/terrain/tundra/heightmap.r16 +0 -0
  181. package/template-assets/terrain/tundra/recipe.json +0 -277
  182. package/template-assets/terrain/tundra/surface.json +0 -54
  183. package/templates/racing/src/ui/Menu.tsx +0 -7
@@ -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
  }
@@ -122,13 +125,11 @@ export class TouchControls {
122
125
  }
123
126
 
124
127
  const center = this.#hasMoveAnchor ? this.#moveAnchor : this.#resting;
125
- place(
126
- this.#moveKnob,
127
- new Vector2(
128
- center.x + this.#input.move.x * MOVE_RADIUS,
129
- center.y - this.#input.move.y * MOVE_RADIUS,
130
- ),
128
+ knobPosition.set(
129
+ center.x + this.#input.move.x * MOVE_RADIUS,
130
+ center.y - this.#input.move.y * MOVE_RADIUS,
131
131
  );
132
+ place(this.#moveKnob, knobPosition);
132
133
  this.#left.material = left ? this.#activeMaterial : this.#idleMaterial;
133
134
  this.#right.material = right ? this.#activeMaterial : this.#idleMaterial;
134
135
  this.#input.leftPressed = left && !this.#wasLeft;
@@ -205,7 +205,9 @@ export class Run extends Scene<GameState, RunnerPhysics> {
205
205
  const previous = frameCtx.state.getState();
206
206
  const next: GameState = {
207
207
  chunks: track.built,
208
- distance,
208
+ // Whole metres: the HUD shows the floor, and a fractional distance would republish every
209
+ // frame. The store skips a key it already holds, so this is the only stillness it needs.
210
+ distance: Math.floor(distance),
209
211
  lane: runner.lane,
210
212
  nearMisses,
211
213
  paused: previous.paused,
@@ -213,14 +215,7 @@ export class Run extends Scene<GameState, RunnerPhysics> {
213
215
  status,
214
216
  uiReady: previous.uiReady,
215
217
  };
216
- if (
217
- next.chunks !== previous.chunks ||
218
- next.lane !== previous.lane ||
219
- next.nearMisses !== previous.nearMisses ||
220
- next.status !== previous.status ||
221
- Math.floor(next.distance) !== Math.floor(previous.distance)
222
- )
223
- frameCtx.state.set(next);
218
+ frameCtx.state.set(next);
224
219
  };
225
220
  }
226
221
 
@@ -19,9 +19,9 @@
19
19
  "format:check": "biome format src"
20
20
  },
21
21
  "dependencies": {
22
- "@threenative/core": "0.3.13",
23
- "@threenative/physics": "0.3.13",
24
- "@threenative/ui": "0.3.13",
22
+ "@threenative/core": ">=0.3.15",
23
+ "@threenative/physics": ">=0.3.15",
24
+ "@threenative/ui": ">=0.3.15",
25
25
  "react": "19.2.0",
26
26
  "react-dom": "19.2.0",
27
27
  "react-reconciler": "0.33.0",
@@ -29,13 +29,13 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@tailwindcss/vite": "4.3.3",
32
- "@threenative/assets": "0.3.14",
33
- "@threenative/playtest": "0.3.13",
32
+ "@threenative/assets": ">=0.3.16",
33
+ "@threenative/playtest": ">=0.3.15",
34
34
  "@types/react": "19.2.0",
35
35
  "@types/react-dom": "19.2.0",
36
36
  "@types/three": "0.187.0",
37
37
  "@vitejs/plugin-react": "6.0.5",
38
- "create-threenative": "0.2.18",
38
+ "create-threenative": "0.2.20",
39
39
  "esbuild": "0.27.0",
40
40
  "playwright": "1.62.1",
41
41
  "tailwindcss": "4.3.3",
@@ -46,7 +46,7 @@
46
46
  "eslint": "10.13.0"
47
47
  },
48
48
  "optionalDependencies": {
49
- "@threenative/runtime-native": "0.3.13"
49
+ "@threenative/runtime-native": ">=0.3.15"
50
50
  },
51
51
  "overrides": {
52
52
  "sharp": ">=0.35.4",
@@ -14,6 +14,9 @@ import { palette } from "./palette.js";
14
14
  const MOVE_RADIUS = 72;
15
15
  const EDGE = 36;
16
16
 
17
+ /** The knob's next point: `update` runs every frame, so it uses one instance. */
18
+ const knobPosition = new Vector2();
19
+
17
20
  export interface ITouchPointer {
18
21
  readonly position: Vector2;
19
22
  }
@@ -100,13 +103,11 @@ export class TouchControls {
100
103
  }
101
104
 
102
105
  const center = this.#hasMoveAnchor ? this.#moveAnchor : this.#resting;
103
- place(
104
- this.#moveKnob,
105
- new Vector2(
106
- center.x + this.#input.move.x * MOVE_RADIUS,
107
- center.y - this.#input.move.y * MOVE_RADIUS,
108
- ),
106
+ knobPosition.set(
107
+ center.x + this.#input.move.x * MOVE_RADIUS,
108
+ center.y - this.#input.move.y * MOVE_RADIUS,
109
109
  );
110
+ place(this.#moveKnob, knobPosition);
110
111
  this.#moveKnob.material = this.#hasMoveAnchor ? this.#activeMaterial : this.#idleMaterial;
111
112
  this.#layout(size);
112
113
  return this.#input;
@@ -19,9 +19,9 @@
19
19
  "format:check": "biome format src"
20
20
  },
21
21
  "dependencies": {
22
- "@threenative/core": "0.3.13",
23
- "@threenative/physics": "0.3.13",
24
- "@threenative/ui": "0.3.13",
22
+ "@threenative/core": ">=0.3.15",
23
+ "@threenative/physics": ">=0.3.15",
24
+ "@threenative/ui": ">=0.3.15",
25
25
  "react": "19.2.0",
26
26
  "react-dom": "19.2.0",
27
27
  "three": "0.187.0"
@@ -30,12 +30,12 @@
30
30
  "@tailwindcss/vite": "4.3.3",
31
31
  "@types/three": "0.187.0",
32
32
  "@vitejs/plugin-react": "6.0.5",
33
- "@threenative/assets": "0.3.14",
34
- "@threenative/playtest": "0.3.13",
33
+ "@threenative/assets": ">=0.3.16",
34
+ "@threenative/playtest": ">=0.3.15",
35
35
  "@types/react": "19.2.0",
36
36
  "@types/react-dom": "19.2.0",
37
37
  "playwright": "1.62.1",
38
- "create-threenative": "0.2.18",
38
+ "create-threenative": "0.2.20",
39
39
  "esbuild": "0.27.0",
40
40
  "tailwindcss": "4.3.3",
41
41
  "typescript": "7.0.2",
@@ -45,7 +45,7 @@
45
45
  "eslint": "10.13.0"
46
46
  },
47
47
  "optionalDependencies": {
48
- "@threenative/runtime-native": "0.3.13"
48
+ "@threenative/runtime-native": ">=0.3.15"
49
49
  },
50
50
  "overrides": {
51
51
  "sharp": ">=0.35.4",
@@ -6,6 +6,8 @@
6
6
  // Independent CPU implementation. The material samples four Unreal textures that this repository
7
7
  // must not carry, so each one is regenerated here from a seeded noise whose per-channel value
8
8
  // quantiles and correlation lengths match the Unreal texture (measured, see the spec).
9
+ import { MathUtils } from "three";
10
+
9
11
  import {
10
12
  BOTTOM_KM,
11
13
  CAMERA_KM,
@@ -110,7 +112,7 @@ const PROFILE_COEFFICIENTS = [
110
112
  const clamp = (v: number): number => Math.max(0, Math.min(1, v));
111
113
  const smooth = (v: number): number => {
112
114
  const t = clamp(v);
113
- return t * t * (3 - 2 * t);
115
+ return MathUtils.smoothstep(t, 0, 1);
114
116
  };
115
117
  const mod = (a: number, n: number): number => ((a % n) + n) % n;
116
118
 
@@ -19,9 +19,9 @@
19
19
  "format:check": "biome format src"
20
20
  },
21
21
  "dependencies": {
22
- "@threenative/core": "0.3.13",
23
- "@threenative/physics": "0.3.13",
24
- "@threenative/ui": "0.3.13",
22
+ "@threenative/core": ">=0.3.15",
23
+ "@threenative/physics": ">=0.3.15",
24
+ "@threenative/ui": ">=0.3.15",
25
25
  "react": "19.2.0",
26
26
  "react-dom": "19.2.0",
27
27
  "react-reconciler": "0.33.0",
@@ -29,13 +29,13 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@tailwindcss/vite": "4.3.3",
32
- "@threenative/assets": "0.3.14",
33
- "@threenative/playtest": "0.3.13",
32
+ "@threenative/assets": ">=0.3.16",
33
+ "@threenative/playtest": ">=0.3.15",
34
34
  "@types/react": "19.2.0",
35
35
  "@types/react-dom": "19.2.0",
36
36
  "@types/three": "0.187.0",
37
37
  "@vitejs/plugin-react": "6.0.5",
38
- "create-threenative": "0.2.18",
38
+ "create-threenative": "0.2.20",
39
39
  "esbuild": "0.27.0",
40
40
  "playwright": "1.62.1",
41
41
  "tailwindcss": "4.3.3",
@@ -46,7 +46,7 @@
46
46
  "eslint": "10.13.0"
47
47
  },
48
48
  "optionalDependencies": {
49
- "@threenative/runtime-native": "0.3.13"
49
+ "@threenative/runtime-native": ">=0.3.15"
50
50
  },
51
51
  "overrides": {
52
52
  "sharp": ">=0.35.4",
@@ -1,6 +1,6 @@
1
1
  import type { SnowField } from "@threenative/core/world";
2
2
  import { CharacterBody3D, CollisionShape3D, type IPhysicsContext } from "@threenative/physics";
3
- import { Object3D } from "three";
3
+ import { MathUtils, Object3D } from "three";
4
4
  import { BOOT_AREA, bootPrint } from "../render/bootPrint.js";
5
5
  import { ExplorerModel, type IFootPose } from "../render/explorer.js";
6
6
  import type { SnowMaterials } from "../render/materials.js";
@@ -45,12 +45,6 @@ export const STANCE = 0.2;
45
45
 
46
46
  const clamp = (value: number, low: number, high: number) => Math.max(low, Math.min(high, value));
47
47
  const lerp = (a: number, b: number, t: number) => a + (b - a) * t;
48
- const damp = (a: number, b: number, rate: number, dt: number) =>
49
- lerp(a, b, 1 - Math.exp(-rate * Math.max(0, dt)));
50
- const smoothstep = (edge0: number, edge1: number, value: number) => {
51
- const t = clamp((value - edge0) / (edge1 - edge0), 0, 1);
52
- return t * t * (3 - 2 * t);
53
- };
54
48
 
55
49
  /** Walking pace through powder: deeper, softer snow is slower; packed snow is faster. */
56
50
  function paceThrough(depth: number, compaction: number, running: boolean): number {
@@ -146,8 +140,8 @@ export class Explorer {
146
140
  const length = Math.hypot(move.x, move.z);
147
141
  const scale = length > 1 ? 1 / length : 1;
148
142
  const moving = length > 0.01;
149
- this.#velocity.x = damp(this.#velocity.x, move.x * scale * pace, moving ? 5 : 8, dt);
150
- this.#velocity.z = damp(this.#velocity.z, move.z * scale * pace, moving ? 5 : 8, dt);
143
+ this.#velocity.x = MathUtils.damp(this.#velocity.x, move.x * scale * pace, moving ? 5 : 8, dt);
144
+ this.#velocity.z = MathUtils.damp(this.#velocity.z, move.z * scale * pace, moving ? 5 : 8, dt);
151
145
  if (!moving && Math.hypot(this.#velocity.x, this.#velocity.z) < 0.025) {
152
146
  this.#velocity.x = 0;
153
147
  this.#velocity.z = 0;
@@ -159,7 +153,7 @@ export class Explorer {
159
153
  if (this.speed > 0.05) {
160
154
  const desired = Math.atan2(this.#velocity.x, this.#velocity.z);
161
155
  const turn = Math.atan2(Math.sin(desired - this.heading), Math.cos(desired - this.heading));
162
- this.heading += turn * (1 - Math.exp(-7 * dt));
156
+ this.heading = MathUtils.damp(this.heading, this.heading + turn, 7, dt);
163
157
  }
164
158
  this.#cycle += travelled / (running ? 1.22 : 1.04);
165
159
  this.#stepFeet(dt, running, hardness);
@@ -169,7 +163,7 @@ export class Explorer {
169
163
  this.speed > 0.02
170
164
  ? Math.cos(this.#cycle * Math.PI * 4) * 0.016
171
165
  : Math.sin(this.#elapsed * 1.8) * 0.003;
172
- this.position.y = damp(
166
+ this.position.y = MathUtils.damp(
173
167
  this.position.y,
174
168
  terrainHeight(anchor.x, anchor.z) + snow.depth - sink + bob,
175
169
  14,
@@ -221,7 +215,7 @@ export class Explorer {
221
215
  progress = Math.max(foot.progress, clamp(foot.progress + foot.stop, 0, 1));
222
216
  }
223
217
  foot.progress = progress;
224
- const eased = smoothstep(0, 1, progress);
218
+ const eased = MathUtils.smoothstep(progress, 0, 1);
225
219
  foot.x = lerp(foot.from.x, foot.to.x, eased);
226
220
  foot.z = lerp(foot.from.z, foot.to.z, eased);
227
221
  const lift =
@@ -2,6 +2,8 @@
2
2
  // Change the sole, the tread or the rim here; `SnowField` only presses whatever shape it is given.
3
3
 
4
4
  /** One sample of a contact profile, in the shape `SnowField.stamp` reads. */
5
+ import { MathUtils } from "three";
6
+
5
7
  interface IPrintSample {
6
8
  readonly bank: number;
7
9
  readonly coverage: number;
@@ -14,7 +16,7 @@ const NOTHING: IPrintSample = { bank: 0, coverage: 0, disturbance: 0, relief: 0,
14
16
 
15
17
  function smoothstep(edge0: number, edge1: number, value: number): number {
16
18
  const t = Math.max(0, Math.min(1, (value - edge0) / (edge1 - edge0)));
17
- return t * t * (3 - 2 * t);
19
+ return MathUtils.smoothstep(t, 0, 1);
18
20
  }
19
21
 
20
22
  /** The sole's area, m². Load over this is the pressure a planted boot puts on the snow. */
@@ -1,5 +1,6 @@
1
1
  // Generated for you. Framing is a game-owned decision.
2
2
  import type { PerspectiveCamera } from "three";
3
+ import { MathUtils } from "three";
3
4
  import type { CameraView } from "../state.js";
4
5
 
5
6
  export function setupCamera(camera: PerspectiveCamera): void {
@@ -62,8 +63,8 @@ export class OrbitFollow {
62
63
  ground: (x: number, z: number) => number,
63
64
  dt: number,
64
65
  ): void {
65
- const ease = 1 - Math.exp(-dt * 4.5);
66
- const settle = 1 - Math.exp(-dt * 5);
66
+ const ease = MathUtils.damp(0, 1, 4.5, dt);
67
+ const settle = MathUtils.damp(0, 1, 5, dt);
67
68
  this.#target.x += (goal.x - this.#target.x) * ease;
68
69
  this.#target.y += (goal.y - this.#target.y) * ease;
69
70
  this.#target.z += (goal.z - this.#target.z) * ease;
@@ -9,6 +9,7 @@ import {
9
9
  Group,
10
10
  InstancedMesh,
11
11
  LineSegments,
12
+ MathUtils,
12
13
  Mesh,
13
14
  Object3D,
14
15
  PlaneGeometry,
@@ -27,16 +28,15 @@ export interface IObstacle {
27
28
  }
28
29
 
29
30
  function seededRandom(seed: number): () => number {
30
- let state = seed;
31
+ let state = seed >>> 0;
31
32
  return () => {
32
33
  state = (state * 1664525 + 1013904223) >>> 0;
33
34
  return state / 4294967296;
34
35
  };
35
36
  }
36
-
37
37
  const smoothstep = (edge0: number, edge1: number, value: number) => {
38
38
  const t = Math.max(0, Math.min(1, (value - edge0) / (edge1 - edge0)));
39
- return t * t * (3 - 2 * t);
39
+ return MathUtils.smoothstep(t, 0, 1);
40
40
  };
41
41
 
42
42
  /** Glade-edge pines by hand, then a ring of forest further out. `[x, z, height]`. */
@@ -14,6 +14,9 @@ import { palette } from "./palette.js";
14
14
  const MOVE_RADIUS = 72;
15
15
  const EDGE = 36;
16
16
 
17
+ /** The knob's next point: `update` runs every frame, so it uses one instance. */
18
+ const knobPosition = new Vector2();
19
+
17
20
  export interface ITouchPointer {
18
21
  readonly position: Vector2;
19
22
  }
@@ -101,13 +104,11 @@ export class TouchControls {
101
104
  }
102
105
 
103
106
  const center = this.#hasMoveAnchor ? this.#moveAnchor : this.#resting;
104
- place(
105
- this.#moveKnob,
106
- new Vector2(
107
- center.x + this.#input.move.x * MOVE_RADIUS,
108
- center.y - this.#input.move.y * MOVE_RADIUS,
109
- ),
107
+ knobPosition.set(
108
+ center.x + this.#input.move.x * MOVE_RADIUS,
109
+ center.y - this.#input.move.y * MOVE_RADIUS,
110
110
  );
111
+ place(this.#moveKnob, knobPosition);
111
112
  this.#moveKnob.material = this.#hasMoveAnchor ? this.#activeMaterial : this.#idleMaterial;
112
113
  this.#layout(size);
113
114
  return this.#input;
@@ -1,7 +1,7 @@
1
1
  // Generated for you. Snowfall, the blizzard and the powder a boot kicks up. `GPUParticles3D` (the
2
2
  // scene passes it in) owns
3
3
  // the buffers, dispatch and lifetime; the flake's shape, colour, size, drift and fall are here.
4
- import { type Sprite, Vector2 } from "three";
4
+ import { MathUtils, type Sprite, Vector2 } from "three";
5
5
  import {
6
6
  Fn,
7
7
  atan,
@@ -233,8 +233,6 @@ export function createWeather(options: {
233
233
  let wind = 0.4;
234
234
  let drifted = { x: 0, z: 0 };
235
235
  let fallen = 0;
236
- const damp = (a: number, b: number, rate: number, dt: number) =>
237
- a + (b - a) * (1 - Math.exp(-rate * Math.max(0, dt)));
238
236
  return {
239
237
  bursts: bursts.map((burst) => burst.particles),
240
238
  burst(at, strength) {
@@ -253,10 +251,10 @@ export function createWeather(options: {
253
251
  update(dt, centre, pixelScale, settings) {
254
252
  fall.pixelScale.value = pixelScale;
255
253
  time += dt;
256
- storm = damp(storm, settings.blizzard ? 1 : 0, 0.95, dt);
254
+ storm = MathUtils.damp(storm, settings.blizzard ? 1 : 0, 0.95, dt);
257
255
  const gust = 1 + 0.22 * Math.sin(time * 1.1) + 0.12 * Math.sin(time * 2.73 + 1.6);
258
256
  const target = (settings.wind * (1 - storm) + (9.5 + settings.wind * 0.5) * storm) * gust;
259
- wind = damp(wind, target, 2.3, dt);
257
+ wind = MathUtils.damp(wind, target, 2.3, dt);
260
258
  drifted = { x: drifted.x + wind * dt, z: drifted.z + wind * 0.24 * dt };
261
259
  fallen += settings.fallSpeed * (0.95 + storm * 0.7) * dt;
262
260
  fall.drift.value.set(drifted.x, drifted.z);
@@ -1,4 +1,5 @@
1
1
  import { Heightfield, SnowField } from "@threenative/core/world";
2
+ import { MathUtils } from "three";
2
3
 
3
4
  /** The playable snowfield is a square this many metres across, centred on the origin. */
4
5
  export const FIELD_SIZE = 24;
@@ -22,7 +23,7 @@ export const EXPLORER_LAYER = 0b1000;
22
23
 
23
24
  function smoothstep(edge0: number, edge1: number, value: number): number {
24
25
  const t = Math.max(0, Math.min(1, (value - edge0) / (edge1 - edge0)));
25
- return t * t * (3 - 2 * t);
26
+ return MathUtils.smoothstep(t, 0, 1);
26
27
  }
27
28
 
28
29
  /** Rolling ground under the snow: gentle swells in the glade, hills beyond it. */
@@ -52,34 +52,34 @@
52
52
  },
53
53
  "mobile-low": {
54
54
  "contributions": {
55
- "graphOutputChanged": ["ssr", "bloom", "vignette", "antialias"]
55
+ "graphOutputChanged": ["bloom", "vignette", "antialias"]
56
56
  },
57
57
  "stages": {
58
58
  "excludes": ["ambientOcclusion", "ssgi", "traa", "motionBlur", "grade", "grain"],
59
- "includes": ["ssr", "bloom", "vignette", "antialias"],
60
- "order": ["ssr", "bloom", "vignette", "antialias"]
59
+ "includes": ["bloom", "vignette", "antialias"],
60
+ "order": ["bloom", "vignette", "antialias"]
61
61
  },
62
62
  "tier": "low"
63
63
  },
64
64
  "mobile-mid": {
65
65
  "contributions": {
66
- "graphOutputChanged": ["ssr", "bloom", "vignette", "antialias"]
66
+ "graphOutputChanged": ["bloom", "vignette", "antialias"]
67
67
  },
68
68
  "stages": {
69
69
  "excludes": ["ambientOcclusion", "ssgi", "traa", "motionBlur", "grade", "grain"],
70
- "includes": ["ssr", "bloom", "vignette", "antialias"],
71
- "order": ["ssr", "bloom", "vignette", "antialias"]
70
+ "includes": ["bloom", "vignette", "antialias"],
71
+ "order": ["bloom", "vignette", "antialias"]
72
72
  },
73
73
  "tier": "low"
74
74
  },
75
75
  "software": {
76
76
  "contributions": {
77
- "graphOutputChanged": ["ssr", "bloom", "vignette", "antialias"]
77
+ "graphOutputChanged": ["bloom", "vignette", "antialias"]
78
78
  },
79
79
  "stages": {
80
80
  "excludes": ["ambientOcclusion", "ssgi", "traa", "motionBlur", "grade", "grain"],
81
- "includes": ["ssr", "bloom", "vignette", "antialias"],
82
- "order": ["ssr", "bloom", "vignette", "antialias"]
81
+ "includes": ["bloom", "vignette", "antialias"],
82
+ "order": ["bloom", "vignette", "antialias"]
83
83
  },
84
84
  "tier": "low"
85
85
  }
@@ -20,9 +20,9 @@
20
20
  "format:check": "biome format src"
21
21
  },
22
22
  "dependencies": {
23
- "@threenative/core": "0.3.13",
24
- "@threenative/physics": "0.3.13",
25
- "@threenative/ui": "0.3.13",
23
+ "@threenative/core": ">=0.3.15",
24
+ "@threenative/physics": ">=0.3.15",
25
+ "@threenative/ui": ">=0.3.15",
26
26
  "react": "19.2.0",
27
27
  "react-dom": "19.2.0",
28
28
  "react-reconciler": "0.33.0",
@@ -30,13 +30,13 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@tailwindcss/vite": "4.3.3",
33
- "@threenative/assets": "0.3.14",
34
- "@threenative/playtest": "0.3.13",
33
+ "@threenative/assets": ">=0.3.16",
34
+ "@threenative/playtest": ">=0.3.15",
35
35
  "@types/react": "19.2.0",
36
36
  "@types/react-dom": "19.2.0",
37
37
  "@types/three": "0.187.0",
38
38
  "@vitejs/plugin-react": "6.0.5",
39
- "create-threenative": "0.2.18",
39
+ "create-threenative": "0.2.20",
40
40
  "esbuild": "0.27.0",
41
41
  "playwright": "1.62.1",
42
42
  "tailwindcss": "4.3.3",
@@ -47,7 +47,7 @@
47
47
  "eslint": "10.13.0"
48
48
  },
49
49
  "optionalDependencies": {
50
- "@threenative/runtime-native": "0.3.13"
50
+ "@threenative/runtime-native": ">=0.3.15"
51
51
  },
52
52
  "overrides": {
53
53
  "sharp": ">=0.35.4",
@@ -1,6 +1,14 @@
1
1
  import { BlendSpace1D, type ICtx, SkeletalMesh3D } from "@threenative/core";
2
2
  import { CharacterBody3D, CollisionShape3D, type IPhysicsContext } from "@threenative/physics";
3
- import { type AnimationClip, Group, type Mesh, type Object3D, Quaternion, Vector3 } from "three";
3
+ import {
4
+ type AnimationClip,
5
+ Group,
6
+ MathUtils,
7
+ type Mesh,
8
+ type Object3D,
9
+ Quaternion,
10
+ Vector3,
11
+ } from "three";
4
12
  import { type IStarterConventions, preparePlayerConventions } from "../conventions.js";
5
13
  import type { ITouchInput } from "../render/touch-controls.js";
6
14
  import type { GameState } from "../state.js";
@@ -143,7 +151,7 @@ export class Player {
143
151
  // Touch walks until the stick is fully deflected; no separate run button.
144
152
  const running = ctx.input.pressed("run") || (touch?.move.length() ?? 0) >= 1;
145
153
  const speed = running ? RUN_SPEED : WALK_SPEED;
146
- const ease = 1 - Math.exp(-dt / 0.15);
154
+ const ease = MathUtils.damp(0, 1, 1 / 0.15, dt);
147
155
  const moveZ = -move.y;
148
156
  this.body.velocity.x += (move.x * speed - this.body.velocity.x) * ease;
149
157
  this.body.velocity.z += (moveZ * speed - this.body.velocity.z) * ease;
@@ -9,7 +9,7 @@
9
9
  // Camera framing is one of the loudest things in a screenshot, so it lives
10
10
  // here in your repo rather than behind a framework option.
11
11
  import type { PerspectiveCamera, Vector3 } from "three";
12
- import { Vector3 as Vec3 } from "three";
12
+ import { MathUtils, Vector3 as Vec3 } from "three";
13
13
 
14
14
  export interface ISpringArmOptions {
15
15
  /** Where the camera sits relative to its target, before smoothing. */
@@ -102,7 +102,7 @@ export function createSpringArm(
102
102
  desired.copy(target).add(targetOffset());
103
103
  // 1 - e^(-dt/damping): the frame-rate-independent form of a lerp. At 30fps
104
104
  // and 120fps the camera ends up in the same place after the same second.
105
- camera.position.lerp(desired, 1 - Math.exp(-dt / damping));
105
+ camera.position.lerp(desired, MathUtils.damp(0, 1, 1 / damping, dt));
106
106
  clear(target);
107
107
  camera.lookAt(aim.copy(target).add(lookAhead));
108
108
  };
@@ -6,6 +6,8 @@
6
6
  // Independent CPU implementation. The material samples four Unreal textures that this repository
7
7
  // must not carry, so each one is regenerated here from a seeded noise whose per-channel value
8
8
  // quantiles and correlation lengths match the Unreal texture (measured, see the spec).
9
+ import { MathUtils } from "three";
10
+
9
11
  import {
10
12
  BOTTOM_KM,
11
13
  CAMERA_KM,
@@ -110,7 +112,7 @@ const PROFILE_COEFFICIENTS = [
110
112
  const clamp = (v: number): number => Math.max(0, Math.min(1, v));
111
113
  const smooth = (v: number): number => {
112
114
  const t = clamp(v);
113
- return t * t * (3 - 2 * t);
115
+ return MathUtils.smoothstep(t, 0, 1);
114
116
  };
115
117
  const mod = (a: number, n: number): number => ((a % n) + n) % n;
116
118
 
@@ -11,6 +11,7 @@ import {
11
11
  DoubleSide,
12
12
  Float32BufferAttribute,
13
13
  LinearMipmapLinearFilter,
14
+ MathUtils,
14
15
  MeshStandardMaterial,
15
16
  RepeatWrapping,
16
17
  SRGBColorSpace,
@@ -86,8 +87,8 @@ function grainNormalTexture(size = 128): DataTexture {
86
87
  const y0 = Math.floor(v);
87
88
  const fx = u - x0;
88
89
  const fy = v - y0;
89
- const sx = fx * fx * (3 - 2 * fx);
90
- const sy = fy * fy * (3 - 2 * fy);
90
+ const sx = MathUtils.smoothstep(fx, 0, 1);
91
+ const sy = MathUtils.smoothstep(fy, 0, 1);
91
92
  const at = (i: number, j: number): number =>
92
93
  values[(((j % count) + count) % count) * count + (((i % count) + count) % count)] ?? 0;
93
94
  const top = at(x0, y0) + (at(x0 + 1, y0) - at(x0, y0)) * sx;
@@ -15,6 +15,9 @@ const MOVE_RADIUS = 72;
15
15
  const BUTTON_RADIUS = 62;
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
  }
@@ -113,13 +116,11 @@ export class TouchControls {
113
116
  }
114
117
 
115
118
  const center = this.#hasMoveAnchor ? this.#moveAnchor : this.#resting;
116
- place(
117
- this.#moveKnob,
118
- new Vector2(
119
- center.x + this.#input.move.x * MOVE_RADIUS,
120
- center.y - this.#input.move.y * MOVE_RADIUS,
121
- ),
119
+ knobPosition.set(
120
+ center.x + this.#input.move.x * MOVE_RADIUS,
121
+ center.y - this.#input.move.y * MOVE_RADIUS,
122
122
  );
123
+ place(this.#moveKnob, knobPosition);
123
124
  this.#jump.material = jump ? this.#activeMaterial : this.#idleMaterial;
124
125
  this.#input.jumpPressed = jump && !this.#wasJump;
125
126
  this.#wasJump = jump;
@@ -451,20 +451,7 @@ export class Play extends Scene<GameState, IPhysicsContext> {
451
451
  ),
452
452
  );
453
453
  frameState.respawns = previous.respawns + (respawned ? 1 : 0);
454
- const current = frameCtx.state.getState();
455
- const changed =
456
- frameState.coyoteJumps !== current.coyoteJumps ||
457
- frameState.flagDisplacement !== current.flagDisplacement ||
458
- frameState.flagReadbacks !== current.flagReadbacks ||
459
- frameState.flagSteps !== current.flagSteps ||
460
- frameState.jumps !== current.jumps ||
461
- frameState.lives !== current.lives ||
462
- frameState.odometer !== current.odometer ||
463
- frameState.peakRise !== current.peakRise ||
464
- frameState.playerX !== current.playerX ||
465
- frameState.progress !== current.progress ||
466
- frameState.respawns !== current.respawns;
467
- if (changed) frameCtx.state.set(frameState);
454
+ frameCtx.state.set(frameState);
468
455
  if (respawned) frameCtx.state.flush();
469
456
  };
470
457
  }