castle-web-cli 0.4.232 → 0.4.233

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 (355) hide show
  1. package/dist/agent-failures.d.ts +8 -0
  2. package/dist/agent-failures.js +19 -2
  3. package/dist/agent-prompts.d.ts +1 -1
  4. package/dist/agent-prompts.js +10 -3
  5. package/dist/agent.d.ts +64 -3
  6. package/dist/agent.js +170 -81
  7. package/dist/castle-host/host.d.ts +1 -0
  8. package/dist/castle-host/host.js +51 -3
  9. package/dist/castleJson.d.ts +4 -2
  10. package/dist/castleJson.js +2 -0
  11. package/dist/check.d.ts +3 -1
  12. package/dist/check.js +11 -1
  13. package/dist/devSessionStorage.js +47 -1
  14. package/dist/importPinMismatch.d.ts +22 -0
  15. package/dist/importPinMismatch.js +77 -0
  16. package/dist/importRegression.js +3 -15
  17. package/dist/imports.d.ts +10 -3
  18. package/dist/imports.js +88 -20
  19. package/dist/index.js +5 -4
  20. package/dist/init.js +1 -1
  21. package/dist/platformDoc.js +22 -0
  22. package/dist/routerFences.d.ts +5 -0
  23. package/dist/routerFences.js +12 -2
  24. package/dist/save-deck.d.ts +5 -0
  25. package/dist/save-deck.js +37 -4
  26. package/dist/serve.js +3 -0
  27. package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
  28. package/dist/shell/assets/index-MVLfNYd9.css +1 -0
  29. package/dist/shell/index.html +2 -2
  30. package/dist/taskSteer.d.ts +13 -0
  31. package/dist/taskSteer.js +22 -2
  32. package/kits/base/castle.json +1 -1
  33. package/kits/base/package-lock.json +1 -1
  34. package/kits/base/sdk/README.md +79 -2
  35. package/kits/base/sdk/avatar.d.ts +6 -2
  36. package/kits/base/sdk/avatar.js +12 -4
  37. package/kits/base/sdk/castle.d.ts +1 -1
  38. package/kits/base/sdk/commands.d.ts +14 -0
  39. package/kits/base/sdk/hub.d.ts +6 -2
  40. package/kits/base/sdk/hub.js +13 -0
  41. package/kits/base/sdk/multiplayer.js +17 -1
  42. package/kits/base/sdk/save.js +2 -1
  43. package/kits/base/sdk/server/hub.d.ts +87 -0
  44. package/kits/base/sdk/server/hub.js +70 -0
  45. package/kits/base/sdk/server/platformHandle.d.ts +31 -1
  46. package/kits/base/sdk/server/storage.d.ts +13 -0
  47. package/kits/base/sdk/server/storage.js +46 -0
  48. package/kits/base/sdk/server/wrapper.d.ts +36 -5
  49. package/kits/base/sdk/server/wrapper.js +83 -8
  50. package/kits/hub-game/CLAUDE.md +329 -11
  51. package/kits/hub-game/blueprints/avatar-10.scene +28 -0
  52. package/kits/hub-game/blueprints/avatar-11.scene +28 -0
  53. package/kits/hub-game/blueprints/avatar-12.scene +28 -0
  54. package/kits/hub-game/blueprints/avatar-13.scene +28 -0
  55. package/kits/hub-game/blueprints/avatar-14.scene +28 -0
  56. package/kits/hub-game/blueprints/avatar-15.scene +28 -0
  57. package/kits/hub-game/blueprints/avatar-4.scene +28 -0
  58. package/kits/hub-game/blueprints/avatar-5.scene +28 -0
  59. package/kits/hub-game/blueprints/avatar-6.scene +28 -0
  60. package/kits/hub-game/blueprints/avatar-7.scene +28 -0
  61. package/kits/hub-game/blueprints/avatar-8.scene +28 -0
  62. package/kits/hub-game/blueprints/avatar-9.scene +28 -0
  63. package/kits/hub-game/code/client/actorBudget.js +47 -0
  64. package/kits/hub-game/code/client/attention.js +11 -2
  65. package/kits/hub-game/code/client/avatar.js +309 -35
  66. package/kits/hub-game/code/client/avatarCap.js +228 -0
  67. package/kits/hub-game/code/client/avatarColors.js +70 -0
  68. package/kits/hub-game/code/client/avatarFaces.js +21 -0
  69. package/kits/hub-game/code/client/avatarShare.js +251 -0
  70. package/kits/hub-game/code/client/ballot.js +467 -0
  71. package/kits/hub-game/code/client/build.js +22 -0
  72. package/kits/hub-game/code/client/chrome.js +1144 -50
  73. package/kits/hub-game/code/client/companion.js +716 -0
  74. package/kits/hub-game/code/client/companionDress.js +99 -0
  75. package/kits/hub-game/code/client/decor.js +509 -0
  76. package/kits/hub-game/code/client/earned.js +131 -0
  77. package/kits/hub-game/code/client/emoteBubble.js +75 -0
  78. package/kits/hub-game/code/client/grab.js +339 -20
  79. package/kits/hub-game/code/client/hookLayer.js +299 -13
  80. package/kits/hub-game/code/client/idle.js +163 -22
  81. package/kits/hub-game/code/client/interestCap.js +81 -0
  82. package/kits/hub-game/code/client/keys.js +36 -0
  83. package/kits/hub-game/code/client/labelsNear.js +205 -0
  84. package/kits/hub-game/code/client/menuIcons.js +34 -0
  85. package/kits/hub-game/code/client/pack.js +6 -2
  86. package/kits/hub-game/code/client/packFormat.js +3 -3
  87. package/kits/hub-game/code/client/rehello.js +167 -0
  88. package/kits/hub-game/code/client/shot.js +92 -0
  89. package/kits/hub-game/code/client/sound.js +63 -8
  90. package/kits/hub-game/code/client/soundscape.js +1151 -0
  91. package/kits/hub-game/code/client/soundscapeActions.js +99 -0
  92. package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
  93. package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
  94. package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
  95. package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
  96. package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
  97. package/kits/hub-game/code/client/soundscapeCues.js +362 -0
  98. package/kits/hub-game/code/client/soundscapeMap.js +181 -0
  99. package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
  100. package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
  101. package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
  102. package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
  103. package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
  104. package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
  105. package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
  106. package/kits/hub-game/code/client/soundscapeUi.js +211 -0
  107. package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
  108. package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
  109. package/kits/hub-game/code/client/spin.js +101 -0
  110. package/kits/hub-game/code/client/state.js +109 -1
  111. package/kits/hub-game/code/client/stuck.js +259 -0
  112. package/kits/hub-game/code/client/talk.js +538 -47
  113. package/kits/hub-game/code/client/tiers.js +516 -27
  114. package/kits/hub-game/code/client/toastBand.js +37 -0
  115. package/kits/hub-game/code/client/together.js +32 -0
  116. package/kits/hub-game/code/client/visibility.js +43 -0
  117. package/kits/hub-game/code/client/wear.js +461 -170
  118. package/kits/hub-game/code/client/yours.js +199 -0
  119. package/kits/hub-game/code/companionSpec.js +45 -0
  120. package/kits/hub-game/code/privateText.js +7 -0
  121. package/kits/hub-game/code/server/actions.js +133 -0
  122. package/kits/hub-game/code/server/actors.js +9 -1
  123. package/kits/hub-game/code/server/ask.js +155 -0
  124. package/kits/hub-game/code/server/ballot.js +539 -0
  125. package/kits/hub-game/code/server/cells.js +100 -0
  126. package/kits/hub-game/code/server/companion.js +82 -0
  127. package/kits/hub-game/code/server/cues.js +70 -0
  128. package/kits/hub-game/code/server/decor.js +269 -0
  129. package/kits/hub-game/code/server/earned.js +461 -0
  130. package/kits/hub-game/code/server/friendBests.js +166 -0
  131. package/kits/hub-game/code/server/friendsAmong.js +232 -0
  132. package/kits/hub-game/code/server/history.js +5 -0
  133. package/kits/hub-game/code/server/hub.js +1254 -50
  134. package/kits/hub-game/code/server/idle.js +30 -11
  135. package/kits/hub-game/code/server/index.js +2 -2
  136. package/kits/hub-game/code/server/labels.js +28 -2
  137. package/kits/hub-game/code/server/manifest.js +378 -7
  138. package/kits/hub-game/code/server/menu.js +133 -0
  139. package/kits/hub-game/code/server/npcs.js +830 -80
  140. package/kits/hub-game/code/server/party.js +2 -2
  141. package/kits/hub-game/code/server/players.js +22 -0
  142. package/kits/hub-game/code/server/shot.js +110 -0
  143. package/kits/hub-game/code/server/standing.js +124 -0
  144. package/kits/hub-game/code/server/vis.js +113 -0
  145. package/kits/hub-game/code/server/wear.js +12 -0
  146. package/kits/hub-game/code/server/yours.js +59 -0
  147. package/kits/hub-game/code/shared/cues.js +9 -0
  148. package/kits/hub-game/code/shared/decor.js +41 -0
  149. package/kits/hub-game/code/shared/shot.js +19 -0
  150. package/kits/hub-game/code/shared/spin.js +57 -0
  151. package/kits/hub-game/code/systems/hub.js +845 -95
  152. package/kits/hub-game/docs/content-pack.md +1 -1
  153. package/kits/hub-game/docs/contract.md +2244 -61
  154. package/kits/hub-game/docs/home-pieces.md +64 -0
  155. package/kits/hub-game/models/avatar-10.pxmodel +28 -0
  156. package/kits/hub-game/models/avatar-11.pxmodel +28 -0
  157. package/kits/hub-game/models/avatar-12.pxmodel +27 -0
  158. package/kits/hub-game/models/avatar-13.pxmodel +24 -0
  159. package/kits/hub-game/models/avatar-14.pxmodel +29 -0
  160. package/kits/hub-game/models/avatar-15.pxmodel +24 -0
  161. package/kits/hub-game/models/avatar-4.pxmodel +29 -0
  162. package/kits/hub-game/models/avatar-5.pxmodel +27 -0
  163. package/kits/hub-game/models/avatar-6.pxmodel +26 -0
  164. package/kits/hub-game/models/avatar-7.pxmodel +25 -0
  165. package/kits/hub-game/models/avatar-8.pxmodel +24 -0
  166. package/kits/hub-game/models/avatar-9.pxmodel +30 -0
  167. package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
  168. package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
  169. package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
  170. package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
  171. package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
  172. package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
  173. package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
  174. package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
  175. package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
  176. package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
  177. package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
  178. package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
  179. package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
  180. package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
  181. package/kits/hub-game/models/hats/cap.pxmodel +162 -0
  182. package/kits/hub-game/models/hats/captain.pxmodel +178 -0
  183. package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
  184. package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
  185. package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
  186. package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
  187. package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
  188. package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
  189. package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
  190. package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
  191. package/kits/hub-game/models/hats/straw.pxmodel +139 -0
  192. package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
  193. package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
  194. package/kits/hub-game/models/hats/witch.pxmodel +147 -0
  195. package/kits/hub-game/package-lock.json +2 -0
  196. package/kits/hub-game/package.json +2 -1
  197. package/kits/hub-game/scripts/check.mjs +78 -11
  198. package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
  199. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
  200. package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
  201. package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
  202. package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
  203. package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
  204. package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
  205. package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
  206. package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
  207. package/kits/hub-game/scripts/gen-earned.mjs +285 -0
  208. package/kits/hub-game/scripts/gen-hats.mjs +827 -0
  209. package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
  210. package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
  211. package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
  212. package/kits/hub-game/scripts/test-actions.mjs +298 -0
  213. package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
  214. package/kits/hub-game/scripts/test-actors.mjs +19 -17
  215. package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
  216. package/kits/hub-game/scripts/test-ask.mjs +269 -0
  217. package/kits/hub-game/scripts/test-attention.mjs +10 -1
  218. package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
  219. package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
  220. package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
  221. package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
  222. package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
  223. package/kits/hub-game/scripts/test-avatar.mjs +540 -7
  224. package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
  225. package/kits/hub-game/scripts/test-build.mjs +31 -0
  226. package/kits/hub-game/scripts/test-cells.mjs +71 -0
  227. package/kits/hub-game/scripts/test-chat.mjs +662 -0
  228. package/kits/hub-game/scripts/test-classic.mjs +2 -0
  229. package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
  230. package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
  231. package/kits/hub-game/scripts/test-companion.mjs +259 -0
  232. package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
  233. package/kits/hub-game/scripts/test-decor.mjs +457 -0
  234. package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
  235. package/kits/hub-game/scripts/test-earned.mjs +1194 -0
  236. package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
  237. package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
  238. package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
  239. package/kits/hub-game/scripts/test-grab.mjs +7 -0
  240. package/kits/hub-game/scripts/test-hats.mjs +422 -168
  241. package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
  242. package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
  243. package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
  244. package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
  245. package/kits/hub-game/scripts/test-idle.mjs +361 -1
  246. package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
  247. package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
  248. package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
  249. package/kits/hub-game/scripts/test-keys.mjs +46 -1
  250. package/kits/hub-game/scripts/test-labels.mjs +596 -0
  251. package/kits/hub-game/scripts/test-manifest.mjs +207 -0
  252. package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
  253. package/kits/hub-game/scripts/test-menu.mjs +296 -0
  254. package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
  255. package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
  256. package/kits/hub-game/scripts/test-pack.mjs +7 -0
  257. package/kits/hub-game/scripts/test-picker.mjs +314 -0
  258. package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
  259. package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
  260. package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
  261. package/kits/hub-game/scripts/test-shot.mjs +756 -0
  262. package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
  263. package/kits/hub-game/scripts/test-spin.mjs +314 -0
  264. package/kits/hub-game/scripts/test-standing.mjs +416 -0
  265. package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
  266. package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
  267. package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
  268. package/kits/hub-game/scripts/test-tiers.mjs +477 -2
  269. package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
  270. package/kits/hub-game/scripts/test-try-on.mjs +22 -22
  271. package/kits/hub-game/scripts/test-vis.mjs +343 -0
  272. package/kits/hub-game/scripts/test-visibility.mjs +134 -0
  273. package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
  274. package/kits/hub-game/scripts/test-yours.mjs +372 -0
  275. package/kits/multiplayer-3d/CLAUDE.md +50 -0
  276. package/kits/multiplayer-3d/castle.json +5 -5
  277. package/kits/multiplayer-3d/code/client/avatars.js +7 -0
  278. package/kits/multiplayer-3d/code/client/gait.js +65 -0
  279. package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
  280. package/kits/multiplayer-3d/code/options.js +5 -0
  281. package/kits/multiplayer-3d/code/server/ownership.js +10 -2
  282. package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
  283. package/kits/multiplayer-3d/code/server/world.js +7 -0
  284. package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
  285. package/kits/multiplayer-3d/package.json +2 -1
  286. package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
  287. package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
  288. package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
  289. package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
  290. package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
  291. package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
  292. package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
  293. package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
  294. package/kits/physics-2d/CLAUDE.md +9 -0
  295. package/kits/physics-2d/castle.json +2 -2
  296. package/kits/physics-2d/engine/scene.js +253 -1
  297. package/kits/physics-2d/engine/skyKey.js +129 -0
  298. package/kits/physics-2d/engine/stillClock.js +106 -0
  299. package/kits/physics-2d/engine/updateBudget.js +21 -0
  300. package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
  301. package/kits/physics-3d/CLAUDE.md +1169 -30
  302. package/kits/physics-3d/behaviors/Player.jsx +629 -72
  303. package/kits/physics-3d/castle.json +3 -3
  304. package/kits/physics-3d/docs/pxmodel-format.md +8 -0
  305. package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
  306. package/kits/physics-3d/engine3d/actornode.js +86 -0
  307. package/kits/physics-3d/engine3d/animationBudget.js +23 -0
  308. package/kits/physics-3d/engine3d/editorWorld.js +6 -0
  309. package/kits/physics-3d/engine3d/emptynodes.js +232 -0
  310. package/kits/physics-3d/engine3d/framecap.js +96 -0
  311. package/kits/physics-3d/engine3d/gait.js +118 -0
  312. package/kits/physics-3d/engine3d/kithooks.js +47 -0
  313. package/kits/physics-3d/engine3d/look.js +507 -48
  314. package/kits/physics-3d/engine3d/lookbake.js +208 -0
  315. package/kits/physics-3d/engine3d/materialpresets.js +2 -0
  316. package/kits/physics-3d/engine3d/motion.js +39 -10
  317. package/kits/physics-3d/engine3d/nearshadows.js +37 -19
  318. package/kits/physics-3d/engine3d/optimize.js +9 -5
  319. package/kits/physics-3d/engine3d/orbitinput.js +487 -9
  320. package/kits/physics-3d/engine3d/orbitlens.js +48 -0
  321. package/kits/physics-3d/engine3d/ownmodel.js +213 -0
  322. package/kits/physics-3d/engine3d/pxmodel.js +42 -11
  323. package/kits/physics-3d/engine3d/shadowfade.js +882 -0
  324. package/kits/physics-3d/engine3d/sky.js +547 -0
  325. package/kits/physics-3d/engine3d/skylife.js +306 -0
  326. package/kits/physics-3d/engine3d/unchanged.js +11 -0
  327. package/kits/physics-3d/engine3d/viewrange.js +52 -0
  328. package/kits/physics-3d/engine3d/world3d.js +796 -69
  329. package/kits/physics-3d/main.jsx +5 -0
  330. package/kits/physics-3d/package.json +1 -1
  331. package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
  332. package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
  333. package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
  334. package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
  335. package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
  336. package/kits/physics-3d/scripts/test-gait.mjs +387 -0
  337. package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
  338. package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
  339. package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
  340. package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
  341. package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
  342. package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
  343. package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
  344. package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
  345. package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
  346. package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
  347. package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
  348. package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
  349. package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
  350. package/kits/physics-3d/systems/physics3d.js +383 -6
  351. package/kits/real-time/castle.json +2 -2
  352. package/kits/real-time/code/server/gameHooks.js +7 -0
  353. package/kits/real-time/code/server/session.js +97 -19
  354. package/package.json +2 -2
  355. package/dist/shell/assets/index-Cf61cNfT.css +0 -1
