aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODEPrim.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs90
1 files changed, 81 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index a41c856..b2c2d8a 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -63,6 +63,9 @@ namespace OpenSim.Region.Physics.OdePlugin
63 63
64 private bool m_isphysical; 64 private bool m_isphysical;
65 65
66 public int ExpectedCollisionContacts { get { return m_expectedCollisionContacts; } }
67 private int m_expectedCollisionContacts = 0;
68
66 /// <summary> 69 /// <summary>
67 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes. 70 /// Is this prim subject to physics? Even if not, it's still solid for collision purposes.
68 /// </summary> 71 /// </summary>
@@ -97,6 +100,9 @@ namespace OpenSim.Region.Physics.OdePlugin
97 private Vector3 m_taintAngularLock = Vector3.One; 100 private Vector3 m_taintAngularLock = Vector3.One;
98 private IntPtr Amotor = IntPtr.Zero; 101 private IntPtr Amotor = IntPtr.Zero;
99 102
103 private object m_assetsLock = new object();
104 private bool m_assetFailed = false;
105
100 private Vector3 m_PIDTarget; 106 private Vector3 m_PIDTarget;
101 private float m_PIDTau; 107 private float m_PIDTau;
102 private float PID_D = 35f; 108 private float PID_D = 35f;
@@ -279,6 +285,7 @@ namespace OpenSim.Region.Physics.OdePlugin
279 } 285 }
280 286
281 m_taintadd = true; 287 m_taintadd = true;
288 m_assetFailed = false;
282 _parent_scene.AddPhysicsActorTaint(this); 289 _parent_scene.AddPhysicsActorTaint(this);
283 } 290 }
284 291
@@ -601,8 +608,8 @@ namespace OpenSim.Region.Physics.OdePlugin
601 break; 608 break;
602 609
603 case HollowShape.Circle: 610 case HollowShape.Circle:
604 // Hollow shape is a perfect cylinder in respect to the cube's scale 611 // Hollow shape is a perfect cyllinder in respect to the cube's scale
605 // Cylinder hollow volume calculation 612 // Cyllinder hollow volume calculation
606 613
607 hollowVolume *= 0.1963495f * 3.07920140172638f; 614 hollowVolume *= 0.1963495f * 3.07920140172638f;
608 break; 615 break;
@@ -840,7 +847,7 @@ namespace OpenSim.Region.Physics.OdePlugin
840 int vertexStride, triStride; 847 int vertexStride, triStride;
841 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap 848 mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap
842 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage 849 mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
843 850 m_expectedCollisionContacts = indexCount;
844 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory 851 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
845 852
846 // We must lock here since m_MeshToTriMeshMap is static and multiple scene threads may call this method at 853 // We must lock here since m_MeshToTriMeshMap is static and multiple scene threads may call this method at
@@ -1377,6 +1384,7 @@ Console.WriteLine("CreateGeom:");
1377 { 1384 {
1378//Console.WriteLine(" CreateGeom 1"); 1385//Console.WriteLine(" CreateGeom 1");
1379 SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2)); 1386 SetGeom(d.CreateSphere(m_targetSpace, _size.X / 2));
1387 m_expectedCollisionContacts = 3;
1380 } 1388 }
1381 catch (AccessViolationException) 1389 catch (AccessViolationException)
1382 { 1390 {
@@ -1391,6 +1399,7 @@ Console.WriteLine("CreateGeom:");
1391 { 1399 {
1392//Console.WriteLine(" CreateGeom 2"); 1400//Console.WriteLine(" CreateGeom 2");
1393 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); 1401 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
1402 m_expectedCollisionContacts = 4;
1394 } 1403 }
1395 catch (AccessViolationException) 1404 catch (AccessViolationException)
1396 { 1405 {
@@ -1406,6 +1415,7 @@ Console.WriteLine("CreateGeom:");
1406 { 1415 {
1407//Console.WriteLine(" CreateGeom 3"); 1416//Console.WriteLine(" CreateGeom 3");
1408 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); 1417 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
1418 m_expectedCollisionContacts = 4;
1409 } 1419 }
1410 catch (AccessViolationException) 1420 catch (AccessViolationException)
1411 { 1421 {
@@ -1421,6 +1431,7 @@ Console.WriteLine("CreateGeom:");
1421 { 1431 {
1422//Console.WriteLine(" CreateGeom 4"); 1432//Console.WriteLine(" CreateGeom 4");
1423 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z)); 1433 SetGeom(d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z));
1434 m_expectedCollisionContacts = 4;
1424 } 1435 }
1425 catch (AccessViolationException) 1436 catch (AccessViolationException)
1426 { 1437 {
@@ -1446,11 +1457,13 @@ Console.WriteLine("CreateGeom:");
1446 _parent_scene.geom_name_map.Remove(prim_geom); 1457 _parent_scene.geom_name_map.Remove(prim_geom);
1447 _parent_scene.actor_name_map.Remove(prim_geom); 1458 _parent_scene.actor_name_map.Remove(prim_geom);
1448 d.GeomDestroy(prim_geom); 1459 d.GeomDestroy(prim_geom);
1460 m_expectedCollisionContacts = 0;
1449 prim_geom = IntPtr.Zero; 1461 prim_geom = IntPtr.Zero;
1450 } 1462 }
1451 catch (System.AccessViolationException) 1463 catch (System.AccessViolationException)
1452 { 1464 {
1453 prim_geom = IntPtr.Zero; 1465 prim_geom = IntPtr.Zero;
1466 m_expectedCollisionContacts = 0;
1454 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name); 1467 m_log.ErrorFormat("[PHYSICS]: PrimGeom dead for {0}", Name);
1455 1468
1456 return false; 1469 return false;
@@ -1489,6 +1502,8 @@ Console.WriteLine("CreateGeom:");
1489 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); 1502 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
1490 // createmesh returns null when it's a shape that isn't a cube. 1503 // createmesh returns null when it's a shape that isn't a cube.
1491 // m_log.Debug(m_localID); 1504 // m_log.Debug(m_localID);
1505 if (mesh == null)
1506 CheckMeshAsset();
1492 } 1507 }
1493 1508
1494#if SPAM 1509#if SPAM
@@ -1988,7 +2003,12 @@ Console.WriteLine(" JointCreateFixed");
1988 // Don't need to re-enable body.. it's done in SetMesh 2003 // Don't need to re-enable body.. it's done in SetMesh
1989 2004
1990 if (_parent_scene.needsMeshing(_pbs)) 2005 if (_parent_scene.needsMeshing(_pbs))
2006 {
1991 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical); 2007 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical);
2008 if (mesh == null)
2009 CheckMeshAsset();
2010 }
2011
1992 } 2012 }
1993 2013
1994 CreateGeom(m_targetSpace, mesh); 2014 CreateGeom(m_targetSpace, mesh);
@@ -2048,6 +2068,8 @@ Console.WriteLine(" JointCreateFixed");
2048 /// </summary> 2068 /// </summary>
2049 private void changeshape() 2069 private void changeshape()
2050 { 2070 {
2071 m_taintshape = false;
2072
2051 // Cleanup of old prim geometry and Bodies 2073 // Cleanup of old prim geometry and Bodies
2052 if (IsPhysical && Body != IntPtr.Zero) 2074 if (IsPhysical && Body != IntPtr.Zero)
2053 { 2075 {
@@ -2075,6 +2097,7 @@ Console.WriteLine(" JointCreateFixed");
2075 2097
2076 IMesh mesh = null; 2098 IMesh mesh = null;
2077 2099
2100
2078 if (_parent_scene.needsMeshing(_pbs)) 2101 if (_parent_scene.needsMeshing(_pbs))
2079 { 2102 {
2080 // Don't need to re-enable body.. it's done in CreateMesh 2103 // Don't need to re-enable body.. it's done in CreateMesh
@@ -2085,6 +2108,8 @@ Console.WriteLine(" JointCreateFixed");
2085 2108
2086 // createmesh returns null when it doesn't mesh. 2109 // createmesh returns null when it doesn't mesh.
2087 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical); 2110 mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, meshlod, IsPhysical);
2111 if (mesh == null)
2112 CheckMeshAsset();
2088 } 2113 }
2089 2114
2090 CreateGeom(m_targetSpace, mesh); 2115 CreateGeom(m_targetSpace, mesh);
@@ -2121,7 +2146,7 @@ Console.WriteLine(" JointCreateFixed");
2121 } 2146 }
2122 2147
2123 resetCollisionAccounting(); 2148 resetCollisionAccounting();
2124 m_taintshape = false; 2149// m_taintshape = false;
2125 } 2150 }
2126 2151
2127 /// <summary> 2152 /// <summary>
@@ -2387,6 +2412,7 @@ Console.WriteLine(" JointCreateFixed");
2387 set 2412 set
2388 { 2413 {
2389 _pbs = value; 2414 _pbs = value;
2415 m_assetFailed = false;
2390 m_taintshape = true; 2416 m_taintshape = true;
2391 } 2417 }
2392 } 2418 }
@@ -2395,15 +2421,15 @@ Console.WriteLine(" JointCreateFixed");
2395 { 2421 {
2396 get 2422 get
2397 { 2423 {
2398 // Averate previous velocity with the new one so 2424 // Average previous velocity with the new one so
2399 // client object interpolation works a 'little' better 2425 // client object interpolation works a 'little' better
2400 if (_zeroFlag) 2426 if (_zeroFlag)
2401 return Vector3.Zero; 2427 return Vector3.Zero;
2402 2428
2403 Vector3 returnVelocity = Vector3.Zero; 2429 Vector3 returnVelocity = Vector3.Zero;
2404 returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2; 2430 returnVelocity.X = (m_lastVelocity.X + _velocity.X) * 0.5f; // 0.5f is mathematically equiv to '/ 2'
2405 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2; 2431 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) * 0.5f;
2406 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2; 2432 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) * 0.5f;
2407 return returnVelocity; 2433 return returnVelocity;
2408 } 2434 }
2409 set 2435 set
@@ -2600,6 +2626,7 @@ Console.WriteLine(" JointCreateFixed");
2600 { 2626 {
2601 Vector3 pv = Vector3.Zero; 2627 Vector3 pv = Vector3.Zero;
2602 bool lastZeroFlag = _zeroFlag; 2628 bool lastZeroFlag = _zeroFlag;
2629 float m_minvelocity = 0;
2603 if (Body != (IntPtr)0) // FIXME -> or if it is a joint 2630 if (Body != (IntPtr)0) // FIXME -> or if it is a joint
2604 { 2631 {
2605 d.Vector3 vec = d.BodyGetPosition(Body); 2632 d.Vector3 vec = d.BodyGetPosition(Body);
@@ -2752,8 +2779,21 @@ Console.WriteLine(" JointCreateFixed");
2752 _acceleration = ((_velocity - m_lastVelocity) / 0.1f); 2779 _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
2753 _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f); 2780 _acceleration = new Vector3(_velocity.X - m_lastVelocity.X / 0.1f, _velocity.Y - m_lastVelocity.Y / 0.1f, _velocity.Z - m_lastVelocity.Z / 0.1f);
2754 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); 2781 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2782
2783 // Note here that linearvelocity is affecting angular velocity... so I'm guessing this is a vehicle specific thing...
2784 // it does make sense to do this for tiny little instabilities with physical prim, however 0.5m/frame is fairly large.
2785 // reducing this to 0.02m/frame seems to help the angular rubberbanding quite a bit, however, to make sure it doesn't affect elevators and vehicles
2786 // adding these logical exclusion situations to maintain this where I think it was intended to be.
2787 if (m_throttleUpdates || m_usePID || (m_vehicle != null && m_vehicle.Type != Vehicle.TYPE_NONE) || (Amotor != IntPtr.Zero))
2788 {
2789 m_minvelocity = 0.5f;
2790 }
2791 else
2792 {
2793 m_minvelocity = 0.02f;
2794 }
2755 2795
2756 if (_velocity.ApproxEquals(pv, 0.5f)) 2796 if (_velocity.ApproxEquals(pv, m_minvelocity))
2757 { 2797 {
2758 m_rotationalVelocity = pv; 2798 m_rotationalVelocity = pv;
2759 } 2799 }
@@ -3211,5 +3251,37 @@ Console.WriteLine(" JointCreateFixed");
3211 { 3251 {
3212 m_material = pMaterial; 3252 m_material = pMaterial;
3213 } 3253 }
3254
3255
3256 private void CheckMeshAsset()
3257 {
3258 if (_pbs.SculptEntry && !m_assetFailed && _pbs.SculptTexture != UUID.Zero)
3259 {
3260 m_assetFailed = true;
3261 Util.FireAndForget(delegate
3262 {
3263 RequestAssetDelegate assetProvider = _parent_scene.RequestAssetMethod;
3264 if (assetProvider != null)
3265 assetProvider(_pbs.SculptTexture, MeshAssetReveived);
3266 });
3267 }
3268 }
3269
3270 void MeshAssetReveived(AssetBase asset)
3271 {
3272 if (asset.Data != null && asset.Data.Length > 0)
3273 {
3274 if (!_pbs.SculptEntry)
3275 return;
3276 if (_pbs.SculptTexture.ToString() != asset.ID)
3277 return;
3278
3279 _pbs.SculptData = new byte[asset.Data.Length];
3280 asset.Data.CopyTo(_pbs.SculptData, 0);
3281 m_assetFailed = false;
3282 m_taintshape = true;
3283 _parent_scene.AddPhysicsActorTaint(this);
3284 }
3285 }
3214 } 3286 }
3215} \ No newline at end of file 3287} \ No newline at end of file