Move GeoTileMetadata out of Editor scripts

This commit is contained in:
s0wlz (Matthias Puchstein)
2026-01-14 21:07:54 +01:00
parent d2b1bd9eb6
commit d7023a57af
2 changed files with 32 additions and 34 deletions

View File

@@ -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>();
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>();
terrain.drawInstanced = true;
var collider = root.AddComponent<TerrainCollider>();
collider.terrainData = terrainData;
// Store metadata as component for later use
var metadata = root.AddComponent<GeoTileMetadata>();
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
}
/// <summary>
/// Component attached to tile prefab roots to store geo metadata.
/// Useful for positioning prefabs in scene or querying tile info at runtime.
/// </summary>
public class GeoTileMetadata : MonoBehaviour
{
public string tileId;
public double xmin;
public double ymin;
public double globalMin;
public double globalMax;
/// <summary>
/// Returns the world position this tile should be placed at, given a global origin.
/// </summary>
public Vector3 GetWorldPosition(double originX, double originY)
{
return new Vector3(
(float)(xmin - originX),
(float)globalMin,
(float)(ymin - originY)
);
}
}

View File

@@ -0,0 +1,26 @@
using UnityEngine;
/// <summary>
/// Component attached to tile prefab roots to store geo metadata.
/// Useful for positioning prefabs in scene or querying tile info at runtime.
/// </summary>
public class GeoTileMetadata : MonoBehaviour
{
public string tileId;
public double xmin;
public double ymin;
public double globalMin;
public double globalMax;
/// <summary>
/// Returns the world position this tile should be placed at, given a global origin.
/// </summary>
public Vector3 GetWorldPosition(double originX, double originY)
{
return new Vector3(
(float)(xmin - originX),
(float)globalMin,
(float)(ymin - originY)
);
}
}