def mirrorSkinCluster( targets, inverse = False ):
    if len( sels ) == 1:
        srcSkin = sgCmds.getNodeFromHistory( sels[0], 'skinCluster' )[0]
        dstSkin = srcSkin
    elif len( sels ) == 2:
        srcSkin = sgCmds.getNodeFromHistory( sels[0], 'skinCluster' )[0]
        dstSkin = sgCmds.getNodeFromHistory( sels[1], 'skinCluster' )[0]
    else:
        return None

    cmds.copySkinWeights( ss=srcSkin.name(), ds=dstSkin.name(), mirrorMode='YZ', surfaceAssociation = 'closestPoint', 
                          influenceAssociation=['oneToOne','closestJoint'], mirrorInverse=inverse )
示例#2
0
文件: sw2.py 项目: jonntd/mayadev-1
def duplicateAndParentProxy():

    selection = pymel.core.ls(sl=1)
    src = selection[0]
    sels = selection[1:]

    proxyMesh = sgCmds.getNodeFromHistory(src, 'RedshiftProxyMesh')

    for sel in sels:
        if not proxyMesh: continue
        mesh = pymel.core.createNode('mesh')
        meshObj = mesh.getParent()
        proxyMesh[0].outMesh >> mesh.inMesh
        meshObj.setParent(sel)

        pymel.core.xform(meshObj, os=1, matrix=sgCmds.getDefaultMatrix())
示例#3
0
文件: sw2.py 项目: jonntd/mayadev-1
def duplicateAndParentProxy():
    
    selection = pymel.core.ls( sl=1 )
    src = selection[0]
    sels = selection[1:]
    
    proxyMesh = sgCmds.getNodeFromHistory( src, 'RedshiftProxyMesh' )
    
    for sel in sels:
        if not proxyMesh: continue
        mesh = pymel.core.createNode( 'mesh' )
        meshObj = mesh.getParent()
        proxyMesh[0].outMesh >> mesh.inMesh
        meshObj.setParent( sel )
        
        pymel.core.xform( meshObj, os=1, matrix= sgCmds.getDefaultMatrix() )
示例#4
0
文件: sw2.py 项目: jonntd/mayadev-1
def setGroupSameMeshs():

    sels = pymel.core.ls(sl=1)

    children = pymel.core.listRelatives(sels[0], c=1, ad=1)

    meshGroup = {}

    for child in children:
        proxyMesh = sgCmds.getNodeFromHistory(child, 'RedshiftProxyMesh')
        if proxyMesh: continue
        numVertices = sgCmds.getNumVertices(child)
        if not numVertices: continue
        if meshGroup.has_key(numVertices):
            meshGroup[numVertices].append(child)
        else:
            meshGroup.update({numVertices: [child]})

    for item in meshGroup.items():
        pymel.core.group(item[1:])
示例#5
0
文件: sw2.py 项目: jonntd/mayadev-1
def setGroupSameMeshs():
    
    sels = pymel.core.ls( sl=1 )
    
    children = pymel.core.listRelatives( sels[0], c=1, ad=1 )
    
    meshGroup = {}
    
    for child in children:
        proxyMesh = sgCmds.getNodeFromHistory( child, 'RedshiftProxyMesh' )
        if proxyMesh: continue
        numVertices = sgCmds.getNumVertices( child )
        if not numVertices: continue
        if meshGroup.has_key( numVertices ):
            meshGroup[numVertices].append( child )
        else:
            meshGroup.update({numVertices:[child]})
    
    for item in meshGroup.items():
        pymel.core.group( item[1:] )
import pymel.core
from maya import cmds, OpenMaya
import pymel.core
from sgMaya import sgCmds

sels = pymel.core.ls( sl=1 )

src = sels[0]
dst = sels[1]

srcSkin = sgCmds.getNodeFromHistory( src, 'skinCluster' )[0]
dstSkin = sgCmds.getNodeFromHistory( dst, 'skinCluster' )[0]

fnSrcSkin = OpenMaya.MFnDependencyNode( sgCmds.getMObject( srcSkin.name() ) )
fnDstSkin = OpenMaya.MFnDependencyNode( sgCmds.getMObject( dstSkin.name() ) )

srcWeightList = fnSrcSkin.findPlug( 'weightList' )
dstWeightList = fnDstSkin.findPlug( 'weightList' )

