Psyop / Cryptomatte

Cryptomatte Nuke plugin, Fusion plugin, sample images, and specification
BSD 3-Clause "New" or "Revised" License
637 stars 152 forks source link

Layers with partial same names wrongly selected #85

Closed JenusL closed 6 years ago

JenusL commented 6 years ago

I have two Cryptomatte layers, cmNode and cmNodeHierarchy. When i select cmNode in Nuke all of cmNodeHierarchy channels are also selected, resulting in a pure_channels array looking like this: ['cmNode00', 'cmNode01', 'cmNode02', 'cmNodeHierarchy', 'cmNodeHierarchy00', 'cmNodeHierarchy01', 'cmNodeHierarchy02']

This makes sense looking at the code https://github.com/Psyop/Cryptomatte/blob/e5ecd25de087c62bad8fd5c16399e8165bf0041a/nuke/cryptomatte_utilities.py#L231

I propose a change to use regex or something similar. And in that case the whole _identify_channels function could be simplified.

New function:

    def _identify_channels(self, name):
        """from a name like "cryptoObject", 
        gets sorted channels, such as cryptoObject00, cryptoObject01, cryptoObject02
        """

        channel_list = []
        if self.nuke_node.Class() in ["Cryptomatte", "Encryptomatte"]:
            # nuke_node is a keyer gizmo or encryptomatte gizmo
            channel_list = self.nuke_node.node('Input1').channels()
        else:
            # nuke_node might a read node
            channel_list = self.nuke_node.channels()

        channel_regex = re.compile(r'({}\d+)\.red'.format(name))
        pure_channels = []
        for channel in channel_list:
            match = channel_regex.match(channel)
            if match:
                pure_channels.append(match.group(1))

        return sorted(pure_channels)

Maybe other plugins than Nuke is affected by this as well.

JenusL commented 6 years ago

If you think this looks good I can create a PR.

jonahfriedman commented 6 years ago

Looks good to me but I won't be able to review it carefully for about a week. Please do feel free to submit a PR and close this ticket! Thanks a lot.

jonahfriedman commented 6 years ago

Merged in #86.