@playcanvas/supersplat-viewer 1.21.0 → 1.22.0
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 +2 -2
- package/package.json +1 -1
- package/public/index.html +10 -2
- package/public/index.js +1949 -817
- 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$2 = 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$3 = 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$2.copy(x);
|
|
19912
19912
|
} else {
|
|
19913
|
-
rotation$
|
|
19913
|
+
rotation$2.set(x, y, z, w);
|
|
19914
19914
|
}
|
|
19915
19915
|
if (this._parent === null) {
|
|
19916
|
-
this.localRotation.copy(rotation$
|
|
19916
|
+
this.localRotation.copy(rotation$2);
|
|
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$2);
|
|
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$3.copy(y);
|
|
20075
20075
|
} else {
|
|
20076
|
-
up$
|
|
20076
|
+
up$3.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$3.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$3);
|
|
20085
|
+
rotation$2.setFromMat4(matrix);
|
|
20086
|
+
this.setRotation(rotation$2);
|
|
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$2.setFromEulerAngles(x, y, z);
|
|
20111
20111
|
if (this._parent === null) {
|
|
20112
|
-
this.localRotation.mul2(rotation$
|
|
20112
|
+
this.localRotation.mul2(rotation$2, 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$2.mul2(invParentRot, rotation$2);
|
|
20118
|
+
this.localRotation.mul2(rotation$2, 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$2.setFromEulerAngles(x, y, z);
|
|
20126
|
+
this.localRotation.mul(rotation$2);
|
|
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
|
|
33146
|
+
const dir = 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
|
|
33170
|
-
if (updateMode === 'enable' && dir
|
|
33168
|
+
invModelMat$1.transformVector(camera.forward, dir);
|
|
33169
|
+
dir.normalize();
|
|
33170
|
+
if (updateMode === 'enable' && dir.equalsApprox(prevDir, 1e-3)) {
|
|
33171
33171
|
return;
|
|
33172
33172
|
}
|
|
33173
|
-
prevDir.copy(dir
|
|
33173
|
+
prevDir.copy(dir);
|
|
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
|
|
33178
|
+
dir: dir.toArray(),
|
|
33179
33179
|
centroids: sh_centroids,
|
|
33180
33180
|
shN_mins: meta.shN.mins,
|
|
33181
33181
|
shN_maxs: meta.shN.maxs
|
|
@@ -73163,73 +73163,6 @@ class CameraFrame {
|
|
|
73163
73163
|
}
|
|
73164
73164
|
}
|
|
73165
73165
|
|
|
73166
|
-
const tmpV1$1 = new Vec3();
|
|
73167
|
-
const rotation$4 = 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$4.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
|
-
|
|
73233
73166
|
class InputDelta {
|
|
73234
73167
|
add(other) {
|
|
73235
73168
|
for(let i = 0; i < this._value.length; i++){
|
|
@@ -73315,25 +73248,6 @@ class InputSource extends InputFrame {
|
|
|
73315
73248
|
super(...args), this._element = null, this._events = new EventHandler();
|
|
73316
73249
|
}
|
|
73317
73250
|
}
|
|
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
|
-
};
|
|
73337
73251
|
|
|
73338
73252
|
const movementState = ()=>{
|
|
73339
73253
|
const state = new Map();
|
|
@@ -73367,60 +73281,6 @@ const movementState = ()=>{
|
|
|
73367
73281
|
};
|
|
73368
73282
|
};
|
|
73369
73283
|
|
|
73370
|
-
const damp$1 = (damping, dt)=>1 - Math.pow(damping, dt * 1000);
|
|
73371
|
-
|
|
73372
|
-
const offset$2 = new Vec3();
|
|
73373
|
-
const angles$1 = new Vec3();
|
|
73374
|
-
const forward$1 = new Vec3();
|
|
73375
|
-
const right$2 = new Vec3();
|
|
73376
|
-
const up$1 = new Vec3();
|
|
73377
|
-
const rotation$3 = new Quat();
|
|
73378
|
-
let FlyController$1 = class FlyController extends InputController$1 {
|
|
73379
|
-
set pitchRange(value) {
|
|
73380
|
-
this._targetPose.pitchRange.copy(value);
|
|
73381
|
-
this._pose.copy(this._targetPose.rotate(Vec3.ZERO));
|
|
73382
|
-
}
|
|
73383
|
-
get pitchRange() {
|
|
73384
|
-
return this._targetPose.pitchRange;
|
|
73385
|
-
}
|
|
73386
|
-
set yawRange(value) {
|
|
73387
|
-
this._targetPose.yawRange.copy(value);
|
|
73388
|
-
this._pose.copy(this._targetPose.rotate(Vec3.ZERO));
|
|
73389
|
-
}
|
|
73390
|
-
get yawRange() {
|
|
73391
|
-
return this._targetPose.yawRange;
|
|
73392
|
-
}
|
|
73393
|
-
attach(pose, smooth = true) {
|
|
73394
|
-
this._targetPose.copy(pose);
|
|
73395
|
-
if (!smooth) {
|
|
73396
|
-
this._pose.copy(this._targetPose);
|
|
73397
|
-
}
|
|
73398
|
-
}
|
|
73399
|
-
detach() {
|
|
73400
|
-
this._targetPose.copy(this._pose);
|
|
73401
|
-
}
|
|
73402
|
-
update(frame, dt) {
|
|
73403
|
-
const { move, rotate } = frame.read();
|
|
73404
|
-
this._targetPose.rotate(angles$1.set(-rotate[1], -rotate[0], 0));
|
|
73405
|
-
rotation$3.setFromEulerAngles(this._pose.angles);
|
|
73406
|
-
rotation$3.transformVector(Vec3.FORWARD, forward$1);
|
|
73407
|
-
rotation$3.transformVector(Vec3.RIGHT, right$2);
|
|
73408
|
-
rotation$3.transformVector(Vec3.UP, up$1);
|
|
73409
|
-
offset$2.set(0, 0, 0);
|
|
73410
|
-
offset$2.add(forward$1.mulScalar(move[2]));
|
|
73411
|
-
offset$2.add(right$2.mulScalar(move[0]));
|
|
73412
|
-
offset$2.add(up$1.mulScalar(move[1]));
|
|
73413
|
-
this._targetPose.move(offset$2);
|
|
73414
|
-
return this._pose.lerp(this._pose, this._targetPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt));
|
|
73415
|
-
}
|
|
73416
|
-
destroy() {
|
|
73417
|
-
this.detach();
|
|
73418
|
-
}
|
|
73419
|
-
constructor(...args){
|
|
73420
|
-
super(...args), this._targetPose = new Pose(), this.rotateDamping = 0.98, this.moveDamping = 0.98;
|
|
73421
|
-
}
|
|
73422
|
-
};
|
|
73423
|
-
|
|
73424
73284
|
const BUTTON_CODES = {
|
|
73425
73285
|
A: 0,
|
|
73426
73286
|
B: 1,
|
|
@@ -74876,65 +74736,6 @@ class MultiTouchSource extends InputSource {
|
|
|
74876
74736
|
}
|
|
74877
74737
|
}
|
|
74878
74738
|
|
|
74879
|
-
const dir = new Vec3();
|
|
74880
|
-
const offset$1 = new Vec3();
|
|
74881
|
-
const angles = new Vec3();
|
|
74882
|
-
const rotation$2 = new Quat();
|
|
74883
|
-
let OrbitController$1 = class OrbitController extends InputController$1 {
|
|
74884
|
-
set pitchRange(range) {
|
|
74885
|
-
this._targetRootPose.pitchRange.copy(range);
|
|
74886
|
-
this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
|
|
74887
|
-
}
|
|
74888
|
-
get pitchRange() {
|
|
74889
|
-
return this._targetRootPose.pitchRange;
|
|
74890
|
-
}
|
|
74891
|
-
set yawRange(range) {
|
|
74892
|
-
this._targetRootPose.yawRange.copy(range);
|
|
74893
|
-
this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
|
|
74894
|
-
}
|
|
74895
|
-
get yawRange() {
|
|
74896
|
-
return this._targetRootPose.yawRange;
|
|
74897
|
-
}
|
|
74898
|
-
set zoomRange(range) {
|
|
74899
|
-
this._targetChildPose.zRange.copy(range);
|
|
74900
|
-
this._childPose.copy(this._targetChildPose.move(Vec3.ZERO));
|
|
74901
|
-
}
|
|
74902
|
-
get zoomRange() {
|
|
74903
|
-
return this._targetRootPose.zRange;
|
|
74904
|
-
}
|
|
74905
|
-
attach(pose, smooth = true) {
|
|
74906
|
-
this._targetRootPose.set(pose.getFocus(dir), pose.angles, 0);
|
|
74907
|
-
this._targetChildPose.position.set(0, 0, pose.distance);
|
|
74908
|
-
if (!smooth) {
|
|
74909
|
-
this._rootPose.copy(this._targetRootPose);
|
|
74910
|
-
this._childPose.copy(this._targetChildPose);
|
|
74911
|
-
}
|
|
74912
|
-
}
|
|
74913
|
-
detach() {
|
|
74914
|
-
this._targetRootPose.copy(this._rootPose);
|
|
74915
|
-
this._targetChildPose.copy(this._childPose);
|
|
74916
|
-
}
|
|
74917
|
-
update(frame, dt) {
|
|
74918
|
-
const { move, rotate } = frame.read();
|
|
74919
|
-
offset$1.set(move[0], move[1], 0);
|
|
74920
|
-
rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(offset$1, offset$1);
|
|
74921
|
-
this._targetRootPose.move(offset$1);
|
|
74922
|
-
const { z: dist } = this._targetChildPose.position;
|
|
74923
|
-
this._targetChildPose.move(offset$1.set(0, 0, dist * (1 + move[2]) - dist));
|
|
74924
|
-
this._targetRootPose.rotate(angles.set(-rotate[1], -rotate[0], 0));
|
|
74925
|
-
this._rootPose.lerp(this._rootPose, this._targetRootPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt), 1);
|
|
74926
|
-
this._childPose.lerp(this._childPose, this._targetChildPose, damp$1(this.zoomDamping, dt), 1, 1);
|
|
74927
|
-
rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(this._childPose.position, offset$1).add(this._rootPose.position);
|
|
74928
|
-
return this._pose.set(offset$1, this._rootPose.angles, this._childPose.position.z);
|
|
74929
|
-
}
|
|
74930
|
-
destroy() {
|
|
74931
|
-
this.detach();
|
|
74932
|
-
}
|
|
74933
|
-
constructor(...args){
|
|
74934
|
-
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;
|
|
74935
|
-
}
|
|
74936
|
-
};
|
|
74937
|
-
|
|
74938
74739
|
class App extends AppBase {
|
|
74939
74740
|
constructor(canvas, options) {
|
|
74940
74741
|
super(canvas);
|
|
@@ -75703,7 +75504,7 @@ const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
|
|
|
75703
75504
|
/** Half-extent of the flatness sampling patch (5x5 when R=2). */
|
|
75704
75505
|
const FLAT_R = 2;
|
|
75705
75506
|
/** 1/sqrt(2), used to normalise 45-degree diagonal normals. */
|
|
75706
|
-
const INV_SQRT2 = 1 / Math.sqrt(2);
|
|
75507
|
+
const INV_SQRT2$1 = 1 / Math.sqrt(2);
|
|
75707
75508
|
/**
|
|
75708
75509
|
* Surface normal candidate directions for querySurfaceNormal.
|
|
75709
75510
|
* Each entry: [dx, dy, dz, t1x, t1y, t1z, t2x, t2y, t2z]
|
|
@@ -75947,7 +75748,7 @@ class VoxelCollision {
|
|
|
75947
75748
|
const score = scoreSurfaceCandidate(this, ix, iy, iz, sx, sy, sz, cand[3], cand[4], cand[5], cand[6], cand[7], cand[8]);
|
|
75948
75749
|
if (score > bestScore) {
|
|
75949
75750
|
bestScore = score;
|
|
75950
|
-
const mag = (Math.abs(dx) + Math.abs(dy) + Math.abs(dz)) > 1 ? INV_SQRT2 : 1;
|
|
75751
|
+
const mag = (Math.abs(dx) + Math.abs(dy) + Math.abs(dz)) > 1 ? INV_SQRT2$1 : 1;
|
|
75951
75752
|
bestNx = sx * mag;
|
|
75952
75753
|
bestNy = sy * mag;
|
|
75953
75754
|
bestNz = sz * mag;
|
|
@@ -76913,7 +76714,7 @@ const initUI = (global) => {
|
|
|
76913
76714
|
'orbitCamera', 'flyCamera', 'fpsCamera',
|
|
76914
76715
|
'performanceModeRow', 'performanceModeCheck', 'performanceModeOption',
|
|
76915
76716
|
'gamingControlsDivider', 'gamingControlsRow', 'gamingControlsCheck', 'gamingControlsOption',
|
|
76916
|
-
'desktopClickToWalk', 'desktopGamingControls',
|
|
76717
|
+
'desktopFlyClickToFly', 'desktopClickToWalk', 'desktopGamingControls',
|
|
76917
76718
|
'touchFlyClickToWalk', 'touchFlyGamingControls',
|
|
76918
76719
|
'touchClickToWalk', 'touchGamingControls',
|
|
76919
76720
|
'walkHint',
|
|
@@ -77031,10 +76832,9 @@ const initUI = (global) => {
|
|
|
77031
76832
|
updateGamingSettingsVisibility();
|
|
77032
76833
|
const updateGamingControls = () => {
|
|
77033
76834
|
dom.gamingControlsCheck.classList.toggle('active', state.gamingControls);
|
|
77034
|
-
|
|
77035
|
-
|
|
77036
|
-
|
|
77037
|
-
}
|
|
76835
|
+
dom.desktopFlyClickToFly.classList.toggle('hidden', state.gamingControls);
|
|
76836
|
+
dom.desktopClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
76837
|
+
dom.desktopGamingControls.classList.toggle('hidden', !state.gamingControls);
|
|
77038
76838
|
dom.touchFlyClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
77039
76839
|
dom.touchFlyGamingControls.classList.toggle('hidden', !state.gamingControls);
|
|
77040
76840
|
dom.touchClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
@@ -77042,6 +76842,7 @@ const initUI = (global) => {
|
|
|
77042
76842
|
localStorage.setItem('gamingControls', String(state.gamingControls));
|
|
77043
76843
|
};
|
|
77044
76844
|
events.on('gamingControls:changed', updateGamingControls);
|
|
76845
|
+
events.on('inputMode:changed', updateGamingControls);
|
|
77045
76846
|
updateGamingControls();
|
|
77046
76847
|
// AR/VR
|
|
77047
76848
|
const arChanged = () => dom.arMode.classList[state.hasAR ? 'remove' : 'add']('hidden');
|
|
@@ -77106,7 +76907,24 @@ const initUI = (global) => {
|
|
|
77106
76907
|
// show the ui and start a timer to hide it again
|
|
77107
76908
|
let uiTimeout = null;
|
|
77108
76909
|
let annotationVisible = false;
|
|
76910
|
+
const isPointerCapturedMode = () => (state.inputMode === 'desktop' &&
|
|
76911
|
+
state.gamingControls &&
|
|
76912
|
+
(state.cameraMode === 'walk' || state.cameraMode === 'fly'));
|
|
76913
|
+
const hideUI = () => {
|
|
76914
|
+
if (uiTimeout) {
|
|
76915
|
+
clearTimeout(uiTimeout);
|
|
76916
|
+
uiTimeout = null;
|
|
76917
|
+
}
|
|
76918
|
+
dom.infoPanel.classList.add('hidden');
|
|
76919
|
+
dom.settingsPanel.classList.add('hidden');
|
|
76920
|
+
dom.walkHint.classList.add('hidden');
|
|
76921
|
+
state.controlsHidden = true;
|
|
76922
|
+
};
|
|
77109
76923
|
const showUI = () => {
|
|
76924
|
+
if (isPointerCapturedMode()) {
|
|
76925
|
+
hideUI();
|
|
76926
|
+
return;
|
|
76927
|
+
}
|
|
77110
76928
|
if (uiTimeout) {
|
|
77111
76929
|
clearTimeout(uiTimeout);
|
|
77112
76930
|
}
|
|
@@ -77124,6 +76942,17 @@ const initUI = (global) => {
|
|
|
77124
76942
|
showUI();
|
|
77125
76943
|
});
|
|
77126
76944
|
events.on('inputEvent', showUI);
|
|
76945
|
+
const updateCapturedUI = () => {
|
|
76946
|
+
if (isPointerCapturedMode()) {
|
|
76947
|
+
hideUI();
|
|
76948
|
+
}
|
|
76949
|
+
else {
|
|
76950
|
+
showUI();
|
|
76951
|
+
}
|
|
76952
|
+
};
|
|
76953
|
+
events.on('cameraMode:changed', updateCapturedUI);
|
|
76954
|
+
events.on('inputMode:changed', updateCapturedUI);
|
|
76955
|
+
events.on('gamingControls:changed', updateCapturedUI);
|
|
77127
76956
|
// keep UI visible while an annotation tooltip is shown
|
|
77128
76957
|
events.on('annotation.activate', () => {
|
|
77129
76958
|
annotationVisible = true;
|
|
@@ -77220,7 +77049,7 @@ const initUI = (global) => {
|
|
|
77220
77049
|
'Tap to walk. Drag to look around.';
|
|
77221
77050
|
};
|
|
77222
77051
|
events.on('cameraMode:changed', (value) => {
|
|
77223
|
-
if (value === 'walk' && !walkHintShown) {
|
|
77052
|
+
if (value === 'walk' && !walkHintShown && !isPointerCapturedMode()) {
|
|
77224
77053
|
walkHintShown = true;
|
|
77225
77054
|
dom.walkHint.textContent = getWalkHintText();
|
|
77226
77055
|
dom.walkHint.classList.remove('hidden');
|
|
@@ -77849,7 +77678,9 @@ class Annotations {
|
|
|
77849
77678
|
this.parentDom = parentDom;
|
|
77850
77679
|
const { state } = global;
|
|
77851
77680
|
const updateVisibility = () => {
|
|
77852
|
-
const
|
|
77681
|
+
const firstPersonGamingControls = ((state.cameraMode === 'walk' || state.cameraMode === 'fly') &&
|
|
77682
|
+
state.gamingControls);
|
|
77683
|
+
const hidden = state.controlsHidden || firstPersonGamingControls;
|
|
77853
77684
|
parentDom.style.display = hidden ? 'none' : 'block';
|
|
77854
77685
|
Annotation.opacity = hidden ? 0.0 : 1.0;
|
|
77855
77686
|
if (this.annotations.length > 0) {
|
|
@@ -78316,97 +78147,647 @@ class Camera {
|
|
|
78316
78147
|
}
|
|
78317
78148
|
}
|
|
78318
78149
|
|
|
78319
|
-
|
|
78320
|
-
|
|
78321
|
-
|
|
78150
|
+
const rotation = new Quat();
|
|
78151
|
+
/**
|
|
78152
|
+
* Apply a CameraFrame rotate delta to camera Euler angles.
|
|
78153
|
+
*
|
|
78154
|
+
* CameraFrame rotate uses [yaw, pitch, roll]-style input deltas, while camera
|
|
78155
|
+
* angles are stored as [pitch, yaw, roll].
|
|
78156
|
+
*
|
|
78157
|
+
* @param angles - Camera Euler angles to mutate.
|
|
78158
|
+
* @param rotate - Frame rotate delta.
|
|
78159
|
+
* @param minPitch - Minimum pitch angle in degrees.
|
|
78160
|
+
* @param maxPitch - Maximum pitch angle in degrees.
|
|
78161
|
+
* @returns The mutated angles.
|
|
78162
|
+
*/
|
|
78163
|
+
const applyFrameRotation = (angles, rotate, minPitch = -90, maxPitch = 90) => {
|
|
78164
|
+
angles.x -= rotate[1];
|
|
78165
|
+
angles.y -= rotate[0];
|
|
78166
|
+
angles.z = 0;
|
|
78167
|
+
angles.x = math.clamp(angles.x, minPitch, maxPitch);
|
|
78168
|
+
return angles;
|
|
78169
|
+
};
|
|
78170
|
+
/**
|
|
78171
|
+
* Calculate camera-relative basis vectors from Euler angles.
|
|
78172
|
+
*
|
|
78173
|
+
* @param angles - Camera Euler angles in degrees.
|
|
78174
|
+
* @param forward - Receives the forward vector.
|
|
78175
|
+
* @param right - Receives the right vector.
|
|
78176
|
+
* @param up - Receives the up vector.
|
|
78177
|
+
*/
|
|
78178
|
+
const setCameraBasis = (angles, forward, right, up) => {
|
|
78179
|
+
rotation.setFromEulerAngles(angles);
|
|
78180
|
+
rotation.transformVector(Vec3.FORWARD, forward);
|
|
78181
|
+
rotation.transformVector(Vec3.RIGHT, right);
|
|
78182
|
+
rotation.transformVector(Vec3.UP, up);
|
|
78183
|
+
};
|
|
78184
|
+
/**
|
|
78185
|
+
* Calculate a camera forward vector from Euler angles.
|
|
78186
|
+
*
|
|
78187
|
+
* @param angles - Camera Euler angles in degrees.
|
|
78188
|
+
* @param forward - Receives the forward vector.
|
|
78189
|
+
*/
|
|
78190
|
+
const setCameraForward = (angles, forward) => {
|
|
78191
|
+
rotation.setFromEulerAngles(angles);
|
|
78192
|
+
rotation.transformVector(Vec3.FORWARD, forward);
|
|
78193
|
+
};
|
|
78194
|
+
/**
|
|
78195
|
+
* Calculate yaw-only movement basis vectors.
|
|
78196
|
+
*
|
|
78197
|
+
* @param yaw - Camera yaw angle in degrees.
|
|
78198
|
+
* @param forward - Receives the horizontal forward vector.
|
|
78199
|
+
* @param right - Receives the horizontal right vector.
|
|
78200
|
+
*/
|
|
78201
|
+
const setYawBasis = (yaw, forward, right) => {
|
|
78202
|
+
rotation.setFromEulerAngles(0, yaw, 0);
|
|
78203
|
+
rotation.transformVector(Vec3.FORWARD, forward);
|
|
78204
|
+
rotation.transformVector(Vec3.RIGHT, right);
|
|
78205
|
+
};
|
|
78206
|
+
/**
|
|
78207
|
+
* Build a world-space offset from local movement along camera basis vectors.
|
|
78208
|
+
*
|
|
78209
|
+
* @param out - Receives the world-space offset.
|
|
78210
|
+
* @param x - Local right movement.
|
|
78211
|
+
* @param y - Local up movement.
|
|
78212
|
+
* @param z - Local forward movement.
|
|
78213
|
+
* @param forward - Forward basis vector.
|
|
78214
|
+
* @param right - Right basis vector.
|
|
78215
|
+
* @param up - Up basis vector.
|
|
78216
|
+
* @returns The mutated output vector.
|
|
78217
|
+
*/
|
|
78218
|
+
const setBasisOffset = (out, x, y, z, forward, right, up) => {
|
|
78219
|
+
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
|
+
return out;
|
|
78221
|
+
};
|
|
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
|
+
|
|
78248
|
+
/** Extra resolve passes above the collider's internal iteration for tight corners */
|
|
78249
|
+
const MAX_COLLISION_PASSES = 4;
|
|
78250
|
+
/** Small clearance that keeps the sphere from resting exactly on a collision surface */
|
|
78251
|
+
const COLLISION_SKIN = 1e-3;
|
|
78252
|
+
/** Maximum surface planes to slide along in a single frame */
|
|
78253
|
+
const MAX_SLIDE_ITERATIONS = 3;
|
|
78254
|
+
const MIN_MOVE_SQ = 1e-10;
|
|
78255
|
+
const INV_SQRT2 = 1 / Math.sqrt(2);
|
|
78256
|
+
const SWEEP_RAY_OFFSETS = [
|
|
78257
|
+
[0, 0, true],
|
|
78258
|
+
[1, 0, false],
|
|
78259
|
+
[-1, 0, false],
|
|
78260
|
+
[0, 1, false],
|
|
78261
|
+
[0, -1, false],
|
|
78262
|
+
[INV_SQRT2, INV_SQRT2, false],
|
|
78263
|
+
[-INV_SQRT2, INV_SQRT2, false],
|
|
78264
|
+
[-INV_SQRT2, -INV_SQRT2, false],
|
|
78265
|
+
[INV_SQRT2, -INV_SQRT2, false]
|
|
78266
|
+
];
|
|
78267
|
+
const v$1 = new Vec3();
|
|
78268
|
+
const remainingMove = new Vec3();
|
|
78269
|
+
const collisionPush = new Vec3();
|
|
78270
|
+
const sweepDir = new Vec3();
|
|
78271
|
+
const sweepNormal = new Vec3();
|
|
78272
|
+
const sweepTangent = new Vec3();
|
|
78273
|
+
const sweepBitangent = new Vec3();
|
|
78274
|
+
const sweepOrigin = new Vec3();
|
|
78275
|
+
const worldUp = new Vec3(0, 1, 0);
|
|
78276
|
+
const worldRight = new Vec3(1, 0, 0);
|
|
78322
78277
|
/** Pre-allocated push-out vector for sphere collision */
|
|
78323
78278
|
const pushOut = { x: 0, y: 0, z: 0 };
|
|
78279
|
+
const sweepHit = {
|
|
78280
|
+
x: 0,
|
|
78281
|
+
y: 0,
|
|
78282
|
+
z: 0,
|
|
78283
|
+
nx: 0,
|
|
78284
|
+
ny: 1,
|
|
78285
|
+
nz: 0,
|
|
78286
|
+
travel: 0
|
|
78287
|
+
};
|
|
78288
|
+
class SphereMover {
|
|
78289
|
+
collision = null;
|
|
78290
|
+
radius;
|
|
78291
|
+
_lastClearPosition = new Vec3();
|
|
78292
|
+
_hasLastClearPosition = false;
|
|
78293
|
+
constructor(radius) {
|
|
78294
|
+
this.radius = radius;
|
|
78295
|
+
}
|
|
78296
|
+
reset(position) {
|
|
78297
|
+
this._setLastClearPosition(position);
|
|
78298
|
+
}
|
|
78299
|
+
move(position, move) {
|
|
78300
|
+
if (!this.collision) {
|
|
78301
|
+
position.add(move);
|
|
78302
|
+
this._setLastClearPosition(position);
|
|
78303
|
+
return;
|
|
78304
|
+
}
|
|
78305
|
+
remainingMove.copy(move);
|
|
78306
|
+
if (this._isMoveComplete(remainingMove)) {
|
|
78307
|
+
this.resolve(position);
|
|
78308
|
+
return;
|
|
78309
|
+
}
|
|
78310
|
+
for (let i = 0; i < MAX_SLIDE_ITERATIONS; i++) {
|
|
78311
|
+
if (this._isMoveComplete(remainingMove)) {
|
|
78312
|
+
break;
|
|
78313
|
+
}
|
|
78314
|
+
if (!this._moveAndSlide(position, remainingMove)) {
|
|
78315
|
+
break;
|
|
78316
|
+
}
|
|
78317
|
+
}
|
|
78318
|
+
}
|
|
78319
|
+
resolve(position) {
|
|
78320
|
+
if (!this.collision) {
|
|
78321
|
+
this._setLastClearPosition(position);
|
|
78322
|
+
return;
|
|
78323
|
+
}
|
|
78324
|
+
this._resolveSphere(position, collisionPush);
|
|
78325
|
+
if (!this._isSphereClear(position) && this._hasLastClearPosition) {
|
|
78326
|
+
position.copy(this._lastClearPosition);
|
|
78327
|
+
}
|
|
78328
|
+
if (this._isSphereClear(position)) {
|
|
78329
|
+
this._setLastClearPosition(position);
|
|
78330
|
+
}
|
|
78331
|
+
}
|
|
78332
|
+
_moveAndSlide(position, move) {
|
|
78333
|
+
const moveSq = move.x * move.x + move.y * move.y + move.z * move.z;
|
|
78334
|
+
const distance = Math.sqrt(moveSq);
|
|
78335
|
+
sweepDir.copy(move).mulScalar(1 / distance);
|
|
78336
|
+
if (!this._querySweep(position, sweepDir, distance, sweepHit)) {
|
|
78337
|
+
position.add(move);
|
|
78338
|
+
this.resolve(position);
|
|
78339
|
+
return false;
|
|
78340
|
+
}
|
|
78341
|
+
position.add(v$1.copy(sweepDir).mulScalar(sweepHit.travel));
|
|
78342
|
+
this.resolve(position);
|
|
78343
|
+
sweepNormal.set(sweepHit.nx, sweepHit.ny, sweepHit.nz);
|
|
78344
|
+
move.add(v$1.copy(sweepDir).mulScalar(-sweepHit.travel));
|
|
78345
|
+
this._clipMove(move, sweepNormal);
|
|
78346
|
+
return true;
|
|
78347
|
+
}
|
|
78348
|
+
_querySweep(position, dir, distance, out) {
|
|
78349
|
+
if (Math.abs(dir.y) < 0.99) {
|
|
78350
|
+
sweepTangent.cross(dir, worldUp).normalize();
|
|
78351
|
+
}
|
|
78352
|
+
else {
|
|
78353
|
+
sweepTangent.cross(dir, worldRight).normalize();
|
|
78354
|
+
}
|
|
78355
|
+
sweepBitangent.cross(dir, sweepTangent).normalize();
|
|
78356
|
+
let found = false;
|
|
78357
|
+
let bestTravel = Infinity;
|
|
78358
|
+
for (let i = 0; i < SWEEP_RAY_OFFSETS.length; i++) {
|
|
78359
|
+
const [tx, ty, centerRay] = SWEEP_RAY_OFFSETS[i];
|
|
78360
|
+
const radiusOffset = centerRay ? 0 : this.radius;
|
|
78361
|
+
const rayExtension = centerRay ? this.radius : 0;
|
|
78362
|
+
sweepOrigin.copy(position);
|
|
78363
|
+
if (!centerRay) {
|
|
78364
|
+
sweepOrigin.add(v$1.copy(sweepTangent).mulScalar(tx * radiusOffset));
|
|
78365
|
+
sweepOrigin.add(v$1.copy(sweepBitangent).mulScalar(ty * radiusOffset));
|
|
78366
|
+
}
|
|
78367
|
+
const hit = this.collision.queryRay(sweepOrigin.x, sweepOrigin.y, sweepOrigin.z, dir.x, dir.y, dir.z, distance + rayExtension + COLLISION_SKIN);
|
|
78368
|
+
if (!hit) {
|
|
78369
|
+
continue;
|
|
78370
|
+
}
|
|
78371
|
+
const hx = hit.x - sweepOrigin.x;
|
|
78372
|
+
const hy = hit.y - sweepOrigin.y;
|
|
78373
|
+
const hz = hit.z - sweepOrigin.z;
|
|
78374
|
+
const hitDistance = Math.max(0, hx * dir.x + hy * dir.y + hz * dir.z);
|
|
78375
|
+
const clearance = centerRay ? this.radius : 0;
|
|
78376
|
+
const travel = math.clamp(hitDistance - clearance - COLLISION_SKIN, 0, distance);
|
|
78377
|
+
if (travel >= bestTravel) {
|
|
78378
|
+
continue;
|
|
78379
|
+
}
|
|
78380
|
+
const surfaceNormal = this.collision.querySurfaceNormal(hit.x, hit.y, hit.z, dir.x, dir.y, dir.z);
|
|
78381
|
+
found = true;
|
|
78382
|
+
bestTravel = travel;
|
|
78383
|
+
out.x = hit.x;
|
|
78384
|
+
out.y = hit.y;
|
|
78385
|
+
out.z = hit.z;
|
|
78386
|
+
out.nx = surfaceNormal.nx;
|
|
78387
|
+
out.ny = surfaceNormal.ny;
|
|
78388
|
+
out.nz = surfaceNormal.nz;
|
|
78389
|
+
out.travel = travel;
|
|
78390
|
+
}
|
|
78391
|
+
return found;
|
|
78392
|
+
}
|
|
78393
|
+
_resolveSphere(position, push) {
|
|
78394
|
+
let collided = false;
|
|
78395
|
+
push.set(0, 0, 0);
|
|
78396
|
+
for (let i = 0; i < MAX_COLLISION_PASSES; i++) {
|
|
78397
|
+
if (!this.collision.querySphere(position.x, position.y, position.z, this.radius, pushOut)) {
|
|
78398
|
+
break;
|
|
78399
|
+
}
|
|
78400
|
+
position.x += pushOut.x;
|
|
78401
|
+
position.y += pushOut.y;
|
|
78402
|
+
position.z += pushOut.z;
|
|
78403
|
+
push.x += pushOut.x;
|
|
78404
|
+
push.y += pushOut.y;
|
|
78405
|
+
push.z += pushOut.z;
|
|
78406
|
+
collided = true;
|
|
78407
|
+
}
|
|
78408
|
+
return collided;
|
|
78409
|
+
}
|
|
78410
|
+
_clipMove(move, push) {
|
|
78411
|
+
const normalSq = push.x * push.x + push.y * push.y + push.z * push.z;
|
|
78412
|
+
if (normalSq <= MIN_MOVE_SQ) {
|
|
78413
|
+
return;
|
|
78414
|
+
}
|
|
78415
|
+
const invPushLen = 1 / Math.sqrt(normalSq);
|
|
78416
|
+
const nx = push.x * invPushLen;
|
|
78417
|
+
const ny = push.y * invPushLen;
|
|
78418
|
+
const nz = push.z * invPushLen;
|
|
78419
|
+
const dot = move.x * nx + move.y * ny + move.z * nz;
|
|
78420
|
+
if (dot < 0) {
|
|
78421
|
+
move.x -= dot * nx;
|
|
78422
|
+
move.y -= dot * ny;
|
|
78423
|
+
move.z -= dot * nz;
|
|
78424
|
+
}
|
|
78425
|
+
}
|
|
78426
|
+
_isMoveComplete(move) {
|
|
78427
|
+
return move.x * move.x + move.y * move.y + move.z * move.z <= MIN_MOVE_SQ;
|
|
78428
|
+
}
|
|
78429
|
+
_isSphereClear(position) {
|
|
78430
|
+
return !this.collision.querySphere(position.x, position.y, position.z, this.radius, pushOut);
|
|
78431
|
+
}
|
|
78432
|
+
_setLastClearPosition(position) {
|
|
78433
|
+
this._lastClearPosition.copy(position);
|
|
78434
|
+
this._hasLastClearPosition = !this.collision || this._isSphereClear(position);
|
|
78435
|
+
}
|
|
78436
|
+
}
|
|
78437
|
+
|
|
78438
|
+
/** Radius of the camera collision sphere (meters) */
|
|
78439
|
+
const CAMERA_RADIUS = 0.2;
|
|
78440
|
+
const forward$3 = new Vec3();
|
|
78441
|
+
const right$3 = new Vec3();
|
|
78442
|
+
const up$2 = new Vec3();
|
|
78443
|
+
const offset$1 = new Vec3();
|
|
78324
78444
|
class FlyController {
|
|
78325
|
-
controller;
|
|
78326
78445
|
fov = 90;
|
|
78446
|
+
_position = new Vec3();
|
|
78447
|
+
_angles = new Vec3();
|
|
78448
|
+
_distance = 1;
|
|
78449
|
+
_spawnPosition = new Vec3();
|
|
78450
|
+
_spawnAngles = new Vec3();
|
|
78451
|
+
_spawnDistance = 1;
|
|
78452
|
+
_mover = new SphereMover(CAMERA_RADIUS);
|
|
78327
78453
|
/** Optional collision for sphere collision with sliding */
|
|
78328
|
-
collision
|
|
78329
|
-
|
|
78330
|
-
this.
|
|
78331
|
-
this.controller.pitchRange = new Vec2(-90, 90);
|
|
78332
|
-
this.controller.rotateDamping = 0.97;
|
|
78333
|
-
this.controller.moveDamping = 0.97;
|
|
78454
|
+
set collision(value) {
|
|
78455
|
+
this._mover.collision = value;
|
|
78456
|
+
this._mover.reset(this._position);
|
|
78334
78457
|
}
|
|
78458
|
+
get collision() {
|
|
78459
|
+
return this._mover.collision;
|
|
78460
|
+
}
|
|
78461
|
+
_hasSpawn = false;
|
|
78335
78462
|
onEnter(camera) {
|
|
78336
|
-
|
|
78337
|
-
|
|
78338
|
-
|
|
78339
|
-
this.controller.attach(p$1, false);
|
|
78463
|
+
this.goto(camera);
|
|
78464
|
+
this._mover.resolve(this._position);
|
|
78465
|
+
this._storeSpawn();
|
|
78340
78466
|
}
|
|
78341
78467
|
update(deltaTime, inputFrame, camera) {
|
|
78342
|
-
const
|
|
78343
|
-
|
|
78344
|
-
|
|
78345
|
-
|
|
78346
|
-
|
|
78347
|
-
|
|
78348
|
-
|
|
78349
|
-
|
|
78350
|
-
|
|
78351
|
-
|
|
78352
|
-
|
|
78353
|
-
|
|
78354
|
-
|
|
78468
|
+
const { move, rotate } = inputFrame.read();
|
|
78469
|
+
applyFrameRotation(this._angles, rotate);
|
|
78470
|
+
this._step(move);
|
|
78471
|
+
camera.position.copy(this._position);
|
|
78472
|
+
camera.angles.set(this._angles.x, this._angles.y, 0);
|
|
78473
|
+
camera.distance = this._distance;
|
|
78474
|
+
camera.fov = this.fov;
|
|
78475
|
+
}
|
|
78476
|
+
onExit(_camera) {
|
|
78477
|
+
}
|
|
78478
|
+
goto(camera) {
|
|
78479
|
+
this._position.copy(camera.position);
|
|
78480
|
+
this._angles.set(camera.angles.x, camera.angles.y, 0);
|
|
78481
|
+
this._distance = camera.distance;
|
|
78482
|
+
this._mover.reset(this._position);
|
|
78483
|
+
}
|
|
78484
|
+
resetToSpawn(camera) {
|
|
78485
|
+
if (!this._hasSpawn) {
|
|
78486
|
+
return false;
|
|
78487
|
+
}
|
|
78488
|
+
this._position.copy(this._spawnPosition);
|
|
78489
|
+
this._angles.copy(this._spawnAngles);
|
|
78490
|
+
this._distance = this._spawnDistance;
|
|
78491
|
+
this._mover.reset(this._position);
|
|
78492
|
+
camera.position.copy(this._position);
|
|
78493
|
+
camera.angles.copy(this._angles);
|
|
78494
|
+
camera.distance = this._distance;
|
|
78495
|
+
camera.fov = this.fov;
|
|
78496
|
+
return true;
|
|
78497
|
+
}
|
|
78498
|
+
_storeSpawn() {
|
|
78499
|
+
this._spawnPosition.copy(this._position);
|
|
78500
|
+
this._spawnAngles.copy(this._angles);
|
|
78501
|
+
this._spawnDistance = this._distance;
|
|
78502
|
+
this._hasSpawn = true;
|
|
78503
|
+
}
|
|
78504
|
+
_step(move) {
|
|
78505
|
+
setCameraBasis(this._angles, forward$3, right$3, up$2);
|
|
78506
|
+
setBasisOffset(offset$1, move[0], move[1], move[2], forward$3, right$3, up$2);
|
|
78507
|
+
this._mover.move(this._position, offset$1);
|
|
78508
|
+
}
|
|
78509
|
+
}
|
|
78510
|
+
|
|
78511
|
+
const RAD_TO_DEG = 180 / Math.PI;
|
|
78512
|
+
const shortestAngle = (angle) => ((angle % 360) + 540) % 360 - 180;
|
|
78513
|
+
const smoothstep = (edge0, edge1, value) => {
|
|
78514
|
+
const t = math.clamp((value - edge0) / (edge1 - edge0), 0, 1);
|
|
78515
|
+
return t * t * (3 - 2 * t);
|
|
78516
|
+
};
|
|
78517
|
+
const approach = (value, target, maxDelta) => {
|
|
78518
|
+
if (value < target) {
|
|
78519
|
+
return Math.min(target, value + maxDelta);
|
|
78520
|
+
}
|
|
78521
|
+
return Math.max(target, value - maxDelta);
|
|
78522
|
+
};
|
|
78523
|
+
const smoothTurnRate = (currentRate, angleDiff, maxTurnRate, turnGain, dt) => {
|
|
78524
|
+
if (dt <= 0) {
|
|
78525
|
+
return currentRate;
|
|
78526
|
+
}
|
|
78527
|
+
const desiredRate = math.clamp(angleDiff * turnGain, -maxTurnRate, maxTurnRate);
|
|
78528
|
+
const smoothing = 1 - Math.exp(-4 * turnGain * dt);
|
|
78529
|
+
return currentRate + (desiredRate - currentRate) * smoothing;
|
|
78530
|
+
};
|
|
78531
|
+
const clampTurnStep = (rate, remaining, dt) => {
|
|
78532
|
+
const step = rate * dt;
|
|
78533
|
+
if (Math.abs(remaining) < 1e-4) {
|
|
78534
|
+
return 0;
|
|
78535
|
+
}
|
|
78536
|
+
return Math.sign(step) === Math.sign(remaining) && Math.abs(step) > Math.abs(remaining) ?
|
|
78537
|
+
remaining :
|
|
78538
|
+
step;
|
|
78539
|
+
};
|
|
78540
|
+
const getYawToTarget = (dx, dz) => Math.atan2(-dx, -dz) * RAD_TO_DEG;
|
|
78541
|
+
const getYawDiffToTarget = (dx, dz, yaw) => {
|
|
78542
|
+
return shortestAngle(getYawToTarget(dx, dz) - yaw);
|
|
78543
|
+
};
|
|
78544
|
+
const getPitchToDirection = (dirY) => {
|
|
78545
|
+
return Math.asin(math.clamp(dirY, -1, 1)) * RAD_TO_DEG;
|
|
78546
|
+
};
|
|
78547
|
+
class ProgressTracker {
|
|
78548
|
+
_blockedTime = 0;
|
|
78549
|
+
_prevDist = Infinity;
|
|
78550
|
+
reset() {
|
|
78551
|
+
this._blockedTime = 0;
|
|
78552
|
+
this._prevDist = Infinity;
|
|
78553
|
+
}
|
|
78554
|
+
update(distance, dt, blockedSpeed, blockedDuration, active = true) {
|
|
78555
|
+
if (active && this._prevDist !== Infinity && dt > 0) {
|
|
78556
|
+
const speed = (this._prevDist - distance) / dt;
|
|
78557
|
+
if (speed < blockedSpeed) {
|
|
78558
|
+
this._blockedTime += dt;
|
|
78559
|
+
if (this._blockedTime >= blockedDuration) {
|
|
78560
|
+
this._prevDist = distance;
|
|
78561
|
+
return true;
|
|
78562
|
+
}
|
|
78355
78563
|
}
|
|
78356
|
-
|
|
78357
|
-
|
|
78358
|
-
pose.position.y += pushOut.y;
|
|
78359
|
-
pose.position.z += pushOut.z;
|
|
78564
|
+
else {
|
|
78565
|
+
this._blockedTime = 0;
|
|
78360
78566
|
}
|
|
78361
78567
|
}
|
|
78362
|
-
|
|
78363
|
-
|
|
78568
|
+
this._prevDist = distance;
|
|
78569
|
+
return false;
|
|
78364
78570
|
}
|
|
78365
|
-
|
|
78571
|
+
}
|
|
78572
|
+
|
|
78573
|
+
const DEG_TO_RAD = Math.PI / 180;
|
|
78574
|
+
/** Target-space radius to keep visible at the stopping distance */
|
|
78575
|
+
const STOP_VIEW_RADIUS = 0.75;
|
|
78576
|
+
/** Minimum standoff from the target */
|
|
78577
|
+
const MIN_STOP_DIST = 0.75;
|
|
78578
|
+
/** Maximum standoff from the target */
|
|
78579
|
+
const MAX_STOP_DIST = 4.0;
|
|
78580
|
+
/** Distance from the standoff point below which arrival can complete */
|
|
78581
|
+
const ARRIVAL_EPSILON = 0.03;
|
|
78582
|
+
/** Forward speed below which arrival can complete */
|
|
78583
|
+
const ARRIVAL_SPEED = 0.05;
|
|
78584
|
+
/** Converts remaining standoff distance to final approach speed */
|
|
78585
|
+
const ARRIVAL_RATE = 1.75;
|
|
78586
|
+
/** Minimum progress speed (m/s) to not count as blocked */
|
|
78587
|
+
const BLOCKED_SPEED$1 = 0.25;
|
|
78588
|
+
/** Seconds of continuous low-progress before stopping the flight */
|
|
78589
|
+
const BLOCKED_DURATION$1 = 0.5;
|
|
78590
|
+
const toTarget = new Vec3();
|
|
78591
|
+
const forward$2 = new Vec3();
|
|
78592
|
+
const postTurnAngles = new Vec3();
|
|
78593
|
+
const getStopDistance = (fov) => {
|
|
78594
|
+
const halfFov = math.clamp(fov, 15, 120) * DEG_TO_RAD * 0.5;
|
|
78595
|
+
return math.clamp(STOP_VIEW_RADIUS / Math.tan(halfFov), MIN_STOP_DIST, MAX_STOP_DIST);
|
|
78596
|
+
};
|
|
78597
|
+
/**
|
|
78598
|
+
* Generates synthetic move/rotate input to auto-fly toward a target position.
|
|
78599
|
+
*/
|
|
78600
|
+
class FlySource {
|
|
78601
|
+
/**
|
|
78602
|
+
* Forward input scale (matches InputController.moveSpeed).
|
|
78603
|
+
*/
|
|
78604
|
+
flySpeed = 4;
|
|
78605
|
+
/**
|
|
78606
|
+
* Maximum pitch/yaw turn rate in degrees per second.
|
|
78607
|
+
*/
|
|
78608
|
+
maxTurnRate = 180;
|
|
78609
|
+
/**
|
|
78610
|
+
* Proportional gain mapping angular error (degrees) to desired turn rate.
|
|
78611
|
+
*/
|
|
78612
|
+
turnGain = 4;
|
|
78613
|
+
/**
|
|
78614
|
+
* Maximum forward acceleration in meters per second squared.
|
|
78615
|
+
*/
|
|
78616
|
+
moveAcceleration = 6;
|
|
78617
|
+
/**
|
|
78618
|
+
* Maximum forward braking in meters per second squared.
|
|
78619
|
+
*/
|
|
78620
|
+
moveDeceleration = 8;
|
|
78621
|
+
/**
|
|
78622
|
+
* Callback fired when an auto-flight completes or is cancelled.
|
|
78623
|
+
*/
|
|
78624
|
+
onComplete = null;
|
|
78625
|
+
_target = null;
|
|
78626
|
+
_yawRate = 0;
|
|
78627
|
+
_pitchRate = 0;
|
|
78628
|
+
_speed = 0;
|
|
78629
|
+
_progress = new ProgressTracker();
|
|
78630
|
+
get isFlying() {
|
|
78631
|
+
return this._target !== null;
|
|
78366
78632
|
}
|
|
78367
|
-
|
|
78368
|
-
|
|
78633
|
+
/**
|
|
78634
|
+
* Begin auto-flying toward a world-space target position.
|
|
78635
|
+
*
|
|
78636
|
+
* @param target - The destination.
|
|
78637
|
+
*/
|
|
78638
|
+
flyTo(target) {
|
|
78639
|
+
const wasFlying = this._target !== null;
|
|
78640
|
+
if (!this._target) {
|
|
78641
|
+
this._target = new Vec3();
|
|
78642
|
+
}
|
|
78643
|
+
this._target.copy(target);
|
|
78644
|
+
if (!wasFlying) {
|
|
78645
|
+
this._yawRate = 0;
|
|
78646
|
+
this._pitchRate = 0;
|
|
78647
|
+
this._speed = 0;
|
|
78648
|
+
}
|
|
78649
|
+
this._progress.reset();
|
|
78650
|
+
}
|
|
78651
|
+
/**
|
|
78652
|
+
* Cancel any active auto-flight.
|
|
78653
|
+
*/
|
|
78654
|
+
cancelFly() {
|
|
78655
|
+
if (this._target) {
|
|
78656
|
+
this._target = null;
|
|
78657
|
+
this._yawRate = 0;
|
|
78658
|
+
this._pitchRate = 0;
|
|
78659
|
+
this._speed = 0;
|
|
78660
|
+
this._progress.reset();
|
|
78661
|
+
this.onComplete?.();
|
|
78662
|
+
}
|
|
78663
|
+
}
|
|
78664
|
+
/**
|
|
78665
|
+
* Compute fly deltas and append them to the frame. Must be called before
|
|
78666
|
+
* the camera controller reads the frame.
|
|
78667
|
+
*
|
|
78668
|
+
* @param dt - Frame delta time in seconds.
|
|
78669
|
+
* @param cameraPosition - Camera world position.
|
|
78670
|
+
* @param cameraAngles - Camera Euler angles in degrees.
|
|
78671
|
+
* @param cameraFov - Camera vertical field-of-view in degrees.
|
|
78672
|
+
* @param frame - The shared CameraFrame to append deltas to.
|
|
78673
|
+
*/
|
|
78674
|
+
update(dt, cameraPosition, cameraAngles, cameraFov, frame) {
|
|
78675
|
+
if (!this._target)
|
|
78676
|
+
return;
|
|
78677
|
+
const target = this._target;
|
|
78678
|
+
toTarget.sub2(target, cameraPosition);
|
|
78679
|
+
const dist = toTarget.length();
|
|
78680
|
+
const stopDistance = getStopDistance(cameraFov);
|
|
78681
|
+
const remainingDist = dist - stopDistance;
|
|
78682
|
+
const activeRemainingDist = Math.max(0, remainingDist);
|
|
78683
|
+
if (activeRemainingDist <= ARRIVAL_EPSILON && this._speed <= ARRIVAL_SPEED) {
|
|
78684
|
+
this.cancelFly();
|
|
78685
|
+
return;
|
|
78686
|
+
}
|
|
78687
|
+
if (dt <= 0) {
|
|
78688
|
+
return;
|
|
78689
|
+
}
|
|
78690
|
+
const invDist = 1 / dist;
|
|
78691
|
+
const dirX = toTarget.x * invDist;
|
|
78692
|
+
const dirY = toTarget.y * invDist;
|
|
78693
|
+
const dirZ = toTarget.z * invDist;
|
|
78694
|
+
const yawDiff = getYawDiffToTarget(toTarget.x, toTarget.z, cameraAngles.y);
|
|
78695
|
+
const pitchDiff = getPitchToDirection(dirY) - cameraAngles.x;
|
|
78696
|
+
this._yawRate = smoothTurnRate(this._yawRate, yawDiff, this.maxTurnRate, this.turnGain, dt);
|
|
78697
|
+
this._pitchRate = smoothTurnRate(this._pitchRate, pitchDiff, this.maxTurnRate, this.turnGain, dt);
|
|
78698
|
+
const yawStep = clampTurnStep(this._yawRate, yawDiff, dt);
|
|
78699
|
+
const pitchStep = clampTurnStep(this._pitchRate, pitchDiff, dt);
|
|
78700
|
+
this._yawRate = yawStep / dt;
|
|
78701
|
+
this._pitchRate = pitchStep / dt;
|
|
78702
|
+
// FlyController applies: _angles += [-rotateY, -rotateX, 0]
|
|
78703
|
+
frame.deltas.rotate.append([-yawStep, -pitchStep, 0]);
|
|
78704
|
+
postTurnAngles.set(cameraAngles.x + pitchStep, cameraAngles.y + yawStep, 0);
|
|
78705
|
+
setCameraForward(postTurnAngles, forward$2);
|
|
78706
|
+
const alignment = math.clamp(forward$2.x * dirX + forward$2.y * dirY + forward$2.z * dirZ, 0, 1);
|
|
78707
|
+
const alignmentScale = smoothstep(0.05, 0.95, alignment);
|
|
78708
|
+
const brakeSpeed = Math.sqrt(2 * this.moveDeceleration * activeRemainingDist);
|
|
78709
|
+
const arrivalSpeed = activeRemainingDist * ARRIVAL_RATE;
|
|
78710
|
+
const maxSpeed = Math.min(this.flySpeed, brakeSpeed, arrivalSpeed);
|
|
78711
|
+
if (maxSpeed > this._speed) {
|
|
78712
|
+
this._speed = approach(this._speed, maxSpeed, this.moveAcceleration * alignmentScale * dt);
|
|
78713
|
+
}
|
|
78714
|
+
else {
|
|
78715
|
+
this._speed = approach(this._speed, maxSpeed, this.moveDeceleration * dt);
|
|
78716
|
+
}
|
|
78717
|
+
const arrivalMove = activeRemainingDist * (1 - Math.exp(-ARRIVAL_RATE * dt));
|
|
78718
|
+
const moveDist = Math.min(this._speed * dt, arrivalMove);
|
|
78719
|
+
if (moveDist > 0) {
|
|
78720
|
+
frame.deltas.move.append([0, 0, moveDist]);
|
|
78721
|
+
}
|
|
78722
|
+
// Only treat low progress as blocked once the camera is substantially
|
|
78723
|
+
// facing the target; otherwise a large turn-in-place would cancel early.
|
|
78724
|
+
if (this._progress.update(dist, dt, BLOCKED_SPEED$1, BLOCKED_DURATION$1, alignment > 0.5 && this._speed > BLOCKED_SPEED$1)) {
|
|
78725
|
+
this.cancelFly();
|
|
78726
|
+
}
|
|
78369
78727
|
}
|
|
78370
78728
|
}
|
|
78371
78729
|
|
|
78372
|
-
const
|
|
78730
|
+
const MIN_DISTANCE = 0.01;
|
|
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();
|
|
78373
78737
|
class OrbitController {
|
|
78374
|
-
controller;
|
|
78375
78738
|
fov = 90;
|
|
78376
|
-
|
|
78377
|
-
|
|
78378
|
-
|
|
78379
|
-
|
|
78380
|
-
|
|
78381
|
-
|
|
78382
|
-
|
|
78383
|
-
|
|
78739
|
+
rotateDamping = 0.97;
|
|
78740
|
+
moveDamping = 0.97;
|
|
78741
|
+
zoomDamping = 0.97;
|
|
78742
|
+
_focus = new Vec3();
|
|
78743
|
+
_targetFocus = new Vec3();
|
|
78744
|
+
_angles = new Vec3();
|
|
78745
|
+
_targetAngles = new Vec3();
|
|
78746
|
+
_distance = 1;
|
|
78747
|
+
_targetDistance = 1;
|
|
78384
78748
|
onEnter(camera) {
|
|
78385
|
-
|
|
78386
|
-
p.angles.copy(camera.angles);
|
|
78387
|
-
p.distance = camera.distance;
|
|
78388
|
-
this.controller.attach(p, false);
|
|
78749
|
+
this._syncPose(camera, false);
|
|
78389
78750
|
}
|
|
78390
78751
|
update(deltaTime, inputFrame, camera) {
|
|
78391
|
-
const
|
|
78392
|
-
|
|
78393
|
-
|
|
78394
|
-
|
|
78752
|
+
const { move, rotate } = inputFrame.read();
|
|
78753
|
+
setCameraBasis(this._angles, forward$1, right$2, up$1);
|
|
78754
|
+
setBasisOffset(pan, move[0], move[1], 0, forward$1, right$2, up$1);
|
|
78755
|
+
this._targetFocus.add(pan);
|
|
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;
|
|
78395
78765
|
camera.fov = this.fov;
|
|
78396
78766
|
}
|
|
78397
|
-
onExit(
|
|
78767
|
+
onExit(_camera) {
|
|
78398
78768
|
}
|
|
78399
78769
|
goto(camera) {
|
|
78400
|
-
|
|
78401
|
-
|
|
78402
|
-
|
|
78403
|
-
|
|
78404
|
-
this.
|
|
78770
|
+
this._syncPose(camera, true);
|
|
78771
|
+
}
|
|
78772
|
+
_syncPose(camera, copyFov) {
|
|
78773
|
+
camera.calcFocusPoint(focus);
|
|
78774
|
+
this._focus.copy(focus);
|
|
78775
|
+
this._targetFocus.copy(focus);
|
|
78776
|
+
this._angles.copy(camera.angles);
|
|
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
|
+
}
|
|
78405
78783
|
}
|
|
78406
78784
|
}
|
|
78407
78785
|
|
|
78408
78786
|
const FIXED_DT = 1 / 60;
|
|
78409
78787
|
const MAX_SUBSTEPS = 10;
|
|
78788
|
+
const SPAWN_HIT_EPSILON = 1e-3;
|
|
78789
|
+
const SPAWN_SEARCH_MIN_STEP = 0.05;
|
|
78790
|
+
const SPAWN_SEARCH_MAX_STEPS = 128;
|
|
78410
78791
|
/** Pre-allocated push-out vector for capsule collision */
|
|
78411
78792
|
const out = { x: 0, y: 0, z: 0 };
|
|
78412
78793
|
const v = new Vec3();
|
|
@@ -78415,13 +78796,13 @@ const forward = new Vec3();
|
|
|
78415
78796
|
const right$1 = new Vec3();
|
|
78416
78797
|
const moveStep = [0, 0, 0];
|
|
78417
78798
|
const offset = new Vec3();
|
|
78418
|
-
const
|
|
78799
|
+
const spawnProbe = new Vec3();
|
|
78419
78800
|
/**
|
|
78420
|
-
* First-person camera controller with spring-damper suspension over
|
|
78801
|
+
* First-person camera controller with spring-damper suspension over collision terrain.
|
|
78421
78802
|
*
|
|
78422
78803
|
* Movement is constrained to the horizontal plane (XZ) relative to the camera yaw.
|
|
78423
78804
|
* Vertical positioning uses a spring-damper system that hovers the capsule above the
|
|
78424
|
-
*
|
|
78805
|
+
* collision surface, filtering out terrain noise for smooth camera motion. Capsule
|
|
78425
78806
|
* collision handles walls and obstacles. When airborne, normal gravity applies.
|
|
78426
78807
|
*/
|
|
78427
78808
|
class WalkController {
|
|
@@ -78479,7 +78860,7 @@ class WalkController {
|
|
|
78479
78860
|
velocityDampingAir = 0.998;
|
|
78480
78861
|
/**
|
|
78481
78862
|
* Target clearance from capsule bottom to ground surface in meters.
|
|
78482
|
-
* The capsule hovers this far above terrain to avoid bouncing on noisy
|
|
78863
|
+
* The capsule hovers this far above terrain to avoid bouncing on noisy surfaces.
|
|
78483
78864
|
*/
|
|
78484
78865
|
hoverHeight = 0.2;
|
|
78485
78866
|
/**
|
|
@@ -78495,34 +78876,43 @@ class WalkController {
|
|
|
78495
78876
|
* Maximum downward raycast distance to search for ground below the capsule.
|
|
78496
78877
|
*/
|
|
78497
78878
|
groundProbeRange = 1.0;
|
|
78879
|
+
/**
|
|
78880
|
+
* Maximum vertical raycast distance to search for walk spawn ground.
|
|
78881
|
+
*/
|
|
78882
|
+
spawnSearchRange = 1000;
|
|
78498
78883
|
_position = new Vec3();
|
|
78499
78884
|
_prevPosition = new Vec3();
|
|
78500
78885
|
_angles = new Vec3();
|
|
78886
|
+
_distance = 1;
|
|
78887
|
+
_spawnPosition = new Vec3();
|
|
78888
|
+
_spawnAngles = new Vec3();
|
|
78889
|
+
_spawnDistance = 1;
|
|
78501
78890
|
_velocity = new Vec3();
|
|
78502
78891
|
_pendingMove = [0, 0, 0];
|
|
78503
78892
|
_accumulator = 0;
|
|
78504
78893
|
_grounded = false;
|
|
78505
78894
|
_jumping = false;
|
|
78506
78895
|
_jumpHeld = false;
|
|
78896
|
+
_spawnGrounded = false;
|
|
78897
|
+
_hasSpawn = false;
|
|
78507
78898
|
onEnter(camera) {
|
|
78508
78899
|
this.goto(camera);
|
|
78509
78900
|
if (this.collision) {
|
|
78510
|
-
this.
|
|
78511
|
-
this.
|
|
78512
|
-
|
|
78513
|
-
if (groundY !== null) {
|
|
78901
|
+
this._hasSpawn = false;
|
|
78902
|
+
if (this._findSpawnPosition(camera.position, spawnProbe)) {
|
|
78903
|
+
this._position.copy(spawnProbe);
|
|
78514
78904
|
this._grounded = true;
|
|
78515
78905
|
this._velocity.y = 0;
|
|
78516
|
-
this.
|
|
78517
|
-
this.
|
|
78906
|
+
this._resolveSpawnCollision();
|
|
78907
|
+
this._storeSpawn();
|
|
78518
78908
|
}
|
|
78909
|
+
this._prevPosition.copy(this._position);
|
|
78519
78910
|
}
|
|
78520
78911
|
}
|
|
78521
78912
|
update(deltaTime, inputFrame, camera) {
|
|
78522
78913
|
const { move, rotate } = inputFrame.read();
|
|
78523
78914
|
// apply rotation at display rate for responsive mouse look
|
|
78524
|
-
this._angles
|
|
78525
|
-
this._angles.x = math.clamp(this._angles.x, -90, 90);
|
|
78915
|
+
applyFrameRotation(this._angles, rotate);
|
|
78526
78916
|
// accumulate movement input so frames without a physics step don't lose input
|
|
78527
78917
|
this._pendingMove[0] += move[0];
|
|
78528
78918
|
this._pendingMove[1] = this._pendingMove[1] || move[1];
|
|
@@ -78546,6 +78936,7 @@ class WalkController {
|
|
|
78546
78936
|
const alpha = this._accumulator / FIXED_DT;
|
|
78547
78937
|
camera.position.lerp(this._prevPosition, this._position, alpha);
|
|
78548
78938
|
camera.angles.set(this._angles.x, this._angles.y, 0);
|
|
78939
|
+
camera.distance = this._distance;
|
|
78549
78940
|
camera.fov = this.fov;
|
|
78550
78941
|
}
|
|
78551
78942
|
_step(dt, move) {
|
|
@@ -78588,12 +78979,8 @@ class WalkController {
|
|
|
78588
78979
|
this._grounded = false;
|
|
78589
78980
|
}
|
|
78590
78981
|
// move
|
|
78591
|
-
|
|
78592
|
-
|
|
78593
|
-
rotation.transformVector(Vec3.RIGHT, right$1);
|
|
78594
|
-
offset.set(0, 0, 0);
|
|
78595
|
-
offset.add(forward.mulScalar(move[2]));
|
|
78596
|
-
offset.add(right$1.mulScalar(move[0]));
|
|
78982
|
+
setYawBasis(this._angles.y, forward, right$1);
|
|
78983
|
+
setBasisOffset(offset, move[0], 0, move[2], forward, right$1, Vec3.UP);
|
|
78597
78984
|
this._velocity.add(offset.mulScalar(this._grounded ? this.moveGroundSpeed : this.moveAirSpeed));
|
|
78598
78985
|
const dampFactor = this._grounded ? this.velocityDampingGround : this.velocityDampingAir;
|
|
78599
78986
|
const alpha = damp(dampFactor, dt);
|
|
@@ -78617,36 +79004,193 @@ class WalkController {
|
|
|
78617
79004
|
this._prevPosition.copy(this._position);
|
|
78618
79005
|
// angles (clamp pitch to avoid gimbal lock)
|
|
78619
79006
|
this._angles.set(camera.angles.x, camera.angles.y, 0);
|
|
79007
|
+
this._distance = camera.distance;
|
|
78620
79008
|
// reset velocity and state
|
|
79009
|
+
this._resetMotion();
|
|
79010
|
+
}
|
|
79011
|
+
/**
|
|
79012
|
+
* Reset the controller to the spawn pose captured on the last walk-mode entry.
|
|
79013
|
+
*
|
|
79014
|
+
* @param camera - Camera state to update with the spawn pose.
|
|
79015
|
+
* @returns True if a spawn pose was available.
|
|
79016
|
+
*/
|
|
79017
|
+
resetToSpawn(camera) {
|
|
79018
|
+
if (!this._hasSpawn) {
|
|
79019
|
+
return false;
|
|
79020
|
+
}
|
|
79021
|
+
this._position.copy(this._spawnPosition);
|
|
79022
|
+
this._prevPosition.copy(this._position);
|
|
79023
|
+
this._angles.copy(this._spawnAngles);
|
|
79024
|
+
this._distance = this._spawnDistance;
|
|
79025
|
+
this._resetMotion();
|
|
79026
|
+
this._grounded = this._spawnGrounded;
|
|
79027
|
+
camera.position.copy(this._position);
|
|
79028
|
+
camera.angles.copy(this._angles);
|
|
79029
|
+
camera.distance = this._distance;
|
|
79030
|
+
camera.fov = this.fov;
|
|
79031
|
+
return true;
|
|
79032
|
+
}
|
|
79033
|
+
_storeSpawn() {
|
|
79034
|
+
this._spawnPosition.copy(this._position);
|
|
79035
|
+
this._spawnAngles.copy(this._angles);
|
|
79036
|
+
this._spawnDistance = this._distance;
|
|
79037
|
+
this._spawnGrounded = this._grounded;
|
|
79038
|
+
this._hasSpawn = true;
|
|
79039
|
+
}
|
|
79040
|
+
_resetMotion() {
|
|
78621
79041
|
this._velocity.set(0, 0, 0);
|
|
78622
79042
|
this._grounded = false;
|
|
78623
79043
|
this._jumping = false;
|
|
79044
|
+
this._jumpHeld = false;
|
|
78624
79045
|
this._pendingMove[0] = 0;
|
|
78625
79046
|
this._pendingMove[1] = 0;
|
|
78626
79047
|
this._pendingMove[2] = 0;
|
|
78627
79048
|
this._accumulator = 0;
|
|
78628
79049
|
}
|
|
78629
79050
|
/**
|
|
78630
|
-
*
|
|
78631
|
-
*
|
|
78632
|
-
* activates inside a solid region. Per-frame collision resolution is unaffected,
|
|
78633
|
-
* avoiding the ceiling launch bug.
|
|
79051
|
+
* Resolve the capsule out of solid geometry at spawn time. This is only used
|
|
79052
|
+
* when walk mode activates inside collision.
|
|
78634
79053
|
*/
|
|
78635
79054
|
_resolveSpawnCollision() {
|
|
78636
|
-
const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
|
|
78637
|
-
const minStep = this.capsuleRadius;
|
|
78638
79055
|
for (let i = 0; i < 100; i++) {
|
|
78639
|
-
|
|
78640
|
-
if (!this.collision.queryCapsule(this._position.x, center, this._position.z, half, this.capsuleRadius, out)) {
|
|
79056
|
+
if (!this._queryCapsule(this._position)) {
|
|
78641
79057
|
break;
|
|
78642
79058
|
}
|
|
78643
|
-
this._position.
|
|
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;
|
|
78644
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);
|
|
78645
79189
|
}
|
|
78646
79190
|
/**
|
|
78647
79191
|
* Cast multiple rays downward to find the average ground surface height.
|
|
78648
79192
|
* Uses 5 rays (center + 4 cardinal at capsule radius) to spatially filter
|
|
78649
|
-
* noisy
|
|
79193
|
+
* noisy collision heights, giving the spring a smoother target.
|
|
78650
79194
|
*
|
|
78651
79195
|
* @param pos - Eye position in PlayCanvas world space.
|
|
78652
79196
|
* @returns Average ground surface Y in PlayCanvas space, or null if no ground found.
|
|
@@ -78704,7 +79248,6 @@ class WalkController {
|
|
|
78704
79248
|
}
|
|
78705
79249
|
}
|
|
78706
79250
|
|
|
78707
|
-
const RAD_TO_DEG = 180 / Math.PI;
|
|
78708
79251
|
/** XZ distance below which the walker considers itself arrived */
|
|
78709
79252
|
const ARRIVAL_DIST = 0.5;
|
|
78710
79253
|
/** Minimum XZ speed (m/s) to not count as blocked */
|
|
@@ -78741,8 +79284,7 @@ class WalkSource {
|
|
|
78741
79284
|
onComplete = null;
|
|
78742
79285
|
_target = null;
|
|
78743
79286
|
_yawRate = 0;
|
|
78744
|
-
|
|
78745
|
-
_prevDist = Infinity;
|
|
79287
|
+
_progress = new ProgressTracker();
|
|
78746
79288
|
get isWalking() {
|
|
78747
79289
|
return this._target !== null;
|
|
78748
79290
|
}
|
|
@@ -78756,8 +79298,7 @@ class WalkSource {
|
|
|
78756
79298
|
this._target = new Vec3();
|
|
78757
79299
|
}
|
|
78758
79300
|
this._target.copy(target);
|
|
78759
|
-
this.
|
|
78760
|
-
this._prevDist = Infinity;
|
|
79301
|
+
this._progress.reset();
|
|
78761
79302
|
}
|
|
78762
79303
|
/**
|
|
78763
79304
|
* Cancel any active auto-walk.
|
|
@@ -78766,7 +79307,7 @@ class WalkSource {
|
|
|
78766
79307
|
if (this._target) {
|
|
78767
79308
|
this._target = null;
|
|
78768
79309
|
this._yawRate = 0;
|
|
78769
|
-
this.
|
|
79310
|
+
this._progress.reset();
|
|
78770
79311
|
this.onComplete?.();
|
|
78771
79312
|
}
|
|
78772
79313
|
}
|
|
@@ -78792,29 +79333,17 @@ class WalkSource {
|
|
|
78792
79333
|
return;
|
|
78793
79334
|
}
|
|
78794
79335
|
// blocked detection: compare with previous frame's distance
|
|
78795
|
-
if (this.
|
|
78796
|
-
|
|
78797
|
-
|
|
78798
|
-
this._blockedTime += dt;
|
|
78799
|
-
if (this._blockedTime >= BLOCKED_DURATION) {
|
|
78800
|
-
this.cancelWalk();
|
|
78801
|
-
return;
|
|
78802
|
-
}
|
|
78803
|
-
}
|
|
78804
|
-
else {
|
|
78805
|
-
this._blockedTime = 0;
|
|
78806
|
-
}
|
|
79336
|
+
if (this._progress.update(xzDist, dt, BLOCKED_SPEED, BLOCKED_DURATION)) {
|
|
79337
|
+
this.cancelWalk();
|
|
79338
|
+
return;
|
|
78807
79339
|
}
|
|
78808
|
-
this._prevDist = xzDist;
|
|
78809
79340
|
// yaw toward target with smoothed turn rate
|
|
78810
|
-
const
|
|
78811
|
-
|
|
78812
|
-
|
|
78813
|
-
|
|
78814
|
-
const smoothing = 1 - Math.exp(-4 * this.turnGain * dt);
|
|
78815
|
-
this._yawRate += (desiredRate - this._yawRate) * smoothing;
|
|
79341
|
+
const yawDiff = getYawDiffToTarget(dx, dz, cameraAngles.y);
|
|
79342
|
+
this._yawRate = smoothTurnRate(this._yawRate, yawDiff, this.maxTurnRate, this.turnGain, dt);
|
|
79343
|
+
const yawStep = clampTurnStep(this._yawRate, yawDiff, dt);
|
|
79344
|
+
this._yawRate = dt > 0 ? yawStep / dt : this._yawRate;
|
|
78816
79345
|
// WalkController applies: _angles.y += -rotate[0]
|
|
78817
|
-
frame.deltas.rotate.append([-
|
|
79346
|
+
frame.deltas.rotate.append([-yawStep, 0, 0]);
|
|
78818
79347
|
// scale forward speed by alignment: turn in place first, then accelerate
|
|
78819
79348
|
const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
|
|
78820
79349
|
frame.deltas.move.append([0, 0, this.walkSpeed * dt * alignment]);
|
|
@@ -78879,6 +79408,10 @@ class CameraManager {
|
|
|
78879
79408
|
walkSource.onComplete = () => {
|
|
78880
79409
|
events.fire('walkComplete');
|
|
78881
79410
|
};
|
|
79411
|
+
const flySource = new FlySource();
|
|
79412
|
+
flySource.onComplete = () => {
|
|
79413
|
+
events.fire('flyComplete');
|
|
79414
|
+
};
|
|
78882
79415
|
const getController = (cameraMode) => {
|
|
78883
79416
|
return controllers[cameraMode];
|
|
78884
79417
|
};
|
|
@@ -78899,6 +79432,7 @@ class CameraManager {
|
|
|
78899
79432
|
// transition state
|
|
78900
79433
|
const transitionSpeed = 1.0;
|
|
78901
79434
|
let transitionTimer = 1;
|
|
79435
|
+
let clearOrbitTargetOnTransitionEnd = false;
|
|
78902
79436
|
// start a new camera transition from the current pose
|
|
78903
79437
|
const startTransition = () => {
|
|
78904
79438
|
from.copy(this.camera);
|
|
@@ -78909,11 +79443,15 @@ class CameraManager {
|
|
|
78909
79443
|
// use dt of 0 if animation is paused
|
|
78910
79444
|
const dt = state.cameraMode === 'anim' && state.animationPaused ? 0 : deltaTime;
|
|
78911
79445
|
// update transition timer
|
|
79446
|
+
const prevTransitionTimer = transitionTimer;
|
|
78912
79447
|
transitionTimer = Math.min(1, transitionTimer + deltaTime * transitionSpeed);
|
|
78913
79448
|
const controller = getController(state.cameraMode);
|
|
78914
79449
|
if (state.cameraMode === 'walk') {
|
|
78915
79450
|
walkSource.update(dt, this.camera.position, this.camera.angles, frame);
|
|
78916
79451
|
}
|
|
79452
|
+
else if (state.cameraMode === 'fly') {
|
|
79453
|
+
flySource.update(dt, this.camera.position, this.camera.angles, this.camera.fov, frame);
|
|
79454
|
+
}
|
|
78917
79455
|
controller.update(dt, frame, target);
|
|
78918
79456
|
if (transitionTimer < 1) {
|
|
78919
79457
|
// lerp away from previous camera during transition
|
|
@@ -78926,19 +79464,38 @@ class CameraManager {
|
|
|
78926
79464
|
if (state.cameraMode === 'anim') {
|
|
78927
79465
|
state.animationTime = controllers.anim.animState.cursor.value;
|
|
78928
79466
|
}
|
|
79467
|
+
if (clearOrbitTargetOnTransitionEnd && prevTransitionTimer < 1 && transitionTimer === 1) {
|
|
79468
|
+
clearOrbitTargetOnTransitionEnd = false;
|
|
79469
|
+
events.fire('orbitTarget:clear');
|
|
79470
|
+
}
|
|
78929
79471
|
};
|
|
78930
79472
|
// handle input events
|
|
78931
|
-
events.on('inputEvent', (eventName
|
|
79473
|
+
events.on('inputEvent', (eventName) => {
|
|
78932
79474
|
switch (eventName) {
|
|
78933
79475
|
case 'frame':
|
|
79476
|
+
events.fire('orbitTarget:clear');
|
|
78934
79477
|
state.cameraMode = 'orbit';
|
|
78935
79478
|
controllers.orbit.goto(frameCamera);
|
|
78936
79479
|
startTransition();
|
|
78937
79480
|
break;
|
|
78938
79481
|
case 'reset':
|
|
78939
|
-
state.cameraMode
|
|
78940
|
-
|
|
78941
|
-
|
|
79482
|
+
if (state.cameraMode === 'walk') {
|
|
79483
|
+
walkSource.cancelWalk();
|
|
79484
|
+
events.fire('walkTarget:clear');
|
|
79485
|
+
startTransition();
|
|
79486
|
+
controllers.walk.resetToSpawn(target);
|
|
79487
|
+
}
|
|
79488
|
+
else if (state.cameraMode === 'fly') {
|
|
79489
|
+
flySource.cancelFly();
|
|
79490
|
+
startTransition();
|
|
79491
|
+
controllers.fly.resetToSpawn(target);
|
|
79492
|
+
}
|
|
79493
|
+
else {
|
|
79494
|
+
events.fire('orbitTarget:clear');
|
|
79495
|
+
state.cameraMode = 'orbit';
|
|
79496
|
+
controllers.orbit.goto(resetCamera);
|
|
79497
|
+
startTransition();
|
|
79498
|
+
}
|
|
78942
79499
|
break;
|
|
78943
79500
|
case 'playPause':
|
|
78944
79501
|
if (state.hasAnimation) {
|
|
@@ -78987,6 +79544,9 @@ class CameraManager {
|
|
|
78987
79544
|
if (prev === 'walk') {
|
|
78988
79545
|
walkSource.cancelWalk();
|
|
78989
79546
|
}
|
|
79547
|
+
else if (prev === 'fly') {
|
|
79548
|
+
flySource.cancelFly();
|
|
79549
|
+
}
|
|
78990
79550
|
// snapshot the current pose before any controller mutation
|
|
78991
79551
|
startTransition();
|
|
78992
79552
|
target.copy(this.camera);
|
|
@@ -79014,8 +79574,10 @@ class CameraManager {
|
|
|
79014
79574
|
tmpCamera.look(this.camera.position, position);
|
|
79015
79575
|
controllers.orbit.goto(tmpCamera);
|
|
79016
79576
|
startTransition();
|
|
79577
|
+
clearOrbitTargetOnTransitionEnd = true;
|
|
79017
79578
|
});
|
|
79018
79579
|
events.on('annotation.activate', (annotation) => {
|
|
79580
|
+
events.fire('orbitTarget:clear');
|
|
79019
79581
|
// switch to orbit camera on pick
|
|
79020
79582
|
state.cameraMode = 'orbit';
|
|
79021
79583
|
const { initial } = annotation.camera;
|
|
@@ -79040,6 +79602,21 @@ class CameraManager {
|
|
|
79040
79602
|
events.on('walkComplete', () => {
|
|
79041
79603
|
events.fire('walkTarget:clear');
|
|
79042
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);
|
|
79610
|
+
}
|
|
79611
|
+
});
|
|
79612
|
+
// cancel any active auto-flight
|
|
79613
|
+
events.on('flyCancel', () => {
|
|
79614
|
+
flySource.cancelFly();
|
|
79615
|
+
events.fire('flyTarget:clear');
|
|
79616
|
+
});
|
|
79617
|
+
events.on('flyComplete', () => {
|
|
79618
|
+
events.fire('flyTarget:clear');
|
|
79619
|
+
});
|
|
79043
79620
|
}
|
|
79044
79621
|
}
|
|
79045
79622
|
|
|
@@ -79066,6 +79643,11 @@ class InputModeTracker {
|
|
|
79066
79643
|
}
|
|
79067
79644
|
}
|
|
79068
79645
|
|
|
79646
|
+
const isCaptureMode$1 = (mode) => mode === 'walk' || mode === 'fly';
|
|
79647
|
+
const isWasdKey = (event) => (event.code === 'KeyW' ||
|
|
79648
|
+
event.code === 'KeyA' ||
|
|
79649
|
+
event.code === 'KeyS' ||
|
|
79650
|
+
event.code === 'KeyD');
|
|
79069
79651
|
/**
|
|
79070
79652
|
* Keyboard shortcuts that switch camera mode and toggle UI affordances.
|
|
79071
79653
|
* Listens on `window` so the user can press 1/2/3, V, G, H, F, R, Space,
|
|
@@ -79080,8 +79662,8 @@ class ModeShortcuts {
|
|
|
79080
79662
|
return;
|
|
79081
79663
|
const { state, events } = global;
|
|
79082
79664
|
if (event.key === 'Escape') {
|
|
79083
|
-
if (this._pointerLock?.
|
|
79084
|
-
else if (state.cameraMode
|
|
79665
|
+
if (this._pointerLock?.recentlyExitedCapture) ;
|
|
79666
|
+
else if (isCaptureMode$1(state.cameraMode) && state.gamingControls && state.inputMode === 'desktop') {
|
|
79085
79667
|
state.gamingControls = false;
|
|
79086
79668
|
}
|
|
79087
79669
|
else if (state.cameraMode === 'walk') {
|
|
@@ -79116,10 +79698,17 @@ class ModeShortcuts {
|
|
|
79116
79698
|
case 'h':
|
|
79117
79699
|
events.fire('inputEvent', 'toggleHelp');
|
|
79118
79700
|
break;
|
|
79701
|
+
case 'r':
|
|
79702
|
+
events.fire('inputEvent', 'reset', event);
|
|
79703
|
+
break;
|
|
79119
79704
|
default:
|
|
79120
|
-
if ((event
|
|
79121
|
-
|
|
79122
|
-
|
|
79705
|
+
if (isWasdKey(event) && state.inputMode === 'desktop') {
|
|
79706
|
+
if (!isCaptureMode$1(state.cameraMode)) {
|
|
79707
|
+
state.cameraMode = 'fly';
|
|
79708
|
+
}
|
|
79709
|
+
if (!state.gamingControls) {
|
|
79710
|
+
state.gamingControls = true;
|
|
79711
|
+
}
|
|
79123
79712
|
}
|
|
79124
79713
|
break;
|
|
79125
79714
|
}
|
|
@@ -79128,9 +79717,6 @@ class ModeShortcuts {
|
|
|
79128
79717
|
case 'f':
|
|
79129
79718
|
events.fire('inputEvent', 'frame', event);
|
|
79130
79719
|
break;
|
|
79131
|
-
case 'r':
|
|
79132
|
-
events.fire('inputEvent', 'reset', event);
|
|
79133
|
-
break;
|
|
79134
79720
|
case ' ':
|
|
79135
79721
|
events.fire('inputEvent', 'playPause', event);
|
|
79136
79722
|
break;
|
|
@@ -79149,34 +79735,35 @@ class ModeShortcuts {
|
|
|
79149
79735
|
}
|
|
79150
79736
|
}
|
|
79151
79737
|
|
|
79738
|
+
const isCaptureMode = (mode) => mode === 'walk' || mode === 'fly';
|
|
79739
|
+
const hasUserActivation = () => (navigator.userActivation?.isActive === true);
|
|
79152
79740
|
/**
|
|
79153
|
-
* Manages the browser's pointer-lock API for
|
|
79154
|
-
* on desktop. Toggles in response to
|
|
79155
|
-
*
|
|
79156
|
-
* rejected.
|
|
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.
|
|
79157
79744
|
*
|
|
79158
|
-
* Also exposes `
|
|
79745
|
+
* Also exposes `recentlyExitedCapture` so the keyboard-shortcut handler can
|
|
79159
79746
|
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
79160
79747
|
*/
|
|
79161
79748
|
class PointerLockManager {
|
|
79162
79749
|
_global = null;
|
|
79163
79750
|
_canvas = null;
|
|
79164
79751
|
_keyboardMouse = null;
|
|
79165
|
-
|
|
79752
|
+
_recentlyExitedCapture = false;
|
|
79166
79753
|
_onPointerLockChange = () => {
|
|
79167
79754
|
const global = this._global;
|
|
79168
79755
|
if (!global)
|
|
79169
79756
|
return;
|
|
79170
79757
|
const { state, events } = global;
|
|
79171
|
-
if (!document.pointerLockElement && state.cameraMode
|
|
79172
|
-
this.
|
|
79758
|
+
if (!document.pointerLockElement && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
79759
|
+
this._recentlyExitedCapture = true;
|
|
79173
79760
|
requestAnimationFrame(() => {
|
|
79174
|
-
this.
|
|
79761
|
+
this._recentlyExitedCapture = false;
|
|
79175
79762
|
});
|
|
79176
79763
|
if (state.inputMode === 'desktop') {
|
|
79177
79764
|
state.gamingControls = false;
|
|
79178
79765
|
}
|
|
79179
|
-
else {
|
|
79766
|
+
else if (state.cameraMode === 'walk') {
|
|
79180
79767
|
events.fire('inputEvent', 'exitWalk');
|
|
79181
79768
|
}
|
|
79182
79769
|
}
|
|
@@ -79192,10 +79779,10 @@ class PointerLockManager {
|
|
|
79192
79779
|
if (!global)
|
|
79193
79780
|
return;
|
|
79194
79781
|
const { state, events } = global;
|
|
79195
|
-
if (state.inputMode === 'desktop') {
|
|
79782
|
+
if (state.inputMode === 'desktop' && isCaptureMode(state.cameraMode)) {
|
|
79196
79783
|
state.gamingControls = false;
|
|
79197
79784
|
}
|
|
79198
|
-
else {
|
|
79785
|
+
else if (state.cameraMode === 'walk') {
|
|
79199
79786
|
events.fire('inputEvent', 'exitWalk');
|
|
79200
79787
|
}
|
|
79201
79788
|
};
|
|
@@ -79203,10 +79790,10 @@ class PointerLockManager {
|
|
|
79203
79790
|
const state = this._global?.state;
|
|
79204
79791
|
if (!state)
|
|
79205
79792
|
return;
|
|
79206
|
-
if (value
|
|
79793
|
+
if (isCaptureMode(value) && state.inputMode === 'desktop' && state.gamingControls) {
|
|
79207
79794
|
this._activate();
|
|
79208
79795
|
}
|
|
79209
|
-
else if (prev
|
|
79796
|
+
else if (isCaptureMode(prev)) {
|
|
79210
79797
|
this._deactivate();
|
|
79211
79798
|
}
|
|
79212
79799
|
};
|
|
@@ -79214,7 +79801,7 @@ class PointerLockManager {
|
|
|
79214
79801
|
const state = this._global?.state;
|
|
79215
79802
|
if (!state)
|
|
79216
79803
|
return;
|
|
79217
|
-
if (state.cameraMode
|
|
79804
|
+
if (isCaptureMode(state.cameraMode) && state.inputMode === 'desktop') {
|
|
79218
79805
|
if (value) {
|
|
79219
79806
|
this._activate();
|
|
79220
79807
|
}
|
|
@@ -79223,11 +79810,31 @@ class PointerLockManager {
|
|
|
79223
79810
|
}
|
|
79224
79811
|
}
|
|
79225
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
|
+
};
|
|
79226
79831
|
_activate() {
|
|
79227
79832
|
if (this._keyboardMouse) {
|
|
79228
79833
|
this._keyboardMouse.source._pointerLock = true;
|
|
79229
79834
|
}
|
|
79230
|
-
this._canvas
|
|
79835
|
+
if (document.pointerLockElement !== this._canvas) {
|
|
79836
|
+
this._canvas?.requestPointerLock();
|
|
79837
|
+
}
|
|
79231
79838
|
}
|
|
79232
79839
|
_deactivate() {
|
|
79233
79840
|
if (this._keyboardMouse) {
|
|
@@ -79237,8 +79844,8 @@ class PointerLockManager {
|
|
|
79237
79844
|
document.exitPointerLock();
|
|
79238
79845
|
}
|
|
79239
79846
|
}
|
|
79240
|
-
get
|
|
79241
|
-
return this.
|
|
79847
|
+
get recentlyExitedCapture() {
|
|
79848
|
+
return this._recentlyExitedCapture;
|
|
79242
79849
|
}
|
|
79243
79850
|
attach(canvas, global, keyboardMouse) {
|
|
79244
79851
|
this._canvas = canvas;
|
|
@@ -79247,6 +79854,8 @@ class PointerLockManager {
|
|
|
79247
79854
|
const { events } = global;
|
|
79248
79855
|
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
79249
79856
|
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
79857
|
+
events.on('inputMode:changed', this._onInputModeChanged);
|
|
79858
|
+
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79250
79859
|
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79251
79860
|
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
79252
79861
|
}
|
|
@@ -79255,7 +79864,9 @@ class PointerLockManager {
|
|
|
79255
79864
|
const { events } = this._global;
|
|
79256
79865
|
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
79257
79866
|
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
79867
|
+
events.off('inputMode:changed', this._onInputModeChanged);
|
|
79258
79868
|
}
|
|
79869
|
+
this._canvas?.removeEventListener('pointerdown', this._onPointerDown);
|
|
79259
79870
|
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79260
79871
|
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
79261
79872
|
this._canvas = null;
|
|
@@ -79264,353 +79875,6 @@ class PointerLockManager {
|
|
|
79264
79875
|
}
|
|
79265
79876
|
}
|
|
79266
79877
|
|
|
79267
|
-
/**
|
|
79268
|
-
* Double-click world picking for splat scenes.
|
|
79269
|
-
*
|
|
79270
|
-
* - **Compute renderer (WebGPU tiled-compute)**: uses engine `Picker` with depth enabled — expected
|
|
79271
|
-
* depth is already provided by the tile-composite path.
|
|
79272
|
-
* - **Raster renderers (WebGL, CPU / GPU sort, etc.)**: custom `pickPS` / `gsplatPS` patch plus
|
|
79273
|
-
* `RGBA16F` alpha-weighted depth accumulation, because the stock pick pass encodes splat IDs /
|
|
79274
|
-
* last-fragment depth rather than expected depth.
|
|
79275
|
-
*/
|
|
79276
|
-
// Override global picking to pack alpha-weighted splat depth instead of meshInstance id.
|
|
79277
|
-
const pickDepthGlsl = /* glsl */ `
|
|
79278
|
-
vec4 encodePickOutput(uint id) {
|
|
79279
|
-
const vec4 inv = vec4(1.0 / 255.0);
|
|
79280
|
-
const uvec4 shifts = uvec4(16, 8, 0, 24);
|
|
79281
|
-
uvec4 col = (uvec4(id) >> shifts) & uvec4(0xff);
|
|
79282
|
-
return vec4(col) * inv;
|
|
79283
|
-
}
|
|
79284
|
-
|
|
79285
|
-
#ifdef GSPLAT_PICK_DEPTH
|
|
79286
|
-
#ifndef CAMERAPLANES
|
|
79287
|
-
#define CAMERAPLANES
|
|
79288
|
-
uniform vec4 camera_params; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79289
|
-
#endif
|
|
79290
|
-
|
|
79291
|
-
vec4 getPickOutput() {
|
|
79292
|
-
float normalizedDepth;
|
|
79293
|
-
if (camera_params.w > 0.5) {
|
|
79294
|
-
normalizedDepth = gl_FragCoord.z;
|
|
79295
|
-
} else {
|
|
79296
|
-
float linearDepth = 1.0 / gl_FragCoord.w;
|
|
79297
|
-
normalizedDepth = (linearDepth - camera_params.z) / (camera_params.y - camera_params.z);
|
|
79298
|
-
}
|
|
79299
|
-
|
|
79300
|
-
return vec4(gaussianColor.a * normalizedDepth, 0.0, 0.0, gaussianColor.a);
|
|
79301
|
-
}
|
|
79302
|
-
#else
|
|
79303
|
-
#ifndef PICK_CUSTOM_ID
|
|
79304
|
-
uniform uint meshInstanceId;
|
|
79305
|
-
|
|
79306
|
-
vec4 getPickOutput() {
|
|
79307
|
-
return encodePickOutput(meshInstanceId);
|
|
79308
|
-
}
|
|
79309
|
-
#endif
|
|
79310
|
-
#endif
|
|
79311
|
-
|
|
79312
|
-
#ifdef DEPTH_PICK_PASS
|
|
79313
|
-
#include "floatAsUintPS"
|
|
79314
|
-
#ifndef CAMERAPLANES
|
|
79315
|
-
#define CAMERAPLANES
|
|
79316
|
-
uniform vec4 camera_params; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79317
|
-
#endif
|
|
79318
|
-
|
|
79319
|
-
vec4 getPickDepth() {
|
|
79320
|
-
float linearDepth;
|
|
79321
|
-
if (camera_params.w > 0.5) {
|
|
79322
|
-
linearDepth = gl_FragCoord.z;
|
|
79323
|
-
} else {
|
|
79324
|
-
float viewDist = 1.0 / gl_FragCoord.w;
|
|
79325
|
-
linearDepth = (viewDist - camera_params.z) / (camera_params.y - camera_params.z);
|
|
79326
|
-
}
|
|
79327
|
-
return float2uint(linearDepth);
|
|
79328
|
-
}
|
|
79329
|
-
#endif
|
|
79330
|
-
`;
|
|
79331
|
-
const pickDepthWgsl = /* wgsl */ `
|
|
79332
|
-
fn encodePickOutput(id: u32) -> vec4f {
|
|
79333
|
-
let inv: vec4f = vec4f(1.0 / 255.0);
|
|
79334
|
-
let shifts: vec4u = vec4u(16u, 8u, 0u, 24u);
|
|
79335
|
-
let col: vec4u = (vec4u(id) >> shifts) & vec4u(0xffu);
|
|
79336
|
-
return vec4f(col) * inv;
|
|
79337
|
-
}
|
|
79338
|
-
|
|
79339
|
-
#ifdef GSPLAT_PICK_DEPTH
|
|
79340
|
-
#ifndef CAMERAPLANES
|
|
79341
|
-
#define CAMERAPLANES
|
|
79342
|
-
uniform camera_params: vec4f; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79343
|
-
#endif
|
|
79344
|
-
|
|
79345
|
-
fn getPickOutput() -> vec4f {
|
|
79346
|
-
var normalizedDepth: f32;
|
|
79347
|
-
if (uniform.camera_params.w > 0.5) {
|
|
79348
|
-
normalizedDepth = pcPosition.z;
|
|
79349
|
-
} else {
|
|
79350
|
-
let linearDepth = 1.0 / pcPosition.w;
|
|
79351
|
-
normalizedDepth = (linearDepth - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
|
|
79352
|
-
}
|
|
79353
|
-
|
|
79354
|
-
let a = f32(gaussianColor.a);
|
|
79355
|
-
return vec4f(a * normalizedDepth, 0.0, 0.0, a);
|
|
79356
|
-
}
|
|
79357
|
-
#else
|
|
79358
|
-
#ifndef PICK_CUSTOM_ID
|
|
79359
|
-
uniform meshInstanceId: u32;
|
|
79360
|
-
|
|
79361
|
-
fn getPickOutput() -> vec4f {
|
|
79362
|
-
return encodePickOutput(uniform.meshInstanceId);
|
|
79363
|
-
}
|
|
79364
|
-
#endif
|
|
79365
|
-
#endif
|
|
79366
|
-
|
|
79367
|
-
#ifdef DEPTH_PICK_PASS
|
|
79368
|
-
#include "floatAsUintPS"
|
|
79369
|
-
#ifndef CAMERAPLANES
|
|
79370
|
-
#define CAMERAPLANES
|
|
79371
|
-
uniform camera_params: vec4f; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79372
|
-
#endif
|
|
79373
|
-
|
|
79374
|
-
fn getPickDepth() -> vec4f {
|
|
79375
|
-
var linearDepth: f32;
|
|
79376
|
-
if (uniform.camera_params.w > 0.5) {
|
|
79377
|
-
linearDepth = pcPosition.z;
|
|
79378
|
-
} else {
|
|
79379
|
-
let viewDist = 1.0 / pcPosition.w;
|
|
79380
|
-
linearDepth = (viewDist - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
|
|
79381
|
-
}
|
|
79382
|
-
return float2uint(linearDepth);
|
|
79383
|
-
}
|
|
79384
|
-
#endif
|
|
79385
|
-
`;
|
|
79386
|
-
const pickPassChunkInjected = [
|
|
79387
|
-
'#ifdef PICK_PASS',
|
|
79388
|
-
' #define GSPLAT_PICK_DEPTH',
|
|
79389
|
-
' #include "pickPS"',
|
|
79390
|
-
'#endif'
|
|
79391
|
-
].join('\n');
|
|
79392
|
-
const safeChunkReplace = (s, find, repl) => {
|
|
79393
|
-
const out = s.replace(find, repl);
|
|
79394
|
-
if (out === s) {
|
|
79395
|
-
throw new Error('picker: engine gsplat/pick chunk patch failed (engine version mismatch?)');
|
|
79396
|
-
}
|
|
79397
|
-
return out;
|
|
79398
|
-
};
|
|
79399
|
-
const patchGsplatPickGlsl = (chunk) => {
|
|
79400
|
-
return safeChunkReplace(safeChunkReplace(chunk, /#ifdef PICK_PASS\s*#include "pickPS"\s*#endif/, pickPassChunkInjected), 'pcFragColor0 = encodePickOutput(vPickId);', 'pcFragColor0 = getPickOutput();');
|
|
79401
|
-
};
|
|
79402
|
-
const patchGsplatPickWgsl = (chunk) => {
|
|
79403
|
-
return safeChunkReplace(safeChunkReplace(chunk, /#ifdef PICK_PASS\s*#include "pickPS"\s*#endif/, pickPassChunkInjected), 'output.color = encodePickOutput(vPickId);', 'output.color = getPickOutput();');
|
|
79404
|
-
};
|
|
79405
|
-
/** Per-device original chunk strings + refcount so we can restore after the last Picker releases. */
|
|
79406
|
-
const pickerShaderPatchState = new WeakMap();
|
|
79407
|
-
const vec4 = new Vec4();
|
|
79408
|
-
const viewProjMat = new Mat4();
|
|
79409
|
-
const clearColor = new Color(0, 0, 0, 1);
|
|
79410
|
-
// Shared buffer for half-to-float conversion
|
|
79411
|
-
const float32 = new Float32Array(1);
|
|
79412
|
-
const uint32 = new Uint32Array(float32.buffer);
|
|
79413
|
-
// Convert 16-bit half-float to 32-bit float using bit manipulation.
|
|
79414
|
-
const half2Float = (h) => {
|
|
79415
|
-
const sign = (h & 0x8000) << 16;
|
|
79416
|
-
const exponent = (h & 0x7C00) >> 10;
|
|
79417
|
-
const mantissa = h & 0x03FF;
|
|
79418
|
-
if (exponent === 0) {
|
|
79419
|
-
if (mantissa === 0) {
|
|
79420
|
-
uint32[0] = sign;
|
|
79421
|
-
}
|
|
79422
|
-
else {
|
|
79423
|
-
let e = -1;
|
|
79424
|
-
let m = mantissa;
|
|
79425
|
-
do {
|
|
79426
|
-
e++;
|
|
79427
|
-
m <<= 1;
|
|
79428
|
-
} while ((m & 0x0400) === 0);
|
|
79429
|
-
uint32[0] = sign | ((127 - 15 - e) << 23) | ((m & 0x03FF) << 13);
|
|
79430
|
-
}
|
|
79431
|
-
}
|
|
79432
|
-
else if (exponent === 31) {
|
|
79433
|
-
uint32[0] = sign | 0x7F800000 | (mantissa << 13);
|
|
79434
|
-
}
|
|
79435
|
-
else {
|
|
79436
|
-
uint32[0] = sign | ((exponent + 127 - 15) << 23) | (mantissa << 13);
|
|
79437
|
-
}
|
|
79438
|
-
return float32[0];
|
|
79439
|
-
};
|
|
79440
|
-
const registerPickerShaderPatches = (app) => {
|
|
79441
|
-
const device = app.graphicsDevice;
|
|
79442
|
-
const existing = pickerShaderPatchState.get(device);
|
|
79443
|
-
if (existing) {
|
|
79444
|
-
existing.refCount++;
|
|
79445
|
-
return;
|
|
79446
|
-
}
|
|
79447
|
-
const glslChunks = ShaderChunks.get(device, 'glsl');
|
|
79448
|
-
const wgslChunks = ShaderChunks.get(device, 'wgsl');
|
|
79449
|
-
const glslPickPS = glslChunks.get('pickPS');
|
|
79450
|
-
const glslGsplatPS = glslChunks.get('gsplatPS');
|
|
79451
|
-
const wgslPickPS = wgslChunks.get('pickPS');
|
|
79452
|
-
const wgslGsplatPS = wgslChunks.get('gsplatPS');
|
|
79453
|
-
// Patch strings before mutating ShaderChunks so engine mismatches leave globals untouched.
|
|
79454
|
-
const patchedGlslGsplatPS = patchGsplatPickGlsl(glslGsplatPS);
|
|
79455
|
-
const patchedWgslGsplatPS = patchGsplatPickWgsl(wgslGsplatPS);
|
|
79456
|
-
const state = {
|
|
79457
|
-
glslPickPS,
|
|
79458
|
-
glslGsplatPS,
|
|
79459
|
-
wgslPickPS,
|
|
79460
|
-
wgslGsplatPS,
|
|
79461
|
-
refCount: 1
|
|
79462
|
-
};
|
|
79463
|
-
pickerShaderPatchState.set(device, state);
|
|
79464
|
-
glslChunks.set('pickPS', pickDepthGlsl);
|
|
79465
|
-
wgslChunks.set('pickPS', pickDepthWgsl);
|
|
79466
|
-
glslChunks.set('gsplatPS', patchedGlslGsplatPS);
|
|
79467
|
-
wgslChunks.set('gsplatPS', patchedWgslGsplatPS);
|
|
79468
|
-
};
|
|
79469
|
-
const unregisterPickerShaderPatches = (app) => {
|
|
79470
|
-
const device = app.graphicsDevice;
|
|
79471
|
-
const state = pickerShaderPatchState.get(device);
|
|
79472
|
-
if (!state) {
|
|
79473
|
-
return;
|
|
79474
|
-
}
|
|
79475
|
-
state.refCount--;
|
|
79476
|
-
if (state.refCount > 0) {
|
|
79477
|
-
return;
|
|
79478
|
-
}
|
|
79479
|
-
const glslChunks = ShaderChunks.get(device, 'glsl');
|
|
79480
|
-
const wgslChunks = ShaderChunks.get(device, 'wgsl');
|
|
79481
|
-
glslChunks.set('pickPS', state.glslPickPS);
|
|
79482
|
-
glslChunks.set('gsplatPS', state.glslGsplatPS);
|
|
79483
|
-
wgslChunks.set('pickPS', state.wgslPickPS);
|
|
79484
|
-
wgslChunks.set('gsplatPS', state.wgslGsplatPS);
|
|
79485
|
-
pickerShaderPatchState.delete(device);
|
|
79486
|
-
};
|
|
79487
|
-
const getWorldPoint = (camera, x, y, width, height, normalizedDepth) => {
|
|
79488
|
-
if (!Number.isFinite(normalizedDepth) || normalizedDepth < 0 || normalizedDepth > 1) {
|
|
79489
|
-
return null;
|
|
79490
|
-
}
|
|
79491
|
-
const cam = camera.camera;
|
|
79492
|
-
const far = cam.farClip;
|
|
79493
|
-
const near = cam.nearClip;
|
|
79494
|
-
const ndcDepth = cam.projection === PROJECTION_ORTHOGRAPHIC ?
|
|
79495
|
-
normalizedDepth :
|
|
79496
|
-
far * normalizedDepth / (normalizedDepth * (far - near) + near);
|
|
79497
|
-
viewProjMat.mul2(cam.projectionMatrix, cam.viewMatrix).invert();
|
|
79498
|
-
vec4.set(x / width * 2 - 1, (1 - y / height) * 2 - 1, ndcDepth * 2 - 1, 1);
|
|
79499
|
-
viewProjMat.transformVec4(vec4, vec4);
|
|
79500
|
-
if (!Number.isFinite(vec4.w) || Math.abs(vec4.w) < 1e-8) {
|
|
79501
|
-
return null;
|
|
79502
|
-
}
|
|
79503
|
-
vec4.mulScalar(1 / vec4.w);
|
|
79504
|
-
if (!Number.isFinite(vec4.x) || !Number.isFinite(vec4.y) || !Number.isFinite(vec4.z)) {
|
|
79505
|
-
return null;
|
|
79506
|
-
}
|
|
79507
|
-
return new Vec3(vec4.x, vec4.y, vec4.z);
|
|
79508
|
-
};
|
|
79509
|
-
class Picker {
|
|
79510
|
-
pick;
|
|
79511
|
-
release;
|
|
79512
|
-
constructor(app, camera) {
|
|
79513
|
-
const { graphicsDevice } = app;
|
|
79514
|
-
let enginePicker;
|
|
79515
|
-
let accumBuffer;
|
|
79516
|
-
let accumTarget;
|
|
79517
|
-
let accumPass;
|
|
79518
|
-
let chunksPatched = false;
|
|
79519
|
-
const initRasterAccum = (width, height) => {
|
|
79520
|
-
accumBuffer = new Texture(graphicsDevice, {
|
|
79521
|
-
format: PIXELFORMAT_RGBA16F,
|
|
79522
|
-
width,
|
|
79523
|
-
height,
|
|
79524
|
-
mipmaps: false,
|
|
79525
|
-
minFilter: FILTER_NEAREST,
|
|
79526
|
-
magFilter: FILTER_NEAREST,
|
|
79527
|
-
addressU: ADDRESS_CLAMP_TO_EDGE,
|
|
79528
|
-
addressV: ADDRESS_CLAMP_TO_EDGE,
|
|
79529
|
-
name: 'picker-accum'
|
|
79530
|
-
});
|
|
79531
|
-
accumTarget = new RenderTarget({
|
|
79532
|
-
colorBuffer: accumBuffer,
|
|
79533
|
-
depth: false // not needed — gaussians are rendered back to front
|
|
79534
|
-
});
|
|
79535
|
-
accumPass = new RenderPassPicker(graphicsDevice, app.renderer);
|
|
79536
|
-
// RGB: additive depth accumulation. Alpha: multiplicative transmittance.
|
|
79537
|
-
accumPass.blendState = new BlendState(true, BLENDEQUATION_ADD, BLENDMODE_ONE, BLENDMODE_ONE_MINUS_SRC_ALPHA, BLENDEQUATION_ADD, BLENDMODE_ZERO, BLENDMODE_ONE_MINUS_SRC_ALPHA);
|
|
79538
|
-
};
|
|
79539
|
-
const readTexture = (texture, x, y, target) => {
|
|
79540
|
-
const texY = graphicsDevice.isWebGL2 ? target.height - y - 1 : y;
|
|
79541
|
-
return texture.read(x, texY, 1, 1, {
|
|
79542
|
-
renderTarget: target,
|
|
79543
|
-
immediate: true
|
|
79544
|
-
});
|
|
79545
|
-
};
|
|
79546
|
-
this.pick = async (x, y) => {
|
|
79547
|
-
const width = Math.floor(graphicsDevice.width);
|
|
79548
|
-
const height = Math.floor(graphicsDevice.height);
|
|
79549
|
-
// bail out if the device hasn't been sized yet
|
|
79550
|
-
if (width <= 0 || height <= 0) {
|
|
79551
|
-
return null;
|
|
79552
|
-
}
|
|
79553
|
-
const screenX = Math.min(width - 1, Math.max(0, Math.floor(x * width)));
|
|
79554
|
-
const screenY = Math.min(height - 1, Math.max(0, Math.floor(y * height)));
|
|
79555
|
-
const worldLayer = app.scene.layers.getLayerByName('World');
|
|
79556
|
-
if (!worldLayer) {
|
|
79557
|
-
return null;
|
|
79558
|
-
}
|
|
79559
|
-
// enable gsplat IDs only for the duration of the pick so we don't pay the
|
|
79560
|
-
// memory/perf cost between picks (picker instances are typically long-lived).
|
|
79561
|
-
const prevEnableIds = app.scene.gsplat.enableIds;
|
|
79562
|
-
app.scene.gsplat.enableIds = true;
|
|
79563
|
-
try {
|
|
79564
|
-
if (app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE) {
|
|
79565
|
-
enginePicker ??= new Picker$1(app, 1, 1, true);
|
|
79566
|
-
enginePicker.resize(width, height);
|
|
79567
|
-
enginePicker.prepare(camera.camera, app.scene, [worldLayer]);
|
|
79568
|
-
return await enginePicker.getWorldPointAsync(screenX, screenY);
|
|
79569
|
-
}
|
|
79570
|
-
if (!chunksPatched) {
|
|
79571
|
-
registerPickerShaderPatches(app);
|
|
79572
|
-
chunksPatched = true;
|
|
79573
|
-
}
|
|
79574
|
-
if (!accumPass) {
|
|
79575
|
-
initRasterAccum(width, height);
|
|
79576
|
-
}
|
|
79577
|
-
else {
|
|
79578
|
-
accumTarget.resize(width, height);
|
|
79579
|
-
}
|
|
79580
|
-
accumPass.init(accumTarget);
|
|
79581
|
-
accumPass.setClearColor(clearColor);
|
|
79582
|
-
accumPass.update(camera.camera, app.scene, [worldLayer], new Map(), false);
|
|
79583
|
-
accumPass.render();
|
|
79584
|
-
const pixels = await readTexture(accumBuffer, screenX, screenY, accumTarget);
|
|
79585
|
-
const r = half2Float(pixels[0]);
|
|
79586
|
-
const transmittance = half2Float(pixels[3]);
|
|
79587
|
-
const alpha = 1 - transmittance;
|
|
79588
|
-
if (!Number.isFinite(r) || !Number.isFinite(alpha) || alpha < 1e-6) {
|
|
79589
|
-
return null;
|
|
79590
|
-
}
|
|
79591
|
-
const normalizedDepth = r / alpha;
|
|
79592
|
-
return getWorldPoint(camera, screenX, screenY, width, height, normalizedDepth);
|
|
79593
|
-
}
|
|
79594
|
-
finally {
|
|
79595
|
-
// Pick is only invoked from user dblclick events, so concurrent invocations
|
|
79596
|
-
// (which would race on enableIds) aren't a concern in practice.
|
|
79597
|
-
// eslint-disable-next-line require-atomic-updates
|
|
79598
|
-
app.scene.gsplat.enableIds = prevEnableIds;
|
|
79599
|
-
}
|
|
79600
|
-
};
|
|
79601
|
-
this.release = () => {
|
|
79602
|
-
if (chunksPatched) {
|
|
79603
|
-
unregisterPickerShaderPatches(app);
|
|
79604
|
-
chunksPatched = false;
|
|
79605
|
-
}
|
|
79606
|
-
enginePicker?.destroy();
|
|
79607
|
-
accumPass?.destroy();
|
|
79608
|
-
accumTarget?.destroy();
|
|
79609
|
-
accumBuffer?.destroy();
|
|
79610
|
-
};
|
|
79611
|
-
}
|
|
79612
|
-
}
|
|
79613
|
-
|
|
79614
79878
|
/**
|
|
79615
79879
|
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79616
79880
|
* pixel offsets that already scale with frame time. This factor converts
|
|
@@ -79664,35 +79928,48 @@ const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
|
|
|
79664
79928
|
const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
|
|
79665
79929
|
|
|
79666
79930
|
const tmpV$4 = new Vec3();
|
|
79931
|
+
const canTargetFly = (global) => (global.state.cameraMode === 'fly' &&
|
|
79932
|
+
!(global.state.inputMode === 'desktop' && global.state.gamingControls));
|
|
79667
79933
|
/**
|
|
79668
|
-
* Click-to-walk
|
|
79669
|
-
*
|
|
79670
|
-
*
|
|
79671
|
-
* camera manager to consume.
|
|
79934
|
+
* Click-to-walk / click-to-fly / click-to-focus (desktop), tap equivalents
|
|
79935
|
+
* on mobile, and double-click-to-pick fallback. Uses collision first and
|
|
79936
|
+
* rendered-scene picking when collision is unavailable.
|
|
79672
79937
|
*/
|
|
79673
79938
|
class WalkInteraction {
|
|
79674
79939
|
collision = null;
|
|
79940
|
+
_picker;
|
|
79675
79941
|
_global = null;
|
|
79676
79942
|
_canvas = null;
|
|
79677
|
-
_picker = null;
|
|
79678
79943
|
_lastPointerOffsetX = 0;
|
|
79679
79944
|
_lastPointerOffsetY = 0;
|
|
79680
79945
|
_mouseClickTracking = false;
|
|
79681
79946
|
_mouseClickDelta = 0;
|
|
79947
|
+
_suppressClick = false;
|
|
79948
|
+
_targetPickRequest = 0;
|
|
79682
79949
|
_lastTap = { time: 0, x: 0, y: 0 };
|
|
79950
|
+
constructor(picker) {
|
|
79951
|
+
this._picker = picker;
|
|
79952
|
+
}
|
|
79683
79953
|
_updateCursor = () => {
|
|
79684
79954
|
const global = this._global;
|
|
79685
79955
|
const canvas = this._canvas;
|
|
79686
79956
|
if (!global || !canvas)
|
|
79687
79957
|
return;
|
|
79688
79958
|
const { state } = global;
|
|
79689
|
-
|
|
79959
|
+
const canClickTarget = state.inputMode === 'desktop' && ((state.cameraMode === 'walk' && !state.gamingControls) ||
|
|
79960
|
+
canTargetFly(global) ||
|
|
79961
|
+
state.cameraMode === 'orbit');
|
|
79962
|
+
if (canClickTarget) {
|
|
79690
79963
|
canvas.style.cursor = this._mouseClickTracking ? 'default' : 'pointer';
|
|
79691
79964
|
}
|
|
79692
79965
|
else {
|
|
79693
79966
|
canvas.style.cursor = '';
|
|
79694
79967
|
}
|
|
79695
79968
|
};
|
|
79969
|
+
_onCameraModeChanged = () => {
|
|
79970
|
+
this._targetPickRequest++;
|
|
79971
|
+
this._updateCursor();
|
|
79972
|
+
};
|
|
79696
79973
|
_pickCollision(offsetX, offsetY) {
|
|
79697
79974
|
if (!this.collision || !this._global)
|
|
79698
79975
|
return null;
|
|
@@ -79709,26 +79986,65 @@ class WalkInteraction {
|
|
|
79709
79986
|
normal: new Vec3(sn.nx, sn.ny, sn.nz)
|
|
79710
79987
|
};
|
|
79711
79988
|
}
|
|
79989
|
+
async _pickSceneTarget(offsetX, offsetY) {
|
|
79990
|
+
const global = this._global;
|
|
79991
|
+
const canvas = this._canvas;
|
|
79992
|
+
if (!global || !canvas)
|
|
79993
|
+
return null;
|
|
79994
|
+
const collisionTarget = this._pickCollision(offsetX, offsetY);
|
|
79995
|
+
if (collisionTarget) {
|
|
79996
|
+
return collisionTarget;
|
|
79997
|
+
}
|
|
79998
|
+
const result = await this._picker.pickSurface(offsetX / canvas.clientWidth, offsetY / canvas.clientHeight);
|
|
79999
|
+
if (result) {
|
|
80000
|
+
return result;
|
|
80001
|
+
}
|
|
80002
|
+
return null;
|
|
80003
|
+
}
|
|
80004
|
+
async _flyToPickedPosition(offsetX, offsetY) {
|
|
80005
|
+
const global = this._global;
|
|
80006
|
+
if (!global || !canTargetFly(global))
|
|
80007
|
+
return;
|
|
80008
|
+
const request = ++this._targetPickRequest;
|
|
80009
|
+
const target = await this._pickSceneTarget(offsetX, offsetY);
|
|
80010
|
+
if (target && request === this._targetPickRequest && this._global && canTargetFly(this._global)) {
|
|
80011
|
+
this._global.events.fire('flyTo', target.position, target.normal);
|
|
80012
|
+
}
|
|
80013
|
+
}
|
|
80014
|
+
async _focusPickedPosition(offsetX, offsetY) {
|
|
80015
|
+
const global = this._global;
|
|
80016
|
+
if (!global || global.state.cameraMode !== 'orbit')
|
|
80017
|
+
return;
|
|
80018
|
+
const request = ++this._targetPickRequest;
|
|
80019
|
+
const target = await this._pickSceneTarget(offsetX, offsetY);
|
|
80020
|
+
if (target && request === this._targetPickRequest && this._global?.state.cameraMode === 'orbit') {
|
|
80021
|
+
const { events } = this._global;
|
|
80022
|
+
events.fire('orbitTarget:set', target.position, target.normal);
|
|
80023
|
+
events.fire('pick', target.position);
|
|
80024
|
+
}
|
|
80025
|
+
}
|
|
79712
80026
|
_onPointerDown = (event) => {
|
|
79713
80027
|
const global = this._global;
|
|
79714
80028
|
if (!global)
|
|
79715
80029
|
return;
|
|
79716
80030
|
const { events } = global;
|
|
79717
|
-
// record offsets for click/tap
|
|
80031
|
+
// record offsets for click/tap target picking
|
|
79718
80032
|
this._lastPointerOffsetX = event.offsetX;
|
|
79719
80033
|
this._lastPointerOffsetY = event.offsetY;
|
|
79720
|
-
// start desktop click
|
|
80034
|
+
// start desktop click target tracking
|
|
79721
80035
|
if (event.pointerType !== 'touch' && event.button === 0) {
|
|
79722
80036
|
this._mouseClickTracking = true;
|
|
79723
80037
|
this._mouseClickDelta = 0;
|
|
79724
80038
|
this._updateCursor();
|
|
79725
80039
|
}
|
|
79726
|
-
//
|
|
80040
|
+
// Manual double-click/tap detection for platforms that do not emit
|
|
80041
|
+
// reliable native dblclick events on the canvas.
|
|
79727
80042
|
const now = Date.now();
|
|
79728
80043
|
const delay = Math.max(0, now - this._lastTap.time);
|
|
79729
80044
|
if (delay < 300 &&
|
|
79730
80045
|
Math.abs(event.clientX - this._lastTap.x) < 8 &&
|
|
79731
80046
|
Math.abs(event.clientY - this._lastTap.y) < 8) {
|
|
80047
|
+
this._suppressClick = true;
|
|
79732
80048
|
events.fire('inputEvent', 'dblclick', event);
|
|
79733
80049
|
this._lastTap.time = 0;
|
|
79734
80050
|
}
|
|
@@ -79750,6 +80066,9 @@ class WalkInteraction {
|
|
|
79750
80066
|
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79751
80067
|
events.fire('walkCancel');
|
|
79752
80068
|
}
|
|
80069
|
+
else if (canTargetFly(global)) {
|
|
80070
|
+
events.fire('flyCancel');
|
|
80071
|
+
}
|
|
79753
80072
|
}
|
|
79754
80073
|
}
|
|
79755
80074
|
};
|
|
@@ -79761,10 +80080,22 @@ class WalkInteraction {
|
|
|
79761
80080
|
if (this._mouseClickTracking && event.pointerType !== 'touch' && event.button === 0) {
|
|
79762
80081
|
this._mouseClickTracking = false;
|
|
79763
80082
|
this._updateCursor();
|
|
79764
|
-
if (this.
|
|
79765
|
-
|
|
79766
|
-
|
|
79767
|
-
|
|
80083
|
+
if (this._suppressClick) {
|
|
80084
|
+
this._suppressClick = false;
|
|
80085
|
+
return;
|
|
80086
|
+
}
|
|
80087
|
+
if (this._mouseClickDelta < TAP_EPSILON) {
|
|
80088
|
+
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80089
|
+
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80090
|
+
if (result) {
|
|
80091
|
+
events.fire('walkTo', result.position, result.normal);
|
|
80092
|
+
}
|
|
80093
|
+
}
|
|
80094
|
+
else if (state.cameraMode === 'fly') {
|
|
80095
|
+
this._flyToPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80096
|
+
}
|
|
80097
|
+
else if (state.cameraMode === 'orbit') {
|
|
80098
|
+
this._focusPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79768
80099
|
}
|
|
79769
80100
|
}
|
|
79770
80101
|
}
|
|
@@ -79778,15 +80109,20 @@ class WalkInteraction {
|
|
|
79778
80109
|
return;
|
|
79779
80110
|
if (!(event instanceof MouseEvent))
|
|
79780
80111
|
return;
|
|
79781
|
-
const {
|
|
79782
|
-
|
|
80112
|
+
const { events, state } = global;
|
|
80113
|
+
const cameraMode = state.cameraMode;
|
|
80114
|
+
if (cameraMode === 'walk')
|
|
79783
80115
|
return;
|
|
79784
|
-
if (
|
|
79785
|
-
this.
|
|
80116
|
+
if (cameraMode === 'fly') {
|
|
80117
|
+
this._flyToPickedPosition(event.offsetX, event.offsetY);
|
|
79786
80118
|
}
|
|
79787
|
-
|
|
79788
|
-
|
|
79789
|
-
|
|
80119
|
+
else if (cameraMode === 'orbit') {
|
|
80120
|
+
const request = ++this._targetPickRequest;
|
|
80121
|
+
const target = await this._pickSceneTarget(event.offsetX, event.offsetY);
|
|
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
|
+
}
|
|
79790
80126
|
}
|
|
79791
80127
|
};
|
|
79792
80128
|
_onMobileTap = () => {
|
|
@@ -79794,11 +80130,21 @@ class WalkInteraction {
|
|
|
79794
80130
|
if (!global)
|
|
79795
80131
|
return;
|
|
79796
80132
|
const { state, events } = global;
|
|
79797
|
-
if (
|
|
80133
|
+
if (this._suppressClick) {
|
|
80134
|
+
this._suppressClick = false;
|
|
79798
80135
|
return;
|
|
79799
|
-
|
|
79800
|
-
if (
|
|
79801
|
-
|
|
80136
|
+
}
|
|
80137
|
+
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
80138
|
+
const result = this._pickCollision(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80139
|
+
if (result) {
|
|
80140
|
+
events.fire('walkTo', result.position, result.normal);
|
|
80141
|
+
}
|
|
80142
|
+
}
|
|
80143
|
+
else if (state.cameraMode === 'fly') {
|
|
80144
|
+
this._flyToPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
80145
|
+
}
|
|
80146
|
+
else if (state.cameraMode === 'orbit') {
|
|
80147
|
+
this._focusPickedPosition(this._lastPointerOffsetX, this._lastPointerOffsetY);
|
|
79802
80148
|
}
|
|
79803
80149
|
};
|
|
79804
80150
|
attach(canvas, global) {
|
|
@@ -79808,12 +80154,13 @@ class WalkInteraction {
|
|
|
79808
80154
|
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79809
80155
|
canvas.addEventListener('pointermove', this._onPointerMove);
|
|
79810
80156
|
canvas.addEventListener('pointerup', this._onPointerUp);
|
|
79811
|
-
// double-click
|
|
80157
|
+
// double-click/tap fallback -> fly target or orbit focus (skipped in walk mode)
|
|
79812
80158
|
events.on('inputEvent', this._onInputEvent);
|
|
79813
|
-
// mobile tap (no movement) →
|
|
80159
|
+
// mobile tap (no movement) → walk/fly target or orbit focus
|
|
79814
80160
|
events.on('mobileTap', this._onMobileTap);
|
|
79815
80161
|
// refresh cursor on mode / gaming-controls change
|
|
79816
|
-
events.on('cameraMode:changed', this.
|
|
80162
|
+
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
80163
|
+
events.on('inputMode:changed', this._updateCursor);
|
|
79817
80164
|
events.on('gamingControls:changed', this._updateCursor);
|
|
79818
80165
|
}
|
|
79819
80166
|
detach() {
|
|
@@ -79826,12 +80173,12 @@ class WalkInteraction {
|
|
|
79826
80173
|
const { events } = this._global;
|
|
79827
80174
|
events.off('inputEvent', this._onInputEvent);
|
|
79828
80175
|
events.off('mobileTap', this._onMobileTap);
|
|
79829
|
-
events.off('cameraMode:changed', this.
|
|
80176
|
+
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
80177
|
+
events.off('inputMode:changed', this._updateCursor);
|
|
79830
80178
|
events.off('gamingControls:changed', this._updateCursor);
|
|
79831
80179
|
}
|
|
79832
80180
|
this._canvas = null;
|
|
79833
80181
|
this._global = null;
|
|
79834
|
-
this._picker = null;
|
|
79835
80182
|
}
|
|
79836
80183
|
}
|
|
79837
80184
|
|
|
@@ -79843,15 +80190,22 @@ class GamepadDevice {
|
|
|
79843
80190
|
orbitSpeed = 18;
|
|
79844
80191
|
gamepadRotateSensitivity = 1.0;
|
|
79845
80192
|
_source = new GamepadSource();
|
|
79846
|
-
|
|
80193
|
+
_global = null;
|
|
80194
|
+
attach(_canvas, global) {
|
|
80195
|
+
this._global = global;
|
|
79847
80196
|
// GamepadSource polls navigator.getGamepads() — no DOM attach needed.
|
|
79848
80197
|
}
|
|
79849
|
-
detach() {
|
|
80198
|
+
detach() {
|
|
80199
|
+
this._global = null;
|
|
80200
|
+
}
|
|
79850
80201
|
update(ctx, frame) {
|
|
79851
|
-
const { dt, cameraComponent, isFirstPerson } = ctx;
|
|
80202
|
+
const { dt, cameraComponent, isFly, isFirstPerson } = ctx;
|
|
79852
80203
|
const { leftStick, rightStick } = this._source.read();
|
|
79853
80204
|
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79854
80205
|
const { deltas } = frame;
|
|
80206
|
+
if (isFly && (leftStick[0] !== 0 || leftStick[1] !== 0 || rightStick[0] !== 0 || rightStick[1] !== 0)) {
|
|
80207
|
+
this._global?.events.fire('flyCancel');
|
|
80208
|
+
}
|
|
79855
80209
|
const v = tmpV$3.set(0, 0, 0);
|
|
79856
80210
|
stickMove.set(leftStick[0], 0, -leftStick[1]);
|
|
79857
80211
|
v.add(stickMove.mulScalar(this.moveSpeed * dt));
|
|
@@ -79864,7 +80218,9 @@ class GamepadDevice {
|
|
|
79864
80218
|
}
|
|
79865
80219
|
|
|
79866
80220
|
const tmpV1 = new Vec3();
|
|
80221
|
+
const tmpV2 = new Vec3();
|
|
79867
80222
|
const keyMove = new Vec3();
|
|
80223
|
+
const flyKeyVelocity = new Vec3();
|
|
79868
80224
|
const panMove = new Vec3();
|
|
79869
80225
|
const mouseRotate = new Vec3();
|
|
79870
80226
|
const wheelMove = new Vec3();
|
|
@@ -79895,6 +80251,8 @@ class KeyboardMouseDevice {
|
|
|
79895
80251
|
orbitSpeed = 18;
|
|
79896
80252
|
wheelSpeed = 0.06;
|
|
79897
80253
|
mouseRotateSensitivity = 0.5;
|
|
80254
|
+
flyMoveAccelerationDamping = 0.992;
|
|
80255
|
+
flyMoveDecelerationDamping = 0.993;
|
|
79898
80256
|
_source = new KeyboardMouseSource();
|
|
79899
80257
|
_global = null;
|
|
79900
80258
|
/** Running WASD/QE/arrow direction (sum of key states). */
|
|
@@ -79904,6 +80262,7 @@ class KeyboardMouseDevice {
|
|
|
79904
80262
|
_shift = 0;
|
|
79905
80263
|
_ctrl = 0;
|
|
79906
80264
|
_jump = 0;
|
|
80265
|
+
_flyKeyVelocity = new Vec3();
|
|
79907
80266
|
/**
|
|
79908
80267
|
* Get the underlying source so other code (PointerLockManager) can
|
|
79909
80268
|
* toggle its private pointer-lock flag, which gates how it consumes
|
|
@@ -79936,16 +80295,24 @@ class KeyboardMouseDevice {
|
|
|
79936
80295
|
for (let i = 0; i < n; i++) {
|
|
79937
80296
|
this._buttons[i] += button[i];
|
|
79938
80297
|
}
|
|
79939
|
-
const { isWalk, isFirstPerson, dt, distance, cameraComponent, mode, touchCount } = ctx;
|
|
79940
|
-
|
|
80298
|
+
const { isFly, isWalk, isFirstPerson, gamingControls, dt, distance, cameraComponent, mode, touchCount } = ctx;
|
|
80299
|
+
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
80300
|
+
// auto-move cancellation and requestFirstPerson events (driven by keyboard axes)
|
|
79941
80301
|
if (isWalk && (this._axis.x !== 0 || this._axis.z !== 0)) {
|
|
79942
80302
|
events.fire('walkCancel');
|
|
79943
80303
|
}
|
|
80304
|
+
if (isFly && (this._axis.x !== 0 || this._axis.y !== 0 || this._axis.z !== 0)) {
|
|
80305
|
+
events.fire('flyCancel');
|
|
80306
|
+
}
|
|
80307
|
+
if (isFly && wheel[0] !== 0) {
|
|
80308
|
+
events.fire('flyCancel');
|
|
80309
|
+
}
|
|
80310
|
+
if (isFly && (gamingControls || pan) && (mouse[0] !== 0 || mouse[1] !== 0)) {
|
|
80311
|
+
events.fire('flyCancel');
|
|
80312
|
+
}
|
|
79944
80313
|
if (!isFirstPerson && this._axis.length() > 0) {
|
|
79945
80314
|
events.fire('inputEvent', 'requestFirstPerson');
|
|
79946
80315
|
}
|
|
79947
|
-
// pan flag: RMB held, RMB just released this frame, or 2+ touches active
|
|
79948
|
-
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
79949
80316
|
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79950
80317
|
const { deltas } = frame;
|
|
79951
80318
|
// move (WASD + mouse-drag pan + wheel)
|
|
@@ -79960,7 +80327,22 @@ class KeyboardMouseDevice {
|
|
|
79960
80327
|
const shiftMul = isWalk ? 2 : 4;
|
|
79961
80328
|
const ctrlMul = isWalk ? 0.5 : 0.25;
|
|
79962
80329
|
const speed = this.moveSpeed * (this._shift ? shiftMul : this._ctrl ? ctrlMul : 1);
|
|
79963
|
-
|
|
80330
|
+
keyMove.mulScalar(speed);
|
|
80331
|
+
if (isFly) {
|
|
80332
|
+
flyKeyVelocity.copy(keyMove);
|
|
80333
|
+
const damping = flyKeyVelocity.lengthSq() > this._flyKeyVelocity.lengthSq() ?
|
|
80334
|
+
this.flyMoveAccelerationDamping :
|
|
80335
|
+
this.flyMoveDecelerationDamping;
|
|
80336
|
+
this._flyKeyVelocity.lerp(this._flyKeyVelocity, flyKeyVelocity, damp(damping, dt));
|
|
80337
|
+
if (flyKeyVelocity.lengthSq() === 0 && this._flyKeyVelocity.lengthSq() < 1e-4) {
|
|
80338
|
+
this._flyKeyVelocity.set(0, 0, 0);
|
|
80339
|
+
}
|
|
80340
|
+
keyMove.copy(this._flyKeyVelocity);
|
|
80341
|
+
}
|
|
80342
|
+
else {
|
|
80343
|
+
this._flyKeyVelocity.set(0, 0, 0);
|
|
80344
|
+
}
|
|
80345
|
+
v.add(tmpV2.copy(keyMove).mulScalar((isFirstPerson ? 1 : 0) * dt));
|
|
79964
80346
|
if (isWalk) {
|
|
79965
80347
|
// Pass jump signal as raw Y; WalkController uses move[1] > 0 as
|
|
79966
80348
|
// a boolean trigger.
|
|
@@ -80004,8 +80386,9 @@ class TouchDevice {
|
|
|
80004
80386
|
_pinchVelocity = 0;
|
|
80005
80387
|
/** Smoothed strafe/vertical velocity from two-finger pan, -1..1 each. */
|
|
80006
80388
|
_panVelocity = [0, 0];
|
|
80007
|
-
/** Tap-detection state — touch count and accumulated
|
|
80389
|
+
/** Tap-detection state — touch count, max touches, and accumulated movement. */
|
|
80008
80390
|
_tapTouches = 0;
|
|
80391
|
+
_tapMaxTouches = 0;
|
|
80009
80392
|
_tapDelta = 0;
|
|
80010
80393
|
/** True for one frame after a tap is detected during gaming controls. */
|
|
80011
80394
|
_tapJump = false;
|
|
@@ -80030,40 +80413,61 @@ class TouchDevice {
|
|
|
80030
80413
|
}
|
|
80031
80414
|
update(ctx, frame) {
|
|
80032
80415
|
const { touch, pinch, count } = this._source.read();
|
|
80033
|
-
const { isWalk, isFirstPerson, isOrbit, gamingControls, dt, distance, cameraComponent } = ctx;
|
|
80416
|
+
const { isFly, isWalk, isFirstPerson, isOrbit, gamingControls, dt, distance, cameraComponent } = ctx;
|
|
80034
80417
|
// running touch count
|
|
80035
80418
|
this._touchCount += count[0];
|
|
80036
|
-
|
|
80037
|
-
|
|
80419
|
+
if (isFly && gamingControls && (this._joystick[0] !== 0 || this._joystick[1] !== 0)) {
|
|
80420
|
+
this._global.events.fire('flyCancel');
|
|
80421
|
+
}
|
|
80422
|
+
// tap detection for click/tap target and focus modes
|
|
80423
|
+
if (isWalk || isFly || isOrbit) {
|
|
80038
80424
|
const prevTaps = this._tapTouches;
|
|
80039
80425
|
this._tapTouches = Math.max(0, this._tapTouches + count[0]);
|
|
80040
80426
|
if (prevTaps === 0 && this._tapTouches > 0) {
|
|
80041
80427
|
this._tapDelta = 0;
|
|
80042
80428
|
}
|
|
80429
|
+
if (this._tapTouches > 0) {
|
|
80430
|
+
this._tapMaxTouches = Math.max(this._tapMaxTouches, this._tapTouches);
|
|
80431
|
+
}
|
|
80043
80432
|
if (this._tapTouches > 0) {
|
|
80044
80433
|
const prevDelta = this._tapDelta;
|
|
80045
|
-
this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]);
|
|
80434
|
+
this._tapDelta += Math.abs(touch[0]) + Math.abs(touch[1]) + Math.abs(pinch[0]);
|
|
80046
80435
|
if (prevDelta < TAP_EPSILON && this._tapDelta >= TAP_EPSILON) {
|
|
80047
|
-
if (!gamingControls) {
|
|
80436
|
+
if (isWalk && !gamingControls) {
|
|
80048
80437
|
this._global.events.fire('walkCancel');
|
|
80049
80438
|
}
|
|
80439
|
+
else if (isFly) {
|
|
80440
|
+
this._global.events.fire('flyCancel');
|
|
80441
|
+
}
|
|
80050
80442
|
}
|
|
80051
80443
|
}
|
|
80052
80444
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
80053
|
-
if (this._tapDelta < TAP_EPSILON) {
|
|
80054
|
-
if (!gamingControls) {
|
|
80445
|
+
if (this._tapDelta < TAP_EPSILON && this._tapMaxTouches === 1) {
|
|
80446
|
+
if (isWalk && !gamingControls) {
|
|
80055
80447
|
// Walk-interaction listens for this and fires walkTo
|
|
80056
80448
|
// after picking.
|
|
80057
80449
|
this._global.events.fire('mobileTap');
|
|
80058
80450
|
}
|
|
80059
|
-
else {
|
|
80451
|
+
else if (isWalk) {
|
|
80060
80452
|
this._tapJump = true;
|
|
80061
80453
|
}
|
|
80454
|
+
else if (isFly && !gamingControls) {
|
|
80455
|
+
// Walk-interaction listens for this and fires flyTo
|
|
80456
|
+
// after picking.
|
|
80457
|
+
this._global.events.fire('mobileTap');
|
|
80458
|
+
}
|
|
80459
|
+
else if (isOrbit) {
|
|
80460
|
+
// Walk-interaction listens for this and sets orbit focus
|
|
80461
|
+
// after picking.
|
|
80462
|
+
this._global.events.fire('mobileTap');
|
|
80463
|
+
}
|
|
80062
80464
|
}
|
|
80465
|
+
this._tapMaxTouches = 0;
|
|
80063
80466
|
}
|
|
80064
80467
|
}
|
|
80065
80468
|
else {
|
|
80066
80469
|
this._tapTouches = 0;
|
|
80470
|
+
this._tapMaxTouches = 0;
|
|
80067
80471
|
}
|
|
80068
80472
|
// smoothed velocities for fly/walk first-person motion (non-gaming)
|
|
80069
80473
|
if (isFirstPerson && !gamingControls && this._touchCount > 1) {
|
|
@@ -80232,6 +80636,9 @@ class TrackpadDevice {
|
|
|
80232
80636
|
}
|
|
80233
80637
|
else {
|
|
80234
80638
|
// fly / walk: always rotate (shift is a speed modifier, not a gesture)
|
|
80639
|
+
if (mode === 'fly') {
|
|
80640
|
+
this._global.events.fire('flyCancel');
|
|
80641
|
+
}
|
|
80235
80642
|
this._orbit[0] += deltaX;
|
|
80236
80643
|
this._orbit[1] += deltaY;
|
|
80237
80644
|
}
|
|
@@ -80307,7 +80714,7 @@ class InputController {
|
|
|
80307
80714
|
_keyboardMouse = new KeyboardMouseDevice();
|
|
80308
80715
|
_touch = new TouchDevice();
|
|
80309
80716
|
_gamepad = new GamepadDevice();
|
|
80310
|
-
_walkInteraction
|
|
80717
|
+
_walkInteraction;
|
|
80311
80718
|
_pointerLock = new PointerLockManager();
|
|
80312
80719
|
_modeShortcuts = new ModeShortcuts();
|
|
80313
80720
|
_inputModeTracker = new InputModeTracker();
|
|
@@ -80317,8 +80724,9 @@ class InputController {
|
|
|
80317
80724
|
get collision() {
|
|
80318
80725
|
return this._walkInteraction.collision;
|
|
80319
80726
|
}
|
|
80320
|
-
constructor(global) {
|
|
80727
|
+
constructor(global, picker) {
|
|
80321
80728
|
this._global = global;
|
|
80729
|
+
this._walkInteraction = new WalkInteraction(picker);
|
|
80322
80730
|
const { app, events } = global;
|
|
80323
80731
|
const canvas = app.graphicsDevice.canvas;
|
|
80324
80732
|
// Trackpad MUST attach before KeyboardMouseDevice so its wheel
|
|
@@ -80644,6 +81052,534 @@ class MeshDebugOverlay {
|
|
|
80644
81052
|
}
|
|
80645
81053
|
}
|
|
80646
81054
|
|
|
81055
|
+
/**
|
|
81056
|
+
* World picking for splat scenes.
|
|
81057
|
+
*
|
|
81058
|
+
* - **Compute renderer (WebGPU tiled-compute)**: uses engine `Picker` with depth enabled — expected
|
|
81059
|
+
* depth is already provided by the tile-composite path.
|
|
81060
|
+
* - **Raster renderers (WebGL, CPU / GPU sort, etc.)**: custom `pickPS` / `gsplatPS` patch plus
|
|
81061
|
+
* `RGBA16F` alpha-weighted depth accumulation, because the stock pick pass encodes splat IDs /
|
|
81062
|
+
* last-fragment depth rather than expected depth.
|
|
81063
|
+
*/
|
|
81064
|
+
// Override global picking to pack alpha-weighted splat depth instead of meshInstance id.
|
|
81065
|
+
const pickDepthGlsl = /* glsl */ `
|
|
81066
|
+
vec4 encodePickOutput(uint id) {
|
|
81067
|
+
const vec4 inv = vec4(1.0 / 255.0);
|
|
81068
|
+
const uvec4 shifts = uvec4(16, 8, 0, 24);
|
|
81069
|
+
uvec4 col = (uvec4(id) >> shifts) & uvec4(0xff);
|
|
81070
|
+
return vec4(col) * inv;
|
|
81071
|
+
}
|
|
81072
|
+
|
|
81073
|
+
#ifdef GSPLAT_PICK_DEPTH
|
|
81074
|
+
#ifndef CAMERAPLANES
|
|
81075
|
+
#define CAMERAPLANES
|
|
81076
|
+
uniform vec4 camera_params; // x: 1/far, y: far, z: near, w: isOrtho
|
|
81077
|
+
#endif
|
|
81078
|
+
|
|
81079
|
+
vec4 getPickOutput() {
|
|
81080
|
+
float normalizedDepth;
|
|
81081
|
+
if (camera_params.w > 0.5) {
|
|
81082
|
+
normalizedDepth = gl_FragCoord.z;
|
|
81083
|
+
} else {
|
|
81084
|
+
float linearDepth = 1.0 / gl_FragCoord.w;
|
|
81085
|
+
normalizedDepth = (linearDepth - camera_params.z) / (camera_params.y - camera_params.z);
|
|
81086
|
+
}
|
|
81087
|
+
|
|
81088
|
+
return vec4(gaussianColor.a * normalizedDepth, 0.0, 0.0, gaussianColor.a);
|
|
81089
|
+
}
|
|
81090
|
+
#else
|
|
81091
|
+
#ifndef PICK_CUSTOM_ID
|
|
81092
|
+
uniform uint meshInstanceId;
|
|
81093
|
+
|
|
81094
|
+
vec4 getPickOutput() {
|
|
81095
|
+
return encodePickOutput(meshInstanceId);
|
|
81096
|
+
}
|
|
81097
|
+
#endif
|
|
81098
|
+
#endif
|
|
81099
|
+
|
|
81100
|
+
#ifdef DEPTH_PICK_PASS
|
|
81101
|
+
#include "floatAsUintPS"
|
|
81102
|
+
#ifndef CAMERAPLANES
|
|
81103
|
+
#define CAMERAPLANES
|
|
81104
|
+
uniform vec4 camera_params; // x: 1/far, y: far, z: near, w: isOrtho
|
|
81105
|
+
#endif
|
|
81106
|
+
|
|
81107
|
+
vec4 getPickDepth() {
|
|
81108
|
+
float linearDepth;
|
|
81109
|
+
if (camera_params.w > 0.5) {
|
|
81110
|
+
linearDepth = gl_FragCoord.z;
|
|
81111
|
+
} else {
|
|
81112
|
+
float viewDist = 1.0 / gl_FragCoord.w;
|
|
81113
|
+
linearDepth = (viewDist - camera_params.z) / (camera_params.y - camera_params.z);
|
|
81114
|
+
}
|
|
81115
|
+
return float2uint(linearDepth);
|
|
81116
|
+
}
|
|
81117
|
+
#endif
|
|
81118
|
+
`;
|
|
81119
|
+
const pickDepthWgsl = /* wgsl */ `
|
|
81120
|
+
fn encodePickOutput(id: u32) -> vec4f {
|
|
81121
|
+
let inv: vec4f = vec4f(1.0 / 255.0);
|
|
81122
|
+
let shifts: vec4u = vec4u(16u, 8u, 0u, 24u);
|
|
81123
|
+
let col: vec4u = (vec4u(id) >> shifts) & vec4u(0xffu);
|
|
81124
|
+
return vec4f(col) * inv;
|
|
81125
|
+
}
|
|
81126
|
+
|
|
81127
|
+
#ifdef GSPLAT_PICK_DEPTH
|
|
81128
|
+
#ifndef CAMERAPLANES
|
|
81129
|
+
#define CAMERAPLANES
|
|
81130
|
+
uniform camera_params: vec4f; // x: 1/far, y: far, z: near, w: isOrtho
|
|
81131
|
+
#endif
|
|
81132
|
+
|
|
81133
|
+
fn getPickOutput() -> vec4f {
|
|
81134
|
+
var normalizedDepth: f32;
|
|
81135
|
+
if (uniform.camera_params.w > 0.5) {
|
|
81136
|
+
normalizedDepth = pcPosition.z;
|
|
81137
|
+
} else {
|
|
81138
|
+
let linearDepth = 1.0 / pcPosition.w;
|
|
81139
|
+
normalizedDepth = (linearDepth - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
|
|
81140
|
+
}
|
|
81141
|
+
|
|
81142
|
+
let a = f32(gaussianColor.a);
|
|
81143
|
+
return vec4f(a * normalizedDepth, 0.0, 0.0, a);
|
|
81144
|
+
}
|
|
81145
|
+
#else
|
|
81146
|
+
#ifndef PICK_CUSTOM_ID
|
|
81147
|
+
uniform meshInstanceId: u32;
|
|
81148
|
+
|
|
81149
|
+
fn getPickOutput() -> vec4f {
|
|
81150
|
+
return encodePickOutput(uniform.meshInstanceId);
|
|
81151
|
+
}
|
|
81152
|
+
#endif
|
|
81153
|
+
#endif
|
|
81154
|
+
|
|
81155
|
+
#ifdef DEPTH_PICK_PASS
|
|
81156
|
+
#include "floatAsUintPS"
|
|
81157
|
+
#ifndef CAMERAPLANES
|
|
81158
|
+
#define CAMERAPLANES
|
|
81159
|
+
uniform camera_params: vec4f; // x: 1/far, y: far, z: near, w: isOrtho
|
|
81160
|
+
#endif
|
|
81161
|
+
|
|
81162
|
+
fn getPickDepth() -> vec4f {
|
|
81163
|
+
var linearDepth: f32;
|
|
81164
|
+
if (uniform.camera_params.w > 0.5) {
|
|
81165
|
+
linearDepth = pcPosition.z;
|
|
81166
|
+
} else {
|
|
81167
|
+
let viewDist = 1.0 / pcPosition.w;
|
|
81168
|
+
linearDepth = (viewDist - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
|
|
81169
|
+
}
|
|
81170
|
+
return float2uint(linearDepth);
|
|
81171
|
+
}
|
|
81172
|
+
#endif
|
|
81173
|
+
`;
|
|
81174
|
+
const pickPassChunkInjected = [
|
|
81175
|
+
'#ifdef PICK_PASS',
|
|
81176
|
+
' #define GSPLAT_PICK_DEPTH',
|
|
81177
|
+
' #include "pickPS"',
|
|
81178
|
+
'#endif'
|
|
81179
|
+
].join('\n');
|
|
81180
|
+
const safeChunkReplace = (s, find, repl) => {
|
|
81181
|
+
const out = s.replace(find, repl);
|
|
81182
|
+
if (out === s) {
|
|
81183
|
+
throw new Error('picker: engine gsplat/pick chunk patch failed (engine version mismatch?)');
|
|
81184
|
+
}
|
|
81185
|
+
return out;
|
|
81186
|
+
};
|
|
81187
|
+
const patchGsplatPickGlsl = (chunk) => {
|
|
81188
|
+
return safeChunkReplace(safeChunkReplace(chunk, /#ifdef PICK_PASS\s*#include "pickPS"\s*#endif/, pickPassChunkInjected), 'pcFragColor0 = encodePickOutput(vPickId);', 'pcFragColor0 = getPickOutput();');
|
|
81189
|
+
};
|
|
81190
|
+
const patchGsplatPickWgsl = (chunk) => {
|
|
81191
|
+
return safeChunkReplace(safeChunkReplace(chunk, /#ifdef PICK_PASS\s*#include "pickPS"\s*#endif/, pickPassChunkInjected), 'output.color = encodePickOutput(vPickId);', 'output.color = getPickOutput();');
|
|
81192
|
+
};
|
|
81193
|
+
/** Per-device original chunk strings + refcount so we can restore after the last Picker releases. */
|
|
81194
|
+
const pickerShaderPatchState = new WeakMap();
|
|
81195
|
+
const vec4 = new Vec4();
|
|
81196
|
+
const viewProjMat = new Mat4();
|
|
81197
|
+
const clearColor = new Color(0, 0, 0, 1);
|
|
81198
|
+
const NORMAL_EPSILON$1 = 1e-12;
|
|
81199
|
+
const NORMAL_OUTLIER_MIN_DOT = 0.35;
|
|
81200
|
+
const NORMAL_SAMPLE_RADII = [1, 2, 4, 8];
|
|
81201
|
+
const NORMAL_SAMPLE_DIRECTIONS = [
|
|
81202
|
+
[1, 0],
|
|
81203
|
+
[1, 1],
|
|
81204
|
+
[0, 1],
|
|
81205
|
+
[-1, 1],
|
|
81206
|
+
[-1, 0],
|
|
81207
|
+
[-1, -1],
|
|
81208
|
+
[0, -1],
|
|
81209
|
+
[1, -1]
|
|
81210
|
+
];
|
|
81211
|
+
// Shared buffer for half-to-float conversion
|
|
81212
|
+
const float32 = new Float32Array(1);
|
|
81213
|
+
const uint32 = new Uint32Array(float32.buffer);
|
|
81214
|
+
// Convert 16-bit half-float to 32-bit float using bit manipulation.
|
|
81215
|
+
const half2Float = (h) => {
|
|
81216
|
+
const sign = (h & 0x8000) << 16;
|
|
81217
|
+
const exponent = (h & 0x7C00) >> 10;
|
|
81218
|
+
const mantissa = h & 0x03FF;
|
|
81219
|
+
if (exponent === 0) {
|
|
81220
|
+
if (mantissa === 0) {
|
|
81221
|
+
uint32[0] = sign;
|
|
81222
|
+
}
|
|
81223
|
+
else {
|
|
81224
|
+
let e = -1;
|
|
81225
|
+
let m = mantissa;
|
|
81226
|
+
do {
|
|
81227
|
+
e++;
|
|
81228
|
+
m <<= 1;
|
|
81229
|
+
} while ((m & 0x0400) === 0);
|
|
81230
|
+
uint32[0] = sign | ((127 - 15 - e) << 23) | ((m & 0x03FF) << 13);
|
|
81231
|
+
}
|
|
81232
|
+
}
|
|
81233
|
+
else if (exponent === 31) {
|
|
81234
|
+
uint32[0] = sign | 0x7F800000 | (mantissa << 13);
|
|
81235
|
+
}
|
|
81236
|
+
else {
|
|
81237
|
+
uint32[0] = sign | ((exponent + 127 - 15) << 23) | (mantissa << 13);
|
|
81238
|
+
}
|
|
81239
|
+
return float32[0];
|
|
81240
|
+
};
|
|
81241
|
+
const registerPickerShaderPatches = (app) => {
|
|
81242
|
+
const device = app.graphicsDevice;
|
|
81243
|
+
const existing = pickerShaderPatchState.get(device);
|
|
81244
|
+
if (existing) {
|
|
81245
|
+
existing.refCount++;
|
|
81246
|
+
return;
|
|
81247
|
+
}
|
|
81248
|
+
const glslChunks = ShaderChunks.get(device, 'glsl');
|
|
81249
|
+
const wgslChunks = ShaderChunks.get(device, 'wgsl');
|
|
81250
|
+
const glslPickPS = glslChunks.get('pickPS');
|
|
81251
|
+
const glslGsplatPS = glslChunks.get('gsplatPS');
|
|
81252
|
+
const wgslPickPS = wgslChunks.get('pickPS');
|
|
81253
|
+
const wgslGsplatPS = wgslChunks.get('gsplatPS');
|
|
81254
|
+
// Patch strings before mutating ShaderChunks so engine mismatches leave globals untouched.
|
|
81255
|
+
const patchedGlslGsplatPS = patchGsplatPickGlsl(glslGsplatPS);
|
|
81256
|
+
const patchedWgslGsplatPS = patchGsplatPickWgsl(wgslGsplatPS);
|
|
81257
|
+
const state = {
|
|
81258
|
+
glslPickPS,
|
|
81259
|
+
glslGsplatPS,
|
|
81260
|
+
wgslPickPS,
|
|
81261
|
+
wgslGsplatPS,
|
|
81262
|
+
refCount: 1
|
|
81263
|
+
};
|
|
81264
|
+
pickerShaderPatchState.set(device, state);
|
|
81265
|
+
glslChunks.set('pickPS', pickDepthGlsl);
|
|
81266
|
+
wgslChunks.set('pickPS', pickDepthWgsl);
|
|
81267
|
+
glslChunks.set('gsplatPS', patchedGlslGsplatPS);
|
|
81268
|
+
wgslChunks.set('gsplatPS', patchedWgslGsplatPS);
|
|
81269
|
+
};
|
|
81270
|
+
const unregisterPickerShaderPatches = (app) => {
|
|
81271
|
+
const device = app.graphicsDevice;
|
|
81272
|
+
const state = pickerShaderPatchState.get(device);
|
|
81273
|
+
if (!state) {
|
|
81274
|
+
return;
|
|
81275
|
+
}
|
|
81276
|
+
state.refCount--;
|
|
81277
|
+
if (state.refCount > 0) {
|
|
81278
|
+
return;
|
|
81279
|
+
}
|
|
81280
|
+
const glslChunks = ShaderChunks.get(device, 'glsl');
|
|
81281
|
+
const wgslChunks = ShaderChunks.get(device, 'wgsl');
|
|
81282
|
+
glslChunks.set('pickPS', state.glslPickPS);
|
|
81283
|
+
glslChunks.set('gsplatPS', state.glslGsplatPS);
|
|
81284
|
+
wgslChunks.set('pickPS', state.wgslPickPS);
|
|
81285
|
+
wgslChunks.set('gsplatPS', state.wgslGsplatPS);
|
|
81286
|
+
pickerShaderPatchState.delete(device);
|
|
81287
|
+
};
|
|
81288
|
+
const getWorldPoint = (camera, x, y, width, height, normalizedDepth) => {
|
|
81289
|
+
if (!Number.isFinite(normalizedDepth) || normalizedDepth < 0 || normalizedDepth > 1) {
|
|
81290
|
+
return null;
|
|
81291
|
+
}
|
|
81292
|
+
const { farClip: far, nearClip: near } = camera;
|
|
81293
|
+
const ndcDepth = camera.projection === PROJECTION_ORTHOGRAPHIC ?
|
|
81294
|
+
normalizedDepth :
|
|
81295
|
+
far * normalizedDepth / (normalizedDepth * (far - near) + near);
|
|
81296
|
+
viewProjMat.mul2(camera.projectionMatrix, camera.viewMatrix).invert();
|
|
81297
|
+
vec4.set(x / width * 2 - 1, (1 - y / height) * 2 - 1, ndcDepth * 2 - 1, 1);
|
|
81298
|
+
viewProjMat.transformVec4(vec4, vec4);
|
|
81299
|
+
if (!Number.isFinite(vec4.w) || Math.abs(vec4.w) < 1e-8) {
|
|
81300
|
+
return null;
|
|
81301
|
+
}
|
|
81302
|
+
vec4.mulScalar(1 / vec4.w);
|
|
81303
|
+
if (!Number.isFinite(vec4.x) || !Number.isFinite(vec4.y) || !Number.isFinite(vec4.z)) {
|
|
81304
|
+
return null;
|
|
81305
|
+
}
|
|
81306
|
+
return new Vec3(vec4.x, vec4.y, vec4.z);
|
|
81307
|
+
};
|
|
81308
|
+
const setCameraFacingNormal = (cameraPosition, position, normal) => {
|
|
81309
|
+
normal.sub2(cameraPosition, position);
|
|
81310
|
+
const len = normal.length();
|
|
81311
|
+
if (len > 1e-6) {
|
|
81312
|
+
normal.mulScalar(1 / len);
|
|
81313
|
+
}
|
|
81314
|
+
else {
|
|
81315
|
+
normal.set(0, 1, 0);
|
|
81316
|
+
}
|
|
81317
|
+
return normal;
|
|
81318
|
+
};
|
|
81319
|
+
class Picker {
|
|
81320
|
+
pick;
|
|
81321
|
+
pickSurface;
|
|
81322
|
+
release;
|
|
81323
|
+
constructor(app, camera) {
|
|
81324
|
+
const { graphicsDevice } = app;
|
|
81325
|
+
let enginePicker;
|
|
81326
|
+
let accumBuffer;
|
|
81327
|
+
let accumTarget;
|
|
81328
|
+
let accumPass;
|
|
81329
|
+
let chunksPatched = false;
|
|
81330
|
+
let pickQueue = Promise.resolve();
|
|
81331
|
+
const cacheCamera = {
|
|
81332
|
+
position: new Vec3(),
|
|
81333
|
+
viewMatrix: new Mat4(),
|
|
81334
|
+
projectionMatrix: new Mat4(),
|
|
81335
|
+
nearClip: 0,
|
|
81336
|
+
farClip: 0,
|
|
81337
|
+
projection: 0
|
|
81338
|
+
};
|
|
81339
|
+
const initRasterAccum = (width, height) => {
|
|
81340
|
+
accumBuffer = new Texture(graphicsDevice, {
|
|
81341
|
+
format: PIXELFORMAT_RGBA16F,
|
|
81342
|
+
width,
|
|
81343
|
+
height,
|
|
81344
|
+
mipmaps: false,
|
|
81345
|
+
minFilter: FILTER_NEAREST,
|
|
81346
|
+
magFilter: FILTER_NEAREST,
|
|
81347
|
+
addressU: ADDRESS_CLAMP_TO_EDGE,
|
|
81348
|
+
addressV: ADDRESS_CLAMP_TO_EDGE,
|
|
81349
|
+
name: 'picker-accum'
|
|
81350
|
+
});
|
|
81351
|
+
accumTarget = new RenderTarget({
|
|
81352
|
+
colorBuffer: accumBuffer,
|
|
81353
|
+
depth: false // not needed — gaussians are rendered back to front
|
|
81354
|
+
});
|
|
81355
|
+
accumPass = new RenderPassPicker(graphicsDevice, app.renderer);
|
|
81356
|
+
// RGB: additive depth accumulation. Alpha: multiplicative transmittance.
|
|
81357
|
+
accumPass.blendState = new BlendState(true, BLENDEQUATION_ADD, BLENDMODE_ONE, BLENDMODE_ONE_MINUS_SRC_ALPHA, BLENDEQUATION_ADD, BLENDMODE_ZERO, BLENDMODE_ONE_MINUS_SRC_ALPHA);
|
|
81358
|
+
};
|
|
81359
|
+
const readTexture = (texture, x, y, target) => {
|
|
81360
|
+
const texY = graphicsDevice.isWebGL2 ? target.height - y - 1 : y;
|
|
81361
|
+
return texture.read(x, texY, 1, 1, {
|
|
81362
|
+
renderTarget: target,
|
|
81363
|
+
immediate: true
|
|
81364
|
+
});
|
|
81365
|
+
};
|
|
81366
|
+
const updateCache = () => {
|
|
81367
|
+
const cam = camera.camera;
|
|
81368
|
+
cacheCamera.position.copy(camera.getPosition());
|
|
81369
|
+
cacheCamera.viewMatrix.copy(cam.viewMatrix);
|
|
81370
|
+
cacheCamera.projectionMatrix.copy(cam.projectionMatrix);
|
|
81371
|
+
cacheCamera.nearClip = cam.nearClip;
|
|
81372
|
+
cacheCamera.farClip = cam.farClip;
|
|
81373
|
+
cacheCamera.projection = cam.projection;
|
|
81374
|
+
};
|
|
81375
|
+
const getCacheCameraSnapshot = () => {
|
|
81376
|
+
return {
|
|
81377
|
+
position: cacheCamera.position.clone(),
|
|
81378
|
+
viewMatrix: cacheCamera.viewMatrix.clone(),
|
|
81379
|
+
projectionMatrix: cacheCamera.projectionMatrix.clone(),
|
|
81380
|
+
nearClip: cacheCamera.nearClip,
|
|
81381
|
+
farClip: cacheCamera.farClip,
|
|
81382
|
+
projection: cacheCamera.projection
|
|
81383
|
+
};
|
|
81384
|
+
};
|
|
81385
|
+
const readRasterBlock = async (blockX, blockY, blockWidth, blockHeight, viewportWidth, viewportHeight, pickCamera) => {
|
|
81386
|
+
const texY = graphicsDevice.isWebGL2 ? accumTarget.height - blockY - blockHeight : blockY;
|
|
81387
|
+
const pixels = await accumBuffer.read(blockX, texY, blockWidth, blockHeight, {
|
|
81388
|
+
renderTarget: accumTarget,
|
|
81389
|
+
immediate: true
|
|
81390
|
+
});
|
|
81391
|
+
return (x, y) => {
|
|
81392
|
+
const localX = x - blockX;
|
|
81393
|
+
const localY = y - blockY;
|
|
81394
|
+
if (localX < 0 || localX >= blockWidth || localY < 0 || localY >= blockHeight) {
|
|
81395
|
+
return null;
|
|
81396
|
+
}
|
|
81397
|
+
const row = graphicsDevice.isWebGL2 ? blockHeight - localY - 1 : localY;
|
|
81398
|
+
const index = (row * blockWidth + localX) * 4;
|
|
81399
|
+
const r = half2Float(pixels[index]);
|
|
81400
|
+
const transmittance = half2Float(pixels[index + 3]);
|
|
81401
|
+
const alpha = 1 - transmittance;
|
|
81402
|
+
if (!Number.isFinite(r) || !Number.isFinite(alpha) || alpha < 1e-6) {
|
|
81403
|
+
return null;
|
|
81404
|
+
}
|
|
81405
|
+
const normalizedDepth = r / alpha;
|
|
81406
|
+
return getWorldPoint(pickCamera, x, y, viewportWidth, viewportHeight, normalizedDepth);
|
|
81407
|
+
};
|
|
81408
|
+
};
|
|
81409
|
+
const pickPosition = async (x, y) => {
|
|
81410
|
+
const width = Math.floor(graphicsDevice.width);
|
|
81411
|
+
const height = Math.floor(graphicsDevice.height);
|
|
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;
|
|
81421
|
+
}
|
|
81422
|
+
const isComputeRenderer = app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE;
|
|
81423
|
+
// Enable gsplat IDs only while rendering the pick target so we
|
|
81424
|
+
// don't pay the memory/perf cost between pick passes.
|
|
81425
|
+
const prevEnableIds = app.scene.gsplat.enableIds;
|
|
81426
|
+
app.scene.gsplat.enableIds = true;
|
|
81427
|
+
try {
|
|
81428
|
+
if (isComputeRenderer) {
|
|
81429
|
+
enginePicker ??= new Picker$1(app, 1, 1, true);
|
|
81430
|
+
enginePicker.resize(width, height);
|
|
81431
|
+
enginePicker.prepare(camera.camera, app.scene, [worldLayer]);
|
|
81432
|
+
}
|
|
81433
|
+
else {
|
|
81434
|
+
if (!chunksPatched) {
|
|
81435
|
+
registerPickerShaderPatches(app);
|
|
81436
|
+
chunksPatched = true;
|
|
81437
|
+
}
|
|
81438
|
+
if (!accumPass) {
|
|
81439
|
+
initRasterAccum(width, height);
|
|
81440
|
+
}
|
|
81441
|
+
else {
|
|
81442
|
+
accumTarget.resize(width, height);
|
|
81443
|
+
}
|
|
81444
|
+
accumPass.init(accumTarget);
|
|
81445
|
+
accumPass.setClearColor(clearColor);
|
|
81446
|
+
accumPass.update(camera.camera, app.scene, [worldLayer], new Map(), false);
|
|
81447
|
+
accumPass.render();
|
|
81448
|
+
}
|
|
81449
|
+
updateCache();
|
|
81450
|
+
}
|
|
81451
|
+
finally {
|
|
81452
|
+
app.scene.gsplat.enableIds = prevEnableIds;
|
|
81453
|
+
}
|
|
81454
|
+
const pickCamera = getCacheCameraSnapshot();
|
|
81455
|
+
if (isComputeRenderer) {
|
|
81456
|
+
const normalizedDepth = await enginePicker.getPointDepthAsync(screenX, screenY);
|
|
81457
|
+
const position = normalizedDepth !== null ?
|
|
81458
|
+
getWorldPoint(pickCamera, screenX, screenY, width, height, normalizedDepth) :
|
|
81459
|
+
null;
|
|
81460
|
+
return position ? { position, camera: pickCamera, screenX, screenY, width, height, isComputeRenderer } : null;
|
|
81461
|
+
}
|
|
81462
|
+
const pixels = await readTexture(accumBuffer, screenX, screenY, accumTarget);
|
|
81463
|
+
const r = half2Float(pixels[0]);
|
|
81464
|
+
const transmittance = half2Float(pixels[3]);
|
|
81465
|
+
const alpha = 1 - transmittance;
|
|
81466
|
+
if (!Number.isFinite(r) || !Number.isFinite(alpha) || alpha < 1e-6) {
|
|
81467
|
+
return null;
|
|
81468
|
+
}
|
|
81469
|
+
const normalizedDepth = r / alpha;
|
|
81470
|
+
const position = getWorldPoint(pickCamera, screenX, screenY, width, height, normalizedDepth);
|
|
81471
|
+
return position ? { position, camera: pickCamera, screenX, screenY, width, height, isComputeRenderer } : null;
|
|
81472
|
+
};
|
|
81473
|
+
const serializePick = (operation) => {
|
|
81474
|
+
// The render targets are shared by all picks on this instance.
|
|
81475
|
+
const result = pickQueue.then(operation, operation);
|
|
81476
|
+
pickQueue = result.then(() => undefined, () => undefined);
|
|
81477
|
+
return result;
|
|
81478
|
+
};
|
|
81479
|
+
const pick = async (x, y) => {
|
|
81480
|
+
const result = await pickPosition(x, y);
|
|
81481
|
+
return result?.position ?? null;
|
|
81482
|
+
};
|
|
81483
|
+
const pickSurface = async (x, y) => {
|
|
81484
|
+
const picked = await pickPosition(x, y);
|
|
81485
|
+
if (!picked) {
|
|
81486
|
+
return null;
|
|
81487
|
+
}
|
|
81488
|
+
const { position, screenX, screenY, width, height } = picked;
|
|
81489
|
+
if (picked.isComputeRenderer) {
|
|
81490
|
+
return {
|
|
81491
|
+
position,
|
|
81492
|
+
normal: setCameraFacingNormal(picked.camera.position, position, new Vec3())
|
|
81493
|
+
};
|
|
81494
|
+
}
|
|
81495
|
+
const maxRadius = NORMAL_SAMPLE_RADII[NORMAL_SAMPLE_RADII.length - 1];
|
|
81496
|
+
const blockX = Math.max(0, screenX - maxRadius);
|
|
81497
|
+
const blockY = Math.max(0, screenY - maxRadius);
|
|
81498
|
+
const blockWidth = Math.min(width - 1, screenX + maxRadius) - blockX + 1;
|
|
81499
|
+
const blockHeight = Math.min(height - 1, screenY + maxRadius) - blockY + 1;
|
|
81500
|
+
const rasterBlock = await readRasterBlock(blockX, blockY, blockWidth, blockHeight, width, height, picked.camera);
|
|
81501
|
+
const samplePixel = (px, py) => {
|
|
81502
|
+
if (px < 0 || px >= width || py < 0 || py >= height) {
|
|
81503
|
+
return Promise.resolve(null);
|
|
81504
|
+
}
|
|
81505
|
+
return Promise.resolve(rasterBlock(px, py));
|
|
81506
|
+
};
|
|
81507
|
+
const sampleRings = await Promise.all(NORMAL_SAMPLE_RADII.map((radius) => {
|
|
81508
|
+
return Promise.all(NORMAL_SAMPLE_DIRECTIONS.map(([dx, dy]) => {
|
|
81509
|
+
const px = screenX + dx * radius;
|
|
81510
|
+
const py = screenY + dy * radius;
|
|
81511
|
+
return samplePixel(px, py);
|
|
81512
|
+
}));
|
|
81513
|
+
}));
|
|
81514
|
+
const toCamera = setCameraFacingNormal(picked.camera.position, position, new Vec3());
|
|
81515
|
+
const candidates = [];
|
|
81516
|
+
const va = new Vec3();
|
|
81517
|
+
const vb = new Vec3();
|
|
81518
|
+
const sampleNormal = new Vec3();
|
|
81519
|
+
sampleRings.forEach((points) => {
|
|
81520
|
+
for (let i = 0; i < NORMAL_SAMPLE_DIRECTIONS.length; i++) {
|
|
81521
|
+
const pointA = points[i];
|
|
81522
|
+
const pointB = points[(i + 1) % NORMAL_SAMPLE_DIRECTIONS.length];
|
|
81523
|
+
if (!pointA || !pointB) {
|
|
81524
|
+
continue;
|
|
81525
|
+
}
|
|
81526
|
+
va.sub2(pointA, position);
|
|
81527
|
+
vb.sub2(pointB, position);
|
|
81528
|
+
if (va.lengthSq() <= NORMAL_EPSILON$1 || vb.lengthSq() <= NORMAL_EPSILON$1) {
|
|
81529
|
+
continue;
|
|
81530
|
+
}
|
|
81531
|
+
// Direction order is clockwise in screen space. Screen Y points
|
|
81532
|
+
// down, so crossing next by current gives a camera-facing normal.
|
|
81533
|
+
sampleNormal.cross(vb, va);
|
|
81534
|
+
if (sampleNormal.lengthSq() <= NORMAL_EPSILON$1) {
|
|
81535
|
+
continue;
|
|
81536
|
+
}
|
|
81537
|
+
const candidate = sampleNormal.clone().normalize();
|
|
81538
|
+
if (candidate.dot(toCamera) < 0) {
|
|
81539
|
+
candidate.mulScalar(-1);
|
|
81540
|
+
}
|
|
81541
|
+
candidates.push(candidate);
|
|
81542
|
+
}
|
|
81543
|
+
});
|
|
81544
|
+
const normal = new Vec3();
|
|
81545
|
+
candidates.forEach((candidate) => {
|
|
81546
|
+
normal.add(candidate);
|
|
81547
|
+
});
|
|
81548
|
+
if (normal.lengthSq() > NORMAL_EPSILON$1) {
|
|
81549
|
+
normal.normalize();
|
|
81550
|
+
const refined = new Vec3();
|
|
81551
|
+
candidates.forEach((candidate) => {
|
|
81552
|
+
if (candidate.dot(normal) >= NORMAL_OUTLIER_MIN_DOT) {
|
|
81553
|
+
refined.add(candidate);
|
|
81554
|
+
}
|
|
81555
|
+
});
|
|
81556
|
+
if (refined.lengthSq() > NORMAL_EPSILON$1) {
|
|
81557
|
+
normal.copy(refined).normalize();
|
|
81558
|
+
}
|
|
81559
|
+
}
|
|
81560
|
+
else {
|
|
81561
|
+
normal.copy(toCamera);
|
|
81562
|
+
}
|
|
81563
|
+
return {
|
|
81564
|
+
position,
|
|
81565
|
+
normal
|
|
81566
|
+
};
|
|
81567
|
+
};
|
|
81568
|
+
this.pick = (x, y) => serializePick(() => pick(x, y));
|
|
81569
|
+
this.pickSurface = (x, y) => serializePick(() => pickSurface(x, y));
|
|
81570
|
+
this.release = () => {
|
|
81571
|
+
if (chunksPatched) {
|
|
81572
|
+
unregisterPickerShaderPatches(app);
|
|
81573
|
+
chunksPatched = false;
|
|
81574
|
+
}
|
|
81575
|
+
enginePicker?.destroy();
|
|
81576
|
+
accumPass?.destroy();
|
|
81577
|
+
accumTarget?.destroy();
|
|
81578
|
+
accumBuffer?.destroy();
|
|
81579
|
+
};
|
|
81580
|
+
}
|
|
81581
|
+
}
|
|
81582
|
+
|
|
80647
81583
|
// ---------------------------------------------------------------------------
|
|
80648
81584
|
// WGSL compute shader: ray-march through the sparse voxel octree per pixel
|
|
80649
81585
|
// ---------------------------------------------------------------------------
|
|
@@ -81280,6 +82216,26 @@ const CIRCLE_OUTER_RADIUS = 0.2;
|
|
|
81280
82216
|
const CIRCLE_INNER_RADIUS = 0.17;
|
|
81281
82217
|
const BEZIER_K = 1 / 6;
|
|
81282
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();
|
|
81283
82239
|
const tmpV = new Vec3();
|
|
81284
82240
|
const tmpScreen = new Vec3();
|
|
81285
82241
|
const tangent = new Vec3();
|
|
@@ -81303,35 +82259,66 @@ const buildBezierRing = (sx, sy) => {
|
|
|
81303
82259
|
}
|
|
81304
82260
|
return `${p} Z`;
|
|
81305
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
|
+
};
|
|
81306
82283
|
class WalkCursor {
|
|
81307
82284
|
svg;
|
|
81308
82285
|
cursorPath;
|
|
81309
82286
|
targetPath;
|
|
81310
|
-
app;
|
|
81311
82287
|
camera;
|
|
81312
82288
|
collision;
|
|
81313
82289
|
canvas;
|
|
82290
|
+
state;
|
|
82291
|
+
picker;
|
|
81314
82292
|
active = false;
|
|
81315
82293
|
walking = false;
|
|
81316
82294
|
targetPos = null;
|
|
81317
82295
|
targetNormal = null;
|
|
82296
|
+
targetMode = null;
|
|
81318
82297
|
smoothNx = 0;
|
|
81319
82298
|
smoothNy = 1;
|
|
81320
82299
|
smoothNz = 0;
|
|
81321
82300
|
hasSmoothedNormal = false;
|
|
82301
|
+
surfaceCursorX = 0;
|
|
82302
|
+
surfaceCursorY = 0;
|
|
82303
|
+
hasSurfaceCursorPosition = false;
|
|
82304
|
+
surfaceCursorVersion = 0;
|
|
82305
|
+
surfaceCursorPickPending = false;
|
|
81322
82306
|
onPointerMove;
|
|
81323
82307
|
onPointerLeave;
|
|
81324
|
-
scratchX = new Float64Array(NUM_SAMPLES);
|
|
81325
|
-
scratchY = new Float64Array(NUM_SAMPLES);
|
|
81326
82308
|
outerX = new Float64Array(NUM_SAMPLES);
|
|
81327
82309
|
outerY = new Float64Array(NUM_SAMPLES);
|
|
81328
82310
|
innerX = new Float64Array(NUM_SAMPLES);
|
|
81329
82311
|
innerY = new Float64Array(NUM_SAMPLES);
|
|
81330
|
-
|
|
81331
|
-
|
|
82312
|
+
collisionTarget = {
|
|
82313
|
+
position: new Vec3(),
|
|
82314
|
+
normal: new Vec3()
|
|
82315
|
+
};
|
|
82316
|
+
constructor(app, camera, collision, events, state, picker) {
|
|
81332
82317
|
this.camera = camera;
|
|
81333
82318
|
this.collision = collision;
|
|
81334
82319
|
this.canvas = app.graphicsDevice.canvas;
|
|
82320
|
+
this.state = state;
|
|
82321
|
+
this.picker = picker;
|
|
81335
82322
|
this.svg = document.createElementNS(SVGNS, 'svg');
|
|
81336
82323
|
this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
|
|
81337
82324
|
this.canvas.parentElement.appendChild(this.svg);
|
|
@@ -81342,38 +82329,59 @@ class WalkCursor {
|
|
|
81342
82329
|
this.cursorPath.setAttribute('fill-rule', 'evenodd');
|
|
81343
82330
|
this.cursorPath.setAttribute('stroke', 'none');
|
|
81344
82331
|
this.svg.appendChild(this.cursorPath);
|
|
81345
|
-
//
|
|
82332
|
+
// Selected target cursor: same ring geometry as hover.
|
|
81346
82333
|
this.targetPath = document.createElementNS(SVGNS, 'path');
|
|
81347
82334
|
this.targetPath.setAttribute('fill', 'white');
|
|
81348
|
-
this.targetPath.setAttribute('fill-opacity', '0.
|
|
82335
|
+
this.targetPath.setAttribute('fill-opacity', '0.6');
|
|
82336
|
+
this.targetPath.setAttribute('fill-rule', 'evenodd');
|
|
81349
82337
|
this.targetPath.setAttribute('stroke', 'none');
|
|
81350
82338
|
this.targetPath.style.display = 'none';
|
|
81351
82339
|
this.svg.appendChild(this.targetPath);
|
|
81352
82340
|
this.svg.style.display = 'none';
|
|
81353
82341
|
this.onPointerMove = (e) => {
|
|
81354
|
-
if (e.pointerType === 'touch')
|
|
82342
|
+
if (e.pointerType === 'touch') {
|
|
82343
|
+
this.hasSurfaceCursorPosition = false;
|
|
82344
|
+
this.surfaceCursorVersion++;
|
|
82345
|
+
this.hideCursor();
|
|
81355
82346
|
return;
|
|
82347
|
+
}
|
|
81356
82348
|
if (e.buttons) {
|
|
81357
|
-
this.
|
|
81358
|
-
this.
|
|
82349
|
+
this.hasSurfaceCursorPosition = false;
|
|
82350
|
+
this.surfaceCursorVersion++;
|
|
82351
|
+
this.hideCursor();
|
|
81359
82352
|
return;
|
|
81360
82353
|
}
|
|
81361
82354
|
this.updateCursor(e.offsetX, e.offsetY);
|
|
81362
82355
|
};
|
|
81363
82356
|
this.onPointerLeave = () => {
|
|
81364
|
-
this.
|
|
81365
|
-
this.
|
|
82357
|
+
this.hasSurfaceCursorPosition = false;
|
|
82358
|
+
this.surfaceCursorVersion++;
|
|
82359
|
+
this.hideCursor();
|
|
81366
82360
|
};
|
|
81367
82361
|
this.canvas.addEventListener('pointermove', this.onPointerMove);
|
|
81368
82362
|
this.canvas.addEventListener('pointerleave', this.onPointerLeave);
|
|
81369
82363
|
const updateActive = () => {
|
|
81370
|
-
|
|
81371
|
-
|
|
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
|
+
}
|
|
81372
82379
|
if (!this.active) {
|
|
81373
82380
|
this.svg.style.display = 'none';
|
|
81374
82381
|
}
|
|
81375
82382
|
};
|
|
81376
82383
|
events.on('cameraMode:changed', updateActive);
|
|
82384
|
+
events.on('inputMode:changed', updateActive);
|
|
81377
82385
|
events.on('gamingControls:changed', updateActive);
|
|
81378
82386
|
events.on('walkTo', () => {
|
|
81379
82387
|
this.walking = true;
|
|
@@ -81389,27 +82397,70 @@ class WalkCursor {
|
|
|
81389
82397
|
this.clearTarget();
|
|
81390
82398
|
});
|
|
81391
82399
|
events.on('walkTarget:set', (pos, normal) => {
|
|
81392
|
-
this.setTarget(pos, normal);
|
|
82400
|
+
this.setTarget(pos, normal, 'walk');
|
|
81393
82401
|
});
|
|
81394
82402
|
events.on('walkTarget:clear', () => {
|
|
81395
82403
|
this.clearTarget();
|
|
81396
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
|
+
});
|
|
81397
82433
|
app.on('prerender', () => {
|
|
81398
82434
|
this.updateTarget();
|
|
81399
82435
|
});
|
|
81400
82436
|
updateActive();
|
|
81401
82437
|
}
|
|
81402
|
-
setTarget(pos, normal) {
|
|
82438
|
+
setTarget(pos, normal, mode) {
|
|
82439
|
+
this.surfaceCursorVersion++;
|
|
81403
82440
|
this.targetPos = pos.clone();
|
|
81404
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;
|
|
81405
82446
|
}
|
|
81406
82447
|
clearTarget() {
|
|
82448
|
+
const mode = this.targetMode;
|
|
81407
82449
|
this.targetPos = null;
|
|
81408
82450
|
this.targetNormal = null;
|
|
82451
|
+
this.targetMode = null;
|
|
82452
|
+
if (mode === 'orbit') {
|
|
82453
|
+
this.cursorPath.style.display = 'none';
|
|
82454
|
+
}
|
|
81409
82455
|
this.targetPath.style.display = 'none';
|
|
82456
|
+
this.refreshSurfaceCursor();
|
|
82457
|
+
}
|
|
82458
|
+
hideCursor() {
|
|
82459
|
+
this.cursorPath.style.display = 'none';
|
|
82460
|
+
this.hasSmoothedNormal = false;
|
|
81410
82461
|
}
|
|
81411
82462
|
projectCircle(px, py, pz, nx, ny, nz, radius, outX, outY) {
|
|
81412
|
-
const normal =
|
|
82463
|
+
const normal = snapNormal(nx, ny, nz, tmpV);
|
|
81413
82464
|
if (Math.abs(normal.y) < 0.99) {
|
|
81414
82465
|
tangent.cross(normal, up).normalize();
|
|
81415
82466
|
}
|
|
@@ -81432,11 +82483,16 @@ class WalkCursor {
|
|
|
81432
82483
|
outY[i] = tmpScreen.y;
|
|
81433
82484
|
}
|
|
81434
82485
|
}
|
|
81435
|
-
|
|
81436
|
-
|
|
81437
|
-
|
|
81438
|
-
|
|
81439
|
-
|
|
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;
|
|
81440
82496
|
}
|
|
81441
82497
|
const { camera, collision } = this;
|
|
81442
82498
|
const cameraPos = camera.getPosition();
|
|
@@ -81444,17 +82500,28 @@ class WalkCursor {
|
|
|
81444
82500
|
tmpV.sub(cameraPos).normalize();
|
|
81445
82501
|
const hit = collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV.x, tmpV.y, tmpV.z, camera.camera.farClip);
|
|
81446
82502
|
if (!hit) {
|
|
81447
|
-
|
|
81448
|
-
this.hasSmoothedNormal = false;
|
|
81449
|
-
return;
|
|
82503
|
+
return null;
|
|
81450
82504
|
}
|
|
81451
|
-
const px = hit.x;
|
|
81452
|
-
const py = hit.y;
|
|
81453
|
-
const pz = hit.z;
|
|
81454
82505
|
const sn = collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV.x, tmpV.y, tmpV.z);
|
|
81455
|
-
|
|
81456
|
-
|
|
81457
|
-
|
|
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;
|
|
81458
82525
|
if (this.hasSmoothedNormal) {
|
|
81459
82526
|
const t = NORMAL_SMOOTH_FACTOR;
|
|
81460
82527
|
nx = this.smoothNx + (nx - this.smoothNx) * t;
|
|
@@ -81472,11 +82539,76 @@ class WalkCursor {
|
|
|
81472
82539
|
this.smoothNy = ny;
|
|
81473
82540
|
this.smoothNz = nz;
|
|
81474
82541
|
this.hasSmoothedNormal = true;
|
|
81475
|
-
this.
|
|
81476
|
-
|
|
81477
|
-
|
|
81478
|
-
this.
|
|
81479
|
-
|
|
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);
|
|
81480
82612
|
}
|
|
81481
82613
|
updateTarget() {
|
|
81482
82614
|
if (!this.active || !this.targetPos || !this.targetNormal) {
|
|
@@ -81484,14 +82616,11 @@ class WalkCursor {
|
|
|
81484
82616
|
}
|
|
81485
82617
|
const camPos = this.camera.getPosition();
|
|
81486
82618
|
const dist = camPos.distance(this.targetPos);
|
|
81487
|
-
if (dist < 2.0) {
|
|
82619
|
+
if (this.targetMode !== 'orbit' && dist < 2.0) {
|
|
81488
82620
|
this.targetPath.style.display = 'none';
|
|
81489
82621
|
return;
|
|
81490
82622
|
}
|
|
81491
|
-
this.
|
|
81492
|
-
this.targetPath.setAttribute('d', buildBezierRing(this.scratchX, this.scratchY));
|
|
81493
|
-
this.targetPath.style.display = '';
|
|
81494
|
-
this.svg.style.display = '';
|
|
82623
|
+
this.renderRing(this.targetPath, this.targetPos, this.targetNormal);
|
|
81495
82624
|
}
|
|
81496
82625
|
destroy() {
|
|
81497
82626
|
this.canvas.removeEventListener('pointermove', this.onPointerMove);
|
|
@@ -81602,6 +82731,7 @@ class Viewer {
|
|
|
81602
82731
|
cameraFrame;
|
|
81603
82732
|
inputController;
|
|
81604
82733
|
cameraManager;
|
|
82734
|
+
picker;
|
|
81605
82735
|
annotations;
|
|
81606
82736
|
forceRenderNextFrame = false;
|
|
81607
82737
|
voxelOverlay = null;
|
|
@@ -81750,7 +82880,8 @@ class Viewer {
|
|
|
81750
82880
|
if (!config.noui) {
|
|
81751
82881
|
this.annotations = new Annotations(global, this.cameraFrame != null);
|
|
81752
82882
|
}
|
|
81753
|
-
this.
|
|
82883
|
+
this.picker = new Picker(app, camera);
|
|
82884
|
+
this.inputController = new InputController(global, this.picker);
|
|
81754
82885
|
this.inputController.collision = collision ?? null;
|
|
81755
82886
|
state.hasCollision = !!collision;
|
|
81756
82887
|
// Create collision debug overlay (voxel uses a compute shader, mesh
|
|
@@ -81774,8 +82905,8 @@ class Viewer {
|
|
|
81774
82905
|
}
|
|
81775
82906
|
this.cameraManager = new CameraManager(global, sceneBound, collision);
|
|
81776
82907
|
applyCamera(this.cameraManager.camera);
|
|
81777
|
-
if (
|
|
81778
|
-
this.walkCursor = new WalkCursor(app, camera, collision, events, state);
|
|
82908
|
+
if (!config.noui) {
|
|
82909
|
+
this.walkCursor = new WalkCursor(app, camera, collision ?? null, events, state, this.picker);
|
|
81779
82910
|
}
|
|
81780
82911
|
const { instance } = gsplat;
|
|
81781
82912
|
if (instance) {
|
|
@@ -81825,7 +82956,8 @@ class Viewer {
|
|
|
81825
82956
|
}
|
|
81826
82957
|
else {
|
|
81827
82958
|
// reveal once low lod has loaded for fastest possible reveal
|
|
81828
|
-
const
|
|
82959
|
+
const resource = results[0].gsplat.resource;
|
|
82960
|
+
const lodLevels = resource?.octree?.lodLevels;
|
|
81829
82961
|
if (lodLevels) {
|
|
81830
82962
|
gsplat.lodRangeMax = gsplat.lodRangeMin = lodLevels - 1;
|
|
81831
82963
|
}
|
|
@@ -82863,7 +83995,7 @@ const initXr = (global) => {
|
|
|
82863
83995
|
});
|
|
82864
83996
|
};
|
|
82865
83997
|
|
|
82866
|
-
var version = "1.
|
|
83998
|
+
var version = "1.22.0";
|
|
82867
83999
|
|
|
82868
84000
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
82869
84001
|
const { contents, contentUrl, aa } = config;
|