threedog 0.5.0 → 0.7.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 (511) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +21 -13
  3. package/core/Assets.js +23 -12
  4. package/core/Audio.js +1 -1
  5. package/core/Baked.js +14 -23
  6. package/core/Budget.js +2 -2
  7. package/core/DebugOverrides.js +33 -18
  8. package/core/Describe.js +10 -11
  9. package/core/Engine.js +50 -46
  10. package/core/I18n.js +2 -2
  11. package/core/Input.js +11 -5
  12. package/core/Inspect.js +6 -3
  13. package/core/InspectMaterials.js +2 -3
  14. package/core/InspectPerf.js +11 -4
  15. package/core/MaterialInfo.js +7 -5
  16. package/core/Rays.js +7 -2
  17. package/core/Stream.js +2 -3
  18. package/core/UrlState.js +49 -9
  19. package/core/Views.js +1 -0
  20. package/core/adaptive.js +2 -2
  21. package/core/assetEntry.js +5 -2
  22. package/core/assetLoad.js +13 -15
  23. package/core/assetManifest.js +6 -3
  24. package/core/assetReport.js +4 -4
  25. package/core/batchGroups.js +9 -1
  26. package/core/catalog.js +16 -3
  27. package/core/chunkStream.js +1 -1
  28. package/core/copies.js +1 -1
  29. package/core/debugView.js +4 -4
  30. package/core/describeRender.js +104 -28
  31. package/core/describeText.js +6 -6
  32. package/core/errorCodes.js +72 -45
  33. package/core/errorHints.js +4 -1
  34. package/core/errors.js +4 -4
  35. package/core/events.generated.js +1 -0
  36. package/core/gameLights.js +9 -2
  37. package/core/lifecycle.js +2 -4
  38. package/core/lightWatch.js +5 -3
  39. package/core/loop.js +18 -11
  40. package/core/math.js +7 -0
  41. package/core/moduleSlots.js +32 -7
  42. package/core/moduleTypes.js +20 -7
  43. package/core/modules.js +7 -7
  44. package/core/namedModel.js +8 -4
  45. package/core/owned.js +33 -30
  46. package/core/page.js +43 -10
  47. package/core/pictureSlots.js +33 -0
  48. package/core/pictureWriters.js +343 -0
  49. package/core/plugins.js +64 -96
  50. package/core/sceneDelta.js +12 -4
  51. package/core/sceneMethods.js +2 -9
  52. package/core/services.js +1 -1
  53. package/core/shadowTypes.js +1 -1
  54. package/core/shadows.js +405 -0
  55. package/core/sharedPoint.js +5 -19
  56. package/core/stackFrames.js +16 -5
  57. package/core/stacks.js +6 -6
  58. package/core/startup.js +9 -11
  59. package/core/thingExplain.js +1 -1
  60. package/core/things.js +1 -1
  61. package/core/tier.js +1 -1
  62. package/core/util.js +1 -1
  63. package/core/validate.js +1 -1
  64. package/core/view.js +43 -0
  65. package/docs/AI.md +62 -58
  66. package/docs/API.md +15 -15
  67. package/docs/CODEMAP.md +36 -54
  68. package/docs/COMMANDS.md +28 -25
  69. package/docs/CONVENTIONS.md +36 -30
  70. package/docs/MIGRATING-0.4.md +93 -1
  71. package/docs/MIGRATING-0.6.md +126 -0
  72. package/docs/MIGRATING-0.7.md +39 -0
  73. package/docs/THREE.md +24 -22
  74. package/docs/api/assets.md +5 -3
  75. package/docs/api/audio.md +2 -2
  76. package/docs/api/budget.md +4 -0
  77. package/docs/api/characters.md +3 -1
  78. package/docs/api/collision.md +2 -2
  79. package/docs/api/engine.md +47 -20
  80. package/docs/api/events.md +2 -1
  81. package/docs/api/grids.md +8 -1
  82. package/docs/api/ground.md +1 -1
  83. package/docs/api/hud.md +3 -0
  84. package/docs/api/input.md +3 -2
  85. package/docs/api/interactions.md +3 -1
  86. package/docs/api/inventory.md +1 -2
  87. package/docs/api/level.md +0 -1
  88. package/docs/api/lightPool.md +1 -1
  89. package/docs/api/occlusion.md +5 -0
  90. package/docs/api/particles.md +6 -3
  91. package/docs/api/pickups.md +6 -0
  92. package/docs/api/post.md +5 -3
  93. package/docs/api/sky.md +12 -10
  94. package/docs/api/terrain.md +12 -6
  95. package/docs/api/terrainDraw.md +12 -0
  96. package/docs/api/tools.md +8 -7
  97. package/docs/api/triggers.md +2 -0
  98. package/docs/api/vegetation.md +7 -2
  99. package/docs/api/vegetationDraw.md +10 -0
  100. package/docs/api/water.md +6 -2
  101. package/docs/api/weather.md +5 -0
  102. package/docs/api/weatherDraw.md +10 -0
  103. package/docs/api/world.md +1 -1
  104. package/docs/recipes/01-new-game.md +19 -23
  105. package/docs/recipes/03-items-pickups.md +25 -4
  106. package/docs/recipes/05-props-bake.md +53 -37
  107. package/docs/recipes/06-clock-events.md +3 -3
  108. package/docs/recipes/07-flow-scenes-pause.md +12 -3
  109. package/docs/recipes/08-weather-sky.md +45 -57
  110. package/docs/recipes/09-materials-lights-models.md +185 -0
  111. package/docs/recipes/10-blender-level.md +2 -2
  112. package/docs/recipes/11-vehicles.md +3 -3
  113. package/docs/recipes/13-animation.md +13 -7
  114. package/docs/recipes/14-custom-module.md +7 -5
  115. package/docs/recipes/15-perf.md +3 -3
  116. package/docs/recipes/16-dev-bridge.md +22 -12
  117. package/docs/recipes/18-world.md +10 -8
  118. package/docs/recipes/19-shooting-picking.md +7 -5
  119. package/docs/recipes/20-content-actions-save.md +6 -2
  120. package/docs/recipes/21-camera.md +8 -3
  121. package/docs/recipes/23-ops.md +1 -1
  122. package/docs/recipes/26-ui-parts.md +35 -11
  123. package/docs/recipes/28-terrain.md +12 -12
  124. package/docs/recipes/29-grid.md +14 -5
  125. package/docs/recipes/30-templates.md +8 -3
  126. package/docs/recipes/31-audio.md +4 -4
  127. package/docs/recipes/32-action-game.md +18 -4
  128. package/docs/recipes/34-environment-lighting.md +102 -38
  129. package/docs/recipes/35-picture-from-reference.md +147 -0
  130. package/docs/recipes/36-sky-ground-plants.md +158 -0
  131. package/docs/recipes/{37-terrain-look-hooks.md → 37-terrain-hooks.md} +9 -13
  132. package/docs/recipes/38-environment-hooks.md +67 -0
  133. package/docs/recipes/40-scene.md +106 -27
  134. package/docs/recipes/42-terrain-shape.md +1 -1
  135. package/docs/recipes/{43-shader-patches-surface-looks.md → 43-shader-patches-surfaces.md} +66 -77
  136. package/docs/recipes/44-water-weather-hooks.md +191 -0
  137. package/docs/recipes/45-cascaded-shadows.md +121 -23
  138. package/docs/recipes/46-blender-art-route.md +17 -20
  139. package/docs/recipes/47-island-snow-backdrop.md +10 -12
  140. package/docs/recipes/49-game-module-contract.md +1 -1
  141. package/docs/recipes/50-own-renderer.md +3 -3
  142. package/docs/recipes/52-around-the-picture.md +181 -0
  143. package/docs/recipes/53-ground-up-close.md +12 -12
  144. package/docs/recipes/54-three-idioms.md +18 -18
  145. package/docs/recipes/55-mods-time-wrap.md +17 -5
  146. package/docs/recipes/56-webgpu-tsl.md +66 -23
  147. package/docs/recipes/57-control.md +39 -0
  148. package/docs/recipes/58-input.md +3 -0
  149. package/docs/recipes/59-depth-post-effects.md +5 -5
  150. package/docs/recipes/60-judge-the-picture.md +39 -24
  151. package/docs/recipes/61-deploy.md +27 -0
  152. package/docs/recipes/62-picture-code.md +244 -0
  153. package/docs/recipes/63-third-person-start.md +77 -0
  154. package/docs/recipes/64-particles.md +35 -0
  155. package/examples/action/.threedog/content-index.json +1 -1
  156. package/examples/action/GAMEMAP.md +7 -5
  157. package/examples/action/main.js +5 -4
  158. package/examples/action/models.js +12 -14
  159. package/examples/action/picture/index.js +13 -0
  160. package/examples/action/picture/lights.js +35 -0
  161. package/examples/action/picture/materials.js +8 -0
  162. package/examples/action/picture/palette.js +33 -0
  163. package/examples/plain-picture/.threedog/content-index.json +1 -0
  164. package/examples/plain-picture/FINDINGS.md +53 -0
  165. package/examples/plain-picture/GAMEMAP.md +90 -0
  166. package/examples/plain-picture/main.js +48 -0
  167. package/examples/plain-picture/picture/index.js +21 -0
  168. package/examples/plain-picture/picture/lights.js +54 -0
  169. package/examples/plain-picture/picture/materials.js +24 -0
  170. package/examples/plain-picture/picture/palette.js +16 -0
  171. package/examples/plain-picture/picture/sky.js +37 -0
  172. package/examples/pullable.json +31 -9
  173. package/examples/rc2d/GAMEMAP.md +8 -3
  174. package/examples/rc2d/README.md +11 -6
  175. package/examples/rc2d/main.js +25 -33
  176. package/examples/rc2d/picture/index.js +18 -0
  177. package/examples/rc2d/picture/lights.js +11 -0
  178. package/examples/rc2d/picture/materials.js +18 -0
  179. package/examples/rc2d/picture/palette.js +15 -0
  180. package/examples/rc2d/picture/post.js +11 -0
  181. package/examples/rc2d/rc2d.js +18 -28
  182. package/examples/sheepisland/.threedog/content-index.json +1 -1
  183. package/examples/sheepisland/GAMEMAP.md +13 -10
  184. package/examples/sheepisland/assets.js +2 -2
  185. package/examples/sheepisland/content/templates.js +1 -1
  186. package/examples/sheepisland/content/vegetation.js +3 -1
  187. package/examples/sheepisland/main.js +15 -9
  188. package/examples/sheepisland/{style/models.js → models.js} +13 -24
  189. package/examples/sheepisland/picture/index.js +20 -0
  190. package/examples/sheepisland/picture/lights.js +34 -0
  191. package/examples/sheepisland/picture/materials.js +61 -0
  192. package/examples/sheepisland/picture/palette.js +60 -0
  193. package/examples/sheepisland/picture/sky.js +20 -0
  194. package/examples/sheepisland/views.js +1 -1
  195. package/examples/styletest/.threedog/content-index.json +1 -1
  196. package/examples/styletest/GAMEMAP.md +15 -11
  197. package/examples/styletest/main.js +20 -30
  198. package/examples/styletest/models.js +29 -29
  199. package/examples/styletest/params.js +1 -4
  200. package/examples/styletest/picture/env.js +38 -0
  201. package/examples/styletest/picture/index.js +16 -0
  202. package/examples/styletest/picture/lights.js +9 -0
  203. package/examples/styletest/picture/materials.js +28 -0
  204. package/examples/styletest/picture/palette.js +22 -0
  205. package/examples/techniques/contact-shadows/README.md +22 -23
  206. package/examples/techniques/contact-shadows/contactShadows.js +32 -16
  207. package/examples/techniques/contact-shadows/main.js +20 -18
  208. package/examples/techniques/contact-shadows/picture/index.js +14 -0
  209. package/examples/techniques/contact-shadows/picture/lights.js +34 -0
  210. package/examples/techniques/contact-shadows/picture/materials.js +12 -0
  211. package/examples/techniques/contact-shadows/picture/palette.js +17 -0
  212. package/examples/techniques/day-night-grade/README.md +13 -16
  213. package/examples/techniques/day-night-grade/main.js +15 -25
  214. package/examples/techniques/day-night-grade/picture/index.js +20 -0
  215. package/examples/techniques/day-night-grade/picture/lights.js +45 -0
  216. package/examples/techniques/day-night-grade/picture/materials.js +15 -0
  217. package/examples/techniques/day-night-grade/picture/palette.js +59 -0
  218. package/examples/techniques/day-night-grade/picture/post.js +25 -0
  219. package/examples/techniques/day-night-grade/picture/sky.js +33 -0
  220. package/examples/techniques/interior-light/README.md +16 -13
  221. package/examples/techniques/interior-light/interiorLight.js +19 -17
  222. package/examples/techniques/interior-light/main.js +30 -67
  223. package/examples/techniques/interior-light/picture/index.js +24 -0
  224. package/examples/techniques/interior-light/picture/lights.js +52 -0
  225. package/examples/techniques/interior-light/picture/materials.js +13 -0
  226. package/examples/techniques/interior-light/picture/palette.js +32 -0
  227. package/examples/techniques/interior-light/picture/sky.js +40 -0
  228. package/examples/techniques/modular-building/README.md +4 -3
  229. package/examples/techniques/modular-building/kit.js +2 -2
  230. package/examples/techniques/modular-building/main.js +9 -17
  231. package/examples/techniques/modular-building/picture/index.js +17 -0
  232. package/examples/techniques/modular-building/picture/lights.js +26 -0
  233. package/examples/techniques/modular-building/picture/materials.js +13 -0
  234. package/examples/techniques/modular-building/picture/palette.js +23 -0
  235. package/examples/techniques/night-lights/README.md +15 -14
  236. package/examples/techniques/night-lights/main.js +20 -43
  237. package/examples/techniques/night-lights/nightLights.js +25 -21
  238. package/examples/techniques/night-lights/picture/index.js +18 -0
  239. package/examples/techniques/night-lights/picture/lights.js +44 -0
  240. package/examples/techniques/night-lights/picture/materials.js +15 -0
  241. package/examples/techniques/night-lights/picture/palette.js +34 -0
  242. package/examples/techniques/night-lights/picture/post.js +9 -0
  243. package/examples/techniques/night-lights/picture/sky.js +36 -0
  244. package/examples/techniques/outlines-and-rim/README.md +2 -2
  245. package/examples/techniques/outlines-and-rim/main.js +15 -38
  246. package/examples/techniques/outlines-and-rim/outlines.js +3 -3
  247. package/examples/techniques/outlines-and-rim/picture/index.js +16 -0
  248. package/examples/techniques/outlines-and-rim/picture/lights.js +18 -0
  249. package/examples/techniques/outlines-and-rim/picture/materials.js +11 -0
  250. package/examples/techniques/outlines-and-rim/picture/palette.js +16 -0
  251. package/examples/techniques/outlines-and-rim/picture/post.js +10 -0
  252. package/examples/techniques/procedural-animation/README.md +5 -3
  253. package/examples/techniques/procedural-animation/main.js +9 -7
  254. package/examples/techniques/procedural-animation/picture/index.js +15 -0
  255. package/examples/techniques/procedural-animation/picture/lights.js +35 -0
  256. package/examples/techniques/procedural-animation/picture/materials.js +10 -0
  257. package/examples/techniques/procedural-animation/picture/palette.js +16 -0
  258. package/examples/techniques/procedural-animation/picture/sky.js +31 -0
  259. package/examples/techniques/procedural-animation/proceduralAnim.js +1 -1
  260. package/examples/techniques/procedural-surface/README.md +2 -0
  261. package/examples/techniques/procedural-surface/main.js +17 -55
  262. package/examples/techniques/procedural-surface/picture/index.js +14 -0
  263. package/examples/techniques/procedural-surface/picture/lights.js +18 -0
  264. package/examples/techniques/procedural-surface/picture/materials.js +34 -0
  265. package/examples/techniques/procedural-surface/picture/palette.js +15 -0
  266. package/examples/techniques/stylized-shading/README.md +13 -14
  267. package/examples/techniques/stylized-shading/main.js +11 -42
  268. package/examples/techniques/stylized-shading/picture/index.js +14 -0
  269. package/examples/techniques/stylized-shading/picture/lights.js +23 -0
  270. package/examples/techniques/stylized-shading/picture/materials.js +18 -0
  271. package/examples/techniques/stylized-shading/picture/palette.js +19 -0
  272. package/examples/techniques/stylized-shading/shading.js +2 -2
  273. package/examples/techniques/sun-and-key-light/README.md +20 -22
  274. package/examples/techniques/sun-and-key-light/keyLight.js +47 -29
  275. package/examples/techniques/sun-and-key-light/main.js +19 -63
  276. package/examples/techniques/sun-and-key-light/picture/index.js +13 -0
  277. package/examples/techniques/sun-and-key-light/picture/lights.js +33 -0
  278. package/examples/techniques/sun-and-key-light/picture/materials.js +9 -0
  279. package/examples/techniques/sun-and-key-light/picture/palette.js +29 -0
  280. package/examples/techniques/sun-and-key-light/picture/sky.js +16 -0
  281. package/examples/techniques/three-looks/README.md +21 -0
  282. package/examples/techniques/three-looks/main.js +58 -0
  283. package/examples/techniques/three-looks/picture/cartoon.js +23 -0
  284. package/examples/techniques/three-looks/picture/cinematic.js +27 -0
  285. package/examples/techniques/three-looks/picture/comic.js +27 -0
  286. package/examples/techniques/three-looks/picture/index.js +14 -0
  287. package/examples/techniques/three-looks/picture/sun.js +23 -0
  288. package/examples/techniques/wet-road/README.md +7 -4
  289. package/examples/techniques/wet-road/main.js +18 -38
  290. package/examples/techniques/wet-road/picture/index.js +17 -0
  291. package/examples/techniques/wet-road/picture/lights.js +57 -0
  292. package/examples/techniques/wet-road/picture/materials.js +16 -0
  293. package/examples/techniques/wet-road/picture/palette.js +24 -0
  294. package/examples/techniques/wet-road/picture/sky.js +46 -0
  295. package/examples/webgpu-tsl/GAMEMAP.md +9 -4
  296. package/examples/webgpu-tsl/README.md +13 -10
  297. package/examples/webgpu-tsl/main.js +30 -7
  298. package/examples/webgpu-tsl/picture/index.js +18 -0
  299. package/examples/webgpu-tsl/picture/lights.js +25 -0
  300. package/examples/webgpu-tsl/picture/materials.js +36 -0
  301. package/examples/webgpu-tsl/picture/palette.js +23 -0
  302. package/examples/webgpu-tsl/picture/post.js +16 -0
  303. package/examples/webgpu-tsl/picture/sky.js +30 -0
  304. package/examples/world/.threedog/content-index.json +1 -1
  305. package/examples/world/GAMEMAP.md +15 -12
  306. package/examples/world/art/humanoid.js +9 -13
  307. package/examples/world/art/index.js +2 -2
  308. package/examples/world/art/models.js +3 -4
  309. package/examples/world/art/shapes.js +2 -2
  310. package/examples/world/assets.js +2 -2
  311. package/examples/world/content/audio.js +1 -1
  312. package/examples/world/content/items.js +1 -1
  313. package/examples/world/content/props.js +1 -1
  314. package/examples/world/content/templates.js +1 -1
  315. package/examples/world/content/vegetation.js +1 -1
  316. package/examples/world/main.js +10 -10
  317. package/examples/world/models.js +17 -7
  318. package/examples/world/picture/index.js +20 -0
  319. package/examples/world/picture/lights.js +41 -0
  320. package/examples/world/picture/materials.js +34 -0
  321. package/examples/world/picture/palette.js +74 -0
  322. package/examples/world/picture/post.js +9 -0
  323. package/examples/world/picture/sky.js +39 -0
  324. package/index.d.ts +7 -16
  325. package/index.js +7 -7
  326. package/llms.txt +15 -13
  327. package/modules/ambience/Ambience.js +1 -1
  328. package/modules/calendar/Calendar.js +1 -1
  329. package/modules/calendar/index.js +1 -0
  330. package/modules/camera/FirstPersonCamera.js +1 -1
  331. package/modules/camera/FixedCamera.js +2 -2
  332. package/modules/camera/RtsCamera.js +1 -1
  333. package/modules/camera/common.js +7 -5
  334. package/modules/characters/Character.js +15 -10
  335. package/modules/characters/NPC.js +5 -5
  336. package/modules/characters/assetModel.js +5 -4
  337. package/modules/characters/index.js +28 -3
  338. package/modules/characters/movers/common.js +6 -1
  339. package/modules/characters/movers/manual.js +3 -0
  340. package/modules/characters/movers/support.js +25 -11
  341. package/modules/characters/npcSim.js +5 -1
  342. package/modules/characters/proceduralRig.js +18 -4
  343. package/modules/characters/useModel.js +2 -2
  344. package/modules/collision/Collision.js +4 -2
  345. package/modules/content/index.js +8 -0
  346. package/modules/content/models.js +56 -11
  347. package/modules/content/props.js +5 -3
  348. package/modules/content/rules.js +12 -4
  349. package/modules/content/templates.js +5 -3
  350. package/modules/gameplay/Interactions.js +91 -16
  351. package/modules/gameplay/Inventory.js +3 -3
  352. package/modules/gameplay/dialogueBox.js +1 -1
  353. package/modules/gameplay/dialogueBubbles.js +1 -1
  354. package/modules/gameplay/interactionPrompt.js +1 -1
  355. package/modules/gameplay/interactions.contract.js +1 -1
  356. package/modules/gameplay/inventoryOps.js +2 -2
  357. package/modules/gameplay/pickups.js +62 -24
  358. package/modules/gameplay/questLog.js +2 -2
  359. package/modules/grid/Layer.js +13 -0
  360. package/modules/grid/index.js +40 -11
  361. package/modules/grid/preview.js +24 -15
  362. package/modules/grid/tiles.js +15 -19
  363. package/modules/hlod/index.js +3 -2
  364. package/modules/hud/index.js +13 -0
  365. package/modules/hud/parts.js +9 -7
  366. package/modules/level/index.js +5 -4
  367. package/modules/lights/index.js +12 -8
  368. package/modules/music/Music.js +1 -1
  369. package/modules/particles/Particles.js +41 -20
  370. package/modules/particles/effect.js +21 -6
  371. package/modules/photo/Photo.js +11 -10
  372. package/modules/settings/Settings.js +7 -7
  373. package/modules/settings/apply.js +5 -5
  374. package/modules/settings/sections.js +2 -2
  375. package/modules/settings/strings.js +1 -1
  376. package/modules/sky/Sky.js +104 -89
  377. package/modules/sky/clouds.js +16 -17
  378. package/modules/sky/dome.js +100 -0
  379. package/modules/sky/domeLayers.js +5 -5
  380. package/modules/sky/environment.js +45 -169
  381. package/modules/sky/fog.js +5 -180
  382. package/modules/sky/frame.js +26 -90
  383. package/modules/sky/season.js +3 -3
  384. package/modules/sky/shader.js +35 -29
  385. package/modules/sky/skyModule.js +25 -22
  386. package/modules/sky/tint.js +9 -11
  387. package/modules/terrain/ChunkManager.js +29 -12
  388. package/modules/terrain/draw.js +154 -0
  389. package/modules/terrain/index.js +44 -66
  390. package/modules/terrain/terrainDefaults.js +2 -2
  391. package/modules/terrain/terrainEdit.js +1 -1
  392. package/modules/terrain/terrainGen.js +2 -2
  393. package/modules/triggers/index.js +10 -6
  394. package/modules/vegetation/Vegetation.js +58 -17
  395. package/modules/vegetation/draw.js +191 -0
  396. package/modules/vegetation/groundChunks.js +1 -1
  397. package/modules/vegetation/index.js +10 -10
  398. package/modules/water/Water.js +135 -88
  399. package/modules/water/surface.js +53 -53
  400. package/modules/weather/Weather.js +52 -17
  401. package/modules/weather/particles.js +13 -5
  402. package/modules/weather/shaders.js +1 -1
  403. package/modules/weather/weatherDraw.js +141 -0
  404. package/modules/world/World.js +2 -2
  405. package/modules/world/views.js +1 -1
  406. package/package.json +3 -2
  407. package/presets.js +2 -2
  408. package/render/PostFX.js +199 -41
  409. package/render/backend.js +52 -6
  410. package/render/cascades.js +195 -0
  411. package/render/cascades.tsl.js +96 -0
  412. package/render/daylight.js +39 -0
  413. package/render/detail.js +5 -5
  414. package/render/effects.js +41 -26
  415. package/render/fx/cel.tsl.js +42 -0
  416. package/render/fx/index.js +7 -5
  417. package/render/fx/patchNodes.tsl.js +1 -1
  418. package/render/fx/postWebGPU.tsl.js +30 -7
  419. package/render/fx/sky.tsl.js +19 -92
  420. package/render/fx/water.tsl.js +1 -1
  421. package/render/layers.js +14 -0
  422. package/render/lighting.js +6 -5
  423. package/render/lightmap.js +142 -0
  424. package/render/lights.js +23 -201
  425. package/render/materials.js +44 -160
  426. package/render/neutral.js +23 -0
  427. package/render/occlusion.js +184 -0
  428. package/render/ownFrame.js +1 -1
  429. package/render/patches.js +34 -29
  430. package/render/postWebGL.js +11 -3
  431. package/render/probes.js +179 -122
  432. package/render/slots.js +4 -4
  433. package/render/terms.js +53 -101
  434. package/render/uniformDecl.js +1 -1
  435. package/types/core.d.ts +333 -296
  436. package/types/gameplay.d.ts +65 -26
  437. package/types/generated/core/Audio.d.ts +1 -1
  438. package/types/generated/core/DebugOverrides.d.ts +14 -6
  439. package/types/generated/core/Input.d.ts +9 -2
  440. package/types/generated/core/page.d.ts +9 -2
  441. package/types/generated/modules/grid/Layer.d.ts +8 -0
  442. package/types/generated/modules/grid/index.d.ts +29 -5
  443. package/types/generated/modules/particles/Particles.d.ts +13 -6
  444. package/types/generated/modules/sky/Sky.d.ts +85 -18
  445. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  446. package/types/generated/modules/water/Water.d.ts +50 -3
  447. package/types/generated/modules/weather/Weather.d.ts +33 -3
  448. package/types/generated/modules/weather/weatherDraw.d.ts +11 -0
  449. package/types/generated/modules/world/World.d.ts +2 -2
  450. package/types/generated/render/PostFX.d.ts +53 -10
  451. package/types/generated/render/lighting.d.ts +29 -0
  452. package/types/generated/render/materials.d.ts +19 -44
  453. package/types/generated/render/occlusion.d.ts +13 -0
  454. package/types/physics.d.ts +5 -3
  455. package/types/tsl.d.ts +8 -0
  456. package/types/world.d.ts +376 -57
  457. package/ui/Focus.js +12 -2
  458. package/ui/LoadingScreen.js +2 -2
  459. package/ui/Parts.js +8 -4
  460. package/ui/UI.js +10 -10
  461. package/ui/cursor.js +1 -1
  462. package/ui/theme.js +33 -27
  463. package/ui/touchPart.js +1 -1
  464. package/core/look/coreParts.js +0 -219
  465. package/core/look/part.js +0 -253
  466. package/core/look/points.js +0 -255
  467. package/core/look/report.js +0 -96
  468. package/core/look/shadowPart.js +0 -63
  469. package/core/look/state.js +0 -45
  470. package/core/look/write.js +0 -70
  471. package/core/styleParts.js +0 -114
  472. package/docs/api/style.md +0 -136
  473. package/docs/api/terrainLook.md +0 -10
  474. package/docs/api/vegetationLook.md +0 -10
  475. package/docs/api/weatherLook.md +0 -10
  476. package/docs/recipes/09-style.md +0 -218
  477. package/docs/recipes/35-style-from-reference.md +0 -153
  478. package/docs/recipes/36-sky-ground-plant-looks.md +0 -118
  479. package/docs/recipes/38-environment-look-hooks.md +0 -99
  480. package/docs/recipes/41-thing-registry.md +0 -97
  481. package/docs/recipes/44-water-weather-look-hooks.md +0 -144
  482. package/docs/recipes/48-make-material.md +0 -75
  483. package/docs/recipes/52-look.md +0 -282
  484. package/examples/action/look.js +0 -5
  485. package/examples/sheepisland/style/index.js +0 -79
  486. package/examples/styletest/look.js +0 -11
  487. package/examples/techniques/day-night-grade/dayNightGrade.js +0 -76
  488. package/examples/webgpu-tsl/tslScene.js +0 -75
  489. package/examples/world/style/index.js +0 -61
  490. package/examples/world/style/plugins/10-bloom.js +0 -5
  491. package/modules/sky/cascades.js +0 -186
  492. package/modules/sky/cascades.tsl.js +0 -82
  493. package/modules/sky/look.js +0 -54
  494. package/modules/sky/lookFog.js +0 -76
  495. package/modules/sky/lookShadow.js +0 -62
  496. package/modules/sky/lookSky.js +0 -169
  497. package/modules/sky/shadow.js +0 -98
  498. package/modules/terrain/look.js +0 -83
  499. package/modules/terrain/lookGround.js +0 -66
  500. package/modules/vegetation/look.js +0 -119
  501. package/modules/vegetation/lookWind.js +0 -98
  502. package/modules/water/look.js +0 -91
  503. package/modules/water/surfaceDefaults.js +0 -3
  504. package/modules/weather/look.js +0 -74
  505. package/modules/weather/weatherLook.js +0 -135
  506. package/render/lookGlow.js +0 -139
  507. package/render/lookSurface.js +0 -224
  508. package/render/postLook.js +0 -164
  509. package/render/surface.js +0 -105
  510. package/types/generated/modules/weather/weatherLook.d.ts +0 -12
  511. package/types/style.d.ts +0 -671
