Skip to content
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

When used as a library, return a Promise #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/obj23dtiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,8 @@ var options = {
outputDirectory : outputDirectory
};

obj23dtiles(objPath, outputPath, options);
console.time('Total');
obj23dtiles(objPath, outputPath, options)
.then(() => {
console.timeEnd('Total');
});
26 changes: 5 additions & 21 deletions lib/obj23dtiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module.exports = obj23dtiles;
obj23dtiles.combine = combine;

function obj23dtiles(objPath, outputPath, options) {
console.time('Total');

if(typeof options.tilesetOptions === 'string') {
options.tilesetOptions = fsExtra.readJsonSync(options.tilesetOptions);
Expand All @@ -29,7 +28,7 @@ function obj23dtiles(objPath, outputPath, options) {
options.batchId = true;
options.b3dm = true;

obj2Tileset(objPath, outputPath, options)
return obj2Tileset(objPath, outputPath, options)
.then(function(result) {
var b3dm = result.b3dm;
var batchTableJson = result.batchTableJson;
Expand All @@ -49,9 +48,6 @@ function obj23dtiles(objPath, outputPath, options) {
tasks.push(fsExtra.writeJson(tilesetPath, tileset, {spaces: 2}));
return Promise.all(tasks);
})
.then(function() {
console.timeEnd('Total');
})
.catch(function(error) {
console.log(error.message || error);
process.exit(1);
Expand All @@ -64,7 +60,7 @@ function obj23dtiles(objPath, outputPath, options) {
process.exit(1);
}

obj2Tileset(objPath, outputPath, options)
return obj2Tileset(objPath, outputPath, options)
.then(function(result) {
var i3dm = result.i3dm;
var batchTableJson = result.batchTableJson;
Expand All @@ -84,9 +80,6 @@ function obj23dtiles(objPath, outputPath, options) {
tasks.push(fsExtra.writeJson(tilesetPath, tileset, {spaces: 2}));
return Promise.all(tasks);
})
.then(function() {
console.timeEnd('Total');
})
.catch(function(error) {
console.log(error.message || error);
process.exit(1);
Expand All @@ -96,7 +89,7 @@ function obj23dtiles(objPath, outputPath, options) {
else if (options && options.b3dm) {
options.binary = true;
options.batchId = true;
obj2B3dm(objPath, options)
return obj2B3dm(objPath, options)
.then(function(result){
var b3dm = result.b3dm;
var batchTableJson = result.batchTableJson;
Expand All @@ -109,9 +102,6 @@ function obj23dtiles(objPath, outputPath, options) {
fsExtra.ensureDirSync(path.dirname(outputPath));
return fsExtra.outputFile(outputPath, b3dm);
})
.then(function() {
console.timeEnd('Total');
})
.catch(function(error) {
console.log(error.message || error);
process.exit(1);
Expand All @@ -124,7 +114,7 @@ function obj23dtiles(objPath, outputPath, options) {
console.log('Convert to i3dm need a custom FeatureTable.');
process.exit(1);
}
obj2I3dm(objPath, options)
return obj2I3dm(objPath, options)
.then(function(result){
var i3dm = result.i3dm;
var batchTableJson = result.batchTableJson;
Expand All @@ -137,16 +127,13 @@ function obj23dtiles(objPath, outputPath, options) {
fsExtra.ensureDirSync(path.dirname(outputPath));
return fsExtra.outputFile(outputPath, i3dm);
})
.then(function() {
console.timeEnd('Total');
})
.catch(function(error) {
console.log(error.message || error);
process.exit(1);
});
}
else {
obj2gltf(objPath, options)
return obj2gltf(objPath, options)
.then(function(result){
var gltf = result.gltf;
if (options && options.binary) {
Expand All @@ -158,9 +145,6 @@ function obj23dtiles(objPath, outputPath, options) {
};
return fsExtra.outputJson(outputPath, gltf, jsonOptions);
})
.then(function() {
console.timeEnd('Total');
})
.catch(function(error) {
console.log(error.message || error);
process.exit(1);
Expand Down