Skip to content

Decouple curve serialization / writing to filesystem [Feature Request] #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vvzen opened this issue Jan 20, 2021 · 2 comments
Open

Comments

@vvzen
Copy link

vvzen commented Jan 20, 2021

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 vvzen changed the title De-couple serialization from write to filesystem Decouple curve serialization / writing to filesystem [Feature Request] Jan 20, 2021
@danielefederico
Copy link
Collaborator

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

@vvzen
Copy link
Author

vvzen commented Jan 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants