diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | 177 |
1 files changed, 130 insertions, 47 deletions
diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs index 4ab6609..3a39971 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 | ||
@@ -167,18 +173,21 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
167 | OSDMap GetMaterial(UUID id) | 173 | OSDMap GetMaterial(UUID id) |
168 | { | 174 | { |
169 | OSDMap map = null; | 175 | OSDMap map = null; |
170 | if (m_knownMaterials.ContainsKey(id)) | 176 | lock (m_knownMaterials) |
171 | { | 177 | { |
172 | map = new OSDMap(); | 178 | if (m_knownMaterials.ContainsKey(id)) |
173 | map["ID"] = OSD.FromBinary(id.GetBytes()); | 179 | { |
174 | map["Material"] = m_knownMaterials[id]; | 180 | map = new OSDMap(); |
181 | map["ID"] = OSD.FromBinary(id.GetBytes()); | ||
182 | map["Material"] = m_knownMaterials[id]; | ||
183 | } | ||
175 | } | 184 | } |
176 | return map; | 185 | return map; |
177 | } | 186 | } |
178 | 187 | ||
179 | void GetStoredMaterialsForPart(SceneObjectPart part) | 188 | void GetStoredMaterialsForPart(SceneObjectPart part) |
180 | { | 189 | { |
181 | OSDMap OSMaterials = null; | 190 | OSD OSMaterials = null; |
182 | OSDArray matsArr = null; | 191 | OSDArray matsArr = null; |
183 | 192 | ||
184 | if (part.DynAttrs == null) | 193 | if (part.DynAttrs == null) |
@@ -188,23 +197,24 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
188 | 197 | ||
189 | lock (part.DynAttrs) | 198 | lock (part.DynAttrs) |
190 | { | 199 | { |
191 | if (part.DynAttrs.ContainsKey("OS:Materials")) | 200 | if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) |
192 | OSMaterials = part.DynAttrs["OS:Materials"]; | ||
193 | if (OSMaterials != null && OSMaterials.ContainsKey("Materials")) | ||
194 | { | 201 | { |
202 | OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); | ||
195 | 203 | ||
196 | OSD osd = OSMaterials["Materials"]; | 204 | if (materialsStore == null) |
197 | if (osd is OSDArray) | 205 | return; |
198 | matsArr = osd as OSDArray; | 206 | |
207 | materialsStore.TryGetValue("Materials", out OSMaterials); | ||
199 | } | 208 | } |
200 | } | ||
201 | 209 | ||
202 | if (OSMaterials == null) | 210 | if (OSMaterials != null && OSMaterials is OSDArray) |
203 | return; | 211 | matsArr = OSMaterials as OSDArray; |
212 | else | ||
213 | return; | ||
214 | } | ||
204 | 215 | ||
205 | m_log.Info("[MaterialsDemoModule]: OSMaterials: " + OSDParser.SerializeJsonString(OSMaterials)); | 216 | m_log.Info("[MaterialsDemoModule]: OSMaterials: " + OSDParser.SerializeJsonString(OSMaterials)); |
206 | 217 | ||
207 | |||
208 | if (matsArr == null) | 218 | if (matsArr == null) |
209 | { | 219 | { |
210 | m_log.Info("[MaterialsDemoModule]: matsArr is null :( "); | 220 | m_log.Info("[MaterialsDemoModule]: matsArr is null :( "); |
@@ -215,13 +225,13 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
215 | { | 225 | { |
216 | if (elemOsd != null && elemOsd is OSDMap) | 226 | if (elemOsd != null && elemOsd is OSDMap) |
217 | { | 227 | { |
218 | |||
219 | OSDMap matMap = elemOsd as OSDMap; | 228 | OSDMap matMap = elemOsd as OSDMap; |
220 | if (matMap.ContainsKey("ID") && matMap.ContainsKey("Material")) | 229 | if (matMap.ContainsKey("ID") && matMap.ContainsKey("Material")) |
221 | { | 230 | { |
222 | try | 231 | try |
223 | { | 232 | { |
224 | m_knownMaterials[matMap["ID"].AsUUID()] = (OSDMap)matMap["Material"]; | 233 | lock (m_knownMaterials) |
234 | m_knownMaterials[matMap["ID"].AsUUID()] = (OSDMap)matMap["Material"]; | ||
225 | } | 235 | } |
226 | catch (Exception e) | 236 | catch (Exception e) |
227 | { | 237 | { |
@@ -232,7 +242,6 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
232 | } | 242 | } |
233 | } | 243 | } |
234 | 244 | ||
235 | |||
236 | void StoreMaterialsForPart(SceneObjectPart part) | 245 | void StoreMaterialsForPart(SceneObjectPart part) |
237 | { | 246 | { |
238 | try | 247 | try |
@@ -246,8 +255,11 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
246 | 255 | ||
247 | if (te.DefaultTexture != null) | 256 | if (te.DefaultTexture != null) |
248 | { | 257 | { |
249 | if (m_knownMaterials.ContainsKey(te.DefaultTexture.MaterialID)) | 258 | lock (m_knownMaterials) |
250 | mats[te.DefaultTexture.MaterialID] = m_knownMaterials[te.DefaultTexture.MaterialID]; | 259 | { |
260 | if (m_knownMaterials.ContainsKey(te.DefaultTexture.MaterialID)) | ||
261 | mats[te.DefaultTexture.MaterialID] = m_knownMaterials[te.DefaultTexture.MaterialID]; | ||
262 | } | ||
251 | } | 263 | } |
252 | 264 | ||
253 | if (te.FaceTextures != null) | 265 | if (te.FaceTextures != null) |
@@ -256,8 +268,11 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
256 | { | 268 | { |
257 | if (face != null) | 269 | if (face != null) |
258 | { | 270 | { |
259 | if (m_knownMaterials.ContainsKey(face.MaterialID)) | 271 | lock (m_knownMaterials) |
260 | mats[face.MaterialID] = m_knownMaterials[face.MaterialID]; | 272 | { |
273 | if (m_knownMaterials.ContainsKey(face.MaterialID)) | ||
274 | mats[face.MaterialID] = m_knownMaterials[face.MaterialID]; | ||
275 | } | ||
261 | } | 276 | } |
262 | } | 277 | } |
263 | } | 278 | } |
@@ -277,7 +292,7 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
277 | OSMaterials["Materials"] = matsArr; | 292 | OSMaterials["Materials"] = matsArr; |
278 | 293 | ||
279 | lock (part.DynAttrs) | 294 | lock (part.DynAttrs) |
280 | part.DynAttrs["OS:Materials"] = OSMaterials; | 295 | part.DynAttrs.SetStore("OpenSim", "Materials", OSMaterials); |
281 | } | 296 | } |
282 | catch (Exception e) | 297 | catch (Exception e) |
283 | { | 298 | { |
@@ -285,7 +300,6 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
285 | } | 300 | } |
286 | } | 301 | } |
287 | 302 | ||
288 | |||
289 | public string RenderMaterialsPostCap(string request, string path, | 303 | public string RenderMaterialsPostCap(string request, string path, |
290 | string param, IOSHttpRequest httpRequest, | 304 | string param, IOSHttpRequest httpRequest, |
291 | IOSHttpResponse httpResponse) | 305 | IOSHttpResponse httpResponse) |
@@ -319,18 +333,21 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
319 | try | 333 | try |
320 | { | 334 | { |
321 | UUID id = new UUID(elem.AsBinary(), 0); | 335 | UUID id = new UUID(elem.AsBinary(), 0); |
322 | 336 | ||
323 | if (m_knownMaterials.ContainsKey(id)) | 337 | lock (m_knownMaterials) |
324 | { | 338 | { |
325 | m_log.Info("[MaterialsDemoModule]: request for known material ID: " + id.ToString()); | 339 | if (m_knownMaterials.ContainsKey(id)) |
326 | OSDMap matMap = new OSDMap(); | 340 | { |
327 | matMap["ID"] = OSD.FromBinary(id.GetBytes()); | 341 | m_log.Info("[MaterialsDemoModule]: request for known material ID: " + id.ToString()); |
342 | OSDMap matMap = new OSDMap(); | ||
343 | matMap["ID"] = OSD.FromBinary(id.GetBytes()); | ||
328 | 344 | ||
329 | matMap["Material"] = m_knownMaterials[id]; | 345 | matMap["Material"] = m_knownMaterials[id]; |
330 | respArr.Add(matMap); | 346 | respArr.Add(matMap); |
347 | } | ||
348 | else | ||
349 | m_log.Info("[MaterialsDemoModule]: request for UNKNOWN material ID: " + id.ToString()); | ||
331 | } | 350 | } |
332 | else | ||
333 | m_log.Info("[MaterialsDemoModule]: request for UNKNOWN material ID: " + id.ToString()); | ||
334 | } | 351 | } |
335 | catch (Exception e) | 352 | catch (Exception e) |
336 | { | 353 | { |
@@ -368,7 +385,8 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
368 | m_log.Debug("[MaterialsDemoModule]: mat: " + OSDParser.SerializeJsonString(mat)); | 385 | m_log.Debug("[MaterialsDemoModule]: mat: " + OSDParser.SerializeJsonString(mat)); |
369 | 386 | ||
370 | UUID id = HashOsd(mat); | 387 | UUID id = HashOsd(mat); |
371 | m_knownMaterials[id] = mat; | 388 | lock (m_knownMaterials) |
389 | m_knownMaterials[id] = mat; | ||
372 | 390 | ||
373 | 391 | ||
374 | var sop = m_scene.GetSceneObjectPart(matLocalID); | 392 | var sop = m_scene.GetSceneObjectPart(matLocalID); |
@@ -476,24 +494,22 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
476 | m_log.Debug("[MaterialsDemoModule]: GET cap handler"); | 494 | m_log.Debug("[MaterialsDemoModule]: GET cap handler"); |
477 | 495 | ||
478 | OSDMap resp = new OSDMap(); | 496 | OSDMap resp = new OSDMap(); |
479 | |||
480 | |||
481 | int matsCount = 0; | 497 | int matsCount = 0; |
482 | |||
483 | OSDArray allOsd = new OSDArray(); | 498 | OSDArray allOsd = new OSDArray(); |
484 | 499 | ||
485 | foreach (KeyValuePair<UUID, OSDMap> kvp in m_knownMaterials) | 500 | lock (m_knownMaterials) |
486 | { | 501 | { |
487 | OSDMap matMap = new OSDMap(); | 502 | foreach (KeyValuePair<UUID, OSDMap> kvp in m_knownMaterials) |
488 | 503 | { | |
489 | matMap["ID"] = OSD.FromBinary(kvp.Key.GetBytes()); | 504 | OSDMap matMap = new OSDMap(); |
490 | 505 | ||
491 | matMap["Material"] = kvp.Value; | 506 | matMap["ID"] = OSD.FromBinary(kvp.Key.GetBytes()); |
492 | allOsd.Add(matMap); | 507 | matMap["Material"] = kvp.Value; |
493 | matsCount++; | 508 | allOsd.Add(matMap); |
509 | matsCount++; | ||
510 | } | ||
494 | } | 511 | } |
495 | 512 | ||
496 | |||
497 | resp["Zipped"] = ZCompressOSD(allOsd, false); | 513 | resp["Zipped"] = ZCompressOSD(allOsd, false); |
498 | m_log.Debug("[MaterialsDemoModule]: matsCount: " + matsCount.ToString()); | 514 | m_log.Debug("[MaterialsDemoModule]: matsCount: " + matsCount.ToString()); |
499 | 515 | ||
@@ -575,5 +591,72 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
575 | output.Flush(); | 591 | output.Flush(); |
576 | } | 592 | } |
577 | 593 | ||
594 | // FIXME: This code is currently still in UuidGatherer since we cannot use Scene.EventManager as some | ||
595 | // calls to the gatherer are done for objects with no scene. | ||
596 | // /// <summary> | ||
597 | // /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps | ||
598 | // /// </summary> | ||
599 | // /// <param name="part"></param> | ||
600 | // /// <param name="assetUuids"></param> | ||
601 | // private void GatherMaterialsUuids(SceneObjectPart part, IDictionary<UUID, AssetType> assetUuids) | ||
602 | // { | ||
603 | // // scan thru the dynAttrs map of this part for any textures used as materials | ||
604 | // OSD osdMaterials = null; | ||
605 | // | ||
606 | // lock (part.DynAttrs) | ||
607 | // { | ||
608 | // if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) | ||
609 | // { | ||
610 | // OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); | ||
611 | // if (materialsStore == null) | ||
612 | // return; | ||
613 | // | ||
614 | // materialsStore.TryGetValue("Materials", out osdMaterials); | ||
615 | // } | ||
616 | // | ||
617 | // if (osdMaterials != null) | ||
618 | // { | ||
619 | // //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); | ||
620 | // | ||
621 | // if (osdMaterials is OSDArray) | ||
622 | // { | ||
623 | // OSDArray matsArr = osdMaterials as OSDArray; | ||
624 | // foreach (OSDMap matMap in matsArr) | ||
625 | // { | ||
626 | // try | ||
627 | // { | ||
628 | // if (matMap.ContainsKey("Material")) | ||
629 | // { | ||
630 | // OSDMap mat = matMap["Material"] as OSDMap; | ||
631 | // if (mat.ContainsKey("NormMap")) | ||
632 | // { | ||
633 | // UUID normalMapId = mat["NormMap"].AsUUID(); | ||
634 | // if (normalMapId != UUID.Zero) | ||
635 | // { | ||
636 | // assetUuids[normalMapId] = AssetType.Texture; | ||
637 | // //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); | ||
638 | // } | ||
639 | // } | ||
640 | // if (mat.ContainsKey("SpecMap")) | ||
641 | // { | ||
642 | // UUID specularMapId = mat["SpecMap"].AsUUID(); | ||
643 | // if (specularMapId != UUID.Zero) | ||
644 | // { | ||
645 | // assetUuids[specularMapId] = AssetType.Texture; | ||
646 | // //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); | ||
647 | // } | ||
648 | // } | ||
649 | // } | ||
650 | // | ||
651 | // } | ||
652 | // catch (Exception e) | ||
653 | // { | ||
654 | // m_log.Warn("[MaterialsDemoModule]: exception getting materials: " + e.Message); | ||
655 | // } | ||
656 | // } | ||
657 | // } | ||
658 | // } | ||
659 | // } | ||
660 | // } | ||
578 | } | 661 | } |
579 | } \ No newline at end of file | 662 | } \ No newline at end of file |