赣州市洪水风险预警系统三维版本
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
import getAccessorByteStride from './getAccessorByteStride.js'
import getComponentReader from './getComponentReader.js'
import numberOfComponentsForType from './numberOfComponentsForType.js'
import arrayFill from '../../Core/arrayFill.js'
import ComponentDatatype from '../../Core/ComponentDatatype.js'
import defined from '../../Core/defined.js'
 
    /**
     * Returns the accessor data in a contiguous array.
     *
     * @param {Object} gltf A javascript object containing a glTF asset.
     * @param {Object} accessor The accessor.
     * @returns {Array} The accessor values in a contiguous array.
     *
     * @private
     */
    function readAccessorPacked(gltf, accessor) {
        var byteStride = getAccessorByteStride(gltf, accessor);
        var componentTypeByteLength = ComponentDatatype.getSizeInBytes(accessor.componentType);
        var numberOfComponents = numberOfComponentsForType(accessor.type);
        var count = accessor.count;
        var values = new Array(numberOfComponents * count);
 
        if (!defined(accessor.bufferView)) {
            arrayFill(values, 0);
            return values;
        }
 
        var bufferView = gltf.bufferViews[accessor.bufferView];
        var source = gltf.buffers[bufferView.buffer].extras._pipeline.source;
        var byteOffset = accessor.byteOffset + bufferView.byteOffset + source.byteOffset;
 
        var dataView = new DataView(source.buffer);
        var components = new Array(numberOfComponents);
        var componentReader = getComponentReader(accessor.componentType);
 
        for (var i = 0; i < count; ++i) {
            componentReader(dataView, byteOffset, numberOfComponents, componentTypeByteLength, components);
            for (var j = 0; j < numberOfComponents; ++j) {
                values[i * numberOfComponents + j] = components[j];
            }
            byteOffset += byteStride;
        }
        return values;
    }
 
    export default readAccessorPacked;