Sfoglia il codice sorgente

Import Bone names (#1)

Nikos Kastellanos 8 anni fa
parent
commit
4a5ba827ae
27 ha cambiato i file con 56 aggiunte e 5 eliminazioni
  1. 11 1
      Animation/Animation/Animations.cs
  2. 23 1
      Animation/ContentReaders/AnimationsReader.cs
  3. 3 1
      Content.Pipeline/AnimationImporters/Animation/AnimationsContent.cs
  4. 4 2
      Content.Pipeline/AnimationImporters/Processors/AnimationsProcessor.cs
  5. 15 0
      Content.Pipeline/AnimationImporters/Serialization/AnimationsWriter.cs
  6. BIN
      Samples/AnimationContent/Dude/dude.xnb
  7. BIN
      bin/Release/Portable/Aether.Animation.dll
  8. BIN
      bin/Release/Portable/Aether.Content.Pipeline.AnimationImporters.dll
  9. BIN
      bin/Release/W10/Aether.Animation.dll
  10. BIN
      bin/Release/W8_1/Aether.Animation.dll
  11. BIN
      bin/Release/WP7_1/Aether.Animation.dll
  12. BIN
      bin/Release/WP8/ARM/Aether.Animation.dll
  13. BIN
      bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.dll
  14. BIN
      bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.exp
  15. BIN
      bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.lib
  16. BIN
      bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.winmd
  17. BIN
      bin/Release/WP8/x86/Aether.Animation.dll
  18. BIN
      bin/Release/WP8/x86/tainicom.Aether.Native.Animation.dll
  19. BIN
      bin/Release/WP8/x86/tainicom.Aether.Native.Animation.exp
  20. BIN
      bin/Release/WP8/x86/tainicom.Aether.Native.Animation.lib
  21. BIN
      bin/Release/WP8/x86/tainicom.Aether.Native.Animation.winmd
  22. BIN
      bin/Release/Windows.XNA/Aether.Animation.dll
  23. BIN
      bin/Release/Windows.XNA/Aether.Content.Pipeline.AnimationImporters.dll
  24. BIN
      bin/Release/Windows.XNA/Aether.Content.Pipeline.GraphicsImporters.dll
  25. BIN
      bin/Release/Windows/Aether.Animation.dll
  26. BIN
      bin/Release/Windows/Aether.Content.Pipeline.AnimationImporters.dll
  27. BIN
      bin/Release/Windows/Aether.Content.Pipeline.GraphicsImporters.dll

+ 11 - 1
Animation/Animation/Animations.cs

@@ -25,6 +25,7 @@ namespace tainicom.Aether.Animation
         internal List<Matrix> _bindPose;
         internal List<Matrix> _invBindPose; // TODO: convert those from List<T> to simple T[] arrays.
         internal List<int> _skeletonHierarchy;
+        internal Dictionary<string, int> _boneMap;
 
         private Matrix[] _boneTransforms;
         private Matrix[] _worldTransforms;
@@ -53,11 +54,12 @@ namespace tainicom.Aether.Animation
         public Matrix[] AnimationTransforms { get { return _animationTransforms; } }
 
 
-        internal Animations(List<Matrix> bindPose, List<Matrix> invBindPose, List<int> skeletonHierarchy, Dictionary<string, Clip> clips)
+        internal Animations(List<Matrix> bindPose, List<Matrix> invBindPose, List<int> skeletonHierarchy, Dictionary<string, int> boneMap, Dictionary<string, Clip> clips)
         {
             _bindPose = bindPose;
             _invBindPose = invBindPose;
             _skeletonHierarchy = skeletonHierarchy;
+            _boneMap = boneMap;
             Clips = clips;
             
             // initialize
@@ -85,6 +87,14 @@ namespace tainicom.Aether.Animation
             _bindPose.CopyTo(_boneTransforms, 0);
         }
         
+        public int GetBoneIndex(string boneName)
+        {
+            int boneIndex;
+            if (!_boneMap.TryGetValue(boneName, out boneIndex))
+                boneIndex = -1;
+            return boneIndex;
+        }
+
         public void Update(TimeSpan time, bool relativeToCurrentTime, Matrix rootTransform)
         {
             UpdateBoneTransforms(time, relativeToCurrentTime);

+ 23 - 1
Animation/ContentReaders/AnimationsReader.cs

@@ -33,7 +33,8 @@ namespace tainicom.Aether.Animation.Content
                 List<Matrix> bindPose = ReadBindPose(input, null);
                 List<Matrix> invBindPose = ReadInvBindPose(input, null);
                 List<int> skeletonHierarchy = ReadSkeletonHierarchy(input, null);
-                animations = new Animations(bindPose, invBindPose, skeletonHierarchy, clips);
+                Dictionary<string, int> boneMap = ReadBoneMap(input, null);
+                animations = new Animations(bindPose, invBindPose, skeletonHierarchy, boneMap, clips);
             }
             else
             {
@@ -41,6 +42,7 @@ namespace tainicom.Aether.Animation.Content
                 ReadBindPose(input, animations._bindPose);
                 ReadInvBindPose(input, animations._invBindPose);
                 ReadSkeletonHierarchy(input, animations._skeletonHierarchy);
+                ReadBoneMap(input, animations._boneMap);
             }
 
             return animations;
@@ -126,6 +128,26 @@ namespace tainicom.Aether.Animation.Content
 
             return skeletonHierarchy;
         }
