From 7243d4f84248092eb5fe4ebe3673501bc84ce250 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Fri, 17 Aug 2012 14:45:18 -0700 Subject: [PATCH] BulletSim: Properly regenerate hulls when objects made physical. This fixes the problem of non-base shapes (cubes and spheres) falling through the terrain. --- .../Region/Framework/Scenes/ScenePresence.cs | 16 ++++----- .../Region/Physics/BulletSPlugin/BSPrim.cs | 34 ++++++++++++++----- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 98afb75be2..65d526fd4e 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -1392,14 +1392,14 @@ namespace OpenSim.Region.Framework.Scenes else if (FlyDisabled) newFlying = false; else - newFlying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); - - if (actor.Flying != newFlying) - { - // Note: ScenePresence.Flying is actually fetched from the physical actor - // so setting PhysActor.Flying here also sets the ScenePresence's value. - actor.Flying = newFlying; - update_movementflag = true; + newFlying = ((flags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); + + if (actor.Flying != newFlying) + { + // Note: ScenePresence.Flying is actually fetched from the physical actor + // so setting PhysActor.Flying here also sets the ScenePresence's value. + actor.Flying = newFlying; + update_movementflag = true; } if (ParentID == 0) diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index a6bc8e25d0..d3f1e9c17f 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -481,11 +481,8 @@ public sealed class BSPrim : PhysicsActor // No locking here because only called when it is safe private void SetObjectDynamic() { - // RA: remove this for the moment. - // The problem is that dynamic objects are hulls so if we are becoming physical - // the shape has to be checked and possibly built. - // Maybe a VerifyCorrectPhysicalShape() routine? - // RecreateGeomAndObject(); + // If it's becoming dynamic, it will need hullness + VerifyCorrectPhysicalShape(); // Bullet wants static objects to have a mass of zero float mass = IsStatic ? 0f : _mass; @@ -1214,6 +1211,27 @@ public sealed class BSPrim : PhysicsActor return; } + private void VerifyCorrectPhysicalShape() + { + if (IsStatic) + { + // if static, we don't need a hull so, if there is one, rebuild without it + if (_hullKey != 0) + { + RecreateGeomAndObject(); + } + } + else + { + // if not static, it will need a hull to efficiently collide with things + if (_hullKey == 0) + { + RecreateGeomAndObject(); + } + + } + } + // Create an object in Bullet if it has not already been created // No locking here because this is done when the physics engine is not simulating // Returns 'true' if an object was actually created. @@ -1338,10 +1356,8 @@ public sealed class BSPrim : PhysicsActor _acceleration = entprop.Acceleration; _rotationalVelocity = entprop.RotationalVelocity; - // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}", - // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); - // DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", - // LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); + DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", + LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); base.RequestPhysicsterseUpdate(); }