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); } } } }
private void RunController(ModelAnimator animator, AnimationController controller) { foreach (BonePose p in animator.BonePoses) { p.CurrentController = controller; p.CurrentBlendController = null; } }
protected void runAnimationController(ModelAnimator animator, AnimationController controller) { this.PreviousAnimationController = currentAnimationController; this.currentAnimationController = controller; foreach (BonePose p in animator.BonePoses) { p.CurrentController = this.PreviousAnimationController; p.CurrentBlendController = this.CurrentAnimationController; p.BlendFactor = 0.5f; } }
public void DrawOnCharacter(ModelAnimator modelAnimator, Vector3 rotation, Matrix view, Matrix projection, Vector3 position, CharacterState charState) { Matrix Model1TransfoMatrix = modelAnimator.GetAbsoluteTransform(modelAnimator.BonePoses["vincent:RightHandIndex1"].Index); Matrix[] Model2TransfoMatrix = new Matrix[weaponModel.Bones.Count]; weaponModel.CopyAbsoluteBoneTransformsTo(Model2TransfoMatrix); Vector3 rotAxis; Matrix translate; if (weaponType.Equals(WeaponType.Melee)) { rotAxis = new Vector3(7.5f * MathHelper.PiOver4, 2.5f * MathHelper.PiOver2, 4.5f * MathHelper.PiOver2); translate = Matrix.CreateTranslation(-0.16f, -0.24f, 0.8f); } else { rotAxis = new Vector3(.5f * MathHelper.PiOver4, 2.5f * MathHelper.PiOver2, 2f * MathHelper.PiOver2); translate = Matrix.CreateTranslation(0f, -0.3f, 0); } rotAxis.Normalize(); if (charState.Equals(CharacterState.FiringRifle) || charState.Equals(CharacterState.ShootRifle)) { rotation.Y += 100; } Matrix tempRotation = Matrix.CreateRotationX(rotation.X) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z); foreach (ModelMesh mesh in weaponModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { Matrix model2Transform = tempRotation * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(position); effect.World = Matrix.CreateFromAxisAngle(rotAxis, MathHelper.Pi) * translate * Model1TransfoMatrix * model2Transform; effect.View = view; effect.Projection = projection; } mesh.Draw(); } }
private void OnPlayAnimation(View unusedView) { if (animator == null || !animator.IsRunning) { AnimationData data = andyRenderable.GetAnimationData(nextAnimation); nextAnimation = (nextAnimation + 1) % andyRenderable.AnimationDataCount; animator = new ModelAnimator(data, andyRenderable); animator.Start(); Toast toast = Toast.MakeText(this, data.Name, ToastLength.Short); Log.Debug( TAG, string.Format( "Starting animation %s - %d ms long", data.Name, data.DurationMs)); toast.SetGravity(GravityFlags.Center, 0, 0); toast.Show(); } }
// Use this for initialization void Start() { modelAnimator = GetComponent <ModelAnimator>(); //Load starting positions startingPositions = modelAnimator.readAnimationsFromFile(Application.dataPath + "/Resources/NAOStartingPositions.txt"); //Set returnToStartingPosition to false for each one foreach (ModelAnimation anim in startingPositions) { anim.returnToStartingPosition = false; } //Load locally created moves modelAnimator.animations = modelAnimator.readAnimationsFromFile(); //Move to fighting stance StartCoroutine(modelAnimator.animateModel(startingPositions[1], val => isMoving = val)); }
public PlayerMenu(Menu menu, LevelMenu levelMenu) : base(menu, new Vector2(640, 160)) { this.levelMenu = levelMenu; playerBackgroundInactive = Game.Instance.ContentManager.Load <Texture2D>("Sprites/Menu/robot_selection_background_inactive"); DrawPrevious = false; // initialize walking player hack Effect clonedEffect = Game.Instance.ContentManager.Load <Effect>("Effects/Basic/Basic").Clone(); playerModel = Game.Instance.ContentManager.Load <MagmaModel>("Models/Player/robot_grp").XnaModel; playerMesh = playerModel.Meshes[0]; foreach (ModelMeshPart meshPart in playerMesh.MeshParts) { Effect oldEffect = meshPart.Effect; meshPart.Effect = clonedEffect; oldEffect.Dispose(); } animator = new ModelAnimator(playerModel); walkController = new AnimationController(Game.Instance, animator.Animations["walk"]); Game.Instance.Components.RemoveAt(Game.Instance.Components.Count - 1); foreach (BonePose p in animator.BonePoses) { p.CurrentController = walkController; p.CurrentBlendController = null; p.BlendFactor = 0.0f; } playerPreview = new RenderTarget2D[MaxPlayers]; for (int i = 0; i < MaxPlayers; ++i) { playerPreview[i] = new RenderTarget2D(Game.Instance.GraphicsDevice, 445, 445, false, Game.Instance.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24Stencil8); } playerTexture = Game.Instance.ContentManager.Load <Texture2D>("Textures/Player/Robot_texture10"); specularTexture = Game.Instance.ContentManager.Load <Texture2D>("Textures/Player/robot_spec"); playerBoxSize = new SineFloat(0.96f, 1.0f, 8.0f); playerBoxSize.Start(0.001f); }
private void InitializeControllers() { animator = new ModelAnimator(Model); controllers = new Dictionary <string, AnimationController>(); foreach (string key in animator.Animations.Keys) { controllers.Add(key, new AnimationController(Game.Instance, animator.Animations[key])); // each controller registers itself in the game. we don't like this. Game.Instance.Components.RemoveAt(Game.Instance.Components.Count - 1); } // Console.WriteLine("components: " + Game.Instance.Components.Count); // set the first default controller RunController("idle0"); animationMode = AnimationMode.Permanent; permanentState = "idle0"; }
// // Use this for initialization void Start() { modelAnimator = GetComponent <ModelAnimator>(); //Load starting positions //startingPositions = modelAnimator.readAnimationsFromFile("Assets/Resources/NAOStartingPositions.txt"); startingPositions = modelAnimator.readAnimationsFromFile(Application.dataPath + "/Resources/NAOStartingPositions.txt"); //Set returnToStartingPosition to false for each one foreach (ModelAnimation anim in startingPositions) { anim.returnToStartingPosition = false; } //Load locally created moves modelAnimator.animations = modelAnimator.readAnimationsFromFile(); //Set up mouse orbit stuff Vector3 angles = transform.eulerAngles; x = angles.y; y = angles.x; transform.rotation = Quaternion.Euler(y, x, 0); //transform.position = transform.rotation * new Vector3(0.0f, 1.0f, -cameraOrbitDistance) + target.position; transform.position = target.transform.position - new Vector3(0.0f, -1.0f, -cameraOrbitDistance); // Make the rigid body not change rotation if (rigidbody) { rigidbody.freezeRotation = true; } //Set up dragging stuff //mainCamera = Camera.mainCamera; maxElbowDistanceFromShoulder = leftShoulder.lossyScale.x * .8F; maxHandDistanceFromShoulder = (leftShoulder.lossyScale.x * .8F) + (leftHand.lossyScale.x * .8F); maxKneeDistanceFromHip = leftThigh.lossyScale.x * 1.15F; //* .8F; //maxFootDistanceFromHip = (leftThigh.lossyScale.x * .8F) + (leftCalf.lossyScale.x * .8F); maxFootDistanceFromHip = (leftThigh.lossyScale.x * 1.15F) + (leftCalf.lossyScale.x * 1.15F); }
public void Draw(GameTime gameTime, Matrix view, Matrix projection) { Vector3 modelRotationModifier = Vector3.Zero; if (CharecterState == CharacterState.FiringRifle || CharecterState == CharacterState.ShootRifle) { modelRotationModifier.Y = 100; } else if ((CharecterState == CharacterState.RifleRun || CharecterState == CharacterState.Running) && (MovementCurrentDirection.X > 0)) { modelRotationModifier.Y = 100; } orientationMatrix = Matrix.CreateRotationX(rotation.X + modelRotationModifier.X) * Matrix.CreateRotationY(rotation.Y + modelRotationModifier.Y) * Matrix.CreateRotationZ(rotation.Z + modelRotationModifier.Z) * Matrix.CreateRotationY(MathHelper.Pi); world = orientationMatrix * Matrix.CreateTranslation(position); ModelAnimator.World = world; foreach (ModelMesh mesh in ModelAnimator.Model.Meshes) { foreach (Effect effect in mesh.Effects) { effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); } } ModelAnimator.Draw(gameTime); orientationMatrix = Matrix.CreateRotationX(rotation.X) * Matrix.CreateRotationY(rotation.Y) * Matrix.CreateRotationZ(rotation.Z) * Matrix.CreateRotationY(MathHelper.Pi); world = orientationMatrix * Matrix.CreateTranslation(position); }
public void Update(GameTime gameTime) { ModelAnimator.Update(gameTime); currentAnimationController.Update(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); } } } }