IEnumerator Load() { var position = gameObject.transform.position; var cartesianCoordinates = new CartesianCoordinates(position.x, position.z); GeographicCoordinates = cartesianCoordinates.TransformedWith(ModelManager.Database.Projection); if (ZipFilename == null) { MeshKey = System.IO.Path.GetFullPath(System.IO.Path.Combine(Path, FltFilename)); } else { MeshKey = System.IO.Path.Combine(System.IO.Path.GetFullPath(System.IO.Path.Combine(Path, ZipFilename)), FltFilename); } while (Meshes == null) { Meshes = MeshManager.LodForName(MeshKey); yield return(new WaitForSecondsRealtime(0.1f)); } if (Meshes.Count == 0) { gameObject.SetActive(false); yield break; } while (MaterialNames == null) { MaterialNames = MeshManager.TexturesForMeshName(MeshKey); yield return(new WaitForSecondsRealtime(0.1f)); } yield return(null); foreach (var name in MaterialNames) { string matKey = System.IO.Path.GetFullPath(System.IO.Path.Combine(Path, name)); MaterialEntries[matKey] = MaterialManager.Entry(matKey); Materials[name] = null; } yield return(null); bool done = false; while (!done) { done = true; foreach (var name in MaterialNames) { if (Materials[name] == null) { string matKey = System.IO.Path.GetFullPath(System.IO.Path.Combine(Path, name)); if (!MaterialEntries[matKey].Loaded) { done = false; break; } Materials[name] = MaterialEntries[matKey].Material; } } if (!done) { yield return(new WaitForSecondsRealtime(0.1f)); } } yield return(null); var meshFilter = gameObject.AddComponent <MeshFilter>(); CurrentLodIndex = Meshes.Count - 1; // Start at min LOD (??? - abrinton) meshFilter.mesh = Meshes[CurrentLodIndex].mesh; yield return(null); var meshEntry = MeshManager.MeshByName[MeshKey]; MeshRenderer = gameObject.AddComponent <MeshRenderer>(); if (Materials.Values.Count != 0) { // Check that the materials in question actually have textures, or we'll be assigning bad materials // and in some cases we have more materials than submeshes. List <Material> materialsToAssign = new List <Material>(); // There needs to be one material per submesh, and the mapping must be correct for (int i = 0; i < Meshes[0].mesh.subMeshCount; ++i) { int texturePatternIndex = meshEntry.submeshToTexturePatternIndex[i]; if (texturePatternIndex != -1) { materialsToAssign.Add(Materials[meshEntry.Textures[texturePatternIndex]]); } } MeshRenderer.sharedMaterials = materialsToAssign.ToArray(); } else { // Don't override single default material, just spit out a warning Debug.LogWarningFormat("no materials specified for {0}", FltFilename); } MeshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; MeshRenderer.receiveShadows = false; PropertyBlock = new MaterialPropertyBlock(); ++ModelManager.ValidCount; Loaded = true; InvokeRepeating("UpdateElevation", 1.0f, 2.0f); }