for i in range( dstWeightList.numElements() ):
    weightsPlugDst = dstWeightList[i].child(0)
    for j in range( weightsPlugDst.numElements() ):
        cmds.removeMultiInstance( weightsPlugDst[0].name() )
    
    weightsPlugSrc = srcWeightList[i].child(0)
    for j in range( weightsPlugSrc.numElements() ):
        logicalIndex = weightsPlugSrc[j].logicalIndex()
        cmds.setAttr( weightsPlugDst.name() + '[%d]' % logicalIndex, weightsPlugSrc[j].asFloat() )
示例#7
0
import pymel.core
from maya import cmds, OpenMaya
import pymel.core
from sgMaya import sgCmds

sels = pymel.core.ls(sl=1)

src = sels[0]
dst = sels[1]

srcSkin = sgCmds.getNodeFromHistory(src, 'skinCluster')[0]
dstSkin = sgCmds.getNodeFromHistory(dst, 'skinCluster')[0]

fnSrcSkin = OpenMaya.MFnDependencyNode(sgCmds.getMObject(srcSkin.name()))
fnDstSkin = OpenMaya.MFnDependencyNode(sgCmds.getMObject(dstSkin.name()))

srcWeightList = fnSrcSkin.findPlug('weightList')
dstWeightList = fnDstSkin.findPlug('weightList')

for i in range(dstWeightList.numElements()):
    weightsPlugDst = dstWeightList[i].child(0)
    for j in range(weightsPlugDst.numElements()):
        cmds.removeMultiInstance(weightsPlugDst[0].name())

    weightsPlugSrc = srcWeightList[i].child(0)
    for j in range(weightsPlugSrc.numElements()):
        logicalIndex = weightsPlugSrc[j].logicalIndex()
        cmds.setAttr(weightsPlugDst.name() + '[%d]' % logicalIndex,
                     weightsPlugSrc[j].asFloat())
from sgMaya import sgCmds
import pymel.core

meshGrps = pymel.core.ls( sl=1 )
children = pymel.core.listRelatives( meshGrps, c=1, ad=1, type='transform' )

for child in children:
    skinNode = sgCmds.getNodeFromHistory( child, 'skinCluster' )
    blendNode = sgCmds.getNodeFromHistory( child, 'blendShape' )
    if skinNode:
        skinNode[0].rename( 'sk_' + child.name() )
        print skinNode[0].name()
    if blendNode:
        blendNode[0].rename( 'bl_' + child.name() )
        print blendNode[0].name()
import pymel.core
from sgMaya import sgCmds

sels = pymel.core.ls(sl=1)

ctl = sels[0]
mesh = sels[1]

blShapeNodes = sgCmds.getNodeFromHistory(mesh, 'blendShape')

for blendNode in blShapeNodes:
    for i in range(blendNode.w.numElements()):
        wPlug = blendNode.w[i]
        attrName = cmds.ls(wPlug.name())[0].split('.')[-1]

        try:
            sgCmds.addAttr(ctl, ln=attrName, k=1, min=0, max=1)
        except:
            continue
        ctl.attr(attrName) >> wPlug
示例#10
0
import sgPlugin
from sgMaya import sgCmds

if not cmds.pluginInfo( 'sgCmdSkinCluster', q=1, l=1 ):
    cmds.loadPlugin( 'sgCmdSkinCluster' )

targets = []
for mesh in pymel.core.ls( type='mesh' ):
    if not sgCmds.getNodeFromHistory( mesh, 'skinCluster' ): continue
    targets.append( mesh.name() )

for target in targets:
    cmds.select( target )
    cmds.sgCmdSkinClustser( cmds.ls( sl=1 ), d=1 )
cmds.select( d=1 )
import pymel.core
from sgMaya import sgCmds
sels = pymel.core.ls( sl=1 )
src = sels[0]
dst = sels[1]

srcChildren = pymel.core.listRelatives( src, c=1, ad=1, type='transform' )
dstChildren = pymel.core.listRelatives( dst, c=1, ad=1, type='transform' )

for i in range( len( srcChildren ) ):
    srcChild = srcChildren[i]
    dstChild = dstChildren[i]
    if not srcChild.getShape(): continue
    if not sgCmds.getNodeFromHistory( srcChild, 'skinCluster' ): continue
    sgCmds.autoCopyWeight( srcChild, dstChild )
示例#12
0
import sgPlugin
from sgMaya import sgCmds

