I am working on a script that will create a duplicate curve mirrored across an axis (currently limited to x). I have successfully duplicated and mirrored the curve in such a way that the cvs reverse order and the shape of the curve itself is mirrored.
However, I haven’t been able to figure out how to mirror the pivots, so that the mirrored curve’s pivot point is on the part of the curve that it is in its counterpart. Without modification, the mirrored pivots remain in the same place as the original pivots. For the time being, I’ve merely centered the pivots on the mirrored curve.
How might I mirror the pivots properly?
I also understand that the way I am mirroring the curve isn’t strictly correct; technically the transform of the curveShape itself doesn’t change. But, I think I’ll be fine as long as I remember to freezeTransforms on my curves I intend to mirror. Am I wrong in thinking this? What problems might occur later when doing it this way? Is there a better way to go about this?
The following is my current code:
import pymel.core as pm
def mirrorCurves( selected ):
for nCurve in selected:
nCurve = nCurve.getShape()
if not isinstance( nCurve, pm.nodetypes.NurbsCurve ):
pm.error( nCurve + ' is Type: ' + type( nCurve ).__name__ + '. Not the required Type: '+pm.nodetypes.NurbsCurve.__name__ )
mirroredCurve = pm.duplicate( nCurve )[0]
newCVs = []
newPivots = []
for cv in mirroredCurve.getCVs():
cv.x = cv.x * -1 #Reverse sign to flip across axis
newCVs.append( cv )
'''
for pivot in mirroredCurve.getPivots():
pivot.x = pm.datatypes.Distance( pivot.x * -1 )
newPivots.append( pivot )
'''
mirroredCurve.setCVs( newCVs )
#mirroredCurve.setPivots( newPivots )
mirroredCurve.updateCurve()
selected = pm.selected()
mirrorCurves( selected )
I’ve left my last attempt at mirroring the pivots commented out (and removed the centerPivots() call on the mirrored curve). With the pivot assignment, I get an error:
Invalid arguments for flag ‘pivots’. Expected ( distance, distance, distance ), got ( ( float, float, float ), ( float, float, float ) )
Finally, is there a better way to get/set the axis values on the cvs/pivots. I’d like to write this so I can specify mirroing across x, y, z or even combination but without some ugly if else block or switch or something. Preferably some manner of reflection that allows me to dynamically select the axis attribute I’m getting and setting.
Thanks! 