@bendyline/molen-client 0.0.2 → 0.0.3
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 +3 -0
- package/dist/assets-Bp0ox8YY.d.mts +59 -0
- package/dist/audio.d.mts +526 -0
- package/dist/audio.mjs +1740 -0
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +19 -167
- package/dist/index.mjs +725 -482
- package/dist/input-CD-dHuv0.d.mts +120 -0
- package/dist/input-CfbIm1MS.mjs +361 -0
- package/dist/markers.d.mts +127 -0
- package/dist/markers.mjs +308 -0
- package/dist/navigation.d.mts +529 -0
- package/dist/navigation.mjs +1402 -0
- package/dist/{renderer-B3pd4N-J.d.mts → renderer-DfWc3MFM.d.mts} +111 -5
- package/dist/vehicles.d.mts +14 -2
- package/dist/vehicles.mjs +82 -25
- package/dist/webgpu-driver-Bt2mvZk9.mjs +165 -0
- package/dist/webgpu-sky-reflections-CymGEes-.mjs +22 -0
- package/package.json +17 -4
- package/dist/webgpu-driver-DXsRuz8j.mjs +0 -75
|
@@ -8,6 +8,8 @@ interface AdmissionOptions {
|
|
|
8
8
|
bytes?: number;
|
|
9
9
|
signal?: AbortSignal;
|
|
10
10
|
label?: string;
|
|
11
|
+
/** Background jobs run only in frame budget that no normal job is waiting for. */
|
|
12
|
+
priority?: "normal" | "background";
|
|
11
13
|
}
|
|
12
14
|
interface AdmissionSample {
|
|
13
15
|
label: string;
|
|
@@ -15,6 +17,8 @@ interface AdmissionSample {
|
|
|
15
17
|
workMs: number;
|
|
16
18
|
bytes: number;
|
|
17
19
|
overBudget: boolean;
|
|
20
|
+
/** Ran from the background lane, so its queue time was deliberately deferred. */
|
|
21
|
+
background: boolean;
|
|
18
22
|
}
|
|
19
23
|
interface SceneAdmission {
|
|
20
24
|
run<T>(task: () => T, options?: AdmissionOptions): Promise<T>;
|
|
@@ -30,6 +34,8 @@ interface FrameAdmissionOptions {
|
|
|
30
34
|
declare class FrameAdmissionQueue implements SceneAdmission {
|
|
31
35
|
private readonly options;
|
|
32
36
|
private jobs;
|
|
37
|
+
private background;
|
|
38
|
+
private readonly queuedBackground;
|
|
33
39
|
private scheduled;
|
|
34
40
|
private disposed;
|
|
35
41
|
private readonly clock;
|
|
@@ -39,6 +45,13 @@ declare class FrameAdmissionQueue implements SceneAdmission {
|
|
|
39
45
|
private readonly maxJobs;
|
|
40
46
|
constructor(options?: FrameAdmissionOptions);
|
|
41
47
|
run<T>(task: () => T, options?: AdmissionOptions): Promise<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Callers keep the promise (preparation caches do, keyed by long-lived resources); the job holds
|
|
50
|
+
* the task and everything it captured. Only a queued job may stay reachable from its promise.
|
|
51
|
+
*/
|
|
52
|
+
private forget;
|
|
53
|
+
/** Move a still-queued background job to the normal lane, behind the jobs already there. */
|
|
54
|
+
promote(promise: Promise<unknown>): void;
|
|
42
55
|
get pending(): number;
|
|
43
56
|
private request;
|
|
44
57
|
/** One frame's budget. Exposed for hosts with a manual frame loop and deterministic tests. */
|
|
@@ -46,6 +59,49 @@ declare class FrameAdmissionQueue implements SceneAdmission {
|
|
|
46
59
|
dispose(): void;
|
|
47
60
|
}
|
|
48
61
|
//#endregion
|
|
62
|
+
//#region src/three/sky-reflections.d.ts
|
|
63
|
+
type RGB = readonly [number, number, number];
|
|
64
|
+
/** Scene-linear radiance, independent of camera position and floating world origin. */
|
|
65
|
+
interface SkyReflectionState {
|
|
66
|
+
zenith: RGB;
|
|
67
|
+
horizon: RGB;
|
|
68
|
+
ground: RGB;
|
|
69
|
+
twilight: RGB;
|
|
70
|
+
twilightStrength: number;
|
|
71
|
+
sunDirection: RGB;
|
|
72
|
+
sunColor: RGB;
|
|
73
|
+
sunGlow: number;
|
|
74
|
+
clouds: number;
|
|
75
|
+
}
|
|
76
|
+
/** A backend owns one PMREM generator and reuses its render target across lighting changes. */
|
|
77
|
+
interface SkyReflectionFilter {
|
|
78
|
+
update(texture: THREE.DataTexture): THREE.Texture;
|
|
79
|
+
dispose(): void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One small half-float panorama and filtered target per viewer; no model-specific textures or
|
|
83
|
+
* network fetches. Quantization suppresses imperceptible ephemeris changes and camera motion
|
|
84
|
+
* never invalidates the map. Explicit host-assigned scene.environment textures take priority.
|
|
85
|
+
*/
|
|
86
|
+
declare class SkyReflections {
|
|
87
|
+
private readonly scene;
|
|
88
|
+
private readonly filter;
|
|
89
|
+
readonly texture: THREE.DataTexture;
|
|
90
|
+
private readonly pixels;
|
|
91
|
+
private readonly directions;
|
|
92
|
+
private key;
|
|
93
|
+
private result;
|
|
94
|
+
private disposed;
|
|
95
|
+
/** False when a host has replaced the scene environment with its own texture. */
|
|
96
|
+
get active(): boolean;
|
|
97
|
+
constructor(scene: THREE.Scene, filter: SkyReflectionFilter);
|
|
98
|
+
update(state: SkyReflectionState): boolean;
|
|
99
|
+
dispose(): void;
|
|
100
|
+
}
|
|
101
|
+
declare function createWebGlSkyReflectionFilter(renderer: THREE.WebGLRenderer): SkyReflectionFilter;
|
|
102
|
+
/** Fallback for authored/static light rigs without a celestial SkyVisual. */
|
|
103
|
+
declare function reflectionStateFromLights(ambient: THREE.HemisphereLight | undefined, sun: THREE.DirectionalLight | undefined, background: THREE.Color, clouds: number): SkyReflectionState;
|
|
104
|
+
//#endregion
|
|
49
105
|
//#region src/sky/astronomy.d.ts
|
|
50
106
|
interface CelestialPosition {
|
|
51
107
|
/** Unit vector toward the body; Y-up, default +X east / -Z north. */
|
|
@@ -128,9 +184,12 @@ declare class SkyVisual {
|
|
|
128
184
|
private lastTime;
|
|
129
185
|
private cloudAttenuation;
|
|
130
186
|
private currentFrame;
|
|
187
|
+
private currentReflections;
|
|
131
188
|
private disposed;
|
|
132
189
|
constructor(data: SkyData, options?: SkyVisualOptions);
|
|
133
190
|
get frame(): SkyFrame;
|
|
191
|
+
/** Sky radiance for the viewer's shared PBR environment, sampled with the celestial frame. */
|
|
192
|
+
get reflectionState(): SkyReflectionState;
|
|
134
193
|
/** Diffuse cloud lighting; actual celestial occlusion comes from the cloud layer geometry. */
|
|
135
194
|
setCloudAttenuation(value: number): void;
|
|
136
195
|
/** Move an Earth observer without rebuilding the dome, bodies or star catalog. */
|
|
@@ -260,8 +319,11 @@ interface InitializedRenderer {
|
|
|
260
319
|
three: ThreeRenderer;
|
|
261
320
|
backend: RendererBackend;
|
|
262
321
|
optimizer?: WebGpuSceneOptimizer;
|
|
322
|
+
reflectionFilter?: SkyReflectionFilter;
|
|
263
323
|
}
|
|
264
324
|
interface RendererOptions {
|
|
325
|
+
/** Shared procedural sky/ground reflections for PBR materials. Default false; Earth viewers enable it. */
|
|
326
|
+
reflections?: boolean;
|
|
265
327
|
admission?: FrameAdmissionOptions;
|
|
266
328
|
/**
|
|
267
329
|
* Which graphics backend to use. Defaults to `'auto'`: probe WebGPU, fall back to WebGL.
|
|
@@ -288,7 +350,7 @@ interface RendererOptions {
|
|
|
288
350
|
/** WebGL only. WebGPU presentation does not preserve the drawing buffer between frames. */
|
|
289
351
|
preserveDrawingBuffer?: boolean;
|
|
290
352
|
powerPreference?: "default" | "high-performance" | "low-power";
|
|
291
|
-
/** Better depth precision for large view ranges; WebGL
|
|
353
|
+
/** Better depth precision for large view ranges; WebGL uses logarithmic depth if EXT_clip_control is unavailable. */
|
|
292
354
|
reverseDepthBuffer?: boolean;
|
|
293
355
|
/** Compatibility fallback for large view ranges; costs early-fragment performance. */
|
|
294
356
|
logarithmicDepthBuffer?: boolean;
|
|
@@ -299,6 +361,13 @@ interface RendererOptions {
|
|
|
299
361
|
/** Background clear color, default a mid grey. */
|
|
300
362
|
clearColor?: string;
|
|
301
363
|
/**
|
|
364
|
+
* WebGL only: `dispose()` also releases the GL context (`forceContextLoss`). Browsers cap live
|
|
365
|
+
* contexts per page (Chromium keeps 16), so a single-page host that mounts and unmounts viewers
|
|
366
|
+
* should enable this; each mount then needs a fresh canvas, because a lost context stays
|
|
367
|
+
* attached to its canvas. Default false keeps a canvas reusable after dispose.
|
|
368
|
+
*/
|
|
369
|
+
releaseContextOnDispose?: boolean;
|
|
370
|
+
/**
|
|
302
371
|
* Stars for every sky, e.g. `decodeStarCatalog` of the `molen.sky` content pack's `stars.bin`.
|
|
303
372
|
* Without a catalog, skies show no stars; `setStarCatalog` supplies one later.
|
|
304
373
|
*/
|
|
@@ -347,6 +416,12 @@ declare class Renderer {
|
|
|
347
416
|
private warmupMaterial;
|
|
348
417
|
private readonly warmedPrograms;
|
|
349
418
|
private readonly warmedMeshes;
|
|
419
|
+
private readonly warmups;
|
|
420
|
+
/** Deferred meshes whose preparation has not settled, with the interest that can promote it. */
|
|
421
|
+
private readonly deferredMeshes;
|
|
422
|
+
private readonly guardedLods;
|
|
423
|
+
/** Shared by every interest, so none captures the scope (and object tree) that created it. */
|
|
424
|
+
private readonly cancel;
|
|
350
425
|
readonly three: ThreeRenderer;
|
|
351
426
|
readonly backend: RendererBackend;
|
|
352
427
|
private fallback;
|
|
@@ -370,15 +445,19 @@ declare class Renderer {
|
|
|
370
445
|
private readonly autoWorldOrigin;
|
|
371
446
|
private readonly timers;
|
|
372
447
|
private disposed;
|
|
448
|
+
private readonly releaseContextOnDispose;
|
|
373
449
|
private deviceLossReason;
|
|
374
450
|
private readonly optimizer;
|
|
375
451
|
private activeSky;
|
|
452
|
+
private readonly reflections;
|
|
453
|
+
private readonly reflectionClearColor;
|
|
376
454
|
private starCatalog;
|
|
377
455
|
private activeWeather;
|
|
378
456
|
private weatherTimeOverride;
|
|
379
457
|
private readonly weatherLightIntensities;
|
|
380
458
|
private environmentSeconds;
|
|
381
459
|
private environmentTimeOverride;
|
|
460
|
+
private readonly lastRenderStats;
|
|
382
461
|
/** Active clear-sky visual and sampled ephemeris, when environment.sky is configured. */
|
|
383
462
|
get sky(): SkyVisual | undefined;
|
|
384
463
|
/** Active weather effects; physical weather data is also available in the simulation component. */
|
|
@@ -407,6 +486,8 @@ declare class Renderer {
|
|
|
407
486
|
/** Shift all engine-owned world objects near the local origin without changing world poses. */
|
|
408
487
|
setWorldOrigin(origin: Vec3): void;
|
|
409
488
|
getWorldOrigin(): Vec3;
|
|
489
|
+
/** Drawing size in CSS pixels as last passed to `setSize` (before the pixel ratio). */
|
|
490
|
+
getViewportSize(): [number, number];
|
|
410
491
|
setCameraClip(near: number, far: number): void;
|
|
411
492
|
private applyCameraPose;
|
|
412
493
|
private maybeRebase;
|
|
@@ -424,8 +505,33 @@ declare class Renderer {
|
|
|
424
505
|
*/
|
|
425
506
|
setPixelRatio(ratio: number): void;
|
|
426
507
|
setSize(width: number, height: number): void;
|
|
427
|
-
/**
|
|
428
|
-
|
|
508
|
+
/**
|
|
509
|
+
* Prepare shared resources once; all dependants await the same admission jobs.
|
|
510
|
+
*
|
|
511
|
+
* With `parent` (the object this root will be added to), LODs are evaluated for the current
|
|
512
|
+
* camera as if attached: the levels they select are prepared before this resolves, and the
|
|
513
|
+
* other levels afterwards in the background, so publication waits only for what can be seen.
|
|
514
|
+
* Queued work is cancelled once every caller waiting for it has aborted, and background work
|
|
515
|
+
* once its mesh or geometry is disposed.
|
|
516
|
+
*/
|
|
517
|
+
prepareObject(root: THREE.Object3D, signal?: AbortSignal, parent?: THREE.Object3D): Promise<void>;
|
|
518
|
+
private prepareMesh;
|
|
519
|
+
private flushWebGlBatches;
|
|
520
|
+
/** Queue one cancellable warm-up job in the lane's admission priority. */
|
|
521
|
+
private warmup;
|
|
522
|
+
/**
|
|
523
|
+
* Until every level is prepared, an LOD keeps showing a prepared level rather than the one it
|
|
524
|
+
* selects: drawing an unprepared level would build its shaders synchronously, mid-frame. The
|
|
525
|
+
* wanted level's background work moves to the normal lane. Three and the scene optimizer call
|
|
526
|
+
* `update` each frame for visible LODs, so the guard costs nothing elsewhere and removes itself.
|
|
527
|
+
*/
|
|
528
|
+
private guardLod;
|
|
529
|
+
/** Returns whether any level is still being prepared. */
|
|
530
|
+
private holdUnpreparedLevel;
|
|
531
|
+
/** Whether `object` still has deferred preparation, optionally moving it to the normal lane. */
|
|
532
|
+
private pendingWithin;
|
|
533
|
+
/** Nobody waits any longer: drop the job from every cache first, then from the queue. */
|
|
534
|
+
private cancelWarmup;
|
|
429
535
|
private rememberPreparation;
|
|
430
536
|
private compileMesh;
|
|
431
537
|
private prepareWebGlGeometries;
|
|
@@ -433,7 +539,7 @@ declare class Renderer {
|
|
|
433
539
|
private renderScene;
|
|
434
540
|
/** Use for independent terrain/content chunks. WebGPU caches eligible opaque draw commands. */
|
|
435
541
|
createRenderGroup(): THREE.Group;
|
|
436
|
-
/**
|
|
542
|
+
/** Last completed visible frame, excluding offscreen resource preparation. */
|
|
437
543
|
stats(): {
|
|
438
544
|
drawCalls: number;
|
|
439
545
|
triangles: number;
|
|
@@ -443,4 +549,4 @@ declare class Renderer {
|
|
|
443
549
|
dispose(): void;
|
|
444
550
|
}
|
|
445
551
|
//#endregion
|
|
446
|
-
export { skyTimeMs as C,
|
|
552
|
+
export { AdmissionOptions as A, skyTimeMs as C, SkyReflections as D, SkyReflectionState as E, FrameAdmissionOptions as M, FrameAdmissionQueue as N, createWebGlSkyReflectionFilter as O, SceneAdmission as P, evaluateEarthSky as S, SkyReflectionFilter as T, SkyVisual as _, RendererBackendPreference as a, CelestialPosition as b, TopDownOrtho as c, GpuFrameTimer as d, GpuFrameTimerOptions as f, SkyStar as g, SkyFrame as h, RendererBackend as i, AdmissionSample as j, reflectionStateFromLights as k, nextWorldOrigin as l, WeatherVisual as m, CameraPose as n, RendererOptions as o, createGpuFrameTimer as p, Renderer as r, ThreeRenderer as s, AutoWorldOriginOptions as t, orthoFrustum as u, SkyVisualOptions as v, starDirection as w, EarthSkyState as x, defaultSkyPalette as y };
|
package/dist/vehicles.d.mts
CHANGED
|
@@ -11,7 +11,19 @@ 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
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Dormant terrain-owned cars merged into one static mesh per tile. A plain mesh shares its
|
|
16
|
+
* compiled shader with every other tile; an instanced batch per model and paint would build one
|
|
17
|
+
* of its own. `userData.vehicleIds[i]` owns vertex range `userData.vehicleRanges[2i..2i+1]`;
|
|
18
|
+
* hide and restore a car with `setParkedVehicleHidden`.
|
|
19
|
+
*/
|
|
15
20
|
declare function createParkedVehicleBatch(placements: readonly VehiclePlacement[], origin?: [number, number]): THREE.Group;
|
|
21
|
+
/** Whether `setParkedVehicleHidden` currently hides car `index` of a parked batch. */
|
|
22
|
+
declare function isParkedVehicleHidden(batch: THREE.Mesh, index: number): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Hide (collapse to a point) or restore one car of a parked batch, e.g. while its detailed
|
|
25
|
+
* model or a driven entity stands in for it. Returns whether the geometry changed.
|
|
26
|
+
*/
|
|
27
|
+
declare function setParkedVehicleHidden(batch: THREE.Mesh, index: number, hidden: boolean): boolean;
|
|
16
28
|
//#endregion
|
|
17
|
-
export { type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, VehicleVisual, createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, vehicleCameraPose };
|
|
29
|
+
export { type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, VehicleVisual, createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose };
|
package/dist/vehicles.mjs
CHANGED
|
@@ -137,38 +137,95 @@ function parkedTemplate(spec, color) {
|
|
|
137
137
|
parkedTemplates.set(key, geometry);
|
|
138
138
|
return geometry;
|
|
139
139
|
}
|
|
140
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Dormant terrain-owned cars merged into one static mesh per tile. A plain mesh shares its
|
|
142
|
+
* compiled shader with every other tile; an instanced batch per model and paint would build one
|
|
143
|
+
* of its own. `userData.vehicleIds[i]` owns vertex range `userData.vehicleRanges[2i..2i+1]`;
|
|
144
|
+
* hide and restore a car with `setParkedVehicleHidden`.
|
|
145
|
+
*/
|
|
141
146
|
function createParkedVehicleBatch(placements, origin = [0, 0]) {
|
|
142
147
|
const group = new THREE.Group();
|
|
143
148
|
group.name = "surface:parked-cars";
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
if (placements.length === 0) return group;
|
|
150
|
+
const templates = placements.map((placement) => parkedTemplate(placement.spec, placement.color));
|
|
151
|
+
const vertices = templates.reduce((sum, template) => sum + template.getAttribute("position").count, 0);
|
|
152
|
+
const positions = new Float32Array(vertices * 3);
|
|
153
|
+
const normals = new Float32Array(vertices * 3);
|
|
154
|
+
const colors = new Float32Array(vertices * 3);
|
|
155
|
+
const ranges = new Uint32Array(placements.length * 2);
|
|
151
156
|
const matrix = new THREE.Matrix4();
|
|
157
|
+
const normalMatrix = new THREE.Matrix3();
|
|
152
158
|
const rotation = new THREE.Quaternion();
|
|
153
159
|
const position = new THREE.Vector3();
|
|
154
160
|
const scale = new THREE.Vector3(1, 1, 1);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
const vertex = new THREE.Vector3();
|
|
162
|
+
let offset = 0;
|
|
163
|
+
placements.forEach((placement, index) => {
|
|
164
|
+
const template = templates[index];
|
|
165
|
+
position.set(placement.position[0] - origin[0], placement.position[1], placement.position[2] - origin[1]);
|
|
166
|
+
rotation.setFromEuler(new THREE.Euler(placement.pitch ?? 0, placement.yaw, placement.roll ?? 0, "YXZ"));
|
|
167
|
+
matrix.compose(position, rotation, scale);
|
|
168
|
+
normalMatrix.getNormalMatrix(matrix);
|
|
169
|
+
const source = template.getAttribute("position");
|
|
170
|
+
const sourceNormals = template.getAttribute("normal");
|
|
171
|
+
const sourceColors = template.getAttribute("color");
|
|
172
|
+
for (let i = 0; i < source.count; i++) {
|
|
173
|
+
vertex.fromBufferAttribute(source, i).applyMatrix4(matrix).toArray(positions, (offset + i) * 3);
|
|
174
|
+
vertex.fromBufferAttribute(sourceNormals, i).applyMatrix3(normalMatrix).normalize().toArray(normals, (offset + i) * 3);
|
|
175
|
+
vertex.fromBufferAttribute(sourceColors, i).toArray(colors, (offset + i) * 3);
|
|
176
|
+
}
|
|
177
|
+
ranges[index * 2] = offset;
|
|
178
|
+
ranges[index * 2 + 1] = source.count;
|
|
179
|
+
offset += source.count;
|
|
180
|
+
});
|
|
181
|
+
const geometry = new THREE.BufferGeometry();
|
|
182
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
|
183
|
+
geometry.setAttribute("normal", new THREE.BufferAttribute(normals, 3));
|
|
184
|
+
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
|
185
|
+
geometry.computeBoundingBox();
|
|
186
|
+
geometry.computeBoundingSphere();
|
|
187
|
+
const mesh = new THREE.Mesh(geometry, parkedMaterial);
|
|
188
|
+
mesh.name = "vehicle:parked";
|
|
189
|
+
mesh.userData.vehicleIds = placements.map((placement) => placement.id);
|
|
190
|
+
mesh.userData.vehicleRanges = ranges;
|
|
191
|
+
mesh.userData.terrainOwnedGeometry = true;
|
|
192
|
+
mesh.castShadow = true;
|
|
193
|
+
mesh.receiveShadow = true;
|
|
194
|
+
group.add(mesh);
|
|
171
195
|
return group;
|
|
172
196
|
}
|
|
197
|
+
/** Whether `setParkedVehicleHidden` currently hides car `index` of a parked batch. */
|
|
198
|
+
function isParkedVehicleHidden(batch, index) {
|
|
199
|
+
return batch.userData.vehicleHidden?.has(index) ?? false;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Hide (collapse to a point) or restore one car of a parked batch, e.g. while its detailed
|
|
203
|
+
* model or a driven entity stands in for it. Returns whether the geometry changed.
|
|
204
|
+
*/
|
|
205
|
+
function setParkedVehicleHidden(batch, index, hidden) {
|
|
206
|
+
const ranges = batch.userData.vehicleRanges;
|
|
207
|
+
const start = ranges?.[index * 2];
|
|
208
|
+
const count = ranges?.[index * 2 + 1];
|
|
209
|
+
if (start === void 0 || count === void 0) return false;
|
|
210
|
+
let saved = batch.userData.vehicleHidden;
|
|
211
|
+
if (saved === void 0) {
|
|
212
|
+
saved = /* @__PURE__ */ new Map();
|
|
213
|
+
batch.userData.vehicleHidden = saved;
|
|
214
|
+
}
|
|
215
|
+
if (saved.has(index) === hidden) return false;
|
|
216
|
+
const attribute = batch.geometry.getAttribute("position");
|
|
217
|
+
const array = attribute.array;
|
|
218
|
+
const from = start * 3, to = (start + count) * 3;
|
|
219
|
+
if (hidden) {
|
|
220
|
+
saved.set(index, array.slice(from, to));
|
|
221
|
+
array.fill(0, from, to);
|
|
222
|
+
} else {
|
|
223
|
+
array.set(saved.get(index), from);
|
|
224
|
+
saved.delete(index);
|
|
225
|
+
}
|
|
226
|
+
attribute.addUpdateRange(from, to - from);
|
|
227
|
+
attribute.needsUpdate = true;
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
173
230
|
//#endregion
|
|
174
|
-
export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, vehicleCameraPose };
|
|
231
|
+
export { createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, isParkedVehicleHidden, setParkedVehicleHidden, vehicleCameraPose };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { n as installWebGpuTimestampGuard } from "./webgpu-frame-timer-Xnuq1Hld.mjs";
|
|
2
|
+
import { CanvasTarget, WebGPUBackend, WebGPURenderer } from "three/webgpu";
|
|
3
|
+
//#region src/three/webgpu-depth-bias.ts
|
|
4
|
+
const guardedBackends = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
/**
|
|
6
|
+
* Three r184 reverses WebGPU depth comparisons but copies polygon offsets unchanged into the
|
|
7
|
+
* pipeline descriptor. Negative offsets then push water/decals behind the surface they cover.
|
|
8
|
+
* The descriptor is built synchronously, even for compileAsync; restore the authored material
|
|
9
|
+
* immediately so cache keys, shared materials and later draws retain their original values.
|
|
10
|
+
*/
|
|
11
|
+
function installWebGpuDepthBiasGuard(renderer) {
|
|
12
|
+
if (!renderer.reversedDepthBuffer) return;
|
|
13
|
+
const backend = renderer.backend;
|
|
14
|
+
if (guardedBackends.has(backend)) return;
|
|
15
|
+
guardedBackends.add(backend);
|
|
16
|
+
const createPipeline = backend.createRenderPipeline;
|
|
17
|
+
backend.createRenderPipeline = (object, promises) => {
|
|
18
|
+
const material = object.material;
|
|
19
|
+
if (!material.polygonOffset) {
|
|
20
|
+
createPipeline.call(backend, object, promises);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const factor = material.polygonOffsetFactor;
|
|
24
|
+
const units = material.polygonOffsetUnits;
|
|
25
|
+
material.polygonOffsetFactor = -factor;
|
|
26
|
+
material.polygonOffsetUnits = -units;
|
|
27
|
+
try {
|
|
28
|
+
createPipeline.call(backend, object, promises);
|
|
29
|
+
} finally {
|
|
30
|
+
material.polygonOffsetFactor = factor;
|
|
31
|
+
material.polygonOffsetUnits = units;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/three/webgpu-render-object-release.ts
|
|
37
|
+
const guarded = /* @__PURE__ */ new WeakSet();
|
|
38
|
+
/**
|
|
39
|
+
* Release WebGPU render state together with the objects it draws. Three r184 has gaps that keep
|
|
40
|
+
* meshes it has drawn reachable, and through `parent` their whole streamed tiles:
|
|
41
|
+
*
|
|
42
|
+
* - Each render object subscribes to its material's and geometry's `dispose` events with a
|
|
43
|
+
* closure that references it. Shared materials never fire, so their listener lists retain a
|
|
44
|
+
* render object (and its mesh) per mesh drawn. Those listeners are replaced here with ones that
|
|
45
|
+
* hold the render object weakly; three still owns it for as long as the mesh is alive.
|
|
46
|
+
* - Instanced and batched meshes build node state of their own (keyed by uuid), and the node
|
|
47
|
+
* cache references the mesh until the render object is disposed. WebGLRenderer honours the
|
|
48
|
+
* mesh's `dispose()` event; release its WebGPU render objects on the same event.
|
|
49
|
+
* - The geometry cache keeps, until the geometry is disposed, a closure over the first render
|
|
50
|
+
* object that drew it. For shared model geometry that pins one early tile per model forever;
|
|
51
|
+
* the closure only needs the attribute list, so it is handed that instead.
|
|
52
|
+
*/
|
|
53
|
+
function installWebGpuRenderObjectRelease(renderer) {
|
|
54
|
+
const objects = renderer._objects;
|
|
55
|
+
if (objects == null || guarded.has(objects)) return;
|
|
56
|
+
guarded.add(objects);
|
|
57
|
+
const owned = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
const unsubscribe = new FinalizationRegistry((detach) => detach());
|
|
59
|
+
const release = (event) => {
|
|
60
|
+
event.target.removeEventListener("dispose", release);
|
|
61
|
+
const mesh = event.target;
|
|
62
|
+
const renderObjects = owned.get(mesh);
|
|
63
|
+
owned.delete(mesh);
|
|
64
|
+
for (const renderObject of [...renderObjects ?? []]) renderObject.dispose();
|
|
65
|
+
};
|
|
66
|
+
const geometries = renderer._geometries;
|
|
67
|
+
if (geometries != null) {
|
|
68
|
+
const initGeometry = geometries.initGeometry;
|
|
69
|
+
geometries.initGeometry = (renderObject) => initGeometry.call(geometries, geometryOwner(renderObject));
|
|
70
|
+
}
|
|
71
|
+
const create = objects.createRenderObject;
|
|
72
|
+
objects.createRenderObject = (...args) => {
|
|
73
|
+
const renderObject = create.apply(objects, args);
|
|
74
|
+
const { material, geometry } = renderObject;
|
|
75
|
+
material.removeEventListener("dispose", renderObject.onMaterialDispose);
|
|
76
|
+
geometry.removeEventListener("dispose", renderObject.onGeometryDispose);
|
|
77
|
+
const detach = listenWeakly(new WeakRef(renderObject), material, geometry);
|
|
78
|
+
unsubscribe.register(renderObject, detach, renderObject);
|
|
79
|
+
let tracked;
|
|
80
|
+
const mesh = renderObject.object;
|
|
81
|
+
if (mesh.isInstancedMesh === true || mesh.isBatchedMesh === true) {
|
|
82
|
+
tracked = owned.get(mesh);
|
|
83
|
+
if (tracked === void 0) {
|
|
84
|
+
tracked = /* @__PURE__ */ new Set();
|
|
85
|
+
owned.set(mesh, tracked);
|
|
86
|
+
mesh.addEventListener("dispose", release);
|
|
87
|
+
}
|
|
88
|
+
tracked.add(renderObject);
|
|
89
|
+
}
|
|
90
|
+
const onDispose = renderObject.onDispose;
|
|
91
|
+
renderObject.onDispose = () => {
|
|
92
|
+
unsubscribe.unregister(renderObject);
|
|
93
|
+
detach();
|
|
94
|
+
tracked?.delete(renderObject);
|
|
95
|
+
onDispose?.();
|
|
96
|
+
};
|
|
97
|
+
return renderObject;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** A stand-in that reads the live render object while it exists and its last attributes after. */
|
|
101
|
+
function geometryOwner(renderObject) {
|
|
102
|
+
const ref = new WeakRef(renderObject);
|
|
103
|
+
const attributes = renderObject.getAttributes();
|
|
104
|
+
return {
|
|
105
|
+
geometry: renderObject.geometry,
|
|
106
|
+
getAttributes: () => ref.deref()?.getAttributes() ?? attributes
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Subscribe on the render object's behalf and return the unsubscribe function. A separate scope
|
|
111
|
+
* on purpose: closures share their creating scope's context, and a listener created beside
|
|
112
|
+
* anything that captures the render object would retain it through that context.
|
|
113
|
+
*/
|
|
114
|
+
function listenWeakly(ref, material, geometry) {
|
|
115
|
+
const onMaterial = () => ref.deref()?.dispose();
|
|
116
|
+
const onGeometry = () => ref.deref()?.onGeometryDispose();
|
|
117
|
+
material.addEventListener("dispose", onMaterial);
|
|
118
|
+
geometry.addEventListener("dispose", onGeometry);
|
|
119
|
+
return () => {
|
|
120
|
+
material.removeEventListener("dispose", onMaterial);
|
|
121
|
+
geometry.removeEventListener("dispose", onGeometry);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/three/webgpu-driver.ts
|
|
126
|
+
/** Loaded only by the asynchronous backend factory, never by a legacy WebGL-only viewer. */
|
|
127
|
+
async function createWebGpuDriver(options) {
|
|
128
|
+
const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
129
|
+
canvas.width = 1;
|
|
130
|
+
canvas.height = 1;
|
|
131
|
+
const renderer = new WebGPURenderer({
|
|
132
|
+
canvas,
|
|
133
|
+
alpha: false,
|
|
134
|
+
antialias: options.antialias ?? false,
|
|
135
|
+
reversedDepthBuffer: options.reverseDepthBuffer ?? false,
|
|
136
|
+
logarithmicDepthBuffer: options.logarithmicDepthBuffer ?? false,
|
|
137
|
+
trackTimestamp: false,
|
|
138
|
+
...options.powerPreference === "high-performance" || options.powerPreference === "low-power" ? { powerPreference: options.powerPreference } : {}
|
|
139
|
+
});
|
|
140
|
+
const initialBackend = renderer.backend;
|
|
141
|
+
try {
|
|
142
|
+
await renderer.init();
|
|
143
|
+
if (!(renderer.backend instanceof WebGPUBackend)) throw new Error("Three.js could not initialize a WebGPU adapter/device");
|
|
144
|
+
installWebGpuTimestampGuard(renderer);
|
|
145
|
+
installWebGpuDepthBiasGuard(renderer);
|
|
146
|
+
installWebGpuRenderObjectRelease(renderer);
|
|
147
|
+
renderer.getContext();
|
|
148
|
+
if (options.canvas !== void 0) {
|
|
149
|
+
const previousTarget = renderer.getCanvasTarget();
|
|
150
|
+
renderer.setCanvasTarget(new CanvasTarget(options.canvas));
|
|
151
|
+
previousTarget.dispose();
|
|
152
|
+
renderer.getContext();
|
|
153
|
+
}
|
|
154
|
+
renderer.info.autoReset = false;
|
|
155
|
+
return renderer;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
const initialized = renderer.hasInitialized();
|
|
158
|
+
if (initialized) renderer.dispose();
|
|
159
|
+
if (!initialized || renderer.backend !== initialBackend) initialBackend.dispose();
|
|
160
|
+
renderer.getCanvasTarget().dispose();
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { createWebGpuDriver };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PMREMGenerator } from "three/webgpu";
|
|
2
|
+
//#region src/three/webgpu-sky-reflections.ts
|
|
3
|
+
/** Kept behind the WebGPU driver import boundary; WebGL never loads the node runtime. */
|
|
4
|
+
function createWebGpuSkyReflectionFilter(renderer) {
|
|
5
|
+
let generator;
|
|
6
|
+
let target;
|
|
7
|
+
return {
|
|
8
|
+
update(texture) {
|
|
9
|
+
generator ??= new PMREMGenerator(renderer);
|
|
10
|
+
target = generator.fromEquirectangular(texture, target);
|
|
11
|
+
return target.texture;
|
|
12
|
+
},
|
|
13
|
+
dispose() {
|
|
14
|
+
target?.dispose();
|
|
15
|
+
generator?.dispose();
|
|
16
|
+
target = void 0;
|
|
17
|
+
generator = void 0;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { createWebGpuSkyReflectionFilter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/molen-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"3d",
|
|
26
26
|
"threejs",
|
|
27
27
|
"webgpu",
|
|
28
|
-
"rendering"
|
|
28
|
+
"rendering",
|
|
29
|
+
"audio"
|
|
29
30
|
],
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
@@ -47,6 +48,18 @@
|
|
|
47
48
|
"./aircraft": {
|
|
48
49
|
"types": "./dist/aircraft.d.mts",
|
|
49
50
|
"default": "./dist/aircraft.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./navigation": {
|
|
53
|
+
"types": "./dist/navigation.d.mts",
|
|
54
|
+
"default": "./dist/navigation.mjs"
|
|
55
|
+
},
|
|
56
|
+
"./markers": {
|
|
57
|
+
"types": "./dist/markers.d.mts",
|
|
58
|
+
"default": "./dist/markers.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./audio": {
|
|
61
|
+
"types": "./dist/audio.d.mts",
|
|
62
|
+
"default": "./dist/audio.mjs"
|
|
50
63
|
}
|
|
51
64
|
},
|
|
52
65
|
"files": [
|
|
@@ -55,8 +68,8 @@
|
|
|
55
68
|
],
|
|
56
69
|
"dependencies": {
|
|
57
70
|
"zod": "^4.6.5",
|
|
58
|
-
"@bendyline/molen-materials": "0.0.
|
|
59
|
-
"@bendyline/molen-schema": "0.0.
|
|
71
|
+
"@bendyline/molen-materials": "0.0.3",
|
|
72
|
+
"@bendyline/molen-schema": "0.0.3"
|
|
60
73
|
},
|
|
61
74
|
"peerDependencies": {
|
|
62
75
|
"@types/three": ">=0.184.0 <0.187.0",
|