Skip to content

Commit ea1a8a6

Browse files
committed
fix bugs for node module usage
1 parent 659b7c4 commit ea1a8a6

2 files changed

Lines changed: 30 additions & 48 deletions

File tree

lib/obj23dtiles.js

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ var obj2gltf = require('./obj2gltf');
55
var obj2B3dm = require('./obj2B3dm');
66
var obj2I3dm = require('./obj2I3dm');
77
var obj2Tileset = require('./obj2Tileset');
8+
var combine = require('./combineTileset');
89

910
module.exports = obj23dtiles;
11+
obj23dtiles.combine = combine;
12+
1013
function obj23dtiles(objPath, outputPath, options) {
1114
console.time('Total');
1215

@@ -18,6 +21,12 @@ function obj23dtiles(objPath, outputPath, options) {
1821
if(typeof options.tilesetOptions === 'string') {
1922
options.tilesetOptions = fsExtra.readJsonSync(options.tilesetOptions);
2023
}
24+
if(typeof options.customBatchTable === 'string') {
25+
options.customBatchTable = fsExtra.readJsonSync(options.customBatchTable);
26+
}
27+
if (typeof options.customFeatureTable === 'string') {
28+
options.customFeatureTable = fsExtra.readJsonSync(options.customFeatureTable);
29+
}
2130

2231
obj2Tileset(objPath, outputPath, options)
2332
.then(function(result) {
@@ -43,25 +52,16 @@ function obj23dtiles(objPath, outputPath, options) {
4352
console.timeEnd('Total');
4453
})
4554
.catch(function(error) {
46-
console.log(error.message);
55+
console.log(error.message || error);
4756
process.exit(1);
4857
});
4958
} else if (options.i3dm) {
5059
options.binary = true;
5160
options.batchId = false;
52-
if(typeof options.tilesetOptions === 'string') {
53-
options.tilesetOptions = fsExtra.readJsonSync(options.tilesetOptions);
54-
}
5561
if (!options.customFeatureTable) {
5662
console.log('Convert to i3dm need a custom FeatureTable.');
5763
process.exit(1);
5864
}
59-
if (typeof options.customFeatureTable === 'string') {
60-
options.customFeatureTable = fsExtra.readJsonSync(options.customFeatureTable);
61-
}
62-
if (options.customBatchTable && typeof options.customBatchTable === 'string') {
63-
options.customBatchTable = fsExtra.readJsonSync(options.customBatchTable);
64-
}
6565

6666
obj2Tileset(objPath, outputPath, options)
6767
.then(function(result) {
@@ -87,7 +87,7 @@ function obj23dtiles(objPath, outputPath, options) {
8787
console.timeEnd('Total');
8888
})
8989
.catch(function(error) {
90-
console.log(error.message);
90+
console.log(error.message || error);
9191
process.exit(1);
9292
});
9393
}
@@ -112,7 +112,7 @@ function obj23dtiles(objPath, outputPath, options) {
112112
console.timeEnd('Total');
113113
})
114114
.catch(function(error) {
115-
console.log(error.message);
115+
console.log(error.message || error);
116116
process.exit(1);
117117
});
118118
}
@@ -123,12 +123,6 @@ function obj23dtiles(objPath, outputPath, options) {
123123
console.log('Convert to i3dm need a custom FeatureTable.');
124124
process.exit(1);
125125
}
126-
if (typeof options.customFeatureTable === 'string') {
127-
options.customFeatureTable = fsExtra.readJsonSync(options.customFeatureTable);
128-
}
129-
if (options.customBatchTable && typeof options.customBatchTable === 'string') {
130-
options.customBatchTable = fsExtra.readJsonSync(options.customBatchTable);
131-
}
132126
obj2I3dm(objPath, options)
133127
.then(function(result){
134128
var i3dm = result.i3dm;
@@ -146,7 +140,7 @@ function obj23dtiles(objPath, outputPath, options) {
146140
console.timeEnd('Total');
147141
})
148142
.catch(function(error) {
149-
console.log(error.message);
143+
console.log(error.message || error);
150144
process.exit(1);
151145
});
152146
}
@@ -167,7 +161,7 @@ function obj23dtiles(objPath, outputPath, options) {
167161
console.timeEnd('Total');
168162
})
169163
.catch(function(error) {
170-
console.log(error.message);
164+
console.log(error.message || error);
171165
process.exit(1);
172166
});
173167
}

lib/obj2b3dm.js

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
var fsExtra = require('fs-extra');
32
var createB3dm = require('./createB3dm');
43
var obj2gltf = require('./obj2gltf');
54

@@ -17,36 +16,25 @@ function obj2B3dm(objPath, options) {
1716
.then(function (result) {
1817
var glb = result.gltf;
1918
var batchTableJson = result.batchTableJson;
20-
19+
var customBatchTable = batchTableJson;
2120
return new Promise(function (resolve, reject) {
2221
if (options.customBatchTable) {
23-
return fsExtra.readJson(options.customBatchTable)
24-
.then(function (customBatchTable) {
25-
if (!(customBatchTable.batchId && customBatchTable.batchId.length === batchTableJson.batchId.length)) {
26-
reject('Custom BatchTable should have a proper "batchId" Array.');
27-
}
28-
resolve({
29-
b3dm : createB3dm({
30-
glb: glb,
31-
featureTableJson: {
32-
BATCH_LENGTH: batchTableJson.batchId.length
33-
},
34-
batchTableJson: customBatchTable
35-
}),
36-
batchTableJson : batchTableJson
37-
});
38-
});
22+
var length = options.customBatchTable[Object.keys(options.customBatchTable)[0]].length;
23+
if (length !== batchTableJson.batchId.length ) {
24+
reject('Custom BatchTable properties\'s length should be equals to default BatchTable \'batchId\' length.');
25+
}
26+
customBatchTable = options.customBatchTable;
27+
resolve({
28+
b3dm : createB3dm({
29+
glb: glb,
30+
featureTableJson: {
31+
BATCH_LENGTH: length
32+
},
33+
batchTableJson: customBatchTable
34+
}),
35+
batchTableJson : batchTableJson
36+
});
3937
}
40-
resolve({
41-
b3dm : createB3dm({
42-
glb: glb,
43-
featureTableJson: {
44-
BATCH_LENGTH: batchTableJson.batchId.length
45-
},
46-
batchTableJson: batchTableJson
47-
}),
48-
batchTableJson : batchTableJson
49-
});
5038
});
5139
});
5240
}

0 commit comments

Comments
 (0)