@bendyline/molen-client 0.0.4 → 0.0.6

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.
@@ -1,4 +1,4 @@
1
- import { n as CameraPose } from "./renderer-DfWc3MFM.mjs";
1
+ import { n as CameraPose } from "./renderer-DNXUCuIZ.mjs";
2
2
 
3
3
  //#region src/camera-track.d.ts
4
4
  interface CameraTrackKeyframe {
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i as readModelSignals, n as ModelSignals, r as createModelSignalVisual, t as ModelSignalVisual } from "./model-signals-DVlLyP-w.mjs";
2
2
  import { a as createUrlAssetProvider, i as UrlAssetProviderOptions, n as AssetProvider, r as LoadedGltf, t as AssetCache } from "./assets-Bp0ox8YY.mjs";
3
- import { A as AdmissionOptions, C as skyTimeMs, D as SkyReflections, E as SkyReflectionState, M as FrameAdmissionOptions, N as FrameAdmissionQueue, O as createWebGlSkyReflectionFilter, P as SceneAdmission, S as evaluateEarthSky, T as SkyReflectionFilter, _ as SkyVisual, a as RendererBackendPreference, b as CelestialPosition, c as TopDownOrtho, d as GpuFrameTimer, f as GpuFrameTimerOptions, g as SkyStar, h as SkyFrame, i as RendererBackend, j as AdmissionSample, k as reflectionStateFromLights, l as nextWorldOrigin, m as WeatherVisual, n as CameraPose, o as RendererOptions, p as createGpuFrameTimer, r as Renderer, s as ThreeRenderer, t as AutoWorldOriginOptions, u as orthoFrustum, v as SkyVisualOptions, w as starDirection, x as EarthSkyState, y as defaultSkyPalette } from "./renderer-DfWc3MFM.mjs";
3
+ import { A as createWebGlSkyReflectionFilter, C as EarthSkyState, D as SkyReflectionFilter, E as starDirection, F as FrameAdmissionQueue, I as SceneAdmission, M as AdmissionOptions, N as AdmissionSample, O as SkyReflectionState, P as FrameAdmissionOptions, S as CelestialPosition, T as skyTimeMs, _ as SkyFrame, a as RendererBackendPreference, b as SkyVisualOptions, c as TopDownOrtho, d as ShadowFocus, f as ShadowQuality, g as WeatherVisual, h as createGpuFrameTimer, i as RendererBackend, j as reflectionStateFromLights, k as SkyReflections, l as nextWorldOrigin, m as GpuFrameTimerOptions, n as CameraPose, o as RendererOptions, p as GpuFrameTimer, r as Renderer, s as ThreeRenderer, t as AutoWorldOriginOptions, u as orthoFrustum, v as SkyStar, w as evaluateEarthSky, x as defaultSkyPalette, y as SkyVisual } from "./renderer-DNXUCuIZ.mjs";
4
4
  import { a as normalizeInputAxis, i as InputMapOptions, n as InputGamepad, o as resolveAction, r as InputMap, t as InputBindings } from "./input-CD-dHuv0.mjs";
5
5
  import { Command, ControlAction, CustomSkyData, Delta, DiagMessage, EarthObserver, EarthSkyData, EngineEvent, EntityId, JsonObject, JsonValue, Keyframe, MessageLink, ModelSignalSpec, Quat, ResolvedWeather, SceneCamera, SceneInput, SceneManifest, SkyAppearance, SkyBodyData, SkyData, SkyData as SkyData$1, SkyPalette, SkyTime, Vec3, WeatherData, WeatherProfile, resolveWeather, weatherProfile } from "@bendyline/molen-schema";
6
6
  import * as THREE from "three";
@@ -849,4 +849,4 @@ declare const defaultEnvironment: EnvironmentData;
849
849
  */
850
850
  declare function applyEnvironment(renderer: Renderer, env: EnvironmentData): void;
851
851
  //#endregion
