threedog 0.7.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +411 -1
  2. package/README.md +8 -11
  3. package/core/{Animator.js → assets/Animator.js} +30 -18
  4. package/core/{Assets.js → assets/Assets.js} +131 -56
  5. package/core/{Baked.js → assets/Baked.js} +4 -4
  6. package/core/assets/assetEntry.js +302 -0
  7. package/core/{assetHot.js → assets/assetHot.js} +9 -7
  8. package/core/{assetLoad.js → assets/assetLoad.js} +55 -16
  9. package/core/assets/assetLod.js +113 -0
  10. package/core/{assetManifest.js → assets/assetManifest.js} +19 -11
  11. package/core/{assetReport.js → assets/assetReport.js} +7 -14
  12. package/core/{namedModel.js → assets/namedModel.js} +17 -13
  13. package/core/{Audio.js → audio/Audio.js} +47 -25
  14. package/core/{audioRules.js → audio/audioRules.js} +8 -5
  15. package/core/{audioVoice.js → audio/audioVoice.js} +17 -30
  16. package/core/{Events.js → base/Events.js} +3 -3
  17. package/core/{I18n.js → base/I18n.js} +15 -12
  18. package/core/{Random.js → base/Random.js} +7 -4
  19. package/core/{Vars.js → base/Vars.js} +14 -4
  20. package/core/{easing.js → base/easing.js} +1 -1
  21. package/core/{errorCodes.js → base/errorCodes.js} +151 -125
  22. package/core/{errorHints.js → base/errorHints.js} +17 -10
  23. package/core/{errors.js → base/errors.js} +12 -10
  24. package/core/{events.generated.js → base/events.generated.js} +11 -0
  25. package/core/base/follows.js +26 -0
  26. package/core/base/math.js +66 -0
  27. package/core/{params.js → base/params.js} +5 -6
  28. package/core/base/saveValues.js +81 -0
  29. package/core/base/sections.js +97 -0
  30. package/core/base/spelling.js +32 -0
  31. package/core/base/util.js +32 -0
  32. package/core/{validate.js → base/validate.js} +34 -34
  33. package/core/{Engine.js → engine/Engine.js} +137 -91
  34. package/core/{Loading.js → engine/Loading.js} +34 -5
  35. package/core/{copies.js → engine/copies.js} +4 -4
  36. package/core/{headlessLoad.js → engine/headlessLoad.js} +32 -15
  37. package/core/{lifecycle.js → engine/lifecycle.js} +41 -34
  38. package/core/{loop.js → engine/loop.js} +88 -49
  39. package/core/engine/moduleSlots.js +176 -0
  40. package/core/{moduleTypes.js → engine/moduleTypes.js} +26 -14
  41. package/core/engine/modules.js +503 -0
  42. package/core/{page.js → engine/page.js} +59 -29
  43. package/core/{plugins.js → engine/plugins.js} +21 -12
  44. package/core/{services.js → engine/services.js} +50 -40
  45. package/core/{startup.js → engine/startup.js} +66 -54
  46. package/core/{Input.js → input/Input.js} +67 -39
  47. package/core/{inputContext.js → input/inputContext.js} +14 -5
  48. package/core/input/inputKeyboard.js +39 -0
  49. package/core/{inputPad.js → input/inputPad.js} +24 -3
  50. package/core/{inputPointer.js → input/inputPointer.js} +11 -3
  51. package/core/input/inputSeat.js +66 -0
  52. package/core/{inputTouch.js → input/inputTouch.js} +24 -7
  53. package/core/{Budget.js → inspect/Budget.js} +21 -20
  54. package/core/{DebugOverrides.js → inspect/DebugOverrides.js} +43 -18
  55. package/core/{Describe.js → inspect/Describe.js} +34 -26
  56. package/core/{Inspect.js → inspect/Inspect.js} +39 -10
  57. package/core/{InspectMaterials.js → inspect/InspectMaterials.js} +7 -8
  58. package/core/{InspectPerf.js → inspect/InspectPerf.js} +19 -13
  59. package/core/{InspectScene.js → inspect/InspectScene.js} +8 -5
  60. package/core/{MaterialInfo.js → inspect/MaterialInfo.js} +3 -2
  61. package/core/{UrlState.js → inspect/UrlState.js} +60 -24
  62. package/core/{catalog.js → inspect/catalog.js} +15 -8
  63. package/core/{checks.js → inspect/checks.js} +7 -5
  64. package/core/{debugView.js → inspect/debugView.js} +4 -4
  65. package/core/{describeRender.js → inspect/describeRender.js} +24 -22
  66. package/core/{describeText.js → inspect/describeText.js} +17 -8
  67. package/core/inspect/geometryWatch.js +38 -0
  68. package/core/{lightWatch.js → inspect/lightWatch.js} +8 -8
  69. package/core/inspect/metadata.generated.js +4140 -0
  70. package/core/{pictureWriters.js → inspect/pictureWriters.js} +130 -47
  71. package/core/{shaderCost.js → inspect/shaderCost.js} +1 -1
  72. package/core/inspect/toolDoor.js +21 -0
  73. package/core/inspect/valueHistory.js +35 -0
  74. package/core/{Ops.js → ops/Ops.js} +44 -14
  75. package/core/{control.js → ops/control.js} +57 -31
  76. package/core/ops/holds.js +140 -0
  77. package/core/{opsAtomic.js → ops/opsAtomic.js} +18 -5
  78. package/core/{opsCheck.js → ops/opsCheck.js} +11 -10
  79. package/core/{opsFail.js → ops/opsFail.js} +5 -7
  80. package/core/{opsGuard.js → ops/opsGuard.js} +3 -3
  81. package/core/{opsRun.js → ops/opsRun.js} +9 -6
  82. package/core/{owned.js → ops/owned.js} +33 -19
  83. package/core/{sharedPoint.js → ops/sharedPoint.js} +13 -16
  84. package/core/{stackFrames.js → ops/stackFrames.js} +2 -2
  85. package/core/{stacks.js → ops/stacks.js} +34 -15
  86. package/core/{wrap.js → ops/wrap.js} +8 -6
  87. package/core/{SaveStore.js → saves/SaveStore.js} +53 -27
  88. package/core/{Saves.js → saves/Saves.js} +171 -54
  89. package/core/saves/saveApply.js +312 -0
  90. package/core/{saveFiles.js → saves/saveFiles.js} +45 -38
  91. package/core/{saveVersions.js → saves/saveVersions.js} +24 -23
  92. package/core/saves/session.js +231 -0
  93. package/core/saves/stateReplace.js +184 -0
  94. package/core/{Rays.js → scene/Rays.js} +44 -30
  95. package/core/{Views.js → scene/Views.js} +16 -8
  96. package/core/{adaptive.js → scene/adaptive.js} +19 -9
  97. package/core/{canvasBox.js → scene/canvasBox.js} +4 -3
  98. package/core/scene/compositeGround.js +72 -0
  99. package/core/scene/floor.js +17 -0
  100. package/core/{gameLights.js → scene/gameLights.js} +17 -7
  101. package/core/{grayMap.js → scene/grayMap.js} +8 -2
  102. package/core/{grid.js → scene/grid.js} +6 -4
  103. package/core/{gridLoad.js → scene/gridLoad.js} +1 -1
  104. package/core/scene/ground.contract.js +14 -0
  105. package/core/scene/ground.js +139 -0
  106. package/core/{movement.js → scene/movement.js} +3 -3
  107. package/core/{pictureSlots.js → scene/pictureSlots.js} +2 -2
  108. package/core/scene/pixel.js +154 -0
  109. package/core/scene/pixelRatio.js +167 -0
  110. package/core/{sceneDelta.js → scene/sceneDelta.js} +5 -5
  111. package/core/{sceneMethods.js → scene/sceneMethods.js} +43 -15
  112. package/core/scene/stepPoses.js +60 -0
  113. package/core/{targeting.js → scene/targeting.js} +4 -5
  114. package/core/{thingExplain.js → scene/thingExplain.js} +7 -6
  115. package/core/{thingOps.js → scene/thingOps.js} +25 -16
  116. package/core/{things.js → scene/things.js} +18 -5
  117. package/core/{threePatches.js → scene/threePatches.js} +1 -1
  118. package/core/{tier.js → scene/tier.js} +10 -0
  119. package/core/scene/view.js +161 -0
  120. package/core/{Batching.js → stream/Batching.js} +85 -28
  121. package/core/{Stream.js → stream/Stream.js} +80 -38
  122. package/core/{batchGroups.js → stream/batchGroups.js} +11 -9
  123. package/core/{chunkStream.js → stream/chunkStream.js} +40 -0
  124. package/core/{scatter.js → stream/scatter.js} +7 -4
  125. package/core/{streamSources.js → stream/streamSources.js} +14 -8
  126. package/core/{Commits.js → threads/Commits.js} +17 -11
  127. package/core/{Jobs.js → threads/Jobs.js} +25 -13
  128. package/core/{Threads.js → threads/Threads.js} +21 -18
  129. package/core/{threadPure.js → threads/threadPure.js} +7 -5
  130. package/core/{threadServe.js → threads/threadServe.js} +3 -3
  131. package/core/{Clock.js → time/Clock.js} +20 -11
  132. package/core/{dayTime.js → time/dayTime.js} +5 -1
  133. package/core/{skip.js → time/skip.js} +28 -21
  134. package/core/{time.js → time/time.js} +32 -20
  135. package/core/{uiClock.js → time/uiClock.js} +4 -4
  136. package/docs/AI.md +92 -72
  137. package/docs/API.md +33 -28
  138. package/docs/CODEMAP.md +121 -200
  139. package/docs/COMMANDS.md +77 -70
  140. package/docs/CONVENTIONS.md +167 -24
  141. package/docs/MIGRATING-0.8.md +171 -0
  142. package/docs/MIGRATING-1.0.md +101 -0
  143. package/docs/THREE.md +140 -38
  144. package/docs/api/assets.md +12 -13
  145. package/docs/api/audio.md +6 -5
  146. package/docs/api/budget.md +4 -4
  147. package/docs/api/calendar.md +10 -11
  148. package/docs/api/cameraRig.md +32 -29
  149. package/docs/api/characters.md +35 -24
  150. package/docs/api/clock.md +1 -1
  151. package/docs/api/collider3d.md +9 -0
  152. package/docs/api/collision.md +12 -9
  153. package/docs/api/content.md +18 -17
  154. package/docs/api/dialogue.md +5 -4
  155. package/docs/api/engine.md +58 -54
  156. package/docs/api/events.md +17 -6
  157. package/docs/api/flow.md +1 -1
  158. package/docs/api/grids.md +1 -1
  159. package/docs/api/ground.md +6 -7
  160. package/docs/api/hud.md +2 -2
  161. package/docs/api/i18n.md +6 -6
  162. package/docs/api/input.md +9 -8
  163. package/docs/api/interactions.md +5 -5
  164. package/docs/api/inventory.md +10 -10
  165. package/docs/api/jobs.md +5 -5
  166. package/docs/api/level.md +10 -9
  167. package/docs/api/lightPool.md +1 -6
  168. package/docs/api/music.md +3 -3
  169. package/docs/api/nav.md +14 -12
  170. package/docs/api/openWorld.md +1 -1
  171. package/docs/api/particles.md +10 -7
  172. package/docs/api/photo.md +4 -2
  173. package/docs/api/pickups.md +3 -3
  174. package/docs/api/post.md +21 -5
  175. package/docs/api/quests.md +7 -5
  176. package/docs/api/rays.md +7 -7
  177. package/docs/api/rigid.md +29 -19
  178. package/docs/api/saves.md +13 -11
  179. package/docs/api/settings.md +9 -8
  180. package/docs/api/sky.md +8 -7
  181. package/docs/api/stream.md +8 -9
  182. package/docs/api/swarm.md +34 -0
  183. package/docs/api/terrain.md +6 -8
  184. package/docs/api/terrainDraw.md +2 -2
  185. package/docs/api/timeline.md +4 -4
  186. package/docs/api/tools.md +27 -22
  187. package/docs/api/triggers.md +2 -0
  188. package/docs/api/vars.md +1 -1
  189. package/docs/api/vegetation.md +4 -3
  190. package/docs/api/vegetationDraw.md +2 -2
  191. package/docs/api/water.md +7 -3
  192. package/docs/api/weather.md +27 -12
  193. package/docs/api/weatherDraw.md +4 -4
  194. package/docs/api/world.md +6 -6
  195. package/docs/recipes/01-new-game.md +28 -43
  196. package/docs/recipes/02-npc.md +21 -23
  197. package/docs/recipes/03-items-pickups.md +37 -53
  198. package/docs/recipes/04-quests.md +5 -4
  199. package/docs/recipes/05-props-bake.md +34 -44
  200. package/docs/recipes/06-clock-events.md +31 -22
  201. package/docs/recipes/07-flow-scenes-pause.md +30 -32
  202. package/docs/recipes/08-weather-sky.md +91 -37
  203. package/docs/recipes/09-materials-lights-models.md +25 -39
  204. package/docs/recipes/10-blender-level.md +22 -11
  205. package/docs/recipes/11-vehicles.md +44 -24
  206. package/docs/recipes/12-navmesh.md +60 -15
  207. package/docs/recipes/13-animation.md +70 -22
  208. package/docs/recipes/14-custom-module.md +33 -20
  209. package/docs/recipes/15-perf.md +51 -28
  210. package/docs/recipes/16-dev-bridge.md +39 -58
  211. package/docs/recipes/18-world.md +49 -28
  212. package/docs/recipes/19-shooting-picking.md +7 -4
  213. package/docs/recipes/20-content-actions-save.md +55 -40
  214. package/docs/recipes/21-camera.md +47 -25
  215. package/docs/recipes/22-shop-gold.md +21 -16
  216. package/docs/recipes/23-ops.md +28 -24
  217. package/docs/recipes/26-ui-parts.md +25 -14
  218. package/docs/recipes/27-net.md +3 -5
  219. package/docs/recipes/28-terrain.md +119 -23
  220. package/docs/recipes/29-grid.md +3 -3
  221. package/docs/recipes/30-templates.md +63 -30
  222. package/docs/recipes/31-audio.md +7 -7
  223. package/docs/recipes/32-action-game.md +21 -11
  224. package/docs/recipes/33-stream-sources.md +6 -3
  225. package/docs/recipes/34-environment-lighting.md +72 -25
  226. package/docs/recipes/35-picture-from-reference.md +20 -23
  227. package/docs/recipes/36-ground-plants.md +106 -0
  228. package/docs/recipes/40-scene.md +18 -21
  229. package/docs/recipes/43-shader-patches-surfaces.md +27 -48
  230. package/docs/recipes/44-water-weather-hooks.md +56 -50
  231. package/docs/recipes/45-cascaded-shadows.md +41 -20
  232. package/docs/recipes/46-blender-art-route.md +9 -10
  233. package/docs/recipes/49-game-module-contract.md +7 -6
  234. package/docs/recipes/50-own-renderer.md +3 -2
  235. package/docs/recipes/51-capability-catalog.md +14 -8
  236. package/docs/recipes/52-around-the-picture.md +56 -100
  237. package/docs/recipes/53-ground-up-close.md +61 -24
  238. package/docs/recipes/55-mods-time-wrap.md +17 -20
  239. package/docs/recipes/56-webgpu-tsl.md +28 -15
  240. package/docs/recipes/57-control.md +39 -12
  241. package/docs/recipes/58-input.md +15 -2
  242. package/docs/recipes/59-depth-post-effects.md +1 -1
  243. package/docs/recipes/60-judge-the-picture.md +30 -25
  244. package/docs/recipes/62-picture-code.md +129 -39
  245. package/docs/recipes/63-third-person-start.md +19 -5
  246. package/docs/recipes/64-particles.md +54 -5
  247. package/docs/recipes/65-swarm.md +140 -0
  248. package/docs/recipes/66-common-tasks.md +313 -0
  249. package/examples/action/.threedog/content-index.json +1 -1
  250. package/examples/action/GAMEMAP.md +5 -5
  251. package/examples/perf-island/.threedog/content-index.json +1 -0
  252. package/examples/{sheepisland → perf-island}/GAMEMAP.md +15 -14
  253. package/examples/{sheepisland → perf-island}/assets.js +1 -1
  254. package/examples/{sheepisland → perf-island}/main.js +8 -8
  255. package/examples/{sheepisland → perf-island}/models.js +1 -1
  256. package/examples/{sheepisland → perf-island}/params.js +1 -1
  257. package/examples/{sheepisland → perf-island}/picture/index.js +1 -1
  258. package/examples/{sheepisland → perf-island}/picture/palette.js +2 -2
  259. package/examples/{sheepisland → perf-island}/views.js +1 -1
  260. package/examples/plain-picture/GAMEMAP.md +4 -1
  261. package/examples/rc2d/GAMEMAP.md +4 -3
  262. package/examples/rc2d/main.js +1 -3
  263. package/examples/rc2d/rc2d.js +1 -1
  264. package/examples/styletest/.threedog/content-index.json +1 -1
  265. package/examples/styletest/GAMEMAP.md +6 -5
  266. package/examples/techniques/contact-shadows/contactShadows.js +1 -1
  267. package/examples/techniques/contact-shadows/main.js +1 -1
  268. package/examples/techniques/interior-light/main.js +1 -1
  269. package/examples/techniques/modular-building/README.md +7 -6
  270. package/examples/techniques/outlines-and-rim/picture/post.js +1 -1
  271. package/examples/techniques/procedural-animation/README.md +1 -1
  272. package/examples/webgpu-tsl/GAMEMAP.md +2 -1
  273. package/examples/world/.threedog/content-index.json +1 -1
  274. package/examples/world/GAMEMAP.md +9 -7
  275. package/examples/world/main.js +3 -3
  276. package/examples/world/picture/sky.js +1 -1
  277. package/index.d.ts +16 -12
  278. package/index.js +53 -32
  279. package/llms.txt +11 -14
  280. package/modules/ambience/Ambience.js +16 -11
  281. package/modules/calendar/Calendar.js +19 -19
  282. package/modules/calendar/index.js +18 -16
  283. package/modules/calendar/schedule.js +11 -6
  284. package/modules/calendar/seasons.js +7 -7
  285. package/modules/camera/FirstPersonCamera.js +5 -5
  286. package/modules/camera/FixedCamera.js +43 -30
  287. package/modules/camera/FollowCamera.js +24 -15
  288. package/modules/camera/RtsCamera.js +12 -11
  289. package/modules/camera/common.js +72 -37
  290. package/modules/camera/contract.js +1 -0
  291. package/modules/camera/pixelSnap.js +62 -0
  292. package/modules/characters/Character.js +166 -70
  293. package/modules/characters/NPC.js +84 -44
  294. package/modules/characters/assetModel.js +16 -12
  295. package/modules/characters/astar.js +48 -27
  296. package/modules/characters/behaviors.js +4 -5
  297. package/modules/characters/character.contract.js +21 -0
  298. package/modules/characters/contract.js +17 -3
  299. package/modules/characters/index.js +240 -226
  300. package/modules/characters/moveHelpers.js +88 -12
  301. package/modules/characters/mover.contract.js +14 -0
  302. package/modules/characters/movers/common.js +22 -18
  303. package/modules/characters/movers/manual.js +1 -1
  304. package/modules/characters/movers/rapier.js +18 -10
  305. package/modules/characters/movers/simple.js +26 -13
  306. package/modules/characters/movers/support.js +24 -13
  307. package/modules/characters/npcAvoid.js +19 -16
  308. package/modules/characters/npcSim.js +88 -32
  309. package/modules/characters/npcView.js +19 -11
  310. package/modules/characters/pathAsync.js +81 -29
  311. package/modules/characters/pathJob.js +38 -21
  312. package/modules/characters/pathWorker.js +1 -1
  313. package/modules/characters/player.js +120 -0
  314. package/modules/characters/playerStrings.js +2 -2
  315. package/modules/characters/proceduralRig.js +2 -2
  316. package/modules/characters/seat.js +56 -0
  317. package/modules/characters/useModel.js +3 -3
  318. package/modules/characters/vehicle.contract.js +8 -5
  319. package/modules/characters/walkTo.js +40 -33
  320. package/modules/collision/Collision.js +69 -45
  321. package/modules/collision/contract.js +15 -0
  322. package/modules/collision/grid.js +6 -1
  323. package/modules/content/explain.js +2 -3
  324. package/modules/content/fields.js +24 -3
  325. package/modules/content/ids.js +5 -3
  326. package/modules/content/index.js +132 -114
  327. package/modules/content/loader.js +117 -140
  328. package/modules/content/markers.js +25 -0
  329. package/modules/content/models.js +54 -17
  330. package/modules/content/packs.js +5 -4
  331. package/modules/content/parts.js +2 -2
  332. package/modules/content/places.js +36 -0
  333. package/modules/content/props.js +22 -17
  334. package/modules/content/rules.js +47 -61
  335. package/modules/content/stages.js +7 -7
  336. package/modules/content/templates.js +80 -49
  337. package/modules/content/words.js +47 -0
  338. package/modules/debug/DebugPanel.js +14 -45
  339. package/modules/flow/contract.js +2 -1
  340. package/modules/flow/index.js +30 -16
  341. package/modules/gameplay/Container.js +17 -13
  342. package/modules/gameplay/Containers.js +23 -6
  343. package/modules/gameplay/Dialogue.js +93 -34
  344. package/modules/gameplay/Interactions.js +93 -51
  345. package/modules/gameplay/Inventory.js +64 -22
  346. package/modules/gameplay/Quests.js +146 -30
  347. package/modules/gameplay/boxOps.js +8 -1
  348. package/modules/gameplay/dialogueBubbles.js +16 -12
  349. package/modules/gameplay/inventoryOps.js +11 -8
  350. package/modules/gameplay/pickups.js +63 -37
  351. package/modules/gameplay/questLog.js +4 -2
  352. package/modules/gameplay/questSave.js +9 -4
  353. package/modules/gameplay/quests.contract.js +1 -1
  354. package/modules/grid/Grid.js +2 -2
  355. package/modules/grid/Layer.js +12 -8
  356. package/modules/grid/index.js +28 -23
  357. package/modules/grid/ops.js +43 -46
  358. package/modules/grid/preview.js +7 -7
  359. package/modules/grid/tiles.js +6 -6
  360. package/modules/hlod/index.js +42 -57
  361. package/modules/hud/index.js +22 -14
  362. package/modules/hud/parts.js +8 -8
  363. package/modules/level/contract.js +16 -0
  364. package/modules/level/heightfield.js +29 -31
  365. package/modules/level/index.js +113 -161
  366. package/modules/level/load.js +196 -0
  367. package/modules/level/meshes.js +65 -0
  368. package/modules/level/nodes.js +40 -23
  369. package/modules/lights/index.js +33 -183
  370. package/modules/lights/slots.js +93 -0
  371. package/modules/lights/sources.js +90 -0
  372. package/modules/music/Music.js +34 -28
  373. package/modules/music/rules.js +1 -1
  374. package/modules/nav/contract.js +16 -0
  375. package/modules/nav/index.js +180 -49
  376. package/modules/nav/navPath.js +45 -10
  377. package/modules/net/Client.js +7 -7
  378. package/modules/net/Host.js +7 -7
  379. package/modules/net/Net.js +1 -1
  380. package/modules/net/index.js +6 -5
  381. package/modules/net/sync.js +2 -2
  382. package/modules/net/transports.js +2 -2
  383. package/modules/particles/Particles.js +95 -29
  384. package/modules/particles/effect.js +86 -32
  385. package/modules/particles/shaders.js +19 -1
  386. package/modules/photo/Photo.js +23 -23
  387. package/modules/rigid/RigidBodies.js +255 -89
  388. package/modules/rigid/Vehicles.js +17 -8
  389. package/modules/rigid/collider3d.contract.js +26 -0
  390. package/modules/rigid/ragdoll.js +298 -0
  391. package/modules/rigid/ragdollBones.js +209 -0
  392. package/modules/rigid/refresh.js +10 -0
  393. package/modules/rigid/sync.js +51 -20
  394. package/modules/settings/Settings.js +177 -61
  395. package/modules/settings/apply.js +20 -13
  396. package/modules/settings/sections.js +19 -14
  397. package/modules/settings/strings.js +2 -2
  398. package/modules/settings/view.js +3 -3
  399. package/modules/sky/Sky.js +29 -22
  400. package/modules/sky/clouds.js +7 -7
  401. package/modules/sky/dome.js +33 -20
  402. package/modules/sky/domeLayers.js +9 -9
  403. package/modules/sky/environment.js +6 -6
  404. package/modules/sky/frame.js +19 -10
  405. package/modules/sky/season.js +7 -1
  406. package/modules/sky/shader.js +24 -25
  407. package/modules/sky/skyModule.js +17 -28
  408. package/modules/sky/tint.js +1 -1
  409. package/modules/swarm/Swarm.js +356 -0
  410. package/modules/swarm/draw.js +68 -0
  411. package/modules/swarm/grid.js +63 -0
  412. package/modules/terrain/ChunkManager.js +71 -59
  413. package/modules/terrain/chunkQueries.js +7 -24
  414. package/modules/terrain/chunkWorker.js +1 -1
  415. package/modules/terrain/draw.js +14 -11
  416. package/modules/terrain/index.js +42 -42
  417. package/modules/terrain/terrainColorMap.js +6 -3
  418. package/modules/terrain/terrainDefaults.js +2 -1
  419. package/modules/terrain/terrainEdit.js +45 -29
  420. package/modules/terrain/terrainGen.js +19 -12
  421. package/modules/terrain/terrainIsland.js +2 -2
  422. package/modules/terrain/terrainMesh.js +7 -6
  423. package/modules/terrain/terrainShape.js +8 -10
  424. package/modules/terrain/terrainShapeMain.js +3 -3
  425. package/modules/timeline/Timeline.js +83 -43
  426. package/modules/timeline/Tween.js +25 -19
  427. package/modules/timeline/shots.js +24 -17
  428. package/modules/triggers/index.js +95 -28
  429. package/modules/vegetation/Vegetation.js +34 -26
  430. package/modules/vegetation/densityMap.js +4 -7
  431. package/modules/vegetation/draw.js +39 -18
  432. package/modules/vegetation/groundChunks.js +21 -38
  433. package/modules/vegetation/index.js +37 -12
  434. package/modules/vegetation/modelGeometry.js +3 -6
  435. package/modules/vegetation/nearFade.js +1 -1
  436. package/modules/water/Water.js +20 -16
  437. package/modules/water/surface.js +3 -3
  438. package/modules/weather/Weather.js +52 -40
  439. package/modules/weather/particles.js +8 -8
  440. package/modules/weather/weatherDraw.js +28 -23
  441. package/modules/world/World.js +28 -15
  442. package/modules/world/explain.js +1 -1
  443. package/modules/world/index.js +30 -17
  444. package/modules/world/persist.js +90 -27
  445. package/modules/world/pos.js +5 -5
  446. package/modules/world/records.js +37 -11
  447. package/modules/world/sim.js +78 -27
  448. package/modules/world/simFar.js +2 -2
  449. package/modules/world/state.js +43 -11
  450. package/modules/world/thingSource.js +20 -5
  451. package/modules/world/views.js +27 -14
  452. package/package.json +48 -7
  453. package/presets.js +1 -3
  454. package/render/PostFX.js +83 -53
  455. package/render/backend.js +31 -33
  456. package/render/cascades.js +17 -12
  457. package/render/cascades.tsl.js +5 -8
  458. package/render/daylight.js +20 -3
  459. package/render/detail.js +8 -7
  460. package/render/effects.js +28 -25
  461. package/render/fuse.js +3 -3
  462. package/render/fx/cloudShadow.tsl.js +3 -3
  463. package/render/fx/detail.tsl.js +1 -1
  464. package/render/fx/index.js +5 -10
  465. package/render/fx/library.tsl.js +11 -0
  466. package/render/fx/lighting.tsl.js +2 -1
  467. package/render/fx/nodeErrors.tsl.js +2 -2
  468. package/render/fx/objectOrigin.tsl.js +1 -2
  469. package/render/fx/particles.tsl.js +8 -6
  470. package/render/fx/patchNodes.tsl.js +5 -15
  471. package/render/fx/postWebGPU.tsl.js +30 -26
  472. package/render/fx/sky.tsl.js +15 -17
  473. package/render/fx/uniforms.tsl.js +4 -4
  474. package/render/fx/wind.tsl.js +1 -1
  475. package/render/fxNumbers.js +3 -0
  476. package/render/layers.js +2 -2
  477. package/render/lighting.js +5 -3
  478. package/render/lightmap.js +41 -21
  479. package/render/lights.js +6 -6
  480. package/render/lit.js +24 -0
  481. package/render/materials.js +8 -7
  482. package/render/mergeCommon.js +22 -0
  483. package/render/modeling.js +2 -2
  484. package/render/occlusion.js +62 -15
  485. package/render/ownFrame.js +4 -4
  486. package/render/patches.js +15 -15
  487. package/render/postWebGL.js +15 -12
  488. package/render/probes.js +41 -19
  489. package/render/recordSweep.js +117 -0
  490. package/render/shaderErrors.js +10 -9
  491. package/render/shadowCache.tsl.js +107 -0
  492. package/render/shadowTypes.js +9 -0
  493. package/{core → render}/shadows.js +59 -13
  494. package/render/slots.js +7 -7
  495. package/render/terms.js +22 -24
  496. package/render/uniformDecl.js +1 -1
  497. package/types/core.d.ts +336 -202
  498. package/types/gameplay.d.ts +254 -130
  499. package/types/generated/core/{Audio.d.ts → audio/Audio.d.ts} +22 -7
  500. package/types/generated/core/{audioVoice.d.ts → audio/audioVoice.d.ts} +2 -2
  501. package/types/generated/core/{Events.d.ts → base/Events.d.ts} +4 -4
  502. package/types/generated/core/{I18n.d.ts → base/I18n.d.ts} +8 -16
  503. package/types/generated/core/{Random.d.ts → base/Random.d.ts} +4 -3
  504. package/types/generated/core/{page.d.ts → engine/page.d.ts} +8 -9
  505. package/types/generated/core/{Input.d.ts → input/Input.d.ts} +28 -10
  506. package/types/generated/core/input/inputSeat.d.ts +26 -0
  507. package/types/generated/core/{Budget.d.ts → inspect/Budget.d.ts} +36 -26
  508. package/types/generated/core/{DebugOverrides.d.ts → inspect/DebugOverrides.d.ts} +17 -3
  509. package/types/generated/core/{Ops.d.ts → ops/Ops.d.ts} +6 -4
  510. package/types/generated/core/{control.d.ts → ops/control.d.ts} +14 -10
  511. package/types/generated/core/{Saves.d.ts → saves/Saves.d.ts} +62 -18
  512. package/types/generated/core/{session.d.ts → saves/session.d.ts} +3 -2
  513. package/types/generated/core/{Rays.d.ts → scene/Rays.d.ts} +8 -27
  514. package/types/generated/core/{Views.d.ts → scene/Views.d.ts} +2 -2
  515. package/types/generated/core/{Batching.d.ts → stream/Batching.d.ts} +7 -7
  516. package/types/generated/core/{Stream.d.ts → stream/Stream.d.ts} +22 -18
  517. package/types/generated/core/{Commits.d.ts → threads/Commits.d.ts} +1 -1
  518. package/types/generated/core/{Jobs.d.ts → threads/Jobs.d.ts} +6 -6
  519. package/types/generated/core/{Threads.d.ts → threads/Threads.d.ts} +4 -4
  520. package/types/generated/modules/calendar/Calendar.d.ts +10 -11
  521. package/types/generated/modules/debug/DebugPanel.d.ts +1 -9
  522. package/types/generated/modules/grid/Grid.d.ts +1 -0
  523. package/types/generated/modules/grid/Layer.d.ts +1 -1
  524. package/types/generated/modules/grid/index.d.ts +3 -3
  525. package/types/generated/modules/music/Music.d.ts +7 -5
  526. package/types/generated/modules/particles/Particles.d.ts +5 -4
  527. package/types/generated/modules/sky/Sky.d.ts +21 -10
  528. package/types/generated/modules/swarm/Swarm.d.ts +80 -0
  529. package/types/generated/modules/timeline/Timeline.d.ts +7 -5
  530. package/types/generated/modules/water/Water.d.ts +1 -0
  531. package/types/generated/modules/weather/Weather.d.ts +14 -16
  532. package/types/generated/modules/weather/weatherDraw.d.ts +3 -3
  533. package/types/generated/modules/world/World.d.ts +11 -7
  534. package/types/generated/render/PostFX.d.ts +21 -23
  535. package/types/generated/render/materials.d.ts +1 -0
  536. package/types/generated/render/occlusion.d.ts +9 -0
  537. package/types/generated/render/patches.d.ts +1 -0
  538. package/types/generated/ui/Focus.d.ts +1 -0
  539. package/types/generated/ui/UI.d.ts +1 -0
  540. package/types/nav.d.ts +47 -15
  541. package/types/physics.d.ts +150 -73
  542. package/types/pixel.d.ts +75 -0
  543. package/types/tsl.d.ts +37 -4
  544. package/types/world.d.ts +48 -75
  545. package/ui/Focus.js +10 -9
  546. package/ui/Parts.js +13 -5
  547. package/ui/UI.js +7 -7
  548. package/ui/defaults.js +3 -2
  549. package/ui/theme.js +7 -5
  550. package/core/assetEntry.js +0 -109
  551. package/core/engineCamera.js +0 -32
  552. package/core/ground.js +0 -104
  553. package/core/holds.js +0 -134
  554. package/core/math.js +0 -48
  555. package/core/moduleSlots.js +0 -100
  556. package/core/modules.js +0 -314
  557. package/core/saveApply.js +0 -210
  558. package/core/saveValues.js +0 -46
  559. package/core/session.js +0 -174
  560. package/core/shadowTypes.js +0 -16
  561. package/core/util.js +0 -17
  562. package/core/view.js +0 -43
  563. package/docs/MIGRATING-0.3.md +0 -248
  564. package/docs/MIGRATING-0.4.md +0 -320
  565. package/docs/MIGRATING-0.5.md +0 -68
  566. package/docs/MIGRATING-0.6.md +0 -126
  567. package/docs/PERF.md +0 -245
  568. package/docs/recipes/36-sky-ground-plants.md +0 -158
  569. package/docs/recipes/37-terrain-hooks.md +0 -115
  570. package/docs/recipes/38-environment-hooks.md +0 -67
  571. package/docs/recipes/42-terrain-shape.md +0 -64
  572. package/docs/recipes/47-island-snow-backdrop.md +0 -43
  573. package/docs/recipes/54-three-idioms.md +0 -88
  574. package/examples/plain-picture/FINDINGS.md +0 -53
  575. package/examples/sheepisland/.threedog/content-index.json +0 -1
  576. package/modules/camera/projection.js +0 -21
  577. /package/core/{mulberry32.js → base/mulberry32.js} +0 -0
  578. /package/core/{inputDefaults.js → input/inputDefaults.js} +0 -0
  579. /package/core/{textureBytes.js → inspect/textureBytes.js} +0 -0
  580. /package/core/{actor.js → ops/actor.js} +0 -0
  581. /package/core/{opsHistory.js → ops/opsHistory.js} +0 -0
  582. /package/core/{saveIds.js → saves/saveIds.js} +0 -0
  583. /package/core/{screenToGround.js → scene/screenToGround.js} +0 -0
  584. /package/core/{cells.js → stream/cells.js} +0 -0
  585. /package/core/{streamCells.js → stream/streamCells.js} +0 -0
  586. /package/core/{pureWorker.js → threads/pureWorker.js} +0 -0
  587. /package/examples/{sheepisland → perf-island}/content/index.js +0 -0
  588. /package/examples/{sheepisland → perf-island}/content/props.js +0 -0
  589. /package/examples/{sheepisland → perf-island}/content/templates.js +0 -0
  590. /package/examples/{sheepisland → perf-island}/content/vegetation.js +0 -0
  591. /package/examples/{sheepisland → perf-island}/picture/lights.js +0 -0
  592. /package/examples/{sheepisland → perf-island}/picture/materials.js +0 -0
  593. /package/examples/{sheepisland → perf-island}/picture/sky.js +0 -0
