Generated Geometry Sample
This sample shows how 3D models can be generated by code during the XNA Framework Content Pipeline build process.Sample Overview
The sample renders a simple terrain with a sky behind it. The input data consists entirely of textures: a height-field bitmap describing the terrain, and a sky bitmap. Custom content pipeline processors convert the height-field bitmap into geometry, and generate a skydome mesh for rendering the sky texture.
How the Sample Works
The TerrainProcessor converts an input height-field bitmap into a 3D model by using the MeshBuilder helper class provided by XNA. It creates a grid of vertices with heights taken from the input bitmap data, and then creates triangles connecting these vertices. It creates a material, sets this to use the rocks.bmp texture, and applies it to the generated terrain. Finally, it chains to the built-in ModelProcessor, so the output data can be converted into a suitable run-time format.
The SkyProcessor works in a similar way. It creates a cylinder model, wraps the input sky texture around this, and then creates a wrapper Sky class that uses a customized projection transform to make sure the sky will always be rendered centered on the camera position, and that it will be drawn as the most distant thing in the scene behind all other geometry.