852
- export { type AdaptiveQualityChange, AdaptiveQualityController, type AdaptiveQualityOptions, type AdaptiveQualityReason, type AdaptiveQualitySample, type AdaptiveQualityStats, type AdmissionOptions, type AdmissionSample, AssetCache, type AssetOptions, type AssetProvider, type AutoWorldOriginOptions, type CameraPose, type CameraTarget, type CelestialPosition, type ClientCore, type ClientCoreOptions, type ClientDiagCode, type ClientError, type ClientOptions, type CustomSkyData, type DecoderConfig, type EarthObserver, type EarthSkyData, type EarthSkyState, type EnvironmentData, type FrameAdmissionOptions, FrameAdmissionQueue, type GpuFrameTimer, type GpuFrameTimerOptions, type InputBindings, type InputGamepad, InputMap, type InputMapOptions, type InputRuleOptions, type InterpTransform, InterpolationBuffer, type KindContext, type KindHandle, type KindView, type LightData, type LoadedGltf, MaterialResolver, type MirrorReader, type ModelSignalVisual, type ModelSignals, type MolenClient, type MountExperienceOptions, type MountedExperience, type Renderable, type RenderableKind, Renderer, type RendererBackend, type RendererBackendPreference, type RendererOptions, type ResolvedWeather, type SceneAdmission, type SceneBackend, SceneMirror, type SceneOptimizationOptions, type SkyAppearance, type SkyBodyData, type SkyData, type SkyFrame, type SkyPalette, type SkyReflectionFilter, type SkyReflectionState, SkyReflections, type SkyStar, type SkyTime, SkyVisual, type SkyVisualOptions, type StarCatalogRow, type StaticBatchOptions, THREE, type ThreeRenderer, ThreeSceneBackend, type TopDownOrtho, type Unsubscribe, type UrlAssetProviderOptions, type WeatherData, type WeatherProfile, WeatherVisual, applyEnvironment, applyInputRules, applySceneCamera, computeClipTime, createClient, createClientCore, createGltfLoader, createGpuFrameTimer, createIndexedDbMaterialStore, createModelSignalVisual, createSnapshotViewer, createUrlAssetProvider, createViewer, createWebGlSkyReflectionFilter, decodeStarCatalog, decodeStarCatalogRows, defaultEnvironment, defaultSkyPalette, encodeStarCatalog, evaluateEarthSky, followCameraPose, lerp3, localCommand, materialFromBaked, mountExperience, nextWorldOrigin, nlerp4, normalizeInputAxis, orthoFrustum, readModelSignals, reflectionStateFromLights, resolveAction, resolveWeather, skyTimeMs, starDirection, weatherProfile };
852
+ export { type AdaptiveQualityChange, AdaptiveQualityController, type AdaptiveQualityOptions, type AdaptiveQualityReason, type AdaptiveQualitySample, type AdaptiveQualityStats, type AdmissionOptions, type AdmissionSample, AssetCache, type AssetOptions, type AssetProvider, type AutoWorldOriginOptions, type CameraPose, type CameraTarget, type CelestialPosition, type ClientCore, type ClientCoreOptions, type ClientDiagCode, type ClientError, type ClientOptions, type CustomSkyData, type DecoderConfig, type EarthObserver, type EarthSkyData, type EarthSkyState, type EnvironmentData, type FrameAdmissionOptions, FrameAdmissionQueue, type GpuFrameTimer, type GpuFrameTimerOptions, type InputBindings, type InputGamepad, InputMap, type InputMapOptions, type InputRuleOptions, type InterpTransform, InterpolationBuffer, type KindContext, type KindHandle, type KindView, type LightData, type LoadedGltf, MaterialResolver, type MirrorReader, type ModelSignalVisual, type ModelSignals, type MolenClient, type MountExperienceOptions, type MountedExperience, type Renderable, type RenderableKind, Renderer, type RendererBackend, type RendererBackendPreference, type RendererOptions, type ResolvedWeather, type SceneAdmission, type SceneBackend, SceneMirror, type SceneOptimizationOptions, type ShadowFocus, type ShadowQuality, type SkyAppearance, type SkyBodyData, type SkyData, type SkyFrame, type SkyPalette, type SkyReflectionFilter, type SkyReflectionState, SkyReflections, type SkyStar, type SkyTime, SkyVisual, type SkyVisualOptions, type StarCatalogRow, type StaticBatchOptions, THREE, type ThreeRenderer, ThreeSceneBackend, type TopDownOrtho, type Unsubscribe, type UrlAssetProviderOptions, type WeatherData, type WeatherProfile, WeatherVisual, applyEnvironment, applyInputRules, applySceneCamera, computeClipTime, createClient, createClientCore, createGltfLoader, createGpuFrameTimer, createIndexedDbMaterialStore, createModelSignalVisual, createSnapshotViewer, createUrlAssetProvider, createViewer, createWebGlSkyReflectionFilter, decodeStarCatalog, decodeStarCatalogRows, defaultEnvironment, defaultSkyPalette, encodeStarCatalog, evaluateEarthSky, followCameraPose, lerp3, localCommand, materialFromBaked, mountExperience, nextWorldOrigin, nlerp4, normalizeInputAxis, orthoFrustum, readModelSignals, reflectionStateFromLights, resolveAction, resolveWeather, skyTimeMs, starDirection, weatherProfile };
package/dist/index.mjs CHANGED
@@ -1087,7 +1087,7 @@ const RIG_NAME = "$environment";
1087
1087
  function findEnvironmentRig(scene) {
1088
1088
  return scene.children.find((child) => child.name === RIG_NAME);
1089
1089
  }
