From ddef8f16e58471d19baa63f14134b25309cf2570 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 25 Jan 2013 16:00:17 -0800 Subject: [PATCH] BulletSim: first attempt at reporting top colliders --- .../Region/Physics/BulletSPlugin/BSDynamics.cs | 10 ++++++---- .../Physics/BulletSPlugin/BSPhysObject.cs | 17 +++++++++++++++++ OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 6 ------ OpenSim/Region/Physics/BulletSPlugin/BSScene.cs | 17 ++++++++++++++++- .../Physics/BulletSPlugin/BulletSimTODO.txt | 4 ++++ 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 5c531fcc2f..06b46201eb 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs @@ -597,8 +597,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin // Moderate angular movement introduced by Bullet. // TODO: possibly set AngularFactor and LinearFactor for the type of vehicle. // Maybe compute linear and angular factor and damping from params. - float angularDamping = BSParam.VehicleAngularDamping; - PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, angularDamping); + PhysicsScene.PE.SetAngularDamping(Prim.PhysBody, BSParam.VehicleAngularDamping); PhysicsScene.PE.SetLinearFactor(Prim.PhysBody, BSParam.VehicleLinearFactorV); PhysicsScene.PE.SetAngularFactorV(Prim.PhysBody, BSParam.VehicleAngularFactorV); @@ -615,8 +614,11 @@ namespace OpenSim.Region.Physics.BulletSPlugin // The actual vehicle gravity is set to zero in Bullet so we can do all the application of same. PhysicsScene.PE.SetGravity(Prim.PhysBody, Vector3.Zero); - VDetailLog("{0},BSDynamics.Refresh,mass={1},frict={2},inert={3},aDamp={4},grav={5}", - Prim.LocalID, m_vehicleMass, Prim.Inertia, angularDamping, m_VehicleGravity); + VDetailLog("{0},BSDynamics.Refresh,mass={1},inert={2},grav={3},aDamp={4},frict={5},rest={6},lFact={7},aFact={8}", + Prim.LocalID, m_vehicleMass, Prim.Inertia, m_VehicleGravity, + BSParam.VehicleAngularDamping, BSParam.VehicleFriction, BSParam.VehicleRestitution, + BSParam.VehicleLinearFactor, BSParam.VehicleAngularFactor + ); } else { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 285d4a2701..5e8143ca00 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -95,6 +95,8 @@ public abstract class BSPhysObject : PhysicsActor SubscribedEventsMs = 0; CollidingStep = 0; CollidingGroundStep = 0; + CollisionAccumulation = 0; + CollisionScore = 0; } // Tell the object to clean up. @@ -239,6 +241,9 @@ public abstract class BSPhysObject : PhysicsActor // The collision flags we think are set in Bullet protected CollisionFlags CurrentCollisionFlags { get; set; } + // Count of collisions for this object + protected long CollisionAccumulation { get; set; } + public override bool IsColliding { get { return (CollidingStep == PhysicsScene.SimulationStep); } set { @@ -300,6 +305,8 @@ public abstract class BSPhysObject : PhysicsActor return ret; } + CollisionAccumulation++; + // if someone has subscribed for collision events.... if (SubscribedEvents()) { CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); @@ -386,6 +393,16 @@ public abstract class BSPhysObject : PhysicsActor public override bool SubscribedEvents() { return (SubscribedEventsMs > 0); } + // Because 'CollisionScore' is calls many times while sorting it should not be recomputed + // each time called. So this is built to be light weight for each collision and to do + // all the processing when the user asks for the info. + public void ComputeCollisionScore() + { + // Scale the collision count by the time since the last collision + long timeAgo = PhysicsScene.SimulationStep - CollidingStep + 1; + CollisionScore = CollisionAccumulation / timeAgo; + } + public override float CollisionScore { get; set; } #endregion // Collisions diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 99903f5189..17fddd79c1 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -59,7 +59,6 @@ public sealed class BSPrim : BSPhysObject private OMV.Vector3 _force; private OMV.Vector3 _velocity; private OMV.Vector3 _torque; - private float _collisionScore; private OMV.Vector3 _acceleration; private OMV.Quaternion _orientation; private int _physicsActorType; @@ -644,11 +643,6 @@ public sealed class BSPrim : BSPhysObject // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); } } - public override float CollisionScore { - get { return _collisionScore; } - set { _collisionScore = value; - } - } public override OMV.Vector3 Acceleration { get { return _acceleration; } set { _acceleration = value; } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs index cb304b6737..4442650040 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSScene.cs @@ -26,6 +26,7 @@ */ using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; @@ -697,7 +698,21 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters public override Dictionary GetTopColliders() { - return new Dictionary(); + Dictionary topColliders; + + lock (PhysObjects) + { + foreach (KeyValuePair kvp in PhysObjects) + { + kvp.Value.ComputeCollisionScore(); + } + + List orderedPrims = new List(PhysObjects.Values); + orderedPrims.OrderByDescending(p => p.CollisionScore).Take(25); + topColliders = orderedPrims.ToDictionary(p => p.LocalID, p => p.CollisionScore); + } + + return topColliders; } public override bool IsThreaded { get { return false; } } diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt index 791779591b..a95e169742 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimTODO.txt @@ -1,5 +1,9 @@ CURRENT PRIORITIES ================================================= +One sided meshes? Should terrain be built into a closed shape? + When meshes get partially wedged into the terrain, they cannot push themselves out. + It is possible that Bullet processes collisions whether entering or leaving a mesh. + Ref: http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4869 Deleting a linkset while standing on the root will leave the physical shape of the root behind. Not sure if it is because standing on it. Done with large prim linksets. Vehicle angular vertical attraction