threedog 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -0,0 +1,62 @@
1
+ // pixelSnap on a camera rig (followCamera, fixedCamera). The rig places the camera as it likes, then rigModule calls apply() once (common.js): that one call site is why the
2
+ // rigs carry no copy of this, and the math itself is pixelGrid's. While it is on, the view height belongs here: buffer rows / pixelsPerMeter, so a resize or
3
+ // engine.setPixelSize keeps the same world-to-pixel scale. A `size` of the game's would make the grid and the picture disagree, so options refuse it and a later write is
4
+ // reported by name.
5
+ import { pixelGrid } from '../../core/scene/pixel.js';
6
+ import { setProjection } from '../../core/scene/view.js';
7
+ import { codedError, coded } from '../../core/base/errorHints.js';
8
+ import { warnOnce } from '../../core/base/validate.js';
9
+ import { readParams, keysSchema } from '../../core/base/params.js';
10
+
11
+ const KEYS = keysSchema(['pixelsPerMeter', 'bounds']);
12
+
13
+ class RigPixelSnap {
14
+ constructor(engine, { pixelsPerMeter, bounds = null }) {
15
+ this.engine = engine; this.bounds = bounds;
16
+ this.grid = pixelGrid({ camera: engine.camera, pixelsPerMeter });
17
+ /** False while something else changed the view height (camera.zoom, the frustum): nothing is rounded then, a grid that does not match the picture means nothing */
18
+ this.agrees = true;
19
+ /** The last rounding, in art pixels on the screen axes */
20
+ this.error = { x: 0, y: 0 };
21
+ this._wrote = null; // the view height this rig last set: anything else showing means an outside write
22
+ }
23
+ _write() { this._wrote = this.grid.viewHeight(this.engine.renderer.domElement.height); setProjection(this.engine, 'orthographic', this._wrote); }
24
+ /** The rig became the camera */
25
+ enter() { this._write(); this.grid.camera = this.engine.camera; }
26
+ /** After the rig's update: view height, bounds, rounding */
27
+ apply() {
28
+ const cam = this.engine.camera, c = this.engine.renderer.domElement, g = this.grid;
29
+ // engine.camera was assigned: the same grid goes on (sprites hold it), and the view height the new camera came with is no outside write
30
+ if (g.camera !== cam) { g.camera = cam; if (cam.isOrthographicCamera) this._wrote = null; }
31
+ this.agrees = !!cam.isOrthographicCamera && (this._wrote == null || g.agrees(this._wrote * g.pixelsPerMeter));
32
+ if (!this.agrees) {
33
+ warnOnce(coded('pixel-conflict', `pixelSnap: something else set the view height (camera.zoom, the frustum or a perspective view), so the camera no longer shows the ${this._wrote} world units `
34
+ + `that pixelsPerMeter ${g.pixelsPerMeter} needs and rounding has stopped. Keep pixelSnap and put them back (to zoom, use engine.setPixelSize), or drop pixelSnap`));
35
+ return;
36
+ }
37
+ this._write();
38
+ const r = g.place(cam.position, { columns: c.width, rows: c.height, bounds: this.bounds });
39
+ cam.position.copy(r.position);
40
+ this.error.x = r.error.x; this.error.y = r.error.y;
41
+ }
42
+ describe() { return { pixelsPerMeter: this.grid.pixelsPerMeter, viewHeight: this._wrote, agrees: this.agrees, error: { ...this.error } }; }
43
+ }
44
+
45
+ /**
46
+ * A view pixelSnap can own: orthographic, with no size of its own. Thrown here, named, at the option that is wrong.
47
+ * @param {string} who the rig or shot, for the message @param {{ projection?: string, size?: number | null }} view
48
+ */
49
+ export function checkPixelView(who, { projection, size }) {
50
+ if (projection !== 'orthographic') throw codedError('camera-option', `${who}: pixelSnap works on an orthographic camera only, a perspective view has no single art pixel size. Add projection: 'orthographic', or drop pixelSnap`);
51
+ if (size != null) throw codedError('pixel-conflict', `${who}: size ${size} with pixelSnap, which decides the view height itself (buffer height / pixelsPerMeter). Drop size, or drop pixelSnap`);
52
+ }
53
+
54
+ /**
55
+ * The pixelSnap option of a rig: null when not asked for. Each rig calls this from its constructor, and enter() from onEnter.
56
+ * @param {any} engine @param {any} opts the pixelSnap option @param {string} who the rig's name, for messages
57
+ */
58
+ export function rigPixelSnap(engine, opts, who) {
59
+ if (!opts) return null;
60
+ readParams(`${who} pixelSnap`, KEYS, opts);
61
+ return new RigPixelSnap(engine, opts);
62
+ }
@@ -8,11 +8,10 @@
8
8
  // Radius and step height default to engine.movement (the single source of "can walk through" parameters); passing radius / stepHeight overrides it for this character only.
9
9
  // How to walk is decided by the mover (movers/: 'simple' default, 'rapier' character controller); feel parameters are identical for both.
10
10
  // The procedural body (capsule, rig read from a model asset, limb swing) is in proceduralRig.js; loading a body by asset name in assetModel.js.
