Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
 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;
 }
        protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context)
        {
            DualTextureMaterialContent dual = new DualTextureMaterialContent();

            // Copy the base (diffuse) texture from the existing BasicEffect material.
            dual.Texture = ((BasicMaterialContent)material).Texture;

            // Add the second lightmap texture.
            dual.Texture2 = new ExternalReference <TextureContent>("lightmap.tga");

            return(base.ConvertMaterial(dual, context));
        }