@@ -0,0 +1,154 @@
1
+ // Pixel-game math and the one object built on it (threedog/pixel). One art pixel on screen is `cell` = 1 / pixelsPerMeter world units along the camera's right and up
2
+ // axes. This file is the only place that derives those axes: the cameras' pixelSnap (modules/camera/pixelSnap.js) and pixelSprite call pixelGrid, so the camera and
3
+ // what it shows cannot round on two different grids. No default look: materials come from the game.
4
+ //
5
+ // Why rounding happens on screen axes and not world axes: a camera turned 45 degrees moves diagonally across world x and z, so world-axis rounding (or a world-axis
6
+ // clamp rounded afterwards) lands between art pixels. Why the view's corner goes on the lattice and not its center: with an odd number of art pixels the center sits on half
7
+ // a pixel, and every sprite edge would then fall exactly on a pixel center, where nearest sampling picks either side from frame to frame. The grid has no anchor to
8
+ // keep: its lattice runs through the world origin and the axes are read fresh on each call, so a zoom or a turn needs no reset.
9
+ import * as THREE from 'three';
10
+ import { codedError } from '../base/errorHints.js';
11
+
12
+ const _q = new THREE.Quaternion(), _pq = new THREE.Quaternion(), _p = new THREE.Vector3(), _s = new THREE.Vector3(), _y = new THREE.Vector3(0, 1, 0);
13
+ // a view looking almost straight down would stretch a vertical sprite without limit; a sprite that tall is already unreadable
14
+ const MIN_COS_PITCH = 0.05;
15
+ const TIE = 1e-4;
16
+
17
+ /**
18
+ * The art pixel grid of an orthographic camera. Pure math on the camera's current orientation.
19
+ * @param {{ camera: THREE.Camera, pixelsPerMeter: number }} o
20
+ */
21
+ export function pixelGrid({ camera, pixelsPerMeter } = /** @type {any} */ ({})) {
22
+ if (!camera?.isCamera) throw codedError('camera-option', 'pixelGrid({ camera, pixelsPerMeter }): camera is the camera that draws the picture, usually engine.camera');
23
+ if (!(pixelsPerMeter > 0)) throw codedError('camera-option', `pixelGrid({ pixelsPerMeter }): how many art pixels one world unit covers, above 0; got ${JSON.stringify(pixelsPerMeter)}`);
24
+ const t = 1 / pixelsPerMeter, right = new THREE.Vector3(), up = new THREE.Vector3(), forward = new THREE.Vector3(), axes = { right, up, forward };
25
+ const placed = { position: new THREE.Vector3(), error: { x: 0, y: 0 } }, shift = { x: 0, y: 0 }, _t = new THREE.Vector3();
26
+ const round = v => Math.round(v / t) * t;
27
+ const grid = {
28
+ camera, pixelsPerMeter, cell: t,
29
+ /** The camera's unit right, up and forward axes now. Throws on a perspective camera: its screen axes change across the picture, so no grid fits */
30
+ axes() {
31
+ if (!grid.camera.isOrthographicCamera) throw codedError('camera-option', "pixelGrid and pixelSnap work on an orthographic camera only: a perspective view has no single art pixel size. Set projection: 'orthographic' on the camera, or drop pixelSnap");
32
+ grid.camera.getWorldQuaternion(_q);
33
+ right.set(1, 0, 0).applyQuaternion(_q); up.set(0, 1, 0).applyQuaternion(_q); forward.set(0, 0, -1).applyQuaternion(_q);
34
+ return axes;
35
+ },
36
+ /** World point -> meters along the screen axes: x right, y up, z forward */
37
+ toScreen(world, out = new THREE.Vector3()) {
38
+ grid.axes();
39
+ return out.set(right.dot(world), up.dot(world), forward.dot(world));
40
+ },
41
+ /** Meters along the screen axes -> world point */
42
+ toWorld(screen, out = new THREE.Vector3()) {
43
+ grid.axes();
44
+ const { x, y, z } = screen;
45
+ return out.copy(right).multiplyScalar(x).addScaledVector(up, y).addScaledVector(forward, z);
46
+ },
47
+ /** The world point rounded to the art grid on the two screen axes; depth stays, so what is in front stays in front */
48
+ snap(world, out = new THREE.Vector3()) {
49
+ const s = grid.toScreen(world, _s);
50
+ return grid.toWorld(s.set(round(s.x), round(s.y), s.z), out);
51
+ },
52
+ /** How far snap moves this point, in art pixels on each screen axis (-0.5 to 0.5). Handed over for a game that wants to use the leftover */
53
+ error(world) {
54
+ const s = grid.toScreen(world, _s);
55
+ return { x: (round(s.x) - s.x) / t, y: (round(s.y) - s.y) / t };
56
+ },
57
+ /**
58
+ * snap for what the camera follows. Its offset from the camera's exact position is what must stay steady on screen, so it takes the rounding the camera got in
59
+ * place(). snap() would round the two on their own, and they would step on different frames: a one-pixel shake. Use it for that one object: a thing standing
60
+ * still would creep against the ground as the leftover changes.
61
+ */
62
+ snapFollowed(world, out = new THREE.Vector3()) {
63
+ const s = grid.toScreen(world, _s);
64
+ // the small bias: with an odd buffer a follower at the view's center is exactly half a pixel off the grid, and float noise would flip that tie every frame
65
+ return grid.toWorld(s.set(round(s.x + shift.x + t * TIE), round(s.y + shift.y + t * TIE), s.z), out);
66
+ },
67
+ /** World units of view height a picture of `rows` art pixels needs */
68
+ viewHeight(rows) { return rows * t; },
69
+ /** Does the camera really show rows / pixelsPerMeter of the world? If not, the grid and the picture disagree. Read from the projection, so camera.zoom counts */
70
+ agrees(rows) { return Math.abs(2 / grid.camera.projectionMatrix.elements[5] - rows * t) <= rows * t * 1e-6; },
71
+ /**
72
+ * Where a camera wanting `position` goes: clamp, then round. Bounds { minX, maxX, minZ, maxZ, minY?, maxY? } are projected on the screen axes and rounded inward, and
73
+ * the view's corner is clamped to them, so the rounding after it cannot cross a bound. A level smaller than the view is centered on that axis. Result: { position,
74
+ * error } (both reused between calls), error in art pixels from the clamped position.
75
+ * @param {THREE.Vector3} position @param {{ columns: number, rows: number, bounds?: any }} view
76
+ */
77
+ place(position, { columns, rows, bounds }) {
78
+ const fit = (v, size, key, axis) => {
79
+ let corner = v - size / 2;
80
+ if (bounds) {
81
+ let lo = Infinity, hi = -Infinity;
82
+ for (const x of [bounds.minX, bounds.maxX]) for (const y of [bounds.minY ?? 0, bounds.maxY ?? 0]) for (const z of [bounds.minZ, bounds.maxZ]) {
83
+ const d = x * axis.x + y * axis.y + z * axis.z;
84
+ if (d < lo) lo = d;
85
+ if (d > hi) hi = d;
86
+ }
87
+ const a = Math.ceil(lo / t) * t, b = Math.floor((hi - size) / t) * t;
88
+ corner = a > b ? (lo + hi - size) / 2 : Math.min(b, Math.max(a, corner));
89
+ }
90
+ const rounded = round(corner);
91
+ placed.error[key] = (rounded - corner) / t; shift[key] = rounded - corner;
92
+ return rounded + size / 2;
93
+ };
94
+ const s = grid.toScreen(position, _t);
95
+ s.x = fit(s.x, columns * t, 'x', right); s.y = fit(s.y, rows * t, 'y', up);
96
+ grid.toWorld(s, placed.position);
97
+ return placed;
98
+ },
99
+ };
100
+ return grid;
101
+ }
102
+
103
+ /**
104
+ * Write a sheet frame into a sprite's UVs. Frames count left to right, top to bottom. flip mirrors it on the UVs, not with a negative scale, so the triangle's winding and
105
+ * its shadow stay right.
106
+ * @param {THREE.Mesh} mesh @param {number} frame @param {boolean} [flip] left out: as it was
107
+ */
108
+ export function spriteFrame(mesh, frame, flip) {
109
+ const d = mesh.userData.pixelSprite;
110
+ if (!d) throw codedError('engine-misuse', 'spriteFrame(mesh, frame): the mesh must come from pixelSprite()');
111
+ if (!(Number.isInteger(frame) && frame >= 0 && frame < d.columns * d.rows)) throw codedError('engine-misuse', `spriteFrame: frame ${JSON.stringify(frame)} is outside the sheet, which has ${d.columns * d.rows} frames`);
112
+ d.frame = frame; d.flip = flip ?? d.flip;
113
+ const c = frame % d.columns, r = Math.floor(frame / d.columns), u0 = c / d.columns, u1 = (c + 1) / d.columns, v1 = 1 - r / d.rows, v0 = 1 - (r + 1) / d.rows;
114
+ const [l, h] = d.flip ? [u1, u0] : [u0, u1], uv = mesh.geometry.attributes.uv;
115
+ uv.setXY(0, l, v1); uv.setXY(1, h, v1); uv.setXY(2, l, v0); uv.setXY(3, h, v0); // PlaneGeometry's order: top left, top right, bottom left, bottom right
116
+ uv.needsUpdate = true;
117
+ return mesh;
118
+ }
119
+
120
+ /**
121
+ * A sprite for an orthographic view of a 3D scene: a plain THREE.Mesh, a vertical plane. Standing upright is what keeps a head out of the wall behind it: the whole figure
122
+ * has the depth of its feet. A plane tilted toward the camera would lean its head back through that wall. The height is stretched by 1 / cos(pitch), which the view's
123
+ * tilt takes back, so one texel is one art pixel.
124
+ * Facing comes from the camera's forward direction, not its position: under an orthographic camera, aiming at the position would give every sprite a different angle.
125
+ * It is applied just before drawing, because a character's root turns with its facing and the sprite must not. mesh.position stays exact (physics, saves, gameplay read it);
126
+ * only the drawn matrix is rounded.
127
+ * @param {{ grid: ReturnType<typeof pixelGrid>, material: THREE.Material, width: number, height: number, columns?: number, rows?: number, frame?: number, flip?: boolean,
128
+ * anchor?: [number, number], snap?: 'world' | 'followed' | false }} o width / height: one frame in texels; anchor: the point on the frame at the mesh's origin, 0 to 1 from the
129
+ * bottom left, feet by default; snap: 'followed' for the one object the camera follows (grid.snapFollowed)
130
+ * @returns {THREE.Mesh}
131
+ */
132
+ export function pixelSprite({ grid, material, width, height, columns = 1, rows = 1, frame = 0, flip = false, anchor = [0.5, 0], snap = 'world' } = /** @type {any} */ ({})) {
133
+ if (!grid?.axes) throw codedError('engine-misuse', 'pixelSprite({ grid }): grid comes from pixelGrid() or engine.cameraRig.pixelSnap.grid');
134
+ if (!material?.isMaterial) throw codedError('engine-misuse', 'pixelSprite({ material }): a three.js material of your own; the engine brings no look');
135
+ if (!(width > 0 && height > 0)) throw codedError('engine-misuse', `pixelSprite({ width, height }): one frame's size in texels; got ${width} x ${height}`);
136
+ if (![false, 'world', 'followed'].includes(snap)) throw codedError('engine-misuse', `pixelSprite({ snap: ${JSON.stringify(snap)} }): use 'world', 'followed' or false`);
137
+ const t = grid.cell, w = width * t, h = height * t;
138
+ // the anchor rounds to a whole texel: otherwise the frame's edges fall between art pixels once the anchor is on the grid
139
+ const geometry = new THREE.PlaneGeometry(w, h).translate(w / 2 - Math.round(anchor[0] * width) * t, h / 2 - Math.round(anchor[1] * height) * t, 0);
140
+ const mesh = new THREE.Mesh(geometry, material);
141
+ mesh.userData.pixelSprite = { columns, rows, frame, flip };
142
+ spriteFrame(mesh, frame);
143
+ mesh.onBeforeRender = () => {
144
+ const f = grid.axes().forward, flat = Math.max(MIN_COS_PITCH, Math.hypot(f.x, f.z)), parent = mesh.parent;
145
+ const turn = _pq.setFromAxisAngle(_y, Math.atan2(-f.x, -f.z));
146
+ mesh.quaternion.copy(turn);
147
+ if (parent) mesh.quaternion.premultiply(parent.getWorldQuaternion(_pq).invert());
148
+ mesh.scale.y = 1 / flat;
149
+ mesh.updateMatrix();
150
+ if (parent) mesh.matrixWorld.multiplyMatrices(parent.matrixWorld, mesh.matrix); else mesh.matrixWorld.copy(mesh.matrix);
151
+ if (snap) mesh.matrixWorld.setPosition(grid[snap === 'followed' ? 'snapFollowed' : 'snap'](_p.setFromMatrixPosition(mesh.matrixWorld), _p));
152
+ };
153
+ return mesh;
154
+ }
@@ -0,0 +1,167 @@
1
+ // The renderer's pixel ratio has one owner, this file: every engine write goes through it, and it decides which request wins, so no two entries fight
2
+ // by "who wrote last". Two modes:
3
+ // ratio (the default) writeRatio: the game's and settings' engine.setPixelRatio (askRatio), adaptive resolution under it, the tier's default, a photo's
4
+ // borrowed ratio.
5
+ // pixelSize (createEngine({ pixelSize }), engine.setPixelSize) one art pixel is k real screen pixels: the ratio is devicePixelRatio / k and fitPixelSize
6
+ // alone sets the drawing buffer. Everything else asking for a ratio is held off, refused or kept for later: adaptive stops (engine.adaptive.on
7
+ // reads false), the tier only updates what comes back when pixelSize ends, a photo keeps the art pixels, engine.setPixelRatio throws.
8
+ // A direct renderer.setPixelRatio by the game is not refused (hard rule 4): the engine yields in both modes (view.pixelRatio in core/ops/owned.js).
9
+ // tests/specs/pixel-size.mjs guards that no other file calls renderer.setPixelRatio.
10
+ import { DEV, warnOnce } from '../base/validate.js';
11
+ import { coded, codedError } from '../base/errorHints.js';
12
+ import { ownMsaa } from '../../render/backend.js';
13
+ import { defaultPixelRatio } from './tier.js';
14
+
15
+ const dpr = () => devicePixelRatio || 1;
16
+
17
+ /** Does pixelSize decide the ratio now: for modules whose rows or tools would otherwise ask for one @param {any} e */
18
+ export const pixelSizeOn = e => e._pixelSize != null;
19
+
20
+ /** The ratio a renderer starts with, before the engine's owned rows exist @param {any} r @param {string} tier @param {number} [pixelRatio] */
21
+ export function firstRatio(r, tier, pixelRatio) { r.setPixelRatio(pixelRatio ?? defaultPixelRatio(dpr(), tier)); }
22
+
23
+ /**
24
+ * The one write in ratio mode; re-reading it after keeps this from counting as an outside write. Skips an equal value because three's setPixelRatio resizes
25
+ * the canvas, which clears the drawing buffer. Does nothing under pixelSize, so a caller that missed the mode still cannot move the art pixels.
26
+ * @param {any} e @param {number} p
27
+ */
28
+ export function writeRatio(e, p) {
29
+ if (e._pixelSize != null) return;
30
+ if (Math.abs(e.renderer.getPixelRatio() - p) > 0.001) e.renderer.setPixelRatio(p);
31
+ e._oPixelRatio.mark();
32
+ }
33
+
34
+ /**
35
+ * engine.setPixelRatio. It is the game's (or settings') request: written even when the game took the ratio. It is also the new ceiling, or adaptive
36
+ * resolution would climb back to the old one and undo the engine's own named entry where the raw three.js call stays. Adaptive writes through writeRatio.
37
+ * @param {any} e @param {number} p
38
+ */
39
+ export function askRatio(e, p) {
40
+ if (e._pixelSize != null) throw codedError('pixel-conflict', `engine.setPixelRatio(${p}): pixelSize ${e._pixelSize} decides the ratio now. Keep pixelSize and drop this call, or call engine.setPixelSize(null) first`);
41
+ writeRatio(e, p);
42
+ Object.assign(e.adaptive, { max: p, lowered: false, from: null, good: 0 });
43
+ }
44
+
45
+ /**
46
+ * The real device became known in start(): the tier's default ratio, unless the game chose one or does not leave the renderer to the engine. Under pixelSize
47
+ * it is kept for when pixelSize ends.
48
+ * @param {any} e @param {string} tier
49
+ */
50
+ export function tierRatio(e, tier) {
51
+ if (!e._ownsRenderer || e._createParams.pixelRatio != null) return;
52
+ const p = e.adaptive.base = defaultPixelRatio(dpr(), tier);
53
+ if (e._pixelSize != null) e.adaptive.max = p; else askRatio(e, p);
54
+ }
55
+
56
+ /**
57
+ * Hand the size and ratio to a renderer that replaces this one, exactly as they were: a recomputed size would move the art pixels.
58
+ * @param {any} from @param {any} to @param {any} size a THREE.Vector2 to read into
59
+ */
60
+ export function carryRatio(from, to, size) { from.getSize(size); to.setDrawingBufferSize(size.x, size.y, from.getPixelRatio()); }
61
+
62
+ /**
63
+ * A ratio for one synchronous draw (a photo at a higher resolution). Returns the call that puts the ratio back. check() first: an outside write not noticed
64
+ * yet would otherwise be marked as the engine's on the way back. Under pixelSize the ratio stays, because a finer buffer draws a picture without the art
65
+ * pixels the game chose.
66
+ * @param {any} e @param {number} p @returns {() => void}
67
+ */
68
+ export function borrowRatio(e, p) {
69
+ if (e._pixelSize != null) return () => {};
70
+ e._oPixelRatio.check();
71
+ const back = e.renderer.getPixelRatio();
72
+ writeRatio(e, p);
73
+ return () => writeRatio(e, back);
74
+ }
75
+
76
+ /** Note the canvas's size in real screen pixels from a ResizeObserver entry; browsers without devicePixelContentBoxSize leave it unknown @param {any} e @param {ResizeObserverEntry} entry */
77
+ export function noteDeviceBox(e, entry) {
78
+ const s = entry.devicePixelContentBoxSize?.[0];
79
+ if (s) e._deviceBox = { w: s.inlineSize, h: s.blockSize };
80
+ }
81
+
82
+ /**
83
+ * The canvas's box in real screen pixels, measured by the browser. CSS size times the ratio is only the fallback: at 150% the CSS size is already rounded, and
84
+ * that error is what makes art pixels uneven. The measured box excludes the padding fitPixelSize added, so it is put back here. Device emulation (DevTools, Playwright's
85
+ * deviceScaleFactor) reports the box unscaled, so a measure far from the CSS size is not used.
86
+ * @param {any} e @param {number} w CSS width @param {number} h CSS height @param {number} s device pixel ratio
87
+ */
88
+ function deviceBox(e, w, h, s) {
89
+ const b = e._deviceBox, st = e.renderer.domElement.style;
90
+ const dw = b && b.w + Math.round((parseFloat(st.paddingRight) || 0) * s), dh = b && b.h + Math.round((parseFloat(st.paddingBottom) || 0) * s);
91
+ if (b && Math.abs(dw - w * s) <= s + 1 && Math.abs(dh - h * s) <= s + 1) return { w: dw, h: dh };
92
+ return { w: Math.round(w * s), h: Math.round(h * s) };
93
+ }
94
+
95
+ const padCanvas = (st, right, bottom) => { st.paddingRight = right ? right + 'px' : ''; st.paddingBottom = bottom ? bottom + 'px' : ''; };
96
+ /** Take off what pixelSize put on the canvas: setPixelSize(null), and dispose, because the page may hand the same canvas to the next engine @param {any} e @param {any} st */
97
+ const plainCanvas = (e, st) => { padCanvas(st, 0, 0); Object.assign(st, e._pixelCss); };
98
+
99
+ /**
100
+ * Resize under pixelSize. A whole number of art pixels rarely fills the canvas: stretching the buffer over the rest would make some art pixels wider, so the
101
+ * last few real pixels (fewer than k) stay padding instead; the box the page laid out does not change. The renderer's size is the buffer in CSS units and the
102
+ * small addition keeps three's floor(size * ratio) on the buffer size when the division comes out just under it.
103
+ * @param {any} e @param {number} w CSS width @param {number} h CSS height @returns {boolean} false: not this mode, the plain resize applies
104
+ */
105
+ export function fitPixelSize(e, w, h) {
106
+ const k = e._pixelSize, r = e.renderer, c = r.domElement, o = e._oPixelRatio;
107
+ if (k == null) return false;
108
+ o.check();
109
+ if (!o.on) { padCanvas(c.style, 0, 0); return false; } // the game took the ratio (core/ops/owned.js): the canvas is a plain one again
110
+ const s = dpr(), dev = deviceBox(e, w, h, s), bw = Math.max(1, Math.floor(dev.w / k)), bh = Math.max(1, Math.floor(dev.h / k)), pr = s / k;
111
+ padCanvas(c.style, (dev.w - bw * k) / s, (dev.h - bh * k) / s);
112
+ if (e._autoSize) { c.style.width = w + 'px'; c.style.height = h + 'px'; }
113
+ if (c.width !== bw || c.height !== bh || r.getPixelRatio() !== pr) {
114
+ r.setDrawingBufferSize((bw + 1e-7) / pr, (bh + 1e-7) / pr, pr); // the post chain follows the renderer on its next draw (postWebGL.js follow)
115
+ e._oAspect.drive(bw / bh);
116
+ }
117
+ o.mark();
118
+ return true;
119
+ }
120
+
121
+ /**
122
+ * A window moved to another display or a page zoom changes devicePixelRatio. A resolution query matches one value only, so each change registers the next
123
+ * one. Armed once: a watch left from before setPixelSize(null) keeps its query, which is still the current value.
124
+ * @param {any} e
125
+ */
126
+ function watchDisplay(e) {
127
+ if (e._displayWatch || typeof matchMedia !== 'function') return;
128
+ e._displayWatch = true;
129
+ matchMedia(`(resolution: ${dpr()}dppx)`).addEventListener('change', () => {
130
+ e._displayWatch = false;
131
+ if (e._pixelSize == null) return;
132
+ watchDisplay(e);
133
+ e._resize();
134
+ }, { once: true, signal: e.signal });
135
+ }
136
+
137
+ /**
138
+ * engine.setPixelSize. A direct renderer.setPixelRatio before this call is over: the call is the newer, named request. autoView.manual('pixelRatio') is a claim
139
+ * on purpose, so it conflicts.
140
+ * @param {any} e @param {number | null} k
141
+ */
142
+ export function askPixelSize(e, k) {
143
+ if (k !== null && !(Number.isInteger(k) && k > 0)) throw codedError('engine-misuse', `engine.setPixelSize(k): k is how many real screen pixels make one art pixel, a whole number from 1 up (null turns it off); got ${JSON.stringify(k)}`);
144
+ const o = e._oPixelRatio, was = e._pixelSize, st = e.renderer.domElement.style;
145
+ o.check();
146
+ if (k === null) {
147
+ if (was == null) return;
148
+ e._pixelSize = null;
149
+ plainCanvas(e, st);
150
+ if (o.on) writeRatio(e, e.adaptive.max); // a ratio the game took stays the game's, as in fitPixelSize
151
+ e._resize();
152
+ return;
153
+ }
154
+ if (o.mode === 'manual') throw codedError('pixel-conflict', `engine.setPixelSize(${k}): the game took the pixel ratio with engine.autoView.manual('pixelRatio'). Keep one: hand it back with engine.autoView.manual('pixelRatio', false), or drop this call`);
155
+ if (o.mode === 'yielded') o.manual(false);
156
+ if (was == null) {
157
+ if (!e._pixelCss) e.signal.addEventListener('abort', () => plainCanvas(e, st), { once: true });
158
+ e._pixelCss = { imageRendering: st.imageRendering, boxSizing: st.boxSizing };
159
+ Object.assign(st, { imageRendering: 'pixelated', boxSizing: 'border-box' }); // border-box: the padding comes out of the box the page gave the canvas
160
+ Object.assign(e.adaptive, { lowered: false, from: null, good: 0 });
161
+ }
162
+ e._pixelSize = k;
163
+ // the canvas's MSAA is fixed when its context is made, so nothing here can switch it off
164
+ if (DEV && (e.post.antialias || ownMsaa(e.renderer))) warnOnce(coded('pixel-conflict', `pixelSize ${k} with antialias on: the edges of art pixels come out blended. It can only be set at creation: createEngine({ antialias: false })`));
165
+ watchDisplay(e);
166
+ e._resize();
167
+ }
@@ -1,4 +1,4 @@
1
- // What entered and left a scene since the last frame, so systems that must reach every object in the scene (the cascades and fog patching
1
+ // What entered and left a scene since the last frame, so systems that must reach every object in the scene (the cascades patching
2
2
  // materials, night glow finding its materials, the room map waiting for a material that reads it) visit only the new subtrees instead of
