From c10405330d0fa5855c3f8180fdc8347cb87fed4f Mon Sep 17 00:00:00 2001 From: dahlia Date: Wed, 24 Apr 2013 20:43:15 -0700 Subject: [PATCH] UUIDGatherer now includes UUIDs which reference texture assets used as materials --- .../Region/Framework/Scenes/UuidGatherer.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index ad33607139..0e83781d19 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs @@ -34,6 +34,7 @@ using System.Threading; using log4net; using OpenMetaverse; using OpenMetaverse.Assets; +using OpenMetaverse.StructuredData; using OpenSim.Framework; using OpenSim.Region.Framework.Scenes.Serialization; using OpenSim.Services.Interfaces; @@ -184,6 +185,9 @@ namespace OpenSim.Region.Framework.Scenes if (!assetUuids.ContainsKey(tii.AssetID)) GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); } + + // get any texture UUIDs used for materials such as normal and specular maps + GatherMaterialsUuids(part, assetUuids); } catch (Exception e) { @@ -208,6 +212,68 @@ namespace OpenSim.Region.Framework.Scenes // } // } + + /// + /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps + /// + /// + /// + public void GatherMaterialsUuids(SceneObjectPart part, IDictionary assetUuids) + { + // scan thru the dynAttrs map of this part for any textures used as materials + OSDMap OSMaterials = null; + + lock (part.DynAttrs) + { + if (part.DynAttrs.ContainsKey("OS:Materials")) + OSMaterials = part.DynAttrs["OS:Materials"]; + if (OSMaterials != null && OSMaterials.ContainsKey("Materials")) + { + OSD osd = OSMaterials["Materials"]; + //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); + + if (osd is OSDArray) + { + OSDArray matsArr = osd as OSDArray; + foreach (OSDMap matMap in matsArr) + { + try + { + if (matMap.ContainsKey("Material")) + { + OSDMap mat = matMap["Material"] as OSDMap; + if (mat.ContainsKey("NormMap")) + { + UUID normalMapId = mat["NormMap"].AsUUID(); + if (normalMapId != UUID.Zero) + { + assetUuids[normalMapId] = AssetType.Texture; + //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); + } + } + if (mat.ContainsKey("SpecMap")) + { + UUID specularMapId = mat["SpecMap"].AsUUID(); + if (specularMapId != UUID.Zero) + { + assetUuids[specularMapId] = AssetType.Texture; + //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); + } + } + } + + } + catch (Exception e) + { + m_log.Warn("[UUID Gatherer]: exception getting materials: " + e.Message); + } + } + } + } + } + } + + /// /// Get an asset synchronously, potentially using an asynchronous callback. If the /// asynchronous callback is used, we will wait for it to complete.