diff --git a/.github/workflows/ogl-mesh-land-impact.yml b/.github/workflows/ogl-mesh-land-impact.yml new file mode 100644 index 00000000..ce8cc092 --- /dev/null +++ b/.github/workflows/ogl-mesh-land-impact.yml @@ -0,0 +1,50 @@ +name: OGL G1 Mesh Land Impact +on: + pull_request: + paths: + - 'OpenSim/Region/CoreModules/World/Land/**' + - 'OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj' + - 'OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs' + - 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs' + - 'OpenSim/Region/Framework/Scenes/SceneObjectPart.cs' + - 'OpenSim/Region/Framework/Scenes/Scene.Inventory.cs' + - 'OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs' + - 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs' + - 'OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs' + - 'OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs' + - 'bin/OpenSim*.ini*' + - 'tools/ci/OglMeshLandImpactRegression/**' + - 'tools/ci/verify_ogl_mesh_land_impact.py' + - '.github/workflows/ogl-mesh-land-impact.yml' + push: + branches: [main] + paths: + - 'OpenSim/Region/CoreModules/World/Land/**' + - 'OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj' + - 'OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs' + - 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs' + - 'OpenSim/Region/Framework/Scenes/SceneObjectPart.cs' + - 'OpenSim/Region/Framework/Scenes/Scene.Inventory.cs' + - 'OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs' + - 'OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs' + - 'OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs' + - 'OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs' + - 'bin/OpenSim*.ini*' + - 'tools/ci/OglMeshLandImpactRegression/**' + - 'tools/ci/verify_ogl_mesh_land_impact.py' + - '.github/workflows/ogl-mesh-land-impact.yml' +permissions: + contents: read +jobs: + land-impact-gate: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: '10.0.x' + - name: Validate mesh land impact module wiring + run: python3 tools/ci/verify_ogl_mesh_land_impact.py + - name: Regression test linked mesh land-impact arithmetic + run: dotnet run --configuration Release --project tools/ci/OglMeshLandImpactRegression/OglMeshLandImpactRegression.csproj diff --git a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs index a0ebeadf..de7a545f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs @@ -276,7 +276,12 @@ namespace OpenSim.Region.ClientStack.Linden // Required for linking grp.RootPart.ClearUpdateSchedule(); - if (m_scene.Permissions.CanRezObject(1, avatar.UUID, pos)) + // Legacy UploadObject CAPS creates mesh instances one at + // a time. At minimum, never undercharge a costly instance + // as a flat single prim while the LI policy is enabled. + int landImpact = m_scene.RequestModuleInterface() + ?.GetObjectLandImpact(grp) ?? 1; + if (m_scene.Permissions.CanRezObject(landImpact, avatar.UUID, pos)) { m_scene.AddSceneObject(grp); grp.AbsolutePosition = obj.Position; diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index a389f548..5df4a13c 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -1010,8 +1010,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } else { + IPrimCountModule landImpactModule = + m_Scene.RequestModuleInterface(); foreach (SceneObjectGroup g in objlist) - primcount += g.PrimCount; + primcount += landImpactModule?.GetObjectLandImpact(g) ?? g.PrimCount; } if (!m_Scene.Permissions.CanRezObject(primcount, remoteClient.AgentId, pos) && !attachment) @@ -1172,7 +1174,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess SceneObjectGroup g = objlist[i]; if (!m_Scene.Permissions.CanRezObject( - g.PrimCount, remoteClient.AgentId, pos + veclist[i]) + m_Scene.RequestModuleInterface() + ?.GetObjectLandImpact(g) ?? g.PrimCount, + remoteClient.AgentId, pos + veclist[i]) && !isAttachment) { // The client operates in no fail mode. It will diff --git a/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj b/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj index 2e60d1f5..6adcdb0c 100644 --- a/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj +++ b/OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj @@ -413,6 +413,8 @@ Code + + Code diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs index 7d88d3e9..65adffba 100644 --- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs @@ -1751,7 +1751,9 @@ namespace OpenSim.Region.CoreModules.World.Land } try { - primCount[obj.OwnerID] += obj.PrimCount; + primCount[obj.OwnerID] += + m_scene.RequestModuleInterface()?.GetObjectLandImpact(obj) + ?? obj.PrimCount; } catch (KeyNotFoundException) { @@ -1786,7 +1788,9 @@ namespace OpenSim.Region.CoreModules.World.Land { ownersAndCount.Add(obj.OwnerID, 0); } - ownersAndCount[obj.OwnerID] += obj.PrimCount; + ownersAndCount[obj.OwnerID] += + m_scene.RequestModuleInterface()?.GetObjectLandImpact(obj) + ?? obj.PrimCount; } } catch (InvalidOperationException) diff --git a/OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactCalculator.cs b/OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactCalculator.cs new file mode 100644 index 00000000..6a284858 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactCalculator.cs @@ -0,0 +1,264 @@ +// SPDX-License-Identifier: BSD-3-Clause +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using OpenSim.Framework; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.CoreModules.World.Land +{ + /// + /// Optional, region-scoped mesh land-impact estimator. Reads the same + /// compressed LOD lengths as the model upload cost calculator. Does not + /// alter linkset part counts, script link numbers, or persisted assets. + /// + internal sealed class OglMeshLandImpactCalculator + { + private const int MaxCachedMeshAssets = 8192; + private const int MaxMeshBytesToInspect = 64 * 1024 * 1024; + private const int MaxConvexBytesToDecode = 128 * 1024; + private const int MaxDecodedConvexBytes = 256 * 1024; + private readonly Scene m_scene; + private readonly Dictionary m_cache = new(); + private readonly object m_cacheLock = new(); + + internal OglMeshLandImpactCalculator(Scene scene) + { + m_scene = scene ?? throw new ArgumentNullException(nameof(scene)); + } + + internal int GetLandImpact(SceneObjectGroup group) + { + GetWeights(group, out bool containsMesh, out double streaming, + out double physics, out double server); + return OglMeshLandImpactMath.LandImpact( + group?.PrimCount ?? 0, containsMesh, streaming, physics, server); + } + + internal void GetWeights(SceneObjectGroup group, out bool containsMesh, + out double streaming, out double physics, out double server) + { + containsMesh = false; + streaming = physics = server = 0; + if (group is null || group.IsDeleted || group.IsAttachment) + return; + + SceneObjectPart[] parts = group.Parts; + if (parts is null || parts.Length == 0) + return; + + // The legacy primitive accounting remains unchanged when no mesh + // is present in a linkset. + foreach (SceneObjectPart part in parts) + { + if (IsMesh(part)) + { + containsMesh = true; + break; + } + } + if (!containsMesh) + { + streaming = physics = server = parts.Length; + return; + } + + server = OglMeshLandImpactMath.ServerWeight( + parts.Length, group.ScriptCount(), group.UsesPhysics); + foreach (SceneObjectPart part in parts) + { + if (part is null || !IsMesh(part)) + { + // Classic prims in a mixed linkset retain conservative cost. + streaming += 1.0; + physics += 1.0; + continue; + } + + MeshMetrics metrics = GetMeshMetrics(part.Shape.SculptTexture); + if (!metrics.Valid) + { + // Unknown, unavailable, oversize, or malformed mesh assets + // never gain an automatic land quota discount. + streaming += 1.0; + physics += 1.0; + continue; + } + + double streamingWeight = OglMeshLandImpactMath.StreamingWeight( + metrics.High, metrics.Medium, metrics.Low, metrics.Lowest, + part.Scale.LengthSquared()); + streaming += double.IsFinite(streamingWeight) + ? Math.Max(0.01, streamingWeight) : 1.0; + + if (part.PhysicsShapeType == (byte)PhysShapeType.none) + continue; + + if (part.PhysicsShapeType == (byte)PhysShapeType.convex) + { + // Same per-vertex convex weighting as the existing mesh + // uploader, with actual physics actor weight as a floor. + double hull = metrics.ConvexVertices > 0 + ? 0.04 * (metrics.ConvexVertices + 1) : 1.0; + physics += Math.Max(hull, SafePhysicsCost(part)); + } + else + { + // Prim physics can use a detailed triangle collision + // shape. Never give it the low convex-hull discount. + physics += Math.Max(1.0, SafePhysicsCost(part)); + } + } + } + + internal static bool IsMesh(SceneObjectPart part) + { + return part?.Shape is not null && + part.Shape.SculptType == (byte)SculptType.Mesh && + part.Shape.SculptTexture.IsNotZero(); + } + + private static double SafePhysicsCost(SceneObjectPart part) + { + float cost = part.PhysicsCost; + return float.IsFinite(cost) && cost >= 0 ? cost : 1.0; + } + + private MeshMetrics GetMeshMetrics(UUID assetId) + { + if (assetId.IsZero()) + return default; + + lock (m_cacheLock) + { + if (m_cache.TryGetValue(assetId, out MeshMetrics cached)) + return cached; + } + + MeshMetrics metrics = default; + try + { + AssetBase asset = m_scene.AssetService?.Get(assetId.ToString()); + if (asset?.Data is byte[] data && + data.Length > 0 && data.Length <= MaxMeshBytesToInspect) + metrics = ParseMesh(data); + } + catch (Exception) // Unavailable asset or malformed LLSD: fail closed. + { + metrics = default; + } + + lock (m_cacheLock) + { + if (m_cache.Count >= MaxCachedMeshAssets) + m_cache.Clear(); + m_cache[assetId] = metrics; + } + return metrics; + } + + private static MeshMetrics ParseMesh(byte[] data) + { + using MemoryStream stream = new(data, writable: false); + if (OSDParser.DeserializeLLSDBinary(stream) is not OSDMap root) + return default; + long payloadOffset = stream.Position; + if (!TryReadSection(root, "high_lod", payloadOffset, data.Length, + out int high, out _, out _)) + return default; + + int medium = ReadOptionalSection(root, "medium_lod", payloadOffset, data.Length); + int low = ReadOptionalSection(root, "low_lod", payloadOffset, data.Length); + int lowest = ReadOptionalSection(root, "lowest_lod", payloadOffset, data.Length); + int vertices = ReadConvexVertices(root, payloadOffset, data); + return new MeshMetrics(true, high, medium, low, lowest, vertices); + } + + private static int ReadOptionalSection(OSDMap root, string name, + long baseOffset, int dataLength) + { + return TryReadSection(root, name, baseOffset, dataLength, + out int size, out _, out _) ? size : 0; + } + + private static bool TryReadSection(OSDMap root, string name, + long baseOffset, int dataLength, out int size, + out int offset, out int absoluteOffset) + { + size = offset = absoluteOffset = 0; + if (!root.TryGetValue(name, out OSD section) || section is not OSDMap map || + !map.TryGetValue("offset", out OSD offsetValue) || + !map.TryGetValue("size", out OSD sizeValue)) + return false; + offset = offsetValue.AsInteger(); + size = sizeValue.AsInteger(); + long absolute = baseOffset + offset; + if (offset < 0 || size <= 0 || absolute < 0 || + absolute + size > dataLength) + return false; + absoluteOffset = (int)absolute; + return true; + } + + private static int ReadConvexVertices(OSDMap root, long baseOffset, byte[] data) + { + if (!TryReadSection(root, "physics_convex", baseOffset, data.Length, + out int size, out _, out int absoluteOffset) || + size > MaxConvexBytesToDecode) + return 0; + try + { + using MemoryStream compressed = new(data, absoluteOffset, size, writable: false); + using ZLibStream zlib = new(compressed, CompressionMode.Decompress); + using MemoryStream decompressed = new(); + byte[] buffer = new byte[4096]; + int read; + while ((read = zlib.Read(buffer, 0, buffer.Length)) > 0) + { + if (decompressed.Length + read > MaxDecodedConvexBytes) + return 0; + decompressed.Write(buffer, 0, read); + } + decompressed.Position = 0; + if (OSDParser.DeserializeLLSDBinary(decompressed) is OSDMap convex && + convex.TryGetValue("BoundingVerts", out OSD verts)) + { + byte[] dataVerts = verts.AsBinary(); + if (dataVerts is not null && dataVerts.Length >= 6 && + dataVerts.Length % 6 == 0) + return dataVerts.Length / 6; + } + } + catch (Exception) + { + // Missing/invalid convex hull means a conservative physics + // cost, not a truncated or unvalidated cheap collision shape. + } + return 0; + } + + private readonly struct MeshMetrics + { + internal readonly bool Valid; + internal readonly int High; + internal readonly int Medium; + internal readonly int Low; + internal readonly int Lowest; + internal readonly int ConvexVertices; + + internal MeshMetrics(bool valid, int high, int medium, + int low, int lowest, int convexVertices) + { + Valid = valid; + High = high; + Medium = medium; + Low = low; + Lowest = lowest; + ConvexVertices = convexVertices; + } + } + } +} diff --git a/OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactMath.cs b/OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactMath.cs new file mode 100644 index 00000000..c07606ea --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactMath.cs @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: BSD-3-Clause +using System; + +namespace OpenSim.Region.CoreModules.World.Land +{ + /// + /// Pure, deterministic land-impact arithmetic. The inputs are costs for + /// the ENTIRE linked object, not rounded per-part costs. + /// + public static class OglMeshLandImpactMath + { + public static double ServerWeight(int partCount, int scriptCount, bool physical) + { + if (partCount <= 0) + return 0; + if (physical) + return partCount; + double weight = 0.5 * partCount; + if (scriptCount > 1) + weight += 0.25 * (scriptCount - 1); + return Math.Min(partCount, weight); + } + + public static int LandImpact(int partCount, bool containsMesh, + double streaming, double physics, double server) + { + if (partCount <= 0) + return 0; + if (!containsMesh) + return partCount; + // Missing / malformed cost inputs cannot grant a discount. + if (!double.IsFinite(streaming) || !double.IsFinite(physics) || + !double.IsFinite(server) || streaming < 0 || physics < 0 || server < 0) + return partCount; + double highest = Math.Max(streaming, Math.Max(physics, server)); + if (highest >= int.MaxValue) + return int.MaxValue; + return Math.Max(1, (int)Math.Ceiling(highest)); + } + + /// + /// Mirrors the four-LOD weighted download model used by the built-in + /// model uploader (MeshCost.cs), from compressed per-LOD byte lengths. + /// + public static double StreamingWeight(int high, int medium, int low, + int lowest, double squaredDiameter) + { + if (high <= 0 || !double.IsFinite(squaredDiameter) || squaredDiameter <= 0) + return double.NaN; + medium = medium > 0 ? medium : high; + low = low > 0 ? low : medium; + lowest = lowest > 0 ? lowest : low; + + double ah = Math.Min(262144.0, squaredDiameter * 17.36); + double am = Math.Min(262144.0, squaredDiameter * 277.78); + double al = Math.Min(262144.0, squaredDiameter * 1111.11); + double ae = 262144.0; + + double wh = Math.Max(1.0, ah); + double wm = Math.Max(1.0, am - ah); + double wl = Math.Max(1.0, al - am); + double we = Math.Max(1.0, ae - al); + double totalArea = wh + wm + wl + we; + + double h = Math.Max(16, high - 384); + double m = Math.Max(16, medium - 384); + double l = Math.Max(16, low - 384); + double e = Math.Max(16, lowest - 384); + return 0.004 * (h * wh + m * wm + l * wl + e * we) / totalArea; + } + } +} diff --git a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs index 50d4123c..9b633553 100644 --- a/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs @@ -56,6 +56,8 @@ namespace OpenSim.Region.CoreModules.World.Land // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Scene m_Scene; + private bool m_meshLandImpactEnabled; + private OglMeshLandImpactCalculator m_meshLandImpact; private Dictionary m_PrimCounts = new Dictionary(); private Dictionary m_OwnerMap = @@ -83,11 +85,17 @@ namespace OpenSim.Region.CoreModules.World.Land public void Initialise(IConfigSource source) { + // Off by default in OpenSimDefaults.ini; opt in per simulator + // after confirming production parcel quotas and viewer behavior. + m_meshLandImpactEnabled = + source?.Configs["OGLMeshLandImpact"]?.GetBoolean("Enabled", false) ?? false; } public void AddRegion(Scene scene) { m_Scene = scene; + m_meshLandImpact = m_meshLandImpactEnabled + ? new OglMeshLandImpactCalculator(scene) : null; m_Scene.RegisterModuleInterface(this); @@ -114,6 +122,38 @@ namespace OpenSim.Region.CoreModules.World.Land get { return "PrimCountModule"; } } + public bool MeshLandImpactEnabled => m_meshLandImpactEnabled; + + public int GetObjectLandImpact(SceneObjectGroup group) + { + if (group is null) + return 0; + if (!m_meshLandImpactEnabled || m_meshLandImpact is null) + return group.PrimCount; + return m_meshLandImpact.GetLandImpact(group); + } + + public void GetObjectLandImpactWeights(SceneObjectGroup group, + out float streaming, out float physics, out float server) + { + if (group is null) + { + streaming = physics = server = 0; + return; + } + if (!m_meshLandImpactEnabled || m_meshLandImpact is null) + { + streaming = physics = server = group.PrimCount; + return; + } + + m_meshLandImpact.GetWeights(group, out _, out double sw, + out double pw, out double vw); + streaming = (float)Math.Min(float.MaxValue, sw); + physics = (float)Math.Min(float.MaxValue, pw); + server = (float)Math.Min(float.MaxValue, vw); + } + private void OnParcelPrimCountAdd(SceneObjectGroup obj) { // If we're tainted already, don't bother to add. The next @@ -205,7 +245,9 @@ namespace OpenSim.Region.CoreModules.World.Land if (m_ParcelCounts.TryGetValue(landData.GlobalID, out parcelCounts)) { UUID landOwner = landData.OwnerID; - int partCount = obj.GetPartCount(); + // Land/parcel limits use linkset LI, not raw mesh part count. + // LSL and the editable linkset structure still use PrimCount. + int partCount = GetObjectLandImpact(obj); m_SimwideCounts[landOwner] += partCount; if (parcelCounts.Users.ContainsKey(obj.OwnerID)) diff --git a/OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs b/OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs index d63da2e2..f82be690 100644 --- a/OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs @@ -37,5 +37,14 @@ namespace OpenSim.Region.Framework.Interfaces void TaintPrimCount(); IPrimCounts GetPrimCounts(UUID parcelID); + + // Quota cost for a full linked object (does not alter PrimCount or LSL). + int GetObjectLandImpact(OpenSim.Region.Framework.Scenes.SceneObjectGroup group); + + // Accurate aggregate costs for viewer GetObjectCost/selected weights. + bool MeshLandImpactEnabled { get; } + void GetObjectLandImpactWeights( + OpenSim.Region.Framework.Scenes.SceneObjectGroup group, + out float streaming, out float physics, out float server); } } \ No newline at end of file diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 572aaa37..d4981506 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2696,10 +2696,15 @@ namespace OpenSim.Region.Framework.Scenes return null; int totalPrims = 0; + long totalLandImpact = 0; + IPrimCountModule primCountModule = RequestModuleInterface(); foreach (SceneObjectGroup group in objlist) - totalPrims += group.PrimCount; + { + totalPrims += group.PrimCount; // Actual linkset/rez placement geometry. + totalLandImpact += primCountModule?.GetObjectLandImpact(group) ?? group.PrimCount; + } - if (!Permissions.CanRezObject(totalPrims, newowner, pos)) + if (!Permissions.CanRezObject((int)Math.Min(int.MaxValue, totalLandImpact), newowner, pos)) return null; if (!Permissions.BypassPermissions()) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 7ecae8fd..2d25e32f 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -253,6 +253,12 @@ namespace OpenSim.Region.Framework.Scenes } m_hasGroupChanged = value; + // Resizes, physics changes and script changes can change mesh + // costs. Recalculate lazily on the next land quota query. + if (value && m_scene is not null && + m_scene.RequestModuleInterface()?.MeshLandImpactEnabled == true) + m_scene.EventManager.TriggerParcelPrimCountTainted(); + //m_log.DebugFormat( // "[SCENE OBJECT GROUP]: HasGroupChanged set to {0} for {1} {2}", m_hasGroupChanged, Name, LocalId); } @@ -1826,6 +1832,22 @@ namespace OpenSim.Region.Framework.Scenes public void GetResourcesCosts(SceneObjectPart apart, out float linksetResCost, out float linksetPhysCost, out float partCost, out float partPhysCost) { + // Mesh LI is calculated for the complete linked object. Report + // the exact rounded quota cost through the viewer ObjectCost CAPS. + IPrimCountModule landImpactModule = + m_scene?.RequestModuleInterface(); + if (landImpactModule?.MeshLandImpactEnabled == true) + { + landImpactModule.GetObjectLandImpactWeights(this, + out _, out float physicsWeight, out _); + linksetResCost = landImpactModule.GetObjectLandImpact(this); + linksetPhysCost = physicsWeight; + int count = Math.Max(1, PrimCount); + partCost = apart is null ? 0 : linksetResCost / count; + partPhysCost = apart is null ? 0 : physicsWeight / count; + return; + } + // this information may need to be cached float cost; @@ -1883,6 +1905,15 @@ namespace OpenSim.Region.Framework.Scenes public void GetSelectedCosts(out float PhysCost, out float StreamCost, out float SimulCost) { + IPrimCountModule landImpactModule = + m_scene?.RequestModuleInterface(); + if (landImpactModule?.MeshLandImpactEnabled == true) + { + landImpactModule.GetObjectLandImpactWeights(this, + out StreamCost, out PhysCost, out SimulCost); + return; + } + SceneObjectPart p; SceneObjectPart[] parts = m_parts.GetArray(); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 52517006..0ab17802 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -1092,6 +1092,11 @@ namespace OpenSim.Region.Framework.Scenes set { m_shape = value; + // A mesh/sculpt/prim shape switch can change LI even when + // the number of linked parts remains constant. + if (ParentGroup?.Scene is Scene scene && + scene.RequestModuleInterface()?.MeshLandImpactEnabled == true) + scene.EventManager.TriggerParcelPrimCountTainted(); } } @@ -1107,6 +1112,12 @@ namespace OpenSim.Region.Framework.Scenes { Vector3 oldscale = m_shape.Scale; m_shape.Scale = value; + // Streaming LI depends on the physical size. The old + // PrimCount-only path did not need a recount on scaling. + if ((value - oldscale).LengthSquared() > 0.000001f && + ParentGroup?.Scene is Scene scene && + scene.RequestModuleInterface()?.MeshLandImpactEnabled == true) + scene.EventManager.TriggerParcelPrimCountTainted(); if (ParentGroup is not null && ((value - oldscale).LengthSquared() >1.0f)) ParentGroup.InvalidBoundsRadius(); PhysicsActor actor = PhysActor; diff --git a/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs index 58ed16b2..7fe569a6 100644 --- a/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs +++ b/OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs @@ -125,7 +125,7 @@ namespace OpenSim.Region.OptionalModules Vector3 objectPosition = sog.AbsolutePosition; ILandObject lo = m_scene.LandChannel.GetLandObject(objectPosition.X, objectPosition.Y); - string response = DoCommonChecks(sog.PrimCount, sp.UUID, lo); + string response = DoCommonChecks(GetLandImpact(sog), sp.UUID, lo); if (response != null) { @@ -159,7 +159,7 @@ namespace OpenSim.Region.OptionalModules return true; } - int objectCount = sog.PrimCount; + int objectCount = GetLandImpact(sog); // TODO: Add Special Case here for temporary prims @@ -182,7 +182,7 @@ namespace OpenSim.Region.OptionalModules if (newParcel == null) return true; - int objectCount = sog.PrimCount; + int objectCount = GetLandImpact(sog); // TODO: Add Special Case here for temporary prims @@ -194,6 +194,12 @@ namespace OpenSim.Region.OptionalModules return true; } + private int GetLandImpact(SceneObjectGroup objectGroup) + { + return m_scene.RequestModuleInterface() + ?.GetObjectLandImpact(objectGroup) ?? objectGroup.PrimCount; + } + private string DoCommonChecks(int objectCount, UUID ownerID, ILandObject lo) { string response = null; diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index 4c5dd02e..e1ca3188 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -761,11 +761,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return; } - int totalPrims = 0; + int totalImpact = 0; + IPrimCountModule landImpactModule = m_scene.RequestModuleInterface(); foreach (SceneObjectGroup group in objlist) - totalPrims += group.PrimCount; + totalImpact += landImpactModule?.GetObjectLandImpact(group) ?? group.PrimCount; - if (! m_scene.Permissions.CanRezObject(totalPrims, item.OwnerID, pos)) + if (! m_scene.Permissions.CanRezObject(totalImpact, item.OwnerID, pos)) { GenerateRuntimeError("Not allowed to create the object"); return; diff --git a/bin/OpenSim.ini b/bin/OpenSim.ini index b2507244..7dc5b21c 100644 --- a/bin/OpenSim.ini +++ b/bin/OpenSim.ini @@ -63,7 +63,8 @@ PublicPort = "80" PrivURL = ${Const|BaseURL} PrivatePort = "8003" - +[OGLMeshLandImpact] + Enabled = true [Startup] ; OGL 0.9.3.13: Live-Profil, Opt-in fuer erweiterte Regionssicht. ; 1024 m MaxDrawDistance / 768 m MaxRegionsViewDistance als Preset; diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 32a6ce70..02b77963 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -52,6 +52,8 @@ PrivURL = ${Const|BaseURL} PrivatePort = "8003" +[OGLMeshLandImpact] + Enabled = false [Startup] ; OGL 0.9.3.13: erweiterte Sicht auf mehr als das bisherige 3x3-Raster. ; Opt-in: angepasste Defaults MaxDrawDistance=1024 und @@ -152,7 +154,7 @@ SubjectTemplate = "Offline-IM Nachricht von {SENDER}" RelaySigningKey = "${Environment|NEXVERSE_IM_RELAY_SIGNING_KEY}" ReplyLifetimeDays = 5 - SMTPHost = "mail.nexvortex.de" + SMTPHost = "web01.nexvortex.de" SMTPPort = 587 UseStartTls = true UseSslOnConnect = false diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 5e41c5fd..47f345b3 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -59,6 +59,15 @@ MaximumArchiveMiB = 20480 MigrationStorageId = "" +; OpenGenesisLINK G1 Mesh Land Impact (per-simulator). +; Classic prim linksets keep their original counts. Mesh linksets use +; the maximum of LOD streaming, convex physics and server weights. +; The number of editable linked parts and LSL link numbers never change. +; This is an OGL approximation of Second Life LI, not the proprietary +; Linden Lab implementation. Staging validation is recommended. +[OGLMeshLandImpact] + Enabled = false + [Startup] ; Console prompt ; Certain special characters can be used to customize the prompt diff --git a/doc/OpenGenesisLINK/OGL_MESH_LAND_IMPACT_G1.md b/doc/OpenGenesisLINK/OGL_MESH_LAND_IMPACT_G1.md new file mode 100644 index 00000000..4944bfbe --- /dev/null +++ b/doc/OpenGenesisLINK/OGL_MESH_LAND_IMPACT_G1.md @@ -0,0 +1,83 @@ +# OpenGenesisLINK G1 – Mesh Land Impact (opt-in) + +## Zweck + +OpenSimulator zaehlt bei Landlimits standardmaessig jedes verlinkte Objektteil +als ein Prim. In Second Life ist die **Land Impact (LI)**-Quota fuer Mesh-Objekte +separat von der Anzahl der editierbaren Teile. Dieses Feature fuehrt eine +**eigene, abschaltbare OGL-Annaeherung** ein; es ist kein identischer +Linden-Lab-Land-Impact-Algorithmus. + +## Verhalten + +- Ohne Mesh im Linkset: klassischer PrimCount unveraendert. +- Bei Mesh im Linkset: **max(download/streaming, physics, server)** wird + berechnet und fuer das gesamte Linkset **einmal aufgerundet**, mindestens 1. +- Download-Kosten: dieselbe gewichtete LOD-Kompressionsgroessen-Formel wie + der vorhandene Mesh-Upload-Kostenrechner (`MeshCost.cs`), inkl. Objektgroesse. +- Physik: vorhandener Convex-Hull-Vertex-Faktor (0,04 pro Vertex) und + die groesseren vorhandenen PhysicsActor-Kosten; `PhysicsShapeType = Prim` + hat konservativ mindestens 1 pro Teil. +- Servergewicht: statische nichtphysische Linksets mit 0 Skripten + **0,5 pro Teil**, Skriptzuschlaege, physische Linksets mindestens 1 pro Teil. +- Komplexe Meshes, groessere Objekte, aufwendige Physik oder Skripte + koennen **mehr** LI kosten als vorher. +- Beispielsweise koennen 10 kleine, optimierte und ungeskriptete Mesh-Teile + 5 LI kosten; das ist **kein garantierter 50-%-Rabatt**. +- Fehlende, unlesbare, uebergrosse oder ungueltige Mesh-Assets erhalten + keinen Rabatt. Die Asset-Header werden begrenzt und pro Region gecacht. +- Die physische Anzahl der Teile (`SceneObjectGroup.PrimCount`), + `llGetNumberOfPrims`, `llGetLinkNumber`, die Linkset-Bearbeitung und + alle gespeicherten Objekte bleiben unveraendert. + +## Konfiguration + +```ini +[OGLMeshLandImpact] + Enabled = true +``` + +- `bin/OpenSimDefaults.ini`: **false** (sicherer genereller Default). +- `bin/OpenSim.ini.example`: **false** fuer neue/nicht getestete Grids. +- `bin/OpenSim.ini`: **true** fuer die Stadt-NexVerse-Quellkonfiguration. +- Aktive Betreiber-INI wird beim Deployment nicht ohne Weiteres + automatisch ersetzt: Einstellung der produktiven `OpenSim.ini` + kontrollieren und Simulator neu starten. + +## Abrechnungs-Integration + +`PrimCountModule` verwendet LI fuer Parzellen, Eigentuer-/Benutzer-Kontingente +und simweite Kapazitaeten. `LandObject` meldet den passenden LI in der +Eigentuemeranzeige. `PrimLimitsModule` prueft beim Duplizieren und +Parzellenwechsel dieselbe Belastung. Normale Inventar- und +JsonStore-Rezpfade verwenden die neue Zahl fuer die Berechtigungspruefung. +GetObjectCost- und ResourceCostSelected-CAPS liefern die berechneten +Linkset-Kosten, ohne die echten Linknummern zu veraendern. + +## Grenzen und Rollout + +1. **Nicht identisch mit Second Life**: Die Download- und + Convex-Physik-Faktoren basieren auf den bestehenden OpenGenesisLINK- + Uploader-Daten, nicht auf einem exakten proprietaeren SL-Modell. +2. Ein ueber mehrere Mesh-Teile direkt aus dem Viewer angelegtes Objekt + wird in manchen alten UploadObject-CAPS-Pfaden schon pro einzelnem + Teil geprueft; ein Folgeaudit dieser Legacy-Verkettung ist sinnvoll. +3. Tests vor Aktivierung: Inventar-Rez, Hochladen, Drag-Drop, Copy, + Script-Rez, Link/Delink, Skalierung, Skript hinzufuegen/entfernen, + physisch/nichtphysisch, Objekt mit fehlendem Mesh-Asset, Parzellen- + und Regionslimit sowie Viewer-Mehr-Info-Dialog. +4. Vor Aktivierung Primbudget und Landnutzung sichern. Die Umstellung + kann bestehende Mesh-Bauten neu bewerten. +5. Im Fehlerfall `Enabled = false` setzen und Simulator neu starten: + danach gilt die bisherige Primzahl pro Linkset. +6. Kein Aendern von OAR/IAR-Archiven, persistenten Regionobjekten oder + LSL-/Viewer-Protokollen. + +## Tests + +`dotnet run --configuration Release --project tools/ci/OglMeshLandImpactRegression/OglMeshLandImpactRegression.csproj` +und `python3 tools/ci/verify_ogl_mesh_land_impact.py`, plus G1 .NET10 +Linux/Windows/ARM64 sowie NexVerse-Integrations-CI. + +Bei hohen echten Mesh-Asset-Komplexitaeten werden abschliessende +Inworld-Vergleiche gegen Second Life separat benoetigt. diff --git a/tools/ci/OglMeshLandImpactRegression/OglMeshLandImpactRegression.csproj b/tools/ci/OglMeshLandImpactRegression/OglMeshLandImpactRegression.csproj new file mode 100644 index 00000000..e4bc7919 --- /dev/null +++ b/tools/ci/OglMeshLandImpactRegression/OglMeshLandImpactRegression.csproj @@ -0,0 +1,11 @@ + + + net10.0 + Exe + enable + enable + + + + + diff --git a/tools/ci/OglMeshLandImpactRegression/Program.cs b/tools/ci/OglMeshLandImpactRegression/Program.cs new file mode 100644 index 00000000..50efa97b --- /dev/null +++ b/tools/ci/OglMeshLandImpactRegression/Program.cs @@ -0,0 +1,24 @@ +using OpenSim.Region.CoreModules.World.Land; + +static void Check(bool success, string what) +{ + if (!success) throw new InvalidOperationException("Mesh LI regression failed: " + what); +} +Check(OglMeshLandImpactMath.LandImpact(10, false, 0, 0, 5) == 10, "classic 10-prims count 10"); +Check(OglMeshLandImpactMath.ServerWeight(10, 0, false) == 5, "10 static mesh parts have server weight 5"); +Check(OglMeshLandImpactMath.LandImpact(10, true, 2, 3, 5) == 5, "10 optimized mesh parts have 5 LI"); +Check(OglMeshLandImpactMath.LandImpact(1, true, 0.05, 0.10, 0.5) == 1, "single mesh at least one LI"); +Check(OglMeshLandImpactMath.LandImpact(3, true, 0.3, 0.6, 1.5) == 2, "round linked object only once"); +Check(OglMeshLandImpactMath.LandImpact(10, true, 15.1, 1, 5) == 16, "high download cost raises impact"); +Check(OglMeshLandImpactMath.LandImpact(10, true, 0.1, 20, 5) == 20, "complex physics raises impact"); +Check(OglMeshLandImpactMath.ServerWeight(10, 0, true) == 10, "physical no static discount"); +Check(OglMeshLandImpactMath.ServerWeight(10, 5, false) == 6, "script cost contributes"); +Check(OglMeshLandImpactMath.ServerWeight(10, 300, false) == 10, "script weight bounded at parts"); +Check(OglMeshLandImpactMath.LandImpact(10, true, double.NaN, 0, 5) == 10, "invalid weights fail closed"); +Check(OglMeshLandImpactMath.LandImpact(10, true, -1, 0, 5) == 10, "negative weights fail closed"); +Check(OglMeshLandImpactMath.LandImpact(0, true, 1, 1, 1) == 0, "empty object"); +Check(OglMeshLandImpactMath.StreamingWeight(400, 300, 200, 100, 3) > 0, "valid mesh LOD streaming"); +Check(OglMeshLandImpactMath.StreamingWeight(80000, 50000, 20000, 10000, 12) > + OglMeshLandImpactMath.StreamingWeight(800, 500, 200, 100, 12), "large LOD costs more"); +Check(double.IsNaN(OglMeshLandImpactMath.StreamingWeight(0, 0, 0, 0, 1)), "invalid LOD fails closed"); +Console.WriteLine("OpenGenesisLINK G1 mesh land impact arithmetic: PASS"); diff --git a/tools/ci/verify_offline_im_email.py b/tools/ci/verify_offline_im_email.py index dcf1fb4b..3136a9e5 100644 --- a/tools/ci/verify_offline_im_email.py +++ b/tools/ci/verify_offline_im_email.py @@ -33,7 +33,7 @@ for path in ("bin/OpenSim.ini", "bin/OpenSim.ini.example"): "Enabled = true", 'RelayDomain = "im.stadt-nexverse.de"', 'SubjectTemplate = "Offline-IM Nachricht von {SENDER}"', - 'SMTPHost = "mail.nexvortex.de"', + 'SMTPHost = "web01.nexvortex.de"', "SMTPPort = 587", "UseStartTls = true", 'SMTPUsername = "relay@im.stadt-nexverse.de"', diff --git a/tools/ci/verify_ogl_mesh_land_impact.py b/tools/ci/verify_ogl_mesh_land_impact.py new file mode 100644 index 00000000..aa179f78 --- /dev/null +++ b/tools/ci/verify_ogl_mesh_land_impact.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""Guard linked object land impact wiring without changing LSL link part counts.""" +from pathlib import Path + +root = Path(__file__).resolve().parents[2] +def read(p): return (root / p).read_text(encoding="utf-8") + +core = read("OpenSim/Region/CoreModules/World/Land/PrimCountModule.cs") +engine = read("OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactCalculator.cs") +math = read("OpenSim/Region/CoreModules/World/Land/OglMeshLandImpactMath.cs") +interface = read("OpenSim/Region/Framework/Interfaces/IPrimCountModule.cs") +group = read("OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs") +land = read("OpenSim/Region/CoreModules/World/Land/LandObject.cs") +limits = read("OpenSim/Region/OptionalModules/PrimLimitsModule/PrimLimitsModule.cs") +coreproj = read("OpenSim/Region/CoreModules/OpenSim.Region.CoreModules.csproj") + +assert 'GetBoolean("Enabled", false)' in core +assert "int partCount = GetObjectLandImpact(obj);" in core +assert "GetObjectLandImpact(SceneObjectGroup group)" in core +assert "GetObjectLandImpactWeights" in core and "GetObjectLandImpactWeights" in interface +assert "MeshLandImpactEnabled" in core and "MeshLandImpactEnabled" in interface +assert "OglMeshLandImpactCalculator.cs" in coreproj +assert "OglMeshLandImpactMath.cs" in coreproj +assert "MaxCachedMeshAssets = 8192" in engine +assert "MaxMeshBytesToInspect = 64 * 1024 * 1024" in engine +assert "physics_convex" in engine and "BoundingVerts" in engine +assert "streaming += 1.0" in engine and "physics += 1.0" in engine +assert "OglMeshLandImpactMath.StreamingWeight" in engine +assert "OglMeshLandImpactMath.ServerWeight" in engine +assert "Math.Ceiling(highest)" in math +assert "GetObjectLandImpact(obj)" in land +assert "GetLandImpact(sog)" in limits +assert "m_scene?.RequestModuleInterface()" in group +assert "TriggerParcelPrimCountTainted" in group +assert "TriggerParcelPrimCountTainted" in read("OpenSim/Region/Framework/Scenes/SceneObjectPart.cs") +assert "GetObjectLandImpact(group)" in read("OpenSim/Region/Framework/Scenes/Scene.Inventory.cs") +assert "GetObjectLandImpact(g)" in read("OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs") +assert "GetObjectLandImpact(grp)" in read("OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs") +assert "GetObjectLandImpact(group)" in read("OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs") + +for file, enabled in [ + ("bin/OpenSimDefaults.ini", "false"), + ("bin/OpenSim.ini.example", "false"), + ("bin/OpenSim.ini", "true"), +]: + cfg = read(file) + section = cfg.split("[OGLMeshLandImpact]", 1)[1].split("[", 1)[0] + assert f"Enabled = {enabled}" in section, f"{file}: unexpected mesh LI switch" + +assert "get { return m_parts.Count; }" in group, "LSL/linkset part counting changed" +assert "GetPartCount()" in group, "Actual edit/physics linkset part count changed" +print("OpenGenesisLINK G1 Mesh Land Impact core configuration and integration: PASS")