For some reason server-side, BEPU renders a very low quality model of my heightmap. I am using brightness information from a 32bit tif file that I generated in Blender. Client side I am using unity's terrain as the display version. Even when downgrading to 16 bit png, client-side everything renders nicely. Server-side clearly something went wrong because when my player (sphere) moves along the map I get HUGE jumps as I move up slopes. At first I thought my heightmap was inverted but when I down scaled on the y-axis I noticed those jumps instead of the player just sinking through hills.
Here is the code I use to generate my terrain:
Code: Select all
public static Terrain CreateFromBitmap(string path_to_config, string path_to_bmp, Vector3 posOffset)
{
Bitmap heightmap = new Bitmap(path_to_bmp);
int width, length;
float xScale = 1, zScale = 1, heightScale = 1;
#region Get heightmap settings from config file
XmlDocument config = new XmlDocument();
config.Load(path_to_config);
width = Convert.ToInt32(config.SelectSingleNode("Config/Width").InnerText);
length = Convert.ToInt32(config.SelectSingleNode("Config/Length").InnerText);
xScale = Convert.ToSingle(config.SelectSingleNode("Config/xScale").InnerText);
zScale = Convert.ToSingle(config.SelectSingleNode("Config/zScale").InnerText);
heightScale = Convert.ToSingle(config.SelectSingleNode("Config/yScale").InnerText);
if (width <= 0 || length <= 0 || xScale <= 0 || zScale <= 0 || heightScale <= 0)
return null;
#endregion
float[,] heights = new float[width, length];
//populate heights array based on pixel brightness levels
for (int x = 0; x < width; x++)
{
for (int z = 0; z < length; z++)
{
heights[x, z] = heightmap.GetPixel(x, z).GetBrightness();
}
}
Terrain terrain = new Terrain(heights, new AffineTransform(new Vector3(-xScale, heightScale, -zScale),
Quaternion.Identity,
new Vector3(posOffset.X, posOffset.Y, posOffset.Z)));
terrain.Shape.QuadTriangleOrganization = BEPUphysics.CollisionShapes.QuadTriangleOrganization.BottomRightUpperLeft;
terrain.Thickness = 1;
return terrain;
}
Another thing I noted is my player doesn't "sit" as expected on the terrain. For example my player is a sphere with radius 0.5, my y-position would be something like 0.498... even on ground defined to be at the 0 level (pure black on the heightmap). This wasn't a problem using XNA.
Final question...if I spawn an entity at the level of the terrain would it fall through? For example say I have a completely flat terrain (a plane at y =0). I spawn a cube of dimensions (1,1,1) with its center 0.5 units above the terrain. Will it fall through? Do I need to spawn it slightly above the terrain so it falls into place?