11
- import { engineOwned } from '../../core/things.js';
12
11
  import * as THREE from 'three';
13
- import { xzOf, yOf } from '../../core/math.js';
14
- import { warnOnce, warnMissing, DEV } from '../../core/validate.js';
15
- import { reportError } from '../../core/errors.js';
12
+ import { xzOf, yOf } from '../../core/base/math.js';
13
+ import { warnOnce, warnMissing, DEV, fmt } from '../../core/base/validate.js';
14
+ import { reportError } from '../../core/base/errors.js';
16
15
  import { simpleMover } from './movers/simple.js';
17
16
  import { rapierMover } from './movers/rapier.js';
18
17
  import { manualMover } from './movers/manual.js';
@@ -21,11 +20,15 @@ import { stateOf, detach, registry, placeAtHeight } from './movers/support.js';
21
20
  import { loadAssetModel, buildNow } from './assetModel.js';
22
21
  import { NO_CHARACTER, capsule, useRig, animateRig, rigFromObject, tintParts } from './proceduralRig.js';
23
22
  import { walkTo } from './walkTo.js';
23
+ import { seatsOf } from './seat.js';
24
24
  import { useModel } from './useModel.js';
25
- import { codedError, coded } from '../../core/errorHints.js';
25
+ import { codedError, coded } from '../../core/base/errorHints.js';
26
+ import { isModelName } from '../../core/base/util.js';
26
27
 
28
+ // A record whose jump / safe is the wrong kind of thing (a damaged or hand-edited save) is repaired so the game keeps running, but said out loud once: bad data is reported, not quietly fixed
29
+ function badField(v, name, want) { if (v != null) warnOnce(`[threedog] character motion: the world record's '${name}' is ${JSON.stringify(v)} but should be ${want}; it was replaced with a fresh one. Check the save or the code that writes the record`); return undefined; }
27
30
  const STRINGS = { noClip: 'character has no skeletal animation; playAction(\'{name}\') skipped (the model needs this action)' };
28
- const MOVERS = { simple: simpleMover, rapier: rapierMover, manual: manualMover };
31
+ const BUILT_IN = { simple: simpleMover, rapier: rapierMover, manual: manualMover };
29
32
 
30
33
  // Options Character understands (shared by player and NPC)
