@bendyline/molen-client 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aircraft.d.mts +112 -3
- package/dist/aircraft.mjs +721 -6
- package/dist/camera-track.d.mts +1 -1
- package/dist/index.d.mts +23 -6
- package/dist/index.mjs +345 -29
- package/dist/{input-BVZjf4T-.mjs → input-BliZYUY1.mjs} +42 -12
- package/dist/{input-CD-dHuv0.d.mts → input-Ckev_Kvj.d.mts} +9 -0
- package/dist/livery-C0abgthY.mjs +302 -0
- package/dist/navigation.d.mts +37 -6
- package/dist/navigation.mjs +518 -142
- package/dist/{renderer-CtEtmwJG.d.mts → renderer-Dzus24ZF.d.mts} +85 -8
- package/dist/vehicles.d.mts +3 -2
- package/dist/vehicles.mjs +62 -20
- package/package.json +3 -3
package/dist/navigation.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { t as InputMap } from "./input-
|
|
1
|
+
import { t as InputMap } from "./input-BliZYUY1.mjs";
|
|
2
|
+
import { boostSpeedMultiplier } from "@bendyline/molen-schema";
|
|
2
3
|
import * as THREE from "three";
|
|
3
4
|
import { Octree } from "three/addons/math/Octree.js";
|
|
4
5
|
import { Capsule } from "three/addons/math/Capsule.js";
|
|
@@ -177,126 +178,6 @@ function selectMedian({ centers, order }, axis, left, right, k) {
|
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
//#endregion
|
|
180
|
-
//#region src/navigation/fly.ts
|
|
181
|
-
var FlyController = class {
|
|
182
|
-
position;
|
|
183
|
-
/** Engine yaw: 0 faces +X (east), -PI/2 faces north. */
|
|
184
|
-
yaw;
|
|
185
|
-
/** Radians above the horizon (negative looks down). */
|
|
186
|
-
pitch;
|
|
187
|
-
minSpeed;
|
|
188
|
-
speedPerMeter;
|
|
189
|
-
sprintFactor;
|
|
190
|
-
minClearance;
|
|
191
|
-
lookSensitivity;
|
|
192
|
-
constructor(position, orientation, options = {}) {
|
|
193
|
-
this.position = [...position];
|
|
194
|
-
this.yaw = orientation.yaw;
|
|
195
|
-
this.pitch = orientation.pitch;
|
|
196
|
-
this.minSpeed = options.minSpeed ?? 12;
|
|
197
|
-
this.speedPerMeter = options.speedPerMeter ?? 1.2;
|
|
198
|
-
this.sprintFactor = options.sprintFactor ?? 4;
|
|
199
|
-
this.minClearance = options.minClearance ?? 2;
|
|
200
|
-
this.lookSensitivity = options.lookSensitivity ?? .003;
|
|
201
|
-
}
|
|
202
|
-
update(dt, input, environment) {
|
|
203
|
-
const step = Math.max(0, Math.min(.1, dt));
|
|
204
|
-
const turned = applyCameraLookDelta(this.yaw, this.pitch, input.look[0], input.look[1], this.lookSensitivity);
|
|
205
|
-
this.yaw = turned.yaw;
|
|
206
|
-
this.pitch = turned.pitch;
|
|
207
|
-
const ground = environment.groundHeight(this.position[0], this.position[2]);
|
|
208
|
-
const aboveGround = ground === void 0 ? 100 : Math.max(0, this.position[1] - ground);
|
|
209
|
-
const speed = Math.max(this.minSpeed, aboveGround * this.speedPerMeter) * (input.sprint ? this.sprintFactor : 1) * step;
|
|
210
|
-
const forward = cameraPlanarForward(this.yaw);
|
|
211
|
-
const right = cameraRight(this.yaw);
|
|
212
|
-
const { move } = input;
|
|
213
|
-
for (let axis = 0; axis < 3; axis++) this.position[axis] = this.position[axis] + (forward[axis] * move.forward + right[axis] * move.right) * speed;
|
|
214
|
-
this.position[1] += move.up * speed;
|
|
215
|
-
const floor = environment.groundHeight(this.position[0], this.position[2]);
|
|
216
|
-
if (floor !== void 0 && this.position[1] < floor + this.minClearance) this.position[1] = floor + this.minClearance;
|
|
217
|
-
const direction = cameraForward(this.yaw, this.pitch);
|
|
218
|
-
return {
|
|
219
|
-
position: [...this.position],
|
|
220
|
-
lookAt: [
|
|
221
|
-
this.position[0] + direction[0],
|
|
222
|
-
this.position[1] + direction[1],
|
|
223
|
-
this.position[2] + direction[2]
|
|
224
|
-
],
|
|
225
|
-
direction
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/navigation/follow.ts
|
|
231
|
-
var FollowController = class {
|
|
232
|
-
position;
|
|
233
|
-
yawOffset = 0;
|
|
234
|
-
pitchOffset = 0;
|
|
235
|
-
distance;
|
|
236
|
-
height;
|
|
237
|
-
lookHeight;
|
|
238
|
-
smoothing;
|
|
239
|
-
recenter;
|
|
240
|
-
minClearance;
|
|
241
|
-
constructor(options = {}) {
|
|
242
|
-
this.distance = options.distance ?? 6;
|
|
243
|
-
this.height = options.height ?? 2.2;
|
|
244
|
-
this.lookHeight = options.lookHeight ?? 1.2;
|
|
245
|
-
this.smoothing = options.smoothing ?? .18;
|
|
246
|
-
this.recenter = options.recenter ?? 1.5;
|
|
247
|
-
this.minClearance = options.minClearance ?? .6;
|
|
248
|
-
}
|
|
249
|
-
/** Snap next frame instead of easing (after a teleport or a subject change). */
|
|
250
|
-
reset() {
|
|
251
|
-
this.position = void 0;
|
|
252
|
-
this.yawOffset = 0;
|
|
253
|
-
this.pitchOffset = 0;
|
|
254
|
-
}
|
|
255
|
-
update(dt, subject, input, environment) {
|
|
256
|
-
const step = Math.max(0, Math.min(.1, dt));
|
|
257
|
-
const looking = input.look[0] !== 0 || input.look[1] !== 0;
|
|
258
|
-
this.yawOffset = Math.max(-Math.PI, Math.min(Math.PI, this.yawOffset - input.look[0] * .005));
|
|
259
|
-
this.pitchOffset = Math.max(-.35, Math.min(.9, this.pitchOffset + input.look[1] * .004));
|
|
260
|
-
if (!looking && this.recenter > 0) {
|
|
261
|
-
const decay = Math.exp(-step / this.recenter);
|
|
262
|
-
this.yawOffset *= decay;
|
|
263
|
-
this.pitchOffset *= decay;
|
|
264
|
-
}
|
|
265
|
-
const heading = subject.heading + this.yawOffset;
|
|
266
|
-
const lookAt = [
|
|
267
|
-
subject.position[0],
|
|
268
|
-
subject.position[1] + this.lookHeight,
|
|
269
|
-
subject.position[2]
|
|
270
|
-
];
|
|
271
|
-
const reach = this.distance * Math.cos(this.pitchOffset);
|
|
272
|
-
const ideal = [
|
|
273
|
-
subject.position[0] - Math.sin(heading) * reach,
|
|
274
|
-
subject.position[1] + this.height + this.distance * Math.sin(this.pitchOffset),
|
|
275
|
-
subject.position[2] + Math.cos(heading) * reach
|
|
276
|
-
];
|
|
277
|
-
if (this.position === void 0) this.position = [...ideal];
|
|
278
|
-
else {
|
|
279
|
-
const blend = this.smoothing <= 0 ? 1 : 1 - Math.exp(-step / this.smoothing);
|
|
280
|
-
for (let axis = 0; axis < 3; axis++) this.position[axis] = this.position[axis] + (ideal[axis] - this.position[axis]) * blend;
|
|
281
|
-
}
|
|
282
|
-
const ground = environment.groundHeight(this.position[0], this.position[2]);
|
|
283
|
-
if (ground !== void 0 && this.position[1] < ground + this.minClearance) this.position[1] = ground + this.minClearance;
|
|
284
|
-
const dx = lookAt[0] - this.position[0];
|
|
285
|
-
const dy = lookAt[1] - this.position[1];
|
|
286
|
-
const dz = lookAt[2] - this.position[2];
|
|
287
|
-
const length = Math.hypot(dx, dy, dz) || 1;
|
|
288
|
-
return {
|
|
289
|
-
position: [...this.position],
|
|
290
|
-
lookAt,
|
|
291
|
-
direction: [
|
|
292
|
-
dx / length,
|
|
293
|
-
dy / length,
|
|
294
|
-
dz / length
|
|
295
|
-
]
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
//#endregion
|
|
300
181
|
//#region src/navigation/pointer.ts
|
|
301
182
|
function emptyGestures() {
|
|
302
183
|
return {
|
|
@@ -478,8 +359,10 @@ const NAVIGATION_ACTIONS = {
|
|
|
478
359
|
jump: "nav-jump",
|
|
479
360
|
interact: "nav-interact",
|
|
480
361
|
view: "nav-view",
|
|
362
|
+
boost: "nav-boost",
|
|
481
363
|
throttleUp: "nav-throttle-up",
|
|
482
364
|
throttleDown: "nav-throttle-down",
|
|
365
|
+
power: "nav-power",
|
|
483
366
|
yawLeft: "nav-yaw-left",
|
|
484
367
|
yawRight: "nav-yaw-right",
|
|
485
368
|
engine: "nav-engine",
|
|
@@ -549,7 +432,8 @@ const STICKS = [
|
|
|
549
432
|
* 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 ←/→)
|
|
550
433
|
* bank, Q/Z work the rudder or pedals, Shift/Ctrl (or +/−, Page Up/Down) set throttle or
|
|
551
434
|
* collective, I toggles the engine, G the gear, F the flaps, R recovers after an impact, Space
|
|
552
|
-
* brakes, V switches the view and E leaves.
|
|
435
|
+
* brakes, V switches the view and E leaves. T toggles travel boost in walk, drive and pilot.
|
|
436
|
+
* Hosts may replace any profile through
|
|
553
437
|
* `InputMap.defineProfile`.
|
|
554
438
|
*/
|
|
555
439
|
function navigationInputProfiles() {
|
|
@@ -583,7 +467,8 @@ function navigationInputProfiles() {
|
|
|
583
467
|
Space: A.jump,
|
|
584
468
|
KeyE: A.interact,
|
|
585
469
|
KeyF: A.interact,
|
|
586
|
-
KeyV: A.view
|
|
470
|
+
KeyV: A.view,
|
|
471
|
+
KeyT: A.boost
|
|
587
472
|
},
|
|
588
473
|
axes: STICKS,
|
|
589
474
|
buttons: [
|
|
@@ -635,6 +520,7 @@ function navigationInputProfiles() {
|
|
|
635
520
|
Space: A.jump,
|
|
636
521
|
KeyE: A.interact,
|
|
637
522
|
KeyV: A.view,
|
|
523
|
+
KeyT: A.boost,
|
|
638
524
|
KeyI: A.engine,
|
|
639
525
|
KeyG: A.gear,
|
|
640
526
|
KeyF: A.flaps,
|
|
@@ -707,6 +593,7 @@ var NavigationInputSource = class {
|
|
|
707
593
|
pointer;
|
|
708
594
|
interactPresses = 0;
|
|
709
595
|
viewPresses = 0;
|
|
596
|
+
boostPresses = 0;
|
|
710
597
|
profile;
|
|
711
598
|
pilotPresses = {
|
|
712
599
|
engine: 0,
|
|
@@ -745,10 +632,14 @@ var NavigationInputSource = class {
|
|
|
745
632
|
this.map.onPress(A.view, () => {
|
|
746
633
|
this.viewPresses++;
|
|
747
634
|
}),
|
|
635
|
+
this.map.onPress(A.boost, () => {
|
|
636
|
+
this.boostPresses++;
|
|
637
|
+
}),
|
|
748
638
|
this.map.onReset(() => {
|
|
749
639
|
this.pointer.reset();
|
|
750
640
|
this.interactPresses = 0;
|
|
751
641
|
this.viewPresses = 0;
|
|
642
|
+
this.boostPresses = 0;
|
|
752
643
|
this.pilotPresses.engine = 0;
|
|
753
644
|
this.pilotPresses.gear = 0;
|
|
754
645
|
this.pilotPresses.flaps = 0;
|
|
@@ -794,8 +685,10 @@ var NavigationInputSource = class {
|
|
|
794
685
|
jump: v(A.jump) !== 0,
|
|
795
686
|
interact: this.interactPresses,
|
|
796
687
|
view: this.viewPresses,
|
|
688
|
+
...this.boostPresses > 0 ? { boost: this.boostPresses } : {},
|
|
797
689
|
taps: gestures.taps,
|
|
798
690
|
...this.profile === "pilot" ? { pilot: {
|
|
691
|
+
...this.map.hasAxis(A.power) ? { power: v(A.power) } : {},
|
|
799
692
|
throttle: v(A.throttleUp) - v(A.throttleDown),
|
|
800
693
|
yaw: v(A.yawRight) - v(A.yawLeft),
|
|
801
694
|
...this.pilotPresses
|
|
@@ -803,6 +696,7 @@ var NavigationInputSource = class {
|
|
|
803
696
|
};
|
|
804
697
|
this.interactPresses = 0;
|
|
805
698
|
this.viewPresses = 0;
|
|
699
|
+
this.boostPresses = 0;
|
|
806
700
|
this.pilotPresses.engine = 0;
|
|
807
701
|
this.pilotPresses.gear = 0;
|
|
808
702
|
this.pilotPresses.flaps = 0;
|
|
@@ -817,6 +711,433 @@ var NavigationInputSource = class {
|
|
|
817
711
|
}
|
|
818
712
|
};
|
|
819
713
|
//#endregion
|
|
714
|
+
//#region src/navigation/controls.ts
|
|
715
|
+
/** Controller discovery and raw axis/button mapping for the built-in navigation profiles. */
|
|
716
|
+
function createNavigationControls(source, options) {
|
|
717
|
+
const map = source.map;
|
|
718
|
+
const doc = options.container.ownerDocument;
|
|
719
|
+
const defaults = new Map(map.profileNames().map((name) => [name, map.getProfile(name)]));
|
|
720
|
+
let storageMessage = "";
|
|
721
|
+
if (options.storageKey) try {
|
|
722
|
+
const saved = JSON.parse(doc.defaultView?.localStorage.getItem(options.storageKey) ?? "null");
|
|
723
|
+
if (saved && typeof saved === "object") {
|
|
724
|
+
for (const name of map.profileNames()) if (Object.hasOwn(saved, name)) try {
|
|
725
|
+
map.defineProfile(name, saved[name]);
|
|
726
|
+
} catch {
|
|
727
|
+
storageMessage = "Some saved mappings were invalid; defaults were restored.";
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
} catch {
|
|
731
|
+
storageMessage = "Saved controls could not be loaded. You can still remap this session.";
|
|
732
|
+
}
|
|
733
|
+
const button = (text, parent, action) => {
|
|
734
|
+
const element = doc.createElement("button");
|
|
735
|
+
element.type = "button";
|
|
736
|
+
element.textContent = text;
|
|
737
|
+
element.addEventListener("click", action);
|
|
738
|
+
parent.append(element);
|
|
739
|
+
return element;
|
|
740
|
+
};
|
|
741
|
+
const dialog = doc.createElement("dialog");
|
|
742
|
+
dialog.setAttribute("aria-label", "Joystick and controller settings");
|
|
743
|
+
dialog.className = "molen-navigation-controls";
|
|
744
|
+
dialog.style.cssText = "box-sizing:border-box;width:min(600px,calc(100vw - 24px));max-height:85vh;overflow:auto;padding:20px;border:1px solid #607b8a;border-radius:12px;background:#162b38;color:#e1edf4;font:14px/1.5 system-ui;color-scheme:dark";
|
|
745
|
+
const heading = doc.createElement("h2");
|
|
746
|
+
heading.textContent = "Joystick and controller settings";
|
|
747
|
+
dialog.append(heading);
|
|
748
|
+
const status = doc.createElement("p");
|
|
749
|
+
status.setAttribute("role", "status");
|
|
750
|
+
const hint = doc.createElement("p");
|
|
751
|
+
hint.textContent = "Press a controller button to let the browser detect it. Move each axis to identify its number below. Controls are suspended while this editor is open.";
|
|
752
|
+
dialog.append(status, hint);
|
|
753
|
+
const select = (text) => {
|
|
754
|
+
const label = doc.createElement("label");
|
|
755
|
+
label.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:10px 0;color:inherit;font:inherit";
|
|
756
|
+
label.append(`${text} `);
|
|
757
|
+
const field = doc.createElement("select");
|
|
758
|
+
field.setAttribute("aria-label", text);
|
|
759
|
+
field.style.cssText = "max-width:100%;min-width:0;font:inherit";
|
|
760
|
+
label.append(field);
|
|
761
|
+
dialog.append(label);
|
|
762
|
+
return field;
|
|
763
|
+
};
|
|
764
|
+
const option = (field, value, text) => {
|
|
765
|
+
const item = doc.createElement("option");
|
|
766
|
+
item.value = value;
|
|
767
|
+
item.textContent = text;
|
|
768
|
+
field.append(item);
|
|
769
|
+
};
|
|
770
|
+
const profile = select("Profile");
|
|
771
|
+
for (const name of map.profileNames()) option(profile, name, name === "pilot" ? "pilot (aircraft)" : name);
|
|
772
|
+
const device = select("Controller");
|
|
773
|
+
const raw = doc.createElement("pre");
|
|
774
|
+
raw.style.cssText = "white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px";
|
|
775
|
+
dialog.append(raw);
|
|
776
|
+
const axis = select("Axis");
|
|
777
|
+
const axisAction = select("Axis action");
|
|
778
|
+
const invertLabel = doc.createElement("label");
|
|
779
|
+
const invert = doc.createElement("input");
|
|
780
|
+
invert.type = "checkbox";
|
|
781
|
+
invertLabel.append(invert, " Reverse axis");
|
|
782
|
+
dialog.append(invertLabel);
|
|
783
|
+
const zoneLabel = doc.createElement("label");
|
|
784
|
+
zoneLabel.style.cssText = "display:block;margin:10px 0";
|
|
785
|
+
zoneLabel.append("Dead zone ");
|
|
786
|
+
const zone = doc.createElement("input");
|
|
787
|
+
zone.type = "number";
|
|
788
|
+
zone.min = "0";
|
|
789
|
+
zone.max = "0.9";
|
|
790
|
+
zone.step = "0.01";
|
|
791
|
+
zone.value = "0.12";
|
|
792
|
+
zone.style.width = "6em";
|
|
793
|
+
zoneLabel.append(zone);
|
|
794
|
+
dialog.append(zoneLabel);
|
|
795
|
+
const bindings = doc.createElement("div");
|
|
796
|
+
const feedback = doc.createElement("p");
|
|
797
|
+
feedback.setAttribute("role", "status");
|
|
798
|
+
feedback.textContent = storageMessage;
|
|
799
|
+
let pairs = [];
|
|
800
|
+
let resume;
|
|
801
|
+
let deviceSignature = "";
|
|
802
|
+
let controlSignature = "";
|
|
803
|
+
const currentDevice = () => map.devices().find((pad) => String(pad.index) === device.value);
|
|
804
|
+
const renderBindings = () => {
|
|
805
|
+
bindings.replaceChildren();
|
|
806
|
+
const current = map.getProfile(profile.value);
|
|
807
|
+
for (const kind of ["axes", "buttons"]) current[kind]?.forEach((binding, index) => {
|
|
808
|
+
const row = doc.createElement("p");
|
|
809
|
+
row.style.cssText = "font-size:12px;overflow-wrap:anywhere";
|
|
810
|
+
row.append(`${"axis" in binding ? `Axis ${binding.axis} (${binding.mode ?? "signed"}${binding.invert ? ", reversed" : ""})` : `Button ${binding.button}`} → ${binding.action.replace("nav-", "")} · ${binding.device?.id ?? "any controller"} `);
|
|
811
|
+
button("Remove", row, () => {
|
|
812
|
+
const next = map.getProfile(profile.value);
|
|
813
|
+
next[kind]?.splice(index, 1);
|
|
814
|
+
map.defineProfile(profile.value, next);
|
|
815
|
+
renderBindings();
|
|
816
|
+
});
|
|
817
|
+
bindings.append(row);
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
const sameDevice = (binding) => {
|
|
821
|
+
const pad = currentDevice();
|
|
822
|
+
return !!pad && (binding.device?.id === void 0 || binding.device.id === pad.id) && (binding.device?.index === void 0 || binding.device.index === pad.index);
|
|
823
|
+
};
|
|
824
|
+
const bindAxis = button("Assign axis", dialog, () => {
|
|
825
|
+
const pad = currentDevice();
|
|
826
|
+
const deadZone = Number(zone.value);
|
|
827
|
+
if (!pad || !Number.isFinite(deadZone) || deadZone < 0 || deadZone >= 1) {
|
|
828
|
+
feedback.textContent = "Choose a detected controller and a dead zone from 0 to less than 1.";
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
const next = map.getProfile(profile.value);
|
|
832
|
+
const pair = pairs[Number(axisAction.value)];
|
|
833
|
+
const actions = pair ? [pair[1], pair[2]] : [NAVIGATION_ACTIONS.power];
|
|
834
|
+
const index = Number(axis.value);
|
|
835
|
+
next.axes = (next.axes ?? []).filter((binding) => !sameDevice(binding) || binding.axis !== index && !actions.includes(binding.action));
|
|
836
|
+
const common = {
|
|
837
|
+
axis: index,
|
|
838
|
+
device: { id: pad.id },
|
|
839
|
+
invert: invert.checked,
|
|
840
|
+
deadZone
|
|
841
|
+
};
|
|
842
|
+
if (pair) next.axes.push({
|
|
843
|
+
...common,
|
|
844
|
+
action: pair[1],
|
|
845
|
+
mode: "negative"
|
|
846
|
+
}, {
|
|
847
|
+
...common,
|
|
848
|
+
action: pair[2],
|
|
849
|
+
mode: "positive"
|
|
850
|
+
});
|
|
851
|
+
else next.axes.push({
|
|
852
|
+
...common,
|
|
853
|
+
deadZone: 0,
|
|
854
|
+
action: NAVIGATION_ACTIONS.power,
|
|
855
|
+
mode: "unit"
|
|
856
|
+
});
|
|
857
|
+
map.defineProfile(profile.value, next);
|
|
858
|
+
feedback.textContent = "Axis assigned. Close the editor to try it; Save keeps it for next time.";
|
|
859
|
+
renderBindings();
|
|
860
|
+
});
|
|
861
|
+
const padButton = select("Button");
|
|
862
|
+
const buttonAction = select("Button action");
|
|
863
|
+
const bindButton = button("Assign button", dialog, () => {
|
|
864
|
+
const pad = currentDevice();
|
|
865
|
+
if (!pad) return;
|
|
866
|
+
const next = map.getProfile(profile.value);
|
|
867
|
+
const index = Number(padButton.value);
|
|
868
|
+
next.buttons = (next.buttons ?? []).filter((binding) => !sameDevice(binding) || binding.button !== index);
|
|
869
|
+
next.buttons.push({
|
|
870
|
+
button: index,
|
|
871
|
+
action: buttonAction.value,
|
|
872
|
+
device: { id: pad.id }
|
|
873
|
+
});
|
|
874
|
+
map.defineProfile(profile.value, next);
|
|
875
|
+
feedback.textContent = "Button assigned. Close the editor to try it; Save keeps it for next time.";
|
|
876
|
+
renderBindings();
|
|
877
|
+
});
|
|
878
|
+
const updateProfile = () => {
|
|
879
|
+
const pilot = profile.value === "pilot";
|
|
880
|
+
pairs = [
|
|
881
|
+
[
|
|
882
|
+
pilot ? "Pitch (positive = nose up)" : "Forward / backward",
|
|
883
|
+
NAVIGATION_ACTIONS.forward,
|
|
884
|
+
NAVIGATION_ACTIONS.back
|
|
885
|
+
],
|
|
886
|
+
[
|
|
887
|
+
pilot ? "Roll (positive = right)" : "Left / right",
|
|
888
|
+
NAVIGATION_ACTIONS.left,
|
|
889
|
+
NAVIGATION_ACTIONS.right
|
|
890
|
+
],
|
|
891
|
+
[
|
|
892
|
+
"Look left / right",
|
|
893
|
+
NAVIGATION_ACTIONS.lookLeft,
|
|
894
|
+
NAVIGATION_ACTIONS.lookRight
|
|
895
|
+
],
|
|
896
|
+
[
|
|
897
|
+
"Look up / down",
|
|
898
|
+
NAVIGATION_ACTIONS.lookUp,
|
|
899
|
+
NAVIGATION_ACTIONS.lookDown
|
|
900
|
+
],
|
|
901
|
+
...pilot ? [[
|
|
902
|
+
"Rudder (positive = right)",
|
|
903
|
+
NAVIGATION_ACTIONS.yawLeft,
|
|
904
|
+
NAVIGATION_ACTIONS.yawRight
|
|
905
|
+
]] : [[
|
|
906
|
+
"Down / up",
|
|
907
|
+
NAVIGATION_ACTIONS.down,
|
|
908
|
+
NAVIGATION_ACTIONS.up
|
|
909
|
+
]]
|
|
910
|
+
];
|
|
911
|
+
axisAction.replaceChildren();
|
|
912
|
+
pairs.forEach((pair, index) => {
|
|
913
|
+
option(axisAction, String(index), pair[0]);
|
|
914
|
+
});
|
|
915
|
+
if (pilot) option(axisAction, "power", "Throttle / collective (absolute lever)");
|
|
916
|
+
buttonAction.replaceChildren();
|
|
917
|
+
const actions = [
|
|
918
|
+
[NAVIGATION_ACTIONS.jump, pilot || profile.value === "drive" ? "Brake" : "Jump"],
|
|
919
|
+
[NAVIGATION_ACTIONS.interact, "Enter / exit vehicle"],
|
|
920
|
+
[NAVIGATION_ACTIONS.view, "Change view"],
|
|
921
|
+
...pilot ? [
|
|
922
|
+
[NAVIGATION_ACTIONS.throttleUp, "Increase throttle"],
|
|
923
|
+
[NAVIGATION_ACTIONS.throttleDown, "Decrease throttle"],
|
|
924
|
+
[NAVIGATION_ACTIONS.engine, "Engine"],
|
|
925
|
+
[NAVIGATION_ACTIONS.gear, "Landing gear"],
|
|
926
|
+
[NAVIGATION_ACTIONS.flaps, "Flaps"],
|
|
927
|
+
[NAVIGATION_ACTIONS.vector, "Thrust vector"],
|
|
928
|
+
[NAVIGATION_ACTIONS.recover, "Recover"]
|
|
929
|
+
] : [
|
|
930
|
+
[NAVIGATION_ACTIONS.sprint, "Sprint / handbrake"],
|
|
931
|
+
[NAVIGATION_ACTIONS.up, "Up"],
|
|
932
|
+
[NAVIGATION_ACTIONS.down, "Down"]
|
|
933
|
+
]
|
|
934
|
+
];
|
|
935
|
+
for (const [value, label] of actions) option(buttonAction, value, label);
|
|
936
|
+
renderBindings();
|
|
937
|
+
};
|
|
938
|
+
profile.addEventListener("change", updateProfile);
|
|
939
|
+
const mappingDetails = doc.createElement("details");
|
|
940
|
+
const mappingSummary = doc.createElement("summary");
|
|
941
|
+
mappingSummary.textContent = "Current mappings";
|
|
942
|
+
mappingDetails.append(mappingSummary, bindings);
|
|
943
|
+
dialog.append(feedback, mappingDetails);
|
|
944
|
+
button("Save", dialog, () => {
|
|
945
|
+
if (!options.storageKey) return;
|
|
946
|
+
try {
|
|
947
|
+
doc.defaultView?.localStorage.setItem(options.storageKey, JSON.stringify(Object.fromEntries(map.profileNames().map((name) => [name, map.getProfile(name)]))));
|
|
948
|
+
feedback.textContent = "Controls saved on this browser.";
|
|
949
|
+
} catch {
|
|
950
|
+
feedback.textContent = "Browser storage is unavailable. Mappings still work for this session.";
|
|
951
|
+
}
|
|
952
|
+
}).hidden = !options.storageKey;
|
|
953
|
+
button("Reset profile", dialog, () => {
|
|
954
|
+
const original = defaults.get(profile.value);
|
|
955
|
+
if (original) map.defineProfile(profile.value, original);
|
|
956
|
+
feedback.textContent = "Default gamepad mappings restored. Save to keep this reset.";
|
|
957
|
+
renderBindings();
|
|
958
|
+
});
|
|
959
|
+
button("Done", dialog, () => dialog.close());
|
|
960
|
+
const close = () => {
|
|
961
|
+
resume?.();
|
|
962
|
+
resume = void 0;
|
|
963
|
+
options.focusTarget.focus();
|
|
964
|
+
};
|
|
965
|
+
dialog.addEventListener("close", close);
|
|
966
|
+
const open = button("Controllers", options.container, () => {
|
|
967
|
+
profile.value = map.activeProfile ?? map.profileNames()[0] ?? "";
|
|
968
|
+
updateProfile();
|
|
969
|
+
resume = map.suspend();
|
|
970
|
+
doc.exitPointerLock?.();
|
|
971
|
+
dialog.showModal();
|
|
972
|
+
poll();
|
|
973
|
+
});
|
|
974
|
+
doc.body.append(dialog);
|
|
975
|
+
const poll = () => {
|
|
976
|
+
if (dialog.open) map.update();
|
|
977
|
+
const pads = map.devices();
|
|
978
|
+
open.textContent = `Controllers (${pads.length})`;
|
|
979
|
+
if (!dialog.open) return;
|
|
980
|
+
const message = map.gamepadStatus === "blocked" ? "Controller access is blocked by the browser or embedding page." : map.gamepadStatus === "unavailable" ? "This browser does not expose controller input. Use HTTPS or localhost in a browser with Gamepad API support." : pads.length ? `${pads.length} controller(s) detected.` : "No controller detected yet. Focus this page and press a controller button.";
|
|
981
|
+
if (status.textContent !== message) status.textContent = message;
|
|
982
|
+
const signature = JSON.stringify(pads.map((pad) => [pad.id, pad.index]));
|
|
983
|
+
if (signature !== deviceSignature) {
|
|
984
|
+
deviceSignature = signature;
|
|
985
|
+
const previous = device.value;
|
|
986
|
+
device.replaceChildren();
|
|
987
|
+
for (const pad of pads) option(device, String(pad.index), `${pad.id} (#${pad.index})`);
|
|
988
|
+
if (pads.some((pad) => String(pad.index) === previous)) device.value = previous;
|
|
989
|
+
}
|
|
990
|
+
const pad = currentDevice();
|
|
991
|
+
const controls = JSON.stringify([
|
|
992
|
+
pad?.id,
|
|
993
|
+
pad?.index,
|
|
994
|
+
pad?.axes.length,
|
|
995
|
+
pad?.buttons.length
|
|
996
|
+
]);
|
|
997
|
+
if (controls !== controlSignature) {
|
|
998
|
+
controlSignature = controls;
|
|
999
|
+
axis.replaceChildren();
|
|
1000
|
+
padButton.replaceChildren();
|
|
1001
|
+
pad?.axes.forEach((_, index) => {
|
|
1002
|
+
option(axis, String(index), String(index));
|
|
1003
|
+
});
|
|
1004
|
+
pad?.buttons.forEach((_, index) => {
|
|
1005
|
+
option(padButton, String(index), String(index));
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
bindAxis.disabled = !pad?.axes.length;
|
|
1009
|
+
bindButton.disabled = !pad?.buttons.length;
|
|
1010
|
+
raw.textContent = pad ? `Axes: ${pad.axes.map((value, index) => `${index}: ${value.toFixed(2)}`).join(" ")}\nPressed buttons: ${pad.buttons.flatMap((value, index) => value.pressed || value.value > .5 ? [index] : []).join(", ") || "none"}` : "";
|
|
1011
|
+
};
|
|
1012
|
+
const timer = setInterval(poll, 100);
|
|
1013
|
+
return { dispose() {
|
|
1014
|
+
clearInterval(timer);
|
|
1015
|
+
resume?.();
|
|
1016
|
+
dialog.remove();
|
|
1017
|
+
open.remove();
|
|
1018
|
+
} };
|
|
1019
|
+
}
|
|
1020
|
+
//#endregion
|
|
1021
|
+
//#region src/navigation/fly.ts
|
|
1022
|
+
var FlyController = class {
|
|
1023
|
+
position;
|
|
1024
|
+
/** Engine yaw: 0 faces +X (east), -PI/2 faces north. */
|
|
1025
|
+
yaw;
|
|
1026
|
+
/** Radians above the horizon (negative looks down). */
|
|
1027
|
+
pitch;
|
|
1028
|
+
minSpeed;
|
|
1029
|
+
speedPerMeter;
|
|
1030
|
+
sprintFactor;
|
|
1031
|
+
minClearance;
|
|
1032
|
+
lookSensitivity;
|
|
1033
|
+
constructor(position, orientation, options = {}) {
|
|
1034
|
+
this.position = [...position];
|
|
1035
|
+
this.yaw = orientation.yaw;
|
|
1036
|
+
this.pitch = orientation.pitch;
|
|
1037
|
+
this.minSpeed = options.minSpeed ?? 12;
|
|
1038
|
+
this.speedPerMeter = options.speedPerMeter ?? 1.2;
|
|
1039
|
+
this.sprintFactor = options.sprintFactor ?? 4;
|
|
1040
|
+
this.minClearance = options.minClearance ?? 2;
|
|
1041
|
+
this.lookSensitivity = options.lookSensitivity ?? .003;
|
|
1042
|
+
}
|
|
1043
|
+
update(dt, input, environment) {
|
|
1044
|
+
const step = Math.max(0, Math.min(.1, dt));
|
|
1045
|
+
const turned = applyCameraLookDelta(this.yaw, this.pitch, input.look[0], input.look[1], this.lookSensitivity);
|
|
1046
|
+
this.yaw = turned.yaw;
|
|
1047
|
+
this.pitch = turned.pitch;
|
|
1048
|
+
const ground = environment.groundHeight(this.position[0], this.position[2]);
|
|
1049
|
+
const aboveGround = ground === void 0 ? 100 : Math.max(0, this.position[1] - ground);
|
|
1050
|
+
const speed = Math.max(this.minSpeed, aboveGround * this.speedPerMeter) * (input.sprint ? this.sprintFactor : 1) * step;
|
|
1051
|
+
const forward = cameraPlanarForward(this.yaw);
|
|
1052
|
+
const right = cameraRight(this.yaw);
|
|
1053
|
+
const { move } = input;
|
|
1054
|
+
for (let axis = 0; axis < 3; axis++) this.position[axis] = this.position[axis] + (forward[axis] * move.forward + right[axis] * move.right) * speed;
|
|
1055
|
+
this.position[1] += move.up * speed;
|
|
1056
|
+
const floor = environment.groundHeight(this.position[0], this.position[2]);
|
|
1057
|
+
if (floor !== void 0 && this.position[1] < floor + this.minClearance) this.position[1] = floor + this.minClearance;
|
|
1058
|
+
const direction = cameraForward(this.yaw, this.pitch);
|
|
1059
|
+
return {
|
|
1060
|
+
position: [...this.position],
|
|
1061
|
+
lookAt: [
|
|
1062
|
+
this.position[0] + direction[0],
|
|
1063
|
+
this.position[1] + direction[1],
|
|
1064
|
+
this.position[2] + direction[2]
|
|
1065
|
+
],
|
|
1066
|
+
direction
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
//#endregion
|
|
1071
|
+
//#region src/navigation/follow.ts
|
|
1072
|
+
var FollowController = class {
|
|
1073
|
+
position;
|
|
1074
|
+
yawOffset = 0;
|
|
1075
|
+
pitchOffset = 0;
|
|
1076
|
+
distance;
|
|
1077
|
+
height;
|
|
1078
|
+
lookHeight;
|
|
1079
|
+
smoothing;
|
|
1080
|
+
recenter;
|
|
1081
|
+
minClearance;
|
|
1082
|
+
constructor(options = {}) {
|
|
1083
|
+
this.distance = options.distance ?? 6;
|
|
1084
|
+
this.height = options.height ?? 2.2;
|
|
1085
|
+
this.lookHeight = options.lookHeight ?? 1.2;
|
|
1086
|
+
this.smoothing = options.smoothing ?? .18;
|
|
1087
|
+
this.recenter = options.recenter ?? 1.5;
|
|
1088
|
+
this.minClearance = options.minClearance ?? .6;
|
|
1089
|
+
}
|
|
1090
|
+
/** Snap next frame instead of easing (after a teleport or a subject change). */
|
|
1091
|
+
reset() {
|
|
1092
|
+
this.position = void 0;
|
|
1093
|
+
this.yawOffset = 0;
|
|
1094
|
+
this.pitchOffset = 0;
|
|
1095
|
+
}
|
|
1096
|
+
update(dt, subject, input, environment) {
|
|
1097
|
+
const step = Math.max(0, Math.min(.1, dt));
|
|
1098
|
+
const looking = input.look[0] !== 0 || input.look[1] !== 0;
|
|
1099
|
+
this.yawOffset = Math.max(-Math.PI, Math.min(Math.PI, this.yawOffset - input.look[0] * .005));
|
|
1100
|
+
this.pitchOffset = Math.max(-.35, Math.min(.9, this.pitchOffset + input.look[1] * .004));
|
|
1101
|
+
if (!looking && this.recenter > 0) {
|
|
1102
|
+
const decay = Math.exp(-step / this.recenter);
|
|
1103
|
+
this.yawOffset *= decay;
|
|
1104
|
+
this.pitchOffset *= decay;
|
|
1105
|
+
}
|
|
1106
|
+
const heading = subject.heading + this.yawOffset;
|
|
1107
|
+
const lookAt = [
|
|
1108
|
+
subject.position[0],
|
|
1109
|
+
subject.position[1] + this.lookHeight,
|
|
1110
|
+
subject.position[2]
|
|
1111
|
+
];
|
|
1112
|
+
const reach = this.distance * Math.cos(this.pitchOffset);
|
|
1113
|
+
const ideal = [
|
|
1114
|
+
subject.position[0] - Math.sin(heading) * reach,
|
|
1115
|
+
subject.position[1] + this.height + this.distance * Math.sin(this.pitchOffset),
|
|
1116
|
+
subject.position[2] + Math.cos(heading) * reach
|
|
1117
|
+
];
|
|
1118
|
+
if (this.position === void 0) this.position = [...ideal];
|
|
1119
|
+
else {
|
|
1120
|
+
const blend = this.smoothing <= 0 ? 1 : 1 - Math.exp(-step / this.smoothing);
|
|
1121
|
+
for (let axis = 0; axis < 3; axis++) this.position[axis] = this.position[axis] + (ideal[axis] - this.position[axis]) * blend;
|
|
1122
|
+
}
|
|
1123
|
+
const ground = environment.groundHeight(this.position[0], this.position[2]);
|
|
1124
|
+
if (ground !== void 0 && this.position[1] < ground + this.minClearance) this.position[1] = ground + this.minClearance;
|
|
1125
|
+
const dx = lookAt[0] - this.position[0];
|
|
1126
|
+
const dy = lookAt[1] - this.position[1];
|
|
1127
|
+
const dz = lookAt[2] - this.position[2];
|
|
1128
|
+
const length = Math.hypot(dx, dy, dz) || 1;
|
|
1129
|
+
return {
|
|
1130
|
+
position: [...this.position],
|
|
1131
|
+
lookAt,
|
|
1132
|
+
direction: [
|
|
1133
|
+
dx / length,
|
|
1134
|
+
dy / length,
|
|
1135
|
+
dz / length
|
|
1136
|
+
]
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
//#endregion
|
|
820
1141
|
//#region src/navigation/orbit.ts
|
|
821
1142
|
const TAU = Math.PI * 2;
|
|
822
1143
|
function smoothstep(t) {
|
|
@@ -1336,7 +1657,11 @@ function requireFinite(value, name, allowZero) {
|
|
|
1336
1657
|
* neighborhood. Large geometries (terrain tiles, building cells) are walked through a per-geometry
|
|
1337
1658
|
* spatial index, so a rebuild costs the triangles near the subject rather than the whole tile.
|
|
1338
1659
|
* Meshes opt out with `userData.walkIgnore`, and water materials (`userData.terrainWaterMaterial`)
|
|
1339
|
-
*
|
|
1660
|
+
* are never solid. Land cover is a solid walking surface: its visible elevation can differ from
|
|
1661
|
+
* bare terrain, and full-tile land cover can replace the bare surface altogether.
|
|
1662
|
+
* A group whose contents lie within an X/Z rectangle of its own frame declares it as
|
|
1663
|
+
* `userData.walkFootprint` (`[minX, minZ, maxX, maxZ]`, like a terrain tile): a scan skips the
|
|
1664
|
+
* whole group when that rectangle is out of reach.
|
|
1340
1665
|
*/
|
|
1341
1666
|
var WalkCollision = class {
|
|
1342
1667
|
origin = new THREE.Vector3();
|
|
@@ -1375,8 +1700,9 @@ var WalkCollision = class {
|
|
|
1375
1700
|
const moved = !this.initialized || band === void 0 !== (this.centerY === void 0) || Math.hypot(x - this.origin.x, z - this.origin.z) >= this.rebuildDistance || band !== void 0 && this.centerY !== void 0 && Math.abs(band - this.centerY) >= this.rebuildDistance;
|
|
1376
1701
|
const now = this.now();
|
|
1377
1702
|
if (!moved && !this.stale && now - this.scannedAt < this.rescanIntervalMs) return;
|
|
1378
|
-
root.updateWorldMatrix(true,
|
|
1703
|
+
root.updateWorldMatrix(true, false);
|
|
1379
1704
|
const inverse = root.matrixWorld.clone().invert();
|
|
1705
|
+
const candidate = new THREE.Matrix4();
|
|
1380
1706
|
const meshes = [];
|
|
1381
1707
|
const centerX = moved ? x : this.origin.x;
|
|
1382
1708
|
const centerZ = moved ? z : this.origin.z;
|
|
@@ -1384,25 +1710,44 @@ var WalkCollision = class {
|
|
|
1384
1710
|
const reach = this.radius + this.rebuildDistance;
|
|
1385
1711
|
const verticalReach = (this.verticalRadius ?? 0) + this.rebuildDistance;
|
|
1386
1712
|
const bounds = new THREE.Box3();
|
|
1387
|
-
|
|
1713
|
+
const sphere = new THREE.Sphere();
|
|
1714
|
+
const footprint = new THREE.Box3();
|
|
1715
|
+
const outOfReach = (min, max) => min.x > centerX + reach || max.x < centerX - reach || min.z > centerZ + reach || max.z < centerZ - reach || centerY !== void 0 && (min.y > centerY + verticalReach || max.y < centerY - verticalReach);
|
|
1716
|
+
const visit = (object, inspect) => {
|
|
1717
|
+
if (!object.visible) return;
|
|
1718
|
+
if (object !== root) object.updateWorldMatrix(false, false);
|
|
1719
|
+
const area = object.userData.walkFootprint;
|
|
1720
|
+
if (area !== void 0) {
|
|
1721
|
+
footprint.min.set(area[0], 0, area[1]);
|
|
1722
|
+
footprint.max.set(area[2], 0, area[3]);
|
|
1723
|
+
footprint.applyMatrix4(candidate.multiplyMatrices(inverse, object.matrixWorld));
|
|
1724
|
+
if (footprint.min.x > centerX + reach || footprint.max.x < centerX - reach || footprint.min.z > centerZ + reach || footprint.max.z < centerZ - reach) return;
|
|
1725
|
+
}
|
|
1726
|
+
inspect(object);
|
|
1727
|
+
for (const child of object.children) visit(child, inspect);
|
|
1728
|
+
};
|
|
1729
|
+
visit(root, (object) => {
|
|
1388
1730
|
if (!(object instanceof THREE.Mesh) || object.userData.walkIgnore === true) return;
|
|
1389
1731
|
if (this.ignoreVehicles && (object.userData.vehicleIds || object.userData.vehicleGeometry)) return;
|
|
1390
|
-
if (object.name === "semantic:landcover") return;
|
|
1391
1732
|
if ((Array.isArray(object.material) ? object.material : [object.material]).every((material) => material.userData.terrainWaterMaterial === true)) return;
|
|
1392
|
-
const matrix =
|
|
1733
|
+
const matrix = candidate.multiplyMatrices(inverse, object.matrixWorld);
|
|
1734
|
+
const known = object instanceof THREE.InstancedMesh ? object.boundingSphere : object.geometry.boundingSphere;
|
|
1735
|
+
if (known !== null) {
|
|
1736
|
+
sphere.copy(known).applyMatrix4(matrix);
|
|
1737
|
+
bounds.min.setScalar(-sphere.radius).add(sphere.center);
|
|
1738
|
+
bounds.max.setScalar(sphere.radius).add(sphere.center);
|
|
1739
|
+
if (outOfReach(bounds.min, bounds.max)) return;
|
|
1740
|
+
}
|
|
1393
1741
|
if (object instanceof THREE.InstancedMesh) {
|
|
1742
|
+
geometryBounds(object.geometry);
|
|
1394
1743
|
if (object.boundingBox === null) object.computeBoundingBox();
|
|
1395
1744
|
bounds.copy(object.boundingBox);
|
|
1396
|
-
} else
|
|
1397
|
-
if (object.geometry.boundingBox === null) object.geometry.computeBoundingBox();
|
|
1398
|
-
bounds.copy(object.geometry.boundingBox);
|
|
1399
|
-
}
|
|
1745
|
+
} else bounds.copy(geometryBounds(object.geometry));
|
|
1400
1746
|
bounds.applyMatrix4(matrix);
|
|
1401
|
-
if (bounds.min
|
|
1402
|
-
if (centerY !== void 0 && (bounds.min.y > centerY + verticalReach || bounds.max.y < centerY - verticalReach)) return;
|
|
1747
|
+
if (outOfReach(bounds.min, bounds.max)) return;
|
|
1403
1748
|
meshes.push({
|
|
1404
1749
|
mesh: object,
|
|
1405
|
-
matrix,
|
|
1750
|
+
matrix: matrix.clone(),
|
|
1406
1751
|
count: object instanceof THREE.InstancedMesh ? object.count : 1,
|
|
1407
1752
|
geometry: object.geometry,
|
|
1408
1753
|
version: object instanceof THREE.InstancedMesh ? object.instanceMatrix.version : (object.geometry.index?.version ?? 0) + (object.geometry.getAttribute("position")?.version ?? 0)
|
|
@@ -1456,7 +1801,7 @@ var WalkCollision = class {
|
|
|
1456
1801
|
const geometry = mesh.geometry;
|
|
1457
1802
|
const position = geometry.getAttribute("position");
|
|
1458
1803
|
if (position === void 0) continue;
|
|
1459
|
-
|
|
1804
|
+
geometryBounds(geometry);
|
|
1460
1805
|
local.multiplyMatrices(offset, matrix);
|
|
1461
1806
|
if (mesh instanceof THREE.InstancedMesh && mesh.boundingBox === null) mesh.computeBoundingBox();
|
|
1462
1807
|
bounds.copy(mesh instanceof THREE.InstancedMesh ? mesh.boundingBox : geometry.boundingBox).applyMatrix4(local);
|
|
@@ -1501,6 +1846,32 @@ var WalkCollision = class {
|
|
|
1501
1846
|
this.octree.build();
|
|
1502
1847
|
}
|
|
1503
1848
|
};
|
|
1849
|
+
/**
|
|
1850
|
+
* The geometry's bounding box, computed once straight from a plain float position array: three's
|
|
1851
|
+
* per-vertex accessors made a freshly streamed building cell's box most of an aircraft's scan.
|
|
1852
|
+
*/
|
|
1853
|
+
function geometryBounds(geometry) {
|
|
1854
|
+
const known = geometry.boundingBox;
|
|
1855
|
+
if (known !== null) return known;
|
|
1856
|
+
const position = geometry.getAttribute("position");
|
|
1857
|
+
if (!(position instanceof THREE.BufferAttribute) || !(position.array instanceof Float32Array) || position.normalized || position.itemSize !== 3 || geometry.morphAttributes.position !== void 0) {
|
|
1858
|
+
geometry.computeBoundingBox();
|
|
1859
|
+
return geometry.boundingBox;
|
|
1860
|
+
}
|
|
1861
|
+
const array = position.array;
|
|
1862
|
+
let minX = Number.POSITIVE_INFINITY, minY = Number.POSITIVE_INFINITY, minZ = Number.POSITIVE_INFINITY, maxX = Number.NEGATIVE_INFINITY, maxY = Number.NEGATIVE_INFINITY, maxZ = Number.NEGATIVE_INFINITY;
|
|
1863
|
+
for (let i = 0, end = position.count * 3; i < end; i += 3) {
|
|
1864
|
+
const x = array[i], y = array[i + 1], z = array[i + 2];
|
|
1865
|
+
if (x < minX) minX = x;
|
|
1866
|
+
if (x > maxX) maxX = x;
|
|
1867
|
+
if (y < minY) minY = y;
|
|
1868
|
+
if (y > maxY) maxY = y;
|
|
1869
|
+
if (z < minZ) minZ = z;
|
|
1870
|
+
if (z > maxZ) maxZ = z;
|
|
1871
|
+
}
|
|
1872
|
+
geometry.boundingBox = new THREE.Box3(new THREE.Vector3(minX, minY, minZ), new THREE.Vector3(maxX, maxY, maxZ));
|
|
1873
|
+
return geometry.boundingBox;
|
|
1874
|
+
}
|
|
1504
1875
|
const BOX_FACES = [
|
|
1505
1876
|
[
|
|
1506
1877
|
0,
|
|
@@ -1600,6 +1971,8 @@ const FLOOR_NORMAL = Math.cos(Math.PI / 3.6);
|
|
|
1600
1971
|
* terrain pauses movement (it is never a bottomless pit) until coverage arrives.
|
|
1601
1972
|
*/
|
|
1602
1973
|
var WalkController = class {
|
|
1974
|
+
/** Four times walking/running speed; jump height and look response stay normal. */
|
|
1975
|
+
boostMode = false;
|
|
1603
1976
|
feet = new THREE.Vector3();
|
|
1604
1977
|
velocity = new THREE.Vector3();
|
|
1605
1978
|
grounded = false;
|
|
@@ -1617,8 +1990,11 @@ var WalkController = class {
|
|
|
1617
1990
|
this.accumulator = 0;
|
|
1618
1991
|
this.jumpHeld = false;
|
|
1619
1992
|
}
|
|
1620
|
-
/**
|
|
1621
|
-
|
|
1993
|
+
/**
|
|
1994
|
+
* Find supported open ground. A separate `groundCollision` can exclude vehicles from the
|
|
1995
|
+
* landing ray while `collision` still rejects body overlaps, placing people beside cars.
|
|
1996
|
+
*/
|
|
1997
|
+
place(collision, sampleHeight, groundCollision = collision) {
|
|
1622
1998
|
const centerX = this.feet.x;
|
|
1623
1999
|
const centerZ = this.feet.z;
|
|
1624
2000
|
for (let ring = 0; ring <= PLACEMENT_RINGS; ring++) {
|
|
@@ -1628,8 +2004,8 @@ var WalkController = class {
|
|
|
1628
2004
|
const z = centerZ + Math.sin(i / count * Math.PI * 2) * ring * PLACEMENT_RING_SPACING;
|
|
1629
2005
|
const ground = sampleHeight(x, z);
|
|
1630
2006
|
if (ground === void 0) continue;
|
|
1631
|
-
const ray = new THREE.Ray(new THREE.Vector3(x -
|
|
1632
|
-
const hit =
|
|
2007
|
+
const ray = new THREE.Ray(new THREE.Vector3(x - groundCollision.origin.x, ground + 1e4, z - groundCollision.origin.z), new THREE.Vector3(0, -1, 0));
|
|
2008
|
+
const hit = groundCollision.octree.rayIntersect(ray);
|
|
1633
2009
|
if (!hit || hit.position.y > ground + 3) continue;
|
|
1634
2010
|
this.feet.set(x, hit.position.y + .02, z);
|
|
1635
2011
|
this.setCapsule(collision);
|
|
@@ -1661,7 +2037,7 @@ var WalkController = class {
|
|
|
1661
2037
|
this.grounded = false;
|
|
1662
2038
|
}
|
|
1663
2039
|
const length = Math.max(1, Math.hypot(input.forward, input.right));
|
|
1664
|
-
const speed = input.sprint ? 4 : WALK_SPEED;
|
|
2040
|
+
const speed = (input.sprint ? 4 : WALK_SPEED) * boostSpeedMultiplier(this.boostMode);
|
|
1665
2041
|
const vx = (Math.cos(input.yaw) * input.forward - Math.sin(input.yaw) * input.right) / length * speed;
|
|
1666
2042
|
const vz = (Math.sin(input.yaw) * input.forward + Math.cos(input.yaw) * input.right) / length * speed;
|
|
1667
2043
|
this.accumulator += Math.min(.1, Math.max(0, dt));
|
|
@@ -1711,4 +2087,4 @@ var WalkController = class {
|
|
|
1711
2087
|
}
|
|
1712
2088
|
};
|
|
1713
2089
|
//#endregion
|
|
1714
|
-
export { CollisionTree, FlyController, FollowController, MAX_LOOK_PITCH, NAVIGATION_ACTIONS, NavigationInputSource, NavigationPointer, OrbitController, RUN_SPEED, TouchStick, WALK_EYE_HEIGHT, WALK_PLACEMENT_RADIUS, WALK_SPEED, WalkCollision, WalkController, applyCameraLookDelta, cameraForward, cameraPlanarForward, cameraRight, createTouchJoystick, idleNavigationInput, navigationInputProfiles, orientationFromDirection, viewNeedsImmediateUpdate };
|
|
2090
|
+
export { CollisionTree, FlyController, FollowController, MAX_LOOK_PITCH, NAVIGATION_ACTIONS, NavigationInputSource, NavigationPointer, OrbitController, RUN_SPEED, TouchStick, WALK_EYE_HEIGHT, WALK_PLACEMENT_RADIUS, WALK_SPEED, WalkCollision, WalkController, applyCameraLookDelta, cameraForward, cameraPlanarForward, cameraRight, createNavigationControls, createTouchJoystick, idleNavigationInput, navigationInputProfiles, orientationFromDirection, viewNeedsImmediateUpdate };
|