- 「Windows Game」プロジェクトを作成し、「Microsoft.Xna.Framework.Content.Pipeline」と「Xclna.Xna.Animation.Content」を参照に追加して下さい。
- ビルドによってプロジェクトに入れるため、DLL をコンパイルして下さい。DLL は「(プロジェクトのディレクトリ)/bin/debug/」に現れます。
- コンパイルされた DLL をコンテントパイプラインの参照として、ドワーフのアニメーションを表示するゲームプロジェクトに追加して下さい。新しいライブラリプロジェクトをリコンパイルする度に、DLL はゲームプロジェクトで自動的に更新されます。
- AnimatedModelProcessor クラスを継承した新しいプロセッサを作成し、ReplaceBasicEffects メソッドをオーバーライドして下さい。このメソッドは他の全ての処理後に呼び出されます。あなたは他の方法で独自に開発したエフェクトも設定できることを覚えておいて下さい。
[ContentProcessor]
public class MyProcessor : AnimatedModelProcessor
{
protected override void ReplaceBasicEffect(SkinningType skinningType,
Microsoft.Xna.Framework.Content.Pipeline.Processors.ModelMeshPartContent meshPart)
{
}
}
- ReplaceBasicEffect メソッドに次のソースコードを記述して下さい。「string myEffectPath」はエフェクトの絶対パスを設定しなければならないことに注意して下さい。
// Make sure we don't replace the basic effect on unskinned models
// This check should almost always be optional.
if (skinningType != SkinningType.None)
{
// The absolute file path of your effect
string myEffectPath = _absolute file path of your effect_;
// Create the effect material content
EffectMaterialContent myEffectContent = new EffectMaterialContent();
myEffectContent.Effect = new ExternalReference<EffectContent>(myEffectPath);
MaterialProcessor processor = new MaterialProcessor();
// Process the material so that it is using a compiled effect
processor.Process(myEffectContent, base.ProcessorContext);
// The textures have already been processed for you. If you want to change how they
// are processed you can override the ConvertMaterial method provided in XNA
TextureReferenceDictionary textureDict = meshPart.Material.Textures;
foreach (string key in textureDict.Keys)
{
myEffectContent.Textures.Add("BasicTexture", textureDict[key]);
break;
}
meshPart.Material = myEffectContent;
}
- ゲームプロジェクトで「dwarfmodel.x」のプロセッサに「MyProcessor」を設定して下さい。
- 最後に LoadGraphicsContent メソッドでビュー行列、プロジェクション行列に現在の値を設定して下さい。
// Add this to the LoadGraphicsContent method
foreach (ModelMesh mesh in model.Meshes)
{
for (int i = 0; i < mesh.MeshParts.Count; i++)
{
ModelMeshPart part = mesh.MeshParts[i];
part.Effect.Parameters["View"].SetValue(view);
part.Effect.Parameters["Projection"].SetValue(projection);
}
}
最終更新:2008年06月01日 05:02