AnimationsWriter.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 AnimationsDataWriter : ContentTypeWriter<AnimationsContent>
  25. {
  26. protected override void Write(ContentWriter output, AnimationsContent value)
  27. {
  28. WriteClips(output, value.Clips);
  29. WriteBindPose(output, value.BindPose);
  30. WriteInvBindPose(output, value.InvBindPose);
  31. WriteSkeletonHierarchy(output, value.SkeletonHierarchy);
  32. WriteBoneNames(output, value.BoneNames);
  33. }
  34. private void WriteClips(ContentWriter output, Dictionary<string, ClipContent> clips)
  35. {
  36. Int32 count = clips.Count;
  37. output.Write((Int32)count);
  38. foreach (var clip in clips)
  39. {
  40. output.Write(clip.Key);
  41. output.WriteObject<ClipContent>(clip.Value);
  42. }
  43. return;
  44. }
  45. private void WriteBindPose(ContentWriter output, List<Microsoft.Xna.Framework.Matrix> bindPoses)
  46. {
  47. Int32 count = bindPoses.Count;
  48. output.Write((Int32)count);
  49. for (int i = 0; i < count; i++)
  50. output.Write(bindPoses[i]);
  51. return;
  52. }
  53. private void WriteInvBindPose(ContentWriter output, List<Microsoft.Xna.Framework.Matrix> invBindPoses)
  54. {
  55. Int32 count = invBindPoses.Count;
  56. output.Write((Int32)count);
  57. for (int i = 0; i < count; i++)
  58. output.Write(invBindPoses[i]);
  59. return;
  60. }
  61. private void WriteSkeletonHierarchy(ContentWriter output, List<int> skeletonHierarchy)
  62. {
  63. Int32 count = skeletonHierarchy.Count;
  64. output.Write((Int32)count);
  65. for (int i = 0; i < count; i++)
  66. output.Write((Int32)skeletonHierarchy[i]);
  67. return;
  68. }
  69. private void WriteBoneNames(ContentWriter output, List<string> boneNames)
  70. {
  71. Int32 count = boneNames.Count;
  72. output.Write((Int32)count);
  73. for (int boneIndex = 0; boneIndex < count; boneIndex++)
  74. {
  75. string boneName = boneNames[boneIndex];
  76. output.Write(boneName);
  77. }
  78. return;
  79. }
  80. public override string GetRuntimeType(TargetPlatform targetPlatform)
  81. {
  82. return "nkast.Aether.Animation.Animations, Aether.Animation";
  83. }
  84. public override string GetRuntimeReader(TargetPlatform targetPlatform)
  85. {
  86. return "nkast.Aether.Animation.Content.AnimationsReader, Aether.Animation";
  87. }
  88. }
  89. }