threedog 1.1.0 → 1.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 (363) hide show
  1. package/CHANGELOG.md +879 -798
  2. package/README.md +1 -1
  3. package/core/assets/Animator.js +41 -3
  4. package/core/assets/Assets.js +100 -24
  5. package/core/assets/assetEntry.js +73 -20
  6. package/core/assets/assetHot.js +68 -16
  7. package/core/assets/assetLoad.js +6 -6
  8. package/core/assets/assetLod.js +9 -2
  9. package/core/assets/assetManifest.js +12 -2
  10. package/core/assets/assetPart.js +54 -0
  11. package/core/assets/ik.js +271 -0
  12. package/core/assets/modelNeeds.js +37 -0
  13. package/core/assets/namedModel.js +102 -29
  14. package/core/assets/nodeVisibility.js +15 -0
  15. package/core/audio/Audio.js +36 -4
  16. package/core/audio/audioReverb.js +99 -0
  17. package/core/audio/audioRules.js +1 -1
  18. package/core/audio/audioVoice.js +1 -1
  19. package/core/base/Events.js +14 -4
  20. package/core/base/Random.js +1 -1
  21. package/core/base/Vars.js +1 -1
  22. package/core/base/docRef.js +51 -0
  23. package/core/base/errorCodes.js +178 -126
  24. package/core/base/errorHints.js +9 -7
  25. package/core/base/errors.js +25 -10
  26. package/core/base/events.generated.js +2 -0
  27. package/core/base/freeParts.js +76 -0
  28. package/core/base/math.js +28 -0
  29. package/core/base/sections.js +5 -5
  30. package/core/base/validate.js +31 -3
  31. package/core/engine/Engine.js +16 -6
  32. package/core/engine/Loading.js +5 -3
  33. package/core/engine/copies.js +1 -1
  34. package/core/engine/headlessLoad.js +4 -1
  35. package/core/engine/lifecycle.js +32 -16
  36. package/core/engine/loop.js +71 -27
  37. package/core/engine/moduleSlots.js +2 -2
  38. package/core/engine/moduleTypes.js +3 -3
  39. package/core/engine/modules.js +65 -39
  40. package/core/engine/page.js +6 -3
  41. package/core/engine/services.js +6 -5
  42. package/core/engine/startup.js +5 -5
  43. package/core/input/Input.js +28 -14
  44. package/core/input/inputContext.js +28 -16
  45. package/core/input/inputKeyboard.js +31 -3
  46. package/core/input/inputPad.js +4 -0
  47. package/core/input/inputPointer.js +2 -1
  48. package/core/input/inputSeat.js +1 -1
  49. package/core/inspect/Budget.js +109 -19
  50. package/core/inspect/DebugOverrides.js +28 -4
  51. package/core/inspect/Describe.js +17 -9
  52. package/core/inspect/Inspect.js +4 -2
  53. package/core/inspect/InspectMaterials.js +3 -1
  54. package/core/inspect/InspectPerf.js +19 -9
  55. package/core/inspect/InspectScene.js +32 -7
  56. package/core/inspect/MaterialInfo.js +19 -2
  57. package/core/inspect/UrlState.js +46 -27
  58. package/core/inspect/catalog.js +28 -9
  59. package/core/inspect/debugView.js +2 -1
  60. package/core/inspect/describeRender.js +25 -13
  61. package/core/inspect/describeText.js +14 -6
  62. package/core/inspect/lightWatch.js +1 -1
  63. package/core/inspect/metadata.generated.js +35 -17
  64. package/core/inspect/pictureChecks.js +148 -0
  65. package/core/inspect/pictureMenu.js +84 -0
  66. package/core/inspect/pictureWriters.js +26 -6
  67. package/core/inspect/textureBytes.js +12 -2
  68. package/core/inspect/toolDoor.js +2 -4
  69. package/core/ops/Ops.js +11 -4
  70. package/core/ops/holds.js +27 -10
  71. package/core/ops/opsAtomic.js +15 -7
  72. package/core/ops/opsGuard.js +2 -2
  73. package/core/ops/opsRun.js +8 -7
  74. package/core/ops/sharedPoint.js +72 -21
  75. package/core/ops/stacks.js +56 -16
  76. package/core/saves/SaveStore.js +9 -3
  77. package/core/saves/Saves.js +32 -23
  78. package/core/saves/saveApply.js +96 -44
  79. package/core/saves/saveIds.js +1 -1
  80. package/core/saves/saveVersions.js +7 -5
  81. package/core/saves/session.js +17 -8
  82. package/core/saves/stateReplace.js +34 -15
  83. package/core/scene/Rays.js +52 -10
  84. package/core/scene/Views.js +13 -7
  85. package/core/scene/adaptive.js +144 -21
  86. package/core/scene/drawOnly.js +17 -0
  87. package/core/scene/gameLights.js +44 -3
  88. package/core/scene/sceneMethods.js +13 -11
  89. package/core/scene/stepPoses.js +11 -3
  90. package/core/scene/targeting.js +5 -3
  91. package/core/scene/thingOps.js +1 -1
  92. package/core/scene/tier.js +15 -0
  93. package/core/stream/Batching.js +30 -7
  94. package/core/stream/Stream.js +26 -7
  95. package/core/stream/batchGroups.js +2 -2
  96. package/core/stream/chunkStream.js +7 -5
  97. package/core/stream/prepare.js +77 -0
  98. package/core/time/skip.js +3 -1
  99. package/core/time/time.js +4 -2
  100. package/docs/AI.md +82 -83
  101. package/docs/API.md +16 -16
  102. package/docs/CODEMAP.md +16 -11
  103. package/docs/COMMANDS.md +139 -142
  104. package/docs/CONVENTIONS.md +37 -49
  105. package/docs/MIGRATING-0.8.md +2 -2
  106. package/docs/MIGRATING-1.0.md +2 -2
  107. package/docs/THREE.md +28 -35
  108. package/docs/api/assets.md +3 -1
  109. package/docs/api/audio.md +4 -2
  110. package/docs/api/budget.md +5 -0
  111. package/docs/api/characters.md +10 -8
  112. package/docs/api/collision.md +6 -4
  113. package/docs/api/engine.md +16 -16
  114. package/docs/api/events.md +3 -2
  115. package/docs/api/ground.md +6 -5
  116. package/docs/api/hud.md +4 -2
  117. package/docs/api/input.md +5 -5
  118. package/docs/api/particles.md +2 -1
  119. package/docs/api/photo.md +3 -0
  120. package/docs/api/post.md +7 -4
  121. package/docs/api/quests.md +2 -2
  122. package/docs/api/rays.md +1 -2
  123. package/docs/api/saves.md +7 -7
  124. package/docs/api/settings.md +2 -2
  125. package/docs/api/tools.md +3 -1
  126. package/docs/api/vars.md +1 -1
  127. package/docs/api/vegetation.md +4 -2
  128. package/docs/api/world.md +1 -1
  129. package/docs/recipes/01-new-game.md +16 -17
  130. package/docs/recipes/02-npc.md +22 -18
  131. package/docs/recipes/03-items-pickups.md +37 -35
  132. package/docs/recipes/04-quests.md +15 -10
  133. package/docs/recipes/05-props-bake.md +101 -95
  134. package/docs/recipes/06-clock-events.md +28 -28
  135. package/docs/recipes/07-flow-scenes-pause.md +29 -26
  136. package/docs/recipes/08-weather-sky.md +52 -64
  137. package/docs/recipes/09-materials-lights-models.md +26 -17
  138. package/docs/recipes/10-blender-level.md +15 -10
  139. package/docs/recipes/11-vehicles.md +12 -7
  140. package/docs/recipes/12-navmesh.md +44 -26
  141. package/docs/recipes/13-animation.md +56 -45
  142. package/docs/recipes/14-custom-module.md +21 -18
  143. package/docs/recipes/15-perf.md +61 -55
  144. package/docs/recipes/16-dev-bridge.md +23 -33
  145. package/docs/recipes/18-world.md +36 -42
  146. package/docs/recipes/19-shooting-picking.md +20 -15
  147. package/docs/recipes/20-content-actions-save.md +48 -56
  148. package/docs/recipes/21-camera.md +45 -54
  149. package/docs/recipes/22-shop-gold.md +12 -7
  150. package/docs/recipes/23-ops.md +25 -23
  151. package/docs/recipes/26-ui-parts.md +67 -47
  152. package/docs/recipes/27-net.md +12 -7
  153. package/docs/recipes/28-terrain.md +24 -21
  154. package/docs/recipes/29-grid.md +32 -27
  155. package/docs/recipes/30-templates.md +21 -20
  156. package/docs/recipes/31-audio.md +39 -22
  157. package/docs/recipes/32-action-game.md +19 -14
  158. package/docs/recipes/33-stream-sources.md +15 -11
  159. package/docs/recipes/34-environment-lighting.md +126 -70
  160. package/docs/recipes/35-picture-from-reference.md +8 -8
  161. package/docs/recipes/36-ground-plants.md +27 -21
  162. package/docs/recipes/40-scene.md +19 -28
  163. package/docs/recipes/43-shader-patches-surfaces.md +15 -12
  164. package/docs/recipes/44-water-weather-hooks.md +34 -31
  165. package/docs/recipes/45-cascaded-shadows.md +35 -26
  166. package/docs/recipes/46-blender-art-route.md +6 -1
  167. package/docs/recipes/49-game-module-contract.md +13 -8
  168. package/docs/recipes/50-own-renderer.md +6 -2
  169. package/docs/recipes/51-capability-catalog.md +15 -8
  170. package/docs/recipes/52-around-the-picture.md +34 -32
  171. package/docs/recipes/53-ground-up-close.md +6 -1
  172. package/docs/recipes/55-mods-time-wrap.md +27 -19
  173. package/docs/recipes/56-webgpu-tsl.md +74 -43
  174. package/docs/recipes/57-control.md +18 -13
  175. package/docs/recipes/58-input.md +26 -16
  176. package/docs/recipes/59-depth-post-effects.md +8 -3
  177. package/docs/recipes/60-judge-the-picture.md +9 -8
  178. package/docs/recipes/61-deploy.md +5 -0
  179. package/docs/recipes/62-picture-code.md +70 -79
  180. package/docs/recipes/63-third-person-start.md +47 -45
  181. package/docs/recipes/64-particles.md +22 -10
  182. package/docs/recipes/65-swarm.md +18 -13
  183. package/docs/recipes/66-common-tasks.md +38 -35
  184. package/examples/action/GAMEMAP.md +2 -3
  185. package/examples/action/main.js +3 -3
  186. package/examples/action/picture/lights.js +3 -1
  187. package/examples/perf-island/GAMEMAP.md +3 -3
  188. package/examples/perf-island/picture/lights.js +2 -1
  189. package/examples/plain-picture/GAMEMAP.md +1 -1
  190. package/examples/rc2d/GAMEMAP.md +1 -1
  191. package/examples/styletest/GAMEMAP.md +2 -2
  192. package/examples/styletest/main.js +1 -1
  193. package/examples/techniques/interior-light/README.md +3 -3
  194. package/examples/techniques/interior-light/interiorLight.js +2 -4
  195. package/examples/techniques/interior-light/picture/lights.js +2 -1
  196. package/examples/techniques/modular-building/picture/lights.js +3 -1
  197. package/examples/techniques/outlines-and-rim/picture/lights.js +3 -1
  198. package/examples/techniques/procedural-animation/README.md +1 -1
  199. package/examples/techniques/procedural-animation/main.js +1 -1
  200. package/examples/webgpu-tsl/GAMEMAP.md +1 -1
  201. package/examples/world/GAMEMAP.md +2 -3
  202. package/examples/world/art/humanoid.js +1 -1
  203. package/examples/world/main.js +6 -3
  204. package/index.d.ts +2 -2
  205. package/llms.txt +101 -0
  206. package/modules/ambience/Ambience.js +21 -5
  207. package/modules/calendar/index.js +9 -5
  208. package/modules/calendar/schedule.js +23 -8
  209. package/modules/camera/FirstPersonCamera.js +3 -1
  210. package/modules/camera/FollowCamera.js +10 -5
  211. package/modules/camera/RtsCamera.js +4 -3
  212. package/modules/camera/common.js +70 -8
  213. package/modules/camera/contract.js +1 -1
  214. package/modules/characters/Character.js +16 -10
  215. package/modules/characters/NPC.js +31 -19
  216. package/modules/characters/assetModel.js +14 -9
  217. package/modules/characters/astar.js +6 -1
  218. package/modules/characters/contract.js +2 -2
  219. package/modules/characters/index.js +34 -22
  220. package/modules/characters/movers/manual.js +1 -1
  221. package/modules/characters/movers/rapier.js +17 -2
  222. package/modules/characters/movers/simple.js +1 -1
  223. package/modules/characters/movers/support.js +16 -7
  224. package/modules/characters/npcAvoid.js +2 -2
  225. package/modules/characters/npcSim.js +3 -2
  226. package/modules/characters/pathAsync.js +24 -8
  227. package/modules/characters/pathJob.js +1 -1
  228. package/modules/characters/player.js +10 -9
  229. package/modules/characters/playerStrings.js +5 -5
  230. package/modules/characters/proceduralRig.js +5 -5
  231. package/modules/characters/useModel.js +6 -0
  232. package/modules/characters/walkTo.js +1 -1
  233. package/modules/collision/Collision.js +29 -18
  234. package/modules/collision/grid.js +22 -4
  235. package/modules/content/index.js +3 -1
  236. package/modules/content/loader.js +1 -1
  237. package/modules/content/models.js +82 -33
  238. package/modules/content/props.js +2 -1
  239. package/modules/content/rules.js +11 -5
  240. package/modules/content/templates.js +3 -3
  241. package/modules/content/words.js +2 -2
  242. package/modules/debug/DebugPanel.js +9 -9
  243. package/modules/flow/index.js +9 -6
  244. package/modules/gameplay/Dialogue.js +34 -20
  245. package/modules/gameplay/Interactions.js +19 -15
  246. package/modules/gameplay/Inventory.js +9 -4
  247. package/modules/gameplay/Quests.js +12 -10
  248. package/modules/gameplay/pickups.js +23 -11
  249. package/modules/grid/index.js +1 -1
  250. package/modules/grid/preview.js +2 -2
  251. package/modules/grid/tiles.js +1 -1
  252. package/modules/hlod/index.js +4 -1
  253. package/modules/hud/index.js +47 -10
  254. package/modules/hud/parts.js +28 -9
  255. package/modules/level/geometry.js +8 -3
  256. package/modules/level/index.js +10 -5
  257. package/modules/level/load.js +4 -2
  258. package/modules/lights/sources.js +1 -1
  259. package/modules/music/Music.js +22 -4
  260. package/modules/nav/index.js +20 -10
  261. package/modules/particles/Particles.js +31 -14
  262. package/modules/particles/effect.js +20 -5
  263. package/modules/particles/lit.js +72 -0
  264. package/modules/photo/Photo.js +72 -28
  265. package/modules/photo/pathTrace.js +106 -0
  266. package/modules/rigid/RigidBodies.js +23 -14
  267. package/modules/rigid/Vehicles.js +3 -13
  268. package/modules/rigid/sync.js +2 -1
  269. package/modules/settings/Settings.js +52 -20
  270. package/modules/settings/apply.js +23 -9
  271. package/modules/settings/sections.js +39 -6
  272. package/modules/settings/strings.js +2 -0
  273. package/modules/settings/view.js +19 -3
  274. package/modules/sky/dome.js +15 -3
  275. package/modules/sky/environment.js +28 -12
  276. package/modules/sky/fog.js +1 -1
  277. package/modules/sky/frame.js +6 -1
  278. package/modules/sky/shader.js +4 -3
  279. package/modules/sky/skyModule.js +8 -4
  280. package/modules/swarm/Swarm.js +1 -1
  281. package/modules/terrain/ChunkManager.js +61 -15
  282. package/modules/terrain/chunkJob.js +2 -2
  283. package/modules/terrain/index.js +20 -5
  284. package/modules/terrain/terrainEdit.js +8 -4
  285. package/modules/terrain/terrainTexture.js +4 -2
  286. package/modules/timeline/Timeline.js +4 -3
  287. package/modules/timeline/Tween.js +3 -0
  288. package/modules/timeline/letterbox.js +1 -0
  289. package/modules/triggers/index.js +36 -17
  290. package/modules/vegetation/Vegetation.js +81 -19
  291. package/modules/vegetation/densityMap.js +13 -8
  292. package/modules/vegetation/draw.js +147 -24
  293. package/modules/vegetation/groundChunks.js +20 -5
  294. package/modules/vegetation/index.js +3 -3
  295. package/modules/vegetation/modelGeometry.js +9 -4
  296. package/modules/water/Water.js +11 -8
  297. package/modules/weather/Weather.js +7 -2
  298. package/modules/weather/shaders.js +25 -5
  299. package/modules/weather/weatherDraw.js +20 -6
  300. package/modules/world/World.js +2 -1
  301. package/modules/world/index.js +2 -2
  302. package/modules/world/persist.js +6 -2
  303. package/modules/world/views.js +15 -2
  304. package/package.json +4 -1
  305. package/presets.js +5 -5
  306. package/render/PostFX.js +84 -41
  307. package/render/backend.js +137 -16
  308. package/render/cascades.js +3 -1
  309. package/render/cascades.tsl.js +2 -0
  310. package/render/daylight.js +7 -1
  311. package/render/detail.js +7 -4
  312. package/render/effects.js +27 -8
  313. package/render/fogLook.js +24 -0
  314. package/render/fuse.js +5 -2
  315. package/render/fx/detail.tsl.js +9 -7
  316. package/render/fx/index.js +7 -2
  317. package/render/fx/library.tsl.js +1 -0
  318. package/render/fx/lightShaft.tsl.js +114 -0
  319. package/render/fx/noise.tsl.js +25 -8
  320. package/render/fx/objectOrigin.tsl.js +39 -10
  321. package/render/fx/particles.tsl.js +23 -6
  322. package/render/fx/patchNodes.tsl.js +17 -12
  323. package/render/fx/pcss.tsl.js +51 -0
  324. package/render/fx/postWebGPU.tsl.js +89 -29
  325. package/render/fx/sky.tsl.js +3 -9
  326. package/render/fxNumbers.js +10 -4
  327. package/render/impostor.tsl.js +107 -0
  328. package/render/lighting.js +33 -1
  329. package/render/lightmap.js +42 -28
  330. package/render/lights.js +19 -3
  331. package/render/materials.js +6 -4
  332. package/render/mergeCommon.js +4 -1
  333. package/render/occlusion.js +14 -4
  334. package/render/patches.js +79 -41
  335. package/render/postRuns.js +32 -0
  336. package/render/postWebGL.js +97 -10
  337. package/render/probes.js +10 -14
  338. package/render/shaderErrors.js +2 -1
  339. package/render/shadowCache.tsl.js +33 -5
  340. package/render/shadows.js +42 -16
  341. package/render/slots.js +8 -5
  342. package/render/vertexInputs.js +52 -0
  343. package/types/core.d.ts +114 -46
  344. package/types/gameplay.d.ts +56 -23
  345. package/types/generated/core/audio/Audio.d.ts +27 -1
  346. package/types/generated/core/base/Random.d.ts +1 -1
  347. package/types/generated/core/input/Input.d.ts +6 -8
  348. package/types/generated/core/input/inputSeat.d.ts +1 -1
  349. package/types/generated/core/inspect/Budget.d.ts +26 -0
  350. package/types/generated/core/inspect/DebugOverrides.d.ts +0 -2
  351. package/types/generated/core/saves/Saves.d.ts +10 -7
  352. package/types/generated/core/saves/session.d.ts +8 -2
  353. package/types/generated/core/scene/Rays.d.ts +1 -3
  354. package/types/generated/modules/particles/Particles.d.ts +1 -1
  355. package/types/generated/modules/world/World.d.ts +2 -1
  356. package/types/generated/render/PostFX.d.ts +35 -9
  357. package/types/physics.d.ts +796 -764
  358. package/types/pixel.d.ts +1 -1
  359. package/types/tsl.d.ts +62 -1
  360. package/types/world.d.ts +12 -3
  361. package/ui/Focus.js +7 -5
  362. package/ui/Parts.js +1 -1
  363. package/ui/touchPart.js +6 -3
