threedog 0.0.0-stage → 0.1.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 (459) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +39 -2
  4. package/core/Animator.js +267 -0
  5. package/core/Assets.js +240 -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/Describe.js +134 -0
  13. package/core/Engine.js +221 -0
  14. package/core/Events.js +95 -0
  15. package/core/I18n.js +94 -0
  16. package/core/Input.js +245 -0
  17. package/core/Inspect.js +97 -0
  18. package/core/InspectScene.js +187 -0
  19. package/core/Jobs.js +146 -0
  20. package/core/Loading.js +149 -0
  21. package/core/Ops.js +272 -0
  22. package/core/Random.js +52 -0
  23. package/core/Rays.js +160 -0
  24. package/core/SaveStore.js +85 -0
  25. package/core/Saves.js +253 -0
  26. package/core/Stream.js +279 -0
  27. package/core/Threads.js +158 -0
  28. package/core/UrlState.js +93 -0
  29. package/core/Vars.js +34 -0
  30. package/core/actor.js +23 -0
  31. package/core/assetEntry.js +89 -0
  32. package/core/assetLoad.js +190 -0
  33. package/core/assetManifest.js +35 -0
  34. package/core/audioRules.js +121 -0
  35. package/core/audioVoice.js +225 -0
  36. package/core/batchGroups.js +116 -0
  37. package/core/canvasBox.js +63 -0
  38. package/core/dayTime.js +15 -0
  39. package/core/describeText.js +136 -0
  40. package/core/easing.js +34 -0
  41. package/core/errorCodes.js +172 -0
  42. package/core/errorHints.js +203 -0
  43. package/core/errors.js +40 -0
  44. package/core/events.generated.js +84 -0
  45. package/core/ground.js +102 -0
  46. package/core/inputContext.js +69 -0
  47. package/core/inputDefaults.js +22 -0
  48. package/core/inputPad.js +35 -0
  49. package/core/inputPointer.js +48 -0
  50. package/core/inputTouch.js +48 -0
  51. package/core/lifecycle.js +68 -0
  52. package/core/lightWatch.js +36 -0
  53. package/core/loop.js +199 -0
  54. package/core/math.js +33 -0
  55. package/core/modules.js +182 -0
  56. package/core/movement.js +19 -0
  57. package/core/mulberry32.js +14 -0
  58. package/core/opsCheck.js +86 -0
  59. package/core/opsGuard.js +26 -0
  60. package/core/opsHistory.js +27 -0
  61. package/core/page.js +78 -0
  62. package/core/pureWorker.js +5 -0
  63. package/core/saveApply.js +128 -0
  64. package/core/saveFiles.js +139 -0
  65. package/core/saveIds.js +53 -0
  66. package/core/saveVersions.js +97 -0
  67. package/core/scatter.js +92 -0
  68. package/core/sceneMethods.js +125 -0
  69. package/core/screenToGround.js +39 -0
  70. package/core/session.js +171 -0
  71. package/core/shadowTypes.js +15 -0
  72. package/core/skip.js +104 -0
  73. package/core/startup.js +133 -0
  74. package/core/streamCells.js +24 -0
  75. package/core/streamSources.js +73 -0
  76. package/core/styleParts.js +96 -0
  77. package/core/targeting.js +64 -0
  78. package/core/thingOps.js +157 -0
  79. package/core/things.js +198 -0
  80. package/core/threadPure.js +120 -0
  81. package/core/threadServe.js +25 -0
  82. package/core/tier.js +11 -0
  83. package/core/validate.js +188 -0
  84. package/docs/AI.md +149 -0
  85. package/docs/API.md +84 -0
  86. package/docs/CODEMAP.md +335 -0
  87. package/docs/COMMANDS.md +96 -0
  88. package/docs/CONVENTIONS.md +134 -0
  89. package/docs/PERF.md +217 -0
  90. package/docs/THREE.md +86 -0
  91. package/docs/api/ambience.md +15 -0
  92. package/docs/api/assets.md +60 -0
  93. package/docs/api/audio.md +53 -0
  94. package/docs/api/budget.md +40 -0
  95. package/docs/api/cameraRig.md +120 -0
  96. package/docs/api/characters.md +142 -0
  97. package/docs/api/clock.md +7 -0
  98. package/docs/api/collision.md +35 -0
  99. package/docs/api/content.md +63 -0
  100. package/docs/api/debug.md +10 -0
  101. package/docs/api/dialogue.md +39 -0
  102. package/docs/api/engine.md +190 -0
  103. package/docs/api/entities.md +61 -0
  104. package/docs/api/events.md +91 -0
  105. package/docs/api/flow.md +27 -0
  106. package/docs/api/grids.md +11 -0
  107. package/docs/api/ground.md +16 -0
  108. package/docs/api/hlod.md +34 -0
  109. package/docs/api/hud.md +31 -0
  110. package/docs/api/i18n.md +10 -0
  111. package/docs/api/input.md +24 -0
  112. package/docs/api/interactions.md +31 -0
  113. package/docs/api/inventory.md +66 -0
  114. package/docs/api/jobs.md +10 -0
  115. package/docs/api/level.md +41 -0
  116. package/docs/api/lightPool.md +56 -0
  117. package/docs/api/music.md +34 -0
  118. package/docs/api/nav.md +26 -0
  119. package/docs/api/net.md +14 -0
  120. package/docs/api/openWorld.md +24 -0
  121. package/docs/api/particles.md +41 -0
  122. package/docs/api/photo.md +15 -0
  123. package/docs/api/post.md +9 -0
  124. package/docs/api/quests.md +36 -0
  125. package/docs/api/rays.md +26 -0
  126. package/docs/api/rigid.md +84 -0
  127. package/docs/api/saves.md +31 -0
  128. package/docs/api/settings.md +36 -0
  129. package/docs/api/sky.md +58 -0
  130. package/docs/api/stream.md +31 -0
  131. package/docs/api/style.md +134 -0
  132. package/docs/api/terrain.md +34 -0
  133. package/docs/api/timeline.md +39 -0
  134. package/docs/api/tools.md +55 -0
  135. package/docs/api/triggers.md +56 -0
  136. package/docs/api/vars.md +9 -0
  137. package/docs/api/vegetation.md +52 -0
  138. package/docs/api/water.md +48 -0
  139. package/docs/api/weather.md +29 -0
  140. package/docs/api/world.md +30 -0
  141. package/docs/recipes/01-new-game.md +148 -0
  142. package/docs/recipes/02-npc.md +151 -0
  143. package/docs/recipes/03-items-pickups.md +158 -0
  144. package/docs/recipes/04-quests.md +83 -0
  145. package/docs/recipes/05-props-bake.md +159 -0
  146. package/docs/recipes/06-clock-events.md +104 -0
  147. package/docs/recipes/07-flow-scenes-pause.md +128 -0
  148. package/docs/recipes/08-weather-sky.md +74 -0
  149. package/docs/recipes/09-style-pack.md +234 -0
  150. package/docs/recipes/10-blender-level.md +67 -0
  151. package/docs/recipes/11-vehicles.md +55 -0
  152. package/docs/recipes/12-navmesh.md +57 -0
  153. package/docs/recipes/13-animation.md +146 -0
  154. package/docs/recipes/14-custom-module.md +91 -0
  155. package/docs/recipes/15-perf.md +78 -0
  156. package/docs/recipes/16-dev-bridge.md +146 -0
  157. package/docs/recipes/18-world.md +185 -0
  158. package/docs/recipes/19-shooting-picking.md +76 -0
  159. package/docs/recipes/20-content-actions-save.md +176 -0
  160. package/docs/recipes/21-camera.md +104 -0
  161. package/docs/recipes/22-shop-gold.md +107 -0
  162. package/docs/recipes/23-ops.md +139 -0
  163. package/docs/recipes/26-ui-parts.md +138 -0
  164. package/docs/recipes/27-net.md +96 -0
  165. package/docs/recipes/28-terrain.md +80 -0
  166. package/docs/recipes/29-grid.md +87 -0
  167. package/docs/recipes/30-templates.md +131 -0
  168. package/docs/recipes/31-audio.md +126 -0
  169. package/docs/recipes/32-action-game.md +33 -0
  170. package/docs/recipes/33-stream-sources.md +37 -0
  171. package/docs/recipes/34-environment-lighting.md +35 -0
  172. package/docs/recipes/35-style-from-reference.md +89 -0
  173. package/docs/recipes/36-sky-ground-plant-looks.md +116 -0
  174. package/docs/recipes/37-terrain-look-hooks.md +97 -0
  175. package/docs/recipes/38-environment-look-hooks.md +81 -0
  176. package/docs/recipes/40-scene.md +79 -0
  177. package/docs/recipes/41-thing-registry.md +64 -0
  178. package/docs/recipes/42-terrain-shape.md +64 -0
  179. package/docs/recipes/43-shader-patches-surface-looks.md +118 -0
  180. package/docs/recipes/44-water-weather-look-hooks.md +133 -0
  181. package/docs/recipes/45-cascaded-shadows.md +51 -0
  182. package/docs/recipes/46-blender-art-route.md +92 -0
  183. package/docs/recipes/47-island-snow-backdrop.md +44 -0
  184. package/examples/action/DESIGN.md +3 -0
  185. package/examples/action/GAMEMAP.md +127 -0
  186. package/examples/action/content/actions.js +8 -0
  187. package/examples/action/content/audio.js +9 -0
  188. package/examples/action/content/index.js +9 -0
  189. package/examples/action/content/items.js +4 -0
  190. package/examples/action/content/places.js +4 -0
  191. package/examples/action/content/props.js +11 -0
  192. package/examples/action/content/templates.js +10 -0
  193. package/examples/action/look.js +5 -0
  194. package/examples/action/main.js +137 -0
  195. package/examples/action/models.js +25 -0
  196. package/examples/sheepisland/GAMEMAP.md +108 -0
  197. package/examples/sheepisland/content/index.js +6 -0
  198. package/examples/sheepisland/content/props.js +19 -0
  199. package/examples/sheepisland/content/templates.js +5 -0
  200. package/examples/sheepisland/content/vegetation.js +8 -0
  201. package/examples/sheepisland/main.js +71 -0
  202. package/examples/sheepisland/params.js +25 -0
  203. package/examples/sheepisland/style/index.js +79 -0
  204. package/examples/sheepisland/style/models.js +59 -0
  205. package/examples/sheepisland/views.js +9 -0
  206. package/examples/styletest/GAMEMAP.md +135 -0
  207. package/examples/styletest/content/index.js +9 -0
  208. package/examples/styletest/content/items.js +8 -0
  209. package/examples/styletest/content/npcs.js +8 -0
  210. package/examples/styletest/content/places.js +5 -0
  211. package/examples/styletest/content/props.js +16 -0
  212. package/examples/styletest/content/templates.js +9 -0
  213. package/examples/styletest/content/vegetation.js +31 -0
  214. package/examples/styletest/look.js +11 -0
  215. package/examples/styletest/main.js +95 -0
  216. package/examples/styletest/models.js +87 -0
  217. package/examples/styletest/overrides.js +33 -0
  218. package/examples/styletest/panel.js +135 -0
  219. package/examples/styletest/params.js +32 -0
  220. package/examples/styletest/views.js +31 -0
  221. package/examples/world/DESIGN.md +5 -0
  222. package/examples/world/GAMEMAP.md +171 -0
  223. package/examples/world/content/actions.js +8 -0
  224. package/examples/world/content/audio.js +25 -0
  225. package/examples/world/content/bodies.js +12 -0
  226. package/examples/world/content/containers.js +4 -0
  227. package/examples/world/content/dialogues.js +33 -0
  228. package/examples/world/content/index.js +17 -0
  229. package/examples/world/content/items.js +10 -0
  230. package/examples/world/content/npcs.js +14 -0
  231. package/examples/world/content/pickups.js +11 -0
  232. package/examples/world/content/places.js +6 -0
  233. package/examples/world/content/props.js +12 -0
  234. package/examples/world/content/quests.js +15 -0
  235. package/examples/world/content/rules.js +23 -0
  236. package/examples/world/content/templates.js +5 -0
  237. package/examples/world/content/vegetation.js +32 -0
  238. package/examples/world/main.js +168 -0
  239. package/examples/world/models.js +28 -0
  240. package/index.d.ts +279 -0
  241. package/index.js +120 -0
  242. package/llms.txt +56 -0
  243. package/modules/ambience/Ambience.js +183 -0
  244. package/modules/camera/FirstPersonCamera.js +133 -0
  245. package/modules/camera/FixedCamera.js +155 -0
  246. package/modules/camera/FollowCamera.js +85 -0
  247. package/modules/camera/RtsCamera.js +134 -0
  248. package/modules/camera/common.js +152 -0
  249. package/modules/camera/index.js +11 -0
  250. package/modules/characters/Character.js +223 -0
  251. package/modules/characters/NPC.js +242 -0
  252. package/modules/characters/assetModel.js +42 -0
  253. package/modules/characters/astar.js +59 -0
  254. package/modules/characters/behaviors.js +72 -0
  255. package/modules/characters/footsteps.js +13 -0
  256. package/modules/characters/index.js +212 -0
  257. package/modules/characters/moveHelpers.js +29 -0
  258. package/modules/characters/movers/common.js +62 -0
  259. package/modules/characters/movers/rapier.js +74 -0
  260. package/modules/characters/movers/simple.js +38 -0
  261. package/modules/characters/npcAvoid.js +129 -0
  262. package/modules/characters/npcSim.js +144 -0
  263. package/modules/characters/npcView.js +42 -0
  264. package/modules/characters/pathAsync.js +107 -0
  265. package/modules/characters/pathJob.js +61 -0
  266. package/modules/characters/pathWorker.js +7 -0
  267. package/modules/characters/playerStrings.js +12 -0
  268. package/modules/characters/proceduralRig.js +54 -0
  269. package/modules/collision/Collision.js +176 -0
  270. package/modules/collision/grid.js +63 -0
  271. package/modules/content/ids.js +95 -0
  272. package/modules/content/index.js +152 -0
  273. package/modules/content/loader.js +187 -0
  274. package/modules/content/models.js +69 -0
  275. package/modules/content/packs.js +69 -0
  276. package/modules/content/props.js +89 -0
  277. package/modules/content/rules.js +133 -0
  278. package/modules/content/templates.js +189 -0
  279. package/modules/debug/DebugPanel.js +168 -0
  280. package/modules/entities/Entities.js +239 -0
  281. package/modules/entities/build.js +25 -0
  282. package/modules/entities/index.js +4 -0
  283. package/modules/flow/index.js +98 -0
  284. package/modules/gameplay/Container.js +227 -0
  285. package/modules/gameplay/Containers.js +89 -0
  286. package/modules/gameplay/Dialogue.js +216 -0
  287. package/modules/gameplay/Interactions.js +243 -0
  288. package/modules/gameplay/Inventory.js +214 -0
  289. package/modules/gameplay/Quests.js +195 -0
  290. package/modules/gameplay/boxOps.js +60 -0
  291. package/modules/gameplay/dialogueBox.js +48 -0
  292. package/modules/gameplay/interactionPrompt.js +28 -0
  293. package/modules/gameplay/inventoryOps.js +137 -0
  294. package/modules/gameplay/pickups.js +113 -0
  295. package/modules/gameplay/questLog.js +54 -0
  296. package/modules/gameplay/questSave.js +71 -0
  297. package/modules/grid/Grid.js +184 -0
  298. package/modules/grid/Layer.js +142 -0
  299. package/modules/grid/index.js +236 -0
  300. package/modules/grid/ops.js +73 -0
  301. package/modules/grid/preview.js +85 -0
  302. package/modules/grid/tiles.js +75 -0
  303. package/modules/hlod/index.js +164 -0
  304. package/modules/hud/index.js +164 -0
  305. package/modules/hud/parts.js +80 -0
  306. package/modules/level/geometry.js +46 -0
  307. package/modules/level/heightfield.js +160 -0
  308. package/modules/level/index.js +231 -0
  309. package/modules/level/nodes.js +84 -0
  310. package/modules/lights/index.js +224 -0
  311. package/modules/music/Music.js +290 -0
  312. package/modules/music/index.js +2 -0
  313. package/modules/music/rules.js +28 -0
  314. package/modules/nav/index.js +154 -0
  315. package/modules/nav/navPath.js +17 -0
  316. package/modules/net/Client.js +136 -0
  317. package/modules/net/Host.js +117 -0
  318. package/modules/net/Net.js +49 -0
  319. package/modules/net/index.js +75 -0
  320. package/modules/net/sync.js +114 -0
  321. package/modules/net/transports.js +118 -0
  322. package/modules/particles/Particles.js +179 -0
  323. package/modules/particles/effect.js +112 -0
  324. package/modules/particles/shaders.js +28 -0
  325. package/modules/photo/Photo.js +143 -0
  326. package/modules/rigid/RigidBodies.js +262 -0
  327. package/modules/rigid/Vehicles.js +97 -0
  328. package/modules/rigid/sync.js +158 -0
  329. package/modules/settings/Settings.js +294 -0
  330. package/modules/settings/apply.js +20 -0
  331. package/modules/settings/index.js +3 -0
  332. package/modules/settings/sections.js +156 -0
  333. package/modules/settings/strings.js +53 -0
  334. package/modules/settings/view.js +65 -0
  335. package/modules/sky/Sky.js +257 -0
  336. package/modules/sky/calendar.js +80 -0
  337. package/modules/sky/cascades.js +125 -0
  338. package/modules/sky/clouds.js +79 -0
  339. package/modules/sky/domeLayers.js +33 -0
  340. package/modules/sky/environment.js +115 -0
  341. package/modules/sky/fog.js +136 -0
  342. package/modules/sky/frame.js +76 -0
  343. package/modules/sky/layers.js +69 -0
  344. package/modules/sky/look.js +50 -0
  345. package/modules/sky/schedule.js +80 -0
  346. package/modules/sky/shader.js +96 -0
  347. package/modules/sky/shadow.js +80 -0
  348. package/modules/sky/skyModule.js +59 -0
  349. package/modules/terrain/ChunkManager.js +291 -0
  350. package/modules/terrain/chunkJob.js +19 -0
  351. package/modules/terrain/chunkQueries.js +42 -0
  352. package/modules/terrain/chunkWorker.js +5 -0
  353. package/modules/terrain/index.js +110 -0
  354. package/modules/terrain/mountTerrain.js +32 -0
  355. package/modules/terrain/terrainColorMap.js +41 -0
  356. package/modules/terrain/terrainDefaults.js +39 -0
  357. package/modules/terrain/terrainEdit.js +139 -0
  358. package/modules/terrain/terrainGen.js +155 -0
  359. package/modules/terrain/terrainIsland.js +131 -0
  360. package/modules/terrain/terrainMesh.js +92 -0
  361. package/modules/terrain/terrainShape.js +108 -0
  362. package/modules/terrain/terrainShapeMain.js +41 -0
  363. package/modules/terrain/terrainTexture.js +44 -0
  364. package/modules/timeline/Timeline.js +249 -0
  365. package/modules/timeline/Tween.js +118 -0
  366. package/modules/timeline/letterbox.js +24 -0
  367. package/modules/timeline/shots.js +88 -0
  368. package/modules/triggers/index.js +261 -0
  369. package/modules/vegetation/Vegetation.js +255 -0
  370. package/modules/vegetation/groundChunks.js +177 -0
  371. package/modules/vegetation/index.js +40 -0
  372. package/modules/vegetation/modelGeometry.js +21 -0
  373. package/modules/water/Water.js +144 -0
  374. package/modules/water/surface.js +88 -0
  375. package/modules/weather/Weather.js +251 -0
  376. package/modules/weather/particles.js +92 -0
  377. package/modules/weather/shaders.js +49 -0
  378. package/modules/world/World.js +231 -0
  379. package/modules/world/cells.js +42 -0
  380. package/modules/world/index.js +64 -0
  381. package/modules/world/persist.js +107 -0
  382. package/modules/world/pos.js +20 -0
  383. package/modules/world/records.js +89 -0
  384. package/modules/world/sim.js +175 -0
  385. package/modules/world/simFar.js +82 -0
  386. package/modules/world/state.js +115 -0
  387. package/modules/world/views.js +182 -0
  388. package/package.json +66 -4
  389. package/presets.js +96 -0
  390. package/render/PostFX.js +243 -0
  391. package/render/detail.js +105 -0
  392. package/render/effects.js +142 -0
  393. package/render/engineUniforms.js +23 -0
  394. package/render/fuse.js +72 -0
  395. package/render/lighting.js +100 -0
  396. package/render/lights.js +16 -0
  397. package/render/materials.js +203 -0
  398. package/render/patches.js +252 -0
  399. package/render/surface.js +67 -0
  400. package/render/uniformDecl.js +29 -0
  401. package/types/common.d.ts +34 -0
  402. package/types/core.d.ts +1773 -0
  403. package/types/gameplay.d.ts +1812 -0
  404. package/types/generated/core/Audio.d.ts +200 -0
  405. package/types/generated/core/Batching.d.ts +47 -0
  406. package/types/generated/core/Budget.d.ts +90 -0
  407. package/types/generated/core/Commits.d.ts +31 -0
  408. package/types/generated/core/Events.d.ts +46 -0
  409. package/types/generated/core/I18n.d.ts +30 -0
  410. package/types/generated/core/Input.d.ts +118 -0
  411. package/types/generated/core/Jobs.d.ts +41 -0
  412. package/types/generated/core/Ops.d.ts +162 -0
  413. package/types/generated/core/Random.d.ts +49 -0
  414. package/types/generated/core/Rays.d.ts +49 -0
  415. package/types/generated/core/Saves.d.ts +161 -0
  416. package/types/generated/core/Stream.d.ts +93 -0
  417. package/types/generated/core/Threads.d.ts +82 -0
  418. package/types/generated/core/audioVoice.d.ts +47 -0
  419. package/types/generated/core/page.d.ts +18 -0
  420. package/types/generated/core/session.d.ts +48 -0
  421. package/types/generated/modules/ambience/Ambience.d.ts +48 -0
  422. package/types/generated/modules/debug/DebugPanel.d.ts +24 -0
  423. package/types/generated/modules/flow/index.d.ts +10 -0
  424. package/types/generated/modules/grid/Grid.d.ts +151 -0
  425. package/types/generated/modules/grid/Layer.d.ts +64 -0
  426. package/types/generated/modules/grid/index.d.ts +86 -0
  427. package/types/generated/modules/hlod/index.d.ts +11 -0
  428. package/types/generated/modules/hud/index.d.ts +10 -0
  429. package/types/generated/modules/lights/index.d.ts +13 -0
  430. package/types/generated/modules/music/Music.d.ts +111 -0
  431. package/types/generated/modules/net/Net.d.ts +34 -0
  432. package/types/generated/modules/net/index.d.ts +53 -0
  433. package/types/generated/modules/net/transports.d.ts +58 -0
  434. package/types/generated/modules/particles/Particles.d.ts +69 -0
  435. package/types/generated/modules/sky/Sky.d.ts +152 -0
  436. package/types/generated/modules/sky/skyModule.d.ts +10 -0
  437. package/types/generated/modules/timeline/Timeline.d.ts +51 -0
  438. package/types/generated/modules/water/Water.d.ts +29 -0
  439. package/types/generated/modules/weather/Weather.d.ts +72 -0
  440. package/types/generated/modules/world/World.d.ts +242 -0
  441. package/types/generated/modules/world/index.d.ts +15 -0
  442. package/types/generated/render/PostFX.d.ts +128 -0
  443. package/types/generated/render/materials.d.ts +90 -0
  444. package/types/generated/render/patches.d.ts +41 -0
  445. package/types/generated/ui/Focus.d.ts +11 -0
  446. package/types/generated/ui/LoadingScreen.d.ts +2 -0
  447. package/types/generated/ui/UI.d.ts +57 -0
  448. package/types/nav.d.ts +52 -0
  449. package/types/physics.d.ts +584 -0
  450. package/types/style.d.ts +628 -0
  451. package/types/worker.d.ts +11 -0
  452. package/types/world.d.ts +772 -0
  453. package/ui/Focus.js +51 -0
  454. package/ui/LoadingScreen.js +42 -0
  455. package/ui/Parts.js +195 -0
  456. package/ui/UI.js +167 -0
  457. package/ui/defaults.js +85 -0
  458. package/ui/theme.js +124 -0
  459. package/ui/touchPart.js +49 -0
