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,162 @@
1
+ // Fixed-shot camera (classic Resident Evil / horror style): several shots placed in the scene, switched as the situation changes.
2
+ // - cut('name') switches at once; blend('name', seconds) transitions smoothly
3
+ // - Auto switching: auto: 'nearest' picks the shot closest to the player; or a trigger zone (triggers module) emits the trigger:enter event,
4
+ // and a tag 'camera:<shot name>' switches to that shot (triggerBlend decides how)
5
+ // - A shot can look at a fixed point (lookAt) or turn with the player via track: true
6
+ // - Movement direction follows the current view: pressing "up" walks into the screen. If a direction key is still held at a shot change, the old direction is kept until release
7
+ // Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
8
+ //
9
+ // engine.use(fixedCamera({
10
+ // shots: {
11
+ // hall: { position: [0, 6, 12], lookAt: [0, 0, 0], fov: 50 },
12
+ // garden: { position: [30, 4, 0], track: true, at: [24, 0, 0] }, // at: position used for the "nearest shot" test, defaults to position
13
+ // },
14
+ // start: 'hall', auto: 'nearest',
15
+ // }));
16
+ // engine.cameraRig.blend('garden', 1.5);
17
+ import * as THREE from 'three';
18
+ import { rigModule, defineRig, viewForward, rightOf } from './common.js';
19
+ import { setProjection } from './projection.js';
20
+ import { vec3 } from '../../core/math.js';
21
+ import { ease as easing } from '../../core/easing.js';
22
+ import { checkOptions, warnMissing } from '../../core/validate.js';
23
+
24
+ export class FixedCamera {
25
+ /**
26
+ * shots { name: { position, lookAt | track: true, fov, at, trackHeight, projection: 'orthographic', size } } (size: world units of view height; default perspective);
27
+ * single-shot shorthand: fixedCamera({ position, lookAt, projection, size }); start initial shot;
28
+ * auto false | 'nearest' (every autoInterval seconds pick the nearest shot); hysteresis how many meters closer a new shot must be to win (avoids flip-flopping);
29
+ * triggerBlend transition seconds for trigger-zone switches (0 = hard cut); trackHeight how high on the character a track shot looks; trackSmoothing head-tracking smoothness;
30
+ * holdDirection keep the direction at a shot change until the key is released (classic fixed-camera controls)
31
+ */
32
+ constructor(engine, { shots = {}, start = null, auto = false, autoInterval = 0.25, hysteresis = 2, triggerBlend = 0,
33
+ trackHeight = 1.2, trackSmoothing = 8, holdDirection = true, ease = 'inOutCubic', ...rest } = {}) {
34
+ if (!Object.keys(shots).length && rest.position) shots = { main: rest }; // setCamera('fixed', { position, lookAt, projection, size })
35
+ else checkOptions('fixedCamera()', rest, []);
36
+ Object.assign(this, { engine, auto, autoInterval, hysteresis, triggerBlend, trackHeight, trackSmoothing, holdDirection, ease });
37
+ this.shots = {};
38
+ for (const [n, s] of Object.entries(shots)) this.add(n, s);
39
+ this.target = null;
40
+ this.current = null;
41
+ this._blend = null; this._autoT = 0; this._held = null;
42
+ this._look = new THREE.Vector3();
43
+ this._baseFov = engine.camera.fov;
44
+ this._dir = { f: { x: 0, z: -1 }, r: { x: 1, z: 0 } };
45
+ engine.events.on('trigger:enter', p => {
46
+ const tag = p.tag;
47
+ const m = typeof tag === 'string' && tag.match(/^camera:(.+)$/);
48
+ if (m && this.shots[m[1]]) this.triggerBlend > 0 ? this.blend(m[1], this.triggerBlend) : this.cut(m[1]);
49
+ });
50
+ const first = start || Object.keys(this.shots)[0];
51
+ if (first) this.cut(first);
52
+ }
53
+
54
+ /** Add or replace a shot */
55
+ add(name, s) {
56
+ checkOptions(`fixedCamera shots.${name}`, s, ['position', 'lookAt', 'track', 'fov', 'at', 'trackHeight', 'projection', 'size']);
57
+ if (s.projection === 'orthographic' && !(s.size > 0)) throw new Error(`fixedCamera shots.${name}: projection 'orthographic' needs size > 0 (world units of view height)`);
58
+ this.shots[name] = {
59
+ position: vec3(s.position), lookAt: s.lookAt ? vec3(s.lookAt) : null, track: !!s.track || !s.lookAt,
60
+ fov: s.fov ?? null, size: s.projection === 'orthographic' ? s.size : null, at: s.at ? vec3(s.at) : null, trackHeight: s.trackHeight,
61
+ };
62
+ return this;
63
+ }
64
+ follow(obj) { this.target = obj; }
65
+ /** Cut to a shot at once */
66
+ cut(name) {
67
+ const s = this.shots[name]; if (!s) { warnMissing('shot', name, Object.keys(this.shots)); return; }
68
+ const changed = this.current !== name;
69
+ this.current = name;
70
+ this._blend?.res(); this._blend = null; // interrupt a running blend: its Promise still resolves (await blend() never hangs)
71
+ this._lookTarget(s, this._look);
72
+ this._place(s.position, this._look, s.fov ?? this._baseFov, s.size);
73
+ if (changed) { this._latchDirection(); this.engine.events.emit('camera:shot', { name }); }
74
+ }
75
+ /** Blend smoothly to a shot; returns a Promise that resolves when the blend ends */
76
+ blend(name, seconds = 1, ease = this.ease) {
77
+ const s = this.shots[name]; if (!s) { warnMissing('shot', name, Object.keys(this.shots)); return Promise.resolve(); }
78
+ if (seconds <= 0 || !this.current) { this.cut(name); return Promise.resolve(); }
79
+ const cam = this.engine.camera;
80
+ return new Promise(res => {
81
+ this._blend?.res();
82
+ this._blend = { from: cam.position.clone(), fromLook: this._look.clone(), fromFov: cam.fov, fromSize: cam.orthoSize || null, t: 0, dur: seconds, ease, res };
83
+ this.current = name;
84
+ this._latchDirection();
85
+ this.engine.events.emit('camera:shot', { name });
86
+ });
87
+ }
88
+
89
+ // Direction: follows the current view; if a direction key is held at a shot change, keep the old direction
90
+ forward() { return (this._held || this._dir).f; }
91
+ right() { return (this._held || this._dir).r; }
92
+ focusPoint() { return this.target ? this.target.position : this._look; }
93
+
94
+ update(dt, input) {
95
+ const s = this.shots[this.current];
96
+ if (!s) return;
97
+ if (this.auto === 'nearest' && this.target && (this._autoT -= dt) <= 0) {
98
+ this._autoT = this.autoInterval;
99
+ const n = this.nearest(this.target.position);
100
+ if (n && n !== this.current) {
101
+ const p = this.target.position, d = k => (this.shots[k].at || this.shots[k].position).distanceTo(p);
102
+ if (d(n) + this.hysteresis < d(this.current)) this.triggerBlend > 0 ? this.blend(n, this.triggerBlend) : this.cut(n);
103
+ }
104
+ }
105
+ const want = this._lookTarget(this.shots[this.current], this._want ??= new THREE.Vector3()); // scratch vectors: no per-frame allocation
106
+ const fov = this.shots[this.current].fov ?? this._baseFov;
107
+ if (this._blend) {
108
+ const b = this._blend; b.t += dt;
109
+ const k = easing(b.ease)(Math.min(1, b.t / b.dur));
110
+ const sh = this.shots[this.current];
111
+ const pos = (this._bp ??= new THREE.Vector3()).copy(b.from).lerp(sh.position, k), look = (this._bl ??= new THREE.Vector3()).copy(b.fromLook).lerp(want, k);
112
+ this._look.copy(look);
113
+ // size blends only between two orthographic shots; a perspective/orthographic mix switches to the target's mode at once
114
+ this._place(pos, look, b.fromFov + (fov - b.fromFov) * k, sh.size && b.fromSize ? b.fromSize + (sh.size - b.fromSize) * k : sh.size);
115
+ if (b.t >= b.dur) { this._blend = null; b.res(); }
116
+ } else {
117
+ if (this.shots[this.current].track) this._look.lerp(want, 1 - Math.exp(-this.trackSmoothing * dt));
118
+ else this._look.copy(want);
119
+ this._place(this.shots[this.current].position, this._look, fov, s.size);
120
+ }
121
+ // Direction: release the hold once no direction key is pressed
122
+ const a = input.axis;
123
+ if (this._held && Math.abs(a.x) < 0.05 && Math.abs(a.y) < 0.05) this._held = null;
124
+ const f = viewForward(this.engine.camera, this._dir.f);
125
+ this._dir = { f, r: rightOf(f) };
126
+ }
127
+
128
+ /** Name of the shot nearest a point */
129
+ nearest(p) {
130
+ let best = null, bd = Infinity;
131
+ for (const [n, s] of Object.entries(this.shots)) { const d = (s.at || s.position).distanceTo(p); if (d < bd) { bd = d; best = n; } }
132
+ return best;
133
+ }
134
+
135
+ _lookTarget(s, out) {
136
+ if (!s.track && s.lookAt) return out.copy(s.lookAt);
137
+ if (this.target) { out.copy(this.target.position); out.y += s.trackHeight ?? this.trackHeight; return out; }
138
+ return s.lookAt ? out.copy(s.lookAt) : out.set(s.position.x, s.position.y, s.position.z - 1);
139
+ }
140
+ _place(pos, look, fov, size = null) {
141
+ const cam = this.engine.camera;
142
+ cam.position.copy(pos); cam.lookAt(look);
143
+ setProjection(cam, size ? 'orthographic' : 'perspective', size);
144
+ if (Math.abs(cam.fov - fov) > 1e-3) { cam.fov = fov; cam.updateProjectionMatrix(); }
145
+ }
146
+ _latchDirection() {
147
+ if (!this.holdDirection) return;
148
+ const a = this.engine.input.axis;
149
+ if (Math.abs(a.x) > 0.05 || Math.abs(a.y) > 0.05) this._held ??= { f: this._dir.f, r: this._dir.r };
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Fixed-shot camera module. Installs engine.cameraRig (pick it or followCamera).
155
+ * fixedCamera({ shots: { name: { position, lookAt | track: true, fov } }, start, auto: 'nearest' })
156
+ * A trigger zone tag 'camera:<name>' switches to that shot on enter. A camera:shot { name } event fires on every switch.
157
+ */
158
+ export function fixedCamera(opts = {}) { return rigModule('fixed', opts); }
159
+ defineRig('fixed', (e, opts) => {
160
+ return new FixedCamera(e, opts);
161
+ }, ['shots', 'start', 'auto', 'autoInterval', 'hysteresis', 'triggerBlend', 'trackHeight', 'trackSmoothing', 'holdDirection', 'ease',
162
+ 'position', 'lookAt', 'track', 'fov', 'projection', 'size', 'at']); // the last row: setCamera('fixed', { position, lookAt }) is a one-shot form
@@ -0,0 +1,91 @@
1
+ // Third-person follow camera: drag (or pointer lock) to rotate, wheel to zoom, stays out of the terrain, smooth follow,
2
+ // optional shoulder offset and lock-on framing.
3
+ // yaw is which side of the focus the camera sits on: camera = focus + (sin yaw, cos yaw) * distance, so it looks along forward() = -(sin yaw, cos yaw).
4
+ // To see a character facing angle f from behind, yaw = f + PI.
5
+ // Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
6
+ // Other cameras: firstPersonCamera, fixedCamera, rtsCamera (top-down strategy); all are engine.cameraRig; switch at runtime with engine.setCamera('firstPerson').
7
+ import * as THREE from 'three';
8
+ import { rigModule, defineRig, YAW_RIG, clickToLock, releaseLock } from './common.js';
9
+ import { setProjection } from './projection.js';
10
+
11
+ export class FollowCamera {
12
+ /** yaw/pitch initial angles (yaw: see the top of this file); distance (min/max zoom range); height how high on the character to look; smoothing follow smoothness;
13
+ * sensitivity drag sensitivity; minPitch/maxPitch pitch range; zoomStep zoom ratio per wheel notch; groundClearance lowest camera height above the ground;
14
+ * shoulder meters to the right of the target the camera aims (over-the-shoulder; negative = left shoulder, 0 = centered);
15
+ * pointerLock click locks the mouse (no dragging; the press that locks is swallowed, swallowLockClick: false delivers it) */
16
+ constructor(engine, { yaw = 0.8, pitch = 0.42, distance = 13, minDistance = 4, maxDistance = 45, height = 1.4, smoothing = 10,
17
+ sensitivity = 1, minPitch = 0.05, maxPitch = 1.35, zoomStep = 0.1, groundClearance = 1.2, invertY = false, shoulder = 0, pointerLock = false, swallowLockClick = true, projection = 'perspective', size = 20 } = {}) {
18
+ this.projection = projection; this.size = size; // 'orthographic': size = world units of view height (the wheel changes size there, clamped to the min/max distance ratio)
19
+ this.size0 = size; this.distance0 = distance;
20
+ Object.assign(this, { engine, yaw, pitch, distance, minDistance, maxDistance, height, smoothing, sensitivity, minPitch, maxPitch, zoomStep, groundClearance });
21
+ Object.assign(this, { invertY, shoulder, pointerLock, swallowLockClick });
22
+ this.target = null;
23
+ /** Lock-on framing set by frame(): { target, strength } or null */
24
+ this.framing = null;
25
+ this.focus = new THREE.Vector3();
26
+ }
27
+ /** Follow obj; opts { distance, height } temporarily override distance/height (for driving), restored on the next follow */
28
+ follow(obj, opts) {
29
+ if (this._saved) { Object.assign(this, this._saved); this._saved = null; }
30
+ if (opts) { this._saved = { distance: this.distance, height: this.height }; if (opts.distance != null) this.distance = opts.distance; if (opts.height != null) this.height = opts.height; }
31
+ this.target = obj; if (obj) this.focus.copy(obj.position);
32
+ }
33
+
34
+ /**
35
+ * Lock-on framing: each frame turn yaw toward "behind the followed object, looking at target" (forward() turns with it, so camera-relative movement strafes around the target).
36
+ * Mouse / stick yaw is ignored while framing; frame(null) hands yaw back. strength: how fast it turns (1/s). Set it once when the lock starts, not every frame
37
+ * @example engine.cameraRig.frame(enemy.object); player.faceMode = 'target'; player.faceTarget = enemy.object;
38
+ */
39
+ frame(target, { strength = 6 } = {}) { this.framing = target ? { target, strength } : null; }
40
+ onEnter(switched) { clickToLock(this, switched); setProjection(this.engine.camera, this.projection, this.size); }
41
+ onExit() { releaseLock(this); }
42
+ onOverride(on) { if (on) releaseLock(this, true); }
43
+
44
+ update(dt, input) {
45
+ const cam = this.engine.camera, fr = this.framing;
46
+ if (fr && this.target) {
47
+ const t = fr.target.position ?? fr.target, p = this.target.position;
48
+ const want = Math.atan2(p.x - t.x, p.z - t.z), d = Math.atan2(Math.sin(want - this.yaw), Math.cos(want - this.yaw));
49
+ this.yaw += d * Math.min(1, dt * fr.strength);
50
+ }
51
+ if (input.enabled) {
52
+ if (!fr) this.yaw -= input.look.dx * 0.005 * this.sensitivity;
53
+ if (!this.lockPitch) this.pitch = Math.min(this.maxPitch, Math.max(this.minPitch, this.pitch + input.look.dy * 0.004 * this.sensitivity * (this.invertY ? -1 : 1)));
54
+ if (input.look.zoom && this.projection === 'orthographic') {
55
+ // distance shows nothing in an orthographic view: zoom `size`, clamped to the same min/max ratio as distance, same wheel feel
56
+ const lo = this.size0 * this.minDistance / this.distance0, hi = this.size0 * this.maxDistance / this.distance0;
57
+ this.size = Math.min(hi, Math.max(lo, this.size * (1 + input.look.zoom * this.zoomStep)));
58
+ cam.orthoSize = this.size; cam.updateProjectionMatrix();
59
+ } else if (input.look.zoom) this.distance = Math.min(this.maxDistance, Math.max(this.minDistance, this.distance * (1 + input.look.zoom * this.zoomStep)));
60
+ }
61
+ if (!this.target) return;
62
+ const want = this.target.position;
63
+ this.focus.lerp(want, 1 - Math.exp(-this.smoothing * dt));
64
+ // shoulder: shift the aim point (and so the camera) sideways along right()
65
+ const sh = this.shoulder, fx = this.focus.x + Math.cos(this.yaw) * sh, fy = this.focus.y + this.height, fz = this.focus.z - Math.sin(this.yaw) * sh, cp = Math.cos(this.pitch);
66
+ const place = d => cam.position.set(fx + Math.sin(this.yaw) * cp * d, fy + Math.sin(this.pitch) * d, fz + Math.cos(this.yaw) * cp * d);
67
+ place(this.distance);
68
+ // Occlusion: pull in when a trunk or house blocks the view (at once); ease back out when clear
69
+ const allowed = this.engine.collision && this.avoidOcclusion !== false ? this.engine.collision.cameraDistance({ x: fx, y: fy, z: fz }, cam.position, this.distance) : this.distance;
70
+ this._d = this._d ?? this.distance;
71
+ this._d = allowed < this._d ? allowed : this._d + (allowed - this._d) * (1 - Math.exp(-3 * dt));
72
+ place(this._d);
73
+ const ground = this.engine.surface(cam.position.x, cam.position.z) + this.groundClearance;
74
+ if (cam.position.y < ground) cam.position.y = ground;
75
+ cam.lookAt(fx, fy, fz);
76
+ }
77
+ }
78
+
79
+ // Forward/right directions relative to the camera heading (for character movement), and the focus point: shared YAW_RIG
80
+ Object.assign(FollowCamera.prototype, YAW_RIG);
81
+
82
+ /**
83
+ * Third-person follow camera module. Installs engine.cameraRig; engine.cameraRig.follow(object).
84
+ * Over the shoulder: followCamera({ distance: 3, shoulder: 0.7, pitch: 0.15, pointerLock: true }); lock-on: engine.cameraRig.frame(target)
85
+ * Top-down game: followCamera({ pitch: 1.1, distance: 30, minDistance: 15, lockPitch: true })
86
+ */
87
+ export function followCamera(opts = {}) { return rigModule('follow', opts); }
88
+ defineRig('follow', (e, opts) => {
89
+ const c = new FollowCamera(e, opts); if (opts.lockPitch) c.lockPitch = true; return c;
90
+ }, ['yaw', 'pitch', 'distance', 'minDistance', 'maxDistance', 'height', 'smoothing', 'sensitivity', 'minPitch', 'maxPitch',
91
+ 'zoomStep', 'groundClearance', 'invertY', 'lockPitch', 'shoulder', 'pointerLock', 'swallowLockClick', 'projection', 'size']);
@@ -0,0 +1,132 @@
1
+ // Strategy-game camera (top-down / oblique 45 degree isometric feel): the camera looks at a point on the ground (the focus), and the player moves that point.
2
+ // - Arrow keys / WASD pan (screen-relative), hold the mouse to drag-pan (grab the ground), mouse at the screen edge pans (edgePan)
3
+ // - Wheel zooms (changes camera height), Q/R rotate (actions rotateLeft / rotateRight, rebindable)
4
+ // - The focus always sticks to the ground (engine.surface); bounds limits the range
5
+ // - screenToGround(ndcX, ndcY) -> ground point under a screen point (for click-to-move and placing buildings)
6
+ // - After follow(object) the focus tracks it (done automatically when the player is created) and WASD goes to the character; manual drag/edge pan drops the follow (unless followLock: true)
7
+ // To not follow: call engine.cameraRig.follow(null) after creating the player, and WASD pans the camera
8
+ // Cutscene takeover: while someone holds engine.takeCamera (engine.cameraOverride is not null) the camera is left alone (see common.js).
9
+ //
10
+ // engine.use(rtsCamera({ height: 30, angle: 0.95, panSpeed: 1, edgePan: true, bounds: { minX: -100, maxX: 100, minZ: -100, maxZ: 100 } }));
11
+ // const p = engine.cameraRig.screenToGround(engine.input.pointer.ndcX, engine.input.pointer.ndcY);
12
+ // engine.cameraRig.moveTo(position); // move the view somewhere; { instant: true } skips smoothing
13
+ import * as THREE from 'three';
14
+ import { rigModule, defineRig, screenToGround, CAMERA_STRINGS, YAW_RIG } from './common.js';
15
+ import { xzOf } from '../../core/math.js';
16
+ import { surfaceOr } from '../../core/ground.js';
17
+
18
+ export class RtsCamera {
19
+ /**
20
+ * height camera height above the focus (zoom changes this); minHeight/maxHeight zoom range; angle pitch-down angle (radians, pi/2 = straight down);
21
+ * yaw initial horizontal facing; panSpeed pan speed multiplier (actual speed scales with height); dragPan drag-to-pan with the mouse;
22
+ * edgePan pan at screen edges; edgeSize edge width (fraction of the screen); bounds { minX, maxX, minZ, maxZ } focus range;
23
+ * rotateKeys rotation keys { left: ['KeyQ'], right: ['KeyR'] } (pick keys your game's other actions do not use), false disables rotation; rotateSpeed rotation speed (radians/second);
24
+ * zoomStep zoom ratio per wheel notch; smoothing smoothness; fov field of view (unchanged if omitted); followLock disallow manual pan while following; start initial focus (position)
25
+ */
26
+ constructor(engine, { height = 30, minHeight = 8, maxHeight = 90, angle = 0.95, yaw = 0, panSpeed = 1, dragPan = true, edgePan = false, edgeSize = 0.02,
27
+ bounds = null, rotateKeys = { left: ['KeyQ'], right: ['KeyR'] }, rotateSpeed = 1.8, zoomStep = 0.12, smoothing = 10, fov = null,
28
+ followLock = false, start = null } = {}) {
29
+ Object.assign(this, { engine, height, minHeight, maxHeight, angle, yaw, panSpeed, dragPan, edgePan, edgeSize, bounds, rotateSpeed, zoomStep, smoothing, followLock });
30
+ this.target = null;
31
+ this.following = false;
32
+ const [sx, sz] = start ? xzOf(start) : [0, 0];
33
+ this.focus = new THREE.Vector3(sx, 0, sz);
34
+ this.focus.y = surfaceOr(engine, this.focus.x, this.focus.z); // a start beyond the island keeps y = 0 instead of -Infinity
35
+ this._f = this.focus.clone(); // smoothed focus
36
+ this._h = height; this._yaw = yaw;
37
+ this._drag = null;
38
+ this._finePointer = matchMedia('(pointer: fine)'); // edge pan is for mice only: query once, read .matches per frame
39
+ this.rotate = !!rotateKeys;
40
+ if (rotateKeys) {
41
+ engine.input.define('rotateLeft', rotateKeys.left || ['KeyQ'], 'camera.rotateLeft');
42
+ engine.input.define('rotateRight', rotateKeys.right || ['KeyR'], 'camera.rotateRight');
43
+ }
44
+ this.fov = fov;
45
+ this._place();
46
+ }
47
+
48
+ /** Follow an object (called automatically when the player is created). While following, WASD moves the character; manual drag/edge pan drops the follow (not with followLock) */
49
+ /** Called when this camera is switched in (module install, setCamera): applies fov */
50
+ onEnter() { if (this.fov) { this.engine.camera.fov = this.fov; this.engine.camera.updateProjectionMatrix(); } }
51
+ follow(obj) { this.target = obj; this.following = !!obj; if (obj) this.moveTo(obj); }
52
+ /** Move the view somewhere; with instant true there is no smoothing */
53
+ moveTo(position, { instant = false } = {}) { const [x, z] = xzOf(position); this.focus.set(x, 0, z); this._clamp(); if (instant) { this._f.copy(this.focus); this._place(); } }
54
+ focusPoint() { return this._f; }
55
+ /** Screen coordinates (-1..1) -> point on the ground (THREE.Vector3); null if the ray misses the ground */
56
+ screenToGround(ndcX, ndcY) { return screenToGround(this.engine, ndcX, ndcY); }
57
+
58
+ update(dt, input) {
59
+ const on = input.enabled;
60
+ if (on) {
61
+ const speed = this.panSpeed * (6 + this._h * 0.9); // higher = faster pan
62
+ let px = 0, pz = 0;
63
+ // WASD: goes to the character while following; pans the camera otherwise
64
+ if (!this.following) { const a = input.axis; px += a.x; pz += a.y; }
65
+ // Edge pan (only while the mouse is inside the view)
66
+ if (this.edgePan && !this._drag && this._finePointer.matches) {
67
+ const e = this.edgeSize * 2, p = input.pointer;
68
+ if (p.ndcX < -1 + e) px -= 1; else if (p.ndcX > 1 - e) px += 1;
69
+ if (p.ndcY > 1 - e) pz += 1; else if (p.ndcY < -1 + e) pz -= 1;
70
+ }
71
+ if ((px || pz) && !(this.followLock && this.following)) {
72
+ const f = this.forward(), r = this.right();
73
+ this.focus.x += (f.x * pz + r.x * px) * speed * dt;
74
+ this.focus.z += (f.z * pz + r.z * px) * speed * dt;
75
+ this.following = false; // manual pan ends the follow
76
+ }
77
+ // Drag pan: remember the grabbed ground point on press, then keep it under the mouse
78
+ if (this.dragPan && input.pointer.down && (!this.followLock || !this.following)) {
79
+ const g = this.screenToGround(input.pointer.ndcX, input.pointer.ndcY);
80
+ if (!this._drag) this._drag = g ? { grab: g, moved: false } : { grab: null };
81
+ else if (g && this._drag.grab && (input.look.dx || input.look.dy || this._drag.moved)) {
82
+ const dx = this._drag.grab.x - g.x, dz = this._drag.grab.z - g.z;
83
+ if (Math.hypot(dx, dz) > 0.01) { this._drag.moved = true; this.following = false; }
84
+ this.focus.x += dx; this.focus.z += dz; this._f.x += dx; this._f.z += dz;
85
+ this._place();
86
+ }
87
+ } else this._drag = null;
88
+ // Zoom, rotate
89
+ if (input.look.zoom) this.height = Math.min(this.maxHeight, Math.max(this.minHeight, this.height * (1 + input.look.zoom * this.zoomStep)));
90
+ if (this.rotate) {
91
+ if (input.down('rotateLeft')) this.yaw += this.rotateSpeed * dt;
92
+ if (input.down('rotateRight')) this.yaw -= this.rotateSpeed * dt;
93
+ }
94
+ }
95
+ if (this.following && this.target) { this.focus.x = this.target.position.x; this.focus.z = this.target.position.z; }
96
+ this._clamp();
97
+ const k = 1 - Math.exp(-this.smoothing * dt);
98
+ this._f.x += (this.focus.x - this._f.x) * k; this._f.z += (this.focus.z - this._f.z) * k;
99
+ this._h += (this.height - this._h) * k;
100
+ this._yaw += (this.yaw - this._yaw) * k;
101
+ this._place();
102
+ }
103
+
104
+ _clamp() {
105
+ const b = this.bounds;
106
+ if (b) { this.focus.x = Math.min(b.maxX ?? Infinity, Math.max(b.minX ?? -Infinity, this.focus.x)); this.focus.z = Math.min(b.maxZ ?? Infinity, Math.max(b.minZ ?? -Infinity, this.focus.z)); }
107
+ }
108
+ _place() {
109
+ const cam = this.engine.camera, f = this._f;
110
+ const g = this.engine.surface(f.x, f.z);
111
+ if (g > -Infinity) f.y = g; // focus sticks to the ground; over the void of terrain({ shape }) it keeps its last height
112
+ const a = Math.min(Math.PI / 2 - 1e-3, Math.max(0.05, this.angle));
113
+ const back = this._h / Math.tan(a); // horizontal back-off distance
114
+ cam.position.set(f.x + Math.sin(this._yaw) * back, f.y + this._h, f.z + Math.cos(this._yaw) * back);
115
+ cam.lookAt(f);
116
+ }
117
+ }
118
+
119
+ // forward / right share YAW_RIG (focusPoint uses its own smoothed focus; the class definition above wins)
120
+ for (const k of ['forward', 'right']) RtsCamera.prototype[k] = YAW_RIG[k];
121
+
122
+ /**
123
+ * Strategy top-down camera module. Installs engine.cameraRig (pick it or followCamera).
124
+ * rtsCamera({ height: 30, angle: 0.95, panSpeed: 1, edgePan: true, bounds, rotateKeys: { left: ['KeyQ'], right: ['KeyR'] } })
125
+ * Actions: rotateLeft / rotateRight (default Q / R)
126
+ */
127
+ export function rtsCamera(opts = {}) { return rigModule('rts', opts); }
128
+ defineRig('rts', (e, opts) => {
129
+ e.i18n.add(CAMERA_STRINGS);
130
+ return new RtsCamera(e, opts);
131
+ }, ['height', 'minHeight', 'maxHeight', 'angle', 'yaw', 'panSpeed', 'dragPan', 'edgePan', 'edgeSize', 'bounds', 'rotateKeys',
132
+ 'rotateSpeed', 'zoomStep', 'smoothing', 'fov', 'followLock', 'start']);
@@ -0,0 +1,182 @@
1
+ // Shared parts of the camera modules: used by every camera (follow / first-person / fixed / strategy top-down).
2
+ //
3
+ // Camera interface (every camera module is named 'cameraRig', only one installed; swap at runtime with engine.setCamera('firstPerson' | 'follow' | 'rts' | 'fixed', options?),
4
+ // the swapped-out camera is kept, so its params survive switching back; engine.cameraRig.kind is the current kind):
5
+ // follow(object) who to follow (called automatically when the player is created)
6
+ // target the object being followed
7
+ // forward() / right() unit directions {x, z} on the XZ plane; player movement uses them
8
+ // update(dt, input) per-frame camera update
9
+ //
10
+ // Cutscene takeover contract: engine.takeCamera(owner, { focus? }) -> { remove() } (core/holds.js); engine.cameraOverride is the holder in charge.
11
+ // A cutscene, a named view or a photo mode that places the camera itself takes it; several can hold it, the latest is in charge.
12
+ // While anyone holds it the camera module leaves the camera alone; with a focus, engine.focus is set to it (the world loads around it).
13
+ // When the last holder removes its claim the camera module resumes from its previous state. cameraOverride itself is read-only.
14
+ import * as THREE from 'three';
15
+ import { ownedProps } from '../../core/validate.js';
16
+ import { readParams, keysSchema } from '../../core/params.js';
17
+ import { setProjection } from './projection.js';
18
+
19
+ const STRINGS = { ownedHint: 'To place the camera yourself, take it: const cam = engine.takeCamera(\'me\'); ... cam.remove() when done' };
20
+
21
+ /** True during a cutscene takeover, and updates engine.focus from the focus the owner supplied */
22
+ function applyOverride(e) {
23
+ const o = e.cameraOverride;
24
+ if (!o) return false;
25
+ if (o.focus) e.focus.copy(o.focus);
26
+ return true;
27
+ }
28
+
29
+ /** Flatten a 3D direction onto the XZ plane and normalize; use fallback when nearly vertical (top-down) */
30
+ function planar(dir, fallback = { x: 0, z: -1 }) {
31
+ const l = Math.hypot(dir.x, dir.z);
32
+ return l < 1e-4 ? { x: fallback.x, z: fallback.z } : { x: dir.x / l, z: dir.z / l };
33
+ }
34
+ /** Right direction from the forward direction (Y up) */
35
+ export const rightOf = f => ({ x: -f.z, z: f.x });
36
+
37
+ /**
38
+ * Shared methods for cameras that compute direction from horizontal yaw (follow, first-person, strategy): Object.assign(Class.prototype, YAW_RIG).
39
+ * forward() / right() are unit directions on the XZ plane; focusPoint() is the follow target's position (the camera position when there is none)
40
+ */
41
+ export const YAW_RIG = {
42
+ forward() { return { x: -Math.sin(this.yaw), z: -Math.cos(this.yaw) }; },
43
+ right() { return { x: Math.cos(this.yaw), z: -Math.sin(this.yaw) }; },
44
+ focusPoint() { return this.target ? this.target.position : this.engine.camera.position; },
45
+ };
46
+
47
+ /**
48
+ * Click-to-lock the mouse for a camera with a pointerLock flag (first person, over-the-shoulder follow); call from onEnter.
49
+ * Locked, mouse motion turns the view without dragging (input.look); Esc releases. Touch screens keep dragging.
50
+ * The press that locks is swallowed (not Mouse0, not a click) unless the rig sets swallowLockClick: false
51
+ */
52
+ export function clickToLock(rig, switched) {
53
+ const e = rig.engine, canvas = e.renderer.domElement;
54
+ const wouldLock = () => rig.pointerLock && !e.cameraOverride && e.input.enabled
55
+ && !matchMedia('(pointer: coarse)').matches && document.pointerLockElement !== canvas;
56
+ // Last outcome, shown by describe(): the drag fallback stays, but a refused lock is no longer silent
57
+ const st = rig.lockState = { configured: !!rig.pointerLock, requested: false, locked: document.pointerLockElement === canvas, lastError: null,
58
+ supported: typeof canvas.requestPointerLock === 'function' };
59
+ const fail = err => { st.locked = false; st.lastError = String(err?.message ?? err ?? 'refused'); st.failedAt = e.elapsed; };
60
+ const lock = () => {
61
+ st.configured = !!rig.pointerLock;
62
+ if (!wouldLock()) return;
63
+ st.requested = true;
64
+ try { const r = canvas.requestPointerLock?.(); r?.catch?.(fail); } catch (err) { fail(err); } // browser refused the lock: fall back to dragging
65
+ };
66
+ rig._off = new AbortController();
67
+ const sig = { signal: AbortSignal.any([e.signal, rig._off.signal]) };
68
+ document.addEventListener('pointerlockchange', () => { st.locked = document.pointerLockElement === canvas; if (st.locked) st.lastError = null; else st.requested = false; }, sig);
69
+ document.addEventListener('pointerlockerror', () => fail('pointerlockerror (browser refused: needs a user gesture, or the page lost focus)'), sig);
70
+ const swallow = () => rig.swallowLockClick !== false && wouldLock();
71
+ e.input.swallowLockClick = swallow; rig._swallow = swallow;
72
+ canvas.addEventListener('click', lock, sig); // removed on switch-away or engine.dispose()
73
+ if (switched) lock(); // a runtime switch (a key press counts as a gesture) locks at once
74
+ }
75
+ /**
76
+ * The pointer-lock state machine for describe(): off (not configured) / unsupported / locked / refused (browser denied) / requesting / waiting-click;
77
+ * plus covered (an element other than the canvas sits at its centre, so a click never reaches it), cameraOverride (a takeover blocks locking) and the last failure
78
+ * @internal
79
+ */
80
+ export function lockView(e, st) {
81
+ if (!st?.configured) return { state: 'off' };
82
+ const state = !st.configured ? 'off' : !st.supported ? 'unsupported' : st.locked ? 'locked' : st.lastError ? 'refused' : st.requested ? 'requesting' : 'waiting-click';
83
+ const c = e.renderer.domElement, r = c.getBoundingClientRect();
84
+ const top = typeof document.elementFromPoint === 'function' ? document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2) : null;
85
+ return { ...st, state, covered: top && top !== c ? (top.id ? '#' + top.id : top.className ? '.' + String(top.className).split(' ')[0] : top.tagName.toLowerCase()) : null,
86
+ cameraOverride: e.cameraOverride?.owner ?? null, lastFailure: st?.lastError ? { reason: st.lastError, agoSec: Math.round((e.elapsed - st.failedAt) / 100) / 10 } : null };
87
+ }
88
+ /** Release the mouse lock; stop listening for clicks too when switched away (call from onExit; from onOverride with keepListening) */
89
+ export function releaseLock(rig, keepListening = false) {
90
+ if (!keepListening) { rig._off?.abort(); if (rig.engine.input.swallowLockClick === rig._swallow) rig.engine.input.swallowLockClick = null; }
91
+ if (document.pointerLockElement === rig.engine.renderer.domElement) document.exitPointerLock?.();
92
+ }
93
+
94
+ /** The camera's own view direction on the XZ plane */
95
+ const _v = new THREE.Vector3();
96
+ export function viewForward(camera, fallback) {
97
+ camera.getWorldDirection(_v);
98
+ // When looking almost straight down, use the camera's "up" to stand for screen-up
99
+ if (Math.hypot(_v.x, _v.z) < 0.05) _v.set(0, 1, 0).applyQuaternion(camera.quaternion);
100
+ return planar(_v, fallback);
101
+ }
102
+
103
+ export { screenToGround } from '../../core/screenToGround.js'; // shared with grid placement and click-to-move; lives in core
104
+
105
+ /** Camera kind table: kind name -> build(engine, opts). Each camera file registers once with defineRig; setCamera switches by name */
106
+ const RIGS = new Map();
107
+ const RIG_PARAMS = new Map(); // kind -> params schema (the option keys of that camera)
108
+ /** keys: the options that camera takes; they become its params schema (engine.catalog) and a misspelled one throws in dev */
109
+ export function defineRig(kind, build, keys = []) { RIGS.set(kind, build); RIG_PARAMS.set(kind, keysSchema(keys)); }
110
+
111
+ /**
112
+ * Wrap a camera as a module: handles cutscene takeover, updates engine.focus, and provides runtime switching engine.setCamera(kind, options?).
113
+ * The camera needs update(dt, input) and focusPoint(); optional onEnter(switching) / onExit() (when switched in / out) and onOverride(on) (cutscene takeover start / end).
114
+ * kind: 'follow' | 'firstPerson' | 'fixed' | 'rts', reported in describe()
115
+ */
116
+ export function rigModule(kind, opts) {
117
+ let c = null, was = false, owned = null, fresh = true, engine = null, fov0 = 50;
118
+ const cache = new Map(); // kind -> camera instance: params like distance and pitch survive switching away and back
119
+ const make = (k, o) => {
120
+ const build = RIGS.get(k);
121
+ if (!build) throw new Error(`setCamera() has no camera kind '${k}'; available: ${[...RIGS.keys()].join(', ')}`);
122
+ readParams(`${k}Camera`, RIG_PARAMS.get(k), o); // also covers setCamera(kind, options)
123
+ const r = build(engine, o ?? {});
124
+ r.kind = k; cache.set(k, r);
125
+ return r;
126
+ };
127
+ function setCamera(k, o) {
128
+ if (k === c.kind && !o) return c;
129
+ const old = c, target = old.target;
130
+ old.onExit?.();
131
+ setProjection(engine.camera); // back to perspective; an orthographic rig sets its own in onEnter / constructor
132
+ engine.camera.fov = fov0; engine.camera.updateProjectionMatrix(); // fov returns to the value at install; each camera applies its own in onEnter / constructor
133
+ const next = o || !cache.has(k) ? make(k, o) : cache.get(k);
134
+ c = engine.cameraRig = next;
135
+ next.onEnter?.(true);
136
+ if (old.yaw !== undefined && next.yaw !== undefined && !(o && o.yaw != null)) next.yaw = old.yaw; // keep turning from the same heading, no sudden spin
137
+ next.follow(target ?? null);
138
+ fresh = true; // the camera position was changed here, not counted as "the game moved the camera"
139
+ engine.events.emit('camera:change', { kind: k, previous: old.kind }); // player settings (sensitivity, fov) live on the rig: the settings menu re-applies them
140
+ return c;
141
+ }
142
+ return {
143
+ name: 'cameraRig', label: 'Camera', params: RIG_PARAMS.get(kind), options: opts, optional: ['collision'], stage: 'control',
144
+ install(e) {
145
+ engine = e; fov0 = e.camera.fov;
146
+ e.setCamera = setCamera;
147
+ c = make(kind, opts);
148
+ c.onEnter?.(false);
149
+ // a new playthrough (newGame / load) starts with the camera as installed (kind, yaw, pitch, distance), placed at the player instead of flying across the map
150
+ e.events.on('session:start', () => {
151
+ const old = c;
152
+ old.onExit?.(); cache.clear();
153
+ setProjection(e.camera);
154
+ e.camera.fov = fov0; e.camera.updateProjectionMatrix();
155
+ c = e.cameraRig = make(kind, opts);
156
+ c.onEnter?.(false); c.follow(e.player?.cameraFollow ? e.player.root : null); fresh = true; // follows the player only if the game asked (createPlayer({ cameraFollow }))
157
+ e.events.emit('camera:change', { kind, previous: old.kind }); // settings re-apply the player's sensitivity / fov to the new rig
158
+ });
159
+ // The camera module places position/orientation every frame: warn once (in dev) if the game changed them between frames
160
+ const cam = e.camera, p = cam.position, q = cam.quaternion;
161
+ owned = ownedProps('camera.position / camera.quaternion', () => [p.x, p.y, p.z, q.x, q.y, q.z, q.w], STRINGS.ownedHint);
162
+ return c;
163
+ },
164
+ frame(dt, e) {
165
+ const over = !!e.cameraOverride;
166
+ if (over !== was) { was = over; c.onOverride?.(over); }
167
+ if (applyOverride(e)) { fresh = true; return; } // not checked during takeover; re-record afterwards
168
+ if (!fresh) owned.check();
169
+ c.update(dt, e.input);
170
+ e.focus.copy(c.focusPoint()); // decides only where the view (terrain, models) loads; the gameplay simulation center is world.anchor (default the player), so moving the camera away changes nothing
171
+ owned.mark(); fresh = false;
172
+ },
173
+ describe(e, ctx) { ctx.out.camera.type = c.kind; if (c.current !== undefined) ctx.out.camera.shot = c.current;
174
+ ctx.out.camera.pointerLock = lockView(e, c.lockState); },
175
+ };
176
+ }
177
+
178
+ /** Shared camera module text */
179
+ export const CAMERA_STRINGS = {
180
+ 'zh-CN': { 'camera.rotateLeft': '视角左转', 'camera.rotateRight': '视角右转' },
181
+ en: { 'camera.rotateLeft': 'Rotate view left', 'camera.rotateRight': 'Rotate view right' },
182
+ };
@@ -0,0 +1,11 @@
1
+ // Camera module collection. All four cameras install as engine.cameraRig, only one at a time:
2
+ // followCamera() third-person follow (default)
3
+ // firstPersonCamera() first person
4
+ // fixedCamera() fixed shots (camera cuts)
5
+ // rtsCamera() strategy top-down (pan, zoom, rotate, screen point -> ground)
6
+ // Cutscene takeover contract engine.takeCamera / cameraOverride: see common.js.
7
+ export { followCamera, FollowCamera } from './FollowCamera.js';
8
+ export { firstPersonCamera, FirstPersonCamera } from './FirstPersonCamera.js';
9
+ export { fixedCamera, FixedCamera } from './FixedCamera.js';
10
+ export { rtsCamera, RtsCamera } from './RtsCamera.js';
11
+ export { screenToGround } from './common.js';
@@ -0,0 +1,34 @@
1
+ // Orthographic projection for engine.camera, without replacing the camera object.
2
+ //
3
+ // engine.camera is one PerspectiveCamera that the render pass, post chain, cascaded shadows, sky and every module hold a reference to.
4
+ // Swapping in a THREE.OrthographicCamera would leave those pointing at the old camera, so the rig flips this same instance instead:
5
+ // updateProjectionMatrix() builds an orthographic matrix while camera.orthoSize is set (isPerspectiveCamera / isOrthographicCamera and
6
+ // left/right/top/bottom follow, so code that branches on the camera type keeps working), and the original perspective one otherwise.
7
+ // Resize needs nothing extra: canvasBox sets camera.aspect and calls updateProjectionMatrix().
8
+
9
+ /**
10
+ * Switch engine.camera between perspective and orthographic.
11
+ * @param {import('three').PerspectiveCamera} cam engine.camera
12
+ * @param {'perspective' | 'orthographic'} projection
13
+ * @param {number} [size] orthographic only: world units covered by the view height (before camera.zoom)
14
+ */
15
+ export function setProjection(cam, projection = 'perspective', size = 20) {
16
+ if (projection !== 'perspective' && projection !== 'orthographic') throw new Error(`projection must be 'perspective' or 'orthographic', got '${projection}'`);
17
+ if (projection === 'orthographic' && !(size > 0)) throw new Error(`orthographic projection needs size > 0 (world units of view height), got ${size}`);
18
+ if (!cam._perspectiveUpdate) {
19
+ const original = cam.updateProjectionMatrix;
20
+ cam._perspectiveUpdate = original;
21
+ cam.updateProjectionMatrix = function () {
22
+ if (!this.orthoSize) return original.call(this);
23
+ const top = this.orthoSize / 2 / this.zoom, right = top * this.aspect;
24
+ this.left = -right; this.right = right; this.top = top; this.bottom = -top;
25
+ this.projectionMatrix.makeOrthographic(-right, right, top, -top, this.near, this.far, this.coordinateSystem);
26
+ this.projectionMatrixInverse.copy(this.projectionMatrix).invert();
27
+ };
28
+ }
29
+ const ortho = projection === 'orthographic';
30
+ if (ortho ? cam.orthoSize === size : !cam.orthoSize) return;
31
+ cam.orthoSize = ortho ? size : 0;
32
+ cam.isOrthographicCamera = ortho; cam.isPerspectiveCamera = !ortho;
33
+ cam.updateProjectionMatrix();
34
+ }