laggykiller / rlottie-python

A ctypes API for rlottie, with additional functions for getting Pillow Image.
https://rlottie-python.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
11 stars 1 forks source link

Any example for `lottie_animation_property_override`? #11

Open muhchaudhary opened 1 month ago

muhchaudhary commented 1 month ago

Hey, sorry if this is a dumb question but I can't get the lottie_animation_property_override function to work on my end. Do you by any chance have an example I could use?

laggykiller commented 1 month ago

I did not expect someone to use that function, so little thought was put into it.

Seems like I wrongly assumed that the *args are ctypes.float. They should be ctypes.double

https://github.com/Samsung/rlottie/blob/d40008707addacb636ff435236d31c694ce2b6cf/inc/rlottie_capi.h#L269-L290

https://github.com/Samsung/rlottie/blob/d40008707addacb636ff435236d31c694ce2b6cf/src/binding/c/lottieanimation_capi.cpp#L199-L286

To change fillcolor property of fill1 object in the layer1->group1->fill1 hirarchy to RED color:

lottie_animation_property_override(
    "LOTTIE_ANIMATION_PROPERTY_FILLCOLOR",
    "layer1.group1.fill1",
    ctypes.c_double(1.0),
    ctypes.c_double(0.0),
    ctypes.c_double(0.0)
)

If all the color property inside group1 needs to be changed to GREEN color:

lottie_animation_property_override(
    "LOTTIE_ANIMATION_PROPERTY_FILLCOLOR",
    "**.group1.**",
    ctypes.c_double(0.0),
    ctypes.c_double(1.0),
    ctypes.c_double(0.0)
)

Please try. If this works please tell me so I can make changes to the docs.

EDIT: Seems like it is not working and need some work, will update about this

laggykiller commented 1 month ago

Please try v1.3.6, I cannot demonstrate that it works, but should be less broken. Maybe you can figure this out yourself. Unfortunately I don't have more time and interest in digging further. Please tell me if it works.

Note that the API has changed: https://rlottie-python.readthedocs.io/en/latest/rlottie_python.html#rlottie_python.rlottie_wrapper.LottieAnimation.lottie_animation_property_override

You should call like:

from rlottie_python import LottieAnimation, LottieAnimationProperty

lottie_animation_property_override(
    LottieAnimationProperty.LOTTIE_ANIMATION_PROPERTY_FILLCOLOR,
    "layer1.group1.fill1",
    ctypes.c_double(1.0),
    ctypes.c_double(0.0),
    ctypes.c_double(0.0)
)
muhchaudhary commented 1 month ago

Sorry for the late reply, testing it with this simple lottie file, it dosn't seem to work

from rlottie_python.rlottie_wrapper import LottieAnimation, LottieAnimationProperty
import ctypes

anim = LottieAnimation.from_file("/home/muhammad/Downloads/circle.json")

anim.lottie_animation_property_override(
    LottieAnimationProperty.LOTTIE_ANIMATION_PROPERTY_FILLCOLOR,
    "Layer.Ellipse.Fill",
    ctypes.c_double(1.0),
    ctypes.c_double(0.1),
    ctypes.c_double(0.5),
)

anim.save_animation("/home/muhammad/Downloads/circle.gif")
laggykiller commented 1 month ago

yes I tried with something similar, not working, need more investigation by others...