赣州市洪水风险预警系统三维版本
guoshilong
2023-02-27 4d8c6dd77427e8e581fda17b6b65ba86bfb7a815
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);