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,58 @@
1
+ // character.walkTo(target, opts): follow characters.findPath on fixed steps. Exists so a hand-written guard / pet / follower does not re-implement
2
+ // path following (turn rate, skipping passed points, stuck detection) every time. Steering only: the mover still owns position (see Character.js).
3
+ // Transient on purpose (like a noSkip timer): a walk is not saved and engine.skip does not fast-forward it. So it never outlives what it steers:
4
+ // one walk per character (a new walkTo cancels the old, else two hooks would fight over move()), and character.dispose() or a save load
5
+ // ends it with 'cancelled' (the loaded state has its own positions; the old path no longer applies). A game that must resume a walk saves the target.
6
+ import { xzOf } from '../../core/math.js';
7
+
8
+ const STUCK_PROGRESS = 0.15; // metres the character must gain on the next point within the stuck window, else it counts as stuck
9
+
10
+ /**
11
+ * @param {any} ch Character
12
+ * @returns {Promise<{ status: 'arrived' | 'noPath' | 'stuck' | 'cancelled' }> & { remove(): void }}
13
+ */
14
+ export function walkTo(ch, target, { speed, arrive = 0.5, turnRate = 8, stuckSeconds = 1.5, maxRepaths = 3, run = false } = {}) {
15
+ const e = ch.engine;
16
+ let done, hook, path = null, i = 0, heading = null, repaths = 0, bestD = Infinity, stuckT = 0;
17
+ const promise = new Promise(res => { done = res; });
18
+ ch._walk?.remove(); // one walk per character: the newer order wins
19
+ let onLoad = null, handle = null;
20
+ const finish = status => { if (!hook) return; hook.remove(); hook = null; onLoad?.remove(); if (ch._walk === handle) ch._walk = null; done({ status }); };
21
+ const dist = (p, x, z) => Math.hypot(p.x - x, p.z - z);
22
+ // points the character is already at or past (a later point is closer) would make it turn back, so drop them
23
+ const skipPassed = (x, z) => {
24
+ while (i < path.length - 1 && (dist(path[i], x, z) < arrive * 0.6 || dist(path[i + 1], x, z) < dist(path[i], x, z))) i++;
25
+ };
26
+ const solve = () => {
27
+ path = e.characters.findPath(ch.root.position, target, { radius: ch.radius });
28
+ i = 0; bestD = Infinity; stuckT = 0;
29
+ if (!path || !path.length) return false;
30
+ const [x, z] = xzOf(ch.root.position);
31
+ skipPassed(x, z);
32
+ return true;
33
+ };
34
+ if (!solve()) { queueMicrotask(() => done({ status: 'noPath' })); return Object.assign(promise, { remove() {} }); }
35
+ onLoad = e.events.on('save:loaded', () => finish('cancelled'));
36
+ hook = e.onFixed(dt => {
37
+ const [gx, gz] = xzOf(target), [x, z] = xzOf(ch.root.position);
38
+ if (Math.hypot(gx - x, gz - z) <= arrive) { ch.move(0, 0, false, dt); return finish('arrived'); }
39
+ skipPassed(x, z);
40
+ const p = path[i], d = dist(p, x, z);
41
+ // stuck: no gain on the next point for stuckSeconds, so replan; give up after maxRepaths
42
+ if (d < bestD - STUCK_PROGRESS) { bestD = d; stuckT = 0; }
43
+ else if ((stuckT += dt) > stuckSeconds) {
44
+ if (++repaths > maxRepaths || !solve()) { ch.move(0, 0, false, dt); return finish(repaths > maxRepaths ? 'stuck' : 'noPath'); }
45
+ return;
46
+ }
47
+ const want = Math.atan2(p.x - x, p.z - z);
48
+ heading ??= ch.facing;
49
+ let diff = want - heading; diff -= Math.PI * 2 * Math.round(diff / (Math.PI * 2));
50
+ const step = turnRate * dt;
51
+ heading += Math.abs(diff) <= step ? diff : Math.sign(diff) * step;
52
+ // slow down while the body is still turning toward the point, so it does not overshoot sideways
53
+ const align = Math.max(0.2, Math.cos(Math.min(Math.abs(diff), Math.PI / 2)));
54
+ ch.move(Math.sin(heading), Math.cos(heading), run, dt, (speed ?? (run ? ch.runSpeed : ch.speed)) * align);
55
+ });
56
+ handle = Object.assign(promise, { remove() { finish('cancelled'); } });
57
+ return ch._walk = handle;
58
+ }
@@ -0,0 +1,274 @@
1
+ // Lightweight collision: characters are upright cylinders, trees/rocks are circles, houses etc. are rotated rectangles.
2
+ // Only keeps walkers from clipping and the camera from being blocked; much faster than a full physics engine, tens of thousands of trees are fine on big maps.
3
+ // For falling, pushing crates and other real physics, add Rapier separately; it does not affect this.
4
+ // Once installed: engine.collision (real physics is another module, rigid() → engine.rigid).
5
+ // Positions are always a single argument (Vector3 / Object3D / [x, y, z] / { x, z }); sizes go in the options object:
6
+ // const h = engine.collision.addBox(house, { halfWidth: 3, halfDepth: 2, rotation: 0.3 }); h.remove();
7
+ import { xzOf } from '../../core/math.js';
8
+ import { checkOptionsArg } from '../../core/validate.js';
9
+ import { readParams, keysSchema } from '../../core/params.js';
10
+ import { CollisionGrid, gridBlocks } from './grid.js';
11
+
12
+ /** One axis of the slab test: narrows S.t0 / S.t1 to where the ray is inside |o + d t| <= h; false when it misses */
13
+ function slab(S, o, d, h) {
14
+ if (Math.abs(d) < 1e-6) return Math.abs(o) <= h;
15
+ let ta = (-h - o) / d, tb = (h - o) / d; if (ta > tb) { const t = ta; ta = tb; tb = t; }
16
+ S.t0 = Math.max(S.t0, ta); S.t1 = Math.min(S.t1, tb);
17
+ return S.t0 <= S.t1;
18
+ }
19
+
20
+ const BOX_KEYS = ['halfWidth', 'halfDepth', 'rotation', 'height', 'y'], CIRCLE_KEYS = ['radius', 'height'], SEG_KEYS = ['thickness', 'height', 'y'], BLOCK_KEYS = ['bounds'];
21
+
22
+ export class Collision {
23
+ /**
24
+ * maxClimb: max walkable slope (height diff / horizontal distance; default slopeRatio derived from engine.movement.maxSlope); canopyHeight: a camera above this height is not blocked by trees
25
+ * cameraPad: camera margin from obstacles; cameraMin: closest camera distance; walkableWaterMargin: how far above the water surface counts as walkable
26
+ * cameraOcclusion: what camera occlusion tests: 'colliders' circles and boxes (default) | 'meshes' meshes registered as camera blockers (level buildings, col_ meshes, via engine.rays) | 'both'
27
+ */
28
+ constructor(engine, { maxClimb = engine.movement.slopeRatio, canopyHeight = 5, cameraPad = 0.5, cameraMin = 1.5, walkableWaterMargin = 0.2, cameraOcclusion = 'colliders' } = {}) {
29
+ this.engine = engine;
30
+ Object.assign(this, { maxClimb, canopyHeight, cameraPad, cameraMin, walkableWaterMargin, cameraOcclusion });
31
+ this.circles = []; // manually added circle colliders {x, z, r, h}
32
+ this.boxes = []; // rectangles {x, z, hw, hd, rot, h}
33
+ this._grid = new CollisionGrid(); // grid index: resolve / camera look only nearby instead of scanning all (circles / boxes change only via addCircle / addBox)
34
+ this._blocked = []; // addBlocked fields {fn, bounds}; empty = zero cost
35
+ this.blockedVersion = 0; // +1 on addBlocked / remove: async paths re-sample their cached ground rasters
36
+ this.version = 0; // +1 on every static collider add/remove; the physics module syncs on it
37
+ this._onGroundCircle = (cx, cz, r) => this._pushCircle(this._rPos, cx, cz, r, this._rRad); // built once: ground.forEachCollider callback
38
+ this._camS = { from: null, to: null, ux: 0, uz: 0, len: 0, pad: 0, want: 0, best: 0, t0: 0, t1: 0 }; // cameraDistance scratch for its callbacks
39
+ this._lineS = { t0: 0, t1: 0 }; // lineClear slab scratch
40
+ this._onCamCircle = (a, b, c) => this._camCircle(a, b, c);
41
+ }
42
+ /** Iterate all manually added static colliders (for the physics module): fn('box' | 'circle', data) */
43
+ forEachStatic(fn) { for (const b of this.boxes) fn('box', b); for (const c of this.circles) fn('circle', c); }
44
+
45
+ /** Add a circle collider (pillar, statue, campfire): position is the centre, radius (default 0.5), height (default 6). Returns a handle { remove() } */
46
+ addCircle(position, opts = {}) {
47
+ checkOptionsArg('collision.addCircle()', opts, CIRCLE_KEYS); if (typeof opts !== 'object') opts = {};
48
+ const [x, z] = xzOf(position), c = { x, z, r: opts.radius ?? 0.5, h: opts.height ?? 6 };
49
+ this.circles.push(c); this._grid.add(c, false); this.version++;
50
+ return { remove: () => { if (!this.circles.includes(c)) return; this.circles = this.circles.filter(o => o !== c); this._grid.remove(c); this.version++; } };
51
+ }
52
+ /**
53
+ * Add a rectangle collider (house, fence): position is the centre; halfWidth / halfDepth (default 1), rotation about the Y axis (radians),
54
+ * height (default 6), y is the box bottom height (omit to sit on the ground; set it for walls on platforms in levels). Returns a handle { remove() }
55
+ */
56
+ addBox(position, opts = {}) {
57
+ checkOptionsArg('collision.addBox()', opts, BOX_KEYS); if (typeof opts !== 'object') opts = {};
58
+ const [x, z] = xzOf(position), hw = opts.halfWidth ?? 1, hd = opts.halfDepth ?? 1, rot = opts.rotation ?? 0;
59
+ const b = { x, z, hw, hd, rot, h: opts.height ?? 6, y: opts.y, c: Math.cos(rot), s: Math.sin(rot), r: Math.hypot(hw, hd) };
60
+ this.boxes.push(b); this._grid.add(b, true); this.version++;
61
+ return { remove: () => { if (!this.boxes.includes(b)) return; this.boxes = this.boxes.filter(o => o !== b); this._grid.remove(b); this.version++; } };
62
+ }
63
+ /**
64
+ * Add a thin wall along the line a -> b (fence, wall; positions like addBox). thickness (default 0.3), height (default 6), y as in addBox.
65
+ * It is a rotated box in the same grid, so a gap between two segments is a gate. Returns a handle { remove() }
66
+ */
67
+ addSegment(a, b, opts = {}) {
68
+ checkOptionsArg('collision.addSegment()', opts, SEG_KEYS); if (typeof opts !== 'object') opts = {};
69
+ const [ax, az] = xzOf(a), [bx, bz] = xzOf(b);
70
+ // box-local +x is (cos r, -sin r) in world, so r = -atan2(dz, dx)
71
+ return this.addBox([(ax + bx) / 2, 0, (az + bz) / 2], { halfWidth: Math.hypot(bx - ax, bz - az) / 2, halfDepth: (opts.thickness ?? 0.3) / 2, rotation: -Math.atan2(bz - az, bx - ax), height: opts.height, y: opts.y });
72
+ }
73
+ /**
74
+ * Mark ground as impassable where fn(x, z) is true (river, lava, cliff edge). Walkers are stopped at its edge (sliding along it) and walkable() says no.
75
+ * fn must be pure and deterministic (no clock, no random). bounds { minX, maxX, minZ, maxZ } skips fn outside it. A bridge: have fn return false over it,
76
+ * or keep the water field exact and let fn test `!onBridge(x, z)`. findPathAsync samples fn into its ground raster (1 m cells), so give bounds to keep that cheap. Returns a handle { remove() }
77
+ */
78
+ addBlocked(fn, opts = {}) {
79
+ checkOptionsArg('collision.addBlocked()', opts, BLOCK_KEYS); if (typeof opts !== 'object') opts = {};
80
+ if (typeof fn !== 'function') throw new Error('collision.addBlocked(fn): fn(x, z) => boolean is required');
81
+ const f = { fn, bounds: opts.bounds ?? null }; this._blocked.push(f); this.version++; this.blockedVersion++;
82
+ return { remove: () => { if (!this._blocked.includes(f)) return; this._blocked = this._blocked.filter(o => o !== f); this.version++; this.blockedVersion++; } };
83
+ }
84
+ /** Is a character of `radius` standing at (x, z) touching blocked ground (centre and four points on its rim). Free when addBlocked was never used */
85
+ blockedAt(x, z, radius = this.engine.movement.radius) {
86
+ const L = this._blocked; if (!L.length) return false;
87
+ for (let i = 0; i < L.length; i++) {
88
+ const { fn, bounds: bd } = L[i];
89
+ if (bd && (x + radius < bd.minX || x - radius > bd.maxX || z + radius < bd.minZ || z - radius > bd.maxZ)) continue;
90
+ if (fn(x, z) || fn(x + radius, z) || fn(x - radius, z) || fn(x, z + radius) || fn(x, z - radius)) return true;
91
+ }
92
+ return false;
93
+ }
94
+ /** Add collision from a three.js object's bounding box (common for house models), pad grows it outward (m). Returns a handle { remove() } */
95
+ addObject(obj, { pad = 0 } = {}) {
96
+ obj.updateMatrixWorld(true);
97
+ const THREE = this.engine.THREE, box = new THREE.Box3().setFromObject(obj), c = box.getCenter(new THREE.Vector3()), s = box.getSize(new THREE.Vector3());
98
+ return this.addBox(c, { halfWidth: s.x / 2 + pad, halfDepth: s.z / 2 + pad, height: s.y });
99
+ }
100
+
101
+ // The per-frame walkers below pass state through fields instead of building callbacks: resolve() and cameraDistance() run every step / frame.
102
+ // resolve saves and restores its fields, so a nested call (from a ground collider callback) stays safe.
103
+ _pushCircle(pos, a, b, c, radius) {
104
+ const dx = pos.x - a, dz = pos.z - b, d = Math.hypot(dx, dz), min = radius + c;
105
+ if (d < min && d > 1e-5) { pos.x = a + dx / d * min; pos.z = b + dz / d * min; this._rHit = true; }
106
+ }
107
+ _pushBox(pos, bx, radius) {
108
+ const lx0 = pos.x - bx.x, lz0 = pos.z - bx.z;
109
+ const lx = lx0 * bx.c - lz0 * bx.s, lz = lx0 * bx.s + lz0 * bx.c; // to box-local coordinates
110
+ const qx = Math.max(-bx.hw, Math.min(bx.hw, lx)), qz = Math.max(-bx.hd, Math.min(bx.hd, lz));
111
+ const dx = lx - qx, dz = lz - qz, d = Math.hypot(dx, dz);
112
+ if (d >= radius) return;
113
+ let nx, nz;
114
+ if (d > 1e-5) { nx = dx / d; nz = dz / d; nx = lx + nx * (radius - d); nz = lz + nz * (radius - d); }
115
+ else { // centre is inside the box: push out along the nearest edge
116
+ const px = bx.hw - Math.abs(lx), pz = bx.hd - Math.abs(lz);
117
+ if (px < pz) { nx = Math.sign(lx) * (bx.hw + radius); nz = lz; } else { nx = lx; nz = Math.sign(lz) * (bx.hd + radius); }
118
+ }
119
+ pos.x = bx.x + nx * bx.c + nz * bx.s; pos.z = bx.z - nx * bx.s + nz * bx.c; this._rHit = true;
120
+ }
121
+
122
+ /** @internal Push a character of radius `radius` out of obstacles; edits pos.x / pos.z directly. Returns whether a collision happened */
123
+ resolve(pos, radius = this.engine.movement.radius) {
124
+ const sPos = this._rPos, sRad = this._rRad;
125
+ this._rPos = pos; this._rRad = radius; this._rHit = false;
126
+ const g = this.engine.ground;
127
+ for (let iter = 0; iter < 2; iter++) {
128
+ g.forEachCollider?.(pos.x, pos.z, radius + 2, this._onGroundCircle);
129
+ const list = this._grid.query(pos.x, pos.z, radius + 2);
130
+ for (let i = 0; i < list.length; i++) {
131
+ const it = list[i];
132
+ if (it._b) this._pushBox(pos, it, radius); else this._pushCircle(pos, it.x, it.z, it.r, radius);
133
+ }
134
+ }
135
+ const hit = this._rHit;
136
+ this._rPos = sPos; this._rRad = sRad;
137
+ return hit;
138
+ }
139
+
140
+ /** Can anyone stand here (for pathfinding): not in water, not too steep, not inside an obstacle. radius is the character radius (m, default engine.movement.radius) */
141
+ walkable(position, { radius = this.engine.movement.radius } = {}) { const [x, z] = xzOf(position); return this.walkableAt(x, z, radius); }
142
+ /**
143
+ * Line of sight with height: is the 3D segment a -> b free of colliders (boxes, circles, terrain trees)? Positions like addBox ([x, y, z] / Vector3 / Object3D).
144
+ * Heights count: a 1 m wall does not block a sight line passing 3 m above it; a collider's `y` and `height` are honoured (no `y` = sits on the ground).
145
+ * Give real eye heights in a and b (`[x, 1.6, z]`); a plain { x, z } counts as y = 0. opts.radius (default 0) fattens the line, e.g. the character radius for "can I walk straight there".
146
+ * Ignores addBlocked fields (water is not a wall). Terrain trees have no stored height and block below `canopyHeight` above the ground. Allocates a little: not for hundreds of pairs per frame.
147
+ * opts.who: world record id of the asker; with events.traceSize > 0 every query is noted as a `sight` trace entry (data: from, to, clear), in full for who === events.traceFocus.
148
+ * @param {any} a @param {any} b @param {{ radius?: number, who?: string }} [opts]
149
+ * @returns {boolean} true = nothing in the way
150
+ * @example if (engine.collision.lineClear(guard.position, player.position, { who: 'guard-1' })) alert(); // guard sees the player
151
+ */
152
+ lineClear(a, b, opts = {}) {
153
+ const clear = this._lineClear(a, b, opts), ev = this.engine.events;
154
+ if (ev.traceSize > 0) { const A = this._vec(a), B = this._vec(b), r = x => Math.round(x * 10) / 10; ev.note('sight', { obj: opts.who, verbose: clear, data: { from: [r(A.x), r(A.y), r(A.z)], to: [r(B.x), r(B.y), r(B.z)], clear } }); } // a clear line is the common case: only kept for the focused object; a blocked one is always kept
155
+ return clear;
156
+ }
157
+ /** @internal */
158
+ _lineClear(a, b, opts) {
159
+ checkOptionsArg('collision.lineClear()', opts, ['radius', 'who']); if (typeof opts !== 'object') opts = {};
160
+ const rad = opts.radius ?? 0;
161
+ const A = this._vec(a), B = this._vec(b), dx = B.x - A.x, dz = B.z - A.z, dy = B.y - A.y;
162
+ const S = this._lineS;
163
+ // y of the segment is linear in t; an obstacle occupying t in [t0, t1] blocks if the segment's y range there overlaps [bottom, top]
164
+ const blocks = (t0, t1, bottom, top) => {
165
+ t0 = Math.max(t0, 0); t1 = Math.min(t1, 1);
166
+ if (t0 > t1) return false;
167
+ const y0 = A.y + dy * t0, y1 = A.y + dy * t1;
168
+ return Math.max(y0, y1) > bottom && Math.min(y0, y1) < top;
169
+ };
170
+ const circle = (cx, cz, r, bottom, top) => {
171
+ const ox = A.x - cx, oz = A.z - cz, R = r + rad, qa = dx * dx + dz * dz, qb = 2 * (ox * dx + oz * dz), qc = ox * ox + oz * oz - R * R;
172
+ if (qa < 1e-12) return qc < 0 && blocks(0, 1, bottom, top); // straight up / down
173
+ const disc = qb * qb - 4 * qa * qc; if (disc < 0) return false;
174
+ const sq = Math.sqrt(disc);
175
+ return blocks((-qb - sq) / (2 * qa), (-qb + sq) / (2 * qa), bottom, top);
176
+ };
177
+ const len = Math.hypot(dx, dz), mx = A.x + dx / 2, mz = A.z + dz / 2;
178
+ const list = this._grid.query(mx, mz, len / 2 + rad + 1);
179
+ for (let i = 0; i < list.length; i++) {
180
+ const it = list[i];
181
+ if (!it._b) { const g = this.engine.surface(it.x, it.z); if (circle(it.x, it.z, it.r, g, g + it.h)) return false; continue; }
182
+ const ox = A.x - it.x, oz = A.z - it.z;
183
+ const lx = ox * it.c - oz * it.s, lz = ox * it.s + oz * it.c, ldx = dx * it.c - dz * it.s, ldz = dx * it.s + dz * it.c;
184
+ S.t0 = 0; S.t1 = 1;
185
+ if (!slab(S, lx, ldx, it.hw + rad) || !slab(S, lz, ldz, it.hd + rad)) continue;
186
+ const bottom = it.y ?? this.engine.surface(it.x, it.z);
187
+ if (blocks(S.t0, S.t1, bottom, bottom + it.h)) return false;
188
+ }
189
+ let treeHit = false;
190
+ this.engine.ground.forEachCollider?.(mx, mz, len / 2 + rad + 1, (cx, cz, r) => {
191
+ if (!treeHit) { const g = this.engine.surface(cx, cz); treeHit = circle(cx, cz, r, g, g + this.canopyHeight); }
192
+ });
193
+ return !treeHit;
194
+ }
195
+ /** @internal position argument -> { x, y, z } (y 0 when only x, z are given) */
196
+ _vec(p) {
197
+ const [x, z] = xzOf(p);
198
+ const q = p.isObject3D ? p.position : p;
199
+ const y = (Array.isArray(q) ? q[1] : q.y) ?? 0;
200
+ return { x, y, z };
201
+ }
202
+ /** @internal The collider grid (boxes and circles added through this module), read by async pathfinding on the main thread */
203
+ get grid() { return this._grid; }
204
+ /** Same as walkable but takes plain numbers (inner loop of A* pathfinding and spawn search, allocates nothing; like engine.surface(x, z)). radius defaults to engine.movement.radius */
205
+ walkableAt(x, z, radius = this.engine.movement.radius) { return this.groundWalkable(x, z) && !this.blockedAt(x, z, radius) && !this._groundBlocks(x, z, radius) && !gridBlocks(this._grid, x, z, radius); }
206
+ /** @internal Ground shape half of walkableAt (water, slope): a smooth field, so async pathfinding samples it on a raster; colliders are tested exactly there */
207
+ groundWalkable(x, z) {
208
+ const e = this.engine;
209
+ // the void of terrain({ shape }): -Infinity is not below a water level of -Infinity, so it must be asked directly
210
+ return e.ground.has(x, z) && !(e.surface(x, z) < e.waterAt(x, z) + this.walkableWaterMargin || e.slope(x, z) > this.maxClimb * 0.8);
211
+ }
212
+ /** Does one of the ground's own colliders (terrain trees) block this spot */
213
+ _groundBlocks(x, z, radius) {
214
+ let blocked = false;
215
+ this.engine.ground.forEachCollider?.(x, z, radius + 1, (cx, cz, r) => { if (!blocked && Math.hypot(x - cx, z - cz) < radius + r) blocked = true; });
216
+ return blocked;
217
+ }
218
+
219
+ /** A camera above the canopy is not blocked by trees: is the line of sight at distance tc above it over (x, z) */
220
+ _yAbove(x, z, tc) { const S = this._camS; return S.from.y + (S.to.y - S.from.y) * (tc / S.len) - this.engine.surface(x, z) > this.canopyHeight; }
221
+ _camCircle(a, b, c) {
222
+ const S = this._camS, from = S.from, tc = (a - from.x) * S.ux + (b - from.z) * S.uz;
223
+ if (tc <= 0.3 || tc >= S.len) return;
224
+ const px = from.x + S.ux * tc - a, pz = from.z + S.uz * tc - b, rr = c + S.pad;
225
+ if (px * px + pz * pz > rr * rr) return;
226
+ const t = tc - Math.sqrt(rr * rr - (px * px + pz * pz)); // distance at which the line of sight (character to camera) hits the obstacle
227
+ if (this._yAbove(a, b, tc)) return;
228
+ S.best = Math.min(S.best, S.want * t / S.len);
229
+ }
230
+ /** Rectangle: rotate the line of sight into box-local coordinates and compute where it enters the box (slab intersection) */
231
+ _camBox(bx) {
232
+ const S = this._camS, from = S.from, ox = from.x - bx.x, oz = from.z - bx.z, len = S.len;
233
+ const lx = ox * bx.c - oz * bx.s, lz = ox * bx.s + oz * bx.c, dx = S.ux * bx.c - S.uz * bx.s, dz = S.ux * bx.s + S.uz * bx.c;
234
+ S.t0 = 0; S.t1 = len;
235
+ if (!slab(S, lx, dx, bx.hw + S.pad) || !slab(S, lz, dz, bx.hd + S.pad)) return;
236
+ if (S.t0 <= 0.3) return;
237
+ const yAt = from.y + (S.to.y - from.y) * (S.t0 / len);
238
+ if (yAt > (bx.y ?? this.engine.surface(bx.x, bx.z)) + bx.h) return; // camera above the wall top
239
+ S.best = Math.min(S.best, S.want * S.t0 / len);
240
+ }
241
+
242
+ /** @internal Camera occlusion: if the line from the character's head to the camera passes through a trunk or house, pull the camera closer. Returns the max allowed distance */
243
+ cameraDistance(from, to, want, pad = this.cameraPad) {
244
+ const mode = this.cameraOcclusion;
245
+ let best = want;
246
+ if (mode !== 'colliders') { // meshes: cast a ray from the head toward the camera, pull closer if it hits a camera-blocking mesh
247
+ const dx = to.x - from.x, dy = to.y - from.y, dz = to.z - from.z, len3 = Math.hypot(dx, dy, dz);
248
+ const hit = len3 > 1e-3 && this.engine.raycast(from, { x: dx, y: dy, z: dz }, { far: len3, occluders: true });
249
+ if (hit) best = Math.min(best, want * Math.max(0, hit.distance - pad) / len3);
250
+ if (mode === 'meshes') return Math.max(this.cameraMin, best);
251
+ }
252
+ const sx = to.x - from.x, sz = to.z - from.z, len = Math.hypot(sx, sz);
253
+ if (len < 1e-3) return mode === 'colliders' ? want : Math.max(this.cameraMin, best);
254
+ const S = this._camS;
255
+ S.from = from; S.to = to; S.ux = sx / len; S.uz = sz / len; S.len = len; S.pad = pad; S.want = want; S.best = best;
256
+ this.engine.ground.forEachCollider?.(from.x + sx / 2, from.z + sz / 2, len / 2 + 1, this._onCamCircle);
257
+ const list = this._grid.query(from.x + sx / 2, from.z + sz / 2, len / 2 + 1);
258
+ for (let i = 0; i < list.length; i++) {
259
+ const it = list[i];
260
+ if (it._b) this._camBox(it); else this._camCircle(it.x, it.z, it.r);
261
+ }
262
+ best = S.best;
263
+ S.from = S.to = null; // do not keep the caller's vectors alive
264
+ return Math.max(this.cameraMin, best);
265
+ }
266
+ }
267
+
268
+ const COLLISION_PARAMS = keysSchema(['maxClimb', 'canopyHeight', 'cameraPad', 'cameraMin', 'walkableWaterMargin', 'cameraOcclusion']);
269
+
270
+ /** Collision module: lightweight character walking collision, covers the whole map. Once installed: engine.collision */
271
+ export function collision(opts = {}) {
272
+ readParams('collision', COLLISION_PARAMS, opts);
273
+ return { name: 'collision', params: COLLISION_PARAMS, options: opts, label: 'Collision', install(e) { return new Collision(e, opts); } };
274
+ }
@@ -0,0 +1,63 @@
1
+ // Grid index of colliders: register each by bounding circle in the cells it covers; queries look at a few nearby cells instead of scanning all colliders.
2
+ // Results are ordered circles first, then boxes, each in insertion order, exactly the callback order of a linear scan (resolve edits the position in turn, so a different order changes the result).
3
+ const CELL = 8, MAX_CELLS = 64, KEY = 1048576; // colliders too large (covering > 64 cells) skip the grid and are scanned linearly, so registration cost does not blow up
4
+ const byOrder = (a, b) => a._b - b._b || a._o - b._o;
5
+
6
+ /** Cell span [x0, x1, z0, z1] that an item (x, z, r) covers */
7
+ const cellRange = it => [Math.floor((it.x - it.r) / CELL), Math.floor((it.x + it.r) / CELL), Math.floor((it.z - it.r) / CELL), Math.floor((it.z + it.r) / CELL)];
8
+
9
+ /** Add it to out once per query (stamp st) when its circle overlaps the query circle; module-level so query() builds no closure */
10
+ function take(out, it, x, z, range, st) {
11
+ if (it._q === st) return;
12
+ it._q = st;
13
+ const dx = it.x - x, dz = it.z - z, rr = range + it.r;
14
+ if (dx * dx + dz * dz < rr * rr) out.push(it);
15
+ }
16
+
17
+ export class CollisionGrid {
18
+ constructor() { this.cells = new Map(); this.big = []; this.seq = 0; this.stamp = 0; this.out = []; }
19
+ /** Register; item needs x, z, r. isBox puts it after circles in the callback order */
20
+ add(item, isBox) {
21
+ item._o = this.seq++; item._b = isBox ? 1 : 0;
22
+ const [x0, x1, z0, z1] = cellRange(item);
23
+ if ((x1 - x0 + 1) * (z1 - z0 + 1) > MAX_CELLS) { this.big.push(item); return; }
24
+ for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
25
+ const k = i * KEY + j; let c = this.cells.get(k); if (!c) this.cells.set(k, c = []); c.push(item);
26
+ }
27
+ }
28
+ remove(item) {
29
+ const bi = this.big.indexOf(item); if (bi >= 0) { this.big.splice(bi, 1); return; }
30
+ const [x0, x1, z0, z1] = cellRange(item);
31
+ for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
32
+ const k = i * KEY + j, c = this.cells.get(k); if (!c) continue;
33
+ c.splice(c.indexOf(item), 1); if (!c.length) this.cells.delete(k);
34
+ }
35
+ }
36
+ /** Colliders intersecting the circle at (x, z) with radius range (exactly filtered, sorted). The returned array is reused by the next query, do not keep it */
37
+ query(x, z, range) {
38
+ const out = this.out; out.length = 0;
39
+ const st = ++this.stamp;
40
+ const big = this.big;
41
+ for (let i = 0; i < big.length; i++) take(out, big[i], x, z, range, st);
42
+ const x0 = Math.floor((x - range) / CELL), x1 = Math.floor((x + range) / CELL), z0 = Math.floor((z - range) / CELL), z1 = Math.floor((z + range) / CELL);
43
+ for (let i = x0; i <= x1; i++) for (let j = z0; j <= z1; j++) {
44
+ const c = this.cells.get(i * KEY + j);
45
+ if (c) for (let k = 0; k < c.length; k++) take(out, c[k], x, z, range, st);
46
+ }
47
+ if (out.length > 1) out.sort(byOrder);
48
+ return out;
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Does a collider in the grid block a character of `radius` standing at (x, z)? The obstacle half of Collision.walkableAt,
54
+ * shared with the pathfinding worker (it rebuilds a grid from the same colliders), so both answer identically. Worker-safe: no imports.
55
+ */
56
+ export function gridBlocks(grid, x, z, radius) {
57
+ for (const it of grid.query(x, z, radius + 1)) {
58
+ if (!it._b) { if (Math.hypot(x - it.x, z - it.z) < radius + it.r) return true; continue; }
59
+ const dx = x - it.x, dz = z - it.z, lx = dx * it.c - dz * it.s, lz = dx * it.s + dz * it.c;
60
+ if (Math.abs(lx) < it.hw + radius && Math.abs(lz) < it.hd + radius) return true;
61
+ }
62
+ return false;
63
+ }
@@ -0,0 +1,13 @@
1
+ // Content's contribution to thing.explain(): rules read from the thing's template (collide, static, interact), which win over the world record's own.
2
+ const safe = f => { try { return f(); } catch { return null; } };
3
+
4
+ /** @internal */
5
+ export function contentExplain(e, t, out) {
6
+ const def = t.template ? safe(() => e.content.template(t.template)) : null;
7
+ if (!def) return;
8
+ Object.assign(out.rules, {
9
+ blocksMovement: def.collide ?? false, pickable: def.static !== false,
10
+ interact: def.interact ? { label: def.interact.label ?? null, op: def.interact.op } : null,
11
+ note: 'blocksMovement = the collision shape (box / circle) walkers stop at; blocking sight is not modelled by the engine',
12
+ });
13
+ }
@@ -0,0 +1,95 @@
1
+ // Stable ids of authored entries (one place for the rules; recipes/30-templates.md "Ids"):
2
+ // written id as written (`chest-home`); may not contain `#` or `/` (runtime and level-node ids use them, so they never collide)
3
+ // keyed content (npcs, containers) the key
4
+ // stateless prop without id `prop:<model>:<index>`, a template prop without id `<template>:<index>` (pure decoration only)
5
+ // level-model node `<level>/<node>` (level module)
6
+ // An entry with state (pickups, grid items, templates with state / container / interact / body) needs a written id: an index id shifts when an entry
7
+ // is inserted above it, and the save then puts its changes on the wrong entry. Dev warns once per load, naming the entries and the id to write.
8
+ // Two entries with the same id in one load are an error with the fix. Source lines ("defined in content/props.js:14") come from the dev-only
9
+ // line tables of packages/tools/vite/vite-threedog-content-src.js (srcOf); a release build has none.
10
+ import { DEV, warnOnce, fmt } from '../../core/validate.js';
11
+
12
+ const STRINGS = {
13
+ badId: 'content: id "{id}" ({what}) may not contain "#" or "/": "#" is for records made during play and "/" for level-model nodes. Write it with - _ . or :, e.g. "{fix}"',
14
+ dup: 'content: id "{id}" is used twice: by {a} and by {b}. Ids name an entry in saves, so each must be unique: rename one, e.g. "{id}-2"',
15
+ noId: 'content: {n} entr(y/ies) with state have no id, so saves match them by array index and an inserted entry shifts them: {list}. '
16
+ + 'Write the id they have now (e.g. id: \'{first}\') to keep old saves working, or a readable one',
17
+ };
18
+ const RENAME_STRINGS = {
19
+ shape: "content renames: write { oldId: 'newId' } (or oldId: null for an entry deleted on purpose), got {got} for '{id}'",
20
+ badTarget: "content renames: '{a}' -> '{b}': the new id may not contain \"#\" (that is for records made during play)",
21
+ stuck: 'content renames: saved data under {list} was not moved. A rename moves saved state only when the old id is gone from content and the new id has none of its own',
22
+ };
23
+
24
+ /** The dev line table the vite plugin attached to a content value (null in release or for data built in code) */
25
+ const tableOf = v => (DEV && v && typeof v === 'object' && globalThis.__threedogSrc?.get(v)) || null;
26
+
27
+ /**
28
+ * Where content entry `key` (array index or object key) of `container` was written: 'content/props.js:14', or null.
29
+ * @param {any} container the array / object a content file exports (props, pickups, npcs, templates...)
30
+ * @param {string | number} key
31
+ * @returns {string | null}
32
+ * @internal
33
+ */
34
+ export function srcOf(container, key) {
35
+ const t = tableOf(container);
36
+ return t ? `${t.file}:${t.at[key] ?? t.line}` : null;
37
+ }
38
+
39
+ /** Per content.load: catches duplicate ids across props, pickups, NPCs, containers and grid items, and collects stateful entries without an id @internal */
40
+ export class IdCheck {
41
+ constructor() { this.seen = new Map(); this.missing = []; }
42
+ /** An authored id: format check, and an error if this load already used it @param {string} id @param {string} what e.g. "props[3] (template chest)" */
43
+ claim(id, what) {
44
+ if (typeof id === 'string' && /[#/]/.test(id)) throw new Error(fmt(STRINGS.badId, { id, what, fix: id.replace(/[#/]/g, '-') }));
45
+ const a = this.seen.get(id);
46
+ if (a) throw new Error(fmt(STRINGS.dup, { id, a, b: what }));
47
+ this.seen.set(id, what);
48
+ }
49
+ /** A stateful entry relies on its index id */
50
+ unnamed(id, what) { this.missing.push(`${what} -> '${id}'`); }
51
+ /** One dev warning per load listing the stateful entries without an id */
52
+ done() {
53
+ if (!DEV || !this.missing.length) return;
54
+ const m = this.missing;
55
+ warnOnce(fmt(STRINGS.noId, { n: String(m.length), list: m.slice(0, 6).join(', ') + (m.length > 6 ? ', …' : ''), first: m[0].split("-> '")[1].slice(0, -1) }));
56
+ }
57
+ }
58
+
59
+ /**
60
+ * content/renames.js ({ oldId: 'newId' | null }): before any placement is added, saved changes, removals, owed time and container goods under an old
61
+ * authored id move to the new id (null drops them quietly). World and inventory remember the map, so a save loaded after content is renamed too.
62
+ * Why in content and not a save version: renaming is an authoring change; the save format stays the same and an unrenamed save still loads. @internal
63
+ * @param {any} e
64
+ * @param {Record<string, string | null>} map
65
+ */
66
+ export function applyRenames(e, map) {
67
+ for (const [a, b] of Object.entries(map || {})) {
68
+ if (b !== null && typeof b !== 'string') throw new Error(fmt(RENAME_STRINGS.shape, { id: a, got: JSON.stringify(b) }));
69
+ if (typeof b === 'string' && b.includes('#')) throw new Error(fmt(RENAME_STRINGS.badTarget, { a, b }));
70
+ }
71
+ const stuck = e.world?.renameIds(map) ?? [];
72
+ e.inventory?.renameIds(map);
73
+ if (DEV && stuck.length) warnOnce(fmt(RENAME_STRINGS.stuck, { list: stuck.join(', ') }));
74
+ }
75
+
76
+ /** Index id of a pickup without a written id (the loader's id, and what `threedog content ids` writes) @param {any} p @param {number} i @internal */
77
+ export const pickupId = (p, i) => p.id ?? `pickup:${p.item}:${i}`;
78
+ /** Index id of a template instance without a written id @param {any} p @param {number} i @internal */
79
+ export const templateId = (p, i) => p.id ?? `${p.template}:${i}`;
80
+ /** Instances of this template keep state a save must find again by id @param {any} d @internal */
81
+ export const stateful = d => !!(d?.state || d?.container || d?.interact || d?.body);
82
+
83
+ /**
84
+ * Stateful entries that rely on their index id, with the id they have now: what dev warns about at load and `threedog content ids` writes into the
85
+ * content files (node side, no engine). One list, so the warning and the writer always agree. Grid items are not here: they cannot load without an id.
86
+ * @param {{ pickups?: any[], props?: any[], templates?: Record<string, any> }} c
87
+ * @returns {{ file: 'pickups' | 'props', index: number, id: string }[]}
88
+ * @internal
89
+ */
90
+ export function missingIds(c) {
91
+ const out = [];
92
+ (Array.isArray(c.pickups) ? c.pickups : []).forEach((p, i) => { if (p && p.id == null) out.push({ file: 'pickups', index: i, id: pickupId(p, i) }); });
93
+ (Array.isArray(c.props) ? c.props : []).forEach((p, i) => { if (p?.template && p.id == null && stateful(c.templates?.[p.template])) out.push({ file: 'props', index: i, id: templateId(p, i) }); });
94
+ return out;
95
+ }