def __init__(self, node_in, reload_metadata=False):
        """Take a nuke node, such as a read node or a Cryptomatte gizmo,
        and Reformat metadata into a dictionary, and collect channel
        information."""
        self.cryptomattes = {}
        self.nuke_node = node_in
        self.selection = None
        self.filename = None

        if not self.nuke_node:
            return

        exr_metadata_dict = {}
        if not reload_metadata:
            exr_metadata_dict = self._load_minimal_metadata()

        if not exr_metadata_dict:
            exr_metadata_dict = self.nuke_node.metadata(view=nuke.thisView()) or {}

        default_selection = None
        
        self.cachable_metadata = {}
        for key, value in exr_metadata_dict.iteritems():
            if key == "input/filename":
                self.filename = value
                self.cachable_metadata[key] = value
            for prefix in CRYPTO_METADATA_LEGAL_PREFIX:
                if not key.startswith(prefix):
                    continue
                numbered_key = key[len(prefix):] # ex: "exr/cryptomatte/ae93ba3/name" --> "ae93ba3/name"
                metadata_id, partial_key = numbered_key.split("/")  # ex: "ae93ba3/name" --> ae93ba3, "name"
                if metadata_id not in self.cryptomattes:
                    self.cryptomattes[metadata_id] = {}
                if partial_key == "name":
                    value = _legal_nuke_layer_name(value)
                self.cryptomattes[metadata_id][partial_key] = value
                self.cryptomattes[metadata_id]['md_prefix'] = prefix
                if partial_key != "manifest":
                    self.cachable_metadata[key] = value
                break

        if self.cryptomattes:
            default_selection = sorted(self.cryptomattes.keys(), key=lambda x: self.cryptomattes[x]['name'])[0]

        for metadata_id, value in self.cryptomattes.iteritems():
            name = value.get("name", "") 
            channels = self._identify_channels(name)
            self.cryptomattes[metadata_id]["channels"] = channels

        self.selection = default_selection
        if self.nuke_node.Class() in ["Cryptomatte", "Encryptomatte"]:
            selection_name = self.nuke_node.knob("cryptoLayer").getValue()
            if selection_name:
                valid_selection = self.set_selection(selection_name)
                if not valid_selection and not self.nuke_node.knob("cryptoLayerLock").getValue():
                    self.selection = default_selection
示例#2
0
    def get_channel_value(node_obj, channel_obj):
        knob = channel_obj[0]
        index = channel_obj[1]

        val = knob.getValue(index, nuke.thisView(), nuke.frame())

        if isinstance(knob, nuke.Enumeration_Knob):
            return int(val)
        if isinstance(knob, nuke.Boolean_Knob):
            return bool(val)
        return val
 def lazy_load_manifest(self):
     import json
     if 'manifest' not in self.cryptomattes[self.selection]:
         manif_key = self.get_selection_metadata_key('manifest')
         manif_str = self.nuke_node.metadata(manif_key,
                                             view=nuke.thisView())
         if manif_str is None:
             return {}
         else:
             self.cryptomattes[self.selection]['manifest'] = manif_str
     try:
         return json.loads(self.cryptomattes[self.selection]['manifest'])
     except ValueError as e:
         print("Cryptomatte: Unable to parse manifest. (%s)." % e)
         return {}
示例#4
0
文件: nukefacade.py 项目: vvzen/kiko
    def get_channel_value(node_obj, channel_obj):
        knob = channel_obj[0]
        index = channel_obj[1]

        val = knob.getValue(index, nuke.thisView(), nuke.frame())

        if isinstance(knob, nuke.Enumeration_Knob):
            return int(val)
        if isinstance(knob, nuke.Boolean_Knob):
            return bool(val)

        converter = get_nuke_to_kiko_converter(node_obj, knob)
        if converter:
            val = converter(node_obj, knob, index, val)

        return val
示例#5
0
def topInputNode(node, ch_class, input=0):
    if node:
        input_node = node.input(input)
        if input_node:
            if nodeClass(input_node) == ch_class:
                return input_node
            else:
                if nodeClass(input_node) == 'JoinViews':
                    #                    print nuke.views()
                    #                    print nuke.thisView()
                    current_view = nuke.views().index(nuke.thisView())
                    return topInputNode(input_node, current_view, ch_class)
                else:
                    return topInputNode(input_node, ch_class)
        else:
            return None
示例#6
0
def topInputKnob(node, ch_class, knob, input=0):
    if node:
        input_node = node.input(input)
        if input_node:
            if nodeClass(input_node) == ch_class:
                if input_node.knob(knob):
                    return input_node[knob]
            else:
                if nodeClass(input_node) == 'JoinViews':
                    #                    print nuke.views()
                    #                    print nuke.thisView()
                    current_view = nuke.views().index(nuke.thisView())
                    return topInputKnob(input_node, current_view, ch_class,
                                        knob)
                else:
                    return topInputKnob(input_node, ch_class, knob)
        else:
            return None
示例#7
0
def topInput(node, input, ch_class, knob, ch_frame):
    if node:
        input_node = node.input(input)
        if input_node:
            if input_node.Class() == ch_class:
                if input_node.knob(knob):
                    return input_node[knob].getValueAt(ch_frame)
            else:
                if input_node.Class() == 'JoinViews':
                    #                    print nuke.views()
                    #                    print nuke.thisView()
                    current_view = nuke.views().index(nuke.thisView())
                    return topInput(input_node, current_view, ch_class, knob,
                                    ch_frame)
                else:
                    return topInput(input_node, 0, ch_class, knob, ch_frame)
        else:
            return None