Skip to content

Commit

Permalink
when used as a library, return a Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
addam committed Jun 3, 2022
1 parent 181b186 commit d93fb65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
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

0 comments on commit d93fb65

Please sign in to comment.