Ejemplo n.º 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");
            }
        }
Ejemplo n.º 2
0
 private void Clear()
 {
     SceneViewport.Clear();
     _spriteBitmapStore.Clear();
     _items.Clear();
     foreach (var gizmo in _gizmos)
     {
         gizmo.Dispose();
     }
     _gizmos.Clear();
     AddGizmo(new AxesGizmo(GizmoCanvasBack));
     UpdateAllGizmoTransforms(); // the axes gizmo
 }
Ejemplo n.º 3
0
        private Rect CalculateMaxBounds(Animation animation, Document document)
        {
            var globalAabb = Rect.Empty;

            for (var i = animation.BeginFrame; i <= animation.EndFrame; i++)
            {
                document.ApplyAnimationToScene(animation.Id, i);

                SceneViewport.Clear();
                var aabb = AddSpritesToViewport(document);

                globalAabb = CombineAabb(globalAabb, aabb);
            }

            return(globalAabb);
        }