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,97 @@
1
+ # Terrain look open points: shading, color map, triangle cut, normals
2
+
3
+ For an AI that wants the ground to look a way the defaults do not: crisp color borders (a river bank, a path edge), a coarse low-poly mesh with
4
+ fine color, a different triangle cut, custom lighting normals. Terrain basics are in `28-terrain.md`, ground color noise in
5
+ `36-sky-ground-plant-looks.md`. Every default below is the original look, bit for bit (checked against hashes of the old output in
6
+ `tests/specs/terrain-look.mjs`). Each knob has three exits: a parameter, a small pure function, or replacing the whole ground material.
7
+
8
+ ## Why the bank is jagged: color lived on the mesh
9
+ With `shading: 'smooth'` or `'flat'` a color is computed at a grid point (or triangle center) and blended across the triangle. At the default
10
+ `resolution: 16` on a 64 m chunk that is one color sample per 4 m, so any border between two ground types can only run along triangle edges.
11
+ Raising `resolution` fixes it at the price of triangles (and collision, and edit granularity). `shading: 'texture'` cuts the link: color is
12
+ computed per pixel into a per-chunk image, the mesh stays as coarse as you like.
13
+
14
+ Material roles (`makeMaterial('role')`) are free labels: a role the style does not list uses `materials.default`, and the engine warns only on a name
15
+ that looks like a typo of a known one (`09-style-pack.md`). A style that wants a special ground surface adds its own role and ground material.
16
+
17
+ ## 1. `shading: 'texture'` (and `colorResolution`)
18
+ ```js
19
+ engine.use(terrain({ ...terrainPreset(), shading: 'texture', colorResolution: 128 }));
20
+ // or as a look of a style pack: terrain: { config: { shading: 'texture', colorResolution: 128 }, colors, biomeColors, ... }
21
+ ```
22
+ - A worker computes a `(colorResolution + 2)^2` RGBA image per chunk with the same rules as the vertex colors (`faceColor`: ground type from your
23
+ `groundType`, `biomeColors` two-color noise blend, `steep` slope colors, `style.terrain.variation` blend / jitter / patches, painted cells).
24
+ The main thread uploads it as a `DataTexture` (sRGB, mipmaps, anisotropy 4). The `+ 2` is a 1 pixel border computed from world coordinates, so
25
+ neighboring chunks hold identical values at the seam and no seam shows (checked byte for byte).
26
+ - Vertex colors are plain white in this mode (they carry no color). The material samples the image by world xz (the `world` patch), so `uv`
27
+ stays free (`world xz / chunk size`, for your own textures). Each chunk gets its own clone of the terrain material (same patches, one compiled
28
+ program), so a change you make to the terrain material object after chunks exist does not reach loaded chunks; pass it through `terrain({ material })`.
29
+ - Painted cells (`terrain.edit(..., { paint })`) keep their whole-cell color; the image of every chunk touched by an edit is re-uploaded in place.
30
+ - Steep-slope colors test a normal interpolated between grid points, so they no longer follow single triangles either.
31
+ - Independent of `resolution`: `resolution` still sets mesh, collision and edit granularity, `colorResolution` only the color detail
32
+ (64 m chunk: 128 = 0.5 m per pixel, 256 = 0.25 m).
33
+
34
+ Numbers (resolution 16, 64 m chunk, a curved ground-type border, rendered top-down in the real engine, error against the true curve):
35
+
36
+ | shading | border RMS error | border jaggedness (RMS 2nd difference) |
37
+ | --- | --- | --- |
38
+ | smooth | 1.12 m | 0.48 |
39
+ | texture, colorResolution 128 | 0.14 m | 0.10 |
40
+
41
+ Cost (software-rendered machine, relative values only):
42
+ - worker time per chunk: about 9 ms for `texture` at 128 (calculation is mostly your `groundType` called once per pixel) against 1.1 ms for smooth
43
+ (measured in Node, the worker runs the same code); 64 costs a quarter, 256 four times that.
44
+ - memory: 130 x 130 x 4 = 68 KB per chunk plus mipmaps (about 90 KB; 23 KB at 64). 69 loaded chunks = about 6 MB at 128.
45
+ - `threedog perf --only=stream --shading=texture` against the default: frame CPU average 5.5 ms both; worst frame 64 ms -> 88 ms (one-time shader
46
+ program compile plus first uploads, it lands once, not per chunk); upload stage total 41 ms -> 112 ms over 69 chunks.
47
+ - Low-tier devices (`engine.tier === 'low'`, see `core/tier.js`): if you did not set `colorResolution`, the terrain module uses 64 there. To skip the
48
+ color map completely on low tier, choose the shading yourself: `shading: engine.tier === 'low' ? 'smooth' : 'texture'` in your terrain() call.
49
+ - With `terrain({ shape })` (an outline, `42-terrain-shape.md`) the map covers the top only: void pixels keep the color of the ground under them
50
+ (no seam at the rim) with alpha 0, and island sides and bottom draw with vertex colors (or `shape.side.material`).
51
+
52
+ ## 2. Lighting normals: `normals` and `normalFn`
53
+ - `shading: 'smooth'` lights with one normal per grid point, `'flat'` one per triangle. In texture mode choose: `normals: 'smooth'` (default) or
54
+ `'flat'` (faceted light, fine color: a low-poly shape with crisp borders).
55
+ - `normalFn(i, j, h, cell) => [nx, ny, nz]` replaces the smooth normal at grid point `(i, j)`; `h(i, j)` reads a grid-point height, `cell` is the
56
+ spacing in meters. Pure like `height` / `groundType` (only its parameters, `Math`; a function you pass travels to workers as source text and an
57
+ outside variable throws naming it). The engine normalizes the result. Default: central difference of the four neighbors.
58
+ ```js
59
+ terrain({ normalFn: (i, j, h, cell) => [(h(i - 1, j) - h(i + 1, j)) / cell, 4, (h(i, j - 1) - h(i, j + 1)) / cell] }) // gentler lighting on slopes
60
+ ```
61
+ `normals` and `normalFn` are looks (a style may set them); they change light only, never height or collision.
62
+
63
+ ## 3. `diagonal`: how a cell is cut into triangles
64
+ ```js
65
+ terrain({ diagonal: 'adaptive' }) // 'fixed' (default) | 'adaptive' | 'alternate'
66
+ ```
67
+ `fixed` cuts every cell the same way (the original mesh). `adaptive` cuts along the diagonal with the smaller height difference, which removes
68
+ the zigzag ridges a fixed cut leaves on a slope; `alternate` flips every other cell (no directional bias on flat low-poly facets). `engine.surface`,
69
+ collision and vegetation heights follow the chosen cut, so nothing floats. Because it changes the walkable shape, it belongs to the game's
70
+ `terrain({...})`, not to a style (rule R34 and `style check` accept `shading`, `colorResolution`, `normals`, `normalFn` in `style.terrain.config`
71
+ and flag `diagonal`).
72
+
73
+ ## 4. `boundsPad`: the chunk bounding sphere margin
74
+ `boundsPad: { up: 3, radius: 8 }` (meters, the original values) is the margin of the culling sphere: the center is raised by `up`, the radius grows
75
+ by `radius`. Raise it if a shader moves vertices far (wind on tall ground cover, a vertex-displacement patch) and chunks pop out at the screen edge.
76
+
77
+ ## 5. Relation to `style.terrain.variation`
78
+ `variation` shapes *what* color a point gets (blend size, grain, patches); `shading` decides *where* that color is evaluated. They compose:
79
+ in texture mode the grain (`jitter.size`, default 0.33 m) is sampled by pixel, so with `colorResolution: 128` (0.5 m pixels) it is coarser than the
80
+ vertex version; set `jitter.size` near the pixel size or use `patches` for the painterly look. In vertex modes the mesh limited every one of these to
81
+ cell size; in texture mode `patches: { size: 20, levels: 4 }` shows real hard-edged strokes.
82
+
83
+ ## 6. Example: a river bank
84
+ ```js
85
+ engine.use(terrain({
86
+ shading: 'texture', colorResolution: 192, resolution: 16,
87
+ height: (x, z) => 0,
88
+ // the border is a curve; the ground type is evaluated per pixel
89
+ groundType: (x, z) => z > 32 + 14 * Math.sin(x * 0.09) ? 'grass' : 'sand',
90
+ colors: { grass: 0x5a8a3a, sand: 0xd8c690 }, biomeColors: { grass: ['grass'], sand: ['sand'] },
91
+ }));
92
+ ```
93
+ Using a preset (`riverAt` of `@threedog/terrain-noise`) the same switch gives crisp banks without more triangles: `terrain({ ...terrainPreset(), shading: 'texture' })`.
94
+
95
+ ## Whole replacement
96
+ Anything beyond this: `terrain({ material })` (or `style.terrain.material`) swaps the ground material and `engine.terrain.T.buildChunk(cx, cz)` returns the
97
+ raw arrays (`pos`, `nor`, `col`, `uv`, and `tex: { data, size }` in texture mode) if you build chunk meshes yourself.
@@ -0,0 +1,83 @@
1
+ # Environment look open points: lights, fog, exposure, sky layers
2
+
3
+ For an AI that wants lighting, fog or the sky to look a way the defaults do not. Sky basics are in `08-weather-sky.md`, clouds and ground color in
4
+ `36-sky-ground-plant-looks.md`, environment lighting in `34-environment-lighting.md`. Every default below draws exactly what it drew before
5
+ (checked pixel by pixel in `tests/specs/appearance-env.mjs`). Each knob has three exits: a parameter, a GLSL function you replace, or turning the
6
+ engine's part off and bringing your own three.js objects.
7
+
8
+ ## Lights: let the sky drive them, drive them yourself, or switch them off
9
+ The engine has one directional light (`engine.lights.sun`, also `engine.sky.sun`; moonlight at night, the shadows live on it) and one hemisphere
10
+ ambient (`engine.lights.hemi` = `engine.sky.hemi`). The sky module rewrites their color and intensity every frame from `style.sky.keyframes`,
11
+ so editing them directly is overwritten (a dev warning says so). **Without the sky module** both lights still exist as a bright placeholder (hemi 1.2, white sun 2 at (40, 80, 30), no shadows): for a night scene set them yourself (`engine.lights.sun.color/intensity`, `engine.lights.hemi.intensity`) or install `sky`. Choose per light:
12
+
13
+ ```js
14
+ engine.use(sky({ sun: 'manual' })); // the sky still aims the sun along the time of day and moves the shadow box
15
+ engine.sky.sun.color.set(0xffd0a0); engine.sky.sun.intensity = 1.4; // yours now, never overwritten
16
+
17
+ engine.use(sky({ sun: false, hemisphere: false })); // a dungeon: both hidden, never touched; the dome still shows sun and moon
18
+ const torch = new THREE.PointLight(0xffa040, 6, 12); engine.add(torch); // add your own lights before engine.start()
19
+ ```
20
+
21
+ - `createEngine({ lights: false })` goes one step further: the default sun and hemisphere are never put in the scene (no placeholder light even before a sky is installed), `engine.lights.sun` / `hemi` stay as detached objects so nothing reads `undefined`. Use it for a scene lit entirely by your own lights.
22
+ - Many lights indoors (lamps, torches in every room): do not add a `PointLight` per lamp; `lightPool({ point: 6 })` keeps a fixed number of real lights and moves them to the nearest sources, so the light count (and shader recompiles) stays constant.
23
+ - Default `true`: the sky drives everything (as before). `'manual'`: color and intensity are the game's; the sun keeps its direction and shadow box.
24
+ `false`: `visible = false`, no shadows, never touched (lightning no longer flashes the ambient either).
25
+ - Shadows: only the engine sun's shadow is managed (size, bias, snapping via `engine.look.shadow.set`). Your own `castShadow` lights work as in
26
+ three.js, each costing its own shadow pass; `engine.setShadows(false)` turns theirs off too and restores them after.
27
+ - Add or remove lights before `engine.start()`: a light count that changes mid-play recompiles every material (one long frame). Many torches:
28
+ `lightPool()`. Brightness tweaks without giving up the keyframes: a multiplier layer, see [recipe 52](52-look.md#skymodify-vs-looklights).
29
+
30
+ ## Fog: kind, color, density, or your own math
31
+ `style.sky.fog` (a look; `sky({ fog })` overrides it):
32
+
33
+ ```js
34
+ fog: { kind: 'exp2' } // three's FogExp2, density derived so it reaches as far as the linear fog did
35
+ fog: { kind: 'height', height: 2, falloff: 0.08, density: 0.03 } // valley mist: thick below y = 2, thinning 8% per meter above
36
+ fog: { kind: 'exp', color: 0xb8c4d0 } // own color: the dome's lower band fades to it, so the horizon line never shows
37
+ fog: { color: sky => sky.isDay ? 0xc8d0d8 : 0x10141c } // a function, evaluated each frame
38
+ fog: { kind: 'exp', glsl: `vec4 threedogFog(vec3 c, float depth, vec3 p){
39
+ float f = 1.0 - exp(-fogDensity * depth);
40
+ return vec4(mix(c, vec3(1.0, 0.85, 0.7), f * 0.3), f); }` } // warm far haze
41
+ ```
42
+
43
+ - `kind`: `'linear'` (default, near = 0.3 x far) | `'exp'` | `'exp2'` | `'height'`. `color`: `'horizon'` (default) | color | `(sky) => color`.
44
+ `density` per meter (default derived from `engine.fogFar`); weather fog divides it, `engine.setFogFar` still moves the derived one.
45
+ - `glsl` replaces the fog math in every material, built-in or yours: `vec4 threedogFog(vec3 color, float depth, vec3 worldPos)` returns
46
+ (fog rgb, amount 0..1). In scope: `fogColor`, `cameraPosition`, `fogNear` / `fogFar` (linear) or `fogDensity` (other kinds),
47
+ `THREEDOG_FOG_HEIGHT`, `THREEDOG_FOG_FALLOFF`.
48
+ - How it works and its limits: `'exp'`, `'height'` and `glsl` replace three's `fog_*` shader chunks once at install (three caches programs by
49
+ material settings, not by source, so the fog model cannot change mid-play; color and density stay live). No custom uniforms (three copies fog
50
+ uniforms into each material when it compiles); write constants. Materials with `fog: false` (the dome) are not fogged; the dome follows the
51
+ fog color as above. A ShaderMaterial of your own gets the same fog when it sets `fog: true` and includes the fog chunks.
52
+ - Whole replacement: `sky({ fog: 'manual' })` creates `scene.fog` once and never writes it (set its color / near / far, or assign your own
53
+ object); `sky({ fog: false })` sets `scene.fog = null` (leave fog out of your materials with `fog: false` and fog in a post pass). Default
54
+ `true` = the sky drives it. This is a sky() option, not a style key.
55
+ - Two engines on one page share three's fog chunks: the same custom `kind` / `height` / `falloff` / `glsl` is fine (reference counted, the
56
+ originals return when the last one is disposed); a different custom setting throws. Plain `linear` / `exp2` do not touch the chunks.
57
+
58
+ ## Exposure and tone mapping over time
59
+ ```js
60
+ exposure: [[0, 1.6], [0.3, 1], [0.75, 1.1]] // style: per time of day (0-1), wraps across midnight
61
+ exposure: sky => sky.isDay ? 1 : 1.5 // or a function, evaluated by the sky module every frame
62
+ engine.look.tone.set({ exposure: 1.3 }); // at run time: number, keyframes or function (replaces the style's);
63
+ engine.look.tone.set({ mapping: 'agx' }); // 'aces' | 'agx' | 'neutral' | 'none'; materials recompile on their next draw
64
+ ```
65
+ A plain number behaves as before (set once, no per-frame work). Keyframes and functions need the sky module (it knows the time of day).
66
+
67
+ ## Extra sky layers: rainbow, aurora, painted bands
68
+ `style.sky.layers` (or `sky({ layers })`), drawn on the dome after clouds and stars; none by default (the dome shader text is then unchanged):
69
+
70
+ ```js
71
+ layers: [{ blend: 'add', uniforms: { uAurora: [0.2, 1, 0.6] }, glsl: `vec4 threedogSkyLayer(vec3 d, float time, vec3 sunDir, float night){
72
+ float band = smoothstep(0.25, 0.45, d.y) * (1.0 - smoothstep(0.55, 0.8, d.y));
73
+ float n = threedogNoise(vec2(d.x * 4.0 + time * 0.05, d.z * 2.0));
74
+ return vec4(uAurora, band * n * night); }` }]
75
+ ```
76
+ Signature `vec4 threedogSkyLayer(vec3 dir, float time, vec3 sunDir, float night)` returns (rgb, amount). `blend: 'mix'` (default) or `'add'`;
77
+ `order` sorts layers (smaller first); `uniforms` like `clouds.uniforms`, live in `engine.sky.dome.material.uniforms.uAurora.value`. Each layer's function is
78
+ renamed (`threedogSkyLayer0`, `1`, ...), so layers from different style parts never clash. Whole replacement: `style.sky.skybox` (a panorama) or
79
+ hide `engine.sky.dome` and add your own background.
80
+
81
+ ## Water and weather particles
82
+ Water depth color, crest foam, wave / surface GLSL, reflections; rain and snow shape, size, density and shaders, the lightning look, and
83
+ particles for the game's own weather (`engine.look.weather.replace`): `44-water-weather-look-hooks.md`.
@@ -0,0 +1,108 @@
1
+ # Scene: what is in the world, where, and what a save keeps
2
+
3
+ The engine's three outward concepts are **Scene** (what stands in the world, where it is, how you interact with it), **Assets** (models, textures,
4
+ sounds, fonts: `05-props-bake.md` §3b) and **Style** (how it looks: `09-style-pack.md`). Content packs belong to Scene: they are the data form of it.
5
+ Patches, ops and world records are the scene's inner machinery; read them when you need them (`23-ops.md`, `18-world.md`).
6
+
7
+ ## 1. Two doors into one scene
8
+ A scene object comes in either of two ways, and both end up in the same scene:
9
+
10
+ - **Plain three.js.** Build a mesh or group, call `engine.add(obj)`. Nothing else is required. This is the right way for anything your code rebuilds
11
+ on every start.
12
+ - **A template.** Define it in `content/templates.js`, place it in `content/props.js` with an `id`, or create it during play with
13
+ `engine.spawn(name, at)`. This is the right way for anything that must be saved, be editable without code, or exist in many copies.
14
+
15
+ The same windmill, both ways:
16
+
17
+ ```js
18
+ // A. plain three.js: your code builds it on every start
19
+ const mill = buildWindmill(); // THREE.Group
20
+ mill.position.set(20, 0, -10);
21
+ engine.snapToGround(mill);
22
+ engine.add(mill, { id: 'mill' });
23
+ engine.collision?.addCircle(mill, { radius: 1.3 });
24
+ engine.onFrame(dt => { mill.userData.blades.rotation.z += dt * 1.5; });
25
+ ```
26
+ ```js
27
+ // B. template: the definition is data; the model is a name in the asset manifest
28
+ // content/templates.js
29
+ export default { windmill: { model: 'windmill', collide: 'circle' } };
30
+ ```
31
+ ```js
32
+ // content/props.js
33
+ export default [{ id: 'windmill-hill', template: 'windmill', x: 20, z: -10 }];
34
+ ```
35
+ ```js
36
+ // main.js: a code-built model registered by name
37
+ engine.assets.manifest({ models: { windmill: buildWindmill } });
38
+ ```
39
+ Route B gives the object an id, a source line (`engine.world.origin('windmill-hill')`), a save record and a place a future editor can write back to.
40
+ Route A gives you less ceremony and full three.js control.
41
+
42
+ ## 2. What goes in content, what stays three.js
43
+ | Put it in content (templates, props, pickups, npcs, containers) | Write it as three.js (`engine.add`, `engine.scene.add`) |
44
+ |---|---|
45
+ | Must come back after a load, or the player can change it and the change must be saved | Rebuilt by your code on every start: lights, decoration, effects, bullets |
46
+ | Should be editable without a code change (position, state, copies) | Procedural or per-frame: particles, trails, shaders, a spinning blade |
47
+ | Many copies of one definition | A one-off with custom geometry or material logic |
48
+ | Has a state worth reading with `world.get(id)` | Pure presentation |
49
+
50
+ The rule check (R33) is deliberately narrow. It flags only the calls that would run again after a load and so duplicate saved data: `world.add`,
51
+ `engine.spawn`, `inventory.spawnPickup`, `npcs.add` and `entities.spawn` at startup. `engine.add`, `collision.*`, `rigid.*`, `interactions.add` and the
52
+ like are fine at startup.
53
+
54
+ ## 3. Which state a save keeps
55
+ The registry (`41-thing-registry.md`) sorts every scene object into one of four kinds:
56
+
57
+ | Kind | What it is | A save keeps | A save loses |
58
+ |---|---|---|---|
59
+ | `record` | A world record: template instance, props entry, pickup, NPC, level node | The record's fields and position; the model is rebuilt from the template | Direct edits to the model; change the record instead (`world.set`) |
60
+ | `code` | Added by your code with a stable id (`engine.add(obj, { id })`) during setup | Moves, visibility and deletion done through `thing.set` / `thing.remove` | Geometry, material changes, children added later, `userData`, state in closures (inside an `onFrame` callback) |
61
+ | `session` | Added by your code without an id, or during play | Nothing: it exists for this session only | Everything. After a load it does not come back. To keep it, make it a template and call `engine.spawn` in an op |
62
+ | `engine` | Owned by an engine module (water, sky, terrain) | Managed by that module | Do not edit it directly |
63
+
64
+ Writing `mesh.position.x = 3` in code always works; it just is not saved and cannot be undone.
65
+
66
+ ## 4. The calls
67
+ - `engine.add(obj, { id })`: registers `obj` under a stable id (`engine.add(obj)` works too: it gets a session id `obj#n`, never saved; `obj.name` is not an id).
68
+ - `engine.thing(idOrObject)`: what is this? Returns `{ id, kind, owner, at, phase, saved, keeps, loses, edit, object }` for any id or object; `engine.pick(x, y).thing` gives the same.
69
+ - `thing.set` and `thing.remove`: ops that move, show, hide or delete a registered object, undoable; for `code` objects they are saved as overrides.
70
+ - `engine.remove(obj)` forgets the object in the registry too.
71
+ Details and what a save keeps: `41-thing-registry.md`.
72
+
73
+ ## 5. Moving from three.js to a template
74
+ When an object turns out to need saving, editing or many copies: register its builder as a model (`assets.manifest({ models: { windmill: buildWindmill } })`),
75
+ write a template, add a placement with an id. Delete the `engine.add` line. Nothing else in the game changes.
76
+
77
+ ## 6. Verify
78
+ `threedog check` flags the startup calls above; `engine.world.origin(id)` and `engine.pick(x, y).thing` say where a record came from (`30-templates.md`
79
+ §5); `engine.world.query({ kind: 'windmill' })` lists the records a save would hold.
80
+
81
+ ## 7. Why is this mesh this colour? (material provenance)
82
+
83
+ `engine.inspect.scene()` / `npx threedog scene` list, for each mesh, one `material:` line and the renderer line (tone mapping, exposure; the same text as `describe().render`). Diagnostics only: nothing about the look changes.
84
+
85
+ ```
86
+ renderer: ACES (style) exposure 1.1 (style) shadows soft (engine)
87
+ ✓ roof [Mesh] (4, 3, 0) r=2 · MeshLambertMaterial/roof
88
+ material: roof from pack-spec [color] · MeshLambertMaterial #3b5168 · map x color #3b5168 (vertexColors off) · map (base colour)
89
+ note: map already carries colour and color #3b5168 is not white: the result is map x color (fine when it is a tint)
90
+ ```
91
+
92
+ - `from` is `pack-spec | pack-instance | pack-function | call-params | default`, `keys` the params the call passed; both come from `userData.materialSource`, which `makeMaterial` records (a material made by hand shows `unknown`).
93
+ - `--json` carries `material.info[]` per mesh: role, from, keys, type, color, maps (base colour vs detail), vertexColors, side, transparent, opacity, colorPath, notes.
94
+ - The tint note is not an error: a map times a non-white colour is how tinting works.
95
+
96
+ ## 8. When to write plain three.js directly, and which integrations you lose
97
+
98
+ Plain three.js is always allowed (`engine.scene`, `engine.renderer`, `engine.camera` are the real objects; `engine.add(obj, { id })` keeps it saveable). Write it directly for a one-off effect, a special mesh, a shader nothing else shares. What you give up depends on how the material or pass was made:
99
+
100
+ | You wrote | Not applied to it |
101
+ |---|---|
102
+ | `new THREE.MeshStandardMaterial(...)` (not `makeMaterial` / a look material) | wind sway, snow and season cover, cloud shadows, the engine fog hook, cascaded shadows, `look.surface` lighting and detail, `look.materials` roles, `debug.view` modes |
103
+ | your own `EffectComposer` / render call | `engine.post` effects, `look.post`, adaptive resolution, photo mode, `describe().render.post` |
104
+ | `renderer.toneMappingExposure = x`, `scene.fog = ...` | the owner record and the debug layer (`describe().look` tags it `three`); the sky keeps writing fog unless `look.fog.replace('manual')` |
105
+
106
+ Keep the integrations by going through the engine: `engine.makeMaterial('role', {...})` for the material, `look.materials.patch(name, { glsl }, { roles })` to add GLSL to a role, `look.post.patch(name, { glsl, slot })` or `look.post.replace([...])` for a screen effect.
107
+
108
+ `patch` vs `replace`: `patch(hook, glsl)` swaps one registered hook (`threedogWind`, `threedogFog`, `threedogLighting`, the water `wave`) and the rest of the engine's shader stays, so the integrations above still work. `replace(impl)` hands over the whole part (the ground material, the water surface, the whole post chain): everything that part did is now yours, including the fog, shadow and season hooks inside it. Prefer `patch`; use `replace` when the hook is too small. `engine.catalog('look.<part>')` lists the hooks and what each `replace` loses.
@@ -0,0 +1,93 @@
1
+ # Things: what is in the scene, who manages it, what a save keeps (engine.thing)
2
+
3
+ Every root you pass to `engine.add` is registered: an id, where it was added (`main.js:50`, dev builds only), who manages it and how much a save
4
+ keeps. World records (template instances, props, pickups, NPCs, level nodes) share the same id space and the same query, so one question works for a
5
+ plain three.js mesh and for a template instance alike. `engine.scene.add` adds without registering: the plain three.js way in, still legal.
6
+
7
+ ## 1. Give it an id
8
+ ```js
9
+ const windmill = buildWindmill(); // any Object3D
10
+ engine.add(windmill, { id: 'windmill' }); // at setup: thing.set / thing.remove changes to it are saved
11
+ engine.add(spark); // effects need no id: obj#7, this session only
12
+ engine.thing('windmill');
13
+ // { id: 'windmill', kind: 'Group', owner: 'game', at: 'main.js:50', phase: 'setup', saved: 'code',
14
+ // keeps: ['position, rotation, scale, visibility and removal made with thing.set / thing.remove (scene save part)'],
15
+ // loses: ['geometry and material changes', 'children added later', 'userData', ...], edit: 'added by code at main.js:50 (id ...)' }
16
+ engine.thing('windmill').object; // the live Object3D (not enumerable, so the result stays JSON-able)
17
+ engine.thing(engine.pick(0, 0).object).id; // any child resolves to its registered root; hit.thing says the same
18
+ ```
19
+ - The id is `{ id }`, else a session id `obj#n` (session tier: never saved). `obj.name` is not an id (GLB roots are all called `Scene`): it only helps `engine.thing(name)` find the object. An id is a non-empty string without `#`,
20
+ unique across `engine.add` objects and world records: a clash throws (`thing-id`) from either side (`engine.add` or `world.add`) and says which one holds it.
21
+ - With several objects in one call (`engine.add(a, b)`) pass no id; add the one that needs an id on its own.
22
+ - `engine.thing(id | name | obj)` throws with the closest id when nothing matches. `engine.inspect(id)` takes the same ids.
23
+ - `describe().scene` gives counts only: `{ game, code, session, world, engine, unsaved, conflicts, orphans }`. Objects of engine modules (particles,
24
+ physics bodies, nav helpers, hlod, grid tiles, the level root, streamed objects) are counted under `engine` and never listed as the game's.
25
+
26
+ ## 2. Four save tiers
27
+ Judged in this order (`thing.saved`):
28
+
29
+ | Tier | When | A save keeps | A save loses |
30
+ |---|---|---|---|
31
+ | `record` | a world record's model (templates, props, pickups, NPCs, level nodes) | the record's fields and position (world part); the model is rebuilt from its template / present | the model object itself; change it through the record |
32
+ | `code` | added by game code with a stable id at setup (before `engine.ready`, or in a `session:start` listener) | position, rotation, scale, visibility and removal made with `thing.set` / `thing.remove` (`scene` part) | geometry and material changes, children added later, `userData`, closure state, writes like `mesh.position.x = 3` |
33
+ | `session` | no stable id, or added during play | nothing: it exists only in this session | everything; it does not come back after a load |
34
+ | `engine` | managed by an engine module | its module's business | direct changes (the module rewrites them) |
35
+
36
+ Only transform, visibility and removal are saved for `code` objects; colours and materials belong to Style and are not saved. To keep something made
37
+ during play, make it a template and create it inside an op with `engine.spawn(name, at)`: a record is saved whole.
38
+
39
+ ## 3. Change it: thing.set / thing.remove (ops, undoable)
40
+ ```js
41
+ const args = { id: 'windmill', position: [5, 0, 2], rotation: 1.2 }; // rotation: a number is yaw, or [x, y, z]; scale: a number or [x, y, z]
42
+ const r = engine.ops.run('thing.set', args);
43
+ engine.ops.undo('thing.set', args, r.value); // back where it was
44
+ engine.ops.run('thing.remove', { id: 'windmill' }); // detached and kept: undo puts it back
45
+ ```
46
+ - A world record id turns into `world.set` / `world.move` (`rot` / `scale` are template instance fields) and `world.remove`; the model follows the
47
+ record. `visible` is refused for a record (`recordVisible`): hide its model with `present({ show })` and a field.
48
+ - A `code` object gets its new values written and recorded as an override; a `session` object only changes in this session.
49
+ - Objects of engine modules are refused (`engineOwned`).
50
+
51
+ ## 4. Saves: the `scene` part (version 1)
52
+ `{ set: { windmill: { position: [5, 0, 2] } }, removed: ['old-fence'] }`, only for `code` objects. A load first undoes the current overrides (a new
53
+ game applies an empty part, so everything goes back to what the code built), then applies the save. An id the save names but no object has yet waits:
54
+ the override applies the moment `engine.add(obj, { id })` runs. One that never comes is an orphan: kept in the save, listed in
55
+ `describe().scene.orphans` and warned once (`thing-orphan`).
56
+
57
+ ## 5. Dev checks
58
+ - `engine.add(obj, { save: true })` for an object that cannot be saved (no id, or during play) warns at once (`thing-unsaved`); objects added inside an
59
+ op are listed by `saves.save()` and in `describe().scene.unsaved`.
60
+ - `engine.add` of a world model throws (`thing-owned`): world adds, places and tears down its models.
61
+ - Code that moves a `positionFrom: 'record'` world model outside its present `update` is warned once and listed in `describe().scene.conflicts`.
62
+ - Rule R33 (`npm run check`) flags the static half: startup calls that create things saved whole, and code writing `world.view()` models.
63
+ - Cost: a release build pays two table writes per `engine.add` (about 2 µs per add in `tests/specs/things.mjs`); dev builds also take a short stack
64
+ for `at`, at most 2000 per session (`describe().scene.atCapped` after that).
65
+
66
+ ## 6. One id, everything: explain() and the three kinds of change
67
+ ```js
68
+ engine.thing('chest-home').explain(); // CLI: npx threedog thing chest-home (MCP: thing); the same JSON
69
+ // { id, kind, owner, definition: { at: 'content/props.js:14', template, templateAt, level?, node?, spawned? }, model, materials: [{ role, name, from, keys }],
70
+ // state, rules: { blocksMovement, pickable, interact, height }, ops: [{ op, desc, args }], saved: { tier, keeps, loses }, change: {…}, overrides? }
71
+ ```
72
+ `ops` lists the ops whose definition names this id, kind or template in the optional `targets` field (`engine.ops.define('chest.toggle', { targets: 'chest', … })`;
73
+ `'*'` = any thing, which `thing.set` / `thing.remove` use). `definition.at` is null in release builds and for code run without a file (page `eval`).
74
+ `thing.explain()` (type `ThingExplanation`) is not `engine.explain({ op | quest | … })`: that one takes a question and answers `{ ok, text }` about why an op or quest cannot run now (recipe 23); this one takes no question and returns the facts about one id. `rules.blocksMovement` is the template's / prop's `collide` shape; the engine does not model blocking sight. Pick the kind of change first:
75
+
76
+ | Kind | How | Lasts |
77
+ |---|---|---|
78
+ | Game state (a chest opens, a door moves) | an op: `ops.run('chest.toggle', { id })`, `thing.set`, `thing.remove` (section 3) | by the thing's save tier |
79
+ | Permanent edit (another model, place, material role) | content entry: `npx threedog content set <id> <field> <json>` (below); template or `engine.add` line: edit the file:line `explain().change.permanent` prints; then reload | forever |
80
+ | Diagnostic override ("show me without it") | `engine.debug.override(owner, id, { visible: false, material: 'flat' \| 'wire', apply })` | until `handle.remove()` / `engine.debug.clear(owner)`; never saved |
81
+
82
+ ```js
83
+ const h = engine.debug.override('ai-session', 'windmill', { material: 'flat' }); // unlit base colour: is the colour wrong, or the light?
84
+ engine.debug.override('ai-session', 'fence', { visible: false });
85
+ engine.describe().scene.overrides; // [{ owner, target, material: 'flat' }, …]: the screen differs from the real state while this is non-empty
86
+ h.remove(); engine.debug.clear('ai-session'); // clear removes every override of that owner (and its debug.view) and nothing else
87
+ ```
88
+ `apply(obj)` may return its undo function: any other look (a view mode) uses the same owner mechanism. Overrides do not touch game state, ops or saves.
89
+
90
+ `npx threedog content set cabin x=12 z=3 place=home --in props` sets several fields in one call (one write, one check, all or nothing; a bare word is a string). `npx threedog content set cabin x 12 --in props` writes a permanent change into the content entry (`-w game` or `--dir folder` picks the game; `--dry` only shows it). It edits just that
91
+ value in place (comments and spacing stay), adds the field when missing, runs the content check (reverting if it fails) and tells you to reload. Fields are the content file's names
92
+ (`x`, `z`, `y`, `rot`, `scale`, `template`, `place`, `model`), not the record's `position`; the value is JSON (`'"home"'` for a string). It refuses, and says why, for an entry built
93
+ by code (loop, spread, computed value) or an id matching several entries (`--in props`). A placed entry wins over a template or npc of the same name.
@@ -0,0 +1,64 @@
1
+ # Terrain outline: islands, floating rocks, a world that ends
2
+
3
+ `terrain({ shape })` decides where there is ground at all. Without it the ground goes on forever, exactly as before. With it, ground exists only
4
+ where `mask > 0`; the rim is cut through the cells in straight lines, walls hang down from it, and an optional underside closes it.
5
+
6
+ ## 1. A floating island with a ragged rim (copy this)
7
+
8
+ ```js
9
+ import { createEngine, openWorld } from 'threedog';
10
+
11
+ const engine = createEngine({ canvas: document.querySelector('canvas') });
12
+ engine.use(openWorld({ camera: 'follow', water: false, terrain: { // water: false -- a floating island has no sea under it
13
+ height: (x, z, n) => 4 + 6 * n.fbm(x * 0.02, z * 0.02),
14
+ shape: {
15
+ mask: (x, z) => 60 - Math.hypot(x, z), // > 0 ground: a 60 m disc (meters read best)
16
+ edge: { noise: 8, size: 20, jitter: 0.6, round: 1.5 }, // ragged outline, jagged rim, top bends down 1.5 m at the edge
17
+ side: { depth: 3, ground: 'cliff' }, // 3 m of cliff band, colored by biomeColors.cliff
18
+ bottom: { depth: (x, z, n, m) => 2 + m * 0.5 + 4 * n.fbm(x * 0.1, z * 0.1), ground: 'rock' }, // hangs lower inland (m grows inward)
19
+ },
20
+ } }));
21
+ await engine.start();
22
+
23
+ const home = { x: 0, z: 0 };
24
+ engine.events.on('terrain:void', ({ who }) => { // fell off: the game decides (the engine never respawns)
25
+ if (who === engine.player) engine.player.placeAt(home);
26
+ });
27
+ ```
28
+
29
+ Colors come from the style pack as usual: add `cliff` and `rock` to `style.terrain.biomeColors` (a name without a color is neutral gray).
30
+
31
+ ## 2. The keys
32
+
33
+ | key | what | default |
34
+ |---|---|---|
35
+ | `mask` | `(x, z, n) => number`, > 0 is ground; pure like `height` (runs in workers, settings through `n.params`). Or a gray image `{ url, size: [w, l], center, threshold }`: whiter is ground, value = gray − threshold, outside the image is void | required |
36
+ | `edge.noise` / `edge.size` | meters of fbm added to the mask, and its wavelength in meters | 0 / 16 |
37
+ | `edge.jitter` | meters of random offset per grid point: a jagged, chipped rim | 0 |
38
+ | `edge.round` | meters the top bends down towards the rim; 0 is a hard cliff edge | 0 |
39
+ | `side.depth` | wall height below the rim: meters or `(x, z, n) => meters` | 2 |
40
+ | `side.ground` / `side.material` | wall color (`biomeColors[ground]`), or a Material / `(engine) => Material` for sides and bottom | `'cliff'` / none |
41
+ | `bottom.depth` | underside below the side band: meters or `(x, z, n, m) => meters` (`m` = mask there) | 4 (only with `bottom`) |
42
+ | `bottom.ground` | underside color | `'rock'` |
43
+ | `voidY` | fall height for `terrain:void` | 50 m under the lowest island chunk loaded |
44
+
45
+ Without `bottom` the island is open underneath (the cheapest choice when the camera never looks up at it).
46
+
47
+ ## 3. What the rest of the engine does off the outline
48
+
49
+ - `engine.surface(x, z)` is `-Infinity`, `engine.ground.has(x, z)` is `false`, `engine.slope` is 0, `engine.groundType` is `'void'`.
50
+ Check `has` before placing things: `engine.snapToGround` over the void throws in development instead of writing an infinite y.
51
+ The same holds for every place-it-here entry (`engine.spawn`, content props, pickups, npcs, `character.placeAt`): in development they throw with this advice, in a release build they keep the caller's y (or 0), never `-Infinity` (a save would turn it into NaN). Camera starts, HUD anchors, grid tiles and shot paths fall back to y 0 / the last height and do not throw.
52
+ - Characters walk off the rim and fall; pathfinding and spawn search treat the void as not walkable.
53
+ - Physics: the top and the walls collide (a rolling barrel stops at a wall, a ball falls off the edge); the underside does not.
54
+ - Vegetation never grows off the outline. `engine.terrain.edit` off it does nothing (returns `{ heights: 0, cells: 0 }`); near the rim it
55
+ still digs, and painting works. The outline itself cannot be edited.
56
+ - The player and every moving rigid body that drops below `engine.terrain.voidY` get one `terrain:void { who, position }` per fall.
57
+ - Global water still draws at its level: a floating island usually turns water off (`water: false` above).
58
+
59
+ ## 4. Limits
60
+
61
+ - The cut follows cell edges, so detail finer than a cell (`chunkSize / resolution`, 4 m by default) is lost. Keep `edge.size` above a cell,
62
+ or raise `resolution`.
63
+ - `shading: 'texture'`: the color map covers the top only (void pixels have alpha 0); sides and bottom use vertex colors or `side.material`.
64
+ - The mask is fixed at start; a game that wants the outline to change while playing builds that itself.
@@ -0,0 +1,120 @@
1
+ # Writing shader patches and surface looks
2
+
3
+ The default surface is flat: `lambert` plus vertex colors. This page is the three exits for changing that, from simplest to most open:
4
+ **1. parameters** in the material spec (nothing changes until you write them), **2. a named patch or GLSL snippet** you write, **3. your own
5
+ material** (a function or instance). Use the first that does the job.
6
+
7
+ ## Material roles are open
8
+ `style.materials` maps a role name to a material. The engine asks for `default terrain vegetation character water pickup prop`; **any other
9
+ name is fine** (`wool`, `bark`, `lantern`): code asks for it with `engine.makeMaterial('wool', { color })`, an unlisted role uses `materials.default`.
10
+ Only a name very close to an existing one (`props`, `charcter`) warns, as a probable typo.
11
+
12
+ ```js
13
+ materials: {
14
+ default: { type: 'lambert' },
15
+ wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 3, normal: 0.01 } },
16
+ rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 4 },
17
+ prop: (params, purpose, engine) => new THREE.MeshMatcapMaterial({ matcap: texture, color: params.color }), // any Material
18
+ }
19
+ ```
20
+ A **function** gets `(params, purpose, engine)`: the call's `params` (color, vertexColors...), the role asked for, and the engine; it returns any
21
+ three.js Material. A **spec** is plain data (`type: lambert | phong | standard | physical | toon | basic` plus material properties), layered over
22
+ `materials.default` when that is a spec too; keys the material has are set, spec keys below are handled by the engine.
23
+
24
+ ## Exit 1: parameters in the spec
25
+ **Texture names.** A texture slot may be an asset name (`map`, `emissiveMap` are sRGB; `normalMap roughnessMap metalnessMap aoMap bumpMap alphaMap
26
+ displacementMap specularMap...` are linear). The engine loads it with `engine.assets.texture`, sets anisotropy, wrap and `repeat` (a number or `[x, y]`;
27
+ `wrap: 'repeat' | 'clamp' | 'mirror'`), and a neutral stand-in (flat normal, white) sits in the slot until the image arrives. A texture object works too.
28
+ A key the type lacks (`roughnessMap` on `lambert`) warns once with the type to use; a misspelled slot (`normalmap`) throws with the near name.
29
+ `style check` verifies the names against the asset pack (`materials.*.map` and the other slots, `materials.*.detail.texture`).
30
+
31
+ **`detail`**: grain, paper or strokes over the surface, in world space (needs no UVs). Off unless written; every number is a uniform, so
32
+ 100 materials with different `scale` / `strength` / `direction` compile **one** program (tested: 8 variants, +0 programs).
33
+
34
+ | key | meaning |
35
+ |---|---|
36
+ | `noise` | `'grain'` (default) `'paper'` `'stroke'`; or `texture: 'name'` (asset name or a Texture), or `glsl` (below) |
37
+ | `projection` | `'world'` top-down (default, fine for ground) or `'triplanar'` (walls, rocks, characters) |
38
+ | `scale` `strength` | repeats per meter (0.25), color effect 0-1 (0.35) |
39
+ | `mode` `tint` | `'multiply'` (default) `'add'` `'mix'`; tint colors the sample |
40
+ | `direction` `stretch` | degrees; stretch along it (strokes default 6): a brush stroke is `{ noise: 'stroke', direction: 20 }` |
41
+ | `octaves` | 1-4 noise layers (2) |
42
+ | `normal` | relief height in meters (bumps the normal; 0 = off) |
43
+ | `roughness` | amount the sample moves roughness (`standard` / `physical`) |
44
+
45
+ Which channels (color, normal, roughness) are on is fixed when the material is made (it is part of the program); the numbers can change any time.
46
+ `style.terrain.detail` (`{ texture, scale, strength }`) is the same patch for the ground.
47
+
48
+ **`lighting`** shapes the light after it is summed. three has no "shadow color": a shadow only removes the sun's light. The patch reads the first
49
+ directional light (the sun; three sorts shadow casters first) and its shadow value for the pixel:
50
+
51
+ | key | effect |
52
+ |---|---|
53
+ | `shadowTint: { color, strength, soft }` | shadowed or sun-averted parts shift hue towards `color`, same brightness. `soft` = terminator width |
54
+ | `rim: { color, strength, power, shadowSide }` | fresnel edge light added to the ambient part; `shadowSide: 1` = only away from the sun (a cool back light) |
55
+ | `wrap` | half-lambert: `(n.l + wrap) / (1 + wrap)` from the sun |
56
+
57
+ Limits: one directional light; point and spot lights are untouched; cloud shadows do not count as shadow for `shadowTint`; `wrap` does not follow a toon
58
+ ramp. Put it on every lit material of the pack with `style.lighting` (same keys; a material's own `lighting` wins, `lighting: false` opts out).
59
+ **Toon** takes `ramp: [0.3, 0.65, 1]` (grays = light strength per band) or colors (a cool band in the shade), `soften: 0..1` melts the bands; `steps` still works.
60
+
61
+ **Seasons**: `style.seasons: { mode: 'mix', strength: 0.5, autumn: { foliage: 0xd98a3a } }`. `multiply` (default) multiplies the color on, which turns
62
+ orange-on-green muddy; `mix` moves the surface `strength` of the way to the color.
63
+
64
+ ## Exit 2: your own GLSL
65
+ `detail.glsl` replaces the noise: `vec4 threedogDetailSample(vec2 p)` returns `vec4(color, height 0-1)`; `p` is already scaled, turned, stretched;
66
+ `uniforms: { uCells: 6 }` (numbers, colors, arrays, textures) are in scope. `lighting.glsl` replaces the three light effects:
67
+ `void threedogLighting(inout ReflectedLight light, vec3 normal, vec3 viewDir, vec3 sunDir, float sunShadow, vec3 albedo)` (view space; `sunShadow` 1 lit,
68
+ 0 shadowed; change `light.directDiffuse` / `indirectDiffuse`, the lights are already summed).
69
+
70
+ For anything else write a **named patch** and add it with `applyEffects(material, { patches: [...] })` (or in a `materials` function):
71
+ ```js
72
+ { name: 'fuzz', // one name per effect; the same name again replaces it
73
+ cacheKey: 'v1', // changes whenever the GLSL text changes, never for uniform values
74
+ uniforms: { uFuzz: { value: 0.3 } }, // numbers live here, so materials with different values share a program
75
+ needs: { patches: ['world'], data: ['vertexColors'] }, // 'world' gives `varying vec3 vThreedogWorld`; data = program inputs you read
76
+ conflicts: ['wind'], // patches it cannot share a material with (checked when added)
77
+ shadow: false, // true = the patch MOVES vertices, so its vertex code also runs in the shadow passes (wind does)
78
+ glsl: { fragment: { pars: 'uniform float uFuzz;', // pars = declarations at the top
79
+ color_fragment: 'diffuseColor.rgb *= 1.0 - uFuzz * 0.5;' } } } // chunk name -> code placed after `#include <chunk>`
80
+ ```
81
+ A chunk value may be `{ before, after }`. A missing chunk throws when the patch is added (`strict`), not as a silent no-op. Chunk names in three **0.187**
82
+ (read from `three/src/renderers/shaders`), in main-body order:
83
+
84
+ | stage | chunk | what is in scope after it |
85
+ |---|---|---|
86
+ | vertex | `begin_vertex` | `transformed` (object space; wind moves it here) |
87
+ | vertex | `project_vertex` | `mvPosition`, `gl_Position` |
88
+ | vertex | `worldpos_vertex` | `worldPosition` (only when shadows, env maps or transmission need it) |
89
+ | fragment | `map_fragment` `color_fragment` | `diffuseColor` (rgb after the map, then the vertex colors) |
90
+ | fragment | `roughnessmap_fragment` `metalnessmap_fragment` | `roughnessFactor`, `metalnessFactor` (standard / physical) |
91
+ | fragment | `normal_fragment_begin` `normal_fragment_maps` | `normal` (view space), `faceDirection`; `vViewPosition` = minus the view-space position |
92
+ | fragment | `emissivemap_fragment` | `totalEmissiveRadiance` |
93
+ | fragment | `lights_fragment_begin` ... `lights_fragment_end` | `reflectedLight.directDiffuse / indirectDiffuse / directSpecular / indirectSpecular`; after `_end` they are final |
94
+ | fragment | `opaque_fragment` | `outgoingLight` and `gl_FragColor`; (called `output_fragment` before r154) |
95
+
96
+ `MeshBasicMaterial` has no lights, so no `lights_*` chunks; `lambert` has no roughness chunks. `vThreedogWorld` is the world position (instancing and
97
+ batching included). Meshes with several patches stack them in the order added, in one program per distinct combination.
98
+
99
+ ## Exit 3: your own material
100
+ A `materials` entry that is a Material instance (cloned per use, its patches kept) or a function returning one; `style.lighting` still shapes plain three.js
101
+ lit materials returned by it. Nothing else is applied: textures, `detail` and `lighting` keys are only read on specs, so call `applyEffects(material,
102
+ { detail, patches })` yourself.
103
+
104
+ ## Three complete looks
105
+ ```js
106
+ const looks = {
107
+ // wool: rough, fuzzy, soft light, a warm rim; one fine grain seen from every side
108
+ wool: { type: 'standard', roughness: 1, detail: { noise: 'grain', projection: 'triplanar', scale: 4, octaves: 3, strength: 0.25, normal: 0.01 },
109
+ lighting: { wrap: 0.5, rim: { color: 0xffd9a8, strength: 0.35, power: 2.5 } } },
110
+ // leaves: toon bands, brush strokes along the wind, cool shade, a bit of transmitted light on the side away from the sun
111
+ leaf: { type: 'toon', ramp: [0.45, 0.8, 1], soften: 0.25, detail: { noise: 'stroke', direction: 35, scale: 1.2, strength: 0.3, mode: 'add' },
112
+ lighting: { shadowTint: { color: 0x5a6fb0, strength: 0.7 }, rim: { color: 0xb8e08a, strength: 0.3, shadowSide: 1 } } },
113
+ // rock: a real texture set, plus a world-space grain that also roughens it
114
+ rock: { type: 'standard', map: 'rock.png', normalMap: 'rock_n.png', roughnessMap: 'rock_r.png', repeat: 3,
115
+ detail: { noise: 'paper', projection: 'triplanar', scale: 0.8, strength: 0.2, normal: 0.02, roughness: 0.3 } },
116
+ };
117
+ ```
118
+ Fetch them with `engine.makeMaterial('wool')`. Check a pack with `threedog style check`; the pixel and program-count guarantees are in `tests/specs/surface.mjs`.
119
+
120
+ To change these from code at run time (`materials`, `surface`, `ground`, `wind` look parts), see recipe 52.