@woosh/meep-engine 2.69.0 → 2.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/meep.cjs CHANGED
@@ -1764,6 +1764,27 @@ function clamp$1(value, min, max) {
1764
1764
  }
1765
1765
  }
1766
1766
 
1767
+ /**
1768
+ * Very small value, used for comparison when compensation for rounding error is required
1769
+ * @type {number}
1770
+ */
1771
+ const EPSILON = 0.000001;
1772
+
1773
+ /**
1774
+ * Comparison of two numbers with a given tolerance
1775
+ * @param {number} a
1776
+ * @param {number} b
1777
+ * @param {number} tolerance
1778
+ * @returns {boolean}
1779
+ */
1780
+ function epsilonEquals(a, b, tolerance) {
1781
+ assert.isNumber(a, 'a');
1782
+ assert.isNumber(b, 'b');
1783
+ assert.isNumber(tolerance, 'tolerance');
1784
+
1785
+ return Math.abs(a - b) <= tolerance;
1786
+ }
1787
+
1767
1788
  /**
1768
1789
  * Linear interpolation between two values controlled by a given fraction
1769
1790
  * @param {number} a
@@ -1775,13 +1796,191 @@ function lerp$1(a, b, fraction) {
1775
1796
  return (b - a) * fraction + a;
1776
1797
  }
1777
1798
 
1799
+ /**
1800
+ * Returns lowest value out of 2 supplied
1801
+ * @param {number} a
1802
+ * @param {number} b
1803
+ * @returns {number}
1804
+ */
1805
+ function min2(a, b) {
1806
+ return a < b ? a : b;
1807
+ }
1808
+
1778
1809
  /**
1779
1810
  *
1780
1811
  * @param {number} v
1781
- * @returns {number} +1 if v>0, 0 if v == 0, -1 if v<0
1812
+ * @returns {number}
1782
1813
  */
