Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@loaders.gl/terrain

Package Overview
Dependencies
Maintainers
9
Versions
270
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/terrain - npm Package Compare versions

Comparing version 3.4.14 to 3.4.15

2

dist/es5/bundle.js
"use strict";
var moduleExports = require('./index');
const moduleExports = require('./index');
globalThis.loaders = globalThis.loaders || {};
module.exports = Object.assign(globalThis.loaders, moduleExports);
//# sourceMappingURL=bundle.js.map

@@ -10,3 +10,3 @@ "use strict";

enumerable: true,
get: function get() {
get: function () {
return _quantizedMeshLoader.QuantizedMeshLoader;

@@ -18,3 +18,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _terrainLoader.TerrainLoader;

@@ -24,5 +24,2 @@ }

exports._typecheckTerrainLoader = exports._typecheckQuantizedMeshLoader = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _parseQuantizedMesh = _interopRequireDefault(require("./lib/parse-quantized-mesh"));

@@ -32,33 +29,17 @@ var _parseTerrain = _interopRequireDefault(require("./lib/parse-terrain"));

var _quantizedMeshLoader = require("./quantized-mesh-loader");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TerrainLoader = _objectSpread(_objectSpread({}, _terrainLoader.TerrainLoader), {}, {
const TerrainLoader = {
..._terrainLoader.TerrainLoader,
parse: _parseTerrain.default
});
};
exports.TerrainLoader = TerrainLoader;
var _typecheckTerrainLoader = TerrainLoader;
const _typecheckTerrainLoader = TerrainLoader;
exports._typecheckTerrainLoader = _typecheckTerrainLoader;
var QuantizedMeshLoader = _objectSpread(_objectSpread({}, _quantizedMeshLoader.QuantizedMeshLoader), {}, {
const QuantizedMeshLoader = {
..._quantizedMeshLoader.QuantizedMeshLoader,
parseSync: _parseQuantizedMesh.default,
parse: function () {
var _parse = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options) {
return _regenerator.default.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", (0, _parseQuantizedMesh.default)(arrayBuffer, options));
case 1:
case "end":
return _context.stop();
}
}, _callee);
}));
function parse(_x, _x2) {
return _parse.apply(this, arguments);
}
return parse;
}()
});
parse: async (arrayBuffer, options) => (0, _parseQuantizedMesh.default)(arrayBuffer, options)
};
exports.QuantizedMeshLoader = QuantizedMeshLoader;
var _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
const _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
exports._typecheckQuantizedMeshLoader = _typecheckQuantizedMeshLoader;
//# sourceMappingURL=index.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -9,7 +8,3 @@ value: true

