{ "pandav:/martini.min.js": { "cubeCode": "Cube(\"pandav:/npm/@maptalks/martini/0.4.0/martini.min\", [], function (module, exports, require, load, process, global) {\n\n function _classCallCheck(a, n) {if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\");}\n function _defineProperties(e, r) {for (var t = 0; t < r.length; t++) {var o = r[t];o.enumerable = o.enumerable || !1, o.configurable = !0, \"value\" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);}}\n function _createClass(e, r, t) {return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e;}\n function _toPropertyKey(t) {var i = _toPrimitive(t, \"string\");return \"symbol\" == _typeof(i) ? i : i + \"\";}\n function _toPrimitive(t, r) {if (\"object\" != _typeof(t) || !t) return t;var e = t[Symbol.toPrimitive];if (void 0 !== e) {var i = e.call(t, r || \"default\");if (\"object\" != _typeof(i)) return i;throw new TypeError(\"@@toPrimitive must return a primitive value.\");}return (\"string\" === r ? String : Number)(t);}\n function _typeof(o) {\"@babel/helpers - typeof\";return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {return typeof o;} : function (o) {return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;}, _typeof(o);}\n !function (t, n) {\n \"object\" == (typeof exports === \"undefined\" ? \"undefined\" : _typeof(exports)) && \"undefined\" != typeof module ? module.exports = n() : \"function\" == typeof define && define.amd ? define(n) : (t = t || self).Martini = n();\n }(void 0, function () {\n \"use strict\";\n\n var t = function () {\n function t(_t, n) {\n _classCallCheck(this, t);\n var e = n.gridSize;\n if (_t.length !== e * e) throw new Error(\"Expected terrain data of length \".concat(e * e, \" (\").concat(e, \" x \").concat(e, \"), got \").concat(_t.length, \".\"));\n this.terrain = _t, this.martini = n, this.errors = new Float32Array(_t.length), this.update();\n }\n return _createClass(t, [{\n key: \"update\",\n value: function update() {\n var _this$martini = this.martini,\n _t2 = _this$martini.numTriangles,\n n = _this$martini.numParentTriangles,\n e = _this$martini.coords,\n s = _this$martini.gridSize,\n i = this.terrain,\n r = this.errors;\n for (var o = _t2 - 1; o >= 0; o--) {\n var _t3 = 4 * o,\n h = e[_t3 + 0],\n a = e[_t3 + 1],\n c = e[_t3 + 2],\n l = e[_t3 + 3],\n u = h + c >> 1,\n g = a + l >> 1,\n d = u + g - a,\n f = g + h - u,\n p = (i[a * s + h] + i[l * s + c]) / 2,\n m = g * s + u,\n M = Math.abs(p - i[m]);\n if (r[m] = Math.max(r[m], M), o < n) {\n var _t4 = (a + f >> 1) * s + (h + d >> 1),\n _n = (l + f >> 1) * s + (c + d >> 1);\n r[m] = Math.max(r[m], r[_t4], r[_n]);\n }\n }\n } },\n {\n key: \"getMesh\",\n value: function getMesh() {\n var _t5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var _this$martini2 = this.martini,\n n = _this$martini2.gridSize,\n e = _this$martini2.indices,\n s = this.errors;\n var i = 0,\n r = 0;\n var o = n - 1;\n function h(o, a, c, l, u, g) {\n var d = o + c >> 1,\n f = a + l >> 1;\n Math.abs(o - u) + Math.abs(a - g) > 1 && s[f * n + d] > _t5 ? (h(u, g, o, a, d, f), h(c, l, u, g, d, f)) : (e[a * n + o] = e[a * n + o] || ++i, e[l * n + c] = e[l * n + c] || ++i, e[g * n + u] = e[g * n + u] || ++i, r++);\n }\n e.fill(0), h(0, 0, o, o, o, 0), h(o, o, 0, 0, 0, o);\n var a = new Uint16Array(2 * i),\n c = new Uint32Array(3 * r);\n var l = 0;\n function u(i, r, o, h, g, d) {\n var f = i + o >> 1,\n p = r + h >> 1;\n if (Math.abs(i - g) + Math.abs(r - d) > 1 && s[p * n + f] > _t5) u(g, d, i, r, f, p), u(o, h, g, d, f, p);else {\n var _t11 = e[r * n + i] - 1,\n _s = e[h * n + o] - 1,\n _u = e[d * n + g] - 1;\n a[2 * _t11] = i, a[2 * _t11 + 1] = r, a[2 * _s] = o, a[2 * _s + 1] = h, a[2 * _u] = g, a[2 * _u + 1] = d, c[l++] = _t11, c[l++] = _s, c[l++] = _u;\n }\n }\n return u(0, 0, o, o, o, 0), u(o, o, 0, 0, 0, o), {\n vertices: a,\n triangles: c };\n\n } },\n {\n key: \"getMeshWithSkirts\",\n value: function getMeshWithSkirts() {\n var _t6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var n = arguments.length > 1 ? arguments[1] : undefined;\n var _this$martini3 = this.martini,\n e = _this$martini3.gridSize,\n s = _this$martini3.indices,\n i = this.errors;\n var r = 0,\n o = 0;\n var h = e - 1;\n var a,\n c,\n l = 0;\n var u = [],\n g = [],\n d = [],\n f = [];\n function p(n, m, M, S, b, w) {\n var x = n + M >> 1,\n y = m + S >> 1;\n Math.abs(n - b) + Math.abs(m - w) > 1 && i[y * e + x] > _t6 ? (p(b, w, n, m, x, y), p(M, S, b, w, x, y)) : (a = m * e + n, c = S * e + M, l = w * e + b, 0 === s[a] && (0 === n ? u.push(r) : n === h && g.push(r), 0 === m ? d.push(r) : m === h && f.push(r), s[a] = ++r), 0 === s[c] && (0 === M ? u.push(r) : M === h && g.push(r), 0 === S ? d.push(r) : S === h && f.push(r), s[c] = ++r), 0 === s[l] && (0 === b ? u.push(r) : b === h && g.push(r), 0 === w ? d.push(r) : w === h && f.push(r), s[l] = ++r), o++);\n }\n var m;\n s.fill(0), p(0, 0, h, h, h, 0), p(h, h, 0, 0, 0, h), m = n ? 2 * (r + 3 * u.length - 2 + 3 * g.length - 2 + 3 * d.length - 2 + 3 * f.length - 2) : 2 * (r + u.length + g.length + d.length + f.length);\n var M = 3 * (o + 2 * (u.length - 1) + 2 * (g.length - 1) + 2 * (d.length - 1) + 2 * (f.length - 1)),\n S = new Uint16Array(m),\n b = new Uint32Array(M);\n var w = 0;\n function x(n, r, o, h, a, c) {\n var l = n + o >> 1,\n u = r + h >> 1;\n if (Math.abs(n - a) + Math.abs(r - c) > 1 && i[u * e + l] > _t6) x(a, c, n, r, l, u), x(o, h, a, c, l, u);else {\n var _t12 = s[r * e + n] - 1,\n _i = s[h * e + o] - 1,\n _l = s[c * e + a] - 1;\n S[2 * _t12] = n, S[2 * _t12 + 1] = r, S[2 * _i] = o, S[2 * _i + 1] = h, S[2 * _l] = a, S[2 * _l + 1] = c, b[w++] = _t12, b[w++] = _i, b[w++] = _l;\n }\n }\n x(0, 0, h, h, h, 0), x(h, h, 0, 0, 0, h), u.sort(function (_t7, n) {\n return S[2 * _t7 + 1] - S[2 * n + 1];\n }), g.sort(function (_t8, n) {\n return S[2 * n + 1] - S[2 * _t8 + 1];\n }), d.sort(function (_t9, n) {\n return S[2 * n] - S[2 * _t9];\n }), f.sort(function (_t10, n) {\n return S[2 * _t10] - S[2 * n];\n });\n var y,\n T,\n z,\n k,\n A = 2 * r,\n U = 0;\n function $(t) {\n U = t.length;\n for (var _e = 0; _e < U - 1; _e++) y = t[_e], T = t[_e + 1], z = A / 2, k = (A + (n ? 6 : 2)) / 2, S[A++] = 2 * y, S[A++] = 2 * y + 1, n && (S[A++] = 2 * y, S[A++] = 2 * y + 1, S[A++] = 2 * T, S[A++] = 2 * T + 1), n ? (b[w++] = z + 1, b[w++] = z, b[w++] = z + 2, b[w++] = z, b[w++] = k, b[w++] = z + 2) : (b[w++] = y, b[w++] = z, b[w++] = T, b[w++] = z, b[w++] = k, b[w++] = T);\n S[A++] = 2 * t[U - 1], S[A++] = 2 * t[U - 1] + 1;\n }\n $(u);\n var E = A;\n $(g);\n var I = A;\n $(d);\n var W = A;\n $(f);\n return {\n vertices: S,\n triangles: b,\n numVerticesWithoutSkirts: r,\n numTrianglesWithoutSkirts: o,\n leftSkirtIndex: E,\n rightSkirtIndex: I,\n bottomSkirtIndex: W,\n topSkirtIndex: A };\n\n } }]);\n\n }();\n return function () {\n function _class() {\n var t = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 257;\n _classCallCheck(this, _class);\n this.gridSize = t;\n var n = t - 1;\n if (n & n - 1) throw new Error(\"Expected grid size to be 2^n+1, got \".concat(t, \".\"));\n this.numTriangles = n * n * 2 - 2, this.numParentTriangles = this.numTriangles - n * n, this.indices = new Uint32Array(this.gridSize * this.gridSize), this.coords = new Uint16Array(4 * this.numTriangles);\n for (var _t13 = 0; _t13 < this.numTriangles; _t13++) {\n var e = _t13 + 2,\n s = 0,\n i = 0,\n r = 0,\n o = 0,\n h = 0,\n a = 0;\n for (1 & e ? r = o = h = n : s = i = a = n; (e >>= 1) > 1;) {\n var _t14 = s + r >> 1,\n _n2 = i + o >> 1;\n 1 & e ? (r = s, o = i, s = h, i = a) : (s = r, i = o, r = h, o = a), h = _t14, a = _n2;\n }\n var c = 4 * _t13;\n this.coords[c + 0] = s, this.coords[c + 1] = i, this.coords[c + 2] = r, this.coords[c + 3] = o;\n }\n }\n return _createClass(_class, [{\n key: \"createTile\",\n value: function createTile(n) {\n return new t(n, this);\n } }]);\n\n }();\n });return module.exports;});", "requires": [], "buildLevel": 0, "fileName": "/martini.min.js" }, "pandav:/index.js": { "cubeCode": "Cube(\"pandav:/npm/@maptalks/martini/0.4.0\", [], function (module, exports, require, load, process, global) {\n\n Object.defineProperty(exports, \"__esModule\", {\n value: true });\n\n exports.default = void 0;\n function _typeof(o) {\"@babel/helpers - typeof\";return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {return typeof o;} : function (o) {return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;}, _typeof(o);}\n function _classCallCheck(a, n) {if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\");}\n function _defineProperties(e, r) {for (var t = 0; t < r.length; t++) {var o = r[t];o.enumerable = o.enumerable || !1, o.configurable = !0, \"value\" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);}}\n function _createClass(e, r, t) {return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e;}\n function _toPropertyKey(t) {var i = _toPrimitive(t, \"string\");return \"symbol\" == _typeof(i) ? i : i + \"\";}\n function _toPrimitive(t, r) {if (\"object\" != _typeof(t) || !t) return t;var e = t[Symbol.toPrimitive];if (void 0 !== e) {var i = e.call(t, r || \"default\");if (\"object\" != _typeof(i)) return i;throw new TypeError(\"@@toPrimitive must return a primitive value.\");}return (\"string\" === r ? String : Number)(t);}\n var Martini = exports.default = function () {\n function Martini() {\n var gridSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 257;\n _classCallCheck(this, Martini);\n this.gridSize = gridSize;\n var tileSize = gridSize - 1;\n if (tileSize & tileSize - 1) throw new Error(\"Expected grid size to be 2^n+1, got \".concat(gridSize, \".\"));\n this.numTriangles = tileSize * tileSize * 2 - 2;\n this.numParentTriangles = this.numTriangles - tileSize * tileSize;\n this.indices = new Uint32Array(this.gridSize * this.gridSize);\n this.coords = new Uint16Array(this.numTriangles * 4);\n for (var i = 0; i < this.numTriangles; i++) {\n var id = i + 2;\n var ax = 0,\n ay = 0,\n bx = 0,\n by = 0,\n cx = 0,\n cy = 0;\n if (id & 1) {\n bx = by = cx = tileSize;\n } else {\n ax = ay = cy = tileSize;\n }\n while ((id >>= 1) > 1) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (id & 1) {\n bx = ax;\n by = ay;\n ax = cx;\n ay = cy;\n } else {\n ax = bx;\n ay = by;\n bx = cx;\n by = cy;\n }\n cx = mx;\n cy = my;\n }\n var k = i * 4;\n this.coords[k + 0] = ax;\n this.coords[k + 1] = ay;\n this.coords[k + 2] = bx;\n this.coords[k + 3] = by;\n }\n }\n return _createClass(Martini, [{\n key: \"createTile\",\n value: function createTile(terrain) {\n return new Tile(terrain, this);\n } }]);\n\n }();\n var Tile = function () {\n function Tile(terrain, martini) {\n _classCallCheck(this, Tile);\n var size = martini.gridSize;\n if (terrain.length !== size * size) throw new Error(\"Expected terrain data of length \".concat(size * size, \" (\").concat(size, \" x \").concat(size, \"), got \").concat(terrain.length, \".\"));\n this.terrain = terrain;\n this.martini = martini;\n this.errors = new Float32Array(terrain.length);\n this.update();\n }\n return _createClass(Tile, [{\n key: \"update\",\n value: function update() {\n var _this$martini = this.martini,\n numTriangles = _this$martini.numTriangles,\n numParentTriangles = _this$martini.numParentTriangles,\n coords = _this$martini.coords,\n size = _this$martini.gridSize;\n var terrain = this.terrain,\n errors = this.errors;\n for (var i = numTriangles - 1; i >= 0; i--) {\n var k = i * 4;\n var ax = coords[k + 0];\n var ay = coords[k + 1];\n var bx = coords[k + 2];\n var by = coords[k + 3];\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n var cx = mx + my - ay;\n var cy = my + ax - mx;\n var interpolatedHeight = (terrain[ay * size + ax] + terrain[by * size + bx]) / 2;\n var middleIndex = my * size + mx;\n var middleError = Math.abs(interpolatedHeight - terrain[middleIndex]);\n errors[middleIndex] = Math.max(errors[middleIndex], middleError);\n if (i < numParentTriangles) {\n var leftChildIndex = (ay + cy >> 1) * size + (ax + cx >> 1);\n var rightChildIndex = (by + cy >> 1) * size + (bx + cx >> 1);\n errors[middleIndex] = Math.max(errors[middleIndex], errors[leftChildIndex], errors[rightChildIndex]);\n }\n }\n } },\n {\n key: \"getMesh\",\n value: function getMesh() {\n var maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var _this$martini2 = this.martini,\n size = _this$martini2.gridSize,\n indices = _this$martini2.indices;\n var errors = this.errors;\n var numVertices = 0;\n var numTriangles = 0;\n var max = size - 1;\n indices.fill(0);\n function countElements(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n countElements(cx, cy, ax, ay, mx, my);\n countElements(bx, by, cx, cy, mx, my);\n } else {\n indices[ay * size + ax] = indices[ay * size + ax] || ++numVertices;\n indices[by * size + bx] = indices[by * size + bx] || ++numVertices;\n indices[cy * size + cx] = indices[cy * size + cx] || ++numVertices;\n numTriangles++;\n }\n }\n countElements(0, 0, max, max, max, 0);\n countElements(max, max, 0, 0, 0, max);\n var vertices = new Uint16Array(numVertices * 2);\n var triangles = new Uint32Array(numTriangles * 3);\n var triIndex = 0;\n function processTriangle(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n processTriangle(cx, cy, ax, ay, mx, my);\n processTriangle(bx, by, cx, cy, mx, my);\n } else {\n var a = indices[ay * size + ax] - 1;\n var b = indices[by * size + bx] - 1;\n var c = indices[cy * size + cx] - 1;\n vertices[2 * a] = ax;\n vertices[2 * a + 1] = ay;\n vertices[2 * b] = bx;\n vertices[2 * b + 1] = by;\n vertices[2 * c] = cx;\n vertices[2 * c + 1] = cy;\n triangles[triIndex++] = a;\n triangles[triIndex++] = b;\n triangles[triIndex++] = c;\n }\n }\n processTriangle(0, 0, max, max, max, 0);\n processTriangle(max, max, 0, 0, 0, max);\n return {\n vertices: vertices,\n triangles: triangles };\n\n } },\n {\n key: \"getMeshWithSkirts\",\n value: function getMeshWithSkirts() {\n var maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var isolateSkirtVertices = arguments.length > 1 ? arguments[1] : undefined;\n var _this$martini3 = this.martini,\n size = _this$martini3.gridSize,\n indices = _this$martini3.indices;\n var errors = this.errors;\n var numVertices = 0;\n var numTriangles = 0;\n var max = size - 1;\n var aIndex,\n bIndex,\n cIndex = 0;\n var leftSkirtIndices = [];\n var rightSkirtIndices = [];\n var bottomSkirtIndices = [];\n var topSkirtIndices = [];\n indices.fill(0);\n function countElements(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n countElements(cx, cy, ax, ay, mx, my);\n countElements(bx, by, cx, cy, mx, my);\n } else {\n aIndex = ay * size + ax;\n bIndex = by * size + bx;\n cIndex = cy * size + cx;\n if (indices[aIndex] === 0) {\n if (ax === 0) leftSkirtIndices.push(numVertices);else if (ax === max) rightSkirtIndices.push(numVertices);\n if (ay === 0) bottomSkirtIndices.push(numVertices);else if (ay === max) topSkirtIndices.push(numVertices);\n indices[aIndex] = ++numVertices;\n }\n if (indices[bIndex] === 0) {\n if (bx === 0) leftSkirtIndices.push(numVertices);else if (bx === max) rightSkirtIndices.push(numVertices);\n if (by === 0) bottomSkirtIndices.push(numVertices);else if (by === max) topSkirtIndices.push(numVertices);\n indices[bIndex] = ++numVertices;\n }\n if (indices[cIndex] === 0) {\n if (cx === 0) leftSkirtIndices.push(numVertices);else if (cx === max) rightSkirtIndices.push(numVertices);\n if (cy === 0) bottomSkirtIndices.push(numVertices);else if (cy === max) topSkirtIndices.push(numVertices);\n indices[cIndex] = ++numVertices;\n }\n numTriangles++;\n }\n }\n countElements(0, 0, max, max, max, 0);\n countElements(max, max, 0, 0, 0, max);\n var numTotalVertices;\n if (isolateSkirtVertices) {\n numTotalVertices = (numVertices + leftSkirtIndices.length * 3 - 2 + rightSkirtIndices.length * 3 - 2 + bottomSkirtIndices.length * 3 - 2 + topSkirtIndices.length * 3 - 2) * 2;\n } else {\n numTotalVertices = (numVertices + leftSkirtIndices.length + rightSkirtIndices.length + bottomSkirtIndices.length + topSkirtIndices.length) * 2;\n }\n var numTotalTriangles = (numTriangles + (leftSkirtIndices.length - 1) * 2 + (rightSkirtIndices.length - 1) * 2 + (bottomSkirtIndices.length - 1) * 2 + (topSkirtIndices.length - 1) * 2) * 3;\n var vertices = new Uint16Array(numTotalVertices);\n var triangles = new Uint32Array(numTotalTriangles);\n var triIndex = 0;\n function processTriangle(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n processTriangle(cx, cy, ax, ay, mx, my);\n processTriangle(bx, by, cx, cy, mx, my);\n } else {\n var a = indices[ay * size + ax] - 1;\n var b = indices[by * size + bx] - 1;\n var c = indices[cy * size + cx] - 1;\n vertices[2 * a] = ax;\n vertices[2 * a + 1] = ay;\n vertices[2 * b] = bx;\n vertices[2 * b + 1] = by;\n vertices[2 * c] = cx;\n vertices[2 * c + 1] = cy;\n triangles[triIndex++] = a;\n triangles[triIndex++] = b;\n triangles[triIndex++] = c;\n }\n }\n processTriangle(0, 0, max, max, max, 0);\n processTriangle(max, max, 0, 0, 0, max);\n leftSkirtIndices.sort(function (a, b) {\n return vertices[2 * a + 1] - vertices[2 * b + 1];\n });\n rightSkirtIndices.sort(function (a, b) {\n return vertices[2 * b + 1] - vertices[2 * a + 1];\n });\n bottomSkirtIndices.sort(function (a, b) {\n return vertices[2 * b] - vertices[2 * a];\n });\n topSkirtIndices.sort(function (a, b) {\n return vertices[2 * a] - vertices[2 * b];\n });\n var skirtIndex = numVertices * 2;\n var currIndex,\n nextIndex,\n currentSkirt,\n nextSkirt,\n skirtLength = 0;\n function constructSkirt(skirt) {\n skirtLength = skirt.length;\n for (var i = 0; i < skirtLength - 1; i++) {\n currIndex = skirt[i];\n nextIndex = skirt[i + 1];\n currentSkirt = skirtIndex / 2;\n nextSkirt = (skirtIndex + (isolateSkirtVertices ? 6 : 2)) / 2;\n vertices[skirtIndex++] = 2 * currIndex;\n vertices[skirtIndex++] = 2 * currIndex + 1;\n if (isolateSkirtVertices) {\n vertices[skirtIndex++] = 2 * currIndex;\n vertices[skirtIndex++] = 2 * currIndex + 1;\n vertices[skirtIndex++] = 2 * nextIndex;\n vertices[skirtIndex++] = 2 * nextIndex + 1;\n }\n if (isolateSkirtVertices) {\n triangles[triIndex++] = currentSkirt + 1;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = currentSkirt + 2;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = nextSkirt;\n triangles[triIndex++] = currentSkirt + 2;\n } else {\n triangles[triIndex++] = currIndex;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = nextIndex;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = nextSkirt;\n triangles[triIndex++] = nextIndex;\n }\n }\n vertices[skirtIndex++] = 2 * skirt[skirtLength - 1];\n vertices[skirtIndex++] = 2 * skirt[skirtLength - 1] + 1;\n }\n constructSkirt(leftSkirtIndices);\n var leftSkirtIndex = skirtIndex;\n constructSkirt(rightSkirtIndices);\n var rightSkirtIndex = skirtIndex;\n constructSkirt(bottomSkirtIndices);\n var bottomSkirtIndex = skirtIndex;\n constructSkirt(topSkirtIndices);\n var topSkirtIndex = skirtIndex;\n return {\n vertices: vertices,\n triangles: triangles,\n numVerticesWithoutSkirts: numVertices,\n numTrianglesWithoutSkirts: numTriangles,\n leftSkirtIndex: leftSkirtIndex,\n rightSkirtIndex: rightSkirtIndex,\n bottomSkirtIndex: bottomSkirtIndex,\n topSkirtIndex: topSkirtIndex };\n\n } }]);\n\n }();return module.exports;});", "requires": [], "buildLevel": 0, "fileName": "/index.js" }, "pandav:/martini.js": { "cubeCode": "Cube(\"pandav:/npm/@maptalks/martini/0.4.0/martini\", [], function (module, exports, require, load, process, global) {\n\n function _classCallCheck(a, n) {if (!(a instanceof n)) throw new TypeError(\"Cannot call a class as a function\");}\n function _defineProperties(e, r) {for (var t = 0; t < r.length; t++) {var o = r[t];o.enumerable = o.enumerable || !1, o.configurable = !0, \"value\" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);}}\n function _createClass(e, r, t) {return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, \"prototype\", { writable: !1 }), e;}\n function _toPropertyKey(t) {var i = _toPrimitive(t, \"string\");return \"symbol\" == _typeof(i) ? i : i + \"\";}\n function _toPrimitive(t, r) {if (\"object\" != _typeof(t) || !t) return t;var e = t[Symbol.toPrimitive];if (void 0 !== e) {var i = e.call(t, r || \"default\");if (\"object\" != _typeof(i)) return i;throw new TypeError(\"@@toPrimitive must return a primitive value.\");}return (\"string\" === r ? String : Number)(t);}\n function _typeof(o) {\"@babel/helpers - typeof\";return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (o) {return typeof o;} : function (o) {return o && \"function\" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? \"symbol\" : typeof o;}, _typeof(o);}\n (function (global, factory) {\n (typeof exports === \"undefined\" ? \"undefined\" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.Martini = factory());\n })(void 0, function () {\n 'use strict';\n\n var Martini = function () {\n function Martini() {\n var gridSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 257;\n _classCallCheck(this, Martini);\n this.gridSize = gridSize;\n var tileSize = gridSize - 1;\n if (tileSize & tileSize - 1) throw new Error(\"Expected grid size to be 2^n+1, got \".concat(gridSize, \".\"));\n this.numTriangles = tileSize * tileSize * 2 - 2;\n this.numParentTriangles = this.numTriangles - tileSize * tileSize;\n this.indices = new Uint32Array(this.gridSize * this.gridSize);\n this.coords = new Uint16Array(this.numTriangles * 4);\n for (var i = 0; i < this.numTriangles; i++) {\n var id = i + 2;\n var ax = 0,\n ay = 0,\n bx = 0,\n by = 0,\n cx = 0,\n cy = 0;\n if (id & 1) {\n bx = by = cx = tileSize;\n } else {\n ax = ay = cy = tileSize;\n }\n while ((id >>= 1) > 1) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (id & 1) {\n bx = ax;\n by = ay;\n ax = cx;\n ay = cy;\n } else {\n ax = bx;\n ay = by;\n bx = cx;\n by = cy;\n }\n cx = mx;\n cy = my;\n }\n var k = i * 4;\n this.coords[k + 0] = ax;\n this.coords[k + 1] = ay;\n this.coords[k + 2] = bx;\n this.coords[k + 3] = by;\n }\n }\n return _createClass(Martini, [{\n key: \"createTile\",\n value: function createTile(terrain) {\n return new Tile(terrain, this);\n } }]);\n\n }();\n var Tile = function () {\n function Tile(terrain, martini) {\n _classCallCheck(this, Tile);\n var size = martini.gridSize;\n if (terrain.length !== size * size) throw new Error(\"Expected terrain data of length \".concat(size * size, \" (\").concat(size, \" x \").concat(size, \"), got \").concat(terrain.length, \".\"));\n this.terrain = terrain;\n this.martini = martini;\n this.errors = new Float32Array(terrain.length);\n this.update();\n }\n return _createClass(Tile, [{\n key: \"update\",\n value: function update() {\n var _this$martini = this.martini,\n numTriangles = _this$martini.numTriangles,\n numParentTriangles = _this$martini.numParentTriangles,\n coords = _this$martini.coords,\n size = _this$martini.gridSize;\n var terrain = this.terrain,\n errors = this.errors;\n for (var i = numTriangles - 1; i >= 0; i--) {\n var k = i * 4;\n var ax = coords[k + 0];\n var ay = coords[k + 1];\n var bx = coords[k + 2];\n var by = coords[k + 3];\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n var cx = mx + my - ay;\n var cy = my + ax - mx;\n var interpolatedHeight = (terrain[ay * size + ax] + terrain[by * size + bx]) / 2;\n var middleIndex = my * size + mx;\n var middleError = Math.abs(interpolatedHeight - terrain[middleIndex]);\n errors[middleIndex] = Math.max(errors[middleIndex], middleError);\n if (i < numParentTriangles) {\n var leftChildIndex = (ay + cy >> 1) * size + (ax + cx >> 1);\n var rightChildIndex = (by + cy >> 1) * size + (bx + cx >> 1);\n errors[middleIndex] = Math.max(errors[middleIndex], errors[leftChildIndex], errors[rightChildIndex]);\n }\n }\n } },\n {\n key: \"getMesh\",\n value: function getMesh() {\n var maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var _this$martini2 = this.martini,\n size = _this$martini2.gridSize,\n indices = _this$martini2.indices;\n var errors = this.errors;\n var numVertices = 0;\n var numTriangles = 0;\n var max = size - 1;\n indices.fill(0);\n function countElements(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n countElements(cx, cy, ax, ay, mx, my);\n countElements(bx, by, cx, cy, mx, my);\n } else {\n indices[ay * size + ax] = indices[ay * size + ax] || ++numVertices;\n indices[by * size + bx] = indices[by * size + bx] || ++numVertices;\n indices[cy * size + cx] = indices[cy * size + cx] || ++numVertices;\n numTriangles++;\n }\n }\n countElements(0, 0, max, max, max, 0);\n countElements(max, max, 0, 0, 0, max);\n var vertices = new Uint16Array(numVertices * 2);\n var triangles = new Uint32Array(numTriangles * 3);\n var triIndex = 0;\n function processTriangle(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n processTriangle(cx, cy, ax, ay, mx, my);\n processTriangle(bx, by, cx, cy, mx, my);\n } else {\n var a = indices[ay * size + ax] - 1;\n var b = indices[by * size + bx] - 1;\n var c = indices[cy * size + cx] - 1;\n vertices[2 * a] = ax;\n vertices[2 * a + 1] = ay;\n vertices[2 * b] = bx;\n vertices[2 * b + 1] = by;\n vertices[2 * c] = cx;\n vertices[2 * c + 1] = cy;\n triangles[triIndex++] = a;\n triangles[triIndex++] = b;\n triangles[triIndex++] = c;\n }\n }\n processTriangle(0, 0, max, max, max, 0);\n processTriangle(max, max, 0, 0, 0, max);\n return {\n vertices: vertices,\n triangles: triangles };\n\n } },\n {\n key: \"getMeshWithSkirts\",\n value: function getMeshWithSkirts() {\n var maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;\n var isolateSkirtVertices = arguments.length > 1 ? arguments[1] : undefined;\n var _this$martini3 = this.martini,\n size = _this$martini3.gridSize,\n indices = _this$martini3.indices;\n var errors = this.errors;\n var numVertices = 0;\n var numTriangles = 0;\n var max = size - 1;\n var aIndex,\n bIndex,\n cIndex = 0;\n var leftSkirtIndices = [];\n var rightSkirtIndices = [];\n var bottomSkirtIndices = [];\n var topSkirtIndices = [];\n indices.fill(0);\n function countElements(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n countElements(cx, cy, ax, ay, mx, my);\n countElements(bx, by, cx, cy, mx, my);\n } else {\n aIndex = ay * size + ax;\n bIndex = by * size + bx;\n cIndex = cy * size + cx;\n if (indices[aIndex] === 0) {\n if (ax === 0) leftSkirtIndices.push(numVertices);else if (ax === max) rightSkirtIndices.push(numVertices);\n if (ay === 0) bottomSkirtIndices.push(numVertices);else if (ay === max) topSkirtIndices.push(numVertices);\n indices[aIndex] = ++numVertices;\n }\n if (indices[bIndex] === 0) {\n if (bx === 0) leftSkirtIndices.push(numVertices);else if (bx === max) rightSkirtIndices.push(numVertices);\n if (by === 0) bottomSkirtIndices.push(numVertices);else if (by === max) topSkirtIndices.push(numVertices);\n indices[bIndex] = ++numVertices;\n }\n if (indices[cIndex] === 0) {\n if (cx === 0) leftSkirtIndices.push(numVertices);else if (cx === max) rightSkirtIndices.push(numVertices);\n if (cy === 0) bottomSkirtIndices.push(numVertices);else if (cy === max) topSkirtIndices.push(numVertices);\n indices[cIndex] = ++numVertices;\n }\n numTriangles++;\n }\n }\n countElements(0, 0, max, max, max, 0);\n countElements(max, max, 0, 0, 0, max);\n var numTotalVertices;\n if (isolateSkirtVertices) {\n numTotalVertices = (numVertices + leftSkirtIndices.length * 3 - 2 + rightSkirtIndices.length * 3 - 2 + bottomSkirtIndices.length * 3 - 2 + topSkirtIndices.length * 3 - 2) * 2;\n } else {\n numTotalVertices = (numVertices + leftSkirtIndices.length + rightSkirtIndices.length + bottomSkirtIndices.length + topSkirtIndices.length) * 2;\n }\n var numTotalTriangles = (numTriangles + (leftSkirtIndices.length - 1) * 2 + (rightSkirtIndices.length - 1) * 2 + (bottomSkirtIndices.length - 1) * 2 + (topSkirtIndices.length - 1) * 2) * 3;\n var vertices = new Uint16Array(numTotalVertices);\n var triangles = new Uint32Array(numTotalTriangles);\n var triIndex = 0;\n function processTriangle(ax, ay, bx, by, cx, cy) {\n var mx = ax + bx >> 1;\n var my = ay + by >> 1;\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n processTriangle(cx, cy, ax, ay, mx, my);\n processTriangle(bx, by, cx, cy, mx, my);\n } else {\n var a = indices[ay * size + ax] - 1;\n var b = indices[by * size + bx] - 1;\n var c = indices[cy * size + cx] - 1;\n vertices[2 * a] = ax;\n vertices[2 * a + 1] = ay;\n vertices[2 * b] = bx;\n vertices[2 * b + 1] = by;\n vertices[2 * c] = cx;\n vertices[2 * c + 1] = cy;\n triangles[triIndex++] = a;\n triangles[triIndex++] = b;\n triangles[triIndex++] = c;\n }\n }\n processTriangle(0, 0, max, max, max, 0);\n processTriangle(max, max, 0, 0, 0, max);\n leftSkirtIndices.sort(function (a, b) {\n return vertices[2 * a + 1] - vertices[2 * b + 1];\n });\n rightSkirtIndices.sort(function (a, b) {\n return vertices[2 * b + 1] - vertices[2 * a + 1];\n });\n bottomSkirtIndices.sort(function (a, b) {\n return vertices[2 * b] - vertices[2 * a];\n });\n topSkirtIndices.sort(function (a, b) {\n return vertices[2 * a] - vertices[2 * b];\n });\n var skirtIndex = numVertices * 2;\n var currIndex,\n nextIndex,\n currentSkirt,\n nextSkirt,\n skirtLength = 0;\n function constructSkirt(skirt) {\n skirtLength = skirt.length;\n for (var i = 0; i < skirtLength - 1; i++) {\n currIndex = skirt[i];\n nextIndex = skirt[i + 1];\n currentSkirt = skirtIndex / 2;\n nextSkirt = (skirtIndex + (isolateSkirtVertices ? 6 : 2)) / 2;\n vertices[skirtIndex++] = 2 * currIndex;\n vertices[skirtIndex++] = 2 * currIndex + 1;\n if (isolateSkirtVertices) {\n vertices[skirtIndex++] = 2 * currIndex;\n vertices[skirtIndex++] = 2 * currIndex + 1;\n vertices[skirtIndex++] = 2 * nextIndex;\n vertices[skirtIndex++] = 2 * nextIndex + 1;\n }\n if (isolateSkirtVertices) {\n triangles[triIndex++] = currentSkirt + 1;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = currentSkirt + 2;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = nextSkirt;\n triangles[triIndex++] = currentSkirt + 2;\n } else {\n triangles[triIndex++] = currIndex;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = nextIndex;\n triangles[triIndex++] = currentSkirt;\n triangles[triIndex++] = nextSkirt;\n triangles[triIndex++] = nextIndex;\n }\n }\n vertices[skirtIndex++] = 2 * skirt[skirtLength - 1];\n vertices[skirtIndex++] = 2 * skirt[skirtLength - 1] + 1;\n }\n constructSkirt(leftSkirtIndices);\n var leftSkirtIndex = skirtIndex;\n constructSkirt(rightSkirtIndices);\n var rightSkirtIndex = skirtIndex;\n constructSkirt(bottomSkirtIndices);\n var bottomSkirtIndex = skirtIndex;\n constructSkirt(topSkirtIndices);\n var topSkirtIndex = skirtIndex;\n return {\n vertices: vertices,\n triangles: triangles,\n numVerticesWithoutSkirts: numVertices,\n numTrianglesWithoutSkirts: numTriangles,\n leftSkirtIndex: leftSkirtIndex,\n rightSkirtIndex: rightSkirtIndex,\n bottomSkirtIndex: bottomSkirtIndex,\n topSkirtIndex: topSkirtIndex };\n\n } }]);\n\n }();\n return Martini;\n });return module.exports;});", "requires": [], "buildLevel": 0, "fileName": "/martini.js" } }