From 1a14a67773de1305855072955c055b1723a9d5af Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Wed, 14 Jan 2026 20:46:25 +0100 Subject: [PATCH] Rotate buildings and trees in Unity importer --- scripts_unity/Editor/GeoBoundsDebug.cs.meta | 2 ++ scripts_unity/Editor/GeoTileImporter.cs | 34 +++++-------------- scripts_unity/Editor/GeoTileImporter.cs.meta | 2 ++ .../Editor/GeoTilePrefabImporter.cs.meta | 2 ++ 4 files changed, 14 insertions(+), 26 deletions(-) create mode 100644 scripts_unity/Editor/GeoBoundsDebug.cs.meta create mode 100644 scripts_unity/Editor/GeoTileImporter.cs.meta create mode 100644 scripts_unity/Editor/GeoTilePrefabImporter.cs.meta diff --git a/scripts_unity/Editor/GeoBoundsDebug.cs.meta b/scripts_unity/Editor/GeoBoundsDebug.cs.meta new file mode 100644 index 0000000..a849124 --- /dev/null +++ b/scripts_unity/Editor/GeoBoundsDebug.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 55ca6d0883f09584a888802b543d4540 diff --git a/scripts_unity/Editor/GeoTileImporter.cs b/scripts_unity/Editor/GeoTileImporter.cs index 33b494d..482f7ac 100644 --- a/scripts_unity/Editor/GeoTileImporter.cs +++ b/scripts_unity/Editor/GeoTileImporter.cs @@ -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) diff --git a/scripts_unity/Editor/GeoTileImporter.cs.meta b/scripts_unity/Editor/GeoTileImporter.cs.meta new file mode 100644 index 0000000..ef094e7 --- /dev/null +++ b/scripts_unity/Editor/GeoTileImporter.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: bfa3bad7852d10a4d9777b2471fa33b2 \ No newline at end of file diff --git a/scripts_unity/Editor/GeoTilePrefabImporter.cs.meta b/scripts_unity/Editor/GeoTilePrefabImporter.cs.meta new file mode 100644 index 0000000..86e1d92 --- /dev/null +++ b/scripts_unity/Editor/GeoTilePrefabImporter.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 3724238c12c2fccb284b3651c756ff19 \ No newline at end of file