Beispiel #1
0
        private void AnimationFinishedCallback(AnimationInstance animation)
        {
            PlayerAnimations.Id id = (PlayerAnimations.Id)animation.id;
            switch (id)
            {
            case PlayerAnimations.Id.Die:
            {
                Debug.Assert(!IsAlive);
                RemoveFromField();
                break;
            }

            case PlayerAnimations.Id.PunchBomb:
            {
                IsPunchingBomb = false;
                break;
            }

            case PlayerAnimations.Id.PickupBomb:
            {
                IsPickingUpBomb = false;
                break;
            }
            }
        }
Beispiel #2
0
        public TestScreen()
        {
            animationLookup = new Dictionary <AnimationId, AnimationContainer>();

            AnimationContainer container;

            container       = new AnimationContainer();
            container.up    = GetAnimation(A.anim_stand_north);
            container.down  = GetAnimation(A.anim_stand_south);
            container.left  = GetAnimation(A.anim_stand_west);
            container.right = GetAnimation(A.anim_stand_east);
            animationLookup[AnimationId.Stand] = container;

            container       = new AnimationContainer();
            container.up    = GetAnimation(A.anim_walk_north);
            container.down  = GetAnimation(A.anim_walk_south);
            container.left  = GetAnimation(A.anim_walk_west);
            container.right = GetAnimation(A.anim_walk_east);
            animationLookup[AnimationId.Walk] = container;

            container       = new AnimationContainer();
            container.up    = GetAnimation(A.anim_kick_north);
            container.down  = GetAnimation(A.anim_kick_south);
            container.left  = GetAnimation(A.anim_kick_west);
            container.right = GetAnimation(A.anim_kick_east);
            animationLookup[AnimationId.Kick] = container;

            groupInstance = new AnimationInstance();
            groupInstance.Init(GetAnimation(A.anim_die_green_1));
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplaceTransition"/> class.
        /// </summary>
        /// <param name="previousAnimation">The animation that should be replaced.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="previousAnimation"/> is <see langword="null"/>.
        /// </exception>
        public ReplaceTransition(AnimationInstance previousAnimation)
        {
            if (previousAnimation == null)
            throw new ArgumentNullException("previousAnimation");

              _previousAnimation = previousAnimation;
        }
Beispiel #4
0
        void LoadAnimations()
        {
            //  clear current state
            curAnimationInstance_ = -1;
            instances_            = null;
            blended_ = null;

            //  get the list of animations from our dictionary
            Dictionary <string, object> tag = loadedModel_.Model.Tag as Dictionary <string, object>;
            object aobj = null;

            if (tag != null)
            {
                tag.TryGetValue("AnimationSet", out aobj);
            }
            animations_ = aobj as AnimationSet;

            //  set up animations
            if (animations_ != null)
            {
                instances_ = new AnimationInstance[animations_.NumAnimations];
                //  I'll need a BlendedAnimation per animation, so that I can let the
                //  blender object transition between them.
                blended_ = new IBlendedAnimation[instances_.Length];
                int ix = 0;
                foreach (Animation a in animations_.Animations)
                {
                    instances_[ix] = new AnimationInstance(a);
                    blended_[ix]   = AnimationBlender.CreateBlendedAnimation(instances_[ix]);
                    ++ix;
                }
            }
        }
Beispiel #5
0
        //update...
        public UpdateFrequency Update(UpdateState state)
        {
            //when pressing A, create a new avatar description
            if (state.PlayerInput[PlayerIndex.One].InputState.Buttons.A.OnPressed)
            {
                this.avatar.AvatarDescription = Microsoft.Xna.Framework.GamerServices.AvatarDescription.CreateRandom();
            }

            //if pressing B, play the cheer animation
            if (state.PlayerInput[PlayerIndex.One].InputState.Buttons.B.OnPressed)
            {
                //start or stop the cheer animation (which is a built in animation in XNA)
                //use a fadein / fadeout
                if (!cheerAnimation.AnimationFinished)
                {
                    cheerAnimation.StopAnimation(0.5f);
                }
                else
                {
                    cheerAnimation = animationController.PlayPresetAnimation(AvatarAnimationPreset.Celebrate, true, 0.5f, 0.5f);
                }
            }

            //when the cheer animation is playing, fade the walking animation out,
            //do this based on the opposite weighitng of the cheer animation (taking fading into account)
            this.walkAnimation.Weighting = 1 - this.cheerAnimation.GetFadeScaledWeighting(state);

            return(UpdateFrequency.FullUpdate60hz);
        }
Beispiel #6
0
        /// <summary>
        /// Combines the new animation with existing animations by inserting the new animation after the
        /// specified animation into the composition chains. The new animation fades in over the
        /// specified duration.
        /// </summary>
        /// <param name="previousAnimation">
        /// The animation after which the new animation should be added.
        /// </param>
        /// <param name="fadeInDuration">The duration over which the new animation fades in.</param>
        /// <returns>The <see cref="AnimationTransition"/>.</returns>
        public static AnimationTransition Compose(AnimationInstance previousAnimation, TimeSpan fadeInDuration)
        {
            if (fadeInDuration > TimeSpan.Zero)
            return new FadeInAndComposeTransition(previousAnimation, fadeInDuration);

              return new ComposeTransition(previousAnimation);
        }
        private void InitaliseAnimations(UpdateManager updateManager)
        {
            //create the controller as an asynchronous controller.
            //this will process animations as a thread task
            //This occurs between the update loop and the draw loop,
            //which is why the UpdateManager must be provided.
            control = model.GetAsyncAnimationController(updateManager);

            //these perform a linear search to find the animation index
            int idleAnimationIndex = control.AnimationIndex("Loiter");
            int jogAnimationIndex  = control.AnimationIndex("Jog");
            int walkAnimationIndex = control.AnimationIndex("Walk");

            //create the idle animation
            idle = control.PlayLoopingAnimation(idleAnimationIndex);

            //give it a random speed
            idle.PlaybackSpeed = (float)random.NextDouble() * 0.5f + 0.6f;


            if (moveSpeed > 0.75)
            {
                //run animation
                move = control.PlayLoopingAnimation(jogAnimationIndex);                 // play a jogging animation
                move.PlaybackSpeed = 0.5f;
            }
            else
            {
                //walk animation
                move = control.PlayLoopingAnimation(walkAnimationIndex);                 // play a walking animation
            }
            //initially don't want the move animation being visible
            move.Weighting = 0;
        }
        private void SetActiveAnimationState(AnimationState animationState)
        {
            if (_activeAnimationState == animationState ||
                _activeModelDrawConditionState == null)
            {
                return;
            }

            var modelInstance = _activeModelDrawConditionState.Model;

            var firstAnimationBlock = animationState.Animations
                                      .FirstOrDefault();

            if (firstAnimationBlock != null)
            {
                foreach (var animation in firstAnimationBlock.Animations)
                {
                    var anim = animation.Value;
                    //Check if the animation does really exist
                    if (anim != null)
                    {
                        var animationInstance = new AnimationInstance(modelInstance, anim);
                        modelInstance.AnimationInstances.Add(animationInstance);
                        animationInstance.Play();
                        break;
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Setup bone attachment.
        /// </summary>
        /// <param name="animator"></param>
        /// <param name="parentBone"></param>
        public virtual void SetBone(AnimationInstance animator, ModelBone parentBone)
        {
            this.parentBone = parentBone;
            this.animator   = animator;

            UpdateTransforms();
        }
    void DrawAnimInstance(AnimationInstance ai)
    {
        int index = sequence.animations.IndexOf(ai);

        showData[index] = EditorGUILayout.Foldout(showData[index], "" + ai.animationData.name + "   " + ai.startTime + " ->  " + (ai.startTime + ai.animationData.duration));


        if (showData[index])
        {
            ai.animationData = (AnimationData)EditorGUILayout.ObjectField("Data", ai.animationData, typeof(AnimationData), true);
            ai.itemIndex     = EditorGUILayout.Popup("Item", ai.itemIndex, sequence.itemNames.ToArray());

            EditorGUIUtility.fieldWidth = 20;
            EditorGUIUtility.labelWidth = 80;
            EditorGUILayout.BeginHorizontal();
            ai.startTime = EditorGUILayout.FloatField("StartTime ", ai.startTime);
            if (!ai.animationData.SetValue)
            {
                ai.animationData.duration = EditorGUILayout.FloatField("Duration ", ai.animationData.duration);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUIUtility.fieldWidth = 0;
            EditorGUIUtility.labelWidth = 0;
            EditorGUILayout.LabelField("EndTime : " + (ai.startTime + ai.animationData.duration));
        }
    }
        /// <summary>
        /// Construct self from a model and active animation name.
        /// </summary>
        /// <param name="model"></param>
        /// <param name="animName"></param>
        public ModelAnim(FBXModel model, string animName)
        {
            ActiveAnimation = new AnimatorList(model);
            if (ActiveAnimation.NotEmpty)
            {
                AnimationInstance sample = ActiveAnimation.Sample;
                ActiveController = SimpleController.TryMake(sample, animName, sample.FirstAnimationName);

                if (ActiveController != null)
                {
                    ActiveAnimation.ApplyController(ActiveController);

                    IdleAnimation = new AnimatorList(model);
                    Debug.Assert(IdleAnimation.NotEmpty, "Could make active but not idle?");
                    sample         = IdleAnimation.Sample;
                    IdleController = SimpleController.TryMake(sample, "idle", null);
                    if (IdleController != null)
                    {
                        IdleAnimation.ApplyController(IdleController);
                    }
                    else
                    {
                        IdleAnimation = null;
                    }
                }
                else
                {
                    ActiveAnimation = null;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FadeInAndComposeTransition"/> class.
        /// </summary>
        /// <param name="previousAnimation">The animation that should be replaced.</param>
        /// <param name="fadeInDuration">The duration over which the new animation fades in.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="fadeInDuration"/> is 0 or negative.
        /// </exception>
        public FadeInAndComposeTransition(AnimationInstance previousAnimation, TimeSpan fadeInDuration)
        {
            if (fadeInDuration <= TimeSpan.Zero)
            throw new ArgumentOutOfRangeException("fadeInDuration", "The fade-in duration must be greater than 0.");

              _previousAnimation = previousAnimation;
              _fadeInDuration = fadeInDuration;
        }
        public void ShouldImplementIList()
        {
            var property         = new AnimatableProperty <float>();
            var compositionChain = AnimationCompositionChain <float> .Create(property, SingleTraits.Instance);

            var list = (IList <AnimationInstance>)compositionChain;
            var animationInstance0 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var animationInstance1 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var animationInstance2 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var wrongInstance = AnimationInstance.Create(new TimelineGroup());

            // The enumerator is not implemented (to prevent garbage).
            Assert.That(() => { list.GetEnumerator(); }, Throws.TypeOf <NotImplementedException>());

            // Add
            Assert.That(() => list.Add(wrongInstance), Throws.ArgumentException);
            list.Add(animationInstance0);

            // Contains
            Assert.IsTrue(list.Contains(animationInstance0));
            Assert.IsFalse(list.Contains(animationInstance1));
            Assert.IsFalse(list.Contains(wrongInstance));

            // IndexOf
            Assert.AreEqual(0, list.IndexOf(animationInstance0));
            Assert.AreEqual(-1, list.IndexOf(animationInstance1));
            Assert.AreEqual(-1, list.IndexOf(wrongInstance));

            // IsReadOnly
            Assert.IsFalse(list.IsReadOnly);

            // Insert
            list.Insert(1, animationInstance1);
            Assert.That(() => list.Insert(0, wrongInstance), Throws.ArgumentException);

            // Indexer
            Assert.AreEqual(animationInstance1, list[1]);
            list[0] = animationInstance2;
            Assert.That(() => list[0] = wrongInstance, Throws.ArgumentException);

            // CopyTo
            AnimationInstance[] array = new AnimationInstance[2];
            list.CopyTo(array, 0);
            Assert.AreEqual(animationInstance2, array[0]);
            Assert.AreEqual(animationInstance1, array[1]);

            // Remove
            Assert.IsTrue(list.Remove(animationInstance2));
            Assert.AreEqual(1, list.Count);
            Assert.IsFalse(list.Remove(wrongInstance));

            // RemoveAt
            list.RemoveAt(0);
            Assert.AreEqual(0, list.Count);
        }
Beispiel #14
0
        private void DrawPlayer(Context context, Player player)
        {
            TextureImage image = TempFindPlayerImage(player);
            float        drawX = player.GetPx() - 0.5f * cellWidth;
            float        drawY = player.GetPy() - 0.5f * cellHeight;

            if (CVars.g_drawPlayerCell.boolValue)
            {
                context.DrawRect(player.GetCx() * cellWidth, player.GetCy() * cellHeight, cellWidth, cellHeight, Color.White);
            }

            if (CVars.g_drawPlayerMovable.boolValue)
            {
                context.DrawRect(drawX, drawY, cellWidth, cellHeight, Color.Yellow);
            }

            if (player.IsInfected())
            {
                if (blink)
                {
                    AnimationInstance anim = player.currentAnimation;
                    anim.Draw(context, drawX + 0.5f * cellWidth, drawY + cellHeight);
                }
            }
            else
            {
                AnimationInstance anim = player.currentAnimation;
                anim.Draw(context, drawX + 0.5f * cellWidth, drawY + cellHeight);
            }

            if (CVars.g_drawPlayerStepRect.boolValue)
            {
                int stepX = Math.Sign(player.px - player.CellCenterPx());
                int stepY = Math.Sign(player.py - player.CellCenterPy());

                bool hasStepX = stepX != 0;
                bool hasStepY = stepY != 0;

                int cx = player.GetCx();
                int cy = player.GetCy();

                if (hasStepX && hasStepY)
                {
                    DrawCellRect(context, cx + stepX, cy, Color.Yellow);
                    DrawCellRect(context, cx, cy + stepY, Color.Yellow);
                    DrawCellRect(context, cx + stepX, cy + stepY, Color.Yellow);
                }
                else if (hasStepX)
                {
                    DrawCellRect(context, cx + stepX, cy, Color.Yellow);
                }
                else if (hasStepY)
                {
                    DrawCellRect(context, cx, cy + stepY, Color.Yellow);
                }
            }
        }
Beispiel #15
0
    void SetupInstance(int animationIndex, int startTime, byte remapFace)
    {
        currentAnimationIndex = animationIndex;
        EditDataSet tempEditSet = AppDataSet.Instance.ExtractEditSetForAnimation(animations[animationIndex]);

        dataSet         = tempEditSet.ToDataSet();
        currentInstance = dataSet.animations[0].CreateInstance(dataSet.animationBits);
        currentInstance.start(startTime, remapFace, false);
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplaceTransition"/> class.
        /// </summary>
        /// <param name="previousAnimation">The animation that should be replaced.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="previousAnimation"/> is <see langword="null"/>.
        /// </exception>
        public ReplaceTransition(AnimationInstance previousAnimation)
        {
            if (previousAnimation == null)
            {
                throw new ArgumentNullException("previousAnimation");
            }

            _previousAnimation = previousAnimation;
        }
Beispiel #17
0
        /// <summary>
        /// Set the owner actor.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="parentBone"></param>
        public virtual void SetOwner(GameActor owner)
        {
            this.owner = owner;
            int lod = Math.Max(0, owner.Animators.Count - 1);

            this.animator = owner.Animators[lod];

            UpdateTransforms();
        }
Beispiel #18
0
        /// <summary>
        /// Setup bone attachment.
        /// </summary>
        /// <param name="animator"></param>
        /// <param name="parentBone"></param>
        public override void SetBone(AnimationInstance animator, ModelBone parentBone)
        {
            base.SetBone(animator, parentBone);

            foreach (Rectangle rect in sides)
            {
                rect.SetBone(animator, parentBone);
            }
        }
Beispiel #19
0
        AnimationInstance ITimeline.CreateInstance()
        {
            if (!IsFrozen)
            {
                throw new AnimationException("This animation is not frozen. Freeze() must be called before the animation can be used.");
            }

            return(AnimationInstance <SkeletonPose> .Create(this));
        }
Beispiel #20
0
 public BlueprintsExtensibility()
 {
     blueprintActor          = Blueprint.Load("/Game/Tests/BlueprintActor");
     blueprintSceneComponent = Blueprint.Load("/Game/Tests/BlueprintSceneComponent");
     actor                 = new Actor(blueprint: blueprintActor);
     sceneComponent        = new SceneComponent(actor, blueprint: blueprintSceneComponent);
     levelScript           = World.GetActor <LevelScript>();
     skeletalMeshComponent = actor.GetComponent <SkeletalMeshComponent>();
     animationInstance     = skeletalMeshComponent.GetAnimationInstance();
 }
Beispiel #21
0
    public void ClearAnimations()
    {
        // Shouldn't have an instance if we don't have an animation
        currentInstance = null;
        dataSet         = null;
        currentState    = State.Idle;

        // Clear the animation
        animations.Clear();
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="FadeInAndComposeTransition"/> class.
        /// </summary>
        /// <param name="previousAnimation">The animation that should be replaced.</param>
        /// <param name="fadeInDuration">The duration over which the new animation fades in.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="fadeInDuration"/> is 0 or negative.
        /// </exception>
        public FadeInAndComposeTransition(AnimationInstance previousAnimation, TimeSpan fadeInDuration)
        {
            if (fadeInDuration <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("fadeInDuration", "The fade-in duration must be greater than 0.");
            }

            _previousAnimation = previousAnimation;
            _fadeInDuration    = fadeInDuration;
        }
Beispiel #23
0
        public void ShouldImplementIList()
        {
            var property = new AnimatableProperty<float>();
              var compositionChain = AnimationCompositionChain<float>.Create(property, SingleTraits.Instance);
              var list = (IList<AnimationInstance>)compositionChain;
              var animationInstance0 = AnimationInstance<float>.Create(new SingleFromToByAnimation());
              var animationInstance1 = AnimationInstance<float>.Create(new SingleFromToByAnimation());
              var animationInstance2 = AnimationInstance<float>.Create(new SingleFromToByAnimation());
              var wrongInstance = AnimationInstance.Create(new TimelineGroup());

              // The enumerator is not implemented (to prevent garbage).
              Assert.That(() => { list.GetEnumerator(); }, Throws.TypeOf<NotImplementedException>());

              // Add
              Assert.That(() => list.Add(wrongInstance), Throws.ArgumentException);
              list.Add(animationInstance0);

              // Contains
              Assert.IsTrue(list.Contains(animationInstance0));
              Assert.IsFalse(list.Contains(animationInstance1));
              Assert.IsFalse(list.Contains(wrongInstance));

              // IndexOf
              Assert.AreEqual(0, list.IndexOf(animationInstance0));
              Assert.AreEqual(-1, list.IndexOf(animationInstance1));
              Assert.AreEqual(-1, list.IndexOf(wrongInstance));

              // IsReadOnly
              Assert.IsFalse(list.IsReadOnly);

              // Insert
              list.Insert(1, animationInstance1);
              Assert.That(() => list.Insert(0, wrongInstance), Throws.ArgumentException);

              // Indexer
              Assert.AreEqual(animationInstance1, list[1]);
              list[0] = animationInstance2;
              Assert.That(() => list[0] = wrongInstance, Throws.ArgumentException);

              // CopyTo
              AnimationInstance[] array = new AnimationInstance[2];
              list.CopyTo(array, 0);
              Assert.AreEqual(animationInstance2, array[0]);
              Assert.AreEqual(animationInstance1, array[1]);

              // Remove
              Assert.IsTrue(list.Remove(animationInstance2));
              Assert.AreEqual(1, list.Count);
              Assert.IsFalse(list.Remove(wrongInstance));

              // RemoveAt
              list.RemoveAt(0);
              Assert.AreEqual(0, list.Count);
        }
Beispiel #24
0
        protected virtual bool SetActiveAnimationState(AnimationState animationState, Random random)
        {
            if (animationState == _activeAnimationState && (_activeModelDrawConditionState?.StillActive() ?? false))
            {
                return(false);
            }

            if (animationState == null ||
                animationState.Animations.Count == 0 ||
                _activeModelDrawConditionState == null)
            {
                return(true);
            }

            PreviousAnimationState = _activeAnimationState;

            if (_activeModelDrawConditionState?.Model != null)
            {
                foreach (var animationInstance in _activeModelDrawConditionState.Model.AnimationInstances)
                {
                    animationInstance.Stop();
                }
            }

            var modelInstance = _activeModelDrawConditionState.Model;

            modelInstance.AnimationInstances.Clear();
            _activeAnimationState = animationState;

            var animationBlock = animationState.Animations[random.Next(0, animationState.Animations.Count - 1)];

            if (animationBlock != null)
            {
                var anim = animationBlock.Animation.Value;
                //Check if the animation does really exist
                if (anim != null)
                {
                    var flags             = animationState.Flags;
                    var mode              = animationBlock.AnimationMode;
                    var animationInstance = new AnimationInstance(modelInstance.ModelBoneInstances, anim, mode, flags, GameObject, _context.Random);
                    modelInstance.AnimationInstances.Add(animationInstance);
                    animationInstance.Play(animationBlock.AnimationSpeedFactorRange.GetValue(random));
                }
            }

            if (animationState != null && animationState.Script != null)
            {
                _context.Scene3D.Game.Lua.ExecuteDrawModuleLuaCode(this, animationState.Script);
            }

            NLog.LogManager.GetCurrentClassLogger().Info($"Set active animation state for {GameObject.Definition.Name}");

            return(true);
        }
Beispiel #25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FadeInAndReplaceTransition"/> class.
        /// </summary>
        /// <param name="previousAnimation">The animation that should be replaced.</param>
        /// <param name="fadeInDuration">The duration over which the new animation fades in.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="previousAnimation"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="fadeInDuration"/> is 0 or negative.
        /// </exception>
        public FadeInAndReplaceTransition(AnimationInstance previousAnimation, TimeSpan fadeInDuration)
        {
            if (previousAnimation == null)
            throw new ArgumentNullException("previousAnimation");
              if (fadeInDuration <= TimeSpan.Zero)
            throw new ArgumentOutOfRangeException("fadeInDuration", "The fade-in duration must be greater than 0.");

              _previousAnimation = previousAnimation;
              _previousAnimationRunCount = previousAnimation.RunCount;
              _fadeInDuration = fadeInDuration;
        }
Beispiel #26
0
        /// <summary>
        /// Runs the KeyFrames Animation.
        /// </summary>
        internal IDisposable Run(Animation animation, Animatable control, IClock clock, Action onComplete)
        {
            var instance = new AnimationInstance <T>(
                animation,
                control,
                this,
                clock ?? control.Clock ?? Clock.GlobalClock,
                onComplete,
                InterpolationHandler);

            return(control.Bind <T>((AvaloniaProperty <T>)Property, instance, BindingPriority.Animation));
        }
Beispiel #27
0
        /// <summary>
        /// Runs the KeyFrames Animation.
        /// </summary>
        internal IDisposable Run(Animation animation, Animatable control, IClock?clock, Action?onComplete)
        {
            var instance = new AnimationInstance <T>(
                animation,
                control,
                this,
                clock ?? control.Clock ?? Clock.GlobalClock,
                onComplete,
                InterpolationHandler);

            return(BindAnimation(control, instance));
        }
        public void OnBeginPlay()
        {
            World.GetFirstPlayerController().SetViewTarget(World.GetActor <Camera>("MainCamera"));

            SkeletalMesh prototypeMesh = SkeletalMesh.Load("/Game/Tests/Characters/Prototype");

            Actor leftPrototype = new("leftPrototype");
            SkeletalMeshComponent leftSkeletalMeshComponent = new(leftPrototype);

            leftSkeletalMeshComponent.SetSkeletalMesh(prototypeMesh);
            leftSkeletalMeshComponent.SetWorldLocation(new(-700.0f, -70.0f, -100.0f));
            leftSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 0.0f, 90.0f));
            leftSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);
            leftSkeletalMeshComponent.PlayAnimation(AnimationSequence.Load("/Game/Tests/Characters/Animations/IdleAnimationSequence"), true);

            Assert.IsTrue(leftSkeletalMeshComponent.IsPlaying);
            Assert.IsTrue(leftSkeletalMeshComponent.GetBoneName(0) == "root");

            Bounds leftSkeletalMeshComponentBounds = default;

            leftSkeletalMeshComponent.GetBounds(leftSkeletalMeshComponent.GetTransform(), ref leftSkeletalMeshComponentBounds);

            Assert.IsFalse(leftSkeletalMeshComponentBounds == default(Bounds));

            Actor rightPrototype = new("rightPrototype");
            SkeletalMeshComponent rightSkeletalMeshComponent = new(rightPrototype);

            rightSkeletalMeshComponent.SetSkeletalMesh(prototypeMesh);
            rightSkeletalMeshComponent.SetWorldLocation(new(-700.0f, 70.0f, -100.0f));
            rightSkeletalMeshComponent.SetWorldRotation(Maths.Euler(0.0f, 0.0f, 90.0f));
            rightSkeletalMeshComponent.SetAnimationMode(AnimationMode.Asset);

            MaterialInstanceDynamic prototypeMaterial = rightSkeletalMeshComponent.CreateAndSetMaterialInstanceDynamic(0);

            prototypeMaterial.SetVectorParameterValue("AccentColor", new(0.0f, 0.5f, 1.0f));

            Assert.IsNotNull(prototypeMaterial.GetParent());

            AnimationMontage rightPrototypeAnimationMontage = AnimationMontage.Load("/Game/Tests/Characters/Animations/RunAnimationMontage");

            rightSkeletalMeshComponent.PlayAnimation(rightPrototypeAnimationMontage, true);

            AnimationInstance rightPrototypeAnimationInstance = rightSkeletalMeshComponent.GetAnimationInstance();

            Assert.IsTrue(rightPrototypeAnimationInstance.IsPlaying(rightPrototypeAnimationMontage));
            Assert.IsTrue(rightSkeletalMeshComponent.GetBoneName(0) == "root");

            Bounds rightSkeletalMeshComponentBounds = default;

            rightSkeletalMeshComponent.GetBounds(rightSkeletalMeshComponent.GetTransform(), ref rightSkeletalMeshComponentBounds);

            Assert.IsFalse(rightSkeletalMeshComponentBounds == default(Bounds));
        }
Beispiel #29
0
        public Actor(ContentRegister content, Vector3 position, float animationSpeed, int animationIndex)
        {
            Matrix.CreateRotationZ(1 - (float)animationIndex, out this.worldMatrix);
            this.worldMatrix.Translation = position;

            model = new ModelInstance();
            this.animationController = model.GetAnimationController();

            content.Add(this);

            this.animation = this.animationController.PlayLoopingAnimation(animationIndex);
            this.animation.PlaybackSpeed = animationSpeed;
        }
        public override void InitDeviceResources(GraphicsDevice device)
        {
            base.InitDeviceResources(device);
            _animators = new AnimatorList(StaticActor.Model);
            /// All animators in the stack should have the same set of animations.
            AnimationInstance animator = _animators.Sample;

            // TODO (****)  Do we need this check???
            if (animator.HasAnimation("full_running"))
            {
                // Add individual animations to blend controller.
                idleController = SimpleController.TryMake(animator, "full_running");
                SetAnimation(idleController);
            }
        }
Beispiel #31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FadeInAndReplaceTransition"/> class.
        /// </summary>
        /// <param name="previousAnimation">The animation that should be replaced.</param>
        /// <param name="fadeInDuration">The duration over which the new animation fades in.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="previousAnimation"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="fadeInDuration"/> is 0 or negative.
        /// </exception>
        public FadeInAndReplaceTransition(AnimationInstance previousAnimation, TimeSpan fadeInDuration)
        {
            if (previousAnimation == null)
            {
                throw new ArgumentNullException("previousAnimation");
            }
            if (fadeInDuration <= TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException("fadeInDuration", "The fade-in duration must be greater than 0.");
            }

            _previousAnimation         = previousAnimation;
            _previousAnimationRunCount = previousAnimation.RunCount;
            _fadeInDuration            = fadeInDuration;
        }
Beispiel #32
0
        private void DrawBomb(Context context, Bomb bomb)
        {
            float drawX = bomb.GetPx();
            float drawY = bomb.GetPy();

            AnimationInstance anim = bomb.currentAnimation;

            anim.Draw(context, drawX, drawY + 0.5f * cellHeight, bomb.IsBlocked ? Color.Red : Color.White);

            if (CVars.g_drawBombDir.boolValue)
            {
                TextureImage dirImage = dirLookup[bomb.direction];
                context.DrawImage(dirImage, drawX - 0.5f * dirImage.GetWidth(), drawY - 0.5f * dirImage.GetHeight());
            }

            context.DrawRect(bomb.cx * cellWidth, bomb.cy * cellHeight, cellWidth, cellHeight, Color.White);
            context.DrawRect(bomb.px - 0.5f * cellWidth, bomb.py - 0.5f * cellHeight, cellWidth, cellHeight, Color.Red);
        }
Beispiel #33
0
        private void DrawAnim(Context context, AnimationInstance instance, int x, int y)
        {
            int          frameIndex = instance.FrameIndex;
            TextureImage texture    = instance.Texture;

            Animation group = instance.Animation;

            Rectangle src;
            int       ox = group.frames[frameIndex].ox;
            int       oy = group.frames[frameIndex].oy;

            src.X      = group.frames[frameIndex].x;
            src.Y      = group.frames[frameIndex].y;
            src.Width  = group.frames[frameIndex].w;
            src.Height = group.frames[frameIndex].h;

            context.DrawImagePart(texture, src, x - ox, y - oy);
        }
Beispiel #34
0
        private void SetActiveAnimationState(AnimationState animationState, Random random)
        {
            if (animationState == null ||
                animationState.Animations.Count == 0 ||
                _activeModelDrawConditionState == null)
            {
                return;
            }

            if (_activeModelDrawConditionState.StillActive() == false)
            {
                _activeAnimationState = null;
            }
            else if (animationState == _activeAnimationState)
            {
                return;
            }

            _activeAnimationState = animationState;

            var modelInstance = _activeModelDrawConditionState.Model;

            modelInstance.AnimationInstances.Clear();

            var animationBlock = animationState.Animations[random.Next(0, animationState.Animations.Count - 1)];

            if (animationBlock != null)
            {
                foreach (var animation in animationBlock.Animations)
                {
                    var anim = animation.Value;
                    //Check if the animation does really exist
                    if (anim != null)
                    {
                        var flags             = animationState.Flags;
                        var mode              = animationBlock.AnimationMode;
                        var animationInstance = new AnimationInstance(modelInstance, anim, mode, flags, GameObject);
                        modelInstance.AnimationInstances.Add(animationInstance);
                        animationInstance.Play();
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Load up our animations and bind to the given model.
        /// </summary>
        /// <param name="sro"></param>
        private void LoadAnimations(FBXModel sro)
        {
            Debug.Assert(SharedAnim != null, "Must set SharedAnim to class's shared animation in constructor.");
            if (SharedAnim.ActiveAnimator == null)
            {
                SharedAnim.ActiveAnimator = new AnimatorList(sro);
            }
            _animators = SharedAnim.ActiveAnimator;
            AnimatorList      animList = SharedAnim.ActiveAnimator;
            AnimationInstance animator = animList.Sample;

            if (animator != null && animator.HasAnimation(SharedAnim.ActiveName))
            {
                if (SharedAnim.ActiveController == null)
                {
                    SharedAnim.ActiveController = SimpleController.TryMake(animator, SharedAnim.ActiveName);
                    AnimActive();
                }
            }
            else
            {
                animList.ApplyController(null);
            }
            if (SharedAnim.IdleAnimator == null)
            {
                SharedAnim.IdleAnimator = new AnimatorList(sro);
                AnimationInstance sharedIdle = SharedAnim.IdleAnimator.Sample;
                if ((sharedIdle != null) && sharedIdle.HasAnimation(SharedAnim.IdleName))
                {
                    SharedAnim.IdleController = SimpleController.TryMake(
                        sharedIdle,
                        SharedAnim.IdleName);
                }
                if (SharedAnim.IdleController != null)
                {
                    AnimIdle();
                }
                else
                {
                    SharedAnim.IdleAnimator = null;
                }
            }
        }
        protected void _InitAnimation(Animation data, ref AnimationInstance instance)
        {
            instance.Started = true;
            instance.Finished = false;

            // set parameter value -- note special case for vector2's
            instance.Parameter = Owner.Components.GetInterface<ValueInterface<float>>("float", data.ParameterName);
            if (instance.Parameter == null && data.ParameterName.EndsWith(".x", StringComparison.CurrentCultureIgnoreCase))
            {
                String param = data.ParameterName.Substring(0, data.ParameterName.Length - 2);
                instance.ParameterX = Owner.Components.GetInterface<ValueInterface<Vector2>>("vector2", param);
            }
            else if (instance.Parameter == null && data.ParameterName.EndsWith(".y", StringComparison.CurrentCultureIgnoreCase))
            {
                String param = data.ParameterName.Substring(0, data.ParameterName.Length - 2);
                instance.ParameterY = Owner.Components.GetInterface<ValueInterface<Vector2>>("vector2", param);
            }

            if (instance.Parameter == null && instance.ParameterX == null && instance.ParameterY == null)
            {
                instance.Finished = true;
                return;
            }

            if (instance.Scale == 0.0f)
                instance.Scale = 1.0f;

            if (data.RandomStart)
            {
                instance.Time = TorqueUtil.GetRandomFloat(data.Duration);
                if (data.PingPong && TorqueUtil.GetRandomFloat() < 0.5f)
                    instance.Scale *= -1.0f;
            }
            else if (instance.Scale > 0.0f)
                instance.Time = 0.0f;
            else
                instance.Time = data.Duration;

            instance.Started = true;
            instance.Finished = false;
            instance.Paused = false;
        }
Beispiel #37
0
 /// <summary>
 /// Combines the new animation with existing animations by inserting the new animation after the 
 /// specified animation into the composition chains. The new animation takes effect immediately.
 /// </summary>
 /// <param name="previousAnimation">
 /// The animation after which the new animation should be added.
 /// </param>
 /// <returns>The <see cref="AnimationTransition"/>.</returns>
 public static AnimationTransition Compose(AnimationInstance previousAnimation)
 {
     return new ComposeTransition(previousAnimation);
 }
Beispiel #38
0
 /// <summary>
 /// Replaces the specified animation with the new animation. The new animation takes effect
 /// immediately. The previous animation is stopped and removed from the animation system. 
 /// </summary>
 /// <param name="previousAnimation">The animation that should be replaced.</param>
 /// <returns>The <see cref="AnimationTransition"/>.</returns>
 public static AnimationTransition Replace(AnimationInstance previousAnimation)
 {
     return new ReplaceTransition(previousAnimation);
 }
Beispiel #39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComposeTransition"/> class.
 /// </summary>
 /// <param name="previousAnimation">The animation that should be replaced.</param>
 public ComposeTransition(AnimationInstance previousAnimation)
 {
     _previousAnimation = previousAnimation;
 }
Beispiel #40
0
        private readonly int _id; // 0 indicates an invalid AnimationController.

        #endregion Fields

        #region Constructors

        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="AnimationController"/> struct.
        /// </summary>
        internal AnimationController(AnimationManager animationManager, AnimationInstance animationInstance)
        {
            Debug.Assert(animationManager != null, "The animation system is null.");
              Debug.Assert(animationInstance != null, "The animation instance is null.");
              Debug.Assert(animationInstance.RunCount > 0, "The animation instance has an invalid RunCount.");

              _id = animationInstance.RunCount;
              _animationManager = animationManager;
              _animationInstance = animationInstance;
        }
Beispiel #41
0
 /// <summary>
 /// Throws an <see cref="InvalidOperationException"/>.
 /// </summary>
 /// <param name="index">
 /// The zero-based index at which <paramref name="child"/> should be inserted.
 /// </param>
 /// <param name="child">The object to insert.</param>
 /// <exception cref="InvalidOperationException">
 /// Cannot add animation instance. The current animation instance cannot have children.
 /// </exception>
 protected override void InsertItem(int index, AnimationInstance child)
 {
     throw new InvalidOperationException("Cannot add animation instance. The current animation instance cannot have children.");
 }