Skip to content

Commit

Permalink
Pad GLB data to 8 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Oct 12, 2022
1 parent 3042a1c commit 15a45ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/createB3dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ function createB3dm(options) {
}

function createB3dmCurrent(glb, featureTableJson, featureTableBinary, batchTableJson, batchTableBinary) {

const glbPadded = getBufferPadded(glb);

const version = 1;
const headerByteLength = 28;
const featureTableJsonByteLength = featureTableJson.length;
const featureTableBinaryByteLength = featureTableBinary.length;
const batchTableJsonByteLength = batchTableJson.length;
const batchTableBinaryByteLength = batchTableBinary.length;
const gltfByteLength = glb.length;
const gltfByteLength = glbPadded.length;
const byteLength = headerByteLength + featureTableJsonByteLength + featureTableBinaryByteLength + batchTableJsonByteLength + batchTableBinaryByteLength + gltfByteLength;

const header = Buffer.alloc(headerByteLength);
Expand All @@ -65,7 +68,7 @@ function createB3dmCurrent(glb, featureTableJson, featureTableBinary, batchTable
header.writeUInt32LE(batchTableJsonByteLength, 20);
header.writeUInt32LE(batchTableBinaryByteLength, 24);

return Buffer.concat([header, featureTableJson, featureTableBinary, batchTableJson, batchTableBinary, glb]);
return Buffer.concat([header, featureTableJson, featureTableBinary, batchTableJson, batchTableBinary, glbPadded]);
}

function createB3dmDeprecated1(glb, batchLength, batchTableJson) {
Expand Down
5 changes: 3 additions & 2 deletions lib/createI3dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ function createI3dm(options) {

const gltfFormat = defined(options.glb) ? 1 : 0;
const gltfBuffer = defined(options.glb) ? options.glb : getGltfUriBuffer(options.uri);
const gltfBufferPadded = getBufferPadded(gltfBuffer);

const featureTableJsonByteLength = featureTableJson.length;
const featureTableBinaryByteLength = featureTableBinary.length;
const batchTableJsonByteLength = batchTableJson.length;
const batchTableBinaryByteLength = batchTableBinary.length;
const gltfByteLength = gltfBuffer.length;
const gltfByteLength = gltfBufferPadded.length;
const byteLength = headerByteLength + featureTableJsonByteLength + featureTableBinaryByteLength + batchTableJsonByteLength + batchTableBinaryByteLength + gltfByteLength;

const header = Buffer.alloc(headerByteLength);
Expand All @@ -48,7 +49,7 @@ function createI3dm(options) {
header.writeUInt32LE(batchTableBinaryByteLength, 24);
header.writeUInt32LE(gltfFormat, 28);

return Buffer.concat([header, featureTableJson, featureTableBinary, batchTableJson, batchTableBinary, gltfBuffer]);
return Buffer.concat([header, featureTableJson, featureTableBinary, batchTableJson, batchTableBinary, gltfBufferPadded]);
}

function getGltfUriBuffer(uri) {
Expand Down

0 comments on commit 15a45ea

Please sign in to comment.