CesiumGS / 3d-tiles

Specification for streaming massive heterogeneous 3D geospatial datasets :earth_americas:
2.04k stars 459 forks source link

Question about B3DM padding #724

Closed wsw0108 closed 1 year ago

wsw0108 commented 1 year ago

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. G9C}5URTVYQV~ L0R0~@Z}M

And if I uncomment the line // glbPre = 0;, the generated b3dm will be loaded success.

wsw0108 commented 1 year ago

close it because FeatureTable is matantory.