def createCurveFromSelPoints(): import sgBFunction_base import sgBModel_data import sgBFunction_curve import sgBFunction_surface import sgBFunction_mesh import sgBFunction_dag sgBFunction_base.autoLoadPlugin( 'sgRigAddition' ) def getPointAttributeFromObject( obj ): import sgCFnc_dag if obj.find( '.' ) == -1: return None cmds.select( obj ) mDagPath, mIntArrU, mIntArrV, mIntArrW = sgCFnc_dag.getMDagPathAndComponent()[0] dagNode = om.MFnDagNode( mDagPath ) if not len( mIntArrU ): return None nodeName = dagNode.fullPathName() if cmds.nodeType( dagNode.fullPathName() ) == 'nurbsCurve': curveInfo = sgBFunction_curve.getCurveInfo_worldSpace( nodeName ) return curveInfo+'.controlPoints[%d]' % mIntArrU[0] elif cmds.nodeType( nodeName ) == 'nurbsSurface': surfInfo = sgBFunction_surface.getSurfaceInfo_worldSpace( nodeName ) spanV = cmds.getAttr( nodeName + '.spansV' ) degreeV = cmds.getAttr( nodeName + '.degreeV' ) vLength = spanV + degreeV index = mIntArrU[0] * vLength + mIntArrV[0] return surfInfo+'.controlPoints[%d]' % index elif cmds.nodeType( nodeName ) == 'mesh': return sgBFunction_mesh.getPointAttrFromVertex( obj ) def getMatrixAttributeFromObject( obj ): if obj.find( '.' ) != -1: return None cmds.select( obj ) return obj+'.wm' import copy selObjs = copy.copy( sgBModel_data.orderedObjects ) node = cmds.createNode( 'sgCurveFromPoints' ) curve = cmds.createNode( 'nurbsCurve' ) cmds.connectAttr( node+'.outputCurve', curve+'.create' ) cmds.setAttr( node + '.createType', 1 ) cmds.setAttr( node + '.degrees', 2 ) for i in range( len( selObjs ) ): pointAttr = getPointAttributeFromObject( selObjs[i] ) mtxAttr = getMatrixAttributeFromObject( selObjs[i] ) if pointAttr: cmds.connectAttr( pointAttr, node+'.input[%d].inputPoint' % i ) else: cmds.connectAttr( mtxAttr, node+'.input[%d].inputMatrix' % i ) return sgBFunction_dag.getTransform( curve )
def exportSgKeyData( targetTransformNodes, startFrame, endFrame, step, folderPath=None, exportByMatrix=False, *args ): import sgBFunction_scene import copy if step < 0.05: cmds.error( "Step Must be larger then %.f." % step ) sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath() sgBFunction_fileAndPath.makeFolder( folderPath ) sgBFunction_fileAndPath.removeChildFiles( folderPath ) targetTransformNodeParents = [] for transformNode in targetTransformNodes: targetTransformNodeParents += sgBFunction_dag.getParents( transformNode ) targetTransformNodeParents.append( transformNode ) targetTransformNodeParents = list( set( targetTransformNodeParents ) ) sgBFunction_scene.exportTransformData( targetTransformNodeParents, folderPath ) cmds.sgBDataCmd_key( targetTransformNodes, se=1, folderPath= folderPath, ebm=exportByMatrix ) cuTime = copy.copy( startFrame ) while cuTime <= endFrame+1: cmds.currentTime( cuTime ) cmds.sgBDataCmd_key( write=1 ) cuTime += step cmds.sgBDataCmd_key( ee=1 )
def exportAlembicData( prefix, exportTargets, startFrame, endFrame, step, path ): import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'AbcExport' ) sgBFunction_base.autoLoadPlugin( 'AbcImport' ) if prefix: prefix += '_' topTransforms = [] visValues = [] for tr in cmds.ls( tr=1 ): if cmds.listRelatives( tr, p=1 ): continue topTransforms.append( tr ) visValues.append( cmds.getAttr( tr+'.v' ) ) cmds.setAttr( tr+'.v', 0 ) sgBFunction_fileAndPath.makeFolder( path ) for target in exportTargets: target = cmds.ls( target, l=1 )[0] cmds.showHidden( target, a=1 ) targetName = target.split( '|' )[-1] filePath = path + '/' + prefix + targetName.replace( ':', '_' ) + '_s' + str( step ).replace( '.', '_' ) + '.abc' cmds.AbcExport( target, j="-frameRange %s %s -step %s -writeVisibility -uvWrite -dataFormat ogawa -root %s -file %s" %( startFrame, endFrame, step, target, filePath ) ) for tr in topTransforms: cmds.setAttr( tr+'.v', 0 ) for i in range( len( topTransforms ) ): cmds.setAttr( topTransforms[i] + '.v', visValues[i] )
def createSquashObject( distTarget, distBase, scaleTarget ): import sgBFunction_attribute import sgBFunction_base import math scaleTargetMtx = cmds.getAttr( scaleTarget+'.wm' ) xVector = om.MVector( *scaleTargetMtx[0:3] ) yVector = om.MVector( *scaleTargetMtx[4:4+3] ) zVector = om.MVector( *scaleTargetMtx[8:8+3] ) targetPos = cmds.xform( distTarget, q=1, ws=1, t=1 ) basePos = cmds.xform( distBase, q=1, ws=1, t=1 ) aimVector = om.MVector( targetPos[0] - basePos[0], targetPos[1] - basePos[1], targetPos[2] - basePos[2] ) vectors = [ xVector, yVector, zVector ] maxDotValue = 0 aimIndex = 0 for i in range( 3 ): dotValue = math.fabs( aimVector * vectors[i] ) if dotValue > maxDotValue: maxDotValue = dotValue aimIndex = i print "max dot value : ", maxDotValue otherIndex1 = ( aimIndex + 1 ) % 3 otherIndex2 = ( aimIndex + 2 ) % 3 sgBFunction_base.autoLoadPlugin( 'sgLocusChRig' ) mmdc = cmds.createNode( 'multMatrixDecompose' ) cmds.connectAttr( distTarget+'.wm', mmdc+'.i[0]' ) cmds.connectAttr( distBase+'.wim', mmdc+'.i[1]' ) sgBFunction_attribute.addAttr( scaleTarget, ln='distanceDefault', k=1 ) sgBFunction_attribute.addAttr( scaleTarget, ln='distanceCurrent', cb=1 ) sgBFunction_attribute.addAttr( scaleTarget, ln='squashRate', k=1 ) sgBFunction_attribute.addAttr( scaleTarget, ln='forceScale', k=1 ) cmds.connectAttr( mmdc+'.outputDistance', scaleTarget+'.distanceCurrent', f=1 ) cmds.setAttr( scaleTarget+'.distanceDefault', cmds.getAttr( mmdc+'.outputDistance' ) ) squashNode = cmds.createNode( 'squash' ) divNode = cmds.createNode( 'multiplyDivide' ) cmds.setAttr( divNode+'.operation', 2 ) cmds.connectAttr( scaleTarget+'.distanceDefault', squashNode+'.lengthOriginal' ) cmds.connectAttr( scaleTarget+'.distanceCurrent', squashNode+'.lengthModify' ) cmds.connectAttr( scaleTarget+'.distanceDefault', divNode+'.input2X' ) cmds.connectAttr( scaleTarget+'.distanceCurrent', divNode+'.input1X' ) axisChar = ['X', 'Y', 'Z' ] cmds.connectAttr( squashNode+'.output', scaleTarget+'.scale%s' % axisChar[ otherIndex1 ] ) cmds.connectAttr( squashNode+'.output', scaleTarget+'.scale%s' % axisChar[ otherIndex2 ] ) cmds.connectAttr( divNode+'.outputX', scaleTarget+'.scale%s' % axisChar[ aimIndex ] ) cmds.connectAttr( scaleTarget+'.squashRate', squashNode+'.squashRate' ) cmds.connectAttr( scaleTarget+'.forceScale', squashNode+'.forceValue' )
def meshSnap( base, others ): import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'meshSnap' ) for sel in others: cmds.select( base, sel ) cmds.meshSnap()
def createRivetFromVertex(targetVertices, connectMatrix=False): import sgBFunction_base sgBFunction_base.autoLoadPlugin('sgRigAddition') def getNodeFromMesh(mesh, isFirst=True): import sgBFunction_dag if cmds.objectType(mesh) == 'transform': mesh = sgBFunction_dag.getShape(mesh) cons = cmds.listConnections(mesh + '.wm', type='sgMatrixFromVertices') if cons: return cons[0] node = cmds.createNode('sgMatrixFromVertices') cmds.connectAttr(mesh + '.outMesh', node + '.inputMesh') cmds.connectAttr(mesh + '.wm', node + '.inputMeshMatrix') return node import sgCFnc_dag cmds.select(targetVertices) pathAndComps = sgCFnc_dag.getMDagPathAndComponent() for mDagPath, mIntArrU, mIntArrV, mIntArrW in pathAndComps: fnMesh = om.MFnMesh(mDagPath) mesh = fnMesh.name() node = getNodeFromMesh(mesh) if connectMatrix: for i in range(len(mIntArrU)): index = mIntArrU[i] cmds.setAttr(node + '.verticeId[%d]' % index, index) tr = cmds.createNode('transform', n=mesh + '_vtxPoint_%d' % index) mmdc = cmds.createNode('multMatrixDecompose') cmds.setAttr(tr + '.dh', 1) cmds.connectAttr(node + '.outputMatrix[%d]' % index, mmdc + '.i[0]') cmds.connectAttr(tr + '.pim', mmdc + '.i[1]') cmds.connectAttr(mmdc + '.ot', tr + '.t') else: for i in range(len(mIntArrU)): index = mIntArrU[i] cmds.setAttr(node + '.verticeId[%d]' % index, index) tr = cmds.createNode('transform', n=mesh + '_vtxPoint_%d' % index) cmds.setAttr(tr + '.dh', 1) cmds.setAttr(tr + '.inheritsTransform', 0) cmds.connectAttr(node + '.outputTranslate[%d]' % index, tr + '.t')
def exportSgMeshData( targetMesh, filePath=None, *args ): sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not filePath: filePath = sgBFunction_fileAndPath.getDefaultSgMeshDataPath() filePath = filePath.replace( '\\', '/' ) folderPath = '/'.join( filePath.split( '/' )[:-1] ) sgBFunction_fileAndPath.makeFolder( folderPath ) cmds.sgBDataCmd_mesh( targetMesh, em=1, fp=filePath ) print '"%s" export to "%s"' %( targetMesh, filePath )
def exportSgMeshData(targetMesh, filePath=None, *args): sgBFunction_base.autoLoadPlugin("sgBDataCmd") if not filePath: filePath = sgBFunction_fileAndPath.getDefaultSgMeshDataPath() filePath = filePath.replace('\\', '/') folderPath = '/'.join(filePath.split('/')[:-1]) sgBFunction_fileAndPath.makeFolder(folderPath) cmds.sgBDataCmd_mesh(targetMesh, em=1, fp=filePath) print '"%s" export to "%s"' % (targetMesh, filePath)
def setKeyCurve( keyCurve, targetCurve, objBaseMatrix = None ): import sgBFunction_dag import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'sgHair' ) nodes = sgBFunction_dag.getNodeFromHistory( targetCurve, 'sgHair_keyCurve' ) if not nodes: node = cmds.deformer( targetCurve, type= 'sgHair_keyCurve' )[0] cmds.connectAttr( 'time1.outTime', node+'.time' ) if objBaseMatrix: mm = cmds.createNode( 'multMatrix' ) cmds.connectAttr( objBaseMatrix+'.wm', mm+'.i[0]' ) cmds.connectAttr( targetCurve+'.wim', mm+'.i[1]' ) cmds.connectAttr( mm+'.o', node+'.baseLocalMatrix' ) else: node = nodes[0] fnNode = om.MFnDependencyNode( sgBFunction_dag.getMObject( node ) ) cuTime = cmds.currentTime( q=1 ) plugKeys = fnNode.findPlug( 'keys' ) targetIndex = 0 for i in range( plugKeys.numElements() ): plugKey = plugKeys[i] plugFrame = plugKey.child( 0 ) timeValue = plugFrame.asMTime().value() if cuTime == timeValue: targetIndex = plugKey.logicalIndex() break if plugKey.logicalIndex() >= targetIndex: targetIndex = plugKey.logicalIndex() + 1 if objBaseMatrix: import sgBFunction_convert mtxObj = cmds.getAttr( objBaseMatrix+'.wm' ) mtxInvCurve = cmds.getAttr( keyCurve+'.wim' ) mMtxObj = sgBFunction_convert.convertMatrixToMMatrix( mtxObj ) mMtxInvCurve = sgBFunction_convert.convertMatrixToMMatrix( mtxInvCurve ) mMtxLocal = mMtxObj * mMtxInvCurve mtxLocal = sgBFunction_convert.convertMMatrixToMatrix( mMtxLocal ) cmds.setAttr( node+'.keys[%d].baseMatrix' % targetIndex, mtxLocal, type='matrix' ) cmds.setAttr( node+'.keys[%d].keyframe' % targetIndex, cuTime ) keyCurveShape = sgBFunction_dag.getShape( keyCurve ) if not cmds.isConnected( keyCurveShape+'.local', node+'.keys[%d].inputCurve' % targetIndex ): cmds.connectAttr( keyCurveShape+'.local', node+'.keys[%d].inputCurve' % targetIndex, f=1 ) '''
def createRivetFromVertex( targetVertices, connectMatrix=False ): import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'sgRigAddition' ) def getNodeFromMesh( mesh, isFirst=True ): import sgBFunction_dag if cmds.objectType( mesh ) == 'transform': mesh = sgBFunction_dag.getShape( mesh ) cons = cmds.listConnections( mesh+'.wm', type='sgMatrixFromVertices' ) if cons: return cons[0] node = cmds.createNode( 'sgMatrixFromVertices' ) cmds.connectAttr( mesh+'.outMesh', node+'.inputMesh' ) cmds.connectAttr( mesh+'.wm', node+'.inputMeshMatrix' ) return node import sgCFnc_dag cmds.select( targetVertices ) pathAndComps = sgCFnc_dag.getMDagPathAndComponent() for mDagPath, mIntArrU, mIntArrV, mIntArrW in pathAndComps: fnMesh = om.MFnMesh( mDagPath ) mesh = fnMesh.name() node = getNodeFromMesh( mesh ) if connectMatrix: for i in range( len( mIntArrU ) ): index = mIntArrU[i] cmds.setAttr( node+'.verticeId[%d]' % index, index ) tr = cmds.createNode( 'transform', n= mesh+'_vtxPoint_%d' % index ) mmdc = cmds.createNode( 'multMatrixDecompose' ) cmds.setAttr( tr+'.dh', 1 ) cmds.connectAttr( node+'.outputMatrix[%d]' % index, mmdc+'.i[0]' ) cmds.connectAttr( tr+'.pim', mmdc+'.i[1]' ) cmds.connectAttr( mmdc+'.ot', tr+'.t' ) else: for i in range( len( mIntArrU ) ): index = mIntArrU[i] cmds.setAttr( node+'.verticeId[%d]' % index, index ) tr = cmds.createNode( 'transform', n= mesh+'_vtxPoint_%d' % index ) cmds.setAttr( tr+'.dh', 1 ) cmds.setAttr( tr+'.inheritsTransform', 0 ) cmds.connectAttr( node+'.outputTranslate[%d]' % index, tr+'.t' )
def createCurveFromSelVertices(): import sgBModel_data import sgBFunction_base import sgBFunction_dag sgBFunction_base.autoLoadPlugin('sgRigAddition') vertices = sgBModel_data.orderedVertices def getMeshAndIndices(vertices): meshName = sgBFunction_dag.getShape(vertices[0].split('.')[0]) indices = [] for vtx in vertices: vtxName = vtx.split('.')[1] index = int(vtxName.split('[')[-1].replace(']', '')) indices.append(index) return meshName, indices def createCurve(mesh, indices): cons = cmds.listConnections(mesh + '.outMesh', type='sgVerticeToCurve', d=1, s=0) if not cons: vtsToCrv = cmds.createNode('sgVerticeToCurve') cmds.connectAttr(mesh + '.outMesh', vtsToCrv + '.inputMesh') cmds.connectAttr(mesh + '.wm', vtsToCrv + '.inputMeshMatrix') targetIndex = 0 else: vtsToCrv = cons[0] cons = cmds.listConnections(vtsToCrv + '.outputCurve', p=1, c=1) outputs = cons[::2] targetIndex = int(outputs[-1].split('[')[-1].replace(']', '')) + 1 crv = cmds.createNode('nurbsCurve') crvObj = cmds.listRelatives(crv, p=1, f=1)[0] cmds.connectAttr(vtsToCrv + '.outputCurve[%d]' % targetIndex, crv + '.create') cmds.connectAttr(crvObj + '.wim', vtsToCrv + '.input[%d].pim' % targetIndex, f=1) attrs = cmds.ls(vtsToCrv + '.input[%d].verticeIds[*]' % targetIndex) for attr in attrs: cmds.removeMultiInstance(attr) for i in range(len(indices)): if indices[i] == 0: indices[i] = -1 cmds.setAttr( vtsToCrv + '.input[%d].verticeIds[%d]' % (targetIndex, i), indices[i]) mesh, indices = getMeshAndIndices(vertices) createCurve(mesh, indices)
def makeSparateShader( targetObject ): import random import maya.OpenMaya as om import sgBFunction_dag import sgBFunction_base import copy sgBFunction_base.autoLoadPlugin( 'sgMesh' ) cmds.sgGetMeshElementInfo( targetObject, set=1 ) targetShape = sgBFunction_dag.getShape( targetObject ) dagPathShape = sgBFunction_dag.getMDagPath( targetShape ) numElement = cmds.sgGetMeshElementInfo( ne=1 ) numFaces = cmds.sgGetMeshElementInfo( np=1 ) faceIndices = cmds.sgGetMeshElementInfo( fi=1 ) for i in range( numElement ): startFaceIndex = 0 lastFaceIndex = 0 for j in range( i ): startFaceIndex += int( numFaces[j] ) for j in range( i+1 ): lastFaceIndex += int( numFaces[j] ) compArray = om.MIntArray() compArray.setLength( int( numFaces[i] ) ) for j in range( startFaceIndex, lastFaceIndex ): compArray.set( faceIndices[j], j-startFaceIndex ) blinnShader = cmds.shadingNode( 'blinn', asShader=1 ) blinnSet = cmds.sets( renderable=1, noSurfaceShader=1, empty=1, name='blinnSG' ) cmds.connectAttr( blinnShader+'.outColor', blinnSet+'.surfaceShader', f=1 ) colorR = random.uniform( 0, 1 ) colorG = random.uniform( 0, 1 ) colorB = random.uniform( 0, 1 ) cmds.setAttr( blinnShader+'.color', colorR, colorG, colorB, type='double3' ) singleComp = om.MFnSingleIndexedComponent() singleCompObj = singleComp.create( om.MFn.kMeshPolygonComponent ) singleComp.addElements( compArray ) selList = om.MSelectionList() selList.add( dagPathShape, singleCompObj ) om.MGlobal.selectCommand( selList ) cmds.sets( e=1, forceElement=blinnSet )
def importSgMeshDatas( folderPath=None, importByMatrix = True, typ='old', *args ): sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgMeshDataPath() if typ == 'old': import os for root, dirs, names in os.walk( folderPath ): for name in names: extension = name.split( '.' )[-1] if extension != 'sgBData_mesh': continue cmds.sgBDataCmd_mesh( im=1, ibm=importByMatrix, fp=root + '/' + name ) else: cmds.sgBDataCmd_mesh( im=1, ibm=importByMatrix, fdp=folderPath )
def exportSgMeshDatas( targetMeshs, folderPath = None, typ='old', *args ): sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgMeshDataFolder() sgBFunction_fileAndPath.makeFolder( folderPath ) if typ == 'old': print len( targetMeshs ) for targetMesh in targetMeshs: targetMeshName = cmds.ls( targetMesh ) if not targetMeshName: continue filePath = folderPath + '/' + targetMeshName[0].replace( ':', '_' ).replace( '|', '_' ) + '.sgBData_mesh' cmds.sgBDataCmd_mesh( targetMeshName[0], em=1, fp= filePath ) else: cmds.sgBDataCmd_mesh( targetMeshs, em=1, fdp= folderPath )
def importSgKeyData( folderPath, *args ): import sgBFunction_scene import os sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath() sgBFunction_fileAndPath.makeFolder( folderPath ) sgBFunction_scene.importTransformData( folderPath ) for root, dirs, names in os.walk( folderPath ): for name in names: if name.split( '.' )[-1] != 'sgKeyData': continue cmds.sgBDataCmd_key( im=1, fp= root + '/' + name )
def importSgKeyData(folderPath, *args): import sgBFunction_scene import os sgBFunction_base.autoLoadPlugin("sgBDataCmd") if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath() sgBFunction_fileAndPath.makeFolder(folderPath) sgBFunction_scene.importTransformData(folderPath) for root, dirs, names in os.walk(folderPath): for name in names: if name.split('.')[-1] != 'sgKeyData': continue cmds.sgBDataCmd_key(im=1, fp=root + '/' + name)
def importSgMeshDatas(folderPath=None, importByMatrix=True, typ='old', *args): sgBFunction_base.autoLoadPlugin("sgBDataCmd") if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgMeshDataPath() if typ == 'old': import os for root, dirs, names in os.walk(folderPath): for name in names: extension = name.split('.')[-1] if extension != 'sgBData_mesh': continue cmds.sgBDataCmd_mesh(im=1, ibm=importByMatrix, fp=root + '/' + name) else: cmds.sgBDataCmd_mesh(im=1, ibm=importByMatrix, fdp=folderPath)
def exportSgMeshDatas(targetMeshs, folderPath=None, typ='old', *args): sgBFunction_base.autoLoadPlugin("sgBDataCmd") if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgMeshDataFolder() sgBFunction_fileAndPath.makeFolder(folderPath) if typ == 'old': print len(targetMeshs) for targetMesh in targetMeshs: targetMeshName = cmds.ls(targetMesh) if not targetMeshName: continue filePath = folderPath + '/' + targetMeshName[0].replace( ':', '_').replace('|', '_') + '.sgBData_mesh' cmds.sgBDataCmd_mesh(targetMeshName[0], em=1, fp=filePath) else: cmds.sgBDataCmd_mesh(targetMeshs, em=1, fdp=folderPath)
def export(*args): import sgBExcute_data import sgBFunction_fileAndPath import sgBFunction_scene import sgBFunction_base import cPickle sgBFunction_base.autoLoadPlugin('AbcExport') sgBFunction_base.autoLoadPlugin('AbcImport') path = cmds.textField(WinA_Global.exportPath_txf, q=1, tx=1) sgBFunction_fileAndPath.makeFile(WinA_Global.pathInfo, False) f = open(WinA_Global.pathInfo, 'w') cPickle.dump(path, f) f.close() if not os.path.exists(path): try: sgBFunction_fileAndPath.makeFolder(path) except: cmds.error('"%s" is not exist path' % path) return None if not os.path.isdir(path): cmds.error('"%s" is not Directory' % path) return None path = cmds.textField(WinA_Global.exportPath_txf, q=1, tx=1) startFrame = cmds.floatField(WinA_Global.fld_startFrame, q=1, v=1) endFrame = cmds.floatField(WinA_Global.fld_endFrame, q=1, v=1) step = cmds.floatField(WinA_Global.fld_step, q=1, v=1) exportType = WinA_Cmd.getExportType() if exportType == 0: exportTargets = cmds.ls(sl=1) elif exportType == 1: exportTargets = [] for tr in cmds.ls(tr=1): if cmds.listRelatives(tr, p=1): continue exportTargets.append(tr) if not exportTargets: cmds.error('Target is not exists') else: sgBExcute_data.exportAlembicData(sgBFunction_scene.getCutNumber(), exportTargets, startFrame, endFrame, step, path)
def createSgWobbleCurve(crv, editMatrix=1, createNewCurve=True, addName='_'): import sgBFunction_base sgBFunction_base.autoLoadPlugin('sgWobble') crvShape = sgModelDag.getShape(crv) if createNewCurve: srcAttr = crvShape + '.local' targetCrvShape = cmds.createNode('nurbsCurve') targetCrv = cmds.listRelatives(targetCrvShape, p=1, f=1)[0] targetAttr = targetCrvShape + '.create' cmds.xform(targetCrv, ws=1, matrix=cmds.getAttr(crv + '.wm')) else: targetCrv = crv srcAttr = sgModelDag.getSourceCurveAttr(crvShape) targetAttr = crvShape + '.create' sgWobbleCurve = cmds.createNode('sgWobbleCurve2', n='sgWobbleCurve') mmNode = cmds.createNode('multMatrix') cmds.connectAttr(srcAttr, sgWobbleCurve + '.inputCurve') cmds.connectAttr(sgWobbleCurve + '.outputCurve', targetAttr, f=1) cmds.setAttr(sgWobbleCurve + '.fallOff1[1].fallOff1_Position', 1) cmds.setAttr(sgWobbleCurve + '.fallOff1[1].fallOff1_FloatValue', 1) cmds.setAttr(sgWobbleCurve + '.fallOff2[1].fallOff2_Position', 1) cmds.setAttr(sgWobbleCurve + '.fallOff2[1].fallOff2_FloatValue', 1) aimMatrix = cmds.createNode('transform', n='aimMatrix') cmds.connectAttr(aimMatrix + '.wm', mmNode + '.i[0]') cmds.connectAttr(crv + '.wim', mmNode + '.i[1]') cmds.connectAttr(mmNode + '.matrixSum', sgWobbleCurve + '.aimMatrix') cmds.connectAttr('time1.outTime', sgWobbleCurve + '.time') cmds.setAttr(aimMatrix + '.dh', 1) cmds.setAttr(aimMatrix + '.dla', 1) mtx = sgModelCurve.getStartCurveMatrix(targetCrv) cmds.xform(aimMatrix, ws=1, matrix=mtx) sgRigAttribute.createSgWobbleAttribute(targetCrv) try: targetCrv = cmds.rename(targetCrv, crv.split('|')[-1] + addName) except: pass return targetCrv, aimMatrix
def createCurveFromSelVertices(): import sgBModel_data import sgBFunction_base import sgBFunction_dag sgBFunction_base.autoLoadPlugin( 'sgRigAddition' ) vertices = sgBModel_data.orderedVertices def getMeshAndIndices( vertices ): meshName = sgBFunction_dag.getShape( vertices[0].split( '.' )[0] ) indices = [] for vtx in vertices: vtxName = vtx.split( '.' )[1] index = int( vtxName.split( '[' )[-1].replace( ']', '' ) ) indices.append( index ) return meshName, indices def createCurve( mesh, indices ): cons = cmds.listConnections( mesh+'.outMesh', type='sgVerticeToCurve', d=1, s=0 ) if not cons: vtsToCrv = cmds.createNode( 'sgVerticeToCurve' ) cmds.connectAttr( mesh+'.outMesh', vtsToCrv+'.inputMesh' ) cmds.connectAttr( mesh+'.wm', vtsToCrv+'.inputMeshMatrix' ) targetIndex = 0 else: vtsToCrv = cons[0] cons = cmds.listConnections( vtsToCrv+'.outputCurve', p=1, c=1 ) outputs = cons[::2] targetIndex = int( outputs[-1].split( '[' )[-1].replace( ']', '' ) ) + 1 crv = cmds.createNode( 'nurbsCurve' ) crvObj = cmds.listRelatives( crv, p=1, f=1 )[0] cmds.connectAttr( vtsToCrv+'.outputCurve[%d]' % targetIndex, crv+'.create' ) cmds.connectAttr( crvObj+'.wim', vtsToCrv+'.input[%d].pim' % targetIndex, f=1 ) attrs = cmds.ls( vtsToCrv+'.input[%d].verticeIds[*]' % targetIndex ) for attr in attrs: cmds.removeMultiInstance( attr ) for i in range( len( indices ) ): if indices[i] == 0: indices[i] = -1 cmds.setAttr( vtsToCrv+'.input[%d].verticeIds[%d]' % (targetIndex,i), indices[i] ) mesh, indices = getMeshAndIndices( vertices ) createCurve( mesh, indices )
def createSgWobbleCurve( crv, editMatrix=1, createNewCurve=True, addName = '_' ): import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'sgWobble' ) crvShape = sgModelDag.getShape( crv ) if createNewCurve: srcAttr = crvShape+'.local' targetCrvShape = cmds.createNode( 'nurbsCurve' ) targetCrv = cmds.listRelatives( targetCrvShape, p=1, f=1 )[0] targetAttr = targetCrvShape+'.create' cmds.xform( targetCrv, ws=1, matrix= cmds.getAttr( crv+'.wm' ) ) else: targetCrv = crv srcAttr = sgModelDag.getSourceCurveAttr( crvShape ) targetAttr = crvShape+'.create' sgWobbleCurve = cmds.createNode( 'sgWobbleCurve2', n='sgWobbleCurve' ) mmNode = cmds.createNode( 'multMatrix' ) cmds.connectAttr( srcAttr, sgWobbleCurve+'.inputCurve' ) cmds.connectAttr( sgWobbleCurve+'.outputCurve', targetAttr, f=1 ) cmds.setAttr( sgWobbleCurve+'.fallOff1[1].fallOff1_Position', 1 ) cmds.setAttr( sgWobbleCurve+'.fallOff1[1].fallOff1_FloatValue', 1 ) cmds.setAttr( sgWobbleCurve+'.fallOff2[1].fallOff2_Position', 1 ) cmds.setAttr( sgWobbleCurve+'.fallOff2[1].fallOff2_FloatValue', 1 ) aimMatrix = cmds.createNode( 'transform', n='aimMatrix' ) cmds.connectAttr( aimMatrix+'.wm', mmNode+'.i[0]' ) cmds.connectAttr( crv+'.wim', mmNode+'.i[1]' ) cmds.connectAttr( mmNode+'.matrixSum', sgWobbleCurve+'.aimMatrix' ) cmds.connectAttr( 'time1.outTime', sgWobbleCurve+'.time') cmds.setAttr( aimMatrix+'.dh',1 ) cmds.setAttr( aimMatrix+'.dla', 1 ) mtx = sgModelCurve.getStartCurveMatrix( targetCrv ) cmds.xform( aimMatrix, ws=1, matrix=mtx ) sgRigAttribute.createSgWobbleAttribute( targetCrv ) try:targetCrv = cmds.rename( targetCrv, crv.split( '|' )[-1]+addName) except: pass return targetCrv, aimMatrix
def export( *args ): import sgBExcute_data import sgBFunction_fileAndPath import sgBFunction_scene import sgBFunction_base import cPickle sgBFunction_base.autoLoadPlugin( 'AbcExport' ) sgBFunction_base.autoLoadPlugin( 'AbcImport' ) path = cmds.textField( WinA_Global.exportPath_txf, q=1, tx=1 ) sgBFunction_fileAndPath.makeFile( WinA_Global.pathInfo, False ) f = open( WinA_Global.pathInfo, 'w' ) cPickle.dump( path, f ) f.close() if not os.path.exists( path ): try: sgBFunction_fileAndPath.makeFolder( path ) except: cmds.error( '"%s" is not exist path' % path ) return None if not os.path.isdir( path ): cmds.error( '"%s" is not Directory' % path ) return None path = cmds.textField( WinA_Global.exportPath_txf, q=1, tx=1 ) startFrame = cmds.floatField( WinA_Global.fld_startFrame, q=1, v=1 ) endFrame = cmds.floatField( WinA_Global.fld_endFrame, q=1, v=1 ) step = cmds.floatField( WinA_Global.fld_step, q=1, v=1 ) exportType = WinA_Cmd.getExportType() if exportType == 0: exportTargets = cmds.ls( sl=1 ) elif exportType == 1: exportTargets = [] for tr in cmds.ls( tr=1 ): if cmds.listRelatives( tr, p=1 ): continue exportTargets.append( tr ) if not exportTargets: cmds.error( 'Target is not exists' ) else: sgBExcute_data.exportAlembicData( sgBFunction_scene.getCutNumber(), exportTargets, startFrame, endFrame, step, path )
def exportSgKeyData(targetTransformNodes, startFrame, endFrame, step, folderPath=None, exportByMatrix=False, *args): import sgBFunction_scene import copy if step < 0.05: cmds.error("Step Must be larger then %.f." % step) sgBFunction_base.autoLoadPlugin("sgBDataCmd") if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath() sgBFunction_fileAndPath.makeFolder(folderPath) sgBFunction_fileAndPath.removeChildFiles(folderPath) targetTransformNodeParents = [] for transformNode in targetTransformNodes: targetTransformNodeParents += sgBFunction_dag.getParents(transformNode) targetTransformNodeParents.append(transformNode) targetTransformNodeParents = list(set(targetTransformNodeParents)) sgBFunction_scene.exportTransformData(targetTransformNodeParents, folderPath) cmds.sgBDataCmd_key(targetTransformNodes, se=1, folderPath=folderPath, ebm=exportByMatrix) cuTime = copy.copy(startFrame) while cuTime <= endFrame + 1: cmds.currentTime(cuTime) cmds.sgBDataCmd_key(write=1) cuTime += step cmds.sgBDataCmd_key(ee=1)
def exportKeyAndCacheData( keyTransformNodes, cacheTransformNodes, keyFolderPath, cacheFolderPath, startFrame, endFrame, step, exportByMatrix=False, exportType='mcc', *args ): import maya.mel as mel import sgBFunction_selection import maya.OpenMaya as om import sgBFunction_scene sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) keyFolderPath = keyFolderPath.replace( '\\', '/' ) cacheFolderPath = cacheFolderPath.replace( '\\', '/' ) def exportKeyEachFrame( *args ): cmds.sgBDataCmd_key( write=1 ) connectedTransforms = sgBFunction_selection.getTransformConnectedObjectsFromGroup( keyTransformNodes ) deformedTransforms = sgBFunction_selection.getDeformedObjectsFromGroup( cacheTransformNodes ) if deformedTransforms and connectedTransforms: sgBFunction_fileAndPath.makeFolder( keyFolderPath ) sgBFunction_fileAndPath.makeFolder( cacheFolderPath ) targetTransformNodeParents = [] for transformNode in connectedTransforms: targetTransformNodeParents += sgBFunction_dag.getParents( transformNode ) targetTransformNodeParents.append( transformNode ) targetTransformNodeParents = list( set( targetTransformNodeParents ) ) sgBFunction_scene.exportTransformData( targetTransformNodeParents, keyFolderPath ) cmds.sgBDataCmd_key( connectedTransforms, se=1, folderPath= keyFolderPath, ebm=exportByMatrix ) callbackId = om.MEventMessage().addEventCallback( 'timeChanged', exportKeyEachFrame ) cmds.select( deformedTransforms ) mel.eval( 'doCreateGeometryCache 6 { "3", "%s", "%s", "OneFile", "1", "%s","1","","0", "export", "0", "%s", "1","0","0","%s","0" };' %( startFrame, endFrame, cacheFolderPath, step, exportType ) ) om.MMessage().removeCallback( callbackId ) cmds.sgBDataCmd_key( ee=1 ) elif deformedTransforms and not connectedTransforms: exportCacheData( deformedTransforms, startFrame, endFrame, step, cacheFolderPath, exportType ) elif not deformedTransforms and connectedTransforms: exportSgKeyData( connectedTransforms, startFrame, endFrame, step, keyFolderPath, exportByMatrix )
def importSgUVData( targetMesh, filePath=None, *args ): sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not filePath: filePath = sgBFunction_fileAndPath.getDefaultSgUVDataPath() targetMesh = sgBFunction_dag.getShape( targetMesh ) targetMeshOrig = sgBFunction_dag.getOrigShape( targetMesh ) targetMeshOrigSrcCon = cmds.listConnections( targetMeshOrig+'.inMesh', p=1, c=1, s=1, d=0 ) if targetMeshOrigSrcCon: cmds.disconnectAttr( targetMeshOrigSrcCon[1], targetMeshOrigSrcCon[0] ) cmds.warning( '"%s" to "%s" are disconnected.' %( targetMeshOrigSrcCon[1], targetMeshOrigSrcCon[0] ) ) cmds.sgBDataCmd_mesh( targetMeshOrig, iuv=1, fp=filePath ) print targetMeshOrig cons = cmds.listConnections( targetMesh+'.inMesh', s=1, d=0, p=1, c=1 ) if not cons: return targetMeshOrig cmds.disconnectAttr( cons[1], cons[0] ) cmds.refresh() cmds.connectAttr( cons[1], cons[0] ) return targetMeshOrig
def makeUvFiles(): import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'sgBDataCmd' ) import sgBModel_fileAndPath import sgBFunction_fileAndPath scenePath = cmds.file( q=1, sceneName=1 ) cmds.file( scenePath, f=1, options="v=0;", ignoreVersion=True ) folderPath = '/'.join( scenePath.split( '/' )[:-1] ) uvPath = folderPath + '/' + sgBModel_fileAndPath.cacheBodyUvFolderName sgBFunction_fileAndPath.makeFolder( uvPath ) meshs = cmds.ls( type='mesh' ) for mesh in meshs: if cmds.getAttr( mesh+'.io' ): continue meshName = mesh.replace( '|', '_' ).replace( ':', '_' ) uvFilePath = uvPath + '/' + meshName + '.sgBData_uvs' cmds.sgBDataCmd_mesh( mesh, euv=1, filePath = uvFilePath )
def importAlembicData( prefix, filePath ): import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'AbcExport' ) beforeTopNodes = sgBFunction_dag.getTopTransformNodes() cmds.AbcImport( filePath, mode='import' ) afterTopNodes = sgBFunction_dag.getTopTransformNodes() fnTargets = [] for afterTopNode in afterTopNodes: if afterTopNode in beforeTopNodes: continue children = cmds.listRelatives( afterTopNode, c=1, ad=1, f=1, type='transform' ) if not children: children = [] children.append( afterTopNode ) for child in children: fnTarget = om.MFnTransform( sgBFunction_dag.getMDagPath( child ) ) fnTargets.append( fnTarget ) for target in fnTargets: targetName = target.name() fullName = target.fullPathName() cmds.rename( fullName, prefix + targetName )
def exportAlembicData(prefix, exportTargets, startFrame, endFrame, step, path): import sgBFunction_base sgBFunction_base.autoLoadPlugin('AbcExport') sgBFunction_base.autoLoadPlugin('AbcImport') if prefix: prefix += '_' topTransforms = [] visValues = [] for tr in cmds.ls(tr=1): if cmds.listRelatives(tr, p=1): continue topTransforms.append(tr) visValues.append(cmds.getAttr(tr + '.v')) cmds.setAttr(tr + '.v', 0) sgBFunction_fileAndPath.makeFolder(path) for target in exportTargets: target = cmds.ls(target, l=1)[0] cmds.showHidden(target, a=1) targetName = target.split('|')[-1] filePath = path + '/' + prefix + targetName.replace( ':', '_') + '_s' + str(step).replace('.', '_') + '.abc' cmds.AbcExport( target, j="-frameRange %s %s -step %s -writeVisibility -uvWrite -dataFormat ogawa -root %s -file %s" % (startFrame, endFrame, step, target, filePath)) for tr in topTransforms: cmds.setAttr(tr + '.v', 0) for i in range(len(topTransforms)): cmds.setAttr(topTransforms[i] + '.v', visValues[i])
def exportKeyAndCacheData(keyTransformNodes, cacheTransformNodes, keyFolderPath, cacheFolderPath, startFrame, endFrame, step, exportByMatrix=False, exportType='mcc', *args): import maya.mel as mel import sgBFunction_selection import maya.OpenMaya as om import sgBFunction_scene sgBFunction_base.autoLoadPlugin("sgBDataCmd") keyFolderPath = keyFolderPath.replace('\\', '/') cacheFolderPath = cacheFolderPath.replace('\\', '/') def exportKeyEachFrame(*args): cmds.sgBDataCmd_key(write=1) connectedTransforms = sgBFunction_selection.getTransformConnectedObjectsFromGroup( keyTransformNodes) deformedTransforms = sgBFunction_selection.getDeformedObjectsFromGroup( cacheTransformNodes) if deformedTransforms and connectedTransforms: sgBFunction_fileAndPath.makeFolder(keyFolderPath) sgBFunction_fileAndPath.makeFolder(cacheFolderPath) targetTransformNodeParents = [] for transformNode in connectedTransforms: targetTransformNodeParents += sgBFunction_dag.getParents( transformNode) targetTransformNodeParents.append(transformNode) targetTransformNodeParents = list(set(targetTransformNodeParents)) sgBFunction_scene.exportTransformData(targetTransformNodeParents, keyFolderPath) cmds.sgBDataCmd_key(connectedTransforms, se=1, folderPath=keyFolderPath, ebm=exportByMatrix) callbackId = om.MEventMessage().addEventCallback( 'timeChanged', exportKeyEachFrame) cmds.select(deformedTransforms) mel.eval( 'doCreateGeometryCache 6 { "3", "%s", "%s", "OneFile", "1", "%s","1","","0", "export", "0", "%s", "1","0","0","%s","0" };' % (startFrame, endFrame, cacheFolderPath, step, exportType)) om.MMessage().removeCallback(callbackId) cmds.sgBDataCmd_key(ee=1) elif deformedTransforms and not connectedTransforms: exportCacheData(deformedTransforms, startFrame, endFrame, step, cacheFolderPath, exportType) elif not deformedTransforms and connectedTransforms: exportSgKeyData(connectedTransforms, startFrame, endFrame, step, keyFolderPath, exportByMatrix)
def createRivetFromVertex_mirror(rivetObj): import sgBFunction_dag import sgBFunction_base import sgBFunction_convert sgBFunction_base.autoLoadPlugin('sgRigAddition') def getNodeFromMesh(mesh, isFirst=True): if cmds.objectType(mesh) == 'transform': mesh = sgBFunction_dag.getShape(mesh) cons = cmds.listConnections(mesh + '.wm', type='sgMatrixFromVertices') if cons: return cons[0] node = cmds.createNode('sgMatrixFromVertices') cmds.connectAttr(mesh + '.outMesh', node + '.inputMesh') cmds.connectAttr(mesh + '.wm', node + '.inputMeshMatrix') return node cons = cmds.listConnections(rivetObj, s=1, d=0, type='sgMatrixFromVertices', p=1, c=1) if not cons: return None node, attr = cons[1].split('.') vtxNum = int(attr.split('[')[1].replace(']', '')) mesh = cmds.listConnections(node, s=1, d=0, type='mesh', shapes=1) if not mesh: return None mesh = mesh[0] fnMesh = om.MFnMesh(sgBFunction_dag.getMDagPath(mesh)) intersector = om.MMeshIntersector() intersector.create(fnMesh.object()) pointArr = om.MPointArray() fnMesh.getPoints(pointArr) pointMirror = om.MPoint(-pointArr[vtxNum].x, pointArr[vtxNum].y, pointArr[vtxNum].z) pointOnMesh = om.MPointOnMesh() intersector.getClosestPoint(pointMirror, pointOnMesh) faceIndex = pointOnMesh.faceIndex() vertices = om.MIntArray() fnMesh.getPolygonVertices(faceIndex, vertices) closeIndex = 0 closeDist = 1000000.0 for i in range(vertices.length()): dist = pointArr[vertices[i]].distanceTo(pointMirror) if closeDist > dist: closeDist = dist closeIndex = vertices[i] cmds.setAttr(node + '.verticeId[%d]' % closeIndex, closeIndex) rivetObjName = rivetObj.split('|')[-1] rivetObjName = rivetObjName.replace(str(vtxNum), str(closeIndex)) newObject = cmds.createNode( 'transform', n=sgBFunction_convert.convertSide(rivetObjName)) cmds.setAttr(newObject + '.dh', 1) cmds.setAttr(newObject + '.inheritsTransform', 0) cmds.connectAttr(node + '.outputTranslate[%d]' % closeIndex, newObject + '.t')
def importSgMeshData( filePath=None, skipByName = False, *args ): sgBFunction_base.autoLoadPlugin( "sgBDataCmd" ) if not filePath: filePath = sgBFunction_fileAndPath.getDefaultSgMeshDataPath() cmds.sgBDataCmd_mesh( im=1, fp=filePath )
def importSgMeshData(filePath=None, skipByName=False, *args): sgBFunction_base.autoLoadPlugin("sgBDataCmd") if not filePath: filePath = sgBFunction_fileAndPath.getDefaultSgMeshDataPath() cmds.sgBDataCmd_mesh(im=1, fp=filePath)
def createInCurve(surface, numCurve, paramRand=0.3, offsetRand=0.15, centerOffset=0.5): import random import sgBFunction_dag import sgBFunction_base sgBFunction_base.autoLoadPlugin("HSBVC.mll") node = cmds.createNode('volumeCurvesOnSurface') cmds.connectAttr(surface + '.wm', node + '.inputMatrix') surfaceShape = sgBFunction_dag.getShape(surface) cmds.connectAttr(surfaceShape + '.local', node + '.inputSurface') minValue, maxValue = cmds.getAttr(surfaceShape + '.minMaxRangeV')[0] if numCurve in [1, 2, 3]: paramRate = (maxValue - minValue) / numCurve else: paramRate = (maxValue - minValue) / (numCurve - 1) outputCurves = cmds.listConnections(node + '.outputCurve') if outputCurves: lenOutputCurves = len(outputCurves) if lenOutputCurves > numCurve: cmds.delete(outputCurves[numCurve - lenOutputCurves:]) if not numCurve: return None curves = [] for i in range(numCurve): addOffsetParam = random.uniform(-paramRate / 2 * paramRand, paramRate / 2 * paramRand) addOffsetCenter = random.uniform(-offsetRand, offsetRand) outputCurveCon = cmds.listConnections(node + '.outputCurve[%d]' % i) if not outputCurveCon: crvNode = cmds.createNode('nurbsCurve') crvObj = cmds.listRelatives(crvNode, p=1)[0] cmds.connectAttr(node + '.outputCurve[%d]' % i, crvNode + '.create') cmds.addAttr(crvObj, ln='paramRate', dv=paramRate * i + addOffsetParam + paramRate * 0.5) cmds.setAttr(crvObj + '.paramRate', e=1, k=1) cmds.addAttr(crvObj, ln='centerRate', dv=centerOffset + addOffsetCenter) cmds.setAttr(crvObj + '.centerRate', e=1, k=1) cmds.connectAttr(crvObj + '.paramRate', node + '.curveInfo[%d].paramRate' % i) cmds.connectAttr(crvObj + '.centerRate', node + '.curveInfo[%d].centerRate' % i) else: crvObj = outputCurveCon[0] cmds.setAttr(crvObj + '.paramRate', paramRate * i + addOffsetParam + paramRate * 0.5) cmds.setAttr(crvObj + '.centerRate', centerOffset + addOffsetCenter) crvObj = cmds.rename(crvObj, surface + '_curve_%d' % i) curves.append(crvObj) if i == numCurve - 1: if not numCurve in [2, 3]: cmds.setAttr(crvObj + '.centerRate', 0) outputLen = numCurve for i in range(outputLen): outputCons = cmds.listConnections(node + '.outputCurve[%d]' % i) if not outputCons: cmds.removeMultiInstance('%s[%d]' % (node + '.outputCurve', i)) cmds.removeMultiInstance('%s[%d]' % (node + '.curveInfo', i)) return curves
def doBake( cameraPath, minFrame, maxFrame, maya=True, mb = True, fbx=True ): import os, time, socket import sgBFunction_dag import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'fbxmaya' ) removeUnknown() cameraPath = cameraPath.replace( '\\', '/' ) ##_ex_Atts = ["renderable"] _attrs = ["horizontalFilmAperture", "verticalFilmAperture", "focalLength", "lensSqueezeRatio", "fStop", "focusDistance", "shutterAngle", "centerOfInterest", "nearClipPlane", "farClipPlane", "filmFit", "filmFitOffset", "horizontalFilmOffset", "verticalFilmOffset", "shakeEnabled", "horizontalShake", "verticalShake", "shakeOverscanEnabled", "shakeOverscan", "preScale", "filmTranslateH", "filmTranslateV", "horizontalRollPivot", "verticalRollPivot", "filmRollValue", "filmRollOrder", "postScale", "depthOfField", "focusRegionScale"] if not (maya or fbx): print "AAA" return if not cmds.ls(sl=1): print "BBB" return sels = cmds.ls(sl=1) src = None src_sh = None for sel in sels: selShape = sgBFunction_dag.getShape( sel ) if cmds.nodeType( selShape ) == 'camera': src = sel src_sh = selShape if not src_sh: cmds.error( "No Camera Selected") if not (cmds.nodeType(src_sh) == "camera"): return trg = cmds.camera()[0] unit = cmds.currentUnit( q=1, time=1 ) unitDict = { 'game':15, 'film':24, 'pal':25, 'ntsc':30, 'show':48, 'palf':50, 'ntscf':60 } camName = cameraPath.split( '/' )[-1] camName += '_%d_%d_%df_bake' %( minFrame, maxFrame, unitDict[ unit ] ) trg = cmds.rename( trg, camName ) trg_sh = cmds.listRelatives(trg, s=True, f=True)[0] ##for at in cmds.listAttr(src_sh): for at in _attrs: ##if at in _ex_Atts: continue try: ##cmds.setAttr("%s.%s" % (src_sh, at), k=1) cmds.setAttr("%s.%s" % (trg_sh, at), k=1) cmds.setAttr("%s.%s" % (trg_sh, at), cmds.getAttr("%s.%s" % (src_sh, at))) cmds.connectAttr("%s.%s" % (src_sh, at), "%s.%s" % (trg_sh, at), f=1) except: pass cmds.pointConstraint(src, trg, offset=[0,0,0], weight=1) cmds.orientConstraint(src, trg, offset=[0,0,0], weight=1) cmds.setAttr(trg + ".rotateAxisX", cmds.getAttr(src + ".rotateAxisX")) cmds.setAttr(trg + ".rotateAxisY", cmds.getAttr(src + ".rotateAxisY")) cmds.setAttr(trg + ".rotateAxisZ", cmds.getAttr(src + ".rotateAxisZ")) cmds.refresh(suspend=True) try: cmds.bakeResults(trg, sm=True, t=(minFrame, maxFrame), sb=1, dic=True, pok=True, sac=False, removeBakedAttributeFromLayer=False, bakeOnOverrideLayer=False, cp=False, s=True) finally: cmds.refresh(suspend=False) cmds.refresh() cmds.delete(trg, constraints=1) try: a = cmds.listConnections(src_sh, s=0, d=1, c=1, p=1, scn=1, sh=1)[::2] b = cmds.listConnections(src_sh, s=0, d=1, c=1, p=1, scn=1, sh=1)[1::2] for i in range(len(a)): cmds.disconnectAttr(a[i], b[i]) except: pass outFN = cameraPath rntN = cmds.fileDialog2(fm=0, dir=outFN) if not rntN: return rntFN = os.path.splitext(rntN[0])[0] if maya: cmds.file(rntFN, force=1, options="v=0;", typ="mayaAscii", pr=1, es=1) if mb: cmds.file(rntFN, force=1, options="v=0;", typ="mayaBinary", pr=1, es=1) if fbx: cmds.file(rntFN, force=1, options="v=0;", typ="FBX export", pr=1, es=1) #print rnt ##setClipboardData(rnt) def showExportCamera(): if cmds.window("exportCamera", ex=1): cmds.deleteUI("exportCamera") cmds.window("exportCamera") cmds.columnLayout( adjustableColumn=True ) cmds.rowColumnLayout(numberOfColumns=2, columnWidth=[(1, 100), (2, 100)] ) mayaCB = cmds.checkBox(l="Maya", v=True) fbxCB = cmds.checkBox(l="FBX", v=True) cmds.setParent("..") #cmds.button(l="Tear off", c=lambda x:tearOffPanel()) cmds.button(l="Export", c=lambda x:doBake(cmds.checkBox(mayaCB, q=1, v=1), cmds.checkBox(fbxCB, q=1, v=1))) cmds.showWindow() showExportCamera()
def tool_curveEditBrush(): import sgBFunction_base import maya.cmds as cmds import maya.mel as mel sgBFunction_base.autoLoadPlugin( 'sgTools' ) melScript = ''' proc int isGreasePencilContext() // // Description: // Returns true if this is Grease Pencil context. // { string $tc = currentToolClass(); return ($tc == "greasePencil"); } global proc artActivateScreenSlider( string $sliderName ) // // Description: // Global procs for activating screen sliders // - sets the flag to activate them. // { // New Artisan Tools. if ( isArtisanCtx() ) { string $artisanCmd = artisanCommand(); if( $sliderName == "upper_radius" ) { artBaseCtx -e -dragSlider "radius" `currentCtx`; } else if( $sliderName == "lower_radius" ) { artBaseCtx -e -dragSlider "lowradius" `currentCtx`; } else if( $sliderName == "opacity" ) { artBaseCtx -e -dragSlider "opacity" `currentCtx`; } else if( $sliderName == "value" ) { artBaseCtx -e -dragSlider "value" `currentCtx`; } else if( $sliderName == "stamp_depth" ) { artBaseCtx -e -dragSlider "depth" `currentCtx`; } else if( $sliderName == "displacement" ) { artBaseCtx -e -dragSlider "displacement" `currentCtx`; } else if( $sliderName == "uv_vector" ) { artBaseCtx -e -dragSlider "uvvector" `currentCtx`; } } else if ( isGreasePencilContext() ) { if( $sliderName == "upper_radius" ) { // Map B to radius artBaseCtx -e -dragSlider "radius" greasePencilContext; } else if( $sliderName == "displacement" ) { // Map m to opacity rather than value but not for the eraser // as this has no effect if ( 4 != `greasePencilCtx -query -greasePencilType greasePencilContext` ) { artBaseCtx -e -dragSlider "opacity" greasePencilContext; } } } // UV Smudge Tool else if ( isSmudgeCtx() ) { texSmudgeUVContext -edit -dragSlider "radius" texSmudgeUVCtx; } // Soft Mod else if ( size( getActiveSoftMod() ) > 0 ) { string $ctx = `currentCtx`; if( `contextInfo -c $ctx` != "softMod" ) $ctx = "softModContext"; softModCtx -e -dragSlider "radius" $ctx; } // Paint Effects. else if ((`isTrue "MayaCreatorExists"`) && isDynPaint()) { if( $sliderName == "displacement" ) { dynPaintResize("offset"); } else if( $sliderName == "lower_radius" ) { dynPaintResize("width"); } else { dynPaintResize("size"); } } else if ($sliderName == "upper_radius") { // upper_radius is the "b" key by default. We only want to use that one // for soft select. The "n" and "m" keys can also come in here so we want // to filter those out. global string $gSoftSelectOptionsCtx; softSelectOptionsCtx -edit -buttonDown $gSoftSelectOptionsCtx; if( `currentCtx` == "sgCurveEditBrushContext1" ) { sgCurveEditBrushContext -e -radiusEditOn 1 sgCurveEditBrushContext1; } } } global proc artDeactivateScreenSlider() // // Description: // Global procs for deactivating screen sliders - sets the flag to // deactivate them. // { // New Artisan Tools. if ( isArtisanCtx() ) { artBaseCtx -e -dragSlider "none" `currentCtx`; } else if ( isGreasePencilContext() ) { artBaseCtx -e -dragSlider "none" greasePencilContext; } // UV Smudge else if ( isSmudgeCtx() ) { texSmudgeUVContext -e -dragSlider "none" texSmudgeUVCtx; } // Soft Mod else if ( size( getActiveSoftMod() ) > 0 ) { string $ctx = `currentCtx`; if( `contextInfo -c $ctx` != "softMod" ) $ctx = "softModContext"; softModCtx -e -dragSlider "none" $ctx; } // Paint Effects. else if (`isTrue "MayaCreatorExists"` && isDynPaint()) { dynPaintResize("none"); } else { // We filter out the "n" and "m" keys in the activate call // but don't here because there isn't a slider name passed // in for deactivate. To soft select context is smart // enough to know that it didn't start and edit so we are // ok to just call this in case we did. global string $gSoftSelectOptionsCtx; softSelectOptionsCtx -edit -buttonUp $gSoftSelectOptionsCtx; } if( `currentCtx` == "sgCurveEditBrushContext1" ) { sgCurveEditBrushContext -e -radiusEditOn 0 sgCurveEditBrushContext1; } } global proc sgCurveEditBrush_contextProperties() { } global proc sgCurveEditBrush_contextValues( string $context ) { } ''' mel.eval( melScript ) import sgBFunction_dag sels = sgBFunction_dag.getChildrenCurveExists( cmds.ls( sl=1 ) ) cmds.select( sels ) if not cmds.contextInfo( "sgCurveEditBrushContext1", ex=1 ): mel.eval( 'sgCurveEditBrushContext sgCurveEditBrushContext1' ) cmds.setToolTo( "sgCurveEditBrushContext1" )
def tool_curveEditBrush(): import sgBFunction_base import maya.cmds as cmds import maya.mel as mel sgBFunction_base.autoLoadPlugin('sgTools') melScript = ''' proc int isGreasePencilContext() // // Description: // Returns true if this is Grease Pencil context. // { string $tc = currentToolClass(); return ($tc == "greasePencil"); } global proc artActivateScreenSlider( string $sliderName ) // // Description: // Global procs for activating screen sliders // - sets the flag to activate them. // { // New Artisan Tools. if ( isArtisanCtx() ) { string $artisanCmd = artisanCommand(); if( $sliderName == "upper_radius" ) { artBaseCtx -e -dragSlider "radius" `currentCtx`; } else if( $sliderName == "lower_radius" ) { artBaseCtx -e -dragSlider "lowradius" `currentCtx`; } else if( $sliderName == "opacity" ) { artBaseCtx -e -dragSlider "opacity" `currentCtx`; } else if( $sliderName == "value" ) { artBaseCtx -e -dragSlider "value" `currentCtx`; } else if( $sliderName == "stamp_depth" ) { artBaseCtx -e -dragSlider "depth" `currentCtx`; } else if( $sliderName == "displacement" ) { artBaseCtx -e -dragSlider "displacement" `currentCtx`; } else if( $sliderName == "uv_vector" ) { artBaseCtx -e -dragSlider "uvvector" `currentCtx`; } } else if ( isGreasePencilContext() ) { if( $sliderName == "upper_radius" ) { // Map B to radius artBaseCtx -e -dragSlider "radius" greasePencilContext; } else if( $sliderName == "displacement" ) { // Map m to opacity rather than value but not for the eraser // as this has no effect if ( 4 != `greasePencilCtx -query -greasePencilType greasePencilContext` ) { artBaseCtx -e -dragSlider "opacity" greasePencilContext; } } } // UV Smudge Tool else if ( isSmudgeCtx() ) { texSmudgeUVContext -edit -dragSlider "radius" texSmudgeUVCtx; } // Soft Mod else if ( size( getActiveSoftMod() ) > 0 ) { string $ctx = `currentCtx`; if( `contextInfo -c $ctx` != "softMod" ) $ctx = "softModContext"; softModCtx -e -dragSlider "radius" $ctx; } // Paint Effects. else if ((`isTrue "MayaCreatorExists"`) && isDynPaint()) { if( $sliderName == "displacement" ) { dynPaintResize("offset"); } else if( $sliderName == "lower_radius" ) { dynPaintResize("width"); } else { dynPaintResize("size"); } } else if ($sliderName == "upper_radius") { // upper_radius is the "b" key by default. We only want to use that one // for soft select. The "n" and "m" keys can also come in here so we want // to filter those out. global string $gSoftSelectOptionsCtx; softSelectOptionsCtx -edit -buttonDown $gSoftSelectOptionsCtx; if( `currentCtx` == "sgCurveEditBrushContext1" ) { sgCurveEditBrushContext -e -radiusEditOn 1 sgCurveEditBrushContext1; } } } global proc artDeactivateScreenSlider() // // Description: // Global procs for deactivating screen sliders - sets the flag to // deactivate them. // { // New Artisan Tools. if ( isArtisanCtx() ) { artBaseCtx -e -dragSlider "none" `currentCtx`; } else if ( isGreasePencilContext() ) { artBaseCtx -e -dragSlider "none" greasePencilContext; } // UV Smudge else if ( isSmudgeCtx() ) { texSmudgeUVContext -e -dragSlider "none" texSmudgeUVCtx; } // Soft Mod else if ( size( getActiveSoftMod() ) > 0 ) { string $ctx = `currentCtx`; if( `contextInfo -c $ctx` != "softMod" ) $ctx = "softModContext"; softModCtx -e -dragSlider "none" $ctx; } // Paint Effects. else if (`isTrue "MayaCreatorExists"` && isDynPaint()) { dynPaintResize("none"); } else { // We filter out the "n" and "m" keys in the activate call // but don't here because there isn't a slider name passed // in for deactivate. To soft select context is smart // enough to know that it didn't start and edit so we are // ok to just call this in case we did. global string $gSoftSelectOptionsCtx; softSelectOptionsCtx -edit -buttonUp $gSoftSelectOptionsCtx; } if( `currentCtx` == "sgCurveEditBrushContext1" ) { sgCurveEditBrushContext -e -radiusEditOn 0 sgCurveEditBrushContext1; } } global proc sgCurveEditBrush_contextProperties() { } global proc sgCurveEditBrush_contextValues( string $context ) { } ''' mel.eval(melScript) import sgBFunction_dag sels = sgBFunction_dag.getChildrenCurveExists(cmds.ls(sl=1)) cmds.select(sels) if not cmds.contextInfo("sgCurveEditBrushContext1", ex=1): mel.eval('sgCurveEditBrushContext sgCurveEditBrushContext1') cmds.setToolTo("sgCurveEditBrushContext1")
def createRivetFromVertex_mirror( rivetObj ): import sgBFunction_dag import sgBFunction_base import sgBFunction_convert sgBFunction_base.autoLoadPlugin( 'sgRigAddition' ) def getNodeFromMesh( mesh, isFirst=True ): if cmds.objectType( mesh ) == 'transform': mesh = sgBFunction_dag.getShape( mesh ) cons = cmds.listConnections( mesh+'.wm', type='sgMatrixFromVertices' ) if cons: return cons[0] node = cmds.createNode( 'sgMatrixFromVertices' ) cmds.connectAttr( mesh+'.outMesh', node+'.inputMesh' ) cmds.connectAttr( mesh+'.wm', node+'.inputMeshMatrix' ) return node cons = cmds.listConnections( rivetObj, s=1, d=0, type='sgMatrixFromVertices', p=1, c=1 ) if not cons: return None node, attr = cons[1].split( '.' ) vtxNum = int( attr.split( '[' )[1].replace( ']', '' ) ) mesh = cmds.listConnections( node, s=1, d=0, type='mesh', shapes=1 ) if not mesh: return None mesh = mesh[0] fnMesh = om.MFnMesh( sgBFunction_dag.getMDagPath( mesh ) ) intersector = om.MMeshIntersector() intersector.create( fnMesh.object() ) pointArr = om.MPointArray() fnMesh.getPoints( pointArr ) pointMirror = om.MPoint( -pointArr[ vtxNum ].x, pointArr[ vtxNum ].y, pointArr[ vtxNum ].z ) pointOnMesh = om.MPointOnMesh() intersector.getClosestPoint( pointMirror, pointOnMesh ) faceIndex = pointOnMesh.faceIndex() vertices = om.MIntArray() fnMesh.getPolygonVertices( faceIndex, vertices ) closeIndex = 0 closeDist = 1000000.0 for i in range( vertices.length() ): dist = pointArr[ vertices[i] ].distanceTo( pointMirror ) if closeDist > dist: closeDist = dist closeIndex = vertices[i] cmds.setAttr( node+'.verticeId[%d]' % closeIndex, closeIndex ) rivetObjName = rivetObj.split( '|' )[-1] rivetObjName = rivetObjName.replace( str( vtxNum ), str( closeIndex ) ) newObject = cmds.createNode( 'transform', n= sgBFunction_convert.convertSide( rivetObjName ) ) cmds.setAttr( newObject+'.dh', 1 ) cmds.setAttr( newObject+'.inheritsTransform', 0 ) cmds.connectAttr( node+'.outputTranslate[%d]' % closeIndex, newObject+'.t' )
import maya.cmds as cmds import maya.mel as mel import os, sys import sgBFunction_base sgBFunction_base.autoLoadPlugin( 'HSBVC' ) selectEventId = None app_dir = mel.eval( 'getenv( "MAYA_APP_DIR" )' ) if not os.path.exists( app_dir+"/LocusCommPackagePrefs/HSBVC_prefs"): os.makedirs( app_dir+"/LocusCommPackagePrefs/HSBVC_prefs" ) imagePath = '' for j in sys.path: if not os.path.isdir( j ): continue dirList = os.listdir( j ) if 'volumeHairTool' in dirList: imagePath = j+'/volumeHairTool/Icon'