threedog 0.2.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/README.md +9 -8
  3. package/core/Animator.js +15 -12
  4. package/core/Assets.js +71 -16
  5. package/core/Audio.js +45 -38
  6. package/core/Baked.js +32 -8
  7. package/core/Batching.js +102 -15
  8. package/core/Budget.js +39 -18
  9. package/core/Clock.js +40 -80
  10. package/core/DebugOverrides.js +45 -10
  11. package/core/Describe.js +104 -43
  12. package/core/Engine.js +183 -59
  13. package/core/Events.js +4 -1
  14. package/core/I18n.js +25 -13
  15. package/core/Input.js +168 -79
  16. package/core/Inspect.js +2 -2
  17. package/core/InspectMaterials.js +85 -0
  18. package/core/InspectPerf.js +61 -0
  19. package/core/InspectScene.js +13 -2
  20. package/core/Loading.js +2 -1
  21. package/core/Ops.js +50 -9
  22. package/core/Random.js +9 -2
  23. package/core/Rays.js +5 -5
  24. package/core/SaveStore.js +41 -9
  25. package/core/Saves.js +71 -15
  26. package/core/Stream.js +14 -10
  27. package/core/Threads.js +26 -7
  28. package/core/UrlState.js +25 -9
  29. package/core/Views.js +9 -6
  30. package/core/actor.js +1 -1
  31. package/core/adaptive.js +93 -0
  32. package/core/assetEntry.js +22 -5
  33. package/core/assetHot.js +176 -0
  34. package/core/assetLoad.js +38 -11
  35. package/core/assetManifest.js +48 -9
  36. package/core/assetReport.js +1 -1
  37. package/core/audioRules.js +13 -11
  38. package/core/audioVoice.js +69 -42
  39. package/core/canvasBox.js +1 -2
  40. package/core/catalog.js +5 -2
  41. package/core/cells.js +62 -0
  42. package/core/checks.js +10 -8
  43. package/core/chunkStream.js +87 -0
  44. package/core/control.js +149 -0
  45. package/core/copies.js +32 -0
  46. package/core/dayTime.js +12 -6
  47. package/core/debugView.js +82 -15
  48. package/core/describeRender.js +37 -17
  49. package/core/describeText.js +41 -21
  50. package/core/engineCamera.js +32 -0
  51. package/core/errorCodes.js +438 -19
  52. package/core/errorHints.js +37 -141
  53. package/core/errors.js +31 -8
  54. package/core/events.generated.js +12 -7
  55. package/core/gameLights.js +62 -0
  56. package/core/grayMap.js +20 -0
  57. package/core/grid.js +14 -13
  58. package/core/gridLoad.js +2 -1
  59. package/core/ground.js +6 -4
  60. package/core/headlessLoad.js +55 -0
  61. package/core/holds.js +78 -50
  62. package/core/inputContext.js +11 -7
  63. package/core/inputDefaults.js +24 -21
  64. package/core/inputPad.js +1 -1
  65. package/core/inputPointer.js +1 -1
  66. package/core/inputTouch.js +2 -2
  67. package/core/lifecycle.js +48 -12
  68. package/core/lightWatch.js +6 -4
  69. package/core/look/coreParts.js +137 -30
  70. package/core/look/part.js +175 -95
  71. package/core/look/points.js +255 -0
  72. package/core/look/report.js +34 -17
  73. package/core/look/shadowPart.js +63 -0
  74. package/core/look/state.js +45 -0
  75. package/core/look/write.js +12 -28
  76. package/core/loop.js +100 -41
  77. package/core/math.js +11 -3
  78. package/core/moduleSlots.js +75 -0
  79. package/core/moduleTypes.js +73 -0
  80. package/core/modules.js +145 -27
  81. package/core/movement.js +2 -2
  82. package/core/namedModel.js +70 -0
  83. package/core/opsCheck.js +3 -3
  84. package/core/opsFail.js +15 -6
  85. package/core/opsGuard.js +4 -4
  86. package/core/opsRun.js +4 -3
  87. package/core/owned.js +168 -0
  88. package/core/page.js +2 -1
  89. package/core/params.js +30 -8
  90. package/core/plugins.js +277 -0
  91. package/core/saveApply.js +99 -17
  92. package/core/saveFiles.js +8 -6
  93. package/core/saveValues.js +46 -0
  94. package/core/saveVersions.js +20 -3
  95. package/core/scatter.js +48 -19
  96. package/core/sceneDelta.js +203 -0
  97. package/core/sceneMethods.js +35 -30
  98. package/core/screenToGround.js +1 -1
  99. package/core/services.js +27 -11
  100. package/core/session.js +28 -25
  101. package/core/shaderCost.js +78 -0
  102. package/core/shadowTypes.js +2 -1
  103. package/core/sharedPoint.js +317 -0
  104. package/core/skip.js +36 -28
  105. package/core/stackFrames.js +34 -0
  106. package/core/stacks.js +166 -0
  107. package/core/startup.js +153 -11
  108. package/core/streamSources.js +0 -11
  109. package/core/styleParts.js +63 -47
  110. package/core/targeting.js +1 -1
  111. package/core/textureBytes.js +20 -0
  112. package/core/thingExplain.js +2 -2
  113. package/core/thingOps.js +29 -6
  114. package/core/things.js +21 -11
  115. package/core/threadPure.js +7 -3
  116. package/core/threePatches.js +47 -0
  117. package/core/tier.js +21 -10
  118. package/core/time.js +236 -0
  119. package/core/uiClock.js +25 -0
  120. package/core/util.js +7 -1
  121. package/core/validate.js +65 -86
  122. package/core/wrap.js +106 -0
  123. package/docs/AI.md +87 -100
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +220 -147
  126. package/docs/COMMANDS.md +56 -35
  127. package/docs/CONVENTIONS.md +90 -28
  128. package/docs/MIGRATING-0.3.md +248 -0
  129. package/docs/MIGRATING-0.4.md +228 -0
  130. package/docs/MIGRATING-0.5.md +68 -0
  131. package/docs/PERF.md +35 -7
  132. package/docs/THREE.md +79 -27
  133. package/docs/api/ambience.md +0 -1
  134. package/docs/api/assets.md +11 -9
  135. package/docs/api/audio.md +10 -14
  136. package/docs/api/calendar.md +41 -0
  137. package/docs/api/cameraRig.md +16 -5
  138. package/docs/api/characters.md +38 -23
  139. package/docs/api/clock.md +6 -5
  140. package/docs/api/collision.md +9 -6
  141. package/docs/api/content.md +6 -4
  142. package/docs/api/dialogue.md +9 -9
  143. package/docs/api/engine.md +63 -60
  144. package/docs/api/events.md +19 -14
  145. package/docs/api/grids.md +3 -3
  146. package/docs/api/ground.md +1 -1
  147. package/docs/api/hud.md +2 -2
  148. package/docs/api/i18n.md +1 -1
  149. package/docs/api/input.md +11 -6
  150. package/docs/api/interactions.md +7 -5
  151. package/docs/api/inventory.md +17 -16
  152. package/docs/api/level.md +0 -1
  153. package/docs/api/lightPool.md +3 -1
  154. package/docs/api/music.md +1 -1
  155. package/docs/api/nav.md +3 -0
  156. package/docs/api/openWorld.md +2 -1
  157. package/docs/api/particles.md +2 -2
  158. package/docs/api/photo.md +0 -2
  159. package/docs/api/pickups.md +15 -0
  160. package/docs/api/post.md +5 -4
  161. package/docs/api/quests.md +2 -3
  162. package/docs/api/rigid.md +16 -14
  163. package/docs/api/saves.md +6 -4
  164. package/docs/api/settings.md +2 -3
  165. package/docs/api/sky.md +11 -44
  166. package/docs/api/stream.md +1 -1
  167. package/docs/api/style.md +28 -26
  168. package/docs/api/terrain.md +9 -6
  169. package/docs/api/terrainLook.md +10 -0
  170. package/docs/api/timeline.md +3 -4
  171. package/docs/api/tools.md +29 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +11 -8
  174. package/docs/api/vegetationLook.md +10 -0
  175. package/docs/api/water.md +4 -20
  176. package/docs/api/weather.md +5 -15
  177. package/docs/api/weatherLook.md +10 -0
  178. package/docs/api/world.md +2 -1
  179. package/docs/recipes/01-new-game.md +48 -34
  180. package/docs/recipes/02-npc.md +24 -7
  181. package/docs/recipes/03-items-pickups.md +35 -21
  182. package/docs/recipes/04-quests.md +12 -5
  183. package/docs/recipes/05-props-bake.md +151 -15
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +40 -9
  186. package/docs/recipes/08-weather-sky.md +145 -36
  187. package/docs/recipes/{09-style-pack.md → 09-style.md} +101 -52
  188. package/docs/recipes/10-blender-level.md +14 -2
  189. package/docs/recipes/11-vehicles.md +64 -7
  190. package/docs/recipes/13-animation.md +14 -6
  191. package/docs/recipes/14-custom-module.md +61 -29
  192. package/docs/recipes/15-perf.md +30 -9
  193. package/docs/recipes/16-dev-bridge.md +61 -37
  194. package/docs/recipes/18-world.md +16 -6
  195. package/docs/recipes/19-shooting-picking.md +6 -6
  196. package/docs/recipes/20-content-actions-save.md +55 -17
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +3 -3
  199. package/docs/recipes/23-ops.md +16 -10
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +11 -5
  202. package/docs/recipes/28-terrain.md +34 -1
  203. package/docs/recipes/29-grid.md +34 -16
  204. package/docs/recipes/30-templates.md +64 -12
  205. package/docs/recipes/31-audio.md +20 -12
  206. package/docs/recipes/32-action-game.md +35 -2
  207. package/docs/recipes/34-environment-lighting.md +26 -3
  208. package/docs/recipes/35-style-from-reference.md +88 -19
  209. package/docs/recipes/36-sky-ground-plant-looks.md +18 -18
  210. package/docs/recipes/37-terrain-look-hooks.md +3 -2
  211. package/docs/recipes/38-environment-look-hooks.md +37 -26
  212. package/docs/recipes/40-scene.md +16 -13
  213. package/docs/recipes/41-thing-registry.md +11 -7
  214. package/docs/recipes/42-terrain-shape.md +2 -2
  215. package/docs/recipes/43-shader-patches-surface-looks.md +158 -76
  216. package/docs/recipes/44-water-weather-look-hooks.md +26 -17
  217. package/docs/recipes/45-cascaded-shadows.md +16 -7
  218. package/docs/recipes/47-island-snow-backdrop.md +7 -7
  219. package/docs/recipes/48-make-material.md +11 -6
  220. package/docs/recipes/49-game-module-contract.md +30 -17
  221. package/docs/recipes/50-own-renderer.md +2 -2
  222. package/docs/recipes/51-capability-catalog.md +3 -3
  223. package/docs/recipes/52-look.md +197 -61
  224. package/docs/recipes/53-ground-up-close.md +1 -1
  225. package/docs/recipes/54-three-idioms.md +88 -0
  226. package/docs/recipes/55-mods-time-wrap.md +112 -0
  227. package/docs/recipes/56-webgpu-tsl.md +260 -0
  228. package/docs/recipes/57-control.md +65 -0
  229. package/docs/recipes/58-input.md +57 -0
  230. package/docs/recipes/59-depth-post-effects.md +83 -0
  231. package/docs/recipes/60-judge-the-picture.md +55 -0
  232. package/examples/action/.threedog/content-index.json +1 -0
  233. package/examples/action/GAMEMAP.md +17 -13
  234. package/examples/action/assets.js +8 -0
  235. package/examples/action/content/actions.js +1 -1
  236. package/examples/action/content/audio.js +5 -5
  237. package/examples/action/look.js +1 -1
  238. package/examples/action/main.js +10 -14
  239. package/examples/action/models.js +24 -23
  240. package/examples/pullable.json +111 -0
  241. package/examples/rc2d/.threedog/content-index.json +1 -0
  242. package/examples/rc2d/GAMEMAP.md +83 -0
  243. package/examples/rc2d/README.md +52 -0
  244. package/examples/rc2d/main.js +63 -0
  245. package/examples/rc2d/rc2d.js +197 -0
  246. package/examples/rc2d/shaders.js +144 -0
  247. package/examples/sheepisland/.threedog/content-index.json +1 -0
  248. package/examples/sheepisland/GAMEMAP.md +13 -11
  249. package/examples/sheepisland/assets.js +5 -0
  250. package/examples/sheepisland/main.js +17 -12
  251. package/examples/sheepisland/style/index.js +6 -6
  252. package/examples/styletest/.threedog/content-index.json +1 -0
  253. package/examples/styletest/GAMEMAP.md +15 -16
  254. package/examples/styletest/assets.js +6 -0
  255. package/examples/styletest/content/templates.js +1 -1
  256. package/examples/styletest/content/vegetation.js +1 -1
  257. package/examples/styletest/look.js +1 -1
  258. package/examples/styletest/main.js +17 -16
  259. package/examples/styletest/models.js +1 -1
  260. package/examples/styletest/params.js +3 -3
  261. package/examples/techniques/contact-shadows/README.md +92 -0
  262. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  263. package/examples/techniques/contact-shadows/main.js +53 -0
  264. package/examples/techniques/day-night-grade/README.md +86 -0
  265. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  266. package/examples/techniques/day-night-grade/main.js +51 -0
  267. package/examples/techniques/interior-light/README.md +103 -0
  268. package/examples/techniques/interior-light/interiorLight.js +45 -0
  269. package/examples/techniques/interior-light/main.js +124 -0
  270. package/examples/techniques/modular-building/README.md +125 -0
  271. package/examples/techniques/modular-building/kit.js +426 -0
  272. package/examples/techniques/modular-building/main.js +47 -0
  273. package/examples/techniques/night-lights/README.md +94 -0
  274. package/examples/techniques/night-lights/main.js +70 -0
  275. package/examples/techniques/night-lights/nightLights.js +91 -0
  276. package/examples/techniques/outlines-and-rim/README.md +59 -0
  277. package/examples/techniques/outlines-and-rim/main.js +84 -0
  278. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  279. package/examples/techniques/procedural-animation/README.md +77 -0
  280. package/examples/techniques/procedural-animation/creature.js +44 -0
  281. package/examples/techniques/procedural-animation/main.js +45 -0
  282. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  283. package/examples/techniques/procedural-surface/README.md +67 -0
  284. package/examples/techniques/procedural-surface/main.js +103 -0
  285. package/examples/techniques/procedural-surface/surface.js +120 -0
  286. package/examples/techniques/stylized-shading/README.md +75 -0
  287. package/examples/techniques/stylized-shading/main.js +93 -0
  288. package/examples/techniques/stylized-shading/shading.js +131 -0
  289. package/examples/techniques/sun-and-key-light/README.md +135 -0
  290. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  291. package/examples/techniques/sun-and-key-light/main.js +95 -0
  292. package/examples/techniques/wet-road/README.md +99 -0
  293. package/examples/techniques/wet-road/main.js +68 -0
  294. package/examples/techniques/wet-road/wetRoad.js +209 -0
  295. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  296. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  297. package/examples/webgpu-tsl/README.md +42 -0
  298. package/examples/webgpu-tsl/main.js +21 -0
  299. package/examples/webgpu-tsl/tslScene.js +75 -0
  300. package/examples/world/.threedog/content-index.json +1 -0
  301. package/examples/world/GAMEMAP.md +22 -15
  302. package/examples/world/art/humanoid.js +42 -0
  303. package/examples/world/art/index.js +11 -0
  304. package/examples/world/art/models.js +58 -0
  305. package/examples/world/art/shapes.js +9 -0
  306. package/examples/world/assets.js +6 -0
  307. package/examples/world/content/audio.js +5 -5
  308. package/examples/world/content/npcs.js +1 -1
  309. package/examples/world/content/props.js +1 -1
  310. package/examples/world/content/rules.js +1 -1
  311. package/examples/world/content/templates.js +1 -1
  312. package/examples/world/content/vegetation.js +1 -1
  313. package/examples/world/main.js +17 -13
  314. package/examples/world/style/index.js +61 -0
  315. package/examples/world/style/plugins/10-bloom.js +5 -0
  316. package/index.d.ts +44 -45
  317. package/index.js +26 -22
  318. package/llms.txt +11 -4
  319. package/modules/ambience/Ambience.js +34 -23
  320. package/modules/calendar/Calendar.js +163 -0
  321. package/modules/calendar/contract.js +21 -0
  322. package/modules/calendar/index.js +81 -0
  323. package/modules/{sky → calendar}/schedule.js +17 -16
  324. package/modules/calendar/seasons.js +55 -0
  325. package/modules/camera/FirstPersonCamera.js +6 -15
  326. package/modules/camera/FixedCamera.js +33 -15
  327. package/modules/camera/FollowCamera.js +90 -16
  328. package/modules/camera/RtsCamera.js +18 -17
  329. package/modules/camera/common.js +70 -19
  330. package/modules/camera/contract.js +17 -0
  331. package/modules/camera/projection.js +11 -24
  332. package/modules/characters/Character.js +177 -42
  333. package/modules/characters/NPC.js +87 -36
  334. package/modules/characters/assetModel.js +4 -13
  335. package/modules/characters/behaviors.js +2 -1
  336. package/modules/characters/contract.js +13 -0
  337. package/modules/characters/footsteps.js +1 -1
  338. package/modules/characters/index.js +87 -49
  339. package/modules/characters/moveHelpers.js +4 -5
  340. package/modules/characters/movers/common.js +97 -19
  341. package/modules/characters/movers/manual.js +20 -0
  342. package/modules/characters/movers/rapier.js +19 -16
  343. package/modules/characters/movers/simple.js +14 -11
  344. package/modules/characters/movers/support.js +172 -0
  345. package/modules/characters/npcAvoid.js +47 -42
  346. package/modules/characters/npcSim.js +12 -8
  347. package/modules/characters/npcView.js +44 -16
  348. package/modules/characters/pathAsync.js +7 -3
  349. package/modules/characters/playerStrings.js +4 -3
  350. package/modules/characters/proceduralRig.js +2 -1
  351. package/modules/characters/useModel.js +1 -1
  352. package/modules/characters/vehicle.contract.js +21 -0
  353. package/modules/characters/walkTo.js +21 -7
  354. package/modules/collision/Collision.js +65 -25
  355. package/modules/collision/grid.js +8 -6
  356. package/modules/content/explain.js +2 -2
  357. package/modules/content/fields.js +102 -0
  358. package/modules/content/ids.js +8 -6
  359. package/modules/content/index.js +96 -27
  360. package/modules/content/loader.js +45 -33
  361. package/modules/content/models.js +11 -40
  362. package/modules/content/packs.js +6 -5
  363. package/modules/content/parts.js +41 -0
  364. package/modules/content/props.js +16 -9
  365. package/modules/content/rules.js +58 -0
  366. package/modules/content/stages.js +80 -0
  367. package/modules/content/templates.js +121 -30
  368. package/modules/debug/DebugPanel.js +24 -17
  369. package/modules/flow/contract.js +16 -0
  370. package/modules/flow/index.js +21 -15
  371. package/modules/gameplay/Container.js +41 -32
  372. package/modules/gameplay/Containers.js +30 -15
  373. package/modules/gameplay/Dialogue.js +113 -55
  374. package/modules/gameplay/Interactions.js +193 -67
  375. package/modules/gameplay/Inventory.js +69 -73
  376. package/modules/gameplay/Quests.js +75 -39
  377. package/modules/gameplay/boxOps.js +3 -3
  378. package/modules/gameplay/dialogue.contract.js +21 -0
  379. package/modules/gameplay/dialogueBox.js +4 -2
  380. package/modules/gameplay/dialogueBubbles.js +116 -0
  381. package/modules/gameplay/interactionPrompt.js +4 -1
  382. package/modules/gameplay/interactions.contract.js +16 -0
  383. package/modules/gameplay/inventory.contract.js +23 -0
  384. package/modules/gameplay/inventoryOps.js +18 -16
  385. package/modules/gameplay/pickups.js +268 -85
  386. package/modules/gameplay/questLog.js +4 -4
  387. package/modules/gameplay/quests.contract.js +17 -0
  388. package/modules/grid/Grid.js +92 -50
  389. package/modules/grid/Layer.js +14 -13
  390. package/modules/grid/index.js +60 -36
  391. package/modules/grid/ops.js +20 -18
  392. package/modules/grid/preview.js +15 -16
  393. package/modules/grid/strings.js +12 -0
  394. package/modules/grid/tiles.js +6 -5
  395. package/modules/hlod/index.js +51 -19
  396. package/modules/hud/index.js +35 -20
  397. package/modules/hud/parts.js +20 -7
  398. package/modules/level/heightfield.js +3 -1
  399. package/modules/level/index.js +45 -20
  400. package/modules/level/nodes.js +4 -3
  401. package/modules/lights/index.js +42 -18
  402. package/modules/music/Music.js +38 -21
  403. package/modules/music/rules.js +1 -1
  404. package/modules/nav/index.js +48 -42
  405. package/modules/net/Client.js +13 -6
  406. package/modules/net/Host.js +19 -5
  407. package/modules/net/Net.js +2 -1
  408. package/modules/net/index.js +13 -8
  409. package/modules/net/sync.js +9 -8
  410. package/modules/net/transports.js +77 -27
  411. package/modules/particles/Particles.js +23 -14
  412. package/modules/particles/contract.js +17 -0
  413. package/modules/particles/effect.js +39 -11
  414. package/modules/photo/Photo.js +53 -36
  415. package/modules/rigid/RigidBodies.js +194 -32
  416. package/modules/rigid/Vehicles.js +18 -15
  417. package/modules/rigid/sync.js +62 -17
  418. package/modules/settings/Settings.js +57 -52
  419. package/modules/settings/apply.js +38 -3
  420. package/modules/settings/sections.js +5 -3
  421. package/modules/settings/strings.js +3 -2
  422. package/modules/settings/view.js +5 -3
  423. package/modules/sky/Sky.js +88 -176
  424. package/modules/sky/cascades.js +86 -25
  425. package/modules/sky/cascades.tsl.js +82 -0
  426. package/modules/sky/clouds.js +34 -19
  427. package/modules/sky/domeLayers.js +30 -15
  428. package/modules/sky/environment.js +83 -13
  429. package/modules/sky/fog.js +140 -95
  430. package/modules/sky/frame.js +112 -44
  431. package/modules/sky/look.js +22 -19
  432. package/modules/sky/lookFog.js +48 -52
  433. package/modules/sky/lookShadow.js +53 -41
  434. package/modules/sky/lookSky.js +82 -21
  435. package/modules/sky/season.js +21 -0
  436. package/modules/sky/shader.js +41 -19
  437. package/modules/sky/shadow.js +44 -20
  438. package/modules/sky/skyModule.js +45 -33
  439. package/modules/sky/tint.js +61 -0
  440. package/modules/terrain/ChunkManager.js +175 -108
  441. package/modules/terrain/chunkJob.js +1 -1
  442. package/modules/terrain/chunkQueries.js +6 -4
  443. package/modules/terrain/index.js +105 -50
  444. package/modules/terrain/look.js +83 -0
  445. package/modules/terrain/lookGround.js +21 -16
  446. package/modules/terrain/terrainDefaults.js +1 -1
  447. package/modules/terrain/terrainEdit.js +18 -20
  448. package/modules/terrain/terrainGen.js +5 -3
  449. package/modules/terrain/terrainIsland.js +5 -4
  450. package/modules/terrain/terrainShape.js +12 -12
  451. package/modules/terrain/terrainShapeMain.js +8 -7
  452. package/modules/terrain/terrainTexture.js +21 -19
  453. package/modules/timeline/Timeline.js +95 -43
  454. package/modules/timeline/Tween.js +18 -10
  455. package/modules/timeline/letterbox.js +2 -2
  456. package/modules/timeline/shots.js +5 -1
  457. package/modules/triggers/index.js +107 -76
  458. package/modules/vegetation/Vegetation.js +186 -110
  459. package/modules/vegetation/densityMap.js +62 -0
  460. package/modules/vegetation/groundChunks.js +52 -58
  461. package/modules/vegetation/index.js +32 -11
  462. package/modules/vegetation/look.js +119 -0
  463. package/modules/vegetation/lookWind.js +71 -10
  464. package/modules/vegetation/modelGeometry.js +3 -2
  465. package/modules/vegetation/nearFade.js +8 -2
  466. package/modules/water/Water.js +65 -27
  467. package/modules/water/look.js +29 -18
  468. package/modules/water/surface.js +64 -25
  469. package/modules/water/surfaceDefaults.js +3 -0
  470. package/modules/weather/Weather.js +62 -104
  471. package/modules/weather/look.js +1 -2
  472. package/modules/weather/particles.js +24 -9
  473. package/modules/weather/strings.js +2 -2
  474. package/modules/weather/weatherLook.js +135 -0
  475. package/modules/world/World.js +24 -7
  476. package/modules/world/explain.js +1 -1
  477. package/modules/world/index.js +18 -4
  478. package/modules/world/persist.js +62 -2
  479. package/modules/world/pos.js +3 -2
  480. package/modules/world/records.js +8 -6
  481. package/modules/world/sim.js +60 -20
  482. package/modules/world/simFar.js +4 -3
  483. package/modules/world/state.js +3 -2
  484. package/modules/world/thingSource.js +1 -1
  485. package/modules/world/views.js +7 -5
  486. package/package.json +7 -3
  487. package/presets.js +41 -27
  488. package/render/PostFX.js +145 -120
  489. package/render/backend.js +440 -0
  490. package/render/detail.js +120 -39
  491. package/render/effects.js +130 -38
  492. package/render/engineUniforms.js +10 -1
  493. package/render/fuse.js +5 -4
  494. package/render/fx/cloudShadow.tsl.js +16 -0
  495. package/render/fx/detail.tsl.js +66 -0
  496. package/render/fx/index.js +26 -0
  497. package/render/fx/lighting.tsl.js +28 -0
  498. package/render/fx/nodeErrors.tsl.js +68 -0
  499. package/render/fx/noise.tsl.js +12 -0
  500. package/render/fx/objectOrigin.tsl.js +42 -0
  501. package/render/fx/particles.tsl.js +139 -0
  502. package/render/fx/patchNodes.tsl.js +403 -0
  503. package/render/fx/postWebGPU.tsl.js +158 -0
  504. package/render/fx/season.tsl.js +13 -0
  505. package/render/fx/sky.tsl.js +260 -0
  506. package/render/fx/uniforms.tsl.js +67 -0
  507. package/render/fx/water.tsl.js +53 -0
  508. package/render/fx/wind.tsl.js +22 -0
  509. package/render/fxNumbers.js +36 -0
  510. package/render/hotGlsl.js +24 -0
  511. package/render/lighting.js +66 -14
  512. package/render/lights.js +223 -4
  513. package/render/lookGlow.js +139 -0
  514. package/render/lookSurface.js +99 -36
  515. package/render/materials.js +71 -52
  516. package/render/modeling.js +73 -0
  517. package/render/ownFrame.js +76 -0
  518. package/render/patches.js +311 -34
  519. package/render/postLook.js +124 -46
  520. package/render/postWebGL.js +197 -0
  521. package/render/probes.js +231 -0
  522. package/render/shaderErrors.js +154 -0
  523. package/render/slots.js +165 -0
  524. package/render/surface.js +53 -17
  525. package/render/terms.js +211 -0
  526. package/render/uniformDecl.js +3 -2
  527. package/types/common.d.ts +2 -2
  528. package/types/core.d.ts +614 -240
  529. package/types/gameplay.d.ts +482 -312
  530. package/types/generated/core/Audio.d.ts +26 -42
  531. package/types/generated/core/Batching.d.ts +6 -2
  532. package/types/generated/core/Budget.d.ts +2 -8
  533. package/types/generated/core/DebugOverrides.d.ts +44 -3
  534. package/types/generated/core/I18n.d.ts +2 -2
  535. package/types/generated/core/Input.d.ts +102 -31
  536. package/types/generated/core/Ops.d.ts +31 -0
  537. package/types/generated/core/Random.d.ts +2 -2
  538. package/types/generated/core/Saves.d.ts +10 -2
  539. package/types/generated/core/Stream.d.ts +1 -1
  540. package/types/generated/core/Threads.d.ts +4 -1
  541. package/types/generated/core/Views.d.ts +0 -1
  542. package/types/generated/core/audioVoice.d.ts +17 -9
  543. package/types/generated/core/control.d.ts +55 -0
  544. package/types/generated/core/session.d.ts +2 -1
  545. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  546. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  547. package/types/generated/modules/calendar/index.d.ts +10 -0
  548. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  549. package/types/generated/modules/grid/Grid.d.ts +61 -25
  550. package/types/generated/modules/grid/Layer.d.ts +5 -5
  551. package/types/generated/modules/grid/index.d.ts +29 -17
  552. package/types/generated/modules/music/Music.d.ts +5 -3
  553. package/types/generated/modules/net/index.d.ts +3 -3
  554. package/types/generated/modules/net/transports.d.ts +12 -3
  555. package/types/generated/modules/particles/Particles.d.ts +1 -1
  556. package/types/generated/modules/sky/Sky.d.ts +12 -104
  557. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  558. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  559. package/types/generated/modules/weather/Weather.d.ts +17 -18
  560. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  561. package/types/generated/modules/world/World.d.ts +18 -3
  562. package/types/generated/render/PostFX.d.ts +67 -30
  563. package/types/generated/render/materials.d.ts +26 -20
  564. package/types/generated/render/modeling.d.ts +30 -0
  565. package/types/generated/render/patches.d.ts +16 -2
  566. package/types/generated/ui/UI.d.ts +6 -3
  567. package/types/nav.d.ts +6 -0
  568. package/types/physics.d.ts +137 -44
  569. package/types/style.d.ts +109 -81
  570. package/types/tsl.d.ts +86 -0
  571. package/types/world.d.ts +158 -110
  572. package/ui/Focus.js +25 -14
  573. package/ui/LoadingScreen.js +1 -1
  574. package/ui/Parts.js +27 -11
  575. package/ui/UI.js +20 -10
  576. package/ui/cursor.js +115 -0
  577. package/ui/defaults.js +15 -11
  578. package/ui/theme.js +9 -6
  579. package/ui/touchPart.js +1 -1
  580. package/core/claims.js +0 -51
  581. package/core/look/layers.js +0 -136
  582. package/core/renamed.js +0 -22
  583. package/docs/api/entities.md +0 -61
  584. package/examples/styletest/overrides.js +0 -33
  585. package/examples/styletest/panel.js +0 -135
  586. package/modules/entities/Entities.js +0 -243
  587. package/modules/entities/build.js +0 -25
  588. package/modules/entities/index.js +0 -4
  589. package/modules/sky/calendar.js +0 -80
  590. package/modules/sky/layers.js +0 -69
  591. package/modules/terrain/chunkLevels.js +0 -40
  592. package/modules/terrain/mountTerrain.js +0 -32
  593. package/modules/world/cells.js +0 -42
