@woosh/meep-engine 2.69.0 → 2.71.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.
Files changed (50) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/bundle-worker-terrain.js +1 -1
  3. package/build/meep.cjs +498 -429
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +498 -429
  6. package/package.json +1 -1
  7. package/src/core/__module.js +1 -0
  8. package/src/core/binary/BinaryBuffer.js +37 -31
  9. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +21 -24
  10. package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +2 -4
  11. package/src/core/geom/3d/cone/compute_bounding_cone_of_2_cones.js +3 -2
  12. package/src/core/geom/3d/morton/v3_morton_encode_bounded.js +34 -0
  13. package/src/core/geom/3d/morton/v3_morton_encode_transformed.js +2 -1
  14. package/src/core/geom/3d/quaternion/quat3_createFromAxisAngle.js +11 -0
  15. package/src/core/geom/3d/quaternion/quat_decode_from_uint32.js +53 -0
  16. package/src/core/geom/3d/quaternion/quat_encode_to_uint32.js +105 -0
  17. package/src/core/geom/Quaternion.js +8 -142
  18. package/src/core/geom/Vector2.js +6 -7
  19. package/src/core/geom/Vector3.js +15 -82
  20. package/src/core/geom/vec3/v3_binary_equality_decode.js +44 -0
  21. package/src/core/geom/vec3/v3_binary_equality_encode.js +47 -0
  22. package/src/core/math/remap.js +5 -1
  23. package/src/core/math/statistics/computeStatisticalPartialMedian.js +1 -1
  24. package/src/core/primitives/numbers/computeHashFloat.js +2 -2
  25. package/src/core/process/task/Task.js +53 -34
  26. package/src/engine/achievements/AchievementManager.js +19 -19
  27. package/src/engine/animation/curve/compression/prototypeCurveCompression.js +6 -6
  28. package/src/engine/animation/curve/draw/build_plot_entity_from_array.js +11 -6
  29. package/src/engine/ecs/dynamic_actions/DynamicActor.js +5 -10
  30. package/src/engine/ecs/dynamic_actions/DynamicActorSystem.js +82 -89
  31. package/src/engine/ecs/dynamic_actions/RuleExecution.js +10 -12
  32. package/src/engine/ecs/gui/GUIElement.js +44 -61
  33. package/src/engine/ecs/gui/GUIElementSystem.js +26 -24
  34. package/src/engine/ecs/gui/hud/HeadsUpDisplay.js +12 -15
  35. package/src/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +15 -15
  36. package/src/engine/ecs/gui/parallax/GuiElementParallax.js +3 -3
  37. package/src/engine/ecs/gui/parallax/GuiElementParallaxSystem.js +2 -2
  38. package/src/engine/ecs/gui/position/ViewportPosition.js +5 -50
  39. package/src/engine/ecs/gui/position/ViewportPositionSerializationAdapter.js +42 -0
  40. package/src/engine/ecs/transform/Transform.js +8 -9
  41. package/src/engine/ecs/transform/TransformSerializationAdapter.js +20 -14
  42. package/src/engine/graphics/ecs/mesh/Mesh.js +11 -11
  43. package/src/engine/graphics/impostors/octahedral/prototypeBaker.js +20 -20
  44. package/src/engine/graphics/texture/sprite/prototypeSpriteCutoutGeometry.js +12 -12
  45. package/src/engine/navigation/ecs/components/PathSerializationAdapter.js +1 -4
  46. package/src/core/binary/ValidatingBitSetWrapper.js +0 -81
  47. package/src/core/binary/jsonToStringToByteArray.js +0 -27
  48. package/src/engine/ecs/components/AreaOfEffect.js +0 -12
  49. package/src/engine/ecs/components/Mortality.js +0 -27
  50. package/src/engine/ecs/systems/AreaOfEffectSystem.js +0 -48
@@ -1762,6 +1762,27 @@ function clamp$1(value, min, max) {
1762
1762
  }
1763
1763
  }
1764
1764
 
1765
+ /**
1766
+ * Very small value, used for comparison when compensation for rounding error is required
1767
+ * @type {number}
1768
+ */
1769
+ const EPSILON = 0.000001;
1770
+
1771
+ /**
1772
+ * Comparison of two numbers with a given tolerance
1773
+ * @param {number} a
1774
+ * @param {number} b
1775
+ * @param {number} tolerance
1776
+ * @returns {boolean}
1777
+ */
1778
+ function epsilonEquals(a, b, tolerance) {
1779
+ assert.isNumber(a, 'a');
1780
+ assert.isNumber(b, 'b');
1781
+ assert.isNumber(tolerance, 'tolerance');
1782
+
1783
+ return Math.abs(a - b) <= tolerance;
1784
+ }
1785
+
1765
1786
  /**
1766
1787
  * Linear interpolation between two values controlled by a given fraction
1767
1788
  * @param {number} a
@@ -1773,13 +1794,190 @@ function lerp$1(a, b, fraction) {
1773
1794
  return (b - a) * fraction + a;
1774
1795
  }
1775
1796
 
1797
+ /**
1798
+ * Returns lowest value out of 2 supplied
1799
+ * @param {number} a
1800
+ * @param {number} b
1801
+ * @returns {number}
1802
+ */
1803
+ function min2(a, b) {
1804
+ return a < b ? a : b;
1805
+ }
1806
+
1776
1807
  /**
1777
1808
  *
1778
1809
  * @param {number} v
1779
- * @returns {number} +1 if v>0, 0 if v == 0, -1 if v<0
1810
+ * @returns {number}
1780
1811
  */
