threedog 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
@@ -0,0 +1,72 @@
1
+ // Built-in NPC behaviors: schedule (go to each stop by schedule), wander (roam near home).
2
+ // Behavior = { near(rec, dt, npc), far(rec, dt) }, registered by engine.npcs.behavior(name, …) and selected by behavior in NPC data (see NPC.js).
3
+ // Like npcSim.js it keeps no state of its own: wander target and pause live in rec.mind (plain values), so it continues after model teardown or loading.
4
+ import { warnOnce } from '../../core/validate.js';
5
+ import { advance, nearStep, goTo, settle } from './npcSim.js';
6
+
7
+ const NO = 'no NPC behavior named "{name}". Registered: {known}. Register a custom behavior first: engine.npcs.behavior("{name}", { near(rec, dt, npc) { … }, far(rec, dt) { … } })';
8
+ const noBehavior = (name, map) => NO.replace(/\{name\}/g, name).replace('{known}', [...map.keys()].join(', '));
9
+
10
+ /** Behavior registry: name -> { near, far } (code, not saved; data only stores the name) */
11
+ export class Behaviors extends Map {
12
+ /** Throw if the name is not registered, listing the registered ones */
13
+ check(name) { if (!this.has(name)) throw new Error(noBehavior(name, this)); }
14
+ /** The behavior this record uses now; if the name is not registered (game has not registered it after loading), warn once and skip */
15
+ of(rec) { const b = this.get(rec.behavior); if (!b) warnOnce(noBehavior(rec.behavior, this)); return b; }
16
+ addBuiltin(e, W) { for (const [n, b] of Object.entries(builtinBehaviors(e, W))) this.set(n, b); }
17
+ }
18
+
19
+ /** Built-in behaviors (e = engine, W = engine.world): { schedule, wander }, registered in npcs.setup */
20
+ function builtinBehaviors(e, W) {
21
+ // schedule: near walks to the current stop by pathfinding, far walks in a straight line (details in npcSim.js)
22
+ const scheduleFar = (rec, dt) => advance(e, W, rec, dt);
23
+ const schedule = {
24
+ near: (rec, dt, npc) => { const ch = npc.character; if (ch) nearStep(e, W, rec, ch, dt); else scheduleFar(rec, dt); },
25
+ far: scheduleFar,
26
+ };
27
+ // Wander params (all in rec.mind, can be passed in add / setBehavior): radius max distance from home in meters, pause how long to wait after arriving ([min, max] seconds), home { x, z } (omitted = where it stood when wandering started)
28
+ const radiusOf = m => m.radius ?? 8;
29
+ const pauseOf = (e, m) => { const [a, b] = m.pause ?? [2, 6]; return e.random.range(a, b); };
30
+ const pick = (e, m) => { // pick a point uniformly in the circle around home (sqrt keeps points from clustering at the center)
31
+ const r = radiusOf(m) * Math.sqrt(e.random.next()), a = e.random.next() * Math.PI * 2;
32
+ return { x: m.home.x + Math.cos(a) * r, z: m.home.z + Math.sin(a) * r };
33
+ };
34
+ const homeOf = (rec, m) => { m.home ??= { x: rec.position.x, z: rec.position.z }; };
35
+
36
+
37
+ // wander: pick a random point near home, walk there, pause, pick the next. Randomness uses engine.random (same seed, same result, saved)
38
+ const wanderFar = (rec, dt) => {
39
+ const m = rec.mind;
40
+ if (!(dt > 0)) return;
41
+ homeOf(rec, m);
42
+ let x = rec.position.x, z = rec.position.z, left = dt, moving = false, guard = 0;
43
+ for (; left > 1e-9 && guard < 16; guard++) {
44
+ if (m.wait > 0) { const w = Math.min(m.wait, left); m.wait -= w; left -= w; moving = false; continue; }
45
+ if (!m.target) m.target = pick(e, m);
46
+ const dx = m.target.x - x, dz = m.target.z - z, d = Math.hypot(dx, dz), t = d / rec.speed;
47
+ if (t <= left) { x = m.target.x; z = m.target.z; left -= t; m.target = null; m.wait = pauseOf(e, m); moving = false; }
48
+ else { x += dx / d * rec.speed * left; z += dz / d * rec.speed * left; left = 0; moving = true; }
49
+ }
50
+ if (left > 1e-9) { const p = pick(e, m); x = p.x; z = p.z; m.target = null; m.wait = 0; moving = false; } // owed time too long (many round trips): land directly at some point in the circle
51
+ settle(e, W, rec, x, z, moving);
52
+ };
53
+ const wander = {
54
+ near: (rec, dt, npc) => {
55
+ const ch = npc.character, m = rec.mind;
56
+ if (!ch) return wanderFar(rec, dt); // model not built yet: walk by data first
57
+ homeOf(rec, m);
58
+ let goal = null;
59
+ if (!rec.busy) {
60
+ if (m.wait > 0) m.wait -= dt;
61
+ else {
62
+ if (!m.target) m.target = pick(e, m);
63
+ if (Math.hypot(m.target.x - ch.root.position.x, m.target.z - ch.root.position.z) < rec.arriveDistance) { m.target = null; m.wait = pauseOf(e, m); }
64
+ else goal = m.target;
65
+ }
66
+ }
67
+ goTo(e, W, rec, ch, goal, dt);
68
+ },
69
+ far: wanderFar,
70
+ };
71
+ return { schedule, wander };
72
+ }
@@ -0,0 +1,13 @@
1
+ // Built-in footstep synth and the ground-type -> sound-name lookup (split out of index.js)
2
+ // Built-in footstep synth, silent until the game names it: sounds: { 'step.grass': { synth: 'footstep', params: { surface: 'grass' } } }.
3
+ // params: surface (a key of STEP_SYNTH or params.surfaces), volume, surfaces ({ mud: [filter, Hz, volume, seconds] } to add or retune one)
4
+ const STEP_SYNTH = { grass: ['bandpass', 900, 0.08, 0.12], sand: ['lowpass', 1400, 0.1, 0.14], rock: ['bandpass', 2400, 0.05, 0.1], snow: ['lowpass', 900, 0.12, 0.16], water: ['bandpass', 600, 0.15, 0.18] };
5
+ export function footstepSynth(audio, params, out) {
6
+ const table = { ...STEP_SYNTH, ...(params.surfaces || {}) };
7
+ const p = table[params.surface] || table.grass;
8
+ // presentation: random footstep pitch
9
+ audio.noiseBurst({ type: p[0], freq: p[1] * params.pitch * (0.9 + Math.random() * 0.2), vol: p[2] * (params.volume ?? 1), dur: p[3], out });
10
+ return p[3] + 0.05;
11
+ }
12
+ /** Sound name for a ground type: the game's createEngine({ audio: { footsteps } }) map, then its default, then 'footstep' */
13
+ export const stepSound = (e, type) => { const m = e.audio.config.footsteps; return m[type] ?? m.default ?? 'footstep'; };
@@ -0,0 +1,215 @@
1
+ // Characters module: player (keyboard/stick control, camera follow, footsteps, enter/exit vehicles) and NPCs (schedule, pathfinding, dialogue).
2
+ // The only pathfinding entry is engine.characters.findPath: uses the navmesh if nav is installed and ready, else A* (astar.js is an internal fallback, not
3
+ // exported).
4
+ // NPC facts live in engine.world (kind 'npc'), the model is just a presentation when near (see the top of NPC.js): NPCs need world() installed (openWorld
5
+ // already does).
6
+ // The player is also a world record (id / kind both 'player'): position, facing, motion state and current vehicle live in the record and are saved with world;
7
+ // world splits near / far by it by default.
8
+ // Only the mover changes the player's position (Character.move / placeAt / enter / exit), then writes back to the record; loading places the player back by the
9
+ // record. So install world() before creating the player.
10
+ // Vehicles are used through an interface (the { object, speed, drive(), seatPosition(), exitPosition() } returned by rigid.addVehicle); rigid is not imported
11
+ // here.
12
+ import { Character, CHARACTER_KEYS } from './Character.js';
13
+ import { NPCManager, NPC } from './NPC.js';
14
+ import { findPath } from './astar.js';
15
+ import { findSpawn, moveInput } from './moveHelpers.js';
16
+ import { AsyncPaths } from './pathAsync.js';
17
+ import { checkOptions, warnOnce, DEV } from '../../core/validate.js';
18
+ import { readParams, keysSchema } from '../../core/params.js';
19
+ import { codedError, coded } from '../../core/errorHints.js';
20
+ import { DEV_STRINGS, STRINGS, validControl } from './playerStrings.js';
21
+ import { footstepSynth, stepSound } from './footsteps.js';
22
+ import { xzOf } from '../../core/math.js';
23
+ export { Character, NPC };
24
+
25
+ /**
26
+ * Characters module. Once installed:
27
+ * engine.characters.createPlayer({ spawn: {x, z}, colors, model, clips }) → player
28
+ * engine.npcs.add({ id, name, schedule, talk, ... }) → NPC handle (needs npcs: true, on by default; data lives in engine.world)
29
+ * engine.npcs.remove(npc or name); engine.characters.removePlayer()
30
+ * three.js object of player and NPC: .object (= .root, Group), position .position (Vector3); spawn / position accept a Vector3 directly
31
+ * When an NPC is far it has no model: npc.root is null, npc.position is the data position
32
+ */
33
+ const PLAYER = 'player';
34
+
35
+
36
+
37
+ /** Navmesh when ready, else A* (characters.findPath; the one synchronous A* entry, see R20) */
38
+ function solvePath(e, from, to, o) {
39
+ const { detailed, ...rest } = o;
40
+ let res;
41
+ if (e.nav?.ready) res = e.nav.findPath(from, to, { ...rest, detailed: true });
42
+ else if (!e.collision) res = { status: 'notReady', path: null };
43
+ else {
44
+ const [sx, sz] = xzOf(from), [gx, gz] = xzOf(to), radius = rest.radius ?? e.movement.radius;
45
+ const path = findPath((x, z) => e.collision.walkableAt(x, z, radius), sx, sz, gx, gz, { ...rest, radius });
46
+ // nav installed but not ready: A* is only a stand-in, tell the caller honestly
47
+ res = { status: e.nav ? 'notReady' : path ? 'ok' : 'noPath', path };
48
+ }
49
+ return detailed ? res : res.path;
50
+ }
51
+
52
+ const CHARACTERS_PARAMS = keysSchema(['npcs', 'brakeKeys', 'brakePad']);
53
+
54
+ export function characters(opts = {}) {
55
+ readParams('characters', CHARACTERS_PARAMS, opts);
56
+ const { npcs = true, brakeKeys, brakePad } = opts; // no brake key by default: characters({ ...presets.keys.brake }) or the game's own
57
+ let mgr = null, paths = null, disposePlayer = null;
58
+ return {
59
+ name: 'characters', params: CHARACTERS_PARAMS, options: opts, label: 'Characters', noSkip: 'fixed only flushes path requests; schedules read the sky clock', optional: ['cameraRig', 'sky', 'interactions', 'dialogue', 'nav', 'collision', 'rigid', 'world'],
60
+ install(e) {
61
+ e.i18n.add(STRINGS);
62
+ e.audio.register('footstep', footstepSynth, { builtIn: true });
63
+ if (npcs) { mgr = new NPCManager(e); e.npcs = mgr; }
64
+ paths = new AsyncPaths(e);
65
+ e.events.on('ground:change', b => paths.dropTiles(b)); // dug or raised ground: resample the path rasters there
66
+ e.events.on('level:loaded', () => paths.tiles.clear()); // another level: none of the cached rasters describe it
67
+ const api = {
68
+ /**
69
+ * Find a spawn point: spiral outward from position (default origin) for walkable ground (no obstacles, gentle slope) that is not in water. Returns a
70
+ * Vector3 (y is ground height).
71
+ * Assumes no terrain: height range minH / maxH is unbounded by default (open worlds pass their own to avoid beaches and peaks); waterMargin minimum
72
+ * height above water in meters (default 0.5)
73
+ */
74
+ findSpawn(position = { x: 0, z: 0 }, opts = {}) { return findSpawn(e, position, opts); },
75
+ /**
76
+ * Pathfinding (the only entry): navmesh if nav is ready, else A* (needs the collision module). Returns [{ x, z }…], null if unreachable.
77
+ * Pass { detailed: true } to get { status, path }: 'ok' found | 'noPath' unreachable | 'notReady' nav installed but mesh not generated yet (path is the
78
+ * A* fallback, may be inaccurate; null without collision)
79
+ */
80
+ findPath(from, to, o = {}) { return solvePath(e, from, to, o); },
81
+ /**
82
+ * findPath for many callers (NPC crowds, AI squads): solved in engine.threads workers, done(path, status) runs on a fixed step ~4 steps later
83
+ * via engine.commits, so threads on / off give the same paths. Keep findPath for the few that need a path now (click-to-move). Details: recipe 12
84
+ * section 4.
85
+ * @param {any} from
86
+ * @param {any} to
87
+ * @param {(path: { x: number, z: number }[] | null, status: 'ok' | 'noPath' | 'notReady') => void} done
88
+ * @param {{ radius?: number, step?: number, maxNodes?: number }} [opts]
89
+ * @returns {{ cancel: () => void }}
90
+ * @example const req = engine.characters.findPathAsync(guard.position, target, (path, status) => { guard.path = path; });
91
+ * req.remove(); // target changed before the answer came
92
+ */
93
+ findPathAsync(from, to, done, opts) { return paths.request(from, to, done, opts); },
94
+ /** How many findPathAsync requests leave per fixed step (default 32); the rest wait for the next steps */
95
+ get pathsPerStep() { return paths.perStep; },
96
+ set pathsPerStep(n) { paths.perStep = Math.max(1, n | 0); },
97
+ /**
98
+ * The 'camera' player control as a value: movement keys / stick relative to the camera (world axes, up = -Z, without a camera module), the 'run' action
99
+ * when the game bound one, input.autopilot.
100
+ * Returns a reused { x, z, run, speed } (do not keep it). Call it from your own control function to wrap the default instead of rewriting it
101
+ * @example createPlayer({ ...presets.player.thirdPerson, control: (p, input) => busy ? null : engine.characters.moveInput() }) // no movement while
102
+ * attacking
103
+ */
104
+ moveInput() { return moveInput(e); },
105
+ /**
106
+ * Remove the current player (exit the vehicle first, stop responding to keys, dispose the model: animation, geometry, materials; the 'player' record in
107
+ * world is removed too)
108
+ */
109
+ removePlayer() { disposePlayer?.(); disposePlayer = null; },
110
+ /**
111
+ * Create the player. The engine assumes no feel: control is required, keys and camera follow come only from options (presets.player.* bundle them).
112
+ * The player is also the world record with id 'player' (needs the world module).
113
+ * Without spawn and with an existing player record in world (loaded before the player was created) it continues from the record's position; move the
114
+ * player with player.placeAt(position)
115
+ * control (required; also the plain property player.control, switch it at any time) decides who moves the player each fixed step:
116
+ * 'camera' moveInput(): movement keys relative to the camera, plus the jump key and vehicle driving
117
+ * function (player, input, dt) => ({ x, z, run?, speed? }) | null: you decide direction and speed (null = stand still); jump key and vehicles stay.
118
+ * Side-scroller: return { x: input.axis.x, z: 0 }
119
+ * 'none': the engine never moves the player; call player.move(x, z, run, dt) yourself once per fixed step (rolls, attack lunges, hit stun)
120
+ * runKeys / jumpKeys bind the 'run' / 'jump' actions (no keys are bound otherwise; player.jump() still works); cameraFollow: true points the camera
121
+ * module at the player (and back after a vehicle)
122
+ * The world record, saving and describe().player work the same for every control
123
+ * @example const player = engine.characters.createPlayer({ ...presets.player.thirdPerson, spawn: engine.characters.findSpawn() })
124
+ * @example const player = engine.characters.createPlayer({ ...presets.player.none, cameraFollow: true }); engine.onFixed(dt => player.move(0, 0, false,
125
+ * dt))
126
+ */
127
+ createPlayer(opts = {}) {
128
+ checkOptions('characters.createPlayer()', opts, [...CHARACTER_KEYS, 'spawn', 'jumpKeys', 'runKeys', 'control', 'cameraFollow']);
129
+ const control = opts.control;
130
+ if (control === undefined) throw codedError('player-control', DEV_STRINGS.noControl);
131
+ if (!validControl(control)) throw codedError('player-control', DEV_STRINGS.badControl.replace('{got}', JSON.stringify(control) ?? String(control)));
132
+ const W = e.world;
133
+ if (!W) throw new Error(DEV_STRINGS.noWorld);
134
+ // vehicle id saved in the player record; a number is a save from before vehicles had ids (the index in rigid.vehicles)
135
+ const vehicleOf = v => v == null ? null : typeof v === 'number' ? (v >= 0 ? e.rigid?.vehicles[v] ?? null : null) : e.rigid?.vehicles.find(c => c.id === v) ?? null;
136
+ disposePlayer?.(); // existing player: dispose the old one first (else two characters respond to keys)
137
+ const p = new Character(e, opts), had = W.get(PLAYER);
138
+ p.control = control;
139
+ p.cameraFollow = !!opts.cameraFollow; // read again on vehicle exit and a new session (Character.js, camera/common.js)
140
+ if (DEV && opts.cameraFollow === undefined && e.cameraRig) warnOnce(coded('player-control', DEV_STRINGS.noFollow));
141
+ if (!had) W.add({ id: PLAYER, kind: PLAYER, position: [0, 0, 0], vehicle: null });
142
+ // place the player by the record (loading, reusing an existing record): do not write back to the record while placing, write once afterwards so
143
+ // record and character agree
144
+ const apply = rec => {
145
+ const car = vehicleOf(rec.vehicle), { x, y, z } = rec.position;
146
+ p.recordId = null;
147
+ if (p.vehicle && p.vehicle !== car) p.exit(); // when loading a walking save, exit the vehicle first, else every step pulls it back to the seat
148
+ p.root.position.set(x, y, z); p.loadMotion(rec);
149
+ if (car && p.vehicle !== car) p.enter(car);
150
+ p.recordId = PLAYER; p._store();
151
+ };
152
+ if (had && !opts.spawn) apply(had);
153
+ else { p.recordId = PLAYER; p.placeAt(opts.spawn || api.findSpawn()); }
154
+ p.addTo();
155
+ p.onStep = type => e.audio.sfx(stepSound(e, type));
156
+ p.onLand = impact => { if (impact > 3) e.audio.sfx(stepSound(e, p.groundType()), { volume: Math.min(2, impact / 6) }); };
157
+ // the game's keys only: no Space-to-jump or Shift-to-run unless it (or a preset it picked) asked
158
+ if (p.canJump && opts.jumpKeys) { e.input.define('jump', opts.jumpKeys, 'input.jump'); e.input.touchButton('jump', 'input.jump'); }
159
+ if (opts.runKeys) e.input.define('run', opts.runKeys, 'input.run');
160
+ // brake: a separate action, only when the game gives keys (characters({ brakeKeys, brakePad }) or presets.keys.brake: B / gamepad LT), does not
161
+ // compete with jump on space. Registered only when driving is possible (rigid installed)
162
+ if (e.rigid && (brakeKeys || brakePad)) e.input.define('brake', brakeKeys ?? [], 'input.brake', { pad: brakePad, context: 'vehicle' });
163
+ e.player = p;
164
+ if (p.cameraFollow) e.cameraRig?.follow(p.root);
165
+ // gameplay keys are read in the fixed step (input snapshot, frame-rate independent); frame only plays animation
166
+ const fixedHook = e.onFixed(dt => {
167
+ const c = p.control;
168
+ if (c === 'none') return; // the game drives the player itself: no key reads, no move
169
+ // player.control set to a bad value at runtime
170
+ if (!validControl(c)) { warnOnce(coded('player-control', DEV_STRINGS.badControl.replace('{got}', JSON.stringify(c) ?? String(c)))); return; }
171
+ const has = a => e.input.actions.has(a); // keys the game bound; an unbound action is simply not used
172
+ // when the interactions module is installed, the vehicle's "exit" interaction handles it
173
+ if (p.vehicle) { if (!e.interactions && has('interact') && e.input.pressed('interact')) p.exit(); }
174
+ else if (p.canJump && has('jump') && e.input.pressed('jump')) p.jump();
175
+ if (p.vehicle) { const a = e.input.autopilot || e.input.axis; p.vehicle.drive(a.y, a.x, e.input.actions.has('brake') && e.input.down('brake') ? 1 : 0); }
176
+ const m = c === 'camera' ? api.moveInput() : c(p, e.input, dt);
177
+ p.move(m?.x ?? 0, m?.z ?? 0, !!m?.run, dt, m?.speed);
178
+ });
179
+ const frameHook = e.onFrame(dt => p.animate(dt));
180
+ // record the stable id of the vehicle the player is in (world.set: world:change fires; it follows an enter / exit that already happened)
181
+ const setCar = id => e.ops.allow(() => W.set(PLAYER, { vehicle: id }));
182
+ const onCar = e.events.on('vehicle:enter', ({ character }) => { if (character === p) setCar(p.vehicle?.id ?? null); });
183
+ const offCar = e.events.on('vehicle:exit', ({ character }) => { if (character === p) setCar(null); });
184
+ // loading: after world is replaced wholesale, place the player back by the record; if the save has no player record (saved before the player was
185
+ // created), add one from the current state
186
+ const onLoad = e.events.on('world:load', () => {
187
+ const rec = W.get(PLAYER);
188
+ if (rec) apply(rec);
189
+ else { W.add({ id: PLAYER, kind: PLAYER, position: p.position, vehicle: null }); p._store(); }
190
+ });
191
+ disposePlayer = () => {
192
+ fixedHook.remove(); frameHook.remove(); onCar.remove(); offCar.remove(); onLoad.remove();
193
+ p.recordId = null; p.dispose(); W.remove(PLAYER);
194
+ if (e.player === p) e.player = null;
195
+ };
196
+ return p;
197
+ },
198
+ };
199
+ return api;
200
+ },
201
+ // NPC simulation and animation are driven by world (simulate / present update); here we only register with world at start; without world, wait for the
202
+ // first npcs.add and then report the error
203
+ init(e) { if (mgr && e.world) mgr.setup(); },
204
+ fixed() { paths.flush(); },
205
+ describe(e, ctx) {
206
+ // with a model report by the model (merged with interaction points and world's own report for the same object into one), without a model report by data
207
+ // position
208
+ for (const r of mgr && e.world ? e.world.query({ kind: 'npc', near: ctx.center, radius: ctx.radius, where: r => e.world.zone == null || r.zone == null || r.zone === e.world.zone }) : []) {
209
+ ctx.near(e.world.view(r.id) ?? r.position, { id: r.id, name: r.name, kind: 'npc', state: r.state });
210
+ }
211
+ if (ctx.out.player) Object.assign(ctx.out.player, { swimming: e.player.swimming, grounded: e.player.grounded, facing: Math.round(e.player.facing * 100) / 100,
212
+ control: typeof e.player.control === 'function' ? 'custom' : e.player.control, faceMode: e.player.faceMode, mover: e.player.mover.name, ...(e.player.anim && { anim: e.player.anim.describe() }), ...(e.player.vehicle && { vehicle: { speed: Math.round(e.player.vehicle.speed * 10) / 10 } }) });
213
+ },
214
+ };
215
+ }
@@ -0,0 +1,29 @@
1
+ // Spawn search and the camera-relative move input (split out of index.js; the characters API calls these with its engine)
2
+ import * as THREE from 'three';
3
+ import { xzOf } from '../../core/math.js';
4
+ import { checkOptionsArg } from '../../core/validate.js';
5
+
6
+ const REQ = { x: 0, z: 0, run: false, speed: undefined }; // moveInput() result, reused every step (no allocation)
7
+
8
+ /** Spiral outward from position for walkable dry ground (characters.findSpawn) */
9
+ export function findSpawn(e, position, opts) {
10
+ const [x, z] = xzOf(position);
11
+ checkOptionsArg('characters.findSpawn()', opts, ['minH', 'maxH', 'maxSlope', 'waterMargin']);
12
+ const { minH = -Infinity, maxH = Infinity, maxSlope = 0.3, waterMargin = 0.5 } = opts;
13
+ for (let r = 0; r < 4000; r += 6) {
14
+ const a = r * 0.37, px = x + Math.cos(a) * r, pz = z + Math.sin(a) * r, h = e.surface(px, pz);
15
+ const dry = h > e.waterAt(px, pz) + waterMargin, walk = !e.collision || e.collision.walkableAt(px, pz);
16
+ if (dry && h > minH && h < maxH && e.slope(px, pz) < maxSlope && walk) return new THREE.Vector3(px, h, pz);
17
+ }
18
+ return new THREE.Vector3(x, e.surface(x, z), z);
19
+ }
20
+
21
+ /** The 'camera' player control as a value (characters.moveInput); returns the reused REQ */
22
+ export function moveInput(e) {
23
+ const inp = e.input, auto = inp.autopilot, a = auto || inp.axis; // autopilot (stress tests, recordings): input.autopilot = { x, y, speed }
24
+ const f = e.cameraRig ? e.cameraRig.forward() : { x: 0, z: -1 }, rt = e.cameraRig ? e.cameraRig.right() : { x: 1, z: 0 };
25
+ // run is the game's key, not a core default
26
+ REQ.x = f.x * a.y + rt.x * a.x; REQ.z = f.z * a.y + rt.z * a.x; REQ.run = inp.actions.has('run') && inp.down('run');
27
+ REQ.speed = auto?.speed; // autopilot can set a speed; without autopilot undefined = the character's own speed
28
+ return REQ;
29
+ }
@@ -0,0 +1,62 @@
1
+ // Shared by all movers: horizontal velocity smoothing, swim check, jump buffer and coyote time, landing, facing and action state.
2
+ // Used by simple.js (built-in) and rapier.js (Rapier character controller), so feel parameters (acceleration, air control, jump) match.
3
+ import { xzOf } from '../../../core/math.js';
4
+
5
+ /** Smooth horizontal velocity toward the target velocity (c.velocity x/y map to world x/z) */
6
+ export function steer(c, dirX, dirZ, run, dt, speedOverride) {
7
+ // push() overrides the requested direction for its duration (knockback, dodge displacement)
8
+ if (c._push > 0) { c._push -= dt; c.velocity.set(c._pushX, c._pushZ); return; }
9
+ const len = Math.hypot(dirX, dirZ);
10
+ let speed = speedOverride ?? (run ? c.runSpeed : c.speed);
11
+ if (c.swimming) speed *= c.swimSpeedFactor;
12
+ const tvx = len > 0.01 ? dirX * speed : 0, tvz = len > 0.01 ? dirZ * speed : 0;
13
+ const k = 1 - Math.exp(-dt * c.acceleration * (c.grounded || c.swimming ? 1 : c.airControl));
14
+ c.velocity.x += (tvx - c.velocity.x) * k; c.velocity.y += (tvz - c.velocity.y) * k;
15
+ }
16
+
17
+ /** Water: decide whether swimming (sets c.swimming); a non-swimmer is put back at (ox, oz). Returns { ground: ground height under the feet, swimY: body height when swimming } */
18
+ export function water(c, ox, oz) {
19
+ const e = c.engine, p = c.root.position;
20
+ let ground = e.surface(p.x, p.z, p.y); // pass the current height: walk the ground under a bridge, the deck on top
21
+ const swimY = e.waterAt(p.x, p.z) - c.swimDepth;
22
+ if (!c.canSwim && ground < swimY) { p.x = ox; p.z = oz; c.velocity.set(0, 0); ground = e.surface(ox, oz, p.y); } // cannot swim: no deep water
23
+ c.swimming = c.canSwim && ground < swimY && p.y <= swimY + 0.3;
24
+ return { ground, swimY };
25
+ }
26
+
27
+ /** Float on the water surface when swimming (gentle bob) */
28
+ export function float(c, swimY) { c.vy = 0; c.grounded = false; c.root.position.y = swimY + Math.sin(c.engine.elapsed * 2) * 0.05; }
29
+
30
+ /** Jump if requested and on the ground (or within coyote time after walking off an edge) */
31
+ export function tryJump(c) {
32
+ if (c._jumpBuffer > 0 && (c.grounded || c._coyote > 0)) {
33
+ c.vy = c.jumpSpeed; c.grounded = false; c._jumpBuffer = 0; c._coyote = 0;
34
+ c.engine.events.emit('character:jump', { character: c });
35
+ }
36
+ }
37
+
38
+ /** Landing: impact is the landing speed */
39
+ export function land(c, impact) {
40
+ c.vy = 0; c.grounded = true;
41
+ c.onLand?.(impact); c.engine.events.emit('character:land', { character: c, impact });
42
+ }
43
+
44
+ /** Angle the character wants to face by its faceMode; null = keep the current facing. While pushed it never turns (a knockback must not spin it round) */
45
+ function faceAngle(c, sp) {
46
+ if (c._push > 0 || c.faceMode === 'manual') return null;
47
+ if (c.faceMode === 'camera') { const f = c.engine.cameraRig?.forward(); if (f) return Math.atan2(f.x, f.z); }
48
+ else if (c.faceMode === 'target' && c.faceTarget) { const [x, z] = xzOf(c.faceTarget), p = c.root.position; return Math.atan2(x - p.x, z - p.z); }
49
+ return sp > 0.3 ? Math.atan2(c.velocity.x, c.velocity.y) : null;
50
+ }
51
+
52
+ /** Turn by faceMode (default: toward the move direction), update moveAmount and action state */
53
+ export function finish(c, dt) {
54
+ const sp = c.velocity.length(), want = faceAngle(c, sp);
55
+ if (want != null) {
56
+ let d = want - c.facing; d = Math.atan2(Math.sin(d), Math.cos(d));
57
+ c.facing += d * Math.min(1, dt * c.turnSpeed);
58
+ c.root.rotation.y = c.facing;
59
+ }
60
+ c.moveAmount = sp;
61
+ c.state = c.swimming ? 'swim' : !c.grounded ? (c.vy > 0 ? 'jump' : 'fall') : sp > c.speed * 1.3 ? 'run' : sp > 0.4 ? 'walk' : 'idle';
62
+ }
@@ -0,0 +1,74 @@
1
+ // Rapier character-controller mover (mover: 'rapier', needs the rigid module): real collision shapes, auto step-up, slope snapping.
2
+ // Feel parameters (speed, acceleration, jump, air control, swimming) match simple; while physics is not ready or the collision under the feet is not built, simple is used temporarily.
3
+ // Native objects: mover.controller (KinematicCharacterController), mover.body, mover.collider.
4
+ // The player uses rigid.playerBody / playerCollider (rigid syncs it to the player position each step); each NPC builds its own kinematic capsule.
5
+ import { steer, water, float, tryJump, land, finish } from './common.js';
6
+
7
+ /** Create the 'rapier' mover (c is the character, fallback is the simple mover used when not ready) */
8
+ export function rapierMover(c, fallback) {
9
+ const m = {
10
+ name: 'rapier', controller: null, body: null, collider: null,
11
+ move(dirX, dirZ, run, dt, speedOverride) {
12
+ const e = c.engine, r = e.rigid, p = c.root.position;
13
+ if (!r?.ready || !r.groundReady(p)) return fallback.move(dirX, dirZ, run, dt, speedOverride);
14
+ if (!m.controller) setup(e, r);
15
+ const col = m.collider, body = m.body.translation();
16
+ // teleported (placeAt, load, leaving a vehicle): first move the collider to the current position
17
+ if (Math.abs(body.x - p.x) + Math.abs(body.y - p.y) + Math.abs(body.z - p.z) > 0.3) {
18
+ m.body.setTranslation({ x: p.x, y: p.y, z: p.z }, true); r.world.propagateModifiedBodyPositionsToColliders();
19
+ }
20
+ steer(c, dirX, dirZ, run, dt, speedOverride);
21
+ const ox = p.x, oz = p.z;
22
+
23
+ // vertical intent: float to the surface when swimming, otherwise gravity + jump
24
+ c._jumpBuffer -= dt; c._coyote -= dt;
25
+ let dy;
26
+ if (c.swimming) dy = e.waterAt(p.x, p.z) - c.swimDepth - p.y;
27
+ else {
28
+ tryJump(c);
29
+ if (c.grounded && c.vy <= 0) { c.vy = 0; dy = 0; } // do not press down while standing (it would break auto step-up); downhill relies on ground snapping
30
+ else { c.vy += c.gravity * dt; dy = c.vy * dt; }
31
+ }
32
+ const wasGrounded = c.grounded;
33
+ m.controller.computeColliderMovement(col, { x: c.velocity.x * dt, y: dy, z: c.velocity.y * dt }, r.R.QueryFilterFlags.EXCLUDE_DYNAMIC | r.R.QueryFilterFlags.EXCLUDE_SENSORS);
34
+ const mv = m.controller.computedMovement();
35
+ p.x += mv.x; p.y += mv.y; p.z += mv.z;
36
+ // hit a wall (not stepping up): velocity becomes the wall-sliding velocity, so standing at a wall does not keep walking
37
+ const want = Math.hypot(c.velocity.x, c.velocity.y) * dt, got = Math.hypot(mv.x, mv.z);
38
+ if (wasGrounded && mv.y <= 1e-3 && got < want * 0.5) c.velocity.set(mv.x / dt, mv.z / dt);
39
+ const grounded = m.controller.computedGrounded();
40
+ if (c.vy > 0 && mv.y < dy * 0.5) c.vy = 0; // hit the ceiling
41
+
42
+ const { swimY } = water(c, ox, oz);
43
+ if (c.swimming) float(c, swimY);
44
+ else if (grounded && !wasGrounded && c.vy <= 0) land(c, -c.vy);
45
+ else if (!grounded && wasGrounded && c.vy <= 0) { c.grounded = false; c._coyote = c.coyoteTime; } // walked off an edge
46
+ else c.grounded = grounded;
47
+ if (m.body !== r.playerBody) m.body.setNextKinematicTranslation({ x: p.x, y: p.y, z: p.z });
48
+ finish(c, dt);
49
+ },
50
+ /** Called when the character is deleted: release the NPC's own capsule and controller */
51
+ dispose() {
52
+ const r = c.engine.rigid;
53
+ if (!m.controller) return;
54
+ r.world.removeCharacterController(m.controller);
55
+ if (m.body !== r.playerBody) r.world.removeRigidBody(m.body);
56
+ m.controller = m.body = m.collider = null;
57
+ },
58
+ };
59
+
60
+ function setup(e, r) {
61
+ const R = r.R, w = r.world, p = c.root.position;
62
+ if (c === e.player) { m.body = r.playerBody; m.collider = r.playerCollider; }
63
+ else {
64
+ const hh = r.playerCapsule.halfHeight;
65
+ m.body = w.createRigidBody(R.RigidBodyDesc.kinematicPositionBased().setTranslation(p.x, p.y, p.z));
66
+ m.collider = w.createCollider(R.ColliderDesc.capsule(hh, c.radius).setTranslation(0, hh + c.radius, 0), m.body);
67
+ }
68
+ const k = m.controller = w.createCharacterController(0.02);
69
+ k.enableAutostep(c.stepHeight, 0.15, false);
70
+ k.setMaxSlopeClimbAngle(Math.atan(e.collision?.maxClimb ?? e.movement.slopeRatio));
71
+ k.enableSnapToGround(c.stepHeight);
72
+ }
73
+ return m;
74
+ }
@@ -0,0 +1,43 @@
1
+ // Built-in mover (default): snap to ground height, step up within step height, back off slopes that are too steep, light collision push-out, swimming, jumping.
2
+ // Needs no physics engine, cheap on large maps.
3
+ import { steer, water, float, tryJump, land, finish } from './common.js';
4
+
5
+ /** Create the 'simple' mover (c is the character) */
6
+ export function simpleMover(c) {
7
+ return {
8
+ name: 'simple',
9
+ move(dirX, dirZ, run, dt, speedOverride) {
10
+ const e = c.engine, p = c.root.position;
11
+ steer(c, dirX, dirZ, run, dt, speedOverride);
12
+
13
+ const ox = p.x, oz = p.z, oh = e.surface(ox, oz, p.y);
14
+ p.x += c.velocity.x * dt; p.z += c.velocity.y * dt;
15
+ // back to the old position where it cannot climb: step up directly within step height; above that check the slope; hitting ground higher than itself in the air counts as a wall
16
+ const nh = e.surface(p.x, p.z, p.y), step = Math.hypot(p.x - ox, p.z - oz), maxClimb = e.collision?.maxClimb ?? e.movement.slopeRatio, rise = nh - Math.max(oh, c.grounded ? oh : p.y);
17
+ const blocked = c.grounded ? (rise > c.stepHeight && step > 1e-4 && (nh - oh) / step > maxClimb) : nh > p.y + c.stepHeight;
18
+ if (blocked) { p.x = ox; p.z = oz; c.velocity.set(0, 0); }
19
+ const col = e.collision;
20
+ if (col?._blocked.length && col.blockedAt(p.x, p.z, c.radius)) { // addBlocked ground (river): slide along it, else stay put
21
+ const nx = p.x, nz = p.z;
22
+ if (!col.blockedAt(nx, oz, c.radius)) p.z = oz; else if (!col.blockedAt(ox, nz, c.radius)) p.x = ox; else { p.x = ox; p.z = oz; c.velocity.set(0, 0); }
23
+ }
24
+ col?.resolve(p, c.radius);
25
+
26
+ const { ground, swimY } = water(c, ox, oz);
27
+
28
+ // vertical: gravity, jump, walking off an edge, landing
29
+ c._jumpBuffer -= dt; c._coyote -= dt;
30
+ if (c.swimming) float(c, swimY);
31
+ else {
32
+ if (c.grounded && ground < p.y - c.stepHeight) { c.grounded = false; c._coyote = c.coyoteTime; } // walked off an edge
33
+ tryJump(c);
34
+ if (c.grounded) { p.y = ground; c.vy = 0; }
35
+ else {
36
+ c.vy += c.gravity * dt; p.y += c.vy * dt;
37
+ if (p.y <= ground) { const impact = -c.vy; p.y = ground; land(c, impact); }
38
+ }
39
+ }
40
+ finish(c, dt);
41
+ },
42
+ };
43
+ }