Skip to content

Commit

Permalink
Fix saving .bin
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Mar 14, 2017
1 parent d46d58f commit 998dcfe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ function saveExternalBuffer(gltf, gltfPath) {
return Promise.resolve(gltf);
}

var binary = buffer.extras._obj2gltf.binary;
delete buffer.extras;
var bufferName = path.basename(gltfPath, path.extname(gltfPath));
var bufferUri = bufferName + '.bin';
buffer.uri = bufferUri;
var bufferPath = path.join(path.dirname(gltfPath), bufferUri);
return fxExtraOutputFile(bufferPath, buffer)
return fxExtraOutputFile(bufferPath, binary)
.then(function() {
return gltf;
});
Expand Down
11 changes: 10 additions & 1 deletion lib/gltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function createGltf(objData) {
var indexBuffer = Buffer.concat(indexBuffers);
var buffer = Buffer.concat([vertexBuffer, indexBuffer]);

// Buffers larger than ~192MB cannot be base64 encoded due to a NodeJS limitation. Instead the buffer will be saved to a .bin file. Source: https://github.com/nodejs/node/issues/4266
// Buffers larger than ~192MB cannot be base64 encoded due to a NodeJS limitation. Source: https://github.com/nodejs/node/issues/4266
var bufferUri;
if (buffer.length <= 201326580) {
bufferUri = 'data:application/octet-stream;base64,' + buffer.toString('base64');
Expand All @@ -329,5 +329,14 @@ function createGltf(objData) {
target : WebGLConstants.ELEMENT_ARRAY_BUFFER
};

// Save the binary to be outputted as a .bin file in convert.js.
if (!defined(bufferUri)) {
gltf.buffers[bufferId].extras = {
_obj2gltf : {
binary : buffer
}
};
}

return gltf;
}

0 comments on commit 998dcfe

Please sign in to comment.