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


最終更新:2008年06月01日 05:02