@@ -1,6 +1,7 @@
1
- import { mergeCommon } from '../../render/mergeCommon.js';
2
- import { copyPatches } from '../../render/patches.js';
3
- import { codedError } from '../../core/base/errorHints.js';
1
+ import { mergeCommon, commonAttributes } from '../../render/mergeCommon.js';
2
+ import { cloneMaterial } from '../../render/patches.js';
3
+ import { coded, codedError } from '../../core/base/errorHints.js';
4
+ import { DEV, warnOnce } from '../../core/base/validate.js';
4
5
 
5
6
  // Multi-material model (bark trunk + alpha-cut leaf cards) -> one geometry with a group per mesh + a material array, so a species stays
6
7
  // one InstancedMesh: instance matrices, felling and LOD swaps work unchanged for every part. Only attributes all meshes share are kept.
@@ -12,8 +13,12 @@ export function fromModel(root, label) {
12
13
  if (!n.isMesh) return;
13
14
  if (Array.isArray(n.material)) throw codedError('vegetation-option', `${label}: model mesh '${n.name}' has several materials; split it into one mesh per material`);
14
15
  geos.push(n.geometry.clone().applyMatrix4(n.matrixWorld.clone().premultiply(inv)));
15
- mats.push(copyPatches(n.material, n.material.clone())); // the clone keeps the model material's own shader patches
16
+ mats.push(cloneMaterial(n.material)); // the copy keeps what the game gave the material: its own lighting / nodes and its shader patches
16
17
  });
