poly-extrude 0.1.0 → 0.3.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * poly-extrude v0.1.0
2
+ * poly-extrude v0.3.0
3
3
  */
4
4
  var earcut$2 = {exports: {}};
5
5
 
@@ -1101,28 +1101,30 @@ function generateTopAndBottom(result, options) {
1101
1101
  var idx0 = i * 3;
1102
1102
  var _leftPoints$i = leftPoints[i],
1103
1103
  x1 = _leftPoints$i[0],
1104
- y1 = _leftPoints$i[1];
1104
+ y1 = _leftPoints$i[1],
1105
+ z1 = _leftPoints$i[2];
1105
1106
  points[idx0] = x1;
1106
1107
  points[idx0 + 1] = y1;
1107
- points[idx0 + 2] = z; // top right
1108
+ points[idx0 + 2] = z + z1; // top right
1108
1109
 
1109
1110
  var _rightPoints$i = rightPoints[i],
1110
1111
  x2 = _rightPoints$i[0],
1111
- y2 = _rightPoints$i[1];
1112
+ y2 = _rightPoints$i[1],
1113
+ z2 = _rightPoints$i[2];
1112
1114
  var idx1 = len * 3 + idx0;
1113
1115
  points[idx1] = x2;
1114
1116
  points[idx1 + 1] = y2;
1115
- points[idx1 + 2] = z; // bottom left
1117
+ points[idx1 + 2] = z + z2; // bottom left
1116
1118
 
1117
1119
  var idx2 = len * 2 * 3 + idx0;
1118
1120
  points[idx2] = x1;
1119
1121
  points[idx2 + 1] = y1;
1120
- points[idx2 + 2] = 0; // bottom right
1122
+ points[idx2 + 2] = z1; // bottom right
1121
1123
 
1122
1124
  var idx3 = len * 2 * 3 + len * 3 + idx0;
1123
1125
  points[idx3] = x2;
1124
1126
  points[idx3 + 1] = y2;
1125
- points[idx3 + 2] = 0;
1127
+ points[idx3 + 2] = z2;
1126
1128
  i++;
1127
1129
  }
1128
1130
 
