@bendyline/molen-client 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/aircraft.d.mts +11 -4
- package/dist/aircraft.mjs +56 -10
- package/dist/audio.d.mts +9 -0
- package/dist/audio.mjs +68 -10
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.mjs +260 -28
- package/dist/{input-CfbIm1MS.mjs → input-BVZjf4T-.mjs} +6 -2
- package/dist/instruments.d.mts +63 -0
- package/dist/instruments.mjs +137 -0
- package/dist/model-signals-BpeXhsim.d.mts +25 -0
- package/dist/model-signals-DLgvjBeZ.mjs +172 -0
- package/dist/navigation.d.mts +25 -2
- package/dist/navigation.mjs +231 -43
- package/dist/{renderer-DPT7XAYh.d.mts → renderer-CtEtmwJG.d.mts} +75 -2
- package/dist/text.d.mts +24 -0
- package/dist/text.mjs +62 -0
- package/dist/{vehicle-interior-0o-8QV_-.d.mts → vehicle-interior-BgcC750p.d.mts} +2 -2
- package/dist/{vehicle-interior-DZT0HmWC.mjs → vehicle-interior-DfpZwWEh.mjs} +4 -1
- package/dist/vehicles.d.mts +20 -4
- package/dist/vehicles.mjs +43 -10
- package/dist/webgpu-ambient-occlusion-9gnp3qOY.mjs +126 -0
- package/dist/{webgpu-driver-Bt2mvZk9.mjs → webgpu-driver-BQnmPRqs.mjs} +41 -1
- package/dist/{webgpu-scene-optimizer-DKRyHBRC.mjs → webgpu-scene-optimizer-Cup4Yvzs.mjs} +9 -2
- package/package.json +12 -4
- package/dist/model-signals-DVlLyP-w.d.mts +0 -17
- package/dist/model-signals-Gw1COJfo.mjs +0 -53
package/dist/navigation.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as InputMap } from "./input-
|
|
1
|
+
import { t as InputMap } from "./input-BVZjf4T-.mjs";
|
|
2
2
|
import * as THREE from "three";
|
|
3
3
|
import { Octree } from "three/addons/math/Octree.js";
|
|
4
4
|
import { Capsule } from "three/addons/math/Capsule.js";
|
|
@@ -63,49 +63,119 @@ const LEAF_SIZE = 16;
|
|
|
63
63
|
* Rendered roads, walls and portal covers can overlap. An octree copies each triangle into
|
|
64
64
|
* every intersecting cell and repeatedly splits those copies, causing long rebuild stalls.
|
|
65
65
|
* A balanced bounding-volume tree stores each triangle once, even for coincident surfaces.
|
|
66
|
+
*
|
|
67
|
+
* Triangle bounds and centers live in flat arrays and each split selects its median instead of
|
|
68
|
+
* sorting: an aircraft's neighborhood over dense ground cover held 170k triangles, and sorting
|
|
69
|
+
* them at every level of the tree took 700 ms of one frame.
|
|
66
70
|
*/
|
|
67
71
|
var CollisionTree = class extends Octree {
|
|
68
72
|
build() {
|
|
69
73
|
this.calcBox();
|
|
70
74
|
this.subTrees = [];
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
]);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
75
|
+
const triangles = this.triangles;
|
|
76
|
+
if (triangles.length > 0) {
|
|
77
|
+
const bounds = new Float64Array(triangles.length * 6);
|
|
78
|
+
const centers = new Float64Array(triangles.length * 3);
|
|
79
|
+
triangles.forEach(({ a, b, c }, index) => {
|
|
80
|
+
const box = index * 6;
|
|
81
|
+
bounds[box] = Math.min(a.x, b.x, c.x);
|
|
82
|
+
bounds[box + 1] = Math.min(a.y, b.y, c.y);
|
|
83
|
+
bounds[box + 2] = Math.min(a.z, b.z, c.z);
|
|
84
|
+
bounds[box + 3] = Math.max(a.x, b.x, c.x);
|
|
85
|
+
bounds[box + 4] = Math.max(a.y, b.y, c.y);
|
|
86
|
+
bounds[box + 5] = Math.max(a.z, b.z, c.z);
|
|
87
|
+
for (let axis = 0; axis < 3; axis++) centers[index * 3 + axis] = (bounds[box + axis] + bounds[box + 3 + axis]) / 2;
|
|
83
88
|
});
|
|
84
|
-
|
|
89
|
+
const order = new Uint32Array(triangles.length);
|
|
90
|
+
for (let index = 0; index < order.length; index++) order[index] = index;
|
|
91
|
+
this.subTrees.push(partition({
|
|
92
|
+
triangles,
|
|
93
|
+
bounds,
|
|
94
|
+
centers,
|
|
95
|
+
order
|
|
96
|
+
}, 0, triangles.length));
|
|
85
97
|
}
|
|
86
98
|
this.triangles = [];
|
|
87
99
|
return this;
|
|
88
100
|
}
|
|
89
101
|
};
|
|
90
|
-
function partition(entries) {
|
|
91
|
-
const bounds =
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
function partition(entries, start, end) {
|
|
103
|
+
const { bounds, centers, order } = entries;
|
|
104
|
+
const box = new THREE.Box3();
|
|
105
|
+
const low = [
|
|
106
|
+
Infinity,
|
|
107
|
+
Infinity,
|
|
108
|
+
Infinity
|
|
109
|
+
];
|
|
110
|
+
const high = [
|
|
111
|
+
-Infinity,
|
|
112
|
+
-Infinity,
|
|
113
|
+
-Infinity
|
|
114
|
+
];
|
|
115
|
+
for (let k = start; k < end; k++) {
|
|
116
|
+
const index = order[k];
|
|
117
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
118
|
+
const center = centers[index * 3 + axis];
|
|
119
|
+
if (center < low[axis]) low[axis] = center;
|
|
120
|
+
if (center > high[axis]) high[axis] = center;
|
|
121
|
+
}
|
|
122
|
+
box.min.x = Math.min(box.min.x, bounds[index * 6]);
|
|
123
|
+
box.min.y = Math.min(box.min.y, bounds[index * 6 + 1]);
|
|
124
|
+
box.min.z = Math.min(box.min.z, bounds[index * 6 + 2]);
|
|
125
|
+
box.max.x = Math.max(box.max.x, bounds[index * 6 + 3]);
|
|
126
|
+
box.max.y = Math.max(box.max.y, bounds[index * 6 + 4]);
|
|
127
|
+
box.max.z = Math.max(box.max.z, bounds[index * 6 + 5]);
|
|
96
128
|
}
|
|
97
|
-
const node = new Octree(
|
|
98
|
-
if (
|
|
99
|
-
node.triangles =
|
|
129
|
+
const node = new Octree(box);
|
|
130
|
+
if (end - start <= LEAF_SIZE) {
|
|
131
|
+
node.triangles = Array.from(order.subarray(start, end)).sort((p, q) => p - q).map((index) => entries.triangles[index]);
|
|
100
132
|
return node;
|
|
101
133
|
}
|
|
102
|
-
const
|
|
103
|
-
const axis =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
node.subTrees.push(partition(entries
|
|
134
|
+
const [sx, sy, sz] = high.map((value, axis) => value - low[axis]);
|
|
135
|
+
const axis = sx >= sy && sx >= sz ? 0 : sy >= sz ? 1 : 2;
|
|
136
|
+
const middle = start + Math.floor((end - start) / 2);
|
|
137
|
+
selectMedian(entries, axis, start, end - 1, middle);
|
|
138
|
+
node.subTrees.push(partition(entries, start, middle), partition(entries, middle, end));
|
|
107
139
|
return node;
|
|
108
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Reorder `order[left..right]` so position `k` holds the entry a full sort by center along `axis`
|
|
143
|
+
* would put there, with smaller entries before it and larger after. Equal centers order by
|
|
144
|
+
* triangle index, so the two halves never depend on how earlier splits arranged the range.
|
|
145
|
+
*/
|
|
146
|
+
function selectMedian({ centers, order }, axis, left, right, k) {
|
|
147
|
+
const before = (p, q) => {
|
|
148
|
+
const cp = centers[p * 3 + axis];
|
|
149
|
+
const cq = centers[q * 3 + axis];
|
|
150
|
+
return cp < cq || cp === cq && p < q;
|
|
151
|
+
};
|
|
152
|
+
const swap = (i, j) => {
|
|
153
|
+
const held = order[i];
|
|
154
|
+
order[i] = order[j];
|
|
155
|
+
order[j] = held;
|
|
156
|
+
};
|
|
157
|
+
while (right > left) {
|
|
158
|
+
const mid = left + (right - left >> 1);
|
|
159
|
+
if (before(order[mid], order[left])) swap(mid, left);
|
|
160
|
+
if (before(order[right], order[left])) swap(right, left);
|
|
161
|
+
if (before(order[right], order[mid])) swap(right, mid);
|
|
162
|
+
const pivot = order[mid];
|
|
163
|
+
let i = left;
|
|
164
|
+
let j = right;
|
|
165
|
+
while (i <= j) {
|
|
166
|
+
while (before(order[i], pivot)) i++;
|
|
167
|
+
while (before(pivot, order[j])) j--;
|
|
168
|
+
if (i <= j) {
|
|
169
|
+
swap(i, j);
|
|
170
|
+
i++;
|
|
171
|
+
j--;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (k <= j) right = j;
|
|
175
|
+
else if (k >= i) left = i;
|
|
176
|
+
else return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
109
179
|
//#endregion
|
|
110
180
|
//#region src/navigation/fly.ts
|
|
111
181
|
var FlyController = class {
|
|
@@ -262,6 +332,7 @@ var NavigationPointer = class {
|
|
|
262
332
|
this.listen("pointermove", (event) => this.move(event));
|
|
263
333
|
this.listen("pointerup", (event) => this.up(event, true));
|
|
264
334
|
this.listen("pointercancel", (event) => this.up(event, false));
|
|
335
|
+
this.listen("lostpointercapture", (event) => this.up(event, false));
|
|
265
336
|
this.listen("wheel", (event) => this.wheel(event), { passive: false });
|
|
266
337
|
this.listen("contextmenu", (event) => event.preventDefault?.());
|
|
267
338
|
}
|
|
@@ -279,7 +350,9 @@ var NavigationPointer = class {
|
|
|
279
350
|
}
|
|
280
351
|
/** Forget held pointers and pending gestures (e.g. on blur or a mode change). */
|
|
281
352
|
reset() {
|
|
353
|
+
const captured = [...this.pointers.keys()];
|
|
282
354
|
this.pointers.clear();
|
|
355
|
+
for (const id of captured) if (this.surface.hasPointerCapture?.(id) === true) this.surface.releasePointerCapture?.(id);
|
|
283
356
|
this.pending = emptyGestures();
|
|
284
357
|
}
|
|
285
358
|
dispose() {
|
|
@@ -309,13 +382,16 @@ var NavigationPointer = class {
|
|
|
309
382
|
startX: event.clientX,
|
|
310
383
|
startY: event.clientY,
|
|
311
384
|
startTime: this.now(),
|
|
312
|
-
moved:
|
|
385
|
+
moved: button !== 0 || event.shiftKey === true || this.pointers.size > 0,
|
|
313
386
|
pan: button === 1 || button === 2 || event.shiftKey === true
|
|
314
387
|
});
|
|
388
|
+
if (this.pointers.size > 1) for (const pointer of this.pointers.values()) pointer.moved = true;
|
|
315
389
|
this.surface.setPointerCapture?.(event.pointerId);
|
|
316
390
|
}
|
|
317
391
|
move(event) {
|
|
318
392
|
if (this.locked() && this.pointers.size <= 1) {
|
|
393
|
+
const pointer = this.pointers.get(event.pointerId);
|
|
394
|
+
if (pointer !== void 0 && (event.movementX || event.movementY)) pointer.moved = true;
|
|
319
395
|
this.pending.look[0] += event.movementX ?? 0;
|
|
320
396
|
this.pending.look[1] += event.movementY ?? 0;
|
|
321
397
|
return;
|
|
@@ -409,6 +485,7 @@ const NAVIGATION_ACTIONS = {
|
|
|
409
485
|
engine: "nav-engine",
|
|
410
486
|
gear: "nav-gear",
|
|
411
487
|
flaps: "nav-flaps",
|
|
488
|
+
vector: "nav-vector",
|
|
412
489
|
recover: "nav-recover"
|
|
413
490
|
};
|
|
414
491
|
const A = NAVIGATION_ACTIONS;
|
|
@@ -468,8 +545,8 @@ const STICKS = [
|
|
|
468
545
|
];
|
|
469
546
|
/**
|
|
470
547
|
* Default key/gamepad bindings per navigation mode. Orbit and fly use Q/E for down/up; walk and
|
|
471
|
-
* drive use E to interact (board or leave a vehicle), Space to jump or brake,
|
|
472
|
-
* the vehicle view. Pilot flies an aircraft: W/S (or ↑/↓) pitch the nose down/up, A/D (or ←/→)
|
|
548
|
+
* drive use E to interact (board or leave a vehicle), Space to jump or brake, Shift to sprint
|
|
549
|
+
* 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 ←/→)
|
|
473
550
|
* bank, Q/Z work the rudder or pedals, Shift/Ctrl (or +/−, Page Up/Down) set throttle or
|
|
474
551
|
* collective, I toggles the engine, G the gear, F the flaps, R recovers after an impact, Space
|
|
475
552
|
* brakes, V switches the view and E leaves. Hosts may replace any profile through
|
|
@@ -561,6 +638,7 @@ function navigationInputProfiles() {
|
|
|
561
638
|
KeyI: A.engine,
|
|
562
639
|
KeyG: A.gear,
|
|
563
640
|
KeyF: A.flaps,
|
|
641
|
+
KeyJ: A.vector,
|
|
564
642
|
KeyR: A.recover
|
|
565
643
|
},
|
|
566
644
|
axes: STICKS,
|
|
@@ -634,6 +712,7 @@ var NavigationInputSource = class {
|
|
|
634
712
|
engine: 0,
|
|
635
713
|
gear: 0,
|
|
636
714
|
flaps: 0,
|
|
715
|
+
vector: 0,
|
|
637
716
|
recover: 0
|
|
638
717
|
};
|
|
639
718
|
lookSpeed;
|
|
@@ -655,6 +734,7 @@ var NavigationInputSource = class {
|
|
|
655
734
|
"engine",
|
|
656
735
|
"gear",
|
|
657
736
|
"flaps",
|
|
737
|
+
"vector",
|
|
658
738
|
"recover"
|
|
659
739
|
].map((name) => this.map.onPress(A[name], () => {
|
|
660
740
|
this.pilotPresses[name]++;
|
|
@@ -665,8 +745,28 @@ var NavigationInputSource = class {
|
|
|
665
745
|
this.map.onPress(A.view, () => {
|
|
666
746
|
this.viewPresses++;
|
|
667
747
|
}),
|
|
668
|
-
this.map.onReset(() =>
|
|
748
|
+
this.map.onReset(() => {
|
|
749
|
+
this.pointer.reset();
|
|
750
|
+
this.interactPresses = 0;
|
|
751
|
+
this.viewPresses = 0;
|
|
752
|
+
this.pilotPresses.engine = 0;
|
|
753
|
+
this.pilotPresses.gear = 0;
|
|
754
|
+
this.pilotPresses.flaps = 0;
|
|
755
|
+
this.pilotPresses.vector = 0;
|
|
756
|
+
this.pilotPresses.recover = 0;
|
|
757
|
+
})
|
|
669
758
|
];
|
|
759
|
+
this.pointer.setPointerLock(this.profile === "walk");
|
|
760
|
+
const document = options.element.ownerDocument;
|
|
761
|
+
const reset = () => this.map.reset();
|
|
762
|
+
document?.defaultView?.addEventListener("blur", reset);
|
|
763
|
+
document?.addEventListener?.("visibilitychange", reset);
|
|
764
|
+
document?.addEventListener?.("pointerlockchange", reset);
|
|
765
|
+
this.unsubscribe.push(() => {
|
|
766
|
+
document?.defaultView?.removeEventListener("blur", reset);
|
|
767
|
+
document?.removeEventListener?.("visibilitychange", reset);
|
|
768
|
+
document?.removeEventListener?.("pointerlockchange", reset);
|
|
769
|
+
});
|
|
670
770
|
}
|
|
671
771
|
setProfile(profile) {
|
|
672
772
|
this.profile = profile;
|
|
@@ -706,6 +806,7 @@ var NavigationInputSource = class {
|
|
|
706
806
|
this.pilotPresses.engine = 0;
|
|
707
807
|
this.pilotPresses.gear = 0;
|
|
708
808
|
this.pilotPresses.flaps = 0;
|
|
809
|
+
this.pilotPresses.vector = 0;
|
|
709
810
|
this.pilotPresses.recover = 0;
|
|
710
811
|
return input;
|
|
711
812
|
}
|
|
@@ -1024,6 +1125,14 @@ function createTouchJoystick(container, input, options = {}) {
|
|
|
1024
1125
|
root.append(knob);
|
|
1025
1126
|
container.append(root);
|
|
1026
1127
|
let pointer;
|
|
1128
|
+
const reset = () => {
|
|
1129
|
+
const captured = pointer;
|
|
1130
|
+
pointer = void 0;
|
|
1131
|
+
if (captured !== void 0 && root.hasPointerCapture(captured)) root.releasePointerCapture(captured);
|
|
1132
|
+
stick.release();
|
|
1133
|
+
input.clearVirtual(source);
|
|
1134
|
+
knob.style.transform = "";
|
|
1135
|
+
};
|
|
1027
1136
|
const publish = () => {
|
|
1028
1137
|
const { forward, right } = stick.axes();
|
|
1029
1138
|
input.setVirtual(source, ACTIONS.forward, Math.max(0, forward));
|
|
@@ -1044,6 +1153,7 @@ function createTouchJoystick(container, input, options = {}) {
|
|
|
1044
1153
|
if (pointer !== void 0) return;
|
|
1045
1154
|
event.preventDefault();
|
|
1046
1155
|
event.stopPropagation();
|
|
1156
|
+
options.focusTarget?.focus({ preventScroll: true });
|
|
1047
1157
|
pointer = event.pointerId;
|
|
1048
1158
|
root.setPointerCapture(event.pointerId);
|
|
1049
1159
|
const { x, y } = center();
|
|
@@ -1060,32 +1170,29 @@ function createTouchJoystick(container, input, options = {}) {
|
|
|
1060
1170
|
const onUp = (event) => {
|
|
1061
1171
|
if (event.pointerId !== pointer) return;
|
|
1062
1172
|
event.stopPropagation();
|
|
1063
|
-
|
|
1064
|
-
stick.release();
|
|
1065
|
-
input.clearVirtual(source);
|
|
1066
|
-
knob.style.transform = "";
|
|
1173
|
+
reset();
|
|
1067
1174
|
};
|
|
1068
1175
|
root.addEventListener("pointerdown", onDown);
|
|
1069
1176
|
root.addEventListener("pointermove", onMove);
|
|
1070
1177
|
root.addEventListener("pointerup", onUp);
|
|
1071
1178
|
root.addEventListener("pointercancel", onUp);
|
|
1179
|
+
root.addEventListener("lostpointercapture", onUp);
|
|
1180
|
+
document.defaultView?.addEventListener("blur", reset);
|
|
1072
1181
|
return {
|
|
1073
1182
|
element: root,
|
|
1074
1183
|
stick,
|
|
1075
1184
|
setVisible(visible) {
|
|
1076
1185
|
root.style.display = visible ? "" : "none";
|
|
1077
|
-
if (!visible)
|
|
1078
|
-
pointer = void 0;
|
|
1079
|
-
stick.release();
|
|
1080
|
-
input.clearVirtual(source);
|
|
1081
|
-
}
|
|
1186
|
+
if (!visible) reset();
|
|
1082
1187
|
},
|
|
1083
1188
|
dispose() {
|
|
1084
1189
|
root.removeEventListener("pointerdown", onDown);
|
|
1085
1190
|
root.removeEventListener("pointermove", onMove);
|
|
1086
1191
|
root.removeEventListener("pointerup", onUp);
|
|
1087
1192
|
root.removeEventListener("pointercancel", onUp);
|
|
1088
|
-
|
|
1193
|
+
root.removeEventListener("lostpointercapture", onUp);
|
|
1194
|
+
document.defaultView?.removeEventListener("blur", reset);
|
|
1195
|
+
reset();
|
|
1089
1196
|
root.remove();
|
|
1090
1197
|
}
|
|
1091
1198
|
};
|
|
@@ -1240,6 +1347,7 @@ var WalkCollision = class {
|
|
|
1240
1347
|
verticalRadius;
|
|
1241
1348
|
rescanIntervalMs;
|
|
1242
1349
|
now;
|
|
1350
|
+
instanceBounds;
|
|
1243
1351
|
meshes = [];
|
|
1244
1352
|
initialized = false;
|
|
1245
1353
|
/** Vertical center of the current neighborhood, or undefined when it spans the whole column. */
|
|
@@ -1255,6 +1363,7 @@ var WalkCollision = class {
|
|
|
1255
1363
|
this.verticalRadius = resolved.verticalRadius === void 0 ? void 0 : requireFinite(resolved.verticalRadius, "verticalRadius", false);
|
|
1256
1364
|
this.rescanIntervalMs = requireFinite(resolved.rescanIntervalMs ?? 0, "rescanIntervalMs", true);
|
|
1257
1365
|
this.now = resolved.now ?? (() => performance.now());
|
|
1366
|
+
this.instanceBounds = resolved.instanceBounds ?? false;
|
|
1258
1367
|
}
|
|
1259
1368
|
/**
|
|
1260
1369
|
* Track the subject at (x, z). With a `verticalRadius`, `y` bounds the neighborhood vertically.
|
|
@@ -1356,7 +1465,8 @@ var WalkCollision = class {
|
|
|
1356
1465
|
const start = geometry.drawRange.start;
|
|
1357
1466
|
const end = Math.min(index?.count ?? position.count, start + geometry.drawRange.count);
|
|
1358
1467
|
const doubleSided = mesh.userData.walkDoubleSided === true;
|
|
1359
|
-
const
|
|
1468
|
+
const boxes = this.instanceBounds && mesh instanceof THREE.InstancedMesh;
|
|
1469
|
+
const spatial = boxes ? void 0 : triangleIndexFor(geometry);
|
|
1360
1470
|
const visit = (vertex) => {
|
|
1361
1471
|
if (vertex < start || vertex + 2 >= end) return;
|
|
1362
1472
|
a.fromBufferAttribute(position, index?.getX(vertex) ?? vertex).applyMatrix4(transform);
|
|
@@ -1374,6 +1484,10 @@ var WalkCollision = class {
|
|
|
1374
1484
|
} else transform.copy(local);
|
|
1375
1485
|
bounds.copy(geometry.boundingBox).applyMatrix4(transform);
|
|
1376
1486
|
if (!inside()) continue;
|
|
1487
|
+
if (boxes) {
|
|
1488
|
+
addBox(this.octree, geometry.boundingBox, transform);
|
|
1489
|
+
continue;
|
|
1490
|
+
}
|
|
1377
1491
|
if (spatial === void 0) {
|
|
1378
1492
|
for (let vertex = start; vertex + 2 < end; vertex += 3) visit(vertex);
|
|
1379
1493
|
continue;
|
|
@@ -1387,6 +1501,80 @@ var WalkCollision = class {
|
|
|
1387
1501
|
this.octree.build();
|
|
1388
1502
|
}
|
|
1389
1503
|
};
|
|
1504
|
+
const BOX_FACES = [
|
|
1505
|
+
[
|
|
1506
|
+
0,
|
|
1507
|
+
2,
|
|
1508
|
+
6,
|
|
1509
|
+
4
|
|
1510
|
+
],
|
|
1511
|
+
[
|
|
1512
|
+
1,
|
|
1513
|
+
5,
|
|
1514
|
+
7,
|
|
1515
|
+
3
|
|
1516
|
+
],
|
|
1517
|
+
[
|
|
1518
|
+
0,
|
|
1519
|
+
4,
|
|
1520
|
+
5,
|
|
1521
|
+
1
|
|
1522
|
+
],
|
|
1523
|
+
[
|
|
1524
|
+
2,
|
|
1525
|
+
3,
|
|
1526
|
+
7,
|
|
1527
|
+
6
|
|
1528
|
+
],
|
|
1529
|
+
[
|
|
1530
|
+
0,
|
|
1531
|
+
1,
|
|
1532
|
+
3,
|
|
1533
|
+
2
|
|
1534
|
+
],
|
|
1535
|
+
[
|
|
1536
|
+
4,
|
|
1537
|
+
6,
|
|
1538
|
+
7,
|
|
1539
|
+
5
|
|
1540
|
+
]
|
|
1541
|
+
];
|
|
1542
|
+
const corners = Array.from({ length: 8 }, () => new THREE.Vector3());
|
|
1543
|
+
const boxCenter = new THREE.Vector3();
|
|
1544
|
+
const faceCenter = new THREE.Vector3();
|
|
1545
|
+
const edge = new THREE.Vector3();
|
|
1546
|
+
const across = new THREE.Vector3();
|
|
1547
|
+
/**
|
|
1548
|
+
* Add `box`, placed by `transform`, as twelve outward-facing triangles: rays test front faces only.
|
|
1549
|
+
* A box collapsed to a point (a hidden instance) adds nothing.
|
|
1550
|
+
*/
|
|
1551
|
+
function addBox(tree, box, transform) {
|
|
1552
|
+
corners.forEach((corner, index) => {
|
|
1553
|
+
corner.set(index & 1 ? box.max.x : box.min.x, index & 2 ? box.max.y : box.min.y, index & 4 ? box.max.z : box.min.z).applyMatrix4(transform);
|
|
1554
|
+
});
|
|
1555
|
+
const [first] = corners;
|
|
1556
|
+
if (corners.every((corner) => corner.equals(first))) return;
|
|
1557
|
+
boxCenter.set(0, 0, 0);
|
|
1558
|
+
for (const corner of corners) boxCenter.add(corner);
|
|
1559
|
+
boxCenter.multiplyScalar(1 / 8);
|
|
1560
|
+
for (const face of BOX_FACES) {
|
|
1561
|
+
const [a, b, c, d] = face.map((index) => corners[index]);
|
|
1562
|
+
faceCenter.copy(a).add(b).add(c).add(d).multiplyScalar(.25).sub(boxCenter);
|
|
1563
|
+
const [p, q, r, t] = edge.subVectors(b, a).cross(across.subVectors(c, a)).dot(faceCenter) >= 0 ? [
|
|
1564
|
+
a,
|
|
1565
|
+
b,
|
|
1566
|
+
c,
|
|
1567
|
+
d
|
|
1568
|
+
] : [
|
|
1569
|
+
a,
|
|
1570
|
+
d,
|
|
1571
|
+
c,
|
|
1572
|
+
b
|
|
1573
|
+
];
|
|
1574
|
+
tree.addTriangle(new THREE.Triangle(p.clone(), q.clone(), r.clone()));
|
|
1575
|
+
tree.addTriangle(new THREE.Triangle(p.clone(), r.clone(), t.clone()));
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1390
1578
|
//#endregion
|
|
1391
1579
|
//#region src/navigation/walk-controller.ts
|
|
1392
1580
|
const WALK_EYE_HEIGHT = 1.7;
|
|
@@ -50,8 +50,14 @@ declare class FrameAdmissionQueue implements SceneAdmission {
|
|
|
50
50
|
* the task and everything it captured. Only a queued job may stay reachable from its promise.
|
|
51
51
|
*/
|
|
52
52
|
private forget;
|
|
53
|
-
/**
|
|
54
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Move a still-queued background job to the normal lane, behind the jobs already there, or with
|
|
55
|
+
* `front` ahead of them: for work a frame is waiting on, such as a material an object holds off
|
|
56
|
+
* switching to until it is prepared.
|
|
57
|
+
*/
|
|
58
|
+
promote(promise: Promise<unknown>, options?: {
|
|
59
|
+
front?: boolean;
|
|
60
|
+
}): void;
|
|
55
61
|
get pending(): number;
|
|
56
62
|
private request;
|
|
57
63
|
/** One frame's budget. Exposed for hosts with a manual frame loop and deterministic tests. */
|
|
@@ -285,6 +291,19 @@ interface ShadowFocus {
|
|
|
285
291
|
radius: number;
|
|
286
292
|
}
|
|
287
293
|
//#endregion
|
|
294
|
+
//#region src/three/webgpu-ambient-occlusion.d.ts
|
|
295
|
+
interface AmbientOcclusionOptions {
|
|
296
|
+
/** World-space sampling radius, meters: about a wall-to-ground crease. */
|
|
297
|
+
radius?: number;
|
|
298
|
+
/** Share of the occlusion applied, 0–1. Sunlit faces keep most of their direct light. */
|
|
299
|
+
strength?: number;
|
|
300
|
+
/**
|
|
301
|
+
* View distance, meters, past which no occlusion is computed; it fades out over the last
|
|
302
|
+
* third. Farther creases are under a pixel, and skipping them is most of an aerial view.
|
|
303
|
+
*/
|
|
304
|
+
reach?: number;
|
|
305
|
+
}
|
|
306
|
+
//#endregion
|
|
288
307
|
//#region src/three/webgpu-scene-optimizer.d.ts
|
|
289
308
|
/**
|
|
290
309
|
* Uses Three render bundles and a pinned, version-aware instance upload adapter.
|
|
@@ -306,6 +325,8 @@ declare class WebGpuSceneOptimizer {
|
|
|
306
325
|
private readonly matrixSamples;
|
|
307
326
|
private readonly restoreRefresh;
|
|
308
327
|
private materialSamples;
|
|
328
|
+
/** The render each material last refreshed a replayed object in; see the constructor. */
|
|
329
|
+
private readonly refreshed;
|
|
309
330
|
private readonly videoMaterials;
|
|
310
331
|
private readonly materialStates;
|
|
311
332
|
constructor(renderer: WebGPURenderer);
|
|
@@ -427,6 +448,12 @@ declare class Renderer {
|
|
|
427
448
|
private warmupMaterial;
|
|
428
449
|
private readonly warmedPrograms;
|
|
429
450
|
private readonly warmedMeshes;
|
|
451
|
+
/**
|
|
452
|
+
* Per mesh, builds of the materials it swaps to itself (`null`: prepared with the mesh); see
|
|
453
|
+
* `prepareVariants`.
|
|
454
|
+
*/
|
|
455
|
+
private readonly warmedVariants;
|
|
456
|
+
private readonly variantInterests;
|
|
430
457
|
private readonly warmups;
|
|
431
458
|
/** Deferred meshes whose preparation has not settled, with the interest that can promote it. */
|
|
432
459
|
private readonly deferredMeshes;
|
|
@@ -461,6 +488,10 @@ declare class Renderer {
|
|
|
461
488
|
private readonly optimizer;
|
|
462
489
|
private activeSky;
|
|
463
490
|
private readonly reflections;
|
|
491
|
+
private occlusionOptions;
|
|
492
|
+
private occlusion;
|
|
493
|
+
private occlusionLoad;
|
|
494
|
+
private occlusionSuspended;
|
|
464
495
|
/** Sun lights whose WebGPU shadow map exists and must not be torn down; see setShadowQuality. */
|
|
465
496
|
private readonly webgpuShadowLights;
|
|
466
497
|
private readonly reflectionClearColor;
|
|
@@ -468,6 +499,8 @@ declare class Renderer {
|
|
|
468
499
|
private activeWeather;
|
|
469
500
|
private weatherTimeOverride;
|
|
470
501
|
private readonly weatherLightIntensities;
|
|
502
|
+
/** The hemisphere the sky reflection map stands in for, and its authored visibility. */
|
|
503
|
+
private hiddenAmbient;
|
|
471
504
|
private environmentSeconds;
|
|
472
505
|
private environmentTimeOverride;
|
|
473
506
|
private readonly lastRenderStats;
|
|
@@ -546,6 +579,18 @@ declare class Renderer {
|
|
|
546
579
|
prepareObject(root: THREE.Object3D, signal?: AbortSignal, parent?: THREE.Object3D): Promise<void>;
|
|
547
580
|
private prepareMesh;
|
|
548
581
|
private flushWebGlBatches;
|
|
582
|
+
/**
|
|
583
|
+
* A mesh that swaps its own material, as an instanced detail switch swaps in an opaque twin for
|
|
584
|
+
* its coarser levels, lists every material in `userData.materialVariants`. Each needs its own
|
|
585
|
+
* shader build, which the first frame to draw it would otherwise make mid-frame: in flight a whole
|
|
586
|
+
* view of trees changed level at once and built their twins in one frame, for most of a second.
|
|
587
|
+
* `userData.materialReady(material)` tells the mesh's owner whether one is ready. Until it is, the
|
|
588
|
+
* owner keeps what it shows; asking queues its build ahead of other work. Most batches never
|
|
589
|
+
* change level, so a variant is built only once its mesh asks for it.
|
|
590
|
+
*/
|
|
591
|
+
private prepareVariants;
|
|
592
|
+
/** Whether `mesh` can draw `material` without building it mid-frame; builds it first if not. */
|
|
593
|
+
private variantReady;
|
|
549
594
|
/** Queue one cancellable warm-up job in the lane's admission priority. */
|
|
550
595
|
private warmup;
|
|
551
596
|
/**
|
|
@@ -562,10 +607,38 @@ declare class Renderer {
|
|
|
562
607
|
/** Nobody waits any longer: drop the job from every cache first, then from the queue. */
|
|
563
608
|
private cancelWarmup;
|
|
564
609
|
private rememberPreparation;
|
|
610
|
+
/** Build `mesh` for the frame's draw target, drawn with `material` when given. */
|
|
565
611
|
private compileMesh;
|
|
566
612
|
private prepareWebGlGeometries;
|
|
567
613
|
render(): void;
|
|
614
|
+
/**
|
|
615
|
+
* The PMREM supplies both diffuse sky irradiance and specular reflection, so while it is the
|
|
616
|
+
* scene environment the hemisphere it was sampled from must not light surfaces as well. The
|
|
617
|
+
* light is hidden, between frames too, rather than dimmed for the visible draw alone: three's
|
|
618
|
+
* WebGPU renderer updates light uniforms once per frame of its own clock, and warm-up compiles
|
|
619
|
+
* finish between viewer frames, so a light restored after each draw could leave its full
|
|
620
|
+
* intensity in the next frame's uniforms and the whole scene flashed bright for that frame.
|
|
621
|
+
* Its intensity stays the authored value for weather and hosts; it shows again when a host
|
|
622
|
+
* environment takes over or the renderer is disposed.
|
|
623
|
+
*/
|
|
624
|
+
private hideReflectedAmbient;
|
|
568
625
|
private renderScene;
|
|
626
|
+
private optimized;
|
|
627
|
+
/**
|
|
628
|
+
* Screen-space ambient occlusion on the WebGPU backend (a no-op on WebGL): creases, corners and
|
|
629
|
+
* the ground around buildings and trees darken a little, as indirect light cannot reach them.
|
|
630
|
+
* The frame then renders through a node pipeline; frames draw directly while it compiles.
|
|
631
|
+
*/
|
|
632
|
+
setAmbientOcclusion(enabled: boolean, options?: AmbientOcclusionOptions): void;
|
|
633
|
+
/**
|
|
634
|
+
* Skip the occlusion computation while keeping ambient occlusion set up: the frame still draws
|
|
635
|
+
* into its target, and the image is copied out unshaded. Each object's shaders are built for
|
|
636
|
+
* one draw target, so turning occlusion off and on again (`setAmbientOcclusion`) built every
|
|
637
|
+
* object in view again, mid-frame, when the target changed; suspending changes nothing there.
|
|
638
|
+
*/
|
|
639
|
+
suspendAmbientOcclusion(suspended: boolean): void;
|
|
640
|
+
/** The occlusion pass for the current camera, building one in the background when needed. */
|
|
641
|
+
private currentOcclusion;
|
|
569
642
|
/** Use for independent terrain/content chunks. WebGPU caches eligible opaque draw commands. */
|
|
570
643
|
createRenderGroup(): THREE.Group;
|
|
571
644
|
/** Last completed visible frame, excluding offscreen resource preparation. */
|
package/dist/text.d.mts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { FontLibrary, FontLibrary as FontLibrary$1, TextLayoutOptions, TextLayoutOptions as TextLayoutOptions$1, TextMeshData, VectorFont, VectorFont as VectorFont$1, VectorGlyph, buildTextMesh, loadFontLibrary, vectorFontSchema } from "@bendyline/molen-materials/text";
|
|
3
|
+
import { FontData } from "three/addons/loaders/FontLoader.js";
|
|
4
|
+
|
|
5
|
+
//#region src/text.d.ts
|
|
6
|
+
interface CompileVectorFontOptions {
|
|
7
|
+
id: string;
|
|
8
|
+
/** Explicit subset, including ? and space. Default: every character in the typeface. */
|
|
9
|
+
characters?: string;
|
|
10
|
+
weight?: number;
|
|
11
|
+
style?: "normal" | "italic";
|
|
12
|
+
/** Segments per outline curve, 2–32; default 6 for medium-fi signage. */
|
|
13
|
+
curveSegments?: number;
|
|
14
|
+
/** Optional pair adjustments in em units from the source font's kerning tables. */
|
|
15
|
+
kerning?: Record<string, number>;
|
|
16
|
+
}
|
|
17
|
+
/** Compile typeface JSON (including TTFLoader output) once, then store the result in a pack.
|
|
18
|
+
* Node and browser compatible; no canvas or OS font dependency. Does not fetch a font.
|
|
19
|
+
*/
|
|
20
|
+
declare function compileVectorFont(data: FontData, options: CompileVectorFontOptions): VectorFont$1;
|
|
21
|
+
/** Caller owns/disposes the geometry and chooses its material, color, transform and batching. */
|
|
22
|
+
declare function createTextGeometry(text: string, fonts: FontLibrary$1, options?: TextLayoutOptions$1): THREE.BufferGeometry;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { CompileVectorFontOptions, type FontLibrary, type TextLayoutOptions, type TextMeshData, type VectorFont, type VectorGlyph, buildTextMesh, compileVectorFont, createTextGeometry, loadFontLibrary, vectorFontSchema };
|
package/dist/text.mjs
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { buildTextMesh, buildTextMesh as buildTextMesh$1, loadFontLibrary, vectorFontSchema, vectorFontSchema as vectorFontSchema$1 } from "@bendyline/molen-materials/text";
|
|
3
|
+
import { Font } from "three/addons/loaders/FontLoader.js";
|
|
4
|
+
//#region src/text.ts
|
|
5
|
+
/** Three.js adapter and offline outline compiler for the shared font engine. */
|
|
6
|
+
/** Compile typeface JSON (including TTFLoader output) once, then store the result in a pack.
|
|
7
|
+
* Node and browser compatible; no canvas or OS font dependency. Does not fetch a font.
|
|
8
|
+
*/
|
|
9
|
+
function compileVectorFont(data, options) {
|
|
10
|
+
const segments = options.curveSegments ?? 6;
|
|
11
|
+
if (!Number.isInteger(segments) || segments < 2 || segments > 32) throw new Error("curveSegments must be 2–32");
|
|
12
|
+
const font = new Font(data);
|
|
13
|
+
const glyphs = {};
|
|
14
|
+
const round = (value) => Math.round(value * 1e6) / 1e6;
|
|
15
|
+
for (const char of new Set(Array.from(options.characters ?? Object.keys(data.glyphs).join("")))) {
|
|
16
|
+
const glyph = data.glyphs[char];
|
|
17
|
+
if (!glyph) continue;
|
|
18
|
+
const geometry = new THREE.ShapeGeometry(font.generateShapes(char, 1), segments);
|
|
19
|
+
const position = geometry.getAttribute("position");
|
|
20
|
+
const points = [];
|
|
21
|
+
for (let i = 0; i < position.count; i++) points.push(round(position.getX(i)), round(position.getY(i)));
|
|
22
|
+
glyphs[char] = {
|
|
23
|
+
advance: round(glyph.ha / data.resolution),
|
|
24
|
+
positions: points,
|
|
25
|
+
indices: Array.from(geometry.index?.array ?? [])
|
|
26
|
+
};
|
|
27
|
+
geometry.dispose();
|
|
28
|
+
}
|
|
29
|
+
const metrics = data;
|
|
30
|
+
return vectorFontSchema$1.parse({
|
|
31
|
+
format: "molen/vector-font@1",
|
|
32
|
+
id: options.id,
|
|
33
|
+
family: data.familyName,
|
|
34
|
+
weight: options.weight ?? 400,
|
|
35
|
+
style: options.style ?? "normal",
|
|
36
|
+
ascent: round((metrics.ascender ?? data.boundingBox.yMax) / data.resolution),
|
|
37
|
+
descent: round((metrics.descender ?? data.boundingBox.yMin) / data.resolution),
|
|
38
|
+
lineHeight: round(((metrics.ascender ?? data.boundingBox.yMax) - (metrics.descender ?? data.boundingBox.yMin)) / data.resolution),
|
|
39
|
+
glyphs,
|
|
40
|
+
kerning: options.kerning ?? {}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Caller owns/disposes the geometry and chooses its material, color, transform and batching. */
|
|
44
|
+
function createTextGeometry(text, fonts, options = {}) {
|
|
45
|
+
const data = buildTextMesh$1(text, fonts, options);
|
|
46
|
+
const geometry = new THREE.BufferGeometry();
|
|
47
|
+
geometry.setAttribute("position", new THREE.BufferAttribute(data.positions, 3));
|
|
48
|
+
geometry.setIndex(new THREE.BufferAttribute(data.indices, 1));
|
|
49
|
+
geometry.computeVertexNormals();
|
|
50
|
+
geometry.computeBoundingBox();
|
|
51
|
+
geometry.computeBoundingSphere();
|
|
52
|
+
geometry.userData.textLayout = {
|
|
53
|
+
text: data.text,
|
|
54
|
+
width: data.width,
|
|
55
|
+
height: data.height,
|
|
56
|
+
missingGlyphs: data.missingGlyphs,
|
|
57
|
+
truncated: data.truncated
|
|
58
|
+
};
|
|
59
|
+
return geometry;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
export { buildTextMesh, compileVectorFont, createTextGeometry, loadFontLibrary, vectorFontSchema };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-
|
|
1
|
+
import { n as ModelSignals, t as ModelSignalVisual } from "./model-signals-BpeXhsim.mjs";
|
|
2
2
|
import { VehicleInteriorSpec, VehicleSpec } from "@bendyline/molen-schema";
|
|
3
3
|
import { Object3D } from "three";
|
|
4
4
|
|
|
@@ -20,7 +20,7 @@ interface VehicleCameraPose {
|
|
|
20
20
|
declare function vehicleCameraPose(transform: {
|
|
21
21
|
pos: [number, number, number];
|
|
22
22
|
rot: [number, number, number, number];
|
|
23
|
-
}, spec: VehicleSpec, options: VehicleCameraOptions): VehicleCameraPose;
|
|
23
|
+
}, spec: Pick<VehicleSpec, "driverEye" | "length">, options: VehicleCameraOptions): VehicleCameraPose;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/vehicle-interior.d.ts
|
|
26
26
|
type VehicleInteriorSignals = ModelSignals;
|