/// <summary> /// Generates a terrain mesh from an input heightfield texture. /// </summary> public override TerrainModelContent Process(Texture2DContent input, ContentProcessorContext context) { Texture2DContent texture = context.Convert <Texture2DContent, Texture2DContent>(input, "FloatingPointTextureProcessor"); PixelBitmapContent <float> heightfield = (PixelBitmapContent <float>)texture.Mipmaps[0]; float[,] heights = new float[heightfield.Width, heightfield.Height]; for (int y = 0; y < heightfield.Height; y++) { for (int x = 0; x < heightfield.Width; x++) { heights[x, y] = heightfield.GetPixel(x, y); } } HeightMapContent heightMap = new HeightMapContent(heightfield.Width, heightfield.Height, heights, VerticalScale, HorizontalScale); string directory = Path.GetDirectoryName(input.Identity.SourceFilename); string texture1 = Path.Combine(directory, ColorTexture); string texture2 = Path.Combine(directory, DetailTexture); // Create a material, and point it at our terrain texture. DualTextureMaterialContent material = new DualTextureMaterialContent { Texture = context.BuildAsset <TextureContent, TextureContent>(new ExternalReference <TextureContent>(texture1), null), Texture2 = context.BuildAsset <TextureContent, TextureContent>(new ExternalReference <TextureContent>(texture2), null), }; TerrainModelContentBuilder terrainModelContentBuilder = new TerrainModelContentBuilder(PatchSize, Tau, heightMap, material, DetailTextureTiling, HorizontalScale); return(terrainModelContentBuilder.Build(context)); }
public TerrainModelContentBuilder(int patchSize, float tau, HeightMapContent heightMap, DualTextureMaterialContent material, int detailTextureTiling, int horizontalScale) { _patchSize = patchSize; _tau = tau; _heightMap = heightMap; _material = material; _detailTextureTiling = detailTextureTiling; _horizontalScale = horizontalScale; }
public PatchContentBuilder(int patchSize, int patchOffsetX, int patchOffsetY, HeightMapContent heightMap, int numLevels, int detailTextureTiling, int horizontalScale) { _patchSize = patchSize; _patchOffsetX = patchOffsetX; _patchOffsetY = patchOffsetY; _heightMap = heightMap; _numLevels = numLevels; _detailTextureTiling = detailTextureTiling; _horizontalScale = horizontalScale; }
public LevelContentBuilder(HeightMapContent heightMap, int patchSize, int numLevels, int level, int startX, int endX, int startY, int endY) { _heightMap = heightMap; _patchSize = patchSize; _numLevels = numLevels; _level = level; _startX = startX; _endX = endX; _startY = startY; _endY = endY; }
public NormalMap(HeightMapContent heightMap) { _heightMap = heightMap; m_nWidth = heightMap.Width; m_nHeight = heightMap.Height; m_pNormals = new Vector3[m_nWidth, m_nHeight]; for (int x = 0; x < m_nWidth; ++x) { for (int y = 0; y < m_nHeight; ++y) { m_pNormals[x, y] = CalculateNormal(x, y); } } }