@@ -149,6 +149,52 @@ function settle(value, from, to, dt) {
149
149
  return to - lag + (value - from + lag) * Math.exp(-FOLLOW_RATE * dt);
150
150
  }
151
151
 
152
+ // The follow camera of a scene that capped its frame rate (`"engine": {
153
+ // "maxFps": n }`, `scene.maxFps` above 0) and set no camera key: the camera
154
+ // `updateCamera` places, the same target and rate, placed differently.
155
+ // updateCamera eases once a frame by 1 - e^(-12 dt), from the update, toward
156
+ // where the player was drawn LAST frame: behind a target moving at v it trails
157
+ // by about v/12 + v dt/2, and the player is then drawn v dt further on. Both
158
+ // change with each frame's dt, and the cap hands frames of 25 to 50 ms on a
159
+ // slow phone, so the player would slide back and forth on screen as it walks.
160
+ // So under the cap the camera is placed as the rigid one is: at the end of
161
+ // the frame, by the physics system (`placeFollowCamera`), on the position the
162
+ // frame is drawn with, and each coordinate is eased as if the target moved
163
+ // steadily from last frame's place to this frame's (`settle`: the exact
164
+ // solution of x' = 12 (target - x)). A steady walk is then trailed by v/12
165
+ // whatever the frames; a target standing still is reached as the lerp
166
+ // reaches it. Last frame's target is on the actor's runtime (`camTarget`).
167
+ // Without the cap updateCamera runs as it always did.
168
+ function placeCapped(scene, id, dt) {
169
+ const actor = scene.getActor(id);
170
+ const t = actor?.components.Transform;
171
+ const props = actor?.components.Player;
172
+ const cam = scene.three?.camera;
173
+ if (!cam || !t || !props || props.$enabled === false) return;
174
+ const per = persistentOf(scene);
175
+ const rt = actor.runtime;
176
+ const target = {
177
+ x: t.x - props.camDistance * Math.sin(per.camAngle),
178
+ y: t.y + props.camHeight,
179
+ z: t.z + props.camDistance * Math.cos(per.camAngle),
180
+ };
181
+ const last = per.camLastAt;
182
+ const jumped = last && Math.hypot(t.x - last.x, t.z - last.z) > TELEPORT_PER_FRAME;
183
+ per.camLastAt = { x: t.x, z: t.z };
184
+ const from = rt.camTarget ?? target;
185
+ rt.camTarget = target;
186
+ if (jumped || Math.hypot(target.x - cam.position.x, target.z - cam.position.z) > 20) {
187
+ cam.position.set(target.x, target.y, target.z);
188
+ } else {
189
+ cam.position.set(
190
+ settle(cam.position.x, from.x, target.x, dt),
191
+ settle(cam.position.y, from.y, target.y, dt),
192
+ settle(cam.position.z, from.z, target.z, dt)
193
+ );
194
+ }
195
+ cam.lookAt(t.x, t.y + 0.5, t.z);
196
+ }
197
+
152
198
  // The follow camera of a scene that set `"engine": { "camera": { "follow":
