kiko icon indicating copy to clipboard operation
kiko copied to clipboard

Decouple curve serialization / writing to filesystem [Feature Request]

Open vvzen opened this issue 3 years ago • 2 comments

Hi all!

I'm on a quest to find a good way to export curve data to track retimes between Hiero, Nuke and Maya and I stumbled upon this nice library! (plus, we're both Italian and working in Framestore so I thought that it was a nice coincidence! :) )

I've been following through the wiki, but I soon realized that the way you've designed kiko means that one can't easily access the serialized object (via a public interface). Basically, everything is meant to be written to disk immediately. In my case, I'd like to embed this curve information into a metadata dictionary in my OTIO timeline (so I don't really need to write only the curve to disk).

For now, I came up with this:

from kiko.operators.factory import OperatorsFactory
from kiko.io import serializer
from kiko.apps.nuke.nukefacade import NukeFacade

s = serializer.Serializer(facade=NukeFacade)
node = nuke.toNode("TimeWarp1")
app_name = NukeFacade.get_app_name()
operators = OperatorsFactory().get_all_operator_names(app_name)

ops = []
for o in operators:
    op_c = None
    if isinstance(o, tuple):
        if OperatorsFactory.has_operator(o[0], version=o[1]):
            op_c = OperatorsFactory().get_operator(o[0], o[1])
    else:
        op_ver = OperatorsFactory().get_latest_version(o)
        if not op_ver is None:
            op_c = OperatorsFactory().get_operator(o, op_ver)

    if op_c is None:
        raise KikoManagerException('Could not find operator %s' % o)

    if not op_c.is_app_supported(app_name):
        continue

    ops.append(op_c)

serialized_curve = s.serialize("test", [node], operators=ops)

..which isn't that pretty :D

I think it could be useful if you could expose 2 separate methods, one for serializing, and the other one (more a utility than anything else) to serialize and write to disk at the same time (export_to_file()). I'd be happy to contribute myslef - at a first glance, it doesn't seem that hard to do.

Thanks!

Valerio

vvzen avatar Jan 20 '21 19:01 vvzen

Hello Valerio, you could add that as a separate method to the Kiko Manager class.

It would be just a matter of creating a new method and place in it all the code used by export_to_file up to the point where the file is created. export_to_file could then call this function, so that there is no duplicated code in different methods of the manager.

If you want to make this change and push it back I will merge it on master.

Thanks, Daniele

danielefederico avatar Jan 21 '21 14:01 danielefederico

Yep, thanks!

I also realized that

# kiko.io.serializer:Serializer
def serialize(self, file_name, objects, operators, hierarchy=False,
                  start_frame=None, end_frame=None, channel_filter=None,
                  force_op_evaluation=False)

has the file_name as an arg, but it's not actually used, which in my case it's actually nice since it means this can easily decoupled. I'll play around a bit more and then open a PR. Thanks!

Valerio

vvzen avatar Jan 21 '21 15:01 vvzen