Question about B3DM padding
wsw0108 opened this issue · 1 comments
wsw0108 commented
Spec says: The binary glTF must start and end on an 8-byte boundary
.
So I encode b3dm file with below code:
inline void encodeB3DM(const std::vector<uint8_t>& glb, std::vector<uint8_t>& data) {
size_t tableLength = 0;
size_t byteLength = 28 + tableLength;
size_t glbPre, glbPost;
align8(byteLength, glbPre);
align8(glb.size(), glbPost);
// glbPre = 0;
byteLength += glbPre + glb.size() + glbPost;
endian::Little::put_s8(data, 'b');
endian::Little::put_s8(data, '3');
endian::Little::put_s8(data, 'd');
endian::Little::put_s8(data, 'm');
endian::Little::put_u32(data, 1); // version
endian::Little::put_u32(data, uint32_t(byteLength)); // byteLength
endian::Little::put_u32(data, 0); // featureTableJSONByteLength
endian::Little::put_u32(data, 0); // featureTableBinaryByteLength
endian::Little::put_u32(data, 0); // batchTableJSONByteLength
endian::Little::put_u32(data, 0); // batchTableBinaryByteLength
for (auto i = 0; i < glbPre; i++) {
endian::Little::put_u8(data, 0);
}
data.insert(data.end(), glb.cbegin(), glb.cend());
for (auto i = 0; i < glbPost; i++) {
endian::Little::put_u8(data, 0);
}
}
glbPre
shoule be 4
, but the generated b3dm file failed to load using CesiumJS 1.99, the error is something like glTF is not valid JSON
.
And if I uncomment the line // glbPre = 0;
, the generated b3dm will be loaded success.
wsw0108 commented
close it because FeatureTable
is matantory.