Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated getBinaryGltf for gltfs with special characters #253

Merged
merged 5 commits into from
Apr 6, 2017

Conversation

likangning93
Copy link
Contributor

getBinaryGltf used to have a problem where gltfs with special characters would cause weird byte offset issues, since the stringified gltf's string length wouldn't be the same as the byte length.

var sceneString = JSON.stringify(gltf);
var sceneLength = Buffer.byteLength(sceneString);
sceneLength += 4 - (sceneLength % 4);
var padding = new Array(sceneLength + 1).join(' ');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure if there was a reason for the padding to be so big before, and then get sliced down to size. Any insights?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either...

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 93.805% when pulling 44bd46d on glbSpecialChars into bf401ef on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 93.804% when pulling 0376a1b on glbSpecialChars into bf401ef on master.

var sceneLength = sceneBuffer.length;
var paddingLength = 4 - (sceneLength % 4); // pad out to 4 bytes as per glb specification
sceneLength += paddingLength;
var paddingBuffer = new Buffer(paddingLength).fill(' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Buffer.alloc(paddingLength, ' ') instead. We should avoid new Buffer throughout but that can be a sweeping change handled later.

var paddingLength = 4 - (sceneLength % 4); // pad out to 4 bytes as per glb specification
sceneLength += paddingLength;
var paddingBuffer = new Buffer(paddingLength).fill(' ');
var scene = (Buffer.concat([sceneBuffer, paddingBuffer]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the outer parentheses.

var sceneString = JSON.stringify(gltf);
var sceneLength = Buffer.byteLength(sceneString);
sceneLength += 4 - (sceneLength % 4);
var padding = new Array(sceneLength + 1).join(' ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either...

@likangning93
Copy link
Contributor Author

@lilleyse updated! Looks like a texture compression test is failing to finish in time though.

@@ -120,18 +120,18 @@ function getBinaryGltf(gltf, embed, embedImage) {

// Create padded binary scene buffer and calculate total length
var sceneString = JSON.stringify(gltf);
var sceneBuffer = new Buffer(sceneString);
var sceneBuffer = Buffer.alloc(Buffer.byteLength(sceneString), sceneString);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Buffer.from(string) instead

@coveralls
Copy link

Coverage Status

Coverage increased (+0.001%) to 93.804% when pulling fd4ae6a on glbSpecialChars into bf401ef on master.

@likangning93
Copy link
Contributor Author

@lilleyse yayyy updated and everything passes!

@lilleyse lilleyse merged commit 6914f5f into master Apr 6, 2017
@lilleyse lilleyse deleted the glbSpecialChars branch April 6, 2017 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants