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,129 @@
1
+ // NPC-vs-NPC avoidance (near NPCs, every fixed step, called from goTo): nearby NPCs push each other apart to at least the sum of their radii; the player is an
2
+ // obstacle (NPCs yield, the player is never pushed).
3
+ // Why it is written this way: a continuous run and a save-then-load of the same scenario must give bit-identical positions:
4
+ // 1. Each NPC pushes only itself and reads neighbours' positions as of the start of this step (stamped), so a neighbour that already moved this step does not
5
+ // matter and order is irrelevant;
6
+ // 2. Neighbour pushes are rounded before summing (neighbour iteration order changes after load; float addition order would differ in the last bit, integer
7
+ // addition does not);
8
+ // 3. No randomness, no state kept in data (start is a per-step scratch value, cleared on load).
9
+ // Push is capped (strength m/s * dt), stronger with more overlap, then constrained by engine.collision (if installed) so NPCs are not pushed into walls.
10
+ // With nav({ crowd: true }) the Recast agents decide and this adds nothing. Only near NPCs with a model; far NPCs are simulated from data without per-NPC
11
+ // avoidance (too costly).
12
+ import { checkOptions } from '../../core/validate.js';
13
+
14
+ const KEYS = ['on', 'radius', 'strength'];
15
+ // push direction is rotated ~25° to the right: two NPCs meeting head-on each swerve to their own right instead of deadlocking in a line
16
+ const COS = 0.906, SIN = 0.423;
17
+ const Q = 1048576; // rounding scale before summing (2^20)
18
+
19
+ const cellKey = (x, z) => (x + 1048576) * 2097152 + z + 1048576;
20
+
21
+ /**
22
+ * Push from one neighbour (offset (dx, dz) from me, distance d, wanted separation min), rounded and added to acc; exactly overlapping picks the direction by
23
+ * tie (±1)
24
+ */
25
+ function shove(acc, dx, dz, d, min, tie) {
26
+ // more overlap pushes harder, a light touch pushes gently: smooth
27
+ const w = Math.min(1, (min - d) / (0.5 * min)), ux = d > 1e-6 ? dx / d : tie, uz = d > 1e-6 ? dz / d : 0;
28
+ acc.x += Math.round((ux * COS - uz * SIN) * w * Q); acc.z += Math.round((ux * SIN + uz * COS) * w * Q);
29
+ }
30
+
31
+ /** @internal @internal Mounted on engine.npcs: engine.npcs.avoid = false | { radius, strength } */
32
+ export class NpcAvoid {
33
+ constructor(engine) {
34
+ this.engine = engine;
35
+ this.on = true; // switch (default on)
36
+ this.radius = null; // avoid radius per NPC (m); null = engine.movement.radius
37
+ this.strength = 3; // max push speed (m/s)
38
+ this._acc = { x: 0, z: 0 };
39
+ /** @internal ids of NPCs that have a model now (NPCManager keeps it): only they take part, so far NPCs cost nothing per step */ this.built = new Set();
40
+ this._ids = [];
41
+ this._start = new Map(); // id → { k: simulation step count, x, z }: position at the start of this step
42
+ // fine grid index for this step (cell size = min distance of two NPCs, query 3x3 cells): the world grid is 32 m per cell, so hundreds of NPCs in one or two
43
+ // cells would make per-pair distance checks too costly
44
+ this._gridN = -1; this._head = new Map(); this._next = new Int32Array(64); this._items = []; this._gx = new Float64Array(64); this._gz = new Float64Array(64);
45
+ engine.events.on('world:remove', ({ id }) => this._start.delete(id));
46
+ // after load the simulation step count returns to the saved value, so the old grid is stale
47
+ engine.events.on('world:load', () => { this._start.clear(); this._gridN = -1; });
48
+ }
49
+
50
+ /**
51
+ * Change settings: set(false) off, set(true) on, set({ radius, strength }) tune (pass only what changes; passing it means on). Read current values from on /
52
+ * radius / strength.
53
+ * @example engine.npcs.avoid.set({ radius: 0.6, strength: 2 }); // a bit sparser, pushed more slowly
54
+ * @param {boolean | { on?: boolean, radius?: number | null, strength?: number }} opts radius per-NPC avoid radius (m, null = engine.movement.radius),
55
+ * strength max push speed (m/s, default 3)
56
+ * @returns {this}
57
+ */
58
+ set(opts) {
59
+ this._gridN = -1;
60
+ if (typeof opts === 'boolean') { this.on = opts; return this; }
61
+ checkOptions('engine.npcs.avoid.set()', opts, KEYS);
62
+ this.on = opts.on ?? true;
63
+ if (opts.radius !== undefined) this.radius = opts.radius;
64
+ if (opts.strength !== undefined) this.strength = opts.strength;
65
+ return this;
66
+ }
67
+
68
+ /** This NPC's simulation step starts: record the start position (called from the near entry in NPC.js, before behaviours change the position) */
69
+ stamp(rec) {
70
+ if (!this.on) return;
71
+ const n = this.engine.world.steps, p = rec.position;
72
+ let s = this._start.get(rec.id);
73
+ if (!s) this._start.set(rec.id, s = { k: n, x: p.x, z: p.z });
74
+ else { s.k = n; s.x = p.x; s.z = p.z; }
75
+ }
76
+
77
+ /**
78
+ * On the first avoid of this step, put model-bearing NPCs into the fine grid by their step-start positions (each NPC then queries only the surrounding 3x3
79
+ * cells)
80
+ */
81
+ _build(W, n, min) {
82
+ const head = this._head, items = this._items, ids = this._ids;
83
+ ids.length = 0; for (const id of this.built) ids.push(id);
84
+ ids.sort(); // by id: model build order depends on frames, the push order must not
85
+ items.length = 0;
86
+ for (const id of ids) { const o = W.get(id); if (o && W.view(id)) items.push(o); }
87
+ head.clear(); this._gridN = n;
88
+ if (items.length > this._next.length) { this._next = new Int32Array(items.length * 2); this._gx = new Float64Array(items.length * 2); this._gz = new Float64Array(items.length * 2); }
89
+ for (let i = 0; i < items.length; i++) {
90
+ const o = items[i], s = this._start.get(o.id), q = s && s.k === n ? s : o.position, c = cellKey(Math.floor(q.x / min), Math.floor(q.z / min));
91
+ this._gx[i] = q.x; this._gz[i] = q.z;
92
+ this._next[i] = head.get(c) ?? -1; head.set(c, i);
93
+ }
94
+ }
95
+
96
+ /** Push ch (the rec's model) apart; call after ch.move, edits ch.root.position x, z directly */
97
+ push(rec, ch, dt) {
98
+ const e = this.engine, W = e.world;
99
+ if (!this.on || e.nav?.crowd) return;
100
+ const n = W.steps, own = this._start.get(rec.id), r = this.radius ?? e.movement.radius, min = 2 * r;
101
+ if (!own || own.k !== n) return; // did not enter via NPC.js (goTo called directly): no avoidance
102
+ if (this._gridN !== n) this._build(W, n, min);
103
+ const head = this._head, nx = this._next, items = this._items, gx = this._gx, gz = this._gz, min2 = min * min;
104
+ // accumulate integers: float addition depends on order and neighbour order changes after load; rounded integer addition is exact and order-independent
105
+ const acc = this._acc; acc.x = acc.z = 0;
106
+ const cx = Math.floor(own.x / min), cz = Math.floor(own.z / min);
107
+ for (let x = cx - 1; x <= cx + 1; x++) for (let z = cz - 1; z <= cz + 1; z++) {
108
+ for (let i = head.get(cellKey(x, z)) ?? -1; i >= 0; i = nx[i]) {
109
+ const o = items[i], dx = own.x - gx[i], dz = own.z - gz[i], d2 = dx * dx + dz * dz;
110
+ if (o === rec || d2 >= min2 || (o.zone != null && rec.zone != null && o.zone !== rec.zone)) continue;
111
+ shove(acc, dx, dz, Math.sqrt(d2), min, rec.id < o.id ? 1 : -1);
112
+ }
113
+ }
114
+ const pl = e.player;
115
+ if (pl?.root) { // the player is an obstacle: only the NPC yields, the player position belongs to the mover
116
+ const q = pl.root.position, m = r + (pl.radius ?? r), dx = own.x - q.x, dz = own.z - q.z, d = Math.hypot(dx, dz);
117
+ if (d < m) shove(acc, dx, dz, d, m, 1);
118
+ }
119
+ const ax = acc.x / Q, az = acc.z / Q;
120
+ const len = Math.sqrt(ax * ax + az * az);
121
+ if (!len) return;
122
+ const k = this.strength * dt / Math.max(1, len), p = ch.root.position;
123
+ const mx = ax * k, mz = az * k;
124
+ p.x += mx; p.z += mz;
125
+ // skip collision for pushes under half a centimetre (the mover keeps it out of walls next step); in a crowd every NPC is nudged every step, so this saves
126
+ // most collision queries
127
+ if (mx * mx + mz * mz > 2.5e-5) e.collision?.resolve(p, ch.radius);
128
+ }
129
+ }
@@ -0,0 +1,150 @@
1
+ // NPC simulation (gameplay logic, runs in world.simulate('npc')): pick a stop from the schedule; with a model, pathfind + move the model via the mover; without
2
+ // a model, walk in a straight line.
3
+ // Reads/writes only world data (plain objects) and the passed-in character (presentation), keeps no state of its own, because models are torn down when far and
4
+ // load replaces all data:
5
+ // state kept elsewhere (path, current stop, velocity) would go out of sync. It all lives in data (rec.nav, rec.motion), so after load the NPC continues exactly
6
+ // as if it had kept running.
7
+ // See the top of NPC.js for record fields.
8
+
9
+ /** Fixed steps an NPC waits for a findPathAsync answer before asking again (answers normally land 4 steps later; a long queue adds perStep batches) */
10
+ const PATH_WAIT = 300;
11
+
12
+ /**
13
+ * Which stop to go to now (index): the latest stop at or before time t (0-1); before the first stop counts as the previous day's last stop; null if no schedule
14
+ */
15
+ export function stopIndex(schedule, t) {
16
+ if (!schedule.length) return null;
17
+ let cur = schedule.length - 1;
18
+ for (let i = 0; i < schedule.length; i++) if (schedule[i].at <= t) cur = i;
19
+ return cur;
20
+ }
21
+ /** time of day: always 0 without sky (only the first stop is used) */
22
+ export const timeOfDay = e => e.sky ? e.sky.timeOfDay : 0;
23
+
24
+ /**
25
+ * Walk without a model (far, or near but model not built yet): head in a straight line to the current scheduled stop; stop at the stop if reached, otherwise at
26
+ * the interpolated point on the line.
27
+ * seconds seconds is the world simulation dt (accumulated fixed-step seconds, same scale as the near mover, may be large): distance = speed * seconds;
28
+ * when several stop-change times are crossed, walk in segments, each toward that segment's stop (day progress = seconds * clock.timeScale / dayLength, same as
29
+ * the sky clock).
30
+ */
31
+ export function advance(e, W, rec, seconds) {
32
+ const s = rec.schedule;
33
+ if (!s.length || !(seconds > 0)) return;
34
+ const p = rec.position;
35
+ let x = p.x, z = p.z;
36
+ const walk = (i, sec) => {
37
+ const g = s[i], dx = g.x - x, dz = g.z - z, d = Math.hypot(dx, dz), go = Math.min(d, rec.speed * sec);
38
+ if (d > 1e-9) { x += dx / d * go; z += dz / d * go; }
39
+ };
40
+ if (!e.sky) walk(stopIndex(s, 0), seconds);
41
+ else {
42
+ const perDay = e.sky.dayLength / e.clock.timeScale, now = e.sky.timeOfDay; // seconds for a full day (infinite when time is stopped: far NPCs do not walk)
43
+ let left = Math.min(1, seconds / perDay); // more than one day counts as one day: every stop is visited once, more would only repeat
44
+ let t = ((now - left) % 1 + 1) % 1;
45
+ for (let guard = 0; left > 1e-9 && guard <= s.length + 1; guard++) {
46
+ let next = Infinity; // next stop-change time after t (tomorrow's first stop if none left today)
47
+ for (const st of s) { const a = st.at > t ? st.at : st.at + 1; if (a < next) next = a; }
48
+ const seg = Math.min(left, next - t);
49
+ walk(stopIndex(s, t), seg * perDay);
50
+ // when landing exactly on a change time take that value, so float error does not leave it on the previous stop
51
+ left -= seg; t = seg === next - t ? next % 1 : t + seg;
52
+ }
53
+ }
54
+ const idx = stopIndex(s, timeOfDay(e)), g = s[idx];
55
+ rec.nav.stop = idx;
56
+ settle(e, W, rec, x, z, Math.hypot(g.x - x, g.z - z) > rec.arriveDistance);
57
+ }
58
+
59
+ /** Set rec.state; with events.traceSize > 0 a change is noted as an `npc:state` trace entry (from, to), so "why did it stop" has a cause chain */
60
+ function noteState(e, rec, next) {
61
+ if (rec.state !== next && e.events.traceSize > 0) e.events.note('npc:state', { obj: rec.id, data: { from: rec.state ?? null, to: next } });
62
+ rec.state = next;
63
+ }
64
+
65
+ /**
66
+ * Settle without a model: write the computed x, z back to data (position, facing, animation state); shared by every behaviour's far. The path is for the model,
67
+ * so it is re-found at the new position after the model is built
68
+ */
69
+ export function settle(e, W, rec, x, z, moving) {
70
+ const p = rec.position, nav = rec.nav; nav.path = null; nav.repath = 0;
71
+ const m = rec.motion ??= {};
72
+ const facing = x !== p.x || z !== p.z ? Math.atan2(x - p.x, z - p.z) : m.facing ?? 0;
73
+ Object.assign(m, { vx: 0, vz: 0, vy: 0, amount: 0, facing, grounded: true, swimming: false, coyote: 0 });
74
+ noteState(e, rec, moving ? 'walk' : 'idle');
75
+ // NPC of another level: this level's ground height is meaningless for it, keep its y
76
+ const here = rec.zone == null || W.zone == null || rec.zone === W.zone;
77
+ W.move(rec.id, { x, y: here ? e.surface(x, z) : p.y, z });
78
+ }
79
+
80
+ /**
81
+ * Near step of a schedule behaviour (every fixed step): pick the stop, goTo it, then copy position and motion state back to data.
82
+ */
83
+ export function nearStep(e, W, rec, ch, dt) {
84
+ const nav = rec.nav;
85
+ const idx = rec.busy ? nav.stop : stopIndex(rec.schedule, timeOfDay(e));
86
+ if (idx !== nav.stop) { nav.stop = idx; nav.path = null; nav.repath = 0; }
87
+ goTo(e, W, rec, ch, idx == null ? null : rec.schedule[idx], dt);
88
+ }
89
+
90
+ /**
91
+ * With a model, take one step toward goal ({ x, z }, null = stand): pathfind, move the model via the character's mover, then copy position and motion state
92
+ * back to data; shared by every behaviour's near.
93
+ * Standing when in conversation (rec.busy), arrived (distance < arriveDistance) or no goal.
94
+ * Pathfinding goes through the single entry engine.characters.findPath; a goal too far (>120 m) first walks straight 100 m, then pathfinds exactly, to avoid
95
+ * one huge search.
96
+ */
97
+ export function goTo(e, W, rec, ch, goal, dt) {
98
+ const nav = rec.nav, p = ch.root.position;
99
+ const dGoal = goal ? Math.hypot(goal.x - p.x, goal.z - p.z) : 0;
100
+ if (rec.busy || !goal || dGoal < rec.arriveDistance) ch.move(0, 0, false, dt);
101
+ else if (e.nav?.crowd) crowdMove(e, ch, goal, dt);
102
+ else {
103
+ nav.repath -= dt;
104
+ // goal changed while waiting, or the answer never came (engine.commits.invalidate dropped it: a partial saves.apply, a level change): ask again
105
+ if (ch._pathReq && (ch._pathReq.goal !== goal || e.tick - ch._pathReq.at > PATH_WAIT)) { ch._pathReq.remove(); ch._pathReq = null; }
106
+ if (!nav.path && nav.repath <= 0 && !ch._pathReq) {
107
+ const far = dGoal > 120, tx = far ? p.x + (goal.x - p.x) / dGoal * 100 : goal.x, tz = far ? p.z + (goal.z - p.z) / dGoal * 100 : goal.z;
108
+ // async: many NPCs repathing in one step cost the main thread almost nothing; the answer lands a few steps later (the NPC waits in place)
109
+ const req = ch._pathReq = e.characters.findPathAsync(p, { x: tx, z: tz }, path => {
110
+ if (ch._pathReq !== req) return;
111
+ ch._pathReq = null; nav.path = path || [{ x: tx, z: tz }];
112
+ }, { step: rec.pathStep });
113
+ req.goal = goal; req.at = e.tick;
114
+ nav.repath = rec.repath;
115
+ }
116
+ if (nav.path?.length) {
117
+ const wp = nav.path[0], dx = wp.x - p.x, dz = wp.z - p.z, d = Math.hypot(dx, dz);
118
+ if (d < 0.8) { nav.path.shift(); if (!nav.path.length) nav.path = null; }
119
+ else {
120
+ const ox = p.x, oz = p.z;
121
+ ch.move(dx / d, dz / d, false, dt);
122
+ if (Math.hypot(p.x - ox, p.z - oz) < 0.002 && ch.moveAmount < 0.2) nav.path = null; // stuck: re-pathfind
123
+ }
124
+ }
125
+ }
126
+ if (!e.nav?.crowd) e.npcs.avoid.push(rec, ch, dt); // keep clear of other NPCs and the player (with crowd, the agents handle it)
127
+ // position belongs to the mover: copy the model position back to data here (world also copies at the end of each fixed step; copying now means later
128
+ // simulation and saves this step see the latest)
129
+ rec.motion = ch.saveMotion(rec.motion ?? {});
130
+ noteState(e, rec, ch.state);
131
+ W.move(rec.id, p);
132
+ }
133
+
134
+ // Crowd avoidance (nav({ crowd: true })): Recast agents steer around other NPCs (smarter than the simple push in npcAvoid.js); the NPC reads the agent velocity
135
+ // and walks itself.
136
+ // The agent belongs to the model (stored on the character) and is deleted with it (dispose in NPC.js); the agent itself does not guarantee identical results
137
+ // after load.
138
+ function crowdMove(e, ch, goal, dt) {
139
+ const nav = e.nav, crowd = nav.crowd, p = ch.root.position;
140
+ // nav mesh was rebuilt: the old agent was destroyed with the old crowd
141
+ if (ch._agent && ch._navVersion !== nav.version) { ch._agent = null; ch._agentGoal = null; }
142
+ ch._navVersion = nav.version;
143
+ if (!ch._agent) ch._agent = crowd.addAgent({ x: p.x, y: p.y, z: p.z }, { radius: ch.radius, height: e.movement.height, maxSpeed: ch.speed, maxAcceleration: ch.acceleration * ch.speed });
144
+ const a = ch._agent;
145
+ if (ch._agentGoal !== goal) { a.requestMoveTarget({ x: goal.x, y: e.surface(goal.x, goal.z), z: goal.z }); ch._agentGoal = goal; }
146
+ const ap = a.position();
147
+ if (Math.hypot(ap.x - p.x, ap.z - p.z) > 1.5) a.teleport({ x: p.x, y: p.y, z: p.z }); // blocked and drifted too far: pull the agent back
148
+ const v = a.velocity(), sp = Math.hypot(v.x, v.z);
149
+ ch.move(sp > 0.05 ? v.x / ch.speed : 0, sp > 0.05 ? v.z / ch.speed : 0, false, dt);
150
+ }
@@ -0,0 +1,42 @@
1
+ // The model side of an NPC (split out of NPC.js): build the Character when the NPC comes near, tear it down when it goes far, start its dialogue.
2
+ // Plain functions that take the NPCManager; the manager keeps the maps (_views, _runtime) and avoid, these read and write them.
3
+ import { Character } from './Character.js';
4
+
5
+ /** Build the model: reads position, motion and animation state from data; attaches an interaction if it has dialogue */
6
+ export function buildNpcView(m, rec) {
7
+ const e = m.engine, rt = m._runtime.get(rec.id) || {};
8
+ const ch = new Character(e, { ...rec.look, speed: rec.speed, model: rt.model ?? rec.look?.model, clips: rt.clips, animation: rt.animation });
9
+ ch.placeAt(rec.position);
10
+ ch.loadMotion(rec.motion); ch.state = rec.state;
11
+ let talk = null;
12
+ if (rec.talk && e.interactions && e.dialogue) talk = e.interactions.add(ch.root, {
13
+ id: rec.id, // stable for the interaction.use op, whether the model is built sync or async
14
+ label: rt.talkLabel || rec.talkLabel || (() => e.t('npc.talk', { name: rec.name })), radius: rec.talkRadius,
15
+ onUse: () => talkToNpc(m, rec.id),
16
+ });
17
+ m._views.set(ch.root, { ch, talk });
18
+ m.avoid.built.add(rec.id);
19
+ return ch.root;
20
+ }
21
+
22
+ /** Tear down the model: interaction, crowd agent, animation, geometry; a model passed in by the game is kept (needed for the next build) */
23
+ export function unbuildNpcView(m, rec, obj) {
24
+ const e = m.engine, v = m._views.get(obj);
25
+ m._views.delete(obj);
26
+ if (rec) m.avoid.built.delete(rec.id);
27
+ if (!v) { e.remove(obj); return; }
28
+ const { ch, talk } = v;
29
+ talk?.remove();
30
+ if (ch._agent && ch._navVersion === e.nav?.version) e.nav.crowd?.removeAgent(ch._agent);
31
+ const model = rec && m._runtime.get(rec.id)?.model;
32
+ if (model && model.parent === ch.root) ch.root.remove(model);
33
+ ch.dispose();
34
+ }
35
+
36
+ /** Start dialogue: stop (busy written to data), face the player, walk on when dialogue ends */
37
+ function talkToNpc(m, id) {
38
+ const e = m.engine, W = m.world, rec = W.get(id); if (!rec) return;
39
+ W.set(id, { busy: true });
40
+ m.character(id)?.face(e.actorPosition() ?? e.focus);
41
+ e.dialogue.start(rec.talk, 'start', () => { if (W.get(id)) W.set(id, { busy: false }); });
42
+ }
@@ -0,0 +1,113 @@
1
+ // engine.characters.findPathAsync: many paths off the main thread, answered on a fixed step (part of the characters module).
2
+ // Requests queue up; each fixed step at most pathsPerStep of them leave as one batch (counted in requests, not milliseconds, so the result never depends on machine speed).
3
+ // A batch runs in an engine.threads lane (pathWorker.js) and lands PATH_LAG steps later through engine.commits; late or no workers -> the same
4
+ // solveBatch runs here at the due step. The batch is tagged with the walkable state it was computed on (navmesh revision or collision version);
5
+ // if that changed before it lands, it is recomputed here on the current state, so threads on / off / slow / crashed give identical paths.
6
+ import { xzOf } from '../../core/math.js';
7
+ import { solveBatch, pathHandler, astarDefaults, RES, TILE, tileOf } from './pathJob.js';
8
+
9
+ /** Steps between sending a batch and its answers taking effect (4 = 67 ms): enough for a worker round trip, short enough that an NPC barely waits */
10
+ const PATH_LAG = 4;
11
+ /** A cached ground raster tile is reused for this many fixed steps (5 s), then sampled again: streamed terrain may have added trees meanwhile */
12
+ const TILE_TTL = 300;
13
+ const NO_DONE = 'characters.findPathAsync(from, to, done): done must be a function (path, status) => { ... }; it runs on a fixed step when the path is ready';
14
+
15
+ /** @internal */
16
+ export class AsyncPaths {
17
+ constructor(e) {
18
+ this.e = e;
19
+ this.queue = [];
20
+ this.perStep = 32;
21
+ this.lane = null;
22
+ this.sent = { rev: -1, ver: -1 }; // what the workers mirror
23
+ this.tiles = new Map(); // 'tx:tz' -> { data, trees, at }
24
+ }
25
+ request(from, to, done, o = {}) {
26
+ if (typeof done !== 'function') throw new Error(NO_DONE);
27
+ const [sx, sz] = xzOf(from), [gx, gz] = xzOf(to);
28
+ const h = { sx, sz, gx, gz, o, done, canceled: false, remove() { h.canceled = true; } };
29
+ this.queue.push(h);
30
+ return h;
31
+ }
32
+ /** Which walkable state answers now: navmesh revision, collision version, or nothing */
33
+ key() { const e = this.e; return e.nav?.ready ? 'n' + e.nav.revision : e.collision ? 'g' + e.collision.version : '-'; }
34
+ /** End of each fixed step: send up to perStep queued requests as one batch */
35
+ flush() {
36
+ const list = [];
37
+ while (this.queue.length && list.length < this.perStep) { const h = this.queue.shift(); if (!h.canceled) list.push(h); }
38
+ if (!list.length) return;
39
+ const e = this.e, T = e.threads, batch = this.build(list);
40
+ const t = e.commits.request({ lag: PATH_LAG, fallback: () => null, apply: r => this.land(batch, list, r) });
41
+ if (!T.size || batch.key === '-') return;
42
+ this.mirror(batch.key);
43
+ this.lane.run(batch).then(r => t.resolve(r), () => {}); // a failed run is ignored: land() computes the same answer here
44
+ }
45
+ /** Plain-data batch: everything the solver needs that the worker does not mirror */
46
+ build(list) {
47
+ const e = this.e, key = this.key(), mode = key[0] === 'n' ? 'nav' : key[0] === 'g' ? 'grid' : 'none', tiles = {}, trees = [], seen = new Set();
48
+ const take = (tk, tx, tz) => {
49
+ if (tiles[tk]) return;
50
+ const c = this.tile(tk, tx, tz); tiles[tk] = c.data;
51
+ for (let i = 0; i < c.trees.length; i += 3) { const id = c.trees[i] + ',' + c.trees[i + 1]; if (!seen.has(id)) { seen.add(id); trees.push(c.trees[i], c.trees[i + 1], c.trees[i + 2]); } }
52
+ };
53
+ const reqs = list.map(({ sx, sz, gx, gz, o }) => {
54
+ if (mode === 'nav') return { mode, s: { x: sx, y: e.surface(sx, sz), z: sz }, g: { x: gx, y: e.surface(gx, gz), z: gz }, reach: e.nav.reach(o.radius) };
55
+ if (mode === 'none') return { mode };
56
+ const radius = o.radius ?? e.movement.radius, dflt = astarDefaults(radius), step = o.step ?? dflt.step, maxNodes = o.maxNodes ?? dflt.maxNodes;
57
+ // A* may wander this far beyond the start-goal box; bounded by how far maxNodes cells can reach
58
+ const m = Math.min(step * Math.sqrt(maxNodes / Math.PI), 16 + Math.hypot(gx - sx, gz - sz) / 2);
59
+ for (let tx = tileOf(Math.min(sx, gx) - m); tx <= tileOf(Math.max(sx, gx) + m); tx++)
60
+ for (let tz = tileOf(Math.min(sz, gz) - m); tz <= tileOf(Math.max(sz, gz) + m); tz++) take(tx + ':' + tz, tx, tz);
61
+ return { mode, s: { x: sx, z: sz }, g: { x: gx, z: gz }, radius, step, maxNodes, navPending: !!e.nav };
62
+ });
63
+ return { type: 'batch', key, reqs, tiles, trees };
64
+ }
65
+ /**
66
+ * One tile of the ground, sampled here (height / water / slope and terrain trees are main-thread functions) and cached for TILE_TTL steps:
67
+ * data = ground shape raster, trees = [x, z, r, ...] of the ground's colliders around the tile
68
+ */
69
+ tile(k, tx, tz) {
70
+ const e = this.e, c = this.tiles.get(k);
71
+ const bv = e.collision.blockedVersion;
72
+ if (c && c.bv === bv && e.tick - c.at < TILE_TTL) return c;
73
+ const data = new Uint8Array(TILE * TILE), col = e.collision, trees = [], span = TILE * RES, blocked = col._blocked.length > 0;
74
+ // addBlocked fields are functions and cannot go to a worker: they are sampled into this same raster (the worker sees blocked cells as unwalkable).
75
+ // A cell counts as blocked if fn is true at its centre or on a ring of half a cell (blockedAt), so a 1 m cell never hides a thin river; bounds skip the sampling outside.
76
+ for (let j = 0; j < TILE; j++) for (let i = 0; i < TILE; i++) {
77
+ const x = (tx * TILE + i) * RES, z = (tz * TILE + j) * RES;
78
+ data[j * TILE + i] = col.groundWalkable(x, z) && !(blocked && col.blockedAt(x, z, RES / 2)) ? 1 : 0;
79
+ }
80
+ // every collider that can touch a point of the tile: half diagonal + the largest character radius we expect + 1 (the same reach walkableAt uses)
81
+ e.ground.forEachCollider?.((tx + 0.5) * span, (tz + 0.5) * span, span * 0.71 + 3, (x, z, r) => { trees.push(x, z, r); });
82
+ const v = { data, trees, at: e.tick, bv };
83
+ this.tiles.set(k, v);
84
+ if (this.tiles.size > 4096) for (const [kk, o] of this.tiles) if (e.tick - o.at >= TILE_TTL) this.tiles.delete(kk);
85
+ return v;
86
+ }
87
+ /** Forget cached tiles overlapping a world box (ground:change) */
88
+ dropTiles({ x0, z0, x1, z1 }) {
89
+ const span = TILE * RES;
90
+ for (const [k, v] of this.tiles) {
91
+ const [tx, tz] = k.split(':').map(Number);
92
+ if ((tx + 1) * span + 3 >= x0 && tx * span - 3 <= x1 && (tz + 1) * span + 3 >= z0 && tz * span - 3 <= z1) this.tiles.delete(k);
93
+ }
94
+ }
95
+ /** Bring the workers' mirror up to the state this batch is tagged with (broadcasts arrive before the batch: one message queue per worker) */
96
+ mirror(key) {
97
+ const e = this.e;
98
+ this.lane ??= e.threads.lane({ create: () => new Worker(new URL('./pathWorker.js', import.meta.url), { type: 'module' }), local: pathHandler });
99
+ if (key[0] === 'n' && this.sent.rev !== e.nav.revision) { this.sent.rev = e.nav.revision; this.lane.broadcast({ type: 'mesh', data: e.nav.exportMesh() }, 'mesh'); }
100
+ if (key[0] === 'g' && this.sent.ver !== e.collision.version) {
101
+ this.sent.ver = e.collision.version;
102
+ const items = [];
103
+ e.collision.forEachStatic((type, o) => items.push(type === 'box' ? { x: o.x, z: o.z, r: o.r, c: o.c, s: o.s, hw: o.hw, hd: o.hd, box: true } : { x: o.x, z: o.z, r: o.r, box: false }));
104
+ this.lane.broadcast({ type: 'colliders', items }, 'colliders');
105
+ }
106
+ }
107
+ /** Due step: worker answer if it arrived and the walkable state is unchanged, else the same solver here on the current state */
108
+ land(batch, list, r) {
109
+ const e = this.e, key = this.key();
110
+ if (!r || key !== batch.key) r = solveBatch(key === batch.key ? batch : this.build(list), { query: e.nav?.query, grid: e.collision?.grid });
111
+ list.forEach((h, i) => { if (!h.canceled) h.done(r[i].path, r[i].status); });
112
+ }
113
+ }
@@ -0,0 +1,62 @@
1
+ // Async pathfinding batch solver: the same code answers in the path worker (pathWorker.js), in the lane's main-thread fallback,
2
+ // and in engine.commits' fallback when a worker reply is late (pathAsync.js). Worker-safe: no three.js, no engine objects.
3
+ // A batch carries everything that is not mirrored in the worker: start / goal (with ground heights), and for A* a raster of the ground half of walkability.
4
+ // The worker mirrors the rest: the navmesh (imported from the bytes the nav module exports) and the collision module's colliders (rebuilt into the same grid).
5
+ import { findPath as astar, astarDefaults } from './astar.js';
6
+ export { astarDefaults };
7
+ import { CollisionGrid, gridBlocks } from '../collision/grid.js';
8
+ import { navSearch } from '../nav/navPath.js';
9
+
10
+ /** Ground shape raster (water, slope): one byte per RES-meter cell, TILE x TILE cells per tile, keyed `${tx}:${tz}` */
11
+ export const RES = 1, TILE = 32;
12
+ export const tileOf = v => Math.floor(Math.round(v / RES) / TILE);
13
+
14
+ /**
15
+ * Walkability from a batch: ground shape from the raster (nearest cell; outside the sent tiles counts as blocked, both sides see the same tiles),
16
+ * colliders tested exactly: the ground's own (terrain trees, sent with the batch) and the collision module's (mirrored grid).
17
+ */
18
+ function snapshotWalkable(tiles, radius, grid, trees) {
19
+ return (x, z) => {
20
+ const ix = Math.round(x / RES), iz = Math.round(z / RES), tx = Math.floor(ix / TILE), tz = Math.floor(iz / TILE);
21
+ const t = tiles[tx + ':' + tz];
22
+ if (!t || !t[(iz - tz * TILE) * TILE + (ix - tx * TILE)]) return false;
23
+ return !gridBlocks(trees, x, z, radius) && !(grid && gridBlocks(grid, x, z, radius));
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Answer every request of a batch: [{ status, path }...] in request order.
29
+ * @param {{ reqs: any[], tiles: Record<string, Uint8Array> }} batch
30
+ * @param {{ query: any, grid: any }} ctx navmesh query and collider grid (live ones on the main thread, mirrored ones in the worker)
31
+ */
32
+ export function solveBatch(batch, ctx) {
33
+ let trees = null;
34
+ return batch.reqs.map(q => {
35
+ if (q.mode === 'nav') return navSearch(ctx.query, q.s, q.g, q.reach);
36
+ if (q.mode !== 'grid') return { status: 'notReady', path: null };
37
+ if (!trees) { trees = new CollisionGrid(); for (let i = 0; i < batch.trees.length; i += 3) trees.add({ x: batch.trees[i], z: batch.trees[i + 1], r: batch.trees[i + 2] }, false); }
38
+ const path = astar(snapshotWalkable(batch.tiles, q.radius, ctx.grid, trees), q.s.x, q.s.z, q.g.x, q.g.z, q);
39
+ return { status: q.navPending ? 'notReady' : path ? 'ok' : 'noPath', path };
40
+ });
41
+ }
42
+
43
+ /**
44
+ * Lane handler: { type: 'mesh', data } (navmesh bytes or null), { type: 'colliders', items }, { type: 'batch', reqs, tiles } → results.
45
+ * @param {() => Promise<any> | any} load gives the Recast module: the worker passes its static import (a worker bundle cannot split chunks);
46
+ * the main-thread fallback imports it on demand so games without nav never download it
47
+ */
48
+ export function pathHandler(load = () => import('@recast-navigation/core')) {
49
+ const ctx = { query: null, grid: null };
50
+ let lib = null, mesh = null, chain = Promise.resolve();
51
+ // Recast loads asynchronously; every message waits for the ones before it, so a batch always sees the mesh / colliders sent before it
52
+ const then = fn => { const p = chain.then(fn); chain = p.catch(() => {}); return p; }; // one failed message must not block the rest
53
+ return msg => {
54
+ if (msg.type === 'mesh') return void then(async () => {
55
+ if (!lib) { const m = await load(); await m.init(); lib = m; }
56
+ ctx.query?.destroy(); mesh?.destroy(); ctx.query = mesh = null;
57
+ if (msg.data) { mesh = lib.importNavMesh(msg.data).navMesh; ctx.query = new lib.NavMeshQuery(mesh); }
58
+ });
59
+ if (msg.type === 'colliders') return void then(() => { const g = new CollisionGrid(); for (const it of msg.items) g.add(it, it.box); ctx.grid = g; });
60
+ return then(() => solveBatch(msg, ctx));
61
+ };
62
+ }
@@ -0,0 +1,7 @@
1
+ // Path worker: answers engine.characters.findPathAsync batches off the main thread (one per engine.threads slot).
2
+ // Recast is imported statically here (a worker bundle is one file); its wasm is inlined, so it loads in a worker without fetching anything.
3
+ import * as recast from '@recast-navigation/core';
4
+ import { serve } from '../../core/threadServe.js';
5
+ import { pathHandler } from './pathJob.js';
6
+
7
+ serve(pathHandler(() => recast));
@@ -0,0 +1,12 @@
1
+ // Player-control error texts, i18n strings and the control check (split out of index.js)
2
+ // The engine picks no player feel: control has no default (genericity rule: core carries no preset). A preset is one spread away, so the error names it first.
3
+ const CONTROL_FIX = "pick how the player moves: createPlayer({ ...presets.player.thirdPerson, spawn }) (import { presets } from 'threedog'), " +
4
+ "control: 'camera' (keys relative to the camera), control: 'none' (the game calls player.move() itself) or a function (player, input, dt) => ({ x, z, run?, speed? })";
5
+ export const DEV_STRINGS = { noControl: 'characters.createPlayer(): no control given; ' + CONTROL_FIX,
6
+ badControl: "characters.createPlayer(): control {got} is not a control; " + CONTROL_FIX + ". (true / false were renamed 'camera' / 'none')",
7
+ noFollow: "characters.createPlayer(): a camera module is installed but cameraFollow was not given, so the camera does not follow the player. " +
8
+ 'Pass cameraFollow: true (presets.player.* do), or cameraFollow: false if the game aims the camera itself',
9
+ noWorld: 'characters.createPlayer() needs world() installed first: the player is a record in world (position is saved, world splits near/far by it). Use engine.use(world(), …); openWorld() already installs it' };
10
+ export const STRINGS = { 'zh-CN': { 'npc.talk': '和{name}说话', 'input.jump': '跳跃', 'input.brake': '刹车' }, en: { 'npc.talk': 'Talk to {name}', 'input.jump': 'Jump', 'input.brake': 'Brake' } };
11
+
12
+ export const validControl = c => c === 'camera' || c === 'none' || typeof c === 'function';
@@ -0,0 +1,58 @@
1
+ // The procedural body of a Character (split out of Character.js): the gray capsule used when nothing draws a character, attaching a style pack's rig,
2
+ // and the limb swing / body bob used when the character has no skeletal animation.
3
+ // A rig is { root, body?, head?, joints?: { name: Group }, limbs: [{ joint, offset: 0 | Math.PI, amp, kind: 'arm' | 'leg', side? }] }; the style pack builds it.
4
+ import * as THREE from 'three';
5
+ import { makeMaterial } from '../../render/materials.js';
6
+ import { warnOnce } from '../../core/validate.js';
7
+
8
+ /** Warned once when no style pack and no model give the character a body */
9
+ export const NO_CHARACTER = 'characters: no style pack / model given, so characters are gray capsules (a placeholder). Pass one: a model '
10
+ + "(createPlayer({ model: 'hero' }) or style.character.model), or a style pack whose style.character.create builds one, "
11
+ + "e.g. createEngine({ style: lowpoly }) with lowpoly from '@threedog/style-lowpoly'";
12
+
13
+ /** Neutral placeholder when the style pack draws no character: one gray capsule, no limbs (the shape belongs to style packs) */
14
+ export function capsule(color, engine) {
15
+ const body = new THREE.Group(); body.position.y = 0.85;
16
+ const m = new THREE.Mesh(new THREE.CapsuleGeometry(0.3, 1.0, 4, 12).translate(0, -0.05, 0), makeMaterial('character', { color }, engine));
17
+ m.castShadow = true; body.add(m);
18
+ const root = new THREE.Group(); root.add(body);
19
+ return { root, body };
20
+ }
21
+
22
+ /** Put a rig under the character root and remember its parts */
23
+ export function useRig(ch, rig) {
24
+ ch.root.add(rig.root); ch._rig = rig;
25
+ ch.hips = rig.body || rig.root; ch.head = rig.head || null;
26
+ ch.bodyBase = ch.hips.position.y;
27
+ ch.limbs = rig.limbs || [];
28
+ // named joints (lowpoly humanoid: armL armR legL legR) become properties so game poses can grab them; never shadow a Character field
29
+ for (const k in rig.joints || {}) {
30
+ if (!(k in ch)) ch[k] = rig.joints[k];
31
+ else if (ch[k] !== rig.joints[k]) warnOnce(`character rig: joint "${k}" has the same name as the Character field ch.${k}, so ch.${k} stays the field; use rig.joints.${k} (or rename the joint)`);
32
+ }
33
+ }
34
+
35
+ /** Swing the limbs and bob the body for the current state (sp = move amount, t = elapsed seconds, st = character state) */
36
+ export function animateRig(ch, sp, t, st) {
37
+ const amp = Math.min(1, sp / ch.runSpeed + 0.35);
38
+ let bob = 0, lean = 0;
39
+ for (const L of ch.limbs) {
40
+ let rx = 0, rz = 0;
41
+ const arm = L.kind === 'arm';
42
+ if (st === 'swim') {
43
+ rx = Math.sin(ch.phase * (arm ? 0.9 : 1.4) + L.offset) * (arm ? 1.6 : 0.5);
44
+ rz = arm ? 0.4 * (L.side || 0) : 0;
45
+ } else if (st === 'jump' || st === 'fall') {
46
+ rx = L.kind === 'leg' ? (L.offset ? -0.5 : 0.7) : -0.6;
47
+ rz = arm ? 0.5 * (L.side || 0) : 0;
48
+ } else if (sp > 0.4) rx = Math.sin(ch.phase + L.offset) * L.amp * amp;
49
+ else rx = arm ? Math.sin(t * 1.5) * 0.04 : 0;
50
+ L.joint.rotation.x = rx; if (arm) L.joint.rotation.z = rz || 0.05 * (L.side || 0);
51
+ }
52
+ if (st === 'swim') lean = 1.0;
53
+ else if (sp > 0.4 && ch.grounded) { bob = Math.abs(Math.cos(ch.phase)) * 0.08 * amp; lean = sp / ch.runSpeed * 0.25; }
54
+ else if (ch.grounded) bob = Math.sin(t * 2) * 0.01;
55
+ ch.hips.position.y = ch.bodyBase + bob;
56
+ ch.hips.rotation.x = lean;
57
+ if (ch.head) ch.head.rotation.x = -lean * 0.6;
58
+ }
@@ -0,0 +1,22 @@
1
+ // Swap a loaded glTF model into a Character: attach it and build its animation state machine from the default / mapped / game-given clips.
2
+ // Split out of Character.js; Character._useModel calls it.
3
+ import { warnOnce } from '../../core/validate.js';
4
+ import { findClip } from '../../core/Animator.js';
5
+
6
+ const DEFAULT_CLIPS = { idle: 'Idle', walk: 'Walk', run: 'Run', swim: 'Swim', jump: 'Jump', fall: 'Fall', drive: 'Drive' };
7
+
8
+ export function useModel(ch, model, clips, animation) {
9
+ const engine = ch.engine; ch.root.add(model);
10
+ // a bone named like a Character field (e.g. "head", "root", "state") makes `ch[name]` mean the field, not the bone: easy to miss when a game
11
+ // reads bones by name; say it once per name and point at the safe lookup
12
+ model.traverse(o => { if (o.isBone && o.name && o.name in ch) warnOnce(`character model "${model.name || 'model'}": bone "${o.name}" has the same name as the Character field ch.${o.name}; read the bone with ch.root.getObjectByName('${o.name}'), not ch.${o.name}, or rename the bone`); });
13
+ const states = {};
14
+ // default names only where the model has the clip (a model without Swim is fine) and the manifest mapped nothing (Assets.animate merges that under
15
+ // these states, so a default Idle must not shadow a mapped Idle_Sword); names the game wrote are always kept so a typo is reported
16
+ const have = model.userData.animations || [], map = engine.assets.mapping(model), mapped = map?.states || {};
17
+ for (const [st, clip] of Object.entries(DEFAULT_CLIPS)) if (!mapped[st] && findClip(have, clip)) states[st] = { clip };
18
+ for (const [st, clip] of Object.entries(clips || {})) states[st] = { clip };
19
+ // the model's own mapping (fade, transitions) beats the style pack's default for every character; the game's per-character config beats both
20
+ ch.anim = engine.assets.animate(model, { ...engine.style.character?.animation, ...map, states, ...(animation || {}) });
21
+ ch.anim.afterPose = dt => ch._firePose(dt); // a mixer pose is applied inside the Animator's update, so the Animator tells us when it is done
22
+ }