UNPKG

nanogl-gltf

Version:
45 lines (44 loc) 2.04 kB
import GltfTypes from "../types/GltfTypes"; import { BaseAccessor, getArrayForDataType } from "./Accessor"; import Assert from "../lib/assert"; /** * The AccessorSparseValues element is an Accessor that contains the new values of the vertices that are sparse. */ export default class AccessorSparseValues extends BaseAccessor { constructor() { super(...arguments); this.gltftype = GltfTypes.ACCESSOR_SPARSE_VALUES; } /** * Parse the AccessorSparseValues data, load the BufferView element and store only the part that is needed in _array attribute. * * Is async as it needs to wait for the BufferView to be created. * @param gltfLoader GLTFLoader to use * @param data Data to parse */ async parse(gltfLoader, data) { var _a, _b; const sparseData = data.elementParent; const accessorData = sparseData.elementParent; this.byteOffset = (_a = data.byteOffset) !== null && _a !== void 0 ? _a : 0; this.count = sparseData.count; this.normalized = (_b = accessorData.normalized) !== null && _b !== void 0 ? _b : false; this.componentType = accessorData.componentType; this.type = accessorData.type; this.sparse = null; this.bufferView = await gltfLoader.getElement(GltfTypes.BUFFERVIEW, data.bufferView); const Arr = getArrayForDataType(this.componentType); if (this.bufferView.byteStride === 0) { this._stride = this.numComps * this.bytesPerElem; this._strideElem = this.numComps; } else { this._stride = this.bufferView.byteStride; this._strideElem = this._stride / Arr.BYTES_PER_ELEMENT; Assert.isTrue(this._strideElem === Math.round(this._strideElem)); } this._array = new Arr(this.bufferView.buffer._bytes, this.byteOffset + this.bufferView.getByteOffset(), this.count * this._strideElem); this._valueHolder = this.createElementHolder(); return Promise.resolve(); } }