@bendyline/molen-client 0.0.9 → 0.0.10
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/README.md +1 -0
- package/dist/aircraft.d.mts +3 -3
- package/dist/aircraft.mjs +35 -5
- package/dist/audio.d.mts +9 -0
- package/dist/audio.mjs +56 -8
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +174 -20
- package/dist/instruments.d.mts +63 -0
- package/dist/instruments.mjs +137 -0
- package/dist/model-signals-BpeXhsim.d.mts +25 -0
- package/dist/model-signals-DLgvjBeZ.mjs +172 -0
- package/dist/navigation.d.mts +15 -0
- package/dist/navigation.mjs +185 -28
- package/dist/{renderer-BRtQK4jX.d.mts → renderer-CtEtmwJG.d.mts} +62 -2
- package/dist/text.d.mts +24 -0
- package/dist/text.mjs +62 -0
- package/dist/{vehicle-interior-GWcXnvXS.d.mts → vehicle-interior-BgcC750p.d.mts} +1 -1
- package/dist/{vehicle-interior-vJQsRLQy.mjs → vehicle-interior-DfpZwWEh.mjs} +4 -1
- package/dist/vehicles.d.mts +3 -3
- package/dist/vehicles.mjs +5 -5
- package/dist/webgpu-ambient-occlusion-9gnp3qOY.mjs +126 -0
- package/dist/{webgpu-driver-Bt2mvZk9.mjs → webgpu-driver-BQnmPRqs.mjs} +41 -1
- package/dist/{webgpu-scene-optimizer-DKRyHBRC.mjs → webgpu-scene-optimizer-Cup4Yvzs.mjs} +9 -2
- package/package.json +12 -4
- package/dist/model-signals-DVlLyP-w.d.mts +0 -17
- package/dist/model-signals-Dp5OV-Y0.mjs +0 -73
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as nlerp4, t as lerp3 } from "./math-ev_jEkRe.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { r as readModelSignals, t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
3
3
|
import { n as normalizeInputAxis, r as resolveAction, t as InputMap } from "./input-BVZjf4T-.mjs";
|
|
4
4
|
import { t as createWebGpuFrameTimer } from "./webgpu-frame-timer-Xnuq1Hld.mjs";
|
|
5
5
|
import { resolveWeather, resolveWeather as resolveWeather$1, skySchema, validateByKind, weatherProfile, weatherSchema } from "@bendyline/molen-schema";
|
|
@@ -1913,7 +1913,7 @@ var ThreeSceneBackend = class ThreeSceneBackend {
|
|
|
1913
1913
|
}
|
|
1914
1914
|
applyModelSignals(id) {
|
|
1915
1915
|
const state = this.modelSignals.get(id);
|
|
1916
|
-
state?.visual?.update(state.signals);
|
|
1916
|
+
state?.visual?.update(state.signals, this.animationTick / this.animationTickRate);
|
|
1917
1917
|
}
|
|
1918
1918
|
destroy(id) {
|
|
1919
1919
|
this.modelSignals.delete(id);
|
|
@@ -2034,8 +2034,8 @@ var ThreeSceneBackend = class ThreeSceneBackend {
|
|
|
2034
2034
|
for (const id of this.animations) {
|
|
2035
2035
|
const binding = this.gltf.get(id);
|
|
2036
2036
|
if (binding) this.poseAnimation(binding);
|
|
2037
|
-
this.applyModelSignals(id);
|
|
2038
2037
|
}
|
|
2038
|
+
for (const id of this.modelSignals.keys()) this.applyModelSignals(id);
|
|
2039
2039
|
for (const handle of this.handles.values()) handle.setTick?.(tick, tickRate, void 0);
|
|
2040
2040
|
if (this.pointLightSlots.length > 0 && this.renderer) this.updateLocalLights(this.renderer.camera);
|
|
2041
2041
|
}
|
|
@@ -2086,6 +2086,7 @@ var ThreeSceneBackend = class ThreeSceneBackend {
|
|
|
2086
2086
|
this.applyModelSignals(id);
|
|
2087
2087
|
this.lastPoseTick.set(id, tick);
|
|
2088
2088
|
}
|
|
2089
|
+
for (const id of this.modelSignals.keys()) if (!this.animations.has(id)) this.applyModelSignals(id);
|
|
2089
2090
|
for (const [id, handle] of this.handles) {
|
|
2090
2091
|
if (handle.setTick === void 0) continue;
|
|
2091
2092
|
const object = handle.object;
|
|
@@ -2293,8 +2294,12 @@ var FrameAdmissionQueue = class {
|
|
|
2293
2294
|
this.queuedBackground.delete(job.promise);
|
|
2294
2295
|
job.promise = void 0;
|
|
2295
2296
|
}
|
|
2296
|
-
/**
|
|
2297
|
-
|
|
2297
|
+
/**
|
|
2298
|
+
* Move a still-queued background job to the normal lane, behind the jobs already there, or with
|
|
2299
|
+
* `front` ahead of them: for work a frame is waiting on, such as a material an object holds off
|
|
2300
|
+
* switching to until it is prepared.
|
|
2301
|
+
*/
|
|
2302
|
+
promote(promise, options = {}) {
|
|
2298
2303
|
const job = this.queuedBackground.get(promise);
|
|
2299
2304
|
const index = job === void 0 ? -1 : this.background.indexOf(job);
|
|
2300
2305
|
if (job === void 0 || index < 0) return;
|
|
@@ -2304,7 +2309,8 @@ var FrameAdmissionQueue = class {
|
|
|
2304
2309
|
...job.options,
|
|
2305
2310
|
priority: "normal"
|
|
2306
2311
|
};
|
|
2307
|
-
this.jobs.
|
|
2312
|
+
if (options.front === true) this.jobs.unshift(job);
|
|
2313
|
+
else this.jobs.push(job);
|
|
2308
2314
|
this.request();
|
|
2309
2315
|
}
|
|
2310
2316
|
get pending() {
|
|
@@ -2766,9 +2772,14 @@ var SkyVisual = class {
|
|
|
2766
2772
|
this.ambientLight.intensity *= 1 - this.cloudAttenuation * .2;
|
|
2767
2773
|
this.ambientLight.color.lerp(new THREE.Color("#b9c2cb"), this.cloudAttenuation * daylight * .6);
|
|
2768
2774
|
const radiance = this.ambientLight.intensity / Math.PI;
|
|
2775
|
+
const saturation = Math.max(0, Math.min(1, light?.skyLightSaturation ?? 1));
|
|
2776
|
+
const cast = (color) => {
|
|
2777
|
+
const luminance = color.r * .2126 + color.g * .7152 + color.b * .0722;
|
|
2778
|
+
return color.setRGB(luminance + (color.r - luminance) * saturation, luminance + (color.g - luminance) * saturation, luminance + (color.b - luminance) * saturation);
|
|
2779
|
+
};
|
|
2769
2780
|
this.currentReflections = {
|
|
2770
|
-
zenith: rgb$1(this.palette.nightZenith.clone().lerp(this.palette.dayZenith, daylight).multiplyScalar(radiance)),
|
|
2771
|
-
horizon: rgb$1(this.palette.nightHorizon.clone().lerp(this.palette.dayHorizon, daylight).multiplyScalar(radiance)),
|
|
2781
|
+
zenith: rgb$1(cast(this.palette.nightZenith.clone().lerp(this.palette.dayZenith, daylight)).multiplyScalar(radiance)),
|
|
2782
|
+
horizon: rgb$1(cast(this.palette.nightHorizon.clone().lerp(this.palette.dayHorizon, daylight)).multiplyScalar(radiance)),
|
|
2772
2783
|
ground: rgb$1(this.palette.ground.clone().multiplyScalar((.08 + daylight * .92) * radiance)),
|
|
2773
2784
|
twilight: rgb$1(this.palette.twilight.clone().multiplyScalar(radiance)),
|
|
2774
2785
|
twilightStrength: smooth$2(-18, -4, altitude) * (1 - smooth$2(0, 16, altitude)),
|
|
@@ -2817,6 +2828,7 @@ var SkyVisual = class {
|
|
|
2817
2828
|
const horizon = this.palette.nightHorizon.clone().lerp(this.palette.dayHorizon, daylight);
|
|
2818
2829
|
const zenith = this.palette.nightZenith.clone().lerp(this.palette.dayZenith, daylight);
|
|
2819
2830
|
const twilight = smooth$2(-18, -4, altitude) * (1 - smooth$2(0, 16, altitude));
|
|
2831
|
+
const brightness = this.data.dome?.brightness ?? 1;
|
|
2820
2832
|
const color = new THREE.Color();
|
|
2821
2833
|
const dir = new THREE.Vector3();
|
|
2822
2834
|
for (let i = 0; i < positions.count; i++) {
|
|
@@ -2826,7 +2838,7 @@ var SkyVisual = class {
|
|
|
2826
2838
|
color.lerp(this.palette.twilight, twilight * Math.exp(-Math.abs(dir.y) * 7) * (.25 + .7 * nearSun));
|
|
2827
2839
|
if (dir.y < 0) color.lerp(this.palette.ground.clone().multiplyScalar(.08 + daylight * .92), smooth$2(0, .2, -dir.y));
|
|
2828
2840
|
const glow = clamp$3(dir.dot(sun)) ** 96 * smooth$2(-2, 5, altitude) * .22;
|
|
2829
|
-
color.lerp(this.palette.sun, glow);
|
|
2841
|
+
color.lerp(this.palette.sun, glow).multiplyScalar(brightness);
|
|
2830
2842
|
colors.setXYZW(i, color.r, color.g, color.b, 1);
|
|
2831
2843
|
}
|
|
2832
2844
|
colors.needsUpdate = true;
|
|
@@ -2943,7 +2955,8 @@ function noise(x, y, period, seed) {
|
|
|
2943
2955
|
const d = hash(wrap(ix + 1, period), wrap(iy + 1, period), seed);
|
|
2944
2956
|
return (a + (b - a) * fx) * (1 - fy) + (c + (d - c) * fx) * fy;
|
|
2945
2957
|
}
|
|
2946
|
-
|
|
2958
|
+
/** Cloud texture texels per side: about 47 m each at the explorer's 24 km cloud scale. */
|
|
2959
|
+
const CLOUD_RESOLUTION = 512;
|
|
2947
2960
|
const PARTICLE_LIMIT = 1400;
|
|
2948
2961
|
/**
|
|
2949
2962
|
* Lightweight layered clouds and local precipitation with standard materials on both graphics
|
|
@@ -3022,6 +3035,7 @@ var WeatherVisual = class {
|
|
|
3022
3035
|
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
|
3023
3036
|
texture.magFilter = THREE.LinearFilter;
|
|
3024
3037
|
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
3038
|
+
texture.anisotropy = 16;
|
|
3025
3039
|
texture.generateMipmaps = true;
|
|
3026
3040
|
texture.colorSpace = THREE.LinearSRGBColorSpace;
|
|
3027
3041
|
this.cloudTexture = texture;
|
|
@@ -3069,7 +3083,7 @@ var WeatherVisual = class {
|
|
|
3069
3083
|
for (let y = 0; y < CLOUD_RESOLUTION; y++) for (let x = 0; x < CLOUD_RESOLUTION; x++) {
|
|
3070
3084
|
let value = 0, weight = 0;
|
|
3071
3085
|
for (let octave = 0; octave < 5; octave++) {
|
|
3072
|
-
const frequency = 8 * 2 ** octave, amplitude = .
|
|
3086
|
+
const frequency = 8 * 2 ** octave, amplitude = .52 ** octave;
|
|
3073
3087
|
value += noise(x / CLOUD_RESOLUTION * frequency, y / CLOUD_RESOLUTION * frequency, frequency, seed + octave) * amplitude;
|
|
3074
3088
|
weight += amplitude;
|
|
3075
3089
|
}
|
|
@@ -3587,6 +3601,12 @@ var Renderer = class Renderer {
|
|
|
3587
3601
|
warmupMaterial;
|
|
3588
3602
|
warmedPrograms = /* @__PURE__ */ new WeakMap();
|
|
3589
3603
|
warmedMeshes = /* @__PURE__ */ new WeakMap();
|
|
3604
|
+
/**
|
|
3605
|
+
* Per mesh, builds of the materials it swaps to itself (`null`: prepared with the mesh); see
|
|
3606
|
+
* `prepareVariants`.
|
|
3607
|
+
*/
|
|
3608
|
+
warmedVariants = /* @__PURE__ */ new WeakMap();
|
|
3609
|
+
variantInterests = /* @__PURE__ */ new WeakMap();
|
|
3590
3610
|
warmups = /* @__PURE__ */ new WeakMap();
|
|
3591
3611
|
/** Deferred meshes whose preparation has not settled, with the interest that can promote it. */
|
|
3592
3612
|
deferredMeshes = /* @__PURE__ */ new WeakMap();
|
|
@@ -3627,6 +3647,10 @@ var Renderer = class Renderer {
|
|
|
3627
3647
|
optimizer;
|
|
3628
3648
|
activeSky;
|
|
3629
3649
|
reflections;
|
|
3650
|
+
occlusionOptions;
|
|
3651
|
+
occlusion;
|
|
3652
|
+
occlusionLoad;
|
|
3653
|
+
occlusionSuspended = false;
|
|
3630
3654
|
/** Sun lights whose WebGPU shadow map exists and must not be torn down; see setShadowQuality. */
|
|
3631
3655
|
webgpuShadowLights = /* @__PURE__ */ new WeakSet();
|
|
3632
3656
|
reflectionClearColor = Object.assign(new THREE.Color(), { a: 1 });
|
|
@@ -3772,12 +3796,12 @@ var Renderer = class Renderer {
|
|
|
3772
3796
|
try {
|
|
3773
3797
|
if (typeof navigator === "undefined" || !("gpu" in navigator) || !navigator.gpu) throw new Error("WebGPU is unavailable in this browser or context");
|
|
3774
3798
|
if (await withProbeTimeout(navigator.gpu.requestAdapter(), probeMs, "adapter request") === null) throw new Error("WebGPU reported no adapter for this device");
|
|
3775
|
-
const { createWebGpuDriver } = await import("./webgpu-driver-
|
|
3799
|
+
const { createWebGpuDriver } = await import("./webgpu-driver-BQnmPRqs.mjs");
|
|
3776
3800
|
const three = await withProbeTimeout(createWebGpuDriver(opts), probeMs, "initialization", (late) => {
|
|
3777
3801
|
late.dispose();
|
|
3778
3802
|
});
|
|
3779
3803
|
try {
|
|
3780
|
-
const optimizer = opts.optimizeWebGpu === false ? void 0 : new (await (import("./webgpu-scene-optimizer-
|
|
3804
|
+
const optimizer = opts.optimizeWebGpu === false ? void 0 : new (await (import("./webgpu-scene-optimizer-Cup4Yvzs.mjs"))).WebGpuSceneOptimizer(three);
|
|
3781
3805
|
return new Renderer(opts, {
|
|
3782
3806
|
three,
|
|
3783
3807
|
backend: "webgpu",
|
|
@@ -3997,9 +4021,11 @@ var Renderer = class Renderer {
|
|
|
3997
4021
|
const background = createLane(true);
|
|
3998
4022
|
const interest = signal === void 0 ? "pinned" : new WarmupInterest(this.cancel);
|
|
3999
4023
|
const deferred = [];
|
|
4024
|
+
const switching = [];
|
|
4000
4025
|
root.traverse((object) => {
|
|
4001
4026
|
const mesh = object;
|
|
4002
4027
|
if (!mesh.isMesh) return;
|
|
4028
|
+
if (mesh.userData.materialVariants !== void 0) switching.push(mesh);
|
|
4003
4029
|
if (deferredLevels !== void 0 && withinAny(mesh, root, deferredLevels)) deferred.push(mesh);
|
|
4004
4030
|
else this.prepareMesh(mesh, foreground, interest);
|
|
4005
4031
|
});
|
|
@@ -4018,6 +4044,7 @@ var Renderer = class Renderer {
|
|
|
4018
4044
|
if (this.deferredMeshes.get(mesh) === meshInterest) this.deferredMeshes.delete(mesh);
|
|
4019
4045
|
});
|
|
4020
4046
|
});
|
|
4047
|
+
for (const mesh of switching) this.prepareVariants(mesh);
|
|
4021
4048
|
for (const [lod, levels] of lods ?? []) if (levels.length > 0) this.guardLod(lod);
|
|
4022
4049
|
const release = () => {
|
|
4023
4050
|
if (interest !== "pinned") interest.release();
|
|
@@ -4150,6 +4177,55 @@ var Renderer = class Renderer {
|
|
|
4150
4177
|
}
|
|
4151
4178
|
lane.glBatches.length = 0;
|
|
4152
4179
|
}
|
|
4180
|
+
/**
|
|
4181
|
+
* A mesh that swaps its own material, as an instanced detail switch swaps in an opaque twin for
|
|
4182
|
+
* its coarser levels, lists every material in `userData.materialVariants`. Each needs its own
|
|
4183
|
+
* shader build, which the first frame to draw it would otherwise make mid-frame: in flight a whole
|
|
4184
|
+
* view of trees changed level at once and built their twins in one frame, for most of a second.
|
|
4185
|
+
* `userData.materialReady(material)` tells the mesh's owner whether one is ready. Until it is, the
|
|
4186
|
+
* owner keeps what it shows; asking queues its build ahead of other work. Most batches never
|
|
4187
|
+
* change level, so a variant is built only once its mesh asks for it.
|
|
4188
|
+
*/
|
|
4189
|
+
prepareVariants(mesh) {
|
|
4190
|
+
let builds = this.warmedVariants.get(mesh);
|
|
4191
|
+
if (builds === void 0) {
|
|
4192
|
+
builds = /* @__PURE__ */ new Map();
|
|
4193
|
+
this.warmedVariants.set(mesh, builds);
|
|
4194
|
+
}
|
|
4195
|
+
builds.set(mesh.material, null);
|
|
4196
|
+
mesh.userData.materialReady ??= (material) => this.variantReady(mesh, material);
|
|
4197
|
+
}
|
|
4198
|
+
/** Whether `mesh` can draw `material` without building it mid-frame; builds it first if not. */
|
|
4199
|
+
variantReady(mesh, material) {
|
|
4200
|
+
const builds = this.warmedVariants.get(mesh);
|
|
4201
|
+
const known = builds?.get(material);
|
|
4202
|
+
if (builds === void 0 || known === null) return true;
|
|
4203
|
+
let promise = known;
|
|
4204
|
+
if (promise === void 0) {
|
|
4205
|
+
let interest = this.variantInterests.get(mesh);
|
|
4206
|
+
if (interest === void 0) {
|
|
4207
|
+
interest = new WarmupInterest(this.cancel);
|
|
4208
|
+
releaseOnDispose(mesh, interest);
|
|
4209
|
+
this.variantInterests.set(mesh, interest);
|
|
4210
|
+
}
|
|
4211
|
+
const warmup = this.warmup(() => this.compileMesh(mesh, material), createLane(true), {
|
|
4212
|
+
label: "shader-variant",
|
|
4213
|
+
bytes: 0
|
|
4214
|
+
});
|
|
4215
|
+
interest.join(warmup);
|
|
4216
|
+
builds.set(material, warmup.promise);
|
|
4217
|
+
const forget = () => {
|
|
4218
|
+
if (builds.get(material) === warmup.promise) builds.delete(material);
|
|
4219
|
+
};
|
|
4220
|
+
warmup.forget.push(forget);
|
|
4221
|
+
warmup.promise.catch(forget);
|
|
4222
|
+
promise = warmup.promise;
|
|
4223
|
+
}
|
|
4224
|
+
const warmup = this.warmups.get(promise);
|
|
4225
|
+
if (warmup === void 0 || warmup.settled) return true;
|
|
4226
|
+
this.admission.promote(promise, { front: true });
|
|
4227
|
+
return false;
|
|
4228
|
+
}
|
|
4153
4229
|
/** Queue one cancellable warm-up job in the lane's admission priority. */
|
|
4154
4230
|
warmup(task, lane, options) {
|
|
4155
4231
|
const controller = new AbortController();
|
|
@@ -4238,15 +4314,24 @@ var Renderer = class Renderer {
|
|
|
4238
4314
|
warmup.forget.push(forget);
|
|
4239
4315
|
promise.catch(forget);
|
|
4240
4316
|
}
|
|
4241
|
-
|
|
4242
|
-
|
|
4317
|
+
/** Build `mesh` for the frame's draw target, drawn with `material` when given. */
|
|
4318
|
+
compileMesh(mesh, material) {
|
|
4319
|
+
const load = this.occlusionOptions !== void 0 ? this.occlusionLoad : void 0;
|
|
4320
|
+
if (load !== void 0 && this.occlusion === void 0) {
|
|
4321
|
+
const retry = () => this.compileMesh(mesh, material);
|
|
4322
|
+
return load.then(retry, retry);
|
|
4323
|
+
}
|
|
4324
|
+
const occlusion = this.occlusionOptions !== void 0 && this.occlusion?.camera === this.camera ? this.occlusion.pass : void 0;
|
|
4325
|
+
const visible = mesh.visible, culled = mesh.frustumCulled, shown = mesh.material;
|
|
4243
4326
|
mesh.visible = true;
|
|
4244
4327
|
mesh.frustumCulled = false;
|
|
4328
|
+
if (material !== void 0) mesh.material = material;
|
|
4245
4329
|
try {
|
|
4246
|
-
return this.three.compileAsync(mesh, this.camera, this.scene);
|
|
4330
|
+
return occlusion !== void 0 ? occlusion.compile(mesh) : this.three.compileAsync(mesh, this.camera, this.scene);
|
|
4247
4331
|
} finally {
|
|
4248
4332
|
mesh.visible = visible;
|
|
4249
4333
|
mesh.frustumCulled = culled;
|
|
4334
|
+
mesh.material = shown;
|
|
4250
4335
|
}
|
|
4251
4336
|
}
|
|
4252
4337
|
prepareWebGlGeometries(meshes) {
|
|
@@ -4317,8 +4402,23 @@ var Renderer = class Renderer {
|
|
|
4317
4402
|
this.hideReflectedAmbient(reflectedAmbient);
|
|
4318
4403
|
const baseFog = this.scene.fog;
|
|
4319
4404
|
if (weather) this.scene.fog = weather.fogFor(baseFog, sky?.frame);
|
|
4405
|
+
const occlusion = this.currentOcclusion();
|
|
4320
4406
|
try {
|
|
4321
|
-
if (
|
|
4407
|
+
if (occlusion) {
|
|
4408
|
+
if (sky) {
|
|
4409
|
+
sky.update(this.environmentTimeOverride ?? this.environmentSeconds);
|
|
4410
|
+
sky.prepareCamera(this.camera);
|
|
4411
|
+
}
|
|
4412
|
+
this.applyShadowFocus();
|
|
4413
|
+
const autoReset = this.three.info.autoReset;
|
|
4414
|
+
this.three.info.reset();
|
|
4415
|
+
this.three.info.autoReset = false;
|
|
4416
|
+
try {
|
|
4417
|
+
this.optimized(() => occlusion.render(sky, !this.occlusionSuspended));
|
|
4418
|
+
} finally {
|
|
4419
|
+
this.three.info.autoReset = autoReset;
|
|
4420
|
+
}
|
|
4421
|
+
} else if (sky) {
|
|
4322
4422
|
sky.update(this.environmentTimeOverride ?? this.environmentSeconds);
|
|
4323
4423
|
sky.prepareCamera(this.camera);
|
|
4324
4424
|
this.applyShadowFocus();
|
|
@@ -4369,20 +4469,70 @@ var Renderer = class Renderer {
|
|
|
4369
4469
|
light.visible = false;
|
|
4370
4470
|
}
|
|
4371
4471
|
renderScene() {
|
|
4472
|
+
this.optimized(() => this.three.render(this.scene, this.camera));
|
|
4473
|
+
}
|
|
4474
|
+
optimized(draw) {
|
|
4372
4475
|
if (this.optimizer === void 0) {
|
|
4373
|
-
|
|
4476
|
+
draw();
|
|
4374
4477
|
return;
|
|
4375
4478
|
}
|
|
4376
4479
|
this.optimizer.prepare(this.scene, this.camera);
|
|
4377
4480
|
const autoUpdate = this.scene.matrixWorldAutoUpdate;
|
|
4378
4481
|
this.scene.matrixWorldAutoUpdate = false;
|
|
4379
4482
|
try {
|
|
4380
|
-
|
|
4483
|
+
draw();
|
|
4381
4484
|
this.optimizer.finish();
|
|
4382
4485
|
} finally {
|
|
4383
4486
|
this.scene.matrixWorldAutoUpdate = autoUpdate;
|
|
4384
4487
|
}
|
|
4385
4488
|
}
|
|
4489
|
+
/**
|
|
4490
|
+
* Screen-space ambient occlusion on the WebGPU backend (a no-op on WebGL): creases, corners and
|
|
4491
|
+
* the ground around buildings and trees darken a little, as indirect light cannot reach them.
|
|
4492
|
+
* The frame then renders through a node pipeline; frames draw directly while it compiles.
|
|
4493
|
+
*/
|
|
4494
|
+
setAmbientOcclusion(enabled, options = {}) {
|
|
4495
|
+
if (this.disposed) throw new Error("Renderer has been disposed");
|
|
4496
|
+
const next = enabled && this.backend === "webgpu" ? { ...options } : void 0;
|
|
4497
|
+
const current = this.occlusionOptions;
|
|
4498
|
+
if (next !== void 0 && current !== void 0 && next.radius === current.radius && next.strength === current.strength && next.reach === current.reach) return;
|
|
4499
|
+
this.occlusion?.pass.dispose();
|
|
4500
|
+
this.occlusion = void 0;
|
|
4501
|
+
this.occlusionOptions = next;
|
|
4502
|
+
this.currentOcclusion();
|
|
4503
|
+
}
|
|
4504
|
+
/**
|
|
4505
|
+
* Skip the occlusion computation while keeping ambient occlusion set up: the frame still draws
|
|
4506
|
+
* into its target, and the image is copied out unshaded. Each object's shaders are built for
|
|
4507
|
+
* one draw target, so turning occlusion off and on again (`setAmbientOcclusion`) built every
|
|
4508
|
+
* object in view again, mid-frame, when the target changed; suspending changes nothing there.
|
|
4509
|
+
*/
|
|
4510
|
+
suspendAmbientOcclusion(suspended) {
|
|
4511
|
+
if (this.disposed) throw new Error("Renderer has been disposed");
|
|
4512
|
+
this.occlusionSuspended = suspended;
|
|
4513
|
+
}
|
|
4514
|
+
/** The occlusion pass for the current camera, building one in the background when needed. */
|
|
4515
|
+
currentOcclusion() {
|
|
4516
|
+
const options = this.occlusionOptions;
|
|
4517
|
+
if (options === void 0) return void 0;
|
|
4518
|
+
if (this.occlusion !== void 0 && this.occlusion.camera !== this.camera) {
|
|
4519
|
+
this.occlusion.pass.dispose();
|
|
4520
|
+
this.occlusion = void 0;
|
|
4521
|
+
}
|
|
4522
|
+
if (this.occlusion === void 0 && this.occlusionLoad === void 0) {
|
|
4523
|
+
const camera = this.camera;
|
|
4524
|
+
this.occlusionLoad = import("./webgpu-ambient-occlusion-9gnp3qOY.mjs").then(({ createWebGpuAmbientOcclusion }) => createWebGpuAmbientOcclusion(this.three, this.scene, camera, options)).then((pass) => {
|
|
4525
|
+
if (this.disposed || this.occlusionOptions !== options) pass.dispose();
|
|
4526
|
+
else this.occlusion = {
|
|
4527
|
+
camera,
|
|
4528
|
+
pass
|
|
4529
|
+
};
|
|
4530
|
+
}).finally(() => {
|
|
4531
|
+
this.occlusionLoad = void 0;
|
|
4532
|
+
});
|
|
4533
|
+
}
|
|
4534
|
+
return this.occlusion?.camera === this.camera ? this.occlusion.pass : void 0;
|
|
4535
|
+
}
|
|
4386
4536
|
/** Use for independent terrain/content chunks. WebGPU caches eligible opaque draw commands. */
|
|
4387
4537
|
createRenderGroup() {
|
|
4388
4538
|
return this.optimizer?.createGroup() ?? new THREE.Group();
|
|
@@ -4408,6 +4558,9 @@ var Renderer = class Renderer {
|
|
|
4408
4558
|
dispose() {
|
|
4409
4559
|
if (this.disposed) return;
|
|
4410
4560
|
this.disposed = true;
|
|
4561
|
+
this.occlusionOptions = void 0;
|
|
4562
|
+
this.occlusion?.pass.dispose();
|
|
4563
|
+
this.occlusion = void 0;
|
|
4411
4564
|
this.activeSky?.dispose();
|
|
4412
4565
|
this.activeSky = void 0;
|
|
4413
4566
|
this.activeWeather?.dispose();
|
|
@@ -4484,8 +4637,9 @@ function unselectedLodLevels(root, camera) {
|
|
|
4484
4637
|
const unselected = /* @__PURE__ */ new Map();
|
|
4485
4638
|
root.traverse((object) => {
|
|
4486
4639
|
const lod = object;
|
|
4487
|
-
if (!lod.isLOD || !lod.autoUpdate
|
|
4640
|
+
if (!lod.isLOD || !lod.autoUpdate) return;
|
|
4488
4641
|
lod.update(camera);
|
|
4642
|
+
if (lod.levels.length < 2) return;
|
|
4489
4643
|
const selected = lod.getCurrentLevel();
|
|
4490
4644
|
unselected.set(lod, lod.levels.filter((_, index) => index !== selected).map((level) => level.object));
|
|
4491
4645
|
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { a as readModelSignals, i as modelSignalDisplacement, n as ModelSignals, r as createModelSignalVisual, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
|
|
2
|
+
import { ModelSignalBinding, ModelSignalExpression, ModelSignalSpec } from "@bendyline/molen-schema";
|
|
3
|
+
|
|
4
|
+
//#region src/model-signal-expressions.d.ts
|
|
5
|
+
/** Compile a bounded dependency graph once. Evaluation is read-only and never executes code. */
|
|
6
|
+
declare function compileModelSignalExpressions(definitions: Record<string, ModelSignalExpression> | undefined): (sources: ModelSignals) => ModelSignals;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/instruments.d.ts
|
|
9
|
+
interface DialInstrumentOptions {
|
|
10
|
+
node: string;
|
|
11
|
+
source: string;
|
|
12
|
+
/** Measured [reading, needle radians from authored rest] pairs, including nonlinear scales. */
|
|
13
|
+
calibration: [number, number][];
|
|
14
|
+
axis?: "x" | "y" | "z";
|
|
15
|
+
responseSeconds?: number;
|
|
16
|
+
/** Usually 2π for a continuously rotating heading or altimeter needle. */
|
|
17
|
+
period?: number;
|
|
18
|
+
missing?: "hold" | "rest";
|
|
19
|
+
}
|
|
20
|
+
/** The same binding can calibrate tick placement with modelSignalDisplacement(binding, reading). */
|
|
21
|
+
declare function dialInstrument(options: DialInstrumentOptions): ModelSignalBinding;
|
|
22
|
+
interface AltimeterInstrumentOptions {
|
|
23
|
+
/** Caller supplies barometrically indicated altitude in feet, or explicitly labels an approximation. */
|
|
24
|
+
source: string;
|
|
25
|
+
hundreds: string;
|
|
26
|
+
thousands: string;
|
|
27
|
+
tenThousands?: string;
|
|
28
|
+
axis?: "x" | "y" | "z";
|
|
29
|
+
/** +Z facing the viewer uses -1 for clockwise motion. Reverse for a frame facing -Z. */
|
|
30
|
+
direction?: 1 | -1;
|
|
31
|
+
responseSeconds?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Three independent, continuous needles: one turn per 1,000 / 10,000 / 100,000 feet. */
|
|
34
|
+
declare function altimeterInstrument(options: AltimeterInstrumentOptions): ModelSignalBinding[];
|
|
35
|
+
interface AttitudeInstrumentOptions {
|
|
36
|
+
/** A bank frame containing the pitch card, inside the authored face mask. */
|
|
37
|
+
bankNode: string;
|
|
38
|
+
pitchNode: string;
|
|
39
|
+
rollSource?: string;
|
|
40
|
+
pitchSource?: string;
|
|
41
|
+
bankAxis?: "x" | "y" | "z";
|
|
42
|
+
pitchAxis?: "x" | "y" | "z";
|
|
43
|
+
/** Local meters per radian; sign follows the face's orientation. */
|
|
44
|
+
pitchScale: number;
|
|
45
|
+
pitchLimit: number;
|
|
46
|
+
bankDirection?: 1 | -1;
|
|
47
|
+
responseSeconds?: number;
|
|
48
|
+
}
|
|
49
|
+
/** Moving horizon behind a fixed aircraft symbol. Geometry supplies the circular mask. */
|
|
50
|
+
declare function attitudeInstrument(options: AttitudeInstrumentOptions): ModelSignalBinding[];
|
|
51
|
+
/** Own an authored lamp/flag node; positive means on, missing readings turn it off. */
|
|
52
|
+
declare function annunciatorInstrument(node: string, source: string): ModelSignalBinding;
|
|
53
|
+
interface NumericInstrumentOptions {
|
|
54
|
+
source: string;
|
|
55
|
+
/** Most-significant to least-significant digit; each has seven node names in a,b,c,d,e,f,g order. */
|
|
56
|
+
digits: [string, string, string, string, string, string, string][];
|
|
57
|
+
/** Prefix for private derived variables, unique when combining multiple readouts. */
|
|
58
|
+
prefix: string;
|
|
59
|
+
}
|
|
60
|
+
/** Fixed-width unsigned integer display; no DOM, textures or per-frame glyph allocation. */
|
|
61
|
+
declare function numericInstrument(options: NumericInstrumentOptions): ModelSignalSpec;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { AltimeterInstrumentOptions, AttitudeInstrumentOptions, DialInstrumentOptions, type ModelSignalVisual, type ModelSignals, NumericInstrumentOptions, altimeterInstrument, annunciatorInstrument, attitudeInstrument, compileModelSignalExpressions, createModelSignalVisual, dialInstrument, modelSignalDisplacement, numericInstrument, readModelSignals };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { i as compileModelSignalExpressions, n as modelSignalDisplacement, r as readModelSignals, t as createModelSignalVisual } from "./model-signals-DLgvjBeZ.mjs";
|
|
2
|
+
//#region src/instruments.ts
|
|
3
|
+
/** The same binding can calibrate tick placement with modelSignalDisplacement(binding, reading). */
|
|
4
|
+
function dialInstrument(options) {
|
|
5
|
+
return {
|
|
6
|
+
node: options.node,
|
|
7
|
+
source: options.source,
|
|
8
|
+
property: "rotation",
|
|
9
|
+
axis: options.axis ?? "z",
|
|
10
|
+
keys: options.calibration.map(([reading, angle]) => [reading, angle]),
|
|
11
|
+
responseSeconds: options.responseSeconds ?? 0,
|
|
12
|
+
...options.period === void 0 ? {} : { period: options.period },
|
|
13
|
+
missing: options.missing ?? "hold"
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Three independent, continuous needles: one turn per 1,000 / 10,000 / 100,000 feet. */
|
|
17
|
+
function altimeterInstrument(options) {
|
|
18
|
+
return [
|
|
19
|
+
[options.hundreds, 1e3],
|
|
20
|
+
[options.thousands, 1e4],
|
|
21
|
+
[options.tenThousands, 1e5]
|
|
22
|
+
].flatMap(([node, feet]) => node === void 0 ? [] : [{
|
|
23
|
+
node,
|
|
24
|
+
source: options.source,
|
|
25
|
+
property: "rotation",
|
|
26
|
+
axis: options.axis ?? "z",
|
|
27
|
+
scale: (options.direction ?? -1) * 2 * Math.PI / feet,
|
|
28
|
+
period: 2 * Math.PI,
|
|
29
|
+
responseSeconds: options.responseSeconds ?? 0
|
|
30
|
+
}]);
|
|
31
|
+
}
|
|
32
|
+
/** Moving horizon behind a fixed aircraft symbol. Geometry supplies the circular mask. */
|
|
33
|
+
function attitudeInstrument(options) {
|
|
34
|
+
return [{
|
|
35
|
+
node: options.bankNode,
|
|
36
|
+
source: options.rollSource ?? "roll",
|
|
37
|
+
property: "rotation",
|
|
38
|
+
axis: options.bankAxis ?? "z",
|
|
39
|
+
scale: options.bankDirection ?? -1,
|
|
40
|
+
period: 2 * Math.PI,
|
|
41
|
+
responseSeconds: options.responseSeconds ?? 0
|
|
42
|
+
}, {
|
|
43
|
+
node: options.pitchNode,
|
|
44
|
+
source: options.pitchSource ?? "pitch",
|
|
45
|
+
property: "position",
|
|
46
|
+
axis: options.pitchAxis ?? "y",
|
|
47
|
+
scale: options.pitchScale,
|
|
48
|
+
min: -Math.abs(options.pitchLimit),
|
|
49
|
+
max: Math.abs(options.pitchLimit),
|
|
50
|
+
responseSeconds: options.responseSeconds ?? 0
|
|
51
|
+
}];
|
|
52
|
+
}
|
|
53
|
+
/** Own an authored lamp/flag node; positive means on, missing readings turn it off. */
|
|
54
|
+
function annunciatorInstrument(node, source) {
|
|
55
|
+
return {
|
|
56
|
+
node,
|
|
57
|
+
source,
|
|
58
|
+
property: "visible",
|
|
59
|
+
scale: 1,
|
|
60
|
+
missing: "hide"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/** Fixed-width unsigned integer display; no DOM, textures or per-frame glyph allocation. */
|
|
64
|
+
function numericInstrument(options) {
|
|
65
|
+
if (!options.prefix || options.digits.length < 1 || options.digits.length > 9) throw new Error("Numeric instruments require a prefix and 1–9 digits");
|
|
66
|
+
const derived = Object.create(null);
|
|
67
|
+
const bindings = [];
|
|
68
|
+
const whole = `${options.prefix}.whole`;
|
|
69
|
+
derived[whole] = {
|
|
70
|
+
op: "floor",
|
|
71
|
+
args: [options.source]
|
|
72
|
+
};
|
|
73
|
+
const segmentMasks = [
|
|
74
|
+
63,
|
|
75
|
+
6,
|
|
76
|
+
91,
|
|
77
|
+
79,
|
|
78
|
+
102,
|
|
79
|
+
109,
|
|
80
|
+
125,
|
|
81
|
+
7,
|
|
82
|
+
127,
|
|
83
|
+
111
|
|
84
|
+
];
|
|
85
|
+
const valid = `${options.prefix}.valid`, positive = `${options.prefix}.positive`, inRange = `${options.prefix}.inRange`;
|
|
86
|
+
derived[positive] = {
|
|
87
|
+
op: "greater",
|
|
88
|
+
args: [whole, -1]
|
|
89
|
+
};
|
|
90
|
+
derived[inRange] = {
|
|
91
|
+
op: "less",
|
|
92
|
+
args: [whole, 10 ** options.digits.length]
|
|
93
|
+
};
|
|
94
|
+
derived[valid] = {
|
|
95
|
+
op: "and",
|
|
96
|
+
args: [positive, inRange]
|
|
97
|
+
};
|
|
98
|
+
options.digits.forEach((nodes, index) => {
|
|
99
|
+
const quotient = `${options.prefix}.${index}.quotient`, integer = `${options.prefix}.${index}.integer`;
|
|
100
|
+
const digit = `${options.prefix}.${index}.digit`, display = `${options.prefix}.${index}.display`;
|
|
101
|
+
derived[quotient] = {
|
|
102
|
+
op: "divide",
|
|
103
|
+
args: [whole, 10 ** (options.digits.length - index - 1)]
|
|
104
|
+
};
|
|
105
|
+
derived[integer] = {
|
|
106
|
+
op: "floor",
|
|
107
|
+
args: [quotient]
|
|
108
|
+
};
|
|
109
|
+
derived[digit] = {
|
|
110
|
+
op: "modulo",
|
|
111
|
+
args: [integer, 10]
|
|
112
|
+
};
|
|
113
|
+
derived[display] = {
|
|
114
|
+
op: "if",
|
|
115
|
+
args: [
|
|
116
|
+
valid,
|
|
117
|
+
digit,
|
|
118
|
+
-1
|
|
119
|
+
]
|
|
120
|
+
};
|
|
121
|
+
nodes.forEach((node, segment) => {
|
|
122
|
+
bindings.push({
|
|
123
|
+
node,
|
|
124
|
+
source: display,
|
|
125
|
+
property: "visible",
|
|
126
|
+
missing: "hide",
|
|
127
|
+
keys: [[-1, 0], ...segmentMasks.map((mask, number) => [number, Number((mask & 1 << segment) !== 0)])]
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
return {
|
|
132
|
+
derived,
|
|
133
|
+
bindings
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//#endregion
|
|
137
|
+
export { altimeterInstrument, annunciatorInstrument, attitudeInstrument, compileModelSignalExpressions, createModelSignalVisual, dialInstrument, modelSignalDisplacement, numericInstrument, readModelSignals };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModelSignalBinding, ModelSignalSource, ModelSignalSpec } from "@bendyline/molen-schema";
|
|
2
|
+
import { Object3D } from "three";
|
|
3
|
+
|
|
4
|
+
//#region src/model-signals.d.ts
|
|
5
|
+
type ModelSignals = Readonly<Record<string, number | undefined>>;
|
|
6
|
+
interface ModelSignalVisual {
|
|
7
|
+
readonly missingNodes: readonly string[];
|
|
8
|
+
/** Unavailable binding sources on the most recent update (including invalid formulas). */
|
|
9
|
+
readonly missingSignals: readonly string[];
|
|
10
|
+
/** Absolute simulation time enables responseSeconds; omission applies readings immediately. */
|
|
11
|
+
update(signals: ModelSignals, timeSeconds?: number): void;
|
|
12
|
+
/** Restore authored transforms before removing or replacing bindings. */
|
|
13
|
+
reset(): void;
|
|
14
|
+
}
|
|
15
|
+
/** Read data only: no expressions, evaluation, prototype traversal, or simulation writes. */
|
|
16
|
+
declare function readModelSignals(sources: Readonly<Record<string, ModelSignalSource>> | undefined, readComponent: (name: string) => unknown): ModelSignals;
|
|
17
|
+
/**
|
|
18
|
+
* A binding's displacement for a signal, before its limits: linear in the signal, or along its
|
|
19
|
+
* keyframed curve, which holds its end values outside the keys. Exported for tests.
|
|
20
|
+
*/
|
|
21
|
+
declare function modelSignalDisplacement(binding: ModelSignalBinding, signal: number): number;
|
|
22
|
+
/** Model-agnostic; moves existing geometry without creating a cockpit or changing physics. */
|
|
23
|
+
declare function createModelSignalVisual(model: Object3D, spec: ModelSignalSpec): ModelSignalVisual;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { readModelSignals as a, modelSignalDisplacement as i, ModelSignals as n, createModelSignalVisual as r, ModelSignalVisual as t };
|