@playcanvas/supersplat-viewer 1.22.0 → 1.22.2
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/index.js +3 -3
- package/package.json +1 -1
- package/public/index.css +90 -29
- package/public/index.html +99 -27
- package/public/index.js +1364 -1045
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -19534,11 +19534,11 @@ const tmpMat4 = new Mat4();
|
|
|
19534
19534
|
const tmpQuat = new Quat();
|
|
19535
19535
|
const position = new Vec3();
|
|
19536
19536
|
const invParentWtm = new Mat4();
|
|
19537
|
-
const rotation$
|
|
19537
|
+
const rotation$4 = new Quat();
|
|
19538
19538
|
const invParentRot = new Quat();
|
|
19539
19539
|
const matrix = new Mat4();
|
|
19540
19540
|
const target = new Vec3();
|
|
19541
|
-
const up$
|
|
19541
|
+
const up$2 = new Vec3();
|
|
19542
19542
|
function createTest(attr, value) {
|
|
19543
19543
|
if (attr instanceof Function) {
|
|
19544
19544
|
return attr;
|
|
@@ -19908,16 +19908,16 @@ class GraphNode extends EventHandler {
|
|
|
19908
19908
|
}
|
|
19909
19909
|
setRotation(x, y, z, w) {
|
|
19910
19910
|
if (x instanceof Quat) {
|
|
19911
|
-
rotation$
|
|
19911
|
+
rotation$4.copy(x);
|
|
19912
19912
|
} else {
|
|
19913
|
-
rotation$
|
|
19913
|
+
rotation$4.set(x, y, z, w);
|
|
19914
19914
|
}
|
|
19915
19915
|
if (this._parent === null) {
|
|
19916
|
-
this.localRotation.copy(rotation$
|
|
19916
|
+
this.localRotation.copy(rotation$4);
|
|
19917
19917
|
} else {
|
|
19918
19918
|
const parentRot = this._parent.getRotation();
|
|
19919
19919
|
invParentRot.copy(parentRot).invert();
|
|
19920
|
-
this.localRotation.copy(invParentRot).mul(rotation$
|
|
19920
|
+
this.localRotation.copy(invParentRot).mul(rotation$4);
|
|
19921
19921
|
}
|
|
19922
19922
|
if (!this._dirtyLocal) {
|
|
19923
19923
|
this._dirtifyLocal();
|
|
@@ -20071,19 +20071,19 @@ class GraphNode extends EventHandler {
|
|
|
20071
20071
|
if (x instanceof Vec3) {
|
|
20072
20072
|
target.copy(x);
|
|
20073
20073
|
if (y instanceof Vec3) {
|
|
20074
|
-
up$
|
|
20074
|
+
up$2.copy(y);
|
|
20075
20075
|
} else {
|
|
20076
|
-
up$
|
|
20076
|
+
up$2.copy(Vec3.UP);
|
|
20077
20077
|
}
|
|
20078
20078
|
} else if (z === undefined) {
|
|
20079
20079
|
return;
|
|
20080
20080
|
} else {
|
|
20081
20081
|
target.set(x, y, z);
|
|
20082
|
-
up$
|
|
20082
|
+
up$2.set(ux, uy, uz);
|
|
20083
20083
|
}
|
|
20084
|
-
matrix.setLookAt(this.getPosition(), target, up$
|
|
20085
|
-
rotation$
|
|
20086
|
-
this.setRotation(rotation$
|
|
20084
|
+
matrix.setLookAt(this.getPosition(), target, up$2);
|
|
20085
|
+
rotation$4.setFromMat4(matrix);
|
|
20086
|
+
this.setRotation(rotation$4);
|
|
20087
20087
|
}
|
|
20088
20088
|
translate(x, y, z) {
|
|
20089
20089
|
if (x instanceof Vec3) {
|
|
@@ -20107,23 +20107,23 @@ class GraphNode extends EventHandler {
|
|
|
20107
20107
|
}
|
|
20108
20108
|
}
|
|
20109
20109
|
rotate(x, y, z) {
|
|
20110
|
-
rotation$
|
|
20110
|
+
rotation$4.setFromEulerAngles(x, y, z);
|
|
20111
20111
|
if (this._parent === null) {
|
|
20112
|
-
this.localRotation.mul2(rotation$
|
|
20112
|
+
this.localRotation.mul2(rotation$4, this.localRotation);
|
|
20113
20113
|
} else {
|
|
20114
20114
|
const rot = this.getRotation();
|
|
20115
20115
|
const parentRot = this._parent.getRotation();
|
|
20116
20116
|
invParentRot.copy(parentRot).invert();
|
|
20117
|
-
rotation$
|
|
20118
|
-
this.localRotation.mul2(rotation$
|
|
20117
|
+
rotation$4.mul2(invParentRot, rotation$4);
|
|
20118
|
+
this.localRotation.mul2(rotation$4, rot);
|
|
20119
20119
|
}
|
|
20120
20120
|
if (!this._dirtyLocal) {
|
|
20121
20121
|
this._dirtifyLocal();
|
|
20122
20122
|
}
|
|
20123
20123
|
}
|
|
20124
20124
|
rotateLocal(x, y, z) {
|
|
20125
|
-
rotation$
|
|
20126
|
-
this.localRotation.mul(rotation$
|
|
20125
|
+
rotation$4.setFromEulerAngles(x, y, z);
|
|
20126
|
+
this.localRotation.mul(rotation$4);
|
|
20127
20127
|
if (!this._dirtyLocal) {
|
|
20128
20128
|
this._dirtifyLocal();
|
|
20129
20129
|
}
|
|
@@ -33143,7 +33143,7 @@ class CustomRenderPass extends RenderPass {
|
|
|
33143
33143
|
}
|
|
33144
33144
|
}
|
|
33145
33145
|
const invModelMat$1 = new Mat4();
|
|
33146
|
-
const dir = new Vec3();
|
|
33146
|
+
const dir$1 = new Vec3();
|
|
33147
33147
|
class GSplatResolveSH {
|
|
33148
33148
|
destroy() {
|
|
33149
33149
|
const { gsplatInstance } = this;
|
|
@@ -33165,17 +33165,17 @@ class GSplatResolveSH {
|
|
|
33165
33165
|
return;
|
|
33166
33166
|
}
|
|
33167
33167
|
invModelMat$1.invert(modelMat);
|
|
33168
|
-
invModelMat$1.transformVector(camera.forward, dir);
|
|
33169
|
-
dir.normalize();
|
|
33170
|
-
if (updateMode === 'enable' && dir.equalsApprox(prevDir, 1e-3)) {
|
|
33168
|
+
invModelMat$1.transformVector(camera.forward, dir$1);
|
|
33169
|
+
dir$1.normalize();
|
|
33170
|
+
if (updateMode === 'enable' && dir$1.equalsApprox(prevDir, 1e-3)) {
|
|
33171
33171
|
return;
|
|
33172
33172
|
}
|
|
33173
|
-
prevDir.copy(dir);
|
|
33173
|
+
prevDir.copy(dir$1);
|
|
33174
33174
|
const execute = ()=>{
|
|
33175
33175
|
const { device } = this;
|
|
33176
33176
|
const { sh_centroids, meta } = this.gsplatInstance.resource.gsplatData;
|
|
33177
33177
|
resolve$1(device.scope, {
|
|
33178
|
-
dir: dir.toArray(),
|
|
33178
|
+
dir: dir$1.toArray(),
|
|
33179
33179
|
centroids: sh_centroids,
|
|
33180
33180
|
shN_mins: meta.shN.mins,
|
|
33181
33181
|
shN_maxs: meta.shN.maxs
|
|
@@ -73163,6 +73163,73 @@ class CameraFrame {
|
|
|
73163
73163
|
}
|
|
73164
73164
|
}
|
|
73165
73165
|
|
|
73166
|
+
const tmpV1$1 = new Vec3();
|
|
73167
|
+
const rotation$3 = new Quat();
|
|
73168
|
+
class Pose {
|
|
73169
|
+
copy(other) {
|
|
73170
|
+
return this.set(other.position, other.angles, other.distance);
|
|
73171
|
+
}
|
|
73172
|
+
clone() {
|
|
73173
|
+
return new Pose(this.position.clone(), this.angles.clone(), this.distance);
|
|
73174
|
+
}
|
|
73175
|
+
equalsApprox(other, epsilon = 1e-6) {
|
|
73176
|
+
return this.position.equalsApprox(other.position, epsilon) && this.angles.equalsApprox(other.angles, epsilon) && Math.abs(this.distance - other.distance) < epsilon;
|
|
73177
|
+
}
|
|
73178
|
+
lerp(lhs, rhs, alpha1, alpha2 = alpha1, alpha3 = alpha1) {
|
|
73179
|
+
this.position.lerp(lhs.position, rhs.position, alpha1);
|
|
73180
|
+
this.angles.x = math.lerpAngle(lhs.angles.x, rhs.angles.x, alpha2) % 360;
|
|
73181
|
+
this.angles.y = math.lerpAngle(lhs.angles.y, rhs.angles.y, alpha2) % 360;
|
|
73182
|
+
this.angles.z = math.lerpAngle(lhs.angles.z, rhs.angles.z, alpha2) % 360;
|
|
73183
|
+
this.distance = math.lerp(lhs.distance, rhs.distance, alpha3);
|
|
73184
|
+
return this;
|
|
73185
|
+
}
|
|
73186
|
+
move(offset) {
|
|
73187
|
+
this.position.add(offset);
|
|
73188
|
+
this.position.x = math.clamp(this.position.x, this.xRange.x, this.xRange.y);
|
|
73189
|
+
this.position.y = math.clamp(this.position.y, this.yRange.x, this.yRange.y);
|
|
73190
|
+
this.position.z = math.clamp(this.position.z, this.zRange.x, this.zRange.y);
|
|
73191
|
+
return this;
|
|
73192
|
+
}
|
|
73193
|
+
rotate(euler) {
|
|
73194
|
+
this.angles.add(euler);
|
|
73195
|
+
this.angles.x %= 360;
|
|
73196
|
+
this.angles.y %= 360;
|
|
73197
|
+
this.angles.z %= 360;
|
|
73198
|
+
this.angles.x = math.clamp(this.angles.x, this.pitchRange.x, this.pitchRange.y);
|
|
73199
|
+
this.angles.y = math.clamp(this.angles.y, this.yawRange.x, this.yawRange.y);
|
|
73200
|
+
return this;
|
|
73201
|
+
}
|
|
73202
|
+
set(position, angles, distance) {
|
|
73203
|
+
this.position.copy(position);
|
|
73204
|
+
this.angles.copy(angles);
|
|
73205
|
+
this.distance = distance;
|
|
73206
|
+
return this;
|
|
73207
|
+
}
|
|
73208
|
+
look(from, to) {
|
|
73209
|
+
this.position.copy(from);
|
|
73210
|
+
this.distance = from.distance(to);
|
|
73211
|
+
const dir = tmpV1$1.sub2(to, from).normalize();
|
|
73212
|
+
const elev = Math.atan2(-dir.y, Math.sqrt(dir.x * dir.x + dir.z * dir.z)) * math.RAD_TO_DEG;
|
|
73213
|
+
const azim = Math.atan2(-dir.x, -dir.z) * math.RAD_TO_DEG;
|
|
73214
|
+
this.angles.set(-elev, azim, 0);
|
|
73215
|
+
return this;
|
|
73216
|
+
}
|
|
73217
|
+
getFocus(out) {
|
|
73218
|
+
return rotation$3.setFromEulerAngles(this.angles).transformVector(Vec3.FORWARD, out).mulScalar(this.distance).add(this.position);
|
|
73219
|
+
}
|
|
73220
|
+
constructor(position = Vec3.ZERO, angles = Vec3.ZERO, distance = 0){
|
|
73221
|
+
this.position = new Vec3();
|
|
73222
|
+
this.angles = new Vec3();
|
|
73223
|
+
this.distance = 0;
|
|
73224
|
+
this.pitchRange = new Vec2(-Infinity, Infinity);
|
|
73225
|
+
this.yawRange = new Vec2(-Infinity, Infinity);
|
|
73226
|
+
this.xRange = new Vec2(-Infinity, Infinity);
|
|
73227
|
+
this.yRange = new Vec2(-Infinity, Infinity);
|
|
73228
|
+
this.zRange = new Vec2(-Infinity, Infinity);
|
|
73229
|
+
this.set(position, angles, distance);
|
|
73230
|
+
}
|
|
73231
|
+
}
|
|
73232
|
+
|
|
73166
73233
|
class InputDelta {
|
|
73167
73234
|
add(other) {
|
|
73168
73235
|
for(let i = 0; i < this._value.length; i++){
|
|
@@ -73248,6 +73315,25 @@ class InputSource extends InputFrame {
|
|
|
73248
73315
|
super(...args), this._element = null, this._events = new EventHandler();
|
|
73249
73316
|
}
|
|
73250
73317
|
}
|
|
73318
|
+
class InputConsumer {
|
|
73319
|
+
update(frame, dt) {
|
|
73320
|
+
frame.read();
|
|
73321
|
+
}
|
|
73322
|
+
}
|
|
73323
|
+
let InputController$1 = class InputController extends InputConsumer {
|
|
73324
|
+
attach(pose, smooth = true) {}
|
|
73325
|
+
detach() {}
|
|
73326
|
+
update(frame, dt) {
|
|
73327
|
+
super.update(frame, dt);
|
|
73328
|
+
return this._pose;
|
|
73329
|
+
}
|
|
73330
|
+
destroy() {
|
|
73331
|
+
this.detach();
|
|
73332
|
+
}
|
|
73333
|
+
constructor(...args){
|
|
73334
|
+
super(...args), this._pose = new Pose();
|
|
73335
|
+
}
|
|
73336
|
+
};
|
|
73251
73337
|
|
|
73252
73338
|
const movementState = ()=>{
|
|
73253
73339
|
const state = new Map();
|
|
@@ -73281,6 +73367,8 @@ const movementState = ()=>{
|
|
|
73281
73367
|
};
|
|
73282
73368
|
};
|
|
73283
73369
|
|
|
73370
|
+
const damp$1 = (damping, dt)=>1 - Math.pow(damping, dt * 1000);
|
|
73371
|
+
|
|
73284
73372
|
const BUTTON_CODES = {
|
|
73285
73373
|
A: 0,
|
|
73286
73374
|
B: 1,
|
|
@@ -74736,6 +74824,65 @@ class MultiTouchSource extends InputSource {
|
|
|
74736
74824
|
}
|
|
74737
74825
|
}
|
|
74738
74826
|
|
|
74827
|
+
const dir = new Vec3();
|
|
74828
|
+
const offset$2 = new Vec3();
|
|
74829
|
+
const angles = new Vec3();
|
|
74830
|
+
const rotation$2 = new Quat();
|
|
74831
|
+
let OrbitController$1 = class OrbitController extends InputController$1 {
|
|
74832
|
+
set pitchRange(range) {
|
|
74833
|
+
this._targetRootPose.pitchRange.copy(range);
|
|
74834
|
+
this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
|
|
74835
|
+
}
|
|
74836
|
+
get pitchRange() {
|
|
74837
|
+
return this._targetRootPose.pitchRange;
|
|
74838
|
+
}
|
|
74839
|
+
set yawRange(range) {
|
|
74840
|
+
this._targetRootPose.yawRange.copy(range);
|
|
74841
|
+
this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
|
|
74842
|
+
}
|
|
74843
|
+
get yawRange() {
|
|
74844
|
+
return this._targetRootPose.yawRange;
|
|
74845
|
+
}
|
|
74846
|
+
set zoomRange(range) {
|
|
74847
|
+
this._targetChildPose.zRange.copy(range);
|
|
74848
|
+
this._childPose.copy(this._targetChildPose.move(Vec3.ZERO));
|
|
74849
|
+
}
|
|
74850
|
+
get zoomRange() {
|
|
74851
|
+
return this._targetRootPose.zRange;
|
|
74852
|
+
}
|
|
74853
|
+
attach(pose, smooth = true) {
|
|
74854
|
+
this._targetRootPose.set(pose.getFocus(dir), pose.angles, 0);
|
|
74855
|
+
this._targetChildPose.position.set(0, 0, pose.distance);
|
|
74856
|
+
if (!smooth) {
|
|
74857
|
+
this._rootPose.copy(this._targetRootPose);
|
|
74858
|
+
this._childPose.copy(this._targetChildPose);
|
|
74859
|
+
}
|
|
74860
|
+
}
|
|
74861
|
+
detach() {
|
|
74862
|
+
this._targetRootPose.copy(this._rootPose);
|
|
74863
|
+
this._targetChildPose.copy(this._childPose);
|
|
74864
|
+
}
|
|
74865
|
+
update(frame, dt) {
|
|
74866
|
+
const { move, rotate } = frame.read();
|
|
74867
|
+
offset$2.set(move[0], move[1], 0);
|
|
74868
|
+
rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(offset$2, offset$2);
|
|
74869
|
+
this._targetRootPose.move(offset$2);
|
|
74870
|
+
const { z: dist } = this._targetChildPose.position;
|
|
74871
|
+
this._targetChildPose.move(offset$2.set(0, 0, dist * (1 + move[2]) - dist));
|
|
74872
|
+
this._targetRootPose.rotate(angles.set(-rotate[1], -rotate[0], 0));
|
|
74873
|
+
this._rootPose.lerp(this._rootPose, this._targetRootPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt), 1);
|
|
74874
|
+
this._childPose.lerp(this._childPose, this._targetChildPose, damp$1(this.zoomDamping, dt), 1, 1);
|
|
74875
|
+
rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(this._childPose.position, offset$2).add(this._rootPose.position);
|
|
74876
|
+
return this._pose.set(offset$2, this._rootPose.angles, this._childPose.position.z);
|
|
74877
|
+
}
|
|
74878
|
+
destroy() {
|
|
74879
|
+
this.detach();
|
|
74880
|
+
}
|
|
74881
|
+
constructor(...args){
|
|
74882
|
+
super(...args), this._targetRootPose = new Pose(), this._rootPose = new Pose(), this._targetChildPose = new Pose(), this._childPose = new Pose(), this.rotateDamping = 0.98, this.moveDamping = 0.98, this.zoomDamping = 0.98;
|
|
74883
|
+
}
|
|
74884
|
+
};
|
|
74885
|
+
|
|
74739
74886
|
class App extends AppBase {
|
|
74740
74887
|
constructor(canvas, options) {
|
|
74741
74888
|
super(canvas);
|
|
@@ -76433,6 +76580,8 @@ const importSettings = (settings) => {
|
|
|
76433
76580
|
return result;
|
|
76434
76581
|
};
|
|
76435
76582
|
|
|
76583
|
+
var version = "1.22.2";
|
|
76584
|
+
|
|
76436
76585
|
class Tooltip {
|
|
76437
76586
|
register;
|
|
76438
76587
|
unregister;
|
|
@@ -76714,7 +76863,7 @@ const initUI = (global) => {
|
|
|
76714
76863
|
'orbitCamera', 'flyCamera', 'fpsCamera',
|
|
76715
76864
|
'performanceModeRow', 'performanceModeCheck', 'performanceModeOption',
|
|
76716
76865
|
'gamingControlsDivider', 'gamingControlsRow', 'gamingControlsCheck', 'gamingControlsOption',
|
|
76717
|
-
'desktopFlyClickToFly', 'desktopClickToWalk', 'desktopGamingControls',
|
|
76866
|
+
'desktopFlyClickToFly', 'desktopFlyGamingControls', 'desktopClickToWalk', 'desktopGamingControls',
|
|
76718
76867
|
'touchFlyClickToWalk', 'touchFlyGamingControls',
|
|
76719
76868
|
'touchClickToWalk', 'touchGamingControls',
|
|
76720
76869
|
'walkHint',
|
|
@@ -76724,11 +76873,13 @@ const initUI = (global) => {
|
|
|
76724
76873
|
'showCollision',
|
|
76725
76874
|
'tooltip',
|
|
76726
76875
|
'annotationNav', 'annotationPrev', 'annotationNext', 'annotationInfo', 'annotationNavTitle',
|
|
76727
|
-
'
|
|
76876
|
+
'viewerBranding', 'viewerTitle', 'appVersionLabel'
|
|
76728
76877
|
].reduce((acc, id) => {
|
|
76729
76878
|
acc[id] = document.getElementById(id);
|
|
76730
76879
|
return acc;
|
|
76731
76880
|
}, {});
|
|
76881
|
+
// populate the info-panel title with the app version
|
|
76882
|
+
dom.appVersionLabel.textContent = version;
|
|
76732
76883
|
// Remove focus from buttons after click so keyboard input isn't captured by the UI
|
|
76733
76884
|
dom.ui.addEventListener('click', () => {
|
|
76734
76885
|
document.activeElement?.blur();
|
|
@@ -76833,6 +76984,7 @@ const initUI = (global) => {
|
|
|
76833
76984
|
const updateGamingControls = () => {
|
|
76834
76985
|
dom.gamingControlsCheck.classList.toggle('active', state.gamingControls);
|
|
76835
76986
|
dom.desktopFlyClickToFly.classList.toggle('hidden', state.gamingControls);
|
|
76987
|
+
dom.desktopFlyGamingControls.classList.toggle('hidden', !state.gamingControls);
|
|
76836
76988
|
dom.desktopClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
76837
76989
|
dom.desktopGamingControls.classList.toggle('hidden', !state.gamingControls);
|
|
76838
76990
|
dom.touchFlyClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
@@ -77137,8 +77289,9 @@ const initUI = (global) => {
|
|
|
77137
77289
|
if (viewUrl.pathname === '/s') {
|
|
77138
77290
|
viewUrl.pathname = '/view';
|
|
77139
77291
|
}
|
|
77140
|
-
dom.
|
|
77141
|
-
dom.
|
|
77292
|
+
dom.viewerBranding.href = viewUrl.toString();
|
|
77293
|
+
dom.viewerBranding.classList.remove('hidden');
|
|
77294
|
+
dom.viewerTitle.href = viewUrl.toString();
|
|
77142
77295
|
}
|
|
77143
77296
|
};
|
|
77144
77297
|
|
|
@@ -78219,31 +78372,6 @@ const setBasisOffset = (out, x, y, z, forward, right, up) => {
|
|
|
78219
78372
|
out.set(right.x * x + up.x * y + forward.x * z, right.y * x + up.y * y + forward.y * z, right.z * x + up.z * y + forward.z * z);
|
|
78220
78373
|
return out;
|
|
78221
78374
|
};
|
|
78222
|
-
/**
|
|
78223
|
-
* Interpolate Euler angles using shortest-path angle interpolation.
|
|
78224
|
-
*
|
|
78225
|
-
* @param result - Receives the interpolated angles.
|
|
78226
|
-
* @param a - Start angles.
|
|
78227
|
-
* @param b - End angles.
|
|
78228
|
-
* @param t - Interpolation factor.
|
|
78229
|
-
* @returns The mutated result.
|
|
78230
|
-
*/
|
|
78231
|
-
const lerpAngles = (result, a, b, t) => {
|
|
78232
|
-
result.x = math.lerpAngle(a.x, b.x, t) % 360;
|
|
78233
|
-
result.y = math.lerpAngle(a.y, b.y, t) % 360;
|
|
78234
|
-
result.z = math.lerpAngle(a.z, b.z, t) % 360;
|
|
78235
|
-
return result;
|
|
78236
|
-
};
|
|
78237
|
-
/**
|
|
78238
|
-
* Convert a damping value to a frame-rate-independent interpolation alpha.
|
|
78239
|
-
*
|
|
78240
|
-
* @param damping - Damping factor.
|
|
78241
|
-
* @param dt - Delta time in seconds.
|
|
78242
|
-
* @returns Interpolation alpha for this frame.
|
|
78243
|
-
*/
|
|
78244
|
-
const dampAlpha = (damping, dt) => {
|
|
78245
|
-
return dt > 0 ? damp(damping, dt) : 0;
|
|
78246
|
-
};
|
|
78247
78375
|
|
|
78248
78376
|
/** Extra resolve passes above the collider's internal iteration for tight corners */
|
|
78249
78377
|
const MAX_COLLISION_PASSES = 4;
|
|
@@ -78264,7 +78392,7 @@ const SWEEP_RAY_OFFSETS = [
|
|
|
78264
78392
|
[-INV_SQRT2, -INV_SQRT2, false],
|
|
78265
78393
|
[INV_SQRT2, -INV_SQRT2, false]
|
|
78266
78394
|
];
|
|
78267
|
-
const v$
|
|
78395
|
+
const v$2 = new Vec3();
|
|
78268
78396
|
const remainingMove = new Vec3();
|
|
78269
78397
|
const collisionPush = new Vec3();
|
|
78270
78398
|
const sweepDir = new Vec3();
|
|
@@ -78338,10 +78466,10 @@ class SphereMover {
|
|
|
78338
78466
|
this.resolve(position);
|
|
78339
78467
|
return false;
|
|
78340
78468
|
}
|
|
78341
|
-
position.add(v$
|
|
78469
|
+
position.add(v$2.copy(sweepDir).mulScalar(sweepHit.travel));
|
|
78342
78470
|
this.resolve(position);
|
|
78343
78471
|
sweepNormal.set(sweepHit.nx, sweepHit.ny, sweepHit.nz);
|
|
78344
|
-
move.add(v$
|
|
78472
|
+
move.add(v$2.copy(sweepDir).mulScalar(-sweepHit.travel));
|
|
78345
78473
|
this._clipMove(move, sweepNormal);
|
|
78346
78474
|
return true;
|
|
78347
78475
|
}
|
|
@@ -78361,8 +78489,8 @@ class SphereMover {
|
|
|
78361
78489
|
const rayExtension = centerRay ? this.radius : 0;
|
|
78362
78490
|
sweepOrigin.copy(position);
|
|
78363
78491
|
if (!centerRay) {
|
|
78364
|
-
sweepOrigin.add(v$
|
|
78365
|
-
sweepOrigin.add(v$
|
|
78492
|
+
sweepOrigin.add(v$2.copy(sweepTangent).mulScalar(tx * radiusOffset));
|
|
78493
|
+
sweepOrigin.add(v$2.copy(sweepBitangent).mulScalar(ty * radiusOffset));
|
|
78366
78494
|
}
|
|
78367
78495
|
const hit = this.collision.queryRay(sweepOrigin.x, sweepOrigin.y, sweepOrigin.z, dir.x, dir.y, dir.z, distance + rayExtension + COLLISION_SKIN);
|
|
78368
78496
|
if (!hit) {
|
|
@@ -78437,9 +78565,9 @@ class SphereMover {
|
|
|
78437
78565
|
|
|
78438
78566
|
/** Radius of the camera collision sphere (meters) */
|
|
78439
78567
|
const CAMERA_RADIUS = 0.2;
|
|
78440
|
-
const forward$
|
|
78441
|
-
const right$
|
|
78442
|
-
const up$
|
|
78568
|
+
const forward$2 = new Vec3();
|
|
78569
|
+
const right$2 = new Vec3();
|
|
78570
|
+
const up$1 = new Vec3();
|
|
78443
78571
|
const offset$1 = new Vec3();
|
|
78444
78572
|
class FlyController {
|
|
78445
78573
|
fov = 90;
|
|
@@ -78502,8 +78630,8 @@ class FlyController {
|
|
|
78502
78630
|
this._hasSpawn = true;
|
|
78503
78631
|
}
|
|
78504
78632
|
_step(move) {
|
|
78505
|
-
setCameraBasis(this._angles, forward$
|
|
78506
|
-
setBasisOffset(offset$1, move[0], move[1], move[2], forward$
|
|
78633
|
+
setCameraBasis(this._angles, forward$2, right$2, up$1);
|
|
78634
|
+
setBasisOffset(offset$1, move[0], move[1], move[2], forward$2, right$2, up$1);
|
|
78507
78635
|
this._mover.move(this._position, offset$1);
|
|
78508
78636
|
}
|
|
78509
78637
|
}
|
|
@@ -78588,7 +78716,7 @@ const BLOCKED_SPEED$1 = 0.25;
|
|
|
78588
78716
|
/** Seconds of continuous low-progress before stopping the flight */
|
|
78589
78717
|
const BLOCKED_DURATION$1 = 0.5;
|
|
78590
78718
|
const toTarget = new Vec3();
|
|
78591
|
-
const forward$
|
|
78719
|
+
const forward$1 = new Vec3();
|
|
78592
78720
|
const postTurnAngles = new Vec3();
|
|
78593
78721
|
const getStopDistance = (fov) => {
|
|
78594
78722
|
const halfFov = math.clamp(fov, 15, 120) * DEG_TO_RAD * 0.5;
|
|
@@ -78627,20 +78755,24 @@ class FlySource {
|
|
|
78627
78755
|
_pitchRate = 0;
|
|
78628
78756
|
_speed = 0;
|
|
78629
78757
|
_progress = new ProgressTracker();
|
|
78630
|
-
|
|
78758
|
+
_speedMul = 1;
|
|
78759
|
+
get isActive() {
|
|
78631
78760
|
return this._target !== null;
|
|
78632
78761
|
}
|
|
78633
78762
|
/**
|
|
78634
78763
|
* Begin auto-flying toward a world-space target position.
|
|
78635
78764
|
*
|
|
78636
78765
|
* @param target - The destination.
|
|
78766
|
+
* @param speedMul - Forward-speed multiplier (mirrors gaming-controls
|
|
78767
|
+
* shift/ctrl: 4 for boost, 0.25 for slow). Defaults to 1.
|
|
78637
78768
|
*/
|
|
78638
|
-
|
|
78769
|
+
navigateTo(target, speedMul = 1) {
|
|
78639
78770
|
const wasFlying = this._target !== null;
|
|
78640
78771
|
if (!this._target) {
|
|
78641
78772
|
this._target = new Vec3();
|
|
78642
78773
|
}
|
|
78643
78774
|
this._target.copy(target);
|
|
78775
|
+
this._speedMul = speedMul;
|
|
78644
78776
|
if (!wasFlying) {
|
|
78645
78777
|
this._yawRate = 0;
|
|
78646
78778
|
this._pitchRate = 0;
|
|
@@ -78651,7 +78783,7 @@ class FlySource {
|
|
|
78651
78783
|
/**
|
|
78652
78784
|
* Cancel any active auto-flight.
|
|
78653
78785
|
*/
|
|
78654
|
-
|
|
78786
|
+
cancel() {
|
|
78655
78787
|
if (this._target) {
|
|
78656
78788
|
this._target = null;
|
|
78657
78789
|
this._yawRate = 0;
|
|
@@ -78666,22 +78798,22 @@ class FlySource {
|
|
|
78666
78798
|
* the camera controller reads the frame.
|
|
78667
78799
|
*
|
|
78668
78800
|
* @param dt - Frame delta time in seconds.
|
|
78669
|
-
* @param
|
|
78670
|
-
* @param cameraAngles - Camera Euler angles in degrees.
|
|
78671
|
-
* @param cameraFov - Camera vertical field-of-view in degrees.
|
|
78801
|
+
* @param camera - The current camera state (read-only).
|
|
78672
78802
|
* @param frame - The shared CameraFrame to append deltas to.
|
|
78673
78803
|
*/
|
|
78674
|
-
update(dt,
|
|
78804
|
+
update(dt, camera, frame) {
|
|
78675
78805
|
if (!this._target)
|
|
78676
78806
|
return;
|
|
78677
78807
|
const target = this._target;
|
|
78808
|
+
const cameraPosition = camera.position;
|
|
78809
|
+
const cameraAngles = camera.angles;
|
|
78678
78810
|
toTarget.sub2(target, cameraPosition);
|
|
78679
78811
|
const dist = toTarget.length();
|
|
78680
|
-
const stopDistance = getStopDistance(
|
|
78812
|
+
const stopDistance = getStopDistance(camera.fov);
|
|
78681
78813
|
const remainingDist = dist - stopDistance;
|
|
78682
78814
|
const activeRemainingDist = Math.max(0, remainingDist);
|
|
78683
78815
|
if (activeRemainingDist <= ARRIVAL_EPSILON && this._speed <= ARRIVAL_SPEED) {
|
|
78684
|
-
this.
|
|
78816
|
+
this.cancel();
|
|
78685
78817
|
return;
|
|
78686
78818
|
}
|
|
78687
78819
|
if (dt <= 0) {
|
|
@@ -78702,12 +78834,12 @@ class FlySource {
|
|
|
78702
78834
|
// FlyController applies: _angles += [-rotateY, -rotateX, 0]
|
|
78703
78835
|
frame.deltas.rotate.append([-yawStep, -pitchStep, 0]);
|
|
78704
78836
|
postTurnAngles.set(cameraAngles.x + pitchStep, cameraAngles.y + yawStep, 0);
|
|
78705
|
-
setCameraForward(postTurnAngles, forward$
|
|
78706
|
-
const alignment = math.clamp(forward$
|
|
78837
|
+
setCameraForward(postTurnAngles, forward$1);
|
|
78838
|
+
const alignment = math.clamp(forward$1.x * dirX + forward$1.y * dirY + forward$1.z * dirZ, 0, 1);
|
|
78707
78839
|
const alignmentScale = smoothstep(0.05, 0.95, alignment);
|
|
78708
78840
|
const brakeSpeed = Math.sqrt(2 * this.moveDeceleration * activeRemainingDist);
|
|
78709
78841
|
const arrivalSpeed = activeRemainingDist * ARRIVAL_RATE;
|
|
78710
|
-
const maxSpeed = Math.min(this.flySpeed, brakeSpeed, arrivalSpeed);
|
|
78842
|
+
const maxSpeed = Math.min(this.flySpeed * this._speedMul, brakeSpeed, arrivalSpeed);
|
|
78711
78843
|
if (maxSpeed > this._speed) {
|
|
78712
78844
|
this._speed = approach(this._speed, maxSpeed, this.moveAcceleration * alignmentScale * dt);
|
|
78713
78845
|
}
|
|
@@ -78722,72 +78854,146 @@ class FlySource {
|
|
|
78722
78854
|
// Only treat low progress as blocked once the camera is substantially
|
|
78723
78855
|
// facing the target; otherwise a large turn-in-place would cancel early.
|
|
78724
78856
|
if (this._progress.update(dist, dt, BLOCKED_SPEED$1, BLOCKED_DURATION$1, alignment > 0.5 && this._speed > BLOCKED_SPEED$1)) {
|
|
78725
|
-
this.
|
|
78857
|
+
this.cancel();
|
|
78726
78858
|
}
|
|
78727
78859
|
}
|
|
78728
78860
|
}
|
|
78729
78861
|
|
|
78730
|
-
const
|
|
78731
|
-
const MAX_DISTANCE = Infinity;
|
|
78732
|
-
const focus = new Vec3();
|
|
78733
|
-
const forward$1 = new Vec3();
|
|
78734
|
-
const right$2 = new Vec3();
|
|
78735
|
-
const up$1 = new Vec3();
|
|
78736
|
-
const pan = new Vec3();
|
|
78862
|
+
const p = new Pose();
|
|
78737
78863
|
class OrbitController {
|
|
78864
|
+
controller;
|
|
78738
78865
|
fov = 90;
|
|
78739
|
-
|
|
78740
|
-
|
|
78741
|
-
|
|
78742
|
-
|
|
78743
|
-
|
|
78744
|
-
|
|
78745
|
-
|
|
78746
|
-
|
|
78747
|
-
_targetDistance = 1;
|
|
78866
|
+
constructor() {
|
|
78867
|
+
this.controller = new OrbitController$1();
|
|
78868
|
+
this.controller.zoomRange = new Vec2(0.01, Infinity);
|
|
78869
|
+
this.controller.pitchRange = new Vec2(-90, 90);
|
|
78870
|
+
this.controller.rotateDamping = 0.97;
|
|
78871
|
+
this.controller.moveDamping = 0.97;
|
|
78872
|
+
this.controller.zoomDamping = 0.97;
|
|
78873
|
+
}
|
|
78748
78874
|
onEnter(camera) {
|
|
78749
|
-
this.
|
|
78875
|
+
this._attach(camera);
|
|
78750
78876
|
}
|
|
78751
78877
|
update(deltaTime, inputFrame, camera) {
|
|
78752
|
-
const
|
|
78753
|
-
|
|
78754
|
-
|
|
78755
|
-
|
|
78756
|
-
this._targetDistance = math.clamp(this._targetDistance * (1 + move[2]), MIN_DISTANCE, MAX_DISTANCE);
|
|
78757
|
-
applyFrameRotation(this._targetAngles, rotate);
|
|
78758
|
-
this._focus.lerp(this._focus, this._targetFocus, dampAlpha(this.moveDamping, deltaTime));
|
|
78759
|
-
lerpAngles(this._angles, this._angles, this._targetAngles, dampAlpha(this.rotateDamping, deltaTime));
|
|
78760
|
-
this._distance = math.lerp(this._distance, this._targetDistance, dampAlpha(this.zoomDamping, deltaTime));
|
|
78761
|
-
setCameraBasis(this._angles, forward$1, right$2, up$1);
|
|
78762
|
-
camera.position.copy(this._focus).sub(forward$1.mulScalar(this._distance));
|
|
78763
|
-
camera.angles.copy(this._angles);
|
|
78764
|
-
camera.distance = this._distance;
|
|
78878
|
+
const pose = this.controller.update(inputFrame, deltaTime);
|
|
78879
|
+
camera.position.copy(pose.position);
|
|
78880
|
+
camera.angles.copy(pose.angles);
|
|
78881
|
+
camera.distance = pose.distance;
|
|
78765
78882
|
camera.fov = this.fov;
|
|
78766
78883
|
}
|
|
78767
78884
|
onExit(_camera) {
|
|
78768
78885
|
}
|
|
78769
78886
|
goto(camera) {
|
|
78770
|
-
this.
|
|
78887
|
+
this.fov = camera.fov;
|
|
78888
|
+
this._attach(camera);
|
|
78771
78889
|
}
|
|
78772
|
-
|
|
78773
|
-
camera.
|
|
78774
|
-
|
|
78775
|
-
this.
|
|
78776
|
-
this.
|
|
78777
|
-
this._targetAngles.copy(camera.angles);
|
|
78778
|
-
this._distance = math.clamp(camera.distance, MIN_DISTANCE, MAX_DISTANCE);
|
|
78779
|
-
this._targetDistance = this._distance;
|
|
78780
|
-
if (copyFov) {
|
|
78781
|
-
this.fov = camera.fov;
|
|
78782
|
-
}
|
|
78890
|
+
_attach(camera) {
|
|
78891
|
+
p.position.copy(camera.position);
|
|
78892
|
+
p.angles.copy(camera.angles);
|
|
78893
|
+
p.distance = Math.max(camera.distance, this.controller.zoomRange.x);
|
|
78894
|
+
this.controller.attach(p, false);
|
|
78783
78895
|
}
|
|
78784
78896
|
}
|
|
78785
78897
|
|
|
78786
|
-
const FIXED_DT = 1 / 60;
|
|
78787
|
-
const MAX_SUBSTEPS = 10;
|
|
78788
78898
|
const SPAWN_HIT_EPSILON = 1e-3;
|
|
78789
78899
|
const SPAWN_SEARCH_MIN_STEP = 0.05;
|
|
78790
78900
|
const SPAWN_SEARCH_MAX_STEPS = 128;
|
|
78901
|
+
const out$1 = { x: 0, y: 0, z: 0 };
|
|
78902
|
+
const v$1 = new Vec3();
|
|
78903
|
+
const probe = new Vec3();
|
|
78904
|
+
const queryCapsule = (collision, pos, p) => {
|
|
78905
|
+
const half = p.capsuleHeight * 0.5 - p.capsuleRadius;
|
|
78906
|
+
const center = pos.y - p.eyeHeight + p.capsuleHeight * 0.5;
|
|
78907
|
+
return collision.queryCapsule(pos.x, center, pos.z, half, p.capsuleRadius, out$1);
|
|
78908
|
+
};
|
|
78909
|
+
const eyeYFromGround = (groundY, p) => groundY + p.hoverHeight + p.eyeHeight;
|
|
78910
|
+
const isInsideSolid = (collision, pos) => {
|
|
78911
|
+
return collision.querySphere(pos.x, pos.y, pos.z, SPAWN_HIT_EPSILON, out$1);
|
|
78912
|
+
};
|
|
78913
|
+
const probeGroundY = (collision, pos, p) => {
|
|
78914
|
+
const hit = collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, p.spawnSearchRange);
|
|
78915
|
+
return hit ? hit.y : null;
|
|
78916
|
+
};
|
|
78917
|
+
const hasSpawnGroundSupport = (collision, pos, p) => {
|
|
78918
|
+
const groundY = probeGroundY(collision, pos, p);
|
|
78919
|
+
if (groundY === null) {
|
|
78920
|
+
return false;
|
|
78921
|
+
}
|
|
78922
|
+
const clearance = pos.y - p.eyeHeight - groundY;
|
|
78923
|
+
return clearance >= -SPAWN_HIT_EPSILON &&
|
|
78924
|
+
clearance <= p.hoverHeight + p.capsuleRadius + SPAWN_HIT_EPSILON;
|
|
78925
|
+
};
|
|
78926
|
+
// Push a candidate eye position out of solid geometry. Returns true if the
|
|
78927
|
+
// candidate becomes clear within the allowed budget and remains supported by
|
|
78928
|
+
// ground beneath it.
|
|
78929
|
+
const resolveSpawnCandidate = (collision, pos, p) => {
|
|
78930
|
+
const startX = pos.x;
|
|
78931
|
+
const startY = pos.y;
|
|
78932
|
+
const startZ = pos.z;
|
|
78933
|
+
const maxResolveDistance = p.capsuleRadius + p.hoverHeight;
|
|
78934
|
+
const maxResolveDistanceSq = maxResolveDistance * maxResolveDistance;
|
|
78935
|
+
for (let i = 0; i < 100; i++) {
|
|
78936
|
+
if (!queryCapsule(collision, pos, p)) {
|
|
78937
|
+
return hasSpawnGroundSupport(collision, pos, p);
|
|
78938
|
+
}
|
|
78939
|
+
pos.add(v$1.set(out$1.x, out$1.y, out$1.z));
|
|
78940
|
+
const dx = pos.x - startX;
|
|
78941
|
+
const dy = pos.y - startY;
|
|
78942
|
+
const dz = pos.z - startZ;
|
|
78943
|
+
if (dx * dx + dy * dy + dz * dz > maxResolveDistanceSq) {
|
|
78944
|
+
return false;
|
|
78945
|
+
}
|
|
78946
|
+
}
|
|
78947
|
+
return false;
|
|
78948
|
+
};
|
|
78949
|
+
// Find the first collision surface below a point that can hold a clear walk
|
|
78950
|
+
// capsule. Writes the resolved eye position to outPos on success.
|
|
78951
|
+
const findClearSpawnGroundBelow = (collision, pos, range, allowInitialHit, p, outPos) => {
|
|
78952
|
+
const hit = collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, range);
|
|
78953
|
+
if (!hit) {
|
|
78954
|
+
return false;
|
|
78955
|
+
}
|
|
78956
|
+
if (!allowInitialHit && Math.abs(pos.y - hit.y) <= SPAWN_HIT_EPSILON) {
|
|
78957
|
+
return false;
|
|
78958
|
+
}
|
|
78959
|
+
outPos.set(pos.x, eyeYFromGround(hit.y, p), pos.z);
|
|
78960
|
+
const clear = !queryCapsule(collision, outPos, p);
|
|
78961
|
+
return clear || resolveSpawnCandidate(collision, outPos, p);
|
|
78962
|
+
};
|
|
78963
|
+
const searchSpawnGround = (collision, pos, direction, p, outPos) => {
|
|
78964
|
+
const step = Math.max(p.capsuleRadius, p.hoverHeight, SPAWN_SEARCH_MIN_STEP, p.spawnSearchRange / SPAWN_SEARCH_MAX_STEPS);
|
|
78965
|
+
const endY = pos.y + direction * p.spawnSearchRange;
|
|
78966
|
+
for (let y = pos.y + direction * step; direction < 0 ? y >= endY : y <= endY; y += direction * step) {
|
|
78967
|
+
probe.set(pos.x, y, pos.z);
|
|
78968
|
+
if (findClearSpawnGroundBelow(collision, probe, p.spawnSearchRange, false, p, outPos)) {
|
|
78969
|
+
return true;
|
|
78970
|
+
}
|
|
78971
|
+
}
|
|
78972
|
+
return false;
|
|
78973
|
+
};
|
|
78974
|
+
/**
|
|
78975
|
+
* Find an eye position for spawning into walk mode. Prefer ground directly
|
|
78976
|
+
* below the camera; if that is not usable, search down and then up for the
|
|
78977
|
+
* first clear walk placement with ground below it. On success, the resolved
|
|
78978
|
+
* eye position is written to outPos.
|
|
78979
|
+
*
|
|
78980
|
+
* @param collision - The active collision implementation.
|
|
78981
|
+
* @param pos - Incoming camera position.
|
|
78982
|
+
* @param p - Walk capsule and spawn-search parameters.
|
|
78983
|
+
* @param outPos - Receives the resolved eye position.
|
|
78984
|
+
* @returns True if a spawn position was found.
|
|
78985
|
+
*/
|
|
78986
|
+
const findWalkSpawn = (collision, pos, p, outPos) => {
|
|
78987
|
+
const insideSolid = isInsideSolid(collision, pos);
|
|
78988
|
+
if (findClearSpawnGroundBelow(collision, pos, p.spawnSearchRange, !insideSolid, p, outPos)) {
|
|
78989
|
+
return true;
|
|
78990
|
+
}
|
|
78991
|
+
return searchSpawnGround(collision, pos, -1, p, outPos) ||
|
|
78992
|
+
searchSpawnGround(collision, pos, 1, p, outPos);
|
|
78993
|
+
};
|
|
78994
|
+
|
|
78995
|
+
const FIXED_DT = 1 / 60;
|
|
78996
|
+
const MAX_SUBSTEPS = 10;
|
|
78791
78997
|
/** Pre-allocated push-out vector for capsule collision */
|
|
78792
78998
|
const out = { x: 0, y: 0, z: 0 };
|
|
78793
78999
|
const v = new Vec3();
|
|
@@ -78899,11 +79105,10 @@ class WalkController {
|
|
|
78899
79105
|
this.goto(camera);
|
|
78900
79106
|
if (this.collision) {
|
|
78901
79107
|
this._hasSpawn = false;
|
|
78902
|
-
if (this.
|
|
79108
|
+
if (findWalkSpawn(this.collision, camera.position, this, spawnProbe)) {
|
|
78903
79109
|
this._position.copy(spawnProbe);
|
|
78904
79110
|
this._grounded = true;
|
|
78905
79111
|
this._velocity.y = 0;
|
|
78906
|
-
this._resolveSpawnCollision();
|
|
78907
79112
|
this._storeSpawn();
|
|
78908
79113
|
}
|
|
78909
79114
|
this._prevPosition.copy(this._position);
|
|
@@ -79047,146 +79252,6 @@ class WalkController {
|
|
|
79047
79252
|
this._pendingMove[2] = 0;
|
|
79048
79253
|
this._accumulator = 0;
|
|
79049
79254
|
}
|
|
79050
|
-
/**
|
|
79051
|
-
* Resolve the capsule out of solid geometry at spawn time. This is only used
|
|
79052
|
-
* when walk mode activates inside collision.
|
|
79053
|
-
*/
|
|
79054
|
-
_resolveSpawnCollision() {
|
|
79055
|
-
for (let i = 0; i < 100; i++) {
|
|
79056
|
-
if (!this._queryCapsule(this._position)) {
|
|
79057
|
-
break;
|
|
79058
|
-
}
|
|
79059
|
-
this._position.add(v.set(out.x, out.y, out.z));
|
|
79060
|
-
}
|
|
79061
|
-
}
|
|
79062
|
-
/**
|
|
79063
|
-
* Find an eye position for spawning into walk mode. Prefer ground directly
|
|
79064
|
-
* below the camera; if that is not usable, search down and then up for the
|
|
79065
|
-
* first clear walk placement with ground below it.
|
|
79066
|
-
*
|
|
79067
|
-
* @param pos - Incoming camera position.
|
|
79068
|
-
* @param outPos - Receives the resolved eye position.
|
|
79069
|
-
* @returns True if a spawn position was found.
|
|
79070
|
-
*/
|
|
79071
|
-
_findSpawnPosition(pos, outPos) {
|
|
79072
|
-
const insideSolid = this._isInsideSolid(pos);
|
|
79073
|
-
if (this._findClearSpawnGroundBelow(pos, this.spawnSearchRange, !insideSolid, outPos)) {
|
|
79074
|
-
return true;
|
|
79075
|
-
}
|
|
79076
|
-
return this._searchSpawnGround(pos, -1, outPos) || this._searchSpawnGround(pos, 1, outPos);
|
|
79077
|
-
}
|
|
79078
|
-
/**
|
|
79079
|
-
* Search vertically for a clear walk spawn placement with ground below it.
|
|
79080
|
-
*
|
|
79081
|
-
* @param pos - Starting position.
|
|
79082
|
-
* @param direction - Vertical search direction: -1 down, 1 up.
|
|
79083
|
-
* @param outPos - Receives the resolved eye position.
|
|
79084
|
-
* @returns True if a spawn position was found.
|
|
79085
|
-
*/
|
|
79086
|
-
_searchSpawnGround(pos, direction, outPos) {
|
|
79087
|
-
const step = Math.max(this.capsuleRadius, this.hoverHeight, SPAWN_SEARCH_MIN_STEP, this.spawnSearchRange / SPAWN_SEARCH_MAX_STEPS);
|
|
79088
|
-
const endY = pos.y + direction * this.spawnSearchRange;
|
|
79089
|
-
for (let y = pos.y + direction * step; direction < 0 ? y >= endY : y <= endY; y += direction * step) {
|
|
79090
|
-
spawnProbe.set(pos.x, y, pos.z);
|
|
79091
|
-
if (this._findClearSpawnGroundBelow(spawnProbe, this.spawnSearchRange, false, outPos)) {
|
|
79092
|
-
return true;
|
|
79093
|
-
}
|
|
79094
|
-
}
|
|
79095
|
-
return false;
|
|
79096
|
-
}
|
|
79097
|
-
/**
|
|
79098
|
-
* Find the first collision surface below a point that can hold a clear walk
|
|
79099
|
-
* capsule.
|
|
79100
|
-
*
|
|
79101
|
-
* @param pos - Ray origin.
|
|
79102
|
-
* @param range - Maximum ray distance.
|
|
79103
|
-
* @param allowInitialHit - Whether a hit at the ray origin is valid.
|
|
79104
|
-
* @param outPos - Receives the resolved eye position.
|
|
79105
|
-
* @returns True if a usable ground position was found.
|
|
79106
|
-
*/
|
|
79107
|
-
_findClearSpawnGroundBelow(pos, range, allowInitialHit, outPos) {
|
|
79108
|
-
const hit = this.collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, range);
|
|
79109
|
-
if (!hit) {
|
|
79110
|
-
return false;
|
|
79111
|
-
}
|
|
79112
|
-
if (!allowInitialHit && Math.abs(pos.y - hit.y) <= SPAWN_HIT_EPSILON) {
|
|
79113
|
-
return false;
|
|
79114
|
-
}
|
|
79115
|
-
outPos.set(pos.x, this._getEyeYFromGround(hit.y), pos.z);
|
|
79116
|
-
const clear = !this._queryCapsule(outPos);
|
|
79117
|
-
const accepted = clear || this._resolveSpawnCandidate(outPos);
|
|
79118
|
-
return accepted;
|
|
79119
|
-
}
|
|
79120
|
-
/**
|
|
79121
|
-
* Convert a ground height to the walk controller's eye position.
|
|
79122
|
-
*
|
|
79123
|
-
* @param groundY - Ground surface height.
|
|
79124
|
-
* @returns Eye position Y.
|
|
79125
|
-
*/
|
|
79126
|
-
_getEyeYFromGround(groundY) {
|
|
79127
|
-
return groundY + this.hoverHeight + this.eyeHeight;
|
|
79128
|
-
}
|
|
79129
|
-
/**
|
|
79130
|
-
* Test whether the incoming camera point starts inside solid collision.
|
|
79131
|
-
*
|
|
79132
|
-
* @param pos - Point to test.
|
|
79133
|
-
* @returns True if the point overlaps solid collision.
|
|
79134
|
-
*/
|
|
79135
|
-
_isInsideSolid(pos) {
|
|
79136
|
-
return this.collision.querySphere(pos.x, pos.y, pos.z, SPAWN_HIT_EPSILON, out);
|
|
79137
|
-
}
|
|
79138
|
-
/**
|
|
79139
|
-
* Try to resolve a spawn candidate and verify it remains supported by ground.
|
|
79140
|
-
*
|
|
79141
|
-
* @param pos - Candidate eye position to resolve in place.
|
|
79142
|
-
* @returns True if the candidate can be made clear and still stand on ground.
|
|
79143
|
-
*/
|
|
79144
|
-
_resolveSpawnCandidate(pos) {
|
|
79145
|
-
const startX = pos.x;
|
|
79146
|
-
const startY = pos.y;
|
|
79147
|
-
const startZ = pos.z;
|
|
79148
|
-
const maxResolveDistance = this.capsuleRadius + this.hoverHeight;
|
|
79149
|
-
const maxResolveDistanceSq = maxResolveDistance * maxResolveDistance;
|
|
79150
|
-
for (let i = 0; i < 100; i++) {
|
|
79151
|
-
if (!this._queryCapsule(pos)) {
|
|
79152
|
-
return this._hasSpawnGroundSupport(pos);
|
|
79153
|
-
}
|
|
79154
|
-
pos.add(v.set(out.x, out.y, out.z));
|
|
79155
|
-
const dx = pos.x - startX;
|
|
79156
|
-
const dy = pos.y - startY;
|
|
79157
|
-
const dz = pos.z - startZ;
|
|
79158
|
-
if (dx * dx + dy * dy + dz * dz > maxResolveDistanceSq) {
|
|
79159
|
-
return false;
|
|
79160
|
-
}
|
|
79161
|
-
}
|
|
79162
|
-
return false;
|
|
79163
|
-
}
|
|
79164
|
-
/**
|
|
79165
|
-
* Verify the resolved spawn candidate is still standing close to ground.
|
|
79166
|
-
*
|
|
79167
|
-
* @param pos - Resolved candidate eye position.
|
|
79168
|
-
* @returns True if ground support is still valid.
|
|
79169
|
-
*/
|
|
79170
|
-
_hasSpawnGroundSupport(pos) {
|
|
79171
|
-
const groundY = this._probeGround(pos);
|
|
79172
|
-
if (groundY === null) {
|
|
79173
|
-
return false;
|
|
79174
|
-
}
|
|
79175
|
-
const clearance = pos.y - this.eyeHeight - groundY;
|
|
79176
|
-
return clearance >= -SPAWN_HIT_EPSILON &&
|
|
79177
|
-
clearance <= this.hoverHeight + this.capsuleRadius + SPAWN_HIT_EPSILON;
|
|
79178
|
-
}
|
|
79179
|
-
/**
|
|
79180
|
-
* Query the current walk capsule at the supplied eye position.
|
|
79181
|
-
*
|
|
79182
|
-
* @param pos - Eye position in PlayCanvas world space.
|
|
79183
|
-
* @returns True if the capsule overlaps collision.
|
|
79184
|
-
*/
|
|
79185
|
-
_queryCapsule(pos) {
|
|
79186
|
-
const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
|
|
79187
|
-
const center = pos.y - this.eyeHeight + this.capsuleHeight * 0.5;
|
|
79188
|
-
return this.collision.queryCapsule(pos.x, center, pos.z, half, this.capsuleRadius, out);
|
|
79189
|
-
}
|
|
79190
79255
|
/**
|
|
79191
79256
|
* Cast multiple rays downward to find the average ground surface height.
|
|
79192
79257
|
* Uses 5 rays (center + 4 cardinal at capsule radius) to spatially filter
|
|
@@ -79285,25 +79350,29 @@ class WalkSource {
|
|
|
79285
79350
|
_target = null;
|
|
79286
79351
|
_yawRate = 0;
|
|
79287
79352
|
_progress = new ProgressTracker();
|
|
79288
|
-
|
|
79353
|
+
_speedMul = 1;
|
|
79354
|
+
get isActive() {
|
|
79289
79355
|
return this._target !== null;
|
|
79290
79356
|
}
|
|
79291
79357
|
/**
|
|
79292
79358
|
* Begin auto-walking toward a world-space target position.
|
|
79293
79359
|
*
|
|
79294
79360
|
* @param target - The destination (XZ used for navigation).
|
|
79361
|
+
* @param speedMul - Forward-speed multiplier (mirrors gaming-controls
|
|
79362
|
+
* shift/ctrl: 2 for run, 0.5 for crawl). Defaults to 1.
|
|
79295
79363
|
*/
|
|
79296
|
-
|
|
79364
|
+
navigateTo(target, speedMul = 1) {
|
|
79297
79365
|
if (!this._target) {
|
|
79298
79366
|
this._target = new Vec3();
|
|
79299
79367
|
}
|
|
79300
79368
|
this._target.copy(target);
|
|
79369
|
+
this._speedMul = speedMul;
|
|
79301
79370
|
this._progress.reset();
|
|
79302
79371
|
}
|
|
79303
79372
|
/**
|
|
79304
79373
|
* Cancel any active auto-walk.
|
|
79305
79374
|
*/
|
|
79306
|
-
|
|
79375
|
+
cancel() {
|
|
79307
79376
|
if (this._target) {
|
|
79308
79377
|
this._target = null;
|
|
79309
79378
|
this._yawRate = 0;
|
|
@@ -79316,25 +79385,26 @@ class WalkSource {
|
|
|
79316
79385
|
* before* the camera controller reads the frame.
|
|
79317
79386
|
*
|
|
79318
79387
|
* @param dt - Frame delta time in seconds.
|
|
79319
|
-
* @param
|
|
79320
|
-
* @param cameraAngles - Camera Euler angles in degrees (previous frame output).
|
|
79388
|
+
* @param camera - The current camera state (read-only).
|
|
79321
79389
|
* @param frame - The shared CameraFrame to append deltas to.
|
|
79322
79390
|
*/
|
|
79323
|
-
update(dt,
|
|
79391
|
+
update(dt, camera, frame) {
|
|
79324
79392
|
if (!this._target)
|
|
79325
79393
|
return;
|
|
79326
79394
|
const target = this._target;
|
|
79395
|
+
const cameraPosition = camera.position;
|
|
79396
|
+
const cameraAngles = camera.angles;
|
|
79327
79397
|
const dx = target.x - cameraPosition.x;
|
|
79328
79398
|
const dz = target.z - cameraPosition.z;
|
|
79329
79399
|
const xzDist = Math.sqrt(dx * dx + dz * dz);
|
|
79330
79400
|
// arrival
|
|
79331
79401
|
if (xzDist < ARRIVAL_DIST) {
|
|
79332
|
-
this.
|
|
79402
|
+
this.cancel();
|
|
79333
79403
|
return;
|
|
79334
79404
|
}
|
|
79335
79405
|
// blocked detection: compare with previous frame's distance
|
|
79336
79406
|
if (this._progress.update(xzDist, dt, BLOCKED_SPEED, BLOCKED_DURATION)) {
|
|
79337
|
-
this.
|
|
79407
|
+
this.cancel();
|
|
79338
79408
|
return;
|
|
79339
79409
|
}
|
|
79340
79410
|
// yaw toward target with smoothed turn rate
|
|
@@ -79346,7 +79416,7 @@ class WalkSource {
|
|
|
79346
79416
|
frame.deltas.rotate.append([-yawStep, 0, 0]);
|
|
79347
79417
|
// scale forward speed by alignment: turn in place first, then accelerate
|
|
79348
79418
|
const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
|
|
79349
|
-
frame.deltas.move.append([0, 0, this.walkSpeed * dt * alignment]);
|
|
79419
|
+
frame.deltas.move.append([0, 0, this.walkSpeed * this._speedMul * dt * alignment]);
|
|
79350
79420
|
}
|
|
79351
79421
|
}
|
|
79352
79422
|
|
|
@@ -79405,12 +79475,13 @@ class CameraManager {
|
|
|
79405
79475
|
controllers.fly.collision = collision;
|
|
79406
79476
|
controllers.walk.collision = collision;
|
|
79407
79477
|
const walkSource = new WalkSource();
|
|
79408
|
-
walkSource.onComplete = () => {
|
|
79409
|
-
events.fire('walkComplete');
|
|
79410
|
-
};
|
|
79411
79478
|
const flySource = new FlySource();
|
|
79412
|
-
|
|
79413
|
-
|
|
79479
|
+
const sourcesByMode = {
|
|
79480
|
+
walk: walkSource,
|
|
79481
|
+
fly: flySource
|
|
79482
|
+
};
|
|
79483
|
+
walkSource.onComplete = flySource.onComplete = () => {
|
|
79484
|
+
events.fire('navigateComplete');
|
|
79414
79485
|
};
|
|
79415
79486
|
const getController = (cameraMode) => {
|
|
79416
79487
|
return controllers[cameraMode];
|
|
@@ -79446,12 +79517,7 @@ class CameraManager {
|
|
|
79446
79517
|
const prevTransitionTimer = transitionTimer;
|
|
79447
79518
|
transitionTimer = Math.min(1, transitionTimer + deltaTime * transitionSpeed);
|
|
79448
79519
|
const controller = getController(state.cameraMode);
|
|
79449
|
-
|
|
79450
|
-
walkSource.update(dt, this.camera.position, this.camera.angles, frame);
|
|
79451
|
-
}
|
|
79452
|
-
else if (state.cameraMode === 'fly') {
|
|
79453
|
-
flySource.update(dt, this.camera.position, this.camera.angles, this.camera.fov, frame);
|
|
79454
|
-
}
|
|
79520
|
+
sourcesByMode[state.cameraMode]?.update(dt, this.camera, frame);
|
|
79455
79521
|
controller.update(dt, frame, target);
|
|
79456
79522
|
if (transitionTimer < 1) {
|
|
79457
79523
|
// lerp away from previous camera during transition
|
|
@@ -79480,13 +79546,13 @@ class CameraManager {
|
|
|
79480
79546
|
break;
|
|
79481
79547
|
case 'reset':
|
|
79482
79548
|
if (state.cameraMode === 'walk') {
|
|
79483
|
-
walkSource.
|
|
79484
|
-
events.fire('
|
|
79549
|
+
walkSource.cancel();
|
|
79550
|
+
events.fire('navTarget:clear');
|
|
79485
79551
|
startTransition();
|
|
79486
79552
|
controllers.walk.resetToSpawn(target);
|
|
79487
79553
|
}
|
|
79488
79554
|
else if (state.cameraMode === 'fly') {
|
|
79489
|
-
flySource.
|
|
79555
|
+
flySource.cancel();
|
|
79490
79556
|
startTransition();
|
|
79491
79557
|
controllers.fly.resetToSpawn(target);
|
|
79492
79558
|
}
|
|
@@ -79541,12 +79607,7 @@ class CameraManager {
|
|
|
79541
79607
|
});
|
|
79542
79608
|
// handle camera mode switching
|
|
79543
79609
|
events.on('cameraMode:changed', (value, prev) => {
|
|
79544
|
-
|
|
79545
|
-
walkSource.cancelWalk();
|
|
79546
|
-
}
|
|
79547
|
-
else if (prev === 'fly') {
|
|
79548
|
-
flySource.cancelFly();
|
|
79549
|
-
}
|
|
79610
|
+
sourcesByMode[prev]?.cancel();
|
|
79550
79611
|
// snapshot the current pose before any controller mutation
|
|
79551
79612
|
startTransition();
|
|
79552
79613
|
target.copy(this.camera);
|
|
@@ -79587,35 +79648,21 @@ class CameraManager {
|
|
|
79587
79648
|
controllers.orbit.goto(tmpCamera);
|
|
79588
79649
|
startTransition();
|
|
79589
79650
|
});
|
|
79590
|
-
// tap-to-
|
|
79591
|
-
events.on('
|
|
79592
|
-
|
|
79593
|
-
|
|
79594
|
-
|
|
79595
|
-
|
|
79596
|
-
});
|
|
79597
|
-
// cancel any active auto-walk
|
|
79598
|
-
events.on('walkCancel', () => {
|
|
79599
|
-
walkSource.cancelWalk();
|
|
79600
|
-
events.fire('walkTarget:clear');
|
|
79601
|
-
});
|
|
79602
|
-
events.on('walkComplete', () => {
|
|
79603
|
-
events.fire('walkTarget:clear');
|
|
79604
|
-
});
|
|
79605
|
-
// click/tap-to-fly: start auto-flying toward a picked 3D position
|
|
79606
|
-
events.on('flyTo', (position, normal) => {
|
|
79607
|
-
if (state.cameraMode === 'fly') {
|
|
79608
|
-
flySource.flyTo(position);
|
|
79609
|
-
events.fire('flyTarget:set', position, normal);
|
|
79651
|
+
// tap-to-navigate: start auto-driving the active mode toward a picked position
|
|
79652
|
+
events.on('navigateTo', (position, normal, speedMul = 1) => {
|
|
79653
|
+
const source = sourcesByMode[state.cameraMode];
|
|
79654
|
+
if (source) {
|
|
79655
|
+
source.navigateTo(position, speedMul);
|
|
79656
|
+
events.fire('navTarget:set', position, normal);
|
|
79610
79657
|
}
|
|
79611
79658
|
});
|
|
79612
|
-
// cancel any active auto-
|
|
79613
|
-
events.on('
|
|
79614
|
-
|
|
79615
|
-
events.fire('
|
|
79659
|
+
// cancel any active auto-navigation in the current mode
|
|
79660
|
+
events.on('navigateCancel', () => {
|
|
79661
|
+
sourcesByMode[state.cameraMode]?.cancel();
|
|
79662
|
+
events.fire('navTarget:clear');
|
|
79616
79663
|
});
|
|
79617
|
-
events.on('
|
|
79618
|
-
events.fire('
|
|
79664
|
+
events.on('navigateComplete', () => {
|
|
79665
|
+
events.fire('navTarget:clear');
|
|
79619
79666
|
});
|
|
79620
79667
|
}
|
|
79621
79668
|
}
|
|
@@ -79735,146 +79782,6 @@ class ModeShortcuts {
|
|
|
79735
79782
|
}
|
|
79736
79783
|
}
|
|
79737
79784
|
|
|
79738
|
-
const isCaptureMode = (mode) => mode === 'walk' || mode === 'fly';
|
|
79739
|
-
const hasUserActivation = () => (navigator.userActivation?.isActive === true);
|
|
79740
|
-
/**
|
|
79741
|
-
* Manages the browser's pointer-lock API for first-person gaming controls
|
|
79742
|
-
* on desktop. Toggles in response to camera mode, input mode, and
|
|
79743
|
-
* gaming-controls changes, and reverts state if the lock is exited or rejected.
|
|
79744
|
-
*
|
|
79745
|
-
* Also exposes `recentlyExitedCapture` so the keyboard-shortcut handler can
|
|
79746
|
-
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
79747
|
-
*/
|
|
79748
|
-
class PointerLockManager {
|
|
79749
|
-
_global = null;
|
|
79750
|
-
_canvas = null;
|
|
79751
|
-
_keyboardMouse = null;
|
|
79752
|
-
_recentlyExitedCapture = false;
|
|
79753
|
-
_onPointerLockChange = () => {
|
|
79754
|
-
const global = this._global;
|
|
79755
|
-
if (!global)
|
|
79756
|
-
return;
|
|
79757
|
-
const { state, events } = global;
|
|
79758
|
-
if (!document.pointerLockElement && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
79759
|
-
this._recentlyExitedCapture = true;
|
|
79760
|
-
requestAnimationFrame(() => {
|
|
79761
|
-
this._recentlyExitedCapture = false;
|
|
79762
|
-
});
|
|
79763
|
-
if (state.inputMode === 'desktop') {
|
|
79764
|
-
state.gamingControls = false;
|
|
79765
|
-
}
|
|
79766
|
-
else if (state.cameraMode === 'walk') {
|
|
79767
|
-
events.fire('inputEvent', 'exitWalk');
|
|
79768
|
-
}
|
|
79769
|
-
}
|
|
79770
|
-
};
|
|
79771
|
-
_onPointerLockError = () => {
|
|
79772
|
-
// Pointer lock request rejected (no user gesture, document hidden,
|
|
79773
|
-
// etc). Revert state so we don't end up stuck in walk mode without
|
|
79774
|
-
// mouse capture.
|
|
79775
|
-
if (this._keyboardMouse) {
|
|
79776
|
-
this._keyboardMouse.source._pointerLock = false;
|
|
79777
|
-
}
|
|
79778
|
-
const global = this._global;
|
|
79779
|
-
if (!global)
|
|
79780
|
-
return;
|
|
79781
|
-
const { state, events } = global;
|
|
79782
|
-
if (state.inputMode === 'desktop' && isCaptureMode(state.cameraMode)) {
|
|
79783
|
-
state.gamingControls = false;
|
|
79784
|
-
}
|
|
79785
|
-
else if (state.cameraMode === 'walk') {
|
|
79786
|
-
events.fire('inputEvent', 'exitWalk');
|
|
79787
|
-
}
|
|
79788
|
-
};
|
|
79789
|
-
_onCameraModeChanged = (value, prev) => {
|
|
79790
|
-
const state = this._global?.state;
|
|
79791
|
-
if (!state)
|
|
79792
|
-
return;
|
|
79793
|
-
if (isCaptureMode(value) && state.inputMode === 'desktop' && state.gamingControls) {
|
|
79794
|
-
this._activate();
|
|
79795
|
-
}
|
|
79796
|
-
else if (isCaptureMode(prev)) {
|
|
79797
|
-
this._deactivate();
|
|
79798
|
-
}
|
|
79799
|
-
};
|
|
79800
|
-
_onGamingControlsChanged = (value) => {
|
|
79801
|
-
const state = this._global?.state;
|
|
79802
|
-
if (!state)
|
|
79803
|
-
return;
|
|
79804
|
-
if (isCaptureMode(state.cameraMode) && state.inputMode === 'desktop') {
|
|
79805
|
-
if (value) {
|
|
79806
|
-
this._activate();
|
|
79807
|
-
}
|
|
79808
|
-
else {
|
|
79809
|
-
this._deactivate();
|
|
79810
|
-
}
|
|
79811
|
-
}
|
|
79812
|
-
};
|
|
79813
|
-
_onInputModeChanged = (value) => {
|
|
79814
|
-
const state = this._global?.state;
|
|
79815
|
-
if (!state || !isCaptureMode(state.cameraMode) || !state.gamingControls) {
|
|
79816
|
-
return;
|
|
79817
|
-
}
|
|
79818
|
-
if (value === 'desktop' && hasUserActivation()) {
|
|
79819
|
-
this._activate();
|
|
79820
|
-
}
|
|
79821
|
-
else if (value !== 'desktop') {
|
|
79822
|
-
this._deactivate();
|
|
79823
|
-
}
|
|
79824
|
-
};
|
|
79825
|
-
_onPointerDown = () => {
|
|
79826
|
-
const state = this._global?.state;
|
|
79827
|
-
if (state && state.inputMode === 'desktop' && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
79828
|
-
this._activate();
|
|
79829
|
-
}
|
|
79830
|
-
};
|
|
79831
|
-
_activate() {
|
|
79832
|
-
if (this._keyboardMouse) {
|
|
79833
|
-
this._keyboardMouse.source._pointerLock = true;
|
|
79834
|
-
}
|
|
79835
|
-
if (document.pointerLockElement !== this._canvas) {
|
|
79836
|
-
this._canvas?.requestPointerLock();
|
|
79837
|
-
}
|
|
79838
|
-
}
|
|
79839
|
-
_deactivate() {
|
|
79840
|
-
if (this._keyboardMouse) {
|
|
79841
|
-
this._keyboardMouse.source._pointerLock = false;
|
|
79842
|
-
}
|
|
79843
|
-
if (document.pointerLockElement === this._canvas) {
|
|
79844
|
-
document.exitPointerLock();
|
|
79845
|
-
}
|
|
79846
|
-
}
|
|
79847
|
-
get recentlyExitedCapture() {
|
|
79848
|
-
return this._recentlyExitedCapture;
|
|
79849
|
-
}
|
|
79850
|
-
attach(canvas, global, keyboardMouse) {
|
|
79851
|
-
this._canvas = canvas;
|
|
79852
|
-
this._global = global;
|
|
79853
|
-
this._keyboardMouse = keyboardMouse;
|
|
79854
|
-
const { events } = global;
|
|
79855
|
-
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
79856
|
-
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
79857
|
-
events.on('inputMode:changed', this._onInputModeChanged);
|
|
79858
|
-
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79859
|
-
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79860
|
-
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
79861
|
-
}
|
|
79862
|
-
detach() {
|
|
79863
|
-
if (this._global) {
|
|
79864
|
-
const { events } = this._global;
|
|
79865
|
-
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
79866
|
-
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
79867
|
-
events.off('inputMode:changed', this._onInputModeChanged);
|
|
79868
|
-
}
|
|
79869
|
-
this._canvas?.removeEventListener('pointerdown', this._onPointerDown);
|
|
79870
|
-
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79871
|
-
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
79872
|
-
this._canvas = null;
|
|
79873
|
-
this._global = null;
|
|
79874
|
-
this._keyboardMouse = null;
|
|
79875
|
-
}
|
|
79876
|
-
}
|
|
79877
|
-
|
|
79878
79785
|
/**
|
|
79879
79786
|
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79880
79787
|
* pixel offsets that already scale with frame time. This factor converts
|
|
@@ -79930,12 +79837,31 @@ const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
|
|
|
79930
79837
|
const tmpV$4 = new Vec3();
|
|
79931
79838
|
const canTargetFly = (global) => (global.state.cameraMode === 'fly' &&
|
|
79932
79839
|
!(global.state.inputMode === 'desktop' && global.state.gamingControls));
|
|
79840
|
+
// Mirror gaming-controls speed modifiers: shift = run/boost, ctrl = crawl/slow.
|
|
79841
|
+
// Multipliers match keyboard-mouse.ts so click-nav and held-key movement feel the same.
|
|
79842
|
+
const computeClickSpeedMul = (event, mode) => {
|
|
79843
|
+
if (!event)
|
|
79844
|
+
return 1;
|
|
79845
|
+
if (mode === 'walk') {
|
|
79846
|
+
if (event.shiftKey)
|
|
79847
|
+
return 2;
|
|
79848
|
+
if (event.ctrlKey)
|
|
79849
|
+
return 0.5;
|
|
79850
|
+
}
|
|
79851
|
+
else if (mode === 'fly') {
|
|
79852
|
+
if (event.shiftKey)
|
|
79853
|
+
return 4;
|
|
79854
|
+
if (event.ctrlKey)
|
|
79855
|
+
return 0.25;
|
|
79856
|
+
}
|
|
79857
|
+
return 1;
|
|
79858
|
+
};
|
|
79933
79859
|
/**
|
|
79934
79860
|
* Click-to-walk / click-to-fly / click-to-focus (desktop), tap equivalents
|
|
79935
79861
|
* on mobile, and double-click-to-pick fallback. Uses collision first and
|
|
79936
79862
|
* rendered-scene picking when collision is unavailable.
|
|
79937
79863
|
*/
|
|
79938
|
-
class
|
|
79864
|
+
class NavInteraction {
|
|
79939
79865
|
collision = null;
|
|
79940
79866
|
_picker;
|
|
79941
79867
|
_global = null;
|
|
@@ -80001,14 +79927,15 @@ class WalkInteraction {
|
|
|
80001
79927
|
}
|
|
80002
79928
|
return null;
|
|
80003
79929
|
}
|
|
80004
|
-
async _flyToPickedPosition(offsetX, offsetY) {
|
|
79930
|
+
async _flyToPickedPosition(offsetX, offsetY, event) {
|
|
80005
79931
|
const global = this._global;
|
|
80006
79932
|
if (!global || !canTargetFly(global))
|
|
80007
79933
|
return;
|
|
80008
79934
|
const request = ++this._targetPickRequest;
|
|
80009
79935
|
const target = await this._pickSceneTarget(offsetX, offsetY);
|
|
80010
79936
|
if (target && request === this._targetPickRequest && this._global && canTargetFly(this._global)) {
|
|
80011
|
-
this._global.
|
|
79937
|
+
const speedMul = computeClickSpeedMul(event, this._global.state.cameraMode);
|
|
79938
|
+
this._global.events.fire('navigateTo', target.position, target.normal, speedMul);
|
|
80012
79939
|
}
|
|
80013
79940
|
}
|
|
80014
79941
|
async _focusPickedPosition(offsetX, offsetY) {
|
|
@@ -80063,11 +79990,8 @@ class WalkInteraction {
|
|
|
80063
79990
|
const prev = this._mouseClickDelta;
|
|
80064
79991
|
this._mouseClickDelta += Math.abs(event.movementX) + Math.abs(event.movementY);
|
|
80065
79992
|
if (prev < TAP_EPSILON && this._mouseClickDelta >= TAP_EPSILON) {
|
|
80066
|
-
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80067
|
-
events.fire('
|
|
80068
|
-
}
|
|
80069
|
-
else if (canTargetFly(global)) {
|
|
80070
|
-
events.fire('flyCancel');
|
|
79993
|
+
if ((state.cameraMode === 'walk' && !state.gamingControls) || canTargetFly(global)) {
|
|
79994
|
+
events.fire('navigateCancel');
|
|
80071
79995
|
}
|
|
80072
79996
|
}
|
|
80073
79997
|
}
|
|
@@ -80088,11 +80012,12 @@ class WalkInteraction {
|
|
|
80088
80012
|
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80089
80013
|
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80090
80014
|
if (result) {
|
|
80091
|
-
|
|
80015
|
+
const speedMul = computeClickSpeedMul(event, state.cameraMode);
|
|
80016
|
+
events.fire('navigateTo', result.position, result.normal, speedMul);
|
|
80092
80017
|
}
|
|
80093
80018
|
}
|
|
80094
80019
|
else if (state.cameraMode === 'fly') {
|
|
80095
|
-
this._flyToPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80020
|
+
this._flyToPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY, event);
|
|
80096
80021
|
}
|
|
80097
80022
|
else if (state.cameraMode === 'orbit') {
|
|
80098
80023
|
this._focusPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
@@ -80110,19 +80035,25 @@ class WalkInteraction {
|
|
|
80110
80035
|
if (!(event instanceof MouseEvent))
|
|
80111
80036
|
return;
|
|
80112
80037
|
const { events, state } = global;
|
|
80113
|
-
|
|
80114
|
-
|
|
80038
|
+
// dblclick swaps the active mode and uses the picked target:
|
|
80039
|
+
// fly → orbit, focus orbit at point
|
|
80040
|
+
// orbit / walk → fly, navigate fly toward point
|
|
80041
|
+
const request = ++this._targetPickRequest;
|
|
80042
|
+
const target = await this._pickSceneTarget(event.offsetX, event.offsetY);
|
|
80043
|
+
if (!target || request !== this._targetPickRequest)
|
|
80115
80044
|
return;
|
|
80116
|
-
|
|
80117
|
-
|
|
80045
|
+
const currentMode = this._global?.state.cameraMode;
|
|
80046
|
+
if (currentMode === 'fly') {
|
|
80047
|
+
// 'pick' switches mode to orbit, which cancels the active fly nav
|
|
80048
|
+
// and would clobber any pre-set orbit target — set it after.
|
|
80049
|
+
events.fire('pick', target.position);
|
|
80050
|
+
events.fire('orbitTarget:set', target.position, target.normal);
|
|
80118
80051
|
}
|
|
80119
|
-
else if (
|
|
80120
|
-
|
|
80121
|
-
|
|
80122
|
-
|
|
80123
|
-
|
|
80124
|
-
events.fire('pick', target.position);
|
|
80125
|
-
}
|
|
80052
|
+
else if (currentMode === 'orbit' || currentMode === 'walk') {
|
|
80053
|
+
state.cameraMode = 'fly';
|
|
80054
|
+
// Modifiers apply against the destination mode (fly), not the source.
|
|
80055
|
+
const speedMul = computeClickSpeedMul(event, 'fly');
|
|
80056
|
+
events.fire('navigateTo', target.position, target.normal, speedMul);
|
|
80126
80057
|
}
|
|
80127
80058
|
};
|
|
80128
80059
|
_onMobileTap = () => {
|
|
@@ -80137,7 +80068,7 @@ class WalkInteraction {
|
|
|
80137
80068
|
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80138
80069
|
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80139
80070
|
if (result) {
|
|
80140
|
-
events.fire('
|
|
80071
|
+
events.fire('navigateTo', result.position, result.normal);
|
|
80141
80072
|
}
|
|
80142
80073
|
}
|
|
80143
80074
|
else if (state.cameraMode === 'fly') {
|
|
@@ -80182,6 +80113,146 @@ class WalkInteraction {
|
|
|
80182
80113
|
}
|
|
80183
80114
|
}
|
|
80184
80115
|
|
|
80116
|
+
const isCaptureMode = (mode) => mode === 'walk' || mode === 'fly';
|
|
80117
|
+
const hasUserActivation = () => (navigator.userActivation?.isActive === true);
|
|
80118
|
+
/**
|
|
80119
|
+
* Manages the browser's pointer-lock API for first-person gaming controls
|
|
80120
|
+
* on desktop. Toggles in response to camera mode, input mode, and
|
|
80121
|
+
* gaming-controls changes, and reverts state if the lock is exited or rejected.
|
|
80122
|
+
*
|
|
80123
|
+
* Also exposes `recentlyExitedCapture` so the keyboard-shortcut handler can
|
|
80124
|
+
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
80125
|
+
*/
|
|
80126
|
+
class PointerLockManager {
|
|
80127
|
+
_global = null;
|
|
80128
|
+
_canvas = null;
|
|
80129
|
+
_keyboardMouse = null;
|
|
80130
|
+
_recentlyExitedCapture = false;
|
|
80131
|
+
_onPointerLockChange = () => {
|
|
80132
|
+
const global = this._global;
|
|
80133
|
+
if (!global)
|
|
80134
|
+
return;
|
|
80135
|
+
const { state, events } = global;
|
|
80136
|
+
if (!document.pointerLockElement && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
80137
|
+
this._recentlyExitedCapture = true;
|
|
80138
|
+
requestAnimationFrame(() => {
|
|
80139
|
+
this._recentlyExitedCapture = false;
|
|
80140
|
+
});
|
|
80141
|
+
if (state.inputMode === 'desktop') {
|
|
80142
|
+
state.gamingControls = false;
|
|
80143
|
+
}
|
|
80144
|
+
else if (state.cameraMode === 'walk') {
|
|
80145
|
+
events.fire('inputEvent', 'exitWalk');
|
|
80146
|
+
}
|
|
80147
|
+
}
|
|
80148
|
+
};
|
|
80149
|
+
_onPointerLockError = () => {
|
|
80150
|
+
// Pointer lock request rejected (no user gesture, document hidden,
|
|
80151
|
+
// etc). Revert state so we don't end up stuck in walk mode without
|
|
80152
|
+
// mouse capture.
|
|
80153
|
+
if (this._keyboardMouse) {
|
|
80154
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
80155
|
+
}
|
|
80156
|
+
const global = this._global;
|
|
80157
|
+
if (!global)
|
|
80158
|
+
return;
|
|
80159
|
+
const { state, events } = global;
|
|
80160
|
+
if (state.inputMode === 'desktop' && isCaptureMode(state.cameraMode)) {
|
|
80161
|
+
state.gamingControls = false;
|
|
80162
|
+
}
|
|
80163
|
+
else if (state.cameraMode === 'walk') {
|
|
80164
|
+
events.fire('inputEvent', 'exitWalk');
|
|
80165
|
+
}
|
|
80166
|
+
};
|
|
80167
|
+
_onCameraModeChanged = (value, prev) => {
|
|
80168
|
+
const state = this._global?.state;
|
|
80169
|
+
if (!state)
|
|
80170
|
+
return;
|
|
80171
|
+
if (isCaptureMode(value) && state.inputMode === 'desktop' && state.gamingControls) {
|
|
80172
|
+
this._activate();
|
|
80173
|
+
}
|
|
80174
|
+
else if (isCaptureMode(prev)) {
|
|
80175
|
+
this._deactivate();
|
|
80176
|
+
}
|
|
80177
|
+
};
|
|
80178
|
+
_onGamingControlsChanged = (value) => {
|
|
80179
|
+
const state = this._global?.state;
|
|
80180
|
+
if (!state)
|
|
80181
|
+
return;
|
|
80182
|
+
if (isCaptureMode(state.cameraMode) && state.inputMode === 'desktop') {
|
|
80183
|
+
if (value) {
|
|
80184
|
+
this._activate();
|
|
80185
|
+
}
|
|
80186
|
+
else {
|
|
80187
|
+
this._deactivate();
|
|
80188
|
+
}
|
|
80189
|
+
}
|
|
80190
|
+
};
|
|
80191
|
+
_onInputModeChanged = (value) => {
|
|
80192
|
+
const state = this._global?.state;
|
|
80193
|
+
if (!state || !isCaptureMode(state.cameraMode) || !state.gamingControls) {
|
|
80194
|
+
return;
|
|
80195
|
+
}
|
|
80196
|
+
if (value === 'desktop' && hasUserActivation()) {
|
|
80197
|
+
this._activate();
|
|
80198
|
+
}
|
|
80199
|
+
else if (value !== 'desktop') {
|
|
80200
|
+
this._deactivate();
|
|
80201
|
+
}
|
|
80202
|
+
};
|
|
80203
|
+
_onPointerDown = () => {
|
|
80204
|
+
const state = this._global?.state;
|
|
80205
|
+
if (state && state.inputMode === 'desktop' && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
80206
|
+
this._activate();
|
|
80207
|
+
}
|
|
80208
|
+
};
|
|
80209
|
+
_activate() {
|
|
80210
|
+
if (this._keyboardMouse) {
|
|
80211
|
+
this._keyboardMouse.source._pointerLock = true;
|
|
80212
|
+
}
|
|
80213
|
+
if (document.pointerLockElement !== this._canvas) {
|
|
80214
|
+
this._canvas?.requestPointerLock();
|
|
80215
|
+
}
|
|
80216
|
+
}
|
|
80217
|
+
_deactivate() {
|
|
80218
|
+
if (this._keyboardMouse) {
|
|
80219
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
80220
|
+
}
|
|
80221
|
+
if (document.pointerLockElement === this._canvas) {
|
|
80222
|
+
document.exitPointerLock();
|
|
80223
|
+
}
|
|
80224
|
+
}
|
|
80225
|
+
get recentlyExitedCapture() {
|
|
80226
|
+
return this._recentlyExitedCapture;
|
|
80227
|
+
}
|
|
80228
|
+
attach(canvas, global, keyboardMouse) {
|
|
80229
|
+
this._canvas = canvas;
|
|
80230
|
+
this._global = global;
|
|
80231
|
+
this._keyboardMouse = keyboardMouse;
|
|
80232
|
+
const { events } = global;
|
|
80233
|
+
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
80234
|
+
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
80235
|
+
events.on('inputMode:changed', this._onInputModeChanged);
|
|
80236
|
+
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
80237
|
+
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
80238
|
+
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
80239
|
+
}
|
|
80240
|
+
detach() {
|
|
80241
|
+
if (this._global) {
|
|
80242
|
+
const { events } = this._global;
|
|
80243
|
+
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
80244
|
+
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
80245
|
+
events.off('inputMode:changed', this._onInputModeChanged);
|
|
80246
|
+
}
|
|
80247
|
+
this._canvas?.removeEventListener('pointerdown', this._onPointerDown);
|
|
80248
|
+
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
80249
|
+
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
80250
|
+
this._canvas = null;
|
|
80251
|
+
this._global = null;
|
|
80252
|
+
this._keyboardMouse = null;
|
|
80253
|
+
}
|
|
80254
|
+
}
|
|
80255
|
+
|
|
80185
80256
|
const tmpV$3 = new Vec3();
|
|
80186
80257
|
const stickMove = new Vec3();
|
|
80187
80258
|
const stickRotate = new Vec3();
|
|
@@ -80204,7 +80275,7 @@ class GamepadDevice {
|
|
|
80204
80275
|
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
80205
80276
|
const { deltas } = frame;
|
|
80206
80277
|
if (isFly && (leftStick[0] !== 0 || leftStick[1] !== 0 || rightStick[0] !== 0 || rightStick[1] !== 0)) {
|
|
80207
|
-
this._global?.events.fire('
|
|
80278
|
+
this._global?.events.fire('navigateCancel');
|
|
80208
80279
|
}
|
|
80209
80280
|
const v = tmpV$3.set(0, 0, 0);
|
|
80210
80281
|
stickMove.set(leftStick[0], 0, -leftStick[1]);
|
|
@@ -80299,16 +80370,16 @@ class KeyboardMouseDevice {
|
|
|
80299
80370
|
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
80300
80371
|
// auto-move cancellation and requestFirstPerson events (driven by keyboard axes)
|
|
80301
80372
|
if (isWalk && (this._axis.x !== 0 || this._axis.z !== 0)) {
|
|
80302
|
-
events.fire('
|
|
80373
|
+
events.fire('navigateCancel');
|
|
80303
80374
|
}
|
|
80304
80375
|
if (isFly && (this._axis.x !== 0 || this._axis.y !== 0 || this._axis.z !== 0)) {
|
|
80305
|
-
events.fire('
|
|
80376
|
+
events.fire('navigateCancel');
|
|
80306
80377
|
}
|
|
80307
80378
|
if (isFly && wheel[0] !== 0) {
|
|
80308
|
-
events.fire('
|
|
80379
|
+
events.fire('navigateCancel');
|
|
80309
80380
|
}
|
|
80310
80381
|
if (isFly && (gamingControls || pan) && (mouse[0] !== 0 || mouse[1] !== 0)) {
|
|
80311
|
-
events.fire('
|
|
80382
|
+
events.fire('navigateCancel');
|
|
80312
80383
|
}
|
|
80313
80384
|
if (!isFirstPerson && this._axis.length() > 0) {
|
|
80314
80385
|
events.fire('inputEvent', 'requestFirstPerson');
|
|
@@ -80417,7 +80488,7 @@ class TouchDevice {
|
|
|
80417
80488
|
// running touch count
|
|
80418
80489
|
this._touchCount += count[0];
|
|
80419
80490
|
if (isFly && gamingControls && (this._joystick[0] !== 0 || this._joystick[1] !== 0)) {
|
|
80420
|
-
this._global.events.fire('
|
|
80491
|
+
this._global.events.fire('navigateCancel');
|
|
80421
80492
|
}
|
|
80422
80493
|
// tap detection for click/tap target and focus modes
|
|
80423
80494
|
if (isWalk || isFly || isOrbit) {
|
|
@@ -80433,18 +80504,15 @@ class TouchDevice {
|
|
|
80433
80504
|
const prevDelta = this._tapDelta;
|
|
80434
80505
|
this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]) + Math.abs(pinch[0]);
|
|
80435
80506
|
if (prevDelta < TAP_EPSILON && this._tapDelta >= TAP_EPSILON) {
|
|
80436
|
-
if (isWalk && !gamingControls) {
|
|
80437
|
-
this._global.events.fire('
|
|
80438
|
-
}
|
|
80439
|
-
else if (isFly) {
|
|
80440
|
-
this._global.events.fire('flyCancel');
|
|
80507
|
+
if ((isWalk && !gamingControls) || isFly) {
|
|
80508
|
+
this._global.events.fire('navigateCancel');
|
|
80441
80509
|
}
|
|
80442
80510
|
}
|
|
80443
80511
|
}
|
|
80444
80512
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
80445
80513
|
if (this._tapDelta < TAP_EPSILON && this._tapMaxTouches === 1) {
|
|
80446
80514
|
if (isWalk && !gamingControls) {
|
|
80447
|
-
// Walk-interaction listens for this and fires
|
|
80515
|
+
// Walk-interaction listens for this and fires navigateTo
|
|
80448
80516
|
// after picking.
|
|
80449
80517
|
this._global.events.fire('mobileTap');
|
|
80450
80518
|
}
|
|
@@ -80452,7 +80520,7 @@ class TouchDevice {
|
|
|
80452
80520
|
this._tapJump = true;
|
|
80453
80521
|
}
|
|
80454
80522
|
else if (isFly && !gamingControls) {
|
|
80455
|
-
// Walk-interaction listens for this and fires
|
|
80523
|
+
// Walk-interaction listens for this and fires navigateTo
|
|
80456
80524
|
// after picking.
|
|
80457
80525
|
this._global.events.fire('mobileTap');
|
|
80458
80526
|
}
|
|
@@ -80637,7 +80705,7 @@ class TrackpadDevice {
|
|
|
80637
80705
|
else {
|
|
80638
80706
|
// fly / walk: always rotate (shift is a speed modifier, not a gesture)
|
|
80639
80707
|
if (mode === 'fly') {
|
|
80640
|
-
this._global.events.fire('
|
|
80708
|
+
this._global.events.fire('navigateCancel');
|
|
80641
80709
|
}
|
|
80642
80710
|
this._orbit[0] += deltaX;
|
|
80643
80711
|
this._orbit[1] += deltaY;
|
|
@@ -80700,7 +80768,7 @@ class TrackpadDevice {
|
|
|
80700
80768
|
|
|
80701
80769
|
/**
|
|
80702
80770
|
* Coordinator that wires together input devices (keyboard-mouse, touch,
|
|
80703
|
-
* trackpad, gamepad) and app-level UX helpers (mode shortcuts,
|
|
80771
|
+
* trackpad, gamepad) and app-level UX helpers (mode shortcuts, nav
|
|
80704
80772
|
* interaction, pointer lock, input-mode tracker), and exposes the
|
|
80705
80773
|
* resulting per-frame `InputFrame` for the camera manager to consume.
|
|
80706
80774
|
*/
|
|
@@ -80714,19 +80782,19 @@ class InputController {
|
|
|
80714
80782
|
_keyboardMouse = new KeyboardMouseDevice();
|
|
80715
80783
|
_touch = new TouchDevice();
|
|
80716
80784
|
_gamepad = new GamepadDevice();
|
|
80717
|
-
|
|
80785
|
+
_navInteraction;
|
|
80718
80786
|
_pointerLock = new PointerLockManager();
|
|
80719
80787
|
_modeShortcuts = new ModeShortcuts();
|
|
80720
80788
|
_inputModeTracker = new InputModeTracker();
|
|
80721
80789
|
set collision(value) {
|
|
80722
|
-
this.
|
|
80790
|
+
this._navInteraction.collision = value;
|
|
80723
80791
|
}
|
|
80724
80792
|
get collision() {
|
|
80725
|
-
return this.
|
|
80793
|
+
return this._navInteraction.collision;
|
|
80726
80794
|
}
|
|
80727
80795
|
constructor(global, picker) {
|
|
80728
80796
|
this._global = global;
|
|
80729
|
-
this.
|
|
80797
|
+
this._navInteraction = new NavInteraction(picker);
|
|
80730
80798
|
const { app, events } = global;
|
|
80731
80799
|
const canvas = app.graphicsDevice.canvas;
|
|
80732
80800
|
// Trackpad MUST attach before KeyboardMouseDevice so its wheel
|
|
@@ -80736,7 +80804,7 @@ class InputController {
|
|
|
80736
80804
|
this._keyboardMouse.attach(canvas, global);
|
|
80737
80805
|
this._touch.attach(canvas, global);
|
|
80738
80806
|
this._gamepad.attach(canvas, global);
|
|
80739
|
-
this.
|
|
80807
|
+
this._navInteraction.attach(canvas, global);
|
|
80740
80808
|
this._pointerLock.attach(canvas, global, this._keyboardMouse);
|
|
80741
80809
|
this._modeShortcuts.attach(global, this._pointerLock);
|
|
80742
80810
|
this._inputModeTracker.attach(global);
|
|
@@ -81196,8 +81264,18 @@ const vec4 = new Vec4();
|
|
|
81196
81264
|
const viewProjMat = new Mat4();
|
|
81197
81265
|
const clearColor = new Color(0, 0, 0, 1);
|
|
81198
81266
|
const NORMAL_EPSILON$1 = 1e-12;
|
|
81199
|
-
const
|
|
81200
|
-
|
|
81267
|
+
const NORMAL_DEGENERATE_EPSILON = 1e-20;
|
|
81268
|
+
// Sampling for the surface-normal estimator runs on a circular footprint of
|
|
81269
|
+
// fixed *world* radius, projected to pixels at the picked-point's depth.
|
|
81270
|
+
// Keeping the world area constant means adjacent cursor positions sample
|
|
81271
|
+
// almost the same world cluster, which stabilises the plane fit. The pixel
|
|
81272
|
+
// radius is clamped so distant picks still get enough samples and very-close
|
|
81273
|
+
// picks don't blow the block read.
|
|
81274
|
+
const NORMAL_SAMPLE_WORLD_RADIUS = 0.2;
|
|
81275
|
+
const NORMAL_SAMPLE_MIN_PX = 6;
|
|
81276
|
+
const NORMAL_SAMPLE_MAX_PX = 48;
|
|
81277
|
+
const NORMAL_RING_FRACTIONS = [0.3, 0.55, 0.8, 1.0];
|
|
81278
|
+
const NORMAL_OUTLIER_THRESHOLD = 2.5;
|
|
81201
81279
|
const NORMAL_SAMPLE_DIRECTIONS = [
|
|
81202
81280
|
[1, 0],
|
|
81203
81281
|
[1, 1],
|
|
@@ -81285,7 +81363,24 @@ const unregisterPickerShaderPatches = (app) => {
|
|
|
81285
81363
|
wgslChunks.set('gsplatPS', state.wgslGsplatPS);
|
|
81286
81364
|
pickerShaderPatchState.delete(device);
|
|
81287
81365
|
};
|
|
81288
|
-
const
|
|
81366
|
+
const createPickCameraSnapshot = () => ({
|
|
81367
|
+
position: new Vec3(),
|
|
81368
|
+
viewMatrix: new Mat4(),
|
|
81369
|
+
projectionMatrix: new Mat4(),
|
|
81370
|
+
nearClip: 0,
|
|
81371
|
+
farClip: 0,
|
|
81372
|
+
projection: 0
|
|
81373
|
+
});
|
|
81374
|
+
const captureCameraSnapshot = (camera, out) => {
|
|
81375
|
+
const cam = camera.camera;
|
|
81376
|
+
out.position.copy(camera.getPosition());
|
|
81377
|
+
out.viewMatrix.copy(cam.viewMatrix);
|
|
81378
|
+
out.projectionMatrix.copy(cam.projectionMatrix);
|
|
81379
|
+
out.nearClip = cam.nearClip;
|
|
81380
|
+
out.farClip = cam.farClip;
|
|
81381
|
+
out.projection = cam.projection;
|
|
81382
|
+
};
|
|
81383
|
+
const getWorldPoint = (camera, x, y, width, height, normalizedDepth, out) => {
|
|
81289
81384
|
if (!Number.isFinite(normalizedDepth) || normalizedDepth < 0 || normalizedDepth > 1) {
|
|
81290
81385
|
return null;
|
|
81291
81386
|
}
|
|
@@ -81303,7 +81398,7 @@ const getWorldPoint = (camera, x, y, width, height, normalizedDepth) => {
|
|
|
81303
81398
|
if (!Number.isFinite(vec4.x) || !Number.isFinite(vec4.y) || !Number.isFinite(vec4.z)) {
|
|
81304
81399
|
return null;
|
|
81305
81400
|
}
|
|
81306
|
-
return new Vec3(vec4.x, vec4.y, vec4.z);
|
|
81401
|
+
return (out ?? new Vec3()).set(vec4.x, vec4.y, vec4.z);
|
|
81307
81402
|
};
|
|
81308
81403
|
const setCameraFacingNormal = (cameraPosition, position, normal) => {
|
|
81309
81404
|
normal.sub2(cameraPosition, position);
|
|
@@ -81316,6 +81411,145 @@ const setCameraFacingNormal = (cameraPosition, position, normal) => {
|
|
|
81316
81411
|
}
|
|
81317
81412
|
return normal;
|
|
81318
81413
|
};
|
|
81414
|
+
// Project a world-space radius around `pos` to its on-screen pixel radius for
|
|
81415
|
+
// the given camera. Uses the projection matrix's [1][1] entry (= 1/tan(fov/2)
|
|
81416
|
+
// for perspective, = 1/orthoHeight for orthographic) so we don't need fov or
|
|
81417
|
+
// orthoHeight on the snapshot.
|
|
81418
|
+
const worldRadiusToPixelRadius = (cam, pos, canvasHeight, worldRadius) => {
|
|
81419
|
+
const projY = cam.projectionMatrix.data[5];
|
|
81420
|
+
if (cam.projection === PROJECTION_ORTHOGRAPHIC) {
|
|
81421
|
+
return worldRadius * projY * canvasHeight / 2;
|
|
81422
|
+
}
|
|
81423
|
+
const dx = pos.x - cam.position.x;
|
|
81424
|
+
const dy = pos.y - cam.position.y;
|
|
81425
|
+
const dz = pos.z - cam.position.z;
|
|
81426
|
+
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
81427
|
+
if (distance < 1e-6)
|
|
81428
|
+
return Infinity;
|
|
81429
|
+
return worldRadius * projY * canvasHeight / (2 * distance);
|
|
81430
|
+
};
|
|
81431
|
+
// Single least-squares plane fit through a cluster of 3D points. The normal
|
|
81432
|
+
// is the eigenvector of the smallest eigenvalue of the points' 3x3 covariance
|
|
81433
|
+
// matrix, computed in closed form (analytic eigendecomposition for 3x3
|
|
81434
|
+
// symmetric, Smith 1961). Returns null on degenerate input.
|
|
81435
|
+
const fitPlaneOnce = (points) => {
|
|
81436
|
+
const n = points.length;
|
|
81437
|
+
if (n < 3)
|
|
81438
|
+
return null;
|
|
81439
|
+
let cx = 0, cy = 0, cz = 0;
|
|
81440
|
+
for (let i = 0; i < n; i++) {
|
|
81441
|
+
cx += points[i].x;
|
|
81442
|
+
cy += points[i].y;
|
|
81443
|
+
cz += points[i].z;
|
|
81444
|
+
}
|
|
81445
|
+
cx /= n;
|
|
81446
|
+
cy /= n;
|
|
81447
|
+
cz /= n;
|
|
81448
|
+
let cxx = 0, cxy = 0, cxz = 0, cyy = 0, cyz = 0, czz = 0;
|
|
81449
|
+
for (let i = 0; i < n; i++) {
|
|
81450
|
+
const dx = points[i].x - cx;
|
|
81451
|
+
const dy = points[i].y - cy;
|
|
81452
|
+
const dz = points[i].z - cz;
|
|
81453
|
+
cxx += dx * dx;
|
|
81454
|
+
cxy += dx * dy;
|
|
81455
|
+
cxz += dx * dz;
|
|
81456
|
+
cyy += dy * dy;
|
|
81457
|
+
cyz += dy * dz;
|
|
81458
|
+
czz += dz * dz;
|
|
81459
|
+
}
|
|
81460
|
+
const q = (cxx + cyy + czz) / 3;
|
|
81461
|
+
const a = cxx - q, b = cyy - q, c = czz - q;
|
|
81462
|
+
const p2 = a * a + b * b + c * c + 2 * (cxy * cxy + cxz * cxz + cyz * cyz);
|
|
81463
|
+
if (p2 < NORMAL_DEGENERATE_EPSILON)
|
|
81464
|
+
return null;
|
|
81465
|
+
const p = Math.sqrt(p2 / 6);
|
|
81466
|
+
const inv = 1 / p;
|
|
81467
|
+
const Bxx = a * inv, Bxy = cxy * inv, Bxz = cxz * inv;
|
|
81468
|
+
const Byy = b * inv, Byz = cyz * inv, Bzz = c * inv;
|
|
81469
|
+
const detB = Bxx * (Byy * Bzz - Byz * Byz) -
|
|
81470
|
+
Bxy * (Bxy * Bzz - Byz * Bxz) +
|
|
81471
|
+
Bxz * (Bxy * Byz - Byy * Bxz);
|
|
81472
|
+
const r = Math.max(-1, Math.min(1, detB / 2));
|
|
81473
|
+
const phi = Math.acos(r) / 3;
|
|
81474
|
+
const lambdaMin = q + 2 * p * Math.cos(phi + 2 * Math.PI / 3);
|
|
81475
|
+
const Mxx = cxx - lambdaMin, Myy = cyy - lambdaMin, Mzz = czz - lambdaMin;
|
|
81476
|
+
const v1x = cxy * cyz - cxz * Myy;
|
|
81477
|
+
const v1y = cxz * cxy - Mxx * cyz;
|
|
81478
|
+
const v1z = Mxx * Myy - cxy * cxy;
|
|
81479
|
+
const v2x = cxy * Mzz - cxz * cyz;
|
|
81480
|
+
const v2y = cxz * cxz - Mxx * Mzz;
|
|
81481
|
+
const v2z = Mxx * cyz - cxy * cxz;
|
|
81482
|
+
const v3x = Myy * Mzz - cyz * cyz;
|
|
81483
|
+
const v3y = cyz * cxz - cxy * Mzz;
|
|
81484
|
+
const v3z = cxy * cyz - Myy * cxz;
|
|
81485
|
+
const l1 = v1x * v1x + v1y * v1y + v1z * v1z;
|
|
81486
|
+
const l2 = v2x * v2x + v2y * v2y + v2z * v2z;
|
|
81487
|
+
const l3 = v3x * v3x + v3y * v3y + v3z * v3z;
|
|
81488
|
+
let vx, vy, vz, lSq;
|
|
81489
|
+
if (l1 >= l2 && l1 >= l3) {
|
|
81490
|
+
vx = v1x;
|
|
81491
|
+
vy = v1y;
|
|
81492
|
+
vz = v1z;
|
|
81493
|
+
lSq = l1;
|
|
81494
|
+
}
|
|
81495
|
+
else if (l2 >= l3) {
|
|
81496
|
+
vx = v2x;
|
|
81497
|
+
vy = v2y;
|
|
81498
|
+
vz = v2z;
|
|
81499
|
+
lSq = l2;
|
|
81500
|
+
}
|
|
81501
|
+
else {
|
|
81502
|
+
vx = v3x;
|
|
81503
|
+
vy = v3y;
|
|
81504
|
+
vz = v3z;
|
|
81505
|
+
lSq = l3;
|
|
81506
|
+
}
|
|
81507
|
+
if (lSq < NORMAL_EPSILON$1)
|
|
81508
|
+
return null;
|
|
81509
|
+
const invLen = 1 / Math.sqrt(lSq);
|
|
81510
|
+
return { cx, cy, cz, vx: vx * invLen, vy: vy * invLen, vz: vz * invLen };
|
|
81511
|
+
};
|
|
81512
|
+
// Two-pass plane fit: first pass on all points, then drop points whose
|
|
81513
|
+
// distance from the fitted plane exceeds NORMAL_OUTLIER_THRESHOLD * the mean
|
|
81514
|
+
// residual, refit on the inliers. Sign-flips the result toward toCamera so
|
|
81515
|
+
// the cursor's tangent basis stays consistent. Returns false on degenerate
|
|
81516
|
+
// input (fewer than 3 points, collinear/coincident samples).
|
|
81517
|
+
const fitPlaneNormal = (points, toCamera, outNormal) => {
|
|
81518
|
+
const first = fitPlaneOnce(points);
|
|
81519
|
+
if (!first)
|
|
81520
|
+
return false;
|
|
81521
|
+
let residualSum = 0;
|
|
81522
|
+
for (let i = 0; i < points.length; i++) {
|
|
81523
|
+
const dx = points[i].x - first.cx;
|
|
81524
|
+
const dy = points[i].y - first.cy;
|
|
81525
|
+
const dz = points[i].z - first.cz;
|
|
81526
|
+
residualSum += Math.abs(dx * first.vx + dy * first.vy + dz * first.vz);
|
|
81527
|
+
}
|
|
81528
|
+
const threshold = (residualSum / points.length) * NORMAL_OUTLIER_THRESHOLD;
|
|
81529
|
+
const inliers = [];
|
|
81530
|
+
for (let i = 0; i < points.length; i++) {
|
|
81531
|
+
const dx = points[i].x - first.cx;
|
|
81532
|
+
const dy = points[i].y - first.cy;
|
|
81533
|
+
const dz = points[i].z - first.cz;
|
|
81534
|
+
if (Math.abs(dx * first.vx + dy * first.vy + dz * first.vz) <= threshold) {
|
|
81535
|
+
inliers.push(points[i]);
|
|
81536
|
+
}
|
|
81537
|
+
}
|
|
81538
|
+
let result = first;
|
|
81539
|
+
if (inliers.length >= 3 && inliers.length < points.length) {
|
|
81540
|
+
const refined = fitPlaneOnce(inliers);
|
|
81541
|
+
if (refined)
|
|
81542
|
+
result = refined;
|
|
81543
|
+
}
|
|
81544
|
+
let { vx, vy, vz } = result;
|
|
81545
|
+
if (vx * toCamera.x + vy * toCamera.y + vz * toCamera.z < 0) {
|
|
81546
|
+
vx = -vx;
|
|
81547
|
+
vy = -vy;
|
|
81548
|
+
vz = -vz;
|
|
81549
|
+
}
|
|
81550
|
+
outNormal.set(vx, vy, vz);
|
|
81551
|
+
return true;
|
|
81552
|
+
};
|
|
81319
81553
|
class Picker {
|
|
81320
81554
|
pick;
|
|
81321
81555
|
pickSurface;
|
|
@@ -81328,14 +81562,10 @@ class Picker {
|
|
|
81328
81562
|
let accumPass;
|
|
81329
81563
|
let chunksPatched = false;
|
|
81330
81564
|
let pickQueue = Promise.resolve();
|
|
81331
|
-
|
|
81332
|
-
|
|
81333
|
-
|
|
81334
|
-
|
|
81335
|
-
nearClip: 0,
|
|
81336
|
-
farClip: 0,
|
|
81337
|
-
projection: 0
|
|
81338
|
-
};
|
|
81565
|
+
let cacheValid = false;
|
|
81566
|
+
let cacheWidth = 0;
|
|
81567
|
+
let cacheHeight = 0;
|
|
81568
|
+
const cacheCamera = createPickCameraSnapshot();
|
|
81339
81569
|
const initRasterAccum = (width, height) => {
|
|
81340
81570
|
accumBuffer = new Texture(graphicsDevice, {
|
|
81341
81571
|
format: PIXELFORMAT_RGBA16F,
|
|
@@ -81363,24 +81593,31 @@ class Picker {
|
|
|
81363
81593
|
immediate: true
|
|
81364
81594
|
});
|
|
81365
81595
|
};
|
|
81366
|
-
const updateCache = () => {
|
|
81596
|
+
const updateCache = (width, height) => {
|
|
81597
|
+
captureCameraSnapshot(camera, cacheCamera);
|
|
81598
|
+
cacheWidth = width;
|
|
81599
|
+
cacheHeight = height;
|
|
81600
|
+
};
|
|
81601
|
+
const cameraMatches = (width, height) => {
|
|
81367
81602
|
const cam = camera.camera;
|
|
81368
|
-
|
|
81369
|
-
|
|
81370
|
-
|
|
81371
|
-
|
|
81372
|
-
|
|
81373
|
-
|
|
81603
|
+
return cacheValid &&
|
|
81604
|
+
cacheWidth === width &&
|
|
81605
|
+
cacheHeight === height &&
|
|
81606
|
+
cacheCamera.viewMatrix.equals(cam.viewMatrix) &&
|
|
81607
|
+
cacheCamera.projectionMatrix.equals(cam.projectionMatrix) &&
|
|
81608
|
+
cacheCamera.nearClip === cam.nearClip &&
|
|
81609
|
+
cacheCamera.farClip === cam.farClip &&
|
|
81610
|
+
cacheCamera.projection === cam.projection;
|
|
81374
81611
|
};
|
|
81375
81612
|
const getCacheCameraSnapshot = () => {
|
|
81376
|
-
|
|
81377
|
-
|
|
81378
|
-
|
|
81379
|
-
|
|
81380
|
-
|
|
81381
|
-
|
|
81382
|
-
|
|
81383
|
-
|
|
81613
|
+
const snapshot = createPickCameraSnapshot();
|
|
81614
|
+
snapshot.position.copy(cacheCamera.position);
|
|
81615
|
+
snapshot.viewMatrix.copy(cacheCamera.viewMatrix);
|
|
81616
|
+
snapshot.projectionMatrix.copy(cacheCamera.projectionMatrix);
|
|
81617
|
+
snapshot.nearClip = cacheCamera.nearClip;
|
|
81618
|
+
snapshot.farClip = cacheCamera.farClip;
|
|
81619
|
+
snapshot.projection = cacheCamera.projection;
|
|
81620
|
+
return snapshot;
|
|
81384
81621
|
};
|
|
81385
81622
|
const readRasterBlock = async (blockX, blockY, blockWidth, blockHeight, viewportWidth, viewportHeight, pickCamera) => {
|
|
81386
81623
|
const texY = graphicsDevice.isWebGL2 ? accumTarget.height - blockY - blockHeight : blockY;
|
|
@@ -81406,20 +81643,10 @@ class Picker {
|
|
|
81406
81643
|
return getWorldPoint(pickCamera, x, y, viewportWidth, viewportHeight, normalizedDepth);
|
|
81407
81644
|
};
|
|
81408
81645
|
};
|
|
81409
|
-
const
|
|
81410
|
-
|
|
81411
|
-
|
|
81412
|
-
// bail out if the device hasn't been sized yet
|
|
81413
|
-
if (width <= 0 || height <= 0) {
|
|
81414
|
-
return null;
|
|
81415
|
-
}
|
|
81416
|
-
const screenX = Math.min(width - 1, Math.max(0, Math.floor(x * width)));
|
|
81417
|
-
const screenY = Math.min(height - 1, Math.max(0, Math.floor(y * height)));
|
|
81418
|
-
const worldLayer = app.scene.layers.getLayerByName('World');
|
|
81419
|
-
if (!worldLayer) {
|
|
81420
|
-
return null;
|
|
81646
|
+
const ensureRendered = (width, height, isComputeRenderer, worldLayer) => {
|
|
81647
|
+
if (cameraMatches(width, height)) {
|
|
81648
|
+
return;
|
|
81421
81649
|
}
|
|
81422
|
-
const isComputeRenderer = app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE;
|
|
81423
81650
|
// Enable gsplat IDs only while rendering the pick target so we
|
|
81424
81651
|
// don't pay the memory/perf cost between pick passes.
|
|
81425
81652
|
const prevEnableIds = app.scene.gsplat.enableIds;
|
|
@@ -81438,7 +81665,8 @@ class Picker {
|
|
|
81438
81665
|
if (!accumPass) {
|
|
81439
81666
|
initRasterAccum(width, height);
|
|
81440
81667
|
}
|
|
81441
|
-
else {
|
|
81668
|
+
else if (cacheWidth !== width || cacheHeight !== height) {
|
|
81669
|
+
cacheValid = false;
|
|
81442
81670
|
accumTarget.resize(width, height);
|
|
81443
81671
|
}
|
|
81444
81672
|
accumPass.init(accumTarget);
|
|
@@ -81446,12 +81674,37 @@ class Picker {
|
|
|
81446
81674
|
accumPass.update(camera.camera, app.scene, [worldLayer], new Map(), false);
|
|
81447
81675
|
accumPass.render();
|
|
81448
81676
|
}
|
|
81449
|
-
updateCache();
|
|
81677
|
+
updateCache(width, height);
|
|
81678
|
+
cacheValid = true;
|
|
81450
81679
|
}
|
|
81451
81680
|
finally {
|
|
81452
81681
|
app.scene.gsplat.enableIds = prevEnableIds;
|
|
81453
81682
|
}
|
|
81683
|
+
};
|
|
81684
|
+
const prepareSample = (x, y) => {
|
|
81685
|
+
const width = Math.floor(graphicsDevice.width);
|
|
81686
|
+
const height = Math.floor(graphicsDevice.height);
|
|
81687
|
+
// bail out if the device hasn't been sized yet
|
|
81688
|
+
if (width <= 0 || height <= 0) {
|
|
81689
|
+
return null;
|
|
81690
|
+
}
|
|
81691
|
+
const worldLayer = app.scene.layers.getLayerByName('World');
|
|
81692
|
+
if (!worldLayer) {
|
|
81693
|
+
return null;
|
|
81694
|
+
}
|
|
81695
|
+
const screenX = Math.min(width - 1, Math.max(0, Math.floor(x * width)));
|
|
81696
|
+
const screenY = Math.min(height - 1, Math.max(0, Math.floor(y * height)));
|
|
81697
|
+
const isComputeRenderer = app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE;
|
|
81698
|
+
ensureRendered(width, height, isComputeRenderer, worldLayer);
|
|
81454
81699
|
const pickCamera = getCacheCameraSnapshot();
|
|
81700
|
+
return { width, height, screenX, screenY, isComputeRenderer, pickCamera };
|
|
81701
|
+
};
|
|
81702
|
+
const pickPosition = async (x, y) => {
|
|
81703
|
+
const sample = prepareSample(x, y);
|
|
81704
|
+
if (!sample) {
|
|
81705
|
+
return null;
|
|
81706
|
+
}
|
|
81707
|
+
const { width, height, screenX, screenY, isComputeRenderer, pickCamera } = sample;
|
|
81455
81708
|
if (isComputeRenderer) {
|
|
81456
81709
|
const normalizedDepth = await enginePicker.getPointDepthAsync(screenX, screenY);
|
|
81457
81710
|
const position = normalizedDepth !== null ?
|
|
@@ -81481,83 +81734,66 @@ class Picker {
|
|
|
81481
81734
|
return result?.position ?? null;
|
|
81482
81735
|
};
|
|
81483
81736
|
const pickSurface = async (x, y) => {
|
|
81484
|
-
const
|
|
81485
|
-
if (!
|
|
81737
|
+
const sample = prepareSample(x, y);
|
|
81738
|
+
if (!sample) {
|
|
81486
81739
|
return null;
|
|
81487
81740
|
}
|
|
81488
|
-
const {
|
|
81489
|
-
if (
|
|
81741
|
+
const { width, height, screenX, screenY, isComputeRenderer, pickCamera } = sample;
|
|
81742
|
+
if (isComputeRenderer) {
|
|
81743
|
+
const normalizedDepth = await enginePicker.getPointDepthAsync(screenX, screenY);
|
|
81744
|
+
const position = normalizedDepth !== null ?
|
|
81745
|
+
getWorldPoint(pickCamera, screenX, screenY, width, height, normalizedDepth) :
|
|
81746
|
+
null;
|
|
81747
|
+
if (!position) {
|
|
81748
|
+
return null;
|
|
81749
|
+
}
|
|
81490
81750
|
return {
|
|
81491
81751
|
position,
|
|
81492
|
-
normal:
|
|
81752
|
+
normal: new Vec3(0, 1, 0)
|
|
81493
81753
|
};
|
|
81494
81754
|
}
|
|
81495
|
-
|
|
81496
|
-
|
|
81497
|
-
|
|
81498
|
-
const
|
|
81499
|
-
const
|
|
81500
|
-
const
|
|
81755
|
+
// Single block read serves both depth (center pixel) and normal
|
|
81756
|
+
// samples. Sized to the maximum possible ring pixel-radius so the
|
|
81757
|
+
// dynamic ring offsets always lie inside the buffer we read.
|
|
81758
|
+
const blockX = Math.max(0, screenX - NORMAL_SAMPLE_MAX_PX);
|
|
81759
|
+
const blockY = Math.max(0, screenY - NORMAL_SAMPLE_MAX_PX);
|
|
81760
|
+
const blockWidth = Math.min(width - 1, screenX + NORMAL_SAMPLE_MAX_PX) - blockX + 1;
|
|
81761
|
+
const blockHeight = Math.min(height - 1, screenY + NORMAL_SAMPLE_MAX_PX) - blockY + 1;
|
|
81762
|
+
const rasterBlock = await readRasterBlock(blockX, blockY, blockWidth, blockHeight, width, height, pickCamera);
|
|
81763
|
+
const position = rasterBlock(screenX, screenY);
|
|
81764
|
+
if (!position) {
|
|
81765
|
+
return null;
|
|
81766
|
+
}
|
|
81501
81767
|
const samplePixel = (px, py) => {
|
|
81502
81768
|
if (px < 0 || px >= width || py < 0 || py >= height) {
|
|
81503
|
-
return
|
|
81769
|
+
return null;
|
|
81504
81770
|
}
|
|
81505
|
-
return
|
|
81771
|
+
return rasterBlock(px, py);
|
|
81506
81772
|
};
|
|
81507
|
-
|
|
81508
|
-
|
|
81509
|
-
|
|
81510
|
-
|
|
81511
|
-
|
|
81512
|
-
|
|
81513
|
-
|
|
81514
|
-
|
|
81515
|
-
const candidates = [];
|
|
81516
|
-
const va = new Vec3();
|
|
81517
|
-
const vb = new Vec3();
|
|
81518
|
-
const sampleNormal = new Vec3();
|
|
81519
|
-
sampleRings.forEach((points) => {
|
|
81520
|
-
for (let i = 0; i < NORMAL_SAMPLE_DIRECTIONS.length; i++) {
|
|
81521
|
-
const pointA = points[i];
|
|
81522
|
-
const pointB = points[(i + 1) % NORMAL_SAMPLE_DIRECTIONS.length];
|
|
81523
|
-
if (!pointA || !pointB) {
|
|
81524
|
-
continue;
|
|
81525
|
-
}
|
|
81526
|
-
va.sub2(pointA, position);
|
|
81527
|
-
vb.sub2(pointB, position);
|
|
81528
|
-
if (va.lengthSq() <= NORMAL_EPSILON$1 || vb.lengthSq() <= NORMAL_EPSILON$1) {
|
|
81529
|
-
continue;
|
|
81530
|
-
}
|
|
81531
|
-
// Direction order is clockwise in screen space. Screen Y points
|
|
81532
|
-
// down, so crossing next by current gives a camera-facing normal.
|
|
81533
|
-
sampleNormal.cross(vb, va);
|
|
81534
|
-
if (sampleNormal.lengthSq() <= NORMAL_EPSILON$1) {
|
|
81535
|
-
continue;
|
|
81536
|
-
}
|
|
81537
|
-
const candidate = sampleNormal.clone().normalize();
|
|
81538
|
-
if (candidate.dot(toCamera) < 0) {
|
|
81539
|
-
candidate.mulScalar(-1);
|
|
81540
|
-
}
|
|
81541
|
-
candidates.push(candidate);
|
|
81542
|
-
}
|
|
81543
|
-
});
|
|
81544
|
-
const normal = new Vec3();
|
|
81545
|
-
candidates.forEach((candidate) => {
|
|
81546
|
-
normal.add(candidate);
|
|
81547
|
-
});
|
|
81548
|
-
if (normal.lengthSq() > NORMAL_EPSILON$1) {
|
|
81549
|
-
normal.normalize();
|
|
81550
|
-
const refined = new Vec3();
|
|
81551
|
-
candidates.forEach((candidate) => {
|
|
81552
|
-
if (candidate.dot(normal) >= NORMAL_OUTLIER_MIN_DOT) {
|
|
81553
|
-
refined.add(candidate);
|
|
81554
|
-
}
|
|
81773
|
+
// Pixel radius corresponding to a fixed world radius at the
|
|
81774
|
+
// picked-point's depth. Clamped so distant picks still sample
|
|
81775
|
+
// enough pixels and very-close picks stay inside the block read.
|
|
81776
|
+
const pixelRadius = Math.max(NORMAL_SAMPLE_MIN_PX, Math.min(NORMAL_SAMPLE_MAX_PX, worldRadiusToPixelRadius(pickCamera, position, height, NORMAL_SAMPLE_WORLD_RADIUS)));
|
|
81777
|
+
const ringPixelRadii = NORMAL_RING_FRACTIONS.map(f => Math.max(1, Math.round(f * pixelRadius)));
|
|
81778
|
+
const sampleRings = ringPixelRadii.map((radius) => {
|
|
81779
|
+
return NORMAL_SAMPLE_DIRECTIONS.map(([dx, dy]) => {
|
|
81780
|
+
return samplePixel(screenX + dx * radius, screenY + dy * radius);
|
|
81555
81781
|
});
|
|
81556
|
-
|
|
81557
|
-
|
|
81782
|
+
});
|
|
81783
|
+
const toCamera = setCameraFacingNormal(pickCamera.position, position, new Vec3());
|
|
81784
|
+
// Collect every valid 3D sample: the picked position plus all ring
|
|
81785
|
+
// samples that didn't fall off-screen or fail the depth read.
|
|
81786
|
+
const fitPoints = [position];
|
|
81787
|
+
for (let i = 0; i < sampleRings.length; i++) {
|
|
81788
|
+
const ring = sampleRings[i];
|
|
81789
|
+
for (let j = 0; j < ring.length; j++) {
|
|
81790
|
+
const pt = ring[j];
|
|
81791
|
+
if (pt)
|
|
81792
|
+
fitPoints.push(pt);
|
|
81558
81793
|
}
|
|
81559
81794
|
}
|
|
81560
|
-
|
|
81795
|
+
const normal = new Vec3();
|
|
81796
|
+
if (!fitPlaneNormal(fitPoints, toCamera, normal)) {
|
|
81561
81797
|
normal.copy(toCamera);
|
|
81562
81798
|
}
|
|
81563
81799
|
return {
|
|
@@ -81576,10 +81812,515 @@ class Picker {
|
|
|
81576
81812
|
accumPass?.destroy();
|
|
81577
81813
|
accumTarget?.destroy();
|
|
81578
81814
|
accumBuffer?.destroy();
|
|
81815
|
+
cacheValid = false;
|
|
81579
81816
|
};
|
|
81580
81817
|
}
|
|
81581
81818
|
}
|
|
81582
81819
|
|
|
81820
|
+
const SVGNS = 'http://www.w3.org/2000/svg';
|
|
81821
|
+
const NUM_SAMPLES = 12;
|
|
81822
|
+
const BASE_OUTER_RADIUS = 0.2;
|
|
81823
|
+
const INNER_OUTER_RATIO = 0.17 / 0.2;
|
|
81824
|
+
// Scenes with halfExtents.length() below this are smaller than the walk
|
|
81825
|
+
// capsule (~1.5 m) — not navigable in walk mode and the world-space ring
|
|
81826
|
+
// engulfs the whole scene. Switch the cursor to a fixed screen size instead.
|
|
81827
|
+
const SMALL_SCENE_THRESHOLD = 2;
|
|
81828
|
+
const SCREEN_OUTER_PIXELS = 60;
|
|
81829
|
+
const BEZIER_K = 1 / 6;
|
|
81830
|
+
const NORMAL_SMOOTH_FACTOR = 0.25;
|
|
81831
|
+
const NORMAL_SNAP_ANGLE = Math.PI / 4;
|
|
81832
|
+
const NORMAL_EPSILON = 1e-6;
|
|
81833
|
+
const createNormalSnapDirections = () => {
|
|
81834
|
+
const result = [];
|
|
81835
|
+
for (let pitchStep = -2; pitchStep <= 2; pitchStep++) {
|
|
81836
|
+
const pitch = pitchStep * NORMAL_SNAP_ANGLE;
|
|
81837
|
+
const cp = Math.cos(pitch);
|
|
81838
|
+
const sy = Math.sin(pitch);
|
|
81839
|
+
if (Math.abs(cp) <= NORMAL_EPSILON) {
|
|
81840
|
+
result.push(new Vec3(0, sy > 0 ? 1 : -1, 0));
|
|
81841
|
+
continue;
|
|
81842
|
+
}
|
|
81843
|
+
for (let yawStep = 0; yawStep < 8; yawStep++) {
|
|
81844
|
+
const yaw = yawStep * NORMAL_SNAP_ANGLE;
|
|
81845
|
+
result.push(new Vec3(Math.cos(yaw) * cp, sy, Math.sin(yaw) * cp));
|
|
81846
|
+
}
|
|
81847
|
+
}
|
|
81848
|
+
return result;
|
|
81849
|
+
};
|
|
81850
|
+
const NORMAL_SNAP_DIRECTIONS = createNormalSnapDirections();
|
|
81851
|
+
const snapNormal = (nx, ny, nz, out) => {
|
|
81852
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
81853
|
+
if (len <= NORMAL_EPSILON) {
|
|
81854
|
+
return out.set(0, 1, 0);
|
|
81855
|
+
}
|
|
81856
|
+
const invLen = 1 / len;
|
|
81857
|
+
const x = nx * invLen;
|
|
81858
|
+
const y = ny * invLen;
|
|
81859
|
+
const z = nz * invLen;
|
|
81860
|
+
let best = NORMAL_SNAP_DIRECTIONS[0];
|
|
81861
|
+
let bestDot = -Infinity;
|
|
81862
|
+
for (let i = 0; i < NORMAL_SNAP_DIRECTIONS.length; i++) {
|
|
81863
|
+
const candidate = NORMAL_SNAP_DIRECTIONS[i];
|
|
81864
|
+
const dot = candidate.x * x + candidate.y * y + candidate.z * z;
|
|
81865
|
+
if (dot > bestDot) {
|
|
81866
|
+
bestDot = dot;
|
|
81867
|
+
best = candidate;
|
|
81868
|
+
}
|
|
81869
|
+
}
|
|
81870
|
+
return out.copy(best);
|
|
81871
|
+
};
|
|
81872
|
+
const tmpV = new Vec3();
|
|
81873
|
+
const tmpScreen = new Vec3();
|
|
81874
|
+
const tangent = new Vec3();
|
|
81875
|
+
const bitangent = new Vec3();
|
|
81876
|
+
const worldPt = new Vec3();
|
|
81877
|
+
const up = new Vec3(0, 1, 0);
|
|
81878
|
+
const right = new Vec3(1, 0, 0);
|
|
81879
|
+
const tmpViewPos = new Vec3();
|
|
81880
|
+
const tmpClipVec = new Vec4();
|
|
81881
|
+
const tmpViewProj = new Mat4();
|
|
81882
|
+
// Compute the world-space radius such that a circle at `pos` projects to a
|
|
81883
|
+
// ring of `pixelDiameter` on screen. Used for the small-scene cursor mode
|
|
81884
|
+
// where we want a constant screen size regardless of zoom.
|
|
81885
|
+
const worldRadiusForPixels = (camera, canvasHeight, pos, pixelDiameter) => {
|
|
81886
|
+
const cam = camera.camera;
|
|
81887
|
+
if (cam.projection === PROJECTION_ORTHOGRAPHIC) {
|
|
81888
|
+
return pixelDiameter * cam.orthoHeight / canvasHeight;
|
|
81889
|
+
}
|
|
81890
|
+
const camPos = camera.getPosition();
|
|
81891
|
+
const dx = pos.x - camPos.x;
|
|
81892
|
+
const dy = pos.y - camPos.y;
|
|
81893
|
+
const dz = pos.z - camPos.z;
|
|
81894
|
+
const distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
81895
|
+
const halfFovTan = Math.tan(cam.fov * Math.PI / 360);
|
|
81896
|
+
return pixelDiameter * distance * halfFovTan / canvasHeight;
|
|
81897
|
+
};
|
|
81898
|
+
const worldPointToDepth = (camera, worldPos) => {
|
|
81899
|
+
if (camera.projection === PROJECTION_ORTHOGRAPHIC) {
|
|
81900
|
+
tmpViewProj.mul2(camera.projectionMatrix, camera.viewMatrix);
|
|
81901
|
+
tmpClipVec.set(worldPos.x, worldPos.y, worldPos.z, 1);
|
|
81902
|
+
tmpViewProj.transformVec4(tmpClipVec, tmpClipVec);
|
|
81903
|
+
if (Math.abs(tmpClipVec.w) < 1e-8) {
|
|
81904
|
+
return -1;
|
|
81905
|
+
}
|
|
81906
|
+
return (tmpClipVec.z / tmpClipVec.w + 1) * 0.5;
|
|
81907
|
+
}
|
|
81908
|
+
camera.viewMatrix.transformPoint(worldPos, tmpViewPos);
|
|
81909
|
+
const linearDepth = -tmpViewPos.z;
|
|
81910
|
+
const range = camera.farClip - camera.nearClip;
|
|
81911
|
+
if (range <= 0) {
|
|
81912
|
+
return -1;
|
|
81913
|
+
}
|
|
81914
|
+
return (linearDepth - camera.nearClip) / range;
|
|
81915
|
+
};
|
|
81916
|
+
const createSurfaceSample = () => ({
|
|
81917
|
+
normalizedDepth: 0,
|
|
81918
|
+
normal: new Vec3(),
|
|
81919
|
+
camera: {
|
|
81920
|
+
position: new Vec3(),
|
|
81921
|
+
viewMatrix: new Mat4(),
|
|
81922
|
+
projectionMatrix: new Mat4(),
|
|
81923
|
+
nearClip: 0,
|
|
81924
|
+
farClip: 0,
|
|
81925
|
+
projection: 0
|
|
81926
|
+
},
|
|
81927
|
+
width: 0,
|
|
81928
|
+
height: 0
|
|
81929
|
+
});
|
|
81930
|
+
const buildBezierRing = (sx, sy) => {
|
|
81931
|
+
const n = sx.length;
|
|
81932
|
+
let p = `M${sx[0].toFixed(1)},${sy[0].toFixed(1)}`;
|
|
81933
|
+
for (let i = 0; i < n; i++) {
|
|
81934
|
+
const i0 = (i - 1 + n) % n;
|
|
81935
|
+
const i1 = i;
|
|
81936
|
+
const i2 = (i + 1) % n;
|
|
81937
|
+
const i3 = (i + 2) % n;
|
|
81938
|
+
const cp1x = sx[i1] + (sx[i2] - sx[i0]) * BEZIER_K;
|
|
81939
|
+
const cp1y = sy[i1] + (sy[i2] - sy[i0]) * BEZIER_K;
|
|
81940
|
+
const cp2x = sx[i2] - (sx[i3] - sx[i1]) * BEZIER_K;
|
|
81941
|
+
const cp2y = sy[i2] - (sy[i3] - sy[i1]) * BEZIER_K;
|
|
81942
|
+
p += ` C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${sx[i2].toFixed(1)},${sy[i2].toFixed(1)}`;
|
|
81943
|
+
}
|
|
81944
|
+
return `${p} Z`;
|
|
81945
|
+
};
|
|
81946
|
+
class CursorRing {
|
|
81947
|
+
path;
|
|
81948
|
+
svg;
|
|
81949
|
+
canvas;
|
|
81950
|
+
camera;
|
|
81951
|
+
smoothing;
|
|
81952
|
+
// null = world-space ring (fixed world radius, shrinks with distance);
|
|
81953
|
+
// number = constant on-screen diameter in pixels.
|
|
81954
|
+
screenPixels;
|
|
81955
|
+
smoothNx = 0;
|
|
81956
|
+
smoothNy = 1;
|
|
81957
|
+
smoothNz = 0;
|
|
81958
|
+
hasSmoothedNormal = false;
|
|
81959
|
+
outerX = new Float64Array(NUM_SAMPLES);
|
|
81960
|
+
outerY = new Float64Array(NUM_SAMPLES);
|
|
81961
|
+
innerX = new Float64Array(NUM_SAMPLES);
|
|
81962
|
+
innerY = new Float64Array(NUM_SAMPLES);
|
|
81963
|
+
constructor(svg, canvas, camera, smoothing, screenPixels) {
|
|
81964
|
+
this.svg = svg;
|
|
81965
|
+
this.canvas = canvas;
|
|
81966
|
+
this.camera = camera;
|
|
81967
|
+
this.smoothing = smoothing;
|
|
81968
|
+
this.screenPixels = screenPixels;
|
|
81969
|
+
this.path = document.createElementNS(SVGNS, 'path');
|
|
81970
|
+
this.path.setAttribute('fill', 'white');
|
|
81971
|
+
this.path.setAttribute('fill-opacity', '0.6');
|
|
81972
|
+
this.path.setAttribute('fill-rule', 'evenodd');
|
|
81973
|
+
this.path.setAttribute('stroke', 'none');
|
|
81974
|
+
this.path.style.display = 'none';
|
|
81975
|
+
svg.appendChild(this.path);
|
|
81976
|
+
}
|
|
81977
|
+
projectCircle(px, py, pz, nx, ny, nz, radius, outX, outY) {
|
|
81978
|
+
const normal = tmpV.set(nx, ny, nz);
|
|
81979
|
+
if (Math.abs(normal.y) < 0.99) {
|
|
81980
|
+
tangent.cross(normal, up).normalize();
|
|
81981
|
+
}
|
|
81982
|
+
else {
|
|
81983
|
+
tangent.cross(normal, right).normalize();
|
|
81984
|
+
}
|
|
81985
|
+
bitangent.cross(normal, tangent);
|
|
81986
|
+
const cam = this.camera.camera;
|
|
81987
|
+
const angleStep = (2 * Math.PI) / NUM_SAMPLES;
|
|
81988
|
+
for (let i = 0; i < NUM_SAMPLES; i++) {
|
|
81989
|
+
const theta = i * angleStep;
|
|
81990
|
+
const ct = Math.cos(theta);
|
|
81991
|
+
const st = Math.sin(theta);
|
|
81992
|
+
const tx = ct * tangent.x + st * bitangent.x;
|
|
81993
|
+
const ty = ct * tangent.y + st * bitangent.y;
|
|
81994
|
+
const tz = ct * tangent.z + st * bitangent.z;
|
|
81995
|
+
worldPt.set(px + tx * radius, py + ty * radius, pz + tz * radius);
|
|
81996
|
+
cam.worldToScreen(worldPt, tmpScreen);
|
|
81997
|
+
outX[i] = tmpScreen.x;
|
|
81998
|
+
outY[i] = tmpScreen.y;
|
|
81999
|
+
}
|
|
82000
|
+
}
|
|
82001
|
+
render(pos, normal) {
|
|
82002
|
+
snapNormal(normal.x, normal.y, normal.z, tmpV);
|
|
82003
|
+
let nx = tmpV.x;
|
|
82004
|
+
let ny = tmpV.y;
|
|
82005
|
+
let nz = tmpV.z;
|
|
82006
|
+
if (this.smoothing) {
|
|
82007
|
+
if (this.hasSmoothedNormal) {
|
|
82008
|
+
const t = NORMAL_SMOOTH_FACTOR;
|
|
82009
|
+
nx = this.smoothNx + (nx - this.smoothNx) * t;
|
|
82010
|
+
ny = this.smoothNy + (ny - this.smoothNy) * t;
|
|
82011
|
+
nz = this.smoothNz + (nz - this.smoothNz) * t;
|
|
82012
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
82013
|
+
if (len > 1e-6) {
|
|
82014
|
+
const invLen = 1.0 / len;
|
|
82015
|
+
nx *= invLen;
|
|
82016
|
+
ny *= invLen;
|
|
82017
|
+
nz *= invLen;
|
|
82018
|
+
}
|
|
82019
|
+
}
|
|
82020
|
+
this.smoothNx = nx;
|
|
82021
|
+
this.smoothNy = ny;
|
|
82022
|
+
this.smoothNz = nz;
|
|
82023
|
+
this.hasSmoothedNormal = true;
|
|
82024
|
+
}
|
|
82025
|
+
const outerRadius = this.screenPixels !== null ?
|
|
82026
|
+
worldRadiusForPixels(this.camera, this.canvas.clientHeight || 1, pos, this.screenPixels) :
|
|
82027
|
+
BASE_OUTER_RADIUS;
|
|
82028
|
+
const innerRadius = outerRadius * INNER_OUTER_RATIO;
|
|
82029
|
+
this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, outerRadius, this.outerX, this.outerY);
|
|
82030
|
+
this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, innerRadius, this.innerX, this.innerY);
|
|
82031
|
+
this.path.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
|
|
82032
|
+
this.path.style.display = '';
|
|
82033
|
+
this.svg.style.display = '';
|
|
82034
|
+
}
|
|
82035
|
+
hide() {
|
|
82036
|
+
this.path.style.display = 'none';
|
|
82037
|
+
this.hasSmoothedNormal = false;
|
|
82038
|
+
}
|
|
82039
|
+
}
|
|
82040
|
+
class NavCursor {
|
|
82041
|
+
svg;
|
|
82042
|
+
hoverRing;
|
|
82043
|
+
targetRing;
|
|
82044
|
+
camera;
|
|
82045
|
+
collision;
|
|
82046
|
+
canvas;
|
|
82047
|
+
state;
|
|
82048
|
+
picker;
|
|
82049
|
+
app;
|
|
82050
|
+
onPrerender;
|
|
82051
|
+
active = false;
|
|
82052
|
+
navigating = false;
|
|
82053
|
+
targetPos = null;
|
|
82054
|
+
targetNormal = null;
|
|
82055
|
+
targetMode = null;
|
|
82056
|
+
surfaceCursorX = 0;
|
|
82057
|
+
surfaceCursorY = 0;
|
|
82058
|
+
hasSurfaceCursorPosition = false;
|
|
82059
|
+
surfaceCursorVersion = 0;
|
|
82060
|
+
surfaceCursorPickPending = false;
|
|
82061
|
+
surfaceSample = createSurfaceSample();
|
|
82062
|
+
hasSurfaceSample = false;
|
|
82063
|
+
scratchHoverPos = new Vec3();
|
|
82064
|
+
onPointerMove;
|
|
82065
|
+
onPointerLeave;
|
|
82066
|
+
collisionTarget = {
|
|
82067
|
+
position: new Vec3(),
|
|
82068
|
+
normal: new Vec3()
|
|
82069
|
+
};
|
|
82070
|
+
constructor(app, camera, collision, events, state, picker, sceneSize) {
|
|
82071
|
+
this.camera = camera;
|
|
82072
|
+
this.collision = collision;
|
|
82073
|
+
this.canvas = app.graphicsDevice.canvas;
|
|
82074
|
+
this.state = state;
|
|
82075
|
+
this.picker = picker;
|
|
82076
|
+
this.app = app;
|
|
82077
|
+
this.svg = document.createElementNS(SVGNS, 'svg');
|
|
82078
|
+
this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
|
|
82079
|
+
this.canvas.parentElement.appendChild(this.svg);
|
|
82080
|
+
const screenPixels = sceneSize < SMALL_SCENE_THRESHOLD ? SCREEN_OUTER_PIXELS : null;
|
|
82081
|
+
this.hoverRing = new CursorRing(this.svg, this.canvas, camera, true, screenPixels);
|
|
82082
|
+
this.targetRing = new CursorRing(this.svg, this.canvas, camera, false, screenPixels);
|
|
82083
|
+
this.svg.style.display = 'none';
|
|
82084
|
+
this.onPointerMove = (e) => {
|
|
82085
|
+
if (e.pointerType === 'touch') {
|
|
82086
|
+
this.hasSurfaceCursorPosition = false;
|
|
82087
|
+
this.surfaceCursorVersion++;
|
|
82088
|
+
this.hoverRing.hide();
|
|
82089
|
+
return;
|
|
82090
|
+
}
|
|
82091
|
+
if (e.buttons) {
|
|
82092
|
+
this.hasSurfaceCursorPosition = false;
|
|
82093
|
+
this.surfaceCursorVersion++;
|
|
82094
|
+
this.hoverRing.hide();
|
|
82095
|
+
return;
|
|
82096
|
+
}
|
|
82097
|
+
this.updateCursor(e.offsetX, e.offsetY);
|
|
82098
|
+
};
|
|
82099
|
+
this.onPointerLeave = () => {
|
|
82100
|
+
this.hasSurfaceCursorPosition = false;
|
|
82101
|
+
this.surfaceCursorVersion++;
|
|
82102
|
+
this.hoverRing.hide();
|
|
82103
|
+
};
|
|
82104
|
+
this.canvas.addEventListener('pointermove', this.onPointerMove);
|
|
82105
|
+
this.canvas.addEventListener('pointerleave', this.onPointerLeave);
|
|
82106
|
+
const updateActive = () => {
|
|
82107
|
+
const flyMouseCaptured = (state.cameraMode === 'fly' &&
|
|
82108
|
+
state.inputMode === 'desktop' &&
|
|
82109
|
+
state.gamingControls);
|
|
82110
|
+
this.active = (state.cameraMode === 'walk' && !state.gamingControls) ||
|
|
82111
|
+
(state.cameraMode === 'fly' && !flyMouseCaptured) ||
|
|
82112
|
+
state.cameraMode === 'orbit';
|
|
82113
|
+
this.surfaceCursorVersion++;
|
|
82114
|
+
this.hoverRing.hide();
|
|
82115
|
+
if (state.inputMode !== 'desktop') {
|
|
82116
|
+
this.hasSurfaceCursorPosition = false;
|
|
82117
|
+
}
|
|
82118
|
+
if (this.targetMode && this.targetMode !== state.cameraMode) {
|
|
82119
|
+
this.navigating = false;
|
|
82120
|
+
this.clearTarget();
|
|
82121
|
+
}
|
|
82122
|
+
if (!this.active) {
|
|
82123
|
+
this.svg.style.display = 'none';
|
|
82124
|
+
}
|
|
82125
|
+
};
|
|
82126
|
+
events.on('cameraMode:changed', updateActive);
|
|
82127
|
+
events.on('inputMode:changed', updateActive);
|
|
82128
|
+
events.on('gamingControls:changed', updateActive);
|
|
82129
|
+
events.on('navigateTo', () => {
|
|
82130
|
+
this.navigating = true;
|
|
82131
|
+
this.hoverRing.hide();
|
|
82132
|
+
});
|
|
82133
|
+
events.on('navigateCancel', () => {
|
|
82134
|
+
this.navigating = false;
|
|
82135
|
+
this.clearTarget();
|
|
82136
|
+
});
|
|
82137
|
+
events.on('navigateComplete', () => {
|
|
82138
|
+
this.navigating = false;
|
|
82139
|
+
this.clearTarget();
|
|
82140
|
+
});
|
|
82141
|
+
events.on('navTarget:set', (pos, normal) => {
|
|
82142
|
+
const mode = state.cameraMode === 'walk' || state.cameraMode === 'fly' ?
|
|
82143
|
+
state.cameraMode : 'walk';
|
|
82144
|
+
this.setTarget(pos, normal, mode);
|
|
82145
|
+
});
|
|
82146
|
+
events.on('navTarget:clear', () => {
|
|
82147
|
+
this.clearTarget();
|
|
82148
|
+
});
|
|
82149
|
+
events.on('orbitTarget:set', (pos, normal) => {
|
|
82150
|
+
this.navigating = false;
|
|
82151
|
+
this.setTarget(pos, normal, 'orbit');
|
|
82152
|
+
});
|
|
82153
|
+
events.on('orbitTarget:clear', () => {
|
|
82154
|
+
if (this.targetMode === 'orbit') {
|
|
82155
|
+
this.clearTarget();
|
|
82156
|
+
}
|
|
82157
|
+
});
|
|
82158
|
+
this.onPrerender = () => {
|
|
82159
|
+
this.updateTarget();
|
|
82160
|
+
};
|
|
82161
|
+
app.on('prerender', this.onPrerender);
|
|
82162
|
+
updateActive();
|
|
82163
|
+
}
|
|
82164
|
+
setTarget(pos, normal, mode) {
|
|
82165
|
+
this.surfaceCursorVersion++;
|
|
82166
|
+
this.targetPos = pos.clone();
|
|
82167
|
+
this.targetNormal = normal.clone();
|
|
82168
|
+
this.targetMode = mode;
|
|
82169
|
+
this.hoverRing.hide();
|
|
82170
|
+
this.targetRing.hide();
|
|
82171
|
+
}
|
|
82172
|
+
clearTarget() {
|
|
82173
|
+
const mode = this.targetMode;
|
|
82174
|
+
this.targetPos = null;
|
|
82175
|
+
this.targetNormal = null;
|
|
82176
|
+
this.targetMode = null;
|
|
82177
|
+
if (mode === 'orbit') {
|
|
82178
|
+
this.hoverRing.hide();
|
|
82179
|
+
}
|
|
82180
|
+
this.targetRing.hide();
|
|
82181
|
+
this.refreshSurfaceCursor();
|
|
82182
|
+
}
|
|
82183
|
+
pickCollision(offsetX, offsetY) {
|
|
82184
|
+
if (!this.collision) {
|
|
82185
|
+
return null;
|
|
82186
|
+
}
|
|
82187
|
+
const { camera, collision } = this;
|
|
82188
|
+
const cameraPos = camera.getPosition();
|
|
82189
|
+
camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV);
|
|
82190
|
+
tmpV.sub(cameraPos).normalize();
|
|
82191
|
+
const hit = collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV.x, tmpV.y, tmpV.z, camera.camera.farClip);
|
|
82192
|
+
if (!hit) {
|
|
82193
|
+
return null;
|
|
82194
|
+
}
|
|
82195
|
+
const sn = collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV.x, tmpV.y, tmpV.z);
|
|
82196
|
+
this.collisionTarget.position.set(hit.x, hit.y, hit.z);
|
|
82197
|
+
this.collisionTarget.normal.set(sn.nx, sn.ny, sn.nz);
|
|
82198
|
+
return this.collisionTarget;
|
|
82199
|
+
}
|
|
82200
|
+
async pickSceneTarget(offsetX, offsetY) {
|
|
82201
|
+
const collisionTarget = this.pickCollision(offsetX, offsetY);
|
|
82202
|
+
if (collisionTarget) {
|
|
82203
|
+
return collisionTarget;
|
|
82204
|
+
}
|
|
82205
|
+
const result = await this.picker.pickSurface(offsetX / this.canvas.clientWidth, offsetY / this.canvas.clientHeight);
|
|
82206
|
+
return result ?? null;
|
|
82207
|
+
}
|
|
82208
|
+
shouldShowSurfaceCursor() {
|
|
82209
|
+
const flyMouseCaptured = this.state.cameraMode === 'fly' &&
|
|
82210
|
+
this.state.inputMode === 'desktop' &&
|
|
82211
|
+
this.state.gamingControls;
|
|
82212
|
+
return this.active &&
|
|
82213
|
+
this.state.inputMode === 'desktop' &&
|
|
82214
|
+
this.hasSurfaceCursorPosition &&
|
|
82215
|
+
!this.navigating && ((this.state.cameraMode === 'fly' && !flyMouseCaptured) ||
|
|
82216
|
+
(this.state.cameraMode === 'orbit' && this.targetMode !== 'orbit'));
|
|
82217
|
+
}
|
|
82218
|
+
updateSurfaceCursor(offsetX, offsetY) {
|
|
82219
|
+
this.surfaceCursorX = offsetX;
|
|
82220
|
+
this.surfaceCursorY = offsetY;
|
|
82221
|
+
this.hasSurfaceCursorPosition = true;
|
|
82222
|
+
this.surfaceCursorVersion++;
|
|
82223
|
+
// Render immediately using the most recent depth sample, re-projecting
|
|
82224
|
+
// at the new pointer position. The async pick below will refresh the
|
|
82225
|
+
// sample.
|
|
82226
|
+
this.renderSurfaceCursor();
|
|
82227
|
+
if (!this.surfaceCursorPickPending) {
|
|
82228
|
+
this.processSurfaceCursor();
|
|
82229
|
+
}
|
|
82230
|
+
}
|
|
82231
|
+
renderSurfaceCursor() {
|
|
82232
|
+
if (!this.hasSurfaceSample || !this.shouldShowSurfaceCursor()) {
|
|
82233
|
+
this.hoverRing.hide();
|
|
82234
|
+
return;
|
|
82235
|
+
}
|
|
82236
|
+
const sample = this.surfaceSample;
|
|
82237
|
+
const position = getWorldPoint(sample.camera, this.surfaceCursorX, this.surfaceCursorY, sample.width, sample.height, sample.normalizedDepth, this.scratchHoverPos);
|
|
82238
|
+
if (!position) {
|
|
82239
|
+
this.hoverRing.hide();
|
|
82240
|
+
return;
|
|
82241
|
+
}
|
|
82242
|
+
this.hoverRing.render(position, sample.normal);
|
|
82243
|
+
}
|
|
82244
|
+
refreshSurfaceCursor() {
|
|
82245
|
+
if (this.hasSurfaceCursorPosition && this.shouldShowSurfaceCursor() && !this.surfaceCursorPickPending) {
|
|
82246
|
+
this.surfaceCursorVersion++;
|
|
82247
|
+
this.processSurfaceCursor();
|
|
82248
|
+
}
|
|
82249
|
+
}
|
|
82250
|
+
processSurfaceCursor() {
|
|
82251
|
+
this.surfaceCursorPickPending = true;
|
|
82252
|
+
const version = this.surfaceCursorVersion;
|
|
82253
|
+
// Capture the camera at pick fire time so the depth we extract from
|
|
82254
|
+
// the result is interpretable through the same view/projection. The
|
|
82255
|
+
// surface cursor only animates while the camera is static, so this
|
|
82256
|
+
// snapshot matches the camera the picker actually rendered with.
|
|
82257
|
+
captureCameraSnapshot(this.camera, this.surfaceSample.camera);
|
|
82258
|
+
const snapshotWidth = this.canvas.clientWidth;
|
|
82259
|
+
const snapshotHeight = this.canvas.clientHeight;
|
|
82260
|
+
this.pickSceneTarget(this.surfaceCursorX, this.surfaceCursorY).then((target) => {
|
|
82261
|
+
if (target) {
|
|
82262
|
+
this.surfaceSample.normalizedDepth = worldPointToDepth(this.surfaceSample.camera, target.position);
|
|
82263
|
+
this.surfaceSample.normal.copy(target.normal);
|
|
82264
|
+
this.surfaceSample.width = snapshotWidth;
|
|
82265
|
+
this.surfaceSample.height = snapshotHeight;
|
|
82266
|
+
this.hasSurfaceSample = this.surfaceSample.normalizedDepth >= 0;
|
|
82267
|
+
}
|
|
82268
|
+
else {
|
|
82269
|
+
this.hasSurfaceSample = false;
|
|
82270
|
+
}
|
|
82271
|
+
this.renderSurfaceCursor();
|
|
82272
|
+
}).catch(() => {
|
|
82273
|
+
if (version === this.surfaceCursorVersion) {
|
|
82274
|
+
this.hasSurfaceSample = false;
|
|
82275
|
+
this.hoverRing.hide();
|
|
82276
|
+
}
|
|
82277
|
+
}).finally(() => {
|
|
82278
|
+
this.surfaceCursorPickPending = false;
|
|
82279
|
+
if (version !== this.surfaceCursorVersion && this.shouldShowSurfaceCursor()) {
|
|
82280
|
+
this.processSurfaceCursor();
|
|
82281
|
+
}
|
|
82282
|
+
});
|
|
82283
|
+
}
|
|
82284
|
+
updateCursor(offsetX, offsetY) {
|
|
82285
|
+
if (!this.active || this.navigating) {
|
|
82286
|
+
this.hoverRing.hide();
|
|
82287
|
+
return;
|
|
82288
|
+
}
|
|
82289
|
+
if (this.state.cameraMode === 'orbit' && this.targetMode === 'orbit') {
|
|
82290
|
+
this.hoverRing.hide();
|
|
82291
|
+
return;
|
|
82292
|
+
}
|
|
82293
|
+
if (this.state.cameraMode === 'fly' || this.state.cameraMode === 'orbit') {
|
|
82294
|
+
this.updateSurfaceCursor(offsetX, offsetY);
|
|
82295
|
+
return;
|
|
82296
|
+
}
|
|
82297
|
+
const target = this.pickCollision(offsetX, offsetY);
|
|
82298
|
+
if (!target) {
|
|
82299
|
+
this.hoverRing.hide();
|
|
82300
|
+
return;
|
|
82301
|
+
}
|
|
82302
|
+
this.hoverRing.render(target.position, target.normal);
|
|
82303
|
+
}
|
|
82304
|
+
updateTarget() {
|
|
82305
|
+
if (!this.active || !this.targetPos || !this.targetNormal) {
|
|
82306
|
+
return;
|
|
82307
|
+
}
|
|
82308
|
+
const camPos = this.camera.getPosition();
|
|
82309
|
+
const dist = camPos.distance(this.targetPos);
|
|
82310
|
+
if (this.targetMode !== 'orbit' && dist < 2.0) {
|
|
82311
|
+
this.targetRing.hide();
|
|
82312
|
+
return;
|
|
82313
|
+
}
|
|
82314
|
+
this.targetRing.render(this.targetPos, this.targetNormal);
|
|
82315
|
+
}
|
|
82316
|
+
destroy() {
|
|
82317
|
+
this.app.off('prerender', this.onPrerender);
|
|
82318
|
+
this.canvas.removeEventListener('pointermove', this.onPointerMove);
|
|
82319
|
+
this.canvas.removeEventListener('pointerleave', this.onPointerLeave);
|
|
82320
|
+
this.svg.remove();
|
|
82321
|
+
}
|
|
82322
|
+
}
|
|
82323
|
+
|
|
81583
82324
|
// ---------------------------------------------------------------------------
|
|
81584
82325
|
// WGSL compute shader: ray-march through the sparse voxel octree per pixel
|
|
81585
82326
|
// ---------------------------------------------------------------------------
|
|
@@ -82210,425 +82951,6 @@ class VoxelDebugOverlay {
|
|
|
82210
82951
|
}
|
|
82211
82952
|
}
|
|
82212
82953
|
|
|
82213
|
-
const SVGNS = 'http://www.w3.org/2000/svg';
|
|
82214
|
-
const NUM_SAMPLES = 12;
|
|
82215
|
-
const CIRCLE_OUTER_RADIUS = 0.2;
|
|
82216
|
-
const CIRCLE_INNER_RADIUS = 0.17;
|
|
82217
|
-
const BEZIER_K = 1 / 6;
|
|
82218
|
-
const NORMAL_SMOOTH_FACTOR = 0.25;
|
|
82219
|
-
const NORMAL_SNAP_ANGLE = Math.PI / 4;
|
|
82220
|
-
const NORMAL_EPSILON = 1e-6;
|
|
82221
|
-
const createNormalSnapDirections = () => {
|
|
82222
|
-
const result = [];
|
|
82223
|
-
for (let pitchStep = -2; pitchStep <= 2; pitchStep++) {
|
|
82224
|
-
const pitch = pitchStep * NORMAL_SNAP_ANGLE;
|
|
82225
|
-
const cp = Math.cos(pitch);
|
|
82226
|
-
const sy = Math.sin(pitch);
|
|
82227
|
-
if (Math.abs(cp) <= NORMAL_EPSILON) {
|
|
82228
|
-
result.push(new Vec3(0, sy > 0 ? 1 : -1, 0));
|
|
82229
|
-
continue;
|
|
82230
|
-
}
|
|
82231
|
-
for (let yawStep = 0; yawStep < 8; yawStep++) {
|
|
82232
|
-
const yaw = yawStep * NORMAL_SNAP_ANGLE;
|
|
82233
|
-
result.push(new Vec3(Math.cos(yaw) * cp, sy, Math.sin(yaw) * cp));
|
|
82234
|
-
}
|
|
82235
|
-
}
|
|
82236
|
-
return result;
|
|
82237
|
-
};
|
|
82238
|
-
const NORMAL_SNAP_DIRECTIONS = createNormalSnapDirections();
|
|
82239
|
-
const tmpV = new Vec3();
|
|
82240
|
-
const tmpScreen = new Vec3();
|
|
82241
|
-
const tangent = new Vec3();
|
|
82242
|
-
const bitangent = new Vec3();
|
|
82243
|
-
const worldPt = new Vec3();
|
|
82244
|
-
const up = new Vec3(0, 1, 0);
|
|
82245
|
-
const right = new Vec3(1, 0, 0);
|
|
82246
|
-
const buildBezierRing = (sx, sy) => {
|
|
82247
|
-
const n = sx.length;
|
|
82248
|
-
let p = `M${sx[0].toFixed(1)},${sy[0].toFixed(1)}`;
|
|
82249
|
-
for (let i = 0; i < n; i++) {
|
|
82250
|
-
const i0 = (i - 1 + n) % n;
|
|
82251
|
-
const i1 = i;
|
|
82252
|
-
const i2 = (i + 1) % n;
|
|
82253
|
-
const i3 = (i + 2) % n;
|
|
82254
|
-
const cp1x = sx[i1] + (sx[i2] - sx[i0]) * BEZIER_K;
|
|
82255
|
-
const cp1y = sy[i1] + (sy[i2] - sy[i0]) * BEZIER_K;
|
|
82256
|
-
const cp2x = sx[i2] - (sx[i3] - sx[i1]) * BEZIER_K;
|
|
82257
|
-
const cp2y = sy[i2] - (sy[i3] - sy[i1]) * BEZIER_K;
|
|
82258
|
-
p += ` C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${sx[i2].toFixed(1)},${sy[i2].toFixed(1)}`;
|
|
82259
|
-
}
|
|
82260
|
-
return `${p} Z`;
|
|
82261
|
-
};
|
|
82262
|
-
const snapNormal = (nx, ny, nz, out) => {
|
|
82263
|
-
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
82264
|
-
if (len <= NORMAL_EPSILON) {
|
|
82265
|
-
return out.set(0, 1, 0);
|
|
82266
|
-
}
|
|
82267
|
-
const invLen = 1 / len;
|
|
82268
|
-
const x = nx * invLen;
|
|
82269
|
-
const y = ny * invLen;
|
|
82270
|
-
const z = nz * invLen;
|
|
82271
|
-
let best = NORMAL_SNAP_DIRECTIONS[0];
|
|
82272
|
-
let bestDot = -Infinity;
|
|
82273
|
-
for (let i = 0; i < NORMAL_SNAP_DIRECTIONS.length; i++) {
|
|
82274
|
-
const candidate = NORMAL_SNAP_DIRECTIONS[i];
|
|
82275
|
-
const dot = candidate.x * x + candidate.y * y + candidate.z * z;
|
|
82276
|
-
if (dot > bestDot) {
|
|
82277
|
-
bestDot = dot;
|
|
82278
|
-
best = candidate;
|
|
82279
|
-
}
|
|
82280
|
-
}
|
|
82281
|
-
return out.copy(best);
|
|
82282
|
-
};
|
|
82283
|
-
class WalkCursor {
|
|
82284
|
-
svg;
|
|
82285
|
-
cursorPath;
|
|
82286
|
-
targetPath;
|
|
82287
|
-
camera;
|
|
82288
|
-
collision;
|
|
82289
|
-
canvas;
|
|
82290
|
-
state;
|
|
82291
|
-
picker;
|
|
82292
|
-
active = false;
|
|
82293
|
-
walking = false;
|
|
82294
|
-
targetPos = null;
|
|
82295
|
-
targetNormal = null;
|
|
82296
|
-
targetMode = null;
|
|
82297
|
-
smoothNx = 0;
|
|
82298
|
-
smoothNy = 1;
|
|
82299
|
-
smoothNz = 0;
|
|
82300
|
-
hasSmoothedNormal = false;
|
|
82301
|
-
surfaceCursorX = 0;
|
|
82302
|
-
surfaceCursorY = 0;
|
|
82303
|
-
hasSurfaceCursorPosition = false;
|
|
82304
|
-
surfaceCursorVersion = 0;
|
|
82305
|
-
surfaceCursorPickPending = false;
|
|
82306
|
-
onPointerMove;
|
|
82307
|
-
onPointerLeave;
|
|
82308
|
-
outerX = new Float64Array(NUM_SAMPLES);
|
|
82309
|
-
outerY = new Float64Array(NUM_SAMPLES);
|
|
82310
|
-
innerX = new Float64Array(NUM_SAMPLES);
|
|
82311
|
-
innerY = new Float64Array(NUM_SAMPLES);
|
|
82312
|
-
collisionTarget = {
|
|
82313
|
-
position: new Vec3(),
|
|
82314
|
-
normal: new Vec3()
|
|
82315
|
-
};
|
|
82316
|
-
constructor(app, camera, collision, events, state, picker) {
|
|
82317
|
-
this.camera = camera;
|
|
82318
|
-
this.collision = collision;
|
|
82319
|
-
this.canvas = app.graphicsDevice.canvas;
|
|
82320
|
-
this.state = state;
|
|
82321
|
-
this.picker = picker;
|
|
82322
|
-
this.svg = document.createElementNS(SVGNS, 'svg');
|
|
82323
|
-
this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
|
|
82324
|
-
this.canvas.parentElement.appendChild(this.svg);
|
|
82325
|
-
// Hover cursor: thick ring
|
|
82326
|
-
this.cursorPath = document.createElementNS(SVGNS, 'path');
|
|
82327
|
-
this.cursorPath.setAttribute('fill', 'white');
|
|
82328
|
-
this.cursorPath.setAttribute('fill-opacity', '0.6');
|
|
82329
|
-
this.cursorPath.setAttribute('fill-rule', 'evenodd');
|
|
82330
|
-
this.cursorPath.setAttribute('stroke', 'none');
|
|
82331
|
-
this.svg.appendChild(this.cursorPath);
|
|
82332
|
-
// Selected target cursor: same ring geometry as hover.
|
|
82333
|
-
this.targetPath = document.createElementNS(SVGNS, 'path');
|
|
82334
|
-
this.targetPath.setAttribute('fill', 'white');
|
|
82335
|
-
this.targetPath.setAttribute('fill-opacity', '0.6');
|
|
82336
|
-
this.targetPath.setAttribute('fill-rule', 'evenodd');
|
|
82337
|
-
this.targetPath.setAttribute('stroke', 'none');
|
|
82338
|
-
this.targetPath.style.display = 'none';
|
|
82339
|
-
this.svg.appendChild(this.targetPath);
|
|
82340
|
-
this.svg.style.display = 'none';
|
|
82341
|
-
this.onPointerMove = (e) => {
|
|
82342
|
-
if (e.pointerType === 'touch') {
|
|
82343
|
-
this.hasSurfaceCursorPosition = false;
|
|
82344
|
-
this.surfaceCursorVersion++;
|
|
82345
|
-
this.hideCursor();
|
|
82346
|
-
return;
|
|
82347
|
-
}
|
|
82348
|
-
if (e.buttons) {
|
|
82349
|
-
this.hasSurfaceCursorPosition = false;
|
|
82350
|
-
this.surfaceCursorVersion++;
|
|
82351
|
-
this.hideCursor();
|
|
82352
|
-
return;
|
|
82353
|
-
}
|
|
82354
|
-
this.updateCursor(e.offsetX, e.offsetY);
|
|
82355
|
-
};
|
|
82356
|
-
this.onPointerLeave = () => {
|
|
82357
|
-
this.hasSurfaceCursorPosition = false;
|
|
82358
|
-
this.surfaceCursorVersion++;
|
|
82359
|
-
this.hideCursor();
|
|
82360
|
-
};
|
|
82361
|
-
this.canvas.addEventListener('pointermove', this.onPointerMove);
|
|
82362
|
-
this.canvas.addEventListener('pointerleave', this.onPointerLeave);
|
|
82363
|
-
const updateActive = () => {
|
|
82364
|
-
const flyMouseCaptured = (state.cameraMode === 'fly' &&
|
|
82365
|
-
state.inputMode === 'desktop' &&
|
|
82366
|
-
state.gamingControls);
|
|
82367
|
-
this.active = (state.cameraMode === 'walk' && !state.gamingControls) ||
|
|
82368
|
-
(state.cameraMode === 'fly' && !flyMouseCaptured) ||
|
|
82369
|
-
state.cameraMode === 'orbit';
|
|
82370
|
-
this.surfaceCursorVersion++;
|
|
82371
|
-
this.hideCursor();
|
|
82372
|
-
if (state.inputMode !== 'desktop') {
|
|
82373
|
-
this.hasSurfaceCursorPosition = false;
|
|
82374
|
-
}
|
|
82375
|
-
if (this.targetMode && this.targetMode !== state.cameraMode) {
|
|
82376
|
-
this.walking = false;
|
|
82377
|
-
this.clearTarget();
|
|
82378
|
-
}
|
|
82379
|
-
if (!this.active) {
|
|
82380
|
-
this.svg.style.display = 'none';
|
|
82381
|
-
}
|
|
82382
|
-
};
|
|
82383
|
-
events.on('cameraMode:changed', updateActive);
|
|
82384
|
-
events.on('inputMode:changed', updateActive);
|
|
82385
|
-
events.on('gamingControls:changed', updateActive);
|
|
82386
|
-
events.on('walkTo', () => {
|
|
82387
|
-
this.walking = true;
|
|
82388
|
-
this.cursorPath.style.display = 'none';
|
|
82389
|
-
this.hasSmoothedNormal = false;
|
|
82390
|
-
});
|
|
82391
|
-
events.on('walkCancel', () => {
|
|
82392
|
-
this.walking = false;
|
|
82393
|
-
this.clearTarget();
|
|
82394
|
-
});
|
|
82395
|
-
events.on('walkComplete', () => {
|
|
82396
|
-
this.walking = false;
|
|
82397
|
-
this.clearTarget();
|
|
82398
|
-
});
|
|
82399
|
-
events.on('walkTarget:set', (pos, normal) => {
|
|
82400
|
-
this.setTarget(pos, normal, 'walk');
|
|
82401
|
-
});
|
|
82402
|
-
events.on('walkTarget:clear', () => {
|
|
82403
|
-
this.clearTarget();
|
|
82404
|
-
});
|
|
82405
|
-
events.on('flyTo', () => {
|
|
82406
|
-
this.walking = true;
|
|
82407
|
-
this.cursorPath.style.display = 'none';
|
|
82408
|
-
this.hasSmoothedNormal = false;
|
|
82409
|
-
});
|
|
82410
|
-
events.on('flyCancel', () => {
|
|
82411
|
-
this.walking = false;
|
|
82412
|
-
this.clearTarget();
|
|
82413
|
-
});
|
|
82414
|
-
events.on('flyComplete', () => {
|
|
82415
|
-
this.walking = false;
|
|
82416
|
-
this.clearTarget();
|
|
82417
|
-
});
|
|
82418
|
-
events.on('flyTarget:set', (pos, normal) => {
|
|
82419
|
-
this.setTarget(pos, normal, 'fly');
|
|
82420
|
-
});
|
|
82421
|
-
events.on('flyTarget:clear', () => {
|
|
82422
|
-
this.clearTarget();
|
|
82423
|
-
});
|
|
82424
|
-
events.on('orbitTarget:set', (pos, normal) => {
|
|
82425
|
-
this.walking = false;
|
|
82426
|
-
this.setTarget(pos, normal, 'orbit');
|
|
82427
|
-
});
|
|
82428
|
-
events.on('orbitTarget:clear', () => {
|
|
82429
|
-
if (this.targetMode === 'orbit') {
|
|
82430
|
-
this.clearTarget();
|
|
82431
|
-
}
|
|
82432
|
-
});
|
|
82433
|
-
app.on('prerender', () => {
|
|
82434
|
-
this.updateTarget();
|
|
82435
|
-
});
|
|
82436
|
-
updateActive();
|
|
82437
|
-
}
|
|
82438
|
-
setTarget(pos, normal, mode) {
|
|
82439
|
-
this.surfaceCursorVersion++;
|
|
82440
|
-
this.targetPos = pos.clone();
|
|
82441
|
-
this.targetNormal = normal.clone();
|
|
82442
|
-
this.targetMode = mode;
|
|
82443
|
-
this.cursorPath.style.display = 'none';
|
|
82444
|
-
this.targetPath.style.display = 'none';
|
|
82445
|
-
this.hasSmoothedNormal = false;
|
|
82446
|
-
}
|
|
82447
|
-
clearTarget() {
|
|
82448
|
-
const mode = this.targetMode;
|
|
82449
|
-
this.targetPos = null;
|
|
82450
|
-
this.targetNormal = null;
|
|
82451
|
-
this.targetMode = null;
|
|
82452
|
-
if (mode === 'orbit') {
|
|
82453
|
-
this.cursorPath.style.display = 'none';
|
|
82454
|
-
}
|
|
82455
|
-
this.targetPath.style.display = 'none';
|
|
82456
|
-
this.refreshSurfaceCursor();
|
|
82457
|
-
}
|
|
82458
|
-
hideCursor() {
|
|
82459
|
-
this.cursorPath.style.display = 'none';
|
|
82460
|
-
this.hasSmoothedNormal = false;
|
|
82461
|
-
}
|
|
82462
|
-
projectCircle(px, py, pz, nx, ny, nz, radius, outX, outY) {
|
|
82463
|
-
const normal = snapNormal(nx, ny, nz, tmpV);
|
|
82464
|
-
if (Math.abs(normal.y) < 0.99) {
|
|
82465
|
-
tangent.cross(normal, up).normalize();
|
|
82466
|
-
}
|
|
82467
|
-
else {
|
|
82468
|
-
tangent.cross(normal, right).normalize();
|
|
82469
|
-
}
|
|
82470
|
-
bitangent.cross(normal, tangent);
|
|
82471
|
-
const cam = this.camera.camera;
|
|
82472
|
-
const angleStep = (2 * Math.PI) / NUM_SAMPLES;
|
|
82473
|
-
for (let i = 0; i < NUM_SAMPLES; i++) {
|
|
82474
|
-
const theta = i * angleStep;
|
|
82475
|
-
const ct = Math.cos(theta);
|
|
82476
|
-
const st = Math.sin(theta);
|
|
82477
|
-
const tx = ct * tangent.x + st * bitangent.x;
|
|
82478
|
-
const ty = ct * tangent.y + st * bitangent.y;
|
|
82479
|
-
const tz = ct * tangent.z + st * bitangent.z;
|
|
82480
|
-
worldPt.set(px + tx * radius, py + ty * radius, pz + tz * radius);
|
|
82481
|
-
cam.worldToScreen(worldPt, tmpScreen);
|
|
82482
|
-
outX[i] = tmpScreen.x;
|
|
82483
|
-
outY[i] = tmpScreen.y;
|
|
82484
|
-
}
|
|
82485
|
-
}
|
|
82486
|
-
renderRing(path, pos, normal) {
|
|
82487
|
-
this.projectCircle(pos.x, pos.y, pos.z, normal.x, normal.y, normal.z, CIRCLE_OUTER_RADIUS, this.outerX, this.outerY);
|
|
82488
|
-
this.projectCircle(pos.x, pos.y, pos.z, normal.x, normal.y, normal.z, CIRCLE_INNER_RADIUS, this.innerX, this.innerY);
|
|
82489
|
-
path.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
|
|
82490
|
-
path.style.display = '';
|
|
82491
|
-
this.svg.style.display = '';
|
|
82492
|
-
}
|
|
82493
|
-
pickCollision(offsetX, offsetY) {
|
|
82494
|
-
if (!this.collision) {
|
|
82495
|
-
return null;
|
|
82496
|
-
}
|
|
82497
|
-
const { camera, collision } = this;
|
|
82498
|
-
const cameraPos = camera.getPosition();
|
|
82499
|
-
camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV);
|
|
82500
|
-
tmpV.sub(cameraPos).normalize();
|
|
82501
|
-
const hit = collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV.x, tmpV.y, tmpV.z, camera.camera.farClip);
|
|
82502
|
-
if (!hit) {
|
|
82503
|
-
return null;
|
|
82504
|
-
}
|
|
82505
|
-
const sn = collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV.x, tmpV.y, tmpV.z);
|
|
82506
|
-
this.collisionTarget.position.set(hit.x, hit.y, hit.z);
|
|
82507
|
-
this.collisionTarget.normal.set(sn.nx, sn.ny, sn.nz);
|
|
82508
|
-
return this.collisionTarget;
|
|
82509
|
-
}
|
|
82510
|
-
async pickSceneTarget(offsetX, offsetY) {
|
|
82511
|
-
const collisionTarget = this.pickCollision(offsetX, offsetY);
|
|
82512
|
-
if (collisionTarget) {
|
|
82513
|
-
return collisionTarget;
|
|
82514
|
-
}
|
|
82515
|
-
const result = await this.picker.pickSurface(offsetX / this.canvas.clientWidth, offsetY / this.canvas.clientHeight);
|
|
82516
|
-
if (result) {
|
|
82517
|
-
return result;
|
|
82518
|
-
}
|
|
82519
|
-
return null;
|
|
82520
|
-
}
|
|
82521
|
-
renderCursor(pos, normal) {
|
|
82522
|
-
let nx = normal.x;
|
|
82523
|
-
let ny = normal.y;
|
|
82524
|
-
let nz = normal.z;
|
|
82525
|
-
if (this.hasSmoothedNormal) {
|
|
82526
|
-
const t = NORMAL_SMOOTH_FACTOR;
|
|
82527
|
-
nx = this.smoothNx + (nx - this.smoothNx) * t;
|
|
82528
|
-
ny = this.smoothNy + (ny - this.smoothNy) * t;
|
|
82529
|
-
nz = this.smoothNz + (nz - this.smoothNz) * t;
|
|
82530
|
-
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
82531
|
-
if (len > 1e-6) {
|
|
82532
|
-
const invLen = 1.0 / len;
|
|
82533
|
-
nx *= invLen;
|
|
82534
|
-
ny *= invLen;
|
|
82535
|
-
nz *= invLen;
|
|
82536
|
-
}
|
|
82537
|
-
}
|
|
82538
|
-
this.smoothNx = nx;
|
|
82539
|
-
this.smoothNy = ny;
|
|
82540
|
-
this.smoothNz = nz;
|
|
82541
|
-
this.hasSmoothedNormal = true;
|
|
82542
|
-
this.renderRing(this.cursorPath, pos, tmpV.set(nx, ny, nz));
|
|
82543
|
-
}
|
|
82544
|
-
shouldShowSurfaceCursor() {
|
|
82545
|
-
const flyMouseCaptured = this.state.cameraMode === 'fly' &&
|
|
82546
|
-
this.state.inputMode === 'desktop' &&
|
|
82547
|
-
this.state.gamingControls;
|
|
82548
|
-
return this.active &&
|
|
82549
|
-
this.state.inputMode === 'desktop' &&
|
|
82550
|
-
this.hasSurfaceCursorPosition &&
|
|
82551
|
-
!this.walking && ((this.state.cameraMode === 'fly' && !flyMouseCaptured) ||
|
|
82552
|
-
(this.state.cameraMode === 'orbit' && this.targetMode !== 'orbit'));
|
|
82553
|
-
}
|
|
82554
|
-
updateSurfaceCursor(offsetX, offsetY) {
|
|
82555
|
-
this.surfaceCursorX = offsetX;
|
|
82556
|
-
this.surfaceCursorY = offsetY;
|
|
82557
|
-
this.hasSurfaceCursorPosition = true;
|
|
82558
|
-
this.surfaceCursorVersion++;
|
|
82559
|
-
if (!this.surfaceCursorPickPending) {
|
|
82560
|
-
this.processSurfaceCursor();
|
|
82561
|
-
}
|
|
82562
|
-
}
|
|
82563
|
-
refreshSurfaceCursor() {
|
|
82564
|
-
if (this.hasSurfaceCursorPosition && this.shouldShowSurfaceCursor() && !this.surfaceCursorPickPending) {
|
|
82565
|
-
this.surfaceCursorVersion++;
|
|
82566
|
-
this.processSurfaceCursor();
|
|
82567
|
-
}
|
|
82568
|
-
}
|
|
82569
|
-
processSurfaceCursor() {
|
|
82570
|
-
this.surfaceCursorPickPending = true;
|
|
82571
|
-
const version = this.surfaceCursorVersion;
|
|
82572
|
-
this.pickSceneTarget(this.surfaceCursorX, this.surfaceCursorY).then((target) => {
|
|
82573
|
-
if (version !== this.surfaceCursorVersion || !this.shouldShowSurfaceCursor()) {
|
|
82574
|
-
return;
|
|
82575
|
-
}
|
|
82576
|
-
if (target) {
|
|
82577
|
-
this.renderCursor(target.position, target.normal);
|
|
82578
|
-
}
|
|
82579
|
-
else {
|
|
82580
|
-
this.hideCursor();
|
|
82581
|
-
}
|
|
82582
|
-
}).catch(() => {
|
|
82583
|
-
if (version === this.surfaceCursorVersion) {
|
|
82584
|
-
this.hideCursor();
|
|
82585
|
-
}
|
|
82586
|
-
}).finally(() => {
|
|
82587
|
-
this.surfaceCursorPickPending = false;
|
|
82588
|
-
if (version !== this.surfaceCursorVersion && this.shouldShowSurfaceCursor()) {
|
|
82589
|
-
this.processSurfaceCursor();
|
|
82590
|
-
}
|
|
82591
|
-
});
|
|
82592
|
-
}
|
|
82593
|
-
updateCursor(offsetX, offsetY) {
|
|
82594
|
-
if (!this.active || this.walking) {
|
|
82595
|
-
this.hideCursor();
|
|
82596
|
-
return;
|
|
82597
|
-
}
|
|
82598
|
-
if (this.state.cameraMode === 'orbit' && this.targetMode === 'orbit') {
|
|
82599
|
-
this.hideCursor();
|
|
82600
|
-
return;
|
|
82601
|
-
}
|
|
82602
|
-
if (this.state.cameraMode === 'fly' || this.state.cameraMode === 'orbit') {
|
|
82603
|
-
this.updateSurfaceCursor(offsetX, offsetY);
|
|
82604
|
-
return;
|
|
82605
|
-
}
|
|
82606
|
-
const target = this.pickCollision(offsetX, offsetY);
|
|
82607
|
-
if (!target) {
|
|
82608
|
-
this.hideCursor();
|
|
82609
|
-
return;
|
|
82610
|
-
}
|
|
82611
|
-
this.renderCursor(target.position, target.normal);
|
|
82612
|
-
}
|
|
82613
|
-
updateTarget() {
|
|
82614
|
-
if (!this.active || !this.targetPos || !this.targetNormal) {
|
|
82615
|
-
return;
|
|
82616
|
-
}
|
|
82617
|
-
const camPos = this.camera.getPosition();
|
|
82618
|
-
const dist = camPos.distance(this.targetPos);
|
|
82619
|
-
if (this.targetMode !== 'orbit' && dist < 2.0) {
|
|
82620
|
-
this.targetPath.style.display = 'none';
|
|
82621
|
-
return;
|
|
82622
|
-
}
|
|
82623
|
-
this.renderRing(this.targetPath, this.targetPos, this.targetNormal);
|
|
82624
|
-
}
|
|
82625
|
-
destroy() {
|
|
82626
|
-
this.canvas.removeEventListener('pointermove', this.onPointerMove);
|
|
82627
|
-
this.canvas.removeEventListener('pointerleave', this.onPointerLeave);
|
|
82628
|
-
this.svg.remove();
|
|
82629
|
-
}
|
|
82630
|
-
}
|
|
82631
|
-
|
|
82632
82954
|
// String.replace wrapper that warns when the source substring is missing, so
|
|
82633
82955
|
// shader chunk patches against the engine fail loudly instead of silently
|
|
82634
82956
|
// producing the original chunk.
|
|
@@ -82736,7 +83058,7 @@ class Viewer {
|
|
|
82736
83058
|
forceRenderNextFrame = false;
|
|
82737
83059
|
voxelOverlay = null;
|
|
82738
83060
|
meshOverlay = null;
|
|
82739
|
-
|
|
83061
|
+
navCursor = null;
|
|
82740
83062
|
origChunks;
|
|
82741
83063
|
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
82742
83064
|
this.global = global;
|
|
@@ -82906,7 +83228,7 @@ class Viewer {
|
|
|
82906
83228
|
this.cameraManager = new CameraManager(global, sceneBound, collision);
|
|
82907
83229
|
applyCamera(this.cameraManager.camera);
|
|
82908
83230
|
if (!config.noui) {
|
|
82909
|
-
this.
|
|
83231
|
+
this.navCursor = new NavCursor(app, camera, collision ?? null, events, state, this.picker, sceneBound.halfExtents.length());
|
|
82910
83232
|
}
|
|
82911
83233
|
const { instance } = gsplat;
|
|
82912
83234
|
if (instance) {
|
|
@@ -82941,18 +83263,22 @@ class Viewer {
|
|
|
82941
83263
|
high: 4
|
|
82942
83264
|
}
|
|
82943
83265
|
};
|
|
82944
|
-
const
|
|
82945
|
-
|
|
82946
|
-
|
|
82947
|
-
|
|
82948
|
-
|
|
82949
|
-
|
|
83266
|
+
const applyPerfSettings = () => {
|
|
83267
|
+
const budget = () => {
|
|
83268
|
+
if (config.budget !== undefined && Number.isFinite(config.budget) && config.budget > 0) {
|
|
83269
|
+
return config.budget;
|
|
83270
|
+
}
|
|
83271
|
+
const quality = platform.mobile ? budgets.mobile : budgets.desktop;
|
|
83272
|
+
return state.performanceMode ? quality.low : quality.high;
|
|
83273
|
+
};
|
|
83274
|
+
gsplat.splatBudget = budget() * 1000000;
|
|
83275
|
+
gsplat.lodRangeMin = 0;
|
|
83276
|
+
gsplat.lodRangeMax = 1000;
|
|
83277
|
+
gsplat.colorUpdateAngle = state.performanceMode ? 4 : 2;
|
|
82950
83278
|
};
|
|
82951
83279
|
if (config.fullload) {
|
|
82952
83280
|
// reveal once full quality has finished loading (used for screenshots)
|
|
82953
|
-
|
|
82954
|
-
gsplat.lodRangeMin = 0;
|
|
82955
|
-
gsplat.lodRangeMax = 1000;
|
|
83281
|
+
applyPerfSettings();
|
|
82956
83282
|
}
|
|
82957
83283
|
else {
|
|
82958
83284
|
// reveal once low lod has loaded for fastest possible reveal
|
|
@@ -82993,13 +83319,8 @@ class Viewer {
|
|
|
82993
83319
|
eventHandler.off('frame:ready', readyHandler);
|
|
82994
83320
|
state.readyToRender = true;
|
|
82995
83321
|
// handle quality mode changes
|
|
82996
|
-
|
|
82997
|
-
|
|
82998
|
-
gsplat.lodRangeMin = 0;
|
|
82999
|
-
gsplat.lodRangeMax = 1000;
|
|
83000
|
-
};
|
|
83001
|
-
events.on('performanceMode:changed', updateLod);
|
|
83002
|
-
updateLod();
|
|
83322
|
+
events.on('performanceMode:changed', applyPerfSettings);
|
|
83323
|
+
applyPerfSettings();
|
|
83003
83324
|
// debug colorize lods
|
|
83004
83325
|
gsplat.debug = config.colorize ? GSPLAT_DEBUG_LOD : GSPLAT_DEBUG_NONE;
|
|
83005
83326
|
gsplat.renderer = rendererTable[config.renderer];
|
|
@@ -83995,8 +84316,6 @@ const initXr = (global) => {
|
|
|
83995
84316
|
});
|
|
83996
84317
|
};
|
|
83997
84318
|
|
|
83998
|
-
var version = "1.22.0";
|
|
83999
|
-
|
|
84000
84319
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
84001
84320
|
const { contents, contentUrl, aa } = config;
|
|
84002
84321
|
const c = contents;
|