dominikh / gutter

MIT License
3 stars 0 forks source link

lottie: support resizing precomps #5

Closed dominikh closed 3 weeks ago

dominikh commented 3 weeks ago

Consider

{
    "v": "5.8.1",
    "fr": 60,
    "ip": 0,
    "op": 1,
    "w": 1024,
    "h": 1024,
    "nm": "emoji_baseball",
    "ddd": 0,
    "assets": [
        {
            "id": "myprecomp",
            "layers": [
                {
                    "ty": 4,
                    "st": 0,
                    "ip": 0,
                    "op": 1,
                    "ks": {
                        "a": {
                            "a": 0,
                            "k": [
                                0,
                                0
                            ]
                        },
                        "p": {
                            "a": 0,
                            "k": [
                                0,
                                0
                            ]
                        },
                        "s": {
                            "a": 0,
                            "k": [
                                100,
                                100
                            ]
                        },
                        "r": {
                            "a": 0,
                            "k": 0
                        },
                        "o": {
                            "a": 0,
                            "k": 100
                        }
                    },
                    "shapes": [
                        {
                            "ty": "rc",
                            "s": {
                                "a": 0,
                                "k": [
                                    1024,
                                    1024
                                ]
                            },
                            "p": {
                                "a": 0,
                                "k": [
                                    512,
                                    512
                                ]
                            },
                            "r": {
                                "a": 0,
                                "k": 0
                            }
                        },
                        {
                            "ty": "fl",
                            "c": {
                                "a": 0,
                                "k": [
                                    0,
                                    1,
                                    0
                                ]
                            },
                            "o": {
                                "a": 0,
                                "k": 100
                            }
                        }
                    ]
                }
            ]
        }
    ],
    "layers": [
        {
            "ty": 0,
            "st": 0,
            "ip": 0,
            "op": 1,
            "ks": {
                "a": {
                    "a": 0,
                    "k": [
                        0,
                        0
                    ]
                },
                "p": {
                    "a": 0,
                    "k": [
                        0,
                        0
                    ]
                },
                "s": {
                    "a": 0,
                    "k": [
                        100,
                        100
                    ]
                },
                "r": {
                    "a": 0,
                    "k": 0
                },
                "o": {
                    "a": 0,
                    "k": 100
                }
            },
            "refId": "myprecomp",
            "w": 256,
            "h": 256
        }
    ]
}

Here, our precomposition layer renders the precomposition myprecomp at a size of 256x256. This means we need to encode the precomposition, then scale it down to a size of 256x256. This proves difficult because we scale by multipliers, not absolute sizes, and we don't know the size of the precomposition, neither before nor after encoding it as a scene. It is not clear if we need the bounding box of the control points (which would be easy), or the bounding box of the rendered scene, which would be difficult.

dominikh commented 3 weeks ago

I was mistaken, the width and height of the precomp layer aren't for scaling, but for clipping. This is more evident with an ellipse than a rectangle...