17
18
  if (!geos.length) throw codedError('vegetation-option', `${label}: model has no meshes`);
19
+ // an attribute only some meshes have (uv on the leaf cards, colors on the trunk) is dropped from all: a material reading it would draw
20
+ // differently from the model shown on its own, so say which one went
21
+ const kept = commonAttributes(geos), lost = [...new Set(geos.flatMap(g => Object.keys(g.attributes)))].filter(n => !kept.includes(n));
22
+ if (DEV && lost.length) warnOnce(coded('vegetation-ignored', `${label}: attribute ${lost.join(', ')} is on only some meshes of the model, so the species draws without it (one instanced geometry keeps what every mesh has). Give every mesh the attribute, or split the model into species`));
18
23
  return { geometry: mergeCommon(geos, true), materials: mats };
19
24
  }
@@ -20,6 +20,7 @@ import { readParams, keysSchema } from '../../core/base/params.js';
20
20
  import { waterShader, wavesPatch, surfacePatch } from './surface.js';
21
21
  import { codedError } from '../../core/base/errorHints.js';
22
22
  import { glslFloat, FRESNEL_POWER } from '../../render/fxNumbers.js';
23
+ import { fogLook } from '../../render/fogLook.js';
23
24
  import { needMaterial } from '../../core/base/validate.js';
