示例#1
0
        public AnimationDescription LoadAnimation(string filePath)
        {
            if (_animations.ContainsKey(filePath))
            {
                return(_animations[filePath]);
            }

            var animation = AnimationDescription.Load(filePath);

            _animations.Add(filePath, animation);

            return(animation);
        }
示例#2
0
        public FileInfo AddAnimation(string filePath)
        {
            var animation = AnimationDescription.Create();

            animation.Name = Path.GetFileNameWithoutExtension(filePath);
            animation.Save(filePath);
            var animationFile = new FileInfo(filePath);

            _animationFiles.Add(filePath, animationFile);

            this.AnimationAdded?.Invoke(this, new FileEventArgs(animationFile));

            return(animationFile);
        }
示例#3
0
        /// <summary>
        /// Initialize the drawing data instance
        /// </summary>
        /// <param name="jointAnimations">Joint animation list</param>
        /// <param name="animationDescription">Animation description</param>
        public void Initialize(JointAnimation[] jointAnimations, AnimationDescription animationDescription)
        {
            if (animationDescription != null)
            {
                Dictionary <string, JointAnimation[]> dictAnimations = new Dictionary <string, JointAnimation[]>();

                foreach (var clip in animationDescription.Clips)
                {
                    JointAnimation[] ja = new JointAnimation[jointAnimations.Length];
                    for (int c = 0; c < ja.Length; c++)
                    {
                        Keyframe[] kfs = new Keyframe[clip.To - clip.From + 1];
                        Array.Copy(jointAnimations[c].Keyframes, clip.From, kfs, 0, kfs.Length);

                        float dTime = kfs[0].Time;
                        for (int k = 0; k < kfs.Length; k++)
                        {
                            kfs[k].Time -= dTime;
                        }

                        ja[c] = new JointAnimation(jointAnimations[c].Joint, kfs);
                    }

                    dictAnimations.Add(clip.Name, ja);
                }

                foreach (var key in dictAnimations.Keys)
                {
                    this.animations.Add(new AnimationClip(key, dictAnimations[key]));
                    this.clips.Add(key);
                }

                foreach (var transition in animationDescription.Transitions)
                {
                    this.AddTransition(
                        transition.ClipFrom,
                        transition.ClipTo,
                        transition.StartFrom,
                        transition.StartTo);
                }
            }
            else
            {
                this.animations.Add(new AnimationClip(DefaultClip, jointAnimations));
                this.clips.Add(DefaultClip);
            }

            //Initialize offsets for animation process with animation palette
            this.InitializeOffsets();
        }
        public DockAnimationEditor(Project project, string text, Image icon, FileInfo file)
            : this()
        {
            _project = project;

            _regularDockText = text;
            _unsavedDockText = text + "*";


            DockText = text;
            Icon     = icon;

            _file = file;

            _animationDescription = _project.LoadAnimation(file.FullName);

            this.txtSurfaceTexPath.Text     = _animationDescription.SurfaceAnimation.TexturePath;
            this.txtSurfaceFrameTime.Text   = _animationDescription.SurfaceAnimation.FrameTime.ToString();
            this.txtSurfaceFrameWidth.Text  = _animationDescription.SurfaceAnimation.FrameWidth.ToString();
            this.txtSurfaceFrameHeight.Text = _animationDescription.SurfaceAnimation.FrameHeight.ToString();
            this.txtSurfaceLoopCount.Text   = _animationDescription.SurfaceAnimation.LoopCount.ToString();

            this.txtSubSurfaceTexPath.Text     = _animationDescription.SubSurfaceAnimation.TexturePath;
            this.txtSubSurfaceFrameTime.Text   = _animationDescription.SubSurfaceAnimation.FrameTime.ToString();
            this.txtSubSurfaceFrameWidth.Text  = _animationDescription.SubSurfaceAnimation.FrameWidth.ToString();
            this.txtSubSurfaceFrameHeight.Text = _animationDescription.SubSurfaceAnimation.FrameHeight.ToString();
            this.txtSubSurfaceLoopCount.Text   = _animationDescription.SubSurfaceAnimation.LoopCount.ToString();

            _subSurfaceAnimation = new Animation(_animationDescription);
            _surfaceAnimation    = new Animation(_animationDescription);



            _subSurfaceAnimation.Play();
            _surfaceAnimation.Play();

            this.subSurfaceAnimView.OnDraw = OnSubAnimDraw;
            this.surfaceAnimView.OnDraw    = OnSurfAnimDraw;

            this.subSurfaceAnimView.OnUpdate = OnSubAnimUpdate;
            this.surfaceAnimView.OnUpdate    = OnSurfAnimUpdate;
        }
