Skip to content

Commit

Permalink
Merge branch 'master' into diffuse-texture-alpha-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 22, 2017
2 parents 883c4ab + 9684790 commit 1a76402
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 132 deletions.
15 changes: 6 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var fsExtra = require('fs-extra');
var gulp = require('gulp');
var gulpJshint = require('gulp-jshint');
var Jasmine = require('jasmine');
var JasmineSpecReporter = require('jasmine-spec-reporter');
var jasmineSpecReporter = require('jasmine-spec-reporter');
var open = require('open');
var path = require('path');
var Promise = require('bluebird');
Expand All @@ -16,9 +16,6 @@ var defined = Cesium.defined;
var DeveloperError = Cesium.DeveloperError;
var argv = yargs.argv;

var fsExtraReadFile = Promise.promisify(fsExtra.readFile);
var fsExtraOutputFile = Promise.promisify(fsExtra.outputFile);

// Add third-party node module binaries to the system path
// since some tasks need to call them directly.
var environmentSeparator = process.platform === 'win32' ? ';' : ':';
Expand Down Expand Up @@ -67,7 +64,7 @@ gulp.task('test', function (done) {
// Travis runs Ubuntu 12.04.5 which has glibc 2.15, while crunch requires glibc 2.22 or higher
excludeCompressedTextures(jasmine);
}
jasmine.addReporter(new JasmineSpecReporter({
jasmine.addReporter(new jasmineSpecReporter.SpecReporter({
displaySuccessfulSpec: !defined(argv.suppressPassed) || !argv.suppressPassed
}));
jasmine.execute();
Expand Down Expand Up @@ -292,12 +289,12 @@ gulp.task('build-cesium', function () {
};
Promise.map(files, function(fileName) {
var filePath = path.join(basePath, fileName);
return fsExtraReadFile(filePath)
return fsExtra.readFile(filePath)
.then(function(buffer) {
var source = buffer.toString();
source = amdify(source, subDependencyMapping);
var outputPath = path.join(outputDir, fileName);
return fsExtraOutputFile(outputPath, source);
return fsExtra.outputFile(outputPath, source);
});
});
});
Expand All @@ -310,12 +307,12 @@ gulp.task('build-cesium-combine', function () {
];
Promise.map(files, function(fileName) {
var filePath = path.join(basePath, fileName);
return fsExtraReadFile(filePath)
return fsExtra.readFile(filePath)
.then(function(buffer) {
var source = buffer.toString();
source = combine(source);
var outputPath = path.join(outputDir, fileName);
return fsExtraOutputFile(outputPath, source);
return fsExtra.outputFile(outputPath, source);
});
});
});
16 changes: 6 additions & 10 deletions lib/compressTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ var Promise = require('bluebird');
var uuid = require('uuid');
var getTempDirectory = require('./getTempDirectory');

Jimp.prototype.getBufferAsync = Promise.promisify(Jimp.prototype.getBuffer);
var fsExtraEnsureDir = Promise.promisify(fsExtra.ensureDir);
var fxExtraReadFile = Promise.promisify(fsExtra.readFile);
var fsExtraRemove = Promise.promisify(fsExtra.remove);
fsExtra.writeFileAsync = Promise.promisify(fsExtra.writeFile);
var jimpGetBuffer = Promise.promisify(Jimp.prototype.getBuffer);

var CesiumMath = Cesium.Math;
var combine = Cesium.combine;
Expand Down Expand Up @@ -177,7 +173,7 @@ function compressTexture(gltf, imageId, options) {
}
}

return fsExtraEnsureDir(tempDirectory)
return Promise.resolve(fsExtra.ensureDir(tempDirectory))
.then(function() {
if (compressRaw) {
// Save the raw image as a png and then send to the compression tool
Expand All @@ -191,7 +187,7 @@ function compressTexture(gltf, imageId, options) {
}
})
.finally(function() {
return fsExtraRemove(tempDirectory);
return fsExtra.remove(tempDirectory);
});
}

Expand Down Expand Up @@ -227,7 +223,7 @@ function createProcess(compressToolPath, options) {

function compressJimpImage(jimpImage, tempDirectory, compressFunction, options) {
// Encode image as png since this is supported by all the compress tools
return jimpImage.getBufferAsync(Jimp.MIME_PNG)
return jimpGetBuffer.call(jimpImage, Jimp.MIME_PNG)
.then(function(buffer) {
return compressBuffer(buffer, '.png', tempDirectory, compressFunction, options);
});
Expand All @@ -236,7 +232,7 @@ function compressJimpImage(jimpImage, tempDirectory, compressFunction, options)
function compressBuffer(buffer, extension, tempDirectory, compressFunction, options) {
// Save temporary image file off to a temp directory
var inputPath = getTempImagePath(tempDirectory, extension);
return fsExtra.writeFileAsync(inputPath, buffer)
return fsExtra.writeFile(inputPath, buffer)
.then(function() {
return compressFile(inputPath, tempDirectory, compressFunction, options);
});
Expand All @@ -249,7 +245,7 @@ function compressFile(inputPath, tempDirectory, compressFunction, options) {
function runCompressTool(path, options, outputPath) {
return createProcess(path, options)
.then(function () {
return fxExtraReadFile(outputPath);
return fsExtra.readFile(outputPath);
});
}

Expand Down
5 changes: 1 addition & 4 deletions lib/directoryExists.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
'use strict';
var fsExtra = require('fs-extra');
var Promise = require('bluebird');

var fsExtraStat = Promise.promisify(fsExtra.stat);

module.exports = directoryExists;

/**
* @private
*/
function directoryExists(directory) {
return fsExtraStat(directory)
return fsExtra.stat(directory)
.then(function(stats) {
return stats.isDirectory();
})
Expand Down
4 changes: 2 additions & 2 deletions lib/encodeImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var Jimp = require('jimp');
var Promise = require('bluebird');

Jimp.prototype.getBufferAsync = Promise.promisify(Jimp.prototype.getBuffer);
var jimpGetBuffer = Promise.promisify(Jimp.prototype.getBuffer);

module.exports = encodeImages;

Expand Down Expand Up @@ -53,7 +53,7 @@ function encodeImages(gltf) {

function loadImageSource(pipelineExtras, mime) {
var image = pipelineExtras.jimpImage;
return image.getBufferAsync(mime)
return jimpGetBuffer.call(image, mime)
.then(function(imageBuffer) {
pipelineExtras.source = imageBuffer;
});
Expand Down
6 changes: 2 additions & 4 deletions lib/loadGltfUris.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var Cesium = require('cesium');
var Jimp = require('jimp');
var Promise = require('bluebird');
var dataUriToBuffer = require('data-uri-to-buffer');
var fs = require('fs');
var fsExtra = require('fs-extra');
var path = require('path');

var defined = Cesium.defined;
Expand All @@ -12,8 +12,6 @@ var DeveloperError = Cesium.DeveloperError;

var isDataUri = require('./isDataUri');

var fsReadFile = Promise.promisify(fs.readFile);

module.exports = loadGltfUris;

/**
Expand Down Expand Up @@ -142,7 +140,7 @@ function isTransparent(image) {
}

function readFromFile(object, name, uriPath) {
return fsReadFile(uriPath)
return fsExtra.readFile(uriPath)
.then(function(data) {
if (name === 'shaders') {
object.extras._pipeline.source = data.toString();
Expand Down
7 changes: 3 additions & 4 deletions lib/readGltf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Cesium = require('cesium');
var fs = require('fs');
var fsExtra = require('fs-extra');
var path = require('path');
var Promise = require('bluebird');

Expand All @@ -12,8 +12,6 @@ var parseBinaryGltf = require('./parseBinaryGltf');
var addPipelineExtras = require('./addPipelineExtras');
var loadGltfUris = require('./loadGltfUris');

var fsReadFile = Promise.promisify(fs.readFile);

module.exports = readGltf;

/**
Expand All @@ -39,7 +37,8 @@ function readGltf(gltfPath, options) {
if (fileExtension !== '.glb' && fileExtension !== '.gltf') {
throw new DeveloperError('Invalid glTF file.');
}
return fsReadFile(gltfPath)

return Promise.resolve(fsExtra.readFile(gltfPath))
.then(function(data) {
var gltf;
if (fileExtension === '.glb') {
Expand Down
4 changes: 1 addition & 3 deletions lib/writeBinaryGltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ var DeveloperError = Cesium.DeveloperError;
var getBinaryGltf = require('./getBinaryGltf');
var writeSource = require('./writeSource');

fsExtra.outputFileAsync = Promise.promisify(fsExtra.outputFile);

module.exports = writeBinaryGltf;

/**
Expand Down Expand Up @@ -71,6 +69,6 @@ function writeBinaryGltf(gltf, options) {
.then(function() {
var glbData = getBinaryGltf(gltf, embed, embedImage);
var glb = glbData.glb;
return fsExtra.outputFileAsync(outputPath, glb);
return fsExtra.outputFile(outputPath, glb);
});
}
4 changes: 1 addition & 3 deletions lib/writeGltf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ var DeveloperError = Cesium.DeveloperError;
var removePipelineExtras = require('./removePipelineExtras');
var writeSource = require('./writeSource');

fsExtra.outputJsonAsync = Promise.promisify(fsExtra.outputJson);

module.exports = writeGltf;

/**
Expand Down Expand Up @@ -72,6 +70,6 @@ function writeGltf(gltf, options) {
return Promise.all(writeSources)
.then(function() {
removePipelineExtras(gltf);
return fsExtra.outputJsonAsync(outputPath, gltf);
return fsExtra.outputJson(outputPath, gltf);
});
}
4 changes: 1 addition & 3 deletions lib/writeSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ var Promise = require('bluebird');
var defaultValue = Cesium.defaultValue;
var defined = Cesium.defined;

var fsOutputFile = Promise.promisify(fsExtra.outputFile);

module.exports = writeSource;

/**
Expand Down Expand Up @@ -38,7 +36,7 @@ function writeSource(objects, name, basePath, embed, embedImage) {
var fileName = defaultValue(pipelineExtras.name, id) + extension;
object.uri = fileName;
var outputPath = path.join(basePath, fileName);
promises.push(fsOutputFile(outputPath, source));
promises.push(fsExtra.outputFile(outputPath, source));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
"clone": "^2.1.0",
"data-uri-to-buffer": "^0.0.4",
"deep-equal": "^1.0.1",
"fs-extra": "^1.0.0",
"fs-extra": "^3.0.1",
"image-size": "^0.5.0",
"jimp": "^0.2.27",
"jsonpath": "^0.2.9",
"mime": "^1.3.4",
"uuid": "^3.0.1",
"yargs": "^6.5.0"
"yargs": "^8.0.1"
},
"devDependencies": {
"coveralls": "^2.11.15",
"gulp": "^3.9.1",
"gulp-jshint": "^2.0.4",
"istanbul": "^0.4.5",
"jasmine": "^2.5.2",
"jasmine-spec-reporter": "^2.7.0",
"jasmine-spec-reporter": "^4.1.0",
"jsdoc": "^3.4.3",
"jshint": "^2.9.4",
"jshint-stylish": "^2.2.1",
Expand Down
11 changes: 3 additions & 8 deletions specs/lib/NodeHelpersSpec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
'use strict';
var Cesium = require('cesium');
var Promise = require('bluebird');
var clone = require('clone');
var fs = require('fs');
var fsExtra = require('fs-extra');

var Matrix4 = Cesium.Matrix4;
var CesiumMath = Cesium.Math;

var fsReadFile = Promise.promisify(fs.readFile);

var NodeHelpers = require('../../lib/NodeHelpers');
var fiveBoxPath = './specs/data/combineObjects/fiveBox.gltf';

Expand Down Expand Up @@ -177,7 +174,7 @@ describe('NodeHelpers', function() {
});

it('performs operations per primitive in a scene', function(done) {
fsReadFile(fiveBoxPath)
fsExtra.readFile(fiveBoxPath)
.then(function(data) {
var gltf = JSON.parse(data);
var scene = gltf.scenes[gltf.scene];
Expand All @@ -204,9 +201,7 @@ describe('NodeHelpers', function() {

done();
})
.catch(function(err) {
throw err;
});
.catch(done.fail);
});

it('maps meshes to nodes', function() {
Expand Down
12 changes: 5 additions & 7 deletions specs/lib/PipelineSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ var processJSON = Pipeline.processJSON;
var processJSONToDisk = Pipeline.processJSONToDisk;
var processJSONWithExtras = Pipeline.processJSONWithExtras;

var fsExtraReadFile = Promise.promisify(fsExtra.readFile);

var gltfPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.gltf';
var gltfEmbeddedPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTestEmbedded.gltf';
var glbPath = './specs/data/boxTexturedUnoptimized/CesiumTexturedBoxTest.glb';
Expand All @@ -25,7 +23,7 @@ var outputGlbPath = './output/CesiumTexturedBoxTest.glb';
describe('Pipeline', function() {
it('optimizes a gltf JSON with embedded resources', function(done) {
var gltfCopy;
expect(fsExtraReadFile(gltfEmbeddedPath)
expect(fsExtra.readFile(gltfEmbeddedPath)
.then(function(data) {
var gltf = JSON.parse(data);
gltfCopy = clone(gltfCopy);
Expand All @@ -43,7 +41,7 @@ describe('Pipeline', function() {
basePath : path.dirname(gltfPath)
};
var gltfCopy;
expect(fsExtraReadFile(gltfPath, options)
expect(fsExtra.readFile(gltfPath, options)
.then(function(data) {
var gltf = JSON.parse(data);
gltfCopy = clone(gltfCopy);
Expand Down Expand Up @@ -85,7 +83,7 @@ describe('Pipeline', function() {
});

it('will write a file to the correct directory', function(done) {
var spy = spyOn(fsExtra, 'outputJsonAsync').and.callFake(function() {});
var spy = spyOn(fsExtra, 'outputJson').and.callFake(function() {});
var options = {
createDirectory : false
};
Expand All @@ -99,7 +97,7 @@ describe('Pipeline', function() {
});

it('will write a binary file', function(done) {
var spy = spyOn(fsExtra, 'outputFileAsync').and.callFake(function() {});
var spy = spyOn(fsExtra, 'outputFile').and.callFake(function() {});
var options = {
binary : true,
createDirectory : false
Expand All @@ -115,7 +113,7 @@ describe('Pipeline', function() {
});

it('will write a file from JSON', function(done) {
var spy = spyOn(fsExtra, 'outputJsonAsync').and.callFake(function() {});
var spy = spyOn(fsExtra, 'outputJson').and.callFake(function() {});
var processOptions = {
createDirectory : false,
basePath : path.dirname(gltfPath)
Expand Down
Loading

0 comments on commit 1a76402

Please sign in to comment.