Пример #1
0
        private Visual3DAnimationNode CreateAnimationNode(Visual3D visual, IList <Position3DKeyFrame> positionKeyFrames)
        {
            var animationNode = new Visual3DAnimationNode(visual);

            foreach (var positionKeyFrame in positionKeyFrames)
            {
                animationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(positionKeyFrame.FrameNumber, positionKeyFrame.Position));
            }

            return(animationNode);
        }
Пример #2
0
        private void StartAnimation1()
        {
            // Create a new CameraAnimationNode that will animate the Camera1
            var objectAnimationNode = new Visual3DAnimationNode(AnimatedObjectVisual3D);

            // NOTE:
            // To animate Model3DGroup or GeometryModel3D create Model3DAnimationNode instead of Visual3DAnimationNode

            // When Visual3DAnimationNode (or Model3DAnimationNode) is created, the RotationCenterPosition is set to the center of the specified 3D object.
            // This makes the rotation and scale animation rotate and scale from the center of the object.
            // In our case we want to only scale upwards (not in all directions).
            // To do that we just adjust the RotationCenterPosition so that its Y position is at the bottom of the 3D object (y = 0)
            objectAnimationNode.RotationCenterPosition = new Point3D(objectAnimationNode.RotationCenterPosition.X, 0, objectAnimationNode.RotationCenterPosition.Z);


            // adjust number of frames between each position key frame so that the whole position animation takes 500 frames (5 seconds)
            int framesPerPosition = 500 / _usedAnimationPositions.Count;


            // Create key frames for position animation
            for (var i = 0; i < _usedAnimationPositions.Count; i++)
            {
                objectAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(i * framesPerPosition, _usedAnimationPositions[i]));
            }

            objectAnimationNode.PositionTrack.EasingFunction = Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction;



            // After position animation is completed, we start simple rotation and scale animation
            double rotationScaleStartFrame = objectAnimationNode.PositionTrack.LastFrame;

            objectAnimationNode.RotationTrack.Keys.Add(new AnglesRotationKeyFrame(0, 0, 0));
            objectAnimationNode.RotationTrack.Keys.Add(new AnglesRotationKeyFrame(rotationScaleStartFrame, 0, 0));
            objectAnimationNode.RotationTrack.Keys.Add(new AnglesRotationKeyFrame(rotationScaleStartFrame + 200, 0, 180));
            objectAnimationNode.RotationTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);

            objectAnimationNode.ScaleTrack.Keys.Add(new Vector3DKeyFrame(0, new Vector3D(1, 1, 1)));                             // No scale until frame 600
            objectAnimationNode.ScaleTrack.Keys.Add(new Vector3DKeyFrame(rotationScaleStartFrame, new Vector3D(1, 1, 1)));       // At frame 600 start scaling ...
            objectAnimationNode.ScaleTrack.Keys.Add(new Vector3DKeyFrame(rotationScaleStartFrame + 100, new Vector3D(3, 3, 3))); // ... to 3x the size ...
            objectAnimationNode.ScaleTrack.Keys.Add(new Vector3DKeyFrame(rotationScaleStartFrame + 200, new Vector3D(1, 1, 1))); // ... and then back to original size
            objectAnimationNode.ScaleTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            // Set this animation to revert but not to repeat
            _animationController.AutoReverse = false;
            _animationController.AutoRepeat  = false;

            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(objectAnimationNode);
        }
Пример #3
0
        public AnimationSettings()
        {
            InitializeComponent();

            _selectedEasingFunction = GetSelectedEasingFunction();

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                UpdateEasingGraph();
            }

            _animationController = new AnimationController();

            // After each animation frame we will update the position of the red line that shows where the animation progress is
            _animationController.AfterFrameUpdated += delegate(object sender, EventArgs args) { UpdateCurrentTimeLine(); };


            _visual3DAnimationNode = new Visual3DAnimationNode(Sphere1);

            _visual3DAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(0, new Point3D(0, 0, 0)));
            _visual3DAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(120, new Point3D(0, 100, 0)));

            _animationController.AnimationNodes.Add(_visual3DAnimationNode);
            _animationController.FramesPerSecond = 60;
            _animationController.AutoRepeat      = true;
            _animationController.AutoReverse     = true;

            _visual3DAnimationNode.PositionTrack.EasingFunction = _selectedEasingFunction;


            _animationController.StartAnimation(subscribeToRenderingEvent: true);

            _animationController.AnimationStopped += delegate(object sender, EventArgs args)
            {
                UpdateStartStopAnimationButton();
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // AnimationController will stop animating when it is collected by GC, but anyway it is better to stop the animation when we leave this sample
                _animationController.StopAnimation();
            };
        }