forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NormalMappingModelProcessor.cs
60 lines (55 loc) · 2.25 KB
/
NormalMappingModelProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#region File Description
//-----------------------------------------------------------------------------
// NormalMappingModelProcessor.cs
//
// This file is subject to the terms and conditions defined in file 'LICENSE.txt', which is part of this source code package.
// MonoGame - Copyright (C) The MonoGame Team
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using System;
#endregion
namespace MonoGame.Tests.ContentPipeline
{
/// <summary>
/// The NormalMappingModelProcessor is used to change the material/effect applied
/// to a model. After going through this processor, the output model will be set
/// up to be rendered with NormalMapping.fx.
/// </summary>
[ContentProcessor(DisplayName = "Normal Mapping Validation")]
public class NormalMappingModelProcessor : ModelProcessor
{
public override ModelContent Process(NodeContent input,
ContentProcessorContext context)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
context.Logger.LogImportantMessage("processing: " + input.Name);
PreprocessSceneHierarchy(input, context, input.Name);
return base.Process(input, context);
}
/// <summary>
/// Recursively calls MeshHelper.CalculateTangentFrames for every MeshContent
/// object in the NodeContent scene.
/// </summary>
/// <param initialFileName="input">A node in the scene. The function should be called
/// with the root of the scene.</param>
private void PreprocessSceneHierarchy(NodeContent input,
ContentProcessorContext context, string inputName)
{
MeshContent mesh = input as MeshContent;
if (mesh != null)
{
MeshHelper.CalculateTangentFrames(mesh,
VertexChannelNames.TextureCoordinate(0),
VertexChannelNames.Tangent(0),
VertexChannelNames.Binormal(0));
}
}
}
}