GLTFBinaryExtension constructor
GLTFBinaryExtension(
- ByteBuffer data
Implementation
GLTFBinaryExtension(ByteBuffer data) {
name = gltfExtensions["KHR_BINARY_GLTF"]!;
// var headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
var headerView = ByteData.view(data, 0, binaryExtensionHeaderLength);
header = {
"magic": LoaderUtils.decodeText(data.asUint8List(0, 4)),
"version": headerView.getUint32(4, Endian.host),
"length": headerView.getUint32(8, Endian.host)
};
if (header["magic"] != binaryExtensionHeaderMagic) {
throw ('THREE.GLTFLoader: Unsupported glTF-Binary header.');
} else if (header["version"] < 2.0) {
throw ('THREE.GLTFLoader: Legacy binary file detected.');
}
// var chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
var chunkView = ByteData.view(data, binaryExtensionHeaderLength);
var chunkIndex = 0;
while (chunkIndex < chunkView.lengthInBytes) {
var chunkLength = chunkView.getUint32(chunkIndex, Endian.host);
chunkIndex += 4;
var chunkType = chunkView.getUint32(chunkIndex, Endian.host);
chunkIndex += 4;
if (chunkType == binaryExtensionChunksTypes["JSON"]) {
var contentArray = Uint8List.view(data, binaryExtensionHeaderLength + chunkIndex, chunkLength);
content = LoaderUtils.decodeText(contentArray);
} else if (chunkType == binaryExtensionChunksTypes["BIN"]) {
var byteOffset = binaryExtensionHeaderLength + 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.');
}
}