diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index b3d0d3d055..fb9c416ec0 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -971,15 +971,11 @@ namespace OpenSim.Framework TotalBytesLength += 9 + 2 + 4; // data } - if (RenderMaterials != null) + bool hasRenderMaterials = RenderMaterials is not null && RenderMaterials.entries is not null && RenderMaterials.entries.Length > 0; + if (hasRenderMaterials) { ExtraParamsNum++; - if (RenderMaterials.entries == null || RenderMaterials.entries.Length == 0) - TotalBytesLength++; - else - { - TotalBytesLength += 1 + 17 * RenderMaterials.entries.Length + 2 + 4; // data - } + TotalBytesLength += 1 + 17 * RenderMaterials.entries.Length + 2 + 4; // data } byte[] safeReturnBytes = new byte[TotalBytesLength]; @@ -1067,7 +1063,7 @@ namespace OpenSim.Framework *returnBytes++ = ReflectionProbe.Flags; } - if (RenderMaterials != null && RenderMaterials.entries != null && RenderMaterials.entries.Length > 0) + if (hasRenderMaterials) { *returnBytes = MaterialsEP; returnBytes += 2; @@ -1508,10 +1504,12 @@ namespace OpenSim.Framework // byte: high entry override utf8 length // utf8 bytes: override - if (RenderMaterials is null || RenderMaterials.overrides is null || RenderMaterials.overrides.Length == 0) + if (RenderMaterials is null) return null; - osUTF8 sb = OSUTF8Cached.Acquire(); + if (RenderMaterials.overrides is null || RenderMaterials.overrides.Length == 0) + return new byte[] { 0 }; // store so outdated viewer caches can be updated + int nentries = 0; for (int i = 0; i < RenderMaterials.overrides.Length; i++) { @@ -1519,8 +1517,9 @@ namespace OpenSim.Framework nentries++; } if(nentries == 0) - return null; + return new byte[] { 0 }; + osUTF8 sb = OSUTF8Cached.Acquire(); sb.Append((byte)nentries); for (int i = 0; i < RenderMaterials.overrides.Length; i++) { @@ -1537,13 +1536,20 @@ namespace OpenSim.Framework public void RenderMaterialsOvrFromRawBin(byte[] data) { - if (RenderMaterials is not null && RenderMaterials.overrides != null) + if (RenderMaterials is not null && RenderMaterials.overrides is not null) RenderMaterials.overrides = null; - if (data is null || data.Length < 16) + + if (data is null || data.Length < 1) return; int nentries = data[0]; - if(nentries > 128) + if (nentries > 128) return; + if (nentries == 0) // for outdated viewer caches + { + RenderMaterials ??= new Primitive.RenderMaterials(); + return; + } + int indx = 1; Primitive.RenderMaterials.RenderMaterialOverrideEntry[] overrides = new Primitive.RenderMaterials.RenderMaterialOverrideEntry[nentries]; try @@ -1558,12 +1564,14 @@ namespace OpenSim.Framework return; indx += ovrlen; } - RenderMaterials ??= new Primitive.RenderMaterials(); - RenderMaterials.overrides = overrides; } catch { + return; } + + RenderMaterials ??= new Primitive.RenderMaterials(); + RenderMaterials.overrides = overrides; } /// diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index b425132c15..86b8424047 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -4970,7 +4970,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP istree = (part.Shape.PCode == (byte)PCode.Grass || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Tree); if((updateFlags & PrimUpdateFlags.MaterialOvr) != 0) - hasMaterialOverride = !istree; + hasMaterialOverride = !istree && part.Shape.RenderMaterials is not null; } else if (update.Entity is ScenePresence presence) { @@ -5495,12 +5495,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP { foreach (SceneObjectPart sop in needMaterials) { - OSDMap data = new(3); - data["id"] = (int)sop.LocalId; + if(sop.Shape.RenderMaterials is null) + continue; + OSDMap data = new(3) + { + ["id"] = (int)sop.LocalId + }; OSDArray sides = new(); OSDArray sidesdata = new(); - if(sop.Shape.RenderMaterials is not null && - sop.Shape.RenderMaterials.overrides is not null && + if( sop.Shape.RenderMaterials.overrides is not null && sop.Shape.RenderMaterials.overrides.Length > 0) { foreach (Primitive.RenderMaterials.RenderMaterialOverrideEntry ovr in sop.Shape.RenderMaterials.overrides) diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs index da3fef7b43..5e885f8947 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs @@ -933,61 +933,63 @@ namespace OpenSim.Region.OptionalModules.Materials else overridedata = string.Empty; + bool changed = false; if (map.TryGetValue("asset_id", out tmp)) { UUID assetID = tmp.AsUUID(); if (assetID.IsNotZero()) { - if (pbs.RenderMaterials is null) + pbs.RenderMaterials ??= new Primitive.RenderMaterials(); + + if (pbs.RenderMaterials.entries is null) { var entries = new Primitive.RenderMaterials.RenderMaterialEntry[1]; entries[0].te_index = (byte)side; entries[0].id = assetID; - pbs.RenderMaterials = new Primitive.RenderMaterials { entries = entries }; + pbs.RenderMaterials.entries = entries; + changed = true; } else { - if (pbs.RenderMaterials.entries is null) + int indx = 0; + while (indx < pbs.RenderMaterials.entries.Length) { - var entries = new Primitive.RenderMaterials.RenderMaterialEntry[1]; - entries[0].te_index = (byte)side; - entries[0].id = assetID; - pbs.RenderMaterials.entries = entries; - } - else - { - int indx = 0; - while (indx < pbs.RenderMaterials.entries.Length) + if (pbs.RenderMaterials.entries[indx].te_index == side) { - if (pbs.RenderMaterials.entries[indx].te_index == side) + if(pbs.RenderMaterials.entries[indx].id .NotEqual(assetID)) { pbs.RenderMaterials.entries[indx].id = assetID; - break; + changed = true; } - indx++; - } - if (indx == pbs.RenderMaterials.entries.Length) - { - Array.Resize(ref pbs.RenderMaterials.entries, indx + 1); - pbs.RenderMaterials.entries[indx].te_index = (byte)side; - pbs.RenderMaterials.entries[indx].id = assetID; + break; } + indx++; + } + if (indx == pbs.RenderMaterials.entries.Length) + { + Array.Resize(ref pbs.RenderMaterials.entries, indx + 1); + pbs.RenderMaterials.entries[indx].te_index = (byte)side; + pbs.RenderMaterials.entries[indx].id = assetID; + changed = true; } } if (string.IsNullOrEmpty(overridedata)) - RemoveMaterialOverride(ref pbs.RenderMaterials.overrides, side); + changed |= RemoveMaterialOverride(ref pbs.RenderMaterials.overrides, side); else - AddMaterialOverride(ref pbs.RenderMaterials.overrides, overridedata, side); - - changedSOPs.Add(sop); + changed |= AddMaterialOverride(ref pbs.RenderMaterials.overrides, overridedata, side); + + if(changed) + changedSOPs.Add(sop); } else if(pbs.RenderMaterials is not null) { - bool changed = RemoveMaterialEntry(ref pbs.RenderMaterials.entries, side); + changed = RemoveMaterialEntry(ref pbs.RenderMaterials.entries, side); changed |= RemoveMaterialOverride(ref pbs.RenderMaterials.overrides, side); - if(pbs.RenderMaterials.entries is null && pbs.RenderMaterials.overrides is null) - pbs.RenderMaterials = null; + //if(pbs.RenderMaterials.entries is null && pbs.RenderMaterials.overrides is null) + // pbs.RenderMaterials = null; + // keep not null so viewer caches can be updated + if(changed) changedSOPs.Add(sop); } @@ -996,11 +998,12 @@ namespace OpenSim.Region.OptionalModules.Materials { if (string.IsNullOrEmpty(overridedata)) { - + if (RemoveMaterialOverride(ref pbs.RenderMaterials.overrides, side)) + changedSOPs.Add(sop); } else { - if(AddMaterialOverride(ref pbs.RenderMaterials.overrides, overridedata, side)) + if (AddMaterialOverride(ref pbs.RenderMaterials.overrides, overridedata, side)) changedSOPs.Add(sop); } } @@ -1056,8 +1059,7 @@ namespace OpenSim.Region.OptionalModules.Materials return false; int indx = 0; - while(overrides[indx].te_index != side && indx < overrides.Length) - indx++; + while( overrides[indx].te_index != side && ++indx < overrides.Length); if (indx >= overrides.Length) return false; @@ -1076,7 +1078,6 @@ namespace OpenSim.Region.OptionalModules.Materials } return true; } - public static readonly UUID llUUIDNull = new("ffffffff-ffff-ffff-ffff-ffffffffffff"); private static bool AddMaterialOverride(ref RenderMaterials.RenderMaterialOverrideEntry[] overrides, string data, int side) { @@ -1086,147 +1087,67 @@ namespace OpenSim.Region.OptionalModules.Materials tst = OSDParser.DeserializeJson(data); if(tst is not OSDMap mainArr) return false; + OSD tmposd; - if (!mainArr.TryGetValue("asset", out tmposd) ) + + if (!mainArr.TryGetValue("materials", out tmposd) || + tmposd is not OSDArray materialsArray || + materialsArray.Count < 1 || + materialsArray[0] is not OSDMap material) return false; - if (mainArr.TryGetValue("materials", out tmposd) && tmposd is OSDArray materialsArray && materialsArray.Count > 0 && materialsArray[0] is OSDMap material) + UUID[] texturesURIs = null; + if (mainArr.TryGetValue("images", out tmposd) && tmposd is OSDArray imagesArray && imagesArray.Count > 0 && imagesArray.Count < 16) { - OSDMap outosd = new(); - OSDArray ti = new OSDArray(4); - - UUID[] texturesURIs = null; - if (mainArr.TryGetValue("images", out tmposd) && tmposd is OSDArray imagesArray && imagesArray.Count > 0) + Span imageURIs = stackalloc UUID[imagesArray.Count]; + for (int i = 0; i < imagesArray.Count; i++) { - UUID[] imageURIs = new UUID[imagesArray.Count]; - for (int i = 0; i < imagesArray.Count; i++) + if (imagesArray[i] is OSDMap tmpim && tmpim.TryGetValue("uri", out OSD tmpimuri) && tmpimuri is OSDString tmpimuristr) { - if (imagesArray[i] is OSDMap tmpim && tmpim.TryGetValue("uri", out OSD tmpimuri) && tmpimuri is OSDString tmpimuristr) - { - if(UUID.TryParse(tmpimuristr.value, out UUID tmpid)) - imageURIs[i] = tmpid; - else - imageURIs[i] = UUID.Zero; - } - else - imageURIs[i] = UUID.Zero; - } - - if (mainArr.TryGetValue("textures", out tmposd) && tmposd is OSDArray texturesArray && texturesArray.Count > 0) - { - texturesURIs = new UUID[texturesArray.Count]; - for (int i = 0; i < texturesArray.Count; i++) - { - if (texturesArray[i] is OSDMap tmptm && tmptm.TryGetValue("source", out OSD tmptmsrc) && tmptmsrc is OSDInteger tmptmsrci) - { - int v = tmptmsrci.value; - if( v < imageURIs.Length) - texturesURIs[i] = imageURIs[v]; - } - } + if(UUID.TryParse(tmpimuristr.value, out UUID tmpid)) + imageURIs[i] = tmpid; } } - bool texturesChanged = false; - UUID[] textureIDs = new UUID[4]; - bool[] textureIDchanged = new bool[4]; - if (material.TryGetValue("pbrMetallicRoughness", out tmposd) && tmposd is OSDMap pmrMap && pmrMap.Count > 0) + if (mainArr.TryGetValue("textures", out tmposd) && tmposd is OSDArray texturesArray && texturesArray.Count > 0 && texturesArray.Count < 16) { - if (pmrMap.TryGetValue("baseColorTexture", out tmposd) && tmposd is OSDMap pmrMapbct && pmrMapbct.Count > 0) + texturesURIs = new UUID[texturesArray.Count]; + for (int i = 0; i < texturesArray.Count; i++) { - if (pmrMapbct.TryGetValue("index", out tmposd) && tmposd is OSDInteger pmrMapbcti) + if (texturesArray[i] is OSDMap tmptm && tmptm.TryGetValue("source", out OSD tmptmsrc) && tmptmsrc is OSDInteger tmptmsrci) { - int v = pmrMapbcti.value; - if (v < texturesURIs.Length) - { - textureIDs[0] = texturesURIs[v]; - textureIDchanged[0] = true; - texturesChanged = true; - } + int v = tmptmsrci.value; + if( v < imageURIs.Length) + texturesURIs[i] = imageURIs[v]; } - if (pmrMapbct.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) - { - if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) - { - OSDMap tmpmap = new OSDMap(); - if (bctr.TryGetValue("offset", out tmposd) && tmposd is OSDArray bcoffset) - { - tmpmap["o"] = bcoffset; - } - if (bctr.TryGetValue("rotation", out tmposd) && tmposd is OSDReal bcrotation) - { - tmpmap["r"] = bcrotation; - } - if (bctr.TryGetValue("scale", out tmposd) && tmposd is OSDArray bcscale) - { - tmpmap["s"] = bcscale; - } - ti.Add(tmpmap); - } - } - } - if (pmrMap.TryGetValue("metallicRoughnessTexture", out tmposd) && tmposd is OSDMap pmrMapmrt && pmrMapmrt.Count > 0) - { - if (pmrMapmrt.TryGetValue("index", out tmposd) && tmposd is OSDInteger pmrMapbcti) - { - int v = pmrMapbcti.value; - if (v < texturesURIs.Length) - { - textureIDs[2] = texturesURIs[v]; - textureIDchanged[2] = true; - texturesChanged = true; - } - } - if (pmrMapmrt.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) - { - if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) - { - OSDMap tmpmap = new OSDMap(); - if (bctr.TryGetValue("offset", out tmposd) && tmposd is OSDArray bcoffset) - { - tmpmap["o"] = bcoffset; - } - if (bctr.TryGetValue("rotation", out tmposd) && tmposd is OSDReal bcrotation) - { - tmpmap["r"] = bcrotation; - } - if (bctr.TryGetValue("scale", out tmposd) && tmposd is OSDArray bcscale) - { - tmpmap["s"] = bcscale; - } - while(ti.Count < 2) - ti.Add(new OSD()); - ti.Add(tmpmap); - } - } - } - if (pmrMap.TryGetValue("baseColorFactor", out tmposd) && tmposd is OSDArray baseColorFactor) - { - outosd["bc"] = baseColorFactor; - } - if (pmrMap.TryGetValue("metallicFactor", out tmposd) && tmposd is OSDReal metallicFactor) - { - outosd["mf"] = metallicFactor; - } - if (pmrMap.TryGetValue("roughnessFactor", out tmposd) && tmposd is OSDReal roughnessFactor) - { - outosd["rf"] = roughnessFactor; } } + } - if (material.TryGetValue("normalTexture", out tmposd) && tmposd is OSDMap ntMap && ntMap.Count > 0) + bool hasTexURIS = texturesURIs is not null; + + OSDMap outosd = new(); + OSDArray ti = new OSDArray(4); + + bool texturesChanged = false; + Span textureIDs = stackalloc UUID[4]; + Span textureIDchanged = stackalloc bool[4]; + + if (material.TryGetValue("pbrMetallicRoughness", out tmposd) && tmposd is OSDMap pmrMap && pmrMap.Count > 0) + { + if (pmrMap.TryGetValue("baseColorTexture", out tmposd) && tmposd is OSDMap pmrMapbct && pmrMapbct.Count > 0) { - if (ntMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger ntMapi) + if (hasTexURIS && pmrMapbct.TryGetValue("index", out tmposd) && tmposd is OSDInteger pmrMapbcti) { - int v = ntMapi.value; + int v = pmrMapbcti.value; if (v < texturesURIs.Length) { - textureIDs[1] = texturesURIs[v]; - textureIDchanged[1] = true; + textureIDs[0] = texturesURIs[v]; + textureIDchanged[0] = true; texturesChanged = true; } } - if (ntMap.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) + if (pmrMapbct.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) { if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) { @@ -1243,23 +1164,15 @@ namespace OpenSim.Region.OptionalModules.Materials { tmpmap["s"] = bcscale; } - if (ti.Count < 2) - { - if (ti.Count == 0) - ti.Add(new OSD()); - ti.Add(tmpmap); - } - else - ti[1] = tmpmap; + ti.Add(tmpmap); } } } - - if (material.TryGetValue("occlusionTexture", out tmposd) && tmposd is OSDMap otMap && otMap.Count > 0) + if (pmrMap.TryGetValue("metallicRoughnessTexture", out tmposd) && tmposd is OSDMap pmrMapmrt && pmrMapmrt.Count > 0) { - if (otMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger otMapi) + if (hasTexURIS && pmrMapmrt.TryGetValue("index", out tmposd) && tmposd is OSDInteger pmrMapbcti) { - int v = otMapi.value; + int v = pmrMapbcti.value; if (v < texturesURIs.Length) { textureIDs[2] = texturesURIs[v]; @@ -1267,7 +1180,7 @@ namespace OpenSim.Region.OptionalModules.Materials texturesChanged = true; } } - if (otMap.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) + if (pmrMapmrt.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) { if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) { @@ -1284,103 +1197,194 @@ namespace OpenSim.Region.OptionalModules.Materials { tmpmap["s"] = bcscale; } + while(ti.Count < 2) + ti.Add(new OSD()); + ti.Add(tmpmap); + } + } + } + if (pmrMap.TryGetValue("baseColorFactor", out tmposd) && tmposd is OSDArray baseColorFactor) + { + outosd["bc"] = baseColorFactor; + } + if (pmrMap.TryGetValue("metallicFactor", out tmposd) && tmposd is OSDReal metallicFactor) + { + outosd["mf"] = metallicFactor; + } + if (pmrMap.TryGetValue("roughnessFactor", out tmposd) && tmposd is OSDReal roughnessFactor) + { + outosd["rf"] = roughnessFactor; + } + } + + if (material.TryGetValue("normalTexture", out tmposd) && tmposd is OSDMap ntMap && ntMap.Count > 0) + { + if (hasTexURIS && ntMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger ntMapi) + { + int v = ntMapi.value; + if (v < texturesURIs.Length) + { + textureIDs[1] = texturesURIs[v]; + textureIDchanged[1] = true; + texturesChanged = true; + } + } + if (ntMap.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) + { + if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) + { + OSDMap tmpmap = new OSDMap(); + if (bctr.TryGetValue("offset", out tmposd) && tmposd is OSDArray bcoffset) + { + tmpmap["o"] = bcoffset; + } + if (bctr.TryGetValue("rotation", out tmposd) && tmposd is OSDReal bcrotation) + { + tmpmap["r"] = bcrotation; + } + if (bctr.TryGetValue("scale", out tmposd) && tmposd is OSDArray bcscale) + { + tmpmap["s"] = bcscale; + } + if (ti.Count < 2) + { + if (ti.Count == 0) + ti.Add(new OSD()); + ti.Add(tmpmap); + } + else + ti[1] = tmpmap; + } + } + } + + if (material.TryGetValue("occlusionTexture", out tmposd) && tmposd is OSDMap otMap && otMap.Count > 0) + { + if (hasTexURIS && otMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger otMapi) + { + int v = otMapi.value; + if (v < texturesURIs.Length) + { + textureIDs[2] = texturesURIs[v]; + textureIDchanged[2] = true; + texturesChanged = true; + } + } + if (otMap.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) + { + if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) + { + OSDMap tmpmap = new OSDMap(); + if (bctr.TryGetValue("offset", out tmposd) && tmposd is OSDArray bcoffset) + { + tmpmap["o"] = bcoffset; + } + if (bctr.TryGetValue("rotation", out tmposd) && tmposd is OSDReal bcrotation) + { + tmpmap["r"] = bcrotation; + } + if (bctr.TryGetValue("scale", out tmposd) && tmposd is OSDArray bcscale) + { + tmpmap["s"] = bcscale; + } + if (ti.Count > 2) + ti[2] = tmpmap; + else + { while (ti.Count < 2) ti.Add(new OSD()); - if (ti.Count > 2) - ti[2] = tmpmap; - else - ti.Add(tmpmap); + ti.Add(tmpmap); } } } + } - if (material.TryGetValue("emissiveTexture", out tmposd) && tmposd is OSDMap etMap && etMap.Count > 0) + if (material.TryGetValue("emissiveTexture", out tmposd) && tmposd is OSDMap etMap && etMap.Count > 0) + { + if (hasTexURIS && etMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger etMapi) { - if (etMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger etMapi) + int v = etMapi.value; + if (v < texturesURIs.Length) { - int v = etMapi.value; - if (v < texturesURIs.Length) - { - textureIDs[3] = texturesURIs[v]; - textureIDchanged[3] = true; - texturesChanged = true; - } + textureIDs[3] = texturesURIs[v]; + textureIDchanged[3] = true; + texturesChanged = true; } - if (etMap.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) + } + if (etMap.TryGetValue("extensions", out tmposd) && tmposd is OSDMap bcext) + { + if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) { - if (bcext.TryGetValue("KHR_texture_transform", out tmposd) && tmposd is OSDMap bctr) + OSDMap tmpmap = new OSDMap(); + if (bctr.TryGetValue("offset", out tmposd) && tmposd is OSDArray bcoffset) + { + tmpmap["o"] = bcoffset; + } + if (bctr.TryGetValue("rotation", out tmposd) && tmposd is OSDReal bcrotation) + { + tmpmap["r"] = bcrotation; + } + if (bctr.TryGetValue("scale", out tmposd) && tmposd is OSDArray bcscale) + { + tmpmap["s"] = bcscale; + } + if (ti.Count > 3) + ti[3] = tmpmap; + else { - OSDMap tmpmap = new OSDMap(); - if (bctr.TryGetValue("offset", out tmposd) && tmposd is OSDArray bcoffset) - { - tmpmap["o"] = bcoffset; - } - if (bctr.TryGetValue("rotation", out tmposd) && tmposd is OSDReal bcrotation) - { - tmpmap["r"] = bcrotation; - } - if (bctr.TryGetValue("scale", out tmposd) && tmposd is OSDArray bcscale) - { - tmpmap["s"] = bcscale; - } while (ti.Count < 3) ti.Add(new OSD()); - if (ti.Count > 4) - ti[3] = tmpmap; - else - ti.Add(tmpmap); + ti.Add(tmpmap); } } } - - if (material.TryGetValue("alphaMode", out tmposd) && tmposd is OSDString aMode) - { - outosd["am"] = aMode.value switch - { - "BLEND" => 1, - "MASK" => 2, - _ => 0 - }; - } - - if (material.TryGetValue("alphaCutoff", out tmposd) && tmposd is OSDReal alphaCutoff) - { - outosd["ac"] = alphaCutoff; - } - - if (material.TryGetValue("emissiveFactor", out tmposd) && tmposd is OSDArray emissiveFactor) - { - outosd["ec"] = emissiveFactor; - } - if (material.TryGetValue("doubleSided", out tmposd) && tmposd is OSDBoolean doubleSided) - { - outosd["ds"] = doubleSided; - } - - if (texturesChanged) - { - OSDArray tex = new(textureIDs.Length); - for(int i = 0; i < textureIDs.Length; i++) - { - if (textureIDchanged[i]) - tex.Add(textureIDs[i]); - else - tex.Add(new OSD()); - } - outosd["tex"] = tex; - } - - if(ti.Count > 0) - outosd["ti"] = ti; - - if (outosd.Count == 0) - return false; - - data = OSDParser.SerializeLLSDNotation(outosd); } - else + + if (material.TryGetValue("alphaMode", out tmposd) && tmposd is OSDString aMode) + { + outosd["am"] = aMode.value switch + { + "BLEND" => 1, + "MASK" => 2, + _ => 0 + }; + } + + if (material.TryGetValue("alphaCutoff", out tmposd) && tmposd is OSDReal alphaCutoff) + { + outosd["ac"] = alphaCutoff; + } + + if (material.TryGetValue("emissiveFactor", out tmposd) && tmposd is OSDArray emissiveFactor) + { + outosd["ec"] = emissiveFactor; + } + if (material.TryGetValue("doubleSided", out tmposd) && tmposd is OSDBoolean doubleSided) + { + outosd["ds"] = doubleSided; + } + + if (texturesChanged) + { + OSDArray tex = new(textureIDs.Length); + for(int i = 0; i < textureIDs.Length; i++) + { + if (textureIDchanged[i]) + tex.Add(textureIDs[i]); + else + tex.Add(new OSD()); + } + outosd["tex"] = tex; + } + + if(ti.Count > 0) + outosd["ti"] = ti; + + if (outosd.Count == 0) return false; + data = OSDParser.SerializeLLSDNotation(outosd); + } catch { @@ -1401,22 +1405,20 @@ namespace OpenSim.Region.OptionalModules.Materials { if (overrides[indx].te_index == side) { - overrides[indx].data = data; - return true; + if(overrides[indx].data != data) + { + overrides[indx].data = data; + return true; + } + return false; } indx++; } - if (indx == overrides.Length) - { - Array.Resize(ref overrides, indx + 1); - overrides[indx].te_index = (byte)side; - if(overrides[indx].data != data) - { - overrides[indx].data = data; - return true; - } - } - return false; + + Array.Resize(ref overrides, indx + 1); + overrides[indx].te_index = (byte)side; + overrides[indx].data = data; + return true; } } }