/// <summary> /// RenderableObject abstract member (needed) /// OBS: Worker thread (don't update UI directly from this thread) /// </summary> public override void Initialize(DrawArgs drawArgs) { if (!IsVisible(drawArgs.WorldCamera)) { return; } if (meshFileName.StartsWith("http")) { Uri meshuri = new Uri(meshFileName); string meshpath = meshuri.AbsolutePath; string extension = Path.GetExtension(meshpath); //download online mesh files to cache and //update meshfilename to new name if (meshuri.Scheme == Uri.UriSchemeHttp || meshuri.Scheme == Uri.UriSchemeHttps) { try { // Offline check if (World.Settings.WorkOffline) { throw new Exception("Offline mode active."); } WebDownload request = new WebDownload(meshFileName); string cachefilename = request.GetHashCode() + extension; //HACK: Hard Coded Path cachefilename = Directory.GetParent(System.Windows.Forms.Application.ExecutablePath) + "//Cache//Models//" + cachefilename; if (!File.Exists(cachefilename)) { request.DownloadFile(cachefilename); } meshFileName = cachefilename; } catch (Exception caught) { Utility.Log.Write(caught); errorMsg = "Failed to download mesh from " + meshFileName; } } } string ext = Path.GetExtension(meshFileName); try { lock (m_thisLock) { if (m_meshTable.ContainsKey(meshFileName)) { m_meshTableElem = m_meshTable[meshFileName]; m_meshTableElem.referenceCount++; m_meshElems = m_meshTableElem.meshElems; } else { if (ext.Equals(".x")) { LoadDirectXMesh(drawArgs); } else if (ext.Equals(".dae") || ext.Equals(".xml")) { LoadColladaMesh(drawArgs); } // if mesh loaded then add to the mesh table if (m_meshElems != null) { m_meshTableElem = new MeshTableElem(); m_meshTableElem.meshFilePath = meshFileName; m_meshTableElem.meshElems = m_meshElems; m_meshTableElem.referenceCount = 1; m_meshTable.Add(meshFileName, m_meshTableElem); } } } if (m_meshElems == null) { throw new InvalidMeshException(); } //vertExaggeration = World.Settings.VerticalExaggeration; //if (m_isElevationRelativeToGround == true) // currentElevation = World.TerrainAccessor.GetElevationAt(Latitude, Longitude); if (refreshTimer == null && m_refreshurl != null) { refreshTimer = new System.Timers.Timer(60000); refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed); refreshTimer.Start(); } isInitialized = true; } catch (Exception caught) { Utility.Log.Write(caught); errorMsg = "Failed to read mesh from " + meshFileName; } }