if not cmds.pluginInfo('sgCmdSkinCluster', q=1, l=1):
    cmds.loadPlugin('sgCmdSkinCluster')

targets = []
for mesh in pymel.core.ls(type='mesh'):
    if not sgCmds.getNodeFromHistory(mesh, 'skinCluster'): continue
    targets.append(mesh.name())

for target in targets:
    cmds.select(target)
    cmds.sgCmdSkinClustser(cmds.ls(sl=1), d=1)
cmds.select(d=1)
示例#13
0
from sgMaya import sgCmds
import pymel.core

sels = pymel.core.ls(sl=1)

srcMesh = sels[0]
others = sels[1:]

srcChildren = srcMesh.listRelatives(c=1, ad=1, type='transform')

for other in others:
    children = other.listRelatives(c=1, ad=1, type='transform')

    for i in range(len(srcChildren)):
        if not sgCmds.getNodeFromHistory(srcChildren[i], 'skinCluster'):
            continue
        sgCmds.autoCopyWeight(srcChildren[i], children[i])
proxyTargets = {'Small_Tree_A':'small_treeA',
                'Small_Tree_B':'small_tree',
                'rainbow_shower_proxy':'tree_flower',
                'plumeria_proxy':'plumeria',
                'palm_tree':'palm_tree',
                'hibiscus_proxy':'hibiscus',
                'small_tree_palm_proxy':'small_tree_palm',
                'treeA_proxy':'treeA',
                'bush':'bush',
                'treeB_proxy':'treeB',
                'tree_flower_proxy':'tree_tmp'}

proxyList = {}
for child in children:
    proxyNode = sgCmds.getNodeFromHistory( child, 'RedshiftProxyMesh' )
    if not proxyNode: continue
    proxyName = proxyNode[0].fileName.get().split( '/' )[-1].split( '.' )[0]
    proxyList[ proxyName ] = proxyNode[0]

for proxyName, node in proxyList.items():
    if not proxyTargets.has_key( proxyName ): continue
    proxyTarget = proxyTargets[ proxyName ]
    if os.path.exists( sceneAnimationPath + '/' + proxyTarget ):
        proxyPath = sceneAnimationPath + '/' + proxyTarget
    else:
        proxyPath = animationPath + '/' + proxyTarget
    
    print "proxyPath : ", proxyPath
    
    firstProxy = None
from sgMaya import sgCmds
import pymel.core

sels = pymel.core.ls( sl=1 )

srcMesh = sels[0]
others = sels[1:]

srcChildren = srcMesh.listRelatives( c=1, ad=1, type='transform' )

for other in others:
    children = other.listRelatives( c=1, ad=1, type='transform' )
    
    for i in range( len( srcChildren ) ):
        if not sgCmds.getNodeFromHistory( srcChildren[i], 'skinCluster' ): continue
        sgCmds.autoCopyWeight( srcChildren[i], children[i] )