3
3
  // each walking the whole scene after any change. While streaming, something is added almost every frame; four full walks of a 1000+
4
4
  // object scene per such frame cost more than the frame's game code.
@@ -14,7 +14,7 @@
14
14
  // Swapping an entry inside a material array in place (mesh.material[1] = m) is not seen; assign a new array instead.
15
15
  // A visitor keeps its own per-object / per-material state (Maps, WeakMaps); nothing here holds an object after it left the scene.
16
16
  import * as THREE from 'three';
17
- import { useSceneVisitor } from '../render/backend.js';
17
+ import { useSceneVisitor } from '../../render/backend.js';
18
18
  import { notePatch, patchOn } from './threePatches.js';
19
19
 
20
20
  const KEY = Symbol.for('threedog.sceneDelta');
@@ -48,7 +48,7 @@ if (!P[KEY]) {
48
48
  const t = patchOn('scene-add-hook') ? trackerOf(this) : null;
49
49
  if (!t) return remove.apply(this, a);
50
50
  let gone = null, roots = null;
51
- for (const c of a) if (c?.parent === this && t.seen.has(c)) (gone ??= []).push(c);
51
+ for (const c of a) if (c?.parent === this) (gone ??= []).push(c); // not only seen ones: a material swap unmarks the root, its children stay counted (left checks each)
52
52
  if (t.rootLeaves.size && this === t.scene) for (const c of a) if (c?.parent === this) (roots ??= []).push(c);
53
53
  const out = remove.apply(this, a);
54
54
  if (gone) for (const c of gone) t.left(c);
@@ -65,10 +65,10 @@ notePatch('scene-add-hook', 'Object3D.prototype.add / remove: wrapped once per p
65
65
  if (P.remove === o.ours.remove) P.remove = o.remove;
66
66
  if (P.add === o.add && P.remove === o.remove) { delete P[KEY]; delete P[ORIG]; }
67
67
  },
68
- { lost: 'plain scene.add is no longer adopted like engine.add, and fog, cascades, night glow and light counts miss objects added later' });
68
+ { lost: 'plain scene.add is no longer adopted like engine.add, and cascades, night glow and light counts miss objects added later' });
69
69
  notePatch('mesh-material-accessor', 'mesh.material on each object with a material that enters a watched scene: an own get / set on that object (the class accessor still runs) so a material swap is seen',
70
70
  () => {}, // off: objects entering from now on keep a plain material (_walk asks patchOn)
71
- { scope: 'objects in the scene', lost: 'mesh.material = other on objects entering from now on is not seen: the new material misses fog and cascades until the object re-enters' });
71
+ { scope: 'objects in the scene', lost: 'mesh.material = other on objects entering from now on is not seen: the new material misses cascades until the object re-enters' });
72
72
 
