threedog 0.2.0 → 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 (596) 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 +83 -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 +190 -57
  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 +43 -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 +128 -0
  58. package/core/gridLoad.js +20 -0
  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 +101 -37
  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 +65 -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 +89 -97
  124. package/docs/API.md +32 -28
  125. package/docs/CODEMAP.md +224 -149
  126. package/docs/COMMANDS.md +57 -34
  127. package/docs/CONVENTIONS.md +92 -30
  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 +12 -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 +41 -25
  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 +65 -62
  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 +31 -29
  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 +30 -13
  172. package/docs/api/triggers.md +5 -10
  173. package/docs/api/vegetation.md +12 -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 +71 -59
  180. package/docs/recipes/02-npc.md +46 -29
  181. package/docs/recipes/03-items-pickups.md +38 -24
  182. package/docs/recipes/04-quests.md +34 -27
  183. package/docs/recipes/05-props-bake.md +154 -18
  184. package/docs/recipes/06-clock-events.md +100 -52
  185. package/docs/recipes/07-flow-scenes-pause.md +41 -10
  186. package/docs/recipes/08-weather-sky.md +146 -37
  187. package/docs/recipes/09-style.md +218 -0
  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 +34 -10
  191. package/docs/recipes/14-custom-module.md +65 -34
  192. package/docs/recipes/15-perf.md +35 -6
  193. package/docs/recipes/16-dev-bridge.md +65 -41
  194. package/docs/recipes/18-world.md +21 -8
  195. package/docs/recipes/19-shooting-picking.md +12 -11
  196. package/docs/recipes/20-content-actions-save.md +63 -25
  197. package/docs/recipes/21-camera.md +49 -16
  198. package/docs/recipes/22-shop-gold.md +18 -18
  199. package/docs/recipes/23-ops.md +17 -11
  200. package/docs/recipes/26-ui-parts.md +61 -12
  201. package/docs/recipes/27-net.md +12 -6
  202. package/docs/recipes/28-terrain.md +35 -2
  203. package/docs/recipes/29-grid.md +71 -33
  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 +27 -4
  208. package/docs/recipes/35-style-from-reference.md +115 -51
  209. package/docs/recipes/36-sky-ground-plant-looks.md +37 -35
  210. package/docs/recipes/37-terrain-look-hooks.md +37 -15
  211. package/docs/recipes/38-environment-look-hooks.md +64 -48
  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 +3 -3
  215. package/docs/recipes/43-shader-patches-surface-looks.md +171 -74
  216. package/docs/recipes/44-water-weather-look-hooks.md +30 -21
  217. package/docs/recipes/45-cascaded-shadows.md +17 -8
  218. package/docs/recipes/46-blender-art-route.md +4 -4
  219. package/docs/recipes/47-island-snow-backdrop.md +11 -10
  220. package/docs/recipes/48-make-material.md +11 -6
  221. package/docs/recipes/49-game-module-contract.md +46 -33
  222. package/docs/recipes/50-own-renderer.md +2 -2
  223. package/docs/recipes/51-capability-catalog.md +4 -4
  224. package/docs/recipes/52-look.md +228 -54
  225. package/docs/recipes/53-ground-up-close.md +58 -0
  226. package/docs/recipes/54-three-idioms.md +88 -0
  227. package/docs/recipes/55-mods-time-wrap.md +112 -0
  228. package/docs/recipes/56-webgpu-tsl.md +260 -0
  229. package/docs/recipes/57-control.md +65 -0
  230. package/docs/recipes/58-input.md +57 -0
  231. package/docs/recipes/59-depth-post-effects.md +83 -0
  232. package/docs/recipes/60-judge-the-picture.md +55 -0
  233. package/examples/action/.threedog/content-index.json +1 -0
  234. package/examples/action/GAMEMAP.md +17 -13
  235. package/examples/action/assets.js +8 -0
  236. package/examples/action/content/actions.js +1 -1
  237. package/examples/action/content/audio.js +5 -5
  238. package/examples/action/look.js +1 -1
  239. package/examples/action/main.js +10 -13
  240. package/examples/action/models.js +24 -23
  241. package/examples/pullable.json +111 -0
  242. package/examples/rc2d/.threedog/content-index.json +1 -0
  243. package/examples/rc2d/GAMEMAP.md +83 -0
  244. package/examples/rc2d/README.md +52 -0
  245. package/examples/rc2d/main.js +63 -0
  246. package/examples/rc2d/rc2d.js +197 -0
  247. package/examples/rc2d/shaders.js +144 -0
  248. package/examples/sheepisland/.threedog/content-index.json +1 -0
  249. package/examples/sheepisland/GAMEMAP.md +13 -11
  250. package/examples/sheepisland/assets.js +5 -0
  251. package/examples/sheepisland/main.js +17 -12
  252. package/examples/sheepisland/style/index.js +6 -6
  253. package/examples/styletest/.threedog/content-index.json +1 -0
  254. package/examples/styletest/GAMEMAP.md +15 -16
  255. package/examples/styletest/assets.js +6 -0
  256. package/examples/styletest/content/npcs.js +1 -1
  257. package/examples/styletest/content/templates.js +1 -1
  258. package/examples/styletest/content/vegetation.js +1 -1
  259. package/examples/styletest/look.js +1 -1
  260. package/examples/styletest/main.js +18 -17
  261. package/examples/styletest/models.js +1 -1
  262. package/examples/styletest/params.js +3 -3
  263. package/examples/techniques/contact-shadows/README.md +92 -0
  264. package/examples/techniques/contact-shadows/contactShadows.js +51 -0
  265. package/examples/techniques/contact-shadows/main.js +53 -0
  266. package/examples/techniques/day-night-grade/README.md +86 -0
  267. package/examples/techniques/day-night-grade/dayNightGrade.js +76 -0
  268. package/examples/techniques/day-night-grade/main.js +51 -0
  269. package/examples/techniques/interior-light/README.md +103 -0
  270. package/examples/techniques/interior-light/interiorLight.js +45 -0
  271. package/examples/techniques/interior-light/main.js +124 -0
  272. package/examples/techniques/modular-building/README.md +125 -0
  273. package/examples/techniques/modular-building/kit.js +426 -0
  274. package/examples/techniques/modular-building/main.js +47 -0
  275. package/examples/techniques/night-lights/README.md +94 -0
  276. package/examples/techniques/night-lights/main.js +70 -0
  277. package/examples/techniques/night-lights/nightLights.js +91 -0
  278. package/examples/techniques/outlines-and-rim/README.md +59 -0
  279. package/examples/techniques/outlines-and-rim/main.js +84 -0
  280. package/examples/techniques/outlines-and-rim/outlines.js +64 -0
  281. package/examples/techniques/procedural-animation/README.md +77 -0
  282. package/examples/techniques/procedural-animation/creature.js +44 -0
  283. package/examples/techniques/procedural-animation/main.js +45 -0
  284. package/examples/techniques/procedural-animation/proceduralAnim.js +118 -0
  285. package/examples/techniques/procedural-surface/README.md +67 -0
  286. package/examples/techniques/procedural-surface/main.js +103 -0
  287. package/examples/techniques/procedural-surface/surface.js +120 -0
  288. package/examples/techniques/stylized-shading/README.md +75 -0
  289. package/examples/techniques/stylized-shading/main.js +93 -0
  290. package/examples/techniques/stylized-shading/shading.js +131 -0
  291. package/examples/techniques/sun-and-key-light/README.md +135 -0
  292. package/examples/techniques/sun-and-key-light/keyLight.js +53 -0
  293. package/examples/techniques/sun-and-key-light/main.js +95 -0
  294. package/examples/techniques/wet-road/README.md +99 -0
  295. package/examples/techniques/wet-road/main.js +68 -0
  296. package/examples/techniques/wet-road/wetRoad.js +209 -0
  297. package/examples/webgpu-tsl/.threedog/content-index.json +1 -0
  298. package/examples/webgpu-tsl/GAMEMAP.md +84 -0
  299. package/examples/webgpu-tsl/README.md +42 -0
  300. package/examples/webgpu-tsl/main.js +21 -0
  301. package/examples/webgpu-tsl/tslScene.js +75 -0
  302. package/examples/world/.threedog/content-index.json +1 -0
  303. package/examples/world/GAMEMAP.md +22 -15
  304. package/examples/world/art/humanoid.js +42 -0
  305. package/examples/world/art/index.js +11 -0
  306. package/examples/world/art/models.js +58 -0
  307. package/examples/world/art/shapes.js +9 -0
  308. package/examples/world/assets.js +6 -0
  309. package/examples/world/content/audio.js +5 -5
  310. package/examples/world/content/npcs.js +2 -2
  311. package/examples/world/content/props.js +1 -1
  312. package/examples/world/content/rules.js +1 -1
  313. package/examples/world/content/templates.js +1 -1
  314. package/examples/world/content/vegetation.js +1 -1
  315. package/examples/world/main.js +17 -13
  316. package/examples/world/style/index.js +61 -0
  317. package/examples/world/style/plugins/10-bloom.js +5 -0
  318. package/index.d.ts +50 -45
  319. package/index.js +27 -22
  320. package/llms.txt +20 -12
  321. package/modules/ambience/Ambience.js +34 -23
  322. package/modules/calendar/Calendar.js +163 -0
  323. package/modules/calendar/contract.js +21 -0
  324. package/modules/calendar/index.js +81 -0
  325. package/modules/{sky → calendar}/schedule.js +17 -16
  326. package/modules/calendar/seasons.js +55 -0
  327. package/modules/camera/FirstPersonCamera.js +6 -15
  328. package/modules/camera/FixedCamera.js +33 -15
  329. package/modules/camera/FollowCamera.js +90 -16
  330. package/modules/camera/RtsCamera.js +18 -17
  331. package/modules/camera/common.js +70 -19
  332. package/modules/camera/contract.js +17 -0
  333. package/modules/camera/projection.js +11 -24
  334. package/modules/characters/Character.js +196 -59
  335. package/modules/characters/NPC.js +87 -36
  336. package/modules/characters/assetModel.js +27 -8
  337. package/modules/characters/behaviors.js +2 -1
  338. package/modules/characters/contract.js +13 -0
  339. package/modules/characters/footsteps.js +1 -1
  340. package/modules/characters/index.js +87 -49
  341. package/modules/characters/moveHelpers.js +4 -5
  342. package/modules/characters/movers/common.js +97 -19
  343. package/modules/characters/movers/manual.js +20 -0
  344. package/modules/characters/movers/rapier.js +19 -16
  345. package/modules/characters/movers/simple.js +14 -11
  346. package/modules/characters/movers/support.js +172 -0
  347. package/modules/characters/npcAvoid.js +47 -42
  348. package/modules/characters/npcSim.js +12 -8
  349. package/modules/characters/npcView.js +44 -16
  350. package/modules/characters/pathAsync.js +7 -3
  351. package/modules/characters/playerStrings.js +4 -3
  352. package/modules/characters/proceduralRig.js +46 -10
  353. package/modules/characters/useModel.js +1 -1
  354. package/modules/characters/vehicle.contract.js +21 -0
  355. package/modules/characters/walkTo.js +21 -7
  356. package/modules/collision/Collision.js +65 -25
  357. package/modules/collision/grid.js +8 -6
  358. package/modules/content/explain.js +2 -2
  359. package/modules/content/fields.js +102 -0
  360. package/modules/content/ids.js +8 -6
  361. package/modules/content/index.js +97 -28
  362. package/modules/content/loader.js +45 -33
  363. package/modules/content/models.js +11 -40
  364. package/modules/content/packs.js +6 -5
  365. package/modules/content/parts.js +41 -0
  366. package/modules/content/props.js +16 -9
  367. package/modules/content/rules.js +58 -0
  368. package/modules/content/stages.js +80 -0
  369. package/modules/content/templates.js +121 -30
  370. package/modules/debug/DebugPanel.js +24 -17
  371. package/modules/flow/contract.js +16 -0
  372. package/modules/flow/index.js +21 -15
  373. package/modules/gameplay/Container.js +41 -32
  374. package/modules/gameplay/Containers.js +30 -15
  375. package/modules/gameplay/Dialogue.js +113 -55
  376. package/modules/gameplay/Interactions.js +193 -67
  377. package/modules/gameplay/Inventory.js +69 -73
  378. package/modules/gameplay/Quests.js +75 -39
  379. package/modules/gameplay/boxOps.js +3 -3
  380. package/modules/gameplay/dialogue.contract.js +21 -0
  381. package/modules/gameplay/dialogueBox.js +4 -2
  382. package/modules/gameplay/dialogueBubbles.js +116 -0
  383. package/modules/gameplay/interactionPrompt.js +4 -1
  384. package/modules/gameplay/interactions.contract.js +16 -0
  385. package/modules/gameplay/inventory.contract.js +23 -0
  386. package/modules/gameplay/inventoryOps.js +18 -16
  387. package/modules/gameplay/pickups.js +268 -85
  388. package/modules/gameplay/questLog.js +4 -4
  389. package/modules/gameplay/quests.contract.js +17 -0
  390. package/modules/grid/Grid.js +92 -50
  391. package/modules/grid/Layer.js +14 -13
  392. package/modules/grid/index.js +60 -36
  393. package/modules/grid/ops.js +20 -18
  394. package/modules/grid/preview.js +15 -16
  395. package/modules/grid/strings.js +12 -0
  396. package/modules/grid/tiles.js +6 -5
  397. package/modules/hlod/index.js +51 -19
  398. package/modules/hud/index.js +35 -20
  399. package/modules/hud/parts.js +20 -7
  400. package/modules/level/heightfield.js +3 -1
  401. package/modules/level/index.js +45 -20
  402. package/modules/level/nodes.js +4 -3
  403. package/modules/lights/index.js +42 -18
  404. package/modules/music/Music.js +38 -21
  405. package/modules/music/rules.js +1 -1
  406. package/modules/nav/index.js +48 -42
  407. package/modules/net/Client.js +13 -6
  408. package/modules/net/Host.js +19 -5
  409. package/modules/net/Net.js +2 -1
  410. package/modules/net/index.js +13 -8
  411. package/modules/net/sync.js +9 -8
  412. package/modules/net/transports.js +77 -27
  413. package/modules/particles/Particles.js +23 -14
  414. package/modules/particles/contract.js +17 -0
  415. package/modules/particles/effect.js +39 -11
  416. package/modules/photo/Photo.js +53 -36
  417. package/modules/rigid/RigidBodies.js +194 -32
  418. package/modules/rigid/Vehicles.js +18 -15
  419. package/modules/rigid/sync.js +62 -17
  420. package/modules/settings/Settings.js +57 -52
  421. package/modules/settings/apply.js +38 -3
  422. package/modules/settings/sections.js +5 -3
  423. package/modules/settings/strings.js +3 -2
  424. package/modules/settings/view.js +5 -3
  425. package/modules/sky/Sky.js +88 -176
  426. package/modules/sky/cascades.js +86 -25
  427. package/modules/sky/cascades.tsl.js +82 -0
  428. package/modules/sky/clouds.js +34 -19
  429. package/modules/sky/domeLayers.js +30 -15
  430. package/modules/sky/environment.js +83 -13
  431. package/modules/sky/fog.js +140 -95
  432. package/modules/sky/frame.js +112 -44
  433. package/modules/sky/look.js +22 -19
  434. package/modules/sky/lookFog.js +48 -52
  435. package/modules/sky/lookShadow.js +53 -41
  436. package/modules/sky/lookSky.js +82 -21
  437. package/modules/sky/season.js +21 -0
  438. package/modules/sky/shader.js +41 -19
  439. package/modules/sky/shadow.js +44 -20
  440. package/modules/sky/skyModule.js +45 -33
  441. package/modules/sky/tint.js +61 -0
  442. package/modules/terrain/ChunkManager.js +175 -108
  443. package/modules/terrain/chunkJob.js +1 -1
  444. package/modules/terrain/chunkQueries.js +6 -4
  445. package/modules/terrain/index.js +105 -50
  446. package/modules/terrain/look.js +83 -0
  447. package/modules/terrain/lookGround.js +21 -16
  448. package/modules/terrain/terrainDefaults.js +1 -1
  449. package/modules/terrain/terrainEdit.js +18 -20
  450. package/modules/terrain/terrainGen.js +5 -3
  451. package/modules/terrain/terrainIsland.js +5 -4
  452. package/modules/terrain/terrainShape.js +12 -12
  453. package/modules/terrain/terrainShapeMain.js +8 -7
  454. package/modules/terrain/terrainTexture.js +21 -19
  455. package/modules/timeline/Timeline.js +95 -43
  456. package/modules/timeline/Tween.js +18 -10
  457. package/modules/timeline/letterbox.js +2 -2
  458. package/modules/timeline/shots.js +5 -1
  459. package/modules/triggers/index.js +107 -76
  460. package/modules/vegetation/Vegetation.js +190 -102
  461. package/modules/vegetation/densityMap.js +62 -0
  462. package/modules/vegetation/groundChunks.js +52 -58
  463. package/modules/vegetation/index.js +31 -10
  464. package/modules/vegetation/look.js +119 -0
  465. package/modules/vegetation/lookWind.js +71 -10
  466. package/modules/vegetation/modelGeometry.js +3 -2
  467. package/modules/vegetation/nearFade.js +45 -0
  468. package/modules/water/Water.js +65 -27
  469. package/modules/water/look.js +29 -18
  470. package/modules/water/surface.js +64 -25
  471. package/modules/water/surfaceDefaults.js +3 -0
  472. package/modules/weather/Weather.js +62 -104
  473. package/modules/weather/look.js +1 -2
  474. package/modules/weather/particles.js +24 -9
  475. package/modules/weather/strings.js +2 -2
  476. package/modules/weather/weatherLook.js +135 -0
  477. package/modules/world/World.js +24 -7
  478. package/modules/world/explain.js +1 -1
  479. package/modules/world/index.js +18 -4
  480. package/modules/world/persist.js +62 -2
  481. package/modules/world/pos.js +3 -2
  482. package/modules/world/records.js +8 -6
  483. package/modules/world/sim.js +60 -20
  484. package/modules/world/simFar.js +4 -3
  485. package/modules/world/state.js +3 -2
  486. package/modules/world/thingSource.js +1 -1
  487. package/modules/world/views.js +7 -5
  488. package/package.json +8 -3
  489. package/presets.js +41 -27
  490. package/render/PostFX.js +145 -120
  491. package/render/backend.js +440 -0
  492. package/render/detail.js +150 -45
  493. package/render/effects.js +130 -38
  494. package/render/engineUniforms.js +10 -1
  495. package/render/fuse.js +5 -4
  496. package/render/fx/cloudShadow.tsl.js +16 -0
  497. package/render/fx/detail.tsl.js +66 -0
  498. package/render/fx/index.js +26 -0
  499. package/render/fx/lighting.tsl.js +28 -0
  500. package/render/fx/nodeErrors.tsl.js +68 -0
  501. package/render/fx/noise.tsl.js +12 -0
  502. package/render/fx/objectOrigin.tsl.js +42 -0
  503. package/render/fx/particles.tsl.js +139 -0
  504. package/render/fx/patchNodes.tsl.js +403 -0
  505. package/render/fx/postWebGPU.tsl.js +158 -0
  506. package/render/fx/season.tsl.js +13 -0
  507. package/render/fx/sky.tsl.js +260 -0
  508. package/render/fx/uniforms.tsl.js +67 -0
  509. package/render/fx/water.tsl.js +53 -0
  510. package/render/fx/wind.tsl.js +22 -0
  511. package/render/fxNumbers.js +36 -0
  512. package/render/hotGlsl.js +24 -0
  513. package/render/lighting.js +66 -14
  514. package/render/lights.js +223 -4
  515. package/render/lookGlow.js +139 -0
  516. package/render/lookSurface.js +99 -36
  517. package/render/materials.js +71 -52
  518. package/render/modeling.js +73 -0
  519. package/render/ownFrame.js +76 -0
  520. package/render/patches.js +311 -34
  521. package/render/postLook.js +124 -46
  522. package/render/postWebGL.js +197 -0
  523. package/render/probes.js +231 -0
  524. package/render/shaderErrors.js +154 -0
  525. package/render/slots.js +165 -0
  526. package/render/surface.js +53 -17
  527. package/render/terms.js +211 -0
  528. package/render/uniformDecl.js +3 -2
  529. package/types/common.d.ts +2 -2
  530. package/types/core.d.ts +620 -244
  531. package/types/gameplay.d.ts +494 -318
  532. package/types/generated/core/Audio.d.ts +26 -42
  533. package/types/generated/core/Batching.d.ts +6 -2
  534. package/types/generated/core/Budget.d.ts +2 -8
  535. package/types/generated/core/DebugOverrides.d.ts +44 -3
  536. package/types/generated/core/I18n.d.ts +2 -2
  537. package/types/generated/core/Input.d.ts +102 -31
  538. package/types/generated/core/Ops.d.ts +31 -0
  539. package/types/generated/core/Random.d.ts +2 -2
  540. package/types/generated/core/Saves.d.ts +10 -2
  541. package/types/generated/core/Stream.d.ts +1 -1
  542. package/types/generated/core/Threads.d.ts +4 -1
  543. package/types/generated/core/Views.d.ts +0 -1
  544. package/types/generated/core/audioVoice.d.ts +17 -9
  545. package/types/generated/core/control.d.ts +55 -0
  546. package/types/generated/core/session.d.ts +2 -1
  547. package/types/generated/modules/ambience/Ambience.d.ts +0 -9
  548. package/types/generated/modules/calendar/Calendar.d.ts +84 -0
  549. package/types/generated/modules/calendar/index.d.ts +10 -0
  550. package/types/generated/modules/debug/DebugPanel.d.ts +2 -2
  551. package/types/generated/modules/grid/Grid.d.ts +61 -25
  552. package/types/generated/modules/grid/Layer.d.ts +5 -5
  553. package/types/generated/modules/grid/index.d.ts +29 -17
  554. package/types/generated/modules/music/Music.d.ts +5 -3
  555. package/types/generated/modules/net/index.d.ts +3 -3
  556. package/types/generated/modules/net/transports.d.ts +12 -3
  557. package/types/generated/modules/particles/Particles.d.ts +1 -1
  558. package/types/generated/modules/sky/Sky.d.ts +12 -104
  559. package/types/generated/modules/sky/skyModule.d.ts +1 -1
  560. package/types/generated/modules/timeline/Timeline.d.ts +8 -6
  561. package/types/generated/modules/weather/Weather.d.ts +17 -18
  562. package/types/generated/modules/weather/weatherLook.d.ts +12 -0
  563. package/types/generated/modules/world/World.d.ts +18 -3
  564. package/types/generated/render/PostFX.d.ts +67 -30
  565. package/types/generated/render/materials.d.ts +26 -20
  566. package/types/generated/render/modeling.d.ts +30 -0
  567. package/types/generated/render/patches.d.ts +16 -2
  568. package/types/generated/ui/UI.d.ts +6 -3
  569. package/types/nav.d.ts +6 -0
  570. package/types/physics.d.ts +137 -44
  571. package/types/style.d.ts +125 -92
  572. package/types/tsl.d.ts +86 -0
  573. package/types/world.d.ts +164 -110
  574. package/ui/Focus.js +25 -14
  575. package/ui/LoadingScreen.js +1 -1
  576. package/ui/Parts.js +27 -11
  577. package/ui/UI.js +20 -10
  578. package/ui/cursor.js +115 -0
  579. package/ui/defaults.js +15 -11
  580. package/ui/theme.js +9 -6
  581. package/ui/touchPart.js +1 -1
  582. package/core/claims.js +0 -51
  583. package/core/look/layers.js +0 -136
  584. package/core/renamed.js +0 -21
  585. package/docs/api/entities.md +0 -61
  586. package/docs/recipes/09-style-pack.md +0 -234
  587. package/examples/styletest/overrides.js +0 -33
  588. package/examples/styletest/panel.js +0 -135
  589. package/modules/entities/Entities.js +0 -243
  590. package/modules/entities/build.js +0 -25
  591. package/modules/entities/index.js +0 -4
  592. package/modules/sky/calendar.js +0 -80
  593. package/modules/sky/layers.js +0 -69
  594. package/modules/terrain/chunkLevels.js +0 -40
  595. package/modules/terrain/mountTerrain.js +0 -32
  596. package/modules/world/cells.js +0 -42
