@carbonenginejs/runtime-utils 0.1.1 → 0.1.3

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.
Files changed (104) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +23 -23
  3. package/README.md +69 -69
  4. package/THIRD-PARTY-NOTICES.md +64 -64
  5. package/docs/README.md +74 -73
  6. package/docs/architecture.md +101 -101
  7. package/docs/concepts/foundation-consolidation.md +85 -85
  8. package/docs/concepts/model-lifecycle.md +111 -0
  9. package/docs/const-kb.md +85 -87
  10. package/docs/core-types/DECORATOR-TODOS.md +25 -25
  11. package/docs/core-types/README.md +229 -168
  12. package/docs/reference/api.md +105 -102
  13. package/docs/reference/classes/README.md +135 -135
  14. package/package.json +139 -139
  15. package/src/arrays.js +5 -5
  16. package/src/audio/audioFormats.js +34 -34
  17. package/src/audio/index.js +1 -1
  18. package/src/box3.js +331 -331
  19. package/src/bytes.js +56 -56
  20. package/src/compression.js +56 -56
  21. package/src/constants/index.js +7 -7
  22. package/src/constants/trinity.js +13 -13
  23. package/src/constants.js +15 -15
  24. package/src/curve.js +79 -79
  25. package/src/d3d/dxgiFormats.js +46 -46
  26. package/src/d3d/index.js +2 -2
  27. package/src/d3d/primitiveTopology.js +11 -11
  28. package/src/document/CjsCarbonDocument.js +212 -212
  29. package/src/document/CjsClassRegistry.js +373 -373
  30. package/src/document/CjsDocumentDehydrator.js +142 -142
  31. package/src/document/CjsDocumentHydrator.js +156 -156
  32. package/src/document/CjsStructRegistry.js +348 -348
  33. package/src/document/hydrationAdapter.js +129 -129
  34. package/src/document/index.js +6 -6
  35. package/src/errors/CjsError.js +286 -286
  36. package/src/errors/index.js +5 -5
  37. package/src/geometry/box.js +22 -22
  38. package/src/geometry/cylinder.js +22 -22
  39. package/src/geometry/helpers/earcut.js +1 -1
  40. package/src/geometry/helpers/misc.js +3 -3
  41. package/src/geometry/index.js +8 -8
  42. package/src/geometry/json.js +67 -67
  43. package/src/geometry/lathe.js +44 -44
  44. package/src/geometry/plane.js +14 -14
  45. package/src/geometry/shape.js +4 -4
  46. package/src/geometry/sphere.js +24 -24
  47. package/src/geometry/torus.js +14 -14
  48. package/src/graphics/colorSpaces.js +22 -22
  49. package/src/graphics/index.js +4 -4
  50. package/src/graphics/pixelFormats.js +158 -158
  51. package/src/graphics/textureDimensions.js +22 -22
  52. package/src/graphics/trinityEnums.js +87 -87
  53. package/src/index.js +62 -62
  54. package/src/is.js +108 -46
  55. package/src/json.js +23 -23
  56. package/src/lifecycle/CjsLifecycleState.js +77 -77
  57. package/src/lifecycle/index.js +1 -1
  58. package/src/lne3.js +70 -70
  59. package/src/lookup.js +48 -48
  60. package/src/mat3.js +51 -51
  61. package/src/mat4.js +699 -699
  62. package/src/math/index.js +25 -25
  63. package/src/math/scalar.js +63 -63
  64. package/src/media/index.js +1 -1
  65. package/src/media/mediaTypes.js +50 -50
  66. package/src/mesh.js +424 -424
  67. package/src/model/CjsEventEmitter.js +333 -333
  68. package/src/model/CjsModel.js +1589 -1544
  69. package/src/model/CjsModelState.js +72 -72
  70. package/src/model/index.js +4 -4
  71. package/src/model/sourceRecordUtils.js +54 -54
  72. package/src/noise.js +310 -310
  73. package/src/num.js +827 -827
  74. package/src/object.js +39 -39
  75. package/src/path.js +53 -53
  76. package/src/pln.js +125 -125
  77. package/src/pool.js +9 -9
  78. package/src/quat.js +144 -144
  79. package/src/ray3.js +188 -188
  80. package/src/renderContext/formats.js +145 -145
  81. package/src/renderContext/index.js +5 -5
  82. package/src/renderContext/presentation.js +125 -125
  83. package/src/renderContext/resources.js +27 -27
  84. package/src/renderContext/upscaling.js +22 -22
  85. package/src/renderContext/window.js +20 -20
  86. package/src/runtime/CjsRuntimeState.js +50 -50
  87. package/src/schema/CjsSchema.js +555 -318
  88. package/src/schema/index.js +4 -4
  89. package/src/shader/index.js +1 -1
  90. package/src/shader/shaderStages.js +37 -37
  91. package/src/sph3.js +181 -181
  92. package/src/tangent.js +288 -288
  93. package/src/text.js +40 -40
  94. package/src/tri3.js +98 -98
  95. package/src/types/carbonTypes.js +635 -635
  96. package/src/types/index.js +2 -2
  97. package/src/utils.js +58 -58
  98. package/src/validation.js +46 -46
  99. package/src/vec2.js +229 -229
  100. package/src/vec3.js +1188 -1172
  101. package/src/vec4.js +347 -347
  102. package/src/vertex.js +108 -108
  103. package/src/webgpu/index.js +1 -1
  104. package/src/webgpu/textureFormats.js +121 -121
