poly-extrude 0.5.0 → 0.7.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.5.0
2
+ * poly-extrude v0.7.0
3
3
  */
4
4
  var earcut$2 = {exports: {}};
5
5
 
@@ -1065,11 +1065,19 @@ function isClosedRing(ring) {
1065
1065
  return x1 === x2 && y1 === y2;
1066
1066
  }
1067
1067
 
1068
+ function checkOptions(options) {
1069
+ options.lineWidth = Math.max(0, options.lineWidth);
1070
+ options.depth = Math.max(0, options.depth);
1071
+ options.sideDepth = Math.max(0, options.sideDepth);
1072
+ }
1073
+
1068
1074
  function extrudePolylines(lines, options) {
1069
1075
  options = Object.assign({}, {
1070
1076
  depth: 2,
1071
- lineWidth: 1
1077
+ lineWidth: 1,
1078
+ bottomStickGround: false
1072
1079
  }, options);
1080
+ checkOptions(options);
1073
1081
  var results = lines.map(function (line) {
1074
1082
  var result = expandLine(line, options);
1075
1083
  result.line = line;
@@ -1090,8 +1098,10 @@ function extrudeSlopes(lines, options) {
1090
1098
  depth: 2,
1091
1099
  lineWidth: 1,
1092
1100
  side: 'left',
1093
- sideDepth: 0
1101
+ sideDepth: 0,
1102
+ bottomStickGround: false
1094
1103
  }, options);
1104
+ checkOptions(options);
1095
1105
  var _options = options,
1096
1106
  depth = _options.depth,
1097
1107
  side = _options.side,
@@ -1135,6 +1145,7 @@ function extrudeSlopes(lines, options) {
1135
1145
  }
1136
1146
 
1137
1147
  function generateTopAndBottom(result, options) {
1148
+ var bottomStickGround = options.bottomStickGround;
1138
1149
  var z = options.depth;
1139
1150
  var depths = result.depths;
1140
1151
  var lz = z,
@@ -1176,12 +1187,22 @@ function generateTopAndBottom(result, options) {
1176
1187
  var idx2 = len * 2 * 3 + idx0;
1177
1188
  points[idx2] = x1;
1178
1189
  points[idx2 + 1] = y1;
1179
- points[idx2 + 2] = z1; // bottom right
1190
+ points[idx2 + 2] = z1;
1191
+
1192
+ if (bottomStickGround) {
1193
+ points[idx2 + 2] = 0;
1194
+ } // bottom right
1195
+
1180
1196
 
1181
1197
  var idx3 = len * 2 * 3 + len * 3 + idx0;
1182
1198
  points[idx3] = x2;
1183
1199
  points[idx3 + 1] = y2;
1184
1200
  points[idx3 + 2] = z2;
1201
+
1202
+ if (bottomStickGround) {
1203
+ points[idx3 + 2] = 0;
1204
+ }
1205
+
1185
1206
  i++;
1186
1207
  }
1187
1208
 
@@ -1242,12 +1263,29 @@ function generateSides(result, options) {
1242
1263
  rightPoints = result.rightPoints,
1243
1264
  uvs = result.uvs;
1244
1265
  var z = options.depth;
1266
+ var bottomStickGround = options.bottomStickGround;
1245
1267
  var rings = [leftPoints, rightPoints];
1246
1268
  var depthsEnable = result.depths;
1247
1269
 
1248
1270
  function addOneSideIndex(v1, v2) {
1249
1271
  var idx = points.length / 3;
1250
- points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2], v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
1272
+ var pIndex = points.length - 1; // top
1273
+
1274
+ points[++pIndex] = v1[0];
1275
+ points[++pIndex] = v1[1];
1276
+ points[++pIndex] = (depthsEnable ? v1.depth : z) + v1[2];
1277
+ points[++pIndex] = v2[0];
1278
+ points[++pIndex] = v2[1];
1279
+ points[++pIndex] = (depthsEnable ? v2.depth : z) + v2[2]; // points.push(v1[0], v1[1], (depthsEnable ? v1.depth : z) + v1[2], v2[0], v2[1], (depthsEnable ? v2.depth : z) + v2[2]);
1280
+ // bottom
1281
+
1282
+ points[++pIndex] = v1[0];
1283
+ points[++pIndex] = v1[1];
1284
+ points[++pIndex] = bottomStickGround ? 0 : v1[2];
1285
+ points[++pIndex] = v2[0];
1286
+ points[++pIndex] = v2[1];
1287
+ points[++pIndex] = bottomStickGround ? 0 : v2[2]; // points.push(v1[0], v1[1], v1[2], v2[0], v2[1], v2[2]);
1288
+
1251
1289
  var a = idx + 2,
1252
1290
  b = idx + 3,
1253
1291
  c = idx,
@@ -1595,8 +1633,980 @@ function cylinder(point, options) {
1595
1633
  };
1596
1634
  }
1597
1635
 
1636
+ function _regeneratorRuntime() {
1637
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1638
+
1639
+ _regeneratorRuntime = function () {
1640
+ return exports;
1641
+ };
1642
+
1643
+ var exports = {},
1644
+ Op = Object.prototype,
1645
+ hasOwn = Op.hasOwnProperty,
1646
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
1647
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
1648
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1649
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1650
+
1651
+ function define(obj, key, value) {
1652
+ return Object.defineProperty(obj, key, {
1653
+ value: value,
1654
+ enumerable: !0,
1655
+ configurable: !0,
1656
+ writable: !0
1657
+ }), obj[key];
1658
+ }
1659
+
1660
+ try {
1661
+ define({}, "");
1662
+ } catch (err) {
1663
+ define = function (obj, key, value) {
1664
+ return obj[key] = value;
1665
+ };
1666
+ }
1667
+
1668
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1669
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1670
+ generator = Object.create(protoGenerator.prototype),
1671
+ context = new Context(tryLocsList || []);
1672
+ return generator._invoke = function (innerFn, self, context) {
1673
+ var state = "suspendedStart";
1674
+ return function (method, arg) {
1675
+ if ("executing" === state) throw new Error("Generator is already running");
1676
+
1677
+ if ("completed" === state) {
1678
+ if ("throw" === method) throw arg;
1679
+ return doneResult();
1680
+ }
1681
+
1682
+ for (context.method = method, context.arg = arg;;) {
1683
+ var delegate = context.delegate;
1684
+
1685
+ if (delegate) {
1686
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1687
+
1688
+ if (delegateResult) {
1689
+ if (delegateResult === ContinueSentinel) continue;
1690
+ return delegateResult;
1691
+ }
1692
+ }
1693
+
1694
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1695
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
1696
+ context.dispatchException(context.arg);
1697
+ } else "return" === context.method && context.abrupt("return", context.arg);
1698
+ state = "executing";
1699
+ var record = tryCatch(innerFn, self, context);
1700
+
1701
+ if ("normal" === record.type) {
1702
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1703
+ return {
1704
+ value: record.arg,
1705
+ done: context.done
1706
+ };
1707
+ }
1708
+
1709
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1710
+ }
1711
+ };
1712
+ }(innerFn, self, context), generator;
1713
+ }
1714
+
1715
+ function tryCatch(fn, obj, arg) {
1716
+ try {
1717
+ return {
1718
+ type: "normal",
1719
+ arg: fn.call(obj, arg)
1720
+ };
1721
+ } catch (err) {
1722
+ return {
1723
+ type: "throw",
1724
+ arg: err
1725
+ };
1726
+ }
1727
+ }
1728
+
1729
+ exports.wrap = wrap;
1730
+ var ContinueSentinel = {};
1731
+
1732
+ function Generator() {}
1733
+
1734
+ function GeneratorFunction() {}
1735
+
1736
+ function GeneratorFunctionPrototype() {}
1737
+
1738
+ var IteratorPrototype = {};
1739
+ define(IteratorPrototype, iteratorSymbol, function () {
1740
+ return this;
1741
+ });
1742
+ var getProto = Object.getPrototypeOf,
1743
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1744
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1745
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1746
+
1747
+ function defineIteratorMethods(prototype) {
1748
+ ["next", "throw", "return"].forEach(function (method) {
1749
+ define(prototype, method, function (arg) {
1750
+ return this._invoke(method, arg);
1751
+ });
1752
+ });
1753
+ }
1754
+
1755
+ function AsyncIterator(generator, PromiseImpl) {
1756
+ function invoke(method, arg, resolve, reject) {
1757
+ var record = tryCatch(generator[method], generator, arg);
1758
+
1759
+ if ("throw" !== record.type) {
1760
+ var result = record.arg,
1761
+ value = result.value;
1762
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1763
+ invoke("next", value, resolve, reject);
1764
+ }, function (err) {
1765
+ invoke("throw", err, resolve, reject);
1766
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1767
+ result.value = unwrapped, resolve(result);
1768
+ }, function (error) {
1769
+ return invoke("throw", error, resolve, reject);
1770
+ });
1771
+ }
1772
+
1773
+ reject(record.arg);
1774
+ }
1775
+
1776
+ var previousPromise;
1777
+
1778
+ this._invoke = function (method, arg) {
1779
+ function callInvokeWithMethodAndArg() {
1780
+ return new PromiseImpl(function (resolve, reject) {
1781
+ invoke(method, arg, resolve, reject);
1782
+ });
1783
+ }
1784
+
1785
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1786
+ };
1787
+ }
1788
+
1789
+ function maybeInvokeDelegate(delegate, context) {
1790
+ var method = delegate.iterator[context.method];
1791
+
1792
+ if (undefined === method) {
1793
+ if (context.delegate = null, "throw" === context.method) {
1794
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
1795
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
1796
+ }
1797
+
1798
+ return ContinueSentinel;
1799
+ }
1800
+
1801
+ var record = tryCatch(method, delegate.iterator, context.arg);
1802
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1803
+ var info = record.arg;
1804
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
1805
+ }
1806
+
1807
+ function pushTryEntry(locs) {
1808
+ var entry = {
1809
+ tryLoc: locs[0]
1810
+ };
1811
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1812
+ }
1813
+
1814
+ function resetTryEntry(entry) {
1815
+ var record = entry.completion || {};
1816
+ record.type = "normal", delete record.arg, entry.completion = record;
1817
+ }
1818
+
1819
+ function Context(tryLocsList) {
1820
+ this.tryEntries = [{
1821
+ tryLoc: "root"
1822
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1823
+ }
1824
+
1825
+ function values(iterable) {
1826
+ if (iterable) {
1827
+ var iteratorMethod = iterable[iteratorSymbol];
1828
+ if (iteratorMethod) return iteratorMethod.call(iterable);
1829
+ if ("function" == typeof iterable.next) return iterable;
1830
+
1831
+ if (!isNaN(iterable.length)) {
1832
+ var i = -1,
1833
+ next = function next() {
1834
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1835
+
1836
+ return next.value = undefined, next.done = !0, next;
1837
+ };
1838
+
1839
+ return next.next = next;
1840
+ }
1841
+ }
1842
+
1843
+ return {
1844
+ next: doneResult
1845
+ };
1846
+ }
1847
+
1848
+ function doneResult() {
1849
+ return {
1850
+ value: undefined,
1851
+ done: !0
1852
+ };
1853
+ }
1854
+
1855
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1856
+ var ctor = "function" == typeof genFun && genFun.constructor;
1857
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1858
+ }, exports.mark = function (genFun) {
1859
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1860
+ }, exports.awrap = function (arg) {
1861
+ return {
1862
+ __await: arg
1863
+ };
1864
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1865
+ return this;
1866
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1867
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
1868
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1869
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1870
+ return result.done ? result.value : iter.next();
1871
+ });
1872
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1873
+ return this;
1874
+ }), define(Gp, "toString", function () {
1875
+ return "[object Generator]";
1876
+ }), exports.keys = function (object) {
1877
+ var keys = [];
1878
+
1879
+ for (var key in object) keys.push(key);
1880
+
1881
+ return keys.reverse(), function next() {
1882
+ for (; keys.length;) {
1883
+ var key = keys.pop();
1884
+ if (key in object) return next.value = key, next.done = !1, next;
1885
+ }
1886
+
1887
+ return next.done = !0, next;
1888
+ };
1889
+ }, exports.values = values, Context.prototype = {
1890
+ constructor: Context,
1891
+ reset: function (skipTempReset) {
1892
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1893
+ },
1894
+ stop: function () {
1895
+ this.done = !0;
1896
+ var rootRecord = this.tryEntries[0].completion;
1897
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
1898
+ return this.rval;
1899
+ },
1900
+ dispatchException: function (exception) {
1901
+ if (this.done) throw exception;
1902
+ var context = this;
1903
+
1904
+ function handle(loc, caught) {
1905
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1906
+ }
1907
+
1908
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1909
+ var entry = this.tryEntries[i],
1910
+ record = entry.completion;
1911
+ if ("root" === entry.tryLoc) return handle("end");
1912
+
1913
+ if (entry.tryLoc <= this.prev) {
1914
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
1915
+ hasFinally = hasOwn.call(entry, "finallyLoc");
1916
+
1917
+ if (hasCatch && hasFinally) {
1918
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1919
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1920
+ } else if (hasCatch) {
1921
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1922
+ } else {
1923
+ if (!hasFinally) throw new Error("try statement without catch or finally");
1924
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1925
+ }
1926
+ }
1927
+ }
1928
+ },
1929
+ abrupt: function (type, arg) {
1930
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1931
+ var entry = this.tryEntries[i];
1932
+
1933
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1934
+ var finallyEntry = entry;
1935
+ break;
1936
+ }
1937
+ }
1938
+
1939
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1940
+ var record = finallyEntry ? finallyEntry.completion : {};
1941
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1942
+ },
1943
+ complete: function (record, afterLoc) {
1944
+ if ("throw" === record.type) throw record.arg;
1945
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
1946
+ },
1947
+ finish: function (finallyLoc) {
1948
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1949
+ var entry = this.tryEntries[i];
1950
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1951
+ }
1952
+ },
1953
+ catch: function (tryLoc) {
1954
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1955
+ var entry = this.tryEntries[i];
1956
+
1957
+ if (entry.tryLoc === tryLoc) {
1958
+ var record = entry.completion;
1959
+
1960
+ if ("throw" === record.type) {
1961
+ var thrown = record.arg;
1962
+ resetTryEntry(entry);
1963
+ }
1964
+
1965
+ return thrown;
1966
+ }
1967
+ }
1968
+
1969
+ throw new Error("illegal catch attempt");
1970
+ },
1971
+ delegateYield: function (iterable, resultName, nextLoc) {
1972
+ return this.delegate = {
1973
+ iterator: values(iterable),
1974
+ resultName: resultName,
1975
+ nextLoc: nextLoc
1976
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1977
+ }
1978
+ }, exports;
1979
+ }
1980
+
1981
+ function _defineProperties(target, props) {
1982
+ for (var i = 0; i < props.length; i++) {
1983
+ var descriptor = props[i];
1984
+ descriptor.enumerable = descriptor.enumerable || false;
1985
+ descriptor.configurable = true;
1986
+ if ("value" in descriptor) descriptor.writable = true;
1987
+ Object.defineProperty(target, descriptor.key, descriptor);
1988
+ }
1989
+ }
1990
+
1991
+ function _createClass(Constructor, protoProps, staticProps) {
1992
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1993
+ if (staticProps) _defineProperties(Constructor, staticProps);
1994
+ Object.defineProperty(Constructor, "prototype", {
1995
+ writable: false
1996
+ });
1997
+ return Constructor;
1998
+ }
1999
+
2000
+ function _inheritsLoose(subClass, superClass) {
2001
+ subClass.prototype = Object.create(superClass.prototype);
2002
+ subClass.prototype.constructor = subClass;
2003
+
2004
+ _setPrototypeOf(subClass, superClass);
2005
+ }
2006
+
2007
+ function _setPrototypeOf(o, p) {
2008
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2009
+ o.__proto__ = p;
2010
+ return o;
2011
+ };
2012
+ return _setPrototypeOf(o, p);
2013
+ }
2014
+
2015
+ // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Quaternion.js
2016
+ // import { clamp } from './MathUtils.js';
2017
+ var Quaternion = /*#__PURE__*/function (_Symbol$iterator) {
2018
+ function Quaternion(x, y, z, w) {
2019
+ if (x === void 0) {
2020
+ x = 0;
2021
+ }
2022
+
2023
+ if (y === void 0) {
2024
+ y = 0;
2025
+ }
2026
+
2027
+ if (z === void 0) {
2028
+ z = 0;
2029
+ }
2030
+
2031
+ if (w === void 0) {
2032
+ w = 1;
2033
+ }
2034
+
2035
+ this.isQuaternion = true;
2036
+ this._x = x;
2037
+ this._y = y;
2038
+ this._z = z;
2039
+ this._w = w;
2040
+ }
2041
+
2042
+ Quaternion.slerpFlat = function slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) {
2043
+ // fuzz-free, array-based Quaternion SLERP operation
2044
+ var x0 = src0[srcOffset0 + 0],
2045
+ y0 = src0[srcOffset0 + 1],
2046
+ z0 = src0[srcOffset0 + 2],
2047
+ w0 = src0[srcOffset0 + 3];
2048
+ var x1 = src1[srcOffset1 + 0],
2049
+ y1 = src1[srcOffset1 + 1],
2050
+ z1 = src1[srcOffset1 + 2],
2051
+ w1 = src1[srcOffset1 + 3];
2052
+
2053
+ if (t === 0) {
2054
+ dst[dstOffset + 0] = x0;
2055
+ dst[dstOffset + 1] = y0;
2056
+ dst[dstOffset + 2] = z0;
2057
+ dst[dstOffset + 3] = w0;
2058
+ return;
2059
+ }
2060
+
2061
+ if (t === 1) {
2062
+ dst[dstOffset + 0] = x1;
2063
+ dst[dstOffset + 1] = y1;
2064
+ dst[dstOffset + 2] = z1;
2065
+ dst[dstOffset + 3] = w1;
2066
+ return;
2067
+ }
2068
+
2069
+ if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) {
2070
+ var s = 1 - t;
2071
+ var cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
2072
+ dir = cos >= 0 ? 1 : -1,
2073
+ sqrSin = 1 - cos * cos; // Skip the Slerp for tiny steps to avoid numeric problems:
2074
+
2075
+ if (sqrSin > Number.EPSILON) {
2076
+ var sin = Math.sqrt(sqrSin),
2077
+ len = Math.atan2(sin, cos * dir);
2078
+ s = Math.sin(s * len) / sin;
2079
+ t = Math.sin(t * len) / sin;
2080
+ }
2081
+
2082
+ var tDir = t * dir;
2083
+ x0 = x0 * s + x1 * tDir;
2084
+ y0 = y0 * s + y1 * tDir;
2085
+ z0 = z0 * s + z1 * tDir;
2086
+ w0 = w0 * s + w1 * tDir; // Normalize in case we just did a lerp:
2087
+
2088
+ if (s === 1 - t) {
2089
+ var f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0);
2090
+ x0 *= f;
2091
+ y0 *= f;
2092
+ z0 *= f;
2093
+ w0 *= f;
2094
+ }
2095
+ }
2096
+
2097
+ dst[dstOffset] = x0;
2098
+ dst[dstOffset + 1] = y0;
2099
+ dst[dstOffset + 2] = z0;
2100
+ dst[dstOffset + 3] = w0;
2101
+ };
2102
+
2103
+ Quaternion.multiplyQuaternionsFlat = function multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) {
2104
+ var x0 = src0[srcOffset0];
2105
+ var y0 = src0[srcOffset0 + 1];
2106
+ var z0 = src0[srcOffset0 + 2];
2107
+ var w0 = src0[srcOffset0 + 3];
2108
+ var x1 = src1[srcOffset1];
2109
+ var y1 = src1[srcOffset1 + 1];
2110
+ var z1 = src1[srcOffset1 + 2];
2111
+ var w1 = src1[srcOffset1 + 3];
2112
+ dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
2113
+ dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
2114
+ dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
2115
+ dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
2116
+ return dst;
2117
+ };
2118
+
2119
+ var _proto = Quaternion.prototype;
2120
+
2121
+ _proto.set = function set(x, y, z, w) {
2122
+ this._x = x;
2123
+ this._y = y;
2124
+ this._z = z;
2125
+ this._w = w;
2126
+
2127
+ this._onChangeCallback();
2128
+
2129
+ return this;
2130
+ };
2131
+
2132
+ _proto.clone = function clone() {
2133
+ return new this.constructor(this._x, this._y, this._z, this._w);
2134
+ };
2135
+
2136
+ _proto.copy = function copy(quaternion) {
2137
+ this._x = quaternion.x;
2138
+ this._y = quaternion.y;
2139
+ this._z = quaternion.z;
2140
+ this._w = quaternion.w;
2141
+
2142
+ this._onChangeCallback();
2143
+
2144
+ return this;
2145
+ };
2146
+
2147
+ _proto.setFromEuler = function setFromEuler(euler, update) {
2148
+ if (update === void 0) {
2149
+ update = true;
2150
+ }
2151
+
2152
+ var x = euler._x,
2153
+ y = euler._y,
2154
+ z = euler._z,
2155
+ order = euler._order; // http://www.mathworks.com/matlabcentral/fileexchange/
2156
+ // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
2157
+ // content/SpinCalc.m
2158
+
2159
+ var cos = Math.cos;
2160
+ var sin = Math.sin;
2161
+ var c1 = cos(x / 2);
2162
+ var c2 = cos(y / 2);
2163
+ var c3 = cos(z / 2);
2164
+ var s1 = sin(x / 2);
2165
+ var s2 = sin(y / 2);
2166
+ var s3 = sin(z / 2);
2167
+
2168
+ switch (order) {
2169
+ case 'XYZ':
2170
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
2171
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
2172
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
2173
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
2174
+ break;
2175
+
2176
+ case 'YXZ':
2177
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
2178
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
2179
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
2180
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
2181
+ break;
2182
+
2183
+ case 'ZXY':
2184
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
2185
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
2186
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
2187
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
2188
+ break;
2189
+
2190
+ case 'ZYX':
2191
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
2192
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
2193
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
2194
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
2195
+ break;
2196
+
2197
+ case 'YZX':
2198
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
2199
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
2200
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
2201
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
2202
+ break;
2203
+
2204
+ case 'XZY':
2205
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
2206
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
2207
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
2208
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
2209
+ break;
2210
+
2211
+ default:
2212
+ console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order);
2213
+ }
2214
+
2215
+ if (update === true) this._onChangeCallback();
2216
+ return this;
2217
+ };
2218
+
2219
+ _proto.setFromAxisAngle = function setFromAxisAngle(axis, angle) {
2220
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
2221
+ // assumes axis is normalized
2222
+ var halfAngle = angle / 2,
2223
+ s = Math.sin(halfAngle);
2224
+ this._x = axis.x * s;
2225
+ this._y = axis.y * s;
2226
+ this._z = axis.z * s;
2227
+ this._w = Math.cos(halfAngle);
2228
+
2229
+ this._onChangeCallback();
2230
+
2231
+ return this;
2232
+ };
2233
+
2234
+ _proto.setFromRotationMatrix = function setFromRotationMatrix(m) {
2235
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
2236
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
2237
+ var te = m.elements,
2238
+ m11 = te[0],
2239
+ m12 = te[4],
2240
+ m13 = te[8],
2241
+ m21 = te[1],
2242
+ m22 = te[5],
2243
+ m23 = te[9],
2244
+ m31 = te[2],
2245
+ m32 = te[6],
2246
+ m33 = te[10],
2247
+ trace = m11 + m22 + m33;
2248
+
2249
+ if (trace > 0) {
2250
+ var s = 0.5 / Math.sqrt(trace + 1.0);
2251
+ this._w = 0.25 / s;
2252
+ this._x = (m32 - m23) * s;
2253
+ this._y = (m13 - m31) * s;
2254
+ this._z = (m21 - m12) * s;
2255
+ } else if (m11 > m22 && m11 > m33) {
2256
+ var _s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
2257
+
2258
+ this._w = (m32 - m23) / _s;
2259
+ this._x = 0.25 * _s;
2260
+ this._y = (m12 + m21) / _s;
2261
+ this._z = (m13 + m31) / _s;
2262
+ } else if (m22 > m33) {
2263
+ var _s2 = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
2264
+
2265
+ this._w = (m13 - m31) / _s2;
2266
+ this._x = (m12 + m21) / _s2;
2267
+ this._y = 0.25 * _s2;
2268
+ this._z = (m23 + m32) / _s2;
2269
+ } else {
2270
+ var _s3 = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
2271
+
2272
+ this._w = (m21 - m12) / _s3;
2273
+ this._x = (m13 + m31) / _s3;
2274
+ this._y = (m23 + m32) / _s3;
2275
+ this._z = 0.25 * _s3;
2276
+ }
2277
+
2278
+ this._onChangeCallback();
2279
+
2280
+ return this;
2281
+ };
2282
+
2283
+ _proto.setFromUnitVectors = function setFromUnitVectors(vFrom, vTo) {
2284
+ // assumes direction vectors vFrom and vTo are normalized
2285
+ var r = vFrom.dot(vTo) + 1;
2286
+
2287
+ if (r < Number.EPSILON) {
2288
+ // vFrom and vTo point in opposite directions
2289
+ r = 0;
2290
+
2291
+ if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) {
2292
+ this._x = -vFrom.y;
2293
+ this._y = vFrom.x;
2294
+ this._z = 0;
2295
+ this._w = r;
2296
+ } else {
2297
+ this._x = 0;
2298
+ this._y = -vFrom.z;
2299
+ this._z = vFrom.y;
2300
+ this._w = r;
2301
+ }
2302
+ } else {
2303
+ // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
2304
+ this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
2305
+ this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
2306
+ this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
2307
+ this._w = r;
2308
+ }
2309
+
2310
+ return this.normalize();
2311
+ } // angleTo(q) {
2312
+ // return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1)));
2313
+ // }
2314
+ ;
2315
+
2316
+ _proto.rotateTowards = function rotateTowards(q, step) {
2317
+ var angle = this.angleTo(q);
2318
+ if (angle === 0) return this;
2319
+ var t = Math.min(1, step / angle);
2320
+ this.slerp(q, t);
2321
+ return this;
2322
+ };
2323
+
2324
+ _proto.identity = function identity() {
2325
+ return this.set(0, 0, 0, 1);
2326
+ };
2327
+
2328
+ _proto.invert = function invert() {
2329
+ // quaternion is assumed to have unit length
2330
+ return this.conjugate();
2331
+ };
2332
+
2333
+ _proto.conjugate = function conjugate() {
2334
+ this._x *= -1;
2335
+ this._y *= -1;
2336
+ this._z *= -1;
2337
+
2338
+ this._onChangeCallback();
2339
+
2340
+ return this;
2341
+ };
2342
+
2343
+ _proto.dot = function dot(v) {
2344
+ return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
2345
+ };
2346
+
2347
+ _proto.lengthSq = function lengthSq() {
2348
+ return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
2349
+ };
2350
+
2351
+ _proto.length = function length() {
2352
+ return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w);
2353
+ };
2354
+
2355
+ _proto.normalize = function normalize() {
2356
+ var l = this.length();
2357
+
2358
+ if (l === 0) {
2359
+ this._x = 0;
2360
+ this._y = 0;
2361
+ this._z = 0;
2362
+ this._w = 1;
2363
+ } else {
2364
+ l = 1 / l;
2365
+ this._x = this._x * l;
2366
+ this._y = this._y * l;
2367
+ this._z = this._z * l;
2368
+ this._w = this._w * l;
2369
+ }
2370
+
2371
+ this._onChangeCallback();
2372
+
2373
+ return this;
2374
+ };
2375
+
2376
+ _proto.multiply = function multiply(q) {
2377
+ return this.multiplyQuaternions(this, q);
2378
+ };
2379
+
2380
+ _proto.premultiply = function premultiply(q) {
2381
+ return this.multiplyQuaternions(q, this);
2382
+ };
2383
+
2384
+ _proto.multiplyQuaternions = function multiplyQuaternions(a, b) {
2385
+ // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
2386
+ var qax = a._x,
2387
+ qay = a._y,
2388
+ qaz = a._z,
2389
+ qaw = a._w;
2390
+ var qbx = b._x,
2391
+ qby = b._y,
2392
+ qbz = b._z,
2393
+ qbw = b._w;
2394
+ this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
2395
+ this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
2396
+ this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
2397
+ this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
2398
+
2399
+ this._onChangeCallback();
2400
+
2401
+ return this;
2402
+ };
2403
+
2404
+ _proto.slerp = function slerp(qb, t) {
2405
+ if (t === 0) return this;
2406
+ if (t === 1) return this.copy(qb);
2407
+ var x = this._x,
2408
+ y = this._y,
2409
+ z = this._z,
2410
+ w = this._w; // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
2411
+
2412
+ var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
2413
+
2414
+ if (cosHalfTheta < 0) {
2415
+ this._w = -qb._w;
2416
+ this._x = -qb._x;
2417
+ this._y = -qb._y;
2418
+ this._z = -qb._z;
2419
+ cosHalfTheta = -cosHalfTheta;
2420
+ } else {
2421
+ this.copy(qb);
2422
+ }
2423
+
2424
+ if (cosHalfTheta >= 1.0) {
2425
+ this._w = w;
2426
+ this._x = x;
2427
+ this._y = y;
2428
+ this._z = z;
2429
+ return this;
2430
+ }
2431
+
2432
+ var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
2433
+
2434
+ if (sqrSinHalfTheta <= Number.EPSILON) {
2435
+ var s = 1 - t;
2436
+ this._w = s * w + t * this._w;
2437
+ this._x = s * x + t * this._x;
2438
+ this._y = s * y + t * this._y;
2439
+ this._z = s * z + t * this._z;
2440
+ this.normalize(); // normalize calls _onChangeCallback()
2441
+
2442
+ return this;
2443
+ }
2444
+
2445
+ var sinHalfTheta = Math.sqrt(sqrSinHalfTheta);
2446
+ var halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta);
2447
+ var ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta,
2448
+ ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
2449
+ this._w = w * ratioA + this._w * ratioB;
2450
+ this._x = x * ratioA + this._x * ratioB;
2451
+ this._y = y * ratioA + this._y * ratioB;
2452
+ this._z = z * ratioA + this._z * ratioB;
2453
+
2454
+ this._onChangeCallback();
2455
+
2456
+ return this;
2457
+ };
2458
+
2459
+ _proto.slerpQuaternions = function slerpQuaternions(qa, qb, t) {
2460
+ return this.copy(qa).slerp(qb, t);
2461
+ };
2462
+
2463
+ _proto.random = function random() {
2464
+ // sets this quaternion to a uniform random unit quaternnion
2465
+ // Ken Shoemake
2466
+ // Uniform random rotations
2467
+ // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
2468
+ var theta1 = 2 * Math.PI * Math.random();
2469
+ var theta2 = 2 * Math.PI * Math.random();
2470
+ var x0 = Math.random();
2471
+ var r1 = Math.sqrt(1 - x0);
2472
+ var r2 = Math.sqrt(x0);
2473
+ return this.set(r1 * Math.sin(theta1), r1 * Math.cos(theta1), r2 * Math.sin(theta2), r2 * Math.cos(theta2));
2474
+ };
2475
+
2476
+ _proto.equals = function equals(quaternion) {
2477
+ return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w;
2478
+ };
2479
+
2480
+ _proto.fromArray = function fromArray(array, offset) {
2481
+ if (offset === void 0) {
2482
+ offset = 0;
2483
+ }
2484
+
2485
+ this._x = array[offset];
2486
+ this._y = array[offset + 1];
2487
+ this._z = array[offset + 2];
2488
+ this._w = array[offset + 3];
2489
+
2490
+ this._onChangeCallback();
2491
+
2492
+ return this;
2493
+ };
2494
+
2495
+ _proto.toArray = function toArray(array, offset) {
2496
+ if (array === void 0) {
2497
+ array = [];
2498
+ }
2499
+
2500
+ if (offset === void 0) {
2501
+ offset = 0;
2502
+ }
2503
+
2504
+ array[offset] = this._x;
2505
+ array[offset + 1] = this._y;
2506
+ array[offset + 2] = this._z;
2507
+ array[offset + 3] = this._w;
2508
+ return array;
2509
+ };
2510
+
2511
+ _proto.fromBufferAttribute = function fromBufferAttribute(attribute, index) {
2512
+ this._x = attribute.getX(index);
2513
+ this._y = attribute.getY(index);
2514
+ this._z = attribute.getZ(index);
2515
+ this._w = attribute.getW(index);
2516
+
2517
+ this._onChangeCallback();
2518
+
2519
+ return this;
2520
+ };
2521
+
2522
+ _proto.toJSON = function toJSON() {
2523
+ return this.toArray();
2524
+ };
2525
+
2526
+ _proto._onChange = function _onChange(callback) {
2527
+ this._onChangeCallback = callback;
2528
+ return this;
2529
+ };
2530
+
2531
+ _proto._onChangeCallback = function _onChangeCallback() {};
2532
+
2533
+ _proto[_Symbol$iterator] = /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
2534
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
2535
+ while (1) {
2536
+ switch (_context.prev = _context.next) {
2537
+ case 0:
2538
+ _context.next = 2;
2539
+ return this._x;
2540
+
2541
+ case 2:
2542
+ _context.next = 4;
2543
+ return this._y;
2544
+
2545
+ case 4:
2546
+ _context.next = 6;
2547
+ return this._z;
2548
+
2549
+ case 6:
2550
+ _context.next = 8;
2551
+ return this._w;
2552
+
2553
+ case 8:
2554
+ case "end":
2555
+ return _context.stop();
2556
+ }
2557
+ }
2558
+ }, _callee, this);
2559
+ });
2560
+
2561
+ _createClass(Quaternion, [{
2562
+ key: "x",
2563
+ get: function get() {
2564
+ return this._x;
2565
+ },
2566
+ set: function set(value) {
2567
+ this._x = value;
2568
+
2569
+ this._onChangeCallback();
2570
+ }
2571
+ }, {
2572
+ key: "y",
2573
+ get: function get() {
2574
+ return this._y;
2575
+ },
2576
+ set: function set(value) {
2577
+ this._y = value;
2578
+
2579
+ this._onChangeCallback();
2580
+ }
2581
+ }, {
2582
+ key: "z",
2583
+ get: function get() {
2584
+ return this._z;
2585
+ },
2586
+ set: function set(value) {
2587
+ this._z = value;
2588
+
2589
+ this._onChangeCallback();
2590
+ }
2591
+ }, {
2592
+ key: "w",
2593
+ get: function get() {
2594
+ return this._w;
2595
+ },
2596
+ set: function set(value) {
2597
+ this._w = value;
2598
+
2599
+ this._onChangeCallback();
2600
+ }
2601
+ }]);
2602
+
2603
+ return Quaternion;
2604
+ }(Symbol.iterator);
2605
+
1598
2606
  // import * as MathUtils from './MathUtils.js';
