diff --git a/addon-modules/BulletSPlugin/BSCharacter.cs b/addon-modules/BulletSPlugin/BSCharacter.cs index fa9fc8d4b9..3a278b3c97 100644 --- a/addon-modules/BulletSPlugin/BSCharacter.cs +++ b/addon-modules/BulletSPlugin/BSCharacter.cs @@ -93,6 +93,7 @@ public class BSCharacter : PhysicsActor _size = size; _orientation = Quaternion.Identity; _velocity = Vector3.Zero; + _buoyancy = 0f; // characters return a buoyancy of zero _scale = new Vector3(1f, 1f, 1f); float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH); _mass = _density*AVvolume; @@ -105,8 +106,8 @@ public class BSCharacter : PhysicsActor shapeData.Velocity = _velocity; shapeData.Scale = _scale; shapeData.Mass = _mass; - shapeData.Flying = isFlying ? ShapeData.numericTrue : ShapeData.numericFalse; - shapeData.Dynamic = ShapeData.numericFalse; + shapeData.Buoyancy = isFlying ? 0f : 1f; + shapeData.Static = ShapeData.numericFalse; BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); @@ -268,7 +269,8 @@ public class BSCharacter : PhysicsActor _flying = value; _scene.TaintedObject(delegate() { - BulletSimAPI.SetObjectFlying(_scene.WorldID, LocalID, _flying); + // simulate flying by changing the effect of gravity + BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _flying ? 0f : 1f); }); } } @@ -415,7 +417,7 @@ public class BSCharacter : PhysicsActor { // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith); - // The following says we're colliding this simulation step + // The following makes IsColliding() and IsCollidingGround() work _collidingStep = _scene.SimulationStep; if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID) { diff --git a/addon-modules/BulletSPlugin/BSPrim.cs b/addon-modules/BulletSPlugin/BSPrim.cs index 06a8a03574..515c4dad61 100644 --- a/addon-modules/BulletSPlugin/BSPrim.cs +++ b/addon-modules/BulletSPlugin/BSPrim.cs @@ -106,6 +106,7 @@ public sealed class BSPrim : PhysicsActor _size = size; _scale = new OMV.Vector3(1f, 1f, 1f); // the scale will be set by CreateGeom depending on object type _orientation = rotation; + _buoyancy = 1f; _mesh = mesh; _hullKey = 0; _pbs = pbs; @@ -181,7 +182,6 @@ public sealed class BSPrim : PhysicsActor _isSelected = value; _scene.TaintedObject(delegate() { - m_log.DebugFormat("{0}: Selected={1}, localID={2}", LogHeader, _isSelected, _localID); SetObjectDynamic(); // SyncUpdated = true; }); @@ -287,6 +287,7 @@ public sealed class BSPrim : PhysicsActor public override OMV.Vector3 Position { get { + // don't do the following GetObjectPosition because this function is called a zillion times // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); return _position; } @@ -332,10 +333,7 @@ public sealed class BSPrim : PhysicsActor _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); + SetObjectDynamic(); }); } return; @@ -390,40 +388,39 @@ public sealed class BSPrim : PhysicsActor _scene.TaintedObject(delegate() { SetObjectDynamic(); - m_log.DebugFormat("{0}: ID={1}, IsPhysical={2}, IsSelected={3}, mass={4}", LogHeader, _localID, _isPhysical, _isSelected, _mass); // SyncUpdated = true; }); } } + + // An object is static (does not move) if selected or not physical + private bool IsStatic + { + get { return _isSelected || !IsPhysical; } + } + + // An object is solid if it's not phantom and if it's not doing VolumeDetect + private bool IsSolid + { + get { return !IsPhantom && !_isVolumeDetect; } + } + // make gravity work if the object is physical and not selected // no locking here because only called when it is safe private void SetObjectDynamic() { - // a selected object is not physical - if (_isSelected || !_isPhysical) - { - _mass = 0f; // non-physical things work best with a mass of zero - BulletSimAPI.SetObjectDynamic(_scene.WorldID, _localID, false, _mass); - } - else - { - _mass = CalculateMass(); - BulletSimAPI.SetObjectDynamic(_scene.WorldID, _localID, true, _mass); - } + // non-physical things work best with a mass of zero + _mass = IsStatic ? 0f : CalculateMass(); + BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), _mass); + // m_log.DebugFormat("{0}: ID={1}, SetObjectDynamic: IsStatic={2}, IsSolid={3}, mass={4}", LogHeader, _localID, IsStatic, IsSolid, _mass); } + + // prims don't fly public override bool Flying { get { return _flying; } - set { - _flying = value; - _scene.TaintedObject(delegate() - { - BulletSimAPI.SetObjectFlying(_scene.WorldID, LocalID, _flying); - // SyncUpdated = true; - }); - } + set { _flying = value; } } - public override bool - SetAlwaysRun { + public override bool SetAlwaysRun { get { return _setAlwaysRun; } set { _setAlwaysRun = value; } } @@ -431,12 +428,12 @@ public sealed class BSPrim : PhysicsActor get { return _throttleUpdates; } set { _throttleUpdates = value; } } - public override bool IsColliding { - get { return _isColliding; } + public override bool IsColliding { + get { return (_collidingStep == _scene.SimulationStep); } set { _isColliding = value; } } - public override bool CollidingGround { - get { return _collidingGround; } + public override bool CollidingGround { + get { return (_collidingGroundStep == _scene.SimulationStep); } set { _collidingGround = value; } } public override bool CollidingObj { @@ -468,7 +465,12 @@ public sealed class BSPrim : PhysicsActor } public override float Buoyancy { get { return _buoyancy; } - set { _buoyancy = value; } + set { _buoyancy = value; + _scene.TaintedObject(delegate() + { + BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); + }); + } } // Used for MoveTo @@ -1003,11 +1005,11 @@ public sealed class BSPrim : PhysicsActor shape.Velocity = _velocity; shape.Scale = _scale; shape.Mass = _isPhysical ? _mass : 0f; + shape.Buoyancy = _buoyancy; shape.MeshKey = _hullKey; shape.Collidable = (!IsPhantom) ? ShapeData.numericTrue : ShapeData.numericFalse; - shape.Flying = _flying ? ShapeData.numericTrue : ShapeData.numericFalse; shape.Friction = _friction; - shape.Dynamic = _isPhysical ? ShapeData.numericTrue : ShapeData.numericFalse; + shape.Static = _isPhysical ? ShapeData.numericFalse : ShapeData.numericTrue; } // Rebuild the geometry and object. @@ -1044,7 +1046,7 @@ public sealed class BSPrim : PhysicsActor public void UpdateProperties(EntityProperties entprop) { bool changed = false; - // we assign to the local variables so the normal set action does not happen + // assign to the local variables so the normal set action does not happen if (_position != entprop.Position) { _position = entprop.Position; diff --git a/addon-modules/BulletSPlugin/BSScene.cs b/addon-modules/BulletSPlugin/BSScene.cs index a302b21139..d656b8aa24 100644 --- a/addon-modules/BulletSPlugin/BSScene.cs +++ b/addon-modules/BulletSPlugin/BSScene.cs @@ -35,23 +35,24 @@ using OpenSim.Region.Physics.Manager; using OpenMetaverse; using OpenSim.Region.Framework; -// TODOs for BulletSim (both BSScene and BSPrim) +// TODOs for BulletSim (for BSScene, BSPrim, BSCharacter and BulletSim) // Does NeedsMeshing() really need to exclude all the different shapes? // Based on material, set density and friction // 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? // In SL one can set both physical and phantom (gravity, does not effect others, makes collisions with ground) +// At the moment, physical and phantom causes object to drop through the terrain // LinkSets // Freeing of memory of linksets in BulletSim::DestroyObject // 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 -// Set bouyancy(). Maybe generalize SetFlying() to SetBouyancy() and use the factor to change the gravity effect // 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, ... +// Use event subscription times to reduce the number of events passed up (_subscribedEventMS) +// Implement the genCollisions feature in BulletSim::SetObjectProperties (don't pass up unneeded collisions) // namespace OpenSim.Region.Physics.BulletSPlugin { diff --git a/addon-modules/BulletSPlugin/BulletSimAPI.cs b/addon-modules/BulletSPlugin/BulletSimAPI.cs index b1f7bd314f..8d97f30bb1 100644 --- a/addon-modules/BulletSPlugin/BulletSimAPI.cs +++ b/addon-modules/BulletSPlugin/BulletSimAPI.cs @@ -59,11 +59,11 @@ public struct ShapeData public Vector3 Velocity; public Vector3 Scale; public float Mass; + public float Buoyancy; public System.UInt64 MeshKey; public int Collidable; - public int Flying; public float Friction; - public int Dynamic; + public int Static; // true if a static object. Otherwise gravity, etc. // note that bools are passed as ints since bool size changes by language } public struct SweepHit @@ -148,7 +148,10 @@ public static extern bool SetObjectDynamic(uint worldID, uint id, bool isDynamic public static extern bool SetObjectGhost(uint worldID, uint id, bool ghostly); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] -public static extern bool SetObjectFlying(uint worldID, uint id, bool flying); +public static extern bool SetObjectProperties(uint worldID, uint id, bool isStatic, bool isSolid, bool genCollisions, float mass); + +[DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] +public static extern bool SetObjectBuoyancy(uint worldID, uint id, float buoyancy); [DllImport("BulletSim", CallingConvention = CallingConvention.Cdecl), SuppressUnmanagedCodeSecurity] public static extern bool HasObject(uint worldID, uint id); diff --git a/bin/BulletSim.dll b/bin/BulletSim.dll index 02f1056f6c..45d81584f7 100755 Binary files a/bin/BulletSim.dll and b/bin/BulletSim.dll differ