@playcanvas/supersplat-viewer 1.22.0 → 1.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/public/index.js +1116 -986
- 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);
|
|
@@ -78219,31 +78366,6 @@ const setBasisOffset = (out, x, y, z, forward, right, up) => {
|
|
|
78219
78366
|
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
78367
|
return out;
|
|
78221
78368
|
};
|
|
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
78369
|
|
|
78248
78370
|
/** Extra resolve passes above the collider's internal iteration for tight corners */
|
|
78249
78371
|
const MAX_COLLISION_PASSES = 4;
|
|
@@ -78264,7 +78386,7 @@ const SWEEP_RAY_OFFSETS = [
|
|
|
78264
78386
|
[-INV_SQRT2, -INV_SQRT2, false],
|
|
78265
78387
|
[INV_SQRT2, -INV_SQRT2, false]
|
|
78266
78388
|
];
|
|
78267
|
-
const v$
|
|
78389
|
+
const v$2 = new Vec3();
|
|
78268
78390
|
const remainingMove = new Vec3();
|
|
78269
78391
|
const collisionPush = new Vec3();
|
|
78270
78392
|
const sweepDir = new Vec3();
|
|
@@ -78338,10 +78460,10 @@ class SphereMover {
|
|
|
78338
78460
|
this.resolve(position);
|
|
78339
78461
|
return false;
|
|
78340
78462
|
}
|
|
78341
|
-
position.add(v$
|
|
78463
|
+
position.add(v$2.copy(sweepDir).mulScalar(sweepHit.travel));
|
|
78342
78464
|
this.resolve(position);
|
|
78343
78465
|
sweepNormal.set(sweepHit.nx, sweepHit.ny, sweepHit.nz);
|
|
78344
|
-
move.add(v$
|
|
78466
|
+
move.add(v$2.copy(sweepDir).mulScalar(-sweepHit.travel));
|
|
78345
78467
|
this._clipMove(move, sweepNormal);
|
|
78346
78468
|
return true;
|
|
78347
78469
|
}
|
|
@@ -78361,8 +78483,8 @@ class SphereMover {
|
|
|
78361
78483
|
const rayExtension = centerRay ? this.radius : 0;
|
|
78362
78484
|
sweepOrigin.copy(position);
|
|
78363
78485
|
if (!centerRay) {
|
|
78364
|
-
sweepOrigin.add(v$
|
|
78365
|
-
sweepOrigin.add(v$
|
|
78486
|
+
sweepOrigin.add(v$2.copy(sweepTangent).mulScalar(tx * radiusOffset));
|
|
78487
|
+
sweepOrigin.add(v$2.copy(sweepBitangent).mulScalar(ty * radiusOffset));
|
|
78366
78488
|
}
|
|
78367
78489
|
const hit = this.collision.queryRay(sweepOrigin.x, sweepOrigin.y, sweepOrigin.z, dir.x, dir.y, dir.z, distance + rayExtension + COLLISION_SKIN);
|
|
78368
78490
|
if (!hit) {
|
|
@@ -78437,9 +78559,9 @@ class SphereMover {
|
|
|
78437
78559
|
|
|
78438
78560
|
/** Radius of the camera collision sphere (meters) */
|
|
78439
78561
|
const CAMERA_RADIUS = 0.2;
|
|
78440
|
-
const forward$
|
|
78441
|
-
const right$
|
|
78442
|
-
const up$
|
|
78562
|
+
const forward$2 = new Vec3();
|
|
78563
|
+
const right$2 = new Vec3();
|
|
78564
|
+
const up$1 = new Vec3();
|
|
78443
78565
|
const offset$1 = new Vec3();
|
|
78444
78566
|
class FlyController {
|
|
78445
78567
|
fov = 90;
|
|
@@ -78502,8 +78624,8 @@ class FlyController {
|
|
|
78502
78624
|
this._hasSpawn = true;
|
|
78503
78625
|
}
|
|
78504
78626
|
_step(move) {
|
|
78505
|
-
setCameraBasis(this._angles, forward$
|
|
78506
|
-
setBasisOffset(offset$1, move[0], move[1], move[2], forward$
|
|
78627
|
+
setCameraBasis(this._angles, forward$2, right$2, up$1);
|
|
78628
|
+
setBasisOffset(offset$1, move[0], move[1], move[2], forward$2, right$2, up$1);
|
|
78507
78629
|
this._mover.move(this._position, offset$1);
|
|
78508
78630
|
}
|
|
78509
78631
|
}
|
|
@@ -78588,7 +78710,7 @@ const BLOCKED_SPEED$1 = 0.25;
|
|
|
78588
78710
|
/** Seconds of continuous low-progress before stopping the flight */
|
|
78589
78711
|
const BLOCKED_DURATION$1 = 0.5;
|
|
78590
78712
|
const toTarget = new Vec3();
|
|
78591
|
-
const forward$
|
|
78713
|
+
const forward$1 = new Vec3();
|
|
78592
78714
|
const postTurnAngles = new Vec3();
|
|
78593
78715
|
const getStopDistance = (fov) => {
|
|
78594
78716
|
const halfFov = math.clamp(fov, 15, 120) * DEG_TO_RAD * 0.5;
|
|
@@ -78627,7 +78749,7 @@ class FlySource {
|
|
|
78627
78749
|
_pitchRate = 0;
|
|
78628
78750
|
_speed = 0;
|
|
78629
78751
|
_progress = new ProgressTracker();
|
|
78630
|
-
get
|
|
78752
|
+
get isActive() {
|
|
78631
78753
|
return this._target !== null;
|
|
78632
78754
|
}
|
|
78633
78755
|
/**
|
|
@@ -78635,7 +78757,7 @@ class FlySource {
|
|
|
78635
78757
|
*
|
|
78636
78758
|
* @param target - The destination.
|
|
78637
78759
|
*/
|
|
78638
|
-
|
|
78760
|
+
navigateTo(target) {
|
|
78639
78761
|
const wasFlying = this._target !== null;
|
|
78640
78762
|
if (!this._target) {
|
|
78641
78763
|
this._target = new Vec3();
|
|
@@ -78651,7 +78773,7 @@ class FlySource {
|
|
|
78651
78773
|
/**
|
|
78652
78774
|
* Cancel any active auto-flight.
|
|
78653
78775
|
*/
|
|
78654
|
-
|
|
78776
|
+
cancel() {
|
|
78655
78777
|
if (this._target) {
|
|
78656
78778
|
this._target = null;
|
|
78657
78779
|
this._yawRate = 0;
|
|
@@ -78666,22 +78788,22 @@ class FlySource {
|
|
|
78666
78788
|
* the camera controller reads the frame.
|
|
78667
78789
|
*
|
|
78668
78790
|
* @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.
|
|
78791
|
+
* @param camera - The current camera state (read-only).
|
|
78672
78792
|
* @param frame - The shared CameraFrame to append deltas to.
|
|
78673
78793
|
*/
|
|
78674
|
-
update(dt,
|
|
78794
|
+
update(dt, camera, frame) {
|
|
78675
78795
|
if (!this._target)
|
|
78676
78796
|
return;
|
|
78677
78797
|
const target = this._target;
|
|
78798
|
+
const cameraPosition = camera.position;
|
|
78799
|
+
const cameraAngles = camera.angles;
|
|
78678
78800
|
toTarget.sub2(target, cameraPosition);
|
|
78679
78801
|
const dist = toTarget.length();
|
|
78680
|
-
const stopDistance = getStopDistance(
|
|
78802
|
+
const stopDistance = getStopDistance(camera.fov);
|
|
78681
78803
|
const remainingDist = dist - stopDistance;
|
|
78682
78804
|
const activeRemainingDist = Math.max(0, remainingDist);
|
|
78683
78805
|
if (activeRemainingDist <= ARRIVAL_EPSILON && this._speed <= ARRIVAL_SPEED) {
|
|
78684
|
-
this.
|
|
78806
|
+
this.cancel();
|
|
78685
78807
|
return;
|
|
78686
78808
|
}
|
|
78687
78809
|
if (dt <= 0) {
|
|
@@ -78702,8 +78824,8 @@ class FlySource {
|
|
|
78702
78824
|
// FlyController applies: _angles += [-rotateY, -rotateX, 0]
|
|
78703
78825
|
frame.deltas.rotate.append([-yawStep, -pitchStep, 0]);
|
|
78704
78826
|
postTurnAngles.set(cameraAngles.x + pitchStep, cameraAngles.y + yawStep, 0);
|
|
78705
|
-
setCameraForward(postTurnAngles, forward$
|
|
78706
|
-
const alignment = math.clamp(forward$
|
|
78827
|
+
setCameraForward(postTurnAngles, forward$1);
|
|
78828
|
+
const alignment = math.clamp(forward$1.x * dirX + forward$1.y * dirY + forward$1.z * dirZ, 0, 1);
|
|
78707
78829
|
const alignmentScale = smoothstep(0.05, 0.95, alignment);
|
|
78708
78830
|
const brakeSpeed = Math.sqrt(2 * this.moveDeceleration * activeRemainingDist);
|
|
78709
78831
|
const arrivalSpeed = activeRemainingDist * ARRIVAL_RATE;
|
|
@@ -78722,72 +78844,146 @@ class FlySource {
|
|
|
78722
78844
|
// Only treat low progress as blocked once the camera is substantially
|
|
78723
78845
|
// facing the target; otherwise a large turn-in-place would cancel early.
|
|
78724
78846
|
if (this._progress.update(dist, dt, BLOCKED_SPEED$1, BLOCKED_DURATION$1, alignment > 0.5 && this._speed > BLOCKED_SPEED$1)) {
|
|
78725
|
-
this.
|
|
78847
|
+
this.cancel();
|
|
78726
78848
|
}
|
|
78727
78849
|
}
|
|
78728
78850
|
}
|
|
78729
78851
|
|
|
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();
|
|
78852
|
+
const p = new Pose();
|
|
78737
78853
|
class OrbitController {
|
|
78854
|
+
controller;
|
|
78738
78855
|
fov = 90;
|
|
78739
|
-
|
|
78740
|
-
|
|
78741
|
-
|
|
78742
|
-
|
|
78743
|
-
|
|
78744
|
-
|
|
78745
|
-
|
|
78746
|
-
|
|
78747
|
-
_targetDistance = 1;
|
|
78856
|
+
constructor() {
|
|
78857
|
+
this.controller = new OrbitController$1();
|
|
78858
|
+
this.controller.zoomRange = new Vec2(0.01, Infinity);
|
|
78859
|
+
this.controller.pitchRange = new Vec2(-90, 90);
|
|
78860
|
+
this.controller.rotateDamping = 0.97;
|
|
78861
|
+
this.controller.moveDamping = 0.97;
|
|
78862
|
+
this.controller.zoomDamping = 0.97;
|
|
78863
|
+
}
|
|
78748
78864
|
onEnter(camera) {
|
|
78749
|
-
this.
|
|
78865
|
+
this._attach(camera);
|
|
78750
78866
|
}
|
|
78751
78867
|
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;
|
|
78868
|
+
const pose = this.controller.update(inputFrame, deltaTime);
|
|
78869
|
+
camera.position.copy(pose.position);
|
|
78870
|
+
camera.angles.copy(pose.angles);
|
|
78871
|
+
camera.distance = pose.distance;
|
|
78765
78872
|
camera.fov = this.fov;
|
|
78766
78873
|
}
|
|
78767
78874
|
onExit(_camera) {
|
|
78768
78875
|
}
|
|
78769
78876
|
goto(camera) {
|
|
78770
|
-
this.
|
|
78877
|
+
this.fov = camera.fov;
|
|
78878
|
+
this._attach(camera);
|
|
78771
78879
|
}
|
|
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
|
-
}
|
|
78880
|
+
_attach(camera) {
|
|
78881
|
+
p.position.copy(camera.position);
|
|
78882
|
+
p.angles.copy(camera.angles);
|
|
78883
|
+
p.distance = Math.max(camera.distance, this.controller.zoomRange.x);
|
|
78884
|
+
this.controller.attach(p, false);
|
|
78783
78885
|
}
|
|
78784
78886
|
}
|
|
78785
78887
|
|
|
78786
|
-
const FIXED_DT = 1 / 60;
|
|
78787
|
-
const MAX_SUBSTEPS = 10;
|
|
78788
78888
|
const SPAWN_HIT_EPSILON = 1e-3;
|
|
78789
78889
|
const SPAWN_SEARCH_MIN_STEP = 0.05;
|
|
78790
78890
|
const SPAWN_SEARCH_MAX_STEPS = 128;
|
|
78891
|
+
const out$1 = { x: 0, y: 0, z: 0 };
|
|
78892
|
+
const v$1 = new Vec3();
|
|
78893
|
+
const probe = new Vec3();
|
|
78894
|
+
const queryCapsule = (collision, pos, p) => {
|
|
78895
|
+
const half = p.capsuleHeight * 0.5 - p.capsuleRadius;
|
|
78896
|
+
const center = pos.y - p.eyeHeight + p.capsuleHeight * 0.5;
|
|
78897
|
+
return collision.queryCapsule(pos.x, center, pos.z, half, p.capsuleRadius, out$1);
|
|
78898
|
+
};
|
|
78899
|
+
const eyeYFromGround = (groundY, p) => groundY + p.hoverHeight + p.eyeHeight;
|
|
78900
|
+
const isInsideSolid = (collision, pos) => {
|
|
78901
|
+
return collision.querySphere(pos.x, pos.y, pos.z, SPAWN_HIT_EPSILON, out$1);
|
|
78902
|
+
};
|
|
78903
|
+
const probeGroundY = (collision, pos, p) => {
|
|
78904
|
+
const hit = collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, p.spawnSearchRange);
|
|
78905
|
+
return hit ? hit.y : null;
|
|
78906
|
+
};
|
|
78907
|
+
const hasSpawnGroundSupport = (collision, pos, p) => {
|
|
78908
|
+
const groundY = probeGroundY(collision, pos, p);
|
|
78909
|
+
if (groundY === null) {
|
|
78910
|
+
return false;
|
|
78911
|
+
}
|
|
78912
|
+
const clearance = pos.y - p.eyeHeight - groundY;
|
|
78913
|
+
return clearance >= -SPAWN_HIT_EPSILON &&
|
|
78914
|
+
clearance <= p.hoverHeight + p.capsuleRadius + SPAWN_HIT_EPSILON;
|
|
78915
|
+
};
|
|
78916
|
+
// Push a candidate eye position out of solid geometry. Returns true if the
|
|
78917
|
+
// candidate becomes clear within the allowed budget and remains supported by
|
|
78918
|
+
// ground beneath it.
|
|
78919
|
+
const resolveSpawnCandidate = (collision, pos, p) => {
|
|
78920
|
+
const startX = pos.x;
|
|
78921
|
+
const startY = pos.y;
|
|
78922
|
+
const startZ = pos.z;
|
|
78923
|
+
const maxResolveDistance = p.capsuleRadius + p.hoverHeight;
|
|
78924
|
+
const maxResolveDistanceSq = maxResolveDistance * maxResolveDistance;
|
|
78925
|
+
for (let i = 0; i < 100; i++) {
|
|
78926
|
+
if (!queryCapsule(collision, pos, p)) {
|
|
78927
|
+
return hasSpawnGroundSupport(collision, pos, p);
|
|
78928
|
+
}
|
|
78929
|
+
pos.add(v$1.set(out$1.x, out$1.y, out$1.z));
|
|
78930
|
+
const dx = pos.x - startX;
|
|
78931
|
+
const dy = pos.y - startY;
|
|
78932
|
+
const dz = pos.z - startZ;
|
|
78933
|
+
if (dx * dx + dy * dy + dz * dz > maxResolveDistanceSq) {
|
|
78934
|
+
return false;
|
|
78935
|
+
}
|
|
78936
|
+
}
|
|
78937
|
+
return false;
|
|
78938
|
+
};
|
|
78939
|
+
// Find the first collision surface below a point that can hold a clear walk
|
|
78940
|
+
// capsule. Writes the resolved eye position to outPos on success.
|
|
78941
|
+
const findClearSpawnGroundBelow = (collision, pos, range, allowInitialHit, p, outPos) => {
|
|
78942
|
+
const hit = collision.queryRay(pos.x, pos.y, pos.z, 0, -1, 0, range);
|
|
78943
|
+
if (!hit) {
|
|
78944
|
+
return false;
|
|
78945
|
+
}
|
|
78946
|
+
if (!allowInitialHit && Math.abs(pos.y - hit.y) <= SPAWN_HIT_EPSILON) {
|
|
78947
|
+
return false;
|
|
78948
|
+
}
|
|
78949
|
+
outPos.set(pos.x, eyeYFromGround(hit.y, p), pos.z);
|
|
78950
|
+
const clear = !queryCapsule(collision, outPos, p);
|
|
78951
|
+
return clear || resolveSpawnCandidate(collision, outPos, p);
|
|
78952
|
+
};
|
|
78953
|
+
const searchSpawnGround = (collision, pos, direction, p, outPos) => {
|
|
78954
|
+
const step = Math.max(p.capsuleRadius, p.hoverHeight, SPAWN_SEARCH_MIN_STEP, p.spawnSearchRange / SPAWN_SEARCH_MAX_STEPS);
|
|
78955
|
+
const endY = pos.y + direction * p.spawnSearchRange;
|
|
78956
|
+
for (let y = pos.y + direction * step; direction < 0 ? y >= endY : y <= endY; y += direction * step) {
|
|
78957
|
+
probe.set(pos.x, y, pos.z);
|
|
78958
|
+
if (findClearSpawnGroundBelow(collision, probe, p.spawnSearchRange, false, p, outPos)) {
|
|
78959
|
+
return true;
|
|
78960
|
+
}
|
|
78961
|
+
}
|
|
78962
|
+
return false;
|
|
78963
|
+
};
|
|
78964
|
+
/**
|
|
78965
|
+
* Find an eye position for spawning into walk mode. Prefer ground directly
|
|
78966
|
+
* below the camera; if that is not usable, search down and then up for the
|
|
78967
|
+
* first clear walk placement with ground below it. On success, the resolved
|
|
78968
|
+
* eye position is written to outPos.
|
|
78969
|
+
*
|
|
78970
|
+
* @param collision - The active collision implementation.
|
|
78971
|
+
* @param pos - Incoming camera position.
|
|
78972
|
+
* @param p - Walk capsule and spawn-search parameters.
|
|
78973
|
+
* @param outPos - Receives the resolved eye position.
|
|
78974
|
+
* @returns True if a spawn position was found.
|
|
78975
|
+
*/
|
|
78976
|
+
const findWalkSpawn = (collision, pos, p, outPos) => {
|
|
78977
|
+
const insideSolid = isInsideSolid(collision, pos);
|
|
78978
|
+
if (findClearSpawnGroundBelow(collision, pos, p.spawnSearchRange, !insideSolid, p, outPos)) {
|
|
78979
|
+
return true;
|
|
78980
|
+
}
|
|
78981
|
+
return searchSpawnGround(collision, pos, -1, p, outPos) ||
|
|
78982
|
+
searchSpawnGround(collision, pos, 1, p, outPos);
|
|
78983
|
+
};
|
|
78984
|
+
|
|
78985
|
+
const FIXED_DT = 1 / 60;
|
|
78986
|
+
const MAX_SUBSTEPS = 10;
|
|
78791
78987
|
/** Pre-allocated push-out vector for capsule collision */
|
|
78792
78988
|
const out = { x: 0, y: 0, z: 0 };
|
|
78793
78989
|
const v = new Vec3();
|
|
@@ -78899,11 +79095,10 @@ class WalkController {
|
|
|
78899
79095
|
this.goto(camera);
|
|
78900
79096
|
if (this.collision) {
|
|
78901
79097
|
this._hasSpawn = false;
|
|
78902
|
-
if (this.
|
|
79098
|
+
if (findWalkSpawn(this.collision, camera.position, this, spawnProbe)) {
|
|
78903
79099
|
this._position.copy(spawnProbe);
|
|
78904
79100
|
this._grounded = true;
|
|
78905
79101
|
this._velocity.y = 0;
|
|
78906
|
-
this._resolveSpawnCollision();
|
|
78907
79102
|
this._storeSpawn();
|
|
78908
79103
|
}
|
|
78909
79104
|
this._prevPosition.copy(this._position);
|
|
@@ -79047,146 +79242,6 @@ class WalkController {
|
|
|
79047
79242
|
this._pendingMove[2] = 0;
|
|
79048
79243
|
this._accumulator = 0;
|
|
79049
79244
|
}
|
|
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
79245
|
/**
|
|
79191
79246
|
* Cast multiple rays downward to find the average ground surface height.
|
|
79192
79247
|
* Uses 5 rays (center + 4 cardinal at capsule radius) to spatially filter
|
|
@@ -79285,7 +79340,7 @@ class WalkSource {
|
|
|
79285
79340
|
_target = null;
|
|
79286
79341
|
_yawRate = 0;
|
|
79287
79342
|
_progress = new ProgressTracker();
|
|
79288
|
-
get
|
|
79343
|
+
get isActive() {
|
|
79289
79344
|
return this._target !== null;
|
|
79290
79345
|
}
|
|
79291
79346
|
/**
|
|
@@ -79293,7 +79348,7 @@ class WalkSource {
|
|
|
79293
79348
|
*
|
|
79294
79349
|
* @param target - The destination (XZ used for navigation).
|
|
79295
79350
|
*/
|
|
79296
|
-
|
|
79351
|
+
navigateTo(target) {
|
|
79297
79352
|
if (!this._target) {
|
|
79298
79353
|
this._target = new Vec3();
|
|
79299
79354
|
}
|
|
@@ -79303,7 +79358,7 @@ class WalkSource {
|
|
|
79303
79358
|
/**
|
|
79304
79359
|
* Cancel any active auto-walk.
|
|
79305
79360
|
*/
|
|
79306
|
-
|
|
79361
|
+
cancel() {
|
|
79307
79362
|
if (this._target) {
|
|
79308
79363
|
this._target = null;
|
|
79309
79364
|
this._yawRate = 0;
|
|
@@ -79316,25 +79371,26 @@ class WalkSource {
|
|
|
79316
79371
|
* before* the camera controller reads the frame.
|
|
79317
79372
|
*
|
|
79318
79373
|
* @param dt - Frame delta time in seconds.
|
|
79319
|
-
* @param
|
|
79320
|
-
* @param cameraAngles - Camera Euler angles in degrees (previous frame output).
|
|
79374
|
+
* @param camera - The current camera state (read-only).
|
|
79321
79375
|
* @param frame - The shared CameraFrame to append deltas to.
|
|
79322
79376
|
*/
|
|
79323
|
-
update(dt,
|
|
79377
|
+
update(dt, camera, frame) {
|
|
79324
79378
|
if (!this._target)
|
|
79325
79379
|
return;
|
|
79326
79380
|
const target = this._target;
|
|
79381
|
+
const cameraPosition = camera.position;
|
|
79382
|
+
const cameraAngles = camera.angles;
|
|
79327
79383
|
const dx = target.x - cameraPosition.x;
|
|
79328
79384
|
const dz = target.z - cameraPosition.z;
|
|
79329
79385
|
const xzDist = Math.sqrt(dx * dx + dz * dz);
|
|
79330
79386
|
// arrival
|
|
79331
79387
|
if (xzDist < ARRIVAL_DIST) {
|
|
79332
|
-
this.
|
|
79388
|
+
this.cancel();
|
|
79333
79389
|
return;
|
|
79334
79390
|
}
|
|
79335
79391
|
// blocked detection: compare with previous frame's distance
|
|
79336
79392
|
if (this._progress.update(xzDist, dt, BLOCKED_SPEED, BLOCKED_DURATION)) {
|
|
79337
|
-
this.
|
|
79393
|
+
this.cancel();
|
|
79338
79394
|
return;
|
|
79339
79395
|
}
|
|
79340
79396
|
// yaw toward target with smoothed turn rate
|
|
@@ -79405,12 +79461,13 @@ class CameraManager {
|
|
|
79405
79461
|
controllers.fly.collision = collision;
|
|
79406
79462
|
controllers.walk.collision = collision;
|
|
79407
79463
|
const walkSource = new WalkSource();
|
|
79408
|
-
walkSource.onComplete = () => {
|
|
79409
|
-
events.fire('walkComplete');
|
|
79410
|
-
};
|
|
79411
79464
|
const flySource = new FlySource();
|
|
79412
|
-
|
|
79413
|
-
|
|
79465
|
+
const sourcesByMode = {
|
|
79466
|
+
walk: walkSource,
|
|
79467
|
+
fly: flySource
|
|
79468
|
+
};
|
|
79469
|
+
walkSource.onComplete = flySource.onComplete = () => {
|
|
79470
|
+
events.fire('navigateComplete');
|
|
79414
79471
|
};
|
|
79415
79472
|
const getController = (cameraMode) => {
|
|
79416
79473
|
return controllers[cameraMode];
|
|
@@ -79446,12 +79503,7 @@ class CameraManager {
|
|
|
79446
79503
|
const prevTransitionTimer = transitionTimer;
|
|
79447
79504
|
transitionTimer = Math.min(1, transitionTimer + deltaTime * transitionSpeed);
|
|
79448
79505
|
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
|
-
}
|
|
79506
|
+
sourcesByMode[state.cameraMode]?.update(dt, this.camera, frame);
|
|
79455
79507
|
controller.update(dt, frame, target);
|
|
79456
79508
|
if (transitionTimer < 1) {
|
|
79457
79509
|
// lerp away from previous camera during transition
|
|
@@ -79480,13 +79532,13 @@ class CameraManager {
|
|
|
79480
79532
|
break;
|
|
79481
79533
|
case 'reset':
|
|
79482
79534
|
if (state.cameraMode === 'walk') {
|
|
79483
|
-
walkSource.
|
|
79484
|
-
events.fire('
|
|
79535
|
+
walkSource.cancel();
|
|
79536
|
+
events.fire('navTarget:clear');
|
|
79485
79537
|
startTransition();
|
|
79486
79538
|
controllers.walk.resetToSpawn(target);
|
|
79487
79539
|
}
|
|
79488
79540
|
else if (state.cameraMode === 'fly') {
|
|
79489
|
-
flySource.
|
|
79541
|
+
flySource.cancel();
|
|
79490
79542
|
startTransition();
|
|
79491
79543
|
controllers.fly.resetToSpawn(target);
|
|
79492
79544
|
}
|
|
@@ -79541,12 +79593,7 @@ class CameraManager {
|
|
|
79541
79593
|
});
|
|
79542
79594
|
// handle camera mode switching
|
|
79543
79595
|
events.on('cameraMode:changed', (value, prev) => {
|
|
79544
|
-
|
|
79545
|
-
walkSource.cancelWalk();
|
|
79546
|
-
}
|
|
79547
|
-
else if (prev === 'fly') {
|
|
79548
|
-
flySource.cancelFly();
|
|
79549
|
-
}
|
|
79596
|
+
sourcesByMode[prev]?.cancel();
|
|
79550
79597
|
// snapshot the current pose before any controller mutation
|
|
79551
79598
|
startTransition();
|
|
79552
79599
|
target.copy(this.camera);
|
|
@@ -79587,35 +79634,21 @@ class CameraManager {
|
|
|
79587
79634
|
controllers.orbit.goto(tmpCamera);
|
|
79588
79635
|
startTransition();
|
|
79589
79636
|
});
|
|
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);
|
|
79637
|
+
// tap-to-navigate: start auto-driving the active mode toward a picked position
|
|
79638
|
+
events.on('navigateTo', (position, normal) => {
|
|
79639
|
+
const source = sourcesByMode[state.cameraMode];
|
|
79640
|
+
if (source) {
|
|
79641
|
+
source.navigateTo(position);
|
|
79642
|
+
events.fire('navTarget:set', position, normal);
|
|
79610
79643
|
}
|
|
79611
79644
|
});
|
|
79612
|
-
// cancel any active auto-
|
|
79613
|
-
events.on('
|
|
79614
|
-
|
|
79615
|
-
events.fire('
|
|
79645
|
+
// cancel any active auto-navigation in the current mode
|
|
79646
|
+
events.on('navigateCancel', () => {
|
|
79647
|
+
sourcesByMode[state.cameraMode]?.cancel();
|
|
79648
|
+
events.fire('navTarget:clear');
|
|
79616
79649
|
});
|
|
79617
|
-
events.on('
|
|
79618
|
-
events.fire('
|
|
79650
|
+
events.on('navigateComplete', () => {
|
|
79651
|
+
events.fire('navTarget:clear');
|
|
79619
79652
|
});
|
|
79620
79653
|
}
|
|
79621
79654
|
}
|
|
@@ -79735,146 +79768,6 @@ class ModeShortcuts {
|
|
|
79735
79768
|
}
|
|
79736
79769
|
}
|
|
79737
79770
|
|
|
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
79771
|
/**
|
|
79879
79772
|
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79880
79773
|
* pixel offsets that already scale with frame time. This factor converts
|
|
@@ -79935,7 +79828,7 @@ const canTargetFly = (global) => (global.state.cameraMode === 'fly' &&
|
|
|
79935
79828
|
* on mobile, and double-click-to-pick fallback. Uses collision first and
|
|
79936
79829
|
* rendered-scene picking when collision is unavailable.
|
|
79937
79830
|
*/
|
|
79938
|
-
class
|
|
79831
|
+
class NavInteraction {
|
|
79939
79832
|
collision = null;
|
|
79940
79833
|
_picker;
|
|
79941
79834
|
_global = null;
|
|
@@ -80008,7 +79901,7 @@ class WalkInteraction {
|
|
|
80008
79901
|
const request = ++this._targetPickRequest;
|
|
80009
79902
|
const target = await this._pickSceneTarget(offsetX, offsetY);
|
|
80010
79903
|
if (target && request === this._targetPickRequest && this._global && canTargetFly(this._global)) {
|
|
80011
|
-
this._global.events.fire('
|
|
79904
|
+
this._global.events.fire('navigateTo', target.position, target.normal);
|
|
80012
79905
|
}
|
|
80013
79906
|
}
|
|
80014
79907
|
async _focusPickedPosition(offsetX, offsetY) {
|
|
@@ -80063,11 +79956,8 @@ class WalkInteraction {
|
|
|
80063
79956
|
const prev = this._mouseClickDelta;
|
|
80064
79957
|
this._mouseClickDelta += Math.abs(event.movementX) + Math.abs(event.movementY);
|
|
80065
79958
|
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');
|
|
79959
|
+
if ((state.cameraMode === 'walk' && !state.gamingControls) || canTargetFly(global)) {
|
|
79960
|
+
events.fire('navigateCancel');
|
|
80071
79961
|
}
|
|
80072
79962
|
}
|
|
80073
79963
|
}
|
|
@@ -80088,7 +79978,7 @@ class WalkInteraction {
|
|
|
80088
79978
|
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80089
79979
|
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80090
79980
|
if (result) {
|
|
80091
|
-
events.fire('
|
|
79981
|
+
events.fire('navigateTo', result.position, result.normal);
|
|
80092
79982
|
}
|
|
80093
79983
|
}
|
|
80094
79984
|
else if (state.cameraMode === 'fly') {
|
|
@@ -80110,19 +80000,23 @@ class WalkInteraction {
|
|
|
80110
80000
|
if (!(event instanceof MouseEvent))
|
|
80111
80001
|
return;
|
|
80112
80002
|
const { events, state } = global;
|
|
80113
|
-
|
|
80114
|
-
|
|
80003
|
+
// dblclick swaps the active mode and uses the picked target:
|
|
80004
|
+
// fly → orbit, focus orbit at point
|
|
80005
|
+
// orbit / walk → fly, navigate fly toward point
|
|
80006
|
+
const request = ++this._targetPickRequest;
|
|
80007
|
+
const target = await this._pickSceneTarget(event.offsetX, event.offsetY);
|
|
80008
|
+
if (!target || request !== this._targetPickRequest)
|
|
80115
80009
|
return;
|
|
80116
|
-
|
|
80117
|
-
|
|
80010
|
+
const currentMode = this._global?.state.cameraMode;
|
|
80011
|
+
if (currentMode === 'fly') {
|
|
80012
|
+
// 'pick' switches mode to orbit, which cancels the active fly nav
|
|
80013
|
+
// and would clobber any pre-set orbit target — set it after.
|
|
80014
|
+
events.fire('pick', target.position);
|
|
80015
|
+
events.fire('orbitTarget:set', target.position, target.normal);
|
|
80118
80016
|
}
|
|
80119
|
-
else if (
|
|
80120
|
-
|
|
80121
|
-
|
|
80122
|
-
if (target && request === this._targetPickRequest && this._global?.state.cameraMode === cameraMode) {
|
|
80123
|
-
events.fire('orbitTarget:set', target.position, target.normal);
|
|
80124
|
-
events.fire('pick', target.position);
|
|
80125
|
-
}
|
|
80017
|
+
else if (currentMode === 'orbit' || currentMode === 'walk') {
|
|
80018
|
+
state.cameraMode = 'fly';
|
|
80019
|
+
events.fire('navigateTo', target.position, target.normal);
|
|
80126
80020
|
}
|
|
80127
80021
|
};
|
|
80128
80022
|
_onMobileTap = () => {
|
|
@@ -80137,7 +80031,7 @@ class WalkInteraction {
|
|
|
80137
80031
|
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80138
80032
|
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80139
80033
|
if (result) {
|
|
80140
|
-
events.fire('
|
|
80034
|
+
events.fire('navigateTo', result.position, result.normal);
|
|
80141
80035
|
}
|
|
80142
80036
|
}
|
|
80143
80037
|
else if (state.cameraMode === 'fly') {
|
|
@@ -80182,6 +80076,146 @@ class WalkInteraction {
|
|
|
80182
80076
|
}
|
|
80183
80077
|
}
|
|
80184
80078
|
|
|
80079
|
+
const isCaptureMode = (mode) => mode === 'walk' || mode === 'fly';
|
|
80080
|
+
const hasUserActivation = () => (navigator.userActivation?.isActive === true);
|
|
80081
|
+
/**
|
|
80082
|
+
* Manages the browser's pointer-lock API for first-person gaming controls
|
|
80083
|
+
* on desktop. Toggles in response to camera mode, input mode, and
|
|
80084
|
+
* gaming-controls changes, and reverts state if the lock is exited or rejected.
|
|
80085
|
+
*
|
|
80086
|
+
* Also exposes `recentlyExitedCapture` so the keyboard-shortcut handler can
|
|
80087
|
+
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
80088
|
+
*/
|
|
80089
|
+
class PointerLockManager {
|
|
80090
|
+
_global = null;
|
|
80091
|
+
_canvas = null;
|
|
80092
|
+
_keyboardMouse = null;
|
|
80093
|
+
_recentlyExitedCapture = false;
|
|
80094
|
+
_onPointerLockChange = () => {
|
|
80095
|
+
const global = this._global;
|
|
80096
|
+
if (!global)
|
|
80097
|
+
return;
|
|
80098
|
+
const { state, events } = global;
|
|
80099
|
+
if (!document.pointerLockElement && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
80100
|
+
this._recentlyExitedCapture = true;
|
|
80101
|
+
requestAnimationFrame(() => {
|
|
80102
|
+
this._recentlyExitedCapture = false;
|
|
80103
|
+
});
|
|
80104
|
+
if (state.inputMode === 'desktop') {
|
|
80105
|
+
state.gamingControls = false;
|
|
80106
|
+
}
|
|
80107
|
+
else if (state.cameraMode === 'walk') {
|
|
80108
|
+
events.fire('inputEvent', 'exitWalk');
|
|
80109
|
+
}
|
|
80110
|
+
}
|
|
80111
|
+
};
|
|
80112
|
+
_onPointerLockError = () => {
|
|
80113
|
+
// Pointer lock request rejected (no user gesture, document hidden,
|
|
80114
|
+
// etc). Revert state so we don't end up stuck in walk mode without
|
|
80115
|
+
// mouse capture.
|
|
80116
|
+
if (this._keyboardMouse) {
|
|
80117
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
80118
|
+
}
|
|
80119
|
+
const global = this._global;
|
|
80120
|
+
if (!global)
|
|
80121
|
+
return;
|
|
80122
|
+
const { state, events } = global;
|
|
80123
|
+
if (state.inputMode === 'desktop' && isCaptureMode(state.cameraMode)) {
|
|
80124
|
+
state.gamingControls = false;
|
|
80125
|
+
}
|
|
80126
|
+
else if (state.cameraMode === 'walk') {
|
|
80127
|
+
events.fire('inputEvent', 'exitWalk');
|
|
80128
|
+
}
|
|
80129
|
+
};
|
|
80130
|
+
_onCameraModeChanged = (value, prev) => {
|
|
80131
|
+
const state = this._global?.state;
|
|
80132
|
+
if (!state)
|
|
80133
|
+
return;
|
|
80134
|
+
if (isCaptureMode(value) && state.inputMode === 'desktop' && state.gamingControls) {
|
|
80135
|
+
this._activate();
|
|
80136
|
+
}
|
|
80137
|
+
else if (isCaptureMode(prev)) {
|
|
80138
|
+
this._deactivate();
|
|
80139
|
+
}
|
|
80140
|
+
};
|
|
80141
|
+
_onGamingControlsChanged = (value) => {
|
|
80142
|
+
const state = this._global?.state;
|
|
80143
|
+
if (!state)
|
|
80144
|
+
return;
|
|
80145
|
+
if (isCaptureMode(state.cameraMode) && state.inputMode === 'desktop') {
|
|
80146
|
+
if (value) {
|
|
80147
|
+
this._activate();
|
|
80148
|
+
}
|
|
80149
|
+
else {
|
|
80150
|
+
this._deactivate();
|
|
80151
|
+
}
|
|
80152
|
+
}
|
|
80153
|
+
};
|
|
80154
|
+
_onInputModeChanged = (value) => {
|
|
80155
|
+
const state = this._global?.state;
|
|
80156
|
+
if (!state || !isCaptureMode(state.cameraMode) || !state.gamingControls) {
|
|
80157
|
+
return;
|
|
80158
|
+
}
|
|
80159
|
+
if (value === 'desktop' && hasUserActivation()) {
|
|
80160
|
+
this._activate();
|
|
80161
|
+
}
|
|
80162
|
+
else if (value !== 'desktop') {
|
|
80163
|
+
this._deactivate();
|
|
80164
|
+
}
|
|
80165
|
+
};
|
|
80166
|
+
_onPointerDown = () => {
|
|
80167
|
+
const state = this._global?.state;
|
|
80168
|
+
if (state && state.inputMode === 'desktop' && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
80169
|
+
this._activate();
|
|
80170
|
+
}
|
|
80171
|
+
};
|
|
80172
|
+
_activate() {
|
|
80173
|
+
if (this._keyboardMouse) {
|
|
80174
|
+
this._keyboardMouse.source._pointerLock = true;
|
|
80175
|
+
}
|
|
80176
|
+
if (document.pointerLockElement !== this._canvas) {
|
|
80177
|
+
this._canvas?.requestPointerLock();
|
|
80178
|
+
}
|
|
80179
|
+
}
|
|
80180
|
+
_deactivate() {
|
|
80181
|
+
if (this._keyboardMouse) {
|
|
80182
|
+
this._keyboardMouse.source._pointerLock = false;
|
|
80183
|
+
}
|
|
80184
|
+
if (document.pointerLockElement === this._canvas) {
|
|
80185
|
+
document.exitPointerLock();
|
|
80186
|
+
}
|
|
80187
|
+
}
|
|
80188
|
+
get recentlyExitedCapture() {
|
|
80189
|
+
return this._recentlyExitedCapture;
|
|
80190
|
+
}
|
|
80191
|
+
attach(canvas, global, keyboardMouse) {
|
|
80192
|
+
this._canvas = canvas;
|
|
80193
|
+
this._global = global;
|
|
80194
|
+
this._keyboardMouse = keyboardMouse;
|
|
80195
|
+
const { events } = global;
|
|
80196
|
+
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
80197
|
+
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
80198
|
+
events.on('inputMode:changed', this._onInputModeChanged);
|
|
80199
|
+
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
80200
|
+
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
80201
|
+
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
80202
|
+
}
|
|
80203
|
+
detach() {
|
|
80204
|
+
if (this._global) {
|
|
80205
|
+
const { events } = this._global;
|
|
80206
|
+
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
80207
|
+
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
80208
|
+
events.off('inputMode:changed', this._onInputModeChanged);
|
|
80209
|
+
}
|
|
80210
|
+
this._canvas?.removeEventListener('pointerdown', this._onPointerDown);
|
|
80211
|
+
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
80212
|
+
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
80213
|
+
this._canvas = null;
|
|
80214
|
+
this._global = null;
|
|
80215
|
+
this._keyboardMouse = null;
|
|
80216
|
+
}
|
|
80217
|
+
}
|
|
80218
|
+
|
|
80185
80219
|
const tmpV$3 = new Vec3();
|
|
80186
80220
|
const stickMove = new Vec3();
|
|
80187
80221
|
const stickRotate = new Vec3();
|
|
@@ -80204,7 +80238,7 @@ class GamepadDevice {
|
|
|
80204
80238
|
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
80205
80239
|
const { deltas } = frame;
|
|
80206
80240
|
if (isFly && (leftStick[0] !== 0 || leftStick[1] !== 0 || rightStick[0] !== 0 || rightStick[1] !== 0)) {
|
|
80207
|
-
this._global?.events.fire('
|
|
80241
|
+
this._global?.events.fire('navigateCancel');
|
|
80208
80242
|
}
|
|
80209
80243
|
const v = tmpV$3.set(0, 0, 0);
|
|
80210
80244
|
stickMove.set(leftStick[0], 0, -leftStick[1]);
|
|
@@ -80299,16 +80333,16 @@ class KeyboardMouseDevice {
|
|
|
80299
80333
|
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
80300
80334
|
// auto-move cancellation and requestFirstPerson events (driven by keyboard axes)
|
|
80301
80335
|
if (isWalk && (this._axis.x !== 0 || this._axis.z !== 0)) {
|
|
80302
|
-
events.fire('
|
|
80336
|
+
events.fire('navigateCancel');
|
|
80303
80337
|
}
|
|
80304
80338
|
if (isFly && (this._axis.x !== 0 || this._axis.y !== 0 || this._axis.z !== 0)) {
|
|
80305
|
-
events.fire('
|
|
80339
|
+
events.fire('navigateCancel');
|
|
80306
80340
|
}
|
|
80307
80341
|
if (isFly && wheel[0] !== 0) {
|
|
80308
|
-
events.fire('
|
|
80342
|
+
events.fire('navigateCancel');
|
|
80309
80343
|
}
|
|
80310
80344
|
if (isFly && (gamingControls || pan) && (mouse[0] !== 0 || mouse[1] !== 0)) {
|
|
80311
|
-
events.fire('
|
|
80345
|
+
events.fire('navigateCancel');
|
|
80312
80346
|
}
|
|
80313
80347
|
if (!isFirstPerson && this._axis.length() > 0) {
|
|
80314
80348
|
events.fire('inputEvent', 'requestFirstPerson');
|
|
@@ -80417,7 +80451,7 @@ class TouchDevice {
|
|
|
80417
80451
|
// running touch count
|
|
80418
80452
|
this._touchCount += count[0];
|
|
80419
80453
|
if (isFly && gamingControls && (this._joystick[0] !== 0 || this._joystick[1] !== 0)) {
|
|
80420
|
-
this._global.events.fire('
|
|
80454
|
+
this._global.events.fire('navigateCancel');
|
|
80421
80455
|
}
|
|
80422
80456
|
// tap detection for click/tap target and focus modes
|
|
80423
80457
|
if (isWalk || isFly || isOrbit) {
|
|
@@ -80433,18 +80467,15 @@ class TouchDevice {
|
|
|
80433
80467
|
const prevDelta = this._tapDelta;
|
|
80434
80468
|
this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]) + Math.abs(pinch[0]);
|
|
80435
80469
|
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');
|
|
80470
|
+
if ((isWalk && !gamingControls) || isFly) {
|
|
80471
|
+
this._global.events.fire('navigateCancel');
|
|
80441
80472
|
}
|
|
80442
80473
|
}
|
|
80443
80474
|
}
|
|
80444
80475
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
80445
80476
|
if (this._tapDelta < TAP_EPSILON && this._tapMaxTouches === 1) {
|
|
80446
80477
|
if (isWalk && !gamingControls) {
|
|
80447
|
-
// Walk-interaction listens for this and fires
|
|
80478
|
+
// Walk-interaction listens for this and fires navigateTo
|
|
80448
80479
|
// after picking.
|
|
80449
80480
|
this._global.events.fire('mobileTap');
|
|
80450
80481
|
}
|
|
@@ -80452,7 +80483,7 @@ class TouchDevice {
|
|
|
80452
80483
|
this._tapJump = true;
|
|
80453
80484
|
}
|
|
80454
80485
|
else if (isFly && !gamingControls) {
|
|
80455
|
-
// Walk-interaction listens for this and fires
|
|
80486
|
+
// Walk-interaction listens for this and fires navigateTo
|
|
80456
80487
|
// after picking.
|
|
80457
80488
|
this._global.events.fire('mobileTap');
|
|
80458
80489
|
}
|
|
@@ -80637,7 +80668,7 @@ class TrackpadDevice {
|
|
|
80637
80668
|
else {
|
|
80638
80669
|
// fly / walk: always rotate (shift is a speed modifier, not a gesture)
|
|
80639
80670
|
if (mode === 'fly') {
|
|
80640
|
-
this._global.events.fire('
|
|
80671
|
+
this._global.events.fire('navigateCancel');
|
|
80641
80672
|
}
|
|
80642
80673
|
this._orbit[0] += deltaX;
|
|
80643
80674
|
this._orbit[1] += deltaY;
|
|
@@ -80700,7 +80731,7 @@ class TrackpadDevice {
|
|
|
80700
80731
|
|
|
80701
80732
|
/**
|
|
80702
80733
|
* Coordinator that wires together input devices (keyboard-mouse, touch,
|
|
80703
|
-
* trackpad, gamepad) and app-level UX helpers (mode shortcuts,
|
|
80734
|
+
* trackpad, gamepad) and app-level UX helpers (mode shortcuts, nav
|
|
80704
80735
|
* interaction, pointer lock, input-mode tracker), and exposes the
|
|
80705
80736
|
* resulting per-frame `InputFrame` for the camera manager to consume.
|
|
80706
80737
|
*/
|
|
@@ -80714,19 +80745,19 @@ class InputController {
|
|
|
80714
80745
|
_keyboardMouse = new KeyboardMouseDevice();
|
|
80715
80746
|
_touch = new TouchDevice();
|
|
80716
80747
|
_gamepad = new GamepadDevice();
|
|
80717
|
-
|
|
80748
|
+
_navInteraction;
|
|
80718
80749
|
_pointerLock = new PointerLockManager();
|
|
80719
80750
|
_modeShortcuts = new ModeShortcuts();
|
|
80720
80751
|
_inputModeTracker = new InputModeTracker();
|
|
80721
80752
|
set collision(value) {
|
|
80722
|
-
this.
|
|
80753
|
+
this._navInteraction.collision = value;
|
|
80723
80754
|
}
|
|
80724
80755
|
get collision() {
|
|
80725
|
-
return this.
|
|
80756
|
+
return this._navInteraction.collision;
|
|
80726
80757
|
}
|
|
80727
80758
|
constructor(global, picker) {
|
|
80728
80759
|
this._global = global;
|
|
80729
|
-
this.
|
|
80760
|
+
this._navInteraction = new NavInteraction(picker);
|
|
80730
80761
|
const { app, events } = global;
|
|
80731
80762
|
const canvas = app.graphicsDevice.canvas;
|
|
80732
80763
|
// Trackpad MUST attach before KeyboardMouseDevice so its wheel
|
|
@@ -80736,7 +80767,7 @@ class InputController {
|
|
|
80736
80767
|
this._keyboardMouse.attach(canvas, global);
|
|
80737
80768
|
this._touch.attach(canvas, global);
|
|
80738
80769
|
this._gamepad.attach(canvas, global);
|
|
80739
|
-
this.
|
|
80770
|
+
this._navInteraction.attach(canvas, global);
|
|
80740
80771
|
this._pointerLock.attach(canvas, global, this._keyboardMouse);
|
|
80741
80772
|
this._modeShortcuts.attach(global, this._pointerLock);
|
|
80742
80773
|
this._inputModeTracker.attach(global);
|
|
@@ -81285,7 +81316,24 @@ const unregisterPickerShaderPatches = (app) => {
|
|
|
81285
81316
|
wgslChunks.set('gsplatPS', state.wgslGsplatPS);
|
|
81286
81317
|
pickerShaderPatchState.delete(device);
|
|
81287
81318
|
};
|
|
81288
|
-
const
|
|
81319
|
+
const createPickCameraSnapshot = () => ({
|
|
81320
|
+
position: new Vec3(),
|
|
81321
|
+
viewMatrix: new Mat4(),
|
|
81322
|
+
projectionMatrix: new Mat4(),
|
|
81323
|
+
nearClip: 0,
|
|
81324
|
+
farClip: 0,
|
|
81325
|
+
projection: 0
|
|
81326
|
+
});
|
|
81327
|
+
const captureCameraSnapshot = (camera, out) => {
|
|
81328
|
+
const cam = camera.camera;
|
|
81329
|
+
out.position.copy(camera.getPosition());
|
|
81330
|
+
out.viewMatrix.copy(cam.viewMatrix);
|
|
81331
|
+
out.projectionMatrix.copy(cam.projectionMatrix);
|
|
81332
|
+
out.nearClip = cam.nearClip;
|
|
81333
|
+
out.farClip = cam.farClip;
|
|
81334
|
+
out.projection = cam.projection;
|
|
81335
|
+
};
|
|
81336
|
+
const getWorldPoint = (camera, x, y, width, height, normalizedDepth, out) => {
|
|
81289
81337
|
if (!Number.isFinite(normalizedDepth) || normalizedDepth < 0 || normalizedDepth > 1) {
|
|
81290
81338
|
return null;
|
|
81291
81339
|
}
|
|
@@ -81303,7 +81351,7 @@ const getWorldPoint = (camera, x, y, width, height, normalizedDepth) => {
|
|
|
81303
81351
|
if (!Number.isFinite(vec4.x) || !Number.isFinite(vec4.y) || !Number.isFinite(vec4.z)) {
|
|
81304
81352
|
return null;
|
|
81305
81353
|
}
|
|
81306
|
-
return new Vec3(vec4.x, vec4.y, vec4.z);
|
|
81354
|
+
return (out ?? new Vec3()).set(vec4.x, vec4.y, vec4.z);
|
|
81307
81355
|
};
|
|
81308
81356
|
const setCameraFacingNormal = (cameraPosition, position, normal) => {
|
|
81309
81357
|
normal.sub2(cameraPosition, position);
|
|
@@ -81328,14 +81376,10 @@ class Picker {
|
|
|
81328
81376
|
let accumPass;
|
|
81329
81377
|
let chunksPatched = false;
|
|
81330
81378
|
let pickQueue = Promise.resolve();
|
|
81331
|
-
|
|
81332
|
-
|
|
81333
|
-
|
|
81334
|
-
|
|
81335
|
-
nearClip: 0,
|
|
81336
|
-
farClip: 0,
|
|
81337
|
-
projection: 0
|
|
81338
|
-
};
|
|
81379
|
+
let cacheValid = false;
|
|
81380
|
+
let cacheWidth = 0;
|
|
81381
|
+
let cacheHeight = 0;
|
|
81382
|
+
const cacheCamera = createPickCameraSnapshot();
|
|
81339
81383
|
const initRasterAccum = (width, height) => {
|
|
81340
81384
|
accumBuffer = new Texture(graphicsDevice, {
|
|
81341
81385
|
format: PIXELFORMAT_RGBA16F,
|
|
@@ -81363,24 +81407,31 @@ class Picker {
|
|
|
81363
81407
|
immediate: true
|
|
81364
81408
|
});
|
|
81365
81409
|
};
|
|
81366
|
-
const updateCache = () => {
|
|
81410
|
+
const updateCache = (width, height) => {
|
|
81411
|
+
captureCameraSnapshot(camera, cacheCamera);
|
|
81412
|
+
cacheWidth = width;
|
|
81413
|
+
cacheHeight = height;
|
|
81414
|
+
};
|
|
81415
|
+
const cameraMatches = (width, height) => {
|
|
81367
81416
|
const cam = camera.camera;
|
|
81368
|
-
|
|
81369
|
-
|
|
81370
|
-
|
|
81371
|
-
|
|
81372
|
-
|
|
81373
|
-
|
|
81417
|
+
return cacheValid &&
|
|
81418
|
+
cacheWidth === width &&
|
|
81419
|
+
cacheHeight === height &&
|
|
81420
|
+
cacheCamera.viewMatrix.equals(cam.viewMatrix) &&
|
|
81421
|
+
cacheCamera.projectionMatrix.equals(cam.projectionMatrix) &&
|
|
81422
|
+
cacheCamera.nearClip === cam.nearClip &&
|
|
81423
|
+
cacheCamera.farClip === cam.farClip &&
|
|
81424
|
+
cacheCamera.projection === cam.projection;
|
|
81374
81425
|
};
|
|
81375
81426
|
const getCacheCameraSnapshot = () => {
|
|
81376
|
-
|
|
81377
|
-
|
|
81378
|
-
|
|
81379
|
-
|
|
81380
|
-
|
|
81381
|
-
|
|
81382
|
-
|
|
81383
|
-
|
|
81427
|
+
const snapshot = createPickCameraSnapshot();
|
|
81428
|
+
snapshot.position.copy(cacheCamera.position);
|
|
81429
|
+
snapshot.viewMatrix.copy(cacheCamera.viewMatrix);
|
|
81430
|
+
snapshot.projectionMatrix.copy(cacheCamera.projectionMatrix);
|
|
81431
|
+
snapshot.nearClip = cacheCamera.nearClip;
|
|
81432
|
+
snapshot.farClip = cacheCamera.farClip;
|
|
81433
|
+
snapshot.projection = cacheCamera.projection;
|
|
81434
|
+
return snapshot;
|
|
81384
81435
|
};
|
|
81385
81436
|
const readRasterBlock = async (blockX, blockY, blockWidth, blockHeight, viewportWidth, viewportHeight, pickCamera) => {
|
|
81386
81437
|
const texY = graphicsDevice.isWebGL2 ? accumTarget.height - blockY - blockHeight : blockY;
|
|
@@ -81406,20 +81457,10 @@ class Picker {
|
|
|
81406
81457
|
return getWorldPoint(pickCamera, x, y, viewportWidth, viewportHeight, normalizedDepth);
|
|
81407
81458
|
};
|
|
81408
81459
|
};
|
|
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;
|
|
81460
|
+
const ensureRendered = (width, height, isComputeRenderer, worldLayer) => {
|
|
81461
|
+
if (cameraMatches(width, height)) {
|
|
81462
|
+
return;
|
|
81421
81463
|
}
|
|
81422
|
-
const isComputeRenderer = app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE;
|
|
81423
81464
|
// Enable gsplat IDs only while rendering the pick target so we
|
|
81424
81465
|
// don't pay the memory/perf cost between pick passes.
|
|
81425
81466
|
const prevEnableIds = app.scene.gsplat.enableIds;
|
|
@@ -81438,7 +81479,8 @@ class Picker {
|
|
|
81438
81479
|
if (!accumPass) {
|
|
81439
81480
|
initRasterAccum(width, height);
|
|
81440
81481
|
}
|
|
81441
|
-
else {
|
|
81482
|
+
else if (cacheWidth !== width || cacheHeight !== height) {
|
|
81483
|
+
cacheValid = false;
|
|
81442
81484
|
accumTarget.resize(width, height);
|
|
81443
81485
|
}
|
|
81444
81486
|
accumPass.init(accumTarget);
|
|
@@ -81446,12 +81488,37 @@ class Picker {
|
|
|
81446
81488
|
accumPass.update(camera.camera, app.scene, [worldLayer], new Map(), false);
|
|
81447
81489
|
accumPass.render();
|
|
81448
81490
|
}
|
|
81449
|
-
updateCache();
|
|
81491
|
+
updateCache(width, height);
|
|
81492
|
+
cacheValid = true;
|
|
81450
81493
|
}
|
|
81451
81494
|
finally {
|
|
81452
81495
|
app.scene.gsplat.enableIds = prevEnableIds;
|
|
81453
81496
|
}
|
|
81497
|
+
};
|
|
81498
|
+
const prepareSample = (x, y) => {
|
|
81499
|
+
const width = Math.floor(graphicsDevice.width);
|
|
81500
|
+
const height = Math.floor(graphicsDevice.height);
|
|
81501
|
+
// bail out if the device hasn't been sized yet
|
|
81502
|
+
if (width <= 0 || height <= 0) {
|
|
81503
|
+
return null;
|
|
81504
|
+
}
|
|
81505
|
+
const worldLayer = app.scene.layers.getLayerByName('World');
|
|
81506
|
+
if (!worldLayer) {
|
|
81507
|
+
return null;
|
|
81508
|
+
}
|
|
81509
|
+
const screenX = Math.min(width - 1, Math.max(0, Math.floor(x * width)));
|
|
81510
|
+
const screenY = Math.min(height - 1, Math.max(0, Math.floor(y * height)));
|
|
81511
|
+
const isComputeRenderer = app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE;
|
|
81512
|
+
ensureRendered(width, height, isComputeRenderer, worldLayer);
|
|
81454
81513
|
const pickCamera = getCacheCameraSnapshot();
|
|
81514
|
+
return { width, height, screenX, screenY, isComputeRenderer, pickCamera };
|
|
81515
|
+
};
|
|
81516
|
+
const pickPosition = async (x, y) => {
|
|
81517
|
+
const sample = prepareSample(x, y);
|
|
81518
|
+
if (!sample) {
|
|
81519
|
+
return null;
|
|
81520
|
+
}
|
|
81521
|
+
const { width, height, screenX, screenY, isComputeRenderer, pickCamera } = sample;
|
|
81455
81522
|
if (isComputeRenderer) {
|
|
81456
81523
|
const normalizedDepth = await enginePicker.getPointDepthAsync(screenX, screenY);
|
|
81457
81524
|
const position = normalizedDepth !== null ?
|
|
@@ -81481,37 +81548,47 @@ class Picker {
|
|
|
81481
81548
|
return result?.position ?? null;
|
|
81482
81549
|
};
|
|
81483
81550
|
const pickSurface = async (x, y) => {
|
|
81484
|
-
const
|
|
81485
|
-
if (!
|
|
81551
|
+
const sample = prepareSample(x, y);
|
|
81552
|
+
if (!sample) {
|
|
81486
81553
|
return null;
|
|
81487
81554
|
}
|
|
81488
|
-
const {
|
|
81489
|
-
if (
|
|
81555
|
+
const { width, height, screenX, screenY, isComputeRenderer, pickCamera } = sample;
|
|
81556
|
+
if (isComputeRenderer) {
|
|
81557
|
+
const normalizedDepth = await enginePicker.getPointDepthAsync(screenX, screenY);
|
|
81558
|
+
const position = normalizedDepth !== null ?
|
|
81559
|
+
getWorldPoint(pickCamera, screenX, screenY, width, height, normalizedDepth) :
|
|
81560
|
+
null;
|
|
81561
|
+
if (!position) {
|
|
81562
|
+
return null;
|
|
81563
|
+
}
|
|
81490
81564
|
return {
|
|
81491
81565
|
position,
|
|
81492
|
-
normal:
|
|
81566
|
+
normal: new Vec3(0, 1, 0)
|
|
81493
81567
|
};
|
|
81494
81568
|
}
|
|
81569
|
+
// Single block read serves both depth (center pixel) and normal samples (ring).
|
|
81495
81570
|
const maxRadius = NORMAL_SAMPLE_RADII[NORMAL_SAMPLE_RADII.length - 1];
|
|
81496
81571
|
const blockX = Math.max(0, screenX - maxRadius);
|
|
81497
81572
|
const blockY = Math.max(0, screenY - maxRadius);
|
|
81498
81573
|
const blockWidth = Math.min(width - 1, screenX + maxRadius) - blockX + 1;
|
|
81499
81574
|
const blockHeight = Math.min(height - 1, screenY + maxRadius) - blockY + 1;
|
|
81500
|
-
const rasterBlock = await readRasterBlock(blockX, blockY, blockWidth, blockHeight, width, height,
|
|
81575
|
+
const rasterBlock = await readRasterBlock(blockX, blockY, blockWidth, blockHeight, width, height, pickCamera);
|
|
81576
|
+
const position = rasterBlock(screenX, screenY);
|
|
81577
|
+
if (!position) {
|
|
81578
|
+
return null;
|
|
81579
|
+
}
|
|
81501
81580
|
const samplePixel = (px, py) => {
|
|
81502
81581
|
if (px < 0 || px >= width || py < 0 || py >= height) {
|
|
81503
|
-
return
|
|
81582
|
+
return null;
|
|
81504
81583
|
}
|
|
81505
|
-
return
|
|
81584
|
+
return rasterBlock(px, py);
|
|
81506
81585
|
};
|
|
81507
|
-
const sampleRings =
|
|
81508
|
-
return
|
|
81509
|
-
|
|
81510
|
-
|
|
81511
|
-
|
|
81512
|
-
|
|
81513
|
-
}));
|
|
81514
|
-
const toCamera = setCameraFacingNormal(picked.camera.position, position, new Vec3());
|
|
81586
|
+
const sampleRings = NORMAL_SAMPLE_RADII.map((radius) => {
|
|
81587
|
+
return NORMAL_SAMPLE_DIRECTIONS.map(([dx, dy]) => {
|
|
81588
|
+
return samplePixel(screenX + dx * radius, screenY + dy * radius);
|
|
81589
|
+
});
|
|
81590
|
+
});
|
|
81591
|
+
const toCamera = setCameraFacingNormal(pickCamera.position, position, new Vec3());
|
|
81515
81592
|
const candidates = [];
|
|
81516
81593
|
const va = new Vec3();
|
|
81517
81594
|
const vb = new Vec3();
|
|
@@ -81576,7 +81653,480 @@ class Picker {
|
|
|
81576
81653
|
accumPass?.destroy();
|
|
81577
81654
|
accumTarget?.destroy();
|
|
81578
81655
|
accumBuffer?.destroy();
|
|
81656
|
+
cacheValid = false;
|
|
81657
|
+
};
|
|
81658
|
+
}
|
|
81659
|
+
}
|
|
81660
|
+
|
|
81661
|
+
const SVGNS = 'http://www.w3.org/2000/svg';
|
|
81662
|
+
const NUM_SAMPLES = 12;
|
|
81663
|
+
const CIRCLE_OUTER_RADIUS = 0.2;
|
|
81664
|
+
const CIRCLE_INNER_RADIUS = 0.17;
|
|
81665
|
+
const BEZIER_K = 1 / 6;
|
|
81666
|
+
const NORMAL_SMOOTH_FACTOR = 0.25;
|
|
81667
|
+
const NORMAL_SNAP_ANGLE = Math.PI / 4;
|
|
81668
|
+
const NORMAL_EPSILON = 1e-6;
|
|
81669
|
+
const createNormalSnapDirections = () => {
|
|
81670
|
+
const result = [];
|
|
81671
|
+
for (let pitchStep = -2; pitchStep <= 2; pitchStep++) {
|
|
81672
|
+
const pitch = pitchStep * NORMAL_SNAP_ANGLE;
|
|
81673
|
+
const cp = Math.cos(pitch);
|
|
81674
|
+
const sy = Math.sin(pitch);
|
|
81675
|
+
if (Math.abs(cp) <= NORMAL_EPSILON) {
|
|
81676
|
+
result.push(new Vec3(0, sy > 0 ? 1 : -1, 0));
|
|
81677
|
+
continue;
|
|
81678
|
+
}
|
|
81679
|
+
for (let yawStep = 0; yawStep < 8; yawStep++) {
|
|
81680
|
+
const yaw = yawStep * NORMAL_SNAP_ANGLE;
|
|
81681
|
+
result.push(new Vec3(Math.cos(yaw) * cp, sy, Math.sin(yaw) * cp));
|
|
81682
|
+
}
|
|
81683
|
+
}
|
|
81684
|
+
return result;
|
|
81685
|
+
};
|
|
81686
|
+
const NORMAL_SNAP_DIRECTIONS = createNormalSnapDirections();
|
|
81687
|
+
const snapNormal = (nx, ny, nz, out) => {
|
|
81688
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
81689
|
+
if (len <= NORMAL_EPSILON) {
|
|
81690
|
+
return out.set(0, 1, 0);
|
|
81691
|
+
}
|
|
81692
|
+
const invLen = 1 / len;
|
|
81693
|
+
const x = nx * invLen;
|
|
81694
|
+
const y = ny * invLen;
|
|
81695
|
+
const z = nz * invLen;
|
|
81696
|
+
let best = NORMAL_SNAP_DIRECTIONS[0];
|
|
81697
|
+
let bestDot = -Infinity;
|
|
81698
|
+
for (let i = 0; i < NORMAL_SNAP_DIRECTIONS.length; i++) {
|
|
81699
|
+
const candidate = NORMAL_SNAP_DIRECTIONS[i];
|
|
81700
|
+
const dot = candidate.x * x + candidate.y * y + candidate.z * z;
|
|
81701
|
+
if (dot > bestDot) {
|
|
81702
|
+
bestDot = dot;
|
|
81703
|
+
best = candidate;
|
|
81704
|
+
}
|
|
81705
|
+
}
|
|
81706
|
+
return out.copy(best);
|
|
81707
|
+
};
|
|
81708
|
+
const tmpV = new Vec3();
|
|
81709
|
+
const tmpScreen = new Vec3();
|
|
81710
|
+
const tangent = new Vec3();
|
|
81711
|
+
const bitangent = new Vec3();
|
|
81712
|
+
const worldPt = new Vec3();
|
|
81713
|
+
const up = new Vec3(0, 1, 0);
|
|
81714
|
+
const right = new Vec3(1, 0, 0);
|
|
81715
|
+
const tmpViewPos = new Vec3();
|
|
81716
|
+
const tmpClipVec = new Vec4();
|
|
81717
|
+
const tmpViewProj = new Mat4();
|
|
81718
|
+
const worldPointToDepth = (camera, worldPos) => {
|
|
81719
|
+
if (camera.projection === PROJECTION_ORTHOGRAPHIC) {
|
|
81720
|
+
tmpViewProj.mul2(camera.projectionMatrix, camera.viewMatrix);
|
|
81721
|
+
tmpClipVec.set(worldPos.x, worldPos.y, worldPos.z, 1);
|
|
81722
|
+
tmpViewProj.transformVec4(tmpClipVec, tmpClipVec);
|
|
81723
|
+
if (Math.abs(tmpClipVec.w) < 1e-8) {
|
|
81724
|
+
return -1;
|
|
81725
|
+
}
|
|
81726
|
+
return (tmpClipVec.z / tmpClipVec.w + 1) * 0.5;
|
|
81727
|
+
}
|
|
81728
|
+
camera.viewMatrix.transformPoint(worldPos, tmpViewPos);
|
|
81729
|
+
const linearDepth = -tmpViewPos.z;
|
|
81730
|
+
const range = camera.farClip - camera.nearClip;
|
|
81731
|
+
if (range <= 0) {
|
|
81732
|
+
return -1;
|
|
81733
|
+
}
|
|
81734
|
+
return (linearDepth - camera.nearClip) / range;
|
|
81735
|
+
};
|
|
81736
|
+
const createSurfaceSample = () => ({
|
|
81737
|
+
normalizedDepth: 0,
|
|
81738
|
+
normal: new Vec3(),
|
|
81739
|
+
camera: {
|
|
81740
|
+
position: new Vec3(),
|
|
81741
|
+
viewMatrix: new Mat4(),
|
|
81742
|
+
projectionMatrix: new Mat4(),
|
|
81743
|
+
nearClip: 0,
|
|
81744
|
+
farClip: 0,
|
|
81745
|
+
projection: 0
|
|
81746
|
+
},
|
|
81747
|
+
width: 0,
|
|
81748
|
+
height: 0
|
|
81749
|
+
});
|
|
81750
|
+
const buildBezierRing = (sx, sy) => {
|
|
81751
|
+
const n = sx.length;
|
|
81752
|
+
let p = `M${sx[0].toFixed(1)},${sy[0].toFixed(1)}`;
|
|
81753
|
+
for (let i = 0; i < n; i++) {
|
|
81754
|
+
const i0 = (i - 1 + n) % n;
|
|
81755
|
+
const i1 = i;
|
|
81756
|
+
const i2 = (i + 1) % n;
|
|
81757
|
+
const i3 = (i + 2) % n;
|
|
81758
|
+
const cp1x = sx[i1] + (sx[i2] - sx[i0]) * BEZIER_K;
|
|
81759
|
+
const cp1y = sy[i1] + (sy[i2] - sy[i0]) * BEZIER_K;
|
|
81760
|
+
const cp2x = sx[i2] - (sx[i3] - sx[i1]) * BEZIER_K;
|
|
81761
|
+
const cp2y = sy[i2] - (sy[i3] - sy[i1]) * BEZIER_K;
|
|
81762
|
+
p += ` C${cp1x.toFixed(1)},${cp1y.toFixed(1)} ${cp2x.toFixed(1)},${cp2y.toFixed(1)} ${sx[i2].toFixed(1)},${sy[i2].toFixed(1)}`;
|
|
81763
|
+
}
|
|
81764
|
+
return `${p} Z`;
|
|
81765
|
+
};
|
|
81766
|
+
class CursorRing {
|
|
81767
|
+
path;
|
|
81768
|
+
svg;
|
|
81769
|
+
camera;
|
|
81770
|
+
smoothing;
|
|
81771
|
+
smoothNx = 0;
|
|
81772
|
+
smoothNy = 1;
|
|
81773
|
+
smoothNz = 0;
|
|
81774
|
+
hasSmoothedNormal = false;
|
|
81775
|
+
outerX = new Float64Array(NUM_SAMPLES);
|
|
81776
|
+
outerY = new Float64Array(NUM_SAMPLES);
|
|
81777
|
+
innerX = new Float64Array(NUM_SAMPLES);
|
|
81778
|
+
innerY = new Float64Array(NUM_SAMPLES);
|
|
81779
|
+
constructor(svg, camera, smoothing) {
|
|
81780
|
+
this.svg = svg;
|
|
81781
|
+
this.camera = camera;
|
|
81782
|
+
this.smoothing = smoothing;
|
|
81783
|
+
this.path = document.createElementNS(SVGNS, 'path');
|
|
81784
|
+
this.path.setAttribute('fill', 'white');
|
|
81785
|
+
this.path.setAttribute('fill-opacity', '0.6');
|
|
81786
|
+
this.path.setAttribute('fill-rule', 'evenodd');
|
|
81787
|
+
this.path.setAttribute('stroke', 'none');
|
|
81788
|
+
this.path.style.display = 'none';
|
|
81789
|
+
svg.appendChild(this.path);
|
|
81790
|
+
}
|
|
81791
|
+
projectCircle(px, py, pz, nx, ny, nz, radius, outX, outY) {
|
|
81792
|
+
const normal = tmpV.set(nx, ny, nz);
|
|
81793
|
+
if (Math.abs(normal.y) < 0.99) {
|
|
81794
|
+
tangent.cross(normal, up).normalize();
|
|
81795
|
+
}
|
|
81796
|
+
else {
|
|
81797
|
+
tangent.cross(normal, right).normalize();
|
|
81798
|
+
}
|
|
81799
|
+
bitangent.cross(normal, tangent);
|
|
81800
|
+
const cam = this.camera.camera;
|
|
81801
|
+
const angleStep = (2 * Math.PI) / NUM_SAMPLES;
|
|
81802
|
+
for (let i = 0; i < NUM_SAMPLES; i++) {
|
|
81803
|
+
const theta = i * angleStep;
|
|
81804
|
+
const ct = Math.cos(theta);
|
|
81805
|
+
const st = Math.sin(theta);
|
|
81806
|
+
const tx = ct * tangent.x + st * bitangent.x;
|
|
81807
|
+
const ty = ct * tangent.y + st * bitangent.y;
|
|
81808
|
+
const tz = ct * tangent.z + st * bitangent.z;
|
|
81809
|
+
worldPt.set(px + tx * radius, py + ty * radius, pz + tz * radius);
|
|
81810
|
+
cam.worldToScreen(worldPt, tmpScreen);
|
|
81811
|
+
outX[i] = tmpScreen.x;
|
|
81812
|
+
outY[i] = tmpScreen.y;
|
|
81813
|
+
}
|
|
81814
|
+
}
|
|
81815
|
+
render(pos, normal) {
|
|
81816
|
+
snapNormal(normal.x, normal.y, normal.z, tmpV);
|
|
81817
|
+
let nx = tmpV.x;
|
|
81818
|
+
let ny = tmpV.y;
|
|
81819
|
+
let nz = tmpV.z;
|
|
81820
|
+
if (this.smoothing) {
|
|
81821
|
+
if (this.hasSmoothedNormal) {
|
|
81822
|
+
const t = NORMAL_SMOOTH_FACTOR;
|
|
81823
|
+
nx = this.smoothNx + (nx - this.smoothNx) * t;
|
|
81824
|
+
ny = this.smoothNy + (ny - this.smoothNy) * t;
|
|
81825
|
+
nz = this.smoothNz + (nz - this.smoothNz) * t;
|
|
81826
|
+
const len = Math.sqrt(nx * nx + ny * ny + nz * nz);
|
|
81827
|
+
if (len > 1e-6) {
|
|
81828
|
+
const invLen = 1.0 / len;
|
|
81829
|
+
nx *= invLen;
|
|
81830
|
+
ny *= invLen;
|
|
81831
|
+
nz *= invLen;
|
|
81832
|
+
}
|
|
81833
|
+
}
|
|
81834
|
+
this.smoothNx = nx;
|
|
81835
|
+
this.smoothNy = ny;
|
|
81836
|
+
this.smoothNz = nz;
|
|
81837
|
+
this.hasSmoothedNormal = true;
|
|
81838
|
+
}
|
|
81839
|
+
this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, CIRCLE_OUTER_RADIUS, this.outerX, this.outerY);
|
|
81840
|
+
this.projectCircle(pos.x, pos.y, pos.z, nx, ny, nz, CIRCLE_INNER_RADIUS, this.innerX, this.innerY);
|
|
81841
|
+
this.path.setAttribute('d', `${buildBezierRing(this.outerX, this.outerY)} ${buildBezierRing(this.innerX, this.innerY)}`);
|
|
81842
|
+
this.path.style.display = '';
|
|
81843
|
+
this.svg.style.display = '';
|
|
81844
|
+
}
|
|
81845
|
+
hide() {
|
|
81846
|
+
this.path.style.display = 'none';
|
|
81847
|
+
this.hasSmoothedNormal = false;
|
|
81848
|
+
}
|
|
81849
|
+
}
|
|
81850
|
+
class NavCursor {
|
|
81851
|
+
svg;
|
|
81852
|
+
hoverRing;
|
|
81853
|
+
targetRing;
|
|
81854
|
+
camera;
|
|
81855
|
+
collision;
|
|
81856
|
+
canvas;
|
|
81857
|
+
state;
|
|
81858
|
+
picker;
|
|
81859
|
+
app;
|
|
81860
|
+
onPrerender;
|
|
81861
|
+
active = false;
|
|
81862
|
+
navigating = false;
|
|
81863
|
+
targetPos = null;
|
|
81864
|
+
targetNormal = null;
|
|
81865
|
+
targetMode = null;
|
|
81866
|
+
surfaceCursorX = 0;
|
|
81867
|
+
surfaceCursorY = 0;
|
|
81868
|
+
hasSurfaceCursorPosition = false;
|
|
81869
|
+
surfaceCursorVersion = 0;
|
|
81870
|
+
surfaceCursorPickPending = false;
|
|
81871
|
+
surfaceSample = createSurfaceSample();
|
|
81872
|
+
hasSurfaceSample = false;
|
|
81873
|
+
scratchHoverPos = new Vec3();
|
|
81874
|
+
onPointerMove;
|
|
81875
|
+
onPointerLeave;
|
|
81876
|
+
collisionTarget = {
|
|
81877
|
+
position: new Vec3(),
|
|
81878
|
+
normal: new Vec3()
|
|
81879
|
+
};
|
|
81880
|
+
constructor(app, camera, collision, events, state, picker) {
|
|
81881
|
+
this.camera = camera;
|
|
81882
|
+
this.collision = collision;
|
|
81883
|
+
this.canvas = app.graphicsDevice.canvas;
|
|
81884
|
+
this.state = state;
|
|
81885
|
+
this.picker = picker;
|
|
81886
|
+
this.app = app;
|
|
81887
|
+
this.svg = document.createElementNS(SVGNS, 'svg');
|
|
81888
|
+
this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
|
|
81889
|
+
this.canvas.parentElement.appendChild(this.svg);
|
|
81890
|
+
this.hoverRing = new CursorRing(this.svg, camera, true);
|
|
81891
|
+
this.targetRing = new CursorRing(this.svg, camera, false);
|
|
81892
|
+
this.svg.style.display = 'none';
|
|
81893
|
+
this.onPointerMove = (e) => {
|
|
81894
|
+
if (e.pointerType === 'touch') {
|
|
81895
|
+
this.hasSurfaceCursorPosition = false;
|
|
81896
|
+
this.surfaceCursorVersion++;
|
|
81897
|
+
this.hoverRing.hide();
|
|
81898
|
+
return;
|
|
81899
|
+
}
|
|
81900
|
+
if (e.buttons) {
|
|
81901
|
+
this.hasSurfaceCursorPosition = false;
|
|
81902
|
+
this.surfaceCursorVersion++;
|
|
81903
|
+
this.hoverRing.hide();
|
|
81904
|
+
return;
|
|
81905
|
+
}
|
|
81906
|
+
this.updateCursor(e.offsetX, e.offsetY);
|
|
81579
81907
|
};
|
|
81908
|
+
this.onPointerLeave = () => {
|
|
81909
|
+
this.hasSurfaceCursorPosition = false;
|
|
81910
|
+
this.surfaceCursorVersion++;
|
|
81911
|
+
this.hoverRing.hide();
|
|
81912
|
+
};
|
|
81913
|
+
this.canvas.addEventListener('pointermove', this.onPointerMove);
|
|
81914
|
+
this.canvas.addEventListener('pointerleave', this.onPointerLeave);
|
|
81915
|
+
const updateActive = () => {
|
|
81916
|
+
const flyMouseCaptured = (state.cameraMode === 'fly' &&
|
|
81917
|
+
state.inputMode === 'desktop' &&
|
|
81918
|
+
state.gamingControls);
|
|
81919
|
+
this.active = (state.cameraMode === 'walk' && !state.gamingControls) ||
|
|
81920
|
+
(state.cameraMode === 'fly' && !flyMouseCaptured) ||
|
|
81921
|
+
state.cameraMode === 'orbit';
|
|
81922
|
+
this.surfaceCursorVersion++;
|
|
81923
|
+
this.hoverRing.hide();
|
|
81924
|
+
if (state.inputMode !== 'desktop') {
|
|
81925
|
+
this.hasSurfaceCursorPosition = false;
|
|
81926
|
+
}
|
|
81927
|
+
if (this.targetMode && this.targetMode !== state.cameraMode) {
|
|
81928
|
+
this.navigating = false;
|
|
81929
|
+
this.clearTarget();
|
|
81930
|
+
}
|
|
81931
|
+
if (!this.active) {
|
|
81932
|
+
this.svg.style.display = 'none';
|
|
81933
|
+
}
|
|
81934
|
+
};
|
|
81935
|
+
events.on('cameraMode:changed', updateActive);
|
|
81936
|
+
events.on('inputMode:changed', updateActive);
|
|
81937
|
+
events.on('gamingControls:changed', updateActive);
|
|
81938
|
+
events.on('navigateTo', () => {
|
|
81939
|
+
this.navigating = true;
|
|
81940
|
+
this.hoverRing.hide();
|
|
81941
|
+
});
|
|
81942
|
+
events.on('navigateCancel', () => {
|
|
81943
|
+
this.navigating = false;
|
|
81944
|
+
this.clearTarget();
|
|
81945
|
+
});
|
|
81946
|
+
events.on('navigateComplete', () => {
|
|
81947
|
+
this.navigating = false;
|
|
81948
|
+
this.clearTarget();
|
|
81949
|
+
});
|
|
81950
|
+
events.on('navTarget:set', (pos, normal) => {
|
|
81951
|
+
const mode = state.cameraMode === 'walk' || state.cameraMode === 'fly' ?
|
|
81952
|
+
state.cameraMode : 'walk';
|
|
81953
|
+
this.setTarget(pos, normal, mode);
|
|
81954
|
+
});
|
|
81955
|
+
events.on('navTarget:clear', () => {
|
|
81956
|
+
this.clearTarget();
|
|
81957
|
+
});
|
|
81958
|
+
events.on('orbitTarget:set', (pos, normal) => {
|
|
81959
|
+
this.navigating = false;
|
|
81960
|
+
this.setTarget(pos, normal, 'orbit');
|
|
81961
|
+
});
|
|
81962
|
+
events.on('orbitTarget:clear', () => {
|
|
81963
|
+
if (this.targetMode === 'orbit') {
|
|
81964
|
+
this.clearTarget();
|
|
81965
|
+
}
|
|
81966
|
+
});
|
|
81967
|
+
this.onPrerender = () => {
|
|
81968
|
+
this.updateTarget();
|
|
81969
|
+
};
|
|
81970
|
+
app.on('prerender', this.onPrerender);
|
|
81971
|
+
updateActive();
|
|
81972
|
+
}
|
|
81973
|
+
setTarget(pos, normal, mode) {
|
|
81974
|
+
this.surfaceCursorVersion++;
|
|
81975
|
+
this.targetPos = pos.clone();
|
|
81976
|
+
this.targetNormal = normal.clone();
|
|
81977
|
+
this.targetMode = mode;
|
|
81978
|
+
this.hoverRing.hide();
|
|
81979
|
+
this.targetRing.hide();
|
|
81980
|
+
}
|
|
81981
|
+
clearTarget() {
|
|
81982
|
+
const mode = this.targetMode;
|
|
81983
|
+
this.targetPos = null;
|
|
81984
|
+
this.targetNormal = null;
|
|
81985
|
+
this.targetMode = null;
|
|
81986
|
+
if (mode === 'orbit') {
|
|
81987
|
+
this.hoverRing.hide();
|
|
81988
|
+
}
|
|
81989
|
+
this.targetRing.hide();
|
|
81990
|
+
this.refreshSurfaceCursor();
|
|
81991
|
+
}
|
|
81992
|
+
pickCollision(offsetX, offsetY) {
|
|
81993
|
+
if (!this.collision) {
|
|
81994
|
+
return null;
|
|
81995
|
+
}
|
|
81996
|
+
const { camera, collision } = this;
|
|
81997
|
+
const cameraPos = camera.getPosition();
|
|
81998
|
+
camera.camera.screenToWorld(offsetX, offsetY, 1.0, tmpV);
|
|
81999
|
+
tmpV.sub(cameraPos).normalize();
|
|
82000
|
+
const hit = collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV.x, tmpV.y, tmpV.z, camera.camera.farClip);
|
|
82001
|
+
if (!hit) {
|
|
82002
|
+
return null;
|
|
82003
|
+
}
|
|
82004
|
+
const sn = collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV.x, tmpV.y, tmpV.z);
|
|
82005
|
+
this.collisionTarget.position.set(hit.x, hit.y, hit.z);
|
|
82006
|
+
this.collisionTarget.normal.set(sn.nx, sn.ny, sn.nz);
|
|
82007
|
+
return this.collisionTarget;
|
|
82008
|
+
}
|
|
82009
|
+
async pickSceneTarget(offsetX, offsetY) {
|
|
82010
|
+
const collisionTarget = this.pickCollision(offsetX, offsetY);
|
|
82011
|
+
if (collisionTarget) {
|
|
82012
|
+
return collisionTarget;
|
|
82013
|
+
}
|
|
82014
|
+
const result = await this.picker.pickSurface(offsetX / this.canvas.clientWidth, offsetY / this.canvas.clientHeight);
|
|
82015
|
+
return result ?? null;
|
|
82016
|
+
}
|
|
82017
|
+
shouldShowSurfaceCursor() {
|
|
82018
|
+
const flyMouseCaptured = this.state.cameraMode === 'fly' &&
|
|
82019
|
+
this.state.inputMode === 'desktop' &&
|
|
82020
|
+
this.state.gamingControls;
|
|
82021
|
+
return this.active &&
|
|
82022
|
+
this.state.inputMode === 'desktop' &&
|
|
82023
|
+
this.hasSurfaceCursorPosition &&
|
|
82024
|
+
!this.navigating && ((this.state.cameraMode === 'fly' && !flyMouseCaptured) ||
|
|
82025
|
+
(this.state.cameraMode === 'orbit' && this.targetMode !== 'orbit'));
|
|
82026
|
+
}
|
|
82027
|
+
updateSurfaceCursor(offsetX, offsetY) {
|
|
82028
|
+
this.surfaceCursorX = offsetX;
|
|
82029
|
+
this.surfaceCursorY = offsetY;
|
|
82030
|
+
this.hasSurfaceCursorPosition = true;
|
|
82031
|
+
this.surfaceCursorVersion++;
|
|
82032
|
+
// Render immediately using the most recent depth sample, re-projecting
|
|
82033
|
+
// at the new pointer position. The async pick below will refresh the
|
|
82034
|
+
// sample.
|
|
82035
|
+
this.renderSurfaceCursor();
|
|
82036
|
+
if (!this.surfaceCursorPickPending) {
|
|
82037
|
+
this.processSurfaceCursor();
|
|
82038
|
+
}
|
|
82039
|
+
}
|
|
82040
|
+
renderSurfaceCursor() {
|
|
82041
|
+
if (!this.hasSurfaceSample || !this.shouldShowSurfaceCursor()) {
|
|
82042
|
+
this.hoverRing.hide();
|
|
82043
|
+
return;
|
|
82044
|
+
}
|
|
82045
|
+
const sample = this.surfaceSample;
|
|
82046
|
+
const position = getWorldPoint(sample.camera, this.surfaceCursorX, this.surfaceCursorY, sample.width, sample.height, sample.normalizedDepth, this.scratchHoverPos);
|
|
82047
|
+
if (!position) {
|
|
82048
|
+
this.hoverRing.hide();
|
|
82049
|
+
return;
|
|
82050
|
+
}
|
|
82051
|
+
this.hoverRing.render(position, sample.normal);
|
|
82052
|
+
}
|
|
82053
|
+
refreshSurfaceCursor() {
|
|
82054
|
+
if (this.hasSurfaceCursorPosition && this.shouldShowSurfaceCursor() && !this.surfaceCursorPickPending) {
|
|
82055
|
+
this.surfaceCursorVersion++;
|
|
82056
|
+
this.processSurfaceCursor();
|
|
82057
|
+
}
|
|
82058
|
+
}
|
|
82059
|
+
processSurfaceCursor() {
|
|
82060
|
+
this.surfaceCursorPickPending = true;
|
|
82061
|
+
const version = this.surfaceCursorVersion;
|
|
82062
|
+
// Capture the camera at pick fire time so the depth we extract from
|
|
82063
|
+
// the result is interpretable through the same view/projection. The
|
|
82064
|
+
// surface cursor only animates while the camera is static, so this
|
|
82065
|
+
// snapshot matches the camera the picker actually rendered with.
|
|
82066
|
+
captureCameraSnapshot(this.camera, this.surfaceSample.camera);
|
|
82067
|
+
const snapshotWidth = this.canvas.clientWidth;
|
|
82068
|
+
const snapshotHeight = this.canvas.clientHeight;
|
|
82069
|
+
this.pickSceneTarget(this.surfaceCursorX, this.surfaceCursorY).then((target) => {
|
|
82070
|
+
if (target) {
|
|
82071
|
+
this.surfaceSample.normalizedDepth = worldPointToDepth(this.surfaceSample.camera, target.position);
|
|
82072
|
+
this.surfaceSample.normal.copy(target.normal);
|
|
82073
|
+
this.surfaceSample.width = snapshotWidth;
|
|
82074
|
+
this.surfaceSample.height = snapshotHeight;
|
|
82075
|
+
this.hasSurfaceSample = this.surfaceSample.normalizedDepth >= 0;
|
|
82076
|
+
}
|
|
82077
|
+
else {
|
|
82078
|
+
this.hasSurfaceSample = false;
|
|
82079
|
+
}
|
|
82080
|
+
this.renderSurfaceCursor();
|
|
82081
|
+
}).catch(() => {
|
|
82082
|
+
if (version === this.surfaceCursorVersion) {
|
|
82083
|
+
this.hasSurfaceSample = false;
|
|
82084
|
+
this.hoverRing.hide();
|
|
82085
|
+
}
|
|
82086
|
+
}).finally(() => {
|
|
82087
|
+
this.surfaceCursorPickPending = false;
|
|
82088
|
+
if (version !== this.surfaceCursorVersion && this.shouldShowSurfaceCursor()) {
|
|
82089
|
+
this.processSurfaceCursor();
|
|
82090
|
+
}
|
|
82091
|
+
});
|
|
82092
|
+
}
|
|
82093
|
+
updateCursor(offsetX, offsetY) {
|
|
82094
|
+
if (!this.active || this.navigating) {
|
|
82095
|
+
this.hoverRing.hide();
|
|
82096
|
+
return;
|
|
82097
|
+
}
|
|
82098
|
+
if (this.state.cameraMode === 'orbit' && this.targetMode === 'orbit') {
|
|
82099
|
+
this.hoverRing.hide();
|
|
82100
|
+
return;
|
|
82101
|
+
}
|
|
82102
|
+
if (this.state.cameraMode === 'fly' || this.state.cameraMode === 'orbit') {
|
|
82103
|
+
this.updateSurfaceCursor(offsetX, offsetY);
|
|
82104
|
+
return;
|
|
82105
|
+
}
|
|
82106
|
+
const target = this.pickCollision(offsetX, offsetY);
|
|
82107
|
+
if (!target) {
|
|
82108
|
+
this.hoverRing.hide();
|
|
82109
|
+
return;
|
|
82110
|
+
}
|
|
82111
|
+
this.hoverRing.render(target.position, target.normal);
|
|
82112
|
+
}
|
|
82113
|
+
updateTarget() {
|
|
82114
|
+
if (!this.active || !this.targetPos || !this.targetNormal) {
|
|
82115
|
+
return;
|
|
82116
|
+
}
|
|
82117
|
+
const camPos = this.camera.getPosition();
|
|
82118
|
+
const dist = camPos.distance(this.targetPos);
|
|
82119
|
+
if (this.targetMode !== 'orbit' && dist < 2.0) {
|
|
82120
|
+
this.targetRing.hide();
|
|
82121
|
+
return;
|
|
82122
|
+
}
|
|
82123
|
+
this.targetRing.render(this.targetPos, this.targetNormal);
|
|
82124
|
+
}
|
|
82125
|
+
destroy() {
|
|
82126
|
+
this.app.off('prerender', this.onPrerender);
|
|
82127
|
+
this.canvas.removeEventListener('pointermove', this.onPointerMove);
|
|
82128
|
+
this.canvas.removeEventListener('pointerleave', this.onPointerLeave);
|
|
82129
|
+
this.svg.remove();
|
|
81580
82130
|
}
|
|
81581
82131
|
}
|
|
81582
82132
|
|
|
@@ -82210,425 +82760,6 @@ class VoxelDebugOverlay {
|
|
|
82210
82760
|
}
|
|
82211
82761
|
}
|
|
82212
82762
|
|
|
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
82763
|
// String.replace wrapper that warns when the source substring is missing, so
|
|
82633
82764
|
// shader chunk patches against the engine fail loudly instead of silently
|
|
82634
82765
|
// producing the original chunk.
|
|
@@ -82736,7 +82867,7 @@ class Viewer {
|
|
|
82736
82867
|
forceRenderNextFrame = false;
|
|
82737
82868
|
voxelOverlay = null;
|
|
82738
82869
|
meshOverlay = null;
|
|
82739
|
-
|
|
82870
|
+
navCursor = null;
|
|
82740
82871
|
origChunks;
|
|
82741
82872
|
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
82742
82873
|
this.global = global;
|
|
@@ -82906,7 +83037,7 @@ class Viewer {
|
|
|
82906
83037
|
this.cameraManager = new CameraManager(global, sceneBound, collision);
|
|
82907
83038
|
applyCamera(this.cameraManager.camera);
|
|
82908
83039
|
if (!config.noui) {
|
|
82909
|
-
this.
|
|
83040
|
+
this.navCursor = new NavCursor(app, camera, collision ?? null, events, state, this.picker);
|
|
82910
83041
|
}
|
|
82911
83042
|
const { instance } = gsplat;
|
|
82912
83043
|
if (instance) {
|
|
@@ -82941,18 +83072,22 @@ class Viewer {
|
|
|
82941
83072
|
high: 4
|
|
82942
83073
|
}
|
|
82943
83074
|
};
|
|
82944
|
-
const
|
|
82945
|
-
|
|
82946
|
-
|
|
82947
|
-
|
|
82948
|
-
|
|
82949
|
-
|
|
83075
|
+
const applyPerfSettings = () => {
|
|
83076
|
+
const budget = () => {
|
|
83077
|
+
if (config.budget !== undefined && Number.isFinite(config.budget) && config.budget > 0) {
|
|
83078
|
+
return config.budget;
|
|
83079
|
+
}
|
|
83080
|
+
const quality = platform.mobile ? budgets.mobile : budgets.desktop;
|
|
83081
|
+
return state.performanceMode ? quality.low : quality.high;
|
|
83082
|
+
};
|
|
83083
|
+
gsplat.splatBudget = budget() * 1000000;
|
|
83084
|
+
gsplat.lodRangeMin = 0;
|
|
83085
|
+
gsplat.lodRangeMax = 1000;
|
|
83086
|
+
gsplat.colorUpdateAngle = state.performanceMode ? 4 : 2;
|
|
82950
83087
|
};
|
|
82951
83088
|
if (config.fullload) {
|
|
82952
83089
|
// reveal once full quality has finished loading (used for screenshots)
|
|
82953
|
-
|
|
82954
|
-
gsplat.lodRangeMin = 0;
|
|
82955
|
-
gsplat.lodRangeMax = 1000;
|
|
83090
|
+
applyPerfSettings();
|
|
82956
83091
|
}
|
|
82957
83092
|
else {
|
|
82958
83093
|
// reveal once low lod has loaded for fastest possible reveal
|
|
@@ -82993,13 +83128,8 @@ class Viewer {
|
|
|
82993
83128
|
eventHandler.off('frame:ready', readyHandler);
|
|
82994
83129
|
state.readyToRender = true;
|
|
82995
83130
|
// handle quality mode changes
|
|
82996
|
-
|
|
82997
|
-
|
|
82998
|
-
gsplat.lodRangeMin = 0;
|
|
82999
|
-
gsplat.lodRangeMax = 1000;
|
|
83000
|
-
};
|
|
83001
|
-
events.on('performanceMode:changed', updateLod);
|
|
83002
|
-
updateLod();
|
|
83131
|
+
events.on('performanceMode:changed', applyPerfSettings);
|
|
83132
|
+
applyPerfSettings();
|
|
83003
83133
|
// debug colorize lods
|
|
83004
83134
|
gsplat.debug = config.colorize ? GSPLAT_DEBUG_LOD : GSPLAT_DEBUG_NONE;
|
|
83005
83135
|
gsplat.renderer = rendererTable[config.renderer];
|
|
@@ -83995,7 +84125,7 @@ const initXr = (global) => {
|
|
|
83995
84125
|
});
|
|
83996
84126
|
};
|
|
83997
84127
|
|
|
83998
|
-
var version = "1.22.
|
|
84128
|
+
var version = "1.22.1";
|
|
83999
84129
|
|
|
84000
84130
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
84001
84131
|
const { contents, contentUrl, aa } = config;
|