-
Notifications
You must be signed in to change notification settings - Fork 23
Operators
An operator takes care of extracting data from the scene. Operators can save any kind of data not necessarily having to do with animation data.
Operators can be channel operators or item operators. Channel operators handle channel data, while item operators handle data related to an item (i.e. a maya or nuke node).
Currently 3 channels operators are supported:
- Curves Operator: for reading/writing animation curves from/to a channel
- Static Operator: for reading/writing a static value from/to a channel
- Bake operator: for reading/writing baked values to a channel
And 1 item operator:
- World Space Operator: for reading/writing the world space matrix of a 3D object
You can extend operators and register them into the Operators factory like this:
from kiko.operators.staticoperator import staticoperator
from kiko.operators.factory import OperatorsFactory
factory = OperatorsFactory()
factory.register(staticoperator.StaticOperator)
Chunks are saved in a default or user defined order. They are read in the same order when a kiko file is loaded. Users can still define the priority (the order) in which they are read at loading time. Any operator can prevent other subsequent operators to run at load time. This can be done with the ignore_following_operators() method of the BaseOperator class.
Here a very simple example which shows how you can build your own operator:
from kiko.constants import APPS, KIKO_TANGENT_TYPES
from kiko.operators.baseoperator import BaseOperator, BaseOperatorLoader
class StaticOperatorLoaderV1(BaseOperatorLoader):
@staticmethod
def version():
"""
Returns the loader version
"""
return 1
@staticmethod
def load(data, facade, node, import_anim_method, start_frame, end_frame,
frame_value, channel=None, time_multiplier=1):
"""
This method loads the data
:param data: the operator data
:param facade: the app facade.
:param node: The app node
:param import_anim_method: the import animation method
:param start_frame: the animation should only be imported from this frame
:param end_frame: the animation should only be imported until this frame
:param frame_value: the offset frame value
:param channel: the channel object, this is None if this is an item operator
:param time_multiplier: time_multiplier in case this scene has a different frame rate compared to the original scene
"""
facade.set_channel_value(node, channel, data['value'])
class MyStaticOperator(BaseOperator):
#IMPORTANT: need to have these two class static members declared in each
#operator class
_loaders = {}
_max_loader_version = None
@staticmethod
def name():
"""
return the operator name
"""
return "MyStaticOperator"
@staticmethod
def validate(facade, node, channel=None, force=False):
"""
validates if the operator should be run or not, channel is None if this is an item operator
"""
return force or not facade.is_channel_connected(node, channel)
@staticmethod
def ignore_following_operators():
"""
if returns true subsequent operators will be ignored
"""
return True
@staticmethod
def is_app_supported(app_name):
"""
returns if the given DCC name is supported
"""
return app_name in APPS.all()
@staticmethod
def is_channel_operator():
"""
returns if this is a channel operator, if returns false this becomes an item operator
"""
return True
@staticmethod
def bakeable():
"""
returns if this is a bakeable operator
"""
return False
@staticmethod
def get_frame_range(facade, node, channel=None):
"""
returns the export frame range of this operator
"""
return None
@staticmethod
def run(facade, node, channel=None, start_frame=None, end_frame=None):
"""
returns the data for this operator
"""
return {'value': facade.get_channel_value(node, channel)}
StaticOperator.register_loader(StaticOperatorLoaderV1)