29 using System.Collections.Generic;
31 using System.Reflection;
32 using System.Text.RegularExpressions;
33 using System.Threading;
36 using OpenMetaverse.Assets;
37 using OpenMetaverse.StructuredData;
38 using OpenSim.Framework;
39 using OpenSim.Region.Framework.Scenes.Serialization;
40 using OpenSim.Services.Interfaces;
43 namespace OpenSim.
Region.Framework.Scenes
56 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
61 public bool Complete {
get {
return m_assetUuidsToInspect.Count <= 0; } }
67 public IDictionary<UUID, sbyte> GatheredUuids {
get;
private set; }
73 public UUID? NextUuidToInspect
80 return m_assetUuidsToInspect.Peek();
109 m_assetService = assetService;
110 GatheredUuids = collector;
113 m_assetUuidsToInspect =
new Queue<UUID>();
123 if (m_assetUuidsToInspect.Contains(uuid))
128 m_assetUuidsToInspect.Enqueue(uuid);
147 for (
int i = 0; i < parts.Length; i++)
156 Primitive.TextureEntry textureEntry = part.Shape.Textures;
157 if (textureEntry != null)
160 if (textureEntry.DefaultTexture != null)
161 RecordTextureEntryAssetUuids(textureEntry.DefaultTexture);
163 if (textureEntry.FaceTextures != null)
166 foreach (
Primitive.TextureEntryFace texture in textureEntry.FaceTextures)
169 RecordTextureEntryAssetUuids(texture);
176 GatheredUuids[part.Shape.SculptTexture] = (sbyte)AssetType.Texture;
179 GatheredUuids[part.Shape.ProjectionTextureUUID] = (sbyte)AssetType.Texture;
182 GatheredUuids[part.CollisionSound] = (sbyte)AssetType.Sound;
188 Primitive.ParticleSystem ps =
new Primitive.ParticleSystem(part.ParticleSystem, 0);
189 if (ps.Texture != UUID.Zero)
190 GatheredUuids[ps.Texture] = (sbyte)AssetType.Texture;
195 "[UUID GATHERER]: Could not check particle system for part {0} {1} in object {2} {3} since it is corrupt. Continuing.",
196 part.Name, part.UUID, sceneObject.Name, sceneObject.UUID);
209 if (!GatheredUuids.ContainsKey(tii.
AssetID))
210 AddForInspection(tii.
AssetID, (sbyte)tii.Type);
221 RecordMaterialsUuids(part);
225 m_log.ErrorFormat(
"[UUID GATHERER]: Failed to get part - {0}", e);
227 "[UUID GATHERER]: Texture entry length for prim was {0} (min is 46)",
228 part.Shape.TextureEntry.Length);
242 UUID nextToInspect = m_assetUuidsToInspect.Dequeue();
246 GetAssetUuids(nextToInspect);
260 while (GatherNext());
277 private void GetAssetUuids(UUID assetUuid)
280 if (GatheredUuids.ContainsKey(assetUuid))
285 AssetBase assetBase = GetAsset(assetUuid);
287 if (null != assetBase)
289 sbyte assetType = assetBase.Type;
290 GatheredUuids[assetUuid] = assetType;
292 if ((sbyte)AssetType.Bodypart == assetType || (sbyte)AssetType.Clothing == assetType)
294 RecordWearableAssetUuids(assetBase);
296 else if ((sbyte)AssetType.Gesture == assetType)
298 RecordGestureAssetUuids(assetBase);
300 else if ((sbyte)AssetType.Notecard == assetType)
302 RecordTextEmbeddedAssetUuids(assetBase);
304 else if ((sbyte)AssetType.LSLText == assetType)
306 RecordTextEmbeddedAssetUuids(assetBase);
310 RecordMaterialAssetUuids(assetBase);
312 else if ((sbyte)AssetType.Object == assetType)
314 RecordSceneObjectAssetUuids(assetBase);
320 m_log.ErrorFormat(
"[UUID GATHERER]: Failed to gather uuids for asset id {0}", assetUuid);
325 private void AddForInspection(UUID assetUuid, sbyte assetType)
330 if ((sbyte)AssetType.Bodypart == assetType
331 || (sbyte)AssetType.Clothing == assetType
332 || (sbyte)AssetType.Gesture == assetType
333 || (sbyte)AssetType.Notecard == assetType
334 || (sbyte)AssetType.LSLText == assetType
336 || (sbyte)AssetType.Object == assetType)
338 AddForInspection(assetUuid);
342 GatheredUuids[assetUuid] = assetType;
348 "[UUID GATHERER]: Failed to gather uuids for asset id {0}, type {1}",
349 assetUuid, assetType);
357 private void RecordTextureEntryAssetUuids(
Primitive.TextureEntryFace texture)
359 GatheredUuids[texture.TextureID] = (sbyte)AssetType.Texture;
361 if (texture.MaterialID !=
UUID.Zero)
362 AddForInspection(texture.MaterialID);
370 private void RecordMaterialsUuids(SceneObjectPart part)
373 OSD osdMaterials = null;
377 if (part.DynAttrs.ContainsStore(
"OpenSim",
"Materials"))
379 OSDMap materialsStore = part.DynAttrs.GetStore(
"OpenSim",
"Materials");
381 if (materialsStore == null)
384 materialsStore.TryGetValue(
"Materials", out osdMaterials);
387 if (osdMaterials != null)
393 OSDArray matsArr = osdMaterials as
OSDArray;
394 foreach (
OSDMap matMap
in matsArr)
398 if (matMap.ContainsKey(
"Material"))
401 if (mat.ContainsKey(
"NormMap"))
403 UUID normalMapId = mat[
"NormMap"].AsUUID();
404 if (normalMapId !=
UUID.Zero)
406 GatheredUuids[normalMapId] = (sbyte)AssetType.Texture;
410 if (mat.ContainsKey(
"SpecMap"))
412 UUID specularMapId = mat[
"SpecMap"].AsUUID();
413 if (specularMapId !=
UUID.Zero)
415 GatheredUuids[specularMapId] = (sbyte)AssetType.Texture;
424 m_log.Warn(
"[UUID Gatherer]: exception getting materials: " + e.Message);
440 return m_assetService.Get(uuid.ToString());
447 private void RecordTextEmbeddedAssetUuids(
AssetBase textAsset)
451 string text = Utils.BytesToString(textAsset.Data);
453 MatchCollection uuidMatches = Util.PermissiveUUIDPattern.Matches(text);
456 foreach (Match uuidMatch
in uuidMatches)
458 UUID uuid =
new UUID(uuidMatch.Value);
461 AddForInspection(uuid);
469 private void RecordWearableAssetUuids(
AssetBase assetBase)
472 AssetWearable wearableAsset =
new AssetBodypart(assetBase.
FullID, assetBase.
Data);
473 wearableAsset.Decode();
478 foreach (UUID uuid
in wearableAsset.Textures.Values)
479 GatheredUuids[uuid] = (sbyte)AssetType.Texture;
488 private void RecordSceneObjectAssetUuids(
AssetBase sceneObjectAsset)
490 string xml = Utils.BytesToString(sceneObjectAsset.Data);
492 CoalescedSceneObjects coa;
495 foreach (SceneObjectGroup sog
in coa.Objects)
496 AddForInspection(sog);
500 SceneObjectGroup sog = SceneObjectSerializer.FromOriginalXmlFormat(xml);
503 AddForInspection(sog);
511 private void RecordGestureAssetUuids(
AssetBase gestureAsset)
513 using (MemoryStream ms =
new MemoryStream(gestureAsset.
Data))
514 using (StreamReader sr =
new StreamReader(ms))
521 int count = Convert.ToInt32(sr.ReadLine());
523 for (
int i = 0 ; i < count ; i++)
525 string type = sr.ReadLine();
528 string name = sr.ReadLine();
531 string id = sr.ReadLine();
534 string unknown = sr.ReadLine();
540 if (
UUID.TryParse(
id, out uuid))
549 private void RecordMaterialAssetUuids(
AssetBase materialAsset)
553 UUID normMap = mat[
"NormMap"].AsUUID();
554 if (normMap !=
UUID.Zero)
555 GatheredUuids[normMap] = (sbyte)AssetType.Texture;
557 UUID specMap = mat[
"SpecMap"].AsUUID();
558 if (specMap !=
UUID.Zero)
559 GatheredUuids[specMap] = (sbyte)AssetType.Texture;
565 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
570 : this(assetService, assetServerURL, new Dictionary<UUID, sbyte>()) {}
573 : base(assetService, collector)
575 m_assetServerURL = assetServerURL;
576 if (!m_assetServerURL.EndsWith(
"/") && !m_assetServerURL.EndsWith(
"="))
577 m_assetServerURL = m_assetServerURL +
"/";
582 if (
string.Empty == m_assetServerURL)
583 return base.GetAsset(uuid);
585 return FetchAsset(uuid);
591 AssetBase asset = m_assetService.Get(assetID.ToString());
595 asset = m_assetService.Get(m_assetServerURL + assetID.ToString());
597 m_log.DebugFormat(
"[HGUUIDGatherer]: Copied asset {0} from {1} to local asset server", assetID, m_assetServerURL);
599 m_log.DebugFormat(
"[HGUUIDGatherer]: Failed to fetch asset {0} from {1}", assetID, m_assetServerURL);
Gather uuids for a given entity.
OpenSim.Framework.SLUtil.OpenSimAssetType OpenSimAssetType
static bool TryFromXml(string xml, out CoalescedSceneObjects coa)
OpenMetaverse.StructuredData.OSDArray OSDArray
OpenSim.Framework.SLUtil.OpenSimAssetType OpenSimAssetType
A dictionary containing task inventory items. Indexed by item UUID.
UuidGatherer(IAssetService assetService)
Initializes a new instance of the OpenSim.Region.Framework.Scenes.UuidGatherer class.
HGUuidGatherer(IAssetService assetService, string assetServerURL)
OpenMetaverse.StructuredData.OSDMap OSDMap
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Represents an item in a task inventory
bool GatherAll()
Gathers all remaining asset UUIDS no matter how many calls are required to the asset service...
UUID ProjectionTextureUUID
Asset class. All Assets are reference by this class or a class derived from this class ...
AssetBase FetchAsset(UUID assetID)
void AddForInspection(SceneObjectGroup sceneObject)
Gather all the asset uuids associated with a given object.
TaskInventoryDictionary TaskInventory
IAssetService m_assetService
bool GatherNext()
Gathers the next set of assets returned by the next uuid to get from the asset service.
Queue< UUID > m_assetUuidsToInspect
OpenMetaverse.StructuredData.OSD OSD
OpenSim.Framework.Animation Animation
HGUuidGatherer(IAssetService assetService, string assetServerURL, IDictionary< UUID, sbyte > collector)
bool AddForInspection(UUID uuid)
Adds the asset uuid for inspection during the gathering process.
Serialize and deserialize coalesced scene objects.
UuidGatherer(IAssetService assetService, IDictionary< UUID, sbyte > collector)
Initializes a new instance of the OpenSim.Region.Framework.Scenes.UuidGatherer class.
override AssetBase GetAsset(UUID uuid)
Get an asset synchronously, potentially using an asynchronous callback. If the asynchronous callback ...
virtual AssetBase GetAsset(UUID uuid)
Get an asset synchronously, potentially using an asynchronous callback. If the asynchronous callback ...