1781
- function sign$1(v) {
1782
- return v > 0 ? 1 : (v < 0 ? -1 : 0);
1812
+ function computeHashFloat(v) {
1813
+ //we break the number up into fractional and whole parts
1814
+ const whole = v | 0;
1815
+
1816
+ const fraction = v - whole;
1817
+
1818
+ //fractional part is scaled up into int32 range, this inexact method, as it will produce 0 hash for values below a certain threshold
1819
+ const fractionHash = fraction * 1367130550;
1820
+
1821
+ //take XOR of both parts
1822
+ return fractionHash ^ whole;
1823
+ }
1824
+
1825
+ const K = Math.SQRT1_2 / 511;
1826
+
1827
+ /**
1828
+ * Based on GDC talk from Bungie on destiny, compressing quaternions for animation
1829
+ * @param {number[]} output
1830
+ * @param {number} output_offset
1831
+ * @param {number} value
1832
+ */
1833
+ function quat_decode_from_uint32(output, output_offset, value) {
1834
+ //read components
1835
+ const max = value & 0x3;
1836
+
1837
+ const iv0 = (value >> 2) & 0x3FF;
1838
+ const iv1 = (value >> 12) & 0x3FF;
1839
+ const iv2 = (value >> 22) & 0x3FF;
1840
+
1841
+ //scale components back to quaternion range
1842
+ const v0 = iv0 * K - Math.SQRT1_2;
1843
+ const v1 = iv1 * K - Math.SQRT1_2;
1844
+ const v2 = iv2 * K - Math.SQRT1_2;
1845
+
1846
+ //restore dropped component using quaternion identity: x^2 + y^2 + z^2 + w^2 = 1
1847
+ const dropped_2 = 1 - v0 * v0 - v1 * v1 - v2 * v2;
1848
+ const dropped = Math.sqrt(dropped_2);
1849
+
1850
+ let x, y, z, w;
1851
+ if (max === 0) {
1852
+ x = dropped;
1853
+ y = v0;
1854
+ z = v1;
1855
+ w = v2;
1856
+ } else if (max === 1) {
1857
+ x = v0;
1858
+ y = dropped;
1859
+ z = v1;
1860
+ w = v2;
1861
+ } else if (max === 2) {
1862
+ x = v0;
1863
+ y = v1;
1864
+ z = dropped;
1865
+ w = v2;
1866
+ } else {
1867
+ x = v0;
1868
+ y = v1;
1869
+ z = v2;
1870
+ w = dropped;
1871
+ }
1872
+
1873
+ output[output_offset] = x;
1874
+ output[output_offset + 1] = y;
1875
+ output[output_offset + 2] = z;
1876
+ output[output_offset + 3] = w;
1877
+ }
1878
+
1879
+ /**
1880
+ * Based on GDC talk from Bungie on destiny, compressing quaternions for animation
1881
+ * @param {number} x
1882
+ * @param {number} y
1883
+ * @param {number} z
1884
+ * @param {number} w
1885
+ * @returns {number}
1886
+ */
1887
+ function quat_encode_to_uint32(x, y, z, w) {
1888
+
1889
+ const absX = Math.abs(x);
1890
+ const absY = Math.abs(y);
1891
+ const absZ = Math.abs(z);
1892
+ const absW = Math.abs(w);
1893
+
1894
+ let v0, v1, v2, dropped, max;
1895
+
1896
+ //pick max component
1897
+ if (absY > absX) {
1898
+ if (absY > absZ) {
1899
+ if (absY > absW) {
1900
+ //absY is max
1901
+ max = 1;
1902
+ } else {
1903
+ //absW is max
1904
+ max = 3;
1905
+ }
1906
+ } else if (absZ > absW) {
1907
+ //absZ is max
1908
+ max = 2;
1909
+ } else {
1910
+ //absW is max
1911
+ max = 3;
1912
+ }
1913
+ } else if (absX > absZ) {
1914
+ if (absX > absW) {
1915
+ max = 0;
1916
+ } else {
1917
+ max = 3;
1918
+ }
1919
+ } else if (absZ > absW) {
1920
+ max = 2;
1921
+ } else {
1922
+ max = 3;
1923
+ }
1924
+
1925
+
1926
+ //max will be dropped
1927
+ if (max === 0) {
1928
+ //dropping x
1929
+ v0 = y;
1930
+ v1 = z;
1931
+ v2 = w;
1932
+
1933
+ dropped = x;
1934
+ } else if (max === 1) {
1935
+ //dropping y
1936
+ v0 = x;
1937
+ v1 = z;
1938
+ v2 = w;
1939
+
1940
+ dropped = y;
1941
+ } else if (max === 2) {
1942
+ //dropping z
1943
+ v0 = x;
1944
+ v1 = y;
1945
+ v2 = w;
1946
+
1947
+ dropped = z;
1948
+ } else {
1949
+ //dropping w
1950
+ v0 = x;
1951
+ v1 = y;
1952
+ v2 = z;
1953
+
1954
+ dropped = w;
1955
+ }
1956
+
1957
+ if (dropped < 0) {
1958
+ //reconstructing dropped value is only possible if it is positive, so we invert the quaternion to make dropped value positive
1959
+ v0 = -v0;
1960
+ v1 = -v1;
1961
+ v2 = -v2;
1962
+ }
1963
+
1964
+ const l = Math.hypot(v0, v1, v2, dropped);
1965
+ const m = 511 / (l * Math.SQRT1_2);
1966
+
1967
+ //re-normalize the remaining components to 10 bit UINT value
1968
+ const oV0 = Math.round(v0 * m + 511);
1969
+ const oV1 = Math.round(v1 * m + 511);
1970
+ const oV2 = Math.round(v2 * m + 511);
1971
+
1972
+ assert.ok(oV0 <= 1023 && oV0 >= 0, `expected 0 <= ov0 <= 1023, instead was '${oV0}'`);
1973
+ assert.ok(oV1 <= 1023 && oV1 >= 0, `expected 0 <= ov1 <= 1023, instead was '${oV1}'`);
1974
+ assert.ok(oV2 <= 1023 && oV2 >= 0, `expected 0 <= ov2 <= 1023, instead was '${oV2}'`);
1975
+
1976
+
1977
+ return (max & 0x3)
1978
+ | ((oV0 & 0x3FF) << 2)
1979
+ | ((oV1 & 0x3FF) << 12)
1980
+ | ((oV2 & 0x3FF) << 22);
1783
1981
  }
1784
1982
 
1785
1983
  /**
@@ -1798,13 +1996,11 @@ function v3_dot(x0, y0, z0, x1, y1, z1) {
1798
1996
 
1799
1997
  /**
1800
1998
  *
1801
- * @param {number} x
1802
- * @param {number} y
1803
- * @param {number} z
1804
- * @return {number}
1999
+ * @param {number} v
2000
+ * @returns {number} +1 if v>0, 0 if v == 0, -1 if v<0
1805
2001
  */
1806
- function v3_length_sqr(x, y, z) {
1807
- return x * x + y * y + z * z;
2002
+ function sign$1(v) {
2003
+ return v > 0 ? 1 : (v < 0 ? -1 : 0);
1808
2004
  }
1809
2005
 
1810
2006
  /**
@@ -1860,6 +2056,110 @@ function v3_angle_cos_between(x0, y0, z0, x1, y1, z1){
1860
2056
  return clamp$1(d / l, -1, 1);
1861
2057
  }
1862
2058
 
2059
+ /**
2060
+ *
2061
+ * @param {BinaryBuffer} buffer
2062
+ * @param {number[]} result
2063
+ * @param {number} result_offset
2064
+ */
2065
+ function v3_binary_equality_decode(buffer, result, result_offset) {
2066
+ const header = buffer.readUint8();
2067
+
2068
+ let x = 0;
2069
+ let y = 0;
2070
+ let z = 0;
2071
+
2072
+ if ((header & 7) === 7) {
2073
+ //all scale components are the same
2074
+ x = buffer.readFloat32();
2075
+ y = x;
2076
+ z = x;
2077
+ } else if ((header & 1) === 1) {
2078
+ //X and Y are the same, Z is different
2079
+ x = buffer.readFloat32();
2080
+ y = x;
2081
+ z = buffer.readFloat32();
2082
+ } else if ((header & 2) === 2) {
2083
+ //Y and Z are the same, X is different
2084
+ x = buffer.readFloat32();
2085
+ y = buffer.readFloat32();
2086
+ z = y;
2087
+ } else if ((header & 4) === 4) {
2088
+ //X and Z are the same, Y is different
2089
+ x = buffer.readFloat32();
2090
+ y = buffer.readFloat32();
2091
+ z = x;
2092
+ } else {
2093
+ //scale components are different
2094
+ x = buffer.readFloat32();
2095
+ y = buffer.readFloat32();
2096
+ z = buffer.readFloat32();
2097
+ }
2098
+
2099
+ result[result_offset] = x;
2100
+ result[result_offset + 1] = y;
2101
+ result[result_offset + 2] = z;
2102
+ }
2103
+
2104
+ /**
2105
+ *
2106
+ * @param {BinaryBuffer} buffer
2107
+ * @param {number} x
2108
+ * @param {number} y
2109
+ * @param {number} z
2110
+ */
2111
+ function v3_binary_equality_encode(buffer, x, y, z){
2112
+
2113
+ let header = 0;
2114
+
2115
+ if (x === y) {
2116
+ header |= 1;
2117
+ }
2118
+
2119
+ if (y === z) {
2120
+ header |= 2;
2121
+ }
2122
+
2123
+ if (x === z) {
2124
+ header |= 4;
2125
+ }
2126
+
2127
+ buffer.writeUint8(header);
2128
+
2129
+ if ((header & 7) === 7) {
2130
+ //all components are the same
2131
+ buffer.writeFloat32(x);
2132
+ } else if (header === 1) {
2133
+ //X and Y are the same, Z is different
2134
+ buffer.writeFloat32(x);
2135
+ buffer.writeFloat32(z);
2136
+ } else if (header === 2) {
2137
+ //Y and Z are the same, X is different
2138
+ buffer.writeFloat32(x);
2139
+ buffer.writeFloat32(y);
2140
+ } else if (header === 4) {
2141
+ //X and Z are the same, Y is different
2142
+ buffer.writeFloat32(x);
2143
+ buffer.writeFloat32(y);
2144
+ } else {
2145
+ //scale components are different
2146
+ buffer.writeFloat32(x);
2147
+ buffer.writeFloat32(y);
2148
+ buffer.writeFloat32(z);
2149
+ }
2150
+ }
2151
+
2152
+ /**
2153
+ *
2154
+ * @param {number} x
2155
+ * @param {number} y
2156
+ * @param {number} z
2157
+ * @return {number}
2158
+ */
2159
+ function v3_length_sqr(x, y, z) {
2160
+ return x * x + y * y + z * z;
2161
+ }
2162
+
1863
2163
  /**
1864
2164
  *
1865
2165
  * @param {Vector3} result
@@ -1931,45 +2231,6 @@ function v3_slerp(
1931
2231
  result.set(x, y, z);
1932
2232
  }
1933
2233
 
1934
- /**
1935
- *
1936
- * @param {number} v
1937
- * @returns {number}
1938
- */
1939
- function computeHashFloat(v) {
1940
- //we break the number up into fractional and whole parts
1941
- const fraction = v % 1;
1942
-
1943
- const whole = v | 0;
1944
-
1945
- //fractional part is scaled up into int32 range, this inexact method, as it will produce 0 hash for values below a certain threshold
1946
- const fractionHash = fraction * 1367130550;
1947
-
1948
- //take XOR of both parts
1949
- return fractionHash ^ whole;
1950
- }
1951
-
1952
- /**
1953
- * Comparison of two numbers with a given tolerance
1954
- * @param {number} a
1955
- * @param {number} b
1956
- * @param {number} tolerance
1957
- * @returns {boolean}
1958
- */
1959
- function epsilonEquals(a, b, tolerance) {
1960
- assert.isNumber(a, 'a');
1961
- assert.isNumber(b, 'b');
1962
- assert.isNumber(tolerance, 'tolerance');
1963
-
1964
- return Math.abs(a - b) <= tolerance;
1965
- }
1966
-
1967
- /**
1968
- * Very small value, used for comparison when compensation for rounding error is required
1969
- * @type {number}
1970
- */
1971
- const EPSILON = 0.000001;
1972
-
1973
2234
  /**
1974
2235
  * @author Alex Goldring
1975
2236
  * @copyright Alex Goldring 2015
@@ -2814,100 +3075,31 @@ let Vector3$1 = class Vector3 {
2814
3075
  /**
2815
3076
  *
2816
3077
  * @param {BinaryBuffer} buffer
3078
+ * @deprecated use dedicated method directly instead
2817
3079
  */
2818
3080
  toBinaryBufferFloat32_EqualityEncoded(buffer) {
2819
3081
  const x = this.x;
2820
3082
  const y = this.y;
2821
3083
  const z = this.z;
2822
3084
 
2823
- let header = 0;
2824
-
2825
- if (x === y) {
2826
- header |= 1;
2827
- }
2828
-
2829
- if (y === z) {
2830
- header |= 2;
2831
- }
2832
-
2833
- if (x === z) {
2834
- header |= 4;
2835
- }
2836
-
2837
- buffer.writeUint8(header);
2838
-
2839
- if ((header & 7) === 7) {
2840
- //all components are the same
2841
- buffer.writeFloat32(x);
2842
- } else if (header === 1) {
2843
- //X and Y are the same, Z is different
2844
- buffer.writeFloat32(x);
2845
- buffer.writeFloat32(z);
2846
- } else if (header === 2) {
2847
- //Y and Z are the same, X is different
2848
- buffer.writeFloat32(x);
2849
- buffer.writeFloat32(y);
2850
- } else if (header === 4) {
2851
- //X and Z are the same, Y is different
2852
- buffer.writeFloat32(x);
2853
- buffer.writeFloat32(y);
2854
- } else {
2855
- //scale components are different
2856
- buffer.writeFloat32(x);
2857
- buffer.writeFloat32(y);
2858
- buffer.writeFloat32(z);
2859
- }
3085
+ v3_binary_equality_encode(buffer, x, y, z);
2860
3086
  }
2861
3087
 
2862
3088
  /**
2863
3089
  * Uses an extra byte for a header. Only writes unique components. Useful for things like scale where all components usually have the same value
2864
3090
  * @param {BinaryBuffer} buffer
3091
+ * @deprecated use dedicated method directly instead
2865
3092
  */
2866
3093
  fromBinaryBufferFloat32_EqualityEncoded(buffer) {
2867
- const header = buffer.readUint8();
2868
-
2869
- let x = 0;
2870
- let y = 0;
2871
- let z = 0;
2872
-
2873
- if ((header & 7) === 7) {
2874
- //all scale components are the same
2875
- x = buffer.readFloat32();
2876
- y = x;
2877
- z = x;
2878
- } else if ((header & 1) === 1) {
2879
- //X and Y are the same, Z is different
2880
- x = buffer.readFloat32();
2881
- y = x;
2882
- z = buffer.readFloat32();
2883
- } else if ((header & 2) === 2) {
2884
- //Y and Z are the same, X is different
2885
- x = buffer.readFloat32();
2886
- y = buffer.readFloat32();
2887
- z = y;
2888
- } else if ((header & 4) === 4) {
2889
- //X and Z are the same, Y is different
2890
- x = buffer.readFloat32();
2891
- y = buffer.readFloat32();
2892
- z = x;
2893
- } else {
2894
- //scale components are different
2895
- x = buffer.readFloat32();
2896
- y = buffer.readFloat32();
2897
- z = buffer.readFloat32();
2898
- }
2899
-
2900
- this.set(x, y, z);
3094
+ v3_binary_equality_decode(buffer, this, 0);
2901
3095
  }
2902
3096
 
2903
3097
  hash() {
2904
- let hash = computeHashFloat(this.x);
2905
-
2906
- hash = ((hash << 5) - hash) + computeHashFloat(this.y);
2907
-
2908
- hash = ((hash << 5) - hash) + computeHashFloat(this.z);
3098
+ const x = computeHashFloat(this.x);
3099
+ const y = computeHashFloat(this.y);
3100
+ const z = computeHashFloat(this.z);
2909
3101
 
2910
- return hash;
3102
+ return x ^ (y << 1) ^ (z << 2);
2911
3103
  }
2912
3104
 
2913
3105
 
@@ -3065,16 +3257,6 @@ Vector3$1.typeName = "Vector3";
3065
3257
  */
3066
3258
  Vector3$1._dot = v3_dot;
3067
3259
 
3068
- /**
3069
- * Returns lowest value out of 2 supplied
3070
- * @param {number} a
3071
- * @param {number} b
3072
- * @returns {number}
3073
- */
3074
- function min2(a, b) {
3075
- return a < b ? a : b;
3076
- }
3077
-
3078
3260
  /**
3079
3261
  * Created by Alex on 10/03/14.
3080
3262
  */
@@ -3084,18 +3266,6 @@ const forward = new Vector3$1();
3084
3266
  const up = new Vector3$1();
3085
3267
  const right = new Vector3$1();
3086
3268
 
3087
- /**
3088
- * just in case you need that function also
3089
- * @param {Vector3} axis
3090
- * @param {number} angle
3091
- * @param {Quaternion} result
3092
- */
3093
- function quat3_createFromAxisAngle(axis, angle, result) {
3094
- const halfAngle = angle * .5;
3095
- const s = Math.sin(halfAngle);
3096
- result.set(axis.x * s, axis.y * s, axis.z * s, Math.cos(halfAngle));
3097
- }
3098
-
3099
3269
  let Quaternion$1 = class Quaternion {
3100
3270
  /**
3101
3271
  *
@@ -4518,31 +4688,7 @@ let Quaternion$1 = class Quaternion {
4518
4688
  * @param {number} value
4519
4689
  */
4520
4690
  decodeFromUint32(value) {
4521
- //read components
4522
- const max = value & 0x3;
4523
-
4524
- const iv0 = (value >> 2) & 0x3FF;
4525
- const iv1 = (value >> 12) & 0x3FF;
4526
- const iv2 = (value >> 22) & 0x3FF;
4527
-
4528
- //scale components back to quaternion range
4529
- const v0 = (iv0 / 511 - 1) * K_CONST;
4530
- const v1 = (iv1 / 511 - 1) * K_CONST;
4531
- const v2 = (iv2 / 511 - 1) * K_CONST;
4532
-
4533
- //restore dropped component using quaternion identity: x^2 + y^2 + z^2 + w^2 = 1
4534
- const dropped_2 = 1 - v0 * v0 - v1 * v1 - v2 * v2;
4535
- const dropped = Math.sqrt(dropped_2);
4536
-
4537
- if (max === 0) {
4538
- this.set(dropped, v0, v1, v2);
4539
- } else if (max === 1) {
4540
- this.set(v0, dropped, v1, v2);
4541
- } else if (max === 2) {
4542
- this.set(v0, v1, dropped, v2);
4543
- } else {
4544
- this.set(v0, v1, v2, dropped);
4545
- }
4691
+ quat_decode_from_uint32(this, 0, value);
4546
4692
  }
4547
4693
 
4548
4694
  /**
@@ -4550,107 +4696,7 @@ let Quaternion$1 = class Quaternion {
4550
4696
  * @returns {number}
4551
4697
  */
4552
4698
  encodeToUint32() {
4553
- const x = this.x;
4554
- const y = this.y;
4555
- const z = this.z;
4556
- const w = this.w;
4557
-
4558
- const absX = Math.abs(x);
4559
- const absY = Math.abs(y);
4560
- const absZ = Math.abs(z);
4561
- const absW = Math.abs(w);
4562
-
4563
- let max = 0;
4564
-
4565
- //pick max component
4566
- if (absY > absX) {
4567
- if (absY > absZ) {
4568
- if (absY > absW) {
4569
- //absY is max
4570
- max = 1;
4571
- } else {
4572
- //absW is max
4573
- max = 3;
4574
- }
4575
- } else if (absZ > absW) {
4576
- //absZ is max
4577
- max = 2;
4578
- } else {
4579
- //absW is max
4580
- max = 3;
4581
- }
4582
- } else if (absX > absZ) {
4583
- if (absX > absW) {
4584
- max = 0;
4585
- } else {
4586
- max = 3;
4587
- }
4588
- } else if (absZ > absW) {
4589
- max = 2;
4590
- } else {
4591
- max = 3;
4592
- }
4593
-
4594
- let v0, v1, v2, dropped;
4595
-
4596
- //max will be dropped
4597
- if (max === 0) {
4598
- //dropping x
4599
- v0 = y;
4600
- v1 = z;
4601
- v2 = w;
4602
-
4603
- dropped = x;
4604
- } else if (max === 1) {
4605
- //dropping y
4606
- v0 = x;
4607
- v1 = z;
4608
- v2 = w;
4609
-
4610
- dropped = y;
4611
- } else if (max === 2) {
4612
- //dropping z
4613
- v0 = x;
4614
- v1 = y;
4615
- v2 = w;
4616
-
4617
- dropped = z;
4618
- } else {
4619
- //dropping w
4620
- v0 = x;
4621
- v1 = y;
4622
- v2 = z;
4623
-
4624
- dropped = w;
4625
- }
4626
-
4627
- if (dropped < 0) {
4628
- //reconstructing dropped value is only possible if it is positive, so we invert the quaternion to make dropped value positive
4629
- v0 = -v0;
4630
- v1 = -v1;
4631
- v2 = -v2;
4632
- }
4633
-
4634
- const l = Math.sqrt(x * x + y * y + z * z + w * w);
4635
- const m = 1 / (l * K_CONST);
4636
-
4637
- //re-normalize the remaining components to 10 bit UINT value
4638
- const oV0 = Math.round((v0 * m + 1) * 511);
4639
- const oV1 = Math.round((v1 * m + 1) * 511);
4640
- const oV2 = Math.round((v2 * m + 1) * 511);
4641
-
4642
- assert.ok(oV0 <= 1023 && oV0 >= 0, `expected 0 <= ov0 <= 1023, instead was '${oV0}'`);
4643
- assert.ok(oV1 <= 1023 && oV1 >= 0, `expected 0 <= ov1 <= 1023, instead was '${oV1}'`);
4644
- assert.ok(oV2 <= 1023 && oV2 >= 0, `expected 0 <= ov2 <= 1023, instead was '${oV2}'`);
4645
-
4646
-
4647
- const result = (max & 0x3)
4648
- | ((oV0 & 0x3FF) << 2)
4649
- | ((oV1 & 0x3FF) << 12)
4650
- | ((oV2 & 0x3FF) << 22)
4651
- ;
4652
-
4653
- return result;
4699
+ return quat_encode_to_uint32(this.x, this.y, this.z, this.w);
4654
4700
  }
4655
4701
 
4656
4702
  /**
@@ -4837,13 +4883,7 @@ Quaternion$1.identity = Object.freeze(new Quaternion$1(0, 0, 0, 1));
4837
4883
  const axis = new Vector3$1();
4838
4884
 
4839
4885
 
4840
- const tempvec3 = new Vector3$1();
4841
-
4842
- /**
4843
- * Used in UINT32 packing
4844
- * @type {number}
4845
- */
4846
- const K_CONST = 0.70710678118; // 1/sqrt(2)
4886
+ const tempvec3 = new Vector3$1();
4847
4887
 
4848
4888
  /**
4849
4889
  * @readonly
@@ -5110,8 +5150,7 @@ class Transform {
5110
5150
  * @returns {boolean}
5111
5151
  */
5112
5152
  equals(other) {
5113
- return other.isTransform
5114
- && this.position.equals(other.position)
5153
+ return this.position.equals(other.position)
5115
5154
  && this.rotation.equals(other.rotation)
5116
5155
  && this.scale.equals(other.scale);
5117
5156
  }
@@ -48945,11 +48984,7 @@ class Vector2 {
48945
48984
  const x = computeHashFloat(this.x);
48946
48985
  const y = computeHashFloat(this.y);
48947
48986
 
48948
- let hash = ((x << 5) - x) + y;
48949
-
48950
- hash |= 0; //convert to 32bit int
48951
-
48952
- return hash;
48987
+ return ((x << 5) - x) + y;
48953
48988
  }
48954
48989
 
48955
48990
  /**
@@ -48960,8 +48995,11 @@ class Vector2 {
48960
48995
  const sin = Math.sin(angle);
48961
48996
  const cos = Math.cos(angle);
48962
48997
 
48963
- const x = this.x * cos - this.y * sin;
48964
- const y = this.x * sin + this.y * cos;
48998
+ const _x = this.x;
48999
+ const _y = this.y;
49000
+
49001
+ const x = _x * cos - _y * sin;
49002
+ const y = _x * sin + _y * cos;
48965
49003
 
48966
49004
  this.set(x, y);
48967
49005
  }
@@ -56784,6 +56822,39 @@ function mortonEncode_magicbits(x, y, z) {
56784
56822
  return x_bits | y_bits | z_bits;
56785
56823
  }
56786
56824
 
56825
+ /**
56826
+ * @param {number} x
56827
+ * @param {number} y
56828
+ * @param {number} z
56829
+ * @param {number[]} bounds
56830
+ * @returns {number}
56831
+ */
56832
+ function v3_morton_encode_bounded(x, y, z, bounds) {
56833
+
56834
+ const bounds_x0 = bounds[0];
56835
+ const bounds_y0 = bounds[1];
56836
+ const bounds_z0 = bounds[2];
56837
+
56838
+ const bounds_x1 = bounds[3];
56839
+ const bounds_y1 = bounds[4];
56840
+ const bounds_z1 = bounds[5];
56841
+
56842
+ const bounds_span_x = bounds_x1 - bounds_x0;
56843
+ const bounds_span_y = bounds_y1 - bounds_y0;
56844
+ const bounds_span_z = bounds_z1 - bounds_z0;
56845
+
56846
+ // scale to 10 bits
56847
+ const ndc_x = 1023 * (x - bounds_x0) / bounds_span_x;
56848
+ const ndc_y = 1023 * (y - bounds_y0) / bounds_span_y;
56849
+ const ndc_z = 1023 * (z - bounds_z0) / bounds_span_z;
56850
+
56851
+ return mortonEncode_magicbits(
56852
+ Math.round(ndc_x),
56853
+ Math.round(ndc_y),
56854
+ Math.round(ndc_z)
56855
+ );
56856
+ }
56857
+
56787
56858
  /**
56788
56859
  * Returns highest value out of 3 supplied
56789
56860
  * @param {number} a
@@ -56846,10 +56917,10 @@ function copy_box_zero_size(data, destination, source) {
56846
56917
  * Assumes data will be normalized to 0...1 value range
56847
56918
  * @param {Float32Array} data
56848
56919
  * @param {number} address
56849
- * @param {number[]} matrix
56920
+ * @param {number[]} bounds
56850
56921
  * @returns {number}
56851
56922
  */
56852
- function build_morton(data, address, matrix) {
56923
+ function build_morton(data, address, bounds) {
56853
56924
 
56854
56925
  const x0 = data[address];
56855
56926
  const y0 = data[address + 1];
@@ -56858,17 +56929,15 @@ function build_morton(data, address, matrix) {
56858
56929
  const y1 = data[address + 4];
56859
56930
  const z1 = data[address + 5];
56860
56931
 
56861
- const cx = (x0 + x1) / 2;
56862
- const cy = (y0 + y1) / 2;
56863
- const cz = (z0 + z1) / 2;
56932
+ const cx = (x0 + x1) * 0.5;
56933
+ const cy = (y0 + y1) * 0.5;
56934
+ const cz = (z0 + z1) * 0.5;
56864
56935
 
56865
- return mortonEncode_magicbits(cx, cy, cz);
56866
- // return v3_morton_encode_transformed(cx, cy, cz, matrix);
56936
+ return v3_morton_encode_bounded(cx, cy, cz, bounds);
56867
56937
 
56868
56938
  }
56869
56939
 
56870
- const scratch_box_0 = new Float32Array(18);
56871
- const stack$8 = [];
56940
+ const stack$8 = SCRATCH_UINT32_TRAVERSAL_STACK;
56872
56941
 
56873
56942
  class BinaryUint32BVH {
56874
56943
  /**
@@ -57099,17 +57168,15 @@ class BinaryUint32BVH {
57099
57168
  * @private
57100
57169
  */
57101
57170
  __compute_bounds_area_of_3_boxes(a, b, c) {
57102
- this.readBounds(a, scratch_box_0, 0);
57103
- this.readBounds(b, scratch_box_0, 6);
57104
- this.readBounds(c, scratch_box_0, 12);
57171
+ const float32 = this.__data_float32;
57105
57172
 
57106
- const x0 = min3(scratch_box_0[0], scratch_box_0[6], scratch_box_0[12]);
57107
- const y0 = min3(scratch_box_0[1], scratch_box_0[7], scratch_box_0[13]);
57108
- const z0 = min3(scratch_box_0[2], scratch_box_0[8], scratch_box_0[14]);
57173
+ const x0 = min3(float32[a + 0], float32[b + 0], float32[c + 0]);
57174
+ const y0 = min3(float32[a + 1], float32[b + 1], float32[c + 1]);
57175
+ const z0 = min3(float32[a + 2], float32[b + 2], float32[c + 2]);
57109
57176
 
57110
- const x1 = max3(scratch_box_0[3], scratch_box_0[9], scratch_box_0[15]);
57111
- const y1 = max3(scratch_box_0[4], scratch_box_0[10], scratch_box_0[16]);
57112
- const z1 = max3(scratch_box_0[5], scratch_box_0[11], scratch_box_0[17]);
57177
+ const x1 = max3(float32[a + 3], float32[b + 3], float32[c + 3]);
57178
+ const y1 = max3(float32[a + 4], float32[b + 4], float32[c + 4]);
57179
+ const z1 = max3(float32[a + 5], float32[b + 5], float32[c + 5]);
57113
57180
 
57114
57181
  return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
57115
57182
  }
@@ -57161,9 +57228,9 @@ class BinaryUint32BVH {
57161
57228
 
57162
57229
  /**
57163
57230
  * Sort leaf nodes according to their morton codes
57164
- * @param {number[]} projection
57231
+ * @param {number[]} bounds
57165
57232
  */
57166
- sort_morton(projection) {
57233
+ sort_morton(bounds) {
57167
57234
 
57168
57235
  const leaf_block_address = this.__node_count_binary * BVH_BINARY_NODE_SIZE;
57169
57236
 
@@ -57193,15 +57260,15 @@ class BinaryUint32BVH {
57193
57260
 
57194
57261
  const pivot_address = pivotIndex * BVH_LEAF_NODE_SIZE + leaf_block_address;
57195
57262
 
57196
- const pivot = build_morton(data, pivot_address);
57263
+ const pivot = build_morton(data, pivot_address, bounds);
57197
57264
 
57198
57265
  /* partition */
57199
57266
  while (i <= j) {
57200
- while (build_morton(data, i * BVH_LEAF_NODE_SIZE + leaf_block_address) < pivot) {
57267
+ while (build_morton(data, i * BVH_LEAF_NODE_SIZE + leaf_block_address, bounds) < pivot) {
57201
57268
  i++;
57202
57269
  }
57203
57270
 
57204
- while (build_morton(data, j * BVH_LEAF_NODE_SIZE + leaf_block_address) > pivot) {
57271
+ while (build_morton(data, j * BVH_LEAF_NODE_SIZE + leaf_block_address, bounds) > pivot) {
57205
57272
  j--;
57206
57273
  }
57207
57274
 
@@ -65349,6 +65416,23 @@ const TaskSignal = {
65349
65416
  Yield: 3
65350
65417
  };
65351
65418
 
65419
+ /**
65420
+ * @template T
65421
+ * @param {T[]} array
65422
+ * @param {T} element
65423
+ * @return {boolean}
65424
+ */
65425
+ function array_push_if_unique(array, element) {
65426
+ const i = array.indexOf(element);
65427
+
65428
+ if (i === -1) {
65429
+ array.push(element);
65430
+ return true;
65431
+ }
65432
+
65433
+ return false;
65434
+ }
65435
+
65352
65436
  /**
65353
65437
  * Created by Alex on 22/05/2016.
65354
65438
  */
@@ -65371,8 +65455,44 @@ const TaskState = {
65371
65455
  * Created by Alex on 22/05/2016.
65372
65456
  */
65373
65457
 
65458
+ /**
65459
+ *
65460
+ * @type {number}
65461
+ */
65462
+ let id_counter$3 = 0;
65374
65463
 
65375
65464
  class Task {
65465
+ /**
65466
+ * @readonly
65467
+ * @type {number}
65468
+ */
65469
+ id = id_counter$3++;
65470
+
65471
+ on = {
65472
+ started: new Signal(),
65473
+ completed: new Signal(),
65474
+ failed: new Signal()
65475
+ };
65476
+
65477
+ /**
65478
+ *
65479
+ * @type {ObservedInteger}
65480
+ */
65481
+ state = new ObservedInteger(TaskState.INITIAL);
65482
+
65483
+ /**
65484
+ * amount of time spent running this task in milliseconds
65485
+ * @type {number}
65486
+ * @public
65487
+ */
65488
+ __executedCpuTime = 0;
65489
+ /**
65490
+ * number of time task's cycle function was executed
65491
+ * @type {number}
65492
+ * @public
65493
+ */
65494
+ __executedCycleCount = 0;
65495
+
65376
65496
  /**
65377
65497
  *
65378
65498
  * @param {string} [name] useful for identifying the task later on, for various UI and debug purposes
@@ -65397,9 +65517,16 @@ class Task {
65397
65517
  assert.isFunction(cycleFunction, 'cycleFunction');
65398
65518
  assert.isNumber(estimatedDuration, 'estimatedDuration');
65399
65519
 
65400
-
65520
+ /**
65521
+ *
65522
+ * @type {Task[]}
65523
+ */
65401
65524
  this.dependencies = dependencies;
65402
65525
 
65526
+ /**
65527
+ *
65528
+ * @type {number}
65529
+ */
65403
65530
  this.estimatedDuration = estimatedDuration;
65404
65531
 
65405
65532
  /**
@@ -65427,30 +65554,6 @@ class Task {
65427
65554
 
65428
65555
  }
65429
65556
 
65430
- this.on = {
65431
- started: new Signal(),
65432
- completed: new Signal(),
65433
- failed: new Signal()
65434
- };
65435
-
65436
- /**
65437
- *
65438
- * @type {ObservedInteger}
65439
- */
65440
- this.state = new ObservedInteger(TaskState.INITIAL);
65441
-
65442
- /**
65443
- * amount of time spent running this task in milliseconds
65444
- * @type {number}
65445
- * @public
65446
- */
65447
- this.__executedCpuTime = 0;
65448
- /**
65449
- * number of time task's cycle function was executed
65450
- * @type {number}
65451
- * @public
65452
- */
65453
- this.__executedCycleCount = 0;
65454
65557
  }
65455
65558
 
65456
65559
  computeProgress() {
@@ -65495,11 +65598,7 @@ class Task {
65495
65598
  } else if (task.isTask) {
65496
65599
 
65497
65600
  //check that the dependency is not registered yet
65498
- if (this.dependencies.indexOf(task) === -1) {
65499
-
65500
- this.dependencies.push(task);
65501
-
65502
- }
65601
+ array_push_if_unique(this.dependencies, task);
65503
65602
 
65504
65603
  } else {
65505
65604
  throw new Error('Expected a Task or a TaskGroup, got something else');
@@ -65513,11 +65612,14 @@ class Task {
65513
65612
  * @param {Array<(Task|TaskGroup)>} tasks
65514
65613
  */
65515
65614
  addDependencies(tasks) {
65516
- if (!Array.isArray(tasks)) {
65517
- throw new Error(`argument 'tasks' is not an Array`);
65518
- }
65615
+ assert.isArray(tasks, 'tasks');
65616
+
65617
+ const task_count = tasks.length;
65519
65618
 
65520
- tasks.forEach(t => this.addDependency(t));
65619
+ for (let i = 0; i < task_count; i++) {
65620
+ const task = tasks[i];
65621
+ this.addDependency(task);
65622
+ }
65521
65623
  }
65522
65624
 
65523
65625
  toString() {
@@ -69857,23 +69959,6 @@ function array_copy_unique(source, source_position, destination, destination_pos
69857
69959
  return j - destination_position;
69858
69960
  }
69859
69961
 
69860
- /**
69861
- * @template T
69862
- * @param {T[]} array
69863
- * @param {T} element
69864
- * @return {boolean}
69865
- */
69866
- function array_push_if_unique(array, element) {
69867
- const i = array.indexOf(element);
69868
-
69869
- if (i === -1) {
69870
- array.push(element);
69871
- return true;
69872
- }
69873
-
69874
- return false;
69875
- }
69876
-
69877
69962
  /**
69878
69963
  * Created by Alex on 01/04/2014.
69879
69964
  */
@@ -87800,7 +87885,7 @@ function computeStatisticalPartialMedian(values, start, end) {
87800
87885
 
87801
87886
  const range = end - start;
87802
87887
 
87803
- const position = (start + range / 2) | 0;
87888
+ const position = (start + range) >> 1;
87804
87889
 
87805
87890
  return copy[position];
87806
87891
  }
@@ -98707,13 +98792,6 @@ function playTrackRealTime(track, ecd) {
98707
98792
  return entity;
98708
98793
  }
98709
98794
 
98710
- /**
98711
- * Magic field that can be added to an individual component to control serialization on level of individual components
98712
- * @readonly
98713
- * @type {string}
98714
- */
98715
- const COMPONENT_SERIALIZATION_TRANSIENT_FIELD = '@serialization_transient';
98716
-
98717
98795
  /**
98718
98796
  * @template A,B
98719
98797
  * @param {A} a
@@ -98785,64 +98863,48 @@ const GUIElementFlag = {
98785
98863
  class GUIElement {
98786
98864
  /**
98787
98865
  *
98788
- * @param {View} [view] parameter is deprecated
98789
- * @constructor
98866
+ * @type {View}
98790
98867
  */
98791
- constructor(view) {
98792
- /**
98793
- *
98794
- * @type {View}
98795
- */
98796
- this.view = null;
98868
+ view = null;
98797
98869
 
98798
- /**
98799
- *
98800
- * @type {String}
98801
- */
98802
- this.klass = null;
98803
-
98804
- /**
98805
- *
98806
- * @type {Object}
98807
- */
98808
- this.parameters = {};
98809
-
98810
- /**
98811
- * ranges from 0..1 in both X and Y, controls anchor point of element positioning
98812
- * @type {Vector2}
98813
- */
98814
- this.anchor = new Vector2(0, 0);
98815
-
98816
- /**
98817
- * Used for visual grouping of elements, system will create and manage named containers to group elements together
98818
- * @readonly
98819
- * @type {String|null}
98820
- */
98821
- this.group = null;
98870
+ /**
98871
+ *
98872
+ * @type {String}
98873
+ */
98874
+ klass = null;
98822
98875
 
98823
- /**
98824
- * @private
98825
- * @type {number}
98826
- */
98827
- this.flags = GUIElementFlag.Managed;
98876
+ /**
98877
+ *
98878
+ * @type {Object}
98879
+ */
98880
+ parameters = {};
98828
98881
 
98882
+ /**
98883
+ * ranges from 0..1 in both X and Y, controls anchor point of element positioning
98884
+ * @type {Vector2}
98885
+ */
98886
+ anchor = new Vector2(0, 0);
98829
98887
 
98830
- /**
98831
- *
98832
- * @type {ObservedBoolean}
98833
- */
98834
- this.visible = new ObservedBoolean(true);
98888
+ /**
98889
+ * Used for visual grouping of elements, system will create and manage named containers to group elements together
98890
+ * @readonly
98891
+ * @type {String|null}
98892
+ */
98893
+ group = null;
98835
98894
 
98895
+ /**
98896
+ * @private
98897
+ * @type {number}
98898
+ */
98899
+ flags = GUIElementFlag.Managed;
98836
98900
 
98837
- if (view !== undefined) {
98838
- console.warn('constructor parameters are deprecated');
98839
- this.view = view;
98840
98901
 
98841
- //set non-serializable flag
98842
- this[COMPONENT_SERIALIZATION_TRANSIENT_FIELD] = true;
98843
- }
98902
+ /**
98903
+ *
98904
+ * @type {ObservedBoolean}
98905
+ */
98906
+ visible = new ObservedBoolean(true);
98844
98907
 
98845
- }
98846
98908
 
98847
98909
  /**
98848
98910
  *
@@ -98999,11 +99061,9 @@ GUIElement.serializable = true;
98999
99061
  class ViewportPosition {
99000
99062
  /**
99001
99063
  *
99002
- * @param {Vector2} [position]
99003
- * @param {Vector2} [offset]
99004
99064
  * @constructor
99005
99065
  */
99006
- constructor({ position, offset } = {}) {
99066
+ constructor(options) {
99007
99067
  /**
99008
99068
  * Clip-scale position, on-screen values are in range of 0 to 1
99009
99069
  * @type {Vector2}
@@ -99049,12 +99109,9 @@ class ViewportPosition {
99049
99109
  */
99050
99110
  this.enabled = new ObservedBoolean(true);
99051
99111
 
99052
- if (position !== void 0) {
99053
- this.position.copy(position);
99054
- }
99055
-
99056
- if (offset !== void 0) {
99057
- this.offset.copy(offset);
99112
+ if (options !== undefined) {
99113
+ console.warn("ViewportPosition constructor options is deprecated, please use static fromJSON method instead if you need similar functionality");
99114
+ this.fromJSON(options);
99058
99115
  }
99059
99116
  }
99060
99117
 
@@ -118643,4 +118700,16 @@ class Blackboard extends AbstractBlackboard {
118643
118700
 
118644
118701
  Blackboard.typeName = 'Blackboard';
118645
118702
 
118703
+ /**
118704
+ * just in case you need that function also
118705
+ * @param {Vector3} axis
118706
+ * @param {number} angle
118707
+ * @param {Quaternion} result
118708
+ */
118709
+ function quat3_createFromAxisAngle(axis, angle, result) {
118710
+ const halfAngle = angle * .5;
118711
+ const s = Math.sin(halfAngle);
118712
+ result.set(axis.x * s, axis.y * s, axis.z * s, Math.cos(halfAngle));
118713
+ }
118714
+
118646
118715
  export { AmbientOcclusionPostProcessEffect, Behavior, BehaviorStatus, Blackboard, Cache, EngineConfiguration, EngineHarness, ForwardPlusRenderingPlugin, HashMap, Light, ParallelBehavior, ParallelBehaviorPolicy, SGMesh, SGMeshSystem, SelectorBehavior, SequenceBehavior, ShadedGeometry, ShadedGeometrySystem, Signal, SignalBinding, Transform, dispatchViaProxy, findSignalHandlerIndexByHandle, findSignalHandlerIndexByHandleAndContext, quat3_createFromAxisAngle, v2_angleBetween, v2_bearing_angle_towards, v2_distance, v2_dot, v2_length_sqr, v2_magnitude, v4_applyMatrix4, v4_distance_sqr, v4_dot, v4_length_sqr };