mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2025-03-03 06:51:43 -05:00
Fix saving .bin
This commit is contained in:
parent
d46d58fdc5
commit
998dcfe649
@ -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;
|
||||
});
|
||||
|
11
lib/gltf.js
11
lib/gltf.js
@ -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');
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user