73
73
  /** The accessor (get / set) `material` resolves to on this object or up its prototype chain, or null when it is a plain value */
74
74
  function materialAccessor(o) {
@@ -1,10 +1,31 @@
1
1
  // Scene and render settings on the engine (split out of Engine.js): add / detach / remove objects, pixel ratio, one-off renders (renderOnce).
2
2
  // add registers each root in the thing registry (things.js) so engine.thing / hit.thing can say what it is and what a save keeps. A plain
3
3
  // engine.scene.add(obj) is registered the same way (things.js adopts roots added under the scene), so both ways in give the same answer.
4
- import { DEV } from './validate.js';
5
- import { codedError } from './errorHints.js';
4
+ import { DEV } from '../base/validate.js';
5
+ import { askRatio, askPixelSize } from './pixelRatio.js';
6
+ import { codedError } from '../base/errorHints.js';
6
7
  import { thing } from './thingOps.js';
7
- import { freshFrame, renderOnce as drawOnce } from '../render/backend.js';
8
+ import { isUnder } from '../base/util.js';
9
+ import { freshFrame, renderOnce as drawOnce } from '../../render/backend.js';
10
+
11
+ /** The geometry and materials of one object */
12
+ const parts = o => [o.geometry, ...[].concat(o.material)].filter(Boolean);
13
+ /**
14
+ * How many objects in the scene use each geometry and material. Why remove asks: disposing a kit that other streamed blocks still draw makes the renderer
15
+ * rebuild all of them (worst frame 270 ms against 79 in the city stress run). One walk per task, so removing ten thousand objects in a loop walks once; an object
16
+ * added later in that task is not counted, so its geometry may be disposed and uploaded again, which costs time and nothing else; one that left by plain scene.remove
17
+ * in that task still counts, so its model waits for the next engine.remove. Batches are left out:
18
+ * batching.held speaks for them, and it lets go when a batch dissolves in the same task.
19
+ * shortcut: one walk of the scene per frame that removes something (not measured at 100k objects); if it shows up in a profile, keep the counts on the scene-add hook instead.
20
+ */
21
+ function sceneUsers(e) {
22
+ if (e._users) return e._users;
23
+ const users = e._users = new Map(), skip = e.batching.root;
24
+ const walk = o => { if (o === skip) return; for (const x of parts(o)) users.set(x, (users.get(x) ?? 0) + 1); for (const c of o.children) walk(c); };
25
+ walk(e.scene);
26
+ queueMicrotask(() => { e._users = null; });
27
+ return users;
28
+ }
8
29
 
9
30
  /** A short stack for "added at main.js:50" (dev): 4 frames are enough (this, add, its caller) and keep the cost low; it is formatted only when read */
10
31
  function captureStack() {
@@ -43,28 +64,28 @@ export const sceneMethods = {
43
64
  * @example engine.thing('windmill').saved // 'code': rebuilt by code each start, thing.set changes saved
44
65
  * @example engine.thing(engine.pick(0, 0).object).edit
45
66
  * @param {string | import('three').Object3D} idOrObj
46
- * @returns {import('../types/core').Thing}
67
+ * @returns {import('../../types/core').Thing}
47
68
  */
48
69
  thing(idOrObj) { return thing(this, idOrObj); },
49
70
  /** @internal Dev: a module found two systems managing one object; listed in describe().scene.conflicts and warned once (code thing-owned) */
50
71
  thingConflict(text) { this._things.conflict(text); },
51
- /** Detach from the parent only (no GPU release; use when you will add it back). Use remove for objects you are done with */
52
- detach(...objs) { for (const o of objs) o.removeFromParent(); },
53
72
  /**
54
- * Delete an object for good: detach it, unregister its rays and dispose geometries and materials (textures are kept). Geometry and materials shared by assets
55
- * model clones are only decremented in use count (see Assets.js)
73
+ * Delete an object for good: detach it, unregister its rays and dispose the geometries and materials nothing else in the scene uses (textures are kept).
74
+ * One still used by another object stays, and goes with its last user. Geometry and materials shared by assets model clones are only decremented in use count (see Assets.js)
56
75
  */
57
76
  remove(...objs) {
58
77
  for (const o of objs) {
78
+ const counted = isUnder(o, this.scene) && !!this._users; // the count was made while this object was still in the scene
59
79
  o.removeFromParent();
60
80
  this._things.forget(o);
61
81
  this.rays.forget(o);
62
82
  this.assets.forget(o);
83
+ this._poses.forget(o);
63
84
  const shared = this.assets.shared, held = this.batching.held; // a batch still drawing the same geometry / material keeps it alive
64
- o.traverse(c => {
65
- if (c.geometry && !shared.has(c.geometry) && !held.has(c.geometry)) c.geometry.dispose();
66
- for (const m of [].concat(c.material || [])) if (!shared.has(m) && !held.has(m)) m.dispose();
67
- });
85
+ if (counted) o.traverse(c => { for (const x of parts(c)) this._users.set(x, (this._users.get(x) ?? 0) - 1); });
86
+ // The whole-scene count only for a part nothing else keeps: unloading a streamed block whose kit is all held by batches walked every object of the district for nothing (7 ms in one frame of the city run)
87
+ const free = []; o.traverse(c => { for (const x of parts(c)) if (!shared.has(x) && !held.has(x)) free.push(x); });
88
+ if (free.length) { const users = sceneUsers(this); for (const x of free) if (!(users.get(x) > 0)) x.dispose(); }
68
89
  }
69
90
  },
70
91
  /**
@@ -88,9 +109,16 @@ export const sceneMethods = {
88
109
  drawOnce(this.renderer, this.scene, camera, target);
89
110
  } finally { if (own) own.inside--; }
90
111
  },
91
- // an engine.setPixelRatio call is the game's (or settings') request: written even when the game took the ratio, and re-read so it is not an outside write
92
- setPixelRatio(p) { this.renderer.setPixelRatio(p); this._oPixelRatio?.mark(); },
93
- /** Raise camera.far to at least far (terrain view range). Goes through ownership: a game that owns camera.far (engine.view.manual('far')) keeps its value. @param {number} far */
112
+ /** Render resolution, and the top adaptive resolution climbs back to. Throws while pixelSize is on (core/scene/pixelRatio.js) @param {number} p */
113
+ setPixelRatio(p) { askRatio(this, p); },
114
+ /**
115
+ * One art pixel becomes k real screen pixels, every one the same width at any display scale, and it stays so through a page zoom or a move to another display.
116
+ * While on, adaptive resolution stops and engine.setPixelRatio throws; a photo keeps the art pixels. null turns it off.
117
+ * @example engine.setPixelSize(3);
118
+ * @param {number | null} k a whole number from 1 up, or null
119
+ */
120
+ setPixelSize(k) { askPixelSize(this, k); },
121
+ /** Raise camera.far to at least far (terrain view range). Goes through ownership: a game that owns camera.far (engine.autoView.manual('far')) keeps its value. @param {number} far */
94
122
  viewFar(far) {
95
123
  if (this.camera.far >= far) return;
96
124
  if (this._oFar) this._oFar.drive(far); else { this.camera.far = far; this.camera.updateProjectionMatrix(); }
@@ -0,0 +1,60 @@
1
+ // Drawing moving things between fixed steps. Characters and rigid bodies move on the 60 Hz fixed step, and their root.position / mesh.position stays the truth
2
+ // that gameplay reads. A screen faster than that (or a frame that ran zero or two steps) would otherwise draw the same pose twice and then jump.
3
+ // Each entry keeps the object's pose at the end of the last two steps; a drawn frame shows the pose engine.stepBlend of the way between them (one step behind, like a swarm).
4
+ // Why the matrix and not position / quaternion: the blended pose exists for one draw only, so nothing gameplay reads ever holds it, and writing a quaternion
5
+ // would rewrite the Euler the mover keeps facing in. The object's own matrix is composed here and matrixAutoUpdate is off just for that draw.
6
+ // Anything that placed the object outside a step (a tween, a frame-driven mover, a platform carried in frame) leaves it different from the step's end: it is then drawn as it stands.
7
+ import * as THREE from 'three';
8
+
9
+ /** Farther than this in one step (squared meters) is a teleport, not motion: drawn at once, never swept across the map */
10
+ const JUMP2 = 16;
11
+ const _v = new THREE.Vector3(), _q = new THREE.Quaternion(), _keep = new THREE.Vector3();
12
+
13
+ /** @internal engine._poses */
14
+ export class StepPoses {
15
+ constructor(engine) {
16
+ this.engine = engine;
17
+ /** object -> { o, last, lastRot, pos, rot, moved } */ this.map = new Map();
18
+ /** objects whose matrix is held for this draw */ this.held = [];
19
+ engine.time.onMove(() => this.end());
20
+ }
21
+ /** place(at): how to move o if a solver owns its pose (a rigid body); gone(): what that solver does when o leaves for good. Core names no module, so the solver says both here */
22
+ add(o, place = null, gone = null) { this.map.set(o, { o, place, gone, last: o.position.clone(), lastRot: o.quaternion.clone(), pos: o.position.clone(), rot: o.quaternion.clone(), moved: false }); }
23
+ remove(o) { this.map.delete(o); }
24
+ /** o and all under it left for good (engine.remove): a level's root takes the crates placed in it along, and a solver must not keep them solid and unseen */
25
+ forget(o) { if (this.map.size) o.traverse(c => this.map.get(c)?.gone?.()); }
26
+ /** A write moves o outside any step: the object goes there, and whatever solves it too, or the solver's next pose would undo the write */
27
+ place(o, at) { o.position.copy(at); this.map.get(o)?.place?.(at); }
28
+ /** End of a fixed step: the latest pose becomes the start of the blend */
29
+ end() {
30
+ for (const p of this.map.values()) {
31
+ const { o, last, lastRot, pos, rot } = p;
32
+ last.copy(pos); lastRot.copy(rot); pos.copy(o.position); rot.copy(o.quaternion);
33
+ p.moved = !last.equals(pos) || !lastRot.equals(rot);
34
+ if (p.moved && last.distanceToSquared(pos) > JUMP2) { last.copy(pos); lastRot.copy(rot); p.moved = false; }
35
+ }
36
+ }
37
+ /** The entry if it should blend now, else null: nothing to blend, or the object was placed outside a step */
38
+ live(p) { return p?.moved && this.engine.stepBlend < 1 && p.o.position.equals(p.pos) && p.o.quaternion.equals(p.rot) ? p : null; }
39
+ /** Before a draw: every moving object draws at its blended pose */
40
+ draw() {
41
+ const a = this.engine.stepBlend;
42
+ if (a >= 1) return;
43
+ for (const p of this.map.values()) {
44
+ if (!this.live(p) || !p.o.matrixAutoUpdate) continue;
45
+ const o = p.o;
46
+ o.matrix.compose(_v.lerpVectors(p.last, p.pos, a), _q.slerpQuaternions(p.lastRot, p.rot, a), o.scale);
47
+ o.matrixAutoUpdate = false; o.matrixWorldNeedsUpdate = true;
48
+ this.held.push(o);
49
+ }
50
+ }
51
+ /** After a draw: the objects go back to their own pose */
52
+ undraw() { for (const o of this.held) o.matrixAutoUpdate = true; this.held.length = 0; }
53
+ /** Run fn with o standing at its blended position: a camera follows what is drawn, or the view would step while the body glides */
54
+ around(o, fn) {
55
+ const p = this.live(this.map.get(o));
56
+ if (!p) return fn();
57
+ _keep.copy(o.position); o.position.lerpVectors(p.last, p.pos, this.engine.stepBlend);
58
+ try { return fn(); } finally { o.position.copy(_keep); }
59
+ }
60
+ }
@@ -1,10 +1,9 @@
1
1
  // Target selection: pure functions (no camera, input or engine state), for lock-on, aim assist, "talk to whoever I'm facing", select the nearest unit.
2
2
  // Why a score and not just "nearest": the player wants what they are looking at; an enemy pressed against their back should not steal the lock.
3
3
  // The caller keeps the current target (in a world record, a module, a variable) and decides when to pick; these functions only answer "which one".
4
- import { xzOf } from './math.js';
5
- import { codedError } from './errorHints.js';
4
+ import { xzOf, wrapAngle } from '../base/math.js';
5
+ import { codedError } from '../base/errorHints.js';
6
6
 
7
- const wrap = a => Math.atan2(Math.sin(a), Math.cos(a));
8
7
  const KEYS = ['radius', 'cone', 'close', 'angleWeight', 'blocked', 'at'];
9
8
  const yawOf = view => typeof view === 'number' ? view : Math.atan2(view.x, view.z);
10
9
  /** Candidate position: an Object3D / NPC / Character / world record has .position; a Vector3 / { x, z } / [x, y, z] is the position itself */
@@ -33,7 +32,7 @@ export function pickTarget(from, view, candidates, opts = {}) {
33
32
  for (const c of candidates) {
34
33
  const [x, z] = xzOf(at(c)), d = Math.hypot(x - fx, z - fz);
35
34
  if (d > radius) continue;
36
- const off = Math.abs(wrap(Math.atan2(x - fx, z - fz) - yaw));
35
+ const off = Math.abs(wrapAngle(Math.atan2(x - fx, z - fz) - yaw));
37
36
  if (off > cone && d > close) continue;
38
37
  const score = d + off * angleWeight;
39
38
  if (score < bestScore && !blocked?.(c)) { bestScore = score; best = c; }
@@ -55,7 +54,7 @@ export function switchTarget(from, view, current, candidates, side, opts = {}) {
55
54
  const list = [];
56
55
  for (const c of candidates) {
57
56
  const [x, z] = xzOf(at(c));
58
- if (Math.hypot(x - fx, z - fz) <= radius && !blocked?.(c)) list.push({ c, a: -wrap(Math.atan2(x - fx, z - fz) - yaw) });
57
+ if (Math.hypot(x - fx, z - fz) <= radius && !blocked?.(c)) list.push({ c, a: -wrapAngle(Math.atan2(x - fx, z - fz) - yaw) });
59
58
  }
60
59
  if (!list.length) return null;
61
60
  list.sort((p, q) => p.a - q.a);
@@ -1,8 +1,9 @@
1
- // engine.thing(id).explain(): everything known about one id in one plain object (JSON-able, same for the CLI `threedog thing <id>`, MCP and tests).
1
+ // engine.explain({ thing: id }): everything known about one id in one plain object (JSON-able, same for the CLI `threedog explain thing <id> --full`, MCP and tests).
2
2
  // Why one object: an AI asked "why is this crate here, blocking me, and how do I change it?" otherwise joins thing(), world.origin, material info, the
3
3
  // template, collision settings and the op list by hand. Each part reads an existing source; nothing here is stored or changes any state.
4
- import { materialInfo } from './MaterialInfo.js';
5
- import { orNull } from './util.js';
4
+ import { Box3, Vector3 } from 'three';
5
+ import { materialInfo } from '../inspect/MaterialInfo.js';
6
+ import { orNull } from '../base/util.js';
6
7
 
7
8
  const MAT_MAX = 8;
8
9
 
@@ -28,10 +29,10 @@ function opsFor(e, t) {
28
29
  }
29
30
 
30
31
  /** What core knows about how the thing takes part in movement / picking: the size of its model. Template and record rules come from a module's explainer (below) */
31
- function rulesOf(e, t, obj) {
32
+ function rulesOf(obj) {
32
33
  const out = {};
33
34
  if (obj) {
34
- const T = e.THREE, size = new T.Box3().setFromObject(obj).getSize(new T.Vector3());
35
+ const size = new Box3().setFromObject(obj).getSize(new Vector3());
35
36
  if (isFinite(size.y)) out.height = Math.round(size.y * 100) / 100;
36
37
  }
37
38
  return out;
@@ -51,7 +52,7 @@ export function explainThing(e, t) {
51
52
  model: t.model ?? null,
52
53
  materials: materialsOf(obj),
53
54
  state,
54
- rules: rulesOf(e, t, obj),
55
+ rules: rulesOf(obj),
55
56
  ops: opsFor(e, t),
56
57
  saved,
57
58
  change: {