@@ -38,12 +38,12 @@ How to judge it: a shot at the real camera, with the busiest background the game
38
38
  - **Selection highlight**: a colored hull or `OutlinePass` on the selected object only.
39
39
 
40
40
  ## The engine helper (optional convenience)
41
- Copy `outlines.js` into a game; `main.js` is only the demo. It gives `trackResolution(engine)` (the drawing-buffer size for screen-unit hulls),
41
+ Copy `outlines.js` into a game; `main.js` (shapes) and `picture/` (this page's whole picture, plain three.js: lights, materials by name, the post pass) are only the demo. It gives `trackResolution(engine)` (the drawing-buffer size for screen-unit hulls),
42
42
  `addHull(mesh, { thickness, units: 'world' | 'screen', color })`, and `rimPatch({ color, strength, power, shadowSide })`.
43
43
 
44
44
  | route | how | width | cost |
45
45
  |---|---|---|---|
46
- | post outline | `@threedog/post-effects` `outline()` via `engine.look.post.add(...)`: one full-screen pass that draws where depth jumps (`mode: 'normal'` / `'both'` also creases) | screen pixels | one full-screen pass reading depth, any number of objects; `'normal'` adds a scene render; `offLayer` adds a render of the exempt objects |
46
+ | post outline | `@threedog/post-effects` `outline()` through `engine.post.add(...)` (see `picture/post.js`): one full-screen pass that draws where depth jumps (`mode: 'normal'` / `'both'` also creases) | screen pixels | one full-screen pass reading depth, any number of objects; `'normal'` adds a scene render; `offLayer` adds a render of the exempt objects |
47
47
  | inverted hull | `addHull(mesh, { units })`: a back-face copy pushed out along smooth normals, unlit, keeps fog | `'world'`: meters, thins with distance; `'screen'`: pixels, constant | one more draw (and its vertices) per outlined mesh; no full-screen cost |
48
48
  | rim light | `rimPatch()`: a fresnel edge light added in the material's lighting (engine `threedogRim`) | follows the form | a few ALU per pixel, no extra draw |
49
49
 
@@ -2,55 +2,32 @@
2
2
  // Outlines and rim demo (page /technique-outlines.html): gray objects in front of a gray wall on gray ground, values deliberately close,
3
3
  // so the silhouette is the problem. Five columns: nothing, post outline, inverted hull in world units, inverted hull in screen pixels,
4
4
  // rim light. A second capsule far behind each column shows the difference between world and screen line widths.
5
- // The post outline runs for the whole frame; every object of the other columns is on OUTLINE_OFF_LAYER so it gets no lines.
6
- // Test page for tests/specs/technique-looks.mjs: window.techTest = { THREE, columns }.
5
+ // The post outline runs for the whole frame; every object of the other columns is on the off layer so it gets no lines.
6
+ // Shapes only here; the whole picture is picture/. Test page for tests/specs/technique-pictures.mjs: window.techTest = { THREE, columns, picture }.
7
7
  import { createEngine, fixedCamera, THREE } from 'threedog';
8
- import { outline, OUTLINE_OFF_LAYER } from '@threedog/post-effects';
9
- import { addHull, rimPatch, trackResolution } from './outlines.js';
10
- import { applyEffects } from 'threedog';
8
+ import { addHull, trackResolution } from './outlines.js';
9
+ import { createPicture } from './picture/index.js';
11
10
 
12
- // ---------- parameters: change these first ----------
13
- const PARAMS = {
14
- sun: [40, 38, 16], sunIntensity: 3.2, hemi: 0.35, // sun offset from its target (direction only); key / fill strengths: the fill sets how dark shade gets
15
- line: 0x24242c, // one line color for every route, so only the method differs
16
- post: { thickness: 1.5, strength: 0.9 },
17
- hullWorld: 0.035, // meters
18
- hullScreen: 2.5, // device pixels
19
- rim: { color: 0xe4ecff, strength: 1.2, power: 2.5, shadowSide: 0.5 },
20
- colors: { object: 0xb3b0aa, wall: 0xa9a7a2, ground: 0xa4a29d, roof: 0x9a958e },
21
- };
22
-
23
- const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-technique-outlines' });
24
- const sky = new THREE.Color(0xa3acb6);
25
- engine.scene.background = sky;
26
- engine.scene.fog = new THREE.Fog(sky, 30, 90);
27
- // no sky drives the sun here, so its position is a plain write (with a sky: look.lights.manual('sun.direction') first). From the right, lower than the default, so every model shows a lit side, a turn and a shaded side
28
- engine.lights.sun.position.copy(engine.lights.sun.target.position).add(new THREE.Vector3(...PARAMS.sun));
29
- engine.lights.sun.intensity = PARAMS.sunIntensity; // plain three.js writes: with no sky nothing else drives these
30
- engine.lights.hemi.intensity = PARAMS.hemi;
11
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-technique-outlines' });
31
12
  engine.use(fixedCamera({ shots: { main: { position: [0, 4.2, 13], lookAt: [0, 1.0, -1], fov: 45 } }, start: 'main' }));
32
- engine.look.post.add(outline({ enabled: true, color: PARAMS.line, ...PARAMS.post, offLayer: OUTLINE_OFF_LAYER }));
13
+ const picture = createPicture(engine), { mat } = picture;
33
14
  trackResolution(engine);
34
15
 
35
- const lit = (/** @type {number} */ color, rim = false) => {
36
- const m = new THREE.MeshLambertMaterial({ color });
37
- return rim ? applyEffects(m, { patches: [rimPatch(PARAMS.rim)] }) : m;
38
- };
39
16
  const geo = { body: new THREE.CapsuleGeometry(0.32, 1.1, 8, 24), ball: new THREE.SphereGeometry(0.42, 40, 20), house: new THREE.BoxGeometry(1.8, 1.6, 1.6) };
40
17
  /** @type {Record<string, (mesh: THREE.Mesh) => void>} */
41
18
  const routes = {
42
19
  none: () => {},
43
20
  'post outline': () => {},
44
- 'hull, world units': mesh => { addHull(mesh, { thickness: PARAMS.hullWorld, units: 'world', color: PARAMS.line }); },
45
- 'hull, screen px': mesh => { addHull(mesh, { thickness: PARAMS.hullScreen, units: 'screen', color: PARAMS.line }); },
21
+ 'hull, world units': mesh => { addHull(mesh, picture.hull.world); },
22
+ 'hull, screen px': mesh => { addHull(mesh, picture.hull.screen); },
46
23
  'rim light': () => {},
47
24
  };
48
- const off = (/** @type {THREE.Object3D} */ o) => o.traverse(c => c.layers.enable(OUTLINE_OFF_LAYER)); // no post lines on this one
25
+ const off = (/** @type {THREE.Object3D} */ o) => o.traverse(c => c.layers.enable(picture.offLayer)); // no post lines on this one
49
26
  const names = Object.keys(routes), columns = [];
50
27
  names.forEach((name, i) => {
51
28
  const x = (i - 2) * 3.2, rim = name === 'rim light';
52
- const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {number[]} */ at, color = PARAMS.colors.object) => {
53
- const m = new THREE.Mesh(g, lit(color, rim));
29
+ const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {number[]} */ at, material = rim ? mat.rimObject : mat.object) => {
30
+ const m = new THREE.Mesh(g, material);
54
31
  m.position.set(at[0], at[1], at[2]); m.castShadow = m.receiveShadow = true;
55
32
  engine.scene.add(m);
56
33
  routes[name](m);
@@ -59,13 +36,13 @@ names.forEach((name, i) => {
59
36
  };
60
37
  const body = add(geo.body, [x - 0.5, 0.87, 1.2]);
61
38
  add(geo.ball, [x + 0.6, 0.42, 1.4]);
62
- add(geo.house, [x, 0.8, -1.4], PARAMS.colors.roof);
39
+ add(geo.house, [x, 0.8, -1.4], rim ? mat.rimRoof : mat.roof);
63
40
  const far = add(geo.body, [x + 0.3, 0.87, -7.5]);
64
41
  columns.push({ name, x, body: { at: body.position.toArray(), radius: 0.32 }, far: { at: far.position.toArray(), radius: 0.32 } });
65
42
  });
66
- const wall = new THREE.Mesh(new THREE.BoxGeometry(40, 5, 0.4), lit(PARAMS.colors.wall));
43
+ const wall = new THREE.Mesh(new THREE.BoxGeometry(40, 5, 0.4), mat.wall);
67
44
  wall.position.set(0, 2.5, -9.5); wall.receiveShadow = true;
68
- const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), lit(PARAMS.colors.ground));
45
+ const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), mat.ground);
69
46
  ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
