create-threenative 0.2.18 → 0.2.21

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 (186) hide show
  1. package/agent-docs/references/assertion-reference.md +1 -1
  2. package/agent-docs/references/capability-reference.md +792 -5
  3. package/agent-docs/references/kit-racing.md +4 -2
  4. package/agent-docs/references/performance-basics.md +2 -1
  5. package/agent-docs/references/terrain-authoring.md +25 -7
  6. package/agent-files/.agents/skills/prd-creator/SKILL.md +24 -0
  7. package/dist/index.js +268 -237
  8. package/dist/quality.d.ts +5 -1
  9. package/dist/quality.js +75 -6
  10. package/dist/terrain-kit.js +1 -1
  11. package/dist/threenative.js +7 -5
  12. package/dist/web-engine-post-effects.js +6 -0
  13. package/dist/web-engine-runtime.js +407 -38
  14. package/package.json +6 -6
  15. package/template-assets/assets/floor-fern-0.glb +0 -0
  16. package/template-assets/assets/floor-litter-0.glb +0 -0
  17. package/template-assets/assets/floor-log-0.glb +0 -0
  18. package/template-assets/assets/floor-log-1.glb +0 -0
  19. package/template-assets/assets/floor-stump-0.glb +0 -0
  20. package/template-assets/assets/floor-twig-0.glb +0 -0
  21. package/template-assets/patches/three@0.187.0.patch +108 -21
  22. package/template-assets/quality/eslint.config.js +1 -1
  23. package/templates/action-rpg/package.json +7 -7
  24. package/templates/action-rpg/src/loot/drops.ts +3 -7
  25. package/templates/action-rpg/src/render/camera.ts +2 -2
  26. package/templates/action-rpg/src/render/clouds.ts +3 -1
  27. package/templates/action-rpg/src/render/materials.ts +3 -2
  28. package/templates/action-rpg/src/render/touch-controls.ts +7 -6
  29. package/templates/action-rpg/src/scenes/Play.ts +1 -15
  30. package/templates/adventure/AGENTS.md +3 -3
  31. package/templates/adventure/CLAUDE.md +3 -3
  32. package/templates/adventure/native-playtests/survives.playtest.json +12 -0
  33. package/templates/adventure/native-playtests/woodland-floor.playtest.json +61 -0
  34. package/templates/adventure/package.json +7 -7
  35. package/templates/adventure/playtests/grass.playtest.json +61 -0
  36. package/templates/adventure/playtests/performance.playtest.json +1 -1
  37. package/templates/adventure/playtests/survives.playtest.json +2 -2
  38. package/templates/adventure/playtests/woodland-floor.playtest.json +61 -0
  39. package/templates/adventure/src/entities/LockOn.ts +42 -4
  40. package/templates/adventure/src/entities/Warden.ts +12 -3
  41. package/templates/adventure/src/level/Vale.ts +241 -16
  42. package/templates/adventure/src/render/camera.ts +2 -2
  43. package/templates/adventure/src/render/foliage.ts +64 -20
  44. package/templates/adventure/src/render/grass.ts +325 -0
  45. package/templates/adventure/src/render/materials.ts +3 -2
  46. package/templates/adventure/src/render/palette.ts +3 -0
  47. package/templates/adventure/src/render/touch-controls.ts +4 -1
  48. package/templates/adventure/src/scenes/Play.ts +96 -1
  49. package/templates/collectathon/package.json +7 -7
  50. package/templates/collectathon/src/level/Course.ts +2 -7
  51. package/templates/collectathon/src/level/terrain.ts +2 -1
  52. package/templates/collectathon/src/render/camera.ts +2 -2
  53. package/templates/collectathon/src/render/ground.ts +4 -4
  54. package/templates/collectathon/src/render/hero.ts +1 -1
  55. package/templates/collectathon/src/render/materials.ts +0 -1
  56. package/templates/collectathon/src/render/sky.ts +4 -3
  57. package/templates/kart/package.json +6 -6
  58. package/templates/kart/src/entities/Kart.ts +2 -1
  59. package/templates/kart/src/render/course.ts +2 -1
  60. package/templates/kart/src/track/Course.ts +3 -1
  61. package/templates/minimal/package.json +6 -6
  62. package/templates/minimal/src/render/camera.ts +2 -2
  63. package/templates/minimal/src/render/clouds.ts +3 -1
  64. package/templates/minimal/src/render/materials.ts +3 -2
  65. package/templates/minimal/src/render/touch-controls.ts +7 -6
  66. package/templates/platformer/package.json +7 -7
  67. package/templates/platformer/playtests/collect.playtest.json +4 -1
  68. package/templates/platformer/src/level/Stage.ts +2 -6
  69. package/templates/platformer/src/scenes/Play.ts +2 -1
  70. package/templates/puzzle/package.json +7 -7
  71. package/templates/puzzle/src/entities/Warden.ts +3 -3
  72. package/templates/puzzle/src/render/camera.ts +2 -2
  73. package/templates/puzzle/src/render/touch-controls.ts +7 -6
  74. package/templates/racing/AGENTS.md +2 -2
  75. package/templates/racing/CLAUDE.md +2 -2
  76. package/templates/racing/CREDITS.md +29 -0
  77. package/templates/racing/assets/engine-loop.wav +0 -0
  78. package/templates/racing/assets/grass/Grass004_color.jpg +0 -0
  79. package/templates/racing/assets/grass/Grass004_normal.jpg +0 -0
  80. package/templates/racing/assets/grass/Grass004_roughness.jpg +0 -0
  81. package/templates/racing/assets/nitro-burst.wav +0 -0
  82. package/templates/racing/assets/tyre-squeal.wav +0 -0
  83. package/templates/racing/package.json +7 -7
  84. package/templates/racing/playtests/drift-natural.playtest.json +68 -0
  85. package/templates/racing/playtests/drift.playtest.json +100 -0
  86. package/templates/racing/playtests/hud.playtest.json +117 -0
  87. package/templates/racing/playtests/launch-pose.playtest.json +34 -0
  88. package/templates/racing/playtests/nitro.playtest.json +158 -0
  89. package/templates/racing/playtests/outcome.playtest.json +4 -4
  90. package/templates/racing/playtests/performance.playtest.json +1 -1
  91. package/templates/racing/playtests/steady-camera.playtest.json +88 -0
  92. package/templates/racing/src/audio/engine.ts +138 -0
  93. package/templates/racing/src/entities/CarBody.ts +83 -10
  94. package/templates/racing/src/entities/Drift.ts +243 -0
  95. package/templates/racing/src/entities/LineDriver.ts +2 -2
  96. package/templates/racing/src/entities/Nitro.ts +72 -0
  97. package/templates/racing/src/entities/RacingCar.ts +86 -21
  98. package/templates/racing/src/entities/Rival.ts +35 -21
  99. package/templates/racing/src/game.ts +6 -0
  100. package/templates/racing/src/gauges.ts +74 -0
  101. package/templates/racing/src/render/camera.ts +29 -4
  102. package/templates/racing/src/render/clouds.ts +3 -1
  103. package/templates/racing/src/render/effects.ts +244 -0
  104. package/templates/racing/src/render/materials.ts +43 -8
  105. package/templates/racing/src/render/shapes.ts +37 -0
  106. package/templates/racing/src/render/skids.ts +84 -0
  107. package/templates/racing/src/render/touch-controls.ts +10 -10
  108. package/templates/racing/src/scenes/Race.ts +277 -25
  109. package/templates/racing/src/state.ts +35 -0
  110. package/templates/racing/src/style.css +3 -0
  111. package/templates/racing/src/track/Ranking.ts +8 -4
  112. package/templates/racing/src/track/Track.ts +132 -58
  113. package/templates/racing/src/track/TrackSector.ts +19 -1
  114. package/templates/racing/src/track/circuit.ts +21 -15
  115. package/templates/racing/src/ui/GameUi.tsx +0 -2
  116. package/templates/racing/src/ui/Hud.tsx +417 -50
  117. package/templates/racing/threenative.config.ts +15 -0
  118. package/templates/racing/tools/make-racing-audio.mjs +388 -0
  119. package/templates/rain/package.json +6 -6
  120. package/templates/rain/src/render/noise-volume.ts +2 -1
  121. package/templates/rain/src/state.ts +3 -1
  122. package/templates/rain/src/ui/GameUi.tsx +1 -1
  123. package/templates/rain/src/ui/automation.ts +10 -8
  124. package/templates/rain/src/ui/tempest.ts +3 -4
  125. package/templates/rts/package.json +6 -6
  126. package/templates/rts/src/sim/terrain.ts +1 -0
  127. package/templates/rts/src/sim/types.ts +1 -0
  128. package/templates/runner/package.json +7 -7
  129. package/templates/runner/src/render/clouds.ts +3 -1
  130. package/templates/runner/src/render/materials.ts +3 -2
  131. package/templates/runner/src/render/touch-controls.ts +7 -6
  132. package/templates/runner/src/scenes/Run.ts +4 -9
  133. package/templates/sailing/package.json +7 -7
  134. package/templates/sailing/src/render/touch-controls.ts +7 -6
  135. package/templates/shooter/package.json +7 -7
  136. package/templates/shooter/src/render/clouds.ts +3 -1
  137. package/templates/snow/package.json +7 -7
  138. package/templates/snow/src/entities/Explorer.ts +6 -12
  139. package/templates/snow/src/render/bootPrint.ts +3 -1
  140. package/templates/snow/src/render/camera.ts +3 -2
  141. package/templates/snow/src/render/scenery.ts +3 -3
  142. package/templates/snow/src/render/touch-controls.ts +7 -6
  143. package/templates/snow/src/render/weather.ts +3 -5
  144. package/templates/snow/src/terrain.ts +2 -1
  145. package/templates/starter/native-playtests/render-chain.playtest.json +9 -9
  146. package/templates/starter/package.json +7 -7
  147. package/templates/starter/src/entities/Player.ts +10 -2
  148. package/templates/starter/src/render/camera.ts +2 -2
  149. package/templates/starter/src/render/clouds.ts +3 -1
  150. package/templates/starter/src/render/materials.ts +3 -2
  151. package/templates/starter/src/render/touch-controls.ts +7 -6
  152. package/templates/starter/src/scenes/Play.ts +1 -14
  153. package/templates/tower-defense/package.json +7 -7
  154. package/templates/tower-defense/src/render/shapes.ts +1 -2
  155. package/templates/tower-defense/src/scenes/Battle.ts +3 -8
  156. package/template-assets/terrain/alpine/assets.json +0 -12
  157. package/template-assets/terrain/alpine/bake.mjs +0 -6
  158. package/template-assets/terrain/alpine/credits.json +0 -164
  159. package/template-assets/terrain/alpine/heightmap.r16 +0 -0
  160. package/template-assets/terrain/alpine/recipe.json +0 -119
  161. package/template-assets/terrain/alpine/surface.json +0 -53
  162. package/template-assets/terrain/coastal/assets.json +0 -11
  163. package/template-assets/terrain/coastal/bake.mjs +0 -6
  164. package/template-assets/terrain/coastal/credits.json +0 -117
  165. package/template-assets/terrain/coastal/heightmap.r16 +0 -0
  166. package/template-assets/terrain/coastal/recipe.json +0 -113
  167. package/template-assets/terrain/coastal/surface.json +0 -41
  168. package/template-assets/terrain/desert/assets.json +0 -12
  169. package/template-assets/terrain/desert/bake.mjs +0 -6
  170. package/template-assets/terrain/desert/credits.json +0 -164
  171. package/template-assets/terrain/desert/heightmap.r16 +0 -0
  172. package/template-assets/terrain/desert/recipe.json +0 -108
  173. package/template-assets/terrain/desert/surface.json +0 -54
  174. package/template-assets/terrain/forest/assets.json +0 -65
  175. package/template-assets/terrain/forest/bake.mjs +0 -8
  176. package/template-assets/terrain/forest/credits.json +0 -225
  177. package/template-assets/terrain/forest/heightmap.r16 +0 -0
  178. package/template-assets/terrain/forest/recipe.json +0 -350
  179. package/template-assets/terrain/forest/surface.json +0 -79
  180. package/template-assets/terrain/tundra/assets.json +0 -12
  181. package/template-assets/terrain/tundra/bake.mjs +0 -6
  182. package/template-assets/terrain/tundra/credits.json +0 -164
  183. package/template-assets/terrain/tundra/heightmap.r16 +0 -0
  184. package/template-assets/terrain/tundra/recipe.json +0 -277
  185. package/template-assets/terrain/tundra/surface.json +0 -54
  186. package/templates/racing/src/ui/Menu.tsx +0 -7
