Merge branch 'master' into bulletsim

This commit is contained in:
Dan Lake
2011-07-20 15:01:32 -07:00
49 changed files with 1464 additions and 845 deletions

View File

@@ -84,13 +84,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
*/
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation)
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical)
Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
return null;
}

View File

@@ -213,12 +213,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
return newPrim;
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, Vector3 size, Quaternion rotation)
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical)
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
PhysicsActor result;
IMesh mesh = null;

View File

@@ -626,13 +626,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, OpenMetaverse.Vector3 position,
OpenMetaverse.Vector3 size, OpenMetaverse.Quaternion rotation)
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, OpenMetaverse.Vector3 position,
OpenMetaverse.Vector3 size, OpenMetaverse.Quaternion rotation, bool isPhysical)
OpenMetaverse.Vector3 size, OpenMetaverse.Quaternion rotation, bool isPhysical, uint localid)
{
PhysicsActor result;

View File

@@ -37,6 +37,18 @@ namespace OpenSim.Region.Physics.Manager
public delegate void physicsCrash();
public delegate void RaycastCallback(bool hitYN, Vector3 collisionPoint, uint localid, float distance, Vector3 normal);
public delegate void RayCallback(List<ContactResult> list);
/// <summary>
/// Contact result from a raycast.
/// </summary>
public struct ContactResult
{
public Vector3 Pos;
public float Depth;
public uint ConsumerID;
public Vector3 Normal;
}
public abstract class PhysicsScene
{
@@ -61,7 +73,6 @@ namespace OpenSim.Region.Physics.Manager
}
}
public abstract void Initialise(IMesher meshmerizer, IConfigSource config);
public abstract PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying);
@@ -78,20 +89,7 @@ namespace OpenSim.Region.Physics.Manager
public abstract void RemovePrim(PhysicsActor prim);
public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation); //To be removed
public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical);
public virtual PhysicsActor AddPrimShape(uint localID, string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical)
{
PhysicsActor ret = AddPrimShape(primName, pbs, position, size, rotation, isPhysical);
if (ret != null)
ret.LocalID = localID;
return ret;
}
Vector3 size, Quaternion rotation, bool isPhysical, uint localid);
public virtual float TimeDilation
{
@@ -225,6 +223,17 @@ namespace OpenSim.Region.Physics.Manager
retMethod(false, Vector3.Zero, 0, 999999999999f, Vector3.Zero);
}
public virtual void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
{
if (retMethod != null)
retMethod(new List<ContactResult>());
}
public virtual List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
{
return new List<ContactResult>();
}
private class NullPhysicsScene : PhysicsScene
{
private static int m_workIndicator;
@@ -262,13 +271,7 @@ namespace OpenSim.Region.Physics.Manager
*/
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation) //To be removed
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical)
Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
m_log.InfoFormat("[PHYSICS]: NullPhysicsScene : AddPrim({0},{1})", position, size);
return PhysicsActor.Null;

View File