@@ -0,0 +1,10 @@
1
+ // Templates: one reusable object = model + collision (+ state). Each placement in props.js is a world record whose kind is the template name.
2
+ // Model names are this example's own generators (models.js, registered in main.js). Recipe: docs/recipes/30-templates.md.
3
+ export default {
4
+ floor: { model: 'floor' }, // walked on; the room has no terrain
5
+ wall: { model: 'wall', collide: 'box' },
6
+ pillar: { model: 'pillar', collide: 'circle' },
7
+ // The enemy: its stats are instance state, so a placement can make a tougher one ({ template: 'slime', hp: 6, maxHp: 6 }).
8
+ // static: false keeps it out of the static ray set, because it moves; hit detection is the example's own rule in main.js.
9
+ slime: { model: 'enemy', static: false, state: { hp: 3, maxHp: 3, damage: 1, cooldown: 0, drop: 'gem' } },
10
+ };
@@ -0,0 +1,5 @@
1
+ // This example's look, as a style part merged over the lowpoly pack (createEngine({ style: [lowpoly, look] })). Logic never reads colors; models.js does.
2
+ export default {
3
+ name: 'action', // a part needs at least one Style field (TypeScript rejects an object that shares none), so it names itself
4
+ action: { floor: 0x5b6168, wall: 0x8a8f96, pillar: 0x9a8c78, enemy: 0x6fbf5a, eye: 0x1d2024 },
5
+ };
@@ -0,0 +1,137 @@
1
+ // @ts-check
2
+ // Action example: one room, one player, one slime, one drop. Shows how an action game wires the engine's systems; the combat rules are this file's own.
3
+ // main.js holds rules only: modules, ops (attack, damage, enemy attack, death), fixed-step logic, presentation. The room, the slime and its stats are
4
+ // content (content/templates.js + props.js, rule R33). The engine has no health, damage or death: all of that is below, as plain game state and ops.
5
+ import { createEngine, openWorld, followCamera, presets, interactions, inventory, content, hud, toast } from '../../index.js';
6
+ import lowpoly from '@threedog/style-lowpoly'; // optional style pack; ?style=none runs with the engine's gray placeholders
7
+ import look from './look.js';
8
+ import data from './content/index.js';
9
+ import { models } from './models.js';
10
+
11
+ const url = new URLSearchParams(location.search);
12
+ // Tuning of the rules (the slime's own numbers are instance state in content/templates.js)
13
+ const TUNE = Object.freeze({
14
+ hp: 5, damage: 1, reach: 1.8, arc: 0.5, attackCooldown: 0.45, // arc = cos of the half-angle in front of the player that a swing hits (60°)
15
+ aggro: 6, enemySpeed: 1.6, enemyReach: 1.3, enemyCooldown: 1.2,
16
+ spawn: Object.freeze({ x: 0, z: -4 }),
17
+ // What happens when the player dies: 'respawn' (back to the spawn, full hp, the room as it is), 'restart' (the room as at the start:
18
+ // session.newGame), 'gameover' (everything stops until R, then newGame). Pick one here or with ?death=...
19
+ onDeath: url.get('death') ?? 'respawn',
20
+ });
21
+
22
+ const style = url.get('style') === 'none' ? undefined : [lowpoly, look];
23
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, ui: { loading: { title: 'action' } }, saveKey: 'threedog-action' });
24
+ // A room needs no terrain, plants, weather, water or physics; a fixed time of day; an over-the-shoulder camera that locks the mouse on click,
25
+ // starting behind the player looking along +Z into the room (yaw = which side of the player the camera sits on: PI = the -Z side)
26
+ engine.use(openWorld({ camera: followCamera({ ...presets.camera.overShoulder, yaw: Math.PI }), terrain: false, vegetation: false, weather: false, water: false, rigid: false, ambience: false,
27
+ sky: { ...presets.calendar.fixedTime, time: 0.42 }, characters: { npcs: false } }),
28
+ interactions({ ...presets.interactions.nearest }), inventory({ ...presets.keys.inventory }), content(), hud());
29
+
30
+ const m = models(engine); // the names content/templates.js uses, written out so `npm run check` can see them
31
+ engine.assets.manifest({ name: 'action', models: { floor: m.floor, wall: m.wall, pillar: m.pillar, enemy: m.enemy } });
32
+ engine.audio.register('blip', (a, p, out) => { a.tone({ freq: (p.freq ?? 440) * p.pitch, dur: 0.12, out }); return 0.12; }); // content/audio.js names it
33
+ engine.characters.createPlayer({ ...presets.player.aim, spawn: TUNE.spawn }); // face where the camera looks: a swing goes where you aim
34
+ engine.content.load(data, { places: { room: { x: 0, z: 0 } } });
35
+
36
+ // ---------- Game state: plain values, described and saved (one player, so it is not keyed by actor) ----------
37
+ /** @returns {{ hp: number, cooldown: number, over: boolean, deaths: number }} */
38
+ const fresh = () => ({ hp: TUNE.hp, cooldown: 0, over: false, deaths: 0 });
39
+ const game = fresh();
40
+ const slimes = () => engine.world.query({ kind: 'slime' }).map(r => ({ id: r.id, hp: r.hp, x: +r.position.x.toFixed(2), z: +r.position.z.toFixed(2) }));
41
+ engine.describe.add('action', () => ({ ...game, maxHp: TUNE.hp, onDeath: TUNE.onDeath, slimes: slimes() }));
42
+ engine.saves.register('action', { version: 1, save: () => ({ ...game }), load: d => { Object.assign(game, fresh(), d); } });
43
+
44
+ // ---------- Ops: every caller (mouse, key, dev bridge, MCP, tests, enemy AI) runs the same rule ----------
45
+ const dist = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
46
+ engine.ops.define('player.attack', {
47
+ desc: 'Swing at every slime within reach in front of the actor',
48
+ can: () => game.over ? 'dead' : game.cooldown > 0 ? 'cooldown' : true,
49
+ run(e, a, ctx) {
50
+ game.cooldown = TUNE.attackCooldown;
51
+ const me = e.world.get(ctx.actor), at = e.actorPosition(ctx.actor), f = me?.facing ?? 0;
52
+ let hits = 0;
53
+ for (const r of e.world.query({ kind: 'slime', near: at, radius: TUNE.reach })) {
54
+ const d = dist(r.position, at) || 1e-6, dot = (Math.sin(f) * (r.position.x - at.x) + Math.cos(f) * (r.position.z - at.z)) / d;
55
+ if (dot >= TUNE.arc && e.ops.run('enemy.damage', { id: r.id, amount: TUNE.damage }).ok) hits++;
56
+ }
57
+ return hits;
58
+ },
59
+ reasons: { dead: 'The player is dead', cooldown: 'Still recovering from the last swing' },
60
+ });
61
+ engine.ops.define('enemy.damage', {
62
+ desc: 'Take hp off a slime; at 0 it dies and leaves its drop', args: { id: 'string', amount: 'number' },
63
+ can: (e, { id }) => e.world.get(id)?.kind === 'slime' || 'noEnemy',
64
+ run(e, { id, amount }) {
65
+ const r = e.world.get(id), hp = Math.max(0, r.hp - amount);
66
+ if (hp > 0) { e.world.set(id, { hp }); e.audio.sfx('hit', { at: r.position }); return hp; }
67
+ // Death: the drop is a pickup made during play (inside an op, rule R33); a stable id ties it to this slime so a save keeps it
68
+ e.inventory.spawnPickup(r.drop, r.position, { id: `${id}-drop`, respawnSeconds: 0 });
69
+ e.world.remove(id); // the saved world remembers the slime is gone
70
+ e.vars.bump('kills');
71
+ e.audio.sfx('kill', { at: r.position });
72
+ return 0;
73
+ },
74
+ reasons: { noEnemy: 'No living slime with that id' },
75
+ });
76
+ engine.ops.define('enemy.attack', {
77
+ desc: 'The acting slime hits the player when in reach and off cooldown',
78
+ can(e, a, ctx) {
79
+ const r = e.world.get(ctx.actor);
80
+ if (r?.kind !== 'slime') return 'notEnemy';
81
+ if (game.over) return 'targetDead';
82
+ return r.cooldown > 0 ? 'cooldown' : dist(r.position, e.actorPosition('player')) > TUNE.enemyReach ? 'outOfReach' : true;
83
+ },
84
+ run(e, a, ctx) {
85
+ const r = e.world.get(ctx.actor);
86
+ r.cooldown = TUNE.enemyCooldown; // a value that changes every step: a direct field write, saved without an event
87
+ game.hp = Math.max(0, game.hp - r.damage);
88
+ e.audio.sfx('hurt');
89
+ if (game.hp === 0) e.ops.run('player.die');
90
+ return game.hp;
91
+ },
92
+ reasons: { notEnemy: 'The actor is not a slime', targetDead: 'The player is already dead', cooldown: 'Still recovering', outOfReach: 'The player is too far' },
93
+ });
94
+ engine.ops.define('player.die', {
95
+ desc: `What dying does in this example (onDeath = ${TUNE.onDeath})`,
96
+ can: () => game.over ? 'dead' : true,
97
+ run(e) {
98
+ game.deaths++;
99
+ if (TUNE.onDeath === 'respawn') { game.hp = TUNE.hp; e.player.placeAt(TUNE.spawn); return 'respawn'; }
100
+ game.over = true; // 'restart' resets at once in the frame hook, 'gameover' waits for R (session.newGame is async flow, not a step)
101
+ return TUNE.onDeath;
102
+ },
103
+ });
104
+
105
+ // ---------- Fixed step: game time (cooldowns, enemy AI, gameplay keys), the same at any frame rate ----------
106
+ engine.world.simulate('slime', {
107
+ near(rec, dt) {
108
+ rec.cooldown = Math.max(0, rec.cooldown - dt);
109
+ const p = engine.actorPosition('player'), d = dist(rec.position, p);
110
+ if (game.over || d > TUNE.aggro) return;
111
+ rec.rot = Math.atan2(p.x - rec.position.x, p.z - rec.position.z); // face the player (+Z is forward)
112
+ if (d > TUNE.enemyReach * 0.8) {
113
+ const s = Math.min(TUNE.enemySpeed * dt, d - TUNE.enemyReach * 0.8);
114
+ engine.world.move(rec.id, { x: rec.position.x + (p.x - rec.position.x) / d * s, z: rec.position.z + (p.z - rec.position.z) / d * s });
115
+ } else if (rec.cooldown === 0) engine.ops.run('enemy.attack', {}, { actor: rec.id });
116
+ },
117
+ });
118
+ engine.onFixed(dt => {
119
+ game.cooldown = Math.max(0, game.cooldown - dt);
120
+ if (engine.input.pressed('attack')) engine.ops.run('player.attack', {}, { source: 'player' });
121
+ });
122
+
123
+ // ---------- Frame: presentation and flow (HUD, death screen, save keys) ----------
124
+ let shownOver = false, restarting = null;
125
+ engine.onFrame(() => {
126
+ engine.hud.bar('hp', { value: game.hp, max: TUNE.hp, label: 'HP' });
127
+ const s = engine.world.query({ kind: 'slime', near: engine.player.position, radius: TUNE.aggro + 2 })[0];
128
+ if (s) engine.hud.bar('enemy', { value: s.hp, max: s.maxHp, label: 'Slime' }); else engine.hud.remove('enemy');
129
+ engine.hud.counter('gem', { icon: '💎', label: 'Gems', value: engine.inventory.count('gem') });
130
+ if (game.over !== shownOver && (shownOver = game.over) && TUNE.onDeath === 'gameover') toast(engine, 'You died. Press R to retry');
131
+ if (game.over && !restarting && (TUNE.onDeath === 'restart' || engine.input.pressed('retry'))) restarting = engine.session.newGame().finally(() => { restarting = null; });
132
+ if (engine.input.pressed('save')) engine.saves.save('slot1').then(ok => { if (ok) toast(engine, 'Saved'); });
133
+ if (engine.input.pressed('load')) engine.saves.load('slot1').then(ok => toast(engine, ok ? 'Loaded' : 'No save yet'));
134
+ });
135
+
136
+ window.engine = engine; // tests, the dev bridge and the console rely on it (before start)
137
+ await engine.start();
@@ -0,0 +1,25 @@
1
+ // Models this example builds in code (floor, wall, pillar, enemy), registered by name in main.js and placed by content/templates.js + props.js.
2
+ // Colors come from the style pack's `action` key (look.js, merged as a style part); with no style pack every model is the engine's neutral gray.
3
+ import { THREE, makeMaterial } from '../../index.js';
4
+
5
+ /** Model generators that read their colors from engine.style.action (missing = gray) @param {{ style: any }} engine */
6
+ export function models(engine) {
7
+ const look = () => engine.style?.action ?? {};
8
+ const mesh = (geo, role, color) => {
9
+ const m = new THREE.Mesh(geo, makeMaterial(role, color === undefined ? {} : { color, flatShading: true }));
10
+ m.castShadow = m.receiveShadow = true;
11
+ return m;
12
+ };
13
+ return {
14
+ floor: () => mesh(new THREE.BoxGeometry(16, 0.2, 16).translate(0, -0.1, 0), 'prop', look().floor),
15
+ wall: () => mesh(new THREE.BoxGeometry(16, 2.4, 0.5).translate(0, 1.2, 0), 'prop', look().wall),
16
+ pillar: () => mesh(new THREE.CylinderGeometry(0.5, 0.6, 2.8, 8).translate(0, 1.4, 0), 'prop', look().pillar),
17
+ // A squat body with two eyes: the eyes face +Z, the facing every character uses (CONVENTIONS: characters face +Z)
18
+ enemy: () => {
19
+ const g = new THREE.Group();
20
+ g.add(mesh(new THREE.SphereGeometry(0.55, 10, 8).scale(1, 0.75, 1).translate(0, 0.42, 0), 'character', look().enemy));
21
+ for (const x of [-0.2, 0.2]) g.add(mesh(new THREE.SphereGeometry(0.09, 6, 4).translate(x, 0.6, 0.48), 'character', look().eye));
22
+ return g;
23
+ },
24
+ };
25
+ }
@@ -0,0 +1,108 @@
1
+ # Game map: sheepisland (generated, do not edit by hand)
2
+
3
+ > Generated by `npm run map` by scanning this folder; paths are relative to it. Pages: /sheepisland.html, entry `main.js`.
4
+ > Content data is in `content/*.js` (condition/effect syntax: `node_modules/threedog/docs/recipes/20-content-actions-save.md`), which main.js hands to the engine with `engine.content.load()`; for the engine API read `node_modules/threedog/docs/API.md` (index) first, then only the module pages listed below.
5
+
6
+ Content: props 15 (from templates 15) · templates 2 · vegetation 1
7
+
8
+ ## Design decisions (hand-written, from DESIGN.md)
9
+
10
+ None yet, write them in `DESIGN.md` (why it is designed this way, what not to change).
11
+
12
+ ## Engine modules (engine.use)
13
+
14
+ - createEngine: { style, saveKey: 'threedog-sheepisland', ui: { loading: { title: 'sheep island' } } }
15
+ - openWorld preset ({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false, sky: { ...pr…) → world, terrain, vegetation, sky, weather, collision, characters, settings, debug
16
+ - content
17
+
18
+ ## Read for this game (per installed module: recipe · api page; core API: `node_modules/threedog/docs/api/engine.md`)
19
+
20
+ - world: `node_modules/threedog/docs/recipes/18-world.md` · `node_modules/threedog/docs/api/world.md`
21
+ - terrain: `node_modules/threedog/docs/recipes/28-terrain.md` · `node_modules/threedog/docs/api/terrain.md`
22
+ - vegetation: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/vegetation.md`
23
+ - sky: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/sky.md`
24
+ - weather: `node_modules/threedog/docs/recipes/08-weather-sky.md` · `node_modules/threedog/docs/api/weather.md`
25
+ - collision: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/collision.md`
26
+ - characters: `node_modules/threedog/docs/recipes/12-navmesh.md` · `node_modules/threedog/docs/api/characters.md`
27
+ - settings: `node_modules/threedog/docs/recipes/26-ui-parts.md` · `node_modules/threedog/docs/api/settings.md`
28
+ - content: `node_modules/threedog/docs/recipes/10-blender-level.md` · `node_modules/threedog/docs/api/content.md`
29
+ - debug: `node_modules/threedog/docs/api/debug.md`
30
+
31
+ Not used yet (check these before writing the system yourself):
32
+
33
+ - inventory: items, stacks, containers and pickups: `inventory({ ...presets.keys.inventory })` (keys required), content/items.js (node_modules/threedog/docs/recipes/03-items-pickups.md)
34
+ - saves: save your own state: `engine.saves.register(key, { version, save, load })` (node_modules/threedog/docs/recipes/20-content-actions-save.md)
35
+ - interactions: press a key near a thing: `interactions({ ...presets.interactions.nearest })` (E, nearest; the game picks the pick mode and keys), template `interact: { label, op }` (node_modules/threedog/docs/recipes/30-templates.md)
36
+ - quests: goals with steps, conditions and rewards: `quests({ ...presets.keys.quests })` (keys required), content/quests.js (node_modules/threedog/docs/recipes/04-quests.md)
37
+ - grids: cell placement for farming and building: `grids()` (node_modules/threedog/docs/recipes/29-grid.md)
38
+
39
+ ## Files
40
+
41
+ content/*.js is content data: how to write it in `node_modules/threedog/docs/recipes/` (02-npc, 03-items-pickups, 04-quests, 20-content-actions-save…).
42
+
43
+ | File | Lines | Description |
44
+ |---|---|---|
45
+ | content/index.js | 7 | |
46
+ | content/props.js | 20 | |
47
+ | content/templates.js | 6 | |
48
+ | content/vegetation.js | 9 | |
49
+ | main.js | 72 | @ts-check Sheep island: a small floating island built only from the engine's public entry points (t… |
50
+ | params.js | 26 | URL parameters of the sheep island page. Import this file first in main.js: it rewrites word values… |
51
+ | style/index.js | 80 | sheepisland: a style pack, LOOKS ONLY (recipes/09-style-pack.md, 35-style-from-reference.md), start… |
52
+ | style/models.js | 60 | sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; regist… |
53
+ | views.js | 10 | Named camera positions of the sheep island. Same name = same framing every time, so two screenshots… |
54
+
55
+ ## NPCs (content/npcs.js)
56
+
57
+ (none)
58
+
59
+ ## Dialogues (content/dialogues.js, node → destination)
60
+
61
+ (none)
62
+
63
+ ## Items (content/items.js)
64
+
65
+ (none)
66
+
67
+ ## Quests (content/quests.js)
68
+
69
+ (none)
70
+
71
+ ## Trigger zones, level markers, places
72
+
73
+ (none)
74
+
75
+ ## Object templates (content/templates.js; placed with props { template }, spawned with engine.spawn)
76
+
77
+ | Template | Model | Collide | Interact (op / label) | Container | State (defaults) | Instances |
78
+ |---|---|---|---|---|---|---|
79
+ | tree | roundTree | circle | — | — | — | 7 placed (world) |
80
+ | sheep | sheep | — | — | — | — | 8 placed (world) |
81
+
82
+ ## Placements (the level is content; counts per content file)
83
+
84
+ - content/props.js: 15 (template tree×7, template sheep×8); 15 with an explicit id, places: world
85
+ - content/vegetation.js: 1 rules (instances generated from each rule)
86
+
87
+ Code that breaks saves or manages world models: none (rule R33).
88
+
89
+ ## Key actions defined by the game (the engine's own are in node_modules/threedog/docs/CODEMAP.md)
90
+
91
+ (none)
92
+
93
+ ## Events the game emits / listens to
94
+
95
+ | Event | Emitted by the game | Listened to by the game |
96
+ |---|---|---|
97
+ | engine:ready | — | main.js |
98
+
99
+ ## Saves
100
+
101
+ - Save prefix saveKey: threedog-sheepisland
102
+ - Content-related saves handled by the engine: story flags and counters (engine.vars), inventory, quest progress, timers (clock, after registered by event name), pickups (world), felled trees (vegetation)
103
+
104
+ ## Style pack keys
105
+
106
+ - Style pack: none (all neutral fallback look)
107
+ - Models (asset names): wheatTuft, roundTree, sheep
108
+ - Vegetation (content/vegetation.js): wheat
@@ -0,0 +1,6 @@
1
+ // Merge every content file in content/ into one object that main.js passes to engine.content.load(). Add a line here for each new content file.
2
+ import templates from './templates.js';
3
+ import props from './props.js';
4
+ import vegetation from './vegetation.js';
5
+
6
+ export default { templates, props, vegetation };
@@ -0,0 +1,19 @@
1
+ // Props in world coordinates (the island is centred on 0, 0; the river runs east-west near z = 2, the wheat field is north-east around 14, -13).
2
+ // Trees ring the meadow, the flock grazes south of the river, facing different ways. rot is yaw in radians.
3
+ export default [
4
+ { id: 'tree-1', template: 'tree', x: -18, z: -10, scale: 1.1, rot: 0.4 },
5
+ { id: 'tree-2', template: 'tree', x: -11, z: -17, scale: 0.9, rot: 2.1 },
6
+ { id: 'tree-3', template: 'tree', x: -21, z: -2, scale: 1.0, rot: 4.0 },
7
+ { id: 'tree-4', template: 'tree', x: 12, z: 17, scale: 1.0, rot: 1.2 },
8
+ { id: 'tree-5', template: 'tree', x: 19, z: 13, scale: 0.85, rot: 5.3 },
9
+ { id: 'tree-6', template: 'tree', x: -2, z: -19, scale: 1.2, rot: 3.1 },
10
+ { id: 'tree-7', template: 'tree', x: 24, z: -2, scale: 0.9, rot: 0.9 },
11
+ { id: 'sheep-1', template: 'sheep', x: -7, z: 12, rot: 0.3 },
12
+ { id: 'sheep-2', template: 'sheep', x: -4.5, z: 13.5, rot: -0.8 },
13
+ { id: 'sheep-3', template: 'sheep', x: -8.5, z: 15, rot: 2.4 },
14
+ { id: 'sheep-4', template: 'sheep', x: -5.5, z: 16.5, rot: 1.1 },
15
+ { id: 'sheep-5', template: 'sheep', x: -2.5, z: 11, rot: -2.0 },
16
+ { id: 'sheep-6', template: 'sheep', x: -10, z: 11.5, rot: 0.9, scale: 0.9 },
17
+ { id: 'sheep-7', template: 'sheep', x: -3, z: 15.5, rot: 3.6, scale: 1.05 },
18
+ { id: 'sheep-8', template: 'sheep', x: -1, z: 13, rot: -0.2, scale: 0.85 },
19
+ ];
@@ -0,0 +1,5 @@
1
+ // Templates: the island's two kinds of objects. Model names come from the example's style asset pack (style/models.js, registered in main.js).
2
+ export default {
3
+ tree: { model: 'roundTree', collide: 'circle' },
4
+ sheep: { model: 'sheep' },
5
+ };
@@ -0,0 +1,8 @@
1
+ // Vegetation: the wheat field. Tufts grow only on the ground type 'wheat' (main.js groundType), so the field's edge is the terrain's, not a list
2
+ // of positions. rule cannot hold functions (it is sent to a worker thread).
3
+ export default {
4
+ wheat: {
5
+ model: 'wheatTuft', wind: 0.04, castShadow: true,
6
+ rule: { perChunk: 9000, cluster: 'none', scale: [1.1, 1.4], stretch: [0.9, 1.15], sink: 0.02, biomes: { wheat: 1 }, avoidFlat: false },
7
+ },
8
+ };
@@ -0,0 +1,71 @@
1
+ // @ts-check
2
+ // Sheep island: a small floating island built only from the engine's public entry points (the acceptance scene of docs/plans/acceptance-sheepisland.md).
3
+ // A meadow with a river, round trees, a wheat field and a flock of sheep on an island with a ragged rim, over a pale backdrop with no horizon.
4
+ // Parameters (params.js): time day | dusk | night, weather clear | snow, view overview | flock | field | river | rim.
5
+ // main.js holds wiring only: modules, the island's terrain functions, view switching and the snow-to-winter link. Objects are content (rule R33),
6
+ // the look is the style pack in style/.
7
+ import { params, VIEW_NAMES } from './params.js'; // first: rewrites ?time=dusk style words before the engine reads the URL
8
+ import { createEngine, openWorld, presets, content, fixedCamera } from '../../index.js';
9
+ import style, { assets } from './style/index.js';
10
+ import data from './content/index.js';
11
+ import { VIEWS } from './views.js';
12
+
13
+ // ---------- 1. The island: outline, height and ground types are world rules, so they live here, not in the style ----------
14
+ // Every function runs in terrain workers: pure, only its parameters and Math (recipe 28 §1).
15
+ const island = {
16
+ resolution: 48, // 64 m chunk / 48 = 1.33 m cells: the rim is cut along cells, so finer cells give a finer brushed edge (recipe 42 §4)
17
+ height: (x, z, n) => {
18
+ const d = Math.abs(z - (6 * Math.sin(x * 0.09) + 2)); // distance to the river's centre line
19
+ return 3 + 1.2 * n.fbm(x * 0.03, z * 0.03) - (d < 3.2 ? (1 - d / 3.2) * 0.6 : 0); // a gentle meadow, a shallow dip for the river
20
+ },
21
+ groundType: (x, z) => {
22
+ if (Math.abs(z - (6 * Math.sin(x * 0.09) + 2)) < 2.4) return 'river';
23
+ const fx = (x - 14) / 9.5, fz = (z + 13) / 6.5; // the wheat field: an ellipse north-east of the river
24
+ return fx * fx + fz * fz < 1 ? 'wheat' : 'grass';
25
+ },
26
+ shape: {
27
+ mask: (x, z) => 30 - Math.hypot(x, z * 1.15), // > 0 is ground: a 60 x 52 m oval
28
+ // a ragged outline and a chipped rim. round stays 0: with round > 0 the bent-down top leaves see-through gaps above the wall (acceptance notes)
29
+ edge: { noise: 3, size: 9, jitter: 0.5, round: 0 },
30
+ // own wall material: it takes no season tint, so in snow the earth walls stay brown under a white top
31
+ side: { depth: 2.5, material: engine => engine.makeMaterial('cliff', { vertexColors: true }) },
32
+ bottom: { depth: (x, z, n, m) => 1.5 + m * 0.35 + 2 * n.fbm(x * 0.08, z * 0.08), ground: 'rock' }, // hangs lower inland
33
+ },
34
+ };
35
+
36
+ // ---------- 2. Engine: own style, open-world preset with a fixed sky; a two-season calendar so snow can turn the island white ----------
37
+ const WINTER_DAY = 1001; // seasons last 1000 days each, so the season never blends towards the next one (it does over the last 20%)
38
+ const engine = createEngine({ canvas: /** @type {HTMLCanvasElement} */ (document.getElementById('view')), style, saveKey: 'threedog-sheepisland',
39
+ ui: { loading: { title: 'sheep island' } } });
40
+ engine.use(openWorld({ camera: fixedCamera(), terrain: island, water: false, rigid: false, ambience: false,
41
+ sky: { ...presets.calendar.fixedTime, time: 0.5, seasons: ['summer', 'winter'], daysPerSeason: 1000 },
42
+ weather: { ...presets.weather.temperate, start: 'clear' }, autoWeather: false }), content());
43
+ engine.assets.manifest(assets);
44
+ engine.content.load(data);
45
+
46
+ // ---------- 3. Snow means winter: the engine's season tint (style.seasons.winter) whitens foliage and ground ----------
47
+ // The weather module sends no change event and a weather has no ground cover of its own, so the calendar day follows the weather each frame.
48
+ engine.onFrame(() => {
49
+ const day = engine.weather?.name === 'snow' ? WINTER_DAY : 1;
50
+ if (engine.sky.day !== day) engine.sky.day = day;
51
+ });
52
+
53
+ // ---------- 4. Views: an op, so the URL, the dev bridge and tests switch the same way ----------
54
+ const state = { view: params.view };
55
+ engine.ops.define('sheepisland.view', {
56
+ desc: 'Move the camera to a named view: overview, flock, field, river, rim', args: { name: 'string' },
57
+ can: (e, { name }) => VIEW_NAMES.includes(name) ? true : 'unknownView',
58
+ run: (e, { name }) => {
59
+ const cam = /** @type {any} */ (engine.cameraRig);
60
+ for (const [n, v] of Object.entries(VIEWS)) cam.add(n, { position: v.pos, lookAt: v.look });
61
+ state.view = name; cam.cut(name);
62
+ return name;
63
+ },
64
+ reasons: { unknownView: 'View names: overview, flock, field, river, rim' },
65
+ });
66
+ engine.describe.add('sheepisland', () => ({ view: state.view, season: engine.sky.season, weather: engine.weather?.name }));
67
+ engine.events.on('engine:ready', () => engine.ops.run('sheepisland.view', { name: params.view }));
68
+ if (params.badView) console.warn(`sheepisland: unknown view '${params.badView}', showing overview. Views: ${VIEW_NAMES.join(', ')}`);
69
+
70
+ engine.start();
71
+ window.engine = engine; // handy for debugging in the browser console
@@ -0,0 +1,25 @@
1
+ // URL parameters of the sheep island page. Import this file first in main.js: it rewrites word values into the forms the engine's own
2
+ // URL state understands (time=dusk -> 18:30, weather=雪 -> snow) before createEngine reads the URL. Same words as the style test page.
3
+ // time day | dusk | night (白天 黄昏 夜晚), or HH:MM weather clear | snow (晴 雪), or any engine weather name
4
+ // view overview | flock | field | river | rim (总览 羊群 麦田 河 边缘)
5
+ /** @type {Record<string, string>} */
6
+ const TIME = { day: '12:00', 白天: '12:00', dusk: '18:30', 黄昏: '18:30', night: '23:00', 夜晚: '23:00' };
7
+ /** @type {Record<string, string>} */
8
+ const WEATHER = { 晴: 'clear', 雪: 'snow' };
9
+ /** @type {Record<string, string>} */
10
+ const VIEWS = { 总览: 'overview', 羊群: 'flock', 麦田: 'field', 河: 'river', 边缘: 'rim' };
11
+ export const VIEW_NAMES = ['overview', 'flock', 'field', 'river', 'rim'];
12
+
13
+ const url = new URL(location.href), q = url.searchParams;
14
+ let changed = false;
15
+ for (const [key, map] of /** @type {[string, Record<string, string>][]} */ ([['time', TIME], ['weather', WEATHER]])) {
16
+ const v = q.get(key);
17
+ if (v && map[v]) { q.set(key, map[v]); changed = true; }
18
+ }
19
+ if (changed) history.replaceState(null, '', url);
20
+
21
+ const view = VIEWS[q.get('view')] ?? q.get('view') ?? 'overview';
22
+ export const params = Object.freeze({
23
+ view: VIEW_NAMES.includes(view) ? view : 'overview',
24
+ badView: q.has('view') && !VIEW_NAMES.includes(view) ? q.get('view') : null,
25
+ });
@@ -0,0 +1,79 @@
1
+ // sheepisland: a style pack, LOOKS ONLY (recipes/09-style-pack.md, 35-style-from-reference.md), started from the new-style template
2
+ // (packages/tools/templates/style). A soft painted diorama: few flat colors, round shapes, soft shadows, a pale warm background with no horizon.
3
+ // The world (island outline, river, wheat field) is the game's terrain() in ../main.js, never here.
4
+ import { makeMaterial, applyEffects } from '../../../index.js';
5
+ import { models, PALETTE } from './models.js';
6
+
7
+ export { models };
8
+ /** Asset pack of the procedural models: engine.assets.manifest(assets) registers roundTree, sheep and wheatTuft */
9
+ export const assets = { name: 'sheepisland', models };
10
+
11
+ // Background: zenith = horizon = fog color at every time, so the dome is one flat tone and no horizon line shows.
12
+ // [time 0-1, zenith, horizon (= fog), sun color, sun intensity, ambient intensity]
13
+ // Ground material with snow that survives shading: 'texture'. The engine's season tint runs at color_fragment, before the per-chunk color map is
14
+ // multiplied in, so in 'mix' mode the map paints the green back over the white. This patch repeats the season mix later (emissivemap_fragment,
15
+ // after every color patch, before lighting), reading the engine's own season uniforms under new names (the season patch declares the old ones).
16
+ /** @param {any} engine */
17
+ function snowyGround(engine) {
18
+ const u = engine.uniforms;
19
+ return applyEffects(makeMaterial('terrain', { vertexColors: true }, engine), { clouds: false, patches: [{
20
+ name: 'snowCover', cacheKey: 1, uniforms: { uSnowTint: u.uGroundTint, uSnowMix: u.uGroundMix },
21
+ glsl: { fragment: { pars: 'uniform vec3 uSnowTint; uniform float uSnowMix;',
22
+ emissivemap_fragment: 'diffuseColor.rgb = mix(diffuseColor.rgb, uSnowTint, uSnowMix);' } } }] });
23
+ }
24
+
25
+ const DAY = 0xefebe4, DUSK = 0xf0d9c4, NIGHT = 0x2c3346;
26
+ export default {
27
+ name: 'sheepisland',
28
+ exposure: 1,
29
+ toneMapping: 'neutral', // neutral keeps the painted colors close to what is written here (aces darkens and shifts them)
30
+
31
+ post: [], // restraint: the reference shows no outline, bloom or grain
32
+
33
+ materials: {
34
+ default: { type: 'lambert' },
35
+ leaf: { type: 'lambert' },
36
+ bark: { type: 'lambert' },
37
+ wool: { type: 'lambert' },
38
+ face: { type: 'lambert' },
39
+ cliff: { type: 'lambert' },
40
+ vegetation: { type: 'lambert', side: 2 }, // the wheat stalks are thin: both sides (THREE.DoubleSide = 2)
41
+ },
42
+
43
+ // Soft light: half-lambert wrap so the shade side of a round blob is not black, and a cool blue shade instead of a gray one
44
+ lighting: { wrap: 0.45, shadowTint: { color: 0x7d88b8, strength: 0.45, soft: 0.3 } },
45
+
46
+ palette: PALETTE,
47
+
48
+ sky: {
49
+ keyframes: [
50
+ [0.00, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
51
+ [0.22, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
52
+ [0.30, DAY, DAY, 0xfff0dc, 1.8, 1.0],
53
+ [0.50, DAY, DAY, 0xfffaf0, 2.3, 1.15],
54
+ [0.70, DAY, DAY, 0xffe6c8, 1.9, 1.0],
55
+ [0.77, DUSK, DUSK, 0xffb07a, 1.5, 0.85],
56
+ [0.84, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
57
+ [1.00, NIGHT, NIGHT, 0x9aaad8, 0.7, 0.85],
58
+ ],
59
+ groundTint: 0xb8c49a, // ambient bounce from below: the green of the meadow, not gray
60
+ sunBrightness: 0, sunGlow: 0, moonBrightness: 0, starDensity: 0, // a flat painted backdrop: no disc, glow or stars
61
+ clouds: { coverage: 0 },
62
+ shadow: { type: 'pcf', radius: 4, extent: 45, mapSize: 2048 }, // soft edges; the island is small, so a tight box keeps them sharp enough
63
+ fog: { kind: 'exp', density: 0.0015 }, // barely there: the far rim fades a touch into the backdrop
64
+ },
65
+
66
+ terrain: {
67
+ config: { shading: 'texture', colorResolution: 256 }, // crisp river bank and field edge without more triangles (recipe 37); 128 (0.5 m pixels) shows stairs up close
68
+ colors: { grassA: 0x92c062, grassB: 0x86b658, river: 0x6aa6d6, riverDeep: 0x5b97ca, wheatA: 0xdcae48, wheatB: 0xd2a442,
69
+ earth: 0xb98d64, rock: 0x94705a },
70
+ biomeColors: { grass: ['grassA', 'grassB'], river: ['river', 'riverDeep'], wheat: ['wheatA', 'wheatB'], cliff: ['earth'], rock: ['rock'] },
71
+ variation: { blend: { size: 14, strength: 0.6 }, jitter: { size: 0.5, min: 0.97, range: 0.04 } }, // low texture: almost no grain
72
+ material: snowyGround,
73
+ },
74
+
75
+ // Snow: winter in the calendar turns foliage and ground most of the way to white ('mix', so green does not go muddy)
76
+ seasons: { mode: /** @type {const} */ ('mix'), strength: 0.82, winter: { foliage: 0xf6f6f8, ground: 0xf4f5f8 } },
77
+ // snow greys the sky towards overcastColor and dims the sun: keep the backdrop pale and the island readable
78
+ weather: { snow: { color: 0xffffff }, overcastColor: 0xe6e3de, types: { snow: { sun: 0.8, grey: 0.25 } } },
79
+ };
@@ -0,0 +1,59 @@
1
+ // sheepisland procedural models: a round tree, a sheep, a wheat tuft. Built in code, no files; registered as an asset pack (index.js `assets`).
2
+ // Colors come from the palette (the engine calls a `function` generator with this.palette = style.palette).
3
+ // Shapes are clusters of smooth spheres: the reference reads as soft blobs, not facets. Shadow flags are set here (the engine does not guess them).
4
+ import { THREE, makeMaterial, applyEffects, mergeColored } from '../../../index.js';
5
+
6
+ /** Default palette of this pack: style.palette */
7
+ export const PALETTE = {
8
+ leaf: 0x6fa64a, // tree crown, main
9
+ leafLight: 0x8fbf5c, // tree crown, upper blobs
10
+ bark: 0x8a6448,
11
+ wool: 0xf3efe6,
12
+ face: 0x2b2725, // sheep face and legs
13
+ wheat: 0xe2b448,
14
+ wheatTip: 0xf0cf6a,
15
+ };
16
+ const pal = ctx => ({ ...PALETTE, ...ctx?.palette });
17
+
18
+ const mesh = (geo, mat) => { const m = new THREE.Mesh(geo, mat); m.castShadow = m.receiveShadow = true; return m; };
19
+ const ball = (r, x, y, z, detail = 3) => new THREE.IcosahedronGeometry(r, detail).translate(x, y, z);
20
+
21
+ // Crown blobs of the round tree: [radius, x, y, z]. Fixed, so every tree has the same silhouette; props vary scale and rotation.
22
+ const CROWN = [[1.7, 0, 3.6, 0], [1.25, 1.1, 3.1, 0.4], [1.2, -1.0, 3.2, -0.5], [1.1, 0.2, 4.6, -0.3], [1.0, -0.4, 3.0, 1.0]];
23
+
24
+ export const models = {
25
+ /** A round tree: short trunk, crown of five soft blobs. The crown takes the season tint (foliage), so a winter style turns it white */
26
+ roundTree: function () {
27
+ const c = pal(this), g = new THREE.Group();
28
+ g.add(mesh(new THREE.CylinderGeometry(0.22, 0.32, 2.6, 8).translate(0, 1.3, 0), makeMaterial('bark', { color: c.bark })));
29
+ // two shades in one geometry: upper blobs lighter, as if lit from above; vertex colors so it stays one draw
30
+ const crown = mergeColored(CROWN.map(([r, x, y, z], i) => [ball(r, x, y, z), i === 3 ? c.leafLight : c.leaf]), { flat: false }); // flat: false = smooth blobs (the default is faceted)
31
+ // applyEffects season: material specs have no `season` key, so a code-built model opts in here (see the acceptance notes)
32
+ g.add(mesh(crown, applyEffects(makeMaterial('leaf', { vertexColors: true }), { season: 'foliage' })));
33
+ return g;
34
+ },
35
+
36
+ /** A sheep, about 1.4 m long, facing +Z: a body of wool blobs, a black head and four black legs */
37
+ sheep: function () {
38
+ const c = pal(this), g = new THREE.Group();
39
+ const wool = mergeColored([[0.5, 0, 0.75, 0], [0.42, 0, 0.8, 0.38], [0.42, 0, 0.8, -0.38], [0.36, 0.22, 0.98, 0], [0.36, -0.22, 0.98, 0.1]]
40
+ .map(([r, x, y, z]) => [ball(r, x, y, z, 2), c.wool]), { flat: false });
41
+ g.add(mesh(wool, makeMaterial('wool', { vertexColors: true })));
42
+ const black = makeMaterial('face', { color: c.face });
43
+ g.add(mesh(new THREE.SphereGeometry(0.22, 16, 12).scale(0.85, 1, 1.25).translate(0, 0.9, 0.78), black)); // head
44
+ for (const [x, z] of [[0.2, 0.32], [-0.2, 0.32], [0.2, -0.32], [-0.2, -0.32]])
45
+ g.add(mesh(new THREE.CylinderGeometry(0.06, 0.06, 0.5, 6).translate(x, 0.25, z), black)); // legs
46
+ return g;
47
+ },
48
+
49
+ /** One wheat tuft for content vegetation (a generator returning a geometry): nine stalks with ears, vertex-colored, one draw per chunk */
50
+ wheatTuft: function () {
51
+ const c = pal(this), parts = [];
52
+ for (let i = 0; i < 9; i++) {
53
+ const a = i * 2.4, r = i ? 0.06 + 0.02 * i : 0, x = Math.cos(a) * r, z = Math.sin(a) * r, h = 0.85 + (i % 3) * 0.1;
54
+ parts.push([new THREE.CylinderGeometry(0.012, 0.018, h, 3).translate(x, h / 2, z), c.wheat]);
55
+ parts.push([new THREE.SphereGeometry(0.06, 5, 4).scale(1, 2.6, 1).translate(x, h + 0.08, z), c.wheatTip]);
56
+ }
57
+ return mergeColored(/** @type {any} */ (parts));
58
+ },
59
+ };
@@ -0,0 +1,9 @@
1
+ // Named camera positions of the sheep island. Same name = same framing every time, so two screenshots differ only by time, weather or style.
2
+ // The island is centred on (0, 0) and is about 60 m across; positions are [x, y, z] in world space.
3
+ export const VIEWS = {
4
+ overview: { pos: [0, 36, 48], look: [0, -1, 0] }, // the whole island floating on the backdrop, from the south, a little above
5
+ flock: { pos: [4, 7, 26], look: [-5, 1, 13] }, // the sheep, the river behind them
6
+ field: { pos: [26, 12, 6], look: [13, 1, -12] }, // the wheat field and the trees beyond
7
+ river: { pos: [-4, 12, 9], look: [-6, 1, 0] }, // the river banks from above: how crisp the ground-type border is
8
+ rim: { pos: [-30, 5, 30], look: [-20, 0, 16] }, // the ragged rim and the wall under it, seen from just above the edge
9
+ };