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,135 @@
1
+ # Water and weather look open points: depth color, foam, reflections, rain and snow, lightning, own particles
2
+
3
+ For an AI that wants water or weather particles to look a way the defaults do not. Water basics are the `water()` module and `style.water` (color, opacity, waves,
4
+ fresnel, normal map); lights, fog and the sky are in `38-environment-look-hooks.md`. Every default below draws exactly what it drew before
5
+ (checked pixel by pixel against the old shaders in `tests/specs/appearance-water.mjs`), and a style that writes none of the new keys gets the same
6
+ shader text, so it pays nothing. Three exits: a parameter, a GLSL function you replace, or your own material.
7
+
8
+ ## Water: depth color and crest foam (parameters)
9
+ ```js
10
+ water: {
11
+ depthColor: { shallow: 0x55ddcc, deep: 0x082040 }, // by 'view' (default): shallow looking down, deep toward the horizon
12
+ depthColor: { shallow: 0x7fe0d0, deep: 0x0a3050, by: 'wave', curve: 1.5 }, // shallow on the crests, deep in the troughs
13
+ foam: { color: 0xffffff, start: 0.55, end: 0.85, opacity: 1 }, // white on the wave tops; foam: true = these defaults
14
+ }
15
+ ```
16
+ - `depthColor` replaces `color` (opacity stays). `'view'` is a fresnel-style blend by the view angle, `'wave'` blends by the wave height; neither
17
+ needs a depth texture. `curve` bends the blend (above 1 keeps more of the shallow color).
18
+ - `foam` uses the same wave height as the vertices: `start` / `end` are fractions of the peak height (`glsl.waveMax`, default 0.29) where
19
+ foam begins and is full. Foam is opaque even on transparent water. All numbers are uniforms (`engine.water.material.uniforms.uFoamStart.value`).
20
+ - **Shore foam is not built in.** An accurate foam line where water meets land needs the distance to the ground under each pixel: a depth
21
+ pre-pass (a `DepthTexture` render target of the scene without water) or a terrain height lookup, both cost a full extra pass or a texture
22
+ read per pixel. Do it yourself through `style.water.material`: render the scene's depth to a target before the water draws
23
+ (`material.onBeforeRender`), pass it as a uniform, and in your fragment compare the scene depth with this fragment's depth, both turned into meters with three's
24
+ `perspectiveDepthToViewZ` (`#include <packing>`); foam
25
+ where the difference is under about a meter. A cheap fake: `engine.addWaterBody` lakes have known radii, so a surface function can foam the
26
+ ring `length(worldPos.xz - center) > radius - 1.0` (pass the center and radius as `uniforms`).
27
+
28
+ ## Water: replace the wave or the surface function (GLSL)
29
+ ```js
30
+ water: {
31
+ uniforms: { uBands: 4, uDeep: [0.05, 0.2, 0.4] }, // numbers, colors, [x, y(, z, w)] arrays, textures; in both stages
32
+ glsl: {
33
+ wave: `float threedogWaterWave(vec3 p, float t) { // p = world position * waveScale, t = time * waveSpeed
34
+ return sin(p.x * 0.5 + t) * 0.2 + sin(p.z * 0.8 - t * 1.3) * 0.1; }`, // height before waveHeight
35
+ waveMax: 0.3, // its peak: foam and depthColor 'wave' divide by it
36
+ surface: `vec4 threedogWaterSurface(vec4 base, float wave, float facing, vec3 worldPos, float time) {
37
+ float b = floor(facing * uBands) / uBands; // toon bands by view angle
38
+ return vec4(mix(uDeep, vec3(0.4, 0.8, 0.9), b), base.a); }`,
39
+ },
40
+ }
41
+ ```
42
+ - `wave` replaces only the vertex motion; the rest of the built-in water stays. Copying the default
43
+ (`modules/water/surface.js`, `WAVE`) draws pixel for pixel the same.
44
+ - `surface` runs before lighting: `base` is the material color and opacity, `wave` the height at this point, `facing` 1 looking straight down and 0
45
+ at grazing angles, `worldPos` the moved surface point. The result is lit, fogged and gets the grazing-angle fresnel like the default water.
46
+ With `surface` written, `depthColor` / `foam` are not added (your function is the whole surface).
47
+ - A wrong signature throws with the right one; misspelled keys warn with the near name; `threedog style check` knows these keys.
48
+
49
+ ## Water: your own material (reflections, refraction)
50
+ `style.water.material: (engine, { uniforms, waves, surface, normalMap }) => Material` replaces the whole water material; the engine still builds
51
+ the meshes, snaps the sea to the focus and scrolls the normal map. Reflections and refraction are not built in (each one renders the scene a
52
+ second time). three's `Reflector` addon works through this exit; the engine water is pre-rotated geometry, so the mirror gets the mesh's
53
+ matrix turned into the XY plane it expects:
54
+
55
+ ```js
56
+ import * as THREE from 'three';
57
+ import { Reflector } from 'three/addons/objects/Reflector.js';
58
+
59
+ water: { material: () => {
60
+ const mirror = new Reflector(new THREE.PlaneGeometry(1, 1), { textureWidth: 512, textureHeight: 512, color: 0x88aacc }), m = mirror.material;
61
+ const toPlane = new THREE.Matrix4().makeRotationX(-Math.PI / 2), back = new THREE.Matrix4().makeRotationX(Math.PI / 2);
62
+ let busy = false;
63
+ m.onBeforeRender = (renderer, scene, camera, geometry, mesh) => {
64
+ if (busy) return; busy = true; // the mirror's own render must not reflect again
65
+ mirror.matrixWorld.copy(mesh.matrixWorld).multiply(toPlane);
66
+ mesh.visible = false; mirror.onBeforeRender(renderer, scene, camera); mesh.visible = true;
67
+ m.uniforms.textureMatrix.value.multiply(back); // undo the turn for the pre-rotated vertices
68
+ busy = false;
69
+ };
70
+ return m;
71
+ } }
72
+ ```
73
+ - Cost: the whole scene drawn once more per frame per water mesh at `textureWidth` x `textureHeight` (shadows are not re-rendered). Use 256-512
74
+ on phones; on `engine.tier === 'low'` return the default-looking material instead.
75
+ - One mirror plane: the material is shared, so water bodies at other levels need `water({ sea: false })` or their own mirror. The Reflector's
76
+ shader has no waves or fog; for both, copy its `fragmentShader` into a `MeshPhongMaterial` patch that samples `tDiffuse` with `textureMatrix`.
77
+ - three's `Refractor` addon (next to `Reflector`) reads `matrixWorld` as an XY plane too, so the same adapter applies (not covered by a test).
78
+ - Tested: `tests/specs/appearance-water.mjs` renders this exact example and finds the reflected box in the mirror texture.
79
+
80
+ ## Weather particles: rain and snow parameters
81
+ `style.weather.rain` / `snow` (left-out keys keep the built-in look; the defaults are pixel for pixel the old ones):
82
+
83
+ ```js
84
+ weather: {
85
+ rain: { color: 0xa8b8d0, opacity: 0.6, length: 1.2, speed: 26, slant: 1.5, density: a => a * a }, // streaks; sparse in a drizzle
86
+ // rain: { shape: 'soft', size: 10, maxSize: 6, sway: 0.3 }, // drops as soft sprites instead of streaks
87
+ snow: { shape: 'soft', size: 28, maxSize: 7, speed: 1, sway: 3, count: 4000 },
88
+ // snow: { texture: 'flake' }, // a sprite image replaces the shape
89
+ }
90
+ ```
91
+ - `shape`: `'line'` (rain default; leans with the wind by `slant`, `length` meters) or a sprite: `'round'` (snow default), `'soft'`, `'square'`
92
+ (`size` pixels at 3 m, capped at `maxSize`; drifts `sway` meters). `speed` is the fall in m/s.
93
+ - `density: amount => share`: how many particles show at a weather amount 0..1 (rain `a => min(1, a * 1.2)`, snow `() => 1`); opacity still
94
+ follows the amount. `count` per system (default `weather({ particles })`, halved on low-tier devices). Coverage is `style.weather.area`.
95
+ - The numbers are uniforms: `engine.weather.systems.get('rain').uniforms.uColor.value.set(0xff0000)` works at run time.
96
+
97
+ ## Weather particles: replace the shaders (GLSL)
98
+ ```js
99
+ snow: { uniforms: { uTint: [1, 0.85, 0.9] }, glsl: { fragment: `uniform float uOpacity;
100
+ void main(){
101
+ vec2 d = gl_PointCoord - 0.5;
102
+ float a = 1.0 - smoothstep(0.1, 0.25, dot(d, d)); // a soft petal
103
+ gl_FragColor = vec4(uTint, uOpacity * a);
104
+ #include <tonemapping_fragment>
105
+ #include <colorspace_fragment>
106
+ }` } }
107
+ ```
108
+ `glsl.vertex` / `glsl.fragment` are the whole shader text; copy `modules/weather/shaders.js` (`lineVert lineFrag pointVert pointFrag`) as the
109
+ start. In scope: `uCam uSize uFallOff uOpacity uColor`; lines add `uWindDir uLen` and the attribute `aEnd` (0 head, 1 tail); sprites add
110
+ `uPx uMaxPx uSway uSwayAmp uMap uUseMap`. Your `uniforms` are declared for you; declare the built-in ones you use, as the copies do. Keep
111
+ the two `#include` lines so the color matches three's materials with and without post-processing.
112
+
113
+ ## Lightning look
114
+ ```js
115
+ weather: { lightning: f => f * f * 0.8 } // flash 1 at the strike -> sky flash amount (default flickers)
116
+ weather: { lightning: () => 0 } // no sky flash: draw your own bolt instead
117
+ engine.events.on('weather:lightning', () => spawnBolt()); // when it strikes stays the weather table's (lightning > 0.5)
118
+ ```
119
+
120
+ ## Particles of the game's own weather
121
+ A field of the game's own weather table (`ash`, `petals`, `sparks`) gets particles with `engine.look.weather.replace({ [field]: spec })`; the amount is
122
+ `engine.weather.current[field]`, so they fade in and out with the weather. The spec takes the rain / snow keys above (default: drifting
123
+ round sprites), or `create` for a system of your own:
124
+
125
+ ```js
126
+ engine.use(sky(), weather({ types: { clear: {}, ashfall: { ash: 1, grey: 0.5, sun: 0.6 } } }));
127
+ engine.look.weather.replace({ ash: { shape: 'soft', color: 0x555555, size: 14, speed: 0.8, sway: 3 } });
128
+ engine.look.weather.replace({ rain: { create: (engine, { area, count }) => { // the same call replaces rain or snow
129
+ const drops = new THREE.InstancedMesh(new THREE.SphereGeometry(0.03), new THREE.MeshBasicMaterial({ color: 0x99bbff }), count);
130
+ return { object: drops, update(amount, { camera, time, wind }) { /* move the instances; shown while amount > 0.02 */ } };
131
+ } } });
132
+ ```
133
+ A field no type has throws with the table's fields. Rain and snow are built only when a type rains or snows, so a desert pays nothing.
134
+
135
+ > Water and weather are also look parts (`engine.look.water`, `engine.look.weather`): recipes/52-look.md, "Water, weather, post".
@@ -0,0 +1,51 @@
1
+ # Cascaded shadows
2
+
3
+ Off by default: the sun casts one shadow map around the focus (`extent`, default 70 m), exactly as before. Cascades split the sun's shadow
4
+ along the view into 2-4 maps (three's CSM addon): sharp near the camera, coarse far away. Use them when near shadows look blocky and the
5
+ world is bigger than one map covers well.
6
+
7
+ ```js
8
+ engine.use(sky({ shadow: { cascades: 3 } })); // or the style pack: style.sky.shadow.cascades
9
+ engine.look.shadow.set({ cascades: 3, maxFar: 150 }); // at run time; { cascades: 1 } switches back
10
+ ```
11
+
12
+ | field | default | meaning |
13
+ |---|---|---|
14
+ | `cascades` | 1 | 1 = one map (the plain path); 2-4 = cascades |
15
+ | `maxFar` | 120 | meters from the camera they cover; no sun shadow beyond |
16
+ | `split` | `'practical'` | where borders fall: `'practical'` / `'uniform'` / `'logarithmic'` / `(count, near, far, out) => void` |
17
+ | `lightMargin` | 100 | meters behind each cascade box toward the light still caught as casters |
18
+ | `fade` | true | cross-fade at borders so no seam shows (two shadow lookups there); false is a little cheaper |
19
+
20
+ `mapSize`, `bias`, `normalBias`, `type`, `radius` and `updateEvery` apply to every cascade. `extent`, `snap` and `ahead` do not: cascades
21
+ follow the camera frustum and snap to whole shadow pixels themselves, so edges do not shimmer while the camera moves.
22
+
23
+ ## How it works (what you can rely on)
24
+ - `engine.sky.sun` stays the light the sky drives (color, intensity, direction, `sky({ sun: 'manual' })`) and is cascade 0; the other
25
+ cascades are extra DirectionalLights that copy its color and intensity every frame. `engine.sky.csm` is three's CSM object (lights,
26
+ breaks, updateFrustums()), null when off.
27
+ - Lit materials (Lambert, Phong, Standard, Physical, Toon, ShaderMaterial with `lights: true` and `#include <lights_fragment_begin>`) get a
28
+ named patch `csm`, added after the material's other patches; wind, cloud shadows, season, detail and lighting patches stay, and wind
29
+ shadows still sway. Materials added later are picked up the next frame (the scene is walked once per frame while cascades are on).
30
+ Never call `CSM.setupMaterial` yourself: it overwrites `onBeforeCompile` and drops every patch. A game patch must not replace
31
+ `lights_fragment_begin` (it would clash with `csm`, reported when added).
32
+ - three's `ShaderChunk` is never changed (the addon's constructor does that globally; the engine swaps the chunk per material instead).
33
+ - With `shadow.updateEvery > 1` cascades move only on frames whose maps re-render (or when the camera jumps), so lights and maps agree.
34
+ - Photo mode raises `setShadowMapSize`, which is the sun's map: the nearest cascade, where it shows most.
35
+
36
+ ## Costs and stalls
37
+ - Each cascade draws the shadow casters once more (each culls to its own box; near ones see little). `engine.budget.byTag()` counts a
38
+ caster once per shadow-casting light, an upper bound. In the styletest acceptance test (software renderer, relative only) 3 cascades
39
+ went from 1 to 3 shadow passes and roughly doubled frame time; do not expect frame rate to improve.
40
+ - Switching cascades on, off or changing any cascade field recompiles every lit material once (a stall), and each material keeps the
41
+ old program until it is disposed (three would otherwise reuse a stale program whose uniforms no longer update). Do it on a settings
42
+ screen, not during play.
43
+ - Ladder for weaker devices: `cascades: 3` -> `2` -> `1` (one map); before dropping a cascade try a smaller `maxFar` or `mapSize`.
44
+ Low-tier devices default to 1 unless the style asks: `shadow: { cascades: 3, low: { cascades: 2 } }`. `sky({ shadow })` options keep
45
+ this: on low they use their own `low.cascades` (default 1).
46
+
47
+ ## With your own lights
48
+ Cascades only split the engine sun. `sky({ sun: false })` plus cascades throws; with your own DirectionalLight use three's CSM addon on it
49
+ directly (and then mind the two points above: `setupMaterial` order and the global chunk swap). Another shadow-casting DirectionalLight
50
+ next to cascades breaks the cascade order (three sorts shadow casters first); keep extra lights shadowless.
51
+
@@ -0,0 +1,114 @@
1
+ # Hand-painted art route: from Blender to the game
2
+
3
+ Code-built geometry (`models.js`, recipe 05) is good for blockout, props and variations, but it cannot reach the finish of hand-made art: painted
4
+ textures, baked shadows, sculpted edges. That finish comes from Blender. This page is the whole path, in order. The level naming rules live in
5
+ `10-blender-level.md`; they are not repeated here.
6
+
7
+ ## 1. In Blender
8
+ 1. **Model** at real scale (1 unit = 1 meter), origin at the object's base. Apply scale and rotation (Ctrl+A).
9
+ 2. **UV unwrap** every textured mesh. A mesh with a texture but no UV set shows one flat pixel (`assets check` warns `texture-without-uv`).
10
+ 3. **Bake** the look into textures: base color (the paint), optional AO, optional baked light. One image per material keeps draw calls low;
11
+ one shared atlas for many small props is cheaper still. Keep textures at 2048 or less (`assets check` warns above that).
12
+ 4. **Name things**: objects, materials and (for animated models) actions. Names survive export and compression, and the engine reads them
13
+ (`spawn`, `col_xxx`, `trigger_xxx`, `template`, `id`; ground type from the material name, see recipe 10).
14
+
15
+ ## 2. Export glTF / GLB
16
+ File > Export > glTF 2.0, into `art/models/` of the game:
17
+ | Setting | Value | Why |
18
+ |---|---|---|
19
+ | Format | glTF Binary (.glb) | one file; `.gltf` plus loose files also works |
20
+ | Include > Custom Properties | on | `template`, `id`, `groundType`, `shape`... reach `userData` only this way |
21
+ | Transform > +Y Up | on | three.js is Y-up; the exporter converts from Blender's Z-up |
22
+ | Mesh > Apply Modifiers | on | the game gets the shape you see |
23
+ | Mesh > UVs, Normals, Vertex Colors | on if used | missing data cannot be added later |
24
+ | Material > Images | Automatic (embedded in the .glb) | `threedog assets` recompresses them anyway |
25
+ | Animation > Actions / NLA tracks | on for animated models | each action becomes one clip; name it as the game will (`Idle`, `Walk`, `Slash`) |
26
+ | Limit to > Visible Objects | off for levels | hidden `col_` boxes must be exported |
27
+
28
+ Do not join meshes or decimate a level: node names are its interface.
29
+
30
+ ## 3. Check, then compress
31
+ ```
32
+ threedog assets check art/models/town.glb # inspect only: spawns, col_ colliders, trigger_ zones, template / id nodes, material suspicions
33
+ threedog assets # compress art/models/*.glb into public/models/ (add -w my-game for a game)
34
+ ```
35
+ `assets check` also lists materials, textures with the color space three gives them (by slot), normal maps, clips, `col_` colliders and template / id nodes.
36
+ After loading, `engine.assets.report('hero')` (or `.reportText`; pass a copy from `model()` to check what the game shows) lists the same from the scene and
37
+ flags what the file has but the scene lost: `normal-map-lost`, `material-replaced` (a style role took over), `clip-lost`, `clip-unmapped` (an animation
38
+ state names a clip the file lacks), `node-lost`, and wrong color spaces. The engine never recomputes normals or drops a normal map on a GLB; only code
39
+ that swaps materials as in section 5 does.
40
+ Swapping an export for a new one: `threedog assets check new.glb --against old.glb` lists what the old file had and the new one lacks (errors: `col_`
41
+ colliders, template / id nodes, spawn / trigger_ / npc_ / marker_ points; warnings: clips, materials, points moved over 0.5 m, a bounding box that changed over 15%).
42
+ `assets check` exits 1 on errors (`--strict`: on warnings too; `--json` for tools). It changes no file.
43
+ `assets` keeps names, hierarchy and materials and only compresses:
44
+ | Step | What it does | When it matters |
45
+ |---|---|---|
46
+ | Meshopt | compresses geometry; the decoder ships with the engine | always on; smaller download, no visual change |
47
+ | WebP | compresses textures for the download | default; GPU memory is unchanged (the GPU holds raw pixels) |
48
+ | KTX2 (`threedog assets --ktx2`) | textures stay compressed on the GPU too | many or large textures; needs the `ktx` tool (KTX-Software), else falls back to WebP and says so (`--ktx2 --strict` fails instead) |
49
+
50
+ It needs `@gltf-transform/cli` (`npm i -D @gltf-transform/cli`). Unchanged files are skipped; `--force` redoes everything.
51
+
52
+ ### The same shot again, before and after
53
+ Declare fixed views once: `engine.views.define('gate', { position: [10, 4, 12], target: [0, 1, 0], fov: 50 })` (`views.show(name)` also works in code). Then
54
+ `npm run shot -- -w my-game --view gate --keep` takes the picture from there in any game (the page's own `?view=` still wins where a page handles it, as
55
+ in the style test). After a change, `npm run shot -- -w my-game --view gate --compare .threedog/shots/<before>.png` prints both file names, one pixel-diff
56
+ number (0 = identical) and the brightness / saturation / contrast / detail differences. A view holds the camera (`engine.takeCamera`) until `views.release()` or the handle `show()` returns is removed; a cutscene that held it before gets it back.
57
+ Views can also be content: `content/views.js` = `{ gate: { position: [10, 4, 12], target: [0, 1, 0], fov: 50 } }` is defined by `engine.content.load` (checked by `npm run check`; example: `examples/action/content/views.js`, `npm run shot -- action --view corner`).
58
+ `describe render` also shows the renderer output color space and warns when it is not srgb; `assets.report` flags color maps that are not srgb and data maps that are.
59
+
60
+ ### Looking at one part of the render
61
+ `engine.debug.view('albedo')` shows only the base color and texture (unlit), `'lighting'` plain white clay under the scene lights, `'shadow'` the same with
62
+ ambient and hemisphere light hidden so shadows read black, `'normals'` the normals as color (a normal map shows here); `'off'` restores everything.
63
+ A view is temporary and owner-scoped (`{ owner }`; another owner needs `force: true` to clear it), never saved, and `describe().render` / `describe render`
64
+ start with a DEBUG VIEW line while one is on, so a screenshot of clay is not taken for the real look. Meshes added after the call are not covered: call it again.
65
+ It needs the debug module (`engine.use(debug())`).
66
+
67
+ ## 4. Use it
68
+ Register the compressed file in the asset pack and refer to it by name everywhere else:
69
+ ```js
70
+ engine.assets.manifest({ name: 'town-art', models: {
71
+ well: '/models/well.glb',
72
+ hero: { url: '/models/hero.glb', critical: true, animation: { states: { attack: { clip: 'Slash', loop: false } } } },
73
+ } });
74
+ // content/templates.js: well: { model: 'well', collide: 'circle' } (recipe 30)
75
+ // content/props.js: { template: 'well', id: 'well-square', place: 'square', x: 4, z: -2 }
76
+ // or in code: engine.add(await engine.assets.model('well', { static: true }));
77
+ ```
78
+ A whole level is `level({ url: '/models/town.glb' })` (recipe 10). Animation clips and their mapping to game actions: `13-animation.md`.
79
+
80
+ ## 5. The GLB's own materials and the style
81
+ **The GLB keeps its own materials.** The engine loads them as they are (textures, colors, roughness) and does not swap them for style roles;
82
+ that is what lets a hand-painted texture show. `style.materials` (recipe 43) applies only to what code builds through `engine.makeMaterial(role, ...)`
83
+ (terrain, vegetation, procedural models, pickups). One scene can mix painted GLB props and styled code-built things.
84
+
85
+ There is no automatic mapping from a GLB material name to a style role and no flag for it. To make a GLB follow the style anyway, do it in your
86
+ game code, per model: name the material in Blender after the role (`wool`, `bark`) and look it up:
87
+ ```js
88
+ const m = await engine.assets.model('hat');
89
+ m.traverse(o => { if (o.isMesh) o.material = engine.makeMaterial(o.material.name, { color: o.material.color.getHex() }); });
90
+ ```
91
+ This replaces the painted material, so the texture is gone unless the role's spec sets `map` (recipe 43, "texture names"). A role the style does
92
+ not list falls back to `materials.default`.
93
+
94
+ ## 6. Smallest copyable flow
95
+ 1. Blender: a cube named `well`, UV unwrapped, base color baked to a texture, export `art/models/well.glb` with the settings above.
96
+ 2. `threedog assets check art/models/well.glb` (no errors), then `threedog assets`.
97
+ 3. Add `well: '/models/well.glb'` to `engine.assets.manifest({ models })`.
98
+ 4. `engine.add(await engine.assets.model('well'))`, then `threedog shot /your-page.html --describe-only` or open the page.
99
+
100
+ ## 7. Troubleshooting
101
+ | Symptom | Cause | Fix |
102
+ |---|---|---|
103
+ | Model too dark, or textures washed out/white | color space: a color map used as data or a data map as color (`assets check` reports `looks like data` / `looks like color`) | color maps (base color, emissive) are sRGB; normal, AO, roughness are Non-Color in Blender; one image per use |
104
+ | Texture shows one flat color | no UV set on that mesh (`texture-without-uv`) | unwrap in Blender, export again |
105
+ | Emissive never glows | emissive texture with black emissive color (`emissive-hidden`) | set the emissive color to white |
106
+ | Node names lost (`spawn`, `col_` not found) | meshes joined before export | keep objects separate; `threedog assets` never flattens or joins; run `assets check` to see what the level finds |
107
+ | Custom properties missing (`template`, `id`) | "Custom Properties" off at export | tick it and export again |
108
+ | Collision does nothing | `col_` object not exported, or no `collision()` module | export hidden objects; `engine.use(level(...), collision())`; test `engine.collision.walkable({ x, z })` |
109
+ | Painted material replaced by the flat style look | game code swapped it (section 5) | remove the swap, or give the role a `map` |
110
+ | File too big | large textures or many materials | textures at 2048 or less, share atlases, `threedog assets --ktx2`; sizes are in the `assets` report (`.threedog/assets-report.json`) |
111
+ | Clip not found | action name differs from the manifest `animation` mapping | rename the action in Blender or change `clip:` |
112
+
113
+ See also: `10-blender-level.md` (level names and markers), `43-shader-patches-surface-looks.md` (material roles and texture slots),
114
+ `35-style-from-reference.md` (a whole style from a reference image).
@@ -0,0 +1,44 @@
1
+ # Floating island look: round rim, snow that settles, flat backdrop
2
+
3
+ A floating island scene (recipe 42 for the outline) usually wants three more things: a soft rim, trees and ground that turn white while
4
+ it snows, and a plain background with no horizon. All three are style or scenario settings; none needs a shader of your own.
5
+
6
+ ## Round rim
7
+ `terrain({ shape: { edge: { round: 1.2 } } })` bends the top down by up to 1.2 m toward the rim. The side wall follows every bend of the
8
+ top (it is split where the rim crosses a cell diagonal), so there is no slit between top and wall at any `round`.
9
+
10
+ ## Season tint on a textured top
11
+ With `shading: 'texture'` the color map is applied before the vertex colors, so every patch after `color_fragment` sees the mapped color.
12
+ `style.seasons: { mode: 'mix', winter: { ground: 0xeef0f2 } }` therefore whitens the textured top like the side walls (recipe 43).
13
+
14
+ ## Snow that settles: `style.weather.snow.cover`
15
+ ```js
16
+ weather: {
17
+ snow: { size: 18, cover: { foliage: 0xf2f4f6, ground: 0xeef0f2, strength: 0.8 } },
18
+ },
19
+ ```
20
+ - While the weather's `snow` amount rises (any type with `snow > 0`), the foliage / ground season tint moves `strength` of the way toward
21
+ these colors, and melts back as it falls. It reuses the season patch uniforms (`uFoliageTint/Mix`, `uGroundTint/Mix`): vegetation, terrain
22
+ and any material with `applyEffects(m, { season: 'ground' })` follow; no extra shader pass.
23
+ - Over a `mode: 'mix'` season the two blend into one mix; a `'multiply'` season gives way while snow lies (use `'mix'` for smooth fades).
24
+ - Leave a part out to keep its season color (`cover: { foliage: 0xffffff }` whitens trees only). Leave `cover` out and snow is particles only.
25
+ - Ash, frost or anything else: `engine.sky.modify('ash', { groundCover: 0x555555, coverAmount: 0.6 })` (one layer per owner, `null` removes).
26
+
27
+ ## Weather changes and seasons in scenarios
28
+ - `engine.events.on('weather:change', ({ from, to }) => ...)`: once per change of name, when the blend starts (`weather.set` with the same name
29
+ again does not fire).
30
+ - `engine.applyState({ season: 'winter' })` (or `?season=winter`): jumps `sky.day` to that season's first day, time of day kept. Needs
31
+ `sky({ seasons })`; a wrong name throws with the calendar's list.
32
+
33
+ ## Flat backdrop: `style.sky.backdrop`
34
+ ```js
35
+ sky: { backdrop: 0xefebe4 }, // one color
36
+ sky: { backdrop: sky => (sky.isDay ? 0xefebe4 : 0x2c3346) }, // per frame (time of day, weather, your own state)
37
+ ```
38
+ - Hides the dome (no gradient, horizon line, sun / moon disk, stars or clouds) and sets `scene.background` to the color. A plain background
39
+ color is not tone mapped, so what you write is what shows. `style.background` stays the color when there is no sky module.
40
+ - The keyframes still light the world (sun, ambient, their colors).
41
+ - Fog: in its default `'horizon'` color the fog follows the backdrop, so far things fade into it; `style.sky.fog.color` of your own wins.
42
+ - Not together with `skybox` (both replace the dome).
43
+ - To fade the backdrop toward gray in snow, read the weather in the function: `sky => new THREE.Color(0xefebe4).lerp(gray, engine.weather.current.snow * 0.3)`
44
+ (reuse the Color objects; it runs every frame).
@@ -0,0 +1,70 @@
1
+ # 48. `engine.makeMaterial(role, spec)`: which keys work, who wins
2
+
3
+ `engine.makeMaterial('furniture', { color: 0x8a5a36 })` returns a normal three.js material. The **role** picks the look from the style pack
4
+ (`style.materials[role]`, unlisted roles use `materials.default`); the **spec** is this call's own settings.
5
+
6
+ ## Which spec keys are accepted
7
+
8
+ - **Any real property of the material**: `color`, `emissive`, `emissiveIntensity`, `roughness`, `metalness` (standard/physical only), `shininess` (phong),
9
+ `transparent`, `opacity`, `side` (`THREE.DoubleSide`), `vertexColors`, `flatShading`, `wireframe`, `alphaTest`, `depthWrite`, `fog`... Colors take
10
+ a hex, a CSS string or a `THREE.Color`; a Vector2 prop takes `[x, y]`.
11
+ - `type`: `'lambert' | 'phong' | 'standard' | 'physical' | 'toon' | 'basic'` (default `lambert`, or whatever the pack says).
12
+ - Texture slots by asset name (or a `THREE.Texture`): `map`, `emissiveMap` (sRGB), `normalMap`, `roughnessMap`, `metalnessMap`, `aoMap`, `bumpMap`,
13
+ `alphaMap`... The slot must exist on the type (`roughnessMap` needs `standard`). Plus `repeat` (number or `[x, y]`) and `wrap` (`repeat | clamp | mirror`).
14
+ - `detail`: grain / paper / strokes / a texture laid over the surface in world space (no UVs).
15
+ - `lighting`: extra light shaping (shadow tint, rim, wrap, own GLSL), merged over `style.lighting`; `false` opts out.
16
+ - toon only: `steps` (number of bands), or `ramp` (+ `soften`). `ramp` on a non-toon type throws.
17
+ - A key the chosen material does not have (`roughness` on lambert) is skipped on purpose, so one spec works for any type.
18
+ A key that looks like a typo of a real one (`roughnes`) warns once in dev with `did you mean 'roughness'?`. Nothing is ever blocked.
19
+
20
+ ## Who wins: pack or call
21
+
22
+ The pack entry is the default, the call wins. For a pack **spec** the two are merged (`default` spec, then the role's spec, then your call);
23
+ the same key in the call overrides the pack's:
24
+
25
+ ```js
26
+ // pack: materials: { building: { type: 'standard', roughness: 0.8 } }
27
+ engine.makeMaterial('building', { roughness: 0.2 }); // roughness 0.2, still standard
28
+ engine.makeMaterial('building', { type: 'toon', steps: 4 }); // your type wins too
29
+ ```
30
+
31
+ A pack entry that is a **Material instance** is cloned, then your keys are set on the clone (keys it lacks are skipped).
32
+ A pack **function** `(params, role, engine) => Material` receives your spec first and decides itself; keys it did not use are set afterwards.
33
+ The pack's `style.lighting` is added unless your spec says `lighting: false`.
34
+
35
+ ## Tweak the returned material directly
36
+
37
+ The result is an ordinary `THREE.Material`; edit it freely. The engine does not wrap or track it, so this is not "bypassing" anything:
38
+
39
+ ```js
40
+ const glass = engine.makeMaterial('window', { color: 0x9fd4ff, transparent: true, opacity: 0.35, side: THREE.DoubleSide });
41
+ glass.depthWrite = false; // plain property edit, fine
42
+ glass.onBeforeCompile = ...; // allowed, but it replaces the engine's shader patches (wind, clouds, detail, lighting) on this material
43
+ ```
44
+
45
+ Keep `makeMaterial` as the way to *create* materials (a style swap then restyles the game, `npm run check` flags a bare `new THREE.Mesh*Material`);
46
+ afterwards use three.js normally. Changing `needsUpdate`-type settings (`vertexColors`, `flatShading`, `transparent`) after first render needs `mat.needsUpdate = true`.
47
+
48
+ ## Copyable examples
49
+
50
+ ```js
51
+ // Solid prop with vertex colors (merged model)
52
+ engine.makeMaterial('prop', { vertexColors: true });
53
+
54
+ // Textured PBR stone
55
+ engine.makeMaterial('rock', { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughness: 0.9, repeat: 4 });
56
+
57
+ // See-through, double-sided
58
+ engine.makeMaterial('banner', { color: 0xd04a3a, transparent: true, opacity: 0.8, side: THREE.DoubleSide });
59
+
60
+ // Glowing lamp
61
+ engine.makeMaterial('lamp', { color: 0x6b5a40, emissive: 0xffc070, emissiveIntensity: 1.2 });
62
+
63
+ // Grain over the surface, no extra shading
64
+ engine.makeMaterial('wall', { color: 0xc9b99a, detail: { noise: 'paper' }, lighting: false });
65
+
66
+ // Toon with an explicit light ramp
67
+ engine.makeMaterial('character', { type: 'toon', color: 0xe8a0a0, ramp: [0.25, 0.6, 1] });
68
+ ```
69
+
70
+ See also: `09-style-pack.md` (writing the pack side), `43-shader-patches-surface-looks.md` (detail / lighting / patches).
@@ -0,0 +1,71 @@
1
+ # Writing a game system module (crops, burning, a production machine) that plugs into the engine's contracts
2
+
3
+ A game system is a module (`{ name, install, ... }`) given to `engine.use(...)`. If it follows the five contracts below it saves, loads, skips time,
4
+ shows in `describe()` and the dev bridge, and can be driven by ops, without special cases. Read recipe 06 (clock, skip), 18 (world records), 23 (ops).
5
+
6
+ ## The five contracts
7
+ 1. **State.** Prefer world records (`engine.world.add({ kind, ... })`, recipe 18): saved, streamed and far-simulated for you. State that is not a
8
+ record (a counter, a machine's queue) goes in `engine.saves.register(key, { save, load, version?, migrate? })`. Raise `version` by 1 whenever the
9
+ saved shape changes and add `migrate: { oldVersion: d => newData }`. Never keep game state only in a closure or module variable.
10
+ 2. **Time, normal play.** Store *when* something happened in game seconds (`engine.clock.now`), and derive the state from `now - startedAt`. Never use
11
+ `Date.now`, `performance.now` or `setTimeout` for game time: they ignore pause, `timeScale`, `step` and saves. If you must accumulate, do it in
12
+ the module `fixed(dt, e)` hook (dt is fixed seconds; game seconds = dt x `clock.timeScale`).
13
+ 3. **Time, skipped** (`engine.skip`, the op `time.skip`, recipe 06 section 2). `fixed` hooks, physics and near simulation do **not** run during a skip.
14
+ A state derived from `clock.now` is exact for free. A module that accumulates in `fixed` must also implement `skip(dt, e, done)` (called once per
15
+ segment, `done` on the last; do heavy work once when `done`), or put the logic in a world record `far(rec, dt)`, which gets one catch-up call.
16
+ 4. **Observable.** Module hook `describe(e, ctx)` puts its return value in `describe().<module name>` (plain JSON; the bridge `describe <name>` and
17
+ `describeText()` show it). A game without a module uses `engine.describe.add(name, fn)`. The name must be new (it throws on a clash).
18
+ 5. **Actions are ops.** `engine.ops.define('noun.verb', { args, can, run, offers, reasons, desc })`. `can` is read-only and returns `true` or a reason
19
+ string (a key of `reasons`); `run` changes state; `offers(e, ctx)` lists the arg sets possible right now (shown by the bridge `ops` command and
20
+ `describe`). Call with `engine.ops.run(name, args)` -> `{ ok, value }` or `{ ok: false, reason }`. Never mutate state from UI code directly.
21
+
22
+ ## Declaring stage and dependencies
23
+ `stage` picks where the hooks run (first to last): `control, world, environment, gameplay, presentation, late (default), audio`; `before / after`
24
+ (module names) only order modules inside one stage; a contradiction with the stage order throws. `requires: ['world']` must already be installed (throws
25
+ otherwise: put those `engine.use` calls first). `optional: { sky: 'what is lost without it' }` is a soft dependency (use `engine.sky?.`). Core never imports
26
+ modules. The module `name` must not clash with an existing engine property.
27
+
28
+ ## One copyable module: a crop
29
+ ```js
30
+ export const crops = () => {
31
+ const plots = new Map(); // id -> plantedAt (game seconds)
32
+ return {
33
+ name: 'crops', stage: 'gameplay', requires: [],
34
+ install(e) {
35
+ e.saves.register('crops', { version: 1, // contract 1: saved and restored
36
+ save: () => [...plots],
37
+ load: d => { plots.clear(); for (const [id, t] of d) plots.set(id, t); } });
38
+ const grown = id => Math.min(1, (e.clock.now - plots.get(id)) / 120); // contracts 2+3: derived from clock.now, so normal == skipped
39
+ e.ops.define('crop.plant', { args: { id: 'string' }, desc: 'Plant a crop plot', // contract 5
40
+ can: (_, { id }) => (plots.has(id) ? 'taken' : true),
41
+ run: (_, { id }) => { plots.set(id, e.clock.now); return id; }, reasons: { taken: 'Plot already planted' } });
42
+ e.ops.define('crop.harvest', { args: { id: 'string' }, desc: 'Harvest a ripe crop',
43
+ can: (_, { id }) => (!plots.has(id) ? 'empty' : grown(id) < 1 ? 'notRipe' : true),
44
+ offers: () => [...plots.keys()].filter(id => grown(id) >= 1).map(id => ({ id })),
45
+ run: (_, { id }) => { plots.delete(id); e.inventory.add('carrot', 2); return id; },
46
+ reasons: { empty: 'Nothing planted', notRipe: 'Not ripe yet' } });
47
+ return { grown }; // becomes engine.crops
48
+ },
49
+ describe: e => ({ plots: plots.size, ripe: [...plots.keys()].filter(id => e.crops.grown(id) >= 1) }), // contract 4
50
+ };
51
+ };
52
+ ```
53
+ Needs the `inventory`
54
+ module (add `requires: ['inventory']`, or drop the `inventory.add` line).
55
+
56
+ ## Check "advance 10h normally == skip 10h" (bridge, no new tools)
57
+ ```
58
+ npx threedog op crop.plant id=a ; npx threedog step 36000 ; npx threedog describe crops # A: normal play
59
+ npx threedog reload ; npx threedog op crop.plant id=a ; npx threedog op time.skip seconds=36000 ; npx threedog describe crops # B: skipped
60
+ npx threedog js "JSON.stringify(engine.crops.grown('a'))" # same number both times; compare whole state with: threedog snap-describe save|diff
61
+ ```
62
+ Both runs must give equal `describe crops` (and `describe time`); if B differs, the module accumulates in `fixed` and needs a `skip` hook or `far`.
63
+
64
+ ## What the engine does NOT check for you
65
+ - That `save` really includes **all** your state, or that `load` is the inverse of `save` (an unsaved field silently resets on load).
66
+ - That your state is equal after skip versus step: it only skips the hooks it knows about. A `setTimeout`, a closure counter or a `fixed` accumulator
67
+ is silently *not* advanced during a skip.
68
+ - That `can` is side-effect free and that `run` does not need `can` to have passed; `offers` is not checked against `can`.
69
+ - That `describe` returns everything that matters (a field left out is invisible to the AI and to snapshot diffs).
70
+ - That the stage/`before`/`after` you chose is the right one for your logic (only contradictions throw).
71
+ - Raising `version` and writing `migrate` when the saved shape changes (the engine only reports a missing step when an old save is loaded).
@@ -0,0 +1,12 @@
1
+ # Bring your own renderer: `createEngine({ renderer })`
2
+
3
+ Pass a ready three.js renderer when the game must own it (shared canvas, an editor, a custom context):
4
+
5
+ ```js
6
+ const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
7
+ const engine = createEngine({ renderer, style }); // canvas defaults to renderer.domElement
8
+ ```
9
+
10
+ - The engine configures only a renderer it created itself. With yours it sets nothing: pixel ratio (unless `pixelRatio` is given), size, tone mapping, exposure and shadow map stay as you left them, so `style.toneMapping` / `style.exposure` do not apply. Set them yourself on the renderer.
11
+ - **WebGL is the fully supported path.** Shader patches (recipe 43) and post effects (the `EffectComposer` chain) are written for `WebGLRenderer`; a WebGPU-style renderer may not run them. Everything else (scene, modules, input, saves, ops) does not depend on the renderer.
12
+ - Changing the renderer, lights or post effects is yours to do at any time; the engine never warns. `engine.describe().render` (CLI: `describe render`) lists the current values and tags each `engine` / `style` / `game`, so an AI can see who set a look.
@@ -0,0 +1,63 @@
1
+ # Capability catalog: ask what the game can do before reading docs
2
+
3
+ `engine.catalog()` answers "which modules are here, what can they do, what do they save, how do they keep time" from the registrations
4
+ that already exist: module definitions (`requires`, `optional`, `stage`, hooks), `engine.ops.define`, `engine.saves.register`,
5
+ `engine.describe.add` and params schemas. There is no second list to keep in sync: a removed op is gone from the catalog at once.
6
+
7
+ ## 1. Ask
8
+ ```js
9
+ engine.catalog(); // short list: [{ id: 'sky', kind: 'module', state: 'running', stage: 'environment', ops: [], saves: ['sky'], time: 'fixed+skip' }, ...]
10
+ engine.catalog('shop'); // one module expanded (below)
11
+ engine.catalog('shop.buy'); // one op: args schema, reasons, can / offers / undo / net, its last attempt
12
+ engine.catalog({ find: 'throw' }); // the short list filtered by id, label, op or save name
13
+ engine.catalog('core'); // what the engine registered itself (time.skip, clock, random...); 'game': what game code registered outside modules
14
+ ```
15
+ From the dev bridge: `npx threedog catalog`, `npx threedog catalog shop`, `npx threedog catalog --find buy` (`--json` for the data). The bridge prints the
16
+ same data and adds the files: `source` (where `name: 'shop'` or `define('shop.buy'` is written), `api` (the generated api page), `recipes` and
17
+ `examples` that use `engine.shop`. The MCP server has one `catalog` tool with the same arguments.
18
+
19
+ A module entry has: `state`, `stage`, `runIndex` (place in `engine.moduleOrder`), `critical`, `requires`, `optional` (`{ name, installed, lost }`),
20
+ `params` (schema, default and the value in use), `ops` (`{ name, desc, args, failures }`), `saves` (`{ key, version, migrates }`),
21
+ `time` (`hooks`, `step: 'fixed' | 'frame' | 'none'`, `skip`), `queries` (`describe().<id>`, names added with `describe.add`, the api's public names) and
22
+ `problems`, such as "fixed hook but no skip hook" or an `optional` module that is missing.
23
+
24
+ `threedog catalog <id>` lists each param as `key:type=default — sentence`: the type (for `any` params) and sentence are read from the module's api page (its options typedef JSDoc), so the schema keeps only names, defaults and checks; a param with no sentence shows `(no doc)` and counts as a problem (rule R38 lists the modules).
25
+
26
+ Who owns what: an op, save part or describe name registered while a module's `install()` or `init()` runs belongs to that module; so does an op named
27
+ `<module>.verb` or a save part keyed by the module name. Everything registered before the first `engine.use` is `core`; the rest is `game`.
28
+
29
+ ## 2. Declare args once (ops)
30
+ An op arg is `'int?'` or the full schema `{ type, default, min, max, values, desc, optional }`. The same object validates the call in dev, fills the
31
+ default before `can` and `run`, and is what the catalog and `threedog catalog` show, so the code never needs `n = 1` in two places.
32
+ ```js
33
+ engine.ops.define('shop.buy', {
34
+ args: { item: 'string', n: { type: 'int', default: 1, min: 1, max: 99, desc: 'how many' } },
35
+ can: (e, { item, n }) => e.inventory.count('gold') >= n * PRICE[item] ? true : 'noMoney',
36
+ run: (e, { item, n }) => e.inventory.add(item, n),
37
+ reasons: { noMoney: 'Not enough gold' }, // the failure codes the catalog lists
38
+ });
39
+ engine.ops.run('shop.buy', { item: 'bread', n: 0 }); // dev: throws "n must be >= 1"; release: returns { ok: false, code: 'badArgs' } (run never starts)
40
+ ```
41
+
42
+ ## 3. Declare module options once (`readParams`)
43
+ ```js
44
+ import { readParams } from 'threedog';
45
+ const PARAMS = { radius: { type: 'number', default: 2, min: 0, desc: 'pickup reach in m' }, sound: 'string?' };
46
+ export const magnet = (opts) => {
47
+ const o = readParams('magnet', PARAMS, opts); // wrong type / out of range throws [module-params] with the fix; an unknown key throws in dev and warns once in a release build
48
+ return { name: 'magnet', params: PARAMS, options: o, stage: 'gameplay', install(e) { return { radius: o.radius }; } };
49
+ };
50
+ ```
51
+ `params` and `options` on the definition are what `engine.catalog('magnet').params` reads; `engine.use` re-checks them in dev for a definition built by hand.
52
+ The schema types are those of op args plus `object`, `array` and `function` (options may hold callbacks; op args may not).
53
+
54
+ ## 4. Debugging with it
55
+ "Why does the throw fail": `threedog catalog combat.throw` shows its args, the failure codes it can return and its last attempt with the reason;
56
+ `threedog explain op combat.throw ...` (recipe 23) then says why for given args. "Does sleeping advance my crops": `threedog catalog crops` shows the
57
+ time hooks; a `fixed` hook without `skip` is listed under problems (recipe 49).
58
+
59
+ ## 5. "How do I get this effect": `threedog how`
60
+ `npx threedog how "rain"` (also `how 下雨`) scores the words of the task against the AI.md task rows and the recipe headings with their first sentence, and prints the
61
+ top five: the API in the row, the recipe path with section (`recipes/08-weather-sky.md §1`) and a one-line snippet. It reads the docs only, so it works with no page
62
+ and prints the same list every run. When a dev page runs it adds up to three live catalog modules whose name matches the first English word. Words match at a word
63
+ start (`rain` does not hit `terrain`); a few Chinese task words are mapped to the English words the docs use. No hit means rephrase, or read AI.md.