BulletSim: add terrainImplementation parameter with default to Mesh.

connector_plugin
Robert Adams 2012-11-21 10:37:40 -08:00
parent 2dc7e9d3fa
commit a59368c4a1
3 changed files with 46 additions and 5 deletions

View File

@ -1145,6 +1145,11 @@ public sealed class BSScene : PhysicsScene, IPhysicsParameters
(s,p,l,v) => { s.UpdateParameterObject(ref s.m_params[0].contactProcessingThreshold, p, l, v); },
(s,o,v) => { BulletSimAPI.SetContactProcessingThreshold2(o.PhysBody.ptr, v); } ),
new ParameterDefn("TerrainImplementation", "Type of shape to use for terrain (0=heightmap, 1=mesh)",
(float)BSTerrainPhys.TerrainImplementation.Mesh,
(s,cf,p,v) => { s.m_params[0].terrainImplementation = cf.GetFloat(p,v); },
(s) => { return s.m_params[0].terrainImplementation; },
(s,p,l,v) => { s.m_params[0].terrainImplementation = v; } ),
new ParameterDefn("TerrainFriction", "Factor to reduce movement against terrain surface" ,
0.5f,
(s,cf,p,v) => { s.m_params[0].terrainFriction = cf.GetFloat(p, v); },

View File

@ -44,6 +44,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin
// The physical implementation of the terrain is wrapped in this class.
public abstract class BSTerrainPhys : IDisposable
{
public enum TerrainImplementation
{
Heightmap = 0,
Mesh = 1
}
public BSScene PhysicsScene { get; private set; }
// Base of the region in world coordinates. Coordinates inside the region are relative to this.
public Vector3 TerrainBase { get; private set; }
@ -246,12 +252,27 @@ public sealed class BSTerrainManager
// Release any physical memory it may be using.
terrainPhys.Dispose();
BSTerrainPhys newTerrainPhys = null; ;
if (MegaRegionParentPhysicsScene == null)
{
// BSTerrainPhys newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id,
// heightMap, minCoords, maxCoords);
BSTerrainPhys newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id,
// TODO: redo terrain implementation selection to be centralized (there is another
// use below) and to accept an asset specification (for a mesh).
switch ((int)PhysicsScene.Params.terrainImplementation)
{
case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id,
heightMap, minCoords, maxCoords);
break;
case (int)BSTerrainPhys.TerrainImplementation.Mesh:
newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id,
heightMap, minCoords, maxCoords);
break;
default:
PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. type={1}/{2}",
LogHeader, (int)PhysicsScene.Params.terrainImplementation, PhysicsScene.Params.terrainImplementation);
break;
}
m_terrains.Add(terrainRegionBase, newTerrainPhys);
m_terrainModified = true;
@ -292,8 +313,22 @@ public sealed class BSTerrainManager
{
DetailLog("{0},UpdateTerrain:NewTerrain,taint,baseX={1},baseY={2}",
BSScene.DetailLogZero, minCoordsX.X, minCoordsX.Y);
BSTerrainPhys newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase,
newTerrainID, heightMapX, minCoordsX, maxCoordsX);
BSTerrainPhys newTerrainPhys = null;
switch ((int)PhysicsScene.Params.terrainImplementation)
{
case (int)BSTerrainPhys.TerrainImplementation.Heightmap:
newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id,
heightMap, minCoords, maxCoords);
break;
case (int)BSTerrainPhys.TerrainImplementation.Mesh:
newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id,
heightMap, minCoords, maxCoords);
break;
default:
PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. type={1}/{2}",
LogHeader, (int)PhysicsScene.Params.terrainImplementation, PhysicsScene.Params.terrainImplementation);
break;
}
m_terrains.Add(terrainRegionBase, newTerrainPhys);
m_terrainModified = true;

View File

@ -283,6 +283,7 @@ public struct ConfigurationParameters
public float ccdSweptSphereRadius;
public float contactProcessingThreshold;
public float terrainImplementation;
public float terrainFriction;
public float terrainHitFraction;
public float terrainRestitution;