package/src/box3.js CHANGED
@@ -1,9 +1,9 @@
1
- import { num } from "./num.js";
2
- import { vec3 } from "./vec3.js";
3
- import { pool } from "./pool.js";
4
-
5
- const FLOAT32_MAX = 3.4028234663852886e38;
6
-
1
+ import { num } from "./num.js";
2
+ import { vec3 } from "./vec3.js";
3
+ import { pool } from "./pool.js";
4
+
5
+ const FLOAT32_MAX = 3.4028234663852886e38;
6
+
7
7
 
8
8
  /**
9
9
  * 3D Box
@@ -58,17 +58,17 @@ box3.$max = function (a)
58
58
  * @param {vec3} p - point to add
59
59
  * @returns {box3} out - receiving box3
60
60
  */
61
- box3.addPoint = function (out, a, p)
62
- {
63
- if (box3.isEmpty(a))
64
- {
65
- out[0] = out[3] = p[0];
66
- out[1] = out[4] = p[1];
67
- out[2] = out[5] = p[2];
68
- return out;
69
- }
70
-
71
- out[0] = Math.min(a[0], p[0]);
61
+ box3.addPoint = function (out, a, p)
62
+ {
63
+ if (box3.isEmpty(a))
64
+ {
65
+ out[0] = out[3] = p[0];
66
+ out[1] = out[4] = p[1];
67
+ out[2] = out[5] = p[2];
68
+ return out;
69
+ }
70
+
71
+ out[0] = Math.min(a[0], p[0]);
72
72
  out[1] = Math.min(a[1], p[1]);
73
73
  out[2] = Math.min(a[2], p[2]);
74
74
  out[3] = Math.max(a[3], p[0]);
@@ -85,13 +85,13 @@ box3.addPoint = function (out, a, p)
85
85
  * @param {Array.<number>} points - points to add
86
86
  * @returns {box3} out - receiving box3
87
87
  */
88
- box3.addPoints = function (out, a, points)
89
- {
90
- if (box3.isEmpty(a))
91
- {
92
- return points.length ? box3.fromPoints(out, points) : box3.empty(out);
93
- }
94
-
88
+ box3.addPoints = function (out, a, points)
89
+ {
90
+ if (box3.isEmpty(a))
91
+ {
92
+ return points.length ? box3.fromPoints(out, points) : box3.empty(out);
93
+ }
94
+
95
95
  let minX = a[0],
96
96
  minY = a[1],
97
97
  minZ = a[2],
@@ -295,14 +295,14 @@ box3.distanceToValues = function (a, px, py, pz)
295
295
  * @param {box3} a - box3 to empty
296
296
  * @returns {box3} - the empty box3
297
297
  */
298
- box3.empty = function (a)
299
- {
300
- a[0] = FLOAT32_MAX;
301
- a[1] = FLOAT32_MAX;
302
- a[2] = FLOAT32_MAX;
303
- a[3] = -FLOAT32_MAX;
304
- a[4] = -FLOAT32_MAX;
305
- a[5] = -FLOAT32_MAX;
298
+ box3.empty = function (a)
299
+ {
300
+ a[0] = FLOAT32_MAX;
301
+ a[1] = FLOAT32_MAX;
302
+ a[2] = FLOAT32_MAX;
303
+ a[3] = -FLOAT32_MAX;
304
+ a[4] = -FLOAT32_MAX;
305
+ a[5] = -FLOAT32_MAX;
306
306
  return a;
307
307
  };
308
308
 
@@ -312,14 +312,14 @@ box3.empty = function (a)
312
312
  * @param {vec3} min - min bounds
313
313
  * @param {vec3} max - max bounds
314
314
  */
315
- box3.bounds.empty = function (min, max)
316
- {
317
- min[0] = FLOAT32_MAX;
318
- min[1] = FLOAT32_MAX;
319
- min[2] = FLOAT32_MAX;
320
- max[0] = -FLOAT32_MAX;
321
- max[1] = -FLOAT32_MAX;
322
- max[2] = -FLOAT32_MAX;
315
+ box3.bounds.empty = function (min, max)
316
+ {
317
+ min[0] = FLOAT32_MAX;
318
+ min[1] = FLOAT32_MAX;
319
+ min[2] = FLOAT32_MAX;
320
+ max[0] = -FLOAT32_MAX;
321
+ max[1] = -FLOAT32_MAX;
322
+ max[2] = -FLOAT32_MAX;
323
323
  };
324
324
 
325
325
  /**
@@ -329,8 +329,8 @@ box3.bounds.empty = function (min, max)
329
329
  * @param {box3} b - box3 to compare
330
330
  * @returns {boolean} - true if box3s are equal
331
331
  */
332
- box3.equals = function (a, b)
333
- {
332
+ box3.equals = function (a, b)
333
+ {
334
334
  let a0 = a[0],
335
335
  a1 = a[1],
336
336
  a2 = a[2],
@@ -346,12 +346,12 @@ box3.equals = function (a, b)
346
346
  b5 = b[5];
347
347
 
348
348
  return (
349
- (a0 === b0 || Math.abs(a0 - b0) <= num.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0))) &&
350
- (a1 === b1 || Math.abs(a1 - b1) <= num.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1))) &&
351
- (a2 === b2 || Math.abs(a2 - b2) <= num.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2))) &&
352
- (a3 === b3 || Math.abs(a3 - b3) <= num.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3))) &&
353
- (a4 === b4 || Math.abs(a4 - b4) <= num.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4))) &&
354
- (a5 === b5 || Math.abs(a5 - b5) <= num.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)))
349
+ (a0 === b0 || Math.abs(a0 - b0) <= num.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0))) &&
350
+ (a1 === b1 || Math.abs(a1 - b1) <= num.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1))) &&
351
+ (a2 === b2 || Math.abs(a2 - b2) <= num.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2))) &&
352
+ (a3 === b3 || Math.abs(a3 - b3) <= num.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3))) &&
353
+ (a4 === b4 || Math.abs(a4 - b4) <= num.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4))) &&
354
+ (a5 === b5 || Math.abs(a5 - b5) <= num.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)))
355
355
  );
