public void Load(ContentManager content, String path, GraphicsDevice graphics, Matrix view, Matrix projection) { this.model = content.Load <Model>(path); ModelAnimator = new ModelAnimator(model); foreach (ModelMesh mesh in model.Meshes) { foreach (Effect effect in mesh.Effects) { if (effect is BasicEffect) { BasicEffect basic = (BasicEffect)effect; basic.View = view; basic.Projection = projection; } else if (effect is BasicPaletteEffect) { BasicPaletteEffect palette = (BasicPaletteEffect)effect; palette.View = view; palette.Projection = projection; palette.EnableDefaultLighting(); palette.DirectionalLight0.Direction = new Vector3(0, 0, 1); } } } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); bsdModel.CopyAbsoluteBoneTransformsTo(_boneTransform); foreach (ModelMesh mesh in bsdModel.Meshes) { //foreach (BasicPaletteEffect effect in mesh.Effects) foreach (Effect effect in mesh.Effects) { if (effect is BasicEffect) { BasicEffect _effect = (BasicEffect)effect; //effect.World = _boneTransform[mesh.ParentBone.Index]; _effect.View = Matrix.CreateLookAt(new Vector3(1500, 500, 0), new Vector3(0, 0, 0), Vector3.Up); _effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height, 10, 10000); //effect.EnableDefaultLighting(); //effect.DirectionalLight0.Direction = new Vector3(0, 0, 300); } else if (effect is BasicPaletteEffect) { BasicPaletteEffect _effect = (BasicPaletteEffect)effect; //effect.World = _boneTransform[mesh.ParentBone.Index]; _effect.View = Matrix.CreateLookAt(new Vector3(1500, 500, 0), new Vector3(0, 0, 0), Vector3.Up); _effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height, 10, 10000); _effect.EnableDefaultLighting(); _effect.DirectionalLight0.Direction = new Vector3(0, 0, 300); } } mesh.Draw(); } if (lastState != bsdState) { lastState = bsdState; Console.WriteLine("State: " + bsdState.ToString()); } RunController(bsdAnimator, bsdAnimationControllers[(int)bsdState]); // TODO: Add your drawing code here base.Draw(gameTime); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); bsdModel = Content.Load <Model>("bsd"); _boneTransform = new Matrix[bsdModel.Bones.Count]; bsdModel.Root.Transform *= Matrix.CreateRotationY(MathHelper.ToRadians(90)); bsdAnimator = new ModelAnimator(this, bsdModel); Viewport port = graphics.GraphicsDevice.Viewport; //view = Matrix.CreateLookAt(new Vector3(0, 500, -1000), Vector3.Zero, Vector3.Up); bsdAnimationControllers[(int)CharacterState.Idle] = new AnimationController(this, bsdAnimator.Animations["Idle"]); bsdAnimationControllers[(int)CharacterState.IdleToWalk] = new AnimationController(this, bsdAnimator.Animations["IdleToWalk"]); bsdAnimationControllers[(int)CharacterState.Walk] = new AnimationController(this, bsdAnimator.Animations["Walk"]); bsdAnimationControllers[(int)CharacterState.WalkToIdle] = new AnimationController(this, bsdAnimator.Animations["WalkToIdle"]); //bsdAnimationControllers[(int)CharacterState.NodHead] = new AnimationController(this, bsdAnimator.Animations["NodHead"]); //bsdAnimationControllers[(int)CharacterState.ShakeHead] = new AnimationController(this, bsdAnimator.Animations["ShakeHead"]); //bsdAnimationControllers[(int)CharacterState.Wave] = new AnimationController(this, bsdAnimator.Animations["Wave"]); //bsdAnimationControllers[(int)CharacterState.Point] = new AnimationController(this, bsdAnimator.Animations["Point"]); //bsdAnimationControllers[(int)CharacterState.PointFinish] = new AnimationController(this, bsdAnimator.Animations["PointFinish"]); //bsdAnimationControllers[(int)CharacterState.PistolReady] = new AnimationController(this, bsdAnimator.Animations["PistolReady"]); //bsdAnimationControllers[(int)CharacterState.PistolShoot] = new AnimationController(this, bsdAnimator.Animations["PistolShoot"]); //bsdAnimationControllers[(int)CharacterState.PistolDone] = new AnimationController(this, bsdAnimator.Animations["PistolDone"]); //bsdAnimationControllers[(int)CharacterState.ThrowReady] = new AnimationController(this, bsdAnimator.Animations["ThrowReady"]); //bsdAnimationControllers[(int)CharacterState.Throw] = new AnimationController(this, bsdAnimator.Animations["Throw"]); //bsdAnimationControllers[(int)CharacterState.ThrowToReady] = new AnimationController(this, bsdAnimator.Animations["ThrowToReady"]); //bsdAnimationControllers[(int)CharacterState.ThrowReadyToDone] = new AnimationController(this, bsdAnimator.Animations["ThrowReadyToDone"]); //bsdAnimationControllers[(int)CharacterState.ThrowToDone] = new AnimationController(this, bsdAnimator.Animations["ThrowToDone"]); //bsdAnimationControllers[(int)CharacterState.DeepBreath] = new AnimationController(this, bsdAnimator.Animations["DeepBreath"]); Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, (float)port.Width / port.Height, .1f, 100000f ); bsdModel.CopyAbsoluteBoneTransformsTo(_boneTransform); foreach (ModelMesh mesh in bsdModel.Meshes) { foreach (Effect effect in mesh.Effects) { if (effect is BasicEffect) { BasicEffect basic = (BasicEffect)effect; basic.View = Matrix.CreateLookAt( new Vector3(1000, 500, 0), new Vector3(0, 150, 0), Vector3.Up); //view; basic.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height, 10, 10000); //projection; } else if (effect is BasicPaletteEffect) { BasicPaletteEffect palette = (BasicPaletteEffect)effect; palette.View = Matrix.CreateLookAt( new Vector3(1000, 500, 0), new Vector3(0, 150, 0), Vector3.Up); //view; palette.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.PiOver4, GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height, 10, 10000); //projection; // enable some lighting palette.EnableDefaultLighting(); //palette.DirectionalLight0.Direction = new Vector3(0, 0, 1); } } } }