/// <summary>
        /// Load all graphical content.
        /// </summary>
        protected override void LoadContent()
        {
            // Load the rigid model
            rigidModel = Content.Load <Model>("AnimatedCube");
            rigidWorld = Matrix.CreateScale(.05f, .05f, .05f);

            // Create animation players/clips for the rigid model
            ModelData modelData = rigidModel.Tag as ModelData;

            if (modelData != null)
            {
                if (modelData.RootAnimationClips != null && modelData.RootAnimationClips.ContainsKey("Take 001"))
                {
                    rigidRootClip = modelData.RootAnimationClips["Take 001"];

                    rigidRootPlayer            = new RootAnimationPlayer();
                    rigidRootPlayer.Completed += new EventHandler(rigidPlayer_Completed);
                    rigidRootPlayer.StartClip(rigidRootClip, 1, TimeSpan.Zero);
                }
                if (modelData.ModelAnimationClips != null && modelData.ModelAnimationClips.ContainsKey("Take 001"))
                {
                    rigidClip = modelData.ModelAnimationClips["Take 001"];

                    rigidPlayer            = new RigidAnimationPlayer(rigidModel.Bones.Count);
                    rigidPlayer.Completed += new EventHandler(rigidPlayer_Completed);
                    rigidPlayer.StartClip(rigidClip, 1, TimeSpan.Zero);
                }
            }

            // Load the skinned model
            skinnedModel = Content.Load <Model>("DudeWalk");
            skinnedWorld = Matrix.CreateScale(.025f, .025f, .025f) * Matrix.CreateRotationY((float)(-Math.PI / 2));

            // Create animation players for the skinned model
            modelData = skinnedModel.Tag as ModelData;
            if (modelData != null)
            {
                if (modelData.RootAnimationClips != null && modelData.RootAnimationClips.ContainsKey("Take 001"))
                {
                    skinnedRootClip = modelData.RootAnimationClips["Take 001"];

                    skinnedRootPlayer            = new RootAnimationPlayer();
                    skinnedRootPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
                if (modelData.ModelAnimationClips != null && modelData.ModelAnimationClips.ContainsKey("Take 001"))
                {
                    skinnedClip = modelData.ModelAnimationClips["Take 001"];

                    skinnedPlayer            = new SkinnedAnimationPlayer(modelData.BindPose, modelData.InverseBindPose, modelData.SkeletonHierarchy);
                    skinnedPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
            }

            // Create the projection/view matrix we'll use for rendering
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), GraphicsDevice.Viewport.AspectRatio, .01f, 200.0f);
            view       = Matrix.CreateLookAt(new Vector3(0, 1, 4), new Vector3(0, 1, 0), Vector3.Up);

            spriteBatch = new SpriteBatch(GraphicsDevice);
            font        = Content.Load <SpriteFont>("font");
        }
        private void DrawSkinnedModel(Model model, SkinnedAnimationPlayer skinnedAnimationPlayer, RootAnimationPlayer rootAnimationPlayer)
        {
            Matrix[] boneTransforms = null;
            if (skinnedAnimationPlayer != null)
            {
                boneTransforms = skinnedAnimationPlayer.GetSkinTransforms();
            }

            Matrix rootTransform = Matrix.Identity;

            if (rootAnimationPlayer != null)
            {
                rootTransform = rootAnimationPlayer.GetCurrentTransform();
            }

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (SkinnedEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.Projection = projection;
                    effect.View       = view;
                    if (boneTransforms != null)
                    {
                        effect.SetBoneTransforms(boneTransforms);
                    }
                    effect.World         = rootTransform * skinnedWorld;
                    effect.SpecularColor = Vector3.Zero;
                }

                mesh.Draw();
            }
        }
