def createFollicleFromVertex(vertices): import sgCFnc_dag import sgBFunction_mesh import sgBFunction_dag cmds.select(vertices) pathAndComps = sgCFnc_dag.getMDagPathAndComponent() for mDagPath, mIntArrU, mIntArrV, mIntArrW in pathAndComps: fnMesh = om.MFnMesh(mDagPath) meshShape = fnMesh.name() meshObj = sgBFunction_dag.getTransform(meshShape) for i in range(len(mIntArrU)): index = mIntArrU[i] pos = cmds.xform(meshShape + '.vtx[%d]' % index, q=1, ws=1, t=1) u, v = sgBFunction_mesh.getUVAtPoint(pos, meshObj) follicle = cmds.createNode('follicle') follicleObj = sgBFunction_dag.getTransform(follicle) cmds.connectAttr(follicle + '.ot', follicleObj + '.t') cmds.connectAttr(follicle + '.or', follicleObj + '.r') cmds.connectAttr(meshShape + '.outMesh', follicle + '.inputMesh') cmds.connectAttr(meshShape + '.wm', follicle + '.inputWorldMatrix') cmds.setAttr(follicle + '.parameterU', u) cmds.setAttr(follicle + '.parameterV', v) cmds.setAttr(follicleObj + '.inheritsTransform', 0)
def createFollicleFromVertex( vertices ): import sgCFnc_dag import sgBFunction_mesh import sgBFunction_dag cmds.select( vertices ) pathAndComps = sgCFnc_dag.getMDagPathAndComponent() for mDagPath, mIntArrU, mIntArrV, mIntArrW in pathAndComps: fnMesh = om.MFnMesh( mDagPath ) meshShape = fnMesh.name() meshObj= sgBFunction_dag.getTransform( meshShape ) for i in range( len( mIntArrU ) ): index = mIntArrU[i] pos = cmds.xform( meshShape+'.vtx[%d]' % index, q=1, ws=1, t=1 ) u, v = sgBFunction_mesh.getUVAtPoint( pos, meshObj ) follicle = cmds.createNode( 'follicle' ) follicleObj = sgBFunction_dag.getTransform( follicle ) cmds.connectAttr( follicle+'.ot', follicleObj+'.t' ) cmds.connectAttr( follicle+'.or', follicleObj+'.r' ) cmds.connectAttr( meshShape+'.outMesh', follicle+'.inputMesh' ) cmds.connectAttr( meshShape+'.wm', follicle+'.inputWorldMatrix' ) cmds.setAttr( follicle+'.parameterU', u ) cmds.setAttr( follicle+'.parameterV', v ) cmds.setAttr( follicleObj+'.inheritsTransform', 0 )
def duplicateShaderToOther( first, second ): import maya.mel as mel import sgBFunction_dag if not cmds.objExists( first ): return None if not cmds.objExists( second ): return None first = sgBFunction_dag.getTransform( first ) second = sgBFunction_dag.getTransform( second ) firstShape = sgBFunction_dag.getShape( first ) secondShape = sgBFunction_dag.getShape( second ) engines = cmds.listConnections( firstShape, type='shadingEngine' ) if not engines: return None engines = list( set( engines ) ) for engine in engines: shaders = cmds.listConnections( engine+'.surfaceShader', s=1, d=0 ) engine = cmds.duplicate( engine, n= 'du_'+engine )[0] if shaders: shader = shaders[0] cmds.hyperShade( objects = shader ) selObjs = cmds.ls( sl=1, l=1 ) targetObjs = [] for selObj in selObjs: if selObj.find( '.' ) != -1: trNode, components = selObj.split( '.' ) if trNode == first: targetObjs.append( second+'.'+components ) elif selObj == firstShape: targetObjs.append( secondShape ) cmds.select( shader ) mel.eval( 'hyperShadePanelMenuCommand("hyperShadePanel1", "duplicateShadingNetwork")' ) shader = cmds.ls( sl=1 )[0] cmds.connectAttr( shader+'.outColor', engine+'.surfaceShader' ) aiShaders = cmds.listConnections( engine+'.aiSurfaceShader', s=1, d=0 ) if aiShaders: aiShader = aiShaders[0] cmds.hyperShade( objects = aiShader ) selObjs = cmds.ls( sl=1, l=1 ) cmds.select( aiShader ) mel.eval( 'hyperShadePanelMenuCommand("hyperShadePanel1", "duplicateShadingNetwork")' ) aiShader = cmds.ls( sl=1 )[0] cmds.connectAttr( aiShader+'.outColor', engine+'.aiSurfaceShader' ) for targetObj in targetObjs: cmds.sets( targetObj, e=1, forceElement=engine )
def createFollicleFromSurfacePoint(surfacePoint): import sgBFunction_dag surfaceNode, noneArrangeStr = surfacePoint.split('.uv[') uvStrs = noneArrangeStr.replace(']', '').split('[') uv = [float(uvStrs[0]), float(uvStrs[1])] surfaceNode = sgBFunction_dag.getShape(surfaceNode) minMaxRangeU = cmds.getAttr(surfaceNode + '.minMaxRangeU')[0] minMaxRangeV = cmds.getAttr(surfaceNode + '.minMaxRangeV')[0] divRateU = minMaxRangeU[1] - minMaxRangeU[0] divRateV = minMaxRangeV[1] - minMaxRangeV[0] follicleNode = cmds.createNode('follicle') cmds.setAttr(follicleNode + '.parameterU', uv[0] / divRateU) cmds.setAttr(follicleNode + '.parameterV', uv[1] / divRateV) cmds.connectAttr(surfaceNode + '.local', follicleNode + '.inputSurface') cmds.connectAttr(surfaceNode + '.wm', follicleNode + '.inputWorldMatrix') follicleObj = sgBFunction_dag.getTransform(follicleNode) cmds.setAttr(follicleObj + '.inheritsTransform', 0) cmds.connectAttr(follicleNode + '.outTranslate', follicleObj + '.t') cmds.connectAttr(follicleNode + '.outRotate', follicleObj + '.r') return follicleObj
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 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 createFollicleFromSurfacePoint( surfacePoint ): import sgBFunction_dag surfaceNode, noneArrangeStr = surfacePoint.split( '.uv[' ) uvStrs = noneArrangeStr.replace( ']', '' ).split( '[' ) uv = [ float( uvStrs[0] ), float( uvStrs[1] ) ] surfaceNode = sgBFunction_dag.getShape( surfaceNode ) minMaxRangeU = cmds.getAttr( surfaceNode+'.minMaxRangeU' )[0] minMaxRangeV = cmds.getAttr( surfaceNode+'.minMaxRangeV' )[0] divRateU = minMaxRangeU[1] - minMaxRangeU[0] divRateV = minMaxRangeV[1] - minMaxRangeV[0] follicleNode = cmds.createNode( 'follicle' ) cmds.setAttr( follicleNode+'.parameterU', uv[0]/divRateU ) cmds.setAttr( follicleNode+'.parameterV', uv[1]/divRateV ) cmds.connectAttr( surfaceNode+'.local', follicleNode+'.inputSurface' ) cmds.connectAttr( surfaceNode+'.wm', follicleNode+'.inputWorldMatrix' ) follicleObj = sgBFunction_dag.getTransform( follicleNode ) cmds.setAttr( follicleObj+'.inheritsTransform', 0 ) cmds.connectAttr( follicleNode+'.outTranslate', follicleObj+'.t' ) cmds.connectAttr( follicleNode+'.outRotate', follicleObj+'.r' ) return follicleObj
def duplicateOnlyCurve( curves ): import sgBFunction_dag curves = sgBFunction_dag.getChildrenCurveExists( curves ) newCurves = [] for curve in curves: curveP = sgBFunction_dag.getParent( curve ) if curveP: newCurveParent = sgBFunction_dag.makeCloneObject( curveP ) else: newCurveParent = None newCurveShape = cmds.createNode( 'nurbsCurve' ) curveShape = sgBFunction_dag.getShape( curve ) cmds.connectAttr( curveShape+'.local', newCurveShape+'.create' ) newCurve = sgBFunction_dag.getTransform( newCurveShape ) newCurve = cmds.rename( newCurve, 'du_' + curve.split( '|' )[-1] ) if newCurveParent: newCurve = cmds.parent( newCurve, newCurveParent )[0] newCurves.append( newCurve ) cmds.refresh() for i in range( len( newCurves ) ): curveShape = sgBFunction_dag.getShape( curves[i] ) newCurveShape = sgBFunction_dag.getShape( newCurves[i] ) if cmds.isConnected( curveShape+'.local', newCurveShape+'.create' ): cmds.disconnectAttr( curveShape+'.local', newCurveShape+'.create' ) return newCurves
def removeUiSeparateView( cam ): import sgBFunction_attribute import sgBFunction_dag uiPrefix = 'separatedViewCam_' uis = cmds.lsUI( wnd=1 ) for ui in uis: if not len( ui ) > len( uiPrefix ): continue if ui[ : len( uiPrefix ) ] != uiPrefix: continue cmds.deleteUI( ui, wnd=1 ) if not cmds.objExists( cam ): return None for cam in cmds.ls( type='camera' ): if not cmds.objExists( cam ): continue cam = sgBFunction_dag.getTransform( cam ) sgBFunction_attribute.addAttr( cam, ln='filmTranslateCams', at='message' ) sgBFunction_attribute.addAttr( cam, ln='aniamtionCam', at='message' ) cons1 = cmds.listConnections( cam+'.filmTranslateCams', d=1, s=0 ) cons2 = cmds.listConnections( cam+'.aniamtionCam', d=1, s=0 ) if cons1: cmds.delete( cons1 ) if cons2: cmds.delete( cons2 )
def removeUiSeparateView(cam): import sgBFunction_attribute import sgBFunction_dag uiPrefix = 'separatedViewCam_' uis = cmds.lsUI(wnd=1) for ui in uis: if not len(ui) > len(uiPrefix): continue if ui[:len(uiPrefix)] != uiPrefix: continue cmds.deleteUI(ui, wnd=1) if not cmds.objExists(cam): return None for cam in cmds.ls(type='camera'): if not cmds.objExists(cam): continue cam = sgBFunction_dag.getTransform(cam) sgBFunction_attribute.addAttr(cam, ln='filmTranslateCams', at='message') sgBFunction_attribute.addAttr(cam, ln='aniamtionCam', at='message') cons1 = cmds.listConnections(cam + '.filmTranslateCams', d=1, s=0) cons2 = cmds.listConnections(cam + '.aniamtionCam', d=1, s=0) if cons1: cmds.delete(cons1) if cons2: cmds.delete(cons2)
def duplicateOnlyCurve(curves): import sgBFunction_dag curves = sgBFunction_dag.getChildrenCurveExists(curves) newCurves = [] for curve in curves: curveP = sgBFunction_dag.getParent(curve) if curveP: newCurveParent = sgBFunction_dag.makeCloneObject(curveP) else: newCurveParent = None newCurveShape = cmds.createNode('nurbsCurve') curveShape = sgBFunction_dag.getShape(curve) cmds.connectAttr(curveShape + '.local', newCurveShape + '.create') newCurve = sgBFunction_dag.getTransform(newCurveShape) newCurve = cmds.rename(newCurve, 'du_' + curve.split('|')[-1]) if newCurveParent: newCurve = cmds.parent(newCurve, newCurveParent)[0] newCurves.append(newCurve) cmds.refresh() for i in range(len(newCurves)): curveShape = sgBFunction_dag.getShape(curves[i]) newCurveShape = sgBFunction_dag.getShape(newCurves[i]) if cmds.isConnected(curveShape + '.local', newCurveShape + '.create'): cmds.disconnectAttr(curveShape + '.local', newCurveShape + '.create') return newCurves
def createClosestFollicle(trObj, meshObj): import sgBFunction_mesh import sgBFunction_dag trObjPos = cmds.xform(trObj, q=1, ws=1, t=1) u, v = sgBFunction_mesh.getUVAtPoint(trObjPos, meshObj) follicle = cmds.createNode('follicle') follicleObj = sgBFunction_dag.getTransform(follicle) cmds.connectAttr(follicle + '.ot', follicleObj + '.t') cmds.connectAttr(follicle + '.or', follicleObj + '.r') meshShape = sgBFunction_dag.getShape(meshObj) cmds.connectAttr(meshShape + '.outMesh', follicle + '.inputMesh') cmds.setAttr(follicle + '.parameterU', u) cmds.setAttr(follicle + '.parameterV', v) return follicleObj
def createClosestFollicle( trObj, meshObj ): import sgBFunction_mesh import sgBFunction_dag trObjPos = cmds.xform( trObj, q=1, ws=1, t=1 ) u, v = sgBFunction_mesh.getUVAtPoint( trObjPos, meshObj ) follicle = cmds.createNode( 'follicle' ) follicleObj = sgBFunction_dag.getTransform( follicle ) cmds.connectAttr( follicle+'.ot', follicleObj+'.t' ) cmds.connectAttr( follicle+'.or', follicleObj+'.r' ) meshShape = sgBFunction_dag.getShape( meshObj ) cmds.connectAttr( meshShape+'.outMesh', follicle+'.inputMesh' ) cmds.setAttr( follicle+'.parameterU', u ) cmds.setAttr( follicle+'.parameterV', v ) return follicleObj
def setKeyCurves( curves ): import sgBFunction_dag import sgBFunction_attribute import math curves = sgBFunction_dag.getChildrenCurveExists( curves ) currentFrame = str( '%.2f' % cmds.currentTime( q=1 ) ).replace( '.', '_' ).replace( '-', 'm' ) frameGroup = 'keyCurveGroup_%s' % currentFrame if not cmds.objExists( frameGroup ): cmds.group( em =1, n=frameGroup ) sgBFunction_attribute.addAttr( frameGroup, ln='frameValue', dt='string' ) cmds.setAttr( frameGroup+'.frameValue', currentFrame, type='string' ) cmds.setAttr( frameGroup+'.overrideEnabled', 1 ) cmds.setAttr( frameGroup+'.overrideColor', int( math.fabs( cmds.currentTime( q=1 ) ) )%32 ) keyCurves = [] for curve in curves: sgBFunction_attribute.addAttr( curve, ln='keyCurveBase', at='message' ) cons = cmds.listConnections( curve+'.keyCurveBase', d=1, s=0 ) if cons: targetCurve = None for con in cons: conP = cmds.listRelatives( con, p=1, f=1 )[0] if cmds.getAttr( conP+'.frameValue' ) == currentFrame: targetCurve = con if targetCurve: keyCurves.append( targetCurve ) continue keyCurveShape = cmds.createNode( 'nurbsCurve' ) curveShape = sgBFunction_dag.getShape( curve ) cmds.connectAttr( curveShape+'.local', keyCurveShape+'.create' ) keyCurve = sgBFunction_dag.getTransform( keyCurveShape ) curveName = curve.split( '|' )[-1] keyCurve = cmds.rename( keyCurve, curveName+'_'+currentFrame ) keyCurves.append( keyCurve ) sgBFunction_attribute.addAttr( keyCurve, ln='keyCurve', at='message' ) cmds.connectAttr( curve+'.keyCurveBase', keyCurve+'.keyCurve' ) cmds.refresh() for i in range( len( curves ) ): baseCurve = sgBFunction_dag.getShape( curves[i] ) keyCurve = sgBFunction_dag.getShape( keyCurves[i] ) if cmds.isConnected( baseCurve+'.local', keyCurve+'.create' ): cmds.disconnectAttr( baseCurve+'.local', keyCurve+'.create' ) try:keyCurves[i] = cmds.parent( keyCurves[i], frameGroup )[0] except:continue targetKeyCurves = [] for i in range( len( curves ) ): baseCurve = curves[i] keyCurve = keyCurves[i] if not cmds.attributeQuery( 'mtxObj_forKeyCurve', node=baseCurve, ex=1 ): cmds.delete( keyCurve ) continue mtxObj = cmds.listConnections( baseCurve + '.mtxObj_forKeyCurve', s=1, d=0 ) if not mtxObj: cmds.delete( keyCurve ) continue targetKeyCurves.append( keyCurve ) setKeyCurve( keyCurve, baseCurve, mtxObj[0] ) return targetKeyCurves
def duplicateShaderToOther(first, second): import maya.mel as mel import sgBFunction_dag if not cmds.objExists(first): return None if not cmds.objExists(second): return None first = sgBFunction_dag.getTransform(first) second = sgBFunction_dag.getTransform(second) firstShape = sgBFunction_dag.getShape(first) secondShape = sgBFunction_dag.getShape(second) engines = cmds.listConnections(firstShape, type='shadingEngine') if not engines: return None engines = list(set(engines)) for engine in engines: shaders = cmds.listConnections(engine + '.surfaceShader', s=1, d=0) engine = cmds.duplicate(engine, n='du_' + engine)[0] if shaders: shader = shaders[0] cmds.hyperShade(objects=shader) selObjs = cmds.ls(sl=1, l=1) targetObjs = [] for selObj in selObjs: if selObj.find('.') != -1: trNode, components = selObj.split('.') if trNode == first: targetObjs.append(second + '.' + components) elif selObj == firstShape: targetObjs.append(secondShape) cmds.select(shader) mel.eval( 'hyperShadePanelMenuCommand("hyperShadePanel1", "duplicateShadingNetwork")' ) shader = cmds.ls(sl=1)[0] cmds.connectAttr(shader + '.outColor', engine + '.surfaceShader') aiShaders = cmds.listConnections(engine + '.aiSurfaceShader', s=1, d=0) if aiShaders: aiShader = aiShaders[0] cmds.hyperShade(objects=aiShader) selObjs = cmds.ls(sl=1, l=1) cmds.select(aiShader) mel.eval( 'hyperShadePanelMenuCommand("hyperShadePanel1", "duplicateShadingNetwork")' ) aiShader = cmds.ls(sl=1)[0] cmds.connectAttr(aiShader + '.outColor', engine + '.aiSurfaceShader') for targetObj in targetObjs: cmds.sets(targetObj, e=1, forceElement=engine)
def setKeyCurves(curves): import sgBFunction_dag import sgBFunction_attribute import math curves = sgBFunction_dag.getChildrenCurveExists(curves) currentFrame = str('%.2f' % cmds.currentTime(q=1)).replace('.', '_').replace( '-', 'm') frameGroup = 'keyCurveGroup_%s' % currentFrame if not cmds.objExists(frameGroup): cmds.group(em=1, n=frameGroup) sgBFunction_attribute.addAttr(frameGroup, ln='frameValue', dt='string') cmds.setAttr(frameGroup + '.frameValue', currentFrame, type='string') cmds.setAttr(frameGroup + '.overrideEnabled', 1) cmds.setAttr(frameGroup + '.overrideColor', int(math.fabs(cmds.currentTime(q=1))) % 32) keyCurves = [] for curve in curves: sgBFunction_attribute.addAttr(curve, ln='keyCurveBase', at='message') cons = cmds.listConnections(curve + '.keyCurveBase', d=1, s=0) if cons: targetCurve = None for con in cons: conP = cmds.listRelatives(con, p=1, f=1)[0] if cmds.getAttr(conP + '.frameValue') == currentFrame: targetCurve = con if targetCurve: keyCurves.append(targetCurve) continue keyCurveShape = cmds.createNode('nurbsCurve') curveShape = sgBFunction_dag.getShape(curve) cmds.connectAttr(curveShape + '.local', keyCurveShape + '.create') keyCurve = sgBFunction_dag.getTransform(keyCurveShape) curveName = curve.split('|')[-1] keyCurve = cmds.rename(keyCurve, curveName + '_' + currentFrame) keyCurves.append(keyCurve) sgBFunction_attribute.addAttr(keyCurve, ln='keyCurve', at='message') cmds.connectAttr(curve + '.keyCurveBase', keyCurve + '.keyCurve') cmds.refresh() for i in range(len(curves)): baseCurve = sgBFunction_dag.getShape(curves[i]) keyCurve = sgBFunction_dag.getShape(keyCurves[i]) if cmds.isConnected(baseCurve + '.local', keyCurve + '.create'): cmds.disconnectAttr(baseCurve + '.local', keyCurve + '.create') try: keyCurves[i] = cmds.parent(keyCurves[i], frameGroup)[0] except: continue targetKeyCurves = [] for i in range(len(curves)): baseCurve = curves[i] keyCurve = keyCurves[i] if not cmds.attributeQuery('mtxObj_forKeyCurve', node=baseCurve, ex=1): cmds.delete(keyCurve) continue mtxObj = cmds.listConnections(baseCurve + '.mtxObj_forKeyCurve', s=1, d=0) if not mtxObj: cmds.delete(keyCurve) continue targetKeyCurves.append(keyCurve) setKeyCurve(keyCurve, baseCurve, mtxObj[0]) return targetKeyCurves
def createRivetFromCurves(curves): import sgBFunction_dag loft = cmds.createNode('loft') info = cmds.createNode('pointOnSurfaceInfo') fbfm = cmds.createNode('fourByFourMatrix') mmdc = cmds.createNode('multMatrixDecompose') null = cmds.createNode('transform') vp = cmds.createNode('vectorProduct') surfShape = cmds.createNode('nurbsSurface') surfObj = sgBFunction_dag.getTransform(surfShape) for i in range(len(curves)): curve = curves[i] shape = sgBFunction_dag.getShape(curve) srcCons = cmds.listConnections(shape + '.create', p=1, c=1) if not srcCons: cmds.connectAttr(shape + '.local', loft + '.inputCurve[%d]' % i) else: cmds.connectAttr(srcCons[1], loft + '.inputCurve[%d]' % i) cmds.setAttr(vp + '.operation', 2) cmds.setAttr(info + '.top', 1) cmds.setAttr(info + '.u', 0.5) cmds.setAttr(info + '.v', 0.5) cmds.connectAttr(loft + '.outputSurface', info + '.inputSurface') cmds.connectAttr(loft + '.outputSurface', surfShape + '.create') cmds.connectAttr(info + '.nnx', fbfm + '.i00') cmds.connectAttr(info + '.nny', fbfm + '.i01') cmds.connectAttr(info + '.nnz', fbfm + '.i02') cmds.connectAttr(info + '.nvx', fbfm + '.i10') cmds.connectAttr(info + '.nvy', fbfm + '.i11') cmds.connectAttr(info + '.nvz', fbfm + '.i12') cmds.connectAttr(info + '.nnx', vp + '.input1X') cmds.connectAttr(info + '.nny', vp + '.input1Y') cmds.connectAttr(info + '.nnz', vp + '.input1Z') cmds.connectAttr(info + '.nvx', vp + '.input2X') cmds.connectAttr(info + '.nvy', vp + '.input2Y') cmds.connectAttr(info + '.nvz', vp + '.input2Z') cmds.connectAttr(vp + '.outputX', fbfm + '.i20') cmds.connectAttr(vp + '.outputY', fbfm + '.i21') cmds.connectAttr(vp + '.outputZ', fbfm + '.i22') cmds.connectAttr(info + '.px', fbfm + '.i30') cmds.connectAttr(info + '.py', fbfm + '.i31') cmds.connectAttr(info + '.pz', fbfm + '.i32') cmds.connectAttr(fbfm + '.output', mmdc + '.i[0]') cmds.connectAttr(null + '.pim', mmdc + '.i[1]') cmds.connectAttr(mmdc + '.ot', null + '.t') cmds.connectAttr(mmdc + '.or', null + '.r') cmds.addAttr(null, ln='parameterU', min=0, max=1, dv=0.5) cmds.setAttr(null + '.parameterU', e=1, k=1) cmds.addAttr(null, ln='parameterV', min=0, max=1, dv=0.5) cmds.setAttr(null + '.parameterV', e=1, k=1) cmds.connectAttr(null + '.parameterU', info + '.u') cmds.connectAttr(null + '.parameterV', info + '.v') cmds.setAttr(null + '.dh', 1) cmds.select(null) return null, surfObj
def createRivetFromCurves( curves ): import sgBFunction_dag loft = cmds.createNode( 'loft' ) info = cmds.createNode( 'pointOnSurfaceInfo' ) fbfm = cmds.createNode( 'fourByFourMatrix' ) mmdc = cmds.createNode( 'multMatrixDecompose' ) null = cmds.createNode( 'transform' ) vp = cmds.createNode( 'vectorProduct' ) surfShape = cmds.createNode( 'nurbsSurface' ) surfObj = sgBFunction_dag.getTransform( surfShape ) for i in range( len( curves ) ): curve = curves[i] shape = sgBFunction_dag.getShape( curve ) srcCons = cmds.listConnections( shape + '.create', p=1, c=1 ) if not srcCons: cmds.connectAttr( shape+'.local', loft+'.inputCurve[%d]' % i ) else: cmds.connectAttr( srcCons[1], loft+'.inputCurve[%d]' % i ) cmds.setAttr( vp+'.operation', 2 ) cmds.setAttr( info+'.top', 1 ) cmds.setAttr( info+'.u', 0.5 ) cmds.setAttr( info+'.v', 0.5 ) cmds.connectAttr( loft + '.outputSurface', info+'.inputSurface' ) cmds.connectAttr( loft + '.outputSurface', surfShape+'.create' ) cmds.connectAttr( info+'.nnx', fbfm+'.i00' ) cmds.connectAttr( info+'.nny', fbfm+'.i01' ) cmds.connectAttr( info+'.nnz', fbfm+'.i02' ) cmds.connectAttr( info+'.nvx', fbfm+'.i10' ) cmds.connectAttr( info+'.nvy', fbfm+'.i11' ) cmds.connectAttr( info+'.nvz', fbfm+'.i12' ) cmds.connectAttr( info+'.nnx', vp+'.input1X' ) cmds.connectAttr( info+'.nny', vp+'.input1Y' ) cmds.connectAttr( info+'.nnz', vp+'.input1Z' ) cmds.connectAttr( info+'.nvx', vp+'.input2X' ) cmds.connectAttr( info+'.nvy', vp+'.input2Y' ) cmds.connectAttr( info+'.nvz', vp+'.input2Z' ) cmds.connectAttr( vp+'.outputX', fbfm+'.i20' ) cmds.connectAttr( vp+'.outputY', fbfm+'.i21' ) cmds.connectAttr( vp+'.outputZ', fbfm+'.i22' ) cmds.connectAttr( info+'.px', fbfm+'.i30' ) cmds.connectAttr( info+'.py', fbfm+'.i31' ) cmds.connectAttr( info+'.pz', fbfm+'.i32' ) cmds.connectAttr( fbfm+'.output', mmdc+'.i[0]' ) cmds.connectAttr( null+'.pim', mmdc+'.i[1]' ) cmds.connectAttr( mmdc+'.ot', null+'.t' ) cmds.connectAttr( mmdc+'.or', null+'.r' ) cmds.addAttr( null, ln='parameterU', min=0, max=1, dv=0.5 ) cmds.setAttr( null+'.parameterU', e=1, k=1 ) cmds.addAttr( null, ln='parameterV', min=0, max=1, dv=0.5 ) cmds.setAttr( null+'.parameterV', e=1, k=1 ) cmds.connectAttr( null+'.parameterU', info+'.u' ) cmds.connectAttr( null+'.parameterV', info+'.v' ) cmds.setAttr( null+'.dh', 1 ) cmds.select( null ) return null, surfObj