@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/bundle-worker-image-decoder.js +1 -1
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +392 -312
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +392 -312
- package/package.json +1 -1
- package/src/core/__module.js +1 -0
- package/src/core/binary/BinaryBuffer.js +37 -31
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +21 -24
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +2 -4
- package/src/core/geom/3d/cone/compute_bounding_cone_of_2_cones.js +3 -2
- package/src/core/geom/3d/morton/v3_morton_encode_bounded.js +34 -0
- package/src/core/geom/3d/morton/v3_morton_encode_transformed.js +2 -1
- package/src/core/geom/3d/quaternion/quat3_createFromAxisAngle.js +11 -0
- package/src/core/geom/3d/quaternion/quat_decode_from_uint32.js +53 -0
- package/src/core/geom/3d/quaternion/quat_encode_to_uint32.js +106 -0
- package/src/core/geom/Quaternion.js +8 -142
- package/src/core/geom/Vector2.js +6 -7
- package/src/core/geom/Vector3.js +15 -82
- package/src/core/geom/vec3/v3_binary_equality_decode.js +44 -0
- package/src/core/geom/vec3/v3_binary_equality_encode.js +47 -0
- package/src/core/primitives/numbers/computeHashFloat.js +2 -2
- package/src/engine/ecs/transform/Transform.js +8 -9
- package/src/engine/ecs/transform/TransformSerializationAdapter.js +18 -7
- package/src/engine/graphics/ecs/mesh/Mesh.js +11 -11
package/build/meep.module.js
CHANGED
|
@@ -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,191 @@ 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}
|
|
1810
|
+
* @returns {number}
|
|
1780
1811
|
*/
|
|
1781
|
-
function
|
|
1782
|
-
|
|
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 max = 0;
|
|
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
|
+
let v0, v1, v2, dropped;
|
|
1926
|
+
|
|
1927
|
+
//max will be dropped
|
|
1928
|
+
if (max === 0) {
|
|
1929
|
+
//dropping x
|
|
1930
|
+
v0 = y;
|
|
1931
|
+
v1 = z;
|
|
1932
|
+
v2 = w;
|
|
1933
|
+
|
|
1934
|
+
dropped = x;
|
|
1935
|
+
} else if (max === 1) {
|
|
1936
|
+
//dropping y
|
|
1937
|
+
v0 = x;
|
|
1938
|
+
v1 = z;
|
|
1939
|
+
v2 = w;
|
|
1940
|
+
|
|
1941
|
+
dropped = y;
|
|
1942
|
+
} else if (max === 2) {
|
|
1943
|
+
//dropping z
|
|
1944
|
+
v0 = x;
|
|
1945
|
+
v1 = y;
|
|
1946
|
+
v2 = w;
|
|
1947
|
+
|
|
1948
|
+
dropped = z;
|
|
1949
|
+
} else {
|
|
1950
|
+
//dropping w
|
|
1951
|
+
v0 = x;
|
|
1952
|
+
v1 = y;
|
|
1953
|
+
v2 = z;
|
|
1954
|
+
|
|
1955
|
+
dropped = w;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
if (dropped < 0) {
|
|
1959
|
+
//reconstructing dropped value is only possible if it is positive, so we invert the quaternion to make dropped value positive
|
|
1960
|
+
v0 = -v0;
|
|
1961
|
+
v1 = -v1;
|
|
1962
|
+
v2 = -v2;
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
const l = Math.sqrt(x * x + y * y + z * z + w * w);
|
|
1966
|
+
const m = 511 / (l * Math.SQRT1_2);
|
|
1967
|
+
|
|
1968
|
+
//re-normalize the remaining components to 10 bit UINT value
|
|
1969
|
+
const oV0 = Math.round(v0 * m + 511);
|
|
1970
|
+
const oV1 = Math.round(v1 * m + 511);
|
|
1971
|
+
const oV2 = Math.round(v2 * m + 511);
|
|
1972
|
+
|
|
1973
|
+
assert.ok(oV0 <= 1023 && oV0 >= 0, `expected 0 <= ov0 <= 1023, instead was '${oV0}'`);
|
|
1974
|
+
assert.ok(oV1 <= 1023 && oV1 >= 0, `expected 0 <= ov1 <= 1023, instead was '${oV1}'`);
|
|
1975
|
+
assert.ok(oV2 <= 1023 && oV2 >= 0, `expected 0 <= ov2 <= 1023, instead was '${oV2}'`);
|
|
1976
|
+
|
|
1977
|
+
|
|
1978
|
+
return (max & 0x3)
|
|
1979
|
+
| ((oV0 & 0x3FF) << 2)
|
|
1980
|
+
| ((oV1 & 0x3FF) << 12)
|
|
1981
|
+
| ((oV2 & 0x3FF) << 22);
|
|
1783
1982
|
}
|
|
1784
1983
|
|
|
1785
1984
|
/**
|
|
@@ -1798,13 +1997,11 @@ function v3_dot(x0, y0, z0, x1, y1, z1) {
|
|
|
1798
1997
|
|
|
1799
1998
|
/**
|
|
1800
1999
|
*
|
|
1801
|
-
* @param {number}
|
|
1802
|
-
* @
|
|
1803
|
-
* @param {number} z
|
|
1804
|
-
* @return {number}
|
|
2000
|
+
* @param {number} v
|
|
2001
|
+
* @returns {number} +1 if v>0, 0 if v == 0, -1 if v<0
|
|
1805
2002
|
*/
|
|
1806
|
-
function
|
|
1807
|
-
return
|
|
2003
|
+
function sign$1(v) {
|
|
2004
|
+
return v > 0 ? 1 : (v < 0 ? -1 : 0);
|
|
1808
2005
|
}
|
|
1809
2006
|
|
|
1810
2007
|
/**
|
|
@@ -1860,6 +2057,110 @@ function v3_angle_cos_between(x0, y0, z0, x1, y1, z1){
|
|
|
1860
2057
|
return clamp$1(d / l, -1, 1);
|
|
1861
2058
|
}
|
|
1862
2059
|
|
|
2060
|
+
/**
|
|
2061
|
+
*
|
|
2062
|
+
* @param {BinaryBuffer} buffer
|
|
2063
|
+
* @param {number[]} result
|
|
2064
|
+
* @param {number} result_offset
|
|
2065
|
+
*/
|
|
2066
|
+
function v3_binary_equality_decode(buffer, result, result_offset) {
|
|
2067
|
+
const header = buffer.readUint8();
|
|
2068
|
+
|
|
2069
|
+
let x = 0;
|
|
2070
|
+
let y = 0;
|
|
2071
|
+
let z = 0;
|
|
2072
|
+
|
|
2073
|
+
if ((header & 7) === 7) {
|
|
2074
|
+
//all scale components are the same
|
|
2075
|
+
x = buffer.readFloat32();
|
|
2076
|
+
y = x;
|
|
2077
|
+
z = x;
|
|
2078
|
+
} else if ((header & 1) === 1) {
|
|
2079
|
+
//X and Y are the same, Z is different
|
|
2080
|
+
x = buffer.readFloat32();
|
|
2081
|
+
y = x;
|
|
2082
|
+
z = buffer.readFloat32();
|
|
2083
|
+
} else if ((header & 2) === 2) {
|
|
2084
|
+
//Y and Z are the same, X is different
|
|
2085
|
+
x = buffer.readFloat32();
|
|
2086
|
+
y = buffer.readFloat32();
|
|
2087
|
+
z = y;
|
|
2088
|
+
} else if ((header & 4) === 4) {
|
|
2089
|
+
//X and Z are the same, Y is different
|
|
2090
|
+
x = buffer.readFloat32();
|
|
2091
|
+
y = buffer.readFloat32();
|
|
2092
|
+
z = x;
|
|
2093
|
+
} else {
|
|
2094
|
+
//scale components are different
|
|
2095
|
+
x = buffer.readFloat32();
|
|
2096
|
+
y = buffer.readFloat32();
|
|
2097
|
+
z = buffer.readFloat32();
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
result[result_offset] = x;
|
|
2101
|
+
result[result_offset + 1] = y;
|
|
2102
|
+
result[result_offset + 2] = z;
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
*
|
|
2107
|
+
* @param {BinaryBuffer} buffer
|
|
2108
|
+
* @param {number} x
|
|
2109
|
+
* @param {number} y
|
|
2110
|
+
* @param {number} z
|
|
2111
|
+
*/
|
|
2112
|
+
function v3_binary_equality_encode(buffer, x, y, z){
|
|
2113
|
+
|
|
2114
|
+
let header = 0;
|
|
2115
|
+
|
|
2116
|
+
if (x === y) {
|
|
2117
|
+
header |= 1;
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
if (y === z) {
|
|
2121
|
+
header |= 2;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
if (x === z) {
|
|
2125
|
+
header |= 4;
|
|
2126
|
+
}
|
|
2127
|
+
|
|
2128
|
+
buffer.writeUint8(header);
|
|
2129
|
+
|
|
2130
|
+
if ((header & 7) === 7) {
|
|
2131
|
+
//all components are the same
|
|
2132
|
+
buffer.writeFloat32(x);
|
|
2133
|
+
} else if (header === 1) {
|
|
2134
|
+
//X and Y are the same, Z is different
|
|
2135
|
+
buffer.writeFloat32(x);
|
|
2136
|
+
buffer.writeFloat32(z);
|
|
2137
|
+
} else if (header === 2) {
|
|
2138
|
+
//Y and Z are the same, X is different
|
|
2139
|
+
buffer.writeFloat32(x);
|
|
2140
|
+
buffer.writeFloat32(y);
|
|
2141
|
+
} else if (header === 4) {
|
|
2142
|
+
//X and Z are the same, Y is different
|
|
2143
|
+
buffer.writeFloat32(x);
|
|
2144
|
+
buffer.writeFloat32(y);
|
|
2145
|
+
} else {
|
|
2146
|
+
//scale components are different
|
|
2147
|
+
buffer.writeFloat32(x);
|
|
2148
|
+
buffer.writeFloat32(y);
|
|
2149
|
+
buffer.writeFloat32(z);
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
/**
|
|
2154
|
+
*
|
|
2155
|
+
* @param {number} x
|
|
2156
|
+
* @param {number} y
|
|
2157
|
+
* @param {number} z
|
|
2158
|
+
* @return {number}
|
|
2159
|
+
*/
|
|
2160
|
+
function v3_length_sqr(x, y, z) {
|
|
2161
|
+
return x * x + y * y + z * z;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
1863
2164
|
/**
|
|
1864
2165
|
*
|
|
1865
2166
|
* @param {Vector3} result
|
|
@@ -1931,45 +2232,6 @@ function v3_slerp(
|
|
|
1931
2232
|
result.set(x, y, z);
|
|
1932
2233
|
}
|
|
1933
2234
|
|
|
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
2235
|
/**
|
|
1974
2236
|
* @author Alex Goldring
|
|
1975
2237
|
* @copyright Alex Goldring 2015
|
|
@@ -2814,100 +3076,31 @@ let Vector3$1 = class Vector3 {
|
|
|
2814
3076
|
/**
|
|
2815
3077
|
*
|
|
2816
3078
|
* @param {BinaryBuffer} buffer
|
|
3079
|
+
* @deprecated use dedicated method directly instead
|
|
2817
3080
|
*/
|
|
2818
3081
|
toBinaryBufferFloat32_EqualityEncoded(buffer) {
|
|
2819
3082
|
const x = this.x;
|
|
2820
3083
|
const y = this.y;
|
|
2821
3084
|
const z = this.z;
|
|
2822
3085
|
|
|
2823
|
-
|
|
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
|
-
}
|
|
3086
|
+
v3_binary_equality_encode(buffer, x, y, z);
|
|
2860
3087
|
}
|
|
2861
3088
|
|
|
2862
3089
|
/**
|
|
2863
3090
|
* 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
3091
|
* @param {BinaryBuffer} buffer
|
|
3092
|
+
* @deprecated use dedicated method directly instead
|
|
2865
3093
|
*/
|
|
2866
3094
|
fromBinaryBufferFloat32_EqualityEncoded(buffer) {
|
|
2867
|
-
|
|
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);
|
|
3095
|
+
v3_binary_equality_decode(buffer, this, 0);
|
|
2901
3096
|
}
|
|
2902
3097
|
|
|
2903
3098
|
hash() {
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
hash = ((hash << 5) - hash) + computeHashFloat(this.z);
|
|
3099
|
+
const x = computeHashFloat(this.x);
|
|
3100
|
+
const y = computeHashFloat(this.y);
|
|
3101
|
+
const z = computeHashFloat(this.z);
|
|
2909
3102
|
|
|
2910
|
-
return
|
|
3103
|
+
return x ^ (y << 1) ^ (z << 2);
|
|
2911
3104
|
}
|
|
2912
3105
|
|
|
2913
3106
|
|
|
@@ -3065,16 +3258,6 @@ Vector3$1.typeName = "Vector3";
|
|
|
3065
3258
|
*/
|
|
3066
3259
|
Vector3$1._dot = v3_dot;
|
|
3067
3260
|
|
|
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
3261
|
/**
|
|
3079
3262
|
* Created by Alex on 10/03/14.
|
|
3080
3263
|
*/
|
|
@@ -3084,18 +3267,6 @@ const forward = new Vector3$1();
|
|
|
3084
3267
|
const up = new Vector3$1();
|
|
3085
3268
|
const right = new Vector3$1();
|
|
3086
3269
|
|
|
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
3270
|
let Quaternion$1 = class Quaternion {
|
|
3100
3271
|
/**
|
|
3101
3272
|
*
|
|
@@ -4518,31 +4689,7 @@ let Quaternion$1 = class Quaternion {
|
|
|
4518
4689
|
* @param {number} value
|
|
4519
4690
|
*/
|
|
4520
4691
|
decodeFromUint32(value) {
|
|
4521
|
-
|
|
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
|
-
}
|
|
4692
|
+
quat_decode_from_uint32(this, 0, value);
|
|
4546
4693
|
}
|
|
4547
4694
|
|
|
4548
4695
|
/**
|
|
@@ -4550,107 +4697,7 @@ let Quaternion$1 = class Quaternion {
|
|
|
4550
4697
|
* @returns {number}
|
|
4551
4698
|
*/
|
|
4552
4699
|
encodeToUint32() {
|
|
4553
|
-
|
|
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;
|
|
4700
|
+
return quat_encode_to_uint32(this.x, this.y, this.z, this.w);
|
|
4654
4701
|
}
|
|
4655
4702
|
|
|
4656
4703
|
/**
|
|
@@ -4837,13 +4884,7 @@ Quaternion$1.identity = Object.freeze(new Quaternion$1(0, 0, 0, 1));
|
|
|
4837
4884
|
const axis = new Vector3$1();
|
|
4838
4885
|
|
|
4839
4886
|
|
|
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)
|
|
4887
|
+
const tempvec3 = new Vector3$1();
|
|
4847
4888
|
|
|
4848
4889
|
/**
|
|
4849
4890
|
* @readonly
|
|
@@ -5110,8 +5151,7 @@ class Transform {
|
|
|
5110
5151
|
* @returns {boolean}
|
|
5111
5152
|
*/
|
|
5112
5153
|
equals(other) {
|
|
5113
|
-
return other.
|
|
5114
|
-
&& this.position.equals(other.position)
|
|
5154
|
+
return this.position.equals(other.position)
|
|
5115
5155
|
&& this.rotation.equals(other.rotation)
|
|
5116
5156
|
&& this.scale.equals(other.scale);
|
|
5117
5157
|
}
|
|
@@ -48945,11 +48985,7 @@ class Vector2 {
|
|
|
48945
48985
|
const x = computeHashFloat(this.x);
|
|
48946
48986
|
const y = computeHashFloat(this.y);
|
|
48947
48987
|
|
|
48948
|
-
|
|
48949
|
-
|
|
48950
|
-
hash |= 0; //convert to 32bit int
|
|
48951
|
-
|
|
48952
|
-
return hash;
|
|
48988
|
+
return ((x << 5) - x) + y;
|
|
48953
48989
|
}
|
|
48954
48990
|
|
|
48955
48991
|
/**
|
|
@@ -48960,8 +48996,11 @@ class Vector2 {
|
|
|
48960
48996
|
const sin = Math.sin(angle);
|
|
48961
48997
|
const cos = Math.cos(angle);
|
|
48962
48998
|
|
|
48963
|
-
const
|
|
48964
|
-
const
|
|
48999
|
+
const _x = this.x;
|
|
49000
|
+
const _y = this.y;
|
|
49001
|
+
|
|
49002
|
+
const x = _x * cos - _y * sin;
|
|
49003
|
+
const y = _x * sin + _y * cos;
|
|
48965
49004
|
|
|
48966
49005
|
this.set(x, y);
|
|
48967
49006
|
}
|
|
@@ -56784,6 +56823,39 @@ function mortonEncode_magicbits(x, y, z) {
|
|
|
56784
56823
|
return x_bits | y_bits | z_bits;
|
|
56785
56824
|
}
|
|
56786
56825
|
|
|
56826
|
+
/**
|
|
56827
|
+
* @param {number} x
|
|
56828
|
+
* @param {number} y
|
|
56829
|
+
* @param {number} z
|
|
56830
|
+
* @param {number[]} bounds
|
|
56831
|
+
* @returns {number}
|
|
56832
|
+
*/
|
|
56833
|
+
function v3_morton_encode_bounded(x, y, z, bounds) {
|
|
56834
|
+
|
|
56835
|
+
const bounds_x0 = bounds[0];
|
|
56836
|
+
const bounds_y0 = bounds[1];
|
|
56837
|
+
const bounds_z0 = bounds[2];
|
|
56838
|
+
|
|
56839
|
+
const bounds_x1 = bounds[3];
|
|
56840
|
+
const bounds_y1 = bounds[4];
|
|
56841
|
+
const bounds_z1 = bounds[5];
|
|
56842
|
+
|
|
56843
|
+
const bounds_span_x = bounds_x1 - bounds_x0;
|
|
56844
|
+
const bounds_span_y = bounds_y1 - bounds_y0;
|
|
56845
|
+
const bounds_span_z = bounds_z1 - bounds_z0;
|
|
56846
|
+
|
|
56847
|
+
// scale to 10 bits
|
|
56848
|
+
const ndc_x = 1023 * (x - bounds_x0) / bounds_span_x;
|
|
56849
|
+
const ndc_y = 1023 * (y - bounds_y0) / bounds_span_y;
|
|
56850
|
+
const ndc_z = 1023 * (z - bounds_z0) / bounds_span_z;
|
|
56851
|
+
|
|
56852
|
+
return mortonEncode_magicbits(
|
|
56853
|
+
Math.round(ndc_x),
|
|
56854
|
+
Math.round(ndc_y),
|
|
56855
|
+
Math.round(ndc_z)
|
|
56856
|
+
);
|
|
56857
|
+
}
|
|
56858
|
+
|
|
56787
56859
|
/**
|
|
56788
56860
|
* Returns highest value out of 3 supplied
|
|
56789
56861
|
* @param {number} a
|
|
@@ -56846,10 +56918,10 @@ function copy_box_zero_size(data, destination, source) {
|
|
|
56846
56918
|
* Assumes data will be normalized to 0...1 value range
|
|
56847
56919
|
* @param {Float32Array} data
|
|
56848
56920
|
* @param {number} address
|
|
56849
|
-
* @param {number[]}
|
|
56921
|
+
* @param {number[]} bounds
|
|
56850
56922
|
* @returns {number}
|
|
56851
56923
|
*/
|
|
56852
|
-
function build_morton(data, address,
|
|
56924
|
+
function build_morton(data, address, bounds) {
|
|
56853
56925
|
|
|
56854
56926
|
const x0 = data[address];
|
|
56855
56927
|
const y0 = data[address + 1];
|
|
@@ -56858,17 +56930,15 @@ function build_morton(data, address, matrix) {
|
|
|
56858
56930
|
const y1 = data[address + 4];
|
|
56859
56931
|
const z1 = data[address + 5];
|
|
56860
56932
|
|
|
56861
|
-
const cx = (x0 + x1)
|
|
56862
|
-
const cy = (y0 + y1)
|
|
56863
|
-
const cz = (z0 + z1)
|
|
56933
|
+
const cx = (x0 + x1) * 0.5;
|
|
56934
|
+
const cy = (y0 + y1) * 0.5;
|
|
56935
|
+
const cz = (z0 + z1) * 0.5;
|
|
56864
56936
|
|
|
56865
|
-
return
|
|
56866
|
-
// return v3_morton_encode_transformed(cx, cy, cz, matrix);
|
|
56937
|
+
return v3_morton_encode_bounded(cx, cy, cz, bounds);
|
|
56867
56938
|
|
|
56868
56939
|
}
|
|
56869
56940
|
|
|
56870
|
-
const
|
|
56871
|
-
const stack$8 = [];
|
|
56941
|
+
const stack$8 = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
56872
56942
|
|
|
56873
56943
|
class BinaryUint32BVH {
|
|
56874
56944
|
/**
|
|
@@ -57099,17 +57169,15 @@ class BinaryUint32BVH {
|
|
|
57099
57169
|
* @private
|
|
57100
57170
|
*/
|
|
57101
57171
|
__compute_bounds_area_of_3_boxes(a, b, c) {
|
|
57102
|
-
this.
|
|
57103
|
-
this.readBounds(b, scratch_box_0, 6);
|
|
57104
|
-
this.readBounds(c, scratch_box_0, 12);
|
|
57172
|
+
const float32 = this.__data_float32;
|
|
57105
57173
|
|
|
57106
|
-
const x0 = min3(
|
|
57107
|
-
const y0 = min3(
|
|
57108
|
-
const z0 = min3(
|
|
57174
|
+
const x0 = min3(float32[a + 0], float32[b + 0], float32[c + 0]);
|
|
57175
|
+
const y0 = min3(float32[a + 1], float32[b + 1], float32[c + 1]);
|
|
57176
|
+
const z0 = min3(float32[a + 2], float32[b + 2], float32[c + 2]);
|
|
57109
57177
|
|
|
57110
|
-
const x1 = max3(
|
|
57111
|
-
const y1 = max3(
|
|
57112
|
-
const z1 = max3(
|
|
57178
|
+
const x1 = max3(float32[a + 3], float32[b + 3], float32[c + 3]);
|
|
57179
|
+
const y1 = max3(float32[a + 4], float32[b + 4], float32[c + 4]);
|
|
57180
|
+
const z1 = max3(float32[a + 5], float32[b + 5], float32[c + 5]);
|
|
57113
57181
|
|
|
57114
57182
|
return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
|
|
57115
57183
|
}
|
|
@@ -57161,9 +57229,9 @@ class BinaryUint32BVH {
|
|
|
57161
57229
|
|
|
57162
57230
|
/**
|
|
57163
57231
|
* Sort leaf nodes according to their morton codes
|
|
57164
|
-
* @param {number[]}
|
|
57232
|
+
* @param {number[]} bounds
|
|
57165
57233
|
*/
|
|
57166
|
-
sort_morton(
|
|
57234
|
+
sort_morton(bounds) {
|
|
57167
57235
|
|
|
57168
57236
|
const leaf_block_address = this.__node_count_binary * BVH_BINARY_NODE_SIZE;
|
|
57169
57237
|
|
|
@@ -57193,15 +57261,15 @@ class BinaryUint32BVH {
|
|
|
57193
57261
|
|
|
57194
57262
|
const pivot_address = pivotIndex * BVH_LEAF_NODE_SIZE + leaf_block_address;
|
|
57195
57263
|
|
|
57196
|
-
const pivot = build_morton(data, pivot_address);
|
|
57264
|
+
const pivot = build_morton(data, pivot_address, bounds);
|
|
57197
57265
|
|
|
57198
57266
|
/* partition */
|
|
57199
57267
|
while (i <= j) {
|
|
57200
|
-
while (build_morton(data, i * BVH_LEAF_NODE_SIZE + leaf_block_address) < pivot) {
|
|
57268
|
+
while (build_morton(data, i * BVH_LEAF_NODE_SIZE + leaf_block_address, bounds) < pivot) {
|
|
57201
57269
|
i++;
|
|
57202
57270
|
}
|
|
57203
57271
|
|
|
57204
|
-
while (build_morton(data, j * BVH_LEAF_NODE_SIZE + leaf_block_address) > pivot) {
|
|
57272
|
+
while (build_morton(data, j * BVH_LEAF_NODE_SIZE + leaf_block_address, bounds) > pivot) {
|
|
57205
57273
|
j--;
|
|
57206
57274
|
}
|
|
57207
57275
|
|
|
@@ -118643,4 +118711,16 @@ class Blackboard extends AbstractBlackboard {
|
|
|
118643
118711
|
|
|
118644
118712
|
Blackboard.typeName = 'Blackboard';
|
|
118645
118713
|
|
|
118714
|
+
/**
|
|
118715
|
+
* just in case you need that function also
|
|
118716
|
+
* @param {Vector3} axis
|
|
118717
|
+
* @param {number} angle
|
|
118718
|
+
* @param {Quaternion} result
|
|
118719
|
+
*/
|
|
118720
|
+
function quat3_createFromAxisAngle(axis, angle, result) {
|
|
118721
|
+
const halfAngle = angle * .5;
|
|
118722
|
+
const s = Math.sin(halfAngle);
|
|
118723
|
+
result.set(axis.x * s, axis.y * s, axis.z * s, Math.cos(halfAngle));
|
|
118724
|
+
}
|
|
118725
|
+
|
|
118646
118726
|
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 };
|