def importCache( targets, cacheFolderPath ): import sgFunctionCache import random for target in targets: target = sgModelDag.getTransform( target ) attrNum = cmds.getAttr( target+'.cacheAttr' ) xmlFileName = 'riceType_%02dShape.xml' % ( attrNum ) xmlFilePath = cacheFolderPath + '/' + xmlFileName animCurve = sgModelDg.getRoofLinearCurve( 1, 32, 1, 32 ) addNode = cmds.createNode( 'addDoubleLinear' ) sgFunctionCache.importCache( target, xmlFilePath ) time1 = sgModelDag.getNodeFromHistory( target, 'time' )[0] cacheFile = sgModelDag.getNodeFromHistory( target, 'cacheFile' )[0] sgRigAttribute.addAttr( target, ln='cacheOffset', k=1, dv=random.uniform( 1, 32 ) ) cmds.connectAttr( time1+'.outTime', addNode+'.input1' ) cmds.connectAttr( target+'.cacheOffset', addNode+'.input2' ) cmds.connectAttr( addNode+'.output', animCurve+'.input' ) cmds.connectAttr( animCurve+'.output', cacheFile+'.time', f=1 )
def addCacheAttr( sels ): attrName = 'cacheAttr' index= 0 for sel in sels: sel = cmds.rename( sel, 'riceType_%02d' % index ) sgRigAttribute.addAttr( sel, ln=attrName, at='long', dv=index ) index += 1
def modelAsReference( worldCtl, model ): sgRigAttribute.addAttr( worldCtl, ln='modelAsReference', at='long', min=0, max=1, cb=1, dv=1 ) cmds.setAttr( model+'.overrideEnabled', 1 ) condition = cmds.createNode( 'condition' ) cmds.connectAttr( worldCtl+'.modelAsReference', condition+'.firstTerm' ) cmds.setAttr( condition+'.colorIfTrueR', 0 ) cmds.setAttr( condition+'.colorIfFalseR', 2 ) cmds.connectAttr( condition+'.outColorR', model+'.overrideDisplayType')
def connectGear( objs, jnt ): import sgModelDag import sgRigDag import sgRigAttribute for obj in objs: size = sgModelDag.getBoundingBoxSize( obj, ws=1 ) sgRigAttribute.addAttr( jnt, ln='size', dv=size[0] ) constJnt = getConstJnt( jnt ) geometryConstObj = sgRigDag.getGeometryConstObj( constJnt ) obj = sgModelDag.getTransform( obj ) cmds.parent( obj, geometryConstObj )
def makeAnimCurveScene(): animCurves = [] for k in range( len( bakeTargetList ) ): #print "bakeTrargetList : ", bakeTargetList[k] tr = bakeTargetList[k][0] for j in range( len( bakeTargetList[k][3] ) ): attr = bakeTargetList[k][3][j][0] info = bakeTargetList[k][3][j][1] animCurve = info.createAnimCurve() #animCurve = cmds.rename( animCurve, 'sceneBake_animCurve_for_%s' %( tr.split( '|' )[-1]+'_'+attr ) ) sgRigAttribute.addAttr( animCurve, ln='bakeTargetAttrName', dt='string' ) cmds.setAttr( animCurve+'.bakeTargetAttrName', tr+'.'+attr, type='string' ) animCurves.append( animCurve ) if not animCurves: animCurves = [cmds.createNode( 'animCurveUU' )] cmds.select( animCurves ) cmds.file( animCurvesPath, force=1, options="v=0;", typ="mayaAscii", es=1 ) cmds.delete( animCurves )
def getMultDoubleLinear( attr ): multNodes = cmds.listConnections( attr, type='multDoubleLinear', s=1, d=0 ) if not multNodes: multNode = cmds.createNode( 'multDoubleLinear' ) sgRigAttribute.addAttr( multNode, ln='clumpWidthMult', at='message' ) attrValue = cmds.getAttr( attr ) cmds.setAttr( multNode+'.input1', attrValue ) cmds.connectAttr( multNode+'.output', attr ) return multNode else: if not cmds.attributeQuery( 'clumpWidthMult', node=multNodes[0], ex=1 ): multNode = cmds.createNode( 'multDoubleLinear' ) sgRigAttribute.addAttr( multNode, ln='clumpWidthMult', at='message' ) attrValue = cmds.getAttr( attr ) cmds.setAttr( multNode+'.input1', attrValue ) cmds.connectAttr( multNode+'.output', attr ) return multNode else: return multNodes[0]
def getConstJnt( jnt ): import sgRigAttribute sgRigAttribute.addAttr( jnt, ln='ConstJnt', at='message' ) cons = cmds.listConnections( jnt+'.ConstJnt', s=1, d=0 ) if cons: return cons[0] mmdc = cmds.createNode( 'sgMultMatrixDecompose' ) constJnt = cmds.createNode( 'joint' ) constJntGrp = cmds.group( constJnt ) cmds.setAttr( constJnt+'.radius', 2 ) cmds.connectAttr( jnt+'.wm', mmdc+'.i[0]' ) cmds.connectAttr( constJntGrp+'.pim', mmdc+'.i[1]' ) cmds.connectAttr( mmdc+'.ot', constJntGrp+'.t' ) cmds.connectAttr( mmdc+'.or', constJntGrp+'.r' ) cmds.connectAttr( constJnt+'.message', jnt+'.ConstJnt' ) return constJnt
def followMatrixConnection( ctl, others ): ctlP = cmds.listRelatives( ctl, p=1 )[0] followMatrix = cmds.createNode( 'followMatrix' ) mmdc = cmds.createNode( 'multMatrixDecompose' ) cmds.connectAttr( others[0]+'.wm', followMatrix+'.originalMatrix' ) sgRigAttribute.addAttr( ctl, ln='_______', at='enum', en='Parent:', cb=1 ) for other in others[1:]: i = others.index( other ) - 1 cmds.connectAttr( other+'.wm', followMatrix+'.inputMatrix[%d]' % i ) attrName = 'parent' + other.split( '_' )[-1][2:] sgRigAttribute.addAttr( ctl, ln= attrName, min=0, max=10, k=1 ) cmds.connectAttr( ctl+'.'+attrName, followMatrix+'.inputWeight[%d]' % i ) cmds.connectAttr( followMatrix+'.outputMatrix', mmdc+'.i[0]' ) cmds.connectAttr( ctlP+'.pim', mmdc+'.i[1]' ) cmds.connectAttr( mmdc+'.ot', ctlP+'.t' ) cmds.connectAttr( mmdc+'.or', ctlP+'.r' )
def connectVisibilty( ctl, mesh, outputCurves, pfxHairs ): sgRigAttribute.addAttr( ctl, ln='meshVis', at='long', min=0, max=1, cb=1 ) sgRigAttribute.addAttr( ctl, ln='outputCurves', at='long', min=0, max=1, cb=1 ) sgRigAttribute.addAttr( ctl, ln='pfxHairs', at='long', min=0, max=1, cb=1 ) sgRigConnection.connectAttrCommon( ctl+'.meshVis', mesh+'.v' ) sgRigConnection.connectAttrCommon( ctl+'.outputCurves', outputCurves+'.v' ) sgRigConnection.connectAttrCommon( ctl+'.pfxHairs', pfxHairs+'.v' )
def followMatrixConnection(ctl, others): ctlP = cmds.listRelatives(ctl, p=1)[0] followMatrix = cmds.createNode('followMatrix') mmdc = cmds.createNode('multMatrixDecompose') cmds.connectAttr(others[0] + '.wm', followMatrix + '.originalMatrix') sgRigAttribute.addAttr(ctl, ln='_______', at='enum', en='Parent:', cb=1) for other in others[1:]: i = others.index(other) - 1 cmds.connectAttr(other + '.wm', followMatrix + '.inputMatrix[%d]' % i) attrName = 'parent' + other.split('_')[-1][2:] sgRigAttribute.addAttr(ctl, ln=attrName, min=0, max=10, k=1) cmds.connectAttr(ctl + '.' + attrName, followMatrix + '.inputWeight[%d]' % i) cmds.connectAttr(followMatrix + '.outputMatrix', mmdc + '.i[0]') cmds.connectAttr(ctlP + '.pim', mmdc + '.i[1]') cmds.connectAttr(mmdc + '.ot', ctlP + '.t') cmds.connectAttr(mmdc + '.or', ctlP + '.r')
def connectRotateGearAttr(ctl, others): import sgRigAttribute sgRigAttribute.addAttr(ctl, ln='rotateGear', k=1) for other in others: sgRigAttribute.addAttr(other, ln='rotateGear', k=1) sgRigAttribute.addAttr(other, ln='globalMult', k=1, dv=1) addNode = cmds.createNode('addDoubleLinear') multNode = cmds.createNode('multDoubleLinear') cmds.connectAttr(other + '.rotateGear', addNode + '.input1') cmds.connectAttr(ctl + '.rotateGear', multNode + '.input1') cmds.connectAttr(other + '.globalMult', multNode + '.input2') cmds.connectAttr(multNode + '.output', addNode + '.input2') cmds.connectAttr(addNode + '.output', other + '.rotateZ')
def connectRotateGearAttr( ctl, others ): import sgRigAttribute sgRigAttribute.addAttr( ctl, ln='rotateGear', k=1 ) for other in others: sgRigAttribute.addAttr( other, ln='rotateGear', k=1 ) sgRigAttribute.addAttr( other, ln='globalMult', k=1, dv=1 ) addNode = cmds.createNode( 'addDoubleLinear' ) multNode = cmds.createNode( 'multDoubleLinear' ) cmds.connectAttr( other+'.rotateGear', addNode+'.input1' ) cmds.connectAttr( ctl+'.rotateGear', multNode+'.input1' ) cmds.connectAttr( other+'.globalMult', multNode+'.input2' ) cmds.connectAttr( multNode+'.output', addNode+'.input2' ) cmds.connectAttr( addNode+'.output', other+'.rotateZ' )
def createRoofPointers(crv, numPointer, roofLength=None): if not roofLength: roofLength = numPointer crv = sgModelDag.getTransform(crv) crvShape = sgModelDag.getShape(crv) sgRigAttribute.addAttr(crv, ln='roofValue', k=1) minValue = cmds.getAttr(crvShape + '.minValue') maxValue = cmds.getAttr(crvShape + '.maxValue') eachInputOffset = float(roofLength) / numPointer pointers = [] for i in range(numPointer): curveInfo = cmds.createNode('pointOnCurveInfo') pointer = cmds.createNode('transform', n=crv + '_pointer_%d' % i) sgRigAttribute.addAttr(pointer, ln='roofPointerNum', dv=i) sgRigAttribute.addAttr(pointer, ln='parameter', dv=i * eachInputOffset, k=1) cmds.setAttr(pointer + '.dh', 1) cmds.connectAttr(crvShape + '.local', curveInfo + '.inputCurve') addNode = cmds.createNode('plusMinusAverage') animCurve = sgModelDg.getRoofLinearCurve(0, float(roofLength), minValue, maxValue) cmds.connectAttr(crv + '.roofValue', addNode + '.input1D[0]') cmds.connectAttr(pointer + '.parameter', addNode + '.input1D[1]') cmds.connectAttr(addNode + '.output1D', animCurve + '.input') cmds.connectAttr(animCurve + '.output', curveInfo + '.parameter') cmds.connectAttr(curveInfo + '.position', pointer + '.t') pointer = cmds.parent(pointer, crv)[0] pointers.append(pointer) return pointers
def createRoofPointers( crv, numPointer, roofLength=None ): if not roofLength: roofLength = numPointer crv = sgModelDag.getTransform( crv ) crvShape= sgModelDag.getShape( crv ) sgRigAttribute.addAttr( crv, ln='roofValue', k=1 ) minValue = cmds.getAttr( crvShape+'.minValue' ) maxValue = cmds.getAttr( crvShape+'.maxValue' ) eachInputOffset = float( roofLength ) / numPointer pointers = [] for i in range( numPointer ): curveInfo = cmds.createNode( 'pointOnCurveInfo' ) pointer = cmds.createNode( 'transform', n= crv+'_pointer_%d' % i ) sgRigAttribute.addAttr( pointer, ln='roofPointerNum', dv=i ) sgRigAttribute.addAttr( pointer, ln='parameter', dv=i*eachInputOffset, k=1 ) cmds.setAttr( pointer+'.dh', 1 ) cmds.connectAttr( crvShape+'.local', curveInfo+'.inputCurve' ) addNode = cmds.createNode( 'plusMinusAverage' ) animCurve = sgModelDg.getRoofLinearCurve( 0, float( roofLength ), minValue, maxValue ) cmds.connectAttr( crv+'.roofValue', addNode+'.input1D[0]' ) cmds.connectAttr( pointer+'.parameter', addNode+'.input1D[1]' ) cmds.connectAttr( addNode+'.output1D', animCurve+'.input' ) cmds.connectAttr( animCurve+'.output', curveInfo+'.parameter' ) cmds.connectAttr( curveInfo+'.position', pointer+'.t' ) pointer = cmds.parent( pointer, crv )[0] pointers.append( pointer ) return pointers
def createConveyerBeltSet(meshName, firstEdgeIndex, secondEdgeIndex): firstEdges = cmds.polySelectSp(meshName + '.e[%d]' % firstEdgeIndex, loop=1) secondEdges = cmds.polySelectSp(meshName + '.e[%d]' % secondEdgeIndex, loop=1) cmds.select(firstEdges) firstCurve = cmds.polyToCurve(form=2, degree=3, n=meshName + '_loopCurve_First')[0] cmds.select(secondEdges) secondCurve = cmds.polyToCurve(form=2, degree=3, n=meshName + '_loopCurve_Second')[0] firstCurveShape = sgModelDag.getShape(firstCurve) secondCurveShape = sgModelDag.getShape(secondCurve) firstSpans = cmds.getAttr(firstCurveShape + '.spans') secondSpans = cmds.getAttr(secondCurveShape + '.spans') firstTangent = sgModelCurve.getTangentAtParam(firstCurveShape, 0.0) firstParamPoint = sgModelCurve.getPointAtParam(firstCurveShape, 0.0) secondParam = sgModelCurve.getParamAtPoint(secondCurveShape, firstParamPoint) secondTangent = sgModelCurve.getTangentAtParam(secondCurveShape, secondParam) if firstTangent * secondTangent < 0: cmds.reverseCurve(secondCurve, ch=1, rpo=1) firstPointers = sgRigCurve.createRoofPointers(firstCurve, firstSpans) secondPointers = sgRigCurve.createRoofPointers(secondCurve, secondSpans) fPos = cmds.xform(firstPointers[0], q=1, ws=1, t=1) minDistPointer = secondPointers[0] minDist = 1000000000.0 for secondPointer in secondPointers: sPos = cmds.xform(secondPointer, q=1, ws=1, t=1) dist = (fPos[0] - sPos[0])**2 + (fPos[1] - sPos[1])**2 + (fPos[2] - sPos[2])**2 if dist < minDist: minDistPointer = secondPointer minDist = dist offset = int(minDistPointer.split('_')[-1]) crvs = [] for i in range(len(firstPointers)): firstPointer = firstPointers[i] secondPointer = '_'.join(secondPointers[i].split('_')[:-1]) + '_%d' % ( (i + offset) % firstSpans) crv = sgRigCurve.createCurveOnTargetPoints( [firstPointer, secondPointer]) crv = cmds.rename(crv, meshName + '_line_%d' % i) crvs.append(crv) cmds.select(crvs) loftSurf = cmds.loft(n=meshName + '_loft')[0] resultObject = cmds.nurbsToPoly(loftSurf, mnd=1, ch=1, f=3, pt=0, pc=200, chr=0.9, ft=0.01, mel=0.001, d=0.1, ut=1, un=3, vt=1, vn=3, uch=0, ucr=0, cht=0.2, es=0, ntr=0, mrt=0, uss=1, n=meshName + '_conveyorBelt') crvGrp = cmds.group(crvs, n=meshName + '_lines') conveyorRig = cmds.group(firstCurve, secondCurve, crvGrp, loftSurf, resultObject, meshName, n=meshName + '_conveyorRig') import sgRigAttribute sgRigAttribute.addAttr(conveyorRig, ln='offset', k=1) cmds.connectAttr(conveyorRig + '.offset', firstCurve + '.roofValue') cmds.connectAttr(conveyorRig + '.offset', secondCurve + '.roofValue') cmds.setAttr(conveyorRig + '.v', 0)
def addControllerToBag( bagObject ): PBagObject = cmds.listRelatives( bagObject, p=1 )[0] bagObject, PivBagObject = sgRigDag.addParent( bagObject, 'Piv' ) cmds.setAttr( bagObject+'.ty', -0.16 ) cmds.setAttr( PivBagObject+'.ty', 0.16 ) cons = cmds.listConnections( bagObject, s=1, d=0, type='animCurve' ) if cons: cmds.delete( cons ) mainCtl = cmds.circle( n='Ctl_' + bagObject, normal=[0,0,1], center=[0,0,1.4] )[0] mainCtl, pmainCtl = sgRigDag.addParent( mainCtl ) mainCtl, omainCtl = sgRigDag.addParent( mainCtl ) cmds.setAttr( mainCtl+'.overrideEnabled', 1 ) cmds.setAttr( mainCtl+'.overrideColor', 6 ) cmds.setAttr( omainCtl+'.ty', 0.16 ) pointDCtl = [[0.0, 0.53619110199777498, -0.080351999999999979], [0.0, 0.53619110199777498, -0.16070399999999996], [0.0, 0.73851681927679846, 0.0], [0.0, 0.53619110199777498, 0.16071360000000001], [0.0, 0.53619110199777498, 0.080356800000000006], [0.0, -0.53616508520269901, 0.080356800000000117], [1.1102230246251568e-16, -0.53616508520269901, 0.16071360000000018], [0.0, -0.73851215501375644, 0.0], [0.0, -0.53616508520269901, -0.1607039999999999], [-1.1102230246251568e-16, -0.53616508520269901, -0.080351999999999923], [0.0, 0.53619110199777498, -0.080351999999999979], [0.0, 0.53619110199777498, -0.080351999999999979]] dCtl = cmds.curve( n='Ctl_DirObj_'+bagObject, p=pointDCtl, d=1 ) cmds.setAttr( dCtl+'.overrideEnabled', 1 ) cmds.setAttr( dCtl+'.overrideColor', 18 ) dCtlChild = sgRigDag.addChild( dCtl ) dCtl, PdCtl = sgRigDag.addParent( dCtl ) shakeObject = sgRigDag.addChild( mainCtl ) shakeObject, pshakeObject = sgRigDag.addParent( shakeObject ) cshakeObject = sgRigDag.addChild( shakeObject ) sgRigConnection.constraint( PdCtl, dCtlChild ) sgRigConnection.constraintAll( mainCtl, PdCtl ) sgRigConnection.constraint( PBagObject, pmainCtl ) sgRigConnection.constraintAll( cshakeObject, PivBagObject ) sgRigConnection.constraint( dCtl, pshakeObject ) cmds.connectAttr( dCtlChild+'.r', cshakeObject+'.r') sgRigAttribute.addAttr( mainCtl, ln='globalShake', k=1, dv=1 ) sgRigAttribute.addAttr( mainCtl, ln='globalTimeMult', k=1, dv=1 ) sgRigAttribute.addAttr( mainCtl, ln='globalOffset', k=1 ) sgRigAttribute.addAttr( mainCtl, ln='shake', k=1, dv=1 ) sgRigAttribute.addAttr( mainCtl, ln='timeMult', k=1, dv=1 ) sgRigAttribute.addAttr( mainCtl, ln='offset', k=1 ) sgRigAttribute.addAttr( mainCtl, ln='showBag', at='long', k=1, min=0, max=1, dv=1 ) mdForTime1 = cmds.createNode( 'multDoubleLinear' ) mdForTime2 = cmds.createNode( 'multDoubleLinear' ) mdForShake1 = cmds.createNode( 'multDoubleLinear' ) mdForShake2 = cmds.createNode( 'multDoubleLinear' ) addForOfs1 = cmds.createNode( 'addDoubleLinear' ) addForOfs2 = cmds.createNode( 'addDoubleLinear' ) animCurve = sgModelDg.getRoofSineCurve( 0, 10, -10, 10 ) cmds.connectAttr( mainCtl+'.globalTimeMult', mdForTime1+'.input1' ) cmds.connectAttr( mainCtl+'.timeMult', mdForTime1+'.input2' ) cmds.connectAttr( mdForTime1+'.output', mdForTime2+'.input1' ) cmds.connectAttr( 'time1.outTime', mdForTime2+'.input2' ) cmds.connectAttr( mainCtl+'.globalOffset', addForOfs1+'.input1' ) cmds.connectAttr( mainCtl+'.offset', addForOfs1+'.input2' ) cmds.connectAttr( addForOfs1+'.output', addForOfs2+'.input1' ) cmds.connectAttr( mdForTime2+'.output', addForOfs2+'.input2' ) cmds.connectAttr( addForOfs2+'.output', animCurve+'.input' ) cmds.connectAttr( mainCtl+'.globalShake', mdForShake1+'.input1' ) cmds.connectAttr( mainCtl+'.shake', mdForShake1+'.input2' ) cmds.connectAttr( mdForShake1+'.output', mdForShake2+'.input1' ) cmds.connectAttr( animCurve+'.output', mdForShake2+'.input2' ) cmds.connectAttr( mainCtl+'.showBag', bagObject+'.v' ) cmds.connectAttr( mdForShake2+'.output', shakeObject+'.rx' ) cmds.setAttr( mainCtl+'.v', e=1, lock=1 )
def createBendToCurve( curve ): import math curve = sgModelDag.getTransform( curve ) cvs = cmds.ls( curve+'.cv[*]', fl=1 ) startPoint= cmds.xform( cvs[0], q=1, ws=1, t=1 ) endPoint = cmds.xform( cvs[-1], q=1, ws=1, t=1 ) bend, handle = cmds.nonLinear( curve, type='bend', lowBound=0, highBound=1, curvature=0) cmds.xform( handle, ws=1, t=startPoint ) vStartPoint = sgModelConvert.convertMVectorFromPointList( startPoint ) vEndPoint = sgModelConvert.convertMVectorFromPointList( endPoint ) vAim = vEndPoint - vStartPoint yVector = om.MVector( *[0,1,0] ) zVector = om.MVector( *[1,0,0] ) dotY = math.fabs(vAim * yVector) dotZ = math.fabs(vAim * zVector) vUp = None if dotY > dotZ: vUp = zVector else: vUp = yVector vCross = vAim ^ vUp vUp = vCross ^ vAim lengthAim = vAim.length() vUp.normalize() vCross.normalize() vUp *= lengthAim vCross *= lengthAim mtx = [ vCross.x, vCross.y, vCross.z, 0, vAim.x, vAim.y, vAim.z, 0, vUp.x, vUp.y, vUp.z, 0, vStartPoint.x, vStartPoint.y, vStartPoint.z, 1 ] cmds.xform( handle, ws=1, matrix=mtx ) handle, handleGrp = sgRigDag.addParent( handle ) sgRigAttribute.addAttr( curve, ln='globalTwist', k=1 ) sgRigAttribute.addAttr( curve, ln='globalBend', k=1 ) sgRigAttribute.addAttr( curve, ln='twist', k=1, dv=0 ) sgRigAttribute.addAttr( curve, ln='bend', k=1, dv=1 ) addTwist = cmds.createNode( 'addDoubleLinear' ) multBend = cmds.createNode( 'multDoubleLinear' ) cmds.connectAttr( curve+'.globalTwist', addTwist+'.input1' ) cmds.connectAttr( curve+'.twist', addTwist+'.input2' ) cmds.connectAttr( curve+'.globalBend', multBend+'.input1' ) cmds.connectAttr( curve+'.bend', multBend+'.input2' ) cmds.connectAttr( multBend+'.output', bend+'.curvature' ) cmds.connectAttr( addTwist+'.output', handle+'.ry' )
def addSurfaceLineObject( targetCurve, multValue = 1, range = 1 ): crvShape = sgModelDag.getShape( targetCurve ) rebuildCurveNode = cmds.createNode( 'rebuildCurve' ) detachCurveNode = cmds.createNode( 'detachCurve' ) circleNode = cmds.createNode( 'makeNurbCircle' ) extrudeNode = cmds.createNode( 'extrude' ) surfaceNode = cmds.createNode( 'nurbsSurface' ) curveInfo = cmds.createNode( 'curveInfo' ) cmds.connectAttr( crvShape+'.worldSpace', curveInfo+'.inputCurve' ) multValue = cmds.getAttr( curveInfo+'.arcLength' ) * multValue cmds.setAttr( rebuildCurveNode+'.spans', multValue ) cmds.setAttr( rebuildCurveNode+'.keepRange', 0 ) cmds.setAttr( detachCurveNode+'.parameter[0]', 0.25 ) cmds.setAttr( detachCurveNode+'.parameter[1]', 0.75 ) cmds.setAttr( extrudeNode+'.fixedPath', 1 ) cmds.setAttr( extrudeNode+'.useProfileNormal', 1 ) cmds.setAttr( extrudeNode+'.useComponentPivot', 1 ) cmds.connectAttr( crvShape+'.local', rebuildCurveNode+'.inputCurve' ) cmds.connectAttr( rebuildCurveNode+'.outputCurve', detachCurveNode+'.inputCurve' ) cmds.connectAttr( circleNode+'.outputCurve', extrudeNode+'.profile' ) cmds.connectAttr( detachCurveNode+'.outputCurve[1]', extrudeNode+'.path' ) cmds.connectAttr( extrudeNode+'.outputSurface', surfaceNode+'.create' ) surfNodeParent = cmds.listRelatives( surfaceNode, p=1 )[0] sgRigAttribute.addAttr( surfNodeParent, ln='radius', min=0, dv=1, k=1 ) sgRigAttribute.addAttr( surfNodeParent, ln='parameter', min= 0, max=range, k=1 ) sgRigAttribute.addAttr( surfNodeParent, ln='length', min=0, max=range, dv=range*0.5, k=1 ) cmds.connectAttr( surfNodeParent+'.radius', circleNode+'.radius' ) rangeNode = cmds.createNode( 'setRange' ) minusMultNode = cmds.createNode( 'multDoubleLinear' ) plusMultNode = cmds.createNode( 'multDoubleLinear' ) minusAddNode = cmds.createNode( 'addDoubleLinear' ) plusAddNode = cmds.createNode( 'addDoubleLinear' ) cmds.connectAttr( surfNodeParent+'.parameter', rangeNode+'.valueX' ) cmds.connectAttr( surfNodeParent+'.length', minusMultNode+'.input1' ) cmds.connectAttr( surfNodeParent+'.length', plusMultNode+'.input1' ) cmds.setAttr( minusMultNode+'.input2', -0.5 ) cmds.setAttr( plusMultNode+'.input2', 0.5 ) cmds.connectAttr( minusMultNode+'.output', minusAddNode+'.input1' ) cmds.connectAttr( plusMultNode+'.output', plusAddNode+'.input1' ) cmds.setAttr( minusAddNode+'.input2', 0 ) cmds.setAttr( plusAddNode +'.input2', range ) cmds.connectAttr( minusAddNode+'.output', rangeNode+'.minX' ) cmds.connectAttr( plusAddNode+'.output', rangeNode+'.maxX' ) cmds.setAttr( rangeNode+'.oldMinX', 0 ) cmds.setAttr( rangeNode+'.oldMaxX', range ) addMinNode = cmds.createNode( 'addDoubleLinear' ) addMaxNode = cmds.createNode( 'addDoubleLinear' ) cmds.connectAttr( rangeNode+'.outValueX', addMinNode+'.input1' ) cmds.connectAttr( rangeNode+'.outValueX', addMaxNode+'.input1' ) cmds.connectAttr( minusMultNode+'.output', addMinNode+'.input2' ) cmds.connectAttr( plusMultNode+'.output', addMaxNode+'.input2' ) minConditionFirst = cmds.createNode( 'condition' ) minConditionSecond = cmds.createNode( 'condition' ) maxConditionFirst = cmds.createNode( 'condition' ) maxConditionSecond = cmds.createNode( 'condition' ) cmds.connectAttr( addMinNode+'.output', minConditionFirst+'.firstTerm' ) cmds.connectAttr( addMinNode+'.output', minConditionFirst+'.colorIfFalseR' ) cmds.setAttr( minConditionFirst+'.secondTerm', range-0.0001 ) cmds.setAttr( minConditionFirst+'.colorIfTrueR', range-0.0001 ) cmds.setAttr( minConditionFirst+'.op', 2 ) cmds.connectAttr( minConditionFirst+'.outColorR', minConditionSecond+'.firstTerm' ) cmds.connectAttr( minConditionFirst+'.outColorR', minConditionSecond+'.colorIfFalseR' ) cmds.setAttr( minConditionSecond+'.secondTerm', 0 ) cmds.setAttr( minConditionSecond+'.colorIfTrueR', 0 ) cmds.setAttr( minConditionSecond+'.op', 4 ) cmds.connectAttr( addMaxNode+'.output', maxConditionFirst+'.firstTerm' ) cmds.connectAttr( addMaxNode+'.output', maxConditionFirst+'.colorIfFalseR' ) cmds.setAttr( maxConditionFirst+'.secondTerm', range ) cmds.setAttr( maxConditionFirst+'.colorIfTrueR', range ) cmds.setAttr( maxConditionFirst+'.op', 2 ) cmds.connectAttr( maxConditionFirst+'.outColorR', maxConditionSecond+'.firstTerm' ) cmds.connectAttr( maxConditionFirst+'.outColorR', maxConditionSecond+'.colorIfFalseR' ) cmds.setAttr( maxConditionSecond+'.secondTerm', 0.0001 ) cmds.setAttr( maxConditionSecond+'.colorIfTrueR', 0.0001 ) cmds.setAttr( maxConditionSecond+'.op', 4 ) minMult = cmds.createNode( 'multDoubleLinear' ) maxMult = cmds.createNode( 'multDoubleLinear' ) cmds.connectAttr( minConditionSecond+'.outColorR', minMult+'.input1' ) cmds.connectAttr( maxConditionSecond+'.outColorR', maxMult+'.input1' ) cmds.setAttr( minMult+'.input2', 1.0/range ) cmds.setAttr( maxMult+'.input2', 1.0/range ) cmds.connectAttr( minMult+'.output', detachCurveNode+'.parameter[0]' ) cmds.connectAttr( maxMult+'.output', detachCurveNode+'.parameter[1]' ) cmds.select( surfNodeParent )
def connectHairControl(ctl, hairSystem): hairSystem = sgModelDag.getNodeFromHistory(hairSystem, 'hairSystem')[0] try: sgRigAttribute.addAttr(ctl, ln='________', en='Hair:', at='enum', cb=1) except: pass sgRigAttribute.addAttr(ctl, ln='dynamicOn', min=0, max=1, at='long', cb=1) sgRigAttribute.addAttr(ctl, ln='startFrame', dv=1, at='long', cb=1) sgRigAttribute.addAttr(ctl, ln='attraction', min=0, max=1, dv=1, k=1) sgRigAttribute.addAttr(ctl, ln='attractionDamp', min=0, dv=0.5, k=1) sgRigAttribute.addAttr(ctl, ln='stiffness', min=0, max=1, dv=0.15, k=1) sgRigAttribute.addAttr(ctl, ln='mass', min=0.1, dv=1, k=1) sgRigAttribute.addAttr(ctl, ln='drag', min=0, dv=0.05, k=1) condition = cmds.createNode('condition') cmds.setAttr(condition + '.secondTerm', 0) cmds.setAttr(condition + '.colorIfTrueR', 1) cmds.setAttr(condition + '.colorIfFalseR', 3) connectAttrCommon(ctl + '.dynamicOn', condition + '.firstTerm') connectAttrCommon(ctl + '.startFrame', hairSystem + '.startFrame') connectAttrCommon(condition + '.outColorR', hairSystem + '.simulationMethod') connectAttrCommon(ctl + '.attraction', hairSystem + '.startCurveAttract') connectAttrCommon(ctl + '.stiffness', hairSystem + '.stiffness') connectAttrCommon(ctl + '.attractionDamp', hairSystem + '.attractionDamp') connectAttrCommon(ctl + '.mass', hairSystem + '.mass') connectAttrCommon(ctl + '.drag', hairSystem + '.drag')
def connectHairControl( ctl, hairSystem ): hairSystem = sgModelDag.getNodeFromHistory( hairSystem, 'hairSystem' )[0] try:sgRigAttribute.addAttr( ctl, ln='________', en='Hair:', at='enum', cb=1 ) except:pass sgRigAttribute.addAttr( ctl, ln='dynamicOn', min=0, max=1, at='long', cb=1 ) sgRigAttribute.addAttr( ctl, ln='startFrame', dv=1, at='long', cb=1 ) sgRigAttribute.addAttr( ctl, ln='attraction', min=0, max=1, dv=1, k=1 ) sgRigAttribute.addAttr( ctl, ln='attractionDamp', min=0, dv=0.5, k=1 ) sgRigAttribute.addAttr( ctl, ln='stiffness', min=0, max=1, dv=0.15, k=1 ) sgRigAttribute.addAttr( ctl, ln='mass', min=0.1, dv=1, k=1 ) sgRigAttribute.addAttr( ctl, ln='drag', min=0, dv=0.05, k=1 ) condition = cmds.createNode( 'condition' ) cmds.setAttr( condition+'.secondTerm', 0 ) cmds.setAttr( condition+'.colorIfTrueR', 1 ) cmds.setAttr( condition+'.colorIfFalseR', 3 ) connectAttrCommon( ctl+'.dynamicOn', condition+'.firstTerm' ) connectAttrCommon( ctl+'.startFrame', hairSystem+'.startFrame' ) connectAttrCommon( condition+'.outColorR', hairSystem+'.simulationMethod' ) connectAttrCommon( ctl+'.attraction', hairSystem+'.startCurveAttract' ) connectAttrCommon( ctl+'.stiffness', hairSystem+'.stiffness' ) connectAttrCommon( ctl+'.attractionDamp', hairSystem+'.attractionDamp' ) connectAttrCommon( ctl+'.mass', hairSystem+'.mass' ) connectAttrCommon( ctl+'.drag', hairSystem+'.drag' )
def createRoofPointers(surface, numPointer, aimDirection='v', roofLength=10): surface = sgModelDag.getTransform(surface) surfaceShape = sgModelDag.getShape(surface) dStr = aimDirection.upper() if dStr == 'V': upStr = 'U' else: upStr = 'V' sgRigAttribute.addAttr(surface, ln='roofValue', k=1) minValue, maxValue = cmds.getAttr(surfaceShape + '.minMaxRange%s' % (dStr))[0] eachInputOffset = float(roofLength) / (numPointer - 1) for i in range(numPointer): surfaceInfo = cmds.createNode('pointOnSurfaceInfo') pointer = cmds.createNode('transform', n=surface + '_pointer%d' % i) cmds.setAttr(pointer + '.dh', 1) cmds.setAttr(pointer + '.dla', 1) cmds.connectAttr(surfaceShape + '.local', surfaceInfo + '.inputSurface') addNode = cmds.createNode('addDoubleLinear') cmds.setAttr(addNode + '.input2', eachInputOffset * i) animCurve = sgModelDg.getRoofLinearCurve(0, float(roofLength), minValue, maxValue) cmds.connectAttr(surface + '.roofValue', addNode + '.input1') cmds.connectAttr(addNode + '.output', animCurve + '.input') cmds.connectAttr(animCurve + '.output', surfaceInfo + '.parameter%s' % (dStr)) fbfMtx = cmds.createNode('fourByFourMatrix') vProduct = cmds.createNode('vectorProduct') mmdc = cmds.createNode('multMatrixDecompose') cmds.setAttr(vProduct + '.op', 2) cmds.connectAttr(surfaceInfo + '.tangent%sx' % (dStr), fbfMtx + '.i00') cmds.connectAttr(surfaceInfo + '.tangent%sy' % (dStr), fbfMtx + '.i01') cmds.connectAttr(surfaceInfo + '.tangent%sz' % (dStr), fbfMtx + '.i02') cmds.connectAttr(surfaceInfo + '.tangent%sx' % (upStr), fbfMtx + '.i10') cmds.connectAttr(surfaceInfo + '.tangent%sy' % (upStr), fbfMtx + '.i11') cmds.connectAttr(surfaceInfo + '.tangent%sz' % (upStr), fbfMtx + '.i12') cmds.connectAttr(surfaceInfo + '.positionX', fbfMtx + '.i30') cmds.connectAttr(surfaceInfo + '.positionY', fbfMtx + '.i31') cmds.connectAttr(surfaceInfo + '.positionZ', fbfMtx + '.i32') cmds.connectAttr(surfaceInfo + '.tangent%s' % (dStr), vProduct + '.input1') cmds.connectAttr(surfaceInfo + '.tangent%s' % (upStr), vProduct + '.input2') cmds.connectAttr(vProduct + '.outputX', fbfMtx + '.i20') cmds.connectAttr(vProduct + '.outputY', fbfMtx + '.i21') cmds.connectAttr(vProduct + '.outputZ', fbfMtx + '.i22') cmds.connectAttr(fbfMtx + '.output', mmdc + '.i[0]') cmds.connectAttr(pointer + '.pim', mmdc + '.i[1]') cmds.connectAttr(mmdc + '.ot', pointer + '.t') cmds.connectAttr(mmdc + '.or', pointer + '.r') cmds.parent(pointer, surface)
def createConveyerBeltSet( meshName, firstEdgeIndex, secondEdgeIndex ): firstEdges = cmds.polySelectSp( meshName+'.e[%d]' % firstEdgeIndex, loop=1 ) secondEdges = cmds.polySelectSp( meshName+'.e[%d]' % secondEdgeIndex, loop=1 ) cmds.select( firstEdges ) firstCurve = cmds.polyToCurve( form=2, degree=3, n=meshName+'_loopCurve_First' )[0] cmds.select( secondEdges ) secondCurve = cmds.polyToCurve( form=2, degree=3, n=meshName+'_loopCurve_Second' )[0] firstCurveShape = sgModelDag.getShape( firstCurve ) secondCurveShape = sgModelDag.getShape( secondCurve ) firstSpans = cmds.getAttr( firstCurveShape +'.spans' ) secondSpans = cmds.getAttr( secondCurveShape+'.spans' ) firstTangent = sgModelCurve.getTangentAtParam( firstCurveShape, 0.0 ) firstParamPoint = sgModelCurve.getPointAtParam( firstCurveShape, 0.0 ) secondParam = sgModelCurve.getParamAtPoint( secondCurveShape, firstParamPoint ) secondTangent = sgModelCurve.getTangentAtParam( secondCurveShape, secondParam ) if firstTangent * secondTangent < 0: cmds.reverseCurve( secondCurve, ch = 1, rpo = 1 ) firstPointers = sgRigCurve.createRoofPointers( firstCurve, firstSpans ) secondPointers = sgRigCurve.createRoofPointers( secondCurve, secondSpans ) fPos = cmds.xform( firstPointers[0], q=1, ws=1, t=1 ) minDistPointer = secondPointers[0] minDist = 1000000000.0 for secondPointer in secondPointers: sPos = cmds.xform( secondPointer, q=1, ws=1, t=1 ) dist = (fPos[0]-sPos[0])**2+(fPos[1]-sPos[1])**2+(fPos[2]-sPos[2])**2 if dist < minDist: minDistPointer = secondPointer minDist = dist offset = int( minDistPointer.split( '_' )[-1] ) crvs = [] for i in range( len( firstPointers ) ): firstPointer = firstPointers[i] secondPointer = '_'.join( secondPointers[i].split( '_' )[:-1] ) + '_%d' %( (i + offset)%firstSpans ) crv = sgRigCurve.createCurveOnTargetPoints( [firstPointer, secondPointer] ) crv = cmds.rename( crv, meshName+'_line_%d' % i ) crvs.append( crv ) cmds.select( crvs ) loftSurf = cmds.loft( n=meshName+'_loft' )[0] resultObject = cmds.nurbsToPoly( loftSurf ,mnd=1 ,ch=1,f=3,pt=0,pc=200,chr=0.9,ft=0.01,mel=0.001, d=0.1, ut=1, un=3, vt=1, vn=3, uch=0, ucr=0, cht=0.2, es=0,ntr=0,mrt=0, uss=1, n=meshName+'_conveyorBelt' ) crvGrp = cmds.group( crvs, n=meshName+'_lines' ) conveyorRig = cmds.group( firstCurve, secondCurve, crvGrp, loftSurf, resultObject, meshName, n=meshName+'_conveyorRig' ) import sgRigAttribute sgRigAttribute.addAttr( conveyorRig, ln='offset', k=1 ) cmds.connectAttr( conveyorRig+'.offset', firstCurve+'.roofValue' ) cmds.connectAttr( conveyorRig+'.offset', secondCurve+'.roofValue' ) cmds.setAttr( conveyorRig+'.v', 0 )
def createRoofPointers( surface, numPointer, aimDirection = 'v', roofLength = 10 ): surface = sgModelDag.getTransform( surface ) surfaceShape = sgModelDag.getShape( surface ) dStr = aimDirection.upper() if dStr == 'V': upStr = 'U' else: upStr = 'V' sgRigAttribute.addAttr( surface, ln='roofValue', k=1 ) minValue, maxValue = cmds.getAttr( surfaceShape+'.minMaxRange%s' % ( dStr ) )[0] eachInputOffset = float( roofLength ) / ( numPointer-1 ) for i in range( numPointer ): surfaceInfo = cmds.createNode( 'pointOnSurfaceInfo' ) pointer = cmds.createNode( 'transform', n= surface+'_pointer%d' % i ) cmds.setAttr( pointer+'.dh', 1 ) cmds.setAttr( pointer+'.dla', 1 ) cmds.connectAttr( surfaceShape+'.local', surfaceInfo+'.inputSurface' ) addNode = cmds.createNode( 'addDoubleLinear' ) cmds.setAttr( addNode+'.input2', eachInputOffset * i ) animCurve = sgModelDg.getRoofLinearCurve( 0, float( roofLength ), minValue, maxValue ) cmds.connectAttr( surface+'.roofValue', addNode+'.input1' ) cmds.connectAttr( addNode+'.output', animCurve+'.input' ) cmds.connectAttr( animCurve+'.output', surfaceInfo+'.parameter%s' %( dStr ) ) fbfMtx = cmds.createNode( 'fourByFourMatrix' ) vProduct = cmds.createNode( 'vectorProduct' ) mmdc = cmds.createNode( 'multMatrixDecompose' ) cmds.setAttr( vProduct+'.op', 2 ) cmds.connectAttr( surfaceInfo + '.tangent%sx' % ( dStr ), fbfMtx+'.i00' ) cmds.connectAttr( surfaceInfo + '.tangent%sy' % ( dStr ), fbfMtx+'.i01' ) cmds.connectAttr( surfaceInfo + '.tangent%sz' % ( dStr ), fbfMtx+'.i02' ) cmds.connectAttr( surfaceInfo + '.tangent%sx' % ( upStr ), fbfMtx+'.i10' ) cmds.connectAttr( surfaceInfo + '.tangent%sy' % ( upStr ), fbfMtx+'.i11' ) cmds.connectAttr( surfaceInfo + '.tangent%sz' % ( upStr ), fbfMtx+'.i12' ) cmds.connectAttr( surfaceInfo + '.positionX', fbfMtx+'.i30' ) cmds.connectAttr( surfaceInfo + '.positionY', fbfMtx+'.i31' ) cmds.connectAttr( surfaceInfo + '.positionZ', fbfMtx+'.i32' ) cmds.connectAttr( surfaceInfo+'.tangent%s' % ( dStr ), vProduct+'.input1' ) cmds.connectAttr( surfaceInfo+'.tangent%s' % ( upStr ), vProduct+'.input2' ) cmds.connectAttr( vProduct+'.outputX', fbfMtx+'.i20' ) cmds.connectAttr( vProduct+'.outputY', fbfMtx+'.i21' ) cmds.connectAttr( vProduct+'.outputZ', fbfMtx+'.i22' ) cmds.connectAttr( fbfMtx+'.output', mmdc+'.i[0]' ) cmds.connectAttr( pointer+'.pim', mmdc+'.i[1]' ) cmds.connectAttr( mmdc+'.ot', pointer+'.t' ) cmds.connectAttr( mmdc+'.or', pointer+'.r' ) cmds.parent( pointer, surface )
def createBendToCurve(curve): import math curve = sgModelDag.getTransform(curve) cvs = cmds.ls(curve + '.cv[*]', fl=1) startPoint = cmds.xform(cvs[0], q=1, ws=1, t=1) endPoint = cmds.xform(cvs[-1], q=1, ws=1, t=1) bend, handle = cmds.nonLinear(curve, type='bend', lowBound=0, highBound=1, curvature=0) cmds.xform(handle, ws=1, t=startPoint) vStartPoint = sgModelConvert.convertMVectorFromPointList(startPoint) vEndPoint = sgModelConvert.convertMVectorFromPointList(endPoint) vAim = vEndPoint - vStartPoint yVector = om.MVector(*[0, 1, 0]) zVector = om.MVector(*[1, 0, 0]) dotY = math.fabs(vAim * yVector) dotZ = math.fabs(vAim * zVector) vUp = None if dotY > dotZ: vUp = zVector else: vUp = yVector vCross = vAim ^ vUp vUp = vCross ^ vAim lengthAim = vAim.length() vUp.normalize() vCross.normalize() vUp *= lengthAim vCross *= lengthAim mtx = [ vCross.x, vCross.y, vCross.z, 0, vAim.x, vAim.y, vAim.z, 0, vUp.x, vUp.y, vUp.z, 0, vStartPoint.x, vStartPoint.y, vStartPoint.z, 1 ] cmds.xform(handle, ws=1, matrix=mtx) handle, handleGrp = sgRigDag.addParent(handle) sgRigAttribute.addAttr(curve, ln='globalTwist', k=1) sgRigAttribute.addAttr(curve, ln='globalBend', k=1) sgRigAttribute.addAttr(curve, ln='twist', k=1, dv=0) sgRigAttribute.addAttr(curve, ln='bend', k=1, dv=1) addTwist = cmds.createNode('addDoubleLinear') multBend = cmds.createNode('multDoubleLinear') cmds.connectAttr(curve + '.globalTwist', addTwist + '.input1') cmds.connectAttr(curve + '.twist', addTwist + '.input2') cmds.connectAttr(curve + '.globalBend', multBend + '.input1') cmds.connectAttr(curve + '.bend', multBend + '.input2') cmds.connectAttr(multBend + '.output', bend + '.curvature') cmds.connectAttr(addTwist + '.output', handle + '.ry')
bakeTargetList = cPickle.load(f) f.close() bakeInfoPath = bakeInfoPath.replace('\\', '/') sceneInfoPath = '/'.join( bakeInfoPath.split('/')[:-1]) + '/sceneInfo.sceneInfo' f = open(sceneInfoPath, 'r') timeUnit, minTime, maxTime = cPickle.load(f) f.close() cmds.currentUnit(time=timeUnit) for k in range(len(bakeTargetList)): #print "bakeTrargetList : ", bakeTargetList[k] tr = bakeTargetList[k][0] for j in range(len(bakeTargetList[k][3])): attr = bakeTargetList[k][3][j][0] info = bakeTargetList[k][3][j][1] animCurve = info.createAnimCurve() #animCurve = cmds.rename( animCurve, 'sceneBake_animCurve_for_%s' %( tr.split( '|' )[-1]+'_'+attr ) ) sgRigAttribute.addAttr(animCurve, ln='bakeTargetAttrName', dt='string') cmds.setAttr(animCurve + '.bakeTargetAttrName', tr + '.' + attr, type='string') cmds.file(rename=scenePath) cmds.file(f=1, save=1, options="v=0;", type="mayaAscii")
def addSurfaceLineObject(targetCurve, multValue=1, range=1): crvShape = sgModelDag.getShape(targetCurve) rebuildCurveNode = cmds.createNode('rebuildCurve') detachCurveNode = cmds.createNode('detachCurve') circleNode = cmds.createNode('makeNurbCircle') extrudeNode = cmds.createNode('extrude') surfaceNode = cmds.createNode('nurbsSurface') curveInfo = cmds.createNode('curveInfo') cmds.connectAttr(crvShape + '.worldSpace', curveInfo + '.inputCurve') multValue = cmds.getAttr(curveInfo + '.arcLength') * multValue cmds.setAttr(rebuildCurveNode + '.spans', multValue) cmds.setAttr(rebuildCurveNode + '.keepRange', 0) cmds.setAttr(detachCurveNode + '.parameter[0]', 0.25) cmds.setAttr(detachCurveNode + '.parameter[1]', 0.75) cmds.setAttr(extrudeNode + '.fixedPath', 1) cmds.setAttr(extrudeNode + '.useProfileNormal', 1) cmds.setAttr(extrudeNode + '.useComponentPivot', 1) cmds.connectAttr(crvShape + '.local', rebuildCurveNode + '.inputCurve') cmds.connectAttr(rebuildCurveNode + '.outputCurve', detachCurveNode + '.inputCurve') cmds.connectAttr(circleNode + '.outputCurve', extrudeNode + '.profile') cmds.connectAttr(detachCurveNode + '.outputCurve[1]', extrudeNode + '.path') cmds.connectAttr(extrudeNode + '.outputSurface', surfaceNode + '.create') surfNodeParent = cmds.listRelatives(surfaceNode, p=1)[0] sgRigAttribute.addAttr(surfNodeParent, ln='radius', min=0, dv=1, k=1) sgRigAttribute.addAttr(surfNodeParent, ln='parameter', min=0, max=range, k=1) sgRigAttribute.addAttr(surfNodeParent, ln='length', min=0, max=range, dv=range * 0.5, k=1) cmds.connectAttr(surfNodeParent + '.radius', circleNode + '.radius') rangeNode = cmds.createNode('setRange') minusMultNode = cmds.createNode('multDoubleLinear') plusMultNode = cmds.createNode('multDoubleLinear') minusAddNode = cmds.createNode('addDoubleLinear') plusAddNode = cmds.createNode('addDoubleLinear') cmds.connectAttr(surfNodeParent + '.parameter', rangeNode + '.valueX') cmds.connectAttr(surfNodeParent + '.length', minusMultNode + '.input1') cmds.connectAttr(surfNodeParent + '.length', plusMultNode + '.input1') cmds.setAttr(minusMultNode + '.input2', -0.5) cmds.setAttr(plusMultNode + '.input2', 0.5) cmds.connectAttr(minusMultNode + '.output', minusAddNode + '.input1') cmds.connectAttr(plusMultNode + '.output', plusAddNode + '.input1') cmds.setAttr(minusAddNode + '.input2', 0) cmds.setAttr(plusAddNode + '.input2', range) cmds.connectAttr(minusAddNode + '.output', rangeNode + '.minX') cmds.connectAttr(plusAddNode + '.output', rangeNode + '.maxX') cmds.setAttr(rangeNode + '.oldMinX', 0) cmds.setAttr(rangeNode + '.oldMaxX', range) addMinNode = cmds.createNode('addDoubleLinear') addMaxNode = cmds.createNode('addDoubleLinear') cmds.connectAttr(rangeNode + '.outValueX', addMinNode + '.input1') cmds.connectAttr(rangeNode + '.outValueX', addMaxNode + '.input1') cmds.connectAttr(minusMultNode + '.output', addMinNode + '.input2') cmds.connectAttr(plusMultNode + '.output', addMaxNode + '.input2') minConditionFirst = cmds.createNode('condition') minConditionSecond = cmds.createNode('condition') maxConditionFirst = cmds.createNode('condition') maxConditionSecond = cmds.createNode('condition') cmds.connectAttr(addMinNode + '.output', minConditionFirst + '.firstTerm') cmds.connectAttr(addMinNode + '.output', minConditionFirst + '.colorIfFalseR') cmds.setAttr(minConditionFirst + '.secondTerm', range - 0.0001) cmds.setAttr(minConditionFirst + '.colorIfTrueR', range - 0.0001) cmds.setAttr(minConditionFirst + '.op', 2) cmds.connectAttr(minConditionFirst + '.outColorR', minConditionSecond + '.firstTerm') cmds.connectAttr(minConditionFirst + '.outColorR', minConditionSecond + '.colorIfFalseR') cmds.setAttr(minConditionSecond + '.secondTerm', 0) cmds.setAttr(minConditionSecond + '.colorIfTrueR', 0) cmds.setAttr(minConditionSecond + '.op', 4) cmds.connectAttr(addMaxNode + '.output', maxConditionFirst + '.firstTerm') cmds.connectAttr(addMaxNode + '.output', maxConditionFirst + '.colorIfFalseR') cmds.setAttr(maxConditionFirst + '.secondTerm', range) cmds.setAttr(maxConditionFirst + '.colorIfTrueR', range) cmds.setAttr(maxConditionFirst + '.op', 2) cmds.connectAttr(maxConditionFirst + '.outColorR', maxConditionSecond + '.firstTerm') cmds.connectAttr(maxConditionFirst + '.outColorR', maxConditionSecond + '.colorIfFalseR') cmds.setAttr(maxConditionSecond + '.secondTerm', 0.0001) cmds.setAttr(maxConditionSecond + '.colorIfTrueR', 0.0001) cmds.setAttr(maxConditionSecond + '.op', 4) minMult = cmds.createNode('multDoubleLinear') maxMult = cmds.createNode('multDoubleLinear') cmds.connectAttr(minConditionSecond + '.outColorR', minMult + '.input1') cmds.connectAttr(maxConditionSecond + '.outColorR', maxMult + '.input1') cmds.setAttr(minMult + '.input2', 1.0 / range) cmds.setAttr(maxMult + '.input2', 1.0 / range) cmds.connectAttr(minMult + '.output', detachCurveNode + '.parameter[0]') cmds.connectAttr(maxMult + '.output', detachCurveNode + '.parameter[1]') cmds.select(surfNodeParent)
sgFunctionFileAndPath.makeFile( scenePath, False ) cmds.file( f=1, new=1 ) f = open( bakeInfoPath, 'r' ) bakeTargetList = cPickle.load( f ) f.close() bakeInfoPath = bakeInfoPath.replace( '\\', '/' ) sceneInfoPath = '/'.join( bakeInfoPath.split( '/' )[:-1]) + '/sceneInfo.sceneInfo' f = open( sceneInfoPath, 'r' ) timeUnit, minTime, maxTime = cPickle.load( f ) f.close() cmds.currentUnit( time = timeUnit ) for k in range( len( bakeTargetList ) ): #print "bakeTrargetList : ", bakeTargetList[k] tr = bakeTargetList[k][0] for j in range( len( bakeTargetList[k][3] ) ): attr = bakeTargetList[k][3][j][0] info = bakeTargetList[k][3][j][1] animCurve = info.createAnimCurve() #animCurve = cmds.rename( animCurve, 'sceneBake_animCurve_for_%s' %( tr.split( '|' )[-1]+'_'+attr ) ) sgRigAttribute.addAttr( animCurve, ln='bakeTargetAttrName', dt='string' ) cmds.setAttr( animCurve+'.bakeTargetAttrName', tr+'.'+attr, type='string' ) cmds.file( rename=scenePath ) cmds.file( f=1, save=1, options="v=0;", type="mayaAscii" )