31
34
  export const CHARACTER_KEYS = ['colors', 'speed', 'runSpeed', 'radius', 'water', 'states', 'swimDepth', 'swimSpeed', 'turnSpeed', 'acceleration', 'gravity',
@@ -35,7 +38,7 @@ const FACE_MODES = ['move', 'camera', 'target', 'manual'];
35
38
  export class Character {
36
39
  /**
37
40
  * @param engine
38
- * @param o model: the body, one path for all: a model asset name (a procedural builder from an asset pack, or a GLB name), or what
41
+ * @param o model: the body, one path for all: a model asset name (a procedural builder from an asset pack, or a GLB name), [name, ...args] for a generator, or what
39
42
  * engine.assets.model() returned; without model and rig a gray capsule (warned once). rig: a ready body (proceduralRig.js format)
40
43
  * colors: { body, skin, legs, hair } per-character part colors (meshes marked userData.part; a capsule takes colors.body)
41
44
  * speed walk speed, runSpeed run speed (m/s), radius collision radius
@@ -50,13 +53,14 @@ export class Character {
50
53
  * coyoteTime how long after leaving a ledge a jump is still allowed, canJump, jumpBuffer how long a jump() pressed early
51
54
  * waits for the ground (s), maxJumps jumps before landing again (2 = double jump), airJumpSpeed takeoff speed of an air jump
52
55
  * (default jumpSpeed). These are the base values and belong to the game; modules change them with engine.mod('move.<stat>').
53
- * fall: { belowY } a height (or (character) => boolean): below it character:fall fires and, unless a listener calls preventDefault(),
54
- * the character goes back to safeGround. false (default) = off
56
+ * fall: { belowY } a height (or (character) => boolean): below it character:fall fires and the rule 'fall' decides (no rule: nothing happens;
57
+ * engine.mod('fall', { owner: 'game', set: 'rescue' }) goes back to safeGround). false (default) = off
55
58
  * channel: the time channel its movement and animation follow when the engine drives it (player 'player', others 'world')
56
59
  * model + clips: optional glTF model and action-name map { idle, walk, run, swim, jump, fall, drive } (shorthand for animation)
57
- * animation: animation state machine config (see core/Animator.js), state names are character state names;
60
+ * animation: animation state machine config (see core/assets/Animator.js), state names are character state names;
58
61
  * without walk/run, move (blend tree, param speed) is used
59
- * mover: 'simple' (default) | 'rapier' (Rapier character controller, needs the rigid module) | 'manual' (the game writes the position;
62
+ * mover: (character, engine) => ({ name, move(x, z, run, dt, y) }) your own (flight, wall running: mover.contract.js, recipe 57) |
63
+ * 'simple' (default) | 'rapier' (Rapier character controller, needs the rigid module) | 'manual' (the game writes the position;
60
64
  * move() only updates grounded / support / safeGround / fall, movers/manual.js); assign at any time: player.mover = 'manual'
61
65
  * faceMode which way it turns each move: 'move' (default, toward its velocity) | 'camera' (along cameraRig.forward(), over-the-shoulder aiming)
62
66
  * | 'target' (toward faceTarget: Object3D / Vector3 / { x, z }, lock-on strafing) | 'manual' (only face() turns it);
@@ -67,7 +71,7 @@ export class Character {
67
71
  turnSpeed = 10, acceleration = 12, gravity = -24, jumpSpeed = 8, stepHeight = engine.movement.stepHeight, airControl = 0.35, coyoteTime = 0.12,
68
72
  canJump = true, maxJumps = 1, airJumpSpeed = null, jumpBuffer = 0.12, fall = false, channel = 'world',
69
73
  model = null, clips = null, animation = null, mover = 'simple', faceMode = 'move', faceTarget = null, rig = null, id = null } = {}) {
70
- /** @internal the id option (a character without a world record); the getter id below is the one public form */ this._ownId = id;
74
+ /** @internal the id option, else the generated one (a character without a world record); the getter id below is the one public form */ this._ownId = id;
71
75
  /** @internal true for a world NPC's model (npcView.js): disposing it keeps the NPC's control slot */ this.npcModel = false;
72
76
  this.engine = engine;
73
77
  if (typeof water !== 'function' && !WATER_MODES.includes(water)) throw codedError('character-option', `character option water: 'swim' | 'block' | 'wade' or (character, { depth }) => one of them; got ${JSON.stringify(water)}`, TypeError);
@@ -87,30 +91,34 @@ export class Character {
87
91
  // toward the input, vy falls with gravity). Nobody owns them and nothing auto-yields: a knockback that should last is push(), a jump pad is
88
92
  // launch(), full control is mover 'manual'.
89
93
  this.vy = 0; this.grounded = true; this._push = 0;
90
- this.onStep = null; this.onLand = null;
94
+ this.limp = null; this.disposed = false; // limp: the ragdoll that has the body (rigid/ragdoll.js)
91
95
  this.root = new THREE.Group();
96
+ engine._poses.add(this.root);
92
97
  this.velocity = new THREE.Vector2();
93
98
  this.facing = 0; this.phase = 0; this.moveAmount = 0;
94
99
  this.swimming = false;
95
- /** Action state the animation plays: 'idle' | 'walk' | 'run' | 'jump' | 'fall' | 'swim' | 'drive', or what the states option returned. Read it freely;
100
+ /** Action state the animation plays: 'idle' | 'walk' | 'run' | 'jump' | 'fall' | 'swim' | 'drive' | 'ragdoll', or what the states option returned. Read it freely;
96
101
  * the engine mover recomputes it every step, so a direct write warns once (states option for own states, character.playAction(name) for one-shot
97
- * actions, mover 'manual' to own it). _stateMark: the engine's last write @type {string} */
98
- this.state = this._stateMark = 'idle';
102
+ * actions, mover 'manual' to own it). stateMark: the engine's last write @type {string} */
103
+ this.state = this.stateMark = 'idle';
99
104
  /** The vehicle it sits in (null on foot) and its seat there (0 = driver, null on foot) */
100
- this.vehicle = null; this.seat = null; this.anim = null;
105
+ /** @internal the seat relation (seat.js), null on foot */ this._ride = null; this.anim = null;
101
106
  /** false while a model named by asset loads (placeholder shows); await whenReady */
102
107
  this.ready = true;
103
108
  /**
104
109
  * id of the world record ('player' for the player); once set, position, facing and motion state are written back to it.
105
- * Do not world.move this record directly; use placeAt
110
+ * A write to that record's position (world.move, world.set, thing.set) is a placeAt
106
111
  * @type {string | null}
107
112
  */
108
113
  this.recordId = null;
109
- /** @internal each mover built once, kept while switching (rapier keeps its native body) */ this._movers = { simple: simpleMover(this) };
114
+ /** @internal where a write to its record's position goes (world.move): placeAt; an NPC's model goes through npc.placeAt, which drops its path too */ this.placeRecord = p => this.placeAt(p);
115
+ /** @internal where a turn written to its record goes; an NPC's facing is saved in its motion */ this._turnRecord = yaw => { this.face(yaw); this._store(); };
116
+ /** @internal each mover built once, kept while switching (rapier keeps its native body), by name or by the game's function */ this._movers = new Map([['simple', simpleMover(this)]]);
117
+ /** @internal the rule character.mover: an entry there wins over this character's own mover and ends with its owner, so a ladder puts back what was there */ this._moverRule = engine.stacks.rule('character.mover', null);
110
118
  this.mover = mover;
111
119
  this._colors = colors;
112
120
  // one path for every body: an object, a procedural builder built now (joints exist at once), or a file asset loaded behind a capsule
113
- const now = typeof model === 'string' ? buildNow(engine, model) : model;
121
+ const now = isModelName(model) ? buildNow(engine, model) : model;
114
122
  if (now) { this._useModel(now, clips, animation); return; }
115
123
  if (!rig && !model) warnOnce(NO_CHARACTER);
116
124
  useRig(this, rig || capsule(colors.body, engine));
@@ -133,13 +141,11 @@ export class Character {
133
141
  /**
134
142
  * The character's id, the one form engine.mod / time.local take for its entries: its world record id ('player' for the player, an NPC's
135
143
  * record id), else the id option you gave it (new Character(e, { id: 'knight-1' })), else a fixed generated one.
136
- * Why one form: the same character had three spellings (player.modId, 'player', the record id) and a typo'd one silently modded nobody.
144
+ * Why one form: a misspelled id silently mods nobody.
137
145
  * @example engine.mod('move.speed', { owner: 'haste', id: 'player', mul: 1.2, for: 5 })
138
146
  * @readonly @type {string}
139
147
  */
140
- get id() { return this.recordId ?? this._ownId ?? (this._modId ??= `character#${++registry(this.engine).n}`); }
141
- /** @internal the engine's own spelling of id (movers, walkTo, time channels) */
142
- get modId() { return this.id; }
148
+ get id() { return this.recordId ?? (this._ownId ??= `character#${++registry(this.engine).n}`); }
143
149
  /**
144
150
  * A movement stat as the mover uses it now: the base field with every engine.mod('move.<name>') entry applied (speed / runSpeed / gravity /
145
151
  * jumpSpeed / canJump (1 or 0)). Read-only; the base is the plain field (player.speed = 6), modifiers go through engine.mod.
@@ -152,7 +158,7 @@ export class Character {
152
158
  * on the ground or in coyote time it is the ground jump, otherwise an air jump while maxJumps allows. air: false = only a ground jump.
153
159
  * @example createPlayer({ ..., maxJumps: 2 }); // double jump: the same jump key twice
154
160
  */
155
- jump({ air = true } = {}) { const j = jumpOf(this); j.buffer = this.jumpBuffer; j.air = air; return this; }
161
+ jump({ air = true } = {}) { const j = jumpOf(this); j.buffer = this.jumpBuffer || 1e-6; j.fresh = true; j.air = air; return this; }
156
162
  /** Give back n jumps for this airtime (a pickup, a wall touch) @param {number} [n] */
157
163
  addJumps(n = 1) { const j = jumpOf(this); j.used = Math.max(0, j.used - n); return this; }
158
164
  /** All jumps back, as if it had landed */
@@ -193,27 +199,76 @@ export class Character {
193
199
  /** Settles (never rejects) once a model named by asset is swapped in or failed; already settled otherwise */
194
200
  get whenReady() { return this._whenReady ?? Promise.resolve(); }
195
201
  get position() { return this.root.position; }
196
- /** The character's three.js root object (= root): add children, set visible, scale on it */
197
- get object() { return this.root; }
198
- addTo(scene = this.engine.scene) { scene.add(engineOwned('characters', this.root)); return this; }
202
+ /** What it rides now (the vehicle contract object), null on foot */
203
+ get vehicle() { return this._ride?.vehicle ?? null; }
204
+ /** @internal Something other than a holder has the body: a ragdoll (rigid/ragdoll.js) or a seat (seat.js). Nothing may move or place it meanwhile */
205
+ get bodyHeld() { return !!(this.limp || this._ride); }
206
+ /** Its seat in that vehicle (0 = driver), null on foot */
207
+ get seat() { return this._ride?.seat ?? null; }
208
+ // Why write-only accessors: these were plain slots until 0.8. A game still assigning one got no error and no sound, because the plain write just
209
+ // made a property nothing reads. The write stays harmless (no throw), only the silence goes. No getter: the old names still read as undefined.
199
210
  /**
200
211
  * Place at a position (Vector3 / Object3D / [x, y, z] / { x, z }). With a y it stands on what a character at that height stands on: the floor there, or a
201
212
  * registered support within step height above it, so a place under a deck stays under it. With { x, z } it stands on the highest support there, else the ground.
213
+ * A rider gets out first (exit: vehicle:exit fires, the vehicle brakes): the seat would otherwise pull it back on the next step.
214
+ * A ragdoll goes there whole, at rest, and stays limp. A walk ends: the game said where it is, so the old order no longer applies.
202
215
  */
203
216
  placeAt(position) {
204
- const [x, z] = xzOf(position), at = placeAtHeight(this.engine, 'character.placeAt()', x, z, yOf(position), this.stepHeight, this.root.position.y);
217
+ this.engine.control?.endTasks(this, 'placed');
218
+ if (this.vehicle) this.exit({ force: true });
219
+ else if (this.recordId && this.engine.world?.get(this.recordId)?.vehicle != null) this._writeSeat(null, null); // its record waited for a vehicle not built yet: the game put it elsewhere
220
+ return this._place(position);
221
+ }
222
+ /** @internal Put it there with no ending of its own: a link crossing, a step out of a vehicle */
223
+ _place(position) {
224
+ const [x, z] = xzOf(position), at = placeAtHeight(this.engine, 'character.placeAt()', x, z, yOf(position), this.stepHeight, this.root.position.y), was = this.root.position;
225
+ this.limp?.shift(x - was.x, at.y - was.y, z - was.z); // limp, root follows the body: the body goes first, or the next step puts root back on it
205
226
  this.root.position.set(x, at.y, z);
206
227
  detach(this);
207
228
  // ground is a safe spot. A support may be unsafe or moving, which only a step can tell: the next mover step applies the rule in endMove
208
229
  if (!at.on) (this.safeGround ??= new THREE.Vector3()).copy(this.root.position);
209
230
  this._store(); return this;
210
231
  }
211
- /** Write position and motion state back to the world record (only if recordId is set; saveMotion writes into the record without allocating) @internal */
212
- /** How it walks now: the mover object ({ name, move, controller? }). Assign a name to switch at any time: c.mover = 'manual' ... c.mover = 'simple' */
213
- get mover() { return this._mover; }
214
- set mover(name) {
215
- if (!MOVERS[name]) { warnMissing('mover', name, Object.keys(MOVERS)); name = 'simple'; }
216
- this._mover = this._movers[name] ??= MOVERS[name](this, this._movers.simple);
232
+ /** @internal Why it could not keep this rot, or null: facing is about Y only, and a seat turns its rider every step. thing.set answers with it, world.set throws it */
233
+ poseProblem({ rot, scale }) {
234
+ const bad = v => v !== undefined && !Number.isFinite(v) && !(Array.isArray(v) && v.length === 3 && v.every(Number.isFinite));
235
+ if (bad(rot) || bad(scale)) return `character '${this.id}': rot and scale on its record are the character's turn and size, a number or [x, y, z]; got ${JSON.stringify({ rot, scale })}`;
236
+ if (rot === undefined) return null;
237
+ if (Array.isArray(rot) && (rot[0] || rot[2])) return `rot ${JSON.stringify(rot)} on character '${this.id}': a character stays upright and turns about Y only, so a tilt about x or z cannot apply. Write a number or [0, yaw, 0]; to lean its picture, turn a child of root`;
238
+ return this.vehicle ? `rot on character '${this.id}': it sits in a vehicle and the seat turns it. Turn the vehicle, or exit() first` : null;
239
+ }
240
+ /** @internal A write to its record's rot / scale (world.set, thing.set): the character owns both, as it owns its position. scale is the picture: radius and height stay */
241
+ takePose(pose) {
242
+ const problem = this.poseProblem(pose), { rot, scale } = pose;
243
+ if (problem) throw codedError('character-option', problem);
244
+ if (rot !== undefined) this._turnRecord(Array.isArray(rot) ? rot[1] : rot);
245
+ if (scale !== undefined) { if (Array.isArray(scale)) this.root.scale.fromArray(scale); else this.root.scale.setScalar(scale); this._scaled = true; }
246
+ }
247
+ /** @internal Built or loaded from its record: scale stays there; rot is a write made while it had no character, taken once. A record without scale takes back one written before */
248
+ _fromRecord(rec) {
249
+ const { rot } = rec, scale = rec.scale ?? (this._scaled ? 1 : undefined);
250
+ delete rec.rot;
251
+ this.takePose({ rot, scale });
252
+ }
253
+ /**
254
+ * How it walks now: the mover object ({ name, move, controller? }). Assign a built-in name or (character, engine) => mover to switch for good: c.mover = 'manual'.
255
+ * For a while, use the rule: engine.mod('character.mover', { owner: 'ladder', id: c.id, set: 'manual' }) and remove the handle after. false in the rule means 'manual'
256
+ */
257
+ get mover() { return this._moverOf(this._moverRule.value(this.id) ?? this._ownMover); }
258
+ set mover(v) { this._moverOf(v); this._ownMover = v; }
259
+ /** @internal the mover for a rule value or an assignment, built the first time */
260
+ _moverOf(v) {
261
+ const key = v === false ? 'manual' : v;
262
+ let m = this._movers.get(key);
263
+ if (m) return m;
264
+ if (typeof key === 'function') {
265
+ m = key(this, this.engine);
266
+ if (typeof m === 'string' || m === false) return this._movers.set(key, this._moverOf(m)).get(key); // the function chose a built-in, once for this character
267
+ if (typeof m?.move !== 'function') throw codedError('character-option', `the mover function for '${this.id}' must return { name, move(x, z, run, dt, y) } (mover.contract.js) or a built-in name, got ${JSON.stringify(m)}`);
268
+ } else if (BUILT_IN[key]) m = BUILT_IN[key](this, this._movers.get('simple'));
269
+ else throw codedError('character-option', `mover ${JSON.stringify(key)}: use 'simple', 'rapier', 'manual' or your own (character, engine) => ({ name, move(x, z, run, dt, y) }). Recipe 57`);
270
+ this._movers.set(key, m);
271
+ return m;
217
272
  }
218
273
  _store() { const id = this.recordId; if (id) { const W = this.engine.world; this.saveMotion(W.get(id)); W.move(id, this.root.position); } }
219
274
  /** After moving root yourself (a cutscene path, a scripted pose): write position and motion back to the world record, so a save right after has it */
@@ -221,21 +276,17 @@ export class Character {
221
276
 
222
277
  /**
223
278
  * Move along a direction (call once per fixed step). dirX/dirZ is a world-space direction (length 0-1), run toggles running.
224
- * How it walks is decided by this.mover ('simple' default / 'rapier'); while driving it follows the seat. dt is used as given (the engine's own
279
+ * How it walks is decided by this.mover ('simple' default / 'rapier'); on a seat nothing moves it here (seat.js holds it). dt is used as given (the engine's own
225
280
  * drivers pass the character's channel dt); speed comes from the stats (character.stat, engine.mod('move.speed')), the direction's length scales it.
226
281
  */
227
- move(dirX, dirZ, run, dt) {
228
- // a held character moves only through its holder (core/control.js): a second driver calling move() in the same step is the bug where keys,
282
+ move(dirX, dirZ, run, dt, dirY = 0) {
283
+ // a held character moves only through its holder (core/ops/control.js): a second driver calling move() in the same step is the bug where keys,
229
284
  // a walk and a cutscene all pushed the player and the last one won
230
285
  if (DEV) this.engine.control?.checkMove(this);
231
- if (this.vehicle) {
232
- const v = this.vehicle;
233
- this.root.position.copy(v.seatPosition(this.seat));
234
- // a visible rider turns with the vehicle (a hidden one only needs the position: saves, interactions, trigger zones measure from it)
235
- if (this.root.visible) { v.object.getWorldQuaternion(this.root.quaternion); this.facing = this.root.rotation.y; }
236
- this.moveAmount = Math.abs(v.speed); this.state = this._stateMark = 'drive';
237
- }
238
- else this.mover.move(dirX, dirZ, run, dt);
286
+ if (this.bodyHeld) return; // release builds skip the check above, so nothing may move it here either
287
+ const m = this.mover;
288
+ if (m !== this._moving) { this._moving?.leave?.(); this._moving = m; } // once per change: what the last mover left standing in the world must not block this one
289
+ m.move(dirX, dirZ, run, dt, dirY);
239
290
  this._store();
240
291
  }
241
292
 
@@ -246,46 +297,89 @@ export class Character {
246
297
  * follows vehicle.object. No-op when every seat is taken
247
298
  */
248
299
  enter(vehicle) {
249
- if (this.vehicle) return;
250
- const e = this.engine, ride = vehicle.passengers ??= [];
300
+ if (this.vehicle || this.limp) return;
301
+ const ride = vehicle.passengers ??= [];
251
302
  let seat = 0;
252
303
  if (vehicle.driver) {
253
304
  const taken = new Set(ride.map(c => c.seat));
254
305
  for (seat = 1; seat < (vehicle.seats ?? 1) && taken.has(seat); seat++);
255
306
  if (seat >= (vehicle.seats ?? 1)) return;
256
307
  }
257
- this.vehicle = vehicle; this.seat = seat;
258
- if (seat === 0) vehicle.driver = this; else ride.push(this);
308
+ this._sit(vehicle, seat);
309
+ }
310
+ /** @internal Why it cannot go back to this seat, or null (it may be there already). Undo of a placement that ended a ride asks this first */
311
+ seatProblem({ vehicle, seat }) {
312
+ if (this.vehicle === vehicle && this.seat === seat) return null;
313
+ if (vehicle.gone || !vehicle.object.parent) return `character '${this.id}': the vehicle it sat in is gone, so it cannot go back to its seat`;
314
+ if (this.vehicle) return `character '${this.id}': it sits in another vehicle now. exit() first`;
315
+ if (this.limp) return `character '${this.id}': it is a ragdoll now. remove() it first`;
316
+ return (seat === 0 ? vehicle.driver : vehicle.passengers.some(c => c.seat === seat)) ? `character '${this.id}': seat ${seat} is taken now` : null;
317
+ }
318
+ /** @internal Back on the seat a placement took it from; seatProblem said it can */
319
+ backInSeat({ vehicle, seat }) {
320
+ if (this.vehicle) return;
321
+ this._sit(vehicle, seat);
322
+ }
323
+ /** @internal Take this seat: enter chose it, or an undo names it */
324
+ _sit(vehicle, seat) {
325
+ const e = this.engine;
326
+ e.control?.endTasks(this, 'seated');
327
+ this._ride = { rider: this, vehicle, id: vehicle.id ?? null, seat, pedal: false };
328
+ const book = seatsOf(e); book.rides.add(this._ride); if (vehicle.id != null) book.vehicles.add(vehicle);
329
+ this.root.position.copy(vehicle.seatPosition(seat)); // the record says the seat at once, not on the next step
330
+ this._writeSeat(this._ride.id, seat);
331
+ if (seat === 0) vehicle.driver = this; else vehicle.passengers.push(this);
259
332
  if (e.player === this) this._driveCtx = e.input.push('vehicle', { pass: true }); // driving: brake lives in this context, walking-only keys are shadowed
260
333
  if (e.player === this && !e.input.keysOf('brake').length) warnOnce(coded('input-keys', "the player drives without a brake key: no module binds one by itself. engine.input.bind(presets.bindings.brake) (B / gamepad LT) or engine.input.bind('brake', ['KeyX'])"));
261
- this.root.visible = vehicle.hideDriver === false; this.velocity.set(0, 0); this.vy = 0; this.swimming = false; this.state = this._stateMark = 'drive'; this._store();
334
+ this.root.visible = vehicle.hideDriver === false; this.velocity.set(0, 0); this.vy = 0; this.swimming = false; this.state = this.stateMark = 'drive'; this._store();
262
335
  // only when the game asked the camera to follow the player (createPlayer({ cameraFollow }))
263
336
  if (e.player === this && this.cameraFollow) e.cameraRig?.follow(vehicle.object, vehicle.camera);
264
337
  e.events.emit('vehicle:enter', { character: this, vehicle });
265
338
  }
266
- /** Exit: step out beside the door, camera returns to the character */
267
- exit() {
339
+ /** @internal The relation's half in the record, saved with it. A load writes nothing: recordId is null while it places */
340
+ _writeSeat(vehicle, seat) { const id = this.recordId; if (id) this.engine.ops.allow(() => this.engine.world.set(id, { vehicle, seat })); }
341
+ /** @internal The first exit the vehicle offers that a body of this size can stand on, or null. Without collision nothing can say no */
342
+ _exitSpot(v, seat) {
343
+ for (let n = 0; n < 8; n++) { // bounded: a vehicle with one exit answers the same point for every n
344
+ const p = v.exitPosition(seat, n);
345
+ if (!p) return null;
346
+ if (this.engine.collision?.walkableAt(p.x, p.z, this.radius, p.y) ?? true) return p;
347
+ }
348
+ return null;
349
+ }
350
+ /**
351
+ * Exit: step out at the first exit the vehicle offers that is walkable, camera returns to the character. With none it refuses and the rider stays seated.
352
+ * force: true gets out anyway, at the first exit: the vehicle is going, or the rider is being placed elsewhere.
353
+ * @param {{ force?: boolean }} [o]
354
+ * @returns {boolean} whether it got out
355
+ */
356
+ exit({ force = false } = {}) {
268
357
  const v = this.vehicle, e = this.engine;
269
- if (!v) return;
270
- const seat = this.seat;
358
+ if (!v) return false;
359
+ const seat = this.seat, at = this._exitSpot(v, seat) ?? (force ? v.exitPosition(seat) : null);
360
+ if (!at) return false;
271
361
  if (seat === 0) { v.drive(0, 0, 1); v.driver = null; } else v.passengers.splice(v.passengers.indexOf(this), 1);
272
- this.vehicle = null; this.seat = null;
362
+ seatsOf(e).rides.delete(this._ride); this._ride = null;
363
+ this._writeSeat(null, null);
273
364
  this._driveCtx?.remove(); this._driveCtx = null;
274
365
  this.root.quaternion.identity(); this.root.rotation.y = this.facing;
275
- this.placeAt(v.exitPosition(seat)); this.root.visible = true; this.grounded = true; this.state = this._stateMark = 'idle';
366
+ this._place(at); this.root.visible = true; this.grounded = true; this.state = this.stateMark = 'idle';
276
367
  if (e.player === this && this.cameraFollow) e.cameraRig?.follow(this.root);
277
368
  e.events.emit('vehicle:exit', { character: this, vehicle: v });
369
+ return true;
278
370
  }
279
371
  /** Dispose this character completely: exit the vehicle first, release animation and mover, remove from the scene and dispose geometries and materials */
280
372
  dispose() {
281
- this._disposed = true; // a model still loading by asset name is dropped on arrival
282
- this._walk?.remove(); // a walk in progress ends 'cancelled' (walkTo.js)
373
+ this.disposed = true; // a model still loading by asset name is dropped on arrival
374
+ this.engine.control?.endTasks(this, 'gone');
283
375
  // a character without a world record or NPC id has nothing to come back as: its control slot goes with it (records drop theirs on world:remove,
284
376
  // an NPC model torn down when far keeps its slot, the NPC lives on)
285
377
  if (!this.recordId && !this.npcModel) this.engine.control?.forget(this.id);
286
- this.exit();
378
+ this.exit({ force: true });
379
+ detach(this); // a disposed rider must leave the platform's rider list, or it is carried and kept alive for as long as the platform lives
380
+ this.engine._poses.remove(this.root);
287
381
  this.anim?.dispose();
288
- for (const m of Object.values(this._movers)) m.dispose?.();
382
+ for (const m of new Set(this._movers.values())) m.dispose?.();
289
383
  this.engine.characters?._capsules.delete(this._rig?.capsule);
290
384
  this.engine.remove(this.root);
291
385
  }
@@ -299,8 +393,8 @@ export class Character {
299
393
  out.vx = this.velocity.x; out.vz = this.velocity.y; out.vy = this.vy; out.facing = this.facing; out.amount = this.moveAmount;
300
394
  out.grounded = this.grounded; out.swimming = this.swimming;
301
395
  // motion format 2 (world part version 4): jump state nested, safe spot and the support's id; written in place so a per-step store allocates nothing
302
- const j = jumpOf(this), jo = out.jump ??= {}; jo.coyote = j.coyote; jo.used = j.used;
303
- const g = this.safeGround; if (g) { const a = out.safe ??= [0, 0, 0]; a[0] = g.x; a[1] = g.y; a[2] = g.z; } else out.safe = null;
396
+ const j = jumpOf(this), jo = (out.jump !== null && typeof out.jump === 'object') ? out.jump : (out.jump = badField(out.jump, 'jump', 'an object { coyote, used }') ?? {}); jo.coyote = j.coyote; jo.used = j.used;
397
+ const g = this.safeGround; if (g) { const a = Array.isArray(out.safe) ? out.safe : (out.safe = badField(out.safe, 'safe', 'an array [x, y, z]') ?? [0, 0, 0]); a[0] = g.x; a[1] = g.y; a[2] = g.z; } else out.safe = null;
304
398
  out.support = stateOf(this).on?.id ?? null;
305
399
  return out;
306
400
  }
@@ -310,7 +404,7 @@ export class Character {
310
404
  this.velocity.set(m.vx ?? 0, m.vz ?? 0); this.vy = m.vy ?? 0; this.facing = m.facing ?? 0; this.root.rotation.y = this.facing;
311
405
  this.moveAmount = m.amount ?? 0; this.grounded = m.grounded ?? true; this.swimming = !!m.swimming;
312
406
  const j = jumpOf(this); j.coyote = m.jump?.coyote ?? 0; j.used = m.jump?.used ?? 0; j.buffer = 0;
313
- this.safeGround = m.safe ? new THREE.Vector3(m.safe[0], m.safe[1], m.safe[2]) : this.safeGround;
407
+ this.safeGround = (Array.isArray(m.safe) && m.safe.length === 3 && m.safe.every(Number.isFinite)) ? new THREE.Vector3(m.safe[0], m.safe[1], m.safe[2]) : this.safeGround;
314
408
  // ride the saved support again (found by id) from its current matrix; no support id = rides nothing
315
409
  detach(this);
316
410
  const en = m.support != null ? registry(this.engine).list.get(m.support) : null;
@@ -320,14 +414,14 @@ export class Character {
320
414
  /** Play a one-shot action (e.g. 'wave', returns to the previous state when done); procedural characters have no actions, warn once and skip */
321
415
  playAction(name) {
322
416
  if (this.anim) this.anim.action(name);
323
- else warnOnce(STRINGS.noClip.replace('{name}', name));
417
+ else warnOnce(fmt(STRINGS.noClip, { name: String(name) }));
324
418
  }
325
419
 
326
420
  /** Ground type under the feet (terrain groundType or level material name); 'water' while swimming. Footstep sounds map it via audio.footsteps */
327
421
  groundType() {
328
422
  if (this.swimming) return 'water';
329
423
  const p = this.root.position;
330
- return this.engine.groundType(p.x, p.z);
424
+ return this.engine.groundType(p.x, p.z, p.y);
331
425
  }
332
426
 
333
427
  /**
@@ -346,15 +440,16 @@ export class Character {
346
440
  * or adjust bones on top of the pose. Returns a handle; h.remove() stops it. Presentation only: never read it for gameplay timing.
347
441
  * @param {(character: Character, dt: number) => void} fn
348
442
  * @returns {{ remove(): void }}
349
- * @example const h = player.onPose(() => sword.position.copy(player.object.getObjectByName('Hand_R').getWorldPosition(v)));
443
+ * @example const h = player.onPose(() => sword.position.copy(player.root.getObjectByName('Hand_R').getWorldPosition(v)));
350
444
  */
351
445
  onPose(fn) { (this._poseFns ??= new Set()).add(fn); return { remove: () => this._poseFns.delete(fn) }; }
352
446
  /** @internal */
353
447
  _firePose(dt) { if (this._poseFns?.size) for (const f of [...this._poseFns]) { try { f(this, dt); } catch (err) { reportError(this.engine, err, 'character.onPose callback'); } } }
354
448
  /** @internal Call every frame: play animation, at the speed of the character's time channel (bullet time on 'enemies' slows their walk cycle too) */
355
449
  animate(dt) {
356
- if (this.engine.time) dt *= this.engine.time.scale(this.channel, this.modId);
357
- this._animate(dt); if (!this.anim) this._firePose(dt);
450
+ dt *= this.engine.still ? 0 : this.engine.time.scale(this.channel, this.id);
451
+ if (!this.limp) this._animate(dt);
452
+ if (!this.anim) this._firePose(dt);
358
453
  }
359
454
  /** @internal */
360
455
  _animate(dt) {
@@ -362,7 +457,8 @@ export class Character {
362
457
  this.phase += dt * (2.2 + sp * 1.25);
363
458
  const s = Math.sin(this.phase);
364
459
  // footstep event: fires once per foot landing (swing direction flips); model and procedural animation share this rhythm
365
- if (this.onStep && this.grounded && sp > 0.4 && Math.sign(s) !== Math.sign(this._lastS ?? s)) this.onStep(this.groundType());
460
+ // the payload stays { character }: a crowd of NPCs steps all the time, and only a listener that wants the ground should pay for reading it
461
+ if (this.grounded && sp > 0.4 && Math.sign(s) !== Math.sign(this._lastS ?? s)) this.engine.events.emit('character:step', { character: this });
366
462
  this._lastS = s;
367
463
  if (this.anim) {
368
464
  const a = this.anim;