def mirrorTransform( target ): import sgBFunction_convert targetLocalName = target.split( '|' )[-1] mirrorTarget = sgBFunction_convert.convertSide( targetLocalName ) if not cmds.objExists( mirrorTarget ): nodeType = cmds.nodeType( target ) mtx = cmds.getAttr( target+'.wm' ) mirrorMtx = sgBFunction_convert.mirrorMatrix( mtx ) mirrorTarget = cmds.createNode( nodeType, n= mirrorTarget ) cmds.xform( mirrorTarget, ws=1, matrix=mirrorMtx ) dh = cmds.getAttr( target+'.dh' ) cmds.setAttr( mirrorTarget+'.dh', dh ) pTargets = cmds.listRelatives( target, p=1, f=1 ) if pTargets: pMirrorTarget = mirrorTransform( pTargets[0] ) pMirrorTargets = cmds.listRelatives( mirrorTarget, p=1, f=1 ) if pMirrorTargets: if cmds.ls( pMirrorTarget ) != cmds.ls( pMirrorTargets[0] ): mirrorTarget = cmds.parent( mirrorTarget, pMirrorTarget )[0] else: mirrorTarget = cmds.parent( mirrorTarget, pMirrorTarget )[0] return mirrorTarget
def mirrorTransform(target): import sgBFunction_convert targetLocalName = target.split('|')[-1] mirrorTarget = sgBFunction_convert.convertSide(targetLocalName) if not cmds.objExists(mirrorTarget): nodeType = cmds.nodeType(target) mtx = cmds.getAttr(target + '.wm') mirrorMtx = sgBFunction_convert.mirrorMatrix(mtx) mirrorTarget = cmds.createNode(nodeType, n=mirrorTarget) cmds.xform(mirrorTarget, ws=1, matrix=mirrorMtx) dh = cmds.getAttr(target + '.dh') cmds.setAttr(mirrorTarget + '.dh', dh) pTargets = cmds.listRelatives(target, p=1, f=1) if pTargets: pMirrorTarget = mirrorTransform(pTargets[0]) pMirrorTargets = cmds.listRelatives(mirrorTarget, p=1, f=1) if pMirrorTargets: if cmds.ls(pMirrorTarget) != cmds.ls(pMirrorTargets[0]): mirrorTarget = cmds.parent(mirrorTarget, pMirrorTarget)[0] else: mirrorTarget = cmds.parent(mirrorTarget, pMirrorTarget)[0] return mirrorTarget
def mirrorNode(target): import sgBFunction_convert mirrorTarget = sgBFunction_convert.convertSide(target) if not cmds.objExists(mirrorTarget): mirrorTarget = cmds.duplicate(target, n=mirrorTarget)[0] return mirrorTarget
def mirrorNode( target ): import sgBFunction_convert mirrorTarget = sgBFunction_convert.convertSide( target ) if not cmds.objExists( mirrorTarget ): mirrorTarget = cmds.duplicate( target, n=mirrorTarget )[0] return mirrorTarget
def mirrorObject(targets): import sgBFunction_convert targets = sgBFunction_convert.singleToList(targets) for target in targets: mtx = cmds.getAttr(target + '.wm') mirrorMtx = sgBFunction_convert.mirrorMatrix(mtx) tr = cmds.createNode('transform', n=sgBFunction_convert.convertSide(target)) cmds.xform(tr, ws=1, matrix=mirrorMtx) cmds.setAttr(tr + '.dh', 1)
def mirrorObject(target): import sgBFunction_convert nodeType = cmds.nodeType(target) mtx = cmds.getAttr(target + '.wm') mirrorMtx = sgBFunction_convert.mirrorMatrix(mtx) mirrorName = sgBFunction_convert.convertSide(target) tr = cmds.createNode(nodeType, n=mirrorName.split('|')[-1]) cmds.xform(tr, ws=1, matrix=mirrorMtx) if nodeType != 'joint': cmds.setAttr(tr + '.dh', 1) return tr
def mirrorObject( target ): import sgBFunction_convert nodeType = cmds.nodeType( target ) mtx = cmds.getAttr( target+'.wm' ) mirrorMtx = sgBFunction_convert.mirrorMatrix( mtx ) mirrorName = sgBFunction_convert.convertSide( target ) tr = cmds.createNode( nodeType, n= mirrorName.split( '|' )[-1] ) cmds.xform( tr, ws=1, matrix=mirrorMtx ) if nodeType != 'joint': cmds.setAttr( tr+'.dh', 1 ) return tr
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 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')