UbitOde let caller try to build meshs like done in chode. Changing this was a bad move i made. Variable colisions softness.

avinationmerge
UbitUmarov 2012-03-24 16:04:13 +00:00
parent 21a97408d4
commit 88d5cb6eef
2 changed files with 3957 additions and 3883 deletions

View File

@ -130,9 +130,10 @@ namespace OpenSim.Region.Physics.OdePlugin
public bool m_disabled;
public uint m_localID;
private IMesh m_mesh;
private object m_meshlock = new object();
private PrimitiveBaseShape _pbs;
public OdeScene _parent_scene;
@ -484,6 +485,24 @@ namespace OpenSim.Region.Physics.OdePlugin
{
set
{
/*
IMesh mesh = null;
if (_parent_scene.needsMeshing(value))
{
bool convex;
if (m_shapetype == 0)
convex = false;
else
convex = true;
mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, (int)LevelOfDetail.High, true, convex);
}
if (mesh != null)
{
lock (m_meshlock)
m_mesh = mesh;
}
*/
AddChange(changes.Shape, value);
}
}
@ -950,6 +969,19 @@ namespace OpenSim.Region.Physics.OdePlugin
CalcPrimBodyData();
m_mesh = null;
if (_parent_scene.needsMeshing(pbs))
{
bool convex;
if (m_shapetype == 0)
convex = false;
else
convex = true;
m_mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, (int)LevelOfDetail.High, true, convex);
}
m_building = true; // control must set this to false when done
AddChange(changes.Add, null);
@ -1052,6 +1084,10 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool setMesh(OdeScene parent_scene)
{
IntPtr vertices, indices;
int vertexCount, indexCount;
int vertexStride, triStride;
if (Body != IntPtr.Zero)
{
if (childPrim)
@ -1068,22 +1104,32 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
IMesh mesh = null;
lock (m_meshlock)
{
if (m_mesh == null)
{
bool convex;
if (m_shapetype == 0)
convex = false;
else
convex = true;
IMesh mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, (int)LevelOfDetail.High, true,convex);
mesh = _parent_scene.mesher.CreateMesh(Name, _pbs, _size, (int)LevelOfDetail.High, true, convex);
}
else
{
mesh = m_mesh;
}
if (mesh == null)
{
m_log.WarnFormat("[PHYSICS]: CreateMesh Failed on prim {0} at <{1},{2},{3}>.", Name, _position.X, _position.Y, _position.Z);
return false;
}
IntPtr vertices, indices;
int vertexCount, indexCount;
int vertexStride, triStride;
mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap
mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
@ -1100,6 +1146,8 @@ namespace OpenSim.Region.Physics.OdePlugin
hasOOBoffsetFromMesh = true;
mesh.releaseSourceMeshData();
m_mesh = null;
}
IntPtr geo = IntPtr.Zero;

View File

@ -160,8 +160,8 @@ namespace OpenSim.Region.Physics.OdePlugin
private Random fluidRandomizer = new Random(Environment.TickCount);
const d.ContactFlags comumContactFlags = d.ContactFlags.SoftERP | d.ContactFlags.SoftCFM |d.ContactFlags.Approx1 | d.ContactFlags.Bounce;
const float comumContactERP = 0.6f;
const float comumSoftContactERP = 0.1f;
const float MaxERP = 0.8f;
const float minERP = 0.1f;
const float comumContactCFM = 0.0001f;
float frictionMovementMult = 0.3f;
@ -527,7 +527,7 @@ namespace OpenSim.Region.Physics.OdePlugin
// sets a global contact for a joint for contactgeom , and base contact description)
private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce, bool softerp)
private IntPtr CreateContacJoint(ref d.ContactGeom contactGeom, float mu, float bounce,float cfm,float erp)
{
if (GlobalContactsArray == IntPtr.Zero || m_global_contactcount >= maxContactsbeforedeath)
return IntPtr.Zero;
@ -545,11 +545,8 @@ namespace OpenSim.Region.Physics.OdePlugin
newcontact.surface.mode = comumContactFlags;
newcontact.surface.mu = mu;
newcontact.surface.bounce = bounce;
newcontact.surface.soft_cfm = comumContactCFM;
if (softerp)
newcontact.surface.soft_erp = comumSoftContactERP;
else
newcontact.surface.soft_erp = comumContactERP;
newcontact.surface.soft_cfm = cfm;
newcontact.surface.soft_erp = erp;
IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(m_global_contactcount * d.Contact.unmanagedSizeOf));
Marshal.StructureToPtr(newcontact, contact, true);
@ -693,9 +690,11 @@ namespace OpenSim.Region.Physics.OdePlugin
// big messy collision analises
float mu = 0;
float bounce = 0;
float cfm = 0.0001f;
float erp = 0.1f;
ContactData contactdata1 = new ContactData(0, 0, false);
ContactData contactdata2 = new ContactData(0, 0, false);
bool erpSoft = false;
String name = null;
bool dop1foot = false;
@ -705,61 +704,65 @@ namespace OpenSim.Region.Physics.OdePlugin
switch (p1.PhysicsActorType)
{
case (int)ActorTypes.Agent:
{
bounce = 0;
mu = 0;
cfm = 0.0001f;
switch (p2.PhysicsActorType)
{
case (int)ActorTypes.Agent:
/*
p1.getContactData(ref contactdata1);
p2.getContactData(ref contactdata2);
bounce = 0;
mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
mu *= frictionMovementMult;
erpSoft = contactdata1.softcolide | contactdata2.softcolide;
*/
p1.CollidingObj = true;
p2.CollidingObj = true;
break;
case (int)ActorTypes.Prim:
/*
p1.getContactData(ref contactdata1);
p2.getContactData(ref contactdata2);
bounce = 0;
mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
mu *= frictionMovementMult;
*/
if (p2.Velocity.LengthSquared() > 0.0f)
p2.CollidingObj = true;
erpSoft = contactdata1.softcolide | contactdata2.softcolide;
dop1foot = true;
break;
default:
ignore=true; // avatar to terrain and water ignored
ignore = true; // avatar to terrain and water ignored
break;
}
break;
}
case (int)ActorTypes.Prim:
switch (p2.PhysicsActorType)
{
case (int)ActorTypes.Agent:
p1.getContactData(ref contactdata1);
p2.getContactData(ref contactdata2);
// p1.getContactData(ref contactdata1);
// p2.getContactData(ref contactdata2);
bounce = 0;
mu = 0;
cfm = 0.0001f;
/*
mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
mu *= frictionMovementMult;
erpSoft = contactdata1.softcolide | contactdata2.softcolide;
*/
dop2foot = true;
if (p1.Velocity.LengthSquared() > 0.0f)
p1.CollidingObj = true;
@ -773,9 +776,16 @@ namespace OpenSim.Region.Physics.OdePlugin
p1.getContactData(ref contactdata1);
p2.getContactData(ref contactdata2);
bounce = contactdata1.bounce * contactdata2.bounce;
erpSoft = contactdata1.softcolide | contactdata2.softcolide;
mu = (float)Math.Sqrt(contactdata1.mu * contactdata2.mu);
cfm = p1.Mass;
if (cfm > p2.Mass)
cfm = p2.Mass;
cfm = (float)Math.Sqrt(cfm);
cfm *= 0.0001f;
if (cfm > 0.8f)
cfm = 0.8f;
if ((Math.Abs(p2.Velocity.X - p1.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y - p1.Velocity.Y) > 0.1f))
mu *= frictionMovementMult;
@ -790,12 +800,17 @@ namespace OpenSim.Region.Physics.OdePlugin
mu = (float)Math.Sqrt(contactdata1.mu * TerrainFriction);
if (Math.Abs(p1.Velocity.X) > 0.1f || Math.Abs(p1.Velocity.Y) > 0.1f)
mu *= frictionMovementMult;
erpSoft = contactdata1.softcolide;
p1.CollidingGround = true;
cfm = p1.Mass;
cfm = (float)Math.Sqrt(cfm);
cfm *= 0.0001f;
if (cfm > 0.8f)
cfm = 0.8f;
}
else if (name == "Water")
{
erpSoft = true;
ignore = true;
}
}
else
@ -815,7 +830,11 @@ namespace OpenSim.Region.Physics.OdePlugin
p2.getContactData(ref contactdata2);
bounce = contactdata2.bounce * TerrainBounce;
mu = (float)Math.Sqrt(contactdata2.mu * TerrainFriction);
erpSoft = contactdata2.softcolide;
cfm = p2.Mass;
cfm = (float)Math.Sqrt(cfm);
cfm *= 0.0001f;
if (cfm > 0.8f)
cfm = 0.8f;
if (Math.Abs(p2.Velocity.X) > 0.1f || Math.Abs(p2.Velocity.Y) > 0.1f)
mu *= frictionMovementMult;
@ -827,7 +846,7 @@ namespace OpenSim.Region.Physics.OdePlugin
else if (name == "Water" &&
(p2.PhysicsActorType == (int)ActorTypes.Prim || p2.PhysicsActorType == (int)ActorTypes.Agent))
{
erpSoft = true;
ignore = true;
}
}
else
@ -848,7 +867,14 @@ namespace OpenSim.Region.Physics.OdePlugin
if (dop2foot && (p2.Position.Z - curContact.pos.Z) > (p2.Size.Z - avCapRadius) * 0.5f)
p2.IsColliding = true;
Joint = CreateContacJoint(ref curContact, mu, bounce, erpSoft);
erp = curContact.depth;
if (erp < minERP)
erp = minERP;
else if (erp > MaxERP)
erp = MaxERP;
Joint = CreateContacJoint(ref curContact, mu, bounce,cfm,erp);
d.JointAttach(Joint, b1, b2);
if (++m_global_contactcount >= maxContactsbeforedeath)