airbnb / lottie-web

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
MIT License
30.56k stars 2.87k forks source link

Canvas renderer ignoring 'context' #2058

Closed blaxbla123 closed 4 years ago

blaxbla123 commented 4 years ago

Tell us about your environment

What did you do? Please explain the steps you took before you encountered the problem.

I wanted to use only one canvas to render an animation as the compositing time in chrome with multiple canvases took too much resources. (I'm trying to do animation that fills the browser window) Here's the jist of the code I used:

const animation = lottie.loadAnimation({
            wrapper: animationObject.items.__container,
            // *tried with 'container' as well
            renderer: 'canvas',
            loop: false,
            autoplay: false,
            animationData: animationObject.data,
            rendererSettings: {
                clearCanvas: false,
                context: canvasContext,
                dpr: animationObject.items.respectDevicePixelRatio === false
                    ? 1
                    : this.ctx.dpr * this.ctx.dprMultiplier,
                preserveAspectRatio: 'xMidYMid slice',
            },
        });

*After reading through the source code, I saw it was looking for the wrapper property instead of the container property when deciding if it wants to create a canvas tag (at CanvasRenderer.configAnimation), unfortunately switching to that didn't work either.

What did you expect to happen?

Lottie would use the canvas context provided and do its magic there.

What actually happened? Please include as much relevant detail as possible.

When wrapper or container is passed, lottie creates a new canvas element for every time i execute 'loadAnimation'. It then proceeds to use the context of the newly created elements instead.

When wrapper or container isn't passed, after finding it out from #1215, lottie successfully uses the canvas context, but ignores:

Please provide a download link to the After Effects file that demonstrates the problem.

https://drive.google.com/drive/folders/1QN2TncgGWrATUA_h_L8ySYIk3vDZD9if?usp=sharing

(There are some things wrong in the project from performance troubleshooting but it should be sorta working)

bodymovin commented 4 years ago

have you tried not passing the wrapper?

blaxbla123 commented 4 years ago

When wrapper or container isn't passed, after finding it out from #1215, lottie successfully uses the canvas context, but ignores:

  • the canvas size - just renders out the full composition size from after effects, cropping it on the canvas:
  • preserveAspectRatio - scaling the canvas down manually reveals that it all starts to render at (0, 0)
blaxbla123 commented 4 years ago

That comment was lighting fast tho, thanks for that xd

bodymovin commented 4 years ago

If you are providing the canvas, the player assumes you'll apply the appropriate transformations to the canvas element before delegating the render to the library. That way you can compose your pieces of the canvas drawing with the animation itself.