/// <summary> /// Generates a new model content from an height map /// </summary> /// <param name="contentFolder">Content folder</param> /// <param name="heightMap">Height map</param> /// <param name="textures">Texture list</param> /// <param name="cellSize">Cell size</param> /// <param name="cellHeight">Cell height</param> /// <returns>Returns a new model content</returns> public static ModelContent FromHeightmap(string contentFolder, string heightMap, IEnumerable <string> textures, float cellSize, float cellHeight) { ModelContent modelContent = new ModelContent(); string texureName = "texture"; string materialName = "material"; string geoName = "geometry"; ImageContent heightMapImage = new ImageContent() { Streams = ContentManager.FindContent(contentFolder, heightMap), }; ImageContent textureImage = new ImageContent() { Streams = ContentManager.FindContent(contentFolder, textures), }; MaterialContent material = MaterialContent.Default; material.DiffuseTexture = texureName; HeightMap hm = HeightMap.FromStream(heightMapImage.Stream, null); hm.BuildGeometry(cellSize, cellHeight, out var vertices, out var indices); SubMeshContent geo = new SubMeshContent(Topology.TriangleList, materialName, true, false); geo.SetVertices(vertices); geo.SetIndices(indices); modelContent.Images.Add(texureName, textureImage); modelContent.Materials.Add(materialName, material); modelContent.Geometry.Add(geoName, materialName, geo); return(modelContent); }