-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcam_proj_setup_ui.py
376 lines (319 loc) · 15.4 KB
/
cam_proj_setup_ui.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
"""
V 2.0
PrMan Projection Setup Tool
By Ali Jafargholi - www.alijafargholi.com - [email protected]
The use of this tool is to setup the connection between the projection nodes
in Maya.
Update: Added https://github.com/mottosso/Qt.py to be able to open the tool
within Maya 2017
"""
from Qt import QtWidgets, QtCore
import functools
import pymel.core as pm
# Global variable to store the UI status, if it's open or closed
prman_projection_ui = None
class PrmanProjectionUi(QtWidgets.QDialog):
"""
"""
def __init__(self, parent=None):
super(PrmanProjectionUi, self).__init__(parent)
self.setWindowTitle("Prman Projection Setup")
# Keep the window on top
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
# Setting the size policy
self.setFixedHeight(150)
self.setMinimumWidth(600)
# Setting the MAIN layout
self.setLayout(QtWidgets.QVBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(1)
self.layout().setAlignment(QtCore.Qt.AlignTop)
# Creating the frames
top_frame = QtWidgets.QFrame()
top_frame.setFrameStyle(QtWidgets.QFrame.Panel | QtWidgets.QFrame.Raised)
# Creating Layout for top frame
top_frame_layout = QtWidgets.QVBoxLayout()
top_frame_layout.setContentsMargins(1, 1, 1, 1)
top_frame_layout.setSpacing(1)
top_frame_layout.setAlignment(QtCore.Qt.AlignTop)
top_frame.setLayout(top_frame_layout)
# Creating the UI elements
info_layout = QtWidgets.QGridLayout()
# Projector Node
projector_label = QtWidgets.QLabel('PxrProjector:')
projector_label.setStyleSheet('font-size: 15px;'
'color: #E5FFFF;'
'letter-spacing: 3px;')
self.projector_name = QtWidgets.QLineEdit()
self.projector_name.setMinimumHeight(20)
self.projector_name.setPlaceholderText("Enter the name of the "
"PxrProjector....")
self.projector_name_button = QtWidgets.QPushButton('GET')
self.projector_name_button.setMinimumHeight(20)
self.projector_name_button.setToolTip('Select the '
'<b>PxrProjector</b> node and '
'the hit this button to '
'get the name')
self.new_projector_button = QtWidgets.QPushButton('Create a New PxrProjector')
self.new_projector_button.setStyleSheet("background-color: #004444")
self.new_projector_button.setMinimumHeight(20)
# Camera Projection Node
projection_camera_label = QtWidgets.QLabel('Camera Projection:')
projection_camera_label.setStyleSheet('font-size: 15px;'
'color: #E5FFFF;'
'letter-spacing: 3px;')
self.projection_camera_name = QtWidgets.QLineEdit()
self.projection_camera_name.setMinimumHeight(20)
self.projection_camera_name.setPlaceholderText("Enter name of camera "
"projection....")
self.projection_camera_name_button = QtWidgets.QPushButton('GET')
self.projection_camera_name_button.setMinimumHeight(20)
self.projection_camera_name_button.setToolTip('Select the '
'<b>Projection '
'Camera</b> node and '
'the hit this button '
'to get the name')
self.new_camera_button = QtWidgets.QPushButton('Create a New Camera')
self.new_camera_button.setStyleSheet("background-color: #004444")
self.new_camera_button.setMinimumHeight(20)
# Place3dTexture Node
place3d_label = QtWidgets.QLabel('Place3DTexture:')
place3d_label.setStyleSheet('font-size: 15px;'
'color: #E5FFFF;'
'letter-spacing: 3px;')
self.place3d_name = QtWidgets.QLineEdit()
self.place3d_name.setMinimumHeight(20)
self.place3d_name.setPlaceholderText("Enter the name of the "
"place3dTexture....")
self.place3d_name_button = QtWidgets.QPushButton('GET')
self.place3d_name_button.setMinimumHeight(20)
self.place3d_name_button.setToolTip('Select the '
'<b>place3dTexture</b> '
'node and the hit this '
'button to get the name')
self.new_place3d_button = QtWidgets.QPushButton('Create New Place3dTexture')
self.new_place3d_button.setStyleSheet("background-color: #004444")
self.new_place3d_button.setMinimumHeight(20)
# Node Info Layout
info_layout.addWidget(projector_label, 0, 0)
info_layout.addWidget(self.projector_name, 0, 1)
info_layout.addWidget(self.projector_name_button, 0, 2)
info_layout.addWidget(self.new_projector_button, 0, 3)
info_layout.addWidget(projection_camera_label, 1, 0)
info_layout.addWidget(self.projection_camera_name, 1, 1)
info_layout.addWidget(self.projection_camera_name_button, 1, 2)
info_layout.addWidget(self.new_camera_button, 1, 3)
info_layout.addWidget(place3d_label, 2, 0)
info_layout.addWidget(self.place3d_name, 2, 1)
info_layout.addWidget(self.place3d_name_button, 2, 2)
info_layout.addWidget(self.new_place3d_button, 2, 3)
# Attribute Transfer Mode
self.link_radio_btn = QtWidgets.QRadioButton('Link')
self.link_radio_btn.setChecked(True)
copy_radio_btn = QtWidgets.QRadioButton('Copy')
transfer_attr_mode = QtWidgets.QLabel("Attribute Transfer Mode:")
copy_or_link_layout = QtWidgets.QHBoxLayout()
copy_or_link_layout.setAlignment(QtCore.Qt.AlignLeft)
copy_or_link_layout.addWidget(transfer_attr_mode)
copy_or_link_layout.addWidget(self.link_radio_btn)
copy_or_link_layout.addWidget(copy_radio_btn)
# Execute Button
final_button_layout = QtWidgets.QHBoxLayout()
final_button_layout.setContentsMargins(0, 0, 5, 5)
final_button_layout.setSpacing(5)
final_button_layout.setAlignment(QtCore.Qt.AlignRight)
setup_button = QtWidgets.QPushButton("Set Up Projection")
setup_button.setFixedHeight(30)
setup_button.setFixedWidth(150)
setup_button.setStyleSheet("background-color: #006000")
cancel_button = QtWidgets.QPushButton("Close")
cancel_button.setFixedHeight(30)
cancel_button.setFixedWidth(40)
cancel_button.setStyleSheet("background-color: #CC2900")
final_button_layout.addWidget(setup_button)
final_button_layout.addWidget(cancel_button)
# Adding the elements to the top frame layout
top_frame_layout.addLayout(info_layout)
top_frame_layout.addLayout(copy_or_link_layout)
top_frame_layout.addLayout(final_button_layout)
# Help frame layout
help_frame = QtWidgets.QFrame()
help_frame_layout = QtWidgets.QVBoxLayout()
help_frame_layout.setContentsMargins(1, 1, 1, 1)
help_frame_layout.setSpacing(3)
help_frame_layout.setAlignment(QtCore.Qt.AlignTop)
help_frame.setLayout(help_frame_layout)
# Help elements
help_page = QtWidgets.QPushButton('Visit the Wiki Page')
help_page.setToolTip('SHow the wiki page')
# Adding the help elements to the Help layout
help_frame_layout.addWidget(help_page)
# Main Layout
main_tab = QtWidgets.QTabWidget()
main_tab.addTab(top_frame, "Projection Setup")
main_tab.addTab(help_frame, "Get Help")
# Adding the widgets to the main layout
self.layout().addWidget(main_tab)
# Connecting the functions
self.projector_name_button.clicked.connect(
functools.partial(self._get_selected_name, self.projector_name))
self.projection_camera_name_button.clicked.connect(
functools.partial(self._get_selected_name,
self.projection_camera_name))
self.place3d_name_button.clicked.connect(functools.partial(
self._get_selected_name, self.place3d_name))
setup_button.clicked.connect(self._setup_projection)
cancel_button.clicked.connect(delete_ui)
self.new_projector_button.clicked.connect(
functools.partial(self._create_new_node,
node_type="PxrProjector",
name_field=self.projector_name))
self.new_camera_button.clicked.connect(
functools.partial(self._create_new_node,
node_type="camera",
name_field=self.projection_camera_name))
self.new_place3d_button.clicked.connect(
functools.partial(self._create_new_node,
node_type="place3dTexture",
name_field=self.place3d_name))
help_page.clicked.connect(self._go_to_wiki)
def _go_to_wiki(self):
"""
Opens the browser link and direct it to the help page for this tool
:return: Node
"""
link_page = 'http://alijafargholi.com/2015/11/' \
'prman-camera-projection-setup-for-maya'
# link_page = "https://www.google.com/"
pm.launch(web=link_page)
def _warning(self, message):
"""
Popping up a UI showing the warning message
:param message: string, warning message
:return: QWidget
"""
warning_box = QtWidgets.QMessageBox()
warning_box.setText(message)
warning_box.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
warning_box.exec_()
def _create_new_node(self, node_type="", name_field=""):
"""
Create a new node
:param node_type: 'PxrProjector' or 'Camera' or 'Place3dTexture'
:param name_field: Name of the UI filed to be set with new node's name
:return: None
"""
if node_type == "camera":
new_name = pm.createNode(node_type).getParent().name()
else:
new_name = pm.createNode(node_type)
name_field.setText(str(new_name))
def _get_selected_name(self, name):
"""
Will get the name of the selected node and set it as a text to the
given field
:name: reference of the field that the name is going to be set to
:return: None
"""
try:
name.setText(str(pm.ls(sl=True)[0].name()))
except IndexError:
self._warning(message="It seems no node is selected.\n")
def _setup_projection(self):
"""
Will gather name info from the UI and will set up the connection
between the nodes
"""
# Collecting the name from UI
pxr_projector = self.projector_name.text()
cam_projector = self.projection_camera_name.text()
place3d = self.place3d_name.text()
# Check the existence of the nodes
for node in [pxr_projector, cam_projector, place3d]:
try:
pm.PyNode(node)
except pm.MayaNodeError:
self._warning(message="can't find <strong>{"
"0}</strong> node".format(node))
return
# Getting the camera shape
try:
cam_projector_shape = pm.PyNode(str(cam_projector)).getShape()
except AttributeError as e:
self._warning(message="It seems there has been a problem with "
"getting the camera's shape name.\nPlease "
"make sure a correct name is assigned")
# Check for nodes type
if pm.nodeType(pxr_projector) != "PxrProjector":
self._warning(message="It seems {0} is not a correct "
"node type.\nPlease make sure correct node "
"is selected.\nIt must be PxrProjector node"
"".format(pxr_projector))
return
if pm.nodeType(cam_projector_shape) != "camera":
self._warning(message="It seems {0} is not a correct "
"node type.\nPlease make sure correct node "
"is selected.\n It must be camera's "
"name".format(cam_projector))
return
if pm.nodeType(place3d) != "place3dTexture":
self._warning(message="It seems {0} is not a correct "
"node type.\nPlease make sure correct node "
"is selected.\n It must be "
"place3dTexture".format(place3d))
return
# Accessing the nodes
place3d_node = pm.PyNode(place3d)
cam_projector_node = pm.PyNode(cam_projector)
cam_projector_shape_node = cam_projector_node.getShape()
pxr_projector_node = pm.PyNode(pxr_projector)
# Connecting the attributes
cord_att = '{0}.coordsys'.format(pxr_projector)
pm.setAttr(cord_att, place3d)
if self.link_radio_btn.isChecked():
pm.pointConstraint(cam_projector_node, place3d_node)
pm.orientConstraint(cam_projector_node, place3d_node)
cam_projector_shape_node.focalLength.connect(
pxr_projector_node.focalLength)
cam_projector_shape_node.horizontalFilmAperture.connect(
pxr_projector_node.apertureX)
cam_projector_shape_node.verticalFilmAperture.connect(
pxr_projector_node.apertureY)
cam_projector_shape_node.nearClipPlane.connect(
pxr_projector_node.nearClipPlane)
cam_projector_shape_node.farClipPlane.connect(
pxr_projector_node.farClipPlane)
else:
pxr_projector_node.focalLength.set(
cam_projector_shape_node.focalLength.get())
pxr_projector_node.apertureX.set(
cam_projector_shape_node.horizontalFilmAperture.get())
pxr_projector_node.apertureY.set(
cam_projector_shape_node.verticalFilmAperture.get())
pxr_projector_node.nearClipPlane.set(
cam_projector_shape_node.nearClipPlane.get())
pxr_projector_node.farClipPlane.set(
cam_projector_shape_node.farClipPlane.get())
place3d_node.setTranslation(cam_projector_node.getTranslation(
space='world'), space='world')
place3d_node.setRotation(cam_projector_node.getRotation(
space='world'), space='world')
def create_ui():
"""
Create a instance of the PrmanProjectionUi and shows the window
:return: QDialog
"""
global prman_projection_ui
if prman_projection_ui is None:
prman_projection_ui = PrmanProjectionUi()
prman_projection_ui.show()
def delete_ui():
"""
If the UI exists in memory, delete it.
:return: None
"""
global prman_projection_ui
if prman_projection_ui is None:
return
prman_projection_ui.deleteLater()
prman_projection_ui = None