356
356
  };
357
357
 
@@ -380,12 +380,12 @@ box3.equalsBounds = function (a, min, max)
380
380
  b5 = max[2];
381
381
 
382
382
  return (
383
- (a0 === b0 || Math.abs(a0 - b0) <= num.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0))) &&
384
- (a1 === b1 || Math.abs(a1 - b1) <= num.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1))) &&
385
- (a2 === b2 || Math.abs(a2 - b2) <= num.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2))) &&
386
- (a3 === b3 || Math.abs(a3 - b3) <= num.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3))) &&
387
- (a4 === b4 || Math.abs(a4 - b4) <= num.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4))) &&
388
- (a5 === b5 || Math.abs(a5 - b5) <= num.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)))
383
+ (a0 === b0 || Math.abs(a0 - b0) <= num.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0))) &&
384
+ (a1 === b1 || Math.abs(a1 - b1) <= num.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1))) &&
385
+ (a2 === b2 || Math.abs(a2 - b2) <= num.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2))) &&
386
+ (a3 === b3 || Math.abs(a3 - b3) <= num.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3))) &&
387
+ (a4 === b4 || Math.abs(a4 - b4) <= num.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4))) &&
388
+ (a5 === b5 || Math.abs(a5 - b5) <= num.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)))
389
389
  );
390
390
  };
391
391
 
@@ -506,18 +506,18 @@ box3.fromArray = function (out, arr, index = 0)
506
506
  * @param {vec3} max - source max bounds
507
507
  * @returns {box3} out - receiving box3
508
508
  */
509
- box3.fromBounds = function (out, min, max)
510
- {
511
- out[0] = min[0];
509
+ box3.fromBounds = function (out, min, max)
510
+ {
511
+ out[0] = min[0];
512
512
  out[1] = min[1];
513
513
  out[2] = min[2];
514
514
  out[3] = max[0];
515
515
  out[4] = max[1];
516
516
  out[5] = max[2];
517
- return out;
518
- };
519
-
520
- box3.from = box3.fromBounds;
517
+ return out;
518
+ };
519
+
520
+ box3.from = box3.fromBounds;
521
521
 
522
522
 
523
523
  /**
@@ -546,28 +546,28 @@ box3.fromPositionSize = function (out, position, size)
546
546
  * @param {Array.<vec3>} points - array of points
547
547
  * @returns {box3} out - receiving box3
548
548
  */
