modify BulletDotNETPrim.cs in preparation for Mantis #4181
parent
1faaa0a43a
commit
daffb69174
|
@ -204,7 +204,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
tempAngularVelocity2 = new btVector3(0, 0, 0);
|
tempAngularVelocity2 = new btVector3(0, 0, 0);
|
||||||
tempInertia1 = new btVector3(0, 0, 0);
|
tempInertia1 = new btVector3(0, 0, 0);
|
||||||
tempInertia2 = new btVector3(0, 0, 0);
|
tempInertia2 = new btVector3(0, 0, 0);
|
||||||
tempOrientation1 = new btQuaternion(0,0,0,1);
|
tempOrientation1 = new btQuaternion(0, 0, 0, 1);
|
||||||
tempOrientation2 = new btQuaternion(0, 0, 0, 1);
|
tempOrientation2 = new btQuaternion(0, 0, 0, 1);
|
||||||
_parent_scene = parent_scene;
|
_parent_scene = parent_scene;
|
||||||
tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero);
|
tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero);
|
||||||
|
@ -218,7 +218,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
|
|
||||||
|
|
||||||
AxisLockLinearLow = new btVector3(-1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize);
|
AxisLockLinearLow = new btVector3(-1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize);
|
||||||
int regionsize = (int) Constants.RegionSize;
|
int regionsize = (int)Constants.RegionSize;
|
||||||
|
|
||||||
if (regionsize == 256)
|
if (regionsize == 256)
|
||||||
regionsize = 512;
|
regionsize = 512;
|
||||||
|
@ -802,7 +802,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
changesize(timestep);
|
changesize(timestep);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
if (m_taintshape)
|
if (m_taintshape)
|
||||||
{
|
{
|
||||||
|
@ -1012,7 +1012,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
{
|
{
|
||||||
if (_parent_scene.needsMeshing(_pbs))
|
if (_parent_scene.needsMeshing(_pbs))
|
||||||
{
|
{
|
||||||
ProcessGeomCreationAsTriMesh(PhysicsVector.Zero,Quaternion.Identity);
|
ProcessGeomCreationAsTriMesh(PhysicsVector.Zero, Quaternion.Identity);
|
||||||
// createmesh returns null when it doesn't mesh.
|
// createmesh returns null when it doesn't mesh.
|
||||||
CreateGeom(IntPtr.Zero, _mesh);
|
CreateGeom(IntPtr.Zero, _mesh);
|
||||||
}
|
}
|
||||||
|
@ -1038,30 +1038,30 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
meshlod = _parent_scene.MeshSculptphysicalLOD;
|
meshlod = _parent_scene.MeshSculptphysicalLOD;
|
||||||
|
|
||||||
IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
|
IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
|
||||||
if (!positionOffset.IsIdentical(PhysicsVector.Zero,0.001f) || orientation != Quaternion.Identity)
|
if (!positionOffset.IsIdentical(PhysicsVector.Zero, 0.001f) || orientation != Quaternion.Identity)
|
||||||
{
|
{
|
||||||
|
|
||||||
float[] xyz = new float[3];
|
float[] xyz = new float[3];
|
||||||
xyz[0] = positionOffset.X;
|
xyz[0] = positionOffset.X;
|
||||||
xyz[1] = positionOffset.Y;
|
xyz[1] = positionOffset.Y;
|
||||||
xyz[2] = positionOffset.Z;
|
xyz[2] = positionOffset.Z;
|
||||||
|
|
||||||
Matrix4 m4 = Matrix4.CreateFromQuaternion(orientation);
|
Matrix4 m4 = Matrix4.CreateFromQuaternion(orientation);
|
||||||
|
|
||||||
float[,] matrix = new float[3,3];
|
float[,] matrix = new float[3, 3];
|
||||||
|
|
||||||
matrix[0, 0] = m4.M11;
|
matrix[0, 0] = m4.M11;
|
||||||
matrix[0, 1] = m4.M12;
|
matrix[0, 1] = m4.M12;
|
||||||
matrix[0, 2] = m4.M13;
|
matrix[0, 2] = m4.M13;
|
||||||
matrix[1, 0] = m4.M21;
|
matrix[1, 0] = m4.M21;
|
||||||
matrix[1, 1] = m4.M22;
|
matrix[1, 1] = m4.M22;
|
||||||
matrix[1, 2] = m4.M23;
|
matrix[1, 2] = m4.M23;
|
||||||
matrix[2, 0] = m4.M31;
|
matrix[2, 0] = m4.M31;
|
||||||
matrix[2, 1] = m4.M32;
|
matrix[2, 1] = m4.M32;
|
||||||
matrix[2, 2] = m4.M33;
|
matrix[2, 2] = m4.M33;
|
||||||
|
|
||||||
|
|
||||||
mesh.TransformLinear(matrix, xyz);
|
mesh.TransformLinear(matrix, xyz);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1627,7 +1627,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
{
|
{
|
||||||
if (m_zeroPosition == null)
|
if (m_zeroPosition == null)
|
||||||
m_zeroPosition = new PhysicsVector(0, 0, 0);
|
m_zeroPosition = new PhysicsVector(0, 0, 0);
|
||||||
m_zeroPosition.setValues(_position.X,_position.Y,_position.Z);
|
m_zeroPosition.setValues(_position.X, _position.Y, _position.Z);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1994,15 +1994,15 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
//SetGeom to a Regular Sphere
|
//SetGeom to a Regular Sphere
|
||||||
if (tempSize1 == null)
|
if (tempSize1 == null)
|
||||||
tempSize1 = new btVector3(0, 0, 0);
|
tempSize1 = new btVector3(0, 0, 0);
|
||||||
tempSize1.setValue(_size.X * 0.5f,_size.Y * 0.5f, _size.Z * 0.5f);
|
tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
|
||||||
SetCollisionShape(new btSphereShape(_size.X*0.5f));
|
SetCollisionShape(new btSphereShape(_size.X * 0.5f));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// uses halfextents
|
// uses halfextents
|
||||||
if (tempSize1 == null)
|
if (tempSize1 == null)
|
||||||
tempSize1 = new btVector3(0, 0, 0);
|
tempSize1 = new btVector3(0, 0, 0);
|
||||||
tempSize1.setValue(_size.X*0.5f, _size.Y*0.5f, _size.Z*0.5f);
|
tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
|
||||||
SetCollisionShape(new btBoxShape(tempSize1));
|
SetCollisionShape(new btBoxShape(tempSize1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2052,14 +2052,24 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//IMesh oldMesh = primMesh;
|
||||||
|
|
||||||
|
//primMesh = mesh;
|
||||||
|
|
||||||
|
//float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
|
||||||
|
//int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
|
||||||
|
////Array.Reverse(indexList);
|
||||||
|
//primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory
|
||||||
|
|
||||||
IMesh oldMesh = primMesh;
|
IMesh oldMesh = primMesh;
|
||||||
|
|
||||||
primMesh = mesh;
|
primMesh = mesh;
|
||||||
|
|
||||||
float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
|
float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
|
||||||
int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
|
int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
|
||||||
//Array.Reverse(indexList);
|
//Array.Reverse(indexList);
|
||||||
primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory
|
mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
|
||||||
|
|
||||||
|
|
||||||
int VertexCount = vertexList.GetLength(0) / 3;
|
int VertexCount = vertexList.GetLength(0) / 3;
|
||||||
int IndexCount = indexList.GetLength(0);
|
int IndexCount = indexList.GetLength(0);
|
||||||
|
@ -2068,17 +2078,17 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
btshapeArray.Dispose();
|
btshapeArray.Dispose();
|
||||||
//Array.Reverse(indexList);
|
//Array.Reverse(indexList);
|
||||||
btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)),
|
btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)),
|
||||||
VertexCount, vertexList, 3*sizeof (float));
|
VertexCount, vertexList, 3 * sizeof(float));
|
||||||
SetCollisionShape(new btGImpactMeshShape(btshapeArray));
|
SetCollisionShape(new btGImpactMeshShape(btshapeArray));
|
||||||
//((btGImpactMeshShape) prim_geom).updateBound();
|
//((btGImpactMeshShape) prim_geom).updateBound();
|
||||||
((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1,1, 1));
|
((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
|
||||||
((btGImpactMeshShape)prim_geom).updateBound();
|
((btGImpactMeshShape)prim_geom).updateBound();
|
||||||
_parent_scene.SetUsingGImpact();
|
_parent_scene.SetUsingGImpact();
|
||||||
if (oldMesh != null)
|
//if (oldMesh != null)
|
||||||
{
|
//{
|
||||||
oldMesh.releasePinned();
|
// oldMesh.releasePinned();
|
||||||
oldMesh = null;
|
// oldMesh = null;
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2143,8 +2153,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
|
|
||||||
if (prim_geom is btGImpactMeshShape)
|
if (prim_geom is btGImpactMeshShape)
|
||||||
{
|
{
|
||||||
((btGImpactMeshShape) prim_geom).setLocalScaling(new btVector3(1, 1, 1));
|
((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
|
||||||
((btGImpactMeshShape) prim_geom).updateBound();
|
((btGImpactMeshShape)prim_geom).updateBound();
|
||||||
}
|
}
|
||||||
//Body.setCollisionFlags(Body.getCollisionFlags() | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK);
|
//Body.setCollisionFlags(Body.getCollisionFlags() | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK);
|
||||||
//Body.setUserPointer((IntPtr) (int)m_localID);
|
//Body.setUserPointer((IntPtr) (int)m_localID);
|
||||||
|
@ -2167,40 +2177,40 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
|
|
||||||
//if (hasTrimesh)
|
//if (hasTrimesh)
|
||||||
//{
|
//{
|
||||||
ProcessGeomCreationAsTriMesh(PhysicsVector.Zero, Quaternion.Identity);
|
ProcessGeomCreationAsTriMesh(PhysicsVector.Zero, Quaternion.Identity);
|
||||||
// createmesh returns null when it doesn't mesh.
|
// createmesh returns null when it doesn't mesh.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (_mesh is Mesh)
|
if (_mesh is Mesh)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_log.Warn("[PHYSICS]: Can't link a OpenSim.Region.Physics.Meshing.Mesh object");
|
m_log.Warn("[PHYSICS]: Can't link a OpenSim.Region.Physics.Meshing.Mesh object");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (BulletDotNETPrim chld in childrenPrim)
|
foreach (BulletDotNETPrim chld in childrenPrim)
|
||||||
{
|
{
|
||||||
if (chld == null)
|
if (chld == null)
|
||||||
continue;
|
continue;
|
||||||
PhysicsVector offset = chld.Position - Position;
|
PhysicsVector offset = chld.Position - Position;
|
||||||
Vector3 pos = new Vector3(offset.X, offset.Y, offset.Z);
|
Vector3 pos = new Vector3(offset.X, offset.Y, offset.Z);
|
||||||
pos *= Quaternion.Inverse(Orientation);
|
pos *= Quaternion.Inverse(Orientation);
|
||||||
//pos *= Orientation;
|
//pos *= Orientation;
|
||||||
offset.setValues(pos.X, pos.Y, pos.Z);
|
offset.setValues(pos.X, pos.Y, pos.Z);
|
||||||
chld.ProcessGeomCreationAsTriMesh(offset, chld.Orientation);
|
chld.ProcessGeomCreationAsTriMesh(offset, chld.Orientation);
|
||||||
|
|
||||||
_mesh.Append(chld._mesh);
|
_mesh.Append(chld._mesh);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
setMesh(_parent_scene, _mesh);
|
setMesh(_parent_scene, _mesh);
|
||||||
|
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
|
if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
|
||||||
tempMotionState1.Dispose();
|
tempMotionState1.Dispose();
|
||||||
|
@ -2252,7 +2262,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
if (Body.Handle != IntPtr.Zero)
|
if (Body.Handle != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
DisableAxisMotor();
|
DisableAxisMotor();
|
||||||
_parent_scene.removeFromWorld(this,Body);
|
_parent_scene.removeFromWorld(this, Body);
|
||||||
Body.Dispose();
|
Body.Dispose();
|
||||||
}
|
}
|
||||||
Body = null;
|
Body = null;
|
||||||
|
@ -2587,10 +2597,10 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
|
||||||
_velocity.Y = tempLinearVelocity1.getY();
|
_velocity.Y = tempLinearVelocity1.getY();
|
||||||
_velocity.Z = tempLinearVelocity1.getZ();
|
_velocity.Z = tempLinearVelocity1.getZ();
|
||||||
|
|
||||||
_acceleration = ((_velocity - m_lastVelocity)/0.1f);
|
_acceleration = ((_velocity - m_lastVelocity) / 0.1f);
|
||||||
_acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X/0.1f,
|
_acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f,
|
||||||
_velocity.Y - m_lastVelocity.Y/0.1f,
|
_velocity.Y - m_lastVelocity.Y / 0.1f,
|
||||||
_velocity.Z - m_lastVelocity.Z/0.1f);
|
_velocity.Z - m_lastVelocity.Z / 0.1f);
|
||||||
//m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
|
//m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
|
||||||
|
|
||||||
if (_velocity.IsIdentical(pv, 0.5f))
|
if (_velocity.IsIdentical(pv, 0.5f))
|
||||||
|
|
Loading…
Reference in New Issue