Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Bone names #1

Merged
merged 1 commit into from Mar 28, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

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

}

@@ -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;
}
}
@@ -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>
@@ -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)
@@ -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";
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN +512 Bytes (100%) bin/Release/W10/Aether.Animation.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.