GLTFBinaryExtension constructor
GLTFBinaryExtension(
- ByteBuffer data
Implementation
GLTFBinaryExtension(ByteBuffer data) {
name = gltfExtensions["KHR_BINARY_GLTF"]!;
// final headerView = DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
final headerView = ByteData.view(data, 0, behl);
header = {
"magic": LoaderUtils.decodeText(data.asUint8List(0, 4)),
"version": headerView.getUint32(4, Endian.host),
"length": headerView.getUint32(8, Endian.host)
};
if (header["magic"] != behm) {
throw ('GLTFLoader: Unsupported glTF-Binary header.');
}
else if (header["version"] < 2.0) {
throw ('GLTFLoader: Legacy binary file detected.');
}
// final chunkView = DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
ByteData chunkView = ByteData.view(data, behl);
int chunkIndex = 0;
while (chunkIndex < chunkView.lengthInBytes) {
final chunkLength = chunkView.getUint32(chunkIndex, Endian.host);
chunkIndex += 4;
final chunkType = chunkView.getUint32(chunkIndex, Endian.host);
chunkIndex += 4;
if (chunkType == bect["JSON"]) {
final contentArray = Uint8List.view(
data, behl + chunkIndex, chunkLength);
content = LoaderUtils.decodeText(contentArray);
} else if (chunkType == bect["BIN"]) {
final byteOffset = behl + chunkIndex;
body = Uint8List.view(data)
.sublist(byteOffset, byteOffset + chunkLength)
.buffer;
}
// Clients must ignore chunks with unknown types.
chunkIndex += chunkLength;
}
if (content == null) {
throw ('THREE.GLTFLoader: JSON content not found.');
}
}