Skip to content

collect_vray_rop

CollectVrayROPRenderProducts

Bases: HoudiniInstancePlugin

Collect Vray Render Products

Collects the instance.data["files"] for the render products.

Provides

instance -> files

Source code in client/ayon_houdini/plugins/publish/collect_vray_rop.py
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class CollectVrayROPRenderProducts(plugin.HoudiniInstancePlugin):
    """Collect Vray Render Products

    Collects the instance.data["files"] for the render products.

    Provides:
        instance    -> files

    """

    label = "VRay ROP Render Products"
    # This specific order value is used so that
    # this plugin runs after CollectFrames
    order = pyblish.api.CollectorOrder + 0.11
    families = ["vray_rop"]

    def process(self, instance):

        rop = hou.node(instance.data.get("instance_node"))

        default_prefix = evalParmNoFrame(rop, "SettingsOutput_img_file_path")
        render_products = []
        # TODO: add render elements if render element

        export_prefix = None
        export_products = []
        if instance.data["splitRender"]:
            export_prefix = evalParmNoFrame(
                rop, "render_export_filepath", pad_character="0"
            )
            beauty_export_product = self.get_render_product_name(
                prefix=export_prefix,
                suffix=None)
            export_products.append(beauty_export_product)
            self.log.debug(
                "Found export product: {}".format(beauty_export_product)
            )
            instance.data["ifdFile"] = beauty_export_product
            instance.data["exportFiles"] = list(export_products)

        beauty_product = self.get_render_product_name(default_prefix)
        render_products.append(beauty_product)
        files_by_aov = {
            "": self.generate_expected_files(instance,
                                                      beauty_product)}

        # Assume it's a multipartExr Render.
        multipartExr = True

        if instance.data.get("RenderElement", True):
            render_element = self.get_render_element_name(rop, default_prefix)
            if render_element:
                for aov, renderpass in render_element.items():
                    render_products.append(renderpass)
                    files_by_aov[aov] = self.generate_expected_files(
                        instance, renderpass)
                    # Set to False as soon as we have a separated aov.
                    multipartExr = False

        # Review Logic expects this key to exist and be True
        # if render is a multipart Exr.
        # As long as we have one AOV then multipartExr should be True.
        instance.data["multipartExr"] = multipartExr

        for product in render_products:
            self.log.debug("Found render product: %s" % product)
        filenames = list(render_products)
        instance.data["files"] = filenames

        # For now by default do NOT try to publish the rendered output
        instance.data["publishJobState"] = "Suspended"
        instance.data["attachTo"] = []      # stub required data

        if "expectedFiles" not in instance.data:
            instance.data["expectedFiles"] = list()
        instance.data["expectedFiles"].append(files_by_aov)
        self.log.debug("expectedFiles:{}".format(files_by_aov))

    def get_render_product_name(self, prefix, suffix="<reName>"):
        """Return the beauty output filename if render element enabled
        """
        # Remove aov suffix from the product: `prefix.aov_suffix` -> `prefix`
        aov_parm = ".{}".format(suffix)
        return prefix.replace(aov_parm, "")

    def get_render_element_name(self, node, prefix, suffix="<reName>"):
        """Return the output filename using the AOV prefix and suffix
        """
        render_element_dict = {}
        # need a rewrite
        re_path = node.evalParm("render_network_render_channels")
        if re_path:
            node_children = hou.node(re_path).children()
            for element in node_children:
                if element.shaderName() != "vray:SettingsRenderChannels":
                    aov = str(element)
                    render_product = prefix.replace(suffix, aov)
                    render_element_dict[aov] = render_product
        return render_element_dict

    def generate_expected_files(self, instance, path):
        """Create expected files in instance data"""

        dir = os.path.dirname(path)
        file = os.path.basename(path)

        if "#" in file:
            def replace(match):
                return "%0{}d".format(len(match.group()))

            file = re.sub("#+", replace, file)

        if "%" not in file:
            return path

        expected_files = []
        start = instance.data["frameStartHandle"]
        end = instance.data["frameEndHandle"]

        for i in range(int(start), (int(end) + 1)):
            expected_files.append(
                os.path.join(dir, (file % i)).replace("\\", "/"))

        return expected_files

generate_expected_files(instance, path)

Create expected files in instance data

Source code in client/ayon_houdini/plugins/publish/collect_vray_rop.py
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
def generate_expected_files(self, instance, path):
    """Create expected files in instance data"""

    dir = os.path.dirname(path)
    file = os.path.basename(path)

    if "#" in file:
        def replace(match):
            return "%0{}d".format(len(match.group()))

        file = re.sub("#+", replace, file)

    if "%" not in file:
        return path

    expected_files = []
    start = instance.data["frameStartHandle"]
    end = instance.data["frameEndHandle"]

    for i in range(int(start), (int(end) + 1)):
        expected_files.append(
            os.path.join(dir, (file % i)).replace("\\", "/"))

    return expected_files

get_render_element_name(node, prefix, suffix='<reName>')

Return the output filename using the AOV prefix and suffix

Source code in client/ayon_houdini/plugins/publish/collect_vray_rop.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def get_render_element_name(self, node, prefix, suffix="<reName>"):
    """Return the output filename using the AOV prefix and suffix
    """
    render_element_dict = {}
    # need a rewrite
    re_path = node.evalParm("render_network_render_channels")
    if re_path:
        node_children = hou.node(re_path).children()
        for element in node_children:
            if element.shaderName() != "vray:SettingsRenderChannels":
                aov = str(element)
                render_product = prefix.replace(suffix, aov)
                render_element_dict[aov] = render_product
    return render_element_dict

get_render_product_name(prefix, suffix='<reName>')

Return the beauty output filename if render element enabled

Source code in client/ayon_houdini/plugins/publish/collect_vray_rop.py
89
90
91
92
93
94
def get_render_product_name(self, prefix, suffix="<reName>"):
    """Return the beauty output filename if render element enabled
    """
    # Remove aov suffix from the product: `prefix.aov_suffix` -> `prefix`
    aov_parm = ".{}".format(suffix)
    return prefix.replace(aov_parm, "")