@@ -3,7 +3,7 @@
3
3
  // The vale's planting and its floor, an old misty forest built in code. Giant gnarled trees (a
4
4
  // twisted trunk with ridged bark, thick roots and limbs, moss on every upward face) under broad
5
5
  // crowns of leaf clumps that sway; far trees in a lighter cut; big lobed broadleaf plants, ferns,
6
- // purple and pink flowers and grass tufts; mossy boulders; an irregular flagstone path; a stream;
6
+ // purple and pink flowers; mossy boulders; an irregular flagstone path; a stream;
7
7
  // mushrooms and logs; ivy and vines on the cliff. Every kind is one `InstancedMesh`, so a forest
8
8
  // costs a few dozen draws and no light of its own. Nothing here is solid: `level/Vale.ts` decides
9
9
  // what blocks, and its height function is the floor everything here stands on.
@@ -20,11 +20,14 @@ import {
20
20
  ConeGeometry,
21
21
  CylinderGeometry,
22
22
  DoubleSide,
23
+ FrontSide,
23
24
  Group,
24
25
  IcosahedronGeometry,
25
26
  InstancedMesh,
26
27
  type Material,
28
+ MathUtils,
27
29
  Mesh,
30
+ MeshStandardMaterial,
28
31
  Object3D,
29
32
  OctahedronGeometry,
30
33
  SphereGeometry,
@@ -333,10 +336,19 @@ function limb(
333
336
  return tube;
334
337
  }
335
338
 
336
- /** Colours bark by its normal: moss on every face that looks up, bark below, darker at the foot. */
337
- export function mossBark(geometry: BufferGeometry, moss: number): BufferGeometry {
339
+ /**
340
+ * Colours bark by its normal: moss on every face that looks up, bark below, darker at the foot.
341
+ * `keepNormals` trusts the normals the geometry already carries instead of recomputing them, for a
342
+ * baked mesh: a recomputed normal on a two-centimetre triangle collapses to NaN, and the NaN lands
343
+ * in the vertex colours this function writes, where bloom carries it across the whole frame.
344
+ */
345
+ export function mossBark(
346
+ geometry: BufferGeometry,
347
+ moss: number,
348
+ keepNormals = false,
349
+ ): BufferGeometry {
338
350
  const g = geometry.index === null ? geometry : geometry.toNonIndexed();
339
- g.computeVertexNormals();
351
+ if (!keepNormals || g.attributes.normal === undefined) g.computeVertexNormals();
340
352
  const normal = g.attributes.normal;
341
353
  const position = g.attributes.position;
342
354
  if (normal === undefined || position === undefined) return g;
@@ -641,19 +653,8 @@ export function plantVale(site: IValeSite): {
641
653
  group.add(instanced(cluster(head), swaying(0.25), placements, false));
642
654
  }
643
655
 
644
- // Grass tufts in the open spaces off the path, where the canopy lets light in.
645
- const tufts: Placement[] = [];
646
- for (let i = 0; i < 340; i += 1) {
647
- // Half of them fringe the path, where the cobbles meet the moss.
648
- const z = clearing.north + rng() * (clearing.south - clearing.north);
649
- const x =
650
- i % 2 === 0
651
- ? site.pathX(z) + (rng() < 0.5 ? -1 : 1) * (1.75 + rng() * 1.4)
652
- : (rng() * 2 - 1) * clearing.half;
653
- if (Math.abs(x - site.pathX(z)) < 1.7 || site.stream.distance(x, z) < 1.4) continue;
654
- tufts.push(P(x, 0, z, 0.7 + rng() * 0.9, 0.6 + rng() * 0.9));
655
- }
656
- group.add(instanced(fan(4, 0.04, 0.42, 0.4, C.grassTip), swaying(0.6), tufts, false));
656
+ // The grass itself is streamed: `render/grass.ts` is its look, `GrassField3D` in `scenes/Play.ts`
657
+ // grows it.
657
658
 
658
659
  // Mushrooms in rings under the giants, fallen logs, and mossy boulders.
659
660
  const mushrooms: Placement[] = [];
@@ -1006,7 +1007,7 @@ export function valeGround(
1006
1007
  0.5 + 0.25 * (Math.sin(x * f + z * f * 0.55) + Math.sin(z * f * 1.4 - x * f * 0.37 + 1.3));
1007
1008
  const smooth = (a: number, b: number, t: number): number => {
1008
1009
  const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
1009
- return u * u * (3 - 2 * u);
1010
+ return MathUtils.smoothstep(u, 0, 1);
1010
1011
  };
1011
1012
  const paintGround = (geometry: BufferGeometry): void => {
1012
1013
  const position = geometry.attributes.position;
@@ -1021,12 +1022,15 @@ export function valeGround(
1021
1022
  c.copy(soil).lerp(moss, 0.35 + 0.55 * smooth(0.35, 0.75, wave(x + 40, z - 17, 0.27)));
1022
1023
  c.lerp(mossBright, smooth(0.6, 0.85, wave(x - 3, z + 5, 0.45)) * 0.5);
1023
1024
  c.lerp(meadow, smooth(0.66, 0.82, wave(x * 0.7, z * 0.7 + 9, 0.21)) * 0.3);
1025
+ // Leaf litter and bare soil under the old trees. The same zone thins the grass and gathers the
1026
+ // scattered debris, so the ground the props stand on is the ground they are meant for.
1024
1027
  let nearTree = 0;
1025
1028
  for (const [tx, tz, ts] of site.trees) {
1026
1029
  const d = Math.hypot(x - tx, z - tz);
1027
- if (d < 5 * ts) nearTree = Math.max(nearTree, 1 - smooth(1.4 * ts, 4.5 * ts, d));
1030
+ nearTree = Math.max(nearTree, 1 - smooth(1.2 * ts, 4.2 * ts, d));
1028
1031
  }
1029
- c.lerp(litter, nearTree * 0.6 * (0.6 + 0.4 * wave(x, z, 0.9)));
1032
+ c.lerp(litter, nearTree * (0.62 + 0.34 * wave(x, z, 0.9)));
1033
+ c.lerp(soil, nearTree * 0.3);
1030
1034
  // Dark soil under the path, the flagstones on top of it.
1031
1035
  const off = Math.abs(x - site.pathX(z)) + (wave(x, z, 1.3) - 0.5) * 0.5;
1032
1036
  if (z > site.clearing.north - 9 && z < site.clearing.south + 1)
@@ -1070,3 +1074,43 @@ export function valeGround(
1070
1074
  meshes.inner.name = "vale-floor";
1071
1075
  return meshes;
1072
1076
  }
1077
+
1078
+ /** What a baked forest-floor part is, so it takes the matching look of the kit. */
1079
+ export type FloorKind = "frond" | "litter" | "wood";
1080
+
1081
+ /**
1082
+ * The forest floor in the kit's own look, tuned here and nowhere else. Wood (logs, stumps, twigs)
1083
+ * takes the old trees' mossy ridged bark, so a fallen log reads as one of them. Litter keeps the
1084
+ * bake's COLOR_0 times its base colour. A frond keeps Arbor's leaf atlas, cut out rather than
1085
+ * blended, exactly as the tree crowns are.
1086
+ */
1087
+ export function floorPart(
1088
+ mesh: Mesh,
1089
+ kind: FloorKind,
1090
+ ): { geometry: BufferGeometry; material: Material } {
1091
+ if (kind === "wood") {
1092
+ // The bake's own normals, never recomputed: see `mossBark`'s `keepNormals`.
1093
+ const baked = mesh.geometry.index === null ? mesh.geometry : mesh.geometry.toNonIndexed();
1094
+ return {
1095
+ // A little moss on the shoulders, never enough to paint a log the colour of the ground it
1096
+ // lies on: the debris has to read as deadwood, not as another patch of grass.
1097
+ geometry: mossBark(baked, 0.18, true),
1098
+ material: surfaced(0xffffff, "bark", { vertexColors: true }),
1099
+ };
1100
+ }
1101
+ const baked = mesh.material as MeshStandardMaterial;
1102
+ const frond = kind === "frond";
1103
+ return {
1104
+ geometry: mesh.geometry,
1105
+ material: new MeshStandardMaterial({
1106
+ // COLOR_0 is the bake's variation; the base colour is its tone, so both multiply.
1107
+ color: frond ? 0xffffff : baked.color,
1108
+ map: frond ? baked.map : null,
1109
+ metalness: 0,
1110
+ roughness: 0.9,
1111
+ side: frond ? DoubleSide : FrontSide,
1112
+ vertexColors: true,
1113
+ ...(frond ? { alphaTest: 0.45 } : {}),
1114
+ }),
1115
+ };
1116
+ }
@@ -0,0 +1,325 @@
1
+ // Generated for you. This is ordinary Three.js TSL — edit or delete it freely.
2
+ //
3
+ // The vale's grass look: the blade shape and the material that bends, sways, thins and colours it.
4
+ // `GrassField3D` (built in `scenes/Play.ts`) owns the streaming, the scatter, the LOD and the
5
+ // pushers; everything you see is decided here. Each blade bends along a quadratic Bezier from its
6
+ // root: a resting lean, a gust field that scrolls downwind, a per-blade flutter, and the pushers'
7
+ // pull, which lays it flat round Wren. Far blades thin out by priority while the ones left widen,
8
+ // so the field holds its cover and nothing pops. Lighting is the scene's own (sun, sky, exposure,
9
+ // fog), plus light through the blade when the sun is behind it and darker roots.
10
+ import { BufferAttribute, BufferGeometry, Color, DoubleSide, type Vector4 } from "three";
11
+ import {
12
+ Fn,
13
+ abs,
14
+ attribute,
15
+ cameraPosition,
16
+ cos,
17
+ cross,
18
+ dot,
19
+ float,
20
+ floor,
21
+ fract,
22
+ max,
23
+ min,
24
+ mix,
25
+ modelWorldMatrix,
26
+ normalize,
27
+ positionGeometry,
28
+ positionWorld,
29
+ pow,
30
+ sin,
31
+ smoothstep,
32
+ sqrt,
33
+ time,
34
+ transformNormalToView,
35
+ varying,
36
+ vec2,
37
+ vec3,
38
+ vec4,
39
+ } from "three/tsl";
40
+ import { MeshStandardNodeMaterial, type Node, type UniformNode } from "three/webgpu";
41
+ import { C } from "./palette.js";
42
+ import { SUN_DIRECTION } from "./sky.js";
43
+
44
+ /** Every look value, in one place. Shape and wind are live through the uniforms below. */
45
+ export const GRASS = {
46
+ /** Blade segments near, mid and far: each level is one draw range of the same geometry. */
47
+ segments: [4, 2, 1],
48
+ bladeHeight: 0.5,
49
+ /** ± share of `bladeHeight`. */
50
+ heightVariation: 0.4,
51
+ bladeWidth: 0.05,
52
+ /** Higher stays wide longer, then a sharper tip. */
53
+ taper: 1.7,
54
+ /** Resting lean, 0 upright to 1 flat. */
55
+ lean: 0.34,
56
+ leanVariation: 0.2,
57
+ /** Where the bend happens: low arcs from the root, high is a straight stem with a drooping tip. */
58
+ curve: 0.6,
59
+ /** 0 is a uniform lawn, 1 strong tufts. */
60
+ clumpStrength: 0.75,
61
+ /** Widens edge-on blades so they do not alias into lines. */
62
+ viewThicken: 0.55,
63
+ /** Sinks the roots to hide the seam with the floor. */
64
+ rootSink: 0.03,
65
+ /** Each far blade is this many times wider, holding the cover the thinning took. */
66
+ farWidth: 2.8,
67
+ /** Degrees in the ground plane the wind blows toward (0 = +X, 90 = +Z). */
68
+ windDirection: 25,
69
+ /** Gust fronts travel this fast, m/s, and are this big, metres. */
70
+ windSpeed: 4.5,
71
+ gustScale: 26,
72
+ /** Lean added at the peak of a gust, and the per-blade jitter. */
73
+ windStrength: 0.55,
74
+ flutter: 0.07,
75
+ /** Gusts brighten the blades they bend, which makes wind read as waves from afar. */
76
+ gustHighlight: 0.45,
77
+ /** How far a pusher lays the blades over. */
78
+ pushStrength: 1,
79
+ baseColor: C.grassRoot,
80
+ tipColor: C.grassTip,
81
+ /** Broad patches drift toward this colour. */
82
+ dryColor: C.grassDry,
83
+ dryAmount: 0.35,
84
+ patchScale: 22,
85
+ /** Per-tuft brightness spread. */
86
+ colorVariation: 0.4,
87
+ /** Darkening toward the roots. */
88
+ ambientOcclusion: 0.45,
89
+ /** Sunlight through a blade lit from behind. */
90
+ translucency: 0.7,
91
+ /** 0 lights each blade by its own normal, 1 like the ground under it (calmer). */
92
+ terrainNormalBlend: 0.6,
93
+ } as const;
94
+
95
+ const rgb = (hex: number): Node<"vec3"> => {
96
+ const c = new Color(hex);
97
+ return vec3(c.r, c.g, c.b);
98
+ };
99
+
100
+ /** The sun colour the translucency carries, as the key light's colour. */
101
+ const SUN_COLOR = new Color(0xffd9a0);
102
+
103
+ /** The field's uniforms the material reads: what `GrassField3D` hands to `grassMaterial`. */
104
+ export interface IGrassFieldUniforms {
105
+ readonly thinStart: UniformNode<"float", number>;
106
+ readonly thinEnd: UniformNode<"float", number>;
107
+ readonly farDensity: UniformNode<"float", number>;
108
+ readonly fadeStart: UniformNode<"float", number>;
109
+ readonly drawDistance: UniformNode<"float", number>;
110
+ readonly pushers: readonly UniformNode<"vec4", Vector4>[];
111
+ push(rootWorld: Node<"vec3">): Node<"vec3">;
112
+ }
113
+
114
+ /** Every LOD of one blade in one geometry, x across (-0.5..0.5) and y along it (0 root, 1 tip). */
115
+ export function grassBlade(): {
116
+ geometry: BufferGeometry;
117
+ lods: { start: number; count: number }[];
118
+ reach: number;
119
+ } {
120
+ const pos: number[] = [];
121
+ const idx: number[] = [];
122
+ const lods: { start: number; count: number }[] = [];
123
+ for (const seg of GRASS.segments) {
124
+ const base = pos.length / 3;
125
+ const start = idx.length;
126
+ for (let r = 0; r < seg; r++) pos.push(-0.5, r / seg, 0, 0.5, r / seg, 0);
127
+ pos.push(0, 1, 0);
128
+ for (let r = 0; r < seg - 1; r++) {
129
+ const a = base + r * 2;
130
+ idx.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
131
+ }
132
+ const a = base + (seg - 1) * 2;
133
+ idx.push(a, a + 1, a + 2);
134
+ lods.push({ start, count: idx.length - start });
135
+ }
136
+ const geometry = new BufferGeometry();
137
+ geometry.setAttribute("position", new BufferAttribute(new Float32Array(pos), 3));
138
+ geometry.setIndex(idx);
139
+ return { geometry, lods, reach: GRASS.bladeHeight * (1 + GRASS.heightVariation) };
140
+ }
141
+
142
+ const hash2 = (p: Node<"vec2">): Node<"float"> => {
143
+ const q = fract(p.mul(vec2(123.34, 456.21)));
144
+ const r = q.add(dot(q, q.add(45.32)));
145
+ return fract(r.x.mul(r.y));
146
+ };
147
+
148
+ /** Smooth value noise, 0..1. */
149
+ const noise = Fn(([p]: [Node<"vec2">]) => {
150
+ const i = floor(p);
151
+ const f = fract(p);
152
+ const u = f.mul(f).mul(float(3).sub(f.mul(2)));
153
+ return mix(
154
+ mix(hash2(i), hash2(i.add(vec2(1, 0))), u.x),
155
+ mix(hash2(i.add(vec2(0, 1))), hash2(i.add(vec2(1, 1))), u.x),
156
+ u.y,
157
+ );
158
+ });
159
+
160
+ /**
161
+ * The blade material for `GrassField3D`: reads the field's instance attributes (`grassRoot`,
162
+ * `grassRand`, `grassClump`) and uniforms. Its thinning uses the field's own ranges, so the CPU
163
+ * trim only drops blades this material already hid.
164
+ */
165
+ export function grassMaterial(field: IGrassFieldUniforms): MeshStandardNodeMaterial {
166
+ const g = GRASS;
167
+ const root = attribute("grassRoot", "vec3");
168
+ const rand = attribute("grassRand", "vec4");
169
+ const clump = attribute("grassClump", "vec4");
170
+ const windAngle = (g.windDirection * Math.PI) / 180;
171
+ const wind = vec2(Math.cos(windAngle), Math.sin(windAngle));
172
+ // The blade's own vertex: after `positionNode` moves it, `positionLocal` reads the moved
173
+ // vertex, whose y is the ground height, not the share of the blade.
174
+ const t = positionGeometry.y;
175
+ const side = positionGeometry.x.mul(2);
176
+ const rootWorld = modelWorldMatrix.mul(vec4(root, 1)).xyz;
177
+ const dist = rootWorld.distance(cameraPosition);
178
+ const r0 = fract(sin(rand.z.mul(9871.13).add(0.71)).mul(43758.5453));
179
+ const r1 = fract(r0.mul(57.31).add(rand.x.mul(3.17)));
180
+
181
+ // Distance thinning: blades past this distance's priority cut-off shrink away; the far edge sinks.
182
+ const thinT = smoothstep(field.thinStart, field.thinEnd, dist);
183
+ const keepEdge = mix(float(1.1), field.farDensity, thinT);
184
+ const keep = float(1).sub(smoothstep(keepEdge.sub(0.1), keepEdge, rand.z));
185
+ const fadeSpan = field.drawDistance.sub(field.fadeStart);
186
+ const fadeT = smoothstep(
187
+ field.fadeStart,
188
+ field.drawDistance,
189
+ dist.add(r0.mul(fadeSpan).mul(0.5)),
190
+ );
191
+ const grow = rand.w.mul(keep).mul(float(1).sub(fadeT));
192
+
193
+ // Facing: random, pulled outward from the tuft centre.
194
+ const a = rand.x.mul(Math.PI * 2);
195
+ const facing = normalize(
196
+ mix(vec2(cos(a), sin(a)), vec2(cos(clump.x), sin(clump.x)), g.clumpStrength * 0.65).add(1e-4),
197
+ );
198
+ const height = float(g.bladeHeight)
199
+ .mul(mix(float(1 - g.heightVariation), float(1 + g.heightVariation), rand.y))
200
+ .mul(mix(float(1), clump.y.add(0.5), g.clumpStrength))
201
+ .mul(grow);
202
+
203
+ // Wind: a gust field scrolling downwind, plus per-blade flutter.
204
+ const wuv = rootWorld.xz.sub(wind.mul(time).mul(g.windSpeed)).div(g.gustScale);
205
+ const gust = smoothstep(
206
+ 0.25,
207
+ 0.8,
208
+ noise(wuv)
209
+ .mul(0.6)
210
+ .add(noise(wuv.mul(2.31).add(17.3)).mul(0.4)),
211
+ );
212
+ const fl = gust.mul(0.6).add(0.4).mul(g.flutter);
213
+ const flutA = sin(time.mul(r0.mul(2.2).add(2.6)).add(r1.mul(Math.PI * 2))).mul(fl);
214
+ const flutB = sin(time.mul(r1.mul(2).add(3.3)).add(r0.mul(Math.PI * 2))).mul(fl);
215
+ const pushed = field.push(rootWorld);
216
+ const press = pushed.z;
217
+ const tipRaw = facing
218
+ .mul(
219
+ max(
220
+ r1
221
+ .sub(0.5)
222
+ .mul(2 * g.leanVariation)
223
+ .add(g.lean),
224
+ 0,
225
+ ),
226
+ )
227
+ .add(wind.mul(gust.mul(0.88).add(0.12).mul(g.windStrength).add(flutA)))
228
+ .add(vec2(wind.y.negate(), wind.x).mul(flutB))
229
+ .add(pushed.xy.mul(g.pushStrength));
230
+ const tip = tipRaw.mul(min(1, float(0.96).div(max(tipRaw.length(), 1e-4))));
231
+ const tipY = sqrt(max(float(1).sub(dot(tip, tip)), 0));
232
+ const h = height.mul(float(1).sub(press.mul(0.3)));
233
+
234
+ // Quadratic Bezier: root, a control point straight up, the tip.
235
+ const p1 = vec3(0, g.curve, 0);
236
+ const p2 = vec3(tip.x, tipY, tip.y);
237
+ const it = float(1).sub(t);
238
+ const curve = p1.mul(it.mul(t).mul(2)).add(p2.mul(t.mul(t)));
239
+ const tangent = normalize(p1.mul(it.mul(2)).add(p2.sub(p1).mul(t.mul(2))));
240
+ // The flat of the blade turns toward the way it bends.
241
+ const f2 = normalize(facing.mul(0.6).add(tip).add(1e-4));
242
+ const across = vec3(f2.y.negate(), 0, f2.x);
243
+ const bladeNormal = normalize(cross(across, tangent));
244
+ const width = float(g.bladeWidth * 0.5)
245
+ .mul(mix(float(1), float(g.farWidth), thinT))
246
+ .mul(r1.mul(0.5).add(0.75))
247
+ .mul(float(1).sub(pow(t, g.taper)))
248
+ .mul(sqrt(grow));
249
+ // Edge-on blades turn a little toward the camera.
250
+ const toCam = normalize(cameraPosition.sub(rootWorld));
251
+ const edge = float(1).sub(abs(dot(bladeNormal, toCam)));
252
+ const thick = edge.mul(edge).mul(g.viewThicken);
253
+ const local = root
254
+ .add(curve.mul(h))
255
+ .add(across.add(bladeNormal.mul(thick)).mul(side.mul(width)))
256
+ .sub(vec3(0, it.mul(g.rootSink), 0));
257
+
258
+ // Per-blade values the fragment stage reads.
259
+ const ground = vec3(
260
+ clump.z,
261
+ sqrt(max(float(1).sub(clump.z.mul(clump.z)).sub(clump.w.mul(clump.w)), 0)),
262
+ clump.w,
263
+ );
264
+ const vNormal = varying(
265
+ normalize(mix(bladeNormal, ground, mix(float(g.terrainNormalBlend), float(1), thinT))),
266
+ );
267
+ const vT = varying(t);
268
+ const vFar = varying(thinT);
269
+ const vTuft = varying(clump.y.mul(0.65).add(r0.mul(0.35)));
270
+ const patchUv = rootWorld.xz.div(g.patchScale);
271
+ const vPatch = varying(
272
+ smoothstep(
273
+ 0.3,
274
+ 0.8,
275
+ noise(patchUv.add(91.7))
276
+ .mul(0.65)
277
+ .add(noise(patchUv.mul(2.7).add(5.3)).mul(0.35)),
278
+ ),
279
+ );
280
+ const vGust = varying(gust);
281
+
282
+ const material = new MeshStandardNodeMaterial({ roughness: 0.75, side: DoubleSide });
283
+ material.name = "GrassBlades";
284
+ material.positionNode = local;
285
+ // The blade's normal, turned to face the viewer: a thin blade is lit on the side you see.
286
+ const view = cameraPosition.sub(positionWorld);
287
+ material.normalNode = transformNormalToView(
288
+ vNormal.mul(dot(vNormal, view).sign().add(0.5).sign()),
289
+ );
290
+ // Far blades converge on one mid colour with little root shade, so the thinned field reads as a surface.
291
+ const tc = mix(vT.mul(vT.mul(0.65).add(0.35)), max(vT, 0.5), vFar.mul(0.8));
292
+ const albedo = mix(rgb(g.baseColor), rgb(g.tipColor), tc);
293
+ const dried = mix(albedo, rgb(g.dryColor), vPatch.mul(g.dryAmount).mul(tc.mul(0.65).add(0.35)));
294
+ const occlusion = mix(
295
+ float(1 - g.ambientOcclusion).add(vFar.mul(0.75 * g.ambientOcclusion)),
296
+ float(1),
297
+ vT,
298
+ );
299
+ material.colorNode = vec4(
300
+ dried
301
+ .mul(vTuft.sub(0.5).mul(g.colorVariation).add(1))
302
+ .mul(vGust.sub(0.4).mul(g.gustHighlight).mul(vT).add(1)),
303
+ 1,
304
+ );
305
+ material.aoNode = occlusion;
306
+ // Sun on the far side of the blade: light comes through, warmer and more saturated.
307
+ const sun = vec3(SUN_DIRECTION.x, SUN_DIRECTION.y, SUN_DIRECTION.z);
308
+ const back = max(dot(vNormal, sun).negate(), 0);
309
+ const through = pow(max(dot(normalize(view), sun.negate()), 0), 5);
310
+ const sunColor = vec3(SUN_COLOR.r, SUN_COLOR.g, SUN_COLOR.b);
311
+ material.emissiveNode = dried
312
+ .mul(vec3(1.05, 1.2, 0.5))
313
+ .mul(sunColor)
314
+ .mul(back.mul(0.45).add(through.mul(back.mul(0.65).add(0.35)).mul(1.1)))
315
+ .mul(vT.mul(0.7).add(0.3))
316
+ .mul(g.translucency);
317
+ return material;
318
+ }
319
+
320
+ /** A blade's standing height at `(x, z)` as a share of its rest height: the CPU mirror of the bend under a pusher. */
321
+ export function grassStandAt(press: number): number {
322
+ const lean = GRASS.lean + press * GRASS.pushStrength;
323
+ const reach = Math.min(lean, 0.96);
324
+ return (1 - 0.3 * press) * Math.sqrt(1 - reach * reach);
325
+ }
@@ -15,6 +15,7 @@ import {
15
15
  LinearFilter,
16
16
  LinearMipmapLinearFilter,
17
17
  type Material,
18
+ MathUtils,
18
19
  MeshBasicMaterial,
19
20
  MeshStandardMaterial,
20
21
  NoColorSpace,
@@ -56,8 +57,8 @@ export function detailTexture(): DataTexture {
56
57
  const tx = fx - x0;
57
58
  const ty = fy - y0;
58
59
  const at = (i: number, j: number): number => rng(((j % cells) * cells + (i % cells)) * 1.37);
59
- const sx = tx * tx * (3 - 2 * tx);
60
- const sy = ty * ty * (3 - 2 * ty);
60
+ const sx = MathUtils.smoothstep(tx, 0, 1);
61
+ const sy = MathUtils.smoothstep(ty, 0, 1);
61
62
  const top = at(x0, y0) + (at(x0 + 1, y0) - at(x0, y0)) * sx;
62
63
  const bottom = at(x0, y0 + 1) + (at(x0 + 1, y0 + 1) - at(x0, y0 + 1)) * sx;
63
64
  return top + (bottom - top) * sy;
@@ -24,6 +24,9 @@ export const palette = {
24
24
  export const C = {
25
25
  grassDark: 0x4e7a2a,
26
26
  grassTip: 0x7f9e44,
27
+ /** The streamed grass: the dark root shade and the colour dry patches drift toward. */
28
+ grassRoot: 0x3b5a1d,
29
+ grassDry: 0xa89a4c,
27
30
  dirt: 0x8b6a48,
28
31
  path: 0xb39a72,
29
32
  stoneDark: 0x5d5a52,
@@ -36,6 +36,9 @@ const STICK_RADIUS = 72;
36
36
  const BUTTON_RADIUS = 46;
37
37
  const EDGE = 36;
38
38
 
39
+ /** The resting stick centre: `update` runs every frame, so it uses one instance. */
40
+ const restPoint = new Vector2();
41
+
39
42
  /** Where each button sits: a quarter-circle fan around the bottom-right corner. */
40
43
  function buttonPoint(size: ITouchViewport, index: number): Vector2 {
41
44
  const cx = size.width - EDGE - BUTTON_RADIUS;
@@ -84,7 +87,7 @@ export class TouchControls {
84
87
  }
85
88
 
86
89
  update(pointers: ReadonlyMap<number, ITouchPointer>, size: ITouchViewport): ITouchInput {
87
- const rest = new Vector2(STICK_RADIUS + EDGE, size.height - STICK_RADIUS - EDGE);
90
+ const rest = restPoint.set(STICK_RADIUS + EDGE, size.height - STICK_RADIUS - EDGE);
88
91
  let thumb: ITouchPointer | undefined;
89
92
  for (const pointer of pointers.values()) {
90
93
  if (pointer.position.x < size.width * 0.45 && pointer.position.y > size.height * 0.4) {
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  GPUParticles3D,
3
+ GrassField3D,
3
4
  Scene,
4
5
  type SceneFrame,
5
6
  afterPhysics,
6
7
  isMobile,
7
8
  isTouchscreenAvailable,
8
9
  } from "@threenative/core";
10
+ import { warmUnculled } from "@threenative/core/world";
9
11
  import { type IPhysicsContext, buildStaticColliders } from "@threenative/physics";
10
12
  import {
11
13
  Box3,
@@ -38,8 +40,13 @@ import { Warden } from "../entities/Warden.js";
38
40
  import { Interactions } from "../interact.js";
39
41
  import { type IHollow, buildHollow } from "../level/Hollow.js";
40
42
  import {
43
+ GRASS_BOUNDS,
41
44
  type IVale,
45
+ type IWoodlandFloor,
46
+ STREAM,
42
47
  buildVale,
48
+ buildWoodlandFloor,
49
+ grassCover,
43
50
  isSolid,
44
51
  makeRng,
45
52
  measureRelief,
@@ -47,10 +54,12 @@ import {
47
54
  } from "../level/Vale.js";
48
55
  import { setupCamera } from "../render/camera.js";
49
56
  import { BURSTS, EFFECTS } from "../render/effects.js";
57
+ import { grassBlade, grassMaterial, grassStandAt } from "../render/grass.js";
50
58
  import { setupLighting } from "../render/lighting.js";
51
59
  import { createLoadingScreen } from "../render/loading.js";
52
60
  import { setupPost } from "../render/postprocessing.js";
53
61
  import { createCompanion, createHeartVessel } from "../render/props.js";
62
+ import { resolveQualityTier } from "../render/quality.js";
54
63
  import { type ISky, createSky, setupSky } from "../render/sky.js";
55
64
  import { loadSurfaces, untexturedSurfaces, updateSurfaceSampling } from "../render/surface.js";
56
65
  import { TouchControls } from "../render/touch-controls.js";
@@ -126,6 +135,8 @@ export class Play extends Scene<GameState, IPhysicsContext> {
126
135
 
127
136
  #sky: ISky | undefined;
128
137
  #vale: IVale | undefined;
138
+ #floor: IWoodlandFloor | undefined;
139
+ #grass: GrassField3D | undefined;
129
140
  #hollow: IHollow | undefined;
130
141
  #hero: Hero | undefined;
131
142
  #dummies: Dummy[] = [];
@@ -147,6 +158,20 @@ export class Play extends Scene<GameState, IPhysicsContext> {
147
158
  this.#sky = createSky();
148
159
  setupSky(ctx.scene, this.#sky);
149
160
  const vale = buildVale(makeRng(1986));
161
+ // The forest floor: baked debris and ferns scattered under the old trees (PRD-889). The `low`
162
+ // tier (a software adapter, or a GPU the tier table rates low) leaves it out: on a CPU adapter
163
+ // it held the first frame window past three minutes. Pass `tier` here to force it either way.
164
+ const tier = resolveQualityTier({
165
+ gpuClass: ctx.renderer.gpuClass?.class,
166
+ mobile: isMobile(),
167
+ software: ctx.renderer.softwareAdapter !== undefined,
168
+ });
169
+ if (tier === "low") console.info("TN_WOODLAND_FLOOR off: quality tier low");
170
+ else {
171
+ const floor = await buildWoodlandFloor(ctx.assets, vale);
172
+ vale.group.add(floor.group);
173
+ this.#floor = floor;
174
+ }
150
175
  const hollow = buildHollow(makeRng(1998));
151
176
  this.#vale = vale;
152
177
  this.#hollow = hollow;
@@ -157,6 +182,54 @@ export class Play extends Scene<GameState, IPhysicsContext> {
157
182
  hero.mesh.position.set(vale.spawn.x, vale.spawn.y + FOOT_OFFSET, vale.spawn.z);
158
183
  hero.mesh.rotation.y = vale.spawnYaw;
159
184
  this.#hero = ctx.entities.add("player", hero);
185
+ // The vale's grass: streamed chunks round the camera, its look in `render/grass.ts`. It lives in
186
+ // the vale's group, so it hides with the vale when Wren is in the Hollow.
187
+ const grass = new GrassField3D({
188
+ blade: grassBlade(),
189
+ bounds: GRASS_BOUNDS,
190
+ // Bigger chunks are fewer draws: the engine's per-draw cost outweighed finer culling here.
191
+ buildBudgetMs: 2,
192
+ chunkSize: 16,
193
+ density: 18,
194
+ drawDistance: 40,
195
+ // Thinned under the old trees, where the floor's litter lies: knee-high grass over a flat leaf
196
+ // layer hides the very thing the layer is there to show.
197
+ getDensity: (x: number, z: number) => grassCover(x, z) * (1 - 0.78 * vale.floorZone(x, z)),
198
+ getHeight: valeHeight,
199
+ lodDistances: [7, 16],
200
+ material: grassMaterial,
201
+ minAltitude: STREAM.water + 0.05,
202
+ thinEnd: 30,
203
+ thinStart: 6,
204
+ });
205
+ vale.group.add(grass);
206
+ this.#grass = grass;
207
+ // What a scenario reads: how many chunks draw, and how high a blade stands beside Wren.
208
+ const standAt = (dx: number): number => {
209
+ const x = hero.mesh.position.x + dx;
210
+ const z = hero.mesh.position.z;
211
+ return grassStandAt(grass.pressAt(x, valeHeight(x, z), z));
212
+ };
213
+ ctx.entities.add("grass", {
214
+ debug: () => ({
215
+ blades: grass.stats.blades,
216
+ pending: grass.stats.pending,
217
+ standFar: standAt(3),
218
+ standNear: standAt(0.5),
219
+ visibleChunks: grass.stats.visibleChunks,
220
+ }),
221
+ });
222
+ ctx.entities.add("floor", {
223
+ debug: () => {
224
+ // No fields when the `low` tier left the floor out, so every total reads 0.
225
+ const fields = this.#floor?.fields ?? [];
226
+ return {
227
+ instances: fields.reduce((total, field) => total + field.stats.instances, 0),
228
+ tiles: fields.reduce((total, field) => total + field.stats.tiles, 0),
229
+ visibleTiles: fields.reduce((total, field) => total + field.stats.visibleTiles, 0),
230
+ };
231
+ },
232
+ });
160
233
  vale.dummies.forEach((at, i) => {
161
234
  this.#dummies.push(ctx.entities.add(`dummy.${i}`, new Dummy(`dummy.${i}`, at)));
162
235
  });
@@ -209,6 +282,26 @@ export class Play extends Scene<GameState, IPhysicsContext> {
209
282
  this.#sky === undefined
210
283
  )
211
284
  throw new Error("Play.enter ran before load() built the world.");
285
+ const floor = this.#floor;
286
+ if (floor !== undefined) {
287
+ floor.prewarm();
288
+ ctx.beforeRender(() => {
289
+ if (vale.group.visible) floor.update(hero.mesh.position);
290
+ });
291
+ }
292
+ const grass = this.#grass;
293
+ if (grass !== undefined) {
294
+ // Once per drawn frame: Wren's feet flatten the grass, then the field streams round the camera.
295
+ grass.prewarm();
296
+ ctx.beforeRender(() => {
297
+ if (!vale.group.visible) return;
298
+ const at = hero.mesh.position;
299
+ grass.pushers[0]?.set(at.x, at.y - FOOT_OFFSET, at.z, 1.2);
300
+ grass.update(ctx.camera);
301
+ });
302
+ // The first chunks draw unculled so their pipeline compiles behind the loading curtain.
303
+ ctx.startup.hold("grass", warmUnculled(ctx, grass));
304
+ }
212
305
  ctx.beforeRender(() => {
213
306
  updateSurfaceSampling(
214
307
  ctx.renderer.temporalUpscale?.() === true ? ctx.renderer.surface().resolutionScale : 1,
@@ -609,7 +702,7 @@ export class Play extends Scene<GameState, IPhysicsContext> {
609
702
  hero.mesh.position.z - f.x * 0.7 - f.z * 0.4 + Math.sin(orb.clock * 1.3) * 0.15,
610
703
  );
611
704
  if (companion.group.position.distanceTo(orbGoal) > 6) companion.group.position.copy(orbGoal);
612
- else companion.group.position.lerp(orbGoal, 1 - Math.exp(-dt * 4));
705
+ else companion.group.position.lerp(orbGoal, MathUtils.damp(0, 1, 4, dt));
613
706
  const orbGap = companion.group.position.distanceTo(head);
614
707
  orb.nearest = Math.min(orb.nearest, orbGap);
615
708
  orb.farthest = Math.max(orb.farthest, orbGap);
@@ -774,6 +867,8 @@ export class Play extends Scene<GameState, IPhysicsContext> {
774
867
  Object.assign(seen, { blocks: hero.shieldBlocks, clanks, hits: hero.slashHits });
775
868
  warden.update(dt, hero);
776
869
  for (const dummy of dummies) dummy.update(dt);
870
+ // Everything that moves has moved, so the lock's bounds and reticle are this frame's pose.
871
+ lock.place(camera, dt);
777
872
  // A target falls inside Wren's slash, so count the fallen after everything has moved.
778
873
  for (const fallen of targets) {
779
874
  if (fallen.alive || counted.has(fallen)) continue;