readAccessorAsUint32 function
Uint32List
readAccessorAsUint32(
- GltfAccessor accessor,
- GltfBufferView bufferView,
- Uint8List bufferData
Resolves an integer-typed accessor (used for indices and joint indices) into a Uint32List.
Implementation
Uint32List readAccessorAsUint32(
GltfAccessor accessor,
GltfBufferView bufferView,
Uint8List bufferData,
) {
final componentCount = accessor.type.componentCount;
final totalComponents = accessor.count * componentCount;
final out = Uint32List(totalComponents);
final stride =
bufferView.byteStride ?? (componentCount * accessor.componentType.bytes);
final start = bufferView.byteOffset + accessor.byteOffset;
final view = ByteData.sublistView(bufferData);
for (int i = 0; i < accessor.count; i++) {
final base = start + i * stride;
for (int c = 0; c < componentCount; c++) {
final off = base + c * accessor.componentType.bytes;
int v;
switch (accessor.componentType) {
case GltfComponentType.byte_:
v = view.getInt8(off);
case GltfComponentType.unsignedByte:
v = view.getUint8(off);
case GltfComponentType.short:
v = view.getInt16(off, Endian.little);
case GltfComponentType.unsignedShort:
v = view.getUint16(off, Endian.little);
case GltfComponentType.unsignedInt:
v = view.getUint32(off, Endian.little);
case GltfComponentType.float:
v = view.getFloat32(off, Endian.little).toInt();
}
out[i * componentCount + c] = v;
}
}
return out;
}