diff options
author | Justin Clark-Casey (justincc) | 2013-06-27 23:42:35 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-06-27 23:42:35 +0100 |
commit | 149487ea0f74a46a70c98b3a31259b667f4d29b2 (patch) | |
tree | 19524863c98a1d5b229cfda790913da1588d372b /OpenSim/Region/OptionalModules | |
parent | Make the concept of namespaces explicit in dynamic attributes (diff) | |
download | opensim-SC-149487ea0f74a46a70c98b3a31259b667f4d29b2.zip opensim-SC-149487ea0f74a46a70c98b3a31259b667f4d29b2.tar.gz opensim-SC-149487ea0f74a46a70c98b3a31259b667f4d29b2.tar.bz2 opensim-SC-149487ea0f74a46a70c98b3a31259b667f4d29b2.tar.xz |
refactor: Move code for gathering textures referenced by materials into MaterialsDemoModule from UuidGatherer
This code is now triggered via EventManager.OnGatherUuids which modules can subscribe to.
Diffstat (limited to 'OpenSim/Region/OptionalModules')
-rw-r--r-- | OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs index 5b15a73..e7b8928 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | |||
@@ -121,9 +121,11 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
121 | return; | 121 | return; |
122 | 122 | ||
123 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName); | 123 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName); |
124 | |||
124 | m_scene = scene; | 125 | m_scene = scene; |
125 | m_scene.EventManager.OnRegisterCaps += new EventManager.RegisterCapsEvent(OnRegisterCaps); | 126 | m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; |
126 | m_scene.EventManager.OnObjectAddedToScene += new Action<SceneObjectGroup>(EventManager_OnObjectAddedToScene); | 127 | m_scene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene; |
128 | m_scene.EventManager.OnGatherUuids += GatherMaterialsUuids; | ||
127 | } | 129 | } |
128 | 130 | ||
129 | void EventManager_OnObjectAddedToScene(SceneObjectGroup obj) | 131 | void EventManager_OnObjectAddedToScene(SceneObjectGroup obj) |
@@ -157,6 +159,10 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
157 | if (!m_enabled) | 159 | if (!m_enabled) |
158 | return; | 160 | return; |
159 | 161 | ||
162 | m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps; | ||
163 | m_scene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene; | ||
164 | m_scene.EventManager.OnGatherUuids -= GatherMaterialsUuids; | ||
165 | |||
160 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | 166 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName); |
161 | } | 167 | } |
162 | 168 | ||
@@ -569,5 +575,67 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
569 | output.Flush(); | 575 | output.Flush(); |
570 | } | 576 | } |
571 | 577 | ||
578 | /// <summary> | ||
579 | /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps | ||
580 | /// </summary> | ||
581 | /// <param name="part"></param> | ||
582 | /// <param name="assetUuids"></param> | ||
583 | private void GatherMaterialsUuids(SceneObjectPart part, IDictionary<UUID, AssetType> assetUuids) | ||
584 | { | ||
585 | // scan thru the dynAttrs map of this part for any textures used as materials | ||
586 | OSD osdMaterials = null; | ||
587 | |||
588 | lock (part.DynAttrs) | ||
589 | { | ||
590 | if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) | ||
591 | { | ||
592 | OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); | ||
593 | materialsStore.TryGetValue("Materials", out osdMaterials); | ||
594 | } | ||
595 | |||
596 | if (osdMaterials != null) | ||
597 | { | ||
598 | //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); | ||
599 | |||
600 | if (osdMaterials is OSDArray) | ||
601 | { | ||
602 | OSDArray matsArr = osdMaterials as OSDArray; | ||
603 | foreach (OSDMap matMap in matsArr) | ||
604 | { | ||
605 | try | ||
606 | { | ||
607 | if (matMap.ContainsKey("Material")) | ||
608 | { | ||
609 | OSDMap mat = matMap["Material"] as OSDMap; | ||
610 | if (mat.ContainsKey("NormMap")) | ||
611 | { | ||
612 | UUID normalMapId = mat["NormMap"].AsUUID(); | ||
613 | if (normalMapId != UUID.Zero) | ||
614 | { | ||
615 | assetUuids[normalMapId] = AssetType.Texture; | ||
616 | //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); | ||
617 | } | ||
618 | } | ||
619 | if (mat.ContainsKey("SpecMap")) | ||
620 | { | ||
621 | UUID specularMapId = mat["SpecMap"].AsUUID(); | ||
622 | if (specularMapId != UUID.Zero) | ||
623 | { | ||
624 | assetUuids[specularMapId] = AssetType.Texture; | ||
625 | //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); | ||
626 | } | ||
627 | } | ||
628 | } | ||
629 | |||
630 | } | ||
631 | catch (Exception e) | ||
632 | { | ||
633 | m_log.Warn("[MaterialsDemoModule]: exception getting materials: " + e.Message); | ||
634 | } | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | } | ||
639 | } | ||
572 | } | 640 | } |
573 | } \ No newline at end of file | 641 | } \ No newline at end of file |