[color="#4a4a4a"]
public void Load(string modelFileName)
{
if (!_isInitialized)
Initialize();
_model = Game.Content.Load<Model>(GameAssetsPath.MODELS_PATH + modelFileName);
// Get the animated model data
Dictionary<string, object> modelTag = (Dictionary<string, object>)_model.Tag;
if (modelTag == null)
throw new InvalidOperationException("This is not a valid animated model.");
// Read tag data
if (modelTag.ContainsKey("AnimatedModelData"))
_animatedModelData = (AnimatedModelData)modelTag["AnimatedModelData"];
else
throw new InvalidOperationException("This is not a valid animated model.");
// Animation
_animationSpeed = 1.0f;
_activeAnimationKeyframe = 0;
_activeAnimationTime = TimeSpan.Zero;
if (_animatedModelData.Animations.Length > 0)
_activeAnimation = _animatedModelData.Animations[0];
_bones = new Matrix[_animatedModelData.BonesBindPose.Length];
_bonesAbsolute = new Matrix[_animatedModelData.BonesBindPose.Length];
_bonesAnimation = new Matrix[_animatedModelData.BonesBindPose.Length];
_bonesTransform = new Matrix[_animatedModelData.BonesBindPose.Length];
for (int i = 0; i < _bones.Length; i++)
{
_bones = _animatedModelData.BonesBindPose;
_bonesTransform = Matrix.Identity;
}
// Get the animated model effect - shared by all meshes
_animatedModelEffect = new AnimatedModelEffect(_model.Meshes[0].Effects[0]);
// Create a default material
_lightMaterial = new LightMaterial();
}
[color="#4A4A4A"]the problem is that the Bone property for each keyframe is -1 (as shown in the screenshot below):
[color="#4A4A4A"]and that causes a System.IndexOutOfRangeException was unhandled error in the following code:
[color="#4A4A4A"]
[color="#4A4A4A"]What am I doing wrong here? Why is this happening?
[color="#4A4A4A"]Btw, I am using XNA 4.0.