示例#16
0
def copyWeightByOnlySpecifyJoints( srcJointsGrp, trgJointsGrp, srcMesh, trgMesh ):
    
    srcJntsGrp = pymel.core.ls( srcJointsGrp )[0]
    trgJntsGrp = pymel.core.ls( trgJointsGrp )[0]
    
    srcJntsChildren = srcJntsGrp.listRelatives( c=1, ad=1, type='joint' )
    trgJntsChildren = trgJntsGrp.listRelatives( c=1, ad=1, type='joint' )
    
    srcPoses = OpenMaya.MPointArray()
    trgPoses = OpenMaya.MPointArray()
    
    srcPoses.setLength( len( srcJntsChildren ) )
    trgPoses.setLength( len( trgJntsChildren ) )
    
    for i in range( srcPoses.length() ):
        srcJnt = srcJntsChildren[i]
        srcJntPos = OpenMaya.MPoint( *srcJnt.wm.get()[-1] )
        srcPoses.set( srcJntPos, i )
        
    for i in range( trgPoses.length() ):
        trgJnt = trgJntsChildren[i]
        trgJntPos = OpenMaya.MPoint( *trgJnt.wm.get()[-1] )
        trgPoses.set( trgJntPos, i )
    
    srcMeshSkin = sgCmds.getNodeFromHistory( srcMesh, 'skinCluster' )[0]
    trgMeshSkin = sgCmds.getNodeFromHistory( trgMesh, 'skinCluster' )[0]
    
    srcToTrgMap = {}
    srcInflueceIndices = []
    for srcJnt in srcJntsChildren:
        cons = srcJnt.wm.listConnections( type='skinCluster', p=1 )
        for con in cons:
            if con.node().name() != srcMeshSkin.name(): continue
            srcInflueceIndices.append( con.index() )
            break
    
    trgInflueceIndices = []
    for trgJnt in trgJntsChildren:
        cons = trgJnt.wm.listConnections( type='skinCluster', p=1 )
        for con in cons:
            if con.node().name() != trgMeshSkin.name(): continue
            trgInflueceIndices.append( con.index() )
            break
    
    for i in range( srcPoses.length() ):
        closeDist = 10000000.0
        closeIndex = 0
        for j in range( trgPoses.length() ):
            dist = srcPoses[i].distanceTo( trgPoses[j] )
            if dist < closeDist:
                closeDist = dist
                closeIndex = j
        srcToTrgMap.update( { srcInflueceIndices[i] : trgInflueceIndices[closeIndex] } )

    fnSrcSkin = OpenMaya.MFnDependencyNode( sgCmds.getMObject( srcMeshSkin ) )
    fnTrgSkin = OpenMaya.MFnDependencyNode( sgCmds.getMObject( trgMeshSkin ) )
    
    plugSrcWeightList = fnSrcSkin.findPlug( 'weightList' )
    plugTrgWeightList = fnTrgSkin.findPlug( 'weightList' )
    
    for i in range( plugSrcWeightList.numElements() ):
        plugSrcWeights = plugSrcWeightList[i].child(0)
        plugTrgWeights = plugTrgWeightList[i].child(0)
        
        trgLogicalIndices = []
        trgValues = []
        sumValue = 0
        for j in range( plugSrcWeights.numElements() ):
            logicalIndex = plugSrcWeights[j].logicalIndex()
            if not srcToTrgMap.has_key( logicalIndex ): continue
            trgInfluenceLogicalIndex = srcToTrgMap[logicalIndex]
            trgLogicalIndices.append( trgInfluenceLogicalIndex )
            trgValues.append( plugSrcWeights[j].asFloat() )
            sumValue += plugSrcWeights[j].asFloat()
        multValue = 1.0 - sumValue
        
        trgOtherLogicalIndices = []
        for j in range( plugTrgWeights.numElements() ):
            trgLogicalIndex = plugTrgWeights[j].logicalIndex()
            if trgLogicalIndex in trgLogicalIndices: continue
            trgOtherLogicalIndices.append( trgLogicalIndex )
        
        for j in range( len( trgLogicalIndices ) ):
            trgAttr = plugTrgWeights.elementByLogicalIndex( trgLogicalIndices[j] ).name()
            cmds.setAttr( trgAttr, trgValues[j] )
        
        for j in range( len( trgOtherLogicalIndices ) ):
            trgAttr = plugTrgWeights.elementByLogicalIndex( trgOtherLogicalIndices[j] ).name()
            cmds.setAttr( trgAttr, cmds.getAttr( trgAttr ) * multValue )
示例#17
0
from sgMaya import sgCmds

sels = cmds.ls(sl=1)

bindJoints = []

for sel in sels:
    skinNodes = sgCmds.getNodeFromHistory(sel, 'skinCluster')

    if not skinNodes: continue
    joints = cmds.listConnections(skinNodes[0] + '.matrix')

    bindJoints += joints

cmds.skinCluster(bindJoints, sels[-1], tsb=1)
cmds.select(sels)
cmds.copySkinWeights(noMirror=True,
                     surfaceAssociation='closestPoint',
                     influenceAssociation='oneToOne')
import pymel.core
from sgMaya import sgCmds

sels = pymel.core.ls( sl=1 )

srcMeshs = sels[:-1]
targetMesh = sels[-1]

srcBlends = []
targetBlend = None

for srcMesh in srcMeshs:
    srcBlends += sgCmds.getNodeFromHistory( srcMesh, 'blendShape' )

targetBlend = sgCmds.getNodeFromHistory( targetMesh, 'blendShape' )[0]

targetBlendAttrs = targetBlend.weight

for srcBlend in srcBlends:
    for i in range( srcBlend.weight.numElements() ):
        attrName = cmds.ls( srcBlend.weight[i].name() )[0].split( '.' )[-1]
        
        cons = srcBlend.weight[i].listConnections( s=1, p=1 )
        
        if pymel.core.attributeQuery( attrName , node=targetBlend, ex=1 ):
            cons[0] >> targetBlend.attr( attrName )