@@ -303,6 +303,10 @@ namespace OpenSim.Region.Physics.Meshing
private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
{
// m_log.DebugFormat(
// "[MESH]: Creating physics proxy for {0}, shape {1}",
// primName, (OpenMetaverse.SculptType)primShape.SculptType);
PrimMesh primMesh;
PrimMesher.SculptMesh sculptMesh;
@@ -668,7 +672,6 @@ namespace OpenSim.Region.Physics.Meshing
// If this mesh has been created already, return it instead of creating another copy
// For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory
key = GetMeshKey(primShape, size, lod);
if (m_uniqueMeshes.TryGetValue(key, out mesh))
return mesh;

View File

@@ -638,7 +638,7 @@ namespace OpenSim.Region.Physics.OdePlugin
float profileEnd;
if (_pbs.PathCurve == (byte)Extrusion.Straight || _pbs.PathCurve == (byte)Extrusion.Flexible)
{
{
taperX1 = _pbs.PathScaleX * 0.01f;
if (taperX1 > 1.0f)
taperX1 = 2.0f - taperX1;
@@ -648,9 +648,9 @@ namespace OpenSim.Region.Physics.OdePlugin
if (taperY1 > 1.0f)
taperY1 = 2.0f - taperY1;
taperY = 1.0f - taperY1;
}
}
else
{
{
taperX = _pbs.PathTaperX * 0.01f;
if (taperX < 0.0f)
taperX = -taperX;
@@ -660,9 +660,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (taperY < 0.0f)
taperY = -taperY;
taperY1 = 1.0f - taperY;
}
}
volume *= (taperX1 * taperY1 + 0.5f * (taperX1 * taperY + taperX * taperY1) + 0.3333333333f * taperX * taperY);
@@ -846,7 +844,6 @@ namespace OpenSim.Region.Physics.OdePlugin
return;
}
// if (IsPhysical && Body == (IntPtr) 0)
// {
// Recreate the body
@@ -859,7 +856,9 @@ namespace OpenSim.Region.Physics.OdePlugin
public void ProcessTaints(float timestep)
{
//Console.WriteLine("ProcessTaints for " + Name);
#if SPAM
Console.WriteLine("ZProcessTaints for " + Name);
#endif
if (m_taintadd)
{
changeadd(timestep);
@@ -1323,7 +1322,9 @@ namespace OpenSim.Region.Physics.OdePlugin
public void CreateGeom(IntPtr m_targetSpace, IMesh _mesh)
{
//Console.WriteLine("CreateGeom:");
#if SPAM
Console.WriteLine("CreateGeom:");
#endif
if (_mesh != null)
{
setMesh(_parent_scene, _mesh);
@@ -1944,7 +1945,6 @@ Console.WriteLine(" JointCreateFixed");
if (_parent_scene.needsMeshing(_pbs))
mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
//IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
#if SPAM
Console.WriteLine("changesize 1");
#endif
@@ -2056,8 +2056,8 @@ Console.WriteLine("changesize 2");
if (IsPhysical)
meshlod = _parent_scene.MeshSculptphysicalLOD;
IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
// createmesh returns null when it doesn't mesh.
IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
#if SPAM
Console.WriteLine("changeshape needed meshing");
#endif
@@ -2284,6 +2284,7 @@ Console.WriteLine("changeshape not need meshing");
if (value.IsFinite())
{
_size = value;
// m_log.DebugFormat("[PHYSICS]: Set size on {0} to {1}", Name, value);
}
else
{

View File

@@ -45,10 +45,15 @@ namespace OpenSim.Region.Physics.OdePlugin
public class ODERayCastRequestManager
{
/// <summary>
/// Pending Raycast Requests
/// Pending raycast requests
/// </summary>
protected List<ODERayCastRequest> m_PendingRequests = new List<ODERayCastRequest>();
/// <summary>
/// Pending ray requests
/// </summary>
protected List<ODERayRequest> m_PendingRayRequests = new List<ODERayRequest>();
/// <summary>
/// Scene that created this object.
/// </summary>
@@ -95,6 +100,29 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
/// <summary>
/// Queues a raycast
/// </summary>
/// <param name="position">Origin of Ray</param>
/// <param name="direction">Ray normal</param>
/// <param name="length">Ray length</param>
/// <param name="count"></param>
/// <param name="retMethod">Return method to send the results</param>
public void QueueRequest(Vector3 position, Vector3 direction, float length, int count, RayCallback retMethod)
{
lock (m_PendingRequests)
{
ODERayRequest req = new ODERayRequest();
req.callbackMethod = retMethod;
req.length = length;
req.Normal = direction;
req.Origin = position;
req.Count = count;
m_PendingRayRequests.Add(req);
}
}
/// <summary>
/// Process all queued raycast requests
/// </summary>
@@ -112,18 +140,26 @@ namespace OpenSim.Region.Physics.OdePlugin
if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
RayCast(reqs[i]); // if there isn't anyone to send results
}
/*
foreach (ODERayCastRequest req in m_PendingRequests)
{
if (req.callbackMethod != null) // quick optimization here, don't raycast
RayCast(req); // if there isn't anyone to send results to
}
*/
m_PendingRequests.Clear();
}
}
lock (m_PendingRayRequests)
{
if (m_PendingRayRequests.Count > 0)
{
ODERayRequest[] reqs = m_PendingRayRequests.ToArray();
for (int i = 0; i < reqs.Length; i++)
{
if (reqs[i].callbackMethod != null) // quick optimization here, don't raycast
RayCast(reqs[i]); // if there isn't anyone to send results
}
m_PendingRayRequests.Clear();
}
}
lock (m_contactResults)
m_contactResults.Clear();
@@ -146,7 +182,6 @@ namespace OpenSim.Region.Physics.OdePlugin
// Remove Ray
d.GeomDestroy(ray);
// Define default results
bool hitYN = false;
uint hitConsumerID = 0;
@@ -177,6 +212,31 @@ namespace OpenSim.Region.Physics.OdePlugin
req.callbackMethod(hitYN, closestcontact, hitConsumerID, distance, snormal);
}
/// <summary>
/// Method that actually initiates the raycast
/// </summary>
/// <param name="req"></param>
private void RayCast(ODERayRequest req)
{
// Create the ray
IntPtr ray = d.CreateRay(m_scene.space, req.length);
d.GeomRaySet(ray, req.Origin.X, req.Origin.Y, req.Origin.Z, req.Normal.X, req.Normal.Y, req.Normal.Z);
// Collide test
d.SpaceCollide2(m_scene.space, ray, IntPtr.Zero, nearCallback);
// Remove Ray
d.GeomDestroy(ray);
// Find closest contact and object.
lock (m_contactResults)
{
// Return results
if (req.callbackMethod != null)
req.callbackMethod(m_contactResults);
}
}
// This is the standard Near. Uses space AABBs to speed up detection.
private void near(IntPtr space, IntPtr g1, IntPtr g2)
{
@@ -342,10 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_contactResults.Add(collisionresult);
}
}
}
}
/// <summary>
@@ -365,11 +422,12 @@ namespace OpenSim.Region.Physics.OdePlugin
public RaycastCallback callbackMethod;
}
public struct ContactResult
public struct ODERayRequest
{
public Vector3 Pos;
public float Depth;
public uint ConsumerID;
public Vector3 Origin;
public Vector3 Normal;
public int Count;
public float length;
public RayCallback callbackMethod;
}
}
}

