Beispiel #1
0
 public override void changeAnim(int i)
 {
     switch(i)
     {
         default:
             activeClip = fly;
             break;
         case 1:
             activeClip = start;
             break;
         case 2:
             activeClip = spin;
             break;
         case 3:
             activeClip = end;
             break;
         case 4:
             activeClip = hit;
             break;
         case 5:
             activeClip = elec;
             break;
     }
     activeIndex = i;
     animPlayer.StartClip(activeClip);
 }
        public override void Draw(GameTime gameTime)
        {
            //clip = skinningData.AnimationClips[currentclip];
            if (restart == true)
            {
                clip = skinningData.AnimationClips[currentclip];
                restart = !restart;
                animationPlayer.StartClip(clip);
            }
            Matrix[] bones = animationPlayer.GetSkinTransforms();

            // Render the skinned mesh.
            foreach (ModelMesh mesh in hippo.Meshes)
            {
                foreach (SkinnedEffect effect in mesh.Effects)
                {
                    effect.SetBoneTransforms(bones);
                    effect.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                    effect.Texture = texture;
                    effect.World = worldMatrix;
                    effect.View = parent.c.view;
                    effect.Projection = parent.c.proj;
                    effect.EnableDefaultLighting();

                }

                mesh.Draw();
            }

            base.Draw(gameTime);
        }
Beispiel #3
0
        public SpawnVortex(Vector3 pos, Vector3 rot, Game1 game)
            : base()
        {
            this.pos = pos;
            this.rot = rot;
            this.game = game;
            model = ModelLibrary.vortex;
            tex = game.Content.Load<Texture2D>(@"Models/Enemies/SpawnPoint/spiraltest");
            scale = new Vector3(0.8f,0.8f,0.7f);

            SkinningData skinningData = ModelLibrary.vortex.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animPlayer = new AnimationPlayer(skinningData);

            animClip = skinningData.AnimationClips["Take 001"];

            animPlayer.StartClip(animClip);

            SetupEffects();

            sb = new SpriteBatch(game.GraphicsDevice);
            targ1 = new RenderTarget2D(game.GraphicsDevice, 1024, 1024);
            targ2 = new RenderTarget2D(game.GraphicsDevice, 1024, 1024);
            texPos = Vector2.Zero;
        }
Beispiel #4
0
		public void StartClip(AnimationClip clip) {
			if (clip == null) {
				throw new ArgumentNullException("clip");
			}

			CurrentClip = clip;
			CurrentTime = TimeSpan.Zero;
			mCurrentKeyframe = 0;
			mSkinningDataValue.BindPose.CopyTo(mBoneTransforms, 0);
		}
Beispiel #5
0
        public override void changeAnim(int i)
        {
            switch(i)
            {
                default:
                    activeClip = fly;
                    break;
                case 1:
                    activeClip = trans;
                    break;
                case 2:
                    activeClip = shoot;
                    break;
                case 3:
                    activeClip = rel;
                    break;
                case 4:
                    activeClip = idle;
                    break;
                case 5:
                    activeClip = attack1;
                    break;
                case 6:
                    activeClip = attack2;
                    break;
                case 7:
                    activeClip = hit1;
                    break;
                case 8:
                    activeClip = hit2;
                    break;
                case 9:
                    activeClip = elec1;
                    break;
                case 10:
                    activeClip = elec2;
                    break;
                case 11:
                    activeClip = trans2;
                    break;
            }

            if(i != 11)
            {
                animSpeed = 1;
            }
            else
            {
                animSpeed = -1;
            }

            activeIndex = i;

            animPlayer.StartClip(activeClip);
        }
Beispiel #6
0
        /// <summary>
        /// 指定されたアニメーションクリップのデコーディング開始
        /// </summary>
        public void StartClip(AnimationClip clip)
        {
            if (clip == null)
                throw new ArgumentNullException("clip");

            currentClipValue = clip;
            currentTimeValue = TimeSpan.Zero;
            currentKeyframe = 0;

            // ボーン変換行列をバインドポーズで初期化する
            skinningDataValue.BindPose.CopyTo(boneTransforms, 0);
        }
        /// <summary>
        /// Starts decoding the specified animation clip.
        /// </summary>
        public void StartClip(AnimationClip clip)
        {
            if (clip == null)
                throw new ArgumentNullException("clip");

            currentClipValue = clip;
            currentTimeValue = TimeSpan.Zero;
            currentKeyframe = 0;

            // Initialize bone transforms to the bind pose.
            skinningDataValue.BindPose.CopyTo(boneTransforms, 0);
        }
