Use GetMeshKey from PrimitiveBaseShape.

bulletsim
Robert Adams 2011-08-29 10:00:58 -07:00 committed by Mic Bowman
parent 648866b597
commit 96dce3e16c
2 changed files with 23 additions and 15 deletions

View File

@ -53,8 +53,11 @@ public sealed class BSPrim : PhysicsActor
private String _avName; private String _avName;
private uint _localID = 0; private uint _localID = 0;
private OMV.Vector3 _size; // _size is what the user passed. _scale is what we pass to the physics engine with the mesh.
private OMV.Vector3 _scale; // Often _scale is unity because the meshmerizer will apply _size when creating the mesh.
private OMV.Vector3 _size; // the multiplier for each mesh dimension as passed by the user
private OMV.Vector3 _scale; // the multiplier for each mesh dimension for the mesh as created by the meshmerizer
private bool _stopped; private bool _stopped;
private bool _grabbed; private bool _grabbed;
private bool _isSelected; private bool _isSelected;
@ -460,6 +463,7 @@ public sealed class BSPrim : PhysicsActor
// no locking here because only called when it is safe // no locking here because only called when it is safe
private void SetObjectDynamic() private void SetObjectDynamic()
{ {
// m_log.DebugFormat("{0}: ID={1}, SetObjectDynamic: IsStatic={2}, IsSolid={3}", LogHeader, _localID, IsStatic, IsSolid);
// non-physical things work best with a mass of zero // non-physical things work best with a mass of zero
if (IsStatic) if (IsStatic)
{ {
@ -474,7 +478,6 @@ public sealed class BSPrim : PhysicsActor
} }
BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), _mass); BulletSimAPI.SetObjectProperties(_scene.WorldID, LocalID, IsStatic, IsSolid, SubscribedEvents(), _mass);
// m_log.DebugFormat("{0}: ID={1}, SetObjectDynamic: IsStatic={2}, IsSolid={3}, mass={4}", LogHeader, _localID, IsStatic, IsSolid, _mass);
} }
// prims don't fly // prims don't fly
@ -955,7 +958,9 @@ public sealed class BSPrim : PhysicsActor
// No locking here because this is done when we know physics is not simulating // No locking here because this is done when we know physics is not simulating
private void CreateGeomMesh() private void CreateGeomMesh()
{ {
ulong newMeshKey = (ulong)_pbs.GetHashCode(); float lod = _pbs.SculptEntry ? _scene.SculptLOD : _scene.MeshLOD;
ulong newMeshKey = (ulong)_pbs.GetMeshKey(_size, lod);
// m_log.DebugFormat("{0}: CreateGeomMesh: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _meshKey, newMeshKey);
// if this new shape is the same as last time, don't recreate the mesh // if this new shape is the same as last time, don't recreate the mesh
if (_meshKey == newMeshKey) return; if (_meshKey == newMeshKey) return;
@ -963,14 +968,13 @@ public sealed class BSPrim : PhysicsActor
// Since we're recreating new, get rid of any previously generated shape // Since we're recreating new, get rid of any previously generated shape
if (_meshKey != 0) if (_meshKey != 0)
{ {
// m_log.DebugFormat("{0}: CreateGeom: deleting old hull. Key={1}", LogHeader, _meshKey); // m_log.DebugFormat("{0}: CreateGeom: deleting old mesh. lID={1}, Key={2}", LogHeader, _localID, _meshKey);
BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey); BulletSimAPI.DestroyMesh(_scene.WorldID, _meshKey);
_mesh = null; _mesh = null;
_meshKey = 0; _meshKey = 0;
} }
_meshKey = newMeshKey; _meshKey = newMeshKey;
int lod = _pbs.SculptEntry ? _scene.SculptLOD : _scene.MeshLOD;
// always pass false for physicalness as this creates some sort of bounding box which we don't need // always pass false for physicalness as this creates some sort of bounding box which we don't need
_mesh = _scene.mesher.CreateMesh(_avName, _pbs, _size, lod, false); _mesh = _scene.mesher.CreateMesh(_avName, _pbs, _size, lod, false);
@ -1001,7 +1005,9 @@ public sealed class BSPrim : PhysicsActor
// No locking here because this is done when we know physics is not simulating // No locking here because this is done when we know physics is not simulating
private void CreateGeomHull() private void CreateGeomHull()
{ {
ulong newHullKey = (ulong)_pbs.GetHashCode(); float lod = _pbs.SculptEntry ? _scene.SculptLOD : _scene.MeshLOD;
ulong newHullKey = (ulong)_pbs.GetMeshKey(_size, lod);
// m_log.DebugFormat("{0}: CreateGeomHull: lID={1}, oldKey={2}, newKey={3}", LogHeader, _localID, _hullKey, newHullKey);
// if the hull hasn't changed, don't rebuild it // if the hull hasn't changed, don't rebuild it
if (newHullKey == _hullKey) return; if (newHullKey == _hullKey) return;
@ -1136,6 +1142,7 @@ public sealed class BSPrim : PhysicsActor
// the mesh or hull must have already been created in Bullet // the mesh or hull must have already been created in Bullet
ShapeData shape; ShapeData shape;
FillShapeInfo(out shape); FillShapeInfo(out shape);
// m_log.DebugFormat("{0}: CreateObject: lID={1}, shape={2}", LogHeader, _localID, shape.Type);
BulletSimAPI.CreateObject(_scene.WorldID, shape); BulletSimAPI.CreateObject(_scene.WorldID, shape);
} }
} }
@ -1227,6 +1234,7 @@ public sealed class BSPrim : PhysicsActor
// No locking here because this is done when the physics engine is not simulating // No locking here because this is done when the physics engine is not simulating
private void RecreateGeomAndObject() private void RecreateGeomAndObject()
{ {
// m_log.DebugFormat("{0}: RecreateGeomAndObject. lID={1}", LogHeader, _localID);
CreateGeom(true); CreateGeom(true);
CreateObject(); CreateObject();
return; return;

View File

@ -73,13 +73,13 @@ public class BSScene : PhysicsScene, IPhysicsParameters
private bool m_initialized = false; private bool m_initialized = false;
public IMesher mesher; public IMesher mesher;
private int m_meshLOD; private float m_meshLOD;
public int MeshLOD public float MeshLOD
{ {
get { return m_meshLOD; } get { return m_meshLOD; }
} }
private int m_sculptLOD; private float m_sculptLOD;
public int SculptLOD public float SculptLOD
{ {
get { return m_sculptLOD; } get { return m_sculptLOD; }
} }
@ -189,8 +189,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
_meshSculptedPrim = true; // mesh sculpted prims _meshSculptedPrim = true; // mesh sculpted prims
_forceSimplePrimMeshing = false; // use complex meshing if called for _forceSimplePrimMeshing = false; // use complex meshing if called for
m_meshLOD = 8; m_meshLOD = 8f;
m_sculptLOD = 32; m_sculptLOD = 32f;
m_maxSubSteps = 10; m_maxSubSteps = 10;
m_fixedTimeStep = 1f / 60f; m_fixedTimeStep = 1f / 60f;
@ -231,8 +231,8 @@ public class BSScene : PhysicsScene, IPhysicsParameters
_meshSculptedPrim = pConfig.GetBoolean("MeshSculptedPrim", _meshSculptedPrim); _meshSculptedPrim = pConfig.GetBoolean("MeshSculptedPrim", _meshSculptedPrim);
_forceSimplePrimMeshing = pConfig.GetBoolean("ForceSimplePrimMeshing", _forceSimplePrimMeshing); _forceSimplePrimMeshing = pConfig.GetBoolean("ForceSimplePrimMeshing", _forceSimplePrimMeshing);
m_meshLOD = pConfig.GetInt("MeshLevelOfDetail", m_meshLOD); m_meshLOD = pConfig.GetFloat("MeshLevelOfDetail", m_meshLOD);
m_sculptLOD = pConfig.GetInt("SculptLevelOfDetail", m_sculptLOD); m_sculptLOD = pConfig.GetFloat("SculptLevelOfDetail", m_sculptLOD);
m_maxSubSteps = pConfig.GetInt("MaxSubSteps", m_maxSubSteps); m_maxSubSteps = pConfig.GetInt("MaxSubSteps", m_maxSubSteps);
m_fixedTimeStep = pConfig.GetFloat("FixedTimeStep", m_fixedTimeStep); m_fixedTimeStep = pConfig.GetFloat("FixedTimeStep", m_fixedTimeStep);