diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 167 |
1 files changed, 86 insertions, 81 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 11868bc..05cc822 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -42,7 +42,7 @@ public sealed class BSPrim : PhysicsActor | |||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
43 | private static readonly string LogHeader = "[BULLETS PRIM]"; | 43 | private static readonly string LogHeader = "[BULLETS PRIM]"; |
44 | 44 | ||
45 | private void DebugLog(string mm, params Object[] xx) { if (_scene.shouldDebugLog) m_log.DebugFormat(mm, xx); } | 45 | private void DebugLog(string mm, params Object[] xx) { if (_scene.ShouldDebugLog) m_log.DebugFormat(mm, xx); } |
46 | 46 | ||
47 | private IMesh _mesh; | 47 | private IMesh _mesh; |
48 | private PrimitiveBaseShape _pbs; | 48 | private PrimitiveBaseShape _pbs; |
@@ -138,14 +138,15 @@ public sealed class BSPrim : PhysicsActor | |||
138 | _isPhysical = pisPhysical; | 138 | _isPhysical = pisPhysical; |
139 | _isVolumeDetect = false; | 139 | _isVolumeDetect = false; |
140 | _subscribedEventsMs = 0; | 140 | _subscribedEventsMs = 0; |
141 | _friction = _scene.Params.defaultFriction; // TODO: compute based on object material | 141 | _friction = _scene.Params.defaultFriction; // TODO: compute based on object material |
142 | _density = _scene.Params.defaultDensity; // TODO: compute based on object material | 142 | _density = _scene.Params.defaultDensity; // TODO: compute based on object material |
143 | _restitution = _scene.Params.defaultRestitution; | 143 | _restitution = _scene.Params.defaultRestitution; |
144 | _linkset = new BSLinkset(_scene, this); // a linkset of one | 144 | _linkset = new BSLinkset(_scene, this); // a linkset of one |
145 | _vehicle = new BSDynamics(this); // add vehicleness | 145 | _vehicle = new BSDynamics(this); // add vehicleness |
146 | _mass = CalculateMass(); | 146 | _mass = CalculateMass(); |
147 | // do the actual object creation at taint time | 147 | // do the actual object creation at taint time |
148 | _scene.TaintedObject(delegate() | 148 | DetailLog("{0},BSPrim.constructor,call", LocalID); |
149 | _scene.TaintedObject("BSPrim.create", delegate() | ||
149 | { | 150 | { |
150 | RecreateGeomAndObject(); | 151 | RecreateGeomAndObject(); |
151 | 152 | ||
@@ -160,17 +161,22 @@ public sealed class BSPrim : PhysicsActor | |||
160 | public void Destroy() | 161 | public void Destroy() |
161 | { | 162 | { |
162 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); | 163 | // m_log.DebugFormat("{0}: Destroy, id={1}", LogHeader, LocalID); |
163 | // DetailLog("{0},Destroy", LocalID); | 164 | |
165 | // Undo any links between me and any other object | ||
166 | BSPrim parentBefore = _linkset.Root; | ||
167 | int childrenBefore = _linkset.NumberOfChildren; | ||
168 | |||
169 | _linkset = _linkset.RemoveMeFromLinkset(this); | ||
170 | |||
171 | DetailLog("{0},BSPrim.Destroy,call,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}", | ||
172 | LocalID, parentBefore.LocalID, childrenBefore, _linkset.Root.LocalID, _linkset.NumberOfChildren); | ||
164 | 173 | ||
165 | // Undo any vehicle properties | 174 | // Undo any vehicle properties |
166 | _vehicle.ProcessTypeChange(Vehicle.TYPE_NONE); | 175 | this.VehicleType = (int)Vehicle.TYPE_NONE; |
167 | _scene.RemoveVehiclePrim(this); // just to make sure | ||
168 | 176 | ||
169 | _scene.TaintedObject(delegate() | 177 | _scene.TaintedObject("BSPrim.destroy", delegate() |
170 | { | 178 | { |
171 | // Undo any links between me and any other object | 179 | DetailLog("{0},BSPrim.Destroy,taint,", LocalID); |
172 | _linkset = _linkset.RemoveMeFromLinkset(this); | ||
173 | |||
174 | // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. | 180 | // everything in the C# world will get garbage collected. Tell the C++ world to free stuff. |
175 | BulletSimAPI.DestroyObject(_scene.WorldID, LocalID); | 181 | BulletSimAPI.DestroyObject(_scene.WorldID, LocalID); |
176 | }); | 182 | }); |
@@ -183,11 +189,11 @@ public sealed class BSPrim : PhysicsActor | |||
183 | get { return _size; } | 189 | get { return _size; } |
184 | set { | 190 | set { |
185 | _size = value; | 191 | _size = value; |
186 | _scene.TaintedObject(delegate() | 192 | _scene.TaintedObject("BSPrim.setSize", delegate() |
187 | { | 193 | { |
188 | _mass = CalculateMass(); // changing size changes the mass | 194 | _mass = CalculateMass(); // changing size changes the mass |
189 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); | 195 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); |
190 | // DetailLog("{0}: setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical); | 196 | // DetailLog("{0}: BSPrim.setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical); |
191 | RecreateGeomAndObject(); | 197 | RecreateGeomAndObject(); |
192 | }); | 198 | }); |
193 | } | 199 | } |
@@ -195,7 +201,7 @@ public sealed class BSPrim : PhysicsActor | |||
195 | public override PrimitiveBaseShape Shape { | 201 | public override PrimitiveBaseShape Shape { |
196 | set { | 202 | set { |
197 | _pbs = value; | 203 | _pbs = value; |
198 | _scene.TaintedObject(delegate() | 204 | _scene.TaintedObject("BSPrim.setShape", delegate() |
199 | { | 205 | { |
200 | _mass = CalculateMass(); // changing the shape changes the mass | 206 | _mass = CalculateMass(); // changing the shape changes the mass |
201 | RecreateGeomAndObject(); | 207 | RecreateGeomAndObject(); |
@@ -213,7 +219,7 @@ public sealed class BSPrim : PhysicsActor | |||
213 | public override bool Selected { | 219 | public override bool Selected { |
214 | set { | 220 | set { |
215 | _isSelected = value; | 221 | _isSelected = value; |
216 | _scene.TaintedObject(delegate() | 222 | _scene.TaintedObject("BSPrim.setSelected", delegate() |
217 | { | 223 | { |
218 | SetObjectDynamic(); | 224 | SetObjectDynamic(); |
219 | }); | 225 | }); |
@@ -224,10 +230,17 @@ public sealed class BSPrim : PhysicsActor | |||
224 | // link me to the specified parent | 230 | // link me to the specified parent |
225 | public override void link(PhysicsActor obj) { | 231 | public override void link(PhysicsActor obj) { |
226 | BSPrim parent = obj as BSPrim; | 232 | BSPrim parent = obj as BSPrim; |
227 | DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, obj.LocalID); | 233 | if (parent != null) |
228 | DetailLog("{0},link,parent={1}", LocalID, obj.LocalID); | 234 | { |
235 | DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, parent.LocalID); | ||
236 | BSPrim parentBefore = _linkset.Root; | ||
237 | int childrenBefore = _linkset.NumberOfChildren; | ||
229 | 238 | ||
230 | _linkset = _linkset.AddMeToLinkset(this, parent); | 239 | _linkset = parent.Linkset.AddMeToLinkset(this); |
240 | |||
241 | DetailLog("{0},BSPrim.link,call,parentBefore={1}, childrenBefore=={2}, parentAfter={3}, childrenAfter={4}", | ||
242 | LocalID, parentBefore.LocalID, childrenBefore, _linkset.Root.LocalID, _linkset.NumberOfChildren); | ||
243 | } | ||
231 | return; | 244 | return; |
232 | } | 245 | } |
233 | 246 | ||
@@ -237,9 +250,14 @@ public sealed class BSPrim : PhysicsActor | |||
237 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen | 250 | // Race condition here: if link() and delink() in same simulation tick, the delink will not happen |
238 | DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID, | 251 | DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID, |
239 | _linkset.Root._avName+"/"+_linkset.Root.LocalID.ToString()); | 252 | _linkset.Root._avName+"/"+_linkset.Root.LocalID.ToString()); |
240 | DetailLog("{0},delink,parent={1}", LocalID, _linkset.Root.LocalID.ToString()); | ||
241 | 253 | ||
242 | _linkset.RemoveMeFromLinkset(this); | 254 | BSPrim parentBefore = _linkset.Root; |
255 | int childrenBefore = _linkset.NumberOfChildren; | ||
256 | |||
257 | _linkset = _linkset.RemoveMeFromLinkset(this); | ||
258 | |||
259 | DetailLog("{0},BSPrim.delink,parentBefore={1},childrenBefore={2},parentAfter={3},childrenAfter={4}, ", | ||
260 | LocalID, parentBefore.LocalID, childrenBefore, _linkset.Root.LocalID, _linkset.NumberOfChildren); | ||
243 | return; | 261 | return; |
244 | } | 262 | } |
245 | 263 | ||
@@ -262,7 +280,7 @@ public sealed class BSPrim : PhysicsActor | |||
262 | 280 | ||
263 | public override void LockAngularMotion(OMV.Vector3 axis) | 281 | public override void LockAngularMotion(OMV.Vector3 axis) |
264 | { | 282 | { |
265 | DetailLog("{0},LockAngularMotion,call,axis={1}", LocalID, axis); | 283 | DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); |
266 | return; | 284 | return; |
267 | } | 285 | } |
268 | 286 | ||
@@ -279,9 +297,9 @@ public sealed class BSPrim : PhysicsActor | |||
279 | set { | 297 | set { |
280 | _position = value; | 298 | _position = value; |
281 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? | 299 | // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? |
282 | _scene.TaintedObject(delegate() | 300 | _scene.TaintedObject("BSPrim.setPosition", delegate() |
283 | { | 301 | { |
284 | DetailLog("{0},SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 302 | DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
285 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 303 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
286 | }); | 304 | }); |
287 | } | 305 | } |
@@ -316,9 +334,9 @@ public sealed class BSPrim : PhysicsActor | |||
316 | get { return _force; } | 334 | get { return _force; } |
317 | set { | 335 | set { |
318 | _force = value; | 336 | _force = value; |
319 | _scene.TaintedObject(delegate() | 337 | _scene.TaintedObject("BSPrim.setForce", delegate() |
320 | { | 338 | { |
321 | DetailLog("{0},setForce,taint,force={1}", LocalID, _force); | 339 | DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); |
322 | // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); | 340 | // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); |
323 | BulletSimAPI.SetObjectForce2(Body.Ptr, _force); | 341 | BulletSimAPI.SetObjectForce2(Body.Ptr, _force); |
324 | }); | 342 | }); |
@@ -331,53 +349,41 @@ public sealed class BSPrim : PhysicsActor | |||
331 | } | 349 | } |
332 | set { | 350 | set { |
333 | Vehicle type = (Vehicle)value; | 351 | Vehicle type = (Vehicle)value; |
334 | _scene.TaintedObject(delegate() | 352 | BSPrim vehiclePrim = this; |
353 | _scene.TaintedObject("setVehicleType", delegate() | ||
335 | { | 354 | { |
336 | DetailLog("{0},SetVehicleType,taint,type={1}", LocalID, type); | 355 | // Done at taint time so we're sure the physics engine is not using the variables |
356 | // Vehicle code changes the parameters for this vehicle type. | ||
337 | _vehicle.ProcessTypeChange(type); | 357 | _vehicle.ProcessTypeChange(type); |
338 | if (type == Vehicle.TYPE_NONE) | 358 | // Tell the scene about the vehicle so it will get processing each frame. |
339 | { | 359 | _scene.VehicleInSceneTypeChanged(this, type); |
340 | _scene.RemoveVehiclePrim(this); | ||
341 | } | ||
342 | else | ||
343 | { | ||
344 | _scene.TaintedObject(delegate() | ||
345 | { | ||
346 | // Tell the physics engine to clear state | ||
347 | BulletSimAPI.ClearForces2(this.Body.Ptr); | ||
348 | }); | ||
349 | |||
350 | // make it so the scene will call us each tick to do vehicle things | ||
351 | _scene.AddVehiclePrim(this); | ||
352 | } | ||
353 | return; | ||
354 | }); | 360 | }); |
355 | } | 361 | } |
356 | } | 362 | } |
357 | public override void VehicleFloatParam(int param, float value) | 363 | public override void VehicleFloatParam(int param, float value) |
358 | { | 364 | { |
359 | _scene.TaintedObject(delegate() | 365 | _scene.TaintedObject("BSPrim.VehicleFloatParam", delegate() |
360 | { | 366 | { |
361 | _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | 367 | _vehicle.ProcessFloatVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); |
362 | }); | 368 | }); |
363 | } | 369 | } |
364 | public override void VehicleVectorParam(int param, OMV.Vector3 value) | 370 | public override void VehicleVectorParam(int param, OMV.Vector3 value) |
365 | { | 371 | { |
366 | _scene.TaintedObject(delegate() | 372 | _scene.TaintedObject("BSPrim.VehicleVectorParam", delegate() |
367 | { | 373 | { |
368 | _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); | 374 | _vehicle.ProcessVectorVehicleParam((Vehicle)param, value, _scene.LastSimulatedTimestep); |
369 | }); | 375 | }); |
370 | } | 376 | } |
371 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) | 377 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) |
372 | { | 378 | { |
373 | _scene.TaintedObject(delegate() | 379 | _scene.TaintedObject("BSPrim.VehicleRotationParam", delegate() |
374 | { | 380 | { |
375 | _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); | 381 | _vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation); |
376 | }); | 382 | }); |
377 | } | 383 | } |
378 | public override void VehicleFlags(int param, bool remove) | 384 | public override void VehicleFlags(int param, bool remove) |
379 | { | 385 | { |
380 | _scene.TaintedObject(delegate() | 386 | _scene.TaintedObject("BSPrim.VehicleFlags", delegate() |
381 | { | 387 | { |
382 | _vehicle.ProcessVehicleFlags(param, remove); | 388 | _vehicle.ProcessVehicleFlags(param, remove); |
383 | }); | 389 | }); |
@@ -395,7 +401,7 @@ public sealed class BSPrim : PhysicsActor | |||
395 | public override void SetVolumeDetect(int param) { | 401 | public override void SetVolumeDetect(int param) { |
396 | bool newValue = (param != 0); | 402 | bool newValue = (param != 0); |
397 | _isVolumeDetect = newValue; | 403 | _isVolumeDetect = newValue; |
398 | _scene.TaintedObject(delegate() | 404 | _scene.TaintedObject("BSPrim.SetVolumeDetect", delegate() |
399 | { | 405 | { |
400 | SetObjectDynamic(); | 406 | SetObjectDynamic(); |
401 | }); | 407 | }); |
@@ -406,9 +412,9 @@ public sealed class BSPrim : PhysicsActor | |||
406 | get { return _velocity; } | 412 | get { return _velocity; } |
407 | set { | 413 | set { |
408 | _velocity = value; | 414 | _velocity = value; |
409 | _scene.TaintedObject(delegate() | 415 | _scene.TaintedObject("BSPrim.setVelocity", delegate() |
410 | { | 416 | { |
411 | DetailLog("{0},SetVelocity,taint,vel={1}", LocalID, _velocity); | 417 | DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); |
412 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); | 418 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); |
413 | }); | 419 | }); |
414 | } | 420 | } |
@@ -416,7 +422,7 @@ public sealed class BSPrim : PhysicsActor | |||
416 | public override OMV.Vector3 Torque { | 422 | public override OMV.Vector3 Torque { |
417 | get { return _torque; } | 423 | get { return _torque; } |
418 | set { _torque = value; | 424 | set { _torque = value; |
419 | DetailLog("{0},SetTorque,call,torque={1}", LocalID, _torque); | 425 | DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); |
420 | } | 426 | } |
421 | } | 427 | } |
422 | public override float CollisionScore { | 428 | public override float CollisionScore { |
@@ -440,10 +446,10 @@ public sealed class BSPrim : PhysicsActor | |||
440 | set { | 446 | set { |
441 | _orientation = value; | 447 | _orientation = value; |
442 | // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? | 448 | // TODO: what does it mean if a child in a linkset changes its orientation? Rebuild the constraint? |
443 | _scene.TaintedObject(delegate() | 449 | _scene.TaintedObject("BSPrim.setOrientation", delegate() |
444 | { | 450 | { |
445 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 451 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); |
446 | DetailLog("{0},setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 452 | DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
447 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 453 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); |
448 | }); | 454 | }); |
449 | } | 455 | } |
@@ -457,7 +463,7 @@ public sealed class BSPrim : PhysicsActor | |||
457 | get { return _isPhysical; } | 463 | get { return _isPhysical; } |
458 | set { | 464 | set { |
459 | _isPhysical = value; | 465 | _isPhysical = value; |
460 | _scene.TaintedObject(delegate() | 466 | _scene.TaintedObject("BSPrim.setIsPhysical", delegate() |
461 | { | 467 | { |
462 | SetObjectDynamic(); | 468 | SetObjectDynamic(); |
463 | }); | 469 | }); |
@@ -478,7 +484,6 @@ public sealed class BSPrim : PhysicsActor | |||
478 | 484 | ||
479 | // Make gravity work if the object is physical and not selected | 485 | // Make gravity work if the object is physical and not selected |
480 | // No locking here because only called when it is safe | 486 | // No locking here because only called when it is safe |
481 | // Only called at taint time so it is save to call into Bullet. | ||
482 | private void SetObjectDynamic() | 487 | private void SetObjectDynamic() |
483 | { | 488 | { |
484 | // RA: remove this for the moment. | 489 | // RA: remove this for the moment. |
@@ -490,8 +495,10 @@ public sealed class BSPrim : PhysicsActor | |||
490 | // Bullet wants static objects to have a mass of zero | 495 | // Bullet wants static objects to have a mass of zero |
491 | float mass = IsStatic ? 0f : _mass; | 496 | float mass = IsStatic ? 0f : _mass; |
492 | 497 | ||
493 | DetailLog("{0},SetObjectDynamic,taint,static={1},solid={2},mass={3}", LocalID, IsStatic, IsSolid, mass); | ||
494 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); | 498 | BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), mass); |
499 | |||
500 | CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr); | ||
501 | DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf); | ||
495 | } | 502 | } |
496 | 503 | ||
497 | // prims don't fly | 504 | // prims don't fly |
@@ -546,9 +553,9 @@ public sealed class BSPrim : PhysicsActor | |||
546 | set { | 553 | set { |
547 | _rotationalVelocity = value; | 554 | _rotationalVelocity = value; |
548 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); | 555 | // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); |
549 | _scene.TaintedObject(delegate() | 556 | _scene.TaintedObject("BSPrim.setRotationalVelocity", delegate() |
550 | { | 557 | { |
551 | DetailLog("{0},SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); | 558 | DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); |
552 | BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); | 559 | BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); |
553 | }); | 560 | }); |
554 | } | 561 | } |
@@ -563,9 +570,9 @@ public sealed class BSPrim : PhysicsActor | |||
563 | get { return _buoyancy; } | 570 | get { return _buoyancy; } |
564 | set { | 571 | set { |
565 | _buoyancy = value; | 572 | _buoyancy = value; |
566 | _scene.TaintedObject(delegate() | 573 | _scene.TaintedObject("BSPrim.setBuoyancy", delegate() |
567 | { | 574 | { |
568 | DetailLog("{0},SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 575 | DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
569 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); | 576 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); |
570 | }); | 577 | }); |
571 | } | 578 | } |
@@ -617,7 +624,7 @@ public sealed class BSPrim : PhysicsActor | |||
617 | m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); | 624 | m_log.WarnFormat("{0}: Got a NaN force applied to a Character", LogHeader); |
618 | return; | 625 | return; |
619 | } | 626 | } |
620 | _scene.TaintedObject(delegate() | 627 | _scene.TaintedObject("BSPrim.AddForce", delegate() |
621 | { | 628 | { |
622 | OMV.Vector3 fSum = OMV.Vector3.Zero; | 629 | OMV.Vector3 fSum = OMV.Vector3.Zero; |
623 | lock (m_accumulatedForces) | 630 | lock (m_accumulatedForces) |
@@ -628,17 +635,17 @@ public sealed class BSPrim : PhysicsActor | |||
628 | } | 635 | } |
629 | m_accumulatedForces.Clear(); | 636 | m_accumulatedForces.Clear(); |
630 | } | 637 | } |
631 | DetailLog("{0},AddObjectForce,taint,force={1}", LocalID, _force); | 638 | DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force); |
632 | BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); | 639 | BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); |
633 | }); | 640 | }); |
634 | } | 641 | } |
635 | 642 | ||
636 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { | 643 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
637 | DetailLog("{0},AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); | 644 | DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); |
638 | // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); | 645 | // m_log.DebugFormat("{0}: AddAngularForce. f={1}, push={2}", LogHeader, force, pushforce); |
639 | } | 646 | } |
640 | public override void SetMomentum(OMV.Vector3 momentum) { | 647 | public override void SetMomentum(OMV.Vector3 momentum) { |
641 | DetailLog("{0},SetMomentum,call,mom={1}", LocalID, momentum); | 648 | DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); |
642 | } | 649 | } |
643 | public override void SubscribeEvents(int ms) { | 650 | public override void SubscribeEvents(int ms) { |
644 | _subscribedEventsMs = ms; | 651 | _subscribedEventsMs = ms; |
@@ -647,7 +654,7 @@ public sealed class BSPrim : PhysicsActor | |||
647 | // make sure first collision happens | 654 | // make sure first collision happens |
648 | _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; | 655 | _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; |
649 | 656 | ||
650 | Scene.TaintedObject(delegate() | 657 | Scene.TaintedObject("BSPrim.SubscribeEvents", delegate() |
651 | { | 658 | { |
652 | BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 659 | BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
653 | }); | 660 | }); |
@@ -655,7 +662,7 @@ public sealed class BSPrim : PhysicsActor | |||
655 | } | 662 | } |
656 | public override void UnSubscribeEvents() { | 663 | public override void UnSubscribeEvents() { |
657 | _subscribedEventsMs = 0; | 664 | _subscribedEventsMs = 0; |
658 | Scene.TaintedObject(delegate() | 665 | Scene.TaintedObject("BSPrim.UnSubscribeEvents", delegate() |
659 | { | 666 | { |
660 | BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 667 | BulletSimAPI.RemoveFromCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
661 | }); | 668 | }); |
@@ -982,7 +989,7 @@ public sealed class BSPrim : PhysicsActor | |||
982 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size); | 989 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to sphere of size {1}", LogHeader, _size); |
983 | if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) | 990 | if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) |
984 | { | 991 | { |
985 | DetailLog("{0},CreateGeom,sphere", LocalID); | 992 | DetailLog("{0},BSPrim.CreateGeom,sphere (force={1}", LocalID, forceRebuild); |
986 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE; | 993 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE; |
987 | // Bullet native objects are scaled by the Bullet engine so pass the size in | 994 | // Bullet native objects are scaled by the Bullet engine so pass the size in |
988 | _scale = _size; | 995 | _scale = _size; |
@@ -996,7 +1003,7 @@ public sealed class BSPrim : PhysicsActor | |||
996 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, type={2}, size={3}", LogHeader, LocalID, _shapeType, _size); | 1003 | // m_log.DebugFormat("{0}: CreateGeom: Defaulting to box. lid={1}, type={2}, size={3}", LogHeader, LocalID, _shapeType, _size); |
997 | if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_BOX)) | 1004 | if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_BOX)) |
998 | { | 1005 | { |
999 | DetailLog("{0},CreateGeom,box", LocalID); | 1006 | DetailLog("{0},BSPrim.CreateGeom,box (force={1})", LocalID, forceRebuild); |
1000 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; | 1007 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; |
1001 | _scale = _size; | 1008 | _scale = _size; |
1002 | // TODO: do we need to check for and destroy a mesh or hull that might have been left from before? | 1009 | // TODO: do we need to check for and destroy a mesh or hull that might have been left from before? |
@@ -1039,12 +1046,12 @@ public sealed class BSPrim : PhysicsActor | |||
1039 | // if this new shape is the same as last time, don't recreate the mesh | 1046 | // if this new shape is the same as last time, don't recreate the mesh |
1040 | if (_meshKey == newMeshKey) return; | 1047 | if (_meshKey == newMeshKey) return; |
1041 | 1048 | ||
1042 | DetailLog("{0},CreateGeomMesh,create,key={1}", LocalID, newMeshKey); | 1049 | DetailLog("{0},BSPrim.CreateGeomMesh,create,key={1}", LocalID, newMeshKey); |
1043 | // Since we're recreating new, get rid of any previously generated shape | 1050 | // Since we're recreating new, get rid of any previously generated shape |
1044 | if (_meshKey != 0) | 1051 | if (_meshKey != 0) |
1045 | { | 1052 | { |
1046 | // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); | 1053 | // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); |
1047 | DetailLog("{0},CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); | 1054 | DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); |
1048 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); | 1055 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); |
1049 | _mesh = null; | 1056 | _mesh = null; |
1050 | _meshKey = 0; | 1057 | _meshKey = 0; |
@@ -1074,7 +1081,7 @@ public sealed class BSPrim : PhysicsActor | |||
1074 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; | 1081 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; |
1075 | // meshes are already scaled by the meshmerizer | 1082 | // meshes are already scaled by the meshmerizer |
1076 | _scale = new OMV.Vector3(1f, 1f, 1f); | 1083 | _scale = new OMV.Vector3(1f, 1f, 1f); |
1077 | DetailLog("{0},CreateGeomMesh,done", LocalID); | 1084 | DetailLog("{0},BSPrim.CreateGeomMesh,done", LocalID); |
1078 | return; | 1085 | return; |
1079 | } | 1086 | } |
1080 | 1087 | ||
@@ -1088,17 +1095,17 @@ public sealed class BSPrim : PhysicsActor | |||
1088 | // if the hull hasn't changed, don't rebuild it | 1095 | // if the hull hasn't changed, don't rebuild it |
1089 | if (newHullKey == _hullKey) return; | 1096 | if (newHullKey == _hullKey) return; |
1090 | 1097 | ||
1091 | DetailLog("{0},CreateGeomHull,create,key={1}", LocalID, _meshKey); | 1098 | DetailLog("{0},BSPrim.CreateGeomHull,create,key={1}", LocalID, _meshKey); |
1092 | 1099 | ||
1093 | // Since we're recreating new, get rid of any previously generated shape | 1100 | // Since we're recreating new, get rid of any previously generated shape |
1094 | if (_hullKey != 0) | 1101 | if (_hullKey != 0) |
1095 | { | 1102 | { |
1096 | // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); | 1103 | // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); |
1097 | DetailLog("{0},CreateGeomHull,deleteOldHull,key={1}", LocalID, _meshKey); | 1104 | DetailLog("{0},BSPrim.CreateGeomHull,deleteOldHull,key={1}", LocalID, _meshKey); |
1098 | BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); | 1105 | BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); |
1099 | _hullKey = 0; | 1106 | _hullKey = 0; |
1100 | _hulls.Clear(); | 1107 | _hulls.Clear(); |
1101 | DetailLog("{0},CreateGeomHull,deleteOldMesh,key={1}", LocalID, _meshKey); | 1108 | DetailLog("{0},BSPrim.CreateGeomHull,deleteOldMesh,key={1}", LocalID, _meshKey); |
1102 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); | 1109 | BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); |
1103 | _mesh = null; // the mesh cannot match either | 1110 | _mesh = null; // the mesh cannot match either |
1104 | _meshKey = 0; | 1111 | _meshKey = 0; |
@@ -1195,7 +1202,7 @@ public sealed class BSPrim : PhysicsActor | |||
1195 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; | 1202 | _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; |
1196 | // meshes are already scaled by the meshmerizer | 1203 | // meshes are already scaled by the meshmerizer |
1197 | _scale = new OMV.Vector3(1f, 1f, 1f); | 1204 | _scale = new OMV.Vector3(1f, 1f, 1f); |
1198 | DetailLog("{0},CreateGeomHull,done", LocalID); | 1205 | DetailLog("{0},BSPrim.CreateGeomHull,done", LocalID); |
1199 | return; | 1206 | return; |
1200 | } | 1207 | } |
1201 | 1208 | ||
@@ -1221,7 +1228,7 @@ public sealed class BSPrim : PhysicsActor | |||
1221 | bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape); | 1228 | bool ret = BulletSimAPI.CreateObject(_scene.WorldID, shape); |
1222 | 1229 | ||
1223 | // the CreateObject() may have recreated the rigid body. Make sure we have the latest. | 1230 | // the CreateObject() may have recreated the rigid body. Make sure we have the latest. |
1224 | m_body.Ptr = BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID); | 1231 | Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); |
1225 | 1232 | ||
1226 | return ret; | 1233 | return ret; |
1227 | } | 1234 | } |
@@ -1333,20 +1340,18 @@ public sealed class BSPrim : PhysicsActor | |||
1333 | 1340 | ||
1334 | // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}", | 1341 | // m_log.DebugFormat("{0}: RequestTerseUpdate. id={1}, ch={2}, pos={3}, rot={4}, vel={5}, acc={6}, rvel={7}", |
1335 | // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | 1342 | // LogHeader, LocalID, changed, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); |
1336 | DetailLog("{0},UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | 1343 | DetailLog("{0},BSPrim.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5}", |
1337 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); | 1344 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity); |
1338 | 1345 | ||
1339 | base.RequestPhysicsterseUpdate(); | 1346 | base.RequestPhysicsterseUpdate(); |
1340 | } | 1347 | } |
1341 | /* | ||
1342 | else | 1348 | else |
1343 | { | 1349 | { |
1344 | // For debugging, we also report the movement of children | 1350 | // For debugging, we also report the movement of children |
1345 | DetailLog("{0},UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", | 1351 | DetailLog("{0},BSPrim.UpdateProperties,child,pos={1},orient={2},vel={3},accel={4},rotVel={5}", |
1346 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | 1352 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, |
1347 | entprop.Acceleration, entprop.RotationalVelocity); | 1353 | entprop.Acceleration, entprop.RotationalVelocity); |
1348 | } | 1354 | } |
1349 | */ | ||
1350 | } | 1355 | } |
1351 | 1356 | ||
1352 | // I've collided with something | 1357 | // I've collided with something |