@playcanvas/supersplat-viewer 1.20.3 → 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 +11 -3
- package/public/index.js +2280 -853
- package/public/index.js.map +1 -1
package/public/index.js
CHANGED
|
@@ -3684,6 +3684,7 @@ const FILTER_NEAREST_MIPMAP_LINEAR = 3;
|
|
|
3684
3684
|
const FILTER_LINEAR_MIPMAP_NEAREST = 4;
|
|
3685
3685
|
const FILTER_LINEAR_MIPMAP_LINEAR = 5;
|
|
3686
3686
|
const FUNC_LESS = 1;
|
|
3687
|
+
const FUNC_EQUAL = 2;
|
|
3687
3688
|
const FUNC_LESSEQUAL = 3;
|
|
3688
3689
|
const FUNC_ALWAYS = 7;
|
|
3689
3690
|
const INDEXFORMAT_UINT8 = 0;
|
|
@@ -19533,11 +19534,11 @@ const tmpMat4 = new Mat4();
|
|
|
19533
19534
|
const tmpQuat = new Quat();
|
|
19534
19535
|
const position = new Vec3();
|
|
19535
19536
|
const invParentWtm = new Mat4();
|
|
19536
|
-
const rotation$
|
|
19537
|
+
const rotation$2 = new Quat();
|
|
19537
19538
|
const invParentRot = new Quat();
|
|
19538
19539
|
const matrix = new Mat4();
|
|
19539
19540
|
const target = new Vec3();
|
|
19540
|
-
const up$
|
|
19541
|
+
const up$3 = new Vec3();
|
|
19541
19542
|
function createTest(attr, value) {
|
|
19542
19543
|
if (attr instanceof Function) {
|
|
19543
19544
|
return attr;
|
|
@@ -19907,16 +19908,16 @@ class GraphNode extends EventHandler {
|
|
|
19907
19908
|
}
|
|
19908
19909
|
setRotation(x, y, z, w) {
|
|
19909
19910
|
if (x instanceof Quat) {
|
|
19910
|
-
rotation$
|
|
19911
|
+
rotation$2.copy(x);
|
|
19911
19912
|
} else {
|
|
19912
|
-
rotation$
|
|
19913
|
+
rotation$2.set(x, y, z, w);
|
|
19913
19914
|
}
|
|
19914
19915
|
if (this._parent === null) {
|
|
19915
|
-
this.localRotation.copy(rotation$
|
|
19916
|
+
this.localRotation.copy(rotation$2);
|
|
19916
19917
|
} else {
|
|
19917
19918
|
const parentRot = this._parent.getRotation();
|
|
19918
19919
|
invParentRot.copy(parentRot).invert();
|
|
19919
|
-
this.localRotation.copy(invParentRot).mul(rotation$
|
|
19920
|
+
this.localRotation.copy(invParentRot).mul(rotation$2);
|
|
19920
19921
|
}
|
|
19921
19922
|
if (!this._dirtyLocal) {
|
|
19922
19923
|
this._dirtifyLocal();
|
|
@@ -20070,19 +20071,19 @@ class GraphNode extends EventHandler {
|
|
|
20070
20071
|
if (x instanceof Vec3) {
|
|
20071
20072
|
target.copy(x);
|
|
20072
20073
|
if (y instanceof Vec3) {
|
|
20073
|
-
up$
|
|
20074
|
+
up$3.copy(y);
|
|
20074
20075
|
} else {
|
|
20075
|
-
up$
|
|
20076
|
+
up$3.copy(Vec3.UP);
|
|
20076
20077
|
}
|
|
20077
20078
|
} else if (z === undefined) {
|
|
20078
20079
|
return;
|
|
20079
20080
|
} else {
|
|
20080
20081
|
target.set(x, y, z);
|
|
20081
|
-
up$
|
|
20082
|
+
up$3.set(ux, uy, uz);
|
|
20082
20083
|
}
|
|
20083
|
-
matrix.setLookAt(this.getPosition(), target, up$
|
|
20084
|
-
rotation$
|
|
20085
|
-
this.setRotation(rotation$
|
|
20084
|
+
matrix.setLookAt(this.getPosition(), target, up$3);
|
|
20085
|
+
rotation$2.setFromMat4(matrix);
|
|
20086
|
+
this.setRotation(rotation$2);
|
|
20086
20087
|
}
|
|
20087
20088
|
translate(x, y, z) {
|
|
20088
20089
|
if (x instanceof Vec3) {
|
|
@@ -20106,23 +20107,23 @@ class GraphNode extends EventHandler {
|
|
|
20106
20107
|
}
|
|
20107
20108
|
}
|
|
20108
20109
|
rotate(x, y, z) {
|
|
20109
|
-
rotation$
|
|
20110
|
+
rotation$2.setFromEulerAngles(x, y, z);
|
|
20110
20111
|
if (this._parent === null) {
|
|
20111
|
-
this.localRotation.mul2(rotation$
|
|
20112
|
+
this.localRotation.mul2(rotation$2, this.localRotation);
|
|
20112
20113
|
} else {
|
|
20113
20114
|
const rot = this.getRotation();
|
|
20114
20115
|
const parentRot = this._parent.getRotation();
|
|
20115
20116
|
invParentRot.copy(parentRot).invert();
|
|
20116
|
-
rotation$
|
|
20117
|
-
this.localRotation.mul2(rotation$
|
|
20117
|
+
rotation$2.mul2(invParentRot, rotation$2);
|
|
20118
|
+
this.localRotation.mul2(rotation$2, rot);
|
|
20118
20119
|
}
|
|
20119
20120
|
if (!this._dirtyLocal) {
|
|
20120
20121
|
this._dirtifyLocal();
|
|
20121
20122
|
}
|
|
20122
20123
|
}
|
|
20123
20124
|
rotateLocal(x, y, z) {
|
|
20124
|
-
rotation$
|
|
20125
|
-
this.localRotation.mul(rotation$
|
|
20125
|
+
rotation$2.setFromEulerAngles(x, y, z);
|
|
20126
|
+
this.localRotation.mul(rotation$2);
|
|
20126
20127
|
if (!this._dirtyLocal) {
|
|
20127
20128
|
this._dirtifyLocal();
|
|
20128
20129
|
}
|
|
@@ -33142,7 +33143,7 @@ class CustomRenderPass extends RenderPass {
|
|
|
33142
33143
|
}
|
|
33143
33144
|
}
|
|
33144
33145
|
const invModelMat$1 = new Mat4();
|
|
33145
|
-
const dir
|
|
33146
|
+
const dir = new Vec3();
|
|
33146
33147
|
class GSplatResolveSH {
|
|
33147
33148
|
destroy() {
|
|
33148
33149
|
const { gsplatInstance } = this;
|
|
@@ -33164,17 +33165,17 @@ class GSplatResolveSH {
|
|
|
33164
33165
|
return;
|
|
33165
33166
|
}
|
|
33166
33167
|
invModelMat$1.invert(modelMat);
|
|
33167
|
-
invModelMat$1.transformVector(camera.forward, dir
|
|
33168
|
-
dir
|
|
33169
|
-
if (updateMode === 'enable' && dir
|
|
33168
|
+
invModelMat$1.transformVector(camera.forward, dir);
|
|
33169
|
+
dir.normalize();
|
|
33170
|
+
if (updateMode === 'enable' && dir.equalsApprox(prevDir, 1e-3)) {
|
|
33170
33171
|
return;
|
|
33171
33172
|
}
|
|
33172
|
-
prevDir.copy(dir
|
|
33173
|
+
prevDir.copy(dir);
|
|
33173
33174
|
const execute = ()=>{
|
|
33174
33175
|
const { device } = this;
|
|
33175
33176
|
const { sh_centroids, meta } = this.gsplatInstance.resource.gsplatData;
|
|
33176
33177
|
resolve$1(device.scope, {
|
|
33177
|
-
dir: dir
|
|
33178
|
+
dir: dir.toArray(),
|
|
33178
33179
|
centroids: sh_centroids,
|
|
33179
33180
|
shN_mins: meta.shN.mins,
|
|
33180
33181
|
shN_maxs: meta.shN.maxs
|
|
@@ -73162,73 +73163,6 @@ class CameraFrame {
|
|
|
73162
73163
|
}
|
|
73163
73164
|
}
|
|
73164
73165
|
|
|
73165
|
-
const tmpV1$1 = new Vec3();
|
|
73166
|
-
const rotation$4 = new Quat();
|
|
73167
|
-
class Pose {
|
|
73168
|
-
copy(other) {
|
|
73169
|
-
return this.set(other.position, other.angles, other.distance);
|
|
73170
|
-
}
|
|
73171
|
-
clone() {
|
|
73172
|
-
return new Pose(this.position.clone(), this.angles.clone(), this.distance);
|
|
73173
|
-
}
|
|
73174
|
-
equalsApprox(other, epsilon = 1e-6) {
|
|
73175
|
-
return this.position.equalsApprox(other.position, epsilon) && this.angles.equalsApprox(other.angles, epsilon) && Math.abs(this.distance - other.distance) < epsilon;
|
|
73176
|
-
}
|
|
73177
|
-
lerp(lhs, rhs, alpha1, alpha2 = alpha1, alpha3 = alpha1) {
|
|
73178
|
-
this.position.lerp(lhs.position, rhs.position, alpha1);
|
|
73179
|
-
this.angles.x = math.lerpAngle(lhs.angles.x, rhs.angles.x, alpha2) % 360;
|
|
73180
|
-
this.angles.y = math.lerpAngle(lhs.angles.y, rhs.angles.y, alpha2) % 360;
|
|
73181
|
-
this.angles.z = math.lerpAngle(lhs.angles.z, rhs.angles.z, alpha2) % 360;
|
|
73182
|
-
this.distance = math.lerp(lhs.distance, rhs.distance, alpha3);
|
|
73183
|
-
return this;
|
|
73184
|
-
}
|
|
73185
|
-
move(offset) {
|
|
73186
|
-
this.position.add(offset);
|
|
73187
|
-
this.position.x = math.clamp(this.position.x, this.xRange.x, this.xRange.y);
|
|
73188
|
-
this.position.y = math.clamp(this.position.y, this.yRange.x, this.yRange.y);
|
|
73189
|
-
this.position.z = math.clamp(this.position.z, this.zRange.x, this.zRange.y);
|
|
73190
|
-
return this;
|
|
73191
|
-
}
|
|
73192
|
-
rotate(euler) {
|
|
73193
|
-
this.angles.add(euler);
|
|
73194
|
-
this.angles.x %= 360;
|
|
73195
|
-
this.angles.y %= 360;
|
|
73196
|
-
this.angles.z %= 360;
|
|
73197
|
-
this.angles.x = math.clamp(this.angles.x, this.pitchRange.x, this.pitchRange.y);
|
|
73198
|
-
this.angles.y = math.clamp(this.angles.y, this.yawRange.x, this.yawRange.y);
|
|
73199
|
-
return this;
|
|
73200
|
-
}
|
|
73201
|
-
set(position, angles, distance) {
|
|
73202
|
-
this.position.copy(position);
|
|
73203
|
-
this.angles.copy(angles);
|
|
73204
|
-
this.distance = distance;
|
|
73205
|
-
return this;
|
|
73206
|
-
}
|
|
73207
|
-
look(from, to) {
|
|
73208
|
-
this.position.copy(from);
|
|
73209
|
-
this.distance = from.distance(to);
|
|
73210
|
-
const dir = tmpV1$1.sub2(to, from).normalize();
|
|
73211
|
-
const elev = Math.atan2(-dir.y, Math.sqrt(dir.x * dir.x + dir.z * dir.z)) * math.RAD_TO_DEG;
|
|
73212
|
-
const azim = Math.atan2(-dir.x, -dir.z) * math.RAD_TO_DEG;
|
|
73213
|
-
this.angles.set(-elev, azim, 0);
|
|
73214
|
-
return this;
|
|
73215
|
-
}
|
|
73216
|
-
getFocus(out) {
|
|
73217
|
-
return rotation$4.setFromEulerAngles(this.angles).transformVector(Vec3.FORWARD, out).mulScalar(this.distance).add(this.position);
|
|
73218
|
-
}
|
|
73219
|
-
constructor(position = Vec3.ZERO, angles = Vec3.ZERO, distance = 0){
|
|
73220
|
-
this.position = new Vec3();
|
|
73221
|
-
this.angles = new Vec3();
|
|
73222
|
-
this.distance = 0;
|
|
73223
|
-
this.pitchRange = new Vec2(-Infinity, Infinity);
|
|
73224
|
-
this.yawRange = new Vec2(-Infinity, Infinity);
|
|
73225
|
-
this.xRange = new Vec2(-Infinity, Infinity);
|
|
73226
|
-
this.yRange = new Vec2(-Infinity, Infinity);
|
|
73227
|
-
this.zRange = new Vec2(-Infinity, Infinity);
|
|
73228
|
-
this.set(position, angles, distance);
|
|
73229
|
-
}
|
|
73230
|
-
}
|
|
73231
|
-
|
|
73232
73166
|
class InputDelta {
|
|
73233
73167
|
add(other) {
|
|
73234
73168
|
for(let i = 0; i < this._value.length; i++){
|
|
@@ -73314,25 +73248,6 @@ class InputSource extends InputFrame {
|
|
|
73314
73248
|
super(...args), this._element = null, this._events = new EventHandler();
|
|
73315
73249
|
}
|
|
73316
73250
|
}
|
|
73317
|
-
class InputConsumer {
|
|
73318
|
-
update(frame, dt) {
|
|
73319
|
-
frame.read();
|
|
73320
|
-
}
|
|
73321
|
-
}
|
|
73322
|
-
let InputController$1 = class InputController extends InputConsumer {
|
|
73323
|
-
attach(pose, smooth = true) {}
|
|
73324
|
-
detach() {}
|
|
73325
|
-
update(frame, dt) {
|
|
73326
|
-
super.update(frame, dt);
|
|
73327
|
-
return this._pose;
|
|
73328
|
-
}
|
|
73329
|
-
destroy() {
|
|
73330
|
-
this.detach();
|
|
73331
|
-
}
|
|
73332
|
-
constructor(...args){
|
|
73333
|
-
super(...args), this._pose = new Pose();
|
|
73334
|
-
}
|
|
73335
|
-
};
|
|
73336
73251
|
|
|
73337
73252
|
const movementState = ()=>{
|
|
73338
73253
|
const state = new Map();
|
|
@@ -73366,60 +73281,6 @@ const movementState = ()=>{
|
|
|
73366
73281
|
};
|
|
73367
73282
|
};
|
|
73368
73283
|
|
|
73369
|
-
const damp$1 = (damping, dt)=>1 - Math.pow(damping, dt * 1000);
|
|
73370
|
-
|
|
73371
|
-
const offset$2 = new Vec3();
|
|
73372
|
-
const angles$1 = new Vec3();
|
|
73373
|
-
const forward$1 = new Vec3();
|
|
73374
|
-
const right$2 = new Vec3();
|
|
73375
|
-
const up$1 = new Vec3();
|
|
73376
|
-
const rotation$3 = new Quat();
|
|
73377
|
-
let FlyController$1 = class FlyController extends InputController$1 {
|
|
73378
|
-
set pitchRange(value) {
|
|
73379
|
-
this._targetPose.pitchRange.copy(value);
|
|
73380
|
-
this._pose.copy(this._targetPose.rotate(Vec3.ZERO));
|
|
73381
|
-
}
|
|
73382
|
-
get pitchRange() {
|
|
73383
|
-
return this._targetPose.pitchRange;
|
|
73384
|
-
}
|
|
73385
|
-
set yawRange(value) {
|
|
73386
|
-
this._targetPose.yawRange.copy(value);
|
|
73387
|
-
this._pose.copy(this._targetPose.rotate(Vec3.ZERO));
|
|
73388
|
-
}
|
|
73389
|
-
get yawRange() {
|
|
73390
|
-
return this._targetPose.yawRange;
|
|
73391
|
-
}
|
|
73392
|
-
attach(pose, smooth = true) {
|
|
73393
|
-
this._targetPose.copy(pose);
|
|
73394
|
-
if (!smooth) {
|
|
73395
|
-
this._pose.copy(this._targetPose);
|
|
73396
|
-
}
|
|
73397
|
-
}
|
|
73398
|
-
detach() {
|
|
73399
|
-
this._targetPose.copy(this._pose);
|
|
73400
|
-
}
|
|
73401
|
-
update(frame, dt) {
|
|
73402
|
-
const { move, rotate } = frame.read();
|
|
73403
|
-
this._targetPose.rotate(angles$1.set(-rotate[1], -rotate[0], 0));
|
|
73404
|
-
rotation$3.setFromEulerAngles(this._pose.angles);
|
|
73405
|
-
rotation$3.transformVector(Vec3.FORWARD, forward$1);
|
|
73406
|
-
rotation$3.transformVector(Vec3.RIGHT, right$2);
|
|
73407
|
-
rotation$3.transformVector(Vec3.UP, up$1);
|
|
73408
|
-
offset$2.set(0, 0, 0);
|
|
73409
|
-
offset$2.add(forward$1.mulScalar(move[2]));
|
|
73410
|
-
offset$2.add(right$2.mulScalar(move[0]));
|
|
73411
|
-
offset$2.add(up$1.mulScalar(move[1]));
|
|
73412
|
-
this._targetPose.move(offset$2);
|
|
73413
|
-
return this._pose.lerp(this._pose, this._targetPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt));
|
|
73414
|
-
}
|
|
73415
|
-
destroy() {
|
|
73416
|
-
this.detach();
|
|
73417
|
-
}
|
|
73418
|
-
constructor(...args){
|
|
73419
|
-
super(...args), this._targetPose = new Pose(), this.rotateDamping = 0.98, this.moveDamping = 0.98;
|
|
73420
|
-
}
|
|
73421
|
-
};
|
|
73422
|
-
|
|
73423
73284
|
const BUTTON_CODES = {
|
|
73424
73285
|
A: 0,
|
|
73425
73286
|
B: 1,
|
|
@@ -74875,65 +74736,6 @@ class MultiTouchSource extends InputSource {
|
|
|
74875
74736
|
}
|
|
74876
74737
|
}
|
|
74877
74738
|
|
|
74878
|
-
const dir = new Vec3();
|
|
74879
|
-
const offset$1 = new Vec3();
|
|
74880
|
-
const angles = new Vec3();
|
|
74881
|
-
const rotation$2 = new Quat();
|
|
74882
|
-
let OrbitController$1 = class OrbitController extends InputController$1 {
|
|
74883
|
-
set pitchRange(range) {
|
|
74884
|
-
this._targetRootPose.pitchRange.copy(range);
|
|
74885
|
-
this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
|
|
74886
|
-
}
|
|
74887
|
-
get pitchRange() {
|
|
74888
|
-
return this._targetRootPose.pitchRange;
|
|
74889
|
-
}
|
|
74890
|
-
set yawRange(range) {
|
|
74891
|
-
this._targetRootPose.yawRange.copy(range);
|
|
74892
|
-
this._rootPose.copy(this._targetRootPose.rotate(Vec3.ZERO));
|
|
74893
|
-
}
|
|
74894
|
-
get yawRange() {
|
|
74895
|
-
return this._targetRootPose.yawRange;
|
|
74896
|
-
}
|
|
74897
|
-
set zoomRange(range) {
|
|
74898
|
-
this._targetChildPose.zRange.copy(range);
|
|
74899
|
-
this._childPose.copy(this._targetChildPose.move(Vec3.ZERO));
|
|
74900
|
-
}
|
|
74901
|
-
get zoomRange() {
|
|
74902
|
-
return this._targetRootPose.zRange;
|
|
74903
|
-
}
|
|
74904
|
-
attach(pose, smooth = true) {
|
|
74905
|
-
this._targetRootPose.set(pose.getFocus(dir), pose.angles, 0);
|
|
74906
|
-
this._targetChildPose.position.set(0, 0, pose.distance);
|
|
74907
|
-
if (!smooth) {
|
|
74908
|
-
this._rootPose.copy(this._targetRootPose);
|
|
74909
|
-
this._childPose.copy(this._targetChildPose);
|
|
74910
|
-
}
|
|
74911
|
-
}
|
|
74912
|
-
detach() {
|
|
74913
|
-
this._targetRootPose.copy(this._rootPose);
|
|
74914
|
-
this._targetChildPose.copy(this._childPose);
|
|
74915
|
-
}
|
|
74916
|
-
update(frame, dt) {
|
|
74917
|
-
const { move, rotate } = frame.read();
|
|
74918
|
-
offset$1.set(move[0], move[1], 0);
|
|
74919
|
-
rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(offset$1, offset$1);
|
|
74920
|
-
this._targetRootPose.move(offset$1);
|
|
74921
|
-
const { z: dist } = this._targetChildPose.position;
|
|
74922
|
-
this._targetChildPose.move(offset$1.set(0, 0, dist * (1 + move[2]) - dist));
|
|
74923
|
-
this._targetRootPose.rotate(angles.set(-rotate[1], -rotate[0], 0));
|
|
74924
|
-
this._rootPose.lerp(this._rootPose, this._targetRootPose, damp$1(this.moveDamping, dt), damp$1(this.rotateDamping, dt), 1);
|
|
74925
|
-
this._childPose.lerp(this._childPose, this._targetChildPose, damp$1(this.zoomDamping, dt), 1, 1);
|
|
74926
|
-
rotation$2.setFromEulerAngles(this._rootPose.angles).transformVector(this._childPose.position, offset$1).add(this._rootPose.position);
|
|
74927
|
-
return this._pose.set(offset$1, this._rootPose.angles, this._childPose.position.z);
|
|
74928
|
-
}
|
|
74929
|
-
destroy() {
|
|
74930
|
-
this.detach();
|
|
74931
|
-
}
|
|
74932
|
-
constructor(...args){
|
|
74933
|
-
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;
|
|
74934
|
-
}
|
|
74935
|
-
};
|
|
74936
|
-
|
|
74937
74739
|
class App extends AppBase {
|
|
74938
74740
|
constructor(canvas, options) {
|
|
74939
74741
|
super(canvas);
|
|
@@ -75351,6 +75153,16 @@ class MeshCollision {
|
|
|
75351
75153
|
this._tris = tris;
|
|
75352
75154
|
this._root = buildBVH(tris, 0, numTris);
|
|
75353
75155
|
}
|
|
75156
|
+
// ---- Public accessors ----
|
|
75157
|
+
/**
|
|
75158
|
+
* Read-only view of the de-indexed triangle data, used by debug overlays.
|
|
75159
|
+
* The underlying typed arrays are reused and must not be mutated.
|
|
75160
|
+
*
|
|
75161
|
+
* @returns the triangle SoA backing this collision.
|
|
75162
|
+
*/
|
|
75163
|
+
get triangles() {
|
|
75164
|
+
return this._tris;
|
|
75165
|
+
}
|
|
75354
75166
|
// ---- Collision interface ----
|
|
75355
75167
|
queryRay(ox, oy, oz, dx, dy, dz, maxDist) {
|
|
75356
75168
|
const len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
@@ -75692,7 +75504,7 @@ const SOLID_LEAF_MARKER = 0xFF000000 >>> 0;
|
|
|
75692
75504
|
/** Half-extent of the flatness sampling patch (5x5 when R=2). */
|
|
75693
75505
|
const FLAT_R = 2;
|
|
75694
75506
|
/** 1/sqrt(2), used to normalise 45-degree diagonal normals. */
|
|
75695
|
-
const INV_SQRT2 = 1 / Math.sqrt(2);
|
|
75507
|
+
const INV_SQRT2$1 = 1 / Math.sqrt(2);
|
|
75696
75508
|
/**
|
|
75697
75509
|
* Surface normal candidate directions for querySurfaceNormal.
|
|
75698
75510
|
* Each entry: [dx, dy, dz, t1x, t1y, t1z, t2x, t2y, t2z]
|
|
@@ -75936,7 +75748,7 @@ class VoxelCollision {
|
|
|
75936
75748
|
const score = scoreSurfaceCandidate(this, ix, iy, iz, sx, sy, sz, cand[3], cand[4], cand[5], cand[6], cand[7], cand[8]);
|
|
75937
75749
|
if (score > bestScore) {
|
|
75938
75750
|
bestScore = score;
|
|
75939
|
-
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;
|
|
75940
75752
|
bestNx = sx * mag;
|
|
75941
75753
|
bestNy = sy * mag;
|
|
75942
75754
|
bestNz = sz * mag;
|
|
@@ -76902,14 +76714,14 @@ const initUI = (global) => {
|
|
|
76902
76714
|
'orbitCamera', 'flyCamera', 'fpsCamera',
|
|
76903
76715
|
'performanceModeRow', 'performanceModeCheck', 'performanceModeOption',
|
|
76904
76716
|
'gamingControlsDivider', 'gamingControlsRow', 'gamingControlsCheck', 'gamingControlsOption',
|
|
76905
|
-
'desktopClickToWalk', 'desktopGamingControls',
|
|
76717
|
+
'desktopFlyClickToFly', 'desktopClickToWalk', 'desktopGamingControls',
|
|
76906
76718
|
'touchFlyClickToWalk', 'touchFlyGamingControls',
|
|
76907
76719
|
'touchClickToWalk', 'touchGamingControls',
|
|
76908
76720
|
'walkHint',
|
|
76909
76721
|
'reset', 'frame',
|
|
76910
76722
|
'loadingText', 'loadingBar',
|
|
76911
76723
|
'joystickBase', 'joystick',
|
|
76912
|
-
'
|
|
76724
|
+
'showCollision',
|
|
76913
76725
|
'tooltip',
|
|
76914
76726
|
'annotationNav', 'annotationPrev', 'annotationNext', 'annotationInfo', 'annotationNavTitle',
|
|
76915
76727
|
'supersplatBranding'
|
|
@@ -77020,10 +76832,9 @@ const initUI = (global) => {
|
|
|
77020
76832
|
updateGamingSettingsVisibility();
|
|
77021
76833
|
const updateGamingControls = () => {
|
|
77022
76834
|
dom.gamingControlsCheck.classList.toggle('active', state.gamingControls);
|
|
77023
|
-
|
|
77024
|
-
|
|
77025
|
-
|
|
77026
|
-
}
|
|
76835
|
+
dom.desktopFlyClickToFly.classList.toggle('hidden', state.gamingControls);
|
|
76836
|
+
dom.desktopClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
76837
|
+
dom.desktopGamingControls.classList.toggle('hidden', !state.gamingControls);
|
|
77027
76838
|
dom.touchFlyClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
77028
76839
|
dom.touchFlyGamingControls.classList.toggle('hidden', !state.gamingControls);
|
|
77029
76840
|
dom.touchClickToWalk.classList.toggle('hidden', state.gamingControls);
|
|
@@ -77031,6 +76842,7 @@ const initUI = (global) => {
|
|
|
77031
76842
|
localStorage.setItem('gamingControls', String(state.gamingControls));
|
|
77032
76843
|
};
|
|
77033
76844
|
events.on('gamingControls:changed', updateGamingControls);
|
|
76845
|
+
events.on('inputMode:changed', updateGamingControls);
|
|
77034
76846
|
updateGamingControls();
|
|
77035
76847
|
// AR/VR
|
|
77036
76848
|
const arChanged = () => dom.arMode.classList[state.hasAR ? 'remove' : 'add']('hidden');
|
|
@@ -77095,7 +76907,24 @@ const initUI = (global) => {
|
|
|
77095
76907
|
// show the ui and start a timer to hide it again
|
|
77096
76908
|
let uiTimeout = null;
|
|
77097
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
|
+
};
|
|
77098
76923
|
const showUI = () => {
|
|
76924
|
+
if (isPointerCapturedMode()) {
|
|
76925
|
+
hideUI();
|
|
76926
|
+
return;
|
|
76927
|
+
}
|
|
77099
76928
|
if (uiTimeout) {
|
|
77100
76929
|
clearTimeout(uiTimeout);
|
|
77101
76930
|
}
|
|
@@ -77113,6 +76942,17 @@ const initUI = (global) => {
|
|
|
77113
76942
|
showUI();
|
|
77114
76943
|
});
|
|
77115
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);
|
|
77116
76956
|
// keep UI visible while an annotation tooltip is shown
|
|
77117
76957
|
events.on('annotation.activate', () => {
|
|
77118
76958
|
annotationVisible = true;
|
|
@@ -77209,7 +77049,7 @@ const initUI = (global) => {
|
|
|
77209
77049
|
'Tap to walk. Drag to look around.';
|
|
77210
77050
|
};
|
|
77211
77051
|
events.on('cameraMode:changed', (value) => {
|
|
77212
|
-
if (value === 'walk' && !walkHintShown) {
|
|
77052
|
+
if (value === 'walk' && !walkHintShown && !isPointerCapturedMode()) {
|
|
77213
77053
|
walkHintShown = true;
|
|
77214
77054
|
dom.walkHint.textContent = getWalkHintText();
|
|
77215
77055
|
dom.walkHint.classList.remove('hidden');
|
|
@@ -77231,15 +77071,15 @@ const initUI = (global) => {
|
|
|
77231
77071
|
dom.flyCamera.classList.toggle('middle', value);
|
|
77232
77072
|
dom.flyCamera.classList.toggle('right', !value);
|
|
77233
77073
|
});
|
|
77234
|
-
//
|
|
77235
|
-
events.on('
|
|
77236
|
-
dom.
|
|
77074
|
+
// Collision overlay toggle (only visible when overlay is available)
|
|
77075
|
+
events.on('hasCollisionOverlay:changed', (value) => {
|
|
77076
|
+
dom.showCollision.classList.toggle('hidden', !value);
|
|
77237
77077
|
});
|
|
77238
|
-
dom.
|
|
77239
|
-
state.
|
|
77078
|
+
dom.showCollision.addEventListener('click', () => {
|
|
77079
|
+
state.collisionOverlayEnabled = !state.collisionOverlayEnabled;
|
|
77240
77080
|
});
|
|
77241
|
-
events.on('
|
|
77242
|
-
dom.
|
|
77081
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
77082
|
+
dom.showCollision.classList.toggle('active', value);
|
|
77243
77083
|
});
|
|
77244
77084
|
dom.settings.addEventListener('click', () => {
|
|
77245
77085
|
dom.settingsPanel.classList.toggle('hidden');
|
|
@@ -77276,7 +77116,7 @@ const initUI = (global) => {
|
|
|
77276
77116
|
tooltip.register(dom.fpsCamera, 'Walk Mode', 'top');
|
|
77277
77117
|
tooltip.register(dom.reset, 'Reset Camera', 'bottom');
|
|
77278
77118
|
tooltip.register(dom.frame, 'Frame Scene', 'bottom');
|
|
77279
|
-
tooltip.register(dom.
|
|
77119
|
+
tooltip.register(dom.showCollision, 'Show Collision', 'top');
|
|
77280
77120
|
tooltip.register(dom.settings, 'Settings', 'top');
|
|
77281
77121
|
tooltip.register(dom.info, 'Help', 'top');
|
|
77282
77122
|
tooltip.register(dom.arMode, 'Enter AR', 'top');
|
|
@@ -77838,7 +77678,9 @@ class Annotations {
|
|
|
77838
77678
|
this.parentDom = parentDom;
|
|
77839
77679
|
const { state } = global;
|
|
77840
77680
|
const updateVisibility = () => {
|
|
77841
|
-
const
|
|
77681
|
+
const firstPersonGamingControls = ((state.cameraMode === 'walk' || state.cameraMode === 'fly') &&
|
|
77682
|
+
state.gamingControls);
|
|
77683
|
+
const hidden = state.controlsHidden || firstPersonGamingControls;
|
|
77842
77684
|
parentDom.style.display = hidden ? 'none' : 'block';
|
|
77843
77685
|
Annotation.opacity = hidden ? 0.0 : 1.0;
|
|
77844
77686
|
if (this.annotations.length > 0) {
|
|
@@ -78305,97 +78147,647 @@ class Camera {
|
|
|
78305
78147
|
}
|
|
78306
78148
|
}
|
|
78307
78149
|
|
|
78308
|
-
|
|
78309
|
-
|
|
78310
|
-
|
|
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);
|
|
78311
78277
|
/** Pre-allocated push-out vector for sphere collision */
|
|
78312
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();
|
|
78313
78444
|
class FlyController {
|
|
78314
|
-
controller;
|
|
78315
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);
|
|
78316
78453
|
/** Optional collision for sphere collision with sliding */
|
|
78317
|
-
collision
|
|
78318
|
-
|
|
78319
|
-
this.
|
|
78320
|
-
|
|
78321
|
-
|
|
78322
|
-
this.
|
|
78454
|
+
set collision(value) {
|
|
78455
|
+
this._mover.collision = value;
|
|
78456
|
+
this._mover.reset(this._position);
|
|
78457
|
+
}
|
|
78458
|
+
get collision() {
|
|
78459
|
+
return this._mover.collision;
|
|
78323
78460
|
}
|
|
78461
|
+
_hasSpawn = false;
|
|
78324
78462
|
onEnter(camera) {
|
|
78325
|
-
|
|
78326
|
-
|
|
78327
|
-
|
|
78328
|
-
this.controller.attach(p$1, false);
|
|
78463
|
+
this.goto(camera);
|
|
78464
|
+
this._mover.resolve(this._position);
|
|
78465
|
+
this._storeSpawn();
|
|
78329
78466
|
}
|
|
78330
78467
|
update(deltaTime, inputFrame, camera) {
|
|
78331
|
-
const
|
|
78332
|
-
|
|
78333
|
-
|
|
78334
|
-
|
|
78335
|
-
|
|
78336
|
-
|
|
78337
|
-
|
|
78338
|
-
|
|
78339
|
-
|
|
78340
|
-
|
|
78341
|
-
|
|
78342
|
-
|
|
78343
|
-
|
|
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
|
+
}
|
|
78344
78563
|
}
|
|
78345
|
-
|
|
78346
|
-
|
|
78347
|
-
pose.position.y += pushOut.y;
|
|
78348
|
-
pose.position.z += pushOut.z;
|
|
78564
|
+
else {
|
|
78565
|
+
this._blockedTime = 0;
|
|
78349
78566
|
}
|
|
78350
78567
|
}
|
|
78351
|
-
|
|
78352
|
-
|
|
78568
|
+
this._prevDist = distance;
|
|
78569
|
+
return false;
|
|
78353
78570
|
}
|
|
78354
|
-
|
|
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;
|
|
78632
|
+
}
|
|
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
|
+
}
|
|
78355
78663
|
}
|
|
78356
|
-
|
|
78357
|
-
|
|
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
|
+
}
|
|
78358
78727
|
}
|
|
78359
78728
|
}
|
|
78360
78729
|
|
|
78361
|
-
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();
|
|
78362
78737
|
class OrbitController {
|
|
78363
|
-
controller;
|
|
78364
78738
|
fov = 90;
|
|
78365
|
-
|
|
78366
|
-
|
|
78367
|
-
|
|
78368
|
-
|
|
78369
|
-
|
|
78370
|
-
|
|
78371
|
-
|
|
78372
|
-
|
|
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;
|
|
78373
78748
|
onEnter(camera) {
|
|
78374
|
-
|
|
78375
|
-
p.angles.copy(camera.angles);
|
|
78376
|
-
p.distance = camera.distance;
|
|
78377
|
-
this.controller.attach(p, false);
|
|
78749
|
+
this._syncPose(camera, false);
|
|
78378
78750
|
}
|
|
78379
78751
|
update(deltaTime, inputFrame, camera) {
|
|
78380
|
-
const
|
|
78381
|
-
|
|
78382
|
-
|
|
78383
|
-
|
|
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;
|
|
78384
78765
|
camera.fov = this.fov;
|
|
78385
78766
|
}
|
|
78386
|
-
onExit(
|
|
78767
|
+
onExit(_camera) {
|
|
78387
78768
|
}
|
|
78388
78769
|
goto(camera) {
|
|
78389
|
-
|
|
78390
|
-
|
|
78391
|
-
|
|
78392
|
-
|
|
78393
|
-
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
|
+
}
|
|
78394
78783
|
}
|
|
78395
78784
|
}
|
|
78396
78785
|
|
|
78397
78786
|
const FIXED_DT = 1 / 60;
|
|
78398
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;
|
|
78399
78791
|
/** Pre-allocated push-out vector for capsule collision */
|
|
78400
78792
|
const out = { x: 0, y: 0, z: 0 };
|
|
78401
78793
|
const v = new Vec3();
|
|
@@ -78404,13 +78796,13 @@ const forward = new Vec3();
|
|
|
78404
78796
|
const right$1 = new Vec3();
|
|
78405
78797
|
const moveStep = [0, 0, 0];
|
|
78406
78798
|
const offset = new Vec3();
|
|
78407
|
-
const
|
|
78799
|
+
const spawnProbe = new Vec3();
|
|
78408
78800
|
/**
|
|
78409
|
-
* First-person camera controller with spring-damper suspension over
|
|
78801
|
+
* First-person camera controller with spring-damper suspension over collision terrain.
|
|
78410
78802
|
*
|
|
78411
78803
|
* Movement is constrained to the horizontal plane (XZ) relative to the camera yaw.
|
|
78412
78804
|
* Vertical positioning uses a spring-damper system that hovers the capsule above the
|
|
78413
|
-
*
|
|
78805
|
+
* collision surface, filtering out terrain noise for smooth camera motion. Capsule
|
|
78414
78806
|
* collision handles walls and obstacles. When airborne, normal gravity applies.
|
|
78415
78807
|
*/
|
|
78416
78808
|
class WalkController {
|
|
@@ -78468,7 +78860,7 @@ class WalkController {
|
|
|
78468
78860
|
velocityDampingAir = 0.998;
|
|
78469
78861
|
/**
|
|
78470
78862
|
* Target clearance from capsule bottom to ground surface in meters.
|
|
78471
|
-
* 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.
|
|
78472
78864
|
*/
|
|
78473
78865
|
hoverHeight = 0.2;
|
|
78474
78866
|
/**
|
|
@@ -78484,34 +78876,43 @@ class WalkController {
|
|
|
78484
78876
|
* Maximum downward raycast distance to search for ground below the capsule.
|
|
78485
78877
|
*/
|
|
78486
78878
|
groundProbeRange = 1.0;
|
|
78879
|
+
/**
|
|
78880
|
+
* Maximum vertical raycast distance to search for walk spawn ground.
|
|
78881
|
+
*/
|
|
78882
|
+
spawnSearchRange = 1000;
|
|
78487
78883
|
_position = new Vec3();
|
|
78488
78884
|
_prevPosition = new Vec3();
|
|
78489
78885
|
_angles = new Vec3();
|
|
78886
|
+
_distance = 1;
|
|
78887
|
+
_spawnPosition = new Vec3();
|
|
78888
|
+
_spawnAngles = new Vec3();
|
|
78889
|
+
_spawnDistance = 1;
|
|
78490
78890
|
_velocity = new Vec3();
|
|
78491
78891
|
_pendingMove = [0, 0, 0];
|
|
78492
78892
|
_accumulator = 0;
|
|
78493
78893
|
_grounded = false;
|
|
78494
78894
|
_jumping = false;
|
|
78495
78895
|
_jumpHeld = false;
|
|
78896
|
+
_spawnGrounded = false;
|
|
78897
|
+
_hasSpawn = false;
|
|
78496
78898
|
onEnter(camera) {
|
|
78497
78899
|
this.goto(camera);
|
|
78498
78900
|
if (this.collision) {
|
|
78499
|
-
this.
|
|
78500
|
-
this.
|
|
78501
|
-
|
|
78502
|
-
if (groundY !== null) {
|
|
78901
|
+
this._hasSpawn = false;
|
|
78902
|
+
if (this._findSpawnPosition(camera.position, spawnProbe)) {
|
|
78903
|
+
this._position.copy(spawnProbe);
|
|
78503
78904
|
this._grounded = true;
|
|
78504
78905
|
this._velocity.y = 0;
|
|
78505
|
-
this.
|
|
78506
|
-
this.
|
|
78906
|
+
this._resolveSpawnCollision();
|
|
78907
|
+
this._storeSpawn();
|
|
78507
78908
|
}
|
|
78909
|
+
this._prevPosition.copy(this._position);
|
|
78508
78910
|
}
|
|
78509
78911
|
}
|
|
78510
78912
|
update(deltaTime, inputFrame, camera) {
|
|
78511
78913
|
const { move, rotate } = inputFrame.read();
|
|
78512
78914
|
// apply rotation at display rate for responsive mouse look
|
|
78513
|
-
this._angles
|
|
78514
|
-
this._angles.x = math.clamp(this._angles.x, -90, 90);
|
|
78915
|
+
applyFrameRotation(this._angles, rotate);
|
|
78515
78916
|
// accumulate movement input so frames without a physics step don't lose input
|
|
78516
78917
|
this._pendingMove[0] += move[0];
|
|
78517
78918
|
this._pendingMove[1] = this._pendingMove[1] || move[1];
|
|
@@ -78535,6 +78936,7 @@ class WalkController {
|
|
|
78535
78936
|
const alpha = this._accumulator / FIXED_DT;
|
|
78536
78937
|
camera.position.lerp(this._prevPosition, this._position, alpha);
|
|
78537
78938
|
camera.angles.set(this._angles.x, this._angles.y, 0);
|
|
78939
|
+
camera.distance = this._distance;
|
|
78538
78940
|
camera.fov = this.fov;
|
|
78539
78941
|
}
|
|
78540
78942
|
_step(dt, move) {
|
|
@@ -78577,12 +78979,8 @@ class WalkController {
|
|
|
78577
78979
|
this._grounded = false;
|
|
78578
78980
|
}
|
|
78579
78981
|
// move
|
|
78580
|
-
|
|
78581
|
-
|
|
78582
|
-
rotation.transformVector(Vec3.RIGHT, right$1);
|
|
78583
|
-
offset.set(0, 0, 0);
|
|
78584
|
-
offset.add(forward.mulScalar(move[2]));
|
|
78585
|
-
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);
|
|
78586
78984
|
this._velocity.add(offset.mulScalar(this._grounded ? this.moveGroundSpeed : this.moveAirSpeed));
|
|
78587
78985
|
const dampFactor = this._grounded ? this.velocityDampingGround : this.velocityDampingAir;
|
|
78588
78986
|
const alpha = damp(dampFactor, dt);
|
|
@@ -78606,36 +79004,193 @@ class WalkController {
|
|
|
78606
79004
|
this._prevPosition.copy(this._position);
|
|
78607
79005
|
// angles (clamp pitch to avoid gimbal lock)
|
|
78608
79006
|
this._angles.set(camera.angles.x, camera.angles.y, 0);
|
|
79007
|
+
this._distance = camera.distance;
|
|
78609
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() {
|
|
78610
79041
|
this._velocity.set(0, 0, 0);
|
|
78611
79042
|
this._grounded = false;
|
|
78612
79043
|
this._jumping = false;
|
|
79044
|
+
this._jumpHeld = false;
|
|
78613
79045
|
this._pendingMove[0] = 0;
|
|
78614
79046
|
this._pendingMove[1] = 0;
|
|
78615
79047
|
this._pendingMove[2] = 0;
|
|
78616
79048
|
this._accumulator = 0;
|
|
78617
79049
|
}
|
|
78618
79050
|
/**
|
|
78619
|
-
*
|
|
78620
|
-
*
|
|
78621
|
-
* activates inside a solid region. Per-frame collision resolution is unaffected,
|
|
78622
|
-
* 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.
|
|
78623
79053
|
*/
|
|
78624
79054
|
_resolveSpawnCollision() {
|
|
78625
|
-
const half = this.capsuleHeight * 0.5 - this.capsuleRadius;
|
|
78626
|
-
const minStep = this.capsuleRadius;
|
|
78627
79055
|
for (let i = 0; i < 100; i++) {
|
|
78628
|
-
|
|
78629
|
-
if (!this.collision.queryCapsule(this._position.x, center, this._position.z, half, this.capsuleRadius, out)) {
|
|
79056
|
+
if (!this._queryCapsule(this._position)) {
|
|
78630
79057
|
break;
|
|
78631
79058
|
}
|
|
78632
|
-
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;
|
|
78633
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);
|
|
78634
79189
|
}
|
|
78635
79190
|
/**
|
|
78636
79191
|
* Cast multiple rays downward to find the average ground surface height.
|
|
78637
79192
|
* Uses 5 rays (center + 4 cardinal at capsule radius) to spatially filter
|
|
78638
|
-
* noisy
|
|
79193
|
+
* noisy collision heights, giving the spring a smoother target.
|
|
78639
79194
|
*
|
|
78640
79195
|
* @param pos - Eye position in PlayCanvas world space.
|
|
78641
79196
|
* @returns Average ground surface Y in PlayCanvas space, or null if no ground found.
|
|
@@ -78693,7 +79248,6 @@ class WalkController {
|
|
|
78693
79248
|
}
|
|
78694
79249
|
}
|
|
78695
79250
|
|
|
78696
|
-
const RAD_TO_DEG = 180 / Math.PI;
|
|
78697
79251
|
/** XZ distance below which the walker considers itself arrived */
|
|
78698
79252
|
const ARRIVAL_DIST = 0.5;
|
|
78699
79253
|
/** Minimum XZ speed (m/s) to not count as blocked */
|
|
@@ -78730,8 +79284,7 @@ class WalkSource {
|
|
|
78730
79284
|
onComplete = null;
|
|
78731
79285
|
_target = null;
|
|
78732
79286
|
_yawRate = 0;
|
|
78733
|
-
|
|
78734
|
-
_prevDist = Infinity;
|
|
79287
|
+
_progress = new ProgressTracker();
|
|
78735
79288
|
get isWalking() {
|
|
78736
79289
|
return this._target !== null;
|
|
78737
79290
|
}
|
|
@@ -78745,8 +79298,7 @@ class WalkSource {
|
|
|
78745
79298
|
this._target = new Vec3();
|
|
78746
79299
|
}
|
|
78747
79300
|
this._target.copy(target);
|
|
78748
|
-
this.
|
|
78749
|
-
this._prevDist = Infinity;
|
|
79301
|
+
this._progress.reset();
|
|
78750
79302
|
}
|
|
78751
79303
|
/**
|
|
78752
79304
|
* Cancel any active auto-walk.
|
|
@@ -78755,7 +79307,7 @@ class WalkSource {
|
|
|
78755
79307
|
if (this._target) {
|
|
78756
79308
|
this._target = null;
|
|
78757
79309
|
this._yawRate = 0;
|
|
78758
|
-
this.
|
|
79310
|
+
this._progress.reset();
|
|
78759
79311
|
this.onComplete?.();
|
|
78760
79312
|
}
|
|
78761
79313
|
}
|
|
@@ -78781,29 +79333,17 @@ class WalkSource {
|
|
|
78781
79333
|
return;
|
|
78782
79334
|
}
|
|
78783
79335
|
// blocked detection: compare with previous frame's distance
|
|
78784
|
-
if (this.
|
|
78785
|
-
|
|
78786
|
-
|
|
78787
|
-
this._blockedTime += dt;
|
|
78788
|
-
if (this._blockedTime >= BLOCKED_DURATION) {
|
|
78789
|
-
this.cancelWalk();
|
|
78790
|
-
return;
|
|
78791
|
-
}
|
|
78792
|
-
}
|
|
78793
|
-
else {
|
|
78794
|
-
this._blockedTime = 0;
|
|
78795
|
-
}
|
|
79336
|
+
if (this._progress.update(xzDist, dt, BLOCKED_SPEED, BLOCKED_DURATION)) {
|
|
79337
|
+
this.cancelWalk();
|
|
79338
|
+
return;
|
|
78796
79339
|
}
|
|
78797
|
-
this._prevDist = xzDist;
|
|
78798
79340
|
// yaw toward target with smoothed turn rate
|
|
78799
|
-
const
|
|
78800
|
-
|
|
78801
|
-
|
|
78802
|
-
|
|
78803
|
-
const smoothing = 1 - Math.exp(-4 * this.turnGain * dt);
|
|
78804
|
-
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;
|
|
78805
79345
|
// WalkController applies: _angles.y += -rotate[0]
|
|
78806
|
-
frame.deltas.rotate.append([-
|
|
79346
|
+
frame.deltas.rotate.append([-yawStep, 0, 0]);
|
|
78807
79347
|
// scale forward speed by alignment: turn in place first, then accelerate
|
|
78808
79348
|
const alignment = Math.max(0, Math.cos(yawDiff * Math.PI / 180));
|
|
78809
79349
|
frame.deltas.move.append([0, 0, this.walkSpeed * dt * alignment]);
|
|
@@ -78868,6 +79408,10 @@ class CameraManager {
|
|
|
78868
79408
|
walkSource.onComplete = () => {
|
|
78869
79409
|
events.fire('walkComplete');
|
|
78870
79410
|
};
|
|
79411
|
+
const flySource = new FlySource();
|
|
79412
|
+
flySource.onComplete = () => {
|
|
79413
|
+
events.fire('flyComplete');
|
|
79414
|
+
};
|
|
78871
79415
|
const getController = (cameraMode) => {
|
|
78872
79416
|
return controllers[cameraMode];
|
|
78873
79417
|
};
|
|
@@ -78888,6 +79432,7 @@ class CameraManager {
|
|
|
78888
79432
|
// transition state
|
|
78889
79433
|
const transitionSpeed = 1.0;
|
|
78890
79434
|
let transitionTimer = 1;
|
|
79435
|
+
let clearOrbitTargetOnTransitionEnd = false;
|
|
78891
79436
|
// start a new camera transition from the current pose
|
|
78892
79437
|
const startTransition = () => {
|
|
78893
79438
|
from.copy(this.camera);
|
|
@@ -78898,11 +79443,15 @@ class CameraManager {
|
|
|
78898
79443
|
// use dt of 0 if animation is paused
|
|
78899
79444
|
const dt = state.cameraMode === 'anim' && state.animationPaused ? 0 : deltaTime;
|
|
78900
79445
|
// update transition timer
|
|
79446
|
+
const prevTransitionTimer = transitionTimer;
|
|
78901
79447
|
transitionTimer = Math.min(1, transitionTimer + deltaTime * transitionSpeed);
|
|
78902
79448
|
const controller = getController(state.cameraMode);
|
|
78903
79449
|
if (state.cameraMode === 'walk') {
|
|
78904
79450
|
walkSource.update(dt, this.camera.position, this.camera.angles, frame);
|
|
78905
79451
|
}
|
|
79452
|
+
else if (state.cameraMode === 'fly') {
|
|
79453
|
+
flySource.update(dt, this.camera.position, this.camera.angles, this.camera.fov, frame);
|
|
79454
|
+
}
|
|
78906
79455
|
controller.update(dt, frame, target);
|
|
78907
79456
|
if (transitionTimer < 1) {
|
|
78908
79457
|
// lerp away from previous camera during transition
|
|
@@ -78915,19 +79464,38 @@ class CameraManager {
|
|
|
78915
79464
|
if (state.cameraMode === 'anim') {
|
|
78916
79465
|
state.animationTime = controllers.anim.animState.cursor.value;
|
|
78917
79466
|
}
|
|
79467
|
+
if (clearOrbitTargetOnTransitionEnd && prevTransitionTimer < 1 && transitionTimer === 1) {
|
|
79468
|
+
clearOrbitTargetOnTransitionEnd = false;
|
|
79469
|
+
events.fire('orbitTarget:clear');
|
|
79470
|
+
}
|
|
78918
79471
|
};
|
|
78919
79472
|
// handle input events
|
|
78920
|
-
events.on('inputEvent', (eventName
|
|
79473
|
+
events.on('inputEvent', (eventName) => {
|
|
78921
79474
|
switch (eventName) {
|
|
78922
79475
|
case 'frame':
|
|
79476
|
+
events.fire('orbitTarget:clear');
|
|
78923
79477
|
state.cameraMode = 'orbit';
|
|
78924
79478
|
controllers.orbit.goto(frameCamera);
|
|
78925
79479
|
startTransition();
|
|
78926
79480
|
break;
|
|
78927
79481
|
case 'reset':
|
|
78928
|
-
state.cameraMode
|
|
78929
|
-
|
|
78930
|
-
|
|
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
|
+
}
|
|
78931
79499
|
break;
|
|
78932
79500
|
case 'playPause':
|
|
78933
79501
|
if (state.hasAnimation) {
|
|
@@ -78976,6 +79544,9 @@ class CameraManager {
|
|
|
78976
79544
|
if (prev === 'walk') {
|
|
78977
79545
|
walkSource.cancelWalk();
|
|
78978
79546
|
}
|
|
79547
|
+
else if (prev === 'fly') {
|
|
79548
|
+
flySource.cancelFly();
|
|
79549
|
+
}
|
|
78979
79550
|
// snapshot the current pose before any controller mutation
|
|
78980
79551
|
startTransition();
|
|
78981
79552
|
target.copy(this.camera);
|
|
@@ -79003,8 +79574,10 @@ class CameraManager {
|
|
|
79003
79574
|
tmpCamera.look(this.camera.position, position);
|
|
79004
79575
|
controllers.orbit.goto(tmpCamera);
|
|
79005
79576
|
startTransition();
|
|
79577
|
+
clearOrbitTargetOnTransitionEnd = true;
|
|
79006
79578
|
});
|
|
79007
79579
|
events.on('annotation.activate', (annotation) => {
|
|
79580
|
+
events.fire('orbitTarget:clear');
|
|
79008
79581
|
// switch to orbit camera on pick
|
|
79009
79582
|
state.cameraMode = 'orbit';
|
|
79010
79583
|
const { initial } = annotation.camera;
|
|
@@ -79029,6 +79602,21 @@ class CameraManager {
|
|
|
79029
79602
|
events.on('walkComplete', () => {
|
|
79030
79603
|
events.fire('walkTarget:clear');
|
|
79031
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
|
+
});
|
|
79032
79620
|
}
|
|
79033
79621
|
}
|
|
79034
79622
|
|
|
@@ -79055,6 +79643,11 @@ class InputModeTracker {
|
|
|
79055
79643
|
}
|
|
79056
79644
|
}
|
|
79057
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');
|
|
79058
79651
|
/**
|
|
79059
79652
|
* Keyboard shortcuts that switch camera mode and toggle UI affordances.
|
|
79060
79653
|
* Listens on `window` so the user can press 1/2/3, V, G, H, F, R, Space,
|
|
@@ -79069,8 +79662,8 @@ class ModeShortcuts {
|
|
|
79069
79662
|
return;
|
|
79070
79663
|
const { state, events } = global;
|
|
79071
79664
|
if (event.key === 'Escape') {
|
|
79072
|
-
if (this._pointerLock?.
|
|
79073
|
-
else if (state.cameraMode
|
|
79665
|
+
if (this._pointerLock?.recentlyExitedCapture) ;
|
|
79666
|
+
else if (isCaptureMode$1(state.cameraMode) && state.gamingControls && state.inputMode === 'desktop') {
|
|
79074
79667
|
state.gamingControls = false;
|
|
79075
79668
|
}
|
|
79076
79669
|
else if (state.cameraMode === 'walk') {
|
|
@@ -79095,8 +79688,8 @@ class ModeShortcuts {
|
|
|
79095
79688
|
events.fire('inputEvent', 'toggleWalk');
|
|
79096
79689
|
break;
|
|
79097
79690
|
case 'v':
|
|
79098
|
-
if (state.
|
|
79099
|
-
state.
|
|
79691
|
+
if (state.hasCollisionOverlay) {
|
|
79692
|
+
state.collisionOverlayEnabled = !state.collisionOverlayEnabled;
|
|
79100
79693
|
}
|
|
79101
79694
|
break;
|
|
79102
79695
|
case 'g':
|
|
@@ -79105,10 +79698,17 @@ class ModeShortcuts {
|
|
|
79105
79698
|
case 'h':
|
|
79106
79699
|
events.fire('inputEvent', 'toggleHelp');
|
|
79107
79700
|
break;
|
|
79701
|
+
case 'r':
|
|
79702
|
+
events.fire('inputEvent', 'reset', event);
|
|
79703
|
+
break;
|
|
79108
79704
|
default:
|
|
79109
|
-
if ((event
|
|
79110
|
-
|
|
79111
|
-
|
|
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
|
+
}
|
|
79112
79712
|
}
|
|
79113
79713
|
break;
|
|
79114
79714
|
}
|
|
@@ -79117,9 +79717,6 @@ class ModeShortcuts {
|
|
|
79117
79717
|
case 'f':
|
|
79118
79718
|
events.fire('inputEvent', 'frame', event);
|
|
79119
79719
|
break;
|
|
79120
|
-
case 'r':
|
|
79121
|
-
events.fire('inputEvent', 'reset', event);
|
|
79122
|
-
break;
|
|
79123
79720
|
case ' ':
|
|
79124
79721
|
events.fire('inputEvent', 'playPause', event);
|
|
79125
79722
|
break;
|
|
@@ -79138,34 +79735,35 @@ class ModeShortcuts {
|
|
|
79138
79735
|
}
|
|
79139
79736
|
}
|
|
79140
79737
|
|
|
79738
|
+
const isCaptureMode = (mode) => mode === 'walk' || mode === 'fly';
|
|
79739
|
+
const hasUserActivation = () => (navigator.userActivation?.isActive === true);
|
|
79141
79740
|
/**
|
|
79142
|
-
* Manages the browser's pointer-lock API for
|
|
79143
|
-
* on desktop. Toggles in response to
|
|
79144
|
-
*
|
|
79145
|
-
* 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.
|
|
79146
79744
|
*
|
|
79147
|
-
* Also exposes `
|
|
79745
|
+
* Also exposes `recentlyExitedCapture` so the keyboard-shortcut handler can
|
|
79148
79746
|
* de-duplicate the Escape keydown that triggered the lock exit.
|
|
79149
79747
|
*/
|
|
79150
79748
|
class PointerLockManager {
|
|
79151
79749
|
_global = null;
|
|
79152
79750
|
_canvas = null;
|
|
79153
79751
|
_keyboardMouse = null;
|
|
79154
|
-
|
|
79752
|
+
_recentlyExitedCapture = false;
|
|
79155
79753
|
_onPointerLockChange = () => {
|
|
79156
79754
|
const global = this._global;
|
|
79157
79755
|
if (!global)
|
|
79158
79756
|
return;
|
|
79159
79757
|
const { state, events } = global;
|
|
79160
|
-
if (!document.pointerLockElement && state.cameraMode
|
|
79161
|
-
this.
|
|
79758
|
+
if (!document.pointerLockElement && isCaptureMode(state.cameraMode) && state.gamingControls) {
|
|
79759
|
+
this._recentlyExitedCapture = true;
|
|
79162
79760
|
requestAnimationFrame(() => {
|
|
79163
|
-
this.
|
|
79761
|
+
this._recentlyExitedCapture = false;
|
|
79164
79762
|
});
|
|
79165
79763
|
if (state.inputMode === 'desktop') {
|
|
79166
79764
|
state.gamingControls = false;
|
|
79167
79765
|
}
|
|
79168
|
-
else {
|
|
79766
|
+
else if (state.cameraMode === 'walk') {
|
|
79169
79767
|
events.fire('inputEvent', 'exitWalk');
|
|
79170
79768
|
}
|
|
79171
79769
|
}
|
|
@@ -79181,10 +79779,10 @@ class PointerLockManager {
|
|
|
79181
79779
|
if (!global)
|
|
79182
79780
|
return;
|
|
79183
79781
|
const { state, events } = global;
|
|
79184
|
-
if (state.inputMode === 'desktop') {
|
|
79782
|
+
if (state.inputMode === 'desktop' && isCaptureMode(state.cameraMode)) {
|
|
79185
79783
|
state.gamingControls = false;
|
|
79186
79784
|
}
|
|
79187
|
-
else {
|
|
79785
|
+
else if (state.cameraMode === 'walk') {
|
|
79188
79786
|
events.fire('inputEvent', 'exitWalk');
|
|
79189
79787
|
}
|
|
79190
79788
|
};
|
|
@@ -79192,10 +79790,10 @@ class PointerLockManager {
|
|
|
79192
79790
|
const state = this._global?.state;
|
|
79193
79791
|
if (!state)
|
|
79194
79792
|
return;
|
|
79195
|
-
if (value
|
|
79793
|
+
if (isCaptureMode(value) && state.inputMode === 'desktop' && state.gamingControls) {
|
|
79196
79794
|
this._activate();
|
|
79197
79795
|
}
|
|
79198
|
-
else if (prev
|
|
79796
|
+
else if (isCaptureMode(prev)) {
|
|
79199
79797
|
this._deactivate();
|
|
79200
79798
|
}
|
|
79201
79799
|
};
|
|
@@ -79203,7 +79801,7 @@ class PointerLockManager {
|
|
|
79203
79801
|
const state = this._global?.state;
|
|
79204
79802
|
if (!state)
|
|
79205
79803
|
return;
|
|
79206
|
-
if (state.cameraMode
|
|
79804
|
+
if (isCaptureMode(state.cameraMode) && state.inputMode === 'desktop') {
|
|
79207
79805
|
if (value) {
|
|
79208
79806
|
this._activate();
|
|
79209
79807
|
}
|
|
@@ -79212,11 +79810,31 @@ class PointerLockManager {
|
|
|
79212
79810
|
}
|
|
79213
79811
|
}
|
|
79214
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
|
+
};
|
|
79215
79831
|
_activate() {
|
|
79216
79832
|
if (this._keyboardMouse) {
|
|
79217
79833
|
this._keyboardMouse.source._pointerLock = true;
|
|
79218
79834
|
}
|
|
79219
|
-
this._canvas
|
|
79835
|
+
if (document.pointerLockElement !== this._canvas) {
|
|
79836
|
+
this._canvas?.requestPointerLock();
|
|
79837
|
+
}
|
|
79220
79838
|
}
|
|
79221
79839
|
_deactivate() {
|
|
79222
79840
|
if (this._keyboardMouse) {
|
|
@@ -79226,8 +79844,8 @@ class PointerLockManager {
|
|
|
79226
79844
|
document.exitPointerLock();
|
|
79227
79845
|
}
|
|
79228
79846
|
}
|
|
79229
|
-
get
|
|
79230
|
-
return this.
|
|
79847
|
+
get recentlyExitedCapture() {
|
|
79848
|
+
return this._recentlyExitedCapture;
|
|
79231
79849
|
}
|
|
79232
79850
|
attach(canvas, global, keyboardMouse) {
|
|
79233
79851
|
this._canvas = canvas;
|
|
@@ -79236,6 +79854,8 @@ class PointerLockManager {
|
|
|
79236
79854
|
const { events } = global;
|
|
79237
79855
|
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
79238
79856
|
events.on('gamingControls:changed', this._onGamingControlsChanged);
|
|
79857
|
+
events.on('inputMode:changed', this._onInputModeChanged);
|
|
79858
|
+
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79239
79859
|
document.addEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79240
79860
|
document.addEventListener('pointerlockerror', this._onPointerLockError);
|
|
79241
79861
|
}
|
|
@@ -79244,7 +79864,9 @@ class PointerLockManager {
|
|
|
79244
79864
|
const { events } = this._global;
|
|
79245
79865
|
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
79246
79866
|
events.off('gamingControls:changed', this._onGamingControlsChanged);
|
|
79867
|
+
events.off('inputMode:changed', this._onInputModeChanged);
|
|
79247
79868
|
}
|
|
79869
|
+
this._canvas?.removeEventListener('pointerdown', this._onPointerDown);
|
|
79248
79870
|
document.removeEventListener('pointerlockchange', this._onPointerLockChange);
|
|
79249
79871
|
document.removeEventListener('pointerlockerror', this._onPointerLockError);
|
|
79250
79872
|
this._canvas = null;
|
|
@@ -79253,353 +79875,6 @@ class PointerLockManager {
|
|
|
79253
79875
|
}
|
|
79254
79876
|
}
|
|
79255
79877
|
|
|
79256
|
-
/**
|
|
79257
|
-
* Double-click world picking for splat scenes.
|
|
79258
|
-
*
|
|
79259
|
-
* - **Compute renderer (WebGPU tiled-compute)**: uses engine `Picker` with depth enabled — expected
|
|
79260
|
-
* depth is already provided by the tile-composite path.
|
|
79261
|
-
* - **Raster renderers (WebGL, CPU / GPU sort, etc.)**: custom `pickPS` / `gsplatPS` patch plus
|
|
79262
|
-
* `RGBA16F` alpha-weighted depth accumulation, because the stock pick pass encodes splat IDs /
|
|
79263
|
-
* last-fragment depth rather than expected depth.
|
|
79264
|
-
*/
|
|
79265
|
-
// Override global picking to pack alpha-weighted splat depth instead of meshInstance id.
|
|
79266
|
-
const pickDepthGlsl = /* glsl */ `
|
|
79267
|
-
vec4 encodePickOutput(uint id) {
|
|
79268
|
-
const vec4 inv = vec4(1.0 / 255.0);
|
|
79269
|
-
const uvec4 shifts = uvec4(16, 8, 0, 24);
|
|
79270
|
-
uvec4 col = (uvec4(id) >> shifts) & uvec4(0xff);
|
|
79271
|
-
return vec4(col) * inv;
|
|
79272
|
-
}
|
|
79273
|
-
|
|
79274
|
-
#ifdef GSPLAT_PICK_DEPTH
|
|
79275
|
-
#ifndef CAMERAPLANES
|
|
79276
|
-
#define CAMERAPLANES
|
|
79277
|
-
uniform vec4 camera_params; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79278
|
-
#endif
|
|
79279
|
-
|
|
79280
|
-
vec4 getPickOutput() {
|
|
79281
|
-
float normalizedDepth;
|
|
79282
|
-
if (camera_params.w > 0.5) {
|
|
79283
|
-
normalizedDepth = gl_FragCoord.z;
|
|
79284
|
-
} else {
|
|
79285
|
-
float linearDepth = 1.0 / gl_FragCoord.w;
|
|
79286
|
-
normalizedDepth = (linearDepth - camera_params.z) / (camera_params.y - camera_params.z);
|
|
79287
|
-
}
|
|
79288
|
-
|
|
79289
|
-
return vec4(gaussianColor.a * normalizedDepth, 0.0, 0.0, gaussianColor.a);
|
|
79290
|
-
}
|
|
79291
|
-
#else
|
|
79292
|
-
#ifndef PICK_CUSTOM_ID
|
|
79293
|
-
uniform uint meshInstanceId;
|
|
79294
|
-
|
|
79295
|
-
vec4 getPickOutput() {
|
|
79296
|
-
return encodePickOutput(meshInstanceId);
|
|
79297
|
-
}
|
|
79298
|
-
#endif
|
|
79299
|
-
#endif
|
|
79300
|
-
|
|
79301
|
-
#ifdef DEPTH_PICK_PASS
|
|
79302
|
-
#include "floatAsUintPS"
|
|
79303
|
-
#ifndef CAMERAPLANES
|
|
79304
|
-
#define CAMERAPLANES
|
|
79305
|
-
uniform vec4 camera_params; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79306
|
-
#endif
|
|
79307
|
-
|
|
79308
|
-
vec4 getPickDepth() {
|
|
79309
|
-
float linearDepth;
|
|
79310
|
-
if (camera_params.w > 0.5) {
|
|
79311
|
-
linearDepth = gl_FragCoord.z;
|
|
79312
|
-
} else {
|
|
79313
|
-
float viewDist = 1.0 / gl_FragCoord.w;
|
|
79314
|
-
linearDepth = (viewDist - camera_params.z) / (camera_params.y - camera_params.z);
|
|
79315
|
-
}
|
|
79316
|
-
return float2uint(linearDepth);
|
|
79317
|
-
}
|
|
79318
|
-
#endif
|
|
79319
|
-
`;
|
|
79320
|
-
const pickDepthWgsl = /* wgsl */ `
|
|
79321
|
-
fn encodePickOutput(id: u32) -> vec4f {
|
|
79322
|
-
let inv: vec4f = vec4f(1.0 / 255.0);
|
|
79323
|
-
let shifts: vec4u = vec4u(16u, 8u, 0u, 24u);
|
|
79324
|
-
let col: vec4u = (vec4u(id) >> shifts) & vec4u(0xffu);
|
|
79325
|
-
return vec4f(col) * inv;
|
|
79326
|
-
}
|
|
79327
|
-
|
|
79328
|
-
#ifdef GSPLAT_PICK_DEPTH
|
|
79329
|
-
#ifndef CAMERAPLANES
|
|
79330
|
-
#define CAMERAPLANES
|
|
79331
|
-
uniform camera_params: vec4f; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79332
|
-
#endif
|
|
79333
|
-
|
|
79334
|
-
fn getPickOutput() -> vec4f {
|
|
79335
|
-
var normalizedDepth: f32;
|
|
79336
|
-
if (uniform.camera_params.w > 0.5) {
|
|
79337
|
-
normalizedDepth = pcPosition.z;
|
|
79338
|
-
} else {
|
|
79339
|
-
let linearDepth = 1.0 / pcPosition.w;
|
|
79340
|
-
normalizedDepth = (linearDepth - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
|
|
79341
|
-
}
|
|
79342
|
-
|
|
79343
|
-
let a = f32(gaussianColor.a);
|
|
79344
|
-
return vec4f(a * normalizedDepth, 0.0, 0.0, a);
|
|
79345
|
-
}
|
|
79346
|
-
#else
|
|
79347
|
-
#ifndef PICK_CUSTOM_ID
|
|
79348
|
-
uniform meshInstanceId: u32;
|
|
79349
|
-
|
|
79350
|
-
fn getPickOutput() -> vec4f {
|
|
79351
|
-
return encodePickOutput(uniform.meshInstanceId);
|
|
79352
|
-
}
|
|
79353
|
-
#endif
|
|
79354
|
-
#endif
|
|
79355
|
-
|
|
79356
|
-
#ifdef DEPTH_PICK_PASS
|
|
79357
|
-
#include "floatAsUintPS"
|
|
79358
|
-
#ifndef CAMERAPLANES
|
|
79359
|
-
#define CAMERAPLANES
|
|
79360
|
-
uniform camera_params: vec4f; // x: 1/far, y: far, z: near, w: isOrtho
|
|
79361
|
-
#endif
|
|
79362
|
-
|
|
79363
|
-
fn getPickDepth() -> vec4f {
|
|
79364
|
-
var linearDepth: f32;
|
|
79365
|
-
if (uniform.camera_params.w > 0.5) {
|
|
79366
|
-
linearDepth = pcPosition.z;
|
|
79367
|
-
} else {
|
|
79368
|
-
let viewDist = 1.0 / pcPosition.w;
|
|
79369
|
-
linearDepth = (viewDist - uniform.camera_params.z) / (uniform.camera_params.y - uniform.camera_params.z);
|
|
79370
|
-
}
|
|
79371
|
-
return float2uint(linearDepth);
|
|
79372
|
-
}
|
|
79373
|
-
#endif
|
|
79374
|
-
`;
|
|
79375
|
-
const pickPassChunkInjected = [
|
|
79376
|
-
'#ifdef PICK_PASS',
|
|
79377
|
-
' #define GSPLAT_PICK_DEPTH',
|
|
79378
|
-
' #include "pickPS"',
|
|
79379
|
-
'#endif'
|
|
79380
|
-
].join('\n');
|
|
79381
|
-
const safeChunkReplace = (s, find, repl) => {
|
|
79382
|
-
const out = s.replace(find, repl);
|
|
79383
|
-
if (out === s) {
|
|
79384
|
-
throw new Error('picker: engine gsplat/pick chunk patch failed (engine version mismatch?)');
|
|
79385
|
-
}
|
|
79386
|
-
return out;
|
|
79387
|
-
};
|
|
79388
|
-
const patchGsplatPickGlsl = (chunk) => {
|
|
79389
|
-
return safeChunkReplace(safeChunkReplace(chunk, /#ifdef PICK_PASS\s*#include "pickPS"\s*#endif/, pickPassChunkInjected), 'pcFragColor0 = encodePickOutput(vPickId);', 'pcFragColor0 = getPickOutput();');
|
|
79390
|
-
};
|
|
79391
|
-
const patchGsplatPickWgsl = (chunk) => {
|
|
79392
|
-
return safeChunkReplace(safeChunkReplace(chunk, /#ifdef PICK_PASS\s*#include "pickPS"\s*#endif/, pickPassChunkInjected), 'output.color = encodePickOutput(vPickId);', 'output.color = getPickOutput();');
|
|
79393
|
-
};
|
|
79394
|
-
/** Per-device original chunk strings + refcount so we can restore after the last Picker releases. */
|
|
79395
|
-
const pickerShaderPatchState = new WeakMap();
|
|
79396
|
-
const vec4 = new Vec4();
|
|
79397
|
-
const viewProjMat = new Mat4();
|
|
79398
|
-
const clearColor = new Color(0, 0, 0, 1);
|
|
79399
|
-
// Shared buffer for half-to-float conversion
|
|
79400
|
-
const float32 = new Float32Array(1);
|
|
79401
|
-
const uint32 = new Uint32Array(float32.buffer);
|
|
79402
|
-
// Convert 16-bit half-float to 32-bit float using bit manipulation.
|
|
79403
|
-
const half2Float = (h) => {
|
|
79404
|
-
const sign = (h & 0x8000) << 16;
|
|
79405
|
-
const exponent = (h & 0x7C00) >> 10;
|
|
79406
|
-
const mantissa = h & 0x03FF;
|
|
79407
|
-
if (exponent === 0) {
|
|
79408
|
-
if (mantissa === 0) {
|
|
79409
|
-
uint32[0] = sign;
|
|
79410
|
-
}
|
|
79411
|
-
else {
|
|
79412
|
-
let e = -1;
|
|
79413
|
-
let m = mantissa;
|
|
79414
|
-
do {
|
|
79415
|
-
e++;
|
|
79416
|
-
m <<= 1;
|
|
79417
|
-
} while ((m & 0x0400) === 0);
|
|
79418
|
-
uint32[0] = sign | ((127 - 15 - e) << 23) | ((m & 0x03FF) << 13);
|
|
79419
|
-
}
|
|
79420
|
-
}
|
|
79421
|
-
else if (exponent === 31) {
|
|
79422
|
-
uint32[0] = sign | 0x7F800000 | (mantissa << 13);
|
|
79423
|
-
}
|
|
79424
|
-
else {
|
|
79425
|
-
uint32[0] = sign | ((exponent + 127 - 15) << 23) | (mantissa << 13);
|
|
79426
|
-
}
|
|
79427
|
-
return float32[0];
|
|
79428
|
-
};
|
|
79429
|
-
const registerPickerShaderPatches = (app) => {
|
|
79430
|
-
const device = app.graphicsDevice;
|
|
79431
|
-
const existing = pickerShaderPatchState.get(device);
|
|
79432
|
-
if (existing) {
|
|
79433
|
-
existing.refCount++;
|
|
79434
|
-
return;
|
|
79435
|
-
}
|
|
79436
|
-
const glslChunks = ShaderChunks.get(device, 'glsl');
|
|
79437
|
-
const wgslChunks = ShaderChunks.get(device, 'wgsl');
|
|
79438
|
-
const glslPickPS = glslChunks.get('pickPS');
|
|
79439
|
-
const glslGsplatPS = glslChunks.get('gsplatPS');
|
|
79440
|
-
const wgslPickPS = wgslChunks.get('pickPS');
|
|
79441
|
-
const wgslGsplatPS = wgslChunks.get('gsplatPS');
|
|
79442
|
-
// Patch strings before mutating ShaderChunks so engine mismatches leave globals untouched.
|
|
79443
|
-
const patchedGlslGsplatPS = patchGsplatPickGlsl(glslGsplatPS);
|
|
79444
|
-
const patchedWgslGsplatPS = patchGsplatPickWgsl(wgslGsplatPS);
|
|
79445
|
-
const state = {
|
|
79446
|
-
glslPickPS,
|
|
79447
|
-
glslGsplatPS,
|
|
79448
|
-
wgslPickPS,
|
|
79449
|
-
wgslGsplatPS,
|
|
79450
|
-
refCount: 1
|
|
79451
|
-
};
|
|
79452
|
-
pickerShaderPatchState.set(device, state);
|
|
79453
|
-
glslChunks.set('pickPS', pickDepthGlsl);
|
|
79454
|
-
wgslChunks.set('pickPS', pickDepthWgsl);
|
|
79455
|
-
glslChunks.set('gsplatPS', patchedGlslGsplatPS);
|
|
79456
|
-
wgslChunks.set('gsplatPS', patchedWgslGsplatPS);
|
|
79457
|
-
};
|
|
79458
|
-
const unregisterPickerShaderPatches = (app) => {
|
|
79459
|
-
const device = app.graphicsDevice;
|
|
79460
|
-
const state = pickerShaderPatchState.get(device);
|
|
79461
|
-
if (!state) {
|
|
79462
|
-
return;
|
|
79463
|
-
}
|
|
79464
|
-
state.refCount--;
|
|
79465
|
-
if (state.refCount > 0) {
|
|
79466
|
-
return;
|
|
79467
|
-
}
|
|
79468
|
-
const glslChunks = ShaderChunks.get(device, 'glsl');
|
|
79469
|
-
const wgslChunks = ShaderChunks.get(device, 'wgsl');
|
|
79470
|
-
glslChunks.set('pickPS', state.glslPickPS);
|
|
79471
|
-
glslChunks.set('gsplatPS', state.glslGsplatPS);
|
|
79472
|
-
wgslChunks.set('pickPS', state.wgslPickPS);
|
|
79473
|
-
wgslChunks.set('gsplatPS', state.wgslGsplatPS);
|
|
79474
|
-
pickerShaderPatchState.delete(device);
|
|
79475
|
-
};
|
|
79476
|
-
const getWorldPoint = (camera, x, y, width, height, normalizedDepth) => {
|
|
79477
|
-
if (!Number.isFinite(normalizedDepth) || normalizedDepth < 0 || normalizedDepth > 1) {
|
|
79478
|
-
return null;
|
|
79479
|
-
}
|
|
79480
|
-
const cam = camera.camera;
|
|
79481
|
-
const far = cam.farClip;
|
|
79482
|
-
const near = cam.nearClip;
|
|
79483
|
-
const ndcDepth = cam.projection === PROJECTION_ORTHOGRAPHIC ?
|
|
79484
|
-
normalizedDepth :
|
|
79485
|
-
far * normalizedDepth / (normalizedDepth * (far - near) + near);
|
|
79486
|
-
viewProjMat.mul2(cam.projectionMatrix, cam.viewMatrix).invert();
|
|
79487
|
-
vec4.set(x / width * 2 - 1, (1 - y / height) * 2 - 1, ndcDepth * 2 - 1, 1);
|
|
79488
|
-
viewProjMat.transformVec4(vec4, vec4);
|
|
79489
|
-
if (!Number.isFinite(vec4.w) || Math.abs(vec4.w) < 1e-8) {
|
|
79490
|
-
return null;
|
|
79491
|
-
}
|
|
79492
|
-
vec4.mulScalar(1 / vec4.w);
|
|
79493
|
-
if (!Number.isFinite(vec4.x) || !Number.isFinite(vec4.y) || !Number.isFinite(vec4.z)) {
|
|
79494
|
-
return null;
|
|
79495
|
-
}
|
|
79496
|
-
return new Vec3(vec4.x, vec4.y, vec4.z);
|
|
79497
|
-
};
|
|
79498
|
-
class Picker {
|
|
79499
|
-
pick;
|
|
79500
|
-
release;
|
|
79501
|
-
constructor(app, camera) {
|
|
79502
|
-
const { graphicsDevice } = app;
|
|
79503
|
-
let enginePicker;
|
|
79504
|
-
let accumBuffer;
|
|
79505
|
-
let accumTarget;
|
|
79506
|
-
let accumPass;
|
|
79507
|
-
let chunksPatched = false;
|
|
79508
|
-
const initRasterAccum = (width, height) => {
|
|
79509
|
-
accumBuffer = new Texture(graphicsDevice, {
|
|
79510
|
-
format: PIXELFORMAT_RGBA16F,
|
|
79511
|
-
width,
|
|
79512
|
-
height,
|
|
79513
|
-
mipmaps: false,
|
|
79514
|
-
minFilter: FILTER_NEAREST,
|
|
79515
|
-
magFilter: FILTER_NEAREST,
|
|
79516
|
-
addressU: ADDRESS_CLAMP_TO_EDGE,
|
|
79517
|
-
addressV: ADDRESS_CLAMP_TO_EDGE,
|
|
79518
|
-
name: 'picker-accum'
|
|
79519
|
-
});
|
|
79520
|
-
accumTarget = new RenderTarget({
|
|
79521
|
-
colorBuffer: accumBuffer,
|
|
79522
|
-
depth: false // not needed — gaussians are rendered back to front
|
|
79523
|
-
});
|
|
79524
|
-
accumPass = new RenderPassPicker(graphicsDevice, app.renderer);
|
|
79525
|
-
// RGB: additive depth accumulation. Alpha: multiplicative transmittance.
|
|
79526
|
-
accumPass.blendState = new BlendState(true, BLENDEQUATION_ADD, BLENDMODE_ONE, BLENDMODE_ONE_MINUS_SRC_ALPHA, BLENDEQUATION_ADD, BLENDMODE_ZERO, BLENDMODE_ONE_MINUS_SRC_ALPHA);
|
|
79527
|
-
};
|
|
79528
|
-
const readTexture = (texture, x, y, target) => {
|
|
79529
|
-
const texY = graphicsDevice.isWebGL2 ? target.height - y - 1 : y;
|
|
79530
|
-
return texture.read(x, texY, 1, 1, {
|
|
79531
|
-
renderTarget: target,
|
|
79532
|
-
immediate: true
|
|
79533
|
-
});
|
|
79534
|
-
};
|
|
79535
|
-
this.pick = async (x, y) => {
|
|
79536
|
-
const width = Math.floor(graphicsDevice.width);
|
|
79537
|
-
const height = Math.floor(graphicsDevice.height);
|
|
79538
|
-
// bail out if the device hasn't been sized yet
|
|
79539
|
-
if (width <= 0 || height <= 0) {
|
|
79540
|
-
return null;
|
|
79541
|
-
}
|
|
79542
|
-
const screenX = Math.min(width - 1, Math.max(0, Math.floor(x * width)));
|
|
79543
|
-
const screenY = Math.min(height - 1, Math.max(0, Math.floor(y * height)));
|
|
79544
|
-
const worldLayer = app.scene.layers.getLayerByName('World');
|
|
79545
|
-
if (!worldLayer) {
|
|
79546
|
-
return null;
|
|
79547
|
-
}
|
|
79548
|
-
// enable gsplat IDs only for the duration of the pick so we don't pay the
|
|
79549
|
-
// memory/perf cost between picks (picker instances are typically long-lived).
|
|
79550
|
-
const prevEnableIds = app.scene.gsplat.enableIds;
|
|
79551
|
-
app.scene.gsplat.enableIds = true;
|
|
79552
|
-
try {
|
|
79553
|
-
if (app.scene.gsplat.currentRenderer === GSPLAT_RENDERER_COMPUTE) {
|
|
79554
|
-
enginePicker ??= new Picker$1(app, 1, 1, true);
|
|
79555
|
-
enginePicker.resize(width, height);
|
|
79556
|
-
enginePicker.prepare(camera.camera, app.scene, [worldLayer]);
|
|
79557
|
-
return await enginePicker.getWorldPointAsync(screenX, screenY);
|
|
79558
|
-
}
|
|
79559
|
-
if (!chunksPatched) {
|
|
79560
|
-
registerPickerShaderPatches(app);
|
|
79561
|
-
chunksPatched = true;
|
|
79562
|
-
}
|
|
79563
|
-
if (!accumPass) {
|
|
79564
|
-
initRasterAccum(width, height);
|
|
79565
|
-
}
|
|
79566
|
-
else {
|
|
79567
|
-
accumTarget.resize(width, height);
|
|
79568
|
-
}
|
|
79569
|
-
accumPass.init(accumTarget);
|
|
79570
|
-
accumPass.setClearColor(clearColor);
|
|
79571
|
-
accumPass.update(camera.camera, app.scene, [worldLayer], new Map(), false);
|
|
79572
|
-
accumPass.render();
|
|
79573
|
-
const pixels = await readTexture(accumBuffer, screenX, screenY, accumTarget);
|
|
79574
|
-
const r = half2Float(pixels[0]);
|
|
79575
|
-
const transmittance = half2Float(pixels[3]);
|
|
79576
|
-
const alpha = 1 - transmittance;
|
|
79577
|
-
if (!Number.isFinite(r) || !Number.isFinite(alpha) || alpha < 1e-6) {
|
|
79578
|
-
return null;
|
|
79579
|
-
}
|
|
79580
|
-
const normalizedDepth = r / alpha;
|
|
79581
|
-
return getWorldPoint(camera, screenX, screenY, width, height, normalizedDepth);
|
|
79582
|
-
}
|
|
79583
|
-
finally {
|
|
79584
|
-
// Pick is only invoked from user dblclick events, so concurrent invocations
|
|
79585
|
-
// (which would race on enableIds) aren't a concern in practice.
|
|
79586
|
-
// eslint-disable-next-line require-atomic-updates
|
|
79587
|
-
app.scene.gsplat.enableIds = prevEnableIds;
|
|
79588
|
-
}
|
|
79589
|
-
};
|
|
79590
|
-
this.release = () => {
|
|
79591
|
-
if (chunksPatched) {
|
|
79592
|
-
unregisterPickerShaderPatches(app);
|
|
79593
|
-
chunksPatched = false;
|
|
79594
|
-
}
|
|
79595
|
-
enginePicker?.destroy();
|
|
79596
|
-
accumPass?.destroy();
|
|
79597
|
-
accumTarget?.destroy();
|
|
79598
|
-
accumBuffer?.destroy();
|
|
79599
|
-
};
|
|
79600
|
-
}
|
|
79601
|
-
}
|
|
79602
|
-
|
|
79603
79878
|
/**
|
|
79604
79879
|
* Displacement-based inputs (mouse, touch, wheel, pinch) return accumulated
|
|
79605
79880
|
* pixel offsets that already scale with frame time. This factor converts
|
|
@@ -79653,35 +79928,48 @@ const screenToWorld = (camera, dx, dy, dz, out = new Vec3()) => {
|
|
|
79653
79928
|
const flipZForOrbit = (mode, z) => (mode === 'orbit' ? -z : z);
|
|
79654
79929
|
|
|
79655
79930
|
const tmpV$4 = new Vec3();
|
|
79931
|
+
const canTargetFly = (global) => (global.state.cameraMode === 'fly' &&
|
|
79932
|
+
!(global.state.inputMode === 'desktop' && global.state.gamingControls));
|
|
79656
79933
|
/**
|
|
79657
|
-
* Click-to-walk
|
|
79658
|
-
*
|
|
79659
|
-
*
|
|
79660
|
-
* 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.
|
|
79661
79937
|
*/
|
|
79662
79938
|
class WalkInteraction {
|
|
79663
79939
|
collision = null;
|
|
79940
|
+
_picker;
|
|
79664
79941
|
_global = null;
|
|
79665
79942
|
_canvas = null;
|
|
79666
|
-
_picker = null;
|
|
79667
79943
|
_lastPointerOffsetX = 0;
|
|
79668
79944
|
_lastPointerOffsetY = 0;
|
|
79669
79945
|
_mouseClickTracking = false;
|
|
79670
79946
|
_mouseClickDelta = 0;
|
|
79947
|
+
_suppressClick = false;
|
|
79948
|
+
_targetPickRequest = 0;
|
|
79671
79949
|
_lastTap = { time: 0, x: 0, y: 0 };
|
|
79950
|
+
constructor(picker) {
|
|
79951
|
+
this._picker = picker;
|
|
79952
|
+
}
|
|
79672
79953
|
_updateCursor = () => {
|
|
79673
79954
|
const global = this._global;
|
|
79674
79955
|
const canvas = this._canvas;
|
|
79675
79956
|
if (!global || !canvas)
|
|
79676
79957
|
return;
|
|
79677
79958
|
const { state } = global;
|
|
79678
|
-
|
|
79959
|
+
const canClickTarget = state.inputMode === 'desktop' && ((state.cameraMode === 'walk' && !state.gamingControls) ||
|
|
79960
|
+
canTargetFly(global) ||
|
|
79961
|
+
state.cameraMode === 'orbit');
|
|
79962
|
+
if (canClickTarget) {
|
|
79679
79963
|
canvas.style.cursor = this._mouseClickTracking ? 'default' : 'pointer';
|
|
79680
79964
|
}
|
|
79681
79965
|
else {
|
|
79682
79966
|
canvas.style.cursor = '';
|
|
79683
79967
|
}
|
|
79684
79968
|
};
|
|
79969
|
+
_onCameraModeChanged = () => {
|
|
79970
|
+
this._targetPickRequest++;
|
|
79971
|
+
this._updateCursor();
|
|
79972
|
+
};
|
|
79685
79973
|
_pickCollision(offsetX, offsetY) {
|
|
79686
79974
|
if (!this.collision || !this._global)
|
|
79687
79975
|
return null;
|
|
@@ -79698,26 +79986,65 @@ class WalkInteraction {
|
|
|
79698
79986
|
normal: new Vec3(sn.nx, sn.ny, sn.nz)
|
|
79699
79987
|
};
|
|
79700
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
|
+
}
|
|
79701
80026
|
_onPointerDown = (event) => {
|
|
79702
80027
|
const global = this._global;
|
|
79703
80028
|
if (!global)
|
|
79704
80029
|
return;
|
|
79705
80030
|
const { events } = global;
|
|
79706
|
-
// record offsets for click/tap
|
|
80031
|
+
// record offsets for click/tap target picking
|
|
79707
80032
|
this._lastPointerOffsetX = event.offsetX;
|
|
79708
80033
|
this._lastPointerOffsetY = event.offsetY;
|
|
79709
|
-
// start desktop click
|
|
80034
|
+
// start desktop click target tracking
|
|
79710
80035
|
if (event.pointerType !== 'touch' && event.button === 0) {
|
|
79711
80036
|
this._mouseClickTracking = true;
|
|
79712
80037
|
this._mouseClickDelta = 0;
|
|
79713
80038
|
this._updateCursor();
|
|
79714
80039
|
}
|
|
79715
|
-
//
|
|
80040
|
+
// Manual double-click/tap detection for platforms that do not emit
|
|
80041
|
+
// reliable native dblclick events on the canvas.
|
|
79716
80042
|
const now = Date.now();
|
|
79717
80043
|
const delay = Math.max(0, now - this._lastTap.time);
|
|
79718
80044
|
if (delay < 300 &&
|
|
79719
80045
|
Math.abs(event.clientX - this._lastTap.x) < 8 &&
|
|
79720
80046
|
Math.abs(event.clientY - this._lastTap.y) < 8) {
|
|
80047
|
+
this._suppressClick = true;
|
|
79721
80048
|
events.fire('inputEvent', 'dblclick', event);
|
|
79722
80049
|
this._lastTap.time = 0;
|
|
79723
80050
|
}
|
|
@@ -79739,6 +80066,9 @@ class WalkInteraction {
|
|
|
79739
80066
|
if (state.cameraMode === 'walk' && !state.gamingControls) {
|
|
79740
80067
|
events.fire('walkCancel');
|
|
79741
80068
|
}
|
|
80069
|
+
else if (canTargetFly(global)) {
|
|
80070
|
+
events.fire('flyCancel');
|
|
80071
|
+
}
|
|
79742
80072
|
}
|
|
79743
80073
|
}
|
|
79744
80074
|
};
|
|
@@ -79750,10 +80080,22 @@ class WalkInteraction {
|
|
|
79750
80080
|
if (this._mouseClickTracking && event.pointerType !== 'touch' && event.button === 0) {
|
|
79751
80081
|
this._mouseClickTracking = false;
|
|
79752
80082
|
this._updateCursor();
|
|
79753
|
-
if (this.
|
|
79754
|
-
|
|
79755
|
-
|
|
79756
|
-
|
|
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);
|
|
79757
80099
|
}
|
|
79758
80100
|
}
|
|
79759
80101
|
}
|
|
@@ -79767,15 +80109,20 @@ class WalkInteraction {
|
|
|
79767
80109
|
return;
|
|
79768
80110
|
if (!(event instanceof MouseEvent))
|
|
79769
80111
|
return;
|
|
79770
|
-
const {
|
|
79771
|
-
|
|
80112
|
+
const { events, state } = global;
|
|
80113
|
+
const cameraMode = state.cameraMode;
|
|
80114
|
+
if (cameraMode === 'walk')
|
|
79772
80115
|
return;
|
|
79773
|
-
if (
|
|
79774
|
-
this.
|
|
80116
|
+
if (cameraMode === 'fly') {
|
|
80117
|
+
this._flyToPickedPosition(event.offsetX, event.offsetY);
|
|
79775
80118
|
}
|
|
79776
|
-
|
|
79777
|
-
|
|
79778
|
-
|
|
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
|
+
}
|
|
79779
80126
|
}
|
|
79780
80127
|
};
|
|
79781
80128
|
_onMobileTap = () => {
|
|
@@ -79783,11 +80130,21 @@ class WalkInteraction {
|
|
|
79783
80130
|
if (!global)
|
|
79784
80131
|
return;
|
|
79785
80132
|
const { state, events } = global;
|
|
79786
|
-
if (
|
|
80133
|
+
if (this._suppressClick) {
|
|
80134
|
+
this._suppressClick = false;
|
|
79787
80135
|
return;
|
|
79788
|
-
|
|
79789
|
-
if (
|
|
79790
|
-
|
|
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);
|
|
79791
80148
|
}
|
|
79792
80149
|
};
|
|
79793
80150
|
attach(canvas, global) {
|
|
@@ -79797,12 +80154,13 @@ class WalkInteraction {
|
|
|
79797
80154
|
canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
79798
80155
|
canvas.addEventListener('pointermove', this._onPointerMove);
|
|
79799
80156
|
canvas.addEventListener('pointerup', this._onPointerUp);
|
|
79800
|
-
// double-click
|
|
80157
|
+
// double-click/tap fallback -> fly target or orbit focus (skipped in walk mode)
|
|
79801
80158
|
events.on('inputEvent', this._onInputEvent);
|
|
79802
|
-
// mobile tap (no movement) →
|
|
80159
|
+
// mobile tap (no movement) → walk/fly target or orbit focus
|
|
79803
80160
|
events.on('mobileTap', this._onMobileTap);
|
|
79804
80161
|
// refresh cursor on mode / gaming-controls change
|
|
79805
|
-
events.on('cameraMode:changed', this.
|
|
80162
|
+
events.on('cameraMode:changed', this._onCameraModeChanged);
|
|
80163
|
+
events.on('inputMode:changed', this._updateCursor);
|
|
79806
80164
|
events.on('gamingControls:changed', this._updateCursor);
|
|
79807
80165
|
}
|
|
79808
80166
|
detach() {
|
|
@@ -79815,12 +80173,12 @@ class WalkInteraction {
|
|
|
79815
80173
|
const { events } = this._global;
|
|
79816
80174
|
events.off('inputEvent', this._onInputEvent);
|
|
79817
80175
|
events.off('mobileTap', this._onMobileTap);
|
|
79818
|
-
events.off('cameraMode:changed', this.
|
|
80176
|
+
events.off('cameraMode:changed', this._onCameraModeChanged);
|
|
80177
|
+
events.off('inputMode:changed', this._updateCursor);
|
|
79819
80178
|
events.off('gamingControls:changed', this._updateCursor);
|
|
79820
80179
|
}
|
|
79821
80180
|
this._canvas = null;
|
|
79822
80181
|
this._global = null;
|
|
79823
|
-
this._picker = null;
|
|
79824
80182
|
}
|
|
79825
80183
|
}
|
|
79826
80184
|
|
|
@@ -79832,15 +80190,22 @@ class GamepadDevice {
|
|
|
79832
80190
|
orbitSpeed = 18;
|
|
79833
80191
|
gamepadRotateSensitivity = 1.0;
|
|
79834
80192
|
_source = new GamepadSource();
|
|
79835
|
-
|
|
80193
|
+
_global = null;
|
|
80194
|
+
attach(_canvas, global) {
|
|
80195
|
+
this._global = global;
|
|
79836
80196
|
// GamepadSource polls navigator.getGamepads() — no DOM attach needed.
|
|
79837
80197
|
}
|
|
79838
|
-
detach() {
|
|
80198
|
+
detach() {
|
|
80199
|
+
this._global = null;
|
|
80200
|
+
}
|
|
79839
80201
|
update(ctx, frame) {
|
|
79840
|
-
const { dt, cameraComponent, isFirstPerson } = ctx;
|
|
80202
|
+
const { dt, cameraComponent, isFly, isFirstPerson } = ctx;
|
|
79841
80203
|
const { leftStick, rightStick } = this._source.read();
|
|
79842
80204
|
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79843
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
|
+
}
|
|
79844
80209
|
const v = tmpV$3.set(0, 0, 0);
|
|
79845
80210
|
stickMove.set(leftStick[0], 0, -leftStick[1]);
|
|
79846
80211
|
v.add(stickMove.mulScalar(this.moveSpeed * dt));
|
|
@@ -79853,7 +80218,9 @@ class GamepadDevice {
|
|
|
79853
80218
|
}
|
|
79854
80219
|
|
|
79855
80220
|
const tmpV1 = new Vec3();
|
|
80221
|
+
const tmpV2 = new Vec3();
|
|
79856
80222
|
const keyMove = new Vec3();
|
|
80223
|
+
const flyKeyVelocity = new Vec3();
|
|
79857
80224
|
const panMove = new Vec3();
|
|
79858
80225
|
const mouseRotate = new Vec3();
|
|
79859
80226
|
const wheelMove = new Vec3();
|
|
@@ -79884,6 +80251,8 @@ class KeyboardMouseDevice {
|
|
|
79884
80251
|
orbitSpeed = 18;
|
|
79885
80252
|
wheelSpeed = 0.06;
|
|
79886
80253
|
mouseRotateSensitivity = 0.5;
|
|
80254
|
+
flyMoveAccelerationDamping = 0.992;
|
|
80255
|
+
flyMoveDecelerationDamping = 0.993;
|
|
79887
80256
|
_source = new KeyboardMouseSource();
|
|
79888
80257
|
_global = null;
|
|
79889
80258
|
/** Running WASD/QE/arrow direction (sum of key states). */
|
|
@@ -79893,6 +80262,7 @@ class KeyboardMouseDevice {
|
|
|
79893
80262
|
_shift = 0;
|
|
79894
80263
|
_ctrl = 0;
|
|
79895
80264
|
_jump = 0;
|
|
80265
|
+
_flyKeyVelocity = new Vec3();
|
|
79896
80266
|
/**
|
|
79897
80267
|
* Get the underlying source so other code (PointerLockManager) can
|
|
79898
80268
|
* toggle its private pointer-lock flag, which gates how it consumes
|
|
@@ -79925,16 +80295,24 @@ class KeyboardMouseDevice {
|
|
|
79925
80295
|
for (let i = 0; i < n; i++) {
|
|
79926
80296
|
this._buttons[i] += button[i];
|
|
79927
80297
|
}
|
|
79928
|
-
const { isWalk, isFirstPerson, dt, distance, cameraComponent, mode, touchCount } = ctx;
|
|
79929
|
-
|
|
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)
|
|
79930
80301
|
if (isWalk && (this._axis.x !== 0 || this._axis.z !== 0)) {
|
|
79931
80302
|
events.fire('walkCancel');
|
|
79932
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
|
+
}
|
|
79933
80313
|
if (!isFirstPerson && this._axis.length() > 0) {
|
|
79934
80314
|
events.fire('inputEvent', 'requestFirstPerson');
|
|
79935
80315
|
}
|
|
79936
|
-
// pan flag: RMB held, RMB just released this frame, or 2+ touches active
|
|
79937
|
-
const pan = this._buttons[2] || +(button[2] === -1) || +(touchCount > 1);
|
|
79938
80316
|
const orbitFactor = isFirstPerson ? cameraComponent.fov / 120 : 1;
|
|
79939
80317
|
const { deltas } = frame;
|
|
79940
80318
|
// move (WASD + mouse-drag pan + wheel)
|
|
@@ -79949,7 +80327,22 @@ class KeyboardMouseDevice {
|
|
|
79949
80327
|
const shiftMul = isWalk ? 2 : 4;
|
|
79950
80328
|
const ctrlMul = isWalk ? 0.5 : 0.25;
|
|
79951
80329
|
const speed = this.moveSpeed * (this._shift ? shiftMul : this._ctrl ? ctrlMul : 1);
|
|
79952
|
-
|
|
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));
|
|
79953
80346
|
if (isWalk) {
|
|
79954
80347
|
// Pass jump signal as raw Y; WalkController uses move[1] > 0 as
|
|
79955
80348
|
// a boolean trigger.
|
|
@@ -79993,8 +80386,9 @@ class TouchDevice {
|
|
|
79993
80386
|
_pinchVelocity = 0;
|
|
79994
80387
|
/** Smoothed strafe/vertical velocity from two-finger pan, -1..1 each. */
|
|
79995
80388
|
_panVelocity = [0, 0];
|
|
79996
|
-
/** Tap-detection state — touch count and accumulated
|
|
80389
|
+
/** Tap-detection state — touch count, max touches, and accumulated movement. */
|
|
79997
80390
|
_tapTouches = 0;
|
|
80391
|
+
_tapMaxTouches = 0;
|
|
79998
80392
|
_tapDelta = 0;
|
|
79999
80393
|
/** True for one frame after a tap is detected during gaming controls. */
|
|
80000
80394
|
_tapJump = false;
|
|
@@ -80019,40 +80413,61 @@ class TouchDevice {
|
|
|
80019
80413
|
}
|
|
80020
80414
|
update(ctx, frame) {
|
|
80021
80415
|
const { touch, pinch, count } = this._source.read();
|
|
80022
|
-
const { isWalk, isFirstPerson, isOrbit, gamingControls, dt, distance, cameraComponent } = ctx;
|
|
80416
|
+
const { isFly, isWalk, isFirstPerson, isOrbit, gamingControls, dt, distance, cameraComponent } = ctx;
|
|
80023
80417
|
// running touch count
|
|
80024
80418
|
this._touchCount += count[0];
|
|
80025
|
-
|
|
80026
|
-
|
|
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) {
|
|
80027
80424
|
const prevTaps = this._tapTouches;
|
|
80028
80425
|
this._tapTouches = Math.max(0, this._tapTouches + count[0]);
|
|
80029
80426
|
if (prevTaps === 0 && this._tapTouches > 0) {
|
|
80030
80427
|
this._tapDelta = 0;
|
|
80031
80428
|
}
|
|
80429
|
+
if (this._tapTouches > 0) {
|
|
80430
|
+
this._tapMaxTouches = Math.max(this._tapMaxTouches, this._tapTouches);
|
|
80431
|
+
}
|
|
80032
80432
|
if (this._tapTouches > 0) {
|
|
80033
80433
|
const prevDelta = this._tapDelta;
|
|
80034
|
-
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]);
|
|
80035
80435
|
if (prevDelta < TAP_EPSILON && this._tapDelta >= TAP_EPSILON) {
|
|
80036
|
-
if (!gamingControls) {
|
|
80436
|
+
if (isWalk && !gamingControls) {
|
|
80037
80437
|
this._global.events.fire('walkCancel');
|
|
80038
80438
|
}
|
|
80439
|
+
else if (isFly) {
|
|
80440
|
+
this._global.events.fire('flyCancel');
|
|
80441
|
+
}
|
|
80039
80442
|
}
|
|
80040
80443
|
}
|
|
80041
80444
|
if (prevTaps > 0 && this._tapTouches === 0) {
|
|
80042
|
-
if (this._tapDelta < TAP_EPSILON) {
|
|
80043
|
-
if (!gamingControls) {
|
|
80445
|
+
if (this._tapDelta < TAP_EPSILON && this._tapMaxTouches === 1) {
|
|
80446
|
+
if (isWalk && !gamingControls) {
|
|
80044
80447
|
// Walk-interaction listens for this and fires walkTo
|
|
80045
80448
|
// after picking.
|
|
80046
80449
|
this._global.events.fire('mobileTap');
|
|
80047
80450
|
}
|
|
80048
|
-
else {
|
|
80451
|
+
else if (isWalk) {
|
|
80049
80452
|
this._tapJump = true;
|
|
80050
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
|
+
}
|
|
80051
80464
|
}
|
|
80465
|
+
this._tapMaxTouches = 0;
|
|
80052
80466
|
}
|
|
80053
80467
|
}
|
|
80054
80468
|
else {
|
|
80055
80469
|
this._tapTouches = 0;
|
|
80470
|
+
this._tapMaxTouches = 0;
|
|
80056
80471
|
}
|
|
80057
80472
|
// smoothed velocities for fly/walk first-person motion (non-gaming)
|
|
80058
80473
|
if (isFirstPerson && !gamingControls && this._touchCount > 1) {
|
|
@@ -80221,6 +80636,9 @@ class TrackpadDevice {
|
|
|
80221
80636
|
}
|
|
80222
80637
|
else {
|
|
80223
80638
|
// fly / walk: always rotate (shift is a speed modifier, not a gesture)
|
|
80639
|
+
if (mode === 'fly') {
|
|
80640
|
+
this._global.events.fire('flyCancel');
|
|
80641
|
+
}
|
|
80224
80642
|
this._orbit[0] += deltaX;
|
|
80225
80643
|
this._orbit[1] += deltaY;
|
|
80226
80644
|
}
|
|
@@ -80296,7 +80714,7 @@ class InputController {
|
|
|
80296
80714
|
_keyboardMouse = new KeyboardMouseDevice();
|
|
80297
80715
|
_touch = new TouchDevice();
|
|
80298
80716
|
_gamepad = new GamepadDevice();
|
|
80299
|
-
_walkInteraction
|
|
80717
|
+
_walkInteraction;
|
|
80300
80718
|
_pointerLock = new PointerLockManager();
|
|
80301
80719
|
_modeShortcuts = new ModeShortcuts();
|
|
80302
80720
|
_inputModeTracker = new InputModeTracker();
|
|
@@ -80306,8 +80724,9 @@ class InputController {
|
|
|
80306
80724
|
get collision() {
|
|
80307
80725
|
return this._walkInteraction.collision;
|
|
80308
80726
|
}
|
|
80309
|
-
constructor(global) {
|
|
80727
|
+
constructor(global, picker) {
|
|
80310
80728
|
this._global = global;
|
|
80729
|
+
this._walkInteraction = new WalkInteraction(picker);
|
|
80311
80730
|
const { app, events } = global;
|
|
80312
80731
|
const canvas = app.graphicsDevice.canvas;
|
|
80313
80732
|
// Trackpad MUST attach before KeyboardMouseDevice so its wheel
|
|
@@ -80363,6 +80782,804 @@ class InputController {
|
|
|
80363
80782
|
}
|
|
80364
80783
|
}
|
|
80365
80784
|
|
|
80785
|
+
// Single-layer overlay rendered after the gaussians, three passes on a fresh
|
|
80786
|
+
// depth buffer:
|
|
80787
|
+
//
|
|
80788
|
+
// 1. Surface depth pre-pass: color writes masked off, depth test/write on.
|
|
80789
|
+
// Stamps the front-most surface depth into the depth buffer.
|
|
80790
|
+
// 2. Surface color pass: depthFunc EQUAL, depth write off, vertex-color
|
|
80791
|
+
// tinted via StandardMaterial. Only the front-most fragment from pass 1
|
|
80792
|
+
// survives so a single layer of semi-transparent surface color blends
|
|
80793
|
+
// onto the camera target.
|
|
80794
|
+
// 3. Wireframe pass: opaque-looking black lines (RENDERSTYLE_WIREFRAME),
|
|
80795
|
+
// depth-tested against the surface depth so back-facing edges are
|
|
80796
|
+
// hidden.
|
|
80797
|
+
//
|
|
80798
|
+
// All three passes use BLEND_NORMAL so they share the layer's *transparent*
|
|
80799
|
+
// render action. PlayCanvas creates separate opaque and transparent render
|
|
80800
|
+
// actions per layer and `clearDepthBuffer` clears the depth buffer for each
|
|
80801
|
+
// of them — if the depth pre-pass were opaque, the transparent action would
|
|
80802
|
+
// wipe the depth before pass 2 and FUNC_EQUAL would always fail.
|
|
80803
|
+
// Linear gray levels picked by dominant face axis, plus the surface alpha.
|
|
80804
|
+
// These values are what we want the framebuffer to actually contain — pre-
|
|
80805
|
+
// encoding below makes that true regardless of the gamma path taken.
|
|
80806
|
+
const SURFACE_GRAY_X = 0.85;
|
|
80807
|
+
const SURFACE_GRAY_Y = 0.55;
|
|
80808
|
+
const SURFACE_GRAY_Z = 0.30;
|
|
80809
|
+
const SURFACE_ALPHA = 0.30;
|
|
80810
|
+
// Build an unindexed mesh where every triangle has three unique vertices that
|
|
80811
|
+
// share the triangle's flat face color (tint by dominant axis of the face
|
|
80812
|
+
// normal, alpha baked in). Per-triangle vertices give the surface a faceted
|
|
80813
|
+
// look matching the voxel overlay.
|
|
80814
|
+
//
|
|
80815
|
+
// `cameraFrameEnabled` controls how the per-vertex color is encoded so the
|
|
80816
|
+
// overlay looks identical between the WebGL (no CameraFrame) and
|
|
80817
|
+
// WebGPU/compute (CameraFrame) paths. With CameraFrame on, the engine's
|
|
80818
|
+
// `gammaCorrectOutput` is a no-op (GAMMA_NONE) and the StandardMaterial
|
|
80819
|
+
// output lands in the framebuffer as-is — so we feed the raw gray value.
|
|
80820
|
+
// Without CameraFrame, `gammaCorrectOutput` applies `pow(1/2.2)` to the
|
|
80821
|
+
// material output, so we feed `pow(gray, 2.2)` here and gamma-correct
|
|
80822
|
+
// undoes it; the framebuffer ends up storing the same raw gray value.
|
|
80823
|
+
// Encode the per-triangle gray + alpha into a flat Uint8 RGBA color stream
|
|
80824
|
+
// (one entry per unwelded vertex, three vertices per triangle). Reuses an
|
|
80825
|
+
// existing buffer if one is provided so colors can be re-baked when the
|
|
80826
|
+
// CameraFrame state toggles at runtime (e.g. XR start/end).
|
|
80827
|
+
const encodeFlatColors = (tris, cameraFrameEnabled, out) => {
|
|
80828
|
+
const encode = (v) => Math.round((cameraFrameEnabled ? v : Math.pow(v, 2.2)) * 255);
|
|
80829
|
+
const grayX = encode(SURFACE_GRAY_X);
|
|
80830
|
+
const grayY = encode(SURFACE_GRAY_Y);
|
|
80831
|
+
const grayZ = encode(SURFACE_GRAY_Z);
|
|
80832
|
+
const alpha = Math.round(SURFACE_ALPHA * 255);
|
|
80833
|
+
const numTris = tris.count;
|
|
80834
|
+
const colors = out ?? new Uint8Array(numTris * 12);
|
|
80835
|
+
for (let i = 0; i < numTris; i++) {
|
|
80836
|
+
const ax = Math.abs(tris.nx[i]);
|
|
80837
|
+
const ay = Math.abs(tris.ny[i]);
|
|
80838
|
+
const az = Math.abs(tris.nz[i]);
|
|
80839
|
+
let gray;
|
|
80840
|
+
if (ax > ay && ax > az) {
|
|
80841
|
+
gray = grayX;
|
|
80842
|
+
}
|
|
80843
|
+
else if (ay > az) {
|
|
80844
|
+
gray = grayY;
|
|
80845
|
+
}
|
|
80846
|
+
else {
|
|
80847
|
+
gray = grayZ;
|
|
80848
|
+
}
|
|
80849
|
+
const oc = i * 12;
|
|
80850
|
+
for (let j = 0; j < 3; j++) {
|
|
80851
|
+
const k = oc + j * 4;
|
|
80852
|
+
colors[k] = gray;
|
|
80853
|
+
colors[k + 1] = gray;
|
|
80854
|
+
colors[k + 2] = gray;
|
|
80855
|
+
colors[k + 3] = alpha;
|
|
80856
|
+
}
|
|
80857
|
+
}
|
|
80858
|
+
return colors;
|
|
80859
|
+
};
|
|
80860
|
+
const buildFlatMesh = (tris, cameraFrameEnabled) => {
|
|
80861
|
+
const numTris = tris.count;
|
|
80862
|
+
const flatPositions = new Float32Array(numTris * 9);
|
|
80863
|
+
const flatColors = encodeFlatColors(tris, cameraFrameEnabled);
|
|
80864
|
+
const flatIndices = new Uint32Array(numTris * 3);
|
|
80865
|
+
for (let i = 0; i < numTris; i++) {
|
|
80866
|
+
const op = i * 9;
|
|
80867
|
+
flatPositions[op] = tris.v0x[i];
|
|
80868
|
+
flatPositions[op + 1] = tris.v0y[i];
|
|
80869
|
+
flatPositions[op + 2] = tris.v0z[i];
|
|
80870
|
+
flatPositions[op + 3] = tris.v1x[i];
|
|
80871
|
+
flatPositions[op + 4] = tris.v1y[i];
|
|
80872
|
+
flatPositions[op + 5] = tris.v1z[i];
|
|
80873
|
+
flatPositions[op + 6] = tris.v2x[i];
|
|
80874
|
+
flatPositions[op + 7] = tris.v2y[i];
|
|
80875
|
+
flatPositions[op + 8] = tris.v2z[i];
|
|
80876
|
+
const oi = i * 3;
|
|
80877
|
+
flatIndices[oi] = oi;
|
|
80878
|
+
flatIndices[oi + 1] = oi + 1;
|
|
80879
|
+
flatIndices[oi + 2] = oi + 2;
|
|
80880
|
+
}
|
|
80881
|
+
return { flatPositions, flatColors, flatIndices };
|
|
80882
|
+
};
|
|
80883
|
+
// Configures a StandardMaterial that emits the per-vertex color directly. The
|
|
80884
|
+
// depth pre-pass and the color pass use the same configuration (so they
|
|
80885
|
+
// compile to identical shaders and produce bit-identical depth values for
|
|
80886
|
+
// FUNC_EQUAL); only their write masks and depth state differ.
|
|
80887
|
+
const makeSurfaceMaterial = () => {
|
|
80888
|
+
const m = new StandardMaterial();
|
|
80889
|
+
m.useLighting = false;
|
|
80890
|
+
m.useSkybox = false;
|
|
80891
|
+
m.useFog = false;
|
|
80892
|
+
m.useTonemap = false;
|
|
80893
|
+
m.ambient = new Color(0, 0, 0);
|
|
80894
|
+
m.diffuse = new Color(0, 0, 0);
|
|
80895
|
+
m.specular = new Color(0, 0, 0);
|
|
80896
|
+
m.emissive = new Color(1, 1, 1);
|
|
80897
|
+
m.emissiveVertexColor = true;
|
|
80898
|
+
m.emissiveVertexColorChannel = 'rgb';
|
|
80899
|
+
m.opacityVertexColor = true;
|
|
80900
|
+
m.opacityVertexColorChannel = 'a';
|
|
80901
|
+
m.opacity = 1;
|
|
80902
|
+
return m;
|
|
80903
|
+
};
|
|
80904
|
+
class MeshDebugOverlay {
|
|
80905
|
+
app;
|
|
80906
|
+
camera;
|
|
80907
|
+
layer;
|
|
80908
|
+
entity;
|
|
80909
|
+
mesh;
|
|
80910
|
+
triangles;
|
|
80911
|
+
flatColors;
|
|
80912
|
+
materials;
|
|
80913
|
+
_enabled = false;
|
|
80914
|
+
constructor(app, collision, camera, cameraFrameEnabled) {
|
|
80915
|
+
this.app = app;
|
|
80916
|
+
this.camera = camera;
|
|
80917
|
+
this.triangles = collision.triangles;
|
|
80918
|
+
const device = app.graphicsDevice;
|
|
80919
|
+
const { flatPositions, flatColors, flatIndices } = buildFlatMesh(this.triangles, cameraFrameEnabled);
|
|
80920
|
+
this.flatColors = flatColors;
|
|
80921
|
+
const mesh = new Mesh(device);
|
|
80922
|
+
mesh.setPositions(flatPositions);
|
|
80923
|
+
mesh.setColors32(flatColors);
|
|
80924
|
+
mesh.setIndices(flatIndices);
|
|
80925
|
+
mesh.update(PRIMITIVE_TRIANGLES);
|
|
80926
|
+
mesh.generateWireframe();
|
|
80927
|
+
this.mesh = mesh;
|
|
80928
|
+
this.layer = new Layer({
|
|
80929
|
+
name: 'CollisionOverlay',
|
|
80930
|
+
enabled: false,
|
|
80931
|
+
clearColorBuffer: false,
|
|
80932
|
+
clearDepthBuffer: true,
|
|
80933
|
+
opaqueSortMode: SORTMODE_MANUAL,
|
|
80934
|
+
transparentSortMode: SORTMODE_MANUAL
|
|
80935
|
+
});
|
|
80936
|
+
app.scene.layers.push(this.layer);
|
|
80937
|
+
camera.camera.layers = [...camera.camera.layers, this.layer.id];
|
|
80938
|
+
// Pass 1: depth pre-pass. Color writes masked off so only depth lands
|
|
80939
|
+
// in the buffer. Both this and pass 2 use the same depthBias /
|
|
80940
|
+
// slopeDepthBias so they write/test identical depth values
|
|
80941
|
+
// (FUNC_EQUAL relies on this) while still sitting slightly behind the
|
|
80942
|
+
// wireframe lines so pass 3's FUNC_LESSEQUAL passes reliably without
|
|
80943
|
+
// z-fighting.
|
|
80944
|
+
const depthMaterial = makeSurfaceMaterial();
|
|
80945
|
+
depthMaterial.cull = CULLFACE_BACK;
|
|
80946
|
+
depthMaterial.blendType = BLEND_NORMAL;
|
|
80947
|
+
depthMaterial.depthTest = true;
|
|
80948
|
+
depthMaterial.depthWrite = true;
|
|
80949
|
+
depthMaterial.depthBias = 1;
|
|
80950
|
+
depthMaterial.slopeDepthBias = 1;
|
|
80951
|
+
depthMaterial.redWrite = false;
|
|
80952
|
+
depthMaterial.greenWrite = false;
|
|
80953
|
+
depthMaterial.blueWrite = false;
|
|
80954
|
+
depthMaterial.alphaWrite = false;
|
|
80955
|
+
depthMaterial.update();
|
|
80956
|
+
const depthInstance = new MeshInstance(mesh, depthMaterial);
|
|
80957
|
+
depthInstance.drawOrder = 0;
|
|
80958
|
+
const depthEntity = new Entity('CollisionDepthPrepass');
|
|
80959
|
+
depthEntity.addComponent('render', {
|
|
80960
|
+
meshInstances: [depthInstance],
|
|
80961
|
+
layers: [this.layer.id]
|
|
80962
|
+
});
|
|
80963
|
+
// Pass 2: surface color, depth EQUAL. Only the front-most fragment
|
|
80964
|
+
// from pass 1 survives, so a single layer of vertex color blends onto
|
|
80965
|
+
// the camera target.
|
|
80966
|
+
const surfaceMaterial = makeSurfaceMaterial();
|
|
80967
|
+
surfaceMaterial.cull = CULLFACE_BACK;
|
|
80968
|
+
surfaceMaterial.blendType = BLEND_NORMAL;
|
|
80969
|
+
surfaceMaterial.depthTest = true;
|
|
80970
|
+
surfaceMaterial.depthFunc = FUNC_EQUAL;
|
|
80971
|
+
surfaceMaterial.depthWrite = false;
|
|
80972
|
+
surfaceMaterial.depthBias = 1;
|
|
80973
|
+
surfaceMaterial.slopeDepthBias = 1;
|
|
80974
|
+
surfaceMaterial.update();
|
|
80975
|
+
const surfaceInstance = new MeshInstance(mesh, surfaceMaterial);
|
|
80976
|
+
surfaceInstance.drawOrder = 1;
|
|
80977
|
+
const surfaceEntity = new Entity('CollisionSurface');
|
|
80978
|
+
surfaceEntity.addComponent('render', {
|
|
80979
|
+
meshInstances: [surfaceInstance],
|
|
80980
|
+
layers: [this.layer.id]
|
|
80981
|
+
});
|
|
80982
|
+
// Pass 3: wireframe — black lines depth-tested against the surface so
|
|
80983
|
+
// back-facing edges are hidden. BLEND_NORMAL with opacity = 1 looks
|
|
80984
|
+
// opaque but routes through the same transparent render action as the
|
|
80985
|
+
// other two passes, keeping all three under one depth clear.
|
|
80986
|
+
const wireframeMaterial = new StandardMaterial();
|
|
80987
|
+
wireframeMaterial.useLighting = false;
|
|
80988
|
+
wireframeMaterial.useSkybox = false;
|
|
80989
|
+
wireframeMaterial.useFog = false;
|
|
80990
|
+
wireframeMaterial.useTonemap = false;
|
|
80991
|
+
wireframeMaterial.ambient = new Color(0, 0, 0);
|
|
80992
|
+
wireframeMaterial.diffuse = new Color(0, 0, 0);
|
|
80993
|
+
wireframeMaterial.specular = new Color(0, 0, 0);
|
|
80994
|
+
wireframeMaterial.emissive = new Color(0, 0, 0);
|
|
80995
|
+
wireframeMaterial.opacity = 1;
|
|
80996
|
+
wireframeMaterial.blendType = BLEND_NORMAL;
|
|
80997
|
+
wireframeMaterial.depthTest = true;
|
|
80998
|
+
wireframeMaterial.depthFunc = FUNC_LESSEQUAL;
|
|
80999
|
+
wireframeMaterial.depthWrite = false;
|
|
81000
|
+
wireframeMaterial.cull = CULLFACE_NONE;
|
|
81001
|
+
wireframeMaterial.update();
|
|
81002
|
+
const wireframeInstance = new MeshInstance(mesh, wireframeMaterial);
|
|
81003
|
+
wireframeInstance.drawOrder = 2;
|
|
81004
|
+
const wireframeEntity = new Entity('CollisionWireframe');
|
|
81005
|
+
wireframeEntity.addComponent('render', {
|
|
81006
|
+
meshInstances: [wireframeInstance],
|
|
81007
|
+
layers: [this.layer.id]
|
|
81008
|
+
});
|
|
81009
|
+
wireframeEntity.render.renderStyle = RENDERSTYLE_WIREFRAME;
|
|
81010
|
+
this.materials = [depthMaterial, surfaceMaterial, wireframeMaterial];
|
|
81011
|
+
this.entity = new Entity('MeshCollisionDebug');
|
|
81012
|
+
this.entity.addChild(depthEntity);
|
|
81013
|
+
this.entity.addChild(surfaceEntity);
|
|
81014
|
+
this.entity.addChild(wireframeEntity);
|
|
81015
|
+
this.entity.enabled = false;
|
|
81016
|
+
app.root.addChild(this.entity);
|
|
81017
|
+
}
|
|
81018
|
+
set enabled(value) {
|
|
81019
|
+
this._enabled = value;
|
|
81020
|
+
this.entity.enabled = value;
|
|
81021
|
+
// Disable the layer too — otherwise its render actions still execute
|
|
81022
|
+
// each frame and the per-layer `clearDepthBuffer` would wipe depth
|
|
81023
|
+
// even when no overlay meshes are submitted.
|
|
81024
|
+
this.layer.enabled = value;
|
|
81025
|
+
}
|
|
81026
|
+
get enabled() {
|
|
81027
|
+
return this._enabled;
|
|
81028
|
+
}
|
|
81029
|
+
/**
|
|
81030
|
+
* Re-bake and re-upload the per-vertex colors so the overlay stays
|
|
81031
|
+
* correct if CameraFrame is destroyed or recreated at runtime (the
|
|
81032
|
+
* gamma path differs between the two states).
|
|
81033
|
+
*
|
|
81034
|
+
* @param cameraFrameEnabled - whether CameraFrame is currently active.
|
|
81035
|
+
*/
|
|
81036
|
+
setCameraFrameEnabled(cameraFrameEnabled) {
|
|
81037
|
+
encodeFlatColors(this.triangles, cameraFrameEnabled, this.flatColors);
|
|
81038
|
+
this.mesh.setColors32(this.flatColors);
|
|
81039
|
+
this.mesh.update(PRIMITIVE_TRIANGLES);
|
|
81040
|
+
}
|
|
81041
|
+
destroy() {
|
|
81042
|
+
// Entity.destroy() removes child entities and tears down their render
|
|
81043
|
+
// components, which destroy the MeshInstances and decref the shared
|
|
81044
|
+
// Mesh (the last decref destroys its GPU buffers). Materials are not
|
|
81045
|
+
// owned by MeshInstance so destroy them explicitly here.
|
|
81046
|
+
this.entity?.destroy();
|
|
81047
|
+
for (const m of this.materials)
|
|
81048
|
+
m.destroy();
|
|
81049
|
+
this.materials.length = 0;
|
|
81050
|
+
this.app.scene.layers.remove(this.layer);
|
|
81051
|
+
this.camera.camera.layers = this.camera.camera.layers.filter(id => id !== this.layer.id);
|
|
81052
|
+
}
|
|
81053
|
+
}
|
|
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
|
+
|
|
80366
81583
|
// ---------------------------------------------------------------------------
|
|
80367
81584
|
// WGSL compute shader: ray-march through the sparse voxel octree per pixel
|
|
80368
81585
|
// ---------------------------------------------------------------------------
|
|
@@ -80377,11 +81594,12 @@ const MAX_STEPS: u32 = 512u;
|
|
|
80377
81594
|
// Target wireframe edge width in pixels
|
|
80378
81595
|
const EDGE_PIXELS: f32 = 1.5;
|
|
80379
81596
|
|
|
80380
|
-
// Wireframe edge alpha
|
|
80381
|
-
|
|
81597
|
+
// Wireframe edge alpha (1.0 = pure black opaque edges, matching the mesh
|
|
81598
|
+
// overlay's wireframe pass).
|
|
81599
|
+
const EDGE_ALPHA: f32 = 0.8;
|
|
80382
81600
|
|
|
80383
|
-
// Interior fill alpha (
|
|
80384
|
-
const FILL_ALPHA: f32 = 0.
|
|
81601
|
+
// Interior fill alpha (matching the mesh overlay's surface alpha).
|
|
81602
|
+
const FILL_ALPHA: f32 = 0.30;
|
|
80385
81603
|
|
|
80386
81604
|
struct Uniforms {
|
|
80387
81605
|
invVP: mat4x4<f32>,
|
|
@@ -80490,14 +81708,16 @@ fn edgeFactor(hitPos: vec3f, voxMin: vec3f, voxSize: f32, edgeWidth: f32) -> f32
|
|
|
80490
81708
|
return 1.0 - smoothstep(0.0, edgeWidth, edgeDist);
|
|
80491
81709
|
}
|
|
80492
81710
|
|
|
80493
|
-
// Shade a voxel hit, returning premultiplied RGBA
|
|
80494
|
-
|
|
81711
|
+
// Shade a voxel hit, returning premultiplied RGBA. Uses the same face-axis
|
|
81712
|
+
// grayscale palette as the mesh collision overlay (0.85 / 0.55 / 0.30 by
|
|
81713
|
+
// dominant axis), with pure black at face edges to mimic that overlay's
|
|
81714
|
+
// wireframe pass.
|
|
81715
|
+
fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f) -> vec4f {
|
|
80495
81716
|
let dist = length(hitPos - ro);
|
|
80496
81717
|
let pixelWorld = 2.0 * dist / (f32(uniforms.screenHeight) * uniforms.projScaleY);
|
|
80497
81718
|
let ew = clamp(EDGE_PIXELS * pixelWorld / voxelRes, 0.01, 0.5);
|
|
80498
81719
|
|
|
80499
81720
|
let ef = edgeFactor(hitPos, voxMin, voxelRes, ew);
|
|
80500
|
-
let distFade = clamp(1.0 - dist * 0.01, 0.2, 1.0);
|
|
80501
81721
|
|
|
80502
81722
|
let local = (hitPos - voxMin) / voxelRes;
|
|
80503
81723
|
let fx = min(local.x, 1.0 - local.x);
|
|
@@ -80512,19 +81732,17 @@ fn shadeVoxelHit(hitPos: vec3f, voxMin: vec3f, voxelRes: f32, ro: vec3f, isFullB
|
|
|
80512
81732
|
}
|
|
80513
81733
|
|
|
80514
81734
|
var baseColor: vec3f;
|
|
80515
|
-
if (
|
|
80516
|
-
|
|
80517
|
-
|
|
80518
|
-
else { baseColor = vec3f(0.55, 0.08, 0.05); }
|
|
80519
|
-
} else {
|
|
80520
|
-
if (faceAxis == 0u) { baseColor = vec3f(0.7, 0.7, 0.72); }
|
|
80521
|
-
else if (faceAxis == 1u) { baseColor = vec3f(0.5, 0.5, 0.52); }
|
|
80522
|
-
else { baseColor = vec3f(0.33, 0.33, 0.35); }
|
|
80523
|
-
}
|
|
81735
|
+
if (faceAxis == 0u) { baseColor = vec3f(0.85); }
|
|
81736
|
+
else if (faceAxis == 1u) { baseColor = vec3f(0.55); }
|
|
81737
|
+
else { baseColor = vec3f(0.30); }
|
|
80524
81738
|
|
|
80525
|
-
|
|
81739
|
+
// Mix the surface base color toward black as the edge factor approaches 1
|
|
81740
|
+
// and ramp alpha from FILL_ALPHA up to EDGE_ALPHA so face edges read as
|
|
81741
|
+
// opaque black lines while the interior stays at the surface tint.
|
|
81742
|
+
let color = mix(baseColor, vec3f(0.0), ef);
|
|
81743
|
+
let alpha = mix(FILL_ALPHA, EDGE_ALPHA, ef);
|
|
80526
81744
|
|
|
80527
|
-
return vec4f(
|
|
81745
|
+
return vec4f(color * alpha, alpha);
|
|
80528
81746
|
}
|
|
80529
81747
|
|
|
80530
81748
|
// Blue (0) -> Cyan (0.25) -> Green (0.5) -> Yellow (0.75) -> Red (1.0)
|
|
@@ -80721,8 +81939,7 @@ fn main(@builtin(global_invocation_id) gid: vec3u) {
|
|
|
80721
81939
|
let voxMin = blockOrigin + vec3f(f32(vx), f32(vy), f32(vz)) * voxelRes;
|
|
80722
81940
|
let vHit = intersectAABB(ro, invDir, voxMin, voxMin + vec3f(voxelRes));
|
|
80723
81941
|
let hitPos = ro + rd * max(vHit.x, 0.0);
|
|
80724
|
-
let
|
|
80725
|
-
let result = shadeVoxelHit(hitPos, voxMin, voxelRes, ro, isFullBlock);
|
|
81942
|
+
let result = shadeVoxelHit(hitPos, voxMin, voxelRes, ro);
|
|
80726
81943
|
textureStore(outputTexture, vec2i(px, py), result);
|
|
80727
81944
|
} else {
|
|
80728
81945
|
let effort = f32(totalWork) / 256.0;
|
|
@@ -80999,6 +82216,26 @@ const CIRCLE_OUTER_RADIUS = 0.2;
|
|
|
80999
82216
|
const CIRCLE_INNER_RADIUS = 0.17;
|
|
81000
82217
|
const BEZIER_K = 1 / 6;
|
|
81001
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();
|
|
81002
82239
|
const tmpV = new Vec3();
|
|
81003
82240
|
const tmpScreen = new Vec3();
|
|
81004
82241
|
const tangent = new Vec3();
|
|
@@ -81022,35 +82259,66 @@ const buildBezierRing = (sx, sy) => {
|
|
|
81022
82259
|
}
|
|
81023
82260
|
return `${p} Z`;
|
|
81024
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
|
+
};
|
|
81025
82283
|
class WalkCursor {
|
|
81026
82284
|
svg;
|
|
81027
82285
|
cursorPath;
|
|
81028
82286
|
targetPath;
|
|
81029
|
-
app;
|
|
81030
82287
|
camera;
|
|
81031
82288
|
collision;
|
|
81032
82289
|
canvas;
|
|
82290
|
+
state;
|
|
82291
|
+
picker;
|
|
81033
82292
|
active = false;
|
|
81034
82293
|
walking = false;
|
|
81035
82294
|
targetPos = null;
|
|
81036
82295
|
targetNormal = null;
|
|
82296
|
+
targetMode = null;
|
|
81037
82297
|
smoothNx = 0;
|
|
81038
82298
|
smoothNy = 1;
|
|
81039
82299
|
smoothNz = 0;
|
|
81040
82300
|
hasSmoothedNormal = false;
|
|
82301
|
+
surfaceCursorX = 0;
|
|
82302
|
+
surfaceCursorY = 0;
|
|
82303
|
+
hasSurfaceCursorPosition = false;
|
|
82304
|
+
surfaceCursorVersion = 0;
|
|
82305
|
+
surfaceCursorPickPending = false;
|
|
81041
82306
|
onPointerMove;
|
|
81042
82307
|
onPointerLeave;
|
|
81043
|
-
scratchX = new Float64Array(NUM_SAMPLES);
|
|
81044
|
-
scratchY = new Float64Array(NUM_SAMPLES);
|
|
81045
82308
|
outerX = new Float64Array(NUM_SAMPLES);
|
|
81046
82309
|
outerY = new Float64Array(NUM_SAMPLES);
|
|
81047
82310
|
innerX = new Float64Array(NUM_SAMPLES);
|
|
81048
82311
|
innerY = new Float64Array(NUM_SAMPLES);
|
|
81049
|
-
|
|
81050
|
-
|
|
82312
|
+
collisionTarget = {
|
|
82313
|
+
position: new Vec3(),
|
|
82314
|
+
normal: new Vec3()
|
|
82315
|
+
};
|
|
82316
|
+
constructor(app, camera, collision, events, state, picker) {
|
|
81051
82317
|
this.camera = camera;
|
|
81052
82318
|
this.collision = collision;
|
|
81053
82319
|
this.canvas = app.graphicsDevice.canvas;
|
|
82320
|
+
this.state = state;
|
|
82321
|
+
this.picker = picker;
|
|
81054
82322
|
this.svg = document.createElementNS(SVGNS, 'svg');
|
|
81055
82323
|
this.svg.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;overflow:visible;z-index:1';
|
|
81056
82324
|
this.canvas.parentElement.appendChild(this.svg);
|
|
@@ -81061,38 +82329,59 @@ class WalkCursor {
|
|
|
81061
82329
|
this.cursorPath.setAttribute('fill-rule', 'evenodd');
|
|
81062
82330
|
this.cursorPath.setAttribute('stroke', 'none');
|
|
81063
82331
|
this.svg.appendChild(this.cursorPath);
|
|
81064
|
-
//
|
|
82332
|
+
// Selected target cursor: same ring geometry as hover.
|
|
81065
82333
|
this.targetPath = document.createElementNS(SVGNS, 'path');
|
|
81066
82334
|
this.targetPath.setAttribute('fill', 'white');
|
|
81067
|
-
this.targetPath.setAttribute('fill-opacity', '0.
|
|
82335
|
+
this.targetPath.setAttribute('fill-opacity', '0.6');
|
|
82336
|
+
this.targetPath.setAttribute('fill-rule', 'evenodd');
|
|
81068
82337
|
this.targetPath.setAttribute('stroke', 'none');
|
|
81069
82338
|
this.targetPath.style.display = 'none';
|
|
81070
82339
|
this.svg.appendChild(this.targetPath);
|
|
81071
82340
|
this.svg.style.display = 'none';
|
|
81072
82341
|
this.onPointerMove = (e) => {
|
|
81073
|
-
if (e.pointerType === 'touch')
|
|
82342
|
+
if (e.pointerType === 'touch') {
|
|
82343
|
+
this.hasSurfaceCursorPosition = false;
|
|
82344
|
+
this.surfaceCursorVersion++;
|
|
82345
|
+
this.hideCursor();
|
|
81074
82346
|
return;
|
|
82347
|
+
}
|
|
81075
82348
|
if (e.buttons) {
|
|
81076
|
-
this.
|
|
81077
|
-
this.
|
|
82349
|
+
this.hasSurfaceCursorPosition = false;
|
|
82350
|
+
this.surfaceCursorVersion++;
|
|
82351
|
+
this.hideCursor();
|
|
81078
82352
|
return;
|
|
81079
82353
|
}
|
|
81080
82354
|
this.updateCursor(e.offsetX, e.offsetY);
|
|
81081
82355
|
};
|
|
81082
82356
|
this.onPointerLeave = () => {
|
|
81083
|
-
this.
|
|
81084
|
-
this.
|
|
82357
|
+
this.hasSurfaceCursorPosition = false;
|
|
82358
|
+
this.surfaceCursorVersion++;
|
|
82359
|
+
this.hideCursor();
|
|
81085
82360
|
};
|
|
81086
82361
|
this.canvas.addEventListener('pointermove', this.onPointerMove);
|
|
81087
82362
|
this.canvas.addEventListener('pointerleave', this.onPointerLeave);
|
|
81088
82363
|
const updateActive = () => {
|
|
81089
|
-
|
|
81090
|
-
|
|
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
|
+
}
|
|
81091
82379
|
if (!this.active) {
|
|
81092
82380
|
this.svg.style.display = 'none';
|
|
81093
82381
|
}
|
|
81094
82382
|
};
|
|
81095
82383
|
events.on('cameraMode:changed', updateActive);
|
|
82384
|
+
events.on('inputMode:changed', updateActive);
|
|
81096
82385
|
events.on('gamingControls:changed', updateActive);
|
|
81097
82386
|
events.on('walkTo', () => {
|
|
81098
82387
|
this.walking = true;
|
|
@@ -81108,27 +82397,70 @@ class WalkCursor {
|
|
|
81108
82397
|
this.clearTarget();
|
|
81109
82398
|
});
|
|
81110
82399
|
events.on('walkTarget:set', (pos, normal) => {
|
|
81111
|
-
this.setTarget(pos, normal);
|
|
82400
|
+
this.setTarget(pos, normal, 'walk');
|
|
81112
82401
|
});
|
|
81113
82402
|
events.on('walkTarget:clear', () => {
|
|
81114
82403
|
this.clearTarget();
|
|
81115
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
|
+
});
|
|
81116
82433
|
app.on('prerender', () => {
|
|
81117
82434
|
this.updateTarget();
|
|
81118
82435
|
});
|
|
81119
82436
|
updateActive();
|
|
81120
82437
|
}
|
|
81121
|
-
setTarget(pos, normal) {
|
|
82438
|
+
setTarget(pos, normal, mode) {
|
|
82439
|
+
this.surfaceCursorVersion++;
|
|
81122
82440
|
this.targetPos = pos.clone();
|
|
81123
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;
|
|
81124
82446
|
}
|
|
81125
82447
|
clearTarget() {
|
|
82448
|
+
const mode = this.targetMode;
|
|
81126
82449
|
this.targetPos = null;
|
|
81127
82450
|
this.targetNormal = null;
|
|
82451
|
+
this.targetMode = null;
|
|
82452
|
+
if (mode === 'orbit') {
|
|
82453
|
+
this.cursorPath.style.display = 'none';
|
|
82454
|
+
}
|
|
81128
82455
|
this.targetPath.style.display = 'none';
|
|
82456
|
+
this.refreshSurfaceCursor();
|
|
82457
|
+
}
|
|
82458
|
+
hideCursor() {
|
|
82459
|
+
this.cursorPath.style.display = 'none';
|
|
82460
|
+
this.hasSmoothedNormal = false;
|
|
81129
82461
|
}
|
|
81130
82462
|
projectCircle(px, py, pz, nx, ny, nz, radius, outX, outY) {
|
|
81131
|
-
const normal =
|
|
82463
|
+
const normal = snapNormal(nx, ny, nz, tmpV);
|
|
81132
82464
|
if (Math.abs(normal.y) < 0.99) {
|
|
81133
82465
|
tangent.cross(normal, up).normalize();
|
|
81134
82466
|
}
|
|
@@ -81151,11 +82483,16 @@ class WalkCursor {
|
|
|
81151
82483
|
outY[i] = tmpScreen.y;
|
|
81152
82484
|
}
|
|
81153
82485
|
}
|
|
81154
|
-
|
|
81155
|
-
|
|
81156
|
-
|
|
81157
|
-
|
|
81158
|
-
|
|
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;
|
|
81159
82496
|
}
|
|
81160
82497
|
const { camera, collision } = this;
|
|
81161
82498
|
const cameraPos = camera.getPosition();
|
|
@@ -81163,17 +82500,28 @@ class WalkCursor {
|
|
|
81163
82500
|
tmpV.sub(cameraPos).normalize();
|
|
81164
82501
|
const hit = collision.queryRay(cameraPos.x, cameraPos.y, cameraPos.z, tmpV.x, tmpV.y, tmpV.z, camera.camera.farClip);
|
|
81165
82502
|
if (!hit) {
|
|
81166
|
-
|
|
81167
|
-
this.hasSmoothedNormal = false;
|
|
81168
|
-
return;
|
|
82503
|
+
return null;
|
|
81169
82504
|
}
|
|
81170
|
-
const px = hit.x;
|
|
81171
|
-
const py = hit.y;
|
|
81172
|
-
const pz = hit.z;
|
|
81173
82505
|
const sn = collision.querySurfaceNormal(hit.x, hit.y, hit.z, tmpV.x, tmpV.y, tmpV.z);
|
|
81174
|
-
|
|
81175
|
-
|
|
81176
|
-
|
|
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;
|
|
81177
82525
|
if (this.hasSmoothedNormal) {
|
|
81178
82526
|
const t = NORMAL_SMOOTH_FACTOR;
|
|
81179
82527
|
nx = this.smoothNx + (nx - this.smoothNx) * t;
|
|
@@ -81191,11 +82539,76 @@ class WalkCursor {
|
|
|
81191
82539
|
this.smoothNy = ny;
|
|
81192
82540
|
this.smoothNz = nz;
|
|
81193
82541
|
this.hasSmoothedNormal = true;
|
|
81194
|
-
this.
|
|
81195
|
-
|
|
81196
|
-
|
|
81197
|
-
this.
|
|
81198
|
-
|
|
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);
|
|
81199
82612
|
}
|
|
81200
82613
|
updateTarget() {
|
|
81201
82614
|
if (!this.active || !this.targetPos || !this.targetNormal) {
|
|
@@ -81203,14 +82616,11 @@ class WalkCursor {
|
|
|
81203
82616
|
}
|
|
81204
82617
|
const camPos = this.camera.getPosition();
|
|
81205
82618
|
const dist = camPos.distance(this.targetPos);
|
|
81206
|
-
if (dist < 2.0) {
|
|
82619
|
+
if (this.targetMode !== 'orbit' && dist < 2.0) {
|
|
81207
82620
|
this.targetPath.style.display = 'none';
|
|
81208
82621
|
return;
|
|
81209
82622
|
}
|
|
81210
|
-
this.
|
|
81211
|
-
this.targetPath.setAttribute('d', buildBezierRing(this.scratchX, this.scratchY));
|
|
81212
|
-
this.targetPath.style.display = '';
|
|
81213
|
-
this.svg.style.display = '';
|
|
82623
|
+
this.renderRing(this.targetPath, this.targetPos, this.targetNormal);
|
|
81214
82624
|
}
|
|
81215
82625
|
destroy() {
|
|
81216
82626
|
this.canvas.removeEventListener('pointermove', this.onPointerMove);
|
|
@@ -81321,9 +82731,11 @@ class Viewer {
|
|
|
81321
82731
|
cameraFrame;
|
|
81322
82732
|
inputController;
|
|
81323
82733
|
cameraManager;
|
|
82734
|
+
picker;
|
|
81324
82735
|
annotations;
|
|
81325
82736
|
forceRenderNextFrame = false;
|
|
81326
82737
|
voxelOverlay = null;
|
|
82738
|
+
meshOverlay = null;
|
|
81327
82739
|
walkCursor = null;
|
|
81328
82740
|
origChunks;
|
|
81329
82741
|
constructor(global, gsplatLoad, skyboxLoad, collisionLoad) {
|
|
@@ -81468,23 +82880,33 @@ class Viewer {
|
|
|
81468
82880
|
if (!config.noui) {
|
|
81469
82881
|
this.annotations = new Annotations(global, this.cameraFrame != null);
|
|
81470
82882
|
}
|
|
81471
|
-
this.
|
|
82883
|
+
this.picker = new Picker(app, camera);
|
|
82884
|
+
this.inputController = new InputController(global, this.picker);
|
|
81472
82885
|
this.inputController.collision = collision ?? null;
|
|
81473
82886
|
state.hasCollision = !!collision;
|
|
81474
|
-
// Create
|
|
82887
|
+
// Create collision debug overlay (voxel uses a compute shader, mesh
|
|
82888
|
+
// uses standard line rendering). The voxel path requires WebGPU.
|
|
81475
82889
|
if (collision instanceof VoxelCollision && config.renderer !== 'webgl') {
|
|
81476
82890
|
this.voxelOverlay = new VoxelDebugOverlay(app, collision, camera);
|
|
81477
82891
|
this.voxelOverlay.mode = config.heatmap ? 'heatmap' : 'overlay';
|
|
81478
|
-
state.
|
|
81479
|
-
events.on('
|
|
82892
|
+
state.hasCollisionOverlay = true;
|
|
82893
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
81480
82894
|
this.voxelOverlay.enabled = value;
|
|
81481
82895
|
app.renderNextFrame = true;
|
|
81482
82896
|
});
|
|
81483
82897
|
}
|
|
82898
|
+
else if (collision instanceof MeshCollision) {
|
|
82899
|
+
this.meshOverlay = new MeshDebugOverlay(app, collision, camera, !!this.cameraFrame);
|
|
82900
|
+
state.hasCollisionOverlay = true;
|
|
82901
|
+
events.on('collisionOverlayEnabled:changed', (value) => {
|
|
82902
|
+
this.meshOverlay.enabled = value;
|
|
82903
|
+
app.renderNextFrame = true;
|
|
82904
|
+
});
|
|
82905
|
+
}
|
|
81484
82906
|
this.cameraManager = new CameraManager(global, sceneBound, collision);
|
|
81485
82907
|
applyCamera(this.cameraManager.camera);
|
|
81486
|
-
if (
|
|
81487
|
-
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);
|
|
81488
82910
|
}
|
|
81489
82911
|
const { instance } = gsplat;
|
|
81490
82912
|
if (instance) {
|
|
@@ -81534,7 +82956,8 @@ class Viewer {
|
|
|
81534
82956
|
}
|
|
81535
82957
|
else {
|
|
81536
82958
|
// reveal once low lod has loaded for fastest possible reveal
|
|
81537
|
-
const
|
|
82959
|
+
const resource = results[0].gsplat.resource;
|
|
82960
|
+
const lodLevels = resource?.octree?.lodLevels;
|
|
81538
82961
|
if (lodLevels) {
|
|
81539
82962
|
gsplat.lodRangeMax = gsplat.lodRangeMin = lodLevels - 1;
|
|
81540
82963
|
}
|
|
@@ -81659,6 +83082,10 @@ class Viewer {
|
|
|
81659
83082
|
camera.camera.clearColor = new Color(background.color);
|
|
81660
83083
|
}
|
|
81661
83084
|
}
|
|
83085
|
+
// Mesh overlay bakes its vertex colors based on the current gamma
|
|
83086
|
+
// path; reapply when CameraFrame is created/destroyed (e.g. on XR
|
|
83087
|
+
// start/end) so the overlay tracks the new path.
|
|
83088
|
+
this.meshOverlay?.setCameraFrameEnabled(!!this.cameraFrame);
|
|
81662
83089
|
}
|
|
81663
83090
|
}
|
|
81664
83091
|
|
|
@@ -82568,7 +83995,7 @@ const initXr = (global) => {
|
|
|
82568
83995
|
});
|
|
82569
83996
|
};
|
|
82570
83997
|
|
|
82571
|
-
var version = "1.
|
|
83998
|
+
var version = "1.22.0";
|
|
82572
83999
|
|
|
82573
84000
|
const loadGsplat = async (app, config, progressCallback) => {
|
|
82574
84001
|
const { contents, contentUrl, aa } = config;
|
|
@@ -82736,8 +84163,8 @@ const main = async (canvas, settingsJson, config) => {
|
|
|
82736
84163
|
hasAR: false,
|
|
82737
84164
|
hasVR: false,
|
|
82738
84165
|
hasCollision: false,
|
|
82739
|
-
|
|
82740
|
-
|
|
84166
|
+
hasCollisionOverlay: false,
|
|
84167
|
+
collisionOverlayEnabled: false,
|
|
82741
84168
|
isFullscreen: false,
|
|
82742
84169
|
controlsHidden: false,
|
|
82743
84170
|
gamingControls: localStorage.getItem('gamingControls') === 'true'
|