Fix saving .bin

This commit is contained in:
Sean Lilley 2017-03-14 13:26:12 -04:00
parent d46d58fdc5
commit 998dcfe649
2 changed files with 13 additions and 2 deletions

View File

@ -110,11 +110,13 @@ function saveExternalBuffer(gltf, gltfPath) {
return Promise.resolve(gltf); return Promise.resolve(gltf);
} }
var binary = buffer.extras._obj2gltf.binary;
delete buffer.extras;
var bufferName = path.basename(gltfPath, path.extname(gltfPath)); var bufferName = path.basename(gltfPath, path.extname(gltfPath));
var bufferUri = bufferName + '.bin'; var bufferUri = bufferName + '.bin';
buffer.uri = bufferUri; buffer.uri = bufferUri;
var bufferPath = path.join(path.dirname(gltfPath), bufferUri); var bufferPath = path.join(path.dirname(gltfPath), bufferUri);
return fxExtraOutputFile(bufferPath, buffer) return fxExtraOutputFile(bufferPath, binary)
.then(function() { .then(function() {
return gltf; return gltf;
}); });

View File

@ -304,7 +304,7 @@ function createGltf(objData) {
var indexBuffer = Buffer.concat(indexBuffers); var indexBuffer = Buffer.concat(indexBuffers);
var buffer = Buffer.concat([vertexBuffer, indexBuffer]); 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; var bufferUri;
if (buffer.length <= 201326580) { if (buffer.length <= 201326580) {
bufferUri = 'data:application/octet-stream;base64,' + buffer.toString('base64'); bufferUri = 'data:application/octet-stream;base64,' + buffer.toString('base64');
@ -329,5 +329,14 @@ function createGltf(objData) {
target : WebGLConstants.ELEMENT_ARRAY_BUFFER 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; return gltf;
} }