From 4589bc84a32366c6aae68b67f1fc7a2ee08be86d Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 26 Sep 2012 09:25:56 -0700 Subject: BulletSim: Terrain sets proper collision flags on creation. Static objects are set to ISLAND_SLEEPING rather than DISABLE_SIMULATION. Might reconsider this and, alternatively, have dynamic objects force activation. Clean up use of DetailLog(). --- .../Region/Physics/BulletSPlugin/BSPhysObject.cs | 10 ++-- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 62 +++++++++++----------- .../Physics/BulletSPlugin/BSShapeCollection.cs | 16 ++++-- .../Physics/BulletSPlugin/BSTerrainManager.cs | 20 +++---- 4 files changed, 56 insertions(+), 52 deletions(-) (limited to 'OpenSim/Region/Physics') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index 3458477..4f83adc 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs @@ -121,8 +121,8 @@ public abstract class BSPhysObject : PhysicsActor // if someone has subscribed for collision events.... if (SubscribedEvents()) { CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); - DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", - LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth); + // DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5}", + // LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth); ret = true; } @@ -151,7 +151,7 @@ public abstract class BSPhysObject : PhysicsActor PhysicsScene.ObjectsWithNoMoreCollisions.Add(this); } - DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count); + // DetailLog("{0},{1}.SendCollisionUpdate,call,numCollisions={2}", LocalID, TypeName, CollisionCollection.Count); base.SendCollisionUpdate(CollisionCollection); // The collisionCollection structure is passed around in the simulator. @@ -163,7 +163,7 @@ public abstract class BSPhysObject : PhysicsActor // Subscribe for collision events. // Parameter is the millisecond rate the caller wishes collision events to occur. public override void SubscribeEvents(int ms) { - DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms); + // DetailLog("{0},{1}.SubscribeEvents,subscribing,ms={2}", LocalID, TypeName, ms); SubscribedEventsMs = ms; if (ms > 0) { @@ -182,7 +182,7 @@ public abstract class BSPhysObject : PhysicsActor } } public override void UnSubscribeEvents() { - DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); + // DetailLog("{0},{1}.UnSubscribeEvents,unsubscribing", LocalID, TypeName); SubscribedEventsMs = 0; PhysicsScene.TaintedObject(TypeName+".UnSubscribeEvents", delegate() { diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 1c6d476..68a153e 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -174,7 +174,7 @@ public sealed class BSPrim : BSPhysObject // Since _size changed, the mesh needs to be rebuilt. If rebuilt, all the correct // scale and margins are set. CreateGeomAndObject(true); - DetailLog("{0},BSPrim.setSize,size={1},scale={2},mass={3},physical={4}", LocalID, _size, _scale, _mass, IsPhysical); + // DetailLog("{0},BSPrim.setSize,size={1},scale={2},mass={3},physical={4}", LocalID, _size, _scale, _mass, IsPhysical); }); } } @@ -204,6 +204,7 @@ public sealed class BSPrim : BSPhysObject _isSelected = value; PhysicsScene.TaintedObject("BSPrim.setSelected", delegate() { + // DetailLog("{0},BSPrim.selected,taint,selected={1}", LocalID, _isSelected); SetObjectDynamic(false); }); } @@ -279,7 +280,7 @@ public sealed class BSPrim : BSPhysObject // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? PhysicsScene.TaintedObject("BSPrim.setPosition", delegate() { - DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); + // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); }); } @@ -317,7 +318,7 @@ public sealed class BSPrim : BSPhysObject _force = value; PhysicsScene.TaintedObject("BSPrim.setForce", delegate() { - DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); + // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); }); } @@ -385,7 +386,7 @@ public sealed class BSPrim : BSPhysObject _isVolumeDetect = newValue; PhysicsScene.TaintedObject("BSPrim.SetVolumeDetect", delegate() { - DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); + // DetailLog("{0},setVolumeDetect,taint,volDetect={1}", LocalID, _isVolumeDetect); SetObjectDynamic(true); }); } @@ -398,7 +399,7 @@ public sealed class BSPrim : BSPhysObject _velocity = value; PhysicsScene.TaintedObject("BSPrim.setVelocity", delegate() { - DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); + // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity); }); } @@ -406,7 +407,7 @@ public sealed class BSPrim : BSPhysObject public override OMV.Vector3 Torque { get { return _torque; } set { _torque = value; - DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); + // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); } } public override float CollisionScore { @@ -433,7 +434,7 @@ public sealed class BSPrim : BSPhysObject PhysicsScene.TaintedObject("BSPrim.setOrientation", delegate() { // _position = BulletSimAPI.GetObjectPosition2(PhysicsScene.World.ptr, BSBody.ptr); - DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); + // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); }); } @@ -450,7 +451,7 @@ public sealed class BSPrim : BSPhysObject _isPhysical = value; PhysicsScene.TaintedObject("BSPrim.setIsPhysical", delegate() { - DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); + // DetailLog("{0},setIsPhysical,taint,isPhys={1}", LocalID, _isPhysical); SetObjectDynamic(true); }); } @@ -470,12 +471,7 @@ public sealed class BSPrim : BSPhysObject } // Make gravity work if the object is physical and not selected - // No locking here because only called when it is safe (called at taint-time). - // There are four flags we're interested in: - // IsStatic: Object does not move, otherwise the object has mass and moves - // isSolid: other objects bounce off of this object - // isVolumeDetect: other objects pass through but can generate collisions - // collisionEvents: whether this object returns collision events + // Called at taint-time!! private void SetObjectDynamic(bool forceRebuild) { #if CSHARP_BODY_MANAGEMENT @@ -488,11 +484,17 @@ public sealed class BSPrim : BSPhysObject #endif // CSHARP_BODY_MANAGEMENT } + // Convert the simulator's physical properties into settings on BulletSim objects. + // There are four flags we're interested in: + // IsStatic: Object does not move, otherwise the object has mass and moves + // isSolid: other objects bounce off of this object + // isVolumeDetect: other objects pass through but can generate collisions + // collisionEvents: whether this object returns collision events private void UpdatePhysicalParameters() { - DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); + // DetailLog("{0},BSPrim.UpdatePhysicalParameters,entry,body={1},shape={2}", LocalID, BSBody, BSShape); - // Mangling all the physical properties requires the object to be out of the physical world. + // Mangling all the physical properties requires the object not be in the physical world. // This is a NOOP if the object is not in the world (BulletSim and Bullet ignore objects not found). BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); @@ -505,7 +507,7 @@ public sealed class BSPrim : BSPhysObject // Set up the object physicalness (does gravity and collisions move this object) MakeDynamic(IsStatic); - // Arrange for collisions events if the simulator wants them + // Arrange for collision events if the simulator wants them EnableCollisions(SubscribedEvents()); #if CSHARP_BODY_MANAGEMENT @@ -522,8 +524,6 @@ public sealed class BSPrim : BSPhysObject if (BSBody.collisionFilter != 0 || BSBody.collisionMask != 0) { BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, (uint)BSBody.collisionFilter, (uint)BSBody.collisionMask); - DetailLog("{0},BSPrim.UpdatePhysicalParameters,setCollisionFilterMask,filter={1},mask={2}", - LocalID, BSBody.collisionFilter.ToString("X"), BSBody.collisionMask.ToString("X")); } // Recompute any linkset parameters. @@ -557,8 +557,8 @@ public sealed class BSPrim : BSPhysObject // There can be special things needed for implementing linksets Linkset.MakeStatic(this); // The activation state is 'sleeping' so Bullet will not try to act on it - // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); - BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION); + BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ISLAND_SLEEPING); + // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_SIMULATION); BSBody.collisionFilter = CollisionFilterGroups.StaticObjectFilter; BSBody.collisionMask = CollisionFilterGroups.StaticObjectMask; @@ -571,16 +571,14 @@ public sealed class BSPrim : BSPhysObject // Set various physical properties so internal dynamic properties will get computed correctly as they are set BulletSimAPI.SetFriction2(BSBody.ptr, PhysicsScene.Params.defaultFriction); BulletSimAPI.SetRestitution2(BSBody.ptr, PhysicsScene.Params.defaultRestitution); + // per http://www.bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=3382 - BulletSimAPI.SetInterpolationLinearVelocity2(BSBody.ptr, OMV.Vector3.Zero); - BulletSimAPI.SetInterpolationAngularVelocity2(BSBody.ptr, OMV.Vector3.Zero); - BulletSimAPI.SetInterpolationVelocity2(BSBody.ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); + BulletSimAPI.ClearAllForces2(BSBody.ptr); // A dynamic object has mass IntPtr collisionShapePtr = BulletSimAPI.GetCollisionShape2(BSBody.ptr); OMV.Vector3 inertia = BulletSimAPI.CalculateLocalInertia2(collisionShapePtr, Linkset.LinksetMass); BulletSimAPI.SetMassProps2(BSBody.ptr, _mass, inertia); - // Inertia is based on our new mass BulletSimAPI.UpdateInertiaTensor2(BSBody.ptr); // Various values for simulation limits @@ -645,7 +643,7 @@ public sealed class BSPrim : BSPhysObject // Create the new body with the shape BSBody = new BulletBody(LocalID, BulletSimAPI.CreateBodyFromShape2(PhysicsScene.World.Ptr, BSShape.Ptr, _position, _orientation)); - BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); + CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.CF_NO_CONTACT_RESPONSE); DetailLog("{0},BSPrim.MakeSolid:rigidBody,body={1},shape={2}", LocalID, BSBody, BSShape); } } @@ -741,7 +739,7 @@ public sealed class BSPrim : BSPhysObject // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); PhysicsScene.TaintedObject("BSPrim.setRotationalVelocity", delegate() { - DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); + // DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); BulletSimAPI.SetAngularVelocity2(BSBody.ptr, _rotationalVelocity); }); } @@ -758,7 +756,7 @@ public sealed class BSPrim : BSPhysObject _buoyancy = value; PhysicsScene.TaintedObject("BSPrim.setBuoyancy", delegate() { - DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); + // DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); // Buoyancy is faked by changing the gravity applied to the object float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); @@ -823,18 +821,18 @@ public sealed class BSPrim : BSPhysObject } m_accumulatedForces.Clear(); } - DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); + // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, fSum); // For unknown reasons, "ApplyCentralForce" adds this force to the total force on the object. BulletSimAPI.ApplyCentralForce2(BSBody.ptr, fSum); }); } public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { - DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); + // DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); } public override void SetMomentum(OMV.Vector3 momentum) { - DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); + // DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); } #region Mass Calculation @@ -1452,7 +1450,7 @@ public sealed class BSPrim : BSPhysObject } // Rebuild the geometry and object. // This is called when the shape changes so we need to recreate the mesh/hull. - // No locking here because this is done when the physics engine is not simulating (taint-time). + // Called at taint-time!!! private void CreateGeomAndObject(bool forceRebuild) { #if CSHARP_BODY_MANAGEMENT diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 7fce8c9..aadb8d6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs @@ -344,7 +344,10 @@ public class BSShapeCollection : IDisposable if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) { haveShape = true; - if (forceRebuild || (prim.BSShape.type != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) + if (forceRebuild + || prim.Scale != shapeData.Size + || prim.BSShape.type != ShapeData.PhysicsShapeType.SHAPE_SPHERE + ) { ret = GetReferenceToNativeShape(prim, shapeData, ShapeData.PhysicsShapeType.SHAPE_SPHERE, ShapeData.FixedShapeKey.KEY_SPHERE); @@ -355,7 +358,10 @@ public class BSShapeCollection : IDisposable else { haveShape = true; - if (forceRebuild || (prim.BSShape.type != ShapeData.PhysicsShapeType.SHAPE_BOX)) + if (forceRebuild + || prim.Scale != shapeData.Size + || prim.BSShape.type != ShapeData.PhysicsShapeType.SHAPE_BOX + ) { ret = GetReferenceToNativeShape( prim, shapeData, ShapeData.PhysicsShapeType.SHAPE_BOX, ShapeData.FixedShapeKey.KEY_BOX); @@ -406,7 +412,7 @@ public class BSShapeCollection : IDisposable newShape.isNativeShape = true; // Don't need to do a 'ReferenceShape()' here because native shapes are not tracked. - DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1}", shapeData.ID, newShape); + // DetailLog("{0},BSShapeCollection.AddNativeShapeToPrim,create,newshape={1}", shapeData.ID, newShape); prim.BSShape = newShape; return true; @@ -683,13 +689,13 @@ public class BSShapeCollection : IDisposable { bodyPtr = BulletSimAPI.CreateBodyFromShape2(sim.ptr, shape.ptr, shapeData.ID, shapeData.Position, shapeData.Rotation); - DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); + // DetailLog("{0},BSShapeCollection.CreateBody,mesh,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); } else { bodyPtr = BulletSimAPI.CreateGhostFromShape2(sim.ptr, shape.ptr, shapeData.ID, shapeData.Position, shapeData.Rotation); - DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); + // DetailLog("{0},BSShapeCollection.CreateBody,ghost,ptr={1}", prim.LocalID, bodyPtr.ToString("X")); } aBody = new BulletBody(shapeData.ID, bodyPtr); diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index 5d5d9cb..50638d6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs @@ -201,10 +201,10 @@ public class BSTerrainManager // The 'doNow' boolean says whether to do all the unmanaged activities right now (like when // calling this routine from initialization or taint-time routines) or whether to delay // all the unmanaged activities to taint-time. - private void UpdateOrCreateTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords, bool doNow) + private void UpdateOrCreateTerrain(uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords, bool atTaintTime) { - DetailLog("{0},BSTerrainManager.UpdateOrCreateTerrain,call,minC={1},maxC={2},doNow={3}", - BSScene.DetailLogZero, minCoords, maxCoords, doNow); + DetailLog("{0},BSTerrainManager.UpdateOrCreateTerrain,call,minC={1},maxC={2},atTaintTime={3}", + BSScene.DetailLogZero, minCoords, maxCoords, atTaintTime); float minZ = float.MaxValue; float maxZ = float.MinValue; @@ -308,11 +308,7 @@ public class BSTerrainManager mapInfo.terrainBody = new BulletBody(mapInfo.ID, BulletSimAPI.CreateBodyWithDefaultMotionState2(mapInfo.terrainShape.ptr, - id, centerPos, Quaternion.Identity)); - - BulletSimAPI.SetCollisionFilterMask2(mapInfo.terrainBody.ptr, - (uint)CollisionFilterGroups.TerrainFilter, - (uint)CollisionFilterGroups.TerrainMask); + id, centerPos, Quaternion.Identity)); } // Make sure the entry is in the heightmap table @@ -333,6 +329,10 @@ public class BSTerrainManager // redo its bounding box now that it is in the world BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, mapInfo.terrainBody.ptr); + BulletSimAPI.SetCollisionFilterMask2(mapInfo.terrainBody.ptr, + (uint)CollisionFilterGroups.TerrainFilter, + (uint)CollisionFilterGroups.TerrainMask); + // Make sure the new shape is processed. BulletSimAPI.Activate2(mapInfo.terrainBody.ptr, true); @@ -341,7 +341,7 @@ public class BSTerrainManager // There is the option to do the changes now (we're already in 'taint time'), or // to do the Bullet operations later. - if (doNow) + if (atTaintTime) rebuildOperation(); else PhysicsScene.TaintedObject("BSScene.UpdateOrCreateTerrain:UpdateExisting", rebuildOperation); @@ -380,7 +380,7 @@ public class BSTerrainManager }; // If already in taint-time, just call Bullet. Otherwise queue the operations for the safe time. - if (doNow) + if (atTaintTime) createOperation(); else PhysicsScene.TaintedObject("BSScene.UpdateOrCreateTerrain:NewTerrain", createOperation); -- cgit v1.1