poly-extrude 0.13.0 → 0.14.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 (68) hide show
  1. package/dist/cylinder.d.ts +11 -0
  2. package/{src → dist}/cylinder.js +108 -111
  3. package/dist/cylinder.js.map +1 -0
  4. package/dist/index.d.ts +7 -0
  5. package/dist/index.js +8 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/math/Curve.d.ts +41 -0
  8. package/dist/math/Curve.js +142 -0
  9. package/dist/math/Curve.js.map +1 -0
  10. package/dist/math/Interpolations.d.ts +8 -0
  11. package/dist/math/Interpolations.js +48 -0
  12. package/dist/math/Interpolations.js.map +1 -0
  13. package/dist/math/Matrix4.d.ts +8 -0
  14. package/dist/math/Matrix4.js +582 -0
  15. package/dist/math/Matrix4.js.map +1 -0
  16. package/dist/math/QuadraticBezierCurve3.d.ts +10 -0
  17. package/dist/math/QuadraticBezierCurve3.js +22 -0
  18. package/dist/math/QuadraticBezierCurve3.js.map +1 -0
  19. package/dist/math/Quaternion.d.ts +46 -0
  20. package/dist/math/Quaternion.js +415 -0
  21. package/dist/math/Quaternion.js.map +1 -0
  22. package/dist/math/Vector3.d.ts +42 -0
  23. package/dist/math/Vector3.js +403 -0
  24. package/dist/math/Vector3.js.map +1 -0
  25. package/dist/path/PathPoint.d.ts +15 -0
  26. package/dist/path/PathPoint.js +35 -0
  27. package/dist/path/PathPoint.js.map +1 -0
  28. package/dist/path/PathPointList.d.ts +27 -0
  29. package/dist/path/PathPointList.js +212 -0
  30. package/dist/path/PathPointList.js.map +1 -0
  31. package/dist/path.d.ts +11 -0
  32. package/{src → dist}/path.js +334 -360
  33. package/dist/path.js.map +1 -0
  34. package/dist/plane.d.ts +2 -0
  35. package/{src → dist}/plane.js +57 -58
  36. package/dist/plane.js.map +1 -0
  37. package/dist/poly-extrude.js +1286 -1581
  38. package/dist/poly-extrude.js.map +1 -1
  39. package/dist/poly-extrude.min.js +2 -2
  40. package/dist/poly-extrude.mjs +1286 -1581
  41. package/dist/poly-extrude.mjs.map +1 -0
  42. package/dist/polygon.d.ts +9 -0
  43. package/{src → dist}/polygon.js +163 -179
  44. package/dist/polygon.js.map +1 -0
  45. package/dist/polyline.d.ts +24 -0
  46. package/{src → dist}/polyline.js +420 -456
  47. package/dist/polyline.js.map +1 -0
  48. package/dist/tube.d.ts +12 -0
  49. package/{src → dist}/tube.js +124 -142
  50. package/dist/tube.js.map +1 -0
  51. package/dist/type.d.ts +9 -0
  52. package/dist/type.js +2 -0
  53. package/dist/type.js.map +1 -0
  54. package/dist/util.d.ts +20 -0
  55. package/dist/util.js +217 -0
  56. package/dist/util.js.map +1 -0
  57. package/package.json +53 -48
  58. package/readme.md +12 -2
  59. package/src/cylinder.ts +124 -0
  60. package/src/index.ts +7 -0
  61. package/src/path.ts +385 -0
  62. package/src/plane.ts +60 -0
  63. package/src/polygon.ts +189 -0
  64. package/src/polyline.ts +473 -0
  65. package/src/tube.ts +155 -0
  66. package/src/type.ts +9 -0
  67. package/src/{util.js → util.ts} +1 -1
  68. package/index.js +0 -7
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * poly-extrude v0.13.0
2
+ * poly-extrude v0.14.0
3
3
  */
4
4
  var earcut$2 = {exports: {}};
5
5
 
@@ -1746,1157 +1746,896 @@ var Vector3 = /*#__PURE__*/function () {
1746
1746
  return Vector3;
1747
1747
  }();
1748
1748
 
1749
- /**
1750
- * https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
1751
- * @param {*} ring
1752
- * @returns
1749
+ /**
1750
+ * https://github.com/Turfjs/turf/blob/master/packages/turf-boolean-clockwise/index.ts
1751
+ * @param {*} ring
1752
+ * @returns
1753
1753
  */
1754
-
1755
1754
  function isClockwise(ring) {
1756
- var sum = 0;
1757
- var i = 1;
1758
- var prev;
1759
- var cur;
1760
- var len = ring.length;
1761
-
1762
- while (i < len) {
1763
- prev = cur || ring[0];
1764
- cur = ring[i];
1765
- sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
1766
- i++;
1767
- }
1768
-
1769
- return sum > 0;
1755
+ let sum = 0;
1756
+ let i = 1;
1757
+ let prev;
1758
+ let cur;
1759
+ const len = ring.length;
1760
+ while (i < len) {
1761
+ prev = cur || ring[0];
1762
+ cur = ring[i];
1763
+ sum += (cur[0] - prev[0]) * (cur[1] + prev[1]);
1764
+ i++;
1765
+ }
1766
+ return sum > 0;
1770
1767
  }
1771
-
1772
1768
  function v3Sub(out, v1, v2) {
1773
- out[0] = v1[0] - v2[0];
1774
- out[1] = v1[1] - v2[1];
1775
- out[2] = v1[2] - v2[2];
1776
- return out;
1769
+ out[0] = v1[0] - v2[0];
1770
+ out[1] = v1[1] - v2[1];
1771
+ out[2] = v1[2] - v2[2];
1772
+ return out;
1777
1773
  }
1778
-
1779
1774
  function v3Normalize(out, v) {
1780
- var x = v[0];
1781
- var y = v[1];
1782
- var z = v[2];
1783
- var d = Math.sqrt(x * x + y * y + z * z) || 1;
1784
- out[0] = x / d;
1785
- out[1] = y / d;
1786
- out[2] = z / d;
1787
- return out;
1775
+ const x = v[0];
1776
+ const y = v[1];
1777
+ const z = v[2];
1778
+ const d = Math.sqrt(x * x + y * y + z * z) || 1;
1779
+ out[0] = x / d;
1780
+ out[1] = y / d;
1781
+ out[2] = z / d;
1782
+ return out;
1788
1783
  }
1789
-
1790
1784
  function v3Cross(out, v1, v2) {
1791
- var ax = v1[0],
1792
- ay = v1[1],
1793
- az = v1[2],
1794
- bx = v2[0],
1795
- by = v2[1],
1796
- bz = v2[2];
1797
- out[0] = ay * bz - az * by;
1798
- out[1] = az * bx - ax * bz;
1799
- out[2] = ax * by - ay * bx;
1800
- return out;
1785
+ const ax = v1[0], ay = v1[1], az = v1[2], bx = v2[0], by = v2[1], bz = v2[2];
1786
+ out[0] = ay * bz - az * by;
1787
+ out[1] = az * bx - ax * bz;
1788
+ out[2] = ax * by - ay * bx;
1789
+ return out;
1801
1790
  }
