Esempio n. 1
0
        protected override void Initialize()
        {
            CharacterTexture = Content.Load <Texture2D>("swat");
            RifleTexture     = Content.Load <Texture2D>("hk_mp5n");

            CharacterMesh = new SkinnedModel();
            CharacterMesh.GraphicsDevice = GraphicsDevice;
            CharacterMesh.FilePath       = @"Content\Soldier.fbx";
            CharacterMesh.Initialize();
            CharacterMesh.Meshes[0].Texture = Content.Load <Texture2D>("swat");

            AnimationIdle          = new SkinnedModelAnimation();
            AnimationIdle.FilePath = @"Content\Rifle Idle.dae";
            AnimationIdle.Load();

            AnimationRunning          = new SkinnedModelAnimation();
            AnimationRunning.FilePath = @"Content\Rifle Run.dae";
            AnimationRunning.Load();

            AnimationWalk          = new SkinnedModelAnimation();
            AnimationWalk.FilePath = @"Content\Rifle Walking.dae";
            AnimationWalk.Load();


            ModelRifle = new SimpleModel();
            ModelRifle.GraphicsDevice = GraphicsDevice;
            ModelRifle.FilePath       = @"Content\mp5.3ds";
            ModelRifle.Initialize();

            ModelInstance      = new SkinnedModelInstance();
            ModelInstance.Mesh = CharacterMesh;
            ModelInstance.SpeedTransitionSecond = 0.4f;
            ModelInstance.Initialize();
            ModelInstance.SetAnimation(AnimationIdle);

            HeadBoneAnimationInstance = ModelInstance.GetBoneAnimationInstance("soldier_Head");
            HandBoneAnimationInstance = ModelInstance.GetBoneAnimationInstance("soldier_RightHand");

            SimpleModelEffect  = this.Content.Load <Effect>("SimpleModelEffect");
            SkinnedModelEffect = this.Content.Load <Effect>("SkinnedModelEffect");

            var Position  = new Vector3(500, 200, 0);
            var Direction = new Vector3(0, 200, 0);

            ViewMatrix       = Matrix.CreateLookAt(Position, Direction, Vector3.Up);
            ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), GraphicsDevice.DisplayMode.AspectRatio, 0.1f, 5000f);

            base.Initialize();
        }
Esempio n. 2
0
        public void SetAnimation(SkinnedModelAnimation animation, GameTime gameTime = null)
        {
            if (gameTime != null)
            {
                TimeAnimationChanged = gameTime.TotalGameTime;
            }

            PreviousAnimation = animation;
            PreviousBoneAnimationInstances.Clear();
            PreviousBoneAnimationInstances.AddRange(BoneAnimationInstances);

            Animation = animation;

            BoneAnimationInstances.Clear();
            foreach (var boneAnimation in animation.BoneAnimations)
            {
                BoneAnimationInstance boneAnimationInstance = new BoneAnimationInstance();
                boneAnimationInstance.BoneAnimation                 = boneAnimation;
                boneAnimationInstance.Updated                       = false;
                boneAnimationInstance.AdditionalTransform           = Matrix.Identity;
                boneAnimationInstance.PreviousBoneAnimationInstance = PreviousBoneAnimationInstances.FirstOrDefault(ni => ni.BoneAnimation.Name == boneAnimation.Name);
                BoneAnimationInstances.Add(boneAnimationInstance);
            }

            foreach (var boneAnimationInstance in BoneAnimationInstances)
            {
                boneAnimationInstance.Parent = BoneAnimationInstances.FirstOrDefault(ni => ni.BoneAnimation == boneAnimationInstance.BoneAnimation.Parent);
            }

            foreach (var meshInstance in MeshInstances)
            {
                meshInstance.BoneInstances.Clear();
                foreach (var bone in meshInstance.Mesh.Bones)
                {
                    var boneInstance = new BoneInstance();
                    boneInstance.Bone = bone;
                    boneInstance.BoneAnimationInstance = BoneAnimationInstances.FirstOrDefault(ni => ni.BoneAnimation.Name == bone.Name);
                    meshInstance.BoneInstances.Add(boneInstance);
                }
            }
        }