Skip to content

Commit

Permalink
Merge pull request #4 from nfa-vfxim/feature/issue-1/update-to-render…
Browse files Browse the repository at this point in the history
…man-25

Further bugfixes for RenderMan 25 update
  • Loading branch information
mervinvb committed Oct 23, 2023
2 parents 970d30d + 4905380 commit 2b6e7a1
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 11 deletions.
8 changes: 8 additions & 0 deletions app.py
Expand Up @@ -124,6 +124,14 @@ def get_output_paths(self, node: hou.Node) -> list[str]:
"""
return self.handler.get_output_paths(node)

def get_output_range(self, node: hou.Node) -> list[int]:
"""Get output frame range for the RenderMan node
Args:
node (hou.Node): RenderMan node
"""
return self.handler.get_output_range(node)

def get_work_template(self) -> str:
"""Get work file template from ShotGrid"""
return self.get_template("work_file_template")
Expand Down
4 changes: 4 additions & 0 deletions info.yml
Expand Up @@ -43,6 +43,10 @@ configuration:
expression: { type: str }
group: { type: str, allows_empty: True }

post_task_script:
type: str
description: The external path to the post task script

# general info about this app
display_name: "RenderMan Render Node"
description: "A ShotGrid Toolkit app to render in Houdini with the RenderMan 25 render engine and Deadline."
Expand Down
12 changes: 12 additions & 0 deletions python/tk_houdini_renderman/farm_dialog.py
Expand Up @@ -133,6 +133,13 @@ def __submit_to_farm(self):
framerange = self.framerange.text()
frames_per_task = int(self.frames_per_task_line.text())

if frames_per_task < 1:
hou.ui.displayMessage(
"Submission canceled because frames per task is set below 1.",
severity=hou.severityType.ImportantMessage,
)
return

if self.smartframes.isChecked():
framerange = get_smart_frame_list(framerange, frames_per_task)

Expand Down Expand Up @@ -161,6 +168,8 @@ def __submit_to_farm(self):

deadline_path = os.getenv("DEADLINE_PATH")

post_task_script = self.app.get_setting("post_task_script")

# Building job info properties
job_info = [
"Plugin=Houdini",
Expand All @@ -173,6 +182,9 @@ def __submit_to_farm(self):
"EnvironmentKeyValue0 = RENDER_ENGINE = RenderMan",
]

if post_task_script:
job_info.append("PostTaskScript=" + post_task_script)

for i, path in enumerate(self.render_paths):
output_directory = os.path.dirname(path)
job_info.append("OutputDirectory{}={}".format(i, output_directory))
Expand Down
30 changes: 19 additions & 11 deletions python/tk_houdini_renderman/handler.py
Expand Up @@ -56,15 +56,8 @@ def submit_to_farm(self, node: hou.Node, network: str):
file_name = os.path.basename(file_name).split(".")[0] + " (%s)" % render_name

# Determine framerange
framerange_type = node.parm("trange").eval()
if framerange_type > 0:
start_frame = int(node.parm("f1").eval())
end_frame = int(node.parm("f2").eval())
framerange = str(start_frame) + "-" + str(end_frame)
else:
current_frame = int(hou.frame())
framerange = str(current_frame) + "-" + str(current_frame)
# TODO add increment parameter
framerange = self.get_output_range(node)
framerange = f"{framerange[0]}-{framerange[1]}"

# Open node so it will work on the farm
# even if the node is not installed
Expand Down Expand Up @@ -545,6 +538,8 @@ def get_output_path(self, node: hou.Node, aov_name: str, network="rop") -> str:
aov_name (str): AOV name
network (str): Network type
"""
aov_name = aov_name[0].lower() + aov_name[1:]

current_filepath = hou.hipFile.path()

work_template = self.app.get_template("work_file_template")
Expand Down Expand Up @@ -625,7 +620,7 @@ def get_output_paths(self, node: hou.Node) -> list[str]:
if node.evalParm("aovBeauty"):
paths.append(self.get_output_path(node, "beauty"))
if len(shading):
paths.append(self.get_output_path(node, "beauty"))
paths.append(self.get_output_path(node, "shading"))
if len(lighting) or len(lightgroups):
paths.append(self.get_output_path(node, "lighting"))
if len(utility) or node.evalParm("tees"):
Expand All @@ -640,13 +635,26 @@ def get_output_paths(self, node: hou.Node) -> list[str]:

# Denoise
if node.evalParm("denoise"):
paths.append(os.path.dirname(self.get_output_path(node, "denoise")))
paths.append(self.get_output_path(node, "denoise"))

# Statistiscs
paths.append(self.get_output_path(node, "stats")[:-3] + "xml")

return paths

def get_output_range(self, node: hou.Node) -> list[int]:
framerange_type = node.parm("trange").eval()
if framerange_type > 0:
start_frame = int(node.parm("f1").eval())
end_frame = int(node.parm("f2").eval())
framerange = [start_frame, end_frame]
else:
current_frame = int(hou.frame())
framerange = [current_frame, current_frame]
# TODO add increment parameter

return framerange

def __create_directory(self, render_path: str):
"""Create directory to render to
Expand Down
43 changes: 43 additions & 0 deletions python/tk_houdini_renderman/post_task_script.py
@@ -0,0 +1,43 @@
import os.path

from Deadline.Scripting import *


def __main__(*args):
deadline_plugin = args[0]

job = deadline_plugin.GetJob()
task = deadline_plugin.GetCurrentTask()

output_directories = job.OutputDirectories
output_filenames = job.OutputFileNames

for i in range(0, len(output_directories)):
output_directory = output_directories[i]
output_filename = output_filenames[i]

if not output_directory.endswith("denoise"):
continue

start_frame = task.GetStartFrame()
end_frame = task.GetEndFrame()

for frame_num in range(start_frame, end_frame + 1):
output_filename = output_filename.replace("%04d", f"{frame_num:04}")
from_path = os.path.join(
output_directory, output_filename.replace("_denoise_", "_beauty_")
)
to_path = os.path.join(output_directory, output_filename)

if os.path.exists(from_path):
if not os.path.exists(to_path):
os.rename(from_path, to_path)
deadline_plugin.LogInfo(f"Renamed denoised frame {frame_num}")
else:
deadline_plugin.LogWarning(
f"Renamed denoise frame {frame_num} already found: {to_path}"
)
else:
deadline_plugin.FailRender(
f"Can't find frame {frame_num} to denoise: {from_path}"
)

0 comments on commit 2b6e7a1

Please sign in to comment.