70
47
  // wall and ground stay ON the outline layer: the pass skips any pixel next to an off object, so an off ground would also erase the
71
48
  // post column's lines where its objects meet the ground. The cost: the post outline also draws the wall's foot and top, as it would in a game
@@ -80,5 +57,5 @@ if (labels) {
80
57
  }));
81
58
  }
82
59
 
83
- Object.assign(window, { engine, techTest: { THREE, columns } });
60
+ Object.assign(window, { engine, techTest: { THREE, columns, picture } });
84
61
  engine.start();
@@ -1,6 +1,6 @@
1
1
  // @ts-check
2
2
  // Outlines and rim light: three ways to make a silhouette read against a background of the same value.
3
- // post outline -> @threedog/post-effects outline() (one full-screen pass on the depth buffer; nothing here, see main.js)
3
+ // post outline -> @threedog/post-effects outline() (one full-screen pass on the depth buffer; nothing here, see picture/post.js)
4
4
  // inverted hull -> addHull(): a slightly larger back-face copy of the mesh drawn in the line color, per object
5
5
  // rim light -> rimPatch(): an edge light added in the material's own lighting, no extra draw at all
6
6
  // Copy this file into a game; it imports only three and threedog.
@@ -45,8 +45,8 @@ export function addHull(mesh, { thickness = 0.03, units = 'world', color = 0x1e1
45
45
  }
46
46
 
47
47
  /**
48
- * Rim light as a patch on any lit material: a fresnel edge light added to the ambient part (engine GLSL threedogRim, recipe 43; the same
49
- * math as the style `lighting.rim` key). `shadowSide` 1 = only on the side turned away from the sun, a back light that separates the
48
+ * Rim light as a patch on any lit material: a fresnel edge light added to the ambient part (engine GLSL threedogRim, recipe 43).
49
+ * `shadowSide` 1 = only on the side turned away from the sun, a back light that separates the
50
50
  * shaded side from a dark background; 0 = all round.
51
51
  * @param {{ color?: THREE.ColorRepresentation, strength?: number, power?: number, shadowSide?: number }} [o]
52
52
  */
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+ // The picture of the outlines demo: wiring only. Nothing here moves, so there is no onRender; a picture with signals would call each part from one.
3
+ import { THREE } from 'threedog';
4
+ import { COLORS, FOG, HULL, TONE_MAPPING } from './palette.js';
5
+ import { createLights } from './lights.js';
6
+ import { createMaterials } from './materials.js';
7
+ import { createPost } from './post.js';
8
+
9
+ /** Returns { mat, hull, offLayer, sun, hemi } @param {any} engine */
10
+ export function createPicture(engine) {
11
+ engine.renderer.toneMapping = TONE_MAPPING;
12
+ engine.scene.background = new THREE.Color(COLORS.sky);
13
+ engine.scene.fog = new THREE.Fog(COLORS.sky, FOG.near, FOG.far);
14
+ const { sun, hemi } = createLights(engine), { offLayer } = createPost(engine);
15
+ return { mat: createMaterials(), hull: HULL, offLayer, sun, hemi };
16
+ }
@@ -0,0 +1,18 @@
1
+ // @ts-check
2
+ // One sun and one ambient, fixed: the scene never changes, so the page has no signals to read. The ambient's ground color is light on purpose: with no
3
+ // room map, it is what keeps the walls near the ground's value.
4
+ import { THREE } from 'threedog';
5
+ import { COLORS, LIGHT } from './palette.js';
6
+
7
+ /** @param {any} engine */
8
+ export function createLights(engine) {
9
+ const hemi = new THREE.HemisphereLight(0xffffff, COLORS.shade, LIGHT.ambient);
10
+ const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
11
+ sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
12
+ sun.castShadow = true;
13
+ sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
14
+ Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
15
+ sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; sun.shadow.radius = 3; // the box covers the row of columns with a little margin
16
+ engine.scene.add(hemi, sun, sun.target);
17
+ return { sun, hemi };
18
+ }
@@ -0,0 +1,11 @@
1
+ // @ts-check
2
+ // Materials by name. The rim column has its own two: same colors, plus the edge light the column shows.
3
+ import { THREE, applyEffects } from 'threedog';
4
+ import { rimPatch } from '../outlines.js';
5
+ import { COLORS, RIM } from './palette.js';
6
+
7
+ export function createMaterials() {
8
+ const lit = (/** @type {number} */ color) => new THREE.MeshLambertMaterial({ color });
9
+ const rim = (/** @type {number} */ color) => applyEffects(lit(color), { patches: [rimPatch(RIM)] });
10
+ return { object: lit(COLORS.object), roof: lit(COLORS.roof), wall: lit(COLORS.wall), ground: lit(COLORS.ground), rimObject: rim(COLORS.object), rimRoof: rim(COLORS.roof) };
11
+ }
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+ // Outlines demo palette: the colors and key values of this page. Values sit close on purpose, so the silhouette is the problem the routes solve.
3
+ import { THREE } from 'threedog';
4
+
5
+ export const COLORS = { object: 0xb3b0aa, wall: 0xa9a7a2, ground: 0xa4a29d, roof: 0x9a958e, sky: 0xa3acb6, shade: 0xe6e6e6 };
6
+ /** One line color for every route, so only the method differs */
7
+ export const LINE = 0x24242c;
8
+ export const OUTLINE = { thickness: 1.5, strength: 0.9 };
9
+ /** thickness: meters for 'world', device pixels for 'screen' */
10
+ export const HULL = { world: { thickness: 0.035, units: /** @type {'world'} */ ('world'), color: LINE }, screen: { thickness: 2.5, units: /** @type {'screen'} */ ('screen'), color: LINE } };
11
+ export const RIM = { color: 0xe4ecff, strength: 1.2, power: 2.5, shadowSide: 0.5 };
12
+ /** sun: offset from its target (direction only), high enough that the turned side of a capsule stays a mid-tone; ambient sets how dark shade gets, and it is all the fill there is */
13
+ export const LIGHT = { sun: [40, 80, 30], sunIntensity: 3.2, ambient: 2.2 };
14
+ export const FOG = { near: 30, far: 90 };
15
+ // a soft curve keeps object, wall and ground close in value, which is the problem this page is about
16
+ export const TONE_MAPPING = THREE.AgXToneMapping;
@@ -0,0 +1,10 @@
1
+ // @ts-check
2
+ // The post route: one full-screen outline for the whole frame. Objects on OUTLINE_OFF_LAYER get no lines; the other columns use it.
3
+ import { outline, OUTLINE_OFF_LAYER } from '@threedog/post-effects';
4
+ import { LINE, OUTLINE } from './palette.js';
5
+
6
+ /** @param {any} engine */
7
+ export function createPost(engine) {
8
+ engine.post.add(outline({ enabled: true, color: LINE, ...OUTLINE, offLayer: OUTLINE_OFF_LAYER }), { name: 'outline', slot: 'hdr' });
9
+ return { offLayer: OUTLINE_OFF_LAYER };
10
+ }
@@ -3,7 +3,7 @@ Animate code-built characters and props without a skeleton: walk cycles from spe
3
3
  # Procedural animation (technique example)
4
4
 
5
5
  A neutral box quadruped that walks, trots, jumps, lands and sits. Run `npm run dev` and open `/procanim.html` (WASD, Shift runs, Space jumps,
6
- stand still 4 s to sit; `?walk=2` walks by itself). The engine never imports this folder.
6
+ stand still 4 s to sit; `?walk=2` walks by itself). The picture is plain three.js in `picture/`. The engine never imports this folder.
7
7
 
