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 bool m_disabled;
public uint m_localID; public uint m_localID;
private IMesh m_mesh;
private object m_meshlock = new object();
private PrimitiveBaseShape _pbs; private PrimitiveBaseShape _pbs;
public OdeScene _parent_scene; public OdeScene _parent_scene;
@ -484,6 +485,24 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
set 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); AddChange(changes.Shape, value);
} }
} }
@ -950,6 +969,19 @@ namespace OpenSim.Region.Physics.OdePlugin
CalcPrimBodyData(); 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 m_building = true; // control must set this to false when done
AddChange(changes.Add, null); AddChange(changes.Add, null);
@ -1052,6 +1084,10 @@ namespace OpenSim.Region.Physics.OdePlugin
private bool setMesh(OdeScene parent_scene) private bool setMesh(OdeScene parent_scene)
{ {
IntPtr vertices, indices;
int vertexCount, indexCount;
int vertexStride, triStride;
if (Body != IntPtr.Zero) if (Body != IntPtr.Zero)
{ {
if (childPrim) if (childPrim)
@ -1068,22 +1104,32 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
} }
IMesh mesh = null;
lock (m_meshlock)
{
if (m_mesh == null)
{
bool convex; bool convex;
if (m_shapetype == 0) if (m_shapetype == 0)
convex = false; convex = false;
else else
convex = true; 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) if (mesh == null)
{ {
m_log.WarnFormat("[PHYSICS]: CreateMesh Failed on prim {0} at <{1},{2},{3}>.", Name, _position.X, _position.Y, _position.Z); m_log.WarnFormat("[PHYSICS]: CreateMesh Failed on prim {0} at <{1},{2},{3}>.", Name, _position.X, _position.Y, _position.Z);
return false; 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.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 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; hasOOBoffsetFromMesh = true;
mesh.releaseSourceMeshData(); mesh.releaseSourceMeshData();
m_mesh = null;
}
IntPtr geo = IntPtr.Zero; IntPtr geo = IntPtr.Zero;

View File

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