Beispiel #8
0
 public ClipPlayer(SkinningData skd, float fps)
 {
     currentClip = skd.AnimationClips["Take 001"];
     keyframeList = currentClip.Keyframes;
     skinData = skd;
     boneTransforms = new Matrix[skd.BindPose.Count];
     skinTransforms = new Matrix[skd.BindPose.Count];
     worldTransforms = new Matrix[skd.BindPose.Count];
     startTime = TimeSpan.FromMilliseconds(0);
     currentTime = startTime;
     endTime = currentTime;
     this.fps = fps;
 }
Beispiel #9
0
        public HeavyModel(Heavy enemy)
            : base(enemy)
        {
            this.heavy = enemy;
            model = ModelLibrary.hevFly;
            scale = new Vector3(.2f);

            setAnims();

            activeClip = fly;
            animPlayer.StartClip(activeClip);

            SetupEffects();
        }
Beispiel #10
0
        public SneakerModel(Sneaker enemy)
            : base(enemy)
        {
            this.sneaker = enemy;
            model = ModelLibrary.sneFly;
            scale = new Vector3(.1f);

            setAnims();

            activeClip = fly;
            animPlayer.StartClip(activeClip);

            SetupEffects();
        }
Beispiel #11
0
        public GunnerModel(Gunner enemy)
            : base(enemy)
        {
            this.gunner = enemy;
            model = ModelLibrary.gunFly1;
            scale = new Vector3(.1f);

            setAnims();

            activeClip = fly;
            animPlayer.StartClip(activeClip);

            SetupEffects();
        }
Beispiel #12
0
        // Load Content
        public static void LoadContent(ContentManager content)
        {
            model = content.Load<Model>("Model\\dude");

            skinData = model.Tag as SkinningData;
            if(skinData == null)
            {
                throw new InvalidOperationException("This model does not contain a SkinningData tag");
            }

            player = new AnimationPlayer(skinData);
            clip = skinData.AnimationClips["Take 001"];

            player.StartClip(clip);

            random = new Random();
        }
        /// <summary>
        /// Duration Based Animation constructor
        /// </summary>
        /// <param name="skin"></param>
        /// <param name="clip"></param>
        /// <param name="Dictionary of valid bones - null if all bones are valid"></param>
        public DurationBasedAnimator(SkinningData skin, AnimationClip clip, Dictionary<int, int> validBones)
        {
            // store skin data
            skindata = skin;

            // store the long clip
            fullclip = clip;
            fullclipDuration = fullclip.Duration;

            // set up empty matrices
            boneTransforms = new Matrix[skin.BindPose.Count];
            worldTransforms = new Matrix[skin.BindPose.Count];
            skinTransforms = new Matrix[skin.BindPose.Count];
            
            durations = new Dictionary<int, DurationClip>();

            this.validBones = validBones;
        }
Beispiel #14
0
        public OtherPlayer(float x, float y, float z, Int32 identity, Int16 mo, float xro, float yro)
        {
            model = mo;
            Console.WriteLine(mo);
            position.X = x;
            position.Y = y;
            position.Z = z;
            id = identity;
            alive = true;
            Console.WriteLine(mo.ToString());
            if (model == Constants.HAMPUS)
            {
                mod = Globals.hampus;
                clipPlayer = new ClipPlayer(Globals.hampusSkinningData, 60);
                animationClip = Globals.hampusSkinningData.AnimationClips["Take 001"];
            }
            else if (model == Constants.RASMUS)
            {
                mod = Globals.rasmus;
                clipPlayer = new ClipPlayer(Globals.rasmusSkinningData, 60);
                animationClip = Globals.rasmusSkinningData.AnimationClips["Take 001"];
            }
            else if (model == Constants.VALTER)
            {
                mod = Globals.valter;
                clipPlayer = new ClipPlayer(Globals.valterSkinningData, 60);
                animationClip = Globals.valterSkinningData.AnimationClips["Take 001"];
            }
            else if (model == Constants.AXEL)
            {
                mod = Globals.axel;
                clipPlayer = new ClipPlayer(Globals.axelSkinningData, 60);
                animationClip = Globals.axelSkinningData.AnimationClips["Take 001"];
            }

            Globals.s += identity;

            xr = xro;
            yr = yro;
            Globals.players[identity] = this;

            //idle
            clipPlayer.play(animationClip, 570, 600, true);
        }
