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,39 @@
1
+ // Terrain defaults: the parameters of the machinery (chunks, flatten, height map, a game's own generator, colors). Pure data, no three.js
2
+ // dependency (the Worker reads it too). The engine has no built-in landform or ground types: without a height function (or a height map) the
3
+ // ground is flat at y = 0; generators such as noise hills and biome tables are presets a game passes in (e.g. terrainPreset() from
4
+ // @threedog/terrain-noise) or its own height / groundType functions.
5
+ export const DEFAULT_TERRAIN = {
6
+ seed: 1337,
7
+ chunkSize: 64, // chunk edge length (m)
8
+ resolution: 16, // cells per chunk; smaller is more "low-poly"
9
+ waterLevel: -Infinity, // no sea unless the game sets a level (terrainPreset() from @threedog/terrain-noise sets 0): water is world shape, not a default
10
+ flatten: [], // flattened plots: [{ x, z, radius, height? }], for villages and houses
11
+ // height map: { url | data: number array (row-major), width, height, size: [width m, length m], min, max, center: [x, z], outside } -- the terrain module reads the image and fills in data
12
+ heightmap: null,
13
+ // a game's own generator, pure functions (sent to workers as source: no outside variables): height(x, z, n) -> meters;
14
+ // groundType(x, z, h, slope, n) -> type name (null = 'default'). n = { fbm(x, z, octaves), noise(x, z), hash(x, z, salt), seed, waterLevel, params }
15
+ height: null,
16
+ groundType: null,
17
+ params: null, // plain data handed to height / groundType as n.params (a preset's settings); must be serializable
18
+ // How the ground gets its color (look only; style.terrain.config may set shading, colorResolution, normals, normalFn):
19
+ // 'smooth' blended per grid point | 'flat' one color and normal per triangle | 'texture' colors come from a per-chunk color map
20
+ // (colorResolution pixels per chunk edge, independent of the mesh resolution; vertex colors are plain white then)
21
+ shading: 'smooth',
22
+ colorResolution: 128, // texture mode: color map pixels per chunk edge (a border pixel is added on each side for seamless chunks)
23
+ normals: null, // texture mode only: lighting normals 'smooth' (default) | 'flat'; flat / smooth shading fix their own
24
+ // pure function (i, j, h, cell) -> [nx, ny, nz] replacing the smooth normal at grid point (i, j); h(i, j) is a grid-point height
25
+ // (null = central difference of the neighbors). Serialized to workers like height / groundType
26
+ normalFn: null,
27
+ // how each cell is cut into two triangles (shape, so it also moves engine.surface): 'fixed' the same diagonal everywhere |
28
+ // 'adaptive' along the diagonal with the smaller height difference | 'alternate' flips every other cell
29
+ diagonal: 'fixed',
30
+ // World outline (null = ground everywhere): { mask, edge, side, bottom, voidY }, see terrainShape.js and recipes/42-terrain-shape.md.
31
+ // mask (x, z, n) -> > 0 ground, pure like height; or a gray image { url | data, width, height, size: [w, l], center, threshold }
32
+ shape: null,
33
+ boundsPad: { up: 3, radius: 8 }, // chunk bounding sphere margin (m): center raised by up, radius grown by radius; raise for tall height-moving shaders
34
+ // Colors are art and come from the style pack (style.terrain): colors palette name -> color, biomeColors ground type -> palette names
35
+ // (two are blended by noise), steep [{ maxNormalY, colors }] slope colors. Empty here: every ground type is the neutral gray fallback
36
+ colors: {},
37
+ biomeColors: {},
38
+ steep: [],
39
+ };
@@ -0,0 +1,139 @@
1
+ // Terrain edits (engine.terrain.edit): dig, raise, flatten, and paint the ground type of cells (tilled soil, wet soil, a path).
2
+ // Records are plain data owned here: grid-point heights and cell types, saved with the save (key 'terrain'). The main-thread generator reads
3
+ // the same maps (so engine.surface / slope / groundType and collision see an edit at once); each worker job carries the edits around its chunk,
4
+ // so a chunk generated later -- or regenerated after the player walked away and back -- comes out edited, identically with threads on or off.
5
+ // Loaded chunks around an edit are rebuilt on the spot (mesh, vegetation, collision token); a worker result built before the edit is dropped.
6
+ import { checkOptions, DEV } from '../../core/validate.js';
7
+ import { xzOf } from '../../core/math.js';
8
+ import { updateColorMap } from './terrainTexture.js';
9
+
10
+ const EDIT_KEYS = ['radius', 'shape', 'raise', 'lower', 'flatten', 'paint'];
11
+ const STRINGS = {
12
+ none: "terrain.edit(): pass at least one of raise, lower, flatten or paint, e.g. engine.terrain.edit(pos, { radius: 2, lower: 1 })",
13
+ many: 'terrain.edit(): raise, lower and flatten all set the height; pass only one of them',
14
+ shape: "terrain.edit(): shape must be 'circle' or 'square', got {got}",
15
+ num: 'terrain.edit(): {k} must be a finite number, got {got}',
16
+ paint: "terrain.edit(): paint must be a ground type name such as 'tilled', or null to give the cells back their generated type; got {got}",
17
+ };
18
+ const fmt = (s, o) => s.replace(/\{(\w+)\}/g, (_, k) => o[k]);
19
+ const unkey = k => [Math.floor(k / 100000) - 50000, (k % 100000) - 50000];
20
+
21
+ /** @internal owned by ChunkManager (engine.terrain.edits) */
22
+ export class TerrainEdits {
23
+ constructor(engine, mgr) {
24
+ this.e = engine; this.mgr = mgr;
25
+ this.h = new Map(); // grid key -> height of grid point (i * cell, j * cell)
26
+ this.t = new Map(); // cell key -> ground type of cell [i, i + 1) x [j, j + 1)
27
+ this.ver = new Map(); // chunk key 'cx,cz' -> edit version (jobs carry it; an older result is stale)
28
+ this.attach();
29
+ engine.saves.register('terrain', { save: () => this.save(), load: d => this.load(d) });
30
+ }
31
+ /** Point the main-thread generator at the edit maps (again after the generator is rebuilt, e.g. a height map finished loading) */
32
+ attach() { this.mgr.T.useEdits(this.h, this.t); }
33
+
34
+ edit(position, o = {}) {
35
+ DEV && this.e.ops.guard('terrain.edit');
36
+ checkOptions('terrain.edit()', o, EDIT_KEYS);
37
+ const ops = ['raise', 'lower', 'flatten'].filter(k => o[k] != null);
38
+ if (!ops.length && !('paint' in o)) throw new Error(STRINGS.none);
39
+ if (ops.length > 1) throw new Error(STRINGS.many);
40
+ for (const k of [...ops, 'radius']) if (o[k] != null && !Number.isFinite(o[k])) throw new Error(fmt(STRINGS.num, { k, got: o[k] }));
41
+ if (o.shape != null && o.shape !== 'circle' && o.shape !== 'square') throw new Error(fmt(STRINGS.shape, { got: JSON.stringify(o.shape) }));
42
+ if ('paint' in o && o.paint !== null && typeof o.paint !== 'string') throw new Error(fmt(STRINGS.paint, { got: JSON.stringify(o.paint) }));
43
+ const T = this.mgr.T, C = T.CELL, [x, z] = xzOf(position), r = o.radius ?? C / 2, sq = o.shape === 'square';
44
+ // off the outline of terrain({ shape }) there is no ground to dig or paint; near the rim the grid points just outside still move,
45
+ // because the rim's height is interpolated from them. The outline itself is not editable
46
+ if (!T.has(x, z)) return { heights: 0, cells: 0 };
47
+ const inside = (px, pz) => sq ? Math.abs(px - x) <= r && Math.abs(pz - z) <= r : (px - x) ** 2 + (pz - z) ** 2 <= r * r;
48
+ // grid indices covered: points use (i * C), cells their center ((i + 0.5) * C); an edit smaller than a cell still takes the nearest one
49
+ const pick = (off, fallback) => {
50
+ const out = [];
51
+ for (let j = Math.floor((z - r) / C) - 1; j <= Math.ceil((z + r) / C); j++)
52
+ for (let i = Math.floor((x - r) / C) - 1; i <= Math.ceil((x + r) / C); i++) if (inside((i + off) * C, (j + off) * C)) out.push(i, j);
53
+ return out.length ? out : fallback;
54
+ };
55
+ let heights = 0, cells = 0, i0 = Infinity, i1 = -Infinity, j0 = Infinity, j1 = -Infinity;
56
+ const grow = (i, j) => { i0 = Math.min(i0, i); i1 = Math.max(i1, i); j0 = Math.min(j0, j); j1 = Math.max(j1, j); };
57
+ if (ops.length) {
58
+ const pts = pick(0, [Math.round(x / C), Math.round(z / C)]);
59
+ // read every height first, then write: the result does not depend on visiting order
60
+ const cur = []; for (let n = 0; n < pts.length; n += 2) cur.push(T.gridH(pts[n], pts[n + 1]));
61
+ for (let n = 0; n < pts.length; n += 2) {
62
+ const h = o.flatten ?? cur[n / 2] + (o.raise ?? 0) - (o.lower ?? 0);
63
+ this.h.set(T.key(pts[n], pts[n + 1]), h); heights++; grow(pts[n], pts[n + 1]);
64
+ }
65
+ }
66
+ if ('paint' in o) {
67
+ const cs = pick(0.5, [Math.floor(x / C), Math.floor(z / C)]);
68
+ for (let n = 0; n < cs.length; n += 2) {
69
+ const k = T.key(cs[n], cs[n + 1]);
70
+ if (o.paint === null) this.t.delete(k); else this.t.set(k, o.paint);
71
+ cells++; grow(cs[n], cs[n + 1]);
72
+ }
73
+ }
74
+ this._touch(i0, i1, j0, j1);
75
+ return { heights, cells };
76
+ }
77
+
78
+ /** Edits a worker needs to build chunk (cx, cz): those of the chunk and its 8 neighbors (normals and borders read one grid point past the edge) */
79
+ forChunk(cx, cz) {
80
+ if (!this.h.size && !this.t.size) return null;
81
+ const R = this.mgr.T.RES, near = (i, j) => Math.abs(Math.floor(i / R) - cx) <= 1 && Math.abs(Math.floor(j / R) - cz) <= 1;
82
+ const h = [], t = [];
83
+ for (const [k, v] of this.h) { const [i, j] = unkey(k); if (near(i, j)) h.push(i, j, v); }
84
+ for (const [k, v] of this.t) { const [i, j] = unkey(k); if (near(i, j)) t.push([i, j, v]); }
85
+ return h.length || t.length ? { h, t } : null;
86
+ }
87
+ version(key) { return this.ver.get(key) ?? 0; }
88
+
89
+ /** Grid range [i0, i1] x [j0, j1] changed: bump the version of every chunk it reaches, rebuild loaded ones now, tell listeners */
90
+ _touch(i0, i1, j0, j1) {
91
+ if (i0 > i1) return;
92
+ const m = this.mgr, R = m.T.RES, C = m.T.CELL;
93
+ // a grid point is shared by the cells on both sides, and smooth normals read one point further
94
+ for (let cz = Math.floor((j0 - 2) / R); cz <= Math.floor((j1 + 2) / R); cz++)
95
+ for (let cx = Math.floor((i0 - 2) / R); cx <= Math.floor((i1 + 2) / R); cx++) {
96
+ const k = cx + ',' + cz, c = m.chunks.get(k);
97
+ this.ver.set(k, this.version(k) + 1);
98
+ if (c?.state === 'ready') this._rebuild(c);
99
+ }
100
+ this.e.events.emit('ground:change', { x0: (i0 - 1) * C, z0: (j0 - 1) * C, x1: (i1 + 2) * C, z1: (j1 + 2) * C });
101
+ }
102
+
103
+ // same code as the worker on the full edit maps, so a rebuilt chunk equals a freshly generated one
104
+ _rebuild(c) {
105
+ const m = this.mgr, T = m.T, t = T.buildChunk(c.cx, c.cz), g = c.terrain.geometry;
106
+ for (const [n, a] of [['position', t.pos], ['normal', t.nor], ['color', t.col], ['uv', t.uv]]) { g.attributes[n].array.set(a); g.attributes[n].needsUpdate = true; }
107
+ if (t.tex) updateColorMap(c, t.tex);
108
+ g.computeBoundingSphere(); g.boundingBox = null;
109
+ c.sphere.center.set(t.sphere[0], t.sphere[1], t.sphere[2]); c.sphere.radius = t.sphere[3];
110
+ const veg = this.e.vegetation;
111
+ if (veg) for (const sp of veg.list()) {
112
+ if (sp.nearOnly && !c.veg[sp.name]) continue; // detail not loaded here; when it is, its job carries the edits
113
+ const r = T.place(c.cx, c.cz, sp.rule, m.density), old = c.veg[sp.name];
114
+ if (!r.n && old) { c.group.remove(old); old.dispose(); delete c.veg[sp.name]; }
115
+ m._applyVeg(c, sp.name, r);
116
+ }
117
+ c.colToken = {}; c.level = -1; c.detailDone.clear(); // edits can change what grows here: re-ask for the near-only species // new token: the physics module rebuilds this chunk's collision
118
+ }
119
+
120
+ save() {
121
+ const h = [], t = [];
122
+ for (const [k, v] of this.h) h.push(...unkey(k), v);
123
+ for (const [k, v] of this.t) t.push([...unkey(k), v]);
124
+ return { h, t };
125
+ }
126
+ load(d) {
127
+ const T = this.mgr.T, before = [...this.h.keys(), ...this.t.keys()];
128
+ this.h.clear(); this.t.clear();
129
+ for (let n = 0; n < (d?.h?.length ?? 0); n += 3) this.h.set(T.key(d.h[n], d.h[n + 1]), d.h[n + 2]);
130
+ for (const [i, j, v] of d?.t || []) this.t.set(T.key(i, j), v);
131
+ // rebuild what changed: chunks that had edits before and chunks that have them now
132
+ const seen = new Set(), R = T.RES;
133
+ for (const k of [...before, ...this.h.keys(), ...this.t.keys()]) {
134
+ const [i, j] = unkey(k), cx = Math.floor(i / R), cz = Math.floor(j / R);
135
+ if (seen.has(cx + ',' + cz)) continue;
136
+ seen.add(cx + ',' + cz); this._touch(cx * R, cx * R + R, cz * R, cz * R + R);
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,155 @@
1
+ // Pure computation: terrain height (a game's height function, a height map, or flat y = 0), ground types, flattened plots, chunk meshes,
2
+ // vegetation placement (with colliders).
3
+ // No three.js dependency; the main thread and the Worker share this code, so results are identical.
4
+ // Note: the config here must be serializable because it is passed to the Worker: a game's own height / groundType function travels as source text (threads.pure rules).
5
+ // Edits (dig, raise, paint) are an overlay of grid-point heights and cell ground types on top of the generated terrain; see terrainEdit.js.
6
+ // Split: defaults in terrainDefaults.js; chunk meshes and vegetation placement in terrainMesh.js (neither depends on three.js).
7
+ import { DEFAULT_TERRAIN } from './terrainDefaults.js';
8
+ import { makeMesher } from './terrainMesh.js';
9
+ import { makeShape, grayAt } from './terrainShape.js';
10
+ import { makeNoise } from '../../core/scatter.js';
11
+ import { compilePure } from '../../core/threadPure.js';
12
+ export { DEFAULT_TERRAIN } from './terrainDefaults.js';
13
+
14
+ const srgbToLinear = c => (c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
15
+ const hexToLinear = h => [((h >> 16) & 255) / 255, ((h >> 8) & 255) / 255, (h & 255) / 255].map(srgbToLinear);
16
+
17
+ export function createTerrain(userCfg = {}) {
18
+ const cfg = { ...DEFAULT_TERRAIN, ...userCfg, colors: { ...DEFAULT_TERRAIN.colors, ...(userCfg.colors || {}) }, boundsPad: { ...DEFAULT_TERRAIN.boundsPad, ...(userCfg.boundsPad || {}) } };
19
+ for (const [k, ok] of [['shading', ['smooth', 'flat', 'texture']], ['diagonal', ['fixed', 'adaptive', 'alternate']], ['normals', [null, 'smooth', 'flat']]])
20
+ if (!ok.includes(cfg[k])) throw new Error(`terrain({ ${k} }) must be ${ok.filter(Boolean).map(v => `'${v}'`).join(' | ')}, got ${JSON.stringify(cfg[k])}`);
21
+ const SEED = cfg.seed | 0, CHUNK = cfg.chunkSize, RES = cfg.resolution, CELL = CHUNK / RES, WATER = cfg.waterLevel;
22
+ const PAL = {};
23
+ for (const k in cfg.colors) PAL[k] = hexToLinear(cfg.colors[k]);
24
+
25
+ const { hash: hash2, noise: vnoise, fbm } = makeNoise(SEED); // shared with vegetation cluster rules on any ground
26
+ const smooth = t => t * t * (3 - 2 * t);
27
+
28
+ function heightmapHeight(x, z) {
29
+ const H = cfg.heightmap, [sx, sz] = H.size, [cx0, cz0] = H.center || [0, 0];
30
+ const u = (x - cx0) / sx + 0.5, v = (z - cz0) / sz + 0.5;
31
+ if (u < 0 || u > 1 || v < 0 || v > 1) return H.outside ?? (Number.isFinite(WATER) ? WATER - 5 : H.min ?? 0); // outside the map: under the water, or the map's floor without water
32
+ return (H.min ?? 0) + grayAt(H, u, v) * ((H.max ?? 60) - (H.min ?? 0));
33
+ }
34
+ // helpers handed to a game's own height / groundType function: it runs in a worker and cannot import or close over anything
35
+ const NOISE = { fbm, noise: vnoise, hash: hash2, seed: SEED, waterLevel: WATER, params: cfg.params ?? {} };
36
+ const userHeight = cfg.height && compilePure(cfg.height, 'terrain({ height })').call;
37
+ const userType = cfg.groundType && compilePure(cfg.groundType, 'terrain({ groundType })').call;
38
+ const userNormal = cfg.normalFn && compilePure(cfg.normalFn, 'terrain({ normalFn })').call;
39
+ // no generator of its own: the engine draws flat ground at y = 0 (a placeholder; the terrain module warns in dev)
40
+ const naturalHeight = userHeight ? (x, z) => userHeight(x, z, NOISE) : cfg.heightmap?.data ? heightmapHeight : () => 0;
41
+ function rawHeight(x, z) {
42
+ let h = naturalHeight(x, z);
43
+ for (const f of cfg.flatten) {
44
+ const d = Math.hypot(x - f.x, z - f.z);
45
+ if (d >= f.radius) continue;
46
+ const target = f.height ?? (f._h ??= naturalHeight(f.x, f.z));
47
+ const t = d < f.radius * 0.6 ? 1 : smooth(1 - (d - f.radius * 0.6) / (f.radius * 0.4));
48
+ h = h + (target - h) * t;
49
+ }
50
+ return h;
51
+ }
52
+
53
+ // edit overlay: grid key -> height (grid point i*CELL, j*CELL) and cell key -> ground type (cell [i, i+1) x [j, j+1)). The main thread holds every edit;
54
+ // a worker gets only those around the chunk it builds (setEdits), which is all buildChunk / place read
55
+ const key = (i, j) => (i + 50000) * 100000 + (j + 50000);
56
+ let EH = new Map(), ET = new Map();
57
+ function setEdits(d) {
58
+ EH = new Map(); ET = new Map();
59
+ if (!d) return;
60
+ for (let n = 0; n < d.h.length; n += 3) EH.set(key(d.h[n], d.h[n + 1]), d.h[n + 2]);
61
+ for (const [i, j, t] of d.t) ET.set(key(i, j), t);
62
+ }
63
+ /** main thread: share the editor's maps (it writes them in place) */
64
+ function useEdits(eh, et) { EH = eh; ET = et; }
65
+ const cellType = (i, j) => ET.size ? ET.get(key(i, j)) : undefined;
66
+ // a cell whose shape or type was edited: vegetation does not grow there
67
+ function editedCell(x, z) {
68
+ if (!EH.size && !ET.size) return false;
69
+ const i = Math.floor(x / CELL), j = Math.floor(z / CELL);
70
+ return ET.has(key(i, j)) || EH.has(key(i, j)) || EH.has(key(i + 1, j)) || EH.has(key(i, j + 1)) || EH.has(key(i + 1, j + 1));
71
+ }
72
+ // world outline (terrain({ shape })): only built when the game passes one, so the default ground runs none of it
73
+ const SHAPE = cfg.shape ? makeShape(cfg.shape, { CELL, NOISE, key, hash: hash2, fbm }) : null;
74
+ const gridRaw = SHAPE?.drop ? (i, j) => rawHeight(i * CELL, j * CELL) - SHAPE.drop(i, j) : (i, j) => rawHeight(i * CELL, j * CELL);
75
+ const cache = new Map();
76
+ function gridH(i, j) {
77
+ const k = key(i, j);
78
+ if (EH.size) { const e = EH.get(k); if (e !== undefined) return e; }
79
+ let h = cache.get(k);
80
+ if (h === undefined) { if (cache.size > 400000) cache.clear(); h = gridRaw(i, j); cache.set(k, h); }
81
+ return h;
82
+ }
83
+ // height exactly matching the low-poly triangles (characters and vegetation use it, so nothing floats)
84
+ // diagonal of a cell: 0 = b-c (the original cut), 1 = a-d; the mesh and surface() read this one function, so characters never float or sink
85
+ const DIAG = cfg.diagonal;
86
+ const diagOf = DIAG === 'fixed' ? () => 0
87
+ : DIAG === 'alternate' ? (i, j) => (i + j) & 1
88
+ : (i, j, ha, hb, hc, hd) => (Math.abs(ha - hd) < Math.abs(hb - hc) ? 1 : 0);
89
+ function surface(x, z) {
90
+ const gx = x / CELL, gz = z / CELL, i = Math.floor(gx), j = Math.floor(gz), fx = gx - i, fz = gz - j;
91
+ const ha = gridH(i, j), hb = gridH(i + 1, j), hc = gridH(i, j + 1), hd = gridH(i + 1, j + 1);
92
+ if (diagOf(i, j, ha, hb, hc, hd)) return fz >= fx ? ha + (hc - ha) * fz + (hd - hc) * fx : ha + (hb - ha) * fx + (hd - hb) * fz;
93
+ return fx + fz <= 1 ? ha + (hb - ha) * fx + (hc - ha) * fz : hd + (hc - hd) * (1 - fx) + (hb - hd) * (1 - fz);
94
+ }
95
+ function slope(x, z) {
96
+ const i = Math.floor(x / CELL), j = Math.floor(z / CELL);
97
+ const ha = gridH(i, j), hb = gridH(i + 1, j), hc = gridH(i, j + 1), hd = gridH(i + 1, j + 1);
98
+ return Math.max(Math.abs(hb - ha), Math.abs(hc - ha), Math.abs(hd - hb), Math.abs(hd - hc)) / CELL;
99
+ }
100
+
101
+ // ground type: a painted cell's type, else the game's groundType function, else 'default'
102
+ function biomeAt(x, z, h = surface(x, z), sl = 0) {
103
+ return cellType(Math.floor(x / CELL), Math.floor(z / CELL)) ?? naturalBiome(x, z, h, sl);
104
+ }
105
+ function naturalBiome(x, z, h, sl) {
106
+ return (userType && userType(x, z, h, sl, NOISE)) ?? 'default';
107
+ }
108
+
109
+ // a ground type the style pack gives no color: one flat neutral gray (no noise blend, no jitter)
110
+ const FALLBACK = [0.5, 0.5, 0.5], GRAY = [FALLBACK];
111
+ const pal = names => names.map(n => PAL[n] || FALLBACK);
112
+ const BCOL = {}; for (const k in cfg.biomeColors) BCOL[k] = pal(cfg.biomeColors[k]);
113
+ const STEEP = cfg.steep.map(s => ({ ny: s.maxNormalY, c: pal(s.colors) }));
114
+ // natural color (painted cells are colored by paintColor per whole cell, so a painted type never bleeds into a neighbor's vertex)
115
+ function faceColor(h, ny, x, z, out) {
116
+ let cols = null;
117
+ for (const s of STEEP) if (ny < s.ny) { cols = s.c; break; }
118
+ return mix(cols || BCOL[naturalBiome(x, z, h, 1 - ny)] || GRAY, x, z, out);
119
+ }
120
+ const paintColor = (type, x, z, out) => mix(BCOL[type] || GRAY, x, z, out);
121
+ // Ground color variation (style.terrain.variation, plain data so it travels to workers): defaults are the original look.
122
+ // blend: wavelength of the two-color noise; jitter: per-cell brightness grain; patches: optional large painterly color blocks
123
+ const V = cfg.variation || {}, BL = V.blend || {}, JT = V.jitter || {}, PT = V.patches;
124
+ const bFreq = BL.size ? 1 / BL.size : 0.03, bStrength = BL.strength ?? 1, jInv = JT.size ? 1 / JT.size : 3, jMin = JT.min ?? 0.92, jRange = JT.range ?? 0.12;
125
+ const pFreq = PT ? 1 / (PT.size || 90) : 0, pLevels = PT?.levels | 0, pTint = PT?.tint != null ? hexToLinear(PT.tint) : null;
126
+ function mix(cols, x, z, out) {
127
+ if (cols === GRAY) { out[0] = out[1] = out[2] = FALLBACK[0]; return out; }
128
+ const a = cols[0], b = cols[1] || a;
129
+ let t = cols.length > 1 ? vnoise(x * bFreq, z * bFreq) : 0;
130
+ if (bStrength !== 1) t = Math.min(1, Math.max(0, 0.5 + (t - 0.5) * bStrength));
131
+ const j = jMin + hash2(Math.floor(x * jInv), Math.floor(z * jInv), 7) * jRange;
132
+ out[0] = (a[0] + (b[0] - a[0]) * t) * j; out[1] = (a[1] + (b[1] - a[1]) * t) * j; out[2] = (a[2] + (b[2] - a[2]) * t) * j;
133
+ if (PT) patch(x, z, out);
134
+ return out;
135
+ }
136
+ // Second, much larger noise (own offsets so it is not correlated with the blend): levels > 0 snaps it to flat blocks (brush strokes
137
+ // instead of soft clouds). Brightens/darkens by strength, or pulls towards `tint` where the noise is high.
138
+ function patch(x, z, out) {
139
+ let n = vnoise(x * pFreq + 91.7, z * pFreq + 17.3);
140
+ if (pLevels > 0) n = Math.floor(n * pLevels) / pLevels;
141
+ const s = PT.strength ?? 0.15;
142
+ if (pTint) { const k = n * s; for (let i = 0; i < 3; i++) out[i] += (pTint[i] - out[i]) * k; }
143
+ else { const k = 1 + (n - 0.5) * 2 * s; out[0] *= k; out[1] *= k; out[2] *= k; }
144
+ }
145
+
146
+ const { buildChunk, place } = makeMesher({ cfg, CHUNK, RES, CELL, gridH, surface, slope, biomeAt, fbm, faceColor, paintColor, cellType, editedCell, diagOf, userNormal, shape: SHAPE });
147
+ // the void: no height (-Infinity), no slope, ground type 'void'; the mesher above keeps the unmasked functions (rim colors, outside corners)
148
+ const has = SHAPE ? SHAPE.has : () => true;
149
+ const query = SHAPE ? {
150
+ surface: (x, z) => (has(x, z) ? surface(x, z) : -Infinity),
151
+ slope: (x, z) => (has(x, z) ? slope(x, z) : 0),
152
+ biomeAt: (x, z, h, sl) => (has(x, z) ? biomeAt(x, z, h, sl) : 'void'),
153
+ } : { surface, slope, biomeAt };
154
+ return { config: cfg, CHUNK, RES, CELL, waterLevel: WATER, ...query, has, shape: SHAPE, fbm, noise: NOISE, buildChunk, place, gridH, setEdits, useEdits, key };
155
+ }
@@ -0,0 +1,131 @@
1
+ // Island chunks (terrain({ shape })): the chunk mesh when the world has an outline. Its own function instead of branches in buildChunk, so the
2
+ // default ground keeps its exact bytes. Pure computation, no three.js (runs in the Worker).
3
+ //
4
+ // Top: every ground cell (or the part of a boundary cell the marching-squares cut keeps, terrainShape.js) is split along the cell's diagonal
5
+ // and fanned into triangles whose heights lie on the same two planes engine.surface reads, so feet and the drawn ground agree up to the rim.
6
+ // Side: each rim segment is pushed down by side.depth (flat outward normal, side.ground color). Bottom (optional): every top vertex again,
7
+ // side.depth + bottom.depth lower, winding reversed; a second band of wall joins the side to it. Vertex order: top, side, bottom -- `top`
8
+ // and `solid` count vertices so the texture-shading material covers only the top and collision leaves the bottom out.
9
+
10
+ /** Unit normal of triangle a, b, q into o (buildChunk's flat triangles use it too) */
11
+ export function faceN(ax, ay, az, bx, by, bz, qx, qy, qz, o) {
12
+ const ux = bx - ax, uy = by - ay, uz = bz - az, vx = qx - ax, vy = qy - ay, vz = qz - az;
13
+ const nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;
14
+ const l = Math.hypot(nx, ny, nz) || 1; o[0] = nx / l; o[1] = ny / l; o[2] = nz / l;
15
+ return o;
16
+ }
17
+
18
+ export function makeIslandBuilder({ CHUNK, RES, CELL, gridH, faceColor, paintColor, cellType, diagOf, gridNormal, textured, smoothLight, colorMap, shape, sphereOf }) {
19
+ const { cut, maskAt, sideDepth, bottomDepth, sideGround, bottomGround } = shape;
20
+ const FULL = [[0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0]];
21
+ const bucket = () => ({ p: [], n: [], c: [] });
22
+ const put = (B, x, y, z, nx, ny, nz, c) => { B.p.push(x, y, z); B.n.push(nx, ny, nz); B.c.push(c[0], c[1], c[2]); };
23
+ const WHITE = [1, 1, 1];
24
+ // keep the part of convex polygon P on one side of the cell diagonal (s >= 0 for sign 1, s <= 0 for sign -1)
25
+ function clip(P, d, sign) {
26
+ const s = (fx, fz) => sign * (d ? fz - fx : 1 - fx - fz), out = [], n = P.length;
27
+ for (let k = 0; k < n; k += 3) {
28
+ const ax = P[k], az = P[k + 1], bx = P[(k + 3) % n], bz = P[(k + 4) % n], sa = s(ax, az), sb = s(bx, bz);
29
+ if (sa >= 0) out.push(ax, az, P[k + 2]);
30
+ if ((sa > 0 && sb < 0) || (sa < 0 && sb > 0)) { const t = sa / (sa - sb); out.push(ax + (bx - ax) * t, az + (bz - az) * t, 0); }
31
+ }
32
+ return out;
33
+ }
34
+
35
+ return function buildIslandChunk(cx, cz) {
36
+ const n = RES, i0 = cx * n, j0 = cz * n, ox = cx * CHUNK, oz = cz * CHUNK;
37
+ const top = bucket(), wall = bucket(), under = bucket();
38
+ const paint = [0, 0, 0], col = [0, 0, 0], nrm = [0, 0, 0], V = [[0, 0, 0], [0, 0, 0], [0, 0, 0]];
39
+ let minH = Infinity, maxH = -Infinity;
40
+ for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) {
41
+ const I = i0 + i, J = j0 + j, polys = cut(I, J) ?? FULL;
42
+ if (!polys.length) continue;
43
+ const x0 = i * CELL, z0 = j * CELL;
44
+ const ha = gridH(I, J), hb = gridH(I + 1, J), hc = gridH(I, J + 1), hd = gridH(I + 1, J + 1), d = diagOf(I, J, ha, hb, hc, hd);
45
+ // the two triangle planes of the cell, chosen exactly as surface() chooses them
46
+ const H = d ? (fx, fz) => (fz >= fx ? ha + (hc - ha) * fz + (hd - hc) * fx : ha + (hb - ha) * fx + (hd - hb) * fz)
47
+ : (fx, fz) => (fx + fz <= 1 ? ha + (hb - ha) * fx + (hc - ha) * fz : hd + (hc - hd) * (1 - fx) + (hb - hd) * (1 - fz));
48
+ const pt = textured ? undefined : cellType(I, J);
49
+ if (pt !== undefined) paintColor(pt, ox + x0 + CELL / 2, oz + z0 + CELL / 2, paint); // a painted cell is one color
50
+ const g = smoothLight ? [gridNormal(I, J), gridNormal(I + 1, J), gridNormal(I, J + 1), gridNormal(I + 1, J + 1)] : null;
51
+ const below = (fx, fz, y) => y - sideDepth(ox + x0 + fx * CELL, oz + z0 + fz * CELL);
52
+ const tri = (P, a, b, q) => {
53
+ for (let k = 0; k < 3; k++) { const s = [a, b, q][k], fx = P[s], fz = P[s + 1]; V[k][0] = x0 + fx * CELL; V[k][1] = H(fx, fz); V[k][2] = z0 + fz * CELL; }
54
+ for (const v of V) { maxH = Math.max(maxH, v[1]); minH = Math.min(minH, v[1]); }
55
+ if (smoothLight) {
56
+ for (let k = 0; k < 3; k++) {
57
+ const s = [a, b, q][k], fx = P[s], fz = P[s + 1], v = V[k];
58
+ for (let c = 0; c < 3; c++) nrm[c] = (g[0][c] * (1 - fx) + g[1][c] * fx) * (1 - fz) + (g[2][c] * (1 - fx) + g[3][c] * fx) * fz;
59
+ const l = Math.hypot(nrm[0], nrm[1], nrm[2]) || 1;
60
+ const c3 = textured ? WHITE : pt !== undefined ? paint : faceColor(v[1], nrm[1] / l, ox + v[0], oz + v[2], col);
61
+ put(top, v[0], v[1], v[2], nrm[0] / l, nrm[1] / l, nrm[2] / l, c3);
62
+ }
63
+ } else {
64
+ faceN(V[0][0], V[0][1], V[0][2], V[1][0], V[1][1], V[1][2], V[2][0], V[2][1], V[2][2], nrm);
65
+ const c3 = textured ? WHITE : pt !== undefined ? paint
66
+ : faceColor((V[0][1] + V[1][1] + V[2][1]) / 3, nrm[1], ox + (V[0][0] + V[1][0] + V[2][0]) / 3, oz + (V[0][2] + V[1][2] + V[2][2]) / 3, col);
67
+ for (const v of V) put(top, v[0], v[1], v[2], nrm[0], nrm[1], nrm[2], c3);
68
+ }
69
+ if (bottomDepth) { // the same triangle hung below, reversed
70
+ const B = [0, 2, 1].map(k => {
71
+ const s = [a, b, q][k], fx = P[s], fz = P[s + 1], v = V[k];
72
+ return [v[0], below(fx, fz, v[1]) - bottomDepth(ox + v[0], oz + v[2], Math.max(0, maskAt(I, J, fx, fz))), v[2]];
73
+ });
74
+ faceN(B[0][0], B[0][1], B[0][2], B[1][0], B[1][1], B[1][2], B[2][0], B[2][1], B[2][2], nrm);
75
+ paintColor(bottomGround, ox + (B[0][0] + B[1][0] + B[2][0]) / 3, oz + (B[0][2] + B[1][2] + B[2][2]) / 3, col);
76
+ for (const v of B) { minH = Math.min(minH, v[1]); put(under, v[0], v[1], v[2], nrm[0], nrm[1], nrm[2], col); }
77
+ }
78
+ };
79
+ for (const P of polys) {
80
+ for (const piece of [clip(P, d, 1), clip(P, d, -1)])
81
+ for (let k = 3; k + 3 < piece.length; k += 3) tri(piece, 0, k + 3, k); // fan, clockwise in (x, z) like buildChunk: normal up
82
+ // rim: consecutive crossings of the counter-clockwise polygon; outward is to the right of P -> Q. A segment that crosses the
83
+ // cell diagonal is walled in two pieces: the top bends there (two planes), and one straight wall edge would leave a triangular
84
+ // slit under the rim -- wide when edge.round bends the top down
85
+ const L = P.length, sd = (fx, fz) => (d ? fz - fx : 1 - fx - fz);
86
+ for (let k = 0; k < L; k += 3) {
87
+ const q = (k + 3) % L;
88
+ if (!P[k + 2] || !P[q + 2]) continue;
89
+ const sp = sd(P[k], P[k + 1]), sq = sd(P[q], P[q + 1]);
90
+ if ((sp > 0 && sq < 0) || (sp < 0 && sq > 0)) {
91
+ const t = sp / (sp - sq), mx = P[k] + (P[q] - P[k]) * t, mz = P[k + 1] + (P[q + 1] - P[k + 1]) * t;
92
+ rim(P[k], P[k + 1], mx, mz); rim(mx, mz, P[q], P[q + 1]);
93
+ } else rim(P[k], P[k + 1], P[q], P[q + 1]);
94
+ }
95
+ }
96
+ // one wall piece under the rim from (pf) to (qf), cell units
97
+ function rim(pfx, pfz, qfx, qfz) {
98
+ const px = x0 + pfx * CELL, pz = z0 + pfz * CELL, qx = x0 + qfx * CELL, qz = z0 + qfz * CELL;
99
+ const dx = qx - px, dz = qz - pz, l = Math.hypot(dx, dz);
100
+ if (l < 1e-9) return;
101
+ const nx = dz / l, nz = -dx / l, pTop = H(pfx, pfz), qTop = H(qfx, qfz);
102
+ const pMid = below(pfx, pfz, pTop), qMid = below(qfx, qfz, qTop);
103
+ paintColor(sideGround, ox + (px + qx) / 2, oz + (pz + qz) / 2, col);
104
+ band(wall, px, pz, qx, qz, pTop, qTop, pMid, qMid, nx, nz, col);
105
+ maxH = Math.max(maxH, pTop, qTop); minH = Math.min(minH, pMid, qMid);
106
+ if (bottomDepth) {
107
+ const pLow = pMid - bottomDepth(ox + px, oz + pz, 0), qLow = qMid - bottomDepth(ox + qx, oz + qz, 0);
108
+ paintColor(bottomGround, ox + (px + qx) / 2, oz + (pz + qz) / 2, col);
109
+ band(wall, px, pz, qx, qz, pMid, qMid, pLow, qLow, nx, nz, col);
110
+ minH = Math.min(minH, pLow, qLow);
111
+ }
112
+ }
113
+ }
114
+ const nTop = top.p.length / 3, nWall = wall.p.length / 3, all = top.p.length + wall.p.length + under.p.length;
115
+ const pos = new Float32Array(all), nor = new Float32Array(all), clr = new Float32Array(all), uv = new Float32Array(all / 3 * 2);
116
+ let o = 0;
117
+ for (const B of [top, wall, under]) { pos.set(B.p, o); nor.set(B.n, o); clr.set(B.c, o); o += B.p.length; }
118
+ for (let k = 0, q = 0; k < all; k += 3) { uv[q++] = (ox + pos[k]) / CHUNK; uv[q++] = (oz + pos[k + 2]) / CHUNK; }
119
+ if (!all) minH = maxH = 0; // a chunk wholly in the void: an empty mesh, still 'ready' so loading never waits on it
120
+ const out = { pos, nor, col: clr, uv, minH, maxH, top: nTop, solid: nTop + nWall, sphere: sphereOf(ox, oz, minH, maxH) };
121
+ if (colorMap && nTop) out.tex = colorMap(cx, cz);
122
+ return out;
123
+ };
124
+
125
+ // one quad of wall from (p, q) top edge down to the bottom edge, front face outward
126
+ function band(B, px, pz, qx, qz, pT, qT, pB, qB, nx, nz, c) {
127
+ if (pT - pB < 1e-6 && qT - qB < 1e-6) return;
128
+ put(B, px, pT, pz, nx, 0, nz, c); put(B, qx, qT, qz, nx, 0, nz, c); put(B, px, pB, pz, nx, 0, nz, c);
129
+ put(B, qx, qT, qz, nx, 0, nz, c); put(B, qx, qB, qz, nx, 0, nz, c); put(B, px, pB, pz, nx, 0, nz, c);
130
+ }
131
+ }
@@ -0,0 +1,92 @@
1
+ // Terrain chunk meshes (flat / smooth / texture shading) and the terrain's vegetation placement (the shared rule code in core/scatter.js).
2
+ // Pure computation, no three.js dependency, shared by the main thread and the Worker.
3
+ // makeMesher(ctx) takes the height, slope and biome functions from createTerrain and returns { buildChunk, place }.
4
+
5
+ import { makePlacer } from '../../core/scatter.js';
6
+ import { makeColorMap } from './terrainColorMap.js';
7
+ import { makeIslandBuilder, faceN } from './terrainIsland.js';
8
+
9
+ // shape (terrain({ shape }), else null): island chunks come from terrainIsland.js and nothing grows where has(x, z) is false
10
+ export function makeMesher({ cfg, CHUNK, RES, CELL, gridH, surface, slope, biomeAt, fbm, faceColor, paintColor, cellType, editedCell, diagOf, userNormal, shape }) {
11
+ const SEED = cfg.seed | 0;
12
+ // lighting normal at a grid point: the game's normalFn, else central difference of the neighboring heights
13
+ const gridNormal = userNormal
14
+ ? (gi, gj) => { const v = userNormal(gi, gj, gridH, CELL), l = Math.hypot(v[0], v[1], v[2]) || 1; return [v[0] / l, v[1] / l, v[2] / l]; }
15
+ : (gi, gj) => {
16
+ const dx = (gridH(gi + 1, gj) - gridH(gi - 1, gj)) / (2 * CELL), dz = (gridH(gi, gj + 1) - gridH(gi, gj - 1)) / (2 * CELL), l = Math.hypot(dx, 1, dz);
17
+ return [-dx / l, 1 / l, -dz / l];
18
+ };
19
+ const textured = cfg.shading === 'texture';
20
+ const smoothLight = cfg.shading === 'smooth' || textured && cfg.normals !== 'flat'; // smooth: one normal per grid point; else per triangle
21
+ // with a shape the map is colored from the unmasked height (filtering at the rim reads real ground colors) and void pixels get alpha 0
22
+ const colorMap = textured ? makeColorMap({ cfg, CHUNK, CELL, surface, faceColor, paintColor, cellType, gridNormal, inside: shape?.has }) : null;
23
+ // chunk bounding sphere [x, y, z, r] for heights minH..maxH, grown by boundsPad
24
+ const half = CHUNK / 2, pad = cfg.boundsPad;
25
+ const sphereOf = (ox, oz, minH, maxH) => [ox + half, (minH + maxH) / 2 + pad.up, oz + half, Math.hypot(half, half, (maxH - minH) / 2 + pad.radius)];
26
+ // build one chunk's terrain mesh (flat: one normal and color per triangle; smooth: per grid point; texture: colors come from the color map, vertex colors are white).
27
+ // uv = world xz / chunk size, continuous across chunks for tiling textures
28
+ function buildChunk(cx, cz) {
29
+ const n = RES, i0 = cx * n, j0 = cz * n, ox = cx * CHUNK, oz = cz * CHUNK;
30
+ const len = n * n * 18;
31
+ const pos = new Float32Array(len), nor = new Float32Array(len), col = new Float32Array(len), uv = new Float32Array(len / 3 * 2);
32
+ if (textured) col.fill(1);
33
+ const tmp = [0, 0, 0];
34
+ let p = 0, q = 0, minH = Infinity, maxH = -Infinity, painted = textured; // painted: the whole cell has the painted type's color (texture mode: no vertex colors to compute)
35
+ function vert(x, y, z, nx, ny, nz) {
36
+ pos[p] = x; pos[p + 1] = y; pos[p + 2] = z; nor[p] = nx; nor[p + 1] = ny; nor[p + 2] = nz;
37
+ if (!textured) { col[p] = tmp[0]; col[p + 1] = tmp[1]; col[p + 2] = tmp[2]; }
38
+ p += 3;
39
+ uv[q++] = (ox + x) / CHUNK; uv[q++] = (oz + z) / CHUNK;
40
+ }
41
+ const N = [0, 0, 0];
42
+ function tri(ax, ay, az, bx, by, bz, qx, qy, qz) {
43
+ faceN(ax, ay, az, bx, by, bz, qx, qy, qz, N);
44
+ const nx = N[0], ny = N[1], nz = N[2];
45
+ if (!painted) faceColor((ay + by + qy) / 3, ny, ox + (ax + bx + qx) / 3, oz + (az + bz + qz) / 3, tmp);
46
+ vert(ax, ay, az, nx, ny, nz); vert(bx, by, bz, nx, ny, nz); vert(qx, qy, qz, nx, ny, nz);
47
+ }
48
+ function svert(x, y, z, gi, gj) {
49
+ const nn = gridNormal(gi, gj);
50
+ if (!painted) faceColor(y, nn[1], ox + x, oz + z, tmp);
51
+ vert(x, y, z, nn[0], nn[1], nn[2]);
52
+ }
53
+ for (let j = 0; j < n; j++) for (let i = 0; i < n; i++) {
54
+ const x0 = i * CELL, z0 = j * CELL, x1 = x0 + CELL, z1 = z0 + CELL;
55
+ const ha = gridH(i0 + i, j0 + j), hb = gridH(i0 + i + 1, j0 + j), hc = gridH(i0 + i, j0 + j + 1), hd = gridH(i0 + i + 1, j0 + j + 1);
56
+ minH = Math.min(minH, ha, hb, hc, hd); maxH = Math.max(maxH, ha, hb, hc, hd);
57
+ if (!textured) {
58
+ const pt = cellType(i0 + i, j0 + j);
59
+ painted = pt !== undefined;
60
+ if (painted) paintColor(pt, ox + x0 + CELL / 2, oz + z0 + CELL / 2, tmp);
61
+ }
62
+ const d = diagOf(i0 + i, j0 + j, ha, hb, hc, hd); // 0: b-c, the original cut; 1: a-d
63
+ if (smoothLight) {
64
+ const I = i0 + i, J = j0 + j;
65
+ if (d) {
66
+ svert(x0, ha, z0, I, J); svert(x0, hc, z1, I, J + 1); svert(x1, hd, z1, I + 1, J + 1);
67
+ svert(x0, ha, z0, I, J); svert(x1, hd, z1, I + 1, J + 1); svert(x1, hb, z0, I + 1, J);
68
+ } else {
69
+ svert(x0, ha, z0, I, J); svert(x0, hc, z1, I, J + 1); svert(x1, hb, z0, I + 1, J);
70
+ svert(x1, hb, z0, I + 1, J); svert(x0, hc, z1, I, J + 1); svert(x1, hd, z1, I + 1, J + 1);
71
+ }
72
+ } else if (d) {
73
+ tri(x0, ha, z0, x0, hc, z1, x1, hd, z1);
74
+ tri(x0, ha, z0, x1, hd, z1, x1, hb, z0);
75
+ } else {
76
+ tri(x0, ha, z0, x0, hc, z1, x1, hb, z0);
77
+ tri(x1, hb, z0, x0, hc, z1, x1, hd, z1);
78
+ }
79
+ }
80
+ const out = { pos, nor, col, uv, minH, maxH, sphere: sphereOf(ox, oz, minH, maxH) };
81
+ if (colorMap) out.tex = colorMap(cx, cz);
82
+ return out;
83
+ }
84
+
85
+ function inFlatZone(x, z) { for (const f of cfg.flatten) if (Math.hypot(x - f.x, z - f.z) < f.radius * (f.clearRatio ?? 0.8)) return true; return false; }
86
+ // vegetation placement: the shared rule code (core/scatter.js) over this terrain's height, slope, ground types and edits
87
+ const skip = shape ? (x, z) => !shape.has(x, z) || editedCell(x, z) : editedCell;
88
+ const place = makePlacer({ chunk: CHUNK, seed: SEED, surface, slope, typeAt: biomeAt, fbm, skip, flat: cfg.flatten.length ? inFlatZone : null });
89
+
90
+ const build = shape ? makeIslandBuilder({ CHUNK, RES, CELL, gridH, faceColor, paintColor, cellType, diagOf, gridNormal, textured, smoothLight, colorMap, shape, sphereOf }) : buildChunk;
91
+ return { buildChunk: build, place, gridNormal };
92
+ }