+
+        private Dictionary<string, int> ReadBoneMap(ContentReader input, Dictionary<string, int> existingInstance)
+        {
+            Dictionary<string, int> boneMap = existingInstance;
+
+            int count = input.ReadInt32();
+            if (boneMap == null)
+                boneMap = new Dictionary<string, int>(count);
+
+            for (int boneIndex = 0; boneIndex < count; boneIndex++)
+            {
+                string key = input.ReadString();
+                if (existingInstance == null)
+                    boneMap.Add(key, boneIndex);
+                else
+                    boneMap[key] = boneIndex;
+            }
+
+            return boneMap;
+        }
         
     }
     

+ 3 - 1
Content.Pipeline/AnimationImporters/Animation/AnimationsContent.cs

@@ -24,14 +24,16 @@ namespace tainicom.Aether.Content.Pipeline.Animation
         public List<Matrix> BindPose { get; private set; }
         public List<Matrix> InvBindPose { get; private set; }
         public List<int> SkeletonHierarchy { get; private set; }
+        public List<string> BoneNames { get; private set; }
         public Dictionary<string, ClipContent> Clips { get; private set; }
 
 
-        internal AnimationsContent(List<Matrix> bindPose, List<Matrix> invBindPose, List<int> skeletonHierarchy, Dictionary<string, ClipContent> clips)
+        internal AnimationsContent(List<Matrix> bindPose, List<Matrix> invBindPose, List<int> skeletonHierarchy, List<string> boneNames, Dictionary<string, ClipContent> clips)
         {
             BindPose = bindPose;
             InvBindPose = invBindPose;
             SkeletonHierarchy = skeletonHierarchy;
+            BoneNames = boneNames;
             Clips = clips;
         }
     }

+ 4 - 2
Content.Pipeline/AnimationImporters/Processors/AnimationsProcessor.cs

@@ -90,19 +90,21 @@ namespace tainicom.Aether.Content.Pipeline.Processors
             List<Matrix> bindPose = new List<Matrix>();
             List<Matrix> invBindPose = new List<Matrix>();
             List<int> skeletonHierarchy = new List<int>();
+            List<string> boneNames = new List<string>();
 
-            foreach (BoneContent bone in bones)
+            foreach(var bone in bones)
             {
                 bindPose.Add(bone.Transform);
                 invBindPose.Add(Matrix.Invert(bone.AbsoluteTransform));
                 skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent));
+                boneNames.Add(bone.Name);
             }
 
             // Convert animation data to our runtime format.
             Dictionary<string, ClipContent> clips;
             clips = ProcessAnimations(input, context, skeleton.Animations, bones, GenerateKeyframesFrequency);
 
-            return new AnimationsContent(bindPose, invBindPose, skeletonHierarchy, clips);
+            return new AnimationsContent(bindPose, invBindPose, skeletonHierarchy, boneNames, clips);
         }
         
         /// <summary>

+ 15 - 0
Content.Pipeline/AnimationImporters/Serialization/AnimationsWriter.cs

@@ -31,6 +31,7 @@ namespace tainicom.Aether.Content.Pipeline.Serialization
             WriteBindPose(output, value.BindPose);
             WriteInvBindPose(output, value.InvBindPose);
             WriteSkeletonHierarchy(output, value.SkeletonHierarchy);
+            WriteBoneNames(output, value.BoneNames);
         }
 
         private void WriteClips(ContentWriter output, Dictionary<string, ClipContent> clips)
@@ -80,6 +81,20 @@ namespace tainicom.Aether.Content.Pipeline.Serialization
             return;
         }
     
+        private void WriteBoneNames(ContentWriter output, List<string> boneNames)
+        {
+            Int32 count = boneNames.Count;
+            output.Write((Int32)count);
+            
+            for (int boneIndex = 0; boneIndex < count; boneIndex++)
+            {
+                var boneName = boneNames[boneIndex];
+                output.Write(boneName);
+            }
+
+            return;
+        }
+
         public override string GetRuntimeType(TargetPlatform targetPlatform)
         {
             return "tainicom.Aether.Animation.Animations, Aether.Animation";

BIN
Samples/AnimationContent/Dude/dude.xnb


BIN
bin/Release/Portable/Aether.Animation.dll


BIN
bin/Release/Portable/Aether.Content.Pipeline.AnimationImporters.dll


BIN
bin/Release/W10/Aether.Animation.dll


BIN
bin/Release/W8_1/Aether.Animation.dll


BIN
bin/Release/WP7_1/Aether.Animation.dll


BIN
bin/Release/WP8/ARM/Aether.Animation.dll


BIN
bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.dll


BIN
bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.exp


BIN
bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.lib


BIN
bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.winmd


BIN
bin/Release/WP8/x86/Aether.Animation.dll


BIN
bin/Release/WP8/x86/tainicom.Aether.Native.Animation.dll


BIN
bin/Release/WP8/x86/tainicom.Aether.Native.Animation.exp


BIN
bin/Release/WP8/x86/tainicom.Aether.Native.Animation.lib


BIN
bin/Release/WP8/x86/tainicom.Aether.Native.Animation.winmd


BIN
bin/Release/Windows.XNA/Aether.Animation.dll


BIN
bin/Release/Windows.XNA/Aether.Content.Pipeline.AnimationImporters.dll


BIN
bin/Release/Windows.XNA/Aether.Content.Pipeline.GraphicsImporters.dll


BIN
bin/Release/Windows/Aether.Animation.dll


BIN
bin/Release/Windows/Aether.Content.Pipeline.AnimationImporters.dll


BIN
bin/Release/Windows/Aether.Content.Pipeline.GraphicsImporters.dll