@loaders.gl/terrain 4.0.0-alpha.8 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.min.js +44 -33
- package/dist/es5/index.js +2 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/lib/utils/version.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/lib/utils/version.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/quantized-mesh-worker.js +15 -5
- package/dist/terrain-worker.js +15 -5
- package/package.json +5 -5
- package/src/index.ts +3 -1
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -33
- package/dist/lib/decode-quantized-mesh.js +0 -227
- package/dist/lib/delatin/index.js +0 -418
- package/dist/lib/helpers/skirt.js +0 -127
- package/dist/lib/parse-quantized-mesh.js +0 -97
- package/dist/lib/parse-terrain.js +0 -154
- package/dist/lib/utils/version.js +0 -7
- package/dist/quantized-mesh-loader.js +0 -22
- package/dist/terrain-loader.js +0 -30
- package/dist/workers/quantized-mesh-worker.js +0 -5
- package/dist/workers/terrain-worker.js +0 -5
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addSkirt = void 0;
|
|
4
|
-
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
-
/**
|
|
6
|
-
* Add skirt to existing mesh
|
|
7
|
-
* @param {object} attributes - POSITION and TEXCOOD_0 attributes data
|
|
8
|
-
* @param {any} triangles - indices array of the mesh geometry
|
|
9
|
-
* @param skirtHeight - height of the skirt geometry
|
|
10
|
-
* @param outsideIndices - edge indices from quantized mesh data
|
|
11
|
-
* @returns - geometry data with added skirt
|
|
12
|
-
*/
|
|
13
|
-
function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
|
|
14
|
-
const outsideEdges = outsideIndices
|
|
15
|
-
? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value)
|
|
16
|
-
: getOutsideEdgesFromTriangles(triangles);
|
|
17
|
-
// 2 new vertices for each outside edge
|
|
18
|
-
const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
|
|
19
|
-
const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
|
|
20
|
-
// 2 new triangles for each outside edge
|
|
21
|
-
const newTriangles = new triangles.constructor(outsideEdges.length * 6);
|
|
22
|
-
for (let i = 0; i < outsideEdges.length; i++) {
|
|
23
|
-
const edge = outsideEdges[i];
|
|
24
|
-
updateAttributesForNewEdge({
|
|
25
|
-
edge,
|
|
26
|
-
edgeIndex: i,
|
|
27
|
-
attributes,
|
|
28
|
-
skirtHeight,
|
|
29
|
-
newPosition,
|
|
30
|
-
newTexcoord0,
|
|
31
|
-
newTriangles
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
attributes.POSITION.value = (0, loader_utils_1.concatenateTypedArrays)(attributes.POSITION.value, newPosition);
|
|
35
|
-
attributes.TEXCOORD_0.value = (0, loader_utils_1.concatenateTypedArrays)(attributes.TEXCOORD_0.value, newTexcoord0);
|
|
36
|
-
const resultTriangles = triangles instanceof Array
|
|
37
|
-
? triangles.concat(newTriangles)
|
|
38
|
-
: (0, loader_utils_1.concatenateTypedArrays)(triangles, newTriangles);
|
|
39
|
-
return {
|
|
40
|
-
attributes,
|
|
41
|
-
triangles: resultTriangles
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
exports.addSkirt = addSkirt;
|
|
45
|
-
/**
|
|
46
|
-
* Get geometry edges that located on a border of the mesh
|
|
47
|
-
* @param {any} triangles - indices array of the mesh geometry
|
|
48
|
-
* @returns {number[][]} - outside edges data
|
|
49
|
-
*/
|
|
50
|
-
function getOutsideEdgesFromTriangles(triangles) {
|
|
51
|
-
const edges = [];
|
|
52
|
-
for (let i = 0; i < triangles.length; i += 3) {
|
|
53
|
-
edges.push([triangles[i], triangles[i + 1]]);
|
|
54
|
-
edges.push([triangles[i + 1], triangles[i + 2]]);
|
|
55
|
-
edges.push([triangles[i + 2], triangles[i]]);
|
|
56
|
-
}
|
|
57
|
-
edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
|
|
58
|
-
const outsideEdges = [];
|
|
59
|
-
let index = 0;
|
|
60
|
-
while (index < edges.length) {
|
|
61
|
-
if (edges[index][0] === edges[index + 1]?.[1] && edges[index][1] === edges[index + 1]?.[0]) {
|
|
62
|
-
index += 2;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
outsideEdges.push(edges[index]);
|
|
66
|
-
index++;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return outsideEdges;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get geometry edges that located on a border of the mesh
|
|
73
|
-
* @param {object} indices - edge indices from quantized mesh data
|
|
74
|
-
* @param {TypedArray} position - position attribute geometry data
|
|
75
|
-
* @returns {number[][]} - outside edges data
|
|
76
|
-
*/
|
|
77
|
-
function getOutsideEdgesFromIndices(indices, position) {
|
|
78
|
-
// Sort skirt indices to create adjacent triangles
|
|
79
|
-
indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
|
|
80
|
-
// Reverse (b - a) to match triangle winding
|
|
81
|
-
indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
|
|
82
|
-
indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
|
|
83
|
-
// Reverse (b - a) to match triangle winding
|
|
84
|
-
indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
|
|
85
|
-
const edges = [];
|
|
86
|
-
for (const index in indices) {
|
|
87
|
-
const indexGroup = indices[index];
|
|
88
|
-
for (let i = 0; i < indexGroup.length - 1; i++) {
|
|
89
|
-
edges.push([indexGroup[i], indexGroup[i + 1]]);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return edges;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Get geometry edges that located on a border of the mesh
|
|
96
|
-
* @param {object} args
|
|
97
|
-
* @param {number[]} args.edge - edge indices in geometry
|
|
98
|
-
* @param {number} args.edgeIndex - edge index in outsideEdges array
|
|
99
|
-
* @param {object} args.attributes - POSITION and TEXCOORD_0 attributes
|
|
100
|
-
* @param {number} args.skirtHeight - height of the skirt geometry
|
|
101
|
-
* @param {TypedArray} args.newPosition - POSITION array for skirt data
|
|
102
|
-
* @param {TypedArray} args.newTexcoord0 - TEXCOORD_0 array for skirt data
|
|
103
|
-
* @param {TypedArray | Array} args.newTriangles - trinagle indices array for skirt data
|
|
104
|
-
* @returns {void}
|
|
105
|
-
*/
|
|
106
|
-
function updateAttributesForNewEdge({ edge, edgeIndex, attributes, skirtHeight, newPosition, newTexcoord0, newTriangles }) {
|
|
107
|
-
const positionsLength = attributes.POSITION.value.length;
|
|
108
|
-
const vertex1Offset = edgeIndex * 2;
|
|
109
|
-
const vertex2Offset = edgeIndex * 2 + 1;
|
|
110
|
-
// Define POSITION for new 1st vertex
|
|
111
|
-
newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
|
|
112
|
-
newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height
|
|
113
|
-
// Define POSITION for new 2nd vertex
|
|
114
|
-
newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
|
|
115
|
-
newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height
|
|
116
|
-
// Use same TEXCOORDS for skirt vertices
|
|
117
|
-
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
|
|
118
|
-
newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
|
|
119
|
-
// Define new triangles
|
|
120
|
-
const triangle1Offset = edgeIndex * 2 * 3;
|
|
121
|
-
newTriangles[triangle1Offset] = edge[0];
|
|
122
|
-
newTriangles[triangle1Offset + 1] = positionsLength / 3 + vertex2Offset;
|
|
123
|
-
newTriangles[triangle1Offset + 2] = edge[1];
|
|
124
|
-
newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
|
|
125
|
-
newTriangles[triangle1Offset + 4] = edge[0];
|
|
126
|
-
newTriangles[triangle1Offset + 5] = positionsLength / 3 + vertex1Offset;
|
|
127
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.parseQuantizedMesh = void 0;
|
|
27
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
28
|
-
const decode_quantized_mesh_1 = __importStar(require("./decode-quantized-mesh"));
|
|
29
|
-
const skirt_1 = require("./helpers/skirt");
|
|
30
|
-
function parseQuantizedMesh(arrayBuffer, options = {}) {
|
|
31
|
-
const { bounds } = options;
|
|
32
|
-
// Don't parse edge indices or format extensions
|
|
33
|
-
const { header, vertexData, triangleIndices: originalTriangleIndices, westIndices, northIndices, eastIndices, southIndices } = (0, decode_quantized_mesh_1.default)(arrayBuffer, decode_quantized_mesh_1.DECODING_STEPS.triangleIndices);
|
|
34
|
-
let triangleIndices = originalTriangleIndices;
|
|
35
|
-
let attributes = getMeshAttributes(vertexData, header, bounds);
|
|
36
|
-
// Compute bounding box before adding skirt so that z values are not skewed
|
|
37
|
-
// TODO: Find bounding box from header, instead of doing extra pass over
|
|
38
|
-
// vertices.
|
|
39
|
-
const boundingBox = (0, schema_1.getMeshBoundingBox)(attributes);
|
|
40
|
-
if (options?.skirtHeight) {
|
|
41
|
-
const { attributes: newAttributes, triangles: newTriangles } = (0, skirt_1.addSkirt)(attributes, triangleIndices, options.skirtHeight, {
|
|
42
|
-
westIndices,
|
|
43
|
-
northIndices,
|
|
44
|
-
eastIndices,
|
|
45
|
-
southIndices
|
|
46
|
-
});
|
|
47
|
-
attributes = newAttributes;
|
|
48
|
-
triangleIndices = newTriangles;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
// Data return by this loader implementation
|
|
52
|
-
loaderData: {
|
|
53
|
-
header: {}
|
|
54
|
-
},
|
|
55
|
-
header: {
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
vertexCount: triangleIndices.length,
|
|
58
|
-
boundingBox
|
|
59
|
-
},
|
|
60
|
-
// TODO
|
|
61
|
-
schema: undefined,
|
|
62
|
-
topology: 'triangle-list',
|
|
63
|
-
mode: 4,
|
|
64
|
-
indices: { value: triangleIndices, size: 1 },
|
|
65
|
-
attributes
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
exports.parseQuantizedMesh = parseQuantizedMesh;
|
|
69
|
-
function getMeshAttributes(vertexData, header, bounds) {
|
|
70
|
-
const { minHeight, maxHeight } = header;
|
|
71
|
-
const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];
|
|
72
|
-
const xScale = maxX - minX;
|
|
73
|
-
const yScale = maxY - minY;
|
|
74
|
-
const zScale = maxHeight - minHeight;
|
|
75
|
-
const nCoords = vertexData.length / 3;
|
|
76
|
-
// vec3. x, y defined by bounds, z in meters
|
|
77
|
-
const positions = new Float32Array(nCoords * 3);
|
|
78
|
-
// vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
|
|
79
|
-
const texCoords = new Float32Array(nCoords * 2);
|
|
80
|
-
// Data is not interleaved; all u, then all v, then all heights
|
|
81
|
-
for (let i = 0; i < nCoords; i++) {
|
|
82
|
-
const x = vertexData[i] / 32767;
|
|
83
|
-
const y = vertexData[i + nCoords] / 32767;
|
|
84
|
-
const z = vertexData[i + nCoords * 2] / 32767;
|
|
85
|
-
positions[3 * i + 0] = x * xScale + minX;
|
|
86
|
-
positions[3 * i + 1] = y * yScale + minY;
|
|
87
|
-
positions[3 * i + 2] = z * zScale + minHeight;
|
|
88
|
-
texCoords[2 * i + 0] = x;
|
|
89
|
-
texCoords[2 * i + 1] = y;
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
POSITION: { value: positions, size: 3 },
|
|
93
|
-
TEXCOORD_0: { value: texCoords, size: 2 }
|
|
94
|
-
// TODO: Parse normals if they exist in the file
|
|
95
|
-
// NORMAL: {}, - optional, but creates the high poly look with lighting
|
|
96
|
-
};
|
|
97
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.makeTerrainMeshFromImage = void 0;
|
|
8
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
9
|
-
const martini_1 = __importDefault(require("@mapbox/martini"));
|
|
10
|
-
const delatin_1 = __importDefault(require("./delatin"));
|
|
11
|
-
const skirt_1 = require("./helpers/skirt");
|
|
12
|
-
/**
|
|
13
|
-
* Returns generated mesh object from image data
|
|
14
|
-
*
|
|
15
|
-
* @param terrainImage terrain image data
|
|
16
|
-
* @param terrainOptions terrain options
|
|
17
|
-
* @returns mesh object
|
|
18
|
-
*/
|
|
19
|
-
function makeTerrainMeshFromImage(terrainImage, terrainOptions) {
|
|
20
|
-
const { meshMaxError, bounds, elevationDecoder } = terrainOptions;
|
|
21
|
-
const { data, width, height } = terrainImage;
|
|
22
|
-
let terrain;
|
|
23
|
-
let mesh;
|
|
24
|
-
switch (terrainOptions.tesselator) {
|
|
25
|
-
case 'martini':
|
|
26
|
-
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
27
|
-
mesh = getMartiniTileMesh(meshMaxError, width, terrain);
|
|
28
|
-
break;
|
|
29
|
-
case 'delatin':
|
|
30
|
-
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
31
|
-
mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
|
|
32
|
-
break;
|
|
33
|
-
// auto
|
|
34
|
-
default:
|
|
35
|
-
if (width === height && !(height & (width - 1))) {
|
|
36
|
-
terrain = getTerrain(data, width, height, elevationDecoder, 'martini');
|
|
37
|
-
mesh = getMartiniTileMesh(meshMaxError, width, terrain);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
terrain = getTerrain(data, width, height, elevationDecoder, 'delatin');
|
|
41
|
-
mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
const { vertices } = mesh;
|
|
46
|
-
let { triangles } = mesh;
|
|
47
|
-
let attributes = getMeshAttributes(vertices, terrain, width, height, bounds);
|
|
48
|
-
// Compute bounding box before adding skirt so that z values are not skewed
|
|
49
|
-
const boundingBox = (0, schema_1.getMeshBoundingBox)(attributes);
|
|
50
|
-
if (terrainOptions.skirtHeight) {
|
|
51
|
-
const { attributes: newAttributes, triangles: newTriangles } = (0, skirt_1.addSkirt)(attributes, triangles, terrainOptions.skirtHeight);
|
|
52
|
-
attributes = newAttributes;
|
|
53
|
-
triangles = newTriangles;
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
// Data return by this loader implementation
|
|
57
|
-
loaderData: {
|
|
58
|
-
header: {}
|
|
59
|
-
},
|
|
60
|
-
header: {
|
|
61
|
-
vertexCount: triangles.length,
|
|
62
|
-
boundingBox
|
|
63
|
-
},
|
|
64
|
-
mode: 4,
|
|
65
|
-
indices: { value: Uint32Array.from(triangles), size: 1 },
|
|
66
|
-
attributes
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
exports.makeTerrainMeshFromImage = makeTerrainMeshFromImage;
|
|
70
|
-
/**
|
|
71
|
-
* Get Martini generated vertices and triangles
|
|
72
|
-
*
|
|
73
|
-
* @param {number} meshMaxError threshold for simplifying mesh
|
|
74
|
-
* @param {number} width width of the input data
|
|
75
|
-
* @param {number[] | Float32Array} terrain elevation data
|
|
76
|
-
* @returns {{vertices: Uint16Array, triangles: Uint32Array}} vertices and triangles data
|
|
77
|
-
*/
|
|
78
|
-
function getMartiniTileMesh(meshMaxError, width, terrain) {
|
|
79
|
-
const gridSize = width + 1;
|
|
80
|
-
const martini = new martini_1.default(gridSize);
|
|
81
|
-
const tile = martini.createTile(terrain);
|
|
82
|
-
const { vertices, triangles } = tile.getMesh(meshMaxError);
|
|
83
|
-
return { vertices, triangles };
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Get Delatin generated vertices and triangles
|
|
87
|
-
*
|
|
88
|
-
* @param {number} meshMaxError threshold for simplifying mesh
|
|
89
|
-
* @param {number} width width of the input data array
|
|
90
|
-
* @param {number} height height of the input data array
|
|
91
|
-
* @param {number[] | Float32Array} terrain elevation data
|
|
92
|
-
* @returns {{vertices: number[], triangles: number[]}} vertices and triangles data
|
|
93
|
-
*/
|
|
94
|
-
function getDelatinTileMesh(meshMaxError, width, height, terrain) {
|
|
95
|
-
const tin = new delatin_1.default(terrain, width + 1, height + 1);
|
|
96
|
-
tin.run(meshMaxError);
|
|
97
|
-
// @ts-expect-error
|
|
98
|
-
const { coords, triangles } = tin;
|
|
99
|
-
const vertices = coords;
|
|
100
|
-
return { vertices, triangles };
|
|
101
|
-
}
|
|
102
|
-
function getTerrain(imageData, width, height, elevationDecoder, tesselator) {
|
|
103
|
-
const { rScaler, bScaler, gScaler, offset } = elevationDecoder;
|
|
104
|
-
// From Martini demo
|
|
105
|
-
// https://observablehq.com/@mourner/martin-real-time-rtin-terrain-mesh
|
|
106
|
-
const terrain = new Float32Array((width + 1) * (height + 1));
|
|
107
|
-
// decode terrain values
|
|
108
|
-
for (let i = 0, y = 0; y < height; y++) {
|
|
109
|
-
for (let x = 0; x < width; x++, i++) {
|
|
110
|
-
const k = i * 4;
|
|
111
|
-
const r = imageData[k + 0];
|
|
112
|
-
const g = imageData[k + 1];
|
|
113
|
-
const b = imageData[k + 2];
|
|
114
|
-
terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (tesselator === 'martini') {
|
|
118
|
-
// backfill bottom border
|
|
119
|
-
for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
|
|
120
|
-
terrain[i] = terrain[i - width - 1];
|
|
121
|
-
}
|
|
122
|
-
// backfill right border
|
|
123
|
-
for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {
|
|
124
|
-
terrain[i] = terrain[i - 1];
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return terrain;
|
|
128
|
-
}
|
|
129
|
-
function getMeshAttributes(vertices, terrain, width, height, bounds) {
|
|
130
|
-
const gridSize = width + 1;
|
|
131
|
-
const numOfVerticies = vertices.length / 2;
|
|
132
|
-
// vec3. x, y in pixels, z in meters
|
|
133
|
-
const positions = new Float32Array(numOfVerticies * 3);
|
|
134
|
-
// vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
|
|
135
|
-
const texCoords = new Float32Array(numOfVerticies * 2);
|
|
136
|
-
const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
|
|
137
|
-
const xScale = (maxX - minX) / width;
|
|
138
|
-
const yScale = (maxY - minY) / height;
|
|
139
|
-
for (let i = 0; i < numOfVerticies; i++) {
|
|
140
|
-
const x = vertices[i * 2];
|
|
141
|
-
const y = vertices[i * 2 + 1];
|
|
142
|
-
const pixelIdx = y * gridSize + x;
|
|
143
|
-
positions[3 * i + 0] = x * xScale + minX;
|
|
144
|
-
positions[3 * i + 1] = -y * yScale + maxY;
|
|
145
|
-
positions[3 * i + 2] = terrain[pixelIdx];
|
|
146
|
-
texCoords[2 * i + 0] = x / width;
|
|
147
|
-
texCoords[2 * i + 1] = y / height;
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
POSITION: { value: positions, size: 3 },
|
|
151
|
-
TEXCOORD_0: { value: texCoords, size: 2 }
|
|
152
|
-
// NORMAL: {}, - optional, but creates the high poly look with lighting
|
|
153
|
-
};
|
|
154
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VERSION = void 0;
|
|
4
|
-
// Version constant cannot be imported, it needs to correspond to the build version of **this** module.
|
|
5
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
exports.VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QuantizedMeshLoader = void 0;
|
|
4
|
-
const version_1 = require("./lib/utils/version");
|
|
5
|
-
/**
|
|
6
|
-
* Worker loader for quantized meshes
|
|
7
|
-
*/
|
|
8
|
-
exports.QuantizedMeshLoader = {
|
|
9
|
-
name: 'Quantized Mesh',
|
|
10
|
-
id: 'quantized-mesh',
|
|
11
|
-
module: 'terrain',
|
|
12
|
-
version: version_1.VERSION,
|
|
13
|
-
worker: true,
|
|
14
|
-
extensions: ['terrain'],
|
|
15
|
-
mimeTypes: ['application/vnd.quantized-mesh'],
|
|
16
|
-
options: {
|
|
17
|
-
'quantized-mesh': {
|
|
18
|
-
bounds: [0, 0, 1, 1],
|
|
19
|
-
skirtHeight: null
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
package/dist/terrain-loader.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TerrainLoader = void 0;
|
|
4
|
-
const version_1 = require("./lib/utils/version");
|
|
5
|
-
/**
|
|
6
|
-
* Worker loader for image encoded terrain
|
|
7
|
-
*/
|
|
8
|
-
exports.TerrainLoader = {
|
|
9
|
-
name: 'Terrain',
|
|
10
|
-
id: 'terrain',
|
|
11
|
-
module: 'terrain',
|
|
12
|
-
version: version_1.VERSION,
|
|
13
|
-
worker: true,
|
|
14
|
-
extensions: ['png', 'pngraw', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'],
|
|
15
|
-
mimeTypes: ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp'],
|
|
16
|
-
options: {
|
|
17
|
-
terrain: {
|
|
18
|
-
tesselator: 'auto',
|
|
19
|
-
bounds: undefined,
|
|
20
|
-
meshMaxError: 10,
|
|
21
|
-
elevationDecoder: {
|
|
22
|
-
rScaler: 1,
|
|
23
|
-
gScaler: 0,
|
|
24
|
-
bScaler: 0,
|
|
25
|
-
offset: 0
|
|
26
|
-
},
|
|
27
|
-
skirtHeight: undefined
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|