예제 #3
0
        public Model3DSkinned(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, String modelName, String clip)
            : base(scene, pos, rotation, scale)
        {
            this.scene     = scene;
            this.modelName = modelName;

            this.clip    = clip;
            this.animate = false;
            this.jumping = false;
            this.rising  = false;
            model        = scene.Game.Content.Load <Model>(modelName);

            // Look up our custom skinning information.
            skinningData = model.Tag as ModelData;

            if (skinningData != null)
            {
                if (skinningData.RootAnimationClips != null)
                {
                    rootAnimationPlayer = new RootAnimationPlayer();
                }
                if (skinningData.ModelAnimationClips != null)
                {
                    skinnedAnimationPlayer = new SkinnedAnimationPlayer(skinningData.BindPose, skinningData.InverseBindPose, skinningData.SkeletonHierarchy);
                    skinnedAnimationPlayer.StartClip(skinningData.ModelAnimationClips[clip]);
                    boneTransforms = skinnedAnimationPlayer.GetSkinTransforms();
                    skinnedAnimationPlayer.Update(new GameTime(new TimeSpan(), new TimeSpan(2)));
                }
            }
            bsLocal = new BoundingSphere();
            foreach (ModelMesh mesh in model.Meshes)
            {
                bsLocal = BoundingSphere.CreateMerged(bsLocal, mesh.BoundingSphere);
            }
            setObject(pos.X, pos.Y, pos.Z);
        }
예제 #4
0
        public Cyclist()
        {
            //string test = typeof(AnimationDataReader).AssemblyQualifiedName;
            TimeScale    = 1;
            skinnedModel = BaseGame.Content.Load <XnaModel>("Content\\Models\\bike_boy");
            objectMatrix = Matrix.CreateScale(0.5f);// Matrix.Identity;

            // Create animation players for the skinned model
            animData = skinnedModel.Tag as AnimationData;
            if (animData != null)
            {
                if (animData.RootAnimationClips != null && animData.RootAnimationClips.ContainsKey("Take 001"))
                {
                    skinnedRootClip = animData.RootAnimationClips["Take 001"];

                    skinnedRootPlayer            = new RootAnimationPlayer();
                    skinnedRootPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
                if (animData.ModelAnimationClips != null && animData.ModelAnimationClips.ContainsKey("Take 001"))
                {
                    skinnedClip = animData.ModelAnimationClips["Take 001"];

                    skinnedPlayer = new SkinnedAnimationPlayer(animData.BindPose, animData.InverseBindPose, animData.SkeletonHierarchy);

                    skinnedPlayer.StartClip(skinnedClip, 1, TimeSpan.Zero);
                    skinnedPlayer.CurrentTimeValue = skinnedClip.Duration;
                    skinnedPlayer.CurrentTimeValue = TimeSpan.Zero;

                    skinnedPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
            }

            rigidModel = BaseGame.Content.Load <XnaModel>("Content\\Models\\bike");

            // Create animation players/clips for the rigid model
            animData2 = rigidModel.Tag as AnimationData;
            if (animData2 != null)
            {
                if (animData2.RootAnimationClips != null && animData2.RootAnimationClips.ContainsKey("Take 001"))
                {
                    rigidRootClip = animData2.RootAnimationClips["Take 001"];

                    rigidRootPlayer            = new RootAnimationPlayer();
                    rigidRootPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                    rigidRootPlayer.StartClip(rigidRootClip, 1, TimeSpan.Zero);
                }
                if (animData2.ModelAnimationClips != null && animData2.ModelAnimationClips.ContainsKey("Take 001"))
                {
                    rigidClip = animData2.ModelAnimationClips["Take 001"];



                    rigidPlayer = new RigidAnimationPlayer(rigidModel.Bones.Count);
                    rigidPlayer.StartClip(rigidClip, 1, TimeSpan.Zero);


                    rigidPlayer.CurrentTimeValue = rigidClip.Duration;
                    rigidPlayer.CurrentTimeValue = TimeSpan.Zero;

                    rigidPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
            }


            skinned = BaseGame.Content.Load <Effect>("Content\\Shaders\\skinned");
            skinned.CurrentTechnique = skinned.Techniques[0];

            Update(null);
        }