8
8
  ## The principle
9
9
  Motion reads as alive when it is tied to cause: feet keep up with the ground, soft parts lag behind the body, weight shows on landing, and
@@ -47,7 +47,7 @@ do ears and tail settle without jitter? Values are a starting point to tune by e
47
47
  `threedog examples pull procedural-animation` copies the folder. `proceduralAnim.js` is the technique and imports nothing:
48
48
  `createProceduralAnimator(parts, knobs)` returns an animator with `update(dt, { speed, state, grounded, vy })`; `spring(stiffness, damping)`
49
49
  is the sub-stepped spring (a long frame stays stable). `creature.js` (`buildCreature`, imports `three`) is a neutral box quadruped that exists
50
- only so there is something to move; `main.js` wires it to a player, in a game change main's import to `from 'threedog'`.
50
+ only so there is something to move; `main.js` wires it to a player.
51
51
  1. Build the body with a pivot (a `Group`) at every joint. Names do not matter to the animator, only the `parts` object you pass.
52
52
  2. Give it to a character as a ready rig: `createPlayer({ ..., rig: { root, body: parts.body, limbs: [] } })` (`npcs.add` takes the same
53
53
  `rig`). `limbs: []` means the engine swings nothing itself (recipe 13 section 3b describes its own limb swing, for comparison).