@@ -1,5 +1,5 @@
1
- // sheepisland: a style pack, LOOKS ONLY (recipes/09-style-pack.md, 35-style-from-reference.md), started from the new-style template
2
- // (packages/tools/templates/style). A soft painted diorama: few flat colors, round shapes, soft shadows, a pale warm background with no horizon.
1
+ // sheepisland: this game's style, LOOKS ONLY (recipes/09-style.md, 35-style-from-reference.md), filled in from the empty style/index.js
2
+ // a new game starts with. A soft painted diorama: few flat colors, round shapes, soft shadows, a pale warm background with no horizon.
3
3
  // The world (island outline, river, wheat field) is the game's terrain() in ../main.js, never here.
4
4
  import { makeMaterial, applyEffects } from '../../../index.js';
5
5
  import { models, PALETTE } from './models.js';
@@ -11,15 +11,15 @@ export const assets = { name: 'sheepisland', models };
11
11
  // Background: zenith = horizon = fog color at every time, so the dome is one flat tone and no horizon line shows.
12
12
  // [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
13
13
  // Ground material with snow that survives shading: 'texture'. The engine's season tint runs at color_fragment, before the per-chunk color map is
14
- // multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (emissivemap_fragment,
14
+ // multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (slot emissive, emissivemap_fragment,
15
15
  // after every color patch, before lighting), reading the engine's own season uniforms under new names (the season patch declares the old ones).
