@bendyline/molen-client 0.0.13 → 0.0.16
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 -1
- package/dist/aircraft.d.mts +10 -2
- package/dist/aircraft.mjs +570 -9
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +40 -3
- package/dist/index.mjs +850 -116
- package/dist/{input-BliZYUY1.mjs → input-CzlS1f2N.mjs} +5 -3
- package/dist/instance-batch-Ds-oKQW4.mjs +222 -0
- package/dist/instancing.d.mts +2 -0
- package/dist/instancing.mjs +3 -0
- package/dist/markers.d.mts +8 -0
- package/dist/markers.mjs +9 -2
- package/dist/navigation.d.mts +12 -3
- package/dist/navigation.mjs +25 -7
- package/dist/render-bounds-B4yQoiYR.d.mts +126 -0
- package/dist/render-bounds-uRp_yPp6.mjs +151 -0
- package/dist/{renderer-DAk7C8jH.d.mts → renderer-Scr1Mz0g.d.mts} +187 -7
- package/dist/snow-cover-Bh0woabf.mjs +218 -0
- package/dist/snow-cover-tEG1uO98.d.mts +67 -0
- package/dist/snow.d.mts +2 -0
- package/dist/snow.mjs +2 -0
- package/dist/{vehicle-interior-DJ4cXTsQ.mjs → vehicle-interior-CNLLi38s.mjs} +9 -1
- package/dist/vehicle-interior-XC2tAySI.d.mts +232 -0
- package/dist/vehicles.d.mts +43 -3
- package/dist/vehicles.mjs +594 -5
- package/dist/{webgpu-clouds-H03g7ID1.mjs → webgpu-clouds-DwSBoV8A.mjs} +15 -11
- package/dist/{webgpu-driver-BQnmPRqs.mjs → webgpu-driver-YWVTLOY7.mjs} +103 -4
- package/dist/webgpu-snow-cover-CiqYhvPq.mjs +55 -0
- package/package.json +11 -3
- package/dist/vehicle-interior-B8TpzTAx.d.mts +0 -56
|
@@ -214,8 +214,10 @@ var InputMap = class {
|
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
attach(target) {
|
|
217
|
-
const editable = (ev) => {
|
|
218
|
-
|
|
217
|
+
const editable = (ev, code) => {
|
|
218
|
+
const control = ev.target?.closest?.("input, textarea, select, button, a, summary, [contenteditable]:not([contenteditable=\"false\"]), [data-molen-input-editor]");
|
|
219
|
+
if (!control) return false;
|
|
220
|
+
return !(String(control.tagName).toUpperCase() === "INPUT" && String(control.type).toLowerCase() === "checkbox") || code === void 0 || code === "Space";
|
|
219
221
|
};
|
|
220
222
|
const add = (type, fn) => {
|
|
221
223
|
target.addEventListener(type, fn);
|
|
@@ -223,7 +225,7 @@ var InputMap = class {
|
|
|
223
225
|
};
|
|
224
226
|
add("keydown", (ev) => {
|
|
225
227
|
const event = ev;
|
|
226
|
-
if (editable(ev) || event.defaultPrevented || event.isComposing) return;
|
|
228
|
+
if (editable(ev, event.code) || event.defaultPrevented || event.isComposing) return;
|
|
227
229
|
if (event.metaKey || event.ctrlKey && !event.code.startsWith("Control") && resolveAction(this.profile.bindings, "ControlLeft") === void 0 && resolveAction(this.profile.bindings, "ControlRight") === void 0 || event.altKey && !event.code.startsWith("Alt") && resolveAction(this.profile.bindings, "AltLeft") === void 0 && resolveAction(this.profile.bindings, "AltRight") === void 0) return;
|
|
228
230
|
if (this.accepting && resolveAction(this.profile.bindings, event.code) !== void 0) event.preventDefault?.();
|
|
229
231
|
this.press(event.code);
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
//#region src/three/instance-batch.ts
|
|
3
|
+
/** The geometry attributes a batch's instance matrices are read through, one matrix column each. */
|
|
4
|
+
const INSTANCE_BATCH_MATRIX_COLUMNS = [
|
|
5
|
+
"instanceMatrix0",
|
|
6
|
+
"instanceMatrix1",
|
|
7
|
+
"instanceMatrix2",
|
|
8
|
+
"instanceMatrix3"
|
|
9
|
+
];
|
|
10
|
+
/** The geometry attribute a batch's instance colors are read through, when it has colors. */
|
|
11
|
+
const INSTANCE_BATCH_COLOR = "instanceColor";
|
|
12
|
+
/**
|
|
13
|
+
* A batch's instance matrices: one interleaved buffer that WebGL reads as a `mat4` attribute and
|
|
14
|
+
* WebGPU as four `vec4` columns, so either backend uploads it once. It keeps the `version` and
|
|
15
|
+
* `usage` an `InstancedBufferAttribute` reports, which its buffer holds.
|
|
16
|
+
*/
|
|
17
|
+
var InstanceMatrixAttribute = class extends THREE.InterleavedBufferAttribute {
|
|
18
|
+
isInstanceMatrixAttribute = true;
|
|
19
|
+
constructor(buffer) {
|
|
20
|
+
super(buffer, 16, 0);
|
|
21
|
+
}
|
|
22
|
+
get version() {
|
|
23
|
+
return this.data.version;
|
|
24
|
+
}
|
|
25
|
+
get usage() {
|
|
26
|
+
return this.data.usage;
|
|
27
|
+
}
|
|
28
|
+
setUsage(usage) {
|
|
29
|
+
this.data.setUsage(usage);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
get updateRanges() {
|
|
33
|
+
return this.data.updateRanges;
|
|
34
|
+
}
|
|
35
|
+
addUpdateRange(start, count) {
|
|
36
|
+
this.data.addUpdateRange(start, count);
|
|
37
|
+
}
|
|
38
|
+
clearUpdateRanges() {
|
|
39
|
+
this.data.clearUpdateRanges();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const INSTANCED = new Set([...INSTANCE_BATCH_MATRIX_COLUMNS, INSTANCE_BATCH_COLOR]);
|
|
43
|
+
const STATE = Symbol("molen.instanceBatch");
|
|
44
|
+
/** Marks a batch's own geometry with the model geometry it draws. */
|
|
45
|
+
const SOURCE = Symbol("molen.instanceBatch.source");
|
|
46
|
+
function stateOf(batch) {
|
|
47
|
+
const owner = batch;
|
|
48
|
+
let state = owner[STATE];
|
|
49
|
+
if (state === void 0) {
|
|
50
|
+
state = {
|
|
51
|
+
geometries: /* @__PURE__ */ new Map(),
|
|
52
|
+
current: void 0,
|
|
53
|
+
matrices: void 0,
|
|
54
|
+
colors: null,
|
|
55
|
+
count: 0,
|
|
56
|
+
constructed: false
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(owner, STATE, { value: state });
|
|
59
|
+
}
|
|
60
|
+
return state;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* An `InstancedMesh` whose instances live in a geometry of its own, so WebGPU builds its shaders
|
|
64
|
+
* once for every batch of the same material and model layout instead of once per batch.
|
|
65
|
+
*
|
|
66
|
+
* Three's WebGPU renderer keys an instanced mesh's node build by the mesh, since its instance
|
|
67
|
+
* matrices are a node bound to that mesh's buffer: every batch streamed in paid a build of its own,
|
|
68
|
+
* about 10 ms of main thread each, which was most of a flight's streaming work. A batch instead
|
|
69
|
+
* carries its matrices and colors as instanced vertex attributes of an `InstancedBufferGeometry`
|
|
70
|
+
* that shares the model geometry's buffers, and the WebGPU driver reads them by name, the way it
|
|
71
|
+
* reads `position`: one build serves every batch, and each draw binds its own batch's vertex
|
|
72
|
+
* buffers, which a recorded render bundle replays as recorded. WebGL draws it as the
|
|
73
|
+
* `InstancedMesh` it is, with no setup, through three's own instancing.
|
|
74
|
+
*
|
|
75
|
+
* It keeps `InstancedMesh`'s API: `count`, `setMatrixAt`, `setColorAt`, bounds, raycasting and
|
|
76
|
+
* `dispose`. Assigning `geometry` selects the model it draws (a level of detail can swap it each
|
|
77
|
+
* frame without a new build, as long as the models share an attribute layout); `geometry` then reads
|
|
78
|
+
* back as the batch's own geometry and `sourceGeometry` as the model. Set colors before the first
|
|
79
|
+
* draw: a batch drawn without colors keeps its build. Models with morph targets are not supported.
|
|
80
|
+
*/
|
|
81
|
+
var InstanceBatch = class extends THREE.InstancedMesh {
|
|
82
|
+
constructor(geometry, material, count) {
|
|
83
|
+
super(geometry, material, count);
|
|
84
|
+
stateOf(this).constructed = true;
|
|
85
|
+
}
|
|
86
|
+
/** The model geometry this batch draws (what `geometry` was last set to). */
|
|
87
|
+
get sourceGeometry() {
|
|
88
|
+
return stateOf(this).current?.[SOURCE];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Draw the instances in `matrices`, sixteen floats each as `Matrix4.elements` lays them out.
|
|
92
|
+
* The batch takes the array over; set `count` to match.
|
|
93
|
+
*/
|
|
94
|
+
setInstanceMatrices(matrices) {
|
|
95
|
+
const buffer = new THREE.InstancedInterleavedBuffer(matrices, 16, 1);
|
|
96
|
+
adoptMatrices(stateOf(this), new InstanceMatrixAttribute(buffer));
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/** Every geometry of this batch's own, one per model it has drawn. */
|
|
100
|
+
batchGeometries() {
|
|
101
|
+
return [...stateOf(this).geometries.values()];
|
|
102
|
+
}
|
|
103
|
+
copy(source, recursive) {
|
|
104
|
+
THREE.Mesh.prototype.copy.call(this, source, recursive);
|
|
105
|
+
const state = stateOf(this);
|
|
106
|
+
const from = stateOf(source);
|
|
107
|
+
if (from.matrices !== void 0) {
|
|
108
|
+
const buffer = from.matrices.data;
|
|
109
|
+
const copied = new THREE.InstancedInterleavedBuffer(new Float32Array(buffer.array), 16, buffer.meshPerAttribute);
|
|
110
|
+
copied.setUsage(buffer.usage);
|
|
111
|
+
state.matrices = new InstanceMatrixAttribute(copied);
|
|
112
|
+
}
|
|
113
|
+
this.instanceColor = from.colors === null ? null : from.colors.clone();
|
|
114
|
+
this.count = from.count;
|
|
115
|
+
for (const geometry of state.geometries.values()) attachInstances(geometry, state);
|
|
116
|
+
this.boundingBox = source.boundingBox?.clone() ?? null;
|
|
117
|
+
this.boundingSphere = source.boundingSphere?.clone() ?? null;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Release the batch's buffers. Its own geometries are released with it, but not the model
|
|
122
|
+
* geometry's buffers, which other batches share: a disposed batch is not drawn again.
|
|
123
|
+
*/
|
|
124
|
+
dispose() {
|
|
125
|
+
super.dispose();
|
|
126
|
+
for (const geometry of stateOf(this).geometries.values()) {
|
|
127
|
+
const shared = Object.keys(geometry.attributes).filter((name) => !INSTANCED.has(name));
|
|
128
|
+
const kept = { ...geometry.attributes };
|
|
129
|
+
const index = geometry.index;
|
|
130
|
+
for (const name of shared) geometry.deleteAttribute(name);
|
|
131
|
+
geometry.index = null;
|
|
132
|
+
geometry.dispose();
|
|
133
|
+
geometry.index = index;
|
|
134
|
+
for (const name of shared) geometry.setAttribute(name, kept[name]);
|
|
135
|
+
}
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
Object.defineProperty(InstanceBatch.prototype, "isInstanceBatch", { value: true });
|
|
140
|
+
/** Whether `object` is an `InstanceBatch`. */
|
|
141
|
+
function isInstanceBatch(object) {
|
|
142
|
+
return object?.isInstanceBatch === true;
|
|
143
|
+
}
|
|
144
|
+
/** Whether `geometry` is one of an `InstanceBatch`'s own geometries. */
|
|
145
|
+
function isInstanceBatchGeometry(geometry) {
|
|
146
|
+
return geometry[SOURCE] !== void 0;
|
|
147
|
+
}
|
|
148
|
+
function attachInstances(geometry, state) {
|
|
149
|
+
const matrices = state.matrices;
|
|
150
|
+
if (matrices !== void 0) INSTANCE_BATCH_MATRIX_COLUMNS.forEach((name, column) => {
|
|
151
|
+
if (geometry.getAttribute(name)?.data !== matrices.data) geometry.setAttribute(name, new THREE.InterleavedBufferAttribute(matrices.data, 4, column * 4));
|
|
152
|
+
});
|
|
153
|
+
if (state.colors === null) geometry.deleteAttribute(INSTANCE_BATCH_COLOR);
|
|
154
|
+
else if (geometry.getAttribute("instanceColor") !== state.colors) geometry.setAttribute(INSTANCE_BATCH_COLOR, state.colors);
|
|
155
|
+
geometry.instanceCount = state.count;
|
|
156
|
+
}
|
|
157
|
+
function batchGeometry(state, source) {
|
|
158
|
+
let geometry = state.geometries.get(source);
|
|
159
|
+
if (geometry !== void 0) return geometry;
|
|
160
|
+
if (source.isInstancedBufferGeometry === true) throw new Error("An InstanceBatch draws a plain model geometry; its instances are its own");
|
|
161
|
+
if (Object.keys(source.morphAttributes).length > 0) throw new Error("An InstanceBatch cannot draw a model with morph targets");
|
|
162
|
+
geometry = new THREE.InstancedBufferGeometry();
|
|
163
|
+
geometry.name = source.name;
|
|
164
|
+
geometry.index = source.index;
|
|
165
|
+
for (const [name, attribute] of Object.entries(source.attributes)) geometry.setAttribute(name, attribute);
|
|
166
|
+
for (const group of source.groups) geometry.addGroup(group.start, group.count, group.materialIndex);
|
|
167
|
+
geometry.drawRange = source.drawRange;
|
|
168
|
+
geometry.boundingBox = source.boundingBox;
|
|
169
|
+
geometry.boundingSphere = source.boundingSphere;
|
|
170
|
+
geometry.userData = source.userData;
|
|
171
|
+
geometry[SOURCE] = source;
|
|
172
|
+
attachInstances(geometry, state);
|
|
173
|
+
state.geometries.set(source, geometry);
|
|
174
|
+
return geometry;
|
|
175
|
+
}
|
|
176
|
+
function adoptMatrices(state, value) {
|
|
177
|
+
if (value.isInstanceMatrixAttribute === true) state.matrices = value;
|
|
178
|
+
else if (!state.constructed && value.itemSize === 16) state.matrices = new InstanceMatrixAttribute(new THREE.InstancedInterleavedBuffer(value.array, 16, 1));
|
|
179
|
+
else throw new Error("An InstanceBatch's instanceMatrix is its own or another batch's (to share instances)");
|
|
180
|
+
for (const geometry of state.geometries.values()) attachInstances(geometry, state);
|
|
181
|
+
}
|
|
182
|
+
Object.defineProperties(InstanceBatch.prototype, {
|
|
183
|
+
geometry: {
|
|
184
|
+
get() {
|
|
185
|
+
return stateOf(this).current;
|
|
186
|
+
},
|
|
187
|
+
set(value) {
|
|
188
|
+
const state = stateOf(this);
|
|
189
|
+
state.current = batchGeometry(state, value[SOURCE] ?? value);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
instanceMatrix: {
|
|
193
|
+
get() {
|
|
194
|
+
return stateOf(this).matrices;
|
|
195
|
+
},
|
|
196
|
+
set(value) {
|
|
197
|
+
adoptMatrices(stateOf(this), value);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
instanceColor: {
|
|
201
|
+
get() {
|
|
202
|
+
return stateOf(this).colors;
|
|
203
|
+
},
|
|
204
|
+
set(value) {
|
|
205
|
+
const state = stateOf(this);
|
|
206
|
+
state.colors = value;
|
|
207
|
+
for (const geometry of state.geometries.values()) attachInstances(geometry, state);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
count: {
|
|
211
|
+
get() {
|
|
212
|
+
return stateOf(this).count;
|
|
213
|
+
},
|
|
214
|
+
set(value) {
|
|
215
|
+
const state = stateOf(this);
|
|
216
|
+
state.count = value;
|
|
217
|
+
for (const geometry of state.geometries.values()) geometry.instanceCount = value;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
//#endregion
|
|
222
|
+
export { isInstanceBatch as a, InstanceMatrixAttribute as i, INSTANCE_BATCH_MATRIX_COLUMNS as n, isInstanceBatchGeometry as o, InstanceBatch as r, INSTANCE_BATCH_COLOR as t };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as expandRenderBounds, c as INSTANCE_BATCH_COLOR, d as InstanceMatrixAttribute, f as isInstanceBatch, i as boxOutsideView, l as INSTANCE_BATCH_MATRIX_COLUMNS, n as RENDER_BOUNDS_STALE, o as markRenderBoundsChanged, p as isInstanceBatchGeometry, r as RENDER_MATRICES_STALE, s as viewProjection, t as RENDER_BOUNDS, u as InstanceBatch } from "./render-bounds-B4yQoiYR.mjs";
|
|
2
|
+
export { INSTANCE_BATCH_COLOR, INSTANCE_BATCH_MATRIX_COLUMNS, InstanceBatch, InstanceMatrixAttribute, RENDER_BOUNDS, RENDER_BOUNDS_STALE, RENDER_MATRICES_STALE, boxOutsideView, expandRenderBounds, isInstanceBatch, isInstanceBatchGeometry, markRenderBoundsChanged, viewProjection };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as expandRenderBounds, i as boxOutsideView, n as RENDER_BOUNDS_STALE, o as markRenderBoundsChanged, r as RENDER_MATRICES_STALE, s as viewProjection, t as RENDER_BOUNDS } from "./render-bounds-uRp_yPp6.mjs";
|
|
2
|
+
import { a as isInstanceBatch, i as InstanceMatrixAttribute, n as INSTANCE_BATCH_MATRIX_COLUMNS, o as isInstanceBatchGeometry, r as InstanceBatch, t as INSTANCE_BATCH_COLOR } from "./instance-batch-Ds-oKQW4.mjs";
|
|
3
|
+
export { INSTANCE_BATCH_COLOR, INSTANCE_BATCH_MATRIX_COLUMNS, InstanceBatch, InstanceMatrixAttribute, RENDER_BOUNDS, RENDER_BOUNDS_STALE, RENDER_MATRICES_STALE, boxOutsideView, expandRenderBounds, isInstanceBatch, isInstanceBatchGeometry, markRenderBoundsChanged, viewProjection };
|
package/dist/markers.d.mts
CHANGED
|
@@ -61,6 +61,14 @@ interface MarkerSpec {
|
|
|
61
61
|
interface MarkerLayerOptions {
|
|
62
62
|
/** Ground height at world X/Z, or undefined while unknown. Required for ground-snapped markers. */
|
|
63
63
|
groundHeight?: (x: number, z: number) => number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* How often a grounded marker reads its ground height again, ms (default 0: every update). The
|
|
66
|
+
* ground beneath a marker changes only as terrain streams in, and a host whose `groundHeight`
|
|
67
|
+
* samples streamed terrain pays for every read: a city's photo pins re-read each frame took
|
|
68
|
+
* about 3% of the main thread while an Earth view loaded. A marker not yet grounded, or moved,
|
|
69
|
+
* reads it at every update until it has one.
|
|
70
|
+
*/
|
|
71
|
+
groundRefreshMs?: number;
|
|
64
72
|
/** Most markers drawn at once; extras nearest last are hidden (default 256). */
|
|
65
73
|
maxVisible?: number;
|
|
66
74
|
/** Distances (meters) over which markers fade out: full at `near`, gone at `far`. */
|
package/dist/markers.mjs
CHANGED
|
@@ -159,13 +159,19 @@ var MarkerLayer = class {
|
|
|
159
159
|
const fadeMs = this.options.fadeMs ?? 180;
|
|
160
160
|
const fadeStep = fadeMs > 0 ? elapsedMs / fadeMs : Number.POSITIVE_INFINITY;
|
|
161
161
|
const hideUntilGrounded = this.options.hideUntilGrounded ?? true;
|
|
162
|
+
const groundRefreshMs = this.options.groundRefreshMs ?? 0;
|
|
162
163
|
const candidates = [];
|
|
163
164
|
for (const entry of this.entries.values()) {
|
|
164
165
|
const { spec } = entry;
|
|
165
166
|
let y = spec.y;
|
|
166
167
|
if (y === void 0) {
|
|
167
|
-
|
|
168
|
-
|
|
168
|
+
if (entry.groundY === void 0 || nowMs - entry.groundReadMs >= groundRefreshMs) {
|
|
169
|
+
const ground = this.options.groundHeight?.(spec.x, spec.z);
|
|
170
|
+
if (ground !== void 0) {
|
|
171
|
+
entry.groundY = ground;
|
|
172
|
+
entry.groundReadMs = nowMs;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
169
175
|
y = entry.groundY === void 0 ? hideUntilGrounded ? void 0 : spec.elevation ?? 0 : entry.groundY + (spec.elevation ?? 0);
|
|
170
176
|
}
|
|
171
177
|
entry.sprite.visible = false;
|
|
@@ -314,6 +320,7 @@ var MarkerLayer = class {
|
|
|
314
320
|
imageKey: spec.image,
|
|
315
321
|
aspect: imageAspect(spec.image) ?? 1,
|
|
316
322
|
groundY: void 0,
|
|
323
|
+
groundReadMs: Number.NEGATIVE_INFINITY,
|
|
317
324
|
distance: 0,
|
|
318
325
|
shown: false,
|
|
319
326
|
presence: 0
|
package/dist/navigation.d.mts
CHANGED
|
@@ -175,6 +175,7 @@ declare const NAVIGATION_ACTIONS: {
|
|
|
175
175
|
readonly gear: "nav-gear";
|
|
176
176
|
readonly flaps: "nav-flaps";
|
|
177
177
|
readonly vector: "nav-vector";
|
|
178
|
+
readonly cyclic: "nav-cyclic";
|
|
178
179
|
readonly recover: "nav-recover";
|
|
179
180
|
};
|
|
180
181
|
/** The navigation modes with a default input profile. */
|
|
@@ -184,9 +185,9 @@ type NavigationProfileName = "orbit" | "fly" | "walk" | "drive" | "pilot";
|
|
|
184
185
|
* drive use E to interact (board or leave a vehicle), Space to jump or brake, Shift to sprint
|
|
185
186
|
* or pull the handbrake, and V to switch the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→)
|
|
186
187
|
* bank, Z/C work the rudder or pedals, =/− (or numpad +/−, Page Up/Down) set throttle or
|
|
187
|
-
* collective,
|
|
188
|
-
*
|
|
189
|
-
* Hosts may replace any profile through
|
|
188
|
+
* collective, and Ctrl stays free for browser shortcuts such as Ctrl+W. I toggles the engine, G
|
|
189
|
+
* the gear, F the flaps, M a helicopter's cyclic between assisted and direct, R recovers after
|
|
190
|
+
* an impact, Space brakes, V switches the view and E leaves. T toggles travel boost in walk, drive and pilot. Hosts may replace any profile through
|
|
190
191
|
* `InputMap.defineProfile`.
|
|
191
192
|
*/
|
|
192
193
|
declare function navigationInputProfiles(): Record<NavigationProfileName, InputProfile>;
|
|
@@ -204,6 +205,8 @@ interface PilotInput {
|
|
|
204
205
|
flaps: number;
|
|
205
206
|
/** Powered-lift lever advances through 0, 25, 50, 75, 100 percent on each press. */
|
|
206
207
|
vector?: number;
|
|
208
|
+
/** Helicopter cyclic toggles between assisted and direct (full authority). */
|
|
209
|
+
cyclic?: number;
|
|
207
210
|
recover: number;
|
|
208
211
|
}
|
|
209
212
|
/** Everything a navigation controller reads in one frame. */
|
|
@@ -618,6 +621,12 @@ declare class WalkController {
|
|
|
618
621
|
swimming: boolean;
|
|
619
622
|
/** Water surface in world meters; null means dry, undefined means coverage is loading. */
|
|
620
623
|
sampleWaterHeight?: (x: number, z: number) => number | null | undefined;
|
|
624
|
+
/**
|
|
625
|
+
* Share of walking and running speed left at the feet (world meters): what the ground costs,
|
|
626
|
+
* such as deep snow (`snowWalkingPace`). Default 1; values are kept within 0.1–1, and swimming
|
|
627
|
+
* ignores it.
|
|
628
|
+
*/
|
|
629
|
+
paceAt?: (x: number, y: number, z: number) => number;
|
|
621
630
|
ready: boolean;
|
|
622
631
|
waitingForTerrain: boolean;
|
|
623
632
|
private accumulator;
|
package/dist/navigation.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as InputMap } from "./input-
|
|
1
|
+
import { t as InputMap } from "./input-CzlS1f2N.mjs";
|
|
2
|
+
import { a as isInstanceBatch } from "./instance-batch-Ds-oKQW4.mjs";
|
|
2
3
|
import { boostSpeedMultiplier } from "@bendyline/molen-schema";
|
|
3
4
|
import * as THREE from "three";
|
|
4
5
|
import { Octree } from "three/addons/math/Octree.js";
|
|
@@ -252,6 +253,9 @@ var NavigationPointer = class {
|
|
|
252
253
|
}
|
|
253
254
|
down(event) {
|
|
254
255
|
this.surface.focus?.({ preventScroll: true });
|
|
256
|
+
try {
|
|
257
|
+
this.surface.setPointerCapture?.(event.pointerId);
|
|
258
|
+
} catch {}
|
|
255
259
|
if (this.pointerLock && event.pointerType !== "touch" && !this.locked()) {
|
|
256
260
|
const request = this.surface.requestPointerLock?.();
|
|
257
261
|
if (request instanceof Promise) request.catch(() => {});
|
|
@@ -267,7 +271,6 @@ var NavigationPointer = class {
|
|
|
267
271
|
pan: button === 1 || button === 2 || event.shiftKey === true
|
|
268
272
|
});
|
|
269
273
|
if (this.pointers.size > 1) for (const pointer of this.pointers.values()) pointer.moved = true;
|
|
270
|
-
this.surface.setPointerCapture?.(event.pointerId);
|
|
271
274
|
}
|
|
272
275
|
move(event) {
|
|
273
276
|
if (this.locked() && this.pointers.size <= 1) {
|
|
@@ -369,6 +372,7 @@ const NAVIGATION_ACTIONS = {
|
|
|
369
372
|
gear: "nav-gear",
|
|
370
373
|
flaps: "nav-flaps",
|
|
371
374
|
vector: "nav-vector",
|
|
375
|
+
cyclic: "nav-cyclic",
|
|
372
376
|
recover: "nav-recover"
|
|
373
377
|
};
|
|
374
378
|
const ACTUATOR_KEYS = {
|
|
@@ -445,9 +449,9 @@ const STICKS = [
|
|
|
445
449
|
* drive use E to interact (board or leave a vehicle), Space to jump or brake, Shift to sprint
|
|
446
450
|
* or pull the handbrake, and V to switch the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→)
|
|
447
451
|
* bank, Z/C work the rudder or pedals, =/− (or numpad +/−, Page Up/Down) set throttle or
|
|
448
|
-
* collective,
|
|
449
|
-
*
|
|
450
|
-
* Hosts may replace any profile through
|
|
452
|
+
* collective, and Ctrl stays free for browser shortcuts such as Ctrl+W. I toggles the engine, G
|
|
453
|
+
* the gear, F the flaps, M a helicopter's cyclic between assisted and direct, R recovers after
|
|
454
|
+
* an impact, Space brakes, V switches the view and E leaves. T toggles travel boost in walk, drive and pilot. Hosts may replace any profile through
|
|
451
455
|
* `InputMap.defineProfile`.
|
|
452
456
|
*/
|
|
453
457
|
function navigationInputProfiles() {
|
|
@@ -531,6 +535,7 @@ function navigationInputProfiles() {
|
|
|
531
535
|
KeyG: A.gear,
|
|
532
536
|
KeyF: A.flaps,
|
|
533
537
|
KeyJ: A.vector,
|
|
538
|
+
KeyM: A.cyclic,
|
|
534
539
|
KeyR: A.recover
|
|
535
540
|
},
|
|
536
541
|
axes: STICKS,
|
|
@@ -620,6 +625,7 @@ var NavigationInputSource = class {
|
|
|
620
625
|
gear: 0,
|
|
621
626
|
flaps: 0,
|
|
622
627
|
vector: 0,
|
|
628
|
+
cyclic: 0,
|
|
623
629
|
recover: 0
|
|
624
630
|
};
|
|
625
631
|
lookSpeed;
|
|
@@ -645,6 +651,7 @@ var NavigationInputSource = class {
|
|
|
645
651
|
"gear",
|
|
646
652
|
"flaps",
|
|
647
653
|
"vector",
|
|
654
|
+
"cyclic",
|
|
648
655
|
"recover"
|
|
649
656
|
].map((name) => this.map.onPress(A[name], () => {
|
|
650
657
|
this.pilotPresses[name]++;
|
|
@@ -668,6 +675,7 @@ var NavigationInputSource = class {
|
|
|
668
675
|
this.pilotPresses.gear = 0;
|
|
669
676
|
this.pilotPresses.flaps = 0;
|
|
670
677
|
this.pilotPresses.vector = 0;
|
|
678
|
+
this.pilotPresses.cyclic = 0;
|
|
671
679
|
this.pilotPresses.recover = 0;
|
|
672
680
|
})
|
|
673
681
|
];
|
|
@@ -727,6 +735,7 @@ var NavigationInputSource = class {
|
|
|
727
735
|
this.pilotPresses.gear = 0;
|
|
728
736
|
this.pilotPresses.flaps = 0;
|
|
729
737
|
this.pilotPresses.vector = 0;
|
|
738
|
+
this.pilotPresses.cyclic = 0;
|
|
730
739
|
this.pilotPresses.recover = 0;
|
|
731
740
|
this.actuatorPresses = {};
|
|
732
741
|
return input;
|
|
@@ -952,6 +961,7 @@ function createNavigationControls(source, options) {
|
|
|
952
961
|
[NAVIGATION_ACTIONS.gear, "Landing gear"],
|
|
953
962
|
[NAVIGATION_ACTIONS.flaps, "Flaps"],
|
|
954
963
|
[NAVIGATION_ACTIONS.vector, "Thrust vector"],
|
|
964
|
+
[NAVIGATION_ACTIONS.cyclic, "Helicopter cyclic: assisted / direct"],
|
|
955
965
|
[NAVIGATION_ACTIONS.recover, "Recover"]
|
|
956
966
|
] : [
|
|
957
967
|
[NAVIGATION_ACTIONS.sprint, "Sprint / handbrake"],
|
|
@@ -1827,7 +1837,7 @@ var WalkCollision = class {
|
|
|
1827
1837
|
const c = new THREE.Vector3();
|
|
1828
1838
|
const inside = () => bounds.min.x <= radius && bounds.max.x >= -radius && bounds.min.z <= radius && bounds.max.z >= -radius && bounds.min.y <= maxY && bounds.max.y >= minY;
|
|
1829
1839
|
for (const { mesh, matrix, count } of meshes) {
|
|
1830
|
-
const geometry = mesh.geometry;
|
|
1840
|
+
const geometry = isInstanceBatch(mesh) ? mesh.sourceGeometry : mesh.geometry;
|
|
1831
1841
|
const position = geometry.getAttribute("position");
|
|
1832
1842
|
if (position === void 0) continue;
|
|
1833
1843
|
geometryBounds(geometry);
|
|
@@ -2011,6 +2021,12 @@ var WalkController = class {
|
|
|
2011
2021
|
swimming = false;
|
|
2012
2022
|
/** Water surface in world meters; null means dry, undefined means coverage is loading. */
|
|
2013
2023
|
sampleWaterHeight;
|
|
2024
|
+
/**
|
|
2025
|
+
* Share of walking and running speed left at the feet (world meters): what the ground costs,
|
|
2026
|
+
* such as deep snow (`snowWalkingPace`). Default 1; values are kept within 0.1–1, and swimming
|
|
2027
|
+
* ignores it.
|
|
2028
|
+
*/
|
|
2029
|
+
paceAt;
|
|
2014
2030
|
ready = false;
|
|
2015
2031
|
waitingForTerrain = false;
|
|
2016
2032
|
accumulator = 0;
|
|
@@ -2083,7 +2099,9 @@ var WalkController = class {
|
|
|
2083
2099
|
this.accumulator += Math.min(.1, Math.max(0, dt));
|
|
2084
2100
|
while (this.accumulator >= STEP) {
|
|
2085
2101
|
this.accumulator -= STEP;
|
|
2086
|
-
const
|
|
2102
|
+
const moving = input.forward !== 0 || input.right !== 0;
|
|
2103
|
+
const pace = this.swimming || !moving || this.paceAt === void 0 ? 1 : Math.min(1, Math.max(.1, this.paceAt(this.feet.x, this.feet.y, this.feet.z)));
|
|
2104
|
+
const speed = (this.swimming ? SWIM_SPEED * (input.sprint ? 1.5 : 1) : (input.sprint ? 4 : WALK_SPEED) * pace) * boostSpeedMultiplier(this.boostMode);
|
|
2087
2105
|
const vx = forwardX * speed;
|
|
2088
2106
|
const vz = forwardZ * speed;
|
|
2089
2107
|
const nextX = this.feet.x + vx * STEP;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
|
|
3
|
+
//#region src/three/instance-batch.d.ts
|
|
4
|
+
/** The geometry attributes a batch's instance matrices are read through, one matrix column each. */
|
|
5
|
+
declare const INSTANCE_BATCH_MATRIX_COLUMNS: readonly string[];
|
|
6
|
+
/** The geometry attribute a batch's instance colors are read through, when it has colors. */
|
|
7
|
+
declare const INSTANCE_BATCH_COLOR = "instanceColor";
|
|
8
|
+
/**
|
|
9
|
+
* A batch's instance matrices: one interleaved buffer that WebGL reads as a `mat4` attribute and
|
|
10
|
+
* WebGPU as four `vec4` columns, so either backend uploads it once. It keeps the `version` and
|
|
11
|
+
* `usage` an `InstancedBufferAttribute` reports, which its buffer holds.
|
|
12
|
+
*/
|
|
13
|
+
declare class InstanceMatrixAttribute extends THREE.InterleavedBufferAttribute {
|
|
14
|
+
readonly isInstanceMatrixAttribute = true;
|
|
15
|
+
constructor(buffer: THREE.InstancedInterleavedBuffer);
|
|
16
|
+
get version(): number;
|
|
17
|
+
get usage(): THREE.Usage;
|
|
18
|
+
setUsage(usage: THREE.Usage): this;
|
|
19
|
+
get updateRanges(): {
|
|
20
|
+
start: number;
|
|
21
|
+
count: number;
|
|
22
|
+
}[];
|
|
23
|
+
addUpdateRange(start: number, count: number): void;
|
|
24
|
+
clearUpdateRanges(): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* An `InstancedMesh` whose instances live in a geometry of its own, so WebGPU builds its shaders
|
|
28
|
+
* once for every batch of the same material and model layout instead of once per batch.
|
|
29
|
+
*
|
|
30
|
+
* Three's WebGPU renderer keys an instanced mesh's node build by the mesh, since its instance
|
|
31
|
+
* matrices are a node bound to that mesh's buffer: every batch streamed in paid a build of its own,
|
|
32
|
+
* about 10 ms of main thread each, which was most of a flight's streaming work. A batch instead
|
|
33
|
+
* carries its matrices and colors as instanced vertex attributes of an `InstancedBufferGeometry`
|
|
34
|
+
* that shares the model geometry's buffers, and the WebGPU driver reads them by name, the way it
|
|
35
|
+
* reads `position`: one build serves every batch, and each draw binds its own batch's vertex
|
|
36
|
+
* buffers, which a recorded render bundle replays as recorded. WebGL draws it as the
|
|
37
|
+
* `InstancedMesh` it is, with no setup, through three's own instancing.
|
|
38
|
+
*
|
|
39
|
+
* It keeps `InstancedMesh`'s API: `count`, `setMatrixAt`, `setColorAt`, bounds, raycasting and
|
|
40
|
+
* `dispose`. Assigning `geometry` selects the model it draws (a level of detail can swap it each
|
|
41
|
+
* frame without a new build, as long as the models share an attribute layout); `geometry` then reads
|
|
42
|
+
* back as the batch's own geometry and `sourceGeometry` as the model. Set colors before the first
|
|
43
|
+
* draw: a batch drawn without colors keeps its build. Models with morph targets are not supported.
|
|
44
|
+
*/
|
|
45
|
+
declare class InstanceBatch<TMaterial extends THREE.Material | THREE.Material[] = THREE.Material | THREE.Material[]> extends THREE.InstancedMesh<THREE.BufferGeometry, TMaterial> {
|
|
46
|
+
readonly isInstanceBatch: true;
|
|
47
|
+
constructor(geometry: THREE.BufferGeometry, material: TMaterial, count: number);
|
|
48
|
+
/** The model geometry this batch draws (what `geometry` was last set to). */
|
|
49
|
+
get sourceGeometry(): THREE.BufferGeometry;
|
|
50
|
+
/**
|
|
51
|
+
* Draw the instances in `matrices`, sixteen floats each as `Matrix4.elements` lays them out.
|
|
52
|
+
* The batch takes the array over; set `count` to match.
|
|
53
|
+
*/
|
|
54
|
+
setInstanceMatrices(matrices: Float32Array): this;
|
|
55
|
+
/** Every geometry of this batch's own, one per model it has drawn. */
|
|
56
|
+
batchGeometries(): THREE.BufferGeometry[];
|
|
57
|
+
override copy(source: InstanceBatch<TMaterial>, recursive?: boolean): this;
|
|
58
|
+
/**
|
|
59
|
+
* Release the batch's buffers. Its own geometries are released with it, but not the model
|
|
60
|
+
* geometry's buffers, which other batches share: a disposed batch is not drawn again.
|
|
61
|
+
*/
|
|
62
|
+
override dispose(): this;
|
|
63
|
+
}
|
|
64
|
+
/** Whether `object` is an `InstanceBatch`. */
|
|
65
|
+
declare function isInstanceBatch(object: unknown): object is InstanceBatch;
|
|
66
|
+
/** Whether `geometry` is one of an `InstanceBatch`'s own geometries. */
|
|
67
|
+
declare function isInstanceBatchGeometry(geometry: THREE.BufferGeometry): boolean;
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/three/render-bounds.d.ts
|
|
70
|
+
/**
|
|
71
|
+
* `userData` key of a render group's bounds: a `THREE.Box3` in the frame of the group's parent
|
|
72
|
+
* that contains everything the group draws, now and as its parts move. A group without one is
|
|
73
|
+
* never left out.
|
|
74
|
+
*/
|
|
75
|
+
declare const RENDER_BOUNDS: "renderBounds";
|
|
76
|
+
/** `userData` flag asking a group's owner to work its bounds out again (see `markRenderBoundsChanged`). */
|
|
77
|
+
declare const RENDER_BOUNDS_STALE: "renderBoundsStale";
|
|
78
|
+
/**
|
|
79
|
+
* `userData` flag an owner sets on its render group when it adds content to it: that content has
|
|
80
|
+
* no world matrices until a walk reaches it, and the renderer may be leaving the group out of the
|
|
81
|
+
* scene's walk. Before a shadow map draws a group it left out, the renderer brings a flagged
|
|
82
|
+
* group's matrices up to date and clears the flag; an owner whose group skips walks while hidden
|
|
83
|
+
* clears it in the walk it does make.
|
|
84
|
+
*/
|
|
85
|
+
declare const RENDER_MATRICES_STALE: "renderMatricesStale";
|
|
86
|
+
/**
|
|
87
|
+
* Tell the render group above `object` that what it draws has changed size: call it after adding
|
|
88
|
+
* or replacing geometry inside streamed content once that content is on show (a landmark's next
|
|
89
|
+
* level of detail arriving, say). The group's owner works its bounds out again before the next
|
|
90
|
+
* frame. Does nothing for an object outside any group with bounds.
|
|
91
|
+
*/
|
|
92
|
+
declare function markRenderBoundsChanged(object: THREE.Object3D): void;
|
|
93
|
+
/** A camera's view volume as the matrix from world to clip space, for `boxOutsideView`. */
|
|
94
|
+
declare function viewProjection(camera: THREE.Camera, target: THREE.Matrix4): THREE.Matrix4;
|
|
95
|
+
/** A camera's depth range, for `boxOutsideView`: its view matrix and the planes it draws between. */
|
|
96
|
+
interface ViewDepth {
|
|
97
|
+
view: THREE.Matrix4;
|
|
98
|
+
near: number;
|
|
99
|
+
far: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Whether a world-space box lies wholly outside a camera's view: every corner beyond the same
|
|
103
|
+
* side of it, or all of them behind a perspective camera. Without `depth` the near and far planes
|
|
104
|
+
* are not tested (ground a camera's far plane cuts is still wanted, and the test then holds for
|
|
105
|
+
* either depth convention). With it, a box wholly nearer than `near` or beyond `far` along the
|
|
106
|
+
* camera's axis is outside too, read in view space: an orthographic shadow map is a box, and
|
|
107
|
+
* ground far along the light's direction lines up with it without being in it. A box across a
|
|
108
|
+
* corner of the view can read as inside when it is not, which only costs the walk it would have
|
|
109
|
+
* saved.
|
|
110
|
+
*/
|
|
111
|
+
declare function boxOutsideView(matrix: THREE.Matrix4, min: THREE.Vector3, max: THREE.Vector3, depth?: ViewDepth): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Grow `bounds` (in `frame`'s own coordinates) to hold everything `object` draws: each mesh's
|
|
114
|
+
* bounding box where it has one already (an instanced mesh's own, over its instances), and
|
|
115
|
+
* otherwise the box round its bounding sphere, which three works out for its own culling anyway.
|
|
116
|
+
* Nothing is measured from vertices that three would not measure too: a box computed here for
|
|
117
|
+
* every building's geometry was a pass over a dense tile's half a million vertices, 5 ms of the
|
|
118
|
+
* job that published it. An object marked `userData.dynamicTransform` may turn about its own
|
|
119
|
+
* origin, so it and what is under it count as the sphere they can sweep there; one that travels
|
|
120
|
+
* needs its owner to state bounds for the whole of its way. Local matrices are read as they stand
|
|
121
|
+
* (static content has them frozen), so the object need not have been drawn or even attached.
|
|
122
|
+
* `padding` is added round each part.
|
|
123
|
+
*/
|
|
124
|
+
declare function expandRenderBounds(bounds: THREE.Box3, object: THREE.Object3D, frame: THREE.Object3D, padding?: number): THREE.Box3;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { expandRenderBounds as a, INSTANCE_BATCH_COLOR as c, InstanceMatrixAttribute as d, isInstanceBatch as f, boxOutsideView as i, INSTANCE_BATCH_MATRIX_COLUMNS as l, RENDER_BOUNDS_STALE as n, markRenderBoundsChanged as o, isInstanceBatchGeometry as p, RENDER_MATRICES_STALE as r, viewProjection as s, RENDER_BOUNDS as t, InstanceBatch as u };
|