/// <summary> /// Procesar el mapa de alturas /// </summary> /// <param name="input">Información del escenario de entrada</param> /// <param name="context">Contexto de procesado</param> /// <returns>Devuelve la información de escenario leída</returns> public override SceneryInfo Process(SceneryFile input, ContentProcessorContext context) { // Cargar la textura del mapa de alturas Texture2DContent terrain = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.HeightMapFile), null); // Obtener el mapa de alturas HeightMap heightMap = this.BuildHeightMap(terrain, input.HeightMapCellScale, context); // Generar los vértices e inicializar el buffer de vértices VertexMultitextured[] vertList = heightMap.BuildVertices( input.HeightMapCellSize, input.ProportionTexture1, input.ProportionTexture2, input.ProportionTexture3); VertexBufferContent vertexBuffer = new VertexBufferContent(VertexMultitextured.SizeInBytes * vertList.Length); vertexBuffer.Write <VertexMultitextured>(0, VertexMultitextured.SizeInBytes, vertList, context.TargetPlatform); // Generar los índices e inicializar los buffers de índices double lowOrderLevels = (Math.Sqrt(heightMap.DataLength) - 1) * 0.5f; int levelCount = Convert.ToInt32(Math.Log(lowOrderLevels, 4.0d)); SceneryNodeInfo sceneryIndexInfo = SceneryNodeInfo.Build( vertList, heightMap.Width, heightMap.Deep, levelCount); // Efecto de renderización CompiledEffect effect = Effect.CompileEffectFromFile( input.EffectFile, null, null, CompilerOptions.None, context.TargetPlatform); // Texturas del terreno Texture2DContent texture1 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.Texture1File), null); Texture2DContent texture2 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.Texture2File), null); Texture2DContent texture3 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.Texture3File), null); Texture2DContent texture4 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.Texture4File), null); Texture2DContent detailTexture1 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.DetailTexture1File), null); Texture2DContent detailTexture2 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.DetailTexture2File), null); Texture2DContent detailTexture3 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.DetailTexture3File), null); Texture2DContent detailTexture4 = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.DetailTexture4File), null); CompiledEffect billboardEffect = Effect.CompileEffectFromFile( input.BillboardEffectFile, null, null, CompilerOptions.None, context.TargetPlatform); Texture2DContent billboardGrassTexture = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.BillboardGrassTextureFile), null); Texture2DContent billboardTreeTexture = context.BuildAndLoadAsset <Texture2DContent, Texture2DContent>(new ExternalReference <Texture2DContent>(input.BillboardTreeTextureFile), null); int billboardsPerTriangle = input.BillboardsPerTriangle; float billboardTreesPercent = input.BillboardTreesPercent; return(new SceneryInfo() { Terrain = terrain, TerrainBuffer = vertexBuffer, TerrainBufferVertexCount = vertList.Length, TerrainInfo = sceneryIndexInfo, Effect = effect, Texture1 = texture1, Texture2 = texture2, Texture3 = texture3, Texture4 = texture4, DetailTexture1 = detailTexture1, DetailTexture2 = detailTexture2, DetailTexture3 = detailTexture3, DetailTexture4 = detailTexture4, BillboardEffect = billboardEffect, BillboardGrass = billboardGrassTexture, BillboardTree = billboardTreeTexture, BillboardsPerTriangle = billboardsPerTriangle, BillboardTreesPercent = billboardTreesPercent, }); }