diff options
author | Oren Hurvitz | 2013-12-06 16:21:11 +0200 |
---|---|---|
committer | dahlia | 2014-01-20 00:38:42 -0800 |
commit | 3018b2c5d7c9de0e8da6d158f0848c840b7864ab (patch) | |
tree | f06f5b35360de9010e618b2cf7c6c109c0527631 /OpenSim/Region/Framework/Scenes/UuidGatherer.cs | |
parent | Renamed MaterialsDemoModule to MaterialsModule (diff) | |
download | opensim-SC-3018b2c5d7c9de0e8da6d158f0848c840b7864ab.zip opensim-SC-3018b2c5d7c9de0e8da6d158f0848c840b7864ab.tar.gz opensim-SC-3018b2c5d7c9de0e8da6d158f0848c840b7864ab.tar.bz2 opensim-SC-3018b2c5d7c9de0e8da6d158f0848c840b7864ab.tar.xz |
Materials module: a) Store materials as assets; b) Finalized it (removed the "Demo" label; removed most of the logging); c) Enabled by default
Changed UuidGatherer to use 'sbyte' to identify assets instead of 'AssetType'. This lets UuidGatherer handle Materials, which are defined in a different enum from 'AssetType'.
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/UuidGatherer.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 138 |
1 files changed, 47 insertions, 91 deletions
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 3e074b9..42a1977 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs | |||
@@ -38,6 +38,7 @@ using OpenMetaverse.StructuredData; | |||
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Region.Framework.Scenes.Serialization; | 39 | using OpenSim.Region.Framework.Scenes.Serialization; |
40 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
41 | using OpenSimAssetType = OpenSim.Framework.SLUtil.OpenSimAssetType; | ||
41 | 42 | ||
42 | namespace OpenSim.Region.Framework.Scenes | 43 | namespace OpenSim.Region.Framework.Scenes |
43 | { | 44 | { |
@@ -83,7 +84,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
83 | /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param> | 84 | /// <param name="assetUuid">The uuid of the asset for which to gather referenced assets</param> |
84 | /// <param name="assetType">The type of the asset for the uuid given</param> | 85 | /// <param name="assetType">The type of the asset for the uuid given</param> |
85 | /// <param name="assetUuids">The assets gathered</param> | 86 | /// <param name="assetUuids">The assets gathered</param> |
86 | public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary<UUID, AssetType> assetUuids) | 87 | public void GatherAssetUuids(UUID assetUuid, sbyte assetType, IDictionary<UUID, sbyte> assetUuids) |
87 | { | 88 | { |
88 | // avoid infinite loops | 89 | // avoid infinite loops |
89 | if (assetUuids.ContainsKey(assetUuid)) | 90 | if (assetUuids.ContainsKey(assetUuid)) |
@@ -93,23 +94,27 @@ namespace OpenSim.Region.Framework.Scenes | |||
93 | { | 94 | { |
94 | assetUuids[assetUuid] = assetType; | 95 | assetUuids[assetUuid] = assetType; |
95 | 96 | ||
96 | if (AssetType.Bodypart == assetType || AssetType.Clothing == assetType) | 97 | if ((sbyte)AssetType.Bodypart == assetType || (sbyte)AssetType.Clothing == assetType) |
97 | { | 98 | { |
98 | GetWearableAssetUuids(assetUuid, assetUuids); | 99 | GetWearableAssetUuids(assetUuid, assetUuids); |
99 | } | 100 | } |
100 | else if (AssetType.Gesture == assetType) | 101 | else if ((sbyte)AssetType.Gesture == assetType) |
101 | { | 102 | { |
102 | GetGestureAssetUuids(assetUuid, assetUuids); | 103 | GetGestureAssetUuids(assetUuid, assetUuids); |
103 | } | 104 | } |
104 | else if (AssetType.Notecard == assetType) | 105 | else if ((sbyte)AssetType.Notecard == assetType) |
105 | { | 106 | { |
106 | GetTextEmbeddedAssetUuids(assetUuid, assetUuids); | 107 | GetTextEmbeddedAssetUuids(assetUuid, assetUuids); |
107 | } | 108 | } |
108 | else if (AssetType.LSLText == assetType) | 109 | else if ((sbyte)AssetType.LSLText == assetType) |
109 | { | 110 | { |
110 | GetTextEmbeddedAssetUuids(assetUuid, assetUuids); | 111 | GetTextEmbeddedAssetUuids(assetUuid, assetUuids); |
111 | } | 112 | } |
112 | else if (AssetType.Object == assetType) | 113 | else if ((sbyte)OpenSimAssetType.Material == assetType) |
114 | { | ||
115 | GetMaterialAssetUuids(assetUuid, assetUuids); | ||
116 | } | ||
117 | else if ((sbyte)AssetType.Object == assetType) | ||
113 | { | 118 | { |
114 | GetSceneObjectAssetUuids(assetUuid, assetUuids); | 119 | GetSceneObjectAssetUuids(assetUuid, assetUuids); |
115 | } | 120 | } |
@@ -136,7 +141,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
136 | /// A dictionary which is populated with the asset UUIDs gathered and the type of that asset. | 141 | /// A dictionary which is populated with the asset UUIDs gathered and the type of that asset. |
137 | /// For assets where the type is not clear (e.g. UUIDs extracted from LSL and notecards), the type is Unknown. | 142 | /// For assets where the type is not clear (e.g. UUIDs extracted from LSL and notecards), the type is Unknown. |
138 | /// </param> | 143 | /// </param> |
139 | public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary<UUID, AssetType> assetUuids) | 144 | public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary<UUID, sbyte> assetUuids) |
140 | { | 145 | { |
141 | // m_log.DebugFormat( | 146 | // m_log.DebugFormat( |
142 | // "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID); | 147 | // "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID); |
@@ -156,7 +161,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
156 | { | 161 | { |
157 | // Get the prim's default texture. This will be used for faces which don't have their own texture | 162 | // Get the prim's default texture. This will be used for faces which don't have their own texture |
158 | if (textureEntry.DefaultTexture != null) | 163 | if (textureEntry.DefaultTexture != null) |
159 | assetUuids[textureEntry.DefaultTexture.TextureID] = AssetType.Texture; | 164 | assetUuids[textureEntry.DefaultTexture.TextureID] = (sbyte)AssetType.Texture; |
160 | 165 | ||
161 | if (textureEntry.FaceTextures != null) | 166 | if (textureEntry.FaceTextures != null) |
162 | { | 167 | { |
@@ -164,20 +169,20 @@ namespace OpenSim.Region.Framework.Scenes | |||
164 | foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) | 169 | foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) |
165 | { | 170 | { |
166 | if (texture != null) | 171 | if (texture != null) |
167 | assetUuids[texture.TextureID] = AssetType.Texture; | 172 | assetUuids[texture.TextureID] = (sbyte)AssetType.Texture; |
168 | } | 173 | } |
169 | } | 174 | } |
170 | } | 175 | } |
171 | 176 | ||
172 | // If the prim is a sculpt then preserve this information too | 177 | // If the prim is a sculpt then preserve this information too |
173 | if (part.Shape.SculptTexture != UUID.Zero) | 178 | if (part.Shape.SculptTexture != UUID.Zero) |
174 | assetUuids[part.Shape.SculptTexture] = AssetType.Texture; | 179 | assetUuids[part.Shape.SculptTexture] = (sbyte)AssetType.Texture; |
175 | 180 | ||
176 | if (part.Shape.ProjectionTextureUUID != UUID.Zero) | 181 | if (part.Shape.ProjectionTextureUUID != UUID.Zero) |
177 | assetUuids[part.Shape.ProjectionTextureUUID] = AssetType.Texture; | 182 | assetUuids[part.Shape.ProjectionTextureUUID] = (sbyte)AssetType.Texture; |
178 | 183 | ||
179 | if (part.CollisionSound != UUID.Zero) | 184 | if (part.CollisionSound != UUID.Zero) |
180 | assetUuids[part.CollisionSound] = AssetType.Sound; | 185 | assetUuids[part.CollisionSound] = (sbyte)AssetType.Sound; |
181 | 186 | ||
182 | if (part.ParticleSystem.Length > 0) | 187 | if (part.ParticleSystem.Length > 0) |
183 | { | 188 | { |
@@ -185,7 +190,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
185 | { | 190 | { |
186 | Primitive.ParticleSystem ps = new Primitive.ParticleSystem(part.ParticleSystem, 0); | 191 | Primitive.ParticleSystem ps = new Primitive.ParticleSystem(part.ParticleSystem, 0); |
187 | if (ps.Texture != UUID.Zero) | 192 | if (ps.Texture != UUID.Zero) |
188 | assetUuids[ps.Texture] = AssetType.Texture; | 193 | assetUuids[ps.Texture] = (sbyte)AssetType.Texture; |
189 | } | 194 | } |
190 | catch (Exception e) | 195 | catch (Exception e) |
191 | { | 196 | { |
@@ -205,7 +210,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
205 | // tii.Name, tii.Type, part.Name, part.UUID); | 210 | // tii.Name, tii.Type, part.Name, part.UUID); |
206 | 211 | ||
207 | if (!assetUuids.ContainsKey(tii.AssetID)) | 212 | if (!assetUuids.ContainsKey(tii.AssetID)) |
208 | GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); | 213 | GatherAssetUuids(tii.AssetID, (sbyte)tii.Type, assetUuids); |
209 | } | 214 | } |
210 | 215 | ||
211 | // FIXME: We need to make gathering modular but we cannot yet, since gatherers are not guaranteed | 216 | // FIXME: We need to make gathering modular but we cannot yet, since gatherers are not guaranteed |
@@ -213,8 +218,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
213 | // inventory transfer. There needs to be a way for a module to register a method without assuming a | 218 | // inventory transfer. There needs to be a way for a module to register a method without assuming a |
214 | // Scene.EventManager is present. | 219 | // Scene.EventManager is present. |
215 | // part.ParentGroup.Scene.EventManager.TriggerGatherUuids(part, assetUuids); | 220 | // part.ParentGroup.Scene.EventManager.TriggerGatherUuids(part, assetUuids); |
216 | |||
217 | GatherMaterialsUuids(part, assetUuids); | ||
218 | } | 221 | } |
219 | catch (Exception e) | 222 | catch (Exception e) |
220 | { | 223 | { |
@@ -225,7 +228,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
225 | } | 228 | } |
226 | } | 229 | } |
227 | } | 230 | } |
228 | 231 | ||
229 | // /// <summary> | 232 | // /// <summary> |
230 | // /// The callback made when we request the asset for an object from the asset service. | 233 | // /// The callback made when we request the asset for an object from the asset service. |
231 | // /// </summary> | 234 | // /// </summary> |
@@ -238,73 +241,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
238 | // Monitor.Pulse(this); | 241 | // Monitor.Pulse(this); |
239 | // } | 242 | // } |
240 | // } | 243 | // } |
241 | |||
242 | /// <summary> | ||
243 | /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps | ||
244 | /// </summary> | ||
245 | /// <param name="part"></param> | ||
246 | /// <param name="assetUuids"></param> | ||
247 | public void GatherMaterialsUuids(SceneObjectPart part, IDictionary<UUID, AssetType> assetUuids) | ||
248 | { | ||
249 | // scan thru the dynAttrs map of this part for any textures used as materials | ||
250 | OSD osdMaterials = null; | ||
251 | |||
252 | lock (part.DynAttrs) | ||
253 | { | ||
254 | if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) | ||
255 | { | ||
256 | OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); | ||
257 | |||
258 | if (materialsStore == null) | ||
259 | return; | ||
260 | |||
261 | materialsStore.TryGetValue("Materials", out osdMaterials); | ||
262 | } | ||
263 | |||
264 | if (osdMaterials != null) | ||
265 | { | ||
266 | //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); | ||
267 | |||
268 | if (osdMaterials is OSDArray) | ||
269 | { | ||
270 | OSDArray matsArr = osdMaterials as OSDArray; | ||
271 | foreach (OSDMap matMap in matsArr) | ||
272 | { | ||
273 | try | ||
274 | { | ||
275 | if (matMap.ContainsKey("Material")) | ||
276 | { | ||
277 | OSDMap mat = matMap["Material"] as OSDMap; | ||
278 | if (mat.ContainsKey("NormMap")) | ||
279 | { | ||
280 | UUID normalMapId = mat["NormMap"].AsUUID(); | ||
281 | if (normalMapId != UUID.Zero) | ||
282 | { | ||
283 | assetUuids[normalMapId] = AssetType.Texture; | ||
284 | //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); | ||
285 | } | ||
286 | } | ||
287 | if (mat.ContainsKey("SpecMap")) | ||
288 | { | ||
289 | UUID specularMapId = mat["SpecMap"].AsUUID(); | ||
290 | if (specularMapId != UUID.Zero) | ||
291 | { | ||
292 | assetUuids[specularMapId] = AssetType.Texture; | ||
293 | //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | |||
298 | } | ||
299 | catch (Exception e) | ||
300 | { | ||
301 | m_log.Warn("[UUID Gatherer]: exception getting materials: " + e.Message); | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | 244 | ||
309 | /// <summary> | 245 | /// <summary> |
310 | /// Get an asset synchronously, potentially using an asynchronous callback. If the | 246 | /// Get an asset synchronously, potentially using an asynchronous callback. If the |
@@ -344,7 +280,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
344 | /// </summary> | 280 | /// </summary> |
345 | /// <param name="scriptUuid"></param> | 281 | /// <param name="scriptUuid"></param> |
346 | /// <param name="assetUuids">Dictionary in which to record the references</param> | 282 | /// <param name="assetUuids">Dictionary in which to record the references</param> |
347 | private void GetTextEmbeddedAssetUuids(UUID embeddingAssetId, IDictionary<UUID, AssetType> assetUuids) | 283 | private void GetTextEmbeddedAssetUuids(UUID embeddingAssetId, IDictionary<UUID, sbyte> assetUuids) |
348 | { | 284 | { |
349 | // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId); | 285 | // m_log.DebugFormat("[ASSET GATHERER]: Getting assets for uuid references in asset {0}", embeddingAssetId); |
350 | 286 | ||
@@ -364,7 +300,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
364 | 300 | ||
365 | // Embedded asset references (if not false positives) could be for many types of asset, so we will | 301 | // Embedded asset references (if not false positives) could be for many types of asset, so we will |
366 | // label these as unknown. | 302 | // label these as unknown. |
367 | assetUuids[uuid] = AssetType.Unknown; | 303 | assetUuids[uuid] = (sbyte)AssetType.Unknown; |
368 | } | 304 | } |
369 | } | 305 | } |
370 | } | 306 | } |
@@ -374,7 +310,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
374 | /// </summary> | 310 | /// </summary> |
375 | /// <param name="wearableAssetUuid"></param> | 311 | /// <param name="wearableAssetUuid"></param> |
376 | /// <param name="assetUuids">Dictionary in which to record the references</param> | 312 | /// <param name="assetUuids">Dictionary in which to record the references</param> |
377 | private void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary<UUID, AssetType> assetUuids) | 313 | private void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary<UUID, sbyte> assetUuids) |
378 | { | 314 | { |
379 | AssetBase assetBase = GetAsset(wearableAssetUuid); | 315 | AssetBase assetBase = GetAsset(wearableAssetUuid); |
380 | 316 | ||
@@ -389,7 +325,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
389 | 325 | ||
390 | foreach (UUID uuid in wearableAsset.Textures.Values) | 326 | foreach (UUID uuid in wearableAsset.Textures.Values) |
391 | { | 327 | { |
392 | assetUuids[uuid] = AssetType.Texture; | 328 | assetUuids[uuid] = (sbyte)AssetType.Texture; |
393 | } | 329 | } |
394 | } | 330 | } |
395 | } | 331 | } |
@@ -401,7 +337,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
401 | /// </summary> | 337 | /// </summary> |
402 | /// <param name="sceneObject"></param> | 338 | /// <param name="sceneObject"></param> |
403 | /// <param name="assetUuids"></param> | 339 | /// <param name="assetUuids"></param> |
404 | private void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, AssetType> assetUuids) | 340 | private void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary<UUID, sbyte> assetUuids) |
405 | { | 341 | { |
406 | AssetBase objectAsset = GetAsset(sceneObjectUuid); | 342 | AssetBase objectAsset = GetAsset(sceneObjectUuid); |
407 | 343 | ||
@@ -430,7 +366,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
430 | /// </summary> | 366 | /// </summary> |
431 | /// <param name="gestureUuid"></param> | 367 | /// <param name="gestureUuid"></param> |
432 | /// <param name="assetUuids"></param> | 368 | /// <param name="assetUuids"></param> |
433 | private void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, AssetType> assetUuids) | 369 | private void GetGestureAssetUuids(UUID gestureUuid, IDictionary<UUID, sbyte> assetUuids) |
434 | { | 370 | { |
435 | AssetBase assetBase = GetAsset(gestureUuid); | 371 | AssetBase assetBase = GetAsset(gestureUuid); |
436 | if (null == assetBase) | 372 | if (null == assetBase) |
@@ -464,9 +400,29 @@ namespace OpenSim.Region.Framework.Scenes | |||
464 | // If it can be parsed as a UUID, it is an asset ID | 400 | // If it can be parsed as a UUID, it is an asset ID |
465 | UUID uuid; | 401 | UUID uuid; |
466 | if (UUID.TryParse(id, out uuid)) | 402 | if (UUID.TryParse(id, out uuid)) |
467 | assetUuids[uuid] = AssetType.Animation; | 403 | assetUuids[uuid] = (sbyte)AssetType.Animation; |
468 | } | 404 | } |
469 | } | 405 | } |
406 | |||
407 | /// <summary> | ||
408 | /// Get the asset uuid's referenced in a material. | ||
409 | /// </summary> | ||
410 | private void GetMaterialAssetUuids(UUID materialUuid, IDictionary<UUID, sbyte> assetUuids) | ||
411 | { | ||
412 | AssetBase assetBase = GetAsset(materialUuid); | ||
413 | if (null == assetBase) | ||
414 | return; | ||
415 | |||
416 | OSDMap mat = (OSDMap)OSDParser.DeserializeLLSDXml(assetBase.Data); | ||
417 | |||
418 | UUID normMap = mat["NormMap"].AsUUID(); | ||
419 | if (normMap != UUID.Zero) | ||
420 | assetUuids[normMap] = (sbyte)AssetType.Texture; | ||
421 | |||
422 | UUID specMap = mat["SpecMap"].AsUUID(); | ||
423 | if (specMap != UUID.Zero) | ||
424 | assetUuids[specMap] = (sbyte)AssetType.Texture; | ||
425 | } | ||
470 | } | 426 | } |
471 | 427 | ||
472 | public class HGUuidGatherer : UuidGatherer | 428 | public class HGUuidGatherer : UuidGatherer |