void SetMaterial(MSceneObject mo, string sMaterialID) { if (sMaterialID == null) { sMaterialID = MMaterial.DEFAULT_MATERIAL; } //MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID); MObject o = MScene.MaterialRoot.FindModuleByName(sMaterialID); MMaterial mat = null; if (o != null && o.Type == MObject.EType.Material) { mat = (MMaterial)o; if (mat != null) { mo.SetMaterial(mat); mat.MaterialID = sMaterialID; } } if (MassiveTools.IsURL(sMaterialID)) { mat = (MMaterial) new MMaterial("URLShader"); MShader DefaultShader = (MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER); mat.AddShader(DefaultShader); mat.ReplaceTexture(Globals.TexturePool.GetTexture(sMaterialID)); mat.MaterialID = sMaterialID; MScene.MaterialRoot.Add(mat); mo.SetMaterial(mat); mo.material.Setup(); } }
private void Network_TextureHandler(object sender, Massive.Events.TextureEvent e) { MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID); MObject o = MScene.MaterialRoot.FindModuleByName(e.TextureID); if (o != null && o.Type == MObject.EType.Material) { MMaterial mat = (MMaterial)o; mo.SetMaterial(mat); } else { if (MassiveTools.IsURL(e.TextureID)) { MMaterial mat = (MMaterial) new MMaterial("URLShader"); MShader DefaultShader = (MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER); mat.AddShader(DefaultShader); mat.ReplaceTexture(Globals.TexturePool.GetTexture(e.TextureID)); MScene.MaterialRoot.Add(mat); mo.SetMaterial(mat); mo.material.Setup(); MMessageBus.ChangedTexture(this, e.InstanceID, e.TextureID); } else { Console.WriteLine("Object " + e.InstanceID + " was null"); MMessageBus.Error(this, "Could not find Material:" + e.TextureID); } } }
private void AstroBodies_SelectedIndexChanged(object sender, EventArgs e) { CurrentBody = (MAstroBody)AstroBodies.SelectedItem; //string sPath = string sPath = CurrentBody.TextureName; if (MassiveTools.IsURL(sPath)) { string cache = MassiveTools.GetCachePath(sPath); if (!File.Exists(cache)) { return; } bmp = Image.FromFile(cache); MapBox.BackgroundImage = bmp; } else { bmp = Image.FromFile(Path.Combine(MFileSystem.AssetsPath, CurrentBody.TextureName)); MapBox.BackgroundImage = bmp; } }
private void Bw_DoWork(object sender, DoWorkEventArgs e) { while ((Globals.ApplicationExiting == false) && (done == false)) { if (Current == null) { if (Downloads.Count > 0) { Current = Downloads[0]; if (Current != null) { if (MassiveTools.IsURL(Current.Filename)) { if (File.Exists(Current.CacheFilename)) { //Console.WriteLine("Cache hit:" + Current.Filename + " -> " + Current.CacheFilename); } else { Globals.Log(this, "Downloading:" + Current.Filename); DownloadFromURL(); } Current.LoadTextureData(Current.CacheFilename); } else { if (File.Exists(Current.Filename)) { Current.LoadTextureData(Current.Filename); } else { string sAbsolute = Path.Combine(MFileSystem.AssetsPath, Current.Filename); if (File.Exists(sAbsolute)) { Current.LoadTextureData(sAbsolute); } else { Current.Error = "File not found " + Current.Filename; } } } Downloads.RemoveAt(0); if (Current.DataIsReady == true) { Current.DoAssign = true; //tell the texture to upload to the GPU on next GUI cycle Current = null; } else { //was there a problem? place at the end of the queue to try again //Downloads.Add(Current); Current = null; } Thread.Sleep(30); } } else { done = true; } } } Current = null; _worker = null; }