@bendyline/molen-client 0.0.1
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/LICENSE +21 -0
- package/NOTICE.md +11 -0
- package/README.md +95 -0
- package/dist/aircraft.d.mts +23 -0
- package/dist/aircraft.mjs +99 -0
- package/dist/camera-track.d.mts +20 -0
- package/dist/camera-track.mjs +102 -0
- package/dist/index.d.mts +1000 -0
- package/dist/index.mjs +4579 -0
- package/dist/math-ev_jEkRe.mjs +42 -0
- package/dist/model-signals-DVlLyP-w.d.mts +17 -0
- package/dist/model-signals-Gw1COJfo.mjs +53 -0
- package/dist/renderer-B3pd4N-J.d.mts +446 -0
- package/dist/vehicle-interior-0o-8QV_-.d.mts +31 -0
- package/dist/vehicle-interior-DZT0HmWC.mjs +12 -0
- package/dist/vehicles.d.mts +17 -0
- package/dist/vehicles.mjs +174 -0
- package/dist/vite.d.mts +24 -0
- package/dist/vite.mjs +57 -0
- package/dist/webgpu-driver-DXsRuz8j.mjs +75 -0
- package/dist/webgpu-frame-timer-Xnuq1Hld.mjs +97 -0
- package/dist/webgpu-scene-optimizer-D6e9ZJQM.mjs +319 -0
- package/package.json +85 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/math.ts
|
|
2
|
+
function lerp3(a, b, t) {
|
|
3
|
+
return [
|
|
4
|
+
a[0] + (b[0] - a[0]) * t,
|
|
5
|
+
a[1] + (b[1] - a[1]) * t,
|
|
6
|
+
a[2] + (b[2] - a[2]) * t
|
|
7
|
+
];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Normalized linear quaternion interpolation along the shorter arc. Not a slerp: the angular
|
|
11
|
+
* rate is not constant across `t`, which is the right trade for interpolating between two
|
|
12
|
+
* consecutive simulation ticks (cheap, always returns a unit quaternion, no trig). A rotation
|
|
13
|
+
* large enough for the difference to read would have to turn most of the way around inside one
|
|
14
|
+
* tick.
|
|
15
|
+
*/
|
|
16
|
+
function nlerp4(a, b, t) {
|
|
17
|
+
let dot = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
18
|
+
let bx = b[0];
|
|
19
|
+
let by = b[1];
|
|
20
|
+
let bz = b[2];
|
|
21
|
+
let bw = b[3];
|
|
22
|
+
if (dot < 0) {
|
|
23
|
+
bx = -bx;
|
|
24
|
+
by = -by;
|
|
25
|
+
bz = -bz;
|
|
26
|
+
bw = -bw;
|
|
27
|
+
dot = -dot;
|
|
28
|
+
}
|
|
29
|
+
const x = a[0] + (bx - a[0]) * t;
|
|
30
|
+
const y = a[1] + (by - a[1]) * t;
|
|
31
|
+
const z = a[2] + (bz - a[2]) * t;
|
|
32
|
+
const w = a[3] + (bw - a[3]) * t;
|
|
33
|
+
const len = Math.sqrt(x * x + y * y + z * z + w * w) || 1;
|
|
34
|
+
return [
|
|
35
|
+
x / len,
|
|
36
|
+
y / len,
|
|
37
|
+
z / len,
|
|
38
|
+
w / len
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { nlerp4 as n, lerp3 as t };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { 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
|
+
update(signals: ModelSignals): void;
|
|
9
|
+
/** Restore authored transforms before removing or replacing bindings. */
|
|
10
|
+
reset(): void;
|
|
11
|
+
}
|
|
12
|
+
/** Read data only: no expressions, evaluation, prototype traversal, or simulation writes. */
|
|
13
|
+
declare function readModelSignals(sources: Readonly<Record<string, ModelSignalSource>> | undefined, readComponent: (name: string) => unknown): ModelSignals;
|
|
14
|
+
/** Model-agnostic; moves existing geometry without creating a cockpit or changing physics. */
|
|
15
|
+
declare function createModelSignalVisual(model: Object3D, spec: ModelSignalSpec): ModelSignalVisual;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { readModelSignals as i, ModelSignals as n, createModelSignalVisual as r, ModelSignalVisual as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/model-signals.ts
|
|
2
|
+
/** Read data only: no expressions, evaluation, prototype traversal, or simulation writes. */
|
|
3
|
+
function readModelSignals(sources, readComponent) {
|
|
4
|
+
const signals = Object.create(null);
|
|
5
|
+
for (const [name, source] of Object.entries(sources ?? {})) {
|
|
6
|
+
let value = readComponent(source.component);
|
|
7
|
+
for (const part of source.path) {
|
|
8
|
+
if (value === null || typeof value !== "object" || !Object.hasOwn(value, part)) {
|
|
9
|
+
value = void 0;
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
value = value[part];
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === "boolean") signals[name] = Number(value);
|
|
15
|
+
else if (typeof value === "number" && Number.isFinite(value)) signals[name] = value;
|
|
16
|
+
}
|
|
17
|
+
return signals;
|
|
18
|
+
}
|
|
19
|
+
/** Model-agnostic; moves existing geometry without creating a cockpit or changing physics. */
|
|
20
|
+
function createModelSignalVisual(model, spec) {
|
|
21
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
22
|
+
model.traverse((node) => {
|
|
23
|
+
const matches = nodes.get(node.name) ?? [];
|
|
24
|
+
matches.push(node);
|
|
25
|
+
nodes.set(node.name, matches);
|
|
26
|
+
});
|
|
27
|
+
const missingNodes = [...new Set(spec.bindings.map((b) => b.node))].filter((name) => !nodes.has(name));
|
|
28
|
+
const bindings = spec.bindings.flatMap((binding) => (nodes.get(binding.node) ?? []).map((node) => {
|
|
29
|
+
node.matrixAutoUpdate = true;
|
|
30
|
+
return {
|
|
31
|
+
binding,
|
|
32
|
+
node,
|
|
33
|
+
rest: node[binding.property][binding.axis]
|
|
34
|
+
};
|
|
35
|
+
}));
|
|
36
|
+
return {
|
|
37
|
+
missingNodes,
|
|
38
|
+
update(signals) {
|
|
39
|
+
for (const { binding, node, rest } of bindings) {
|
|
40
|
+
const signal = signals[binding.source];
|
|
41
|
+
if (signal === void 0 || !Number.isFinite(signal)) continue;
|
|
42
|
+
const value = signal * binding.scale + (binding.offset ?? 0);
|
|
43
|
+
if (!Number.isFinite(value)) continue;
|
|
44
|
+
node[binding.property][binding.axis] = rest + Math.max(binding.min ?? -Infinity, Math.min(binding.max ?? Infinity, value));
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
reset() {
|
|
48
|
+
for (const { binding, node, rest } of bindings) node[binding.property][binding.axis] = rest;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { readModelSignals as n, createModelSignalVisual as t };
|
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { EarthObserver, Quat, ResolvedWeather, SkyData, SkyPalette, SkyTime, Vec3, WeatherData } from "@bendyline/molen-schema";
|
|
2
|
+
import * as THREE from "three";
|
|
3
|
+
import { WebGPURenderer } from "three/webgpu";
|
|
4
|
+
|
|
5
|
+
//#region src/frame-admission.d.ts
|
|
6
|
+
/** Shared main-thread work queue. A job is indivisible; oversize jobs run alone and are reported. */
|
|
7
|
+
interface AdmissionOptions {
|
|
8
|
+
bytes?: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
label?: string;
|
|
11
|
+
}
|
|
12
|
+
interface AdmissionSample {
|
|
13
|
+
label: string;
|
|
14
|
+
queueMs: number;
|
|
15
|
+
workMs: number;
|
|
16
|
+
bytes: number;
|
|
17
|
+
overBudget: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface SceneAdmission {
|
|
20
|
+
run<T>(task: () => T, options?: AdmissionOptions): Promise<T>;
|
|
21
|
+
}
|
|
22
|
+
interface FrameAdmissionOptions {
|
|
23
|
+
maxMilliseconds?: number;
|
|
24
|
+
maxBytes?: number;
|
|
25
|
+
maxJobs?: number;
|
|
26
|
+
now?: () => number;
|
|
27
|
+
schedule?: (callback: () => void) => void;
|
|
28
|
+
onSample?: (sample: AdmissionSample) => void;
|
|
29
|
+
}
|
|
30
|
+
declare class FrameAdmissionQueue implements SceneAdmission {
|
|
31
|
+
private readonly options;
|
|
32
|
+
private jobs;
|
|
33
|
+
private scheduled;
|
|
34
|
+
private disposed;
|
|
35
|
+
private readonly clock;
|
|
36
|
+
private readonly schedule;
|
|
37
|
+
private readonly maxMs;
|
|
38
|
+
private readonly maxBytes;
|
|
39
|
+
private readonly maxJobs;
|
|
40
|
+
constructor(options?: FrameAdmissionOptions);
|
|
41
|
+
run<T>(task: () => T, options?: AdmissionOptions): Promise<T>;
|
|
42
|
+
get pending(): number;
|
|
43
|
+
private request;
|
|
44
|
+
/** One frame's budget. Exposed for hosts with a manual frame loop and deterministic tests. */
|
|
45
|
+
flush(): void;
|
|
46
|
+
dispose(): void;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/sky/astronomy.d.ts
|
|
50
|
+
interface CelestialPosition {
|
|
51
|
+
/** Unit vector toward the body; Y-up, default +X east / -Z north. */
|
|
52
|
+
direction: Vec3;
|
|
53
|
+
/** Geometric topocentric altitude; no atmospheric refraction. */
|
|
54
|
+
altitudeDeg: number;
|
|
55
|
+
/** Clockwise from geographic north, before northOffsetDeg. */
|
|
56
|
+
azimuthDeg: number;
|
|
57
|
+
distanceKm: number;
|
|
58
|
+
angularDiameterDeg: number;
|
|
59
|
+
}
|
|
60
|
+
interface EarthSkyState {
|
|
61
|
+
utcMs: number;
|
|
62
|
+
julianDate: number;
|
|
63
|
+
sun: CelestialPosition;
|
|
64
|
+
moon: CelestialPosition & {
|
|
65
|
+
illuminatedFraction: number; /** Synodic cycle: 0 new, 0.25 first quarter, 0.5 full, 0.75 last quarter. */
|
|
66
|
+
phase: number;
|
|
67
|
+
};
|
|
68
|
+
/** Columns transforming J2000 equatorial Cartesian coordinates into the local world. */
|
|
69
|
+
starBasis: [Vec3, Vec3, Vec3];
|
|
70
|
+
}
|
|
71
|
+
/** Explicit, seekable simulation clock; no implicit Date.now or browser timezone. */
|
|
72
|
+
declare function skyTimeMs(time: SkyTime, simulationSeconds?: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* Compact Earth ephemeris: Keplerian Sun + Moon with the major lunar perturbations,
|
|
75
|
+
* ellipsoidal observer parallax, sidereal rotation and stellar precession.
|
|
76
|
+
* Formula reference: https://www.stjarnhimlen.se/comp/ppcomp.html (Paul Schlyter).
|
|
77
|
+
* Intended for visual skies, not navigation: no refraction, nutation, eclipses, or light time.
|
|
78
|
+
*/
|
|
79
|
+
declare function evaluateEarthSky(utcMs: number, observer: EarthObserver): EarthSkyState;
|
|
80
|
+
/** Map a catalog J2000 position (degrees) through a sampled Earth's star basis. */
|
|
81
|
+
declare function starDirection(rightAscensionDeg: number, declinationDeg: number, state: EarthSkyState): Vec3;
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/sky/visual.d.ts
|
|
84
|
+
declare const defaultSkyPalette: Required<SkyPalette>;
|
|
85
|
+
interface SkyFrame {
|
|
86
|
+
sunDirection: Vec3;
|
|
87
|
+
moonDirection?: Vec3;
|
|
88
|
+
sunDiameterDeg: number;
|
|
89
|
+
moonDiameterDeg: number;
|
|
90
|
+
moonIllumination: number;
|
|
91
|
+
daylight: number;
|
|
92
|
+
starVisibility: number;
|
|
93
|
+
earth?: EarthSkyState;
|
|
94
|
+
}
|
|
95
|
+
interface SkyStar {
|
|
96
|
+
/** Unit direction in the unrotated star sphere. Earth skies use J2000 equatorial XYZ. */
|
|
97
|
+
direction: Vec3;
|
|
98
|
+
magnitude: number;
|
|
99
|
+
color?: string;
|
|
100
|
+
}
|
|
101
|
+
interface SkyVisualOptions {
|
|
102
|
+
/**
|
|
103
|
+
* The star catalog: `decodeStarCatalog` of the `molen.sky` pack for Earth, or an authored
|
|
104
|
+
* world's own. Without one the sky has no stars.
|
|
105
|
+
*/
|
|
106
|
+
stars?: readonly SkyStar[];
|
|
107
|
+
shadows?: "off" | "low" | "medium" | "high";
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generic clear-sky dome, celestial spheres, batched stars and lighting, using standard
|
|
111
|
+
* materials on WebGL and WebGPU. A separate background scene avoids far-plane, reverse-depth,
|
|
112
|
+
* logarithmic-depth and floating-origin coupling. No textures, shaders or network requests.
|
|
113
|
+
*/
|
|
114
|
+
declare class SkyVisual {
|
|
115
|
+
readonly scene: THREE.Scene;
|
|
116
|
+
readonly camera: THREE.PerspectiveCamera;
|
|
117
|
+
readonly lights: THREE.Group;
|
|
118
|
+
readonly sunLight: THREE.DirectionalLight;
|
|
119
|
+
readonly moonLight: THREE.DirectionalLight;
|
|
120
|
+
readonly ambientLight: THREE.HemisphereLight;
|
|
121
|
+
readonly data: SkyData;
|
|
122
|
+
private readonly dome;
|
|
123
|
+
private readonly sun;
|
|
124
|
+
private readonly moon;
|
|
125
|
+
private readonly stars;
|
|
126
|
+
private catalog;
|
|
127
|
+
private readonly palette;
|
|
128
|
+
private lastTime;
|
|
129
|
+
private cloudAttenuation;
|
|
130
|
+
private currentFrame;
|
|
131
|
+
private disposed;
|
|
132
|
+
constructor(data: SkyData, options?: SkyVisualOptions);
|
|
133
|
+
get frame(): SkyFrame;
|
|
134
|
+
/** Diffuse cloud lighting; actual celestial occlusion comes from the cloud layer geometry. */
|
|
135
|
+
setCloudAttenuation(value: number): void;
|
|
136
|
+
/** Move an Earth observer without rebuilding the dome, bodies or star catalog. */
|
|
137
|
+
setObserver(observer: EarthObserver): void;
|
|
138
|
+
/** Seek in simulation seconds. Earth render samples use a stable one-second UTC grid. */
|
|
139
|
+
update(simulationSeconds: number): SkyFrame;
|
|
140
|
+
/** Copy view orientation/projection only; celestial bodies never translate with the camera. */
|
|
141
|
+
prepareCamera(camera: THREE.Camera): void;
|
|
142
|
+
private updateDome;
|
|
143
|
+
private updateBody;
|
|
144
|
+
/**
|
|
145
|
+
* Replace the star catalog, e.g. once a catalog loaded from a content pack arrives. `undefined`
|
|
146
|
+
* removes the stars. Takes effect on the next update.
|
|
147
|
+
*/
|
|
148
|
+
setStars(stars: readonly SkyStar[] | undefined): void;
|
|
149
|
+
private catalogFrom;
|
|
150
|
+
private updateStars;
|
|
151
|
+
dispose(): void;
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/weather/visual.d.ts
|
|
155
|
+
/**
|
|
156
|
+
* Lightweight layered clouds and local precipitation with standard materials on both graphics
|
|
157
|
+
* backends. Patterns are seeded and sampled at absolute simulation time, not integrated frames.
|
|
158
|
+
* Cloud layers use absolute world altitudes; particles are visual and do not accumulate or collide.
|
|
159
|
+
*/
|
|
160
|
+
declare class WeatherVisual {
|
|
161
|
+
readonly object: THREE.Group;
|
|
162
|
+
readonly fog: THREE.Fog;
|
|
163
|
+
private state;
|
|
164
|
+
private cloudNoise;
|
|
165
|
+
private cloudTexture;
|
|
166
|
+
private readonly cloudLayers;
|
|
167
|
+
private cloudKey;
|
|
168
|
+
private noiseSeed;
|
|
169
|
+
private particles;
|
|
170
|
+
private particleTexture;
|
|
171
|
+
private readonly cameraPosition;
|
|
172
|
+
private readonly right;
|
|
173
|
+
private readonly up;
|
|
174
|
+
private readonly color;
|
|
175
|
+
private disposed;
|
|
176
|
+
constructor(data: WeatherData);
|
|
177
|
+
/** Resolved copy; editing it does not change the visual. */
|
|
178
|
+
get data(): ResolvedWeather;
|
|
179
|
+
/** Replace weather while retaining geometry, particles and cached noise. */
|
|
180
|
+
setData(data: WeatherData): void;
|
|
181
|
+
get cloudAttenuation(): number;
|
|
182
|
+
get stats(): {
|
|
183
|
+
cloudLayers: number;
|
|
184
|
+
particles: number;
|
|
185
|
+
};
|
|
186
|
+
/** Update camera-relative geometry using the renderer's absolute floating origin. */
|
|
187
|
+
update(seconds: number, camera: THREE.Camera, origin: Vec3, sky?: SkyFrame): void;
|
|
188
|
+
/** Combine weather visibility with an authored/streaming fog limit without mutating it. */
|
|
189
|
+
fogFor(base: THREE.Fog | THREE.FogExp2 | null, sky?: SkyFrame): THREE.Fog | THREE.FogExp2;
|
|
190
|
+
private buildClouds;
|
|
191
|
+
private updateClouds;
|
|
192
|
+
private buildParticles;
|
|
193
|
+
private updateParticles;
|
|
194
|
+
dispose(): void;
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/three/gpu-frame-timer.d.ts
|
|
198
|
+
interface GpuFrameTimerOptions {
|
|
199
|
+
/** Maximum outstanding queries, including an active measurement. Default 4. */
|
|
200
|
+
maxPendingQueries?: number;
|
|
201
|
+
/** Sample one frame out of this many to limit instrumentation overhead. Default 4. */
|
|
202
|
+
sampleEveryFrames?: number;
|
|
203
|
+
}
|
|
204
|
+
interface GpuFrameTimer {
|
|
205
|
+
/** Returns false when unsupported, busy, suspended, or this frame is not sampled. */
|
|
206
|
+
begin(): boolean;
|
|
207
|
+
/** Finish the measurement started by begin(); safe when begin() returned false. */
|
|
208
|
+
end(): void;
|
|
209
|
+
/** Poll once per animation frame. Returns the latest completed valid duration in milliseconds. */
|
|
210
|
+
poll(): number | undefined;
|
|
211
|
+
dispose(): void;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Optional WebGL2 timing. Reads a result only after QUERY_RESULT_AVAILABLE; never waits,
|
|
215
|
+
* flushes, finishes, or schedules polling. Unavailable extensions return undefined.
|
|
216
|
+
* Context restoration reacquires the extension and starts with fresh query objects.
|
|
217
|
+
*/
|
|
218
|
+
declare function createGpuFrameTimer(context: WebGLRenderingContext | WebGL2RenderingContext, options?: GpuFrameTimerOptions): GpuFrameTimer | undefined;
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/three/webgpu-scene-optimizer.d.ts
|
|
221
|
+
/**
|
|
222
|
+
* Uses Three render bundles and a pinned, version-aware instance upload adapter.
|
|
223
|
+
* Bundles are restricted to opaque, unskinned content with ordinary object callbacks. Re-recording
|
|
224
|
+
* on camera changes deliberately keeps Three's frustum culling, sorting and LOD decisions intact.
|
|
225
|
+
*/
|
|
226
|
+
declare class WebGpuSceneOptimizer {
|
|
227
|
+
private readonly renderer;
|
|
228
|
+
private readonly instances;
|
|
229
|
+
private readonly renderHook;
|
|
230
|
+
private readonly groups;
|
|
231
|
+
private active;
|
|
232
|
+
private frame;
|
|
233
|
+
private stableCameraFrames;
|
|
234
|
+
private cameraState;
|
|
235
|
+
private readonly frameSize;
|
|
236
|
+
private readonly matrixSamples;
|
|
237
|
+
private readonly restoreRefresh;
|
|
238
|
+
private materialSamples;
|
|
239
|
+
private readonly videoMaterials;
|
|
240
|
+
private readonly materialStates;
|
|
241
|
+
constructor(renderer: WebGPURenderer);
|
|
242
|
+
createGroup(): THREE.Group;
|
|
243
|
+
/** Update matrices once; Renderer suppresses Three's duplicate scene traversal for this frame. */
|
|
244
|
+
prepare(scene: THREE.Scene, camera: THREE.Camera): void;
|
|
245
|
+
/** Three counts command recording, not cached execution; retain the actual recorded workload. */
|
|
246
|
+
finish(): void;
|
|
247
|
+
private sampleMatrix;
|
|
248
|
+
private setEnabled;
|
|
249
|
+
private disable;
|
|
250
|
+
private sampleMaterial;
|
|
251
|
+
private sampleValue;
|
|
252
|
+
dispose(): void;
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/three/renderer.d.ts
|
|
256
|
+
type RendererBackend = "webgl" | "webgpu";
|
|
257
|
+
type RendererBackendPreference = "auto" | RendererBackend;
|
|
258
|
+
type ThreeRenderer = THREE.WebGLRenderer | WebGPURenderer;
|
|
259
|
+
interface InitializedRenderer {
|
|
260
|
+
three: ThreeRenderer;
|
|
261
|
+
backend: RendererBackend;
|
|
262
|
+
optimizer?: WebGpuSceneOptimizer;
|
|
263
|
+
}
|
|
264
|
+
interface RendererOptions {
|
|
265
|
+
admission?: FrameAdmissionOptions;
|
|
266
|
+
/**
|
|
267
|
+
* Which graphics backend to use. Defaults to `'auto'`: probe WebGPU, fall back to WebGL.
|
|
268
|
+
* `'webgl'` skips the probe entirely — pin it when the pixels must be reproducible.
|
|
269
|
+
* `'webgpu'` is strict and never silently falls back.
|
|
270
|
+
*/
|
|
271
|
+
backend?: RendererBackendPreference;
|
|
272
|
+
/**
|
|
273
|
+
* How long the WebGPU probe may take before `'auto'` gives up and uses WebGL (default 5000ms;
|
|
274
|
+
* 0 or Infinity waits forever). A context can advertise `navigator.gpu` and then never settle
|
|
275
|
+
* its initialization — headless software rendering does exactly this — and without a bound the
|
|
276
|
+
* page hangs with no error rather than falling back. `'webgpu'` rejects on timeout instead.
|
|
277
|
+
*/
|
|
278
|
+
backendProbeTimeoutMs?: number;
|
|
279
|
+
/** Persistent instance buffers and managed tile command caches. Defaults to true on WebGPU. */
|
|
280
|
+
optimizeWebGpu?: boolean;
|
|
281
|
+
/** Device loss requires a new viewer/canvas. Auto fallback applies during initialization. */
|
|
282
|
+
onDeviceLost?: (reason: string) => void;
|
|
283
|
+
canvas?: HTMLCanvasElement | OffscreenCanvas;
|
|
284
|
+
width?: number;
|
|
285
|
+
height?: number;
|
|
286
|
+
pixelRatio?: number;
|
|
287
|
+
antialias?: boolean;
|
|
288
|
+
/** WebGL only. WebGPU presentation does not preserve the drawing buffer between frames. */
|
|
289
|
+
preserveDrawingBuffer?: boolean;
|
|
290
|
+
powerPreference?: "default" | "high-performance" | "low-power";
|
|
291
|
+
/** Better depth precision for large view ranges; WebGL requires EXT_clip_control. */
|
|
292
|
+
reverseDepthBuffer?: boolean;
|
|
293
|
+
/** Compatibility fallback for large view ranges; costs early-fragment performance. */
|
|
294
|
+
logarithmicDepthBuffer?: boolean;
|
|
295
|
+
cameraNear?: number;
|
|
296
|
+
cameraFar?: number;
|
|
297
|
+
/** Optional automatic large-world origin rebasing driven by camera movement. */
|
|
298
|
+
autoWorldOrigin?: AutoWorldOriginOptions;
|
|
299
|
+
/** Background clear color, default a mid grey. */
|
|
300
|
+
clearColor?: string;
|
|
301
|
+
/**
|
|
302
|
+
* Stars for every sky, e.g. `decodeStarCatalog` of the `molen.sky` content pack's `stars.bin`.
|
|
303
|
+
* Without a catalog, skies show no stars; `setStarCatalog` supplies one later.
|
|
304
|
+
*/
|
|
305
|
+
stars?: readonly SkyStar[];
|
|
306
|
+
}
|
|
307
|
+
interface AutoWorldOriginOptions {
|
|
308
|
+
/** Rebase after the camera moves farther than this world-space distance from the current origin. */
|
|
309
|
+
threshold: number;
|
|
310
|
+
/** Snap the new origin to this grid size; omitted means use the exact camera position. */
|
|
311
|
+
gridSize?: number;
|
|
312
|
+
/** Include vertical movement in the threshold and new origin. Defaults to horizontal XZ only. */
|
|
313
|
+
includeY?: boolean;
|
|
314
|
+
}
|
|
315
|
+
interface CameraPose {
|
|
316
|
+
position: Vec3;
|
|
317
|
+
/** Either a look-at target or an explicit rotation quaternion. */
|
|
318
|
+
lookAt?: Vec3;
|
|
319
|
+
rotation?: Quat;
|
|
320
|
+
}
|
|
321
|
+
/** The framing for the orthographic top-down camera: where it looks and how much it covers. */
|
|
322
|
+
interface TopDownOrtho {
|
|
323
|
+
/** World XZ the camera centers on. */
|
|
324
|
+
center: [number, number];
|
|
325
|
+
/** Vertical world extent the viewport covers. */
|
|
326
|
+
viewHeight: number;
|
|
327
|
+
/** Camera height above the ground (for depth ordering). */
|
|
328
|
+
cameraHeight?: number;
|
|
329
|
+
rotationDeg?: number;
|
|
330
|
+
}
|
|
331
|
+
/** Orthographic half-extents for a vertical view extent at an aspect ratio (pure; testable). */
|
|
332
|
+
declare function orthoFrustum(viewHeight: number, aspect: number): {
|
|
333
|
+
halfW: number;
|
|
334
|
+
halfH: number;
|
|
335
|
+
};
|
|
336
|
+
/** Pure automatic-origin policy, exported so hosts can predict and test rebases without WebGL. */
|
|
337
|
+
declare function nextWorldOrigin(current: Vec3, cameraPosition: Vec3, options: AutoWorldOriginOptions): Vec3 | undefined;
|
|
338
|
+
/**
|
|
339
|
+
* Thin wrapper over the three.js renderer + scene + camera. The engine owns the single
|
|
340
|
+
* construction path so capture settings (pixel ratio, AA, tone mapping) are deterministic.
|
|
341
|
+
* The `backend` option selects WebGPU or WebGL — see docs-src/guide/rendering-backends.md.
|
|
342
|
+
*/
|
|
343
|
+
declare class Renderer {
|
|
344
|
+
readonly admission: FrameAdmissionQueue;
|
|
345
|
+
private readonly preparedResources;
|
|
346
|
+
private warmupTarget;
|
|
347
|
+
private warmupMaterial;
|
|
348
|
+
private readonly warmedPrograms;
|
|
349
|
+
private readonly warmedMeshes;
|
|
350
|
+
readonly three: ThreeRenderer;
|
|
351
|
+
readonly backend: RendererBackend;
|
|
352
|
+
private fallback;
|
|
353
|
+
get fallbackReason(): string | undefined;
|
|
354
|
+
readonly scene: THREE.Scene;
|
|
355
|
+
/** World-space objects live here so the renderer can rebase them near the camera. */
|
|
356
|
+
readonly worldRoot: THREE.Group;
|
|
357
|
+
camera: THREE.PerspectiveCamera | THREE.OrthographicCamera;
|
|
358
|
+
readonly defaultClearColor: THREE.Color;
|
|
359
|
+
private aspect;
|
|
360
|
+
private viewportWidth;
|
|
361
|
+
private viewportHeight;
|
|
362
|
+
private pixelRatio;
|
|
363
|
+
private readonly uploadBatchBytes;
|
|
364
|
+
private worldOrigin;
|
|
365
|
+
private cameraPose;
|
|
366
|
+
/** The active top-down framing, so a resize can refit the orthographic bounds. */
|
|
367
|
+
private ortho;
|
|
368
|
+
private readonly cameraNear;
|
|
369
|
+
private readonly cameraFar;
|
|
370
|
+
private readonly autoWorldOrigin;
|
|
371
|
+
private readonly timers;
|
|
372
|
+
private disposed;
|
|
373
|
+
private deviceLossReason;
|
|
374
|
+
private readonly optimizer;
|
|
375
|
+
private activeSky;
|
|
376
|
+
private starCatalog;
|
|
377
|
+
private activeWeather;
|
|
378
|
+
private weatherTimeOverride;
|
|
379
|
+
private readonly weatherLightIntensities;
|
|
380
|
+
private environmentSeconds;
|
|
381
|
+
private environmentTimeOverride;
|
|
382
|
+
/** Active clear-sky visual and sampled ephemeris, when environment.sky is configured. */
|
|
383
|
+
get sky(): SkyVisual | undefined;
|
|
384
|
+
/** Active weather effects; physical weather data is also available in the simulation component. */
|
|
385
|
+
get weather(): WeatherVisual | undefined;
|
|
386
|
+
/** Apply the singleton weather component without rebuilding the sky or moving the camera. */
|
|
387
|
+
setWeather(data: WeatherData | undefined): void;
|
|
388
|
+
/** Standalone weather preview clock. Undefined follows simulation time, independently of sky seeks. */
|
|
389
|
+
setWeatherTimeOverride(seconds: number | undefined): void;
|
|
390
|
+
/**
|
|
391
|
+
* Stars for every sky this renderer shows, e.g. `decodeStarCatalog` of a content pack's
|
|
392
|
+
* molen/stars@1 file. Applies to the current sky at once and survives sky changes;
|
|
393
|
+
* `undefined` removes the stars.
|
|
394
|
+
*/
|
|
395
|
+
setStarCatalog(stars: readonly SkyStar[] | undefined): void;
|
|
396
|
+
/** Absolute simulation seconds, shared by live playback, paused snapshots and captures. */
|
|
397
|
+
setEnvironmentTime(seconds: number): void;
|
|
398
|
+
/** Preview a sky at absolute simulation seconds without seeking the world; undefined resumes its clock. */
|
|
399
|
+
setEnvironmentTimeOverride(seconds: number | undefined): void;
|
|
400
|
+
/** Prefer WebGPU when available; explicit webgpu is strict and never silently falls back. */
|
|
401
|
+
static create(opts?: RendererOptions): Promise<Renderer>;
|
|
402
|
+
constructor(opts?: RendererOptions, initialized?: InitializedRenderer);
|
|
403
|
+
/** Pose the perspective camera (leaving top-down ortho mode if it was active). */
|
|
404
|
+
setCamera(pose: CameraPose): void;
|
|
405
|
+
/** Vertical field of view in degrees (perspective camera only; a no-op for ortho). */
|
|
406
|
+
setFov(fovDeg: number): void;
|
|
407
|
+
/** Shift all engine-owned world objects near the local origin without changing world poses. */
|
|
408
|
+
setWorldOrigin(origin: Vec3): void;
|
|
409
|
+
getWorldOrigin(): Vec3;
|
|
410
|
+
setCameraClip(near: number, far: number): void;
|
|
411
|
+
private applyCameraPose;
|
|
412
|
+
private maybeRebase;
|
|
413
|
+
private applyWorldOrigin;
|
|
414
|
+
/** Switch to a top-down orthographic camera looking straight down at a world point. */
|
|
415
|
+
setTopDownOrtho(opts: TopDownOrtho): void;
|
|
416
|
+
/**
|
|
417
|
+
* The WebGPU device-loss reason once the device is gone (undefined while it is live). Every
|
|
418
|
+
* later `render()` throws, so a frame loop stops here instead of failing once per frame.
|
|
419
|
+
*/
|
|
420
|
+
get deviceLost(): string | undefined;
|
|
421
|
+
/**
|
|
422
|
+
* Update the device pixel ratio after a display change. Three applies the ratio on the next
|
|
423
|
+
* `setSize`, so callers pair the two (the mount's resize handler does).
|
|
424
|
+
*/
|
|
425
|
+
setPixelRatio(ratio: number): void;
|
|
426
|
+
setSize(width: number, height: number): void;
|
|
427
|
+
/** Prepare shared resources once; all dependants await the same admission jobs. */
|
|
428
|
+
prepareObject(root: THREE.Object3D, signal?: AbortSignal): Promise<void>;
|
|
429
|
+
private rememberPreparation;
|
|
430
|
+
private compileMesh;
|
|
431
|
+
private prepareWebGlGeometries;
|
|
432
|
+
render(): void;
|
|
433
|
+
private renderScene;
|
|
434
|
+
/** Use for independent terrain/content chunks. WebGPU caches eligible opaque draw commands. */
|
|
435
|
+
createRenderGroup(): THREE.Group;
|
|
436
|
+
/** Render stats for the screenshot stats block. */
|
|
437
|
+
stats(): {
|
|
438
|
+
drawCalls: number;
|
|
439
|
+
triangles: number;
|
|
440
|
+
};
|
|
441
|
+
/** Optional backend-specific GPU timing with the same nonblocking polling interface. */
|
|
442
|
+
createGpuTimer(options?: GpuFrameTimerOptions): GpuFrameTimer | undefined;
|
|
443
|
+
dispose(): void;
|
|
444
|
+
}
|
|
445
|
+
//#endregion
|
|
446
|
+
export { skyTimeMs as C, FrameAdmissionOptions as D, AdmissionSample as E, FrameAdmissionQueue as O, evaluateEarthSky as S, AdmissionOptions 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, SceneAdmission 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 };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-DVlLyP-w.mjs";
|
|
2
|
+
import { VehicleInteriorSpec, VehicleSpec } from "@bendyline/molen-schema";
|
|
3
|
+
import { Object3D } from "three";
|
|
4
|
+
|
|
5
|
+
//#region src/vehicle-camera.d.ts
|
|
6
|
+
interface VehicleCameraOptions {
|
|
7
|
+
view: "cockpit" | "chase";
|
|
8
|
+
lookYaw?: number;
|
|
9
|
+
lookPitch?: number;
|
|
10
|
+
/** Distance to the first static obstruction between two absolute world points. */
|
|
11
|
+
obstructionDistance?: (from: [number, number, number], to: [number, number, number]) => number | undefined;
|
|
12
|
+
}
|
|
13
|
+
interface VehicleCameraPose {
|
|
14
|
+
position: [number, number, number];
|
|
15
|
+
lookAt: [number, number, number];
|
|
16
|
+
yaw: number;
|
|
17
|
+
pitch: number;
|
|
18
|
+
}
|
|
19
|
+
/** Seat-space cockpit and collision-shortened chase views for any vehicle host. */
|
|
20
|
+
declare function vehicleCameraPose(transform: {
|
|
21
|
+
pos: [number, number, number];
|
|
22
|
+
rot: [number, number, number, number];
|
|
23
|
+
}, spec: VehicleSpec, options: VehicleCameraOptions): VehicleCameraPose;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/vehicle-interior.d.ts
|
|
26
|
+
type VehicleInteriorSignals = ModelSignals;
|
|
27
|
+
type VehicleInteriorVisual = ModelSignalVisual;
|
|
28
|
+
/** Vehicle convenience wrapper around the platform's model-signal binding system. */
|
|
29
|
+
declare function createVehicleInteriorVisual(model: Object3D, spec: VehicleInteriorSpec): VehicleInteriorVisual;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { VehicleCameraPose as a, VehicleCameraOptions as i, VehicleInteriorVisual as n, vehicleCameraPose as o, createVehicleInteriorVisual as r, VehicleInteriorSignals as t };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as createModelSignalVisual } from "./model-signals-Gw1COJfo.mjs";
|
|
2
|
+
//#region src/vehicle-interior.ts
|
|
3
|
+
/** Vehicle convenience wrapper around the platform's model-signal binding system. */
|
|
4
|
+
function createVehicleInteriorVisual(model, spec) {
|
|
5
|
+
const visual = createModelSignalVisual(model, spec);
|
|
6
|
+
return {
|
|
7
|
+
...visual,
|
|
8
|
+
missingNodes: [...new Set([...spec.nodes.filter((name) => !model.getObjectByName(name)), ...visual.missingNodes])]
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createVehicleInteriorVisual as t };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { a as VehicleCameraPose, i as VehicleCameraOptions, n as VehicleInteriorVisual, o as vehicleCameraPose, r as createVehicleInteriorVisual, t as VehicleInteriorSignals } from "./vehicle-interior-0o-8QV_-.mjs";
|
|
2
|
+
import { VehicleData, VehiclePlacement } from "@bendyline/molen-schema";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
|
|
5
|
+
//#region src/vehicles.d.ts
|
|
6
|
+
interface VehicleVisual {
|
|
7
|
+
object: THREE.Object3D;
|
|
8
|
+
interior?: VehicleInteriorVisual;
|
|
9
|
+
update(steer: number, wheelAngle: number, signals?: VehicleInteriorSignals): void;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
}
|
|
12
|
+
/** Bind a loaded entity GLB to generic wheel/steering animation using external node names. */
|
|
13
|
+
declare function createVehicleVisual(model: THREE.Object3D, vehicle: VehicleData): VehicleVisual;
|
|
14
|
+
/** Shared proxy geometry and instance batches for dormant terrain-owned entities. */
|
|
15
|
+
declare function createParkedVehicleBatch(placements: readonly VehiclePlacement[], origin?: [number, number]): THREE.Group;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type VehicleCameraOptions, type VehicleCameraPose, type VehicleInteriorSignals, type VehicleInteriorVisual, VehicleVisual, createParkedVehicleBatch, createVehicleInteriorVisual, createVehicleVisual, vehicleCameraPose };
|