1802
-
1803
1791
  function generateNormal(indices, position) {
1804
- function v3Set(p, a, b, c) {
1805
- p[0] = a;
1806
- p[1] = b;
1807
- p[2] = c;
1808
- }
1809
-
1810
- var p1 = [];
1811
- var p2 = [];
1812
- var p3 = [];
1813
- var v21 = [];
1814
- var v32 = [];
1815
- var n = [];
1816
- var len = indices.length;
1817
- var normals = new Float32Array(position.length);
1818
- var f = 0;
1819
-
1820
- while (f < len) {
1821
- // const i1 = indices[f++] * 3;
1822
- // const i2 = indices[f++] * 3;
1823
- // const i3 = indices[f++] * 3;
1824
- // const i1 = indices[f];
1825
- // const i2 = indices[f + 1];
1826
- // const i3 = indices[f + 2];
1827
- var a = indices[f],
1828
- b = indices[f + 1],
1829
- c = indices[f + 2];
1830
- var i1 = a * 3,
1831
- i2 = b * 3,
1832
- i3 = c * 3;
1833
- v3Set(p1, position[i1], position[i1 + 1], position[i1 + 2]);
1834
- v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
1835
- v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
1836
- v3Sub(v32, p3, p2);
1837
- v3Sub(v21, p1, p2);
1838
- v3Cross(n, v32, v21); // Already be weighted by the triangle area
1839
-
1840
- for (var _i = 0; _i < 3; _i++) {
1841
- normals[i1 + _i] += n[_i];
1842
- normals[i2 + _i] += n[_i];
1843
- normals[i3 + _i] += n[_i];
1792
+ function v3Set(p, a, b, c) {
1793
+ p[0] = a;
1794
+ p[1] = b;
1795
+ p[2] = c;
1844
1796
  }
1845
-
1846
- f += 3;
1847
- }
1848
-
1849
- var i = 0;
1850
- var l = normals.length;
1851
-
1852
- while (i < l) {
1853
- v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
1854
- v3Normalize(n, n);
1855
- normals[i] = n[0] || 0;
1856
- normals[i + 1] = n[1] || 0;
1857
- normals[i + 2] = n[2] || 0;
1858
- i += 3;
1859
- }
1860
-
1861
- return normals;
1797
+ const p1 = [];
1798
+ const p2 = [];
1799
+ const p3 = [];
1800
+ const v21 = [];
1801
+ const v32 = [];
1802
+ const n = [];
1803
+ const len = indices.length;
1804
+ const normals = new Float32Array(position.length);
1805
+ let f = 0;
1806
+ while (f < len) {
1807
+ // const i1 = indices[f++] * 3;
1808
+ // const i2 = indices[f++] * 3;
1809
+ // const i3 = indices[f++] * 3;
1810
+ // const i1 = indices[f];
1811
+ // const i2 = indices[f + 1];
1812
+ // const i3 = indices[f + 2];
1813
+ const a = indices[f], b = indices[f + 1], c = indices[f + 2];
1814
+ const i1 = a * 3, i2 = b * 3, i3 = c * 3;
1815
+ v3Set(p1, position[i1], position[i1 + 1], position[i1 + 2]);
1816
+ v3Set(p2, position[i2], position[i2 + 1], position[i2 + 2]);
1817
+ v3Set(p3, position[i3], position[i3 + 1], position[i3 + 2]);
1818
+ v3Sub(v32, p3, p2);
1819
+ v3Sub(v21, p1, p2);
1820
+ v3Cross(n, v32, v21);
1821
+ // Already be weighted by the triangle area
1822
+ for (let i = 0; i < 3; i++) {
1823
+ normals[i1 + i] += n[i];
1824
+ normals[i2 + i] += n[i];
1825
+ normals[i3 + i] += n[i];
1826
+ }
1827
+ f += 3;
1828
+ }
1829
+ let i = 0;
1830
+ const l = normals.length;
1831
+ while (i < l) {
1832
+ v3Set(n, normals[i], normals[i + 1], normals[i + 2]);
1833
+ v3Normalize(n, n);
1834
+ normals[i] = n[0] || 0;
1835
+ normals[i + 1] = n[1] || 0;
1836
+ normals[i + 2] = n[2] || 0;
1837
+ i += 3;
1838
+ }
1839
+ return normals;
1862
1840
  }
1863
1841
  function merge(results) {
1864
- if (results.length === 1) {
1865
- var _result = {
1866
- position: results[0].position,
1867
- normal: results[0].normal,
1868
- uv: results[0].uv,
1869
- indices: results[0].indices,
1870
- results: results
1842
+ if (results.length === 1) {
1843
+ const result = {
1844
+ position: results[0].position,
1845
+ normal: results[0].normal,
1846
+ uv: results[0].uv,
1847
+ indices: results[0].indices,
1848
+ results
1849
+ };
1850
+ return result;
1851
+ }
1852
+ let plen = 0, ilen = 0;
1853
+ for (let i = 0, len = results.length; i < len; i++) {
1854
+ const { position, indices } = results[i];
1855
+ plen += position.length;
1856
+ ilen += indices.length;
1857
+ }
1858
+ const result = {
1859
+ position: new Float32Array(plen),
1860
+ normal: new Float32Array(plen),
1861
+ uv: new Float32Array(plen / 3 * 2),
1862
+ indices: new Uint32Array(ilen),
1863
+ results
1871
1864
  };
1872
- return _result;
1873
- }
1874
-
1875
- var plen = 0,
1876
- ilen = 0;
1877
-
1878
- for (var i = 0, len = results.length; i < len; i++) {
1879
- var _results$i = results[i],
1880
- position = _results$i.position,
1881
- indices = _results$i.indices;
1882
- plen += position.length;
1883
- ilen += indices.length;
1884
- }
1885
-
1886
- var result = {
1887
- position: new Float32Array(plen),
1888
- normal: new Float32Array(plen),
1889
- uv: new Float32Array(plen / 3 * 2),
1890
- indices: new Uint32Array(ilen),
1891
- results: results
1892
- };
1893
- var pOffset = 0,
1894
- pCount = 0,
1895
- iIdx = 0,
1896
- uvOffset = 0;
1897
-
1898
- for (var _i2 = 0, _len = results.length; _i2 < _len; _i2++) {
1899
- var _results$_i = results[_i2],
1900
- _position = _results$_i.position,
1901
- _indices = _results$_i.indices,
1902
- normal = _results$_i.normal,
1903
- uv = _results$_i.uv;
1904
- result.position.set(_position, pOffset);
1905
- result.normal.set(normal, pOffset);
1906
- result.uv.set(uv, uvOffset);
1907
- var j = 0;
1908
- var len1 = _indices.length;
1909
-
1910
- while (j < len1) {
1911
- var pIndex = _indices[j] + pCount;
1912
- result.indices[iIdx] = pIndex;
1913
- iIdx++;
1914
- j++;
1865
+ let pOffset = 0, pCount = 0, iIdx = 0, uvOffset = 0;
1866
+ for (let i = 0, len = results.length; i < len; i++) {
1867
+ const { position, indices, normal, uv } = results[i];
1868
+ result.position.set(position, pOffset);
1869
+ result.normal.set(normal, pOffset);
1870
+ result.uv.set(uv, uvOffset);
1871
+ let j = 0;
1872
+ const len1 = indices.length;
1873
+ while (j < len1) {
1874
+ const pIndex = indices[j] + pCount;
1875
+ result.indices[iIdx] = pIndex;
1876
+ iIdx++;
1877
+ j++;
1878
+ }
1879
+ uvOffset += uv.length;
1880
+ pOffset += position.length;
1881
+ pCount += position.length / 3;
1915
1882
  }
1916
-
1917
- uvOffset += uv.length;
1918
- pOffset += _position.length;
1919
- pCount += _position.length / 3;
1920
- }
1921
-
1922
- return result;
1883
+ return result;
1923
1884
  }
1924
1885
  function radToDeg(rad) {
1925
- return rad * 180 / Math.PI;
1886
+ return rad * 180 / Math.PI;
1926
1887
  }
1927
1888
  function degToRad(angle) {
1928
- return angle / 180 * Math.PI;
1929
- } // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
1930
-
1889
+ return angle / 180 * Math.PI;
1890
+ }
1891
+ // https://github.com/mrdoob/three.js/blob/16f13e3b07e31d0e9a00df7c3366bbe0e464588c/src/geometries/ExtrudeGeometry.js?_pjax=%23js-repo-pjax-container#L736
1931
1892
  function generateSideWallUV(uvs, vertices, indexA, indexB, indexC, indexD) {
1932
- var idx1 = indexA * 3,
1933
- idx2 = indexB * 3,
1934
- idx3 = indexC * 3,
1935
- idx4 = indexD * 3;
1936
- var a_x = vertices[idx1];
1937
- var a_y = vertices[idx1 + 1];
1938
- var a_z = vertices[idx1 + 2];
1939
- var b_x = vertices[idx2];
1940
- var b_y = vertices[idx2 + 1];
1941
- var b_z = vertices[idx2 + 2];
1942
- var c_x = vertices[idx3];
1943
- var c_y = vertices[idx3 + 1];
1944
- var c_z = vertices[idx3 + 2];
1945
- var d_x = vertices[idx4];
1946
- var d_y = vertices[idx4 + 1];
1947
- var d_z = vertices[idx4 + 2];
1948
- var uIndex = uvs.length - 1;
1949
-
1950
- if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
1951
- uvs[++uIndex] = a_x;
1952
- uvs[++uIndex] = 1 - a_z;
1953
- uvs[++uIndex] = b_x;
1954
- uvs[++uIndex] = 1 - b_z;
1955
- uvs[++uIndex] = c_x;
1956
- uvs[++uIndex] = 1 - c_z;
1957
- uvs[++uIndex] = d_x;
1958
- uvs[++uIndex] = 1 - d_z; // uvs.push(a_x, 1 - a_z);
1959
- // uvs.push(b_x, 1 - b_z);
1960
- // uvs.push(c_x, 1 - c_z);
1961
- // uvs.push(d_x, 1 - d_z);
1962
- } else {
1963
- uvs[++uIndex] = a_y;
1964
- uvs[++uIndex] = 1 - a_z;
1965
- uvs[++uIndex] = b_y;
1966
- uvs[++uIndex] = 1 - b_z;
1967
- uvs[++uIndex] = c_y;
1968
- uvs[++uIndex] = 1 - c_z;
1969
- uvs[++uIndex] = d_y;
1970
- uvs[++uIndex] = 1 - d_z; // uvs.push(a_y, 1 - a_z);
1971
- // uvs.push(b_y, 1 - b_z);
1972
- // uvs.push(c_y, 1 - c_z);
1973
- // uvs.push(d_y, 1 - d_z);
1974
- }
1893
+ const idx1 = indexA * 3, idx2 = indexB * 3, idx3 = indexC * 3, idx4 = indexD * 3;
1894
+ const a_x = vertices[idx1];
1895
+ const a_y = vertices[idx1 + 1];
1896
+ const a_z = vertices[idx1 + 2];
1897
+ const b_x = vertices[idx2];
1898
+ const b_y = vertices[idx2 + 1];
1899
+ const b_z = vertices[idx2 + 2];
1900
+ const c_x = vertices[idx3];
1901
+ const c_y = vertices[idx3 + 1];
1902
+ const c_z = vertices[idx3 + 2];
1903
+ const d_x = vertices[idx4];
1904
+ const d_y = vertices[idx4 + 1];
1905
+ const d_z = vertices[idx4 + 2];
1906
+ let uIndex = uvs.length - 1;
1907
+ if (Math.abs(a_y - b_y) < Math.abs(a_x - b_x)) {
1908
+ uvs[++uIndex] = a_x;
1909
+ uvs[++uIndex] = 1 - a_z;
1910
+ uvs[++uIndex] = b_x;
1911
+ uvs[++uIndex] = 1 - b_z;
1912
+ uvs[++uIndex] = c_x;
1913
+ uvs[++uIndex] = 1 - c_z;
1914
+ uvs[++uIndex] = d_x;
1915
+ uvs[++uIndex] = 1 - d_z;
1916
+ // uvs.push(a_x, 1 - a_z);
1917
+ // uvs.push(b_x, 1 - b_z);
1918
+ // uvs.push(c_x, 1 - c_z);
1919
+ // uvs.push(d_x, 1 - d_z);
1920
+ }
1921
+ else {
1922
+ uvs[++uIndex] = a_y;
1923
+ uvs[++uIndex] = 1 - a_z;
1924
+ uvs[++uIndex] = b_y;
1925
+ uvs[++uIndex] = 1 - b_z;
1926
+ uvs[++uIndex] = c_y;
1927
+ uvs[++uIndex] = 1 - c_z;
1928
+ uvs[++uIndex] = d_y;
1929
+ uvs[++uIndex] = 1 - d_z;
1930
+ // uvs.push(a_y, 1 - a_z);
1931
+ // uvs.push(b_y, 1 - b_z);
1932
+ // uvs.push(c_y, 1 - c_z);
1933
+ // uvs.push(d_y, 1 - d_z);
1934
+ }
1975
1935
  }
1976
1936
  function line2Vectors(line) {
1977
- var points = [];
1978
-
1979
- for (var i = 0, len = line.length; i < len; i++) {
1980
- var p = line[i];
1981
- var x = p[0],
1982
- y = p[1],
1983
- z = p[2];
1984
- var v = new Vector3(x, y, z || 0);
1985
- points[i] = v;
1986
- }
1987
-
1988
- return points;
1937
+ const points = [];
1938
+ for (let i = 0, len = line.length; i < len; i++) {
1939
+ const p = line[i];
1940
+ const [x, y, z] = p;
1941
+ const v = new Vector3(x, y, z || 0);
1942
+ points[i] = v;
1943
+ }
1944
+ return points;
1989
1945
  }
1990
1946
  function calLineDistance(line) {
1991
- var distance = 0;
1992
-
1993
- for (var i = 0, len = line.length; i < len; i++) {
1994
- var p1 = line[i],
1995
- p2 = line[i + 1];
1996
-
1997
- if (i === 0) {
1998
- p1.distance = 0;
1999
- }
2000
-
2001
- if (p1 && p2) {
2002
- var x1 = p1[0],
2003
- y1 = p1[1],
2004
- z1 = p1[2];
2005
- var x2 = p2[0],
2006
- y2 = p2[1],
2007
- z2 = p2[2];
2008
- var dx = x1 - x2,
2009
- dy = y1 - y2,
2010
- dz = (z1 || 0) - (z2 || 0);
2011
- var dis = Math.sqrt(dx * dx + dy * dy + dz * dz);
2012
- distance += dis;
2013
- p2.distance = distance;
1947
+ let distance = 0;
1948
+ for (let i = 0, len = line.length; i < len; i++) {
1949
+ const p1 = line[i], p2 = line[i + 1];
1950
+ if (i === 0) {
1951
+ p1.distance = 0;
1952
+ }
1953
+ if (p1 && p2) {
1954
+ const [x1, y1, z1] = p1;
1955
+ const [x2, y2, z2] = p2;
1956
+ const dx = x1 - x2, dy = y1 - y2, dz = (z1 || 0) - (z2 || 0);
1957
+ const dis = Math.sqrt(dx * dx + dy * dy + dz * dz);
1958
+ distance += dis;
1959
+ p2.distance = distance;
1960
+ }
2014
1961
  }
2015
- }
2016
-
2017
- return distance;
1962
+ return distance;
2018
1963
  }
2019
1964
 
2020
1965
  function extrudePolygons(polygons, options) {
2021
- options = Object.assign({}, {
2022
- depth: 2
2023
- }, options);
2024
- var results = polygons.map(function (polygon) {
2025
- for (var i = 0, len = polygon.length; i < len; i++) {
2026
- var ring = polygon[i];
2027
- validateRing(ring);
2028
-
2029
- if (i === 0) {
2030
- if (!isClockwise(ring)) {
2031
- polygon[i] = ring.reverse();
1966
+ options = Object.assign({}, { depth: 2 }, options);
1967
+ const results = polygons.map(polygon => {
1968
+ for (let i = 0, len = polygon.length; i < len; i++) {
1969
+ const ring = polygon[i];
1970
+ validateRing(ring);
1971
+ if (i === 0) {
1972
+ if (!isClockwise(ring)) {
1973
+ polygon[i] = ring.reverse();
1974
+ }
1975
+ }
1976
+ else if (isClockwise(ring)) {
1977
+ polygon[i] = ring.reverse();
1978
+ }
1979
+ if (isClosedRing(ring)) {
1980
+ ring.splice(ring.length - 1, 1);
1981
+ }
2032
1982
  }
2033
- } else if (isClockwise(ring)) {
2034
- polygon[i] = ring.reverse();
2035
- }
2036
-
2037
- if (isClosedRing(ring)) {
2038
- ring.splice(ring.length - 1, 1);
2039
- }
2040
- }
2041
-
2042
- var result = flatVertices(polygon, options);
2043
- result.polygon = polygon;
2044
- var triangles = earcut$1(result.flatVertices, result.holes, 2);
2045
- generateTopAndBottom$1(result, triangles);
2046
- generateSides$1(result, options);
2047
- result.position = new Float32Array(result.points);
2048
- result.indices = new Uint32Array(result.indices);
2049
- result.uv = new Float32Array(result.uv);
2050
- result.normal = generateNormal(result.indices, result.position);
1983
+ const result = flatVertices(polygon, options);
1984
+ result.polygon = polygon;
1985
+ const triangles = earcut$1(result.flatVertices, result.holes, 2);
1986
+ generateTopAndBottom$1(result, triangles);
1987
+ generateSides$1(result, options);
1988
+ result.position = new Float32Array(result.points);
1989
+ result.indices = new Uint32Array(result.indices);
1990
+ result.uv = new Float32Array(result.uv);
1991
+ result.normal = generateNormal(result.indices, result.position);
1992
+ return result;
1993
+ });
1994
+ const result = merge(results);
1995
+ result.polygons = polygons;
2051
1996
  return result;
2052
- });
2053
- var result = merge(results);
2054
- result.polygons = polygons;
2055
- return result;
2056
1997
  }
2057
-
2058
1998
  function generateTopAndBottom$1(result, triangles) {
2059
- var indices = [];
2060
- var count = result.count;
2061
-
2062
- for (var i = 0, len = triangles.length; i < len; i += 3) {
2063
- // top
2064
- var a = triangles[i],
2065
- b = triangles[i + 1],
2066
- c = triangles[i + 2];
2067
- indices[i] = a;
2068
- indices[i + 1] = b;
2069
- indices[i + 2] = c; // bottom
2070
-
2071
- var idx = len + i;
2072
- var a1 = count + a,
2073
- b1 = count + b,
2074
- c1 = count + c;
2075
- indices[idx] = a1;
2076
- indices[idx + 1] = b1;
2077
- indices[idx + 2] = c1;
2078
- }
2079
-
2080
- result.indices = indices;
1999
+ const indices = [];
2000
+ const { count } = result;
2001
+ for (let i = 0, len = triangles.length; i < len; i += 3) {
2002
+ // top
2003
+ const a = triangles[i], b = triangles[i + 1], c = triangles[i + 2];
2004
+ indices[i] = a;
2005
+ indices[i + 1] = b;
2006
+ indices[i + 2] = c;
2007
+ // bottom
2008
+ const idx = len + i;
2009
+ const a1 = count + a, b1 = count + b, c1 = count + c;
2010
+ indices[idx] = a1;
2011
+ indices[idx + 1] = b1;
2012
+ indices[idx + 2] = c1;
2013
+ }
2014
+ result.indices = indices;
2081
2015
  }
2082
-
2083
2016
  function generateSides$1(result, options) {
2084
- var points = result.points,
2085
- indices = result.indices,
2086
- polygon = result.polygon,
2087
- uv = result.uv;
2088
- var depth = options.depth;
2089
- var pIndex = points.length - 1;
2090
- var iIndex = indices.length - 1;
2091
-
2092
- for (var i = 0, len = polygon.length; i < len; i++) {
2093
- var ring = polygon[i];
2094
- var j = 0;
2095
- var len1 = ring.length;
2096
-
2097
- while (j < len1) {
2098
- var v1 = ring[j];
2099
- var v2 = ring[j + 1];
2100
-
2101
- if (j === len1 - 1) {
2102
- v2 = ring[0];
2103
- }
2104
-
2105
- var idx = points.length / 3;
2106
- var x1 = v1[0],
2107
- y1 = v1[1],
2108
- z1 = v1[2] || 0,
2109
- x2 = v2[0],
2110
- y2 = v2[1],
2111
- z2 = v2[2] || 0;
2112
- points[++pIndex] = x1;
2113
- points[++pIndex] = y1;
2114
- points[++pIndex] = z1 + depth;
2115
- points[++pIndex] = x2;
2116
- points[++pIndex] = y2;
2117
- points[++pIndex] = z2 + depth;
2118
- points[++pIndex] = x1;
2119
- points[++pIndex] = y1;
2120
- points[++pIndex] = z1;
2121
- points[++pIndex] = x2;
2122
- points[++pIndex] = y2;
2123
- points[++pIndex] = z2; // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
2124
-
2125
- var a = idx + 2,
2126
- b = idx + 3,
2127
- c = idx,
2128
- d = idx + 1; // points.push(p3, p4, p1, p2);
2129
- // index.push(a, c, b, c, d, b);
2130
-
2131
- indices[++iIndex] = a;
2132
- indices[++iIndex] = c;
2133
- indices[++iIndex] = b;
2134
- indices[++iIndex] = c;
2135
- indices[++iIndex] = d;
2136
- indices[++iIndex] = b; // index.push(c, d, b);
2137
-
2138
- generateSideWallUV(uv, points, a, b, c, d);
2139
- j++;
2017
+ const { points, indices, polygon, uv } = result;
2018
+ const depth = options.depth;
2019
+ let pIndex = points.length - 1;
2020
+ let iIndex = indices.length - 1;
2021
+ for (let i = 0, len = polygon.length; i < len; i++) {
2022
+ const ring = polygon[i];
2023
+ let j = 0;
2024
+ const len1 = ring.length;
2025
+ while (j < len1) {
2026
+ const v1 = ring[j];
2027
+ let v2 = ring[j + 1];
2028
+ if (j === len1 - 1) {
2029
+ v2 = ring[0];
2030
+ }
2031
+ const idx = points.length / 3;
2032
+ const x1 = v1[0], y1 = v1[1], z1 = v1[2] || 0, x2 = v2[0], y2 = v2[1], z2 = v2[2] || 0;
2033
+ points[++pIndex] = x1;
2034
+ points[++pIndex] = y1;
2035
+ points[++pIndex] = z1 + depth;
2036
+ points[++pIndex] = x2;
2037
+ points[++pIndex] = y2;
2038
+ points[++pIndex] = z2 + depth;
2039
+ points[++pIndex] = x1;
2040
+ points[++pIndex] = y1;
2041
+ points[++pIndex] = z1;
2042
+ points[++pIndex] = x2;
2043
+ points[++pIndex] = y2;
2044
+ points[++pIndex] = z2;
2045
+ // points.push(x1, y1, z, x2, y2, z, x1, y1, 0, x2, y2, 0);
2046
+ const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
2047
+ // points.push(p3, p4, p1, p2);
2048
+ // index.push(a, c, b, c, d, b);
2049
+ indices[++iIndex] = a;
2050
+ indices[++iIndex] = c;
2051
+ indices[++iIndex] = b;
2052
+ indices[++iIndex] = c;
2053
+ indices[++iIndex] = d;
2054
+ indices[++iIndex] = b;
2055
+ // index.push(c, d, b);
2056
+ generateSideWallUV(uv, points, a, b, c, d);
2057
+ j++;
2058
+ }
2140
2059
  }
2141
- }
2142
2060
  }
2143
-
2144
2061
  function calPolygonPointsCount(polygon) {
2145
- var count = 0;
2146
- var i = 0;
2147
- var len = polygon.length;
2148
-
2149
- while (i < len) {
2150
- count += polygon[i].length;
2151
- i++;
2152
- }
2153
-
2154
- return count;
2062
+ let count = 0;
2063
+ let i = 0;
2064
+ const len = polygon.length;
2065
+ while (i < len) {
2066
+ count += (polygon[i].length);
2067
+ i++;
2068
+ }
2069
+ return count;
2155
2070
  }
2156
-
2157
2071
  function flatVertices(polygon, options) {
2158
- var count = calPolygonPointsCount(polygon);
2159
- var len = polygon.length;
2160
- var holes = [],
2161
- flatVertices = new Float32Array(count * 2),
2162
- points = [],
2163
- uv = [];
2164
- var pOffset = count * 3,
2165
- uOffset = count * 2;
2166
- var depth = options.depth;
2167
- var idx0 = 0,
2168
- idx1 = 0,
2169
- idx2 = 0;
2170
-
2171
- for (var i = 0; i < len; i++) {
2172
- var ring = polygon[i];
2173
-
2174
- if (i > 0) {
2175
- holes.push(idx0 / 2);
2176
- }
2177
-
2178
- var j = 0;
2179
- var len1 = ring.length;
2180
-
2181
- while (j < len1) {
2182
- var c = ring[j];
2183
- var x = c[0],
2184
- y = c[1],
2185
- z = c[2] || 0;
2186
- flatVertices[idx0++] = x;
2187
- flatVertices[idx0++] = y; // top vertices
2188
-
2189
- points[idx1] = x;
2190
- points[idx1 + 1] = y;
2191
- points[idx1 + 2] = depth + z; // bottom vertices
2192
-
2193
- points[pOffset + idx1] = x;
2194
- points[pOffset + idx1 + 1] = y;
2195
- points[pOffset + idx1 + 2] = z;
2196
- uv[idx2] = x;
2197
- uv[idx2 + 1] = y;
2198
- uv[uOffset + idx2] = x;
2199
- uv[uOffset + idx2 + 1] = y;
2200
- idx1 += 3;
2201
- idx2 += 2;
2202
- j++;
2072
+ const count = calPolygonPointsCount(polygon);
2073
+ const len = polygon.length;
2074
+ const holes = [], flatVertices = new Float32Array(count * 2), points = [], uv = [];
2075
+ const pOffset = count * 3, uOffset = count * 2;
2076
+ const depth = options.depth;
2077
+ let idx0 = 0, idx1 = 0, idx2 = 0;
2078
+ for (let i = 0; i < len; i++) {
2079
+ const ring = polygon[i];
2080
+ if (i > 0) {
2081
+ holes.push(idx0 / 2);
2082
+ }
2083
+ let j = 0;
2084
+ const len1 = ring.length;
2085
+ while (j < len1) {
2086
+ const c = ring[j];
2087
+ const x = c[0], y = c[1], z = c[2] || 0;
2088
+ flatVertices[idx0++] = x;
2089
+ flatVertices[idx0++] = y;
2090
+ // top vertices
2091
+ points[idx1] = x;
2092
+ points[idx1 + 1] = y;
2093
+ points[idx1 + 2] = depth + z;
2094
+ // bottom vertices
2095
+ points[pOffset + idx1] = x;
2096
+ points[pOffset + idx1 + 1] = y;
2097
+ points[pOffset + idx1 + 2] = z;
2098
+ uv[idx2] = x;
2099
+ uv[idx2 + 1] = y;
2100
+ uv[uOffset + idx2] = x;
2101
+ uv[uOffset + idx2 + 1] = y;
2102
+ idx1 += 3;
2103
+ idx2 += 2;
2104
+ j++;
2105
+ }
2203
2106
  }
2204
- }
2205
-
2206
- return {
2207
- flatVertices: flatVertices,
2208
- holes: holes,
2209
- points: points,
2210
- count: count,
2211
- uv: uv
2212
- };
2107
+ return {
2108
+ flatVertices,
2109
+ holes,
2110
+ points,
2111
+ count,
2112
+ uv
2113
+ };
2213
2114
  }
2214
-
2215
2115
  function validateRing(ring) {
2216
- if (!isClosedRing(ring)) {
2217
- ring.push(ring[0]);
2218
- }
2116
+ if (!isClosedRing(ring)) {
2117
+ ring.push(ring[0]);
2118
+ }
2219
2119
  }
2220
-
2221
2120
  function isClosedRing(ring) {
2222
- var len = ring.length;
2223
- var _ring$ = ring[0],
2224
- x1 = _ring$[0],
2225
- y1 = _ring$[1],
2226
- _ring = ring[len - 1],
2227
- x2 = _ring[0],
2228
- y2 = _ring[1];
2229
- return x1 === x2 && y1 === y2;
2121
+ const len = ring.length;
2122
+ const [x1, y1] = ring[0], [x2, y2] = ring[len - 1];
2123
+ return (x1 === x2 && y1 === y2);
2230
2124
  }
2231
2125
 
2232
2126
  function checkOptions(options) {
2233
- options.lineWidth = Math.max(0, options.lineWidth);
2234
- options.depth = Math.max(0, options.depth);
2235
- options.sideDepth = Math.max(0, options.sideDepth);
2127
+ options.lineWidth = Math.max(0, options.lineWidth);
2128
+ options.depth = Math.max(0, options.depth);
2129
+ options.sideDepth = Math.max(0, options.sideDepth);
2236
2130
  }
2237
-
2238
2131
  function extrudePolylines(lines, options) {
2239
- options = Object.assign({}, {
2240
- depth: 2,
2241
- lineWidth: 1,
2242
- bottomStickGround: false,
2243
- pathUV: false
2244
- }, options);
2245
- checkOptions(options);
2246
- var results = lines.map(function (line) {
2247
- var result = expandLine(line, options);
2248
- result.line = line;
2249
- generateTopAndBottom(result, options);
2250
- generateSides(result, options);
2251
- result.position = new Float32Array(result.points);
2252
- result.indices = new Uint32Array(result.indices);
2253
- result.uv = new Float32Array(result.uv);
2254
- result.normal = generateNormal(result.indices, result.position);
2132
+ options = Object.assign({}, { depth: 2, lineWidth: 1, bottomStickGround: false, pathUV: false }, options);
2133
+ checkOptions(options);
2134
+ const results = lines.map(line => {
2135
+ const result = expandLine(line, options);
2136
+ result.line = line;
2137
+ generateTopAndBottom(result, options);
2138
+ generateSides(result, options);
2139
+ result.position = new Float32Array(result.points);
2140
+ result.indices = new Uint32Array(result.indices);
2141
+ result.uv = new Float32Array(result.uv);
2142
+ result.normal = generateNormal(result.indices, result.position);
2143
+ return result;
2144
+ });
2145
+ const result = merge(results);
2146
+ result.lines = lines;
2255
2147
  return result;
2256
- });
2257
- var result = merge(results);
2258
- result.lines = lines;
2259
- return result;
2260
2148
  }
2261
2149
  function extrudeSlopes(lines, options) {
2262
- options = Object.assign({}, {
2263
- depth: 2,
2264
- lineWidth: 1,
2265
- side: 'left',
2266
- sideDepth: 0,
2267
- bottomStickGround: false,
2268
- pathUV: false,
2269
- isSlope: true
2270
- }, options);
2271
- checkOptions(options);
2272
- var _options = options,
2273
- depth = _options.depth,
2274
- side = _options.side,
2275
- sideDepth = _options.sideDepth;
2276
- var results = lines.map(function (line) {
2277
- var tempResult = expandLine(line, options);
2278
- tempResult.line = line;
2279
- var leftPoints = tempResult.leftPoints,
2280
- rightPoints = tempResult.rightPoints;
2281
- var result = {
2282
- line: line
2283
- };
2284
- var depths;
2285
-
2286
- for (var i = 0, len = line.length; i < len; i++) {
2287
- line[i][2] = line[i][2] || 0;
2288
- }
2289
-
2290
- if (side === 'left') {
2291
- result.leftPoints = leftPoints;
2292
- result.rightPoints = line;
2293
- depths = [sideDepth, depth];
2294
- } else {
2295
- result.leftPoints = line;
2296
- result.rightPoints = rightPoints;
2297
- depths = [depth, sideDepth];
2298
- }
2299
-
2300
- result.depths = depths;
2301
- generateTopAndBottom(result, options);
2302
- generateSides(result, options);
2303
- result.position = new Float32Array(result.points);
2304
- result.indices = new Uint32Array(result.indices);
2305
- result.uv = new Float32Array(result.uv);
2306
- result.normal = generateNormal(result.indices, result.position);
2150
+ options = Object.assign({}, { depth: 2, lineWidth: 1, side: 'left', sideDepth: 0, bottomStickGround: false, pathUV: false, isSlope: true }, options);
2151
+ checkOptions(options);
2152
+ const { depth, side, sideDepth } = options;
2153
+ const results = lines.map(line => {
2154
+ const tempResult = expandLine(line, options);
2155
+ tempResult.line = line;
2156
+ const { leftPoints, rightPoints } = tempResult;
2157
+ const result = { line };
2158
+ let depths;
2159
+ for (let i = 0, len = line.length; i < len; i++) {
2160
+ line[i][2] = line[i][2] || 0;
2161
+ }
2162
+ if (side === 'left') {
2163
+ result.leftPoints = leftPoints;
2164
+ result.rightPoints = line;
2165
+ depths = [sideDepth, depth];
2166
+ }
2167
+ else {
2168
+ result.leftPoints = line;
2169
+ result.rightPoints = rightPoints;
2170
+ depths = [depth, sideDepth];
2171
+ }
2172
+ result.depths = depths;
2173
+ generateTopAndBottom(result, options);
2174
+ generateSides(result, options);
2175
+ result.position = new Float32Array(result.points);
2176
+ result.indices = new Uint32Array(result.indices);
2177
+ result.uv = new Float32Array(result.uv);
2178
+ result.normal = generateNormal(result.indices, result.position);
2179
+ return result;
2180
+ });
2181
+ const result = merge(results);
2182
+ result.lines = lines;
2307
2183
  return result;
2308
- });
2309
- var result = merge(results);
2310
- result.lines = lines;
2311
- return result;
2312
2184
  }
2313
-
2314
2185
  function generateTopAndBottom(result, options) {
2315
- var bottomStickGround = options.bottomStickGround;
2316
- var z = options.depth;
2317
- var depths = result.depths;
2318
- var lz = z,
2319
- rz = z;
2320
-
2321
- if (depths) {
2322
- lz = depths[0];
2323
- rz = depths[1];
2324
- }
2325
-
2326
- var leftPoints = result.leftPoints,
2327
- rightPoints = result.rightPoints;
2328
- var line = result.line;
2329
- var pathUV = options.pathUV;
2330
-
2331
- if (pathUV) {
2332
- calLineDistance(line);
2333
-
2334
- for (var _i = 0, _len = line.length; _i < _len; _i++) {
2335
- leftPoints[_i].distance = rightPoints[_i].distance = line[_i].distance;
2186
+ const bottomStickGround = options.bottomStickGround;
2187
+ const z = options.depth;
2188
+ const depths = result.depths;
2189
+ let lz = z, rz = z;
2190
+ if (depths) {
2191
+ lz = depths[0];
2192
+ rz = depths[1];
2336
2193
  }
2337
- }
2338
-
2339
- var i = 0,
2340
- len = leftPoints.length;
2341
- var points = [],
2342
- indices = [],
2343
- uv = [];
2344
-
2345
- while (i < len) {
2346
- // top left
2347
- var idx0 = i * 3;
2348
- var _leftPoints$i = leftPoints[i],
2349
- x1 = _leftPoints$i[0],
2350
- y1 = _leftPoints$i[1],
2351
- z1 = _leftPoints$i[2];
2352
- points[idx0] = x1;
2353
- points[idx0 + 1] = y1;
2354
- points[idx0 + 2] = lz + z1; // top right
2355
-
2356
- var _rightPoints$i = rightPoints[i],
2357
- x2 = _rightPoints$i[0],
2358
- y2 = _rightPoints$i[1],
2359
- z2 = _rightPoints$i[2];
2360
- var idx1 = len * 3 + idx0;
2361
- points[idx1] = x2;
2362
- points[idx1 + 1] = y2;
2363
- points[idx1 + 2] = rz + z2; // bottom left
2364
-
2365
- var idx2 = len * 2 * 3 + idx0;
2366
- points[idx2] = x1;
2367
- points[idx2 + 1] = y1;
2368
- points[idx2 + 2] = z1;
2369
-
2370
- if (bottomStickGround) {
2371
- points[idx2 + 2] = 0;
2372
- } // bottom right
2373
-
2374
-
2375
- var idx3 = len * 2 * 3 + len * 3 + idx0;
2376
- points[idx3] = x2;
2377
- points[idx3 + 1] = y2;
2378
- points[idx3 + 2] = z2;
2379
-
2380
- if (bottomStickGround) {
2381
- points[idx3 + 2] = 0;
2382
- } // generate path uv
2383
-
2384
-
2194
+ const { leftPoints, rightPoints } = result;
2195
+ const line = result.line;
2196
+ const pathUV = options.pathUV;
2385
2197
  if (pathUV) {
2386
- var p = line[i];
2387
- var uvx = p.distance;
2388
- var uIndex0 = i * 2;
2389
- uv[uIndex0] = uvx;
2390
- uv[uIndex0 + 1] = 1;
2391
- var uIndex1 = len * 2 + uIndex0;
2392
- uv[uIndex1] = uvx;
2393
- uv[uIndex1 + 1] = 0;
2394
- var uIndex2 = len * 2 * 2 + uIndex0;
2395
- uv[uIndex2] = uvx;
2396
- uv[uIndex2 + 1] = 1;
2397
- var uIndex3 = len * 2 * 2 + len * 2 + uIndex0;
2398
- uv[uIndex3] = uvx;
2399
- uv[uIndex3 + 1] = 0;
2198
+ calLineDistance(line);
2199
+ for (let i = 0, len = line.length; i < len; i++) {
2200
+ leftPoints[i].distance = rightPoints[i].distance = line[i].distance;
2201
+ }
2400
2202
  }
2401
-
2402
- i++;
2403
- }
2404
-
2405
- if (!pathUV) {
2406
- i = 0;
2407
- len = points.length;
2408
- var uIndex = uv.length - 1;
2409
-
2203
+ let i = 0, len = leftPoints.length;
2204
+ const points = [], indices = [], uv = [];
2410
2205
  while (i < len) {
2411
- var x = points[i],
2412
- y = points[i + 1];
2413
- uv[++uIndex] = x;
2414
- uv[++uIndex] = y; // uvs.push(x, y);
2415
-
2416
- i += 3;
2206
+ // top left
2207
+ const idx0 = i * 3;
2208
+ const [x1, y1, z1] = leftPoints[i];
2209
+ points[idx0] = x1;
2210
+ points[idx0 + 1] = y1;
2211
+ points[idx0 + 2] = lz + z1;
2212
+ // top right
2213
+ const [x2, y2, z2] = rightPoints[i];
2214
+ const idx1 = len * 3 + idx0;
2215
+ points[idx1] = x2;
2216
+ points[idx1 + 1] = y2;
2217
+ points[idx1 + 2] = rz + z2;
2218
+ // bottom left
2219
+ const idx2 = (len * 2) * 3 + idx0;
2220
+ points[idx2] = x1;
2221
+ points[idx2 + 1] = y1;
2222
+ points[idx2 + 2] = z1;
2223
+ if (bottomStickGround) {
2224
+ points[idx2 + 2] = 0;
2225
+ }
2226
+ // bottom right
2227
+ const idx3 = (len * 2) * 3 + len * 3 + idx0;
2228
+ points[idx3] = x2;
2229
+ points[idx3 + 1] = y2;
2230
+ points[idx3 + 2] = z2;
2231
+ if (bottomStickGround) {
2232
+ points[idx3 + 2] = 0;
2233
+ }
2234
+ // generate path uv
2235
+ if (pathUV) {
2236
+ const p = line[i];
2237
+ const uvx = p.distance;
2238
+ const uIndex0 = i * 2;
2239
+ uv[uIndex0] = uvx;
2240
+ uv[uIndex0 + 1] = 1;
2241
+ const uIndex1 = len * 2 + uIndex0;
2242
+ uv[uIndex1] = uvx;
2243
+ uv[uIndex1 + 1] = 0;
2244
+ const uIndex2 = (len * 2) * 2 + uIndex0;
2245
+ uv[uIndex2] = uvx;
2246
+ uv[uIndex2 + 1] = 1;
2247
+ const uIndex3 = (len * 2) * 2 + len * 2 + uIndex0;
2248
+ uv[uIndex3] = uvx;
2249
+ uv[uIndex3 + 1] = 0;
2250
+ }
2251
+ i++;
2252
+ }
2253
+ if (!pathUV) {
2254
+ i = 0;
2255
+ len = points.length;
2256
+ let uIndex = uv.length - 1;
2257
+ while (i < len) {
2258
+ const x = points[i], y = points[i + 1];
2259
+ uv[++uIndex] = x;
2260
+ uv[++uIndex] = y;
2261
+ // uvs.push(x, y);
2262
+ i += 3;
2263
+ }
2417
2264
  }
2418
- }
2419
-
2420
- i = 0;
2421
- len = leftPoints.length;
2422
- var iIndex = indices.length - 1;
2423
-
2424
- while (i < len - 1) {
2425
- // top
2426
- // left1 left2 right1,right2
2427
- var a1 = i,
2428
- b1 = i + 1,
2429
- c1 = a1 + len,
2430
- d1 = b1 + len;
2431
- indices[++iIndex] = a1;
2432
- indices[++iIndex] = c1;
2433
- indices[++iIndex] = b1;
2434
- indices[++iIndex] = c1;
2435
- indices[++iIndex] = d1;
2436
- indices[++iIndex] = b1; // index.push(a1, c1, b1);
2437
- // index.push(c1, d1, b1);
2438
- // bottom
2439
- // left1 left2 right1,right2
2440
-
2441
- var len2 = len * 2;
2442
- var a2 = i + len2,
2443
- b2 = a2 + 1,
2444
- c2 = a2 + len,
2445
- d2 = b2 + len;
2446
- indices[++iIndex] = a2;
2447
- indices[++iIndex] = c2;
2448
- indices[++iIndex] = b2;
2449
- indices[++iIndex] = c2;
2450
- indices[++iIndex] = d2;
2451
- indices[++iIndex] = b2; // index.push(a2, c2, b2);
2452
- // index.push(c2, d2, b2);
2453
-
2454
- i++;
2455
- }
2456
-
2457
- result.indices = indices;
2458
- result.points = points;
2459
- result.uv = uv;
2460
-
2461
- if (depths) {
2462
- len = leftPoints.length;
2463
2265
  i = 0;
2464
-
2465
- while (i < len) {
2466
- leftPoints[i].depth = lz;
2467
- rightPoints[i].depth = rz;
2468
- i++;
2266
+ len = leftPoints.length;
2267
+ let iIndex = indices.length - 1;
2268
+ while (i < len - 1) {
2269
+ // top
2270
+ // left1 left2 right1,right2
2271
+ const a1 = i, b1 = i + 1, c1 = a1 + len, d1 = b1 + len;
2272
+ indices[++iIndex] = a1;
2273
+ indices[++iIndex] = c1;
2274
+ indices[++iIndex] = b1;
2275
+ indices[++iIndex] = c1;
2276
+ indices[++iIndex] = d1;
2277
+ indices[++iIndex] = b1;
2278
+ // index.push(a1, c1, b1);
2279
+ // index.push(c1, d1, b1);
2280
+ // bottom
2281
+ // left1 left2 right1,right2
2282
+ const len2 = len * 2;
2283
+ const a2 = i + len2, b2 = a2 + 1, c2 = a2 + len, d2 = b2 + len;
2284
+ indices[++iIndex] = a2;
2285
+ indices[++iIndex] = c2;
2286
+ indices[++iIndex] = b2;
2287
+ indices[++iIndex] = c2;
2288
+ indices[++iIndex] = d2;
2289
+ indices[++iIndex] = b2;
2290
+ // index.push(a2, c2, b2);
2291
+ // index.push(c2, d2, b2);
2292
+ i++;
2293
+ }
2294
+ result.indices = indices;
2295
+ result.points = points;
2296
+ result.uv = uv;
2297
+ if (depths) {
2298
+ len = leftPoints.length;
2299
+ i = 0;
2300
+ while (i < len) {
2301
+ leftPoints[i].depth = lz;
2302
+ rightPoints[i].depth = rz;
2303
+ i++;
2304
+ }
2469
2305
  }
2470
- }
2471
2306
  }
2472
-
2473
2307
  function generateSides(result, options) {
2474
- var points = result.points,
2475
- indices = result.indices,
2476
- leftPoints = result.leftPoints,
2477
- rightPoints = result.rightPoints,
2478
- uv = result.uv;
2479
- var z = options.depth;
2480
- var bottomStickGround = options.bottomStickGround;
2481
- var rings = [leftPoints, rightPoints];
2482
- var depthsEnable = result.depths;
2483
- var pathUV = options.pathUV;
2484
- var lineWidth = options.lineWidth;
2485
- var pIndex = points.length - 1;
2486
- var iIndex = indices.length - 1;
2487
- var uIndex = uv.length - 1;
2488
-
2489
- function addOneSideIndex(v1, v2) {
2490
- var idx = points.length / 3; // let pIndex = points.length - 1;
2491
-
2492
- var v1Depth = depthsEnable ? v1.depth : z;
2493
- var v2Depth = depthsEnable ? v2.depth : z; // top
2494
-
2495
- points[++pIndex] = v1[0];
2496
- points[++pIndex] = v1[1];
2497
- points[++pIndex] = v1Depth + v1[2];
2498
- points[++pIndex] = v2[0];
2499
- points[++pIndex] = v2[1];
2500
- points[++pIndex] = v2Depth + v2[2]; // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
2501
- // bottom
2502
-
2503
- points[++pIndex] = v1[0];
2504
- points[++pIndex] = v1[1];
2505
- points[++pIndex] = bottomStickGround ? 0 : v1[2];
2506
- points[++pIndex] = v2[0];
2507
- points[++pIndex] = v2[1];
2508
- points[++pIndex] = bottomStickGround ? 0 : v2[2]; // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
2509
-
2510
- var a = idx + 2,
2511
- b = idx + 3,
2512
- c = idx,
2513
- d = idx + 1;
2514
- indices[++iIndex] = a;
2515
- indices[++iIndex] = c;
2516
- indices[++iIndex] = b;
2517
- indices[++iIndex] = c;
2518
- indices[++iIndex] = d;
2519
- indices[++iIndex] = b; // index.push(a, c, b, c, d, b);
2520
-
2521
- if (!pathUV) {
2522
- generateSideWallUV(uv, points, a, b, c, d);
2523
- } else {
2524
- uv[++uIndex] = v1.distance;
2525
- uv[++uIndex] = v1Depth / lineWidth;
2526
- uv[++uIndex] = v2.distance;
2527
- uv[++uIndex] = v2Depth / lineWidth;
2528
- uv[++uIndex] = v1.distance;
2529
- uv[++uIndex] = 0;
2530
- uv[++uIndex] = v2.distance;
2531
- uv[++uIndex] = 0;
2308
+ const { points, indices, leftPoints, rightPoints, uv } = result;
2309
+ const z = options.depth;
2310
+ const bottomStickGround = options.bottomStickGround;
2311
+ const rings = [leftPoints, rightPoints];
2312
+ const depthsEnable = result.depths;
2313
+ const pathUV = options.pathUV;
2314
+ const lineWidth = options.lineWidth;
2315
+ let pIndex = points.length - 1;
2316
+ let iIndex = indices.length - 1;
2317
+ let uIndex = uv.length - 1;
2318
+ function addOneSideIndex(v1, v2) {
2319
+ const idx = points.length / 3;
2320
+ // let pIndex = points.length - 1;
2321
+ const v1Depth = (depthsEnable ? v1.depth : z);
2322
+ const v2Depth = (depthsEnable ? v2.depth : z);
2323
+ // top
2324
+ points[++pIndex] = v1[0];
2325
+ points[++pIndex] = v1[1];
2326
+ points[++pIndex] = v1Depth + v1[2];
2327
+ points[++pIndex] = v2[0];
2328
+ points[++pIndex] = v2[1];
2329
+ points[++pIndex] = v2Depth + v2[2];
2330
+ // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
2331
+ // bottom
2332
+ points[++pIndex] = v1[0];
2333
+ points[++pIndex] = v1[1];
2334
+ points[++pIndex] = bottomStickGround ? 0 : v1[2];
2335
+ points[++pIndex] = v2[0];
2336
+ points[++pIndex] = v2[1];
2337
+ points[++pIndex] = bottomStickGround ? 0 : v2[2];
2338
+ // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
2339
+ const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
2340
+ indices[++iIndex] = a;
2341
+ indices[++iIndex] = c;
2342
+ indices[++iIndex] = b;
2343
+ indices[++iIndex] = c;
2344
+ indices[++iIndex] = d;
2345
+ indices[++iIndex] = b;
2346
+ // index.push(a, c, b, c, d, b);
2347
+ if (!pathUV) {
2348
+ generateSideWallUV(uv, points, a, b, c, d);
2349
+ }
2350
+ else {
2351
+ uv[++uIndex] = v1.distance;
2352
+ uv[++uIndex] = v1Depth / lineWidth;
2353
+ uv[++uIndex] = v2.distance;
2354
+ uv[++uIndex] = v2Depth / lineWidth;
2355
+ uv[++uIndex] = v1.distance;
2356
+ uv[++uIndex] = 0;
2357
+ uv[++uIndex] = v2.distance;
2358
+ uv[++uIndex] = 0;
2359
+ }
2532
2360
  }
2533
- }
2534
-
2535
- for (var i = 0, _len2 = rings.length; i < _len2; i++) {
2536
- var ring = rings[i];
2537
-
2538
- if (i > 0) {
2539
- ring = ring.map(function (p) {
2540
- return p;
2541
- });
2542
- ring = ring.reverse();
2361
+ for (let i = 0, len = rings.length; i < len; i++) {
2362
+ let ring = rings[i];
2363
+ if (i > 0) {
2364
+ ring = ring.map(p => {
2365
+ return p;
2366
+ });
2367
+ ring = ring.reverse();
2368
+ }
2369
+ let j = 0;
2370
+ const len1 = ring.length - 1;
2371
+ while (j < len1) {
2372
+ const v1 = ring[j];
2373
+ const v2 = ring[j + 1];
2374
+ addOneSideIndex(v1, v2);
2375
+ j++;
2376
+ }
2543
2377
  }
2544
-
2545
- var j = 0;
2546
- var len1 = ring.length - 1;
2547
-
2548
- while (j < len1) {
2549
- var v1 = ring[j];
2550
- var v2 = ring[j + 1];
2551
- addOneSideIndex(v1, v2);
2552
- j++;
2378
+ const len = leftPoints.length;
2379
+ const vs = [rightPoints[0], leftPoints[0], leftPoints[len - 1], rightPoints[len - 1]];
2380
+ for (let i = 0; i < vs.length; i += 2) {
2381
+ const v1 = vs[i], v2 = vs[i + 1];
2382
+ addOneSideIndex(v1, v2);
2553
2383
  }
2554
- }
2555
-
2556
- var len = leftPoints.length;
2557
- var vs = [rightPoints[0], leftPoints[0], leftPoints[len - 1], rightPoints[len - 1]];
2558
-
2559
- for (var _i2 = 0; _i2 < vs.length; _i2 += 2) {
2560
- var _v = vs[_i2],
2561
- _v2 = vs[_i2 + 1];
2562
- addOneSideIndex(_v, _v2);
2563
- }
2564
2384
  }
2565
-
2566
- var TEMPV1 = {
2567
- x: 0,
2568
- y: 0
2569
- },
2570
- TEMPV2 = {
2571
- x: 0,
2572
- y: 0
2573
- };
2385
+ const TEMPV1 = { x: 0, y: 0 }, TEMPV2 = { x: 0, y: 0 };
2574
2386
  function expandLine(line, options) {
2575
- // let preAngle = 0;
2576
- var radius = options.lineWidth / 2;
2577
-
2578
- if (options.isSlope) {
2579
- radius *= 2;
2580
- }
2581
-
2582
- var points = [],
2583
- leftPoints = [],
2584
- rightPoints = [];
2585
- var len = line.length;
2586
- var i = 0;
2587
-
2588
- while (i < len) {
2589
- var p1 = line[i],
2590
- p2 = line[i + 1];
2591
- var currentp = line[i]; // last vertex
2592
-
2593
- if (i === len - 1) {
2594
- p1 = line[len - 2];
2595
- p2 = line[len - 1];
2596
- }
2597
-
2598
- var dy = p2[1] - p1[1],
2599
- dx = p2[0] - p1[0];
2600
- var rAngle = 0;
2601
- var rad = Math.atan(dy / dx);
2602
- var angle = radToDeg(rad); // preAngle = angle;
2603
-
2604
- if (i === 0 || i === len - 1) {
2605
- rAngle = angle;
2606
- rAngle -= 90;
2607
- } else {
2608
- // 至少3个顶点才会触发
2609
- var p0 = line[i - 1];
2610
- TEMPV1.x = p0[0] - p1[0];
2611
- TEMPV1.y = p0[1] - p1[1];
2612
- TEMPV2.x = p2[0] - p1[0];
2613
- TEMPV2.y = p2[1] - p1[1];
2614
- var vAngle = getAngle(TEMPV1, TEMPV2);
2615
- rAngle = angle - vAngle / 2;
2616
- }
2617
-
2618
- var rRad = degToRad(rAngle);
2619
- var p3 = currentp;
2620
- var x = Math.cos(rRad) + p3[0],
2621
- y = Math.sin(rRad) + p3[1];
2622
- var p4 = [x, y];
2623
-
2624
- var _translateLine = translateLine(p1, p2, radius),
2625
- line1 = _translateLine[0],
2626
- line2 = _translateLine[1];
2627
-
2628
- var op1 = lineIntersection(line1[0], line1[1], p3, p4);
2629
- var op2 = lineIntersection(line2[0], line2[1], p3, p4); // 平行,回头路
2630
-
2631
- if (!op1 || !op2) {
2632
- var len1 = points.length;
2633
- var point1 = points[len1 - 2];
2634
- var point2 = points[len1 - 1];
2635
-
2636
- if (!point1 || !point2) {
2637
- continue;
2638
- }
2639
-
2640
- op1 = [point1[0], point1[1]];
2641
- op2 = [point2[0], point2[1]];
2387
+ // let preAngle = 0;
2388
+ let radius = options.lineWidth / 2;
2389
+ if (options.isSlope) {
2390
+ radius *= 2;
2642
2391
  }
2643
-
2644
- op1[2] = currentp[2] || 0;
2645
- op2[2] = currentp[2] || 0; // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
2646
-
2647
- points.push(op1, op2);
2648
-
2649
- if (leftOnLine(op1, p1, p2)) {
2650
- leftPoints.push(op1);
2651
- rightPoints.push(op2);
2652
- } else {
2653
- leftPoints.push(op2);
2654
- rightPoints.push(op1);
2392
+ const points = [], leftPoints = [], rightPoints = [];
2393
+ const len = line.length;
2394
+ let i = 0;
2395
+ while (i < len) {
2396
+ let p1 = line[i], p2 = line[i + 1];
2397
+ const currentp = line[i];
2398
+ // last vertex
2399
+ if (i === len - 1) {
2400
+ p1 = line[len - 2];
2401
+ p2 = line[len - 1];
2402
+ }
2403
+ const dy = p2[1] - p1[1], dx = p2[0] - p1[0];
2404
+ let rAngle = 0;
2405
+ const rad = Math.atan(dy / dx);
2406
+ const angle = radToDeg(rad);
2407
+ // preAngle = angle;
2408
+ if (i === 0 || i === len - 1) {
2409
+ rAngle = angle;
2410
+ rAngle -= 90;
2411
+ }
2412
+ else {
2413
+ // 至少3个顶点才会触发
2414
+ const p0 = line[i - 1];
2415
+ TEMPV1.x = p0[0] - p1[0];
2416
+ TEMPV1.y = p0[1] - p1[1];
2417
+ TEMPV2.x = p2[0] - p1[0];
2418
+ TEMPV2.y = p2[1] - p1[1];
2419
+ const vAngle = getAngle(TEMPV1, TEMPV2);
2420
+ rAngle = angle - vAngle / 2;
2421
+ }
2422
+ const rRad = degToRad(rAngle);
2423
+ const p3 = currentp;
2424
+ const x = Math.cos(rRad) + p3[0], y = Math.sin(rRad) + p3[1];
2425
+ const p4 = [x, y];
2426
+ const [line1, line2] = translateLine(p1, p2, radius);
2427
+ let op1 = lineIntersection(line1[0], line1[1], p3, p4);
2428
+ let op2 = lineIntersection(line2[0], line2[1], p3, p4);
2429
+ // 平行,回头路
2430
+ if (!op1 || !op2) {
2431
+ const len1 = points.length;
2432
+ const point1 = points[len1 - 2];
2433
+ const point2 = points[len1 - 1];
2434
+ if (!point1 || !point2) {
2435
+ continue;
2436
+ }
2437
+ op1 = [point1[0], point1[1]];
2438
+ op2 = [point2[0], point2[1]];
2439
+ }
2440
+ op1[2] = currentp[2] || 0;
2441
+ op2[2] = currentp[2] || 0;
2442
+ // const [op1, op2] = calOffsetPoint(rRad, radius, p1);
2443
+ points.push(op1, op2);
2444
+ if (leftOnLine(op1, p1, p2)) {
2445
+ leftPoints.push(op1);
2446
+ rightPoints.push(op2);
2447
+ }
2448
+ else {
2449
+ leftPoints.push(op2);
2450
+ rightPoints.push(op1);
2451
+ }
2452
+ i++;
2655
2453
  }
2656
-
2657
- i++;
2658
- }
2659
-
2660
- return {
2661
- offsetPoints: points,
2662
- leftPoints: leftPoints,
2663
- rightPoints: rightPoints,
2664
- line: line
2665
- };
2666
- } // eslint-disable-next-line no-unused-vars
2667
-
2668
- var getAngle = function getAngle(_ref, _ref2) {
2669
- var x1 = _ref.x,
2670
- y1 = _ref.y;
2671
- var x2 = _ref2.x,
2672
- y2 = _ref2.y;
2673
- var dot = x1 * x2 + y1 * y2;
2674
- var det = x1 * y2 - y1 * x2;
2675
- var angle = Math.atan2(det, dot) / Math.PI * 180;
2676
- return (angle + 360) % 360;
2454
+ return { offsetPoints: points, leftPoints, rightPoints, line };
2455
+ }
2456
+ const getAngle = ({ x: x1, y: y1 }, { x: x2, y: y2 }) => {
2457
+ const dot = x1 * x2 + y1 * y2;
2458
+ const det = x1 * y2 - y1 * x2;
2459
+ const angle = Math.atan2(det, dot) / Math.PI * 180;
2460
+ return (angle + 360) % 360;
2677
2461
  };
2678
-
2679
2462
  function leftOnLine(p, p1, p2) {
2680
- var x1 = p1[0],
2681
- y1 = p1[1];
2682
- var x2 = p2[0],
2683
- y2 = p2[1];
2684
- var x = p[0],
2685
- y = p[1];
2686
- return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
2463
+ const [x1, y1] = p1;
2464
+ const [x2, y2] = p2;
2465
+ const [x, y] = p;
2466
+ return (y1 - y2) * x + (x2 - x1) * y + x1 * y2 - x2 * y1 > 0;
2687
2467
  }
2688
- /**
2689
- * 平移线
2690
- * @param {*} p1
2691
- * @param {*} p2
2692
- * @param {*} distance
2693
- * @returns
2468
+ /**
2469
+ * 平移线
2470
+ * @param {*} p1
2471
+ * @param {*} p2
2472
+ * @param {*} distance
2473
+ * @returns
2694
2474
  */
2695
-
2696
2475
  function translateLine(p1, p2, distance) {
2697
- var dy = p2[1] - p1[1],
2698
- dx = p2[0] - p1[0];
2699
- var rad = Math.atan2(dy, dx);
2700
- var rad1 = rad + Math.PI / 2;
2701
- var offsetX = Math.cos(rad1) * distance,
2702
- offsetY = Math.sin(rad1) * distance;
2703
- var tp1 = [p1[0] + offsetX, p1[1] + offsetY];
2704
- var tp2 = [p2[0] + offsetX, p2[1] + offsetY];
2705
- var rad2 = rad - Math.PI / 2;
2706
- offsetX = Math.cos(rad2) * distance;
2707
- offsetY = Math.sin(rad2) * distance;
2708
- var tp3 = [p1[0] + offsetX, p1[1] + offsetY];
2709
- var tp4 = [p2[0] + offsetX, p2[1] + offsetY];
2710
- return [[tp1, tp2], [tp3, tp4]];
2476
+ const dy = p2[1] - p1[1], dx = p2[0] - p1[0];
2477
+ const rad = Math.atan2(dy, dx);
2478
+ const rad1 = rad + Math.PI / 2;
2479
+ let offsetX = Math.cos(rad1) * distance, offsetY = Math.sin(rad1) * distance;
2480
+ const tp1 = [p1[0] + offsetX, p1[1] + offsetY];
2481
+ const tp2 = [p2[0] + offsetX, p2[1] + offsetY];
2482
+ const rad2 = rad - Math.PI / 2;
2483
+ offsetX = Math.cos(rad2) * distance;
2484
+ offsetY = Math.sin(rad2) * distance;
2485
+ const tp3 = [p1[0] + offsetX, p1[1] + offsetY];
2486
+ const tp4 = [p2[0] + offsetX, p2[1] + offsetY];
2487
+ return [[tp1, tp2], [tp3, tp4]];
2711
2488
  }
2712
- /**
2713
- * 直线交点
2714
- * @param {*} p1
2715
- * @param {*} p2
2716
- * @param {*} p3
2717
- * @param {*} p4
2718
- * @returns
2489
+ /**
2490
+ * 直线交点
2491
+ * @param {*} p1
2492
+ * @param {*} p2
2493
+ * @param {*} p3
2494
+ * @param {*} p4
2495
+ * @returns
2719
2496
  */
2720
-
2721
-
2722
2497
  function lineIntersection(p1, p2, p3, p4) {
2723
- var dx1 = p2[0] - p1[0],
2724
- dy1 = p2[1] - p1[1];
2725
- var dx2 = p4[0] - p3[0],
2726
- dy2 = p4[1] - p3[1];
2727
-
2728
- if (dx1 === 0 && dx2 === 0) {
2729
- return null;
2730
- }
2731
-
2732
- if (dy1 === 0 && dy2 === 0) {
2733
- return null;
2734
- }
2735
-
2736
- var k1 = dy1 / dx1;
2737
- var k2 = dy2 / dx2;
2738
- var b1 = p1[1] - k1 * p1[0];
2739
- var b2 = p3[1] - k2 * p3[0];
2740
- var x, y;
2741
-
2742
- if (dx1 === 0) {
2743
- x = p1[0];
2744
- y = k2 * x + b2;
2745
- } else if (dx2 === 0) {
2746
- x = p3[0];
2747
- y = k1 * x + b1;
2748
- } else if (dy1 === 0) {
2749
- y = p1[1];
2750
- x = (y - b2) / k2;
2751
- } else if (dy2 === 0) {
2752
- y = p3[1];
2753
- x = (y - b1) / k1;
2754
- } else {
2755
- x = (b2 - b1) / (k1 - k2);
2756
- y = k1 * x + b1;
2757
- }
2758
-
2759
- return [x, y];
2498
+ const dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1];
2499
+ const dx2 = p4[0] - p3[0], dy2 = p4[1] - p3[1];
2500
+ if (dx1 === 0 && dx2 === 0) {
2501
+ return null;
2502
+ }
2503
+ if (dy1 === 0 && dy2 === 0) {
2504
+ return null;
2505
+ }
2506
+ const k1 = dy1 / dx1;
2507
+ const k2 = dy2 / dx2;
2508
+ const b1 = p1[1] - k1 * p1[0];
2509
+ const b2 = p3[1] - k2 * p3[0];
2510
+ let x, y;
2511
+ if (dx1 === 0) {
2512
+ x = p1[0];
2513
+ y = k2 * x + b2;
2514
+ }
2515
+ else if (dx2 === 0) {
2516
+ x = p3[0];
2517
+ y = k1 * x + b1;
2518
+ }
2519
+ else if (dy1 === 0) {
2520
+ y = p1[1];
2521
+ x = (y - b2) / k2;
2522
+ }
2523
+ else if (dy2 === 0) {
2524
+ y = p3[1];
2525
+ x = (y - b1) / k1;
2526
+ }
2527
+ else {
2528
+ x = (b2 - b1) / (k1 - k2);
2529
+ y = k1 * x + b1;
2530
+ }
2531
+ return [x, y];
2760
2532
  }
2761
2533
 
2762
2534
  function cylinder(point, options) {
2763
- if (options === void 0) {
2764
- options = {};
2765
- }
2766
-
2767
- options = Object.assign({}, {
2768
- radius: 1,
2769
- height: 2,
2770
- radialSegments: 6
2771
- }, options);
2772
- var radialSegments = Math.round(Math.max(4, options.radialSegments));
2773
- var _options = options,
2774
- radius = _options.radius,
2775
- height = _options.height;
2776
- var aRad = 360 / radialSegments / 360 * Math.PI * 2;
2777
- var circlePointsLen = radialSegments + 1;
2778
- var points = new Float32Array(circlePointsLen * 3 * 2);
2779
- var centerx = point[0],
2780
- centery = point[1];
2781
- var idx = 0,
2782
- uIdx = 0;
2783
- var offset = circlePointsLen * 3,
2784
- uOffset = circlePointsLen * 2;
2785
- var indices = [],
2786
- uv = [];
2787
- var iIndex = indices.length - 1;
2788
-
2789
- for (var i = -1; i < radialSegments; i++) {
2790
- var rad = aRad * i;
2791
- var x = Math.cos(rad) * radius + centerx,
2792
- y = Math.sin(rad) * radius + centery; // bottom vertices
2793
-
2794
- points[idx] = x;
2795
- points[idx + 1] = y;
2796
- points[idx + 2] = 0; // top vertices
2797
-
2798
- points[idx + offset] = x;
2799
- points[idx + 1 + offset] = y;
2800
- points[idx + 2 + offset] = height;
2801
- var u = 0,
2802
- v = 0;
2803
- u = 0.5 + x / radius / 2;
2804
- v = 0.5 + y / radius / 2;
2805
- uv[uIdx] = u;
2806
- uv[uIdx + 1] = v;
2807
- uv[uIdx + uOffset] = u;
2808
- uv[uIdx + 1 + uOffset] = v;
2809
- idx += 3;
2810
- uIdx += 2;
2811
-
2812
- if (i > 1) {
2813
- // bottom indices
2814
- // indices.push(0, i - 1, i);
2815
- indices[++iIndex] = 0;
2816
- indices[++iIndex] = i - 1;
2817
- indices[++iIndex] = i;
2535
+ options = Object.assign({}, { radius: 1, height: 2, radialSegments: 6 }, options);
2536
+ const radialSegments = Math.round(Math.max(4, options.radialSegments));
2537
+ let { radius, height } = options;
2538
+ radius = radius;
2539
+ height = height;
2540
+ const aRad = 360 / radialSegments / 360 * Math.PI * 2;
2541
+ const circlePointsLen = (radialSegments + 1);
2542
+ const points = new Float32Array(circlePointsLen * 3 * 2);
2543
+ const [centerx, centery] = point;
2544
+ let idx = 0, uIdx = 0;
2545
+ const offset = circlePointsLen * 3, uOffset = circlePointsLen * 2;
2546
+ const indices = [], uv = [];
2547
+ let iIndex = indices.length - 1;
2548
+ for (let i = -1; i < radialSegments; i++) {
2549
+ const rad = aRad * i;
2550
+ const x = Math.cos(rad) * radius + centerx, y = Math.sin(rad) * radius + centery;
2551
+ // bottom vertices
2552
+ points[idx] = x;
2553
+ points[idx + 1] = y;
2554
+ points[idx + 2] = 0;
2555
+ // top vertices
2556
+ points[idx + offset] = x;
2557
+ points[idx + 1 + offset] = y;
2558
+ points[idx + 2 + offset] = height;
2559
+ let u = 0, v = 0;
2560
+ u = 0.5 + x / radius / 2;
2561
+ v = 0.5 + y / radius / 2;
2562
+ uv[uIdx] = u;
2563
+ uv[uIdx + 1] = v;
2564
+ uv[uIdx + uOffset] = u;
2565
+ uv[uIdx + 1 + uOffset] = v;
2566
+ idx += 3;
2567
+ uIdx += 2;
2568
+ if (i > 1) {
2569
+ // bottom indices
2570
+ // indices.push(0, i - 1, i);
2571
+ indices[++iIndex] = 0;
2572
+ indices[++iIndex] = i - 1;
2573
+ indices[++iIndex] = i;
2574
+ }
2818
2575
  }
2819
- }
2820
-
2821
- idx -= 3;
2822
- points[idx] = points[0];
2823
- points[idx + 1] = points[1];
2824
- points[idx + 2] = points[2];
2825
- var pointsLen = points.length;
2826
- points[pointsLen - 3] = points[0];
2827
- points[pointsLen - 2] = points[1];
2828
- points[pointsLen - 1] = height;
2829
- var indicesLen = indices.length; // top indices
2830
-
2831
- iIndex = indices.length - 1;
2832
-
2833
- for (var _i = 0; _i < indicesLen; _i++) {
2834
- var index = indices[_i];
2835
- indices[++iIndex] = index + circlePointsLen; // indices.push(index + circlePointsLen);
2836
- }
2837
-
2838
- var sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
2839
- var pIndex = -1;
2840
- idx = circlePointsLen * 2;
2841
- uIdx = 0;
2842
- iIndex = indices.length - 1;
2843
- var uvIndex = uv.length - 1;
2844
-
2845
- for (var _i2 = 0, len = points.length / 2; _i2 < len - 3; _i2 += 3) {
2846
- var x1 = points[_i2],
2847
- y1 = points[_i2 + 1],
2848
- x2 = points[_i2 + 3],
2849
- y2 = points[_i2 + 4];
2850
- sidePoints[++pIndex] = x1;
2851
- sidePoints[++pIndex] = y1;
2852
- sidePoints[++pIndex] = height;
2853
- sidePoints[++pIndex] = x2;
2854
- sidePoints[++pIndex] = y2;
2855
- sidePoints[++pIndex] = height;
2856
- sidePoints[++pIndex] = x1;
2857
- sidePoints[++pIndex] = y1;
2858
- sidePoints[++pIndex] = 0;
2859
- sidePoints[++pIndex] = x2;
2860
- sidePoints[++pIndex] = y2;
2861
- sidePoints[++pIndex] = 0;
2862
- var a = idx + 2,
2863
- b = idx + 3,
2864
- c = idx,
2865
- d = idx + 1; // indices.push(a, c, b, c, d, b);
2866
-
2867
- indices[++iIndex] = c;
2868
- indices[++iIndex] = a;
2869
- indices[++iIndex] = d;
2870
- indices[++iIndex] = a;
2871
- indices[++iIndex] = b;
2872
- indices[++iIndex] = d; // indices.push(c, a, d, a, b, d);
2873
-
2874
- idx += 4;
2875
- var u1 = uIdx / circlePointsLen,
2876
- u2 = (uIdx + 1) / circlePointsLen;
2877
- uv[++uvIndex] = u1;
2878
- uv[++uvIndex] = height / radius / 2;
2879
- uv[++uvIndex] = u2;
2880
- uv[++uvIndex] = height / radius / 2;
2881
- uv[++uvIndex] = u1;
2882
- uv[++uvIndex] = 0;
2883
- uv[++uvIndex] = u2;
2884
- uv[++uvIndex] = 0; // uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
2885
-
2886
- uIdx++;
2887
- }
2888
-
2889
- var position = new Float32Array(points.length + sidePoints.length);
2890
- position.set(points, 0);
2891
- position.set(sidePoints, points.length);
2892
- var normal = generateNormal(indices, position);
2893
- return {
2894
- points: points,
2895
- indices: new Uint32Array(indices),
2896
- position: position,
2897
- normal: normal,
2898
- uv: new Float32Array(uv)
2899
- };
2576
+ idx -= 3;
2577
+ points[idx] = points[0];
2578
+ points[idx + 1] = points[1];
2579
+ points[idx + 2] = points[2];
2580
+ const pointsLen = points.length;
2581
+ points[pointsLen - 3] = points[0];
2582
+ points[pointsLen - 2] = points[1];
2583
+ points[pointsLen - 1] = height;
2584
+ const indicesLen = indices.length;
2585
+ // top indices
2586
+ iIndex = indices.length - 1;
2587
+ for (let i = 0; i < indicesLen; i++) {
2588
+ const index = indices[i];
2589
+ indices[++iIndex] = index + circlePointsLen;
2590
+ // indices.push(index + circlePointsLen);
2591
+ }
2592
+ const sidePoints = new Float32Array((circlePointsLen * 3 * 2 - 6) * 2);
2593
+ let pIndex = -1;
2594
+ idx = circlePointsLen * 2;
2595
+ uIdx = 0;
2596
+ iIndex = indices.length - 1;
2597
+ let uvIndex = uv.length - 1;
2598
+ for (let i = 0, len = points.length / 2; i < len - 3; i += 3) {
2599
+ const x1 = points[i], y1 = points[i + 1], x2 = points[i + 3], y2 = points[i + 4];
2600
+ sidePoints[++pIndex] = x1;
2601
+ sidePoints[++pIndex] = y1;
2602
+ sidePoints[++pIndex] = height;
2603
+ sidePoints[++pIndex] = x2;
2604
+ sidePoints[++pIndex] = y2;
2605
+ sidePoints[++pIndex] = height;
2606
+ sidePoints[++pIndex] = x1;
2607
+ sidePoints[++pIndex] = y1;
2608
+ sidePoints[++pIndex] = 0;
2609
+ sidePoints[++pIndex] = x2;
2610
+ sidePoints[++pIndex] = y2;
2611
+ sidePoints[++pIndex] = 0;
2612
+ const a = idx + 2, b = idx + 3, c = idx, d = idx + 1;
2613
+ // indices.push(a, c, b, c, d, b);
2614
+ indices[++iIndex] = c;
2615
+ indices[++iIndex] = a;
2616
+ indices[++iIndex] = d;
2617
+ indices[++iIndex] = a;
2618
+ indices[++iIndex] = b;
2619
+ indices[++iIndex] = d;
2620
+ // indices.push(c, a, d, a, b, d);
2621
+ idx += 4;
2622
+ const u1 = uIdx / circlePointsLen, u2 = (uIdx + 1) / circlePointsLen;
2623
+ uv[++uvIndex] = u1;
2624
+ uv[++uvIndex] = height / radius / 2;
2625
+ uv[++uvIndex] = u2;
2626
+ uv[++uvIndex] = height / radius / 2;
2627
+ uv[++uvIndex] = u1;
2628
+ uv[++uvIndex] = 0;
2629
+ uv[++uvIndex] = u2;
2630
+ uv[++uvIndex] = 0;
2631
+ // uvs.push(u1, height / radius / 2, u2, height / radius / 2, u1, 0, u2, 0);
2632
+ uIdx++;
2633
+ }
2634
+ const position = new Float32Array(points.length + sidePoints.length);
2635
+ position.set(points, 0);
2636
+ position.set(sidePoints, points.length);
2637
+ const normal = generateNormal(indices, position);
2638
+ return { points, indices: new Uint32Array(indices), position, normal, uv: new Float32Array(uv) };
2900
2639
  }
2901
2640
 
2902
2641
  /* eslint-disable no-tabs */
@@ -4191,539 +3930,505 @@ var PathPointList = /*#__PURE__*/function () {
4191
3930
  return PathPointList;
4192
3931
  }();
4193
3932
 
4194
- var UP$1 = new Vector3(0, 0, 1);
4195
- var right = new Vector3();
4196
- var left = new Vector3(); // for sharp corners
4197
-
4198
- var leftOffset = new Vector3();
4199
- var rightOffset = new Vector3();
4200
- var tempPoint1 = new Vector3();
4201
- var tempPoint2 = new Vector3();
3933
+ const UP$1 = new Vector3(0, 0, 1);
3934
+ const right = new Vector3();
3935
+ const left = new Vector3();
3936
+ // for sharp corners
3937
+ const leftOffset = new Vector3();
3938
+ const rightOffset = new Vector3();
3939
+ const tempPoint1 = new Vector3();
3940
+ const tempPoint2 = new Vector3();
4202
3941
  function expandPaths(lines, options) {
4203
- options = Object.assign({}, {
4204
- lineWidth: 1,
4205
- cornerRadius: 0,
4206
- cornerSplit: 10
4207
- }, options);
4208
- var results = lines.map(function (line) {
4209
- var points = line2Vectors(line);
4210
- var pathPointList = new PathPointList();
4211
- pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP$1);
4212
- var result = generatePathVertexData(pathPointList, options);
4213
- result.line = line;
4214
- result.position = new Float32Array(result.position);
4215
- result.indices = new Uint32Array(result.indices);
4216
- result.uv = new Float32Array(result.uv);
4217
- result.normal = new Float32Array(result.normal);
3942
+ options = Object.assign({}, { lineWidth: 1, cornerRadius: 0, cornerSplit: 10 }, options);
3943
+ const results = lines.map(line => {
3944
+ const points = line2Vectors(line);
3945
+ const pathPointList = new PathPointList();
3946
+ //@ts-ignore
3947
+ pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP$1);
3948
+ const params = generatePathVertexData(pathPointList, options);
3949
+ const result = {
3950
+ position: new Float32Array(params.position),
3951
+ indices: new Uint32Array(params.indices),
3952
+ uv: new Float32Array(params.uv),
3953
+ normal: new Float32Array(params.normal),
3954
+ line,
3955
+ count: params.count
3956
+ };
3957
+ return result;
3958
+ });
3959
+ const result = merge(results);
3960
+ result.lines = lines;
4218
3961
  return result;
4219
- });
4220
- var result = merge(results);
4221
- result.lines = lines;
4222
- return result;
4223
- } // Vertex Data Generate Functions
3962
+ }
3963
+ // Vertex Data Generate Functions
4224
3964
  // code copy from https://github.com/shawn0326/three.path/blob/master/src/PathGeometry.js
4225
-
4226
3965
  function generatePathVertexData(pathPointList, options) {
4227
- var width = options.lineWidth || 0.1;
4228
- var progress = 1;
4229
- var halfWidth = width / 2;
4230
- var sideWidth = width;
4231
- var totalDistance = pathPointList.distance();
4232
- var progressDistance = progress * totalDistance;
4233
-
4234
- if (totalDistance === 0) {
4235
- return null;
4236
- }
4237
-
4238
- var sharpUvOffset = halfWidth / sideWidth; // const sharpUvOffset2 = halfWidth / totalDistance;
4239
-
4240
- var count = 0; // modify data
4241
-
4242
- var position = [];
4243
- var normal = [];
4244
- var uv = [];
4245
- var indices = [];
4246
- var verticesCount = 0;
4247
- var pIndex = position.length - 1;
4248
- var nIndex = normal.length - 1;
4249
- var uIndex = uv.length - 1;
4250
- var iIndex = indices.length - 1;
4251
-
4252
- function addVertices(pathPoint) {
4253
- var first = position.length === 0;
4254
- var sharpCorner = pathPoint.sharp && !first;
4255
- var uvDist = pathPoint.dist / sideWidth; // const uvDist2 = pathPoint.dist / totalDistance;
4256
-
4257
- var dir = pathPoint.dir;
4258
- var up = pathPoint.up;
4259
- var _right = pathPoint.right;
4260
-
4261
- {
4262
- right.copy(_right).multiplyScalar(halfWidth * pathPoint.widthScale);
3966
+ const width = options.lineWidth || 0.1;
3967
+ const progress = 1;
3968
+ const halfWidth = width / 2;
3969
+ const sideWidth = (width);
3970
+ const totalDistance = pathPointList.distance();
3971
+ const progressDistance = progress * totalDistance;
3972
+ let count = 0;
3973
+ // modify data
3974
+ const position = [];
3975
+ const normal = [];
3976
+ const uv = [];
3977
+ const indices = [];
3978
+ let verticesCount = 0;
3979
+ if (totalDistance === 0) {
3980
+ return {
3981
+ position: position,
3982
+ normal,
3983
+ uv: uv,
3984
+ indices: indices,
3985
+ count
3986
+ };
4263
3987
  }
4264
-
4265
- {
4266
- left.copy(_right).multiplyScalar(-halfWidth * pathPoint.widthScale);
3988
+ const sharpUvOffset = halfWidth / sideWidth;
3989
+ // const sharpUvOffset2 = halfWidth / totalDistance;
3990
+ let pIndex = position.length - 1;
3991
+ let nIndex = normal.length - 1;
3992
+ let uIndex = uv.length - 1;
3993
+ let iIndex = indices.length - 1;
3994
+ function addVertices(pathPoint) {
3995
+ const first = position.length === 0;
3996
+ const sharpCorner = pathPoint.sharp && !first;
3997
+ const uvDist = pathPoint.dist / sideWidth;
3998
+ // const uvDist2 = pathPoint.dist / totalDistance;
3999
+ const dir = pathPoint.dir;
4000
+ const up = pathPoint.up;
4001
+ const _right = pathPoint.right;
4002
+ //@ts-ignore
4003
+ {
4004
+ right.copy(_right).multiplyScalar(halfWidth * pathPoint.widthScale);
4005
+ }
4006
+ //@ts-ignore
4007
+ {
4008
+ left.copy(_right).multiplyScalar(-halfWidth * pathPoint.widthScale);
4009
+ }
4010
+ right.add(pathPoint.pos);
4011
+ left.add(pathPoint.pos);
4012
+ if (sharpCorner) {
4013
+ leftOffset.fromArray(position, position.length - 6).sub(left);
4014
+ rightOffset.fromArray(position, position.length - 3).sub(right);
4015
+ const leftDist = leftOffset.length();
4016
+ const rightDist = rightOffset.length();
4017
+ const sideOffset = leftDist - rightDist;
4018
+ let longerOffset, longEdge;
4019
+ if (sideOffset > 0) {
4020
+ longerOffset = leftOffset;
4021
+ longEdge = left;
4022
+ }
4023
+ else {
4024
+ longerOffset = rightOffset;
4025
+ longEdge = right;
4026
+ }
4027
+ tempPoint1.copy(longerOffset).setLength(Math.abs(sideOffset)).add(longEdge);
4028
+ // eslint-disable-next-line prefer-const
4029
+ let _cos = tempPoint2.copy(longEdge).sub(tempPoint1).normalize().dot(dir);
4030
+ // eslint-disable-next-line prefer-const
4031
+ let _len = tempPoint2.copy(longEdge).sub(tempPoint1).length();
4032
+ // eslint-disable-next-line prefer-const
4033
+ let _dist = _cos * _len * 2;
4034
+ tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
4035
+ if (sideOffset > 0) {
4036
+ position[++pIndex] = tempPoint1.x;
4037
+ position[++pIndex] = tempPoint1.y;
4038
+ position[++pIndex] = tempPoint1.z;
4039
+ position[++pIndex] = right.x;
4040
+ position[++pIndex] = right.y;
4041
+ position[++pIndex] = right.z;
4042
+ position[++pIndex] = left.x;
4043
+ position[++pIndex] = left.y;
4044
+ position[++pIndex] = left.z;
4045
+ position[++pIndex] = right.x;
4046
+ position[++pIndex] = right.y;
4047
+ position[++pIndex] = right.z;
4048
+ position[++pIndex] = tempPoint2.x;
4049
+ position[++pIndex] = tempPoint2.y;
4050
+ position[++pIndex] = tempPoint2.z;
4051
+ position[++pIndex] = right.x;
4052
+ position[++pIndex] = right.y;
4053
+ position[++pIndex] = right.z;
4054
+ // position.push(
4055
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
4056
+ // right.x, right.y, right.z, // 5
4057
+ // left.x, left.y, left.z, // 4
4058
+ // right.x, right.y, right.z, // 3
4059
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
4060
+ // right.x, right.y, right.z // 1
4061
+ // );
4062
+ verticesCount += 6;
4063
+ indices[++iIndex] = verticesCount - 6;
4064
+ indices[++iIndex] = verticesCount - 8;
4065
+ indices[++iIndex] = verticesCount - 7;
4066
+ indices[++iIndex] = verticesCount - 6;
4067
+ indices[++iIndex] = verticesCount - 7;
4068
+ indices[++iIndex] = verticesCount - 5;
4069
+ indices[++iIndex] = verticesCount - 4;
4070
+ indices[++iIndex] = verticesCount - 6;
4071
+ indices[++iIndex] = verticesCount - 5;
4072
+ indices[++iIndex] = verticesCount - 2;
4073
+ indices[++iIndex] = verticesCount - 4;
4074
+ indices[++iIndex] = verticesCount - 1;
4075
+ // indices.push(
4076
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
4077
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
4078
+ // verticesCount - 4, verticesCount - 6, verticesCount - 5,
4079
+ // verticesCount - 2, verticesCount - 4, verticesCount - 1
4080
+ // );
4081
+ count += 12;
4082
+ }
4083
+ else {
4084
+ position[++pIndex] = left.x;
4085
+ position[++pIndex] = left.y;
4086
+ position[++pIndex] = left.z;
4087
+ position[++pIndex] = tempPoint1.x;
4088
+ position[++pIndex] = tempPoint1.y;
4089
+ position[++pIndex] = tempPoint1.z;
4090
+ position[++pIndex] = left.x;
4091
+ position[++pIndex] = left.y;
4092
+ position[++pIndex] = left.z;
4093
+ position[++pIndex] = right.x;
4094
+ position[++pIndex] = right.y;
4095
+ position[++pIndex] = right.z;
4096
+ position[++pIndex] = left.x;
4097
+ position[++pIndex] = left.y;
4098
+ position[++pIndex] = left.z;
4099
+ position[++pIndex] = tempPoint2.x;
4100
+ position[++pIndex] = tempPoint2.y;
4101
+ position[++pIndex] = tempPoint2.z;
4102
+ // position.push(
4103
+ // left.x, left.y, left.z, // 6
4104
+ // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
4105
+ // left.x, left.y, left.z, // 4
4106
+ // right.x, right.y, right.z, // 3
4107
+ // left.x, left.y, left.z, // 2
4108
+ // tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
4109
+ // );
4110
+ verticesCount += 6;
4111
+ indices[++iIndex] = verticesCount - 6;
4112
+ indices[++iIndex] = verticesCount - 8;
4113
+ indices[++iIndex] = verticesCount - 7;
4114
+ indices[++iIndex] = verticesCount - 6;
4115
+ indices[++iIndex] = verticesCount - 7;
4116
+ indices[++iIndex] = verticesCount - 5;
4117
+ indices[++iIndex] = verticesCount - 6;
4118
+ indices[++iIndex] = verticesCount - 5;
4119
+ indices[++iIndex] = verticesCount - 3;
4120
+ indices[++iIndex] = verticesCount - 2;
4121
+ indices[++iIndex] = verticesCount - 3;
4122
+ indices[++iIndex] = verticesCount - 1;
4123
+ // indices.push(
4124
+ // verticesCount - 6, verticesCount - 8, verticesCount - 7,
4125
+ // verticesCount - 6, verticesCount - 7, verticesCount - 5,
4126
+ // verticesCount - 6, verticesCount - 5, verticesCount - 3,
4127
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
4128
+ // );
4129
+ count += 12;
4130
+ }
4131
+ for (let i = 0; i < 6; i++) {
4132
+ normal[++nIndex] = up.x;
4133
+ normal[++nIndex] = up.y;
4134
+ normal[++nIndex] = up.z;
4135
+ }
4136
+ // normal.push(
4137
+ // up.x, up.y, up.z,
4138
+ // up.x, up.y, up.z,
4139
+ // up.x, up.y, up.z,
4140
+ // up.x, up.y, up.z,
4141
+ // up.x, up.y, up.z,
4142
+ // up.x, up.y, up.z
4143
+ // );
4144
+ uv[++uIndex] = uvDist - sharpUvOffset;
4145
+ uv[++uIndex] = 0;
4146
+ uv[++uIndex] = uvDist - sharpUvOffset;
4147
+ uv[++uIndex] = 1;
4148
+ uv[++uIndex] = uvDist;
4149
+ uv[++uIndex] = 0;
4150
+ uv[++uIndex] = uvDist;
4151
+ uv[++uIndex] = 1;
4152
+ uv[++uIndex] = uvDist + sharpUvOffset;
4153
+ uv[++uIndex] = 0;
4154
+ uv[++uIndex] = uvDist + sharpUvOffset;
4155
+ uv[++uIndex] = 1;
4156
+ // uv.push(
4157
+ // uvDist - sharpUvOffset, 0,
4158
+ // uvDist - sharpUvOffset, 1,
4159
+ // uvDist, 0,
4160
+ // uvDist, 1,
4161
+ // uvDist + sharpUvOffset, 0,
4162
+ // uvDist + sharpUvOffset, 1
4163
+ // );
4164
+ // if (generateUv2) {
4165
+ // uv2.push(
4166
+ // uvDist2 - sharpUvOffset2, 0,
4167
+ // uvDist2 - sharpUvOffset2, 1,
4168
+ // uvDist2, 0,
4169
+ // uvDist2, 1,
4170
+ // uvDist2 + sharpUvOffset2, 0,
4171
+ // uvDist2 + sharpUvOffset2, 1
4172
+ // );
4173
+ // }
4174
+ }
4175
+ else {
4176
+ position[++pIndex] = left.x;
4177
+ position[++pIndex] = left.y;
4178
+ position[++pIndex] = left.z;
4179
+ position[++pIndex] = right.x;
4180
+ position[++pIndex] = right.y;
4181
+ position[++pIndex] = right.z;
4182
+ // position.push(
4183
+ // left.x, left.y, left.z,
4184
+ // right.x, right.y, right.z
4185
+ // );
4186
+ normal[++nIndex] = up.x;
4187
+ normal[++nIndex] = up.y;
4188
+ normal[++nIndex] = up.z;
4189
+ normal[++nIndex] = up.x;
4190
+ normal[++nIndex] = up.y;
4191
+ normal[++nIndex] = up.z;
4192
+ // normal.push(
4193
+ // up.x, up.y, up.z,
4194
+ // up.x, up.y, up.z
4195
+ // );
4196
+ uv[++uIndex] = uvDist;
4197
+ uv[++uIndex] = 0;
4198
+ uv[++uIndex] = uvDist;
4199
+ uv[++uIndex] = 1;
4200
+ // uv.push(
4201
+ // uvDist, 0,
4202
+ // uvDist, 1
4203
+ // );
4204
+ // if (generateUv2) {
4205
+ // uv2.push(
4206
+ // uvDist2, 0,
4207
+ // uvDist2, 1
4208
+ // );
4209
+ // }
4210
+ verticesCount += 2;
4211
+ if (!first) {
4212
+ indices[++iIndex] = verticesCount - 2;
4213
+ indices[++iIndex] = verticesCount - 4;
4214
+ indices[++iIndex] = verticesCount - 3;
4215
+ indices[++iIndex] = verticesCount - 2;
4216
+ indices[++iIndex] = verticesCount - 3;
4217
+ indices[++iIndex] = verticesCount - 1;
4218
+ // indices.push(
4219
+ // verticesCount - 2, verticesCount - 4, verticesCount - 3,
4220
+ // verticesCount - 2, verticesCount - 3, verticesCount - 1
4221
+ // );
4222
+ count += 6;
4223
+ }
4224
+ }
4267
4225
  }
4268
-
4269
- right.add(pathPoint.pos);
4270
- left.add(pathPoint.pos);
4271
-
4272
- if (sharpCorner) {
4273
- leftOffset.fromArray(position, position.length - 6).sub(left);
4274
- rightOffset.fromArray(position, position.length - 3).sub(right);
4275
- var leftDist = leftOffset.length();
4276
- var rightDist = rightOffset.length();
4277
- var sideOffset = leftDist - rightDist;
4278
- var longerOffset, longEdge;
4279
-
4280
- if (sideOffset > 0) {
4281
- longerOffset = leftOffset;
4282
- longEdge = left;
4283
- } else {
4284
- longerOffset = rightOffset;
4285
- longEdge = right;
4286
- }
4287
-
4288
- tempPoint1.copy(longerOffset).setLength(Math.abs(sideOffset)).add(longEdge); // eslint-disable-next-line prefer-const
4289
-
4290
- var _cos = tempPoint2.copy(longEdge).sub(tempPoint1).normalize().dot(dir); // eslint-disable-next-line prefer-const
4291
-
4292
-
4293
- var _len = tempPoint2.copy(longEdge).sub(tempPoint1).length(); // eslint-disable-next-line prefer-const
4294
-
4295
-
4296
- var _dist = _cos * _len * 2;
4297
-
4298
- tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
4299
-
4300
- if (sideOffset > 0) {
4301
- position[++pIndex] = tempPoint1.x;
4302
- position[++pIndex] = tempPoint1.y;
4303
- position[++pIndex] = tempPoint1.z;
4304
- position[++pIndex] = right.x;
4305
- position[++pIndex] = right.y;
4306
- position[++pIndex] = right.z;
4307
- position[++pIndex] = left.x;
4308
- position[++pIndex] = left.y;
4309
- position[++pIndex] = left.z;
4310
- position[++pIndex] = right.x;
4311
- position[++pIndex] = right.y;
4312
- position[++pIndex] = right.z;
4313
- position[++pIndex] = tempPoint2.x;
4314
- position[++pIndex] = tempPoint2.y;
4315
- position[++pIndex] = tempPoint2.z;
4316
- position[++pIndex] = right.x;
4317
- position[++pIndex] = right.y;
4318
- position[++pIndex] = right.z; // position.push(
4319
- // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
4320
- // right.x, right.y, right.z, // 5
4321
- // left.x, left.y, left.z, // 4
4322
- // right.x, right.y, right.z, // 3
4323
- // tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
4324
- // right.x, right.y, right.z // 1
4325
- // );
4326
-
4327
- verticesCount += 6;
4328
- indices[++iIndex] = verticesCount - 6;
4329
- indices[++iIndex] = verticesCount - 8;
4330
- indices[++iIndex] = verticesCount - 7;
4331
- indices[++iIndex] = verticesCount - 6;
4332
- indices[++iIndex] = verticesCount - 7;
4333
- indices[++iIndex] = verticesCount - 5;
4334
- indices[++iIndex] = verticesCount - 4;
4335
- indices[++iIndex] = verticesCount - 6;
4336
- indices[++iIndex] = verticesCount - 5;
4337
- indices[++iIndex] = verticesCount - 2;
4338
- indices[++iIndex] = verticesCount - 4;
4339
- indices[++iIndex] = verticesCount - 1; // indices.push(
4340
- // verticesCount - 6, verticesCount - 8, verticesCount - 7,
4341
- // verticesCount - 6, verticesCount - 7, verticesCount - 5,
4342
- // verticesCount - 4, verticesCount - 6, verticesCount - 5,
4343
- // verticesCount - 2, verticesCount - 4, verticesCount - 1
4344
- // );
4345
-
4346
- count += 12;
4347
- } else {
4348
- position[++pIndex] = left.x;
4349
- position[++pIndex] = left.y;
4350
- position[++pIndex] = left.z;
4351
- position[++pIndex] = tempPoint1.x;
4352
- position[++pIndex] = tempPoint1.y;
4353
- position[++pIndex] = tempPoint1.z;
4354
- position[++pIndex] = left.x;
4355
- position[++pIndex] = left.y;
4356
- position[++pIndex] = left.z;
4357
- position[++pIndex] = right.x;
4358
- position[++pIndex] = right.y;
4359
- position[++pIndex] = right.z;
4360
- position[++pIndex] = left.x;
4361
- position[++pIndex] = left.y;
4362
- position[++pIndex] = left.z;
4363
- position[++pIndex] = tempPoint2.x;
4364
- position[++pIndex] = tempPoint2.y;
4365
- position[++pIndex] = tempPoint2.z; // position.push(
4366
- // left.x, left.y, left.z, // 6
4367
- // tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
4368
- // left.x, left.y, left.z, // 4
4369
- // right.x, right.y, right.z, // 3
4370
- // left.x, left.y, left.z, // 2
4371
- // tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
4372
- // );
4373
-
4374
- verticesCount += 6;
4375
- indices[++iIndex] = verticesCount - 6;
4376
- indices[++iIndex] = verticesCount - 8;
4377
- indices[++iIndex] = verticesCount - 7;
4378
- indices[++iIndex] = verticesCount - 6;
4379
- indices[++iIndex] = verticesCount - 7;
4380
- indices[++iIndex] = verticesCount - 5;
4381
- indices[++iIndex] = verticesCount - 6;
4382
- indices[++iIndex] = verticesCount - 5;
4383
- indices[++iIndex] = verticesCount - 3;
4384
- indices[++iIndex] = verticesCount - 2;
4385
- indices[++iIndex] = verticesCount - 3;
4386
- indices[++iIndex] = verticesCount - 1; // indices.push(
4387
- // verticesCount - 6, verticesCount - 8, verticesCount - 7,
4388
- // verticesCount - 6, verticesCount - 7, verticesCount - 5,
4389
- // verticesCount - 6, verticesCount - 5, verticesCount - 3,
4390
- // verticesCount - 2, verticesCount - 3, verticesCount - 1
4391
- // );
4392
-
4393
- count += 12;
4394
- }
4395
-
4396
- for (var i = 0; i < 6; i++) {
4397
- normal[++nIndex] = up.x;
4398
- normal[++nIndex] = up.y;
4399
- normal[++nIndex] = up.z;
4400
- } // normal.push(
4401
- // up.x, up.y, up.z,
4402
- // up.x, up.y, up.z,
4403
- // up.x, up.y, up.z,
4404
- // up.x, up.y, up.z,
4405
- // up.x, up.y, up.z,
4406
- // up.x, up.y, up.z
4407
- // );
4408
-
4409
-
4410
- uv[++uIndex] = uvDist - sharpUvOffset;
4411
- uv[++uIndex] = 0;
4412
- uv[++uIndex] = uvDist - sharpUvOffset;
4413
- uv[++uIndex] = 1;
4414
- uv[++uIndex] = uvDist;
4415
- uv[++uIndex] = 0;
4416
- uv[++uIndex] = uvDist;
4417
- uv[++uIndex] = 1;
4418
- uv[++uIndex] = uvDist + sharpUvOffset;
4419
- uv[++uIndex] = 0;
4420
- uv[++uIndex] = uvDist + sharpUvOffset;
4421
- uv[++uIndex] = 1; // uv.push(
4422
- // uvDist - sharpUvOffset, 0,
4423
- // uvDist - sharpUvOffset, 1,
4424
- // uvDist, 0,
4425
- // uvDist, 1,
4426
- // uvDist + sharpUvOffset, 0,
4427
- // uvDist + sharpUvOffset, 1
4428
- // );
4429
- // if (generateUv2) {
4430
- // uv2.push(
4431
- // uvDist2 - sharpUvOffset2, 0,
4432
- // uvDist2 - sharpUvOffset2, 1,
4433
- // uvDist2, 0,
4434
- // uvDist2, 1,
4435
- // uvDist2 + sharpUvOffset2, 0,
4436
- // uvDist2 + sharpUvOffset2, 1
4437
- // );
4438
- // }
4439
- } else {
4440
- position[++pIndex] = left.x;
4441
- position[++pIndex] = left.y;
4442
- position[++pIndex] = left.z;
4443
- position[++pIndex] = right.x;
4444
- position[++pIndex] = right.y;
4445
- position[++pIndex] = right.z; // position.push(
4446
- // left.x, left.y, left.z,
4447
- // right.x, right.y, right.z
4448
- // );
4449
-
4450
- normal[++nIndex] = up.x;
4451
- normal[++nIndex] = up.y;
4452
- normal[++nIndex] = up.z;
4453
- normal[++nIndex] = up.x;
4454
- normal[++nIndex] = up.y;
4455
- normal[++nIndex] = up.z; // normal.push(
4456
- // up.x, up.y, up.z,
4457
- // up.x, up.y, up.z
4458
- // );
4459
-
4460
- uv[++uIndex] = uvDist;
4461
- uv[++uIndex] = 0;
4462
- uv[++uIndex] = uvDist;
4463
- uv[++uIndex] = 1; // uv.push(
4464
- // uvDist, 0,
4465
- // uvDist, 1
4466
- // );
4467
- // if (generateUv2) {
4468
- // uv2.push(
4469
- // uvDist2, 0,
4470
- // uvDist2, 1
4471
- // );
4472
- // }
4473
-
4474
- verticesCount += 2;
4475
-
4476
- if (!first) {
4477
- indices[++iIndex] = verticesCount - 2;
4478
- indices[++iIndex] = verticesCount - 4;
4479
- indices[++iIndex] = verticesCount - 3;
4480
- indices[++iIndex] = verticesCount - 2;
4481
- indices[++iIndex] = verticesCount - 3;
4482
- indices[++iIndex] = verticesCount - 1; // indices.push(
4483
- // verticesCount - 2, verticesCount - 4, verticesCount - 3,
4484
- // verticesCount - 2, verticesCount - 3, verticesCount - 1
4485
- // );
4486
-
4487
- count += 6;
4488
- }
4226
+ let lastPoint;
4227
+ if (progressDistance > 0) {
4228
+ for (let i = 0; i < pathPointList.count; i++) {
4229
+ const pathPoint = pathPointList.array[i];
4230
+ if (pathPoint.dist > progressDistance) {
4231
+ const prevPoint = pathPointList.array[i - 1];
4232
+ lastPoint = new PathPoint();
4233
+ // linear lerp for progress
4234
+ const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
4235
+ lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
4236
+ addVertices(lastPoint);
4237
+ break;
4238
+ }
4239
+ else {
4240
+ addVertices(pathPoint);
4241
+ }
4242
+ }
4489
4243
  }
4490
- }
4491
-
4492
- var lastPoint;
4493
-
4494
- if (progressDistance > 0) {
4495
- for (var i = 0; i < pathPointList.count; i++) {
4496
- var pathPoint = pathPointList.array[i];
4497
-
4498
- if (pathPoint.dist > progressDistance) {
4499
- var prevPoint = pathPointList.array[i - 1];
4500
- lastPoint = new PathPoint(); // linear lerp for progress
4501
-
4502
- var alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
4503
- lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
4504
- addVertices(lastPoint);
4505
- break;
4506
- } else {
4507
- addVertices(pathPoint);
4508
- }
4244
+ else {
4245
+ lastPoint = pathPointList.array[0];
4509
4246
  }
4510
- } else {
4511
- lastPoint = pathPointList.array[0];
4512
- }
4513
-
4514
- return {
4515
- position: position,
4516
- normal: normal,
4517
- uv: uv,
4518
- indices: indices,
4519
- count: count
4520
- };
4247
+ return {
4248
+ position: position,
4249
+ normal,
4250
+ uv: uv,
4251
+ indices: indices,
4252
+ count
4253
+ };
4521
4254
  }
4522
4255
 
4523
- var UP = new Vector3(0, 0, 1);
4524
- var normalDir = new Vector3();
4256
+ const UP = new Vector3(0, 0, 1);
4257
+ const normalDir = new Vector3();
4525
4258
  function expandTubes(lines, options) {
4526
- options = Object.assign({}, {
4527
- radius: 1,
4528
- cornerSplit: 0,
4529
- radialSegments: 8,
4530
- startRad: -Math.PI / 4
4531
- }, options);
4532
- var results = lines.map(function (line) {
4533
- var points = line2Vectors(line);
4534
- var pathPointList = new PathPointList();
4535
- pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
4536
- var result = generateTubeVertexData(pathPointList, options);
4537
- result.line = line;
4538
- result.position = new Float32Array(result.points);
4539
- result.indices = new Uint32Array(result.indices);
4540
- result.uv = new Float32Array(result.uv);
4541
- result.normal = new Float32Array(result.normal);
4259
+ options = Object.assign({}, { radius: 1, cornerSplit: 0, radialSegments: 8, startRad: -Math.PI / 4 }, options);
4260
+ const results = lines.map(line => {
4261
+ const points = line2Vectors(line);
4262
+ const pathPointList = new PathPointList();
4263
+ //@ts-ignore
4264
+ pathPointList.set(points, 0, options.cornerSplit, UP);
4265
+ const result = generateTubeVertexData(pathPointList, options);
4266
+ result.line = line;
4267
+ result.position = new Float32Array(result.points);
4268
+ result.indices = new Uint32Array(result.indices);
4269
+ result.uv = new Float32Array(result.uv);
4270
+ result.normal = new Float32Array(result.normal);
4271
+ return result;
4272
+ });
4273
+ const result = merge(results);
4274
+ result.lines = lines;
4542
4275
  return result;
4543
- });
4544
- var result = merge(results);
4545
- result.lines = lines;
4546
- return result;
4547
- } // Vertex Data Generate Functions
4276
+ }
4277
+ // Vertex Data Generate Functions
4548
4278
  // code copy from https://github.com/shawn0326/three.path/blob/master/src/PathGeometry.js
4549
-
4550
4279
  function generateTubeVertexData(pathPointList, options) {
4551
- var radius = Math.max(options.radius || 1, 0.00000001);
4552
- var progress = options.progress !== undefined ? options.progress : 1;
4553
- var radialSegments = Math.max(3, options.radialSegments || 8);
4554
- var startRad = options.startRad || 0;
4555
- var circum = radius * 2 * Math.PI;
4556
- var totalDistance = pathPointList.distance();
4557
- var progressDistance = progress * totalDistance;
4558
-
4559
- if (progressDistance === 0) {
4560
- return null;
4561
- }
4562
-
4563
- var count = 0; // modify data
4564
-
4565
- var points = [];
4566
- var normal = [];
4567
- var uv = []; // const uv2 = [];
4568
-
4569
- var indices = [];
4570
- var verticesCount = 0;
4571
- var pIndex = -1;
4572
- var nIndex = -1;
4573
- var uIndex = -1;
4574
- var iIndex = -1;
4575
-
4576
- function addVertices(pathPoint, radius, radialSegments) {
4577
- var first = points.length === 0;
4578
- var uvDist = pathPoint.dist / circum; // const uvDist2 = pathPoint.dist / totalDistance;
4579
-
4580
- for (var i = 0; i <= radialSegments; i++) {
4581
- var r = i;
4582
-
4583
- if (r === radialSegments) {
4584
- r = 0;
4585
- }
4586
-
4587
- normalDir.copy(pathPoint.up).applyAxisAngle(pathPoint.dir, startRad + Math.PI * 2 * r / radialSegments).normalize();
4588
- var scale = radius * pathPoint.widthScale;
4589
- points[++pIndex] = pathPoint.pos.x + normalDir.x * scale;
4590
- points[++pIndex] = pathPoint.pos.y + normalDir.y * scale;
4591
- points[++pIndex] = pathPoint.pos.z + normalDir.z * scale;
4592
- normal[++nIndex] = normalDir.x;
4593
- normal[++nIndex] = normalDir.y;
4594
- normal[++nIndex] = normalDir.z;
4595
- uv[++uIndex] = uvDist;
4596
- uv[++uIndex] = i / radialSegments; // uvs.push(uvDist, r / radialSegments);
4597
- // if (generateUv2) {
4598
- // uv2.push(uvDist2, r / radialSegments);
4599
- // }
4600
-
4601
- verticesCount++;
4280
+ const radius = Math.max(options.radius || 1, 0.00000001);
4281
+ const progress = options.progress !== undefined ? options.progress : 1;
4282
+ const radialSegments = Math.max(3, options.radialSegments || 8);
4283
+ const startRad = options.startRad || 0;
4284
+ const circum = radius * 2 * Math.PI;
4285
+ const totalDistance = pathPointList.distance();
4286
+ const progressDistance = progress * totalDistance;
4287
+ if (progressDistance === 0) {
4288
+ return null;
4602
4289
  }
4603
-
4604
- if (!first) {
4605
- var begin1 = verticesCount - (radialSegments + 1) * 2;
4606
- var begin2 = verticesCount - (radialSegments + 1);
4607
-
4608
- for (var _i = 0; _i < radialSegments; _i++) {
4609
- indices[++iIndex] = begin2 + _i;
4610
- indices[++iIndex] = begin1 + _i;
4611
- indices[++iIndex] = begin1 + _i + 1;
4612
- indices[++iIndex] = begin2 + _i;
4613
- indices[++iIndex] = begin1 + _i + 1;
4614
- indices[++iIndex] = begin2 + _i + 1; // index.push(
4615
- // begin2 + i,
4616
- // begin1 + i,
4617
- // begin1 + i + 1,
4618
- // begin2 + i,
4619
- // begin1 + i + 1,
4620
- // begin2 + i + 1
4621
- // );
4622
-
4623
- count += 6;
4624
- }
4290
+ let count = 0;
4291
+ // modify data
4292
+ const points = [];
4293
+ const normal = [];
4294
+ const uv = [];
4295
+ // const uv2 = [];
4296
+ const indices = [];
4297
+ let verticesCount = 0;
4298
+ let pIndex = -1;
4299
+ let nIndex = -1;
4300
+ let uIndex = -1;
4301
+ let iIndex = -1;
4302
+ function addVertices(pathPoint, radius, radialSegments) {
4303
+ const first = points.length === 0;
4304
+ const uvDist = pathPoint.dist / circum;
4305
+ // const uvDist2 = pathPoint.dist / totalDistance;
4306
+ for (let i = 0; i <= radialSegments; i++) {
4307
+ let r = i;
4308
+ if (r === radialSegments) {
4309
+ r = 0;
4310
+ }
4311
+ normalDir.copy(pathPoint.up).applyAxisAngle(pathPoint.dir, startRad + Math.PI * 2 * r / radialSegments).normalize();
4312
+ const scale = radius * pathPoint.widthScale;
4313
+ points[++pIndex] = pathPoint.pos.x + normalDir.x * scale;
4314
+ points[++pIndex] = pathPoint.pos.y + normalDir.y * scale;
4315
+ points[++pIndex] = pathPoint.pos.z + normalDir.z * scale;
4316
+ normal[++nIndex] = normalDir.x;
4317
+ normal[++nIndex] = normalDir.y;
4318
+ normal[++nIndex] = normalDir.z;
4319
+ uv[++uIndex] = uvDist;
4320
+ uv[++uIndex] = i / radialSegments;
4321
+ // uvs.push(uvDist, r / radialSegments);
4322
+ // if (generateUv2) {
4323
+ // uv2.push(uvDist2, r / radialSegments);
4324
+ // }
4325
+ verticesCount++;
4326
+ }
4327
+ if (!first) {
4328
+ const begin1 = verticesCount - (radialSegments + 1) * 2;
4329
+ const begin2 = verticesCount - (radialSegments + 1);
4330
+ for (let i = 0; i < radialSegments; i++) {
4331
+ indices[++iIndex] = begin2 + i;
4332
+ indices[++iIndex] = begin1 + i;
4333
+ indices[++iIndex] = begin1 + i + 1;
4334
+ indices[++iIndex] = begin2 + i;
4335
+ indices[++iIndex] = begin1 + i + 1;
4336
+ indices[++iIndex] = begin2 + i + 1;
4337
+ // index.push(
4338
+ // begin2 + i,
4339
+ // begin1 + i,
4340
+ // begin1 + i + 1,
4341
+ // begin2 + i,
4342
+ // begin1 + i + 1,
4343
+ // begin2 + i + 1
4344
+ // );
4345
+ count += 6;
4346
+ }
4347
+ }
4625
4348
  }
4626
- }
4627
-
4628
- if (progressDistance > 0) {
4629
- for (var i = 0; i < pathPointList.count; i++) {
4630
- var pathPoint = pathPointList.array[i];
4631
-
4632
- if (pathPoint.dist > progressDistance) {
4633
- var prevPoint = pathPointList.array[i - 1];
4634
- var lastPoint = new PathPoint(); // linear lerp for progress
4635
-
4636
- var alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
4637
- lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
4638
- addVertices(lastPoint, radius, radialSegments);
4639
- break;
4640
- } else {
4641
- addVertices(pathPoint, radius, radialSegments);
4642
- }
4349
+ if (progressDistance > 0) {
4350
+ for (let i = 0; i < pathPointList.count; i++) {
4351
+ const pathPoint = pathPointList.array[i];
4352
+ if (pathPoint.dist > progressDistance) {
4353
+ const prevPoint = pathPointList.array[i - 1];
4354
+ const lastPoint = new PathPoint();
4355
+ // linear lerp for progress
4356
+ const alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
4357
+ lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
4358
+ addVertices(lastPoint, radius, radialSegments);
4359
+ break;
4360
+ }
4361
+ else {
4362
+ addVertices(pathPoint, radius, radialSegments);
4363
+ }
4364
+ }
4643
4365
  }
4644
- }
4645
-
4646
- return {
4647
- points: points,
4648
- normal: normal,
4649
- uv: uv,
4650
- // uv2,
4651
- indices: indices,
4652
- count: count
4653
- };
4366
+ return {
4367
+ points,
4368
+ normal,
4369
+ uv,
4370
+ // uv2,
4371
+ indices,
4372
+ count
4373
+ };
4654
4374
  }
4655
4375
 
4656
4376
  function plane(width, height, devideW, devideH) {
4657
- devideW = Math.max(1, devideW);
4658
- devideH = Math.max(1, devideH);
4659
- var dx = width / devideW,
4660
- dy = height / devideH;
4661
- var minX = -width / 2,
4662
- maxY = height / 2,
4663
- minY = -height / 2;
4664
- var len = (devideW + 1) * (devideH + 1);
4665
- var position = new Float32Array(len * 3),
4666
- uv = new Float32Array(len * 2),
4667
- normal = new Float32Array(len * 3),
4668
- indices = new Uint32Array(len * 10);
4669
- var index = 0,
4670
- uIndex = 0,
4671
- iIndex = 0;
4672
-
4673
- for (var j = 0; j <= devideH; j++) {
4674
- for (var i = 0; i <= devideW; i++) {
4675
- var x = minX + dx * i;
4676
- var y = maxY - dy * j;
4677
- position[index] = x;
4678
- position[index + 1] = y;
4679
- position[index + 2] = 0;
4680
- normal[index] = 0;
4681
- normal[index + 1] = 0;
4682
- normal[index + 2] = 1; // position.push(x, y, 0);
4683
- // normal.push(0, 0, 1);
4684
-
4685
- var uvx = (x - minX) / width,
4686
- uvy = (y - minY) / height; // uv.push(uvx, uvy);
4687
-
4688
- uv[uIndex] = uvx;
4689
- uv[uIndex + 1] = uvy;
4690
- index += 3;
4691
- uIndex += 2;
4692
-
4693
- if (i < devideW && j < devideH) {
4694
- var a = j * (devideW + 1) + i,
4695
- b = a + 1,
4696
- c = (devideW + 1) * (j + 1) + i,
4697
- d = c + 1;
4698
- indices[iIndex] = a;
4699
- indices[iIndex + 1] = c;
4700
- indices[iIndex + 2] = b;
4701
- indices[iIndex + 3] = c;
4702
- indices[iIndex + 4] = d;
4703
- indices[iIndex + 5] = b;
4704
- iIndex += 6; // indexs.push(a, c, b, c, d, b);
4705
- }
4377
+ devideW = Math.max(1, devideW);
4378
+ devideH = Math.max(1, devideH);
4379
+ const dx = width / devideW, dy = height / devideH;
4380
+ const minX = -width / 2, maxY = height / 2, minY = -height / 2;
4381
+ const len = (devideW + 1) * (devideH + 1);
4382
+ const position = new Float32Array(len * 3), uv = new Float32Array(len * 2), normal = new Float32Array(len * 3), indices = new Uint32Array(len * 10);
4383
+ let index = 0, uIndex = 0, iIndex = 0;
4384
+ for (let j = 0; j <= devideH; j++) {
4385
+ for (let i = 0; i <= devideW; i++) {
4386
+ const x = minX + dx * i;
4387
+ const y = maxY - dy * j;
4388
+ position[index] = x;
4389
+ position[index + 1] = y;
4390
+ position[index + 2] = 0;
4391
+ normal[index] = 0;
4392
+ normal[index + 1] = 0;
4393
+ normal[index + 2] = 1;
4394
+ // position.push(x, y, 0);
4395
+ // normal.push(0, 0, 1);
4396
+ const uvx = (x - minX) / width, uvy = (y - minY) / height;
4397
+ // uv.push(uvx, uvy);
4398
+ uv[uIndex] = uvx;
4399
+ uv[uIndex + 1] = uvy;
4400
+ index += 3;
4401
+ uIndex += 2;
4402
+ if (i < devideW && j < devideH) {
4403
+ const a = j * (devideW + 1) + i, b = a + 1, c = (devideW + 1) * (j + 1) + i, d = c + 1;
4404
+ indices[iIndex] = a;
4405
+ indices[iIndex + 1] = c;
4406
+ indices[iIndex + 2] = b;
4407
+ indices[iIndex + 3] = c;
4408
+ indices[iIndex + 4] = d;
4409
+ indices[iIndex + 5] = b;
4410
+ iIndex += 6;
4411
+ // indexs.push(a, c, b, c, d, b);
4412
+ }
4413
+ }
4706
4414
  }
4707
- }
4708
-
4709
- var indexArray = new Uint32Array(iIndex);
4710
-
4711
- for (var _i = 0, _len = indexArray.length; _i < _len; _i++) {
4712
- indexArray[_i] = indices[_i];
4713
- } // for (let j = 0; j < devideH; j++) {
4714
- // for (let i = 0; i < devideW; i++) {
4715
- // const a = j * (devideW + 1) + i, b = a + 1, c = (devideW + 1) * (j + 1) + i, d = c + 1;
4716
- // indexs.push(a, c, b, c, d, b);
4717
- // }
4718
- // }
4719
-
4720
-
4721
- return {
4722
- position: position,
4723
- uv: uv,
4724
- normal: normal,
4725
- indices: indexArray
4726
- };
4415
+ const indexArray = new Uint32Array(iIndex);
4416
+ for (let i = 0, len = indexArray.length; i < len; i++) {
4417
+ indexArray[i] = indices[i];
4418
+ }
4419
+ // for (let j = 0; j < devideH; j++) {
4420
+ // for (let i = 0; i < devideW; i++) {
4421
+ // const a = j * (devideW + 1) + i, b = a + 1, c = (devideW + 1) * (j + 1) + i, d = c + 1;
4422
+ // indexs.push(a, c, b, c, d, b);
4423
+ // }
4424
+ // }
4425
+ return {
4426
+ position,
4427
+ uv,
4428
+ normal,
4429
+ indices: indexArray
4430
+ };
4727
4431
  }
4728
4432
 
4729
4433
  export { cylinder, expandLine, expandPaths, expandTubes, extrudePolygons, extrudePolylines, extrudeSlopes, leftOnLine, plane };
4434
+ //# sourceMappingURL=poly-extrude.mjs.map