Rotate buildings and trees in Unity importer

This commit is contained in:
2026-01-14 20:46:25 +01:00
parent 73ec27e3b7
commit 1a14a67773
4 changed files with 14 additions and 26 deletions

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 55ca6d0883f09584a888802b543d4540

View File

@@ -25,7 +25,6 @@ public class GeoTileImporter : EditorWindow
private float tileSizeMeters = 1000f;
private int heightmapResolution = 1025;
private bool flipTerrainNorthSouth = true;
private string parentName = "Geo_Terrain_Tiles";
private string buildingsParentName = "Geo_Buildings";
@@ -73,7 +72,6 @@ public class GeoTileImporter : EditorWindow
GUILayout.Label("Terrain", EditorStyles.boldLabel);
tileSizeMeters = EditorGUILayout.FloatField("Tile size (m)", tileSizeMeters);
heightmapResolution = EditorGUILayout.IntField("Heightmap resolution", heightmapResolution);
flipTerrainNorthSouth = EditorGUILayout.ToggleLeft("Flip terrain north/south", flipTerrainNorthSouth);
GUILayout.Space(10);
GUILayout.Label("Scene", EditorStyles.boldLabel);
@@ -428,11 +426,8 @@ public class GeoTileImporter : EditorWindow
if (raw.Length == w * h)
{
for (int y = 0; y < h; y++)
{
int srcY = flipTerrainNorthSouth ? (h - 1 - y) : y;
for (int x = 0; x < w; x++)
heights[y, x] = raw[srcY * w + x] / 65535f;
}
heights[y, x] = raw[y * w + x] / 65535f;
usedU16 = true;
}
}
@@ -445,11 +440,8 @@ public class GeoTileImporter : EditorWindow
{
var pixels = tex.GetPixels();
for (int y = 0; y < h; y++)
{
int srcY = flipTerrainNorthSouth ? (h - 1 - y) : y;
for (int x = 0; x < w; x++)
heights[y, x] = pixels[srcY * w + x].r;
}
heights[y, x] = pixels[y * w + x].r;
}
terrainData.SetHeights(0, 0, heights);
@@ -479,17 +471,11 @@ public class GeoTileImporter : EditorWindow
}
else
{
var orthoTileSize = flipTerrainNorthSouth
? new Vector2(tileSizeMeters, -tileSizeMeters)
: new Vector2(tileSizeMeters, tileSizeMeters);
var orthoTileOffset = flipTerrainNorthSouth
? new Vector2(0f, -tileSizeMeters)
: Vector2.zero;
var layer = new TerrainLayer
{
diffuseTexture = orthoTex,
tileSize = orthoTileSize,
tileOffset = orthoTileOffset
tileSize = new Vector2(tileSizeMeters, tileSizeMeters),
tileOffset = Vector2.zero
};
terrainData.terrainLayers = new[] { layer };
terrainData.alphamapResolution = 16;
@@ -565,12 +551,11 @@ public class GeoTileImporter : EditorWindow
continue;
}
// Note: Building GLB vertices have absolute Z (elevation) from CityGML,
// so container Y should be 0, not gmin (which would add gmin twice)
var inst = PrefabUtility.InstantiatePrefab(prefab) as GameObject ?? Instantiate(prefab);
inst.name = tileId;
inst.transform.SetParent(parent.transform, false);
inst.transform.position = new Vector3(ux, 0f, uz);
inst.transform.position = new Vector3(ux, gmin, uz);
inst.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
inst.isStatic = true;
imported++;
}
@@ -625,13 +610,10 @@ public class GeoTileImporter : EditorWindow
}
// Create container for this tile's tree chunks
// Note: Tree GLB vertices use absolute elevation (z_ground from DGM),
// so container Y should be 0, not gmin (which would add gmin twice)
// Scale Z by -1 to correct coordinate system mismatch (Python negates Z in export)
var tileContainer = new GameObject($"Trees_{tileId}");
tileContainer.transform.SetParent(parent.transform, false);
tileContainer.transform.position = new Vector3(ux, 0f, uz);
tileContainer.transform.localScale = new Vector3(1f, 1f, -1f);
tileContainer.transform.position = new Vector3(ux, gmin, uz);
tileContainer.transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
tileContainer.isStatic = true;
foreach (var chunkPath in chunkFiles)

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bfa3bad7852d10a4d9777b2471fa33b2

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3724238c12c2fccb284b3651c756ff19