def makeDisplayMod( origMods ): import sgBFunction_convert origMods = sgBFunction_convert.singleToList( origMods ) displayMods = [] for origMod in origMods: displayMod = cmds.duplicate( origMod, n='display_'+origMod )[0] displayMods.append( displayMod ) cmds.select( displayMods ) return displayMods
def getTopJointChildren( topNodes ): import sgBFunction_convert topNodes = sgBFunction_convert.singleToList( topNodes ) returnList = [] for topNode in topNodes: if cmds.nodeType( topNode ) == 'joint': returnList.append( topNode ) continue returnList += getTopJointChildren( cmds.listRelatives( topNode, c=1, f=1 ) ) return returnList
def getTopJointChildren(topNodes): import sgBFunction_convert topNodes = sgBFunction_convert.singleToList(topNodes) returnList = [] for topNode in topNodes: if cmds.nodeType(topNode) == 'joint': returnList.append(topNode) continue returnList += getTopJointChildren(cmds.listRelatives(topNode, c=1, f=1)) return returnList
def mirrorObject(targets): import sgBFunction_convert targets = sgBFunction_convert.singleToList(targets) for target in targets: mtx = cmds.getAttr(target + '.wm') mirrorMtx = sgBFunction_convert.mirrorMatrix(mtx) tr = cmds.createNode('transform', n=sgBFunction_convert.convertSide(target)) cmds.xform(tr, ws=1, matrix=mirrorMtx) cmds.setAttr(tr + '.dh', 1)
def displayModConnect( displayMods ): import sgBFunction_dag import sgBFunction_convert import sgBFunction_connection displayMods = sgBFunction_convert.singleToList( displayMods ) for displayMod in displayMods: origMod = displayMod.replace( 'display_', '' ) sgBFunction_connection.constraintAll( origMod, displayMod ) displayModShape = sgBFunction_dag.getShape( displayMod ) origModShape = sgBFunction_dag.getShape( origMod ) cmds.connectAttr( origModShape+'.outMesh', displayModShape+'.inMesh' )
def bindConnect(targets, jnt): import sgBFunction_dag import sgBModel_data import sgBFunction_attribute import sgBFunction_convert targets = sgBFunction_convert.singleToList(targets) def getBindConnectObjectDcmp(jnt): sgBFunction_attribute.addAttr(jnt, ln='bindConnectObject', at='message') cons = cmds.listConnections(jnt + '.bindConnectObject', d=1, s=0) if not cons: bindConnectObject = cmds.createNode('transform', n='BindCObj_' + jnt) sgBFunction_attribute.addAttr(bindConnectObject, ln='bindConnectObject_target', at='message') cmds.connectAttr(jnt + '.bindConnectObject', bindConnectObject + '.bindConnectObject_target') cmds.parent(bindConnectObject, jnt) else: bindConnectObject = cons[0] cons = cmds.listConnections(bindConnectObject + '.wm', type='decomposeMatrix') if not cons: dcmp = cmds.createNode('decomposeMatrix') cmds.connectAttr(bindConnectObject + '.wm', dcmp + '.imat') else: dcmp = cons[0] cmds.xform(bindConnectObject, ws=1, matrix=sgBModel_data.getDefaultMatrix()) return dcmp dcmp = getBindConnectObjectDcmp(jnt) for target in targets: cmds.connectAttr(dcmp + '.ot', target + '.t') cmds.connectAttr(dcmp + '.or', target + '.r') cmds.connectAttr(dcmp + '.os', target + '.s') cmds.connectAttr(dcmp + '.osh', target + '.sh')
def addWobbleCurve(targetCurves): import sgBFunction_convert import sgBFunction_dag targetCurves = sgBFunction_convert.singleToList(targetCurves) targetCurves = sgBFunction_dag.getChildrenShapeExists(targetCurves) for targetCurve in targetCurves: targetShape = sgBFunction_dag.getShape(targetCurve) cons = cmds.listConnections(targetShape + '.create', p=1, c=1, s=1, d=0) sourceAttr = '' if not cons: origShape = cmds.createNode('nurbsCurve') cmds.connectAttr(targetShape + '.local', origShape + '.create') cmds.refresh() cmds.disconnectAttr(targetShape + '.local', origShape + '.create') origObject = cmds.listRelatives(origShape, p=1)[0] origShape = cmds.parent(origShape, targetCurve) cmds.setAttr(origShape + '.io', 1) cmds.delete(origObject) sourceAttr = origShape + '.local' else: sourceAttr = cons[1] sgWobbleCurve = cmds.createNode('sgWobbleCurve2') cmds.connectAttr(sourceAttr, sgWobbleCurve + '.inputCurve') cmds.connectAttr(sgWobbleCurve + '.outputCurve', targetShape + '.create', f=1) cmds.connectAttr('time1.outTime', sgWobbleCurve + '.time') cmds.setAttr(sgWobbleCurve + '.fallOff1[0].fallOff1_Position', 0.2) cmds.setAttr(sgWobbleCurve + '.fallOff1[0].fallOff1_FloatValue', 0.0) cmds.setAttr(sgWobbleCurve + '.fallOff1[1].fallOff1_Position', 1) cmds.setAttr(sgWobbleCurve + '.fallOff1[1].fallOff1_FloatValue', 1) cmds.setAttr(sgWobbleCurve + '.timeMult1', 2)
def createBJT_from_RJT( rjts ): import sgBFunction_convert rjts = sgBFunction_convert.singleToList( rjts ) for rjt in rjts: if cmds.objExists( rjt.replace( '_RJT', '_BJT' ) ): cmds.warning( "%s is aleady exists." % rjt.replace( '_RJT', '_BJT' ) ) continue rjtP = cmds.listRelatives( rjt, p=1, f=1 )[0] targetP = cmds.listConnections( rjtP+'.t' )[0] cmds.select( targetP ) target = cmds.joint() target = cmds.rename( target, rjt.replace( '_RJT', '_BJT' ) ) cmds.connectAttr( rjt+'.t', target+'.t' ) cmds.connectAttr( rjt+'.r', target+'.r' )
def setWobbleCurveRotateRandom( wobbleCurves, randMin, randMax ): import random import sgBFunction_convert import sgBFunction_dag wobbleCurves = sgBFunction_convert.singleToList( wobbleCurves ) for curve in wobbleCurves: wobbleNode = sgBFunction_dag.getNodeFromHistory( curve, 'sgWobbleCurve2' ) if not wobbleNode: continue mmdc = cmds.listConnections( wobbleNode[0]+'.aimMatrix' ) if not mmdc: continue aimMatrixObj = cmds.listConnections( mmdc[0]+'.i[0]' ) if not aimMatrixObj: continue randomValueRotate = random.uniform( randMin, randMax ) cmds.setAttr( aimMatrixObj[0]+'.rotateY', randomValueRotate )
def setNearestPointOnCurveInfo( targetCrvs, createTransform = False ): import sgBFunction_convert import sgBFunction_dag targetCrvs = sgBFunction_convert.singleToList( targetCrvs ) infos = [] for crv in targetCrvs: crv = sgBFunction_dag.getShape( crv ) npc = cmds.createNode( 'nearestPointOnCurve' ) info = cmds.createNode( 'pointOnCurveInfo' ) cmds.connectAttr( crv+'.worldSpace[0]', npc+'.inputCurve' ) cmds.connectAttr( crv+'.worldSpace[0]', info+'.inputCurve' ) cmds.connectAttr( npc+'.parameter', info+'.parameter' ) infos.append( npc ) if createTransform: transforms = [] for info in infos: trNode = cmds.createNode( 'transform' ) fbf = cmds.createNode( 'fourByFourMatrix' ) mmdc= cmds.createNode( 'multMatrixDecompose' ) cmds.connectAttr( info+'.positionX', fbf+'.i30' ) cmds.connectAttr( info+'.positionY', fbf+'.i31' ) cmds.connectAttr( info+'.positionZ', fbf+'.i32' ) cmds.setAttr( trNode+'.dh', 1 ) cmds.connectAttr( fbf+'.output', mmdc+'.i[0]' ) cmds.connectAttr( trNode+'.pim', mmdc+'.i[1]' ) cmds.connectAttr( mmdc+'.ot', trNode+'.t' ) transforms.append( trNode ) cmds.select( transforms ) return infos
def setWobbleCurveRotateRandom(wobbleCurves, randMin, randMax): import random import sgBFunction_convert import sgBFunction_dag wobbleCurves = sgBFunction_convert.singleToList(wobbleCurves) for curve in wobbleCurves: wobbleNode = sgBFunction_dag.getNodeFromHistory( curve, 'sgWobbleCurve2') if not wobbleNode: continue mmdc = cmds.listConnections(wobbleNode[0] + '.aimMatrix') if not mmdc: continue aimMatrixObj = cmds.listConnections(mmdc[0] + '.i[0]') if not aimMatrixObj: continue randomValueRotate = random.uniform(randMin, randMax) cmds.setAttr(aimMatrixObj[0] + '.rotateY', randomValueRotate)
def bindConnect( targets, jnt ): import sgBFunction_dag import sgBModel_data import sgBFunction_attribute import sgBFunction_convert targets = sgBFunction_convert.singleToList( targets ) def getBindConnectObjectDcmp( jnt ): sgBFunction_attribute.addAttr( jnt, ln='bindConnectObject', at='message' ) cons = cmds.listConnections( jnt+'.bindConnectObject', d=1, s=0 ) if not cons: bindConnectObject = cmds.createNode( 'transform', n= 'BindCObj_' + jnt ) sgBFunction_attribute.addAttr( bindConnectObject, ln='bindConnectObject_target', at='message' ) cmds.connectAttr( jnt+'.bindConnectObject', bindConnectObject+'.bindConnectObject_target' ) cmds.parent( bindConnectObject, jnt ) else: bindConnectObject = cons[0] cons = cmds.listConnections( bindConnectObject+'.wm', type='decomposeMatrix' ) if not cons: dcmp = cmds.createNode( 'decomposeMatrix' ) cmds.connectAttr( bindConnectObject+'.wm', dcmp+'.imat' ) else: dcmp = cons[0] cmds.xform( bindConnectObject, ws=1, matrix=sgBModel_data.getDefaultMatrix() ) return dcmp dcmp = getBindConnectObjectDcmp( jnt ) for target in targets: cmds.connectAttr( dcmp+'.ot', target+'.t' ) cmds.connectAttr( dcmp+'.or', target+'.r' ) cmds.connectAttr( dcmp+'.os', target+'.s' ) cmds.connectAttr( dcmp+'.osh', target+'.sh' )
def addWobbleCurve( targetCurves ): import sgBFunction_convert import sgBFunction_dag targetCurves = sgBFunction_convert.singleToList( targetCurves ) targetCurves = sgBFunction_dag.getChildrenShapeExists( targetCurves ) for targetCurve in targetCurves: targetShape = sgBFunction_dag.getShape( targetCurve ) cons = cmds.listConnections( targetShape+'.create', p=1, c=1, s=1, d=0 ) sourceAttr = '' if not cons: origShape = cmds.createNode( 'nurbsCurve' ) cmds.connectAttr( targetShape+'.local', origShape+'.create' ) cmds.refresh() cmds.disconnectAttr( targetShape+'.local', origShape+'.create' ) origObject = cmds.listRelatives( origShape, p=1 )[0] origShape = cmds.parent( origShape, targetCurve ) cmds.setAttr( origShape+'.io', 1 ) cmds.delete( origObject ) sourceAttr = origShape+'.local' else: sourceAttr = cons[1] sgWobbleCurve = cmds.createNode( 'sgWobbleCurve2' ) cmds.connectAttr( sourceAttr, sgWobbleCurve + '.inputCurve' ) cmds.connectAttr( sgWobbleCurve+'.outputCurve', targetShape+'.create', f=1 ) cmds.connectAttr( 'time1.outTime', sgWobbleCurve+'.time' ) cmds.setAttr( sgWobbleCurve +'.fallOff1[0].fallOff1_Position', 0.2 ) cmds.setAttr( sgWobbleCurve +'.fallOff1[0].fallOff1_FloatValue', 0.0 ) cmds.setAttr( sgWobbleCurve +'.fallOff1[1].fallOff1_Position', 1 ) cmds.setAttr( sgWobbleCurve +'.fallOff1[1].fallOff1_FloatValue', 1 ) cmds.setAttr( sgWobbleCurve + '.timeMult1', 2 )