@@ -54,15 +54,20 @@ private static final class TargetAndStream {
5454 }
5555
5656 private final Map <String , TargetAndStream > tile2Target = new HashMap <String , TargetAndStream >();
57+ private String tilesetPath ;
58+ private boolean generateMeta = false ;
5759
5860
5961 private TiledObjTargetProvider (int zLevel , MapProjection mapProjection ,
60- File tilesFolder , File mtlFile , PrintStream mtlStream ) {
62+ File tilesFolder , File mtlFile , PrintStream mtlStream ,
63+ String tilesetPath ) {
6164 this .zLevel = zLevel ;
6265 this .tilesFolder = tilesFolder .getParentFile ();
6366 this .mtlFile = mtlFile ;
6467 this .mtlStream = mtlStream ;
6568 this .mapProjection = mapProjection ;
69+ this .tilesetPath = tilesetPath ;
70+ this .generateMeta = (tilesetPath != null );
6671 }
6772
6873 @ Override
@@ -183,60 +188,46 @@ public void close() {
183188 for (Entry <String , TargetAndStream > entry : this .tile2Target .entrySet ()) {
184189 TargetAndStream t = entry .getValue ();
185190 t .pstream .close ();
186-
187- JSONObject meta = new JSONObject ();
188-
189- AxisAlignedBoundingBoxXZ tileBBOX =
190- tile2boundingBox (Integer .valueOf (1 ), Integer .valueOf (2 ), Integer .valueOf (0 ));
191-
192- AxisAlignedBoundingBoxXZ union = AxisAlignedBoundingBoxXZ .union (t .boundingVolume , tileBBOX );
193191
194- double [] region = encodeRegion (t .minY , t .maxY , union );
195-
196- if (fullBBOX == null ) {
197- fullBBOX = union ;
198- }
199- else {
200- fullBBOX = AxisAlignedBoundingBoxXZ .union (union , fullBBOX );
192+ if (generateMeta ) {
193+ fullBBOX = generateMetaInfoForTile (children , entry .getKey (), t , fullBBOX );
201194 }
195+
202196 minY = Math .min (t .minY , minY );
203197 maxY = Math .max (t .maxY , maxY );
204-
205- meta .put ("boundingVolume" , new JSONObject ());
206- meta .getJSONObject ("boundingVolume" ).put ("region" , new JSONArray (region ));
207-
208- double diag = (t .boundingVolume .sizeX () + t .boundingVolume .sizeZ ()) / 2 ;
209- meta .put ("geometricError" , diag );
210-
211- JSONObject content = new JSONObject ();
212- double [] contentRegion = encodeRegion (t .minY , t .maxY , t .boundingVolume );
213-
214- content .put ("url" , entry .getKey () + ".b3dm" );
215- content .put ("boundingVolume" , new JSONObject ());
216- content .getJSONObject ("boundingVolume" ).put ("region" , new JSONArray (contentRegion ));
217-
218- meta .put ("content" , content );
219- children .put (meta );
220198 }
221199
200+ if (generateMeta ) {
201+ writeTileset (fullBBOX , minY , maxY , tileset , children );
202+ }
203+ }
204+
205+ private void writeTileset (AxisAlignedBoundingBoxXZ fullBBOX , double minY , double maxY ,
206+ JSONObject tileset , JSONArray children ) {
207+ File tilesetFile = new File (this .tilesetPath );
208+
222209 File metaFile = new File (this .tilesFolder .getPath () +
223- File .separator + "tileset.json" );
210+ File .separator + this .tilesetPath );
211+
212+ if (tilesetFile .isAbsolute ()) {
213+ metaFile = tilesetFile ;
214+ }
224215
225216 tileset .put ("asset" , new JSONObject ().put ("version" , "0.0" ));
226217
227-
228218 JSONObject rootJson = new JSONObject ().put (
229219 "boundingVolume" , new JSONObject ().put (
230220 "region" , encodeRegion (minY , maxY , fullBBOX )));
231-
221+
232222 LatLon origin = this .mapProjection .getOrigin ();
233223 VectorXYZ cartesianOrigin = WGS84Util .cartesianFromLatLon (origin , 0.0 );
234224 double [] transform = WGS84Util .eastNorthUpToFixedFrame (cartesianOrigin );
235225
236226 rootJson .put ("transform" , new JSONArray (transform ));
237227
238228 tileset .put ("root" , rootJson );
239- double extentDiagonal = (fullBBOX .sizeX () + fullBBOX .sizeZ ()) / 2 ;
229+ double extentDiagonal = (fullBBOX .sizeX () + fullBBOX .sizeZ ()) / 20 ;
230+
240231 tileset .put ("geometricError" , extentDiagonal );
241232 rootJson .put ("refine" , "add" );
242233 rootJson .put ("children" , children );
@@ -253,6 +244,42 @@ public void close() {
253244 }
254245 }
255246
247+ private AxisAlignedBoundingBoxXZ generateMetaInfoForTile (JSONArray children ,
248+ String tms , TargetAndStream t , AxisAlignedBoundingBoxXZ fullBBOX ) {
249+ JSONObject meta = new JSONObject ();
250+
251+ AxisAlignedBoundingBoxXZ tileBBOX =
252+ tile2boundingBox (Integer .valueOf (1 ), Integer .valueOf (2 ), Integer .valueOf (0 ));
253+
254+ AxisAlignedBoundingBoxXZ union = AxisAlignedBoundingBoxXZ .union (t .boundingVolume , tileBBOX );
255+
256+ double [] region = encodeRegion (t .minY , t .maxY , union );
257+
258+ if (fullBBOX == null ) {
259+ fullBBOX = union ;
260+ }
261+ else {
262+ fullBBOX = AxisAlignedBoundingBoxXZ .union (union , fullBBOX );
263+ }
264+
265+ meta .put ("boundingVolume" , new JSONObject ());
266+ meta .getJSONObject ("boundingVolume" ).put ("region" , new JSONArray (region ));
267+
268+ meta .put ("geometricError" , t .maxY );
269+
270+ JSONObject content = new JSONObject ();
271+ double [] contentRegion = encodeRegion (t .minY , t .maxY , t .boundingVolume );
272+
273+ content .put ("url" , tms + ".b3dm" );
274+ content .put ("boundingVolume" , new JSONObject ());
275+ content .getJSONObject ("boundingVolume" ).put ("region" , new JSONArray (contentRegion ));
276+
277+ meta .put ("content" , content );
278+ children .put (meta );
279+
280+ return fullBBOX ;
281+ }
282+
256283 private double [] encodeRegion (double minY , double maxY , AxisAlignedBoundingBoxXZ union ) {
257284 VectorXZ bottomRight = union .bottomRight ();
258285 VectorXZ topLeft = union .topLeft ();
@@ -320,7 +347,7 @@ public static final void writeObjFileTiled(
320347 final File objDirectory , MapData mapData ,
321348 final MapProjection mapProjection ,
322349 Camera camera , Projection projection ,
323- int tilesZoomLevel )
350+ int tilesZoomLevel , String tilesetPath )
324351 throws IOException {
325352
326353 if (!objDirectory .getParentFile ().exists ()) {
@@ -341,7 +368,8 @@ public static final void writeObjFileTiled(
341368
342369 /* create iterator which creates and wraps .obj files as needed */
343370 TargetProvider <RenderableToObj > targetProvider =
344- new TiledObjTargetProvider (tilesZoomLevel , mapProjection , objDirectory , mtlFile , mtlStream );
371+ new TiledObjTargetProvider (tilesZoomLevel ,
372+ mapProjection , objDirectory , mtlFile , mtlStream , tilesetPath );
345373
346374 /* write file content */
347375
0 commit comments