private void RemoveMaterialInFace(Primitive.TextureEntryFace face) { UUID id = face.MaterialID; if (id == UUID.Zero) { return; } lock (materialslock) { if (!m_Materials.ContainsKey(id)) { return; } else { m_MaterialsRefCount[id]--; if (m_MaterialsRefCount[id] <= 0) { FaceMaterial oldFaceMat = m_Materials[id]; m_changed.Remove(oldFaceMat); m_Materials.Remove(id); m_MaterialsRefCount.Remove(id); m_cache.Expire(id.ToString()); } } } }
public bool Delete(string id) { if (m_Cache != null) { m_Cache.Expire(id); } bool result = false; if (IsHG(id)) { result = m_HGService.Delete(id); } else { result = m_GridService.Delete(id); } if (result && m_Cache != null) { m_Cache.Expire(id); } return(result); }
public bool Delete(string id) { if (m_Cache != null) { m_Cache.Expire(id); } return(m_AssetService.Delete(id)); }
public virtual bool Delete(string id) { m_Cache?.Expire(id); if (m_ServerURI == null) { return(false); } string uri = m_ServerURI + "/assets/" + id; return(SynchronousRestObjectRequester.MakeRequest <int, bool>("DELETE", uri, 0, m_Auth)); }
public bool Delete(string id) { string uri = MapServer(id) + "/assets/" + id; if (SynchronousRestObjectRequester.MakeRequest <int, bool>("DELETE", uri, 0, m_Auth)) { if (m_Cache != null) { m_Cache.Expire(id); } return(true); } return(false); }
/// <summary> /// Delete an asset /// </summary> /// <param name="id"></param> /// <returns></returns> public bool Delete(string id) { if (String.IsNullOrEmpty(m_serverUrl)) { m_log.Error("[SIMIAN ASSET CONNECTOR]: No AssetServerURI configured"); throw new InvalidOperationException(); } if (m_cache != null) { m_cache.Expire(id); } return(SimianDeleteOperation(id)); }
private void EventManager_OnBackup(ISimulationDataService datastore, bool forcedBackup) { List <FaceMaterial> toStore = null; lock (materialslock) { if (m_storeBusy && !forcedBackup) { return; } if (m_changed.Count == 0) { if (forcedBackup) { return; } UUID id; int throttle = 0; while (delayedDelete.Count > 0 && throttle < 5) { id = delayedDelete.Dequeue(); if (m_Materials.ContainsKey(id)) { if (m_MaterialsRefCount[id] <= 0) { m_Materials.Remove(id); m_MaterialsRefCount.Remove(id); m_cache.Expire(id.ToString()); ++throttle; } } } return; } if (forcedBackup) { toStore = new List <FaceMaterial>(m_changed.Keys); m_changed.Clear(); } else { toStore = new List <FaceMaterial>(); double storetime = Util.GetTimeStamp() - 30.0; foreach (KeyValuePair <FaceMaterial, double> kvp in m_changed) { if (kvp.Value < storetime) { toStore.Add(kvp.Key); } } foreach (FaceMaterial fm in toStore) { m_changed.Remove(fm); } } } if (toStore.Count > 0) { m_storeBusy = true; if (forcedBackup) { foreach (FaceMaterial fm in toStore) { AssetBase a = MakeAsset(fm, false); m_scene.AssetService.Store(a); } m_storeBusy = false; } else { Util.FireAndForget(delegate { foreach (FaceMaterial fm in toStore) { AssetBase a = MakeAsset(fm, false); m_scene.AssetService.Store(a); } m_storeBusy = false; }); } } }
public string RenderMaterialsPutCap(string request, UUID agentID) { OSDMap req = (OSDMap)OSDParser.DeserializeLLSDXml(request); OSDMap resp = new OSDMap(); OSDMap materialsFromViewer = null; OSDArray respArr = new OSDArray(); HashSet <SceneObjectPart> parts = new HashSet <SceneObjectPart>(); if (req.ContainsKey("Zipped")) { OSD osd = null; byte[] inBytes = req["Zipped"].AsBinary(); try { osd = ZDecompressBytesToOsd(inBytes); if (osd != null && osd is OSDMap) { materialsFromViewer = osd as OSDMap; if (materialsFromViewer.ContainsKey("FullMaterialsPerFace")) { OSD matsOsd = materialsFromViewer["FullMaterialsPerFace"]; if (matsOsd is OSDArray) { OSDArray matsArr = matsOsd as OSDArray; try { foreach (OSDMap matsMap in matsArr) { uint primLocalID = 0; try { primLocalID = matsMap["ID"].AsUInteger(); } catch (Exception e) { m_log.Warn("[Materials]: cannot decode \"ID\" from matsMap: " + e.Message); continue; } SceneObjectPart sop = m_scene.GetSceneObjectPart(primLocalID); if (sop == null) { m_log.WarnFormat("[Materials]: SOP not found for localId: {0}", primLocalID.ToString()); continue; } if (!m_scene.Permissions.CanEditObject(sop.UUID, agentID)) { m_log.WarnFormat("User {0} can't edit object {1} {2}", agentID, sop.Name, sop.UUID); continue; } OSDMap mat = null; try { mat = matsMap["Material"] as OSDMap; } catch (Exception e) { m_log.Warn("[Materials]: cannot decode \"Material\" from matsMap: " + e.Message); continue; } Primitive.TextureEntry te = new Primitive.TextureEntry(sop.Shape.TextureEntry, 0, sop.Shape.TextureEntry.Length); if (te == null) { m_log.WarnFormat("[Materials]: Error in TextureEntry for SOP {0} {1}", sop.Name, sop.UUID); continue; } UUID id; if (mat == null) { // This happens then the user removes a material from a prim id = UUID.Zero; } else { id = getNewID(mat); } int face = -1; UUID oldid = UUID.Zero; if (matsMap.ContainsKey("Face")) { face = matsMap["Face"].AsInteger(); Primitive.TextureEntryFace faceEntry = te.CreateFace((uint)face); oldid = faceEntry.MaterialID; faceEntry.MaterialID = id; } else { if (te.DefaultTexture == null) { m_log.WarnFormat("[Materials]: TextureEntry.DefaultTexture is null in {0} {1}", sop.Name, sop.UUID); } else { oldid = te.DefaultTexture.MaterialID; te.DefaultTexture.MaterialID = id; } } //m_log.DebugFormat("[Materials]: in \"{0}\" {1}, setting material ID for face {2} to {3}", sop.Name, sop.UUID, face, id); // We can't use sop.UpdateTextureEntry(te) because it filters, so do it manually sop.Shape.TextureEntry = te.GetBytes(); lock (m_Materials) { if (oldid != UUID.Zero && m_MaterialsRefCount.ContainsKey(oldid)) { m_MaterialsRefCount[oldid]--; if (m_MaterialsRefCount[oldid] <= 0) { m_Materials.Remove(oldid); m_MaterialsRefCount.Remove(oldid); m_cache.Expire(oldid.ToString()); } } if (id != UUID.Zero) { AssetBase asset = CacheMaterialAsAsset(id, agentID, mat, sop); if (asset != null) { ulong materialHash = (ulong)primLocalID << 32; if (face < 0) { materialHash += 0xffffffff; } else { materialHash += (ulong)face; } m_changes[materialHash] = asset; m_changesTime[materialHash] = Util.GetTimeStampMS(); } } } if (!parts.Contains(sop)) { parts.Add(sop); } } foreach (SceneObjectPart sop in parts) { if (sop.ParentGroup != null && !sop.ParentGroup.IsDeleted) { sop.TriggerScriptChangedEvent(Changed.TEXTURE); sop.ScheduleFullUpdate(); sop.ParentGroup.HasGroupChanged = true; } } } catch (Exception e) { m_log.Warn("[Materials]: exception processing received material ", e); } } } } } catch (Exception e) { m_log.Warn("[Materials]: exception decoding zipped CAP payload ", e); //return ""; } } resp["Zipped"] = ZCompressOSD(respArr, false); string response = OSDParser.SerializeLLSDXmlString(resp); //m_log.Debug("[Materials]: cap request: " + request); //m_log.Debug("[Materials]: cap request (zipped portion): " + ZippedOsdBytesToString(req["Zipped"].AsBinary())); //m_log.Debug("[Materials]: cap response: " + response); return(response); }
/// <summary> /// Called once new texture data has been received for this updater. /// </summary> /// <param name="data"></param> /// <param name="scene"></param> /// <param name="isReuseable">True if the data given is reuseable.</param> /// <returns>The asset UUID given to the incoming data.</returns> public UUID DataReceived(byte[] data, Scene scene) { // this are local assets and will not work without cache IAssetCache iac = scene.RequestModuleInterface <IAssetCache>(); if (iac == null) { return(UUID.Zero); } SceneObjectPart part = scene.GetSceneObjectPart(PrimID); if (part == null || data == null || data.Length <= 1) { string msg = string.Format("DynamicTextureModule: Error preparing image using URL {0}", Url); scene.SimChat(Utils.StringToBytes(msg), ChatTypeEnum.Say, 0, part.ParentGroup.RootPart.AbsolutePosition, part.Name, part.UUID, false); return(UUID.Zero); } byte[] assetData = null; AssetBase oldAsset = null; if (BlendWithOldTexture) { Primitive.TextureEntryFace curFace; if (Face == ALL_SIDES) { curFace = part.Shape.Textures.DefaultTexture; } else { try { curFace = part.Shape.Textures.GetFace((uint)Face); } catch { curFace = null; } } if (curFace != null) { oldAsset = scene.AssetService.Get(curFace.TextureID.ToString()); if (oldAsset != null) { assetData = BlendTextures(data, oldAsset.Data, FrontAlpha); } } } else if (FrontAlpha < 255) { assetData = BlendTextures(data, null, FrontAlpha); } if (assetData == null) { assetData = new byte[data.Length]; Array.Copy(data, assetData, data.Length); } // Create a new asset for user AssetBase asset = new AssetBase( UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000), (sbyte)AssetType.Texture, part.OwnerID.ToString()); asset.Data = assetData; asset.Description = string.Format("URL image : {0}", Url); if (asset.Description.Length > 128) { asset.Description = asset.Description.Substring(0, 128); } asset.Local = true; // dynamic images aren't saved in the assets server asset.Temporary = ((Disp & DISP_TEMP) != 0); iac.Cache(asset); UUID oldID = UpdatePart(part, asset.FullID); if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0)) { if (oldAsset == null) { oldAsset = scene.AssetService.Get(oldID.ToString()); } if (oldAsset != null) { if (oldAsset.Temporary) { iac.Expire(oldID.ToString()); } } } return(asset.FullID); }