threedog 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (506) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +268 -0
  5. package/core/Assets.js +256 -0
  6. package/core/Audio.js +267 -0
  7. package/core/Baked.js +72 -0
  8. package/core/Batching.js +247 -0
  9. package/core/Budget.js +221 -0
  10. package/core/Clock.js +94 -0
  11. package/core/Commits.js +77 -0
  12. package/core/DebugOverrides.js +143 -0
  13. package/core/Describe.js +145 -0
  14. package/core/Engine.js +184 -0
  15. package/core/Events.js +153 -0
  16. package/core/I18n.js +94 -0
  17. package/core/Input.js +245 -0
  18. package/core/Inspect.js +77 -0
  19. package/core/InspectScene.js +191 -0
  20. package/core/Jobs.js +146 -0
  21. package/core/Loading.js +149 -0
  22. package/core/MaterialInfo.js +32 -0
  23. package/core/Ops.js +256 -0
  24. package/core/Random.js +52 -0
  25. package/core/Rays.js +160 -0
  26. package/core/SaveStore.js +85 -0
  27. package/core/Saves.js +254 -0
  28. package/core/Stream.js +279 -0
  29. package/core/Threads.js +158 -0
  30. package/core/UrlState.js +94 -0
  31. package/core/Vars.js +35 -0
  32. package/core/Views.js +49 -0
  33. package/core/actor.js +23 -0
  34. package/core/assetEntry.js +89 -0
  35. package/core/assetLoad.js +190 -0
  36. package/core/assetManifest.js +35 -0
  37. package/core/assetReport.js +83 -0
  38. package/core/audioRules.js +121 -0
  39. package/core/audioVoice.js +225 -0
  40. package/core/batchGroups.js +116 -0
  41. package/core/canvasBox.js +63 -0
  42. package/core/catalog.js +169 -0
  43. package/core/checks.js +67 -0
  44. package/core/claims.js +51 -0
  45. package/core/dayTime.js +15 -0
  46. package/core/debugView.js +76 -0
  47. package/core/describeRender.js +45 -0
  48. package/core/describeText.js +143 -0
  49. package/core/easing.js +34 -0
  50. package/core/errorCodes.js +205 -0
  51. package/core/errorHints.js +208 -0
  52. package/core/errors.js +40 -0
  53. package/core/events.generated.js +84 -0
  54. package/core/ground.js +102 -0
  55. package/core/holds.js +106 -0
  56. package/core/inputContext.js +69 -0
  57. package/core/inputDefaults.js +22 -0
  58. package/core/inputPad.js +35 -0
  59. package/core/inputPointer.js +48 -0
  60. package/core/inputTouch.js +48 -0
  61. package/core/lifecycle.js +69 -0
  62. package/core/lightWatch.js +56 -0
  63. package/core/look/coreParts.js +112 -0
  64. package/core/look/layers.js +136 -0
  65. package/core/look/part.js +173 -0
  66. package/core/look/report.js +79 -0
  67. package/core/look/write.js +86 -0
  68. package/core/loop.js +200 -0
  69. package/core/math.js +33 -0
  70. package/core/modules.js +196 -0
  71. package/core/movement.js +19 -0
  72. package/core/mulberry32.js +14 -0
  73. package/core/opsAtomic.js +31 -0
  74. package/core/opsCheck.js +97 -0
  75. package/core/opsFail.js +20 -0
  76. package/core/opsGuard.js +26 -0
  77. package/core/opsHistory.js +27 -0
  78. package/core/opsRun.js +77 -0
  79. package/core/page.js +78 -0
  80. package/core/params.js +132 -0
  81. package/core/pureWorker.js +5 -0
  82. package/core/renamed.js +21 -0
  83. package/core/saveApply.js +128 -0
  84. package/core/saveFiles.js +139 -0
  85. package/core/saveIds.js +53 -0
  86. package/core/saveVersions.js +97 -0
  87. package/core/scatter.js +92 -0
  88. package/core/sceneMethods.js +100 -0
  89. package/core/screenToGround.js +39 -0
  90. package/core/services.js +73 -0
  91. package/core/session.js +171 -0
  92. package/core/shadowTypes.js +15 -0
  93. package/core/skip.js +104 -0
  94. package/core/startup.js +135 -0
  95. package/core/streamCells.js +24 -0
  96. package/core/streamSources.js +73 -0
  97. package/core/styleParts.js +96 -0
  98. package/core/targeting.js +64 -0
  99. package/core/thingExplain.js +68 -0
  100. package/core/thingOps.js +168 -0
  101. package/core/things.js +212 -0
  102. package/core/threadPure.js +120 -0
  103. package/core/threadServe.js +25 -0
  104. package/core/tier.js +11 -0
  105. package/core/util.js +11 -0
  106. package/core/validate.js +204 -0
  107. package/docs/AI.md +123 -0
  108. package/docs/API.md +83 -0
  109. package/docs/CODEMAP.md +347 -0
  110. package/docs/COMMANDS.md +108 -0
  111. package/docs/CONVENTIONS.md +145 -0
  112. package/docs/PERF.md +217 -0
  113. package/docs/THREE.md +86 -0
  114. package/docs/api/ambience.md +15 -0
  115. package/docs/api/assets.md +62 -0
  116. package/docs/api/audio.md +53 -0
  117. package/docs/api/budget.md +40 -0
  118. package/docs/api/cameraRig.md +120 -0
  119. package/docs/api/characters.md +144 -0
  120. package/docs/api/clock.md +7 -0
  121. package/docs/api/collision.md +39 -0
  122. package/docs/api/content.md +64 -0
  123. package/docs/api/dialogue.md +39 -0
  124. package/docs/api/engine.md +199 -0
  125. package/docs/api/entities.md +61 -0
  126. package/docs/api/events.md +95 -0
  127. package/docs/api/flow.md +27 -0
  128. package/docs/api/grids.md +11 -0
  129. package/docs/api/ground.md +16 -0
  130. package/docs/api/hlod.md +34 -0
  131. package/docs/api/hud.md +31 -0
  132. package/docs/api/i18n.md +10 -0
  133. package/docs/api/input.md +24 -0
  134. package/docs/api/interactions.md +31 -0
  135. package/docs/api/inventory.md +66 -0
  136. package/docs/api/jobs.md +10 -0
  137. package/docs/api/level.md +41 -0
  138. package/docs/api/lightPool.md +56 -0
  139. package/docs/api/music.md +34 -0
  140. package/docs/api/nav.md +26 -0
  141. package/docs/api/net.md +14 -0
  142. package/docs/api/openWorld.md +24 -0
  143. package/docs/api/particles.md +41 -0
  144. package/docs/api/photo.md +15 -0
  145. package/docs/api/post.md +10 -0
  146. package/docs/api/quests.md +36 -0
  147. package/docs/api/rays.md +26 -0
  148. package/docs/api/rigid.md +84 -0
  149. package/docs/api/saves.md +32 -0
  150. package/docs/api/settings.md +36 -0
  151. package/docs/api/sky.md +58 -0
  152. package/docs/api/stream.md +31 -0
  153. package/docs/api/style.md +134 -0
  154. package/docs/api/terrain.md +34 -0
  155. package/docs/api/timeline.md +39 -0
  156. package/docs/api/tools.md +57 -0
  157. package/docs/api/triggers.md +56 -0
  158. package/docs/api/vars.md +9 -0
  159. package/docs/api/vegetation.md +52 -0
  160. package/docs/api/water.md +48 -0
  161. package/docs/api/weather.md +29 -0
  162. package/docs/api/world.md +30 -0
  163. package/docs/recipes/01-new-game.md +148 -0
  164. package/docs/recipes/02-npc.md +167 -0
  165. package/docs/recipes/03-items-pickups.md +158 -0
  166. package/docs/recipes/04-quests.md +83 -0
  167. package/docs/recipes/05-props-bake.md +159 -0
  168. package/docs/recipes/06-clock-events.md +117 -0
  169. package/docs/recipes/07-flow-scenes-pause.md +132 -0
  170. package/docs/recipes/08-weather-sky.md +74 -0
  171. package/docs/recipes/09-style-pack.md +234 -0
  172. package/docs/recipes/10-blender-level.md +67 -0
  173. package/docs/recipes/11-vehicles.md +55 -0
  174. package/docs/recipes/12-navmesh.md +79 -0
  175. package/docs/recipes/13-animation.md +149 -0
  176. package/docs/recipes/14-custom-module.md +91 -0
  177. package/docs/recipes/15-perf.md +78 -0
  178. package/docs/recipes/16-dev-bridge.md +180 -0
  179. package/docs/recipes/18-world.md +185 -0
  180. package/docs/recipes/19-shooting-picking.md +76 -0
  181. package/docs/recipes/20-content-actions-save.md +176 -0
  182. package/docs/recipes/21-camera.md +153 -0
  183. package/docs/recipes/22-shop-gold.md +107 -0
  184. package/docs/recipes/23-ops.md +175 -0
  185. package/docs/recipes/26-ui-parts.md +138 -0
  186. package/docs/recipes/27-net.md +96 -0
  187. package/docs/recipes/28-terrain.md +80 -0
  188. package/docs/recipes/29-grid.md +87 -0
  189. package/docs/recipes/30-templates.md +131 -0
  190. package/docs/recipes/31-audio.md +126 -0
  191. package/docs/recipes/32-action-game.md +33 -0
  192. package/docs/recipes/33-stream-sources.md +37 -0
  193. package/docs/recipes/34-environment-lighting.md +36 -0
  194. package/docs/recipes/35-style-from-reference.md +89 -0
  195. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  196. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  197. package/docs/recipes/38-environment-look-hooks.md +83 -0
  198. package/docs/recipes/40-scene.md +108 -0
  199. package/docs/recipes/41-thing-registry.md +93 -0
  200. package/docs/recipes/42-terrain-shape.md +64 -0
  201. package/docs/recipes/43-shader-patches-surface-looks.md +120 -0
  202. package/docs/recipes/44-water-weather-look-hooks.md +135 -0
  203. package/docs/recipes/45-cascaded-shadows.md +51 -0
  204. package/docs/recipes/46-blender-art-route.md +114 -0
  205. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  206. package/docs/recipes/48-make-material.md +70 -0
  207. package/docs/recipes/49-game-module-contract.md +71 -0
  208. package/docs/recipes/50-own-renderer.md +12 -0
  209. package/docs/recipes/51-capability-catalog.md +63 -0
  210. package/docs/recipes/52-look.md +108 -0
  211. package/examples/action/DESIGN.md +3 -0
  212. package/examples/action/GAMEMAP.md +127 -0
  213. package/examples/action/content/actions.js +8 -0
  214. package/examples/action/content/audio.js +9 -0
  215. package/examples/action/content/index.js +10 -0
  216. package/examples/action/content/items.js +4 -0
  217. package/examples/action/content/places.js +4 -0
  218. package/examples/action/content/props.js +11 -0
  219. package/examples/action/content/templates.js +10 -0
  220. package/examples/action/content/views.js +6 -0
  221. package/examples/action/look.js +5 -0
  222. package/examples/action/main.js +137 -0
  223. package/examples/action/models.js +25 -0
  224. package/examples/sheepisland/GAMEMAP.md +107 -0
  225. package/examples/sheepisland/content/index.js +6 -0
  226. package/examples/sheepisland/content/props.js +19 -0
  227. package/examples/sheepisland/content/templates.js +5 -0
  228. package/examples/sheepisland/content/vegetation.js +8 -0
  229. package/examples/sheepisland/main.js +71 -0
  230. package/examples/sheepisland/params.js +25 -0
  231. package/examples/sheepisland/style/index.js +79 -0
  232. package/examples/sheepisland/style/models.js +59 -0
  233. package/examples/sheepisland/views.js +9 -0
  234. package/examples/styletest/GAMEMAP.md +135 -0
  235. package/examples/styletest/content/index.js +9 -0
  236. package/examples/styletest/content/items.js +8 -0
  237. package/examples/styletest/content/npcs.js +8 -0
  238. package/examples/styletest/content/places.js +5 -0
  239. package/examples/styletest/content/props.js +16 -0
  240. package/examples/styletest/content/templates.js +9 -0
  241. package/examples/styletest/content/vegetation.js +31 -0
  242. package/examples/styletest/look.js +11 -0
  243. package/examples/styletest/main.js +95 -0
  244. package/examples/styletest/models.js +87 -0
  245. package/examples/styletest/overrides.js +33 -0
  246. package/examples/styletest/panel.js +135 -0
  247. package/examples/styletest/params.js +32 -0
  248. package/examples/styletest/views.js +31 -0
  249. package/examples/world/DESIGN.md +5 -0
  250. package/examples/world/GAMEMAP.md +171 -0
  251. package/examples/world/content/actions.js +8 -0
  252. package/examples/world/content/audio.js +25 -0
  253. package/examples/world/content/bodies.js +12 -0
  254. package/examples/world/content/containers.js +4 -0
  255. package/examples/world/content/dialogues.js +33 -0
  256. package/examples/world/content/index.js +17 -0
  257. package/examples/world/content/items.js +10 -0
  258. package/examples/world/content/npcs.js +14 -0
  259. package/examples/world/content/pickups.js +11 -0
  260. package/examples/world/content/places.js +6 -0
  261. package/examples/world/content/props.js +12 -0
  262. package/examples/world/content/quests.js +15 -0
  263. package/examples/world/content/rules.js +23 -0
  264. package/examples/world/content/templates.js +5 -0
  265. package/examples/world/content/vegetation.js +32 -0
  266. package/examples/world/main.js +168 -0
  267. package/examples/world/models.js +28 -0
  268. package/index.d.ts +306 -0
  269. package/index.js +122 -0
  270. package/llms.txt +61 -0
  271. package/modules/ambience/Ambience.js +186 -0
  272. package/modules/camera/FirstPersonCamera.js +131 -0
  273. package/modules/camera/FixedCamera.js +162 -0
  274. package/modules/camera/FollowCamera.js +91 -0
  275. package/modules/camera/RtsCamera.js +132 -0
  276. package/modules/camera/common.js +182 -0
  277. package/modules/camera/index.js +11 -0
  278. package/modules/camera/projection.js +34 -0
  279. package/modules/characters/Character.js +235 -0
  280. package/modules/characters/NPC.js +242 -0
  281. package/modules/characters/assetModel.js +42 -0
  282. package/modules/characters/astar.js +66 -0
  283. package/modules/characters/behaviors.js +72 -0
  284. package/modules/characters/footsteps.js +13 -0
  285. package/modules/characters/index.js +215 -0
  286. package/modules/characters/moveHelpers.js +29 -0
  287. package/modules/characters/movers/common.js +62 -0
  288. package/modules/characters/movers/rapier.js +74 -0
  289. package/modules/characters/movers/simple.js +43 -0
  290. package/modules/characters/npcAvoid.js +129 -0
  291. package/modules/characters/npcSim.js +150 -0
  292. package/modules/characters/npcView.js +42 -0
  293. package/modules/characters/pathAsync.js +113 -0
  294. package/modules/characters/pathJob.js +62 -0
  295. package/modules/characters/pathWorker.js +7 -0
  296. package/modules/characters/playerStrings.js +12 -0
  297. package/modules/characters/proceduralRig.js +58 -0
  298. package/modules/characters/useModel.js +22 -0
  299. package/modules/characters/walkTo.js +58 -0
  300. package/modules/collision/Collision.js +274 -0
  301. package/modules/collision/grid.js +63 -0
  302. package/modules/content/explain.js +13 -0
  303. package/modules/content/ids.js +95 -0
  304. package/modules/content/index.js +154 -0
  305. package/modules/content/loader.js +190 -0
  306. package/modules/content/models.js +69 -0
  307. package/modules/content/packs.js +69 -0
  308. package/modules/content/props.js +89 -0
  309. package/modules/content/rules.js +134 -0
  310. package/modules/content/templates.js +189 -0
  311. package/modules/debug/DebugPanel.js +174 -0
  312. package/modules/entities/Entities.js +243 -0
  313. package/modules/entities/build.js +25 -0
  314. package/modules/entities/index.js +4 -0
  315. package/modules/flow/index.js +101 -0
  316. package/modules/gameplay/Container.js +227 -0
  317. package/modules/gameplay/Containers.js +89 -0
  318. package/modules/gameplay/Dialogue.js +219 -0
  319. package/modules/gameplay/Interactions.js +253 -0
  320. package/modules/gameplay/Inventory.js +224 -0
  321. package/modules/gameplay/Quests.js +205 -0
  322. package/modules/gameplay/boxOps.js +60 -0
  323. package/modules/gameplay/dialogueBox.js +48 -0
  324. package/modules/gameplay/interactionPrompt.js +28 -0
  325. package/modules/gameplay/inventoryOps.js +137 -0
  326. package/modules/gameplay/pickups.js +115 -0
  327. package/modules/gameplay/questLog.js +54 -0
  328. package/modules/gameplay/questSave.js +71 -0
  329. package/modules/grid/Grid.js +184 -0
  330. package/modules/grid/Layer.js +142 -0
  331. package/modules/grid/index.js +236 -0
  332. package/modules/grid/ops.js +73 -0
  333. package/modules/grid/preview.js +85 -0
  334. package/modules/grid/tiles.js +79 -0
  335. package/modules/hlod/index.js +167 -0
  336. package/modules/hud/index.js +167 -0
  337. package/modules/hud/parts.js +80 -0
  338. package/modules/level/geometry.js +46 -0
  339. package/modules/level/heightfield.js +160 -0
  340. package/modules/level/index.js +233 -0
  341. package/modules/level/nodes.js +84 -0
  342. package/modules/lights/index.js +227 -0
  343. package/modules/music/Music.js +294 -0
  344. package/modules/music/index.js +2 -0
  345. package/modules/music/rules.js +28 -0
  346. package/modules/nav/index.js +156 -0
  347. package/modules/nav/navPath.js +17 -0
  348. package/modules/net/Client.js +137 -0
  349. package/modules/net/Host.js +117 -0
  350. package/modules/net/Net.js +49 -0
  351. package/modules/net/index.js +77 -0
  352. package/modules/net/sync.js +114 -0
  353. package/modules/net/transports.js +118 -0
  354. package/modules/particles/Particles.js +179 -0
  355. package/modules/particles/effect.js +112 -0
  356. package/modules/particles/shaders.js +28 -0
  357. package/modules/photo/Photo.js +146 -0
  358. package/modules/rigid/RigidBodies.js +265 -0
  359. package/modules/rigid/Vehicles.js +97 -0
  360. package/modules/rigid/sync.js +158 -0
  361. package/modules/settings/Settings.js +297 -0
  362. package/modules/settings/apply.js +21 -0
  363. package/modules/settings/index.js +3 -0
  364. package/modules/settings/sections.js +156 -0
  365. package/modules/settings/strings.js +53 -0
  366. package/modules/settings/view.js +65 -0
  367. package/modules/sky/Sky.js +259 -0
  368. package/modules/sky/calendar.js +80 -0
  369. package/modules/sky/cascades.js +125 -0
  370. package/modules/sky/clouds.js +79 -0
  371. package/modules/sky/domeLayers.js +33 -0
  372. package/modules/sky/environment.js +141 -0
  373. package/modules/sky/fog.js +139 -0
  374. package/modules/sky/frame.js +77 -0
  375. package/modules/sky/layers.js +69 -0
  376. package/modules/sky/look.js +51 -0
  377. package/modules/sky/lookFog.js +80 -0
  378. package/modules/sky/lookShadow.js +50 -0
  379. package/modules/sky/lookSky.js +108 -0
  380. package/modules/sky/schedule.js +80 -0
  381. package/modules/sky/shader.js +96 -0
  382. package/modules/sky/shadow.js +74 -0
  383. package/modules/sky/skyModule.js +60 -0
  384. package/modules/terrain/ChunkManager.js +260 -0
  385. package/modules/terrain/chunkJob.js +19 -0
  386. package/modules/terrain/chunkLevels.js +40 -0
  387. package/modules/terrain/chunkQueries.js +42 -0
  388. package/modules/terrain/chunkWorker.js +5 -0
  389. package/modules/terrain/index.js +118 -0
  390. package/modules/terrain/lookGround.js +61 -0
  391. package/modules/terrain/mountTerrain.js +32 -0
  392. package/modules/terrain/terrainColorMap.js +41 -0
  393. package/modules/terrain/terrainDefaults.js +39 -0
  394. package/modules/terrain/terrainEdit.js +139 -0
  395. package/modules/terrain/terrainGen.js +155 -0
  396. package/modules/terrain/terrainIsland.js +131 -0
  397. package/modules/terrain/terrainMesh.js +92 -0
  398. package/modules/terrain/terrainShape.js +108 -0
  399. package/modules/terrain/terrainShapeMain.js +41 -0
  400. package/modules/terrain/terrainTexture.js +44 -0
  401. package/modules/timeline/Timeline.js +253 -0
  402. package/modules/timeline/Tween.js +114 -0
  403. package/modules/timeline/letterbox.js +24 -0
  404. package/modules/timeline/shots.js +90 -0
  405. package/modules/triggers/index.js +268 -0
  406. package/modules/vegetation/Vegetation.js +256 -0
  407. package/modules/vegetation/groundChunks.js +177 -0
  408. package/modules/vegetation/index.js +43 -0
  409. package/modules/vegetation/lookWind.js +37 -0
  410. package/modules/vegetation/modelGeometry.js +21 -0
  411. package/modules/water/Water.js +160 -0
  412. package/modules/water/look.js +80 -0
  413. package/modules/water/surface.js +88 -0
  414. package/modules/weather/Weather.js +242 -0
  415. package/modules/weather/look.js +75 -0
  416. package/modules/weather/particles.js +92 -0
  417. package/modules/weather/shaders.js +49 -0
  418. package/modules/weather/strings.js +15 -0
  419. package/modules/world/World.js +231 -0
  420. package/modules/world/cells.js +42 -0
  421. package/modules/world/explain.js +11 -0
  422. package/modules/world/index.js +71 -0
  423. package/modules/world/persist.js +107 -0
  424. package/modules/world/pos.js +20 -0
  425. package/modules/world/records.js +89 -0
  426. package/modules/world/sim.js +175 -0
  427. package/modules/world/simFar.js +82 -0
  428. package/modules/world/state.js +115 -0
  429. package/modules/world/thingSource.js +44 -0
  430. package/modules/world/views.js +182 -0
  431. package/package.json +66 -4
  432. package/presets.js +96 -0
  433. package/render/PostFX.js +240 -0
  434. package/render/detail.js +105 -0
  435. package/render/effects.js +144 -0
  436. package/render/engineUniforms.js +23 -0
  437. package/render/fuse.js +84 -0
  438. package/render/lighting.js +100 -0
  439. package/render/lights.js +18 -0
  440. package/render/lookSurface.js +161 -0
  441. package/render/materials.js +220 -0
  442. package/render/patches.js +252 -0
  443. package/render/postLook.js +86 -0
  444. package/render/surface.js +69 -0
  445. package/render/uniformDecl.js +29 -0
  446. package/types/common.d.ts +34 -0
  447. package/types/core.d.ts +1965 -0
  448. package/types/gameplay.d.ts +1822 -0
  449. package/types/generated/core/Audio.d.ts +200 -0
  450. package/types/generated/core/Batching.d.ts +47 -0
  451. package/types/generated/core/Budget.d.ts +90 -0
  452. package/types/generated/core/Commits.d.ts +31 -0
  453. package/types/generated/core/DebugOverrides.d.ts +52 -0
  454. package/types/generated/core/Events.d.ts +89 -0
  455. package/types/generated/core/I18n.d.ts +30 -0
  456. package/types/generated/core/Input.d.ts +118 -0
  457. package/types/generated/core/Jobs.d.ts +41 -0
  458. package/types/generated/core/Ops.d.ts +203 -0
  459. package/types/generated/core/Random.d.ts +49 -0
  460. package/types/generated/core/Rays.d.ts +49 -0
  461. package/types/generated/core/Saves.d.ts +162 -0
  462. package/types/generated/core/Stream.d.ts +93 -0
  463. package/types/generated/core/Threads.d.ts +82 -0
  464. package/types/generated/core/Views.d.ts +33 -0
  465. package/types/generated/core/audioVoice.d.ts +47 -0
  466. package/types/generated/core/page.d.ts +18 -0
  467. package/types/generated/core/session.d.ts +48 -0
  468. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  469. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  470. package/types/generated/modules/flow/index.d.ts +10 -0
  471. package/types/generated/modules/grid/Grid.d.ts +151 -0
  472. package/types/generated/modules/grid/Layer.d.ts +65 -0
  473. package/types/generated/modules/grid/index.d.ts +86 -0
  474. package/types/generated/modules/hlod/index.d.ts +11 -0
  475. package/types/generated/modules/hud/index.d.ts +10 -0
  476. package/types/generated/modules/lights/index.d.ts +13 -0
  477. package/types/generated/modules/music/Music.d.ts +111 -0
  478. package/types/generated/modules/net/Net.d.ts +34 -0
  479. package/types/generated/modules/net/index.d.ts +53 -0
  480. package/types/generated/modules/net/transports.d.ts +58 -0
  481. package/types/generated/modules/particles/Particles.d.ts +69 -0
  482. package/types/generated/modules/sky/Sky.d.ts +145 -0
  483. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  484. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  485. package/types/generated/modules/water/Water.d.ts +29 -0
  486. package/types/generated/modules/weather/Weather.d.ts +62 -0
  487. package/types/generated/modules/world/World.d.ts +242 -0
  488. package/types/generated/modules/world/index.d.ts +15 -0
  489. package/types/generated/render/PostFX.d.ts +125 -0
  490. package/types/generated/render/materials.d.ts +100 -0
  491. package/types/generated/render/patches.d.ts +41 -0
  492. package/types/generated/ui/Focus.d.ts +11 -0
  493. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  494. package/types/generated/ui/UI.d.ts +57 -0
  495. package/types/nav.d.ts +52 -0
  496. package/types/physics.d.ts +592 -0
  497. package/types/style.d.ts +638 -0
  498. package/types/worker.d.ts +11 -0
  499. package/types/world.d.ts +772 -0
  500. package/ui/Focus.js +51 -0
  501. package/ui/LoadingScreen.js +42 -0
  502. package/ui/Parts.js +199 -0
  503. package/ui/UI.js +167 -0
  504. package/ui/defaults.js +85 -0
  505. package/ui/theme.js +124 -0
  506. package/ui/touchPart.js +49 -0
