@jgengine/shell 0.19.0 → 0.21.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 (203) hide show
  1. package/CHANGELOG.md +346 -0
  2. package/dist/GameHost.d.ts +12 -1
  3. package/dist/GameHost.js +14 -1
  4. package/dist/GamePlayerShell.js +113 -15
  5. package/dist/Shell3dPresentation.d.ts +2 -2
  6. package/dist/Shell3dPresentation.js +49 -7
  7. package/dist/ShellChrome.d.ts +2 -1
  8. package/dist/ShellChrome.js +22 -6
  9. package/dist/ShellHudPresentation.d.ts +11 -1
  10. package/dist/ShellHudPresentation.js +20 -6
  11. package/dist/audio/audioEngine.d.ts +16 -0
  12. package/dist/audio/audioEngine.js +178 -89
  13. package/dist/audio/audioWire.js +2 -2
  14. package/dist/audio/synthEngine.d.ts +7 -1
  15. package/dist/audio/synthEngine.js +103 -38
  16. package/dist/camera/GameCameraRig.js +2 -1
  17. package/dist/camera/GameFirstPersonCamera.d.ts +2 -2
  18. package/dist/camera/GameFirstPersonCamera.js +17 -13
  19. package/dist/camera/cameraRigs.js +8 -2
  20. package/dist/camera/chaseHeading.d.ts +9 -0
  21. package/dist/camera/chaseHeading.js +10 -0
  22. package/dist/camera/customMuzzle.d.ts +14 -0
  23. package/dist/camera/customMuzzle.js +68 -0
  24. package/dist/camera/index.d.ts +1 -0
  25. package/dist/camera/index.js +1 -0
  26. package/dist/camera/rigResolve.d.ts +3 -0
  27. package/dist/camera/rigResolve.js +11 -0
  28. package/dist/combat/ProjectileModels.d.ts +31 -0
  29. package/dist/combat/ProjectileModels.js +70 -0
  30. package/dist/commandSink.d.ts +1 -2
  31. package/dist/commandSink.js +3 -2
  32. package/dist/defineGame.d.ts +12 -5
  33. package/dist/defineGame.js +24 -9
  34. package/dist/devtools/DevtoolsOverlay.d.ts +2 -69
  35. package/dist/devtools/DevtoolsOverlay.js +14 -168
  36. package/dist/devtools/DevtoolsRuntime.d.ts +7 -0
  37. package/dist/devtools/DevtoolsRuntime.js +61 -0
  38. package/dist/devtools/agentBridge.js +1 -1
  39. package/dist/devtools/devtoolsReports.d.ts +68 -0
  40. package/dist/devtools/devtoolsReports.js +100 -0
  41. package/dist/devtools/latencyInstrumentation.d.ts +3 -0
  42. package/dist/devtools/latencyInstrumentation.js +11 -0
  43. package/dist/devtools/playtestProbe.d.ts +4 -0
  44. package/dist/devtools/playtestProbe.js +22 -0
  45. package/dist/drivers/FrameDriver.js +25 -21
  46. package/dist/drivers/HudOnlyDriver.d.ts +6 -1
  47. package/dist/drivers/HudOnlyDriver.js +32 -14
  48. package/dist/environment/EnvironmentScene.js +11 -10
  49. package/dist/inputSink.d.ts +6 -6
  50. package/dist/inputSink.js +60 -21
  51. package/dist/lazyShell3dPresentation.d.ts +9 -0
  52. package/dist/lazyShell3dPresentation.js +24 -0
  53. package/dist/materialOverride.d.ts +42 -0
  54. package/dist/materialOverride.js +95 -36
  55. package/dist/multiplayer.d.ts +33 -3
  56. package/dist/multiplayer.js +105 -22
  57. package/dist/pointer/pointerService.d.ts +2 -0
  58. package/dist/pointer/pointerService.js +12 -2
  59. package/dist/postfx/PostProcessing.d.ts +10 -0
  60. package/dist/postfx/PostProcessing.js +9 -41
  61. package/dist/postfx/gradeShader.d.ts +1 -1
  62. package/dist/postfx/gradeShader.js +30 -2
  63. package/dist/postfx/shadowPrepass.d.ts +3 -0
  64. package/dist/postfx/shadowPrepass.js +18 -0
  65. package/dist/presentationRecovery.d.ts +75 -0
  66. package/dist/presentationRecovery.js +204 -0
  67. package/dist/presentationRecovery3d.d.ts +4 -0
  68. package/dist/presentationRecovery3d.js +32 -0
  69. package/dist/presentationResolve.d.ts +8 -1
  70. package/dist/presentationResolve.js +5 -2
  71. package/dist/render/CascadedShadows.d.ts +7 -2
  72. package/dist/render/CascadedShadows.js +98 -20
  73. package/dist/render/EnvironmentLighting.js +74 -35
  74. package/dist/render/HairCards.d.ts +7 -0
  75. package/dist/render/HairCards.js +23 -0
  76. package/dist/render/SceneModels.js +51 -77
  77. package/dist/render/authoredSurfaceMaterial.d.ts +43 -0
  78. package/dist/render/authoredSurfaceMaterial.js +108 -0
  79. package/dist/render/materialAppearanceSignals.d.ts +23 -0
  80. package/dist/render/materialAppearanceSignals.js +58 -0
  81. package/dist/render/materialAsset.d.ts +98 -0
  82. package/dist/render/materialAsset.js +454 -0
  83. package/dist/render/measureBounds.js +16 -3
  84. package/dist/render/measureCollisionMesh.js +8 -1
  85. package/dist/render/modelAssets.d.ts +8 -0
  86. package/dist/render/modelAssets.js +43 -0
  87. package/dist/render/modelBindPose.d.ts +5 -0
  88. package/dist/render/modelBindPose.js +35 -0
  89. package/dist/render/modelLoad.d.ts +3 -0
  90. package/dist/render/modelLoad.js +9 -0
  91. package/dist/render/modelNodeVisibility.d.ts +6 -0
  92. package/dist/render/modelNodeVisibility.js +18 -0
  93. package/dist/render/modelRender.d.ts +18 -1
  94. package/dist/render/modelRender.js +81 -3
  95. package/dist/render/projectedOverdraw.d.ts +35 -0
  96. package/dist/render/projectedOverdraw.js +204 -0
  97. package/dist/render/resolveModel.d.ts +12 -2
  98. package/dist/render/resolveModel.js +21 -4
  99. package/dist/render/rigNode.d.ts +26 -0
  100. package/dist/render/rigNode.js +32 -0
  101. package/dist/render/spriteRender.d.ts +4 -0
  102. package/dist/render/spriteRender.js +5 -0
  103. package/dist/render/staticShapeInstances.d.ts +34 -0
  104. package/dist/render/staticShapeInstances.js +78 -0
  105. package/dist/render/useFootIk.js +76 -11
  106. package/dist/render/useModelAnimation.d.ts +28 -2
  107. package/dist/render/useModelAnimation.js +194 -69
  108. package/dist/render/useModelInstance.d.ts +25 -0
  109. package/dist/render/useModelInstance.js +43 -0
  110. package/dist/scatter/scatterModels.d.ts +3 -2
  111. package/dist/scatter/scatterModels.js +15 -7
  112. package/dist/scene/AuthoredScene.d.ts +14 -6
  113. package/dist/scene/AuthoredScene.js +30 -9
  114. package/dist/scene/GeneratedAssetRenderer.js +11 -42
  115. package/dist/settings/SettingsMenu.js +11 -18
  116. package/dist/settings/SettingsRuntime.d.ts +5 -0
  117. package/dist/settings/SettingsRuntime.js +29 -2
  118. package/dist/shellControlSuspension.d.ts +18 -0
  119. package/dist/shellControlSuspension.js +28 -0
  120. package/dist/shellInputPublication.d.ts +28 -0
  121. package/dist/shellInputPublication.js +49 -0
  122. package/dist/shellPointerInput.d.ts +18 -0
  123. package/dist/shellPointerInput.js +49 -0
  124. package/dist/structures/BuildingKitBatch.d.ts +3 -1
  125. package/dist/structures/BuildingKitBatch.js +34 -59
  126. package/dist/structures/BuildingRenderBudget.d.ts +23 -0
  127. package/dist/structures/BuildingRenderBudget.js +54 -0
  128. package/dist/structures/GeneratedBuilding.js +13 -8
  129. package/dist/structures/buildingKitMaterials.d.ts +20 -0
  130. package/dist/structures/buildingKitMaterials.js +70 -0
  131. package/dist/structures/buildingSpatialBatch.d.ts +11 -0
  132. package/dist/structures/buildingSpatialBatch.js +45 -0
  133. package/dist/terrain/GrassField.d.ts +2 -1
  134. package/dist/terrain/GrassField.js +59 -5
  135. package/dist/terrain/grassGeometry.d.ts +10 -0
  136. package/dist/terrain/grassGeometry.js +55 -0
  137. package/dist/terrain/grassMaterial.js +2 -2
  138. package/dist/terrain/terrainDetailMaterial.d.ts +3 -3
  139. package/dist/terrain/terrainDetailMaterial.js +7 -7
  140. package/dist/touch/TouchControlsOverlay.js +4 -4
  141. package/dist/useShellMultiplayerSync.js +4 -0
  142. package/dist/vfx/ParticleField.d.ts +23 -20
  143. package/dist/vfx/ParticleField.js +168 -50
  144. package/dist/visibility/CullingProvider.js +2 -62
  145. package/dist/visibility/cullingDriver.d.ts +9 -0
  146. package/dist/visibility/cullingDriver.js +68 -0
  147. package/dist/weather/AuthoredWeatherLayer.d.ts +16 -0
  148. package/dist/weather/AuthoredWeatherLayer.js +31 -0
  149. package/dist/weather/DustField.d.ts +2 -1
  150. package/dist/weather/DustField.js +17 -3
  151. package/dist/weather/FireSpreadLayer.d.ts +4 -2
  152. package/dist/weather/FireSpreadLayer.js +5 -11
  153. package/dist/weather/LightningStrike.d.ts +4 -1
  154. package/dist/weather/LightningStrike.js +13 -17
  155. package/dist/weather/RainField.d.ts +2 -1
  156. package/dist/weather/RainField.js +17 -3
  157. package/dist/weather/RainImpactField.d.ts +16 -0
  158. package/dist/weather/RainImpactField.js +89 -0
  159. package/dist/weather/SnowField.d.ts +2 -1
  160. package/dist/weather/SnowField.js +17 -3
  161. package/dist/weather/WeatherLayer.d.ts +11 -2
  162. package/dist/weather/WeatherLayer.js +30 -6
  163. package/dist/weather/index.d.ts +2 -0
  164. package/dist/weather/index.js +2 -0
  165. package/dist/weather/weatherMath.d.ts +2 -0
  166. package/dist/weather/weatherMath.js +8 -0
  167. package/dist/weather/weatherShelter.d.ts +18 -0
  168. package/dist/weather/weatherShelter.js +75 -0
  169. package/dist/weather/weatherUniforms.d.ts +40 -1
  170. package/dist/weather/weatherUniforms.js +29 -9
  171. package/dist/world/AuthoredFlocks.d.ts +22 -0
  172. package/dist/world/AuthoredFlocks.js +87 -0
  173. package/dist/world/StaticObjectModels.d.ts +8 -0
  174. package/dist/world/StaticObjectModels.js +75 -0
  175. package/dist/world/WorldHud.d.ts +14 -6
  176. package/dist/world/WorldHud.js +25 -12
  177. package/dist/world/WorldParticles.d.ts +10 -23
  178. package/dist/world/WorldParticles.js +209 -61
  179. package/dist/world/WorldScene.d.ts +3 -1
  180. package/dist/world/WorldScene.js +41 -26
  181. package/dist/world/staticObjectBatches.d.ts +35 -0
  182. package/dist/world/staticObjectBatches.js +163 -0
  183. package/dist/world/worldBarSamples.d.ts +37 -33
  184. package/dist/world/worldBarSamples.js +117 -75
  185. package/package.json +4 -4
  186. package/skills/ce-handoff/SKILL.md +1 -1
  187. package/skills/jgengine/SKILL.md +22 -2
  188. package/skills/jgengine/api.md +28 -17
  189. package/skills/jgengine/recipes/minimal-game.md +7 -2
  190. package/skills/jgengine-ui/SKILL.md +3 -1
  191. package/skills/jgengine-ui/api.md +204 -67
  192. package/skills/jgengine-ui/capabilities.md +115 -1
  193. package/skills/jgengine-ui/reference-primitives.md +93 -3
  194. package/skills/jgengine-ui/reference.md +2 -0
  195. package/skills/jgengine-world/SKILL.md +12 -3
  196. package/skills/jgengine-world/api.md +200 -57
  197. package/skills/jgengine-world/capabilities.md +116 -3
  198. package/skills/jgengine-world/recipes/character-animation.md +31 -8
  199. package/skills/jgengine-world/recipes/controls.md +4 -0
  200. package/skills/jgengine-world/recipes/npc-senses.md +12 -0
  201. package/skills/jgengine-world/recipes/vehicle-feel.md +3 -1
  202. package/skills/jgengine-world/reference.md +152 -5
  203. package/skills/jgengine-world/visibility.md +28 -1
