G'day,
Just wondering if anyone knows any good ways to mirror character poses for limbs?
I'm just having to manually do it all the time and it feels like there must be a better way.
Any ideas?
Thanks,
Pete
def MirrorObject(InputName): FoundOpposite = False if "L_" in InputName: OpposideSide = InputName.replace("L_","R_") FoundOpposite = True if "R_" in InputName: OpposideSide = InputName.replace("R_","L_") FoundOpposite = True if FoundOpposite == True: #Store the Opposite Side OppositeObj = hou.node(OpposideSide) #Store Current Side thisSide = hou.node(InputName) #Rotations if OppositeObj.parm("rx").isLocked() == False: OppositeObj.parm("rx").set(thisSide.parm("rx").eval()) OppositeObj.parm("ry").set(thisSide.parm("ry").eval()) OppositeObj.parm("rz").set(thisSide.parm("rz").eval()) #Transforms if OppositeObj.parm("tx").isLocked() == False: OppositeObj.parm("tx").set(-thisSide.parm("tx").eval()) OppositeObj.parm("ty").set(thisSide.parm("ty").eval()) OppositeObj.parm("tz").set(thisSide.parm("tz").eval()) #Mirror the selected bones for node in hou.selectedNodes(): path = node.path() MirrorObject(path)
#Store all Currently Selected Objects ValuesToSave = "" for node in hou.selectedNodes(): #Node Path ValuesToSave += node.path()+',' #Rotation ValuesToSave += str(node.parm("rx").eval())+"," ValuesToSave += str(node.parm("ry").eval())+"," ValuesToSave += str(node.parm("rz").eval())+"," #Transform ValuesToSave += str(node.parm("tx").eval())+"," ValuesToSave += str(node.parm("ty").eval())+"," ValuesToSave += str(node.parm("tz").eval())+"\n" #Save to disk SaveFile = hou.hscriptExpression("$JOB")+'TempPose.txt' file = open(SaveFile, "w") file.write(ValuesToSave) file.close()
#Read the transforms from disk and Restore to selected objects StoredFile = open(hou.hscriptExpression("$JOB")+'TempPose.txt',"r") LoadedValues = StoredFile.readlines() for Line in LoadedValues: LineSplit = Line.split(",") TargetItem = hou.node(LineSplit[0]) #Load Rotations try: TargetItem.parm("rx").set( float(LineSplit[1]) ) TargetItem.parm("ry").set(LineSplit[2]) TargetItem.parm("rz").set(LineSplit[3]) except: pass #Load Transforms try: TargetItem.parm("tx").set(LineSplit[4]) TargetItem.parm("ty").set(LineSplit[5]) TargetItem.parm("tz").set(LineSplit[6]) except: pass """the try is there to avoid issues with permissions on some parameters"""
#Read the transforms from disk and Restore to selected objects StoredFile = open(hou.hscriptExpression("$JOB")+'TempPose.txt',"r") LoadedValues = StoredFile.readlines() for Line in LoadedValues: LineSplit = Line.split(",") TargetItem = hou.node(LineSplit[0]) MirrorMultiplier = 1#This is used to flip the rotations in certain cases #Check for opposite side FoundOpposite = False if "L_" in LineSplit[0]: OpposideSide = LineSplit[0].replace("L_","R_") FoundOpposite = True if "R_" in LineSplit[0]: OpposideSide = LineSplit[0].replace("R_","L_") FoundOpposite = True if FoundOpposite == True: #Change the target item if the opposite item was found TargetItem = hou.node(OpposideSide) #If there was no opposide set the mirror multiplyer to mirror this bone if FoundOpposite == False: MirrorMultiplier = -1; #This is a really hacky way of differentiating between objects that should have mirrored rotations... try: TargetItem.parm("tx").set(0.0) MirrorMultiplier = -1; except: pass #Load Rotations try: TargetItem.parm("rx").set(float(LineSplit[1])) TargetItem.parm("ry").set(float(LineSplit[2])*MirrorMultiplier) TargetItem.parm("rz").set(float(LineSplit[3])*MirrorMultiplier) except: pass #Load Transforms try: TargetItem.parm("tx").set(-float(LineSplit[4])) TargetItem.parm("ty").set(LineSplit[5]) TargetItem.parm("tz").set(LineSplit[6]) except: print ("Transform Not Active"); pass