From 441b3ad2c20d43f7b401571b9ab6490e224c99ff Mon Sep 17 00:00:00 2001 From: Gilles Vink Date: Mon, 10 Oct 2022 21:42:43 +0200 Subject: [PATCH] Implemented filters and made bugfix --- app.py | 14 ++- python/tk_houdini_renderman/handler.py | 129 ++++++++++++++++++++++--- 2 files changed, 126 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 26eab85..8176f0b 100644 --- a/app.py +++ b/app.py @@ -45,15 +45,19 @@ def get_all_renderman_nodes(): lop_nodes = ( hou.lopNodeTypeCategory().nodeType("sgtk_hdprman").instances() ) - nodes = ( - lop_nodes - + hou.ropNodeTypeCategory().nodeType("sgtk_ris").instances() - ) + rop_nodes = hou.ropNodeTypeCategory().nodeType("sgtk_ris").instances() + nodes = lop_nodes + rop_nodes return nodes @staticmethod def get_output_path(node): - output_path = node.parm("picture").eval() + + if node.type().nameComponents()[2] == "sgtk_ris": + parameter = "ri_display_0" + else: + parameter = "picture" + + output_path = node.parm(parameter).eval() return output_path def get_work_template(self): diff --git a/python/tk_houdini_renderman/handler.py b/python/tk_houdini_renderman/handler.py index 58d7553..de5149c 100644 --- a/python/tk_houdini_renderman/handler.py +++ b/python/tk_houdini_renderman/handler.py @@ -46,8 +46,12 @@ def submit_to_farm(self, node, network): # Set filters if network == "lop": - filters = self.__check_filters(node) - self.__set_filter_filename(node, filters) + filters = self.__check_lop_filters(node) + self.__set_lop_filter_filename(node, filters) + + if network == "rop": + filters = self.__check_rop_filters(node) + self.__set_rop_filter_filename(filters, render_node=node) # Determine basic variables for submission file_name = hou.hipFile.name() @@ -89,8 +93,12 @@ def execute_render(self, node, network): # Set filters if network == "lop": - filters = self.__check_filters(node) - self.__set_filter_filename(node, filters) + filters = self.__check_lop_filters(node) + self.__set_lop_filter_filename(node, filters) + + if network == "rop": + filters = self.__check_rop_filters(node) + self.__set_rop_filter_filename(filters, render_node=node) # Execute rendering if network == "lop": @@ -209,7 +217,7 @@ def __calculate_path(self, node, network): return render_path - def __calculate_filter_path(self, node, filter): + def __calculate_filter_path(self, node, filter, render_node=None): # Get all necessary data current_filepath = hou.hipFile.path() work_template = self.app.get_template("work_file_template") @@ -218,10 +226,20 @@ def __calculate_filter_path(self, node, filter): # Set fields fields = work_template.get_fields(current_filepath) fields["SEQ"] = "FORMAT: $F" - fields["name"] = node.parm("name").eval() fields["aov_name"] = filter - fields["width"] = node.parm("resolutionx").eval() - fields["height"] = node.parm("resolutiony").eval() + + if render_node: + fields["name"] = render_node.parm("name").eval() + camera = render_node.parm("camera").eval() + resolution_x = hou.node(camera).parm("resx").eval() + resolution_y = hou.node(camera).parm("resy").eval() + fields["width"] = resolution_x + fields["height"] = resolution_y + + else: + fields["name"] = node.parm("name").eval() + fields["width"] = node.parm("resolutionx").eval() + fields["height"] = node.parm("resolutiony").eval() # Apply fields render_path = render_template.apply_fields(fields).replace(os.sep, "/") @@ -250,7 +268,36 @@ def __create_directory(self, render_path): self.app.logger.debug("Created directory %s." % directory) @staticmethod - def __check_filters(node): + def __check_rop_filters(node): + + # Create list to appends filters to + filters = [] + + # We have two types of filters + filter_types = ["displayfilter", "samplefilter"] + + # Iterate trough filters + for filter_type in filter_types: + + # Get amount of filters for filter type + filter_amount = node.parm("ri_%ss" % filter_type).eval() + + # Iterate trough amount of existing filters + for filter_number in range(0, filter_amount): + + # Create parameter name to search for values + parm_name = "ri_%s%s" % (filter_type, str(filter_number)) + + # Get value of parameter + filter_parameter = node.parm(parm_name).eval() + + # Add to list + filters.append(filter_parameter) + + return filters + + @staticmethod + def __check_lop_filters(node): # Amount of groups in the filter tab in the node tabs = range(0, 5) @@ -282,7 +329,25 @@ def __check_filters(node): # Return return filters - def __set_filter_filename(self, node, filters): + def __set_rop_filter_filename(self, filters, render_node): + # Iterate trough filters + for node in filters: + + # Get node shader network + node = hou.node(node) + + # Get node type + node_type = node.type().nameComponents()[2] + + # Calculate render path + render_path = self.__calculate_filter_path( + node, node_type, render_node=render_node + ) + + # Set render path + node.parm("filename").set(render_path) + + def __set_lop_filter_filename(self, node, filters): # This function will process the filter specfied, and # populate the path if it is possible to do for item in filters: @@ -304,9 +369,43 @@ def __set_filter_filename(self, node, filters): parameter.set(render_path) def get_filters_output(self, node): + + if node.type().nameComponents()[2] == "sgtk_ris": + filter_passes = self.__get_filters_rop_output(node) + + else: + filter_passes = self.__get_filters_lop_output(node) + + return filter_passes + + def __get_filters_rop_output(self, node): + filters = self.__check_rop_filters(node) + filter_passes = [] + for node in filters: + + # Get node shader network + node = hou.node(node) + + # Get node type + node_type = node.nameComponents()[2] + + parameter = node.parm("filename") + + if parameter is None: + continue + + # Build a dictionary per item, containing the name of the + # filter and the path where the file is rendered to + rendered_filter = {"name": node_type, "path": parameter.eval()} + + filter_passes.append(rendered_filter) + + return filters + + def __get_filters_lop_output(self, node): # This function will check every item in the filters group, # and return the file paths that are in there - filters = self.__check_filters(node) + filters = self.__check_lop_filters(node) filter_passes = [] for item in filters: # Look at our dictionary and get the keys/values supplied @@ -345,7 +444,13 @@ def get_published_status(self, node): regex = r"[$][fF]\d" # Get the raw string from the picture parameter - file_path = node.parm("picture").rawValue() + + if node.type().nameComponents()[2] == "sgtk_ris": + parameter = "ri_display_0" + else: + parameter = "picture" + + file_path = node.parm(parameter).rawValue() # Detect "$F4" in the file path, and return it frame_match = re.search(regex, file_path)