1090
- const SHADOW_MAP_SIZE = {
1090
+ const SHADOW_MAP_SIZE$1 = {
1091
1091
  low: 1024,
1092
1092
  medium: 2048,
1093
1093
  high: 4096
@@ -1121,9 +1121,12 @@ function applyEnvironment(renderer, env) {
1121
1121
  7
1122
1122
  ];
1123
1123
  dir.position.set(d[0], d[1], d[2]);
1124
+ dir.userData.molenSun = true;
1125
+ dir.userData.molenSunDirection = new THREE.Vector3(d[0], d[1], d[2]).normalize();
1126
+ rig.add(dir.target);
1124
1127
  if (shadows !== "off" && sun.castShadow === true) {
1125
1128
  dir.castShadow = true;
1126
- const size = SHADOW_MAP_SIZE[shadows];
1129
+ const size = SHADOW_MAP_SIZE$1[shadows];
1127
1130
  dir.shadow.mapSize.set(size, size);
1128
1131
  dir.shadow.camera.near = .5;
1129
1132
  dir.shadow.camera.far = 500;
@@ -1167,6 +1170,7 @@ function textureFrom(image, filter, srgb) {
1167
1170
  /** Upload a BakedMaterial's slots onto a MeshStandardMaterial. */
1168
1171
  function materialFromBaked(baked) {
1169
1172
  for (const image of Object.values(baked.slots)) if (image !== void 0) validateImage(image);
1173
+ if (baked.meta.alphaCoverage && (baked.meta.alphaTest !== void 0 || !baked.slots.baseColor)) throw new Error("alphaCoverage requires baseColor and cannot be combined with alphaTest");
1170
1174
  const material = new THREE.MeshStandardMaterial({
1171
1175
  roughness: 1,
1172
1176
  metalness: 1
@@ -1197,6 +1201,24 @@ function materialFromBaked(baked) {
1197
1201
  material.alphaTest = baked.meta.alphaTest;
1198
1202
  material.transparent = false;
1199
1203
  }
1204
+ if (baked.meta.alphaCoverage) {
1205
+ material.alphaTest = 0;
1206
+ material.transparent = true;
1207
+ material.depthWrite = false;
1208
+ for (const texture of [
1209
+ material.map,
1210
+ material.normalMap,
1211
+ material.roughnessMap,
1212
+ material.metalnessMap,
1213
+ material.emissiveMap,
1214
+ material.aoMap
1215
+ ]) {
1216
+ if (!texture || texture.magFilter === THREE.NearestFilter) continue;
1217
+ texture.generateMipmaps = true;
1218
+ texture.minFilter = THREE.LinearMipmapLinearFilter;
1219
+ texture.needsUpdate = true;
1220
+ }
1221
+ }
1200
1222
  return material;
1201
1223
  }
1202
1224
  const GREY = "#cccccc";
@@ -3254,6 +3276,53 @@ function createGpuFrameTimer(context, options = {}) {
3254
3276
  };
3255
3277
  }
3256
3278
  //#endregion
3279
+ //#region src/three/shadow-focus.ts
3280
+ const SHADOW_MAP_SIZE = {
3281
+ low: 1024,
3282
+ medium: 2048,
3283
+ high: 4096
3284
+ };
3285
+ const UP = new THREE.Vector3(0, 1, 0);
3286
+ const scratchCenter = new THREE.Vector3();
3287
+ const scratchRight = new THREE.Vector3();
3288
+ const scratchUp = new THREE.Vector3();
3289
+ const scratchForward = new THREE.Vector3();
3290
+ /**
3291
+ * Aim `light`'s shadow at `center` (scene coordinates, after rebasing) from `direction` (a unit
3292
+ * vector toward the sun), covering ±`radius`. The light and its target move; the direction of
3293
+ * the light is unchanged.
3294
+ */
3295
+ function focusDirectionalShadow(light, direction, center, radius) {
3296
+ const toSun = scratchForward.copy(direction).normalize();
3297
+ const size = light.shadow.mapSize.x || 2048;
3298
+ const texel = 2 * radius / size;
3299
+ const right = scratchRight.crossVectors(Math.abs(toSun.y) > .999 ? new THREE.Vector3(1, 0, 0) : UP, toSun);
3300
+ right.normalize();
3301
+ const up = scratchUp.crossVectors(toSun, right).normalize();
3302
+ const snapped = scratchCenter.copy(center);
3303
+ const along = snapped.dot(toSun);
3304
+ const x = Math.round(snapped.dot(right) / texel) * texel;
3305
+ const y = Math.round(snapped.dot(up) / texel) * texel;
3306
+ snapped.copy(right).multiplyScalar(x).addScaledVector(up, y).addScaledVector(toSun, along);
3307
+ const distance = radius * 2 + 1e3;
3308
+ light.target.position.copy(snapped);
3309
+ light.position.copy(snapped).addScaledVector(toSun, distance);
3310
+ light.target.updateMatrixWorld();
3311
+ light.updateMatrixWorld();
3312
+ const camera = light.shadow.camera;
3313
+ if (camera.left !== -radius || camera.top !== radius || camera.far !== distance + radius * 2 + 1e3) {
3314
+ camera.left = -radius;
3315
+ camera.right = radius;
3316
+ camera.top = radius;
3317
+ camera.bottom = -radius;
3318
+ camera.near = 1;
3319
+ camera.far = distance + radius * 2 + 1e3;
3320
+ camera.updateProjectionMatrix();
3321
+ }
3322
+ light.shadow.bias = -4e-4;
3323
+ light.shadow.normalBias = texel * 1.2;
3324
+ }
3325
+ //#endregion
3257
3326
  //#region src/three/sky-reflections.ts
3258
3327
  const WIDTH = 256;
3259
3328
  const HEIGHT = 128;
@@ -3514,10 +3583,59 @@ var Renderer = class Renderer {
3514
3583
  drawCalls: 0,
3515
3584
  triangles: 0
3516
3585
  };
3586
+ shadowFocus;
3587
+ shadowCenter = new THREE.Vector3();
3588
+ shadowDirection = new THREE.Vector3();
3517
3589
  /** Active clear-sky visual and sampled ephemeris, when environment.sky is configured. */
3518
3590
  get sky() {
3519
3591
  return this.activeSky;
3520
3592
  }
3593
+ /**
3594
+ * Aim the sun's shadow at a focus (absolute world coordinates) covering ±`radius` meters, or
3595
+ * `undefined` for the environment's own fixed box. Call whenever what the camera frames
3596
+ * moves: an orbit target, a walker, a car. Shadows must be on (`setShadowQuality`).
3597
+ */
3598
+ setShadowFocus(focus) {
3599
+ if (focus !== void 0 && (!(focus.radius > 0) || !Number.isFinite(focus.radius))) throw new RangeError("Shadow focus radius must be a positive number of meters");
3600
+ this.shadowFocus = focus === void 0 ? void 0 : {
3601
+ center: [...focus.center],
3602
+ radius: focus.radius
3603
+ };
3604
+ }
3605
+ /** Turn sun shadows on at a map resolution, or off, without rebuilding the environment. */
3606
+ setShadowQuality(quality) {
3607
+ const enabled = quality !== "off";
3608
+ for (const light of this.sunLights()) {
3609
+ light.castShadow = enabled;
3610
+ if (!enabled) continue;
3611
+ const size = SHADOW_MAP_SIZE[quality];
3612
+ if (light.shadow.mapSize.x !== size) {
3613
+ light.shadow.mapSize.set(size, size);
3614
+ light.shadow.map?.dispose();
3615
+ light.shadow.map = null;
3616
+ }
3617
+ }
3618
+ this.three.shadowMap.enabled = enabled;
3619
+ this.three.shadowMap.type = quality === "low" ? THREE.PCFShadowMap : THREE.PCFSoftShadowMap;
3620
+ }
3621
+ /** The directional lights standing for the sun: the environment rig's, and the sky's. */
3622
+ sunLights() {
3623
+ const lights = [];
3624
+ findEnvironmentRig(this.scene)?.traverse((object) => {
3625
+ if (object instanceof THREE.DirectionalLight && object.userData.molenSun === true) lights.push(object);
3626
+ });
3627
+ if (this.activeSky) lights.push(this.activeSky.sunLight);
3628
+ return lights;
3629
+ }
3630
+ applyShadowFocus() {
3631
+ const focus = this.shadowFocus;
3632
+ if (focus === void 0 || !this.three.shadowMap.enabled) return;
3633
+ const center = this.shadowCenter.set(focus.center[0] - this.worldOrigin[0], focus.center[1] - this.worldOrigin[1], focus.center[2] - this.worldOrigin[2]);
3634
+ for (const light of this.sunLights()) {
3635
+ if (!light.castShadow) continue;
3636
+ focusDirectionalShadow(light, light === this.activeSky?.sunLight ? this.shadowDirection.fromArray(this.activeSky.frame.sunDirection) : this.shadowDirection.copy(light.userData.molenSunDirection), center, focus.radius);
3637
+ }
3638
+ }
3521
3639
  /** Active weather effects; physical weather data is also available in the simulation component. */
3522
3640
  get weather() {
3523
3641
  return this.activeWeather;
@@ -3651,9 +3769,11 @@ var Renderer = class Renderer {
3651
3769
  this.defaultClearColor = new THREE.Color(opts.clearColor ?? "#1a1a20");
3652
3770
  this.three.setClearColor(this.defaultClearColor, 1);
3653
3771
  this.scene = new THREE.Scene();
3772
+ this.scene.matrixAutoUpdate = false;
3654
3773
  this.reflections = opts.reflections === true ? new SkyReflections(this.scene, initialized?.reflectionFilter ?? createWebGlSkyReflectionFilter(this.three)) : void 0;
3655
3774
  this.worldRoot = new THREE.Group();
3656
3775
  this.worldRoot.name = "molen:world-root";
3776
+ this.worldRoot.matrixAutoUpdate = false;
3657
3777
  this.scene.add(this.worldRoot);
3658
3778
  this.aspect = width / height;
3659
3779
  this.camera = new THREE.PerspectiveCamera(60, this.aspect, cameraNear, cameraFar);
@@ -3718,6 +3838,7 @@ var Renderer = class Renderer {
3718
3838
  applyWorldOrigin(origin) {
3719
3839
  this.worldOrigin = [...origin];
3720
3840
  this.worldRoot.position.set(-origin[0], -origin[1], -origin[2]);
3841
+ this.worldRoot.updateMatrix();
3721
3842
  }
3722
3843
  /** Switch to a top-down orthographic camera looking straight down at a world point. */
3723
3844
  setTopDownOrtho(opts) {
@@ -4128,6 +4249,7 @@ var Renderer = class Renderer {
4128
4249
  if (sky) {
4129
4250
  sky.update(this.environmentTimeOverride ?? this.environmentSeconds);
4130
4251
  sky.prepareCamera(this.camera);
4252
+ this.applyShadowFocus();
4131
4253
  const autoClear = this.three.autoClear;
4132
4254
  const autoReset = this.three.info.autoReset;
4133
4255
  this.three.info.reset();
@@ -4140,7 +4262,10 @@ var Renderer = class Renderer {
4140
4262
  this.three.autoClear = autoClear;
4141
4263
  this.three.info.autoReset = autoReset;
4142
4264
  }
4143
- } else this.renderScene();
4265
+ } else {
4266
+ this.applyShadowFocus();
4267
+ this.renderScene();
4268
+ }
4144
4269
  const info = this.three.info.render;
4145
4270
  this.lastRenderStats.drawCalls = "drawCalls" in info ? info.drawCalls : info.calls;
4146
4271
  this.lastRenderStats.triangles = info.triangles;
@@ -74,12 +74,16 @@ interface MarkerLayerOptions {
74
74
  hideUntilGrounded?: boolean;
75
75
  /**
76
76
  * Hide markers whose on-screen footprints overlap a more important one: higher `priority`
77
- * first, then markers already shown (so pins do not flicker as the camera moves), then the
78
- * nearest. `padding` adds CSS pixels around each footprint (default 4). Off by default.
77
+ * first, then markers already shown, then the nearest. A shown marker keeps its place until
78
+ * the inner part of its footprint is covered, so pins do not flicker as the camera moves; a
79
+ * newcomer needs its whole footprint clear. `padding` adds CSS pixels around each footprint
80
+ * (default 4). Off by default.
79
81
  */
80
82
  declutter?: boolean | {
81
83
  padding?: number;
82
84
  };
85
+ /** Milliseconds a marker takes to fade in or out as it is shown or hidden (default 180; 0 pops). */
86
+ fadeMs?: number;
83
87
  renderOrder?: number;
84
88
  }
85
89
  interface MarkerScreenPosition {
@@ -107,6 +111,7 @@ declare class MarkerLayer {
107
111
  private readonly loader;
108
112
  private visible;
109
113
  private disposed;
114
+ private lastUpdateMs;
110
115
  constructor(host: MarkerHost, options?: MarkerLayerOptions);
111
116
  /** Replace the marker set. Markers are matched by id, so unchanged images are not reloaded. */
112
117
  set(markers: readonly MarkerSpec[]): void;
package/dist/markers.mjs CHANGED
@@ -68,6 +68,8 @@ function composeMarkerImage(image, style = {}) {
68
68
  }
69
69
  //#endregion
70
70
  //#region src/markers/marker-layer.ts
71
+ /** Share of a shown marker's footprint, per side, that others may cover before it yields. */
72
+ const DECLUTTER_KEEP_INSET = .2;
71
73
  const scratch = new THREE.Vector3();
72
74
  const viewSpace = new THREE.Vector3();
73
75
  /**
@@ -107,6 +109,7 @@ var MarkerLayer = class {
107
109
  loader = new THREE.TextureLoader();
108
110
  visible = true;
109
111
  disposed = false;
112
+ lastUpdateMs;
110
113
  constructor(host, options = {}) {
111
114
  this.host = host;
112
115
  this.options = options;
@@ -150,6 +153,11 @@ var MarkerLayer = class {
150
153
  if (this.disposed) return;
151
154
  const [, viewportHeight] = this.host.getViewportSize();
152
155
  const perPixel = this.worldPerPixel(viewportHeight);
156
+ const nowMs = performance.now();
157
+ const elapsedMs = this.lastUpdateMs === void 0 ? Number.POSITIVE_INFINITY : nowMs - this.lastUpdateMs;
158
+ this.lastUpdateMs = nowMs;
159
+ const fadeMs = this.options.fadeMs ?? 180;
160
+ const fadeStep = fadeMs > 0 ? elapsedMs / fadeMs : Number.POSITIVE_INFINITY;
153
161
  const hideUntilGrounded = this.options.hideUntilGrounded ?? true;
154
162
  const candidates = [];
155
163
  for (const entry of this.entries.values()) {
@@ -161,7 +169,11 @@ var MarkerLayer = class {
161
169
  y = entry.groundY === void 0 ? hideUntilGrounded ? void 0 : spec.elevation ?? 0 : entry.groundY + (spec.elevation ?? 0);
162
170
  }
163
171
  entry.sprite.visible = false;
164
- if (y === void 0 || !this.visible) continue;
172
+ if (y === void 0 || !this.visible) {
173
+ entry.presence = 0;
174
+ entry.shown = false;
175
+ continue;
176
+ }
165
177
  entry.sprite.position.set(spec.x, y, spec.z);
166
178
  entry.distance = Math.hypot(spec.x - cameraPosition[0], y - cameraPosition[1], spec.z - cameraPosition[2]);
167
179
  candidates.push(entry);
@@ -175,12 +187,12 @@ var MarkerLayer = class {
175
187
  const taken = [];
176
188
  let drawn = 0;
177
189
  for (const entry of candidates) {
190
+ const wasShown = entry.shown;
178
191
  entry.shown = false;
179
- if (drawn >= budget) continue;
180
192
  const opacity = fade === void 0 ? 1 : Math.max(0, Math.min(1, (fade.far - entry.distance) / (fade.far - fade.near)));
181
- if (opacity <= 0) continue;
182
193
  const size = entry.spec.size ?? 56;
183
- if (project !== void 0) {
194
+ let chosen = drawn < budget && opacity > 0;
195
+ if (chosen && project !== void 0) {
184
196
  const screen = project(entry.sprite.position);
185
197
  if (screen !== void 0) {
186
198
  const width = size * entry.aspect;
@@ -191,16 +203,27 @@ var MarkerLayer = class {
191
203
  screen[0] + width / 2 + padding,
192
204
  top + size + padding
193
205
  ];
194
- if (taken.some((other) => box[0] < other[2] && box[2] > other[0] && box[1] < other[3] && box[3] > other[1])) continue;
195
- taken.push(box);
206
+ const inset = wasShown ? padding + Math.min(width, size) * DECLUTTER_KEEP_INSET : 0;
207
+ const test = [
208
+ box[0] + inset,
209
+ box[1] + inset,
210
+ box[2] - inset,
211
+ box[3] - inset
212
+ ];
213
+ if (taken.some((other) => test[0] < other[2] && test[2] > other[0] && test[1] < other[3] && test[3] > other[1])) chosen = false;
214
+ else taken.push(box);
196
215
  }
197
216
  }
198
- drawn++;
199
- entry.material.opacity = opacity;
217
+ entry.presence = chosen ? Math.min(1, entry.presence + fadeStep) : Math.max(0, entry.presence - fadeStep);
218
+ if (entry.presence <= 0) continue;
219
+ if (chosen) {
220
+ drawn++;
221
+ entry.shown = true;
222
+ }
223
+ entry.material.opacity = opacity * entry.presence;
200
224
  entry.sprite.scale.set(size * entry.aspect * perPixel, size * perPixel, 1);
201
225
  entry.sprite.center.set(.5, (entry.spec.anchor ?? "bottom") === "bottom" ? 0 : .5);
202
226
  entry.sprite.visible = true;
203
- entry.shown = true;
204
227
  }
205
228
  }
206
229
  /** CSS-pixel projection of rebased sprite positions, set up once per update. */
@@ -221,7 +244,7 @@ var MarkerLayer = class {
221
244
  pick(x, y) {
222
245
  let best;
223
246
  for (const [id, entry] of this.entries) {
224
- if (!entry.sprite.visible) continue;
247
+ if (!entry.sprite.visible || !entry.shown) continue;
225
248
  const p = entry.sprite.position;
226
249
  const screen = projectWorldToScreen(this.host, [
227
250
  p.x,
@@ -257,7 +280,11 @@ var MarkerLayer = class {
257
280
  }
258
281
  setVisible(visible) {
259
282
  this.visible = visible;
260
- if (!visible) for (const entry of this.entries.values()) entry.sprite.visible = false;
283
+ if (!visible) for (const entry of this.entries.values()) {
284
+ entry.sprite.visible = false;
285
+ entry.presence = 0;
286
+ entry.shown = false;
287
+ }
261
288
  }
262
289
  dispose() {
263
290
  if (this.disposed) return;
@@ -288,7 +315,8 @@ var MarkerLayer = class {
288
315
  aspect: imageAspect(spec.image) ?? 1,
289
316
  groundY: void 0,
290
317
  distance: 0,
291
- shown: false
318
+ shown: false,
319
+ presence: 0
292
320
  };
293
321
  entry.texture = this.acquire(spec.image, entry);
294
322
  material.map = entry.texture;
@@ -305,8 +305,8 @@ declare class OrbitController {
305
305
  private current;
306
306
  private flight;
307
307
  private clock;
308
- private readonly minRange;
309
- private readonly maxRange;
308
+ private minRange;
309
+ private maxRange;
310
310
  private readonly minPitch;
311
311
  private readonly maxPitch;
312
312
  private readonly rotateSensitivity;
@@ -317,6 +317,19 @@ declare class OrbitController {
317
317
  get state(): OrbitState;
318
318
  /** Whether a fly-to animation is running. */
319
319
  get flying(): boolean;
320
+ /** The current camera distance limits, meters. */
321
+ get rangeLimits(): {
322
+ minRange: number;
323
+ maxRange: number;
324
+ };
325
+ /**
326
+ * Change the camera distance limits (omitted fields keep their values), for example when the
327
+ * distance a scene can draw changes. A camera beyond the new limits eases back inside them.
328
+ */
329
+ setRangeLimits(limits: {
330
+ minRange?: number;
331
+ maxRange?: number;
332
+ }): void;
320
333
  /** Jump to a framing immediately (fields omitted keep their values). */
321
334
  set(state: Partial<OrbitState>): void;
322
335
  /** Animate to a framing; direct input during the flight cancels it. */
@@ -761,6 +761,26 @@ var OrbitController = class {
761
761
  get flying() {
762
762
  return this.flight !== void 0;
763
763
  }
764
+ /** The current camera distance limits, meters. */
765
+ get rangeLimits() {
766
+ return {
767
+ minRange: this.minRange,
768
+ maxRange: this.maxRange
769
+ };
770
+ }
771
+ /**
772
+ * Change the camera distance limits (omitted fields keep their values), for example when the
773
+ * distance a scene can draw changes. A camera beyond the new limits eases back inside them.
774
+ */
775
+ setRangeLimits(limits) {
776
+ const minRange = limits.minRange ?? this.minRange;
777
+ const maxRange = limits.maxRange ?? this.maxRange;
778
+ if (!(minRange > 0) || !Number.isFinite(minRange) || !(maxRange >= minRange)) throw new RangeError("Orbit range limits need 0 < minRange <= maxRange");
779
+ this.minRange = minRange;
780
+ this.maxRange = maxRange;
781
+ this.goal = this.clamp(this.goal);
782
+ if (this.flight !== void 0) this.flight.to = this.clamp(this.flight.to);
783
+ }
764
784
  /** Jump to a framing immediately (fields omitted keep their values). */
765
785
  set(state) {
766
786
  this.flight = void 0;
@@ -276,6 +276,15 @@ interface GpuFrameTimer {
276
276
  */
277
277
  declare function createGpuFrameTimer(context: WebGLRenderingContext | WebGL2RenderingContext, options?: GpuFrameTimerOptions): GpuFrameTimer | undefined;
278
278
  //#endregion
279
+ //#region src/three/shadow-focus.d.ts
280
+ type ShadowQuality = "off" | "low" | "medium" | "high";
281
+ interface ShadowFocus {
282
+ /** Focus point in absolute world coordinates (before any floating-origin rebase). */
283
+ center: readonly [number, number, number];
284
+ /** Half-width of the shadowed square around the focus, meters. */
285
+ radius: number;
286
+ }
287
+ //#endregion
279
288
  //#region src/three/webgpu-scene-optimizer.d.ts
280
289
  /**
281
290
  * Uses Three render bundles and a pinned, version-aware instance upload adapter.
@@ -458,8 +467,22 @@ declare class Renderer {
458
467
  private environmentSeconds;
459
468
  private environmentTimeOverride;
460
469
  private readonly lastRenderStats;
470
+ private shadowFocus;
471
+ private readonly shadowCenter;
472
+ private readonly shadowDirection;
461
473
  /** Active clear-sky visual and sampled ephemeris, when environment.sky is configured. */
462
474
  get sky(): SkyVisual | undefined;
475
+ /**
476
+ * Aim the sun's shadow at a focus (absolute world coordinates) covering ±`radius` meters, or
477
+ * `undefined` for the environment's own fixed box. Call whenever what the camera frames
478
+ * moves: an orbit target, a walker, a car. Shadows must be on (`setShadowQuality`).
479
+ */
480
+ setShadowFocus(focus: ShadowFocus | undefined): void;
481
+ /** Turn sun shadows on at a map resolution, or off, without rebuilding the environment. */
482
+ setShadowQuality(quality: ShadowQuality): void;
483
+ /** The directional lights standing for the sun: the environment rig's, and the sky's. */
484
+ private sunLights;
485
+ private applyShadowFocus;
463
486
  /** Active weather effects; physical weather data is also available in the simulation component. */
464
487
  get weather(): WeatherVisual | undefined;
465
488
  /** Apply the singleton weather component without rebuilding the sky or moving the camera. */
@@ -549,4 +572,4 @@ declare class Renderer {
549
572
  dispose(): void;
550
573
  }
551
574
  //#endregion
552
- export { AdmissionOptions as A, skyTimeMs as C, SkyReflections as D, SkyReflectionState as E, FrameAdmissionOptions as M, FrameAdmissionQueue as N, createWebGlSkyReflectionFilter as O, SceneAdmission as P, evaluateEarthSky as S, SkyReflectionFilter as T, SkyVisual as _, RendererBackendPreference as a, CelestialPosition as b, TopDownOrtho as c, GpuFrameTimer as d, GpuFrameTimerOptions as f, SkyStar as g, SkyFrame as h, RendererBackend as i, AdmissionSample as j, reflectionStateFromLights as k, nextWorldOrigin as l, WeatherVisual as m, CameraPose as n, RendererOptions as o, createGpuFrameTimer as p, Renderer as r, ThreeRenderer as s, AutoWorldOriginOptions as t, orthoFrustum as u, SkyVisualOptions as v, starDirection as w, EarthSkyState as x, defaultSkyPalette as y };
575
+ export { createWebGlSkyReflectionFilter as A, EarthSkyState as C, SkyReflectionFilter as D, starDirection as E, FrameAdmissionQueue as F, SceneAdmission as I, AdmissionOptions as M, AdmissionSample as N, SkyReflectionState as O, FrameAdmissionOptions as P, CelestialPosition as S, skyTimeMs as T, SkyFrame as _, RendererBackendPreference as a, SkyVisualOptions as b, TopDownOrtho as c, ShadowFocus as d, ShadowQuality as f, WeatherVisual as g, createGpuFrameTimer as h, RendererBackend as i, reflectionStateFromLights as j, SkyReflections as k, nextWorldOrigin as l, GpuFrameTimerOptions as m, CameraPose as n, RendererOptions as o, GpuFrameTimer as p, Renderer as r, ThreeRenderer as s, AutoWorldOriginOptions as t, orthoFrustum as u, SkyStar as v, evaluateEarthSky as w, defaultSkyPalette as x, SkyVisual as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/molen-client",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -68,7 +68,7 @@
68
68
  ],
69
69
  "dependencies": {
70
70
  "zod": "^4.6.5",
71
- "@bendyline/molen-materials": "0.0.4",
71
+ "@bendyline/molen-materials": "0.0.5",
72
72
  "@bendyline/molen-schema": "0.0.4"
73
73
  },
74
74
  "peerDependencies": {