cmq penso che quello sia un esempio vecchio (tipo per 1.0 o 2.0), io faccio così:
namespace NormalMappingProcessor
{
[ContentProcessor(DisplayName = "Model - ShipGame Normal Mapping")]
public class NormalMappingModelProcessor : ModelProcessor
{
public const string TextureMapKey = "Texture";
public const string NormalMapKey = "Bump0";
public const string SpecularMapKey = "Specular0";
public const string GlowMapKey = "Emissive0";
public override ModelContent Process(NodeContent input,
ContentProcessorContext context)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
PreprocessSceneHierarchy(input);
return base.Process(input, context);
}
private void PreprocessSceneHierarchy(NodeContent input)
{
MeshContent mesh = input as MeshContent;
if (mesh != null)
{
MeshHelper.CalculateTangentFrames(mesh,
VertexChannelNames.TextureCoordinate(0),
VertexChannelNames.Tangent(0),
VertexChannelNames.Binormal(0));
foreach (GeometryContent geometry in mesh.Geometry)
{
if (false == geometry.Material.Textures.ContainsKey(TextureMapKey))
geometry.Material.Textures.Add(TextureMapKey,
new ExternalReference<TextureContent>(
"null_color.tga"));
if (false == geometry.Material.Textures.ContainsKey(NormalMapKey))
geometry.Material.Textures.Add(NormalMapKey,
new ExternalReference<TextureContent>(
"null_normal.tga"));
if (false == geometry.Material.Textures.ContainsKey(SpecularMapKey))
geometry.Material.Textures.Add(SpecularMapKey,
new ExternalReference<TextureContent>(
"null_specular.tga"));
if (false == geometry.Material.Textures.ContainsKey(GlowMapKey))
geometry.Material.Textures.Add(GlowMapKey,
new ExternalReference<TextureContent>(
"null_glow.tga"));
}
}
foreach (NodeContent child in input.Children)
{
PreprocessSceneHierarchy(child);
}
}
static IList<string> acceptableVertexChannelNames =
new string[]
{
VertexChannelNames.TextureCoordinate(0),
VertexChannelNames.Normal(0),
VertexChannelNames.Binormal(0),
VertexChannelNames.Tangent(0)
};
protected override void ProcessVertexChannel(GeometryContent geometry,
int vertexChannelIndex, ContentProcessorContext context)
{
String vertexChannelName =
geometry.Vertices.Channels[vertexChannelIndex].Name;
// if this vertex channel has an acceptable names, process it as normal.
if (acceptableVertexChannelNames.Contains(vertexChannelName))
{
base.ProcessVertexChannel(geometry, vertexChannelIndex, context);
}
// otherwise, remove it from the vertex channels; it's just extra data
// we don't need.
else
{
geometry.Vertices.Channels.Remove(vertexChannelName);
}
}
protected override MaterialContent ConvertMaterial(MaterialContent material,
ContentProcessorContext context)
{
EffectMaterialContent normalMappingMaterial = new EffectMaterialContent();
normalMappingMaterial.Effect = new ExternalReference<EffectContent>
("shaders/NormalMapping.fx");
foreach (KeyValuePair<String, ExternalReference<TextureContent>> texture
in material.Textures)
{
normalMappingMaterial.Textures.Add(texture.Key, texture.Value);
}
return context.Convert<MaterialContent, MaterialContent>
(normalMappingMaterial, typeof(MaterialProcessor).Name);
}
}
}