@@ -1176,7 +1178,7 @@ function generateSides(result, options) {
1176
1178
 
1177
1179
  function addOneSideIndex(v1, v2) {
1178
1180
  var idx = points.length / 3;
1179
- points.push(v1[0], v1[1], z, v2[0], v2[1], z, v1[0], v1[1], 0, v2[0], v2[1], 0);
1181
+ points.push(v1[0], v1[1], z + v1[2], v2[0], v2[1], z + v2[2], v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
1180
1182
  var a = idx + 2,
1181
1183
  b = idx + 3,
1182
1184
  c = idx,
@@ -1305,13 +1307,14 @@ function expandLine(line, options) {
1305
1307
  function calOffsetPoint(rad, radius, p) {
1306
1308
  var x = p[0],
1307
1309
  y = p[1];
1310
+ var z = p[2] || 0;
1308
1311
  var x1 = Math.cos(rad) * radius,
1309
1312
  y1 = Math.sin(rad) * radius;
1310
- var p1 = [x + x1, y + y1];
1313
+ var p1 = [x + x1, y + y1, z];
1311
1314
  var rad1 = rad += Math.PI;
1312
1315
  var x2 = Math.cos(rad1) * radius,
1313
1316
  y2 = Math.sin(rad1) * radius;
1314
- var p2 = [x + x2, y + y2];
1317
+ var p2 = [x + x2, y + y2, z];
1315
1318
  return [p1, p2];
1316
1319
  }
1317
1320
 
@@ -1454,4 +1457,1973 @@ function cylinder(point, options) {
1454
1457
  };
1455
1458
  }
1456
1459
 
1457
- export { cylinder, expandLine, extrudePolygons, extrudePolylines };
1460
+ // import * as MathUtils from './MathUtils.js';
1461
+ // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js
1462
+ var Vector3 = /*#__PURE__*/function () {
1463
+ function Vector3(x, y, z) {
1464
+ if (x === void 0) {
1465
+ x = 0;
1466
+ }
1467
+
1468
+ if (y === void 0) {
1469
+ y = 0;
1470
+ }
1471
+
1472
+ if (z === void 0) {
1473
+ z = 0;
1474
+ }
1475
+
1476
+ this.x = x;
1477
+ this.y = y;
1478
+ this.z = z;
1479
+ }
1480
+
1481
+ var _proto = Vector3.prototype;
1482
+
1483
+ _proto.set = function set(x, y, z) {
1484
+ if (z === undefined) z = this.z; // sprite.scale.set(x,y)
1485
+
1486
+ this.x = x;
1487
+ this.y = y;
1488
+ this.z = z;
1489
+ return this;
1490
+ } // setScalar(scalar) {
1491
+ // this.x = scalar;
1492
+ // this.y = scalar;
1493
+ // this.z = scalar;
1494
+ // return this;
1495
+ // }
1496
+ // setX(x) {
1497
+ // this.x = x;
1498
+ // return this;
1499
+ // }
1500
+ // setY(y) {
1501
+ // this.y = y;
1502
+ // return this;
1503
+ // }
1504
+ // setZ(z) {
1505
+ // this.z = z;
1506
+ // return this;
1507
+ // }
1508
+ // setComponent(index, value) {
1509
+ // switch (index) {
1510
+ // case 0: this.x = value; break;
1511
+ // case 1: this.y = value; break;
1512
+ // case 2: this.z = value; break;
1513
+ // default: throw new Error('index is out of range: ' + index);
1514
+ // }
1515
+ // return this;
1516
+ // }
1517
+ // getComponent(index) {
1518
+ // switch (index) {
1519
+ // case 0: return this.x;
1520
+ // case 1: return this.y;
1521
+ // case 2: return this.z;
1522
+ // default: throw new Error('index is out of range: ' + index);
1523
+ // }
1524
+ // }
1525
+ ;
1526
+
1527
+ _proto.clone = function clone() {
1528
+ return new this.constructor(this.x, this.y, this.z);
1529
+ };
1530
+
1531
+ _proto.copy = function copy(v) {
1532
+ this.x = v.x;
1533
+ this.y = v.y;
1534
+ this.z = v.z;
1535
+ return this;
1536
+ };
1537
+
1538
+ _proto.add = function add(v) {
1539
+ this.x += v.x;
1540
+ this.y += v.y;
1541
+ this.z += v.z;
1542
+ return this;
1543
+ };
1544
+
1545
+ _proto.addScalar = function addScalar(s) {
1546
+ this.x += s;
1547
+ this.y += s;
1548
+ this.z += s;
1549
+ return this;
1550
+ };
1551
+
1552
+ _proto.addVectors = function addVectors(a, b) {
1553
+ this.x = a.x + b.x;
1554
+ this.y = a.y + b.y;
1555
+ this.z = a.z + b.z;
1556
+ return this;
1557
+ };
1558
+
1559
+ _proto.addScaledVector = function addScaledVector(v, s) {
1560
+ this.x += v.x * s;
1561
+ this.y += v.y * s;
1562
+ this.z += v.z * s;
1563
+ return this;
1564
+ };
1565
+
1566
+ _proto.sub = function sub(v) {
1567
+ this.x -= v.x;
1568
+ this.y -= v.y;
1569
+ this.z -= v.z;
1570
+ return this;
1571
+ };
1572
+
1573
+ _proto.subScalar = function subScalar(s) {
1574
+ this.x -= s;
1575
+ this.y -= s;
1576
+ this.z -= s;
1577
+ return this;
1578
+ };
1579
+
1580
+ _proto.subVectors = function subVectors(a, b) {
1581
+ this.x = a.x - b.x;
1582
+ this.y = a.y - b.y;
1583
+ this.z = a.z - b.z;
1584
+ return this;
1585
+ };
1586
+
1587
+ _proto.multiply = function multiply(v) {
1588
+ this.x *= v.x;
1589
+ this.y *= v.y;
1590
+ this.z *= v.z;
1591
+ return this;
1592
+ };
1593
+
1594
+ _proto.multiplyScalar = function multiplyScalar(scalar) {
1595
+ this.x *= scalar;
1596
+ this.y *= scalar;
1597
+ this.z *= scalar;
1598
+ return this;
1599
+ };
1600
+
1601
+ _proto.multiplyVectors = function multiplyVectors(a, b) {
1602
+ this.x = a.x * b.x;
1603
+ this.y = a.y * b.y;
1604
+ this.z = a.z * b.z;
1605
+ return this;
1606
+ } // applyEuler(euler) {
1607
+ // return this.applyQuaternion(_quaternion.setFromEuler(euler));
1608
+ // }
1609
+ // applyAxisAngle(axis, angle) {
1610
+ // return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
1611
+ // }
1612
+ // applyMatrix3(m) {
1613
+ // const x = this.x, y = this.y, z = this.z;
1614
+ // const e = m.elements;
1615
+ // this.x = e[0] * x + e[3] * y + e[6] * z;
1616
+ // this.y = e[1] * x + e[4] * y + e[7] * z;
1617
+ // this.z = e[2] * x + e[5] * y + e[8] * z;
1618
+ // return this;
1619
+ // }
1620
+ // applyNormalMatrix(m) {
1621
+ // return this.applyMatrix3(m).normalize();
1622
+ // }
1623
+ ;
1624
+
1625
+ _proto.applyMatrix4 = function applyMatrix4(m) {
1626
+ var x = this.x,
1627
+ y = this.y,
1628
+ z = this.z;
1629
+ var e = m.elements;
1630
+ var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
1631
+ this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
1632
+ this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
1633
+ this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
1634
+ return this;
1635
+ } // applyQuaternion(q) {
1636
+ // const x = this.x, y = this.y, z = this.z;
1637
+ // const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
1638
+ // // calculate quat * vector
1639
+ // const ix = qw * x + qy * z - qz * y;
1640
+ // const iy = qw * y + qz * x - qx * z;
1641
+ // const iz = qw * z + qx * y - qy * x;
1642
+ // const iw = - qx * x - qy * y - qz * z;
1643
+ // // calculate result * inverse quat
1644
+ // this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
1645
+ // this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
1646
+ // this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
1647
+ // return this;
1648
+ // }
1649
+ // project(camera) {
1650
+ // return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
1651
+ // }
1652
+ // unproject(camera) {
1653
+ // return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);
1654
+ // }
1655
+ // transformDirection(m) {
1656
+ // // input: THREE.Matrix4 affine matrix
1657
+ // // vector interpreted as a direction
1658
+ // const x = this.x, y = this.y, z = this.z;
1659
+ // const e = m.elements;
1660
+ // this.x = e[0] * x + e[4] * y + e[8] * z;
1661
+ // this.y = e[1] * x + e[5] * y + e[9] * z;
1662
+ // this.z = e[2] * x + e[6] * y + e[10] * z;
1663
+ // return this.normalize();
1664
+ // }
1665
+ ;
1666
+
1667
+ _proto.divide = function divide(v) {
1668
+ this.x /= v.x;
1669
+ this.y /= v.y;
1670
+ this.z /= v.z;
1671
+ return this;
1672
+ };
1673
+
1674
+ _proto.divideScalar = function divideScalar(scalar) {
1675
+ return this.multiplyScalar(1 / scalar);
1676
+ };
1677
+
1678
+ _proto.min = function min(v) {
1679
+ this.x = Math.min(this.x, v.x);
1680
+ this.y = Math.min(this.y, v.y);
1681
+ this.z = Math.min(this.z, v.z);
1682
+ return this;
1683
+ };
1684
+
1685
+ _proto.max = function max(v) {
1686
+ this.x = Math.max(this.x, v.x);
1687
+ this.y = Math.max(this.y, v.y);
1688
+ this.z = Math.max(this.z, v.z);
1689
+ return this;
1690
+ };
1691
+
1692
+ _proto.clamp = function clamp(min, max) {
1693
+ // assumes min < max, componentwise
1694
+ this.x = Math.max(min.x, Math.min(max.x, this.x));
1695
+ this.y = Math.max(min.y, Math.min(max.y, this.y));
1696
+ this.z = Math.max(min.z, Math.min(max.z, this.z));
1697
+ return this;
1698
+ };
1699
+
1700
+ _proto.clampScalar = function clampScalar(minVal, maxVal) {
1701
+ this.x = Math.max(minVal, Math.min(maxVal, this.x));
1702
+ this.y = Math.max(minVal, Math.min(maxVal, this.y));
1703
+ this.z = Math.max(minVal, Math.min(maxVal, this.z));
1704
+ return this;
1705
+ };
1706
+
1707
+ _proto.clampLength = function clampLength(min, max) {
1708
+ var length = this.length();
1709
+ return this.divideScalar(length || 1).multiplyScalar(Math.max(min, Math.min(max, length)));
1710
+ } // floor() {
1711
+ // this.x = Math.floor(this.x);
1712
+ // this.y = Math.floor(this.y);
1713
+ // this.z = Math.floor(this.z);
1714
+ // return this;
1715
+ // }
1716
+ // ceil() {
1717
+ // this.x = Math.ceil(this.x);
1718
+ // this.y = Math.ceil(this.y);
1719
+ // this.z = Math.ceil(this.z);
1720
+ // return this;
1721
+ // }
1722
+ // round() {
1723
+ // this.x = Math.round(this.x);
1724
+ // this.y = Math.round(this.y);
1725
+ // this.z = Math.round(this.z);
1726
+ // return this;
1727
+ // }
1728
+ // roundToZero() {
1729
+ // this.x = (this.x < 0) ? Math.ceil(this.x) : Math.floor(this.x);
1730
+ // this.y = (this.y < 0) ? Math.ceil(this.y) : Math.floor(this.y);
1731
+ // this.z = (this.z < 0) ? Math.ceil(this.z) : Math.floor(this.z);
1732
+ // return this;
1733
+ // }
1734
+ // negate() {
1735
+ // this.x = -this.x;
1736
+ // this.y = -this.y;
1737
+ // this.z = -this.z;
1738
+ // return this;
1739
+ // }
1740
+ ;
1741
+
1742
+ _proto.dot = function dot(v) {
1743
+ return this.x * v.x + this.y * v.y + this.z * v.z;
1744
+ } // TODO lengthSquared?
1745
+ ;
1746
+
1747
+ _proto.lengthSq = function lengthSq() {
1748
+ return this.x * this.x + this.y * this.y + this.z * this.z;
1749
+ };
1750
+
1751
+ _proto.length = function length() {
1752
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
1753
+ } // manhattanLength() {
1754
+ // return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z);
1755
+ // }
1756
+ ;
1757
+
1758
+ _proto.normalize = function normalize() {
1759
+ return this.divideScalar(this.length() || 1);
1760
+ };
1761
+
1762
+ _proto.setLength = function setLength(length) {
1763
+ return this.normalize().multiplyScalar(length);
1764
+ };
1765
+
1766
+ _proto.lerp = function lerp(v, alpha) {
1767
+ this.x += (v.x - this.x) * alpha;
1768
+ this.y += (v.y - this.y) * alpha;
1769
+ this.z += (v.z - this.z) * alpha;
1770
+ return this;
1771
+ };
1772
+
1773
+ _proto.lerpVectors = function lerpVectors(v1, v2, alpha) {
1774
+ this.x = v1.x + (v2.x - v1.x) * alpha;
1775
+ this.y = v1.y + (v2.y - v1.y) * alpha;
1776
+ this.z = v1.z + (v2.z - v1.z) * alpha;
1777
+ return this;
1778
+ };
1779
+
1780
+ _proto.cross = function cross(v) {
1781
+ return this.crossVectors(this, v);
1782
+ };
1783
+
1784
+ _proto.crossVectors = function crossVectors(a, b) {
1785
+ var ax = a.x,
1786
+ ay = a.y,
1787
+ az = a.z;
1788
+ var bx = b.x,
1789
+ by = b.y,
1790
+ bz = b.z;
1791
+ this.x = ay * bz - az * by;
1792
+ this.y = az * bx - ax * bz;
1793
+ this.z = ax * by - ay * bx;
1794
+ return this;
1795
+ } // projectOnVector(v) {
1796
+ // const denominator = v.lengthSq();
1797
+ // if (denominator === 0) return this.set(0, 0, 0);
1798
+ // const scalar = v.dot(this) / denominator;
1799
+ // return this.copy(v).multiplyScalar(scalar);
1800
+ // }
1801
+ // projectOnPlane(planeNormal) {
1802
+ // _vector.copy(this).projectOnVector(planeNormal);
1803
+ // return this.sub(_vector);
1804
+ // }
1805
+ // reflect(normal) {
1806
+ // // reflect incident vector off plane orthogonal to normal
1807
+ // // normal is assumed to have unit length
1808
+ // return this.sub(_vector.copy(normal).multiplyScalar(2 * this.dot(normal)));
1809
+ // }
1810
+ // angleTo(v) {
1811
+ // const denominator = Math.sqrt(this.lengthSq() * v.lengthSq());
1812
+ // if (denominator === 0) return Math.PI / 2;
1813
+ // const theta = this.dot(v) / denominator;
1814
+ // // clamp, to handle numerical problems
1815
+ // return Math.acos(MathUtils.clamp(theta, -1, 1));
1816
+ // }
1817
+ ;
1818
+
1819
+ _proto.distanceTo = function distanceTo(v) {
1820
+ return Math.sqrt(this.distanceToSquared(v));
1821
+ } // distanceToSquared(v) {
1822
+ // const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
1823
+ // return dx * dx + dy * dy + dz * dz;
1824
+ // }
1825
+ // manhattanDistanceTo(v) {
1826
+ // return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z);
1827
+ // }
1828
+ // setFromSpherical(s) {
1829
+ // return this.setFromSphericalCoords(s.radius, s.phi, s.theta);
1830
+ // }
1831
+ // setFromSphericalCoords(radius, phi, theta) {
1832
+ // const sinPhiRadius = Math.sin(phi) * radius;
1833
+ // this.x = sinPhiRadius * Math.sin(theta);
1834
+ // this.y = Math.cos(phi) * radius;
1835
+ // this.z = sinPhiRadius * Math.cos(theta);
1836
+ // return this;
1837
+ // }
1838
+ // setFromCylindrical(c) {
1839
+ // return this.setFromCylindricalCoords(c.radius, c.theta, c.y);
1840
+ // }
1841
+ // setFromCylindricalCoords(radius, theta, y) {
1842
+ // this.x = radius * Math.sin(theta);
1843
+ // this.y = y;
1844
+ // this.z = radius * Math.cos(theta);
1845
+ // return this;
1846
+ // }
1847
+ // setFromMatrixPosition(m) {
1848
+ // const e = m.elements;
1849
+ // this.x = e[12];
1850
+ // this.y = e[13];
1851
+ // this.z = e[14];
1852
+ // return this;
1853
+ // }
1854
+ // setFromMatrixScale(m) {
1855
+ // const sx = this.setFromMatrixColumn(m, 0).length();
1856
+ // const sy = this.setFromMatrixColumn(m, 1).length();
1857
+ // const sz = this.setFromMatrixColumn(m, 2).length();
1858
+ // this.x = sx;
1859
+ // this.y = sy;
1860
+ // this.z = sz;
1861
+ // return this;
1862
+ // }
1863
+ // setFromMatrixColumn(m, index) {
1864
+ // return this.fromArray(m.elements, index * 4);
1865
+ // }
1866
+ // setFromMatrix3Column(m, index) {
1867
+ // return this.fromArray(m.elements, index * 3);
1868
+ // }
1869
+ // setFromEuler(e) {
1870
+ // this.x = e._x;
1871
+ // this.y = e._y;
1872
+ // this.z = e._z;
1873
+ // return this;
1874
+ // }
1875
+ // setFromColor(c) {
1876
+ // this.x = c.r;
1877
+ // this.y = c.g;
1878
+ // this.z = c.b;
1879
+ // return this;
1880
+ // }
1881
+ ;
1882
+
1883
+ _proto.equals = function equals(v) {
1884
+ return v.x === this.x && v.y === this.y && v.z === this.z;
1885
+ };
1886
+
1887
+ _proto.fromArray = function fromArray(array, offset) {
1888
+ if (offset === void 0) {
1889
+ offset = 0;
1890
+ }
1891
+
1892
+ this.x = array[offset];
1893
+ this.y = array[offset + 1];
1894
+ this.z = array[offset + 2];
1895
+ return this;
1896
+ } // toArray(array = [], offset = 0) {
1897
+ // array[offset] = this.x;
1898
+ // array[offset + 1] = this.y;
1899
+ // array[offset + 2] = this.z;
1900
+ // return array;
1901
+ // }
1902
+ // fromBufferAttribute(attribute, index) {
1903
+ // this.x = attribute.getX(index);
1904
+ // this.y = attribute.getY(index);
1905
+ // this.z = attribute.getZ(index);
1906
+ // return this;
1907
+ // }
1908
+ ;
1909
+
1910
+ _proto.random = function random() {
1911
+ this.x = Math.random();
1912
+ this.y = Math.random();
1913
+ this.z = Math.random();
1914
+ return this;
1915
+ } // randomDirection() {
1916
+ // // Derived from https://mathworld.wolfram.com/SpherePointPicking.html
1917
+ // const u = (Math.random() - 0.5) * 2;
1918
+ // const t = Math.random() * Math.PI * 2;
1919
+ // const f = Math.sqrt(1 - u ** 2);
1920
+ // this.x = f * Math.cos(t);
1921
+ // this.y = f * Math.sin(t);
1922
+ // this.z = u;
1923
+ // return this;
1924
+ // }
1925
+ ;
1926
+
1927
+ return Vector3;
1928
+ }();
1929
+
1930
+ /* eslint-disable no-tabs */
1931
+ /**
1932
+ * PathPoint
1933
+ */
1934
+
1935
+ var PathPoint = /*#__PURE__*/function () {
1936
+ function PathPoint() {
1937
+ this.pos = new Vector3();
1938
+ this.dir = new Vector3();
1939
+ this.right = new Vector3();
1940
+ this.up = new Vector3(); // normal
1941
+
1942
+ this.dist = 0; // distance from start
1943
+
1944
+ this.widthScale = 1; // for corner
1945
+
1946
+ this.sharp = false; // marks as sharp corner
1947
+ }
1948
+
1949
+ var _proto = PathPoint.prototype;
1950
+
1951
+ _proto.lerpPathPoints = function lerpPathPoints(p1, p2, alpha) {
1952
+ this.pos.lerpVectors(p1.pos, p2.pos, alpha);
1953
+ this.dir.lerpVectors(p1.dir, p2.dir, alpha);
1954
+ this.up.lerpVectors(p1.up, p2.up, alpha);
1955
+ this.right.lerpVectors(p1.right, p2.right, alpha);
1956
+ this.dist = (p2.dist - p1.dist) * alpha + p1.dist;
1957
+ this.widthScale = (p2.widthScale - p1.widthScale) * alpha + p1.widthScale;
1958
+ };
1959
+
1960
+ _proto.copy = function copy(source) {
1961
+ this.pos.copy(source.pos);
1962
+ this.dir.copy(source.dir);
1963
+ this.up.copy(source.up);
1964
+ this.right.copy(source.right);
1965
+ this.dist = source.dist;
1966
+ this.widthScale = source.widthScale;
1967
+ };
1968
+
1969
+ return PathPoint;
1970
+ }();
1971
+
1972
+ // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Matrix4.js
1973
+ // import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../constants.js';
1974
+ // import { Vector3 } from './Vector3.js';
1975
+ var Matrix4 = /*#__PURE__*/function () {
1976
+ function Matrix4(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
1977
+ this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
1978
+
1979
+ if (n11 !== undefined) {
1980
+ this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44);
1981
+ }
1982
+ }
1983
+
1984
+ var _proto = Matrix4.prototype;
1985
+
1986
+ _proto.set = function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
1987
+ var te = this.elements;
1988
+ te[0] = n11;
1989
+ te[4] = n12;
1990
+ te[8] = n13;
1991
+ te[12] = n14;
1992
+ te[1] = n21;
1993
+ te[5] = n22;
1994
+ te[9] = n23;
1995
+ te[13] = n24;
1996
+ te[2] = n31;
1997
+ te[6] = n32;
1998
+ te[10] = n33;
1999
+ te[14] = n34;
2000
+ te[3] = n41;
2001
+ te[7] = n42;
2002
+ te[11] = n43;
2003
+ te[15] = n44;
2004
+ return this;
2005
+ } // identity() {
2006
+ // this.set(
2007
+ // 1, 0, 0, 0,
2008
+ // 0, 1, 0, 0,
2009
+ // 0, 0, 1, 0,
2010
+ // 0, 0, 0, 1
2011
+ // );
2012
+ // return this;
2013
+ // }
2014
+ // clone() {
2015
+ // return new Matrix4().fromArray(this.elements);
2016
+ // }
2017
+ // copy(m) {
2018
+ // const te = this.elements;
2019
+ // const me = m.elements;
2020
+ // te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3];
2021
+ // te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7];
2022
+ // te[8] = me[8]; te[9] = me[9]; te[10] = me[10]; te[11] = me[11];
2023
+ // te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; te[15] = me[15];
2024
+ // return this;
2025
+ // }
2026
+ // copyPosition(m) {
2027
+ // const te = this.elements, me = m.elements;
2028
+ // te[12] = me[12];
2029
+ // te[13] = me[13];
2030
+ // te[14] = me[14];
2031
+ // return this;
2032
+ // }
2033
+ // setFromMatrix3(m) {
2034
+ // const me = m.elements;
2035
+ // this.set(
2036
+ // me[0], me[3], me[6], 0,
2037
+ // me[1], me[4], me[7], 0,
2038
+ // me[2], me[5], me[8], 0,
2039
+ // 0, 0, 0, 1
2040
+ // );
2041
+ // return this;
2042
+ // }
2043
+ // extractBasis(xAxis, yAxis, zAxis) {
2044
+ // xAxis.setFromMatrixColumn(this, 0);
2045
+ // yAxis.setFromMatrixColumn(this, 1);
2046
+ // zAxis.setFromMatrixColumn(this, 2);
2047
+ // return this;
2048
+ // }
2049
+ // makeBasis(xAxis, yAxis, zAxis) {
2050
+ // this.set(
2051
+ // xAxis.x, yAxis.x, zAxis.x, 0,
2052
+ // xAxis.y, yAxis.y, zAxis.y, 0,
2053
+ // xAxis.z, yAxis.z, zAxis.z, 0,
2054
+ // 0, 0, 0, 1
2055
+ // );
2056
+ // return this;
2057
+ // }
2058
+ // extractRotation(m) {
2059
+ // // this method does not support reflection matrices
2060
+ // const te = this.elements;
2061
+ // const me = m.elements;
2062
+ // const scaleX = 1 / _v1.setFromMatrixColumn(m, 0).length();
2063
+ // const scaleY = 1 / _v1.setFromMatrixColumn(m, 1).length();
2064
+ // const scaleZ = 1 / _v1.setFromMatrixColumn(m, 2).length();
2065
+ // te[0] = me[0] * scaleX;
2066
+ // te[1] = me[1] * scaleX;
2067
+ // te[2] = me[2] * scaleX;
2068
+ // te[3] = 0;
2069
+ // te[4] = me[4] * scaleY;
2070
+ // te[5] = me[5] * scaleY;
2071
+ // te[6] = me[6] * scaleY;
2072
+ // te[7] = 0;
2073
+ // te[8] = me[8] * scaleZ;
2074
+ // te[9] = me[9] * scaleZ;
2075
+ // te[10] = me[10] * scaleZ;
2076
+ // te[11] = 0;
2077
+ // te[12] = 0;
2078
+ // te[13] = 0;
2079
+ // te[14] = 0;
2080
+ // te[15] = 1;
2081
+ // return this;
2082
+ // }
2083
+ // makeRotationFromEuler(euler) {
2084
+ // const te = this.elements;
2085
+ // const x = euler.x, y = euler.y, z = euler.z;
2086
+ // const a = Math.cos(x), b = Math.sin(x);
2087
+ // const c = Math.cos(y), d = Math.sin(y);
2088
+ // const e = Math.cos(z), f = Math.sin(z);
2089
+ // if (euler.order === 'XYZ') {
2090
+ // const ae = a * e, af = a * f, be = b * e, bf = b * f;
2091
+ // te[0] = c * e;
2092
+ // te[4] = -c * f;
2093
+ // te[8] = d;
2094
+ // te[1] = af + be * d;
2095
+ // te[5] = ae - bf * d;
2096
+ // te[9] = -b * c;
2097
+ // te[2] = bf - ae * d;
2098
+ // te[6] = be + af * d;
2099
+ // te[10] = a * c;
2100
+ // } else if (euler.order === 'YXZ') {
2101
+ // const ce = c * e, cf = c * f, de = d * e, df = d * f;
2102
+ // te[0] = ce + df * b;
2103
+ // te[4] = de * b - cf;
2104
+ // te[8] = a * d;
2105
+ // te[1] = a * f;
2106
+ // te[5] = a * e;
2107
+ // te[9] = -b;
2108
+ // te[2] = cf * b - de;
2109
+ // te[6] = df + ce * b;
2110
+ // te[10] = a * c;
2111
+ // } else if (euler.order === 'ZXY') {
2112
+ // const ce = c * e, cf = c * f, de = d * e, df = d * f;
2113
+ // te[0] = ce - df * b;
2114
+ // te[4] = -a * f;
2115
+ // te[8] = de + cf * b;
2116
+ // te[1] = cf + de * b;
2117
+ // te[5] = a * e;
2118
+ // te[9] = df - ce * b;
2119
+ // te[2] = -a * d;
2120
+ // te[6] = b;
2121
+ // te[10] = a * c;
2122
+ // } else if (euler.order === 'ZYX') {
2123
+ // const ae = a * e, af = a * f, be = b * e, bf = b * f;
2124
+ // te[0] = c * e;
2125
+ // te[4] = be * d - af;
2126
+ // te[8] = ae * d + bf;
2127
+ // te[1] = c * f;
2128
+ // te[5] = bf * d + ae;
2129
+ // te[9] = af * d - be;
2130
+ // te[2] = -d;
2131
+ // te[6] = b * c;
2132
+ // te[10] = a * c;
2133
+ // } else if (euler.order === 'YZX') {
2134
+ // const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
2135
+ // te[0] = c * e;
2136
+ // te[4] = bd - ac * f;
2137
+ // te[8] = bc * f + ad;
2138
+ // te[1] = f;
2139
+ // te[5] = a * e;
2140
+ // te[9] = -b * e;
2141
+ // te[2] = -d * e;
2142
+ // te[6] = ad * f + bc;
2143
+ // te[10] = ac - bd * f;
2144
+ // } else if (euler.order === 'XZY') {
2145
+ // const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
2146
+ // te[0] = c * e;
2147
+ // te[4] = -f;
2148
+ // te[8] = d * e;
2149
+ // te[1] = ac * f + bd;
2150
+ // te[5] = a * e;
2151
+ // te[9] = ad * f - bc;
2152
+ // te[2] = bc * f - ad;
2153
+ // te[6] = b * e;
2154
+ // te[10] = bd * f + ac;
2155
+ // }
2156
+ // // bottom row
2157
+ // te[3] = 0;
2158
+ // te[7] = 0;
2159
+ // te[11] = 0;
2160
+ // // last column
2161
+ // te[12] = 0;
2162
+ // te[13] = 0;
2163
+ // te[14] = 0;
2164
+ // te[15] = 1;
2165
+ // return this;
2166
+ // }
2167
+ // makeRotationFromQuaternion(q) {
2168
+ // return this.compose(_zero, q, _one);
2169
+ // }
2170
+ // lookAt(eye, target, up) {
2171
+ // const te = this.elements;
2172
+ // _z.subVectors(eye, target);
2173
+ // if (_z.lengthSq() === 0) {
2174
+ // // eye and target are in the same position
2175
+ // _z.z = 1;
2176
+ // }
2177
+ // _z.normalize();
2178
+ // _x.crossVectors(up, _z);
2179
+ // if (_x.lengthSq() === 0) {
2180
+ // // up and z are parallel
2181
+ // if (Math.abs(up.z) === 1) {
2182
+ // _z.x += 0.0001;
2183
+ // } else {
2184
+ // _z.z += 0.0001;
2185
+ // }
2186
+ // _z.normalize();
2187
+ // _x.crossVectors(up, _z);
2188
+ // }
2189
+ // _x.normalize();
2190
+ // _y.crossVectors(_z, _x);
2191
+ // te[0] = _x.x; te[4] = _y.x; te[8] = _z.x;
2192
+ // te[1] = _x.y; te[5] = _y.y; te[9] = _z.y;
2193
+ // te[2] = _x.z; te[6] = _y.z; te[10] = _z.z;
2194
+ // return this;
2195
+ // }
2196
+ ;
2197
+
2198
+ _proto.multiply = function multiply(m) {
2199
+ return this.multiplyMatrices(this, m);
2200
+ } // premultiply(m) {
2201
+ // return this.multiplyMatrices(m, this);
2202
+ // }
2203
+ // multiplyMatrices(a, b) {
2204
+ // const ae = a.elements;
2205
+ // const be = b.elements;
2206
+ // const te = this.elements;
2207
+ // const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
2208
+ // const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
2209
+ // const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
2210
+ // const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];
2211
+ // const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
2212
+ // const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
2213
+ // const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
2214
+ // const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];
2215
+ // te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
2216
+ // te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
2217
+ // te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
2218
+ // te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
2219
+ // te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
2220
+ // te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
2221
+ // te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
2222
+ // te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
2223
+ // te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
2224
+ // te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
2225
+ // te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
2226
+ // te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
2227
+ // te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
2228
+ // te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
2229
+ // te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
2230
+ // te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
2231
+ // return this;
2232
+ // }
2233
+ // multiplyScalar(s) {
2234
+ // const te = this.elements;
2235
+ // te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s;
2236
+ // te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s;
2237
+ // te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s;
2238
+ // te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s;
2239
+ // return this;
2240
+ // }
2241
+ // determinant() {
2242
+ // const te = this.elements;
2243
+ // const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12];
2244
+ // const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13];
2245
+ // const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14];
2246
+ // const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
2247
+ // //TODO: make this more efficient
2248
+ // //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
2249
+ // return (
2250
+ // n41 * (
2251
+ // + n14 * n23 * n32
2252
+ // - n13 * n24 * n32
2253
+ // - n14 * n22 * n33
2254
+ // + n12 * n24 * n33
2255
+ // + n13 * n22 * n34
2256
+ // - n12 * n23 * n34
2257
+ // ) +
2258
+ // n42 * (
2259
+ // + n11 * n23 * n34
2260
+ // - n11 * n24 * n33
2261
+ // + n14 * n21 * n33
2262
+ // - n13 * n21 * n34
2263
+ // + n13 * n24 * n31
2264
+ // - n14 * n23 * n31
2265
+ // ) +
2266
+ // n43 * (
2267
+ // + n11 * n24 * n32
2268
+ // - n11 * n22 * n34
2269
+ // - n14 * n21 * n32
2270
+ // + n12 * n21 * n34
2271
+ // + n14 * n22 * n31
2272
+ // - n12 * n24 * n31
2273
+ // ) +
2274
+ // n44 * (
2275
+ // - n13 * n22 * n31
2276
+ // - n11 * n23 * n32
2277
+ // + n11 * n22 * n33
2278
+ // + n13 * n21 * n32
2279
+ // - n12 * n21 * n33
2280
+ // + n12 * n23 * n31
2281
+ // )
2282
+ // );
2283
+ // }
2284
+ // transpose() {
2285
+ // const te = this.elements;
2286
+ // let tmp;
2287
+ // tmp = te[1]; te[1] = te[4]; te[4] = tmp;
2288
+ // tmp = te[2]; te[2] = te[8]; te[8] = tmp;
2289
+ // tmp = te[6]; te[6] = te[9]; te[9] = tmp;
2290
+ // tmp = te[3]; te[3] = te[12]; te[12] = tmp;
2291
+ // tmp = te[7]; te[7] = te[13]; te[13] = tmp;
2292
+ // tmp = te[11]; te[11] = te[14]; te[14] = tmp;
2293
+ // return this;
2294
+ // }
2295
+ // setPosition(x, y, z) {
2296
+ // const te = this.elements;
2297
+ // if (x.isVector3) {
2298
+ // te[12] = x.x;
2299
+ // te[13] = x.y;
2300
+ // te[14] = x.z;
2301
+ // } else {
2302
+ // te[12] = x;
2303
+ // te[13] = y;
2304
+ // te[14] = z;
2305
+ // }
2306
+ // return this;
2307
+ // }
2308
+ // invert() {
2309
+ // // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
2310
+ // const te = this.elements,
2311
+ // n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3],
2312
+ // n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7],
2313
+ // n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11],
2314
+ // n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15],
2315
+ // t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
2316
+ // t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
2317
+ // t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
2318
+ // t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
2319
+ // const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
2320
+ // if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
2321
+ // const detInv = 1 / det;
2322
+ // te[0] = t11 * detInv;
2323
+ // te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
2324
+ // te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
2325
+ // te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
2326
+ // te[4] = t12 * detInv;
2327
+ // te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
2328
+ // te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
2329
+ // te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
2330
+ // te[8] = t13 * detInv;
2331
+ // te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
2332
+ // te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
2333
+ // te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
2334
+ // te[12] = t14 * detInv;
2335
+ // te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
2336
+ // te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
2337
+ // te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
2338
+ // return this;
2339
+ // }
2340
+ // scale(v) {
2341
+ // const te = this.elements;
2342
+ // const x = v.x, y = v.y, z = v.z;
2343
+ // te[0] *= x; te[4] *= y; te[8] *= z;
2344
+ // te[1] *= x; te[5] *= y; te[9] *= z;
2345
+ // te[2] *= x; te[6] *= y; te[10] *= z;
2346
+ // te[3] *= x; te[7] *= y; te[11] *= z;
2347
+ // return this;
2348
+ // }
2349
+ // getMaxScaleOnAxis() {
2350
+ // const te = this.elements;
2351
+ // const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
2352
+ // const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
2353
+ // const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
2354
+ // return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
2355
+ // }
2356
+ // makeTranslation(x, y, z) {
2357
+ // if (x.isVector3) {
2358
+ // this.set(
2359
+ // 1, 0, 0, x.x,
2360
+ // 0, 1, 0, x.y,
2361
+ // 0, 0, 1, x.z,
2362
+ // 0, 0, 0, 1
2363
+ // );
2364
+ // } else {
2365
+ // this.set(
2366
+ // 1, 0, 0, x,
2367
+ // 0, 1, 0, y,
2368
+ // 0, 0, 1, z,
2369
+ // 0, 0, 0, 1
2370
+ // );
2371
+ // }
2372
+ // return this;
2373
+ // }
2374
+ // makeRotationX(theta) {
2375
+ // const c = Math.cos(theta), s = Math.sin(theta);
2376
+ // this.set(
2377
+ // 1, 0, 0, 0,
2378
+ // 0, c, -s, 0,
2379
+ // 0, s, c, 0,
2380
+ // 0, 0, 0, 1
2381
+ // );
2382
+ // return this;
2383
+ // }
2384
+ // makeRotationY(theta) {
2385
+ // const c = Math.cos(theta), s = Math.sin(theta);
2386
+ // this.set(
2387
+ // c, 0, s, 0,
2388
+ // 0, 1, 0, 0,
2389
+ // -s, 0, c, 0,
2390
+ // 0, 0, 0, 1
2391
+ // );
2392
+ // return this;
2393
+ // }
2394
+ // makeRotationZ(theta) {
2395
+ // const c = Math.cos(theta), s = Math.sin(theta);
2396
+ // this.set(
2397
+ // c, -s, 0, 0,
2398
+ // s, c, 0, 0,
2399
+ // 0, 0, 1, 0,
2400
+ // 0, 0, 0, 1
2401
+ // );
2402
+ // return this;
2403
+ // }
2404
+ ;
2405
+
2406
+ _proto.makeRotationAxis = function makeRotationAxis(axis, angle) {
2407
+ // Based on http://www.gamedev.net/reference/articles/article1199.asp
2408
+ var c = Math.cos(angle);
2409
+ var s = Math.sin(angle);
2410
+ var t = 1 - c;
2411
+ var x = axis.x,
2412
+ y = axis.y,
2413
+ z = axis.z;
2414
+ var tx = t * x,
2415
+ ty = t * y;
2416
+ this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1);
2417
+ return this;
2418
+ } // makeScale(x, y, z) {
2419
+ // this.set(
2420
+ // x, 0, 0, 0,
2421
+ // 0, y, 0, 0,
2422
+ // 0, 0, z, 0,
2423
+ // 0, 0, 0, 1
2424
+ // );
2425
+ // return this;
2426
+ // }
2427
+ // makeShear(xy, xz, yx, yz, zx, zy) {
2428
+ // this.set(
2429
+ // 1, yx, zx, 0,
2430
+ // xy, 1, zy, 0,
2431
+ // xz, yz, 1, 0,
2432
+ // 0, 0, 0, 1
2433
+ // );
2434
+ // return this;
2435
+ // }
2436
+ // compose(position, quaternion, scale) {
2437
+ // const te = this.elements;
2438
+ // const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
2439
+ // const x2 = x + x, y2 = y + y, z2 = z + z;
2440
+ // const xx = x * x2, xy = x * y2, xz = x * z2;
2441
+ // const yy = y * y2, yz = y * z2, zz = z * z2;
2442
+ // const wx = w * x2, wy = w * y2, wz = w * z2;
2443
+ // const sx = scale.x, sy = scale.y, sz = scale.z;
2444
+ // te[0] = (1 - (yy + zz)) * sx;
2445
+ // te[1] = (xy + wz) * sx;
2446
+ // te[2] = (xz - wy) * sx;
2447
+ // te[3] = 0;
2448
+ // te[4] = (xy - wz) * sy;
2449
+ // te[5] = (1 - (xx + zz)) * sy;
2450
+ // te[6] = (yz + wx) * sy;
2451
+ // te[7] = 0;
2452
+ // te[8] = (xz + wy) * sz;
2453
+ // te[9] = (yz - wx) * sz;
2454
+ // te[10] = (1 - (xx + yy)) * sz;
2455
+ // te[11] = 0;
2456
+ // te[12] = position.x;
2457
+ // te[13] = position.y;
2458
+ // te[14] = position.z;
2459
+ // te[15] = 1;
2460
+ // return this;
2461
+ // }
2462
+ // decompose(position, quaternion, scale) {
2463
+ // const te = this.elements;
2464
+ // let sx = _v1.set(te[0], te[1], te[2]).length();
2465
+ // const sy = _v1.set(te[4], te[5], te[6]).length();
2466
+ // const sz = _v1.set(te[8], te[9], te[10]).length();
2467
+ // // if determine is negative, we need to invert one scale
2468
+ // const det = this.determinant();
2469
+ // if (det < 0) sx = -sx;
2470
+ // position.x = te[12];
2471
+ // position.y = te[13];
2472
+ // position.z = te[14];
2473
+ // // scale the rotation part
2474
+ // _m1.copy(this);
2475
+ // const invSX = 1 / sx;
2476
+ // const invSY = 1 / sy;
2477
+ // const invSZ = 1 / sz;
2478
+ // _m1.elements[0] *= invSX;
2479
+ // _m1.elements[1] *= invSX;
2480
+ // _m1.elements[2] *= invSX;
2481
+ // _m1.elements[4] *= invSY;
2482
+ // _m1.elements[5] *= invSY;
2483
+ // _m1.elements[6] *= invSY;
2484
+ // _m1.elements[8] *= invSZ;
2485
+ // _m1.elements[9] *= invSZ;
2486
+ // _m1.elements[10] *= invSZ;
2487
+ // quaternion.setFromRotationMatrix(_m1);
2488
+ // scale.x = sx;
2489
+ // scale.y = sy;
2490
+ // scale.z = sz;
2491
+ // return this;
2492
+ // }
2493
+ // makePerspective(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
2494
+ // const te = this.elements;
2495
+ // const x = 2 * near / (right - left);
2496
+ // const y = 2 * near / (top - bottom);
2497
+ // const a = (right + left) / (right - left);
2498
+ // const b = (top + bottom) / (top - bottom);
2499
+ // let c, d;
2500
+ // if (coordinateSystem === WebGLCoordinateSystem) {
2501
+ // c = - (far + near) / (far - near);
2502
+ // d = (- 2 * far * near) / (far - near);
2503
+ // } else if (coordinateSystem === WebGPUCoordinateSystem) {
2504
+ // c = - far / (far - near);
2505
+ // d = (- far * near) / (far - near);
2506
+ // } else {
2507
+ // throw new Error('THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem);
2508
+ // }
2509
+ // te[0] = x; te[4] = 0; te[8] = a; te[12] = 0;
2510
+ // te[1] = 0; te[5] = y; te[9] = b; te[13] = 0;
2511
+ // te[2] = 0; te[6] = 0; te[10] = c; te[14] = d;
2512
+ // te[3] = 0; te[7] = 0; te[11] = - 1; te[15] = 0;
2513
+ // return this;
2514
+ // }
2515
+ // makeOrthographic(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) {
2516
+ // const te = this.elements;
2517
+ // const w = 1.0 / (right - left);
2518
+ // const h = 1.0 / (top - bottom);
2519
+ // const p = 1.0 / (far - near);
2520
+ // const x = (right + left) * w;
2521
+ // const y = (top + bottom) * h;
2522
+ // let z, zInv;
2523
+ // if (coordinateSystem === WebGLCoordinateSystem) {
2524
+ // z = (far + near) * p;
2525
+ // zInv = - 2 * p;
2526
+ // } else if (coordinateSystem === WebGPUCoordinateSystem) {
2527
+ // z = near * p;
2528
+ // zInv = - 1 * p;
2529
+ // } else {
2530
+ // throw new Error('THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem);
2531
+ // }
2532
+ // te[0] = 2 * w; te[4] = 0; te[8] = 0; te[12] = - x;
2533
+ // te[1] = 0; te[5] = 2 * h; te[9] = 0; te[13] = - y;
2534
+ // te[2] = 0; te[6] = 0; te[10] = zInv; te[14] = - z;
2535
+ // te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1;
2536
+ // return this;
2537
+ // }
2538
+ ;
2539
+
2540
+ _proto.equals = function equals(matrix) {
2541
+ var te = this.elements;
2542
+ var me = matrix.elements;
2543
+
2544
+ for (var i = 0; i < 16; i++) {
2545
+ if (te[i] !== me[i]) return false;
2546
+ }
2547
+
2548
+ return true;
2549
+ } // fromArray(array, offset = 0) {
2550
+ // for (let i = 0; i < 16; i++) {
2551
+ // this.elements[i] = array[i + offset];
2552
+ // }
2553
+ // return this;
2554
+ // }
2555
+ // toArray(array = [], offset = 0) {
2556
+ // const te = this.elements;
2557
+ // array[offset] = te[0];
2558
+ // array[offset + 1] = te[1];
2559
+ // array[offset + 2] = te[2];
2560
+ // array[offset + 3] = te[3];
2561
+ // array[offset + 4] = te[4];
2562
+ // array[offset + 5] = te[5];
2563
+ // array[offset + 6] = te[6];
2564
+ // array[offset + 7] = te[7];
2565
+ // array[offset + 8] = te[8];
2566
+ // array[offset + 9] = te[9];
2567
+ // array[offset + 10] = te[10];
2568
+ // array[offset + 11] = te[11];
2569
+ // array[offset + 12] = te[12];
2570
+ // array[offset + 13] = te[13];
2571
+ // array[offset + 14] = te[14];
2572
+ // array[offset + 15] = te[15];
2573
+ // return array;
2574
+ // }
2575
+ ;
2576
+
2577
+ return Matrix4;
2578
+ }(); // const _v1 = new Vector3();
2579
+
2580
+ function _inheritsLoose(subClass, superClass) {
2581
+ subClass.prototype = Object.create(superClass.prototype);
2582
+ subClass.prototype.constructor = subClass;
2583
+
2584
+ _setPrototypeOf(subClass, superClass);
2585
+ }
2586
+
2587
+ function _setPrototypeOf(o, p) {
2588
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2589
+ o.__proto__ = p;
2590
+ return o;
2591
+ };
2592
+ return _setPrototypeOf(o, p);
2593
+ }
2594
+
2595
+ // code copy from https://github.com/mrdoob/three.js/blob/dev/src/extras/core/Curve.js
2596
+ // import * as MathUtils from '../../math/MathUtils.js';
2597
+ // import { Vector2 } from '../../math/Vector2.js';
2598
+ // import { Vector3 } from '../../math/Vector3.js';
2599
+ // import { Matrix4 } from '../../math/Matrix4.js';
2600
+
2601
+ /**
2602
+ * Extensible curve object.
2603
+ *
2604
+ * Some common of curve methods:
2605
+ * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
2606
+ * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
2607
+ * .getPoints(), .getSpacedPoints()
2608
+ * .getLength()
2609
+ * .updateArcLengths()
2610
+ *
2611
+ * This following curves inherit from THREE.Curve:
2612
+ *
2613
+ * -- 2D curves --
2614
+ * THREE.ArcCurve
2615
+ * THREE.CubicBezierCurve
2616
+ * THREE.EllipseCurve
2617
+ * THREE.LineCurve
2618
+ * THREE.QuadraticBezierCurve
2619
+ * THREE.SplineCurve
2620
+ *
2621
+ * -- 3D curves --
2622
+ * THREE.CatmullRomCurve3
2623
+ * THREE.CubicBezierCurve3
2624
+ * THREE.LineCurve3
2625
+ * THREE.QuadraticBezierCurve3
2626
+ *
2627
+ * A series of curves can be represented as a THREE.CurvePath.
2628
+ *
2629
+ **/
2630
+ var Curve = /*#__PURE__*/function () {
2631
+ function Curve() {
2632
+ this.type = 'Curve';
2633
+ this.arcLengthDivisions = 200;
2634
+ } // Virtual base class method to overwrite and implement in subclasses
2635
+
2636
+
2637
+ var _proto = Curve.prototype;
2638
+
2639
+ _proto.getPoint = function getPoint() {
2640
+ console.warn('THREE.Curve: .getPoint() not implemented.');
2641
+ return null;
2642
+ } // Get point at relative position in curve according to arc length
2643
+ // - u [0 .. 1]
2644
+ ;
2645
+
2646
+ _proto.getPointAt = function getPointAt(u, optionalTarget) {
2647
+ var t = this.getUtoTmapping(u);
2648
+ return this.getPoint(t, optionalTarget);
2649
+ } // Get sequence of points using getPoint( t )
2650
+ ;
2651
+
2652
+ _proto.getPoints = function getPoints(divisions) {
2653
+ if (divisions === void 0) {
2654
+ divisions = 5;
2655
+ }
2656
+
2657
+ var points = [];
2658
+
2659
+ for (var d = 0; d <= divisions; d++) {
2660
+ points.push(this.getPoint(d / divisions));
2661
+ }
2662
+
2663
+ return points;
2664
+ } // // Get sequence of points using getPointAt( u )
2665
+ // getSpacedPoints(divisions = 5) {
2666
+ // const points = [];
2667
+ // for (let d = 0; d <= divisions; d++) {
2668
+ // points.push(this.getPointAt(d / divisions));
2669
+ // }
2670
+ // return points;
2671
+ // }
2672
+ // Get total curve arc length
2673
+ ;
2674
+
2675
+ _proto.getLength = function getLength() {
2676
+ var lengths = this.getLengths();
2677
+ return lengths[lengths.length - 1];
2678
+ } // Get list of cumulative segment lengths
2679
+ ;
2680
+
2681
+ _proto.getLengths = function getLengths(divisions) {
2682
+ if (divisions === void 0) {
2683
+ divisions = this.arcLengthDivisions;
2684
+ }
2685
+
2686
+ if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) {
2687
+ return this.cacheArcLengths;
2688
+ }
2689
+
2690
+ this.needsUpdate = false;
2691
+ var cache = [];
2692
+ var current,
2693
+ last = this.getPoint(0);
2694
+ var sum = 0;
2695
+ cache.push(0);
2696
+
2697
+ for (var p = 1; p <= divisions; p++) {
2698
+ current = this.getPoint(p / divisions);
2699
+ sum += current.distanceTo(last);
2700
+ cache.push(sum);
2701
+ last = current;
2702
+ }
2703
+
2704
+ this.cacheArcLengths = cache;
2705
+ return cache; // { sums: cache, sum: sum }; Sum is in the last element.
2706
+ } // updateArcLengths() {
2707
+ // this.needsUpdate = true;
2708
+ // this.getLengths();
2709
+ // }
2710
+ // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
2711
+ ;
2712
+
2713
+ _proto.getUtoTmapping = function getUtoTmapping(u, distance) {
2714
+ var arcLengths = this.getLengths();
2715
+ var i = 0;
2716
+ var il = arcLengths.length;
2717
+ var targetArcLength; // The targeted u distance value to get
2718
+
2719
+ if (distance) {
2720
+ targetArcLength = distance;
2721
+ } else {
2722
+ targetArcLength = u * arcLengths[il - 1];
2723
+ } // binary search for the index with largest value smaller than target u distance
2724
+
2725
+
2726
+ var low = 0,
2727
+ high = il - 1,
2728
+ comparison;
2729
+
2730
+ while (low <= high) {
2731
+ i = Math.floor(low + (high - low) / 2); // less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
2732
+
2733
+ comparison = arcLengths[i] - targetArcLength;
2734
+
2735
+ if (comparison < 0) {
2736
+ low = i + 1;
2737
+ } else if (comparison > 0) {
2738
+ high = i - 1;
2739
+ } else {
2740
+ high = i;
2741
+ break; // DONE
2742
+ }
2743
+ }
2744
+
2745
+ i = high;
2746
+
2747
+ if (arcLengths[i] === targetArcLength) {
2748
+ return i / (il - 1);
2749
+ } // we could get finer grain at lengths, or use simple interpolation between two points
2750
+
2751
+
2752
+ var lengthBefore = arcLengths[i];
2753
+ var lengthAfter = arcLengths[i + 1];
2754
+ var segmentLength = lengthAfter - lengthBefore; // determine where we are between the 'before' and 'after' points
2755
+
2756
+ var segmentFraction = (targetArcLength - lengthBefore) / segmentLength; // add that fractional amount to t
2757
+
2758
+ var t = (i + segmentFraction) / (il - 1);
2759
+ return t;
2760
+ } // Returns a unit vector tangent at t
2761
+ // In case any sub curve does not implement its tangent derivation,
2762
+ // 2 points a small delta apart will be used to find its gradient
2763
+ // which seems to give a reasonable approximation
2764
+ // getTangent(t, optionalTarget) {
2765
+ // const delta = 0.0001;
2766
+ // let t1 = t - delta;
2767
+ // let t2 = t + delta;
2768
+ // // Capping in case of danger
2769
+ // if (t1 < 0) t1 = 0;
2770
+ // if (t2 > 1) t2 = 1;
2771
+ // const pt1 = this.getPoint(t1);
2772
+ // const pt2 = this.getPoint(t2);
2773
+ // const tangent = optionalTarget || ((pt1.isVector2) ? new Vector2() : new Vector3());
2774
+ // tangent.copy(pt2).sub(pt1).normalize();
2775
+ // return tangent;
2776
+ // }
2777
+ // getTangentAt(u, optionalTarget) {
2778
+ // const t = this.getUtoTmapping(u);
2779
+ // return this.getTangent(t, optionalTarget);
2780
+ // }
2781
+ // computeFrenetFrames(segments, closed) {
2782
+ // // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
2783
+ // const normal = new Vector3();
2784
+ // const tangents = [];
2785
+ // const normals = [];
2786
+ // const binormals = [];
2787
+ // const vec = new Vector3();
2788
+ // const mat = new Matrix4();
2789
+ // // compute the tangent vectors for each segment on the curve
2790
+ // for (let i = 0; i <= segments; i++) {
2791
+ // const u = i / segments;
2792
+ // tangents[i] = this.getTangentAt(u, new Vector3());
2793
+ // }
2794
+ // // select an initial normal vector perpendicular to the first tangent vector,
2795
+ // // and in the direction of the minimum tangent xyz component
2796
+ // normals[0] = new Vector3();
2797
+ // binormals[0] = new Vector3();
2798
+ // let min = Number.MAX_VALUE;
2799
+ // const tx = Math.abs(tangents[0].x);
2800
+ // const ty = Math.abs(tangents[0].y);
2801
+ // const tz = Math.abs(tangents[0].z);
2802
+ // if (tx <= min) {
2803
+ // min = tx;
2804
+ // normal.set(1, 0, 0);
2805
+ // }
2806
+ // if (ty <= min) {
2807
+ // min = ty;
2808
+ // normal.set(0, 1, 0);
2809
+ // }
2810
+ // if (tz <= min) {
2811
+ // normal.set(0, 0, 1);
2812
+ // }
2813
+ // vec.crossVectors(tangents[0], normal).normalize();
2814
+ // normals[0].crossVectors(tangents[0], vec);
2815
+ // binormals[0].crossVectors(tangents[0], normals[0]);
2816
+ // // compute the slowly-varying normal and binormal vectors for each segment on the curve
2817
+ // for (let i = 1; i <= segments; i++) {
2818
+ // normals[i] = normals[i - 1].clone();
2819
+ // binormals[i] = binormals[i - 1].clone();
2820
+ // vec.crossVectors(tangents[i - 1], tangents[i]);
2821
+ // if (vec.length() > Number.EPSILON) {
2822
+ // vec.normalize();
2823
+ // const theta = Math.acos(MathUtils.clamp(tangents[i - 1].dot(tangents[i]), - 1, 1)); // clamp for floating pt errors
2824
+ // normals[i].applyMatrix4(mat.makeRotationAxis(vec, theta));
2825
+ // }
2826
+ // binormals[i].crossVectors(tangents[i], normals[i]);
2827
+ // }
2828
+ // // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
2829
+ // if (closed === true) {
2830
+ // let theta = Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]), - 1, 1));
2831
+ // theta /= segments;
2832
+ // if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) {
2833
+ // theta = - theta;
2834
+ // }
2835
+ // for (let i = 1; i <= segments; i++) {
2836
+ // // twist a little...
2837
+ // normals[i].applyMatrix4(mat.makeRotationAxis(tangents[i], theta * i));
2838
+ // binormals[i].crossVectors(tangents[i], normals[i]);
2839
+ // }
2840
+ // }
2841
+ // return {
2842
+ // tangents: tangents,
2843
+ // normals: normals,
2844
+ // binormals: binormals
2845
+ // };
2846
+ // }
2847
+ // clone() {
2848
+ // return new this.constructor().copy(this);
2849
+ // }
2850
+ // copy(source) {
2851
+ // this.arcLengthDivisions = source.arcLengthDivisions;
2852
+ // return this;
2853
+ // }
2854
+ // toJSON() {
2855
+ // const data = {
2856
+ // metadata: {
2857
+ // version: 4.6,
2858
+ // type: 'Curve',
2859
+ // generator: 'Curve.toJSON'
2860
+ // }
2861
+ // };
2862
+ // data.arcLengthDivisions = this.arcLengthDivisions;
2863
+ // data.type = this.type;
2864
+ // return data;
2865
+ // }
2866
+ // fromJSON(json) {
2867
+ // this.arcLengthDivisions = json.arcLengthDivisions;
2868
+ // return this;
2869
+ // }
2870
+ ;
2871
+
2872
+ return Curve;
2873
+ }();
2874
+
2875
+ /**
2876
+ * // code copy from https://github.com/mrdoob/three.js/blob/dev/src/extras/core/Interpolations.js
2877
+ * Bezier Curves formulas obtained from
2878
+ * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
2879
+ */
2880
+
2881
+
2882
+ function QuadraticBezierP0(t, p) {
2883
+ var k = 1 - t;
2884
+ return k * k * p;
2885
+ }
2886
+
2887
+ function QuadraticBezierP1(t, p) {
2888
+ return 2 * (1 - t) * t * p;
2889
+ }
2890
+
2891
+ function QuadraticBezierP2(t, p) {
2892
+ return t * t * p;
2893
+ }
2894
+
2895
+ function QuadraticBezier(t, p0, p1, p2) {
2896
+ return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2);
2897
+ } //
2898
+
2899
+ var QuadraticBezierCurve3 = /*#__PURE__*/function (_Curve) {
2900
+ _inheritsLoose(QuadraticBezierCurve3, _Curve);
2901
+
2902
+ function QuadraticBezierCurve3(v0, v1, v2) {
2903
+ var _this;
2904
+
2905
+ if (v0 === void 0) {
2906
+ v0 = new Vector3();
2907
+ }
2908
+
2909
+ if (v1 === void 0) {
2910
+ v1 = new Vector3();
2911
+ }
2912
+
2913
+ if (v2 === void 0) {
2914
+ v2 = new Vector3();
2915
+ }
2916
+
2917
+ _this = _Curve.call(this) || this;
2918
+ _this.isQuadraticBezierCurve3 = true;
2919
+ _this.type = 'QuadraticBezierCurve3';
2920
+ _this.v0 = v0;
2921
+ _this.v1 = v1;
2922
+ _this.v2 = v2;
2923
+ return _this;
2924
+ }
2925
+
2926
+ var _proto = QuadraticBezierCurve3.prototype;
2927
+
2928
+ _proto.getPoint = function getPoint(t, optionalTarget) {
2929
+ if (optionalTarget === void 0) {
2930
+ optionalTarget = new Vector3();
2931
+ }
2932
+
2933
+ var point = optionalTarget;
2934
+ var v0 = this.v0,
2935
+ v1 = this.v1,
2936
+ v2 = this.v2;
2937
+ point.set(QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y), QuadraticBezier(t, v0.z, v1.z, v2.z));
2938
+ return point;
2939
+ } // copy(source) {
2940
+ // super.copy(source);
2941
+ // this.v0.copy(source.v0);
2942
+ // this.v1.copy(source.v1);
2943
+ // this.v2.copy(source.v2);
2944
+ // return this;
2945
+ // }
2946
+ // toJSON() {
2947
+ // const data = super.toJSON();
2948
+ // data.v0 = this.v0.toArray();
2949
+ // data.v1 = this.v1.toArray();
2950
+ // data.v2 = this.v2.toArray();
2951
+ // return data;
2952
+ // }
2953
+ // fromJSON(json) {
2954
+ // super.fromJSON(json);
2955
+ // this.v0.fromArray(json.v0);
2956
+ // this.v1.fromArray(json.v1);
2957
+ // this.v2.fromArray(json.v2);
2958
+ // return this;
2959
+ // }
2960
+ ;
2961
+
2962
+ return QuadraticBezierCurve3;
2963
+ }(Curve);
2964
+
2965
+ /* eslint-disable no-tabs */
2966
+ var helpVec3_1 = new Vector3();
2967
+ var helpVec3_2 = new Vector3();
2968
+ var helpVec3_3 = new Vector3();
2969
+ var helpMat4 = new Matrix4();
2970
+ var helpCurve = new QuadraticBezierCurve3();
2971
+
2972
+ function _getCornerBezierCurve(last, current, next, cornerRadius, firstCorner, out) {
2973
+ var lastDir = helpVec3_1.subVectors(current, last);
2974
+ var nextDir = helpVec3_2.subVectors(next, current);
2975
+ var lastDirLength = lastDir.length();
2976
+ var nextDirLength = nextDir.length();
2977
+ lastDir.normalize();
2978
+ nextDir.normalize(); // cornerRadius can not bigger then lineDistance / 2, auto fix this
2979
+
2980
+ var v0Dist = Math.min((firstCorner ? lastDirLength / 2 : lastDirLength) * 0.999999, cornerRadius);
2981
+ out.v0.copy(current).sub(lastDir.multiplyScalar(v0Dist));
2982
+ out.v1.copy(current);
2983
+ var v2Dist = Math.min(nextDirLength / 2 * 0.999999, cornerRadius);
2984
+ out.v2.copy(current).add(nextDir.multiplyScalar(v2Dist));
2985
+ return out;
2986
+ }
2987
+ /**
2988
+ * PathPointList
2989
+ * input points to generate a PathPoint list
2990
+ */
2991
+
2992
+
2993
+ var PathPointList = /*#__PURE__*/function () {
2994
+ function PathPointList() {
2995
+ this.array = []; // path point array
2996
+
2997
+ this.count = 0;
2998
+ }
2999
+ /**
3000
+ * Set points
3001
+ * @param {THREE.Vector3[]} points key points array
3002
+ * @param {number} cornerRadius? the corner radius. set 0 to disable round corner. default is 0.1
3003
+ * @param {number} cornerSplit? the corner split. default is 10.
3004
+ * @param {number} up? force up. default is auto up (calculate by tangent).
3005
+ * @param {boolean} close? close path. default is false.
3006
+ */
3007
+
3008
+
3009
+ var _proto = PathPointList.prototype;
3010
+
3011
+ _proto.set = function set(points, cornerRadius, cornerSplit, up, close) {
3012
+ if (cornerRadius === void 0) {
3013
+ cornerRadius = 0.1;
3014
+ }
3015
+
3016
+ if (cornerSplit === void 0) {
3017
+ cornerSplit = 10;
3018
+ }
3019
+
3020
+ if (up === void 0) {
3021
+ up = null;
3022
+ }
3023
+
3024
+ if (close === void 0) {
3025
+ close = false;
3026
+ }
3027
+
3028
+ points = points.slice(0);
3029
+
3030
+ if (points.length < 2) {
3031
+ console.warn('PathPointList: points length less than 2.');
3032
+ this.count = 0;
3033
+ return;
3034
+ } // Auto close
3035
+
3036
+
3037
+ if (close && !points[0].equals(points[points.length - 1])) {
3038
+ points.push(new Vector3().copy(points[0]));
3039
+ } // Generate path point list
3040
+
3041
+
3042
+ for (var i = 0, l = points.length; i < l; i++) {
3043
+ if (i === 0) {
3044
+ this._start(points[i], points[i + 1], up);
3045
+ } else if (i === l - 1) {
3046
+ if (close) {
3047
+ // Connect end point and start point
3048
+ this._corner(points[i], points[1], cornerRadius, cornerSplit, up); // Fix start point
3049
+
3050
+
3051
+ var dist = this.array[0].dist; // should not copy dist
3052
+
3053
+ this.array[0].copy(this.array[this.count - 1]);
3054
+ this.array[0].dist = dist;
3055
+ } else {
3056
+ this._end(points[i]);
3057
+ }
3058
+ } else {
3059
+ this._corner(points[i], points[i + 1], cornerRadius, cornerSplit, up);
3060
+ }
3061
+ }
3062
+ }
3063
+ /**
3064
+ * Get distance of this path
3065
+ * @return {number}
3066
+ */
3067
+ ;
3068
+
3069
+ _proto.distance = function distance() {
3070
+ if (this.count > 0) {
3071
+ return this.array[this.count - 1].dist;
3072
+ }
3073
+
3074
+ return 0;
3075
+ };
3076
+
3077
+ _proto._getByIndex = function _getByIndex(index) {
3078
+ if (!this.array[index]) {
3079
+ this.array[index] = new PathPoint();
3080
+ }
3081
+
3082
+ return this.array[index];
3083
+ };
3084
+
3085
+ _proto._start = function _start(current, next, up) {
3086
+ this.count = 0;
3087
+
3088
+ var point = this._getByIndex(this.count);
3089
+
3090
+ point.pos.copy(current);
3091
+ point.dir.subVectors(next, current); // init start up dir
3092
+
3093
+ if (up) {
3094
+ point.up.copy(up);
3095
+ } else {
3096
+ // select an initial normal vector perpendicular to the first tangent vector
3097
+ var min = Number.MAX_VALUE;
3098
+ var tx = Math.abs(point.dir.x);
3099
+ var ty = Math.abs(point.dir.y);
3100
+ var tz = Math.abs(point.dir.z);
3101
+
3102
+ if (tx < min) {
3103
+ min = tx;
3104
+ point.up.set(1, 0, 0);
3105
+ }
3106
+
3107
+ if (ty < min) {
3108
+ min = ty;
3109
+ point.up.set(0, 1, 0);
3110
+ }
3111
+
3112
+ if (tz < min) {
3113
+ point.up.set(0, 0, 1);
3114
+ }
3115
+ }
3116
+
3117
+ point.right.crossVectors(point.dir, point.up).normalize();
3118
+ point.up.crossVectors(point.right, point.dir).normalize();
3119
+ point.dist = 0;
3120
+ point.widthScale = 1;
3121
+ point.sharp = false;
3122
+ point.dir.normalize();
3123
+ this.count++;
3124
+ };
3125
+
3126
+ _proto._end = function _end(current) {
3127
+ var lastPoint = this.array[this.count - 1];
3128
+
3129
+ var point = this._getByIndex(this.count);
3130
+
3131
+ point.pos.copy(current);
3132
+ point.dir.subVectors(current, lastPoint.pos);
3133
+ var dist = point.dir.length();
3134
+ point.dir.normalize();
3135
+ point.up.copy(lastPoint.up); // copy last up
3136
+
3137
+ var vec = helpVec3_1.crossVectors(lastPoint.dir, point.dir);
3138
+
3139
+ if (vec.length() > Number.EPSILON) {
3140
+ vec.normalize();
3141
+ var theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
3142
+
3143
+ point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
3144
+ }
3145
+
3146
+ point.right.crossVectors(point.dir, point.up).normalize();
3147
+ point.dist = lastPoint.dist + dist;
3148
+ point.widthScale = 1;
3149
+ point.sharp = false;
3150
+ this.count++;
3151
+ };
3152
+
3153
+ _proto._corner = function _corner(current, next, cornerRadius, cornerSplit, up) {
3154
+ if (cornerRadius > 0 && cornerSplit > 0) {
3155
+ var lastPoint = this.array[this.count - 1];
3156
+
3157
+ var curve = _getCornerBezierCurve(lastPoint.pos, current, next, cornerRadius, this.count - 1 === 0, helpCurve);
3158
+
3159
+ var samplerPoints = curve.getPoints(cornerSplit); // TODO optimize
3160
+
3161
+ for (var f = 0; f < cornerSplit; f++) {
3162
+ this._sharpCorner(samplerPoints[f], samplerPoints[f + 1], up, f === 0 ? 1 : 0);
3163
+ }
3164
+
3165
+ if (!samplerPoints[cornerSplit].equals(next)) {
3166
+ this._sharpCorner(samplerPoints[cornerSplit], next, up, 2);
3167
+ }
3168
+ } else {
3169
+ this._sharpCorner(current, next, up, 0, true);
3170
+ }
3171
+ } // dirType: 0 - use middle dir / 1 - use last dir / 2- use next dir
3172
+ ;
3173
+
3174
+ _proto._sharpCorner = function _sharpCorner(current, next, up, dirType, sharp) {
3175
+ if (dirType === void 0) {
3176
+ dirType = 0;
3177
+ }
3178
+
3179
+ if (sharp === void 0) {
3180
+ sharp = false;
3181
+ }
3182
+
3183
+ var lastPoint = this.array[this.count - 1];
3184
+
3185
+ var point = this._getByIndex(this.count);
3186
+
3187
+ var lastDir = helpVec3_1.subVectors(current, lastPoint.pos);
3188
+ var nextDir = helpVec3_2.subVectors(next, current);
3189
+ var lastDirLength = lastDir.length();
3190
+ lastDir.normalize();
3191
+ nextDir.normalize();
3192
+ point.pos.copy(current);
3193
+
3194
+ if (dirType === 1) {
3195
+ point.dir.copy(lastDir);
3196
+ } else if (dirType === 2) {
3197
+ point.dir.copy(nextDir);
3198
+ } else {
3199
+ point.dir.addVectors(lastDir, nextDir);
3200
+ point.dir.normalize();
3201
+ }
3202
+
3203
+ if (up) {
3204
+ if (point.dir.dot(up) === 1) {
3205
+ point.right.crossVectors(nextDir, up).normalize();
3206
+ } else {
3207
+ point.right.crossVectors(point.dir, up).normalize();
3208
+ }
3209
+
3210
+ point.up.crossVectors(point.right, point.dir).normalize();
3211
+ } else {
3212
+ point.up.copy(lastPoint.up);
3213
+ var vec = helpVec3_3.crossVectors(lastPoint.dir, point.dir);
3214
+
3215
+ if (vec.length() > Number.EPSILON) {
3216
+ vec.normalize();
3217
+ var theta = Math.acos(Math.min(Math.max(lastPoint.dir.dot(point.dir), -1), 1)); // clamp for floating pt errors
3218
+
3219
+ point.up.applyMatrix4(helpMat4.makeRotationAxis(vec, theta));
3220
+ }
3221
+
3222
+ point.right.crossVectors(point.dir, point.up).normalize();
3223
+ }
3224
+
3225
+ point.dist = lastPoint.dist + lastDirLength;
3226
+
3227
+ var _cos = lastDir.dot(nextDir);
3228
+
3229
+ point.widthScale = Math.min(1 / Math.sqrt((1 + _cos) / 2), 1.415) || 1;
3230
+ point.sharp = Math.abs(_cos - 1) > 0.05 && sharp;
3231
+ this.count++;
3232
+ };
3233
+
3234
+ return PathPointList;
3235
+ }();
3236
+
3237
+ var UP = new Vector3(0, 0, 1);
3238
+ function expandPaths(lines, options) {
3239
+ options = Object.assign({}, {
3240
+ lineWidth: 1,
3241
+ cornerRadius: 0,
3242
+ cornerSplit: 10
3243
+ }, options);
3244
+ var results = lines.map(function (line) {
3245
+ var points = line.map(function (p) {
3246
+ var x = p[0],
3247
+ y = p[1],
3248
+ z = p[2];
3249
+ return new Vector3(x, y, z || 0);
3250
+ });
3251
+ var pathPointList = new PathPointList();
3252
+ pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
3253
+ var result = generatePathVertexData(pathPointList, options);
3254
+ result.line = line;
3255
+ result.position = new Float32Array(result.points);
3256
+ result.indices = new Uint32Array(result.index);
3257
+ result.uv = new Float32Array(result.uvs);
3258
+ result.normal = new Float32Array(result.normal);
3259
+ return result;
3260
+ });
3261
+ var result = merge(results);
3262
+ result.lines = lines;
3263
+ return result;
3264
+ } // Vertex Data Generate Functions
3265
+ // code copy from https://github.com/shawn0326/three.path/blob/master/src/PathGeometry.js
3266
+
3267
+ function generatePathVertexData(pathPointList, options) {
3268
+ var width = options.lineWidth || 0.1;
3269
+ var progress = 1;
3270
+ var halfWidth = width / 2;
3271
+ var sideWidth = width;
3272
+ var totalDistance = pathPointList.distance();
3273
+ var progressDistance = progress * totalDistance;
3274
+
3275
+ if (totalDistance === 0) {
3276
+ return null;
3277
+ }
3278
+
3279
+ var sharpUvOffset = halfWidth / sideWidth; // const sharpUvOffset2 = halfWidth / totalDistance;
3280
+
3281
+ var count = 0; // modify data
3282
+
3283
+ var position = [];
3284
+ var normal = [];
3285
+ var uv = [];
3286
+ var indices = [];
3287
+ var verticesCount = 0;
3288
+ var right = new Vector3();
3289
+ var left = new Vector3(); // for sharp corners
3290
+
3291
+ var leftOffset = new Vector3();
3292
+ var rightOffset = new Vector3();
3293
+ var tempPoint1 = new Vector3();
3294
+ var tempPoint2 = new Vector3();
3295
+
3296
+ function addVertices(pathPoint) {
3297
+ var first = position.length === 0;
3298
+ var sharpCorner = pathPoint.sharp && !first;
3299
+ var uvDist = pathPoint.dist / sideWidth; // const uvDist2 = pathPoint.dist / totalDistance;
3300
+
3301
+ var dir = pathPoint.dir;
3302
+ var up = pathPoint.up;
3303
+ var _right = pathPoint.right;
3304
+
3305
+ {
3306
+ right.copy(_right).multiplyScalar(halfWidth * pathPoint.widthScale);
3307
+ }
3308
+
3309
+ {
3310
+ left.copy(_right).multiplyScalar(-halfWidth * pathPoint.widthScale);
3311
+ }
3312
+
3313
+ right.add(pathPoint.pos);
3314
+ left.add(pathPoint.pos);
3315
+
3316
+ if (sharpCorner) {
3317
+ leftOffset.fromArray(position, position.length - 6).sub(left);
3318
+ rightOffset.fromArray(position, position.length - 3).sub(right);
3319
+ var leftDist = leftOffset.length();
3320
+ var rightDist = rightOffset.length();
3321
+ var sideOffset = leftDist - rightDist;
3322
+ var longerOffset, longEdge;
3323
+
3324
+ if (sideOffset > 0) {
3325
+ longerOffset = leftOffset;
3326
+ longEdge = left;
3327
+ } else {
3328
+ longerOffset = rightOffset;
3329
+ longEdge = right;
3330
+ }
3331
+
3332
+ tempPoint1.copy(longerOffset).setLength(Math.abs(sideOffset)).add(longEdge); // eslint-disable-next-line prefer-const
3333
+
3334
+ var _cos = tempPoint2.copy(longEdge).sub(tempPoint1).normalize().dot(dir); // eslint-disable-next-line prefer-const
3335
+
3336
+
3337
+ var _len = tempPoint2.copy(longEdge).sub(tempPoint1).length(); // eslint-disable-next-line prefer-const
3338
+
3339
+
3340
+ var _dist = _cos * _len * 2;
3341
+
3342
+ tempPoint2.copy(dir).setLength(_dist).add(tempPoint1);
3343
+
3344
+ if (sideOffset > 0) {
3345
+ position.push(tempPoint1.x, tempPoint1.y, tempPoint1.z, // 6
3346
+ right.x, right.y, right.z, // 5
3347
+ left.x, left.y, left.z, // 4
3348
+ right.x, right.y, right.z, // 3
3349
+ tempPoint2.x, tempPoint2.y, tempPoint2.z, // 2
3350
+ right.x, right.y, right.z // 1
3351
+ );
3352
+ verticesCount += 6;
3353
+ indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 4, verticesCount - 6, verticesCount - 5, verticesCount - 2, verticesCount - 4, verticesCount - 1);
3354
+ count += 12;
3355
+ } else {
3356
+ position.push(left.x, left.y, left.z, // 6
3357
+ tempPoint1.x, tempPoint1.y, tempPoint1.z, // 5
3358
+ left.x, left.y, left.z, // 4
3359
+ right.x, right.y, right.z, // 3
3360
+ left.x, left.y, left.z, // 2
3361
+ tempPoint2.x, tempPoint2.y, tempPoint2.z // 1
3362
+ );
3363
+ verticesCount += 6;
3364
+ indices.push(verticesCount - 6, verticesCount - 8, verticesCount - 7, verticesCount - 6, verticesCount - 7, verticesCount - 5, verticesCount - 6, verticesCount - 5, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
3365
+ count += 12;
3366
+ }
3367
+
3368
+ normal.push(up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z, up.x, up.y, up.z);
3369
+ uv.push(uvDist - sharpUvOffset, 0, uvDist - sharpUvOffset, 1, uvDist, 0, uvDist, 1, uvDist + sharpUvOffset, 0, uvDist + sharpUvOffset, 1); // if (generateUv2) {
3370
+ // uv2.push(
3371
+ // uvDist2 - sharpUvOffset2, 0,
3372
+ // uvDist2 - sharpUvOffset2, 1,
3373
+ // uvDist2, 0,
3374
+ // uvDist2, 1,
3375
+ // uvDist2 + sharpUvOffset2, 0,
3376
+ // uvDist2 + sharpUvOffset2, 1
3377
+ // );
3378
+ // }
3379
+ } else {
3380
+ position.push(left.x, left.y, left.z, right.x, right.y, right.z);
3381
+ normal.push(up.x, up.y, up.z, up.x, up.y, up.z);
3382
+ uv.push(uvDist, 0, uvDist, 1); // if (generateUv2) {
3383
+ // uv2.push(
3384
+ // uvDist2, 0,
3385
+ // uvDist2, 1
3386
+ // );
3387
+ // }
3388
+
3389
+ verticesCount += 2;
3390
+
3391
+ if (!first) {
3392
+ indices.push(verticesCount - 2, verticesCount - 4, verticesCount - 3, verticesCount - 2, verticesCount - 3, verticesCount - 1);
3393
+ count += 6;
3394
+ }
3395
+ }
3396
+ }
3397
+
3398
+ var lastPoint;
3399
+
3400
+ if (progressDistance > 0) {
3401
+ for (var i = 0; i < pathPointList.count; i++) {
3402
+ var pathPoint = pathPointList.array[i];
3403
+
3404
+ if (pathPoint.dist > progressDistance) {
3405
+ var prevPoint = pathPointList.array[i - 1];
3406
+ lastPoint = new PathPoint(); // linear lerp for progress
3407
+
3408
+ var alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
3409
+ lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
3410
+ addVertices(lastPoint);
3411
+ break;
3412
+ } else {
3413
+ addVertices(pathPoint);
3414
+ }
3415
+ }
3416
+ } else {
3417
+ lastPoint = pathPointList.array[0];
3418
+ }
3419
+
3420
+ return {
3421
+ points: position,
3422
+ normal: normal,
3423
+ uvs: uv,
3424
+ index: indices,
3425
+ count: count
3426
+ };
3427
+ }
3428
+
3429
+ export { cylinder, expandLine, expandPaths, extrudePolygons, extrudePolylines };