0
\$\begingroup\$

I'm trying to make multiple animations for multiple models in XNA 4.0 and I need to get the name of the model/asset from the content processor which is a custom one (XNA default I think), I'm trying doing this by the split method which requires reading from a file the animations but I need to get the model's name to match it with the files because I'll have several files for several models.

public override ModelContent Process(NodeContent input,
                                         ContentProcessorContext context)
    {
        ValidateMesh(input, context, null);

        // Find the skeleton.
        BoneContent skeleton = MeshHelper.FindSkeleton(input);

        if (skeleton == null)
            throw new InvalidContentException("Input skeleton not found.");

        // We don't want to have to worry about different parts of the model being
        // in different local coordinate systems, so let's just bake everything.
        FlattenTransforms(input, skeleton);

        // Read the bind pose and skeleton hierarchy data.
        IList<BoneContent> bones = MeshHelper.FlattenSkeleton(skeleton);

        if (bones.Count > SkinnedEffect.MaxBones)
        {
            throw new InvalidContentException(string.Format(
                "Skeleton has {0} bones, but the maximum supported is {1}.",
                bones.Count, SkinnedEffect.MaxBones));
        }

        List<Matrix> bindPose = new List<Matrix>();
        List<Matrix> inverseBindPose = new List<Matrix>();
        List<int> skeletonHierarchy = new List<int>();

        foreach (BoneContent bone in bones)
        {
            bindPose.Add(bone.Transform);
            inverseBindPose.Add(Matrix.Invert(bone.AbsoluteTransform));
            skeletonHierarchy.Add(bones.IndexOf(bone.Parent as BoneContent));
        }

        // Convert animation data to our runtime format.
        Dictionary<string, AnimationClip> animationClips;
        animationClips = ProcessAnimations(skeleton.Animations, bones);

        //split animations
        animationClips = SplitAnimations(animationClips["Take 001"], @"F:\Education\GP\GP\Animations\defs.txt");

        // Chain to the base ModelProcessor class so it can convert the model data.
        ModelContent model = base.Process(input, context);

        // Store our custom animation data in the Tag property of the model.
        model.Tag = new SkinningData(animationClips, bindPose,
                                     inverseBindPose, skeletonHierarchy);

        return model;
    }

I want to replace the "defs" with the model/asset name to make it load the correct animations. Sorry if my question is vague or redundant. Thanks in advance. Is there something wrong with the question ? ._.!

\$\endgroup\$
0
\$\begingroup\$

I ended up doing something that might seem stupid and costly that I loop at all the files till I find the right one and ignoring the exception that I get if the animations doesn't match the model.

foreach (string file in Directory.EnumerateFiles(@"F:\Education\Animations", "*.txt"))
        {
            try
            {
                animationClips = SplitAnimations(animationClips["Take 001"], file);
            }
            catch (Exception e)
            {
                continue;
            }
        }
\$\endgroup\$
  • \$\begingroup\$ Which turned out not be correct in all cases. \$\endgroup\$ – The Wizard Of Code Feb 6 '15 at 17:43
0
\$\begingroup\$

Finally fixed by naming the parent joint of any model I have by the model's name then I get to read from the file I need by getting the name of the first bone in my mesh and excluding the extra '1' in the end of the string. Now each model will know which file to load for the animations without any fuzz.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.