Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
optional override of subobjects with similar ID
Browse files Browse the repository at this point in the history
  • Loading branch information
sambaas committed Jan 6, 2022
1 parent 5e4304c commit d934ca5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
7 changes: 6 additions & 1 deletion TileBakeLibrary/BinaryMeshData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private Vector3Double ConvertVertex(Vector3 vertex)
return new Vector3Double(X, Y, Z);
}

public void ImportData(Tile tile)
public void ImportData(Tile tile, bool replaceExistingIDs = false)
{
origin = tile.position;
tileSize = tile.size;
Expand All @@ -151,6 +151,11 @@ public void ImportData(Tile tile)
IdentifierData identifierdata = BinaryMeshReader.ReadBinaryIdentifiers(identifierFilename);
foreach (Identifier identifier in identifierdata.identifiers)
{
if(replaceExistingIDs && tile.SubObjects.Any((subObject) => subObject.id == identifier.objectID)){
Console.WriteLine($"Replacing object with ID: {identifier.objectID}");
continue;
}

SubObject subobject = new SubObject();
subobject.id = identifier.objectID;
subobject.parentSubmeshIndex = identifier.submeshIndex;
Expand Down
27 changes: 3 additions & 24 deletions TileBakeLibrary/CityJSONToTileConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class CityJSONToTileConverter
private float lod = 0;
private string filterType = "";

public string TilingMethod = "Overlap";
public string TilingMethod = "OVERLAP"; //OVERLAP, TILED

private int tileSize = 1000;

Expand Down Expand Up @@ -179,7 +179,6 @@ public void Convert()
}

//Create a threadable task for every file, that returns a list of parsed cityobjects

Console.WriteLine($"Parsing {sourceFiles.Length} CityJSON files...");
totalFiles = sourceFiles.Length;
if (sourceFiles.Length > 0)
Expand All @@ -203,10 +202,8 @@ public void Convert()
}
);


thread.Start();


Stopwatch watch = new Stopwatch();
watch.Start();
tiles = new List<Tile>();
Expand Down Expand Up @@ -239,8 +236,6 @@ public void Convert()
}
}



private void PrepareTiles()
{
TileSubobjects();
Expand Down Expand Up @@ -306,7 +301,7 @@ private void WriteTileData()
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
Console.Write($"\rBaking {tiles.Count} tiles");
//Threaded writing of binary meshes + compression
Console.Write("\rsaving files... ");
Console.Write("\rSaving files... ");
int counter = 0;

Parallel.ForEach(tiles, tile =>
Expand All @@ -317,24 +312,11 @@ private void WriteTileData()
}
else
{
//Bake the tile, and lets save it!

//tile.Bake();

//Console.WriteLine($"Saving {tile.filePath} containing {tile.SubObjects.Count} SubObjects");

//Create binary files
//BinaryMeshWriter.Save(tile);
BinaryMeshData bmd = new BinaryMeshData();
if (tile.filePath.Contains("NaN") == false)
{
bmd.ExportData(tile);



//Compressed variant
//if (brotliCompress) BrotliCompress.Compress(tile.filePath);

//Optionaly write other format(s) for previewing purposes
if (createOBJFiles) OBJWriter.Save(tile);
}
Expand Down Expand Up @@ -374,8 +356,6 @@ public void CompressFiles()
Console.WriteLine($"Duration: {elapsedTimeString}");
}



public void SetObjectFilters(CityObjectFilter[] cityObjectFilters)
{
this.cityObjectFilters = cityObjectFilters;
Expand All @@ -387,9 +367,8 @@ public void SetObjectFilters(CityObjectFilter[] cityObjectFilters)
private void ParseExistingBinaryTile(Tile tile)
{
BinaryMeshData bmd = new BinaryMeshData();
bmd.ImportData(tile);
bmd.ImportData(tile, replaceExistingIDs);
bmd = null;

// Console.WriteLine($"Parsed existing tile {tile.filePath} with {tile.SubObjects.Count} subobjects");
}

Expand Down
2 changes: 1 addition & 1 deletion TileBakeTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ private static void StartConverting(string sourcePath, string targetPath)
tileBaker.SetClipSpikes(removeSpikes, spikeCeiling, spikeFloor);
tileBaker.SetObjectFilters(configFile.cityObjectFilters);
tileBaker.SetTileSize(configFile.tileSize);
tileBaker.TilingMethod = configFile.tilingMethod;
}
tileBaker.TilingMethod = configFile.tilingMethod;

tileBaker.Convert();
}
Expand Down

0 comments on commit d934ca5

Please sign in to comment.