-
Notifications
You must be signed in to change notification settings - Fork 250
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
Fix bug where gltfPipeline was not writingSources in all cases #94
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
'use strict'; | ||
var async = require('async'); | ||
var addDefaults = require('./addDefaults'); | ||
var addPipelineExtras = require('./addPipelineExtras'); | ||
var removeUnused = require('./removeUnused'); | ||
|
@@ -16,6 +17,7 @@ var loadGltfUris = require('./loadGltfUris'); | |
var quantizeAttributes = require('./quantizeAttributes'); | ||
var cacheOptimizeIndices = require('./cacheOptimizeIndices'); | ||
var encodeImages = require('./encodeImages'); | ||
var writeSource = require('./writeSource'); | ||
var Cesium = require('cesium'); | ||
var defaultValue = Cesium.defaultValue; | ||
|
||
|
@@ -26,13 +28,27 @@ module.exports = { | |
processFileToDisk : processFileToDisk | ||
}; | ||
|
||
function writeSources(gltf, callback) { | ||
var embed = true; | ||
var embedImage = true; | ||
async.each(['buffers', 'images', 'shaders'], function(name, asyncCallback) { | ||
writeSource(gltf, undefined, name, embed, embedImage, asyncCallback); | ||
}, function() { | ||
callback(); | ||
}); | ||
} | ||
|
||
function processJSON(gltf, options, callback) { | ||
addPipelineExtras(gltf); | ||
loadGltfUris(gltf, options, function(err, gltf) { | ||
if (err) { | ||
throw err; | ||
} | ||
processJSONWithExtras(gltf, options, callback); | ||
processJSONWithExtras(gltf, options, function(gltf) { | ||
writeSources(gltf, function() { | ||
callback(gltf); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
|
@@ -66,7 +82,9 @@ function processJSONWithExtras(gltfWithExtras, options, callback) { | |
function processFile(inputPath, options, callback) { | ||
readGltf(inputPath, options, function(gltf) { | ||
processJSONWithExtras(gltf, options, function(gltf) { | ||
callback(gltf); | ||
writeSources(gltf, function() { | ||
callback(gltf); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
@@ -84,14 +102,22 @@ function writeFile(gltf, outputPath, options, callback) { | |
} | ||
|
||
function processJSONToDisk(gltf, outputPath, options, callback) { | ||
processJSON(gltf, options, function(gltf) { | ||
writeFile(gltf, outputPath, options, callback); | ||
addPipelineExtras(gltf); | ||
loadGltfUris(gltf, options, function(err, gltf) { | ||
if (err) { | ||
throw err; | ||
} | ||
processJSONWithExtras(gltf, options, function(gltf) { | ||
writeFile(gltf, outputPath, options, callback); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change here and in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can change back to its original version now, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, these functions can't use |
||
}); | ||
} | ||
|
||
function processFileToDisk(inputPath, outputPath, options, callback) { | ||
processFile(inputPath, options, function(gltf) { | ||
writeFile(gltf, outputPath, options, callback); | ||
readGltf(inputPath, options, function(gltf) { | ||
processJSONWithExtras(gltf, options, function(gltf) { | ||
writeFile(gltf, outputPath, options, callback); | ||
}); | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,19 +107,43 @@ describe('gltfPipeline', function() { | |
createDirectory : false | ||
}; | ||
readGltf(gltfPath, options, function(gltf) { | ||
var options = { basePath : path.dirname(gltfPath) }; | ||
processJSONToDisk(gltf, outputPath, options, function() { | ||
expect(path.normalize(spy.calls.first().args[0])).toEqual(path.normalize('./output/')); | ||
expect(path.normalize(spy.calls.first().args[0])).toEqual(path.normalize('output/output')); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('will write sources from JSON', function(done) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test and the other may not be needed based on the comments above. |
||
var options = {}; | ||
readGltf(gltfEmbeddedPath, options, function (gltf) { | ||
var initialUri = gltf['buffers'].CesiumTexturedBoxTest.uri; | ||
processJSON(gltf, options, function () { | ||
var finalUri = gltf['buffers'].CesiumTexturedBoxTest.uri; | ||
expect(initialUri).not.toEqual(finalUri); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initial uri will be a filepath to the .bin file, so the comparison will always pass. A quick fix for these 2 tests is to read from |
||
done(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these two tests it's more accurate to compare the data uris since we are checking that it wrote the data back to those. |
||
}); | ||
}); | ||
}); | ||
|
||
it('will write sources from file', function(done) { | ||
var options = {}; | ||
readGltf(gltfEmbeddedPath, options, function (gltf) { | ||
var initialUri = gltf['buffers'].CesiumTexturedBoxTest.uri; | ||
processFile(gltfEmbeddedPath, options, function (gltfFinal) { | ||
var finalUri = gltfFinal['buffers'].CesiumTexturedBoxTest.uri; | ||
expect(initialUri).not.toEqual(finalUri); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('will add image processing extras if this is a pipeline with image processing', function(done) { | ||
var options = { | ||
imageProcess: true | ||
imageProcess : true | ||
}; | ||
readGltf(gltfEmbeddedPath, options, function(gltf) { | ||
var gltfCopy = clone(gltf); | ||
processJSON(gltf, options, function (gltf) { | ||
expect(gltf).toBeDefined(); | ||
var images = gltf.images; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a callback for when the async finishes, and instead you should send in
asyncCallback
towriteSource
. Check out howwriteGltf
handles this.