* BulletDotNET Updates.

* Should react somewhat normally to editing, and setting physics now.
0.6.5-rc1
Teravus Ovares 2009-04-07 00:13:08 +00:00
parent 39f5dd1973
commit 9459b16cc2
4 changed files with 221 additions and 61 deletions

View File

@ -178,6 +178,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private btTransform tempTransform3; private btTransform tempTransform3;
private btTransform tempTransform4; private btTransform tempTransform4;
private btTriangleIndexVertexArray btshapeArray; private btTriangleIndexVertexArray btshapeArray;
private bool forceenable = false;
public btRigidBody Body; public btRigidBody Body;
@ -722,6 +723,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
{ {
if (m_taintadd) if (m_taintadd)
{ {
m_log.Debug("[PHYSICS]: TaintAdd");
changeadd(timestep); changeadd(timestep);
} }
@ -733,55 +735,91 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
SetBody(Mass); SetBody(Mass);
else else
SetBody(0); SetBody(0);
m_log.Debug("[PHYSICS]: GEOM_DOESNT_EXSIT");
} }
if (!_position.IsIdentical(m_taintposition, 0f)) if (!_position.IsIdentical(m_taintposition, 0f))
{
m_log.Debug("[PHYSICS]: TaintMove");
changemove(timestep); changemove(timestep);
}
if (m_taintrot != _orientation) if (m_taintrot != _orientation)
{
m_log.Debug("[PHYSICS]: TaintRotate");
rotate(timestep); rotate(timestep);
// } //
if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent))
{
m_log.Debug("[PHYSICS]: TaintPhysics");
changePhysicsStatus(timestep); changePhysicsStatus(timestep);
}
// //
if (!_size.IsIdentical(m_taintsize, 0)) if (!_size.IsIdentical(m_taintsize, 0))
{
m_log.Debug("[PHYSICS]: TaintSize");
changesize(timestep); changesize(timestep);
}
// //
if (m_taintshape) if (m_taintshape)
{
m_log.Debug("[PHYSICS]: TaintShape");
changeshape(timestep); changeshape(timestep);
// } //
if (m_taintforce) if (m_taintforce)
{
m_log.Debug("[PHYSICS]: TaintForce");
changeAddForce(timestep); changeAddForce(timestep);
}
if (m_taintaddangularforce) if (m_taintaddangularforce)
{
m_log.Debug("[PHYSICS]: TaintAngularForce");
changeAddAngularForce(timestep); changeAddAngularForce(timestep);
}
if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f)) if (!m_taintTorque.IsIdentical(PhysicsVector.Zero, 0.001f))
{
m_log.Debug("[PHYSICS]: TaintTorque");
changeSetTorque(timestep); changeSetTorque(timestep);
}
if (m_taintdisable) if (m_taintdisable)
{
m_log.Debug("[PHYSICS]: TaintDisable");
changedisable(timestep); changedisable(timestep);
}
if (m_taintselected != m_isSelected) if (m_taintselected != m_isSelected)
{
m_log.Debug("[PHYSICS]: TaintSelected");
changeSelectedStatus(timestep); changeSelectedStatus(timestep);
}
if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f)) if (!m_taintVelocity.IsIdentical(PhysicsVector.Zero, 0.001f))
{
m_log.Debug("[PHYSICS]: TaintVelocity");
changevelocity(timestep); changevelocity(timestep);
}
if (m_taintparent != _parent) if (m_taintparent != _parent)
{
m_log.Debug("[PHYSICS]: TaintLink");
changelink(timestep); changelink(timestep);
}
if (m_taintCollidesWater != m_collidesWater) if (m_taintCollidesWater != m_collidesWater)
{
changefloatonwater(timestep); changefloatonwater(timestep);
}
if (!m_angularlock.IsIdentical(m_taintAngularLock, 0)) if (!m_angularlock.IsIdentical(m_taintAngularLock, 0))
{
m_log.Debug("[PHYSICS]: TaintAngularLock");
changeAngularLock(timestep); changeAngularLock(timestep);
}
if (m_taintremove)
{
DisposeOfBody();
Dispose();
}
} }
@ -789,19 +827,41 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void changeadd(float timestep) private void changeadd(float timestep)
{ {
if (_mesh == null) //SetCollisionShape(null);
// Construction of new prim
if (Body != null)
{ {
if (Body.Handle != IntPtr.Zero)
{
_parent_scene.removeFromWorld(this, Body);
//Body.Dispose();
}
//Body = null;
// TODO: dispose parts that make up body
}
if (_parent_scene.needsMeshing(_pbs)) if (_parent_scene.needsMeshing(_pbs))
{ {
// Don't need to re-enable body.. it's done in SetMesh // Don't need to re-enable body.. it's done in SetMesh
_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); float meshlod = _parent_scene.meshSculptLOD;
// createmesh returns null when it's a shape that isn't a cube.
}
}
CreateGeom(IntPtr.Zero, primMesh);
enableBody(); if (IsPhysical)
changeSelectedStatus(timestep); meshlod = _parent_scene.MeshSculptphysicalLOD;
IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
// createmesh returns null when it doesn't mesh.
CreateGeom(IntPtr.Zero, mesh);
}
else
{
_mesh = null;
CreateGeom(IntPtr.Zero, null);
}
if (IsPhysical)
SetBody(Mass);
else
SetBody(0);
//changeSelectedStatus(timestep);
m_taintadd = false; m_taintadd = false;
} }
@ -809,7 +869,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void changemove(float timestep) private void changemove(float timestep)
{ {
m_log.Debug("[PHYSICS]: _________ChangeMove");
tempTransform2 = Body.getWorldTransform(); tempTransform2 = Body.getWorldTransform();
btQuaternion quat = tempTransform2.getRotation(); btQuaternion quat = tempTransform2.getRotation();
tempPosition2.setValue(_position.X, _position.Y, _position.Z); tempPosition2.setValue(_position.X, _position.Y, _position.Z);
@ -825,7 +885,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void rotate(float timestep) private void rotate(float timestep)
{ {
m_log.Debug("[PHYSICS]: _________ChangeRotate");
tempTransform2 = Body.getWorldTransform(); tempTransform2 = Body.getWorldTransform();
tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W); tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W);
tempTransform2.setRotation(tempOrientation2); tempTransform2.setRotation(tempOrientation2);
@ -837,8 +897,39 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void changePhysicsStatus(float timestep) private void changePhysicsStatus(float timestep)
{ {
if (Body != null)
{
if (Body.Handle != IntPtr.Zero)
{
_parent_scene.removeFromWorld(this, Body);
//Body.Dispose();
}
//Body = null;
// TODO: dispose parts that make up body
}
m_log.Debug("[PHYSICS]: _________ChangePhysics");
if (_parent_scene.needsMeshing(_pbs))
{
// Don't need to re-enable body.. it's done in SetMesh
float meshlod = _parent_scene.meshSculptLOD;
if (IsPhysical)
meshlod = _parent_scene.MeshSculptphysicalLOD;
IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
// createmesh returns null when it doesn't mesh.
CreateGeom(IntPtr.Zero, mesh);
}
else
{
_mesh = null;
CreateGeom(IntPtr.Zero, null);
}
SetCollisionShape(prim_geom); SetCollisionShape(prim_geom);
if (m_isphysical)
SetBody(Mass); SetBody(Mass);
else
SetBody(0);
changeSelectedStatus(timestep); changeSelectedStatus(timestep);
resetCollisionAccounting(); resetCollisionAccounting();
@ -847,31 +938,36 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void changesize(float timestep) private void changesize(float timestep)
{ {
if (Body != null)
{
if (Body.Handle != IntPtr.Zero)
{
_parent_scene.removeFromWorld(this, Body);
//Body.Dispose();
}
//Body = null;
// TODO: dispose parts that make up body
}
m_log.Debug("[PHYSICS]: _________ChangeSize");
SetCollisionShape(null); SetCollisionShape(null);
// Construction of new prim // Construction of new prim
if (_parent_scene.needsMeshing(_pbs)) if (_parent_scene.needsMeshing(_pbs))
{ {
// Don't need to re-enable body.. it's done in SetMesh
float meshlod = _parent_scene.meshSculptLOD; float meshlod = _parent_scene.meshSculptLOD;
if (IsPhysical) if (IsPhysical)
meshlod = _parent_scene.MeshSculptphysicalLOD; meshlod = _parent_scene.MeshSculptphysicalLOD;
// Don't need to re-enable body.. it's done in SetMesh
IMesh mesh = null;
if (_parent_scene.needsMeshing(_pbs))
mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
//IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size, meshlod, IsPhysical);
IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
// createmesh returns null when it doesn't mesh.
CreateGeom(IntPtr.Zero, mesh); CreateGeom(IntPtr.Zero, mesh);
} }
else else
{ {
_mesh = null; _mesh = null;
CreateGeom(IntPtr.Zero, _mesh); CreateGeom(IntPtr.Zero, null);
} }
if (IsPhysical) if (IsPhysical)
@ -885,6 +981,16 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void changeshape(float timestep) private void changeshape(float timestep)
{ {
if (Body != null)
{
if (Body.Handle != IntPtr.Zero)
{
_parent_scene.removeFromWorld(this, Body);
//Body.Dispose();
}
//Body = null;
// TODO: dispose parts that make up body
}
// Cleanup of old prim geometry and Bodies // Cleanup of old prim geometry and Bodies
if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero) if (IsPhysical && Body != null && Body.Handle != IntPtr.Zero)
{ {
@ -898,12 +1004,12 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
} }
else else
{ {
disableBody(); //disableBody();
} }
} }
try try
{ {
SetCollisionShape(null); //SetCollisionShape(null);
} }
catch (System.AccessViolationException) catch (System.AccessViolationException)
{ {
@ -968,6 +1074,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
} }
} }
resetCollisionAccounting(); resetCollisionAccounting();
m_taintshape = false; m_taintshape = false;
} }
@ -1004,6 +1111,16 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void changeSelectedStatus(float timestep) private void changeSelectedStatus(float timestep)
{ {
// TODO: throw new NotImplementedException(); // TODO: throw new NotImplementedException();
if (m_taintselected)
{
disableBodySoft();
}
else
{
enableBodySoft();
}
m_isSelected = m_taintselected;
} }
private void changevelocity(float timestep) private void changevelocity(float timestep)
@ -1584,6 +1701,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
public void CreateGeom(IntPtr m_targetSpace, IMesh p_mesh) public void CreateGeom(IntPtr m_targetSpace, IMesh p_mesh)
{ {
m_log.Debug("[PHYSICS]: _________CreateGeom");
if (p_mesh != null) if (p_mesh != null)
{ {
_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); _mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
@ -1631,7 +1749,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
// TODO: Set Collision Body Mesh // TODO: Set Collision Body Mesh
// This sleeper is there to moderate how long it takes between // This sleeper is there to moderate how long it takes between
// setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object
m_log.Debug("_________SetMesh");
Thread.Sleep(10); Thread.Sleep(10);
//Kill Body so that mesh can re-make the geom //Kill Body so that mesh can re-make the geom
@ -1647,7 +1765,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
} }
else else
{ {
disableBody(); //disableBody();
} }
} }
@ -1683,6 +1801,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
private void SetCollisionShape(btCollisionShape shape) private void SetCollisionShape(btCollisionShape shape)
{ {
/*
if (shape == null) if (shape == null)
m_log.Debug("[PHYSICS]:SetShape!Null"); m_log.Debug("[PHYSICS]:SetShape!Null");
else else
@ -1698,6 +1817,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
prim_geom.Dispose(); prim_geom.Dispose();
prim_geom = null; prim_geom = null;
} }
*/
prim_geom = shape; prim_geom = shape;
//Body.set //Body.set
@ -1705,12 +1825,13 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
public void SetBody(float mass) public void SetBody(float mass)
{ {
m_log.DebugFormat("[PHYSICS]: SetBody! {0}",mass); //m_log.DebugFormat("[PHYSICS]: SetBody! {0}",mass);
/*
if (Body != null && Body.Handle != IntPtr.Zero) if (Body != null && Body.Handle != IntPtr.Zero)
{ {
DisposeOfBody(); DisposeOfBody();
} }
*/
if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero) if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
tempMotionState1.Dispose(); tempMotionState1.Dispose();
if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero) if (tempTransform2 != null && tempTransform2.Handle != IntPtr.Zero)
@ -1728,17 +1849,40 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero) if (tempInertia1 != null && tempInertia1.Handle != IntPtr.Zero)
tempInertia1.Dispose(); tempInertia1.Dispose();
tempInertia1 = new btVector3(0, 0, 0); tempInertia1 = new btVector3(0, 0, 0);
/*
if (prim_geom.Handle == IntPtr.Zero) if (prim_geom.Handle == IntPtr.Zero)
{ {
m_log.Warn("[PHYSICS]:PrimGeom is Disposed!"); m_log.Warn("[PHYSICS]:PrimGeom is Disposed!");
CreateGeom(IntPtr.Zero, primMesh); if (_parent_scene.needsMeshing(_pbs))
{
// Don't need to re-enable body.. it's done in SetMesh
float meshlod = _parent_scene.meshSculptLOD;
if (IsPhysical)
meshlod = _parent_scene.MeshSculptphysicalLOD;
IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
// createmesh returns null when it doesn't mesh.
CreateGeom(IntPtr.Zero, mesh);
}
else
{
_mesh = null;
CreateGeom(IntPtr.Zero, null);
}
} }
*/
prim_geom.calculateLocalInertia(mass, tempInertia1); prim_geom.calculateLocalInertia(mass, tempInertia1);
if (mass == 0) if (mass != 0)
Body = new btRigidBody(mass, tempMotionState1, prim_geom); _parent_scene.addActivePrim(this);
else else
_parent_scene.remActivePrim(this);
// Body = new btRigidBody(mass, tempMotionState1, prim_geom);
//else
Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1);
if (prim_geom is btGImpactMeshShape) if (prim_geom is btGImpactMeshShape)
@ -1810,6 +1954,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
public void disableBody() public void disableBody()
{ {
//this kills the body so things like 'mesh' can re-create it. //this kills the body so things like 'mesh' can re-create it.
/*
lock (this) lock (this)
{ {
if (!childPrim) if (!childPrim)
@ -1861,6 +2006,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
} }
} }
*/
m_disabled = true; m_disabled = true;
m_collisionscore = 0; m_collisionscore = 0;
} }
@ -1885,7 +2031,9 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
if (m_isphysical && Body.Handle != IntPtr.Zero) if (m_isphysical && Body.Handle != IntPtr.Zero)
{ {
Body.clearForces(); Body.clearForces();
Body.forceActivationState(1); Body.forceActivationState(4);
forceenable = true;
} }
m_disabled = false; m_disabled = false;
} }
@ -1922,8 +2070,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
{ {
PhysicsVector pv = new PhysicsVector(0, 0, 0); PhysicsVector pv = new PhysicsVector(0, 0, 0);
bool lastZeroFlag = _zeroFlag; bool lastZeroFlag = _zeroFlag;
if (tempPosition2 != null && tempPosition2.Handle != IntPtr.Zero) if (tempPosition3 != null && tempPosition3.Handle != IntPtr.Zero)
tempPosition2.Dispose(); tempPosition3.Dispose();
if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero) if (tempTransform3 != null && tempTransform3.Handle != IntPtr.Zero)
tempTransform3.Dispose(); tempTransform3.Dispose();
@ -1939,7 +2087,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
tempTransform3 = Body.getInterpolationWorldTransform(); tempTransform3 = Body.getInterpolationWorldTransform();
tempPosition2 = tempTransform3.getOrigin(); // vec tempPosition3 = tempTransform3.getOrigin(); // vec
tempOrientation2 = tempTransform3.getRotation(); // ori tempOrientation2 = tempTransform3.getRotation(); // ori
tempAngularVelocity1 = Body.getInterpolationAngularVelocity(); //rotvel tempAngularVelocity1 = Body.getInterpolationAngularVelocity(); //rotvel
tempLinearVelocity1 = Body.getInterpolationLinearVelocity(); // vel tempLinearVelocity1 = Body.getInterpolationLinearVelocity(); // vel
@ -1950,9 +2098,9 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
m_lastposition = _position; m_lastposition = _position;
m_lastorientation = _orientation; m_lastorientation = _orientation;
l_position.X = tempPosition2.getX(); l_position.X = tempPosition3.getX();
l_position.Y = tempPosition2.getY(); l_position.Y = tempPosition3.getY();
l_position.Z = tempPosition2.getZ(); l_position.Z = tempPosition3.getZ();
l_orientation.X = tempOrientation2.getX(); l_orientation.X = tempOrientation2.getX();
l_orientation.Y = tempOrientation2.getY(); l_orientation.Y = tempOrientation2.getY();
l_orientation.Z = tempOrientation2.getZ(); l_orientation.Z = tempOrientation2.getZ();
@ -2103,6 +2251,11 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
} }
m_lastposition = l_position; m_lastposition = l_position;
if (forceenable)
{
Body.forceActivationState(1);
forceenable = false;
}
} }
else else
{ {

View File

@ -187,8 +187,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
newPrim = new BulletDotNETPrim(name, this, pos, siz, rot, mesh, pbs, isphysical); newPrim = new BulletDotNETPrim(name, this, pos, siz, rot, mesh, pbs, isphysical);
lock (m_prims) //lock (m_prims)
m_prims.Add(newPrim); // m_prims.Add(newPrim);
return newPrim; return newPrim;
@ -267,6 +267,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
{ {
foreach (BulletDotNETPrim prim in m_prims) foreach (BulletDotNETPrim prim in m_prims)
{ {
if (prim != null)
prim.Move(timeStep); prim.Move(timeStep);
} }
} }
@ -279,6 +280,10 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
foreach (BulletDotNETPrim prm in m_activePrims) foreach (BulletDotNETPrim prm in m_activePrims)
{ {
/*
if (prm != null)
if (prm.Body != null)
*/
prm.UpdatePositionAndVelocity(); prm.UpdatePositionAndVelocity();
} }
@ -487,6 +492,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
{ {
m_world.removeRigidBody(body); m_world.removeRigidBody(body);
} }
remActivePrim(prm);
m_prims.Remove(prm); m_prims.Remove(prm);
} }
@ -662,6 +668,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
{ {
m_prims.Add(pPrim); m_prims.Add(pPrim);
m_world.addRigidBody(pPrim.Body); m_world.addRigidBody(pPrim.Body);
m_log.Debug("ADDED");
} }
} }
} }

Binary file not shown.

Binary file not shown.