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