@loaders.gl/terrain 3.1.3 → 4.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/index.js +14 -24
- package/dist/index.js.map +1 -0
- package/dist/lib/decode-quantized-mesh.js +241 -200
- package/dist/lib/decode-quantized-mesh.js.map +1 -0
- package/dist/lib/delatin/index.js +443 -397
- package/dist/lib/delatin/index.js.map +1 -0
- package/dist/lib/helpers/skirt.js +91 -119
- package/dist/lib/helpers/skirt.js.map +1 -0
- package/dist/lib/parse-quantized-mesh.js +90 -89
- package/dist/lib/parse-quantized-mesh.js.map +1 -0
- package/dist/lib/parse-terrain.js +166 -148
- package/dist/lib/parse-terrain.js.map +1 -0
- package/dist/lib/utils/version.js +2 -7
- package/dist/lib/utils/version.js.map +1 -0
- package/dist/quantized-mesh-loader.js +16 -21
- package/dist/quantized-mesh-loader.js.map +1 -0
- package/dist/quantized-mesh-worker.js +1 -1
- package/dist/terrain-loader.js +24 -32
- package/dist/terrain-loader.js.map +1 -0
- package/dist/terrain-worker.js +1 -1
- package/dist/workers/quantized-mesh-worker.js +4 -5
- package/dist/workers/quantized-mesh-worker.js.map +1 -0
- package/dist/workers/terrain-worker.js +4 -5
- package/dist/workers/terrain-worker.js.map +1 -0
- package/package.json +8 -8
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -77
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/decode-quantized-mesh.js +0 -299
- package/dist/es5/lib/decode-quantized-mesh.js.map +0 -1
- package/dist/es5/lib/delatin/index.js +0 -506
- package/dist/es5/lib/delatin/index.js.map +0 -1
- package/dist/es5/lib/helpers/skirt.js +0 -120
- package/dist/es5/lib/helpers/skirt.js.map +0 -1
- package/dist/es5/lib/parse-quantized-mesh.js +0 -119
- package/dist/es5/lib/parse-quantized-mesh.js.map +0 -1
- package/dist/es5/lib/parse-terrain.js +0 -219
- package/dist/es5/lib/parse-terrain.js.map +0 -1
- package/dist/es5/lib/utils/version.js +0 -9
- package/dist/es5/lib/utils/version.js.map +0 -1
- package/dist/es5/quantized-mesh-loader.js +0 -28
- package/dist/es5/quantized-mesh-loader.js.map +0 -1
- package/dist/es5/terrain-loader.js +0 -36
- package/dist/es5/terrain-loader.js.map +0 -1
- package/dist/es5/workers/quantized-mesh-worker.js +0 -8
- package/dist/es5/workers/quantized-mesh-worker.js.map +0 -1
- package/dist/es5/workers/terrain-worker.js +0 -8
- package/dist/es5/workers/terrain-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -16
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/decode-quantized-mesh.js +0 -268
- package/dist/esm/lib/decode-quantized-mesh.js.map +0 -1
- package/dist/esm/lib/delatin/index.js +0 -464
- package/dist/esm/lib/delatin/index.js.map +0 -1
- package/dist/esm/lib/helpers/skirt.js +0 -99
- package/dist/esm/lib/helpers/skirt.js.map +0 -1
- package/dist/esm/lib/parse-quantized-mesh.js +0 -96
- package/dist/esm/lib/parse-quantized-mesh.js.map +0 -1
- package/dist/esm/lib/parse-terrain.js +0 -180
- package/dist/esm/lib/parse-terrain.js.map +0 -1
- package/dist/esm/lib/utils/version.js +0 -2
- package/dist/esm/lib/utils/version.js.map +0 -1
- package/dist/esm/quantized-mesh-loader.js +0 -18
- package/dist/esm/quantized-mesh-loader.js.map +0 -1
- package/dist/esm/terrain-loader.js +0 -26
- package/dist/esm/terrain-loader.js.map +0 -1
- package/dist/esm/workers/quantized-mesh-worker.js +0 -4
- package/dist/esm/workers/quantized-mesh-worker.js.map +0 -1
- package/dist/esm/workers/terrain-worker.js +0 -4
- package/dist/esm/workers/terrain-worker.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/delatin/index.ts"],"names":["Delatin","constructor","data","width","height","coords","triangles","_halfedges","_candidates","_queueIndices","_queue","_errors","_rms","_pending","_pendingLen","_rmsSum","x1","y1","p0","_addPoint","p1","p2","p3","t0","_addTriangle","_flush","run","maxError","getMaxError","refine","_step","getRMSD","Math","sqrt","heightAt","x","y","i","t","a","b","c","_findCandidate","p0x","p0y","p1x","p1y","p2x","p2y","minX","min","minY","maxX","max","maxY","w00","orient","w01","w02","a01","b01","a12","b12","a20","b20","z0","z1","z2","mx","my","rms","dx","floor","w0","w1","w2","wasInside","z","dz","abs","_queuePush","_queuePop","e0","e1","e2","ax","ay","bx","by","cx","cy","px","py","pn","_handleCollinear","h0","h1","h2","t1","t2","_legalize","length","push","ab","bc","ca","e","a0","b0","al","ar","bl","br","pr","pl","inCircle","hal","har","hbl","hbr","_queueRemove","t3","error","_queueUp","n","_queueSwap","_queueDown","_queuePopBack","pop","it","indexOf","Error","_queueLess","j","pi","pj","j0","i0","j1","j2","dy","ex","ey","fx","fy","ap","bp","cp"],"mappings":"AAmBA,eAAe,MAAMA,OAAN,CAAc;AAC3BC,EAAAA,WAAW,CAACC,IAAD,EAAOC,KAAP,EAAcC,MAAM,GAAGD,KAAvB,EAA8B;AACvC,SAAKD,IAAL,GAAYA,IAAZ;AACA,SAAKC,KAAL,GAAaA,KAAb;AACA,SAAKC,MAAL,GAAcA,MAAd;AAEA,SAAKC,MAAL,GAAc,EAAd;AACA,SAAKC,SAAL,GAAiB,EAAjB;AAGA,SAAKC,UAAL,GAAkB,EAAlB;AACA,SAAKC,WAAL,GAAmB,EAAnB;AACA,SAAKC,aAAL,GAAqB,EAArB;AAEA,SAAKC,MAAL,GAAc,EAAd;AACA,SAAKC,OAAL,GAAe,EAAf;AACA,SAAKC,IAAL,GAAY,EAAZ;AACA,SAAKC,QAAL,GAAgB,EAAhB;AACA,SAAKC,WAAL,GAAmB,CAAnB;AAEA,SAAKC,OAAL,GAAe,CAAf;AAEA,UAAMC,EAAE,GAAGb,KAAK,GAA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GE,EAAhB;AACA,QAAMqD,EAAE,GAAGtD,EAAE,GAAGE,EAAhB;AAEA,QAAMqD,EAAE,GAAG1E,EAAE,GAAGA,EAAL,GAAUqE,EAAE,GAAGA,EAA1B;AACA,QAAMM,EAAE,GAAGL,EAAE,GAAGA,EAAL,GAAUC,EAAE,GAAGA,EAA1B;AACA,QAAMK,EAAE,GAAGJ,EAAE,GAAGA,EAAL,GAAUC,EAAE,GAAGA,EAA1B;AAEA,SAAOzE,EAAE,IAAIuE,EAAE,GAAGK,EAAL,GAAUD,EAAE,GAAGF,EAAnB,CAAF,GAA2BJ,EAAE,IAAIC,EAAE,GAAGM,EAAL,GAAUD,EAAE,GAAGH,EAAnB,CAA7B,GAAsDE,EAAE,IAAIJ,EAAE,GAAGG,EAAL,GAAUF,EAAE,GAAGC,EAAnB,CAAxD,GAAiF,CAAxF;AACD","sourcesContent":["// ISC License\n\n// Copyright(c) 2019, Michael Fogleman, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and / or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS.IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\n// @ts-nocheck\n\n/* eslint-disable complexity, max-params, max-statements, max-depth, no-constant-condition */\nexport default class Delatin {\n constructor(data, width, height = width) {\n this.data = data; // height data\n this.width = width;\n this.height = height;\n\n this.coords = []; // vertex coordinates (x, y)\n this.triangles = []; // mesh triangle indices\n\n // additional triangle data\n this._halfedges = [];\n this._candidates = [];\n this._queueIndices = [];\n\n this._queue = []; // queue of added triangles\n this._errors = [];\n this._rms = [];\n this._pending = []; // triangles pending addition to queue\n this._pendingLen = 0;\n\n this._rmsSum = 0;\n\n const x1 = width - 1;\n const y1 = height - 1;\n const p0 = this._addPoint(0, 0);\n const p1 = this._addPoint(x1, 0);\n const p2 = this._addPoint(0, y1);\n const p3 = this._addPoint(x1, y1);\n\n // add initial two triangles\n const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);\n this._addTriangle(p0, p3, p1, t0, -1, -1);\n this._flush();\n }\n\n // refine the mesh until its maximum error gets below the given one\n run(maxError = 1) {\n while (this.getMaxError() > maxError) {\n this.refine();\n }\n }\n\n // refine the mesh with a single point\n refine() {\n this._step();\n this._flush();\n }\n\n // max error of the current mesh\n getMaxError() {\n return this._errors[0];\n }\n\n // root-mean-square deviation of the current mesh\n getRMSD() {\n return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;\n }\n\n // height value at a given position\n heightAt(x, y) {\n return this.data[this.width * y + x];\n }\n\n // rasterize and queue all triangles that got added or updated in _step\n _flush() {\n const coords = this.coords;\n for (let i = 0; i < this._pendingLen; i++) {\n const t = this._pending[i];\n // rasterize triangle to find maximum pixel error\n const a = 2 * this.triangles[t * 3 + 0];\n const b = 2 * this.triangles[t * 3 + 1];\n const c = 2 * this.triangles[t * 3 + 2];\n this._findCandidate(\n coords[a],\n coords[a + 1],\n coords[b],\n coords[b + 1],\n coords[c],\n coords[c + 1],\n t\n );\n }\n this._pendingLen = 0;\n }\n\n // rasterize a triangle, find its max error, and queue it for processing\n _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {\n // triangle bounding box\n const minX = Math.min(p0x, p1x, p2x);\n const minY = Math.min(p0y, p1y, p2y);\n const maxX = Math.max(p0x, p1x, p2x);\n const maxY = Math.max(p0y, p1y, p2y);\n\n // forward differencing variables\n let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);\n let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);\n let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);\n const a01 = p1y - p0y;\n const b01 = p0x - p1x;\n const a12 = p2y - p1y;\n const b12 = p1x - p2x;\n const a20 = p0y - p2y;\n const b20 = p2x - p0x;\n\n // pre-multiplied z values at vertices\n const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);\n const z0 = this.heightAt(p0x, p0y) / a;\n const z1 = this.heightAt(p1x, p1y) / a;\n const z2 = this.heightAt(p2x, p2y) / a;\n\n // iterate over pixels in bounding box\n let maxError = 0;\n let mx = 0;\n let my = 0;\n let rms = 0;\n for (let y = minY; y <= maxY; y++) {\n // compute starting offset\n let dx = 0;\n if (w00 < 0 && a12 !== 0) {\n dx = Math.max(dx, Math.floor(-w00 / a12));\n }\n if (w01 < 0 && a20 !== 0) {\n dx = Math.max(dx, Math.floor(-w01 / a20));\n }\n if (w02 < 0 && a01 !== 0) {\n dx = Math.max(dx, Math.floor(-w02 / a01));\n }\n\n let w0 = w00 + a12 * dx;\n let w1 = w01 + a20 * dx;\n let w2 = w02 + a01 * dx;\n\n let wasInside = false;\n\n for (let x = minX + dx; x <= maxX; x++) {\n // check if inside triangle\n if (w0 >= 0 && w1 >= 0 && w2 >= 0) {\n wasInside = true;\n\n // compute z using barycentric coordinates\n const z = z0 * w0 + z1 * w1 + z2 * w2;\n const dz = Math.abs(z - this.heightAt(x, y));\n rms += dz * dz;\n if (dz > maxError) {\n maxError = dz;\n mx = x;\n my = y;\n }\n } else if (wasInside) {\n break;\n }\n\n w0 += a12;\n w1 += a20;\n w2 += a01;\n }\n\n w00 += b12;\n w01 += b20;\n w02 += b01;\n }\n\n if ((mx === p0x && my === p0y) || (mx === p1x && my === p1y) || (mx === p2x && my === p2y)) {\n maxError = 0;\n }\n\n // update triangle metadata\n this._candidates[2 * t] = mx;\n this._candidates[2 * t + 1] = my;\n this._rms[t] = rms;\n\n // add triangle to priority queue\n this._queuePush(t, maxError, rms);\n }\n\n // process the next triangle in the queue, splitting it with a new point\n _step() {\n // pop triangle with highest error from priority queue\n const t = this._queuePop();\n\n const e0 = t * 3 + 0;\n const e1 = t * 3 + 1;\n const e2 = t * 3 + 2;\n\n const p0 = this.triangles[e0];\n const p1 = this.triangles[e1];\n const p2 = this.triangles[e2];\n\n const ax = this.coords[2 * p0];\n const ay = this.coords[2 * p0 + 1];\n const bx = this.coords[2 * p1];\n const by = this.coords[2 * p1 + 1];\n const cx = this.coords[2 * p2];\n const cy = this.coords[2 * p2 + 1];\n const px = this._candidates[2 * t];\n const py = this._candidates[2 * t + 1];\n\n const pn = this._addPoint(px, py);\n\n if (orient(ax, ay, bx, by, px, py) === 0) {\n this._handleCollinear(pn, e0);\n } else if (orient(bx, by, cx, cy, px, py) === 0) {\n this._handleCollinear(pn, e1);\n } else if (orient(cx, cy, ax, ay, px, py) === 0) {\n this._handleCollinear(pn, e2);\n } else {\n const h0 = this._halfedges[e0];\n const h1 = this._halfedges[e1];\n const h2 = this._halfedges[e2];\n\n const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);\n const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);\n const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);\n\n this._legalize(t0);\n this._legalize(t1);\n this._legalize(t2);\n }\n }\n\n // add coordinates for a new vertex\n _addPoint(x, y) {\n const i = this.coords.length >> 1;\n this.coords.push(x, y);\n return i;\n }\n\n // add or update a triangle in the mesh\n _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {\n const t = e / 3; // new triangle index\n\n // add triangle vertices\n this.triangles[e + 0] = a;\n this.triangles[e + 1] = b;\n this.triangles[e + 2] = c;\n\n // add triangle halfedges\n this._halfedges[e + 0] = ab;\n this._halfedges[e + 1] = bc;\n this._halfedges[e + 2] = ca;\n\n // link neighboring halfedges\n if (ab >= 0) {\n this._halfedges[ab] = e + 0;\n }\n if (bc >= 0) {\n this._halfedges[bc] = e + 1;\n }\n if (ca >= 0) {\n this._halfedges[ca] = e + 2;\n }\n\n // init triangle metadata\n this._candidates[2 * t + 0] = 0;\n this._candidates[2 * t + 1] = 0;\n this._queueIndices[t] = -1;\n this._rms[t] = 0;\n\n // add triangle to pending queue for later rasterization\n this._pending[this._pendingLen++] = t;\n\n // return first halfedge index\n return e;\n }\n\n _legalize(a) {\n // if the pair of triangles doesn't satisfy the Delaunay condition\n // (p1 is inside the circumcircle of [p0, pl, pr]), flip them,\n // then do the same check/flip recursively for the new pair of triangles\n //\n // pl pl\n // /||\\ / \\\n // al/ || \\bl al/ \\a\n // / || \\ / \\\n // / a||b \\ flip /___ar___\\\n // p0\\ || /p1 => p0\\---bl---/p1\n // \\ || / \\ /\n // ar\\ || /br b\\ /br\n // \\||/ \\ /\n // pr pr\n\n const b = this._halfedges[a];\n\n if (b < 0) {\n return;\n }\n\n const a0 = a - (a % 3);\n const b0 = b - (b % 3);\n const al = a0 + ((a + 1) % 3);\n const ar = a0 + ((a + 2) % 3);\n const bl = b0 + ((b + 2) % 3);\n const br = b0 + ((b + 1) % 3);\n const p0 = this.triangles[ar];\n const pr = this.triangles[a];\n const pl = this.triangles[al];\n const p1 = this.triangles[bl];\n const coords = this.coords;\n\n if (\n !inCircle(\n coords[2 * p0],\n coords[2 * p0 + 1],\n coords[2 * pr],\n coords[2 * pr + 1],\n coords[2 * pl],\n coords[2 * pl + 1],\n coords[2 * p1],\n coords[2 * p1 + 1]\n )\n ) {\n return;\n }\n\n const hal = this._halfedges[al];\n const har = this._halfedges[ar];\n const hbl = this._halfedges[bl];\n const hbr = this._halfedges[br];\n\n this._queueRemove(a0 / 3);\n this._queueRemove(b0 / 3);\n\n const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);\n const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);\n\n this._legalize(t0 + 1);\n this._legalize(t1 + 2);\n }\n\n // handle a case where new vertex is on the edge of a triangle\n _handleCollinear(pn, a) {\n const a0 = a - (a % 3);\n const al = a0 + ((a + 1) % 3);\n const ar = a0 + ((a + 2) % 3);\n const p0 = this.triangles[ar];\n const pr = this.triangles[a];\n const pl = this.triangles[al];\n const hal = this._halfedges[al];\n const har = this._halfedges[ar];\n\n const b = this._halfedges[a];\n\n if (b < 0) {\n const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);\n const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);\n this._legalize(t0 + 1);\n this._legalize(t1 + 2);\n return;\n }\n\n const b0 = b - (b % 3);\n const bl = b0 + ((b + 2) % 3);\n const br = b0 + ((b + 1) % 3);\n const p1 = this.triangles[bl];\n const hbl = this._halfedges[bl];\n const hbr = this._halfedges[br];\n\n this._queueRemove(b0 / 3);\n\n const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);\n const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);\n const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);\n const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);\n\n this._legalize(t0);\n this._legalize(t1);\n this._legalize(t2);\n this._legalize(t3);\n }\n\n // priority queue methods\n\n _queuePush(t, error, rms) {\n const i = this._queue.length;\n this._queueIndices[t] = i;\n this._queue.push(t);\n this._errors.push(error);\n this._rmsSum += rms;\n this._queueUp(i);\n }\n\n _queuePop() {\n const n = this._queue.length - 1;\n this._queueSwap(0, n);\n this._queueDown(0, n);\n return this._queuePopBack();\n }\n\n _queuePopBack() {\n const t = this._queue.pop();\n this._errors.pop();\n this._rmsSum -= this._rms[t];\n this._queueIndices[t] = -1;\n return t;\n }\n\n _queueRemove(t) {\n const i = this._queueIndices[t];\n if (i < 0) {\n const it = this._pending.indexOf(t);\n if (it !== -1) {\n this._pending[it] = this._pending[--this._pendingLen];\n } else {\n throw new Error('Broken triangulation (something went wrong).');\n }\n return;\n }\n const n = this._queue.length - 1;\n if (n !== i) {\n this._queueSwap(i, n);\n if (!this._queueDown(i, n)) {\n this._queueUp(i);\n }\n }\n this._queuePopBack();\n }\n\n _queueLess(i, j) {\n return this._errors[i] > this._errors[j];\n }\n\n _queueSwap(i, j) {\n const pi = this._queue[i];\n const pj = this._queue[j];\n this._queue[i] = pj;\n this._queue[j] = pi;\n this._queueIndices[pi] = j;\n this._queueIndices[pj] = i;\n const e = this._errors[i];\n this._errors[i] = this._errors[j];\n this._errors[j] = e;\n }\n\n _queueUp(j0) {\n let j = j0;\n while (true) {\n const i = (j - 1) >> 1;\n if (i === j || !this._queueLess(j, i)) {\n break;\n }\n this._queueSwap(i, j);\n j = i;\n }\n }\n\n _queueDown(i0, n) {\n let i = i0;\n while (true) {\n const j1 = 2 * i + 1;\n if (j1 >= n || j1 < 0) {\n break;\n }\n const j2 = j1 + 1;\n let j = j1;\n if (j2 < n && this._queueLess(j2, j1)) {\n j = j2;\n }\n if (!this._queueLess(j, i)) {\n break;\n }\n this._queueSwap(i, j);\n i = j;\n }\n return i > i0;\n }\n}\n\nfunction orient(ax, ay, bx, by, cx, cy) {\n return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);\n}\n\nfunction inCircle(ax, ay, bx, by, cx, cy, px, py) {\n const dx = ax - px;\n const dy = ay - py;\n const ex = bx - px;\n const ey = by - py;\n const fx = cx - px;\n const fy = cy - py;\n\n const ap = dx * dx + dy * dy;\n const bp = ex * ex + ey * ey;\n const cp = fx * fx + fy * fy;\n\n return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;\n}\n"],"file":"index.js"}
|
|
@@ -1,127 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
skirtHeight,
|
|
29
|
-
newPosition,
|
|
30
|
-
newTexcoord0,
|
|
31
|
-
newTriangles
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
attributes.POSITION.value = (0, loader_utils_1.concatenateTypedArrays)(attributes.POSITION.value, newPosition);
|
|
35
|
-
attributes.TEXCOORD_0.value = (0, loader_utils_1.concatenateTypedArrays)(attributes.TEXCOORD_0.value, newTexcoord0);
|
|
36
|
-
const resultTriangles = triangles instanceof Array
|
|
37
|
-
? triangles.concat(newTriangles)
|
|
38
|
-
: (0, loader_utils_1.concatenateTypedArrays)(triangles, newTriangles);
|
|
39
|
-
return {
|
|
40
|
-
attributes,
|
|
41
|
-
triangles: resultTriangles
|
|
42
|
-
};
|
|
1
|
+
import { concatenateTypedArrays } from '@loaders.gl/loader-utils';
|
|
2
|
+
export function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
|
|
3
|
+
const outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
|
|
4
|
+
const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
|
|
5
|
+
const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
|
|
6
|
+
const newTriangles = new triangles.constructor(outsideEdges.length * 6);
|
|
7
|
+
|
|
8
|
+
for (let i = 0; i < outsideEdges.length; i++) {
|
|
9
|
+
const edge = outsideEdges[i];
|
|
10
|
+
updateAttributesForNewEdge({
|
|
11
|
+
edge,
|
|
12
|
+
edgeIndex: i,
|
|
13
|
+
attributes,
|
|
14
|
+
skirtHeight,
|
|
15
|
+
newPosition,
|
|
16
|
+
newTexcoord0,
|
|
17
|
+
newTriangles
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);
|
|
22
|
+
attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);
|
|
23
|
+
const resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : concatenateTypedArrays(triangles, newTriangles);
|
|
24
|
+
return {
|
|
25
|
+
attributes,
|
|
26
|
+
triangles: resultTriangles
|
|
27
|
+
};
|
|
43
28
|
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get geometry edges that located on a border of the mesh
|
|
47
|
-
* @param {any} triangles - indices array of the mesh geometry
|
|
48
|
-
* @returns {number[][]} - outside edges data
|
|
49
|
-
*/
|
|
29
|
+
|
|
50
30
|
function getOutsideEdgesFromTriangles(triangles) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
31
|
+
const edges = [];
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < triangles.length; i += 3) {
|
|
34
|
+
edges.push([triangles[i], triangles[i + 1]]);
|
|
35
|
+
edges.push([triangles[i + 1], triangles[i + 2]]);
|
|
36
|
+
edges.push([triangles[i + 2], triangles[i]]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
|
|
40
|
+
const outsideEdges = [];
|
|
41
|
+
let index = 1;
|
|
42
|
+
|
|
43
|
+
while (index < edges.length) {
|
|
44
|
+
if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
|
|
45
|
+
index += 2;
|
|
46
|
+
} else {
|
|
47
|
+
outsideEdges.push(edges[index - 1]);
|
|
48
|
+
index++;
|
|
68
49
|
}
|
|
69
|
-
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return outsideEdges;
|
|
70
53
|
}
|
|
71
|
-
|
|
72
|
-
* Get geometry edges that located on a border of the mesh
|
|
73
|
-
* @param {object} indices - edge indices from quantized mesh data
|
|
74
|
-
* @param {TypedArray} position - position attribute geometry data
|
|
75
|
-
* @returns {number[][]} - outside edges data
|
|
76
|
-
*/
|
|
54
|
+
|
|
77
55
|
function getOutsideEdgesFromIndices(indices, position) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
edges.push([indexGroup[i], indexGroup[i + 1]]);
|
|
90
|
-
}
|
|
56
|
+
indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
|
|
57
|
+
indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
|
|
58
|
+
indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
|
|
59
|
+
indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
|
|
60
|
+
const edges = [];
|
|
61
|
+
|
|
62
|
+
for (const index in indices) {
|
|
63
|
+
const indexGroup = indices[index];
|
|
64
|
+
|
|
65
|
+
for (let i = 0; i < indexGroup.length - 1; i++) {
|
|
66
|
+
edges.push([indexGroup[i], indexGroup[i + 1]]);
|
|
91
67
|
}
|
|
92
|
-
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return edges;
|
|
93
71
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const triangle1Offset = edgeIndex * 2 * 3;
|
|
121
|
-
newTriangles[triangle1Offset] = edge[0];
|
|
122
|
-
newTriangles[triangle1Offset + 1] = edge[1];
|
|
123
|
-
newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;
|
|
124
|
-
newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
|
|
125
|
-
newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;
|
|
126
|
-
newTriangles[triangle1Offset + 5] = edge[0];
|
|
72
|
+
|
|
73
|
+
function updateAttributesForNewEdge({
|
|
74
|
+
edge,
|
|
75
|
+
edgeIndex,
|
|
76
|
+
attributes,
|
|
77
|
+
skirtHeight,
|
|
78
|
+
newPosition,
|
|
79
|
+
newTexcoord0,
|
|
80
|
+
newTriangles
|
|
81
|
+
}) {
|
|
82
|
+
const positionsLength = attributes.POSITION.value.length;
|
|
83
|
+
const vertex1Offset = edgeIndex * 2;
|
|
84
|
+
const vertex2Offset = edgeIndex * 2 + 1;
|
|
85
|
+
newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
|
|
86
|
+
newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;
|
|
87
|
+
newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
|
|
88
|
+
newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight;
|
|
89
|
+
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
|
|
90
|
+
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
|
|
91
|
+
const triangle1Offset = edgeIndex * 2 * 3;
|
|
92
|
+
newTriangles[triangle1Offset] = edge[0];
|
|
93
|
+
newTriangles[triangle1Offset + 1] = edge[1];
|
|
94
|
+
newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;
|
|
95
|
+
newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
|
|
96
|
+
newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;
|
|
97
|
+
newTriangles[triangle1Offset + 5] = edge[0];
|
|
127
98
|
}
|
|
99
|
+
//# sourceMappingURL=skirt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/helpers/skirt.ts"],"names":["concatenateTypedArrays","addSkirt","attributes","triangles","skirtHeight","outsideIndices","outsideEdges","getOutsideEdgesFromIndices","POSITION","value","getOutsideEdgesFromTriangles","newPosition","constructor","length","newTexcoord0","TEXCOORD_0","newTriangles","i","edge","updateAttributesForNewEdge","edgeIndex","resultTriangles","Array","concat","edges","push","sort","a","b","Math","min","max","index","indices","position","westIndices","eastIndices","southIndices","northIndices","indexGroup","positionsLength","vertex1Offset","vertex2Offset","set","subarray","triangle1Offset"],"mappings":"AAAA,SAAQA,sBAAR,QAAqC,0BAArC;AAiBA,OAAO,SAASC,QAAT,CAAkBC,UAAlB,EAA8BC,SAA9B,EAAyCC,WAAzC,EAA8DC,cAA9D,EAA4F;AACjG,QAAMC,YAAY,GAAGD,cAAc,GAC/BE,0BAA0B,CAACF,cAAD,EAAiBH,UAAU,CAACM,QAAX,CAAoBC,KAArC,CADK,GAE/BC,4BAA4B,CAACP,SAAD,CAFhC;AAKA,QAAMQ,WAAW,GAAG,IAAIT,UAAU,CAACM,QAAX,CAAoBC,KAApB,CAA0BG,WAA9B,CAA0CN,YAAY,CAACO,MAAb,GAAsB,CAAhE,CAApB;AACA,QAAMC,YAAY,GAAG,IAAIZ,UAAU,CAACa,UAAX,CAAsBN,KAAtB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AG,CAFlB;AAIA3B,EAAAA,YAAY,CAAC6B,GAAb,CACEzC,UAAU,CAACa,UAAX,CAAsBN,KAAtB,CAA4BmC,QAA5B,CAAqC1B,IAAI,CAAC,CAAD,CAAJ,GAAU,CAA/C,EAAkDA,IAAI,CAAC,CAAD,CAAJ,GAAU,CAAV,GAAc,CAAhE,CADF,EAEEwB,aAAa,GAAG,CAFlB;AAMA,QAAMG,eAAe,GAAGzB,SAAS,GAAG,CAAZ,GAAgB,CAAxC;AACAJ,EAAAA,YAAY,CAAC6B,eAAD,CAAZ,GAAgC3B,IAAI,CAAC,CAAD,CAApC;AACAF,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoC3B,IAAI,CAAC,CAAD,CAAxC;AACAF,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoCL,eAAe,GAAG,CAAlB,GAAsBE,aAA1D;AAEA1B,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoCL,eAAe,GAAG,CAAlB,GAAsBE,aAA1D;AACA1B,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoCL,eAAe,GAAG,CAAlB,GAAsBC,aAA1D;AACAzB,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoC3B,IAAI,CAAC,CAAD,CAAxC;AACD","sourcesContent":["import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nexport type EdgeIndices = {\n westIndices: number[];\n northIndices: number[];\n eastIndices: number[];\n southIndices: number[];\n};\n\n/**\n * Add skirt to existing mesh\n * @param {object} attributes - POSITION and TEXCOOD_0 attributes data\n * @param {any} triangles - indices array of the mesh geometry\n * @param skirtHeight - height of the skirt geometry\n * @param outsideIndices - edge indices from quantized mesh data\n * @returns - geometry data with added skirt\n */\nexport function addSkirt(attributes, triangles, skirtHeight: number, outsideIndices?: EdgeIndices) {\n const outsideEdges = outsideIndices\n ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value)\n : getOutsideEdgesFromTriangles(triangles);\n\n // 2 new vertices for each outside edge\n const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);\n const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);\n\n // 2 new triangles for each outside edge\n const newTriangles = new triangles.constructor(outsideEdges.length * 6);\n\n for (let i = 0; i < outsideEdges.length; i++) {\n const edge = outsideEdges[i];\n\n updateAttributesForNewEdge({\n edge,\n edgeIndex: i,\n attributes,\n skirtHeight,\n newPosition,\n newTexcoord0,\n newTriangles\n });\n }\n\n attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);\n attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);\n const resultTriangles =\n triangles instanceof Array\n ? triangles.concat(newTriangles)\n : concatenateTypedArrays(triangles, newTriangles);\n\n return {\n attributes,\n triangles: resultTriangles\n };\n}\n\n/**\n * Get geometry edges that located on a border of the mesh\n * @param {any} triangles - indices array of the mesh geometry\n * @returns {number[][]} - outside edges data\n */\nfunction getOutsideEdgesFromTriangles(triangles) {\n const edges: number[][] = [];\n for (let i = 0; i < triangles.length; i += 3) {\n edges.push([triangles[i], triangles[i + 1]]);\n edges.push([triangles[i + 1], triangles[i + 2]]);\n edges.push([triangles[i + 2], triangles[i]]);\n }\n\n edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));\n\n const outsideEdges: number[][] = [];\n let index = 1;\n while (index < edges.length) {\n if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {\n index += 2;\n } else {\n outsideEdges.push(edges[index - 1]);\n index++;\n }\n }\n return outsideEdges;\n}\n\n/**\n * Get geometry edges that located on a border of the mesh\n * @param {object} indices - edge indices from quantized mesh data\n * @param {TypedArray} position - position attribute geometry data\n * @returns {number[][]} - outside edges data\n */\nfunction getOutsideEdgesFromIndices(indices: EdgeIndices, position) {\n // Sort skirt indices to create adjacent triangles\n indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);\n // Reverse (b - a) to match triangle winding\n indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);\n indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);\n // Reverse (b - a) to match triangle winding\n indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);\n\n const edges: number[][] = [];\n for (const index in indices) {\n const indexGroup = indices[index];\n for (let i = 0; i < indexGroup.length - 1; i++) {\n edges.push([indexGroup[i], indexGroup[i + 1]]);\n }\n }\n return edges;\n}\n\n/**\n * Get geometry edges that located on a border of the mesh\n * @param {object} args\n * @param {number[]} args.edge - edge indices in geometry\n * @param {number} args.edgeIndex - edge index in outsideEdges array\n * @param {object} args.attributes - POSITION and TEXCOORD_0 attributes\n * @param {number} args.skirtHeight - height of the skirt geometry\n * @param {TypedArray} args.newPosition - POSITION array for skirt data\n * @param {TypedArray} args.newTexcoord0 - TEXCOORD_0 array for skirt data\n * @param {TypedArray | Array} args.newTriangles - trinagle indices array for skirt data\n * @returns {void}\n */\nfunction updateAttributesForNewEdge({\n edge,\n edgeIndex,\n attributes,\n skirtHeight,\n newPosition,\n newTexcoord0,\n newTriangles\n}) {\n const positionsLength = attributes.POSITION.value.length;\n const vertex1Offset = edgeIndex * 2;\n const vertex2Offset = edgeIndex * 2 + 1;\n\n // Define POSITION for new 1st vertex\n newPosition.set(\n attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3),\n vertex1Offset * 3\n );\n newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height\n\n // Define POSITION for new 2nd vertex\n newPosition.set(\n attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3),\n vertex2Offset * 3\n );\n newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height\n\n // Use same TEXCOORDS for skirt vertices\n newTexcoord0.set(\n attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2),\n vertex1Offset * 2\n );\n newTexcoord0.set(\n attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2),\n vertex2Offset * 2\n );\n\n // Define new triangles\n const triangle1Offset = edgeIndex * 2 * 3;\n newTriangles[triangle1Offset] = edge[0];\n newTriangles[triangle1Offset + 1] = edge[1];\n newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;\n\n newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;\n newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;\n newTriangles[triangle1Offset + 5] = edge[0];\n}\n"],"file":"skirt.js"}
|
|
@@ -1,95 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
23
|
-
const decode_quantized_mesh_1 = __importStar(require("./decode-quantized-mesh"));
|
|
24
|
-
const skirt_1 = require("./helpers/skirt");
|
|
1
|
+
import { getMeshBoundingBox } from '@loaders.gl/schema';
|
|
2
|
+
import decode, { DECODING_STEPS } from './decode-quantized-mesh';
|
|
3
|
+
import { addSkirt } from './helpers/skirt';
|
|
4
|
+
|
|
25
5
|
function getMeshAttributes(vertexData, header, bounds) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
const {
|
|
7
|
+
minHeight,
|
|
8
|
+
maxHeight
|
|
9
|
+
} = header;
|
|
10
|
+
const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
|
|
11
|
+
const xScale = maxX - minX;
|
|
12
|
+
const yScale = maxY - minY;
|
|
13
|
+
const zScale = maxHeight - minHeight;
|
|
14
|
+
const nCoords = vertexData.length / 3;
|
|
15
|
+
const positions = new Float32Array(nCoords * 3);
|
|
16
|
+
const texCoords = new Float32Array(nCoords * 2);
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < nCoords; i++) {
|
|
19
|
+
const x = vertexData[i] / 32767;
|
|
20
|
+
const y = vertexData[i + nCoords] / 32767;
|
|
21
|
+
const z = vertexData[i + nCoords * 2] / 32767;
|
|
22
|
+
positions[3 * i + 0] = x * xScale + minX;
|
|
23
|
+
positions[3 * i + 1] = y * yScale + minY;
|
|
24
|
+
positions[3 * i + 2] = z * zScale + minHeight;
|
|
25
|
+
texCoords[2 * i + 0] = x;
|
|
26
|
+
texCoords[2 * i + 1] = y;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
POSITION: {
|
|
31
|
+
value: positions,
|
|
32
|
+
size: 3
|
|
33
|
+
},
|
|
34
|
+
TEXCOORD_0: {
|
|
35
|
+
value: texCoords,
|
|
36
|
+
size: 2
|
|
46
37
|
}
|
|
47
|
-
|
|
48
|
-
POSITION: { value: positions, size: 3 },
|
|
49
|
-
TEXCOORD_0: { value: texCoords, size: 2 }
|
|
50
|
-
// TODO: Parse normals if they exist in the file
|
|
51
|
-
// NORMAL: {}, - optional, but creates the high poly look with lighting
|
|
52
|
-
};
|
|
38
|
+
};
|
|
53
39
|
}
|
|
40
|
+
|
|
54
41
|
function getTileMesh(arrayBuffer, options) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
42
|
+
if (!arrayBuffer) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
bounds
|
|
48
|
+
} = options;
|
|
49
|
+
const {
|
|
50
|
+
header,
|
|
51
|
+
vertexData,
|
|
52
|
+
triangleIndices: originalTriangleIndices,
|
|
53
|
+
westIndices,
|
|
54
|
+
northIndices,
|
|
55
|
+
eastIndices,
|
|
56
|
+
southIndices
|
|
57
|
+
} = decode(arrayBuffer, DECODING_STEPS.triangleIndices);
|
|
58
|
+
let triangleIndices = originalTriangleIndices;
|
|
59
|
+
let attributes = getMeshAttributes(vertexData, header, bounds);
|
|
60
|
+
const boundingBox = getMeshBoundingBox(attributes);
|
|
61
|
+
|
|
62
|
+
if (options.skirtHeight) {
|
|
63
|
+
const {
|
|
64
|
+
attributes: newAttributes,
|
|
65
|
+
triangles: newTriangles
|
|
66
|
+
} = addSkirt(attributes, triangleIndices, options.skirtHeight, {
|
|
67
|
+
westIndices,
|
|
68
|
+
northIndices,
|
|
69
|
+
eastIndices,
|
|
70
|
+
southIndices
|
|
71
|
+
});
|
|
72
|
+
attributes = newAttributes;
|
|
73
|
+
triangleIndices = newTriangles;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
loaderData: {
|
|
78
|
+
header: {}
|
|
79
|
+
},
|
|
80
|
+
header: {
|
|
81
|
+
vertexCount: triangleIndices.length,
|
|
82
|
+
boundingBox
|
|
83
|
+
},
|
|
84
|
+
mode: 4,
|
|
85
|
+
indices: {
|
|
86
|
+
value: triangleIndices,
|
|
87
|
+
size: 1
|
|
88
|
+
},
|
|
89
|
+
attributes
|
|
90
|
+
};
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
|
|
93
|
+
export default function loadQuantizedMesh(arrayBuffer, options) {
|
|
94
|
+
return getTileMesh(arrayBuffer, options['quantized-mesh']);
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
+
//# sourceMappingURL=parse-quantized-mesh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-quantized-mesh.ts"],"names":["getMeshBoundingBox","decode","DECODING_STEPS","addSkirt","getMeshAttributes","vertexData","header","bounds","minHeight","maxHeight","minX","minY","maxX","maxY","xScale","yScale","zScale","nCoords","length","positions","Float32Array","texCoords","i","x","y","z","POSITION","value","size","TEXCOORD_0","getTileMesh","arrayBuffer","options","triangleIndices","originalTriangleIndices","westIndices","northIndices","eastIndices","southIndices","attributes","boundingBox","skirtHeight","newAttributes","triangles","newTriangles","loaderData","vertexCount","mode","indices","loadQuantizedMesh"],"mappings":"AAAA,SAAQA,kBAAR,QAAiC,oBAAjC;AACA,OAAOC,MAAP,IAAgBC,cAAhB,QA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AAA,WADF;AAEEC,MAAAA,YAFF;AAGEC,MAAAA,WAHF;AAIEC,MAAAA;AAJF,KAJmE,CAArE;AAWAC,IAAAA,UAAU,GAAGG,aAAb;AACAT,IAAAA,eAAe,GAAGW,YAAlB;AACD;;AAED,SAAO;AAELC,IAAAA,UAAU,EAAE;AACVvC,MAAAA,MAAM,EAAE;AADE,KAFP;AAKLA,IAAAA,MAAM,EAAE;AAENwC,MAAAA,WAAW,EAAEb,eAAe,CAACf,MAFvB;AAGNsB,MAAAA;AAHM,KALH;AAULO,IAAAA,IAAI,EAAE,CAVD;AAWLC,IAAAA,OAAO,EAAE;AAACrB,MAAAA,KAAK,EAAEM,eAAR;AAAyBL,MAAAA,IAAI,EAAE;AAA/B,KAXJ;AAYLW,IAAAA;AAZK,GAAP;AAcD;;AAED,eAAe,SAASU,iBAAT,CAA2BlB,WAA3B,EAAwCC,OAAxC,EAAiD;AAC9D,SAAOF,WAAW,CAACC,WAAD,EAAcC,OAAO,CAAC,gBAAD,CAArB,CAAlB;AACD","sourcesContent":["import {getMeshBoundingBox} from '@loaders.gl/schema';\nimport decode, {DECODING_STEPS} from './decode-quantized-mesh';\nimport {addSkirt} from './helpers/skirt';\n\nfunction getMeshAttributes(vertexData, header, bounds) {\n const {minHeight, maxHeight} = header;\n const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];\n const xScale = maxX - minX;\n const yScale = maxY - minY;\n const zScale = maxHeight - minHeight;\n\n const nCoords = vertexData.length / 3;\n // vec3. x, y defined by bounds, z in meters\n const positions = new Float32Array(nCoords * 3);\n\n // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.\n const texCoords = new Float32Array(nCoords * 2);\n\n // Data is not interleaved; all u, then all v, then all heights\n for (let i = 0; i < nCoords; i++) {\n const x = vertexData[i] / 32767;\n const y = vertexData[i + nCoords] / 32767;\n const z = vertexData[i + nCoords * 2] / 32767;\n\n positions[3 * i + 0] = x * xScale + minX;\n positions[3 * i + 1] = y * yScale + minY;\n positions[3 * i + 2] = z * zScale + minHeight;\n\n texCoords[2 * i + 0] = x;\n texCoords[2 * i + 1] = y;\n }\n\n return {\n POSITION: {value: positions, size: 3},\n TEXCOORD_0: {value: texCoords, size: 2}\n // TODO: Parse normals if they exist in the file\n // NORMAL: {}, - optional, but creates the high poly look with lighting\n };\n}\n\nfunction getTileMesh(arrayBuffer, options) {\n if (!arrayBuffer) {\n return null;\n }\n const {bounds} = options;\n // Don't parse edge indices or format extensions\n const {\n header,\n vertexData,\n triangleIndices: originalTriangleIndices,\n westIndices,\n northIndices,\n eastIndices,\n southIndices\n } = decode(arrayBuffer, DECODING_STEPS.triangleIndices);\n let triangleIndices = originalTriangleIndices;\n let attributes = getMeshAttributes(vertexData, header, bounds);\n\n // Compute bounding box before adding skirt so that z values are not skewed\n // TODO: Find bounding box from header, instead of doing extra pass over\n // vertices.\n const boundingBox = getMeshBoundingBox(attributes);\n\n if (options.skirtHeight) {\n const {attributes: newAttributes, triangles: newTriangles} = addSkirt(\n attributes,\n triangleIndices,\n options.skirtHeight,\n {\n westIndices,\n northIndices,\n eastIndices,\n southIndices\n }\n );\n attributes = newAttributes;\n triangleIndices = newTriangles;\n }\n\n return {\n // Data return by this loader implementation\n loaderData: {\n header: {}\n },\n header: {\n // @ts-ignore\n vertexCount: triangleIndices.length,\n boundingBox\n },\n mode: 4, // TRIANGLES\n indices: {value: triangleIndices, size: 1},\n attributes\n };\n}\n\nexport default function loadQuantizedMesh(arrayBuffer, options) {\n return getTileMesh(arrayBuffer, options['quantized-mesh']);\n}\n"],"file":"parse-quantized-mesh.js"}
|