diff --git a/scripts_unity/Editor/GeoTilePrefabImporter.cs b/scripts_unity/Editor/GeoTilePrefabImporter.cs index 22761fa..3b2f933 100644 --- a/scripts_unity/Editor/GeoTilePrefabImporter.cs +++ b/scripts_unity/Editor/GeoTilePrefabImporter.cs @@ -399,15 +399,12 @@ public class GeoTilePrefabImporter : EditorWindow ApplyOrthoTexture(terrainData, tile.TileId); } - // Create root GameObject with Terrain - var root = new GameObject(tile.TileId); - var terrain = root.AddComponent(); - terrain.terrainData = terrainData; + // Create root GameObject with Terrain (ensures prefab contains the terrain asset) + var root = Terrain.CreateTerrainGameObject(terrainData); + root.name = tile.TileId; + var terrain = root.GetComponent(); terrain.drawInstanced = true; - var collider = root.AddComponent(); - collider.terrainData = terrainData; - // Store metadata as component for later use var metadata = root.AddComponent(); metadata.tileId = tile.TileId; @@ -507,6 +504,7 @@ public class GeoTilePrefabImporter : EditorWindow instance.name = "Buildings"; instance.transform.SetParent(root.transform, false); instance.transform.localPosition = new Vector3(0f, -(float)tile.GlobalMin, 0f); + instance.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); instance.isStatic = true; } @@ -529,11 +527,10 @@ public class GeoTilePrefabImporter : EditorWindow // Tree GLB vertices use absolute elevation (z_ground from DGM). // Since prefab root will be at Y=gmin when placed, offset trees by -gmin // so tree world Y = gmin + (-gmin) + GLB_Y = GLB_Y (correct absolute elevation) - // Scale Z by -1 to correct coordinate system mismatch (Python negates Z in export) var treesContainer = new GameObject("Trees"); treesContainer.transform.SetParent(root.transform, false); treesContainer.transform.localPosition = new Vector3(0f, -(float)tile.GlobalMin, 0f); - treesContainer.transform.localScale = new Vector3(1f, 1f, -1f); + treesContainer.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); treesContainer.isStatic = true; foreach (var chunkPath in chunkFiles) @@ -934,28 +931,3 @@ public class GeoTilePrefabImporter : EditorWindow #endregion } - -/// -/// Component attached to tile prefab roots to store geo metadata. -/// Useful for positioning prefabs in scene or querying tile info at runtime. -/// -public class GeoTileMetadata : MonoBehaviour -{ - public string tileId; - public double xmin; - public double ymin; - public double globalMin; - public double globalMax; - - /// - /// Returns the world position this tile should be placed at, given a global origin. - /// - public Vector3 GetWorldPosition(double originX, double originY) - { - return new Vector3( - (float)(xmin - originX), - (float)globalMin, - (float)(ymin - originY) - ); - } -} diff --git a/scripts_unity/GeoDataUtils/GeoTileMetadata.cs b/scripts_unity/GeoDataUtils/GeoTileMetadata.cs new file mode 100644 index 0000000..e48e676 --- /dev/null +++ b/scripts_unity/GeoDataUtils/GeoTileMetadata.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +/// +/// Component attached to tile prefab roots to store geo metadata. +/// Useful for positioning prefabs in scene or querying tile info at runtime. +/// +public class GeoTileMetadata : MonoBehaviour +{ + public string tileId; + public double xmin; + public double ymin; + public double globalMin; + public double globalMax; + + /// + /// Returns the world position this tile should be placed at, given a global origin. + /// + public Vector3 GetWorldPosition(double originX, double originY) + { + return new Vector3( + (float)(xmin - originX), + (float)globalMin, + (float)(ymin - originY) + ); + } +}