16
16
  /** @param {any} engine */
17
17
  function snowyGround(engine) {
18
18
  const u = engine.uniforms;
19
19
  return applyEffects(makeMaterial('terrain', { vertexColors: true }, engine), { clouds: false, patches: [{
20
20
  name: 'snowCover', cacheKey: 1, uniforms: { uSnowTint: u.uGroundTint, uSnowMix: u.uGroundMix },
21
- glsl: { fragment: { pars: 'uniform vec3 uSnowTint; uniform float uSnowMix;',
22
- emissivemap_fragment: 'diffuseColor.rgb = mix(diffuseColor.rgb, uSnowTint, uSnowMix);' } } }] });
21
+ pars: 'uniform vec3 uSnowTint; uniform float uSnowMix;',
22
+ slot: 'emissive', glsl: 'diffuseColor.rgb = mix(diffuseColor.rgb, uSnowTint, uSnowMix);' }] });
23
23
  }
24
24
 
25
25
  const DAY = 0xefebe4, DUSK = 0xf0d9c4, NIGHT = 0x2c3346;
@@ -28,7 +28,7 @@ export default {
28
28
  exposure: 1,
29
29
  toneMapping: 'neutral', // neutral keeps the painted colors close to what is written here (aces darkens and shifts them)
30
30
 
31
- post: [], // restraint: the reference shows no outline, bloom or grain
31
+ // no post plugins: restraint, the reference shows no outline, bloom or grain
32
32
 
33
33
  materials: {
34
34
  default: { type: 'lambert' },
@@ -0,0 +1 @@
1
+ {"version":1,"files":{"content/items.js":{"kind":"items","mtime":1793494482512.194,"from":0,"count":3,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1793540086876.2478,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1793494482518.1973,"from":0,"count":2,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1793494482521.1953,"from":0,"count":12,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1793699847094.7925,"from":0,"count":6,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1793699847095.7913,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"apple":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"key":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":5,"placed":false},{"file":"content/props.js","kind":"props","line":10,"placed":true}],"guide":[{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"stage":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"pine":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"round-tree":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"rock":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"flower-a":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"flower-b":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"flower-c":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"stone":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"metal":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"glass":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"shadow-stage":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"room":[{"file":"content/props.js","kind":"props","line":15,"placed":true},{"file":"content/templates.js","kind":"templates","line":8,"placed":false}],"woodBlock":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"stoneBlock":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"metalBall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"glassPanes":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"shadowStage":[{"file":"content/templates.js","kind":"templates","line":7,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":10,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":16,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":20,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":25,"placed":false}]}}
@@ -11,11 +11,11 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
11
11
 
12
12
  ## Engine modules (engine.use)
13
13
 
14
- - createEngine: { style: parts.length ? parts : undefined, strings: terrainStrings, saveKey: 'threedog-styletest', ui: { load…
15
- - openWorld preset ({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, …) → world, terrain, vegetation, sky, weather, water, collision, rigid, characters, ambience, settings, debug
14
+ - createEngine: { bindings: { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...prese…
15
+ - openWorld preset ({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, …) → world, terrain, vegetation, calendar, sky, weather, water, collision, rigid, characters, ambience, settings, debug
16
16
  - interactions ({ ...presets.interactions.nearest })
17
17
  - dialogue ({ holdSeconds: 1e6 })
18
- - inventory ({ ...presets.keys.inventory })
18
+ - inventory
19
19
  - hud
20
20
  - lightPool ({ point: 2 })
21
21
  - content
@@ -25,19 +25,19 @@ None yet, write them in `DESIGN.md` (why it is designed this way, what not to ch
25
25
  - world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
26
26
  - terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
27
27
  - vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
28
+ - calendar: `node_modules/threedog/docs/recipes/06-clock-events.md` · `node_modules/threedog/docs/api/calendar.md`
28
29
  - sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
29
30
  - weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
30
31
  - water: `node_modules/threedog/docs/recipes/44-water-weather-look-hooks.md` · `node_modules/threedog/docs/api/water.md`
31
32
  - collision: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/collision.md`
32
33
  - rigid: `node_modules/threedog/docs/recipes/11-vehicles.md` · `node_modules/threedog/docs/api/rigid.md`
33
34
  - characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
34
- - ambience: `node_modules/threedog/docs/recipes/31-audio.md` · `node_modules/threedog/docs/api/ambience.md`
35
- - …7 more modules: their pages are in `node_modules/threedog/docs/api/`
35
+ - …8 more modules: their pages are in `node_modules/threedog/docs/api/`
36
36
 
37
37
  Not used yet (check these before writing the system yourself):
38
38
 
39
39
  - saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
40
- - quests: goals with steps, conditions and rewards: `quests({ ...presets.keys.quests })` (keys required), content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
40
+ - quests: goals with steps, conditions and rewards: `quests()` + key map presets.bindings.quests, content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
41
41
  - grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
42
42
 
43
43
  ## Files
@@ -46,6 +46,7 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
46
46
 
47
47
  | File | Lines | Description |
48
48
  |---|---|---|
49
+ | assets.js | 7 | The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own fil… |
49
50
  | content/index.js | 10 | |
50
51
  | content/items.js | 9 | |
51
52
  | content/npcs.js | 9 | |
@@ -53,17 +54,15 @@ content/*.js is content data: how to write it in `node_modules/threedog/docs/rec
53
54
  | content/props.js | 17 | |
54
55
  | content/templates.js | 10 | |
55
56
  | content/vegetation.js | 32 | |
56
- | look.js | 12 | This example's look, a style part merged over the lowpoly pack (createEngine({ style: [lowpoly, loo… |
57
- | main.js | 96 | @ts-check Style test: one fixed scene to judge a style pack by (and the check an AI runs after turn… |
58
- | models.js | 88 | The exhibits that are not in the lowpoly asset pack, built in code and registered by name in main.j… |
59
- | overrides.js | 34 | What the style workbench exports: the values the user changed, as a plain object literal to paste i… |
60
- | panel.js | 136 | Style workbench (?panel=1): sliders and color pickers over the running style test, plus an export o… |
57
+ | look.js | 12 | This example's look, a style part merged over the style under test (createEngine({ style: [worldSty… |
58
+ | main.js | 97 | @ts-check Style test: one fixed scene to judge a style by (and the check an AI runs after turning a… |
59
+ | models.js | 88 | The exhibits that are not in the world example's art (../world/art), built in code and registered b… |
61
60
  | params.js | 33 | URL parameters of the style test page. Import this file first in main.js: it rewrites word values i… |
62
61
  | views.js | 32 | Named camera positions of the style test. Same name = same framing every time, so two screenshots d… |
63
62
 
64
63
  ## NPCs (content/npcs.js)
65
64
 
66
- | id | Name | Schedule | Dialogue entry |
65
+ | id | Name | Schedule | Interact |
67
66
  |---|---|---|---|
68
67
  | guide | Guide | wander | — |
69
68
 
@@ -90,7 +89,7 @@ Starting inventory: apple×5, key×1, wood×12. Pickups: 0.
90
89
  - Place stage: a flat spot near water (found at startup); all exhibits are placed relative to it
91
90
  - Place water: the nearest water to the stage (found at startup)
92
91
 
93
- ## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
92
+ ## Object templates (content/templates.js; placed with props { template }, spawned with engine.content.spawn)
94
93
 
95
94
  | Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
96
95
  |---|---|---|---|---|---|---|
@@ -126,10 +125,10 @@ Code that breaks saves or manages world models: none (rule R33).
126
125
  ## Saves
127
126
 
128
127
  - Save prefix saveKey: threedog-styletest
129
- - Saved parts of the engine modules (vars, inventory, quests, timers, world...): `npx threedog catalog` (saves per module)
128
+ - Saved parts of the engine modules (vars, inventory, quests, timers, world...): `threedog catalog` (saves per module)
130
129
 
131
- ## Style pack keys
130
+ ## Style keys
132
131
 
133
- - Style pack: parts
132
+ - Style: parts
134
133
  - Models (asset names): pine, pineLow, roundTree, roundTreeLow, rock, grass, flower, woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room
135
134
  - Vegetation (content/vegetation.js): 松树, 圆树, 石头, 草, 野花
@@ -0,0 +1,6 @@
1
+ // The asset packs this game registers (main.js: engine.assets.manifest(packs)). Kept in their own file so `npm run check` imports the same
2
+ // objects and checks the model / sound names content uses against them (one source, no scanning of main.js).
3
+ import { assets as worldArt } from '../world/art/index.js'; // the world example's procedural trees / rocks / humanoid
4
+ import { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } from './models.js';
5
+
6
+ export default [worldArt, { name: 'styletest', models: { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } }]; // the names content/templates.js uses
@@ -1,4 +1,4 @@
1
- // Templates: the exhibits. Model names are registered in main.js (models.js); trees, rocks and flowers come from the lowpoly asset pack.
1
+ // Templates: the exhibits. Model names are registered in main.js (models.js); trees, rocks and flowers come from the world example's art (../world/art).
2
2
  export default {
3
3
  woodBlock: { model: 'woodBlock' },
4
4
  stoneBlock: { model: 'stoneBlock' },
@@ -1,4 +1,4 @@
1
- // Vegetation: name -> model (an asset name from the lowpoly asset pack; use an array for parameters) and growth rule.
1
+ // Vegetation: name -> model (an asset name from the world example's asset pack, ../../world/art/; use an array for parameters) and growth rule.
2
2
  // rule.biomes lists the biomes it grows in, values are spawn probabilities; rule cannot hold functions (it is sent to a worker thread).
3
3
  export default {
4
4
  松树: {
@@ -1,4 +1,4 @@
1
- // This example's look, a style part merged over the lowpoly pack (createEngine({ style: [lowpoly, look] })): how the test surfaces feel.
1
+ // This example's look, a style part merged over the style under test (createEngine({ style: [worldStyle, look] }), worldStyle = ../world/style): how the test surfaces feel.
2
2
  // The exhibits ask for roles wood / stone / metal / glass; a style that does not define them falls back to materials.default.
3
3
  export default {
4
4
  name: 'styletest',
@@ -1,15 +1,17 @@
1
1
  // @ts-check
2
- // Style test: one fixed scene to judge a style pack by (and the check an AI runs after turning a reference picture into a style).
2
+ // Style test: one fixed scene to judge a style by (and the check an AI runs after turning a reference picture into a style).
3
3
  // Exhibits (content/): character, trees, rock, grass, flowers, water, terrain, glass, a shadow receiver, wood / stone / metal, a lit room (outside and inside),
4
4
  // and the UI parts (HUD, dialogue, bag) on the `ui` view. Parameters (params.js): time, weather, style, env, view, panel. Camera views: views.js.
5
5
  // main.js holds wiring only: modules, finding the stage, view switching, the lamp. The exhibits are content (rule R33).
6
6
  import { params } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
7
7
  import { createEngine, openWorld, presets, content, interactions, dialogue, inventory, fixedCamera, hud, lightPool, createTerrain } from '../../index.js';
8
- import lowpoly, { assets as lowpolyAssets } from '@threedog/style-lowpoly'; // optional package: the style under test, and the procedural trees / rocks
8
+ // The style under test: the world example's style folder (its look, named 'world'); the world example's procedural trees / rocks / humanoid are registered from assets.js.
9
+ // To judge your own look, point this import and the one in assets.js at your game's style/index.js.
10
+ import worldStyle from '../world/style/index.js';
9
11
  import { terrainPreset, riverAt, terrainStrings } from '@threedog/terrain-noise';
10
12
  import look from './look.js';
11
13
  import data from './content/index.js';
12
- import { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } from './models.js';
14
+ import packs from './assets.js';
13
15
  import { makeViews, pathAt } from './views.js';
14
16
 
15
17
  // ---------- 0. The stage: a flat spot with water close by (same seed = same place every run) ----------
@@ -32,25 +34,24 @@ for (let r = 0, found = false; r < 3000 && !found; r += 10) {
32
34
  }
33
35
 
34
36
  // ---------- 1. Engine: style under test + open-world preset with a fixed sky (no clock drift between screenshots) ----------
35
- const parts = params.style === 'none' ? [] : [lowpoly, look];
37
+ const parts = params.style === 'none' ? [] : [worldStyle, look];
36
38
  if (params.overrides) parts.push(params.overrides); // the workbench's "rebuild preview" values
37
- const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style: parts.length ? parts : undefined, strings: terrainStrings, saveKey: 'threedog-styletest',
39
+ const engine = createEngine({ bindings: { ...presets.bindings.walk, ...presets.bindings.interact, ...presets.bindings.inventory, ...presets.bindings.debug, ...presets.bindings.dialogNumbers }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style: parts.length ? parts : undefined, strings: terrainStrings, saveKey: 'threedog-styletest',
38
40
  ui: { loading: { title: 'style test' } } });
39
- engine.use(openWorld({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, radius: 30 }], sky: { ...presets.calendar.fixedTime, time: 0.5 },
41
+ engine.use(openWorld({ camera: fixedCamera(), seed: SEED, terrain: terrainPreset(), flatten: [{ x: stage.x, z: stage.z, radius: 30 }], calendar: { ...presets.calendar.fixedTime, time: 0.5 },
40
42
  weather: presets.weather.temperate, autoWeather: false }),
41
- interactions({ ...presets.interactions.nearest }), dialogue({ holdSeconds: 1e6 }), inventory({ ...presets.keys.inventory }), hud(), lightPool({ point: 2 }), content());
43
+ interactions({ ...presets.interactions.nearest }), dialogue({ holdSeconds: 1e6 }), inventory(), hud(), lightPool({ point: 2 }), content());
42
44
 
43
- engine.assets.manifest(lowpolyAssets);
44
- engine.assets.manifest({ name: 'styletest', models: { woodBlock, stoneBlock, metalBall, glassPanes, shadowStage, room } }); // the names content/templates.js uses
45
+ engine.assets.manifest(packs); // assets.js: the world example's trees / rocks and the test models content/templates.js uses
45
46
  engine.characters.createPlayer({ ...presets.player.thirdPerson, model: params.style === 'none' ? null : 'humanoid', spawn: { x: stage.x + 0.5, z: stage.z + 6 } }); // style=none: the gray capsule
46
47
  engine.content.load(data, { places: { stage, water } });
47
- if (params.env) { engine.look.env.replace('sky'); engine.look.env.set({ intensity: 0.8 }); engine.sky.modify('env', { ambient: 0.6 }); } // soft ambient from the sky: lower the hemisphere ambient so shadows stay
48
+ if (params.env) { engine.look.env.replace('sky'); engine.look.env.set({ intensity: 0.8 }); engine.mod('look.lights.hemi.intensity', { owner: 'env', mul: 0.6 }); } // soft ambient from the sky: lower the hemisphere ambient so shadows stay
48
49
 
49
50
  // ---------- 2. The room's lamp: emissive plus one pooled light, on from 18:00 to 06:00 ----------
50
51
  const lampPos = [stage.x + 14, engine.surface(stage.x + 14, stage.z - 2) + 2.7, stage.z - 2];
51
52
  const lampLight = engine.lightPool.add({ x: lampPos[0], y: lampPos[1], z: lampPos[2] }, { color: 0xffc070, intensity: 0, distance: 9 });
52
53
  let lampOn = false;
53
- engine.sky.between('18:00', '06:00', { on: () => { lampOn = true; }, off: () => { lampOn = false; } });
54
+ engine.calendar.between('18:00', '06:00', { on: () => { lampOn = true; }, off: () => { lampOn = false; } });
54
55
  engine.onFrame(() => {
55
56
  const lamp = /** @type {import('three').Mesh<any, import('three').MeshLambertMaterial> | undefined} */ (engine.world.view('room')?.getObjectByName('lamp'));
56
57
  if (lamp) lamp.material.emissiveIntensity = lampOn ? 1.6 : 0;
@@ -63,7 +64,7 @@ const state = { view: params.view, since: 0, views: /** @type {any} */ (null) };
63
64
  /** Show the UI exhibits only on the ui view; close them when leaving it */
64
65
  function showUi(on) {
65
66
  if (on) {
66
- engine.dialogue.say('The light is best just before dusk. Mind the step.', { speaker: 'Guide', lock: false });
67
+ engine.dialogue.say('The light is best just before dusk. Mind the step.', { speaker: 'Guide' }); // the main box, shown for its look
67
68
  engine.ui.open('inventory');
68
69
  } else { engine.dialogue.end(); engine.ui.close('inventory'); }
69
70
  }
@@ -71,12 +72,12 @@ function showUi(on) {
71
72
  function setView(name) {
72
73
  const cam = /** @type {any} */ (engine.cameraRig), views = makeViews(engine, stage, water);
73
74
  for (const [n, v] of Object.entries(views)) cam.add(n, { position: v.pos, lookAt: v.look });
74
- state.view = name; state.since = engine.elapsed; state.views = views;
75
+ state.view = name; state.since = engine.time.now('real'); state.views = views;
75
76
  showUi(name === 'ui');
76
77
  cam.cut(name);
77
78
  }
78
79
  engine.onFrame(() => {
79
- if (state.view === 'path' && state.views) /** @type {any} */ (engine.cameraRig).shots.path.position.fromArray(pathAt(state.views.path, engine.elapsed - state.since));
80
+ if (state.view === 'path' && state.views) /** @type {any} */ (engine.cameraRig).shots.path.position.fromArray(pathAt(state.views.path, engine.time.now('real') - state.since));
80
81
  });
81
82
  engine.ops.define('styletest.view', {
82
83
  desc: 'Move the camera to a named view: overview, character, water, room, path, ui', args: { name: 'string' },
@@ -88,8 +89,8 @@ engine.describe.add('styletest', () => ({ view: state.view, style: params.style,
88
89
  engine.events.on('engine:ready', () => engine.ops.run('styletest.view', { name: params.view }));
89
90
  if (params.badView) console.warn(`styletest: unknown view '${params.badView}', showing overview. Views: overview, character, water, room, path, ui`);
90
91
 
91
- // The workbench is a dev tool loaded only on ?panel=1 (its package may be missing: panel.js then says so in the page)
92
- if (params.panel) import('./panel.js').then(m => m.openPanel(engine, params.overrides));
92
+ // The dev panel (@threedog/tools/panel) on ?panel=1; a production build gets a stub (tweakpane may be missing: the panel then says so in the page)
93
+ if (params.panel) import('@threedog/tools/panel').then(m => m.openPanel(engine, { overrides: params.overrides }));
93
94
 
94
95
  engine.start();
95
96
  window.engine = engine; // handy for debugging in the browser console
@@ -1,4 +1,4 @@
1
- // The exhibits that are not in the lowpoly asset pack, built in code and registered by name in main.js (content/templates.js places them).
1
+ // The exhibits that are not in the world example's art (../world/art), built in code and registered by name in main.js (content/templates.js places them).
2
2
  // Every surface goes through makeMaterial(role), so the style decides the feel: roles wood, stone, metal, glass, building.
3
3
  // Shadow flags are set here, on the model (the engine does not guess them).
4
4
  import { THREE, mergeColored, makeMaterial } from '../../index.js';
@@ -1,9 +1,9 @@
1
1
  // URL parameters of the style test page. Import this file first in main.js: it rewrites word values into the forms the engine's own
2
2
  // URL state understands (time=dusk -> 18:30, weather=雨 -> rain) before createEngine reads the URL.
3
3
  // time day | dusk | night, or HH:MM weather clear | rain | snow (晴 雨 雪), or any engine weather name
4
- // style lowpoly | none env 1 = environment lighting from the sky (default 0)
4
+ // style world | none env 1 = environment lighting from the sky (default 0)
5
5
  // view overview | character | water | room | path | ui (总览 角色特写 水面 室内 移动镜头路径 界面)
6
- // panel 1 = the style workbench (needs the tweakpane dev package)
6
+ // panel 1 = the dev panel, @threedog/tools/panel (needs the tweakpane dev package)
7
7
  // ov style overrides the workbench exports for "rebuild preview" (JSON, URL-encoded)
8
8
  /** @type {Record<string, string>} */
9
9
  const TIME = { day: '12:00', 白天: '12:00', dusk: '18:30', 黄昏: '18:30', night: '23:00', 夜晚: '23:00' };
@@ -24,7 +24,7 @@ if (changed) history.replaceState(null, '', url);
24
24
  const view = VIEWS[q.get('view')] ?? q.get('view') ?? 'overview';
25
25
  export const params = Object.freeze({
26
26
  view: VIEW_NAMES.includes(view) ? view : 'overview',
27
- style: q.get('style') === 'none' ? 'none' : 'lowpoly',
27
+ style: q.get('style') === 'none' ? 'none' : 'world',
28
28
  env: q.get('env') === '1',
29
29
  panel: q.get('panel') === '1',
30
30
  overrides: q.get('ov') ? JSON.parse(q.get('ov')) : null,
@@ -0,0 +1,92 @@
1
+ Contact shadows: make objects sit on the ground instead of floating (shadow box size, bias, fill balance, baked and screen-space AO, probes).
2
+
3
+ # Contact shadows (technique example)
4
+
5
+ A neutral gray scene with small objects on the ground and on a table. Demo: `npm run dev` in the engine package, open `/contact-shadows.html`
6
+ (`?mode=float` shows the failure, `&ao=1` the AO pass, `&probes=1` probes). The engine never imports this folder.
7
+
8
+ ## The principle
9
+ A cup on a table, a box on the floor, a character's feet: if nothing darkens the ground right where the object touches it, the eye reads a
10
+ gap, and the object hovers. What grounds it is a small, dark, sharp-ish shadow at the foot plus darkening in the creases between parts. Three
11
+ things usually remove that darkening together (`?mode=float` is the engine's defaults, built for a 140 m open world):
12
+ 1. **The shadow map is too coarse for small things.** Shadow detail is texels per meter, nothing else. One sun map covers a box of
13
+ `2 * extent` meters: `extent: 70` on a 2048 map is 140 m / 2048 = **6.8 cm per texel**. A 10 cm cup's shadow is one or two texels,
14
+ blurred away by the soft filter.
15
+ 2. **The bias pushes the shadow off the foot.** Acne is a sampling error of about one texel, so the bias that cures it scales with the texel.
16
+ `normalBias` moves the lookup along the surface normal so flat ground does not shadow itself; 4 cm is right for 6.8 cm texels and far
17
+ too much under a 10 cm cup: the shadow starts a few centimeters away from its base. Too low: stripes on the ground. Too high: shadows
18
+ detach (peter-panning).
19
+ 3. **The fill washes out what shadow is left.** A shadow is only the absence of the sun; what you see in it is the fill (hemisphere and
20
+ environment light). When the fill is close to the sun, a shadow darkens the ground by 10-20% and reads as dirt, not contact.
21
+ A fourth cause is plain placement: an object 1 cm above its support also floats. Put it at `y = support + half height`.
22
+
23
+ Occlusion is geometry, not light: a crease or a foot is dark because the surroundings block the sky, which is why ambient occlusion (baked
24
+ or screen-space) grounds things even where the sun shadow is soft. Light probes are different: indirect light sampled at points; they do not
25
+ ground small objects by themselves, they make the fill vary so shadowed corners and the space under a roof are darker than open ground.
26
+
27
+ How to judge it: take a shot at the game's real camera and look at whether small things sit or hover. `threedog shot` prints "shadow area
28
+ ... darkened by N%"; on the demo the defaults give "shadow area 8.0% (darkened by 11.0%)", the technique "8.9% (darkened by 26.0%)".
29
+ How strongly shadows should read is a decision for DESIGN.md, not a fixed value.
30
+
31
+ ## Plain three.js
32
+ - Shadow box: a `DirectionalLight`'s `shadow.camera` is an `OrthographicCamera`; its `left/right/top/bottom` set the box, `shadow.mapSize`
33
+ the texels ([DirectionalLightShadow](https://threejs.org/docs/#api/en/lights/shadows/DirectionalLightShadow),
34
+ [LightShadow](https://threejs.org/docs/#api/en/lights/shadows/LightShadow) for `bias`, `normalBias`, `radius`). Long views use cascades
35
+ ([webgl_shadowmap_csm](https://threejs.org/examples/#webgl_shadowmap_csm)).
36
+ - Fill: [HemisphereLight](https://threejs.org/docs/#api/en/lights/HemisphereLight) intensity and `scene.environment` /
37
+ `material.envMapIntensity`.
38
+ - Screen-space AO: `GTAOPass` in `three/addons/postprocessing` ([webgl_postprocessing_gtao](https://threejs.org/examples/#webgl_postprocessing_gtao)).
39
+ - Baked AO: write occlusion into a vertex `color` attribute with `material.vertexColors = true`, or into an `aoMap` from a DCC tool.
40
+ - Probes: [LightProbe](https://threejs.org/docs/#api/en/lights/LightProbe) with `LightProbeGenerator` from a cube render.
41
+ - A blob shadow: a transparent quad with a radial gradient texture under the object, `depthWrite: false`.
42
+
43
+ ## Style routes
44
+ - **Realistic**: a tight shadow box, small texel-sized bias, a fill low enough that shadows read, plus AO in the creases. Costs shadow-map
45
+ tuning and possibly a screen AO pass.
46
+ - **Pastel / flat-shaded**: the same box and bias, a gentler fill (soft shadows read as color, not black). No extra cost.
47
+ - **High-contrast / noir**: a lower fill, perhaps a tinted hemisphere ground color. No extra cost.
48
+ - **Toon whose material ignores light**: contact only from vertex AO or a blob decal under the object. One quad per object, no shadow map.
49
+ - **Big open world**: keep the default box for the far view and use cascades; bias, fill and vertex AO still apply.
50
+ - **Interiors with strong bounce** (a sunlit room): probes, baked once and shipped.
51
+
52
+ ## The engine helper (optional convenience)
53
+ `contactShadows.js` combines what the engine already has. `applyContactShadows(engine, opts)` does steps 1-3 below (and 5 with `ao: true`);
54
+ it returns `{ remove(), describe() }` and writes as owner `contact-shadows`, so `engine.describe().look.shadow` says who set the box.
55
+ `groundStatic(geometry)` bakes vertex AO with the ground as occluder (wraps `bakeVertexAO`). `shadowTexelCm()` gives one texel in
56
+ centimeters. The starting values sit in `PARAMS` (tied to this example's 16 m scene; your game picks its own); `threedog examples pull
57
+ contact-shadows` copies the file, then tune `PARAMS` against your DESIGN.md look.
58
+
59
+ | Step | What | Cost (1280x720, laptop GPU, this demo) |
60
+ |---|---|---|
61
+ | 1. Size the shadow box to what the player sees up close | `look.shadow.set({ extent: 8 })`: 16 m / 2048 = **0.8 cm per texel** | none: same map, same draws (4.1 -> 4.3 ms a frame) |
62
+ | 2. Bias in texels, not by habit | `normalBias` about 1.5 texels (1.2 cm here), `bias` near 0; re-check after changing `extent` | none |
63
+ | 3. Fill balance | `engine.mod('look.lights.hemi.intensity', { mul: 0.4 })`: shadows go from 11% to 26% darker on average (shot look numbers) | none |
64
+ | 4. Baked vertex AO on static code-built models | `groundStatic(geometry)`: dark foot, dark creases between parts | load time only: ~95 ms for 880 vertices x 32 rays; 0 per frame |
65
+ | 5. Screen-space AO (optional) | `applyContactShadows(engine, { ao: true })` (GTAO from `@threedog/post-effects`) | **+6.3 ms a frame** (4.3 -> 10.6 ms): only where contact must hold for moving things too |
66
+ | 6. Light probes (optional) | `await engine.bakeProbes({ bounds, spacing })`: bounce light, darker under roofs, lighter beside a sunlit wall | load: 3.6 s for 75 probes (ship the JSON, `engine.loadProbes`); +0.8 ms a frame |
67
+ | Bigger map instead | `mapSize: 4096` | +0.6 ms a frame and 4x the shadow memory; try a smaller `extent` first |
68
+
69
+ Measured with `engine.step` + a 1 px `readPixels` per frame, median of 120 frames. Notes on the engine side:
70
+ - The box follows `engine.focus`, so a compact box is fine for a third-person or fixed camera; the far ground loses its sun shadow, which is
71
+ what cascades are for (`look.shadow.set({ cascades: 3 })`, recipe 45) when the view is long.
72
+ - The sky's ambient column feeds the hemisphere light AND the environment map (recipe 34), so a strong env plus a strong hemi doubles the
73
+ fill. A multiplier (`engine.mod('look.lights.hemi.intensity')`) keeps the day-night cycle.
74
+ - Which steps where: small props on tables, a tidy room, a yard: 1-3, plus 4 for every static code-built model (free at run time).
75
+ Characters and moving props that must look planted close up: add 5 on desktop, keep it off on low-tier devices (`look.post` lists
76
+ `ao.enabled` as costly).
77
+
78
+ Rules (correctness):
79
+ - Vertex AO needs `vertexColors: true` on the material and vertices where the darkening should be; it is baked once, so only static geometry.
80
+ - Under a day-night cycle change the fill with a multiplier (`engine.mod('look.lights.hemi.intensity')`), not `look.lights.set({ hemi })`: a set value replaces the keyframes.
81
+ - `look.shadow` is a sky-module part: `applyContactShadows` needs `sky()` installed. Change cascades / map type on a settings screen (they recompile).
82
+ - `ao()` comes from `@threedog/post-effects`; install it in the game.
83
+
84
+ Common mistakes:
85
+ - Raising `mapSize` to 8192 before shrinking `extent` (16x memory for what `extent` gives free).
86
+ - Copying a `normalBias` from another game: it belongs to that game's texel size.
87
+ - Brightening the whole scene with hemisphere light "so shadows are not black": that is what makes everything float; lift exposure instead.
88
+ - Baking vertex AO on a 12-triangle box: the corners get it, the faces cannot (no vertices there; tessellate big faces).
89
+ - Turning on screen AO and leaving the fill at full: AO darkens creases inside a washed-out picture and looks like dirt.
90
+
91
+ Sources: written for this engine from the three.js docs (`LightShadow.bias / normalBias`, `GTAOPass`, `LightProbeGenerator`) and the common
92
+ shadow-mapping literature (Microsoft "Common Techniques to Improve Shadow Depth Maps"); no code copied.
@@ -0,0 +1,51 @@
1
+ // @ts-check
2
+ // Contact shadows: make objects sit ON the ground instead of hovering above it. Technique example (README.md next to this file); copy and adapt.
3
+ // It only combines what the engine already has: a sun shadow box sized to the scene, small biases, a fill light that leaves shadows dark,
4
+ // optional screen-space AO, and baked vertex AO for static code-built models. Every number is a starting point for a compact scene (a room,
5
+ // a yard, a table top); change PARAMS, not the code.
6
+ import { bakeVertexAO, THREE } from 'threedog';
7
+ import { ao } from '@threedog/post-effects';
8
+
9
+ export const PARAMS = {
10
+ extent: 8, // m, half size of the sun's shadow box around engine.focus: the area the player sees up close, not the whole level
11
+ mapSize: 2048, // px per side; texel = 2 * extent / mapSize (8 m / 2048 -> 0.8 cm). The engine default 70 m box gives 6.8 cm
12
+ normalBias: 0.012, // m, about 1.5 texels: enough against acne, small enough that a 5 cm cup keeps its shadow under its foot
13
+ bias: -0.00002, // shadow-camera depth; normalBias does most of the work, keep this near 0
14
+ fill: 0.4, // x the sky's ambient (hemisphere + environment): lower = darker shadows. 1 = the sky's own value
15
+ ao: false, // screen-space AO post pass (GTAO, @threedog/post-effects): creases and contact corners, +~6 ms on a laptop GPU
16
+ aoRadius: 0.35, // m, how far from a contact AO reaches; about the size of the smallest object you want grounded
17
+ aoIntensity: 0.8, // 0..1
18
+ };
19
+
20
+ /** One shadow-map texel in centimeters for a box of half size `extent` m drawn into `mapSize` px */
21
+ export const shadowTexelCm = (extent = PARAMS.extent, mapSize = PARAMS.mapSize) => 200 * extent / mapSize;
22
+
23
+ /**
24
+ * Apply the grounding settings to a running engine with a sky (look.shadow is a sky part). Returns { remove(), describe() }: remove() gives
25
+ * every value back to the style / engine. Owner 'contact-shadows' shows in engine.describe().look as the writer.
26
+ * @param {import('threedog').Engine} engine
27
+ * @param {Partial<typeof PARAMS>} [opts]
28
+ */
29
+ export function applyContactShadows(engine, opts = {}) {
30
+ const p = { ...PARAMS, ...opts }, owner = 'contact-shadows', handles = [];
31
+ handles.push(engine.look.shadow.set({ extent: p.extent, mapSize: p.mapSize, normalBias: p.normalBias, bias: p.bias }, { owner }));
32
+ // a multiplier on the sky's ambient, not a fixed hemi intensity: the day-night cycle keeps working (look.lights.set would freeze it)
33
+ if (p.fill !== 1) handles.push(engine.mod('look.lights.hemi.intensity', { owner, mul: p.fill }));
34
+ if (p.ao) handles.push(engine.look.post.add(ao({ enabled: true, radius: p.aoRadius, intensity: p.aoIntensity }), { owner }));
35
+ return {
36
+ remove() { for (const h of handles.splice(0)) h.remove(); },
37
+ describe: () => ({ ...p, texelCm: +shadowTexelCm(p.extent, p.mapSize).toFixed(2) }),
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Bake ambient occlusion into a static code-built geometry standing on flat ground at height `ground` (in the geometry's own space):
43
+ * the ground is an occluder, so the foot of the model darkens where it meets the floor. Draw it with `vertexColors: true`.
44
+ * Cost: once at load (tens of ms for a few thousand vertices), nothing per frame. Detail is per vertex: tessellate big faces first.
45
+ * @param {THREE.BufferGeometry} geometry
46
+ * @param {{ ground?: number, samples?: number, strength?: number, radius?: number }} [o]
47
+ */
48
+ export function groundStatic(geometry, { ground = 0, samples = 32, strength = 0.75, radius } = {}) {
49
+ const floor = new THREE.PlaneGeometry(40, 40).rotateX(-Math.PI / 2).translate(0, ground, 0);
50
+ return bakeVertexAO(geometry, { samples, strength, radius, occluders: [floor] });
51
+ }
@@ -0,0 +1,53 @@
1
+ // @ts-check
2
+ // Demo page for the contact-shadows technique (page /contact-shadows.html). A neutral gray yard at 14:30: a table with a small cup and a ball on
3
+ // it, a crate stack (static, code-built, vertex AO baked), a figure-sized capsule and a wall corner.
4
+ // URL: ?mode=float the engine defaults (70 m shadow box, 4 cm normal bias, full fill): the "small object floats" failure
5
+ // &ao=1 add the screen-space AO pass &probes=1 bake light probes over the yard (bounce light from the wall)
6
+ // Test page for tests/specs/contact-shadows.mjs: window.contactTest = { THREE, points, cs } (points: world spots the spec reads brightness at).
7
+ import { createEngine, sky, fixedCamera, makeMaterial, THREE } from 'threedog';
8
+ import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
9
+ import { applyContactShadows, groundStatic } from './contactShadows.js';
10
+
11
+ const url = new URLSearchParams(location.search), float = url.get('mode') === 'float';
12
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), ui: { loading: false }, saveKey: 'threedog-contact' });
13
+ engine.use(sky({ time: '14:30' }));
14
+ engine.use(fixedCamera({ position: [1.9, 1.6, 2.3], lookAt: [0, 0.55, -0.1] }));
15
+
16
+ const gray = (/** @type {number} */ c, vertexColors = false) => makeMaterial('prop', { color: c, vertexColors });
17
+ const ground = new THREE.Mesh(new THREE.PlaneGeometry(40, 40), makeMaterial('terrain', { color: 0x9a9a9a }));
18
+ ground.rotation.x = -Math.PI / 2;
19
+ ground.receiveShadow = true;
20
+ engine.scene.add(ground);
21
+
22
+ const add = (/** @type {THREE.BufferGeometry} */ g, /** @type {THREE.Material} */ m, x = 0, y = 0, z = 0) => {
23
+ const mesh = new THREE.Mesh(g, m);
24
+ mesh.position.set(x, y, z);
25
+ mesh.castShadow = mesh.receiveShadow = true;
26
+ engine.scene.add(mesh);
27
+ return mesh;
28
+ };
29
+ // the table: top 1.2 x 0.8 at 0.75 m, four legs. Objects sit exactly on their support (y = half height): a 1 cm gap also reads as floating
30
+ add(new THREE.BoxGeometry(1.2, 0.05, 0.8), gray(0xb0b0b0), 0, 0.725, 0);
31
+ for (const [x, z] of [[-0.55, -0.35], [0.55, -0.35], [-0.55, 0.35], [0.55, 0.35]]) add(new THREE.BoxGeometry(0.05, 0.7, 0.05), gray(0x8c8c8c), x, 0.35, z);
32
+ const cup = add(new THREE.CylinderGeometry(0.04, 0.035, 0.1, 24), gray(0xd0d0d0), 0.2, 0.75 + 0.05, 0.1);
33
+ add(new THREE.SphereGeometry(0.07, 24, 16), gray(0xc4c4c4), -0.25, 0.75 + 0.07, -0.1);
34
+ // a small object on the ground, where floating is easiest to see
35
+ const block = add(new THREE.BoxGeometry(0.12, 0.12, 0.12), gray(0xc8c8c8), 1.1, 0.06, 0.6);
36
+ // the crate stack: one static merged geometry with baked vertex AO (darker at the floor and between crates). Tessellated boxes: AO is per vertex
37
+ const crate = (/** @type {number} */ s, /** @type {number} */ x, /** @type {number} */ y, /** @type {number} */ z) => new THREE.BoxGeometry(s, s, s, 6, 6, 6).translate(x, y + s / 2, z);
38
+ const stack = mergeGeometries([crate(0.6, 0, 0, 0), crate(0.6, 0.62, 0, 0.05), crate(0.45, 0.3, 0.6, 0)]);
39
+ if (!float) groundStatic(stack, { ground: 0 });
40
+ add(stack, gray(0xb4b4b4, !float), -1.6, 0, -0.6);
41
+ // a figure-sized capsule and a wall corner (the probes' bounce light shows next to the wall)
42
+ add(new THREE.CapsuleGeometry(0.25, 1.2, 8, 16), gray(0xa8a8a8), 1.4, 0.85, -1.2);
43
+ add(new THREE.BoxGeometry(5, 2.5, 0.2), gray(0xbcbcbc), 0, 1.25, -2.4);
44
+ add(new THREE.BoxGeometry(0.2, 2.5, 4), gray(0xbcbcbc), -2.6, 1.25, -0.5);
45
+
46
+ // the shadow box centers on engine.focus, which the fixed camera puts at its lookAt (the table): the middle of the compact scene
47
+ const cs = float ? null : applyContactShadows(engine, { ao: url.get('ao') === '1' });
48
+ if (url.get('probes') === '1') await engine.bakeProbes({ bounds: { min: [-3, 0.2, -2.2], max: [3, 2, 3] }, spacing: 1.5 });
49
+
50
+ // small objects (base center and half width, m) and open spots on the same surfaces; the spec reads just beside each base on the side away from the sun
51
+ const points = { cup: { at: [0.2, 0.751, 0.1], r: 0.04 }, block: { at: [1.1, 0.001, 0.6], r: 0.06 }, tableOpen: [-0.4, 0.751, 0.3], groundOpen: [-1.0, 0.001, 0.9] };
52
+ Object.assign(window, { engine, contactTest: { THREE, points, cs, cup } });
53
+ engine.start();
@@ -0,0 +1,86 @@
1
+ Day-night grade: light and color grade across the day, with a dark but readable night.
2
+
3
+ # Day-night grade (technique example)
4
+
5
+ A neutral gray scene under one clock: sky, sun / moon, ambient, exposure, a color grade and lamps all keyed by the time of day. Demo:
6
+ `npm run dev` in the engine package, open `/day-night-grade.html` (the day runs in 4 minutes; `?time=17:00` starts at a time). Shots:
7
+ `threedog shot /day-night-grade.html --time 12:00` (and `17:00`, `22:00`). The engine never imports this folder.
8
+
9
+ ## The principle
10
+ A time of day is read from three things at once: the light's color and direction, how dark the shadows are, and how much color is left in
11
+ the picture. Changing only brightness gives an underexposed photo, not evening or night. Every number below is this example's current value
12
+ on a gray scene, given to explain an effect.
13
+
14
+ **Noon is the reference.** At noon `sun 3 x sin(elevation) + ambient 1.1` is close to pi, the level where mid-tone albedos show at their own
15
+ value on three's AgX curve (recipe 52). Grade neutral, exposure 1. Tune the palette here first; every other time is a deviation from it.
16
+
17
+ **Dusk: warm without oversaturation.**
18
+ - Put the warmth in the **light** (sun color `0xffa264`, horizon `0xdc9c6c`), not only in the grade: the lit sides turn warm and the shadow
19
+ sides stay cool, and that contrast is what reads as evening (warm key / cool fill).
20
+ - Drop the ambient (0.7) as the sun drops, so shadows deepen and take the sky's blue.
21
+ - In the grade, raise temperature and **lower saturation** (0.9): warm light on warm-ish albedos already adds chroma; a saturation boost on
22
+ top clips oranges into neon. The demo's 17:00 shot measures saturation 0.14 on a gray scene.
23
+ - Lamps fade in before dark (about 16:40 here), the way people switch them on.
24
+
25
+ **Night: dark but readable.**
26
+ - **Moonlight** is a weak, blue-white key (`0x8fa4d4`, 0.35). It still casts a direction, so forms read.
27
+ - **Ambient floor** (the example uses 0.26): keep some. With none, faces away from the moon are pure black and the player sees nothing.
28
+ - **Exposure** lifts a little (1.15) but nowhere near day: the demo's night mean luminance is about half of noon (0.35 vs 0.69).
29
+ - **The grade cools and desaturates** (temperature -0.45, saturation 0.72): eyes lose color in the dark (the Purkinje shift), so less color
30
+ reads as night even at a readable brightness. A touch of contrast (1.06) keeps silhouettes.
31
+ - **Lamps carry the scene**: warm pools of light where the player goes, emissive windows and lamp heads that read as light sources. Warm
32
+ lamps against a cool night is the strongest night cue.
33
+
34
+ How to judge it: shoot each time of day at the game's real camera (`threedog shot --time`) and read luminance, saturation, the "dark" area
35
+ and your own eyes. Common failures: night = noon with lower exposure (daytime colors, an underexposed photo); night with no ambient (crushed
36
+ black; the shot reports the "dark" area); dusk = saturation up (neon oranges).
37
+
38
+ ## Plain three.js
39
+ - Tone and exposure: `renderer.toneMapping = THREE.AgXToneMapping` and `renderer.toneMappingExposure`
40
+ ([WebGLRenderer](https://threejs.org/docs/#api/en/renderers/WebGLRenderer), [webgl_tonemapping](https://threejs.org/examples/#webgl_tonemapping)).
41
+ - Light over time: interpolate a few keyframes per frame and write `DirectionalLight.color` / `.intensity`, `HemisphereLight` colors and
42
+ intensity, `scene.fog.color` and `scene.background` ([Color.lerpColors](https://threejs.org/docs/#api/en/math/Color)).
43
+ - Grade: a final pass in `EffectComposer` — a `ShaderPass` that shifts temperature / saturation / contrast, or `LUTPass` with a 3D LUT
44
+ ([webgl_postprocessing_3dlut](https://threejs.org/examples/#webgl_postprocessing_3dlut)).
45
+ - Lamps: `PointLight` / `SpotLight` intensity and `material.emissiveIntensity`, faded by a daylight value, never toggled.
46
+
47
+ ## Style routes
48
+ - **Naturalistic**: warm sun at dusk, a blue moon, a cooled and desaturated night grade, lamps as the night's light. One full-screen grade pass.
49
+ - **Pastel / cozy**: night kept lighter (more ambient, more exposure) and dusk pinker. Same cost.
50
+ - **Horror**: a lower ambient floor, lamps carry everything; darkness is part of play. Same cost, often more lamps.
51
+ - **Stylized flat**: skip the grade and key only the sky and lamps; the palette swap does the work. No post pass.
52
+ - **Pixel / palette-limited**: swap whole palettes or a small set of LUTs at fixed times instead of continuous curves. One lookup.
53
+
54
+ ## The engine helper (optional convenience)
55
+ `dayNightGrade.js` holds one clock and four tables, all keyed by `engine.calendar.timeOfDay` (0 midnight, 0.5 noon). `threedog examples pull
56
+ day-night-grade` copies it; replace its colors with the ones your DESIGN.md look names.
57
+
58
+ | Table | Read by | What it sets |
59
+ |---|---|---|
60
+ | `SKY` = `style.sky.keyframes` | the sky module | dome zenith / horizon, fog (= horizon), sun color + intensity (the moon at night), ambient (hemisphere and environment map) |
61
+ | `EXPOSURE` = `style.exposure` | the sky module | `renderer.toneMappingExposure` |
62
+ | `GRADE` | `followDayNight` each frame | the `lut()` post effect: temperature, saturation, contrast (`look.post`, owner `day-night`) |
63
+ | `LAMPS` | `followDayNight` each frame | the game's lamps: point-light intensity and emissive strength, by `calendar.daylight` (`LAMPS.offAbove: 0.35`) |
64
+
65
+ `dayNightStyle()` returns the first two plus the `lut` effect as a style fragment: `createEngine({ style: [yourStyle, dayNightStyle()] })`.
66
+ `followDayNight(engine, { lamps })` writes the grade and lamps; `sample(rows, t)` is the interpolation. Keyframes interpolate linearly and
67
+ wrap at midnight, so the first and last rows are the same night. The demo spec checks that ground under a lamp is over 1.3x open ground at 22:00.
68
+
69
+ Cost (1280x720, laptop GPU, this demo; median of 120 frames):
70
+ - Keyframes, exposure, lamp writes: no measurable cost (uniform writes).
71
+ - The `lut` grade pass: about **+1.5 ms** a frame (22:00: 5.8 ms with it, 4.3 ms without), mostly the post chain's full-screen pass; other
72
+ `ldr` effects (vignette, grain) fuse into the same pass for free.
73
+ - Point lights: each one adds to every lit material's shader. Keep `distance` short; for many lamps use `engine.lightPool` (recipe 09).
74
+ - `followDayNight` writes the grade only when it moved (sum of changes > 0.004), so the fused shader is not refreshed every frame.
75
+
76
+ Rules (correctness):
77
+ - Never toggle `light.visible` (or add / remove lights) as the day turns: a light-count change recompiles every lit material. Write intensity.
78
+ - Under a cycle, adjust brightness through the keyframes or `engine.mod('look.lights.hemi.intensity' | 'look.lights.sun.intensity', { mul })`; `look.lights.set` replaces
79
+ the keyframe value. Fixing night brightness with `look.lights.set({ hemi })` freezes the cycle; use the keyframe ambient, or
80
+ `engine.mod('look.lights.hemi.intensity', { mul })` for a place (a cave).
81
+ - Lamps and gameplay read `calendar.daylight` / `isDay` / `between`, never the clock text (`if (clock === '18:00')` breaks other day
82
+ lengths; recipe 08).
83
+ - `lut()` comes from `@threedog/post-effects`; install it in the game.
84
+
85
+ Sources: written for this engine from its sky contract (recipe 08), the three.js `toneMappingExposure` / AgX docs and common film-grading
86
+ practice (warm key / cool fill, Purkinje shift at night); no code copied.