threedog 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "threedog",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Web 3D game engine on three.js for large low-poly worlds: core + modules + style packs, built to be driven by an AI",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/penstic123-code/ThreeDog.js-Game-Engine.git",
9
+ "directory": "packages/engine"
10
+ },
11
+ "homepage": "https://github.com/penstic123-code/ThreeDog.js-Game-Engine#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/penstic123-code/ThreeDog.js-Game-Engine/issues"
14
+ },
15
+ "engines": {
16
+ "node": ">=20.11"
17
+ },
18
+ "type": "module",
19
+ "main": "./index.js",
20
+ "types": "./index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./index.d.ts",
24
+ "default": "./index.js"
25
+ },
26
+ "./error-hints": "./core/errorHints.js",
27
+ "./worker": {
28
+ "types": "./types/worker.d.ts",
29
+ "default": "./core/threadServe.js"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "files": [
34
+ "index.js",
35
+ "index.d.ts",
36
+ "presets.js",
37
+ "core",
38
+ "modules",
39
+ "render",
40
+ "ui",
41
+ "types",
42
+ "docs",
43
+ "examples",
44
+ "CHANGELOG.md",
45
+ "llms.txt"
46
+ ],
47
+ "scripts": {
48
+ "dev": "vite",
49
+ "build": "vite build",
50
+ "preview": "vite preview",
51
+ "test": "threedog test",
52
+ "map": "threedog map"
53
+ },
54
+ "peerDependencies": {
55
+ "three": "^0.187.0"
56
+ },
57
+ "devDependencies": {
58
+ "vite": "^8.3.5"
59
+ },
60
+ "dependencies": {
61
+ "@dimforge/rapier3d-compat": "^0.21.0",
62
+ "@recast-navigation/core": "^0.44.0",
63
+ "@recast-navigation/generators": "^0.44.0",
64
+ "@recast-navigation/three": "^0.44.0",
65
+ "@types/three": "~0.187.0",
66
+ "three-mesh-bvh": "^0.9.17"
67
+ }
68
+ }
package/presets.js ADDED
@@ -0,0 +1,96 @@
1
+ // Opt-in gameplay presets: named, plain option objects a game picks on purpose, like a style pack for feel.
2
+ // The engine never applies one by itself (weather() alone has only 'clear', sky() has no seasons and no day cycle, music() does not duck for dialogue, no module binds a gameplay key, createPlayer() and interactions() refuse to guess a feel
3
+ // or a key); a preset only bundles options the game could write itself, so spreading it and overriding a field is always the same as writing it out:
4
+ // engine.use(weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] }));
5
+ // engine.characters.createPlayer({ ...presets.player.lockOn, faceTarget: boss });
6
+ // engine.use(interactions({ ...presets.interactions.nearest, keys: ['KeyF'] }));
7
+ // No imports and no engine state: plain data plus small control functions that call public API only.
8
+
9
+ /** @import { WeatherOptions, SkyOptions } from './types/world' */
10
+
11
+ /** A side-scroller moves only along world X (left / right keys); W / S do nothing. Reads input by action like the 'camera' control */
12
+ function sideScroll(p, input) { return { x: (input.autopilot || input.axis).x, z: 0, run: input.actions.has('run') && input.down('run') }; }
13
+
14
+ // The keys the walking presets bind (the engine binds none by itself): Shift / gamepad LB runs, Space / gamepad A jumps
15
+ const RUN = Object.freeze(['ShiftLeft', 'ShiftRight', 'PadLB']), JUMP = Object.freeze(['Space', 'PadA']);
16
+ const walk = (control, faceMode) => Object.freeze({ control, faceMode, runKeys: RUN, jumpKeys: JUMP, cameraFollow: true });
17
+ const use = pick => Object.freeze({ pick, keys: Object.freeze(['KeyE', 'PadX']) });
18
+
19
+ /**
20
+ * Opt-in presets, grouped by the option they fill. Each value is an options object for the function named in its group.
21
+ * @example engine.use(openWorld({ weather: presets.weather.temperate, sky: presets.calendar.fourSeasons }))
22
+ * @example engine.use(followCamera(presets.camera.overShoulder)); engine.characters.createPlayer({ ...presets.player.aim, spawn })
23
+ * @example engine.use(interactions({ ...presets.interactions.nearest }))
24
+ */
25
+ export const presets = Object.freeze({
26
+ /** weather({ ... }) options */
27
+ weather: Object.freeze({
28
+ /** Seven temperate weathers (clear cloudy overcast rain storm snow fog) and an automatic-weather pool weighted toward clear */
29
+ temperate: Object.freeze({
30
+ types: Object.freeze({
31
+ clear: { cloud: 0.15, sun: 1.0, fog: 1.0, wind: 0.8, rain: 0, snow: 0, grey: 0.0, lightning: 0 },
32
+ cloudy: { cloud: 0.45, sun: 0.85, fog: 0.9, wind: 1.1, rain: 0, snow: 0, grey: 0.15, lightning: 0 },
33
+ overcast: { cloud: 0.85, sun: 0.45, fog: 0.75, wind: 1.3, rain: 0, snow: 0, grey: 0.45, lightning: 0 },
34
+ rain: { cloud: 0.9, sun: 0.35, fog: 0.6, wind: 1.6, rain: 0.6, snow: 0, grey: 0.55, lightning: 0 },
35
+ storm: { cloud: 1.0, sun: 0.2, fog: 0.45, wind: 2.6, rain: 1.0, snow: 0, grey: 0.7, lightning: 1 },
36
+ snow: { cloud: 0.85, sun: 0.5, fog: 0.55, wind: 0.9, rain: 0, snow: 1.0, grey: 0.5, lightning: 0 },
37
+ fog: { cloud: 0.6, sun: 0.55, fog: 0.25, wind: 0.4, rain: 0, snow: 0, grey: 0.5, lightning: 0 },
38
+ }),
39
+ autoPool: Object.freeze(['clear', 'clear', 'clear', 'cloudy', 'cloudy', 'overcast', 'rain', 'storm', 'fog']),
40
+ }),
41
+ }),
42
+ /** sky({ ... }) calendar options */
43
+ calendar: Object.freeze({
44
+ /** Spring, summer, autumn, winter, 7 days each, with the 360 s day cycle of `cycle` (a cozy life sim; set daysPerSeason: 28 for longer seasons) */
45
+ fourSeasons: Object.freeze({ seasons: Object.freeze(['spring', 'summer', 'autumn', 'winter']), daysPerSeason: 7, dayLength: 360 }),
46
+ /** A day-night cycle, one day = 360 game seconds (6 minutes at timeScale 1); sky() alone keeps a fixed time of day */
47
+ cycle: Object.freeze({ dayLength: 360 }),
48
+ /** One time of day that never moves (dungeon, arena, space station), what sky() does without a dayLength; pick the hour with time */
49
+ fixedTime: Object.freeze({ dayLength: Infinity }),
50
+ }),
51
+ /** characters.createPlayer({ ... }) movement, facing, run / jump keys and camera follow (createPlayer has no default: pick one of these or write the options) */
52
+ player: Object.freeze({
53
+ /** The engine does nothing: no key reads, no turning, no camera follow; the game calls player.move() and player.face() itself (add cameraFollow: true to keep the camera on it) */
54
+ none: Object.freeze({ control: 'none', faceMode: 'manual', cameraFollow: false }),
55
+ /** Keys relative to the camera, Shift runs, Space jumps, turn toward the move direction, camera follows (adventure, life sim) */
56
+ thirdPerson: walk('camera', 'move'),
57
+ /** Keys relative to the camera while facing faceTarget: strafe around a locked-on enemy (soulslike); set faceTarget */
58
+ lockOn: walk('camera', 'target'),
59
+ /** Keys relative to the camera while facing where the camera looks (over-the-shoulder shooter) */
60
+ aim: walk('camera', 'camera'),
61
+ /** Left / right only along world X, turn toward the move direction (2.5D side-scroller; pair with a side-on camera) */
62
+ sideScroller: walk(sideScroll, 'move'),
63
+ }),
64
+ /** interactions({ ... }) selection and key (interactions has no default pick or key: pick one of these or write { pick, keys }) */
65
+ interactions: Object.freeze({
66
+ /** E / gamepad X uses the nearest one in reach (top-down, third person, life sim) */
67
+ nearest: use('nearest'),
68
+ /** E uses only what the actor faces, within 60° (soulslike: the door behind you stays dark) */
69
+ facing: use('facing'),
70
+ /** E uses the one closest to the screen-center ray (first person, shooters) */
71
+ aim: use('aim'),
72
+ }),
73
+ /**
74
+ * Keys for modules that open or do one thing (no module binds a key by itself): spread one into that module's options,
75
+ * e.g. inventory({ ...presets.keys.inventory, capacity: 20 }), characters({ ...presets.keys.brake })
76
+ */
77
+ keys: Object.freeze({
78
+ /** inventory(): I / gamepad Y opens the bag */
79
+ inventory: Object.freeze({ keys: Object.freeze(['KeyI']), pad: Object.freeze(['PadY']) }),
80
+ /** quests(): J / gamepad Select opens the quest log */
81
+ quests: Object.freeze({ keys: Object.freeze(['KeyJ']), pad: Object.freeze(['PadSelect']) }),
82
+ /** photo(): P / gamepad RB takes a photo */
83
+ photo: Object.freeze({ keys: Object.freeze(['KeyP']), pad: Object.freeze(['PadRB']) }),
84
+ /** grids.preview(): R turns the placement preview (spread into the preview options; rotate names the action) */
85
+ gridRotate: Object.freeze({ rotateKeys: Object.freeze(['KeyR']) }),
86
+ /** characters(): B / gamepad LT brakes while driving */
87
+ brake: Object.freeze({ brakeKeys: Object.freeze(['KeyB']), brakePad: Object.freeze(['PadLT']) }),
88
+ }),
89
+ /** followCamera({ ... }) options */
90
+ camera: Object.freeze({
91
+ /** Far, slow orbit for open landscapes (the follow camera's own defaults) */
92
+ follow: Object.freeze({}),
93
+ /** Close over-the-shoulder view with a locked mouse (third-person shooter, soulslike) */
94
+ overShoulder: Object.freeze({ distance: 3, shoulder: 0.7, pitch: 0.15, pointerLock: true }),
95
+ }),
96
+ });
@@ -0,0 +1,240 @@
1
+ // Post-processing as an ordered list of named effects in four slots. The engine owns no look of its own here: bloom, AO and
2
+ // outline are effects a style pack registers (they come from @threedog/post-effects); games add theirs with look.post.replace([...]).
3
+ // An effect promises only a name, params and on/off; how it draws is its create() (a three.js Pass under WebGLRenderer),
4
+ // so a WebGPU backend can later bring its own implementation without changing callers.
5
+ //
6
+ // Why EffectComposer and not three 0.187's renderer.setEffects(): setEffects fixes MSAA when the renderer is created (no
7
+ // runtime switch for the settings menu) and always tone-maps last, so there is no place for sRGB-space effects (LUT, palette
8
+ // quantising, paper grain). The composer stays an internal detail; nothing public returns it.
9
+ //
10
+ // MSAA lives in the composer's render targets, so it survives any effect and can be switched at runtime. With nothing on
11
+ // (antialias included) the scene renders straight to the canvas and nothing is allocated.
12
+ import * as THREE from 'three';
13
+ import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
14
+ import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
15
+ import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
16
+ import { warnMissing, warnOnce } from '../core/validate.js';
17
+ import { renamed } from '../core/errorHints.js';
18
+ import { FusedPass, groupFuse, checkDepthOrder } from './fuse.js';
19
+ import { definePostLook } from './postLook.js';
20
+ /** @import { Engine } from '../types/core' */
21
+
22
+ /**
23
+ * @typedef {'scene' | 'hdr' | 'ldr' | 'final'} PostSlot
24
+ * scene: replaces the scene render (one at a time, e.g. a pixelating render); hdr: linear color before tone mapping (bloom, AO,
25
+ * outline); ldr: sRGB color after tone mapping (LUT, palette, grain, vignette); final: last of all (FXAA / SMAA).
26
+ * @typedef {{ engine: Engine, scene: import('three').Scene, camera: import('three').Camera, width: number, height: number, params: Record<string, any> }} PostContext
27
+ * width / height are in device pixels.
28
+ * @typedef {{ uniforms?: Record<string, string>, values?: (params: Record<string, any>) => Record<string, any>, glsl: string, reads?: boolean }} PostFuse
29
+ * A GLSL snippet that colors the pixel; neighboring effects with a fuse run as ONE fullscreen pass. glsl is statements that edit
30
+ * `vec4 color` (the input pixel so far) and may use vUv, tDiffuse, uTime (s), uResolution (device px) and fxHash(vec2). uniforms
31
+ * declares extra ones by GLSL type ({ uVigStrength: 'float' }; names must be unique across effects, prefix with the effect name);
32
+ * values(params) returns their current values. reads: true when the snippet samples tDiffuse at other uvs (blur, color fringe):
33
+ * it then starts a new group, so it sees the real input.
34
+ * @typedef {{ name: string, create?: (ctx: PostContext) => object, fuse?: PostFuse, slot?: PostSlot, order?: number, enabled?: boolean, costly?: boolean,
35
+ * needsDepth?: boolean, params?: Record<string, any>, update?: (impl: any, params: Record<string, any>) => void }} PostEffect
36
+ * create: builds the implementation the first time the effect is on (WebGL: a three.js postprocessing Pass); optional when fuse is given.
37
+ * fuse: see PostFuse; effects with a fuse in the same slot next to each other are merged (never in slot 'scene'), their params
38
+ * update in place (no update() needed).
39
+ * order: position inside the slot, low first (ties keep add order). costly: off by default on low-tier devices.
40
+ * needsDepth: the scene's depth texture is kept for it (readBuffer.depthTexture). Only the buffer the scene render wrote holds
41
+ * scene depth, so a depth reader must run before any pass that swaps buffers (needsSwap, e.g. a ShaderPass, a scene-slot
42
+ * RenderPixelatedPass, or the tone-mapping output); the chain throws when it would not. A pass that writes the scene depth into its own output (gl_FragDepth, then set pass.keepsDepth = true; dof does) does not count as a swap. update: apply new params in place;
43
+ * without it set() rebuilds the implementation.
44
+ * @typedef {{ readonly name: string, readonly slot: PostSlot, readonly order: number, readonly enabled: boolean,
45
+ * readonly params: Record<string, any> }} PostHandle
46
+ */
47
+
48
+ const SLOTS = ['scene', 'hdr', 'ldr', 'final'];
49
+
50
+ export class PostFX {
51
+ /**
52
+ * @param {Engine} engine
53
+ * @param {{ antialias?: boolean, effects?: PostEffect[], enabled?: Record<string, boolean> }} [opts]
54
+ * @internal
55
+ */
56
+ constructor(engine, { antialias = true, effects = [], enabled = {} } = {}) {
57
+ /** @internal */ this.engine = engine;
58
+ /** @internal */ this._aa = antialias;
59
+ /** @internal */ this._list = /** @type {any[]} */ ([]);
60
+ /** @internal EffectComposer, built the first time anything is on */ this.composer = /** @type {any} */ (null);
61
+ if (!Array.isArray(effects)) throw new Error('style.post must be an array of post effects, e.g. post: [bloom({ strength: 0.35 })] (see recipe 09)');
62
+ for (const name in enabled) if (!effects.some(e => e?.name === name))
63
+ throw new Error(`createEngine({ post }): no post effect named '${name}'; the style pack registers: ${effects.map(e => e.name).join(', ') || 'none'}`);
64
+ /** @internal */ this._fused = /** @type {Map<string, FusedPass>} */ (new Map());
65
+ /** @internal */ this._scenePass = /** @type {any} */ (null);
66
+ /** @internal */ this._output = /** @type {any} */ (null);
67
+ /** @internal */ this._building = true; // add() skips chain rebuilds until every style effect is in
68
+ /** Why a costly effect started off (name -> reason), shown by describe().render and logged once: a silent "bloom is missing" in headless / software rendering looked like a bug @internal */
69
+ this._offWhy = /** @type {Record<string, string>} */ ({});
70
+ for (const e of effects) {
71
+ const lowOff = enabled[e.name] == null && e.costly && engine.tier === 'low';
72
+ if (lowOff) this._offWhy[e.name] = `starts off: costly effect on a low-tier device (${engine.headless ? 'headless runs use software rendering, which is low tier' : 'weak GPU or software rendering'}); turn it on with createEngine({ post: { ${e.name}: true } }) or engine.look.post.set({ '${e.name}.enabled': true })`;
73
+ this._add(e, { enabled: enabled[e.name] ?? (lowOff ? false : undefined) });
74
+ }
75
+ const why = Object.entries(this._offWhy);
76
+ if (why.length) warnOnce(`post: ${why.map(([n]) => n).join(', ')} ${why.length > 1 ? 'are' : 'is'} off by default here. ${why[0][1]}`);
77
+ this._building = false;
78
+ this._sync();
79
+ /** look.post: the style's effects are its style layer; look.post.set writes its 'game' layer @internal */ this._look = definePostLook(this, effects);
80
+ }
81
+
82
+ /**
83
+ * MSAA on (read-only; switch with post.setAntialias(on))
84
+ * @returns {boolean}
85
+ */
86
+ get antialias() { return this._aa; }
87
+ /**
88
+ * Whether any post work runs (antialias or an enabled effect)
89
+ * @returns {boolean}
90
+ */
91
+ get active() { return this._aa || this._list.some(e => e.enabled); }
92
+
93
+ /**
94
+ * Renamed in 0.2: throws and names the new call (engine.look.post.patch / engine.look.post.replace, recipes/52-look.md)
95
+ * @param {PostEffect} _effect
96
+ * @param {{ slot?: PostSlot, order?: number, enabled?: boolean }} [_opts]
97
+ * @returns {never}
98
+ * @experimental
99
+ */
100
+ add(_effect, _opts) { return renamed('postAdd'); }
101
+ /** Effects are added by look.post (patch generates a fuse effect, replace swaps the chain) with this @internal */
102
+ _add(effect, { slot, order, enabled } = {}) {
103
+ if (!effect || typeof effect.name !== 'string' || (typeof effect.create !== 'function' && !effect.fuse))
104
+ throw new Error("post effect: needs { name: 'myEffect', create: (ctx) => pass } (or a fuse snippet, see PostEffect)");
105
+ if (this.get(effect.name)) throw new Error(`post effect '${effect.name}' is already added; change it with look.post.set({ '${effect.name}.<param>': value }), or drop it with look.post.replace([...])`);
106
+ const s = slot ?? effect.slot ?? 'hdr';
107
+ if (!SLOTS.includes(s)) throw new Error(`post effect '${effect.name}': unknown slot '${s}', use ${SLOTS.join(' | ')}`);
108
+ if (effect.fuse && s === 'scene') throw new Error(`post effect '${effect.name}': a fuse snippet colors an existing image, it cannot replace the scene render; use slot 'hdr' | 'ldr' | 'final'`);
109
+ const other = s === 'scene' && this._list.find(e => e.slot === 'scene');
110
+ if (other) throw new Error(`post slot 'scene' already holds '${other.name}'; remove it first (only one effect can replace the scene render)`);
111
+ const post = this;
112
+ const h = {
113
+ name: effect.name, slot: s, order: order ?? effect.order ?? 0, enabled: enabled ?? effect.enabled ?? true,
114
+ params: { ...effect.params }, _def: effect, _impl: /** @type {any} */ (null), _removed: false,
115
+ enable() { return renamed('postHandle'); }, // the old handle verbs throw renamed-api; look.post writes through _enable / _set / _remove
116
+ set() { return renamed('postHandle'); },
117
+ remove() { return renamed('postHandle'); },
118
+ _enable(on) { const was = h.enabled; post._change(() => { h.enabled = !!on; }, () => { h.enabled = was; }); },
119
+ _set(p) {
120
+ Object.assign(h.params, p);
121
+ if (effect.fuse) { for (const p of post._fused.values()) p.refresh(); return; }
122
+ if (!h._impl) return;
123
+ if (effect.update) effect.update(h._impl, h.params); else { h._impl.dispose?.(); h._impl = null; post._sync(); }
124
+ },
125
+ _remove() {
126
+ if (h._removed) return;
127
+ h._removed = true; h._impl?.dispose?.(); h._impl = null;
128
+ post._list = post._list.filter(e => e !== h); post._sync();
129
+ },
130
+ };
131
+ // a create() that throws or an order that breaks depth leaves no half-added effect behind
132
+ this._change(() => this._list.push(h), () => { h._impl?.dispose?.(); h._impl = null; this._list = this._list.filter(e => e !== h); });
133
+ return h;
134
+ }
135
+ /**
136
+ * Read-only record of an added effect (name, slot, order, enabled, params), or undefined. Change one with engine.look.post.set({ 'bloom.strength': 0.6 })
137
+ * @param {string} name
138
+ * @returns {PostHandle | undefined}
139
+ * @experimental
140
+ */
141
+ get(name) { return this._list.find(e => e.name === name); }
142
+ /**
143
+ * Renamed in 0.2: throws and names the new call (engine.look.post.set({ 'bloom.enabled': on }); MSAA: engine.post.setAntialias(on))
144
+ * @param {string} _name
145
+ * @param {boolean} _on
146
+ * @returns {never}
147
+ * @experimental
148
+ */
149
+ enable(_name, _on) { return renamed('postEnable'); }
150
+ /**
151
+ * Turn MSAA (antialiasing of the post chain) on or off. It is a render target setting, not a look part.
152
+ * @example engine.post.setAntialias(false);
153
+ * @param {boolean} on
154
+ * @returns {void}
155
+ * @experimental
156
+ */
157
+ setAntialias(on) {
158
+ this._aa = !!on;
159
+ if (this.composer) for (const rt of [this.composer.renderTarget1, this.composer.renderTarget2]) { rt.samples = on ? 4 : 0; rt.dispose(); }
160
+ this._sync();
161
+ }
162
+ /**
163
+ * Effects in render order: [{ name, slot, order, enabled }]
164
+ * @returns {{ name: string, slot: PostSlot, order: number, enabled: boolean }[]}
165
+ * @experimental
166
+ */
167
+ list() { return this._sorted().map(({ name, slot, order, enabled }) => ({ name, slot, order, enabled })); }
168
+
169
+ /** @internal */
170
+ _sorted() { return SLOTS.flatMap(s => this._list.filter(e => e.slot === s).sort((a, b) => a.order - b.order)); }
171
+ /** @internal */
172
+ _size() { return this.engine.renderer.getSize(new THREE.Vector2()).multiplyScalar(this.engine.renderer.getPixelRatio()); }
173
+ /** Apply a list change, rebuild the chain, and undo the change when the rebuild throws (then rethrow) @internal */
174
+ _change(apply, undo) {
175
+ apply();
176
+ try { this._sync(); } catch (err) { undo(); this._sync(); throw err; }
177
+ }
178
+ // One FusedPass per group of neighboring fuse effects, kept while the same effects stay grouped (a changed group recompiles once)
179
+ /** @internal */
180
+ _fuseEntry(group, used) {
181
+ const key = group.map(e => e.name).join('+'), old = this._fused.get(key);
182
+ let pass = old && old.items.every((e, i) => e === group[i]) ? old : null;
183
+ if (!pass) { old?.dispose(); pass = new FusedPass(group); this._fused.set(key, pass); }
184
+ used.add(key);
185
+ return { name: `fused(${key})`, _impl: pass };
186
+ }
187
+ // Rebuild the pass chain from the list: scene (or the default RenderPass) -> hdr -> tone-mapped output -> ldr -> final.
188
+ // Only enabled effects are in the chain; an implementation is built the first time its effect is on and kept after.
189
+ /** @internal */
190
+ _sync() {
191
+ if (this._building || (!this.composer && !this.active)) return;
192
+ const { renderer, scene, camera } = this.engine, size = this._size();
193
+ if (!this.composer) {
194
+ const rt = new THREE.WebGLRenderTarget(size.x, size.y, { type: THREE.HalfFloatType, samples: this._aa ? 4 : 0 });
195
+ this.composer = new EffectComposer(renderer, rt);
196
+ // EffectComposer takes a given target's size (device pixels) as its CSS size; reset it so setPixelRatio does not scale twice
197
+ const css = renderer.getSize(new THREE.Vector2());
198
+ this.composer.setSize(css.x, css.y);
199
+ this._scenePass = new RenderPass(scene, camera);
200
+ this._output = new OutputPass();
201
+ }
202
+ const c = this.composer, on = this._sorted().filter(e => e.enabled);
203
+ for (const e of on) if (!e._impl && !e._def.fuse) {
204
+ e._impl = e._def.create({ engine: this.engine, scene, camera, width: size.x, height: size.y, params: e.params });
205
+ if (!e._impl || typeof e._impl.render !== 'function') { e._impl = null; throw new Error(`post effect '${e.name}': create() must return a pass with render() (a three.js postprocessing Pass)`); }
206
+ }
207
+ const used = new Set();
208
+ const slot = s => groupFuse(on.filter(e => e.slot === s)).map(g => Array.isArray(g) ? this._fuseEntry(g, used) : g);
209
+ const named = [slot('scene')[0] ?? { name: 'scene render', _impl: this._scenePass }, ...slot('hdr'),
210
+ { name: 'output (tone mapping)', _impl: this._output }, ...slot('ldr'), ...slot('final')];
211
+ for (const [k, p] of this._fused) if (!used.has(k)) { p.dispose(); this._fused.delete(k); }
212
+ checkDepthOrder(named);
213
+ // Effects reading depth (outline) need a depth texture on both ping-pong targets; added once, kept
214
+ if (on.some(e => e._def.needsDepth)) for (const rt of [c.renderTarget1, c.renderTarget2]) if (!rt.depthTexture) { rt.depthTexture = new THREE.DepthTexture(size.x, size.y); rt.dispose(); }
215
+ c.passes = named.map(e => e._impl);
216
+ for (const p of c.passes) p.setSize(size.x, size.y);
217
+ }
218
+
219
+ /**
220
+ * Dispose the composer, every effect and the render targets (called by engine.dispose)
221
+ * @internal
222
+ */
223
+ dispose() {
224
+ for (const e of this._list) { e._impl?.dispose?.(); e._impl = null; }
225
+ for (const p of this._fused.values()) p.dispose();
226
+ this._fused.clear();
227
+ if (!this.composer) return;
228
+ this._scenePass.dispose(); this._output.dispose();
229
+ this.composer.dispose(); this.composer = null;
230
+ }
231
+ /** @param {number} w @param {number} h @returns {void} */
232
+ setSize(w, h) { this.composer?.setSize(w, h); }
233
+ /** @param {number} r @returns {void} */
234
+ setPixelRatio(r) { this.composer?.setPixelRatio(r); }
235
+ /** @param {number} dt @returns {void} */
236
+ render(dt) {
237
+ if (this.active) { if (!this.composer) this._sync(); this.composer.render(dt); }
238
+ else this.engine.renderer.render(this.engine.scene, this.engine.camera);
239
+ }
240
+ }
@@ -0,0 +1,105 @@
1
+ // The `detail` surface patch: grain, paper, brush strokes or a texture laid over any lit material in world space (no UVs needed).
2
+ // Everything that differs between materials is a uniform (scale, strength, direction, stretch, octaves, mode, tint), so N materials with
3
+ // different values share ONE shader program; only the structure is in the cacheKey: source kind, projection, which channels it touches.
4
+ import * as THREE from 'three';
5
+ import { checkOptions, warnOnce } from '../core/validate.js';
6
+ import { placeholderTexture, hashText } from './effects.js';
7
+ import { declareUniforms } from './uniformDecl.js';
8
+
9
+ /**
10
+ * @typedef {{ texture?: string | import('three').Texture, noise?: 'grain' | 'paper' | 'stroke', glsl?: string, uniforms?: Record<string, any>,
11
+ * projection?: 'world' | 'triplanar', scale?: number, strength?: number, mode?: 'multiply' | 'add' | 'mix', tint?: import('../types/common').ColorLike,
12
+ * direction?: number, stretch?: number, octaves?: number, normal?: number, roughness?: number }} DetailOptions
13
+ */
14
+ const KEYS = ['texture', 'noise', 'glsl', 'uniforms', 'projection', 'scale', 'strength', 'mode', 'tint', 'direction', 'stretch', 'octaves', 'normal', 'roughness'];
15
+ const NOISES = ['grain', 'paper', 'stroke'];
16
+ const MODES = ['multiply', 'add', 'mix'];
17
+
18
+ const NOISE = `float threedogDHash(vec2 p){ return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
19
+ float threedogDNoise(vec2 p){ vec2 i = floor(p), f = fract(p); f = f*f*(3.0-2.0*f);
20
+ return mix(mix(threedogDHash(i), threedogDHash(i+vec2(1,0)), f.x), mix(threedogDHash(i+vec2(0,1)), threedogDHash(i+vec2(1,1)), f.x), f.y); }
21
+ float threedogDFbm(vec2 p){ float s = 0.0, a = 0.5, n = 0.0;
22
+ for (int i = 0; i < 4; i++) { if (float(i) >= uDetailOctaves) break; s += a * threedogDNoise(p); n += a; p = p * 2.03 + 17.0; a *= 0.5; }
23
+ return s / n; }`;
24
+
25
+ // Built-in sources: p is already scaled, turned by direction and stretched along it; returns (color, height)
26
+ const SOURCES = {
27
+ tex: 'vec4 threedogDetailSample(vec2 p){ vec3 c = texture2D(uDetail, p).rgb; return vec4(c, dot(c, vec3(0.299, 0.587, 0.114))); }',
28
+ grain: 'vec4 threedogDetailSample(vec2 p){ float s = threedogDFbm(p); return vec4(vec3(s), s); }',
29
+ paper: 'vec4 threedogDetailSample(vec2 p){ float s = 0.65 * threedogDFbm(p) + 0.35 * threedogDNoise(vec2(p.x * 7.0, p.y * 0.9)); return vec4(vec3(s), s); }',
30
+ stroke: 'vec4 threedogDetailSample(vec2 p){ float s = smoothstep(0.15, 0.85, threedogDFbm(vec2(p.x, p.y * 1.7))); return vec4(vec3(s), s); }',
31
+ };
32
+
33
+ // p (world position) -> sample; 'world' looks straight down (xz), 'triplanar' blends the three axis planes by the surface normal
34
+ const PROJECT = {
35
+ world: 'vec4 threedogDetail(vec3 w){ return threedogDetailSample(threedogDetailUV(w.xz)); }',
36
+ triplanar: `vec4 threedogDetail(vec3 w){
37
+ vec3 n = abs(normalize(cross(dFdx(w), dFdy(w)))); n /= n.x + n.y + n.z;
38
+ return threedogDetailSample(threedogDetailUV(w.zy)) * n.x + threedogDetailSample(threedogDetailUV(w.xz)) * n.y + threedogDetailSample(threedogDetailUV(w.xy)) * n.z; }`,
39
+ };
40
+
41
+ const COLOR = `{ vec3 tdc = threedogDS.rgb * uDetailTint;
42
+ if (uDetailMode < 0.5) diffuseColor.rgb *= mix(vec3(1.0), tdc * 2.0, uDetailStrength);
43
+ else if (uDetailMode < 1.5) diffuseColor.rgb += (tdc - 0.5) * uDetailStrength;
44
+ else diffuseColor.rgb = mix(diffuseColor.rgb, tdc, uDetailStrength); }`;
45
+ // Screen-space bump (the same maths as three's bump map): uDetailBump is the relief height in meters per unit of height
46
+ const BUMP = `vec3 threedogDetailBump(vec3 surfPos, vec3 surfNorm, float h, float k, float faceDir){
47
+ vec3 sx = dFdx(surfPos), sy = dFdy(surfPos), r1 = cross(sy, surfNorm), r2 = cross(surfNorm, sx);
48
+ float det = dot(sx, r1) * faceDir;
49
+ return normalize(abs(det) * surfNorm - k * sign(det) * (dFdx(h) * r1 + dFdy(h) * r2)); }`;
50
+
51
+ /**
52
+ * The `detail` patch from a detail option object (see MaterialDetail in types/style.d.ts). `engine` loads a texture given by asset name.
53
+ * @internal use materialSpec.detail, style.terrain.detail or applyEffects(mat, { detail })
54
+ * @param {any} o
55
+ * @param {{ assets?: any } | null} engine
56
+ * @param {string} [label] where the options came from, for errors
57
+ * @returns {import('./patches.js').ShaderPatch}
58
+ */
59
+ export function detailPatch(o, engine, label = 'detail') {
60
+ checkOptions(label, o, KEYS);
61
+ if (o.mode !== undefined && !MODES.includes(o.mode)) throw new Error(`${label}.mode '${o.mode}' is not a blend mode; use ${MODES.join(' | ')}`);
62
+ if (o.noise !== undefined && !NOISES.includes(o.noise)) throw new Error(`${label}.noise '${o.noise}' is not a built-in noise; use ${NOISES.join(' | ')}, or write your own with glsl: 'vec4 threedogDetailSample(vec2 p){ ... }'`);
63
+ const proj = o.projection ?? 'world';
64
+ if (!PROJECT[proj]) throw new Error(`${label}.projection '${proj}' must be 'world' (top-down) or 'triplanar'`);
65
+ if (o.glsl && !/vec4\s+threedogDetailSample\s*\(\s*vec2/.test(o.glsl)) throw new Error(`${label}.glsl must define \`vec4 threedogDetailSample(vec2 p)\`: p is the scaled, turned, stretched position; return vec4(color rgb, height 0-1). uDetailOctaves and the uniforms you list are in scope`);
66
+ const src = o.glsl ? 'glsl:' + hashText(o.glsl) : o.texture ? 'tex' : o.noise ?? 'grain';
67
+ const isStroke = o.noise === 'stroke', ang = (o.direction ?? 0) * Math.PI / 180;
68
+ const colorOn = o.strength !== 0 && (o.strength !== undefined || !(o.normal || o.roughness)), bump = !!o.normal, rough = !!o.roughness;
69
+ const u = /** @type {Record<string, { value: any }>} */ ({
70
+ uDetailScale: { value: o.scale ?? 0.25 }, uDetailStrength: { value: o.strength ?? 0.35 }, uDetailMode: { value: Math.max(0, MODES.indexOf(o.mode ?? 'multiply')) },
71
+ uDetailTint: { value: new THREE.Color(o.tint ?? 0xffffff) }, uDetailDir: { value: new THREE.Vector2(Math.cos(ang), Math.sin(ang)) },
72
+ uDetailStretch: { value: o.stretch ?? (isStroke ? 6 : 1) }, uDetailOctaves: { value: o.octaves ?? 2 },
73
+ uDetailBump: { value: o.normal ?? 0 }, uDetailRough: { value: o.roughness ?? 0 },
74
+ });
75
+ let decl = '';
76
+ if (o.texture || o.glsl) {
77
+ let tex;
78
+ if (o.texture?.isTexture) tex = o.texture;
79
+ else {
80
+ tex = placeholderTexture('detail');
81
+ if (typeof o.texture === 'string') {
82
+ if (!engine?.assets) throw new Error(`${label}.texture '${o.texture}' is an asset name but no engine is known; pass the engine (makeMaterial(role, params, engine), applyEffects(mat, { detail, engine })) or give a THREE.Texture`);
83
+ engine.assets.texture(o.texture).then(t => {
84
+ const own = t.clone(); // shares the image (no second upload); own wrapping
85
+ own.wrapS = own.wrapT = THREE.RepeatWrapping; own.colorSpace = THREE.SRGBColorSpace; own.needsUpdate = true;
86
+ tex.dispose(); u.uDetail.value = own;
87
+ }).catch(err => warnOnce(err.message));
88
+ }
89
+ }
90
+ if (o.texture) { tex.wrapS = tex.wrapT = THREE.RepeatWrapping; u.uDetail = { value: tex }; decl = 'uniform sampler2D uDetail;'; }
91
+ }
92
+ const own = declareUniforms(label + '.uniforms', o.uniforms);
93
+ Object.assign(u, own.uniforms); decl += '\n' + own.decl;
94
+ const pars = `uniform float uDetailScale, uDetailStrength, uDetailMode, uDetailStretch, uDetailOctaves, uDetailBump, uDetailRough;
95
+ uniform vec3 uDetailTint; uniform vec2 uDetailDir; ${decl}
96
+ ${NOISE}
97
+ vec2 threedogDetailUV(vec2 w){ vec2 p = w * uDetailScale; p = vec2(uDetailDir.x * p.x + uDetailDir.y * p.y, -uDetailDir.y * p.x + uDetailDir.x * p.y); p.x /= uDetailStretch; return p; }
98
+ ${o.glsl ?? SOURCES[o.texture ? 'tex' : o.noise ?? 'grain']}
99
+ ${PROJECT[proj]}
100
+ ${BUMP}`;
101
+ const fragment = /** @type {Record<string, string>} */ ({ pars, color_fragment: `vec4 threedogDS = threedogDetail(vThreedogWorld);\n${colorOn ? COLOR : ''}` });
102
+ if (bump) fragment.normal_fragment_maps = 'normal = threedogDetailBump(-vViewPosition, normal, threedogDS.a, uDetailBump, faceDirection);';
103
+ if (rough) fragment.roughnessmap_fragment = 'roughnessFactor = clamp(roughnessFactor + (threedogDS.a - 0.5) * uDetailRough, 0.04, 1.0);';
104
+ return { name: 'detail', cacheKey: `${src}|${proj}|${colorOn ? 'c' : ''}${bump ? 'n' : ''}${rough ? 'r' : ''}`, needs: { patches: ['world'] }, uniforms: u, glsl: { fragment } };
105
+ }