@maptalks/transform-control 0.91.2 → 0.91.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/transform-control v0.91.
|
|
2
|
+
* @maptalks/transform-control v0.91.4
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2023 maptalks.org
|
|
5
5
|
*/
|
|
@@ -1291,9 +1291,9 @@ class B {
|
|
|
1291
1291
|
}
|
|
1292
1292
|
}
|
|
1293
1293
|
|
|
1294
|
-
const y = [], p = [], v = [], L = [], M = [], d = [ 177 / 170, 177 / 170, 177 / 170 ], E = [ 1, 2, 3, 4, 12 ];
|
|
1294
|
+
const y = [], p = [], v = [], L = [], M = [], d = [ 177 / 170, 177 / 170, 177 / 170 ], E = [], O = [ 1, 2, 3, 4, 12 ];
|
|
1295
1295
|
|
|
1296
|
-
class
|
|
1296
|
+
class F {
|
|
1297
1297
|
constructor() {
|
|
1298
1298
|
this.translate = new D, this.rotation = new u, this.scaling = new m, this.planeHelper = new b,
|
|
1299
1299
|
this.xyzScaleHelper = new B, this._meshes = this.t(), this.s = !0;
|
|
@@ -1314,10 +1314,12 @@ class O {
|
|
|
1314
1314
|
for (const o in this._meshes) for (let g = 0; g < this._meshes[o].length; g++) {
|
|
1315
1315
|
const r = this._meshes[o][g];
|
|
1316
1316
|
for (let g = 0; g < r.length; g++) {
|
|
1317
|
-
const C = r[g], a = C.getUniform("uPickingId"), h = s.copy(y, C.translate)
|
|
1317
|
+
const C = r[g], a = C.getUniform("uPickingId"), h = s.copy(y, C.translate);
|
|
1318
|
+
let w = s.copy(E, C.rotation);
|
|
1319
|
+
const c = C.scaling;
|
|
1318
1320
|
if (11 === a && (this.s ? (w[2] += n, C.rotation[2] += n) : this.s || (w[2] += n,
|
|
1319
|
-
C.rotation[2] += n, w[0] = 360, w[2] -= 90)),
|
|
1320
|
-
c[1] += I, c[2] += I; else {
|
|
1321
|
+
C.rotation[2] += n, w[0] = 360, w[2] -= 90)), a > 100 && 1 === i.getTargets().length && (w = i.getTargets()[0].getRotation()),
|
|
1322
|
+
O.indexOf(a) > -1) if (12 !== a) c[0] += I, c[1] += I, c[2] += I; else {
|
|
1321
1323
|
const A = this._meshes.translate[4][0];
|
|
1322
1324
|
c[0] = 1.2 * A.scaling[0], c[1] = 1.2 * A.scaling[0], c[2] = 1.2 * A.scaling[0];
|
|
1323
1325
|
}
|
|
@@ -1353,9 +1355,9 @@ class O {
|
|
|
1353
1355
|
}
|
|
1354
1356
|
}
|
|
1355
1357
|
|
|
1356
|
-
const
|
|
1358
|
+
const x = [], U = [], V = [], S = new o(0, 0), k = [], T = [], H = [];
|
|
1357
1359
|
|
|
1358
|
-
class
|
|
1360
|
+
class J {
|
|
1359
1361
|
constructor() {
|
|
1360
1362
|
this.o = [], this.g = [ 0, 0, 0 ], this.C = [ 1, 1, 1 ], this.h = [ 0, 0, 0 ];
|
|
1361
1363
|
}
|
|
@@ -1379,7 +1381,7 @@ class H {
|
|
|
1379
1381
|
const g = this.o[o], r = g.getRotation(), C = g.getScale(), a = this.B(I, g, i, t, e);
|
|
1380
1382
|
let h = null;
|
|
1381
1383
|
h = i >= 0 ? i : i * (this.options && this.options.scaleStrength || 1);
|
|
1382
|
-
const w = s.add(
|
|
1384
|
+
const w = s.add(H, s.set(x, h * C[0], h * C[1], h * C[2]), C);
|
|
1383
1385
|
if (Math.min(...w) < n) {
|
|
1384
1386
|
const A = Math.min(...w);
|
|
1385
1387
|
w[0] = w[0] * (n / A), w[1] = w[1] * (n / A), w[2] = w[2] * (n / A);
|
|
@@ -1389,7 +1391,7 @@ class H {
|
|
|
1389
1391
|
const Q = g.getTranslation();
|
|
1390
1392
|
g.setTRS(Q, c, w);
|
|
1391
1393
|
}
|
|
1392
|
-
s.set(
|
|
1394
|
+
s.set(H, i, i, i), s.add(this.h, t, this.h), s.add(this.C, H, this.C), s.add(this.g, e, this.g),
|
|
1393
1395
|
A.indexOf("translate") > -1 ? o.fire("positionchange", {
|
|
1394
1396
|
action: A,
|
|
1395
1397
|
type: "positionchange",
|
|
@@ -1415,15 +1417,15 @@ class H {
|
|
|
1415
1417
|
});
|
|
1416
1418
|
}
|
|
1417
1419
|
B(t, i, n, I, o) {
|
|
1418
|
-
const g = i.getCenter(), r = i.getTransformOrigin(), C = t.getGLRes(), a = t.coordinateToPointAtRes(g, C,
|
|
1419
|
-
a.z = t.altitudeToPoint(g.z, C), s.set(
|
|
1420
|
-
const h = t.coordinateToPointAtRes(r, C,
|
|
1421
|
-
h.z = t.altitudeToPoint(r.z, C), s.set(
|
|
1422
|
-
const w = s.sub(
|
|
1423
|
-
s.set(
|
|
1424
|
-
const Q = e.fromRotationTranslationScale(
|
|
1425
|
-
s.transformMat4(w, w, Q), s.add(w, w,
|
|
1426
|
-
const f = t.pointAtResToCoordinate(
|
|
1420
|
+
const g = i.getCenter(), r = i.getTransformOrigin(), C = t.getGLRes(), a = t.coordinateToPointAtRes(g, C, S);
|
|
1421
|
+
a.z = t.altitudeToPoint(g.z, C), s.set(k, a.x, a.y, a.z || 0);
|
|
1422
|
+
const h = t.coordinateToPointAtRes(r, C, S);
|
|
1423
|
+
h.z = t.altitudeToPoint(r.z, C), s.set(T, h.x, h.y, h.z || 0);
|
|
1424
|
+
const w = s.sub(x, k, T), c = A.fromEuler(U, 0, 0, I[2]);
|
|
1425
|
+
s.set(H, n + 1, n + 1, n + 1);
|
|
1426
|
+
const Q = e.fromRotationTranslationScale(V, c, o, H);
|
|
1427
|
+
s.transformMat4(w, w, Q), s.add(w, w, T), S.set(w[0], w[1]);
|
|
1428
|
+
const f = t.pointAtResToCoordinate(S, C);
|
|
1427
1429
|
return f.z = w[2] / t.altitudeToPoint(1, C), f;
|
|
1428
1430
|
}
|
|
1429
1431
|
p(A, e, t) {
|
|
@@ -1484,12 +1486,12 @@ class H {
|
|
|
1484
1486
|
}
|
|
1485
1487
|
}
|
|
1486
1488
|
|
|
1487
|
-
const
|
|
1489
|
+
const N = [ 5, 6, 7, 8, 9, 10 ], R = [ 5, 7, 8, 9, 10 ], _ = [ 2, 4, 11 ], K = [ 1, 3, 12 ], z = [ 12, 16 ], G = [ 1, 2, 3, 4 ], j = [ 1, 2, 3, 4, 12 ], Z = [], Y = [], W = [], q = [], X = [], $ = [], AA = [];
|
|
1488
1490
|
|
|
1489
|
-
class
|
|
1491
|
+
class eA extends(r(C(a))){
|
|
1490
1492
|
constructor(A = {}) {
|
|
1491
1493
|
super(A), this.options = A, this.mouseAction = "moving", this.O = this.options.mode || "translate",
|
|
1492
|
-
this.F = !0, this.TransformHelper = new
|
|
1494
|
+
this.F = !0, this.TransformHelper = new F, this.U = new J, this.helperScene = new t.Scene([]),
|
|
1493
1495
|
this.addToMapCount = 0;
|
|
1494
1496
|
}
|
|
1495
1497
|
enable() {
|
|
@@ -1500,7 +1502,10 @@ class AA extends(r(C(a))){
|
|
|
1500
1502
|
this;
|
|
1501
1503
|
}
|
|
1502
1504
|
setMode(A) {
|
|
1503
|
-
this.O = A, this.V(), this.layerRenderer && this.layerRenderer.setToRedraw()
|
|
1505
|
+
this.O = A, this.V(), this.layerRenderer && this.layerRenderer.setToRedraw(), this.fire("modechange", {
|
|
1506
|
+
mode: A,
|
|
1507
|
+
type: "modechange"
|
|
1508
|
+
});
|
|
1504
1509
|
}
|
|
1505
1510
|
getMode() {
|
|
1506
1511
|
return this.O;
|
|
@@ -1509,7 +1514,7 @@ class AA extends(r(C(a))){
|
|
|
1509
1514
|
return this.F;
|
|
1510
1515
|
}
|
|
1511
1516
|
S(A) {
|
|
1512
|
-
|
|
1517
|
+
N.indexOf(A) > -1 ? this.O = "translate" : _.indexOf(A) > -1 ? this.O = "rotation" : K.indexOf(A) > -1 ? this.O = "scaling" : "xyzScale" !== this.O && (this.O = "translate");
|
|
1513
1518
|
}
|
|
1514
1519
|
k() {
|
|
1515
1520
|
return this.O;
|
|
@@ -1590,7 +1595,7 @@ class AA extends(r(C(a))){
|
|
|
1590
1595
|
this.TransformHelper._meshes.translate.forEach(A => {
|
|
1591
1596
|
for (let e = 0; e < A.length; e++) {
|
|
1592
1597
|
const t = A[e];
|
|
1593
|
-
|
|
1598
|
+
G.indexOf(t.getUniform("uPickingId")) > -1 && t.material.set("color", t.originColor);
|
|
1594
1599
|
}
|
|
1595
1600
|
});
|
|
1596
1601
|
}
|
|
@@ -1645,14 +1650,14 @@ class AA extends(r(C(a))){
|
|
|
1645
1650
|
} else if ("z-translate" === this.$) {
|
|
1646
1651
|
let A = 0;
|
|
1647
1652
|
if (this.iA()) {
|
|
1648
|
-
const e = this.map.getGLRes(), t = this.map._pointAtResToContainerPoint(new o(n.point[0], n.point[1]), e), I = this.map._pointAtResToContainerPoint(new o(s.point[0], s.point[1]), e), g = i.length(i.set(
|
|
1653
|
+
const e = this.map.getGLRes(), t = this.map._pointAtResToContainerPoint(new o(n.point[0], n.point[1]), e), I = this.map._pointAtResToContainerPoint(new o(s.point[0], s.point[1]), e), g = i.length(i.set(q, s.point[0] - n.point[0], s.point[1] - n.point[1]));
|
|
1649
1654
|
A = I.y < t.y ? g : -g;
|
|
1650
1655
|
} else A = s.point[2] - n.point[2];
|
|
1651
1656
|
I[2] = A;
|
|
1652
1657
|
}
|
|
1653
1658
|
} else if ("rotation" === A) C = this.nA(s.point, n.point), C >= 0 ? this.TransformHelper.I(!0) : this.TransformHelper.I(!1),
|
|
1654
1659
|
g[2] += C; else if ("scaling" === A || "xyzScale" === A) {
|
|
1655
|
-
const A = this.IA(), e = i.length(i.set(
|
|
1660
|
+
const A = this.IA(), e = i.length(i.set(q, this.firstDownPoint.point[0] - A[0], this.firstDownPoint.point[1] - A[1])), t = i.length(i.set(q, n.point[0] - A[0], n.point[1] - A[1]));
|
|
1656
1661
|
r = this.oA(s.point, n.point, A, t), a = this.oA(s.point, n.point, A, e);
|
|
1657
1662
|
}
|
|
1658
1663
|
this.TransformHelper.updateMatrix(this.map, this.U, C, a, I), this.U.m(this.$, I, g, r, .01, this.map, this);
|
|
@@ -1662,18 +1667,18 @@ class AA extends(r(C(a))){
|
|
|
1662
1667
|
this.lastPickingMesh = e[this.currentPickingObject.meshId];
|
|
1663
1668
|
}
|
|
1664
1669
|
oA(A, e, t, s, n) {
|
|
1665
|
-
const I = (i.length(i.set(
|
|
1670
|
+
const I = (i.length(i.set(q, A[0] - t[0], A[1] - t[1])) - i.length(i.set(q, e[0] - t[0], e[1] - t[1]))) / s;
|
|
1666
1671
|
return n ? (n[0] - .01) * I : I;
|
|
1667
1672
|
}
|
|
1668
1673
|
IA() {
|
|
1669
|
-
const A = this.map, e = this.U.getCoordinates(), t = A.coordinateToPointAtRes(e, A.getGLRes()), i = s.set(
|
|
1674
|
+
const A = this.map, e = this.U.getCoordinates(), t = A.coordinateToPointAtRes(e, A.getGLRes()), i = s.set(X, t.x, t.y, 0), n = P(A, this.U.getTranslation());
|
|
1670
1675
|
return s.add(i, i, n), i;
|
|
1671
1676
|
}
|
|
1672
1677
|
Z(t) {
|
|
1673
|
-
const i = this.TransformHelper.planeHelper.getMeshes()[0][0], n = e.getTranslation(
|
|
1674
|
-
let o = A.fromEuler(
|
|
1678
|
+
const i = this.TransformHelper.planeHelper.getMeshes()[0][0], n = e.getTranslation(W, i.localTransform), I = e.getScaling(Y, i.localTransform);
|
|
1679
|
+
let o = A.fromEuler(Z, 0, 0, 0);
|
|
1675
1680
|
const g = this.map.getBearing();
|
|
1676
|
-
t && !this.iA() ? (o = A.fromEuler(
|
|
1681
|
+
t && !this.iA() ? (o = A.fromEuler(Z, 90, 0, -g), 0 === i.rotation[0] && (this.q = !0),
|
|
1677
1682
|
s.set(i.rotation, 90, 0, -g)) : (90 === i.rotation[0] && (this.q = !0), s.set(i.rotation, 0, 0, -g)),
|
|
1678
1683
|
e.fromRotationTranslationScale(i.localTransform, o, n, I);
|
|
1679
1684
|
}
|
|
@@ -1681,7 +1686,7 @@ class AA extends(r(C(a))){
|
|
|
1681
1686
|
if (this.map.getPitch()) return !1;
|
|
1682
1687
|
const A = this.map.cameraPosition, e = this.map.coordinateToPointAtRes(this.map.getCenter(), this.map.getGLRes());
|
|
1683
1688
|
s.set(e, e.x, e.y, 0);
|
|
1684
|
-
const t = this.U.getCoordinates(), i = this.map.coordinateToPointAtRes(t, this.map.getGLRes()), n = P(this.map, this.U.getTranslation()), I = s.set(
|
|
1689
|
+
const t = this.U.getCoordinates(), i = this.map.coordinateToPointAtRes(t, this.map.getGLRes()), n = P(this.map, this.U.getTranslation()), I = s.set(W, i.x, i.y, 0), o = s.add(I, I, n), g = s.subtract([], A, o), r = s.subtract([], A, e);
|
|
1685
1690
|
return s.angle(g, r) < 1 / 180 * Math.PI;
|
|
1686
1691
|
}
|
|
1687
1692
|
Y() {
|
|
@@ -1689,7 +1694,7 @@ class AA extends(r(C(a))){
|
|
|
1689
1694
|
if (this.currentPickingObject && null != this.currentPickingObject.meshId) {
|
|
1690
1695
|
this.gA(), this.lastPickingObject && null != this.lastPickingObject.meshId && this.lastPickingObject.meshId !== this.currentPickingObject.meshId && this.rA();
|
|
1691
1696
|
const e = A[this.currentPickingObject.meshId];
|
|
1692
|
-
if (e &&
|
|
1697
|
+
if (e && z.indexOf(this.currentPickingObject.pickingId) < 0) if (this.currentPickingObject.pickingId > 100) this.CA(e); else {
|
|
1693
1698
|
const A = [ e.originColor[0], e.originColor[1], e.originColor[2], .8 ];
|
|
1694
1699
|
e.material.set("color", A), this.aA(e, .5);
|
|
1695
1700
|
}
|
|
@@ -1704,27 +1709,27 @@ class AA extends(r(C(a))){
|
|
|
1704
1709
|
});
|
|
1705
1710
|
}
|
|
1706
1711
|
gA() {
|
|
1707
|
-
6 === this.currentPickingObject.pickingId ? this.map.setCursor("ns-resize") :
|
|
1712
|
+
6 === this.currentPickingObject.pickingId ? this.map.setCursor("ns-resize") : R.indexOf(this.currentPickingObject.pickingId) > -1 ? this.map.setCursor("move") : this.map.setCursor("pointer");
|
|
1708
1713
|
}
|
|
1709
1714
|
rA() {
|
|
1710
1715
|
const A = this.lastPickingMesh;
|
|
1711
1716
|
if (!A) return;
|
|
1712
1717
|
const e = A.getUniform("uPickingId"), t = this.G();
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
}) :
|
|
1718
|
+
R.indexOf(e) > -1 ? t.forEach(A => {
|
|
1719
|
+
R.indexOf(A.getUniform("uPickingId")) > -1 && A.material.set("color", A.originColor);
|
|
1720
|
+
}) : j.indexOf(e) > -1 ? t.forEach(A => {
|
|
1716
1721
|
const e = A.getUniform("uPickingId");
|
|
1717
|
-
|
|
1722
|
+
G.indexOf(e) > -1 && A.material.set("color", A.originColor);
|
|
1718
1723
|
}) : 11 === e && t.forEach(A => {
|
|
1719
|
-
|
|
1724
|
+
G.indexOf(A.getUniform("uPickingId")) > -1 && A.material.set("color", A.originColor);
|
|
1720
1725
|
}), A.material.set("color", A.originColor), A.properties.relatedMeshes && A.properties.relatedMeshes.forEach(A => {
|
|
1721
1726
|
A.material.set("color", A.originColor);
|
|
1722
1727
|
});
|
|
1723
1728
|
}
|
|
1724
1729
|
aA(A, e) {
|
|
1725
1730
|
const t = A.getUniform("uPickingId"), s = this.G();
|
|
1726
|
-
|
|
1727
|
-
if (
|
|
1731
|
+
R.indexOf(t) > -1 ? s.forEach(t => {
|
|
1732
|
+
if (R.indexOf(t.getUniform("uPickingId")) > -1 && t.getUniform("uPickingId") !== A.getUniform("uPickingId")) {
|
|
1728
1733
|
const A = [ t.originColor[0], t.originColor[1], t.originColor[2], e ];
|
|
1729
1734
|
t.material.set("color", A);
|
|
1730
1735
|
}
|
|
@@ -1746,7 +1751,7 @@ class AA extends(r(C(a))){
|
|
|
1746
1751
|
this.map && this.U && (this.U.v(), this.TransformHelper.updateMatrix(this.map, this.U, 0, 0, [ 0, 0, 0 ]));
|
|
1747
1752
|
}
|
|
1748
1753
|
nA(A, e) {
|
|
1749
|
-
const t = this.IA(), s = i.set(
|
|
1754
|
+
const t = this.IA(), s = i.set($, e[0] - t[0], e[1] - t[1]), n = i.set(AA, A[0] - t[0], A[1] - t[1]), I = Math.atan2(s[1], s[0]);
|
|
1750
1755
|
return (Math.atan2(n[1], n[0]) - I) / Math.PI * 180;
|
|
1751
1756
|
}
|
|
1752
1757
|
X(A) {
|
|
@@ -1869,10 +1874,10 @@ class AA extends(r(C(a))){
|
|
|
1869
1874
|
}
|
|
1870
1875
|
}
|
|
1871
1876
|
|
|
1872
|
-
|
|
1877
|
+
eA.mergeOptions({
|
|
1873
1878
|
scaleStrength: 2
|
|
1874
1879
|
});
|
|
1875
1880
|
|
|
1876
|
-
export {
|
|
1881
|
+
export { eA as TransformControl };
|
|
1877
1882
|
|
|
1878
|
-
"undefined" != typeof console && console.log("@maptalks/transform-control v0.91.
|
|
1883
|
+
"undefined" != typeof console && console.log("@maptalks/transform-control v0.91.4");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/transform-control v0.91.
|
|
2
|
+
* @maptalks/transform-control v0.91.4
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2023 maptalks.org
|
|
5
5
|
*/
|
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
* LICENSE : UNLICENSED
|
|
10
10
|
* (c) 2016-2023 maptalks.org
|
|
11
11
|
*/
|
|
12
|
-
let P=0;function b(A){return null==A}function D(A){return!b(A)}function y(A){return!b(A)&&("string"==typeof A||null!==A.constructor&&A.constructor===String)}function B(A){for(let t=1;t<arguments.length;t++){const e=arguments[t];for(const t in e)A[t]=e[t]}return A}function d(A){switch(A){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+A)}function p(A){return 0===A.indexOf("data:")&&A.indexOf("base64,")>0}function v(A){const t=function(A){return"undefined"!=typeof self?self.atob(A):window.atob(A)}(A.substring(A.indexOf(",")+1)),e=t.length,s=new Uint8Array(e);for(let A=0;A<e;A++)s[A]=t.charCodeAt(A);return s.buffer}const M=[],L=[],E=[],O=[0,0,0],F=function(A){return A[0]=0,A[1]=0,A[2]=0,A[3]=1,A}([]),x=[1,1,1];function U(A,t,e,s,n,i,r){const o=d(r);if((0===n||n===s*o.BYTES_PER_ELEMENT)&&i%o.BYTES_PER_ELEMENT==0){const n=new o(t,i,e*s);return A.set(n),A}0===n&&(n=s*o.BYTES_PER_ELEMENT);const a=new Uint8Array(s*o.BYTES_PER_ELEMENT);for(let r=0;r<e;r++){let e=null;const h=new Uint8Array(t,n*r+i,s*o.BYTES_PER_ELEMENT);a.set(h),e=new o(a.buffer,0,s);for(let t=0;t<s;t++)A[r*s+t]=e[t]}return A}const V="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function T(A,t,e){const s=new Uint8Array(A,t,e);return V.decode(s)}const S={get:function(A,t={}){t||(t={});const e=new AbortController,s=e.signal,n=B({},t);n.signal=s,n.method||(n.method="GET");const i=fetch(A,n).then(A=>{const e=this.t(A,t.responseType);return e.message?e:e.then(e=>"arraybuffer"===t.responseType?{data:e,cacheControl:A.headers.get("Cache-Control"),expires:A.headers.get("Expires"),contentType:A.headers.get("Content-Type")}:e).catch(A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A})}).catch(A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A});return i.xhr=e,i},t:(A,t)=>200!==A.status?{status:A.status,statusText:A.statusText,message:`incorrect http request with status code(${A.status}): ${A.statusText}`}:"arraybuffer"===t?A.arrayBuffer():"json"===t?A.json():A.text(),getArrayBuffer:(A,t={})=>(t||(t={}),t.responseType="arraybuffer",S.get(A,t)),getJSON:function(A,t={}){return t&&t.jsonp?S.jsonp(A):((t=t||{}).responseType="json",S.get(A,t))},jsonp:function(A){const t="_maptalks_jsonp_"+P++;A.match(/\?/)?A+="&callback="+t:A+="?callback="+t;let e=document.createElement("script");return e.type="text/javascript",e.src=A,new Promise(A=>{window[t]=function(s){document.getElementsByTagName("head")[0].removeChild(e),e=null,delete window[t],A(s)},document.getElementsByTagName("head")[0].appendChild(e)})}};class k{constructor(A,t,e){this.s=A,this.decoders=t,this.i=e,this.images={},this.o={}}requestImageFromBufferURI(A,t,e){if(this.buffers[A.id]){const s=this.buffers[A.id],n=this.h(t,s);return this.getImageByBuffer(n,e)}if(this.o[A.id])return this.o[A.id].then(()=>{const s=this.buffers[A.id],n=this.h(t,s);return this.getImageByBuffer(n,e)});if(p(A.uri)){const s=this.buffers[A.id]=v(A.uri),n=this.h(t,s);return this.getImageByBuffer(n,e)}let s;const n=A.uri.indexOf("blob:")>=0;return s=A.uri.indexOf("://")>0||n?A.uri:this.rootPath+"/"+A.uri,this.o[A.id]=S.getArrayBuffer(s,null).then(s=>{const n=this.buffers[A.id]=s.data,i=this.h(t,n);return this.getImageByBuffer(i,e)})}getImageByBuffer(A,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=this.decoders;return e[t.mimeType]?e[t.mimeType](A,{supportedFormats:this.i}):"image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType?(console.warn("missing transcoder for "+t.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.I(t.id,A)}requestExternalImage(A){if(this.images[A.id])return Promise.resolve(this.images[A.id]);const t=0===A.uri.indexOf("data:image/")?A.uri:this.rootPath+"/"+A.uri;return this.o[A.id]?this.o[A.id].then(()=>this.images[A.id]):this.o[A.id]=this.I(A.id,t)}I(A,t){return new Promise((e,s)=>{this.s(t,(n,i)=>{n?s(n):(URL.revokeObjectURL(t),this.images[A]=i,e(this.images[A]))})})}}const _=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],N=[];class R{constructor(A,t,e){this.rootPath=A,this.gltf=t,this.g=!1,this.glbBuffer=e,this.buffers={},this.requests={},this.accessors={},this.C()}u(A,t){const e=this.gltf,s=e.accessors[t];if(void 0===s.bufferView)return this.accessors[s.id]=this.l(A,t,null,0),Promise.resolve(this.accessors[s.id]);if(s&&this.accessors[s.id])return Promise.resolve(this.accessors[s.id]);const n=e.bufferViews[s.bufferView];return this.m(n).then(e=>{const{buffer:n,byteOffset:i}=e;return this.accessors[s.id]=this.l(A,t,n,i)})}m(A){const t=this.gltf.buffers[A.buffer];if(this.buffers[t.id]){const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then(()=>{const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})});if("binary_glTF"!==A.buffer&&"KHR_binary_glTF"!==A.buffer&&t.uri){if(p(t.uri)){const A=this.buffers[t.id]=v(t.uri);return Promise.resolve({buffer:A,byteOffset:0})}let A;const e=t.uri.indexOf("blob:")>=0;return A=t.uri.indexOf("://")>0||e?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=S.getArrayBuffer(A,null).then(s=>(e&&URL.revokeObjectURL(A),{buffer:this.buffers[t.id]=s.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}l(A,t,e,s=0){const n=this.gltf,i=n.accessors[t],r=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(r.byteOffset||0)+s,a=this.P(i.type),h=d(i.componentType),I=r.byteStride||0,c={array:void 0,name:A,accessorName:t,byteLength:i.count*a*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:a,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(c.min=i.min),i.max&&(c.max=i.max),e)if(this.g)c.byteStride=I,c.byteOffset=o+(i.byteOffset||0),!I||I===a*h.BYTES_PER_ELEMENT||"indices"===A||"input"===A||"output"===A||A.indexOf("morph")>=0?(c.array=this.D(e,i.count,a,o+(i.byteOffset||0),h),c.array.buffer.byteLength===c.byteLength&&(c.byteOffset=0)):c.array=new Uint8Array(e,o,r.byteLength);else if(i.interleaved){c.byteStride=0,c.byteOffset=0;const A=new h(i.count*a);if(c.array=U(A,e,i.count,a,I,o+(i.byteOffset||0),i.componentType),c.extensions&&c.extensions.WEB3D_quantized_attributes&&a>2){const A=new Float32Array(c.array.length),{decodeMatrix:t}=c.extensions.WEB3D_quantized_attributes;for(let e=0;e<c.array.length;e+=a){N[0]=c.array[e],N[1]=c.array[e+1],N[2]=c.array[e+2],N[3]=1;const s=u(N,N,t);A[e]=s[0],A[e+1]=s[1],A[e+2]=s[2]}c.componentType=5126,c.array=A}}else c.byteStride=0,c.array=this.D(e,i.count,a,o+(i.byteOffset||0),h),c.byteOffset=c.array.byteOffset;else{c.array=new h(i.count);const A=c.min||c.max;A&&(c.array[0]=A[0],c.array[1]=A[1],c.array[2]=A[2])}return c}C(){const A=this.gltf.accessors;if(Array.isArray(A))for(let t=0;t<A.length;t++)for(let e=0;e<A.length;e++)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0);else for(const t in A)for(const e in A)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0)}D(A,t,e,s,n){return s%n.BYTES_PER_ELEMENT!=0&&(A=A.slice(s,s+t*e*n.BYTES_PER_ELEMENT),s=0),new n(A,s,e*t)}P(A){const t=_.indexOf(A);return _[t+1]}requestKHRTechniquesWebgl(A){const{shaders:t}=A,e=t.map(A=>{if(void 0!==A.bufferView){const t=this.gltf.bufferViews[A.bufferView],{byteLength:e}=t;return this.m(t).then(s=>{const{buffer:n,byteOffset:i}=s,r=T(n,i+(t.byteOffset||0),e);return A.content=r,A})}if(A.uri){if(p(A.uri)){const t=v(A.uri),e=T(t,0,t.byteLength);return A.content=e,Promise.resolve(A)}{const t=this.rootPath+"/"+A.uri;return S.get(t).then(t=>(A.content=t,A))}}return Promise.resolve(A)});return Promise.all(e).then(()=>A)}}class H extends k{constructor(A,t,e,s,n,i){super(s,n,i),this.rootPath=A,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=e,this.accessor=new R(A,t,e)}iterate(A,t){const e=this.gltf[t];if(!e)return;let s=0;for(const t in e)A(t,e[t],s++)}createNode(A){const t={};if(D(A.name)&&(t.name=A.name),D(A.children)&&(t.children=A.children),D(A.jointName)&&(t.jointName=A.jointName),D(A.matrix)&&(t.matrix=A.matrix),D(A.rotation)&&(t.rotation=A.rotation),D(A.scale)&&(t.scale=A.scale),D(A.translation)&&(t.translation=A.translation),D(A.extras)&&(t.extras=A.extras),D(A.meshes)&&(t.mesh=A.meshes[0]),t.translation||t.rotation||t.scale){const A=function(A,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const e=function(A,t){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=t[0],A[13]=t[1],A[14]=t[2],A[15]=1,A}(M,t.translation||O),s=function(A,t){var e=t[0],s=t[1],n=t[2],i=t[3],r=e+e,o=s+s,a=n+n,h=e*r,I=s*r,c=s*o,g=n*r,f=n*o,C=n*a,u=i*r,l=i*o,w=i*a;return A[0]=1-c-C,A[1]=I+w,A[2]=g-l,A[3]=0,A[4]=I-w,A[5]=1-h-C,A[6]=f+u,A[7]=0,A[8]=g+l,A[9]=f-u,A[10]=1-h-c,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(L,t.rotation||F),n=function(A,t){return A[0]=t[0],A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=t[1],A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=t[2],A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(E,t.scale||x);return o(n,s,n),o(A,e,n)}return function(A){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(A)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=A}return t}B(A){const t={};for(const e in A){const s=A[e];let n,i;s.instanceTechnique&&s.instanceTechnique.values?(n=s.instanceTechnique,i=n.values.diffuse):(n=s,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const r={baseColorTexture:{index:i}};s.name&&(r.name=s.name),s.extensions&&(r.extensions=s.extensions),s.extras&&(r.extras=s.extras),t[e]=r}return t}p(A){if(A.bufferView||A.extensions&&(A.extensions.KHR_binary_glTF||A.extensions.binary_glTF)){const t=A.bufferView?A:A.extensions.KHR_binary_glTF||A.extensions.binary_glTF;A.extensions&&(A.mimeType=t.mimeType,A.width=t.width,A.height=t.height);const e=this.gltf.bufferViews[t.bufferView],s=(e.byteOffset||0)+this.glbBuffer.byteOffset,n=e.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,s,n);return this.getImageByBuffer(i,A)}return this.requestExternalImage(A)}v(A){const t=this.gltf.textures[A];if(!t)return null;const e=this.gltf.images[t.source];return this.p(e).then(A=>{const s=this.gltf.samplers[t.sampler];return{image:{array:A.data,width:A.width,height:A.height,index:t.source,mimeType:e.mimeType,name:e.name,extras:e.extras},sampler:s}})}getBaseColorTexture(A){const t=this.gltf.materials[A];let e,s;if(t.instanceTechnique&&t.instanceTechnique.values?(e=t.instanceTechnique,s=e.values.diffuse):(e=t,s=e.values.tex||e.values.diffuseTex||e.values.diffuse),void 0===s||void 0===this.gltf.textures)return null;const n=this.gltf.textures[s];if(!n)return null;const i=this.gltf.samplers[n.sampler];return{format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}class J extends k{constructor(A,t,e,s,n,i){super(s,n,i),this.rootPath=A,this.gltf=t,this.glbBuffer=e,this.buffers={},this.requests={},this.accessor=new R(A,t,e)}iterate(A,t){const e=this.gltf[t];if(e)for(let t=0;t<e.length;t++)A(t,e[t],t)}createNode(A){const t={};return B(t,A),!D(A.weights)&&this.gltf.meshes&&D(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:A.weights&&(t.weights=A.weights),t}v(A){const t=this.gltf.textures[A];if(!t)return null;let e=t.source;if(t.extensions&&t.extensions.EXT_texture_webp&&(e=t.extensions.EXT_texture_webp.source),!D(e))return null;const s=this.gltf.images[e];return this.p(s).then(A=>{if(!A)return null;const e={image:{array:A.data,mipmap:A.mipmap,width:A.width,height:A.height,index:t.source,mimeType:s.mimeType,name:s.name,extensions:s.extensions,extras:s.extras}};B(e,t);const n=D(t.sampler)?this.gltf.samplers[t.sampler]:void 0;return n&&(e.sampler=n,e.sampler.magFilter=n.magFilter||9729,e.sampler.minFilter=n.minFilter||9729,e.sampler.wrapS=n.wrapS||10497,e.sampler.wrapT=n.wrapT||10497),A.format&&(e.format=A.format),e})}p(A){if(!D(A.bufferView))return this.requestExternalImage(A);{const t=this.gltf.bufferViews[A.bufferView],e=this.gltf.buffers[t.buffer];if(e.uri)return this.requestImageFromBufferURI(e,t,A);if(this.glbBuffer)return this.M(t,A)}return null}M(A,t){const e=this.h(A,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(e,t)}h(A,t,e){e=e||0;const s=A.byteOffset+e,n=A.byteLength;return new Uint8Array(t,s,n)}L(A,t){const e=new Array(A.byteLength);for(let t=0;t<A.byteLength;t++)e[t]=String.fromCharCode(A[t]);return e.join(""),"data:"+(t=t||"image/png")+";base64,"+function(A){return"undefined"!=typeof self?self.btoa(A):window.btoa(A)}(unescape(encodeURIComponent(e)))}getAnimations(A){const t=[];return A.forEach(A=>{t.push(this.getSamplers(A.samplers))}),Promise.all(t).then(t=>{for(let e=0;e<t.length;e++)A[e].samplers=t[e];return A})}getSamplers(A){const t=[];for(let e=0;e<A.length;e++)(D(A[e].input)||D(A[e].output))&&(t.push(this.accessor.u("input",A[e].input)),t.push(this.accessor.u("output",A[e].output)));return Promise.all(t).then(t=>{for(let e=0;e<t.length/2;e++)A[e].input=t[2*e],A[e].output=t[2*e+1],A[e].interpolation||(A[e].interpolation="LINEAR");return A})}}const K="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class j{static read(A,t=0,e=0){e||(e=A.byteLength);const s=new DataView(A,t,e),n=s.getUint32(4,!0);if(1===n)return j.readV1(s,t);if(2===n)return j.readV2(A,t);throw new Error("Unsupported glb version : "+n)}static readV1(A,t){const e=A.getUint32(8,!0),s=A.getUint32(12,!0);if(e!==A.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=z(A.buffer,20+t,s);return{json:JSON.parse(n),glbBuffer:{byteOffset:20+t+s,buffer:A.buffer,byteLength:e}}}static readV2(A,t){let e,s,n;const i=new DataView(A,t+12);let r=0;for(;r<i.byteLength;){const o=i.getUint32(r,!0);r+=4;const a=i.getUint32(r,!0);if(r+=4,1313821514===a)e=z(A,t+12+r,o);else if(5130562===a){n=t+12+r,s=o;break}r+=o}return{json:JSON.parse(e),glbBuffer:{byteOffset:n,buffer:A,byteLength:s}}}}function z(A,t,e){if(K){const s=new Uint8Array(A,t,e);return K.decode(s)}return function(A){const t=A.length;let e="";for(let s=0;s<t;){let n=A[s++];if(128&n){let e=G[n>>3&7];if(!(64&n)||!e||s+e>t)return null;for(n&=63>>e;e>0;e-=1){const t=A[s++];if(128!=(192&t))return null;n=n<<6|63&t}}e+=String.fromCharCode(n)}return e}(new Uint8Array(A,t,e))}const G=[1,1,1,1,2,2,3,0],Z=[0,0,0],Y=[0,0,0,1],q=[1,1,1],W={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},X={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},$={O(A,t,e,s,n,i,r,o){const a=D(A)?t.animations:[t.animations[0]],h={};for(let t=0;t<a.length;t++){const c=a[t],g=c.name||t;if(D(A)&&g!==A)continue;const f=c.channelsMap[e];if(f)for(let A=0;A<f.length;A++){const t=f[A];"translation"===t.target.path?(this.F(n,c.samplers[t.sampler],s,1),h.translation=I(Z,n)):"rotation"===t.target.path?(this.U(i,c.samplers[t.sampler],s,1),h.rotation=m(Y,i)):"scale"===t.target.path?(this.F(r,c.samplers[t.sampler],s,1),h.scale=I(q,r)):"weights"===t.target.path&&o&&(this.F(o,c.samplers[t.sampler],s,o.length),h.weights=o)}}return h},F(A,t,e,s){switch(t.interpolation){case"LINEAR":{const n=this.V(X,t,e,1*s);n&&(A=function(A,t,e,s){for(let n=0;n<A.length;n++)A[n]=t[n]+s*(e[n]-t[n]);return A}(A,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this.V(X,t,e,1*s);n&&(A=function(A,t){for(let e=0;e<A.length;e++)A[e]=t[e];return A}(A,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.V(X,t,e,3*s);n&&(A=this.T(A,n,t.input.array,3*s));break}}return A},U(A,t,e){switch(t.interpolation){case"LINEAR":{const s=this.V(X,t,e,1);s&&w(A,s.PREVIOUS,s.NEXT,s.INTERPOLATION);break}case"STEP":{const s=this.V(X,t,e,1);s&&(A=C(A,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.V(X,t,e,3);if(s){for(let A=0;A<s.PREVIOUS.length;A++)s.PREVIOUS[A]=Math.acos(s.PREVIOUS[A]),s.NEXT[A]=Math.acos(s.NEXT[A]);A=this.T(A,s,t.input.array,3);for(let t=0;t<A.length;t++)A[t]=Math.cos(A[t])}break}}return A},S(A,t){const e=A.length;let s,n,i,r=0,o=e-1,a=Math.floor((r+o)/2);for(;r<=e-1&&o>=0;){if(r===o)return null;if(A[a]<=t&&t<=A[a+1]){const e=A[a];return s=a,n=a+1,i=(t-e)/(A[a+1]-e),{preIndx:s,nextIndex:n,interpolation:i}}t<A[a]?(o=a,a=Math.floor((r+o)/2)):A[a+1]<t&&(r=a,a=Math.floor((r+o)/2))}return null},V(A,t,e,s){const n=t.input.array,i=t.output.array,r=t.output.itemSize;(e<n[0]||e>n[n.length-1])&&(e=Math.max(n[0],Math.min(n[n.length-1],e))),e===n[n.length-1]&&(e=n[0]);const o=this.S(n,e);if(!o||!o.nextIndex)return null;const{preIndx:a,nextIndex:h,interpolation:I}=o;A.PREINDEX=a,A.NEXTINDEX=h,A.INTERPOLATION=I;const c=r*s;return A.PREVIOUS=i.subarray(A.PREINDEX*c,(A.PREINDEX+1)*c),A.NEXT=i.subarray(A.NEXTINDEX*c,(A.NEXTINDEX+1)*c),A},T(A,t,e,s){const n=t.INTERPOLATION,i=e[t.PREINDEX],r=e[t.NEXTINDEX];for(let e=0;e<3;e++){const o=t.PREVIOUS[s+e],a=(r-i)*t.PREVIOUS[2*s+e],h=t.NEXT[3+e],I=(r-i)*t.NEXT[e],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*a+(2*-Math.pow(n,3)+3*Math.pow(n,2))*h+(Math.pow(n,3)-Math.pow(n,2))*I;A[e]=c}return A},getAnimationClip(A,t,e,s){const n=A.nodes[t]&&A.nodes[t].weights;return c(Z,...W.TRANSLATION),C(Y,...W.ROTATION),c(q,...W.SCALE),this.O(s,A,t,e,Z,Y,q,n)},getTimeSpan(A){if(!A.animations)return null;if(A.timeSpan)return A.timeSpan;const t=A.animations;return A.timeSpan={},t.forEach((t,e)=>{let s=-1/0,n=1/0;const i=t.channels;for(let A=0;A<i.length;A++){const e=i[A],r=t.samplers[e.sampler].input.array;r[r.length-1]>s&&(s=r[r.length-1]),r[0]<n&&(n=r[0])}const r=t.name||e;A.timeSpan[r]={max:s,min:n}}),A.timeSpan},getTimeSpanByName(A,t){const e=this.getTimeSpan(A);return e?D(t)?e[t]:e[Object.keys(e)[0]]:null}};let AA=!1;if("undefined"!=typeof OffscreenCanvas){let A;try{A=new OffscreenCanvas(2,2).getContext("2d")}catch(A){}A&&"undefined"!=typeof createImageBitmap&&(AA=!0)}const tA="undefined"==typeof document?null:document.createElement("canvas");class eA{constructor(A,t,e){if(this.options=e||{},this.options.decoders||(this.options.decoders={}),t.buffer instanceof ArrayBuffer){const{json:e,glbBuffer:s}=j.read(t.buffer,t.byteOffset,t.byteLength);this.k(A,e,s)}else this.k(A,t);this._=new R(this.rootPath,this.gltf,this.glbBuffer),this.N()}N(){const A=this.gltf.extensionsRequired;if(A){if(A.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(A.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}R(){const A=this.gltf.extensions;return A&&A.KHR_techniques_webgl?this._.requestKHRTechniquesWebgl(A.KHR_techniques_webgl).then(t=>(A.KHR_techniques_webgl=t,A)):Promise.resolve(A)}load(A){A=A||{};const t=this.H(A),e=this.J(),s=this.K(),n=this.R();return Promise.all([t,e,s,n]).then(A=>(A[0].animations=A[1],A[0].textures=A[2],A[0].extensions=A[3],A[0].transferables=this.transferables||[],this.createChannelsMap(A[0]),A[0]))}createChannelsMap(A){const t=A.animations;if(t)for(let A=0;A<t.length;A++){const e=t[A];e.channelsMap={};for(let A=0;A<e.channels.length;A++){const t=e.channels[A];e.channelsMap[t.target.node]||(e.channelsMap[t.target.node]=[]),e.channelsMap[t.target.node].push(t)}}}getExternalResources(){const A=[];if(this.gltf){const{buffers:t,images:e}=this.gltf;for(let e=0;e<t.length;e++)t[e].uri&&t[e].uri.indexOf("data:application/octet-stream;base64")<0&&A.push({type:"buffer",uri:t[e].uri});for(let t=0;t<e.length;t++)e[t].uri&&e[t].uri.indexOf("data:image/")<0&&A.push({type:"image",uri:e[t].uri})}return A}static getAnimationClip(A,t,e,s){return $.getAnimationClip(A,t,e,s)}static getAnimationTimeSpan(A,t){return $.getTimeSpanByName(A,t)}static getTypedArrayCtor(A){return d(A)}static readInterleavedArray(A,t,e,s,n,i,r){return U(A,t,e,s,n,i,r)}k(A,t,e){this.gltf=t,this.glbBuffer=e,this.version=t.asset?+t.asset.version:1,this.rootPath=A,this.buffers={},this.requests={},this.options.requestImage=AA?rA.bind(this):this.options.requestImage||sA,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new J(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((A,t,e)=>{t.id="buffer_"+e},"buffers"),this.adapter.iterate((A,t,e)=>{t.id="image_"+e},"images"),this.adapter.iterate((A,t,e)=>{t.id="accessor_"+e},"accessors")):(this.adapter=new H(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((A,t,e)=>{t.id="accessor_"+e},"accessors"),this.adapter.iterate((A,t,e)=>{t.id="image_"+e},"images"))}j(A,t){if(A.children&&A.children.length>0){if(!("number"==typeof(e=A.children[0])&&isFinite(e)||y(A.children[0])))return A;const s=A.children.map(A=>{const e=t[A];return e.nodeIndex=A,this.j(e,t)});A.children=s}var e;return A}H(A){return this.G(A).then(A=>{const t=this.scenes=[];let e;for(const t in A)A[t]=this.j(A[t],A),A[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate((s,n,i)=>{const r={};n.name&&(r.name=n.name),n.nodes&&(r.nodes=n.nodes.map(t=>A[t])),this.gltf.scene===s&&(e=i),t.push(r)},"scenes");const s={textures:this.gltf.textures,asset:this.gltf.asset,scene:e,scenes:t,nodes:A,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(s.extensions=this.gltf.extensions),1===this.version){const A=this.adapter.B(this.gltf.materials);s.materials=A}return s})}G(A){return this.Z(A).then(()=>{const A=this.nodes={};return this.adapter.iterate((t,e)=>{const s=this.adapter.createNode(e,this.meshes,this.skins);A[t]=s},"nodes"),A})}Y(){this.skins=[];const A=[];return this.adapter.iterate((t,e,s)=>{A.push(this.q(e).then(A=>{A.index=s,this.skins.push(A)}))},"skins"),A}q(A){const t=A.inverseBindMatrices;return this.adapter.accessor.u("inverseBindMatrices",t).then(t=>(A.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),A))}J(){const A=this.gltf.animations;return D(A)?this.adapter.getAnimations(A):null}Z(A){this.meshes={};let t=[];return this.adapter.iterate((e,s,n)=>{t.push(this.W(s,A).then(A=>{A.index=n,this.meshes[e]=A}))},"meshes"),t=t.concat(this.Y()),Promise.all(t)}W(A,t){const e=A.primitives.map(A=>this.X(A,t)).filter(A=>!!A);return Promise.all(e).then(t=>{const e={};return B(e,A),e.primitives=t,e})}K(){const A=this.gltf.textures;if(!A)return null;const t=[];for(const e in A)t.push(this.adapter.v(e));return Promise.all(t).then(t=>{if(this.transferables)for(let A=0;A<t.length;A++){const e=t[A].image.array;if(t[A]&&e){let A;A=e instanceof ImageBitmap?e:e.buffer,A&&this.transferables.indexOf(A)<0&&this.transferables.push(A)}}if(!Array.isArray(A)){const e={},s=Object.keys(A);for(let A=0;A<t.length;A++)t[A]&&(e[s[A]]=t[A]);return e}return t})}X(A,t){let e;const s=[],n=A.extensions;if(D(A.targets))for(let t=0;t<A.targets.length;t++){const e=A.targets[t];for(const A in e){const n=this.adapter.accessor.u(`morphTargets_${A}_${t}`,e[A]);n&&s.push(n)}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const A=this.options.decoders.draco,{bufferView:i,attributes:r}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],a=this._.m(o).then(e=>{const{buffer:s,byteOffset:n}=e;let{byteOffset:i}=o;const a=o.byteLength;i||(i=0);const h=new DataView(s,n+i,a),I={attributes:r,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return A(h,I).then(A=>{const t=Object.values(A.attributes);return A.indices&&t.push(A.indices),t})});s.push(a),e=Promise.all(s)}else{const t=A.attributes;for(const A in t){const e=this.adapter.accessor.u(A,t[A]);e&&s.push(e)}if(D(A.indices)){const t=this.adapter.accessor.u("indices",A.indices);t&&s.push(t)}e=Promise.all(s)}return e.then(t=>{if(n&&n.KHR_draco_mesh_compression){const e=A.targets?A.targets.length:0;t[e]=t[e].concat(t.slice(0,e)),t=t[e]}let e,s;const i={attributes:t.reduce((A,t)=>{if("indices"===t.name)e=t;else if(t.name.indexOf("morphTargets_")>-1)s=s||{},s[t.name.slice(13)]=t;else{if(!("POSITION"!==t.name||t.min&&t.max)){const A=[1/0,1/0,1/0],e=[-1/0,-1/0,-1/0],{itemSize:s,array:n}=t,i=n.length/s;for(let t=0;t<i;t++)for(let i=0;i<s;i++){const r=t*s+i;n[r]<A[i]&&(A[i]=n[r]),n[r]>e[i]&&(e[i]=n[r])}if(t.quantization){const s=t.quantization,n=s.range/(1<<s.quantizationBits),i=s.minValues;f(A,A,n),g(A,A,i),f(e,e,n),g(e,e,i)}t.min=A,t.max=e}A[t.name]=t}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),A},{}),material:A.material};return e&&(i.indices=e),s&&(i.morphTargets=s),i.mode=D(A.mode)?A.mode:4,D(A.extras)&&(i.extras=A.extras),i})}}function sA(A,t){const e=new Image;e.crossOrigin="",e.onload=()=>{if(!tA)return void t(new Error("There is no canvas to draw image!"));tA.width=e.width,tA.height=e.height;const A=tA.getContext("2d",{willReadFrequently:!0});A.drawImage(e,0,0,e.width,e.height);const s=A.getImageData(0,0,e.width,e.height),n={width:e.width,height:e.height,data:new Uint8Array(s.data)};t(null,n)},e.onerror=function(A){t(A)},e.src=A}let nA,iA;function rA(A,t){nA||(nA=new OffscreenCanvas(2,2),iA=nA.getContext("2d",{willReadFrequently:!0}));let e=null;if(y(A))e=fetch(A).then(A=>A.arrayBuffer()).then(A=>{const t=new Blob([new Uint8Array(A)]);return createImageBitmap(t)});else{const t=new Blob([A]);e=createImageBitmap(t)}e.then(oA.bind(this)).then(A=>{t(null,A)}).catch(A=>{console.warn(A),t(A)})}function oA(A){let{width:t,height:e}=A;aA(t)||(t=hA(t)),aA(e)||(e=hA(e));const s=this.options.maxTextureSize;s&&(t=Math.min(s,t),e=Math.min(s,e)),nA.width=t,nA.height=e,iA.drawImage(A,0,0,t,e),A.close();const n=iA.getImageData(0,0,t,e);return{width:t,height:e,data:new Uint8Array(n.data)}}function aA(A){return 0==(A&A-1)&&0!==A}function hA(A){return Math.pow(2,Math.floor(Math.log(A)/Math.LN2))}const IA=[];function cA(A,e,s,n,r,o){const a=[],h=t.quat.fromEuler([],s[0],s[1],s[2]),I=t.mat4.fromRotationTranslationScale([],h,e,n);return function(A){return new eA("",i[A]).load().then(A=>A)}(A).then(A=>{t.reshader.GLTFHelper.exportGLTFPack(A).getMeshesInfo().forEach((A,i)=>{const h=new t.reshader.Material({color:r||A.materialInfo.baseColorFactor}),c=new t.reshader.Mesh(A.geometry,h);c.setUniform("uPickingId",o+i);const g=c.getDefines();g.HAS_PICKING_ID=2,c.setDefines(g),c.translate=e,c.rotation=s,c.scaling=n,t.mat4.multiply(c.localTransform,I,A.nodeMatrix),c.originTransform=t.mat4.copy([],c.localTransform),c.originColor=r||A.materialInfo.baseColorFactor,a.push(c)}),o>100&&(a[0].properties.relatedMeshes=a.slice(1,2),a[1].properties.relatedMeshes=a.slice(0,1),a[2].properties.relatedMeshes=a.slice(3,4),a[3].properties.relatedMeshes=a.slice(2,3),a[4].properties.relatedMeshes=a.slice(5,6),a[5].properties.relatedMeshes=a.slice(4,5),a[6].properties.relatedMeshes=a.slice(0,6))}),a}function gA(A,t){return Math.abs(A)*Math.sign(t)}function fA(A,e){const s=A.getCoordinates(),i=e.coordinateToPointAtRes(s,e.getGLRes()),r=[i.x,i.y,0],o=CA(e,A.getTranslation());t.vec3.add(r,r,o);const a=function(A,t,e,s){return A._pointAtResToContainerPoint(t,e,s)}(e,new n.Point(r[0],r[1]),e.getGLRes());a.x+=85;const h=function(A,e,s,i){if(i){const r=s/A._getResolution(),o=A.width/2,a=A.height/2;IA[0]=(e.x-o)/o,IA[1]=e.y/a-1,IA[3]=i*r;const h=t.mat4.invert([],A.projViewMatrix);t.vec3.transformMat4(IA,IA,h);const I=A.getGLScale();return t.vec3.set(IA,IA[0]/I,IA[1]/I,IA[2]/I),t.vec3.scale(IA,IA,1/r),new n.Point(IA[0],IA[1])}{const t=A.containerPointToCoordinate(e);return A.coordinateToPointAtRes(t,s)}}(e,a,e.getGLRes());return Math.sqrt(Math.pow(h.x-r[0],2)+Math.pow(h.y-r[1],2))/5.272881136101205}function CA(A,e){if(!A)return e;const s=A.distanceToPointAtRes(e[0],e[1],A.getGLRes()),n=A.altitudeToPoint(e[2],A.getGLRes());return t.vec3.set([],gA(s.x,e[0]),gA(s.y,e[1]),gA(n,e[2]))}class uA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=340/177,e=cA("jiantou",[1.2*t,0,0],[0,0,90],[t,t,t],[89/255,206/255,147/255,0],7),s=cA("jiantou",[0,1.2*t,0],[0,0,180],[t,t,t],[89/255,206/255,147/255,0],8),n=cA("jiantou",[-1.2*t,0,0],[0,0,270],[t,t,t],[89/255,206/255,147/255,0],9),i=cA("jiantou",[0,-1.2*t,0],[0,0,0],[t,t,t],[89/255,206/255,147/255,0],10);return A.push(e,s,n,i),A}getMeshes(){return this._meshes}}class lA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("xuanzhuan",[0,0,0],[180,0,0],[340/177*.5,340/177*.5,340/177*.5],[50/255,130/255,184/255,.8],11);return A.push(t),A}getMeshes(){return this._meshes}}class wA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("yuanhuan",[0,0,0],[0,0,0],[340/177*.5,340/177*.5,340/177*.5],[149/255,179/255,199/255,.5],12);return A.push(t),A}getMeshes(){return this._meshes}}class QA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("plane",[0,0,0],[0,0,0],[10,10,10],[1,0,0,.5],16);return A.push(t),A}getMeshes(){return this._meshes}}class mA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("xyzScale",[0,0,0],[0,0,0],[2,2,2],null,113);return A.push(t),A}getMeshes(){return this._meshes}}const PA=[],bA=[],DA=[],yA=[],BA=[],dA=[177/170,177/170,177/170],pA=[1,2,3,4,12];class vA{constructor(){this.translate=new uA,this.rotation=new lA,this.scaling=new wA,this.planeHelper=new QA,this.xyzScaleHelper=new mA,this._meshes=this.AA(),this.tA=!0}AA(){const A={};A.translate=this.translate.getMeshes(),A.rotation=this.rotation.getMeshes(),A.scaling=this.scaling.getMeshes(),A.planeHelper=this.planeHelper.getMeshes(),A.xyzScale=this.xyzScaleHelper.getMeshes();const t=340/177,e=cA("yuanhuan41",[-2.745*t,2.745*t,0],[90,0,0],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],1),s=cA("yuanhuan41",[2.745*t,2.745*t,0],[-90,0,180],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],2),n=cA("yuanhuan41",[2.745*t,-2.745*t,0],[90,0,180],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],3),i=cA("yuanhuan41",[-2.745*t,-2.745*t,0],[-90,0,0],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],4),r=cA("yuanpan",[0,0,0],[90,0,0],[.5*t,.5*t,.5*t],[89/255,206/255,147/255,.5],5),o=cA("zzhou",[0,0,6.5],[90,0,0],[1,1,1],[14/255,127/255,191/255,1],6);return A.translate.push(e,s,n,i,r,o),A}updateMatrix(A,e,s,n,i){const r=e.getCoordinates(),o=A.coordinateToPointAtRes(r,A.getGLRes()),a=e.eA();t.vec3.set(bA,o.x,o.y,a);const h=t.vec3.copy(PA,i),I=CA(A,e.getTranslation());t.vec3.add(bA,bA,I),t.vec3.add(bA,bA,h);for(const i in this._meshes)for(let r=0;r<this._meshes[i].length;r++){const o=this._meshes[i][r];for(let r=0;r<o.length;r++){const a=o[r],h=a.getUniform("uPickingId"),I=t.vec3.copy(PA,a.translate),c=[a.rotation[0],a.rotation[1],a.rotation[2]],g=a.scaling;if(11===h&&(this.tA?(c[2]+=s,a.rotation[2]+=s):this.tA||(c[2]+=s,a.rotation[2]+=s,c[0]=360,c[2]-=90)),pA.indexOf(h)>-1)if(12!==h)g[0]+=n,g[1]+=n,g[2]+=n;else{const A=this._meshes.translate[4][0];g[0]=1.2*A.scaling[0],g[1]=1.2*A.scaling[0],g[2]=1.2*A.scaling[0]}let f=fA(e,A);if(f=t.vec3.set(DA,f,f,f),t.vec3.multiply(I,I,f),t.vec3.multiply(f,f,g),1===h||2===h||3===h||4===h){const A=t.vec3.multiply(BA,g,dA);t.vec3.multiply(I,I,A)}const C=t.quat.fromEuler(yA,c[0],c[1],c[2]);if(t.vec3.add(I,I,bA),"xyzScale"===i){const A=t.mat4.fromRotationTranslationScale([],C,I,f);t.mat4.multiply(a.localTransform,A,a.originTransform)}else t.mat4.fromRotationTranslationScale(a.localTransform,C,I,f)}}}getMeshes(A){const t={};return A?("xyzScale"===A?t[A]=this._meshes[A]:(t.translate=this._meshes.translate,"translate"!==A&&(t[A]=this._meshes[A])),t):t}sA(A){this.tA=A}dispose(){for(const A in this._meshes)for(let t=0;t<this._meshes[A].length;t++){const e=this._meshes[A][t];for(let A=0;A<e.length;A++){const t=e[A];t.geometry.dispose(),t.dispose()}}}}const MA=[],LA=[],EA=[],OA=new e.Point(0,0),FA=[],xA=[],UA=[];class VA{constructor(){this.nA=[],this.iA=[0,0,0],this.rA=[1,1,1],this.oA=[0,0,0]}aA(A){Array.isArray(A)?A.forEach(A=>{this.aA(A)}):(A.on("remove",this.hA,this),A.IA={coordinate:A.getCoordinates(),translation:A.getTranslation(),rotation:A.getRotation(),scale:A.getScale()},this.nA.push(A))}cA(){this.nA.forEach(A=>{A.off("remove",this.hA,this)}),this.nA=[]}gA(A,e,s,n,i,r,o){for(let o=0;o<this.nA.length;o++){const a=this.nA[o],h=a.getRotation(),I=a.getScale(),c=this.fA(r,a,n,s,e);let g=null;g=n>=0?n:n*(this.options&&this.options.scaleStrength||1);const f=t.vec3.add(UA,t.vec3.set(MA,g,g*(I[1]/I[0]),g*(I[2]/I[0])),I);if(Math.min(...f)<i){const A=Math.min(...f);f[0]=f[0]*(i/A),f[1]=f[1]*(i/A),f[2]=f[2]*(i/A)}const C=t.vec3.add(h,s,h);a.setCoordinates(c),this.CA(A,f,I);const u=a.getTranslation();a.setTRS(u,C,f)}t.vec3.set(UA,n,n,n),t.vec3.add(this.oA,s,this.oA),t.vec3.add(this.rA,UA,this.rA),t.vec3.add(this.iA,e,this.iA),A.indexOf("translate")>-1?o.fire("positionchange",{action:A,type:"positionchange",target:this.nA,center:this.getCoordinates(),scale:this.rA,rotation:this.oA,translation:this.iA,deltaTranslate:e,deltaRotation:s,deltaScale:n}):o.fire("transforming",{action:A,type:"transforming",target:this.nA,center:this.nA[0].getTransformOrigin(),scale:this.rA,rotation:this.oA,translation:this.iA,deltaTranslate:e,deltaRotation:s,deltaScale:n})}fA(A,e,s,n,i){const r=e.getCenter(),o=e.getTransformOrigin(),a=A.getGLRes(),h=A.coordinateToPointAtRes(r,a,OA);h.z=A.altitudeToPoint(r.z,a),t.vec3.set(FA,h.x,h.y,h.z||0);const I=A.coordinateToPointAtRes(o,a,OA);I.z=A.altitudeToPoint(o.z,a),t.vec3.set(xA,I.x,I.y,I.z||0);const c=t.vec3.sub(MA,FA,xA),g=t.quat.fromEuler(LA,0,0,n[2]);t.vec3.set(UA,s+1,s+1,s+1);const f=t.mat4.fromRotationTranslationScale(EA,g,i,UA);t.vec3.transformMat4(c,c,f),t.vec3.add(c,c,xA),OA.set(c[0],c[1]);const C=A.pointAtResToCoordinate(OA,a);return C.z=c[2]/A.altitudeToPoint(1,a),C}CA(A,t,e){return"x-scale"===A&&(t[1]=e[1],t[2]=e[2]),"y-scale"===A&&(t[0]=e[0],t[2]=e[2]),"z-scale"===A&&(t[0]=e[0],t[1]=e[1]),t}uA(){this.nA.forEach(A=>{if(A.IA){const{coordinate:t,translation:e,rotation:s,scale:n}=A.IA;A.setCoordinates(t),A.setTRS(e,s,n)}})}getScale(){return this.rA}getTranslation(){return this.iA}getRotation(){return this.oA}lA(){return this.nA[0]?this.nA[0].getLayer():null}getCoordinates(){let A=0,t=0,s=0;const n=this.nA.length;if(!n)return null;for(let e=0;e<n;e++){const n=this.nA[e].getCenter();A+=n.x,t+=n.y,s+=n.z||0}A/=n,t/=n,s/=n;const i=new e.Coordinate(A,t,s);for(let A=0;A<n;A++)this.nA[A].setTransformOrigin(i);return i}hA(A){const t=A.target,e=this.nA.indexOf(t);e>-1&&(delete t.IA,this.nA.splice(e,1))}getTargets(){return this.nA}eA(){let A=0;const t=this.nA.length;for(let e=0;e<t;e++){A+=this.nA[e].getPointZ()}return A/=t,A}wA(){for(let A=0;A<this.nA.length;A++)if(this.nA[A].isVisible())return!0;return!1}}const TA=[5,6,7,8,9,10],SA=[5,7,8,9,10],kA=[2,4,11],_A=[1,3,12],NA=[12,16],RA=[1,2,3,4],HA=[1,2,3,4,12],JA=[],KA=[],jA=[],zA=[],GA=[],ZA=[],YA=[];class qA extends(e.Eventable(e.Handlerable(e.Class))){constructor(A={}){super(A),this.options=A,this.mouseAction="moving",this.QA=this.options.mode||"translate",this.mA=!0,this.TransformHelper=new vA,this.PA=new VA,this.helperScene=new t.reshader.Scene([]),this.addToMapCount=0}enable(){return this.mA=!0,this.layerRenderer&&this.layerRenderer.setToRedraw(),this}disable(){return this.mA=!1,this.layerRenderer&&this.layerRenderer.setToRedraw(),this.map&&this.map.resetCursor(),this}setMode(A){this.QA=A,this.bA(),this.layerRenderer&&this.layerRenderer.setToRedraw()}getMode(){return this.QA}isEnable(){return this.mA}DA(A){TA.indexOf(A)>-1?this.QA="translate":kA.indexOf(A)>-1?this.QA="rotation":_A.indexOf(A)>-1?this.QA="scaling":"xyzScale"!==this.QA&&(this.QA="translate")}yA(){return this.QA}addTo(A){this.map&&(this.BA(),console.warn("transform control has been added to a map, it suggest remove from the map before")),this.addToMapCount++,this.map=A,this.container=A.getContainer(),A.on("dom:mousemove",this.dA,this),A.on("dom:mousedown",this.pA,this),A.on("dom:mouseup",this.vA,this),A.on("zooming moving dragrotating",this.MA,this),this.LA()}remove(){this.map&&this.container&&this.layerRenderer&&(this.BA(),this.TransformHelper.dispose(),this.layerRenderer.setToRedraw(),delete this.map,delete this.layer,delete this.layerRenderer,delete this.container,delete this.PA)}BA(){this.container&&this.map&&(this.map.off("dom:mousemove",this.dA,this),this.map.off("dom:mousedown",this.pA,this),this.map.off("dom:mouseup",this.vA,this),this.map.off("zooming moving dragrotating",this.MA,this),this.layer&&this.layer.off("renderend",this.render,this))}dA(A){if(this.EA()){if(this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},"moving"===this.mouseAction){const A=this.OA();this.currentPickingObject=this.FA(this.currentMousePosition,A,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.pickingId?(this.DA(this.currentPickingObject.pickingId),6===this.currentPickingObject.pickingId?this.xA(!0):this.xA(!1)):(this.xA(!1),this.DA()),this.UA()}this.VA(this.currentMousePosition)}}pA(A){if(!this.EA()||0!==A.domEvent.button)return;const t=this.OA();this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},this.TA=!0,this.currentPickingObject=this.FA(this.currentMousePosition,t,"meshes"),this.firstDownPoint=this.FA(this.currentMousePosition,t,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.meshId?(this.mouseAction="transform",this.SA(this.currentPickingObject.pickingId),this.map.config("zoomable",!1),this.map.config("draggable",!1),this.layerRenderer&&this.layerRenderer.setToRedraw()):(this.mouseAction="pan",this.map.config("zoomable",!0),this.map.config("draggable",!0),this.bA()),this.lastMousePosition=this.currentMousePosition,this.lastPickingObject=this.currentPickingObject,this.lastPickingMesh=t[this.currentPickingObject.meshId]}vA(){"transform"===this.mouseAction&&(this.firstDownPoint=null,this.bA(),this.TA=!0,this.fire("transformend",{action:this.kA,type:"transformend"})),this.mouseAction="moving","xyzScale"!==this.QA&&(this.QA="translate"),this.map.config("zoomable",!0),this.map.config("draggable",!0),this.layerRenderer&&this.layerRenderer.setToRedraw()}MA(){const A=this.TransformHelper.planeHelper.getMeshes()[0][0],t=this.map.getBearing();A.rotation[2]=-t,this._A()}_A(){this.EA()&&(this.TransformHelper.updateMatrix(this.map,this.PA,0,0,[0,0,0]),this.TA=!0)}picked(A){if(!this.layerRenderer)return!1;const t=this.OA(),s=this.map;let n=A;A instanceof e.Point||(n=s.coordinateToContainerPoint(new e.Coordinate(A)));const i=this.FA(n,t,"picked");return!(!i||null===i.meshId)}bA(){const A=this.TransformHelper.getMeshes("scaling").scaling[0][0];A.scaling=[340/177*.6,340/177*.6,340/177*.6],this.layerRenderer&&(this.NA(A),this.RA())}RA(){this.TransformHelper._meshes.translate.forEach(A=>{for(let t=0;t<A.length;t++){const e=A[t];RA.indexOf(e.getUniform("uPickingId"))>-1&&e.material.set("color",e.originColor)}})}NA(A){const e=this.PA.getCoordinates(),s=this.map.coordinateToPointAtRes(e,this.map.getGLRes()),n=[s.x,s.y,0],i=CA(this.map,this.PA.getTranslation());t.vec3.add(n,n,i);const r=t.vec3.copy([],A.translate),o=A.scaling;let a=fA(this.PA,this.map);a=t.vec3.set([],a,a,a),t.vec3.multiply(r,r,a),t.vec3.multiply(a,a,o),t.vec3.add(r,r,n),t.mat4.fromRotationTranslationScale(A.localTransform,[0,0,0,1],r,a);this.OA().forEach(A=>{const e=A.getUniform("uPickingId");if(1===e||3===e||2===e||4===e){const e=t.vec3.copy([],A.translate),s=170/177;A.scaling=[s,s,s];const i=A.scaling,r=A.rotation;let o=fA(this.PA,this.map);o=t.vec3.set([],o,o,o),t.vec3.multiply(e,e,o),t.vec3.multiply(o,o,i),t.vec3.add(e,e,n);const a=t.quat.fromEuler([],r[0],r[1],r[2]);t.mat4.fromRotationTranslationScale(A.localTransform,a,e,o)}})}HA(A){const t=this.map.containerPointToCoordinate(A),e=this.map.coordinateToPointAtRes(t,this.map.getGLRes());return{point:[e.x,e.y]}}VA(A){if("transform"===this.mouseAction){const A=this.yA(),s=CA(this.map,this.PA.getTranslation()),n=this.PA.eA();let i=null,r=null;if(s[2]+n<.01&&"z-translate"!==this.kA)i=this.HA(this.currentMousePosition),r=this.HA(this.lastMousePosition);else{const A=this.TransformHelper.planeHelper.getMeshes()[0];if(i=this.FA(this.currentMousePosition,A,"plane"),r=this.FA(this.lastMousePosition,A,"plane"),!i||null===i.meshId||!r||null===r.meshId)return}const o=[0,0,0],a=[0,0,0];let h=0,I=0,c=0;if("translate"===A){if("xy-translate"===this.kA){const A=i.point[0]-r.point[0],t=i.point[1]-r.point[1];o[0]=A,o[1]=t}else if("x-translate"===this.kA){const A=i.point[0]-r.point[0];o[0]=A}else if("y-translate"===this.kA){const A=i.point[1]-r.point[1];o[1]=A}else if("z-translate"===this.kA){let A=0;if(this.JA()){const s=this.map.getGLRes(),n=this.map._pointAtResToContainerPoint(new e.Point(r.point[0],r.point[1]),s),o=this.map._pointAtResToContainerPoint(new e.Point(i.point[0],i.point[1]),s),a=t.vec2.length(t.vec2.set(zA,i.point[0]-r.point[0],i.point[1]-r.point[1]));A=o.y<n.y?a:-a}else A=i.point[2]-r.point[2];o[2]=A}}else if("rotation"===A)I=this.KA(i.point,r.point),I>=0?this.TransformHelper.sA(!0):this.TransformHelper.sA(!1),a[2]+=I;else if("scaling"===A||"xyzScale"===A){const A=this.jA(),e=t.vec2.length(t.vec2.set(zA,this.firstDownPoint.point[0]-A[0],this.firstDownPoint.point[1]-A[1])),s=t.vec2.length(t.vec2.set(zA,r.point[0]-A[0],r.point[1]-A[1]));h=this.zA(i.point,r.point,A,s),c=this.zA(i.point,r.point,A,e)}this.TransformHelper.updateMatrix(this.map,this.PA,I,c,o),this.PA.gA(this.kA,o,a,h,.01,this.map,this)}this.lastMousePosition=A,this.lastPickingObject=this.currentPickingObject;const s=this.OA();this.lastPickingMesh=s[this.currentPickingObject.meshId]}zA(A,e,s,n,i){const r=(t.vec2.length(t.vec2.set(zA,A[0]-s[0],A[1]-s[1]))-t.vec2.length(t.vec2.set(zA,e[0]-s[0],e[1]-s[1])))/n;return i?(i[0]-.01)*r:r}jA(){const A=this.map,e=this.PA.getCoordinates(),s=A.coordinateToPointAtRes(e,A.getGLRes()),n=t.vec3.set(GA,s.x,s.y,0),i=CA(A,this.PA.getTranslation());return t.vec3.add(n,n,i),n}xA(A){const e=this.TransformHelper.planeHelper.getMeshes()[0][0],s=t.mat4.getTranslation(jA,e.localTransform),n=t.mat4.getScaling(KA,e.localTransform);let i=t.quat.fromEuler(JA,0,0,0);const r=this.map.getBearing();A&&!this.JA()?(i=t.quat.fromEuler(JA,90,0,-r),0===e.rotation[0]&&(this.TA=!0),t.vec3.set(e.rotation,90,0,-r)):(90===e.rotation[0]&&(this.TA=!0),t.vec3.set(e.rotation,0,0,-r)),t.mat4.fromRotationTranslationScale(e.localTransform,i,s,n)}JA(){if(this.map.getPitch())return!1;const A=this.map.cameraPosition,e=this.map.coordinateToPointAtRes(this.map.getCenter(),this.map.getGLRes());t.vec3.set(e,e.x,e.y,0);const s=this.PA.getCoordinates(),n=this.map.coordinateToPointAtRes(s,this.map.getGLRes()),i=CA(this.map,this.PA.getTranslation()),r=t.vec3.set(jA,n.x,n.y,0),o=t.vec3.add(r,r,i),a=t.vec3.subtract([],A,o),h=t.vec3.subtract([],A,e);return t.vec3.angle(a,h)<1/180*Math.PI}UA(){const A=this.OA();if(this.currentPickingObject&&null!=this.currentPickingObject.meshId){this.GA(),this.lastPickingObject&&null!=this.lastPickingObject.meshId&&this.lastPickingObject.meshId!==this.currentPickingObject.meshId&&this.ZA();const t=A[this.currentPickingObject.meshId];if(t&&NA.indexOf(this.currentPickingObject.pickingId)<0)if(this.currentPickingObject.pickingId>100)this.YA(t);else{const A=[t.originColor[0],t.originColor[1],t.originColor[2],.8];t.material.set("color",A),this.qA(t,.5)}this.layerRenderer.setToRedraw()}else this.lastPickingObject&&null!=this.lastPickingObject.meshId&&(this.map.resetCursor(),this.ZA(),this.layerRenderer.setToRedraw())}YA(A){const t=[1,179/255,2/255,1];A.material.set("color",t),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach(A=>{A.material.set("color",t)})}GA(){6===this.currentPickingObject.pickingId?this.map.setCursor("ns-resize"):SA.indexOf(this.currentPickingObject.pickingId)>-1?this.map.setCursor("move"):this.map.setCursor("pointer")}ZA(){const A=this.lastPickingMesh;if(!A)return;const t=A.getUniform("uPickingId"),e=this.OA();SA.indexOf(t)>-1?e.forEach(A=>{SA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)}):HA.indexOf(t)>-1?e.forEach(A=>{const t=A.getUniform("uPickingId");RA.indexOf(t)>-1&&A.material.set("color",A.originColor)}):11===t&&e.forEach(A=>{RA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)}),A.material.set("color",A.originColor),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach(A=>{A.material.set("color",A.originColor)})}qA(A,t){const e=A.getUniform("uPickingId"),s=this.OA();SA.indexOf(e)>-1?s.forEach(e=>{if(SA.indexOf(e.getUniform("uPickingId"))>-1&&e.getUniform("uPickingId")!==A.getUniform("uPickingId")){const A=[e.originColor[0],e.originColor[1],e.originColor[2],t];e.material.set("color",A)}}):"scaling"===this.QA?s.forEach(A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=[149/255,179/255,199/255,.8];A.material.set("color",t)}}):"rotation"===this.QA&&s.forEach(A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=A.originColor;A.material.set("color",[t[0],t[1],t[2],0])}})}reset(){this.map&&this.PA&&(this.PA.uA(),this.TransformHelper.updateMatrix(this.map,this.PA,0,0,[0,0,0]))}KA(A,e){const s=this.jA(),n=t.vec2.set(ZA,e[0]-s[0],e[1]-s[1]),i=t.vec2.set(YA,A[0]-s[0],A[1]-s[1]),r=Math.atan2(n[1],n[0]);return(Math.atan2(i[1],i[0])-r)/Math.PI*180}SA(A){return this.kA=113===A||114===A?"x-scale":115===A||116===A?"z-scale":117===A||118===A?"y-scale":119===A?"xyz-scale":5===A?"xy-translate":6===A?"z-translate":7===A||9===A?"x-translate":8===A||10===A?"y-translate":11===A?"z-rotate":"scale",this.kA}transform(A){if(!A)return;if(this.layerRenderer&&this.layerRenderer.layer&&(this.layerRenderer.layer.off("renderend",this.render),this.layerRenderer.layer.off("resizeCanvas",this.WA)),!this.map)return void console.error("should add to a target first");if(this.PA&&(this.PA.cA(),this.PA.aA(A)),!this.PA.getTargets().length)return;const t=this.map;this.TransformHelper.updateMatrix(t,this.PA,0,0,[0,0,0]),this.XA(),this.TA=!0}getTransformTarget(){return this.PA}hA(){delete this.PA}XA(){const A=this.PA.lA();A&&(A.off("renderend",this.render),A.off("resizeCanvas",this.WA));const e=this.map.getLayers();let s=null;for(let A=0;A<e.length;A++)if(e[A]instanceof t.GroupGLLayer){s=e[A];break}if(!s)return;const n=s.getLayers(),i=n.indexOf(A);if(i<0)return;n.splice(i,1),n.push(A);const r=this.map,o=A.getRenderer();this.layerRenderer=o,this.regl=o.regl,this.renderer=o.renderer,this.$A=this.layerRenderer.getFBORayPicking(),this.At={projViewMatrix:r.projViewMatrix},A.on("renderend",this.render,this),A.on("resizeCanvas",this.WA,this),o.setToRedraw()}WA(){this.$A.clear(),this.TA=!0}FA(A,t,e){const s=this.map;if(!(s&&this.$A&&this.layerRenderer&&this.layerRenderer.canvas))return null;const n=s.getDevicePixelRatio(),i=A.x*n,r=A.y*n,o={projViewMatrix:this.map.projViewMatrix,pointSize:1},a=this.layerRenderer.canvas.gl&&this.layerRenderer.canvas.gl.wrap;(this.TA||a||!this.tt||this.tt!==e)&&(this.$A.render(t,o,!0),this.tt=e,this.TA=!1);return this.$A.pick(i,r,10,o,{viewMatrix:this.map.viewMatrix,projMatrix:this.map.projMatrix,returnPoint:!0})}LA(){const A=this.map.getDevicePixelRatio(),e={x:0,y:0,width:()=>this.map?this.map.width*A:1,height:()=>this.map?this.map.height*A:1};this.et=new t.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main()\n\n{\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n\n\n}\n\n",frag:"precision mediump float;\n\nuniform vec4 color;\n\n\n\nvoid main() {\n\n gl_FragColor = color;\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:function(A,e){return t.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}}],extraCommandProps:{viewport:e,depth:{enable:!0,func:"always",mask:!0,range:[0,0]},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}},defines:{}})}render(){if(!this.EA())return;const A=this.OA();this.helperScene.setMeshes(A);const t=this.layerRenderer.getFrameContext();if(t&&t.renderTarget&&this.layerRenderer.getFrameTimestamp()!==t.timestamp)return;this._A(),this.et.filter=t&&t.sceneFilter;const e=t&&t.renderTarget&&t.renderTarget.fbo;this.renderer.render(this.et,this.At,this.helperScene,e)}OA(){let A=[];const t=this.TransformHelper.getMeshes(this.QA);for(const e in t){if("translate"===e)continue;const s=t[e];for(let t=0;t<s.length;t++)A=A.concat(s[t])}const e=t.translate;if(e)for(let t=0;t<e.length;t++)A=A.concat(e[t]);return A}EA(){const A=this.layerRenderer,t=A&&A.layer;return A&&this.PA&&t&&t.isVisible()&&this.PA.wA()&&this.regl&&this.mA}}qA.mergeOptions({scaleStrength:2}),A.TransformControl=qA,Object.defineProperty(A,"A",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/transform-control v0.91.2")}));
|
|
12
|
+
let P=0;function b(A){return null==A}function D(A){return!b(A)}function y(A){return!b(A)&&("string"==typeof A||null!==A.constructor&&A.constructor===String)}function B(A){for(let t=1;t<arguments.length;t++){const e=arguments[t];for(const t in e)A[t]=e[t]}return A}function d(A){switch(A){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+A)}function p(A){return 0===A.indexOf("data:")&&A.indexOf("base64,")>0}function v(A){const t=function(A){return"undefined"!=typeof self?self.atob(A):window.atob(A)}(A.substring(A.indexOf(",")+1)),e=t.length,s=new Uint8Array(e);for(let A=0;A<e;A++)s[A]=t.charCodeAt(A);return s.buffer}const M=[],L=[],E=[],O=[0,0,0],F=function(A){return A[0]=0,A[1]=0,A[2]=0,A[3]=1,A}([]),x=[1,1,1];function U(A,t,e,s,n,i,r){const o=d(r);if((0===n||n===s*o.BYTES_PER_ELEMENT)&&i%o.BYTES_PER_ELEMENT==0){const n=new o(t,i,e*s);return A.set(n),A}0===n&&(n=s*o.BYTES_PER_ELEMENT);const a=new Uint8Array(s*o.BYTES_PER_ELEMENT);for(let r=0;r<e;r++){let e=null;const h=new Uint8Array(t,n*r+i,s*o.BYTES_PER_ELEMENT);a.set(h),e=new o(a.buffer,0,s);for(let t=0;t<s;t++)A[r*s+t]=e[t]}return A}const V="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function T(A,t,e){const s=new Uint8Array(A,t,e);return V.decode(s)}const S={get:function(A,t={}){t||(t={});const e=new AbortController,s=e.signal,n=B({},t);n.signal=s,n.method||(n.method="GET");const i=fetch(A,n).then(A=>{const e=this.t(A,t.responseType);return e.message?e:e.then(e=>"arraybuffer"===t.responseType?{data:e,cacheControl:A.headers.get("Cache-Control"),expires:A.headers.get("Expires"),contentType:A.headers.get("Content-Type")}:e).catch(A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A})}).catch(A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A});return i.xhr=e,i},t:(A,t)=>200!==A.status?{status:A.status,statusText:A.statusText,message:`incorrect http request with status code(${A.status}): ${A.statusText}`}:"arraybuffer"===t?A.arrayBuffer():"json"===t?A.json():A.text(),getArrayBuffer:(A,t={})=>(t||(t={}),t.responseType="arraybuffer",S.get(A,t)),getJSON:function(A,t={}){return t&&t.jsonp?S.jsonp(A):((t=t||{}).responseType="json",S.get(A,t))},jsonp:function(A){const t="_maptalks_jsonp_"+P++;A.match(/\?/)?A+="&callback="+t:A+="?callback="+t;let e=document.createElement("script");return e.type="text/javascript",e.src=A,new Promise(A=>{window[t]=function(s){document.getElementsByTagName("head")[0].removeChild(e),e=null,delete window[t],A(s)},document.getElementsByTagName("head")[0].appendChild(e)})}};class k{constructor(A,t,e){this.s=A,this.decoders=t,this.i=e,this.images={},this.o={}}requestImageFromBufferURI(A,t,e){if(this.buffers[A.id]){const s=this.buffers[A.id],n=this.h(t,s);return this.getImageByBuffer(n,e)}if(this.o[A.id])return this.o[A.id].then(()=>{const s=this.buffers[A.id],n=this.h(t,s);return this.getImageByBuffer(n,e)});if(p(A.uri)){const s=this.buffers[A.id]=v(A.uri),n=this.h(t,s);return this.getImageByBuffer(n,e)}let s;const n=A.uri.indexOf("blob:")>=0;return s=A.uri.indexOf("://")>0||n?A.uri:this.rootPath+"/"+A.uri,this.o[A.id]=S.getArrayBuffer(s,null).then(s=>{const n=this.buffers[A.id]=s.data,i=this.h(t,n);return this.getImageByBuffer(i,e)})}getImageByBuffer(A,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=this.decoders;return e[t.mimeType]?e[t.mimeType](A,{supportedFormats:this.i}):"image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType?(console.warn("missing transcoder for "+t.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.I(t.id,A)}requestExternalImage(A){if(this.images[A.id])return Promise.resolve(this.images[A.id]);const t=0===A.uri.indexOf("data:image/")?A.uri:this.rootPath+"/"+A.uri;return this.o[A.id]?this.o[A.id].then(()=>this.images[A.id]):this.o[A.id]=this.I(A.id,t)}I(A,t){return new Promise((e,s)=>{this.s(t,(n,i)=>{n?s(n):(URL.revokeObjectURL(t),this.images[A]=i,e(this.images[A]))})})}}const _=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],N=[];class R{constructor(A,t,e){this.rootPath=A,this.gltf=t,this.g=!1,this.glbBuffer=e,this.buffers={},this.requests={},this.accessors={},this.C()}u(A,t){const e=this.gltf,s=e.accessors[t];if(void 0===s.bufferView)return this.accessors[s.id]=this.l(A,t,null,0),Promise.resolve(this.accessors[s.id]);if(s&&this.accessors[s.id])return Promise.resolve(this.accessors[s.id]);const n=e.bufferViews[s.bufferView];return this.m(n).then(e=>{const{buffer:n,byteOffset:i}=e;return this.accessors[s.id]=this.l(A,t,n,i)})}m(A){const t=this.gltf.buffers[A.buffer];if(this.buffers[t.id]){const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then(()=>{const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})});if("binary_glTF"!==A.buffer&&"KHR_binary_glTF"!==A.buffer&&t.uri){if(p(t.uri)){const A=this.buffers[t.id]=v(t.uri);return Promise.resolve({buffer:A,byteOffset:0})}let A;const e=t.uri.indexOf("blob:")>=0;return A=t.uri.indexOf("://")>0||e?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=S.getArrayBuffer(A,null).then(s=>(e&&URL.revokeObjectURL(A),{buffer:this.buffers[t.id]=s.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}l(A,t,e,s=0){const n=this.gltf,i=n.accessors[t],r=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(r.byteOffset||0)+s,a=this.P(i.type),h=d(i.componentType),I=r.byteStride||0,c={array:void 0,name:A,accessorName:t,byteLength:i.count*a*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:a,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(c.min=i.min),i.max&&(c.max=i.max),e)if(this.g)c.byteStride=I,c.byteOffset=o+(i.byteOffset||0),!I||I===a*h.BYTES_PER_ELEMENT||"indices"===A||"input"===A||"output"===A||A.indexOf("morph")>=0?(c.array=this.D(e,i.count,a,o+(i.byteOffset||0),h),c.array.buffer.byteLength===c.byteLength&&(c.byteOffset=0)):c.array=new Uint8Array(e,o,r.byteLength);else if(i.interleaved){c.byteStride=0,c.byteOffset=0;const A=new h(i.count*a);if(c.array=U(A,e,i.count,a,I,o+(i.byteOffset||0),i.componentType),c.extensions&&c.extensions.WEB3D_quantized_attributes&&a>2){const A=new Float32Array(c.array.length),{decodeMatrix:t}=c.extensions.WEB3D_quantized_attributes;for(let e=0;e<c.array.length;e+=a){N[0]=c.array[e],N[1]=c.array[e+1],N[2]=c.array[e+2],N[3]=1;const s=u(N,N,t);A[e]=s[0],A[e+1]=s[1],A[e+2]=s[2]}c.componentType=5126,c.array=A}}else c.byteStride=0,c.array=this.D(e,i.count,a,o+(i.byteOffset||0),h),c.byteOffset=c.array.byteOffset;else{c.array=new h(i.count);const A=c.min||c.max;A&&(c.array[0]=A[0],c.array[1]=A[1],c.array[2]=A[2])}return c}C(){const A=this.gltf.accessors;if(Array.isArray(A))for(let t=0;t<A.length;t++)for(let e=0;e<A.length;e++)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0);else for(const t in A)for(const e in A)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0)}D(A,t,e,s,n){return s%n.BYTES_PER_ELEMENT!=0&&(A=A.slice(s,s+t*e*n.BYTES_PER_ELEMENT),s=0),new n(A,s,e*t)}P(A){const t=_.indexOf(A);return _[t+1]}requestKHRTechniquesWebgl(A){const{shaders:t}=A,e=t.map(A=>{if(void 0!==A.bufferView){const t=this.gltf.bufferViews[A.bufferView],{byteLength:e}=t;return this.m(t).then(s=>{const{buffer:n,byteOffset:i}=s,r=T(n,i+(t.byteOffset||0),e);return A.content=r,A})}if(A.uri){if(p(A.uri)){const t=v(A.uri),e=T(t,0,t.byteLength);return A.content=e,Promise.resolve(A)}{const t=this.rootPath+"/"+A.uri;return S.get(t).then(t=>(A.content=t,A))}}return Promise.resolve(A)});return Promise.all(e).then(()=>A)}}class H extends k{constructor(A,t,e,s,n,i){super(s,n,i),this.rootPath=A,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=e,this.accessor=new R(A,t,e)}iterate(A,t){const e=this.gltf[t];if(!e)return;let s=0;for(const t in e)A(t,e[t],s++)}createNode(A){const t={};if(D(A.name)&&(t.name=A.name),D(A.children)&&(t.children=A.children),D(A.jointName)&&(t.jointName=A.jointName),D(A.matrix)&&(t.matrix=A.matrix),D(A.rotation)&&(t.rotation=A.rotation),D(A.scale)&&(t.scale=A.scale),D(A.translation)&&(t.translation=A.translation),D(A.extras)&&(t.extras=A.extras),D(A.meshes)&&(t.mesh=A.meshes[0]),t.translation||t.rotation||t.scale){const A=function(A,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const e=function(A,t){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=t[0],A[13]=t[1],A[14]=t[2],A[15]=1,A}(M,t.translation||O),s=function(A,t){var e=t[0],s=t[1],n=t[2],i=t[3],r=e+e,o=s+s,a=n+n,h=e*r,I=s*r,c=s*o,g=n*r,f=n*o,C=n*a,u=i*r,l=i*o,w=i*a;return A[0]=1-c-C,A[1]=I+w,A[2]=g-l,A[3]=0,A[4]=I-w,A[5]=1-h-C,A[6]=f+u,A[7]=0,A[8]=g+l,A[9]=f-u,A[10]=1-h-c,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(L,t.rotation||F),n=function(A,t){return A[0]=t[0],A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=t[1],A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=t[2],A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(E,t.scale||x);return o(n,s,n),o(A,e,n)}return function(A){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(A)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=A}return t}B(A){const t={};for(const e in A){const s=A[e];let n,i;s.instanceTechnique&&s.instanceTechnique.values?(n=s.instanceTechnique,i=n.values.diffuse):(n=s,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const r={baseColorTexture:{index:i}};s.name&&(r.name=s.name),s.extensions&&(r.extensions=s.extensions),s.extras&&(r.extras=s.extras),t[e]=r}return t}p(A){if(A.bufferView||A.extensions&&(A.extensions.KHR_binary_glTF||A.extensions.binary_glTF)){const t=A.bufferView?A:A.extensions.KHR_binary_glTF||A.extensions.binary_glTF;A.extensions&&(A.mimeType=t.mimeType,A.width=t.width,A.height=t.height);const e=this.gltf.bufferViews[t.bufferView],s=(e.byteOffset||0)+this.glbBuffer.byteOffset,n=e.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,s,n);return this.getImageByBuffer(i,A)}return this.requestExternalImage(A)}v(A){const t=this.gltf.textures[A];if(!t)return null;const e=this.gltf.images[t.source];return this.p(e).then(A=>{const s=this.gltf.samplers[t.sampler];return{image:{array:A.data,width:A.width,height:A.height,index:t.source,mimeType:e.mimeType,name:e.name,extras:e.extras},sampler:s}})}getBaseColorTexture(A){const t=this.gltf.materials[A];let e,s;if(t.instanceTechnique&&t.instanceTechnique.values?(e=t.instanceTechnique,s=e.values.diffuse):(e=t,s=e.values.tex||e.values.diffuseTex||e.values.diffuse),void 0===s||void 0===this.gltf.textures)return null;const n=this.gltf.textures[s];if(!n)return null;const i=this.gltf.samplers[n.sampler];return{format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}class J extends k{constructor(A,t,e,s,n,i){super(s,n,i),this.rootPath=A,this.gltf=t,this.glbBuffer=e,this.buffers={},this.requests={},this.accessor=new R(A,t,e)}iterate(A,t){const e=this.gltf[t];if(e)for(let t=0;t<e.length;t++)A(t,e[t],t)}createNode(A){const t={};return B(t,A),!D(A.weights)&&this.gltf.meshes&&D(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:A.weights&&(t.weights=A.weights),t}v(A){const t=this.gltf.textures[A];if(!t)return null;let e=t.source;if(t.extensions&&t.extensions.EXT_texture_webp&&(e=t.extensions.EXT_texture_webp.source),!D(e))return null;const s=this.gltf.images[e];return this.p(s).then(A=>{if(!A)return null;const e={image:{array:A.data,mipmap:A.mipmap,width:A.width,height:A.height,index:t.source,mimeType:s.mimeType,name:s.name,extensions:s.extensions,extras:s.extras}};B(e,t);const n=D(t.sampler)?this.gltf.samplers[t.sampler]:void 0;return n&&(e.sampler=n,e.sampler.magFilter=n.magFilter||9729,e.sampler.minFilter=n.minFilter||9729,e.sampler.wrapS=n.wrapS||10497,e.sampler.wrapT=n.wrapT||10497),A.format&&(e.format=A.format),e})}p(A){if(!D(A.bufferView))return this.requestExternalImage(A);{const t=this.gltf.bufferViews[A.bufferView],e=this.gltf.buffers[t.buffer];if(e.uri)return this.requestImageFromBufferURI(e,t,A);if(this.glbBuffer)return this.M(t,A)}return null}M(A,t){const e=this.h(A,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(e,t)}h(A,t,e){e=e||0;const s=A.byteOffset+e,n=A.byteLength;return new Uint8Array(t,s,n)}L(A,t){const e=new Array(A.byteLength);for(let t=0;t<A.byteLength;t++)e[t]=String.fromCharCode(A[t]);return e.join(""),"data:"+(t=t||"image/png")+";base64,"+function(A){return"undefined"!=typeof self?self.btoa(A):window.btoa(A)}(unescape(encodeURIComponent(e)))}getAnimations(A){const t=[];return A.forEach(A=>{t.push(this.getSamplers(A.samplers))}),Promise.all(t).then(t=>{for(let e=0;e<t.length;e++)A[e].samplers=t[e];return A})}getSamplers(A){const t=[];for(let e=0;e<A.length;e++)(D(A[e].input)||D(A[e].output))&&(t.push(this.accessor.u("input",A[e].input)),t.push(this.accessor.u("output",A[e].output)));return Promise.all(t).then(t=>{for(let e=0;e<t.length/2;e++)A[e].input=t[2*e],A[e].output=t[2*e+1],A[e].interpolation||(A[e].interpolation="LINEAR");return A})}}const K="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class j{static read(A,t=0,e=0){e||(e=A.byteLength);const s=new DataView(A,t,e),n=s.getUint32(4,!0);if(1===n)return j.readV1(s,t);if(2===n)return j.readV2(A,t);throw new Error("Unsupported glb version : "+n)}static readV1(A,t){const e=A.getUint32(8,!0),s=A.getUint32(12,!0);if(e!==A.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=z(A.buffer,20+t,s);return{json:JSON.parse(n),glbBuffer:{byteOffset:20+t+s,buffer:A.buffer,byteLength:e}}}static readV2(A,t){let e,s,n;const i=new DataView(A,t+12);let r=0;for(;r<i.byteLength;){const o=i.getUint32(r,!0);r+=4;const a=i.getUint32(r,!0);if(r+=4,1313821514===a)e=z(A,t+12+r,o);else if(5130562===a){n=t+12+r,s=o;break}r+=o}return{json:JSON.parse(e),glbBuffer:{byteOffset:n,buffer:A,byteLength:s}}}}function z(A,t,e){if(K){const s=new Uint8Array(A,t,e);return K.decode(s)}return function(A){const t=A.length;let e="";for(let s=0;s<t;){let n=A[s++];if(128&n){let e=G[n>>3&7];if(!(64&n)||!e||s+e>t)return null;for(n&=63>>e;e>0;e-=1){const t=A[s++];if(128!=(192&t))return null;n=n<<6|63&t}}e+=String.fromCharCode(n)}return e}(new Uint8Array(A,t,e))}const G=[1,1,1,1,2,2,3,0],Z=[0,0,0],Y=[0,0,0,1],q=[1,1,1],W={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},X={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},$={O(A,t,e,s,n,i,r,o){const a=D(A)?t.animations:[t.animations[0]],h={};for(let t=0;t<a.length;t++){const c=a[t],g=c.name||t;if(D(A)&&g!==A)continue;const f=c.channelsMap[e];if(f)for(let A=0;A<f.length;A++){const t=f[A];"translation"===t.target.path?(this.F(n,c.samplers[t.sampler],s,1),h.translation=I(Z,n)):"rotation"===t.target.path?(this.U(i,c.samplers[t.sampler],s,1),h.rotation=m(Y,i)):"scale"===t.target.path?(this.F(r,c.samplers[t.sampler],s,1),h.scale=I(q,r)):"weights"===t.target.path&&o&&(this.F(o,c.samplers[t.sampler],s,o.length),h.weights=o)}}return h},F(A,t,e,s){switch(t.interpolation){case"LINEAR":{const n=this.V(X,t,e,1*s);n&&(A=function(A,t,e,s){for(let n=0;n<A.length;n++)A[n]=t[n]+s*(e[n]-t[n]);return A}(A,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this.V(X,t,e,1*s);n&&(A=function(A,t){for(let e=0;e<A.length;e++)A[e]=t[e];return A}(A,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.V(X,t,e,3*s);n&&(A=this.T(A,n,t.input.array,3*s));break}}return A},U(A,t,e){switch(t.interpolation){case"LINEAR":{const s=this.V(X,t,e,1);s&&w(A,s.PREVIOUS,s.NEXT,s.INTERPOLATION);break}case"STEP":{const s=this.V(X,t,e,1);s&&(A=C(A,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.V(X,t,e,3);if(s){for(let A=0;A<s.PREVIOUS.length;A++)s.PREVIOUS[A]=Math.acos(s.PREVIOUS[A]),s.NEXT[A]=Math.acos(s.NEXT[A]);A=this.T(A,s,t.input.array,3);for(let t=0;t<A.length;t++)A[t]=Math.cos(A[t])}break}}return A},S(A,t){const e=A.length;let s,n,i,r=0,o=e-1,a=Math.floor((r+o)/2);for(;r<=e-1&&o>=0;){if(r===o)return null;if(A[a]<=t&&t<=A[a+1]){const e=A[a];return s=a,n=a+1,i=(t-e)/(A[a+1]-e),{preIndx:s,nextIndex:n,interpolation:i}}t<A[a]?(o=a,a=Math.floor((r+o)/2)):A[a+1]<t&&(r=a,a=Math.floor((r+o)/2))}return null},V(A,t,e,s){const n=t.input.array,i=t.output.array,r=t.output.itemSize;(e<n[0]||e>n[n.length-1])&&(e=Math.max(n[0],Math.min(n[n.length-1],e))),e===n[n.length-1]&&(e=n[0]);const o=this.S(n,e);if(!o||!o.nextIndex)return null;const{preIndx:a,nextIndex:h,interpolation:I}=o;A.PREINDEX=a,A.NEXTINDEX=h,A.INTERPOLATION=I;const c=r*s;return A.PREVIOUS=i.subarray(A.PREINDEX*c,(A.PREINDEX+1)*c),A.NEXT=i.subarray(A.NEXTINDEX*c,(A.NEXTINDEX+1)*c),A},T(A,t,e,s){const n=t.INTERPOLATION,i=e[t.PREINDEX],r=e[t.NEXTINDEX];for(let e=0;e<3;e++){const o=t.PREVIOUS[s+e],a=(r-i)*t.PREVIOUS[2*s+e],h=t.NEXT[3+e],I=(r-i)*t.NEXT[e],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*a+(2*-Math.pow(n,3)+3*Math.pow(n,2))*h+(Math.pow(n,3)-Math.pow(n,2))*I;A[e]=c}return A},getAnimationClip(A,t,e,s){const n=A.nodes[t]&&A.nodes[t].weights;return c(Z,...W.TRANSLATION),C(Y,...W.ROTATION),c(q,...W.SCALE),this.O(s,A,t,e,Z,Y,q,n)},getTimeSpan(A){if(!A.animations)return null;if(A.timeSpan)return A.timeSpan;const t=A.animations;return A.timeSpan={},t.forEach((t,e)=>{let s=-1/0,n=1/0;const i=t.channels;for(let A=0;A<i.length;A++){const e=i[A],r=t.samplers[e.sampler].input.array;r[r.length-1]>s&&(s=r[r.length-1]),r[0]<n&&(n=r[0])}const r=t.name||e;A.timeSpan[r]={max:s,min:n}}),A.timeSpan},getTimeSpanByName(A,t){const e=this.getTimeSpan(A);return e?D(t)?e[t]:e[Object.keys(e)[0]]:null}};let AA=!1;if("undefined"!=typeof OffscreenCanvas){let A;try{A=new OffscreenCanvas(2,2).getContext("2d")}catch(A){}A&&"undefined"!=typeof createImageBitmap&&(AA=!0)}const tA="undefined"==typeof document?null:document.createElement("canvas");class eA{constructor(A,t,e){if(this.options=e||{},this.options.decoders||(this.options.decoders={}),t.buffer instanceof ArrayBuffer){const{json:e,glbBuffer:s}=j.read(t.buffer,t.byteOffset,t.byteLength);this.k(A,e,s)}else this.k(A,t);this._=new R(this.rootPath,this.gltf,this.glbBuffer),this.N()}N(){const A=this.gltf.extensionsRequired;if(A){if(A.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(A.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}R(){const A=this.gltf.extensions;return A&&A.KHR_techniques_webgl?this._.requestKHRTechniquesWebgl(A.KHR_techniques_webgl).then(t=>(A.KHR_techniques_webgl=t,A)):Promise.resolve(A)}load(A){A=A||{};const t=this.H(A),e=this.J(),s=this.K(),n=this.R();return Promise.all([t,e,s,n]).then(A=>(A[0].animations=A[1],A[0].textures=A[2],A[0].extensions=A[3],A[0].transferables=this.transferables||[],this.createChannelsMap(A[0]),A[0]))}createChannelsMap(A){const t=A.animations;if(t)for(let A=0;A<t.length;A++){const e=t[A];e.channelsMap={};for(let A=0;A<e.channels.length;A++){const t=e.channels[A];e.channelsMap[t.target.node]||(e.channelsMap[t.target.node]=[]),e.channelsMap[t.target.node].push(t)}}}getExternalResources(){const A=[];if(this.gltf){const{buffers:t,images:e}=this.gltf;for(let e=0;e<t.length;e++)t[e].uri&&t[e].uri.indexOf("data:application/octet-stream;base64")<0&&A.push({type:"buffer",uri:t[e].uri});for(let t=0;t<e.length;t++)e[t].uri&&e[t].uri.indexOf("data:image/")<0&&A.push({type:"image",uri:e[t].uri})}return A}static getAnimationClip(A,t,e,s){return $.getAnimationClip(A,t,e,s)}static getAnimationTimeSpan(A,t){return $.getTimeSpanByName(A,t)}static getTypedArrayCtor(A){return d(A)}static readInterleavedArray(A,t,e,s,n,i,r){return U(A,t,e,s,n,i,r)}k(A,t,e){this.gltf=t,this.glbBuffer=e,this.version=t.asset?+t.asset.version:1,this.rootPath=A,this.buffers={},this.requests={},this.options.requestImage=AA?rA.bind(this):this.options.requestImage||sA,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new J(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((A,t,e)=>{t.id="buffer_"+e},"buffers"),this.adapter.iterate((A,t,e)=>{t.id="image_"+e},"images"),this.adapter.iterate((A,t,e)=>{t.id="accessor_"+e},"accessors")):(this.adapter=new H(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((A,t,e)=>{t.id="accessor_"+e},"accessors"),this.adapter.iterate((A,t,e)=>{t.id="image_"+e},"images"))}j(A,t){if(A.children&&A.children.length>0){if(!("number"==typeof(e=A.children[0])&&isFinite(e)||y(A.children[0])))return A;const s=A.children.map(A=>{const e=t[A];return e.nodeIndex=A,this.j(e,t)});A.children=s}var e;return A}H(A){return this.G(A).then(A=>{const t=this.scenes=[];let e;for(const t in A)A[t]=this.j(A[t],A),A[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate((s,n,i)=>{const r={};n.name&&(r.name=n.name),n.nodes&&(r.nodes=n.nodes.map(t=>A[t])),this.gltf.scene===s&&(e=i),t.push(r)},"scenes");const s={textures:this.gltf.textures,asset:this.gltf.asset,scene:e,scenes:t,nodes:A,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(s.extensions=this.gltf.extensions),1===this.version){const A=this.adapter.B(this.gltf.materials);s.materials=A}return s})}G(A){return this.Z(A).then(()=>{const A=this.nodes={};return this.adapter.iterate((t,e)=>{const s=this.adapter.createNode(e,this.meshes,this.skins);A[t]=s},"nodes"),A})}Y(){this.skins=[];const A=[];return this.adapter.iterate((t,e,s)=>{A.push(this.q(e).then(A=>{A.index=s,this.skins.push(A)}))},"skins"),A}q(A){const t=A.inverseBindMatrices;return this.adapter.accessor.u("inverseBindMatrices",t).then(t=>(A.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),A))}J(){const A=this.gltf.animations;return D(A)?this.adapter.getAnimations(A):null}Z(A){this.meshes={};let t=[];return this.adapter.iterate((e,s,n)=>{t.push(this.W(s,A).then(A=>{A.index=n,this.meshes[e]=A}))},"meshes"),t=t.concat(this.Y()),Promise.all(t)}W(A,t){const e=A.primitives.map(A=>this.X(A,t)).filter(A=>!!A);return Promise.all(e).then(t=>{const e={};return B(e,A),e.primitives=t,e})}K(){const A=this.gltf.textures;if(!A)return null;const t=[];for(const e in A)t.push(this.adapter.v(e));return Promise.all(t).then(t=>{if(this.transferables)for(let A=0;A<t.length;A++){const e=t[A].image.array;if(t[A]&&e){let A;A=e instanceof ImageBitmap?e:e.buffer,A&&this.transferables.indexOf(A)<0&&this.transferables.push(A)}}if(!Array.isArray(A)){const e={},s=Object.keys(A);for(let A=0;A<t.length;A++)t[A]&&(e[s[A]]=t[A]);return e}return t})}X(A,t){let e;const s=[],n=A.extensions;if(D(A.targets))for(let t=0;t<A.targets.length;t++){const e=A.targets[t];for(const A in e){const n=this.adapter.accessor.u(`morphTargets_${A}_${t}`,e[A]);n&&s.push(n)}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const A=this.options.decoders.draco,{bufferView:i,attributes:r}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],a=this._.m(o).then(e=>{const{buffer:s,byteOffset:n}=e;let{byteOffset:i}=o;const a=o.byteLength;i||(i=0);const h=new DataView(s,n+i,a),I={attributes:r,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return A(h,I).then(A=>{const t=Object.values(A.attributes);return A.indices&&t.push(A.indices),t})});s.push(a),e=Promise.all(s)}else{const t=A.attributes;for(const A in t){const e=this.adapter.accessor.u(A,t[A]);e&&s.push(e)}if(D(A.indices)){const t=this.adapter.accessor.u("indices",A.indices);t&&s.push(t)}e=Promise.all(s)}return e.then(t=>{if(n&&n.KHR_draco_mesh_compression){const e=A.targets?A.targets.length:0;t[e]=t[e].concat(t.slice(0,e)),t=t[e]}let e,s;const i={attributes:t.reduce((A,t)=>{if("indices"===t.name)e=t;else if(t.name.indexOf("morphTargets_")>-1)s=s||{},s[t.name.slice(13)]=t;else{if(!("POSITION"!==t.name||t.min&&t.max)){const A=[1/0,1/0,1/0],e=[-1/0,-1/0,-1/0],{itemSize:s,array:n}=t,i=n.length/s;for(let t=0;t<i;t++)for(let i=0;i<s;i++){const r=t*s+i;n[r]<A[i]&&(A[i]=n[r]),n[r]>e[i]&&(e[i]=n[r])}if(t.quantization){const s=t.quantization,n=s.range/(1<<s.quantizationBits),i=s.minValues;f(A,A,n),g(A,A,i),f(e,e,n),g(e,e,i)}t.min=A,t.max=e}A[t.name]=t}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),A},{}),material:A.material};return e&&(i.indices=e),s&&(i.morphTargets=s),i.mode=D(A.mode)?A.mode:4,D(A.extras)&&(i.extras=A.extras),i})}}function sA(A,t){const e=new Image;e.crossOrigin="",e.onload=()=>{if(!tA)return void t(new Error("There is no canvas to draw image!"));tA.width=e.width,tA.height=e.height;const A=tA.getContext("2d",{willReadFrequently:!0});A.drawImage(e,0,0,e.width,e.height);const s=A.getImageData(0,0,e.width,e.height),n={width:e.width,height:e.height,data:new Uint8Array(s.data)};t(null,n)},e.onerror=function(A){t(A)},e.src=A}let nA,iA;function rA(A,t){nA||(nA=new OffscreenCanvas(2,2),iA=nA.getContext("2d",{willReadFrequently:!0}));let e=null;if(y(A))e=fetch(A).then(A=>A.arrayBuffer()).then(A=>{const t=new Blob([new Uint8Array(A)]);return createImageBitmap(t)});else{const t=new Blob([A]);e=createImageBitmap(t)}e.then(oA.bind(this)).then(A=>{t(null,A)}).catch(A=>{console.warn(A),t(A)})}function oA(A){let{width:t,height:e}=A;aA(t)||(t=hA(t)),aA(e)||(e=hA(e));const s=this.options.maxTextureSize;s&&(t=Math.min(s,t),e=Math.min(s,e)),nA.width=t,nA.height=e,iA.drawImage(A,0,0,t,e),A.close();const n=iA.getImageData(0,0,t,e);return{width:t,height:e,data:new Uint8Array(n.data)}}function aA(A){return 0==(A&A-1)&&0!==A}function hA(A){return Math.pow(2,Math.floor(Math.log(A)/Math.LN2))}const IA=[];function cA(A,e,s,n,r,o){const a=[],h=t.quat.fromEuler([],s[0],s[1],s[2]),I=t.mat4.fromRotationTranslationScale([],h,e,n);return function(A){return new eA("",i[A]).load().then(A=>A)}(A).then(A=>{t.reshader.GLTFHelper.exportGLTFPack(A).getMeshesInfo().forEach((A,i)=>{const h=new t.reshader.Material({color:r||A.materialInfo.baseColorFactor}),c=new t.reshader.Mesh(A.geometry,h);c.setUniform("uPickingId",o+i);const g=c.getDefines();g.HAS_PICKING_ID=2,c.setDefines(g),c.translate=e,c.rotation=s,c.scaling=n,t.mat4.multiply(c.localTransform,I,A.nodeMatrix),c.originTransform=t.mat4.copy([],c.localTransform),c.originColor=r||A.materialInfo.baseColorFactor,a.push(c)}),o>100&&(a[0].properties.relatedMeshes=a.slice(1,2),a[1].properties.relatedMeshes=a.slice(0,1),a[2].properties.relatedMeshes=a.slice(3,4),a[3].properties.relatedMeshes=a.slice(2,3),a[4].properties.relatedMeshes=a.slice(5,6),a[5].properties.relatedMeshes=a.slice(4,5),a[6].properties.relatedMeshes=a.slice(0,6))}),a}function gA(A,t){return Math.abs(A)*Math.sign(t)}function fA(A,e){const s=A.getCoordinates(),i=e.coordinateToPointAtRes(s,e.getGLRes()),r=[i.x,i.y,0],o=CA(e,A.getTranslation());t.vec3.add(r,r,o);const a=function(A,t,e,s){return A._pointAtResToContainerPoint(t,e,s)}(e,new n.Point(r[0],r[1]),e.getGLRes());a.x+=85;const h=function(A,e,s,i){if(i){const r=s/A._getResolution(),o=A.width/2,a=A.height/2;IA[0]=(e.x-o)/o,IA[1]=e.y/a-1,IA[3]=i*r;const h=t.mat4.invert([],A.projViewMatrix);t.vec3.transformMat4(IA,IA,h);const I=A.getGLScale();return t.vec3.set(IA,IA[0]/I,IA[1]/I,IA[2]/I),t.vec3.scale(IA,IA,1/r),new n.Point(IA[0],IA[1])}{const t=A.containerPointToCoordinate(e);return A.coordinateToPointAtRes(t,s)}}(e,a,e.getGLRes());return Math.sqrt(Math.pow(h.x-r[0],2)+Math.pow(h.y-r[1],2))/5.272881136101205}function CA(A,e){if(!A)return e;const s=A.distanceToPointAtRes(e[0],e[1],A.getGLRes()),n=A.altitudeToPoint(e[2],A.getGLRes());return t.vec3.set([],gA(s.x,e[0]),gA(s.y,e[1]),gA(n,e[2]))}class uA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=340/177,e=cA("jiantou",[1.2*t,0,0],[0,0,90],[t,t,t],[89/255,206/255,147/255,0],7),s=cA("jiantou",[0,1.2*t,0],[0,0,180],[t,t,t],[89/255,206/255,147/255,0],8),n=cA("jiantou",[-1.2*t,0,0],[0,0,270],[t,t,t],[89/255,206/255,147/255,0],9),i=cA("jiantou",[0,-1.2*t,0],[0,0,0],[t,t,t],[89/255,206/255,147/255,0],10);return A.push(e,s,n,i),A}getMeshes(){return this._meshes}}class lA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("xuanzhuan",[0,0,0],[180,0,0],[340/177*.5,340/177*.5,340/177*.5],[50/255,130/255,184/255,.8],11);return A.push(t),A}getMeshes(){return this._meshes}}class wA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("yuanhuan",[0,0,0],[0,0,0],[340/177*.5,340/177*.5,340/177*.5],[149/255,179/255,199/255,.5],12);return A.push(t),A}getMeshes(){return this._meshes}}class QA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("plane",[0,0,0],[0,0,0],[10,10,10],[1,0,0,.5],16);return A.push(t),A}getMeshes(){return this._meshes}}class mA{constructor(A){this.$=A,this._meshes=this.AA()}setCoordinate(A){this.$=A}AA(){const A=[],t=cA("xyzScale",[0,0,0],[0,0,0],[2,2,2],null,113);return A.push(t),A}getMeshes(){return this._meshes}}const PA=[],bA=[],DA=[],yA=[],BA=[],dA=[177/170,177/170,177/170],pA=[],vA=[1,2,3,4,12];class MA{constructor(){this.translate=new uA,this.rotation=new lA,this.scaling=new wA,this.planeHelper=new QA,this.xyzScaleHelper=new mA,this._meshes=this.AA(),this.tA=!0}AA(){const A={};A.translate=this.translate.getMeshes(),A.rotation=this.rotation.getMeshes(),A.scaling=this.scaling.getMeshes(),A.planeHelper=this.planeHelper.getMeshes(),A.xyzScale=this.xyzScaleHelper.getMeshes();const t=340/177,e=cA("yuanhuan41",[-2.745*t,2.745*t,0],[90,0,0],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],1),s=cA("yuanhuan41",[2.745*t,2.745*t,0],[-90,0,180],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],2),n=cA("yuanhuan41",[2.745*t,-2.745*t,0],[90,0,180],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],3),i=cA("yuanhuan41",[-2.745*t,-2.745*t,0],[-90,0,0],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],4),r=cA("yuanpan",[0,0,0],[90,0,0],[.5*t,.5*t,.5*t],[89/255,206/255,147/255,.5],5),o=cA("zzhou",[0,0,6.5],[90,0,0],[1,1,1],[14/255,127/255,191/255,1],6);return A.translate.push(e,s,n,i,r,o),A}updateMatrix(A,e,s,n,i){const r=e.getCoordinates(),o=A.coordinateToPointAtRes(r,A.getGLRes()),a=e.eA();t.vec3.set(bA,o.x,o.y,a);const h=t.vec3.copy(PA,i),I=CA(A,e.getTranslation());t.vec3.add(bA,bA,I),t.vec3.add(bA,bA,h);for(const i in this._meshes)for(let r=0;r<this._meshes[i].length;r++){const o=this._meshes[i][r];for(let r=0;r<o.length;r++){const a=o[r],h=a.getUniform("uPickingId"),I=t.vec3.copy(PA,a.translate);let c=t.vec3.copy(pA,a.rotation);const g=a.scaling;if(11===h&&(this.tA?(c[2]+=s,a.rotation[2]+=s):this.tA||(c[2]+=s,a.rotation[2]+=s,c[0]=360,c[2]-=90)),h>100&&1===e.getTargets().length&&(c=e.getTargets()[0].getRotation()),vA.indexOf(h)>-1)if(12!==h)g[0]+=n,g[1]+=n,g[2]+=n;else{const A=this._meshes.translate[4][0];g[0]=1.2*A.scaling[0],g[1]=1.2*A.scaling[0],g[2]=1.2*A.scaling[0]}let f=fA(e,A);if(f=t.vec3.set(DA,f,f,f),t.vec3.multiply(I,I,f),t.vec3.multiply(f,f,g),1===h||2===h||3===h||4===h){const A=t.vec3.multiply(BA,g,dA);t.vec3.multiply(I,I,A)}const C=t.quat.fromEuler(yA,c[0],c[1],c[2]);if(t.vec3.add(I,I,bA),"xyzScale"===i){const A=t.mat4.fromRotationTranslationScale([],C,I,f);t.mat4.multiply(a.localTransform,A,a.originTransform)}else t.mat4.fromRotationTranslationScale(a.localTransform,C,I,f)}}}getMeshes(A){const t={};return A?("xyzScale"===A?t[A]=this._meshes[A]:(t.translate=this._meshes.translate,"translate"!==A&&(t[A]=this._meshes[A])),t):t}sA(A){this.tA=A}dispose(){for(const A in this._meshes)for(let t=0;t<this._meshes[A].length;t++){const e=this._meshes[A][t];for(let A=0;A<e.length;A++){const t=e[A];t.geometry.dispose(),t.dispose()}}}}const LA=[],EA=[],OA=[],FA=new e.Point(0,0),xA=[],UA=[],VA=[];class TA{constructor(){this.nA=[],this.iA=[0,0,0],this.rA=[1,1,1],this.oA=[0,0,0]}aA(A){Array.isArray(A)?A.forEach(A=>{this.aA(A)}):(A.on("remove",this.hA,this),A.IA={coordinate:A.getCoordinates(),translation:A.getTranslation(),rotation:A.getRotation(),scale:A.getScale()},this.nA.push(A))}cA(){this.nA.forEach(A=>{A.off("remove",this.hA,this)}),this.nA=[]}gA(A,e,s,n,i,r,o){for(let o=0;o<this.nA.length;o++){const a=this.nA[o],h=a.getRotation(),I=a.getScale(),c=this.fA(r,a,n,s,e);let g=null;g=n>=0?n:n*(this.options&&this.options.scaleStrength||1);const f=t.vec3.add(VA,t.vec3.set(LA,g*I[0],g*I[1],g*I[2]),I);if(Math.min(...f)<i){const A=Math.min(...f);f[0]=f[0]*(i/A),f[1]=f[1]*(i/A),f[2]=f[2]*(i/A)}const C=t.vec3.add(h,s,h);a.setCoordinates(c),this.CA(A,f,I);const u=a.getTranslation();a.setTRS(u,C,f)}t.vec3.set(VA,n,n,n),t.vec3.add(this.oA,s,this.oA),t.vec3.add(this.rA,VA,this.rA),t.vec3.add(this.iA,e,this.iA),A.indexOf("translate")>-1?o.fire("positionchange",{action:A,type:"positionchange",target:this.nA,center:this.getCoordinates(),scale:this.rA,rotation:this.oA,translation:this.iA,deltaTranslate:e,deltaRotation:s,deltaScale:n}):o.fire("transforming",{action:A,type:"transforming",target:this.nA,center:this.nA[0].getTransformOrigin(),scale:this.rA,rotation:this.oA,translation:this.iA,deltaTranslate:e,deltaRotation:s,deltaScale:n})}fA(A,e,s,n,i){const r=e.getCenter(),o=e.getTransformOrigin(),a=A.getGLRes(),h=A.coordinateToPointAtRes(r,a,FA);h.z=A.altitudeToPoint(r.z,a),t.vec3.set(xA,h.x,h.y,h.z||0);const I=A.coordinateToPointAtRes(o,a,FA);I.z=A.altitudeToPoint(o.z,a),t.vec3.set(UA,I.x,I.y,I.z||0);const c=t.vec3.sub(LA,xA,UA),g=t.quat.fromEuler(EA,0,0,n[2]);t.vec3.set(VA,s+1,s+1,s+1);const f=t.mat4.fromRotationTranslationScale(OA,g,i,VA);t.vec3.transformMat4(c,c,f),t.vec3.add(c,c,UA),FA.set(c[0],c[1]);const C=A.pointAtResToCoordinate(FA,a);return C.z=c[2]/A.altitudeToPoint(1,a),C}CA(A,t,e){return"x-scale"===A&&(t[1]=e[1],t[2]=e[2]),"y-scale"===A&&(t[0]=e[0],t[2]=e[2]),"z-scale"===A&&(t[0]=e[0],t[1]=e[1]),t}uA(){this.nA.forEach(A=>{if(A.IA){const{coordinate:t,translation:e,rotation:s,scale:n}=A.IA;A.setCoordinates(t),A.setTRS(e,s,n)}})}getScale(){return this.rA}getTranslation(){return this.iA}getRotation(){return this.oA}lA(){return this.nA[0]?this.nA[0].getLayer():null}getCoordinates(){let A=0,t=0,s=0;const n=this.nA.length;if(!n)return null;for(let e=0;e<n;e++){const n=this.nA[e].getCenter();A+=n.x,t+=n.y,s+=n.z||0}A/=n,t/=n,s/=n;const i=new e.Coordinate(A,t,s);for(let A=0;A<n;A++)this.nA[A].setTransformOrigin(i);return i}hA(A){const t=A.target,e=this.nA.indexOf(t);e>-1&&(delete t.IA,this.nA.splice(e,1))}getTargets(){return this.nA}eA(){let A=0;const t=this.nA.length;for(let e=0;e<t;e++){A+=this.nA[e].getPointZ()}return A/=t,A}wA(){for(let A=0;A<this.nA.length;A++)if(this.nA[A].isVisible())return!0;return!1}}const SA=[5,6,7,8,9,10],kA=[5,7,8,9,10],_A=[2,4,11],NA=[1,3,12],RA=[12,16],HA=[1,2,3,4],JA=[1,2,3,4,12],KA=[],jA=[],zA=[],GA=[],ZA=[],YA=[],qA=[];class WA extends(e.Eventable(e.Handlerable(e.Class))){constructor(A={}){super(A),this.options=A,this.mouseAction="moving",this.QA=this.options.mode||"translate",this.mA=!0,this.TransformHelper=new MA,this.PA=new TA,this.helperScene=new t.reshader.Scene([]),this.addToMapCount=0}enable(){return this.mA=!0,this.layerRenderer&&this.layerRenderer.setToRedraw(),this}disable(){return this.mA=!1,this.layerRenderer&&this.layerRenderer.setToRedraw(),this.map&&this.map.resetCursor(),this}setMode(A){this.QA=A,this.bA(),this.layerRenderer&&this.layerRenderer.setToRedraw(),this.fire("modechange",{mode:A,type:"modechange"})}getMode(){return this.QA}isEnable(){return this.mA}DA(A){SA.indexOf(A)>-1?this.QA="translate":_A.indexOf(A)>-1?this.QA="rotation":NA.indexOf(A)>-1?this.QA="scaling":"xyzScale"!==this.QA&&(this.QA="translate")}yA(){return this.QA}addTo(A){this.map&&(this.BA(),console.warn("transform control has been added to a map, it suggest remove from the map before")),this.addToMapCount++,this.map=A,this.container=A.getContainer(),A.on("dom:mousemove",this.dA,this),A.on("dom:mousedown",this.pA,this),A.on("dom:mouseup",this.vA,this),A.on("zooming moving dragrotating",this.MA,this),this.LA()}remove(){this.map&&this.container&&this.layerRenderer&&(this.BA(),this.TransformHelper.dispose(),this.layerRenderer.setToRedraw(),delete this.map,delete this.layer,delete this.layerRenderer,delete this.container,delete this.PA)}BA(){this.container&&this.map&&(this.map.off("dom:mousemove",this.dA,this),this.map.off("dom:mousedown",this.pA,this),this.map.off("dom:mouseup",this.vA,this),this.map.off("zooming moving dragrotating",this.MA,this),this.layer&&this.layer.off("renderend",this.render,this))}dA(A){if(this.EA()){if(this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},"moving"===this.mouseAction){const A=this.OA();this.currentPickingObject=this.FA(this.currentMousePosition,A,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.pickingId?(this.DA(this.currentPickingObject.pickingId),6===this.currentPickingObject.pickingId?this.xA(!0):this.xA(!1)):(this.xA(!1),this.DA()),this.UA()}this.VA(this.currentMousePosition)}}pA(A){if(!this.EA()||0!==A.domEvent.button)return;const t=this.OA();this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},this.TA=!0,this.currentPickingObject=this.FA(this.currentMousePosition,t,"meshes"),this.firstDownPoint=this.FA(this.currentMousePosition,t,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.meshId?(this.mouseAction="transform",this.SA(this.currentPickingObject.pickingId),this.map.config("zoomable",!1),this.map.config("draggable",!1),this.layerRenderer&&this.layerRenderer.setToRedraw()):(this.mouseAction="pan",this.map.config("zoomable",!0),this.map.config("draggable",!0),this.bA()),this.lastMousePosition=this.currentMousePosition,this.lastPickingObject=this.currentPickingObject,this.lastPickingMesh=t[this.currentPickingObject.meshId]}vA(){"transform"===this.mouseAction&&(this.firstDownPoint=null,this.bA(),this.TA=!0,this.fire("transformend",{action:this.kA,type:"transformend"})),this.mouseAction="moving","xyzScale"!==this.QA&&(this.QA="translate"),this.map.config("zoomable",!0),this.map.config("draggable",!0),this.layerRenderer&&this.layerRenderer.setToRedraw()}MA(){const A=this.TransformHelper.planeHelper.getMeshes()[0][0],t=this.map.getBearing();A.rotation[2]=-t,this._A()}_A(){this.EA()&&(this.TransformHelper.updateMatrix(this.map,this.PA,0,0,[0,0,0]),this.TA=!0)}picked(A){if(!this.layerRenderer)return!1;const t=this.OA(),s=this.map;let n=A;A instanceof e.Point||(n=s.coordinateToContainerPoint(new e.Coordinate(A)));const i=this.FA(n,t,"picked");return!(!i||null===i.meshId)}bA(){const A=this.TransformHelper.getMeshes("scaling").scaling[0][0];A.scaling=[340/177*.6,340/177*.6,340/177*.6],this.layerRenderer&&(this.NA(A),this.RA())}RA(){this.TransformHelper._meshes.translate.forEach(A=>{for(let t=0;t<A.length;t++){const e=A[t];HA.indexOf(e.getUniform("uPickingId"))>-1&&e.material.set("color",e.originColor)}})}NA(A){const e=this.PA.getCoordinates(),s=this.map.coordinateToPointAtRes(e,this.map.getGLRes()),n=[s.x,s.y,0],i=CA(this.map,this.PA.getTranslation());t.vec3.add(n,n,i);const r=t.vec3.copy([],A.translate),o=A.scaling;let a=fA(this.PA,this.map);a=t.vec3.set([],a,a,a),t.vec3.multiply(r,r,a),t.vec3.multiply(a,a,o),t.vec3.add(r,r,n),t.mat4.fromRotationTranslationScale(A.localTransform,[0,0,0,1],r,a);this.OA().forEach(A=>{const e=A.getUniform("uPickingId");if(1===e||3===e||2===e||4===e){const e=t.vec3.copy([],A.translate),s=170/177;A.scaling=[s,s,s];const i=A.scaling,r=A.rotation;let o=fA(this.PA,this.map);o=t.vec3.set([],o,o,o),t.vec3.multiply(e,e,o),t.vec3.multiply(o,o,i),t.vec3.add(e,e,n);const a=t.quat.fromEuler([],r[0],r[1],r[2]);t.mat4.fromRotationTranslationScale(A.localTransform,a,e,o)}})}HA(A){const t=this.map.containerPointToCoordinate(A),e=this.map.coordinateToPointAtRes(t,this.map.getGLRes());return{point:[e.x,e.y]}}VA(A){if("transform"===this.mouseAction){const A=this.yA(),s=CA(this.map,this.PA.getTranslation()),n=this.PA.eA();let i=null,r=null;if(s[2]+n<.01&&"z-translate"!==this.kA)i=this.HA(this.currentMousePosition),r=this.HA(this.lastMousePosition);else{const A=this.TransformHelper.planeHelper.getMeshes()[0];if(i=this.FA(this.currentMousePosition,A,"plane"),r=this.FA(this.lastMousePosition,A,"plane"),!i||null===i.meshId||!r||null===r.meshId)return}const o=[0,0,0],a=[0,0,0];let h=0,I=0,c=0;if("translate"===A){if("xy-translate"===this.kA){const A=i.point[0]-r.point[0],t=i.point[1]-r.point[1];o[0]=A,o[1]=t}else if("x-translate"===this.kA){const A=i.point[0]-r.point[0];o[0]=A}else if("y-translate"===this.kA){const A=i.point[1]-r.point[1];o[1]=A}else if("z-translate"===this.kA){let A=0;if(this.JA()){const s=this.map.getGLRes(),n=this.map._pointAtResToContainerPoint(new e.Point(r.point[0],r.point[1]),s),o=this.map._pointAtResToContainerPoint(new e.Point(i.point[0],i.point[1]),s),a=t.vec2.length(t.vec2.set(GA,i.point[0]-r.point[0],i.point[1]-r.point[1]));A=o.y<n.y?a:-a}else A=i.point[2]-r.point[2];o[2]=A}}else if("rotation"===A)I=this.KA(i.point,r.point),I>=0?this.TransformHelper.sA(!0):this.TransformHelper.sA(!1),a[2]+=I;else if("scaling"===A||"xyzScale"===A){const A=this.jA(),e=t.vec2.length(t.vec2.set(GA,this.firstDownPoint.point[0]-A[0],this.firstDownPoint.point[1]-A[1])),s=t.vec2.length(t.vec2.set(GA,r.point[0]-A[0],r.point[1]-A[1]));h=this.zA(i.point,r.point,A,s),c=this.zA(i.point,r.point,A,e)}this.TransformHelper.updateMatrix(this.map,this.PA,I,c,o),this.PA.gA(this.kA,o,a,h,.01,this.map,this)}this.lastMousePosition=A,this.lastPickingObject=this.currentPickingObject;const s=this.OA();this.lastPickingMesh=s[this.currentPickingObject.meshId]}zA(A,e,s,n,i){const r=(t.vec2.length(t.vec2.set(GA,A[0]-s[0],A[1]-s[1]))-t.vec2.length(t.vec2.set(GA,e[0]-s[0],e[1]-s[1])))/n;return i?(i[0]-.01)*r:r}jA(){const A=this.map,e=this.PA.getCoordinates(),s=A.coordinateToPointAtRes(e,A.getGLRes()),n=t.vec3.set(ZA,s.x,s.y,0),i=CA(A,this.PA.getTranslation());return t.vec3.add(n,n,i),n}xA(A){const e=this.TransformHelper.planeHelper.getMeshes()[0][0],s=t.mat4.getTranslation(zA,e.localTransform),n=t.mat4.getScaling(jA,e.localTransform);let i=t.quat.fromEuler(KA,0,0,0);const r=this.map.getBearing();A&&!this.JA()?(i=t.quat.fromEuler(KA,90,0,-r),0===e.rotation[0]&&(this.TA=!0),t.vec3.set(e.rotation,90,0,-r)):(90===e.rotation[0]&&(this.TA=!0),t.vec3.set(e.rotation,0,0,-r)),t.mat4.fromRotationTranslationScale(e.localTransform,i,s,n)}JA(){if(this.map.getPitch())return!1;const A=this.map.cameraPosition,e=this.map.coordinateToPointAtRes(this.map.getCenter(),this.map.getGLRes());t.vec3.set(e,e.x,e.y,0);const s=this.PA.getCoordinates(),n=this.map.coordinateToPointAtRes(s,this.map.getGLRes()),i=CA(this.map,this.PA.getTranslation()),r=t.vec3.set(zA,n.x,n.y,0),o=t.vec3.add(r,r,i),a=t.vec3.subtract([],A,o),h=t.vec3.subtract([],A,e);return t.vec3.angle(a,h)<1/180*Math.PI}UA(){const A=this.OA();if(this.currentPickingObject&&null!=this.currentPickingObject.meshId){this.GA(),this.lastPickingObject&&null!=this.lastPickingObject.meshId&&this.lastPickingObject.meshId!==this.currentPickingObject.meshId&&this.ZA();const t=A[this.currentPickingObject.meshId];if(t&&RA.indexOf(this.currentPickingObject.pickingId)<0)if(this.currentPickingObject.pickingId>100)this.YA(t);else{const A=[t.originColor[0],t.originColor[1],t.originColor[2],.8];t.material.set("color",A),this.qA(t,.5)}this.layerRenderer.setToRedraw()}else this.lastPickingObject&&null!=this.lastPickingObject.meshId&&(this.map.resetCursor(),this.ZA(),this.layerRenderer.setToRedraw())}YA(A){const t=[1,179/255,2/255,1];A.material.set("color",t),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach(A=>{A.material.set("color",t)})}GA(){6===this.currentPickingObject.pickingId?this.map.setCursor("ns-resize"):kA.indexOf(this.currentPickingObject.pickingId)>-1?this.map.setCursor("move"):this.map.setCursor("pointer")}ZA(){const A=this.lastPickingMesh;if(!A)return;const t=A.getUniform("uPickingId"),e=this.OA();kA.indexOf(t)>-1?e.forEach(A=>{kA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)}):JA.indexOf(t)>-1?e.forEach(A=>{const t=A.getUniform("uPickingId");HA.indexOf(t)>-1&&A.material.set("color",A.originColor)}):11===t&&e.forEach(A=>{HA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)}),A.material.set("color",A.originColor),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach(A=>{A.material.set("color",A.originColor)})}qA(A,t){const e=A.getUniform("uPickingId"),s=this.OA();kA.indexOf(e)>-1?s.forEach(e=>{if(kA.indexOf(e.getUniform("uPickingId"))>-1&&e.getUniform("uPickingId")!==A.getUniform("uPickingId")){const A=[e.originColor[0],e.originColor[1],e.originColor[2],t];e.material.set("color",A)}}):"scaling"===this.QA?s.forEach(A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=[149/255,179/255,199/255,.8];A.material.set("color",t)}}):"rotation"===this.QA&&s.forEach(A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=A.originColor;A.material.set("color",[t[0],t[1],t[2],0])}})}reset(){this.map&&this.PA&&(this.PA.uA(),this.TransformHelper.updateMatrix(this.map,this.PA,0,0,[0,0,0]))}KA(A,e){const s=this.jA(),n=t.vec2.set(YA,e[0]-s[0],e[1]-s[1]),i=t.vec2.set(qA,A[0]-s[0],A[1]-s[1]),r=Math.atan2(n[1],n[0]);return(Math.atan2(i[1],i[0])-r)/Math.PI*180}SA(A){return this.kA=113===A||114===A?"x-scale":115===A||116===A?"z-scale":117===A||118===A?"y-scale":119===A?"xyz-scale":5===A?"xy-translate":6===A?"z-translate":7===A||9===A?"x-translate":8===A||10===A?"y-translate":11===A?"z-rotate":"scale",this.kA}transform(A){if(!A)return;if(this.layerRenderer&&this.layerRenderer.layer&&(this.layerRenderer.layer.off("renderend",this.render),this.layerRenderer.layer.off("resizeCanvas",this.WA)),!this.map)return void console.error("should add to a target first");if(this.PA&&(this.PA.cA(),this.PA.aA(A)),!this.PA.getTargets().length)return;const t=this.map;this.TransformHelper.updateMatrix(t,this.PA,0,0,[0,0,0]),this.XA(),this.TA=!0}getTransformTarget(){return this.PA}hA(){delete this.PA}XA(){const A=this.PA.lA();A&&(A.off("renderend",this.render),A.off("resizeCanvas",this.WA));const e=this.map.getLayers();let s=null;for(let A=0;A<e.length;A++)if(e[A]instanceof t.GroupGLLayer){s=e[A];break}if(!s)return;const n=s.getLayers(),i=n.indexOf(A);if(i<0)return;n.splice(i,1),n.push(A);const r=this.map,o=A.getRenderer();this.layerRenderer=o,this.regl=o.regl,this.renderer=o.renderer,this.$A=this.layerRenderer.getFBORayPicking(),this.At={projViewMatrix:r.projViewMatrix},A.on("renderend",this.render,this),A.on("resizeCanvas",this.WA,this),o.setToRedraw()}WA(){this.$A.clear(),this.TA=!0}FA(A,t,e){const s=this.map;if(!(s&&this.$A&&this.layerRenderer&&this.layerRenderer.canvas))return null;const n=s.getDevicePixelRatio(),i=A.x*n,r=A.y*n,o={projViewMatrix:this.map.projViewMatrix,pointSize:1},a=this.layerRenderer.canvas.gl&&this.layerRenderer.canvas.gl.wrap;(this.TA||a||!this.tt||this.tt!==e)&&(this.$A.render(t,o,!0),this.tt=e,this.TA=!1);return this.$A.pick(i,r,10,o,{viewMatrix:this.map.viewMatrix,projMatrix:this.map.projMatrix,returnPoint:!0})}LA(){const A=this.map.getDevicePixelRatio(),e={x:0,y:0,width:()=>this.map?this.map.width*A:1,height:()=>this.map?this.map.height*A:1};this.et=new t.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main()\n\n{\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n\n\n}\n\n",frag:"precision mediump float;\n\nuniform vec4 color;\n\n\n\nvoid main() {\n\n gl_FragColor = color;\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:function(A,e){return t.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}}],extraCommandProps:{viewport:e,depth:{enable:!0,func:"always",mask:!0,range:[0,0]},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}},defines:{}})}render(){if(!this.EA())return;const A=this.OA();this.helperScene.setMeshes(A);const t=this.layerRenderer.getFrameContext();if(t&&t.renderTarget&&this.layerRenderer.getFrameTimestamp()!==t.timestamp)return;this._A(),this.et.filter=t&&t.sceneFilter;const e=t&&t.renderTarget&&t.renderTarget.fbo;this.renderer.render(this.et,this.At,this.helperScene,e)}OA(){let A=[];const t=this.TransformHelper.getMeshes(this.QA);for(const e in t){if("translate"===e)continue;const s=t[e];for(let t=0;t<s.length;t++)A=A.concat(s[t])}const e=t.translate;if(e)for(let t=0;t<e.length;t++)A=A.concat(e[t]);return A}EA(){const A=this.layerRenderer,t=A&&A.layer;return A&&this.PA&&t&&t.isVisible()&&this.PA.wA()&&this.regl&&this.mA}}WA.mergeOptions({scaleStrength:2}),A.TransformControl=WA,Object.defineProperty(A,"A",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/transform-control v0.91.4")}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptalks/transform-control",
|
|
3
|
-
"version": "0.91.
|
|
3
|
+
"version": "0.91.4",
|
|
4
4
|
"description": "a plugin to control model's translate、rotation and scale",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"rollup-plugin-terser": "^5.3.1"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@maptalks/gl": "^0.91.
|
|
46
|
+
"@maptalks/gl": "^0.91.4",
|
|
47
47
|
"@maptalks/gltf-loader": "^0.91.2"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "0405287fcb343ac4aba96ed7556adec1824c24dd"
|
|
50
50
|
}
|