exports.default = decode;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
var QUANTIZED_MESH_HEADER = new Map([['centerX', Float64Array.BYTES_PER_ELEMENT], ['centerY', Float64Array.BYTES_PER_ELEMENT], ['centerZ', Float64Array.BYTES_PER_ELEMENT], ['minHeight', Float32Array.BYTES_PER_ELEMENT], ['maxHeight', Float32Array.BYTES_PER_ELEMENT], ['boundingSphereCenterX', Float64Array.BYTES_PER_ELEMENT], ['boundingSphereCenterY', Float64Array.BYTES_PER_ELEMENT], ['boundingSphereCenterZ', Float64Array.BYTES_PER_ELEMENT], ['boundingSphereRadius', Float64Array.BYTES_PER_ELEMENT], ['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT], ['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT], ['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]]);
const QUANTIZED_MESH_HEADER = new Map([['centerX', Float64Array.BYTES_PER_ELEMENT], ['centerY', Float64Array.BYTES_PER_ELEMENT], ['centerZ', Float64Array.BYTES_PER_ELEMENT], ['minHeight', Float32Array.BYTES_PER_ELEMENT], ['maxHeight', Float32Array.BYTES_PER_ELEMENT], ['boundingSphereCenterX', Float64Array.BYTES_PER_ELEMENT], ['boundingSphereCenterY', Float64Array.BYTES_PER_ELEMENT], ['boundingSphereCenterZ', Float64Array.BYTES_PER_ELEMENT], ['boundingSphereRadius', Float64Array.BYTES_PER_ELEMENT], ['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT], ['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT], ['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]]);
function decodeZigZag(value) {

@@ -19,22 +14,11 @@ return value >> 1 ^ -(value & 1);

function decodeHeader(dataView) {
var position = 0;
var header = {};
var _iterator = _createForOfIteratorHelper(QUANTIZED_MESH_HEADER),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
key = _step$value[0],
bytesCount = _step$value[1];
var getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
header[key] = getter.call(dataView, position, true);
position += bytesCount;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
let position = 0;
const header = {};
for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {
const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;
header[key] = getter.call(dataView, position, true);
position += bytesCount;
}
return {
header: header,
header,
headerEndPosition: position

@@ -44,16 +28,16 @@ };

function decodeVertexData(dataView, headerEndPosition) {
var position = headerEndPosition;
var elementsPerVertex = 3;
var vertexCount = dataView.getUint32(position, true);
var vertexData = new Uint16Array(vertexCount * elementsPerVertex);
let position = headerEndPosition;
const elementsPerVertex = 3;
const vertexCount = dataView.getUint32(position, true);
const vertexData = new Uint16Array(vertexCount * elementsPerVertex);
position += Uint32Array.BYTES_PER_ELEMENT;
var bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
var elementArrayLength = vertexCount * bytesPerArrayElement;
var uArrayStartPosition = position;
var vArrayStartPosition = uArrayStartPosition + elementArrayLength;
var heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
var u = 0;
var v = 0;
var height = 0;
for (var i = 0; i < vertexCount; i++) {
const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;
const elementArrayLength = vertexCount * bytesPerArrayElement;
const uArrayStartPosition = position;
const vArrayStartPosition = uArrayStartPosition + elementArrayLength;
const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;
let u = 0;
let v = 0;
let height = 0;
for (let i = 0; i < vertexCount; i++) {
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));

@@ -68,3 +52,3 @@ v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));

return {
vertexData: vertexData,
vertexData,
vertexDataEndPosition: position

@@ -74,4 +58,4 @@ };

function decodeIndex(buffer, position, indicesCount, bytesPerIndex) {
var encoded = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
var indices;
let encoded = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
let indices;
if (bytesPerIndex === 2) {

@@ -85,5 +69,5 @@ indices = new Uint16Array(buffer, position, indicesCount);

}
var highest = 0;
for (var i = 0; i < indices.length; ++i) {
var code = indices[i];
let highest = 0;
for (let i = 0; i < indices.length; ++i) {
const code = indices[i];
indices[i] = highest - code;

@@ -97,46 +81,46 @@ if (code === 0) {

function decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {
var position = vertexDataEndPosition;
var elementsPerVertex = 3;
var vertexCount = vertexData.length / elementsPerVertex;
var bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
let position = vertexDataEndPosition;
const elementsPerVertex = 3;
const vertexCount = vertexData.length / elementsPerVertex;
const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
if (position % bytesPerIndex !== 0) {
position += bytesPerIndex - position % bytesPerIndex;
}
var triangleCount = dataView.getUint32(position, true);
const triangleCount = dataView.getUint32(position, true);
position += Uint32Array.BYTES_PER_ELEMENT;
var triangleIndicesCount = triangleCount * 3;
var triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
const triangleIndicesCount = triangleCount * 3;
const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex);
position += triangleIndicesCount * bytesPerIndex;
return {
triangleIndicesEndPosition: position,
triangleIndices: triangleIndices
triangleIndices
};
}
function decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {
var position = triangleIndicesEndPosition;
var elementsPerVertex = 3;
var vertexCount = vertexData.length / elementsPerVertex;
var bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
var westVertexCount = dataView.getUint32(position, true);
let position = triangleIndicesEndPosition;
const elementsPerVertex = 3;
const vertexCount = vertexData.length / elementsPerVertex;
const bytesPerIndex = vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;
const westVertexCount = dataView.getUint32(position, true);
position += Uint32Array.BYTES_PER_ELEMENT;
var westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);
position += westVertexCount * bytesPerIndex;
var southVertexCount = dataView.getUint32(position, true);
const southVertexCount = dataView.getUint32(position, true);
position += Uint32Array.BYTES_PER_ELEMENT;
var southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false);
position += southVertexCount * bytesPerIndex;
var eastVertexCount = dataView.getUint32(position, true);
const eastVertexCount = dataView.getUint32(position, true);
position += Uint32Array.BYTES_PER_ELEMENT;
var eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);
position += eastVertexCount * bytesPerIndex;
var northVertexCount = dataView.getUint32(position, true);
const northVertexCount = dataView.getUint32(position, true);
position += Uint32Array.BYTES_PER_ELEMENT;
var northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false);
position += northVertexCount * bytesPerIndex;
return {
edgeIndicesEndPosition: position,
westIndices: westIndices,
southIndices: southIndices,
eastIndices: eastIndices,
northIndices: northIndices
westIndices,
southIndices,
eastIndices,
northIndices
};

@@ -151,16 +135,16 @@ }

function decodeExtensions(dataView, indicesEndPosition) {
var extensions = {};
const extensions = {};
if (dataView.byteLength <= indicesEndPosition) {
return {
extensions: extensions,
extensions,
extensionsEndPosition: indicesEndPosition
};
}
var position = indicesEndPosition;
let position = indicesEndPosition;
while (position < dataView.byteLength) {
var extensionId = dataView.getUint8(position, true);
const extensionId = dataView.getUint8(position, true);
position += Uint8Array.BYTES_PER_ELEMENT;
var extensionLength = dataView.getUint32(position, true);
const extensionLength = dataView.getUint32(position, true);
position += Uint32Array.BYTES_PER_ELEMENT;
var extensionView = new DataView(dataView.buffer, position, extensionLength);
const extensionView = new DataView(dataView.buffer, position, extensionLength);
switch (extensionId) {

@@ -183,7 +167,7 @@ case 1:

return {
extensions: extensions,
extensions,
extensionsEndPosition: position
};
}
var DECODING_STEPS = {
const DECODING_STEPS = {
header: 0,

@@ -196,65 +180,70 @@ vertices: 1,

exports.DECODING_STEPS = DECODING_STEPS;
var DEFAULT_OPTIONS = {
const DEFAULT_OPTIONS = {
maxDecodingStep: DECODING_STEPS.extensions
};
function decode(data, userOptions) {
var options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
var view = new DataView(data);
var _decodeHeader = decodeHeader(view),
header = _decodeHeader.header,
headerEndPosition = _decodeHeader.headerEndPosition;
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
const view = new DataView(data);
const {
header,
headerEndPosition
} = decodeHeader(view);
if (options.maxDecodingStep < DECODING_STEPS.vertices) {
return {
header: header
header
};
}
var _decodeVertexData = decodeVertexData(view, headerEndPosition),
vertexData = _decodeVertexData.vertexData,
vertexDataEndPosition = _decodeVertexData.vertexDataEndPosition;
const {
vertexData,
vertexDataEndPosition
} = decodeVertexData(view, headerEndPosition);
if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {
return {
header: header,
vertexData: vertexData
header,
vertexData
};
}
var _decodeTriangleIndice = decodeTriangleIndices(view, vertexData, vertexDataEndPosition),
triangleIndices = _decodeTriangleIndice.triangleIndices,
triangleIndicesEndPosition = _decodeTriangleIndice.triangleIndicesEndPosition;
const {
triangleIndices,
triangleIndicesEndPosition
} = decodeTriangleIndices(view, vertexData, vertexDataEndPosition);
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {
return {
header: header,
vertexData: vertexData,
triangleIndices: triangleIndices
header,
vertexData,
triangleIndices
};
}
var _decodeEdgeIndices = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition),
westIndices = _decodeEdgeIndices.westIndices,
southIndices = _decodeEdgeIndices.southIndices,
eastIndices = _decodeEdgeIndices.eastIndices,
northIndices = _decodeEdgeIndices.northIndices,
edgeIndicesEndPosition = _decodeEdgeIndices.edgeIndicesEndPosition;
const {
westIndices,
southIndices,
eastIndices,
northIndices,
edgeIndicesEndPosition
} = decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);
if (options.maxDecodingStep < DECODING_STEPS.extensions) {
return {
header: header,
vertexData: vertexData,
triangleIndices: triangleIndices,
westIndices: westIndices,
northIndices: northIndices,
eastIndices: eastIndices,
southIndices: southIndices
header,
vertexData,
triangleIndices,
westIndices,
northIndices,
eastIndices,
southIndices
};
}
var _decodeExtensions = decodeExtensions(view, edgeIndicesEndPosition),
extensions = _decodeExtensions.extensions;
const {
extensions
} = decodeExtensions(view, edgeIndicesEndPosition);
return {
header: header,
vertexData: vertexData,
triangleIndices: triangleIndices,
westIndices: westIndices,
northIndices: northIndices,
eastIndices: eastIndices,
southIndices: southIndices,
extensions: extensions
header,
vertexData,
triangleIndices,
westIndices,
northIndices,
eastIndices,
southIndices,
extensions
};
}
//# sourceMappingURL=decode-quantized-mesh.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -8,8 +7,5 @@ value: true

exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var Delatin = function () {
function Delatin(data, width) {
var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : width;
(0, _classCallCheck2.default)(this, Delatin);
class Delatin {
constructor(data, width) {
let height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : width;
this.data = data;

@@ -29,366 +25,324 @@ this.width = width;

this._rmsSum = 0;
var x1 = width - 1;
var y1 = height - 1;
var p0 = this._addPoint(0, 0);
var p1 = this._addPoint(x1, 0);
var p2 = this._addPoint(0, y1);
var p3 = this._addPoint(x1, y1);
var t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
const x1 = width - 1;
const y1 = height - 1;
const p0 = this._addPoint(0, 0);
const p1 = this._addPoint(x1, 0);
const p2 = this._addPoint(0, y1);
const p3 = this._addPoint(x1, y1);
const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
this._addTriangle(p0, p3, p1, t0, -1, -1);
this._flush();
}
(0, _createClass2.default)(Delatin, [{
key: "run",
value: function run() {
var maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
while (this.getMaxError() > maxError) {
this.refine();
}
run() {
let maxError = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
while (this.getMaxError() > maxError) {
this.refine();
}
}, {
key: "refine",
value: function refine() {
this._step();
this._flush();
}
refine() {
this._step();
this._flush();
}
getMaxError() {
return this._errors[0];
}
getRMSD() {
return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
}
heightAt(x, y) {
return this.data[this.width * y + x];
}
_flush() {
const coords = this.coords;
for (let i = 0; i < this._pendingLen; i++) {
const t = this._pending[i];
const a = 2 * this.triangles[t * 3 + 0];
const b = 2 * this.triangles[t * 3 + 1];
const c = 2 * this.triangles[t * 3 + 2];
this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
}
}, {
key: "getMaxError",
value: function getMaxError() {
return this._errors[0];
}
}, {
key: "getRMSD",
value: function getRMSD() {
return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
}
}, {
key: "heightAt",
value: function heightAt(x, y) {
return this.data[this.width * y + x];
}
}, {
key: "_flush",
value: function _flush() {
var coords = this.coords;
for (var i = 0; i < this._pendingLen; i++) {
var t = this._pending[i];
var a = 2 * this.triangles[t * 3 + 0];
var b = 2 * this.triangles[t * 3 + 1];
var c = 2 * this.triangles[t * 3 + 2];
this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
this._pendingLen = 0;
}
_findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
const minX = Math.min(p0x, p1x, p2x);
const minY = Math.min(p0y, p1y, p2y);
const maxX = Math.max(p0x, p1x, p2x);
const maxY = Math.max(p0y, p1y, p2y);
let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
const a01 = p1y - p0y;
const b01 = p0x - p1x;
const a12 = p2y - p1y;
const b12 = p1x - p2x;
const a20 = p0y - p2y;
const b20 = p2x - p0x;
const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
const z0 = this.heightAt(p0x, p0y) / a;
const z1 = this.heightAt(p1x, p1y) / a;
const z2 = this.heightAt(p2x, p2y) / a;
let maxError = 0;
let mx = 0;
let my = 0;
let rms = 0;
for (let y = minY; y <= maxY; y++) {
let dx = 0;
if (w00 < 0 && a12 !== 0) {
dx = Math.max(dx, Math.floor(-w00 / a12));
}
this._pendingLen = 0;
}
}, {
key: "_findCandidate",
value: function _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
var minX = Math.min(p0x, p1x, p2x);
var minY = Math.min(p0y, p1y, p2y);
var maxX = Math.max(p0x, p1x, p2x);
var maxY = Math.max(p0y, p1y, p2y);
var w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
var w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
var w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
var a01 = p1y - p0y;
var b01 = p0x - p1x;
var a12 = p2y - p1y;
var b12 = p1x - p2x;
var a20 = p0y - p2y;
var b20 = p2x - p0x;
var a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
var z0 = this.heightAt(p0x, p0y) / a;
var z1 = this.heightAt(p1x, p1y) / a;
var z2 = this.heightAt(p2x, p2y) / a;
var maxError = 0;
var mx = 0;
var my = 0;
var rms = 0;
for (var y = minY; y <= maxY; y++) {
var dx = 0;
if (w00 < 0 && a12 !== 0) {
dx = Math.max(dx, Math.floor(-w00 / a12));
}
if (w01 < 0 && a20 !== 0) {
dx = Math.max(dx, Math.floor(-w01 / a20));
}
if (w02 < 0 && a01 !== 0) {
dx = Math.max(dx, Math.floor(-w02 / a01));
}
var w0 = w00 + a12 * dx;
var w1 = w01 + a20 * dx;
var w2 = w02 + a01 * dx;
var wasInside = false;
for (var x = minX + dx; x <= maxX; x++) {
if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
wasInside = true;
var z = z0 * w0 + z1 * w1 + z2 * w2;
var dz = Math.abs(z - this.heightAt(x, y));
rms += dz * dz;
if (dz > maxError) {
maxError = dz;
mx = x;
my = y;
}
} else if (wasInside) {
break;
if (w01 < 0 && a20 !== 0) {
dx = Math.max(dx, Math.floor(-w01 / a20));
}
if (w02 < 0 && a01 !== 0) {
dx = Math.max(dx, Math.floor(-w02 / a01));
}
let w0 = w00 + a12 * dx;
let w1 = w01 + a20 * dx;
let w2 = w02 + a01 * dx;
let wasInside = false;
for (let x = minX + dx; x <= maxX; x++) {
if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
wasInside = true;
const z = z0 * w0 + z1 * w1 + z2 * w2;
const dz = Math.abs(z - this.heightAt(x, y));
rms += dz * dz;
if (dz > maxError) {
maxError = dz;
mx = x;
my = y;
}
w0 += a12;
w1 += a20;
w2 += a01;
} else if (wasInside) {
break;
}
w00 += b12;
w01 += b20;
w02 += b01;
w0 += a12;
w1 += a20;
w2 += a01;
}
if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
maxError = 0;
}
this._candidates[2 * t] = mx;
this._candidates[2 * t + 1] = my;
this._rms[t] = rms;
this._queuePush(t, maxError, rms);
w00 += b12;
w01 += b20;
w02 += b01;
}
}, {
key: "_step",
value: function _step() {
var t = this._queuePop();
var e0 = t * 3 + 0;
var e1 = t * 3 + 1;
var e2 = t * 3 + 2;
var p0 = this.triangles[e0];
var p1 = this.triangles[e1];
var p2 = this.triangles[e2];
var ax = this.coords[2 * p0];
var ay = this.coords[2 * p0 + 1];
var bx = this.coords[2 * p1];
var by = this.coords[2 * p1 + 1];
var cx = this.coords[2 * p2];
var cy = this.coords[2 * p2 + 1];
var px = this._candidates[2 * t];
var py = this._candidates[2 * t + 1];
var pn = this._addPoint(px, py);
if (orient(ax, ay, bx, by, px, py) === 0) {
this._handleCollinear(pn, e0);
} else if (orient(bx, by, cx, cy, px, py) === 0) {
this._handleCollinear(pn, e1);
} else if (orient(cx, cy, ax, ay, px, py) === 0) {
this._handleCollinear(pn, e2);
} else {
var h0 = this._halfedges[e0];
var h1 = this._halfedges[e1];
var h2 = this._halfedges[e2];
var t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
var t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
var t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
this._legalize(t0);
this._legalize(t1);
this._legalize(t2);
}
if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
maxError = 0;
}
}, {
key: "_addPoint",
value: function _addPoint(x, y) {
var i = this.coords.length >> 1;
this.coords.push(x, y);
return i;
}
}, {
key: "_addTriangle",
value: function _addTriangle(a, b, c, ab, bc, ca) {
var e = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : this.triangles.length;
var t = e / 3;
this.triangles[e + 0] = a;
this.triangles[e + 1] = b;
this.triangles[e + 2] = c;
this._halfedges[e + 0] = ab;
this._halfedges[e + 1] = bc;
this._halfedges[e + 2] = ca;
if (ab >= 0) {
this._halfedges[ab] = e + 0;
}
if (bc >= 0) {
this._halfedges[bc] = e + 1;
}
if (ca >= 0) {
this._halfedges[ca] = e + 2;
}
this._candidates[2 * t + 0] = 0;
this._candidates[2 * t + 1] = 0;
this._queueIndices[t] = -1;
this._rms[t] = 0;
this._pending[this._pendingLen++] = t;
return e;
}
}, {
key: "_legalize",
value: function _legalize(a) {
var b = this._halfedges[a];
if (b < 0) {
return;
}
var a0 = a - a % 3;
var b0 = b - b % 3;
var al = a0 + (a + 1) % 3;
var ar = a0 + (a + 2) % 3;
var bl = b0 + (b + 2) % 3;
var br = b0 + (b + 1) % 3;
var p0 = this.triangles[ar];
var pr = this.triangles[a];
var pl = this.triangles[al];
var p1 = this.triangles[bl];
var coords = this.coords;
if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
return;
}
var hal = this._halfedges[al];
var har = this._halfedges[ar];
var hbl = this._halfedges[bl];
var hbr = this._halfedges[br];
this._queueRemove(a0 / 3);
this._queueRemove(b0 / 3);
var t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
var t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
this._legalize(t0 + 1);
this._legalize(t1 + 2);
}
}, {
key: "_handleCollinear",
value: function _handleCollinear(pn, a) {
var a0 = a - a % 3;
var al = a0 + (a + 1) % 3;
var ar = a0 + (a + 2) % 3;
var p0 = this.triangles[ar];
var pr = this.triangles[a];
var pl = this.triangles[al];
var hal = this._halfedges[al];
var har = this._halfedges[ar];
var b = this._halfedges[a];
if (b < 0) {
var _t = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
var _t2 = this._addTriangle(p0, pn, pl, _t, -1, hal);
this._legalize(_t + 1);
this._legalize(_t2 + 2);
return;
}
var b0 = b - b % 3;
var bl = b0 + (b + 2) % 3;
var br = b0 + (b + 1) % 3;
var p1 = this.triangles[bl];
var hbl = this._halfedges[bl];
var hbr = this._halfedges[br];
this._queueRemove(b0 / 3);
var t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
var t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
var t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
var t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
this._candidates[2 * t] = mx;
this._candidates[2 * t + 1] = my;
this._rms[t] = rms;
this._queuePush(t, maxError, rms);
}
_step() {
const t = this._queuePop();
const e0 = t * 3 + 0;
const e1 = t * 3 + 1;
const e2 = t * 3 + 2;
const p0 = this.triangles[e0];
const p1 = this.triangles[e1];
const p2 = this.triangles[e2];
const ax = this.coords[2 * p0];
const ay = this.coords[2 * p0 + 1];
const bx = this.coords[2 * p1];
const by = this.coords[2 * p1 + 1];
const cx = this.coords[2 * p2];
const cy = this.coords[2 * p2 + 1];
const px = this._candidates[2 * t];
const py = this._candidates[2 * t + 1];
const pn = this._addPoint(px, py);
if (orient(ax, ay, bx, by, px, py) === 0) {
this._handleCollinear(pn, e0);
} else if (orient(bx, by, cx, cy, px, py) === 0) {
this._handleCollinear(pn, e1);
} else if (orient(cx, cy, ax, ay, px, py) === 0) {
this._handleCollinear(pn, e2);
} else {
const h0 = this._halfedges[e0];
const h1 = this._halfedges[e1];
const h2 = this._halfedges[e2];
const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
this._legalize(t0);
this._legalize(t1);
this._legalize(t2);
this._legalize(t3);
}
}, {
key: "_queuePush",
value: function _queuePush(t, error, rms) {
var i = this._queue.length;
this._queueIndices[t] = i;
this._queue.push(t);
this._errors.push(error);
this._rmsSum += rms;
this._queueUp(i);
}
_addPoint(x, y) {
const i = this.coords.length >> 1;
this.coords.push(x, y);
return i;
}
_addTriangle(a, b, c, ab, bc, ca) {
let e = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : this.triangles.length;
const t = e / 3;
this.triangles[e + 0] = a;
this.triangles[e + 1] = b;
this.triangles[e + 2] = c;
this._halfedges[e + 0] = ab;
this._halfedges[e + 1] = bc;
this._halfedges[e + 2] = ca;
if (ab >= 0) {
this._halfedges[ab] = e + 0;
}
}, {
key: "_queuePop",
value: function _queuePop() {
var n = this._queue.length - 1;
this._queueSwap(0, n);
this._queueDown(0, n);
return this._queuePopBack();
if (bc >= 0) {
this._halfedges[bc] = e + 1;
}
}, {
key: "_queuePopBack",
value: function _queuePopBack() {
var t = this._queue.pop();
this._errors.pop();
this._rmsSum -= this._rms[t];
this._queueIndices[t] = -1;
return t;
if (ca >= 0) {
this._halfedges[ca] = e + 2;
}
}, {
key: "_queueRemove",
value: function _queueRemove(t) {
var i = this._queueIndices[t];
if (i < 0) {
var it = this._pending.indexOf(t);
if (it !== -1) {
this._pending[it] = this._pending[--this._pendingLen];
} else {
throw new Error('Broken triangulation (something went wrong).');
}
return;
}
var n = this._queue.length - 1;
if (n !== i) {
this._queueSwap(i, n);
if (!this._queueDown(i, n)) {
this._queueUp(i);
}
}
this._queuePopBack();
this._candidates[2 * t + 0] = 0;
this._candidates[2 * t + 1] = 0;
this._queueIndices[t] = -1;
this._rms[t] = 0;
this._pending[this._pendingLen++] = t;
return e;
}
_legalize(a) {
const b = this._halfedges[a];
if (b < 0) {
return;
}
}, {
key: "_queueLess",
value: function _queueLess(i, j) {
return this._errors[i] > this._errors[j];
const a0 = a - a % 3;
const b0 = b - b % 3;
const al = a0 + (a + 1) % 3;
const ar = a0 + (a + 2) % 3;
const bl = b0 + (b + 2) % 3;
const br = b0 + (b + 1) % 3;
const p0 = this.triangles[ar];
const pr = this.triangles[a];
const pl = this.triangles[al];
const p1 = this.triangles[bl];
const coords = this.coords;
if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
return;
}
}, {
key: "_queueSwap",
value: function _queueSwap(i, j) {
var pi = this._queue[i];
var pj = this._queue[j];
this._queue[i] = pj;
this._queue[j] = pi;
this._queueIndices[pi] = j;
this._queueIndices[pj] = i;
var e = this._errors[i];
this._errors[i] = this._errors[j];
this._errors[j] = e;
const hal = this._halfedges[al];
const har = this._halfedges[ar];
const hbl = this._halfedges[bl];
const hbr = this._halfedges[br];
this._queueRemove(a0 / 3);
this._queueRemove(b0 / 3);
const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
this._legalize(t0 + 1);
this._legalize(t1 + 2);
}
_handleCollinear(pn, a) {
const a0 = a - a % 3;
const al = a0 + (a + 1) % 3;
const ar = a0 + (a + 2) % 3;
const p0 = this.triangles[ar];
const pr = this.triangles[a];
const pl = this.triangles[al];
const hal = this._halfedges[al];
const har = this._halfedges[ar];
const b = this._halfedges[a];
if (b < 0) {
const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);
this._legalize(t0 + 1);
this._legalize(t1 + 2);
return;
}
}, {
key: "_queueUp",
value: function _queueUp(j0) {
var j = j0;
while (true) {
var i = j - 1 >> 1;
if (i === j || !this._queueLess(j, i)) {
break;
}
this._queueSwap(i, j);
j = i;
const b0 = b - b % 3;
const bl = b0 + (b + 2) % 3;
const br = b0 + (b + 1) % 3;
const p1 = this.triangles[bl];
const hbl = this._halfedges[bl];
const hbr = this._halfedges[br];
this._queueRemove(b0 / 3);
const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
this._legalize(t0);
this._legalize(t1);
this._legalize(t2);
this._legalize(t3);
}
_queuePush(t, error, rms) {
const i = this._queue.length;
this._queueIndices[t] = i;
this._queue.push(t);
this._errors.push(error);
this._rmsSum += rms;
this._queueUp(i);
}
_queuePop() {
const n = this._queue.length - 1;
this._queueSwap(0, n);
this._queueDown(0, n);
return this._queuePopBack();
}
_queuePopBack() {
const t = this._queue.pop();
this._errors.pop();
this._rmsSum -= this._rms[t];
this._queueIndices[t] = -1;
return t;
}
_queueRemove(t) {
const i = this._queueIndices[t];
if (i < 0) {
const it = this._pending.indexOf(t);
if (it !== -1) {
this._pending[it] = this._pending[--this._pendingLen];
} else {
throw new Error('Broken triangulation (something went wrong).');
}
return;
}
}, {
key: "_queueDown",
value: function _queueDown(i0, n) {
var i = i0;
while (true) {
var j1 = 2 * i + 1;
if (j1 >= n || j1 < 0) {
break;
}
var j2 = j1 + 1;
var j = j1;
if (j2 < n && this._queueLess(j2, j1)) {
j = j2;
}
if (!this._queueLess(j, i)) {
break;
}
this._queueSwap(i, j);
i = j;
const n = this._queue.length - 1;
if (n !== i) {
this._queueSwap(i, n);
if (!this._queueDown(i, n)) {
this._queueUp(i);
}
return i > i0;
}
}]);
return Delatin;
}();
this._queuePopBack();
}
_queueLess(i, j) {
return this._errors[i] > this._errors[j];
}
_queueSwap(i, j) {
const pi = this._queue[i];
const pj = this._queue[j];
this._queue[i] = pj;
this._queue[j] = pi;
this._queueIndices[pi] = j;
this._queueIndices[pj] = i;
const e = this._errors[i];
this._errors[i] = this._errors[j];
this._errors[j] = e;
}
_queueUp(j0) {
let j = j0;
while (true) {
const i = j - 1 >> 1;
if (i === j || !this._queueLess(j, i)) {
break;
}
this._queueSwap(i, j);
j = i;
}
}
_queueDown(i0, n) {
let i = i0;
while (true) {
const j1 = 2 * i + 1;
if (j1 >= n || j1 < 0) {
break;
}
const j2 = j1 + 1;
let j = j1;
if (j2 < n && this._queueLess(j2, j1)) {
j = j2;
}
if (!this._queueLess(j, i)) {
break;
}
this._queueSwap(i, j);
i = j;
}
return i > i0;
}
}
exports.default = Delatin;

@@ -399,13 +353,13 @@ function orient(ax, ay, bx, by, cx, cy) {

function inCircle(ax, ay, bx, by, cx, cy, px, py) {
var dx = ax - px;
var dy = ay - py;
var ex = bx - px;
var ey = by - py;
var fx = cx - px;
var fy = cy - py;
var ap = dx * dx + dy * dy;
var bp = ex * ex + ey * ey;
var cp = fx * fx + fy * fy;
const dx = ax - px;
const dy = ay - py;
const ex = bx - px;
const ey = by - py;
const fx = cx - px;
const fy = cy - py;
const ap = dx * dx + dy * dy;
const bp = ex * ex + ey * ey;
const cp = fx * fx + fy * fy;
return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
}
//# sourceMappingURL=index.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -8,19 +7,18 @@ value: true

exports.addSkirt = addSkirt;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _loaderUtils = require("@loaders.gl/loader-utils");
function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
var outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
var newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
var newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
var newTriangles = new triangles.constructor(outsideEdges.length * 6);
for (var i = 0; i < outsideEdges.length; i++) {
var edge = outsideEdges[i];
const outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
const newTriangles = new triangles.constructor(outsideEdges.length * 6);
for (let i = 0; i < outsideEdges.length; i++) {
const edge = outsideEdges[i];
updateAttributesForNewEdge({
edge: edge,
edge,
edgeIndex: i,
attributes: attributes,
skirtHeight: skirtHeight,
newPosition: newPosition,
newTexcoord0: newTexcoord0,
newTriangles: newTriangles
attributes,
skirtHeight,
newPosition,
newTexcoord0,
newTriangles
});

@@ -30,5 +28,5 @@ }

attributes.TEXCOORD_0.value = (0, _loaderUtils.concatenateTypedArrays)(attributes.TEXCOORD_0.value, newTexcoord0);
var resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : (0, _loaderUtils.concatenateTypedArrays)(triangles, newTriangles);
const resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : (0, _loaderUtils.concatenateTypedArrays)(triangles, newTriangles);
return {
attributes: attributes,
attributes,
triangles: resultTriangles

@@ -38,4 +36,4 @@ };

function getOutsideEdgesFromTriangles(triangles) {
var edges = [];
for (var i = 0; i < triangles.length; i += 3) {
const edges = [];
for (let i = 0; i < triangles.length; i += 3) {
edges.push([triangles[i], triangles[i + 1]]);

@@ -45,7 +43,5 @@ edges.push([triangles[i + 1], triangles[i + 2]]);

}
edges.sort(function (a, b) {
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));
});
var outsideEdges = [];
var index = 0;
edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
const outsideEdges = [];
let index = 0;
while (index < edges.length) {

@@ -63,18 +59,10 @@ var _edges, _edges2;

function getOutsideEdgesFromIndices(indices, position) {
indices.westIndices.sort(function (a, b) {
return position[3 * a + 1] - position[3 * b + 1];
});
indices.eastIndices.sort(function (a, b) {
return position[3 * b + 1] - position[3 * a + 1];
});
indices.southIndices.sort(function (a, b) {
return position[3 * b] - position[3 * a];
});
indices.northIndices.sort(function (a, b) {
return position[3 * a] - position[3 * b];
});
var edges = [];
for (var index in indices) {
var indexGroup = indices[index];
for (var i = 0; i < indexGroup.length - 1; i++) {
indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
const edges = [];
for (const index in indices) {
const indexGroup = indices[index];
for (let i = 0; i < indexGroup.length - 1; i++) {
edges.push([indexGroup[i], indexGroup[i + 1]]);

@@ -86,12 +74,14 @@ }

function updateAttributesForNewEdge(_ref) {
var edge = _ref.edge,
edgeIndex = _ref.edgeIndex,
attributes = _ref.attributes,
skirtHeight = _ref.skirtHeight,
newPosition = _ref.newPosition,
newTexcoord0 = _ref.newTexcoord0,
newTriangles = _ref.newTriangles;
var positionsLength = attributes.POSITION.value.length;
var vertex1Offset = edgeIndex * 2;
var vertex2Offset = edgeIndex * 2 + 1;
let {
edge,
edgeIndex,
attributes,
skirtHeight,
newPosition,
newTexcoord0,
newTriangles
} = _ref;
const positionsLength = attributes.POSITION.value.length;
const vertex1Offset = edgeIndex * 2;
const vertex2Offset = edgeIndex * 2 + 1;
newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);

@@ -103,3 +93,3 @@ newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;

newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
var triangle1Offset = edgeIndex * 2 * 3;
const triangle1Offset = edgeIndex * 2 * 3;
newTriangles[triangle1Offset] = edge[0];

@@ -106,0 +96,0 @@ newTriangles[triangle1Offset + 1] = positionsLength / 3 + vertex2Offset;

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {

@@ -9,27 +7,23 @@ value: true

exports.default = loadQuantizedMesh;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _schema = require("@loaders.gl/schema");
var _decodeQuantizedMesh = _interopRequireWildcard(require("./decode-quantized-mesh"));
var _skirt = require("./helpers/skirt");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function getMeshAttributes(vertexData, header, bounds) {
var minHeight = header.minHeight,
maxHeight = header.maxHeight;
var _ref = bounds || [0, 0, 1, 1],
_ref2 = (0, _slicedToArray2.default)(_ref, 4),
minX = _ref2[0],
minY = _ref2[1],
maxX = _ref2[2],
maxY = _ref2[3];
var xScale = maxX - minX;
var yScale = maxY - minY;
var zScale = maxHeight - minHeight;
var nCoords = vertexData.length / 3;
var positions = new Float32Array(nCoords * 3);
var texCoords = new Float32Array(nCoords * 2);
for (var i = 0; i < nCoords; i++) {
var x = vertexData[i] / 32767;
var y = vertexData[i + nCoords] / 32767;
var z = vertexData[i + nCoords * 2] / 32767;
const {
minHeight,
maxHeight
} = header;
const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
const xScale = maxX - minX;
const yScale = maxY - minY;
const zScale = maxHeight - minHeight;
const nCoords = vertexData.length / 3;
const positions = new Float32Array(nCoords * 3);
const texCoords = new Float32Array(nCoords * 2);
for (let i = 0; i < nCoords; i++) {
const x = vertexData[i] / 32767;
const y = vertexData[i + nCoords] / 32767;
const z = vertexData[i + nCoords * 2] / 32767;
positions[3 * i + 0] = x * xScale + minX;

@@ -56,23 +50,27 @@ positions[3 * i + 1] = y * yScale + minY;

}
var bounds = options.bounds;
var _decode = (0, _decodeQuantizedMesh.default)(arrayBuffer, _decodeQuantizedMesh.DECODING_STEPS.triangleIndices),
header = _decode.header,
vertexData = _decode.vertexData,
originalTriangleIndices = _decode.triangleIndices,
westIndices = _decode.westIndices,
northIndices = _decode.northIndices,
eastIndices = _decode.eastIndices,
southIndices = _decode.southIndices;
var triangleIndices = originalTriangleIndices;
var attributes = getMeshAttributes(vertexData, header, bounds);
var boundingBox = (0, _schema.getMeshBoundingBox)(attributes);
const {
bounds
} = options;
const {
header,
vertexData,
triangleIndices: originalTriangleIndices,
westIndices,
northIndices,
eastIndices,
southIndices
} = (0, _decodeQuantizedMesh.default)(arrayBuffer, _decodeQuantizedMesh.DECODING_STEPS.triangleIndices);
let triangleIndices = originalTriangleIndices;
let attributes = getMeshAttributes(vertexData, header, bounds);
const boundingBox = (0, _schema.getMeshBoundingBox)(attributes);
if (options.skirtHeight) {
var _addSkirt = (0, _skirt.addSkirt)(attributes, triangleIndices, options.skirtHeight, {
westIndices: westIndices,
northIndices: northIndices,
eastIndices: eastIndices,
southIndices: southIndices
}),
newAttributes = _addSkirt.attributes,
newTriangles = _addSkirt.triangles;
const {
attributes: newAttributes,
triangles: newTriangles
} = (0, _skirt.addSkirt)(attributes, triangleIndices, options.skirtHeight, {
westIndices,
northIndices,
eastIndices,
southIndices
});
attributes = newAttributes;

@@ -87,3 +85,3 @@ triangleIndices = newTriangles;

vertexCount: triangleIndices.length,
boundingBox: boundingBox
boundingBox
},

@@ -95,3 +93,3 @@ mode: 4,

},
attributes: attributes
attributes
};

@@ -98,0 +96,0 @@ }

@@ -8,6 +8,2 @@ "use strict";

exports.default = loadTerrain;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _schema = require("@loaders.gl/schema");

@@ -17,16 +13,16 @@ var _martini = _interopRequireDefault(require("@mapbox/martini"));

var _skirt = require("./helpers/skirt");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
var rScaler = elevationDecoder.rScaler,
bScaler = elevationDecoder.bScaler,
gScaler = elevationDecoder.gScaler,
offset = elevationDecoder.offset;
var terrain = new Float32Array((width + 1) * (height + 1));
for (var i = 0, y = 0; y < height; y++) {
for (var x = 0; x < width; x++, i++) {
var k = i * 4;
var r = imageData[k + 0];
var g = imageData[k + 1];
var b = imageData[k + 2];
const {
rScaler,
bScaler,
gScaler,
offset
} = elevationDecoder;
const terrain = new Float32Array((width + 1) * (height + 1));
for (let i = 0, y = 0; y < height; y++) {
for (let x = 0; x < width; x++, i++) {
const k = i * 4;
const r = imageData[k + 0];
const g = imageData[k + 1];
const b = imageData[k + 2];
terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;

@@ -36,7 +32,7 @@ }

if (tesselator === 'martini') {
for (var _i = (width + 1) * width, _x = 0; _x < width; _x++, _i++) {
terrain[_i] = terrain[_i - width - 1];
for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
terrain[i] = terrain[i - width - 1];
}
for (var _i2 = height, _y = 0; _y < height + 1; _y++, _i2 += height + 1) {
terrain[_i2] = terrain[_i2 - 1];
for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {
terrain[i] = terrain[i - 1];
}

@@ -47,18 +43,13 @@ }

function getMeshAttributes(vertices, terrain, width, height, bounds) {
var gridSize = width + 1;
var numOfVerticies = vertices.length / 2;
var positions = new Float32Array(numOfVerticies * 3);
var texCoords = new Float32Array(numOfVerticies * 2);
var _ref = bounds || [0, 0, width, height],
_ref2 = (0, _slicedToArray2.default)(_ref, 4),
minX = _ref2[0],
minY = _ref2[1],
maxX = _ref2[2],
maxY = _ref2[3];
var xScale = (maxX - minX) / width;
var yScale = (maxY - minY) / height;
for (var i = 0; i < numOfVerticies; i++) {
var x = vertices[i * 2];
var y = vertices[i * 2 + 1];
var pixelIdx = y * gridSize + x;
const gridSize = width + 1;
const numOfVerticies = vertices.length / 2;
const positions = new Float32Array(numOfVerticies * 3);
const texCoords = new Float32Array(numOfVerticies * 2);
const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
const xScale = (maxX - minX) / width;
const yScale = (maxY - minY) / height;
for (let i = 0; i < numOfVerticies; i++) {
const x = vertices[i * 2];
const y = vertices[i * 2 + 1];
const pixelIdx = y * gridSize + x;
positions[3 * i + 0] = x * xScale + minX;

@@ -85,10 +76,14 @@ positions[3 * i + 1] = -y * yScale + maxY;

}
var meshMaxError = terrainOptions.meshMaxError,
bounds = terrainOptions.bounds,
elevationDecoder = terrainOptions.elevationDecoder;
var data = terrainImage.data,
width = terrainImage.width,
height = terrainImage.height;
var terrain;
var mesh;
const {
meshMaxError,
bounds,
elevationDecoder
} = terrainOptions;
const {
data,
width,
height
} = terrainImage;
let terrain;
let mesh;
switch (terrainOptions.tesselator) {

@@ -113,12 +108,15 @@ case 'martini':

}
var _mesh = mesh,
vertices = _mesh.vertices;
var _mesh2 = mesh,
triangles = _mesh2.triangles;
var attributes = getMeshAttributes(vertices, terrain, width, height, bounds);
var boundingBox = (0, _schema.getMeshBoundingBox)(attributes);
const {
vertices
} = mesh;
let {
triangles
} = mesh;
let attributes = getMeshAttributes(vertices, terrain, width, height, bounds);
const boundingBox = (0, _schema.getMeshBoundingBox)(attributes);
if (terrainOptions.skirtHeight) {
var _addSkirt = (0, _skirt.addSkirt)(attributes, triangles, terrainOptions.skirtHeight),
newAttributes = _addSkirt.attributes,
newTriangles = _addSkirt.triangles;
const {
attributes: newAttributes,
triangles: newTriangles
} = (0, _skirt.addSkirt)(attributes, triangles, terrainOptions.skirtHeight);
attributes = newAttributes;

@@ -133,3 +131,3 @@ triangles = newTriangles;

vertexCount: triangles.length,
boundingBox: boundingBox
boundingBox
},

@@ -141,56 +139,43 @@ mode: 4,

},
attributes: attributes
attributes
};
}
function getMartiniTileMesh(meshMaxError, width, terrain) {
var gridSize = width + 1;
var martini = new _martini.default(gridSize);
var tile = martini.createTile(terrain);
var _tile$getMesh = tile.getMesh(meshMaxError),
vertices = _tile$getMesh.vertices,
triangles = _tile$getMesh.triangles;
const gridSize = width + 1;
const martini = new _martini.default(gridSize);
const tile = martini.createTile(terrain);
const {
vertices,
triangles
} = tile.getMesh(meshMaxError);
return {
vertices: vertices,
triangles: triangles
vertices,
triangles
};
}
function getDelatinTileMesh(meshMaxError, width, height, terrain) {
var tin = new _delatin.default(terrain, width + 1, height + 1);
const tin = new _delatin.default(terrain, width + 1, height + 1);
tin.run(meshMaxError);
var coords = tin.coords,
triangles = tin.triangles;
var vertices = coords;
const {
coords,
triangles
} = tin;
const vertices = coords;
return {
vertices: vertices,
triangles: triangles
vertices,
triangles
};
}
function loadTerrain(_x2, _x3, _x4) {
return _loadTerrain.apply(this, arguments);
async function loadTerrain(arrayBuffer, options, context) {
const loadImageOptions = {
...options,
mimeType: 'application/x.image',
image: {
...options.image,
type: 'data'
}
};
const image = await context.parse(arrayBuffer, loadImageOptions);
return getMesh(image, options.terrain);
}
function _loadTerrain() {
_loadTerrain = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer, options, context) {
var loadImageOptions, image;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
loadImageOptions = _objectSpread(_objectSpread({}, options), {}, {
mimeType: 'application/x.image',
image: _objectSpread(_objectSpread({}, options.image), {}, {
type: 'data'
})
});
_context.next = 3;
return context.parse(arrayBuffer, loadImageOptions);
case 3:
image = _context.sent;
return _context.abrupt("return", getMesh(image, options.terrain));
case 5:
case "end":
return _context.stop();
}
}, _callee);
}));
return _loadTerrain.apply(this, arguments);
}
//# sourceMappingURL=parse-terrain.js.map

@@ -7,4 +7,4 @@ "use strict";

exports.VERSION = void 0;
var VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : 'latest';
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : 'latest';
exports.VERSION = VERSION;
//# sourceMappingURL=version.js.map

@@ -8,3 +8,3 @@ "use strict";

var _version = require("./lib/utils/version");
var QuantizedMeshLoader = {
const QuantizedMeshLoader = {
name: 'Quantized Mesh',

@@ -25,4 +25,4 @@ id: 'quantized-mesh',

exports.QuantizedMeshLoader = QuantizedMeshLoader;
var _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
const _typecheckQuantizedMeshLoader = QuantizedMeshLoader;
exports._typecheckQuantizedMeshLoader = _typecheckQuantizedMeshLoader;
//# sourceMappingURL=quantized-mesh-loader.js.map

@@ -8,3 +8,3 @@ "use strict";

var _version = require("./lib/utils/version");
var TerrainLoader = {
const TerrainLoader = {
name: 'Terrain',

@@ -33,4 +33,4 @@ id: 'terrain',

exports.TerrainLoader = TerrainLoader;
var _typecheckTerrainWorkerLoader = TerrainLoader;
const _typecheckTerrainWorkerLoader = TerrainLoader;
exports._typecheckTerrainWorkerLoader = _typecheckTerrainWorkerLoader;
//# sourceMappingURL=terrain-loader.js.map

@@ -1,2 +0,2 @@

export const VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : 'latest';
export const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : 'latest';
//# sourceMappingURL=version.js.map

@@ -1196,3 +1196,3 @@ (() => {

// src/lib/utils/version.ts
var VERSION = true ? "3.4.14" : "latest";
var VERSION = true ? "3.4.15" : "latest";

@@ -1199,0 +1199,0 @@ // src/terrain-loader.ts

@@ -1196,3 +1196,3 @@ (() => {

// src/lib/utils/version.ts
var VERSION = true ? "3.4.14" : "latest";
var VERSION = true ? "3.4.15" : "latest";

@@ -1199,0 +1199,0 @@ // src/terrain-loader.ts

{
"name": "@loaders.gl/terrain",
"version": "3.4.14",
"version": "3.4.15",
"description": "Framework-independent loader for terrain raster formats",

@@ -38,8 +38,8 @@ "license": "MIT",

"@babel/runtime": "^7.3.1",
"@loaders.gl/images": "3.4.14",
"@loaders.gl/loader-utils": "3.4.14",
"@loaders.gl/schema": "3.4.14",
"@loaders.gl/images": "3.4.15",
"@loaders.gl/loader-utils": "3.4.15",
"@loaders.gl/schema": "3.4.15",
"@mapbox/martini": "^0.2.0"
},
"gitHead": "dffa197c6ae79bac5277d5e8a132f4cd274e74e5"
"gitHead": "19e941d5805568e449ef9092490d6568a4853298"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc