From 67d92e4e168bf0861024e3be5cd069c77c9144f6 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 6 Feb 2013 11:49:10 -0800 Subject: [PATCH 1/7] BulletSim: remove an exception which occurs if a physics mesh asset is not found. --- OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index f59b9d973b..fe0f984144 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -895,9 +895,11 @@ public sealed class BSShapeCollection : IDisposable // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset if (prim.BaseShape.SculptEntry && !prim.LastAssetBuildFailed && prim.BaseShape.SculptTexture != OMV.UUID.Zero) { - prim.LastAssetBuildFailed = true; - BSPhysObject xprim = prim; DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed); + // This will prevent looping through this code as we keep trying to get the failed shape + prim.LastAssetBuildFailed = true; + + BSPhysObject xprim = prim; Util.FireAndForget(delegate { RequestAssetDelegate assetProvider = PhysicsScene.RequestAssetMethod; @@ -908,7 +910,7 @@ public sealed class BSShapeCollection : IDisposable { bool assetFound = false; // DEBUG DEBUG string mismatchIDs = String.Empty; // DEBUG DEBUG - if (yprim.BaseShape.SculptEntry) + if (asset != null && yprim.BaseShape.SculptEntry) { if (yprim.BaseShape.SculptTexture.ToString() == asset.ID) { From 0baa2590bef8ad4e0a78a7c88d55acd0848e0068 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 6 Feb 2013 15:52:28 -0800 Subject: [PATCH 2/7] BulletSim: check for completely degenerate meshes (ones with all triangles having zero width) and output an error rather than throwing and exception. --- .../BulletSPlugin/BSShapeCollection.cs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index fe0f984144..15747c9020 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -608,7 +608,7 @@ public sealed class BSShapeCollection : IDisposable // Since we're recreating new, get rid of the reference to the previous shape DereferenceShape(prim.PhysShape, shapeCallback); - newShape = CreatePhysicalMesh(prim.PhysObjectName, newMeshKey, prim.BaseShape, prim.Size, lod); + newShape = CreatePhysicalMesh(prim, newMeshKey, prim.BaseShape, prim.Size, lod); // Take evasive action if the mesh was not constructed. newShape = VerifyMeshCreated(newShape, prim); @@ -619,7 +619,7 @@ public sealed class BSShapeCollection : IDisposable return true; // 'true' means a new shape has been added to this prim } - private BulletShape CreatePhysicalMesh(string objName, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) + private BulletShape CreatePhysicalMesh(BSPhysObject prim, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod) { BulletShape newShape = new BulletShape(); @@ -631,7 +631,7 @@ public sealed class BSShapeCollection : IDisposable } else { - IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, + IMesh meshData = PhysicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod, false, // say it is not physical so a bounding box is not built false // do not cache the mesh and do not use previously built versions ); @@ -651,18 +651,20 @@ public sealed class BSShapeCollection : IDisposable realIndicesIndex = 0; for (int tri = 0; tri < indices.Length; tri += 3) { + // Compute displacements into vertex array for each vertex of the triangle int v1 = indices[tri + 0] * 3; int v2 = indices[tri + 1] * 3; int v3 = indices[tri + 2] * 3; - if (!((verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] + // Check to see if any two of the vertices are the same + if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0] && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) - || (verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] + || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0] && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1] && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2]) - || (verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] + || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0] && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1] - && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2])) + && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]) ) ) { // None of the vertices of the triangles are the same. This is a good triangle; @@ -676,8 +678,16 @@ public sealed class BSShapeCollection : IDisposable DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", BSScene.DetailLogZero, indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3); - newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, - realIndicesIndex, indices, verticesAsFloats.Length/3, verticesAsFloats); + if (realIndicesIndex != 0) + { + newShape = PhysicsScene.PE.CreateMeshShape(PhysicsScene.World, + realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats); + } + else + { + PhysicsScene.Logger.ErrorFormat("{0} All mesh triangles degenerate. Prim {1} at {2} in {3}", + LogHeader, prim.PhysObjectName, prim.RawPosition, PhysicsScene.Name); + } } } newShape.shapeKey = newMeshKey; From d2ece00e68c070bf9ffbda3f76e4eccf3c33545f Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 6 Feb 2013 15:59:59 -0800 Subject: [PATCH 3/7] BulletSim: set removing zero width triangles in meshes to be enabled by default. This should fix the invisible barrier in sculptie doorways bug. --- OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 2 +- OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 306928ad33..965c3823b8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -220,7 +220,7 @@ public static class BSParam (s) => { return BSParam.NumericBool(ShouldUseHullsForPhysicalObjects); }, (s,p,l,v) => { ShouldUseHullsForPhysicalObjects = BSParam.BoolNumeric(v); } ), new ParameterDefn("ShouldRemoveZeroWidthTriangles", "If true, remove degenerate triangles from meshes", - ConfigurationParameters.numericFalse, + ConfigurationParameters.numericTrue, (s,cf,p,v) => { ShouldRemoveZeroWidthTriangles = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, (s) => { return BSParam.NumericBool(ShouldRemoveZeroWidthTriangles); }, (s,p,l,v) => { ShouldRemoveZeroWidthTriangles = BSParam.BoolNumeric(v); } ), diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 823402ba03..ec25aa927e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -75,6 +75,7 @@ public abstract class BSPhysObject : PhysicsActor PhysicsScene = parentScene; LocalID = localID; PhysObjectName = name; + Name = name; // PhysicsActor also has the name of the object. Someday consolidate. TypeName = typeName; // We don't have any physical representation yet. From e2c1e37b077bad2d1b6d0ac5277c3f9001d819dd Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 7 Feb 2013 00:15:50 +0000 Subject: [PATCH 4/7] Add key length validation to DAMap.Add(KeyValuePair kvp) to match Add(string key, OSDMap store) --- OpenSim/Framework/DAMap.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs index 291c8b8385..dd9c61b0d5 100644 --- a/OpenSim/Framework/DAMap.cs +++ b/OpenSim/Framework/DAMap.cs @@ -188,7 +188,8 @@ namespace OpenSim.Framework } public void Add(KeyValuePair kvp) - { + { + ValidateKey(kvp.Key); lock (this) m_map.Add(kvp.Key, kvp.Value); } From c8c5d74c22056deb0b079d0651c005d610626f66 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 7 Feb 2013 00:22:39 +0000 Subject: [PATCH 5/7] minor: add method doc to DAMap.ValidateKey() --- OpenSim/Framework/DAMap.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs index dd9c61b0d5..24e0895620 100644 --- a/OpenSim/Framework/DAMap.cs +++ b/OpenSim/Framework/DAMap.cs @@ -168,6 +168,10 @@ namespace OpenSim.Framework } } + /// + /// Validate the key used for storing separate data stores. + /// + /// private static void ValidateKey(string key) { if (key.Length < MIN_STORE_NAME_LENGTH) From df37738ce7702774c4d3ff1f3835bfe87e0f1a5e Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Wed, 6 Feb 2013 16:42:55 -0800 Subject: [PATCH 6/7] WebStats will now use actual logfile as specified in OpenSim.exe.config rather than hardcoded ./OpenSim.log. This allows for rotating logs and other file appender types --- OpenSim/Framework/Util.cs | 16 +++++++++++++++- OpenSim/Region/UserStatistics/WebStatsModule.cs | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 9b1e97d237..d9148fb7c1 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -45,6 +45,7 @@ using System.Text.RegularExpressions; using System.Xml; using System.Threading; using log4net; +using log4net.Appender; using Nini.Config; using Nwc.XmlRpc; using OpenMetaverse; @@ -816,9 +817,22 @@ namespace OpenSim.Framework return "."; } + public static string logFile() + { + foreach (IAppender appender in LogManager.GetRepository().GetAppenders()) + { + if (appender is FileAppender) + { + return ((FileAppender)appender).File; + } + } + + return "./OpenSim.log"; + } + public static string logDir() { - return "."; + return Path.GetDirectoryName(logFile()); } // From: http://coercedcode.blogspot.com/2008/03/c-generate-unique-filenames-within.html diff --git a/OpenSim/Region/UserStatistics/WebStatsModule.cs b/OpenSim/Region/UserStatistics/WebStatsModule.cs index 438ef485ab..b98b762764 100644 --- a/OpenSim/Region/UserStatistics/WebStatsModule.cs +++ b/OpenSim/Region/UserStatistics/WebStatsModule.cs @@ -420,7 +420,7 @@ namespace OpenSim.Region.UserStatistics Encoding encoding = Encoding.ASCII; int sizeOfChar = encoding.GetByteCount("\n"); byte[] buffer = encoding.GetBytes("\n"); - string logfile = Util.logDir() + "/" + "OpenSim.log"; + string logfile = Util.logFile(); FileStream fs = new FileStream(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); Int64 tokenCount = 0; Int64 endPosition = fs.Length / sizeOfChar; From e17392acbb46e1e48e169069a822f8b814762214 Mon Sep 17 00:00:00 2001 From: Mic Bowman Date: Wed, 6 Feb 2013 17:29:17 -0800 Subject: [PATCH 7/7] Enables script access to the per object dynamic attributes through the JsonStore script functions. Adds JsonAttachObjectStore to associate a store identifier with an object (scripts can only access the store in their host object, this could be extended but isn't necessary for now). Note this opens a method to the DAMap OSDMap. This will be removed later, but greatly simplifies the code for now. The JsonStore and these scripts are disabled by default. --- OpenSim/Framework/DAMap.cs | 8 +++ .../Framework/Interfaces/IJsonStoreModule.cs | 1 + .../Scripting/JsonStore/JsonStore.cs | 64 +++++++++++++++---- .../Scripting/JsonStore/JsonStoreModule.cs | 28 ++++++++ .../JsonStore/JsonStoreScriptModule.cs | 16 +++++ 5 files changed, 104 insertions(+), 13 deletions(-) diff --git a/OpenSim/Framework/DAMap.cs b/OpenSim/Framework/DAMap.cs index 291c8b8385..7d7738a2a0 100644 --- a/OpenSim/Framework/DAMap.cs +++ b/OpenSim/Framework/DAMap.cs @@ -73,6 +73,14 @@ namespace OpenSim.Framework m_map = (OSDMap)OSDParser.DeserializeLLSDXml(rawXml); } + // WARNING: this is temporary for experimentation only, it will be removed!!!! + public OSDMap TopLevelMap + { + get { return m_map; } + set { m_map = value; } + } + + public void ReadXml(XmlReader reader) { ReadXml(reader.ReadInnerXml()); diff --git a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs index 0bb45673cc..cc7885a7a0 100644 --- a/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IJsonStoreModule.cs @@ -35,6 +35,7 @@ namespace OpenSim.Region.Framework.Interfaces public interface IJsonStoreModule { + bool AttachObjectStore(UUID objectID); bool CreateStore(string value, ref UUID result); bool DestroyStore(UUID storeID); bool TestStore(UUID storeID); diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs index 0b7b31bd32..751e463a49 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs @@ -49,7 +49,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private OSD m_ValueStore; + protected virtual OSD ValueStore { get; set; } protected class TakeValueCallbackClass { @@ -108,17 +108,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- - public JsonStore() : this("") {} - - public JsonStore(string value) + public JsonStore() { m_TakeStore = new List(); m_ReadStore = new List(); - + } + + public JsonStore(string value) + { if (String.IsNullOrEmpty(value)) - m_ValueStore = new OSDMap(); + ValueStore = new OSDMap(); else - m_ValueStore = OSDParser.DeserializeJson(value); + ValueStore = OSDParser.DeserializeJson(value); } // ----------------------------------------------------------------- @@ -129,7 +130,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore public bool TestPath(string expr, bool useJson) { Stack path = ParsePathExpression(expr); - OSD result = ProcessPathExpression(m_ValueStore,path); + OSD result = ProcessPathExpression(ValueStore,path); if (result == null) return false; @@ -148,7 +149,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore public bool GetValue(string expr, out string value, bool useJson) { Stack path = ParsePathExpression(expr); - OSD result = ProcessPathExpression(m_ValueStore,path); + OSD result = ProcessPathExpression(ValueStore,path); return ConvertOutputValue(result,out value,useJson); } @@ -184,7 +185,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore Stack path = ParsePathExpression(expr); string pexpr = PathExpressionToKey(path); - OSD result = ProcessPathExpression(m_ValueStore,path); + OSD result = ProcessPathExpression(ValueStore,path); if (result == null) { m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); @@ -215,7 +216,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore Stack path = ParsePathExpression(expr); string pexpr = PathExpressionToKey(path); - OSD result = ProcessPathExpression(m_ValueStore,path); + OSD result = ProcessPathExpression(ValueStore,path); if (result == null) { m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); @@ -245,7 +246,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore Stack path = ParsePathExpression(expr); if (path.Count == 0) { - m_ValueStore = ovalue; + ValueStore = ovalue; return true; } @@ -254,7 +255,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore if (pexpr != "") pexpr += "."; - OSD result = ProcessPathExpression(m_ValueStore,path); + OSD result = ProcessPathExpression(ValueStore,path); if (result == null) return false; @@ -522,4 +523,41 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore return pkey; } } + + public class JsonObjectStore : JsonStore + { + private static readonly ILog m_log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private Scene m_scene; + private UUID m_objectID; + + protected override OSD ValueStore + { + get + { + SceneObjectPart sop = m_scene.GetSceneObjectPart(m_objectID); + if (sop == null) + { + // This is bad + return null; + } + + return sop.DynAttrs.TopLevelMap; + } + + // cannot set the top level + set + { + m_log.InfoFormat("[JsonStore] cannot set top level value in object store"); + } + } + + public JsonObjectStore(Scene scene, UUID oid) : base() + { + m_scene = scene; + m_objectID = oid; + } + } + } diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs index b9b3ebca21..a36ef4257d 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs @@ -170,6 +170,34 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore #region ScriptInvocationInteface + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + public bool AttachObjectStore(UUID objectID) + { + if (! m_enabled) return false; + + SceneObjectPart sop = m_scene.GetSceneObjectPart(objectID); + if (sop == null) + { + m_log.InfoFormat("[JsonStore] unable to attach to unknown object; {0}",objectID); + return false; + } + + lock (m_JsonValueStore) + { + if (m_JsonValueStore.ContainsKey(objectID)) + return true; + + JsonStore map = new JsonObjectStore(m_scene,objectID); + m_JsonValueStore.Add(objectID,map); + } + + return true; + } + // ----------------------------------------------------------------- /// /// diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index ec880a7220..48b4a9f302 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -169,6 +169,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore m_comms.RegisterScriptInvocations(this); // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); + // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore"); // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); // m_comms.RegisterScriptInvocation(this, "JsonTestStore"); @@ -214,6 +215,21 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore #endregion #region ScriptInvocationInteface + // ----------------------------------------------------------------- + /// + /// + /// + // ----------------------------------------------------------------- + [ScriptInvocation] + public UUID JsonAttachObjectStore(UUID hostID, UUID scriptID) + { + UUID uuid = UUID.Zero; + if (! m_store.AttachObjectStore(hostID)) + GenerateRuntimeError("Failed to create Json store"); + + return hostID; + } + // ----------------------------------------------------------------- /// ///