def setup_VisibilityGRP(self): visGrp = adbAttr.NodeAttr([self.RIG.VISIBILITY_GRP]) visGrp.AddSeparator(self.RIG.VISIBILITY_GRP, 'Joints') visGrp.addAttr( '{Side}_{Basename}_Clavicule_JNT'.format(**self.nameStructure), True) visGrp.addAttr('{Side}_{Basename}_IK_JNT'.format(**self.nameStructure), False) visGrp.AddSeparator(self.RIG.VISIBILITY_GRP, 'Controls') visGrp.addAttr( '{Side}_{Basename}_Clavicule_CTRL'.format(**self.nameStructure), True) for attr in visGrp.allAttrs.keys(): for module in self.BUILD_MODULES: for grp in module.VISRULE_GRP.getChildren(): shortName = NC.getBasename(grp).split( '{Basename}_'.format(**self.nameStructure))[-1] if shortName.lower() in attr.lower(): try: pm.connectAttr( '{}.{}'.format(visGrp.subject, attr), '{}.vis'.format(grp)) except: pass
def mirror(self, axis='X'): """ Mirror a transform according to given axis. """ for subject in self.transform: # get the name if (pm.PyNode(subject).name()).startswith('r__'): _name = '{}'.format(str(subject).replace('r__', 'l__')) elif (pm.PyNode(subject).name()).startswith('l__'): _name = '{}'.format( str(pm.PyNode(subject)).replace('l__', 'r__')) else: _name = None # temp unlock all user defined attributes locks_attr_list = adbAttr.NodeAttr(self.transform).getLock_attr() # Unlock all att_to_unlock = [ 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'v' ] for att in att_to_unlock: pm.PyNode(subject).setAttr(att, lock=False, keyable=True) # mirror function dup = pm.duplicate(subject, rr=True, name=_name)[0] offset_grp = pm.group(name='dup_grp', em=True) pm.makeIdentity(dup, n=0, s=1, r=1, t=1, apply=True, pn=1) pm.parent(dup, offset_grp) if axis == 'x': pm.PyNode(offset_grp).scaleX.set(-1) elif axis == 'y': pm.PyNode(offset_grp).scaleY.set(-1) elif axis == 'z': pm.PyNode(offset_grp).scaleZ.set(-1) elif axis == 'X': pm.PyNode(offset_grp).scaleX.set(-1) elif axis == 'Y': pm.PyNode(offset_grp).scaleY.set(-1) elif axis == 'Z': pm.PyNode(offset_grp).scaleZ.set(-1) pm.parent(dup, world=True) pm.makeIdentity(dup, n=0, s=1, r=1, t=1, apply=True, pn=1) pm.delete(offset_grp) # relock attribute for attrs in locks_attr_list: if attrs: for att in attrs: pm.PyNode(subject).setAttr(att, lock=True, channelBox=True, keyable=False) pm.PyNode(dup).setAttr(att, lock=True, channelBox=True, keyable=False)
def createVariableFkSystem(self): """ Create an Fk Variable system based on a Bend Attribute Returns: Module - Class object of the FkVariable Class """ resultOffset_grp = [ adb.makeroot_func(subject=x, suff='OFFSET', forceNameConvention=True) for x in self.spine_chain_joints ] settingsGrpAttr = adbAttr.NodeAttr([self.RIG.SETTINGS_GRP]) settingsGrpAttr.addAttr('Bend', 0) fkV = Slide.FkVariable(module_name='Bend', joint_chain=self.spine_chain_joints, driver=[self.RIG.SETTINGS_GRP], range=2, driver_axis='Bend', target_axis='rx', useMinus=False) fkV.start() fkV.build() pm.parent(fkV.metaData_GRP, self.RIG.SETTINGS_GRP) return fkV
def createNetworkNode(self, _metaDataNode): spaceAttrNode = moduleBase.ModuleBase.createMetaDataGrp('{}_attribute'.format(self.NAME), type ='transform') spaceAttr = adbAttr.NodeAttr(spaceAttrNode) spaceAttr.addAttr(self.NAME, 'enum', eName = str(':'.join(self.attrNames))) pm.PyNode('{}.{}'.format(spaceAttrNode , spaceAttr.attrName)) >> self.choiceNode.selector return spaceAttrNode
def setup_SettingGRP(self): setting_ctrl = adbAttr.NodeAttr([self.RIG.SETTINGS_GRP]) setting_ctrl.AddSeparator([self.RIG.SETTINGS_GRP], 'VolumePreservation') adbAttr.NodeAttr.copyAttr( self.spine_squash_stretch.metaData_GRP, [self.RIG.SETTINGS_GRP], nicename='{Side}_{Basename}'.format(**self.nameStructure), forceConnection=True)
def createSticky(stickyName = 'Deformer', scale = 0.2): """ Sticky : Creates a rivet with a softmod deformer Returns the sticky locator """ rivetData = buildRivet() rivet_trans = rivetData[0] curveFromMeshEdgeList = rivetData[1] MeshName = rivetData[2] pm.PyNode(rivet_trans).v.set(0) ## master and offset grp deformer__sys__ = pm.createNode('transform', n = '{}_{}__{}'.format(stickyName, NC.SYSTEM, NC.GRP)) deformer_offset_grp__ = pm.createNode('transform', n = '{}__offset__{}'.format(stickyName, NC.GRP)) pm.parent(deformer_offset_grp__, deformer__sys__) ## create locator sticky_locator = pm.spaceLocator(name = '{}_sticky'.format(MeshName)) adb.changeColor_func(sticky_locator, 'index', col = 18) pm.PyNode(sticky_locator).localScaleX.set(scale) pm.PyNode(sticky_locator).localScaleY.set(scale) pm.PyNode(sticky_locator).localScaleZ.set(scale) pm.parent(sticky_locator, deformer_offset_grp__) pm.matchTransform(deformer_offset_grp__, rivet_trans.getParent(), rot = True, pos=True) ## create softmod softModName = '{}__softMod__'.format(stickyName) softModDeformer = pm.softMod(MeshName,n=softModName) pm.softMod(softModDeformer[0], edit = True, wn=(sticky_locator,sticky_locator), fas=False, fm=False ) pm.PyNode('{}HandleShape'.format(softModDeformer[0])).v.set(0) ## connect falloff Center adb.connect_axesAttr(deformer_offset_grp__, softModDeformer[0], outputs = ['translate'], inputs = ['falloffCenter']) deformer_offset_grp__.inverseMatrix >> softModDeformer[0].bindPreMatrix _sticky_Attr = adbAttr.NodeAttr([sticky_locator]) _sticky_Attr.addAttr('Softmod_Falloff_Radius', 0.75, min = 0, max = 100 ) sticky_locator.Softmod_Falloff_Radius >> softModDeformer[0].falloffRadius ##giving new input geo to curveFromMeshEdges groupPartsNodeName = pm.listConnections(softModName, t='groupParts') for index in range(len(curveFromMeshEdgeList)): pm.PyNode('{}GroupParts.outputGeometry'.format(softModName)) >> curveFromMeshEdgeList[index].inputMesh adb.connect_axesAttr(rivet_trans.getParent(), deformer_offset_grp__, outputs = ['translate', 'rotate'], inputs = []) ## clean scene pm.delete(softModDeformer[1]) pm.parent(rivet_trans.getParent(),deformer__sys__) pm.select(clear=True) sys.stdout.write('// Result: Sticky created // \n ') return sticky_locator
def wrapSetUp(_HiRez = pm.selected(), _LoRez=pm.selected()): """ Custom wrapDeformer Setup Select target - HiRez first, then the source - LoRez The script will create a duplicate of the HiRez with a blenshape and add a DeltaMush on the HiRez @param Hirez: Target which will receive the wrap @param Lorez: Source ## EXTERIOR CLASS BUILD #------------------------ import adb_utils.Script__WrapDeformer_Setup as adbWrapSetUp reload(adbWrapSetUp) #or from adb_utils.Script__WrapDeformer_Setup import wrapSetUp """ ## Define Variable type if isinstance(_HiRez, str) and isinstance(_LoRez, str): hi = _HiRez lo = _LoRez elif len(_HiRez) == 2: hi = _HiRez[0] lo = _LoRez[1] dup = pm.duplicate(hi, n='{}__{}__'.format(hi,'duplicate_wrap'), ic=1, rr=1)[0] wrapData = adbWrap.wrapDeformer(str(dup),str(lo)) ## add custom attribute on wrap node wrap_node = adbAttr.NodeAttr([wrapData]) wrap_node.addAttr('mushEnveloppe', 1) wrap_node.addAttr('smoothingIterations', 10) wrap_node.addAttr('smoothingStep', 0.5) ## blendShape blendShape = pm.blendShape(dup, hi, exclusive="deformPartition#", o = "world", w = [(0, 1.0)], ib=1, n = '{}__{}__'.format(hi, 'BLS'))[0] ## Mush mush = pm.deltaMush(hi, smoothingIterations=10, envelope=1, smoothingStep=0.5, pinBorderVertices=1, n = '{}_{}'.format(hi, 'mush')) pm.PyNode(wrapData).mushEnveloppe >> pm.PyNode(mush).envelope pm.PyNode(wrapData).smoothingIterations >> pm.PyNode(mush).smoothingIterations pm.PyNode(wrapData).smoothingStep >> pm.PyNode(mush).smoothingStep ## Clean Up pm.PyNode(dup).v.set(0)
def setupVisRule(self, tansformList, parent, name=False, defaultValue=True): """ Edit : for setting up the visrule for Fk shapes ctrl Original one from ModuleBase """ if name: visRuleGrp = pm.group(n=name, em=1, parent=parent) else: visRuleGrp = pm.group(n='{}_{}__{}'.format( NC.getNameNoSuffix(tansformList[0]), NC.getSuffix(tansformList[0]), NC.VISRULE), em=1, parent=parent) visRuleGrp.v.set(0) visRuleAttr = adbAttr.NodeAttr([visRuleGrp]) visRuleAttr.addAttr('vis', 'enum', eName="2:0") self.nameStructure['Suffix'] = NC.ADDLINEAR_SUFFIX addDouble = pm.shadingNode( 'addDoubleLinear', asUtility=1, n='{Side}__{Basename}_visrule__{Suffix}'.format( **self.nameStructure)) self.nameStructure['Suffix'] = NC.REVERSE_SUFFIX reverse = pm.shadingNode( 'reverse', asUtility=1, n='{Side}__{Basename}_visrule__{Suffix}'.format( **self.nameStructure)) addDouble.input2.set(1) pm.connectAttr('{}.{}'.format(visRuleGrp, visRuleAttr.name), '{}.inputX'.format(reverse), f=1) pm.connectAttr('{}.outputX'.format(reverse), '{}.input1'.format(addDouble), f=1) for transform in tansformList: pm.connectAttr('{}.output'.format(addDouble), '{}.drawStyle'.format(transform)) adb.lockAttr_func( visRuleGrp, ['tx', 'ty', 'tz', 'rx', 'ry', 'rx', 'rz', 'sx', 'sy', 'sz', 'v']) return visRuleGrp, visRuleAttr.name
def setup_VisibilityGRP(self): visGrp = adbAttr.NodeAttr([self.RIG.VISIBILITY_GRP]) visGrp.AddSeparator(self.RIG.VISIBILITY_GRP, 'Joints') visGrp.addAttr('{Side}_{Basename}_FK_JNT'.format(**self.nameStructure), self.config['VISRULES']['FK_Reg_JNT']) visGrp.addAttr( '{Side}_{Basename}_FK_Reverse_JNT'.format(**self.nameStructure), self.config['VISRULES']['FK_Rev_JNT']) visGrp.addAttr('{Side}_{Basename}_IK_JNT'.format(**self.nameStructure), self.config['VISRULES']['IK_JNT']) visGrp.addAttr( '{Side}_{Basename}_MACRO_JNT'.format(**self.nameStructure), self.config['VISRULES']['Macro_JNT']) visGrp.AddSeparator(self.RIG.VISIBILITY_GRP, 'Controls') visGrp.addAttr( '{Side}_{Basename}_FK_CTRL'.format(**self.nameStructure), self.config['VISRULES']['FK_Reg_CTRL']) visGrp.addAttr( '{Side}_{Basename}_FK_Reverse_CTRL'.format(**self.nameStructure), self.config['VISRULES']['FK_Rev_CTRL']) visGrp.addAttr( '{Side}_{Basename}_IK_CTRL'.format(**self.nameStructure), self.config['VISRULES']['IK_CTRL']) visGrp.addAttr( '{Side}_{Basename}_CHEST_CTRL'.format(**self.nameStructure), self.config['VISRULES']['Chest_CTRL']) visGrp.addAttr( '{Side}_{Basename}_HIPS_CTRL'.format(**self.nameStructure), self.config['VISRULES']['Hips_CTRL']) for attr in visGrp.allAttrs.keys(): for module in self.BUILD_MODULES: for grp in module.VISRULE_GRP.getChildren(): shortName = NC.getBasename(grp).split( '{Basename}_'.format(**self.nameStructure))[-1] if shortName.lower() in attr.lower(): try: pm.connectAttr( '{}.{}'.format(visGrp.subject, attr), '{}.vis'.format(grp)) except: pass
def setupVisRule(tansformList, parent, name=False, defaultValue=True): """ setup VisRule group for a tansform. Connect the tansform visibility to the visRule group Arguments: tansform {List} -- Control to connect parent {transform} -- parent of the VisRule group """ if name: visRuleGrp = pm.group(n=name, em=1, parent=parent) else: visRuleGrp = pm.group(n='{}_{}__{}'.format(NC.getNameNoSuffix(tansformList[0]), NC.getSuffix(tansformList[0]), NC.VISRULE), em=1, parent=parent) visRuleGrp.v.set(0) visRuleAttr = adbAttr.NodeAttr([visRuleGrp]) visRuleAttr.addAttr('vis', defaultValue) for transform in tansformList: pm.connectAttr('{}.{}'.format(visRuleGrp, visRuleAttr.name), '{}.v'.format(transform)) adb.lockAttr_func(visRuleGrp, ['tx', 'ty', 'tz', 'rx', 'ry', 'rx', 'rz', 'sx', 'sy', 'sz','v']) return visRuleGrp, visRuleAttr.name
def setup_SpaceGRP(self, transform, Ik_FK_attributeName=[]): switch_ctrl = adbAttr.NodeAttr([transform]) for name in Ik_FK_attributeName: switch_ctrl.addAttr(name, 'enum', eName="IK:FK:") return Ik_FK_attributeName
def footGroupSetup(self): ## Create Attributes footAttr = adbAttr.NodeAttr([self.Foot_MOD.metaData_GRP]) footAttr.addAttr('heelRoll', 0) footAttr.addAttr('heelSide', 0) footAttr.addAttr('heelTwist', 0) footAttr.addAttr('ballRoll', 0) footAttr.addAttr('toeRoll', 0) footAttr.addAttr('toeSide', 0) footAttr.addAttr('toeBend', 0) @changeColor('index', 2) def createJoints(): points = [ pm.PyNode(guide).getRotatePivot(space='world') for guide in self.starter_Foot ] self.foot_chain = Joint.Joint.point_base( *points, name='{Side}__{Basename}'.format(**self.nameStructure), chain=True, padding=2) self.footAnkle_joint, self.footBall_joint, self.footToes_joint, self.footHeel_joint, = self.foot_chain.joints # Parenting the joints pm.parent(self.footHeel_joint, self.footAnkle_joint) pm.PyNode(self.footAnkle_joint).rename( '{Side}__{Basename}_{Parts[0]}_END'.format( **self.nameStructure)) pm.PyNode(self.footBall_joint).rename( '{Side}__{Basename}_{Parts[1]}_END'.format( **self.nameStructure)) pm.PyNode(self.footToes_joint).rename( '{Side}__{Basename}_{Parts[2]}_END'.format( **self.nameStructure)) pm.PyNode(self.footHeel_joint).rename( '{Side}__{Basename}_{Parts[3]}_END'.format( **self.nameStructure)) adb.AutoSuffix(self.foot_chain.joints) pm.parent(self.footAnkle_joint, self.Foot_MOD.OUTPUT_GRP) self.footOffsetGrp = self.createPivotGrps( self.footAnkle_joint, name='{Basename}_Offset'.format(**self.nameStructure)) ## orient joint if self.side == NC.RIGTH_SIDE_PREFIX: mirror_chain_1 = pm.mirrorJoint(self.footAnkle_joint, mirrorYZ=1) mirror_chain_3 = pm.mirrorJoint(mirror_chain_1[0], mirrorBehavior=1, mirrorYZ=1) pm.delete(self.footAnkle_joint, mirror_chain_1) self.foot_chain = Joint.Joint(mirror_chain_3) self.footAnkle_joint, self.footBall_joint, self.footToes_joint, self.footHeel_joint = self.foot_chain.joints pm.PyNode(self.footAnkle_joint).rename( '{Side}__{Basename}_{Parts[0]}_END'.format( **self.nameStructure)) pm.PyNode(self.footBall_joint).rename( '{Side}__{Basename}_{Parts[1]}_END'.format( **self.nameStructure)) pm.PyNode(self.footToes_joint).rename( '{Side}__{Basename}_{Parts[2]}_END'.format( **self.nameStructure)) pm.PyNode(self.footHeel_joint).rename( '{Side}__{Basename}_{Parts[3]}_END'.format( **self.nameStructure)) adb.AutoSuffix(self.foot_chain.joints) pm.makeIdentity(self.footOffsetGrp.getChildren(), n=0, t=1, apply=True, pn=1) adb.makeroot_func(self.footOffsetGrp, suff='Output', forceNameConvention=1) Transform(self.footOffsetGrp).pivotPoint = Transform( self.footAnkle_joint).worldTrans self.foot_chain.radius = 1.0 self.nameStructure['Suffix'] = NC.VISRULE moduleBase.ModuleBase.setupVisRule( [self.footAnkle_joint], self.Foot_MOD.VISRULE_GRP, '{Side}__{Basename}_JNT__{Suffix}'.format( **self.nameStructure), True) return self.foot_chain.joints # ============ # Build # ============ createJoints()
def autoClavicule( self, arm_ik_joints=[], poleVector_ctl=[], arm_ik_offset_ctrl=[], ): self.AUTO_CLAVICULE_MOD = moduleBase.ModuleBase() self.AUTO_CLAVICULE_MOD._start( '{Side}__AutoClavicule'.format(**self.nameStructure), _metaDataNode='transform') self.BUILD_MODULES += [self.AUTO_CLAVICULE_MOD] pm.parent(self.AUTO_CLAVICULE_MOD.metaData_GRP, self.RIG.SETTINGS_GRP) pm.parent(self.AUTO_CLAVICULE_MOD.MOD_GRP, self.RIG.MODULES_GRP) autoClaviculeGrp = adbAttr.NodeAttr( [self.AUTO_CLAVICULE_MOD.metaData_GRP]) autoClaviculeGrp.addAttr('Toggle', True) autoClaviculeGrp.addAttr('RemapNode', 'message') def ik_chain_duplicate(): self.ik_AutoShoulder_joint = [ pm.duplicate(joint, parentOnly=True)[0] for joint in arm_ik_joints ] pm.parent(self.ik_AutoShoulder_joint[-1], self.ik_AutoShoulder_joint[-2]) pm.parent(self.ik_AutoShoulder_joint[-2], self.ik_AutoShoulder_joint[0]) pm.PyNode(self.ik_AutoShoulder_joint[0]).rename( '{Side}__Auto{Basename}_Ik_Shoulder'.format( **self.nameStructure)) pm.PyNode(self.ik_AutoShoulder_joint[1]).rename( '{Side}__Auto{Basename}_Ik_Elbow'.format(**self.nameStructure)) pm.PyNode(self.ik_AutoShoulder_joint[2]).rename( '{Side}__Auto{Basename}_Ik_Wrist'.format(**self.nameStructure)) adb.AutoSuffix(self.ik_AutoShoulder_joint) self.nameStructure['Suffix'] = NC.IKHANDLE_SUFFIX autoShoulder_IkHandle, autoShoulder_IkHandle_effector = pm.ikHandle( n='{Side}__Auto{Basename}__{Suffix}'.format( **self.nameStructure), sj=self.ik_AutoShoulder_joint[0], ee=self.ik_AutoShoulder_joint[-1]) autoShoulder_IkHandle.v.set(0) self.autoShoulder_IkHandle = autoShoulder_IkHandle adb.makeroot_func(self.autoShoulder_IkHandle) pm.poleVectorConstraint(poleVector_ctl, autoShoulder_IkHandle, weight=1) self.AUTO_CLAVICULE_MOD.setFinalHiearchy( RIG_GRP_LIST=[self.autoShoulder_IkHandle.getParent()], OUTPUT_GRP_LIST=[self.ik_AutoShoulder_joint[0]]) adb.matrixConstraint(arm_ik_offset_ctrl, self.autoShoulder_IkHandle.getParent()) pm.parent(self.AUTO_CLAVICULE_MOD.MOD_GRP, self.RIG.MODULES_GRP) self.nameStructure['Suffix'] = NC.VISRULE moduleBase.ModuleBase.setupVisRule( [self.ik_AutoShoulder_joint[0]], self.AUTO_CLAVICULE_MOD.VISRULE_GRP, name='{Side}__{Basename}_IK_JNT__{Suffix}'.format( **self.nameStructure), defaultValue=False) def claviculeSetup(): autoShoulder_grp = adb.makeroot_func(self.clavicule_ctrl, suff='AutoClavicule', forceNameConvention=True) self.nameStructure['Suffix'] = NC.MULTIPLY_DIVIDE_SUFFIX autoShoulder_toggle = pm.shadingNode( 'multiplyDivide', au=True, n='{Side}__Auto{Basename}_toggle__{Suffix}'.format( **self.nameStructure)) self.nameStructure['Suffix'] = NC.REMAP_COLOR_SUFFIX autoShoulder_remapNode = pm.shadingNode( 'remapColor', au=True, n='{Side}__Auto{Basename}__{Suffix}'.format( **self.nameStructure)) autoShoulder_remapNode.outColorR >> self.AUTO_CLAVICULE_MOD.metaData_GRP.RemapNode if self.side == 'L': autoShoulder_remapNode.inputMin.set(-90) autoShoulder_remapNode.inputMax.set(90) autoShoulder_remapNode.outputMin.set(-45) autoShoulder_remapNode.outputMax.set(45) elif self.side == 'R': autoShoulder_remapNode.inputMin.set(90) autoShoulder_remapNode.inputMax.set(-90) autoShoulder_remapNode.outputMin.set(-45) autoShoulder_remapNode.outputMax.set(45) for color in AUTO_CLAVICULE_CONFIG.keys(): for points in AUTO_CLAVICULE_CONFIG[color].keys(): pm.PyNode('{}.{}[{}].{}_Interp'.format( autoShoulder_remapNode, color, str(points), color)).set(3) pm.PyNode('{}.{}[{}].{}_Position'.format( autoShoulder_remapNode, color, str(points), color)).set(AUTO_CLAVICULE_CONFIG[color][points][0]) pm.PyNode('{}.{}[{}].{}_FloatValue'.format( autoShoulder_remapNode, color, str(points), color)).set(AUTO_CLAVICULE_CONFIG[color][points][1]) ## Connection claviculePoseReader = PoseReader.poseReader( name='{Side}__Clavicule'.format(**self.nameStructure), driver=self.AUTO_CLAVICULE_MOD.OUTPUT_GRP, target=self.ik_AutoShoulder_joint[0], upPostion=(0, 10, 0), targetPosition=(10, 0, 0), )[0] claviculePoseReader[0].rx >> autoShoulder_toggle.input1X claviculePoseReader[0].ry >> autoShoulder_toggle.input1Y claviculePoseReader[0].rz >> autoShoulder_toggle.input1Z autoShoulder_toggle.outputX >> autoShoulder_remapNode.colorR autoShoulder_toggle.outputY >> autoShoulder_remapNode.colorG autoShoulder_toggle.outputZ >> autoShoulder_remapNode.colorB autoShoulder_remapNode.outColorR >> autoShoulder_grp.rx autoShoulder_remapNode.outColorG >> autoShoulder_grp.ry autoShoulder_remapNode.outColorB >> autoShoulder_grp.rz self.AUTO_CLAVICULE_MOD.metaData_GRP.Toggle >> autoShoulder_toggle.input2X self.AUTO_CLAVICULE_MOD.metaData_GRP.Toggle >> autoShoulder_toggle.input2Y self.AUTO_CLAVICULE_MOD.metaData_GRP.Toggle >> autoShoulder_toggle.input2Z # ============================ # BUILD # ============================ ik_chain_duplicate() claviculeSetup()
def poseReader(name = '', driver='joint1__CTRL', target = 'joint2__CTRL', upPostion = (0,10,0), targetPosition = (10,0,0), twistPosition = (0,0,10), twist=False): """ Create a Pose Reader import adb_library.adb_utils.Script__PoseReader as PoseReader PoseReader.PoseReader() """ poseReaderGrp = pm.createNode('transform', name='{}_PoseReader__{}'.format(name, NC.GRP)) pm.matchTransform(poseReaderGrp, driver, pos=True, rot=False) mainPoseReader = Locator.Locator.create(name='{}_tempPoseReader__{}'.format(name, NC.LOC)) mainPoseReaderOutput = Locator.Locator.create(name='{}_MainPoseReader__{}'.format(name, NC.LOC)) upPoseReader = Locator.Locator.create(name='{}_UpPoseReader__{}'.format(name, NC.LOC)) targetPoseReader = Locator.Locator.create(name='{}_TargetPoseReader__{}'.format(name, NC.LOC)) poseReaderLocs = [mainPoseReader.locators, upPoseReader.locators, targetPoseReader.locators, mainPoseReaderOutput.locators] [pm.matchTransform(loc, target, pos=True, rot=False) for loc in poseReaderLocs] [pm.parent(loc, poseReaderGrp) for loc in poseReaderLocs] targetGrp = adb.makeroot_func(targetPoseReader.locators) pm.move(upPoseReader.locators[0], upPostion, r=1, os=1, wd=1) pm.move(targetPoseReader.locators[0], targetPosition, r=1, os=1, wd=1) pm.aimConstraint(targetPoseReader.locators[0], mainPoseReader.locators[0], weight=1, upVector=tuple(dt.Vector(upPostion).normal()), worldUpObject=upPoseReader.locators[0], worldUpType="object", offset=(0, 0, 0), aimVector=tuple(dt.Vector(targetPosition).normal())) pm.parent(poseReaderGrp, driver) adb.matrixConstraint(target, targetGrp) # add double Function adb.makeroot_func(mainPoseReader.locators) adb.makeroot_func(upPoseReader.locators) mainPoseReader.locators[0].tx.set(targetPosition[0]*-1) upPoseReader.locators[0].tx.set(targetPosition[0]*-1) mult = pm.shadingNode('multiplyDivide', asUtility=1, n='{}_PR_double__{}'.format(name, NC.MULTIPLY_DIVIDE_SUFFIX)) mult.input2X.set(2) mult.input2Y.set(2) mult.input2Z.set(2) mainPoseReader.locators[0].rx >> mult.input1X mainPoseReader.locators[0].ry >> mult.input1Y mainPoseReader.locators[0].rz >> mult.input1Z mult.outputX >> mainPoseReaderOutput.locators[0].rx mult.outputY >> mainPoseReaderOutput.locators[0].ry mult.outputZ >> mainPoseReaderOutput.locators[0].rz ## add Twist if twist: twistPoseReaderGrp = pm.createNode('transform', name='{}_TwistPoseReader__{}'.format(name, NC.GRP)) pm.matchTransform(twistPoseReaderGrp, driver, pos=True, rot=False) twistMainPoseReader = Locator.Locator.create(name='{}_TwistMainPoseReader__{}'.format(name, NC.LOC)) twistTargetPoseReader = Locator.Locator.create(name='{}_TwistTargetPoseReader__{}'.format(name, NC.LOC)) twistUpPoseReader = Locator.Locator.create(name='{}_TwistUpPoseReader__{}'.format(name, NC.LOC)) twistPoseReaderLocs = [twistMainPoseReader.locators, twistUpPoseReader.locators, twistTargetPoseReader.locators] [pm.parent(loc, twistPoseReaderGrp) for loc in twistPoseReaderLocs] pm.parent(twistPoseReaderGrp, poseReaderGrp) [pm.matchTransform(loc, target, pos=True, rot=False) for loc in twistPoseReaderLocs] pm.move(twistUpPoseReader.locators[0], targetPosition, r=1, os=1, wd=1) pm.move(twistTargetPoseReader.locators[0], twistPosition, r=1, os=1, wd=1) pm.aimConstraint(twistTargetPoseReader.locators[0], twistMainPoseReader.locators[0], weight=1, upVector=tuple(dt.Vector(targetPosition).normal()), worldUpObject=twistUpPoseReader.locators[0], worldUpType="object", offset=(0, 0, 0), aimVector=tuple(dt.Vector(twistPosition).normal())) pm.parent(twistTargetPoseReader.locators[0], targetGrp) mult.outputY >> twistPoseReaderGrp.ry mult.outputZ >> twistPoseReaderGrp.rz ## add Extra Attributes mainLocAttr = adbAttr.NodeAttr(mainPoseReaderOutput.locators) mainLocAttr.addAttr('bend', 0) mainLocAttr.addAttr('twist', 0) mainLocAttr.addAttr('bendSide', 0) if twist: twistMainPoseReader.locators[0].rx >>mainPoseReaderOutput.locators[0].twist mainPoseReaderOutput.locators[0].ry >> mainPoseReaderOutput.locators[0].bendSide mainPoseReaderOutput.locators[0].rz >>mainPoseReaderOutput.locators[0].bend poseReaderGrp.v.set(0) return mainPoseReaderOutput.locators, upPoseReader.locators, targetPoseReader.locators # poseReader()
def follicule_rivet( references_obj, target_mesh, visibility=True, ): """ Method that creates a follicule rivet on the target mesh base on the position of the reference object # NOTES: UV must be done on the target mesh in order to work properly @param obj : (list) list of objects that is used as reference to get the closest point on the surface @param target_mesh : (str) name of the transform of the mesh. @param visibility : (bool) visibility of the locators Returns: (list) Follicules, follicule_locs """ follicule_sys = adbFolli.Folli(1, len(references_obj), radius=0.5, sub=target_mesh) follicule_joint = follicule_sys.getJoints follicule_shape = follicule_sys.getFollicules follicules = [x.getParent() for x in follicule_shape] follicule_locs = [] ## Set u_v values u_v_values = [ Transform.get_closest_u_v_point_on_mesh(obj, target_mesh) for obj in references_obj ] for uv_values, joint in zip(u_v_values, follicule_joint): joint.u_param.set(uv_values[0] * 100) joint.v_param.set(uv_values[1] * 100) ## Replace follicules_joints by a locators for fol_jnt, fol in zip(follicule_joint, follicules): foll_loc = pm.spaceLocator() follicule_locs.append(foll_loc) pm.rename(foll_loc, fol_jnt.replace('jnt', 'loc')) pm.matchTransform(foll_loc, fol, pos=True, rot=True) pm.parent(foll_loc, fol_jnt.getParent()) follicule_loc_attr = adbAttr.NodeAttr([foll_loc]) follicule_loc_attr.addAttr('U_Param', fol_jnt.u_param.get(), min=-100, max=100) follicule_loc_attr.addAttr('V_Param', fol_jnt.v_param.get(), min=-100, max=100) foll_loc.U_Param >> fol.u_param foll_loc.V_Param >> fol.v_param ## Clean up pm.delete(fol_jnt) [x.v.set(0) for x in follicule_shape] ## Hide the red follicule [x.v.set(visibility) for x in follicule_locs] return follicules, follicule_locs
def buildRivet(scale = 0.2): """ Creates a Rivet Between 2 edges Returns : - Rivet locator, - List of the 2 edge from curves nodes - Mesh Name """ if not (pm.pluginInfo('matrixNodes', q=True, loaded=True)): pm.loadPlugin( 'matrixNodes' ) _edges = pm.filterExpand(selectionMask = 32) ## Edge if len(_edges) < 2: pm.warning('n\Need 2 edges selected') elif len(_edges) > 2: pm.error('Too much edges selected! Only select 2!!') else: objectFromEdge = _edges[0].split('.')[0] edgeMaxNumber = pm.polyEvaluate(objectFromEdge, edge = True) objectShape = pm.PyNode(objectFromEdge).getShape() edgeCount = len(_edges) edgeNumber = [(edge.split('.e[')[1]).split(']')[0] for edge in _edges] ## RIVET LOC AND GRP SET UP rivet_grp= pm.group(em=True, name = '{}_rivet__grp__'.format(objectFromEdge)) rivet_locator = pm.spaceLocator(name = '{}_rivet'.format(objectFromEdge)) adb.changeColor_func(rivet_locator, 'index', col = 17) pm.PyNode(rivet_locator).localScaleX.set(scale) pm.PyNode(rivet_locator).localScaleY.set(scale) pm.PyNode(rivet_locator).localScaleZ.set(scale) pm.parent(rivet_locator, rivet_grp) _rivet_Attr = adbAttr.NodeAttr([rivet_locator]) _rivet_Attr.addAttr("edges_index", 'float2', nc=2) _rivet_Attr.addAttr("edge_index_0", int(edgeNumber[0]), min = 0, max = edgeMaxNumber, parent = "edges_index") _rivet_Attr.addAttr("edge_index_1", int(edgeNumber[1]), min = 0, max = edgeMaxNumber, parent = "edges_index") print _rivet_Attr _rivet_Attr.addAttr("UV", 'float2', nc=2) _rivet_Attr.addAttr("U_pos", 0.5, min = 0, max = 1, parent = "UV") _rivet_Attr.addAttr("V_pos", 0.5, min = 0, max = 1, parent = "UV") ## NODES CREATION curveFromEdge_nodes = [pm.createNode('curveFromMeshEdge', name = 'curveFromEdge_{}_{}'.format(objectFromEdge, x)) for x in edgeNumber] loft_node = pm.createNode('loft', name = 'rivet_loft__node__') pm.PyNode(loft_node).degree.set(1) pointOnSurface_node = pm.createNode('pointOnSurfaceInfo', name = 'pointOnSurface_node') pm.PyNode(pointOnSurface_node).turnOnPercentage.set(1) matrix_node = pm.createNode('fourByFourMatrix', name = 'mat__node__') decomposeMatrix_node = pm.createNode('decomposeMatrix', name = 'decompMat__node__') ## MAKING THE CONNECTIONS objectShape.worldMesh >> pm.PyNode(curveFromEdge_nodes[0]).inputMesh objectShape.worldMesh >> pm.PyNode(curveFromEdge_nodes[1]).inputMesh for index in range(0, edgeCount): pm.PyNode('{}.{}'.format(curveFromEdge_nodes[index], 'outputCurve')) >> pm.PyNode('{}.inputCurve[{}]'.format(loft_node, index)) loft_node.outputSurface >> pointOnSurface_node.inputSurface rivet_locator.U_pos >> pointOnSurface_node.parameterU rivet_locator.V_pos >> pointOnSurface_node.parameterV pos_node_attr = ['normal', 'tangentU.tangentU', 'tangentV.tangentV', 'position.position'] xyz = 'XYZ' for i in range(len(pos_node_attr)): for j in range(3): axe = xyz[j] if 'tU' in pos_node_attr[i]: axe = axe.lower() elif 'tV' in pos_node_attr[i]: axe = axe.lower() pm.PyNode('{}.{}{}'.format(pointOnSurface_node, pos_node_attr[i], axe)) >> pm.PyNode('{}.in{}{}'.format(matrix_node, i, j)) matrix_node.output >> decomposeMatrix_node.inputMatrix for i in range(3): axe = xyz[i] pm.PyNode('{}.outputRotate{}'.format(decomposeMatrix_node, axe)) >> pm.PyNode('{}.rotate{}'.format(rivet_grp, axe)) pm.PyNode('{}.outputTranslate{}'.format(decomposeMatrix_node, axe)) >> pm.PyNode('{}.translate{}'.format(rivet_grp, axe)) rivet_locator.edge_index_0 >> curveFromEdge_nodes[0].edgeIndex[0] rivet_locator.edge_index_1 >> curveFromEdge_nodes[1].edgeIndex[0] sys.stdout.write('// Result: Rivet created! // \n') return rivet_locator, curveFromEdge_nodes, objectFromEdge
def setup_SettingGRP(self): setting_ctrl = adbAttr.NodeAttr([self.RIG.SETTINGS_GRP]) adbAttr.NodeAttr.copyAttr( self.AUTO_CLAVICULE_MOD.metaData_GRP, [self.RIG.SETTINGS_GRP], nicename='{Side}_AutoClavicule'.format(**self.nameStructure), forceConnection=True)
pm.skinCluster(folli_proxy, bind_joints) adbWrap.wrapDeformer(ik_spline_curve, ik_curve_proxy) wrap_ik_spline = adbWrap.wrapDeformer(geo, ik_spline_proxy) wrap_folli = adbWrap.wrapDeformer(geo, folli_proxy) wrap_ik_spline.rename('x__ik_spline__wrap__') wrap_folli.rename('x__follicule__wrap__') ## Swith set up rv_ik_spline = pm.shadingNode('remapValue', asUtility=1, n='ik_spline__rv__') rev_ik_spline = pm.shadingNode('reverse', asUtility=1, n='ik_spline__rv__') rv_ik_spline.inputMin.set(1) rv_ik_spline.inputMax.set(10) ## add the swith attribute ik_blend_ctrl = adbAttr.NodeAttr([attribute_ctrl]) ik_blend_ctrl.addAttr('IK_blend', 1, min=1, max=10) ParamBlend = pm.PyNode(attribute_ctrl).name() + ".IK_blend" pm.PyNode(ParamBlend) >> pm.PyNode(rv_ik_spline).inputValue pm.PyNode(rv_ik_spline).outValue >> pm.PyNode(wrap_folli).envelope pm.PyNode(rv_ik_spline).outValue >> pm.PyNode(rev_ik_spline).inputX pm.PyNode(rev_ik_spline).outputX >> pm.PyNode(wrap_ik_spline).envelope ## Clean up pm.PyNode(ik_spline_curve).v.set(False)
def wrapDeformer(_HiRez=pm.selected(), _LoRez=pm.selected()): """ Custom wrapDeformer Select target - HiRez first, then the source - LoRez @param Hirez: Target which will receive the wrap : str or selection @param Lorez: Source : str of selection ## EXTERIOR CLASS BUILD #------------------------ import adb_utils.Script__WrapDeformer as adbWrap reload(adbWrap) #or from adb_utils.Script__WrapDeformer import wrapDeformer """ ## Define Variable type if isinstance(_HiRez, str) and isinstance(_LoRez, str): print('a') HiRez = _HiRez LoRez = _LoRez elif len(_HiRez) == 2: print('b') HiRez = _HiRez[0] LoRez = _LoRez[1] else: print('c') HiRez = _HiRez LoRez = _LoRez ## get Orig node orig_node = adb.getShapeOrig(LoRez) if orig_node == None: cls = pm.cluster(LoRez) pm.delete(cls) orig_node = adb.getShapeOrig(LoRez) # raise RuntimeError("No 'Orig' Node for: {}".format(LoRez)) ## Wrap Node creation pm.select(HiRez, r=True) pm.select(LoRez, add=True) wrapData = pm.deformer(HiRez, name='{}_{}'.format(HiRez, 'wrap'), type='wrap')[0] pm.PyNode(wrapData).maxDistance.set(1) pm.PyNode(wrapData).autoWeightThreshold.set(1) pm.PyNode(wrapData).exclusiveBind.set(0) pm.PyNode(wrapData).falloffMode.set(0) ## add custom attribute on LoRez mesh if adb.attrExist(LoRez, 'dropoff'): pass else: LoRez_node = adbAttr.NodeAttr([LoRez]) LoRez_node.addAttr('dropoff', 4) LoRez_node.addAttr('smoothness', 0) LoRez_node.addAttr('inflType', 2) ## Connections (pm.PyNode(LoRez).getShape() ).worldMesh[0] >> pm.PyNode(wrapData).driverPoints[0] (pm.PyNode(HiRez).getShape() ).worldMatrix[0] >> pm.PyNode(wrapData).geomMatrix pm.PyNode(LoRez).dropoff >> pm.PyNode(wrapData).dropoff[0] pm.PyNode(LoRez).inflType >> pm.PyNode(wrapData).inflType[0] pm.PyNode(LoRez).smoothness >> pm.PyNode(wrapData).smoothness[0] pm.PyNode(orig_node).worldMesh[0] >> pm.PyNode(wrapData).basePoints[0] ## Clean Up) pm.PyNode(LoRez).v.set(0) sys.stdout.write('custom wrap deformer created \n') return wrapData # wrapDeformer()
def ik_fk_switch( ctrl_name='', blend_attribute='', result_joints=[], ik_joints=[], fk_joints=[], lenght_blend=1, ): """ Function to create an Ik - Fk rotation based script @param ctrl_name : (str) Name of the control having the switch attribute @param blend_attribute : (sr) Name of blend attribute @param result_joints : (list) List of result joints @param ik_joints : (list) List of ik joints @param fk_joints : (list) List of fk joints example: ik_fk_switch(ctrl_name = 'locator1', blend_attribute = 'ik_fk_switch', result_joints = ['result_01', 'result_02', 'result_03'], ik_joints = ['ik_01', 'ik_02', 'ik_03'], fk_joints = ['fk_01', 'fk_02', 'fk_03'], ) """ ## add attribute message switch_ctrl = adbAttr.NodeAttr([ctrl_name]) switch_ctrl.addAttr('lenght_blend', lenght_blend, keyable=False) ## Creation of the remaps values and blendColor nodes BlendColorColl_R = [ pm.shadingNode('blendColors', asUtility=1, n="Rotate__BC") for x in result_joints ] RemapValueColl = [ pm.shadingNode('remapValue', asUtility=1, n="Blend__RV") for x in result_joints ] ## Connect the FK in the Color 1 for oFK, oBlendColor in zip(ik_joints, BlendColorColl_R): pm.PyNode(oFK).rx >> pm.PyNode(oBlendColor).color1R pm.PyNode(oFK).ry >> pm.PyNode(oBlendColor).color1G pm.PyNode(oFK).rz >> pm.PyNode(oBlendColor).color1B ## Connect the IK in the Color 2 for oIK, oBlendColor in zip(fk_joints, BlendColorColl_R): pm.PyNode(oIK).rx >> pm.PyNode(oBlendColor).color2R pm.PyNode(oIK).ry >> pm.PyNode(oBlendColor).color2G pm.PyNode(oIK).rz >> pm.PyNode(oBlendColor).color2B ## Connect the BlendColor node in the Blend joint chain for oBlendColor, oBlendJoint in zip(BlendColorColl_R, result_joints): pm.PyNode(oBlendColor).outputR >> pm.PyNode(oBlendJoint).rx pm.PyNode(oBlendColor).outputG >> pm.PyNode(oBlendJoint).ry pm.PyNode(oBlendColor).outputB >> pm.PyNode(oBlendJoint).rz for oBlendColor in BlendColorColl_R: pm.PyNode(oBlendColor).blender.set(1) ## Connect the Remap Values to Blend Colors for oRemapValue, oBlendColor in zip(RemapValueColl, BlendColorColl_R): pm.PyNode(oRemapValue).outValue >> pm.PyNode(oBlendColor).blender ## Connect the IK -FK Control to Remap Value blend_switch = '{}.{}'.format(ctrl_name, blend_attribute) for each in RemapValueColl: pm.PyNode(blend_switch) >> pm.PyNode(each).inputValue pm.PyNode('{}.{}'.format( ctrl_name, switch_ctrl.attrName)) >> pm.PyNode(each).inputMax