@@ -61,7 +61,7 @@ starting point for a mid-sized box creature: cycle `stride`, `strideGrow`; gait
61
61
  idle `breathe`, `breatheRate`; springs `earStiffness`, `earDamping`, `tailStiffness`, ...; landing `squash`, `squashMax`.
62
62
 
63
63
  Rules (correctness):
64
- - **Looks run per frame, gameplay per fixed step.** `update` belongs in `onPose` / `onFrame` with that frame's `dt`. It reads facts the fixed
64
+ - **Visuals run per frame, gameplay per fixed step.** `update` belongs in `onPose` / `onFrame` with that frame's `dt`. It reads facts the fixed
65
65
  steps wrote (`moveAmount`, `state`, `grounded`, `vy`) and writes only the body's own parts. Never read a pose for gameplay (hit timing,
66
66
  footstep damage): frames drop and fast-forward runs frame hooks at a lower rate (`engine.step`).
67
67
  - **Write absolute values from a remembered rest pose**, never `+=` per frame. `rest.bodyY` is read once; every frame sets
@@ -75,3 +75,5 @@ speed, they return to rest at idle, the body returns to its rest height, the cha
75
75
  Sources: written for this example; no code copied. Background: distance-driven gait cycles, springs for secondary motion and squash and
76
76
  stretch are common practice (David Rosen, "An Indie Approach to Procedural Animation", GDC 2014; the squash-and-stretch principle from
77
77
  Thomas and Johnston, *The Illusion of Life*, 1981).