549
- box3.fromPoints = function (out, points)
550
- {
551
- if (!points.length) return box3.empty(out);
552
-
553
- out[0] = out[3] = points[0][0];
554
- out[1] = out[4] = points[0][1];
555
- out[2] = out[5] = points[0][2];
556
-
557
- for (let i = 1; i < points.length; i++)
558
- {
559
- out[0] = Math.min(out[0], points[i][0]);
560
- out[1] = Math.min(out[1], points[i][1]);
549
+ box3.fromPoints = function (out, points)
550
+ {
551
+ if (!points.length) return box3.empty(out);
552
+
553
+ out[0] = out[3] = points[0][0];
554
+ out[1] = out[4] = points[0][1];
555
+ out[2] = out[5] = points[0][2];
556
+
557
+ for (let i = 1; i < points.length; i++)
558
+ {
559
+ out[0] = Math.min(out[0], points[i][0]);
560
+ out[1] = Math.min(out[1], points[i][1]);
561
561
  out[2] = Math.min(out[2], points[i][2]);
562
562
  out[3] = Math.max(out[3], points[i][0]);
563
563
  out[4] = Math.max(out[4], points[i][1]);
564
564
  out[5] = Math.max(out[5], points[i][2]);
565
565
  }
566
-
567
- return out;
568
- };
569
-
570
- box3.setPoints = box3.fromPoints;
566
+
567
+ return out;
568
+ };
569
+
570
+ box3.setPoints = box3.fromPoints;
571
571
 
572
572
  /**
573
573
  * Sets a box3 from a sphere's components
@@ -595,10 +595,10 @@ box3.fromPositionRadius = function (out, position, radius)
595
595
  * @param {sph3} sphere - source sphere
596
596
  * @returns {box3} out - receiving box3
597
597
  */
598
- box3.fromSph3 = function (out, sphere)
599
- {
600
- if (sphere[3] < 0) return box3.empty(out);
601
-
598
+ box3.fromSph3 = function (out, sphere)
599
+ {
600
+ if (sphere[3] < 0) return box3.empty(out);
601
+
602
602
  out[0] = sphere[0] - sphere[3];
603
603
  out[1] = sphere[1] - sphere[3];
604
604
  out[2] = sphere[2] - sphere[3];
@@ -675,16 +675,16 @@ box3.getCenter = function (out, a)
675
675
  * @param {vec3} p - the point to clamp
676
676
  * @returns {vec3} [out] - receiving vec3
677
677
  */
678
- box3.getClampedPoint = function (out, a, p)
679
- {
680
- if (box3.isEmpty(a))
681
- {
682
- out[0] = p[0];
683
- out[1] = p[1];
684
- out[2] = p[2];
685
- return out;
686
- }
687
-
678
+ box3.getClampedPoint = function (out, a, p)
679
+ {
680
+ if (box3.isEmpty(a))
681
+ {
682
+ out[0] = p[0];
683
+ out[1] = p[1];
684
+ out[2] = p[2];
685
+ return out;
686
+ }
687
+
688
688
  out[0] = Math.max(a[0], Math.min(a[3], p[0]));
689
689
  out[1] = Math.max(a[1], Math.min(a[4], p[1]));
690
690
  out[2] = Math.max(a[2], Math.min(a[5], p[2]));
@@ -728,16 +728,16 @@ box3.getMin = function (out, a)
728
728
  * @param {box3} a - source box
729
729
  * @returns {vec3} [out] - receiving vec3
730
730
  */
731
- box3.getSize = function (out, a)
732
- {
733
- if (box3.isEmpty(a))
734
- {
735
- out[0] = 0;
736
- out[1] = 0;
737
- out[2] = 0;
738
- return out;
739
- }
740
-
731
+ box3.getSize = function (out, a)
732
+ {
733
+ if (box3.isEmpty(a))
734
+ {
735
+ out[0] = 0;
736
+ out[1] = 0;
737
+ out[2] = 0;
738
+ return out;
739
+ }
740
+
741
741
  out[0] = a[3] - a[0];
742
742
  out[1] = a[4] - a[1];
743
743
  out[2] = a[5] - a[2];
@@ -751,9 +751,9 @@ box3.getSize = function (out, a)
751
751
  * @param {box3} a - source box
752
752
  * @returns {vec3} [out] - receiving vec3
753
753
  */
754
- box3.getPosition = function (out, a)
755
- {
756
- return box3.getCenter(out, a);
754
+ box3.getPosition = function (out, a)
755
+ {
756
+ return box3.getCenter(out, a);
757
757
  };
758
758
 
759
759
  /**
@@ -761,10 +761,10 @@ box3.getPosition = function (out, a)
761
761
  * @param {box3} a
762
762
  * @returns {number}
763
763
  */
764
- box3.radius = function (a)
765
- {
766
- if (box3.isEmpty(a)) return 0;
767
-
764
+ box3.radius = function (a)
765
+ {
766
+ if (box3.isEmpty(a)) return 0;
767
+
768
768
  let sX = a[3] - a[0],
769
769
  sY = a[4] - a[1],
770
770
  sZ = a[5] - a[2];
@@ -780,16 +780,16 @@ box3.radius = function (a)
780
780
  * @param {box3} b - second box3
781
781
  * @returns {box3} out - receiving box3
782
782
  */
783
- box3.intersect = function (out, a, b)
784
- {
785
- out[0] = Math.max(a[0], b[0]);
786
- out[1] = Math.max(a[1], b[1]);
787
- out[2] = Math.max(a[2], b[2]);
788
- out[3] = Math.min(a[3], b[3]);
789
- out[4] = Math.min(a[4], b[4]);
790
- out[5] = Math.min(a[5], b[5]);
791
- return box3.isEmpty(out) ? box3.empty(out) : out;
792
- };
783
+ box3.intersect = function (out, a, b)
784
+ {
785
+ out[0] = Math.max(a[0], b[0]);
786
+ out[1] = Math.max(a[1], b[1]);
787
+ out[2] = Math.max(a[2], b[2]);
788
+ out[3] = Math.min(a[3], b[3]);
789
+ out[4] = Math.min(a[4], b[4]);
790
+ out[5] = Math.min(a[5], b[5]);
791
+ return box3.isEmpty(out) ? box3.empty(out) : out;
792
+ };
793
793
 
794
794
  /**
795
795
  * Sets a box3 from the intersect of a box3 and min and max bounds
@@ -800,16 +800,16 @@ box3.intersect = function (out, a, b)
800
800
  * @param {vec3} max - max bounds
801
801
  * @returns {box3} out - receiving box3
802
802
  */
803
- box3.intersectBounds = function (out, a, min, max)
804
- {
805
- out[0] = Math.max(a[0], min[0]);
806
- out[1] = Math.max(a[1], min[1]);
807
- out[2] = Math.max(a[2], min[2]);
808
- out[3] = Math.min(a[3], max[0]);
809
- out[4] = Math.min(a[4], max[1]);
810
- out[5] = Math.min(a[5], max[2]);
811
- return box3.isEmpty(out) ? box3.empty(out) : out;
812
- };
803
+ box3.intersectBounds = function (out, a, min, max)
804
+ {
805
+ out[0] = Math.max(a[0], min[0]);
806
+ out[1] = Math.max(a[1], min[1]);
807
+ out[2] = Math.max(a[2], min[2]);
808
+ out[3] = Math.min(a[3], max[0]);
809
+ out[4] = Math.min(a[4], max[1]);
810
+ out[5] = Math.min(a[5], max[2]);
811
+ return box3.isEmpty(out) ? box3.empty(out) : out;
812
+ };
813
813
 
814
814
  /**
815
815
  * Checks for box3 intersection with another box3
@@ -852,32 +852,32 @@ box3.intersectsBounds = function (a, min, max)
852
852
  * @param {number} constant - plane constant
853
853
  * @returns {boolean} - true if intersection occurs
854
854
  */
855
- box3.intersectsNormalConstant = function (a, normal, constant)
856
- {
857
- let tMin = 0,
858
- tMax = 0;
859
-
860
- if (normal[0] > 0)
861
- {
862
- tMin += normal[0] * a[0];
863
- tMax += normal[0] * a[3];
864
- }
865
- else
866
- {
867
- tMin += normal[0] * a[3];
868
- tMax += normal[0] * a[0];
869
- }
870
-
871
- if (normal[1] > 0)
872
- {
873
- tMin += normal[1] * a[1];
874
- tMax += normal[1] * a[4];
875
- }
876
- else
877
- {
878
- tMin += normal[1] * a[4];
879
- tMax += normal[1] * a[1];
880
- }
855
+ box3.intersectsNormalConstant = function (a, normal, constant)
856
+ {
857
+ let tMin = 0,
858
+ tMax = 0;
859
+
860
+ if (normal[0] > 0)
861
+ {
862
+ tMin += normal[0] * a[0];
863
+ tMax += normal[0] * a[3];
864
+ }
865
+ else
866
+ {
867
+ tMin += normal[0] * a[3];
868
+ tMax += normal[0] * a[0];
869
+ }
870
+
871
+ if (normal[1] > 0)
872
+ {
873
+ tMin += normal[1] * a[1];
874
+ tMax += normal[1] * a[4];
875
+ }
876
+ else
877
+ {
878
+ tMin += normal[1] * a[4];
879
+ tMax += normal[1] * a[1];
880
+ }
881
881
 
882
882
  if (normal[2] > 0)
883
883
  {
@@ -890,7 +890,7 @@ box3.intersectsNormalConstant = function (a, normal, constant)
890
890
  tMax += normal[2] * a[2];
891
891
  }
892
892
 
893
- return (tMin <= -constant && tMax >= -constant);
893
+ return (tMin <= -constant && tMax >= -constant);
894
894
  };
895
895
 
896
896
  /**
@@ -940,11 +940,11 @@ box3.intersectsValues = function (a, px, py, pz)
940
940
  * @param {number} radius - sphere radius to compare
941
941
  * @returns {boolean} - true if intersection occurs
942
942
  */
943
- box3.intersectsPositionRadius = function (a, position, radius)
944
- {
945
- if (box3.isEmpty(a) || radius < 0) return false;
946
-
947
- let x = Math.max(a[0], Math.min(a[3], position[0])) - position[0],
943
+ box3.intersectsPositionRadius = function (a, position, radius)
944
+ {
945
+ if (box3.isEmpty(a) || radius < 0) return false;
946
+
947
+ let x = Math.max(a[0], Math.min(a[3], position[0])) - position[0],
948
948
  y = Math.max(a[1], Math.min(a[4], position[1])) - position[1],
949
949
  z = Math.max(a[2], Math.min(a[5], position[2])) - position[2];
950
950
 
@@ -958,10 +958,10 @@ box3.intersectsPositionRadius = function (a, position, radius)
958
958
  * @param {sph3} sphere - sph3 to compare
959
959
  * @returns {boolean} - true if intersection occurs
960
960
  */
961
- box3.intersectsSph3 = function (a, sphere)
962
- {
963
- if (box3.isEmpty(a) || sphere[3] < 0) return false;
964
-
961
+ box3.intersectsSph3 = function (a, sphere)
962
+ {
963
+ if (box3.isEmpty(a) || sphere[3] < 0) return false;
964
+
965
965
  let x = Math.max(a[0], Math.min(a[3], sphere[0])) - sphere[0],
966
966
  y = Math.max(a[1], Math.min(a[4], sphere[1])) - sphere[1],
967
967
  z = Math.max(a[2], Math.min(a[5], sphere[2])) - sphere[2];
@@ -975,10 +975,10 @@ box3.intersectsSph3 = function (a, sphere)
975
975
  * @param {box3} a - source box3
976
976
  * @returns {boolean} - true if empty
977
977
  */
978
- box3.isEmpty = function (a)
979
- {
980
- return (a[3] < a[0]) || (a[4] < a[1]) || (a[5] < a[2]);
981
- };
978
+ box3.isEmpty = function (a)
979
+ {
980
+ return (a[3] < a[0]) || (a[4] < a[1]) || (a[5] < a[2]);
981
+ };
982
982
 
983
983
  /**
984
984
  * Checks if bounds are empty
@@ -987,10 +987,10 @@ box3.isEmpty = function (a)
987
987
  * @param {vec3} max
988
988
  * @returns {boolean}
989
989
  */
990
- box3.bounds.isEmpty = function (min, max)
991
- {
992
- return (max[0] < min[0]) || (max[1] < min[1]) || (max[2] < min[2]);
993
- };
990
+ box3.bounds.isEmpty = function (min, max)
991
+ {
992
+ return (max[0] < min[0]) || (max[1] < min[1]) || (max[2] < min[2]);
993
+ };
994
994
 
995
995
  /**
996
996
  * Sets a box3 from values
@@ -1059,10 +1059,10 @@ box3.squaredDistanceToPoint = function (a, p)
1059
1059
  * @param {box3} a - source box3
1060
1060
  * @returns {number} - surface area
1061
1061
  */
1062
- box3.surfaceArea = function (a)
1063
- {
1064
- if (box3.isEmpty(a)) return 0;
1065
-
1062
+ box3.surfaceArea = function (a)
1063
+ {
1064
+ if (box3.isEmpty(a)) return 0;
1065
+
1066
1066
  let aa = a[3] - a[0],
1067
1067
  h = a[4] - a[1],
1068
1068
  d = a[5] - a[2];
@@ -1113,26 +1113,26 @@ box3.toBounds = function (a, outMin, outMax)
1113
1113
  * @param {Array} [points]
1114
1114
  * @returns {Array<Array>} points
1115
1115
  */
1116
- box3.toPoints = function (a, points = [])
1117
- {
1118
- if (box3.isEmpty(a)) return points;
1119
-
1120
- const
1121
- ax = a[0],
1122
- ay = a[1],
1123
- az = a[2],
1124
- bx = a[3],
1125
- by = a[4],
1126
- bz = a[5];
1127
-
1128
- points.push([ bx, by, bz ]);
1129
- points.push([ ax, by, bz ]);
1130
- points.push([ bx, by, az ]);
1131
- points.push([ ax, by, az ]);
1132
- points.push([ bx, ay, bz ]);
1133
- points.push([ ax, ay, bz ]);
1134
- points.push([ bx, ay, az ]);
1135
- points.push([ ax, ay, az ]);
1116
+ box3.toPoints = function (a, points = [])
1117
+ {
1118
+ if (box3.isEmpty(a)) return points;
1119
+
1120
+ const
1121
+ ax = a[0],
1122
+ ay = a[1],
1123
+ az = a[2],
1124
+ bx = a[3],
1125
+ by = a[4],
1126
+ bz = a[5];
1127
+
1128
+ points.push([ bx, by, bz ]);
1129
+ points.push([ ax, by, bz ]);
1130
+ points.push([ bx, by, az ]);
1131
+ points.push([ ax, by, az ]);
1132
+ points.push([ bx, ay, bz ]);
1133
+ points.push([ ax, ay, bz ]);
1134
+ points.push([ bx, ay, az ]);
1135
+ points.push([ ax, ay, az ]);
1136
1136
 
1137
1137
  return points;
1138
1138
  };
@@ -1143,16 +1143,16 @@ box3.toPoints = function (a, points = [])
1143
1143
  * @param outCenter
1144
1144
  * @returns {number}
1145
1145
  */
1146
- box3.toPositionRadius = function (a, outCenter)
1147
- {
1148
- if (box3.isEmpty(a))
1149
- {
1150
- outCenter[0] = 0;
1151
- outCenter[1] = 0;
1152
- outCenter[2] = 0;
1153
- return 0;
1154
- }
1155
-
1146
+ box3.toPositionRadius = function (a, outCenter)
1147
+ {
1148
+ if (box3.isEmpty(a))
1149
+ {
1150
+ outCenter[0] = 0;
1151
+ outCenter[1] = 0;
1152
+ outCenter[2] = 0;
1153
+ return 0;
1154
+ }
1155
+
1156
1156
  let sX = a[3] - a[0],
1157
1157
  sY = a[4] - a[1],
1158
1158
  sZ = a[5] - a[2];
@@ -1171,16 +1171,16 @@ box3.toPositionRadius = function (a, outCenter)
1171
1171
  * @param {vec3} outCenter
1172
1172
  * @returns {number}
1173
1173
  */
1174
- box3.bounds.toPositionRadius = function (minBounds, maxBounds, outCenter)
1175
- {
1176
- if (box3.bounds.isEmpty(minBounds, maxBounds))
1177
- {
1178
- outCenter[0] = 0;
1179
- outCenter[1] = 0;
1180
- outCenter[2] = 0;
1181
- return 0;
1182
- }
1183
-
1174
+ box3.bounds.toPositionRadius = function (minBounds, maxBounds, outCenter)
1175
+ {
1176
+ if (box3.bounds.isEmpty(minBounds, maxBounds))
1177
+ {
1178
+ outCenter[0] = 0;
1179
+ outCenter[1] = 0;
1180
+ outCenter[2] = 0;
1181
+ return 0;
1182
+ }
1183
+
1184
1184
  let sX = maxBounds[0] - minBounds[0],
1185
1185
  sY = maxBounds[1] - minBounds[1],
1186
1186
  sZ = maxBounds[2] - minBounds[2];
@@ -1219,35 +1219,35 @@ box3.translate = function (out, a, v)
1219
1219
  * @param {mat4} m - mat4 to transform with
1220
1220
  * @returns {box3} out - receiving box3
1221
1221
  */
1222
- box3.transformMat4 = function (out, a, m)
1223
- {
1224
- if (box3.isEmpty(a)) return box3.empty(out);
1225
-
1226
- const
1227
- ax = a[0],
1228
- ay = a[1],
1229
- az = a[2],
1230
- bx = a[3],
1231
- by = a[4],
1232
- bz = a[5],
1233
- point = vec3.alloc();
1234
-
1235
- out[0] = out[1] = out[2] = Infinity;
1236
- out[3] = out[4] = out[5] = -Infinity;
1237
-
1238
- for (let i = 0; i < 8; i++)
1239
- {
1240
- point[0] = i & 1 ? bx : ax;
1241
- point[1] = i & 2 ? by : ay;
1242
- point[2] = i & 4 ? bz : az;
1243
- vec3.transformMat4(point, point, m);
1244
- box3.addPoint(out, out, point);
1245
- }
1246
-
1247
- vec3.unalloc(point);
1248
-
1249
- return out;
1250
- };
1222
+ box3.transformMat4 = function (out, a, m)
1223
+ {
1224
+ if (box3.isEmpty(a)) return box3.empty(out);
1225
+
1226
+ const
1227
+ ax = a[0],
1228
+ ay = a[1],
1229
+ az = a[2],
1230
+ bx = a[3],
1231
+ by = a[4],
1232
+ bz = a[5],
1233
+ point = vec3.alloc();
1234
+
1235
+ out[0] = out[1] = out[2] = Infinity;
1236
+ out[3] = out[4] = out[5] = -Infinity;
1237
+
1238
+ for (let i = 0; i < 8; i++)
1239
+ {
1240
+ point[0] = i & 1 ? bx : ax;
1241
+ point[1] = i & 2 ? by : ay;
1242
+ point[2] = i & 4 ? bz : az;
1243
+ vec3.transformMat4(point, point, m);
1244
+ box3.addPoint(out, out, point);
1245
+ }
1246
+
1247
+ vec3.unalloc(point);
1248
+
1249
+ return out;
1250
+ };
1251
1251
 
1252
1252
  /**
1253
1253
  * Sets a box3 from the union of two box3s
@@ -1257,11 +1257,11 @@ box3.transformMat4 = function (out, a, m)
1257
1257
  * @param {box3} b - second box3
1258
1258
  * @returns {box3} out - receiving box3
1259
1259
  */
1260
- box3.union = function (out, a, b)
1261
- {
1262
- if (box3.isEmpty(a)) return box3.copy(out, b);
1263
- if (box3.isEmpty(b)) return box3.copy(out, a);
1264
-
1260
+ box3.union = function (out, a, b)
1261
+ {
1262
+ if (box3.isEmpty(a)) return box3.copy(out, b);
1263
+ if (box3.isEmpty(b)) return box3.copy(out, a);
1264
+
1265
1265
  out[0] = Math.min(a[0], b[0]);
1266
1266
  out[1] = Math.min(a[1], b[1]);
1267
1267
  out[2] = Math.min(a[2], b[2]);
@@ -1280,11 +1280,11 @@ box3.union = function (out, a, b)
1280
1280
  * @param {vec3} max - max bounds
1281
1281
  * @returns {box3} out - receiving box3
1282
1282
  */
1283
- box3.unionBounds = function (out, a, min, max)
1284
- {
1285
- if (box3.isEmpty(a)) return box3.fromBounds(out, min, max);
1286
- if (min[0] > max[0] || min[1] > max[1] || min[2] > max[2]) return box3.copy(out, a);
1287
-
1283
+ box3.unionBounds = function (out, a, min, max)
1284
+ {
1285
+ if (box3.isEmpty(a)) return box3.fromBounds(out, min, max);
1286
+ if (min[0] > max[0] || min[1] > max[1] || min[2] > max[2]) return box3.copy(out, a);
1287
+
1288
1288
  out[0] = Math.min(a[0], min[0]);
1289
1289
  out[1] = Math.min(a[1], min[1]);
1290
1290
  out[2] = Math.min(a[2], min[2]);
@@ -1304,82 +1304,82 @@ box3.unionBounds = function (out, a, min, max)
1304
1304
  * @param {vec3} bMin
1305
1305
  * @param {vec3} bMax
1306
1306
  */
1307
- box3.bounds.union = function (outMin, outMax, aMin, aMax, bMin, bMax)
1308
- {
1307
+ box3.bounds.union = function (outMin, outMax, aMin, aMax, bMin, bMax)
1308
+ {
1309
1309
  outMin[0] = Math.min(aMin[0], bMin[0]);
1310
1310
  outMin[1] = Math.min(aMin[1], bMin[1]);
1311
1311
  outMin[2] = Math.min(aMin[2], bMin[2]);
1312
1312
  outMax[0] = Math.max(aMax[0], bMax[0]);
1313
- outMax[1] = Math.max(aMax[1], bMax[1]);
1314
- outMax[2] = Math.max(aMax[2], bMax[2]);
1315
- };
1316
-
1317
- export const {
1318
- bounds,
1319
- alloc,
1320
- unalloc,
1321
- $min,
1322
- $max,
1323
- addPoint,
1324
- addPoints,
1325
- clone,
1326
- contains,
1327
- containsBounds,
1328
- containsPoint,
1329
- containsValue,
1330
- copy,
1331
- copyMin,
1332
- copyMax,
1333
- create,
1334
- distanceToPoint,
1335
- distanceToValues,
1336
- empty,
1337
- equals,
1338
- equalsBounds,
1339
- exactEquals,
1340
- exactEqualsBounds,
1341
- expandScalar,
1342
- expandValues,
1343
- expandVec3,
1344
- fromArray,
1345
- fromBounds,
1346
- from,
1347
- fromPositionSize,
1348
- fromPoints,
1349
- setPoints,
1350
- fromPositionRadius,
1351
- fromSph3,
1352
- fromTransform,
1353
- fromValues,
1354
- getCenter,
1355
- getClampedPoint,
1356
- getMax,
1357
- getMin,
1358
- getSize,
1359
- getPosition,
1360
- radius,
1361
- intersect,
1362
- intersectBounds,
1363
- intersects,
1364
- intersectsBounds,
1365
- intersectsNormalConstant,
1366
- intersectsPln,
1367
- intersectsPoint,
1368
- intersectsValues,
1369
- intersectsPositionRadius,
1370
- intersectsSph3,
1371
- isEmpty,
1372
- set,
1373
- setMinBounds,
1374
- setMaxBounds,
1375
- squaredDistanceToPoint,
1376
- surfaceArea,
1377
- toArray,
1378
- toBounds,
1379
- toPoints,
1380
- toPositionRadius,
1381
- translate,
1382
- transformMat4,
1383
- union,
1384
- unionBounds
1385
- } = box3;
1313
+ outMax[1] = Math.max(aMax[1], bMax[1]);
1314
+ outMax[2] = Math.max(aMax[2], bMax[2]);
1315
+ };
1316
+
1317
+ export const {
1318
+ bounds,
1319
+ alloc,
1320
+ unalloc,
1321
+ $min,
1322
+ $max,
1323
+ addPoint,
1324
+ addPoints,
1325
+ clone,
1326
+ contains,
1327
+ containsBounds,
1328
+ containsPoint,
1329
+ containsValue,
1330
+ copy,
1331
+ copyMin,
1332
+ copyMax,
1333
+ create,
1334
+ distanceToPoint,
1335
+ distanceToValues,
1336
+ empty,
1337
+ equals,
1338
+ equalsBounds,
1339
+ exactEquals,
1340
+ exactEqualsBounds,
1341
+ expandScalar,
1342
+ expandValues,
1343
+ expandVec3,
1344
+ fromArray,
1345
+ fromBounds,
1346
+ from,
1347
+ fromPositionSize,
1348
+ fromPoints,
1349
+ setPoints,
1350
+ fromPositionRadius,
1351
+ fromSph3,
1352
+ fromTransform,
1353
+ fromValues,
1354
+ getCenter,
1355
+ getClampedPoint,
1356
+ getMax,
1357
+ getMin,
1358
+ getSize,
1359
+ getPosition,
1360
+ radius,
1361
+ intersect,
1362
+ intersectBounds,
1363
+ intersects,
1364
+ intersectsBounds,
1365
+ intersectsNormalConstant,
1366
+ intersectsPln,
1367
+ intersectsPoint,
1368
+ intersectsValues,
1369
+ intersectsPositionRadius,
1370
+ intersectsSph3,
1371
+ isEmpty,
1372
+ set,
1373
+ setMinBounds,
1374
+ setMaxBounds,
1375
+ squaredDistanceToPoint,
1376
+ surfaceArea,
1377
+ toArray,
1378
+ toBounds,
1379
+ toPoints,
1380
+ toPositionRadius,
1381
+ translate,
1382
+ transformMat4,
1383
+ union,
1384
+ unionBounds
1385
+ } = box3;