@@ -0,0 +1,220 @@
1
+ // Materials and shaders:
2
+ // 1. Material factory makeMaterial(role, params): modules ask the style pack for a material; the pack decides the look (matte, glossy, realistic, toon)
3
+ // 2. Effects injected into stock three.js materials (shadows, fog and tone mapping kept): wind sway, cloud shadows, season tint, ground detail texture
4
+ //
5
+ // Style pack usage (an entry may also be a Material instance or a function returning any Material, see makeMaterial):
6
+ // materials: {
7
+ // default: { type: 'lambert' }, // 'lambert' matte | 'phong' glossy | 'standard' realistic PBR | 'toon' cartoon bands
8
+ // terrain: { type: 'standard', roughness: 0.95 },
9
+ // vegetation: { type: 'toon', steps: 3 },
10
+ // character: { type: 'toon', steps: 3 },
11
+ // building: { type: 'standard', roughness: 0.8, metalness: 0 },
12
+ // water: { type: 'phong', shininess: 90 },
13
+ // }
14
+ // Role names are open: a game can add its own and fetch it with makeMaterial('furniture', { color: 0x8a5a36 }).
15
+ import * as THREE from 'three';
16
+ import { closest, warnMissing, warnOnce, checkOptions } from '../core/validate.js';
17
+ import { patchMaterial, copyPatches } from './patches.js';
18
+ import { declareUniforms } from './uniformDecl.js';
19
+ import { EFFECTS } from './effects.js';
20
+ import { detailPatch } from './detail.js';
21
+ import { applySurface } from './surface.js';
22
+ import { lightingPatch, rampTexture } from './lighting.js';
23
+ import { groundDetail, materialOverrides, materialReplace, materialPatches, materialMade, surfaceLighting, surfaceRamp } from './lookSurface.js';
24
+ /** @import { ColorLike, Material, BufferGeometry } from '../types/common' */
25
+
26
+ // ---------- style pack per engine ----------
27
+ // Live engines in creation order: only makeMaterial called without an engine (a game's module-level code) uses the first one's style pack
28
+ const ENGINES = [];
29
+ /**
30
+ * Register an engine's style pack and assets for makeMaterial; returns a handle whose remove() unregisters it (engine.dispose)
31
+ * @internal
32
+ * @param {{ style: any, assets: any }} engine
33
+ * @returns {{ remove(): void }}
34
+ */
35
+ export function registerEngine(engine) {
36
+ ENGINES.push(engine);
37
+ return { remove: () => { const i = ENGINES.indexOf(engine); if (i >= 0) ENGINES.splice(i, 1); } };
38
+ }
39
+ function owner(engine) {
40
+ if (engine) return engine;
41
+ if (ENGINES.length > 1 && ENGINES.some(e => e.style !== ENGINES[0].style))
42
+ warnOnce(`makeMaterial: ${ENGINES.length} engines with different style packs are running; using the first one's. Pass the engine as the third argument: makeMaterial(role, params, engine)`);
43
+ return ENGINES[0] ?? null;
44
+ }
45
+
46
+ // ---------- material factory ----------
47
+ const toonRamps = new Map();
48
+ function toonRamp(steps) {
49
+ if (!toonRamps.has(steps)) {
50
+ const data = new Uint8Array(steps * 4);
51
+ for (let i = 0; i < steps; i++) { const v = Math.round(((i + 1) / steps) * 255); data.set([v, v, v, 255], i * 4); }
52
+ const t = new THREE.DataTexture(data, steps, 1); t.minFilter = t.magFilter = THREE.NearestFilter; t.needsUpdate = true;
53
+ toonRamps.set(steps, t);
54
+ }
55
+ return toonRamps.get(steps);
56
+ }
57
+ const TYPES = { lambert: THREE.MeshLambertMaterial, phong: THREE.MeshPhongMaterial, standard: THREE.MeshStandardMaterial, physical: THREE.MeshPhysicalMaterial, toon: THREE.MeshToonMaterial, basic: THREE.MeshBasicMaterial };
58
+
59
+ // A style pack's materials can give them a look, or add new names.
60
+ /**
61
+ * Material roles the engine itself uses
62
+ * @type {string[]}
63
+ */
64
+ export const MATERIAL_PURPOSES = ['default', 'terrain', 'vegetation', 'character', 'water', 'pickup', 'prop'];
65
+
66
+ // The style pack's materials[role] (or materials.default) decides the material; params are this call's specifics (color, vertex colors, double-sided...).
67
+ // Only properties the material has are set, so one params object works for any material, built-in or custom.
68
+ // Spec keys handled by makeMaterial / applySurface rather than copied onto the material
69
+ const SPEC_KEYS = ['steps', 'ramp', 'soften', 'repeat', 'wrap', 'detail', 'lighting'];
70
+ const isSpec = e => e && !e.isMaterial && typeof e !== 'function';
71
+ /**
72
+ * Create a material by role: makeMaterial('furniture', { color: 0x8a5a36 }); the look comes from the style pack's materials[role] (unlisted roles use materials.default).
73
+ * Roles the engine uses: default terrain vegetation character water pickup prop (MATERIAL_PURPOSES); a game may pick new names (e.g. 'building'),
74
+ * and a name close to an existing role ('props', 'charcter') warns in dev.
75
+ * A style pack entry has one of three forms; params are then applied to the result (keys the material lacks are skipped):
76
+ * @example
77
+ * materials: {
78
+ * default: { type: 'toon', steps: 3 }, // spec: type lambert | phong | standard | physical | toon | basic, plus properties
79
+ * water: new THREE.MeshMatcapMaterial({ matcap: tex }), // instance: cloned on every call
80
+ * prop: (params, purpose, engine) => new THREE.ShaderMaterial({ ... }), // function: returns any three.js Material
81
+ * }
82
+ * A pack Material instance is cloned with its shader patches (applyEffects) kept.
83
+ * Whose style pack decides: engine.makeMaterial(purpose, params) (this engine's) or the third argument; without either the first live engine's
84
+ * (fine for a one-engine game; engine code and style packs always pass the engine, and two engines on the page warn in dev).
85
+ * @param {string} [purpose]
86
+ * @param {{ color?: ColorLike, [prop: string]: any }} [params]
87
+ * @param {{ style: any }} [engine]
88
+ * @returns {Material}
89
+ */
90
+ export function makeMaterial(purpose = 'default', params = {}, engine = undefined) {
91
+ const M = owner(engine)?.style?.materials || {};
92
+ // New role names are allowed; warn only when a name is close to an existing one (probably a typo)
93
+ if (!(purpose in M) && !MATERIAL_PURPOSES.includes(purpose)) {
94
+ const known = [...new Set([...MATERIAL_PURPOSES, ...Object.keys(M)])];
95
+ if (closest(purpose, known)) warnMissing('material', purpose, known);
96
+ }
97
+ const eng = owner(engine), rep = materialReplace(eng, purpose); // look.materials.replace(role, ...) beats the style's entry
98
+ const entry = rep ?? M[purpose] ?? M.default, key = purpose in M ? purpose : 'default';
99
+ let m, props = params;
100
+ if (entry?.isMaterial) m = copyPatches(entry, entry.clone());
101
+ else if (typeof entry === 'function') {
102
+ m = entry(params, purpose, eng);
103
+ if (!m?.isMaterial) throw new Error(`style.materials.${key} returned ${m}; the function must return a three.js Material`);
104
+ } else {
105
+ // A spec layers on top of materials.default when that is a spec too
106
+ // look.materials.set layers (game / debug) lie over the style's spec; look.surface.ramp over a toon material's own ramp
107
+ const merged = { ...(isSpec(M.default) ? M.default : {}), ...entry, ...materialOverrides(eng, 'default'), ...(purpose === 'default' ? {} : materialOverrides(eng, purpose)), ...params };
108
+ if ((merged.type ?? 'lambert') === 'toon') Object.assign(merged, surfaceRamp(eng)); // the pack-wide ramp wins over the spec's own
109
+ const { type = 'lambert', steps = 3, ramp, soften, ...rest } = merged;
110
+ const Ctor = TYPES[type];
111
+ if (!Ctor) throw new Error(`style.materials.${key}: unknown type '${type}'; use ${Object.keys(TYPES).join(' | ')}, or give a Material instance or a function (params, purpose) => Material`);
112
+ m = new Ctor();
113
+ if (type === 'toon') m.gradientMap = ramp ? rampTexture(ramp, soften) : toonRamp(steps);
114
+ else if (ramp || soften !== undefined) throw new Error(`style.materials.${key}: ramp / soften belong to type 'toon' (this is '${type}')`);
115
+ props = applySurface(m, rest, `style.materials.${key}`, eng, surfaceLighting(eng));
116
+ }
117
+ // the pack's style.lighting also shapes pack Materials and function results that are plain three.js lit materials (specs got it above)
118
+ if (props === params && surfaceLighting(eng) && (m.isMeshStandardMaterial || m.isMeshLambertMaterial || m.isMeshPhongMaterial || m.isMeshToonMaterial))
119
+ patchMaterial(m, [lightingPatch(surfaceLighting(eng), 'style.lighting')]);
120
+ for (const k in props) {
121
+ if (k === 'type' || !(k in m)) continue;
122
+ const v = props[k];
123
+ if (m[k]?.isColor) m[k].set(v); else if (m[k]?.isVector2 && Array.isArray(v)) m[k].set(...v); else m[k] = v;
124
+ }
125
+ // A key this material lacks is skipped on purpose (one params object works for any material type), but a key that looks like a typo of a real
126
+ // property ('roughnes') warns once with the suggestion. loose: keys with no close match (a spec shared across types) stay silent.
127
+ // `k in m` also finds accessor properties on the prototype (MeshPhysicalMaterial clearcoat, sheen, ...), which Object.keys does not list
128
+ const unknown = Object.fromEntries(Object.entries(params).filter(([k]) => !(k in m)));
129
+ checkOptions(`makeMaterial('${purpose}')`, unknown, [...Object.keys(m), ...SPEC_KEYS, 'type'], { loose: true });
130
+ m.userData.purpose = purpose;
131
+ // Minimal provenance for inspect.scene (diagnostic only, one small object per material): which layer supplied the spec
132
+ m.userData.materialSource = { role: purpose, from: !entry ? (Object.keys(params).length ? 'call-params' : 'default') : entry.isMaterial ? 'pack-instance' : typeof entry === 'function' ? 'pack-function' : 'pack-spec', keys: Object.keys(params) };
133
+ const added = materialPatches(eng, purpose); // look.materials.patch(name, patch, { roles })
134
+ if (added.length) patchMaterial(m, added);
135
+ materialMade(eng, purpose, m);
136
+ m.needsUpdate = true;
137
+ return m;
138
+ }
139
+
140
+ // ---------- shader effects (named patches, see patches.js; the built-in ones are in effects.js) ----------
141
+ // A style's own sway function (style.wind.glsl): must define threedogWind(); its uniforms are declared for it
142
+ export function windCustom({ glsl, uniforms }) {
143
+ if (!/void\s+threedogWind\s*\(/.test(glsl || '')) throw new Error('style.wind.glsl must define `void threedogWind(inout vec3 transformed, vec3 ip, vec3 position)`: move the vertex (object space) by the sway; ip = world position of this instance, uTime / uWind / uWindFreq / THREEDOG_WIND_AMP are in scope');
144
+ return { glsl, ...declareUniforms('style.wind.uniforms', uniforms) };
145
+ }
146
+ /**
147
+ * Add effects to any material (built-in, from a style pack, or third-party); returns the same material. The one entry for shader effects:
148
+ * wind (sway amplitude; the shadow sways too, nothing else to set up), clouds (drifting cloud shadows, default on; how dark is
149
+ * style.clouds.shadow), season ('foliage' | 'ground' seasonal tint), and patches: your own named patches (see ShaderPatch in
150
+ * render/patches.js), detail (grain / paper / strokes / a texture over the surface, see MaterialDetail in types/style.d.ts; a texture given by
151
+ * asset name loads from `engine`, default the first live engine). The 'world' patch (varying vThreedogWorld, world position) comes with clouds, and is added for any of your
152
+ * patches that lists it in needs.patches.
153
+ * Built-in effects the material cannot take (MeshBasicMaterial has no lighting chunk for clouds) are skipped with a one-time warning;
154
+ * your own patches throw when their anchor is missing. Calling again with the same effect replaces it.
155
+ * @example
156
+ * applyEffects(new THREE.MeshToonMaterial({ color: 0x5a8a3a }), { wind: 0.03, season: 'foliage' });
157
+ * applyEffects(mat, { clouds: false, patches: [{ name: 'snap', cacheKey: 64, uniforms: { uGrid: { value: 64 } },
158
+ * glsl: { vertex: { pars: 'uniform float uGrid;', project_vertex: 'gl_Position.xy = floor(gl_Position.xy / gl_Position.w * uGrid) / uGrid * gl_Position.w;' } } }] });
159
+ * @param {Material} material
160
+ * @param {{ wind?: number | { amplitude: number, glsl: string, uniforms?: Record<string, any> }, clouds?: boolean, season?: 'foliage' | 'ground', detail?: import('./detail.js').DetailOptions, engine?: { assets: any }, patches?: import('./patches.js').ShaderPatch[] }} [opts]
161
+ * @returns {Material}
162
+ */
163
+ export function applyEffects(material, { wind, clouds = true, season, detail, engine, patches } = {}) {
164
+ const list = [];
165
+ if (clouds || patches?.some(p => p.needs?.patches?.includes('world'))) list.push(EFFECTS.world());
166
+ if (clouds) list.push(EFFECTS.clouds());
167
+ if (season) list.push(EFFECTS.season(season));
168
+ if (wind) list.push(typeof wind === 'number' ? EFFECTS.wind(wind) : EFFECTS.wind(wind.amplitude, windCustom(wind)));
169
+ if (detail) list.push(EFFECTS.world(), detailPatch(detail, owner(engine), 'detail'));
170
+ patchMaterial(material, list, { strict: false });
171
+ if (patches) patchMaterial(material, patches);
172
+ return material;
173
+ }
174
+
175
+ /**
176
+ * Terrain material: base (default the style's 'terrain' role with vertex colors) + cloud shadows + season tint + optional detail texture
177
+ * (style.terrain.detail). Pass the engine so its style pack and assets are used.
178
+ * @param {Material | null} [base]
179
+ * @param {{ style: any, assets: any }} [engine]
180
+ * @returns {Material}
181
+ */
182
+ export function terrainMaterial(base = null, engine = undefined) {
183
+ const e = owner(engine);
184
+ // look.ground.detail (style.terrain.detail) is the `detail` patch with its options (texture, or noise / glsl; top-down world projection, multiply)
185
+ const det = groundDetail(e), on = det && ((det.texture && e?.assets) || det.noise || det.glsl);
186
+ return applyEffects(base || makeMaterial('terrain', { vertexColors: true }, e ?? undefined),
187
+ { season: 'ground', engine: e ?? undefined, ...(on && { detail: { scale: 0.25, strength: 0.35, ...det } }) });
188
+ }
189
+
190
+ /**
191
+ * Merge several geometries into one vertex-colored geometry (a tree = trunk + canopy in one draw call): [[geometry, color], ...].
192
+ * flat (default true): one normal per triangle, the faceted low-poly look; false keeps each part's own (smooth) normals.
193
+ * UVs are kept when every part has them, so the merged model can still take a texture.
194
+ * @example
195
+ * const trunk = new THREE.CylinderGeometry(0.2, 0.3, 2).translate(0, 1, 0), crown = new THREE.SphereGeometry(1.2).translate(0, 2.6, 0);
196
+ * const tree = mergeColored([[trunk, 0x7a5536], [crown, 0x4c8a3b]], { flat: false }); // smooth crown
197
+ * @param {[BufferGeometry, ColorLike][]} parts
198
+ * @param {{ flat?: boolean }} [opts]
199
+ * @returns {BufferGeometry}
200
+ */
201
+ export function mergeColored(parts, { flat = true } = {}) {
202
+ const pos = [], nor = [], col = [], uv = [];
203
+ const keepUV = parts.every(([g]) => g.attributes.uv);
204
+ for (const [g0, hex] of parts) {
205
+ if (!flat && !g0.attributes.normal) g0.computeVertexNormals();
206
+ const g = g0.index ? g0.toNonIndexed() : g0;
207
+ if (flat) g.computeVertexNormals();
208
+ const c = new THREE.Color(hex), p = g.attributes.position.array, n = g.attributes.normal.array;
209
+ for (let i = 0; i < p.length; i++) { pos.push(p[i]); nor.push(n[i]); }
210
+ for (let i = 0; i < p.length / 3; i++) col.push(c.r, c.g, c.b);
211
+ if (keepUV) for (const v of g.attributes.uv.array) uv.push(v);
212
+ }
213
+ const g = new THREE.BufferGeometry();
214
+ g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
215
+ g.setAttribute('normal', new THREE.Float32BufferAttribute(nor, 3));
216
+ g.setAttribute('color', new THREE.Float32BufferAttribute(col, 3));
217
+ if (keepUV) g.setAttribute('uv', new THREE.Float32BufferAttribute(uv, 2));
218
+ g.computeBoundingSphere();
219
+ return g;
220
+ }
@@ -0,0 +1,252 @@
1
+ // Named shader patches: one way to add shader code to any three.js material (WebGLRenderer only).
2
+ // A patch says where its code goes (after or before a `#include <chunk>` anchor), which uniforms it needs and what makes its
3
+ // program unique (cacheKey). Patches stack: the material's own onBeforeCompile runs first, then every patch in the order added,
4
+ // and the program cache key joins all of them, so two patches never overwrite each other and differently-parameterised
5
+ // materials never share a program. A missing anchor is reported when the patch is added, not discovered as a silent no-op.
6
+ // GLSL lives under `glsl`; a WebGPU node version would be a separate field once a WebGPU path exists (WebGPURenderer does not
7
+ // run onBeforeCompile). Engine uniforms (engine.uniforms: uTime, uWind, uCloud...) are resolved per renderer when the program
8
+ // compiles, so one material works under any engine and two engines on a page each drive their own time and weather.
9
+ // A patch that moves vertices (shadow: true) owns its shadow: meshes using the material get matching depth and distance
10
+ // materials automatically (see the customDepthMaterial / customDistanceMaterial defaults below), callers never set them.
11
+ // material.clone() does not carry patches (three's Material.copy skips onBeforeCompile): copy them with copyPatches(from, to).
12
+ //
13
+ // Composition contract (each part is checked, so a bad combination fails loudly in development instead of rendering wrong):
14
+ // needs.data program inputs the code reads, named like three's program parameters ('instancing', 'instancingColor',
15
+ // 'vertexColors', 'skinning', 'batching'); checked when the program compiles, one console.error per material.
16
+ // needs.patches patches that must already be on the material (their varyings / functions are used); checked when added.
17
+ // conflicts patch names this one cannot share a material with (both write the same output); checked when added, both ways.
18
+ // uniforms a name belongs to one patch: two patches bringing different objects under one uniform name is a conflict
19
+ // (the same engine uniform, e.g. engine.uniforms.uTime, counts as one object).
20
+ // shadow render steps: without it the patch runs only in the color pass; with it its vertex code also runs in the
21
+ // depth pass (directional / spot shadows) and the distance pass (point-light shadows).
22
+ // cacheKey must change whenever the GLSL text changes (defines, branches), never for uniform values. The program key is
23
+ // the material's own key + '|threedog:' + name=cacheKey of every patch in order; one name + cacheKey producing
24
+ // two different GLSL texts throws, since those materials would silently share one program.
25
+ import * as THREE from 'three';
26
+ import { closest } from '../core/validate.js';
27
+ import { sameUniform, resolveUniform } from './engineUniforms.js';
28
+ /** @import { Material } from '../types/common' */
29
+
30
+ /**
31
+ * @typedef {{ before?: string, after?: string, replace?: string } | string} PatchCode code for one anchor (a plain string goes after the include;
32
+ * replace swaps the include itself for new code, one patch per anchor)
33
+ * @typedef {{ name: string, cacheKey?: string | number, uniforms?: Record<string, { value: any }>, shadow?: boolean,
34
+ * needs?: { data?: string[], patches?: string[] }, conflicts?: string[],
35
+ * glsl?: { vertex?: Record<string, PatchCode>, fragment?: Record<string, PatchCode> } }} ShaderPatch
36
+ * glsl.vertex / glsl.fragment: anchor chunk name -> code; the key `pars` is declarations placed at the top of the shader.
37
+ * shadow: the patch moves vertices, so the depth and point-light distance passes run its vertex code too.
38
+ * needs.data: program inputs read, e.g. ['instancing']; needs.patches: patches it builds on, e.g. ['world'] (the vThreedogWorld varying).
39
+ * conflicts: patch names it cannot be combined with. cacheKey: changes whenever the GLSL text changes (see the header).
40
+ */
41
+
42
+ // Shader source of built-in materials, to check anchors before the first compile
43
+ const LIB = { MeshBasicMaterial: 'basic', MeshLambertMaterial: 'lambert', MeshPhongMaterial: 'phong', MeshStandardMaterial: 'standard',
44
+ MeshPhysicalMaterial: 'physical', MeshToonMaterial: 'toon', MeshMatcapMaterial: 'matcap', MeshDepthMaterial: 'depth',
45
+ MeshDistanceMaterial: 'distance', MeshNormalMaterial: 'normal', PointsMaterial: 'points', SpriteMaterial: 'sprite' };
46
+ function sourceOf(m, stage) {
47
+ if (m.isShaderMaterial) return m[stage + 'Shader'];
48
+ const id = LIB[m.type];
49
+ return id ? THREE.ShaderLib[id][stage + 'Shader'] : null;
50
+ }
51
+ /** Anchors the patch needs that the material's shader lacks ([] = fits; null = unknown material, checked at compile time) */
52
+ function missing(m, p) {
53
+ const out = [];
54
+ for (const stage of ['vertex', 'fragment']) {
55
+ const src = sourceOf(m, stage);
56
+ if (src == null) return null;
57
+ for (const k in p.glsl?.[stage] || {}) if (k !== 'pars' && !src.includes(`#include <${k}>`)) out.push(`${stage} <${k}>`);
58
+ }
59
+ return out;
60
+ }
61
+
62
+ // Why a patch cannot join the material's list, or '' (composition rules from the header)
63
+ let deriving = false; // re-entrancy flag, set and cleared inside one synchronous call (never across a frame)
64
+ const CODE = new Map(); // name=cacheKey -> GLSL text, to catch a cacheKey that does not follow the code
65
+ const replaced = p => ['vertex', 'fragment'].flatMap(st => Object.entries(p.glsl?.[st] || {}).filter(([, c]) => typeof c === 'object' && c.replace != null).map(([k]) => st + k));
66
+ const DATA = ['instancing', 'instancingColor', 'vertexColors', 'skinning', 'batching'];
67
+ function clash(list, p) {
68
+ for (const d of p.needs?.data || []) if (!DATA.includes(d)) {
69
+ const near = closest(d, DATA);
70
+ return `patch '${p.name}' needs.data names '${d}', which is not a program input; use ${DATA.join(' | ')}` + (near ? ` (did you mean '${near}'?)` : '');
71
+ }
72
+ const others = list.filter(q => q.name !== p.name);
73
+ for (const q of others) if (p.conflicts?.includes(q.name) || q.conflicts?.includes(p.name))
74
+ return `patches '${q.name}' and '${p.name}' cannot be combined on one material; keep one of them, or use two materials`;
75
+ for (const n of p.needs?.patches || []) if (!others.some(q => q.name === n))
76
+ return `patch '${p.name}' needs patch '${n}' on the material first; put '${n}' before it in the patches list (applyEffects adds the built-in 'world' itself when a patch needs it), or fix why '${n}' was skipped`;
77
+ for (const q of others) for (const u in p.uniforms || {}) if (q.uniforms?.[u] && !sameUniform(q.uniforms[u], p.uniforms[u]))
78
+ return `patches '${q.name}' and '${p.name}' both bring a uniform named '${u}'; rename one (prefix it with the patch name), or share engine.uniforms.${u}`;
79
+ const mine = replaced(p);
80
+ for (const q of others) if (replaced(q).some(k => mine.includes(k)))
81
+ return `patches '${q.name}' and '${p.name}' both replace one chunk; keep one, or add code before / after it`;
82
+ const key = p.name + '=' + (p.cacheKey ?? ''), code = JSON.stringify(p.glsl ?? {});
83
+ if (CODE.has(key) && CODE.get(key) !== code)
84
+ return `patch '${p.name}' produced different GLSL under the same cacheKey '${p.cacheKey ?? ''}'; put every value that changes the code into cacheKey`;
85
+ CODE.set(key, code);
86
+ return '';
87
+ }
88
+
89
+ const LISTS = new WeakMap(); // material -> its patches (not userData: that gets JSON-cloned and exported to glTF)
90
+ const PROTO_COMPILE = THREE.Material.prototype.onBeforeCompile;
91
+ const warned = new Set();
92
+
93
+ function apply(shader, list, m, renderer) {
94
+ for (const p of list) for (const d of p.needs?.data || []) if (!shader[d]) {
95
+ const tag = `${m.uuid}:${p.name}:${d}`;
96
+ if (!warned.has(tag)) { warned.add(tag); console.error(`[threedog] patch '${p.name}' needs '${d}', which this mesh does not provide (e.g. 'instancing' needs an InstancedMesh, 'vertexColors' needs material.vertexColors and a color attribute)`); }
97
+ }
98
+ for (const stage of ['vertex', 'fragment']) {
99
+ const key = stage + 'Shader', pars = [], at = new Map();
100
+ for (const p of list) {
101
+ for (const u in p.uniforms) shader.uniforms[u] = resolveUniform(p.uniforms[u], renderer);
102
+ for (const [k, code] of Object.entries(p.glsl?.[stage] || {})) {
103
+ if (k === 'pars') { pars.push(code); continue; }
104
+ const slot = at.get(k) || at.set(k, { before: [], after: [], replace: null }).get(k);
105
+ if (typeof code === 'string') slot.after.push(code);
106
+ else { if (code.before) slot.before.push(code.before); if (code.after) slot.after.push(code.after); if (code.replace != null) slot.replace = code.replace; }
107
+ }
108
+ }
109
+ let src = shader[key];
110
+ for (const [k, { before, after, replace }] of at) {
111
+ const inc = `#include <${k}>`;
112
+ if (!src.includes(inc)) {
113
+ const tag = `${m.type}:${k}`;
114
+ if (!warned.has(tag)) { warned.add(tag); console.error(`[threedog] shader patch anchor ${inc} not found in ${m.type}; add it to your shader or #include the threedog_* chunks by hand (see render/patches.js)`); }
115
+ continue;
116
+ }
117
+ src = src.replace(inc, () => [...before, replace ?? inc, ...after].join('\n'));
118
+ }
119
+ shader[key] = pars.join('\n') + '\n' + src;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Add named shader patches to any material; returns the same material. Stacks with the material's own onBeforeCompile
125
+ * and with earlier patches; a patch with the same name replaces the earlier one. A missing anchor throws (strict) or
126
+ * skips that patch with a one-time warning (strict: false, used for the engine's automatic effects). Composition errors
127
+ * (conflicts, a needed patch missing, a uniform name taken, cacheKey not following the code) throw the same way.
128
+ * @example
129
+ * // reads the world position varying of 'clouds', and must not share a material with the engine's 'wind'
130
+ * patchMaterial(mat, [{ name: 'ripple', needs: { patches: ['clouds'] }, conflicts: ['wind'], shadow: true, ... }]);
131
+ * patchMaterial(mat, [{ name: 'snap', cacheKey: 64, uniforms: { uGrid: { value: 64 } }, glsl: {
132
+ * vertex: { pars: 'uniform float uGrid;', project_vertex: 'gl_Position.xy = floor(gl_Position.xy / gl_Position.w * uGrid) / uGrid * gl_Position.w;' } } }]);
133
+ * @internal games and style packs go through applyEffects(material, { patches })
134
+ * @param {Material} material
135
+ * @param {ShaderPatch[]} patches
136
+ * @param {{ strict?: boolean }} [opts]
137
+ * @returns {Material}
138
+ */
139
+ export function patchMaterial(material, patches, { strict = true } = {}) {
140
+ const m = /** @type {any} */ (material);
141
+ let list = LISTS.get(m);
142
+ if (!list) {
143
+ LISTS.set(m, list = []);
144
+ const prev = m.onBeforeCompile;
145
+ const prevKey = Object.hasOwn(m, 'customProgramCacheKey') ? m.customProgramCacheKey.bind(m) : prev !== PROTO_COMPILE ? () => prev.toString() : () => '';
146
+ m.onBeforeCompile = function (shader, renderer) { if (prev !== PROTO_COMPILE) prev.call(this, shader, renderer); apply(shader, list, m, renderer); };
147
+ m.addEventListener('dispose', () => dropShadow(m));
148
+ m.customProgramCacheKey = () => prevKey() + '|threedog:' + list.map(p => p.name + '=' + (p.cacheKey ?? '')).join(',');
149
+ }
150
+ for (const p of patches) {
151
+ const bad = deriving ? '' : clash(list, p);
152
+ if (bad) {
153
+ if (strict) throw new Error(`[threedog] ${bad}`);
154
+ console.error(`[threedog] ${bad}; patch '${p.name}' skipped`);
155
+ continue;
156
+ }
157
+ const gaps = missing(m, p);
158
+ if (gaps?.length) {
159
+ const msg = `patch '${p.name}' needs ${gaps.join(', ')}, which ${m.type} does not have`;
160
+ if (strict) throw new Error(msg + '; use a material that has these chunks, or #include the threedog_* chunks in your own shader');
161
+ if (!warned.has(msg)) { warned.add(msg); console.warn('[threedog] ' + msg + '; skipped'); }
162
+ continue;
163
+ }
164
+ const i = list.findIndex(q => q.name === p.name);
165
+ if (i >= 0) list[i] = p; else list.push(p);
166
+ }
167
+ dropShadow(m);
168
+ m.needsUpdate = true;
169
+ return m;
170
+ }
171
+
172
+ /**
173
+ * Names of the patches on a material (in order), e.g. ['clouds', 'tint', 'wind']
174
+ * @param {Material} material
175
+ * @returns {string[]}
176
+ */
177
+ export function materialPatches(material) { return (LISTS.get(material) || []).map(p => p.name); }
178
+
179
+ /**
180
+ * Take the patch named `name` off a material (no-op when absent); returns the material.
181
+ * @internal sky cascades
182
+ * @param {Material} material
183
+ * @param {string} name
184
+ * @returns {Material}
185
+ */
186
+ export function unpatchMaterial(material, name) {
187
+ const list = LISTS.get(material), i = list ? list.findIndex(p => p.name === name) : -1;
188
+ if (i >= 0) { list.splice(i, 1); dropShadow(material); material.needsUpdate = true; }
189
+ return material;
190
+ }
191
+
192
+ /**
193
+ * Give `to` the patches of `from`, e.g. after `from.clone()` (three's Material.copy does not carry onBeforeCompile, so a clone
194
+ * starts without patches). Returns `to`.
195
+ * @internal engine code that clones materials (makeMaterial, vegetation fromModel) calls it
196
+ * @param {Material} from
197
+ * @param {Material} to
198
+ * @returns {Material}
199
+ */
200
+ export function copyPatches(from, to) {
201
+ const list = LISTS.get(from);
202
+ if (!list?.length || from === to) return to;
203
+ deriving = true; // already checked on `from`
204
+ try { return patchMaterial(to, list, { strict: false }); } finally { deriving = false; }
205
+ }
206
+
207
+ // ---------- shadows follow vertex-moving patches ----------
208
+ // Depth / distance materials carrying the material's vertex-moving patches; undefined when nothing moves. Cached per material
209
+ // and kind; patchMaterial and material.dispose() drop (and dispose) the cached ones, so patches added later are picked up.
210
+ const shadowMats = new WeakMap();
211
+ function dropShadow(material) {
212
+ const byKind = shadowMats.get(material);
213
+ if (byKind) for (const k in byKind) byKind[k]?.dispose();
214
+ shadowMats.delete(material);
215
+ }
216
+ const moves = m => !!LISTS.get(m)?.some(p => p.shadow);
217
+ /**
218
+ * Whether the material carries a vertex-moving patch (shadow: true, e.g. wind). Such code reads object space (position.y, the model
219
+ * origin), so baking these meshes into world space (merging, HLOD proxies) would change how they move.
220
+ * @internal
221
+ * @param {Material | Material[]} material
222
+ * @returns {boolean}
223
+ */
224
+ export function movesVertices(material) { return [].concat(material).some(moves); }
225
+ function shadowMaterial(material, kind) {
226
+ let byKind = shadowMats.get(material);
227
+ if (!byKind) shadowMats.set(material, byKind = {});
228
+ if (kind in byKind) return byKind[kind];
229
+ const moving = LISTS.get(material).filter(p => p.shadow).map(p => ({ ...p, needs: { data: p.needs?.data }, conflicts: undefined, glsl: { vertex: p.glsl?.vertex } }));
230
+ // three copies side, alphaTest, map and clipping from the drawn material onto the depth material on every draw
231
+ const base = kind === 'depth' ? new THREE.MeshDepthMaterial() : new THREE.MeshDistanceMaterial();
232
+ deriving = true; // vertex-only copies of patches already checked on the source material
233
+ try { return byKind[kind] = patchMaterial(base, moving, { strict: false }); } finally { deriving = false; }
234
+ }
235
+ // The shadow passes read object.customDepthMaterial (sun / spot) and customDistanceMaterial (point lights); three has no other hook.
236
+ // Their default (nothing assigned) becomes "my material's moving patches in that pass", so a wind material casts a swaying shadow
237
+ // however the mesh was built (game code, level load, instancing, a swapped material); an explicit assignment still wins. It must be
238
+ // on Mesh.prototype before any mesh exists (Object3D's constructor assigns both, which would otherwise make own properties).
239
+ // Explicit values live under a global symbol, so a second copy of this file (hot reload) redefining the accessor loses none.
240
+ for (const [prop, kind] of [['customDepthMaterial', 'depth'], ['customDistanceMaterial', 'distance']]) {
241
+ const own = Symbol.for('threedog.' + prop);
242
+ Object.defineProperty(THREE.Mesh.prototype, prop, {
243
+ configurable: true,
244
+ get() {
245
+ if (Object.hasOwn(this, own)) return this[own];
246
+ // multi-material mesh (trunk + leaves): one shadow material serves every group, so take the first one that moves
247
+ const m = Array.isArray(this.material) ? this.material.find(moves) : this.material;
248
+ return moves(m) ? shadowMaterial(m, kind) : undefined;
249
+ },
250
+ set(v) { if (v === undefined) delete this[own]; else this[own] = v; }, // Object3D's constructor assigns undefined
251
+ });
252
+ }
@@ -0,0 +1,86 @@
1
+ // look.post: the post-processing chain as a look part (recipes/52-look.md).
2
+ // set({ bloom: { strength: 0.6 }, vignette: false }) keys are '<effect>.<param>' and '<effect>.enabled'; false / true is the same as enabled
3
+ // patch('grain', glsl | { glsl, slot, order, uniforms, values }) generates a fuse effect named 'grain' (PostFuse in PostFX.js); patch('grain', null) removes it
4
+ // add(effect, { owner }) adds ONE custom pass (name, create | fuse, slot, order, params) without replacing the chain; returns { remove() }
5
+ // replace([effect, ...]) swaps the whole chain for these effects; replace(null) gives the style's chain back
6
+ // The old engine.post.add / enable and handle set / enable / remove were removed in 0.2 (they throw renamed-api): this part is the one way to change the chain, so describe().look
7
+ // and describe().render say who changed what. Style-pack effects (bloom, ao, outline ...) are the style layer; the keys come and go with the
8
+ // effects, so the part adds and removes its params as the chain changes (core/look/dynamic.js).
9
+ // Why '<effect>.<param>' keys and not one object per effect: layering and owners are per key, so a game can change bloom.strength and leave
10
+ // the style's bloom.threshold alone.
11
+ import { defineLookPart } from '../core/look/part.js';
12
+ import { codedError } from '../core/errorHints.js';
13
+
14
+ /** @param {any} post PostFX @param {any[]} styleDefs the style pack's effects */
15
+ export function definePostLook(post, styleDefs) {
16
+ const e = post.engine, low = e.tier === 'low', generated = new Map(), source = new Map();
17
+ const defaultOn = d => (d.enabled ?? true) && !(d.costly && low); // a costly effect starts off on low-tier devices unless the game said otherwise
18
+ const decl = h => {
19
+ const d = h._def, n = h.name;
20
+ return { [`${n}.enabled`]: { type: 'bool', default: !!defaultOn(d), cost: d.costly ? 'gpu' : 'uniform',
21
+ why: low && d.costly ? (post._offWhy[n] ?? `costly effect: off on low-tier devices`) : `post effect '${n}'${styleDefs.includes(d) ? ' of the style pack' : ''}`,
22
+ off: `look.post.set({ ${n}: ${defaultOn(d) ? 'false' : 'true'} })` },
23
+ ...Object.fromEntries(Object.entries(d.params ?? {}).map(([k, v]) => [`${n}.${k}`, { type: 'any', default: v, neutral: true, cost: d.fuse ? 'uniform' : 'recompile' }])) };
24
+ };
25
+ const styleValues = () => Object.fromEntries(post._list.filter(h => styleDefs.includes(h._def)).flatMap(h => Object.entries(h.params).map(([k, v]) => [`${h.name}.${k}`, v])));
26
+ /** The game layer records what differs from the default (createEngine({ post }), or an effect the game added) */
27
+ const record = h => { if (!styleDefs.includes(h._def) || h.enabled !== !!defaultOn(h._def)) part.write('game', { [`${h.name}.enabled`]: h.enabled }); };
28
+ const split = k => { const i = k.indexOf('.'); return [k.slice(0, i), k.slice(i + 1)]; };
29
+ const part = defineLookPart(e, {
30
+ id: 'post', group: 'screen', module: 'core', object: () => post.composer, docs: ['recipes/52-look.md'], applyAtStart: false,
31
+ params: Object.assign({}, ...post._list.map(decl)), style: styleValues,
32
+ read: () => ({}),
33
+ normalize(p) { // post.set({ vignette: false }) -> { 'vignette.enabled': false }
34
+ return Object.fromEntries(Object.entries(p).map(([k, v]) => (typeof v === 'boolean' && part.has(`${k}.enabled`) ? [`${k}.enabled`, v] : [k, v])));
35
+ },
36
+ apply(v, changed) {
37
+ const sets = new Map();
38
+ for (const k of changed) {
39
+ const [n, p] = split(k), h = post.get(n);
40
+ if (!h) continue;
41
+ if (p === 'enabled') { if (h.enabled !== !!v[k]) h._enable(!!v[k]); } else if (h.params[p] !== v[k]) (sets.get(h) ?? sets.set(h, {}).get(h))[p] = v[k];
42
+ }
43
+ for (const [h, p] of sets) h._set(p);
44
+ },
45
+ hooks: { '*': { signature: 'GLSL statements that edit `vec4 color` (see PostFuse in render/PostFX.js); spec { glsl, slot: "ldr", order, uniforms, values }', scope: ['vUv', 'tDiffuse', 'uTime', 'uResolution', 'fxHash(vec2)'] } },
46
+ extraSignatures: { add: 'add(effect, { owner })' },
47
+ applyHook(name, impl) {
48
+ if (impl != null && generated.has(name) && source.get(name) === impl) return; // the same spec again (a rolled-back write re-applies every hook): keep the built effect
49
+ generated.get(name)?._remove();
50
+ source.delete(name);
51
+ if (generated.delete(name)) part.retract(name + '.');
52
+ if (impl == null) return;
53
+ if (post.get(name)) throw new Error(`look.post.patch/add('${name}'): an effect named '${name}' already exists; pick another name, or change it with look.post.set({ '${name}.<param>': value })`);
54
+ const s = typeof impl === 'string' ? { glsl: impl } : impl, { slot, order, params, ...fuse } = s;
55
+ // add(effect) passes a whole effect (create | fuse): it keeps its own slot / order / enabled; patch(name, spec) is a fuse snippet in 'ldr'
56
+ const h = s.create || s.fuse ? post._add({ ...s, name }) : post._add({ name, fuse, slot: slot ?? 'ldr', order, params });
57
+ generated.set(name, h); source.set(name, impl); part.extend(decl(h));
58
+ },
59
+ replace: { accepts: 'an array of post effects ({ name, create | fuse, slot, order, params }); null gives the style\'s chain back',
60
+ loses: ['every effect the style, patch() or a replaced chain brought (their look.post values go with them)'] },
61
+ // checked before the record is written, so a wrong replace never reaches applyReplace (review H1)
62
+ validate: (k, v) => (k === '@replace' && !Array.isArray(v) ? 'is an array of effects like [bloom({ strength: 0.4 }), myGrain]; null gives the style chain back' : null),
63
+ applyReplace(impl) {
64
+ if (impl != null && !Array.isArray(impl)) throw new Error('look.post.replace(effects): effects is an array like [bloom({ strength: 0.4 }), myGrain]; null gives the style chain back');
65
+ post._building = true;
66
+ try {
67
+ for (const h of [...post._list]) { h._remove(); part.retract(h.name + '.'); }
68
+ generated.clear(); source.clear();
69
+ for (const d of impl ?? styleDefs) { const lowOff = impl == null && d.costly && low; const h = post._add(d, { enabled: lowOff ? false : undefined }); part.extend(decl(h)); }
70
+ part.restyle(impl ? {} : styleValues());
71
+ } finally { post._building = false; post._sync(); }
72
+ },
73
+ });
74
+ /** Add one custom pass; it is a patch under the effect's name, so owner layers, describe, remove and rollback work like every look verb */
75
+ part.add = (effect, o) => {
76
+ if (!effect || typeof effect.name !== 'string' || (typeof effect.create !== 'function' && !effect.fuse))
77
+ throw codedError('look-verb', "look.post.add(effect): needs { name: 'myEffect', create: (ctx) => pass } (or a fuse snippet { name, fuse: { glsl } }, see PostEffect)");
78
+ // checked here, before any write: the hook key is the effect name, so a second write under it would replace (and tear down) the first effect
79
+ if (post.get(effect.name)) throw codedError('look-verb', `look.post.add: post effect '${effect.name}' is already added; change it with look.post.set({ '${effect.name}.<param>': value }), or drop it with its handle.remove() / look.post.replace([...])`);
80
+ part.patch(effect.name, effect, o);
81
+ // patch's handle would drop the owner's WHOLE post layer (every other effect this owner added); remove only this effect's hook
82
+ return { remove: () => { part.patch(effect.name, null, o); } };
83
+ };
84
+ for (const h of post._list) record(h);
85
+ return { part };
86
+ }
@@ -0,0 +1,69 @@
1
+ // Surface keys of a material spec (used by makeMaterial): texture names (`map: 'rock.png'`), `detail`, `lighting`.
2
+ // Textures load through engine.assets.texture by name; a neutral stand-in sits in the slot until the image arrives, so nothing flashes.
3
+ import * as THREE from 'three';
4
+ import { closest, warnOnce } from '../core/validate.js';
5
+ import { placeholderTexture, EFFECTS } from './effects.js';
6
+ import { detailPatch } from './detail.js';
7
+ import { lightingPatch } from './lighting.js';
8
+ import { patchMaterial } from './patches.js';
9
+ import { surfaceDetail } from './lookSurface.js';
10
+
11
+ // Color textures are sRGB; the rest hold data and stay linear (three would otherwise gamma-decode normals and roughness)
12
+ const COLOR_SLOTS = ['map', 'emissiveMap', 'lightMap', 'sheenColorMap', 'specularColorMap'];
13
+ const DATA_SLOTS = ['normalMap', 'roughnessMap', 'metalnessMap', 'aoMap', 'bumpMap', 'alphaMap', 'displacementMap', 'specularMap', 'clearcoatMap',
14
+ 'clearcoatNormalMap', 'clearcoatRoughnessMap', 'sheenRoughnessMap', 'specularIntensityMap', 'transmissionMap', 'thicknessMap', 'iridescenceMap', 'anisotropyMap'];
15
+ const TEXTURE_SLOTS = [...COLOR_SLOTS, ...DATA_SLOTS];
16
+ const WRAPS = { repeat: THREE.RepeatWrapping, clamp: THREE.ClampToEdgeWrapping, mirror: THREE.MirroredRepeatWrapping };
17
+ const SURFACE_KEYS = ['repeat', 'wrap', 'detail', 'lighting'];
18
+
19
+ // 1x1 stand-in with no effect on the look: a flat normal for normalMap, white for everything else (gray would dim color and roughness)
20
+ function standIn(slot) {
21
+ if (slot === 'normalMap') return placeholderTexture('normal');
22
+ const t = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1); t.needsUpdate = true;
23
+ return t;
24
+ }
25
+
26
+ function loadSlot(m, slot, name, { repeat, wrap }, where, engine) {
27
+ if (!engine?.assets) throw new Error(`${where}.${slot}: '${name}' is an asset name but no engine is known; pass the engine (makeMaterial(role, params, engine)) or give a THREE.Texture`);
28
+ const stand = standIn(slot);
29
+ m[slot] = stand;
30
+ engine.assets.texture(name, COLOR_SLOTS.includes(slot) ? {} : { color: false }).then(t => {
31
+ const own = t.clone(); // the loaded image is shared; wrapping and repeat belong to this material
32
+ own.wrapS = own.wrapT = WRAPS[wrap]; if (repeat) own.repeat.set(repeat[0], repeat[1]);
33
+ own.needsUpdate = true;
34
+ m[slot] = own; stand.dispose();
35
+ }).catch(err => warnOnce(`${where}.${slot}: texture '${name}' did not load (${err.message}). Register it (engine.assets.manifest({ textures: { name: 'file.png' } })) or write its URL`));
36
+ }
37
+
38
+ /**
39
+ * Handle the surface keys of a material spec: asset names in texture slots are loaded and assigned, `repeat` / `wrap` shape them,
40
+ * `detail` / `lighting` add the named patches. Returns the properties left for makeMaterial to assign as they are.
41
+ * @internal
42
+ * @param {any} m the new material
43
+ * @param {Record<string, any>} props the spec's properties without type / steps
44
+ * @param {string} where e.g. 'style.materials.rock', for errors
45
+ * @param {any} engine
46
+ * @param {any} [lit] style.lighting (the pack's default for every lit material)
47
+ */
48
+ export function applySurface(m, props, where, engine, lit) {
49
+ const rest = {}, tex = { repeat: null, wrap: 'repeat' };
50
+ if (props.repeat != null) tex.repeat = typeof props.repeat === 'number' ? [props.repeat, props.repeat] : props.repeat;
51
+ if (props.wrap != null) {
52
+ if (!WRAPS[props.wrap]) throw new Error(`${where}.wrap '${props.wrap}' must be ${Object.keys(WRAPS).join(' | ')}`);
53
+ tex.wrap = props.wrap;
54
+ }
55
+ for (const k in props) {
56
+ if (SURFACE_KEYS.includes(k)) continue;
57
+ const v = props[k];
58
+ if (typeof v === 'string' && /map$/i.test(k)) {
59
+ if (!TEXTURE_SLOTS.includes(k)) throw new Error(`${where}.${k} is not a texture slot${closest(k, TEXTURE_SLOTS) ? `; did you mean '${closest(k, TEXTURE_SLOTS)}'?` : ''} (slots: ${TEXTURE_SLOTS.join(', ')})`);
60
+ if (!(k in m)) { warnOnce(`${where}.${k}: a '${m.type}' material has no ${k}; use type 'standard' (or 'physical' for clearcoat / sheen maps)`); continue; }
61
+ loadSlot(m, k, v, tex, where, engine);
62
+ } else rest[k] = v;
63
+ }
64
+ const det = props.detail === false ? null : props.detail ?? surfaceDetail(engine); // look.surface.detail is the pack-wide default
65
+ if (det) patchMaterial(m, [EFFECTS.world(), detailPatch(det, engine, `${where}.detail`)]);
66
+ const l = props.lighting === false ? null : { ...lit, ...props.lighting };
67
+ if (l && Object.keys(l).length) patchMaterial(m, [lightingPatch(l, `${where}.lighting`)]);
68
+ return rest;
69
+ }