/// <summary> /// Constructs a new animation player. /// </summary> public AnimationPlayer(SkinningData skinningData) { if (skinningData == null) { throw new ArgumentNullException("skinningData"); } skinningDataValue = skinningData; boneTransforms = new Matrix[skinningData.BindPose.Count]; worldTransforms = new Matrix[skinningData.BindPose.Count]; skinTransforms = new Matrix[skinningData.BindPose.Count]; }
/// <summary> /// Creates a model with both information loaded from a model file and mesh defined /// using VertexBuffer and IndexBuffer /// </summary> /// <param name="transforms">Transforms applied to each model meshes</param> /// <param name="mesh">A collection of model meshes</param> /// <param name="model"></param> public AnimatedModel(Microsoft.Xna.Framework.Graphics.Model aModel) : base(null, aModel.Meshes) { this.skinnedModel = aModel; // Look up our custom skinning information. skinningData = aModel.Tag as SkinningData; if (skinningData == null) throw new GoblinException("This model does not contain a SkinningData tag."); // Create an animation player, and start decoding an animation clip. animationPlayer = new AnimationPlayer(skinningData); Matrix[] newBones = animationPlayer.GetBoneTransforms(); int k = animationPlayer.GetBoneTransforms().Length; this.transforms = new Matrix[k]; for (int i = 0; i < k; i++) this.transforms[i] = newBones[i]; CalculateMinimumBoundingSphere(); //The text you pass in here needs to match the .fx shader file shader = new SkinnedModelShader(); resourceName = ""; #if WINDOWS shaderName = TypeDescriptor.GetClassName(shader); #endif modelLoaderName = "AnimatedModelLoader"; }
/// <summary> /// Copies only the geometry (Mesh, /// MinimumBoundingBox, MinimumBoundingSphere, TriangleCount and Transforms) /// </summary> /// <param name="model">A source model from which to copy</param> public override void CopyGeometry(IModel model) { if (!(model is AnimatedModel)) return; AnimatedModel srcModel = (AnimatedModel)model; skinnedModel = srcModel.SkinnedModel; vertices.AddRange(((IPhysicsMeshProvider)model).Vertices); indices.AddRange(((IPhysicsMeshProvider)model).Indices); // Look up our custom skinning information. skinningData = srcModel.skinnedModel.Tag as SkinningData; if (skinningData == null) throw new GoblinException("This model does not contain a SkinningData tag."); // Create an animation player, and start decoding an animation clip. animationPlayer = new AnimationPlayer(skinningData); triangleCount = srcModel.TriangleCount; boundingBox = srcModel.MinimumBoundingBox; boundingSphere = srcModel.MinimumBoundingSphere; UseInternalMaterials = srcModel.UseInternalMaterials; }