1599
- // code copy from https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js
2607
+
2608
+ var _quaternion = new Quaternion();
2609
+
1600
2610
  var Vector3 = /*#__PURE__*/function () {
1601
2611
  function Vector3(x, y, z) {
1602
2612
  if (x === void 0) {
@@ -1744,10 +2754,11 @@ var Vector3 = /*#__PURE__*/function () {
1744
2754
  } // applyEuler(euler) {
1745
2755
  // return this.applyQuaternion(_quaternion.setFromEuler(euler));
1746
2756
  // }
1747
- // applyAxisAngle(axis, angle) {
1748
- // return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
1749
- // }
1750
- // applyMatrix3(m) {
2757
+ ;
2758
+
2759
+ _proto.applyAxisAngle = function applyAxisAngle(axis, angle) {
2760
+ return this.applyQuaternion(_quaternion.setFromAxisAngle(axis, angle));
2761
+ } // applyMatrix3(m) {
1751
2762
  // const x = this.x, y = this.y, z = this.z;
1752
2763
  // const e = m.elements;
1753
2764
  // this.x = e[0] * x + e[3] * y + e[6] * z;
@@ -1770,21 +2781,27 @@ var Vector3 = /*#__PURE__*/function () {
1770
2781
  this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
1771
2782
  this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
1772
2783
  return this;
1773
- } // applyQuaternion(q) {
1774
- // const x = this.x, y = this.y, z = this.z;
1775
- // const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
1776
- // // calculate quat * vector
1777
- // const ix = qw * x + qy * z - qz * y;
1778
- // const iy = qw * y + qz * x - qx * z;
1779
- // const iz = qw * z + qx * y - qy * x;
1780
- // const iw = - qx * x - qy * y - qz * z;
1781
- // // calculate result * inverse quat
1782
- // this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
1783
- // this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
1784
- // this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
1785
- // return this;
1786
- // }
1787
- // project(camera) {
2784
+ };
2785
+
2786
+ _proto.applyQuaternion = function applyQuaternion(q) {
2787
+ var x = this.x,
2788
+ y = this.y,
2789
+ z = this.z;
2790
+ var qx = q.x,
2791
+ qy = q.y,
2792
+ qz = q.z,
2793
+ qw = q.w; // calculate quat * vector
2794
+
2795
+ var ix = qw * x + qy * z - qz * y;
2796
+ var iy = qw * y + qz * x - qx * z;
2797
+ var iz = qw * z + qx * y - qy * x;
2798
+ var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
2799
+
2800
+ this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
2801
+ this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;
2802
+ this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;
2803
+ return this;
2804
+ } // project(camera) {
1788
2805
  // return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);
1789
2806
  // }
1790
2807
  // unproject(camera) {
@@ -2715,21 +3732,6 @@ var Matrix4 = /*#__PURE__*/function () {
2715
3732
  return Matrix4;
2716
3733
  }(); // const _v1 = new Vector3();
2717
3734
 
2718
- function _inheritsLoose(subClass, superClass) {
2719
- subClass.prototype = Object.create(superClass.prototype);
2720
- subClass.prototype.constructor = subClass;
2721
-
2722
- _setPrototypeOf(subClass, superClass);
2723
- }
2724
-
2725
- function _setPrototypeOf(o, p) {
2726
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2727
- o.__proto__ = p;
2728
- return o;
2729
- };
2730
- return _setPrototypeOf(o, p);
2731
- }
2732
-
2733
3735
  // code copy from https://github.com/mrdoob/three.js/blob/dev/src/extras/core/Curve.js
2734
3736
  // import * as MathUtils from '../../math/MathUtils.js';
2735
3737
  // import { Vector2 } from '../../math/Vector2.js';
@@ -3372,7 +4374,7 @@ var PathPointList = /*#__PURE__*/function () {
3372
4374
  return PathPointList;
3373
4375
  }();
3374
4376
 
3375
- var UP = new Vector3(0, 0, 1);
4377
+ var UP$1 = new Vector3(0, 0, 1);
3376
4378
  function expandPaths(lines, options) {
3377
4379
  options = Object.assign({}, {
3378
4380
  lineWidth: 1,
@@ -3387,7 +4389,7 @@ function expandPaths(lines, options) {
3387
4389
  return new Vector3(x, y, z || 0);
3388
4390
  });
3389
4391
  var pathPointList = new PathPointList();
3390
- pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
4392
+ pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP$1);
3391
4393
  var result = generatePathVertexData(pathPointList, options);
3392
4394
  result.line = line;
3393
4395
  result.position = new Float32Array(result.points);
@@ -3564,4 +4566,142 @@ function generatePathVertexData(pathPointList, options) {
3564
4566
  };
3565
4567
  }
3566
4568
 
3567
- export { cylinder, expandLine, expandPaths, extrudePolygons, extrudePolylines, extrudeSlopes, leftOnLine };
4569
+ var UP = new Vector3(0, 0, 1);
4570
+ function expandTubes(lines, options) {
4571
+ options = Object.assign({}, {
4572
+ radius: 1,
4573
+ cornerSplit: 0,
4574
+ radialSegments: 8,
4575
+ startRad: -Math.PI / 4
4576
+ }, options);
4577
+ var results = lines.map(function (line) {
4578
+ var points = line.map(function (p) {
4579
+ var x = p[0],
4580
+ y = p[1],
4581
+ z = p[2];
4582
+ return new Vector3(x, y, z || 0);
4583
+ });
4584
+ var pathPointList = new PathPointList();
4585
+ pathPointList.set(points, options.cornerRadius, options.cornerSplit, UP);
4586
+ var result = generateTubeVertexData(pathPointList, options);
4587
+ result.line = line;
4588
+ result.position = new Float32Array(result.points);
4589
+ result.indices = new Uint32Array(result.index);
4590
+ result.uv = new Float32Array(result.uvs);
4591
+ result.normal = new Float32Array(result.normal);
4592
+ return result;
4593
+ });
4594
+ var result = merge(results);
4595
+ result.lines = lines;
4596
+ return result;
4597
+ } // Vertex Data Generate Functions
4598
+ // code copy from https://github.com/shawn0326/three.path/blob/master/src/PathGeometry.js
4599
+
4600
+ function generateTubeVertexData(pathPointList, options) {
4601
+ var radius = Math.max(options.radius || 1, 0.00000001);
4602
+ var progress = options.progress !== undefined ? options.progress : 1;
4603
+ var radialSegments = Math.max(3, options.radialSegments || 8);
4604
+ var startRad = options.startRad || 0;
4605
+ var circum = radius * 2 * Math.PI;
4606
+ var totalDistance = pathPointList.distance();
4607
+ var progressDistance = progress * totalDistance;
4608
+
4609
+ if (progressDistance === 0) {
4610
+ return null;
4611
+ }
4612
+
4613
+ var count = 0; // modify data
4614
+
4615
+ var points = [];
4616
+ var normal = [];
4617
+ var uvs = []; // const uv2 = [];
4618
+
4619
+ var index = [];
4620
+ var verticesCount = 0;
4621
+ var normalDir = new Vector3();
4622
+ var pIndex = -1;
4623
+ var nIndex = -1;
4624
+ var uIndex = -1;
4625
+ var iIndex = -1;
4626
+
4627
+ function addVertices(pathPoint, radius, radialSegments) {
4628
+ var first = points.length === 0;
4629
+ var uvDist = pathPoint.dist / circum; // const uvDist2 = pathPoint.dist / totalDistance;
4630
+
4631
+ for (var i = 0; i <= radialSegments; i++) {
4632
+ var r = i;
4633
+
4634
+ if (r === radialSegments) {
4635
+ r = 0;
4636
+ }
4637
+
4638
+ normalDir.copy(pathPoint.up).applyAxisAngle(pathPoint.dir, startRad + Math.PI * 2 * r / radialSegments).normalize();
4639
+ var scale = radius * pathPoint.widthScale;
4640
+ points[++pIndex] = pathPoint.pos.x + normalDir.x * scale;
4641
+ points[++pIndex] = pathPoint.pos.y + normalDir.y * scale;
4642
+ points[++pIndex] = pathPoint.pos.z + normalDir.z * scale;
4643
+ normal[++nIndex] = normalDir.x;
4644
+ normal[++nIndex] = normalDir.y;
4645
+ normal[++nIndex] = normalDir.z;
4646
+ uvs[++uIndex] = uvDist;
4647
+ uvs[++uIndex] = i / radialSegments; // uvs.push(uvDist, r / radialSegments);
4648
+ // if (generateUv2) {
4649
+ // uv2.push(uvDist2, r / radialSegments);
4650
+ // }
4651
+
4652
+ verticesCount++;
4653
+ }
4654
+
4655
+ if (!first) {
4656
+ var begin1 = verticesCount - (radialSegments + 1) * 2;
4657
+ var begin2 = verticesCount - (radialSegments + 1);
4658
+
4659
+ for (var _i = 0; _i < radialSegments; _i++) {
4660
+ index[++iIndex] = begin2 + _i;
4661
+ index[++iIndex] = begin1 + _i;
4662
+ index[++iIndex] = begin1 + _i + 1;
4663
+ index[++iIndex] = begin2 + _i;
4664
+ index[++iIndex] = begin1 + _i + 1;
4665
+ index[++iIndex] = begin2 + _i + 1; // index.push(
4666
+ // begin2 + i,
4667
+ // begin1 + i,
4668
+ // begin1 + i + 1,
4669
+ // begin2 + i,
4670
+ // begin1 + i + 1,
4671
+ // begin2 + i + 1
4672
+ // );
4673
+
4674
+ count += 6;
4675
+ }
4676
+ }
4677
+ }
4678
+
4679
+ if (progressDistance > 0) {
4680
+ for (var i = 0; i < pathPointList.count; i++) {
4681
+ var pathPoint = pathPointList.array[i];
4682
+
4683
+ if (pathPoint.dist > progressDistance) {
4684
+ var prevPoint = pathPointList.array[i - 1];
4685
+ var lastPoint = new PathPoint(); // linear lerp for progress
4686
+
4687
+ var alpha = (progressDistance - prevPoint.dist) / (pathPoint.dist - prevPoint.dist);
4688
+ lastPoint.lerpPathPoints(prevPoint, pathPoint, alpha);
4689
+ addVertices(lastPoint, radius, radialSegments);
4690
+ break;
4691
+ } else {
4692
+ addVertices(pathPoint, radius, radialSegments);
4693
+ }
4694
+ }
4695
+ }
4696
+
4697
+ return {
4698
+ points: points,
4699
+ normal: normal,
4700
+ uvs: uvs,
4701
+ // uv2,
4702
+ index: index,
4703
+ count: count
4704
+ };
4705
+ }
4706
+
4707
+ export { cylinder, expandLine, expandPaths, expandTubes, extrudePolygons, extrudePolylines, extrudeSlopes, leftOnLine };