@@ -4,6 +4,7 @@ import * as THREE from "three";
4
4
  import { useDisposable } from "../render/useDisposable.js";
5
5
  import { createWeatherQuadGeometry } from "./weatherGeometry.js";
6
6
  import { DEFAULT_DUST_COUNT, DEFAULT_DUST_DENSITY, resolveWeatherInstanceCount } from "./weatherMath.js";
7
+ import { WEATHER_SHELTER_SHADER } from "./weatherShelter.js";
7
8
  import { useWeatherUniformSet } from "./weatherUniforms.js";
8
9
  const DEFAULT_VOLUME = [70, 22, 70];
9
10
  const DEFAULT_ORIGIN = [0, 0, 0];
@@ -16,13 +17,16 @@ const DEFAULT_DUST_COLOR = "#c8a878";
16
17
  *
17
18
  * @capability weather-dust airborne particulate that turns still air into visible wind
18
19
  */
19
- export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_DENSITY, budget, volume = DEFAULT_VOLUME, wind, origin = DEFAULT_ORIGIN, followCamera = true, speed = 2.4, size = 0.16, sway = 0.5, opacity = 0.3, color = DEFAULT_DUST_COLOR, groundBias = 0.65, timeScale, seed = 51407, renderOrder = 10, frustumCulled, }) {
20
+ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_DENSITY, budget, volume = DEFAULT_VOLUME, wind, origin = DEFAULT_ORIGIN, followCamera = true, speed = 2.4, size = 0.16, sway = 0.5, opacity = 0.3, color = DEFAULT_DUST_COLOR, groundBias = 0.65, timeScale, timeSeconds, seed = 51407, renderOrder = 10, frustumCulled, }) {
20
21
  const { camera } = useThree();
21
- const shared = useWeatherUniformSet({ wind, timeScale });
22
+ const shared = useWeatherUniformSet({ wind, timeScale, timeSeconds });
22
23
  const geometry = useDisposable(() => createWeatherQuadGeometry(count, seed), [count, seed]);
23
24
  const material = useDisposable(() => {
24
25
  const uniforms = {
25
26
  uTime: shared.time,
27
+ uShelterCenters: shared.shelterCenters,
28
+ uShelterShapes: shared.shelterShapes,
29
+ uShelterCount: shared.shelterCount,
26
30
  uWind: shared.wind,
27
31
  uAnchor: { value: new THREE.Vector3() },
28
32
  uVolume: { value: new THREE.Vector3() },
@@ -39,6 +43,7 @@ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_D
39
43
  depthWrite: false,
40
44
  blending: THREE.NormalBlending,
41
45
  vertexShader: `
46
+ ${WEATHER_SHELTER_SHADER}
42
47
  uniform float uTime;
43
48
  uniform vec3 uWind;
44
49
  uniform vec3 uAnchor;
@@ -51,6 +56,7 @@ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_D
51
56
  attribute vec3 aSpawn;
52
57
  attribute float aDrift;
53
58
 
59
+ varying float vExposure;
54
60
  varying vec2 vUv;
55
61
  varying float vDrift;
56
62
  varying float vFade;
@@ -76,6 +82,7 @@ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_D
76
82
  vec3 travel = normalize(vec3(uWind.x, 0.0, uWind.z) + vec3(0.0001, 0.0, 0.0)) * carry;
77
83
  vec3 local = spawn * uVolume + (uWind + travel) * uTime + bob;
78
84
  vec3 worldCenter = mod(local - origin, uVolume) + origin;
85
+ vExposure = weatherExposure(worldCenter);
79
86
 
80
87
  // Fade at the top of the volume so recycled motes do not pop into view against the sky.
81
88
  float height = (worldCenter.y - origin.y) / max(uVolume.y, 0.001);
@@ -93,6 +100,7 @@ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_D
93
100
  uniform float uOpacity;
94
101
  uniform vec3 uColor;
95
102
 
103
+ varying float vExposure;
96
104
  varying vec2 vUv;
97
105
  varying float vDrift;
98
106
  varying float vFade;
@@ -102,6 +110,7 @@ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_D
102
110
  // No hard core: dust is diffuse, and a bright centre reads as snow.
103
111
  float puff = smoothstep(1.0, 0.05, distanceFromCenter);
104
112
  float alpha = puff * puff * uOpacity * (0.35 + 0.65 * vDrift) * vFade;
113
+ alpha *= vExposure;
105
114
  if (alpha < 0.001) discard;
106
115
  gl_FragColor = vec4(uColor, alpha);
107
116
  }
@@ -123,7 +132,12 @@ export function DustField({ count = DEFAULT_DUST_COUNT, density = DEFAULT_DUST_D
123
132
  uniforms.uOpacity.value = opacity;
124
133
  uniforms.uGroundBias.value = groundBias;
125
134
  uniforms.uColor.value.set(color);
126
- geometry.instanceCount = resolveWeatherInstanceCount(count, density, budget);
135
+ geometry.instanceCount = resolveWeatherInstanceCount(count, density * shared.dust.value, budget);
136
+ const metrics = shared.metrics?.dust;
137
+ if (metrics !== undefined) {
138
+ metrics.count = geometry.instanceCount;
139
+ metrics.capacity = geometry.getAttribute("aSpawn").count;
140
+ }
127
141
  });
128
142
  return (_jsx("mesh", { geometry: geometry, material: material, frustumCulled: frustumCulled ?? !followCamera, renderOrder: renderOrder }));
129
143
  }
@@ -2,7 +2,7 @@ import * as THREE from "three";
2
2
  import type { FireGrid } from "@jgengine/core/world/weather";
3
3
  export interface FireSpreadLayerProps {
4
4
  grid: FireGrid;
5
- cellSize: number;
5
+ cellSize?: number;
6
6
  origin?: readonly [number, number];
7
7
  /** Sample ground height so flames sit on terrain; defaults to y=0. */
8
8
  heightAt?: (x: number, z: number) => number;
@@ -10,5 +10,7 @@ export interface FireSpreadLayerProps {
10
10
  flameHeight?: number;
11
11
  burningColor?: THREE.ColorRepresentation;
12
12
  emberColor?: THREE.ColorRepresentation;
13
+ /** Absolute authoritative simulation clock; use for pause and snapshot restore. */
14
+ timeSeconds?: () => number;
13
15
  }
14
- export declare function FireSpreadLayer({ grid, cellSize, origin, heightAt, flameHeight, burningColor, emberColor, }: FireSpreadLayerProps): import("react").JSX.Element;
16
+ export declare function FireSpreadLayer({ grid, cellSize, origin, heightAt, flameHeight, burningColor, emberColor, timeSeconds, }: FireSpreadLayerProps): import("react").JSX.Element;
@@ -3,8 +3,7 @@ import { useEffect, useMemo, useRef } from "react";
3
3
  import { useFrame } from "@react-three/fiber";
4
4
  import * as THREE from "three";
5
5
  import { setBillboardQuaternion } from "./fireSpreadPose.js";
6
- const HIDDEN = new THREE.Matrix4().makeScale(0, 0, 0);
7
- export function FireSpreadLayer({ grid, cellSize, origin = [0, 0], heightAt, flameHeight = 1.6, burningColor = "#ff6a1a", emberColor = "#4a1206", }) {
6
+ export function FireSpreadLayer({ grid, cellSize = grid.cellSize, origin = grid.origin, heightAt, flameHeight = 1.6, burningColor = "#ff6a1a", emberColor = "#4a1206", timeSeconds, }) {
8
7
  const flames = useRef(null);
9
8
  const scorch = useRef(null);
10
9
  const capacity = grid.cols * grid.rows;
@@ -33,13 +32,12 @@ export function FireSpreadLayer({ grid, cellSize, origin = [0, 0], heightAt, fla
33
32
  const scorchMesh = scorch.current;
34
33
  if (flameMesh === null || scorchMesh === null)
35
34
  return;
36
- const cells = grid.snapshot();
37
- const flicker = 0.85 + 0.15 * Math.sin(state.clock.elapsedTime * 12);
35
+ const flicker = 0.85 + 0.15 * Math.sin((timeSeconds?.() ?? state.clock.elapsedTime) * 12);
38
36
  let flameIndex = 0;
39
37
  let scorchIndex = 0;
40
38
  for (let row = 0; row < grid.rows; row += 1) {
41
39
  for (let col = 0; col < grid.cols; col += 1) {
42
- const cell = cells[row * grid.cols + col];
40
+ const cell = grid.cell(col, row);
43
41
  const x = origin[0] + col * cellSize;
44
42
  const z = origin[1] + row * cellSize;
45
43
  const groundY = heightAt?.(x, z) ?? 0;
@@ -60,12 +58,8 @@ export function FireSpreadLayer({ grid, cellSize, origin = [0, 0], heightAt, fla
60
58
  }
61
59
  }
62
60
  }
63
- for (let i = flameIndex; i < capacity; i += 1)
64
- flameMesh.setMatrixAt(i, HIDDEN);
65
- for (let i = scorchIndex; i < capacity; i += 1)
66
- scorchMesh.setMatrixAt(i, HIDDEN);
67
- flameMesh.count = capacity;
68
- scorchMesh.count = capacity;
61
+ flameMesh.count = flameIndex;
62
+ scorchMesh.count = scorchIndex;
69
63
  flameMesh.instanceMatrix.needsUpdate = true;
70
64
  scorchMesh.instanceMatrix.needsUpdate = true;
71
65
  });
@@ -13,5 +13,8 @@ export interface LightningStrikeProps {
13
13
  jaggedness?: number;
14
14
  impactLight?: number;
15
15
  renderOrder?: number;
16
+ /** Supply both fields to replay the strike from authoritative simulation state. */
17
+ timeSeconds?: () => number;
18
+ startedAt?: number;
16
19
  }
17
- export declare function LightningStrike({ origin, target, strikeKey, seed, visible, duration, color, glow, branches, jaggedness, impactLight, renderOrder, }: LightningStrikeProps): import("react").JSX.Element;
20
+ export declare function LightningStrike({ origin, target, strikeKey, seed, visible, duration, color, glow, branches, jaggedness, impactLight, renderOrder, timeSeconds, startedAt, }: LightningStrikeProps): import("react").JSX.Element;
@@ -3,6 +3,7 @@ import { useEffect, useMemo, useRef } from "react";
3
3
  import { useFrame } from "@react-three/fiber";
4
4
  import * as THREE from "three";
5
5
  import { useDisposable } from "../render/useDisposable.js";
6
+ import { lightningStrikeEnvelope } from "./weatherMath.js";
6
7
  const DEFAULT_COLOR = "#bdd4ff";
7
8
  function createRandom(seed) {
8
9
  let state = seed >>> 0;
@@ -47,7 +48,7 @@ function createLightningSegments(origin, target, seed, branches, jaggedness) {
47
48
  for (let index = 0; index < points.length - 1; index += 1) {
48
49
  segments.push({ from: points[index], to: points[index + 1] });
49
50
  }
50
- const branchCount = Math.max(0, Math.floor(branches));
51
+ const branchCount = Math.max(0, Math.min(64, Math.floor(branches)));
51
52
  for (let index = 0; index < branchCount; index += 1) {
52
53
  const sourceIndex = 2 + Math.floor(random() * Math.max(1, points.length - 5));
53
54
  const source = points[sourceIndex];
@@ -78,8 +79,9 @@ function writeLightningGeometry(geometry, segments) {
78
79
  geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
79
80
  geometry.computeBoundingSphere();
80
81
  }
81
- export function LightningStrike({ origin, target, strikeKey = 0, seed = 451, visible = true, duration = 0.18, color = DEFAULT_COLOR, glow = 2.4, branches = 5, jaggedness = 0.08, impactLight = 26, renderOrder = 20, }) {
82
- const lifeRef = useRef(0);
82
+ export function LightningStrike({ origin, target, strikeKey = 0, seed = 451, visible = true, duration = 0.18, color = DEFAULT_COLOR, glow = 2.4, branches = 5, jaggedness = 0.08, impactLight = 26, renderOrder = 20, timeSeconds, startedAt, }) {
83
+ const localTime = useRef(0);
84
+ const startRef = useRef(null);
83
85
  const lightRef = useRef(null);
84
86
  const geometry = useDisposable(() => new THREE.BufferGeometry(), []);
85
87
  const material = useDisposable(() => new THREE.LineBasicMaterial({
@@ -97,28 +99,22 @@ export function LightningStrike({ origin, target, strikeKey = 0, seed = 451, vis
97
99
  }, [geometry, material, renderOrder]);
98
100
  useEffect(() => {
99
101
  if (!visible) {
100
- lifeRef.current = 0;
102
+ startRef.current = null;
101
103
  material.opacity = 0;
102
104
  if (lightRef.current !== null)
103
105
  lightRef.current.intensity = 0;
104
106
  return;
105
107
  }
106
108
  writeLightningGeometry(geometry, createLightningSegments(origin, target, seed ^ hashStrikeKey(strikeKey), branches, jaggedness));
107
- lifeRef.current = duration;
108
- }, [branches, duration, geometry, jaggedness, material, origin, seed, strikeKey, target, visible]);
109
+ startRef.current = startedAt ?? timeSeconds?.() ?? localTime.current;
110
+ }, [branches, duration, geometry, jaggedness, material, origin, seed, strikeKey, target, visible, startedAt, timeSeconds]);
109
111
  useFrame((_state, delta) => {
110
- if (!visible || lifeRef.current <= 0) {
111
- material.opacity = 0;
112
- if (lightRef.current !== null)
113
- lightRef.current.intensity = 0;
114
- return;
115
- }
116
- lifeRef.current = Math.max(0, lifeRef.current - delta);
117
- const amount = duration <= 0 ? 0 : lifeRef.current / duration;
118
- const flicker = 0.62 + Math.random() * 0.38;
119
- material.opacity = amount * glow * flicker;
112
+ localTime.current += delta;
113
+ const now = timeSeconds?.() ?? localTime.current;
114
+ const amount = visible && startRef.current !== null ? lightningStrikeEnvelope(now, startRef.current, duration, seed ^ hashStrikeKey(strikeKey)) : 0;
115
+ material.opacity = amount * glow;
120
116
  if (lightRef.current !== null)
121
- lightRef.current.intensity = amount * impactLight * flicker;
117
+ lightRef.current.intensity = amount * impactLight;
122
118
  });
123
119
  return (_jsxs(_Fragment, { children: [_jsx("primitive", { object: line }), _jsx("pointLight", { ref: lightRef, position: [target[0], target[1], target[2]], color: color, intensity: 0, distance: 56, decay: 2 })] }));
124
120
  }
@@ -15,8 +15,9 @@ export interface RainFieldProps {
15
15
  color?: THREE.ColorRepresentation;
16
16
  lightning?: number;
17
17
  timeScale?: number;
18
+ timeSeconds?: number | (() => number);
18
19
  seed?: number;
19
20
  renderOrder?: number;
20
21
  frustumCulled?: boolean;
21
22
  }
22
- export declare function RainField({ count, density, budget, volume, wind, origin, followCamera, speed, length, width, opacity, color, lightning, timeScale, seed, renderOrder, frustumCulled, }: RainFieldProps): import("react").JSX.Element;
23
+ export declare function RainField({ count, density, budget, volume, wind, origin, followCamera, speed, length, width, opacity, color, lightning, timeScale, timeSeconds, seed, renderOrder, frustumCulled, }: RainFieldProps): import("react").JSX.Element;
@@ -4,17 +4,21 @@ import * as THREE from "three";
4
4
  import { useDisposable } from "../render/useDisposable.js";
5
5
  import { createWeatherQuadGeometry } from "./weatherGeometry.js";
6
6
  import { DEFAULT_RAIN_COUNT, DEFAULT_RAIN_DENSITY, resolveWeatherInstanceCount } from "./weatherMath.js";
7
+ import { WEATHER_SHELTER_SHADER } from "./weatherShelter.js";
7
8
  import { useWeatherUniformSet } from "./weatherUniforms.js";
8
9
  const DEFAULT_VOLUME = [56, 42, 56];
9
10
  const DEFAULT_ORIGIN = [0, 0, 0];
10
11
  const DEFAULT_RAIN_COLOR = "#b8c4d8";
11
- export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_DENSITY, budget, volume = DEFAULT_VOLUME, wind, origin = DEFAULT_ORIGIN, followCamera = true, speed = 22, length = 1.35, width = 0.018, opacity = 0.48, color = DEFAULT_RAIN_COLOR, lightning, timeScale, seed = 11939, renderOrder = 10, frustumCulled, }) {
12
+ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_DENSITY, budget, volume = DEFAULT_VOLUME, wind, origin = DEFAULT_ORIGIN, followCamera = true, speed = 22, length = 1.35, width = 0.018, opacity = 0.48, color = DEFAULT_RAIN_COLOR, lightning, timeScale, timeSeconds, seed = 11939, renderOrder = 10, frustumCulled, }) {
12
13
  const { camera } = useThree();
13
- const shared = useWeatherUniformSet({ wind, lightning, timeScale });
14
+ const shared = useWeatherUniformSet({ wind, lightning, timeScale, timeSeconds });
14
15
  const geometry = useDisposable(() => createWeatherQuadGeometry(count, seed), [count, seed]);
15
16
  const material = useDisposable(() => {
16
17
  const uniforms = {
17
18
  uTime: shared.time,
19
+ uShelterCenters: shared.shelterCenters,
20
+ uShelterShapes: shared.shelterShapes,
21
+ uShelterCount: shared.shelterCount,
18
22
  uWind: shared.wind,
19
23
  uLightning: shared.lightning,
20
24
  uAnchor: { value: new THREE.Vector3() },
@@ -31,6 +35,7 @@ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_D
31
35
  depthWrite: false,
32
36
  blending: THREE.NormalBlending,
33
37
  vertexShader: `
38
+ ${WEATHER_SHELTER_SHADER}
34
39
  uniform float uTime;
35
40
  uniform vec3 uWind;
36
41
  uniform vec3 uAnchor;
@@ -42,6 +47,7 @@ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_D
42
47
  attribute vec3 aSpawn;
43
48
  attribute float aDrift;
44
49
 
50
+ varying float vExposure;
45
51
  varying vec2 vUv;
46
52
  varying float vDrift;
47
53
 
@@ -54,6 +60,7 @@ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_D
54
60
  vec3 velocity = vec3(uWind.x, -speed, uWind.z);
55
61
  vec3 local = aSpawn * uVolume + velocity * uTime;
56
62
  vec3 worldCenter = mod(local - origin, uVolume) + origin;
63
+ vExposure = weatherExposure(worldCenter);
57
64
  vec3 direction = normalize(velocity);
58
65
  vec3 cameraRay = normalize(cameraPosition - worldCenter);
59
66
  vec3 sideRaw = cross(direction, cameraRay);
@@ -69,6 +76,7 @@ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_D
69
76
  uniform vec3 uColor;
70
77
  uniform float uLightning;
71
78
 
79
+ varying float vExposure;
72
80
  varying vec2 vUv;
73
81
  varying float vDrift;
74
82
 
@@ -76,6 +84,7 @@ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_D
76
84
  float across = smoothstep(0.0, 0.45, vUv.x) * smoothstep(1.0, 0.55, vUv.x);
77
85
  float along = smoothstep(0.0, 0.28, vUv.y) * smoothstep(1.0, 0.58, vUv.y);
78
86
  float alpha = across * along * uOpacity * (0.55 + 0.45 * vDrift);
87
+ alpha *= vExposure;
79
88
  if (alpha < 0.001) discard;
80
89
  vec3 litColor = uColor * (1.0 + uLightning * 2.25);
81
90
  gl_FragColor = vec4(litColor, alpha);
@@ -97,7 +106,12 @@ export function RainField({ count = DEFAULT_RAIN_COUNT, density = DEFAULT_RAIN_D
97
106
  uniforms.uWidth.value = width;
98
107
  uniforms.uOpacity.value = opacity;
99
108
  uniforms.uColor.value.set(color);
100
- geometry.instanceCount = resolveWeatherInstanceCount(count, density, budget);
109
+ geometry.instanceCount = resolveWeatherInstanceCount(count, density * shared.rain.value, budget);
110
+ const metrics = shared.metrics?.rain;
111
+ if (metrics !== undefined) {
112
+ metrics.count = geometry.instanceCount;
113
+ metrics.capacity = geometry.getAttribute("aSpawn").count;
114
+ }
101
115
  });
102
116
  return (_jsx("mesh", { geometry: geometry, material: material, frustumCulled: frustumCulled ?? !followCamera, renderOrder: renderOrder }));
103
117
  }
@@ -0,0 +1,16 @@
1
+ import * as THREE from "three";
2
+ /** Bounded ripple pool with terrain height and sky exposure query adapters. */
3
+ export interface RainImpactFieldProps {
4
+ /** Fixed splash pool, clamped to 256. Default 64. */
5
+ count?: number;
6
+ extent?: number;
7
+ heightAt: (x: number, z: number) => number;
8
+ /** Sky exposure 0..1; sheltered surfaces produce no splashes. */
9
+ exposureAt?: (x: number, y: number, z: number) => number;
10
+ seed?: number;
11
+ color?: THREE.ColorRepresentation;
12
+ }
13
+ /** Bounded ground ripples sharing precipitation intensity and authoritative animation time.
14
+ * @capability rain-ground-ripples Render bounded rain impacts on exposed terrain using the shared precipitation clock.
15
+ */
16
+ export declare function RainImpactField({ count, extent, heightAt, exposureAt, seed, color }: RainImpactFieldProps): import("react").JSX.Element;
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useFrame } from "@react-three/fiber";
3
+ import * as THREE from "three";
4
+ import { useDisposable } from "../render/useDisposable.js";
5
+ import { createWeatherQuadGeometry } from "./weatherGeometry.js";
6
+ import { useWeatherUniformSet } from "./weatherUniforms.js";
7
+ /** Bounded ground ripples sharing precipitation intensity and authoritative animation time.
8
+ * @capability rain-ground-ripples Render bounded rain impacts on exposed terrain using the shared precipitation clock.
9
+ */
10
+ export function RainImpactField({ count = 64, extent = 48, heightAt, exposureAt, seed = 11939, color = "#b8c4d8" }) {
11
+ const capacity = Math.max(0, Math.min(256, Math.floor(Number.isFinite(count) ? count : 64)));
12
+ const size = Math.max(1, Number.isFinite(extent) ? extent : 48);
13
+ const shared = useWeatherUniformSet();
14
+ const geometry = useDisposable(() => {
15
+ const value = createWeatherQuadGeometry(capacity, seed);
16
+ value.setAttribute("aGround", new THREE.InstancedBufferAttribute(new Float32Array(capacity), 1));
17
+ value.setAttribute("aExposure", new THREE.InstancedBufferAttribute(new Float32Array(capacity), 1));
18
+ value.instanceCount = capacity;
19
+ return value;
20
+ }, [capacity, seed]);
21
+ const material = useDisposable(() => new THREE.ShaderMaterial({
22
+ transparent: true,
23
+ side: THREE.DoubleSide,
24
+ depthWrite: false,
25
+ uniforms: { uTime: shared.time, uRain: shared.rain, uAnchor: { value: new THREE.Vector2() }, uExtent: { value: size }, uColor: { value: new THREE.Color(color) } },
26
+ vertexShader: `
27
+ uniform float uTime;
28
+ uniform float uExtent;
29
+ uniform vec2 uAnchor;
30
+ attribute vec3 aSpawn;
31
+ attribute float aDrift;
32
+ attribute float aGround;
33
+ attribute float aExposure;
34
+ varying vec2 vUv;
35
+ varying float vPhase;
36
+ varying float vExposure;
37
+ void main() {
38
+ vUv = uv;
39
+ vPhase = fract(uTime * (1.6 + aDrift * 0.8) + aDrift);
40
+ vExposure = aExposure;
41
+ float radius = 0.08 + vPhase * 0.45;
42
+ vec2 center = uAnchor + (aSpawn.xz - 0.5) * uExtent;
43
+ vec3 world = vec3(center.x + position.x * radius, aGround + 0.015, center.y + position.y * radius);
44
+ gl_Position = projectionMatrix * viewMatrix * vec4(world, 1.0);
45
+ }
46
+ `,
47
+ fragmentShader: `
48
+ uniform float uRain;
49
+ uniform vec3 uColor;
50
+ varying vec2 vUv;
51
+ varying float vPhase;
52
+ varying float vExposure;
53
+ void main() {
54
+ float radius = length(vUv - 0.5) * 2.0;
55
+ float ring = smoothstep(0.65, 0.8, radius) * (1.0 - smoothstep(0.84, 1.0, radius));
56
+ float alpha = ring * (1.0 - vPhase) * min(1.0, uRain) * vExposure * 0.45;
57
+ if (alpha < 0.001) discard;
58
+ gl_FragColor = vec4(uColor, alpha);
59
+ }
60
+ `,
61
+ }), [shared, size, color]);
62
+ useFrame((state) => {
63
+ const anchorX = Math.round(state.camera.position.x / 8) * 8;
64
+ const anchorZ = Math.round(state.camera.position.z / 8) * 8;
65
+ material.uniforms.uAnchor.value.set(anchorX, anchorZ);
66
+ const spawn = geometry.getAttribute("aSpawn");
67
+ const ground = geometry.getAttribute("aGround");
68
+ const exposure = geometry.getAttribute("aExposure");
69
+ for (let i = 0; i < capacity; i += 1) {
70
+ const x = anchorX + (spawn.getX(i) - 0.5) * size;
71
+ const z = anchorZ + (spawn.getZ(i) - 0.5) * size;
72
+ const y = heightAt(x, z);
73
+ ground.setX(i, Number.isFinite(y) ? y : 0);
74
+ const open = exposureAt?.(x, y, z) ?? 1;
75
+ exposure.setX(i, Math.max(0, Math.min(1, Number.isFinite(open) ? open : 0)));
76
+ }
77
+ ground.needsUpdate = true;
78
+ exposure.needsUpdate = true;
79
+ const metrics = shared.metrics?.impacts;
80
+ if (metrics !== undefined) {
81
+ metrics.count = geometry.instanceCount;
82
+ metrics.capacity = geometry.getAttribute("aSpawn").count;
83
+ metrics.heightQueries = capacity;
84
+ metrics.exposureQueries = exposureAt === undefined ? 0 : capacity;
85
+ metrics.queryBudget = capacity * (exposureAt === undefined ? 1 : 2);
86
+ }
87
+ });
88
+ return _jsx("mesh", { geometry: geometry, material: material, frustumCulled: false, renderOrder: 9 });
89
+ }
@@ -14,8 +14,9 @@ export interface SnowFieldProps {
14
14
  opacity?: number;
15
15
  color?: THREE.ColorRepresentation;
16
16
  timeScale?: number;
17
+ timeSeconds?: number | (() => number);
17
18
  seed?: number;
18
19
  renderOrder?: number;
19
20
  frustumCulled?: boolean;
20
21
  }
21
- export declare function SnowField({ count, density, budget, volume, wind, origin, followCamera, speed, size, sway, opacity, color, timeScale, seed, renderOrder, frustumCulled, }: SnowFieldProps): import("react").JSX.Element;
22
+ export declare function SnowField({ count, density, budget, volume, wind, origin, followCamera, speed, size, sway, opacity, color, timeScale, timeSeconds, seed, renderOrder, frustumCulled, }: SnowFieldProps): import("react").JSX.Element;
@@ -4,17 +4,21 @@ import * as THREE from "three";
4
4
  import { useDisposable } from "../render/useDisposable.js";
5
5
  import { createWeatherQuadGeometry } from "./weatherGeometry.js";
6
6
  import { DEFAULT_SNOW_COUNT, DEFAULT_SNOW_DENSITY, resolveWeatherInstanceCount } from "./weatherMath.js";
7
+ import { WEATHER_SHELTER_SHADER } from "./weatherShelter.js";
7
8
  import { useWeatherUniformSet } from "./weatherUniforms.js";
8
9
  const DEFAULT_VOLUME = [52, 38, 52];
9
10
  const DEFAULT_ORIGIN = [0, 0, 0];
10
11
  const DEFAULT_SNOW_COLOR = "#ffffff";
11
- export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_DENSITY, budget, volume = DEFAULT_VOLUME, wind, origin = DEFAULT_ORIGIN, followCamera = true, speed = 3.2, size = 0.11, sway = 0.62, opacity = 0.86, color = DEFAULT_SNOW_COLOR, timeScale, seed = 72931, renderOrder = 11, frustumCulled, }) {
12
+ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_DENSITY, budget, volume = DEFAULT_VOLUME, wind, origin = DEFAULT_ORIGIN, followCamera = true, speed = 3.2, size = 0.11, sway = 0.62, opacity = 0.86, color = DEFAULT_SNOW_COLOR, timeScale, timeSeconds, seed = 72931, renderOrder = 11, frustumCulled, }) {
12
13
  const { camera } = useThree();
13
- const shared = useWeatherUniformSet({ wind, timeScale });
14
+ const shared = useWeatherUniformSet({ wind, timeScale, timeSeconds });
14
15
  const geometry = useDisposable(() => createWeatherQuadGeometry(count, seed), [count, seed]);
15
16
  const material = useDisposable(() => {
16
17
  const uniforms = {
17
18
  uTime: shared.time,
19
+ uShelterCenters: shared.shelterCenters,
20
+ uShelterShapes: shared.shelterShapes,
21
+ uShelterCount: shared.shelterCount,
18
22
  uWind: shared.wind,
19
23
  uAnchor: { value: new THREE.Vector3() },
20
24
  uVolume: { value: new THREE.Vector3() },
@@ -30,6 +34,7 @@ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_D
30
34
  depthWrite: false,
31
35
  blending: THREE.NormalBlending,
32
36
  vertexShader: `
37
+ ${WEATHER_SHELTER_SHADER}
33
38
  uniform float uTime;
34
39
  uniform vec3 uWind;
35
40
  uniform vec3 uAnchor;
@@ -41,6 +46,7 @@ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_D
41
46
  attribute vec3 aSpawn;
42
47
  attribute float aDrift;
43
48
 
49
+ varying float vExposure;
44
50
  varying vec2 vUv;
45
51
  varying float vDrift;
46
52
 
@@ -58,6 +64,7 @@ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_D
58
64
  ) * uSway * (0.45 + 0.55 * aDrift);
59
65
  vec3 local = aSpawn * uVolume + vec3(uWind.x, -fallSpeed, uWind.z) * uTime + wander;
60
66
  vec3 worldCenter = mod(local - origin, uVolume) + origin;
67
+ vExposure = weatherExposure(worldCenter);
61
68
  float flakeSize = uSize * (0.48 + 1.08 * aDrift);
62
69
  vec3 right = vec3(viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0]);
63
70
  vec3 up = vec3(viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1]);
@@ -70,6 +77,7 @@ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_D
70
77
  uniform float uOpacity;
71
78
  uniform vec3 uColor;
72
79
 
80
+ varying float vExposure;
73
81
  varying vec2 vUv;
74
82
  varying float vDrift;
75
83
 
@@ -78,6 +86,7 @@ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_D
78
86
  float disc = smoothstep(1.0, 0.12, distanceFromCenter);
79
87
  float core = smoothstep(0.54, 0.0, distanceFromCenter) * 0.42;
80
88
  float alpha = (disc + core) * uOpacity * (0.56 + 0.44 * vDrift);
89
+ alpha *= vExposure;
81
90
  if (alpha < 0.001) discard;
82
91
  gl_FragColor = vec4(uColor, alpha);
83
92
  }
@@ -98,7 +107,12 @@ export function SnowField({ count = DEFAULT_SNOW_COUNT, density = DEFAULT_SNOW_D
98
107
  uniforms.uSway.value = sway;
99
108
  uniforms.uOpacity.value = opacity;
100
109
  uniforms.uColor.value.set(color);
101
- geometry.instanceCount = resolveWeatherInstanceCount(count, density, budget);
110
+ geometry.instanceCount = resolveWeatherInstanceCount(count, density * shared.snow.value, budget);
111
+ const metrics = shared.metrics?.snow;
112
+ if (metrics !== undefined) {
113
+ metrics.count = geometry.instanceCount;
114
+ metrics.capacity = geometry.getAttribute("aSpawn").count;
115
+ }
102
116
  });
103
117
  return (_jsx("mesh", { geometry: geometry, material: material, frustumCulled: frustumCulled ?? !followCamera, renderOrder: renderOrder }));
104
118
  }
@@ -1,8 +1,11 @@
1
1
  import type { ReactNode } from "react";
2
+ import type { EditorVolume } from "@jgengine/core/editor/types";
3
+ import type { AuthoredWeatherSample } from "@jgengine/core/world/authoredWeather";
2
4
  import { type DustFieldProps } from "./DustField.js";
3
5
  import { type RainFieldProps } from "./RainField.js";
6
+ import { type RainImpactFieldProps } from "./RainImpactField.js";
4
7
  import { type SnowFieldProps } from "./SnowField.js";
5
- import { type WeatherVector } from "./weatherUniforms.js";
8
+ import { type WeatherVector, type WeatherParticleMetrics } from "./weatherUniforms.js";
6
9
  /** `"mixed"` runs rain and snow together; `"dust"` is airborne particulate and composes with either via `dust`. */
7
10
  export type WeatherLayerMode = "clear" | "rain" | "snow" | "mixed" | "dust";
8
11
  export interface WeatherLayerProps {
@@ -11,13 +14,19 @@ export interface WeatherLayerProps {
11
14
  wind?: WeatherVector;
12
15
  lightning?: number;
13
16
  timeScale?: number;
17
+ timeSeconds?: number | (() => number);
18
+ /** Read authored conditions at the camera from the authoritative simulation clock. */
19
+ sample?: (x: number, z: number) => AuthoredWeatherSample;
20
+ shelters?: readonly EditorVolume[];
21
+ metrics?: WeatherParticleMetrics;
14
22
  rain?: Omit<RainFieldProps, "wind" | "lightning" | "timeScale"> | false;
15
23
  snow?: Omit<SnowFieldProps, "wind" | "timeScale"> | false;
16
24
  /** Airborne particulate. Drawn in `"dust"` mode, and alongside rain/snow whenever `dustAlways` is set. */
17
25
  dust?: Omit<DustFieldProps, "wind" | "timeScale"> | false;
18
26
  /** Keep dust in the air in every mode — a world that is dusty whatever else the sky is doing. */
19
27
  dustAlways?: boolean;
28
+ impacts?: RainImpactFieldProps | false;
20
29
  enabled?: boolean;
21
30
  children?: ReactNode;
22
31
  }
23
- export declare function WeatherLayer({ mode, intensity, wind, lightning, timeScale, rain, snow, dust, dustAlways, enabled, children, }: WeatherLayerProps): import("react").JSX.Element | null;
32
+ export declare function WeatherLayer({ mode, intensity, wind, lightning, timeScale, timeSeconds, sample, shelters, metrics, rain, snow, dust, dustAlways, impacts, enabled, children, }: WeatherLayerProps): import("react").JSX.Element | null;
@@ -1,19 +1,43 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { DustField } from "./DustField.js";
3
3
  import { RainField } from "./RainField.js";
4
+ import { RainImpactField } from "./RainImpactField.js";
4
5
  import { SnowField } from "./SnowField.js";
5
6
  import { WeatherUniformProvider } from "./weatherUniforms.js";
7
+ function clearMetrics(metrics, layer) {
8
+ metrics[layer].count = 0;
9
+ metrics[layer].capacity = 0;
10
+ if (layer === "impacts") {
11
+ metrics.impacts.heightQueries = 0;
12
+ metrics.impacts.exposureQueries = 0;
13
+ metrics.impacts.queryBudget = 0;
14
+ }
15
+ }
6
16
  function resolveLayerDensity(value, fallback, intensity) {
7
17
  return (value ?? fallback) * intensity;
8
18
  }
9
- export function WeatherLayer({ mode = "clear", intensity = 1, wind, lightning, timeScale, rain, snow, dust, dustAlways = false, enabled = true, children, }) {
10
- if (!enabled)
19
+ export function WeatherLayer({ mode = "clear", intensity = 1, wind, lightning, timeScale, timeSeconds, sample, shelters, metrics, rain, snow, dust, dustAlways = false, impacts, enabled = true, children, }) {
20
+ if (!enabled) {
21
+ if (metrics !== undefined)
22
+ for (const layer of ["rain", "snow", "dust", "impacts"])
23
+ clearMetrics(metrics, layer);
11
24
  return null;
25
+ }
12
26
  const rainProps = rain === false ? null : (rain ?? {});
13
27
  const snowProps = snow === false ? null : (snow ?? {});
14
- const showRain = rainProps !== null && (mode === "rain" || mode === "mixed");
15
- const showSnow = snowProps !== null && (mode === "snow" || mode === "mixed");
28
+ const showRain = rainProps !== null && (sample !== undefined || mode === "rain" || mode === "mixed");
29
+ const showSnow = snowProps !== null && (sample !== undefined || mode === "snow" || mode === "mixed");
16
30
  const dustProps = dust === false ? null : (dust ?? {});
17
- const showDust = dustProps !== null && (mode === "dust" || dustAlways);
18
- return (_jsxs(WeatherUniformProvider, { wind: wind, lightning: lightning, timeScale: timeScale, children: [showRain ? (_jsx(RainField, { ...rainProps, density: resolveLayerDensity(rainProps.density, 0.45, intensity) })) : null, showSnow ? (_jsx(SnowField, { ...snowProps, density: resolveLayerDensity(snowProps.density, 0.5, intensity) })) : null, showDust ? (_jsx(DustField, { ...dustProps, density: resolveLayerDensity(dustProps.density, 0.4, intensity) })) : null, children] }));
31
+ const showDust = dustProps !== null && (sample !== undefined || mode === "dust" || dustAlways);
32
+ if (metrics !== undefined) {
33
+ if (!showRain)
34
+ clearMetrics(metrics, "rain");
35
+ if (!showSnow)
36
+ clearMetrics(metrics, "snow");
37
+ if (!showDust)
38
+ clearMetrics(metrics, "dust");
39
+ if (!showRain || impacts === undefined || impacts === false)
40
+ clearMetrics(metrics, "impacts");
41
+ }
42
+ return (_jsxs(WeatherUniformProvider, { wind: wind, lightning: lightning, timeScale: timeScale, timeSeconds: timeSeconds, sample: sample, shelters: shelters, metrics: metrics, children: [showRain ? (_jsx(RainField, { ...rainProps, density: resolveLayerDensity(rainProps.density, 0.45, intensity) })) : null, showSnow ? (_jsx(SnowField, { ...snowProps, density: resolveLayerDensity(snowProps.density, 0.5, intensity) })) : null, showDust ? (_jsx(DustField, { ...dustProps, density: resolveLayerDensity(dustProps.density, 0.4, intensity) })) : null, showRain && impacts !== undefined && impacts !== false ? _jsx(RainImpactField, { ...impacts }) : null, children] }));
19
43
  }
@@ -1,4 +1,6 @@
1
1
  export { DustField, type DustFieldProps } from "./DustField.js";
2
+ export { AuthoredWeatherLayer, type AuthoredWeatherLayerProps } from "./AuthoredWeatherLayer.js";
3
+ export { RainImpactField, type RainImpactFieldProps } from "./RainImpactField.js";
2
4
  export { FireSpreadLayer, type FireSpreadLayerProps } from "./FireSpreadLayer.js";
3
5
  export { LightningStrike, type LightningStrikeProps } from "./LightningStrike.js";
4
6
  export { RainField, type RainFieldProps } from "./RainField.js";
@@ -1,4 +1,6 @@
1
1
  export { DustField } from "./DustField.js";
2
+ export { AuthoredWeatherLayer } from "./AuthoredWeatherLayer.js";
3
+ export { RainImpactField } from "./RainImpactField.js";
2
4
  export { FireSpreadLayer } from "./FireSpreadLayer.js";
3
5
  export { LightningStrike } from "./LightningStrike.js";
4
6
  export { RainField } from "./RainField.js";
@@ -16,3 +16,5 @@ export interface WeatherSeedAttributes {
16
16
  }
17
17
  /** @internal */
18
18
  export declare function createWeatherSeedAttributes(maxCount: number, seed: number): WeatherSeedAttributes;
19
+ /** @internal */
20
+ export declare function lightningStrikeEnvelope(timeSeconds: number, startedAt: number, duration: number, seed: number): number;
@@ -40,3 +40,11 @@ export function createWeatherSeedAttributes(maxCount, seed) {
40
40
  }
41
41
  return { spawn, drift };
42
42
  }
43
+ /** @internal */
44
+ export function lightningStrikeEnvelope(timeSeconds, startedAt, duration, seed) {
45
+ const elapsed = timeSeconds - startedAt;
46
+ if (elapsed < 0 || duration <= 0 || elapsed >= duration)
47
+ return 0;
48
+ const flicker = 0.62 + (Math.sin(elapsed * 97 + seed) * 0.5 + 0.5) * 0.38;
49
+ return (1 - elapsed / duration) * flicker;
50
+ }
@@ -0,0 +1,18 @@
1
+ import * as THREE from "three";
2
+ import type { EditorVolume } from "@jgengine/core/editor/types";
3
+ /** Cosmetic roof clipping is bounded independently of authoritative shelter queries. */
4
+ export declare const WEATHER_SHELTER_BUDGET = 32;
5
+ /** Reusable buffers for the nearest authored shelters submitted to weather shaders. */
6
+ export interface WeatherShelterUniforms {
7
+ shelterCenters: THREE.IUniform<THREE.Vector4[]>;
8
+ shelterShapes: THREE.IUniform<THREE.Vector4[]>;
9
+ shelterCount: THREE.IUniform<number>;
10
+ shelterIndices: Int32Array;
11
+ shelterDistances: Float64Array;
12
+ }
13
+ /** @internal */
14
+ export declare function createWeatherShelterUniforms(): WeatherShelterUniforms;
15
+ /** @internal */
16
+ export declare function updateWeatherShelters(uniforms: WeatherShelterUniforms, shelters: readonly EditorVolume[], x: number, y: number, z: number): void;
17
+ /** @internal */
18
+ export declare const WEATHER_SHELTER_SHADER = "\n uniform vec4 uShelterCenters[32];\n uniform vec4 uShelterShapes[32];\n uniform int uShelterCount;\n float weatherExposure(vec3 point) {\n float exposure = 1.0;\n for (int i = 0; i < 32; i++) {\n if (i >= uShelterCount) break;\n vec4 center = uShelterCenters[i];\n vec4 shape = uShelterShapes[i];\n vec3 delta = abs(point - center.xyz);\n bool inside = center.w < 0.5 ? all(lessThanEqual(delta, shape.xyz)) : center.w < 1.5 ? length(delta) <= shape.x : length(delta.xz) <= shape.x && delta.y <= shape.y;\n if (inside) exposure = min(exposure, shape.w);\n }\n return exposure;\n }\n";