You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
2.1 KiB
JavaScript
54 lines
2.1 KiB
JavaScript
import Ellipsoid from "../Core/Ellipsoid.js";
|
|
import HeightmapEncoding from "../Core/HeightmapEncoding.js";
|
|
import HeightmapTessellator from "../Core/HeightmapTessellator.js";
|
|
import Rectangle from "../Core/Rectangle.js";
|
|
import RuntimeError from "../Core/RuntimeError.js";
|
|
import Lerc from "../ThirdParty/LercDecode.js";
|
|
import createTaskProcessorWorker from "./createTaskProcessorWorker.js";
|
|
|
|
function createVerticesFromHeightmap(parameters, transferableObjects) {
|
|
// LERC encoded buffers must be decoded, then we can process them like normal
|
|
if (parameters.encoding === HeightmapEncoding.LERC) {
|
|
var result;
|
|
try {
|
|
result = Lerc.decode(parameters.heightmap);
|
|
} catch (error) {
|
|
throw new RuntimeError(error);
|
|
}
|
|
|
|
var lercStatistics = result.statistics[0];
|
|
if (lercStatistics.minValue === Number.MAX_VALUE) {
|
|
throw new RuntimeError("Invalid tile data");
|
|
}
|
|
|
|
parameters.heightmap = result.pixels[0];
|
|
parameters.width = result.width;
|
|
parameters.height = result.height;
|
|
}
|
|
|
|
parameters.ellipsoid = Ellipsoid.clone(parameters.ellipsoid);
|
|
parameters.rectangle = Rectangle.clone(parameters.rectangle);
|
|
|
|
var statistics = HeightmapTessellator.computeVertices(parameters);
|
|
var vertices = statistics.vertices;
|
|
transferableObjects.push(vertices.buffer);
|
|
|
|
return {
|
|
vertices: vertices.buffer,
|
|
numberOfAttributes: statistics.encoding.getStride(),
|
|
minimumHeight: statistics.minimumHeight,
|
|
maximumHeight: statistics.maximumHeight,
|
|
gridWidth: parameters.width,
|
|
gridHeight: parameters.height,
|
|
boundingSphere3D: statistics.boundingSphere3D,
|
|
orientedBoundingBox: statistics.orientedBoundingBox,
|
|
occludeePointInScaledSpace: statistics.occludeePointInScaledSpace,
|
|
encoding: statistics.encoding,
|
|
westIndicesSouthToNorth: statistics.westIndicesSouthToNorth,
|
|
southIndicesEastToWest: statistics.southIndicesEastToWest,
|
|
eastIndicesNorthToSouth: statistics.eastIndicesNorthToSouth,
|
|
northIndicesWestToEast: statistics.northIndicesWestToEast,
|
|
};
|
|
}
|
|
export default createTaskProcessorWorker(createVerticesFromHeightmap);
|