24
25
 
25
26
  const GREY = new THREE.Color(0xcccccc);
@@ -28,7 +29,8 @@ const GREY = new THREE.Color(0xcccccc);
28
29
  /** @import { WaterBody, WaterOptions, WaterShaderOptions } from '../../types/world' */
29
30
  // Options accepted by water(): the structural choices only
30
31
  const WATER_OPTIONS = ['sea', 'level', 'flat', 'size', 'segments'];
31
- const WATER_PARAMS = keysSchema(WATER_OPTIONS);
32
+ // size / segments divide each other (cell) and the sea snap: zero or non-finite would make NaN coordinates (size is meters, so a sub-meter plane is valid: > 0)
33
+ const WATER_PARAMS = keysSchema(WATER_OPTIONS, {}, { size: { type: 'number', min: Number.MIN_VALUE, optional: true }, segments: { type: 'int', min: 1, optional: true } });
32
34
  const SHADER_PARAMS = keysSchema(['wave', 'surface', 'depthColor', 'foam', 'uniforms']);
33
35
  const NORMAL_PARAMS = { scale: { type: 'number', min: 0, optional: true, desc: 'normal map strength' }, repeat: { type: 'number', min: 0, optional: true, desc: 'tiles per meter' },
34
36
  speed: { type: 'position', optional: true, desc: 'scroll [x, z] per second' } };
