GpuAnimatedModelProcessor.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #region License
  2. // Copyright 2011-2016 Kastellanos Nikolaos
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #endregion
  16. using System.ComponentModel;
  17. using Microsoft.Xna.Framework.Content.Pipeline;
  18. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  19. using Microsoft.Xna.Framework.Content.Pipeline.Processors;
  20. using Microsoft.Xna.Framework.Graphics;
  21. namespace nkast.Aether.Content.Pipeline.Processors
  22. {
  23. [ContentProcessor(DisplayName = "GPU AnimatedModel - Aether")]
  24. public class GpuAnimatedModelProcessor : ModelProcessor
  25. {
  26. private int _maxBones = SkinnedEffect.MaxBones;
  27. private int _generateKeyframesFrequency = 0;
  28. private bool _fixRealBoneRoot = false;
  29. #if !PORTABLE
  30. [DisplayName("MaxBones")]
  31. #endif
  32. [DefaultValue(SkinnedEffect.MaxBones)]
  33. public virtual int MaxBones
  34. {
  35. get { return _maxBones; }
  36. set { _maxBones = value; }
  37. }
  38. #if !PORTABLE
  39. [DisplayName("Generate Keyframes Frequency")]
  40. #endif
  41. [DefaultValue(0)] // (0=no, 30=30fps, 60=60fps)
  42. public virtual int GenerateKeyframesFrequency
  43. {
  44. get { return _generateKeyframesFrequency; }
  45. set { _generateKeyframesFrequency = value; }
  46. }
  47. #if !PORTABLE
  48. [DisplayName("Fix BoneRoot from MG importer")]
  49. #endif
  50. [DefaultValue(false)]
  51. public virtual bool FixRealBoneRoot
  52. {
  53. get { return _fixRealBoneRoot; }
  54. set { _fixRealBoneRoot = value; }
  55. }
  56. [DefaultValue(MaterialProcessorDefaultEffect.SkinnedEffect)]
  57. public override MaterialProcessorDefaultEffect DefaultEffect
  58. {
  59. get { return base.DefaultEffect; }
  60. set { base.DefaultEffect = value; }
  61. }
  62. public GpuAnimatedModelProcessor()
  63. {
  64. DefaultEffect = MaterialProcessorDefaultEffect.SkinnedEffect;
  65. }
  66. public override ModelContent Process(NodeContent input, ContentProcessorContext context)
  67. {
  68. var animationProcessor = new AnimationsProcessor();
  69. animationProcessor.MaxBones = this.MaxBones;
  70. animationProcessor.GenerateKeyframesFrequency = this.GenerateKeyframesFrequency;
  71. animationProcessor.FixRealBoneRoot = this._fixRealBoneRoot;
  72. var animation = animationProcessor.Process(input, context);
  73. ModelContent model = base.Process(input, context);
  74. model.Tag = animation;
  75. return model;
  76. }
  77. }
  78. }