@viggle/splat-engine-three 0.2.0 → 0.4.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.
@@ -5,14 +5,23 @@ import { Color, Matrix3, Matrix4 as Matrix43, Object3D, SRGBColorSpace, Vector3
5
5
  import { Euler, MathUtils, Vector3 as Vector35 } from "three";
6
6
 
7
7
  // src/math.ts
8
+ var DEG_TO_RAD = Math.PI / 180;
9
+ var RAD_TO_DEG = 180 / Math.PI;
8
10
  var Vec3 = class _Vec3 {
9
11
  x;
10
12
  y;
11
13
  z;
14
+ /** Three numbers, or one array-like of three. */
12
15
  constructor(x = 0, y = 0, z = 0) {
13
- this.x = x;
14
- this.y = y;
15
- this.z = z;
16
+ if (typeof x !== "number" && x.length === 3) {
17
+ this.x = x[0];
18
+ this.y = x[1];
19
+ this.z = x[2];
20
+ } else {
21
+ this.x = x;
22
+ this.y = y;
23
+ this.z = z;
24
+ }
16
25
  }
17
26
  set(x, y, z) {
18
27
  this.x = x;
@@ -73,13 +82,14 @@ var Vec3 = class _Vec3 {
73
82
  length() {
74
83
  return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
75
84
  }
76
- normalize() {
77
- const lengthSq = this.x * this.x + this.y * this.y + this.z * this.z;
85
+ /** Normalize `src` (default: this) into this. A zero vector is left as it was. */
86
+ normalize(src = this) {
87
+ const lengthSq = src.x * src.x + src.y * src.y + src.z * src.z;
78
88
  if (lengthSq > 0) {
79
89
  const invLength = 1 / Math.sqrt(lengthSq);
80
- this.x *= invLength;
81
- this.y *= invLength;
82
- this.z *= invLength;
90
+ this.x = src.x * invLength;
91
+ this.y = src.y * invLength;
92
+ this.z = src.z * invLength;
83
93
  }
84
94
  return this;
85
95
  }
@@ -89,17 +99,171 @@ var Vec3 = class _Vec3 {
89
99
  this.z = lhs.z + alpha * (rhs.z - lhs.z);
90
100
  return this;
91
101
  }
102
+ // The rest of PlayCanvas's Vec3, which the rig does not use.
103
+ addScalar(scalar) {
104
+ this.x += scalar;
105
+ this.y += scalar;
106
+ this.z += scalar;
107
+ return this;
108
+ }
109
+ /** `this += rhs * scalar`. */
110
+ addScaled(rhs, scalar) {
111
+ this.x += rhs.x * scalar;
112
+ this.y += rhs.y * scalar;
113
+ this.z += rhs.z * scalar;
114
+ return this;
115
+ }
116
+ subScalar(scalar) {
117
+ this.x -= scalar;
118
+ this.y -= scalar;
119
+ this.z -= scalar;
120
+ return this;
121
+ }
122
+ /** Component-wise. */
123
+ mul(rhs) {
124
+ this.x *= rhs.x;
125
+ this.y *= rhs.y;
126
+ this.z *= rhs.z;
127
+ return this;
128
+ }
129
+ /** Component-wise. */
130
+ mul2(lhs, rhs) {
131
+ this.x = lhs.x * rhs.x;
132
+ this.y = lhs.y * rhs.y;
133
+ this.z = lhs.z * rhs.z;
134
+ return this;
135
+ }
136
+ /** {@link mulScalar}. */
137
+ scale(scalar) {
138
+ return this.mulScalar(scalar);
139
+ }
140
+ /** Component-wise. */
141
+ div(rhs) {
142
+ this.x /= rhs.x;
143
+ this.y /= rhs.y;
144
+ this.z /= rhs.z;
145
+ return this;
146
+ }
147
+ /** Component-wise. */
148
+ div2(lhs, rhs) {
149
+ this.x = lhs.x / rhs.x;
150
+ this.y = lhs.y / rhs.y;
151
+ this.z = lhs.z / rhs.z;
152
+ return this;
153
+ }
154
+ divScalar(scalar) {
155
+ this.x /= scalar;
156
+ this.y /= scalar;
157
+ this.z /= scalar;
158
+ return this;
159
+ }
160
+ distance(rhs) {
161
+ const x = this.x - rhs.x;
162
+ const y = this.y - rhs.y;
163
+ const z = this.z - rhs.z;
164
+ return Math.sqrt(x * x + y * y + z * z);
165
+ }
166
+ distanceSq(rhs) {
167
+ const x = this.x - rhs.x;
168
+ const y = this.y - rhs.y;
169
+ const z = this.z - rhs.z;
170
+ return x * x + y * y + z * z;
171
+ }
172
+ lengthSq() {
173
+ return this.x * this.x + this.y * this.y + this.z * this.z;
174
+ }
175
+ equals(rhs) {
176
+ return this.x === rhs.x && this.y === rhs.y && this.z === rhs.z;
177
+ }
178
+ equalsApprox(rhs, epsilon = 1e-6) {
179
+ return Math.abs(this.x - rhs.x) < epsilon && Math.abs(this.y - rhs.y) < epsilon && Math.abs(this.z - rhs.z) < epsilon;
180
+ }
181
+ floor(src = this) {
182
+ this.x = Math.floor(src.x);
183
+ this.y = Math.floor(src.y);
184
+ this.z = Math.floor(src.z);
185
+ return this;
186
+ }
187
+ ceil(src = this) {
188
+ this.x = Math.ceil(src.x);
189
+ this.y = Math.ceil(src.y);
190
+ this.z = Math.ceil(src.z);
191
+ return this;
192
+ }
193
+ round(src = this) {
194
+ this.x = Math.round(src.x);
195
+ this.y = Math.round(src.y);
196
+ this.z = Math.round(src.z);
197
+ return this;
198
+ }
199
+ /** Component-wise minimum with `rhs`. */
200
+ min(rhs) {
201
+ if (rhs.x < this.x) this.x = rhs.x;
202
+ if (rhs.y < this.y) this.y = rhs.y;
203
+ if (rhs.z < this.z) this.z = rhs.z;
204
+ return this;
205
+ }
206
+ /** Component-wise maximum with `rhs`. */
207
+ max(rhs) {
208
+ if (rhs.x > this.x) this.x = rhs.x;
209
+ if (rhs.y > this.y) this.y = rhs.y;
210
+ if (rhs.z > this.z) this.z = rhs.z;
211
+ return this;
212
+ }
213
+ /** Project this onto `rhs`. */
214
+ project(rhs) {
215
+ const aDotB = this.x * rhs.x + this.y * rhs.y + this.z * rhs.z;
216
+ const bDotB = rhs.x * rhs.x + rhs.y * rhs.y + rhs.z * rhs.z;
217
+ const s = aDotB / bDotB;
218
+ this.x = rhs.x * s;
219
+ this.y = rhs.y * s;
220
+ this.z = rhs.z * s;
221
+ return this;
222
+ }
223
+ /** Read three numbers from `arr` at `offset`; missing ones keep their value. */
224
+ fromArray(arr, offset = 0) {
225
+ this.x = arr[offset] ?? this.x;
226
+ this.y = arr[offset + 1] ?? this.y;
227
+ this.z = arr[offset + 2] ?? this.z;
228
+ return this;
229
+ }
230
+ toArray(arr = [], offset = 0) {
231
+ arr[offset] = this.x;
232
+ arr[offset + 1] = this.y;
233
+ arr[offset + 2] = this.z;
234
+ return arr;
235
+ }
236
+ toString() {
237
+ return `[${this.x}, ${this.y}, ${this.z}]`;
238
+ }
239
+ static ZERO = Object.freeze(new _Vec3(0, 0, 0));
240
+ static HALF = Object.freeze(new _Vec3(0.5, 0.5, 0.5));
241
+ static ONE = Object.freeze(new _Vec3(1, 1, 1));
242
+ static UP = Object.freeze(new _Vec3(0, 1, 0));
243
+ static DOWN = Object.freeze(new _Vec3(0, -1, 0));
244
+ static RIGHT = Object.freeze(new _Vec3(1, 0, 0));
245
+ static LEFT = Object.freeze(new _Vec3(-1, 0, 0));
246
+ static FORWARD = Object.freeze(new _Vec3(0, 0, -1));
247
+ static BACK = Object.freeze(new _Vec3(0, 0, 1));
92
248
  };
93
249
  var Quat = class _Quat {
94
250
  x;
95
251
  y;
96
252
  z;
97
253
  w;
254
+ /** Four numbers, or one array-like of four. */
98
255
  constructor(x = 0, y = 0, z = 0, w = 1) {
99
- this.x = x;
100
- this.y = y;
101
- this.z = z;
102
- this.w = w;
256
+ if (typeof x !== "number" && x.length === 4) {
257
+ this.x = x[0];
258
+ this.y = x[1];
259
+ this.z = x[2];
260
+ this.w = x[3];
261
+ } else {
262
+ this.x = x;
263
+ this.y = y;
264
+ this.z = z;
265
+ this.w = w;
266
+ }
103
267
  }
104
268
  set(x, y, z, w) {
105
269
  this.x = x;
@@ -118,10 +282,12 @@ var Quat = class _Quat {
118
282
  clone() {
119
283
  return new _Quat(this.x, this.y, this.z, this.w);
120
284
  }
121
- conjugate() {
122
- this.x *= -1;
123
- this.y *= -1;
124
- this.z *= -1;
285
+ /** Conjugate `src` (default: this) into this. */
286
+ conjugate(src = this) {
287
+ this.x = src.x * -1;
288
+ this.y = src.y * -1;
289
+ this.z = src.z * -1;
290
+ this.w = src.w;
125
291
  return this;
126
292
  }
127
293
  dot(other) {
@@ -130,24 +296,26 @@ var Quat = class _Quat {
130
296
  length() {
131
297
  return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
132
298
  }
133
- mulScalar(scalar) {
134
- this.x *= scalar;
135
- this.y *= scalar;
136
- this.z *= scalar;
137
- this.w *= scalar;
299
+ /** `this = src * scalar`, `src` defaulting to this. */
300
+ mulScalar(scalar, src = this) {
301
+ this.x = src.x * scalar;
302
+ this.y = src.y * scalar;
303
+ this.z = src.z * scalar;
304
+ this.w = src.w * scalar;
138
305
  return this;
139
306
  }
140
- normalize() {
141
- let len = this.length();
307
+ /** Normalize `src` (default: this) into this; a zero quaternion becomes the identity. */
308
+ normalize(src = this) {
309
+ let len = src.length();
142
310
  if (len === 0) {
143
311
  this.x = this.y = this.z = 0;
144
312
  this.w = 1;
145
313
  } else {
146
314
  len = 1 / len;
147
- this.x *= len;
148
- this.y *= len;
149
- this.z *= len;
150
- this.w *= len;
315
+ this.x = src.x * len;
316
+ this.y = src.y * len;
317
+ this.z = src.z * len;
318
+ this.w = src.w * len;
151
319
  }
152
320
  return this;
153
321
  }
@@ -258,7 +426,156 @@ var Quat = class _Quat {
258
426
  }
259
427
  return this.mulScalar(1 / this.length());
260
428
  }
429
+ // The rest of PlayCanvas's Quat, which the rig does not use.
430
+ lengthSq() {
431
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
432
+ }
433
+ /** The inverse of `src` (default: this), into this. */
434
+ invert(src = this) {
435
+ return this.conjugate(src).normalize();
436
+ }
437
+ /** Normalized linear blend from `lhs` to `rhs`, taking the short way round. */
438
+ lerp(lhs, rhs, alpha) {
439
+ const omt = (1 - alpha) * (lhs.dot(rhs) < 0 ? -1 : 1);
440
+ this.x = lhs.x * omt + rhs.x * alpha;
441
+ this.y = lhs.y * omt + rhs.y * alpha;
442
+ this.z = lhs.z * omt + rhs.z * alpha;
443
+ this.w = lhs.w * omt + rhs.w * alpha;
444
+ return this.normalize();
445
+ }
446
+ equals(rhs) {
447
+ return this.x === rhs.x && this.y === rhs.y && this.z === rhs.z && this.w === rhs.w;
448
+ }
449
+ equalsApprox(rhs, epsilon = 1e-6) {
450
+ return Math.abs(this.x - rhs.x) < epsilon && Math.abs(this.y - rhs.y) < epsilon && Math.abs(this.z - rhs.z) < epsilon && Math.abs(this.w - rhs.w) < epsilon;
451
+ }
452
+ /** A rotation of `angle` degrees about the unit vector `axis`. */
453
+ setFromAxisAngle(axis, angle) {
454
+ angle *= 0.5 * DEG_TO_RAD;
455
+ const sa = Math.sin(angle);
456
+ const ca = Math.cos(angle);
457
+ this.x = sa * axis.x;
458
+ this.y = sa * axis.y;
459
+ this.z = sa * axis.z;
460
+ this.w = ca;
461
+ return this;
462
+ }
463
+ /**
464
+ * Write this rotation's axis into `axis` and return its angle in degrees.
465
+ * The axis is flipped to have no negative component where it can be, the
466
+ * angle with it.
467
+ */
468
+ getAxisAngle(axis) {
469
+ let rad = Math.acos(this.w) * 2;
470
+ const s = Math.sin(rad / 2);
471
+ if (s !== 0) {
472
+ axis.x = this.x / s;
473
+ axis.y = this.y / s;
474
+ axis.z = this.z / s;
475
+ if (axis.x < 0 || axis.y < 0 || axis.z < 0) {
476
+ axis.x *= -1;
477
+ axis.y *= -1;
478
+ axis.z *= -1;
479
+ rad *= -1;
480
+ }
481
+ } else {
482
+ axis.x = 1;
483
+ axis.y = 0;
484
+ axis.z = 0;
485
+ }
486
+ return rad * RAD_TO_DEG;
487
+ }
488
+ /** From Euler angles in degrees, applied X, then Y, then Z (as PlayCanvas). */
489
+ setFromEulerAngles(ex, ey = 0, ez = 0) {
490
+ if (ex instanceof Vec3) {
491
+ ey = ex.y;
492
+ ez = ex.z;
493
+ ex = ex.x;
494
+ }
495
+ const halfToRad = 0.5 * DEG_TO_RAD;
496
+ ex *= halfToRad;
497
+ ey *= halfToRad;
498
+ ez *= halfToRad;
499
+ const sx = Math.sin(ex);
500
+ const cx = Math.cos(ex);
501
+ const sy = Math.sin(ey);
502
+ const cy = Math.cos(ey);
503
+ const sz = Math.sin(ez);
504
+ const cz = Math.cos(ez);
505
+ this.x = sx * cy * cz - cx * sy * sz;
506
+ this.y = cx * sy * cz + sx * cy * sz;
507
+ this.z = cx * cy * sz - sx * sy * cz;
508
+ this.w = cx * cy * cz + sx * sy * sz;
509
+ return this;
510
+ }
511
+ /** This rotation as Euler angles in degrees (see {@link setFromEulerAngles}). */
512
+ getEulerAngles(eulers = new Vec3()) {
513
+ let x, y, z;
514
+ const qx = this.x, qy = this.y, qz = this.z, qw = this.w;
515
+ const a2 = 2 * (qw * qy - qx * qz);
516
+ if (a2 <= -0.99999) {
517
+ x = 2 * Math.atan2(qx, qw);
518
+ y = -Math.PI / 2;
519
+ z = 0;
520
+ } else if (a2 >= 0.99999) {
521
+ x = 2 * Math.atan2(qx, qw);
522
+ y = Math.PI / 2;
523
+ z = 0;
524
+ } else {
525
+ x = Math.atan2(2 * (qw * qx + qy * qz), 1 - 2 * (qx * qx + qy * qy));
526
+ y = Math.asin(a2);
527
+ z = Math.atan2(2 * (qw * qz + qx * qy), 1 - 2 * (qy * qy + qz * qz));
528
+ }
529
+ return eulers.set(x, y, z).mulScalar(RAD_TO_DEG);
530
+ }
531
+ /** The shortest rotation taking unit vector `from` to unit vector `to`. */
532
+ setFromDirections(from, to) {
533
+ const dotProduct = 1 + from.dot(to);
534
+ if (dotProduct < Number.EPSILON) {
535
+ if (Math.abs(from.x) > Math.abs(from.y)) {
536
+ this.x = -from.z;
537
+ this.y = 0;
538
+ this.z = from.x;
539
+ this.w = 0;
540
+ } else {
541
+ this.x = 0;
542
+ this.y = -from.z;
543
+ this.z = from.y;
544
+ this.w = 0;
545
+ }
546
+ } else {
547
+ this.x = from.y * to.z - from.z * to.y;
548
+ this.y = from.z * to.x - from.x * to.z;
549
+ this.z = from.x * to.y - from.y * to.x;
550
+ this.w = dotProduct;
551
+ }
552
+ return this.normalize();
553
+ }
554
+ /** Read four numbers from `arr` at `offset`; missing ones keep their value. */
555
+ fromArray(arr, offset = 0) {
556
+ this.x = arr[offset] ?? this.x;
557
+ this.y = arr[offset + 1] ?? this.y;
558
+ this.z = arr[offset + 2] ?? this.z;
559
+ this.w = arr[offset + 3] ?? this.w;
560
+ return this;
561
+ }
562
+ toArray(arr = [], offset = 0) {
563
+ arr[offset] = this.x;
564
+ arr[offset + 1] = this.y;
565
+ arr[offset + 2] = this.z;
566
+ arr[offset + 3] = this.w;
567
+ return arr;
568
+ }
569
+ toString() {
570
+ return `[${this.x}, ${this.y}, ${this.z}, ${this.w}]`;
571
+ }
572
+ static IDENTITY = Object.freeze(new _Quat(0, 0, 0, 1));
573
+ static ZERO = Object.freeze(new _Quat(0, 0, 0, 0));
261
574
  };
575
+ var _x = new Vec3();
576
+ var _y = new Vec3();
577
+ var _z = new Vec3();
578
+ var _scale = new Vec3();
262
579
  var Mat4 = class _Mat4 {
263
580
  data;
264
581
  constructor() {
@@ -366,8 +683,9 @@ var Mat4 = class _Mat4 {
366
683
  mul(rhs) {
367
684
  return this.mul2(this, rhs);
368
685
  }
369
- invert() {
370
- const s = this.data;
686
+ /** The inverse of `src` (default: this), into this. A singular matrix gives the identity. */
687
+ invert(src = this) {
688
+ const s = src.data;
371
689
  const a00 = s[0], a01 = s[1], a02 = s[2], a03 = s[3];
372
690
  const a10 = s[4], a11 = s[5], a12 = s[6], a13 = s[7];
373
691
  const a20 = s[8], a21 = s[9], a22 = s[10], a23 = s[11];
@@ -420,6 +738,406 @@ var Mat4 = class _Mat4 {
420
738
  Math.sqrt(d[8] * d[8] + d[9] * d[9] + d[10] * d[10])
421
739
  );
422
740
  }
741
+ // The rest of PlayCanvas's Mat4, which the rig does not use.
742
+ /** Copy 16 column-major numbers in; {@link setFromArray} under PlayCanvas's name. */
743
+ set(src) {
744
+ return this.setFromArray(src);
745
+ }
746
+ add2(lhs, rhs) {
747
+ const a = lhs.data, b = rhs.data, r = this.data;
748
+ for (let i = 0; i < 16; i++) r[i] = a[i] + b[i];
749
+ return this;
750
+ }
751
+ add(rhs) {
752
+ return this.add2(this, rhs);
753
+ }
754
+ equals(rhs) {
755
+ const l = this.data, r = rhs.data;
756
+ for (let i = 0; i < 16; i++) if (l[i] !== r[i]) return false;
757
+ return true;
758
+ }
759
+ isIdentity() {
760
+ const m = this.data;
761
+ return m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 0 && m[4] === 0 && m[5] === 1 && m[6] === 0 && m[7] === 0 && m[8] === 0 && m[9] === 0 && m[10] === 1 && m[11] === 0 && m[12] === 0 && m[13] === 0 && m[14] === 0 && m[15] === 1;
762
+ }
763
+ /** `this = lhs * rhs` for affine matrices (the bottom rows taken as 0 0 0 1). */
764
+ mulAffine2(lhs, rhs) {
765
+ const a = lhs.data, b = rhs.data, r = this.data;
766
+ const a00 = a[0], a01 = a[1], a02 = a[2];
767
+ const a10 = a[4], a11 = a[5], a12 = a[6];
768
+ const a20 = a[8], a21 = a[9], a22 = a[10];
769
+ const a30 = a[12], a31 = a[13], a32 = a[14];
770
+ let b0, b1, b2;
771
+ b0 = b[0];
772
+ b1 = b[1];
773
+ b2 = b[2];
774
+ r[0] = a00 * b0 + a10 * b1 + a20 * b2;
775
+ r[1] = a01 * b0 + a11 * b1 + a21 * b2;
776
+ r[2] = a02 * b0 + a12 * b1 + a22 * b2;
777
+ r[3] = 0;
778
+ b0 = b[4];
779
+ b1 = b[5];
780
+ b2 = b[6];
781
+ r[4] = a00 * b0 + a10 * b1 + a20 * b2;
782
+ r[5] = a01 * b0 + a11 * b1 + a21 * b2;
783
+ r[6] = a02 * b0 + a12 * b1 + a22 * b2;
784
+ r[7] = 0;
785
+ b0 = b[8];
786
+ b1 = b[9];
787
+ b2 = b[10];
788
+ r[8] = a00 * b0 + a10 * b1 + a20 * b2;
789
+ r[9] = a01 * b0 + a11 * b1 + a21 * b2;
790
+ r[10] = a02 * b0 + a12 * b1 + a22 * b2;
791
+ r[11] = 0;
792
+ b0 = b[12];
793
+ b1 = b[13];
794
+ b2 = b[14];
795
+ r[12] = a00 * b0 + a10 * b1 + a20 * b2 + a30;
796
+ r[13] = a01 * b0 + a11 * b1 + a21 * b2 + a31;
797
+ r[14] = a02 * b0 + a12 * b1 + a22 * b2 + a32;
798
+ r[15] = 1;
799
+ return this;
800
+ }
801
+ /** `vec` as a point (w = 1) through this matrix. */
802
+ transformPoint(vec, res = new Vec3()) {
803
+ const m = this.data;
804
+ const { x, y, z } = vec;
805
+ res.x = x * m[0] + y * m[4] + z * m[8] + m[12];
806
+ res.y = x * m[1] + y * m[5] + z * m[9] + m[13];
807
+ res.z = x * m[2] + y * m[6] + z * m[10] + m[14];
808
+ return res;
809
+ }
810
+ /** `vec` as a direction (w = 0) through this matrix. */
811
+ transformVector(vec, res = new Vec3()) {
812
+ const m = this.data;
813
+ const { x, y, z } = vec;
814
+ res.x = x * m[0] + y * m[4] + z * m[8];
815
+ res.y = x * m[1] + y * m[5] + z * m[9];
816
+ res.z = x * m[2] + y * m[6] + z * m[10];
817
+ return res;
818
+ }
819
+ transformVec4(vec, res = { x: 0, y: 0, z: 0, w: 0 }) {
820
+ const m = this.data;
821
+ const { x, y, z, w } = vec;
822
+ res.x = x * m[0] + y * m[4] + z * m[8] + w * m[12];
823
+ res.y = x * m[1] + y * m[5] + z * m[9] + w * m[13];
824
+ res.z = x * m[2] + y * m[6] + z * m[10] + w * m[14];
825
+ res.w = x * m[3] + y * m[7] + z * m[11] + w * m[15];
826
+ return res;
827
+ }
828
+ /** A transform at `position` whose -Z looks at `target`, with `up` as near up as it can be. */
829
+ setLookAt(position, target, up) {
830
+ _z.sub2(position, target).normalize();
831
+ _y.copy(up).normalize();
832
+ _x.cross(_y, _z).normalize();
833
+ _y.cross(_z, _x);
834
+ const r = this.data;
835
+ r[0] = _x.x;
836
+ r[1] = _x.y;
837
+ r[2] = _x.z;
838
+ r[3] = 0;
839
+ r[4] = _y.x;
840
+ r[5] = _y.y;
841
+ r[6] = _y.z;
842
+ r[7] = 0;
843
+ r[8] = _z.x;
844
+ r[9] = _z.y;
845
+ r[10] = _z.z;
846
+ r[11] = 0;
847
+ r[12] = position.x;
848
+ r[13] = position.y;
849
+ r[14] = position.z;
850
+ r[15] = 1;
851
+ return this;
852
+ }
853
+ setFrustum(left, right, bottom, top, znear, zfar) {
854
+ const temp1 = 2 * znear;
855
+ const temp2 = right - left;
856
+ const temp3 = top - bottom;
857
+ const temp4 = zfar - znear;
858
+ const r = this.data;
859
+ r[0] = temp1 / temp2;
860
+ r[1] = 0;
861
+ r[2] = 0;
862
+ r[3] = 0;
863
+ r[4] = 0;
864
+ r[5] = temp1 / temp3;
865
+ r[6] = 0;
866
+ r[7] = 0;
867
+ r[8] = (right + left) / temp2;
868
+ r[9] = (top + bottom) / temp3;
869
+ r[10] = (-zfar - znear) / temp4;
870
+ r[11] = -1;
871
+ r[12] = 0;
872
+ r[13] = 0;
873
+ r[14] = -temp1 * zfar / temp4;
874
+ r[15] = 0;
875
+ return this;
876
+ }
877
+ /** `fov` in degrees: vertical, or horizontal when `fovIsHorizontal`. */
878
+ setPerspective(fov, aspect, znear, zfar, fovIsHorizontal = false) {
879
+ let halfX, halfY;
880
+ if (fovIsHorizontal) {
881
+ halfX = znear * Math.tan(fov * Math.PI / 360);
882
+ halfY = halfX / aspect;
883
+ } else {
884
+ halfY = znear * Math.tan(fov * Math.PI / 360);
885
+ halfX = halfY * aspect;
886
+ }
887
+ return this.setFrustum(-halfX, halfX, -halfY, halfY, znear, zfar);
888
+ }
889
+ setOrtho(left, right, bottom, top, near, far) {
890
+ const r = this.data;
891
+ r[0] = 2 / (right - left);
892
+ r[1] = 0;
893
+ r[2] = 0;
894
+ r[3] = 0;
895
+ r[4] = 0;
896
+ r[5] = 2 / (top - bottom);
897
+ r[6] = 0;
898
+ r[7] = 0;
899
+ r[8] = 0;
900
+ r[9] = 0;
901
+ r[10] = -2 / (far - near);
902
+ r[11] = 0;
903
+ r[12] = -(right + left) / (right - left);
904
+ r[13] = -(top + bottom) / (top - bottom);
905
+ r[14] = -(far + near) / (far - near);
906
+ r[15] = 1;
907
+ return this;
908
+ }
909
+ /** A rotation of `angle` degrees about the unit vector `axis`. */
910
+ setFromAxisAngle(axis, angle) {
911
+ angle *= DEG_TO_RAD;
912
+ const { x, y, z } = axis;
913
+ const c = Math.cos(angle);
914
+ const s = Math.sin(angle);
915
+ const t = 1 - c;
916
+ const tx = t * x;
917
+ const ty = t * y;
918
+ const m = this.data;
919
+ m[0] = tx * x + c;
920
+ m[1] = tx * y + s * z;
921
+ m[2] = tx * z - s * y;
922
+ m[3] = 0;
923
+ m[4] = tx * y - s * z;
924
+ m[5] = ty * y + c;
925
+ m[6] = ty * z + s * x;
926
+ m[7] = 0;
927
+ m[8] = tx * z + s * y;
928
+ m[9] = ty * z - x * s;
929
+ m[10] = t * z * z + c;
930
+ m[11] = 0;
931
+ m[12] = 0;
932
+ m[13] = 0;
933
+ m[14] = 0;
934
+ m[15] = 1;
935
+ return this;
936
+ }
937
+ setTranslate(x, y, z) {
938
+ const m = this.data;
939
+ m[0] = 1;
940
+ m[1] = 0;
941
+ m[2] = 0;
942
+ m[3] = 0;
943
+ m[4] = 0;
944
+ m[5] = 1;
945
+ m[6] = 0;
946
+ m[7] = 0;
947
+ m[8] = 0;
948
+ m[9] = 0;
949
+ m[10] = 1;
950
+ m[11] = 0;
951
+ m[12] = x;
952
+ m[13] = y;
953
+ m[14] = z;
954
+ m[15] = 1;
955
+ return this;
956
+ }
957
+ setScale(x, y, z) {
958
+ const m = this.data;
959
+ m[0] = x;
960
+ m[1] = 0;
961
+ m[2] = 0;
962
+ m[3] = 0;
963
+ m[4] = 0;
964
+ m[5] = y;
965
+ m[6] = 0;
966
+ m[7] = 0;
967
+ m[8] = 0;
968
+ m[9] = 0;
969
+ m[10] = z;
970
+ m[11] = 0;
971
+ m[12] = 0;
972
+ m[13] = 0;
973
+ m[14] = 0;
974
+ m[15] = 1;
975
+ return this;
976
+ }
977
+ setViewport(x, y, width2, height) {
978
+ const m = this.data;
979
+ m[0] = width2 * 0.5;
980
+ m[1] = 0;
981
+ m[2] = 0;
982
+ m[3] = 0;
983
+ m[4] = 0;
984
+ m[5] = height * 0.5;
985
+ m[6] = 0;
986
+ m[7] = 0;
987
+ m[8] = 0;
988
+ m[9] = 0;
989
+ m[10] = 0.5;
990
+ m[11] = 0;
991
+ m[12] = x + width2 * 0.5;
992
+ m[13] = y + height * 0.5;
993
+ m[14] = 0.5;
994
+ m[15] = 1;
995
+ return this;
996
+ }
997
+ /** Reflection about the plane `normal · p = distance`. */
998
+ setReflection(normal, distance) {
999
+ const a = normal.x, b = normal.y, c = normal.z;
1000
+ const m = this.data;
1001
+ m[0] = 1 - 2 * a * a;
1002
+ m[1] = -2 * a * b;
1003
+ m[2] = -2 * a * c;
1004
+ m[3] = 0;
1005
+ m[4] = -2 * a * b;
1006
+ m[5] = 1 - 2 * b * b;
1007
+ m[6] = -2 * b * c;
1008
+ m[7] = 0;
1009
+ m[8] = -2 * a * c;
1010
+ m[9] = -2 * b * c;
1011
+ m[10] = 1 - 2 * c * c;
1012
+ m[11] = 0;
1013
+ m[12] = -2 * a * distance;
1014
+ m[13] = -2 * b * distance;
1015
+ m[14] = -2 * c * distance;
1016
+ m[15] = 1;
1017
+ return this;
1018
+ }
1019
+ /** The transpose of `src` (default: this), into this. */
1020
+ transpose(src = this) {
1021
+ const s = src.data;
1022
+ const t = this.data;
1023
+ if (s === t) {
1024
+ let tmp;
1025
+ tmp = s[1];
1026
+ t[1] = s[4];
1027
+ t[4] = tmp;
1028
+ tmp = s[2];
1029
+ t[2] = s[8];
1030
+ t[8] = tmp;
1031
+ tmp = s[3];
1032
+ t[3] = s[12];
1033
+ t[12] = tmp;
1034
+ tmp = s[6];
1035
+ t[6] = s[9];
1036
+ t[9] = tmp;
1037
+ tmp = s[7];
1038
+ t[7] = s[13];
1039
+ t[13] = tmp;
1040
+ tmp = s[11];
1041
+ t[11] = s[14];
1042
+ t[14] = tmp;
1043
+ } else {
1044
+ t[0] = s[0];
1045
+ t[1] = s[4];
1046
+ t[2] = s[8];
1047
+ t[3] = s[12];
1048
+ t[4] = s[1];
1049
+ t[5] = s[5];
1050
+ t[6] = s[9];
1051
+ t[7] = s[13];
1052
+ t[8] = s[2];
1053
+ t[9] = s[6];
1054
+ t[10] = s[10];
1055
+ t[11] = s[14];
1056
+ t[12] = s[3];
1057
+ t[13] = s[7];
1058
+ t[14] = s[11];
1059
+ t[15] = s[15];
1060
+ }
1061
+ return this;
1062
+ }
1063
+ /** The X axis (first column). */
1064
+ getX(x = new Vec3()) {
1065
+ return x.set(this.data[0], this.data[1], this.data[2]);
1066
+ }
1067
+ /** The Y axis (second column). */
1068
+ getY(y = new Vec3()) {
1069
+ return y.set(this.data[4], this.data[5], this.data[6]);
1070
+ }
1071
+ /** The Z axis (third column). */
1072
+ getZ(z = new Vec3()) {
1073
+ return z.set(this.data[8], this.data[9], this.data[10]);
1074
+ }
1075
+ /** `-1` when the axes are mirrored, else `1`. */
1076
+ get scaleSign() {
1077
+ this.getX(_x);
1078
+ this.getY(_y);
1079
+ this.getZ(_z);
1080
+ _x.cross(_x, _y);
1081
+ return _x.dot(_z) < 0 ? -1 : 1;
1082
+ }
1083
+ /** A rotation from Euler angles in degrees (see {@link Quat.setFromEulerAngles}). */
1084
+ setFromEulerAngles(ex, ey, ez) {
1085
+ ex *= DEG_TO_RAD;
1086
+ ey *= DEG_TO_RAD;
1087
+ ez *= DEG_TO_RAD;
1088
+ const s1 = Math.sin(-ex);
1089
+ const c1 = Math.cos(-ex);
1090
+ const s2 = Math.sin(-ey);
1091
+ const c2 = Math.cos(-ey);
1092
+ const s3 = Math.sin(-ez);
1093
+ const c3 = Math.cos(-ez);
1094
+ const m = this.data;
1095
+ m[0] = c2 * c3;
1096
+ m[1] = -c2 * s3;
1097
+ m[2] = s2;
1098
+ m[3] = 0;
1099
+ m[4] = c1 * s3 + c3 * s1 * s2;
1100
+ m[5] = c1 * c3 - s1 * s2 * s3;
1101
+ m[6] = -c2 * s1;
1102
+ m[7] = 0;
1103
+ m[8] = s1 * s3 - c1 * c3 * s2;
1104
+ m[9] = c3 * s1 + c1 * s2 * s3;
1105
+ m[10] = c1 * c2;
1106
+ m[11] = 0;
1107
+ m[12] = 0;
1108
+ m[13] = 0;
1109
+ m[14] = 0;
1110
+ m[15] = 1;
1111
+ return this;
1112
+ }
1113
+ /** The rotation as Euler angles in degrees, with any scale divided out. */
1114
+ getEulerAngles(eulers = new Vec3()) {
1115
+ this.getScale(_scale);
1116
+ const sx = _scale.x, sy = _scale.y, sz = _scale.z;
1117
+ if (sx === 0 || sy === 0 || sz === 0) return eulers.set(0, 0, 0);
1118
+ const m = this.data;
1119
+ const y = Math.asin(-m[2] / sx);
1120
+ const halfPi = Math.PI * 0.5;
1121
+ let x, z;
1122
+ if (y < halfPi) {
1123
+ if (y > -halfPi) {
1124
+ x = Math.atan2(m[6] / sy, m[10] / sz);
1125
+ z = Math.atan2(m[1] / sx, m[0] / sx);
1126
+ } else {
1127
+ z = 0;
1128
+ x = -Math.atan2(m[4] / sy, m[5] / sy);
1129
+ }
1130
+ } else {
1131
+ z = 0;
1132
+ x = Math.atan2(m[4] / sy, m[5] / sy);
1133
+ }
1134
+ return eulers.set(x, y, z).mulScalar(RAD_TO_DEG);
1135
+ }
1136
+ toString() {
1137
+ return `[${this.data.join(", ")}]`;
1138
+ }
1139
+ static IDENTITY = Object.freeze(new _Mat4());
1140
+ static ZERO = Object.freeze(new _Mat4().set([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
423
1141
  };
424
1142
 
425
1143
  // src/loader/skeleton/skeleton-data.ts
@@ -464,7 +1182,7 @@ function loadSkeletonLibrary() {
464
1182
  var _mat = new Mat4();
465
1183
  var _pos = new Vec3();
466
1184
  var _rot = new Quat();
467
- var _scale = new Vec3();
1185
+ var _scale2 = new Vec3();
468
1186
  var _delta = new Quat();
469
1187
  function sourceFrames(animationData) {
470
1188
  const numFrames = animationData.numFrames;
@@ -483,7 +1201,7 @@ function decomposeBone(data, numBones, bone, frames, extract2 = extractBonePose,
483
1201
  for (let k = 0; k < n; k++) {
484
1202
  const offset = (frames[k] * numBones + bone) * 16;
485
1203
  for (let i = 0; i < 16; i++) _mat.data[i] = data[offset + i];
486
- extract2(_mat, _pos, _rot, _scale);
1204
+ extract2(_mat, _pos, _rot, _scale2);
487
1205
  if (reference) {
488
1206
  _pos.sub(reference.position).add(reference.targetPosition);
489
1207
  _delta.mul2(reference.inverseRotation, _rot);
@@ -497,9 +1215,9 @@ function decomposeBone(data, numBones, bone, frames, extract2 = extractBonePose,
497
1215
  rotations[k * 4 + 1] = _rot.y;
498
1216
  rotations[k * 4 + 2] = _rot.z;
499
1217
  rotations[k * 4 + 3] = _rot.w;
500
- scales[k * 3] = _scale.x;
501
- scales[k * 3 + 1] = _scale.y;
502
- scales[k * 3 + 2] = _scale.z;
1218
+ scales[k * 3] = _scale2.x;
1219
+ scales[k * 3 + 1] = _scale2.y;
1220
+ scales[k * 3 + 2] = _scale2.z;
503
1221
  }
504
1222
  return { frames, positions, rotations, scales };
505
1223
  }
@@ -614,7 +1332,7 @@ function boneReference(data, bone, referenceRest) {
614
1332
  targetRotation: new Quat()
615
1333
  };
616
1334
  for (let i = 0; i < 16; i++) _mat.data[i] = data[bone * 16 + i];
617
- extractRigidBonePose(_mat, reference.position, reference.inverseRotation, _scale);
1335
+ extractRigidBonePose(_mat, reference.position, reference.inverseRotation, _scale2);
618
1336
  reference.inverseRotation.conjugate();
619
1337
  setReferenceTargetPose(referenceRest, bone, reference.targetPosition, reference.targetRotation);
620
1338
  return reference;
@@ -1555,6 +2273,7 @@ async function isCached(url) {
1555
2273
  const cached = await cache.match(cacheKeyFor(url));
1556
2274
  return cached !== void 0 && !isExpired(cached);
1557
2275
  }
2276
+ var evictExpired = indexAssetCache;
1558
2277
 
1559
2278
  // src/animation.ts
1560
2279
  function hasConversionOptions(options) {
@@ -5148,6 +5867,7 @@ var _screenSizeCull = 0;
5148
5867
  var _minOpacity = 0.05;
5149
5868
  var _pruneRatio = 0;
5150
5869
  var _pruneVoxelSize = 0.04;
5870
+ var _depthWriteAlpha = 0;
5151
5871
  var clamp = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
5152
5872
  var warnedAboutCap = false;
5153
5873
  var SplatQuality = {
@@ -5299,6 +6019,54 @@ var SplatQuality = {
5299
6019
  * application wants - a character deliberately drawn over the scene.
5300
6020
  */
5301
6021
  depthOcclusion: true,
6022
+ /**
6023
+ * Alpha at which a splat writes depth, so that a splat object drawn later
6024
+ * is hidden behind the solid parts of one drawn earlier. `0` (the default)
6025
+ * writes no depth: the behaviour before this setting existed.
6026
+ *
6027
+ * Every splat object is sorted and drawn on its own, so where two of them
6028
+ * overlap - a weapon in a hand, two fighters in a clinch, a character
6029
+ * behind a prop - whichever draws second paints over the other across the
6030
+ * whole overlap, whatever is really in front. The PlayCanvas build sorts
6031
+ * every splat on a layer together and does not have the problem. With this
6032
+ * on, each splat object follows its colour draw with a depth-only draw of
6033
+ * its solid parts: the fragments of single splats whose alpha (the
6034
+ * gaussian's falloff times the splat's opacity) reaches this value. An
6035
+ * object drawn after it depth-tests against that, so its parts behind the
6036
+ * first object's solid parts are hidden; its parts in front paint over it,
6037
+ * as they should. An object never tests against its own depth, so one that
6038
+ * overlaps nothing draws exactly as it did.
6039
+ *
6040
+ * `0.1`-`0.2` came closest to the PlayCanvas build in the A/B suite's
6041
+ * overlap cases (a staff through a hand). Lower, the faint edges of the
6042
+ * first object hide the second; higher, too little of a character is solid
6043
+ * enough to hide anything.
6044
+ *
6045
+ * What it costs:
6046
+ * - A second, depth-only draw of every splat object. Its quads are cut to
6047
+ * where a splat is above this alpha, so the fragments are few; the vertex
6048
+ * work, which under WebGL includes the skinning, is paid twice.
6049
+ * - Where the first object is faint but above this alpha, it hides the
6050
+ * second outright instead of letting it show through: a harder edge
6051
+ * where the two overlap.
6052
+ * - Where the first object is fainter than this alpha, the second still
6053
+ * paints over it, as before.
6054
+ * - The alpha is taken after {@link Splat.setOpacity}, so an object fading
6055
+ * out keeps hiding what is behind it at its cores until its opacity
6056
+ * falls below this value. Opt a fading object out with its own
6057
+ * {@link Splat.depthWriteAlpha} for the fade.
6058
+ * - Splats now hide whatever draws after them in depth: transparent meshes
6059
+ * and particles behind a character, and post-processing that reads the
6060
+ * depth buffer sees them.
6061
+ *
6062
+ * Read per frame. A splat's own {@link Splat.depthWriteAlpha} overrides it.
6063
+ */
6064
+ get depthWriteAlpha() {
6065
+ return _depthWriteAlpha;
6066
+ },
6067
+ set depthWriteAlpha(value) {
6068
+ _depthWriteAlpha = clamp(value, 0, 1);
6069
+ },
5302
6070
  /**
5303
6071
  * Collect {@link SplatQuality.timings}. Off by default.
5304
6072
  *
@@ -5346,10 +6114,14 @@ var SplatQuality = {
5346
6114
  SplatQuality.pruneRatio = 0;
5347
6115
  SplatQuality.pruneVoxelSize = 0.04;
5348
6116
  SplatQuality.depthOcclusion = true;
6117
+ SplatQuality.depthWriteAlpha = 0;
5349
6118
  SplatQuality.passTimings = false;
5350
6119
  resetTimings();
5351
6120
  }
5352
6121
  };
6122
+ function effectiveDepthWriteAlpha(splatAlpha) {
6123
+ return splatAlpha ?? SplatQuality.depthWriteAlpha;
6124
+ }
5353
6125
  function effectiveMinPixelSize(splatMinPixelSize) {
5354
6126
  const global = SplatQuality.screenSizeCull;
5355
6127
  return global > splatMinPixelSize ? global : splatMinPixelSize;
@@ -5629,6 +6401,7 @@ import {
5629
6401
  InstancedBufferAttribute,
5630
6402
  InstancedBufferGeometry,
5631
6403
  LinearTransfer,
6404
+ NoBlending,
5632
6405
  OneFactor,
5633
6406
  OneMinusSrcAlphaFactor,
5634
6407
  Quaternion as Quaternion2,
@@ -6270,6 +7043,10 @@ uniform float uMinPixelSize;
6270
7043
  // expressions below reduce, bit for bit, to what they were before the cutoff
6271
7044
  // was a setting at all. See SplatQuality.quadAlphaCutoff.
6272
7045
  uniform float uAlphaCutoffScale;
7046
+ #ifdef DEPTH_ONLY
7047
+ // 1 / SplatQuality.depthWriteAlpha: the depth write sizes its quads to that alpha.
7048
+ uniform float uDepthCutoffScale;
7049
+ #endif
6273
7050
  // World rotation (xyzw) and scale of the splat object.
6274
7051
  uniform vec4 uModelRotation;
6275
7052
  uniform vec3 uModelScale;
@@ -6497,7 +7274,11 @@ void main(void) {
6497
7274
 
6498
7275
  // A splat whose peak alpha is already under the cutoff cannot put a
6499
7276
  // fragment on screen: its own quad would be empty.
7277
+ #ifdef DEPTH_ONLY
7278
+ float alphaOverCutoff = clr.a * uDepthCutoffScale;
7279
+ #else
6500
7280
  float alphaOverCutoff = clr.a * uAlphaCutoffScale;
7281
+ #endif
6501
7282
  if (alphaOverCutoff <= 1.0) {
6502
7283
  gl_Position = discardVec;
6503
7284
  return;
@@ -6529,6 +7310,11 @@ in mediump vec4 gaussianColor;
6529
7310
 
6530
7311
  layout(location = 0) out highp vec4 fragColor;
6531
7312
 
7313
+ #ifdef DEPTH_ONLY
7314
+ // SplatQuality.depthWriteAlpha: the alpha at which a fragment writes depth.
7315
+ uniform float uDepthAlpha;
7316
+ #endif
7317
+
6532
7318
  const float EXP4 = exp(-4.0);
6533
7319
  const float INV_EXP4 = 1.0 / (1.0 - EXP4);
6534
7320
 
@@ -6543,11 +7329,18 @@ void main(void) {
6543
7329
  discard;
6544
7330
  }
6545
7331
  mediump float alpha = normExp(A) * gaussianColor.a;
7332
+ #ifdef DEPTH_ONLY
7333
+ if (alpha < uDepthAlpha) {
7334
+ discard;
7335
+ }
7336
+ fragColor = vec4(0.0);
7337
+ #else
6546
7338
  if (alpha < 1.0 / 255.0) {
6547
7339
  discard;
6548
7340
  }
6549
7341
  // Premultiplied.
6550
7342
  fragColor = vec4(gaussianColor.rgb * alpha, alpha);
7343
+ #endif
6551
7344
  }
6552
7345
  `
6553
7346
  );
@@ -6555,7 +7348,7 @@ void main(void) {
6555
7348
  // src/splat/webgl/splat-mesh.ts
6556
7349
  var _position = new Vector33();
6557
7350
  var _quaternion = new Quaternion2();
6558
- var _scale2 = new Vector33();
7351
+ var _scale3 = new Vector33();
6559
7352
  var _viewport = new Vector4();
6560
7353
  var RELIGHT_UNIFORMS = [
6561
7354
  "uRelightTex",
@@ -6572,6 +7365,7 @@ var RELIGHT_UNIFORMS = [
6572
7365
  var WebGLSplatImpl = class {
6573
7366
  geometry;
6574
7367
  material;
7368
+ depthMaterial;
6575
7369
  /** The depth sort runs on the CPU, so it needs CPU-side centres. */
6576
7370
  needsCpuCenters = true;
6577
7371
  _host;
@@ -6656,8 +7450,25 @@ var WebGLSplatImpl = class {
6656
7450
  blendSrcAlpha: OneFactor,
6657
7451
  blendDstAlpha: OneMinusSrcAlphaFactor
6658
7452
  });
7453
+ material.uniforms.uDepthCutoffScale = { value: 0 };
7454
+ material.uniforms.uDepthAlpha = { value: 2 };
7455
+ const depth = new RawShaderMaterial({
7456
+ name: "SplatDepthWrite",
7457
+ glslVersion: GLSL3,
7458
+ vertexShader: material.vertexShader,
7459
+ fragmentShader: SPLAT_FRAGMENT_GLSL,
7460
+ uniforms: material.uniforms,
7461
+ side: DoubleSide,
7462
+ // Drawn in the transparent list, straight after the colour draw.
7463
+ transparent: true,
7464
+ depthTest: true,
7465
+ depthWrite: true,
7466
+ colorWrite: false,
7467
+ blending: NoBlending
7468
+ });
6659
7469
  this.geometry = geometry;
6660
7470
  this.material = material;
7471
+ this.depthMaterial = depth;
6661
7472
  this._host = host;
6662
7473
  this._splat = splat;
6663
7474
  this._engine = engine;
@@ -6714,6 +7525,10 @@ var WebGLSplatImpl = class {
6714
7525
  this.syncRelight();
6715
7526
  this.material.defines = defines;
6716
7527
  this.material.needsUpdate = true;
7528
+ const depth = this.depthMaterial;
7529
+ depth.vertexShader = this.material.vertexShader;
7530
+ depth.defines = { ...defines, DEPTH_ONLY: "" };
7531
+ depth.needsUpdate = true;
6717
7532
  }
6718
7533
  /** Point the relight uniforms at the splat's current binding. */
6719
7534
  syncRelight() {
@@ -6772,9 +7587,9 @@ var WebGLSplatImpl = class {
6772
7587
  const target = gl.getRenderTarget();
6773
7588
  const outputColorSpace = target ? target.texture.colorSpace : gl.outputColorSpace;
6774
7589
  u.uOutputLinear.value = ColorManagement.getTransfer(outputColorSpace) === LinearTransfer ? 1 : 0;
6775
- this._host.matrixWorld.decompose(_position, _quaternion, _scale2);
7590
+ this._host.matrixWorld.decompose(_position, _quaternion, _scale3);
6776
7591
  u.uModelRotation.value.set(_quaternion.x, _quaternion.y, _quaternion.z, _quaternion.w);
6777
- u.uModelScale.value.copy(_scale2);
7592
+ u.uModelScale.value.copy(_scale3);
6778
7593
  u.uMinPixelSize.value = effectiveMinPixelSize(splat.minPixelSize);
6779
7594
  u.uAlphaCutoffScale.value = 1 / Math.max(1 / 65535, SplatQuality.quadAlphaCutoff);
6780
7595
  u.transformPalette.value = splat.transformPalette.texture;
@@ -6786,7 +7601,11 @@ var WebGLSplatImpl = class {
6786
7601
  u.splatGroupRots.value = splat.groupRotsTexture ?? null;
6787
7602
  if (this.material.depthTest !== SplatQuality.depthOcclusion) {
6788
7603
  this.material.depthTest = SplatQuality.depthOcclusion;
7604
+ this.depthMaterial.depthTest = SplatQuality.depthOcclusion;
6789
7605
  }
7606
+ const depthAlpha = effectiveDepthWriteAlpha(splat.depthWriteAlpha);
7607
+ u.uDepthCutoffScale.value = depthAlpha > 0 ? 1 / depthAlpha : 0;
7608
+ u.uDepthAlpha.value = depthAlpha > 0 ? depthAlpha : 2;
6790
7609
  this._engine.syncLighting();
6791
7610
  if (!SplatQuality.passTimings) {
6792
7611
  this._sortFor(camera);
@@ -6855,6 +7674,7 @@ var WebGLSplatImpl = class {
6855
7674
  this._asyncSorter?.dispose();
6856
7675
  this.geometry.dispose();
6857
7676
  this.material.dispose();
7677
+ this.depthMaterial.dispose();
6858
7678
  }
6859
7679
  };
6860
7680
 
@@ -6905,6 +7725,8 @@ var SplatMesh = class extends Mesh {
6905
7725
  _engine;
6906
7726
  _asyncSort;
6907
7727
  _impl = null;
7728
+ /** Set by the first of this frame's two draws, which prepared it, for the second. */
7729
+ _prepared = false;
6908
7730
  /**
6909
7731
  * @param asyncSort - See {@link SplatBackend.createImpl}.
6910
7732
  * @internal Construct a {@link Splat} instead; it creates its own mesh.
@@ -6921,6 +7743,9 @@ var SplatMesh = class extends Mesh {
6921
7743
  _attach(backend) {
6922
7744
  const impl = backend.createImpl(this, this.splat, this._engine, this._asyncSort);
6923
7745
  this._impl = impl;
7746
+ const quad = impl.geometry.index.count;
7747
+ impl.geometry.addGroup(0, quad, 0);
7748
+ impl.geometry.addGroup(0, quad, 1);
6924
7749
  this.geometry = impl.geometry;
6925
7750
  this.material = impl.material;
6926
7751
  this.frustumCulled = true;
@@ -6951,13 +7776,35 @@ var SplatMesh = class extends Mesh {
6951
7776
  syncRelight() {
6952
7777
  this._impl?.syncRelight();
6953
7778
  }
6954
- onBeforeRender(renderer, _scene, camera) {
6955
- if (!this._impl) {
7779
+ onBeforeRender(renderer, _scene, camera, _geometry, material) {
7780
+ const impl = this._impl;
7781
+ if (!impl) {
6956
7782
  const backend = backendFor(renderer);
6957
7783
  if (backend) this._attach(backend);
6958
7784
  return;
6959
7785
  }
6960
- this._impl.beforeRender(renderer, camera);
7786
+ if (this._prepared) {
7787
+ this._prepared = false;
7788
+ } else {
7789
+ impl.beforeRender(renderer, camera);
7790
+ this._prepared = Array.isArray(this.material);
7791
+ }
7792
+ if (material !== impl.depthMaterial) this._syncDepthWrite(impl);
7793
+ }
7794
+ /**
7795
+ * Draw the depth group from the next frame on when this splat writes
7796
+ * depth, and only the colour group when it does not. The render list for
7797
+ * this frame is already made.
7798
+ *
7799
+ * Both groups are transparent, so they draw in the transparent list one
7800
+ * after the other: three.js sorts by render order, then depth, then object,
7801
+ * and keeps a group's order within that. The depth this object writes is
7802
+ * there for the splat objects drawn after it, never for its own colour.
7803
+ */
7804
+ _syncDepthWrite(impl) {
7805
+ const on = effectiveDepthWriteAlpha(this.splat.depthWriteAlpha) > 0;
7806
+ if (on === Array.isArray(this.material)) return;
7807
+ this.material = on ? [impl.material, impl.depthMaterial] : impl.material;
6961
7808
  }
6962
7809
  /**
6963
7810
  * A second mesh drawing the same splat data, at the same transform. The
@@ -7084,6 +7931,12 @@ var Splat = class _Splat {
7084
7931
  localBounds = new Box3();
7085
7932
  /** Discard splats smaller than this many pixels on screen. `0` draws everything. */
7086
7933
  minPixelSize = 0;
7934
+ /**
7935
+ * This splat's own {@link SplatQuality.depthWriteAlpha}: the alpha above which
7936
+ * it writes depth. `null` (the default) follows the global setting; `0`
7937
+ * never writes depth, whatever the global one says.
7938
+ */
7939
+ depthWriteAlpha = null;
7087
7940
  _activeSplatCount;
7088
7941
  _importanceOrder = null;
7089
7942
  /** `_importanceOrder` inverted: each splat's place in it. @internal */
@@ -7163,6 +8016,7 @@ var Splat = class _Splat {
7163
8016
  copy.grade.copy(this.grade);
7164
8017
  copy.effects.x = this.effects.x;
7165
8018
  copy.minPixelSize = this.minPixelSize;
8019
+ copy.depthWriteAlpha = this.depthWriteAlpha;
7166
8020
  copy.antiAlias = this.antiAlias;
7167
8021
  return copy;
7168
8022
  }
@@ -10698,7 +11552,9 @@ var Character = class _Character {
10698
11552
  * animates in lockstep) but on `layerIds`. With the body occluded by real
10699
11553
  * objects, this copy is what shows through obstacles: give it a see-through
10700
11554
  * look with its own {@link Splat.setOpacity} or {@link Splat.setColorModifier}
10701
- * (the PlayCanvas build's `applyOverlaySplatStyle` is not ported).
11555
+ * (the PlayCanvas build's `applyOverlaySplatStyle` is not ported). It
11556
+ * writes no depth under {@link SplatQuality.depthWriteAlpha}, so it never
11557
+ * hides what it is meant to show through.
10702
11558
  * Synchronous: reuses the decoded data.
10703
11559
  */
10704
11560
  addOverlaySplat(layerIds) {
@@ -10709,6 +11565,7 @@ var Character = class _Character {
10709
11565
  sourceBoneCount: source.sourceBoneCount
10710
11566
  });
10711
11567
  this.armature.linkSplat(splat);
11568
+ splat.depthWriteAlpha = 0;
10712
11569
  splat.setLayers(layerIds);
10713
11570
  splat.setRenderingEnabled(this._active);
10714
11571
  this._applyLook(splat);
@@ -12012,7 +12869,7 @@ import {
12012
12869
  BufferGeometry as BufferGeometry2,
12013
12870
  CustomBlending as CustomBlending2,
12014
12871
  Mesh as Mesh2,
12015
- NoBlending,
12872
+ NoBlending as NoBlending2,
12016
12873
  NormalBlending,
12017
12874
  OneFactor as OneFactor2,
12018
12875
  OrthographicCamera,
@@ -12097,7 +12954,7 @@ var WebGLPostFXProgram = class {
12097
12954
  depthTest: false,
12098
12955
  depthWrite: false,
12099
12956
  transparent: blend !== "none",
12100
- blending: blend === "add" ? CustomBlending2 : blend === "alpha" ? NormalBlending : NoBlending,
12957
+ blending: blend === "add" ? CustomBlending2 : blend === "alpha" ? NormalBlending : NoBlending2,
12101
12958
  blendEquation: AddEquation,
12102
12959
  blendSrc: OneFactor2,
12103
12960
  blendDst: OneFactor2,
@@ -12771,7 +13628,7 @@ var RigidBody = class extends EventDispatcher {
12771
13628
  teleport(position, rotation) {
12772
13629
  const o = this.object;
12773
13630
  o.updateWorldMatrix(true, false);
12774
- o.matrixWorld.decompose(_pos2, _quat, _scale3);
13631
+ o.matrixWorld.decompose(_pos2, _quat, _scale4);
12775
13632
  _pos2.copy(position);
12776
13633
  if (rotation instanceof Euler2) _quat.setFromEuler(rotation);
12777
13634
  else if (rotation) _quat.copy(rotation);
@@ -12833,7 +13690,7 @@ var RigidBody = class extends EventDispatcher {
12833
13690
  _readObjectPose(pos, quat) {
12834
13691
  const o = this.object;
12835
13692
  o.updateWorldMatrix(true, false);
12836
- o.matrixWorld.decompose(pos, quat, _scale3);
13693
+ o.matrixWorld.decompose(pos, quat, _scale4);
12837
13694
  if (this._linearOffset && this._angularOffset) {
12838
13695
  pos.add(_vec.copy(this._linearOffset).applyQuaternion(quat));
12839
13696
  quat.multiply(this._angularOffset);
@@ -12973,7 +13830,7 @@ function setObjectWorldPose(object, pos, quat) {
12973
13830
  parent.updateWorldMatrix(true, false);
12974
13831
  _mat2.compose(pos, quat, _one);
12975
13832
  _mat2.premultiply(_mat22.copy(parent.matrixWorld).invert());
12976
- _mat2.decompose(object.position, object.quaternion, _scale3);
13833
+ _mat2.decompose(object.position, object.quaternion, _scale4);
12977
13834
  } else {
12978
13835
  object.position.copy(pos);
12979
13836
  object.quaternion.copy(quat);
@@ -13025,8 +13882,8 @@ function createShape(A, desc, owner, parts) {
13025
13882
  }
13026
13883
  function createMeshShape(A, source, convexHull, owner, parts) {
13027
13884
  owner.updateWorldMatrix(true, false);
13028
- owner.matrixWorld.decompose(_pos2, _quat, _scale3);
13029
- const ownerScale = _scale3.clone();
13885
+ owner.matrixWorld.decompose(_pos2, _quat, _scale4);
13886
+ const ownerScale = _scale4.clone();
13030
13887
  const pieces = [];
13031
13888
  if (source instanceof BufferGeometry3) {
13032
13889
  pieces.push({ geometry: source, matrix: new Matrix44() });
@@ -13088,7 +13945,7 @@ function createMeshShape(A, source, convexHull, owner, parts) {
13088
13945
  }
13089
13946
  var _pos2 = new Vector38();
13090
13947
  var _vec = new Vector38();
13091
- var _scale3 = new Vector38();
13948
+ var _scale4 = new Vector38();
13092
13949
  var _one = new Vector38(1, 1, 1);
13093
13950
  var _zero = new Vector38(0, 0, 0);
13094
13951
  var _quat = new Quaternion3();
@@ -13541,12 +14398,46 @@ var Scene = class _Scene extends SplatEngine {
13541
14398
  transparent;
13542
14399
  /** Frames per second cap; `0` for none. Read every frame. */
13543
14400
  maxFps;
14401
+ /**
14402
+ * Speed of time for the loop {@link start} runs: each frame's step is
14403
+ * multiplied by it before physics, the characters and every listener see
14404
+ * it. `0` freezes the game while it keeps drawing; `0.5` is half speed.
14405
+ * PlayCanvas's `app.timeScale`. Default `1`. A {@link tick} called by hand
14406
+ * takes its `dt` as given.
14407
+ */
14408
+ timeScale = 1;
14409
+ /**
14410
+ * Longest step, in seconds, the loop {@link start} runs takes in one frame,
14411
+ * before {@link timeScale}, so a frame after a stall does not fling bodies.
14412
+ * PlayCanvas's `app.maxDeltaTime`. Default `0.1`.
14413
+ */
14414
+ maxDeltaTime = MAX_DELTA_TIME;
14415
+ /**
14416
+ * When `'update'` listeners run relative to the characters:
14417
+ * - `'characters-first'` (the default): every character advances, then
14418
+ * every listener runs. A listener reads this frame's poses.
14419
+ * - `'registration'`: characters and listeners run in the order they were
14420
+ * added, as in the PlayCanvas build, where each character is an
14421
+ * `app.on('update')` handler of its own. A listener added before a
14422
+ * character runs before it, so a pose it sets is used this frame.
14423
+ *
14424
+ * A character added back with `enableAutoUpdate` / `setActive(true)` moves
14425
+ * to the end, as in the PlayCanvas build. Set at {@link Scene.create}.
14426
+ */
14427
+ updateOrder;
13544
14428
  _listeners = {
13545
14429
  update: /* @__PURE__ */ new Set(),
13546
14430
  postUpdate: /* @__PURE__ */ new Set(),
13547
14431
  preRender: /* @__PURE__ */ new Set(),
13548
14432
  postRender: /* @__PURE__ */ new Set()
13549
14433
  };
14434
+ /** Listener → the wrapper {@link once} registered for it, per event. */
14435
+ _onceWrappers = {
14436
+ update: /* @__PURE__ */ new Map(),
14437
+ postUpdate: /* @__PURE__ */ new Map(),
14438
+ preRender: /* @__PURE__ */ new Map(),
14439
+ postRender: /* @__PURE__ */ new Map()
14440
+ };
13550
14441
  _running = false;
13551
14442
  _suspended = false;
13552
14443
  _lastTime = -1;
@@ -13570,6 +14461,7 @@ var Scene = class _Scene extends SplatEngine {
13570
14461
  this.threeScene = threeScene;
13571
14462
  this.physics = physics;
13572
14463
  this.maxFps = opts.maxFps ?? 0;
14464
+ this.updateOrder = opts.updateOrder ?? "characters-first";
13573
14465
  this._maxPixelRatio = opts.maxPixelRatio ?? 1;
13574
14466
  const bg = opts.bgColor ?? { r: 0.08, g: 0.08, b: 0.12, a: 1 };
13575
14467
  this.transparent = bg.a < 1;
@@ -13678,18 +14570,53 @@ var Scene = class _Scene extends SplatEngine {
13678
14570
  this.postfx.resize(width2, height);
13679
14571
  }
13680
14572
  /**
13681
- * Run `fn` every frame. `'update'` runs after physics and the characters
13682
- * have advanced, `'postUpdate'` after every `'update'` listener,
13683
- * `'preRender'` / `'postRender'` around the draw. `dt` is in seconds.
14573
+ * Run `fn` every frame. `'update'` runs after physics, and after or among
14574
+ * the characters as {@link updateOrder} says; `'postUpdate'` after every
14575
+ * `'update'` listener and character; `'preRender'` / `'postRender'` around
14576
+ * the draw. `dt` is in seconds.
13684
14577
  * @returns A function that removes the listener.
13685
14578
  */
13686
14579
  on(event, fn) {
13687
- this._listeners[event].add(fn);
14580
+ if (event === "update" && this.updateOrder === "registration") {
14581
+ this.addUpdater(fn);
14582
+ } else {
14583
+ this._listeners[event].add(fn);
14584
+ }
13688
14585
  return () => this.off(event, fn);
13689
14586
  }
13690
- /** Remove a listener added with {@link on}. */
14587
+ /**
14588
+ * Run `fn` on the next frame only. {@link off} with the same `fn` cancels
14589
+ * it, as for {@link on}.
14590
+ * @returns A function that removes the listener.
14591
+ */
14592
+ once(event, fn) {
14593
+ const wrappers = this._onceWrappers[event];
14594
+ const previous = wrappers.get(fn);
14595
+ if (previous) this._remove(event, previous);
14596
+ const cancel = () => {
14597
+ if (wrappers.get(fn) === wrapper) wrappers.delete(fn);
14598
+ this._remove(event, wrapper);
14599
+ };
14600
+ const wrapper = (dt) => {
14601
+ cancel();
14602
+ fn(dt);
14603
+ };
14604
+ wrappers.set(fn, wrapper);
14605
+ this.on(event, wrapper);
14606
+ return cancel;
14607
+ }
14608
+ /** Remove a listener added with {@link on} or {@link once}. */
13691
14609
  off(event, fn) {
14610
+ const wrapper = this._onceWrappers[event].get(fn);
14611
+ if (wrapper) {
14612
+ this._onceWrappers[event].delete(fn);
14613
+ this._remove(event, wrapper);
14614
+ }
14615
+ this._remove(event, fn);
14616
+ }
14617
+ _remove(event, fn) {
13692
14618
  this._listeners[event].delete(fn);
14619
+ if (event === "update") this.removeUpdater(fn);
13693
14620
  }
13694
14621
  /** Start the render loop. */
13695
14622
  start() {
@@ -13714,13 +14641,15 @@ var Scene = class _Scene extends SplatEngine {
13714
14641
  if (time - this._lastFrameTime < 1e3 / this.maxFps - 2) return;
13715
14642
  }
13716
14643
  this._lastFrameTime = time;
13717
- const dt = this._lastTime < 0 ? 0 : Math.min(MAX_DELTA_TIME, (time - this._lastTime) / 1e3);
14644
+ const dt = this._lastTime < 0 ? 0 : Math.min(this.maxDeltaTime, Math.max(0, (time - this._lastTime) / 1e3));
13718
14645
  this._lastTime = time;
13719
- this.tick(dt);
14646
+ this.tick(dt * this.timeScale);
13720
14647
  }
13721
14648
  /**
13722
- * Advance and draw one frame by hand: physics, characters, the `'update'`
13723
- * listeners, then the render. The loop {@link start} runs calls this.
14649
+ * Advance and draw one frame by hand: physics, characters and the
14650
+ * `'update'` listeners (in {@link updateOrder}), then the render. The loop
14651
+ * {@link start} runs calls this with its step clamped to
14652
+ * {@link maxDeltaTime} and scaled by {@link timeScale}.
13724
14653
  */
13725
14654
  tick(dt) {
13726
14655
  if (this.destroyed) return;
@@ -13768,6 +14697,7 @@ var Scene = class _Scene extends SplatEngine {
13768
14697
  this._resizeObserver?.disconnect();
13769
14698
  this.skeletalAnimationLibrary.clear();
13770
14699
  for (const set of Object.values(this._listeners)) set.clear();
14700
+ for (const map of Object.values(this._onceWrappers)) map.clear();
13771
14701
  try {
13772
14702
  this.postfx.destroyAll();
13773
14703
  } catch {
@@ -14554,31 +15484,37 @@ function makeXform(pos, rot) {
14554
15484
  return t;
14555
15485
  }
14556
15486
  var BROKEN_SEPARATION = 0.08;
15487
+ function between(a, b, make) {
15488
+ return () => make(bodyOf(a), bodyOf(b));
15489
+ }
14557
15490
  var Joint = class {
14558
15491
  bodyA;
15492
+ /** `null` when the joint holds `bodyA` to the world. */
14559
15493
  bodyB;
14560
15494
  _c;
14561
15495
  _world;
14562
15496
  _native;
14563
- _make;
15497
+ /** Makes the native constraint against the bodies' current native objects. */
15498
+ _build;
14564
15499
  _disableCollision;
14565
15500
  /** Set while a body is rebuilding: the constraint is gone, the joint is not. */
14566
15501
  _suspended = false;
14567
15502
  /** Breaking threshold (N·s) stored on the wrapper for our own poll;
14568
15503
  * `0` means "unbreakable". */
14569
15504
  _breakThreshold;
14570
- /** Joint anchor in each body's local frame, for the separation test. */
15505
+ /** Joint anchor in `bodyA`'s local frame, and in `bodyB`'s (or the world,
15506
+ * with no `bodyB`), for the separation test. */
14571
15507
  _anchorA;
14572
15508
  _anchorB;
14573
15509
  _broken = false;
14574
- constructor(world, bodyA, bodyB, make, disableCollision, breakThreshold, anchorA, anchorB) {
15510
+ constructor(world, bodyA, bodyB, build, disableCollision, breakThreshold, anchorA, anchorB) {
14575
15511
  this._world = world;
14576
15512
  this._native = world.dynamicsWorld;
14577
15513
  this.bodyA = bodyA;
14578
15514
  this.bodyB = bodyB;
14579
- this._make = make;
15515
+ this._build = build;
14580
15516
  this._disableCollision = disableCollision;
14581
- this._c = make(bodyOf(bodyA), bodyOf(bodyB));
15517
+ this._c = build();
14582
15518
  this._native.addConstraint(this._c, disableCollision);
14583
15519
  this._breakThreshold = breakThreshold;
14584
15520
  this._anchorA = anchorA ? new Vector311(anchorA.x, anchorA.y, anchorA.z) : null;
@@ -14613,7 +15549,7 @@ var Joint = class {
14613
15549
  resume() {
14614
15550
  if (!this._suspended) return;
14615
15551
  this._suspended = false;
14616
- this._c = this._make(bodyOf(this.bodyA), bodyOf(this.bodyB));
15552
+ this._c = this._build();
14617
15553
  this._native.addConstraint(this._c, this._disableCollision);
14618
15554
  }
14619
15555
  isBroken() {
@@ -14633,7 +15569,8 @@ var Joint = class {
14633
15569
  _anchorSeparation() {
14634
15570
  if (!this._anchorA || !this._anchorB) return 0;
14635
15571
  anchorWorld(this.bodyA, this._anchorA, _sepA);
14636
- anchorWorld(this.bodyB, this._anchorB, _sepB);
15572
+ if (this.bodyB) anchorWorld(this.bodyB, this._anchorB, _sepB);
15573
+ else _sepB.copy(this._anchorB);
14637
15574
  return _sepA.distanceTo(_sepB);
14638
15575
  }
14639
15576
  };
@@ -14665,7 +15602,14 @@ function createConeTwistJoint(opts) {
14665
15602
  A.destroy(fB);
14666
15603
  return c;
14667
15604
  };
14668
- return new Joint(world, opts.bodyA, opts.bodyB, make, opts.disableCollisionBetweenLinkedBodies ?? true, 0);
15605
+ return new Joint(
15606
+ world,
15607
+ opts.bodyA,
15608
+ opts.bodyB,
15609
+ between(opts.bodyA, opts.bodyB, make),
15610
+ opts.disableCollisionBetweenLinkedBodies ?? true,
15611
+ 0
15612
+ );
14669
15613
  }
14670
15614
  function createGeneric6DofJoint(opts) {
14671
15615
  const world = worldOf(opts.bodyA, opts.bodyB);
@@ -14705,7 +15649,7 @@ function createGeneric6DofJoint(opts) {
14705
15649
  world,
14706
15650
  opts.bodyA,
14707
15651
  opts.bodyB,
14708
- make,
15652
+ between(opts.bodyA, opts.bodyB, make),
14709
15653
  opts.disableCollisionBetweenLinkedBodies ?? true,
14710
15654
  breakImpulse ?? 0,
14711
15655
  locked ? frameInA.position : void 0,
@@ -14735,7 +15679,78 @@ function createHingeJoint(opts) {
14735
15679
  A.destroy(aB);
14736
15680
  return c;
14737
15681
  };
14738
- return new Joint(world, opts.bodyA, opts.bodyB, make, opts.disableCollisionBetweenLinkedBodies ?? true, 0);
15682
+ return new Joint(
15683
+ world,
15684
+ opts.bodyA,
15685
+ opts.bodyB,
15686
+ between(opts.bodyA, opts.bodyB, make),
15687
+ opts.disableCollisionBetweenLinkedBodies ?? true,
15688
+ 0
15689
+ );
15690
+ }
15691
+ var PointToPointJoint = class extends Joint {
15692
+ _pivotB;
15693
+ constructor(world, bodyA, bodyB, pivotInA, pivotInB, disableCollision, breakImpulse) {
15694
+ const pivotB = copyXYZ(pivotInB);
15695
+ const build = () => {
15696
+ const A = ammo();
15697
+ const pA = new A.btVector3(pivotInA.x, pivotInA.y, pivotInA.z);
15698
+ const pB = new A.btVector3(pivotB.x, pivotB.y, pivotB.z);
15699
+ let c;
15700
+ if (bodyB) {
15701
+ c = new A.btPoint2PointConstraint(bodyOf(bodyA), bodyOf(bodyB), pA, pB);
15702
+ } else {
15703
+ c = new A.btPoint2PointConstraint(bodyOf(bodyA), pA);
15704
+ c.setPivotB(pB);
15705
+ }
15706
+ if (breakImpulse !== void 0) c.setBreakingImpulseThreshold(breakImpulse);
15707
+ A.destroy(pA);
15708
+ A.destroy(pB);
15709
+ return c;
15710
+ };
15711
+ super(world, bodyA, bodyB, build, disableCollision, breakImpulse ?? 0, pivotInA, pivotB);
15712
+ this._pivotB = pivotB;
15713
+ }
15714
+ setPivotB(pivot) {
15715
+ this._pivotB.x = pivot.x;
15716
+ this._pivotB.y = pivot.y;
15717
+ this._pivotB.z = pivot.z;
15718
+ this._anchorB?.set(pivot.x, pivot.y, pivot.z);
15719
+ const c = this._c;
15720
+ if (!c) return;
15721
+ const A = ammo();
15722
+ const p = new A.btVector3(pivot.x, pivot.y, pivot.z);
15723
+ c.setPivotB(p);
15724
+ A.destroy(p);
15725
+ this.bodyA.activate();
15726
+ this.bodyB?.activate();
15727
+ }
15728
+ };
15729
+ function createPointToPointJoint(opts) {
15730
+ const bodyB = opts.bodyB ?? null;
15731
+ const world = bodyB ? worldOf(opts.bodyA, bodyB) : opts.bodyA.world;
15732
+ bodyOf(opts.bodyA);
15733
+ const pivotInA = copyXYZ(opts.pivotInA);
15734
+ let pivotInB = opts.pivotInB;
15735
+ if (!pivotInB) {
15736
+ const at = anchorWorld(opts.bodyA, _sepA.set(pivotInA.x, pivotInA.y, pivotInA.z), new Vector311());
15737
+ if (bodyB) {
15738
+ const t = bodyOf(bodyB).getWorldTransform();
15739
+ const o = t.getOrigin();
15740
+ const q = t.getRotation();
15741
+ at.sub(_sepO.set(o.x(), o.y(), o.z())).applyQuaternion(_sepQ.set(q.x(), q.y(), q.z(), q.w()).invert());
15742
+ }
15743
+ pivotInB = at;
15744
+ }
15745
+ return new PointToPointJoint(
15746
+ world,
15747
+ opts.bodyA,
15748
+ bodyB,
15749
+ pivotInA,
15750
+ pivotInB,
15751
+ opts.disableCollisionBetweenLinkedBodies ?? true,
15752
+ opts.breakImpulse
15753
+ );
14739
15754
  }
14740
15755
 
14741
15756
  // src/skeletal/ragdoll.ts
@@ -15926,6 +16941,7 @@ var LodBundle = class {
15926
16941
  splat.effects.x = previous.effects.x;
15927
16942
  splat.minPixelSize = previous.minPixelSize;
15928
16943
  splat.antiAlias = previous.antiAlias;
16944
+ splat.depthWriteAlpha = previous.depthWriteAlpha;
15929
16945
  if (packed.numSplats === 0) {
15930
16946
  previous.destroy();
15931
16947
  this._splat = splat;
@@ -22150,6 +23166,9 @@ function stripUndefined3(o) {
22150
23166
  }
22151
23167
 
22152
23168
  export {
23169
+ Vec3,
23170
+ Quat,
23171
+ Mat4,
22153
23172
  setAssetFetch,
22154
23173
  indexAssetCache,
22155
23174
  cachedFetch,
@@ -22157,15 +23176,18 @@ export {
22157
23176
  installFetchInterceptor,
22158
23177
  uninstallFetchInterceptor,
22159
23178
  isCached,
23179
+ evictExpired,
22160
23180
  clearAnimRootRotation,
22161
23181
  Animation,
22162
23182
  Pose,
22163
23183
  computeBoneStretch,
23184
+ buildSourceBoneRemap,
22164
23185
  Armature,
22165
23186
  SplatEngine,
22166
23187
  EngineDisposedError,
22167
23188
  packSplats,
22168
23189
  SplatQuality,
23190
+ effectiveDepthWriteAlpha,
22169
23191
  effectiveMinPixelSize,
22170
23192
  beginFrameTimings,
22171
23193
  pruneSplats,
@@ -22239,6 +23261,7 @@ export {
22239
23261
  createConeTwistJoint,
22240
23262
  createGeneric6DofJoint,
22241
23263
  createHingeJoint,
23264
+ createPointToPointJoint,
22242
23265
  DEFAULT_HUMANOID_RAGDOLL,
22243
23266
  Ragdoll,
22244
23267
  Environment,
@@ -22293,6 +23316,7 @@ export {
22293
23316
  getRelightPlaceholder,
22294
23317
  ENVIRONMENT_PROXY_DEFAULTS,
22295
23318
  ENVIRONMENT_DEFAULT_LOD,
22296
- SplatRelight
23319
+ SplatRelight,
23320
+ setPlayCanvasLightColor
22297
23321
  };
22298
- //# sourceMappingURL=chunk-BHNNSHJG.js.map
23322
+ //# sourceMappingURL=chunk-SASRTGRD.js.map