aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs23
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs92
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdeScene.cs77
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs7
4 files changed, 142 insertions, 57 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 123c8ff..b3045bd 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -638,7 +638,7 @@ namespace OpenSim.Region.Physics.OdePlugin
638 float profileEnd; 638 float profileEnd;
639 639
640 if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible) 640 if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
641 { 641 {
642 taperX1 = _pbs.PathScaleX * 0.01f; 642 taperX1 = _pbs.PathScaleX * 0.01f;
643 if (taperX1 > 1.0f) 643 if (taperX1 > 1.0f)
644 taperX1 = 2.0f - taperX1; 644 taperX1 = 2.0f - taperX1;
@@ -648,9 +648,9 @@ namespace OpenSim.Region.Physics.OdePlugin
648 if (taperY1 > 1.0f) 648 if (taperY1 > 1.0f)
649 taperY1 = 2.0f - taperY1; 649 taperY1 = 2.0f - taperY1;
650 taperY = 1.0f - taperY1; 650 taperY = 1.0f - taperY1;
651 } 651 }
652 else 652 else
653 { 653 {
654 taperX = _pbs.PathTaperX * 0.01f; 654 taperX = _pbs.PathTaperX * 0.01f;
655 if (taperX < 0.0f) 655 if (taperX < 0.0f)
656 taperX = -taperX; 656 taperX = -taperX;
@@ -660,9 +660,7 @@ namespace OpenSim.Region.Physics.OdePlugin
660 if (taperY < 0.0f) 660 if (taperY < 0.0f)
661 taperY = -taperY; 661 taperY = -taperY;
662 taperY1 = 1.0f - taperY; 662 taperY1 = 1.0f - taperY;
663 663 }
664 }
665
666 664
667 volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY); 665 volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
668 666
@@ -846,7 +844,6 @@ namespace OpenSim.Region.Physics.OdePlugin
846 return; 844 return;
847 } 845 }
848 846
849
850 // if (IsPhysical && Body == (IntPtr) 0) 847 // if (IsPhysical && Body == (IntPtr) 0)
851 // { 848 // {
852 // Recreate the body 849 // Recreate the body
@@ -859,7 +856,9 @@ namespace OpenSim.Region.Physics.OdePlugin
859 856
860 public void ProcessTaints(float timestep) 857 public void ProcessTaints(float timestep)
861 { 858 {
862//Console.WriteLine("ProcessTaints for " + Name); 859#if SPAM
860Console.WriteLine("ZProcessTaints for " + Name);
861#endif
863 if (m_taintadd) 862 if (m_taintadd)
864 { 863 {
865 changeadd(timestep); 864 changeadd(timestep);
@@ -1323,7 +1322,9 @@ namespace OpenSim.Region.Physics.OdePlugin
1323 1322
1324 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh) 1323 public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh)
1325 { 1324 {
1326//Console.WriteLine("CreateGeom:"); 1325#if SPAM
1326Console.WriteLine("CreateGeom:");
1327#endif
1327 if (_mesh != null) 1328 if (_mesh != null)
1328 { 1329 {
1329 setMesh(_parent_scene, _mesh); 1330 setMesh(_parent_scene, _mesh);
@@ -1944,7 +1945,6 @@ Console.WriteLine(" JointCreateFixed");
1944 if (_parent_scene.needsMeshing(_pbs)) 1945 if (_parent_scene.needsMeshing(_pbs))
1945 mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical); 1946 mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
1946 1947
1947 //IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
1948#if SPAM 1948#if SPAM
1949Console.WriteLine("changesize 1"); 1949Console.WriteLine("changesize 1");
1950#endif 1950#endif
@@ -2056,8 +2056,8 @@ Console.WriteLine("changesize 2");
2056 if (IsPhysical) 2056 if (IsPhysical)
2057 meshlod = _parent_scene.MeshSculptphysicalLOD; 2057 meshlod = _parent_scene.MeshSculptphysicalLOD;
2058 2058
2059 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
2060 // createmesh returns null when it doesn't mesh. 2059 // createmesh returns null when it doesn't mesh.
2060 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
2061#if SPAM 2061#if SPAM
2062Console.WriteLine("changeshape needed meshing"); 2062Console.WriteLine("changeshape needed meshing");
2063#endif 2063#endif
@@ -2284,6 +2284,7 @@ Console.WriteLine("changeshape not need meshing");
2284 if (value.IsFinite()) 2284 if (value.IsFinite())
2285 { 2285 {
2286 _size = value; 2286 _size = value;
2287// m_log.DebugFormat("[PHYSICS]: Set size on {0} to {1}", Name, value);
2287 } 2288 }
2288 else 2289 else
2289 { 2290 {
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
index ba77dae..6c2bdde 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
@@ -45,11 +45,16 @@ namespace OpenSim.Region.Physics.OdePlugin
45 public class ODERayCastRequestManager 45 public class ODERayCastRequestManager
46 { 46 {
47 /// <summary> 47 /// <summary>
48 /// Pending Raycast Requests 48 /// Pending raycast requests
49 /// </summary> 49 /// </summary>
50 protected List<ODERayCastRequest> m_PendingRequests = new List<ODERayCastRequest>(); 50 protected List<ODERayCastRequest> m_PendingRequests = new List<ODERayCastRequest>();
51 51
52 /// <summary> 52 /// <summary>
53 /// Pending ray requests
54 /// </summary>
55 protected List<ODERayRequest> m_PendingRayRequests = new List<ODERayRequest>();
56
57 /// <summary>
53 /// Scene that created this object. 58 /// Scene that created this object.
54 /// </summary> 59 /// </summary>
55 private OdeScene m_scene; 60 private OdeScene m_scene;
@@ -96,6 +101,29 @@ namespace OpenSim.Region.Physics.OdePlugin
96 } 101 }
97 102
98 /// <summary> 103 /// <summary>
104 /// Queues a raycast
105 /// </summary>
106 /// <param name="position">Origin of Ray</param>
107 /// <param name="direction">Ray normal</param>
108 /// <param name="length">Ray length</param>
109 /// <param name="count"></param>
110 /// <param name="retMethod">Return method to send the results</param>
111 public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
112 {
113 lock (m_PendingRequests)
114 {
115 ODERayRequest req = new ODERayRequest();
116 req.callbackMethod = retMethod;
117 req.length = length;
118 req.Normal = direction;
119 req.Origin = position;
120 req.Count = count;
121
122 m_PendingRayRequests.Add(req);
123 }
124 }
125
126 /// <summary>
99 /// Process all queued raycast requests 127 /// Process all queued raycast requests
100 /// </summary> 128 /// </summary>
101 /// <returns>Time in MS the raycasts took to process.</returns> 129 /// <returns>Time in MS the raycasts took to process.</returns>
@@ -112,15 +140,23 @@ namespace OpenSim.Region.Physics.OdePlugin
112 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast 140 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
113 RayCast(reqs[i]); // if there isn't anyone to send results 141 RayCast(reqs[i]); // if there isn't anyone to send results
114 } 142 }
115 /* 143
116 foreach (ODERayCastRequest req in m_PendingRequests) 144 m_PendingRequests.Clear();
145 }
146 }
147
148 lock (m_PendingRayRequests)
149 {
150 if (m_PendingRayRequests.Count > 0)
151 {
152 ODERayRequest[] reqs = m_PendingRayRequests.ToArray();
153 for (int i = 0; i < reqs.Length; i++)
117 { 154 {
118 if (req.callbackMethod != null) // quick optimization here, don't raycast 155 if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
119 RayCast(req); // if there isn't anyone to send results to 156 RayCast(reqs[i]); // if there isn't anyone to send results
120
121 } 157 }
122 */ 158
123 m_PendingRequests.Clear(); 159 m_PendingRayRequests.Clear();
124 } 160 }
125 } 161 }
126 162
@@ -146,7 +182,6 @@ namespace OpenSim.Region.Physics.OdePlugin
146 // Remove Ray 182 // Remove Ray
147 d.GeomDestroy(ray); 183 d.GeomDestroy(ray);
148 184
149
150 // Define default results 185 // Define default results
151 bool hitYN = false; 186 bool hitYN = false;
152 uint hitConsumerID = 0; 187 uint hitConsumerID = 0;
@@ -177,6 +212,31 @@ namespace OpenSim.Region.Physics.OdePlugin
177 req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal); 212 req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal);
178 } 213 }
179 214
215 /// <summary>
216 /// Method that actually initiates the raycast
217 /// </summary>
218 /// <param name="req"></param>
219 private void RayCast(ODERayRequest req)
220 {
221 // Create the ray
222 IntPtr ray = d.CreateRay(m_scene.space, req.length);
223 d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
224
225 // Collide test
226 d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
227
228 // Remove Ray
229 d.GeomDestroy(ray);
230
231 // Find closest contact and object.
232 lock (m_contactResults)
233 {
234 // Return results
235 if (req.callbackMethod != null)
236 req.callbackMethod(m_contactResults);
237 }
238 }
239
180 // This is the standard Near. Uses space AABBs to speed up detection. 240 // This is the standard Near. Uses space AABBs to speed up detection.
181 private void near(IntPtr space, IntPtr g1, IntPtr g2) 241 private void near(IntPtr space, IntPtr g1, IntPtr g2)
182 { 242 {
@@ -342,10 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
342 m_contactResults.Add(collisionresult); 402 m_contactResults.Add(collisionresult);
343 } 403 }
344 } 404 }
345
346
347 } 405 }
348
349 } 406 }
350 407
351 /// <summary> 408 /// <summary>
@@ -365,11 +422,12 @@ namespace OpenSim.Region.Physics.OdePlugin
365 public RaycastCallback callbackMethod; 422 public RaycastCallback callbackMethod;
366 } 423 }
367 424
368 public struct ContactResult 425 public struct ODERayRequest
369 { 426 {
370 public Vector3 Pos; 427 public Vector3 Origin;
371 public float Depth;
372 public uint ConsumerID;
373 public Vector3 Normal; 428 public Vector3 Normal;
429 public int Count;
430 public float length;
431 public RayCallback callbackMethod;
374 } 432 }
375} 433} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
index 99392cc..a307469 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdeScene.cs
@@ -1677,7 +1677,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1677 } 1677 }
1678 1678
1679 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation, 1679 private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
1680 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) 1680 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical, uint localID)
1681 { 1681 {
1682 Vector3 pos = position; 1682 Vector3 pos = position;
1683 Vector3 siz = size; 1683 Vector3 siz = size;
@@ -1691,7 +1691,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1691 lock (_prims) 1691 lock (_prims)
1692 _prims.Add(newPrim); 1692 _prims.Add(newPrim);
1693 } 1693 }
1694 1694 newPrim.LocalID = localID;
1695 return newPrim; 1695 return newPrim;
1696 } 1696 }
1697 1697
@@ -1708,13 +1708,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1708 } 1708 }
1709 1709
1710 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, 1710 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1711 Vector3 size, Quaternion rotation) //To be removed 1711 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
1712 {
1713 return AddPrimShape(primName, pbs, position, size, rotation, false);
1714 }
1715
1716 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1717 Vector3 size, Quaternion rotation, bool isPhysical)
1718 { 1712 {
1719#if SPAM 1713#if SPAM
1720 m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName); 1714 m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName);
@@ -1723,22 +1717,23 @@ namespace OpenSim.Region.Physics.OdePlugin
1723 PhysicsActor result; 1717 PhysicsActor result;
1724 IMesh mesh = null; 1718 IMesh mesh = null;
1725 1719
1726 if (needsMeshing(pbs)) 1720 // Don't create the mesh here - wait until the mesh data is loaded from the asset store.
1727 { 1721// if (needsMeshing(pbs))
1728 try 1722// {
1729 { 1723// try
1730 mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical); 1724// {
1731 } 1725// mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical);
1732 catch(Exception e) 1726// }
1733 { 1727// catch(Exception e)
1734 m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName); 1728// {
1735 m_log.Debug(e.ToString()); 1729// m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName);
1736 mesh = null; 1730// m_log.Debug(e.ToString());
1737 return null; 1731// mesh = null;
1738 } 1732// return null;
1739 } 1733// }
1740 1734// }
1741 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); 1735
1736 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical, localid);
1742 1737
1743 return result; 1738 return result;
1744 } 1739 }
@@ -2590,7 +2585,9 @@ namespace OpenSim.Region.Physics.OdePlugin
2590 { 2585 {
2591 if (!(_taintedPrimH.Contains(taintedprim))) 2586 if (!(_taintedPrimH.Contains(taintedprim)))
2592 { 2587 {
2593//Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.m_primName); 2588#if SPAM
2589Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
2590#endif
2594 _taintedPrimH.Add(taintedprim); // HashSet for searching 2591 _taintedPrimH.Add(taintedprim); // HashSet for searching
2595 _taintedPrimL.Add(taintedprim); // List for ordered readout 2592 _taintedPrimL.Add(taintedprim); // List for ordered readout
2596 } 2593 }
@@ -3733,6 +3730,34 @@ namespace OpenSim.Region.Physics.OdePlugin
3733 } 3730 }
3734 } 3731 }
3735 3732
3733 public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
3734 {
3735 if (retMethod != null)
3736 {
3737 m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
3738 }
3739 }
3740
3741 public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
3742 {
3743 ContactResult[] ourResults = null;
3744 RayCallback retMethod = delegate(List<ContactResult> results)
3745 {
3746 ourResults = new ContactResult[results.Count];
3747 results.CopyTo(ourResults, 0);
3748 };
3749 int waitTime = 0;
3750 m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
3751 while (ourResults == null && waitTime < 1000)
3752 {
3753 Thread.Sleep(1);
3754 waitTime++;
3755 }
3756 if (ourResults == null)
3757 return new List<ContactResult> ();
3758 return new List<ContactResult>(ourResults);
3759 }
3760
3736#if USE_DRAWSTUFF 3761#if USE_DRAWSTUFF
3737 // Keyboard callback 3762 // Keyboard callback
3738 public void command(int cmd) 3763 public void command(int cmd)
diff --git a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs
index a7f8baa..2ea810f 100644
--- a/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Tests/ODETestClass.cs
@@ -31,17 +31,18 @@ using NUnit.Framework;
31using OpenMetaverse; 31using OpenMetaverse;
32using OpenSim.Framework; 32using OpenSim.Framework;
33using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
34using OpenSim.Region.Physics.OdePlugin;
34using log4net; 35using log4net;
35using System.Reflection; 36using System.Reflection;
36 37
37namespace OpenSim.Region.Physics.OdePlugin 38namespace OpenSim.Region.Physics.OdePlugin.Tests
38{ 39{
39 [TestFixture] 40 [TestFixture]
40 public class ODETestClass 41 public class ODETestClass
41 { 42 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 44
44 private OdePlugin cbt; 45 private OpenSim.Region.Physics.OdePlugin.OdePlugin cbt;
45 private PhysicsScene ps; 46 private PhysicsScene ps;
46 private IMeshingPlugin imp; 47 private IMeshingPlugin imp;
47 48
@@ -83,7 +84,7 @@ namespace OpenSim.Region.Physics.OdePlugin
83 Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f); 84 Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
84 Vector3 size = new Vector3(0.5f, 0.5f, 0.5f); 85 Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
85 Quaternion rot = Quaternion.Identity; 86 Quaternion rot = Quaternion.Identity;
86 PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true); 87 PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true, 0);
87 OdePrim oprim = (OdePrim)prim; 88 OdePrim oprim = (OdePrim)prim;
88 OdeScene pscene = (OdeScene) ps; 89 OdeScene pscene = (OdeScene) ps;
89 90