BulletSim: first attempt at reporting top colliders

user_profiles
Robert Adams 2013-01-25 16:00:17 -08:00
parent dd08e1fba6
commit ddef8f16e5
5 changed files with 43 additions and 11 deletions

View File

@ -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
{

View File

@ -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

View File

@ -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; }

View File

@ -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<uint, float> GetTopColliders()
{
return new Dictionary<uint, float>();
Dictionary<uint, float> topColliders;
lock (PhysObjects)
{
foreach (KeyValuePair<uint, BSPhysObject> kvp in PhysObjects)
{
kvp.Value.ComputeCollisionScore();
}
List<BSPhysObject> orderedPrims = new List<BSPhysObject>(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; } }

View File

@ -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