Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Import Bone names #1

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Animation/Animation/Animations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Animations
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;
Expand Down Expand Up @@ -53,11 +54,12 @@ public class Animations
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
Expand Down Expand Up @@ -85,6 +87,14 @@ public void SetClip(Clip clip)
_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);
Expand Down
24 changes: 23 additions & 1 deletion Animation/ContentReaders/AnimationsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ protected override Animations Read(ContentReader input, Animations existingInsta
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
{
ReadAnimationClips(input, animations.Clips);
ReadBindPose(input, animations._bindPose);
ReadInvBindPose(input, animations._invBindPose);
ReadSkeletonHierarchy(input, animations._skeletonHierarchy);
ReadBoneMap(input, animations._boneMap);
}

return animations;
Expand Down Expand Up @@ -126,6 +128,26 @@ private List<int> ReadSkeletonHierarchy(ContentReader input, List<int> existingI

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;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ public class AnimationsContent
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,21 @@ public override AnimationsContent Process(NodeContent input, ContentProcessorCon
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ protected override void Write(ContentWriter output, AnimationsContent value)
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)
Expand Down Expand Up @@ -80,6 +81,20 @@ private void WriteSkeletonHierarchy(ContentWriter output, List<int> skeletonHier
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";
Expand Down
Binary file modified Samples/AnimationContent/Dude/dude.xnb
Binary file not shown.
Binary file modified bin/Release/Portable/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/Portable/Aether.Content.Pipeline.AnimationImporters.dll
Binary file not shown.
Binary file modified bin/Release/W10/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/W8_1/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/WP7_1/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/WP8/ARM/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.dll
Binary file not shown.
Binary file modified bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.exp
Binary file not shown.
Binary file modified bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.lib
Binary file not shown.
Binary file modified bin/Release/WP8/ARM/tainicom.Aether.Native.Animation.winmd
Binary file not shown.
Binary file modified bin/Release/WP8/x86/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/WP8/x86/tainicom.Aether.Native.Animation.dll
Binary file not shown.
Binary file modified bin/Release/WP8/x86/tainicom.Aether.Native.Animation.exp
Binary file not shown.
Binary file modified bin/Release/WP8/x86/tainicom.Aether.Native.Animation.lib
Binary file not shown.
Binary file modified bin/Release/WP8/x86/tainicom.Aether.Native.Animation.winmd
Binary file not shown.
Binary file modified bin/Release/Windows.XNA/Aether.Animation.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified bin/Release/Windows/Aether.Animation.dll
Binary file not shown.
Binary file modified bin/Release/Windows/Aether.Content.Pipeline.AnimationImporters.dll
Binary file not shown.
Binary file not shown.