153
199
  // "rigid" } }` (the kit's CLAUDE.md has the terms). It moves with the player
154
200
  // as one piece: the offset from the player (its angle and height) and the
@@ -222,26 +268,92 @@ function placeFollowing(scene, id, dt) {
222
268
  // (`scene.cameraOrbit`), which a scene load does not replace, and never on
223
269
  // `scene.persistent`.
224
270
 
225
- // The camera looks at the player this far above its Transform.
226
- const LOOK_HEIGHT = 0.8;
227
- // The nearest and farthest the player can zoom, metres from that point. A
228
- // Player whose camDistance/camHeight start it outside these is given room to
229
- // where it starts.
230
- const ORBIT_NEAREST = 3;
231
- const ORBIT_FARTHEST = 12;
232
- // The lowest and highest the camera tilts, above the horizontal.
233
- const ORBIT_PITCH_LEAST = 5 * DEG;
234
- const ORBIT_PITCH_MOST = 70 * DEG;
271
+ // The numbers below are Roblox's default (Classic) third-person camera at
272
+ // our scale. A Roblox character is 5 studs tall; ours, the kit's
273
+ // player.pxmodel standing on its 1.4 m capsule (the hub's avatar), is 1.46 m
274
+ // from the soles of its feet (0.02 m above the model's origin) to the top of
275
+ // its cap (1.48 m), so one stud is 1.46 / 5 = 0.292 m here.
276
+ const STUD = 1.46 / 5;
277
+ // The camera looks at the player this far above its Transform. Roblox looks
278
+ // at the root part plus 1.5 studs; the root part is the torso's middle, and
279
+ // so is our Transform (the capsule's middle, 0.70 m above the model's origin,
280
+ // where the torso's middle is 0.69), so the same 1.5 studs: 0.438 m, the neck.
281
+ const LOOK_HEIGHT = 1.5 * STUD;
282
+ // How far from that point the camera starts: Roblox's 12.5 studs, 3.65 m,
283
+ // the same two and a half character heights.
284
+ const ORBIT_START = 12.5 * STUD;
285
+ // The nearest and farthest the player can zoom, metres from that point.
286
+ // Roblox lets the player in to 0.5 studs, which is first person; here the
287
+ // nearest keeps the camera clear of the character, which an avatar hides
288
+ // itself from within about 1 m. The farthest is Roblox's 128 studs, 37.4 m.
289
+ const ORBIT_NEAREST = 1.5;
290
+ const ORBIT_FARTHEST = 128 * STUD;
291
+ // The lowest and highest the camera tilts, above the horizontal: Roblox's 80
292
+ // degrees either way. Below the horizontal the camera is lower than the point
293
+ // it looks at, looking up, and the ground (a fixed solid, as walls are) holds
294
+ // it above itself as a wall holds it in front (`limitReach`, `sweep`).
295
+ const ORBIT_PITCH_LEAST = -80 * DEG;
296
+ const ORBIT_PITCH_MOST = 80 * DEG;
297
+ // The tilt the camera starts at, whatever the Player's camDistance and
298
+ // camHeight: 15 degrees down, behind the player, as Roblox starts. With the
299
+ // 70 degree lens (engine3d/orbitlens.js `fitOrbitLens`) the top of the frame
300
+ // is 20 degrees above the horizon: a world's sky shows.
301
+ const ORBIT_PITCH_START = 15 * DEG;
235
302
  // How fast the camera's angle, tilt and distance catch up with what was
236
303
  // asked: quick enough to feel direct, slow enough to take the steps out of a
237
304
  // finger's drag.
238
305
  const ORBIT_RATE = 20;
239
306
  // How fast the character turns to face the way it walks.
240
307
  const FACE_RATE = 12;
241
- // The camera stays this far in front of what is between it and the player,
242
- // and no nearer the point it looks at than CAMERA_NEAREST.
308
+ // The camera stays at least this far off every fixed surface: it is a ball
309
+ // of this radius swept out from the point it looks at (`sweep`), so it is
310
+ // this far off whatever stops it, square to the surface, however the line
311
+ // meets it (a wall met at a grazing angle, a box's edge or corner, the
312
+ // ground seen along at a low angle). A wider lens than the default's needs
313
+ // more: the lens's near plane must stay clear of the surface whichever way
314
+ // the camera looks, so the margin is the distance from the camera to the
315
+ // near plane's corners plus LENS_CLEARANCE when that is more
316
+ // (`lensMargin`). At the default 70 degrees on a 20:9 screen the corners
317
+ // are 0.198 m off and the margin is 0.25 m; at 120 degrees on 20:9, 0.484 m.
243
318
  const CAMERA_MARGIN = 0.25;
319
+ const LENS_CLEARANCE = 0.05;
320
+ // A look point nearer fixed surfaces than the margin and START_SKIN (a
321
+ // player pressed against a wall, or in a corner, with a wide lens) has the
322
+ // ball start moved the least way that puts it that far off all of them
323
+ // together (`findStart`), and looked around again, START_TRIES times at
324
+ // most; a point within START_SETTLED of that distance is taken. A gap too
325
+ // narrow for that leaves the ball smaller, down to START_LEAST.
326
+ const START_SKIN = 0.05;
327
+ const START_TRIES = 8;
328
+ const START_SETTLED = 1e-4;
329
+ const START_LEAST = 0.02;
330
+ // Where no start is found at all (the look point inside a solid) the camera
331
+ // is held by a ray alone, as it was before the ball (`onRay`): a margin
332
+ // short of the hit, no nearer the look point than CAMERA_NEAREST, but never
333
+ // past a real surface: then SURFACE_GAP short of it.
244
334
  const CAMERA_NEAREST = 0.6;
335
+ const SURFACE_GAP = 0.01;
336
+ // The lens the orbit camera is drawn with (world3d.js `orbitFov`, which sets
337
+ // it on the camera at the draw that follows this placement): the scene's
338
+ // `engine.camera.fov`, 10 to 120 degrees, else 70.
339
+ const ORBIT_FOV = 70;
340
+ function orbitFov(scene) {
341
+ const fov = scene.data?.engine?.camera?.fov;
342
+ return typeof fov === 'number' && fov >= 10 && fov <= 120 ? fov : ORBIT_FOV;
343
+ }
344
+ // The margin for this frame's lens: CAMERA_MARGIN, or the near plane's
345
+ // corners' distance from the camera, near * sqrt(1 + tan^2(v/2) +
346
+ // (aspect tan(v/2))^2), plus LENS_CLEARANCE, whichever is more. A point of
347
+ // the near plane is no farther from the camera than its corners, so a camera
348
+ // that far off a surface, square to it, has the whole near plane in front of
349
+ // it.
350
+ function lensMargin(scene, cam) {
351
+ const near = Number.isFinite(cam.near) && cam.near > 0 ? cam.near : 0.1;
352
+ const aspect = Number.isFinite(cam.aspect) && cam.aspect > 0 ? cam.aspect : 1;
353
+ const half = Math.tan((orbitFov(scene) * DEG) / 2);
354
+ const corner = near * Math.sqrt(1 + half * half + aspect * half * (aspect * half));
355
+ return Math.max(CAMERA_MARGIN, corner + LENS_CLEARANCE);
356
+ }
245
357
  // How fast the camera moves back out once nothing is in the way.
246
358
  const CAMERA_OUT_RATE = 6;
247
359
  // Within this of the distance it wants, a camera let back out is let go.
@@ -249,11 +361,16 @@ const CAMERA_OUT_DONE = 1e-4;
249
361
  // A camera something else placed is eased on from where it was left at this
250
362
  // rate: a twentieth of the way is left after 0.3 s.
251
363
  const TAKEOVER_RATE = 10;
364
+ // A settled shot uses its exact authored pose, avoiding round-trip drift.
365
+ const SHOT_SETTLED = 1e-10;
366
+ // Stay off the poles, where lookAt cannot retain the shot's azimuth.
367
+ const SHOT_PITCH_LIMIT = 89 * DEG;
368
+ const SHOT_YAW_EPS = 1e-8;
252
369
  // The camera was placed on the frame before this one when the scene time it
253
370
  // was last placed at is this frame's length ago, to within this (seconds).
254
371
  const PLACED_WITHIN = 1e-6;
255
372
  // A takeover blend farther than this from the camera's place has its drawn
256
- // point tested for collision too (a second ray, only while it lasts).
373
+ // point tested for collision too (a second sweep, only while it lasts).
257
374
  const BLEND_TESTED = 1e-4;
258
375
 
259
376
  const clamp = (value, least, most) => Math.max(least, Math.min(most, value));
@@ -279,13 +396,15 @@ function persistentOf(scene) {
279
396
  // This frame's walk: a direction on the ground no longer than 1, or null
280
397
  // standing still. W/S and up/down walk away from and toward the camera, A/D
281
398
  // strafe, the stick does both by how far it is pushed; left/right swing the
282
- // camera at `turnSpeed`. The character's facing eases toward the walk and
283
- // stays put standing still.
399
+ // camera at `turnSpeed`. Under a held shot the camera cannot swing, so
400
+ // left/right strafe like A/D instead. The character's facing eases toward
401
+ // the walk and stays put standing still.
284
402
  function driveOrbiting(scene, per, rt, props, dt) {
285
403
  const keys = scene.keys;
286
- per.camAngle += held(keys, ['ArrowRight'], ['ArrowLeft']) * props.turnSpeed * dt;
404
+ const shot = validOrbitShot(scene.orbitShot);
405
+ if (!shot) per.camAngle += held(keys, ['ArrowRight'], ['ArrowLeft']) * props.turnSpeed * dt;
287
406
  let ahead = held(keys, ['KeyW', 'ArrowUp'], ['KeyS', 'ArrowDown']);
288
- let aside = held(keys, ['KeyD'], ['KeyA']);
407
+ let aside = shot ? held(keys, ['KeyD', 'ArrowRight'], ['KeyA', 'ArrowLeft']) : held(keys, ['KeyD'], ['KeyA']);
289
408
  const stick = scene.moveInput;
290
409
  if (ahead === 0 && aside === 0 && stick?.active && Math.hypot(stick.x, stick.y) >= 0.15) {
291
410
  ahead = -stick.y;
@@ -356,23 +475,29 @@ function updateOrbiting(actor, scene, props, dt) {
356
475
 
357
476
  const finiteOr = (value, otherwise) => (Number.isFinite(value) ? value : otherwise);
358
477
 
359
- // The tilt and distance the player has chosen, on the runtime. They start
360
- // where the Player's camDistance and camHeight put the fixed camera, and
361
- // start there again for a Player with other numbers.
478
+ // The tilt and distance the player has chosen, on the runtime: they start
479
+ // at the scene's starting pitch and distance (or the defaults), and start
480
+ // again when those keys or camDistance/camHeight change. The latter two
481
+ // ask for a fresh camera but do not set its orbit distance or pitch.
362
482
  function orbitChoice(scene, props) {
363
483
  const distance = finiteOr(props.camDistance, 9);
364
484
  const height = finiteOr(props.camHeight, 7);
485
+ // Only a finite number is a start; anything else is the default, so a
486
+ // copy of the same scene data (a fresh {} included) never restarts it.
487
+ const startDistance = finiteOr(scene.data?.engine?.camera?.distance, undefined);
488
+ const startPitch = finiteOr(scene.data?.engine?.camera?.pitch, undefined);
365
489
  const chosen = scene.cameraOrbit;
366
- if (chosen && chosen.distance === distance && chosen.height === height) return chosen;
367
- const rise = height - LOOK_HEIGHT;
368
- const range = Math.max(CAMERA_NEAREST, Math.hypot(distance, rise));
490
+ if (chosen && chosen.distance === distance && chosen.height === height
491
+ && Object.is(chosen.startDistance, startDistance) && Object.is(chosen.startPitch, startPitch)) return chosen;
369
492
  scene.cameraOrbit = {
370
493
  distance,
371
494
  height,
372
- range,
373
- pitch: clamp(Math.atan2(rise, distance), ORBIT_PITCH_LEAST, ORBIT_PITCH_MOST),
374
- nearest: Math.min(ORBIT_NEAREST, range),
375
- farthest: Math.max(ORBIT_FARTHEST, range),
495
+ startDistance,
496
+ startPitch,
497
+ range: clamp(finiteOr(startDistance, ORBIT_START), ORBIT_NEAREST, ORBIT_FARTHEST),
498
+ pitch: Number.isFinite(startPitch) ? clamp(startPitch * DEG, ORBIT_PITCH_LEAST, ORBIT_PITCH_MOST) : ORBIT_PITCH_START,
499
+ nearest: ORBIT_NEAREST,
500
+ farthest: ORBIT_FARTHEST,
376
501
  };
377
502
  return scene.cameraOrbit;
378
503
  }
@@ -388,24 +513,245 @@ function steerOrbit(per, chosen, look) {
388
513
  // placed from) toward where it wants to be: a unit direction.
389
514
  const ray = { from: { x: 0, y: 0, z: 0 }, dir: { x: 0, y: 0, z: 0 } };
390
515
 
391
- // The farthest the camera may be along `ray` (`state.limit`, +Infinity when
392
- // nothing holds it): CAMERA_MARGIN in front of the nearest fixed solid within
393
- // its distance (and the margin past it), never nearer than CAMERA_NEAREST. A nearer limit is taken at
394
- // once; a farther one, or none, is eased out to at CAMERA_OUT_RATE, and once
395
- // the camera is back at its distance it is let go. Not asked while physics
396
- // has no world.
397
- function limitReach(phys, state, dt) {
398
- if (!phys?.castRayFixed || !phys.ready()) return;
399
- const hit = phys.castRayFixed(ray.from, ray.dir, state.range + CAMERA_MARGIN);
400
- const wall = hit ? Math.max(CAMERA_NEAREST, hit.distance - CAMERA_MARGIN) : Infinity;
401
- if (wall <= state.limit) {
402
- state.limit = wall;
516
+ // Whether this frame's camera collides: a physics world, and an api with the
517
+ // lens's queries (systems/physics3d.js `castBallFixed`, `nearFixed`,
518
+ // `castRayFixedNormal`).
519
+ const collides = (phys) => Boolean(phys?.castBallFixed && phys.nearFixed && phys.castRayFixedNormal && phys.ready());
520
+
521
+ // Where the camera's ball is swept from this frame (`findStart`), and its
522
+ // radius: the look point (`ray.from`) and the margin, or, near surfaces, a
523
+ // point moved off them (and, in a gap narrower than twice the margin, a
524
+ // smaller ball). `clear` is false when no start was found; then it is the
525
+ // look point and the camera is held by a ray alone (`sweep`).
526
+ const start = { x: 0, y: 0, z: 0, radius: 0, clear: true };
527
+
528
+ // The ball must start clear of everything (rapier does not answer a ball
529
+ // that starts touching a solid reliably). Every fixed surface within the
530
+ // radius and START_SKIN of the start (`nearFixed`) gives a plane touching
531
+ // its solid at its nearest point, with all of a convex solid behind it; the
532
+ // start is the look point moved the least way that puts it that far in
533
+ // front of every plane found so far, all together (`leastMove`), so in a
534
+ // corner the moves do not undo each other; then it is looked around again,
535
+ // until nothing is that near. Each plane keeps the ball off its solid, so
536
+ // planes found from earlier places still hold. The move grows from nothing
537
+ // as the look point comes nearer, so the camera does not jump. Where no
538
+ // place is that far off every plane (a gap narrower than twice the radius)
539
+ // the place that falls least short is taken with the ball made that much
540
+ // smaller, no smaller than START_LEAST. Then the camera point stays out of
541
+ // the walls but the lens does not: its near plane cuts into them (accepted,
542
+ // as Roblox's camera clips there; the near plane is not shrunk). One query
543
+ // in the open; two by a wall or in a corner.
544
+ function findStart(phys, margin) {
545
+ start.x = ray.from.x;
546
+ start.y = ray.from.y;
547
+ start.z = ray.from.z;
548
+ start.radius = margin;
549
+ start.clear = true;
550
+ if (!collides(phys)) return;
551
+ planes.length = 0;
552
+ let radius = margin;
553
+ for (let i = 0; i < START_TRIES; i += 1) {
554
+ const near = phys.nearFixed(start, radius + START_SKIN);
555
+ let closest = Infinity;
556
+ for (const n of near) {
557
+ if (n.inside || !n.normal || !(n.distance >= 0)) return giveUpStart();
558
+ closest = Math.min(closest, n.distance);
559
+ }
560
+ if (closest >= radius + START_SKIN - START_SETTLED) {
561
+ start.radius = radius;
562
+ return;
563
+ }
564
+ for (const n of near) if (n.distance < radius + START_SKIN - START_SETTLED) addPlane(n);
565
+ const move = leastMove(radius + START_SKIN);
566
+ if (move.short > 0) radius -= move.short;
567
+ if (!(radius >= START_LEAST)) return giveUpStart();
568
+ start.x = ray.from.x + move.x;
569
+ start.y = ray.from.y + move.y;
570
+ start.z = ray.from.z + move.z;
571
+ }
572
+ return giveUpStart();
573
+ }
574
+ function giveUpStart() {
575
+ start.x = ray.from.x;
576
+ start.y = ray.from.y;
577
+ start.z = ray.from.z;
578
+ start.clear = false;
579
+ }
580
+
581
+ // The planes `findStart` has found this frame: a unit normal facing the
582
+ // look point's side and the offset along it (n . p = d on the plane).
583
+ const planes = [];
584
+ const MOST_PLANES = 12;
585
+ function addPlane(near) {
586
+ const n = near.normal;
587
+ const d = n.x * near.point.x + n.y * near.point.y + n.z * near.point.z;
588
+ if (!Number.isFinite(d) || planes.length >= MOST_PLANES) return;
589
+ for (const p of planes) if (p.x * n.x + p.y * n.y + p.z * n.z > 1 - 1e-9 && Math.abs(p.d - d) < 1e-6) return;
590
+ planes.push({ x: n.x, y: n.y, z: n.z, d });
591
+ }
592
+
593
+ // The least move from the look point that leaves it `gap` or more in front
594
+ // of every plane: the nearest point of the intersection of their
595
+ // half-spaces, which lies on at most three of the planes, so it is the
596
+ // nearest of the moves onto each set of up to three that clears them all.
597
+ // When none does, the one that falls least short (`short`, how much).
598
+ const best = { x: 0, y: 0, z: 0, short: 0 };
599
+ const trial = { x: 0, y: 0, z: 0 };
600
+ const want = [];
601
+ function leastMove(gap) {
602
+ const at = ray.from;
603
+ want.length = 0;
604
+ for (const p of planes) want.push(gap - (p.x * at.x + p.y * at.y + p.z * at.z - p.d));
605
+ let bestShort = Infinity;
606
+ let bestLength = Infinity;
607
+ const consider = () => {
608
+ let short = 0;
609
+ for (let i = 0; i < planes.length; i += 1) {
610
+ const p = planes[i];
611
+ short = Math.max(short, want[i] - (p.x * trial.x + p.y * trial.y + p.z * trial.z));
612
+ }
613
+ const length = Math.hypot(trial.x, trial.y, trial.z);
614
+ const fits = short <= 1e-9;
615
+ const bestFits = bestShort <= 1e-9;
616
+ if ((fits && (!bestFits || length < bestLength)) || (!fits && !bestFits && (short < bestShort - 1e-12 || (short <= bestShort + 1e-12 && length < bestLength)))) {
617
+ bestShort = short;
618
+ bestLength = length;
619
+ best.x = trial.x;
620
+ best.y = trial.y;
621
+ best.z = trial.z;
622
+ }
623
+ };
624
+ trial.x = 0;
625
+ trial.y = 0;
626
+ trial.z = 0;
627
+ consider();
628
+ const n = planes.length;
629
+ for (let i = 0; i < n; i += 1) {
630
+ const a = planes[i];
631
+ trial.x = a.x * want[i];
632
+ trial.y = a.y * want[i];
633
+ trial.z = a.z * want[i];
634
+ consider();
635
+ for (let j = i + 1; j < n; j += 1) {
636
+ const b = planes[j];
637
+ const c = a.x * b.x + a.y * b.y + a.z * b.z;
638
+ const det = 1 - c * c;
639
+ if (det > 1e-9) {
640
+ const s = (want[i] - c * want[j]) / det;
641
+ const t = (want[j] - c * want[i]) / det;
642
+ trial.x = a.x * s + b.x * t;
643
+ trial.y = a.y * s + b.y * t;
644
+ trial.z = a.z * s + b.z * t;
645
+ consider();
646
+ }
647
+ for (let k = j + 1; k < n; k += 1) {
648
+ const e = planes[k];
649
+ // Cramer's rule on the rows a, b, e.
650
+ const bxeX = b.y * e.z - b.z * e.y;
651
+ const bxeY = b.z * e.x - b.x * e.z;
652
+ const bxeZ = b.x * e.y - b.y * e.x;
653
+ const exaX = e.y * a.z - e.z * a.y;
654
+ const exaY = e.z * a.x - e.x * a.z;
655
+ const exaZ = e.x * a.y - e.y * a.x;
656
+ const axbX = a.y * b.z - a.z * b.y;
657
+ const axbY = a.z * b.x - a.x * b.z;
658
+ const axbZ = a.x * b.y - a.y * b.x;
659
+ const det3 = a.x * bxeX + a.y * bxeY + a.z * bxeZ;
660
+ if (Math.abs(det3) <= 1e-9) continue;
661
+ trial.x = (want[i] * bxeX + want[j] * exaX + want[k] * axbX) / det3;
662
+ trial.y = (want[i] * bxeY + want[j] * exaY + want[k] * axbY) / det3;
663
+ trial.z = (want[i] * bxeZ + want[j] * exaZ + want[k] * axbZ) / det3;
664
+ consider();
665
+ }
666
+ }
667
+ }
668
+ best.short = bestShort <= 1e-9 ? 0 : bestShort;
669
+ return best;
670
+ }
671
+
672
+ // The farthest the camera may be along a ray that met `hit`, when it is held
673
+ // by a ray alone: the margin short of it, never nearer than CAMERA_NEAREST,
674
+ // except that a hit with a normal (a real surface: systems/physics3d.js
675
+ // `castRayFixedNormal`) is never passed: then no farther than SURFACE_GAP
676
+ // short of it.
677
+ function onRay(hit, margin) {
678
+ const most = Math.max(CAMERA_NEAREST, hit.distance - margin);
679
+ return hit.normal ? Math.min(most, Math.max(0, hit.distance - SURFACE_GAP)) : most;
680
+ }
681
+
682
+ // How far from `start` along the unit `dir` the camera may be, looking no
683
+ // farther than `length`: where a ball of `start.radius` (the margin, but in
684
+ // a gap too narrow for it) swept that way first touches a fixed solid (its
685
+ // time of impact), or +Infinity when it touches nothing. The camera there
686
+ // is that far off what stopped it and off everything it passed, so the
687
+ // whole near plane is in front of every surface, at any angle. Without a
688
+ // start, `onRay` of a ray from the look point. One query.
689
+ function sweep(phys, dir, length, margin) {
690
+ if (start.clear) {
691
+ const hit = phys.castBallFixed(start, dir, length, start.radius);
692
+ return hit ? Math.max(0, hit.distance) : Infinity;
693
+ }
694
+ const hit = phys.castRayFixedNormal(start, dir, length + margin);
695
+ return hit ? onRay(hit, margin) : Infinity;
696
+ }
697
+
698
+ // The farthest the camera may be along `ray` from `start` (`state.limit`,
699
+ // +Infinity when nothing holds it), Roblox's Popper: the sweep toward where
700
+ // the camera wants to be (its distance), each frame. A nearer limit is taken
701
+ // at once; a farther one, or none, is eased out to at CAMERA_OUT_RATE, never
702
+ // past what this frame's sweep touched, and once the camera is back at its
703
+ // distance it is let go. The ease is measured from the look point, from how
704
+ // far from it the camera was drawn last frame (`state.out`), not along this
705
+ // frame's ray: the start moves as the player nears or leaves a wall, so a
706
+ // limit along the ray from last frame's start is not where the camera was
707
+ // (review 7: a wall 0.5 m off removed let the camera out 1.161 m in a frame
708
+ // where easing allows 1.139). And it eases whatever drew the camera short of
709
+ // its distance, a start moved off a wall too, not only a sweep that held it
710
+ // (review 8: a box beside the look point removed let it out 0.062 m where
711
+ // 0.006 m is allowed); only a zoom moves it at its own pace. The camera is drawn at the nearer of its
712
+ // distance and the limit, so an easing camera never passes what the sweep
713
+ // touches. Not asked while physics has no world.
714
+ // Queries a frame: one `nearFixed` in the open, two by a wall or in a corner
715
+ // (START_TRIES at most), and one sweep, one more while a takeover blend
716
+ // lasts (`holdBlend`). A sweep is three rapier queries as a rule and 25 at
717
+ // most (systems/physics3d.js `castBallFixed`). As a rule 4 in the open and 5
718
+ // by a wall; at most 8 + 2 * 25 = 58 (a blend, a slanted corner, and rapier
719
+ // missing solids in both sweeps). None without a world.
720
+ function limitReach(phys, state, margin, dt) {
721
+ findStart(phys, margin);
722
+ if (!collides(phys)) return;
723
+ const was = state.out;
724
+ // A camera just placed: where the sweep allows, at once.
725
+ if (!Number.isFinite(was) || !Number.isFinite(state.outRange)) {
726
+ state.limit = sweep(phys, ray.dir, state.range, margin);
403
727
  return;
404
728
  }
405
- // Out from where the camera is, not from a limit past its distance.
406
- const from = Math.min(state.limit, state.range);
407
- state.limit = from + (Math.min(wall, state.range) - from) * eased(CAMERA_OUT_RATE, dt);
408
- if (wall === Infinity && state.limit >= state.range - CAMERA_OUT_DONE) state.limit = Infinity;
729
+ // How far short of its distance it was drawn last frame (held by a wall,
730
+ // or its start moved off one), eased away at CAMERA_OUT_RATE; and the
731
+ // distance itself as the player zooms, at the zoom's own pace. So it is
732
+ // let out at 6/s whatever drew it short, and a nearer wall takes it in at
733
+ // once. Along this frame's ray from this frame's start. The ball is swept
734
+ // only as far as the camera will be drawn, so the place drawn is the
735
+ // place the sweep checked (`castBallFixed` confirms its end is clear).
736
+ // (Zoomed in since, it is short of no more than the new distance.)
737
+ const short = Math.max(0, Math.min(state.outRange, state.range) - was);
738
+ const free = short <= CAMERA_OUT_DONE;
739
+ const letOut = free ? Infinity : alongRay(state.range - short * (1 - eased(CAMERA_OUT_RATE, dt)));
740
+ const wall = sweep(phys, ray.dir, Math.min(state.range, letOut), margin);
741
+ state.limit = free && wall === Infinity ? Infinity : Math.min(wall, letOut);
742
+ }
743
+
744
+ // How far along `ray` (or the unit `dir`) from `start` the camera is `out`
745
+ // from the look point
746
+ // (the farther place, where it moves away from the look point); the place
747
+ // nearest the look point when none is that far.
748
+ function alongRay(out, dir = ray.dir) {
749
+ const sx = start.x - ray.from.x;
750
+ const sy = start.y - ray.from.y;
751
+ const sz = start.z - ray.from.z;
752
+ const ahead = sx * dir.x + sy * dir.y + sz * dir.z;
753
+ const square = ahead * ahead - (sx * sx + sy * sy + sz * sz) + out * out;
754
+ return Math.max(0, -ahead + Math.sqrt(Math.max(0, square)));
409
755
  }
410
756
 
411
757
  // How far from its place (x, y, z) the camera is drawn this frame: nothing,
@@ -427,28 +773,178 @@ function takenOver(off, at, x, y, z, mine, jumped, dt) {
427
773
  }
428
774
 
429
775
  // The point drawn while a takeover blend lasts (its place plus `off`) is
430
- // collided as its place is: if a fixed solid lies between the look point
431
- // (`ray.from`) and it, it is pulled in along its own ray to CAMERA_MARGIN
432
- // in front (never nearer than CAMERA_NEAREST), and the pull is kept in
433
- // `off`, so the next frame eases on from where it was drawn.
776
+ // collided as its place is: swept toward from `start`, and if the ball
777
+ // touches a fixed solid short of it, it is pulled in along that line to
778
+ // where the ball stopped, and the pull is kept in `off`, so the next frame
779
+ // eases on from where it was drawn. One more query, only while it lasts.
780
+ // Returns whether it was pulled in.
434
781
  const drawn = { x: 0, y: 0, z: 0 };
435
782
 
436
- function holdBlend(phys, off, x, y, z) {
437
- if (!phys?.castRayFixed || !phys.ready()) return;
438
- drawn.x = x + off.x - ray.from.x;
439
- drawn.y = y + off.y - ray.from.y;
440
- drawn.z = z + off.z - ray.from.z;
783
+ function holdBlend(phys, off, x, y, z, margin) {
784
+ if (!collides(phys)) return;
785
+ drawn.x = x + off.x - start.x;
786
+ drawn.y = y + off.y - start.y;
787
+ drawn.z = z + off.z - start.z;
441
788
  const length = Math.hypot(drawn.x, drawn.y, drawn.z);
442
- if (!(length > CAMERA_NEAREST)) return;
789
+ if (!(length > 0)) return false;
443
790
  drawn.x /= length;
444
791
  drawn.y /= length;
445
792
  drawn.z /= length;
446
- const hit = phys.castRayFixed(ray.from, drawn, length + CAMERA_MARGIN);
447
- const most = hit ? Math.max(CAMERA_NEAREST, hit.distance - CAMERA_MARGIN) : Infinity;
448
- if (most >= length) return;
449
- off.x = ray.from.x + drawn.x * most - x;
450
- off.y = ray.from.y + drawn.y * most - y;
451
- off.z = ray.from.z + drawn.z * most - z;
793
+ const most = sweep(phys, drawn, length, margin);
794
+ if (most >= length) return false;
795
+ off.x = start.x + drawn.x * most - x;
796
+ off.y = start.y + drawn.y * most - y;
797
+ off.z = start.z + drawn.z * most - z;
798
+ return true;
799
+ }
800
+
801
+ // While a takeover blend lasts: a blend held in last frame is let out at
802
+ // the collision pace (`easeBlendOut`), and the point drawn is collided
803
+ // (`holdBlend`). Whether a wall has held it in, this frame or before in
804
+ // this blend: from then on, to the blend's end, it is let out at the
805
+ // collision pace.
806
+ function blendHeldIn(phys, state, off, x, y, z, margin, dt) {
807
+ const was = state.blendHeld === true && Number.isFinite(state.drawnOut);
808
+ if (was) easeBlendOut(state, off, x, y, z, dt);
809
+ return holdBlend(phys, off, x, y, z, margin) || was;
810
+ }
811
+
812
+ // A blend a wall held in (`holdBlend`, last frame) is let back out at the
813
+ // collision pace, not the blend's: no farther from the look point than
814
+ // easing at CAMERA_OUT_RATE from where it was drawn (`state.drawnOut`)
815
+ // toward where the camera rests this frame (review 10: not its distance,
816
+ // which a start moved off a wall can leave short of the place, holding the
817
+ // blend open for good), as `limitReach` lets its place out, so a
818
+ // wall that goes does not let the blend's TAKEOVER_RATE carry it out
819
+ // (review 9: 0.246 m in a frame where 0.179 m is allowed). Pulled in along
820
+ // its own line from `start`, and the pull kept in `off`. A blend whose own
821
+ // point is no farther than that goes on at its own pace. Returns whether it
822
+ // was held.
823
+ const blendDir = { x: 0, y: 0, z: 0 };
824
+ function easeBlendOut(state, off, x, y, z, dt) {
825
+ const px = x + off.x;
826
+ const py = y + off.y;
827
+ const pz = z + off.z;
828
+ const own = Math.hypot(px - ray.from.x, py - ray.from.y, pz - ray.from.z);
829
+ const was = state.drawnOut;
830
+ // Toward where the camera rests this frame (its place, which a start
831
+ // moved off a wall can put farther out than its distance), and let go
832
+ // within CAMERA_OUT_DONE of it, so a held blend always ends.
833
+ const rest = Math.hypot(x - ray.from.x, y - ray.from.y, z - ray.from.z);
834
+ const allowed = was + Math.max(0, rest - was) * eased(CAMERA_OUT_RATE, dt);
835
+ if (own <= allowed || rest - allowed <= CAMERA_OUT_DONE) return false;
836
+ blendDir.x = px - start.x;
837
+ blendDir.y = py - start.y;
838
+ blendDir.z = pz - start.z;
839
+ const length = Math.hypot(blendDir.x, blendDir.y, blendDir.z);
840
+ if (!(length > 0)) return false;
841
+ blendDir.x /= length;
842
+ blendDir.y /= length;
843
+ blendDir.z /= length;
844
+ const along = Math.min(length, alongRay(allowed, blendDir));
845
+ off.x = start.x + blendDir.x * along - x;
846
+ off.y = start.y + blendDir.y * along - y;
847
+ off.z = start.z + blendDir.z * along - z;
848
+ return true;
849
+ }
850
+
851
+ // Client-side, per-player shots only belong to the orbit camera. Neither
852
+ // its chosen angles nor its lens are changed; the deck places the shot clear
853
+ // of solids. Scratch is shared, while the drawn look travels with the actor.
854
+ const shotPose = { x: 0, y: 0, z: 0, yaw: 0, pitch: 0 };
855
+ function validOrbitShot(shot) {
856
+ const valid = shot && shot.look && Number.isFinite(shot.look.x) && Number.isFinite(shot.look.y)
857
+ && Number.isFinite(shot.look.z) && Number.isFinite(shot.distance) && shot.distance > 0
858
+ && Number.isFinite(shot.pitch) && Number.isFinite(shot.yaw);
859
+ if (!valid) return null;
860
+ const pitch = clamp(shot.pitch, -89, 89) * DEG;
861
+ const yaw = shot.yaw * DEG;
862
+ const flat = Math.cos(pitch);
863
+ shotPose.x = shot.look.x - flat * Math.sin(yaw) * shot.distance;
864
+ shotPose.y = shot.look.y + Math.sin(pitch) * shot.distance;
865
+ shotPose.z = shot.look.z + flat * Math.cos(yaw) * shot.distance;
866
+ shotPose.yaw = Math.atan2(flat * Math.sin(yaw), flat * Math.cos(yaw));
867
+ shotPose.pitch = pitch;
868
+ // Finite inputs can still overflow when added; treat that as absent too.
869
+ return Number.isFinite(shotPose.x) && Number.isFinite(shotPose.y) && Number.isFinite(shotPose.z) ? shot : null;
870
+ }
871
+ function ownsShotCamera(scene, drawnLook, cam, dt) {
872
+ return typeof drawnLook.placedAt === 'number' && Math.abs(scene.time - dt - drawnLook.placedAt) < PLACED_WITHIN
873
+ && drawnLook.atX === cam.position.x && drawnLook.atY === cam.position.y && drawnLook.atZ === cam.position.z
874
+ && drawnLook.qX === cam.quaternion.x && drawnLook.qY === cam.quaternion.y
875
+ && drawnLook.qZ === cam.quaternion.z && drawnLook.qW === cam.quaternion.w;
876
+ }
877
+ function recordShotCamera(scene, drawnLook, cam) {
878
+ drawnLook.placedAt = scene.time;
879
+ drawnLook.atX = cam.position.x;
880
+ drawnLook.atY = cam.position.y;
881
+ drawnLook.atZ = cam.position.z;
882
+ drawnLook.qX = cam.quaternion.x;
883
+ drawnLook.qY = cam.quaternion.y;
884
+ drawnLook.qZ = cam.quaternion.z;
885
+ drawnLook.qW = cam.quaternion.w;
886
+ }
887
+ function placeOrbitShot(scene, cam, rt, state, before, t, shot, dt) {
888
+ const drawnLook = (rt.orbitShot ??= { active: false, returning: false, x: 0, y: 0, z: 0 });
889
+ const continuing = drawnLook.active || drawnLook.returning;
890
+ if (!continuing || !ownsShotCamera(scene, drawnLook, cam, dt)) {
891
+ // The previous orbit look point gives the focus distance. Along the
892
+ // actual drawn direction, so even a camera another system placed has
893
+ // no rotation snap on entry. No temporary vectors on the frame path.
894
+ const at = cam.position;
895
+ const distance = (continuing
896
+ ? Math.hypot(at.x - shot.look.x, at.y - shot.look.y, at.z - shot.look.z)
897
+ : Math.hypot(at.x - (before?.x ?? t.x), at.y - ((state.heightTo ?? t.y) + LOOK_HEIGHT), at.z - (before?.z ?? t.z))) || shot.distance;
898
+ const q = cam.quaternion;
899
+ drawnLook.x = at.x - 2 * (q.x * q.z + q.w * q.y) * distance;
900
+ drawnLook.y = at.y + 2 * (q.w * q.x - q.y * q.z) * distance;
901
+ drawnLook.z = at.z + (2 * (q.x * q.x + q.y * q.y) - 1) * distance;
902
+ // The camera's right vector retains azimuth even when its forward
903
+ // vector is vertical. Seed it on entry or an ownership interruption.
904
+ drawnLook.yaw = Math.atan2(2 * (q.x * q.z - q.w * q.y), 1 - 2 * (q.y * q.y + q.z * q.z));
905
+ }
906
+ drawnLook.active = true;
907
+ drawnLook.returning = false;
908
+ const at = cam.position;
909
+ if (at.x === shotPose.x && at.y === shotPose.y && at.z === shotPose.z
910
+ && drawnLook.x === shot.look.x && drawnLook.y === shot.look.y && drawnLook.z === shot.look.z) {
911
+ drawnLook.yaw = shotPose.yaw;
912
+ cam.lookAt(drawnLook.x, drawnLook.y, drawnLook.z);
913
+ recordShotCamera(scene, drawnLook, cam);
914
+ return;
915
+ }
916
+ const k = eased(TAKEOVER_RATE, dt);
917
+ // Ease around the drawn focus, so opposite shots never cross through it.
918
+ const dx = at.x - drawnLook.x;
919
+ const dy = at.y - drawnLook.y;
920
+ const dz = at.z - drawnLook.z;
921
+ const flat = Math.hypot(dx, dz);
922
+ const distance = Math.hypot(flat, dy);
923
+ const yaw = flat < SHOT_YAW_EPS * distance ? drawnLook.yaw : Math.atan2(-dx, dz);
924
+ const pitch = Math.atan2(dy, flat);
925
+ const nextYaw = yaw + arc(shotPose.yaw - yaw) * k;
926
+ const nextPitch = clamp(pitch + (shotPose.pitch - pitch) * k, -SHOT_PITCH_LIMIT, SHOT_PITCH_LIMIT);
927
+ const nextDistance = distance + (shot.distance - distance) * k;
928
+ drawnLook.yaw = nextYaw;
929
+ drawnLook.x += (shot.look.x - drawnLook.x) * k;
930
+ drawnLook.y += (shot.look.y - drawnLook.y) * k;
931
+ drawnLook.z += (shot.look.z - drawnLook.z) * k;
932
+ if (Math.abs(arc(shotPose.yaw - nextYaw)) < SHOT_SETTLED && Math.abs(shotPose.pitch - nextPitch) < SHOT_SETTLED
933
+ && Math.abs(shot.distance - nextDistance) < SHOT_SETTLED
934
+ && Math.hypot(shot.look.x - drawnLook.x, shot.look.y - drawnLook.y, shot.look.z - drawnLook.z) < SHOT_SETTLED) {
935
+ drawnLook.x = shot.look.x;
936
+ drawnLook.y = shot.look.y;
937
+ drawnLook.z = shot.look.z;
938
+ drawnLook.yaw = shotPose.yaw;
939
+ at.set(shotPose.x, shotPose.y, shotPose.z);
940
+ } else {
941
+ const nextFlat = Math.cos(nextPitch);
942
+ at.set(drawnLook.x - nextFlat * Math.sin(nextYaw) * nextDistance,
943
+ drawnLook.y + Math.sin(nextPitch) * nextDistance,
944
+ drawnLook.z + nextFlat * Math.cos(nextYaw) * nextDistance);
945
+ }
946
+ cam.lookAt(drawnLook.x, drawnLook.y, drawnLook.z);
947
+ recordShotCamera(scene, drawnLook, cam);
452
948
  }
453
949
 
454
950
  // The orbit camera, placed at the end of the frame as the rigid one is
@@ -476,11 +972,32 @@ function placeOrbiting(scene, id, dt) {
476
972
  per.camLastAt = { x: t.x, z: t.z };
477
973
  const at = cam.position;
478
974
  const state = (rt.orbit ??= { off: { x: 0, y: 0, z: 0 } });
975
+ const shot = validOrbitShot(scene.orbitShot);
976
+ if (shot) {
977
+ placeOrbitShot(scene, cam, rt, state, before, t, shot, dt);
978
+ // `look` was consumed above and is deliberately dropped while held.
979
+ scene.orbitOwnModel = id;
980
+ return;
981
+ }
982
+ const drawnLook = rt.orbitShot;
983
+ const handBack = drawnLook?.active === true;
984
+ const keptShot = drawnLook && ownsShotCamera(scene, drawnLook, cam, dt);
985
+ if (handBack) {
986
+ drawnLook.active = false;
987
+ drawnLook.returning = keptShot;
988
+ drawnLook.offX = drawnLook.x - t.x;
989
+ drawnLook.offY = drawnLook.y - t.y - LOOK_HEIGHT;
990
+ drawnLook.offZ = drawnLook.z - t.z;
991
+ }
992
+ if (drawnLook && !keptShot) {
993
+ drawnLook.returning = false;
994
+ drawnLook.offX = drawnLook.offY = drawnLook.offZ = 0;
995
+ }
479
996
  // Placed on the frame before too: a frame this did not place on (the
480
997
  // Player turned off, even by a collision callback after its update)
481
998
  // breaks the chain.
482
999
  const placed = typeof state.placedAt === 'number' && Math.abs(scene.time - dt - state.placedAt) < PLACED_WITHIN;
483
- const mine = placed && !jumped && state.x === at.x && state.y === at.y && state.z === at.z;
1000
+ const mine = !handBack && placed && !jumped && state.x === at.x && state.y === at.y && state.z === at.z;
484
1001
  if (mine) {
485
1002
  if (look && !look.locked) steerOrbit(per, chosen, look);
486
1003
  const k = eased(ORBIT_RATE, dt);
@@ -489,7 +1006,7 @@ function placeOrbiting(scene, id, dt) {
489
1006
  state.range += (chosen.range - state.range) * k;
490
1007
  state.height = settle(state.height, state.heightTo, t.y, dt);
491
1008
  } else {
492
- Object.assign(state, { yaw: per.camAngle, pitch: chosen.pitch, range: chosen.range, height: t.y, limit: Infinity });
1009
+ Object.assign(state, { yaw: per.camAngle, pitch: chosen.pitch, range: chosen.range, height: t.y, limit: Infinity, out: undefined, outRange: undefined, blendHeld: false, drawnOut: undefined });
493
1010
  }
494
1011
  state.heightTo = t.y;
495
1012
  const flat = Math.cos(state.pitch);
@@ -501,19 +1018,52 @@ function placeOrbiting(scene, id, dt) {
501
1018
  ray.from.x = t.x;
502
1019
  ray.from.y = state.height + LOOK_HEIGHT;
503
1020
  ray.from.z = t.z;
504
- limitReach(scene.physics3d, state, dt);
505
- const reach = Math.max(Math.min(state.range, state.limit), Math.min(CAMERA_NEAREST, state.range), 0);
506
- const x = ray.from.x + ray.dir.x * reach;
507
- const y = ray.from.y + ray.dir.y * reach;
508
- const z = ray.from.z + ray.dir.z * reach;
1021
+ const margin = lensMargin(scene, cam);
1022
+ limitReach(scene.physics3d, state, margin, dt);
1023
+ // Drawn at the nearer of its distance and the limit, out from the ball's
1024
+ // start (the look point, or a point moved off a surface it is pressed to).
1025
+ const reach = Math.max(Math.min(state.range, state.limit), 0);
1026
+ const x = start.x + ray.dir.x * reach;
1027
+ const y = start.y + ray.dir.y * reach;
1028
+ const z = start.z + ray.dir.z * reach;
1029
+ // How far from the look point it is placed, and the distance it was
1030
+ // placed for, for the next frame's ease.
1031
+ state.out = Math.hypot(x - ray.from.x, y - ray.from.y, z - ray.from.z);
1032
+ state.outRange = state.range;
509
1033
  const off = takenOver(state.off, at, x, y, z, mine, jumped, dt);
510
- if (Math.hypot(off.x, off.y, off.z) > BLEND_TESTED) holdBlend(scene.physics3d, off, x, y, z);
1034
+ state.blendHeld = Math.hypot(off.x, off.y, off.z) > BLEND_TESTED && blendHeldIn(scene.physics3d, state, off, x, y, z, margin, dt);
511
1035
  cam.position.set(x + off.x, y + off.y, z + off.z);
1036
+ // How far from the look point it is drawn, for a held blend's ease.
1037
+ state.drawnOut = Math.hypot(x + off.x - ray.from.x, y + off.y - ray.from.y, z + off.z - ray.from.z);
512
1038
  state.placedAt = scene.time;
513
1039
  state.x = at.x;
514
1040
  state.y = at.y;
515
1041
  state.z = at.z;
516
- cam.lookAt(t.x, t.y + LOOK_HEIGHT, t.z);
1042
+ if (drawnLook?.returning) {
1043
+ // Decay the hand-back offset, rather than chasing the moving player:
1044
+ // walking carries the look point immediately and cannot hold it open.
1045
+ const left = jumped ? 0 : Math.exp(-TAKEOVER_RATE * dt);
1046
+ drawnLook.offX *= left;
1047
+ drawnLook.offY *= left;
1048
+ drawnLook.offZ *= left;
1049
+ drawnLook.x = t.x + drawnLook.offX;
1050
+ drawnLook.y = t.y + LOOK_HEIGHT + drawnLook.offY;
1051
+ drawnLook.z = t.z + drawnLook.offZ;
1052
+ if (Math.hypot(drawnLook.offX, drawnLook.offY, drawnLook.offZ) < BLEND_TESTED) {
1053
+ drawnLook.offX = drawnLook.offY = drawnLook.offZ = 0;
1054
+ drawnLook.returning = false;
1055
+ } else {
1056
+ cam.lookAt(drawnLook.x, drawnLook.y, drawnLook.z);
1057
+ }
1058
+ }
1059
+ if (!drawnLook?.returning) {
1060
+ cam.lookAt(t.x, t.y + LOOK_HEIGHT, t.z);
1061
+ }
1062
+ if (drawnLook) recordShotCamera(scene, drawnLook, cam);
1063
+ // The actor the camera was placed for, for this frame's draw: its model is
1064
+ // left out of the frame if the final camera is inside it
1065
+ // (engine3d/ownmodel.js; the draw takes the name, a load drops it).
1066
+ scene.orbitOwnModel = id;
517
1067
  }
518
1068
 
519
1069
  // The nearest Lookable the player is facing, within its range.
@@ -572,9 +1122,13 @@ export class Player {
572
1122
  const shape = actor.components.Shape;
573
1123
  const dims = { radius: shape?.radius ?? 0.35, height: shape?.height ?? 1.4 };
574
1124
  // Under the camera key the player is held steady on screen: the hover
575
- // and the fall-faster pull are forces (hoverSteadily). Without it every
576
- // call below is the one made before the key had this meaning.
577
- const steady = scene.cameraFollowsRigidly === true;
1125
+ // and the fall-faster pull are forces (hoverSteadily). So they are under
1126
+ // the frame cap (`engine.maxFps`, `scene.maxFps` above 0), whose frames
1127
+ // are handed what they took, 1 to 3 physics steps' worth: there an
1128
+ // impulse per frame against gravity per step bobs the player with the
1129
+ // accumulator's carry (the kit's CLAUDE.md, maxFps). Without either key
1130
+ // every call below is the one made before the keys had this meaning.
1131
+ const steady = scene.cameraFollowsRigidly === true || scene.maxFps > 0;
578
1132
  const grounded = steady ? hoverSteadily(phys, actor, t, dims) : applyHover(phys, actor, t, dims, dt);
579
1133
  const drive = readDrive(scene.keys, scene.moveInput);
580
1134
  per.camAngle += drive.turn * this.props.turnSpeed * dt;
@@ -612,7 +1166,10 @@ export class Player {
612
1166
  }
613
1167
  }
614
1168
 
615
- if (scene.cameraFollowsRigidly !== true) updateCamera(scene, t, per, this.props, dt);
1169
+ if (scene.cameraFollowsRigidly !== true) {
1170
+ if (scene.maxFps > 0) scene.followCamera = { id: actor.id, data: scene.data, dt, place: placeCapped };
1171
+ else updateCamera(scene, t, per, this.props, dt);
1172
+ }
616
1173
  const remaining = scene.actorsWith('Pickup').length;
617
1174
  const total = per.score + remaining;
618
1175
  const score =