From 602569e5f701a0e64c2ae253b23c39acb54b00a9 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 1 Dec 2023 23:32:25 +0000 Subject: [PATCH] try to match viewer protocol changes on test feature --- OpenSim/Framework/PrimitiveBaseShape.cs | 2 + .../ClientStack/Linden/UDP/LLClientView.cs | 132 ++++---- .../Materials/MaterialsModule.cs | 308 ++++++++++++++++++ 3 files changed, 370 insertions(+), 72 deletions(-) diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index 8829582470..b3d0d3d055 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -1554,6 +1554,8 @@ namespace OpenSim.Framework int ovrlen = data[indx++]; ovrlen += data[indx++] << 8; overrides[i].data = Utils.BytesToString(data,indx, ovrlen); + if(overrides[i].data.StartsWith("{\"asset")) // ignore old test data + return; indx += ovrlen; } RenderMaterials ??= new Primitive.RenderMaterials(); diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index dc4839ac1c..7f449f96ea 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -5499,62 +5499,43 @@ namespace OpenSim.Region.ClientStack.LindenUDP foreach (SceneObjectPart sop in needMaterials) { Primitive.RenderMaterials.RenderMaterialOverrideEntry[] overrides = sop.Shape.RenderMaterials.overrides; - /* - osUTF8 sbinner = LLSDxmlEncode2.Start(); - LLSDxmlEncode2.AddArray(sbinner); - LLSDxmlEncode2.AddMap(sbinner); - LLSDxmlEncode2.AddElem("object_id", sop.UUID, sbinner); - LLSDxmlEncode2.AddElem("region_handle_low", (int)m_scene.RegionInfo.WorldLocX, sbinner); - LLSDxmlEncode2.AddElem("region_handle_high", (int)m_scene.RegionInfo.WorldLocY, sbinner); - LLSDxmlEncode2.AddArray("sides", sbinner); - foreach (Primitive.RenderMaterials.RenderMaterialOverrideEntry ovr in overrides) - LLSDxmlEncode2.AddElem(ovr.te_index, sbinner); - LLSDxmlEncode2.AddEndArray(sbinner); - LLSDxmlEncode2.AddArray("gltf_json", sbinner); - foreach (Primitive.RenderMaterials.RenderMaterialOverrideEntry ovr in overrides) - { - LLSDxmlEncode2.AddElem(ovr.data, sbinner); - } - LLSDxmlEncode2.AddEndArray(sbinner); - LLSDxmlEncode2.AddEndMapAndArray(sbinner); - LLSDxmlEncode2.AddEnd(sbinner); - */ - OSDMap data = new OSDMap(6); - data["local_id"] = sop.LocalId; - data["object_id"] = sop.UUID; - data["region_handle_x"]= (int)m_scene.RegionInfo.WorldLocX; - data["region_handle_y"]= (int)m_scene.RegionInfo.WorldLocY; + + OSDMap data = new OSDMap(3); + data["id"] = (int)sop.LocalId; OSDArray sides = new OSDArray(); - OSDArray gltf = new OSDArray(); + OSDArray sidesdata = new OSDArray(); foreach (Primitive.RenderMaterials.RenderMaterialOverrideEntry ovr in overrides) { sides.Add(ovr.te_index); - gltf.Add(ovr.data); + sidesdata.Add(new OSDllsdxml(ovr.data)); } - data["sides"] = sides; - data["gltf_json"] = gltf; + data["te"] = sides; + data["od"] = sidesdata; - string inner = OSDParser.SerializeLLSDNotationFull(data); + string inner = OSDParser.SerializeLLSDNotation(data); + if (inner.Length < 4) + continue; - osUTF8 sb = eq.StartEvent("LargeGenericMessage"); - LLSDxmlEncode2.AddArrayAndMap("AgentData", sb); - LLSDxmlEncode2.AddElem("AgentID", m_agentId, sb); - //LLSDxmlEncode2.AddElem("TransactionID", UUID.Zero, sb); - //LLSDxmlEncode2.AddElem("SessionID", m_sessionId, sb); - LLSDxmlEncode2.AddEndMapAndArray(sb); + byte[] innerB = Util.UTF8NBGetbytes(inner); + if (innerB.Length > 4096 - 32) + { + m_log.Debug($"[LLCLIENTVIEW]: GenericStreamingMessage packet too large ({innerB.Length})"); + continue; + } - LLSDxmlEncode2.AddArrayAndMap("MethodData", sb); - LLSDxmlEncode2.AddElem("Method", "GLTFMaterialOverride", sb); - LLSDxmlEncode2.AddElem("Invoice", UUID.Zero, sb); - LLSDxmlEncode2.AddEndMapAndArray(sb); + UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint); + byte[] dataptr = buf.Data; - LLSDxmlEncode2.AddArrayAndMap("ParamList", sb); - //LLSDxmlEncode2.AddElem("Parameter", sbinner, sb); - LLSDxmlEncode2.AddElem("Parameter", inner, sb); - LLSDxmlEncode2.AddEndMapAndArray(sb); + //setup header + Buffer.BlockCopy(GenericStreamingMessageHeader, 0, dataptr, 0, 7); + Utils.UInt16ToBytes(16757, dataptr, 7); + dataptr[9] = (byte)(innerB.Length); + dataptr[10] = (byte)(innerB.Length >> 8); - //OSUTF8Cached.Release(sbinner); - eq.Enqueue(eq.EndEventToBytes(sb), AgentId); + Buffer.BlockCopy(innerB, 0, dataptr, 11, innerB.Length); + buf.DataLength = innerB.Length + 11; + // send it + m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task); } } #endregion Packet Sending @@ -5583,35 +5564,42 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion } + static private readonly byte[] GenericStreamingMessageHeader = new byte[] { + Helpers.MSG_RELIABLE, + 0, 0, 0, 0, // sequence number + 0, // extra + 31 // ID 31 (high frequency) + }; + // hack.. dont use -/* - public void SendPartFullUpdate(ISceneEntity ent, uint? parentID) - { - if (ent is SceneObjectPart) - { - SceneObjectPart part = (SceneObjectPart)ent; - ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); - packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; - packet.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f); - packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; - - ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, mysp); - if (parentID.HasValue) + /* + public void SendPartFullUpdate(ISceneEntity ent, uint? parentID) { - blk.ParentID = parentID.Value; + if (ent is SceneObjectPart) + { + SceneObjectPart part = (SceneObjectPart)ent; + ObjectUpdatePacket packet = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); + packet.RegionData.RegionHandle = m_scene.RegionInfo.RegionHandle; + packet.RegionData.TimeDilation = Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f); + packet.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; + + ObjectUpdatePacket.ObjectDataBlock blk = CreatePrimUpdateBlock(part, mysp); + if (parentID.HasValue) + { + blk.ParentID = parentID.Value; + } + + packet.ObjectData[0] = blk; + + OutPacket(packet, ThrottleOutPacketType.Task, true); + } + + // m_log.DebugFormat( + // "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}", + // updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name); + // } - - packet.ObjectData[0] = blk; - - OutPacket(packet, ThrottleOutPacketType.Task, true); - } - -// m_log.DebugFormat( -// "[LLCLIENTVIEW]: Sent {0} updates in ProcessEntityUpdates() for {1} {2} in {3}", -// updatesThisCall, Name, SceneAgent.IsChildAgent ? "child" : "root", Scene.Name); -// - } -*/ + */ public void ReprioritizeUpdates() { m_entityUpdates.Reprioritize(UpdatePriorityHandler); diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs index 77a2aec34e..5fcac02234 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsModule.cs @@ -1076,9 +1076,317 @@ 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) { + OSD tst; + try + { + tst = OSDParser.DeserializeJson(data); + if(tst is not OSDMap mainArr) + return false; + OSD tmposd; + if (!mainArr.TryGetValue("asset", out tmposd) ) + return false; + + if (mainArr.TryGetValue("materials", out tmposd) && tmposd is OSDArray materialsArray && materialsArray.Count > 0 && materialsArray[0] is OSDMap material) + { + OSDMap outosd = new(); + OSDArray ti = new OSDArray(4); + + UUID[] texturesURIs = null; + if (mainArr.TryGetValue("images", out tmposd) && tmposd is OSDArray imagesArray && imagesArray.Count > 0) + { + 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(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]; + } + } + } + } + + 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 (pmrMap.TryGetValue("baseColorTexture", out tmposd) && tmposd is OSDMap pmrMapbct && pmrMapbct.Count > 0) + { + if (pmrMapbct.TryGetValue("index", out tmposd) && tmposd is OSDInteger pmrMapbcti) + { + int v = pmrMapbcti.value; + if (v < texturesURIs.Length) + { + textureIDs[0] = texturesURIs[v]; + textureIDchanged[0] = true; + texturesChanged = true; + } + } + 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) + { + if (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 (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; + } + while (ti.Count < 2) + ti.Add(new OSD()); + if (ti.Count > 2) + ti[2] = tmpmap; + else + ti.Add(tmpmap); + } + } + } + + if (material.TryGetValue("emissiveTexture", out tmposd) && tmposd is OSDMap etMap && etMap.Count > 0) + { + if (etMap.TryGetValue("index", out tmposd) && tmposd is OSDInteger etMapi) + { + int v = etMapi.value; + if (v < texturesURIs.Length) + { + textureIDs[3] = texturesURIs[v]; + textureIDchanged[3] = true; + texturesChanged = true; + } + } + if (etMap.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 < 3) + ti.Add(new OSD()); + if (ti.Count > 4) + ti[3] = tmpmap; + else + 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 + return false; + + } + catch (Exception e) + { + return false; + } + if (overrides is null) { var entries = new RenderMaterials.RenderMaterialOverrideEntry[1];