rather than converting existing materials to assets, just retrieve them and make them available for viewing. Any new materials added to the scene will become assets.

master-beforevarregion
dahlia 2014-01-20 13:57:14 -08:00
parent 719810e9d8
commit af58631f00
1 changed files with 12 additions and 32 deletions

View File

@ -149,12 +149,10 @@ namespace OpenSim.Region.OptionalModules.Materials
} }
/// <summary> /// <summary>
/// Searches the part for any legacy materials stored in DynAttrs and converts them to assets, replacing /// Finds any legacy materials stored in DynAttrs that may exist for this part and add them to 'm_regionMaterials'.
/// the MaterialIDs in the TextureEntries for the part.
/// Deletes the legacy materials from the part as they are no longer needed.
/// </summary> /// </summary>
/// <param name="part"></param> /// <param name="part"></param>
private void ConvertLegacyMaterialsInPart(SceneObjectPart part) private void GetLegacyStoredMaterialsInPart(SceneObjectPart part)
{ {
if (part.DynAttrs == null) if (part.DynAttrs == null)
return; return;
@ -183,10 +181,6 @@ namespace OpenSim.Region.OptionalModules.Materials
if (matsArr == null) if (matsArr == null)
return; return;
var te = new Primitive.TextureEntry(part.Shape.TextureEntry, 0, part.Shape.TextureEntry.Length);
if (te == null)
return;
foreach (OSD elemOsd in matsArr) foreach (OSD elemOsd in matsArr)
{ {
if (elemOsd != null && elemOsd is OSDMap) if (elemOsd != null && elemOsd is OSDMap)
@ -194,32 +188,18 @@ namespace OpenSim.Region.OptionalModules.Materials
OSDMap matMap = elemOsd as OSDMap; OSDMap matMap = elemOsd as OSDMap;
if (matMap.ContainsKey("ID") && matMap.ContainsKey("Material")) if (matMap.ContainsKey("ID") && matMap.ContainsKey("Material"))
{ {
UUID id = matMap["ID"].AsUUID(); try
OSDMap material = (OSDMap)matMap["Material"]; {
bool used = false; lock (m_regionMaterials)
m_regionMaterials[matMap["ID"].AsUUID()] = (OSDMap)matMap["Material"];
foreach (var face in te.FaceTextures) }
if (face != null && face.MaterialID == id) catch (Exception e)
used = true; {
m_log.Warn("[Materials]: exception decoding persisted legacy material: " + e.ToString());
if (used)
{ // store legacy material in new asset format, and update the part texture entry with the new hashed UUID
var newId = StoreMaterialAsAsset(part.CreatorID, material, part);
foreach (var face in te.FaceTextures)
if (face != null && face.MaterialID == id)
face.MaterialID = newId;
} }
} }
} }
} }
part.Shape.TextureEntry = te.GetBytes();
part.ParentGroup.HasGroupChanged = true;
part.ScheduleFullUpdate();
lock (part.DynAttrs)
part.DynAttrs.RemoveStore("OpenSim", "Materials");
} }
/// <summary> /// <summary>
@ -230,12 +210,12 @@ namespace OpenSim.Region.OptionalModules.Materials
if (part.Shape == null) if (part.Shape == null)
return; return;
ConvertLegacyMaterialsInPart(part);
var te = new Primitive.TextureEntry(part.Shape.TextureEntry, 0, part.Shape.TextureEntry.Length); var te = new Primitive.TextureEntry(part.Shape.TextureEntry, 0, part.Shape.TextureEntry.Length);
if (te == null) if (te == null)
return; return;
GetLegacyStoredMaterialsInPart(part);
GetStoredMaterialInFace(part, te.DefaultTexture); GetStoredMaterialInFace(part, te.DefaultTexture);
foreach (Primitive.TextureEntryFace face in te.FaceTextures) foreach (Primitive.TextureEntryFace face in te.FaceTextures)