new BulletSPlugin and version of BulletSim.dll
parent
080db3019e
commit
53fa87ad76
|
@ -30,6 +30,7 @@ using log4net;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
using OpenSim.Region.Physics.Manager;
|
using OpenSim.Region.Physics.Manager;
|
||||||
|
using OpenSim.Region.CoreModules.RegionSync.RegionSyncModule;
|
||||||
|
|
||||||
namespace OpenSim.Region.Physics.BulletSPlugin
|
namespace OpenSim.Region.Physics.BulletSPlugin
|
||||||
{
|
{
|
||||||
|
@ -123,7 +124,19 @@ public class BSCharacter : PhysicsActor
|
||||||
|
|
||||||
public override void RequestPhysicsterseUpdate()
|
public override void RequestPhysicsterseUpdate()
|
||||||
{
|
{
|
||||||
base.RequestPhysicsterseUpdate();
|
if (PhysEngineToSceneConnectorModule.IsPhysEngineActorS)
|
||||||
|
{
|
||||||
|
// if the values have changed and it was I who changed them, send an update
|
||||||
|
if (this.lastValues.Changed(this) && ChangingActorID == RegionSyncServerModule.ActorID)
|
||||||
|
{
|
||||||
|
// m_log.DebugFormat("{0}: Sending terse update for {1}", LogHeader, LocalID);
|
||||||
|
PhysEngineToSceneConnectorModule.RouteUpdate(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base.RequestPhysicsterseUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Stopped {
|
public override bool Stopped {
|
||||||
|
@ -132,6 +145,7 @@ public class BSCharacter : PhysicsActor
|
||||||
public override Vector3 Size {
|
public override Vector3 Size {
|
||||||
get { return _size; }
|
get { return _size; }
|
||||||
set { _size = value;
|
set { _size = value;
|
||||||
|
base.ChangingActorID = RegionSyncServerModule.ActorID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override PrimitiveBaseShape Shape {
|
public override PrimitiveBaseShape Shape {
|
||||||
|
@ -158,11 +172,12 @@ public class BSCharacter : PhysicsActor
|
||||||
|
|
||||||
public override Vector3 Position {
|
public override Vector3 Position {
|
||||||
get {
|
get {
|
||||||
_position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
|
// _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
|
||||||
return _position;
|
return _position;
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
_position = value;
|
_position = value;
|
||||||
|
base.ChangingActorID = RegionSyncServerModule.ActorID;
|
||||||
_scene.TaintedObject(delegate()
|
_scene.TaintedObject(delegate()
|
||||||
{
|
{
|
||||||
BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
|
BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
|
||||||
|
@ -178,7 +193,7 @@ public class BSCharacter : PhysicsActor
|
||||||
get { return _force; }
|
get { return _force; }
|
||||||
set {
|
set {
|
||||||
_force = value;
|
_force = value;
|
||||||
m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force);
|
// m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force);
|
||||||
_scene.TaintedObject(delegate()
|
_scene.TaintedObject(delegate()
|
||||||
{
|
{
|
||||||
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
|
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
|
||||||
|
@ -204,6 +219,7 @@ public class BSCharacter : PhysicsActor
|
||||||
get { return _velocity; }
|
get { return _velocity; }
|
||||||
set {
|
set {
|
||||||
_velocity = value;
|
_velocity = value;
|
||||||
|
base.ChangingActorID = RegionSyncServerModule.ActorID;
|
||||||
_scene.TaintedObject(delegate()
|
_scene.TaintedObject(delegate()
|
||||||
{
|
{
|
||||||
BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity);
|
BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity);
|
||||||
|
@ -229,7 +245,7 @@ public class BSCharacter : PhysicsActor
|
||||||
_orientation = value;
|
_orientation = value;
|
||||||
_scene.TaintedObject(delegate()
|
_scene.TaintedObject(delegate()
|
||||||
{
|
{
|
||||||
_position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
|
// _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
|
||||||
BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
|
BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -329,15 +345,16 @@ public class BSCharacter : PhysicsActor
|
||||||
_force.X += force.X;
|
_force.X += force.X;
|
||||||
_force.Y += force.Y;
|
_force.Y += force.Y;
|
||||||
_force.Z += force.Z;
|
_force.Z += force.Z;
|
||||||
|
base.ChangingActorID = RegionSyncServerModule.ActorID;
|
||||||
|
_scene.TaintedObject(delegate()
|
||||||
|
{
|
||||||
|
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader);
|
m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader);
|
||||||
}
|
}
|
||||||
_scene.TaintedObject(delegate()
|
|
||||||
{
|
|
||||||
BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
|
|
||||||
});
|
|
||||||
//m_lastUpdateSent = false;
|
//m_lastUpdateSent = false;
|
||||||
}
|
}
|
||||||
public override void AddAngularForce(Vector3 force, bool pushforce) {
|
public override void AddAngularForce(Vector3 force, bool pushforce) {
|
||||||
|
@ -387,14 +404,13 @@ public class BSCharacter : PhysicsActor
|
||||||
}
|
}
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
base.RequestPhysicsterseUpdate();
|
this.RequestPhysicsterseUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Collide(uint collidingWith, ActorTypes type, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth)
|
public void Collide(uint collidingWith, ActorTypes type, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
|
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
|
||||||
if (_subscribedEventsMs == 0) return; // don't want collisions
|
|
||||||
|
|
||||||
// The following says we're colliding this simulation step
|
// The following says we're colliding this simulation step
|
||||||
_collidingStep = _scene.SimulationStep;
|
_collidingStep = _scene.SimulationStep;
|
||||||
|
@ -403,6 +419,8 @@ public class BSCharacter : PhysicsActor
|
||||||
_collidingGroundStep = _scene.SimulationStep;
|
_collidingGroundStep = _scene.SimulationStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_subscribedEventsMs == 0) return; // don't want collisions
|
||||||
|
|
||||||
Dictionary<uint, ContactPoint> contactPoints = new Dictionary<uint, ContactPoint>();
|
Dictionary<uint, ContactPoint> contactPoints = new Dictionary<uint, ContactPoint>();
|
||||||
contactPoints.Add(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
|
contactPoints.Add(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
|
||||||
CollisionEventUpdate args = new CollisionEventUpdate(LocalID, (int)type, 1, contactPoints);
|
CollisionEventUpdate args = new CollisionEventUpdate(LocalID, (int)type, 1, contactPoints);
|
||||||
|
|
|
@ -56,6 +56,7 @@ public sealed class BSPrim : PhysicsActor
|
||||||
private bool _stopped;
|
private bool _stopped;
|
||||||
private bool _grabbed;
|
private bool _grabbed;
|
||||||
private bool _isSelected;
|
private bool _isSelected;
|
||||||
|
private bool _isVolumeDetect;
|
||||||
private OMV.Vector3 _position;
|
private OMV.Vector3 _position;
|
||||||
private float _mass;
|
private float _mass;
|
||||||
private float _density;
|
private float _density;
|
||||||
|
@ -109,6 +110,7 @@ public sealed class BSPrim : PhysicsActor
|
||||||
_hullKey = 0;
|
_hullKey = 0;
|
||||||
_pbs = pbs;
|
_pbs = pbs;
|
||||||
_isPhysical = pisPhysical;
|
_isPhysical = pisPhysical;
|
||||||
|
_isVolumeDetect = false;
|
||||||
_subscribedEventsMs = 0;
|
_subscribedEventsMs = 0;
|
||||||
_friction = _scene.DefaultFriction; // TODO: compute based on object material
|
_friction = _scene.DefaultFriction; // TODO: compute based on object material
|
||||||
_density = _scene.DefaultDensity; // TODO: compute based on object material
|
_density = _scene.DefaultDensity; // TODO: compute based on object material
|
||||||
|
@ -323,7 +325,21 @@ public sealed class BSPrim : PhysicsActor
|
||||||
public override void VehicleFlags(int param, bool remove) { }
|
public override void VehicleFlags(int param, bool remove) { }
|
||||||
|
|
||||||
// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
|
// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
|
||||||
public override void SetVolumeDetect(int param) { return; }
|
public override void SetVolumeDetect(int param) {
|
||||||
|
bool newValue = (param != 0);
|
||||||
|
if (_isVolumeDetect != newValue)
|
||||||
|
{
|
||||||
|
_isVolumeDetect = newValue;
|
||||||
|
_scene.TaintedObject(delegate()
|
||||||
|
{
|
||||||
|
// make the object ghostly or not (walk throughable)
|
||||||
|
BulletSimAPI.SetObjectGhost(_scene.WorldID, LocalID, _isVolumeDetect);
|
||||||
|
// set whether we hear about collisions
|
||||||
|
BulletSimAPI.SetObjectCollidable(_scene.WorldID, LocalID, !IsPhantom);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } }
|
public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } }
|
||||||
public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } }
|
public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } }
|
||||||
|
@ -1069,15 +1085,15 @@ public sealed class BSPrim : PhysicsActor
|
||||||
public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
|
public void Collide(uint collidingWith, ActorTypes type, OMV.Vector3 contactPoint, OMV.Vector3 contactNormal, float pentrationDepth)
|
||||||
{
|
{
|
||||||
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
|
// m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith);
|
||||||
if (_subscribedEventsMs == 0) return; // nothing in the object is waiting for collision events
|
// The following makes IsColliding() and IsCollidingGround() work
|
||||||
|
|
||||||
// The following makes it so we can sense we're colliding this simulation step
|
|
||||||
_collidingStep = _scene.SimulationStep;
|
_collidingStep = _scene.SimulationStep;
|
||||||
if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID)
|
if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID)
|
||||||
{
|
{
|
||||||
_collidingGroundStep = _scene.SimulationStep;
|
_collidingGroundStep = _scene.SimulationStep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_subscribedEventsMs == 0) return; // nothing in the object is waiting for collision events
|
||||||
|
|
||||||
// create the event for the collision
|
// create the event for the collision
|
||||||
Dictionary<uint, ContactPoint> contactPoints = new Dictionary<uint, ContactPoint>();
|
Dictionary<uint, ContactPoint> contactPoints = new Dictionary<uint, ContactPoint>();
|
||||||
contactPoints.Add(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
|
contactPoints.Add(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth));
|
||||||
|
|
|
@ -40,14 +40,18 @@ using OpenSim.Region.Framework;
|
||||||
// Based on material, set density and friction
|
// Based on material, set density and friction
|
||||||
// More efficient memory usage in passing hull information from BSPrim to BulletSim
|
// More efficient memory usage in passing hull information from BSPrim to BulletSim
|
||||||
// Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly?
|
// Four states of prim: Physical, regular, phantom and selected. Are we modeling these correctly?
|
||||||
// In SL one can set both physical and phantom (gravity, does not effect others, makes collisions)
|
// In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground)
|
||||||
// Need three states for objects: sense and report collisions, have physical effects, affects other objects
|
|
||||||
// LinkSets
|
// LinkSets
|
||||||
// Freeing of memory of linksets in BulletSim::DestroyObject
|
// Freeing of memory of linksets in BulletSim::DestroyObject
|
||||||
// Should prim.link() and prim.delink() be done at taint time?
|
// Set child prims phantom since the physicality is handled by the parent prim
|
||||||
|
// Linked children need rotation relative to parent (passed as world rotation)
|
||||||
|
// Should prim.link() and prim.delink() membership checking happen at taint time?
|
||||||
// Pass collision enable flags to BulletSim code so collisions are not reported up unless they are really needed
|
// Pass collision enable flags to BulletSim code so collisions are not reported up unless they are really needed
|
||||||
// Set child prims phantom since the physicality is handled by the parent prim
|
// Set bouyancy(). Maybe generalize SetFlying() to SetBouyancy() and use the factor to change the gravity effect
|
||||||
// Linked children need rotation relative to parent (passed as world rotation)
|
// Test sculpties
|
||||||
|
// Mesh sharing. Use meshHash to tell if we already have a hull of that shape and only create once
|
||||||
|
// Do attachments need to be handled separately? Need collision events. Do not collide with VolumeDetect
|
||||||
|
// Parameterize BulletSim. Pass a structure of parameters to the C++ code. Capsule size, friction, ...
|
||||||
//
|
//
|
||||||
namespace OpenSim.Region.Physics.BulletSPlugin
|
namespace OpenSim.Region.Physics.BulletSPlugin
|
||||||
{
|
{
|
||||||
|
@ -82,6 +86,7 @@ public class BSScene : PhysicsScene
|
||||||
|
|
||||||
public delegate void TaintCallback();
|
public delegate void TaintCallback();
|
||||||
private List<TaintCallback> _taintedObjects;
|
private List<TaintCallback> _taintedObjects;
|
||||||
|
private Object _taintLock = new Object();
|
||||||
|
|
||||||
private BulletSimAPI.DebugLogCallback debugLogCallbackHandle;
|
private BulletSimAPI.DebugLogCallback debugLogCallbackHandle;
|
||||||
|
|
||||||
|
@ -243,19 +248,22 @@ public class BSScene : PhysicsScene
|
||||||
IntPtr updatePointer = updatedEntities[ii];
|
IntPtr updatePointer = updatedEntities[ii];
|
||||||
EntityProperties entprop = (EntityProperties)Marshal.PtrToStructure(updatePointer, typeof(EntityProperties));
|
EntityProperties entprop = (EntityProperties)Marshal.PtrToStructure(updatePointer, typeof(EntityProperties));
|
||||||
// m_log.DebugFormat("{0}: entprop: id={1}, pos={2}", LogHeader, entprop.ID, entprop.Position);
|
// m_log.DebugFormat("{0}: entprop: id={1}, pos={2}", LogHeader, entprop.ID, entprop.Position);
|
||||||
if (m_avatars.ContainsKey(entprop.ID))
|
BSCharacter actor;
|
||||||
|
if (m_avatars.TryGetValue(entprop.ID, out actor))
|
||||||
{
|
{
|
||||||
BSCharacter actor = m_avatars[entprop.ID];
|
|
||||||
actor.UpdateProperties(entprop);
|
actor.UpdateProperties(entprop);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (m_prims.ContainsKey(entprop.ID))
|
BSPrim prim;
|
||||||
|
if (m_prims.TryGetValue(entprop.ID, out prim))
|
||||||
{
|
{
|
||||||
BSPrim prim = m_prims[entprop.ID];
|
|
||||||
prim.UpdateProperties(entprop);
|
prim.UpdateProperties(entprop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (collidersCount > 0 || updatedEntityCount > 0) m_log.WarnFormat("{0}: collisions={1}, updates={2}", LogHeader, collidersCount/2, updatedEntityCount);
|
||||||
|
|
||||||
return 11f; // returns frames per second
|
return 11f; // returns frames per second
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,20 +277,18 @@ public class BSScene : PhysicsScene
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorTypes type = ActorTypes.Prim;
|
ActorTypes type = ActorTypes.Prim;
|
||||||
if (m_avatars.ContainsKey(collidingWith))
|
if (collidingWith == TERRAIN_ID || collidingWith == GROUNDPLANE_ID)
|
||||||
type = ActorTypes.Agent;
|
|
||||||
else if (collidingWith == TERRAIN_ID || collidingWith == GROUNDPLANE_ID)
|
|
||||||
type = ActorTypes.Ground;
|
type = ActorTypes.Ground;
|
||||||
|
else if (m_avatars.ContainsKey(collidingWith))
|
||||||
|
type = ActorTypes.Agent;
|
||||||
|
|
||||||
if (m_prims.ContainsKey(localID))
|
BSPrim prim;
|
||||||
{
|
if (m_prims.TryGetValue(localID, out prim)) {
|
||||||
BSPrim prim = m_prims[localID];
|
|
||||||
prim.Collide(collidingWith, type, Vector3.Zero, Vector3.UnitZ, 0.01f);
|
prim.Collide(collidingWith, type, Vector3.Zero, Vector3.UnitZ, 0.01f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_avatars.ContainsKey(localID))
|
BSCharacter actor;
|
||||||
{
|
if (m_avatars.TryGetValue(localID, out actor)) {
|
||||||
BSCharacter actor = m_avatars[localID];
|
|
||||||
actor.Collide(collidingWith, type, Vector3.Zero, Vector3.UnitZ, 0.01f);
|
actor.Collide(collidingWith, type, Vector3.Zero, Vector3.UnitZ, 0.01f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -440,8 +446,8 @@ public class BSScene : PhysicsScene
|
||||||
// We rely on C#'s closure to save and restore the context for the delegate.
|
// We rely on C#'s closure to save and restore the context for the delegate.
|
||||||
public void TaintedObject(TaintCallback callback)
|
public void TaintedObject(TaintCallback callback)
|
||||||
{
|
{
|
||||||
// do we need to lock?
|
lock (_taintLock)
|
||||||
_taintedObjects.Add(callback);
|
_taintedObjects.Add(callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,8 +457,12 @@ public class BSScene : PhysicsScene
|
||||||
public void ProcessTaints()
|
public void ProcessTaints()
|
||||||
{
|
{
|
||||||
// swizzle a new list into the list location so we can process what's there
|
// swizzle a new list into the list location so we can process what's there
|
||||||
List<TaintCallback> newList = new List<TaintCallback>();
|
List<TaintCallback> oldList;
|
||||||
List<TaintCallback> oldList = (List<TaintCallback>)Interlocked.Exchange(ref _taintedObjects, newList);
|
lock (_taintLock)
|
||||||
|
{
|
||||||
|
oldList = _taintedObjects;
|
||||||
|
_taintedObjects = new List<TaintCallback>();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (TaintCallback callback in oldList)
|
foreach (TaintCallback callback in oldList)
|
||||||
{
|
{
|
||||||
|
|
|
@ -144,6 +144,9 @@ public static extern bool SetObjectCollidable(uint worldID, uint id, bool phanto
|
||||||
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||||
public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass);
|
public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic, float mass);
|
||||||
|
|
||||||
|
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||||
|
public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly);
|
||||||
|
|
||||||
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity]
|
||||||
public static extern bool SetObjectFlying(uint worldID, uint id, bool flying);
|
public static extern bool SetObjectFlying(uint worldID, uint id, bool flying);
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue