Exemple #1
0
        private IEnumerable <RenderTargetBitmap> ProduceAnimationFrames(Animation animation, int firstFrame, int lastFrame)
        {
            if (_document == null)
            {
                throw new Exception("Call PrepareDocument() first");
            }

            var bounds       = GetAnimationWorldBounds(animation, _document);
            var cameraCenter = new Vector(bounds.X + bounds.Width * 0.5, bounds.Y + bounds.Height * 0.5);

            var scale = GetCoercedScale();

            var width  = 500; //(int)Math.Ceiling(bounds.Width * scale);
            var height = 500; //(int) Math.Ceiling(bounds.Height * scale);

            ConfigureViewport(width, height);

            for (var i = firstFrame; i <= lastFrame; i++)
            {
                _document.ApplyAnimationToScene(animation.Id, i);

                SceneViewport.Clear();
                SceneViewport.PanTo(cameraCenter);
                SceneViewport.SetZoom(scale);

                AddSpritesToViewport(_document);
                var renderTarget = new RenderTargetBitmap(width, height, 144, 144, PixelFormats.Default);
                renderTarget.Render(SceneViewport);
                yield return(renderTarget);

                SavePng(renderTarget, $"{animation.Name}_{i:000}.png");
            }
        }
Exemple #2
0
 public void PanTo(Vector worldDistance)
 {
     SceneViewport.PanTo(worldDistance);
     UpdateAllGizmoTransforms();
 }