78
+
79
+ This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). A game on the default WebGPU route writes the same ideas in TSL (recipe 56).
@@ -1,19 +1,21 @@
1
1
  // @ts-check
2
2
  // Procedural animation demo (page /procanim.html): the player is a code-built four-legged body animated without a skeleton. WASD walks,
3
3
  // Shift runs, Space jumps (landing squashes); stand still for 4 s and the game's own 'sit' state (the character `states` hook) takes over.
4
- // Test page for tests/specs/procedural-animation.mjs: window.procAnimTest = { animator, parts, player }.
5
- import { createEngine, openWorld, followCamera, presets, makeMaterial, THREE } from '../../../index.js';
4
+ // Test page for tests/specs/procedural-animation.mjs: window.procAnimTest = { animator, parts, player }. Shapes and motion only here; the whole picture is picture/.
5
+ import { createEngine, openWorld, followCamera, presets, THREE } from 'threedog';
6
6
  import { buildCreature } from './creature.js';
7
7
  import { createProceduralAnimator } from './proceduralAnim.js';
8
+ import { createPicture } from './picture/index.js';
8
9
 
9
- const engine = createEngine({ bindings: { ...presets.bindings.walk }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-procanim' });
10
+ const engine = createEngine({ bindings: { ...presets.bindings.walk }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-procanim' });
10
11
  engine.use(openWorld({ camera: followCamera({ ...presets.camera.follow, distance: 4 }), terrain: false, vegetation: false, weather: false, water: false, rigid: false,
11
12
  ambience: false, calendar: { ...presets.calendar.fixedTime, time: 0.4 }, characters: { npcs: false } }));
12
- const floor = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), makeMaterial('terrain', { color: 0x7d7d7d }));
13
+ const { mat } = createPicture(engine);
14
+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(60, 60), mat.floor);
13
15
  floor.rotation.x = -Math.PI / 2; floor.receiveShadow = true;
14
16
  engine.scene.add(floor);
15
17
 
16
- const { root, parts } = buildCreature({ material: makeMaterial('prop', { color: 0xa0a0a0 }) });
18
+ const { root, parts } = buildCreature({ material: mat.creature });
17
19
  const RUN_SPEED = 7;
18
20
  // The game's own state: 'sit' after 4 s without moving. The hook runs every fixed step after the mover's state; null keeps the mover's.
19
21
  let stillSince = 0;
@@ -28,8 +30,8 @@ const player = engine.characters.createPlayer({
28
30
  });
29
31
 
30
32
  const animator = createProceduralAnimator(parts, { runSpeed: RUN_SPEED });
31
- // Looks run per frame, right after the engine applied its own pose (onPose): read the facts the fixed steps wrote (speed, state, grounded,
32
- // vy), never write anything gameplay reads. A frame hook is the right clock for looks: it runs once per drawn frame with that frame's dt.
33
+ // Visuals run per frame, right after the engine applied its own pose (onPose): read the facts the fixed steps wrote (speed, state, grounded,
34
+ // vy), never write anything gameplay reads. A frame hook is the right clock for visuals: it runs once per drawn frame with that frame's dt.
33
35
  player.onPose((ch, dt) => {
34
36
  animator.update(dt, { speed: ch.moveAmount, state: ch.state, grounded: ch.grounded, vy: ch.vy });
35
37
  if (ch.state === 'sit') { // a state the engine does not know: the game decides its pose, on top of the animator's rest pose
@@ -0,0 +1,15 @@
1
+ // @ts-check
2
+ // The picture of the procedural-animation demo: wiring only.
3
+ import { TONE_MAPPING } from './palette.js';
4
+ import { createLights } from './lights.js';
5
+ import { createMaterials } from './materials.js';
6
+ import { createSky } from './sky.js';
7
+
8
+ /** Returns { mat }. @param {any} engine */
9
+ export function createPicture(engine) {
10
+ engine.renderer.toneMapping = TONE_MAPPING;
11
+ const lights = createLights(engine), sky = createSky(engine), { mat } = createMaterials();
12
+ // onRender, not onFrame: onFrame runs before the sky module, so it would read last frame's signals
13
+ engine.onRender(() => { lights.update(engine.uniforms); sky.update(engine.uniforms); });
14
+ return { mat };
15
+ }
@@ -0,0 +1,35 @@
1
+ // @ts-check
2
+ // One sun and one ambient that follow the time of day.
3
+ import { THREE } from 'threedog';
4
+ import { LIGHT, SHADOW } from './palette.js';
5
+
6
+ /** @param {any} engine */
7
+ export function createLights(engine) {
8
+ const { ambient, sun: key } = LIGHT, { extent, near, far, bias, normalBias, radius } = SHADOW;
9
+ const hemi = new THREE.HemisphereLight(ambient.dayColor, ambient.dayGround, ambient.day);
10
+ const sun = new THREE.DirectionalLight(key.dayColor, key.day);
11
+ sun.castShadow = true;
12
+ sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
13
+ Object.assign(sun.shadow.camera, { left: -extent, right: extent, top: extent, bottom: -extent, near, far });
14
+ sun.shadow.camera.updateProjectionMatrix();
15
+ Object.assign(sun.shadow, { bias, normalBias, radius });
16
+ engine.scene.add(hemi, sun, sun.target);
17
+
18
+ const dir = new THREE.Vector3(), day = new THREE.Color(), night = new THREE.Color();
19
+ return {
20
+ /** @param {any} s engine.uniforms */
21
+ update(s) {
22
+ const d = s.uSunDir.value, light = s.uDaylight.value;
23
+ // below the horizon the same light is the moon, across the sky from where the sun went
24
+ dir.set(d.y < 0 ? -d.x : d.x, Math.abs(d.y), d.z).normalize();
25
+ // the shadow box rides on the focus: that is where the creature is, wherever it walks
26
+ sun.target.position.copy(engine.focus);
27
+ sun.position.copy(dir).multiplyScalar(60).add(sun.target.position);
28
+ sun.intensity = THREE.MathUtils.lerp(key.night, key.day, light) * Math.min(1, Math.abs(d.y) / 0.08);
29
+ sun.color.copy(night.set(key.nightColor)).lerp(day.set(key.dayColor), light);
30
+ hemi.intensity = THREE.MathUtils.lerp(ambient.night, ambient.day, light);
31
+ hemi.color.copy(night.set(ambient.nightColor)).lerp(day.set(ambient.dayColor), light);
32
+ hemi.groundColor.copy(night.set(ambient.nightGround)).lerp(day.set(ambient.dayGround), light);
33
+ },
34
+ };
35
+ }
@@ -0,0 +1,10 @@
1
+ // @ts-check
2
+ // Materials by name, plain Lambert: matte gray keeps highlights from competing with the motion.
3
+ import { THREE } from 'threedog';
4
+ import { COLORS } from './palette.js';
5
+
6
+ export function createMaterials() {
7
+ const mat = /** @type {Record<keyof typeof COLORS, THREE.MeshLambertMaterial>} */ ({});
8
+ for (const [name, color] of Object.entries(COLORS)) mat[/** @type {keyof typeof COLORS} */ (name)] = new THREE.MeshLambertMaterial({ color });
9
+ return { mat };
10
+ }
@@ -0,0 +1,16 @@
1
+ // @ts-check
2
+ // Palette of the gray floor: neutral on purpose, so motion is the only thing to look at. The numbers for a game come from its own picture.
3
+ import { THREE } from 'threedog';
4
+
5
+ /** Materials by name */
6
+ export const COLORS = { floor: 0x7d7d7d, creature: 0xa0a0a0 };
7
+ /** Sun (the moon at night) and ambient, day and night ends; the time of day blends between them */
8
+ export const LIGHT = {
9
+ sun: { day: 3, night: 0.4, dayColor: 0xffffff, nightColor: 0xa8a8a8 },
10
+ ambient: { day: 1.4, night: 0.35, dayColor: 0xb9b9b9, nightColor: 0x212121, dayGround: 0x4a4a4a, nightGround: 0x3a3a3a },
11
+ };
12
+ /** Only the creature casts and it stays at the focus, so a small box does. The blur keeps the edge soft: a sharp shadow under a boxy body reads as black cut-outs, and it hides the texels moving as the box follows the focus */
13
+ export const SHADOW = { extent: 24, near: 1, far: 120, bias: -0.0002, normalBias: 0.04, radius: 3 };
14
+ /** Sky colors as they appear on screen: the gradient skips the tone curve */
15
+ export const SKY = { dayTop: 0xb5b5b5, dayHorizon: 0xbababa, nightTop: 0x252525, nightHorizon: 0x292929, radius: 400 };
16
+ export const TONE_MAPPING = THREE.AgXToneMapping;
@@ -0,0 +1,31 @@
1
+ // @ts-check
2
+ // A gray gradient sphere in place of the engine's dome. No fog: the floor ends at 30 m, too near for fog to show.
3
+ import { THREE } from 'threedog';
4
+ import { SKY } from './palette.js';
5
+
6
+ /** @param {any} engine */
7
+ export function createSky(engine) {
8
+ const skyMat = new THREE.ShaderMaterial({
9
+ side: THREE.BackSide, depthWrite: false, fog: false,
10
+ uniforms: { uTop: { value: new THREE.Color() }, uHorizon: { value: new THREE.Color() } },
11
+ vertexShader: 'varying vec3 vDir; void main(){ vDir = normalize(position); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
12
+ fragmentShader: `uniform vec3 uTop; uniform vec3 uHorizon; varying vec3 vDir;
13
+ void main(){ gl_FragColor = vec4(mix(uHorizon, uTop, smoothstep(0.0, 0.6, vDir.y)), 1.0);
14
+ #include <colorspace_fragment>
15
+ }`,
16
+ });
17
+ const dome = new THREE.Mesh(new THREE.SphereGeometry(SKY.radius, 32, 16), skyMat);
18
+ dome.renderOrder = -1;
19
+ engine.scene.add(dome);
20
+ engine.sky.dome.visible = false;
21
+ const day = new THREE.Color(), night = new THREE.Color(), { uTop, uHorizon } = skyMat.uniforms;
22
+ return {
23
+ /** @param {any} s engine.uniforms */
24
+ update(s) {
25
+ const light = s.uDaylight.value;
26
+ uTop.value.copy(night.set(SKY.nightTop)).lerp(day.set(SKY.dayTop), light);
27
+ uHorizon.value.copy(night.set(SKY.nightHorizon)).lerp(day.set(SKY.dayHorizon), light);
28
+ dome.position.copy(engine.camera.position); // the camera walks with the creature; the sky must not come closer
29
+ },
30
+ };
31
+ }
@@ -69,7 +69,7 @@ export function createProceduralAnimator(parts, knobs = {}) {
69
69
  return {
70
70
  knobs: K,
71
71
  /**
72
- * Pose for this frame. Call it once per rendered frame (onFrame or character.onPose) with the frame's dt: looks only, never gameplay.
72
+ * Pose for this frame. Call it once per rendered frame (onFrame or character.onPose) with the frame's dt: visuals only, never gameplay.
73
73
  * @param {number} dt frame seconds
74
74
  * @param {{ speed: number, state: string, grounded: boolean, vy?: number }} motion what the character is doing (written by fixed steps)
75
75
  */
@@ -65,3 +65,5 @@ Rules (correctness):
65
65
 
66
66
  Sources: triplanar mapping as commonly described (Ben Golus, "Normal Mapping for a Triplanar Shader", 2017); vertex AO and edge wear as
67
67
  standard game-art practice. Code written for this engine; nothing copied.
68
+
69
+ This example is written in GLSL: it is the WebGL route (`threedog new-game --webgl`). A game on the default WebGPU route writes the same ideas in TSL (recipe 56).
@@ -3,66 +3,29 @@
3
3
  // 1 plain, 2 world-space triplanar noise at a scale picked from the camera, 3 the same noise at a scale tuned up close (it fades away at
4
4
  // this distance: the lesson), 4 stacked: lazily painted brush texture + baked cavity AO + edge wear. In front, crates from one
5
5
  // InstancedMesh: the left half with one color, the right half with per-instance hue / value jitter.
6
- // Test page for tests/specs/technique-looks.mjs: window.techTest = { THREE, walls, crates }.
6
+ // Shapes only here; the whole picture is picture/. Test page for tests/specs/technique-pictures.mjs: window.techTest = { THREE, walls, crates, scales, picture }.
7
7
  import { createEngine, fixedCamera, THREE } from 'threedog';
8
- import { scaleForCamera, worldVariation, brushTexture, cavity, edgeWear, jitterInstances } from './surface.js';
8
+ import { createPicture } from './picture/index.js';
9
9
 
10
- // ---------- parameters: change these first ----------
11
- const PARAMS = {
12
- sun: [30, 40, 26], sunIntensity: 3.2, hemi: 0.35, // sun offset from its target (direction only); key / fill strengths: the fill sets how dark shade gets
13
- camera: { position: [0, 4.5, 15], lookAt: [0, 1.2, 0], fov: 45 }, // the shot the scales are chosen for: use your game's camera here
14
- wall: 0xd6d0c6, roof: 0x8c847d, crate: 0xb7a58f, ground: 0x8f8d88,
15
- noise: { cellPx: 14, strength: 0.4 }, // cells of 14 screen pixels: reads as plaster patches at this distance
16
- closeUpScale: 40, // repeats per meter an artist picks 1 m from the wall; invisible at 15 m
17
- brush: { cellPx: 120, strength: 0.5 }, // one brush tile over ~120 px, so single strokes are ~10 px
18
- cavity: { strength: 0.9 },
19
- wear: { width: 0.1, strength: 0.7 },
20
- jitter: { hue: 0.03, value: 0.12 },
21
- };
22
-
23
- const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-technique-surface' });
24
- const sky = new THREE.Color(0xa3acb6);
25
- engine.scene.background = sky;
26
- engine.scene.fog = new THREE.Fog(sky, 30, 90);
27
- // no sky drives the sun here, so its position is a plain write (with a sky: look.lights.manual('sun.direction') first). From the right, lower than the default, so every model shows a lit side, a turn and a shaded side
28
- engine.lights.sun.position.copy(engine.lights.sun.target.position).add(new THREE.Vector3(...PARAMS.sun));
29
- engine.lights.sun.intensity = PARAMS.sunIntensity; // plain three.js writes: with no sky nothing else drives these
30
- engine.lights.hemi.intensity = PARAMS.hemi;
31
- engine.use(fixedCamera({ shots: { main: /** @type {any} */ (PARAMS.camera) }, start: 'main' }));
32
-
33
- // distance to the walls' fronts and the real drawing-buffer height: the two numbers every scale below comes from
34
- const viewH = engine.renderer.getDrawingBufferSize(new THREE.Vector2()).y || 540;
35
- const dist = Math.hypot(PARAMS.camera.position[1] - 1.1, PARAMS.camera.position[2]);
36
- const noiseScale = scaleForCamera(PARAMS.camera, dist, viewH, PARAMS.noise.cellPx);
37
- const brushScale = scaleForCamera(PARAMS.camera, dist, viewH, PARAMS.brush.cellPx);
10
+ const SHOT = { position: [0, 4.5, 15], lookAt: [0, 1.2, 0], fov: 45 }; // the shot the scales are chosen for: use your game's camera here
11
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), lights: false, ui: { loading: false }, saveKey: 'threedog-technique-surface' });
12
+ engine.use(fixedCamera({ shots: { main: /** @type {any} */ (SHOT) }, start: 'main' }));
13
+ const picture = createPicture(engine, SHOT);
38
14
 
39
15
  const W = 2.8, H = 2.2, D = 2.4;
16
+ // occluders for the baked cavity, in the walls' local space: the ground under them and the roof slab over them
17
+ const occluders = () => [new THREE.PlaneGeometry(12, 12).rotateX(-Math.PI / 2).translate(0, -H / 2, 0), new THREE.BoxGeometry(W + 0.5, 0.25, D + 0.5).translate(0, H / 2 + 0.12, 0)];
40
18
  /** One house: walls (a box with enough segments to carry vertex AO), a roof slab that overhangs */
41
- function house(/** @type {number} */ x, /** @type {(g: THREE.BoxGeometry) => THREE.Material} */ wallMaterial) {
42
- const g = new THREE.BoxGeometry(W, H, D, 14, 11, 12), m = wallMaterial(g);
19
+ function house(/** @type {number} */ x, /** @type {(g: THREE.BoxGeometry, occluders: THREE.BufferGeometry[]) => THREE.Material} */ wallMaterial) {
20
+ const g = new THREE.BoxGeometry(W, H, D, 14, 11, 12), m = wallMaterial(g, occluders());
43
21
  const walls = new THREE.Mesh(g, m);
44
22
  walls.position.set(x, H / 2, -D / 2);
45
- const roof = new THREE.Mesh(new THREE.BoxGeometry(W + 0.5, 0.25, D + 0.5), new THREE.MeshLambertMaterial({ color: PARAMS.roof }));
23
+ const roof = new THREE.Mesh(new THREE.BoxGeometry(W + 0.5, 0.25, D + 0.5), picture.roof);
46
24
  roof.position.set(x, H + 0.12, -D / 2);
47
25
  for (const o of [walls, roof]) { o.castShadow = o.receiveShadow = true; engine.scene.add(o); }
48
26
  return walls;
49
27
  }
50
- const lambert = () => new THREE.MeshLambertMaterial({ color: PARAMS.wall });
51
- const variants = {
52
- plain: () => lambert(),
53
- 'noise, scale from camera': () => worldVariation(lambert(), { scale: noiseScale, strength: PARAMS.noise.strength }),
54
- 'noise, tuned up close': () => worldVariation(lambert(), { scale: PARAMS.closeUpScale, strength: PARAMS.noise.strength }),
55
- 'brush + cavity + wear': (/** @type {THREE.BoxGeometry} */ g) => {
56
- // occluders in the walls' local space: the ground under them and the roof slab over them
57
- const groundG = new THREE.PlaneGeometry(12, 12).rotateX(-Math.PI / 2).translate(0, -H / 2, 0);
58
- const roofG = new THREE.BoxGeometry(W + 0.5, 0.25, D + 0.5).translate(0, H / 2 + 0.12, 0);
59
- cavity(g, { occluders: [groundG, roofG], strength: PARAMS.cavity.strength, radius: 0.9 });
60
- const m = new THREE.MeshLambertMaterial({ color: PARAMS.wall, vertexColors: true });
61
- worldVariation(m, { scale: brushScale, strength: PARAMS.brush.strength, texture: brushTexture() });
62
- return edgeWear(g, m, PARAMS.wear);
63
- },
64
- };
65
- const walls = Object.entries(variants).map(([name, make], i) => {
28
+ const walls = Object.entries(picture.walls).map(([name, make], i) => {
66
29
  const x = (i - 1.5) * 4.1, mesh = house(x, make);
67
30
  // test spots: a grid over the front face (z = 0), inset from the edges; bottom / middle rows for the cavity check
68
31
  const grid = [];
@@ -71,21 +34,20 @@ const walls = Object.entries(variants).map(([name, make], i) => {
71
34
  });
72
35
 
73
36
  // crates: one InstancedMesh, the left half plain, the right half jittered (two meshes so both halves share the geometry and material)
74
- const crateG = new THREE.BoxGeometry(0.6, 0.6, 0.6), crateM = new THREE.MeshLambertMaterial({ color: 0xffffff });
37
+ const crateG = new THREE.BoxGeometry(0.6, 0.6, 0.6);
75
38
  const crates = ['same', 'jitter'].map((kind, k) => {
76
- const im = new THREE.InstancedMesh(crateG, crateM, 8), t = new THREE.Object3D(), spots = [];
39
+ const im = new THREE.InstancedMesh(crateG, picture.crate, 8), t = new THREE.Object3D(), spots = [];
77
40
  for (let i = 0; i < 8; i++) {
78
41
  t.position.set((k ? 0.6 : -7.4) + i * 0.95, 0.3, 3.2); t.rotation.y = (i * 0.37) % 0.5 - 0.25; t.updateMatrix();
79
42
  im.setMatrixAt(i, t.matrix); spots.push([t.position.x, 0.62, 3.2]); // top face center: lit the same way on every crate
80
43
  }
81
- if (k) jitterInstances(im, PARAMS.crate, PARAMS.jitter);
82
- else for (let i = 0; i < 8; i++) im.setColorAt(i, new THREE.Color(PARAMS.crate));
44
+ if (k) picture.crateJitter(im); else picture.crateSame(im);
83
45
  im.castShadow = im.receiveShadow = true;
84
46
  engine.scene.add(im);
85
47
  return { kind, mesh: im, spots };
86
48
  });
87
49
 
88
- const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), new THREE.MeshLambertMaterial({ color: PARAMS.ground }));
50
+ const ground = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), picture.ground);
89
51
  ground.rotation.x = -Math.PI / 2; ground.receiveShadow = true;
90
52
  engine.scene.add(ground);
91
53
 
@@ -99,5 +61,5 @@ if (labels) {
99
61
  }));
100
62
  }
101
63
 
102
- Object.assign(window, { engine, techTest: { THREE, walls, crates, scales: { noise: noiseScale, brush: brushScale, closeUp: PARAMS.closeUpScale, dist, viewH } } });
64
+ Object.assign(window, { engine, techTest: { THREE, walls, crates, scales: picture.scales, picture } });
103
65
  engine.start();
@@ -0,0 +1,14 @@
1
+ // @ts-check
2
+ // The picture of the surface demo: wiring only. Nothing here moves, so there is no onRender; a picture with signals would call each part from one.
3
+ import { THREE } from 'threedog';
4
+ import { COLORS, FOG, TONE_MAPPING } from './palette.js';
5
+ import { createLights } from './lights.js';
6
+ import { createMaterials } from './materials.js';
7
+
8
+ /** Returns { walls, roof, ground, crate, crateSame, crateJitter, scales, sun, hemi } @param {any} engine @param {{ fov: number, position: number[] }} shot */
9
+ export function createPicture(engine, shot) {
10
+ engine.renderer.toneMapping = TONE_MAPPING;
11
+ engine.scene.background = new THREE.Color(COLORS.sky);
12
+ engine.scene.fog = new THREE.Fog(COLORS.sky, FOG.near, FOG.far);
13
+ return { ...createLights(engine), ...createMaterials(engine, shot) };
14
+ }
@@ -0,0 +1,18 @@
1
+ // @ts-check
2
+ // One sun and one ambient, fixed: the scene never changes, so the page has no signals to read.
3
+ import { THREE } from 'threedog';
4
+ import { COLORS, LIGHT } from './palette.js';
5
+
6
+ /** @param {any} engine */
7
+ export function createLights(engine) {
8
+ const hemi = new THREE.HemisphereLight(0xffffff, COLORS.shade, LIGHT.ambient);
9
+ const sun = new THREE.DirectionalLight(0xffffff, LIGHT.sunIntensity);
10
+ sun.position.set(LIGHT.sun[0], LIGHT.sun[1], LIGHT.sun[2]);
11
+ sun.castShadow = true;
12
+ sun.shadow.mapSize.setScalar(engine.tier === 'low' ? 1024 : 2048);
13
+ Object.assign(sun.shadow.camera, { left: -30, right: 30, top: 30, bottom: -30, near: 1, far: 250 });
14
+ sun.shadow.camera.updateProjectionMatrix();
15
+ sun.shadow.bias = -0.0001; sun.shadow.normalBias = 0.03; sun.shadow.radius = 3;
16
+ engine.scene.add(hemi, sun, sun.target);
17
+ return { sun, hemi };
18
+ }
@@ -0,0 +1,34 @@
1
+ // @ts-check
2
+ // Materials by name. The wall variants are the point of the page: every scale comes from the shot and the real drawing-buffer height, never by eye.
3
+ import { THREE } from 'threedog';
4
+ import { scaleForCamera, worldVariation, brushTexture, cavity, edgeWear, jitterInstances } from '../surface.js';
5
+ import { BRUSH, CAVITY, CLOSE_UP_SCALE, COLORS, JITTER, NOISE, WEAR } from './palette.js';
6
+
7
+ /** @param {any} engine @param {{ fov: number, position: number[] }} shot the camera the scales are chosen for */
8
+ export function createMaterials(engine, shot) {
9
+ const viewH = engine.renderer.getDrawingBufferSize(new THREE.Vector2()).y || 540;
10
+ const dist = Math.hypot(shot.position[1] - 1.1, shot.position[2]); // to the walls' fronts
11
+ const noiseScale = scaleForCamera(shot, dist, viewH, NOISE.cellPx), brushScale = scaleForCamera(shot, dist, viewH, BRUSH.cellPx);
12
+ const lambert = () => new THREE.MeshLambertMaterial({ color: COLORS.wall });
13
+ /** @type {Record<string, (g: THREE.BoxGeometry, occluders: THREE.BufferGeometry[]) => THREE.Material>} */
14
+ const walls = {
15
+ plain: () => lambert(),
16
+ 'noise, scale from camera': () => worldVariation(lambert(), { scale: noiseScale, strength: NOISE.strength }),
17
+ 'noise, tuned up close': () => worldVariation(lambert(), { scale: CLOSE_UP_SCALE, strength: NOISE.strength }),
18
+ 'brush + cavity + wear': (g, occluders) => {
19
+ cavity(g, { occluders, ...CAVITY });
20
+ const m = new THREE.MeshLambertMaterial({ color: COLORS.wall, vertexColors: true });
21
+ worldVariation(m, { scale: brushScale, strength: BRUSH.strength, texture: brushTexture() });
22
+ return edgeWear(g, m, WEAR);
23
+ },
24
+ };
25
+ return {
26
+ walls, scales: { noise: noiseScale, brush: brushScale, closeUp: CLOSE_UP_SCALE, dist, viewH },
27
+ roof: new THREE.MeshLambertMaterial({ color: COLORS.roof }), ground: new THREE.MeshLambertMaterial({ color: COLORS.ground }),
28
+ crate: new THREE.MeshLambertMaterial({ color: 0xffffff }), // white: the instance colors are the crates' whole color
29
+ /** @param {THREE.InstancedMesh} im */
30
+ crateSame(im) { for (let i = 0; i < im.count; i++) im.setColorAt(i, new THREE.Color(COLORS.crate)); },
31
+ /** @param {THREE.InstancedMesh} im */
32
+ crateJitter(im) { jitterInstances(im, COLORS.crate, JITTER); },
33
+ };
34
+ }
@@ -0,0 +1,15 @@
1
+ // @ts-check
2
+ // Surface demo palette: the colors and the values each surface tool takes. Sizes are in screen pixels on purpose: the shot decides the scale.
3
+ import { THREE } from 'threedog';
4
+
5
+ export const COLORS = { wall: 0xd6d0c6, roof: 0x8c847d, crate: 0xb7a58f, ground: 0x8f8d88, sky: 0xa3acb6, shade: 0xe6e6e6 };
6
+ export const NOISE = { cellPx: 14, strength: 0.5 }; // cells of 14 screen pixels: reads as plaster patches at this distance
7
+ export const CLOSE_UP_SCALE = 40; // repeats per meter an artist picks 1 m from the wall; invisible at 15 m
8
+ export const BRUSH = { cellPx: 120, strength: 0.5 }; // one brush tile over ~120 px, so single strokes are ~10 px
9
+ export const CAVITY = { strength: 0.9, radius: 0.9 };
10
+ export const WEAR = { width: 0.1, strength: 0.7 };
11
+ export const JITTER = { hue: 0.03, value: 0.12 };
12
+ /** sun: offset from its target (direction only); ambient sets how dark shade gets, and it is all the fill there is */
13
+ export const LIGHT = { sun: [30, 40, 26], sunIntensity: 3.2, ambient: 2 };
14
+ export const FOG = { near: 30, far: 90 };
15
+ export const TONE_MAPPING = THREE.AgXToneMapping;