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();
            }
        }
Exemple #2
0
        public override void Draw(GameTime time)
        {
            worldMatrix.Forward     = viewVector;
            worldMatrix.Right       = rightVector;
            worldMatrix.Up          = upVector;
            worldMatrix.Translation = pos;

            //worldMatrix = Matrix.CreateFromQuaternion(rotationQuat) * Matrix.CreateTranslation(pos);
            //scene.Game.GraphicsDevice.RasterizerState = RasterizerState.CullNone;
            //scene.Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            boneTransforms = skinnedAnimationPlayer.GetSkinTransforms();
            effectContainer.updateMutable(this);
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (Effect currentEffect in mesh.Effects)
                {
                    if (currentEffect.GetType() == typeof(SkinnedEffect))
                    {
                        effectContainer.drawMutable(currentEffect);
                    }
                    else
                    {
                        currentEffect.Parameters["Bones"].SetValue(boneTransforms);
                        currentEffect.Parameters["View"].SetValue(World * scene.Camera.MView);
                        currentEffect.Parameters["Projection"].SetValue(scene.Camera.MProjection);
                    }
                }
                mesh.Draw();
                Matrix world = Matrix.Identity;
                world = boneTransforms[mesh.ParentBone.Index] * World;
                bs    = bsLocal.Transform(world);
            }
            /* not tested */
            if (!moving)
            {
                stopAnimation();
            }
            else
            {
                startAnimation();
            }
            updateAnimation(time);
            base.Draw(time);
        }
Exemple #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);
        }
        /// <summary>
        /// Render car model with this seperate method because we
        /// render it in 2 steps, first the solid stuff, then the alpha glass.
        /// We also rotate the wheels around :)
        /// </summary>
        /// <param name="carNumber">Car type number (0, 1 or 2) for the car
        /// texture</param>
        /// <param name="carColor">Car color we are currently using.</param>
        /// <param name="shadowCarMode">In the shadow car mode we render
        /// everything (including wheels and glass) with a special ShadowCar
        /// shader, that is very transparent. Used for the shadow car when
        /// playing that shows how we drove the last time.</param>
        /// <param name="renderMatrix">Render matrix for the car</param>
        public void RenderCar(bool renderCyclist, Color carColor,
                              Matrix renderMatrix)
        {
            //renderMatrix = Matrix.CreateTranslation(renderMatrix.Translation + Vector3.UnitZ * 5);
            // Multiply object matrix by render matrix, result is used multiple
            // times here.
            renderMatrix = objectMatrix * renderMatrix;


            Matrix[] boneTransforms = null;
            if (skinnedPlayer != null)
            {
                boneTransforms = skinnedPlayer.GetSkinTransforms();
            }

            Matrix rootTransform = Matrix.Identity;

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


            if (renderCyclist)
            {
                foreach (ModelMesh mesh in skinnedModel.Meshes)
                {
                    //mesh.MeshParts[0].
                    //skinned.Parameters["diffuseTexture"].SetValue();


                    foreach (Effect effect in mesh.Effects)
                    {
                        //effect.Parameters["diffuseTexture"].SetValue(effect);
                        effect.Parameters["viewProj"].SetValue(BaseGame.ViewProjectionMatrix);
                        effect.Parameters["world"].SetValue(rootTransform * renderMatrix);
                        effect.Parameters["Bones"].SetValue(boneTransforms);
                        effect.CommitChanges();

                        //effect.EnableDefaultLighting();
                        //effect.Projection = BaseGame.ProjectionMatrix;
                        //effect.View = BaseGame.ViewMatrix;
                        //if (boneTransforms != null)
                        //effect.SetBoneTransforms(boneTransforms);
                        //effect.World = rootTransform * renderMatrix;
                        //effect.SpecularColor = Vector3.Zero;
                    }

                    mesh.Draw();
                }
            }

            boneTransforms = null;
            if (rigidPlayer != null)
            {
                boneTransforms = rigidPlayer.GetBoneTransforms();
            }

            rootTransform = Matrix.Identity;
            if (rigidRootPlayer != null)
            {
                rootTransform = rigidRootPlayer.GetCurrentTransform();
            }

            foreach (ModelMesh mesh in rigidModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.DiffuseColor = Color.Lerp(Color.White, carColor, 0.5f).ToVector3();
                    effect.Projection   = BaseGame.ProjectionMatrix;
                    effect.View         = BaseGame.ViewMatrix;
                    if (boneTransforms != null)
                    {
                        effect.World = boneTransforms[mesh.ParentBone.Index] * rootTransform * renderMatrix;
                    }
                    else
                    {
                        effect.World = rootTransform * renderMatrix;
                    }
                    effect.SpecularPower = 64;
                }

                mesh.Draw();
            }
        }