3 Replies - 1230 Views - Last Post: 11 April 2013 - 05:30 AM

#1 Lost_My_Password  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-November 12

Error: animationPlayer returns null when put into a new class. XNA 4

Posted 09 April 2013 - 01:33 PM

Hey there, I've been trying to clean up my primary game1.cs and have started using the updated "SkinnedModel(With Custom Anims) Pipeline". Long story short I wanted to make an external class instead of having my Game1 all mucked up with code. The animationPlayer is returning null and I'm not sure why. Can anybody help? Here's the AnimatedModel class I'm working on:





    class AnimatedModel
    {        
        AnimationPlayer animationPlayer;
        GraphicsDeviceManager graphics;
        GraphicsDevice device;

        ContentManager content;

        KeyboardState currentKBD, prevKBD;
        GamePadState currentGamePadState, prevGamePadState;

        float leftTriggerValue, rightTriggerValue;

        bool Jumping = false;

        enum modelState { Idle, Jumping, Walking, Turning_Left, Turning_Right, Walking_Backwards }
        modelState modelstate = modelState.Idle;

        Model model;
        Matrix world;
        Matrix view;
        Matrix projection;

        protected void Initialize()
        {
            content.RootDirectory = "Content";
            
            //Thought it had something to do with Initialize, but that didn't work.
            
            //SkinningData skinningData = model.Tag as SkinningData;
            //AnimationPlayer animationPlayer = new AnimationPlayer(skinningData);
        }

        public AnimatedModel(Model Model, Matrix World, Matrix View, Matrix Projection, Game Game)
        {
            device = Game.GraphicsDevice;
            model = Model;
                        
            Matrix[] transforms = new Matrix[model.Bones.Count];
            
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                world = transforms[mesh.ParentBone.Index];
            }
            
            
            view = View;
            projection = Projection;
                       
        }

        protected void LoadContent()
        {
            #region Load Animated Models

            model = content.Load<Model>("Models/bsod2");

            SkinningData skinningData = model.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            animationPlayer = new AnimationPlayer(skinningData);

            //animationPlayer.RegisteredEvents["WalkLoop"].Add("WalkLoopFrame", new AnimationPlayer.EventCallback(OnWalkLoop));

            AnimationClip clip = skinningData.AnimationClips["Idle"];

            animationPlayer.StartClip(clip);

            #endregion
        }

        protected void UnloadContent()
        {
            //content.Unload();
        }

        public void UpdateAnimatedModel(GameTime gameTime)
        {            

            animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
            
            HandleInput(gameTime);
                        
        }

        public void DrawAnimatedModel(Model Model, Matrix World, Matrix View, Matrix Projection)
        {
            #region SkinnedEffect
            
            foreach (ModelMesh mesh in model.Meshes)
            {
                Matrix[] bones = animationPlayer.GetSkinTransforms();

                foreach (SkinnedEffect effect in mesh.Effects)
                {  
                    effect.SetBoneTransforms(bones);
                    effect.World = world;
                    effect.View = view;
                    effect.Projection = projection;
                }

                mesh.Draw();
               
            }
            #endregion
        }



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SkinnedModel;



Is This A Good Question/Topic? 0
  • +

Replies To: Error: animationPlayer returns null when put into a new class. XNA 4

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9379
  • View blog
  • Posts: 35,225
  • Joined: 12-June 08

Re: Error: animationPlayer returns null when put into a new class. XNA 4

Posted 09 April 2013 - 01:34 PM

Wow.. VB6 is a far cry from C#/XNA.

Moving.
Was This Post Helpful? 0
  • +
  • -

#3 Lost_My_Password  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-November 12

Re: Error: animationPlayer returns null when put into a new class. XNA 4

Posted 09 April 2013 - 03:07 PM

Sorry mod! Had multiple DiC windows open and posted in the wrong one :X
Was This Post Helpful? 0
  • +
  • -

#4 oyyou  Icon User is offline

  • D.I.C Head

Reputation: 27
  • View blog
  • Posts: 184
  • Joined: 26-April 10

Re: Error: animationPlayer returns null when put into a new class. XNA 4

Posted 11 April 2013 - 05:30 AM

I'm no programming expert, but is it possible that you're trying to load something too soon?
So for example, you're doing all of that stuff in the constructor, and then some in the LoadContent.

Could it be that you're trying something too soon?
Also, the "model" is being assigned multiple things, once in the constructor and again it the LoadContent. You may just wanna try putting in some breakpoints and see where it's going wrong

E.G One near the end of your constructor and one near the end of your LoadContent.

If it was working before you moved it into it's own class, it's more than likely just an easy mistake you've made.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1