@bendyline/molen-client 0.0.7 → 0.0.8
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
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-IbO4GJpF.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-
|
|
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-DPT7XAYh.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";
|
|
@@ -836,7 +836,7 @@ interface EnvironmentData {
|
|
|
836
836
|
near?: number;
|
|
837
837
|
far?: number;
|
|
838
838
|
};
|
|
839
|
-
toneMapping?: "none" | "aces" | "agx";
|
|
839
|
+
toneMapping?: "none" | "aces" | "agx" | "neutral";
|
|
840
840
|
exposure?: number;
|
|
841
841
|
shadows?: "off" | "low" | "medium" | "high";
|
|
842
842
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1143,7 +1143,7 @@ function applyEnvironment(renderer, env) {
|
|
|
1143
1143
|
renderer.three.shadowMap.type = shadows === "low" ? THREE.PCFShadowMap : THREE.PCFSoftShadowMap;
|
|
1144
1144
|
renderer.three.setClearColor(env.background !== void 0 ? new THREE.Color(env.background) : renderer.defaultClearColor, 1);
|
|
1145
1145
|
scene.fog = env.fog !== void 0 ? new THREE.Fog(new THREE.Color(env.fog.color), env.fog.near ?? 1, env.fog.far ?? 1e3) : null;
|
|
1146
|
-
renderer.three.toneMapping = env.toneMapping === "aces" ? THREE.ACESFilmicToneMapping : env.toneMapping === "agx" ? THREE.AgXToneMapping : THREE.NoToneMapping;
|
|
1146
|
+
renderer.three.toneMapping = env.toneMapping === "aces" ? THREE.ACESFilmicToneMapping : env.toneMapping === "agx" ? THREE.AgXToneMapping : env.toneMapping === "neutral" ? THREE.NeutralToneMapping : THREE.NoToneMapping;
|
|
1147
1147
|
renderer.three.toneMappingExposure = env.exposure ?? 1;
|
|
1148
1148
|
}
|
|
1149
1149
|
//#endregion
|
|
@@ -2711,14 +2711,15 @@ var SkyVisual = class {
|
|
|
2711
2711
|
this.moonLight.intensity *= 1 - this.cloudAttenuation * .9;
|
|
2712
2712
|
this.ambientLight.intensity *= 1 - this.cloudAttenuation * .2;
|
|
2713
2713
|
this.ambientLight.color.lerp(new THREE.Color("#b9c2cb"), this.cloudAttenuation * daylight * .6);
|
|
2714
|
+
const radiance = this.ambientLight.intensity / Math.PI;
|
|
2714
2715
|
this.currentReflections = {
|
|
2715
|
-
zenith: rgb$1(this.palette.nightZenith.clone().lerp(this.palette.dayZenith, daylight)),
|
|
2716
|
-
horizon: rgb$1(this.palette.nightHorizon.clone().lerp(this.palette.dayHorizon, daylight)),
|
|
2717
|
-
ground: rgb$1(this.palette.ground.clone().multiplyScalar(.08 + daylight * .92)),
|
|
2718
|
-
twilight: rgb$1(this.palette.twilight),
|
|
2716
|
+
zenith: rgb$1(this.palette.nightZenith.clone().lerp(this.palette.dayZenith, daylight).multiplyScalar(radiance)),
|
|
2717
|
+
horizon: rgb$1(this.palette.nightHorizon.clone().lerp(this.palette.dayHorizon, daylight).multiplyScalar(radiance)),
|
|
2718
|
+
ground: rgb$1(this.palette.ground.clone().multiplyScalar((.08 + daylight * .92) * radiance)),
|
|
2719
|
+
twilight: rgb$1(this.palette.twilight.clone().multiplyScalar(radiance)),
|
|
2719
2720
|
twilightStrength: smooth$2(-18, -4, altitude) * (1 - smooth$2(0, 16, altitude)),
|
|
2720
2721
|
sunDirection,
|
|
2721
|
-
sunColor: rgb$1(this.palette.sun),
|
|
2722
|
+
sunColor: rgb$1(this.palette.sun.clone().multiplyScalar(radiance)),
|
|
2722
2723
|
sunGlow: smooth$2(-2, 5, altitude) * .22,
|
|
2723
2724
|
clouds: this.cloudAttenuation
|
|
2724
2725
|
};
|
|
@@ -3292,7 +3293,7 @@ const scratchForward = new THREE.Vector3();
|
|
|
3292
3293
|
* vector toward the sun), covering ±`radius`. The light and its target move; the direction of
|
|
3293
3294
|
* the light is unchanged.
|
|
3294
3295
|
*/
|
|
3295
|
-
function focusDirectionalShadow(light, direction, center, radius) {
|
|
3296
|
+
function focusDirectionalShadow(light, direction, center, radius, biasAddsTowardLight = false) {
|
|
3296
3297
|
const toSun = scratchForward.copy(direction).normalize();
|
|
3297
3298
|
const size = light.shadow.mapSize.x || 2048;
|
|
3298
3299
|
const texel = 2 * radius / size;
|
|
@@ -3319,7 +3320,7 @@ function focusDirectionalShadow(light, direction, center, radius) {
|
|
|
3319
3320
|
camera.far = distance + radius * 2 + 1e3;
|
|
3320
3321
|
camera.updateProjectionMatrix();
|
|
3321
3322
|
}
|
|
3322
|
-
light.shadow.bias = -4e-4;
|
|
3323
|
+
light.shadow.bias = biasAddsTowardLight ? 4e-4 : -4e-4;
|
|
3323
3324
|
light.shadow.normalBias = texel * 1.2;
|
|
3324
3325
|
}
|
|
3325
3326
|
//#endregion
|
|
@@ -3572,6 +3573,8 @@ var Renderer = class Renderer {
|
|
|
3572
3573
|
optimizer;
|
|
3573
3574
|
activeSky;
|
|
3574
3575
|
reflections;
|
|
3576
|
+
/** Sun lights whose WebGPU shadow map exists and must not be torn down; see setShadowQuality. */
|
|
3577
|
+
webgpuShadowLights = /* @__PURE__ */ new WeakSet();
|
|
3575
3578
|
reflectionClearColor = Object.assign(new THREE.Color(), { a: 1 });
|
|
3576
3579
|
starCatalog;
|
|
3577
3580
|
activeWeather;
|
|
@@ -3606,18 +3609,32 @@ var Renderer = class Renderer {
|
|
|
3606
3609
|
setShadowQuality(quality) {
|
|
3607
3610
|
const enabled = quality !== "off";
|
|
3608
3611
|
for (const light of this.sunLights()) {
|
|
3612
|
+
if (this.backend === "webgpu" && this.webgpuShadowLights.has(light)) {
|
|
3613
|
+
light.shadow.autoUpdate = enabled;
|
|
3614
|
+
light.shadow.intensity = enabled ? 1 : 0;
|
|
3615
|
+
continue;
|
|
3616
|
+
}
|
|
3609
3617
|
light.castShadow = enabled;
|
|
3610
3618
|
if (!enabled) continue;
|
|
3611
3619
|
const size = SHADOW_MAP_SIZE[quality];
|
|
3612
3620
|
if (light.shadow.mapSize.x !== size) {
|
|
3613
3621
|
light.shadow.mapSize.set(size, size);
|
|
3614
|
-
|
|
3615
|
-
|
|
3622
|
+
if (this.backend === "webgl") {
|
|
3623
|
+
light.shadow.map?.dispose();
|
|
3624
|
+
light.shadow.map = null;
|
|
3625
|
+
}
|
|
3616
3626
|
}
|
|
3627
|
+
if (this.backend === "webgpu") this.webgpuShadowLights.add(light);
|
|
3617
3628
|
}
|
|
3629
|
+
if (this.backend === "webgpu" && this.three.shadowMap.enabled) return;
|
|
3618
3630
|
this.three.shadowMap.enabled = enabled;
|
|
3619
3631
|
this.three.shadowMap.type = quality === "low" ? THREE.PCFShadowMap : THREE.PCFSoftShadowMap;
|
|
3620
3632
|
}
|
|
3633
|
+
/** WebGL PCF shadow lookups against a reversed depth buffer; see focusDirectionalShadow. */
|
|
3634
|
+
webglReversedPcfShadows() {
|
|
3635
|
+
const three = this.three;
|
|
3636
|
+
return three.state?.buffers.depth.getReversed() === true && three.shadowMap.type !== THREE.BasicShadowMap && three.shadowMap.type !== THREE.VSMShadowMap;
|
|
3637
|
+
}
|
|
3621
3638
|
/** The directional lights standing for the sun: the environment rig's, and the sky's. */
|
|
3622
3639
|
sunLights() {
|
|
3623
3640
|
const lights = [];
|
|
@@ -3633,7 +3650,7 @@ var Renderer = class Renderer {
|
|
|
3633
3650
|
const center = this.shadowCenter.set(focus.center[0] - this.worldOrigin[0], focus.center[1] - this.worldOrigin[1], focus.center[2] - this.worldOrigin[2]);
|
|
3634
3651
|
for (const light of this.sunLights()) {
|
|
3635
3652
|
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);
|
|
3653
|
+
focusDirectionalShadow(light, light === this.activeSky?.sunLight ? this.shadowDirection.fromArray(this.activeSky.frame.sunDirection) : this.shadowDirection.copy(light.userData.molenSunDirection), center, focus.radius, this.backend === "webgl" && this.webglReversedPcfShadows());
|
|
3637
3654
|
}
|
|
3638
3655
|
}
|
|
3639
3656
|
/** Active weather effects; physical weather data is also available in the simulation component. */
|
|
@@ -3704,7 +3721,7 @@ var Renderer = class Renderer {
|
|
|
3704
3721
|
late.dispose();
|
|
3705
3722
|
});
|
|
3706
3723
|
try {
|
|
3707
|
-
const optimizer = opts.optimizeWebGpu === false ? void 0 : new (await (import("./webgpu-scene-optimizer-
|
|
3724
|
+
const optimizer = opts.optimizeWebGpu === false ? void 0 : new (await (import("./webgpu-scene-optimizer-DKRyHBRC.mjs"))).WebGpuSceneOptimizer(three);
|
|
3708
3725
|
return new Renderer(opts, {
|
|
3709
3726
|
three,
|
|
3710
3727
|
backend: "webgpu",
|
|
@@ -297,6 +297,8 @@ declare class WebGpuSceneOptimizer {
|
|
|
297
297
|
private readonly renderHook;
|
|
298
298
|
private readonly groups;
|
|
299
299
|
private active;
|
|
300
|
+
/** Bundled groups set aside between frames; see `finish`. */
|
|
301
|
+
private suspended;
|
|
300
302
|
private frame;
|
|
301
303
|
private stableCameraFrames;
|
|
302
304
|
private cameraState;
|
|
@@ -459,6 +461,8 @@ declare class Renderer {
|
|
|
459
461
|
private readonly optimizer;
|
|
460
462
|
private activeSky;
|
|
461
463
|
private readonly reflections;
|
|
464
|
+
/** Sun lights whose WebGPU shadow map exists and must not be torn down; see setShadowQuality. */
|
|
465
|
+
private readonly webgpuShadowLights;
|
|
462
466
|
private readonly reflectionClearColor;
|
|
463
467
|
private starCatalog;
|
|
464
468
|
private activeWeather;
|
|
@@ -480,6 +484,8 @@ declare class Renderer {
|
|
|
480
484
|
setShadowFocus(focus: ShadowFocus | undefined): void;
|
|
481
485
|
/** Turn sun shadows on at a map resolution, or off, without rebuilding the environment. */
|
|
482
486
|
setShadowQuality(quality: ShadowQuality): void;
|
|
487
|
+
/** WebGL PCF shadow lookups against a reversed depth buffer; see focusDirectionalShadow. */
|
|
488
|
+
private webglReversedPcfShadows;
|
|
483
489
|
/** The directional lights standing for the sun: the environment rig's, and the sky's. */
|
|
484
490
|
private sunLights;
|
|
485
491
|
private applyShadowFocus;
|
|
@@ -76,6 +76,8 @@ var WebGpuSceneOptimizer = class {
|
|
|
76
76
|
renderHook;
|
|
77
77
|
groups = /* @__PURE__ */ new WeakSet();
|
|
78
78
|
active = [];
|
|
79
|
+
/** Bundled groups set aside between frames; see `finish`. */
|
|
80
|
+
suspended = [];
|
|
79
81
|
frame = 0;
|
|
80
82
|
stableCameraFrames = 0;
|
|
81
83
|
cameraState = [];
|
|
@@ -92,7 +94,7 @@ var WebGpuSceneOptimizer = class {
|
|
|
92
94
|
const refresh = nodes.needsRefresh;
|
|
93
95
|
nodes.needsRefresh = (object) => {
|
|
94
96
|
const group = object.bundle;
|
|
95
|
-
if (group !== null && this.groups.has(group) && group.eligible && group.version === group.recordedVersion && !renderer.getMRT()?.has("velocity")) {
|
|
97
|
+
if (group !== null && this.groups.has(group) && group.eligible && group.version === group.recordedVersion && !renderer.shadowMap.enabled && !renderer.getMRT()?.has("velocity")) {
|
|
96
98
|
const monitor = object.getMonitor();
|
|
97
99
|
if (!monitor.hasNode && !monitor.hasAnimation && monitor.renderObjects.has(object)) return false;
|
|
98
100
|
}
|
|
@@ -131,6 +133,8 @@ var WebGpuSceneOptimizer = class {
|
|
|
131
133
|
/** Update matrices once; Renderer suppresses Three's duplicate scene traversal for this frame. */
|
|
132
134
|
prepare(scene, camera) {
|
|
133
135
|
this.frame++;
|
|
136
|
+
for (const group of this.suspended) Object.assign(group, { isBundleGroup: true });
|
|
137
|
+
this.suspended = [];
|
|
134
138
|
this.active = [];
|
|
135
139
|
this.materialSamples.clear();
|
|
136
140
|
if (scene.matrixWorldAutoUpdate) scene.updateMatrixWorld();
|
|
@@ -155,6 +159,8 @@ var WebGpuSceneOptimizer = class {
|
|
|
155
159
|
scene.environmentIntensity,
|
|
156
160
|
this.renderer.toneMapping,
|
|
157
161
|
this.renderer.toneMappingExposure,
|
|
162
|
+
this.renderer.shadowMap.enabled,
|
|
163
|
+
this.renderer.shadowMap.type,
|
|
158
164
|
this.renderer.outputColorSpace,
|
|
159
165
|
this.frameSize.x,
|
|
160
166
|
this.frameSize.y,
|
|
@@ -175,6 +181,8 @@ var WebGpuSceneOptimizer = class {
|
|
|
175
181
|
if (object instanceof THREE.Light) {
|
|
176
182
|
lights.push(object, ...object.matrixWorld.elements);
|
|
177
183
|
for (const value of Object.values(object)) this.sampleValue(lights, value);
|
|
184
|
+
const shadow = object.shadow;
|
|
185
|
+
if (shadow !== void 0) lights.push(object.castShadow, shadow.mapSize.x, shadow.mapSize.y, shadow.map);
|
|
178
186
|
}
|
|
179
187
|
if (object instanceof THREE.DirectionalLight || object instanceof THREE.SpotLight) {
|
|
180
188
|
lights.push(...object.target.matrixWorld.elements);
|
|
@@ -189,7 +197,7 @@ var WebGpuSceneOptimizer = class {
|
|
|
189
197
|
own.cursor = 0;
|
|
190
198
|
own.changed = false;
|
|
191
199
|
own.writeArray(view);
|
|
192
|
-
own.eligible = cacheView &&
|
|
200
|
+
own.eligible = cacheView && scene.overrideMaterial === null && scene.onBeforeRender === THREE.Object3D.prototype.onBeforeRender && this.renderer.getRenderObjectFunction() === this.renderHook && this.renderer.xr?.isPresenting !== true;
|
|
193
201
|
this.active.push(own);
|
|
194
202
|
}
|
|
195
203
|
if (group !== void 0 && cacheView) {
|
|
@@ -257,6 +265,11 @@ var WebGpuSceneOptimizer = class {
|
|
|
257
265
|
};
|
|
258
266
|
group.recordedVersion = group.version;
|
|
259
267
|
}
|
|
268
|
+
for (const group of this.active) {
|
|
269
|
+
if (!group.isBundleGroup) continue;
|
|
270
|
+
Object.assign(group, { isBundleGroup: false });
|
|
271
|
+
this.suspended.push(group);
|
|
272
|
+
}
|
|
260
273
|
}
|
|
261
274
|
sampleMatrix(matrix) {
|
|
262
275
|
let sample = this.matrixSamples.get(matrix);
|
|
@@ -312,6 +325,7 @@ var WebGpuSceneOptimizer = class {
|
|
|
312
325
|
this.restoreRefresh();
|
|
313
326
|
this.instances.dispose();
|
|
314
327
|
this.active = [];
|
|
328
|
+
this.suspended = [];
|
|
315
329
|
this.materialSamples.clear();
|
|
316
330
|
}
|
|
317
331
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/molen-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
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.7",
|
|
72
|
+
"@bendyline/molen-schema": "0.0.6"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"@types/three": ">=0.184.0 <0.187.0",
|