// Use this for initialization IEnumerator Start() { layerMask = 1 << 8; wayList = new List<long>(); //StartCoroutine(LoadChunk(-8.6f,41.1767f,-8.55f,41.1923f)); MapChunkLoader.precision = GeoUTMConverter.Precision; GeoUTMConverter latlon2Utm = new GeoUTMConverter(); latlon2Utm.ToUTM((minimumLat+maximumLat)/2f,(minimumLon+maximumLon)/2f); transform.position = new Vector3(((float)latlon2Utm.X - offsetPositionX), -0.1f, ((float)latlon2Utm.Y - offsetPositionZ)); //GeoUTMConverter bottomLeft = new GeoUTMConverter(); //GeoUTMConverter topRight = new GeoUTMConverter(); //bottomLeft.ToUTM(minimumLat,minimumLon); //topRight.ToUTM(maximumLat,maximumLon); GameObject floor = new GameObject(); floor.name = "Ground"; floor.isStatic = true; /*GoogleElevation ge = new GoogleElevation(); ge.coordinates.Add(minimumLat); ge.coordinates.Add(minimumLon); ge.coordinates.Add(minimumLat); ge.coordinates.Add(maximumLon); ge.coordinates.Add(maximumLat); ge.coordinates.Add(maximumLon); ge.coordinates.Add(maximumLat); ge.coordinates.Add(minimumLon); */ //ge.SyncGetHeights(); //yield return StartCoroutine(ge.GetHeights()); //Mesh msh = CreateGroundWithHeights((float)(topRight.X-bottomLeft.X)/1.9f,(float)(topRight.Y-bottomLeft.Y)/1.9f,ge.heights); CreateGround cg = new CreateGround(); cg.maxLat = maximumLat + 0.001f; cg.maxLon = maximumLon + 0.001f; cg.minLat = minimumLat - 0.001f; cg.minLon = minimumLon - 0.001f; cg.numberOfDivisions = numberOfDivisions; MeshFilter mf = floor.AddComponent<MeshFilter>(); mf.mesh = cg.GetGroundMesh() ; MeshRenderer mr = floor.AddComponent<MeshRenderer>(); mr.material = groundMaterial; floor.transform.position = transform.position; floor.transform.parent = transform; floor.layer = LayerMask.NameToLayer("RayCast"); MeshCollider m = floor.AddComponent<MeshCollider>(); yield return StartCoroutine(LoadChunk(minimumLon,minimumLat,maximumLon,maximumLat)); }
// Use this for initialization IEnumerator Start() { Loom.Current.GetComponent<Loom>(); layerMask = 1 << 8; wayList = new List<long>(); //StartCoroutine(LoadChunk(-8.6f,41.1767f,-8.55f,41.1923f)); MapChunkLoader.precision = GeoUTMConverter.Precision; GeoUTMConverter latlon2Utm = new GeoUTMConverter(); latlon2Utm.ToUTM((minimumLat+maximumLat)/2f,(minimumLon+maximumLon)/2f); transform.position = new Vector3(((float)latlon2Utm.X - offsetPositionX), -0.1f, ((float)latlon2Utm.Y - offsetPositionZ)); GameObject floor = new GameObject(); floor.name = "Ground"; floor.isStatic = true; CreateGround cg = new CreateGround(); cg.maxLat = maximumLat + 0.01f * (maximumLat - minimumLat); //0.0001f; cg.maxLon = maximumLon + 0.01f * (maximumLat - minimumLat); cg.minLat = minimumLat - 0.01f * (maximumLat - minimumLat); cg.minLon = minimumLon - 0.01f * (maximumLat - minimumLat); cg.numberOfDivisions = numberOfDivisions; MeshFilter mf = floor.AddComponent<MeshFilter>(); MeshRenderer mr = floor.AddComponent<MeshRenderer>(); mr.material = groundMaterial; floor.transform.position = transform.position; floor.transform.parent = transform; floor.layer = LayerMask.NameToLayer("RayCast"); string floorPath = Application.persistentDataPath + "Assets/Resources/Objs/" + cg.maxLat + "I" + cg.maxLon + ".obj"; if (!File.Exists(floorPath)) // If the file isn't cached we calculate everything and then we cache it { mf.sharedMesh = cg.GetGroundMesh(); if (exportObjs) { ObjExporter oe = new ObjExporter(); oe.MeshToFile(mf, floorPath); } } else { ObjImporter oi = new ObjImporter(); StartCoroutine(oi.FileToMesh("file://" + floorPath)); while (oi._myMesh == null) { yield return null; } mf.sharedMesh = oi._myMesh; Debug.LogWarning("Loaded Ground Chunk from cache"); } //Texture2D t = new Texture2D(1024, 1024); MapTexture mt = new MapTexture(); mt.getTexture(cg.minLon.ToString(), cg.minLat.ToString(), cg.maxLon.ToString(), cg.maxLat.ToString(),Application.persistentDataPath,mr.material); while (mt.texture == null) { yield return null; } //t.LoadImage(mt.ReadFully(mt.mq_dataStream)); //mr.material.SetTexture("_MainTex", t); MeshCollider m = floor.AddComponent<MeshCollider>(); Loom l = Loom.Current; LoadChunk(minimumLon, minimumLat, maximumLon, maximumLat); //StartCoroutine(); }