Beispiel #15
0
        private void LoadKillers()
        {
            rasmus = Content.Load<Model>("Models/rasmusFinal");
            hampus = Content.Load<Model>("Models/hampusFinal");
            valter = Content.Load<Model>("Models/valterFinal");
            axel = Content.Load<Model>("Models/axelFinal5");
            rifleModel = Content.Load<Model>("Models/rifleHands1");
            gunPos = riflePos;
            currentWep = rifleModel;

            hampusSkinningData = hampus.Tag as SkinningData;
            rasmusSkinningData = rasmus.Tag as SkinningData;
            axelSkinningData = axel.Tag as SkinningData;
            valterSkinningData = valter.Tag as SkinningData;
            if (hampusSkinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag. Har du satt SkinnedModelProcessor? ");
            Globals.hampusSkinningData = hampusSkinningData;
            Globals.rasmusSkinningData = rasmusSkinningData;
            Globals.axelSkinningData = axelSkinningData;
            Globals.valterSkinningData = valterSkinningData;
            rifleSkinningData = rifleModel.Tag as SkinningData;
            if (rifleSkinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag. Har du satt SkinnedModelProcessor? ");

            clipPlayer = new ClipPlayer(rifleSkinningData, fps);
            rifleClip = rifleSkinningData.AnimationClips["Take 001"];

            shadowEffect = Content.Load<Effect>("Effects/ShadowEffect");
        }
Beispiel #16
0
 public void PlayAnimation(String Animation)
 {
     clip = skinningData.AnimationClips[Animation];
     if (clip != animationPlayer.CurrentClip)
         animationPlayer.StartClip(clip);
 }
        public Zombie(int health, int maxHealth, ZombieType type, ref Model modelwalk, ref Model modelatt, ref Model modelhurt, ref Model modeldie, Action<Entity, Entity> attackFunction, Func<Vector3, Vector3, PathFinding.Node> astarGetter)
            : base()
        {
            this.astarGetter = astarGetter;
            this.model = modelwalk;
            this.HealthPoints = health;
            this.MaxHealth = maxHealth;

            this.MaxVelocity = 0.04f;
            this.MaxAcceleration = 0.04f;
            if (type == ZombieType.Boss)
            {
                this.MaxVelocity *= 2;
                this.MaxAcceleration *= 2;
                this.modelRadius *= 2;
            }
            ArriveRadius = 1;
            FleeRadius = 30;
            TimeToTarget = 0.070f;
            RotationTimeToTarget = 0.00025f;
            InterpolationSpeed = 10;
            TargetRotation = 0.02f;
            SlowRotationThreshold = (float)Math.PI;
            SlowRadiusThreshold = (float)Math.PI * 3;
            MaxRotationSpeed = (float)Math.PI / 12;
            MaxRotationAcceleration = (float)Math.PI;

            PosState = EntityPositionState.SteeringWander;
            OrState = EntityOrientationState.Face;
            BehaviouralState = BehaviourState.Wander;

            zombieType = type;
            MeleeAttack = new Weapon(WeaponType.ZombieHands);
            RangedAttack = new Weapon(WeaponType.Vomit);
            if (type == ZombieType.Boss)
            {
                MeleeAttack.FirePower *= 2;
                RangedAttack.FirePower *= 2;
            }
            this.AttackFunction = attackFunction;
            lastAttackTime = 0;

            // Look up our custom skinning information. for walking
            skinningDatawalk = (SkinningData)modelwalk.Tag;

            if (skinningDatawalk == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerwalk = new AnimationPlayer(skinningDatawalk);
            clipwalk = skinningDatawalk.AnimationClips["Take 001"];
            animationPlayerwalk.StartClip(clipwalk);

            // Look up our custom skinning information. for dying
            skinningDatadie = (SkinningData)modeldie.Tag;

            if (skinningDatadie == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerdie = new AnimationPlayer(skinningDatadie);
            clipdie = skinningDatadie.AnimationClips["Take 001"];
            animationPlayerdie.StartClip(clipdie);

            // Look up our custom skinning information. for attacking
            skinningDataattack = (SkinningData)modelatt.Tag;

            if (skinningDataattack == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerattack = new AnimationPlayer(skinningDataattack);
            clipattack = skinningDataattack.AnimationClips["Take 001"];
            animationPlayerattack.StartClip(clipattack);

            // Look up our custom skinning information. for hurting
            skinningDatahurt = (SkinningData)modelhurt.Tag;

            if (skinningDatahurt == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerhurt = new AnimationPlayer(skinningDatahurt);
            cliphurt = skinningDatahurt.AnimationClips["Take 001"];
            animationPlayerhurt.StartClip(cliphurt);
        }
Beispiel #18
0
        protected void setAnims()
        {
            SkinningData skinningData = ModelLibrary.sneFly.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animPlayer = new AnimationPlayer(skinningData);

            fly = skinningData.AnimationClips["Take 001"];

            skinningData = ModelLibrary.sneStart.Tag as SkinningData;
            start = skinningData.AnimationClips["Take 001"];

            skinningData = ModelLibrary.sneSpin.Tag as SkinningData;
            spin = skinningData.AnimationClips["Take 001"];

            skinningData = ModelLibrary.sneEnd.Tag as SkinningData;
            end = skinningData.AnimationClips["Take 001"];

            skinningData = ModelLibrary.sneHit.Tag as SkinningData;
            hit = skinningData.AnimationClips["Take 001"];

            skinningData = ModelLibrary.sneElec.Tag as SkinningData;
            elec = skinningData.AnimationClips["Take 001"];
        }
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            // Load the model.
            currentModel = Content.Load<Model>("InfectedDruggie");

            // Look up our custom skinning information.
            SkinningData skinningData = currentModel.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            //AnimationClip clip = skinningData.AnimationClips["Take 001"];

            //animationPlayer.RegisteredEvents["Fall"].Add("FireFrame", new AnimationPlayer.EventCallBack(OnFire));

               // animations = new AnimationClip[3];
            //animations[0] = new AnimationClip[skinningData.AnimationClips];

            fpos = skinningData.AnimationClips["Fpos"];
            idle = skinningData.AnimationClips["Idle"];
            idle2 = skinningData.AnimationClips["Idle2"];
            run = skinningData.AnimationClips["Run"];
            attack = skinningData.AnimationClips["Attack"];
            die = skinningData.AnimationClips["Die"];

            /* animations[0] = idle;
             animations[1] = jump;
             animations[3] = fall;
             */

            // start with idle animation

                animationPlayer.StartClip(run, true);
        }
Beispiel #20
0
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Allow switching the texture
            // This is just for demonstration purposes -- in the actual program
            // we'll need to have the texture control on a hold timer or mouse
            // button click so that it doesn't quickly flitter through textures
            // like in this demo.
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                currentTexture += 1;
            }

            // Use F1-F8 to switch animations
            // Animations are written into FBX file by their animation track name.  We cna call them
            // direction in the AnimationClips array.  These are all of the animations I want to use
            // for the hippo.  Some have gotten initialized away from the hippo's actual standing location
            // for some reason, but we can just transform the hippo's location in the game to correct
            // for this.
            if (Keyboard.GetState().IsKeyDown(Keys.F1))
            {
                clip = skinningData.AnimationClips["Dance"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F2))
            {
                clip = skinningData.AnimationClips["Headshake"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F3))
            {
                clip = skinningData.AnimationClips["Jump"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F4))
            {
                clip = skinningData.AnimationClips["Looking"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F5))
            {
                clip = skinningData.AnimationClips["Stomplong"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F6))
            {
                clip = skinningData.AnimationClips["Wiggleface"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F7))
            {
                clip = skinningData.AnimationClips["Grazing"];
                animationPlayer.StartClip(clip);
                animating = true;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.F8))
            {
                animating = false;
            }

            if (animating)  // Process animation
            {
                animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);

                Matrix[] boneTransforms = new Matrix[m.Bones.Count];
                animationPlayer.GetBoneTransforms().CopyTo(boneTransforms, 0);

                animationPlayer.UpdateWorldTransforms(Matrix.Identity, boneTransforms);
                animationPlayer.UpdateSkinTransforms();
            }
            else //Stop animation at current frame
            {

                Matrix[] boneTransforms = new Matrix[m.Bones.Count];
            }

            base.Update(gameTime);
        }
        public Hero(int health, int maxHealth, ref Model modelwalk, ref Model  modeldie, ref Model modelhurt, Action<Entity, Entity> actionFunction)
            : base()
        {
            this.model = modelwalk;
            this.HealthPoints = health;
            this.MaxHealth = maxHealth;
            this.Stance = AnimationStance.Standing;

            PowerupsList = new List<Powerup>();
            ItemsList = new Dictionary<Item, int>();
            WeaponsList = new Dictionary<Weapon, int>();
            this.ActionFunction = actionFunction;

            //get animations
            // Look up our custom skinning information. for walking

            skinningDatawalk = (SkinningData)modelwalk.Tag;

            if (skinningDatawalk == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerwalk = new AnimationPlayer(skinningDatawalk);
            clipwalk = skinningDatawalk.AnimationClips["Take 001"];
            animationPlayerwalk.StartClip(clipwalk);

            // Look up our custom skinning information. for dying
            skinningDatadie = (SkinningData)modeldie.Tag;

            if (skinningDatadie == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerdie = new AnimationPlayer(skinningDatadie);
            clipdie = skinningDatadie.AnimationClips["Take 001"];
            animationPlayerdie.StartClip(clipdie);

            // Look up our custom skinning information. for hurting
            skinningDatahurt = (SkinningData)modelhurt.Tag;

            if (skinningDatahurt == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayerhurt = new AnimationPlayer(skinningDatahurt);
            cliphurt = skinningDatahurt.AnimationClips["Take 001"];
            animationPlayerhurt.StartClip(cliphurt);

            //adding flanking info
            for (int i = 0; i < 6; i++)
            {
                slots[i] = new Node();
            }
        }
Beispiel #22
0
        protected override void LoadContent()
        {
            hippo = parent.Content.Load<Model>(@"hippo/pet_hippo");
            textures[0] = parent.Content.Load<Texture2D>(@"hippo/hippo_blueeyes_default");
            textures[1] = parent.Content.Load<Texture2D>(@"hippo/hippo_blueeyes_pink");
            textures[2] = parent.Content.Load<Texture2D>(@"hippo/hippo_blueeyes_blue");
            textures[3] = parent.Content.Load<Texture2D>(@"hippo/hippo_blueeyes_camo");

            texture = textures[0];

            skinningData = hippo.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            // Set clip to an animation track as written in the .fbx file
            currentclip = clips[0];
            clip = skinningData.AnimationClips[currentclip];

            // initialize animation
            animationPlayer.StartClip(clip);
            animating = true;

            hipposound = parent.Content.Load<SoundEffect>(@"sound\hipposound");
            birds = parent.Content.Load<SoundEffect>(@"sound\birds");
        }
        AnimationClip ExtractAnimation(AnimationClip rootAnimation, int startFrame, int endFrame)
        {
            TimeSpan startTime = ConvertFrameNumberToTimeSpan(startFrame);
            TimeSpan endTime = ConvertFrameNumberToTimeSpan(endFrame);

            List<Keyframe> keyframes = new List<Keyframe>();

            foreach (Keyframe keyframe in rootAnimation.Keyframes)
            {

                if (keyframe.Time >= startTime && keyframe.Time <= endTime)
                {
                    Keyframe newKeyframe = new Keyframe(keyframe.Bone, keyframe.Time - startTime, keyframe.Transform);
                    keyframes.Add(newKeyframe);
                }
            }
            return new AnimationClip(endTime - startTime, keyframes);
        }
		private static AnimationClip ProcessAnimation(AnimationContent animation, Dictionary<string, int> boneMap) {
			int num = 0;
			bool count;
			List<Keyframe> keyframes = new List<Keyframe>();
			IEnumerator<KeyValuePair<string, AnimationChannel>> enumerator = animation.Channels.GetEnumerator();
			try {
				while (true) {
					count = enumerator.MoveNext();
					if (!count) {
						break;
					}
					KeyValuePair<string, AnimationChannel> current = enumerator.Current;
					count = boneMap.TryGetValue(current.Key, out num);
					if (!count) {
						throw new InvalidContentException(string.Format("Found animation for bone '{0}', which is not part of the skeleton.", current.Key));
					}
					IEnumerator<AnimationKeyframe> enumerator1 = current.Value.GetEnumerator();
					try {
						while (true) {
							count = enumerator1.MoveNext();
							if (!count) {
								break;
							}
							AnimationKeyframe animationKeyframe = enumerator1.Current;
							keyframes.Add(new Keyframe(num, animationKeyframe.Time, animationKeyframe.Transform));
						}
					} finally {
						count = enumerator1 == null;
						if (!count) {
							enumerator1.Dispose();
						}
					}
				}
			} finally {
				count = enumerator == null;
				if (!count) {
					enumerator.Dispose();
				}
			}
			keyframes.Sort(SkinnedModelProcessor.CompareKeyframeTimes);
			count = keyframes.Count != 0;
			if (count) {
				count = !(animation.Duration <= TimeSpan.Zero);
				if (count) {
					AnimationClip animationClip = new AnimationClip(animation.Duration, keyframes);
					return animationClip;
				} else {
					throw new InvalidContentException("Animation has a zero duration.");
				}
			} else {
				throw new InvalidContentException("Animation has no keyframes.");
			}
		}
        /// <summary>
        /// Converts an intermediate format content pipeline AnimationContentDictionary
        /// object to our runtime AnimationClip format.
        /// </summary>
        static Dictionary<string, AnimationClip> ProcessAnimations(
            AnimationContentDictionary animations, IList<BoneContent> bones,
            ContentProcessorContext context, ContentIdentity sourceIdentity)
        {
            // Build up a table mapping bone names to indices.
            Dictionary<string, int> boneMap = new Dictionary<string, int>();

            for (int i = 0; i < bones.Count; i++)
            {
                string boneName = bones[i].Name;

                if (!string.IsNullOrEmpty(boneName))
                    boneMap.Add(boneName, i);
            }

            // Convert each animation in turn.
            Dictionary<string, AnimationClip> animationClips;
            animationClips = new Dictionary<string, AnimationClip>();

            foreach (KeyValuePair<string, AnimationContent> animation in animations)
            {
                AnimationClip processed = ProcessAnimation(animation.Value, boneMap, animation.Key);

                animationClips.Add(animation.Key, processed);
            }

            // Check to see if there's an animation clip definition
            // Here, we're checking for a file with the _Anims suffix.
            // So, if your model is named dude.fbx, we'd add dude_Anims.xml in the same folder
            // and the pipeline will see the file and use it to override the animations in the
            // original model file.
            string SourceModelFile = sourceIdentity.SourceFilename;
            string SourcePath = Path.GetDirectoryName(SourceModelFile);
            string AnimFilename = Path.GetFileNameWithoutExtension(SourceModelFile);
            AnimFilename += "_Anims.xml";
            string AnimPath = Path.Combine(SourcePath, AnimFilename);
            if (File.Exists(AnimPath))
            {
                context.AddDependency(AnimPath);

                AnimationDefinition AnimDef = context.BuildAndLoadAsset<XmlImporter, AnimationDefinition>(new ExternalReference<XmlImporter>(AnimPath), null);

                //breaks up original animation clips into new clips
                if (animationClips.ContainsKey(AnimDef.originalClipName))
                {
                    //graps main clip
                    AnimationClip MainClip = animationClips[AnimDef.originalClipName];
                    //remove original clip from animations
                    animationClips.Remove(AnimDef.originalClipName);

                    foreach (AnimationDefinition.clipPart Part in AnimDef.ClipParts)
                    {
                        //calculate frame times
                        TimeSpan StartTime = GetTimeSpanForFrame(Part.StartFrame, AnimDef.originalFrameCount, MainClip.Duration.Ticks);
                        TimeSpan EndTime = GetTimeSpanForFrame(Part.EndFrame, AnimDef.originalFrameCount, MainClip.Duration.Ticks);

                        //get keyframes for animation clip thats in start and end time
                        List<Keyframe> Keyframes = new List<Keyframe>();
                        foreach (Keyframe AnimFrame in MainClip.Keyframes)
                        {
                            if ((AnimFrame.Time >= StartTime) && (AnimFrame.Time <= EndTime))
                            {
                                Keyframe NewFrame = new Keyframe(AnimFrame.Bone, AnimFrame.Time - StartTime, AnimFrame.Transform);
                                Keyframes.Add(NewFrame);
                            }
                        }

                        //process events
                        /*List<AnimationEvent> Events = new List<AnimationEvent>();
                        if (Part.Events != null)
                        {
                            foreach (AnimationDefinition.clipPart.Event Event in Part.Events)
                            {
                                TimeSpan EventTime = GetTimeSpanForFrame(Event.Keyframe, AnimDef.originalFrameCount, MainClip.Duration.Ticks);
                                EventTime -= StartTime;

                                AnimationEvent newEvent = new AnimationEvent();
                                newEvent.EventTime = EventTime;
                                newEvent.EventName = Event.Name;
                                Events.Add(newEvent);
                            }
                        }*/

                        AnimationClip newClip = new AnimationClip(EndTime - StartTime, Keyframes, Part.ClipName);
                        animationClips[Part.ClipName] = newClip;
                    }
                }
            }

               /* if (animationClips.Count == 0)
            {
                throw new InvalidContentException(
                            "Input file does not contain any animations.");
            }*/

            return animationClips;
        }
 public AnimationPackage(SkinningData skin, float keyframeCount)
 {
     keyframes = keyframeCount;
     fullclip = skin.AnimationClips["Take 001"];
     bpCount = skin.BindPose.Count;
     ms = (int)fullclip.Duration.TotalMilliseconds;
     c = ms / keyframeCount;
     animations = new Dictionary<int, DurationClip>();
 }
Beispiel #27
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            c = new Camera(this);
            Components.Add(c);

            // Load model
            m = Content.Load<Model>("pet_hippo");

            // Load textures into an array
            textures[0] = Content.Load<Texture2D>("hippo_blueeyes_default");
            textures[1] = Content.Load<Texture2D>("hippo_blueeyes_pink");
            textures[2] = Content.Load<Texture2D>("hippo_blueeyes_blue");
            textures[3] = Content.Load<Texture2D>("hippo_blueeyes_camo");

            skinningData = m.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            // Set clip to an animation track as written in the .fbx file
            clip = skinningData.AnimationClips["Dance"];

            // initialize animation
            animationPlayer.StartClip(clip);
            animating = true;
        }
        private void LoadAnimations()
        {
            // Create an animation player, and start decoding an animation clip.
            mIdlePlayer = new AnimationPlayer( mSkinData );
            mRunPlayer = new AnimationPlayer( mSkinData );
            mJumpPlayer = new AnimationPlayer( mSkinData );
            mFallPlayer = new AnimationPlayer( mSkinData );

            mIdleClip = mSkinData.AnimationClips[ "idle" ];
            mRunClip = mSkinData.AnimationClips[ "run" ];
            mJumpClip = mSkinData.AnimationClips[ "jump" ];
            mFallClip = mSkinData.AnimationClips[ "fall" ];

            mRunPlayer.StartClip( mRunClip );
            mIdlePlayer.StartClip( mIdleClip );
            mJumpPlayer.StartClip( mJumpClip );
            mFallPlayer.StartClip( mFallClip );
        }
Beispiel #29
0
 public void play(AnimationClip clip, float startFrame,
     float endFrame, bool loop)
 {
     this.currentClip = clip;
     startTime = TimeSpan.FromMilliseconds(startFrame / fps * 1000);
     endTime = TimeSpan.FromMilliseconds(endFrame / fps * 1000);
     currentTime = startTime;
     isLooping = loop;
     keyframeList = currentClip.Keyframes;
     donePlayingAnimation = false;
 }
        Dictionary<string, AnimationClip> SplitAnimations(AnimationClip rootAnimation, string animationDefs)
        {
            Dictionary<string, AnimationClip> splitAnimations = new Dictionary<string, AnimationClip>();
            StreamReader fileReader = new StreamReader(animationDefs);

            while (!fileReader.EndOfStream)
            {

                string line = fileReader.ReadLine();
                string[] parts = line.Split(' ');
                string animName = parts[0].Trim('"');
                int startFrame = int.Parse(parts[1]);
                int endFrame = int.Parse(parts[2]);
                splitAnimations[animName] = ExtractAnimation(rootAnimation, startFrame, endFrame);
            }

            fileReader.Close();
            return splitAnimations;
        }