import pymel.core
from sgMaya import sgCmds

sels = pymel.core.ls( sl=1 )

ctl = sels[0]
mesh = sels[1]

blShapeNodes = sgCmds.getNodeFromHistory( mesh, 'blendShape' )

for blendNode in blShapeNodes:
    for i in range( blendNode.w.numElements() ):
        wPlug = blendNode.w[i]
        attrName = cmds.ls( wPlug.name() )[0].split( '.' )[-1]
            
        try:sgCmds.addAttr( ctl, ln=attrName, k=1, min=0, max=1 ) 
        except:continue
        ctl.attr( attrName ) >> wPlug
from sgMaya import sgCmds

sels = cmds.ls( sl=1 )

bindJoints = []

for sel in sels:
    skinNodes = sgCmds.getNodeFromHistory( sel, 'skinCluster' )
    
    if not skinNodes: continue
    joints = cmds.listConnections( skinNodes[0] + '.matrix' )
    
    bindJoints += joints
    
cmds.skinCluster( bindJoints, sels[-1], tsb=1 )
cmds.select( sels )
cmds.copySkinWeights( noMirror=True, surfaceAssociation='closestPoint', influenceAssociation ='oneToOne' )
from sgMaya import sgCmds
import pymel.core

meshGrps = pymel.core.ls(sl=1)
children = pymel.core.listRelatives(meshGrps, c=1, ad=1, type='transform')

for child in children:
    skinNode = sgCmds.getNodeFromHistory(child, 'skinCluster')
    blendNode = sgCmds.getNodeFromHistory(child, 'blendShape')
    if skinNode:
        skinNode[0].rename('sk_' + child.name())
        print skinNode[0].name()
    if blendNode:
        blendNode[0].rename('bl_' + child.name())
        print blendNode[0].name()
示例#22
0
                   'bg_237_Heilala_Festival:treeA_proxy_ori18':['bg_237_Heilala_Festival_gpu2:treeA_proxy_ori31_gpu',
                                                                'bg_237_Heilala_Festival_gpu2:treeA_proxy_ori12_gpu',
                                                                'bg_237_Heilala_Festival_gpu2:treeA_proxy_ori20_gpu',
                                                                'bg_237_Heilala_Festival_gpu2:treeA_proxy_ori32_gpu'],
                   'bg_237_Heilala_Festival:palm_tree_all|bg_237_Heilala_Festival:palm_tree13|bg_237_Heilala_Festival:palm_tree13':['bg_237_Heilala_Festival_gpu2:palm_tree14_gpu'],
                   'bg_237_Heilala_Festival:polySurface590':['bg_237_Heilala_Festival_gpu2:Small_Tree_A10686262626262_gpu'],
                   'bg_237_Heilala_Festival:pasted__rock1573065729457287':['bg_237_Heilala_Festival_gpu2:rock15737257295_gpu',
                                                                           'bg_237_Heilala_Festival_gpu2:rock1573725729557287_gpu'],
                   'bg_237_Heilala_Festival:pasted__rock15730657293':['bg_237_Heilala_Festival_gpu2:rock1573725729557289_gpu',
                                                                       'bg_237_Heilala_Festival_gpu2:rock1573725729557290_gpu']}

for src, dst in setMatrixTargets.items():
    pymel.core.xform( src, ws=1, matrix=cmds.getAttr( dst + '.wm' ) )

for src, dsts in duplicateTargets.items():
    proxyMesh = sgCmds.getNodeFromHistory( src, 'RedshiftProxyMesh' )
    for dst in dsts:
        if not dst: continue
        if proxyMesh:
            mesh = pymel.core.createNode( 'mesh' )
            meshObj = mesh.getParent()
            proxyMesh[0].outMesh >> mesh.inMesh
        else:
            meshObj = pymel.core.duplicate( src )[0]
        pymel.core.xform( meshObj, ws=1, matrix=cmds.getAttr( dst + '.wm' ) )
        srcP = cmds.listRelatives( src, p=1, f=1 )[0]
        meshObj.setParent( srcP )
        meshObj.rename( src.split( ':' )[-1] )
        if src == 'bg_237_Heilala_Festival:pasted__rock15730657293':
            print "src : ", src
            pymel.core.move( 0, -8.52, 0, meshObj, ws=1, r=1 )