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

@loaders.gl/terrain

Package Overview
Dependencies
Maintainers
8
Versions
271
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.0.0-alpha.4 to 3.0.0-alpha.5

dist/dist.min.js.map

4

dist/es5/bundle.js
"use strict";
var moduleExports = require('./index');
const moduleExports = require('./index');
var _global = typeof window === 'undefined' ? global : window;
const _global = typeof window === 'undefined' ? global : window;

@@ -7,0 +7,0 @@ _global.loaders = _global.loaders || {};

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

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

@@ -15,3 +15,3 @@ }

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

@@ -22,3 +22,3 @@ }

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

@@ -29,3 +29,3 @@ }

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

@@ -32,0 +32,0 @@ }

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = decode;
exports.default = decode;
exports.DECODING_STEPS = void 0;
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]]);
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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]]);
function decodeZigZag(value) {

@@ -26,26 +15,13 @@ return value >> 1 ^ -(value & 1);

function decodeHeader(dataView) {
var position = 0;
var header = {};
let position = 0;
const 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();
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

@@ -56,17 +32,17 @@ };

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;
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 (var i = 0; i < vertexCount; i++) {
for (let i = 0; i < vertexCount; i++) {
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));

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

return {
vertexData: vertexData,
vertexData,
vertexDataEndPosition: position

@@ -88,5 +64,4 @@ };

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

@@ -103,6 +78,6 @@ if (bytesPerIndex === 2) {

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

@@ -119,6 +94,6 @@

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;

@@ -129,10 +104,10 @@ if (position % bytesPerIndex !== 0) {

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
};

@@ -142,28 +117,28 @@ }

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
};

@@ -181,7 +156,7 @@ }

