@loaders.gl/terrain
Advanced tools
Comparing version 4.0.0-beta.2 to 4.0.0-beta.3
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
(() => { | ||
@@ -9,3 +10,3 @@ // ../loader-utils/src/loader-types.ts | ||
function getTransferList(object, recursive = true, transfers) { | ||
const transfersSet = transfers || new Set(); | ||
const transfersSet = transfers || /* @__PURE__ */ new Set(); | ||
if (!object) { | ||
@@ -53,7 +54,11 @@ } else if (isTransferable(object)) { | ||
} | ||
var onMessageWrapperMap = new Map(); | ||
var onMessageWrapperMap = /* @__PURE__ */ new Map(); | ||
var WorkerBody = class { | ||
/** Check that we are actually in a worker thread */ | ||
static inWorkerThread() { | ||
return typeof self !== "undefined" || Boolean(getParentPort()); | ||
} | ||
/* | ||
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any | ||
*/ | ||
static set onmessage(onMessage) { | ||
@@ -102,2 +107,7 @@ function handleMessage(message) { | ||
} | ||
/** | ||
* Send a message from a worker to creating thread (main thread) | ||
* @param type | ||
* @param payload | ||
*/ | ||
static postMessage(type, payload) { | ||
@@ -134,2 +144,3 @@ const data = { source: "loaders.gl", type, payload }; | ||
options, | ||
// @ts-expect-error fetch missing | ||
context: { | ||
@@ -205,3 +216,5 @@ ...context, | ||
if (!TypedArrayConstructor) { | ||
throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types'); | ||
throw new Error( | ||
'"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types' | ||
); | ||
} | ||
@@ -246,3 +259,3 @@ const sumLength = arrays.reduce((acc, value) => acc + value.length, 0); | ||
// src/lib/decode-quantized-mesh.ts | ||
var QUANTIZED_MESH_HEADER = new Map([ | ||
var QUANTIZED_MESH_HEADER = /* @__PURE__ */ new Map([ | ||
["centerX", Float64Array.BYTES_PER_ELEMENT], | ||
@@ -291,3 +304,5 @@ ["centerY", Float64Array.BYTES_PER_ELEMENT], | ||
v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true)); | ||
height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true)); | ||
height += decodeZigZag( | ||
dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true) | ||
); | ||
vertexData[i] = u; | ||
@@ -331,3 +346,8 @@ vertexData[i + vertexCount] = v; | ||
const triangleIndicesCount = triangleCount * 3; | ||
const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex); | ||
const triangleIndices = decodeIndex( | ||
dataView.buffer, | ||
position, | ||
triangleIndicesCount, | ||
bytesPerIndex | ||
); | ||
position += triangleIndicesCount * bytesPerIndex; | ||
@@ -350,3 +370,9 @@ return { | ||
position += Uint32Array.BYTES_PER_ELEMENT; | ||
const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false); | ||
const southIndices = decodeIndex( | ||
dataView.buffer, | ||
position, | ||
southVertexCount, | ||
bytesPerIndex, | ||
false | ||
); | ||
position += southVertexCount * bytesPerIndex; | ||
@@ -359,3 +385,9 @@ const eastVertexCount = dataView.getUint32(position, true); | ||
position += Uint32Array.BYTES_PER_ELEMENT; | ||
const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false); | ||
const northIndices = decodeIndex( | ||
dataView.buffer, | ||
position, | ||
northVertexCount, | ||
bytesPerIndex, | ||
false | ||
); | ||
position += northVertexCount * bytesPerIndex; | ||
@@ -371,6 +403,13 @@ return { | ||
function decodeVertexNormalsExtension(extensionDataView) { | ||
return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength); | ||
return new Uint8Array( | ||
extensionDataView.buffer, | ||
extensionDataView.byteOffset, | ||
extensionDataView.byteLength | ||
); | ||
} | ||
function decodeWaterMaskExtension(extensionDataView) { | ||
return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength); | ||
return extensionDataView.buffer.slice( | ||
extensionDataView.byteOffset, | ||
extensionDataView.byteOffset + extensionDataView.byteLength | ||
); | ||
} | ||
@@ -426,3 +465,7 @@ function decodeExtensions(dataView, indicesEndPosition) { | ||
} | ||
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition); | ||
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices( | ||
view, | ||
vertexData, | ||
vertexDataEndPosition | ||
); | ||
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) { | ||
@@ -528,8 +571,20 @@ return { header, vertexData, triangleIndices }; | ||
const vertex2Offset = edgeIndex * 2 + 1; | ||
newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3); | ||
newPosition.set( | ||
attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), | ||
vertex1Offset * 3 | ||
); | ||
newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; | ||
newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3); | ||
newPosition.set( | ||
attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), | ||
vertex2Offset * 3 | ||
); | ||
newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; | ||
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2); | ||
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2); | ||
newTexcoord0.set( | ||
attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), | ||
vertex1Offset * 2 | ||
); | ||
newTexcoord0.set( | ||
attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), | ||
vertex2Offset * 2 | ||
); | ||
const triangle1Offset = edgeIndex * 2 * 3; | ||
@@ -560,8 +615,13 @@ newTriangles[triangle1Offset] = edge[0]; | ||
if (options?.skirtHeight) { | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangleIndices, options.skirtHeight, { | ||
westIndices, | ||
northIndices, | ||
eastIndices, | ||
southIndices | ||
}); | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt( | ||
attributes, | ||
triangleIndices, | ||
options.skirtHeight, | ||
{ | ||
westIndices, | ||
northIndices, | ||
eastIndices, | ||
southIndices | ||
} | ||
); | ||
attributes = newAttributes; | ||
@@ -571,2 +631,3 @@ triangleIndices = newTriangles; | ||
return { | ||
// Data return by this loader implementation | ||
loaderData: { | ||
@@ -576,8 +637,11 @@ header: {} | ||
header: { | ||
// @ts-ignore | ||
vertexCount: triangleIndices.length, | ||
boundingBox | ||
}, | ||
// TODO | ||
schema: void 0, | ||
topology: "triangle-list", | ||
mode: 4, | ||
// TRIANGLES | ||
indices: { value: triangleIndices, size: 1 }, | ||
@@ -609,2 +673,4 @@ attributes | ||
TEXCOORD_0: { value: texCoords, size: 2 } | ||
// TODO: Parse normals if they exist in the file | ||
// NORMAL: {}, - optional, but creates the high poly look with lighting | ||
}; | ||
@@ -619,3 +685,5 @@ } | ||
if (tileSize & tileSize - 1) | ||
throw new Error(`Expected grid size to be 2^n+1, got ${gridSize}.`); | ||
throw new Error( | ||
`Expected grid size to be 2^n+1, got ${gridSize}.` | ||
); | ||
this.numTriangles = tileSize * tileSize * 2 - 2; | ||
@@ -665,3 +733,5 @@ this.numParentTriangles = this.numTriangles - tileSize * tileSize; | ||
if (terrain.length !== size * size) | ||
throw new Error(`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.`); | ||
throw new Error( | ||
`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.` | ||
); | ||
this.terrain = terrain; | ||
@@ -775,2 +845,3 @@ this.martini = martini; | ||
} | ||
// refine the mesh until its maximum error gets below the given one | ||
run(maxError = 1) { | ||
@@ -781,2 +852,3 @@ while (this.getMaxError() > maxError) { | ||
} | ||
// refine the mesh with a single point | ||
refine() { | ||
@@ -786,11 +858,15 @@ this._step(); | ||
} | ||
// max error of the current mesh | ||
getMaxError() { | ||
return this._errors[0]; | ||
} | ||
// root-mean-square deviation of the current mesh | ||
getRMSD() { | ||
return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0; | ||
} | ||
// height value at a given position | ||
heightAt(x, y) { | ||
return this.data[this.width * y + x]; | ||
} | ||
// rasterize and queue all triangles that got added or updated in _step | ||
_flush() { | ||
@@ -803,6 +879,15 @@ const coords = this.coords; | ||
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); | ||
this._findCandidate( | ||
coords[a], | ||
coords[a + 1], | ||
coords[b], | ||
coords[b + 1], | ||
coords[c], | ||
coords[c + 1], | ||
t | ||
); | ||
} | ||
this._pendingLen = 0; | ||
} | ||
// rasterize a triangle, find its max error, and queue it for processing | ||
_findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) { | ||
@@ -875,2 +960,3 @@ const minX = Math.min(p0x, p1x, p2x); | ||
} | ||
// process the next triangle in the queue, splitting it with a new point | ||
_step() { | ||
@@ -911,2 +997,3 @@ const t = this._queuePop(); | ||
} | ||
// add coordinates for a new vertex | ||
_addPoint(x, y) { | ||
@@ -917,2 +1004,3 @@ const i = this.coords.length >> 1; | ||
} | ||
// add or update a triangle in the mesh | ||
_addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) { | ||
@@ -958,3 +1046,12 @@ const t = e / 3; | ||
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])) { | ||
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; | ||
@@ -973,2 +1070,3 @@ } | ||
} | ||
// handle a case where new vertex is on the edge of a triangle | ||
_handleCollinear(pn, a) { | ||
@@ -1007,2 +1105,3 @@ const a0 = a - a % 3; | ||
} | ||
// priority queue methods | ||
_queuePush(t, error, rms) { | ||
@@ -1141,3 +1240,7 @@ const i = this._queue.length; | ||
if (terrainOptions.skirtHeight) { | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangles, terrainOptions.skirtHeight); | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt( | ||
attributes, | ||
triangles, | ||
terrainOptions.skirtHeight | ||
); | ||
attributes = newAttributes; | ||
@@ -1147,2 +1250,3 @@ triangles = newTriangles; | ||
return { | ||
// Data return by this loader implementation | ||
loaderData: { | ||
@@ -1156,2 +1260,3 @@ header: {} | ||
mode: 4, | ||
// TRIANGLES | ||
indices: { value: Uint32Array.from(triangles), size: 1 }, | ||
@@ -1218,2 +1323,3 @@ attributes | ||
TEXCOORD_0: { value: texCoords, size: 2 } | ||
// NORMAL: {}, - optional, but creates the high poly look with lighting | ||
}; | ||
@@ -1223,3 +1329,3 @@ } | ||
// src/lib/utils/version.ts | ||
var VERSION = true ? "4.0.0-beta.2" : "latest"; | ||
var VERSION = true ? "4.0.0-beta.3" : "latest"; | ||
@@ -1226,0 +1332,0 @@ // src/terrain-loader.ts |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
(() => { | ||
@@ -9,3 +10,3 @@ // ../loader-utils/src/loader-types.ts | ||
function getTransferList(object, recursive = true, transfers) { | ||
const transfersSet = transfers || new Set(); | ||
const transfersSet = transfers || /* @__PURE__ */ new Set(); | ||
if (!object) { | ||
@@ -53,7 +54,11 @@ } else if (isTransferable(object)) { | ||
} | ||
var onMessageWrapperMap = new Map(); | ||
var onMessageWrapperMap = /* @__PURE__ */ new Map(); | ||
var WorkerBody = class { | ||
/** Check that we are actually in a worker thread */ | ||
static inWorkerThread() { | ||
return typeof self !== "undefined" || Boolean(getParentPort()); | ||
} | ||
/* | ||
* (type: WorkerMessageType, payload: WorkerMessagePayload) => any | ||
*/ | ||
static set onmessage(onMessage) { | ||
@@ -102,2 +107,7 @@ function handleMessage(message) { | ||
} | ||
/** | ||
* Send a message from a worker to creating thread (main thread) | ||
* @param type | ||
* @param payload | ||
*/ | ||
static postMessage(type, payload) { | ||
@@ -134,2 +144,3 @@ const data = { source: "loaders.gl", type, payload }; | ||
options, | ||
// @ts-expect-error fetch missing | ||
context: { | ||
@@ -205,3 +216,5 @@ ...context, | ||
if (!TypedArrayConstructor) { | ||
throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types'); | ||
throw new Error( | ||
'"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types' | ||
); | ||
} | ||
@@ -246,3 +259,3 @@ const sumLength = arrays.reduce((acc, value) => acc + value.length, 0); | ||
// src/lib/decode-quantized-mesh.ts | ||
var QUANTIZED_MESH_HEADER = new Map([ | ||
var QUANTIZED_MESH_HEADER = /* @__PURE__ */ new Map([ | ||
["centerX", Float64Array.BYTES_PER_ELEMENT], | ||
@@ -291,3 +304,5 @@ ["centerY", Float64Array.BYTES_PER_ELEMENT], | ||
v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true)); | ||
height += decodeZigZag(dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true)); | ||
height += decodeZigZag( | ||
dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true) | ||
); | ||
vertexData[i] = u; | ||
@@ -331,3 +346,8 @@ vertexData[i + vertexCount] = v; | ||
const triangleIndicesCount = triangleCount * 3; | ||
const triangleIndices = decodeIndex(dataView.buffer, position, triangleIndicesCount, bytesPerIndex); | ||
const triangleIndices = decodeIndex( | ||
dataView.buffer, | ||
position, | ||
triangleIndicesCount, | ||
bytesPerIndex | ||
); | ||
position += triangleIndicesCount * bytesPerIndex; | ||
@@ -350,3 +370,9 @@ return { | ||
position += Uint32Array.BYTES_PER_ELEMENT; | ||
const southIndices = decodeIndex(dataView.buffer, position, southVertexCount, bytesPerIndex, false); | ||
const southIndices = decodeIndex( | ||
dataView.buffer, | ||
position, | ||
southVertexCount, | ||
bytesPerIndex, | ||
false | ||
); | ||
position += southVertexCount * bytesPerIndex; | ||
@@ -359,3 +385,9 @@ const eastVertexCount = dataView.getUint32(position, true); | ||
position += Uint32Array.BYTES_PER_ELEMENT; | ||
const northIndices = decodeIndex(dataView.buffer, position, northVertexCount, bytesPerIndex, false); | ||
const northIndices = decodeIndex( | ||
dataView.buffer, | ||
position, | ||
northVertexCount, | ||
bytesPerIndex, | ||
false | ||
); | ||
position += northVertexCount * bytesPerIndex; | ||
@@ -371,6 +403,13 @@ return { | ||
function decodeVertexNormalsExtension(extensionDataView) { | ||
return new Uint8Array(extensionDataView.buffer, extensionDataView.byteOffset, extensionDataView.byteLength); | ||
return new Uint8Array( | ||
extensionDataView.buffer, | ||
extensionDataView.byteOffset, | ||
extensionDataView.byteLength | ||
); | ||
} | ||
function decodeWaterMaskExtension(extensionDataView) { | ||
return extensionDataView.buffer.slice(extensionDataView.byteOffset, extensionDataView.byteOffset + extensionDataView.byteLength); | ||
return extensionDataView.buffer.slice( | ||
extensionDataView.byteOffset, | ||
extensionDataView.byteOffset + extensionDataView.byteLength | ||
); | ||
} | ||
@@ -426,3 +465,7 @@ function decodeExtensions(dataView, indicesEndPosition) { | ||
} | ||
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices(view, vertexData, vertexDataEndPosition); | ||
const { triangleIndices, triangleIndicesEndPosition } = decodeTriangleIndices( | ||
view, | ||
vertexData, | ||
vertexDataEndPosition | ||
); | ||
if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) { | ||
@@ -528,8 +571,20 @@ return { header, vertexData, triangleIndices }; | ||
const vertex2Offset = edgeIndex * 2 + 1; | ||
newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3); | ||
newPosition.set( | ||
attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), | ||
vertex1Offset * 3 | ||
); | ||
newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; | ||
newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3); | ||
newPosition.set( | ||
attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), | ||
vertex2Offset * 3 | ||
); | ||
newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; | ||
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2); | ||
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2); | ||
newTexcoord0.set( | ||
attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), | ||
vertex1Offset * 2 | ||
); | ||
newTexcoord0.set( | ||
attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), | ||
vertex2Offset * 2 | ||
); | ||
const triangle1Offset = edgeIndex * 2 * 3; | ||
@@ -560,8 +615,13 @@ newTriangles[triangle1Offset] = edge[0]; | ||
if (options?.skirtHeight) { | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangleIndices, options.skirtHeight, { | ||
westIndices, | ||
northIndices, | ||
eastIndices, | ||
southIndices | ||
}); | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt( | ||
attributes, | ||
triangleIndices, | ||
options.skirtHeight, | ||
{ | ||
westIndices, | ||
northIndices, | ||
eastIndices, | ||
southIndices | ||
} | ||
); | ||
attributes = newAttributes; | ||
@@ -571,2 +631,3 @@ triangleIndices = newTriangles; | ||
return { | ||
// Data return by this loader implementation | ||
loaderData: { | ||
@@ -576,8 +637,11 @@ header: {} | ||
header: { | ||
// @ts-ignore | ||
vertexCount: triangleIndices.length, | ||
boundingBox | ||
}, | ||
// TODO | ||
schema: void 0, | ||
topology: "triangle-list", | ||
mode: 4, | ||
// TRIANGLES | ||
indices: { value: triangleIndices, size: 1 }, | ||
@@ -609,2 +673,4 @@ attributes | ||
TEXCOORD_0: { value: texCoords, size: 2 } | ||
// TODO: Parse normals if they exist in the file | ||
// NORMAL: {}, - optional, but creates the high poly look with lighting | ||
}; | ||
@@ -619,3 +685,5 @@ } | ||
if (tileSize & tileSize - 1) | ||
throw new Error(`Expected grid size to be 2^n+1, got ${gridSize}.`); | ||
throw new Error( | ||
`Expected grid size to be 2^n+1, got ${gridSize}.` | ||
); | ||
this.numTriangles = tileSize * tileSize * 2 - 2; | ||
@@ -665,3 +733,5 @@ this.numParentTriangles = this.numTriangles - tileSize * tileSize; | ||
if (terrain.length !== size * size) | ||
throw new Error(`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.`); | ||
throw new Error( | ||
`Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.` | ||
); | ||
this.terrain = terrain; | ||
@@ -775,2 +845,3 @@ this.martini = martini; | ||
} | ||
// refine the mesh until its maximum error gets below the given one | ||
run(maxError = 1) { | ||
@@ -781,2 +852,3 @@ while (this.getMaxError() > maxError) { | ||
} | ||
// refine the mesh with a single point | ||
refine() { | ||
@@ -786,11 +858,15 @@ this._step(); | ||
} | ||
// max error of the current mesh | ||
getMaxError() { | ||
return this._errors[0]; | ||
} | ||
// root-mean-square deviation of the current mesh | ||
getRMSD() { | ||
return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0; | ||
} | ||
// height value at a given position | ||
heightAt(x, y) { | ||
return this.data[this.width * y + x]; | ||
} | ||
// rasterize and queue all triangles that got added or updated in _step | ||
_flush() { | ||
@@ -803,6 +879,15 @@ const coords = this.coords; | ||
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); | ||
this._findCandidate( | ||
coords[a], | ||
coords[a + 1], | ||
coords[b], | ||
coords[b + 1], | ||
coords[c], | ||
coords[c + 1], | ||
t | ||
); | ||
} | ||
this._pendingLen = 0; | ||
} | ||
// rasterize a triangle, find its max error, and queue it for processing | ||
_findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) { | ||
@@ -875,2 +960,3 @@ const minX = Math.min(p0x, p1x, p2x); | ||
} | ||
// process the next triangle in the queue, splitting it with a new point | ||
_step() { | ||
@@ -911,2 +997,3 @@ const t = this._queuePop(); | ||
} | ||
// add coordinates for a new vertex | ||
_addPoint(x, y) { | ||
@@ -917,2 +1004,3 @@ const i = this.coords.length >> 1; | ||
} | ||
// add or update a triangle in the mesh | ||
_addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) { | ||
@@ -958,3 +1046,12 @@ const t = e / 3; | ||
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])) { | ||
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; | ||
@@ -973,2 +1070,3 @@ } | ||
} | ||
// handle a case where new vertex is on the edge of a triangle | ||
_handleCollinear(pn, a) { | ||
@@ -1007,2 +1105,3 @@ const a0 = a - a % 3; | ||
} | ||
// priority queue methods | ||
_queuePush(t, error, rms) { | ||
@@ -1141,3 +1240,7 @@ const i = this._queue.length; | ||
if (terrainOptions.skirtHeight) { | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt(attributes, triangles, terrainOptions.skirtHeight); | ||
const { attributes: newAttributes, triangles: newTriangles } = addSkirt( | ||
attributes, | ||
triangles, | ||
terrainOptions.skirtHeight | ||
); | ||
attributes = newAttributes; | ||
@@ -1147,2 +1250,3 @@ triangles = newTriangles; | ||
return { | ||
// Data return by this loader implementation | ||
loaderData: { | ||
@@ -1156,2 +1260,3 @@ header: {} | ||
mode: 4, | ||
// TRIANGLES | ||
indices: { value: Uint32Array.from(triangles), size: 1 }, | ||
@@ -1218,2 +1323,3 @@ attributes | ||
TEXCOORD_0: { value: texCoords, size: 2 } | ||
// NORMAL: {}, - optional, but creates the high poly look with lighting | ||
}; | ||
@@ -1223,3 +1329,3 @@ } | ||
// src/lib/utils/version.ts | ||
var VERSION = true ? "4.0.0-beta.2" : "latest"; | ||
var VERSION = true ? "4.0.0-beta.3" : "latest"; | ||
@@ -1226,0 +1332,0 @@ // src/terrain-loader.ts |
{ | ||
"name": "@loaders.gl/terrain", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.3", | ||
"description": "Framework-independent loader for terrain raster formats", | ||
"license": "MIT", | ||
"type": "module", | ||
"publishConfig": { | ||
@@ -22,4 +23,11 @@ "access": "public" | ||
"types": "dist/index.d.ts", | ||
"main": "dist/es5/index.js", | ||
"module": "dist/esm/index.js", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.js", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"sideEffects": false, | ||
@@ -32,4 +40,4 @@ "files": [ | ||
"scripts": { | ||
"pre-build": "npm run build-worker && npm run build-worker2 && npm run build-bundle", | ||
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js", | ||
"pre-build": "npm run build-worker && npm run build-worker2 && npm run build-bundle && npm run build-bundle -- --env=dev", | ||
"build-bundle": "ocular-bundle ./src/index.ts", | ||
"build-worker": "esbuild src/workers/terrain-worker.ts --bundle --outfile=dist/terrain-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"", | ||
@@ -40,8 +48,8 @@ "build-worker2": "esbuild src/workers/quantized-mesh-worker.ts --bundle --outfile=dist/quantized-mesh-worker.js --define:__VERSION__=\\\"$npm_package_version\\\"" | ||
"@babel/runtime": "^7.3.1", | ||
"@loaders.gl/images": "4.0.0-beta.2", | ||
"@loaders.gl/loader-utils": "4.0.0-beta.2", | ||
"@loaders.gl/schema": "4.0.0-beta.2", | ||
"@loaders.gl/images": "4.0.0-beta.3", | ||
"@loaders.gl/loader-utils": "4.0.0-beta.3", | ||
"@loaders.gl/schema": "4.0.0-beta.3", | ||
"@mapbox/martini": "^0.2.0" | ||
}, | ||
"gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc" | ||
"gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af" | ||
} |
7327
Yes
347803
62
+ Added@loaders.gl/images@4.0.0-beta.3(transitive)
+ Added@loaders.gl/loader-utils@4.0.0-beta.3(transitive)
+ Added@loaders.gl/schema@4.0.0-beta.3(transitive)
+ Added@loaders.gl/worker-utils@4.0.0-beta.3(transitive)
- Removed@loaders.gl/images@4.0.0-beta.2(transitive)
- Removed@loaders.gl/loader-utils@4.0.0-beta.2(transitive)
- Removed@loaders.gl/schema@4.0.0-beta.2(transitive)
- Removed@loaders.gl/worker-utils@4.0.0-beta.2(transitive)