@@ -163,9 +165,10 @@ export class Water {
163
165
  /** Scale a mesh's UVs to size * repeat (the normal map tiles in meters); a no-op without a normal map or when already at that factor @internal */
164
166
  _tile(mesh) {
165
167
  const u = this._uv.get(mesh); if (!this.normalTexture || !u) return;
166
- const f = u.size * this._normal.repeat, k = f / u.f; if (k === 1) return;
167
- const uv = mesh.geometry.attributes.uv; for (let i = 0; i < uv.count; i++) uv.setXY(i, uv.getX(i) * k, uv.getY(i) * k);
168
- uv.needsUpdate = true; u.f = f;
168
+ const f = u.sx * this._normal.repeat, g = u.sz * this._normal.repeat; if (f === u.f && g === u.g) return;
169
+ // always from the UVs the mesh was made with: scaling the current ones by f / u.f would divide by zero after repeat 0 and lose them for good
170
+ const uv = mesh.geometry.attributes.uv; for (let i = 0; i < uv.count; i++) uv.setXY(i, u.base[i * 2] * f, u.base[i * 2 + 1] * g);
171
+ uv.needsUpdate = true; u.f = f; u.g = g;
169
172
  }
170
173
  /** The patches and uniforms for what shader() was given @internal */
171
174
  _build(given) {
@@ -184,11 +187,11 @@ export class Water {
184
187
  return { patches: surface ? [waves, surface, fresnel] : [waves, fresnel], uniforms: { ...waves.uniforms, ...surface?.uniforms, uFresnel } };
185
188
  }
186
189
  /** What grazing angles reflect: the fog color; with no fog the sky's horizon, because a fixed gray glows on dark water at night; with no sky a neutral gray @internal */
187
- _reflects() { const e = this.engine; return e.scene.fog?.color ?? (e.sky ? e.uniforms.uSkyHorizon.value : GREY); }
190
+ _reflects() { const e = this.engine; return fogLook(e.scene, e.renderer)?.color ?? (e.sky ? e.uniforms.uSkyHorizon.value : GREY); }
188
191
  /** @internal */
189
- _prep(mesh, size) {
192
+ _prep(mesh, sx, sz = sx) {
190
193
  mesh.receiveShadow = true; mesh.renderOrder = 1;
191
- this._uv.set(mesh, { size, f: 1 }); this._tile(mesh);
194
+ this._uv.set(mesh, { sx, sz, f: 1, g: 1, base: Float32Array.from(mesh.geometry.attributes.uv.array) }); this._tile(mesh);
192
195
  }
193
196
  /** @internal */
194
197
  _addBody(b) {
@@ -197,7 +200,7 @@ export class Water {
197
200
  const geo = b.radius ? new THREE.CircleGeometry(b.radius, Math.max(16, seg * 2)).rotateX(-Math.PI / 2) : new THREE.PlaneGeometry(b.hw * 2, b.hd * 2, seg, seg).rotateX(-Math.PI / 2);
198
201
  const m = new THREE.Mesh(geo, this._material);
199
202
  m.position.set(b.x, b.level - 0.1, b.z);
200
- this._prep(m, b.radius ? b.radius * 2 : Math.max(b.hw, b.hd) * 2);
203
+ this._prep(m, b.radius ? b.radius * 2 : b.hw * 2, b.radius ? b.radius * 2 : b.hd * 2); // a rectangle tiles per meter on each axis
201
204
  this.engine.add(m, { owner: 'engine:water' });
202
205
  this.bodies.set(b, m);
203
206
  }
@@ -17,6 +17,7 @@ import { readParams, keysSchema } from '../../core/base/params.js';
17
17
  import { STRINGS, ERR } from './strings.js';
18
18
  import { codedError } from '../../core/base/errorHints.js';
19
19
  import { STEP } from '../../core/time/time.js';
20
+ import { resetSignals } from '../../render/effects.js';
20
21
  import { weatherDrawModule } from './weatherDraw.js';
21
22
  import { isPlainObject } from '../../core/base/util.js';
22
23
  import { saveNumberOk, saveValues, SAVE_MAX_SECONDS } from '../../core/base/saveValues.js';
@@ -54,7 +55,7 @@ export class Weather {
54
55
  this.types = {};
55
56
  for (const k of Object.keys(table)) {
56
57
  const v = { ...CALM, ...table[k] };
57
- for (const f in v) if (typeof v[f] !== 'number') throw codedError('weather-option', fmt(ERR.field, { k, f, got: String(JSON.stringify(v[f])) }));
58
+ for (const f in v) if (!Number.isFinite(v[f])) throw codedError('weather-option', fmt(ERR.field, { k, f, got: String(JSON.stringify(v[f])) }));
58
59
  this.types[k] = v;
59
60
  }
60
61
  // a game field one type has ('heat' on 'heatwave') is 0 on the others, so a change always blends between two numbers
@@ -186,6 +187,8 @@ export class Weather {
186
187
 
187
188
  }
188
189
 
190
+ const WEATHER_SIGNALS = ['uWeatherCloud', 'uWind', 'uRain', 'uSnow', 'uWeatherLight', 'uWeatherFog']; // the shared signals the state writes each frame (handed back on dispose)
191
+
189
192
  /**
190
193
  * Weather: two modules for one engine.use: the state (engine.weather, type 'world') and its picture (engine.weatherDraw, type 'picture'; sky optional)
191
194
  * @param {WeatherOptions} [opts]
@@ -203,7 +206,7 @@ export function weather(opts = {}) {
203
206
  if (opts.auto) w.auto = true;
204
207
  // the transition is saved too (current / from / to / t / dur): a save made 30% into sun -> rain loads 30% in, not as full rain, and fires no
205
208
  // weather:change (nothing changed for the player). A damaged part, or a weather the game no longer has, loads as a finished switch to that name
206
- ctx.saves.register('weather', { notAtomic: 'moves on its own timers like the calendar: an op that sets it means it to stay',
209
+ ctx.saves.define('weather', { notAtomic: 'moves on its own timers like the calendar: an op that sets it means it to stay',
207
210
  save: () => ({ name: w.name, auto: w.auto, autoTimer: w.autoTimer, nextBolt: w.nextBolt, current: { ...w.current }, from: { ...w.from }, to: { ...w.to }, t: w.t, dur: w.dur }),
208
211
  load: d => {
209
212
  if (!d) return;
@@ -220,6 +223,8 @@ export function weather(opts = {}) {
220
223
  return w;
221
224
  },
222
225
  fixed(dt) { w.tick(dt); },
226
+ // removed: the signals written below go back to clear weather, not the last storm's values
227
+ dispose(e) { resetSignals(e, WEATHER_SIGNALS); },
223
228
  // the weather as signals (engine.uniforms) every frame, from the state and not its picture: a game that draws its own rain still reads them
224
229
  frame(_dt, e) { const U = e.uniforms, c = w.current; U.uWeatherCloud.value = c.cloud; U.uWind.value = c.wind; U.uRain.value = c.rain; U.uSnow.value = c.snow; U.uWeatherLight.value = c.sun; U.uWeatherFog.value = c.fog; },
225
230
  // engine.skip: fixed hooks do not run, so the skipped fixed steps are replayed here without events (a bolt nobody saw)
@@ -4,9 +4,12 @@
4
4
  // and the output color space like three's own materials, so rain looks the same with and without post-processing.
5
5
  // weather({ rain: { glsl: { vertex, fragment } } }) replaces either text (recipes/44); copy these as the starting point.
6
6
  import * as THREE from 'three';
7
+ import { warnOnce } from '../../core/base/validate.js';
8
+ import { coded } from '../../core/base/errorHints.js';
7
9
 
8
10
  export const lineVert = `uniform vec3 uCam; uniform float uSize; uniform float uFallOff; uniform vec2 uWindDir; uniform float uLen; attribute float aEnd;
9
11
  varying float vA;
12
+ #include <fog_pars_vertex>
10
13
  void main(){
11
14
  vec3 p = position;
12
15
  float fall = mod(p.y - uFallOff, uSize);
@@ -14,26 +17,33 @@ void main(){
14
17
  w += uCam;
15
18
  w.y -= aEnd * uLen; w.x -= aEnd * uWindDir.x * 0.2; w.z -= aEnd * uWindDir.y * 0.2;
16
19
  vA = 1.0 - aEnd * 0.8;
17
- gl_Position = projectionMatrix * viewMatrix * vec4(w, 1.0);
20
+ vec4 mvPosition = viewMatrix * vec4(w, 1.0);
21
+ gl_Position = projectionMatrix * mvPosition;
22
+ #include <fog_vertex>
18
23
  }`;
19
24
  export const lineFrag = `uniform float uOpacity; uniform vec3 uColor; varying float vA;
25
+ #include <fog_pars_fragment>
20
26
  void main(){
21
27
  gl_FragColor = vec4(uColor, uOpacity * vA);
22
28
  #include <tonemapping_fragment>
23
29
  #include <colorspace_fragment>
30
+ #include <fog_fragment>
24
31
  }`;
25
32
  export const pointVert = `uniform vec3 uCam; uniform float uSize; uniform float uPx; uniform float uMaxPx; uniform float uFallOff; uniform float uSway; uniform float uSwayAmp;
33
+ #include <fog_pars_vertex>
26
34
  void main(){
27
35
  vec3 p = position;
28
36
  float fall = mod(p.y - uFallOff, uSize);
29
37
  vec3 w = vec3(mod(p.x - uCam.x + sin(uSway*0.7 + p.y)*uSwayAmp, uSize) - uSize*0.5, fall - uSize*0.35, mod(p.z - uCam.z + cos(uSway*0.5 + p.x)*uSwayAmp, uSize) - uSize*0.5) + uCam;
30
- vec4 mv = viewMatrix * vec4(w, 1.0);
31
- gl_PointSize = min(uPx * 3.0 / -mv.z, uMaxPx);
32
- gl_Position = projectionMatrix * mv;
38
+ vec4 mvPosition = viewMatrix * vec4(w, 1.0);
39
+ gl_PointSize = min(uPx * 3.0 / -mvPosition.z, uMaxPx);
40
+ gl_Position = projectionMatrix * mvPosition;
41
+ #include <fog_vertex>
33
42
  }`;
34
43
  // sprite alpha by shape (d = offset from the sprite center, |d| <= 0.5); a texture, when there is one, replaces the shape
35
44
  export const SHAPES = { round: 'step(dot(d,d), 0.25)', soft: '1.0 - smoothstep(0.0, 0.25, dot(d,d))', square: '1.0' };
36
45
  export const pointFrag = (shape = 'round') => `uniform float uOpacity; uniform vec3 uColor; uniform sampler2D uMap; uniform float uUseMap;
46
+ #include <fog_pars_fragment>
37
47
  void main(){
38
48
  vec2 d = gl_PointCoord - 0.5;
39
49
  vec4 c = uUseMap > 0.5 ? texture2D(uMap, gl_PointCoord) : vec4(1.0, 1.0, 1.0, ${SHAPES[shape]});
@@ -41,9 +51,19 @@ void main(){
41
51
  gl_FragColor = vec4(uColor * c.rgb, uOpacity * c.a);
42
52
  #include <tonemapping_fragment>
43
53
  #include <colorspace_fragment>
54
+ #include <fog_fragment>
44
55
  }`;
45
56
 
46
57
  /** Particle shader material (transparent, no depth write) */
47
- export const shaderMat = (vertexShader, fragmentShader, uniforms) => new THREE.ShaderMaterial({ vertexShader, fragmentShader, uniforms, transparent: true, depthWrite: false });
58
+ export const shaderMat = (vertexShader, fragmentShader, uniforms) => {
59
+ // fogged like the WebGPU node materials (and the engine's particles): the fog chunks are in the shaders above; their uniforms are this material's own
60
+ // (three writes the scene's fog into them each draw), added beside the { value } objects the engine shares with the game.
61
+ // Only when the vertex shader provides vFogDepth (fog_vertex): the default fragment reads it under USE_FOG, and a game's own vertex without
62
+ // the chunks would fail to link with scene fog on (the fog chunks are empty without USE_FOG, so the default fragment is fine unfogged)
63
+ const fog = vertexShader.includes('fog_vertex');
64
+ if (fog) for (const k of ['fogColor', 'fogNear', 'fogFar', 'fogDensity']) uniforms[k] ??= THREE.UniformsUtils.clone(THREE.UniformsLib.fog)[k];
65
+ else warnOnce(coded('weather-option', 'weather glsl.vertex has no fog chunks, so this weather is not fogged on WebGL (WebGPU fogs it). Add #include <fog_pars_vertex> before main() and #include <fog_vertex> after gl_Position (mvPosition = the view-space position), and <fog_pars_fragment> / <fog_fragment> in your fragment, to fade it into fog'), 'weather-glsl-fog');
66
+ return new THREE.ShaderMaterial({ vertexShader, fragmentShader, uniforms, transparent: true, depthWrite: false, fog });
67
+ };
48
68
  /** Initial particle positions: presentation only, no effect on gameplay */
49
69
  export const scatter = (n, size) => { const a = new Float32Array(n); for (let i = 0; i < n; i++) a[i] = Math.random() * size; return a; }; // presentation
@@ -8,6 +8,7 @@ import { readParams, keysSchema } from '../../core/base/params.js';
8
8
  import { isOptions } from '../../core/base/util.js';
9
9
  import { codedError } from '../../core/base/errorHints.js';
10
10
  import { onRendererSwap } from '../../render/backend.js';
11
+ import { onTierChange } from '../../core/scene/tier.js';
11
12
  import { makeSystem, updateSystem, dropSystem, RAIN, SNOW } from './particles.js';
12
13
 
13
14
  const DRAW_PARAMS = keysSchema(['particles', 'area', 'rain', 'snow']); // the picture options of weather(): the rest are the state's
@@ -29,7 +30,8 @@ export class WeatherDraw {
29
30
  /** @internal */ this._ctx = null; /** @internal */ this._h = {};
30
31
  /** @internal */ this._tint = { color: null, amount: 0, horizon: 0 };
31
32
  /** Default particle count per system: weather({ particles }), else 6000 (3000 on low-tier devices) @type {number} */
32
- this.particles = particles ?? (engine.tier === 'low' ? 3000 : 6000);
33
+ this.particles = particles ?? this._tierCount();
34
+ /** @internal the game gave no count: the default follows the tier (follow(), below) */ this._countFollows = particles == null;
33
35
  /** @internal */ this.area = area;
34
36
  /** Particle systems drawn now: field -> { field, object, material, uniforms, spec } (rain / snow when the table has them, plus fields engine.weather.defineField adds) @type {Map<string, any>} */
35
37
  this.systems = new Map();
@@ -46,6 +48,16 @@ export class WeatherDraw {
46
48
  }
47
49
  }
48
50
 
51
+ /** @internal the default count for the tier */
52
+ _tierCount() { return this.engine.tier === 'low' ? 3000 : 6000; }
53
+ /** @internal the tier changed (a stored preset arrives after install): a default count follows it, by building the systems again like a renderer swap does; a count the game gave stays */
54
+ _tierChanged() {
55
+ const n = this._tierCount();
56
+ if (!this._countFollows || n === this.particles) return;
57
+ this.particles = n;
58
+ this._rebuild();
59
+ }
60
+
49
61
  /** @internal the weather table (state half) */
50
62
  get types() { return this.state.types; }
51
63
  /** @internal the state half, read only and read live: a replaced weather module must not leave the picture on the old one */
@@ -57,7 +69,7 @@ export class WeatherDraw {
57
69
  defineField(field, spec) {
58
70
  const fields = [...new Set(Object.values(this.types).flatMap(t => Object.keys(t)))];
59
71
  if (!fields.includes(field)) throw codedError('weather-option', `weather.defineField('${field}'): no weather type has this field; add it to a type in weather({ types }) (e.g. ashfall: { ${field}: 1 }), or use one of ${fields.join(', ')}`);
60
- if (spec !== null && (typeof spec !== 'object' || Array.isArray(spec))) throw codedError('weather-option', `weather.defineField('${field}', spec): spec is an object, e.g. { shape: 'soft', color: 0x555555 } or { create }, or null to give the field back; see recipes/44-water-weather-hooks.md`);
72
+ if (spec !== null && (typeof spec !== 'object' || Array.isArray(spec))) throw codedError('weather-option', `weather.defineField('${field}', spec): spec is an object, e.g. { shape: 'soft', color: 0x555555 } or { create }, or null to give the field back; see recipes/44-water-weather-hooks.md §"Particles of the game's own weather"`);
61
73
  if (spec) return this._build(field, spec, BASE[field]);
62
74
  if (BASE[field] && this._used(field)) return this._build(field, this._given[field], BASE[field]);
63
75
  const s = this.systems.get(field);
@@ -76,16 +88,17 @@ export class WeatherDraw {
76
88
  }
77
89
 
78
90
  /**
79
- * @internal fallback 'webgl': systems built before start() carry WebGPURenderer node materials; rebuild them for the renderer in use, keeping what
91
+ * @internal build the systems again (fallback 'webgl', or a tier change that moves the default count): systems built before start() carry WebGPURenderer node materials; rebuild them for the renderer in use, keeping what
80
92
  * the game wrote since (spec numbers, uniforms, its material). A defineField() create(engine) object is the game's own and stays (the scene check names it
81
93
  * if WebGL cannot draw it).
82
94
  */
83
- _rendererSwapped() {
95
+ _rebuild() {
84
96
  for (const [f, sys] of [...this.systems]) {
85
97
  if (sys.own) continue;
86
98
  const given = sys.given;
87
99
  const next = this._build(f, sys.spec, sys.base);
88
- for (const k in sys.uniforms) if (next.uniforms[k]) next.uniforms[k].value = sys.uniforms[k].value;
100
+ // only what the game gave: a value the old slot owns (particles.tsl.js mapSlot's white stand-in, `.own`) is freed with the old material
101
+ for (const k in sys.uniforms) if (next.uniforms[k] && !sys.uniforms[k].own) next.uniforms[k].value = sys.uniforms[k].value;
89
102
  if (given) next.material = given;
90
103
  }
91
104
  }
@@ -130,7 +143,8 @@ export function weatherDrawModule(opts) {
130
143
  install(e, ctx) { e.i18n.add({ 'zh-CN': { 'module.weatherDraw': '天气外观' }, en: { 'module.weatherDraw': 'weather drawing' } });
131
144
  L = new WeatherDraw(e, opts);
132
145
  L._ctx = ctx; // the weather's entries on the shared points go with this module (ctx.mod)
133
- ctx.track(onRendererSwap(e, () => L._rendererSwapped()));
146
+ ctx.track(onRendererSwap(e, () => L._rebuild()));
147
+ ctx.track(onTierChange(e, () => L._tierChanged())); // the default particle count follows the tier
134
148
  ctx.track(e.audio.condition('weather', v => [].concat(v).includes(e.weather.name))); // audio rule condition { weather: 'rain' | ['rain', 'storm'] }
135
149
  for (const k of ['rain', 'snow', 'wind']) ctx.track(e.audio.measure(k, () => e.weather.current[k])); // data rules: { rain: { lt: 0.2 } }, volume add: { rain: 0.22 }
136
150
  builtInSounds(e.assets, { thunder: (audio, p, out) => { const dur = p.duration ?? 3.5, delay = 0.4 + Math.random() * 1.5; // presentation: thunder delay
@@ -178,7 +178,8 @@ export class World {
178
178
  * Register how a kind of thing looks: models are built automatically within radius meters of any full-detail stream source (engine.stream: player, camera
179
179
  * focus, teleport destination) and torn down when far from all of them (radius × 1.25); tearing down never touches the record. Callbacks:
180
180
  * build(rec) → three.js object (may be async). world adds it to the scene and places it at rec.position; if it throws / fails / returns a non-object:
181
- * reported once, does not block ready, retried when you leave and come back.
181
+ * reported once, does not block ready, retried when you leave and come back. Only the position is world's: rec.rot / rec.scale are the build's to apply
182
+ * (rotate the root or a child, in its own units) and update's to follow.
182
183
  * update(rec, obj, dt): called every frame for records that have a model (change the picture from the data, e.g. an opened chest swaps texture).
183
184
  * dispose(rec, obj): called on teardown (record first, model second); if omitted, engine.remove(obj).
184
185
  * show(rec) → false: this record has no model right now (picked up, waiting to respawn); re-evaluated when world.set changes records of this kind.
@@ -13,7 +13,7 @@ const PLACED = '[session] {n} world record(s) were created or removed by code be
13
13
  + 'Move them to content (content/props.js with an id and a template from content/templates.js), or create them during play inside an op';
14
14
 
15
15
  /**
16
- * Dev check on the new-game state (saves.register checkNewGame, run once start() finished): authored things come from content, so a new game has
16
+ * Dev check on the new-game state (saves.define checkNewGame, run once start() finished): authored things come from content, so a new game has
17
17
  * no runtime records but the player and removes nothing. Changed fields are not checked: simulation may already move authored records (an NPC
18
18
  * walking its schedule) while loading runs in real time. Lives here, not in core/saves/session.js: only the world knows its own save format.
19
19
  * @param {any} d the world part of the new-game state
@@ -49,7 +49,7 @@ export function world(opts = {}) {
49
49
  // after the modules, not in world's own step: physics writes the models at stage late, and a record must end the step on the solver's result, a save included
50
50
  ctx.track(e.onFixed(() => w._v.pull(), { phase: 'late' }));
51
51
  ctx.track(e.time.onMove(() => w._s.moved()));
52
- ctx.saves.register('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
52
+ ctx.saves.define('world', { atomic: true, version: 5, migrate: WORLD_MIGRATE, save: () => w.toJSON(), load: d => w.fromJSON(d), checkNewGame: codePlaced });
53
53
  ctx.things.addSource(recordSource(w)); // engine.thing / thing.set / the shared id space reach the records through this
54
54
  ctx.things.explainWith(worldExplain);
55
55
  ctx.budget.metric('worldRecords', () => w.records.size);
@@ -62,7 +62,7 @@ function diff(rec, base) {
62
62
 
63
63
  const mapValues = (o, f) => o && typeof o === 'object' ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, f(v)])) : o;
64
64
 
65
- /** Upgrade steps of the world save part (saves.register version 5) @internal */
65
+ /** Upgrade steps of the world save part (saves.define version 5) @internal */
66
66
  export const WORLD_MIGRATE = {
67
67
  1: d => ({ ...d, records: Object.fromEntries((d?.records || []).map(({ id, ...r }) => [id, r])) }), // array of records -> keyed by id
68
68
  2: d => { // runtime ids `<kind>-<n>` -> `<kind>#<n>`: record keys, owed keys, and field values that name a renamed record
@@ -195,7 +195,10 @@ function checkWorldSave(d, kindOf, assets) {
195
195
  /** Load: replace runtime records wholesale; loaded initial records go back to the original then get the save's changes; unloaded content waits for its add. Independent of the order of content.load @internal */
196
196
  export function loadWorld(w, d) {
197
197
  checkWorldSave(d, id => w._base.get(id)?.kind, w.engine.assets); // before anything is cleared: a refused save leaves the world as it was (the rollback then has nothing to undo here)
198
- w._v.clear();
198
+ // a replacement rebuilds every model (its afterLoad hooks and the physics parts rebuild what they attach for the new state); outside one, an atomic op's
199
+ // rollback puts plain data back and runs no afterLoad, so a model whose record comes back the same stays (views.keepSame)
200
+ const built = w.engine.saves.replacing ? null : new Map(w.records);
201
+ if (!built) w._v.clear();
199
202
  w.records.clear(); w._cells.clear(); w._unsaved.clear();
200
203
  for (const id of [...w._origin.keys()]) if (!w._base.has(id)) w._origin.delete(id); // runtime records come from the save now (no op to name)
201
204
  w._seq = d?.seq ?? 0;
@@ -205,6 +208,7 @@ export function loadWorld(w, d) {
205
208
  renamePending(w); // content/renames.js, before initial records take their diffs
206
209
  for (const [id, base] of w._base) if (!w._removed.has(id)) w._insert(w._fromBase(id, base));
207
210
  for (const [id, r] of Object.entries(d?.records || {})) w._insert({ id, ...r });
211
+ if (built) w._v.keepSame(built);
208
212
  w.engine.events.emit('world:load', { count: w.records.size });
209
213
  }
210
214
 
@@ -172,6 +172,7 @@ export class Views {
172
172
  v.obj = obj; v.pending = false; this.byObj.set(obj, rec.id);
173
173
  if (p.positionFrom === 'view') { this.moving.add(rec.id); v.at = { ...rec.position }; } // at: the record as pull last left it
174
174
  obj.position.copy(rec.position);
175
+ // only the position: rot / scale are the build's to read (its own units, a turned child, a baked size), as in 1.1; engine presenters place them in their build
175
176
  if (!obj.parent) e.add(obj, { owner: 'world', id: rec.id }); // the registry knows it as the record (engine.thing / hit.thing)
176
177
  };
177
178
  let out;
@@ -179,11 +180,12 @@ export class Views {
179
180
  try { out = p.build(rec); if (typeof out?.then !== 'function') { done(out); return; } } catch (err) { fail(err); return; } finally { this.w._building = null; }
180
181
  out.then(done).catch(fail).then(() => this.wake()); // an async build settled: waiters of a paused engine resolve here (see wake)
181
182
  }
182
- unview(id) {
183
+ /** @param {string} id @param {any} [rec] the record the model was built from, when the world no longer holds it (keepSame) */
184
+ unview(id, rec = this.w.records.get(id)) {
183
185
  const v = this.map.get(id); if (!v) return;
184
186
  this.map.delete(id); this.moving.delete(id);
185
187
  if (v.obj) this.byObj.delete(v.obj);
186
- if (v.obj) this.drop(this.w.records.get(id), v.p, v.obj);
188
+ if (v.obj) this.drop(rec, v.p, v.obj);
187
189
  }
188
190
  /**
189
191
  * Tear down a model. A dispose error is reported on its own (naming the kind's dispose) and not thrown outward — otherwise loading a save would report it as
@@ -194,4 +196,15 @@ export class Views {
194
196
  try { p.dispose(rec, obj); } catch (err) { reportError(this.w.engine, err, say(STRINGS.disposeFailed, rec.kind), { soft: true }); }
195
197
  }
196
198
  clear() { for (const id of [...this.map.keys()]) this.unview(id); this.dirty = true; }
199
+ /**
200
+ * A load replaced the records (built: the ones the models were built from). A model whose record came back the same stays; the rest go and rebuild nearby.
201
+ * Tearing down every model would leave an atomic op's rollback, which puts most of the world back unchanged and runs no afterLoad, without the scene
202
+ * and its colliders for frames (review l2 #2). Same means the same data: a record that cannot be compared counts as changed.
203
+ * @param {Map<string, any>} built
204
+ */
205
+ keepSame(built) {
206
+ const same = (a, b) => { try { return JSON.stringify(a) === JSON.stringify(b); } catch { return false; } };
207
+ for (const id of [...this.map.keys()]) { const was = built.get(id), now = this.w.records.get(id); if (!now || !was || !same(was, now)) this.unview(id, was); }
208
+ this.dirty = true;
209
+ }
197
210
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "threedog",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Web 3D game engine on three.js: core + optional modules, no built-in art (the picture comes from your own style), built to be driven by an AI",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,8 +25,10 @@
25
25
  },
26
26
  "./error-hints": "./core/base/errorHints.js",
27
27
  "./spelling": "./core/base/spelling.js",
28
+ "./model-needs": "./core/assets/modelNeeds.js",
28
29
  "./metadata": "./core/inspect/metadata.generated.js",
29
30
  "./grid": "./core/scene/grid.js",
31
+ "./draw-only": "./core/scene/drawOnly.js",
30
32
  "./layers": "./render/layers.js",
31
33
  "./pixel": {
32
34
  "types": "./types/pixel.d.ts",
@@ -84,6 +86,7 @@
84
86
  "./render/fx/patchNodes.tsl.js",
85
87
  "./render/fx/postWebGPU.tsl.js",
86
88
  "./render/fx/sky.tsl.js",
89
+ "./render/impostor.tsl.js",
87
90
  "./render/lighting.js",
88
91
  "./render/ownFrame.js",
89
92
  "./render/patches.js",
package/presets.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // Opt-in gameplay presets: named, plain option objects a game picks on purpose, like a style for feel.
2
- // The engine never applies one by itself (weather() alone has only 'clear', sky() has no seasons and no day cycle, music() does not duck for dialogue, no module binds a gameplay key, createPlayer() and interactions() refuse to guess a feel
2
+ // The engine never applies one by itself (weather() alone has only 'clear', sky() has no seasons and no day cycle, music() does not duck for dialogue, no module binds a gameplay key, addPlayer() and interactions() refuse to guess a feel
3
3
  // or a key); a preset only bundles options the game could write itself, so spreading it and overriding a field is always the same as writing it out:
4
4
  // engine.use(weather({ ...presets.weather.temperate, autoPool: ['clear', 'rain'] }));
5
- // engine.characters.createPlayer({ ...presets.player.lockOn, faceTarget: boss });
5
+ // engine.characters.addPlayer({ ...presets.player.lockOn, faceTarget: boss });
6
6
  // engine.use(interactions({ ...presets.interactions.nearest, radius: 3 }));
7
7
  // No imports and no engine state: plain data plus small control functions that call public API only.
8
8
 
@@ -17,7 +17,7 @@ const keys = (...k) => Object.freeze(k);
17
17
  /**
18
18
  * Opt-in presets, grouped by the option they fill. Each value is an options object for the function named in its group.
19
19
  * @example engine.use(openWorld({ weather: presets.weather.temperate, calendar: presets.calendar.fourSeasons }))
20
- * @example engine.use(followCamera(presets.camera.overShoulder)); engine.characters.createPlayer({ ...presets.player.aim, spawn })
20
+ * @example engine.use(followCamera(presets.camera.overShoulder)); engine.characters.addPlayer({ ...presets.player.aim, spawn })
21
21
  * @example engine.use(interactions({ ...presets.interactions.nearest }))
22
22
  */
23
23
  export const presets = Object.freeze({
@@ -46,7 +46,7 @@ export const presets = Object.freeze({
46
46
  /** One time of day that never moves (dungeon, arena, space station), what calendar() does without a dayLength; pick the hour with time */
47
47
  fixedTime: Object.freeze({ dayLength: Infinity }),
48
48
  }),
49
- /** characters.createPlayer({ ... }) movement, facing and camera follow (createPlayer has no default: pick one of these or write the options; keys: presets.bindings.walk) */
49
+ /** characters.addPlayer({ ... }) movement, facing and camera follow (addPlayer has no default: pick one of these or write the options; keys: presets.bindings.walk) */
50
50
  player: Object.freeze({
51
51
  /** Keys relative to the camera, turn toward the move direction, camera follows (adventure, life sim) */
52
52
  thirdPerson: walk('camera', 'move'),
@@ -72,7 +72,7 @@ export const presets = Object.freeze({
72
72
  * an action bound to [] has deliberately no key.
73
73
  */
74
74
  bindings: Object.freeze({
75
- /** characters.createPlayer(): Shift / gamepad LB runs, Space / gamepad A jumps */
75
+ /** characters.addPlayer(): Shift / gamepad LB runs, Space / gamepad A jumps */
76
76
  walk: Object.freeze({ run: keys('ShiftLeft', 'ShiftRight', 'PadLB'), jump: keys('Space', 'PadA') }),
77
77
  /** interactions(): E / gamepad X uses the picked one */
78
78
  interact: Object.freeze({ interact: keys('KeyE', 'PadX') }),