|
@@ -8,13 +8,23 @@ using tainicom.Aether.Animation;
|
|
|
|
|
|
namespace Samples.Animation
|
|
|
{
|
|
|
+ enum DrawMode : int
|
|
|
+ {
|
|
|
+ CPU,
|
|
|
+ GPU,
|
|
|
+ }
|
|
|
+
|
|
|
public class Game1 : Microsoft.Xna.Framework.Game
|
|
|
{
|
|
|
GraphicsDeviceManager graphics;
|
|
|
SpriteBatch spriteBatch;
|
|
|
SpriteFont font;
|
|
|
- Model _model;
|
|
|
+ Model _model_CPU;
|
|
|
+ Model _model_GPU;
|
|
|
Animations _animations;
|
|
|
+ DrawMode drawMode = DrawMode.CPU;
|
|
|
+
|
|
|
+ KeyboardState prevKeyboardState;
|
|
|
|
|
|
public Game1()
|
|
|
{
|
|
@@ -32,9 +42,10 @@ namespace Samples.Animation
|
|
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
|
|
font = Content.Load<SpriteFont>("font");
|
|
|
|
|
|
- _model = Content.Load<Model>("Dude/dude");
|
|
|
+ _model_CPU = Content.Load<Model>("Dude/dude");
|
|
|
+ _model_GPU = Content.Load<Model>("Dude/dude_GPU");
|
|
|
|
|
|
- _animations = _model.GetAnimations();
|
|
|
+ _animations = _model_CPU.GetAnimations(); // Animation Data are the same between the two models
|
|
|
var clip = _animations.Clips["Take 001"];
|
|
|
_animations.SetClip(clip);
|
|
|
}
|
|
@@ -45,10 +56,21 @@ namespace Samples.Animation
|
|
|
|
|
|
protected override void Update(GameTime gameTime)
|
|
|
{
|
|
|
+ var keyboardState = Keyboard.GetState();
|
|
|
+ var gamePadState = GamePad.GetState(PlayerIndex.One);
|
|
|
+
|
|
|
// Allows the game to exit
|
|
|
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
|
|
+ if (keyboardState.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Back == ButtonState.Pressed)
|
|
|
this.Exit();
|
|
|
|
|
|
+ if ((keyboardState.IsKeyDown(Keys.Space) && prevKeyboardState.IsKeyUp(Keys.Space)) || gamePadState.Buttons.A == ButtonState.Pressed)
|
|
|
+ {
|
|
|
+ int drawModesCount = Enum.GetValues(drawMode.GetType()).Length;
|
|
|
+ drawMode = (DrawMode)(((int)drawMode + 1) % drawModesCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ prevKeyboardState = keyboardState;
|
|
|
+
|
|
|
_animations.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
|
|
|
|
|
|
base.Update(gameTime);
|
|
@@ -77,7 +99,11 @@ namespace Samples.Animation
|
|
|
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
|
|
|
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
|
|
|
|
|
|
- var m = _model;
|
|
|
+ Model m = _model_CPU;
|
|
|
+ if (drawMode == DrawMode.CPU)
|
|
|
+ m = _model_CPU;
|
|
|
+ else if (drawMode == DrawMode.GPU)
|
|
|
+ m = _model_GPU;
|
|
|
|
|
|
float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
|
|
|
Matrix[] transforms = new Matrix[m.Bones.Count];
|
|
@@ -94,12 +120,17 @@ namespace Samples.Animation
|
|
|
{
|
|
|
foreach (var part in mesh.MeshParts)
|
|
|
{
|
|
|
- ((BasicEffect)part.Effect).SpecularColor = Vector3.Zero;
|
|
|
+ if (drawMode == DrawMode.CPU)
|
|
|
+ ((BasicEffect)part.Effect).SpecularColor = Vector3.Zero;
|
|
|
+ else if (drawMode == DrawMode.GPU)
|
|
|
+ ((SkinnedEffect)part.Effect).SpecularColor = Vector3.Zero;
|
|
|
ConfigureEffectMatrices((IEffectMatrices)part.Effect, Matrix.Identity, view, projection);
|
|
|
ConfigureEffectLighting((IEffectLights)part.Effect);
|
|
|
-
|
|
|
- // animate vertices on CPU
|
|
|
- part.UpdateVertices(_animations.AnimationTransforms);
|
|
|
+
|
|
|
+ if (drawMode == DrawMode.CPU)
|
|
|
+ part.UpdateVertices(_animations.AnimationTransforms); // animate vertices on CPU
|
|
|
+ else if (drawMode == DrawMode.GPU)
|
|
|
+ ((SkinnedEffect)part.Effect).SetBoneTransforms(_animations.AnimationTransforms);// animate vertices on GPU
|
|
|
}
|
|
|
mesh.Draw();
|
|
|
}
|
|
@@ -117,13 +148,13 @@ namespace Samples.Animation
|
|
|
}
|
|
|
|
|
|
spriteBatch.Begin();
|
|
|
+ spriteBatch.DrawString(font, "Draw Mode: " + drawMode, new Vector2(32, 32), Color.White);
|
|
|
spriteBatch.DrawString(font, msec.ToString("#0.000",CultureInfo.InvariantCulture) + "ms", new Vector2(32, GraphicsDevice.Viewport.Height - 130), Color.White);
|
|
|
spriteBatch.DrawString(font, avg.ToString("#0.000",CultureInfo.InvariantCulture) + "ms (avg)", new Vector2(32, GraphicsDevice.Viewport.Height - 100), Color.White);
|
|
|
spriteBatch.DrawString(font, msecMin.ToString("#0.000",CultureInfo.InvariantCulture) + "ms (min)", new Vector2(32, GraphicsDevice.Viewport.Height - 70), Color.White);
|
|
|
spriteBatch.DrawString(font, msecMax.ToString("#0.000",CultureInfo.InvariantCulture) + "ms (max)", new Vector2(32, GraphicsDevice.Viewport.Height - 40), Color.White);
|
|
|
spriteBatch.End();
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
base.Draw(gameTime);
|
|
|
}
|
|
|
|