@loaders.gl/terrain 3.1.4 → 3.1.8

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/dist.min.js CHANGED
@@ -323,12 +323,12 @@
323
323
  }
324
324
  edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
325
325
  const outsideEdges = [];
326
- let index = 1;
326
+ let index = 0;
327
327
  while (index < edges.length) {
328
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
328
+ if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
329
329
  index += 2;
330
330
  } else {
331
- outsideEdges.push(edges[index - 1]);
331
+ outsideEdges.push(edges[index]);
332
332
  index++;
333
333
  }
334
334
  }
@@ -52,13 +52,15 @@ function getOutsideEdgesFromTriangles(triangles) {
52
52
  return Math.min.apply(Math, (0, _toConsumableArray2.default)(a)) - Math.min.apply(Math, (0, _toConsumableArray2.default)(b)) || Math.max.apply(Math, (0, _toConsumableArray2.default)(a)) - Math.max.apply(Math, (0, _toConsumableArray2.default)(b));
53
53
  });
54
54
  var outsideEdges = [];
55
- var index = 1;
55
+ var index = 0;
56
56
 
57
57
  while (index < edges.length) {
58
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
58
+ var _edges, _edges2;
59
+
60
+ if (edges[index][0] === ((_edges = edges[index + 1]) === null || _edges === void 0 ? void 0 : _edges[1]) && edges[index][1] === ((_edges2 = edges[index + 1]) === null || _edges2 === void 0 ? void 0 : _edges2[0])) {
59
61
  index += 2;
60
62
  } else {
61
- outsideEdges.push(edges[index - 1]);
63
+ outsideEdges.push(edges[index]);
62
64
  index++;
63
65
  }
64
66
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/helpers/skirt.ts"],"names":["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;;AAiBO,SAASA,QAAT,CAAkBC,UAAlB,EAA8BC,SAA9B,EAAyCC,WAAzC,EAA8DC,cAA9D,EAA4F;AACjG,MAAMC,YAAY,GAAGD,cAAc,GAC/BE,0BAA0B,CAACF,cAAD,EAAiBH,UAAU,CAACM,QAAX,CAAoBC,KAArC,CADK,GAE/BC,4BAA4B,CAACP,SAAD,CAFhC;AAKA,MAAMQ,WAAW,GAAG,IAAIT,UAAU,CAACM,QAAX,CAAoBC,KAApB,CAA0BG,WAA9B,CAA0CN,YAAY,CAACO,MAAb,GAAsB,CAAhE,CAApB;AACA,MAAMC,YAAY,GAAG,IAAIZ,UAAU,CAACa,UAAX,CAAsBN,KAAtB,CAA4BG,WAAhC,CAA4CN,YAAY,CAACO,MAAb,GAAsB,CAAlE,CAArB;AAGA,MAAMG,YAAY,GAAG,IAAIb,SAAS,CAACS,WAAd,CAA0BN,YAAY,CAACO,MAAb,GAAsB,CAAhD,CAArB;;AAEA,OAAK,IAAII,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGX,YAAY,CAACO,MAAjC,EAAyCI,CAAC,EAA1C,EAA8C;AAC5C,QAAMC,IAAI,GAAGZ,YAAY,CAACW,CAAD,CAAzB;AAEAE,IAAAA,0BAA0B,CAAC;AACzBD,MAAAA,IAAI,EAAJA,IADyB;AAEzBE,MAAAA,SAAS,EAAEH,CAFc;AAGzBf,MAAAA,UAAU,EAAVA,UAHyB;AAIzBE,MAAAA,WAAW,EAAXA,WAJyB;AAKzBO,MAAAA,WAAW,EAAXA,WALyB;AAMzBG,MAAAA,YAAY,EAAZA,YANyB;AAO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;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
+ {"version":3,"sources":["../../../../src/lib/helpers/skirt.ts"],"names":["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;;AAiBO,SAASA,QAAT,CAAkBC,UAAlB,EAA8BC,SAA9B,EAAyCC,WAAzC,EAA8DC,cAA9D,EAA4F;AACjG,MAAMC,YAAY,GAAGD,cAAc,GAC/BE,0BAA0B,CAACF,cAAD,EAAiBH,UAAU,CAACM,QAAX,CAAoBC,KAArC,CADK,GAE/BC,4BAA4B,CAACP,SAAD,CAFhC;AAKA,MAAMQ,WAAW,GAAG,IAAIT,UAAU,CAACM,QAAX,CAAoBC,KAApB,CAA0BG,WAA9B,CAA0CN,YAAY,CAACO,MAAb,GAAsB,CAAhE,CAApB;AACA,MAAMC,YAAY,GAAG,IAAIZ,UAAU,CAACa,UAAX,CAAsBN,KAAtB,CAA4BG,WAAhC,CAA4CN,YAAY,CAACO,MAAb,GAAsB,CAAlE,CAArB;AAGA,MAAMG,YAAY,GAAG,IAAIb,SAAS,CAACS,WAAd,CAA0BN,YAAY,CAACO,MAAb,GAAsB,CAAhD,CAArB;;AAEA,OAAK,IAAII,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGX,YAAY,CAACO,MAAjC,EAAyCI,CAAC,EAA1C,EAA8C;AAC5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uB,aAAa,GAAG,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,MAAMG,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 = 0;\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]);\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"}
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VERSION = void 0;
7
- var VERSION = typeof "3.1.4" !== 'undefined' ? "3.1.4" : 'latest';
7
+ var VERSION = typeof "3.1.8" !== 'undefined' ? "3.1.8" : 'latest';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
@@ -38,13 +38,15 @@ function getOutsideEdgesFromTriangles(triangles) {
38
38
 
39
39
  edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
40
40
  const outsideEdges = [];
41
- let index = 1;
41
+ let index = 0;
42
42
 
43
43
  while (index < edges.length) {
44
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
44
+ var _edges, _edges2;
45
+
46
+ if (edges[index][0] === ((_edges = edges[index + 1]) === null || _edges === void 0 ? void 0 : _edges[1]) && edges[index][1] === ((_edges2 = edges[index + 1]) === null || _edges2 === void 0 ? void 0 : _edges2[0])) {
45
47
  index += 2;
46
48
  } else {
47
- outsideEdges.push(edges[index - 1]);
49
+ outsideEdges.push(edges[index]);
48
50
  index++;
49
51
  }
50
52
  }
@@ -1 +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,CAA4BG,WAAhC,CAA4CN,YAAY,CAACO,MAAb,GAAsB,CAAlE,CAArB;AAGA,QAAMG,YAAY,GAAG,IAAIb,SAAS,CAACS,WAAd,CAA0BN,YAAY,CAACO,MAAb,GAAsB,CAAhD,CAArB;;AAEA,OAAK,IAAII,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGX,YAAY,CAACO,MAAjC,EAAyCI,CAAC,EAA1C,EAA8C;AAC5C,UAAMC,IAAI,GAAGZ,YAAY,CAACW,CAAD,CAAzB;AAEAE,IAAAA,0BAA0B,CAAC;AACzBD,MAAAA,IADyB;AAEzBE,MAAAA,SAAS,EAAEH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,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
+ {"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,CAA4BG,WAAhC,CAA4CN,YAAY,CAACO,MAAb,GAAsB,CAAlE,CAArB;AAGA,QAAMG,YAAY,GAAG,IAAIb,SAAS,CAACS,WAAd,CAA0BN,YAAY,CAACO,MAAb,GAAsB,CAAhD,CAArB;;AAEA,OAAK,IAAII,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGX,YAAY,CAACO,MAAjC,EAAyCI,CAAC,EAA1C,EAA8C;AAC5C,UAAMC,IAAI,GAAGZ,YAAY,CAACW,CAAD,CAAzB;AAEAE,IAA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J,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 = 0;\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]);\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,2 +1,2 @@
1
- export const VERSION = typeof "3.1.4" !== 'undefined' ? "3.1.4" : 'latest';
1
+ export const VERSION = typeof "3.1.8" !== 'undefined' ? "3.1.8" : 'latest';
2
2
  //# sourceMappingURL=version.js.map
@@ -56,13 +56,13 @@ function getOutsideEdgesFromTriangles(triangles) {
56
56
  }
57
57
  edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
58
58
  const outsideEdges = [];
59
- let index = 1;
59
+ let index = 0;
60
60
  while (index < edges.length) {
61
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
61
+ if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
62
62
  index += 2;
63
63
  }
64
64
  else {
65
- outsideEdges.push(edges[index - 1]);
65
+ outsideEdges.push(edges[index]);
66
66
  index++;
67
67
  }
68
68
  }
@@ -434,12 +434,12 @@
434
434
  }
435
435
  edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
436
436
  const outsideEdges = [];
437
- let index = 1;
437
+ let index = 0;
438
438
  while (index < edges.length) {
439
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
439
+ if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
440
440
  index += 2;
441
441
  } else {
442
- outsideEdges.push(edges[index - 1]);
442
+ outsideEdges.push(edges[index]);
443
443
  index++;
444
444
  }
445
445
  }
@@ -1161,7 +1161,7 @@
1161
1161
  }
