ClipWriter.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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;
  17. using System.Collections.Generic;
  18. using Microsoft.Xna.Framework.Content.Pipeline;
  19. using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
  20. using nkast.Aether.Content.Pipeline.Animation;
  21. namespace nkast.Aether.Content.Pipeline.Serialization
  22. {
  23. [ContentTypeWriter]
  24. class ClipWriter : ContentTypeWriter<ClipContent>
  25. {
  26. protected override void Write(ContentWriter output, ClipContent value)
  27. {
  28. WriteDuration(output, value.Duration);
  29. WriteKeyframes(output, value.Keyframes);
  30. }
  31. private void WriteDuration(ContentWriter output, TimeSpan duration)
  32. {
  33. output.Write(duration.Ticks);
  34. }
  35. private void WriteKeyframes(ContentWriter output, IList<KeyframeContent> keyframes)
  36. {
  37. Int32 count = keyframes.Count;
  38. output.Write((Int32)count);
  39. for (int i = 0; i < count; i++)
  40. {
  41. KeyframeContent keyframe = keyframes[i];
  42. output.Write(keyframe.Bone);
  43. output.Write(keyframe.Time.Ticks);
  44. output.Write(keyframe.Transform.M11);
  45. output.Write(keyframe.Transform.M12);
  46. output.Write(keyframe.Transform.M13);
  47. output.Write(keyframe.Transform.M21);
  48. output.Write(keyframe.Transform.M22);
  49. output.Write(keyframe.Transform.M23);
  50. output.Write(keyframe.Transform.M31);
  51. output.Write(keyframe.Transform.M32);
  52. output.Write(keyframe.Transform.M33);
  53. output.Write(keyframe.Transform.M41);
  54. output.Write(keyframe.Transform.M42);
  55. output.Write(keyframe.Transform.M43);
  56. }
  57. return;
  58. }
  59. public override string GetRuntimeType(TargetPlatform targetPlatform)
  60. {
  61. return "nkast.Aether.Animation.Clip, Aether.Animation";
  62. }
  63. public override string GetRuntimeReader(TargetPlatform targetPlatform)
  64. {
  65. return "nkast.Aether.Animation.Content.ClipReader, Aether.Animation";
  66. }
  67. }
  68. }