@viggle/splat-engine-three 0.2.0 → 0.3.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) {
@@ -6555,7 +7274,7 @@ void main(void) {
6555
7274
  // src/splat/webgl/splat-mesh.ts
6556
7275
  var _position = new Vector33();
6557
7276
  var _quaternion = new Quaternion2();
6558
- var _scale2 = new Vector33();
7277
+ var _scale3 = new Vector33();
6559
7278
  var _viewport = new Vector4();
6560
7279
  var RELIGHT_UNIFORMS = [
6561
7280
  "uRelightTex",
@@ -6772,9 +7491,9 @@ var WebGLSplatImpl = class {
6772
7491
  const target = gl.getRenderTarget();
6773
7492
  const outputColorSpace = target ? target.texture.colorSpace : gl.outputColorSpace;
6774
7493
  u.uOutputLinear.value = ColorManagement.getTransfer(outputColorSpace) === LinearTransfer ? 1 : 0;
6775
- this._host.matrixWorld.decompose(_position, _quaternion, _scale2);
7494
+ this._host.matrixWorld.decompose(_position, _quaternion, _scale3);
6776
7495
  u.uModelRotation.value.set(_quaternion.x, _quaternion.y, _quaternion.z, _quaternion.w);
6777
- u.uModelScale.value.copy(_scale2);
7496
+ u.uModelScale.value.copy(_scale3);
6778
7497
  u.uMinPixelSize.value = effectiveMinPixelSize(splat.minPixelSize);
6779
7498
  u.uAlphaCutoffScale.value = 1 / Math.max(1 / 65535, SplatQuality.quadAlphaCutoff);
6780
7499
  u.transformPalette.value = splat.transformPalette.texture;
@@ -12771,7 +13490,7 @@ var RigidBody = class extends EventDispatcher {
12771
13490
  teleport(position, rotation) {
12772
13491
  const o = this.object;
12773
13492
  o.updateWorldMatrix(true, false);
12774
- o.matrixWorld.decompose(_pos2, _quat, _scale3);
13493
+ o.matrixWorld.decompose(_pos2, _quat, _scale4);
12775
13494
  _pos2.copy(position);
12776
13495
  if (rotation instanceof Euler2) _quat.setFromEuler(rotation);
12777
13496
  else if (rotation) _quat.copy(rotation);
@@ -12833,7 +13552,7 @@ var RigidBody = class extends EventDispatcher {
12833
13552
  _readObjectPose(pos, quat) {
12834
13553
  const o = this.object;
12835
13554
  o.updateWorldMatrix(true, false);
12836
- o.matrixWorld.decompose(pos, quat, _scale3);
13555
+ o.matrixWorld.decompose(pos, quat, _scale4);
12837
13556
  if (this._linearOffset && this._angularOffset) {
12838
13557
  pos.add(_vec.copy(this._linearOffset).applyQuaternion(quat));
12839
13558
  quat.multiply(this._angularOffset);
@@ -12973,7 +13692,7 @@ function setObjectWorldPose(object, pos, quat) {
12973
13692
  parent.updateWorldMatrix(true, false);
12974
13693
  _mat2.compose(pos, quat, _one);
12975
13694
  _mat2.premultiply(_mat22.copy(parent.matrixWorld).invert());
12976
- _mat2.decompose(object.position, object.quaternion, _scale3);
13695
+ _mat2.decompose(object.position, object.quaternion, _scale4);
12977
13696
  } else {
12978
13697
  object.position.copy(pos);
12979
13698
  object.quaternion.copy(quat);
@@ -13025,8 +13744,8 @@ function createShape(A, desc, owner, parts) {
13025
13744
  }
13026
13745
  function createMeshShape(A, source, convexHull, owner, parts) {
13027
13746
  owner.updateWorldMatrix(true, false);
13028
- owner.matrixWorld.decompose(_pos2, _quat, _scale3);
13029
- const ownerScale = _scale3.clone();
13747
+ owner.matrixWorld.decompose(_pos2, _quat, _scale4);
13748
+ const ownerScale = _scale4.clone();
13030
13749
  const pieces = [];
13031
13750
  if (source instanceof BufferGeometry3) {
13032
13751
  pieces.push({ geometry: source, matrix: new Matrix44() });
@@ -13088,7 +13807,7 @@ function createMeshShape(A, source, convexHull, owner, parts) {
13088
13807
  }
13089
13808
  var _pos2 = new Vector38();
13090
13809
  var _vec = new Vector38();
13091
- var _scale3 = new Vector38();
13810
+ var _scale4 = new Vector38();
13092
13811
  var _one = new Vector38(1, 1, 1);
13093
13812
  var _zero = new Vector38(0, 0, 0);
13094
13813
  var _quat = new Quaternion3();
@@ -13541,12 +14260,46 @@ var Scene = class _Scene extends SplatEngine {
13541
14260
  transparent;
13542
14261
  /** Frames per second cap; `0` for none. Read every frame. */
13543
14262
  maxFps;
14263
+ /**
14264
+ * Speed of time for the loop {@link start} runs: each frame's step is
14265
+ * multiplied by it before physics, the characters and every listener see
14266
+ * it. `0` freezes the game while it keeps drawing; `0.5` is half speed.
14267
+ * PlayCanvas's `app.timeScale`. Default `1`. A {@link tick} called by hand
14268
+ * takes its `dt` as given.
14269
+ */
14270
+ timeScale = 1;
14271
+ /**
14272
+ * Longest step, in seconds, the loop {@link start} runs takes in one frame,
14273
+ * before {@link timeScale}, so a frame after a stall does not fling bodies.
14274
+ * PlayCanvas's `app.maxDeltaTime`. Default `0.1`.
14275
+ */
14276
+ maxDeltaTime = MAX_DELTA_TIME;
14277
+ /**
14278
+ * When `'update'` listeners run relative to the characters:
14279
+ * - `'characters-first'` (the default): every character advances, then
14280
+ * every listener runs. A listener reads this frame's poses.
14281
+ * - `'registration'`: characters and listeners run in the order they were
14282
+ * added, as in the PlayCanvas build, where each character is an
14283
+ * `app.on('update')` handler of its own. A listener added before a
14284
+ * character runs before it, so a pose it sets is used this frame.
14285
+ *
14286
+ * A character added back with `enableAutoUpdate` / `setActive(true)` moves
14287
+ * to the end, as in the PlayCanvas build. Set at {@link Scene.create}.
14288
+ */
14289
+ updateOrder;
13544
14290
  _listeners = {
13545
14291
  update: /* @__PURE__ */ new Set(),
13546
14292
  postUpdate: /* @__PURE__ */ new Set(),
13547
14293
  preRender: /* @__PURE__ */ new Set(),
13548
14294
  postRender: /* @__PURE__ */ new Set()
13549
14295
  };
14296
+ /** Listener → the wrapper {@link once} registered for it, per event. */
14297
+ _onceWrappers = {
14298
+ update: /* @__PURE__ */ new Map(),
14299
+ postUpdate: /* @__PURE__ */ new Map(),
14300
+ preRender: /* @__PURE__ */ new Map(),
14301
+ postRender: /* @__PURE__ */ new Map()
14302
+ };
13550
14303
  _running = false;
13551
14304
  _suspended = false;
13552
14305
  _lastTime = -1;
@@ -13570,6 +14323,7 @@ var Scene = class _Scene extends SplatEngine {
13570
14323
  this.threeScene = threeScene;
13571
14324
  this.physics = physics;
13572
14325
  this.maxFps = opts.maxFps ?? 0;
14326
+ this.updateOrder = opts.updateOrder ?? "characters-first";
13573
14327
  this._maxPixelRatio = opts.maxPixelRatio ?? 1;
13574
14328
  const bg = opts.bgColor ?? { r: 0.08, g: 0.08, b: 0.12, a: 1 };
13575
14329
  this.transparent = bg.a < 1;
@@ -13678,18 +14432,53 @@ var Scene = class _Scene extends SplatEngine {
13678
14432
  this.postfx.resize(width2, height);
13679
14433
  }
13680
14434
  /**
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.
14435
+ * Run `fn` every frame. `'update'` runs after physics, and after or among
14436
+ * the characters as {@link updateOrder} says; `'postUpdate'` after every
14437
+ * `'update'` listener and character; `'preRender'` / `'postRender'` around
14438
+ * the draw. `dt` is in seconds.
13684
14439
  * @returns A function that removes the listener.
13685
14440
  */
13686
14441
  on(event, fn) {
13687
- this._listeners[event].add(fn);
14442
+ if (event === "update" && this.updateOrder === "registration") {
14443
+ this.addUpdater(fn);
14444
+ } else {
14445
+ this._listeners[event].add(fn);
14446
+ }
13688
14447
  return () => this.off(event, fn);
13689
14448
  }
13690
- /** Remove a listener added with {@link on}. */
14449
+ /**
14450
+ * Run `fn` on the next frame only. {@link off} with the same `fn` cancels
14451
+ * it, as for {@link on}.
14452
+ * @returns A function that removes the listener.
14453
+ */
14454
+ once(event, fn) {
14455
+ const wrappers = this._onceWrappers[event];
14456
+ const previous = wrappers.get(fn);
14457
+ if (previous) this._remove(event, previous);
14458
+ const cancel = () => {
14459
+ if (wrappers.get(fn) === wrapper) wrappers.delete(fn);
14460
+ this._remove(event, wrapper);
14461
+ };
14462
+ const wrapper = (dt) => {
14463
+ cancel();
14464
+ fn(dt);
14465
+ };
14466
+ wrappers.set(fn, wrapper);
14467
+ this.on(event, wrapper);
14468
+ return cancel;
14469
+ }
14470
+ /** Remove a listener added with {@link on} or {@link once}. */
13691
14471
  off(event, fn) {
14472
+ const wrapper = this._onceWrappers[event].get(fn);
14473
+ if (wrapper) {
14474
+ this._onceWrappers[event].delete(fn);
14475
+ this._remove(event, wrapper);
14476
+ }
14477
+ this._remove(event, fn);
14478
+ }
14479
+ _remove(event, fn) {
13692
14480
  this._listeners[event].delete(fn);
14481
+ if (event === "update") this.removeUpdater(fn);
13693
14482
  }
13694
14483
  /** Start the render loop. */
13695
14484
  start() {
@@ -13714,13 +14503,15 @@ var Scene = class _Scene extends SplatEngine {
13714
14503
  if (time - this._lastFrameTime < 1e3 / this.maxFps - 2) return;
13715
14504
  }
13716
14505
  this._lastFrameTime = time;
13717
- const dt = this._lastTime < 0 ? 0 : Math.min(MAX_DELTA_TIME, (time - this._lastTime) / 1e3);
14506
+ const dt = this._lastTime < 0 ? 0 : Math.min(this.maxDeltaTime, Math.max(0, (time - this._lastTime) / 1e3));
13718
14507
  this._lastTime = time;
13719
- this.tick(dt);
14508
+ this.tick(dt * this.timeScale);
13720
14509
  }
13721
14510
  /**
13722
- * Advance and draw one frame by hand: physics, characters, the `'update'`
13723
- * listeners, then the render. The loop {@link start} runs calls this.
14511
+ * Advance and draw one frame by hand: physics, characters and the
14512
+ * `'update'` listeners (in {@link updateOrder}), then the render. The loop
14513
+ * {@link start} runs calls this with its step clamped to
14514
+ * {@link maxDeltaTime} and scaled by {@link timeScale}.
13724
14515
  */
13725
14516
  tick(dt) {
13726
14517
  if (this.destroyed) return;
@@ -13768,6 +14559,7 @@ var Scene = class _Scene extends SplatEngine {
13768
14559
  this._resizeObserver?.disconnect();
13769
14560
  this.skeletalAnimationLibrary.clear();
13770
14561
  for (const set of Object.values(this._listeners)) set.clear();
14562
+ for (const map of Object.values(this._onceWrappers)) map.clear();
13771
14563
  try {
13772
14564
  this.postfx.destroyAll();
13773
14565
  } catch {
@@ -14554,31 +15346,37 @@ function makeXform(pos, rot) {
14554
15346
  return t;
14555
15347
  }
14556
15348
  var BROKEN_SEPARATION = 0.08;
15349
+ function between(a, b, make) {
15350
+ return () => make(bodyOf(a), bodyOf(b));
15351
+ }
14557
15352
  var Joint = class {
14558
15353
  bodyA;
15354
+ /** `null` when the joint holds `bodyA` to the world. */
14559
15355
  bodyB;
14560
15356
  _c;
14561
15357
  _world;
14562
15358
  _native;
14563
- _make;
15359
+ /** Makes the native constraint against the bodies' current native objects. */
15360
+ _build;
14564
15361
  _disableCollision;
14565
15362
  /** Set while a body is rebuilding: the constraint is gone, the joint is not. */
14566
15363
  _suspended = false;
14567
15364
  /** Breaking threshold (N·s) stored on the wrapper for our own poll;
14568
15365
  * `0` means "unbreakable". */
14569
15366
  _breakThreshold;
14570
- /** Joint anchor in each body's local frame, for the separation test. */
15367
+ /** Joint anchor in `bodyA`'s local frame, and in `bodyB`'s (or the world,
15368
+ * with no `bodyB`), for the separation test. */
14571
15369
  _anchorA;
14572
15370
  _anchorB;
14573
15371
  _broken = false;
14574
- constructor(world, bodyA, bodyB, make, disableCollision, breakThreshold, anchorA, anchorB) {
15372
+ constructor(world, bodyA, bodyB, build, disableCollision, breakThreshold, anchorA, anchorB) {
14575
15373
  this._world = world;
14576
15374
  this._native = world.dynamicsWorld;
14577
15375
  this.bodyA = bodyA;
14578
15376
  this.bodyB = bodyB;
14579
- this._make = make;
15377
+ this._build = build;
14580
15378
  this._disableCollision = disableCollision;
14581
- this._c = make(bodyOf(bodyA), bodyOf(bodyB));
15379
+ this._c = build();
14582
15380
  this._native.addConstraint(this._c, disableCollision);
14583
15381
  this._breakThreshold = breakThreshold;
14584
15382
  this._anchorA = anchorA ? new Vector311(anchorA.x, anchorA.y, anchorA.z) : null;
@@ -14613,7 +15411,7 @@ var Joint = class {
14613
15411
  resume() {
14614
15412
  if (!this._suspended) return;
14615
15413
  this._suspended = false;
14616
- this._c = this._make(bodyOf(this.bodyA), bodyOf(this.bodyB));
15414
+ this._c = this._build();
14617
15415
  this._native.addConstraint(this._c, this._disableCollision);
14618
15416
  }
14619
15417
  isBroken() {
@@ -14633,7 +15431,8 @@ var Joint = class {
14633
15431
  _anchorSeparation() {
14634
15432
  if (!this._anchorA || !this._anchorB) return 0;
14635
15433
  anchorWorld(this.bodyA, this._anchorA, _sepA);
14636
- anchorWorld(this.bodyB, this._anchorB, _sepB);
15434
+ if (this.bodyB) anchorWorld(this.bodyB, this._anchorB, _sepB);
15435
+ else _sepB.copy(this._anchorB);
14637
15436
  return _sepA.distanceTo(_sepB);
14638
15437
  }
14639
15438
  };
@@ -14665,7 +15464,14 @@ function createConeTwistJoint(opts) {
14665
15464
  A.destroy(fB);
14666
15465
  return c;
14667
15466
  };
14668
- return new Joint(world, opts.bodyA, opts.bodyB, make, opts.disableCollisionBetweenLinkedBodies ?? true, 0);
15467
+ return new Joint(
15468
+ world,
15469
+ opts.bodyA,
15470
+ opts.bodyB,
15471
+ between(opts.bodyA, opts.bodyB, make),
15472
+ opts.disableCollisionBetweenLinkedBodies ?? true,
15473
+ 0
15474
+ );
14669
15475
  }
14670
15476
  function createGeneric6DofJoint(opts) {
14671
15477
  const world = worldOf(opts.bodyA, opts.bodyB);
@@ -14705,7 +15511,7 @@ function createGeneric6DofJoint(opts) {
14705
15511
  world,
14706
15512
  opts.bodyA,
14707
15513
  opts.bodyB,
14708
- make,
15514
+ between(opts.bodyA, opts.bodyB, make),
14709
15515
  opts.disableCollisionBetweenLinkedBodies ?? true,
14710
15516
  breakImpulse ?? 0,
14711
15517
  locked ? frameInA.position : void 0,
@@ -14735,7 +15541,78 @@ function createHingeJoint(opts) {
14735
15541
  A.destroy(aB);
14736
15542
  return c;
14737
15543
  };
14738
- return new Joint(world, opts.bodyA, opts.bodyB, make, opts.disableCollisionBetweenLinkedBodies ?? true, 0);
15544
+ return new Joint(
15545
+ world,
15546
+ opts.bodyA,
15547
+ opts.bodyB,
15548
+ between(opts.bodyA, opts.bodyB, make),
15549
+ opts.disableCollisionBetweenLinkedBodies ?? true,
15550
+ 0
15551
+ );
15552
+ }
15553
+ var PointToPointJoint = class extends Joint {
15554
+ _pivotB;
15555
+ constructor(world, bodyA, bodyB, pivotInA, pivotInB, disableCollision, breakImpulse) {
15556
+ const pivotB = copyXYZ(pivotInB);
15557
+ const build = () => {
15558
+ const A = ammo();
15559
+ const pA = new A.btVector3(pivotInA.x, pivotInA.y, pivotInA.z);
15560
+ const pB = new A.btVector3(pivotB.x, pivotB.y, pivotB.z);
15561
+ let c;
15562
+ if (bodyB) {
15563
+ c = new A.btPoint2PointConstraint(bodyOf(bodyA), bodyOf(bodyB), pA, pB);
15564
+ } else {
15565
+ c = new A.btPoint2PointConstraint(bodyOf(bodyA), pA);
15566
+ c.setPivotB(pB);
15567
+ }
15568
+ if (breakImpulse !== void 0) c.setBreakingImpulseThreshold(breakImpulse);
15569
+ A.destroy(pA);
15570
+ A.destroy(pB);
15571
+ return c;
15572
+ };
15573
+ super(world, bodyA, bodyB, build, disableCollision, breakImpulse ?? 0, pivotInA, pivotB);
15574
+ this._pivotB = pivotB;
15575
+ }
15576
+ setPivotB(pivot) {
15577
+ this._pivotB.x = pivot.x;
15578
+ this._pivotB.y = pivot.y;
15579
+ this._pivotB.z = pivot.z;
15580
+ this._anchorB?.set(pivot.x, pivot.y, pivot.z);
15581
+ const c = this._c;
15582
+ if (!c) return;
15583
+ const A = ammo();
15584
+ const p = new A.btVector3(pivot.x, pivot.y, pivot.z);
15585
+ c.setPivotB(p);
15586
+ A.destroy(p);
15587
+ this.bodyA.activate();
15588
+ this.bodyB?.activate();
15589
+ }
15590
+ };
15591
+ function createPointToPointJoint(opts) {
15592
+ const bodyB = opts.bodyB ?? null;
15593
+ const world = bodyB ? worldOf(opts.bodyA, bodyB) : opts.bodyA.world;
15594
+ bodyOf(opts.bodyA);
15595
+ const pivotInA = copyXYZ(opts.pivotInA);
15596
+ let pivotInB = opts.pivotInB;
15597
+ if (!pivotInB) {
15598
+ const at = anchorWorld(opts.bodyA, _sepA.set(pivotInA.x, pivotInA.y, pivotInA.z), new Vector311());
15599
+ if (bodyB) {
15600
+ const t = bodyOf(bodyB).getWorldTransform();
15601
+ const o = t.getOrigin();
15602
+ const q = t.getRotation();
15603
+ at.sub(_sepO.set(o.x(), o.y(), o.z())).applyQuaternion(_sepQ.set(q.x(), q.y(), q.z(), q.w()).invert());
15604
+ }
15605
+ pivotInB = at;
15606
+ }
15607
+ return new PointToPointJoint(
15608
+ world,
15609
+ opts.bodyA,
15610
+ bodyB,
15611
+ pivotInA,
15612
+ pivotInB,
15613
+ opts.disableCollisionBetweenLinkedBodies ?? true,
15614
+ opts.breakImpulse
15615
+ );
14739
15616
  }
14740
15617
 
14741
15618
  // src/skeletal/ragdoll.ts
@@ -22150,6 +23027,9 @@ function stripUndefined3(o) {
22150
23027
  }
22151
23028
 
22152
23029
  export {
23030
+ Vec3,
23031
+ Quat,
23032
+ Mat4,
22153
23033
  setAssetFetch,
22154
23034
  indexAssetCache,
22155
23035
  cachedFetch,
@@ -22157,10 +23037,12 @@ export {
22157
23037
  installFetchInterceptor,
22158
23038
  uninstallFetchInterceptor,
22159
23039
  isCached,
23040
+ evictExpired,
22160
23041
  clearAnimRootRotation,
22161
23042
  Animation,
22162
23043
  Pose,
22163
23044
  computeBoneStretch,
23045
+ buildSourceBoneRemap,
22164
23046
  Armature,
22165
23047
  SplatEngine,
22166
23048
  EngineDisposedError,
@@ -22239,6 +23121,7 @@ export {
22239
23121
  createConeTwistJoint,
22240
23122
  createGeneric6DofJoint,
22241
23123
  createHingeJoint,
23124
+ createPointToPointJoint,
22242
23125
  DEFAULT_HUMANOID_RAGDOLL,
22243
23126
  Ragdoll,
22244
23127
  Environment,
@@ -22293,6 +23176,7 @@ export {
22293
23176
  getRelightPlaceholder,
22294
23177
  ENVIRONMENT_PROXY_DEFAULTS,
22295
23178
  ENVIRONMENT_DEFAULT_LOD,
22296
- SplatRelight
23179
+ SplatRelight,
23180
+ setPlayCanvasLightColor
22297
23181
  };
22298
- //# sourceMappingURL=chunk-BHNNSHJG.js.map
23182
+ //# sourceMappingURL=chunk-2GKWT24B.js.map