@antv/g-canvas 1.3.1 → 1.5.1
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/index.esm.js +4 -5
- package/dist/index.js +3 -4
- package/dist/index.umd.js +379 -1009
- package/dist/index.umd.min.js +6 -6
- package/package.json +9 -9
package/dist/index.umd.js
CHANGED
|
@@ -1090,151 +1090,6 @@
|
|
|
1090
1090
|
|
|
1091
1091
|
return Math.sqrt(y);
|
|
1092
1092
|
};
|
|
1093
|
-
/**
|
|
1094
|
-
* 3x3 Matrix
|
|
1095
|
-
* @module mat3
|
|
1096
|
-
*/
|
|
1097
|
-
|
|
1098
|
-
/**
|
|
1099
|
-
* Creates a new identity mat3
|
|
1100
|
-
*
|
|
1101
|
-
* @returns {mat3} a new 3x3 matrix
|
|
1102
|
-
*/
|
|
1103
|
-
|
|
1104
|
-
function create() {
|
|
1105
|
-
var out = new ARRAY_TYPE(9);
|
|
1106
|
-
|
|
1107
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
1108
|
-
out[1] = 0;
|
|
1109
|
-
out[2] = 0;
|
|
1110
|
-
out[3] = 0;
|
|
1111
|
-
out[5] = 0;
|
|
1112
|
-
out[6] = 0;
|
|
1113
|
-
out[7] = 0;
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
out[0] = 1;
|
|
1117
|
-
out[4] = 1;
|
|
1118
|
-
out[8] = 1;
|
|
1119
|
-
return out;
|
|
1120
|
-
}
|
|
1121
|
-
/**
|
|
1122
|
-
* Multiplies two mat3's
|
|
1123
|
-
*
|
|
1124
|
-
* @param {mat3} out the receiving matrix
|
|
1125
|
-
* @param {ReadonlyMat3} a the first operand
|
|
1126
|
-
* @param {ReadonlyMat3} b the second operand
|
|
1127
|
-
* @returns {mat3} out
|
|
1128
|
-
*/
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
function multiply(out, a, b) {
|
|
1132
|
-
var a00 = a[0],
|
|
1133
|
-
a01 = a[1],
|
|
1134
|
-
a02 = a[2];
|
|
1135
|
-
var a10 = a[3],
|
|
1136
|
-
a11 = a[4],
|
|
1137
|
-
a12 = a[5];
|
|
1138
|
-
var a20 = a[6],
|
|
1139
|
-
a21 = a[7],
|
|
1140
|
-
a22 = a[8];
|
|
1141
|
-
var b00 = b[0],
|
|
1142
|
-
b01 = b[1],
|
|
1143
|
-
b02 = b[2];
|
|
1144
|
-
var b10 = b[3],
|
|
1145
|
-
b11 = b[4],
|
|
1146
|
-
b12 = b[5];
|
|
1147
|
-
var b20 = b[6],
|
|
1148
|
-
b21 = b[7],
|
|
1149
|
-
b22 = b[8];
|
|
1150
|
-
out[0] = b00 * a00 + b01 * a10 + b02 * a20;
|
|
1151
|
-
out[1] = b00 * a01 + b01 * a11 + b02 * a21;
|
|
1152
|
-
out[2] = b00 * a02 + b01 * a12 + b02 * a22;
|
|
1153
|
-
out[3] = b10 * a00 + b11 * a10 + b12 * a20;
|
|
1154
|
-
out[4] = b10 * a01 + b11 * a11 + b12 * a21;
|
|
1155
|
-
out[5] = b10 * a02 + b11 * a12 + b12 * a22;
|
|
1156
|
-
out[6] = b20 * a00 + b21 * a10 + b22 * a20;
|
|
1157
|
-
out[7] = b20 * a01 + b21 * a11 + b22 * a21;
|
|
1158
|
-
out[8] = b20 * a02 + b21 * a12 + b22 * a22;
|
|
1159
|
-
return out;
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Creates a matrix from a vector translation
|
|
1163
|
-
* This is equivalent to (but much faster than):
|
|
1164
|
-
*
|
|
1165
|
-
* mat3.identity(dest);
|
|
1166
|
-
* mat3.translate(dest, dest, vec);
|
|
1167
|
-
*
|
|
1168
|
-
* @param {mat3} out mat3 receiving operation result
|
|
1169
|
-
* @param {ReadonlyVec2} v Translation vector
|
|
1170
|
-
* @returns {mat3} out
|
|
1171
|
-
*/
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
function fromTranslation(out, v) {
|
|
1175
|
-
out[0] = 1;
|
|
1176
|
-
out[1] = 0;
|
|
1177
|
-
out[2] = 0;
|
|
1178
|
-
out[3] = 0;
|
|
1179
|
-
out[4] = 1;
|
|
1180
|
-
out[5] = 0;
|
|
1181
|
-
out[6] = v[0];
|
|
1182
|
-
out[7] = v[1];
|
|
1183
|
-
out[8] = 1;
|
|
1184
|
-
return out;
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Creates a matrix from a given angle
|
|
1188
|
-
* This is equivalent to (but much faster than):
|
|
1189
|
-
*
|
|
1190
|
-
* mat3.identity(dest);
|
|
1191
|
-
* mat3.rotate(dest, dest, rad);
|
|
1192
|
-
*
|
|
1193
|
-
* @param {mat3} out mat3 receiving operation result
|
|
1194
|
-
* @param {Number} rad the angle to rotate the matrix by
|
|
1195
|
-
* @returns {mat3} out
|
|
1196
|
-
*/
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
function fromRotation(out, rad) {
|
|
1200
|
-
var s = Math.sin(rad),
|
|
1201
|
-
c = Math.cos(rad);
|
|
1202
|
-
out[0] = c;
|
|
1203
|
-
out[1] = s;
|
|
1204
|
-
out[2] = 0;
|
|
1205
|
-
out[3] = -s;
|
|
1206
|
-
out[4] = c;
|
|
1207
|
-
out[5] = 0;
|
|
1208
|
-
out[6] = 0;
|
|
1209
|
-
out[7] = 0;
|
|
1210
|
-
out[8] = 1;
|
|
1211
|
-
return out;
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Creates a matrix from a vector scaling
|
|
1215
|
-
* This is equivalent to (but much faster than):
|
|
1216
|
-
*
|
|
1217
|
-
* mat3.identity(dest);
|
|
1218
|
-
* mat3.scale(dest, dest, vec);
|
|
1219
|
-
*
|
|
1220
|
-
* @param {mat3} out mat3 receiving operation result
|
|
1221
|
-
* @param {ReadonlyVec2} v Scaling vector
|
|
1222
|
-
* @returns {mat3} out
|
|
1223
|
-
*/
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
function fromScaling(out, v) {
|
|
1227
|
-
out[0] = v[0];
|
|
1228
|
-
out[1] = 0;
|
|
1229
|
-
out[2] = 0;
|
|
1230
|
-
out[3] = 0;
|
|
1231
|
-
out[4] = v[1];
|
|
1232
|
-
out[5] = 0;
|
|
1233
|
-
out[6] = 0;
|
|
1234
|
-
out[7] = 0;
|
|
1235
|
-
out[8] = 1;
|
|
1236
|
-
return out;
|
|
1237
|
-
}
|
|
1238
1093
|
/**
|
|
1239
1094
|
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
|
|
1240
1095
|
* @module mat4
|
|
@@ -1246,8 +1101,7 @@
|
|
|
1246
1101
|
* @returns {mat4} a new 4x4 matrix
|
|
1247
1102
|
*/
|
|
1248
1103
|
|
|
1249
|
-
|
|
1250
|
-
function create$1() {
|
|
1104
|
+
function create() {
|
|
1251
1105
|
var out = new ARRAY_TYPE(16);
|
|
1252
1106
|
|
|
1253
1107
|
if (ARRAY_TYPE != Float32Array) {
|
|
@@ -1345,7 +1199,7 @@
|
|
|
1345
1199
|
*/
|
|
1346
1200
|
|
|
1347
1201
|
|
|
1348
|
-
function multiply
|
|
1202
|
+
function multiply(out, a, b) {
|
|
1349
1203
|
var a00 = a[0],
|
|
1350
1204
|
a01 = a[1],
|
|
1351
1205
|
a02 = a[2],
|
|
@@ -1409,7 +1263,7 @@
|
|
|
1409
1263
|
*/
|
|
1410
1264
|
|
|
1411
1265
|
|
|
1412
|
-
function create$
|
|
1266
|
+
function create$1() {
|
|
1413
1267
|
var out = new ARRAY_TYPE(3);
|
|
1414
1268
|
|
|
1415
1269
|
if (ARRAY_TYPE != Float32Array) {
|
|
@@ -1474,7 +1328,7 @@
|
|
|
1474
1328
|
|
|
1475
1329
|
|
|
1476
1330
|
var forEach = function () {
|
|
1477
|
-
var vec = create$
|
|
1331
|
+
var vec = create$1();
|
|
1478
1332
|
return function (a, stride, offset, count, fn, arg) {
|
|
1479
1333
|
var i, l;
|
|
1480
1334
|
|
|
@@ -1517,7 +1371,7 @@
|
|
|
1517
1371
|
*/
|
|
1518
1372
|
|
|
1519
1373
|
|
|
1520
|
-
function create$
|
|
1374
|
+
function create$2() {
|
|
1521
1375
|
var out = new ARRAY_TYPE(2);
|
|
1522
1376
|
|
|
1523
1377
|
if (ARRAY_TYPE != Float32Array) {
|
|
@@ -1527,21 +1381,6 @@
|
|
|
1527
1381
|
|
|
1528
1382
|
return out;
|
|
1529
1383
|
}
|
|
1530
|
-
/**
|
|
1531
|
-
* Creates a new vec2 initialized with the given values
|
|
1532
|
-
*
|
|
1533
|
-
* @param {Number} x X component
|
|
1534
|
-
* @param {Number} y Y component
|
|
1535
|
-
* @returns {vec2} a new 2D vector
|
|
1536
|
-
*/
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
function fromValues$1(x, y) {
|
|
1540
|
-
var out = new ARRAY_TYPE(2);
|
|
1541
|
-
out[0] = x;
|
|
1542
|
-
out[1] = y;
|
|
1543
|
-
return out;
|
|
1544
|
-
}
|
|
1545
1384
|
/**
|
|
1546
1385
|
* Normalize a vec2
|
|
1547
1386
|
*
|
|
@@ -1577,24 +1416,6 @@
|
|
|
1577
1416
|
function dot(a, b) {
|
|
1578
1417
|
return a[0] * b[0] + a[1] * b[1];
|
|
1579
1418
|
}
|
|
1580
|
-
/**
|
|
1581
|
-
* Transforms the vec2 with a mat3
|
|
1582
|
-
* 3rd vector component is implicitly '1'
|
|
1583
|
-
*
|
|
1584
|
-
* @param {vec2} out the receiving vector
|
|
1585
|
-
* @param {ReadonlyVec2} a the vector to transform
|
|
1586
|
-
* @param {ReadonlyMat3} m matrix to transform with
|
|
1587
|
-
* @returns {vec2} out
|
|
1588
|
-
*/
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
function transformMat3(out, a, m) {
|
|
1592
|
-
var x = a[0],
|
|
1593
|
-
y = a[1];
|
|
1594
|
-
out[0] = m[0] * x + m[3] * y + m[6];
|
|
1595
|
-
out[1] = m[1] * x + m[4] * y + m[7];
|
|
1596
|
-
return out;
|
|
1597
|
-
}
|
|
1598
1419
|
/**
|
|
1599
1420
|
* Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
|
|
1600
1421
|
*
|
|
@@ -1622,7 +1443,7 @@
|
|
|
1622
1443
|
|
|
1623
1444
|
|
|
1624
1445
|
var forEach$1 = function () {
|
|
1625
|
-
var vec = create$
|
|
1446
|
+
var vec = create$2();
|
|
1626
1447
|
return function (a, stride, offset, count, fn, arg) {
|
|
1627
1448
|
var i, l;
|
|
1628
1449
|
|
|
@@ -1681,9 +1502,9 @@
|
|
|
1681
1502
|
|
|
1682
1503
|
if (pick) {
|
|
1683
1504
|
// invert with world matrix
|
|
1684
|
-
var invertWorldMat = invert(create
|
|
1505
|
+
var invertWorldMat = invert(create(), worldTransform); // transform client position to local space, do picking in local space
|
|
1685
1506
|
|
|
1686
|
-
var localPosition = transformMat4(create$
|
|
1507
|
+
var localPosition = transformMat4(create$1(), fromValues(position[0], position[1], 0), invertWorldMat); // account for anchor
|
|
1687
1508
|
|
|
1688
1509
|
var _displayObject$getGeo = displayObject.getGeometryBounds(),
|
|
1689
1510
|
halfExtents = _displayObject$getGeo.halfExtents;
|
|
@@ -1710,7 +1531,9 @@
|
|
|
1710
1531
|
var generatePath = _this.pathGeneratorFactoryCache[displayObject.nodeName];
|
|
1711
1532
|
|
|
1712
1533
|
if (generatePath) {
|
|
1534
|
+
context.beginPath();
|
|
1713
1535
|
generatePath(context, displayObject.parsedStyle);
|
|
1536
|
+
context.closePath();
|
|
1714
1537
|
}
|
|
1715
1538
|
|
|
1716
1539
|
return context.isPointInPath(position.x, position.y);
|
|
@@ -1724,7 +1547,7 @@
|
|
|
1724
1547
|
|
|
1725
1548
|
renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
|
|
1726
1549
|
var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
|
|
1727
|
-
var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject,
|
|
1550
|
+
var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject, worldTransform, isHitOriginShape, clipPath, isHitClipPath;
|
|
1728
1551
|
|
|
1729
1552
|
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
1730
1553
|
while (1) {
|
|
@@ -1761,52 +1584,79 @@
|
|
|
1761
1584
|
|
|
1762
1585
|
hitTestList.sort(function (a, b) {
|
|
1763
1586
|
return b.sortable.renderOrder - a.sortable.renderOrder;
|
|
1764
|
-
});
|
|
1587
|
+
}); // test with clip path & origin shape
|
|
1588
|
+
// @see https://github.com/antvis/g/issues/1064
|
|
1589
|
+
|
|
1765
1590
|
pickedDisplayObjects = [];
|
|
1766
1591
|
_i = 0, _hitTestList = hitTestList;
|
|
1767
1592
|
|
|
1768
1593
|
case 9:
|
|
1769
1594
|
if (!(_i < _hitTestList.length)) {
|
|
1770
|
-
_context.next =
|
|
1595
|
+
_context.next = 36;
|
|
1771
1596
|
break;
|
|
1772
1597
|
}
|
|
1773
1598
|
|
|
1774
|
-
displayObject = _hitTestList[_i];
|
|
1599
|
+
displayObject = _hitTestList[_i];
|
|
1600
|
+
worldTransform = displayObject.getWorldTransform();
|
|
1601
|
+
isHitOriginShape = _this2.isHit(displayObject, position, worldTransform);
|
|
1602
|
+
|
|
1603
|
+
if (!isHitOriginShape) {
|
|
1604
|
+
_context.next = 33;
|
|
1605
|
+
break;
|
|
1606
|
+
}
|
|
1775
1607
|
|
|
1776
1608
|
clipPath = displayObject.parsedStyle.clipPath;
|
|
1777
|
-
objectToTest = clipPath || displayObject;
|
|
1778
|
-
worldTransform = displayObject.getWorldTransform(); // clipped's world matrix * clipPath's local matrix
|
|
1779
1609
|
|
|
1780
|
-
if (clipPath) {
|
|
1781
|
-
|
|
1610
|
+
if (!clipPath) {
|
|
1611
|
+
_context.next = 27;
|
|
1612
|
+
break;
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
worldTransform = multiply(create(), worldTransform, clipPath.getLocalTransform());
|
|
1616
|
+
isHitClipPath = _this2.isHit(clipPath, position, worldTransform);
|
|
1617
|
+
|
|
1618
|
+
if (!isHitClipPath) {
|
|
1619
|
+
_context.next = 25;
|
|
1620
|
+
break;
|
|
1782
1621
|
}
|
|
1783
1622
|
|
|
1784
|
-
if (!
|
|
1785
|
-
_context.next =
|
|
1623
|
+
if (!topmost) {
|
|
1624
|
+
_context.next = 24;
|
|
1786
1625
|
break;
|
|
1787
1626
|
}
|
|
1788
1627
|
|
|
1628
|
+
result.picked = [displayObject];
|
|
1629
|
+
return _context.abrupt("return", result);
|
|
1630
|
+
|
|
1631
|
+
case 24:
|
|
1632
|
+
pickedDisplayObjects.push(displayObject);
|
|
1633
|
+
|
|
1634
|
+
case 25:
|
|
1635
|
+
_context.next = 33;
|
|
1636
|
+
break;
|
|
1637
|
+
|
|
1638
|
+
case 27:
|
|
1789
1639
|
if (!topmost) {
|
|
1790
|
-
_context.next =
|
|
1640
|
+
_context.next = 32;
|
|
1791
1641
|
break;
|
|
1792
1642
|
}
|
|
1793
1643
|
|
|
1794
1644
|
result.picked = [displayObject];
|
|
1795
1645
|
return _context.abrupt("return", result);
|
|
1796
1646
|
|
|
1797
|
-
case
|
|
1647
|
+
case 32:
|
|
1798
1648
|
pickedDisplayObjects.push(displayObject);
|
|
1799
1649
|
|
|
1800
|
-
case
|
|
1650
|
+
case 33:
|
|
1801
1651
|
_i++;
|
|
1802
1652
|
_context.next = 9;
|
|
1803
1653
|
break;
|
|
1804
1654
|
|
|
1805
|
-
case
|
|
1655
|
+
case 36:
|
|
1806
1656
|
result.picked = pickedDisplayObjects;
|
|
1807
1657
|
return _context.abrupt("return", result);
|
|
1808
1658
|
|
|
1809
|
-
case
|
|
1659
|
+
case 38:
|
|
1810
1660
|
case "end":
|
|
1811
1661
|
return _context.stop();
|
|
1812
1662
|
}
|
|
@@ -2080,104 +1930,6 @@
|
|
|
2080
1930
|
return totalLength / 2;
|
|
2081
1931
|
}
|
|
2082
1932
|
|
|
2083
|
-
function quadraticAt(p0, p1, p2, t) {
|
|
2084
|
-
var onet = 1 - t;
|
|
2085
|
-
return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
|
|
2086
|
-
} // 求极值
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
function extrema(p0, p1, p2) {
|
|
2090
|
-
var a = p0 + p2 - 2 * p1;
|
|
2091
|
-
|
|
2092
|
-
if (isNumberEqual(a, 0)) {
|
|
2093
|
-
return [0.5];
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
var rst = (p0 - p1) / a;
|
|
2097
|
-
|
|
2098
|
-
if (rst <= 1 && rst >= 0) {
|
|
2099
|
-
return [rst];
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
|
-
return [];
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
|
-
function derivativeAt(p0, p1, p2, t) {
|
|
2106
|
-
return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
|
|
2107
|
-
} // 分割贝塞尔曲线
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
|
|
2111
|
-
// 划分点
|
|
2112
|
-
var xt = quadraticAt(x1, x2, x3, t);
|
|
2113
|
-
var yt = quadraticAt(y1, y2, y3, t); // 分割的第一条曲线的控制点
|
|
2114
|
-
|
|
2115
|
-
var controlPoint1 = line.pointAt(x1, y1, x2, y2, t); // 分割的第二条曲线的控制点
|
|
2116
|
-
|
|
2117
|
-
var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
|
|
2118
|
-
return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
|
|
2119
|
-
} // 使用迭代法取贝塞尔曲线的长度
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
|
|
2123
|
-
if (iterationCount === 0) {
|
|
2124
|
-
return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
|
|
2128
|
-
var left = quadratics[0];
|
|
2129
|
-
var right = quadratics[1];
|
|
2130
|
-
left.push(iterationCount - 1);
|
|
2131
|
-
right.push(iterationCount - 1);
|
|
2132
|
-
return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
var quadratic = {
|
|
2136
|
-
box: function box(x1, y1, x2, y2, x3, y3) {
|
|
2137
|
-
var xExtrema = extrema(x1, x2, x3)[0];
|
|
2138
|
-
var yExtrema = extrema(y1, y2, y3)[0]; // 控制点不加入 box 的计算
|
|
2139
|
-
|
|
2140
|
-
var xArr = [x1, x3];
|
|
2141
|
-
var yArr = [y1, y3];
|
|
2142
|
-
|
|
2143
|
-
if (xExtrema !== undefined) {
|
|
2144
|
-
xArr.push(quadraticAt(x1, x2, x3, xExtrema));
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
if (yExtrema !== undefined) {
|
|
2148
|
-
yArr.push(quadraticAt(y1, y2, y3, yExtrema));
|
|
2149
|
-
}
|
|
2150
|
-
|
|
2151
|
-
return getBBoxByArray(xArr, yArr);
|
|
2152
|
-
},
|
|
2153
|
-
length: function length(x1, y1, x2, y2, x3, y3) {
|
|
2154
|
-
return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
|
|
2155
|
-
},
|
|
2156
|
-
nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
2157
|
-
return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
|
|
2158
|
-
},
|
|
2159
|
-
pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
|
|
2160
|
-
var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
|
|
2161
|
-
return distance(point.x, point.y, x0, y0);
|
|
2162
|
-
},
|
|
2163
|
-
interpolationAt: quadraticAt,
|
|
2164
|
-
pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
|
|
2165
|
-
return {
|
|
2166
|
-
x: quadraticAt(x1, x2, x3, t),
|
|
2167
|
-
y: quadraticAt(y1, y2, y3, t)
|
|
2168
|
-
};
|
|
2169
|
-
},
|
|
2170
|
-
divide: function divide(x1, y1, x2, y2, x3, y3, t) {
|
|
2171
|
-
return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
|
|
2172
|
-
},
|
|
2173
|
-
tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
|
|
2174
|
-
var dx = derivativeAt(x1, x2, x3, t);
|
|
2175
|
-
var dy = derivativeAt(y1, y2, y3, t);
|
|
2176
|
-
var angle = Math.atan2(dy, dx);
|
|
2177
|
-
return piMod(angle);
|
|
2178
|
-
}
|
|
2179
|
-
};
|
|
2180
|
-
|
|
2181
1933
|
function cubicAt(p0, p1, p2, p3, t) {
|
|
2182
1934
|
var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
|
|
2183
1935
|
|
|
@@ -2454,7 +2206,7 @@
|
|
|
2454
2206
|
increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
|
|
2455
2207
|
clipPathTargets = _displayObject$parsed.clipPathTargets;
|
|
2456
2208
|
var r = rInPixels.value;
|
|
2457
|
-
var halfLineWidth = ((lineWidth
|
|
2209
|
+
var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2;
|
|
2458
2210
|
var absDistance = distance$1(r, r, position.x, position.y);
|
|
2459
2211
|
var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
|
|
2460
2212
|
var hasFill = fill && !fill.isNone;
|
|
@@ -2495,7 +2247,7 @@
|
|
|
2495
2247
|
var hasStroke = stroke && !stroke.isNone;
|
|
2496
2248
|
var rx = rxInPixels.value;
|
|
2497
2249
|
var ry = ryInPixels.value;
|
|
2498
|
-
var halfLineWith = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + increasedLineWidthForHitTesting.value) / 2;
|
|
2250
|
+
var halfLineWith = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0)) / 2;
|
|
2499
2251
|
var squareX = (x - rx) * (x - rx);
|
|
2500
2252
|
var squareY = (y - ry) * (y - ry); // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
|
|
2501
2253
|
|
|
@@ -2526,23 +2278,17 @@
|
|
|
2526
2278
|
x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
|
|
2527
2279
|
_displayObject$parsed3 = _displayObject$parsed.defY,
|
|
2528
2280
|
y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3;
|
|
2529
|
-
return inLine(x1.value, y1.value, x2.value, y2.value, lineWidth.value + increasedLineWidthForHitTesting.value, position.x + x, position.y + y);
|
|
2281
|
+
return inLine(x1.value, y1.value, x2.value, y2.value, ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0), position.x + x, position.y + y);
|
|
2530
2282
|
}
|
|
2531
2283
|
|
|
2532
2284
|
function isPointInStroke(segments, lineWidth, px, py, length, x, y) {
|
|
2533
2285
|
var isHit = false;
|
|
2534
|
-
var halfWidth = lineWidth / 2;
|
|
2535
2286
|
|
|
2536
2287
|
for (var i = 0; i < segments.length; i++) {
|
|
2537
2288
|
var segment = segments[i];
|
|
2538
2289
|
var currentPoint = segment.currentPoint,
|
|
2539
2290
|
params = segment.params,
|
|
2540
|
-
prePoint = segment.prePoint
|
|
2541
|
-
box = segment.box; // 如果在前面已经生成过包围盒,直接按照包围盒计算
|
|
2542
|
-
|
|
2543
|
-
if (box && !inBox(box.x - halfWidth, box.y - halfWidth, box.width + lineWidth, box.height + lineWidth, px, py)) {
|
|
2544
|
-
continue;
|
|
2545
|
-
}
|
|
2291
|
+
prePoint = segment.prePoint;
|
|
2546
2292
|
|
|
2547
2293
|
switch (segment.command) {
|
|
2548
2294
|
// L 和 Z 都是直线, M 不进行拾取
|
|
@@ -2550,11 +2296,19 @@
|
|
|
2550
2296
|
case 'Z':
|
|
2551
2297
|
isHit = inLine(prePoint[0], prePoint[1], currentPoint[0], currentPoint[1], lineWidth, px, py);
|
|
2552
2298
|
break;
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2299
|
+
// case 'Q':
|
|
2300
|
+
// const qDistance = QuadUtil.pointDistance(
|
|
2301
|
+
// prePoint[0],
|
|
2302
|
+
// prePoint[1],
|
|
2303
|
+
// params[1],
|
|
2304
|
+
// params[2],
|
|
2305
|
+
// params[3],
|
|
2306
|
+
// params[4],
|
|
2307
|
+
// px,
|
|
2308
|
+
// py,
|
|
2309
|
+
// );
|
|
2310
|
+
// isHit = qDistance <= lineWidth / 2;
|
|
2311
|
+
// break;
|
|
2558
2312
|
|
|
2559
2313
|
case 'C':
|
|
2560
2314
|
var cDistance = cubic.pointDistance(prePoint[0], // 上一段结束位置, 即 C 的起始点
|
|
@@ -2562,36 +2316,6 @@
|
|
|
2562
2316
|
params[2], params[3], params[4], params[5], params[6], px, py, length);
|
|
2563
2317
|
isHit = cDistance <= lineWidth / 2;
|
|
2564
2318
|
break;
|
|
2565
|
-
|
|
2566
|
-
case 'A':
|
|
2567
|
-
// 计算点到椭圆圆弧的距离,暂时使用近似算法,后面可以改成切割法求最近距离
|
|
2568
|
-
var arcParams = segment.arcParams;
|
|
2569
|
-
var cx = arcParams.cx,
|
|
2570
|
-
cy = arcParams.cy,
|
|
2571
|
-
rx = arcParams.rx,
|
|
2572
|
-
ry = arcParams.ry,
|
|
2573
|
-
startAngle = arcParams.startAngle,
|
|
2574
|
-
endAngle = arcParams.endAngle,
|
|
2575
|
-
xRotation = arcParams.xRotation;
|
|
2576
|
-
var r = rx > ry ? rx : ry;
|
|
2577
|
-
var scaleX = rx > ry ? 1 : rx / ry;
|
|
2578
|
-
var scaleY = rx > ry ? ry / rx : 1; // const m = transform(null, [
|
|
2579
|
-
// ['t', -cx, -cy],
|
|
2580
|
-
// ['r', -xRotation],
|
|
2581
|
-
// ['s', 1 / scaleX, 1 / scaleY],
|
|
2582
|
-
// ]);
|
|
2583
|
-
// FIXME
|
|
2584
|
-
|
|
2585
|
-
var m = fromTranslation(create(), [-cx, -cy]);
|
|
2586
|
-
multiply(m, fromRotation(create(), -xRotation), m);
|
|
2587
|
-
multiply(m, fromScaling(create(), [1 / scaleX, 1 / scaleY]), m);
|
|
2588
|
-
var p = fromValues$1(px, py);
|
|
2589
|
-
p = transformMat3(p, p, m); // isHit = inArc(cx, cy, r, startAngle, endAngle, lineWidth, px, py);
|
|
2590
|
-
// console.log(m, p[0], px - cx);
|
|
2591
|
-
// isHit = inArc(cx, cy, r, startAngle, endAngle, lineWidth, px, py);
|
|
2592
|
-
|
|
2593
|
-
isHit = inArc(0, 0, r, startAngle, endAngle, lineWidth, p[0], p[1]);
|
|
2594
|
-
break;
|
|
2595
2319
|
}
|
|
2596
2320
|
|
|
2597
2321
|
if (isHit) {
|
|
@@ -2625,7 +2349,7 @@
|
|
|
2625
2349
|
var isHit = false;
|
|
2626
2350
|
|
|
2627
2351
|
if (hasStroke || isClipPath) {
|
|
2628
|
-
isHit = isPointInStroke(segments, lineWidth.value + increasedLineWidthForHitTesting.value, position.x + x, position.y + y, totalLength);
|
|
2352
|
+
isHit = isPointInStroke(segments, ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0), position.x + x, position.y + y, totalLength);
|
|
2629
2353
|
}
|
|
2630
2354
|
|
|
2631
2355
|
if (!isHit && (hasFill || isClipPath)) {
|
|
@@ -2659,7 +2383,7 @@
|
|
|
2659
2383
|
var isHit = false;
|
|
2660
2384
|
|
|
2661
2385
|
if (hasStroke || isClipPath) {
|
|
2662
|
-
isHit = inPolyline(points.points, lineWidth.value + increasedLineWidthForHitTesting.value, position.x + x, position.y + y, true);
|
|
2386
|
+
isHit = inPolyline(points.points, ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0), position.x + x, position.y + y, true);
|
|
2663
2387
|
}
|
|
2664
2388
|
|
|
2665
2389
|
if (!isHit && (hasFill || isClipPath)) {
|
|
@@ -2687,7 +2411,7 @@
|
|
|
2687
2411
|
return false;
|
|
2688
2412
|
}
|
|
2689
2413
|
|
|
2690
|
-
return inPolyline(points.points, lineWidth.value + increasedLineWidthForHitTesting.value, position.x + x, position.y + y, false);
|
|
2414
|
+
return inPolyline(points.points, ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0), position.x + x, position.y + y, false);
|
|
2691
2415
|
}
|
|
2692
2416
|
|
|
2693
2417
|
function isPointInPath$6(displayObject, position, isPointInPath) {
|
|
@@ -2721,7 +2445,7 @@
|
|
|
2721
2445
|
height = heightValue;
|
|
2722
2446
|
}
|
|
2723
2447
|
|
|
2724
|
-
var lineWidthForHitTesting = lineWidth.value + increasedLineWidthForHitTesting.value; // 无圆角时的策略
|
|
2448
|
+
var lineWidthForHitTesting = ((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + ((increasedLineWidthForHitTesting === null || increasedLineWidthForHitTesting === void 0 ? void 0 : increasedLineWidthForHitTesting.value) || 0); // 无圆角时的策略
|
|
2725
2449
|
|
|
2726
2450
|
if (!hasRadius) {
|
|
2727
2451
|
var halfWidth = lineWidthForHitTesting / 2; // 同时填充和带有边框
|
|
@@ -3905,10 +3629,8 @@
|
|
|
3905
3629
|
* Common utilities
|
|
3906
3630
|
* @module glMatrix
|
|
3907
3631
|
*/
|
|
3908
|
-
// Configuration Constants
|
|
3909
3632
|
|
|
3910
3633
|
|
|
3911
|
-
var EPSILON$1 = 0.000001;
|
|
3912
3634
|
var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
3913
3635
|
if (!Math.hypot) Math.hypot = function () {
|
|
3914
3636
|
var y = 0,
|
|
@@ -3920,34 +3642,6 @@
|
|
|
3920
3642
|
|
|
3921
3643
|
return Math.sqrt(y);
|
|
3922
3644
|
};
|
|
3923
|
-
/**
|
|
3924
|
-
* 3x3 Matrix
|
|
3925
|
-
* @module mat3
|
|
3926
|
-
*/
|
|
3927
|
-
|
|
3928
|
-
/**
|
|
3929
|
-
* Creates a new identity mat3
|
|
3930
|
-
*
|
|
3931
|
-
* @returns {mat3} a new 3x3 matrix
|
|
3932
|
-
*/
|
|
3933
|
-
|
|
3934
|
-
function create$4() {
|
|
3935
|
-
var out = new ARRAY_TYPE$1(9);
|
|
3936
|
-
|
|
3937
|
-
if (ARRAY_TYPE$1 != Float32Array) {
|
|
3938
|
-
out[1] = 0;
|
|
3939
|
-
out[2] = 0;
|
|
3940
|
-
out[3] = 0;
|
|
3941
|
-
out[5] = 0;
|
|
3942
|
-
out[6] = 0;
|
|
3943
|
-
out[7] = 0;
|
|
3944
|
-
}
|
|
3945
|
-
|
|
3946
|
-
out[0] = 1;
|
|
3947
|
-
out[4] = 1;
|
|
3948
|
-
out[8] = 1;
|
|
3949
|
-
return out;
|
|
3950
|
-
}
|
|
3951
3645
|
/**
|
|
3952
3646
|
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
|
|
3953
3647
|
* @module mat4
|
|
@@ -3959,8 +3653,7 @@
|
|
|
3959
3653
|
* @returns {mat4} a new 4x4 matrix
|
|
3960
3654
|
*/
|
|
3961
3655
|
|
|
3962
|
-
|
|
3963
|
-
function create$1$1() {
|
|
3656
|
+
function create$3() {
|
|
3964
3657
|
var out = new ARRAY_TYPE$1(16);
|
|
3965
3658
|
|
|
3966
3659
|
if (ARRAY_TYPE$1 != Float32Array) {
|
|
@@ -3985,328 +3678,230 @@
|
|
|
3985
3678
|
return out;
|
|
3986
3679
|
}
|
|
3987
3680
|
/**
|
|
3988
|
-
*
|
|
3989
|
-
* matrix. If a matrix is built with fromRotationTranslation,
|
|
3990
|
-
* the returned vector will be the same as the translation vector
|
|
3991
|
-
* originally supplied.
|
|
3992
|
-
* @param {vec3} out Vector to receive translation component
|
|
3993
|
-
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
3994
|
-
* @return {vec3} out
|
|
3995
|
-
*/
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
function getTranslation(out, mat) {
|
|
3999
|
-
out[0] = mat[12];
|
|
4000
|
-
out[1] = mat[13];
|
|
4001
|
-
out[2] = mat[14];
|
|
4002
|
-
return out;
|
|
4003
|
-
}
|
|
4004
|
-
/**
|
|
4005
|
-
* Returns the scaling factor component of a transformation
|
|
4006
|
-
* matrix. If a matrix is built with fromRotationTranslationScale
|
|
4007
|
-
* with a normalized Quaternion paramter, the returned vector will be
|
|
4008
|
-
* the same as the scaling vector
|
|
4009
|
-
* originally supplied.
|
|
4010
|
-
* @param {vec3} out Vector to receive scaling factor component
|
|
4011
|
-
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
4012
|
-
* @return {vec3} out
|
|
4013
|
-
*/
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
function getScaling(out, mat) {
|
|
4017
|
-
var m11 = mat[0];
|
|
4018
|
-
var m12 = mat[1];
|
|
4019
|
-
var m13 = mat[2];
|
|
4020
|
-
var m21 = mat[4];
|
|
4021
|
-
var m22 = mat[5];
|
|
4022
|
-
var m23 = mat[6];
|
|
4023
|
-
var m31 = mat[8];
|
|
4024
|
-
var m32 = mat[9];
|
|
4025
|
-
var m33 = mat[10];
|
|
4026
|
-
out[0] = Math.hypot(m11, m12, m13);
|
|
4027
|
-
out[1] = Math.hypot(m21, m22, m23);
|
|
4028
|
-
out[2] = Math.hypot(m31, m32, m33);
|
|
4029
|
-
return out;
|
|
4030
|
-
}
|
|
4031
|
-
/**
|
|
4032
|
-
* Returns a quaternion representing the rotational component
|
|
4033
|
-
* of a transformation matrix. If a matrix is built with
|
|
4034
|
-
* fromRotationTranslation, the returned quaternion will be the
|
|
4035
|
-
* same as the quaternion originally supplied.
|
|
4036
|
-
* @param {quat} out Quaternion to receive the rotation component
|
|
4037
|
-
* @param {ReadonlyMat4} mat Matrix to be decomposed (input)
|
|
4038
|
-
* @return {quat} out
|
|
4039
|
-
*/
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
function getRotation(out, mat) {
|
|
4043
|
-
var scaling = new ARRAY_TYPE$1(3);
|
|
4044
|
-
getScaling(scaling, mat);
|
|
4045
|
-
var is1 = 1 / scaling[0];
|
|
4046
|
-
var is2 = 1 / scaling[1];
|
|
4047
|
-
var is3 = 1 / scaling[2];
|
|
4048
|
-
var sm11 = mat[0] * is1;
|
|
4049
|
-
var sm12 = mat[1] * is2;
|
|
4050
|
-
var sm13 = mat[2] * is3;
|
|
4051
|
-
var sm21 = mat[4] * is1;
|
|
4052
|
-
var sm22 = mat[5] * is2;
|
|
4053
|
-
var sm23 = mat[6] * is3;
|
|
4054
|
-
var sm31 = mat[8] * is1;
|
|
4055
|
-
var sm32 = mat[9] * is2;
|
|
4056
|
-
var sm33 = mat[10] * is3;
|
|
4057
|
-
var trace = sm11 + sm22 + sm33;
|
|
4058
|
-
var S = 0;
|
|
4059
|
-
|
|
4060
|
-
if (trace > 0) {
|
|
4061
|
-
S = Math.sqrt(trace + 1.0) * 2;
|
|
4062
|
-
out[3] = 0.25 * S;
|
|
4063
|
-
out[0] = (sm23 - sm32) / S;
|
|
4064
|
-
out[1] = (sm31 - sm13) / S;
|
|
4065
|
-
out[2] = (sm12 - sm21) / S;
|
|
4066
|
-
} else if (sm11 > sm22 && sm11 > sm33) {
|
|
4067
|
-
S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
|
|
4068
|
-
out[3] = (sm23 - sm32) / S;
|
|
4069
|
-
out[0] = 0.25 * S;
|
|
4070
|
-
out[1] = (sm12 + sm21) / S;
|
|
4071
|
-
out[2] = (sm31 + sm13) / S;
|
|
4072
|
-
} else if (sm22 > sm33) {
|
|
4073
|
-
S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
|
|
4074
|
-
out[3] = (sm31 - sm13) / S;
|
|
4075
|
-
out[0] = (sm12 + sm21) / S;
|
|
4076
|
-
out[1] = 0.25 * S;
|
|
4077
|
-
out[2] = (sm23 + sm32) / S;
|
|
4078
|
-
} else {
|
|
4079
|
-
S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
|
|
4080
|
-
out[3] = (sm12 - sm21) / S;
|
|
4081
|
-
out[0] = (sm31 + sm13) / S;
|
|
4082
|
-
out[1] = (sm23 + sm32) / S;
|
|
4083
|
-
out[2] = 0.25 * S;
|
|
4084
|
-
}
|
|
4085
|
-
|
|
4086
|
-
return out;
|
|
4087
|
-
}
|
|
4088
|
-
/**
|
|
4089
|
-
* 3 Dimensional Vector
|
|
4090
|
-
* @module vec3
|
|
4091
|
-
*/
|
|
4092
|
-
|
|
4093
|
-
/**
|
|
4094
|
-
* Creates a new, empty vec3
|
|
3681
|
+
* Copy the values from one mat4 to another
|
|
4095
3682
|
*
|
|
4096
|
-
* @
|
|
3683
|
+
* @param {mat4} out the receiving matrix
|
|
3684
|
+
* @param {ReadonlyMat4} a the source matrix
|
|
3685
|
+
* @returns {mat4} out
|
|
4097
3686
|
*/
|
|
4098
3687
|
|
|
4099
3688
|
|
|
4100
|
-
function
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
3689
|
+
function copy(out, a) {
|
|
3690
|
+
out[0] = a[0];
|
|
3691
|
+
out[1] = a[1];
|
|
3692
|
+
out[2] = a[2];
|
|
3693
|
+
out[3] = a[3];
|
|
3694
|
+
out[4] = a[4];
|
|
3695
|
+
out[5] = a[5];
|
|
3696
|
+
out[6] = a[6];
|
|
3697
|
+
out[7] = a[7];
|
|
3698
|
+
out[8] = a[8];
|
|
3699
|
+
out[9] = a[9];
|
|
3700
|
+
out[10] = a[10];
|
|
3701
|
+
out[11] = a[11];
|
|
3702
|
+
out[12] = a[12];
|
|
3703
|
+
out[13] = a[13];
|
|
3704
|
+
out[14] = a[14];
|
|
3705
|
+
out[15] = a[15];
|
|
4109
3706
|
return out;
|
|
4110
3707
|
}
|
|
4111
3708
|
/**
|
|
4112
|
-
*
|
|
3709
|
+
* Multiplies two mat4s
|
|
4113
3710
|
*
|
|
4114
|
-
* @param {
|
|
4115
|
-
* @
|
|
3711
|
+
* @param {mat4} out the receiving matrix
|
|
3712
|
+
* @param {ReadonlyMat4} a the first operand
|
|
3713
|
+
* @param {ReadonlyMat4} b the second operand
|
|
3714
|
+
* @returns {mat4} out
|
|
4116
3715
|
*/
|
|
4117
3716
|
|
|
4118
3717
|
|
|
4119
|
-
function
|
|
4120
|
-
var
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
3718
|
+
function multiply$1(out, a, b) {
|
|
3719
|
+
var a00 = a[0],
|
|
3720
|
+
a01 = a[1],
|
|
3721
|
+
a02 = a[2],
|
|
3722
|
+
a03 = a[3];
|
|
3723
|
+
var a10 = a[4],
|
|
3724
|
+
a11 = a[5],
|
|
3725
|
+
a12 = a[6],
|
|
3726
|
+
a13 = a[7];
|
|
3727
|
+
var a20 = a[8],
|
|
3728
|
+
a21 = a[9],
|
|
3729
|
+
a22 = a[10],
|
|
3730
|
+
a23 = a[11];
|
|
3731
|
+
var a30 = a[12],
|
|
3732
|
+
a31 = a[13],
|
|
3733
|
+
a32 = a[14],
|
|
3734
|
+
a33 = a[15]; // Cache only the current line of the second matrix
|
|
4134
3735
|
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
out[
|
|
3736
|
+
var b0 = b[0],
|
|
3737
|
+
b1 = b[1],
|
|
3738
|
+
b2 = b[2],
|
|
3739
|
+
b3 = b[3];
|
|
3740
|
+
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
3741
|
+
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
3742
|
+
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
3743
|
+
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
3744
|
+
b0 = b[4];
|
|
3745
|
+
b1 = b[5];
|
|
3746
|
+
b2 = b[6];
|
|
3747
|
+
b3 = b[7];
|
|
3748
|
+
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
3749
|
+
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
3750
|
+
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
3751
|
+
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
3752
|
+
b0 = b[8];
|
|
3753
|
+
b1 = b[9];
|
|
3754
|
+
b2 = b[10];
|
|
3755
|
+
b3 = b[11];
|
|
3756
|
+
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
3757
|
+
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
3758
|
+
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
3759
|
+
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
3760
|
+
b0 = b[12];
|
|
3761
|
+
b1 = b[13];
|
|
3762
|
+
b2 = b[14];
|
|
3763
|
+
b3 = b[15];
|
|
3764
|
+
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
3765
|
+
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
3766
|
+
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
3767
|
+
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
4140
3768
|
return out;
|
|
4141
3769
|
}
|
|
4142
3770
|
/**
|
|
4143
|
-
*
|
|
3771
|
+
* Translate a mat4 by the given vector
|
|
4144
3772
|
*
|
|
4145
|
-
* @param {
|
|
4146
|
-
* @param {
|
|
4147
|
-
* @
|
|
3773
|
+
* @param {mat4} out the receiving matrix
|
|
3774
|
+
* @param {ReadonlyMat4} a the matrix to translate
|
|
3775
|
+
* @param {ReadonlyVec3} v vector to translate by
|
|
3776
|
+
* @returns {mat4} out
|
|
4148
3777
|
*/
|
|
4149
3778
|
|
|
4150
3779
|
|
|
4151
|
-
function
|
|
4152
|
-
var x =
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
var
|
|
3780
|
+
function translate(out, a, v) {
|
|
3781
|
+
var x = v[0],
|
|
3782
|
+
y = v[1],
|
|
3783
|
+
z = v[2];
|
|
3784
|
+
var a00, a01, a02, a03;
|
|
3785
|
+
var a10, a11, a12, a13;
|
|
3786
|
+
var a20, a21, a22, a23;
|
|
4156
3787
|
|
|
4157
|
-
if (
|
|
4158
|
-
|
|
4159
|
-
|
|
3788
|
+
if (a === out) {
|
|
3789
|
+
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
|
|
3790
|
+
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
|
|
3791
|
+
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
|
|
3792
|
+
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
|
|
3793
|
+
} else {
|
|
3794
|
+
a00 = a[0];
|
|
3795
|
+
a01 = a[1];
|
|
3796
|
+
a02 = a[2];
|
|
3797
|
+
a03 = a[3];
|
|
3798
|
+
a10 = a[4];
|
|
3799
|
+
a11 = a[5];
|
|
3800
|
+
a12 = a[6];
|
|
3801
|
+
a13 = a[7];
|
|
3802
|
+
a20 = a[8];
|
|
3803
|
+
a21 = a[9];
|
|
3804
|
+
a22 = a[10];
|
|
3805
|
+
a23 = a[11];
|
|
3806
|
+
out[0] = a00;
|
|
3807
|
+
out[1] = a01;
|
|
3808
|
+
out[2] = a02;
|
|
3809
|
+
out[3] = a03;
|
|
3810
|
+
out[4] = a10;
|
|
3811
|
+
out[5] = a11;
|
|
3812
|
+
out[6] = a12;
|
|
3813
|
+
out[7] = a13;
|
|
3814
|
+
out[8] = a20;
|
|
3815
|
+
out[9] = a21;
|
|
3816
|
+
out[10] = a22;
|
|
3817
|
+
out[11] = a23;
|
|
3818
|
+
out[12] = a00 * x + a10 * y + a20 * z + a[12];
|
|
3819
|
+
out[13] = a01 * x + a11 * y + a21 * z + a[13];
|
|
3820
|
+
out[14] = a02 * x + a12 * y + a22 * z + a[14];
|
|
3821
|
+
out[15] = a03 * x + a13 * y + a23 * z + a[15];
|
|
4160
3822
|
}
|
|
4161
3823
|
|
|
4162
|
-
out[0] = a[0] * len;
|
|
4163
|
-
out[1] = a[1] * len;
|
|
4164
|
-
out[2] = a[2] * len;
|
|
4165
3824
|
return out;
|
|
4166
3825
|
}
|
|
4167
3826
|
/**
|
|
4168
|
-
*
|
|
3827
|
+
* Creates a matrix from a vector scaling
|
|
3828
|
+
* This is equivalent to (but much faster than):
|
|
4169
3829
|
*
|
|
4170
|
-
*
|
|
4171
|
-
*
|
|
4172
|
-
* @returns {Number} dot product of a and b
|
|
4173
|
-
*/
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
function dot$1(a, b) {
|
|
4177
|
-
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
4178
|
-
}
|
|
4179
|
-
/**
|
|
4180
|
-
* Computes the cross product of two vec3's
|
|
3830
|
+
* mat4.identity(dest);
|
|
3831
|
+
* mat4.scale(dest, dest, vec);
|
|
4181
3832
|
*
|
|
4182
|
-
* @param {
|
|
4183
|
-
* @param {ReadonlyVec3}
|
|
4184
|
-
* @
|
|
4185
|
-
* @returns {vec3} out
|
|
3833
|
+
* @param {mat4} out mat4 receiving operation result
|
|
3834
|
+
* @param {ReadonlyVec3} v Scaling vector
|
|
3835
|
+
* @returns {mat4} out
|
|
4186
3836
|
*/
|
|
4187
3837
|
|
|
4188
3838
|
|
|
4189
|
-
function
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
out[
|
|
4197
|
-
out[
|
|
4198
|
-
out[
|
|
3839
|
+
function fromScaling(out, v) {
|
|
3840
|
+
out[0] = v[0];
|
|
3841
|
+
out[1] = 0;
|
|
3842
|
+
out[2] = 0;
|
|
3843
|
+
out[3] = 0;
|
|
3844
|
+
out[4] = 0;
|
|
3845
|
+
out[5] = v[1];
|
|
3846
|
+
out[6] = 0;
|
|
3847
|
+
out[7] = 0;
|
|
3848
|
+
out[8] = 0;
|
|
3849
|
+
out[9] = 0;
|
|
3850
|
+
out[10] = v[2];
|
|
3851
|
+
out[11] = 0;
|
|
3852
|
+
out[12] = 0;
|
|
3853
|
+
out[13] = 0;
|
|
3854
|
+
out[14] = 0;
|
|
3855
|
+
out[15] = 1;
|
|
4199
3856
|
return out;
|
|
4200
3857
|
}
|
|
4201
3858
|
/**
|
|
4202
|
-
*
|
|
4203
|
-
* @
|
|
4204
|
-
*/
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
var len = length;
|
|
4208
|
-
/**
|
|
4209
|
-
* Perform some operation over an array of vec3s.
|
|
4210
|
-
*
|
|
4211
|
-
* @param {Array} a the array of vectors to iterate over
|
|
4212
|
-
* @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
|
|
4213
|
-
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
4214
|
-
* @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
|
|
4215
|
-
* @param {Function} fn Function to call for each vector in the array
|
|
4216
|
-
* @param {Object} [arg] additional argument to pass to fn
|
|
4217
|
-
* @returns {Array} a
|
|
4218
|
-
* @function
|
|
4219
|
-
*/
|
|
4220
|
-
|
|
4221
|
-
var forEach$2 = function () {
|
|
4222
|
-
var vec = create$2$1();
|
|
4223
|
-
return function (a, stride, offset, count, fn, arg) {
|
|
4224
|
-
var i, l;
|
|
4225
|
-
|
|
4226
|
-
if (!stride) {
|
|
4227
|
-
stride = 3;
|
|
4228
|
-
}
|
|
4229
|
-
|
|
4230
|
-
if (!offset) {
|
|
4231
|
-
offset = 0;
|
|
4232
|
-
}
|
|
4233
|
-
|
|
4234
|
-
if (count) {
|
|
4235
|
-
l = Math.min(count * stride + offset, a.length);
|
|
4236
|
-
} else {
|
|
4237
|
-
l = a.length;
|
|
4238
|
-
}
|
|
4239
|
-
|
|
4240
|
-
for (i = offset; i < l; i += stride) {
|
|
4241
|
-
vec[0] = a[i];
|
|
4242
|
-
vec[1] = a[i + 1];
|
|
4243
|
-
vec[2] = a[i + 2];
|
|
4244
|
-
fn(vec, vec, arg);
|
|
4245
|
-
a[i] = vec[0];
|
|
4246
|
-
a[i + 1] = vec[1];
|
|
4247
|
-
a[i + 2] = vec[2];
|
|
4248
|
-
}
|
|
4249
|
-
|
|
4250
|
-
return a;
|
|
4251
|
-
};
|
|
4252
|
-
}();
|
|
4253
|
-
/**
|
|
4254
|
-
* 4 Dimensional Vector
|
|
4255
|
-
* @module vec4
|
|
3859
|
+
* 3 Dimensional Vector
|
|
3860
|
+
* @module vec3
|
|
4256
3861
|
*/
|
|
4257
3862
|
|
|
4258
3863
|
/**
|
|
4259
|
-
* Creates a new, empty
|
|
3864
|
+
* Creates a new, empty vec3
|
|
4260
3865
|
*
|
|
4261
|
-
* @returns {
|
|
3866
|
+
* @returns {vec3} a new 3D vector
|
|
4262
3867
|
*/
|
|
4263
3868
|
|
|
4264
3869
|
|
|
4265
|
-
function create$
|
|
4266
|
-
var out = new ARRAY_TYPE$1(
|
|
3870
|
+
function create$1$1() {
|
|
3871
|
+
var out = new ARRAY_TYPE$1(3);
|
|
4267
3872
|
|
|
4268
3873
|
if (ARRAY_TYPE$1 != Float32Array) {
|
|
4269
3874
|
out[0] = 0;
|
|
4270
3875
|
out[1] = 0;
|
|
4271
3876
|
out[2] = 0;
|
|
4272
|
-
out[3] = 0;
|
|
4273
3877
|
}
|
|
4274
3878
|
|
|
4275
3879
|
return out;
|
|
4276
3880
|
}
|
|
4277
3881
|
/**
|
|
4278
|
-
*
|
|
3882
|
+
* Creates a new vec3 initialized with the given values
|
|
4279
3883
|
*
|
|
4280
|
-
* @param {
|
|
4281
|
-
* @param {
|
|
4282
|
-
* @
|
|
3884
|
+
* @param {Number} x X component
|
|
3885
|
+
* @param {Number} y Y component
|
|
3886
|
+
* @param {Number} z Z component
|
|
3887
|
+
* @returns {vec3} a new 3D vector
|
|
4283
3888
|
*/
|
|
4284
3889
|
|
|
4285
3890
|
|
|
4286
|
-
function
|
|
4287
|
-
var
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
var len = x * x + y * y + z * z + w * w;
|
|
4292
|
-
|
|
4293
|
-
if (len > 0) {
|
|
4294
|
-
len = 1 / Math.sqrt(len);
|
|
4295
|
-
}
|
|
4296
|
-
|
|
4297
|
-
out[0] = x * len;
|
|
4298
|
-
out[1] = y * len;
|
|
4299
|
-
out[2] = z * len;
|
|
4300
|
-
out[3] = w * len;
|
|
3891
|
+
function fromValues$1(x, y, z) {
|
|
3892
|
+
var out = new ARRAY_TYPE$1(3);
|
|
3893
|
+
out[0] = x;
|
|
3894
|
+
out[1] = y;
|
|
3895
|
+
out[2] = z;
|
|
4301
3896
|
return out;
|
|
4302
3897
|
}
|
|
4303
3898
|
/**
|
|
4304
|
-
* Perform some operation over an array of
|
|
3899
|
+
* Perform some operation over an array of vec3s.
|
|
4305
3900
|
*
|
|
4306
3901
|
* @param {Array} a the array of vectors to iterate over
|
|
4307
|
-
* @param {Number} stride Number of elements between the start of each
|
|
3902
|
+
* @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
|
|
4308
3903
|
* @param {Number} offset Number of elements to skip at the beginning of the array
|
|
4309
|
-
* @param {Number} count Number of
|
|
3904
|
+
* @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
|
|
4310
3905
|
* @param {Function} fn Function to call for each vector in the array
|
|
4311
3906
|
* @param {Object} [arg] additional argument to pass to fn
|
|
4312
3907
|
* @returns {Array} a
|
|
@@ -4314,13 +3909,13 @@
|
|
|
4314
3909
|
*/
|
|
4315
3910
|
|
|
4316
3911
|
|
|
4317
|
-
var forEach$
|
|
4318
|
-
var vec = create$
|
|
3912
|
+
var forEach$2 = function () {
|
|
3913
|
+
var vec = create$1$1();
|
|
4319
3914
|
return function (a, stride, offset, count, fn, arg) {
|
|
4320
3915
|
var i, l;
|
|
4321
3916
|
|
|
4322
3917
|
if (!stride) {
|
|
4323
|
-
stride =
|
|
3918
|
+
stride = 3;
|
|
4324
3919
|
}
|
|
4325
3920
|
|
|
4326
3921
|
if (!offset) {
|
|
@@ -4337,264 +3932,15 @@
|
|
|
4337
3932
|
vec[0] = a[i];
|
|
4338
3933
|
vec[1] = a[i + 1];
|
|
4339
3934
|
vec[2] = a[i + 2];
|
|
4340
|
-
vec[3] = a[i + 3];
|
|
4341
3935
|
fn(vec, vec, arg);
|
|
4342
3936
|
a[i] = vec[0];
|
|
4343
3937
|
a[i + 1] = vec[1];
|
|
4344
3938
|
a[i + 2] = vec[2];
|
|
4345
|
-
a[i + 3] = vec[3];
|
|
4346
3939
|
}
|
|
4347
3940
|
|
|
4348
3941
|
return a;
|
|
4349
3942
|
};
|
|
4350
3943
|
}();
|
|
4351
|
-
/**
|
|
4352
|
-
* Quaternion
|
|
4353
|
-
* @module quat
|
|
4354
|
-
*/
|
|
4355
|
-
|
|
4356
|
-
/**
|
|
4357
|
-
* Creates a new identity quat
|
|
4358
|
-
*
|
|
4359
|
-
* @returns {quat} a new quaternion
|
|
4360
|
-
*/
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
function create$4$1() {
|
|
4364
|
-
var out = new ARRAY_TYPE$1(4);
|
|
4365
|
-
|
|
4366
|
-
if (ARRAY_TYPE$1 != Float32Array) {
|
|
4367
|
-
out[0] = 0;
|
|
4368
|
-
out[1] = 0;
|
|
4369
|
-
out[2] = 0;
|
|
4370
|
-
}
|
|
4371
|
-
|
|
4372
|
-
out[3] = 1;
|
|
4373
|
-
return out;
|
|
4374
|
-
}
|
|
4375
|
-
/**
|
|
4376
|
-
* Sets a quat from the given angle and rotation axis,
|
|
4377
|
-
* then returns it.
|
|
4378
|
-
*
|
|
4379
|
-
* @param {quat} out the receiving quaternion
|
|
4380
|
-
* @param {ReadonlyVec3} axis the axis around which to rotate
|
|
4381
|
-
* @param {Number} rad the angle in radians
|
|
4382
|
-
* @returns {quat} out
|
|
4383
|
-
**/
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
function setAxisAngle(out, axis, rad) {
|
|
4387
|
-
rad = rad * 0.5;
|
|
4388
|
-
var s = Math.sin(rad);
|
|
4389
|
-
out[0] = s * axis[0];
|
|
4390
|
-
out[1] = s * axis[1];
|
|
4391
|
-
out[2] = s * axis[2];
|
|
4392
|
-
out[3] = Math.cos(rad);
|
|
4393
|
-
return out;
|
|
4394
|
-
}
|
|
4395
|
-
/**
|
|
4396
|
-
* Performs a spherical linear interpolation between two quat
|
|
4397
|
-
*
|
|
4398
|
-
* @param {quat} out the receiving quaternion
|
|
4399
|
-
* @param {ReadonlyQuat} a the first operand
|
|
4400
|
-
* @param {ReadonlyQuat} b the second operand
|
|
4401
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
4402
|
-
* @returns {quat} out
|
|
4403
|
-
*/
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
function slerp(out, a, b, t) {
|
|
4407
|
-
// benchmarks:
|
|
4408
|
-
// http://jsperf.com/quaternion-slerp-implementations
|
|
4409
|
-
var ax = a[0],
|
|
4410
|
-
ay = a[1],
|
|
4411
|
-
az = a[2],
|
|
4412
|
-
aw = a[3];
|
|
4413
|
-
var bx = b[0],
|
|
4414
|
-
by = b[1],
|
|
4415
|
-
bz = b[2],
|
|
4416
|
-
bw = b[3];
|
|
4417
|
-
var omega, cosom, sinom, scale0, scale1; // calc cosine
|
|
4418
|
-
|
|
4419
|
-
cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)
|
|
4420
|
-
|
|
4421
|
-
if (cosom < 0.0) {
|
|
4422
|
-
cosom = -cosom;
|
|
4423
|
-
bx = -bx;
|
|
4424
|
-
by = -by;
|
|
4425
|
-
bz = -bz;
|
|
4426
|
-
bw = -bw;
|
|
4427
|
-
} // calculate coefficients
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
if (1.0 - cosom > EPSILON$1) {
|
|
4431
|
-
// standard case (slerp)
|
|
4432
|
-
omega = Math.acos(cosom);
|
|
4433
|
-
sinom = Math.sin(omega);
|
|
4434
|
-
scale0 = Math.sin((1.0 - t) * omega) / sinom;
|
|
4435
|
-
scale1 = Math.sin(t * omega) / sinom;
|
|
4436
|
-
} else {
|
|
4437
|
-
// "from" and "to" quaternions are very close
|
|
4438
|
-
// ... so we can do a linear interpolation
|
|
4439
|
-
scale0 = 1.0 - t;
|
|
4440
|
-
scale1 = t;
|
|
4441
|
-
} // calculate final values
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
out[0] = scale0 * ax + scale1 * bx;
|
|
4445
|
-
out[1] = scale0 * ay + scale1 * by;
|
|
4446
|
-
out[2] = scale0 * az + scale1 * bz;
|
|
4447
|
-
out[3] = scale0 * aw + scale1 * bw;
|
|
4448
|
-
return out;
|
|
4449
|
-
}
|
|
4450
|
-
/**
|
|
4451
|
-
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
4452
|
-
*
|
|
4453
|
-
* NOTE: The resultant quaternion is not normalized, so you should be sure
|
|
4454
|
-
* to renormalize the quaternion yourself where necessary.
|
|
4455
|
-
*
|
|
4456
|
-
* @param {quat} out the receiving quaternion
|
|
4457
|
-
* @param {ReadonlyMat3} m rotation matrix
|
|
4458
|
-
* @returns {quat} out
|
|
4459
|
-
* @function
|
|
4460
|
-
*/
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
function fromMat3(out, m) {
|
|
4464
|
-
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
|
4465
|
-
// article "Quaternion Calculus and Fast Animation".
|
|
4466
|
-
var fTrace = m[0] + m[4] + m[8];
|
|
4467
|
-
var fRoot;
|
|
4468
|
-
|
|
4469
|
-
if (fTrace > 0.0) {
|
|
4470
|
-
// |w| > 1/2, may as well choose w > 1/2
|
|
4471
|
-
fRoot = Math.sqrt(fTrace + 1.0); // 2w
|
|
4472
|
-
|
|
4473
|
-
out[3] = 0.5 * fRoot;
|
|
4474
|
-
fRoot = 0.5 / fRoot; // 1/(4w)
|
|
4475
|
-
|
|
4476
|
-
out[0] = (m[5] - m[7]) * fRoot;
|
|
4477
|
-
out[1] = (m[6] - m[2]) * fRoot;
|
|
4478
|
-
out[2] = (m[1] - m[3]) * fRoot;
|
|
4479
|
-
} else {
|
|
4480
|
-
// |w| <= 1/2
|
|
4481
|
-
var i = 0;
|
|
4482
|
-
if (m[4] > m[0]) i = 1;
|
|
4483
|
-
if (m[8] > m[i * 3 + i]) i = 2;
|
|
4484
|
-
var j = (i + 1) % 3;
|
|
4485
|
-
var k = (i + 2) % 3;
|
|
4486
|
-
fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
|
|
4487
|
-
out[i] = 0.5 * fRoot;
|
|
4488
|
-
fRoot = 0.5 / fRoot;
|
|
4489
|
-
out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
|
|
4490
|
-
out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
|
|
4491
|
-
out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
|
|
4492
|
-
}
|
|
4493
|
-
|
|
4494
|
-
return out;
|
|
4495
|
-
}
|
|
4496
|
-
/**
|
|
4497
|
-
* Normalize a quat
|
|
4498
|
-
*
|
|
4499
|
-
* @param {quat} out the receiving quaternion
|
|
4500
|
-
* @param {ReadonlyQuat} a quaternion to normalize
|
|
4501
|
-
* @returns {quat} out
|
|
4502
|
-
* @function
|
|
4503
|
-
*/
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
var normalize$2 = normalize$1$1;
|
|
4507
|
-
/**
|
|
4508
|
-
* Sets a quaternion to represent the shortest rotation from one
|
|
4509
|
-
* vector to another.
|
|
4510
|
-
*
|
|
4511
|
-
* Both vectors are assumed to be unit length.
|
|
4512
|
-
*
|
|
4513
|
-
* @param {quat} out the receiving quaternion.
|
|
4514
|
-
* @param {ReadonlyVec3} a the initial vector
|
|
4515
|
-
* @param {ReadonlyVec3} b the destination vector
|
|
4516
|
-
* @returns {quat} out
|
|
4517
|
-
*/
|
|
4518
|
-
|
|
4519
|
-
var rotationTo = function () {
|
|
4520
|
-
var tmpvec3 = create$2$1();
|
|
4521
|
-
var xUnitVec3 = fromValues$2(1, 0, 0);
|
|
4522
|
-
var yUnitVec3 = fromValues$2(0, 1, 0);
|
|
4523
|
-
return function (out, a, b) {
|
|
4524
|
-
var dot$1$1 = dot$1(a, b);
|
|
4525
|
-
|
|
4526
|
-
if (dot$1$1 < -0.999999) {
|
|
4527
|
-
cross(tmpvec3, xUnitVec3, a);
|
|
4528
|
-
if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
|
|
4529
|
-
normalize$1(tmpvec3, tmpvec3);
|
|
4530
|
-
setAxisAngle(out, tmpvec3, Math.PI);
|
|
4531
|
-
return out;
|
|
4532
|
-
} else if (dot$1$1 > 0.999999) {
|
|
4533
|
-
out[0] = 0;
|
|
4534
|
-
out[1] = 0;
|
|
4535
|
-
out[2] = 0;
|
|
4536
|
-
out[3] = 1;
|
|
4537
|
-
return out;
|
|
4538
|
-
} else {
|
|
4539
|
-
cross(tmpvec3, a, b);
|
|
4540
|
-
out[0] = tmpvec3[0];
|
|
4541
|
-
out[1] = tmpvec3[1];
|
|
4542
|
-
out[2] = tmpvec3[2];
|
|
4543
|
-
out[3] = 1 + dot$1$1;
|
|
4544
|
-
return normalize$2(out, out);
|
|
4545
|
-
}
|
|
4546
|
-
};
|
|
4547
|
-
}();
|
|
4548
|
-
/**
|
|
4549
|
-
* Performs a spherical linear interpolation with two control points
|
|
4550
|
-
*
|
|
4551
|
-
* @param {quat} out the receiving quaternion
|
|
4552
|
-
* @param {ReadonlyQuat} a the first operand
|
|
4553
|
-
* @param {ReadonlyQuat} b the second operand
|
|
4554
|
-
* @param {ReadonlyQuat} c the third operand
|
|
4555
|
-
* @param {ReadonlyQuat} d the fourth operand
|
|
4556
|
-
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
4557
|
-
* @returns {quat} out
|
|
4558
|
-
*/
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
var sqlerp = function () {
|
|
4562
|
-
var temp1 = create$4$1();
|
|
4563
|
-
var temp2 = create$4$1();
|
|
4564
|
-
return function (out, a, b, c, d, t) {
|
|
4565
|
-
slerp(temp1, a, d, t);
|
|
4566
|
-
slerp(temp2, b, c, t);
|
|
4567
|
-
slerp(out, temp1, temp2, 2 * t * (1 - t));
|
|
4568
|
-
return out;
|
|
4569
|
-
};
|
|
4570
|
-
}();
|
|
4571
|
-
/**
|
|
4572
|
-
* Sets the specified quaternion with values corresponding to the given
|
|
4573
|
-
* axes. Each axis is a vec3 and is expected to be unit length and
|
|
4574
|
-
* perpendicular to all other specified axes.
|
|
4575
|
-
*
|
|
4576
|
-
* @param {ReadonlyVec3} view the vector representing the viewing direction
|
|
4577
|
-
* @param {ReadonlyVec3} right the vector representing the local "right" direction
|
|
4578
|
-
* @param {ReadonlyVec3} up the vector representing the local "up" direction
|
|
4579
|
-
* @returns {quat} out
|
|
4580
|
-
*/
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
var setAxes = function () {
|
|
4584
|
-
var matr = create$4();
|
|
4585
|
-
return function (out, view, right, up) {
|
|
4586
|
-
matr[0] = right[0];
|
|
4587
|
-
matr[3] = right[1];
|
|
4588
|
-
matr[6] = right[2];
|
|
4589
|
-
matr[1] = up[0];
|
|
4590
|
-
matr[4] = up[1];
|
|
4591
|
-
matr[7] = up[2];
|
|
4592
|
-
matr[2] = -view[0];
|
|
4593
|
-
matr[5] = -view[1];
|
|
4594
|
-
matr[8] = -view[2];
|
|
4595
|
-
return normalize$2(out, fromMat3(out, matr));
|
|
4596
|
-
};
|
|
4597
|
-
}();
|
|
4598
3944
|
|
|
4599
3945
|
var StyleRendererFactory = g.Syringe.defineToken('StyleRendererFactory');
|
|
4600
3946
|
var CircleRendererContribution = g.Syringe.defineToken('CircleRenderer', {
|
|
@@ -5121,8 +4467,10 @@
|
|
|
5121
4467
|
this.renderQueue = [];
|
|
5122
4468
|
this.restoreStack = [];
|
|
5123
4469
|
this.clearFullScreen = false;
|
|
5124
|
-
this.
|
|
5125
|
-
this.
|
|
4470
|
+
this.vpMatrix = create$3();
|
|
4471
|
+
this.dprMatrix = create$3();
|
|
4472
|
+
this.tmpMat4 = create$3();
|
|
4473
|
+
this.tmpVec3 = create$1$1();
|
|
5126
4474
|
}
|
|
5127
4475
|
|
|
5128
4476
|
var _proto = CanvasRendererPlugin.prototype;
|
|
@@ -5154,7 +4502,7 @@
|
|
|
5154
4502
|
};
|
|
5155
4503
|
|
|
5156
4504
|
renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
|
|
5157
|
-
var _this$canvasConfig, width, height, context;
|
|
4505
|
+
var dpr, _this$canvasConfig, width, height, context;
|
|
5158
4506
|
|
|
5159
4507
|
return _regeneratorRuntime$3().wrap(function _callee$(_context) {
|
|
5160
4508
|
while (1) {
|
|
@@ -5165,12 +4513,15 @@
|
|
|
5165
4513
|
_this.renderingContext.root.addEventListener(g.ElementEvent.CULLED, handleCulled); // clear fullscreen
|
|
5166
4514
|
|
|
5167
4515
|
|
|
4516
|
+
dpr = _this.contextService.getDPR();
|
|
5168
4517
|
_this$canvasConfig = _this.canvasConfig, width = _this$canvasConfig.width, height = _this$canvasConfig.height;
|
|
5169
4518
|
context = _this.contextService.getContext();
|
|
5170
4519
|
|
|
5171
|
-
_this.clearRect(context, 0, 0, width, height);
|
|
4520
|
+
_this.clearRect(context, 0, 0, width * dpr, height * dpr);
|
|
5172
4521
|
|
|
5173
|
-
|
|
4522
|
+
fromScaling(_this.dprMatrix, fromValues$1(dpr, dpr, 1));
|
|
4523
|
+
|
|
4524
|
+
case 7:
|
|
5174
4525
|
case "end":
|
|
5175
4526
|
return _context.stop();
|
|
5176
4527
|
}
|
|
@@ -5185,40 +4536,49 @@
|
|
|
5185
4536
|
renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
|
|
5186
4537
|
var context = _this.contextService.getContext();
|
|
5187
4538
|
|
|
4539
|
+
var dpr = _this.contextService.getDPR();
|
|
4540
|
+
|
|
5188
4541
|
var _this$canvasConfig2 = _this.canvasConfig,
|
|
5189
4542
|
width = _this$canvasConfig2.width,
|
|
5190
|
-
height = _this$canvasConfig2.height; //
|
|
5191
|
-
// 1. dirty rectangle rendering disabled
|
|
5192
|
-
// 2. camera changed
|
|
4543
|
+
height = _this$canvasConfig2.height; // some heuristic conditions such as 80% object changed
|
|
5193
4544
|
|
|
5194
|
-
|
|
4545
|
+
var _renderingService$get = renderingService.getStats(),
|
|
4546
|
+
total = _renderingService$get.total,
|
|
4547
|
+
rendered = _renderingService$get.rendered;
|
|
5195
4548
|
|
|
5196
|
-
|
|
5197
|
-
|
|
4549
|
+
var ratio = rendered / total;
|
|
4550
|
+
_this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > 100 && ratio > 0.8;
|
|
5198
4551
|
|
|
4552
|
+
if (context) {
|
|
5199
4553
|
if (_this.clearFullScreen) {
|
|
5200
|
-
|
|
5201
|
-
} // account for camera's world matrix
|
|
4554
|
+
context.resetTransform();
|
|
5202
4555
|
|
|
5203
|
-
|
|
5204
|
-
|
|
4556
|
+
_this.clearRect(context, 0, 0, width * dpr, height * dpr);
|
|
4557
|
+
}
|
|
5205
4558
|
}
|
|
5206
4559
|
}); // render at the end of frame
|
|
5207
4560
|
|
|
5208
4561
|
renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
|
|
5209
|
-
var context = _this.contextService.getContext();
|
|
4562
|
+
var context = _this.contextService.getContext(); // clear & clip dirty rectangle
|
|
4563
|
+
|
|
4564
|
+
|
|
4565
|
+
multiply$1(_this.vpMatrix, _this.dprMatrix, _this.camera.getOrthoMatrix());
|
|
5210
4566
|
|
|
5211
|
-
if (_this.clearFullScreen)
|
|
4567
|
+
if (_this.clearFullScreen) {
|
|
4568
|
+
_this.renderingContext.root.forEach(function (object) {
|
|
4569
|
+
if (object.isVisible() && !object.isCulled()) {
|
|
4570
|
+
_this.renderDisplayObject(object, renderingService);
|
|
4571
|
+
}
|
|
4572
|
+
});
|
|
4573
|
+
} else {
|
|
5212
4574
|
// merge removed AABB
|
|
5213
|
-
var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(
|
|
5214
|
-
// this.renderQueue.filter((o) => o.nodeName !== Shape.GROUP)),
|
|
5215
|
-
_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
|
|
4575
|
+
var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
|
|
5216
4576
|
var minX = _ref2.minX,
|
|
5217
4577
|
minY = _ref2.minY,
|
|
5218
4578
|
maxX = _ref2.maxX,
|
|
5219
4579
|
maxY = _ref2.maxY;
|
|
5220
4580
|
var aabb = new g.AABB();
|
|
5221
|
-
aabb.setMinMax(fromValues$
|
|
4581
|
+
aabb.setMinMax(fromValues$1(minX, minY, 0), fromValues$1(maxX, maxY, 0));
|
|
5222
4582
|
return aabb;
|
|
5223
4583
|
})));
|
|
5224
4584
|
|
|
@@ -5227,14 +4587,17 @@
|
|
|
5227
4587
|
if (g.AABB.isEmpty(dirtyRenderBounds)) {
|
|
5228
4588
|
_this.renderQueue = [];
|
|
5229
4589
|
return;
|
|
5230
|
-
}
|
|
5231
|
-
|
|
4590
|
+
}
|
|
5232
4591
|
|
|
5233
4592
|
var _this$convertAABB2Rec = _this.convertAABB2Rect(dirtyRenderBounds),
|
|
5234
4593
|
x = _this$convertAABB2Rec.x,
|
|
5235
4594
|
y = _this$convertAABB2Rec.y,
|
|
5236
4595
|
width = _this$convertAABB2Rec.width,
|
|
5237
|
-
height = _this$convertAABB2Rec.height;
|
|
4596
|
+
height = _this$convertAABB2Rec.height; // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
4597
|
+
|
|
4598
|
+
|
|
4599
|
+
context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
|
|
4600
|
+
context.save();
|
|
5238
4601
|
|
|
5239
4602
|
_this.clearRect(context, x, y, width, height);
|
|
5240
4603
|
|
|
@@ -5261,7 +4624,8 @@
|
|
|
5261
4624
|
if (object && object.isVisible() && !object.isCulled()) {
|
|
5262
4625
|
_this.renderDisplayObject(object, renderingService);
|
|
5263
4626
|
}
|
|
5264
|
-
});
|
|
4627
|
+
});
|
|
4628
|
+
context.restore(); // save dirty AABBs in last frame
|
|
5265
4629
|
|
|
5266
4630
|
_this.renderQueue.forEach(function (object) {
|
|
5267
4631
|
_this.saveDirtyAABB(object);
|
|
@@ -5271,22 +4635,19 @@
|
|
|
5271
4635
|
_this.renderQueue = [];
|
|
5272
4636
|
} // pop restore stack, eg. root -> parent -> child
|
|
5273
4637
|
|
|
5274
|
-
|
|
4638
|
+
|
|
4639
|
+
_this.restoreStack.forEach(function () {
|
|
5275
4640
|
context.restore();
|
|
5276
4641
|
}); // clear restore stack
|
|
5277
4642
|
|
|
5278
4643
|
|
|
5279
4644
|
_this.restoreStack = [];
|
|
5280
4645
|
_this.clearFullScreen = false;
|
|
5281
|
-
context.restore();
|
|
5282
4646
|
});
|
|
5283
4647
|
renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
|
|
5284
|
-
if (_this.clearFullScreen
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
_this.renderDisplayObject(object, renderingService);
|
|
5288
|
-
}
|
|
5289
|
-
} else {
|
|
4648
|
+
if (!_this.clearFullScreen && ( // basic shapes
|
|
4649
|
+
object.nodeName !== g.Shape.GROUP && !object.isCustomElement || // should not ignore group since clipPath may affect its children
|
|
4650
|
+
object.parsedStyle.clipPath)) {
|
|
5290
4651
|
// render at the end of frame
|
|
5291
4652
|
_this.renderQueue.push(object);
|
|
5292
4653
|
}
|
|
@@ -5320,21 +4681,18 @@
|
|
|
5320
4681
|
this.styleRendererFactoryCache[nodeName] = this.styleRendererFactory(nodeName);
|
|
5321
4682
|
}
|
|
5322
4683
|
|
|
5323
|
-
var styleRenderer = this.styleRendererFactoryCache[nodeName];
|
|
4684
|
+
var styleRenderer = this.styleRendererFactoryCache[nodeName];
|
|
5324
4685
|
|
|
5325
|
-
|
|
4686
|
+
if (this.pathGeneratorFactoryCache[nodeName] === undefined) {
|
|
4687
|
+
this.pathGeneratorFactoryCache[nodeName] = this.pathGeneratorFactory(nodeName);
|
|
4688
|
+
}
|
|
5326
4689
|
|
|
5327
|
-
this.
|
|
4690
|
+
var generatePath = this.pathGeneratorFactoryCache[nodeName]; // clip path
|
|
5328
4691
|
|
|
5329
|
-
var clipPathShape = object.
|
|
4692
|
+
var clipPathShape = object.parsedStyle.clipPath;
|
|
5330
4693
|
|
|
5331
4694
|
if (clipPathShape) {
|
|
5332
|
-
context.
|
|
5333
|
-
// (object.parentElement as DisplayObject)?.getWorldTransform() || mat4.identity(this.tmpMat4);
|
|
5334
|
-
// mat4.multiply(this.tmpMat4, parentTransform, clipPathShape.getLocalTransform());
|
|
5335
|
-
// apply clip shape's RTS
|
|
5336
|
-
|
|
5337
|
-
this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
|
|
4695
|
+
this.applyWorldTransform(context, clipPathShape, object.getWorldTransform()); // generate path in local space
|
|
5338
4696
|
|
|
5339
4697
|
if (this.pathGeneratorFactoryCache[clipPathShape.nodeName] === undefined) {
|
|
5340
4698
|
this.pathGeneratorFactoryCache[clipPathShape.nodeName] = this.pathGeneratorFactory(clipPathShape.nodeName);
|
|
@@ -5343,31 +4701,28 @@
|
|
|
5343
4701
|
var _generatePath = this.pathGeneratorFactoryCache[clipPathShape.nodeName];
|
|
5344
4702
|
|
|
5345
4703
|
if (_generatePath) {
|
|
5346
|
-
|
|
4704
|
+
context.save(); // save clip
|
|
4705
|
+
// if (object.nodeName === Shape.GROUP || object.isCustomElement) {
|
|
4706
|
+
|
|
4707
|
+
this.restoreStack.push(object); // }
|
|
4708
|
+
|
|
5347
4709
|
context.beginPath();
|
|
5348
4710
|
|
|
5349
4711
|
_generatePath(context, clipPathShape.parsedStyle);
|
|
5350
4712
|
|
|
5351
4713
|
context.closePath();
|
|
4714
|
+
context.clip();
|
|
5352
4715
|
}
|
|
5353
|
-
|
|
5354
|
-
context.restore();
|
|
5355
|
-
context.clip();
|
|
5356
4716
|
} // fill & stroke
|
|
5357
4717
|
|
|
5358
4718
|
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
this.useAnchor(context, object); // generate path in local space
|
|
4719
|
+
if (styleRenderer) {
|
|
4720
|
+
this.applyWorldTransform(context, object);
|
|
4721
|
+
context.save(); // apply attributes to context
|
|
5364
4722
|
|
|
5365
|
-
|
|
5366
|
-
this.pathGeneratorFactoryCache[object.nodeName] = this.pathGeneratorFactory(object.nodeName);
|
|
4723
|
+
this.applyAttributesToContext(context, object);
|
|
5367
4724
|
}
|
|
5368
4725
|
|
|
5369
|
-
var generatePath = this.pathGeneratorFactoryCache[object.nodeName];
|
|
5370
|
-
|
|
5371
4726
|
if (generatePath) {
|
|
5372
4727
|
context.beginPath();
|
|
5373
4728
|
generatePath(context, object.parsedStyle);
|
|
@@ -5379,23 +4734,13 @@
|
|
|
5379
4734
|
|
|
5380
4735
|
|
|
5381
4736
|
if (styleRenderer) {
|
|
5382
|
-
styleRenderer.render(context, object.parsedStyle, object, renderingService);
|
|
5383
|
-
} // restore applied attributes, eg. shadowBlur shadowColor...
|
|
4737
|
+
styleRenderer.render(context, object.parsedStyle, object, renderingService); // restore applied attributes, eg. shadowBlur shadowColor...
|
|
5384
4738
|
|
|
4739
|
+
context.restore();
|
|
4740
|
+
} // finish rendering, clear dirty flag
|
|
5385
4741
|
|
|
5386
|
-
context.restore(); // finish rendering, clear dirty flag
|
|
5387
4742
|
|
|
5388
4743
|
object.renderable.dirty = false;
|
|
5389
|
-
this.restoreStack.push(object);
|
|
5390
|
-
};
|
|
5391
|
-
|
|
5392
|
-
_proto.shouldClearFullScreen = function shouldClearFullScreen() {
|
|
5393
|
-
var renderer = this.canvasConfig.renderer;
|
|
5394
|
-
|
|
5395
|
-
var _renderer$getConfig = renderer.getConfig(),
|
|
5396
|
-
enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering;
|
|
5397
|
-
|
|
5398
|
-
return !enableDirtyRectangleRendering || this.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED);
|
|
5399
4744
|
};
|
|
5400
4745
|
|
|
5401
4746
|
_proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
|
|
@@ -5475,29 +4820,11 @@
|
|
|
5475
4820
|
// save last dirty aabb
|
|
5476
4821
|
renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
|
|
5477
4822
|
}
|
|
5478
|
-
}
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
ty = _mat4$getTranslation[1];
|
|
5484
|
-
|
|
5485
|
-
var _mat4$getScaling = getScaling(create$2$1(), transform),
|
|
5486
|
-
sx = _mat4$getScaling[0],
|
|
5487
|
-
sy = _mat4$getScaling[1];
|
|
5488
|
-
|
|
5489
|
-
var rotation = getRotation(create$4$1(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
5490
|
-
|
|
5491
|
-
var _getEuler = g.getEuler(create$2$1(), rotation),
|
|
5492
|
-
eux = _getEuler[0],
|
|
5493
|
-
euy = _getEuler[1],
|
|
5494
|
-
euz = _getEuler[2]; // gimbal lock at 90 degrees
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
var rts = g.fromRotationTranslationScale(eux || euz, tx, ty, sx, sy); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
5498
|
-
|
|
5499
|
-
context.transform(rts[0], rts[1], rts[3], rts[4], rts[6], rts[7]);
|
|
5500
|
-
};
|
|
4823
|
+
}
|
|
4824
|
+
/**
|
|
4825
|
+
* TODO: batch the same global attributes
|
|
4826
|
+
*/
|
|
4827
|
+
;
|
|
5501
4828
|
|
|
5502
4829
|
_proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
|
|
5503
4830
|
var _object$parsedStyle = object.parsedStyle,
|
|
@@ -5540,7 +4867,9 @@
|
|
|
5540
4867
|
context.filter = object.style.filter;
|
|
5541
4868
|
}
|
|
5542
4869
|
|
|
5543
|
-
|
|
4870
|
+
var hasShadow = !g.isNil(shadowColor) && shadowBlur.value > 0;
|
|
4871
|
+
|
|
4872
|
+
if (hasShadow) {
|
|
5544
4873
|
context.shadowColor = shadowColor.toString();
|
|
5545
4874
|
context.shadowBlur = shadowBlur && shadowBlur.value || 0;
|
|
5546
4875
|
context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
|
|
@@ -5548,21 +4877,45 @@
|
|
|
5548
4877
|
}
|
|
5549
4878
|
};
|
|
5550
4879
|
|
|
5551
|
-
_proto.
|
|
4880
|
+
_proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
|
|
4881
|
+
var tx = 0;
|
|
4882
|
+
var ty = 0;
|
|
4883
|
+
|
|
5552
4884
|
var _ref4 = object.parsedStyle || {},
|
|
5553
4885
|
anchor = _ref4.anchor;
|
|
5554
4886
|
|
|
5555
|
-
var
|
|
5556
|
-
var
|
|
5557
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
5558
|
-
var tx = -((anchor && anchor[0].value || 0) * width);
|
|
5559
|
-
var ty = -((anchor && anchor[1].value || 0) * height);
|
|
4887
|
+
var anchorX = anchor && anchor[0].value || 0;
|
|
4888
|
+
var anchorY = anchor && anchor[1].value || 0;
|
|
5560
4889
|
|
|
5561
|
-
if (
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
4890
|
+
if (anchorX !== 0 || anchorY !== 0) {
|
|
4891
|
+
var bounds = object.getGeometryBounds();
|
|
4892
|
+
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
4893
|
+
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
4894
|
+
tx = -(anchorX * width);
|
|
4895
|
+
ty = -(anchorY * height);
|
|
4896
|
+
} // apply clip shape's RTS
|
|
4897
|
+
|
|
4898
|
+
|
|
4899
|
+
if (matrix) {
|
|
4900
|
+
copy(this.tmpMat4, object.getLocalTransform());
|
|
4901
|
+
this.tmpVec3[0] = tx;
|
|
4902
|
+
this.tmpVec3[1] = ty;
|
|
4903
|
+
this.tmpVec3[2] = 0;
|
|
4904
|
+
translate(this.tmpMat4, this.tmpMat4, this.tmpVec3);
|
|
4905
|
+
multiply$1(this.tmpMat4, matrix, this.tmpMat4);
|
|
4906
|
+
multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
4907
|
+
} else {
|
|
4908
|
+
// apply RTS transformation in world space
|
|
4909
|
+
copy(this.tmpMat4, object.getWorldTransform());
|
|
4910
|
+
this.tmpVec3[0] = tx;
|
|
4911
|
+
this.tmpVec3[1] = ty;
|
|
4912
|
+
this.tmpVec3[2] = 0;
|
|
4913
|
+
translate(this.tmpMat4, this.tmpMat4, this.tmpVec3);
|
|
4914
|
+
multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
|
|
4915
|
+
} // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
4916
|
+
|
|
4917
|
+
|
|
4918
|
+
context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
|
|
5566
4919
|
};
|
|
5567
4920
|
|
|
5568
4921
|
_proto.safeMergeAABB = function safeMergeAABB() {
|
|
@@ -6117,7 +5470,7 @@
|
|
|
6117
5470
|
var addTouchEventListener = function addTouchEventListener($el) {
|
|
6118
5471
|
$el.addEventListener('touchstart', onPointerDown, true);
|
|
6119
5472
|
$el.addEventListener('touchend', onPointerUp, true);
|
|
6120
|
-
|
|
5473
|
+
globalThis.document.addEventListener('touchmove', onPointerMove, true);
|
|
6121
5474
|
$el.addEventListener('touchcancel', onPointerCancel, true);
|
|
6122
5475
|
};
|
|
6123
5476
|
|
|
@@ -6140,7 +5493,8 @@
|
|
|
6140
5493
|
var removeTouchEventListener = function removeTouchEventListener($el) {
|
|
6141
5494
|
$el.removeEventListener('touchstart', onPointerDown, true);
|
|
6142
5495
|
$el.removeEventListener('touchend', onPointerUp, true);
|
|
6143
|
-
$el.removeEventListener('
|
|
5496
|
+
$el.removeEventListener('touchcancel', onPointerCancel, true);
|
|
5497
|
+
globalThis.document.removeEventListener('touchmove', onPointerMove, true);
|
|
6144
5498
|
};
|
|
6145
5499
|
|
|
6146
5500
|
var removeMouseEventListener = function removeMouseEventListener($el) {
|
|
@@ -6649,6 +6003,11 @@
|
|
|
6649
6003
|
_proto.apply = function apply(renderingService) {
|
|
6650
6004
|
var _this = this;
|
|
6651
6005
|
|
|
6006
|
+
var setTransform = function setTransform(object, $el) {
|
|
6007
|
+
var worldTransform = object.getWorldTransform();
|
|
6008
|
+
$el.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
|
|
6009
|
+
};
|
|
6010
|
+
|
|
6652
6011
|
var handleMounted = function handleMounted(e) {
|
|
6653
6012
|
var object = e.target;
|
|
6654
6013
|
|
|
@@ -6663,6 +6022,7 @@
|
|
|
6663
6022
|
Object.keys(object.attributes).forEach(function (name) {
|
|
6664
6023
|
_this.updateAttribute(name, object);
|
|
6665
6024
|
});
|
|
6025
|
+
setTransform(object, $el);
|
|
6666
6026
|
}
|
|
6667
6027
|
};
|
|
6668
6028
|
|
|
@@ -6694,6 +6054,16 @@
|
|
|
6694
6054
|
}
|
|
6695
6055
|
};
|
|
6696
6056
|
|
|
6057
|
+
var handleBoundsChanged = function handleBoundsChanged(e) {
|
|
6058
|
+
var object = e.target;
|
|
6059
|
+
|
|
6060
|
+
if (object.nodeName === g.Shape.HTML) {
|
|
6061
|
+
var $el = _this.getOrCreateEl(object);
|
|
6062
|
+
|
|
6063
|
+
setTransform(object, $el);
|
|
6064
|
+
}
|
|
6065
|
+
};
|
|
6066
|
+
|
|
6697
6067
|
renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
|
|
6698
6068
|
return _regeneratorRuntime$5().wrap(function _callee$(_context) {
|
|
6699
6069
|
while (1) {
|
|
@@ -6705,7 +6075,9 @@
|
|
|
6705
6075
|
|
|
6706
6076
|
_this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
6707
6077
|
|
|
6708
|
-
|
|
6078
|
+
_this.renderingContext.root.addEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
6079
|
+
|
|
6080
|
+
case 4:
|
|
6709
6081
|
case "end":
|
|
6710
6082
|
return _context.stop();
|
|
6711
6083
|
}
|
|
@@ -6718,6 +6090,8 @@
|
|
|
6718
6090
|
_this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
6719
6091
|
|
|
6720
6092
|
_this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
6093
|
+
|
|
6094
|
+
_this.renderingContext.root.removeEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
|
|
6721
6095
|
});
|
|
6722
6096
|
};
|
|
6723
6097
|
|
|
@@ -6778,12 +6152,9 @@
|
|
|
6778
6152
|
|
|
6779
6153
|
break;
|
|
6780
6154
|
|
|
6781
|
-
case 'modelMatrix':
|
|
6782
6155
|
case 'transformOrigin':
|
|
6783
6156
|
var transformOrigin = object.parsedStyle.transformOrigin;
|
|
6784
6157
|
$el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
|
|
6785
|
-
var worldTransform = object.getWorldTransform();
|
|
6786
|
-
$el.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
|
|
6787
6158
|
break;
|
|
6788
6159
|
|
|
6789
6160
|
case 'width':
|
|
@@ -7008,11 +6379,10 @@
|
|
|
7008
6379
|
this.$canvas.width = this.dpr * width;
|
|
7009
6380
|
this.$canvas.height = this.dpr * height; // set CSS style width & height
|
|
7010
6381
|
|
|
7011
|
-
g.setDOMSize(this.$canvas, width, height);
|
|
7012
|
-
|
|
6382
|
+
g.setDOMSize(this.$canvas, width, height); // const dpr = this.getDPR();
|
|
6383
|
+
// scale all drawing operations by the dpr
|
|
7013
6384
|
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
7014
|
-
|
|
7015
|
-
this.context.scale(dpr, dpr);
|
|
6385
|
+
// this.context.scale(dpr, dpr);
|
|
7016
6386
|
}
|
|
7017
6387
|
};
|
|
7018
6388
|
|