@@ -133,24 +133,62 @@ def create_reprojection_on_camera(cam_tfm, cam_shp):
133133 return node
134134
135135
136- def find_reprojection_nodes ( cam_tfm , cam_shp ):
136+ def _find_auxiliary_set_nodes ( point_from_set_node ):
137137 """
138138 Find all the reprojection nodes on the camera.
139139 """
140- nodes = (
140+ nodes = []
141+
142+ object_set_nodes = (
141143 maya .cmds .listConnections (
142- cam_shp + '.focalLength ' ,
143- source = False ,
144- destination = True ,
145- type = 'mmReprojection ' ,
144+ point_from_set_node + '.set ' ,
145+ source = True ,
146+ destination = False ,
147+ type = 'objectSet ' ,
146148 exactType = True ,
147149 skipConversionNodes = True ,
148150 )
149151 or []
150152 )
151- if not nodes :
152- return nodes
153- reprojection_node = nodes [0 ]
153+ nodes += object_set_nodes
154+
155+ # transform_plugs = (
156+ # maya.cmds.listConnections(
157+ # point_from_set_node + '.matrix',
158+ # source=True,
159+ # destination=False,
160+ # plugs=True,
161+ # type='transform',
162+ # exactType=False,
163+ # skipConversionNodes=True,
164+ # )
165+ # or []
166+ # )
167+ # # nodes += transform_nodes
168+
169+ # mesh_plugs = (
170+ # maya.cmds.listConnections(
171+ # point_from_set_node + '.mesh',
172+ # source=True,
173+ # destination=False,
174+ # plugs=True,
175+ # type='mesh',
176+ # exactType=True,
177+ # skipConversionNodes=True,
178+ # )
179+ # or []
180+ # )
181+ # # nodes += mesh_nodes
182+
183+ return nodes
184+
185+
186+ def _find_auxiliary_reprojection_nodes (reprojection_node ):
187+ """
188+ Find all the reprojection nodes on the camera.
189+ """
190+ nodes = []
191+
154192 # Get connected MultiplyDivide nodes connected.
155193 mult_nodes = (
156194 maya .cmds .listConnections (
@@ -165,6 +203,7 @@ def find_reprojection_nodes(cam_tfm, cam_shp):
165203 or []
166204 )
167205 nodes += mult_nodes
206+
168207 # Get connected offset PlusMinusAverage nodes.
169208 offset_plusminus_nodes = (
170209 maya .cmds .listConnections (
@@ -178,6 +217,58 @@ def find_reprojection_nodes(cam_tfm, cam_shp):
178217 or []
179218 )
180219 nodes += offset_plusminus_nodes
220+
221+ # Get connected mmPointFromObjectSet nodes.
222+ point_from_set_nodes = (
223+ maya .cmds .listConnections (
224+ reprojection_node + '.transformWorldMatrix' ,
225+ source = True ,
226+ destination = False ,
227+ type = 'mmPointFromObjectSet' ,
228+ exactType = True ,
229+ skipConversionNodes = True ,
230+ )
231+ or []
232+ )
233+ nodes += point_from_set_nodes
234+
235+ return nodes
236+
237+
238+ def _find_object_set_nodes (reproj_node ):
239+ reproj_aux_nodes = _find_auxiliary_reprojection_nodes (reproj_node )
240+ point_from_set_nodes = [
241+ x for x in reproj_aux_nodes if maya .cmds .nodeType (x ) == 'mmPointFromObjectSet'
242+ ]
243+ set_nodes = []
244+ for point_from_set_node in point_from_set_nodes :
245+ set_nodes += _find_auxiliary_set_nodes (point_from_set_node )
246+
247+ return list (sorted (set (set_nodes + point_from_set_nodes )))
248+
249+
250+ def find_reprojection_nodes (cam_tfm , cam_shp ):
251+ """
252+ Find all the reprojection nodes on the camera.
253+ """
254+ nodes = (
255+ maya .cmds .listConnections (
256+ cam_shp + '.focalLength' ,
257+ source = False ,
258+ destination = True ,
259+ type = 'mmReprojection' ,
260+ exactType = True ,
261+ skipConversionNodes = True ,
262+ )
263+ or []
264+ )
265+ if not nodes :
266+ return nodes
267+ reprojection_node = nodes [0 ]
268+
269+ # Get the other nodes.
270+ nodes += _find_auxiliary_reprojection_nodes (reprojection_node )
271+ nodes += _find_object_set_nodes (reprojection_node )
181272 return nodes
182273
183274
@@ -215,17 +306,70 @@ def reset_pan_zoom(cam_tfm, cam_shp):
215306 return
216307
217308
218- def connect_transform_to_reprojection (tfm , reproj ):
309+ def _cleanup_object_set_nodes (reproj_node ):
310+ old_nodes = _find_object_set_nodes (reproj_node )
311+ if len (old_nodes ) > 0 :
312+ maya .cmds .delete (old_nodes )
313+ return len (old_nodes )
314+
315+
316+ def connect_transform_to_reprojection (tfm , reproj_node ):
219317 """
220- Connect 'tfm' to the reprojection node, 'reproj '.
318+ Connect 'tfm' to the reprojection node, 'reproj_node '.
221319
222320 :param tfm: Transform node name to be connected.
223321 :type tfm: str
224322
225- :param reproj : The re-projection node.
226- :type reproj : str
323+ :param reproj_node : The re-projection node.
324+ :type reproj_node : str
227325 """
326+ _cleanup_object_set_nodes (reproj_node )
327+
228328 src = tfm + '.worldMatrix'
229- dst = reproj + '.transformWorldMatrix'
230- maya .cmds .connectAttr (src , dst )
329+ dst = reproj_node + '.transformWorldMatrix'
330+ maya .cmds .connectAttr (src , dst , force = True )
331+ return
332+
333+
334+ def connect_objects_to_reprojection (objects , reproj_node ):
335+ """
336+ Connect all the objects and components in 'objects' to the
337+ reprojection node, 'reproj_node'.
338+
339+ :param objects:
340+ :type objects: str
341+
342+ :param reproj_node: The re-projection node.
343+ :type reproj_node: str
344+
345+ """
346+ _cleanup_object_set_nodes (reproj_node )
347+
348+ point_from_set_node = maya .cmds .createNode ('mmPointFromObjectSet' )
349+ set_node = maya .cmds .sets (objects , name = reproj_node + '_center_objectSet' )
350+ maya .cmds .connectAttr (
351+ set_node + '.message' , point_from_set_node + '.set' , force = True
352+ )
353+
354+ nodes = maya .cmds .ls (objects , objectsOnly = True , long = True )
355+ for i , node in enumerate (nodes ):
356+ if not node .startswith ('|' ):
357+ # Only DAG objects can be connected.
358+ continue
359+
360+ # Both shapes and transforms should always contain a
361+ # worldMatrix attribute.
362+ src = node + '.worldMatrix[0]'
363+ dst = point_from_set_node + '.matrix[{}]' .format (i )
364+ maya .cmds .connectAttr (src , dst , force = True )
365+
366+ node_type = maya .cmds .nodeType (node )
367+ if node_type == 'mesh' :
368+ src = node + '.worldMesh[0]'
369+ dst = point_from_set_node + '.mesh[{}]' .format (i )
370+ maya .cmds .connectAttr (src , dst , force = True )
371+
372+ src = point_from_set_node + '.outMatrix'
373+ dst = reproj_node + '.transformWorldMatrix'
374+ maya .cmds .connectAttr (src , dst , force = True )
231375 return
0 commit comments