示例#5
0
 public Animation(AnimationDescription description) :
     base(description)
 {
 }
示例#6
0
    protected Node ST_PlayConversationAnims(
        SmartCharacter user, 
        AnimationDescription[] myAnims, 
        AnimationDescription[] userAnims)
    {
        BehaviorMecanim myBehavior = 
            this.GetComponent<BehaviorMecanim>();
        BehaviorMecanim userBehavior =
            user.GetComponent<BehaviorMecanim>();

        List<Node> animations = new List<Node>();
        for (int i = 0; i < myAnims.Length; i++)
        {
            animations.Add(
                myBehavior.ST_PlayGesture(
                    myAnims[i].Name, myAnims[i].Layer, 1500));
            animations.Add(
                userBehavior.ST_PlayGesture(
                    userAnims[i].Name, userAnims[i].Layer, 1500));
        }

        return new Sequence(animations.ToArray());
    }
示例#7
0
 protected Node ST_ApproachConverse(
     SmartCharacter user,
     AnimationDescription[] myAnims,
     AnimationDescription[] userAnims) {
     return new Sequence(
             Node_GoToUpToRadius(Val.V(() => user.transform.position), 1.3f),
             Node_HeadLook(Val.V(() => user.MarkerHead.position)),
             user.Node_HeadLook(Val.V(() => this.MarkerHead.position)),
             user.Node_HeadLook(Val.V(() => this.MarkerHead.position)),
         ST_PlayConversationAnims(user, myAnims, userAnims),
         Node_HeadLookStop(),
         user.Node_HeadLookStop()
     );
 }
示例#8
0
 protected Node ST_PlainConverse(
     SmartCharacter user,
     AnimationDescription[] myAnims,
     AnimationDescription[] userAnims) {
     return new Sequence(
             Node_HeadLook(Val.V(() => user.MarkerHead.position)),
             user.Node_HeadLook(Val.V(() => this.MarkerHead.position)),
         ST_PlayConversationAnims(user, myAnims, userAnims),
         Node_HeadLookStop(),
         user.Node_HeadLookStop()
     );
 }
