diff options
Diffstat (limited to '')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 84 |
1 files changed, 58 insertions, 26 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index f89b376..90da7a6 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -80,28 +80,27 @@ public abstract class BSPhysObject : PhysicsActor | |||
80 | Name = name; // PhysicsActor also has the name of the object. Someday consolidate. | 80 | Name = name; // PhysicsActor also has the name of the object. Someday consolidate. |
81 | TypeName = typeName; | 81 | TypeName = typeName; |
82 | 82 | ||
83 | // The collection of things that push me around | 83 | // Oddity if object is destroyed and recreated very quickly it could still have the old body. |
84 | PhysicalActors = new BSActorCollection(PhysScene); | 84 | if (!PhysBody.HasPhysicalBody) |
85 | PhysBody = new BulletBody(localID); | ||
85 | 86 | ||
86 | // Initialize variables kept in base. | 87 | // Clean out anything that might be in the physical actor list. |
87 | GravModifier = 1.0f; | 88 | // Again, a workaround for destroying and recreating an object very quickly. |
88 | Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); | 89 | PhysicalActors.Dispose(); |
89 | HoverActive = false; | ||
90 | |||
91 | // We don't have any physical representation yet. | ||
92 | PhysBody = new BulletBody(localID); | ||
93 | PhysShape = new BSShapeNull(); | ||
94 | 90 | ||
95 | UserSetCenterOfMassDisplacement = null; | 91 | UserSetCenterOfMassDisplacement = null; |
96 | 92 | ||
97 | PrimAssetState = PrimAssetCondition.Unknown; | 93 | PrimAssetState = PrimAssetCondition.Unknown; |
98 | 94 | ||
95 | // Initialize variables kept in base. | ||
96 | // Beware that these cause taints to be queued whch can cause race conditions on startup. | ||
97 | GravModifier = 1.0f; | ||
98 | Gravity = new OMV.Vector3(0f, 0f, BSParam.Gravity); | ||
99 | HoverActive = false; | ||
100 | |||
99 | // Default material type. Also sets Friction, Restitution and Density. | 101 | // Default material type. Also sets Friction, Restitution and Density. |
100 | SetMaterial((int)MaterialAttributes.Material.Wood); | 102 | SetMaterial((int)MaterialAttributes.Material.Wood); |
101 | 103 | ||
102 | CollisionCollection = new CollisionEventUpdate(); | ||
103 | CollisionsLastReported = CollisionCollection; | ||
104 | CollisionsLastTick = new CollisionEventUpdate(); | ||
105 | CollisionsLastTickStep = -1; | 104 | CollisionsLastTickStep = -1; |
106 | 105 | ||
107 | SubscribedEventsMs = 0; | 106 | SubscribedEventsMs = 0; |
@@ -136,6 +135,15 @@ public abstract class BSPhysObject : PhysicsActor | |||
136 | // This mostly prevents property updates and collisions until the object is completely here. | 135 | // This mostly prevents property updates and collisions until the object is completely here. |
137 | public bool IsInitialized { get; protected set; } | 136 | public bool IsInitialized { get; protected set; } |
138 | 137 | ||
138 | // Set to 'true' if an object (mesh/linkset/sculpty) is not completely constructed. | ||
139 | // This test is used to prevent some updates to the object when it only partially exists. | ||
140 | // There are several reasons and object might be incomplete: | ||
141 | // Its underlying mesh/sculpty is an asset which must be fetched from the asset store | ||
142 | // It is a linkset who is being added to or removed from | ||
143 | // It is changing state (static to physical, for instance) which requires rebuilding | ||
144 | // This is a computed value based on the underlying physical object construction | ||
145 | abstract public bool IsIncomplete { get; } | ||
146 | |||
139 | // Return the object mass without calculating it or having side effects | 147 | // Return the object mass without calculating it or having side effects |
140 | public abstract float RawMass { get; } | 148 | public abstract float RawMass { get; } |
141 | // Set the raw mass but also update physical mass properties (inertia, ...) | 149 | // Set the raw mass but also update physical mass properties (inertia, ...) |
@@ -148,9 +156,9 @@ public abstract class BSPhysObject : PhysicsActor | |||
148 | public OMV.Vector3 Inertia { get; set; } | 156 | public OMV.Vector3 Inertia { get; set; } |
149 | 157 | ||
150 | // Reference to the physical body (btCollisionObject) of this object | 158 | // Reference to the physical body (btCollisionObject) of this object |
151 | public BulletBody PhysBody; | 159 | public BulletBody PhysBody = new BulletBody(0); |
152 | // Reference to the physical shape (btCollisionShape) of this object | 160 | // Reference to the physical shape (btCollisionShape) of this object |
153 | public BSShape PhysShape; | 161 | public BSShape PhysShape = new BSShapeNull(); |
154 | 162 | ||
155 | // The physical representation of the prim might require an asset fetch. | 163 | // The physical representation of the prim might require an asset fetch. |
156 | // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'. | 164 | // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'. |
@@ -159,6 +167,11 @@ public abstract class BSPhysObject : PhysicsActor | |||
159 | Unknown, Waiting, FailedAssetFetch, FailedMeshing, Fetched | 167 | Unknown, Waiting, FailedAssetFetch, FailedMeshing, Fetched |
160 | } | 168 | } |
161 | public PrimAssetCondition PrimAssetState { get; set; } | 169 | public PrimAssetCondition PrimAssetState { get; set; } |
170 | public virtual bool AssetFailed() | ||
171 | { | ||
172 | return ( (this.PrimAssetState == PrimAssetCondition.FailedAssetFetch) | ||
173 | || (this.PrimAssetState == PrimAssetCondition.FailedMeshing) ); | ||
174 | } | ||
162 | 175 | ||
163 | // The objects base shape information. Null if not a prim type shape. | 176 | // The objects base shape information. Null if not a prim type shape. |
164 | public PrimitiveBaseShape BaseShape { get; protected set; } | 177 | public PrimitiveBaseShape BaseShape { get; protected set; } |
@@ -223,7 +236,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
223 | public virtual OMV.Quaternion RawOrientation { get; set; } | 236 | public virtual OMV.Quaternion RawOrientation { get; set; } |
224 | public abstract OMV.Quaternion ForceOrientation { get; set; } | 237 | public abstract OMV.Quaternion ForceOrientation { get; set; } |
225 | 238 | ||
226 | public OMV.Vector3 RawVelocity { get; set; } | 239 | public virtual OMV.Vector3 RawVelocity { get; set; } |
227 | public abstract OMV.Vector3 ForceVelocity { get; set; } | 240 | public abstract OMV.Vector3 ForceVelocity { get; set; } |
228 | 241 | ||
229 | public OMV.Vector3 RawForce { get; set; } | 242 | public OMV.Vector3 RawForce { get; set; } |
@@ -241,7 +254,12 @@ public abstract class BSPhysObject : PhysicsActor | |||
241 | 254 | ||
242 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } | 255 | public virtual bool ForceBodyShapeRebuild(bool inTaintTime) { return false; } |
243 | 256 | ||
244 | public override bool PIDActive { set { MoveToTargetActive = value; } } | 257 | public override bool PIDActive |
258 | { | ||
259 | get { return MoveToTargetActive; } | ||
260 | set { MoveToTargetActive = value; } | ||
261 | } | ||
262 | |||
245 | public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } } | 263 | public override OMV.Vector3 PIDTarget { set { MoveToTargetTarget = value; } } |
246 | public override float PIDTau { set { MoveToTargetTau = value; } } | 264 | public override float PIDTau { set { MoveToTargetTau = value; } } |
247 | 265 | ||
@@ -290,11 +308,20 @@ public abstract class BSPhysObject : PhysicsActor | |||
290 | // Note this is a displacement from the root's coordinates. Zero means use the root prim as center-of-mass. | 308 | // Note this is a displacement from the root's coordinates. Zero means use the root prim as center-of-mass. |
291 | public OMV.Vector3? UserSetCenterOfMassDisplacement { get; set; } | 309 | public OMV.Vector3? UserSetCenterOfMassDisplacement { get; set; } |
292 | 310 | ||
293 | public OMV.Vector3 LockedLinearAxis { get; set; } // zero means locked. one means free. | 311 | public OMV.Vector3 LockedLinearAxis; // zero means locked. one means free. |
294 | public OMV.Vector3 LockedAngularAxis { get; set; } // zero means locked. one means free. | 312 | public OMV.Vector3 LockedAngularAxis; // zero means locked. one means free. |
295 | public const float FreeAxis = 1f; | 313 | public const float FreeAxis = 1f; |
314 | public const float LockedAxis = 0f; | ||
296 | public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(FreeAxis, FreeAxis, FreeAxis); // All axis are free | 315 | public readonly OMV.Vector3 LockedAxisFree = new OMV.Vector3(FreeAxis, FreeAxis, FreeAxis); // All axis are free |
297 | 316 | ||
317 | // If an axis is locked (flagged above) then the limits of that axis are specified here. | ||
318 | // Linear axis limits are relative to the object's starting coordinates. | ||
319 | // Angular limits are limited to -PI to +PI | ||
320 | public OMV.Vector3 LockedLinearAxisLow; | ||
321 | public OMV.Vector3 LockedLinearAxisHigh; | ||
322 | public OMV.Vector3 LockedAngularAxisLow; | ||
323 | public OMV.Vector3 LockedAngularAxisHigh; | ||
324 | |||
298 | // Enable physical actions. Bullet will keep sleeping non-moving physical objects so | 325 | // Enable physical actions. Bullet will keep sleeping non-moving physical objects so |
299 | // they need waking up when parameters are changed. | 326 | // they need waking up when parameters are changed. |
300 | // Called in taint-time!! | 327 | // Called in taint-time!! |
@@ -416,12 +443,12 @@ public abstract class BSPhysObject : PhysicsActor | |||
416 | } | 443 | } |
417 | 444 | ||
418 | // The collisions that have been collected for the next collision reporting (throttled by subscription) | 445 | // The collisions that have been collected for the next collision reporting (throttled by subscription) |
419 | protected CollisionEventUpdate CollisionCollection; | 446 | protected CollisionEventUpdate CollisionCollection = new CollisionEventUpdate(); |
420 | // This is the collision collection last reported to the Simulator. | 447 | // This is the collision collection last reported to the Simulator. |
421 | public CollisionEventUpdate CollisionsLastReported; | 448 | public CollisionEventUpdate CollisionsLastReported = new CollisionEventUpdate(); |
422 | // Remember the collisions recorded in the last tick for fancy collision checking | 449 | // Remember the collisions recorded in the last tick for fancy collision checking |
423 | // (like a BSCharacter walking up stairs). | 450 | // (like a BSCharacter walking up stairs). |
424 | public CollisionEventUpdate CollisionsLastTick; | 451 | public CollisionEventUpdate CollisionsLastTick = new CollisionEventUpdate(); |
425 | private long CollisionsLastTickStep = -1; | 452 | private long CollisionsLastTickStep = -1; |
426 | 453 | ||
427 | // The simulation step is telling this object about a collision. | 454 | // The simulation step is telling this object about a collision. |
@@ -462,8 +489,11 @@ public abstract class BSPhysObject : PhysicsActor | |||
462 | 489 | ||
463 | // If someone has subscribed for collision events log the collision so it will be reported up | 490 | // If someone has subscribed for collision events log the collision so it will be reported up |
464 | if (SubscribedEvents()) { | 491 | if (SubscribedEvents()) { |
465 | CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | 492 | lock (PhysScene.CollisionLock) |
466 | DetailLog("{0},{1}.Collison.AddCollider,call,with={2},point={3},normal={4},depth={5},colliderMoving={6}", | 493 | { |
494 | CollisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | ||
495 | } | ||
496 | DetailLog("{0},{1}.Collision.AddCollider,call,with={2},point={3},normal={4},depth={5},colliderMoving={6}", | ||
467 | LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth, ColliderIsMoving); | 497 | LocalID, TypeName, collidingWith, contactPoint, contactNormal, pentrationDepth, ColliderIsMoving); |
468 | 498 | ||
469 | ret = true; | 499 | ret = true; |
@@ -474,12 +504,14 @@ public abstract class BSPhysObject : PhysicsActor | |||
474 | // Send the collected collisions into the simulator. | 504 | // Send the collected collisions into the simulator. |
475 | // Called at taint time from within the Step() function thus no locking problems | 505 | // Called at taint time from within the Step() function thus no locking problems |
476 | // with CollisionCollection and ObjectsWithNoMoreCollisions. | 506 | // with CollisionCollection and ObjectsWithNoMoreCollisions. |
507 | // Called with BSScene.CollisionLock locked to protect the collision lists. | ||
477 | // Return 'true' if there were some actual collisions passed up | 508 | // Return 'true' if there were some actual collisions passed up |
478 | public virtual bool SendCollisions() | 509 | public virtual bool SendCollisions() |
479 | { | 510 | { |
480 | bool ret = true; | 511 | bool ret = true; |
481 | 512 | ||
482 | // If the 'no collision' call, force it to happen right now so quick collision_end | 513 | // If no collisions this call but there were collisions last call, force the collision |
514 | // event to be happen right now so quick collision_end. | ||
483 | bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); | 515 | bool force = (CollisionCollection.Count == 0 && CollisionsLastReported.Count != 0); |
484 | 516 | ||
485 | // throttle the collisions to the number of milliseconds specified in the subscription | 517 | // throttle the collisions to the number of milliseconds specified in the subscription |
@@ -562,7 +594,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
562 | 594 | ||
563 | #region Per Simulation Step actions | 595 | #region Per Simulation Step actions |
564 | 596 | ||
565 | public BSActorCollection PhysicalActors; | 597 | public BSActorCollection PhysicalActors = new BSActorCollection(); |
566 | 598 | ||
567 | // When an update to the physical properties happens, this event is fired to let | 599 | // When an update to the physical properties happens, this event is fired to let |
568 | // different actors to modify the update before it is passed around | 600 | // different actors to modify the update before it is passed around |