aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs66
1 files changed, 35 insertions, 31 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
index c157669..a6bc8e2 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs
@@ -42,8 +42,6 @@ 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); }
46
47 private IMesh _mesh; 45 private IMesh _mesh;
48 private PrimitiveBaseShape _pbs; 46 private PrimitiveBaseShape _pbs;
49 private ShapeData.PhysicsShapeType _shapeType; 47 private ShapeData.PhysicsShapeType _shapeType;
@@ -141,8 +139,8 @@ public sealed class BSPrim : PhysicsActor
141 _friction = _scene.Params.defaultFriction; // TODO: compute based on object material 139 _friction = _scene.Params.defaultFriction; // TODO: compute based on object material
142 _density = _scene.Params.defaultDensity; // TODO: compute based on object material 140 _density = _scene.Params.defaultDensity; // TODO: compute based on object material
143 _restitution = _scene.Params.defaultRestitution; 141 _restitution = _scene.Params.defaultRestitution;
144 _linkset = new BSLinkset(_scene, this); // a linkset of one 142 _linkset = new BSLinkset(Scene, this); // a linkset of one
145 _vehicle = new BSDynamics(this); // add vehicleness 143 _vehicle = new BSDynamics(Scene, this); // add vehicleness
146 _mass = CalculateMass(); 144 _mass = CalculateMass();
147 // do the actual object creation at taint time 145 // do the actual object creation at taint time
148 DetailLog("{0},BSPrim.constructor,call", LocalID); 146 DetailLog("{0},BSPrim.constructor,call", LocalID);
@@ -193,7 +191,7 @@ public sealed class BSPrim : PhysicsActor
193 { 191 {
194 _mass = CalculateMass(); // changing size changes the mass 192 _mass = CalculateMass(); // changing size changes the mass
195 BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical); 193 BulletSimAPI.SetObjectScaleMass(_scene.WorldID, _localID, _scale, (IsPhysical ? _mass : 0f), IsPhysical);
196 // DetailLog("{0}: BSPrim.setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical); 194 DetailLog("{0}: BSPrim.setSize: size={1}, mass={2}, physical={3}", LocalID, _size, _mass, IsPhysical);
197 RecreateGeomAndObject(); 195 RecreateGeomAndObject();
198 }); 196 });
199 } 197 }
@@ -232,7 +230,6 @@ public sealed class BSPrim : PhysicsActor
232 BSPrim parent = obj as BSPrim; 230 BSPrim parent = obj as BSPrim;
233 if (parent != null) 231 if (parent != null)
234 { 232 {
235 DebugLog("{0}: link {1}/{2} to {3}", LogHeader, _avName, _localID, parent.LocalID);
236 BSPrim parentBefore = _linkset.LinksetRoot; 233 BSPrim parentBefore = _linkset.LinksetRoot;
237 int childrenBefore = _linkset.NumberOfChildren; 234 int childrenBefore = _linkset.NumberOfChildren;
238 235
@@ -248,8 +245,6 @@ public sealed class BSPrim : PhysicsActor
248 public override void delink() { 245 public override void delink() {
249 // TODO: decide if this parent checking needs to happen at taint time 246 // TODO: decide if this parent checking needs to happen at taint time
250 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen 247 // Race condition here: if link() and delink() in same simulation tick, the delink will not happen
251 DebugLog("{0}: delink {1}/{2}. Parent={3}", LogHeader, _avName, _localID,
252 _linkset.LinksetRoot._avName+"/"+_linkset.LinksetRoot.LocalID.ToString());
253 248
254 BSPrim parentBefore = _linkset.LinksetRoot; 249 BSPrim parentBefore = _linkset.LinksetRoot;
255 int childrenBefore = _linkset.NumberOfChildren; 250 int childrenBefore = _linkset.NumberOfChildren;
@@ -280,7 +275,7 @@ public sealed class BSPrim : PhysicsActor
280 275
281 public override void LockAngularMotion(OMV.Vector3 axis) 276 public override void LockAngularMotion(OMV.Vector3 axis)
282 { 277 {
283 // DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis); 278 DetailLog("{0},BSPrim.LockAngularMotion,call,axis={1}", LocalID, axis);
284 return; 279 return;
285 } 280 }
286 281
@@ -299,7 +294,7 @@ public sealed class BSPrim : PhysicsActor
299 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint? 294 // TODO: what does it mean to set the position of a child prim?? Rebuild the constraint?
300 _scene.TaintedObject("BSPrim.setPosition", delegate() 295 _scene.TaintedObject("BSPrim.setPosition", delegate()
301 { 296 {
302 // DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 297 DetailLog("{0},BSPrim.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
303 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 298 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
304 }); 299 });
305 } 300 }
@@ -336,7 +331,7 @@ public sealed class BSPrim : PhysicsActor
336 _force = value; 331 _force = value;
337 _scene.TaintedObject("BSPrim.setForce", delegate() 332 _scene.TaintedObject("BSPrim.setForce", delegate()
338 { 333 {
339 // DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force); 334 DetailLog("{0},BSPrim.setForce,taint,force={1}", LocalID, _force);
340 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force); 335 // BulletSimAPI.SetObjectForce(_scene.WorldID, _localID, _force);
341 BulletSimAPI.SetObjectForce2(Body.Ptr, _force); 336 BulletSimAPI.SetObjectForce2(Body.Ptr, _force);
342 }); 337 });
@@ -354,7 +349,7 @@ public sealed class BSPrim : PhysicsActor
354 { 349 {
355 // Done at taint time so we're sure the physics engine is not using the variables 350 // 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. 351 // Vehicle code changes the parameters for this vehicle type.
357 _vehicle.ProcessTypeChange(type); 352 _vehicle.ProcessTypeChange(type, Scene.LastSimulatedTimestep);
358 // Tell the scene about the vehicle so it will get processing each frame. 353 // Tell the scene about the vehicle so it will get processing each frame.
359 _scene.VehicleInSceneTypeChanged(this, type); 354 _scene.VehicleInSceneTypeChanged(this, type);
360 }); 355 });
@@ -414,7 +409,7 @@ public sealed class BSPrim : PhysicsActor
414 _velocity = value; 409 _velocity = value;
415 _scene.TaintedObject("BSPrim.setVelocity", delegate() 410 _scene.TaintedObject("BSPrim.setVelocity", delegate()
416 { 411 {
417 // DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity); 412 DetailLog("{0},BSPrim.SetVelocity,taint,vel={1}", LocalID, _velocity);
418 BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity); 413 BulletSimAPI.SetObjectVelocity(_scene.WorldID, LocalID, _velocity);
419 }); 414 });
420 } 415 }
@@ -422,7 +417,7 @@ public sealed class BSPrim : PhysicsActor
422 public override OMV.Vector3 Torque { 417 public override OMV.Vector3 Torque {
423 get { return _torque; } 418 get { return _torque; }
424 set { _torque = value; 419 set { _torque = value;
425 // DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque); 420 DetailLog("{0},BSPrim.SetTorque,call,torque={1}", LocalID, _torque);
426 } 421 }
427 } 422 }
428 public override float CollisionScore { 423 public override float CollisionScore {
@@ -449,7 +444,7 @@ public sealed class BSPrim : PhysicsActor
449 _scene.TaintedObject("BSPrim.setOrientation", delegate() 444 _scene.TaintedObject("BSPrim.setOrientation", delegate()
450 { 445 {
451 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); 446 // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID);
452 // DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation); 447 DetailLog("{0},BSPrim.setOrientation,taint,pos={1},orient={2}", LocalID, _position, _orientation);
453 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); 448 BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation);
454 }); 449 });
455 } 450 }
@@ -501,13 +496,15 @@ public sealed class BSPrim : PhysicsActor
501 _linkset.Refresh(this); 496 _linkset.Refresh(this);
502 497
503 CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr); 498 CollisionFlags cf = BulletSimAPI.GetCollisionFlags2(Body.Ptr);
504 // DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf); 499 DetailLog("{0},BSPrim.SetObjectDynamic,taint,static={1},solid={2},mass={3}, cf={4}", LocalID, IsStatic, IsSolid, mass, cf);
505 } 500 }
506 501
507 // prims don't fly 502 // prims don't fly
508 public override bool Flying { 503 public override bool Flying {
509 get { return _flying; } 504 get { return _flying; }
510 set { _flying = value; } 505 set {
506 _flying = value;
507 }
511 } 508 }
512 public override bool SetAlwaysRun { 509 public override bool SetAlwaysRun {
513 get { return _setAlwaysRun; } 510 get { return _setAlwaysRun; }
@@ -558,7 +555,7 @@ public sealed class BSPrim : PhysicsActor
558 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity); 555 // m_log.DebugFormat("{0}: RotationalVelocity={1}", LogHeader, _rotationalVelocity);
559 _scene.TaintedObject("BSPrim.setRotationalVelocity", delegate() 556 _scene.TaintedObject("BSPrim.setRotationalVelocity", delegate()
560 { 557 {
561 // DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity); 558 DetailLog("{0},BSPrim.SetRotationalVel,taint,rotvel={1}", LocalID, _rotationalVelocity);
562 BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity); 559 BulletSimAPI.SetObjectAngularVelocity(_scene.WorldID, LocalID, _rotationalVelocity);
563 }); 560 });
564 } 561 }
@@ -575,7 +572,7 @@ public sealed class BSPrim : PhysicsActor
575 _buoyancy = value; 572 _buoyancy = value;
576 _scene.TaintedObject("BSPrim.setBuoyancy", delegate() 573 _scene.TaintedObject("BSPrim.setBuoyancy", delegate()
577 { 574 {
578 // DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 575 DetailLog("{0},BSPrim.SetBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
579 BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy); 576 BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, _localID, _buoyancy);
580 }); 577 });
581 } 578 }
@@ -638,17 +635,17 @@ public sealed class BSPrim : PhysicsActor
638 } 635 }
639 m_accumulatedForces.Clear(); 636 m_accumulatedForces.Clear();
640 } 637 }
641 // DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force); 638 DetailLog("{0},BSPrim.AddObjectForce,taint,force={1}", LocalID, _force);
642 BulletSimAPI.AddObjectForce2(Body.Ptr, fSum); 639 BulletSimAPI.AddObjectForce2(Body.Ptr, fSum);
643 }); 640 });
644 } 641 }
645 642
646 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { 643 public override void AddAngularForce(OMV.Vector3 force, bool pushforce) {
647 // DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce); 644 DetailLog("{0},BSPrim.AddAngularForce,call,angForce={1},push={2}", LocalID, force, pushforce);
648 // 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);
649 } 646 }
650 public override void SetMomentum(OMV.Vector3 momentum) { 647 public override void SetMomentum(OMV.Vector3 momentum) {
651 // DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum); 648 DetailLog("{0},BSPrim.SetMomentum,call,mom={1}", LocalID, momentum);
652 } 649 }
653 public override void SubscribeEvents(int ms) { 650 public override void SubscribeEvents(int ms) {
654 _subscribedEventsMs = ms; 651 _subscribedEventsMs = ms;
@@ -992,7 +989,7 @@ public sealed class BSPrim : PhysicsActor
992 // 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);
993 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE)) 990 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_SPHERE))
994 { 991 {
995 // DetailLog("{0},BSPrim.CreateGeom,sphere (force={1}", LocalID, forceRebuild); 992 DetailLog("{0},BSPrim.CreateGeom,sphere (force={1}", LocalID, forceRebuild);
996 _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE; 993 _shapeType = ShapeData.PhysicsShapeType.SHAPE_SPHERE;
997 // 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
998 _scale = _size; 995 _scale = _size;
@@ -1006,7 +1003,7 @@ public sealed class BSPrim : PhysicsActor
1006 // 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);
1007 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_BOX)) 1004 if (forceRebuild || (_shapeType != ShapeData.PhysicsShapeType.SHAPE_BOX))
1008 { 1005 {
1009 // DetailLog("{0},BSPrim.CreateGeom,box (force={1})", LocalID, forceRebuild); 1006 DetailLog("{0},BSPrim.CreateGeom,box (force={1})", LocalID, forceRebuild);
1010 _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX; 1007 _shapeType = ShapeData.PhysicsShapeType.SHAPE_BOX;
1011 _scale = _size; 1008 _scale = _size;
1012 // 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?
@@ -1042,19 +1039,26 @@ public sealed class BSPrim : PhysicsActor
1042 // No locking here because this is done when we know physics is not simulating 1039 // No locking here because this is done when we know physics is not simulating
1043 private void CreateGeomMesh() 1040 private void CreateGeomMesh()
1044 { 1041 {
1045 float lod = _pbs.SculptEntry ? _scene.SculptLOD : _scene.MeshLOD; 1042 // level of detail based on size and type of the object
1043 float lod = _scene.MeshLOD;
1044 if (_pbs.SculptEntry)
1045 lod = _scene.SculptLOD;
1046 float maxAxis = Math.Max(_size.X, Math.Max(_size.Y, _size.Z));
1047 if (maxAxis > _scene.MeshMegaPrimThreshold)
1048 lod = _scene.MeshMegaPrimLOD;
1049
1046 ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod); 1050 ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod);
1047 // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey); 1051 // m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey);
1048 1052
1049 // if this new shape is the same as last time, don't recreate the mesh 1053 // if this new shape is the same as last time, don't recreate the mesh
1050 if (_meshKey == newMeshKey) return; 1054 if (_meshKey == newMeshKey) return;
1051 1055
1052 // DetailLog("{0},BSPrim.CreateGeomMesh,create,key={1}", LocalID, newMeshKey); 1056 DetailLog("{0},BSPrim.CreateGeomMesh,create,key={1}", LocalID, newMeshKey);
1053 // Since we're recreating new, get rid of any previously generated shape 1057 // Since we're recreating new, get rid of any previously generated shape
1054 if (_meshKey != 0) 1058 if (_meshKey != 0)
1055 { 1059 {
1056 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey); 1060 // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey);
1057 // DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey); 1061 DetailLog("{0},BSPrim.CreateGeomMesh,deleteOld,key={1}", LocalID, _meshKey);
1058 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); 1062 BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey);
1059 _mesh = null; 1063 _mesh = null;
1060 _meshKey = 0; 1064 _meshKey = 0;
@@ -1084,7 +1088,7 @@ public sealed class BSPrim : PhysicsActor
1084 _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH; 1088 _shapeType = ShapeData.PhysicsShapeType.SHAPE_MESH;
1085 // meshes are already scaled by the meshmerizer 1089 // meshes are already scaled by the meshmerizer
1086 _scale = new OMV.Vector3(1f, 1f, 1f); 1090 _scale = new OMV.Vector3(1f, 1f, 1f);
1087 // DetailLog("{0},BSPrim.CreateGeomMesh,done", LocalID); 1091 DetailLog("{0},BSPrim.CreateGeomMesh,done", LocalID);
1088 return; 1092 return;
1089 } 1093 }
1090 1094
@@ -1098,13 +1102,13 @@ public sealed class BSPrim : PhysicsActor
1098 // if the hull hasn't changed, don't rebuild it 1102 // if the hull hasn't changed, don't rebuild it
1099 if (newHullKey == _hullKey) return; 1103 if (newHullKey == _hullKey) return;
1100 1104
1101 // DetailLog("{0},BSPrim.CreateGeomHull,create,oldKey={1},newKey={2}", LocalID, _hullKey, newHullKey); 1105 DetailLog("{0},BSPrim.CreateGeomHull,create,oldKey={1},newKey={2}", LocalID, _hullKey, newHullKey);
1102 1106
1103 // Since we're recreating new, get rid of any previously generated shape 1107 // Since we're recreating new, get rid of any previously generated shape
1104 if (_hullKey != 0) 1108 if (_hullKey != 0)
1105 { 1109 {
1106 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey); 1110 // m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _hullKey);
1107 // DetailLog("{0},BSPrim.CreateGeomHull,deleteOldHull,key={1}", LocalID, _hullKey); 1111 DetailLog("{0},BSPrim.CreateGeomHull,deleteOldHull,key={1}", LocalID, _hullKey);
1108 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey); 1112 BulletSimAPI.DestroyHull(_scene.WorldID, _hullKey);
1109 _hullKey = 0; 1113 _hullKey = 0;
1110 } 1114 }
@@ -1198,7 +1202,7 @@ public sealed class BSPrim : PhysicsActor
1198 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL; 1202 _shapeType = ShapeData.PhysicsShapeType.SHAPE_HULL;
1199 // meshes are already scaled by the meshmerizer 1203 // meshes are already scaled by the meshmerizer
1200 _scale = new OMV.Vector3(1f, 1f, 1f); 1204 _scale = new OMV.Vector3(1f, 1f, 1f);
1201 // DetailLog("{0},BSPrim.CreateGeomHull,done", LocalID); 1205 DetailLog("{0},BSPrim.CreateGeomHull,done", LocalID);
1202 return; 1206 return;
1203 } 1207 }
1204 1208