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