glmaths 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/glmaths.js CHANGED
@@ -6,20 +6,20 @@ var glmaths = (function (exports) {
6
6
  * @extends Float32Array
7
7
  */
8
8
  class Vec3 extends Float32Array {
9
- static get zero() { return new Vec3(0, 0, 0); }
10
- static get Zero() { return new Vec3(0, 0, 0); }
11
- static get ZERO() { return new Vec3(0, 0, 0); }
12
- static get one() { return new Vec3(1, 1, 1); }
13
- static get One() { return new Vec3(1, 1, 1); }
14
- static get ONE() { return new Vec3(1, 1, 1); }
15
- static get unitX() { return new Vec3(1, 0, 0); }
16
- static get UnitX() { return new Vec3(1, 0, 0); }
17
- static get unitY() { return new Vec3(0, 1, 0); }
18
- static get UnitY() { return new Vec3(0, 1, 0); }
19
- static get unitZ() { return new Vec3(0, 0, 1); }
20
- static get UnitZ() { return new Vec3(0, 0, 1); }
21
- /**
22
- * Creates a new Vec3
9
+ static get zero() { return vec3(0, 0, 0); }
10
+ static get Zero() { return vec3(0, 0, 0); }
11
+ static get ZERO() { return vec3(0, 0, 0); }
12
+ static get one() { return vec3(1, 1, 1); }
13
+ static get One() { return vec3(1, 1, 1); }
14
+ static get ONE() { return vec3(1, 1, 1); }
15
+ static get unitX() { return vec3(1, 0, 0); }
16
+ static get UnitX() { return vec3(1, 0, 0); }
17
+ static get unitY() { return vec3(0, 1, 0); }
18
+ static get UnitY() { return vec3(0, 1, 0); }
19
+ static get unitZ() { return vec3(0, 0, 1); }
20
+ static get UnitZ() { return vec3(0, 0, 1); }
21
+ /**
22
+ * Creates new vec3
23
23
  *
24
24
  * @param {Number} x X component, defaults to 0
25
25
  * @param {Number} y Y component, defaults to 0
@@ -41,10 +41,10 @@ var glmaths = (function (exports) {
41
41
  * Adds two vec3's
42
42
  *
43
43
  * @param {Number | Vec3} b the second operand
44
- * @param {Vec3} out the receiving vector, defaults to this
44
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
45
45
  * @returns {Vec3} out
46
46
  */
47
- plus(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
47
+ plus(b, out = index.ALWAYS_COPY ? vec3() : this) {
48
48
  if (typeof b === 'number') {
49
49
  out[0] = this[0] + b;
50
50
  out[1] = this[1] + b;
@@ -61,10 +61,10 @@ var glmaths = (function (exports) {
61
61
  * Subtracts two vec3's
62
62
  *
63
63
  * @param {Number | Vec3} b the second operand
64
- * @param {Vec3} out the receiving vector, defaults to this
64
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
65
65
  * @returns {Vec3} out
66
66
  */
67
- minus(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
67
+ minus(b, out = index.ALWAYS_COPY ? vec3() : this) {
68
68
  if (typeof b === 'number') {
69
69
  out[0] = this[0] - b;
70
70
  out[1] = this[1] - b;
@@ -81,10 +81,10 @@ var glmaths = (function (exports) {
81
81
  * Multiplies two vec3's
82
82
  *
83
83
  * @param {Number | Vec3} b the second operand
84
- * @param {Vec3} out the receiving vector, defaults to this
84
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
85
85
  * @returns {Vec3} out
86
86
  */
87
- mult(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
87
+ mult(b, out = index.ALWAYS_COPY ? vec3() : this) {
88
88
  if (typeof b === 'number') {
89
89
  out[0] = this[0] * b;
90
90
  out[1] = this[1] * b;
@@ -101,10 +101,10 @@ var glmaths = (function (exports) {
101
101
  * Divides two vec3's
102
102
  *
103
103
  * @param {Number | Vec3} b the second operand
104
- * @param {Vec3} out the receiving vector, defaults to this
104
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
105
105
  * @returns {Vec3} out
106
106
  */
107
- div(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
107
+ div(b, out = index.ALWAYS_COPY ? vec3() : this) {
108
108
  if (typeof b === 'number') {
109
109
  out[0] = this[0] / b;
110
110
  out[1] = this[1] / b;
@@ -117,7 +117,7 @@ var glmaths = (function (exports) {
117
117
  }
118
118
  return out;
119
119
  }
120
- invDiv(b, out = index.ALWAYS_COPY ? new Vec3() : this) {
120
+ invDiv(b, out = index.ALWAYS_COPY ? vec3() : this) {
121
121
  if (typeof b === 'number') {
122
122
  out[0] = b / this[0];
123
123
  out[1] = b / this[1];
@@ -131,18 +131,18 @@ var glmaths = (function (exports) {
131
131
  return out;
132
132
  }
133
133
  /**
134
- * Negates the components of a vec3
134
+ * Negates the components of this vec3
135
135
  *
136
- * @param {Vec3} out the receiving vector, defaults to this
136
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
137
137
  * @returns {Vec3} out
138
138
  */
139
- negate(out = index.ALWAYS_COPY ? new Vec3() : this) {
139
+ negate(out = index.ALWAYS_COPY ? vec3() : this) {
140
140
  out[0] = -this[0];
141
141
  out[1] = -this[1];
142
142
  out[2] = -this[2];
143
143
  return out;
144
144
  }
145
- unaryPlus(out = index.ALWAYS_COPY ? new Vec3() : this) {
145
+ unaryPlus(out = index.ALWAYS_COPY ? vec3() : this) {
146
146
  if (!out.equals(this)) {
147
147
  out[0] = this[0];
148
148
  out[1] = this[1];
@@ -151,13 +151,13 @@ var glmaths = (function (exports) {
151
151
  return out;
152
152
  }
153
153
  /**
154
- * Normalizes a vec3
154
+ * Normalizes vec3
155
155
  *
156
156
  * @param {Vec3} v the vector to normalize
157
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
157
+ * @param {Vec3} out the receiving vector, defaults to new vec3
158
158
  * @returns {Vec3} out
159
159
  */
160
- static normalize(v, out = new Vec3()) {
160
+ static normalize(v, out = vec3()) {
161
161
  const x = v[0], y = v[1], z = v[2];
162
162
  let len = x * x + y * y + z * z;
163
163
  if (len > 0)
@@ -168,12 +168,12 @@ var glmaths = (function (exports) {
168
168
  return out;
169
169
  }
170
170
  /**
171
- * Normalizes a vec3
171
+ * Normalizes this vec3
172
172
  *
173
- * @param {Vec3} out the receiving vector, defaults to this
173
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
174
174
  * @returns {Vec3} out
175
175
  */
176
- normalize(out = index.ALWAYS_COPY ? new Vec3() : this) {
176
+ normalize(out = index.ALWAYS_COPY ? vec3() : this) {
177
177
  const x = this[0], y = this[1], z = this[2];
178
178
  let len = x * x + y * y + z * z;
179
179
  if (len > 0)
@@ -204,7 +204,7 @@ var glmaths = (function (exports) {
204
204
  return this[0] === b[0] && this[1] === b[1] && this[2] === b[2];
205
205
  }
206
206
  /**
207
- * Calculates the squared length of a vec3
207
+ * Calculates the squared length of vec3
208
208
  *
209
209
  * @returns {Number} squared length of a vector
210
210
  */
@@ -213,7 +213,7 @@ var glmaths = (function (exports) {
213
213
  return x * x + y * y + z * z;
214
214
  }
215
215
  /**
216
- * Calculates the length of a vec3
216
+ * Calculates the length of vec3
217
217
  *
218
218
  * @returns {Number} length of a vector
219
219
  */
@@ -222,104 +222,104 @@ var glmaths = (function (exports) {
222
222
  return Math.sqrt(x * x + y * y + z * z);
223
223
  }
224
224
  /**
225
- * Returns a new vec3 with each component floored
225
+ * Returns vec3 with each component floored
226
226
  *
227
227
  * @param {Vec3} v the vector to floor
228
228
  * @returns {Vec3} a new floored vector
229
229
  */
230
- static floor(v, out = new Vec3()) {
230
+ static floor(v, out = vec3()) {
231
231
  out[0] = Math.floor(v[0]);
232
232
  out[1] = Math.floor(v[1]);
233
233
  out[2] = Math.floor(v[2]);
234
234
  return out;
235
235
  }
236
236
  /**
237
- * Returns a new vec3 with each component rounded
237
+ * Returns vec3 with each component rounded
238
238
  *
239
239
  * @param {Vec3} v the vector to round
240
240
  * @returns {Vec3} a new rounded vector
241
241
  */
242
- static round(v, out = new Vec3()) {
242
+ static round(v, out = vec3()) {
243
243
  out[0] = Math.round(v[0]);
244
244
  out[1] = Math.round(v[1]);
245
245
  out[2] = Math.round(v[2]);
246
246
  return out;
247
247
  }
248
248
  /**
249
- * Returns a new vec3 with each component ceiled
249
+ * Returns vec3 with each component ceiled
250
250
  *
251
251
  * @param {Vec3} v the vector to ceil
252
252
  * @returns {Vec3} a new ceiled vector
253
253
  */
254
- static ceil(v, out = new Vec3()) {
254
+ static ceil(v, out = vec3()) {
255
255
  out[0] = Math.ceil(v[0]);
256
256
  out[1] = Math.ceil(v[1]);
257
257
  out[2] = Math.ceil(v[2]);
258
258
  return out;
259
259
  }
260
260
  /**
261
- * Floors each component of a vec3
261
+ * Floors each component of vec3
262
262
  *
263
263
  * @returns {Vec3} this
264
264
  */
265
- floor(out = index.ALWAYS_COPY ? new Vec3() : this) {
265
+ floor(out = index.ALWAYS_COPY ? vec3() : this) {
266
266
  out[0] = Math.floor(this[0]);
267
267
  out[1] = Math.floor(this[1]);
268
268
  out[2] = Math.floor(this[2]);
269
269
  return out;
270
270
  }
271
271
  /**
272
- * Rounds each component of a vec3
272
+ * Rounds each component of vec3
273
273
  *
274
274
  * @returns {Vec3} this
275
275
  */
276
- round(out = index.ALWAYS_COPY ? new Vec3() : this) {
276
+ round(out = index.ALWAYS_COPY ? vec3() : this) {
277
277
  out[0] = Math.round(this[0]);
278
278
  out[1] = Math.round(this[1]);
279
279
  out[2] = Math.round(this[2]);
280
280
  return out;
281
281
  }
282
282
  /**
283
- * Ceils each component of a vec3
283
+ * Ceils each component of vec3
284
284
  *
285
285
  * @returns {Vec3} this
286
286
  */
287
- ceil(out = index.ALWAYS_COPY ? new Vec3() : this) {
287
+ ceil(out = index.ALWAYS_COPY ? vec3() : this) {
288
288
  out[0] = Math.ceil(this[0]);
289
289
  out[1] = Math.ceil(this[1]);
290
290
  out[2] = Math.ceil(this[2]);
291
291
  return out;
292
292
  }
293
293
  /**
294
- * Returns the inverse of a vec3
294
+ * Returns the inverse of vec3
295
295
  *
296
296
  * @param {Vec3} v the source vector
297
297
  * @returns {Vec3} a new inverted vector
298
298
  */
299
- static inverse(v, out = new Vec3()) {
299
+ static inverse(v, out = vec3()) {
300
300
  out[0] = 1.0 / v[0];
301
301
  out[1] = 1.0 / v[1];
302
302
  out[2] = 1.0 / v[2];
303
303
  return out;
304
304
  }
305
305
  /**
306
- * Inverts a vec3 component-wise
306
+ * Inverts vec3 component-wise
307
307
  *
308
308
  * @returns {Vec3} this
309
309
  */
310
- inverse(out = index.ALWAYS_COPY ? new Vec3() : this) {
310
+ inverse(out = index.ALWAYS_COPY ? vec3() : this) {
311
311
  out[0] = 1.0 / this[0];
312
312
  out[1] = 1.0 / this[1];
313
313
  out[2] = 1.0 / this[2];
314
314
  return out;
315
315
  }
316
316
  /**
317
- * Creates a new vec3 initialized with values from a vector
317
+ * Creates vec3 initialized with values from a vector
318
318
  *
319
- * @returns {Vec3} a new Vec3
319
+ * @returns {Vec3} vec3
320
320
  */
321
321
  clone() {
322
- return new Vec3(this[0], this[1], this[2]);
322
+ return vec3(this[0], this[1], this[2]);
323
323
  }
324
324
  /**
325
325
  * Returns a string representation of a vector
@@ -339,7 +339,7 @@ var glmaths = (function (exports) {
339
339
  const r = index.RANDOM() * 2.0 * Math.PI;
340
340
  const z = index.RANDOM() * 2.0 - 1.0;
341
341
  const zScale = Math.sqrt(1.0 - z * z) * scale;
342
- return new Vec3(Math.cos(r) * zScale, Math.sin(r) * zScale, z * scale);
342
+ return vec3(Math.cos(r) * zScale, Math.sin(r) * zScale, z * scale);
343
343
  }
344
344
  /**
345
345
  * Calculates the angle between two vec3's
@@ -370,10 +370,10 @@ var glmaths = (function (exports) {
370
370
  *
371
371
  * @param {Vec3} a the first operand
372
372
  * @param {Vec3} b the second operand
373
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
373
+ * @param {Vec3} out the receiving vector, defaults to new vec3
374
374
  * @returns {Vec3} out
375
375
  */
376
- static cross(a, b, out = new Vec3()) {
376
+ static cross(a, b, out = vec3()) {
377
377
  const ax = a[0], ay = a[1], az = a[2];
378
378
  const bx = b[0], by = b[1], bz = b[2];
379
379
  out[0] = ay * bz - az * by;
@@ -413,10 +413,10 @@ var glmaths = (function (exports) {
413
413
  * @param {Vec3} a the first operand
414
414
  * @param {Vec3} b the second operand
415
415
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
416
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
416
+ * @param {Vec3} out the receiving vector, defaults to new vec3
417
417
  * @returns {Vec3} out
418
418
  */
419
- static lerp(a, b, t, out = new Vec3()) {
419
+ static lerp(a, b, t, out = vec3()) {
420
420
  const ax = a[0], ay = a[1], az = a[2];
421
421
  out[0] = ax + (b[0] - ax) * t;
422
422
  out[1] = ay + (b[1] - ay) * t;
@@ -429,10 +429,10 @@ var glmaths = (function (exports) {
429
429
  * @param {Vec3} a the first operand
430
430
  * @param {Vec3} b the second operand
431
431
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
432
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
432
+ * @param {Vec3} out the receiving vector, defaults to new vec3
433
433
  * @returns {Vec3} out
434
434
  */
435
- static slerp(a, b, t, out = new Vec3()) {
435
+ static slerp(a, b, t, out = vec3()) {
436
436
  const angle = Math.acos(Math.min(Math.max(Vec3.dot(a, b), -1), 1));
437
437
  const sinTotal = Math.sin(angle);
438
438
  const ratioA = Math.sin((1 - t) * angle) / sinTotal;
@@ -449,7 +449,7 @@ var glmaths = (function (exports) {
449
449
  * @param {Vec3} b the second operand
450
450
  * @returns {Vec3} a new vector with the max components
451
451
  */
452
- static max(a, b, out = new Vec3()) {
452
+ static max(a, b, out = vec3()) {
453
453
  out[0] = Math.max(a[0], b[0]);
454
454
  out[1] = Math.max(a[1], b[1]);
455
455
  out[2] = Math.max(a[2], b[2]);
@@ -462,7 +462,7 @@ var glmaths = (function (exports) {
462
462
  * @param {Vec3} b the second operand
463
463
  * @returns {Vec3} a new vector with the min components
464
464
  */
465
- static min(a, b, out = new Vec3()) {
465
+ static min(a, b, out = vec3()) {
466
466
  out[0] = Math.min(a[0], b[0]);
467
467
  out[1] = Math.min(a[1], b[1]);
468
468
  out[2] = Math.min(a[2], b[2]);
@@ -477,7 +477,7 @@ var glmaths = (function (exports) {
477
477
  * @param {Vec3} out the receiving vector
478
478
  * @returns {Vec3} out
479
479
  */
480
- static clamp(v, min, max, out = new Vec3()) {
480
+ static clamp(v, min, max, out = vec3()) {
481
481
  const minX = typeof min === 'number' ? min : min[0];
482
482
  const minY = typeof min === 'number' ? min : min[1];
483
483
  const minZ = typeof min === 'number' ? min : min[2];
@@ -498,7 +498,7 @@ var glmaths = (function (exports) {
498
498
  * @param {Vec3} out the receiving vector
499
499
  * @returns {Vec3} out
500
500
  */
501
- static mix(a, b, t, out = new Vec3()) {
501
+ static mix(a, b, t, out = vec3()) {
502
502
  if (typeof t === 'number') {
503
503
  out[0] = a[0] + (b[0] - a[0]) * t;
504
504
  out[1] = a[1] + (b[1] - a[1]) * t;
@@ -520,7 +520,7 @@ var glmaths = (function (exports) {
520
520
  * @param {Vec3} out the receiving vector
521
521
  * @returns {Vec3} out
522
522
  */
523
- static smoothstep(edge0, edge1, v, out = new Vec3()) {
523
+ static smoothstep(edge0, edge1, v, out = vec3()) {
524
524
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
525
525
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
526
526
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -536,14 +536,14 @@ var glmaths = (function (exports) {
536
536
  return out;
537
537
  }
538
538
  /**
539
- * Rotates a vec3 around the X axis
539
+ * Rotates vec3 around the X axis
540
540
  *
541
541
  * @param {Vec3} v the vector to rotate
542
542
  * @param {Number} rad the angle of rotation in radians
543
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
543
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
544
544
  * @returns {Vec3} a new rotated vector
545
545
  */
546
- static rotateX(v, rad, origin = Vec3.zero, out = new Vec3()) {
546
+ static rotateX(v, rad, origin = vec3.zero, out = vec3()) {
547
547
  const p1 = v[1] - origin[1];
548
548
  const p2 = v[2] - origin[2];
549
549
  out[0] = v[0];
@@ -552,13 +552,13 @@ var glmaths = (function (exports) {
552
552
  return out;
553
553
  }
554
554
  /**
555
- * Rotates a vec3 around the X axis
555
+ * Rotates vec3 around the X axis
556
556
  *
557
557
  * @param {Number} rad the angle of rotation in radians
558
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
558
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
559
559
  * @returns {Vec3} a rotated vector
560
560
  */
561
- rotateX(rad, origin = Vec3.zero, out = index.ALWAYS_COPY ? new Vec3() : this) {
561
+ rotateX(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
562
562
  const p1 = this[1] - origin[1];
563
563
  const p2 = this[2] - origin[2];
564
564
  out[0] = this[0];
@@ -567,14 +567,14 @@ var glmaths = (function (exports) {
567
567
  return out;
568
568
  }
569
569
  /**
570
- * Rotates a vec3 around the Y axis
570
+ * Rotates vec3 around the Y axis
571
571
  *
572
572
  * @param {Vec3} v the vector to rotate
573
573
  * @param {Number} rad the angle of rotation in radians
574
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
574
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
575
575
  * @returns {Vec3} a rotated vector
576
576
  */
577
- static rotateY(v, rad, origin = Vec3.zero, out = new Vec3()) {
577
+ static rotateY(v, rad, origin = vec3.zero, out = vec3()) {
578
578
  const p0 = v[0] - origin[0];
579
579
  const p2 = v[2] - origin[2];
580
580
  out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0];
@@ -583,12 +583,12 @@ var glmaths = (function (exports) {
583
583
  return out;
584
584
  }
585
585
  /**
586
- * Rotates a vec3 around the Y axis
586
+ * Rotates vec3 around the Y axis
587
587
  *
588
588
  * @param {Number} rad the angle of rotation in radians
589
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
589
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
590
590
  */
591
- rotateY(rad, origin = Vec3.zero, out = index.ALWAYS_COPY ? new Vec3() : this) {
591
+ rotateY(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
592
592
  const p0 = this[0] - origin[0];
593
593
  const p2 = this[2] - origin[2];
594
594
  out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0];
@@ -597,14 +597,14 @@ var glmaths = (function (exports) {
597
597
  return out;
598
598
  }
599
599
  /**
600
- * Rotates a vec3 around the Z axis
600
+ * Rotates vec3 around the Z axis
601
601
  *
602
602
  * @param {Vec3} v the vector to rotate
603
603
  * @param {Number} rad the angle of rotation in radians
604
604
  * @param {Vec3} origin the origin of the rotation, defaults to ZERO
605
605
  * @returns {Vec3} a new rotated vector
606
606
  */
607
- static rotateZ(v, rad, origin = Vec3.zero, out = new Vec3()) {
607
+ static rotateZ(v, rad, origin = vec3.zero, out = vec3()) {
608
608
  const p0 = v[0] - origin[0];
609
609
  const p1 = v[1] - origin[1];
610
610
  out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0];
@@ -613,12 +613,12 @@ var glmaths = (function (exports) {
613
613
  return out;
614
614
  }
615
615
  /**
616
- * Rotates a vec3 around the Z axis
616
+ * Rotates vec3 around the Z axis
617
617
  *
618
618
  * @param {Number} rad the angle of rotation in radians
619
- * @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
619
+ * @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
620
620
  */
621
- rotateZ(rad, origin = Vec3.zero, out = index.ALWAYS_COPY ? new Vec3() : this) {
621
+ rotateZ(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
622
622
  const p0 = this[0] - origin[0];
623
623
  const p1 = this[1] - origin[1];
624
624
  out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0];
@@ -636,7 +636,7 @@ var glmaths = (function (exports) {
636
636
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
637
637
  * @returns {Vec3} a new vector
638
638
  */
639
- static hermite(a, b, c, d, t, out = new Vec3()) {
639
+ static hermite(a, b, c, d, t, out = vec3()) {
640
640
  const factorTimes2 = t * t;
641
641
  const factor1 = factorTimes2 * (2 * t - 3) + 1;
642
642
  const factor2 = factorTimes2 * (t - 2) + t;
@@ -657,7 +657,7 @@ var glmaths = (function (exports) {
657
657
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
658
658
  * @returns {Vec3} a new vector
659
659
  */
660
- static bezier(a, b, c, d, t, out = new Vec3()) {
660
+ static bezier(a, b, c, d, t, out = vec3()) {
661
661
  const inverseFactor = 1 - t;
662
662
  const inverseFactorTimesTwo = inverseFactor * inverseFactor;
663
663
  const factorTimes2 = t * t;
@@ -676,10 +676,10 @@ var glmaths = (function (exports) {
676
676
  * @param {Vec3} a the first operand
677
677
  * @param {Vec3} b the second operand
678
678
  * @param {Number} scale the amount to scale b by before adding
679
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
679
+ * @param {Vec3} out the receiving vector, defaults to new vec3
680
680
  * @returns {Vec3} out
681
681
  */
682
- static scaleAndAdd(a, b, scale, out = new Vec3()) {
682
+ static scaleAndAdd(a, b, scale, out = vec3()) {
683
683
  out[0] = a[0] + b[0] * scale;
684
684
  out[1] = a[1] + b[1] * scale;
685
685
  out[2] = a[2] + b[2] * scale;
@@ -690,10 +690,10 @@ var glmaths = (function (exports) {
690
690
  *
691
691
  * @param {Vec3} I the incident vector
692
692
  * @param {Vec3} N the surface normal
693
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
693
+ * @param {Vec3} out the receiving vector, defaults to new vec3
694
694
  * @returns {Vec3} out
695
695
  */
696
- static reflect(I, N, out = new Vec3()) {
696
+ static reflect(I, N, out = vec3()) {
697
697
  const d = Vec3.dot(N, I) * 2;
698
698
  out[0] = I[0] - d * N[0];
699
699
  out[1] = I[1] - d * N[1];
@@ -706,10 +706,10 @@ var glmaths = (function (exports) {
706
706
  * @param {Vec3} I the incident vector
707
707
  * @param {Vec3} N the surface normal
708
708
  * @param {Number} eta the ratio of indices of refraction
709
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
709
+ * @param {Vec3} out the receiving vector, defaults to new vec3
710
710
  * @returns {Vec3} out
711
711
  */
712
- static refract(I, N, eta, out = new Vec3()) {
712
+ static refract(I, N, eta, out = vec3()) {
713
713
  const d = Vec3.dot(N, I);
714
714
  const k = 1.0 - eta * eta * (1.0 - d * d);
715
715
  if (k < 0.0) {
@@ -728,10 +728,10 @@ var glmaths = (function (exports) {
728
728
  * @param {Vec3} N the vector to orient
729
729
  * @param {Vec3} I the incident vector
730
730
  * @param {Vec3} Nref the reference vector
731
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
731
+ * @param {Vec3} out the receiving vector, defaults to new vec3
732
732
  * @returns {Vec3} out
733
733
  */
734
- static faceforward(N, I, Nref, out = new Vec3()) {
734
+ static faceforward(N, I, Nref, out = vec3()) {
735
735
  const d = Vec3.dot(Nref, I);
736
736
  const sign = d < 0 ? 1 : -1;
737
737
  out[0] = N[0] * sign;
@@ -745,10 +745,10 @@ var glmaths = (function (exports) {
745
745
  * @param {Vec3} p1 the first vertex
746
746
  * @param {Vec3} p2 the second vertex
747
747
  * @param {Vec3} p3 the third vertex
748
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
748
+ * @param {Vec3} out the receiving vector, defaults to new vec3
749
749
  * @returns {Vec3} out
750
750
  */
751
- static triangleNormal(p1, p2, p3, out = new Vec3()) {
751
+ static triangleNormal(p1, p2, p3, out = vec3()) {
752
752
  const e1x = p2[0] - p1[0], e1y = p2[1] - p1[1], e1z = p2[2] - p1[2];
753
753
  const e2x = p3[0] - p1[0], e2y = p3[1] - p1[1], e2z = p3[2] - p1[2];
754
754
  out[0] = e1y * e2z - e1z * e2y;
@@ -768,10 +768,10 @@ var glmaths = (function (exports) {
768
768
  *
769
769
  * @param {Vec3} a the vector to project
770
770
  * @param {Vec3} b the vector to project onto
771
- * @param {Vec3} out the receiving vector, defaults to a new Vec3
771
+ * @param {Vec3} out the receiving vector, defaults to new vec3
772
772
  * @returns {Vec3} out
773
773
  */
774
- static project(a, b, out = new Vec3()) {
774
+ static project(a, b, out = vec3()) {
775
775
  const d = Vec3.dot(a, b) / Vec3.dot(b, b);
776
776
  out[0] = b[0] * d;
777
777
  out[1] = b[1] * d;
@@ -796,22 +796,22 @@ var glmaths = (function (exports) {
796
796
  *
797
797
  * @param {Vec3} b the second operand
798
798
  * @param {Number} scale the amount to scale b by before adding
799
- * @param {Vec3} out the receiving vector, defaults to this
799
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
800
800
  * @returns {Vec3} out
801
801
  */
802
- scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? new Vec3() : this) {
802
+ scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec3() : this) {
803
803
  out[0] = this[0] + b[0] * scale;
804
804
  out[1] = this[1] + b[1] * scale;
805
805
  out[2] = this[2] + b[2] * scale;
806
806
  return out;
807
807
  }
808
808
  /**
809
- * Returns a vec3 with each component set to its absolute value
809
+ * Returns vec3 with each component set to its absolute value
810
810
  *
811
- * @param {Vec3} out the receiving vector, defaults to this
811
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
812
812
  * @returns {Vec3} out
813
813
  */
814
- abs(out = index.ALWAYS_COPY ? new Vec3() : this) {
814
+ abs(out = index.ALWAYS_COPY ? vec3() : this) {
815
815
  out[0] = Math.abs(this[0]);
816
816
  out[1] = Math.abs(this[1]);
817
817
  out[2] = Math.abs(this[2]);
@@ -822,10 +822,10 @@ var glmaths = (function (exports) {
822
822
  *
823
823
  * @param {Vec3 | number} min the lower bound (per-component or scalar)
824
824
  * @param {Vec3 | number} max the upper bound (per-component or scalar)
825
- * @param {Vec3} out the receiving vector, defaults to this
825
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
826
826
  * @returns {Vec3} out
827
827
  */
828
- clamp(min, max, out = index.ALWAYS_COPY ? new Vec3() : this) {
828
+ clamp(min, max, out = index.ALWAYS_COPY ? vec3() : this) {
829
829
  const minX = typeof min === 'number' ? min : min[0];
830
830
  const minY = typeof min === 'number' ? min : min[1];
831
831
  const minZ = typeof min === 'number' ? min : min[2];
@@ -842,10 +842,10 @@ var glmaths = (function (exports) {
842
842
  *
843
843
  * @param {Vec3} b the second operand
844
844
  * @param {Vec3 | number} t interpolation amount (per-component or scalar)
845
- * @param {Vec3} out the receiving vector, defaults to this
845
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
846
846
  * @returns {Vec3} out
847
847
  */
848
- mix(b, t, out = index.ALWAYS_COPY ? new Vec3() : this) {
848
+ mix(b, t, out = index.ALWAYS_COPY ? vec3() : this) {
849
849
  if (typeof t === 'number') {
850
850
  out[0] = this[0] + (b[0] - this[0]) * t;
851
851
  out[1] = this[1] + (b[1] - this[1]) * t;
@@ -862,10 +862,10 @@ var glmaths = (function (exports) {
862
862
  * Generates a step function by comparing this vector to edge.
863
863
  *
864
864
  * @param {Vec3 | number} edge the edge value (per-component or scalar)
865
- * @param {Vec3} out the receiving vector, defaults to this
865
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
866
866
  * @returns {Vec3} out
867
867
  */
868
- step(edge, out = index.ALWAYS_COPY ? new Vec3() : this) {
868
+ step(edge, out = index.ALWAYS_COPY ? vec3() : this) {
869
869
  if (typeof edge === 'number') {
870
870
  out[0] = this[0] < edge ? 0 : 1;
871
871
  out[1] = this[1] < edge ? 0 : 1;
@@ -883,10 +883,10 @@ var glmaths = (function (exports) {
883
883
  *
884
884
  * @param {Vec3 | number} edge0 the lower edge (per-component or scalar)
885
885
  * @param {Vec3 | number} edge1 the upper edge (per-component or scalar)
886
- * @param {Vec3} out the receiving vector, defaults to this
886
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
887
887
  * @returns {Vec3} out
888
888
  */
889
- smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? new Vec3() : this) {
889
+ smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec3() : this) {
890
890
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
891
891
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
892
892
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -904,10 +904,10 @@ var glmaths = (function (exports) {
904
904
  /**
905
905
  * Returns the fractional part of each component.
906
906
  *
907
- * @param {Vec3} out the receiving vector, defaults to this
907
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
908
908
  * @returns {Vec3} out
909
909
  */
910
- fract(out = index.ALWAYS_COPY ? new Vec3() : this) {
910
+ fract(out = index.ALWAYS_COPY ? vec3() : this) {
911
911
  out[0] = this[0] - Math.floor(this[0]);
912
912
  out[1] = this[1] - Math.floor(this[1]);
913
913
  out[2] = this[2] - Math.floor(this[2]);
@@ -916,10 +916,10 @@ var glmaths = (function (exports) {
916
916
  /**
917
917
  * Returns the sign of each component (-1, 0, or 1).
918
918
  *
919
- * @param {Vec3} out the receiving vector, defaults to this
919
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
920
920
  * @returns {Vec3} out
921
921
  */
922
- sign(out = index.ALWAYS_COPY ? new Vec3() : this) {
922
+ sign(out = index.ALWAYS_COPY ? vec3() : this) {
923
923
  out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
924
924
  out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
925
925
  out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0;
@@ -928,10 +928,10 @@ var glmaths = (function (exports) {
928
928
  /**
929
929
  * Clamps each component to [0, 1].
930
930
  *
931
- * @param {Vec3} out the receiving vector, defaults to this
931
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
932
932
  * @returns {Vec3} out
933
933
  */
934
- saturate(out = index.ALWAYS_COPY ? new Vec3() : this) {
934
+ saturate(out = index.ALWAYS_COPY ? vec3() : this) {
935
935
  out[0] = Math.min(Math.max(this[0], 0), 1);
936
936
  out[1] = Math.min(Math.max(this[1], 0), 1);
937
937
  out[2] = Math.min(Math.max(this[2], 0), 1);
@@ -941,10 +941,10 @@ var glmaths = (function (exports) {
941
941
  * Transforms this vec3 with a Mat3
942
942
  *
943
943
  * @param {Mat3} m the 3x3 matrix to transform with
944
- * @param {Vec3} out the receiving vector, defaults to this
944
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
945
945
  * @returns {Vec3} out
946
946
  */
947
- transformMat3(m, out = index.ALWAYS_COPY ? new Vec3() : this) {
947
+ transformMat3(m, out = index.ALWAYS_COPY ? vec3() : this) {
948
948
  const x = this[0], y = this[1], z = this[2];
949
949
  out[0] = x * m[0] + y * m[3] + z * m[6];
950
950
  out[1] = x * m[1] + y * m[4] + z * m[7];
@@ -955,10 +955,10 @@ var glmaths = (function (exports) {
955
955
  * Transforms this vec3 with a Mat4 (as a point, w=1)
956
956
  *
957
957
  * @param {Mat4} m the 4x4 matrix to transform with
958
- * @param {Vec3} out the receiving vector, defaults to this
958
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
959
959
  * @returns {Vec3} out
960
960
  */
961
- transformMat4(m, out = index.ALWAYS_COPY ? new Vec3() : this) {
961
+ transformMat4(m, out = index.ALWAYS_COPY ? vec3() : this) {
962
962
  const x = this[0], y = this[1], z = this[2];
963
963
  let w = m[3] * x + m[7] * y + m[11] * z + m[15];
964
964
  w = w || 1.0;
@@ -971,10 +971,10 @@ var glmaths = (function (exports) {
971
971
  * Transforms this vec3 with a quaternion
972
972
  *
973
973
  * @param {Quat} q the quaternion to transform with
974
- * @param {Vec3} out the receiving vector, defaults to this
974
+ * @param {Vec3} out the receiving vector, defaults to new vec3()
975
975
  * @returns {Vec3} out
976
976
  */
977
- transformQuat(q, out = index.ALWAYS_COPY ? new Vec3() : this) {
977
+ transformQuat(q, out = index.ALWAYS_COPY ? vec3() : this) {
978
978
  const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
979
979
  const x = this[0], y = this[1], z = this[2];
980
980
  let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x;
@@ -1008,6 +1008,7 @@ var glmaths = (function (exports) {
1008
1008
  Vec3.prototype.unaryMinus = Vec3.prototype.negate;
1009
1009
  Vec3.prototype.sqrLen = Vec3.prototype.squaredLength;
1010
1010
  Vec3.prototype.str = Vec3.prototype.toString;
1011
+ Vec3.prototype.normalized = Vec3.prototype.normalize;
1011
1012
  Vec3.prototype.transformMat3x3 = Vec3.prototype.transformMat3;
1012
1013
  Vec3.prototype.transformMat4x4 = Vec3.prototype.transformMat4;
1013
1014
  const createVec3 = (...args) => {
@@ -1032,14 +1033,14 @@ var glmaths = (function (exports) {
1032
1033
  * @extends Float32Array
1033
1034
  */
1034
1035
  class Vec4 extends Float32Array {
1035
- static get zero() { return new Vec4(0, 0, 0, 0); }
1036
- static get Zero() { return new Vec4(0, 0, 0, 0); }
1037
- static get ZERO() { return new Vec4(0, 0, 0, 0); }
1038
- static get one() { return new Vec4(1, 1, 1, 1); }
1039
- static get One() { return new Vec4(1, 1, 1, 1); }
1040
- static get ONE() { return new Vec4(1, 1, 1, 1); }
1036
+ static get zero() { return vec4(0, 0, 0, 0); }
1037
+ static get Zero() { return vec4(0, 0, 0, 0); }
1038
+ static get ZERO() { return vec4(0, 0, 0, 0); }
1039
+ static get one() { return vec4(1, 1, 1, 1); }
1040
+ static get One() { return vec4(1, 1, 1, 1); }
1041
+ static get ONE() { return vec4(1, 1, 1, 1); }
1041
1042
  /**
1042
- * Creates a new Vec4
1043
+ * Creates a vec4
1043
1044
  *
1044
1045
  * @param {Number} x X component, defaults to 0
1045
1046
  * @param {Number} y Y component, defaults to 0
@@ -1065,10 +1066,10 @@ var glmaths = (function (exports) {
1065
1066
  * Adds two vec4's
1066
1067
  *
1067
1068
  * @param {Vec4 | Number} b the second operand
1068
- * @param {Vec4} out the receiving vector, defaults to this
1069
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1069
1070
  * @returns {Vec4} out
1070
1071
  */
1071
- plus(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1072
+ plus(b, out = index.ALWAYS_COPY ? vec4() : this) {
1072
1073
  if (typeof b === 'number') {
1073
1074
  out[0] = this[0] + b;
1074
1075
  out[1] = this[1] + b;
@@ -1087,10 +1088,10 @@ var glmaths = (function (exports) {
1087
1088
  * Subtracts two vec4's
1088
1089
  *
1089
1090
  * @param {Vec4 | Number} b the second operand
1090
- * @param {Vec4} out the receiving vector, defaults to this
1091
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1091
1092
  * @returns {Vec4} out
1092
1093
  */
1093
- minus(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1094
+ minus(b, out = index.ALWAYS_COPY ? vec4() : this) {
1094
1095
  if (typeof b === 'number') {
1095
1096
  out[0] = this[0] - b;
1096
1097
  out[1] = this[1] - b;
@@ -1109,10 +1110,10 @@ var glmaths = (function (exports) {
1109
1110
  * Multiplies two vec4's
1110
1111
  *
1111
1112
  * @param {Vec4 | Number} b the second operand
1112
- * @param {Vec4} out the receiving vector, defaults to this
1113
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1113
1114
  * @returns {Vec4} out
1114
1115
  */
1115
- mult(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1116
+ mult(b, out = index.ALWAYS_COPY ? vec4() : this) {
1116
1117
  if (typeof b === 'number') {
1117
1118
  out[0] = this[0] * b;
1118
1119
  out[1] = this[1] * b;
@@ -1131,10 +1132,10 @@ var glmaths = (function (exports) {
1131
1132
  * Divides two vec4's
1132
1133
  *
1133
1134
  * @param {Vec4 | Number} b the second operand
1134
- * @param {Vec4} out the receiving vector, defaults to this
1135
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1135
1136
  * @returns {Vec4} out
1136
1137
  */
1137
- div(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1138
+ div(b, out = index.ALWAYS_COPY ? vec4() : this) {
1138
1139
  if (typeof b === 'number') {
1139
1140
  out[0] = this[0] / b;
1140
1141
  out[1] = this[1] / b;
@@ -1149,7 +1150,7 @@ var glmaths = (function (exports) {
1149
1150
  }
1150
1151
  return out;
1151
1152
  }
1152
- invDiv(b, out = index.ALWAYS_COPY ? new Vec4() : this) {
1153
+ invDiv(b, out = index.ALWAYS_COPY ? vec4() : this) {
1153
1154
  if (typeof b === 'number') {
1154
1155
  out[0] = b / this[0];
1155
1156
  out[1] = b / this[1];
@@ -1167,17 +1168,17 @@ var glmaths = (function (exports) {
1167
1168
  /**
1168
1169
  * Negates the components of a vec4
1169
1170
  *
1170
- * @param {Vec4} out the receiving vector, defaults to this
1171
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1171
1172
  * @returns {Vec4} out
1172
1173
  */
1173
- negate(out = index.ALWAYS_COPY ? new Vec4() : this) {
1174
+ negate(out = index.ALWAYS_COPY ? vec4() : this) {
1174
1175
  out[0] = -this[0];
1175
1176
  out[1] = -this[1];
1176
1177
  out[2] = -this[2];
1177
1178
  out[3] = -this[3];
1178
1179
  return out;
1179
1180
  }
1180
- unaryPlus(out = index.ALWAYS_COPY ? new Vec4() : this) {
1181
+ unaryPlus(out = index.ALWAYS_COPY ? vec4() : this) {
1181
1182
  if (!out.equals(this)) {
1182
1183
  out[0] = this[0];
1183
1184
  out[1] = this[1];
@@ -1189,10 +1190,29 @@ var glmaths = (function (exports) {
1189
1190
  /**
1190
1191
  * Normalizes a vec4
1191
1192
  *
1192
- * @param {Vec4} out the receiving vector, defaults to this
1193
+ * @param {Vec4} v vector to normalize
1194
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1195
+ * @returns {Vec4} out
1196
+ */
1197
+ static normalize(v, out = vec4()) {
1198
+ const x = v[0], y = v[1], z = v[2], w = v[3];
1199
+ let len = x * x + y * y + z * z + w * w;
1200
+ if (len > 0) {
1201
+ len = 1.0 / Math.sqrt(len);
1202
+ }
1203
+ out[0] = x * len;
1204
+ out[1] = y * len;
1205
+ out[2] = z * len;
1206
+ out[3] = w * len;
1207
+ return out;
1208
+ }
1209
+ /**
1210
+ * Normalizes a vec4
1211
+ *
1212
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1193
1213
  * @returns {Vec4} out
1194
1214
  */
1195
- normalize(out = index.ALWAYS_COPY ? new Vec4() : this) {
1215
+ normalize(out = index.ALWAYS_COPY ? vec4() : this) {
1196
1216
  const x = this[0], y = this[1], z = this[2], w = this[3];
1197
1217
  let len = x * x + y * y + z * z + w * w;
1198
1218
  if (len > 0) {
@@ -1244,10 +1264,10 @@ var glmaths = (function (exports) {
1244
1264
  /**
1245
1265
  * Math.floor the components of a vec4
1246
1266
  *
1247
- * @param {Vec4} out the receiving vector, defaults to this
1267
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1248
1268
  * @returns {Vec4} out
1249
1269
  */
1250
- floor(out = index.ALWAYS_COPY ? new Vec4() : this) {
1270
+ floor(out = index.ALWAYS_COPY ? vec4() : this) {
1251
1271
  out[0] = Math.floor(this[0]);
1252
1272
  out[1] = Math.floor(this[1]);
1253
1273
  out[2] = Math.floor(this[2]);
@@ -1257,10 +1277,10 @@ var glmaths = (function (exports) {
1257
1277
  /**
1258
1278
  * Math.round the components of a vec4
1259
1279
  *
1260
- * @param {Vec4} out the receiving vector, defaults to this
1280
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1261
1281
  * @returns {Vec4} out
1262
1282
  */
1263
- round(out = index.ALWAYS_COPY ? new Vec4() : this) {
1283
+ round(out = index.ALWAYS_COPY ? vec4() : this) {
1264
1284
  out[0] = Math.round(this[0]);
1265
1285
  out[1] = Math.round(this[1]);
1266
1286
  out[2] = Math.round(this[2]);
@@ -1270,10 +1290,10 @@ var glmaths = (function (exports) {
1270
1290
  /**
1271
1291
  * Math.ceil the components of a vec4
1272
1292
  *
1273
- * @param {Vec4} out the receiving vector, defaults to this
1293
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1274
1294
  * @returns {Vec4} out
1275
1295
  */
1276
- ceil(out = index.ALWAYS_COPY ? new Vec4() : this) {
1296
+ ceil(out = index.ALWAYS_COPY ? vec4() : this) {
1277
1297
  out[0] = Math.ceil(this[0]);
1278
1298
  out[1] = Math.ceil(this[1]);
1279
1299
  out[2] = Math.ceil(this[2]);
@@ -1283,10 +1303,10 @@ var glmaths = (function (exports) {
1283
1303
  /**
1284
1304
  * Returns the inverse of the components of a vec4
1285
1305
  *
1286
- * @param {Vec4} out the receiving vector, defaults to this
1306
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1287
1307
  * @returns {Vec4} out
1288
1308
  */
1289
- inverse(out = index.ALWAYS_COPY ? new Vec4() : this) {
1309
+ inverse(out = index.ALWAYS_COPY ? vec4() : this) {
1290
1310
  out[0] = 1.0 / this[0];
1291
1311
  out[1] = 1.0 / this[1];
1292
1312
  out[2] = 1.0 / this[2];
@@ -1294,12 +1314,12 @@ var glmaths = (function (exports) {
1294
1314
  return out;
1295
1315
  }
1296
1316
  /**
1297
- * Creates a new vec4 initialized with values from a vector
1317
+ * Creates a vec4 initialized with values from a vector
1298
1318
  *
1299
- * @returns {Vec4} a new vec4
1319
+ * @returns {Vec4} a vec4
1300
1320
  */
1301
1321
  clone() {
1302
- return new Vec4(this[0], this[1], this[2], this[3]);
1322
+ return vec4(this[0], this[1], this[2], this[3]);
1303
1323
  }
1304
1324
  /**
1305
1325
  * Returns a string representation of a vec4
@@ -1313,10 +1333,10 @@ var glmaths = (function (exports) {
1313
1333
  * Generates a random vector with the given scale
1314
1334
  *
1315
1335
  * @param {Number} scale length of the resulting vector, defaults to 1.0
1316
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1336
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1317
1337
  * @returns {Vec4} out
1318
1338
  */
1319
- static random(scale = 1.0, out = new Vec4()) {
1339
+ static random(scale = 1.0, out = vec4()) {
1320
1340
  // Marsaglia, George. Choosing a Point from the Surface of a
1321
1341
  // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.
1322
1342
  // http://projecteuclid.org/euclid.aoms/1177692644;
@@ -1354,10 +1374,10 @@ var glmaths = (function (exports) {
1354
1374
  * @param {Vec4} u the first operand
1355
1375
  * @param {Vec4} v the second operand
1356
1376
  * @param {Vec4} w the third operand
1357
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1377
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1358
1378
  * @returns {Vec4} out
1359
1379
  */
1360
- static cross(u, v, w, out = new Vec4()) {
1380
+ static cross(u, v, w, out = vec4()) {
1361
1381
  const A = v[0] * w[1] - v[1] * w[0], B = v[0] * w[2] - v[2] * w[0], C = v[0] * w[3] - v[3] * w[0], D = v[1] * w[2] - v[2] * w[1], E = v[1] * w[3] - v[3] * w[1], F = v[2] * w[3] - v[3] * w[2];
1362
1382
  const G = u[0], H = u[1], I = u[2], J = u[3];
1363
1383
  out[0] = H * F - I * E + J * D;
@@ -1400,10 +1420,10 @@ var glmaths = (function (exports) {
1400
1420
  * @param {Vec4} a the first operand
1401
1421
  * @param {Vec4} b the second operand
1402
1422
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
1403
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1423
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1404
1424
  * @returns {Vec4} out
1405
1425
  */
1406
- static lerp(a, b, t, out = new Vec4()) {
1426
+ static lerp(a, b, t, out = vec4()) {
1407
1427
  const ax = a[0], ay = a[1], az = a[2], aw = a[3];
1408
1428
  out[0] = ax + (b[0] - ax) * t;
1409
1429
  out[1] = ay + (b[1] - ay) * t;
@@ -1416,10 +1436,10 @@ var glmaths = (function (exports) {
1416
1436
  *
1417
1437
  * @param {Vec4} a the first operand
1418
1438
  * @param {Vec4} b the second operand
1419
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1439
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1420
1440
  * @returns {Vec4} out
1421
1441
  */
1422
- static max(a, b, out = new Vec4()) {
1442
+ static max(a, b, out = vec4()) {
1423
1443
  out[0] = Math.max(a[0], b[0]);
1424
1444
  out[1] = Math.max(a[1], b[1]);
1425
1445
  out[2] = Math.max(a[2], b[2]);
@@ -1431,10 +1451,10 @@ var glmaths = (function (exports) {
1431
1451
  *
1432
1452
  * @param {Vec4} a the first operand
1433
1453
  * @param {Vec4} b the second operand
1434
- * @param {Vec4} out the receiving vector, defaults to new Vec4()
1454
+ * @param {Vec4} out the receiving vector, defaults to new vec4()
1435
1455
  * @returns {Vec4} out
1436
1456
  */
1437
- static min(a, b, out = new Vec4()) {
1457
+ static min(a, b, out = vec4()) {
1438
1458
  out[0] = Math.min(a[0], b[0]);
1439
1459
  out[1] = Math.min(a[1], b[1]);
1440
1460
  out[2] = Math.min(a[2], b[2]);
@@ -1450,7 +1470,7 @@ var glmaths = (function (exports) {
1450
1470
  * @param {Vec4} out the receiving vector
1451
1471
  * @returns {Vec4} out
1452
1472
  */
1453
- static clamp(v, min, max, out = new Vec4()) {
1473
+ static clamp(v, min, max, out = vec4()) {
1454
1474
  const minX = typeof min === 'number' ? min : min[0];
1455
1475
  const minY = typeof min === 'number' ? min : min[1];
1456
1476
  const minZ = typeof min === 'number' ? min : min[2];
@@ -1474,7 +1494,7 @@ var glmaths = (function (exports) {
1474
1494
  * @param {Vec4} out the receiving vector
1475
1495
  * @returns {Vec4} out
1476
1496
  */
1477
- static mix(a, b, t, out = new Vec4()) {
1497
+ static mix(a, b, t, out = vec4()) {
1478
1498
  if (typeof t === 'number') {
1479
1499
  out[0] = a[0] + (b[0] - a[0]) * t;
1480
1500
  out[1] = a[1] + (b[1] - a[1]) * t;
@@ -1498,7 +1518,7 @@ var glmaths = (function (exports) {
1498
1518
  * @param {Vec4} out the receiving vector
1499
1519
  * @returns {Vec4} out
1500
1520
  */
1501
- static smoothstep(edge0, edge1, v, out = new Vec4()) {
1521
+ static smoothstep(edge0, edge1, v, out = vec4()) {
1502
1522
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
1503
1523
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
1504
1524
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -1525,7 +1545,7 @@ var glmaths = (function (exports) {
1525
1545
  * @param {Vec4} out the receiving vector
1526
1546
  * @returns {Vec4} out
1527
1547
  */
1528
- scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? new Vec4() : this) {
1548
+ scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec4() : this) {
1529
1549
  out[0] = this[0] + b[0] * scale;
1530
1550
  out[1] = this[1] + b[1] * scale;
1531
1551
  out[2] = this[2] + b[2] * scale;
@@ -1538,7 +1558,7 @@ var glmaths = (function (exports) {
1538
1558
  * @param {Vec4} out the receiving vector
1539
1559
  * @returns {Vec4} out
1540
1560
  */
1541
- abs(out = index.ALWAYS_COPY ? new Vec4() : this) {
1561
+ abs(out = index.ALWAYS_COPY ? vec4() : this) {
1542
1562
  out[0] = Math.abs(this[0]);
1543
1563
  out[1] = Math.abs(this[1]);
1544
1564
  out[2] = Math.abs(this[2]);
@@ -1553,7 +1573,7 @@ var glmaths = (function (exports) {
1553
1573
  * @param {Vec4} out the receiving vector
1554
1574
  * @returns {Vec4} out
1555
1575
  */
1556
- clamp(min, max, out = index.ALWAYS_COPY ? new Vec4() : this) {
1576
+ clamp(min, max, out = index.ALWAYS_COPY ? vec4() : this) {
1557
1577
  const minX = typeof min === 'number' ? min : min[0];
1558
1578
  const minY = typeof min === 'number' ? min : min[1];
1559
1579
  const minZ = typeof min === 'number' ? min : min[2];
@@ -1576,7 +1596,7 @@ var glmaths = (function (exports) {
1576
1596
  * @param {Vec4} out the receiving vector
1577
1597
  * @returns {Vec4} out
1578
1598
  */
1579
- mix(b, t, out = index.ALWAYS_COPY ? new Vec4() : this) {
1599
+ mix(b, t, out = index.ALWAYS_COPY ? vec4() : this) {
1580
1600
  if (typeof t === 'number') {
1581
1601
  out[0] = this[0] + (b[0] - this[0]) * t;
1582
1602
  out[1] = this[1] + (b[1] - this[1]) * t;
@@ -1598,7 +1618,7 @@ var glmaths = (function (exports) {
1598
1618
  * @param {Vec4} out the receiving vector
1599
1619
  * @returns {Vec4} out
1600
1620
  */
1601
- step(edge, out = index.ALWAYS_COPY ? new Vec4() : this) {
1621
+ step(edge, out = index.ALWAYS_COPY ? vec4() : this) {
1602
1622
  if (typeof edge === 'number') {
1603
1623
  out[0] = this[0] < edge ? 0 : 1;
1604
1624
  out[1] = this[1] < edge ? 0 : 1;
@@ -1621,7 +1641,7 @@ var glmaths = (function (exports) {
1621
1641
  * @param {Vec4} out the receiving vector
1622
1642
  * @returns {Vec4} out
1623
1643
  */
1624
- smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? new Vec4() : this) {
1644
+ smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec4() : this) {
1625
1645
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
1626
1646
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
1627
1647
  const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
@@ -1646,7 +1666,7 @@ var glmaths = (function (exports) {
1646
1666
  * @param {Vec4} out the receiving vector
1647
1667
  * @returns {Vec4} out
1648
1668
  */
1649
- fract(out = index.ALWAYS_COPY ? new Vec4() : this) {
1669
+ fract(out = index.ALWAYS_COPY ? vec4() : this) {
1650
1670
  out[0] = this[0] - Math.floor(this[0]);
1651
1671
  out[1] = this[1] - Math.floor(this[1]);
1652
1672
  out[2] = this[2] - Math.floor(this[2]);
@@ -1659,7 +1679,7 @@ var glmaths = (function (exports) {
1659
1679
  * @param {Vec4} out the receiving vector
1660
1680
  * @returns {Vec4} out
1661
1681
  */
1662
- sign(out = index.ALWAYS_COPY ? new Vec4() : this) {
1682
+ sign(out = index.ALWAYS_COPY ? vec4() : this) {
1663
1683
  out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
1664
1684
  out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
1665
1685
  out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0;
@@ -1672,7 +1692,7 @@ var glmaths = (function (exports) {
1672
1692
  * @param {Vec4} out the receiving vector
1673
1693
  * @returns {Vec4} out
1674
1694
  */
1675
- saturate(out = index.ALWAYS_COPY ? new Vec4() : this) {
1695
+ saturate(out = index.ALWAYS_COPY ? vec4() : this) {
1676
1696
  out[0] = Math.min(Math.max(this[0], 0), 1);
1677
1697
  out[1] = Math.min(Math.max(this[1], 0), 1);
1678
1698
  out[2] = Math.min(Math.max(this[2], 0), 1);
@@ -1686,7 +1706,7 @@ var glmaths = (function (exports) {
1686
1706
  * @param {Vec4} out the receiving vector
1687
1707
  * @returns {Vec4} out
1688
1708
  */
1689
- transformMat4(m, out = index.ALWAYS_COPY ? new Vec4() : this) {
1709
+ transformMat4(m, out = index.ALWAYS_COPY ? vec4() : this) {
1690
1710
  const x = this[0], y = this[1], z = this[2], w = this[3];
1691
1711
  out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
1692
1712
  out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
@@ -1701,7 +1721,7 @@ var glmaths = (function (exports) {
1701
1721
  * @param {Vec4} out the receiving vector
1702
1722
  * @returns {Vec4} out
1703
1723
  */
1704
- transformQuat(q, out = index.ALWAYS_COPY ? new Vec4() : this) {
1724
+ transformQuat(q, out = index.ALWAYS_COPY ? vec4() : this) {
1705
1725
  const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
1706
1726
  const x = this[0], y = this[1], z = this[2];
1707
1727
  let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x;
@@ -1728,7 +1748,7 @@ var glmaths = (function (exports) {
1728
1748
  * @param {Vec4} out the receiving vector
1729
1749
  * @returns {Vec4} out
1730
1750
  */
1731
- static scaleAndAdd(a, b, scale, out = new Vec4()) {
1751
+ static scaleAndAdd(a, b, scale, out = vec4()) {
1732
1752
  out[0] = a[0] + b[0] * scale;
1733
1753
  out[1] = a[1] + b[1] * scale;
1734
1754
  out[2] = a[2] + b[2] * scale;
@@ -1752,6 +1772,7 @@ var glmaths = (function (exports) {
1752
1772
  Vec4.prototype.unaryMinus = Vec4.prototype.negate;
1753
1773
  Vec4.prototype.sqrLen = Vec4.prototype.squaredLength;
1754
1774
  Vec4.prototype.str = Vec4.prototype.toString;
1775
+ Vec4.prototype.normalized = Vec4.prototype.normalize;
1755
1776
  Vec4.prototype.transformMat4x4 = Vec4.prototype.transformMat4;
1756
1777
  const createVec4 = (...args) => {
1757
1778
  const out = new Vec4();
@@ -1837,12 +1858,12 @@ var glmaths = (function (exports) {
1837
1858
  * @extends Float32Array
1838
1859
  */
1839
1860
  class Vec2 extends Float32Array {
1840
- static get zero() { return new Vec2(0, 0); }
1841
- static get Zero() { return new Vec2(0, 0); }
1842
- static get ZERO() { return new Vec2(0, 0); }
1843
- static get one() { return new Vec2(1, 1); }
1844
- static get One() { return new Vec2(1, 1); }
1845
- static get ONE() { return new Vec2(1, 1); }
1861
+ static get zero() { return vec2(0, 0); }
1862
+ static get Zero() { return vec2(0, 0); }
1863
+ static get ZERO() { return vec2(0, 0); }
1864
+ static get one() { return vec2(1, 1); }
1865
+ static get One() { return vec2(1, 1); }
1866
+ static get ONE() { return vec2(1, 1); }
1846
1867
  /**
1847
1868
  * Creates a new Vec2 initialized with the given values
1848
1869
  *
@@ -1862,10 +1883,10 @@ var glmaths = (function (exports) {
1862
1883
  * Adds two vec2's
1863
1884
  *
1864
1885
  * @param {Vec2 | Number} b the second operand
1865
- * @param {Vec2} out the receiving vector, defaults to this
1886
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1866
1887
  * @returns {Vec2} out
1867
1888
  */
1868
- plus(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1889
+ plus(b, out = index.ALWAYS_COPY ? vec2() : this) {
1869
1890
  if (typeof b === 'number') {
1870
1891
  out[0] = this[0] + b;
1871
1892
  out[1] = this[1] + b;
@@ -1880,10 +1901,10 @@ var glmaths = (function (exports) {
1880
1901
  * Subtracts vector b from a vector
1881
1902
  *
1882
1903
  * @param {Vec2 | Number} b the second operand
1883
- * @param {Vec2} out the receiving vector, defaults to this
1904
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1884
1905
  * @returns {Vec2} out
1885
1906
  */
1886
- minus(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1907
+ minus(b, out = index.ALWAYS_COPY ? vec2() : this) {
1887
1908
  if (typeof b === 'number') {
1888
1909
  out[0] = this[0] - b;
1889
1910
  out[1] = this[1] - b;
@@ -1898,10 +1919,10 @@ var glmaths = (function (exports) {
1898
1919
  * Multiplies two vec2's component-wise
1899
1920
  *
1900
1921
  * @param {Vec2 | Number} b the second operand
1901
- * @param {Vec2} out the receiving vector, defaults to this
1922
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1902
1923
  * @returns {Vec2} out
1903
1924
  */
1904
- mult(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1925
+ mult(b, out = index.ALWAYS_COPY ? vec2() : this) {
1905
1926
  if (typeof b === 'number') {
1906
1927
  out[0] = this[0] * b;
1907
1928
  out[1] = this[1] * b;
@@ -1916,10 +1937,10 @@ var glmaths = (function (exports) {
1916
1937
  * Divides two vec2's component-wise
1917
1938
  *
1918
1939
  * @param {Vec2 | Number} b the second operand
1919
- * @param {Vec2} out the receiving vector, defaults to this
1940
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1920
1941
  * @returns {Vec2} out
1921
1942
  */
1922
- div(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1943
+ div(b, out = index.ALWAYS_COPY ? vec2() : this) {
1923
1944
  if (typeof b === 'number') {
1924
1945
  out[0] = this[0] / b;
1925
1946
  out[1] = this[1] / b;
@@ -1934,10 +1955,10 @@ var glmaths = (function (exports) {
1934
1955
  * Divides this vector by argument
1935
1956
  *
1936
1957
  * @param {Vec2 | Number} a the first operand
1937
- * @param {Vec2} out the receiving vector, defaults to this
1958
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1938
1959
  * @returns {Vec2} out
1939
1960
  */
1940
- invDiv(a, out = index.ALWAYS_COPY ? new Vec2() : this) {
1961
+ invDiv(a, out = index.ALWAYS_COPY ? vec2() : this) {
1941
1962
  if (typeof a === 'number') {
1942
1963
  out[0] = a / this[0];
1943
1964
  out[1] = a / this[1];
@@ -1952,10 +1973,10 @@ var glmaths = (function (exports) {
1952
1973
  * Remainder of this divided by argument
1953
1974
  *
1954
1975
  * @param {Vec2 | Number} a the first operand
1955
- * @param {Vec2} out the receiving vector, defaults to this
1976
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1956
1977
  * @returns {Vec2} out
1957
1978
  */
1958
- rem(b, out = index.ALWAYS_COPY ? new Vec2() : this) {
1979
+ rem(b, out = index.ALWAYS_COPY ? vec2() : this) {
1959
1980
  if (typeof b === 'number') {
1960
1981
  out[0] = this[0] % b;
1961
1982
  out[1] = this[1] % b;
@@ -1969,15 +1990,15 @@ var glmaths = (function (exports) {
1969
1990
  /**
1970
1991
  * Negates the components of a vec2
1971
1992
  *
1972
- * @param {Vec2} out the receiving vector, defaults to this
1993
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1973
1994
  * @returns {Vec2} out
1974
1995
  */
1975
- negate(out = index.ALWAYS_COPY ? new Vec2() : this) {
1996
+ negate(out = index.ALWAYS_COPY ? vec2() : this) {
1976
1997
  out[0] = -this[0];
1977
1998
  out[1] = -this[1];
1978
1999
  return out;
1979
2000
  }
1980
- unaryPlus(out = index.ALWAYS_COPY ? new Vec2() : this) {
2001
+ unaryPlus(out = index.ALWAYS_COPY ? vec2() : this) {
1981
2002
  if (!out.equals(this)) {
1982
2003
  out[0] = this[0];
1983
2004
  out[1] = this[1];
@@ -1985,11 +2006,28 @@ var glmaths = (function (exports) {
1985
2006
  return out;
1986
2007
  }
1987
2008
  /**
1988
- * Normalize a vector to unit length. Modifies in-place.
2009
+ * Normalize a vector to unit length.
1989
2010
  *
2011
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
1990
2012
  * @returns {Vec2} this
1991
2013
  */
1992
- normalize(out = index.ALWAYS_COPY ? new Vec2() : this) {
2014
+ static normalize(v, out = vec2()) {
2015
+ const x = v[0], y = v[1];
2016
+ let len = x * x + y * y;
2017
+ if (len > 0) {
2018
+ len = 1.0 / Math.sqrt(len);
2019
+ }
2020
+ out[0] = x * len;
2021
+ out[1] = y * len;
2022
+ return out;
2023
+ }
2024
+ /**
2025
+ * Normalize a vector to unit length.
2026
+ *
2027
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2028
+ * @returns {Vec2} this
2029
+ */
2030
+ normalize(out = index.ALWAYS_COPY ? vec2() : this) {
1993
2031
  const x = this[0], y = this[1];
1994
2032
  let len = x * x + y * y;
1995
2033
  if (len > 0) {
@@ -2039,10 +2077,10 @@ var glmaths = (function (exports) {
2039
2077
  /**
2040
2078
  * Math.floor the components of a vec2
2041
2079
  *
2042
- * @param {Vec2} out the receiving vector, defaults to this
2080
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2043
2081
  * @returns {Vec2} out
2044
2082
  */
2045
- floor(out = index.ALWAYS_COPY ? new Vec2() : this) {
2083
+ floor(out = index.ALWAYS_COPY ? vec2() : this) {
2046
2084
  out[0] = Math.floor(this[0]);
2047
2085
  out[1] = Math.floor(this[1]);
2048
2086
  return out;
@@ -2050,10 +2088,10 @@ var glmaths = (function (exports) {
2050
2088
  /**
2051
2089
  * Math.round the components of a vec2
2052
2090
  *
2053
- * @param {Vec2} out the receiving vector, defaults to this
2091
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2054
2092
  * @returns {Vec2} out
2055
2093
  */
2056
- round(out = index.ALWAYS_COPY ? new Vec2() : this) {
2094
+ round(out = index.ALWAYS_COPY ? vec2() : this) {
2057
2095
  out[0] = Math.round(this[0]);
2058
2096
  out[1] = Math.round(this[1]);
2059
2097
  return out;
@@ -2061,10 +2099,10 @@ var glmaths = (function (exports) {
2061
2099
  /**
2062
2100
  * Math.ceil the components of a vec2
2063
2101
  *
2064
- * @param {Vec2} out the receiving vector, defaults to this
2102
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2065
2103
  * @returns {Vec2} out
2066
2104
  */
2067
- ceil(out = index.ALWAYS_COPY ? new Vec2() : this) {
2105
+ ceil(out = index.ALWAYS_COPY ? vec2() : this) {
2068
2106
  out[0] = Math.ceil(this[0]);
2069
2107
  out[1] = Math.ceil(this[1]);
2070
2108
  return out;
@@ -2072,10 +2110,10 @@ var glmaths = (function (exports) {
2072
2110
  /**
2073
2111
  * Returns the inverse of the components (1/x, 1/y)
2074
2112
  *
2075
- * @param {Vec2} out the receiving vector, defaults to this
2113
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2076
2114
  * @returns {Vec2} out
2077
2115
  */
2078
- inverse(out = index.ALWAYS_COPY ? new Vec2() : this) {
2116
+ inverse(out = index.ALWAYS_COPY ? vec2() : this) {
2079
2117
  out[0] = 1.0 / this[0];
2080
2118
  out[1] = 1.0 / this[1];
2081
2119
  return out;
@@ -2085,16 +2123,16 @@ var glmaths = (function (exports) {
2085
2123
  *
2086
2124
  * @returns {Vec2} a new Vec2
2087
2125
  */
2088
- clone() { return new Vec2(this[0], this[1]); }
2126
+ clone() { return vec2(this[0], this[1]); }
2089
2127
  /**
2090
2128
  * Rotates a vec2 around an origin point
2091
2129
  *
2092
2130
  * @param {Number} rad the angle of rotation in radians
2093
- * @param {Vec2} origin the origin of the rotation, defaults to ZERO
2094
- * @param {Vec2} out the receiving vector, defaults to this
2131
+ * @param {Vec2} origin the origin of the rotation, defaults to vec2(0, 0)
2132
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2095
2133
  * @returns {Vec2} out
2096
2134
  */
2097
- rotate(rad = 0, origin = Vec2.ZERO, out = index.ALWAYS_COPY ? new Vec2() : this) {
2135
+ rotate(rad = 0, origin = vec2.zero, out = index.ALWAYS_COPY ? vec2() : this) {
2098
2136
  const p0 = this[0] - origin[0];
2099
2137
  const p1 = this[1] - origin[1];
2100
2138
  const sinC = Math.sin(rad);
@@ -2117,7 +2155,7 @@ var glmaths = (function (exports) {
2117
2155
  * @param {Number} scale length of the resulting vector, defaults to 1.0
2118
2156
  * @returns {Vec2} a new random Vec2
2119
2157
  */
2120
- static random(scale = 1.0, out = new Vec2()) {
2158
+ static random(scale = 1.0, out = vec2()) {
2121
2159
  const angleR = index.RANDOM() * 2.0 * Math.PI;
2122
2160
  out[0] = Math.cos(angleR) * scale;
2123
2161
  out[1] = Math.sin(angleR) * scale;
@@ -2211,7 +2249,7 @@ var glmaths = (function (exports) {
2211
2249
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
2212
2250
  * @returns {Vec2} a new interpolated Vec2
2213
2251
  */
2214
- static lerp(a, b, t, out = new Vec2()) {
2252
+ static lerp(a, b, t, out = vec2()) {
2215
2253
  const a0 = a[0], a1 = a[1];
2216
2254
  out[0] = a0 + (b[0] - a0) * t;
2217
2255
  out[1] = a1 + (b[1] - a1) * t;
@@ -2224,7 +2262,7 @@ var glmaths = (function (exports) {
2224
2262
  * @param {Vec2} b the second operand
2225
2263
  * @returns {Vec2} a new Vec2 with max components
2226
2264
  */
2227
- static max(a, b, out = new Vec2()) {
2265
+ static max(a, b, out = vec2()) {
2228
2266
  out[0] = Math.max(a[0], b[0]);
2229
2267
  out[1] = Math.max(a[1], b[1]);
2230
2268
  return out;
@@ -2236,7 +2274,7 @@ var glmaths = (function (exports) {
2236
2274
  * @param {Vec2} b the second operand
2237
2275
  * @returns {Vec2} a new Vec2 with min components
2238
2276
  */
2239
- static min(a, b, out = new Vec2()) {
2277
+ static min(a, b, out = vec2()) {
2240
2278
  out[0] = Math.min(a[0], b[0]);
2241
2279
  out[1] = Math.min(a[1], b[1]);
2242
2280
  return out;
@@ -2249,7 +2287,7 @@ var glmaths = (function (exports) {
2249
2287
  * @param {Vec2 | Number} max the upper bound
2250
2288
  * @returns {Vec2} a new clamped Vec2
2251
2289
  */
2252
- static clamp(v, min, max, out = new Vec2()) {
2290
+ static clamp(v, min, max, out = vec2()) {
2253
2291
  if (typeof min === 'number' && typeof max === 'number') {
2254
2292
  out[0] = Math.min(Math.max(v[0], min), max);
2255
2293
  out[1] = Math.min(Math.max(v[1], min), max);
@@ -2272,7 +2310,7 @@ var glmaths = (function (exports) {
2272
2310
  * @param {Vec2 | Number} t interpolation factor (scalar or per-component)
2273
2311
  * @returns {Vec2} a new interpolated Vec2
2274
2312
  */
2275
- static mix(a, b, t, out = new Vec2()) {
2313
+ static mix(a, b, t, out = vec2()) {
2276
2314
  if (typeof t === 'number') {
2277
2315
  out[0] = a[0] + (b[0] - a[0]) * t;
2278
2316
  out[1] = a[1] + (b[1] - a[1]) * t;
@@ -2291,7 +2329,7 @@ var glmaths = (function (exports) {
2291
2329
  * @param {Vec2} v the source vector
2292
2330
  * @returns {Vec2} a new smoothstepped Vec2
2293
2331
  */
2294
- static smoothstep(edge0, edge1, v, out = new Vec2()) {
2332
+ static smoothstep(edge0, edge1, v, out = vec2()) {
2295
2333
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
2296
2334
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
2297
2335
  const e1x = typeof edge1 === 'number' ? edge1 : edge1[0];
@@ -2307,10 +2345,10 @@ var glmaths = (function (exports) {
2307
2345
  *
2308
2346
  * @param {Vec2} b the second operand
2309
2347
  * @param {Number} scale the amount to scale b by before adding
2310
- * @param {Vec2} out the receiving vector, defaults to this
2348
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2311
2349
  * @returns {Vec2} out
2312
2350
  */
2313
- scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? new Vec2() : this) {
2351
+ scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec2() : this) {
2314
2352
  out[0] = this[0] + b[0] * scale;
2315
2353
  out[1] = this[1] + b[1] * scale;
2316
2354
  return out;
@@ -2318,10 +2356,10 @@ var glmaths = (function (exports) {
2318
2356
  /**
2319
2357
  * Component-wise absolute value
2320
2358
  *
2321
- * @param {Vec2} out the receiving vector, defaults to this
2359
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2322
2360
  * @returns {Vec2} out
2323
2361
  */
2324
- abs(out = index.ALWAYS_COPY ? new Vec2() : this) {
2362
+ abs(out = index.ALWAYS_COPY ? vec2() : this) {
2325
2363
  out[0] = Math.abs(this[0]);
2326
2364
  out[1] = Math.abs(this[1]);
2327
2365
  return out;
@@ -2329,10 +2367,10 @@ var glmaths = (function (exports) {
2329
2367
  /**
2330
2368
  * Component-wise sign
2331
2369
  *
2332
- * @param {Vec2} out the receiving vector, defaults to this
2370
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2333
2371
  * @returns {Vec2} out
2334
2372
  */
2335
- sign(out = index.ALWAYS_COPY ? new Vec2() : this) {
2373
+ sign(out = index.ALWAYS_COPY ? vec2() : this) {
2336
2374
  out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
2337
2375
  out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
2338
2376
  return out;
@@ -2340,10 +2378,10 @@ var glmaths = (function (exports) {
2340
2378
  /**
2341
2379
  * Component-wise fractional part (x - floor(x))
2342
2380
  *
2343
- * @param {Vec2} out the receiving vector, defaults to this
2381
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2344
2382
  * @returns {Vec2} out
2345
2383
  */
2346
- fract(out = index.ALWAYS_COPY ? new Vec2() : this) {
2384
+ fract(out = index.ALWAYS_COPY ? vec2() : this) {
2347
2385
  out[0] = this[0] - Math.floor(this[0]);
2348
2386
  out[1] = this[1] - Math.floor(this[1]);
2349
2387
  return out;
@@ -2353,10 +2391,10 @@ var glmaths = (function (exports) {
2353
2391
  *
2354
2392
  * @param {Vec2 | Number} min the lower bound
2355
2393
  * @param {Vec2 | Number} max the upper bound
2356
- * @param {Vec2} out the receiving vector, defaults to this
2394
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2357
2395
  * @returns {Vec2} out
2358
2396
  */
2359
- clamp(min, max, out = index.ALWAYS_COPY ? new Vec2() : this) {
2397
+ clamp(min, max, out = index.ALWAYS_COPY ? vec2() : this) {
2360
2398
  if (typeof min === 'number' && typeof max === 'number') {
2361
2399
  out[0] = Math.min(Math.max(this[0], min), max);
2362
2400
  out[1] = Math.min(Math.max(this[1], min), max);
@@ -2374,10 +2412,10 @@ var glmaths = (function (exports) {
2374
2412
  /**
2375
2413
  * Clamp components to [0, 1]
2376
2414
  *
2377
- * @param {Vec2} out the receiving vector, defaults to this
2415
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2378
2416
  * @returns {Vec2} out
2379
2417
  */
2380
- saturate(out = index.ALWAYS_COPY ? new Vec2() : this) {
2418
+ saturate(out = index.ALWAYS_COPY ? vec2() : this) {
2381
2419
  out[0] = Math.min(Math.max(this[0], 0), 1);
2382
2420
  out[1] = Math.min(Math.max(this[1], 0), 1);
2383
2421
  return out;
@@ -2387,10 +2425,10 @@ var glmaths = (function (exports) {
2387
2425
  *
2388
2426
  * @param {Vec2} b the second operand
2389
2427
  * @param {Vec2 | Number} t interpolation factor (scalar or per-component)
2390
- * @param {Vec2} out the receiving vector, defaults to this
2428
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2391
2429
  * @returns {Vec2} out
2392
2430
  */
2393
- mix(b, t, out = index.ALWAYS_COPY ? new Vec2() : this) {
2431
+ mix(b, t, out = index.ALWAYS_COPY ? vec2() : this) {
2394
2432
  if (typeof t === 'number') {
2395
2433
  out[0] = this[0] + (b[0] - this[0]) * t;
2396
2434
  out[1] = this[1] + (b[1] - this[1]) * t;
@@ -2405,10 +2443,10 @@ var glmaths = (function (exports) {
2405
2443
  * Component-wise step function
2406
2444
  *
2407
2445
  * @param {Vec2 | Number} edge the edge threshold
2408
- * @param {Vec2} out the receiving vector, defaults to this
2446
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2409
2447
  * @returns {Vec2} out
2410
2448
  */
2411
- step(edge, out = index.ALWAYS_COPY ? new Vec2() : this) {
2449
+ step(edge, out = index.ALWAYS_COPY ? vec2() : this) {
2412
2450
  if (typeof edge === 'number') {
2413
2451
  out[0] = this[0] < edge ? 0 : 1;
2414
2452
  out[1] = this[1] < edge ? 0 : 1;
@@ -2424,10 +2462,10 @@ var glmaths = (function (exports) {
2424
2462
  *
2425
2463
  * @param {Vec2 | Number} edge0 the lower edge
2426
2464
  * @param {Vec2 | Number} edge1 the upper edge
2427
- * @param {Vec2} out the receiving vector, defaults to this
2465
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2428
2466
  * @returns {Vec2} out
2429
2467
  */
2430
- smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? new Vec2() : this) {
2468
+ smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec2() : this) {
2431
2469
  const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
2432
2470
  const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
2433
2471
  const e1x = typeof edge1 === 'number' ? edge1 : edge1[0];
@@ -2442,10 +2480,10 @@ var glmaths = (function (exports) {
2442
2480
  * Transforms the vec2 with a Mat2 (column-major 2x2)
2443
2481
  *
2444
2482
  * @param {Mat2} m matrix to transform with
2445
- * @param {Vec2} out the receiving vector, defaults to this
2483
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2446
2484
  * @returns {Vec2} out
2447
2485
  */
2448
- transformMat2(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2486
+ transformMat2(m, out = index.ALWAYS_COPY ? vec2() : this) {
2449
2487
  const x = this[0], y = this[1];
2450
2488
  out[0] = m[0] * x + m[2] * y;
2451
2489
  out[1] = m[1] * x + m[3] * y;
@@ -2455,10 +2493,10 @@ var glmaths = (function (exports) {
2455
2493
  * Transforms the vec2 with a Mat2x3 (2D affine transform)
2456
2494
  *
2457
2495
  * @param {Mat2x3} m matrix to transform with
2458
- * @param {Vec2} out the receiving vector, defaults to this
2496
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2459
2497
  * @returns {Vec2} out
2460
2498
  */
2461
- transformMat2x3(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2499
+ transformMat2x3(m, out = index.ALWAYS_COPY ? vec2() : this) {
2462
2500
  const x = this[0], y = this[1];
2463
2501
  out[0] = m[0] * x + m[2] * y + m[4];
2464
2502
  out[1] = m[1] * x + m[3] * y + m[5];
@@ -2468,10 +2506,10 @@ var glmaths = (function (exports) {
2468
2506
  * Transforms the vec2 with a Mat3 (column-major 3x3)
2469
2507
  *
2470
2508
  * @param {Mat3} m matrix to transform with
2471
- * @param {Vec2} out the receiving vector, defaults to this
2509
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2472
2510
  * @returns {Vec2} out
2473
2511
  */
2474
- transformMat3(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2512
+ transformMat3(m, out = index.ALWAYS_COPY ? vec2() : this) {
2475
2513
  const x = this[0], y = this[1];
2476
2514
  out[0] = m[0] * x + m[3] * y + m[6];
2477
2515
  out[1] = m[1] * x + m[4] * y + m[7];
@@ -2481,10 +2519,10 @@ var glmaths = (function (exports) {
2481
2519
  * Transforms the vec2 with a Mat4 (column-major 4x4)
2482
2520
  *
2483
2521
  * @param {Mat4} m matrix to transform with
2484
- * @param {Vec2} out the receiving vector, defaults to this
2522
+ * @param {Vec2} out the receiving vector, defaults to new vec2()
2485
2523
  * @returns {Vec2} out
2486
2524
  */
2487
- transformMat4(m, out = index.ALWAYS_COPY ? new Vec2() : this) {
2525
+ transformMat4(m, out = index.ALWAYS_COPY ? vec2() : this) {
2488
2526
  const x = this[0], y = this[1];
2489
2527
  out[0] = m[0] * x + m[4] * y + m[12];
2490
2528
  out[1] = m[1] * x + m[5] * y + m[13];
@@ -2499,7 +2537,7 @@ var glmaths = (function (exports) {
2499
2537
  * @param {Vec2} out the receiving vector
2500
2538
  * @returns {Vec2} out
2501
2539
  */
2502
- static scaleAndAdd(a, b, scale, out = new Vec2()) {
2540
+ static scaleAndAdd(a, b, scale, out = vec2()) {
2503
2541
  out[0] = a[0] + b[0] * scale;
2504
2542
  out[1] = a[1] + b[1] * scale;
2505
2543
  return out;
@@ -2512,7 +2550,7 @@ var glmaths = (function (exports) {
2512
2550
  * @param {Vec2} out the receiving vector
2513
2551
  * @returns {Vec2} out
2514
2552
  */
2515
- static reflect(I, N, out = new Vec2()) {
2553
+ static reflect(I, N, out = vec2()) {
2516
2554
  const d = Vec2.dot(N, I);
2517
2555
  out[0] = I[0] - 2 * d * N[0];
2518
2556
  out[1] = I[1] - 2 * d * N[1];
@@ -2536,6 +2574,7 @@ var glmaths = (function (exports) {
2536
2574
  Vec2.prototype.sqrLen = Vec2.prototype.squaredLength;
2537
2575
  Vec2.prototype.str = Vec2.prototype.toString;
2538
2576
  Vec2.prototype.lerpV = Vec2.prototype.mix;
2577
+ Vec2.prototype.normalized = Vec2.prototype.normalize;
2539
2578
  Vec2.prototype.transformMat2x2 = Vec2.prototype.transformMat2;
2540
2579
  Vec2.prototype.transformMat2d = Vec2.prototype.transformMat2x3;
2541
2580
  Vec2.prototype.transformMat3x3 = Vec2.prototype.transformMat3;
@@ -2562,9 +2601,9 @@ var glmaths = (function (exports) {
2562
2601
  * @extends Float32Array
2563
2602
  */
2564
2603
  class Mat3 extends Float32Array {
2565
- static get identity() { return new Mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2566
- static get Identity() { return new Mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2567
- static get IDENTITY() { return new Mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2604
+ static get identity() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2605
+ static get Identity() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2606
+ static get IDENTITY() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
2568
2607
  /**
2569
2608
  * Create a new mat3 with the given values
2570
2609
  *
@@ -2596,15 +2635,15 @@ var glmaths = (function (exports) {
2596
2635
  * @returns {Mat3} a new Mat3
2597
2636
  */
2598
2637
  clone() {
2599
- return new Mat3(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8]);
2638
+ return mat3(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8]);
2600
2639
  }
2601
2640
  /**
2602
2641
  * Transposes a mat3
2603
2642
  *
2604
- * @param {Mat3} out the receiving matrix, defaults to this
2643
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2605
2644
  * @returns {Mat3} out
2606
2645
  */
2607
- transpose(out = index.ALWAYS_COPY ? new Mat3() : this) {
2646
+ transpose(out = index.ALWAYS_COPY ? mat3() : this) {
2608
2647
  if (out.exactEquals(this)) {
2609
2648
  const a01 = this[1], a02 = this[2], a12 = this[5];
2610
2649
  out[1] = this[3];
@@ -2630,10 +2669,10 @@ var glmaths = (function (exports) {
2630
2669
  /**
2631
2670
  * Inverts a mat3
2632
2671
  *
2633
- * @param {Mat3} out the receiving matrix, defaults to this
2672
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2634
2673
  * @returns {Mat3|null} out, or null if not invertible
2635
2674
  */
2636
- invert(out = index.ALWAYS_COPY ? new Mat3() : this) {
2675
+ invert(out = index.ALWAYS_COPY ? mat3() : this) {
2637
2676
  const a00 = this[0], a01 = this[1], a02 = this[2];
2638
2677
  const a10 = this[3], a11 = this[4], a12 = this[5];
2639
2678
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2658,10 +2697,10 @@ var glmaths = (function (exports) {
2658
2697
  /**
2659
2698
  * Calculates the adjugate of a mat3
2660
2699
  *
2661
- * @param {Mat3} out the receiving matrix, defaults to this
2700
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2662
2701
  * @returns {Mat3} out
2663
2702
  */
2664
- adjoint(out = index.ALWAYS_COPY ? new Mat3() : this) {
2703
+ adjoint(out = index.ALWAYS_COPY ? mat3() : this) {
2665
2704
  const a00 = this[0], a01 = this[1], a02 = this[2];
2666
2705
  const a10 = this[3], a11 = this[4], a12 = this[5];
2667
2706
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2687,7 +2726,7 @@ var glmaths = (function (exports) {
2687
2726
  const a20 = this[6], a21 = this[7], a22 = this[8];
2688
2727
  return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
2689
2728
  }
2690
- multiply(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
2729
+ multiply(b, out = index.ALWAYS_COPY ? mat3() : this) {
2691
2730
  if (b instanceof Vec2)
2692
2731
  return b.transformMat3(this);
2693
2732
  if (b instanceof Vec3)
@@ -2713,10 +2752,10 @@ var glmaths = (function (exports) {
2713
2752
  * Translates a mat3 by the given vector
2714
2753
  *
2715
2754
  * @param {Vec2} v vector to translate by
2716
- * @param {Mat3} out the receiving matrix, defaults to this
2755
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2717
2756
  * @returns {Mat3} out
2718
2757
  */
2719
- translate(v, out = index.ALWAYS_COPY ? new Mat3() : this) {
2758
+ translate(v, out = index.ALWAYS_COPY ? mat3() : this) {
2720
2759
  const a00 = this[0], a01 = this[1], a02 = this[2];
2721
2760
  const a10 = this[3], a11 = this[4], a12 = this[5];
2722
2761
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2736,10 +2775,10 @@ var glmaths = (function (exports) {
2736
2775
  * Rotates a mat3 by the given angle
2737
2776
  *
2738
2777
  * @param {Number} rad the angle to rotate the matrix by
2739
- * @param {Mat3} out the receiving matrix, defaults to this
2778
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2740
2779
  * @returns {Mat3} out
2741
2780
  */
2742
- rotate(rad, out = index.ALWAYS_COPY ? new Mat3() : this) {
2781
+ rotate(rad, out = index.ALWAYS_COPY ? mat3() : this) {
2743
2782
  const a00 = this[0], a01 = this[1], a02 = this[2];
2744
2783
  const a10 = this[3], a11 = this[4], a12 = this[5];
2745
2784
  const a20 = this[6], a21 = this[7], a22 = this[8];
@@ -2759,10 +2798,10 @@ var glmaths = (function (exports) {
2759
2798
  * Scales a mat3 by the given vector
2760
2799
  *
2761
2800
  * @param {Vec2} v the vector to scale by
2762
- * @param {Mat3} out the receiving matrix, defaults to this
2801
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2763
2802
  * @returns {Mat3} out
2764
2803
  */
2765
- scale(v, out = index.ALWAYS_COPY ? new Mat3() : this) {
2804
+ scale(v, out = index.ALWAYS_COPY ? mat3() : this) {
2766
2805
  const x = v[0], y = v[1];
2767
2806
  out[0] = x * this[0];
2768
2807
  out[1] = x * this[1];
@@ -2779,10 +2818,10 @@ var glmaths = (function (exports) {
2779
2818
  * Creates a matrix from a translation vector
2780
2819
  *
2781
2820
  * @param {Vec2} v translation vector
2782
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2821
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2783
2822
  * @returns {Mat3} out
2784
2823
  */
2785
- static fromTranslation(v, out = new Mat3()) {
2824
+ static fromTranslation(v, out = mat3()) {
2786
2825
  out[0] = 1;
2787
2826
  out[1] = 0;
2788
2827
  out[2] = 0;
@@ -2798,10 +2837,10 @@ var glmaths = (function (exports) {
2798
2837
  * Creates a matrix from a given angle
2799
2838
  *
2800
2839
  * @param {Number} rad the angle to rotate the matrix by
2801
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2840
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2802
2841
  * @returns {Mat3} out
2803
2842
  */
2804
- static fromRotation(rad, out = new Mat3()) {
2843
+ static fromRotation(rad, out = mat3()) {
2805
2844
  const s = Math.sin(rad), c = Math.cos(rad);
2806
2845
  out[0] = c;
2807
2846
  out[1] = s;
@@ -2818,10 +2857,10 @@ var glmaths = (function (exports) {
2818
2857
  * Creates a matrix from a scaling vector
2819
2858
  *
2820
2859
  * @param {Vec2} v scaling vector
2821
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2860
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2822
2861
  * @returns {Mat3} out
2823
2862
  */
2824
- static fromScaling(v, out = new Mat3()) {
2863
+ static fromScaling(v, out = mat3()) {
2825
2864
  out[0] = v[0];
2826
2865
  out[1] = 0;
2827
2866
  out[2] = 0;
@@ -2837,10 +2876,10 @@ var glmaths = (function (exports) {
2837
2876
  * Creates a mat3 from a Mat2x3
2838
2877
  *
2839
2878
  * @param {Mat2x3} a the Mat2x3 to convert
2840
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2879
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2841
2880
  * @returns {Mat3} out
2842
2881
  */
2843
- static fromMat2x3(a, out = new Mat3()) {
2882
+ static fromMat2x3(a, out = mat3()) {
2844
2883
  out[0] = a[0];
2845
2884
  out[1] = a[1];
2846
2885
  out[2] = 0;
@@ -2856,10 +2895,10 @@ var glmaths = (function (exports) {
2856
2895
  * Calculates a mat3 from the given quaternion
2857
2896
  *
2858
2897
  * @param {Quat} q quaternion to create matrix from
2859
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2898
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2860
2899
  * @returns {Mat3} out
2861
2900
  */
2862
- static fromQuat(q, out = new Mat3()) {
2901
+ static fromQuat(q, out = mat3()) {
2863
2902
  const x = q[0], y = q[1], z = q[2], w = q[3];
2864
2903
  const x2 = x + x, y2 = y + y, z2 = z + z;
2865
2904
  const xx = x * x2, yx = y * x2, yy = y * y2;
@@ -2880,10 +2919,10 @@ var glmaths = (function (exports) {
2880
2919
  * Calculates a mat3 normal matrix (transpose inverse) from a mat4
2881
2920
  *
2882
2921
  * @param {Mat4} a the source mat4 to derive the normal matrix from
2883
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2922
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2884
2923
  * @returns {Mat3|null} out, or null if not invertible
2885
2924
  */
2886
- static normalFromMat4(a, out = new Mat3()) {
2925
+ static normalFromMat4(a, out = mat3()) {
2887
2926
  const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
2888
2927
  const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
2889
2928
  const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
@@ -2919,10 +2958,10 @@ var glmaths = (function (exports) {
2919
2958
  * Copies the upper-left 3x3 values of a mat4 into a mat3
2920
2959
  *
2921
2960
  * @param {Mat4} a the source mat4
2922
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2961
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2923
2962
  * @returns {Mat3} out
2924
2963
  */
2925
- static fromMat4(a, out = new Mat3()) {
2964
+ static fromMat4(a, out = mat3()) {
2926
2965
  out[0] = a[0];
2927
2966
  out[1] = a[1];
2928
2967
  out[2] = a[2];
@@ -2939,10 +2978,10 @@ var glmaths = (function (exports) {
2939
2978
  *
2940
2979
  * @param {Number} width width of the projection
2941
2980
  * @param {Number} height height of the projection
2942
- * @param {Mat3} out the receiving matrix, defaults to new Mat3()
2981
+ * @param {Mat3} out the receiving matrix, defaults to mat3()
2943
2982
  * @returns {Mat3} out
2944
2983
  */
2945
- static projection(width, height, out = new Mat3()) {
2984
+ static projection(width, height, out = mat3()) {
2946
2985
  out[0] = 2 / width;
2947
2986
  out[1] = 0;
2948
2987
  out[2] = 0;
@@ -2968,10 +3007,10 @@ var glmaths = (function (exports) {
2968
3007
  * Adds two mat3's
2969
3008
  *
2970
3009
  * @param {Mat3} b the second operand
2971
- * @param {Mat3} out the receiving matrix, defaults to this
3010
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2972
3011
  * @returns {Mat3} out
2973
3012
  */
2974
- plus(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
3013
+ plus(b, out = index.ALWAYS_COPY ? mat3() : this) {
2975
3014
  out[0] = this[0] + b[0];
2976
3015
  out[1] = this[1] + b[1];
2977
3016
  out[2] = this[2] + b[2];
@@ -2987,10 +3026,10 @@ var glmaths = (function (exports) {
2987
3026
  * Subtracts matrix b from this
2988
3027
  *
2989
3028
  * @param {Mat3} b the second operand
2990
- * @param {Mat3} out the receiving matrix, defaults to this
3029
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
2991
3030
  * @returns {Mat3} out
2992
3031
  */
2993
- minus(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
3032
+ minus(b, out = index.ALWAYS_COPY ? mat3() : this) {
2994
3033
  out[0] = this[0] - b[0];
2995
3034
  out[1] = this[1] - b[1];
2996
3035
  out[2] = this[2] - b[2];
@@ -3006,10 +3045,10 @@ var glmaths = (function (exports) {
3006
3045
  * Multiplies each element of a mat3 by a scalar number
3007
3046
  *
3008
3047
  * @param {Number} b amount to scale the matrix's elements by
3009
- * @param {Mat3} out the receiving matrix, defaults to this
3048
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
3010
3049
  * @returns {Mat3} out
3011
3050
  */
3012
- scaleScalar(b, out = index.ALWAYS_COPY ? new Mat3() : this) {
3051
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat3() : this) {
3013
3052
  out[0] = this[0] * b;
3014
3053
  out[1] = this[1] * b;
3015
3054
  out[2] = this[2] * b;
@@ -3026,10 +3065,10 @@ var glmaths = (function (exports) {
3026
3065
  *
3027
3066
  * @param {Mat3} b the second operand
3028
3067
  * @param {Number} scale the amount to scale b's elements by before adding
3029
- * @param {Mat3} out the receiving matrix, defaults to this
3068
+ * @param {Mat3} out the receiving matrix, defaults to new mat3()
3030
3069
  * @returns {Mat3} out
3031
3070
  */
3032
- multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? new Mat3() : this) {
3071
+ multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? mat3() : this) {
3033
3072
  out[0] = this[0] + b[0] * scale;
3034
3073
  out[1] = this[1] + b[1] * scale;
3035
3074
  out[2] = this[2] + b[2] * scale;
@@ -3089,7 +3128,7 @@ var glmaths = (function (exports) {
3089
3128
  Mat3.prototype.times = Mat3.prototype.multiply;
3090
3129
  Mat3.prototype.str = Mat3.prototype.toString;
3091
3130
  Mat3.prototype.multiplyScalar = Mat3.prototype.scaleScalar;
3092
- const mat3 = Object.assign((...args) => {
3131
+ const createMat3 = (...args) => {
3093
3132
  const out = new Mat3();
3094
3133
  let i = 0;
3095
3134
  for (const a of args) {
@@ -3100,7 +3139,9 @@ var glmaths = (function (exports) {
3100
3139
  out[i++] = v;
3101
3140
  }
3102
3141
  return out;
3103
- }, Mat3);
3142
+ };
3143
+ Object.setPrototypeOf(createMat3, Mat3);
3144
+ const mat3 = createMat3;
3104
3145
  const mat3x3 = mat3;
3105
3146
 
3106
3147
  var _a;
@@ -3109,9 +3150,9 @@ var glmaths = (function (exports) {
3109
3150
  * @extends Float32Array
3110
3151
  */
3111
3152
  class Mat4 extends Float32Array {
3112
- static get identity() { return new _a(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3113
- static get Identity() { return new _a(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3114
- static get IDENTITY() { return new _a(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3153
+ static get identity() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3154
+ static get Identity() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3155
+ static get IDENTITY() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
3115
3156
  /**
3116
3157
  * Creates a new 4x4 matrix
3117
3158
  *
@@ -3157,15 +3198,15 @@ var glmaths = (function (exports) {
3157
3198
  * @returns {Mat4} a new 4x4 matrix
3158
3199
  */
3159
3200
  clone() {
3160
- return new _a(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8], this[9], this[10], this[11], this[12], this[13], this[14], this[15]);
3201
+ return mat4(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8], this[9], this[10], this[11], this[12], this[13], this[14], this[15]);
3161
3202
  }
3162
3203
  /**
3163
3204
  * Transposes a mat4
3164
3205
  *
3165
- * @param {Mat4} out the receiving matrix, defaults to this
3206
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3166
3207
  * @returns {Mat4} out
3167
3208
  */
3168
- transpose(out = index.ALWAYS_COPY ? new _a() : this) {
3209
+ transpose(out = index.ALWAYS_COPY ? mat4() : this) {
3169
3210
  if (out.exactEquals(this)) {
3170
3211
  const a01 = this[1], a02 = this[2], a03 = this[3];
3171
3212
  const a12 = this[6], a13 = this[7], a23 = this[11];
@@ -3205,10 +3246,10 @@ var glmaths = (function (exports) {
3205
3246
  /**
3206
3247
  * Inverts a mat4
3207
3248
  *
3208
- * @param {Mat4} out the receiving matrix, defaults to this
3249
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3209
3250
  * @returns {Mat4} out
3210
3251
  */
3211
- invert(out = index.ALWAYS_COPY ? new _a() : this) {
3252
+ invert(out = index.ALWAYS_COPY ? mat4() : this) {
3212
3253
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3213
3254
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
3214
3255
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3250,10 +3291,10 @@ var glmaths = (function (exports) {
3250
3291
  /**
3251
3292
  * Calculates the adjugate of a mat4
3252
3293
  *
3253
- * @param {Mat4} out the receiving matrix, defaults to this
3294
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3254
3295
  * @returns {Mat4} out
3255
3296
  */
3256
- adjoint(out = index.ALWAYS_COPY ? new _a() : this) {
3297
+ adjoint(out = index.ALWAYS_COPY ? mat4() : this) {
3257
3298
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3258
3299
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
3259
3300
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3305,7 +3346,7 @@ var glmaths = (function (exports) {
3305
3346
  (a01 * a13 - a03 * a11) * (a20 * a32 - a22 * a30) +
3306
3347
  (a02 * a13 - a03 * a12) * (a20 * a31 - a21 * a30));
3307
3348
  }
3308
- multiply(b, out = index.ALWAYS_COPY ? new _a() : this) {
3349
+ multiply(b, out = index.ALWAYS_COPY ? mat4() : this) {
3309
3350
  if (b instanceof Vec2)
3310
3351
  return b.transformMat4(this);
3311
3352
  if (b instanceof Vec3)
@@ -3351,10 +3392,10 @@ var glmaths = (function (exports) {
3351
3392
  * Translates a mat4 by the given Vec3
3352
3393
  *
3353
3394
  * @param {Vec3} v vector to translate by
3354
- * @param {Mat4} out the receiving matrix, defaults to this
3395
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3355
3396
  * @returns {Mat4} out
3356
3397
  */
3357
- translate(v, out = index.ALWAYS_COPY ? new _a() : this) {
3398
+ translate(v, out = index.ALWAYS_COPY ? mat4() : this) {
3358
3399
  const x = v[0], y = v[1], z = v[2];
3359
3400
  if (out.exactEquals(this)) {
3360
3401
  out[12] = this[0] * x + this[4] * y + this[8] * z + this[12];
@@ -3389,10 +3430,10 @@ var glmaths = (function (exports) {
3389
3430
  * Scales a mat4 by the dimensions in the given Vec3 not using vectorization
3390
3431
  *
3391
3432
  * @param {Vec3} v the Vec3 to scale the matrix by
3392
- * @param {Mat4} out the receiving matrix, defaults to this
3433
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3393
3434
  * @returns {Mat4} out
3394
3435
  */
3395
- scale(v, out = index.ALWAYS_COPY ? new _a() : this) {
3436
+ scale(v, out = index.ALWAYS_COPY ? mat4() : this) {
3396
3437
  const x = v[0], y = v[1], z = v[2];
3397
3438
  out[0] = this[0] * x;
3398
3439
  out[1] = this[1] * x;
@@ -3417,10 +3458,10 @@ var glmaths = (function (exports) {
3417
3458
  *
3418
3459
  * @param {Number} rad the angle to rotate the matrix by
3419
3460
  * @param {Vec3} axis the axis to rotate around
3420
- * @param {Mat4} out the receiving matrix, defaults to this
3461
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3421
3462
  * @returns {Mat4} out
3422
3463
  */
3423
- rotate(rad, axis, out = index.ALWAYS_COPY ? new _a() : this) {
3464
+ rotate(rad, axis, out = index.ALWAYS_COPY ? mat4() : this) {
3424
3465
  let x = axis[0], y = axis[1], z = axis[2];
3425
3466
  let len = Math.sqrt(x * x + y * y + z * z);
3426
3467
  if (len < index.EPSILON)
@@ -3458,10 +3499,10 @@ var glmaths = (function (exports) {
3458
3499
  * Rotates a mat4 by the given angle around the X axis
3459
3500
  *
3460
3501
  * @param {Number} rad the angle to rotate the matrix by
3461
- * @param {Mat4} out the receiving matrix, defaults to this
3502
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3462
3503
  * @returns {Mat4} out
3463
3504
  */
3464
- rotateX(rad, out = index.ALWAYS_COPY ? new _a() : this) {
3505
+ rotateX(rad, out = index.ALWAYS_COPY ? mat4() : this) {
3465
3506
  const s = Math.sin(rad), c = Math.cos(rad);
3466
3507
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
3467
3508
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3489,10 +3530,10 @@ var glmaths = (function (exports) {
3489
3530
  * Rotates a mat4 by the given angle around the Y axis
3490
3531
  *
3491
3532
  * @param {Number} rad the angle to rotate the matrix by
3492
- * @param {Mat4} out the receiving matrix, defaults to this
3533
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3493
3534
  * @returns {Mat4} out
3494
3535
  */
3495
- rotateY(rad, out = index.ALWAYS_COPY ? new _a() : this) {
3536
+ rotateY(rad, out = index.ALWAYS_COPY ? mat4() : this) {
3496
3537
  const s = Math.sin(rad), c = Math.cos(rad);
3497
3538
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3498
3539
  const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
@@ -3520,10 +3561,10 @@ var glmaths = (function (exports) {
3520
3561
  * Rotates a mat4 by the given angle around the Z axis
3521
3562
  *
3522
3563
  * @param {Number} rad the angle to rotate the matrix by
3523
- * @param {Mat4} out the receiving matrix, defaults to this
3564
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
3524
3565
  * @returns {Mat4} out
3525
3566
  */
3526
- rotateZ(rad, out = index.ALWAYS_COPY ? new _a() : this) {
3567
+ rotateZ(rad, out = index.ALWAYS_COPY ? mat4() : this) {
3527
3568
  const s = Math.sin(rad), c = Math.cos(rad);
3528
3569
  const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
3529
3570
  const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
@@ -3679,10 +3720,10 @@ var glmaths = (function (exports) {
3679
3720
  * Creates a matrix from a vector translation
3680
3721
  *
3681
3722
  * @param {Vec3} v translation vector
3682
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3723
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3683
3724
  * @returns {Mat4} out
3684
3725
  */
3685
- static fromTranslation(v, out = new _a()) {
3726
+ static fromTranslation(v, out = mat4()) {
3686
3727
  out[0] = out[5] = out[10] = out[15] = 1;
3687
3728
  out[1] = out[2] = out[3] = out[4] = out[6] = out[7] = out[8] = out[9] = out[11] = 0;
3688
3729
  out[12] = v[0];
@@ -3694,10 +3735,10 @@ var glmaths = (function (exports) {
3694
3735
  * Creates a matrix from a vector scaling
3695
3736
  *
3696
3737
  * @param {Vec3} v scaling vector
3697
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3738
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3698
3739
  * @returns {Mat4} out
3699
3740
  */
3700
- static fromScaling(v, out = new _a()) {
3741
+ static fromScaling(v, out = mat4()) {
3701
3742
  out[0] = v[0];
3702
3743
  out[5] = v[1];
3703
3744
  out[10] = v[2];
@@ -3710,10 +3751,10 @@ var glmaths = (function (exports) {
3710
3751
  *
3711
3752
  * @param {Number} rad the angle to rotate the matrix by
3712
3753
  * @param {Vec3} axis the axis to rotate around
3713
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3754
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3714
3755
  * @returns {Mat4} out
3715
3756
  */
3716
- static fromRotation(rad, axis, out = new _a()) {
3757
+ static fromRotation(rad, axis, out = mat4()) {
3717
3758
  let x = axis[0], y = axis[1], z = axis[2];
3718
3759
  let len = Math.sqrt(x * x + y * y + z * z);
3719
3760
  if (len < index.EPSILON)
@@ -3743,10 +3784,10 @@ var glmaths = (function (exports) {
3743
3784
  * Creates a matrix from the given angle around the X axis
3744
3785
  *
3745
3786
  * @param {Number} rad the angle to rotate the matrix by
3746
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3787
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3747
3788
  * @returns {Mat4} out
3748
3789
  */
3749
- static fromXRotation(rad, out = new _a()) {
3790
+ static fromXRotation(rad, out = mat4()) {
3750
3791
  const s = Math.sin(rad), c = Math.cos(rad);
3751
3792
  out[0] = 1;
3752
3793
  out[1] = out[2] = out[3] = out[4] = out[7] = out[8] = out[11] = out[12] = out[13] = out[14] = 0;
@@ -3761,10 +3802,10 @@ var glmaths = (function (exports) {
3761
3802
  * Creates a matrix from the given angle around the Y axis
3762
3803
  *
3763
3804
  * @param {Number} rad the angle to rotate the matrix by
3764
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3805
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3765
3806
  * @returns {Mat4} out
3766
3807
  */
3767
- static fromYRotation(rad, out = new _a()) {
3808
+ static fromYRotation(rad, out = mat4()) {
3768
3809
  const s = Math.sin(rad), c = Math.cos(rad);
3769
3810
  out[0] = c;
3770
3811
  out[1] = out[3] = out[4] = out[6] = out[7] = out[9] = out[11] = out[12] = out[13] = out[14] = 0;
@@ -3778,10 +3819,10 @@ var glmaths = (function (exports) {
3778
3819
  * Creates a matrix from the given angle around the Z axis
3779
3820
  *
3780
3821
  * @param {Number} rad the angle to rotate the matrix by
3781
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3822
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3782
3823
  * @returns {Mat4} out
3783
3824
  */
3784
- static fromZRotation(rad, out = new _a()) {
3825
+ static fromZRotation(rad, out = mat4()) {
3785
3826
  const s = Math.sin(rad), c = Math.cos(rad);
3786
3827
  out[0] = c;
3787
3828
  out[1] = s;
@@ -3796,10 +3837,10 @@ var glmaths = (function (exports) {
3796
3837
  *
3797
3838
  * @param {Quat} q rotation quaternion
3798
3839
  * @param {Vec3} v translation vector
3799
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3840
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3800
3841
  * @returns {Mat4} out
3801
3842
  */
3802
- static fromRotationTranslation(q, v, out = new _a()) {
3843
+ static fromRotationTranslation(q, v, out = mat4()) {
3803
3844
  const x = q[0], y = q[1], z = q[2], w = q[3];
3804
3845
  const x2 = x + x, y2 = y + y, z2 = z + z;
3805
3846
  const xx = x * x2, xy = x * y2, xz = x * z2;
@@ -3827,10 +3868,10 @@ var glmaths = (function (exports) {
3827
3868
  * @param {Quat} q rotation quaternion
3828
3869
  * @param {Vec3} v translation vector
3829
3870
  * @param {Vec3} s scaling vector
3830
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3871
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3831
3872
  * @returns {Mat4} out
3832
3873
  */
3833
- static fromRotationTranslationScale(q, v, s, out = new _a()) {
3874
+ static fromRotationTranslationScale(q, v, s, out = mat4()) {
3834
3875
  const x = q[0], y = q[1], z = q[2], w = q[3];
3835
3876
  const x2 = x + x, y2 = y + y, z2 = z + z;
3836
3877
  const xx = x * x2, xy = x * y2, xz = x * z2;
@@ -3860,10 +3901,10 @@ var glmaths = (function (exports) {
3860
3901
  * @param {Vec3} v translation vector
3861
3902
  * @param {Vec3} s scaling vector
3862
3903
  * @param {Vec3} o the origin vector
3863
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3904
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3864
3905
  * @returns {Mat4} out
3865
3906
  */
3866
- static fromRotationTranslationScaleOrigin(q, v, s, o, out = new _a()) {
3907
+ static fromRotationTranslationScaleOrigin(q, v, s, o, out = mat4()) {
3867
3908
  const x = q[0], y = q[1], z = q[2], w = q[3];
3868
3909
  const x2 = x + x, y2 = y + y, z2 = z + z;
3869
3910
  const xx = x * x2, xy = x * y2, xz = x * z2;
@@ -3900,10 +3941,10 @@ var glmaths = (function (exports) {
3900
3941
  * Calculates a 4x4 matrix from the given quaternion
3901
3942
  *
3902
3943
  * @param {Quat} q quaternion to create matrix from
3903
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3944
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3904
3945
  * @returns {Mat4} out
3905
3946
  */
3906
- static fromQuat(q, out = new _a()) {
3947
+ static fromQuat(q, out = mat4()) {
3907
3948
  const x = q[0], y = q[1], z = q[2], w = q[3];
3908
3949
  const x2 = x + x, y2 = y + y, z2 = z + z;
3909
3950
  const xx = x * x2, yx = y * x2, yy = y * y2;
@@ -3931,10 +3972,10 @@ var glmaths = (function (exports) {
3931
3972
  * @param {Number} top top bound of the frustum
3932
3973
  * @param {Number} near near bound of the frustum
3933
3974
  * @param {Number} far far bound of the frustum
3934
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
3975
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3935
3976
  * @returns {Mat4} out
3936
3977
  */
3937
- static frustum(left, right, bottom, top, near, far, out = new _a()) {
3978
+ static frustum(left, right, bottom, top, near, far, out = mat4()) {
3938
3979
  const rl = 1 / (right - left);
3939
3980
  const tb = 1 / (top - bottom);
3940
3981
  const nf = 1 / (near - far);
@@ -3958,10 +3999,10 @@ var glmaths = (function (exports) {
3958
3999
  * @param {Number} aspect aspect ratio, typically viewport width / height
3959
4000
  * @param {Number} near near bound of the frustum
3960
4001
  * @param {Number | null} far far bound of the frustum, can be null or Infinity
3961
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4002
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3962
4003
  * @returns {Mat4} out
3963
4004
  */
3964
- static perspectiveNO(fovy, aspect, near, far, out = new _a()) {
4005
+ static perspectiveNO(fovy, aspect, near, far, out = mat4()) {
3965
4006
  const f = 1.0 / Math.tan(fovy / 2);
3966
4007
  const lh = index.LEFT_HANDED;
3967
4008
  out[0] = f / aspect;
@@ -3988,10 +4029,10 @@ var glmaths = (function (exports) {
3988
4029
  * @param {Number} aspect aspect ratio, typically viewport width / height
3989
4030
  * @param {Number} near near bound of the frustum
3990
4031
  * @param {Number | null} far far bound of the frustum, can be null or Infinity
3991
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4032
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
3992
4033
  * @returns {Mat4} out
3993
4034
  */
3994
- static perspectiveZO(fovy, aspect, near, far, out = new _a()) {
4035
+ static perspectiveZO(fovy, aspect, near, far, out = mat4()) {
3995
4036
  const f = 1.0 / Math.tan(fovy / 2);
3996
4037
  const lh = index.LEFT_HANDED;
3997
4038
  out[0] = f / aspect;
@@ -4025,10 +4066,10 @@ var glmaths = (function (exports) {
4025
4066
  * @param {Object} fov object containing upDegrees, downDegrees, leftDegrees, rightDegrees
4026
4067
  * @param {Number} near near bound of the frustum
4027
4068
  * @param {Number} far far bound of the frustum
4028
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4069
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4029
4070
  * @returns {Mat4} out
4030
4071
  */
4031
- static perspectiveFromFieldOfView(fov, near, far, out = new _a()) {
4072
+ static perspectiveFromFieldOfView(fov, near, far, out = mat4()) {
4032
4073
  const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);
4033
4074
  const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);
4034
4075
  const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);
@@ -4065,10 +4106,10 @@ var glmaths = (function (exports) {
4065
4106
  * @param {Number} top top bound of the frustum
4066
4107
  * @param {Number} near near bound of the frustum
4067
4108
  * @param {Number} far far bound of the frustum
4068
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4109
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4069
4110
  * @returns {Mat4} out
4070
4111
  */
4071
- static orthoNO(left, right, bottom, top, near, far, out = new _a()) {
4112
+ static orthoNO(left, right, bottom, top, near, far, out = mat4()) {
4072
4113
  const lr = 1 / (left - right);
4073
4114
  const bt = 1 / (bottom - top);
4074
4115
  const nf = 1 / (near - far);
@@ -4102,10 +4143,10 @@ var glmaths = (function (exports) {
4102
4143
  * @param {Number} top top bound of the frustum
4103
4144
  * @param {Number} near near bound of the frustum
4104
4145
  * @param {Number} far far bound of the frustum
4105
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4146
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4106
4147
  * @returns {Mat4} out
4107
4148
  */
4108
- static orthoZO(left, right, bottom, top, near, far, out = new _a()) {
4149
+ static orthoZO(left, right, bottom, top, near, far, out = mat4()) {
4109
4150
  const lr = 1 / (left - right);
4110
4151
  const bt = 1 / (bottom - top);
4111
4152
  const nf = 1 / (near - far);
@@ -4135,10 +4176,10 @@ var glmaths = (function (exports) {
4135
4176
  * @param {Vec3} eye position of the viewer
4136
4177
  * @param {Vec3} center point the viewer is looking at
4137
4178
  * @param {Vec3} up vector pointing up
4138
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4179
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4139
4180
  * @returns {Mat4} out
4140
4181
  */
4141
- static lookAt(eye, center, up, out = new _a()) {
4182
+ static lookAt(eye, center, up, out = mat4()) {
4142
4183
  let x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
4143
4184
  const eyex = eye[0], eyey = eye[1], eyez = eye[2];
4144
4185
  const upx = up[0], upy = up[1], upz = up[2];
@@ -4230,10 +4271,10 @@ var glmaths = (function (exports) {
4230
4271
  * @param {Vec3} eye position of the viewer
4231
4272
  * @param {Vec3} target point the viewer is looking at
4232
4273
  * @param {Vec3} up vector pointing up
4233
- * @param {Mat4} out the receiving matrix, defaults to new Mat4()
4274
+ * @param {Mat4} out the receiving matrix, defaults to mat4()
4234
4275
  * @returns {Mat4} out
4235
4276
  */
4236
- static targetTo(eye, target, up, out = new _a()) {
4277
+ static targetTo(eye, target, up, out = mat4()) {
4237
4278
  const eyex = eye[0], eyey = eye[1], eyez = eye[2];
4238
4279
  const upx = up[0], upy = up[1], upz = up[2];
4239
4280
  let z0, z1, z2;
@@ -4292,7 +4333,7 @@ var glmaths = (function (exports) {
4292
4333
  * @param {Mat4} out the receiving matrix, defaults to a new Mat4
4293
4334
  * @returns {Mat4} out
4294
4335
  */
4295
- static infinitePerspective(fovy, aspect, near, out = new _a()) {
4336
+ static infinitePerspective(fovy, aspect, near, out = mat4()) {
4296
4337
  const f = 1.0 / Math.tan(fovy / 2);
4297
4338
  const lh = index.LEFT_HANDED;
4298
4339
  out[0] = f / aspect;
@@ -4349,7 +4390,7 @@ var glmaths = (function (exports) {
4349
4390
  const a10 = model[4], a11 = model[5], a12 = model[6], a13 = model[7];
4350
4391
  const a20 = model[8], a21 = model[9], a22 = model[10], a23 = model[11];
4351
4392
  const a30 = model[12], a31 = model[13], a32 = model[14], a33 = model[15];
4352
- const pm = new _a();
4393
+ const pm = mat4();
4353
4394
  let b0 = proj[0], b1 = proj[1], b2 = proj[2], b3 = proj[3];
4354
4395
  pm[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
4355
4396
  pm[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
@@ -4407,10 +4448,10 @@ var glmaths = (function (exports) {
4407
4448
  * Adds two mat4's
4408
4449
  *
4409
4450
  * @param {Mat4} b the second operand
4410
- * @param {Mat4} out the receiving matrix, defaults to this
4451
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4411
4452
  * @returns {Mat4} out
4412
4453
  */
4413
- plus(b, out = index.ALWAYS_COPY ? new _a() : this) {
4454
+ plus(b, out = index.ALWAYS_COPY ? mat4() : this) {
4414
4455
  out[0] = this[0] + b[0];
4415
4456
  out[1] = this[1] + b[1];
4416
4457
  out[2] = this[2] + b[2];
@@ -4433,10 +4474,10 @@ var glmaths = (function (exports) {
4433
4474
  * Subtracts matrix b from a mat4
4434
4475
  *
4435
4476
  * @param {Mat4} b the second operand
4436
- * @param {Mat4} out the receiving matrix, defaults to this
4477
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4437
4478
  * @returns {Mat4} out
4438
4479
  */
4439
- minus(b, out = index.ALWAYS_COPY ? new _a() : this) {
4480
+ minus(b, out = index.ALWAYS_COPY ? mat4() : this) {
4440
4481
  out[0] = this[0] - b[0];
4441
4482
  out[1] = this[1] - b[1];
4442
4483
  out[2] = this[2] - b[2];
@@ -4459,10 +4500,10 @@ var glmaths = (function (exports) {
4459
4500
  * Multiplies each element of a mat4 by a scalar number
4460
4501
  *
4461
4502
  * @param {Number} b amount to scale the matrix's elements by
4462
- * @param {Mat4} out the receiving matrix, defaults to this
4503
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4463
4504
  * @returns {Mat4} out
4464
4505
  */
4465
- scaleScalar(b, out = index.ALWAYS_COPY ? new _a() : this) {
4506
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat4() : this) {
4466
4507
  out[0] = this[0] * b;
4467
4508
  out[1] = this[1] * b;
4468
4509
  out[2] = this[2] * b;
@@ -4486,10 +4527,10 @@ var glmaths = (function (exports) {
4486
4527
  *
4487
4528
  * @param {Mat4} b the second operand
4488
4529
  * @param {Number} scale the amount to scale b's elements by before adding
4489
- * @param {Mat4} out the receiving matrix, defaults to this
4530
+ * @param {Mat4} out the receiving matrix, defaults to new mat4()
4490
4531
  * @returns {Mat4} out
4491
4532
  */
4492
- multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? new _a() : this) {
4533
+ multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? mat4() : this) {
4493
4534
  out[0] = this[0] + b[0] * scale;
4494
4535
  out[1] = this[1] + b[1] * scale;
4495
4536
  out[2] = this[2] + b[2] * scale;
@@ -4553,7 +4594,7 @@ var glmaths = (function (exports) {
4553
4594
  Mat4.prototype.times = Mat4.prototype.multiply;
4554
4595
  Mat4.prototype.str = Mat4.prototype.toString;
4555
4596
  Mat4.prototype.multiplyScalar = Mat4.prototype.scaleScalar;
4556
- const mat4 = Object.assign((...args) => {
4597
+ const createMat4 = (...args) => {
4557
4598
  const out = new Mat4();
4558
4599
  let i = 0;
4559
4600
  for (const a of args) {
@@ -4564,7 +4605,9 @@ var glmaths = (function (exports) {
4564
4605
  out[i++] = v;
4565
4606
  }
4566
4607
  return out;
4567
- }, Mat4);
4608
+ };
4609
+ Object.setPrototypeOf(createMat4, Mat4);
4610
+ const mat4 = createMat4;
4568
4611
  const mat4x4 = mat4;
4569
4612
 
4570
4613
  /**
@@ -4572,9 +4615,9 @@ var glmaths = (function (exports) {
4572
4615
  * @extends Vec4
4573
4616
  */
4574
4617
  class Quat extends Float32Array {
4575
- static get identity() { return new Quat(0, 0, 0, 1); }
4576
- static get Identity() { return new Quat(0, 0, 0, 1); }
4577
- static get IDENTITY() { return new Quat(0, 0, 0, 1); }
4618
+ static get identity() { return quat(0, 0, 0, 1); }
4619
+ static get Identity() { return quat(0, 0, 0, 1); }
4620
+ static get IDENTITY() { return quat(0, 0, 0, 1); }
4578
4621
  /**
4579
4622
  * Creates a new quaternion
4580
4623
  *
@@ -4594,10 +4637,10 @@ var glmaths = (function (exports) {
4594
4637
  * Calculates the Hamilton product of two quaternions
4595
4638
  *
4596
4639
  * @param {Quat} b the second operand
4597
- * @param {Quat} out the receiving quaternion, defaults to this
4640
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4598
4641
  * @returns {Quat} out
4599
4642
  */
4600
- multiply(b, out = index.ALWAYS_COPY ? new Quat() : this) {
4643
+ multiply(b, out = index.ALWAYS_COPY ? quat() : this) {
4601
4644
  if (typeof b === 'number') {
4602
4645
  out[0] = this[0] * b;
4603
4646
  out[1] = this[1] * b;
@@ -4635,7 +4678,7 @@ var glmaths = (function (exports) {
4635
4678
  *
4636
4679
  * @param {Vec3} axis the axis around which to rotate
4637
4680
  * @param {Number} rad the angle in radians
4638
- * @param {Quat} out the receiving quaternion, defaults to this
4681
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4639
4682
  * @returns {Quat} out
4640
4683
  */
4641
4684
  setAxisAngle(axis, rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4690,7 +4733,7 @@ var glmaths = (function (exports) {
4690
4733
  * Rotates a quaternion by the given angle about the X axis
4691
4734
  *
4692
4735
  * @param {Number} rad angle in radians to rotate
4693
- * @param {Quat} out the receiving quaternion, defaults to this
4736
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4694
4737
  * @returns {Quat} out
4695
4738
  */
4696
4739
  rotateX(rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4707,7 +4750,7 @@ var glmaths = (function (exports) {
4707
4750
  * Rotates a quaternion by the given angle about the Y axis
4708
4751
  *
4709
4752
  * @param {Number} rad angle in radians to rotate
4710
- * @param {Quat} out the receiving quaternion, defaults to this
4753
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4711
4754
  * @returns {Quat} out
4712
4755
  */
4713
4756
  rotateY(rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4724,7 +4767,7 @@ var glmaths = (function (exports) {
4724
4767
  * Rotates a quaternion by the given angle about the Z axis
4725
4768
  *
4726
4769
  * @param {Number} rad angle in radians to rotate
4727
- * @param {Quat} out the receiving quaternion, defaults to this
4770
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4728
4771
  * @returns {Quat} out
4729
4772
  */
4730
4773
  rotateZ(rad, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4767,7 +4810,7 @@ var glmaths = (function (exports) {
4767
4810
  /**
4768
4811
  * Calculates the exponential of the unit quaternion
4769
4812
  *
4770
- * @param {Quat} out the receiving quaternion, defaults to this
4813
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4771
4814
  * @returns {Quat} out
4772
4815
  */
4773
4816
  exp(out = index.ALWAYS_COPY ? quat() : this) {
@@ -4801,7 +4844,7 @@ var glmaths = (function (exports) {
4801
4844
  /**
4802
4845
  * Calculates the natural logarithm of the unit quaternion
4803
4846
  *
4804
- * @param {Quat} out the receiving quaternion, defaults to this
4847
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4805
4848
  * @returns {Quat} out
4806
4849
  */
4807
4850
  ln(out = index.ALWAYS_COPY ? quat() : this) {
@@ -4875,7 +4918,7 @@ var glmaths = (function (exports) {
4875
4918
  *
4876
4919
  * @param {Quat} b the second operand
4877
4920
  * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
4878
- * @param {Quat} out the receiving quaternion, defaults to this
4921
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4879
4922
  * @returns {Quat} out
4880
4923
  */
4881
4924
  slerp(b, t, out = index.ALWAYS_COPY ? quat() : this) {
@@ -4954,7 +4997,7 @@ var glmaths = (function (exports) {
4954
4997
  /**
4955
4998
  * Calculates the inverse of a quaternion
4956
4999
  *
4957
- * @param {Quat} out the receiving quaternion, defaults to this
5000
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4958
5001
  * @returns {Quat} out
4959
5002
  */
4960
5003
  invert(out = index.ALWAYS_COPY ? quat() : this) {
@@ -4985,7 +5028,7 @@ var glmaths = (function (exports) {
4985
5028
  /**
4986
5029
  * Calculates the conjugate of a quaternion
4987
5030
  *
4988
- * @param {Quat} out the receiving quaternion, defaults to this
5031
+ * @param {Quat} out the receiving quaternion, defaults to new quat()
4989
5032
  * @returns {Quat} out
4990
5033
  */
4991
5034
  conjugate(out = index.ALWAYS_COPY ? quat() : this) {
@@ -5206,11 +5249,12 @@ var glmaths = (function (exports) {
5206
5249
  /**
5207
5250
  * Normalizes a quaternion
5208
5251
  *
5209
- * @param {Quat} out the receiving vector, defaults to this
5252
+ * @param {Quat} q the quaternion to normalize
5253
+ * @param {Quat} out the receiving vector, defaults to new quat()
5210
5254
  * @returns {Quat} out
5211
5255
  */
5212
- normalize(out = index.ALWAYS_COPY ? new Quat() : this) {
5213
- const x = this[0], y = this[1], z = this[2], w = this[3];
5256
+ static normalize(q, out = quat()) {
5257
+ const x = q[0], y = q[1], z = q[2], w = q[3];
5214
5258
  let len = x * x + y * y + z * z + w * w;
5215
5259
  if (len > 0) {
5216
5260
  len = 1.0 / Math.sqrt(len);
@@ -5221,6 +5265,15 @@ var glmaths = (function (exports) {
5221
5265
  out[3] = w * len;
5222
5266
  return out;
5223
5267
  }
5268
+ /**
5269
+ * Normalizes a quaternion
5270
+ *
5271
+ * @param {Quat} out the receiving vector, defaults to new quat()
5272
+ * @returns {Quat} out
5273
+ */
5274
+ normalize(out = index.ALWAYS_COPY ? quat() : this) {
5275
+ return Quat.normalize(this, out);
5276
+ }
5224
5277
  /**
5225
5278
  * Creates a quaternion that looks along the given direction vector
5226
5279
  *
@@ -5229,7 +5282,7 @@ var glmaths = (function (exports) {
5229
5282
  * @param {Quat} out the receiving quaternion, defaults to quat()
5230
5283
  * @returns {Quat} out
5231
5284
  */
5232
- static quatLookAt(direction, up, out = new Quat()) {
5285
+ static quatLookAt(direction, up, out = quat()) {
5233
5286
  const f = vec3(direction[0], direction[1], direction[2]).normalize();
5234
5287
  const s = Vec3.cross(f, up).normalize();
5235
5288
  const u = Vec3.cross(s, f);
@@ -5349,7 +5402,10 @@ var glmaths = (function (exports) {
5349
5402
  Quat.prototype.scale = Quat.prototype.multiply;
5350
5403
  Quat.prototype.times = Quat.prototype.multiply;
5351
5404
  Quat.prototype.str = Quat.prototype.toString;
5352
- const quat = Object.assign((x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w), Quat);
5405
+ Quat.prototype.normalized = Quat.prototype.normalize;
5406
+ const createQuat = (x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w);
5407
+ Object.setPrototypeOf(createQuat, Quat);
5408
+ const quat = createQuat;
5353
5409
 
5354
5410
  /**
5355
5411
  * Dual Quaternion for rigid body transformations (rotation + translation)
@@ -5357,9 +5413,9 @@ var glmaths = (function (exports) {
5357
5413
  * @extends Float32Array
5358
5414
  */
5359
5415
  class Quat2 extends Float32Array {
5360
- static get identity() { return new Quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5361
- static get Identity() { return new Quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5362
- static get IDENTITY() { return new Quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5416
+ static get identity() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5417
+ static get Identity() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5418
+ static get IDENTITY() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
5363
5419
  /**
5364
5420
  * Creates a new dual quaternion
5365
5421
  *
@@ -5378,11 +5434,11 @@ var glmaths = (function (exports) {
5378
5434
  * Multiply two dual quaternions
5379
5435
  *
5380
5436
  * @param {Quat2} b the second operand
5381
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5437
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5382
5438
  * @returns {Quat2} out
5383
5439
  */
5384
5440
  // @ts-ignore
5385
- this.multiply = (b, out = index.ALWAYS_COPY ? new Quat2() : this) => {
5441
+ this.multiply = (b, out = index.ALWAYS_COPY ? quat2() : this) => {
5386
5442
  const ax0 = this[0], ay0 = this[1], az0 = this[2], aw0 = this[3];
5387
5443
  const bx1 = b[4], by1 = b[5], bz1 = b[6], bw1 = b[7];
5388
5444
  const ax1 = this[4], ay1 = this[5], az1 = this[6], aw1 = this[7];
@@ -5484,7 +5540,7 @@ var glmaths = (function (exports) {
5484
5540
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5485
5541
  * @returns {Quat2} out
5486
5542
  */
5487
- static fromRotationTranslation(q, t, out = new Quat2()) {
5543
+ static fromRotationTranslation(q, t, out = quat2()) {
5488
5544
  const ax = t[0] * 0.5, ay = t[1] * 0.5, az = t[2] * 0.5;
5489
5545
  const bx = q[0], by = q[1], bz = q[2], bw = q[3];
5490
5546
  out[0] = bx;
@@ -5504,7 +5560,7 @@ var glmaths = (function (exports) {
5504
5560
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5505
5561
  * @returns {Quat2} out
5506
5562
  */
5507
- static fromTranslation(t, out = new Quat2()) {
5563
+ static fromTranslation(t, out = quat2()) {
5508
5564
  out[0] = 0;
5509
5565
  out[1] = 0;
5510
5566
  out[2] = 0;
@@ -5522,7 +5578,7 @@ var glmaths = (function (exports) {
5522
5578
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5523
5579
  * @returns {Quat2} out
5524
5580
  */
5525
- static fromRotation(q, out = new Quat2()) {
5581
+ static fromRotation(q, out = quat2()) {
5526
5582
  out[0] = q[0];
5527
5583
  out[1] = q[1];
5528
5584
  out[2] = q[2];
@@ -5540,7 +5596,7 @@ var glmaths = (function (exports) {
5540
5596
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5541
5597
  * @returns {Quat2} out
5542
5598
  */
5543
- static fromMat4(m, out = new Quat2()) {
5599
+ static fromMat4(m, out = quat2()) {
5544
5600
  const r = m.getRotation();
5545
5601
  const t = m.getTranslation();
5546
5602
  return Quat2.fromRotationTranslation(r, t, out);
@@ -5551,16 +5607,16 @@ var glmaths = (function (exports) {
5551
5607
  * @returns {Quat2} a new dual quaternion
5552
5608
  */
5553
5609
  clone() {
5554
- return new Quat2(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7]);
5610
+ return quat2(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7]);
5555
5611
  }
5556
5612
  /**
5557
5613
  * Translate by a Vec3
5558
5614
  *
5559
5615
  * @param {Vec3} v the translation vector
5560
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5616
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5561
5617
  * @returns {Quat2} out
5562
5618
  */
5563
- translate(v, out = index.ALWAYS_COPY ? new Quat2() : this) {
5619
+ translate(v, out = index.ALWAYS_COPY ? quat2() : this) {
5564
5620
  const ax1 = this[0], ay1 = this[1], az1 = this[2], aw1 = this[3];
5565
5621
  const bx1 = v[0] * 0.5, by1 = v[1] * 0.5, bz1 = v[2] * 0.5;
5566
5622
  const ax2 = this[4], ay2 = this[5], az2 = this[6], aw2 = this[7];
@@ -5577,10 +5633,10 @@ var glmaths = (function (exports) {
5577
5633
  /**
5578
5634
  * Calculates the conjugate of a dual quaternion
5579
5635
  *
5580
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5636
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5581
5637
  * @returns {Quat2} out
5582
5638
  */
5583
- conjugate(out = index.ALWAYS_COPY ? new Quat2() : this) {
5639
+ conjugate(out = index.ALWAYS_COPY ? quat2() : this) {
5584
5640
  out[0] = -this[0];
5585
5641
  out[1] = -this[1];
5586
5642
  out[2] = -this[2];
@@ -5594,10 +5650,10 @@ var glmaths = (function (exports) {
5594
5650
  /**
5595
5651
  * Calculates the inverse of a dual quaternion
5596
5652
  *
5597
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5653
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5598
5654
  * @returns {Quat2} out
5599
5655
  */
5600
- invert(out = index.ALWAYS_COPY ? new Quat2() : this) {
5656
+ invert(out = index.ALWAYS_COPY ? quat2() : this) {
5601
5657
  const sqlen = this.squaredLength();
5602
5658
  out[0] = -this[0] / sqlen;
5603
5659
  out[1] = -this[1] / sqlen;
@@ -5629,16 +5685,17 @@ var glmaths = (function (exports) {
5629
5685
  /**
5630
5686
  * Normalize the dual quaternion
5631
5687
  *
5632
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5688
+ * @param {Quat2} q the quaternion to normalize
5689
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5633
5690
  * @returns {Quat2} out
5634
5691
  */
5635
- normalize(out = index.ALWAYS_COPY ? new Quat2() : this) {
5636
- let magnitude = this.squaredLength();
5692
+ static normalize(q, out = quat2()) {
5693
+ let magnitude = q.squaredLength();
5637
5694
  if (magnitude > 0) {
5638
5695
  magnitude = Math.sqrt(magnitude);
5639
- const a0 = this[0] / magnitude, a1 = this[1] / magnitude;
5640
- const a2 = this[2] / magnitude, a3 = this[3] / magnitude;
5641
- const b0 = this[4], b1 = this[5], b2 = this[6], b3 = this[7];
5696
+ const a0 = q[0] / magnitude, a1 = q[1] / magnitude;
5697
+ const a2 = q[2] / magnitude, a3 = q[3] / magnitude;
5698
+ const b0 = q[4], b1 = q[5], b2 = q[6], b3 = q[7];
5642
5699
  const a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
5643
5700
  out[0] = a0;
5644
5701
  out[1] = a1;
@@ -5651,6 +5708,15 @@ var glmaths = (function (exports) {
5651
5708
  }
5652
5709
  return out;
5653
5710
  }
5711
+ /**
5712
+ * Normalize the dual quaternion
5713
+ *
5714
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5715
+ * @returns {Quat2} out
5716
+ */
5717
+ normalize(out = index.ALWAYS_COPY ? quat2() : this) {
5718
+ return Quat2.normalize(this, out);
5719
+ }
5654
5720
  /**
5655
5721
  * Dot product of the real parts of two dual quaternions
5656
5722
  *
@@ -5670,7 +5736,7 @@ var glmaths = (function (exports) {
5670
5736
  * @param {Quat2} out the receiving dual quaternion, defaults to quat2()
5671
5737
  * @returns {Quat2} out
5672
5738
  */
5673
- static lerp(a, b, t, out = new Quat2()) {
5739
+ static lerp(a, b, t, out = quat2()) {
5674
5740
  const mt = 1 - t;
5675
5741
  if (Quat2.dot(a, b) < 0)
5676
5742
  t = -t;
@@ -5688,10 +5754,10 @@ var glmaths = (function (exports) {
5688
5754
  * Adds two dual quaternions
5689
5755
  *
5690
5756
  * @param {Quat2} b the second operand
5691
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5757
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5692
5758
  * @returns {Quat2} out
5693
5759
  */
5694
- plus(b, out = index.ALWAYS_COPY ? new Quat2() : this) {
5760
+ plus(b, out = index.ALWAYS_COPY ? quat2() : this) {
5695
5761
  out[0] = this[0] + b[0];
5696
5762
  out[1] = this[1] + b[1];
5697
5763
  out[2] = this[2] + b[2];
@@ -5706,10 +5772,10 @@ var glmaths = (function (exports) {
5706
5772
  * Scales a dual quaternion by a scalar
5707
5773
  *
5708
5774
  * @param {Number} s the scalar to scale by
5709
- * @param {Quat2} out the receiving dual quaternion, defaults to this
5775
+ * @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
5710
5776
  * @returns {Quat2} out
5711
5777
  */
5712
- scale(s, out = index.ALWAYS_COPY ? new Quat2() : this) {
5778
+ scale(s, out = index.ALWAYS_COPY ? quat2() : this) {
5713
5779
  out[0] = this[0] * s;
5714
5780
  out[1] = this[1] * s;
5715
5781
  out[2] = this[2] * s;
@@ -5771,17 +5837,20 @@ var glmaths = (function (exports) {
5771
5837
  }
5772
5838
  // @aliases
5773
5839
  Quat2.prototype.sqrLen = Quat2.prototype.squaredLength;
5840
+ Quat2.prototype.normalized = Quat2.prototype.normalize;
5774
5841
  Quat2.prototype.str = Quat2.prototype.toString;
5775
5842
  Quat2.prototype.add = Quat2.prototype.plus;
5776
- const quat2 = Object.assign((x1 = 0, y1 = 0, z1 = 0, w1 = 1, x2 = 0, y2 = 0, z2 = 0, w2 = 0) => new Quat2(x1, y1, z1, w1, x2, y2, z2, w2), Quat2);
5843
+ const createQuat2 = (x1 = 0, y1 = 0, z1 = 0, w1 = 1, x2 = 0, y2 = 0, z2 = 0, w2 = 0) => new Quat2(x1, y1, z1, w1, x2, y2, z2, w2);
5844
+ Object.setPrototypeOf(createQuat2, Quat2);
5845
+ const quat2 = createQuat2;
5777
5846
 
5778
5847
  /** 2x2 Matrix in column-major order
5779
5848
  * @extends Float32Array
5780
5849
  */
5781
5850
  class Mat2 extends Float32Array {
5782
- static get identity() { return new Mat2(1, 0, 0, 1); }
5783
- static get Identity() { return new Mat2(1, 0, 0, 1); }
5784
- static get IDENTITY() { return new Mat2(1, 0, 0, 1); }
5851
+ static get identity() { return mat2(1, 0, 0, 1); }
5852
+ static get Identity() { return mat2(1, 0, 0, 1); }
5853
+ static get IDENTITY() { return mat2(1, 0, 0, 1); }
5785
5854
  /**
5786
5855
  * Creates a new Mat2
5787
5856
  *
@@ -5803,15 +5872,15 @@ var glmaths = (function (exports) {
5803
5872
  * @returns {Mat2} a new Mat2
5804
5873
  */
5805
5874
  clone() {
5806
- return new Mat2(this[0], this[1], this[2], this[3]);
5875
+ return mat2(this[0], this[1], this[2], this[3]);
5807
5876
  }
5808
5877
  /**
5809
5878
  * Transposes a mat2
5810
5879
  *
5811
- * @param {Mat2} out the receiving matrix, defaults to this
5880
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5812
5881
  * @returns {Mat2} out
5813
5882
  */
5814
- transpose(out = index.ALWAYS_COPY ? new Mat2() : this) {
5883
+ transpose(out = index.ALWAYS_COPY ? mat2() : this) {
5815
5884
  if (out.exactEquals(this)) {
5816
5885
  const tmp = out[1];
5817
5886
  out[1] = out[2];
@@ -5828,10 +5897,10 @@ var glmaths = (function (exports) {
5828
5897
  /**
5829
5898
  * Inverts a mat2
5830
5899
  *
5831
- * @param {Mat2} out the receiving matrix, defaults to this
5900
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5832
5901
  * @returns {Mat2} out or null if the matrix is not invertible
5833
5902
  */
5834
- invert(out = index.ALWAYS_COPY ? new Mat2() : this) {
5903
+ invert(out = index.ALWAYS_COPY ? mat2() : this) {
5835
5904
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
5836
5905
  // Calculate the determinant
5837
5906
  let det = a0 * a3 - a2 * a1;
@@ -5847,10 +5916,10 @@ var glmaths = (function (exports) {
5847
5916
  /**
5848
5917
  * Calculates the adjugate of a mat2
5849
5918
  *
5850
- * @param {Mat2} out the receiving matrix, defaults to this
5919
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5851
5920
  * @returns {Mat2} out
5852
5921
  */
5853
- adjoint(out = index.ALWAYS_COPY ? new Mat2() : this) {
5922
+ adjoint(out = index.ALWAYS_COPY ? mat2() : this) {
5854
5923
  let a0 = this[0];
5855
5924
  out[0] = this[3];
5856
5925
  out[1] = -this[1];
@@ -5870,10 +5939,10 @@ var glmaths = (function (exports) {
5870
5939
  * Rotates a mat2 by the given angle
5871
5940
  *
5872
5941
  * @param {Number} rad the angle to rotate the matrix by
5873
- * @param {Mat2} out the receiving matrix, defaults to this
5942
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5874
5943
  * @returns {Mat2} out
5875
5944
  */
5876
- rotate(rad, out = index.ALWAYS_COPY ? new Mat2() : this) {
5945
+ rotate(rad, out = index.ALWAYS_COPY ? mat2() : this) {
5877
5946
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
5878
5947
  const s = Math.sin(rad), c = Math.cos(rad);
5879
5948
  out[0] = a0 * c + a2 * s;
@@ -5886,10 +5955,10 @@ var glmaths = (function (exports) {
5886
5955
  * Scales a mat2 by the dimensions in the given Vec2
5887
5956
  *
5888
5957
  * @param {Vec2} v the Vec2 to scale the matrix by
5889
- * @param {Mat2} out the receiving matrix, defaults to this
5958
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5890
5959
  * @returns {Mat2} out
5891
5960
  */
5892
- scale(v, out = index.ALWAYS_COPY ? new Mat2() : this) {
5961
+ scale(v, out = index.ALWAYS_COPY ? mat2() : this) {
5893
5962
  const v0 = v[0], v1 = v[1];
5894
5963
  out[0] = this[0] * v0;
5895
5964
  out[1] = this[1] * v0;
@@ -5901,10 +5970,10 @@ var glmaths = (function (exports) {
5901
5970
  * Creates a Mat2 from a given angle
5902
5971
  *
5903
5972
  * @param {Number} rad the angle to rotate the matrix by
5904
- * @param {Mat2} out the receiving matrix, defaults to new Mat2()
5973
+ * @param {Mat2} out the receiving matrix, defaults to mat2()
5905
5974
  * @returns {Mat2} out
5906
5975
  */
5907
- static fromRotation(rad, out = new Mat2()) {
5976
+ static fromRotation(rad, out = mat2()) {
5908
5977
  const s = Math.sin(rad), c = Math.cos(rad);
5909
5978
  out[0] = c;
5910
5979
  out[1] = s;
@@ -5916,10 +5985,10 @@ var glmaths = (function (exports) {
5916
5985
  * Creates a Mat2 from a scaling vector
5917
5986
  *
5918
5987
  * @param {Vec2} v scaling vector
5919
- * @param {Mat2} out the receiving matrix, defaults to new Mat2()
5988
+ * @param {Mat2} out the receiving matrix, defaults to mat2()
5920
5989
  * @returns {Mat2} out
5921
5990
  */
5922
- static fromScaling(v, out = new Mat2()) {
5991
+ static fromScaling(v, out = mat2()) {
5923
5992
  out[0] = v[0];
5924
5993
  out[1] = out[2] = 0;
5925
5994
  out[3] = v[1];
@@ -5947,7 +6016,7 @@ var glmaths = (function (exports) {
5947
6016
  * @param {Mat2} D the diagonal matrix
5948
6017
  * @param {Mat2} U the upper triangular matrix
5949
6018
  */
5950
- LDU(L = new Mat2(), D = new Mat2(), U = new Mat2()) {
6019
+ LDU(L = mat2(), D = mat2(), U = mat2()) {
5951
6020
  L[2] = this[2] / this[0];
5952
6021
  U[0] = this[0];
5953
6022
  U[1] = this[1];
@@ -5958,10 +6027,10 @@ var glmaths = (function (exports) {
5958
6027
  * Adds two Mat2's
5959
6028
  *
5960
6029
  * @param {Mat2} b the second operand
5961
- * @param {Mat2} out the receiving matrix, defaults to this
6030
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5962
6031
  * @returns {Mat2} out
5963
6032
  */
5964
- plus(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6033
+ plus(b, out = index.ALWAYS_COPY ? mat2() : this) {
5965
6034
  out[0] = this[0] + b[0];
5966
6035
  out[1] = this[1] + b[1];
5967
6036
  out[2] = this[2] + b[2];
@@ -5972,17 +6041,17 @@ var glmaths = (function (exports) {
5972
6041
  * Subtracts matrix b from a mat2
5973
6042
  *
5974
6043
  * @param {Mat2} b the second operand
5975
- * @param {Mat2} out the receiving matrix, defaults to this
6044
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
5976
6045
  * @returns {Mat2} out
5977
6046
  */
5978
- minus(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6047
+ minus(b, out = index.ALWAYS_COPY ? mat2() : this) {
5979
6048
  out[0] = this[0] - b[0];
5980
6049
  out[1] = this[1] - b[1];
5981
6050
  out[2] = this[2] - b[2];
5982
6051
  out[3] = this[3] - b[3];
5983
6052
  return out;
5984
6053
  }
5985
- multiply(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6054
+ multiply(b, out = index.ALWAYS_COPY ? mat2() : this) {
5986
6055
  if (b instanceof Vec2)
5987
6056
  return b.transformMat2(this);
5988
6057
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
@@ -6016,10 +6085,10 @@ var glmaths = (function (exports) {
6016
6085
  * Multiplies each element of a mat2 by a scalar value
6017
6086
  *
6018
6087
  * @param {Number} b amount to scale the matrix's elements by
6019
- * @param {Mat2} out the receiving matrix, defaults to this
6088
+ * @param {Mat2} out the receiving matrix, defaults to new mat2()
6020
6089
  * @returns {Mat2} out
6021
6090
  */
6022
- scaleScalar(b, out = index.ALWAYS_COPY ? new Mat2() : this) {
6091
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat2() : this) {
6023
6092
  out[0] = this[0] * b;
6024
6093
  out[1] = this[1] * b;
6025
6094
  out[2] = this[2] * b;
@@ -6056,9 +6125,9 @@ var glmaths = (function (exports) {
6056
6125
  * @extends Float32Array
6057
6126
  */
6058
6127
  class Mat2x3 extends Float32Array {
6059
- static get identity() { return new Mat2x3(1, 0, 0, 1, 0, 0); }
6060
- static get Identity() { return new Mat2x3(1, 0, 0, 1, 0, 0); }
6061
- static get IDENTITY() { return new Mat2x3(1, 0, 0, 1, 0, 0); }
6128
+ static get identity() { return mat2x3(1, 0, 0, 1, 0, 0); }
6129
+ static get Identity() { return mat2x3(1, 0, 0, 1, 0, 0); }
6130
+ static get IDENTITY() { return mat2x3(1, 0, 0, 1, 0, 0); }
6062
6131
  /**
6063
6132
  * Creates a new Mat2x3
6064
6133
  *
@@ -6081,10 +6150,10 @@ var glmaths = (function (exports) {
6081
6150
  /**
6082
6151
  * Inverts a mat2x3
6083
6152
  *
6084
- * @param {Mat2x3} out the receiving matrix, defaults to this
6153
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6085
6154
  * @returns {Mat2x3} out or null if the matrix is not invertible
6086
6155
  */
6087
- invert(out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6156
+ invert(out = index.ALWAYS_COPY ? mat2x3() : this) {
6088
6157
  const aa = this[0], ab = this[1], ac = this[2], ad = this[3];
6089
6158
  const atx = this[4], aty = this[5];
6090
6159
  let det = aa * ad - ab * ac;
@@ -6111,10 +6180,10 @@ var glmaths = (function (exports) {
6111
6180
  * Rotates a mat2x3 by the given angle
6112
6181
  *
6113
6182
  * @param {Number} rad the angle to rotate the matrix by
6114
- * @param {Mat2x3} out the receiving matrix, defaults to this
6183
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6115
6184
  * @returns {Mat2x3} out
6116
6185
  */
6117
- rotate(rad, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6186
+ rotate(rad, out = index.ALWAYS_COPY ? mat2x3() : this) {
6118
6187
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
6119
6188
  const s = Math.sin(rad);
6120
6189
  const c = Math.cos(rad);
@@ -6130,10 +6199,10 @@ var glmaths = (function (exports) {
6130
6199
  * Scales a mat2x3 by the dimensions in the given Vec2
6131
6200
  *
6132
6201
  * @param {Vec2} v the Vec2 to scale the matrix by
6133
- * @param {Mat2x3} out the receiving matrix, defaults to this
6202
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6134
6203
  * @returns {Mat2x3} out
6135
6204
  */
6136
- scale(v, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6205
+ scale(v, out = index.ALWAYS_COPY ? mat2x3() : this) {
6137
6206
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
6138
6207
  const v0 = v[0], v1 = v[1];
6139
6208
  out[0] = a0 * v0;
@@ -6148,10 +6217,10 @@ var glmaths = (function (exports) {
6148
6217
  * Translates a mat2x3 by the dimensions in the given Vec2
6149
6218
  *
6150
6219
  * @param {Vec2} v the Vec2 to translate the matrix by
6151
- * @param {Mat2x3} out the receiving matrix, defaults to this
6220
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6152
6221
  * @returns {Mat2x3} out
6153
6222
  */
6154
- translate(v, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6223
+ translate(v, out = index.ALWAYS_COPY ? mat2x3() : this) {
6155
6224
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
6156
6225
  const v0 = v[0], v1 = v[1];
6157
6226
  out[0] = a0;
@@ -6166,10 +6235,10 @@ var glmaths = (function (exports) {
6166
6235
  * Creates a Mat2x3 from a given angle
6167
6236
  *
6168
6237
  * @param {Number} rad the angle to rotate the matrix by
6169
- * @param {Mat2x3} out the receiving matrix, defaults to new Mat2x3()
6238
+ * @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
6170
6239
  * @returns {Mat2x3} out
6171
6240
  */
6172
- static fromRotation(rad, out = new Mat2x3()) {
6241
+ static fromRotation(rad, out = mat2x3()) {
6173
6242
  const s = Math.sin(rad), c = Math.cos(rad);
6174
6243
  out[0] = c;
6175
6244
  out[1] = s;
@@ -6182,10 +6251,10 @@ var glmaths = (function (exports) {
6182
6251
  * Creates a Mat2x3 from a scaling vector
6183
6252
  *
6184
6253
  * @param {Vec2} v scaling vector
6185
- * @param {Mat2x3} out the receiving matrix, defaults to new Mat2x3()
6254
+ * @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
6186
6255
  * @returns {Mat2x3} out
6187
6256
  */
6188
- static fromScaling(v, out = new Mat2x3()) {
6257
+ static fromScaling(v, out = mat2x3()) {
6189
6258
  out[0] = v[0];
6190
6259
  out[1] = out[2] = 0;
6191
6260
  out[3] = v[1];
@@ -6196,10 +6265,10 @@ var glmaths = (function (exports) {
6196
6265
  * Creates a Mat2x3 from a translation vector
6197
6266
  *
6198
6267
  * @param {Vec2} v translation vector
6199
- * @param {Mat2x3} out the receiving matrix, defaults to new Mat2x3()
6268
+ * @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
6200
6269
  * @returns {Mat2x3} out
6201
6270
  */
6202
- static fromTranslation(v, out = new Mat2x3()) {
6271
+ static fromTranslation(v, out = mat2x3()) {
6203
6272
  out[0] = out[3] = 1;
6204
6273
  out[1] = out[2] = 0;
6205
6274
  out[4] = v[0];
@@ -6226,10 +6295,10 @@ var glmaths = (function (exports) {
6226
6295
  * Adds two Mat2x3's
6227
6296
  *
6228
6297
  * @param {Mat2x3} b the second operand
6229
- * @param {Mat2x3} out the receiving matrix, defaults to this
6298
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6230
6299
  * @returns {Mat2x3} out
6231
6300
  */
6232
- plus(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6301
+ plus(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6233
6302
  out[0] = this[0] + b[0];
6234
6303
  out[1] = this[1] + b[1];
6235
6304
  out[2] = this[2] + b[2];
@@ -6242,10 +6311,10 @@ var glmaths = (function (exports) {
6242
6311
  * Subtracts matrix b from a mat2x3
6243
6312
  *
6244
6313
  * @param {Mat2x3} b the second operand
6245
- * @param {Mat2x3} out the receiving matrix, defaults to this
6314
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6246
6315
  * @returns {Mat2x3} out
6247
6316
  */
6248
- minus(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6317
+ minus(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6249
6318
  out[0] = this[0] - b[0];
6250
6319
  out[1] = this[1] - b[1];
6251
6320
  out[2] = this[2] - b[2];
@@ -6254,7 +6323,7 @@ var glmaths = (function (exports) {
6254
6323
  out[5] = this[5] - b[5];
6255
6324
  return out;
6256
6325
  }
6257
- multiply(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6326
+ multiply(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6258
6327
  if (b instanceof Vec2)
6259
6328
  return b.transformMat2x3(this);
6260
6329
  const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
@@ -6291,10 +6360,10 @@ var glmaths = (function (exports) {
6291
6360
  * Multiplies each element of a mat2x3 by a scalar value
6292
6361
  *
6293
6362
  * @param {Number} b amount to scale the matrix's elements by
6294
- * @param {Mat2x3} out the receiving matrix, defaults to this
6363
+ * @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
6295
6364
  * @returns {Mat2x3} out
6296
6365
  */
6297
- scaleScalar(b, out = index.ALWAYS_COPY ? new Mat2x3() : this) {
6366
+ scaleScalar(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
6298
6367
  out[0] = this[0] * b;
6299
6368
  out[1] = this[1] * b;
6300
6369
  out[2] = this[2] * b;
@@ -6309,7 +6378,7 @@ var glmaths = (function (exports) {
6309
6378
  * @returns {Mat2x3} a new Mat2x3
6310
6379
  */
6311
6380
  clone() {
6312
- return new Mat2x3(this[0], this[1], this[2], this[3], this[4], this[5]);
6381
+ return mat2x3(this[0], this[1], this[2], this[3], this[4], this[5]);
6313
6382
  }
6314
6383
  }
6315
6384
  // @aliases
@@ -6321,7 +6390,20 @@ var glmaths = (function (exports) {
6321
6390
  Mat2x3.prototype.times = Mat2x3.prototype.multiply;
6322
6391
  Mat2x3.prototype.str = Mat2x3.prototype.toString;
6323
6392
  Mat2x3.prototype.multiplyScalar = Mat2x3.prototype.scaleScalar;
6324
- const mat2x3 = Object.assign((a = 0, b = 0, c = 0, d = 0, tx = 0, ty = 0) => new Mat2x3(a, b, c, d, tx, ty), Mat2x3);
6393
+ const createMat2x3 = (...args) => {
6394
+ const out = new Mat2x3();
6395
+ let i = 0;
6396
+ for (const a of args) {
6397
+ if (typeof a === 'number')
6398
+ out[i++] = a;
6399
+ else
6400
+ for (const v of a)
6401
+ out[i++] = v;
6402
+ }
6403
+ return out;
6404
+ };
6405
+ Object.setPrototypeOf(createMat2x3, Mat2x3);
6406
+ const mat2x3 = createMat2x3;
6325
6407
  const mat2d = mat2x3;
6326
6408
 
6327
6409
  function makeArr(a) {