GLTFBinaryExtension constructor
GLTFBinaryExtension(
- ByteBuffer data
Implementation
GLTFBinaryExtension(ByteBuffer data) {
// var headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
var headerView = ByteData.view(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
this.header = {
"magic": LoaderUtils.decodeText(data.asUint8List(0, 4)),
"version": headerView.getUint32(4, Endian.host),
"length": headerView.getUint32(8, Endian.host)
};
if (this.header["magic"] != BINARY_EXTENSION_HEADER_MAGIC) {
throw ('THREE.GLTFLoader: Unsupported glTF-Binary header.');
} else if (this.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, BINARY_EXTENSION_HEADER_LENGTH);
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 == BINARY_EXTENSION_CHUNK_TYPES["JSON"]) {
var contentArray = Uint8List.view(
data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
this.content = LoaderUtils.decodeText(contentArray);
} else if (chunkType == BINARY_EXTENSION_CHUNK_TYPES["BIN"]) {
var byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
this.body = Uint8List.view(data)
.sublist(byteOffset, byteOffset + chunkLength)
.buffer;
}
// Clients must ignore chunks with unknown types.
chunkIndex += chunkLength;
}
if (this.content == null) {
throw ('THREE.GLTFLoader: JSON content not found.');
}
}