@bendyline/molen-client 0.0.3 → 0.0.5
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.
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +109 -3
- package/dist/markers.d.mts +15 -0
- package/dist/markers.mjs +77 -10
- package/dist/navigation.d.mts +46 -5
- package/dist/navigation.mjs +128 -4
- package/dist/{renderer-DfWc3MFM.d.mts → renderer-DNXUCuIZ.d.mts} +24 -1
- package/dist/vehicles.d.mts +18 -1
- package/dist/vehicles.mjs +15 -4
- package/package.json +3 -3
package/dist/camera-track.d.mts
CHANGED
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
|
|
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;
|
|
@@ -3254,6 +3257,53 @@ function createGpuFrameTimer(context, options = {}) {
|
|
|
3254
3257
|
};
|
|
3255
3258
|
}
|
|
3256
3259
|
//#endregion
|
|
3260
|
+
//#region src/three/shadow-focus.ts
|
|
3261
|
+
const SHADOW_MAP_SIZE = {
|
|
3262
|
+
low: 1024,
|
|
3263
|
+
medium: 2048,
|
|
3264
|
+
high: 4096
|
|
3265
|
+
};
|
|
3266
|
+
const UP = new THREE.Vector3(0, 1, 0);
|
|
3267
|
+
const scratchCenter = new THREE.Vector3();
|
|
3268
|
+
const scratchRight = new THREE.Vector3();
|
|
3269
|
+
const scratchUp = new THREE.Vector3();
|
|
3270
|
+
const scratchForward = new THREE.Vector3();
|
|
3271
|
+
/**
|
|
3272
|
+
* Aim `light`'s shadow at `center` (scene coordinates, after rebasing) from `direction` (a unit
|
|
3273
|
+
* vector toward the sun), covering ±`radius`. The light and its target move; the direction of
|
|
3274
|
+
* the light is unchanged.
|
|
3275
|
+
*/
|
|
3276
|
+
function focusDirectionalShadow(light, direction, center, radius) {
|
|
3277
|
+
const toSun = scratchForward.copy(direction).normalize();
|
|
3278
|
+
const size = light.shadow.mapSize.x || 2048;
|
|
3279
|
+
const texel = 2 * radius / size;
|
|
3280
|
+
const right = scratchRight.crossVectors(Math.abs(toSun.y) > .999 ? new THREE.Vector3(1, 0, 0) : UP, toSun);
|
|
3281
|
+
right.normalize();
|
|
3282
|
+
const up = scratchUp.crossVectors(toSun, right).normalize();
|
|
3283
|
+
const snapped = scratchCenter.copy(center);
|
|
3284
|
+
const along = snapped.dot(toSun);
|
|
3285
|
+
const x = Math.round(snapped.dot(right) / texel) * texel;
|
|
3286
|
+
const y = Math.round(snapped.dot(up) / texel) * texel;
|
|
3287
|
+
snapped.copy(right).multiplyScalar(x).addScaledVector(up, y).addScaledVector(toSun, along);
|
|
3288
|
+
const distance = radius * 2 + 1e3;
|
|
3289
|
+
light.target.position.copy(snapped);
|
|
3290
|
+
light.position.copy(snapped).addScaledVector(toSun, distance);
|
|
3291
|
+
light.target.updateMatrixWorld();
|
|
3292
|
+
light.updateMatrixWorld();
|
|
3293
|
+
const camera = light.shadow.camera;
|
|
3294
|
+
if (camera.left !== -radius || camera.top !== radius || camera.far !== distance + radius * 2 + 1e3) {
|
|
3295
|
+
camera.left = -radius;
|
|
3296
|
+
camera.right = radius;
|
|
3297
|
+
camera.top = radius;
|
|
3298
|
+
camera.bottom = -radius;
|
|
3299
|
+
camera.near = 1;
|
|
3300
|
+
camera.far = distance + radius * 2 + 1e3;
|
|
3301
|
+
camera.updateProjectionMatrix();
|
|
3302
|
+
}
|
|
3303
|
+
light.shadow.bias = -4e-4;
|
|
3304
|
+
light.shadow.normalBias = texel * 1.2;
|
|
3305
|
+
}
|
|
3306
|
+
//#endregion
|
|
3257
3307
|
//#region src/three/sky-reflections.ts
|
|
3258
3308
|
const WIDTH = 256;
|
|
3259
3309
|
const HEIGHT = 128;
|
|
@@ -3514,10 +3564,59 @@ var Renderer = class Renderer {
|
|
|
3514
3564
|
drawCalls: 0,
|
|
3515
3565
|
triangles: 0
|
|
3516
3566
|
};
|
|
3567
|
+
shadowFocus;
|
|
3568
|
+
shadowCenter = new THREE.Vector3();
|
|
3569
|
+
shadowDirection = new THREE.Vector3();
|
|
3517
3570
|
/** Active clear-sky visual and sampled ephemeris, when environment.sky is configured. */
|
|
3518
3571
|
get sky() {
|
|
3519
3572
|
return this.activeSky;
|
|
3520
3573
|
}
|
|
3574
|
+
/**
|
|
3575
|
+
* Aim the sun's shadow at a focus (absolute world coordinates) covering ±`radius` meters, or
|
|
3576
|
+
* `undefined` for the environment's own fixed box. Call whenever what the camera frames
|
|
3577
|
+
* moves: an orbit target, a walker, a car. Shadows must be on (`setShadowQuality`).
|
|
3578
|
+
*/
|
|
3579
|
+
setShadowFocus(focus) {
|
|
3580
|
+
if (focus !== void 0 && (!(focus.radius > 0) || !Number.isFinite(focus.radius))) throw new RangeError("Shadow focus radius must be a positive number of meters");
|
|
3581
|
+
this.shadowFocus = focus === void 0 ? void 0 : {
|
|
3582
|
+
center: [...focus.center],
|
|
3583
|
+
radius: focus.radius
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3586
|
+
/** Turn sun shadows on at a map resolution, or off, without rebuilding the environment. */
|
|
3587
|
+
setShadowQuality(quality) {
|
|
3588
|
+
const enabled = quality !== "off";
|
|
3589
|
+
for (const light of this.sunLights()) {
|
|
3590
|
+
light.castShadow = enabled;
|
|
3591
|
+
if (!enabled) continue;
|
|
3592
|
+
const size = SHADOW_MAP_SIZE[quality];
|
|
3593
|
+
if (light.shadow.mapSize.x !== size) {
|
|
3594
|
+
light.shadow.mapSize.set(size, size);
|
|
3595
|
+
light.shadow.map?.dispose();
|
|
3596
|
+
light.shadow.map = null;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3599
|
+
this.three.shadowMap.enabled = enabled;
|
|
3600
|
+
this.three.shadowMap.type = quality === "low" ? THREE.PCFShadowMap : THREE.PCFSoftShadowMap;
|
|
3601
|
+
}
|
|
3602
|
+
/** The directional lights standing for the sun: the environment rig's, and the sky's. */
|
|
3603
|
+
sunLights() {
|
|
3604
|
+
const lights = [];
|
|
3605
|
+
findEnvironmentRig(this.scene)?.traverse((object) => {
|
|
3606
|
+
if (object instanceof THREE.DirectionalLight && object.userData.molenSun === true) lights.push(object);
|
|
3607
|
+
});
|
|
3608
|
+
if (this.activeSky) lights.push(this.activeSky.sunLight);
|
|
3609
|
+
return lights;
|
|
3610
|
+
}
|
|
3611
|
+
applyShadowFocus() {
|
|
3612
|
+
const focus = this.shadowFocus;
|
|
3613
|
+
if (focus === void 0 || !this.three.shadowMap.enabled) return;
|
|
3614
|
+
const center = this.shadowCenter.set(focus.center[0] - this.worldOrigin[0], focus.center[1] - this.worldOrigin[1], focus.center[2] - this.worldOrigin[2]);
|
|
3615
|
+
for (const light of this.sunLights()) {
|
|
3616
|
+
if (!light.castShadow) continue;
|
|
3617
|
+
focusDirectionalShadow(light, light === this.activeSky?.sunLight ? this.shadowDirection.fromArray(this.activeSky.frame.sunDirection) : this.shadowDirection.copy(light.userData.molenSunDirection), center, focus.radius);
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3521
3620
|
/** Active weather effects; physical weather data is also available in the simulation component. */
|
|
3522
3621
|
get weather() {
|
|
3523
3622
|
return this.activeWeather;
|
|
@@ -3651,9 +3750,11 @@ var Renderer = class Renderer {
|
|
|
3651
3750
|
this.defaultClearColor = new THREE.Color(opts.clearColor ?? "#1a1a20");
|
|
3652
3751
|
this.three.setClearColor(this.defaultClearColor, 1);
|
|
3653
3752
|
this.scene = new THREE.Scene();
|
|
3753
|
+
this.scene.matrixAutoUpdate = false;
|
|
3654
3754
|
this.reflections = opts.reflections === true ? new SkyReflections(this.scene, initialized?.reflectionFilter ?? createWebGlSkyReflectionFilter(this.three)) : void 0;
|
|
3655
3755
|
this.worldRoot = new THREE.Group();
|
|
3656
3756
|
this.worldRoot.name = "molen:world-root";
|
|
3757
|
+
this.worldRoot.matrixAutoUpdate = false;
|
|
3657
3758
|
this.scene.add(this.worldRoot);
|
|
3658
3759
|
this.aspect = width / height;
|
|
3659
3760
|
this.camera = new THREE.PerspectiveCamera(60, this.aspect, cameraNear, cameraFar);
|
|
@@ -3718,6 +3819,7 @@ var Renderer = class Renderer {
|
|
|
3718
3819
|
applyWorldOrigin(origin) {
|
|
3719
3820
|
this.worldOrigin = [...origin];
|
|
3720
3821
|
this.worldRoot.position.set(-origin[0], -origin[1], -origin[2]);
|
|
3822
|
+
this.worldRoot.updateMatrix();
|
|
3721
3823
|
}
|
|
3722
3824
|
/** Switch to a top-down orthographic camera looking straight down at a world point. */
|
|
3723
3825
|
setTopDownOrtho(opts) {
|
|
@@ -4128,6 +4230,7 @@ var Renderer = class Renderer {
|
|
|
4128
4230
|
if (sky) {
|
|
4129
4231
|
sky.update(this.environmentTimeOverride ?? this.environmentSeconds);
|
|
4130
4232
|
sky.prepareCamera(this.camera);
|
|
4233
|
+
this.applyShadowFocus();
|
|
4131
4234
|
const autoClear = this.three.autoClear;
|
|
4132
4235
|
const autoReset = this.three.info.autoReset;
|
|
4133
4236
|
this.three.info.reset();
|
|
@@ -4140,7 +4243,10 @@ var Renderer = class Renderer {
|
|
|
4140
4243
|
this.three.autoClear = autoClear;
|
|
4141
4244
|
this.three.info.autoReset = autoReset;
|
|
4142
4245
|
}
|
|
4143
|
-
} else
|
|
4246
|
+
} else {
|
|
4247
|
+
this.applyShadowFocus();
|
|
4248
|
+
this.renderScene();
|
|
4249
|
+
}
|
|
4144
4250
|
const info = this.three.info.render;
|
|
4145
4251
|
this.lastRenderStats.drawCalls = "drawCalls" in info ? info.drawCalls : info.calls;
|
|
4146
4252
|
this.lastRenderStats.triangles = info.triangles;
|
package/dist/markers.d.mts
CHANGED
|
@@ -72,6 +72,18 @@ interface MarkerLayerOptions {
|
|
|
72
72
|
occlude?: boolean;
|
|
73
73
|
/** Hide ground-snapped markers until their ground height is known (default true). */
|
|
74
74
|
hideUntilGrounded?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Hide markers whose on-screen footprints overlap a more important one: higher `priority`
|
|
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.
|
|
81
|
+
*/
|
|
82
|
+
declutter?: boolean | {
|
|
83
|
+
padding?: number;
|
|
84
|
+
};
|
|
85
|
+
/** Milliseconds a marker takes to fade in or out as it is shown or hidden (default 180; 0 pops). */
|
|
86
|
+
fadeMs?: number;
|
|
75
87
|
renderOrder?: number;
|
|
76
88
|
}
|
|
77
89
|
interface MarkerScreenPosition {
|
|
@@ -99,6 +111,7 @@ declare class MarkerLayer {
|
|
|
99
111
|
private readonly loader;
|
|
100
112
|
private visible;
|
|
101
113
|
private disposed;
|
|
114
|
+
private lastUpdateMs;
|
|
102
115
|
constructor(host: MarkerHost, options?: MarkerLayerOptions);
|
|
103
116
|
/** Replace the marker set. Markers are matched by id, so unchanged images are not reloaded. */
|
|
104
117
|
set(markers: readonly MarkerSpec[]): void;
|
|
@@ -109,6 +122,8 @@ declare class MarkerLayer {
|
|
|
109
122
|
* camera's absolute world position (the one given to `setCamera`).
|
|
110
123
|
*/
|
|
111
124
|
update(cameraPosition: readonly [number, number, number]): void;
|
|
125
|
+
/** CSS-pixel projection of rebased sprite positions, set up once per update. */
|
|
126
|
+
private screenProjector;
|
|
112
127
|
/** The front-most drawn marker under a CSS-pixel point, if any. */
|
|
113
128
|
pick(x: number, y: number): string | undefined;
|
|
114
129
|
/** Where a marker's anchor point appears on screen (for DOM callouts), if it exists. */
|
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,30 +169,82 @@ 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)
|
|
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);
|
|
168
180
|
}
|
|
169
|
-
|
|
181
|
+
const declutter = this.options.declutter;
|
|
182
|
+
const padding = typeof declutter === "object" ? declutter.padding ?? 4 : declutter === true ? 4 : 0;
|
|
183
|
+
candidates.sort((a, b) => (b.spec.priority ?? 0) - (a.spec.priority ?? 0) || (declutter ? Number(b.shown) - Number(a.shown) : 0) || a.distance - b.distance || a.spec.id.localeCompare(b.spec.id));
|
|
170
184
|
const budget = this.options.maxVisible ?? 256;
|
|
171
185
|
const fade = this.options.fade;
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
const project = declutter ? this.screenProjector() : void 0;
|
|
187
|
+
const taken = [];
|
|
188
|
+
let drawn = 0;
|
|
189
|
+
for (const entry of candidates) {
|
|
190
|
+
const wasShown = entry.shown;
|
|
191
|
+
entry.shown = false;
|
|
174
192
|
const opacity = fade === void 0 ? 1 : Math.max(0, Math.min(1, (fade.far - entry.distance) / (fade.far - fade.near)));
|
|
175
|
-
if (opacity <= 0) continue;
|
|
176
193
|
const size = entry.spec.size ?? 56;
|
|
177
|
-
|
|
194
|
+
let chosen = drawn < budget && opacity > 0;
|
|
195
|
+
if (chosen && project !== void 0) {
|
|
196
|
+
const screen = project(entry.sprite.position);
|
|
197
|
+
if (screen !== void 0) {
|
|
198
|
+
const width = size * entry.aspect;
|
|
199
|
+
const top = (entry.spec.anchor ?? "bottom") === "bottom" ? screen[1] - size : screen[1] - size / 2;
|
|
200
|
+
const box = [
|
|
201
|
+
screen[0] - width / 2 - padding,
|
|
202
|
+
top - padding,
|
|
203
|
+
screen[0] + width / 2 + padding,
|
|
204
|
+
top + size + padding
|
|
205
|
+
];
|
|
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);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
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;
|
|
178
224
|
entry.sprite.scale.set(size * entry.aspect * perPixel, size * perPixel, 1);
|
|
179
225
|
entry.sprite.center.set(.5, (entry.spec.anchor ?? "bottom") === "bottom" ? 0 : .5);
|
|
180
226
|
entry.sprite.visible = true;
|
|
181
227
|
}
|
|
182
228
|
}
|
|
229
|
+
/** CSS-pixel projection of rebased sprite positions, set up once per update. */
|
|
230
|
+
screenProjector() {
|
|
231
|
+
const [width, height] = this.host.getViewportSize();
|
|
232
|
+
this.host.worldRoot.updateWorldMatrix(true, false);
|
|
233
|
+
this.host.camera.updateMatrixWorld();
|
|
234
|
+
const camera = this.host.camera;
|
|
235
|
+
return (position) => {
|
|
236
|
+
const world = this.host.worldRoot.localToWorld(scratch.copy(position));
|
|
237
|
+
viewSpace.copy(world).applyMatrix4(camera.matrixWorldInverse);
|
|
238
|
+
if (viewSpace.z >= 0) return void 0;
|
|
239
|
+
world.project(camera);
|
|
240
|
+
return [(world.x + 1) / 2 * width, (1 - world.y) / 2 * height];
|
|
241
|
+
};
|
|
242
|
+
}
|
|
183
243
|
/** The front-most drawn marker under a CSS-pixel point, if any. */
|
|
184
244
|
pick(x, y) {
|
|
185
245
|
let best;
|
|
186
246
|
for (const [id, entry] of this.entries) {
|
|
187
|
-
if (!entry.sprite.visible) continue;
|
|
247
|
+
if (!entry.sprite.visible || !entry.shown) continue;
|
|
188
248
|
const p = entry.sprite.position;
|
|
189
249
|
const screen = projectWorldToScreen(this.host, [
|
|
190
250
|
p.x,
|
|
@@ -220,7 +280,11 @@ var MarkerLayer = class {
|
|
|
220
280
|
}
|
|
221
281
|
setVisible(visible) {
|
|
222
282
|
this.visible = visible;
|
|
223
|
-
if (!visible) for (const entry of this.entries.values())
|
|
283
|
+
if (!visible) for (const entry of this.entries.values()) {
|
|
284
|
+
entry.sprite.visible = false;
|
|
285
|
+
entry.presence = 0;
|
|
286
|
+
entry.shown = false;
|
|
287
|
+
}
|
|
224
288
|
}
|
|
225
289
|
dispose() {
|
|
226
290
|
if (this.disposed) return;
|
|
@@ -239,7 +303,8 @@ var MarkerLayer = class {
|
|
|
239
303
|
transparent: true,
|
|
240
304
|
depthWrite: false,
|
|
241
305
|
depthTest: this.options.occlude ?? true,
|
|
242
|
-
sizeAttenuation: false
|
|
306
|
+
sizeAttenuation: false,
|
|
307
|
+
fog: false
|
|
243
308
|
});
|
|
244
309
|
const entry = {
|
|
245
310
|
spec: { ...spec },
|
|
@@ -249,7 +314,9 @@ var MarkerLayer = class {
|
|
|
249
314
|
imageKey: spec.image,
|
|
250
315
|
aspect: imageAspect(spec.image) ?? 1,
|
|
251
316
|
groundY: void 0,
|
|
252
|
-
distance: 0
|
|
317
|
+
distance: 0,
|
|
318
|
+
shown: false,
|
|
319
|
+
presence: 0
|
|
253
320
|
};
|
|
254
321
|
entry.texture = this.acquire(spec.image, entry);
|
|
255
322
|
material.map = entry.texture;
|
package/dist/navigation.d.mts
CHANGED
|
@@ -155,15 +155,39 @@ declare const NAVIGATION_ACTIONS: {
|
|
|
155
155
|
readonly jump: "nav-jump";
|
|
156
156
|
readonly interact: "nav-interact";
|
|
157
157
|
readonly view: "nav-view";
|
|
158
|
+
readonly throttleUp: "nav-throttle-up";
|
|
159
|
+
readonly throttleDown: "nav-throttle-down";
|
|
160
|
+
readonly yawLeft: "nav-yaw-left";
|
|
161
|
+
readonly yawRight: "nav-yaw-right";
|
|
162
|
+
readonly engine: "nav-engine";
|
|
163
|
+
readonly gear: "nav-gear";
|
|
164
|
+
readonly flaps: "nav-flaps";
|
|
165
|
+
readonly recover: "nav-recover";
|
|
158
166
|
};
|
|
159
167
|
/** The navigation modes with a default input profile. */
|
|
160
|
-
type NavigationProfileName = "orbit" | "fly" | "walk" | "drive";
|
|
168
|
+
type NavigationProfileName = "orbit" | "fly" | "walk" | "drive" | "pilot";
|
|
161
169
|
/**
|
|
162
170
|
* Default key/gamepad bindings per navigation mode. Orbit and fly use Q/E for down/up; walk and
|
|
163
171
|
* drive use E to interact (board or leave a vehicle), Space to jump or brake, and V to switch
|
|
164
|
-
* the vehicle view.
|
|
172
|
+
* the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→)
|
|
173
|
+
* bank, Q/Z work the rudder or pedals, Shift/Ctrl (or +/−, Page Up/Down) set throttle or
|
|
174
|
+
* collective, I toggles the engine, G the gear, F the flaps, R recovers after an impact, Space
|
|
175
|
+
* brakes, V switches the view and E leaves. Hosts may replace any profile through
|
|
176
|
+
* `InputMap.defineProfile`.
|
|
165
177
|
*/
|
|
166
178
|
declare function navigationInputProfiles(): Record<NavigationProfileName, InputProfile>;
|
|
179
|
+
/** Flight controls beyond pitch (`-move.forward`) and roll (`move.right`), in the pilot profile. */
|
|
180
|
+
interface PilotInput {
|
|
181
|
+
/** Held throttle or collective change, -1..1 (more power positive). */
|
|
182
|
+
throttle: number;
|
|
183
|
+
/** Held rudder or pedals, -1..1 (right positive). */
|
|
184
|
+
yaw: number;
|
|
185
|
+
/** Presses since the previous frame (edge-triggered). */
|
|
186
|
+
engine: number;
|
|
187
|
+
gear: number;
|
|
188
|
+
flaps: number;
|
|
189
|
+
recover: number;
|
|
190
|
+
}
|
|
167
191
|
/** Everything a navigation controller reads in one frame. */
|
|
168
192
|
interface NavigationInput {
|
|
169
193
|
/** Movement intent, each -1..1 (forward, right, up). */
|
|
@@ -192,6 +216,8 @@ interface NavigationInput {
|
|
|
192
216
|
x: number;
|
|
193
217
|
y: number;
|
|
194
218
|
}>;
|
|
219
|
+
/** Flight controls, present while the `pilot` profile is active. */
|
|
220
|
+
pilot?: PilotInput;
|
|
195
221
|
}
|
|
196
222
|
/** An input with no intent; controllers treat it as "hold still". */
|
|
197
223
|
declare function idleNavigationInput(): NavigationInput;
|
|
@@ -224,6 +250,8 @@ declare class NavigationInputSource {
|
|
|
224
250
|
readonly pointer: NavigationPointer;
|
|
225
251
|
private interactPresses;
|
|
226
252
|
private viewPresses;
|
|
253
|
+
private profile;
|
|
254
|
+
private readonly pilotPresses;
|
|
227
255
|
private readonly lookSpeed;
|
|
228
256
|
private readonly unsubscribe;
|
|
229
257
|
constructor(options: NavigationInputSourceOptions);
|
|
@@ -277,8 +305,8 @@ declare class OrbitController {
|
|
|
277
305
|
private current;
|
|
278
306
|
private flight;
|
|
279
307
|
private clock;
|
|
280
|
-
private
|
|
281
|
-
private
|
|
308
|
+
private minRange;
|
|
309
|
+
private maxRange;
|
|
282
310
|
private readonly minPitch;
|
|
283
311
|
private readonly maxPitch;
|
|
284
312
|
private readonly rotateSensitivity;
|
|
@@ -289,6 +317,19 @@ declare class OrbitController {
|
|
|
289
317
|
get state(): OrbitState;
|
|
290
318
|
/** Whether a fly-to animation is running. */
|
|
291
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;
|
|
292
333
|
/** Jump to a framing immediately (fields omitted keep their values). */
|
|
293
334
|
set(state: Partial<OrbitState>): void;
|
|
294
335
|
/** Animate to a framing; direct input during the flight cancels it. */
|
|
@@ -526,4 +567,4 @@ declare class WalkController {
|
|
|
526
567
|
private setCapsule;
|
|
527
568
|
}
|
|
528
569
|
//#endregion
|
|
529
|
-
export { type CameraOrientation, CollisionTree, FlyController, type FlyControllerOptions, FollowController, type FollowControllerOptions, type FollowSubject, MAX_LOOK_PITCH, NAVIGATION_ACTIONS, type NavigationEnvironment, type NavigationGestures, type NavigationInput, NavigationInputSource, type NavigationInputSourceOptions, type NavigationKeyTarget, NavigationPointer, type NavigationPointerEvent, type NavigationPointerOptions, type NavigationPointerSurface, type NavigationPose, type NavigationProfileName, type NavigationVector, type NavigationWheelEvent, OrbitController, type OrbitControllerOptions, type OrbitFlyToOptions, type OrbitState, RUN_SPEED, type TouchJoystick, type TouchJoystickOptions, TouchStick, type TouchStickOptions, WALK_EYE_HEIGHT, WALK_PLACEMENT_RADIUS, WALK_SPEED, WalkCollision, type WalkCollisionOptions, WalkController, type WalkInput, applyCameraLookDelta, cameraForward, cameraPlanarForward, cameraRight, createTouchJoystick, idleNavigationInput, navigationInputProfiles, orientationFromDirection, viewNeedsImmediateUpdate };
|
|
570
|
+
export { type CameraOrientation, CollisionTree, FlyController, type FlyControllerOptions, FollowController, type FollowControllerOptions, type FollowSubject, MAX_LOOK_PITCH, NAVIGATION_ACTIONS, type NavigationEnvironment, type NavigationGestures, type NavigationInput, NavigationInputSource, type NavigationInputSourceOptions, type NavigationKeyTarget, NavigationPointer, type NavigationPointerEvent, type NavigationPointerOptions, type NavigationPointerSurface, type NavigationPose, type NavigationProfileName, type NavigationVector, type NavigationWheelEvent, OrbitController, type OrbitControllerOptions, type OrbitFlyToOptions, type OrbitState, type PilotInput, RUN_SPEED, type TouchJoystick, type TouchJoystickOptions, TouchStick, type TouchStickOptions, WALK_EYE_HEIGHT, WALK_PLACEMENT_RADIUS, WALK_SPEED, WalkCollision, type WalkCollisionOptions, WalkController, type WalkInput, applyCameraLookDelta, cameraForward, cameraPlanarForward, cameraRight, createTouchJoystick, idleNavigationInput, navigationInputProfiles, orientationFromDirection, viewNeedsImmediateUpdate };
|
package/dist/navigation.mjs
CHANGED
|
@@ -401,7 +401,15 @@ const NAVIGATION_ACTIONS = {
|
|
|
401
401
|
sprint: "nav-sprint",
|
|
402
402
|
jump: "nav-jump",
|
|
403
403
|
interact: "nav-interact",
|
|
404
|
-
view: "nav-view"
|
|
404
|
+
view: "nav-view",
|
|
405
|
+
throttleUp: "nav-throttle-up",
|
|
406
|
+
throttleDown: "nav-throttle-down",
|
|
407
|
+
yawLeft: "nav-yaw-left",
|
|
408
|
+
yawRight: "nav-yaw-right",
|
|
409
|
+
engine: "nav-engine",
|
|
410
|
+
gear: "nav-gear",
|
|
411
|
+
flaps: "nav-flaps",
|
|
412
|
+
recover: "nav-recover"
|
|
405
413
|
};
|
|
406
414
|
const A = NAVIGATION_ACTIONS;
|
|
407
415
|
const MOVE_KEYS = {
|
|
@@ -461,7 +469,11 @@ const STICKS = [
|
|
|
461
469
|
/**
|
|
462
470
|
* Default key/gamepad bindings per navigation mode. Orbit and fly use Q/E for down/up; walk and
|
|
463
471
|
* drive use E to interact (board or leave a vehicle), Space to jump or brake, and V to switch
|
|
464
|
-
* the vehicle view.
|
|
472
|
+
* the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→)
|
|
473
|
+
* bank, Q/Z work the rudder or pedals, Shift/Ctrl (or +/−, Page Up/Down) set throttle or
|
|
474
|
+
* collective, I toggles the engine, G the gear, F the flaps, R recovers after an impact, Space
|
|
475
|
+
* brakes, V switches the view and E leaves. Hosts may replace any profile through
|
|
476
|
+
* `InputMap.defineProfile`.
|
|
465
477
|
*/
|
|
466
478
|
function navigationInputProfiles() {
|
|
467
479
|
const aerial = {
|
|
@@ -520,7 +532,73 @@ function navigationInputProfiles() {
|
|
|
520
532
|
orbit: aerial,
|
|
521
533
|
fly: aerial,
|
|
522
534
|
walk: ground,
|
|
523
|
-
drive: ground
|
|
535
|
+
drive: ground,
|
|
536
|
+
pilot: {
|
|
537
|
+
bindings: {
|
|
538
|
+
KeyW: A.forward,
|
|
539
|
+
ArrowUp: A.forward,
|
|
540
|
+
KeyS: A.back,
|
|
541
|
+
ArrowDown: A.back,
|
|
542
|
+
KeyA: A.left,
|
|
543
|
+
ArrowLeft: A.left,
|
|
544
|
+
KeyD: A.right,
|
|
545
|
+
ArrowRight: A.right,
|
|
546
|
+
KeyQ: A.yawLeft,
|
|
547
|
+
KeyZ: A.yawRight,
|
|
548
|
+
ShiftLeft: A.throttleUp,
|
|
549
|
+
ShiftRight: A.throttleUp,
|
|
550
|
+
Equal: A.throttleUp,
|
|
551
|
+
NumpadAdd: A.throttleUp,
|
|
552
|
+
PageUp: A.throttleUp,
|
|
553
|
+
ControlLeft: A.throttleDown,
|
|
554
|
+
ControlRight: A.throttleDown,
|
|
555
|
+
Minus: A.throttleDown,
|
|
556
|
+
NumpadSubtract: A.throttleDown,
|
|
557
|
+
PageDown: A.throttleDown,
|
|
558
|
+
Space: A.jump,
|
|
559
|
+
KeyE: A.interact,
|
|
560
|
+
KeyV: A.view,
|
|
561
|
+
KeyI: A.engine,
|
|
562
|
+
KeyG: A.gear,
|
|
563
|
+
KeyF: A.flaps,
|
|
564
|
+
KeyR: A.recover
|
|
565
|
+
},
|
|
566
|
+
axes: STICKS,
|
|
567
|
+
buttons: [
|
|
568
|
+
{
|
|
569
|
+
button: 7,
|
|
570
|
+
action: A.throttleUp
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
button: 6,
|
|
574
|
+
action: A.throttleDown
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
button: 4,
|
|
578
|
+
action: A.yawLeft
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
button: 5,
|
|
582
|
+
action: A.yawRight
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
button: 0,
|
|
586
|
+
action: A.jump
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
button: 2,
|
|
590
|
+
action: A.interact
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
button: 3,
|
|
594
|
+
action: A.view
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
button: 1,
|
|
598
|
+
action: A.engine
|
|
599
|
+
}
|
|
600
|
+
]
|
|
601
|
+
}
|
|
524
602
|
};
|
|
525
603
|
}
|
|
526
604
|
/** An input with no intent; controllers treat it as "hold still". */
|
|
@@ -551,6 +629,13 @@ var NavigationInputSource = class {
|
|
|
551
629
|
pointer;
|
|
552
630
|
interactPresses = 0;
|
|
553
631
|
viewPresses = 0;
|
|
632
|
+
profile;
|
|
633
|
+
pilotPresses = {
|
|
634
|
+
engine: 0,
|
|
635
|
+
gear: 0,
|
|
636
|
+
flaps: 0,
|
|
637
|
+
recover: 0
|
|
638
|
+
};
|
|
554
639
|
lookSpeed;
|
|
555
640
|
unsubscribe;
|
|
556
641
|
constructor(options) {
|
|
@@ -564,7 +649,16 @@ var NavigationInputSource = class {
|
|
|
564
649
|
});
|
|
565
650
|
this.pointer = new NavigationPointer(options.element, options);
|
|
566
651
|
this.lookSpeed = options.gamepadLookSpeed ?? 900;
|
|
652
|
+
this.profile = options.profile ?? "orbit";
|
|
567
653
|
this.unsubscribe = [
|
|
654
|
+
...[
|
|
655
|
+
"engine",
|
|
656
|
+
"gear",
|
|
657
|
+
"flaps",
|
|
658
|
+
"recover"
|
|
659
|
+
].map((name) => this.map.onPress(A[name], () => {
|
|
660
|
+
this.pilotPresses[name]++;
|
|
661
|
+
})),
|
|
568
662
|
this.map.onPress(A.interact, () => {
|
|
569
663
|
this.interactPresses++;
|
|
570
664
|
}),
|
|
@@ -575,6 +669,7 @@ var NavigationInputSource = class {
|
|
|
575
669
|
];
|
|
576
670
|
}
|
|
577
671
|
setProfile(profile) {
|
|
672
|
+
this.profile = profile;
|
|
578
673
|
this.map.setProfile(profile);
|
|
579
674
|
this.pointer.setPointerLock(profile === "walk");
|
|
580
675
|
}
|
|
@@ -599,10 +694,19 @@ var NavigationInputSource = class {
|
|
|
599
694
|
jump: v(A.jump) !== 0,
|
|
600
695
|
interact: this.interactPresses,
|
|
601
696
|
view: this.viewPresses,
|
|
602
|
-
taps: gestures.taps
|
|
697
|
+
taps: gestures.taps,
|
|
698
|
+
...this.profile === "pilot" ? { pilot: {
|
|
699
|
+
throttle: v(A.throttleUp) - v(A.throttleDown),
|
|
700
|
+
yaw: v(A.yawRight) - v(A.yawLeft),
|
|
701
|
+
...this.pilotPresses
|
|
702
|
+
} } : {}
|
|
603
703
|
};
|
|
604
704
|
this.interactPresses = 0;
|
|
605
705
|
this.viewPresses = 0;
|
|
706
|
+
this.pilotPresses.engine = 0;
|
|
707
|
+
this.pilotPresses.gear = 0;
|
|
708
|
+
this.pilotPresses.flaps = 0;
|
|
709
|
+
this.pilotPresses.recover = 0;
|
|
606
710
|
return input;
|
|
607
711
|
}
|
|
608
712
|
dispose() {
|
|
@@ -657,6 +761,26 @@ var OrbitController = class {
|
|
|
657
761
|
get flying() {
|
|
658
762
|
return this.flight !== void 0;
|
|
659
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
|
+
}
|
|
660
784
|
/** Jump to a framing immediately (fields omitted keep their values). */
|
|
661
785
|
set(state) {
|
|
662
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 {
|
|
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/dist/vehicles.d.mts
CHANGED
|
@@ -11,6 +11,23 @@ interface VehicleVisual {
|
|
|
11
11
|
}
|
|
12
12
|
/** Bind a loaded entity GLB to generic wheel/steering animation using external node names. */
|
|
13
13
|
declare function createVehicleVisual(model: THREE.Object3D, vehicle: VehicleData): VehicleVisual;
|
|
14
|
+
/** The dimensions a vehicle proxy is built from (a `VehicleSpec` satisfies it). */
|
|
15
|
+
interface VehicleProxyDimensions {
|
|
16
|
+
width: number;
|
|
17
|
+
length: number;
|
|
18
|
+
height: number;
|
|
19
|
+
wheelbase: number;
|
|
20
|
+
wheelTrack: number;
|
|
21
|
+
wheelRadius: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The parked-car proxy shape with a white body, for instanced rendering: per-instance paint comes
|
|
25
|
+
* from `instanceColor` (three multiplies vertex colours by it, so glass and tyres stay dark).
|
|
26
|
+
* Cached by dimensions; never dispose the returned geometry.
|
|
27
|
+
*/
|
|
28
|
+
declare function vehicleProxyGeometry(dimensions: VehicleProxyDimensions): THREE.BufferGeometry;
|
|
29
|
+
/** The shared vertex-coloured material of parked and proxy vehicles. */
|
|
30
|
+
declare const vehicleProxyMaterial: THREE.MeshStandardMaterial;
|
|
14
31
|
/**
|
|
15
32
|
* Dormant terrain-owned cars merged into one static mesh per tile. A plain mesh shares its
|
|
16
33
|
* compiled shader with every other tile; an instanced batch per model and paint would build one
|
|
@@ -26,4 +43,4 @@ declare function isParkedVehicleHidden(batch: THREE.Mesh, index: number): boolea
|
|
|
26
43
|
*/
|
|
27
44
|
declare function setParkedVehicleHidden(batch: THREE.Mesh, index: number, hidden: boolean): boolean;
|
|
28
45
|
//#endregion
|
|
29
|
-
export { type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, VehicleVisual, createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose };
|
|
46
|
+
export { type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, VehicleProxyDimensions, VehicleVisual, createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose, vehicleProxyGeometry, vehicleProxyMaterial };
|
package/dist/vehicles.mjs
CHANGED
|
@@ -36,7 +36,7 @@ function createVehicleVisual(model, vehicle) {
|
|
|
36
36
|
const frontWheels = new Set(vehicle.visual.frontWheelNodes);
|
|
37
37
|
const wheels = [];
|
|
38
38
|
let steeringWheel;
|
|
39
|
-
const color = new THREE.Color(vehicle.color);
|
|
39
|
+
const color = vehicle.color !== void 0 ? new THREE.Color(vehicle.color) : void 0;
|
|
40
40
|
model.traverse((object) => {
|
|
41
41
|
object.userData.vehicleGeometry = true;
|
|
42
42
|
const named = nodes.get(object.name) ?? [];
|
|
@@ -45,11 +45,12 @@ function createVehicleVisual(model, vehicle) {
|
|
|
45
45
|
if (object instanceof THREE.Mesh) {
|
|
46
46
|
object.castShadow = true;
|
|
47
47
|
object.receiveShadow = true;
|
|
48
|
-
|
|
48
|
+
const cloned = (Array.isArray(object.material) ? object.material : [object.material]).map((source) => {
|
|
49
49
|
const material = source.clone();
|
|
50
|
-
if (source.name === vehicle.visual.paintMaterial && "color" in material) material.color.copy(color);
|
|
50
|
+
if (color !== void 0 && source.name === vehicle.visual.paintMaterial && "color" in material) material.color.copy(color);
|
|
51
51
|
return material;
|
|
52
52
|
});
|
|
53
|
+
object.material = Array.isArray(object.material) ? cloned : cloned[0];
|
|
53
54
|
}
|
|
54
55
|
});
|
|
55
56
|
for (const name of vehicle.visual.wheelNodes) for (const node of nodes.get(name) ?? []) wheels.push({
|
|
@@ -107,6 +108,16 @@ function coloredBox(x, y, z, width, height, length, color) {
|
|
|
107
108
|
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
|
108
109
|
return geometry;
|
|
109
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The parked-car proxy shape with a white body, for instanced rendering: per-instance paint comes
|
|
113
|
+
* from `instanceColor` (three multiplies vertex colours by it, so glass and tyres stay dark).
|
|
114
|
+
* Cached by dimensions; never dispose the returned geometry.
|
|
115
|
+
*/
|
|
116
|
+
function vehicleProxyGeometry(dimensions) {
|
|
117
|
+
return parkedTemplate(dimensions, "#ffffff");
|
|
118
|
+
}
|
|
119
|
+
/** The shared vertex-coloured material of parked and proxy vehicles. */
|
|
120
|
+
const vehicleProxyMaterial = parkedMaterial;
|
|
110
121
|
/** Generic dimension-driven proxy used only for large dormant parking batches. */
|
|
111
122
|
function parkedTemplate(spec, color) {
|
|
112
123
|
const key = `${spec.width}:${spec.length}:${spec.height}:${spec.wheelbase}:${color}`;
|
|
@@ -228,4 +239,4 @@ function setParkedVehicleHidden(batch, index, hidden) {
|
|
|
228
239
|
return true;
|
|
229
240
|
}
|
|
230
241
|
//#endregion
|
|
231
|
-
export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose };
|
|
242
|
+
export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose, vehicleProxyGeometry, vehicleProxyMaterial };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/molen-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
],
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"zod": "^4.6.5",
|
|
71
|
-
"@bendyline/molen-materials": "0.0.
|
|
72
|
-
"@bendyline/molen-schema": "0.0.
|
|
71
|
+
"@bendyline/molen-materials": "0.0.4",
|
|
72
|
+
"@bendyline/molen-schema": "0.0.4"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@types/three": ">=0.184.0 <0.187.0",
|