示例#9
0
        private Storyboard CreateEnterAnimation(Windows.UI.Xaml.Controls.Panel layoutRoot)
        {
            var enterAnimation = new Storyboard();

            // Use the AnimationDescription object if available. Otherwise, return an empty storyboard (no animation).
            if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Core.AnimationMetrics.AnimationDescription"))
            {
                Storyboard.SetTarget(enterAnimation, layoutRoot);

                var ad = new AnimationDescription(AnimationEffect.EnterPage, AnimationEffectTarget.Primary);
                for (int i = 0; i < layoutRoot.Children.Count; i++)
                {
                    // Add a render transform to the existing one just for animations
                    var element = layoutRoot.Children[i];
                    var tg      = new TransformGroup();
                    tg.Children.Add(new TranslateTransform());
                    tg.Children.Add(element.RenderTransform);
                    element.RenderTransform = tg;

                    // Calculate the stagger for each animation. Note that this has a max
                    var delayMs = Math.Min(ad.StaggerDelay.TotalMilliseconds * i * ad.StaggerDelayFactor, ad.DelayLimit.Milliseconds);
                    var delay   = TimeSpan.FromMilliseconds(delayMs);

                    foreach (var description in ad.Animations)
                    {
                        var animation = new DoubleAnimationUsingKeyFrames();

                        // Start the animation at the right offset
                        var startSpline = new SplineDoubleKeyFrame();
                        startSpline.KeyTime = TimeSpan.FromMilliseconds(0);
                        Storyboard.SetTarget(animation, element);

                        // Hold at that offset until the stagger delay is hit
                        var middleSpline = new SplineDoubleKeyFrame();
                        middleSpline.KeyTime = delay;

                        // Animation from delayed time to last time
                        var endSpline = new SplineDoubleKeyFrame();
                        endSpline.KeySpline = new KeySpline()
                        {
                            ControlPoint1 = description.Control1, ControlPoint2 = description.Control2
                        };
                        endSpline.KeyTime = description.Duration + delay;

                        // Do the translation
                        if (description.Type == PropertyAnimationType.Translation)
                        {
                            startSpline.Value  = ANIMATION_TRANSLATION_START;
                            middleSpline.Value = ANIMATION_TRANSLATION_START;
                            endSpline.Value    = ANIMATION_TRANSLATION_END;

                            Storyboard.SetTargetProperty(animation, "(UIElement.RenderTransform).(TransformGroup.Children)[0].X");
                        }
                        // Opacity
                        else if (description.Type == PropertyAnimationType.Opacity)
                        {
                            startSpline.Value  = ANIMATION_OPACITY_START;
                            middleSpline.Value = ANIMATION_OPACITY_START;
                            endSpline.Value    = ANIMATION_OPACITY_END;

                            Storyboard.SetTargetProperty(animation, "Opacity");
                        }
                        else
                        {
                            throw new Exception("Encountered an unexpected animation type.");
                        }

                        // Put the final animation together
                        animation.KeyFrames.Add(startSpline);
                        animation.KeyFrames.Add(middleSpline);
                        animation.KeyFrames.Add(endSpline);
                        enterAnimation.Children.Add(animation);
                    }
                }
            }
            return(enterAnimation);
        }
        /// <summary>
        /// Retrieves the specified metrics and displays them in textual form.
        /// </summary>
        /// <param name="effect">The AnimationEffect whose metrics are to be displayed.</param>
        /// <param name="target">The AnimationEffecTarget whose metrics are to be displayed.</param>
        private void DisplayMetrics(AnimationEffect effect, AnimationEffectTarget target)
        {
            var s = new System.Text.StringBuilder();
            AnimationDescription animationDescription = new AnimationDescription(effect, target);

            s.AppendFormat("Stagger delay = {0}ms", animationDescription.StaggerDelay.TotalMilliseconds);
            s.AppendLine();
            s.AppendFormat("Stagger delay factor = {0}", animationDescription.StaggerDelayFactor);
            s.AppendLine();
            s.AppendFormat("Delay limit = {0}ms", animationDescription.DelayLimit.TotalMilliseconds);
            s.AppendLine();
            s.AppendFormat("ZOrder = {0}", animationDescription.ZOrder);
            s.AppendLine();
            s.AppendLine();

            int animationIndex = 0;

            foreach (var animation in animationDescription.Animations)
            {
                s.AppendFormat("Animation #{0}:", ++animationIndex);
                s.AppendLine();

                switch (animation.Type)
                {
                case PropertyAnimationType.Scale:
                {
                    ScaleAnimation scale = animation as ScaleAnimation;
                    s.AppendLine("Type = Scale");
                    if (scale.InitialScaleX.HasValue)
                    {
                        s.AppendFormat("InitialScaleX = {0}", scale.InitialScaleX.Value);
                        s.AppendLine();
                    }
                    if (scale.InitialScaleY.HasValue)
                    {
                        s.AppendFormat("InitialScaleY = {0}", scale.InitialScaleY.Value);
                        s.AppendLine();
                    }
                    s.AppendFormat("FinalScaleX = {0}", scale.FinalScaleX);
                    s.AppendLine();
                    s.AppendFormat("FinalScaleY = {0}", scale.FinalScaleY);
                    s.AppendLine();
                    s.AppendFormat("Origin = {0}, {1}", scale.NormalizedOrigin.X, scale.NormalizedOrigin.Y);
                    s.AppendLine();
                }
                break;

                case PropertyAnimationType.Translation:
                    s.AppendLine("Type = Translation");
                    break;

                case PropertyAnimationType.Opacity:
                {
                    OpacityAnimation opacity = animation as OpacityAnimation;
                    s.AppendLine("Type = Opacity");
                    if (opacity.InitialOpacity.HasValue)
                    {
                        s.AppendFormat("InitialOpacity = {0}", opacity.InitialOpacity.Value);
                        s.AppendLine();
                    }
                    s.AppendFormat("FinalOpacity = {0}", opacity.FinalOpacity);
                    s.AppendLine();
                }
                break;
                }

                s.AppendFormat("Delay = {0}ms", animation.Delay.TotalMilliseconds);
                s.AppendLine();
                s.AppendFormat("Duration = {0}ms", animation.Duration.TotalMilliseconds);
                s.AppendLine();
                s.AppendFormat("Cubic Bezier control points");
                s.AppendLine();
                s.AppendFormat("    X1 = {0}, Y1 = {1}", animation.Control1.X, animation.Control1.Y);
                s.AppendLine();
                s.AppendFormat("    X2 = {0}, Y2 = {1}", animation.Control2.X, animation.Control2.Y);
                s.AppendLine();
                s.AppendLine();
            }

            Metrics.Text = s.ToString();
        }
示例#11
0
 /// <summary>
 /// Constructor de serialización
 /// </summary>
 /// <param name="info">Info</param>
 /// <param name="context">Context</param>
 protected AnimationDictionary(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     Definition = info.GetValue <AnimationDescription>("Definition");
 }