forked from HumanArk/hafarm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Clarisse.py
152 lines (123 loc) · 6.05 KB
/
Clarisse.py
1
2
3
4
5
6
7
8
9
10
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Standards:
import os, sys
# Custom:
from uuid import uuid4
import utils
from HaGraph import HaGraph
from HaGraph import HaGraphItem
from hafarm import GraphvizRender
from hafarm import SlurmRender
# Host specific:
import ix
class ClarisseWrapper(HaGraphItem):
def __init__(self, clarisse_image, render_archive, *args, **kwargs):
index, name = str(uuid4()), 'clarisse'
tags, path = '/clarisse/farm', ''
dependencies = []
super(ClarisseWrapper, self).__init__(index, dependencies, name, path, tags, *args, **kwargs)
# Note: Force non-default version of backend support class.
self.parms['command'] << { 'command': '$CLARISSE_HOME/crender' }
# NOTE: SCENE_FILE has to be first in a row
self.parms['req_license'] = 'clarisse_lic=1'
self.parms['req_resources'] = ''
self.parms['job_on_hold'] = False
self.parms['queue'] = '3d'
self.parms['group'] = ''
#NOTE We render single frame per task, so double 'start_frame' isn't a bug.
self.parms['frame_range_arg'] = ["-start_frame %s -end_frame %s", 'start_frame', 'start_frame']
self.parms['pre_render_script'] = 'clarisse_temp_dir=`mktemp -d --tmpdir=/tmp`; \
export CLARISSE_TEMP_DIR=$clarisse_temp_dir;\n echo Making Clarisse own tmp place in $clarisse_temp_dir '
self.parms['post_render_script'] = 'echo Deleting Clarisse tmp: $clarisse_temp_dir; rm -rf $CLARISSE_TEMP_DIR;'
command = self.parms['command_arg']
self.parms['target_list'] = [clarisse_image.get_full_name()]
self.parms['priority'] = 0
self.parms['job_on_hold'] = False
# Scene file.
# command += ['@SCENE_FILE/>']
self.parms['scene_file'] = render_archive
# Add camera option to commanline:
camera = self.parms['target_list']
self.parms['command_arg'] = ['@SCENE_FILE/>'
, '-startup_script'
, '$HAFARM_HOME/scripts/clarisse/123.py'
, ' -image %s ' % camera[0] ]
# target image to render:
picture_path = clarisse_image.m_object.get_attribute("save_as").get_string()
format_idx = int(clarisse_image.m_object.get_attribute("format").get_double())
self.parms['output_picture'] = picture_path + "00001" + CLARISSE_FORMATS[format_idx]
# name, frame range per Clarisse image:
_, job_name = os.path.split(render_archive)
self.parms['job_name'] = self.generate_unique_job_name(job_name) + "_" + clarisse_image.get_name()
self.parms['start_frame'] = int(clarisse_image.m_object.get_attribute("first_frame").get_string())
self.parms['end_frame'] = int(clarisse_image.m_object.get_attribute("last_frame").get_string())
# Get rid of frames = 0
if self.parms['start_frame'] < 1:
self.parms['start_frame'] = 1
"""
================== THIS IS TEMPORARY HAFARM GUI for NON-PyQt environment. ==========================
"""
CLARISSE_FORMATS = ('.exr', '.exr', ".jpg", ".bmp", ".tga", ".png", ".png", ".tiff", ".tiff", ".tiff")
class RenderButton(ix.api.GuiPushButton):
def __init__(self, parent, x, y, w, h, label):
ix.api.GuiPushButton.__init__(self, parent, x, y, w, h, label)
self.connect(self, 'EVT_ID_PUSH_BUTTON_CLICK', self.on_click)
self.parent = parent
def on_click(self, sender, evtid):
'''Runs per selected iamge in Clarisse GUI.
'''
render_archive = self.parent.parms['render_archive']
selected_images = self.parent.parms['selected_images']
graph = HaGraph()
graph.set_render(SlurmRender.SlurmRender)
for image in selected_images:
graph.add_node( ClarisseWrapper( image, str(render_archive) ) )
graph.render()
self.set_label('Render sent!')
def hafarm_run():
"""To be called by shelf button in Clarisse.
"""
# If archive is not there, quit:
render_archive = ix.api.GuiWidget_open_file(ix.application)
if not render_archive or not os.path.isfile(render_archive):
sys.exit()
# Windows and its labeling.
window = ix.api.GuiWindow(ix.application, 5, 0, 320, 280)
label = ix.api.GuiLabel(window, 5, 5, 320, 40, "Clarisse Hafarm manager.")
label.set_justification(ix.api.GuiWidget.JUSTIFY_CENTER)
# TODO: This isn't used atm
label2 = ix.api.GuiLabel(window, 5, 10, 320, 70, "Host groups:")
groups = ix.api.GuiListView(window, 5, 60, 100, 60)
for group in ('old_intel', 'new_intel', 'grafika', 'render'):
groups.add_item(str(group))
# The list of selected images
selected_images = []
for item in ix.selection:
if item.is_kindof("Image"):
selected_images.append(item)
# The list of Clarisse imagaes to be rendered one by one on a farm (these will be separeted jobs)
label3 = ix.api.GuiLabel(window, 5, 110, 320, 60, "Clarisse images:")
images = ix.api.GuiLineEdit(window, 5,150, 320, 20, " ". join([x.get_name() for x in selected_images]))
# Get frame range
frame_range = ix.application.get_current_frame_range()
start_frame = int(frame_range[0])
end_frame = int(frame_range[1])
# Get rid of 0 frame...
if start_frame < 1: start_frame = 1
# Set frameranges
startFrameLabel = ix.api.GuiLabel(window, 200, 60, 80, 20, "Start Frame:")
startFrameLineEdit = ix.api.GuiLineEdit(window, 280, 60, 40, 20)
startFrameLineEdit.set_text(str(start_frame))
endFrameLabel = ix.api.GuiLabel(window, 200, 80, 80, 20, "End Frame:")
endFrameLineEdit = ix.api.GuiLineEdit(window, 280, 80, 40, 20)
endFrameLineEdit.set_text(str(end_frame))
# Render me button
renderButton = RenderButton(window, 5, 250, 128, 22, "Render")
# FIXME: In proper class this wouldn't be here...
window.parms = {}
window.parms['selected_images'] = selected_images
window.parms['render_archive'] = render_archive
window.parms['start_frame'] = start_frame
window.parms['end_frame'] = end_frame
# show time...
window.show()
while window.is_shown(): ix.application.check_for_events()