@@ -1,12 +1,13 @@
1
1
  // @ts-check
2
- // Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/acceptance-sheepisland.md).
2
+ // Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/done/acceptance-sheepisland.md).
3
3
  // A meadow with a river, round trees, a wheat field and a flock of sheep on an island with a ragged rim, over a pale backdrop with no horizon.
4
4
  // Parameters (params.js): time day | dusk | night, weather clear | snow, view overview | flock | field | river | rim.
5
5
  // main.js holds wiring only: modules, the island's terrain functions, view switching and the snow-to-winter link. Objects are content (rule R33),
6
- // the look is the style pack in style/.
6
+ // the look is the style in style/.
7
7
  import { params, VIEW_NAMES } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
8
8
  import { createEngine, openWorld, presets, content, fixedCamera } from '../../index.js';
9
- import style, { assets } from './style/index.js';
9
+ import style from './style/index.js';
10
+ import packs from './assets.js';
10
11
  import data from './content/index.js';
11
12
  import { VIEWS } from './views.js';
12
13
 
@@ -14,12 +15,16 @@ import { VIEWS } from './views.js';
14
15
  // Every function runs in terrain workers: pure, only its parameters and Math (recipe 28 §1).
15
16
  const island = {
16
17
  resolution: 48, // 64 m chunk / 48 = 1.33 m cells: the rim is cut along cells, so finer cells give a finer brushed edge (recipe 42 §4)
18
+ // the river's centre line z = amp * sin(x * freq) + shift: one set of numbers both functions read (n.params), so the dip and the river
19
+ // ground type cannot drift apart
20
+ params: { river: { amp: 6, freq: 0.09, shift: 2, dip: 3.2, wet: 2.4 } },
17
21
  height: (x, z, n) => {
18
- const d = Math.abs(z - (6 * Math.sin(x * 0.09) + 2)); // distance to the river's centre line
19
- return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d < 3.2 ? (1 - d / 3.2) * 0.6 : 0); // a gentle meadow, a shallow dip for the river
22
+ const r = n.params.river, d = Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)); // distance to the river's centre line
23
+ return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d < r.dip ? (1 - d / r.dip) * 0.6 : 0); // a gentle meadow, a shallow dip for the river
20
24
  },
