From 1f822c60778367e964b053104fe179c4dab4c8e0 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 15 Jul 2020 22:56:09 +0100 Subject: [PATCH] allow the use of Sky or water from a asset, not just full daycycle. This may need more work --- OpenSim/Framework/ViewerDaycycle.cs | 61 ++++++++++++++++++- OpenSim/Framework/ViewerEnvironment.cs | 40 +++++++++++- .../World/LightShare/EnvironmentModule.cs | 16 +++-- 3 files changed, 107 insertions(+), 10 deletions(-) diff --git a/OpenSim/Framework/ViewerDaycycle.cs b/OpenSim/Framework/ViewerDaycycle.cs index 44ebbda54d..f3ea1775ec 100644 --- a/OpenSim/Framework/ViewerDaycycle.cs +++ b/OpenSim/Framework/ViewerDaycycle.cs @@ -137,6 +137,59 @@ namespace OpenSim.Framework array[3] = new OSDMap(); } + public bool replaceWaterFromOSD(string name, OSDMap map) + { + WaterData water = new WaterData(); + if(string.IsNullOrWhiteSpace(name)) + name = "Water"; + try + { + water.FromOSD(name, map); + } + catch + { + return false; + } + waterframes.Clear(); + waterframes[name] = water; + waterTrack.Clear(); + TrackEntry t = new TrackEntry() + { + time = -1, + frameName = name + }; + waterTrack.Add(t); + return true; + } + + public bool replaceSkyFromOSD(string name, OSDMap map) + { + SkyData sky = new SkyData(); + if (string.IsNullOrWhiteSpace(name)) + name = "Sky"; + try + { + sky.FromOSD(name, map); + } + catch + { + return false; + } + skyframes.Clear(); + skyframes[name] = sky; + + TrackEntry t = new TrackEntry() + { + time = -1, + frameName = name + }; + skyTrack0.Clear(); + skyTrack0.Add(t); + skyTracks = new List[3]; + + return true; + } + public void FromOSD(OSDMap map) { CompareTrackEntries cte = new CompareTrackEntries(); @@ -188,9 +241,11 @@ namespace OpenSim.Framework { if (d.TryGetValue("key_name", out OSD dname)) { - TrackEntry t = new TrackEntry(); - t.time = dtime; - t.frameName = dname; + TrackEntry t = new TrackEntry() + { + time = dtime, + frameName = dname + }; waterTrack.Add(t); } } diff --git a/OpenSim/Framework/ViewerEnvironment.cs b/OpenSim/Framework/ViewerEnvironment.cs index 980ecfe4c8..547d7c2952 100644 --- a/OpenSim/Framework/ViewerEnvironment.cs +++ b/OpenSim/Framework/ViewerEnvironment.cs @@ -373,16 +373,52 @@ namespace OpenSim.Framework OSDMap map = osd as OSDMap; if (map == null) return false; - if(!map.TryGetValue("type", out OSD tmp)) + if (!map.TryGetValue("type", out OSD tmp)) return false; string type = tmp.AsString(); - if(type != "daycycle") + if (type != "daycycle") return false; Cycle = new DayCycle(); Cycle.FromOSD(map); return true; } + public bool FromAssetOSD(string name, OSD osd) + { + OSDMap map = osd as OSDMap; + if (map == null) + return false; + if (!map.TryGetValue("type", out OSD tmp)) + return false; + string type = tmp.AsString(); + + bool ok = false; + if (type == "water") + { + if (Cycle == null) + Cycle = new DayCycle(); + ok = Cycle.replaceWaterFromOSD(name, map); + } + else + { + if (type == "daycycle") + { + Cycle = new DayCycle(); + Cycle.FromOSD(map); + ok = true; + } + else if(type == "sky") + { + if (Cycle == null) + Cycle = new DayCycle(); + ok = Cycle.replaceSkyFromOSD(name, map); + } + } + if(ok && !string.IsNullOrWhiteSpace(name)) + Cycle.Name = name; + return ok; + } + public OSD ToOSD() { OSDMap env = new OSDMap(); diff --git a/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs b/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs index 10752f7cf1..85e29dc056 100644 --- a/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs +++ b/OpenSim/Region/CoreModules/World/LightShare/EnvironmentModule.cs @@ -594,16 +594,16 @@ namespace OpenSim.Region.CoreModules.World.LightShare try { OSD req = OSDParser.Deserialize(httpRequest.InputStream); - if(req is OpenMetaverse.StructuredData.OSDMap) + if(req is OSDMap) { - OSDMap map = req as OpenMetaverse.StructuredData.OSDMap; + OSDMap map = req as OSDMap; if(map.TryGetValue("environment", out OSD env)) { if (VEnv == null) // need a proper clone VEnv = m_DefaultEnv.Clone(); - OSDMap evmap = (OSDMap)env; + OSDMap evmap = env as OSDMap; if(evmap.TryGetValue("day_asset", out OSD tmp) && !evmap.ContainsKey("day_cycle")) { string id = tmp.AsString(); @@ -616,7 +616,11 @@ namespace OpenSim.Region.CoreModules.World.LightShare try { OSD oenv = OSDParser.Deserialize(asset.Data); - VEnv.CycleFromOSD(oenv); + evmap.TryGetValue("day_name", out tmp); + if(tmp is OSDString) + VEnv.FromAssetOSD(tmp.AsString(), oenv); + else + VEnv.FromAssetOSD(null, oenv); } catch { @@ -624,7 +628,9 @@ namespace OpenSim.Region.CoreModules.World.LightShare return; } } - VEnv.FromOSD(env); + else + VEnv.FromOSD(env); + if(lchannel == null) { StoreOnRegion(VEnv);