1162
1162
 
1163
1163
  // src/lib/utils/version.ts
1164
- var VERSION = true ? "3.1.4" : "latest";
1164
+ var VERSION = true ? "3.1.8" : "latest";
1165
1165
 
1166
1166
  // src/terrain-loader.ts
1167
1167
  var TerrainLoader = {
@@ -434,12 +434,12 @@
434
434
  }
435
435
  edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
436
436
  const outsideEdges = [];
437
- let index = 1;
437
+ let index = 0;
438
438
  while (index < edges.length) {
439
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
439
+ if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
440
440
  index += 2;
441
441
  } else {
442
- outsideEdges.push(edges[index - 1]);
442
+ outsideEdges.push(edges[index]);
443
443
  index++;
444
444
  }
445
445
  }
@@ -1161,7 +1161,7 @@
1161
1161
  }
1162
1162
 
1163
1163
  // src/lib/utils/version.ts
1164
- var VERSION = true ? "3.1.4" : "latest";
1164
+ var VERSION = true ? "3.1.8" : "latest";
1165
1165
 
1166
1166
  // src/terrain-loader.ts
1167
1167
  var TerrainLoader = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/terrain",
3
- "version": "3.1.4",
3
+ "version": "3.1.8",
4
4
  "description": "Framework-independent loader for terrain raster formats",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -35,9 +35,9 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@babel/runtime": "^7.3.1",
38
- "@loaders.gl/loader-utils": "3.1.4",
39
- "@loaders.gl/schema": "3.1.4",
38
+ "@loaders.gl/loader-utils": "3.1.8",
39
+ "@loaders.gl/schema": "3.1.8",
40
40
  "@mapbox/martini": "^0.2.0"
41
41
  },
42
- "gitHead": "4d27d3ac6023e53b562dcad83b9254b198e81ee5"
42
+ "gitHead": "0ef07b4e9fc20f5a882224cf241c6fd1bad898d8"
43
43
  }
@@ -70,12 +70,12 @@ function getOutsideEdgesFromTriangles(triangles) {
70
70
  edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
71
71
 
72
72
  const outsideEdges: number[][] = [];
73
- let index = 1;
73
+ let index = 0;
74
74
  while (index < edges.length) {
75
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
75
+ if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
76
76
  index += 2;
77
77
  } else {
78
- outsideEdges.push(edges[index - 1]);
78
+ outsideEdges.push(edges[index]);
79
79
  index++;
80
80
  }
81
81
  }