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