Code cleanup
This commit is contained in:
@@ -220,9 +220,9 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1274200471}
|
||||
- component: {fileID: 1274200470}
|
||||
- component: {fileID: 1274200473}
|
||||
- component: {fileID: 1274200472}
|
||||
- component: {fileID: 1274200474}
|
||||
m_Layer: 0
|
||||
m_Name: APIManager
|
||||
m_TagString: Untagged
|
||||
@@ -230,29 +230,6 @@ GameObject:
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1274200470
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1274200469}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0c03158bf19bc8c4ab178ebaee653914, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Map
|
||||
overpassUrl: https://mapz.honzuvkod.dev/api/interpreter
|
||||
queryRadiusMeters: 200
|
||||
latitude: 50.772789001464844
|
||||
longitude: 15.076871871948242
|
||||
buildingMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
|
||||
defaultFloorHeight: 3
|
||||
defaultBuildingHeight: 6
|
||||
roadMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
|
||||
defaultRoadWidth: 4
|
||||
metersPerUnit: 1
|
||||
autoStart: 1
|
||||
--- !u!4 &1274200471
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -324,6 +301,26 @@ MeshFilter:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1274200469}
|
||||
m_Mesh: {fileID: 0}
|
||||
--- !u!114 &1274200474
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1274200469}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a58b19ca2646e434ea88b8112260362b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::MapRenderer
|
||||
queryRadiusMeters: 1000
|
||||
buildingMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
|
||||
defaultFloorHeight: 3
|
||||
defaultBuildingHeight: 6
|
||||
roadMaterial: {fileID: 2100000, guid: 283cf727b4c3ac64c94d59598e221b10, type: 2}
|
||||
defaultRoadWidth: 4
|
||||
metersPerUnit: 1
|
||||
autoStart: 1
|
||||
--- !u!1 &1865882987
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -11,12 +11,12 @@ using UnityEngine.Networking;
|
||||
public class MapRenderer : MonoBehaviour
|
||||
{
|
||||
[Header("Overpass settings")]
|
||||
public string overpassUrl = "https://mapz.honzuvkod.dev/api/interpreter";
|
||||
public const string overpassUrl = "https://mapz.honzuvkod.dev/api/interpreter";
|
||||
public float queryRadiusMeters = 200f; // radius around lat/lon to query
|
||||
|
||||
[Header("Location (lat, lon)")]
|
||||
public double latitude; // example Prague
|
||||
public double longitude;
|
||||
private double latitude = 50.7727878;
|
||||
private double longitude = 15.0718625;
|
||||
|
||||
[Header("Building settings")]
|
||||
public Material buildingMaterial;
|
||||
@@ -31,35 +31,27 @@ public class MapRenderer : MonoBehaviour
|
||||
public float metersPerUnit = 1f; // scale: 1 unit = 1 meter
|
||||
public bool autoStart = true;
|
||||
|
||||
// Internal storage
|
||||
[Header("Storage")]
|
||||
Dictionary<long, Vector2> nodes = new Dictionary<long, Vector2>(); // id -> latlon
|
||||
List<Way> parsedWays = new List<Way>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (autoStart)
|
||||
StartCoroutine(GenerateForLocation(latitude, longitude));
|
||||
if (autoStart) { StartCoroutine(RenderMap()); }
|
||||
}
|
||||
|
||||
// Public entry for other scripts
|
||||
public void StartGenerating(double lat, double lon)
|
||||
public void StartGenerating()
|
||||
{
|
||||
latitude = lat; longitude = lon;
|
||||
StartCoroutine(GenerateForLocation(lat, lon));
|
||||
StartCoroutine(RenderMap());
|
||||
}
|
||||
|
||||
IEnumerator GenerateForLocation(double lat, double lon)
|
||||
IEnumerator RenderMap()
|
||||
{
|
||||
ClearChildren();
|
||||
|
||||
// compute bbox from radius
|
||||
float degPerMeter = 1f / 111000f; // approximate
|
||||
double delta = queryRadiusMeters * degPerMeter;
|
||||
double south = lat - delta;
|
||||
double north = lat + delta;
|
||||
double west = lon - delta;
|
||||
double east = lon + delta;
|
||||
//TODO: GPS update
|
||||
|
||||
string q = $"[out:xml][timeout:25];(way[\"building\"]({south.ToString().Replace(",",".")},{west.ToString().Replace(",", ".")},{north.ToString().Replace(",", ".")},{east.ToString().Replace(",", ".")});way[\"highway\"]({south.ToString().Replace(",", ".")},{west.ToString().Replace(",", ".")},{north.ToString().Replace(",", ".")},{east.ToString().Replace(",", ".")}););(._;>;);out body;";
|
||||
string q = $"[out:xml][timeout:90];(way[\"building\"](around:{queryRadiusMeters.ToString().Replace(",", ".")},{latitude.ToString().Replace(",", ".")},{longitude.ToString().Replace(",", ".")});way[\"highway\"](around:{queryRadiusMeters.ToString().Replace(",", ".")},{latitude.ToString().Replace(",", ".")},{longitude.ToString().Replace(",", ".")}););(._;>;);out body;";
|
||||
|
||||
WWWForm form = new WWWForm();
|
||||
form.AddField("data", q);
|
||||
@@ -78,14 +70,12 @@ public class MapRenderer : MonoBehaviour
|
||||
string xml = www.downloadHandler.text;
|
||||
ParseOverpassXml(xml);
|
||||
|
||||
// create separate GameObjects for buildings and roads
|
||||
GameObject buildingsRoot = new GameObject("Buildings");
|
||||
buildingsRoot.transform.parent = this.transform;
|
||||
|
||||
GameObject roadsRoot = new GameObject("Roads");
|
||||
roadsRoot.transform.parent = this.transform;
|
||||
|
||||
// iterate parsed ways
|
||||
foreach (var w in parsedWays)
|
||||
{
|
||||
if (w.tags.ContainsKey("building"))
|
||||
@@ -106,7 +96,6 @@ public class MapRenderer : MonoBehaviour
|
||||
|
||||
void ClearChildren()
|
||||
{
|
||||
// remove existing generated children
|
||||
List<GameObject> toDestroy = new List<GameObject>();
|
||||
foreach (Transform t in transform)
|
||||
toDestroy.Add(t.gameObject);
|
||||
@@ -122,7 +111,7 @@ public class MapRenderer : MonoBehaviour
|
||||
public Dictionary<string, string> tags = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
List<Way> parsedWays = new List<Way>();
|
||||
|
||||
|
||||
void ParseOverpassXml(string xmlText)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ Material:
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: New Material
|
||||
m_Name: TestMaterial
|
||||
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
Reference in New Issue
Block a user