1783
- function sign$1(v) {
1784
- return v > 0 ? 1 : (v < 0 ? -1 : 0);
1814
+ function computeHashFloat(v) {
1815
+ //we break the number up into fractional and whole parts
1816
+ const whole = v | 0;
1817
+
1818
+ const fraction = v - whole;
1819
+
1820
+ //fractional part is scaled up into int32 range, this inexact method, as it will produce 0 hash for values below a certain threshold
1821
+ const fractionHash = fraction * 1367130550;
1822
+
1823
+ //take XOR of both parts
1824
+ return fractionHash ^ whole;
1825
+ }
1826
+
1827
+ const K = Math.SQRT1_2 / 511;
1828
+
1829
+ /**
1830
+ * Based on GDC talk from Bungie on destiny, compressing quaternions for animation
1831
+ * @param {number[]} output
1832
+ * @param {number} output_offset
1833
+ * @param {number} value
1834
+ */
1835
+ function quat_decode_from_uint32(output, output_offset, value) {
1836
+ //read components
1837
+ const max = value & 0x3;
1838
+
1839
+ const iv0 = (value >> 2) & 0x3FF;
1840
+ const iv1 = (value >> 12) & 0x3FF;
1841
+ const iv2 = (value >> 22) & 0x3FF;
1842
+
1843
+ //scale components back to quaternion range
1844
+ const v0 = iv0 * K - Math.SQRT1_2;
1845
+ const v1 = iv1 * K - Math.SQRT1_2;
1846
+ const v2 = iv2 * K - Math.SQRT1_2;
1847
+
1848
+ //restore dropped component using quaternion identity: x^2 + y^2 + z^2 + w^2 = 1
1849
+ const dropped_2 = 1 - v0 * v0 - v1 * v1 - v2 * v2;
1850
+ const dropped = Math.sqrt(dropped_2);
1851
+
1852
+ let x, y, z, w;
1853
+ if (max === 0) {
1854
+ x = dropped;
1855
+ y = v0;
1856
+ z = v1;
1857
+ w = v2;
1858
+ } else if (max === 1) {
1859
+ x = v0;
1860
+ y = dropped;
1861
+ z = v1;
1862
+ w = v2;
1863
+ } else if (max === 2) {
1864
+ x = v0;
1865
+ y = v1;
1866
+ z = dropped;
1867
+ w = v2;
1868
+ } else {
1869
+ x = v0;
1870
+ y = v1;
1871
+ z = v2;
1872
+ w = dropped;
1873
+ }
1874
+
1875
+ output[output_offset] = x;
1876
+ output[output_offset + 1] = y;
1877
+ output[output_offset + 2] = z;
1878
+ output[output_offset + 3] = w;
1879
+ }
1880
+
1881
+ /**
1882
+ * Based on GDC talk from Bungie on destiny, compressing quaternions for animation
1883
+ * @param {number} x
1884
+ * @param {number} y
1885
+ * @param {number} z
1886
+ * @param {number} w
1887
+ * @returns {number}
1888
+ */
1889
+ function quat_encode_to_uint32(x, y, z, w) {
1890
+
1891
+ const absX = Math.abs(x);
1892
+ const absY = Math.abs(y);
1893
+ const absZ = Math.abs(z);
1894
+ const absW = Math.abs(w);
1895
+
1896
+ let max = 0;
1897
+
1898
+ //pick max component
1899
+ if (absY > absX) {
1900
+ if (absY > absZ) {
1901
+ if (absY > absW) {
1902
+ //absY is max
1903
+ max = 1;
1904
+ } else {
1905
+ //absW is max
1906
+ max = 3;
1907
+ }
1908
+ } else if (absZ > absW) {
1909
+ //absZ is max
1910
+ max = 2;
1911
+ } else {
1912
+ //absW is max
1913
+ max = 3;
1914
+ }
1915
+ } else if (absX > absZ) {
1916
+ if (absX > absW) {
1917
+ max = 0;
1918
+ } else {
1919
+ max = 3;
1920
+ }
1921
+ } else if (absZ > absW) {
1922
+ max = 2;
1923
+ } else {
1924
+ max = 3;
1925
+ }
1926
+
1927
+ let v0, v1, v2, dropped;
1928
+
1929
+ //max will be dropped
1930
+ if (max === 0) {
1931
+ //dropping x
1932
+ v0 = y;
1933
+ v1 = z;
1934
+ v2 = w;
1935
+
1936
+ dropped = x;
1937
+ } else if (max === 1) {
1938
+ //dropping y
1939
+ v0 = x;
1940
+ v1 = z;
1941
+ v2 = w;
1942
+
1943
+ dropped = y;
1944
+ } else if (max === 2) {
1945
+ //dropping z
1946
+ v0 = x;
1947
+ v1 = y;
1948
+ v2 = w;
1949
+
1950
+ dropped = z;
1951
+ } else {
1952
+ //dropping w
1953
+ v0 = x;
1954
+ v1 = y;
1955
+ v2 = z;
1956
+
1957
+ dropped = w;
1958
+ }
1959
+
1960
+ if (dropped < 0) {
1961
+ //reconstructing dropped value is only possible if it is positive, so we invert the quaternion to make dropped value positive
1962
+ v0 = -v0;
1963
+ v1 = -v1;
1964
+ v2 = -v2;
1965
+ }
1966
+
1967
+ const l = Math.sqrt(x * x + y * y + z * z + w * w);
1968
+ const m = 511 / (l * Math.SQRT1_2);
1969
+
1970
+ //re-normalize the remaining components to 10 bit UINT value
1971
+ const oV0 = Math.round(v0 * m + 511);
1972
+ const oV1 = Math.round(v1 * m + 511);
1973
+ const oV2 = Math.round(v2 * m + 511);
1974
+
1975
+ assert.ok(oV0 <= 1023 && oV0 >= 0, `expected 0 <= ov0 <= 1023, instead was '${oV0}'`);
1976
+ assert.ok(oV1 <= 1023 && oV1 >= 0, `expected 0 <= ov1 <= 1023, instead was '${oV1}'`);
1977
+ assert.ok(oV2 <= 1023 && oV2 >= 0, `expected 0 <= ov2 <= 1023, instead was '${oV2}'`);
1978
+
1979
+
1980
+ return (max & 0x3)
1981
+ | ((oV0 & 0x3FF) << 2)
1982
+ | ((oV1 & 0x3FF) << 12)
1983
+ | ((oV2 & 0x3FF) << 22);
1785
1984
  }
1786
1985
 
1787
1986
  /**
@@ -1800,13 +1999,11 @@ function v3_dot(x0, y0, z0, x1, y1, z1) {
1800
1999
 
1801
2000
  /**
1802
2001
  *
1803
- * @param {number} x
1804
- * @param {number} y
1805
- * @param {number} z
1806
- * @return {number}
2002
+ * @param {number} v
2003
+ * @returns {number} +1 if v>0, 0 if v == 0, -1 if v<0
1807
2004
  */
1808
- function v3_length_sqr(x, y, z) {
1809
- return x * x + y * y + z * z;
2005
+ function sign$1(v) {
2006
+ return v > 0 ? 1 : (v < 0 ? -1 : 0);
1810
2007
  }
1811
2008
 
1812
2009
  /**
@@ -1862,6 +2059,110 @@ function v3_angle_cos_between(x0, y0, z0, x1, y1, z1){
1862
2059
  return clamp$1(d / l, -1, 1);
1863
2060
  }
1864
2061
 
2062
+ /**
2063
+ *
2064
+ * @param {BinaryBuffer} buffer
2065
+ * @param {number[]} result
2066
+ * @param {number} result_offset
2067
+ */
2068
+ function v3_binary_equality_decode(buffer, result, result_offset) {
2069
+ const header = buffer.readUint8();
2070
+
2071
+ let x = 0;
2072
+ let y = 0;
2073
+ let z = 0;
2074
+
2075
+ if ((header & 7) === 7) {
2076
+ //all scale components are the same
2077
+ x = buffer.readFloat32();
2078
+ y = x;
2079
+ z = x;
2080
+ } else if ((header & 1) === 1) {
2081
+ //X and Y are the same, Z is different
2082
+ x = buffer.readFloat32();
2083
+ y = x;
2084
+ z = buffer.readFloat32();
2085
+ } else if ((header & 2) === 2) {
2086
+ //Y and Z are the same, X is different
2087
+ x = buffer.readFloat32();
2088
+ y = buffer.readFloat32();
2089
+ z = y;
2090
+ } else if ((header & 4) === 4) {
2091
+ //X and Z are the same, Y is different
2092
+ x = buffer.readFloat32();
2093
+ y = buffer.readFloat32();
2094
+ z = x;
2095
+ } else {
2096
+ //scale components are different
2097
+ x = buffer.readFloat32();
2098
+ y = buffer.readFloat32();
2099
+ z = buffer.readFloat32();
2100
+ }
2101
+
2102
+ result[result_offset] = x;
2103
+ result[result_offset + 1] = y;
2104
+ result[result_offset + 2] = z;
2105
+ }
2106
+
2107
+ /**
2108
+ *
2109
+ * @param {BinaryBuffer} buffer
2110
+ * @param {number} x
2111
+ * @param {number} y
2112
+ * @param {number} z
2113
+ */
2114
+ function v3_binary_equality_encode(buffer, x, y, z){
2115
+
2116
+ let header = 0;
2117
+
2118
+ if (x === y) {
2119
+ header |= 1;
2120
+ }
2121
+
2122
+ if (y === z) {
2123
+ header |= 2;
2124
+ }
2125
+
2126
+ if (x === z) {
2127
+ header |= 4;
2128
+ }
2129
+
2130
+ buffer.writeUint8(header);
2131
+
2132
+ if ((header & 7) === 7) {
2133
+ //all components are the same
2134
+ buffer.writeFloat32(x);
2135
+ } else if (header === 1) {
2136
+ //X and Y are the same, Z is different
2137
+ buffer.writeFloat32(x);
2138
+ buffer.writeFloat32(z);
2139
+ } else if (header === 2) {
2140
+ //Y and Z are the same, X is different
2141
+ buffer.writeFloat32(x);
2142
+ buffer.writeFloat32(y);
2143
+ } else if (header === 4) {
2144
+ //X and Z are the same, Y is different
2145
+ buffer.writeFloat32(x);
2146
+ buffer.writeFloat32(y);
2147
+ } else {
2148
+ //scale components are different
2149
+ buffer.writeFloat32(x);
2150
+ buffer.writeFloat32(y);
2151
+ buffer.writeFloat32(z);
2152
+ }
2153
+ }
2154
+
2155
+ /**
2156
+ *
2157
+ * @param {number} x
2158
+ * @param {number} y
2159
+ * @param {number} z
2160
+ * @return {number}
2161
+ */
2162
+ function v3_length_sqr(x, y, z) {
2163
+ return x * x + y * y + z * z;
2164
+ }
2165
+
1865
2166
  /**
1866
2167
  *
1867
2168
  * @param {Vector3} result
@@ -1933,45 +2234,6 @@ function v3_slerp(
1933
2234
  result.set(x, y, z);
1934
2235
  }
1935
2236
 
1936
- /**
1937
- *
1938
- * @param {number} v
1939
- * @returns {number}
1940
- */
1941
- function computeHashFloat(v) {
1942
- //we break the number up into fractional and whole parts
1943
- const fraction = v % 1;
1944
-
1945
- const whole = v | 0;
1946
-
1947
- //fractional part is scaled up into int32 range, this inexact method, as it will produce 0 hash for values below a certain threshold
1948
- const fractionHash = fraction * 1367130550;
1949
-
1950
- //take XOR of both parts
1951
- return fractionHash ^ whole;
1952
- }
1953
-
1954
- /**
1955
- * Comparison of two numbers with a given tolerance
1956
- * @param {number} a
1957
- * @param {number} b
1958
- * @param {number} tolerance
1959
- * @returns {boolean}
1960
- */
1961
- function epsilonEquals(a, b, tolerance) {
1962
- assert.isNumber(a, 'a');
1963
- assert.isNumber(b, 'b');
1964
- assert.isNumber(tolerance, 'tolerance');
1965
-
1966
- return Math.abs(a - b) <= tolerance;
1967
- }
1968
-
1969
- /**
1970
- * Very small value, used for comparison when compensation for rounding error is required
1971
- * @type {number}
1972
- */
1973
- const EPSILON = 0.000001;
1974
-
1975
2237
  /**
1976
2238
  * @author Alex Goldring
1977
2239
  * @copyright Alex Goldring 2015
@@ -2816,100 +3078,31 @@ let Vector3$1 = class Vector3 {
2816
3078
  /**
2817
3079
  *
2818
3080
  * @param {BinaryBuffer} buffer
3081
+ * @deprecated use dedicated method directly instead
2819
3082
  */
2820
3083
  toBinaryBufferFloat32_EqualityEncoded(buffer) {
2821
3084
  const x = this.x;
2822
3085
  const y = this.y;
2823
3086
  const z = this.z;
2824
3087
 
2825
- let header = 0;
2826
-
2827
- if (x === y) {
2828
- header |= 1;
2829
- }
2830
-
2831
- if (y === z) {
2832
- header |= 2;
2833
- }
2834
-
2835
- if (x === z) {
2836
- header |= 4;
2837
- }
2838
-
2839
- buffer.writeUint8(header);
2840
-
2841
- if ((header & 7) === 7) {
2842
- //all components are the same
2843
- buffer.writeFloat32(x);
2844
- } else if (header === 1) {
2845
- //X and Y are the same, Z is different
2846
- buffer.writeFloat32(x);
2847
- buffer.writeFloat32(z);
2848
- } else if (header === 2) {
2849
- //Y and Z are the same, X is different
2850
- buffer.writeFloat32(x);
2851
- buffer.writeFloat32(y);
2852
- } else if (header === 4) {
2853
- //X and Z are the same, Y is different
2854
- buffer.writeFloat32(x);
2855
- buffer.writeFloat32(y);
2856
- } else {
2857
- //scale components are different
2858
- buffer.writeFloat32(x);
2859
- buffer.writeFloat32(y);
2860
- buffer.writeFloat32(z);
2861
- }
3088
+ v3_binary_equality_encode(buffer, x, y, z);
2862
3089
  }
2863
3090
 
2864
3091
  /**
2865
3092
  * Uses an extra byte for a header. Only writes unique components. Useful for things like scale where all components usually have the same value
2866
3093
  * @param {BinaryBuffer} buffer
3094
+ * @deprecated use dedicated method directly instead
2867
3095
  */
2868
3096
  fromBinaryBufferFloat32_EqualityEncoded(buffer) {
2869
- const header = buffer.readUint8();
2870
-
2871
- let x = 0;
2872
- let y = 0;
2873
- let z = 0;
2874
-
2875
- if ((header & 7) === 7) {
2876
- //all scale components are the same
2877
- x = buffer.readFloat32();
2878
- y = x;
2879
- z = x;
2880
- } else if ((header & 1) === 1) {
2881
- //X and Y are the same, Z is different
2882
- x = buffer.readFloat32();
2883
- y = x;
2884
- z = buffer.readFloat32();
2885
- } else if ((header & 2) === 2) {
2886
- //Y and Z are the same, X is different
2887
- x = buffer.readFloat32();
2888
- y = buffer.readFloat32();
2889
- z = y;
2890
- } else if ((header & 4) === 4) {
2891
- //X and Z are the same, Y is different
2892
- x = buffer.readFloat32();
2893
- y = buffer.readFloat32();
2894
- z = x;
2895
- } else {
2896
- //scale components are different
2897
- x = buffer.readFloat32();
2898
- y = buffer.readFloat32();
2899
- z = buffer.readFloat32();
2900
- }
2901
-
2902
- this.set(x, y, z);
3097
+ v3_binary_equality_decode(buffer, this, 0);
2903
3098
  }
2904
3099
 
2905
3100
  hash() {
2906
- let hash = computeHashFloat(this.x);
2907
-
2908
- hash = ((hash << 5) - hash) + computeHashFloat(this.y);
2909
-
2910
- hash = ((hash << 5) - hash) + computeHashFloat(this.z);
3101
+ const x = computeHashFloat(this.x);
3102
+ const y = computeHashFloat(this.y);
3103
+ const z = computeHashFloat(this.z);
2911
3104
 
2912
- return hash;
3105
+ return x ^ (y << 1) ^ (z << 2);
2913
3106
  }
2914
3107
 
2915
3108
 
@@ -3067,16 +3260,6 @@ Vector3$1.typeName = "Vector3";
3067
3260
  */
3068
3261
  Vector3$1._dot = v3_dot;
3069
3262
 
3070
- /**
3071
- * Returns lowest value out of 2 supplied
3072
- * @param {number} a
3073
- * @param {number} b
3074
- * @returns {number}
3075
- */
3076
- function min2(a, b) {
3077
- return a < b ? a : b;
3078
- }
3079
-
3080
3263
  /**
3081
3264
  * Created by Alex on 10/03/14.
3082
3265
  */
@@ -3086,18 +3269,6 @@ const forward = new Vector3$1();
3086
3269
  const up = new Vector3$1();
3087
3270
  const right = new Vector3$1();
3088
3271
 
3089
- /**
3090
- * just in case you need that function also
3091
- * @param {Vector3} axis
3092
- * @param {number} angle
3093
- * @param {Quaternion} result
3094
- */
3095
- function quat3_createFromAxisAngle(axis, angle, result) {
3096
- const halfAngle = angle * .5;
3097
- const s = Math.sin(halfAngle);
3098
- result.set(axis.x * s, axis.y * s, axis.z * s, Math.cos(halfAngle));
3099
- }
3100
-
3101
3272
  let Quaternion$1 = class Quaternion {
3102
3273
  /**
3103
3274
  *
@@ -4520,31 +4691,7 @@ let Quaternion$1 = class Quaternion {
4520
4691
  * @param {number} value
4521
4692
  */
4522
4693
  decodeFromUint32(value) {
4523
- //read components
4524
- const max = value & 0x3;
4525
-
4526
- const iv0 = (value >> 2) & 0x3FF;
4527
- const iv1 = (value >> 12) & 0x3FF;
4528
- const iv2 = (value >> 22) & 0x3FF;
4529
-
4530
- //scale components back to quaternion range
4531
- const v0 = (iv0 / 511 - 1) * K_CONST;
4532
- const v1 = (iv1 / 511 - 1) * K_CONST;
4533
- const v2 = (iv2 / 511 - 1) * K_CONST;
4534
-
4535
- //restore dropped component using quaternion identity: x^2 + y^2 + z^2 + w^2 = 1
4536
- const dropped_2 = 1 - v0 * v0 - v1 * v1 - v2 * v2;
4537
- const dropped = Math.sqrt(dropped_2);
4538
-
4539
- if (max === 0) {
4540
- this.set(dropped, v0, v1, v2);
4541
- } else if (max === 1) {
4542
- this.set(v0, dropped, v1, v2);
4543
- } else if (max === 2) {
4544
- this.set(v0, v1, dropped, v2);
4545
- } else {
4546
- this.set(v0, v1, v2, dropped);
4547
- }
4694
+ quat_decode_from_uint32(this, 0, value);
4548
4695
  }
4549
4696
 
4550
4697
  /**
@@ -4552,107 +4699,7 @@ let Quaternion$1 = class Quaternion {
4552
4699
  * @returns {number}
4553
4700
  */
4554
4701
  encodeToUint32() {
4555
- const x = this.x;
4556
- const y = this.y;
4557
- const z = this.z;
4558
- const w = this.w;
4559
-
4560
- const absX = Math.abs(x);
4561
- const absY = Math.abs(y);
4562
- const absZ = Math.abs(z);
4563
- const absW = Math.abs(w);
4564
-
4565
- let max = 0;
4566
-
4567
- //pick max component
4568
- if (absY > absX) {
4569
- if (absY > absZ) {
4570
- if (absY > absW) {
4571
- //absY is max
4572
- max = 1;
4573
- } else {
4574
- //absW is max
4575
- max = 3;
4576
- }
4577
- } else if (absZ > absW) {
4578
- //absZ is max
4579
- max = 2;
4580
- } else {
4581
- //absW is max
4582
- max = 3;
4583
- }
4584
- } else if (absX > absZ) {
4585
- if (absX > absW) {
4586
- max = 0;
4587
- } else {
4588
- max = 3;
4589
- }
4590
- } else if (absZ > absW) {
4591
- max = 2;
4592
- } else {
4593
- max = 3;
4594
- }
4595
-
4596
- let v0, v1, v2, dropped;
4597
-
4598
- //max will be dropped
4599
- if (max === 0) {
4600
- //dropping x
4601
- v0 = y;
4602
- v1 = z;
4603
- v2 = w;
4604
-
4605
- dropped = x;
4606
- } else if (max === 1) {
4607
- //dropping y
4608
- v0 = x;
4609
- v1 = z;
4610
- v2 = w;
4611
-
4612
- dropped = y;
4613
- } else if (max === 2) {
4614
- //dropping z
4615
- v0 = x;
4616
- v1 = y;
4617
- v2 = w;
4618
-
4619
- dropped = z;
4620
- } else {
4621
- //dropping w
4622
- v0 = x;
4623
- v1 = y;
4624
- v2 = z;
4625
-
4626
- dropped = w;
4627
- }
4628
-
4629
- if (dropped < 0) {
4630
- //reconstructing dropped value is only possible if it is positive, so we invert the quaternion to make dropped value positive
4631
- v0 = -v0;
4632
- v1 = -v1;
4633
- v2 = -v2;
4634
- }
4635
-
4636
- const l = Math.sqrt(x * x + y * y + z * z + w * w);
4637
- const m = 1 / (l * K_CONST);
4638
-
4639
- //re-normalize the remaining components to 10 bit UINT value
4640
- const oV0 = Math.round((v0 * m + 1) * 511);
4641
- const oV1 = Math.round((v1 * m + 1) * 511);
4642
- const oV2 = Math.round((v2 * m + 1) * 511);
4643
-
4644
- assert.ok(oV0 <= 1023 && oV0 >= 0, `expected 0 <= ov0 <= 1023, instead was '${oV0}'`);
4645
- assert.ok(oV1 <= 1023 && oV1 >= 0, `expected 0 <= ov1 <= 1023, instead was '${oV1}'`);
4646
- assert.ok(oV2 <= 1023 && oV2 >= 0, `expected 0 <= ov2 <= 1023, instead was '${oV2}'`);
4647
-
4648
-
4649
- const result = (max & 0x3)
4650
- | ((oV0 & 0x3FF) << 2)
4651
- | ((oV1 & 0x3FF) << 12)
4652
- | ((oV2 & 0x3FF) << 22)
4653
- ;
4654
-
4655
- return result;
4702
+ return quat_encode_to_uint32(this.x, this.y, this.z, this.w);
4656
4703
  }
4657
4704
 
4658
4705
  /**
@@ -4839,13 +4886,7 @@ Quaternion$1.identity = Object.freeze(new Quaternion$1(0, 0, 0, 1));
4839
4886
  const axis = new Vector3$1();
4840
4887
 
4841
4888
 
4842
- const tempvec3 = new Vector3$1();
4843
-
4844
- /**
4845
- * Used in UINT32 packing
4846
- * @type {number}
4847
- */
4848
- const K_CONST = 0.70710678118; // 1/sqrt(2)
4889
+ const tempvec3 = new Vector3$1();
4849
4890
 
4850
4891
  /**
4851
4892
  * @readonly
@@ -5112,8 +5153,7 @@ class Transform {
5112
5153
  * @returns {boolean}
5113
5154
  */
5114
5155
  equals(other) {
5115
- return other.isTransform
5116
- && this.position.equals(other.position)
5156
+ return this.position.equals(other.position)
5117
5157
  && this.rotation.equals(other.rotation)
5118
5158
  && this.scale.equals(other.scale);
5119
5159
  }
@@ -48947,11 +48987,7 @@ class Vector2 {
48947
48987
  const x = computeHashFloat(this.x);
48948
48988
  const y = computeHashFloat(this.y);
48949
48989
 
48950
- let hash = ((x << 5) - x) + y;
48951
-
48952
- hash |= 0; //convert to 32bit int
48953
-
48954
- return hash;
48990
+ return ((x << 5) - x) + y;
48955
48991
  }
48956
48992
 
48957
48993
  /**
@@ -48962,8 +48998,11 @@ class Vector2 {
48962
48998
  const sin = Math.sin(angle);
48963
48999
  const cos = Math.cos(angle);
48964
49000
 
48965
- const x = this.x * cos - this.y * sin;
48966
- const y = this.x * sin + this.y * cos;
49001
+ const _x = this.x;
49002
+ const _y = this.y;
49003
+
49004
+ const x = _x * cos - _y * sin;
49005
+ const y = _x * sin + _y * cos;
48967
49006
 
48968
49007
  this.set(x, y);
48969
49008
  }
@@ -56786,6 +56825,39 @@ function mortonEncode_magicbits(x, y, z) {
56786
56825
  return x_bits | y_bits | z_bits;
56787
56826
  }
56788
56827
 
56828
+ /**
56829
+ * @param {number} x
56830
+ * @param {number} y
56831
+ * @param {number} z
56832
+ * @param {number[]} bounds
56833
+ * @returns {number}
56834
+ */
56835
+ function v3_morton_encode_bounded(x, y, z, bounds) {
56836
+
56837
+ const bounds_x0 = bounds[0];
56838
+ const bounds_y0 = bounds[1];
56839
+ const bounds_z0 = bounds[2];
56840
+
56841
+ const bounds_x1 = bounds[3];
56842
+ const bounds_y1 = bounds[4];
56843
+ const bounds_z1 = bounds[5];
56844
+
56845
+ const bounds_span_x = bounds_x1 - bounds_x0;
56846
+ const bounds_span_y = bounds_y1 - bounds_y0;
56847
+ const bounds_span_z = bounds_z1 - bounds_z0;
56848
+
56849
+ // scale to 10 bits
56850
+ const ndc_x = 1023 * (x - bounds_x0) / bounds_span_x;
56851
+ const ndc_y = 1023 * (y - bounds_y0) / bounds_span_y;
56852
+ const ndc_z = 1023 * (z - bounds_z0) / bounds_span_z;
56853
+
56854
+ return mortonEncode_magicbits(
56855
+ Math.round(ndc_x),
56856
+ Math.round(ndc_y),
56857
+ Math.round(ndc_z)
56858
+ );
56859
+ }
56860
+
56789
56861
  /**
56790
56862
  * Returns highest value out of 3 supplied
56791
56863
  * @param {number} a
@@ -56848,10 +56920,10 @@ function copy_box_zero_size(data, destination, source) {
56848
56920
  * Assumes data will be normalized to 0...1 value range
56849
56921
  * @param {Float32Array} data
56850
56922
  * @param {number} address
56851
- * @param {number[]} matrix
56923
+ * @param {number[]} bounds
56852
56924
  * @returns {number}
56853
56925
  */
56854
- function build_morton(data, address, matrix) {
56926
+ function build_morton(data, address, bounds) {
56855
56927
 
56856
56928
  const x0 = data[address];
56857
56929
  const y0 = data[address + 1];
@@ -56860,17 +56932,15 @@ function build_morton(data, address, matrix) {
56860
56932
  const y1 = data[address + 4];
56861
56933
  const z1 = data[address + 5];
56862
56934
 
56863
- const cx = (x0 + x1) / 2;
56864
- const cy = (y0 + y1) / 2;
56865
- const cz = (z0 + z1) / 2;
56935
+ const cx = (x0 + x1) * 0.5;
56936
+ const cy = (y0 + y1) * 0.5;
56937
+ const cz = (z0 + z1) * 0.5;
56866
56938
 
56867
- return mortonEncode_magicbits(cx, cy, cz);
56868
- // return v3_morton_encode_transformed(cx, cy, cz, matrix);
56939
+ return v3_morton_encode_bounded(cx, cy, cz, bounds);
56869
56940
 
56870
56941
  }
56871
56942
 
56872
- const scratch_box_0 = new Float32Array(18);
56873
- const stack$8 = [];
56943
+ const stack$8 = SCRATCH_UINT32_TRAVERSAL_STACK;
56874
56944
 
56875
56945
  class BinaryUint32BVH {
56876
56946
  /**
@@ -57101,17 +57171,15 @@ class BinaryUint32BVH {
57101
57171
  * @private
57102
57172
  */
57103
57173
  __compute_bounds_area_of_3_boxes(a, b, c) {
57104
- this.readBounds(a, scratch_box_0, 0);
57105
- this.readBounds(b, scratch_box_0, 6);
57106
- this.readBounds(c, scratch_box_0, 12);
57174
+ const float32 = this.__data_float32;
57107
57175
 
57108
- const x0 = min3(scratch_box_0[0], scratch_box_0[6], scratch_box_0[12]);
57109
- const y0 = min3(scratch_box_0[1], scratch_box_0[7], scratch_box_0[13]);
57110
- const z0 = min3(scratch_box_0[2], scratch_box_0[8], scratch_box_0[14]);
57176
+ const x0 = min3(float32[a + 0], float32[b + 0], float32[c + 0]);
57177
+ const y0 = min3(float32[a + 1], float32[b + 1], float32[c + 1]);
57178
+ const z0 = min3(float32[a + 2], float32[b + 2], float32[c + 2]);
57111
57179
 
57112
- const x1 = max3(scratch_box_0[3], scratch_box_0[9], scratch_box_0[15]);
57113
- const y1 = max3(scratch_box_0[4], scratch_box_0[10], scratch_box_0[16]);
57114
- const z1 = max3(scratch_box_0[5], scratch_box_0[11], scratch_box_0[17]);
57180
+ const x1 = max3(float32[a + 3], float32[b + 3], float32[c + 3]);
57181
+ const y1 = max3(float32[a + 4], float32[b + 4], float32[c + 4]);
57182
+ const z1 = max3(float32[a + 5], float32[b + 5], float32[c + 5]);
57115
57183
 
57116
57184
  return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
57117
57185
  }
@@ -57163,9 +57231,9 @@ class BinaryUint32BVH {
57163
57231
 
57164
57232
  /**
57165
57233
  * Sort leaf nodes according to their morton codes
57166
- * @param {number[]} projection
57234
+ * @param {number[]} bounds
57167
57235
  */
57168
- sort_morton(projection) {
57236
+ sort_morton(bounds) {
57169
57237
 
57170
57238
  const leaf_block_address = this.__node_count_binary * BVH_BINARY_NODE_SIZE;
57171
57239
 
@@ -57195,15 +57263,15 @@ class BinaryUint32BVH {
57195
57263
 
57196
57264
  const pivot_address = pivotIndex * BVH_LEAF_NODE_SIZE + leaf_block_address;
57197
57265
 
57198
- const pivot = build_morton(data, pivot_address);
57266
+ const pivot = build_morton(data, pivot_address, bounds);
57199
57267
 
57200
57268
  /* partition */
57201
57269
  while (i <= j) {
57202
- while (build_morton(data, i * BVH_LEAF_NODE_SIZE + leaf_block_address) < pivot) {
57270
+ while (build_morton(data, i * BVH_LEAF_NODE_SIZE + leaf_block_address, bounds) < pivot) {
57203
57271
  i++;
57204
57272
  }
57205
57273
 
57206
- while (build_morton(data, j * BVH_LEAF_NODE_SIZE + leaf_block_address) > pivot) {
57274
+ while (build_morton(data, j * BVH_LEAF_NODE_SIZE + leaf_block_address, bounds) > pivot) {
57207
57275
  j--;
57208
57276
  }
57209
57277
 
@@ -118645,6 +118713,18 @@ class Blackboard extends AbstractBlackboard {
118645
118713
 
118646
118714
  Blackboard.typeName = 'Blackboard';
118647
118715
 
118716
+ /**
118717
+ * just in case you need that function also
118718
+ * @param {Vector3} axis
118719
+ * @param {number} angle
118720
+ * @param {Quaternion} result
118721
+ */
118722
+ function quat3_createFromAxisAngle(axis, angle, result) {
118723
+ const halfAngle = angle * .5;
118724
+ const s = Math.sin(halfAngle);
118725
+ result.set(axis.x * s, axis.y * s, axis.z * s, Math.cos(halfAngle));
118726
+ }
118727
+
118648
118728
  exports.AmbientOcclusionPostProcessEffect = AmbientOcclusionPostProcessEffect;
118649
118729
  exports.Behavior = Behavior;
118650
118730
  exports.BehaviorStatus = BehaviorStatus;