Getting Started - `File not found`..

Jun 19, 2010 at 1:07 AM
Edited Jun 19, 2010 at 1:15 AM

Hi,

 

I`m guessing you guys are busy with questions - here`s mine ( hopefully an easy one ):

 

I`ve added my x model into the content folder, but the Content.Load method is throwing a `File not found`.  The model is definately there.  Is my project referencing some other folder root?

 

Code is adapted from the Blend sample into a fresh XNA 3.1 Windows project as follows ( with screen grab of my SolutionExplorer ) :

 

solutionexplorer.jpg

using System;
using System.Collections.Generic;
using System.Linq;
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 Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using XNAnimation;
using XNAnimation.Controllers;
using XNAnimation.Effects;


namespace CharTest9
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        Matrix[] absoluteBoneTransforms;
        Matrix cameraView;
        Matrix cameraProjection;

        KeyboardState lastKeyboradState;

        SkinnedModel skinnedModel;

        int activeSkinnedModelIndex = 0;

        readonly String[] skinnedModelFiles = {"legsTest"};

        readonly Matrix[] worldTransformations = {Matrix.CreateTranslation(0, -12, 0)};

        AnimationController animationController;

        int activeAnimationClipIndex = 0;

        bool enableInterpolation = false;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
           // graphics.PreferMultiSampling = true;

            Content.RootDirectory = "Content";
        }

        private void LoadSkinnedModel()
        {
            // Loads an animated model
            skinnedModel = Content.Load<SkinnedModel>(skinnedModelFiles[activeSkinnedModelIndex]);

            // Copy the absolute transformation of each node
            absoluteBoneTransforms = new Matrix[skinnedModel.Model.Bones.Count];
            skinnedModel.Model.CopyBoneTransformsTo(absoluteBoneTransforms);

            // Creates an animation controller
            animationController = new AnimationController(skinnedModel.SkeletonBones);

            // Start the first animation stored in the AnimationClips dictionary
            animationController.StartClip(
                skinnedModel.AnimationClips.Values[activeAnimationClipIndex]);
        }
        
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Setup camera
            cameraView = Matrix.CreateLookAt(new Vector3(10, 15, 30), new Vector3(0, 2, 0), Vector3.Up);
            cameraProjection = Matrix.CreatePerspectiveFieldOfView(1, 1, 1, 1000);

            // Load a skinned model
            activeSkinnedModelIndex = 0;
            activeAnimationClipIndex = 0;

            LoadSkinnedModel();

        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboradState = Keyboard.GetState();

            // Exit
            if (keyboradState.IsKeyDown(Keys.Escape))
                Exit();

            // 'Up' and 'Down' changes the animation speed
            if (keyboradState.IsKeyDown(Keys.Up))
            {
                animationController.Speed += 0.005f;
            }
            else if (keyboradState.IsKeyDown(Keys.Down))
            {
                animationController.Speed = (animationController.Speed < 0.1f) ?
                    0.1f : animationController.Speed - 0.005f;
            }

            // 'Left' and 'Right loop through the animations
            if (keyboradState.IsKeyDown(Keys.Left) && lastKeyboradState.IsKeyUp(Keys.Left))
            {
                activeAnimationClipIndex = ((activeAnimationClipIndex - 1) < 0) ?
                    skinnedModel.AnimationClips.Count - 1 : activeAnimationClipIndex - 1;
                animationController.CrossFade(skinnedModel.AnimationClips.Values[activeAnimationClipIndex],
                    TimeSpan.FromMilliseconds(300));
            }
            else if (keyboradState.IsKeyDown(Keys.Right) && lastKeyboradState.IsKeyUp(Keys.Right))
            {
                activeAnimationClipIndex = (activeAnimationClipIndex + 1) % skinnedModel.AnimationClips.Count;
                animationController.CrossFade(skinnedModel.AnimationClips.Values[activeAnimationClipIndex],
                    TimeSpan.FromMilliseconds(300));
            }

            // 'Enter' enable/disable animation interpolation
            if (keyboradState.IsKeyDown(Keys.Enter) && lastKeyboradState.IsKeyUp(Keys.Enter))
            {
                enableInterpolation = !enableInterpolation;

                if (enableInterpolation)
                {
                    animationController.TranslationInterpolation = InterpolationMode.Linear;
                    animationController.OrientationInterpolation = InterpolationMode.Spherical;
                    animationController.ScaleInterpolation = InterpolationMode.Linear;
                }
                else
                {
                    animationController.TranslationInterpolation = InterpolationMode.None;
                    animationController.OrientationInterpolation = InterpolationMode.None;
                    animationController.ScaleInterpolation = InterpolationMode.None;
                }
            }

            // 'Tab' changes the current animated model
            if (keyboradState.IsKeyDown(Keys.Tab) && lastKeyboradState.IsKeyUp(Keys.Tab))
            {
                activeSkinnedModelIndex = (activeSkinnedModelIndex + 1) % skinnedModelFiles.Length;
                activeAnimationClipIndex = 0;
                LoadSkinnedModel();
            }

            lastKeyboradState = keyboradState;

            // Update the animation according to the elapsed time
            animationController.Update(gameTime.ElapsedGameTime, Matrix.Identity);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // In this first version of the library the animated model is draw 
            // through an internal Model object
            foreach (ModelMesh modelMesh in skinnedModel.Model.Meshes)
            {
                foreach (SkinnedModelBasicEffect effect in modelMesh.Effects)
                {
                    // Setup world transform
                    effect.World = absoluteBoneTransforms[modelMesh.ParentBone.Index] *
                        worldTransformations[activeSkinnedModelIndex];

                    // Setup camera
                    effect.View = cameraView;
                    effect.Projection = cameraProjection;

                    // Set the animated bones to the model
                    effect.Bones = animationController.SkinnedBoneTransforms;

                    // OPTIONAL - Configure material
                    effect.Material.DiffuseColor = new Vector3(0.8f);
                    effect.Material.SpecularColor = new Vector3(0.3f);
                    effect.Material.SpecularPower = 8;

                    // OPTIONAL - Configure lights
                    effect.AmbientLightColor = new Vector3(0.1f);
                    effect.LightEnabled = true;
                    effect.EnabledLights = EnabledLights.One;
                    effect.PointLights[0].Color = Vector3.One;
                    effect.PointLights[0].Position = new Vector3(100);
                }

                // Draw a model mesh
                modelMesh.Draw();
            }

            base.Draw(gameTime);
        }
    }
}

 

Jul 22, 2010 at 9:33 PM
Edited Jul 22, 2010 at 9:34 PM
Try to change {"legsTest"} to {"Content\\legsTest"}