21
- groundType: (x, z) => {
22
- if (Math.abs(z - (6 * Math.sin(x * 0.09) + 2)) < 2.4) return 'river';
25
+ groundType: (x, z, h, slope, n) => {
26
+ const r = n.params.river;
27
+ if (Math.abs(z - (r.amp * Math.sin(x * r.freq) + r.shift)) < r.wet) return 'river';
23
28
  const fx = (x - 14) / 9.5, fz = (z + 13) / 6.5; // the wheat field: an ellipse north-east of the river
24
29
  return fx * fx + fz * fz < 1 ? 'wheat' : 'grass';
25
30
  },
@@ -35,19 +40,19 @@ const island = {
35
40
 
36
41
  // ---------- 2. Engine: own style, open-world preset with a fixed sky; a two-season calendar so snow can turn the island white ----------
37
42
  const WINTER_DAY = 1001; // seasons last 1000 days each, so the season never blends towards the next one (it does over the last 20%)
38
- const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
43
+ const engine = createEngine({ bindings: { ...presets.bindings.debug }, canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
39
44
  ui: { loading: { title: 'sheep island' } } });
40
45
  engine.use(openWorld({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
41
- sky: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
46
+ calendar: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
42
47
  weather: { ...presets.weather.temperate, start: 'clear' }, autoWeather: false }), content());
43
- engine.assets.manifest(assets);
48
+ engine.assets.manifest(packs);
44
49
  engine.content.load(data);
45
50
 
46
51
  // ---------- 3. Snow means winter: the engine's season tint (style.seasons.winter) whitens foliage and ground ----------
47
52
  // The weather module sends no change event and a weather has no ground cover of its own, so the calendar day follows the weather each frame.
48
53
  engine.onFrame(() => {
49
54
  const day = engine.weather?.name === 'snow' ? WINTER_DAY : 1;
50
- if (engine.sky.day !== day) engine.sky.day = day;
55
+ if (engine.calendar.day !== day) engine.calendar.day = day;
51
56
  });
52
57
 
53
58
  // ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
@@ -63,7 +68,7 @@ engine.ops.define('sheepisland.view', {
63
68
  },
64
69
  reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
65
70
  });
66
- engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.sky.season, weather: engine.weather?.name }));
71
+ engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.calendar.season, weather: engine.weather?.name }));
67
72
  engine.events.on('engine:ready', () => engine.ops.run('sheepisland.view', { name: params.view }));
68
73
  if (params.badView) console.warn(`sheepisland: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
69
74
 
@@ -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
@@ -2,7 +2,7 @@
2
2
  export default {
3
3
  guide: {
4
4
  name: 'Guide',
5
- colors: { body: 0x4f6d8f, legs: 0x5b4a3a, hair: 0xd8d4cc },
5
+ model: 'humanoid', colors: { body: 0x4f6d8f, legs: 0x5b4a3a, hair: 0xd8d4cc },
6
6
  start: { place: 'stage', x: 2.5, z: 4 }, behavior: 'wander', mind: { radius: 0 },
7
7
  },
8
8
  };
@@ -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.characters.createPlayer({ ...presets.player.thirdPerson, spawn: { x: stage.x + 0.5, z: stage.z + 6 } });
45
+ engine.assets.manifest(packs); // assets.js: the world example's trees / rocks and the test models content/templates.js uses
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();