View File

@@ -1677,7 +1677,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
IMesh mesh, PrimitiveBaseShape pbs, bool isphysical)
IMesh mesh, PrimitiveBaseShape pbs, bool isphysical, uint localID)
{
Vector3 pos = position;
Vector3 siz = size;
@@ -1691,7 +1691,7 @@ namespace OpenSim.Region.Physics.OdePlugin
lock (_prims)
_prims.Add(newPrim);
}
newPrim.LocalID = localID;
return newPrim;
}
@@ -1708,13 +1708,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation) //To be removed
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical)
Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
#if SPAM
m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName);
@@ -1723,22 +1717,23 @@ namespace OpenSim.Region.Physics.OdePlugin
PhysicsActor result;
IMesh mesh = null;
if (needsMeshing(pbs))
{
try
{
mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical);
}
catch(Exception e)
{
m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName);
m_log.Debug(e.ToString());
mesh = null;
return null;
}
}
// Don't create the mesh here - wait until the mesh data is loaded from the asset store.
// if (needsMeshing(pbs))
// {
// try
// {
// mesh = mesher.CreateMesh(primName, pbs, size, 32f, isPhysical);
// }
// catch(Exception e)
// {
// m_log.ErrorFormat("[PHYSICS]: Exception while meshing prim {0}.", primName);
// m_log.Debug(e.ToString());
// mesh = null;
// return null;
// }
// }
result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical);
result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical, localid);
return result;
}
@@ -2590,7 +2585,9 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (!(_taintedPrimH.Contains(taintedprim)))
{
//Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.m_primName);
#if SPAM
Console.WriteLine("AddPhysicsActorTaint to " + taintedprim.Name);
#endif
_taintedPrimH.Add(taintedprim); // HashSet for searching
_taintedPrimL.Add(taintedprim); // List for ordered readout
}
@@ -3733,6 +3730,34 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
public override void RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayCallback retMethod)
{
if (retMethod != null)
{
m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
}
}
public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
{
ContactResult[] ourResults = null;
RayCallback retMethod = delegate(List<ContactResult> results)
{
ourResults = new ContactResult[results.Count];
results.CopyTo(ourResults, 0);
};
int waitTime = 0;
m_rayCastManager.QueueRequest(position, direction, length, Count, retMethod);
while (ourResults == null && waitTime < 1000)
{
Thread.Sleep(1);
waitTime++;
}
if (ourResults == null)
return new List<ContactResult> ();
return new List<ContactResult>(ourResults);
}
#if USE_DRAWSTUFF
// Keyboard callback
public void command(int cmd)

View File

@@ -31,17 +31,18 @@ using NUnit.Framework;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
using OpenSim.Region.Physics.OdePlugin;
using log4net;
using System.Reflection;
namespace OpenSim.Region.Physics.OdePlugin
namespace OpenSim.Region.Physics.OdePlugin.Tests
{
[TestFixture]
public class ODETestClass
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private OdePlugin cbt;
private OpenSim.Region.Physics.OdePlugin.OdePlugin cbt;
private PhysicsScene ps;
private IMeshingPlugin imp;
@@ -83,7 +84,7 @@ namespace OpenSim.Region.Physics.OdePlugin
Vector3 position = new Vector3(((float)Constants.RegionSize * 0.5f), ((float)Constants.RegionSize * 0.5f), 128f);
Vector3 size = new Vector3(0.5f, 0.5f, 0.5f);
Quaternion rot = Quaternion.Identity;
PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true);
PhysicsActor prim = ps.AddPrimShape("CoolShape", newcube, position, size, rot, true, 0);
OdePrim oprim = (OdePrim)prim;
OdeScene pscene = (OdeScene) ps;

View File

@@ -91,13 +91,7 @@ namespace OpenSim.Region.Physics.POSPlugin
*/
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation)
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical)
Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
POSPrim prim = new POSPrim();
prim.Position = position;

View File

@@ -108,13 +108,7 @@ namespace OpenSim.Region.Physics.PhysXPlugin
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation) //To be removed
{
return AddPrimShape(primName, pbs, position, size, rotation, false);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical)
Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
return AddPrim(position, size, rotation);
}