public Dancer(AnimatedModelInstance modelInstance) { _modelInstance = modelInstance; _animationPlayer = new AnimationPlayer(AnimationManager.Instance.GetAnimationData()); Position = Vector3.Zero; Forward = Vector3.UnitZ; Up = Vector3.UnitY; _worldMatrix = Matrix.CreateWorld(Position, Forward, Up); _dancerBehavior = new IdleDancerBehavior(this); _modelInstance.SkinTransforms = _animationPlayer.GetSkinTransforms(); }
public SkinnedModel(Model model, List<Keys> lstkeys, Vector3 position, Vector3 rotation, Vector3 scale) { this.model = model; this.lstKeys = lstkeys; this.position = position; this.rotation = rotation; this.scale = scale; this.skinningData = model.Tag as SkinningData; if (skinningData == null) throw new InvalidOperationException ("This model does not contain a SkinningData tag."); animationPlayer = new AnimationPlayer(skinningData); bones = animationPlayer.GetSkinTransforms(); }
public static void DrawModelAnim(Model mod, Matrix world, AnimationPlayer anim) { Matrix[] bones = anim.GetSkinTransforms(); foreach (ModelMesh mesh in mod.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { effect.SetBoneTransforms(bones); effect.View = GameCore.Camera.getView(); effect.Projection = GameCore.Camera.getProj(); effect.EnableDefaultLighting(); effect.SpecularColor = new Vector3(0.25f); effect.SpecularPower = 16; } mesh.Draw(); } }
/// <summary> /// Performs required setup sequence for model /// </summary> protected void SetupModel() { //Get texture animation data skinningData = model.Tag as SkinningData; //Double check the model if (skinningData == null) throw new InvalidOperationException ("This model does not contain a SkinningData tag."); // Create an animation player, and start decoding an animation clip. animationPlayer = new AnimationPlayer(skinningData); //get location of bones bones = animationPlayer.GetSkinTransforms(); scale = 1.0f; }
protected override void LoadContent() { _model = Content.Load<Model>(_fileName); var skinningData = _model.Tag as SkinningData; if (skinningData != null) { _animationPlayer = new AnimationPlayer(skinningData); var clip = skinningData.AnimationClips["Take 001"]; _animationPlayer.StartClip(clip); _bones = _animationPlayer.GetSkinTransforms(); } else { _bones = new Matrix[_model.Bones.Count]; _model.CopyAbsoluteBoneTransformsTo(_bones); } var bestFit = new BoundingSphere(); foreach (var mesh in _model.Meshes) { if (bestFit.Contains(mesh.BoundingSphere) != ContainmentType.Contains) bestFit = BoundingSphere.CreateMerged(bestFit, mesh.BoundingSphere); } _worldMatrix = Matrix.Identity; _viewMatrix = Matrix.CreateTranslation(bestFit.Center) * Matrix.CreateTranslation(0, -bestFit.Radius * 1.5f, -bestFit.Radius * 4); _projMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, bestFit.Radius * 2 * 10.0f); foreach (var mesh in _model.Meshes) { foreach (var effect in mesh.Effects) { var em = effect as IEffectMatrices; em.World = _worldMatrix; em.View = _viewMatrix; em.Projection = _projMatrix; var basic = effect as BasicEffect; if (basic != null) basic.EnableDefaultLighting(); var skinned = effect as SkinnedEffect; if (skinned != null) skinned.EnableDefaultLighting(); } } }
private void DrawModel(GameTime gameTime, Microsoft.Xna.Framework.Graphics.Model meshModel, Matrix mtxWorld, AnimationPlayer animationPlayer) { float angle = (float)gameTime.TotalGameTime.TotalMilliseconds / 1000f; Vector3 lightDirection = new Vector3((float)Math.Cos(angle), (float)Math.Sin(angle), -1f); Matrix[] mtxMeshTransform = new Matrix[meshModel.Bones.Count]; meshModel.CopyAbsoluteBoneTransformsTo(mtxMeshTransform); Matrix[] bones = null; if (animationPlayer != null) bones = animationPlayer.GetSkinTransforms(); //bones[0] = Matrix.CreateScale(500f) * World;// *mtxWorld; // Compute camera matrices. /* View = Matrix.CreateTranslation(0, 0, 0) * Matrix.CreateRotationY(MathHelper.ToRadians(0f)) * Matrix.CreateRotationX(MathHelper.ToRadians(0f)) * Matrix.CreateLookAt(new Vector3(0, 0, -100f), new Vector3(0, 0, 0), Vector3.Up); */ /* Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1.6f, 1, 10000); */ foreach (ModelMesh mesh in meshModel.Meshes) { foreach (Effect effect2 in mesh.Effects) { ((IEffectMatrices)effect2).View = View; ((IEffectMatrices)effect2).Projection = Projection; ((IEffectLights)effect2).EnableDefaultLighting(); ((IEffectLights)effect2).DirectionalLight0.Direction = lightDirection; //((IEffectLights)effect2).PreferPerPixelLighting = true; //((IEffectLights)effect2).SpecularColor = new Vector3(0.25f); //((IEffectLights)effect2).SpecularPower = 16; if (effect2 is SkinnedEffect) { if (animationPlayer != null) ((SkinnedEffect)effect2).SetBoneTransforms(bones); ((IEffectMatrices)effect2).World = World * mtxWorld; } else { if (((BasicEffect)effect2).Texture != null) { ((BasicEffect)effect2).TextureEnabled = true; ((BasicEffect)effect2).VertexColorEnabled = false; } ((IEffectMatrices)effect2).World = mtxMeshTransform[mesh.ParentBone.Index] * World * mtxWorld; } } mesh.Draw(); } }