Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 54 55 | import getAccessorByteStride from "./getAccessorByteStride.js";
import getComponentReader from "./getComponentReader.js";
import numberOfComponentsForType from "./numberOfComponentsForType.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) {
const byteStride = getAccessorByteStride(gltf, accessor);
const componentTypeByteLength = ComponentDatatype.getSizeInBytes(
accessor.componentType,
);
const numberOfComponents = numberOfComponentsForType(accessor.type);
const count = accessor.count;
const values = new Array(numberOfComponents * count);
if (!defined(accessor.bufferView)) {
return values.fill(0);
}
const bufferView = gltf.bufferViews[accessor.bufferView];
const source = gltf.buffers[bufferView.buffer].extras._pipeline.source;
let byteOffset =
accessor.byteOffset + bufferView.byteOffset + source.byteOffset;
const dataView = new DataView(source.buffer);
const components = new Array(numberOfComponents);
const componentReader = getComponentReader(accessor.componentType);
for (let i = 0; i < count; ++i) {
componentReader(
dataView,
byteOffset,
numberOfComponents,
componentTypeByteLength,
components,
);
for (let j = 0; j < numberOfComponents; ++j) {
values[i * numberOfComponents + j] = components[j];
}
byteOffset += byteStride;
}
return values;
}
export default readAccessorPacked;
|