From 5c94346bd7fd218ede591182b045aeb4a57b108e Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 01:17:19 +0000 Subject: [PATCH 01/15] refactor: Move functions that lookup asset ids from task inventory or pass them through to ScriptUtils class in OpenSim.Region.Framework.dll Renames functions to better reflect what they do. This is so that code registering with modInvoke() can reuse this code to provide functions that behave in a consistent manner with existing LSL/OSSL functions. --- .../Framework/Scenes/Scripting/ScriptUtils.cs | 122 ++++++++++++++++++ .../Shared/Api/Implementation/LSL_Api.cs | 104 +++------------ 2 files changed, 137 insertions(+), 89 deletions(-) create mode 100644 OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs new file mode 100644 index 0000000000..d8aa2584a6 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs @@ -0,0 +1,122 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Region.Framework.Scenes.Scripting +{ + /// + /// Utility functions for use by scripts manipulating the scene. + /// + public static class ScriptUtils + { + /// + /// Get an asset id given an item name and an item type. + /// + /// UUID.Zero if the name and type did not match any item. + /// + /// + /// + public static UUID GetAssetIdFromItemName(SceneObjectPart part, string name, int type) + { + TaskInventoryItem item = part.Inventory.GetInventoryItem(name); + + if (item != null && item.Type == type) + return item.AssetID; + else + return UUID.Zero; + } + + /// + /// accepts a valid UUID, -or- a name of an inventory item. + /// Returns a valid UUID or UUID.Zero if key invalid and item not found + /// in prim inventory. + /// + /// Scene object part to search for inventory item + /// + /// + public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier) + { + UUID key; + + // if we can parse the string as a key, use it. + // else try to locate the name in inventory of object. found returns key, + // not found returns UUID.Zero + if (!UUID.TryParse(identifier, out key)) + { + TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); + + if (item != null) + key = item.AssetID; + else + key = UUID.Zero; + } + + return key; + } + + + /// + /// Return the UUID of the asset matching the specified key or name + /// and asset type. + /// + /// Scene object part to search for inventory item + /// + /// + /// + public static UUID GetAssetIdFromKeyOrItemName(SceneObjectPart part, string identifier, AssetType type) + { + UUID key; + + if (!UUID.TryParse(identifier, out key)) + { + TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); + if (item != null && item.Type == (int)type) + key = item.AssetID; + } + else + { + lock (part.TaskInventory) + { + foreach (KeyValuePair item in part.TaskInventory) + { + if (item.Value.Type == (int)type && item.Value.Name == identifier) + { + key = item.Value.ItemID; + break; + } + } + } + } + + return key; + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 0db6fe317b..4fa3c6077f 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -45,6 +45,7 @@ using OpenSim.Region.CoreModules.World.Terrain; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Animation; +using OpenSim.Region.Framework.Scenes.Scripting; using OpenSim.Region.Physics.Manager; using OpenSim.Region.ScriptEngine.Shared; using OpenSim.Region.ScriptEngine.Shared.Api.Plugins; @@ -333,79 +334,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } - protected UUID InventoryKey(string name, int type) - { - TaskInventoryItem item = m_host.Inventory.GetInventoryItem(name); - - if (item != null && item.Type == type) - return item.AssetID; - else - return UUID.Zero; - } - - /// - /// accepts a valid UUID, -or- a name of an inventory item. - /// Returns a valid UUID or UUID.Zero if key invalid and item not found - /// in prim inventory. - /// - /// - /// - protected UUID KeyOrName(string k) - { - UUID key; - - // if we can parse the string as a key, use it. - // else try to locate the name in inventory of object. found returns key, - // not found returns UUID.Zero - if (!UUID.TryParse(k, out key)) - { - TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k); - - if (item != null) - key = item.AssetID; - else - key = UUID.Zero; - } - - return key; - } - - /// - /// Return the UUID of the asset matching the specified key or name - /// and asset type. - /// - /// - /// - /// - protected UUID KeyOrName(string k, AssetType type) - { - UUID key; - - if (!UUID.TryParse(k, out key)) - { - TaskInventoryItem item = m_host.Inventory.GetInventoryItem(k); - if (item != null && item.Type == (int)type) - key = item.AssetID; - } - else - { - lock (m_host.TaskInventory) - { - foreach (KeyValuePair item in m_host.TaskInventory) - { - if (item.Value.Type == (int)type && item.Value.Name == k) - { - key = item.Value.ItemID; - break; - } - } - } - } - - - return key; - } - //These are the implementations of the various ll-functions used by the LSL scripts. public LSL_Float llSin(double f) { @@ -1816,7 +1744,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { UUID textureID = new UUID(); - textureID = InventoryKey(texture, (int)AssetType.Texture); + textureID = ScriptUtils.GetAssetIdFromItemName(m_host, texture, (int)AssetType.Texture); if (textureID == UUID.Zero) { if (!UUID.TryParse(texture, out textureID)) @@ -2450,7 +2378,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_SoundModule != null) { m_SoundModule.SendSound(m_host.UUID, - KeyOrName(sound, AssetType.Sound), volume, false, 0, + ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0, 0, false, false); } } @@ -2460,7 +2388,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); if (m_SoundModule != null) { - m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), + m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), volume, 20, false); } } @@ -2470,7 +2398,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); if (m_SoundModule != null) { - m_SoundModule.LoopSound(m_host.UUID, KeyOrName(sound), + m_SoundModule.LoopSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), volume, 20, true); } } @@ -2492,7 +2420,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_SoundModule != null) { m_SoundModule.SendSound(m_host.UUID, - KeyOrName(sound, AssetType.Sound), volume, false, 0, + ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, false, 0, 0, true, false); } } @@ -2504,7 +2432,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_SoundModule != null) { m_SoundModule.SendSound(m_host.UUID, - KeyOrName(sound, AssetType.Sound), volume, true, 0, 0, + ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, true, 0, 0, false, false); } } @@ -2521,7 +2449,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); if (m_SoundModule != null) - m_SoundModule.PreloadSound(m_host.UUID, KeyOrName(sound), 0); + m_SoundModule.PreloadSound(m_host.UUID, ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound), 0); ScriptSleep(1000); } @@ -3352,7 +3280,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (presence != null) { // Do NOT try to parse UUID, animations cannot be triggered by ID - UUID animID = InventoryKey(anim, (int)AssetType.Animation); + UUID animID = ScriptUtils.GetAssetIdFromItemName(m_host, anim, (int)AssetType.Animation); if (animID == UUID.Zero) presence.Animator.AddAnimation(anim, m_host.UUID); else @@ -3374,7 +3302,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (presence != null) { - UUID animID = KeyOrName(anim); + UUID animID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, anim); if (animID == UUID.Zero) presence.Animator.RemoveAnimation(anim); @@ -4319,7 +4247,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api private void DoLLTeleport(ScenePresence sp, string destination, Vector3 targetPos, Vector3 targetLookAt) { - UUID assetID = KeyOrName(destination); + UUID assetID = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, destination); // The destinaion is not an asset ID and also doesn't name a landmark. // Use it as a sim name @@ -4386,7 +4314,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); // TODO: Parameter check logic required. - m_host.CollisionSound = KeyOrName(impact_sound, AssetType.Sound); + m_host.CollisionSound = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, impact_sound, AssetType.Sound); m_host.CollisionSoundVolume = (float)impact_volume; } @@ -5912,7 +5840,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_SoundModule != null) { m_SoundModule.TriggerSoundLimited(m_host.UUID, - KeyOrName(sound, AssetType.Sound), volume, + ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, sound, AssetType.Sound), volume, bottom_south_west, top_north_east); } } @@ -6346,7 +6274,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api break; case (int)ScriptBaseClass.PSYS_SRC_TEXTURE: - prules.Texture = KeyOrName(rules.GetLSLStringItem(i + 1)); + prules.Texture = ScriptUtils.GetAssetIdFromKeyOrItemName(m_host, rules.GetLSLStringItem(i + 1)); break; case (int)ScriptBaseClass.PSYS_SRC_BURST_RATE: @@ -7269,9 +7197,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UUID sculptId; if (!UUID.TryParse(map, out sculptId)) - { - sculptId = InventoryKey(map, (int)AssetType.Texture); - } + sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture); if (sculptId == UUID.Zero) return; From 36463612794f95776e8ddea14333827cbce35eff Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 5 Feb 2013 17:19:55 -0800 Subject: [PATCH 02/15] BulletSim: make removing zero width triangles from meshes optional and, for the moment, default to 'off'. --- .../Region/Physics/BulletSPlugin/BSParam.cs | 6 +++ .../BulletSPlugin/BSShapeCollection.cs | 51 +++++++++--------- bin/lib32/BulletSim.dll | Bin 546304 -> 546304 bytes bin/lib64/BulletSim.dll | Bin 694272 -> 694272 bytes 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index bdd9ce44d8..306928ad33 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs @@ -62,6 +62,7 @@ public static class BSParam public static bool ShouldMeshSculptedPrim { get; private set; } // cause scuplted prims to get meshed public static bool ShouldForceSimplePrimMeshing { get; private set; } // if a cube or sphere, let Bullet do internal shapes public static bool ShouldUseHullsForPhysicalObjects { get; private set; } // 'true' if should create hulls for physical objects + public static bool ShouldRemoveZeroWidthTriangles { get; private set; } public static float TerrainImplementation { get; private set; } public static float TerrainFriction { get; private set; } @@ -218,6 +219,11 @@ public static class BSParam (s,cf,p,v) => { ShouldUseHullsForPhysicalObjects = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, (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, + (s,cf,p,v) => { ShouldRemoveZeroWidthTriangles = cf.GetBoolean(p, BSParam.BoolNumeric(v)); }, + (s) => { return BSParam.NumericBool(ShouldRemoveZeroWidthTriangles); }, + (s,p,l,v) => { ShouldRemoveZeroWidthTriangles = BSParam.BoolNumeric(v); } ), new ParameterDefn("MeshLevelOfDetail", "Level of detail to render meshes (32, 16, 8 or 4. 32=most detailed)", 32f, diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index f17e51340c..f59b9d973b 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -640,34 +640,37 @@ public sealed class BSShapeCollection : IDisposable { int[] indices = meshData.getIndexListAsInt(); - // int realIndicesIndex = indices.Length; + int realIndicesIndex = indices.Length; float[] verticesAsFloats = meshData.getVertexListAsFloat(); - // Remove degenerate triangles. These are triangles with two of the vertices - // are the same. This is complicated by the problem that vertices are not - // made unique in sculpties so we have to compare the values in the vertex. - int realIndicesIndex = 0; - for (int tri = 0; tri < indices.Length; tri += 3) + if (BSParam.ShouldRemoveZeroWidthTriangles) { - 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] - && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] - && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2] ) - || ( 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 + 1] == verticesAsFloats[v3 + 1] - && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2] ) ) - ) + // Remove degenerate triangles. These are triangles with two of the vertices + // are the same. This is complicated by the problem that vertices are not + // made unique in sculpties so we have to compare the values in the vertex. + realIndicesIndex = 0; + for (int tri = 0; tri < indices.Length; tri += 3) { - // None of the vertices of the triangles are the same. This is a good triangle; - indices[realIndicesIndex + 0] = indices[tri + 0]; - indices[realIndicesIndex + 1] = indices[tri + 1]; - indices[realIndicesIndex + 2] = indices[tri + 2]; - realIndicesIndex += 3; + 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] + && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1] + && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2]) + || (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 + 1] == verticesAsFloats[v3 + 1] + && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2])) + ) + { + // None of the vertices of the triangles are the same. This is a good triangle; + indices[realIndicesIndex + 0] = indices[tri + 0]; + indices[realIndicesIndex + 1] = indices[tri + 1]; + indices[realIndicesIndex + 2] = indices[tri + 2]; + realIndicesIndex += 3; + } } } DetailLog("{0},BSShapeCollection.CreatePhysicalMesh,origTri={1},realTri={2},numVerts={3}", diff --git a/bin/lib32/BulletSim.dll b/bin/lib32/BulletSim.dll index 0d24f121c095374b445098ad73884a0ffd76912c..de4f95ad08c7abbb05070781ff91ab75db689792 100755 GIT binary patch delta 1114 zcmZ8fT}YEr82&!@Z9CHiXE<|0qSj0o6YTtmm4uNOgJx*k#h^h-KQ5THQb|E*BO$tp zL4#wUunQ3{CKL=dXg7mFT^JZF5ZuKqA}5zyvS=W`HFZ(5r!brRv>K@E>l4R3P|`@}ahy3$hZ zMi{^OUm%N?#i#{c(EZ{W{MZcXC~7z_-doVyGao;fle44#;nh!~$5?kJf6+&~^3;0Ep$9)vpjR7uK7u!j}9td9bp z2ds!W8Bt{!c?FS;BauAtQaw_Hh`u5A5Nhr_R9prm4R~8FKp7ALqye(A42>p{fXF#D zA|>xQ!oI&Y$xVO|@S_!2B$`lb+md3HtE7O}Cy7-X>S!q_vV1XHz|-ObNV-pax1r`X z13oYa^&<y@B;61X8c}o0(h)}r_=0L zjngDe(Pf&ZdHRlS(K0=tKdHtrb21m}WP{Ad{4B_#Y>~xTlBL)R%d*l%_Kxka3ahex yrg6-j+|7G=Klkwv5A!IG@mapeQ+$nY@H{W@60h(BUgO$;F<>8X=eh%Ex8XO(`rFF@ delta 1144 zcmZ8gT}YEr82&!@Z97wov;3Pdk=e`%8hU=jO2R-vaK@**88m8@Qi0{Fkp)7F4DBY0 zgtNel1tYxJMS(D(73->9C=7}a^kRY0jlnL2Mo{#gIq2jI58wB^@AEw8=i6c_Pb}q0 z=$0?P4nMc(W0v!yj)wt#A)rfC0W1ImUS6H=p}OYO0aXTguB>_oDz1)Y@Mj1vDHa2I2yV^|*aS=i zlEUeL1xljVf$CcP(2-7A^2DM4lovtSyr@XzPUFD$gI>V6A*+n#`SZY&Vgp9qYB)@^ zxp9OMd|3G|OQyMi2LWEuTn%Z1%2=kE<VF#!8>aU7vWLu%4pwW#Ef zf6#PCBRVs1ACr3GB|g$aMo5r^$TW$ND48QmBuQ4t8p)6>$&msnl09NjL~ALg_0&xn z9ik&NNJBJCC+Reur%NKf2E^>!gBUqB{o@6y z4`cuWCLk`^D##gZrq#eLd3(+NRW6;AjrvM!%gfn-QqEQ}$(8BlnRzi8`MIevMTsei gxy6RlCz^4(Gcs(yX2w}}h&ght;P&vJoGa%605?`FL;wH) delta 142 zcmZqJpw+NJYXKwklV5z3nHhbVJQ$jT7~6vwL6`}MnSq!Eh*^P{4T#yd2QhMN`o{}Y zAIJa%Oh8<|Rgg2-OjnYZ-%fTCgHK=X;uoinJ^#!MlybF-Nv=#U&&-R-$j?oU3Cd4O hEh>pgNiCb+XU6Hi{e~H5%^~K;zxcL?|Kwab4*=;aFPQ)U From eddfed3812354c5990631be0ac985cc25d5aa0e9 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 01:37:22 +0000 Subject: [PATCH 03/15] Allow JsonReadNotecard() to accept the name of the notecard as well as the asset ID. Agreed in discussion with cmickeyb. This is to make this consistent with similar existing LSL/OSSL functions such as llTriggerSound() and osNpcLoadAppearance() that allow an item name or an asset id. --- .../JsonStore/JsonStoreScriptModule.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs index 5b7a79d013..ec880a7220 100644 --- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs @@ -39,6 +39,7 @@ using OpenMetaverse.StructuredData; using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Scenes.Scripting; using System.Collections.Generic; using System.Text.RegularExpressions; @@ -256,10 +257,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// // ----------------------------------------------------------------- [ScriptInvocation] - public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) + public UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { UUID reqID = UUID.Random(); - Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); + Util.FireAndForget(o => DoJsonReadNotecard(reqID, hostID, scriptID, storeID, path, notecardIdentifier)); return reqID; } @@ -463,14 +464,23 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore /// /// // ----------------------------------------------------------------- - private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) + private void DoJsonReadNotecard( + UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string notecardIdentifier) { + UUID assetID; + + if (!UUID.TryParse(notecardIdentifier, out assetID)) + { + SceneObjectPart part = m_scene.GetSceneObjectPart(hostID); + assetID = ScriptUtils.GetAssetIdFromItemName(part, notecardIdentifier, (int)AssetType.Notecard); + } + AssetBase a = m_scene.AssetService.Get(assetID.ToString()); if (a == null) - GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID)); + GenerateRuntimeError(String.Format("Unable to find notecard asset {0}", assetID)); if (a.Type != (sbyte)AssetType.Notecard) - GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID)); + GenerateRuntimeError(String.Format("Invalid notecard asset {0}", assetID)); m_log.DebugFormat("[JsonStoreScripts]: read notecard in context {0}",storeID); @@ -483,11 +493,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore } catch (Exception e) { - m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}",e.Message); + m_log.WarnFormat("[JsonStoreScripts]: Json parsing failed; {0}", e.Message); } - GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString())); - m_comms.DispatchReply(scriptID,0,"",reqID.ToString()); + GenerateRuntimeError(String.Format("Json parsing failed for {0}", assetID)); + m_comms.DispatchReply(scriptID, 0, "", reqID.ToString()); } // ----------------------------------------------------------------- From dfe5826f9fd8854ddb5f0cc465564d8f124d7786 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 01:44:37 +0000 Subject: [PATCH 04/15] Remove wrong code in ScriptUtils.GetAssetIdFromKeyOrItemName which would return the item ID instead of the asset ID if the identifier was a uuid that matched an inventory item name. This would practically never happen. This makes this overloaded version of the function consistent with the other version. It looks like this accidentally came over in commit c5af16a from Tue Oct 16 12:40:21 2012 However, there's arguably a case for looking for an item name that matches a UUID before assuming that the identifier is already an asset ID. --- .../Framework/Scenes/Scripting/ScriptUtils.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs index d8aa2584a6..f08ba59ea3 100644 --- a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs +++ b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs @@ -82,7 +82,6 @@ namespace OpenSim.Region.Framework.Scenes.Scripting return key; } - /// /// Return the UUID of the asset matching the specified key or name /// and asset type. @@ -101,20 +100,6 @@ namespace OpenSim.Region.Framework.Scenes.Scripting if (item != null && item.Type == (int)type) key = item.AssetID; } - else - { - lock (part.TaskInventory) - { - foreach (KeyValuePair item in part.TaskInventory) - { - if (item.Value.Type == (int)type && item.Value.Name == identifier) - { - key = item.Value.ItemID; - break; - } - } - } - } return key; } From 9ebad38c34315302d6ed26356fc4da5c0465e3cb Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 02:08:44 +0000 Subject: [PATCH 05/15] Remove unused ScriptEngineLoader and ScriptEngineInterface in OpenSim.Region.Framework.dll I believe this predates the generic system of registering interfaces and is very long unused. --- OpenSim/Region/Framework/Scenes/Scene.cs | 11 -- .../Scenes/Scripting/ScriptEngineInterface.cs | 38 ------ .../Scenes/Scripting/ScriptEngineLoader.cs | 119 ------------------ 3 files changed, 168 deletions(-) delete mode 100644 OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineInterface.cs delete mode 100644 OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineLoader.cs diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index f8d84e359e..482235c327 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4482,19 +4482,8 @@ namespace OpenSim.Region.Framework.Scenes #region Script Engine - private List ScriptEngines = new List(); public bool DumpAssetsToFile; - /// - /// - /// - /// - public void AddScriptEngine(ScriptEngineInterface scriptEngine) - { - ScriptEngines.Add(scriptEngine); - scriptEngine.InitializeEngine(this); - } - private bool ScriptDanger(SceneObjectPart part,Vector3 pos) { ILandObject parcel = LandChannel.GetLandObject(pos.X, pos.Y); diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineInterface.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineInterface.cs deleted file mode 100644 index 812a21c97e..0000000000 --- a/OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineInterface.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -//TODO: WHERE TO PLACE THIS? - -namespace OpenSim.Region.Framework.Scenes.Scripting -{ - public interface ScriptEngineInterface - { - void InitializeEngine(Scene Sceneworld); - void Shutdown(); -// void StartScript(string ScriptID, IScriptHost ObjectID); - } -} diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineLoader.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineLoader.cs deleted file mode 100644 index c58ccc5de8..0000000000 --- a/OpenSim/Region/Framework/Scenes/Scripting/ScriptEngineLoader.cs +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* Original code: Tedd Hansen */ -using System; -using System.IO; -using System.Reflection; -using log4net; - -namespace OpenSim.Region.Framework.Scenes.Scripting -{ - public class ScriptEngineLoader - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - public ScriptEngineInterface LoadScriptEngine(string EngineName) - { - ScriptEngineInterface ret = null; - try - { - ret = - LoadAndInitAssembly( - Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine." + EngineName + ".dll"), - "OpenSim.Region.ScriptEngine." + EngineName + ".ScriptEngine"); - } - catch (Exception e) - { - m_log.Error("[ScriptEngine]: " + - "Error loading assembly \"" + EngineName + "\": " + e.Message + ", " + - e.StackTrace.ToString()); - } - return ret; - } - - /// - /// Does actual loading and initialization of script Assembly - /// - /// AppDomain to load script into - /// FileName of script assembly (.dll) - /// - private ScriptEngineInterface LoadAndInitAssembly(string FileName, string NameSpace) - { - //Common.SendToDebug("Loading ScriptEngine Assembly " + FileName); - // Load .Net Assembly (.dll) - // Initialize and return it - - // TODO: Add error handling - - Assembly a; - //try - //{ - - - // Load to default appdomain (temporary) - a = Assembly.LoadFrom(FileName); - // Load to specified appdomain - // TODO: Insert security - //a = FreeAppDomain.Load(FileName); - //} - //catch (Exception e) - //{ - // m_log.Error("[ScriptEngine]: Error loading assembly \String.Empty + FileName + "\": " + e.ToString()); - //} - - - //m_log.Debug("Loading: " + FileName); - //foreach (Type _t in a.GetTypes()) - //{ - // m_log.Debug("Type: " + _t.ToString()); - //} - - Type t; - //try - //{ - t = a.GetType(NameSpace, true); - //} - //catch (Exception e) - //{ - // m_log.Error("[ScriptEngine]: Error initializing type \String.Empty + NameSpace + "\" from \String.Empty + FileName + "\": " + e.ToString()); - //} - - ScriptEngineInterface ret; - //try - //{ - ret = (ScriptEngineInterface) Activator.CreateInstance(t); - //} - //catch (Exception e) - //{ - // m_log.Error("[ScriptEngine]: Error initializing type \String.Empty + NameSpace + "\" from \String.Empty + FileName + "\": " + e.ToString()); - //} - - return ret; - } - } -} From 2ce8a050e4181c2f2a9ee215a400c02678d88865 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 02:15:54 +0000 Subject: [PATCH 06/15] Remove very long unused IScriptHost and NullScriptHost --- .../Framework/Scenes/SceneObjectPart.cs | 2 +- .../Framework/Scenes/Scripting/IScriptHost.cs | 46 ---------- .../Scenes/Scripting/NullScriptHost.cs | 91 ------------------- 3 files changed, 1 insertion(+), 138 deletions(-) delete mode 100644 OpenSim/Region/Framework/Scenes/Scripting/IScriptHost.cs delete mode 100644 OpenSim/Region/Framework/Scenes/Scripting/NullScriptHost.cs diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 189d2987eb..19e6d3759a 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -116,7 +116,7 @@ namespace OpenSim.Region.Framework.Scenes #endregion Enumerations - public class SceneObjectPart : IScriptHost, ISceneEntity + public class SceneObjectPart : ISceneEntity { /// /// Denote all sides of the prim diff --git a/OpenSim/Region/Framework/Scenes/Scripting/IScriptHost.cs b/OpenSim/Region/Framework/Scenes/Scripting/IScriptHost.cs deleted file mode 100644 index f3be02842a..0000000000 --- a/OpenSim/Region/Framework/Scenes/Scripting/IScriptHost.cs +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using OpenMetaverse; - -namespace OpenSim.Region.Framework.Scenes.Scripting -{ - public interface IScriptHost - { - string Name { get; set; } - string Description { get; set; } - - UUID UUID { get; } - UUID OwnerID { get; } - UUID CreatorID { get; } - Vector3 AbsolutePosition { get; } - - string SitName { get; set; } - string TouchName { get; set; } - void SetText(string text, Vector3 color, double alpha); - } -} diff --git a/OpenSim/Region/Framework/Scenes/Scripting/NullScriptHost.cs b/OpenSim/Region/Framework/Scenes/Scripting/NullScriptHost.cs deleted file mode 100644 index d7198f0305..0000000000 --- a/OpenSim/Region/Framework/Scenes/Scripting/NullScriptHost.cs +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using OpenMetaverse; -using log4net; -using System.Reflection; -using OpenSim.Framework; - -namespace OpenSim.Region.Framework.Scenes.Scripting -{ - public class NullScriptHost : IScriptHost - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Vector3 m_pos = new Vector3(((int)Constants.RegionSize * 0.5f), ((int)Constants.RegionSize * 0.5f), 30); - - public string Name - { - get { return "Object"; } - set { } - } - - public string SitName - { - get { return String.Empty; } - set { } - } - - public string TouchName - { - get { return String.Empty; } - set { } - } - - public string Description - { - get { return String.Empty; } - set { } - } - - public UUID UUID - { - get { return UUID.Zero; } - } - - public UUID OwnerID - { - get { return UUID.Zero; } - } - - public UUID CreatorID - { - get { return UUID.Zero; } - } - - public Vector3 AbsolutePosition - { - get { return m_pos; } - } - - public void SetText(string text, Vector3 color, double alpha) - { - m_log.Warn("Tried to SetText "+text+" on NullScriptHost"); - } - } -} From 145e38e5e9bed04d5c41880a5d508cab4603cc1d Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 02:21:17 +0000 Subject: [PATCH 07/15] Remove long unused Scene.DumpAssetsToFile boolean. --- OpenSim/Region/Application/OpenSimBase.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 5 ----- OpenSim/Tests/Common/Helpers/SceneHelpers.cs | 2 +- OpenSim/Tests/Common/Mock/TestScene.cs | 3 +-- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index f5c06df3fb..3c8e199067 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -714,7 +714,7 @@ namespace OpenSim return new Scene( regionInfo, circuitManager, sceneGridService, - simDataService, estateDataService, false, + simDataService, estateDataService, Config, m_version); } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 482235c327..de3978c4db 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -720,7 +720,6 @@ namespace OpenSim.Region.Framework.Scenes public Scene(RegionInfo regInfo, AgentCircuitManager authen, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, - bool dumpAssetsToFile, IConfigSource config, string simulatorVersion) : this(regInfo) { @@ -811,8 +810,6 @@ namespace OpenSim.Region.Framework.Scenes RegisterDefaultSceneEvents(); - DumpAssetsToFile = dumpAssetsToFile; - // XXX: Don't set the public property since we don't want to activate here. This needs to be handled // better in the future. m_scripts_enabled = !RegionInfo.RegionSettings.DisableScripts; @@ -4482,8 +4479,6 @@ namespace OpenSim.Region.Framework.Scenes #region Script Engine - public bool DumpAssetsToFile; - private bool ScriptDanger(SceneObjectPart part,Vector3 pos) { ILandObject parcel = LandChannel.GetLandObject(pos.X, pos.Y); diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index ea3e3487f0..dc20f13555 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs @@ -139,7 +139,7 @@ namespace OpenSim.Tests.Common SceneCommunicationService scs = new SceneCommunicationService(); TestScene testScene = new TestScene( - regInfo, m_acm, scs, m_simDataService, m_estateDataService, false, configSource, null); + regInfo, m_acm, scs, m_simDataService, m_estateDataService, configSource, null); INonSharedRegionModule godsModule = new GodsModule(); godsModule.Initialise(new IniConfigSource()); diff --git a/OpenSim/Tests/Common/Mock/TestScene.cs b/OpenSim/Tests/Common/Mock/TestScene.cs index d4b564869b..a7e0dfbb99 100644 --- a/OpenSim/Tests/Common/Mock/TestScene.cs +++ b/OpenSim/Tests/Common/Mock/TestScene.cs @@ -41,10 +41,9 @@ namespace OpenSim.Tests.Common.Mock public TestScene( RegionInfo regInfo, AgentCircuitManager authen, SceneCommunicationService sceneGridService, ISimulationDataService simDataService, IEstateDataService estateDataService, - bool dumpAssetsToFile, IConfigSource config, string simulatorVersion) : base(regInfo, authen, sceneGridService, simDataService, estateDataService, - dumpAssetsToFile, config, simulatorVersion) + config, simulatorVersion) { } From 07a7ec4d1b7af92bf385a04f20ed208cf339bcac Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 6 Feb 2013 02:40:32 +0000 Subject: [PATCH 08/15] minor: Add explanation of MaptileStaticUUID setting in Regions.ini.example --- bin/Regions/Regions.ini.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/Regions/Regions.ini.example b/bin/Regions/Regions.ini.example index f5282a7f80..ab3a62aea9 100644 --- a/bin/Regions/Regions.ini.example +++ b/bin/Regions/Regions.ini.example @@ -45,4 +45,8 @@ ExternalHostName = "SYSTEMIP" ; * ; RegionType = "Mainland" + +; * +; * UUID of texture to use as a maptile for this region. +; * Only set if you have disabled dynamic generation of the map tile from the region contents. ; MaptileStaticUUID = "00000000-0000-0000-0000-000000000000" From e5beb480eaf23fa7454728724de80b2a67ded1e8 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 6 Feb 2013 08:03:04 +0000 Subject: [PATCH 09/15] Partial port of Avination's support for the new physics parameters. Implements the parameters as properties, the serialization and database storage (MySQL only). Implements llSetPrimitiveParams for prim physics shape and the other 4 extra params. Only the prim shape type "None" is currently functional. No support for the Viewer UI (yet), that will be ported in due course. Lots more to port, this is a large-ish changeset. --- OpenSim/Data/MySQL/MySQLSimulationData.cs | 56 +++++++---- .../MySQL/Resources/RegionStore.migrations | 13 +++ OpenSim/Framework/ExtraPhysicsData.cs | 50 ++++++++++ .../Framework/Scenes/SceneObjectPart.cs | 96 ++++++++++++++++++- .../Serialization/SceneObjectSerializer.cs | 43 +++++++++ .../Shared/Api/Implementation/LSL_Api.cs | 16 ++++ .../Shared/Api/Runtime/LSL_Constants.cs | 11 +++ 7 files changed, 264 insertions(+), 21 deletions(-) create mode 100644 OpenSim/Framework/ExtraPhysicsData.cs diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index c95311e6c7..2f471a0c07 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -52,7 +52,7 @@ namespace OpenSim.Data.MySQL private string m_connectionString; private object m_dbLock = new object(); - protected virtual Assembly Assembly + protected Assembly Assembly { get { return GetType().Assembly; } } @@ -119,8 +119,10 @@ namespace OpenSim.Data.MySQL // Eligibility check // - if ((flags & (uint)PrimFlags.Temporary) != 0) - return; + // PrimFlags.Temporary is not used in OpenSim code and cannot + // be guaranteed to always be clear. Don't check it. +// if ((flags & (uint)PrimFlags.Temporary) != 0) +// return; if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) return; @@ -135,7 +137,7 @@ namespace OpenSim.Data.MySQL foreach (SceneObjectPart prim in obj.Parts) { cmd.Parameters.Clear(); - + cmd.CommandText = "replace into prims (" + "UUID, CreationDate, " + "Name, Text, Description, " + @@ -171,8 +173,10 @@ namespace OpenSim.Data.MySQL "ParticleSystem, ClickAction, Material, " + "CollisionSound, CollisionSoundVolume, " + "PassTouches, " + - "LinkNumber, MediaURL, DynAttrs) " + - "values (?UUID, " + + "LinkNumber, MediaURL, " + + "PhysicsShapeType, Density, GravityModifier, " + + "Friction, Restitution, DynAttrs " + + ") values (" + "?UUID, " + "?CreationDate, ?Name, ?Text, " + "?Description, ?SitName, ?TouchName, " + "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " + @@ -203,15 +207,17 @@ namespace OpenSim.Data.MySQL "?SaleType, ?ColorR, ?ColorG, " + "?ColorB, ?ColorA, ?ParticleSystem, " + "?ClickAction, ?Material, ?CollisionSound, " + - "?CollisionSoundVolume, ?PassTouches, ?LinkNumber, " + - "?MediaURL, ?DynAttrs)"; - + "?CollisionSoundVolume, ?PassTouches, " + + "?LinkNumber, ?MediaURL, " + + "?PhysicsShapeType, ?Density, ?GravityModifier, " + + "?Friction, ?Restitution, ?DynAttrs)"; + FillPrimCommand(cmd, prim, obj.UUID, regionUUID); - + ExecuteNonQuery(cmd); - + cmd.Parameters.Clear(); - + cmd.CommandText = "replace into primshapes (" + "UUID, Shape, ScaleX, ScaleY, " + "ScaleZ, PCode, PathBegin, PathEnd, " + @@ -234,9 +240,9 @@ namespace OpenSim.Data.MySQL "?ProfileEnd, ?ProfileCurve, " + "?ProfileHollow, ?Texture, ?ExtraParams, " + "?State, ?Media)"; - + FillShapeCommand(cmd, prim); - + ExecuteNonQuery(cmd); } } @@ -582,7 +588,7 @@ namespace OpenSim.Data.MySQL cmd.CommandText = "insert into terrain (RegionUUID, " + "Revision, Heightfield) values (?RegionUUID, " + "1, ?Heightfield)"; - + cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter)); ExecuteNonQuery(cmd); @@ -741,7 +747,7 @@ namespace OpenSim.Data.MySQL { //No result, so store our default windlight profile and return it nWP.regionID = regionUUID; - StoreRegionWindlightSettings(nWP); +// StoreRegionWindlightSettings(nWP); return nWP; } else @@ -1097,7 +1103,8 @@ namespace OpenSim.Data.MySQL "?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " + "?SunVectorX, ?SunVectorY, ?SunVectorZ, " + "?LoadedCreationDateTime, ?LoadedCreationID, " + - "?TerrainImageID, ?TelehubObject, ?ParcelImageID) "; + "?TerrainImageID, " + + "?TelehubObject, ?ParcelImageID)"; FillRegionSettingsCommand(cmd, rs); @@ -1300,6 +1307,12 @@ namespace OpenSim.Data.MySQL else prim.DynAttrs = new DAMap(); + prim.PhysicsShapeType = (byte)Convert.ToInt32(row["PhysicsShapeType"].ToString()); + prim.Density = (float)(double)row["Density"]; + prim.GravityModifier = (float)(double)row["GravityModifier"]; + prim.Friction = (float)(double)row["Friction"]; + prim.Bounciness = (float)(double)row["Restitution"]; + return prim; } @@ -1499,7 +1512,7 @@ namespace OpenSim.Data.MySQL for (int x = 0; x < (int)Constants.RegionSize; x++) for (int y = 0; y < (int)Constants.RegionSize; y++) { - double height = val[x, y]; + double height = 20.0; if (height == 0.0) height = double.Epsilon; @@ -1646,6 +1659,12 @@ namespace OpenSim.Data.MySQL cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum); cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl); + cmd.Parameters.AddWithValue("PhysicsShapeType", prim.PhysicsShapeType); + cmd.Parameters.AddWithValue("Density", (double)prim.Density); + cmd.Parameters.AddWithValue("GravityModifier", (double)prim.GravityModifier); + cmd.Parameters.AddWithValue("Friction", (double)prim.Friction); + cmd.Parameters.AddWithValue("Restitution", (double)prim.Bounciness); + if (prim.DynAttrs.Count > 0) cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml()); else @@ -1728,6 +1747,7 @@ namespace OpenSim.Data.MySQL cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime); cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID); cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID); + cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID); cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject); } diff --git a/OpenSim/Data/MySQL/Resources/RegionStore.migrations b/OpenSim/Data/MySQL/Resources/RegionStore.migrations index c48aec2798..48cd60b6d0 100644 --- a/OpenSim/Data/MySQL/Resources/RegionStore.migrations +++ b/OpenSim/Data/MySQL/Resources/RegionStore.migrations @@ -910,3 +910,16 @@ BEGIN; ALTER TABLE prims ADD COLUMN DynAttrs TEXT; COMMIT; + +:VERSION 47 #---------------- Extra prim params + +BEGIN; + +ALTER TABLE prims ADD COLUMN `PhysicsShapeType` tinyint(4) NOT NULL default '0'; +ALTER TABLE prims ADD COLUMN `Density` double NOT NULL default '1000'; +ALTER TABLE prims ADD COLUMN `GravityModifier` double NOT NULL default '1'; +ALTER TABLE prims ADD COLUMN `Friction` double NOT NULL default '0.6'; +ALTER TABLE prims ADD COLUMN `Restitution` double NOT NULL default '0.5'; + +COMMIT; + diff --git a/OpenSim/Framework/ExtraPhysicsData.cs b/OpenSim/Framework/ExtraPhysicsData.cs new file mode 100644 index 0000000000..9e7334f0da --- /dev/null +++ b/OpenSim/Framework/ExtraPhysicsData.cs @@ -0,0 +1,50 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using OpenMetaverse; + +namespace OpenSim.Framework +{ + public enum PhysShapeType : byte + { + prim = 0, + none = 1, + convex = 2, + + invalid = 255 // use to mark invalid data in ExtraPhysicsData + } + + public struct ExtraPhysicsData + { + public float Density; + public float GravitationModifier; + public float Friction; + public float Bounce; + public PhysShapeType PhysShapeType; + + } +} diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 19e6d3759a..55b5462e4d 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -302,6 +302,13 @@ namespace OpenSim.Region.Framework.Scenes protected Vector3 m_lastAcceleration; protected Vector3 m_lastAngularVelocity; protected int m_lastTerseSent; + + protected byte m_physicsShapeType = (byte)PhysShapeType.prim; + // TODO: Implement these + //protected float m_density = 1000.0f; // in kg/m^3 + //protected float m_gravitymod = 1.0f; + //protected float m_friction = 0.6f; // wood + //protected float m_bounce = 0.5f; // wood /// /// Stores media texture data @@ -1322,6 +1329,69 @@ namespace OpenSim.Region.Framework.Scenes set { m_collisionSoundVolume = value; } } + public byte DefaultPhysicsShapeType() + { + byte type; + + if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh)) + type = (byte)PhysShapeType.convex; + else + type = (byte)PhysShapeType.prim; + + return type; + } + + public byte PhysicsShapeType + { + get { return m_physicsShapeType; } + set + { + byte oldv = m_physicsShapeType; + + if (value >= 0 && value <= (byte)PhysShapeType.convex) + { + if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this) + m_physicsShapeType = DefaultPhysicsShapeType(); + else + m_physicsShapeType = value; + } + else + m_physicsShapeType = DefaultPhysicsShapeType(); + + if (m_physicsShapeType != oldv && ParentGroup != null) + { + if (m_physicsShapeType == (byte)PhysShapeType.none) + { + if (PhysActor != null) + { + Velocity = new Vector3(0, 0, 0); + Acceleration = new Vector3(0, 0, 0); + if (ParentGroup.RootPart == this) + AngularVelocity = new Vector3(0, 0, 0); + ParentGroup.Scene.RemovePhysicalPrim(1); + RemoveFromPhysics(); + } + } + else if (PhysActor == null) + { + ApplyPhysics((uint)Flags, VolumeDetectActive); + } + else + { + // TODO: Update physics actor + } + + if (ParentGroup != null) + ParentGroup.HasGroupChanged = true; + } + } + } + + public float Density { get; set; } + public float GravityModifier { get; set; } + public float Friction { get; set; } + public float Bounciness { get; set; } + #endregion Public Properties with only Get private uint ApplyMask(uint val, bool set, uint mask) @@ -1523,9 +1593,8 @@ namespace OpenSim.Region.Framework.Scenes if (!ParentGroup.Scene.CollidablePrims) return; -// m_log.DebugFormat( -// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", -// Name, LocalId, UUID, m_physicalPrim); + if (PhysicsShapeType == (byte)PhysShapeType.none) + return; bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; @@ -3878,6 +3947,26 @@ namespace OpenSim.Region.Framework.Scenes } } + public void UpdateExtraPhysics(ExtraPhysicsData physdata) + { + if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null) + return; + + if (PhysicsShapeType != (byte)physdata.PhysShapeType) + { + PhysicsShapeType = (byte)physdata.PhysShapeType; + + } + + if(Density != physdata.Density) + Density = physdata.Density; + if(GravityModifier != physdata.GravitationModifier) + GravityModifier = physdata.GravitationModifier; + if(Friction != physdata.Friction) + Friction = physdata.Friction; + if(Bounciness != physdata.Bounce) + Bounciness = physdata.Bounce; + } /// /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. /// @@ -3949,6 +4038,7 @@ namespace OpenSim.Region.Framework.Scenes if (SetPhantom || ParentGroup.IsAttachment + || PhysicsShapeType == (byte)PhysShapeType.none || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints { AddFlag(PrimFlags.Phantom); diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 4a2a47e685..78229fee5c 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -367,6 +367,13 @@ namespace OpenSim.Region.Framework.Scenes.Serialization m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2); m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3); m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4); + + m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType); + m_SOPXmlProcessors.Add("Density", ProcessDensity); + m_SOPXmlProcessors.Add("Friction", ProcessFriction); + m_SOPXmlProcessors.Add("Bounce", ProcessBounce); + m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier); + #endregion #region TaskInventoryXmlProcessors initialization @@ -594,6 +601,31 @@ namespace OpenSim.Region.Framework.Scenes.Serialization obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty); } + private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlTextReader reader) + { + obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty); + } + + private static void ProcessDensity(SceneObjectPart obj, XmlTextReader reader) + { + obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty); + } + + private static void ProcessFriction(SceneObjectPart obj, XmlTextReader reader) + { + obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty); + } + + private static void ProcessBounce(SceneObjectPart obj, XmlTextReader reader) + { + obj.Bounciness = reader.ReadElementContentAsFloat("Bounce", String.Empty); + } + + private static void ProcessGravityModifier(SceneObjectPart obj, XmlTextReader reader) + { + obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty); + } + private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader) { List errorNodeNames; @@ -1257,6 +1289,17 @@ namespace OpenSim.Region.Framework.Scenes.Serialization writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString()); writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString()); + if(sop.PhysicsShapeType != sop.DefaultPhysicsShapeType()) + writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower()); + if (sop.Density != 1000.0f) + writer.WriteElementString("Density", sop.Density.ToString().ToLower()); + if (sop.Friction != 0.6f) + writer.WriteElementString("Friction", sop.Friction.ToString().ToLower()); + if (sop.Bounciness != 0.5f) + writer.WriteElementString("Bounce", sop.Bounciness.ToString().ToLower()); + if (sop.GravityModifier != 1.0f) + writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower()); + writer.WriteEndElement(); } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 4fa3c6077f..64052ae94c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -7594,6 +7594,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api part.ScriptSetPhysicsStatus(physics); break; + case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE: + if (remain < 1) + return null; + + int shape_type = rules.GetLSLIntegerItem(idx++); + + ExtraPhysicsData physdata = new ExtraPhysicsData(); + physdata.Density = part.Density; + physdata.Bounce = part.Bounciness; + physdata.GravitationModifier = part.GravityModifier; + physdata.PhysShapeType = (PhysShapeType)shape_type; + + part.UpdateExtraPhysics(physdata); + + break; + case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: if (remain < 1) return null; diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 9bf1a64cf9..bd66ba3700 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs @@ -661,6 +661,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase public const int PRIM_MEDIA_PERM_GROUP = 2; public const int PRIM_MEDIA_PERM_ANYONE = 4; + public const int PRIM_PHYSICS_SHAPE_TYPE = 30; + public const int PRIM_PHYSICS_SHAPE_PRIM = 0; + public const int PRIM_PHYSICS_SHAPE_CONVEX = 2; + public const int PRIM_PHYSICS_SHAPE_NONE = 1; + + public const int PRIM_PHYSICS_MATERIAL = 31; + public const int DENSITY = 1; + public const int FRICTION = 2; + public const int RESTITUTION = 4; + public const int GRAVITY_MULTIPLIER = 8; + // extra constants for llSetPrimMediaParams public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000); From 054a9928a0a393e6e880c0a716714b9f009f6ede Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 6 Feb 2013 18:13:02 +0000 Subject: [PATCH 10/15] Fix a bug I brought in by manually editing a diff file. Terrain is if cource not always at 20m. --- OpenSim/Data/MySQL/MySQLSimulationData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index 2f471a0c07..41174f4137 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -1512,7 +1512,7 @@ namespace OpenSim.Data.MySQL for (int x = 0; x < (int)Constants.RegionSize; x++) for (int y = 0; y < (int)Constants.RegionSize; y++) { - double height = 20.0; + double height = val[x, y]; if (height == 0.0) height = double.Epsilon; From 67d92e4e168bf0861024e3be5cd069c77c9144f6 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 6 Feb 2013 11:49:10 -0800 Subject: [PATCH 11/15] 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 12/15] 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 13/15] 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 14/15] 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 15/15] 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)