function decodeExtensions(dataView, indicesEndPosition) {
var extensions = {};
const extensions = {};
if (dataView.byteLength <= indicesEndPosition) {
return {
extensions: extensions,
extensions,
extensionsEndPosition: indicesEndPosition

@@ -191,10 +166,10 @@ };

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);

@@ -222,3 +197,3 @@ switch (extensionId) {

return {
extensions: extensions,
extensions,
extensionsEndPosition: position

@@ -228,3 +203,3 @@ };

var DECODING_STEPS = {
const DECODING_STEPS = {
header: 0,

@@ -237,3 +212,3 @@ vertices: 1,

exports.DECODING_STEPS = DECODING_STEPS;
var DEFAULT_OPTIONS = {
const DEFAULT_OPTIONS = {
maxDecodingStep: DECODING_STEPS.extensions

@@ -243,71 +218,74 @@ };

function decode(data, userOptions) {
var options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
var view = new DataView(data);
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
const view = new DataView(data);
const {
header,
headerEndPosition
} = decodeHeader(view);
var _decodeHeader = decodeHeader(view),
header = _decodeHeader.header,
headerEndPosition = _decodeHeader.headerEndPosition;
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

@@ -5,11 +5,7 @@ "use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = loadQuantizedMesh;
exports.default = loadQuantizedMesh;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _loaderUtils = require("@loaders.gl/loader-utils");

@@ -20,23 +16,18 @@

function getMeshAttributes(vertexData, header, bounds) {
var minHeight = header.minHeight,
maxHeight = header.maxHeight;
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);
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;
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;

@@ -66,10 +57,11 @@ 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,
triangleIndices = _decode.triangleIndices;
var attributes = getMeshAttributes(vertexData, header, bounds);
const {
bounds
} = options;
const {
header,
vertexData,
triangleIndices
} = (0, _decodeQuantizedMesh.default)(arrayBuffer, _decodeQuantizedMesh.DECODING_STEPS.triangleIndices);
const attributes = getMeshAttributes(vertexData, header, bounds);
return {

@@ -88,3 +80,3 @@ loaderData: {

},
attributes: attributes
attributes
};

@@ -91,0 +83,0 @@ }

@@ -8,10 +8,4 @@ "use strict";

});
exports["default"] = loadTerrain;
exports.default = loadTerrain;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _martini = _interopRequireDefault(require("@mapbox/martini"));

@@ -22,15 +16,17 @@

function getTerrain(imageData, tileSize, elevationDecoder) {
var rScaler = elevationDecoder.rScaler,
bScaler = elevationDecoder.bScaler,
gScaler = elevationDecoder.gScaler,
offset = elevationDecoder.offset;
var gridSize = tileSize + 1;
var terrain = new Float32Array(gridSize * gridSize);
const {
rScaler,
bScaler,
gScaler,
offset
} = elevationDecoder;
const gridSize = tileSize + 1;
const terrain = new Float32Array(gridSize * gridSize);
for (var i = 0, y = 0; y < tileSize; y++) {
for (var x = 0; x < tileSize; x++, i++) {
var k = i * 4;
var r = imageData[k + 0];
var g = imageData[k + 1];
var b = imageData[k + 2];
for (let i = 0, y = 0; y < tileSize; y++) {
for (let x = 0; x < tileSize; 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;

@@ -40,8 +36,8 @@ }

for (var _i = gridSize * (gridSize - 1), _x = 0; _x < gridSize - 1; _x++, _i++) {
terrain[_i] = terrain[_i - gridSize];
for (let i = gridSize * (gridSize - 1), x = 0; x < gridSize - 1; x++, i++) {
terrain[i] = terrain[i - gridSize];
}
for (var _i2 = gridSize - 1, _y = 0; _y < gridSize; _y++, _i2 += gridSize) {
terrain[_i2] = terrain[_i2 - 1];
for (let i = gridSize - 1, y = 0; y < gridSize; y++, i += gridSize) {
terrain[i] = terrain[i - 1];
}

@@ -53,21 +49,14 @@

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

@@ -97,17 +86,18 @@ positions[3 * i + 1] = -y * yScale + maxY;

var meshMaxError = terrainOptions.meshMaxError,
bounds = terrainOptions.bounds,
elevationDecoder = terrainOptions.elevationDecoder;
var data = terrainImage.data;
var tileSize = terrainImage.width;
var gridSize = tileSize + 1;
var terrain = getTerrain(data, tileSize, elevationDecoder);
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;
var attributes = getMeshAttributes(vertices, terrain, tileSize, bounds);
const {
meshMaxError,
bounds,
elevationDecoder
} = terrainOptions;
const data = terrainImage.data;
const tileSize = terrainImage.width;
const gridSize = tileSize + 1;
const terrain = getTerrain(data, tileSize, elevationDecoder);
const martini = new _martini.default(gridSize);
const tile = martini.createTile(terrain);
const {
vertices,
triangles
} = tile.getMesh(meshMaxError);
const attributes = getMeshAttributes(vertices, terrain, tileSize, bounds);
return {

@@ -126,35 +116,12 @@ loaderData: {

},
attributes: attributes
attributes
};
}
function loadTerrain(_x2, _x3, _x4) {
return _loadTerrain.apply(this, arguments);
async function loadTerrain(arrayBuffer, options, context) {
options.image = options.image || {};
options.image.type = 'data';
const image = await context.parse(arrayBuffer, options, options.baseUri);
return getMartiniTileMesh(image, options.terrain);
}
function _loadTerrain() {
_loadTerrain = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(arrayBuffer, options, context) {
var image;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options.image = options.image || {};
options.image.type = 'data';
_context.next = 4;
return context.parse(arrayBuffer, options, options.baseUri);
case 4:
image = _context.sent;
return _context.abrupt("return", getMartiniTileMesh(image, options.terrain));
case 6:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return _loadTerrain.apply(this, arguments);
}
//# sourceMappingURL=parse-terrain.js.map

@@ -10,19 +10,12 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _version = require("./lib/utils/version");
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _parseQuantizedMesh = _interopRequireDefault(require("./lib/parse-quantized-mesh"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var VERSION = typeof "3.0.0-alpha.4" !== 'undefined' ? "3.0.0-alpha.4" : 'latest';
var QuantizedMeshWorkerLoader = {
const QuantizedMeshWorkerLoader = {
name: 'Quantized Mesh',
id: 'quantized-mesh',
name: 'Quantized Mesh',
version: VERSION,
module: 'terrain',
version: _version.VERSION,
worker: true,
extensions: ['terrain'],

@@ -32,3 +25,2 @@ mimeTypes: ['application/vnd.quantized-mesh'],

'quantized-mesh': {
workerUrl: "https://unpkg.com/@loaders.gl/terrain@".concat(VERSION, "/dist/quantized-mesh-loader.worker.js"),
bounds: [0, 0, 1, 1]

@@ -39,30 +31,7 @@ }

exports.QuantizedMeshWorkerLoader = QuantizedMeshWorkerLoader;
var QuantizedMeshLoader = _objectSpread(_objectSpread({}, QuantizedMeshWorkerLoader), {}, {
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;
}()
});
const QuantizedMeshLoader = { ...QuantizedMeshWorkerLoader,
parseSync: _parseQuantizedMesh.default,
parse: async (arrayBuffer, options) => (0, _parseQuantizedMesh.default)(arrayBuffer, options)
};
exports.QuantizedMeshLoader = QuantizedMeshLoader;
//# sourceMappingURL=quantized-mesh-loader.js.map

@@ -10,15 +10,12 @@ "use strict";

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _version = require("./lib/utils/version");
var _parseTerrain = _interopRequireDefault(require("./lib/parse-terrain"));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var VERSION = typeof "3.0.0-alpha.4" !== 'undefined' ? "3.0.0-alpha.4" : 'latest';
var TerrainWorkerLoader = {
const TerrainWorkerLoader = {
name: 'Terrain',
id: 'terrain',
name: 'Terrain',
version: VERSION,
module: 'terrain',
version: _version.VERSION,
worker: true,
extensions: ['png', 'pngraw'],

@@ -29,3 +26,2 @@ mimeTypes: ['image/png'],

bounds: null,
workerUrl: "https://unpkg.com/@loaders.gl/terrain@".concat(VERSION, "/dist/terrain-loader.worker.js"),
meshMaxError: 10,

@@ -42,8 +38,6 @@ elevationDecoder: {

exports.TerrainWorkerLoader = TerrainWorkerLoader;
var TerrainLoader = _objectSpread(_objectSpread({}, TerrainWorkerLoader), {}, {
parse: _parseTerrain["default"]
});
const TerrainLoader = { ...TerrainWorkerLoader,
parse: _parseTerrain.default
};
exports.TerrainLoader = TerrainLoader;
//# sourceMappingURL=terrain-loader.js.map

@@ -1,4 +0,4 @@

var moduleExports = require('./index');
const moduleExports = require('./index');
var _global = typeof window === 'undefined' ? global : window;
const _global = typeof window === 'undefined' ? global : window;

@@ -5,0 +5,0 @@ _global.loaders = _global.loaders || {};

@@ -1,11 +0,3 @@

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
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 _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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]]);
function decodeZigZag(value) {

@@ -16,26 +8,13 @@ return value >> 1 ^ -(value & 1);

function decodeHeader(dataView) {
var position = 0;
var header = {};
let position = 0;
const header = {};
var _iterator = _createForOfIteratorHelper(QUANTIZED_MESH_HEADER),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var _step$value = _slicedToArray(_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();
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

@@ -46,17 +25,17 @@ };

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;
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 (var i = 0; i < vertexCount; i++) {
for (let i = 0; i < vertexCount; i++) {
u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));

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

return {
vertexData: vertexData,
vertexData,
vertexDataEndPosition: position

@@ -78,5 +57,4 @@ };

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

@@ -93,6 +71,6 @@ if (bytesPerIndex === 2) {

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

@@ -109,6 +87,6 @@

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;

@@ -119,10 +97,10 @@ if (position % bytesPerIndex !== 0) {

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
};

@@ -132,28 +110,28 @@ }

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
};

@@ -171,7 +149,7 @@ }

function decodeExtensions(dataView, indicesEndPosition) {
var extensions = {};
const extensions = {};
if (dataView.byteLength <= indicesEndPosition) {
return {
extensions: extensions,
extensions,
extensionsEndPosition: indicesEndPosition

@@ -181,10 +159,10 @@ };

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);

@@ -212,3 +190,3 @@ switch (extensionId) {

return {
extensions: extensions,
extensions,
extensionsEndPosition: position

@@ -218,3 +196,3 @@ };

export var DECODING_STEPS = {
export const DECODING_STEPS = {
header: 0,

@@ -226,75 +204,78 @@ vertices: 1,

};
var DEFAULT_OPTIONS = {
const DEFAULT_OPTIONS = {
maxDecodingStep: DECODING_STEPS.extensions
};
export default function decode(data, userOptions) {
var options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
var view = new DataView(data);
const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);
const view = new DataView(data);
const {
header,
headerEndPosition
} = decodeHeader(view);
var _decodeHeader = decodeHeader(view),
header = _decodeHeader.header,
headerEndPosition = _decodeHeader.headerEndPosition;
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

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

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { getMeshBoundingBox } from '@loaders.gl/loader-utils';

@@ -6,23 +5,18 @@ import decode, { DECODING_STEPS } from './decode-quantized-mesh';

function getMeshAttributes(vertexData, header, bounds) {
var minHeight = header.minHeight,
maxHeight = header.maxHeight;
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);
var _ref = bounds || [0, 0, 1, 1],
_ref2 = _slicedToArray(_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;
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;

@@ -52,10 +46,11 @@ positions[3 * i + 1] = y * yScale + minY;

var bounds = options.bounds;
var _decode = decode(arrayBuffer, DECODING_STEPS.triangleIndices),
header = _decode.header,
vertexData = _decode.vertexData,
triangleIndices = _decode.triangleIndices;
var attributes = getMeshAttributes(vertexData, header, bounds);
const {
bounds
} = options;
const {
header,
vertexData,
triangleIndices
} = decode(arrayBuffer, DECODING_STEPS.triangleIndices);
const attributes = getMeshAttributes(vertexData, header, bounds);
return {

@@ -74,3 +69,3 @@ loaderData: {

},
attributes: attributes
attributes
};

@@ -77,0 +72,0 @@ }

@@ -1,4 +0,1 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import Martini from '@mapbox/martini';

@@ -8,15 +5,17 @@ import { getMeshBoundingBox } from '@loaders.gl/loader-utils';

function getTerrain(imageData, tileSize, elevationDecoder) {
var rScaler = elevationDecoder.rScaler,
bScaler = elevationDecoder.bScaler,
gScaler = elevationDecoder.gScaler,
offset = elevationDecoder.offset;
var gridSize = tileSize + 1;
var terrain = new Float32Array(gridSize * gridSize);
const {
rScaler,
bScaler,
gScaler,
offset
} = elevationDecoder;
const gridSize = tileSize + 1;
const terrain = new Float32Array(gridSize * gridSize);
for (var i = 0, y = 0; y < tileSize; y++) {
for (var x = 0; x < tileSize; x++, i++) {
var k = i * 4;
var r = imageData[k + 0];
var g = imageData[k + 1];
var b = imageData[k + 2];
for (let i = 0, y = 0; y < tileSize; y++) {
for (let x = 0; x < tileSize; 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;

@@ -26,8 +25,8 @@ }

for (var _i = gridSize * (gridSize - 1), _x = 0; _x < gridSize - 1; _x++, _i++) {
terrain[_i] = terrain[_i - gridSize];
for (let i = gridSize * (gridSize - 1), x = 0; x < gridSize - 1; x++, i++) {
terrain[i] = terrain[i - gridSize];
}
for (var _i2 = gridSize - 1, _y = 0; _y < gridSize; _y++, _i2 += gridSize) {
terrain[_i2] = terrain[_i2 - 1];
for (let i = gridSize - 1, y = 0; y < gridSize; y++, i += gridSize) {
terrain[i] = terrain[i - 1];
}

@@ -39,21 +38,14 @@

function getMeshAttributes(vertices, terrain, tileSize, bounds) {
var gridSize = tileSize + 1;
var numOfVerticies = vertices.length / 2;
var positions = new Float32Array(numOfVerticies * 3);
var texCoords = new Float32Array(numOfVerticies * 2);
const gridSize = tileSize + 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, tileSize, tileSize];
const xScale = (maxX - minX) / tileSize;
const yScale = (maxY - minY) / tileSize;
var _ref = bounds || [0, 0, tileSize, tileSize],
_ref2 = _slicedToArray(_ref, 4),
minX = _ref2[0],
minY = _ref2[1],
maxX = _ref2[2],
maxY = _ref2[3];
var xScale = (maxX - minX) / tileSize;
var yScale = (maxY - minY) / tileSize;
for (var i = 0; i < numOfVerticies; i++) {
var x = vertices[i * 2];
var y = vertices[i * 2 + 1];
var pixelIdx = y * gridSize + x;
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;

@@ -83,17 +75,18 @@ positions[3 * i + 1] = -y * yScale + maxY;

var meshMaxError = terrainOptions.meshMaxError,
bounds = terrainOptions.bounds,
elevationDecoder = terrainOptions.elevationDecoder;
var data = terrainImage.data;
var tileSize = terrainImage.width;
var gridSize = tileSize + 1;
var terrain = getTerrain(data, tileSize, elevationDecoder);
var martini = new Martini(gridSize);
var tile = martini.createTile(terrain);
var _tile$getMesh = tile.getMesh(meshMaxError),
vertices = _tile$getMesh.vertices,
triangles = _tile$getMesh.triangles;
var attributes = getMeshAttributes(vertices, terrain, tileSize, bounds);
const {
meshMaxError,
bounds,
elevationDecoder
} = terrainOptions;
const data = terrainImage.data;
const tileSize = terrainImage.width;
const gridSize = tileSize + 1;
const terrain = getTerrain(data, tileSize, elevationDecoder);
const martini = new Martini(gridSize);
const tile = martini.createTile(terrain);
const {
vertices,
triangles
} = tile.getMesh(meshMaxError);
const attributes = getMeshAttributes(vertices, terrain, tileSize, bounds);
return {

@@ -112,35 +105,12 @@ loaderData: {

},
attributes: attributes
attributes
};
}
export default function loadTerrain(_x2, _x3, _x4) {
return _loadTerrain.apply(this, arguments);
export default async function loadTerrain(arrayBuffer, options, context) {
options.image = options.image || {};
options.image.type = 'data';
const image = await context.parse(arrayBuffer, options, options.baseUri);
return getMartiniTileMesh(image, options.terrain);
}
function _loadTerrain() {
_loadTerrain = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(arrayBuffer, options, context) {
var image;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options.image = options.image || {};
options.image.type = 'data';
_context.next = 4;
return context.parse(arrayBuffer, options, options.baseUri);
case 4:
image = _context.sent;
return _context.abrupt("return", getMartiniTileMesh(image, options.terrain));
case 6:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return _loadTerrain.apply(this, arguments);
}
//# sourceMappingURL=parse-terrain.js.map

@@ -1,15 +0,9 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { VERSION } from './lib/utils/version';
import parseQuantizedMesh from './lib/parse-quantized-mesh';
var VERSION = typeof "3.0.0-alpha.4" !== 'undefined' ? "3.0.0-alpha.4" : 'latest';
export var QuantizedMeshWorkerLoader = {
export const QuantizedMeshWorkerLoader = {
name: 'Quantized Mesh',
id: 'quantized-mesh',
name: 'Quantized Mesh',
module: 'terrain',
version: VERSION,
worker: true,
extensions: ['terrain'],

@@ -19,3 +13,2 @@ mimeTypes: ['application/vnd.quantized-mesh'],

'quantized-mesh': {
workerUrl: "https://unpkg.com/@loaders.gl/terrain@".concat(VERSION, "/dist/quantized-mesh-loader.worker.js"),
bounds: [0, 0, 1, 1]

@@ -25,27 +18,6 @@ }

};
export var QuantizedMeshLoader = _objectSpread(_objectSpread({}, QuantizedMeshWorkerLoader), {}, {
export const QuantizedMeshLoader = { ...QuantizedMeshWorkerLoader,
parseSync: parseQuantizedMesh,
parse: function () {
var _parse = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(arrayBuffer, options) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", parseQuantizedMesh(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) => parseQuantizedMesh(arrayBuffer, options)
};
//# sourceMappingURL=quantized-mesh-loader.js.map

@@ -1,13 +0,9 @@

import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { VERSION } from './lib/utils/version';
import loadTerrain from './lib/parse-terrain';
var VERSION = typeof "3.0.0-alpha.4" !== 'undefined' ? "3.0.0-alpha.4" : 'latest';
export var TerrainWorkerLoader = {
export const TerrainWorkerLoader = {
name: 'Terrain',
id: 'terrain',
name: 'Terrain',
module: 'terrain',
version: VERSION,
worker: true,
extensions: ['png', 'pngraw'],

@@ -18,3 +14,2 @@ mimeTypes: ['image/png'],

bounds: null,
workerUrl: "https://unpkg.com/@loaders.gl/terrain@".concat(VERSION, "/dist/terrain-loader.worker.js"),
meshMaxError: 10,

@@ -30,5 +25,5 @@ elevationDecoder: {

};
export var TerrainLoader = _objectSpread(_objectSpread({}, TerrainWorkerLoader), {}, {
export const TerrainLoader = { ...TerrainWorkerLoader,
parse: loadTerrain
});
};
//# sourceMappingURL=terrain-loader.js.map
{
"name": "@loaders.gl/terrain",
"version": "3.0.0-alpha.4",
"version": "3.0.0-alpha.5",
"description": "Framework-independent loader for terrain raster formats",

@@ -23,3 +23,2 @@ "license": "MIT",

"module": "dist/esm/index.js",
"esnext": "dist/es6/index.js",
"sideEffects": false,

@@ -32,12 +31,13 @@ "files": [

"scripts": {
"pre-build": "npm run build-worker && npm run build-bundle && npm run build-bundle -- --env.dev",
"build-bundle": "webpack --display=minimal --config ../../scripts/bundle.config.js",
"build-worker": "webpack --entry ./src/terrain-loader.worker.js --output ./dist/terrain-loader.worker.js --config ../../scripts/worker-webpack-config.js && webpack --entry ./src/quantized-mesh-loader.worker.js --output ./dist/quantized-mesh-loader.worker.js --config ../../scripts/worker-webpack-config.js"
"pre-build": "npm run build-worker && npm run build-worker2 && npm run build-bundle && npm run build-bundle -- --env.dev",
"build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js",
"build-worker": "webpack --entry ./src/workers/terrain-worker.js --output ./dist/terrain-worker.js --config ../../scripts/webpack/worker.js",
"build-worker2": "webpack --entry ./src/workers/quantized-mesh-worker.js --output ./dist/quantized-mesh-worker.js --config ../../scripts/webpack/worker.js"
},
"dependencies": {
"@babel/runtime": "^7.3.1",
"@loaders.gl/loader-utils": "3.0.0-alpha.4",
"@loaders.gl/loader-utils": "3.0.0-alpha.5",
"@mapbox/martini": "^0.2.0"
},
"gitHead": "51999b245ade896a4b5750269e68154ee299d035"
"gitHead": "a07341a8276a7435df4f79f035a3a2b2354e19c4"
}

@@ -0,14 +1,16 @@

/** @typedef {import('@loaders.gl/loader-utils').WorkerLoaderObject} WorkerLoaderObject */
/** @typedef {import('@loaders.gl/loader-utils').LoaderObject} LoaderObject */
/** @typedef {import('@loaders.gl/loader-utils').WorkerLoaderObject} WorkerLoaderObject */
import {VERSION} from './lib/utils/version';
import parseQuantizedMesh from './lib/parse-quantized-mesh';
// __VERSION__ is injected by babel-plugin-version-inline
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
/** @type {WorkerLoaderObject} */
/**
* Worker loader for quantized meshes
* @type {WorkerLoaderObject}
*/
export const QuantizedMeshWorkerLoader = {
name: 'Quantized Mesh',
id: 'quantized-mesh',
name: 'Quantized Mesh',
module: 'terrain',
version: VERSION,
worker: true,
extensions: ['terrain'],

@@ -18,3 +20,2 @@ mimeTypes: ['application/vnd.quantized-mesh'],

'quantized-mesh': {
workerUrl: `https://unpkg.com/@loaders.gl/terrain@${VERSION}/dist/quantized-mesh-loader.worker.js`,
bounds: [0, 0, 1, 1]

@@ -25,3 +26,6 @@ }

/** @type {LoaderObject} */
/**
* Loader for quantized meshes
* @type {LoaderObject}
*/
export const QuantizedMeshLoader = {

@@ -28,0 +32,0 @@ ...QuantizedMeshWorkerLoader,

@@ -1,12 +0,16 @@

// __VERSION__ is injected by babel-plugin-version-inline
/** @typedef {import('@loaders.gl/loader-utils').WorkerLoaderObject} WorkerLoaderObject */
/** @typedef {import('@loaders.gl/loader-utils').LoaderObject} LoaderObject */
import {VERSION} from './lib/utils/version';
import loadTerrain from './lib/parse-terrain';
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
/**
* Worker loader for quantized meshes
* @type {WorkerLoaderObject}
*/
export const TerrainWorkerLoader = {
name: 'Terrain',
id: 'terrain',
name: 'Terrain',
module: 'terrain',
version: VERSION,
worker: true,
extensions: ['png', 'pngraw'],

@@ -17,3 +21,2 @@ mimeTypes: ['image/png'],

bounds: null,
workerUrl: `https://unpkg.com/@loaders.gl/terrain@${VERSION}/dist/terrain-loader.worker.js`,
meshMaxError: 10,

@@ -30,2 +33,6 @@ elevationDecoder: {

/**
* Loader for quantized meshes
* @type {LoaderObject}
*/
export const TerrainLoader = {

@@ -32,0 +39,0 @@ ...TerrainWorkerLoader,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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

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