Exemplo n.º 1
0
def setMultiObjectCombine( models ):
    
    first = models[0]
    others = models[1:]
    
    firstOrigShape = sgModelDag.getOrigShape( first )

    for other in others:
        if not cmds.objExists( other ): continue
        otherOrigShape = sgModelDag.getOrigShape( other )
        if firstOrigShape == otherOrigShape: continue
        if cmds.isConnected( firstOrigShape+'.outMesh', otherOrigShape+'.inMesh' ): continue
        cmds.connectAttr( firstOrigShape+'.outMesh', otherOrigShape+'.inMesh', f=1 )
Exemplo n.º 2
0
def importCache( mesh, xmlFilePath ):
    
    mesh = sgModelDag.getShape( mesh )
    
    xmlFileSplits = xmlFilePath.split( '/' )
    cachePath = '/'.join( xmlFileSplits[:-1] )
    cacheName = xmlFileSplits[-1].split( '.' )[0]
    
    deformer = cmds.createNode( 'historySwitch' )
    cacheNode = cmds.createNode( 'cacheFile' )
    
    cmds.connectAttr( cacheNode+'.outCacheData[0]', deformer+'.inPositions[0]')
    cmds.connectAttr( cacheNode+'.inRange',         deformer+'.playFromCache' )
    cmds.connectAttr( 'time1.outTime', cacheNode+'.time' )
    
    cmds.setAttr( cacheNode+'.cachePath', cachePath, type='string' )
    cmds.setAttr( cacheNode+'.cacheName', cacheName, type='string' )
    
    #print "xml filePath : ", xmlFilePath
    startFrame, endFrame = sgModelData.getStartAndEndFrameFromXmlFile( xmlFilePath )
    cmds.playbackOptions( animationStartTime = startFrame, animationEndTime= endFrame,
                          minTime = startFrame+5, maxTime= endFrame-5 )
    
    cmds.setAttr( cacheNode+'.startFrame',    startFrame )
    cmds.setAttr( cacheNode+'.sourceStart',   startFrame )
    cmds.setAttr( cacheNode+'.sourceEnd',     endFrame )
    cmds.setAttr( cacheNode+'.originalStart', startFrame )
    cmds.setAttr( cacheNode+'.originalEnd',   endFrame )

    origMesh = sgModelDag.getOrigShape( mesh )
    if not origMesh: return None
    
    cmds.connectAttr( origMesh+'.worldMesh', deformer+'.undeformedGeometry[0]' )
    cmds.connectAttr( deformer+'.outputGeometry[0]', mesh+'.inMesh', f=1 )
Exemplo n.º 3
0
def setMultiObjectCombine(models):

    first = models[0]
    others = models[1:]

    firstOrigShape = sgModelDag.getOrigShape(first)

    for other in others:
        if not cmds.objExists(other): continue
        otherOrigShape = sgModelDag.getOrigShape(other)
        if firstOrigShape == otherOrigShape: continue
        if cmds.isConnected(firstOrigShape + '.outMesh',
                            otherOrigShape + '.inMesh'):
            continue
        cmds.connectAttr(firstOrigShape + '.outMesh',
                         otherOrigShape + '.inMesh',
                         f=1)
Exemplo n.º 4
0
def buildCacheScene(meshShapeNames, cachePath):

    cachePath = cachePath.replace('\\', '/')
    meshs = bulidMeshFromData(meshShapeNames)

    xmlFiles = []
    for root, dirs, names in os.walk(cachePath):
        for name in names:
            if name[-4:].lower() == '.xml':
                xmlFiles.append(name)

    for mesh in meshs:
        xmlFileName = mesh.replace(':', '_') + '.xml'
        if not xmlFileName in xmlFiles: continue

        xmlFilePath = cachePath + '/' + xmlFileName

        deformer = cmds.createNode('historySwitch')
        cacheNode = cmds.createNode('cacheFile')

        cmds.connectAttr(cacheNode + '.outCacheData[0]',
                         deformer + '.inPositions[0]')
        cmds.connectAttr(cacheNode + '.inRange', deformer + '.playFromCache')
        cmds.connectAttr('time1.outTime', cacheNode + '.time')

        cmds.setAttr(cacheNode + '.cachePath', cachePath, type='string')
        cmds.setAttr(cacheNode + '.cacheName',
                     mesh.replace(':', '_'),
                     type='string')

        timeUnit = getTimeUnitFromFile()
        if timeUnit:
            cmds.currentUnit(time=timeUnit)

        startFrame, endFrame = getStartAndEndFrameFromXmlFile(xmlFilePath)
        cmds.playbackOptions(animationStartTime=startFrame,
                             animationEndTime=endFrame,
                             minTime=startFrame + 5,
                             maxTime=endFrame - 5)

        cmds.setAttr(cacheNode + '.startFrame', startFrame)
        cmds.setAttr(cacheNode + '.sourceStart', startFrame)
        cmds.setAttr(cacheNode + '.sourceEnd', endFrame)
        cmds.setAttr(cacheNode + '.originalStart', startFrame)
        cmds.setAttr(cacheNode + '.originalEnd', endFrame)

        origMesh = sgModelDag.getOrigShape(mesh)

        cmds.connectAttr(origMesh + '.worldMesh',
                         deformer + '.undeformedGeometry[0]')
        cmds.connectAttr(deformer + '.outputGeometry[0]',
                         mesh + '.inMesh',
                         f=1)
Exemplo n.º 5
0
def setInverseSkinCluster( skinedObject, shapedObject, target ):
    
    skinCluster = sgModelDag.getNodeFromHistory( skinedObject, 'skinCluster' )
    if not skinCluster: return None
    skinCluster = skinCluster[0]
    
    targetShape = sgModelDag.getShape( target )
    shapedShape = sgModelDag.getShape( shapedObject )
    origShape = sgModelDag.getOrigShape( skinedObject )
    cmds.connectAttr( origShape+'.outMesh', targetShape+'.inMesh', f=1 )
    
    invSkinCluster = cmds.deformer( target, type='inverseSkinCluster' )[0]

    cmds.connectAttr( skinCluster+'.message', invSkinCluster+'.targetSkinCluster' )
    cmds.connectAttr( skinedObject+'.wm', invSkinCluster+'.geomMatrix' )
    cmds.connectAttr( shapedShape+'.outMesh', invSkinCluster+'.inMesh' )
Exemplo n.º 6
0
def setInverseSkinCluster(skinedObject, shapedObject, target):

    skinCluster = sgModelDag.getNodeFromHistory(skinedObject, 'skinCluster')
    if not skinCluster: return None
    skinCluster = skinCluster[0]

    targetShape = sgModelDag.getShape(target)
    shapedShape = sgModelDag.getShape(shapedObject)
    origShape = sgModelDag.getOrigShape(skinedObject)
    cmds.connectAttr(origShape + '.outMesh', targetShape + '.inMesh', f=1)

    invSkinCluster = cmds.deformer(target, type='inverseSkinCluster')[0]

    cmds.connectAttr(skinCluster + '.message',
                     invSkinCluster + '.targetSkinCluster')
    cmds.connectAttr(skinedObject + '.wm', invSkinCluster + '.geomMatrix')
    cmds.connectAttr(shapedShape + '.outMesh', invSkinCluster + '.inMesh')
Exemplo n.º 7
0
def buildCacheScene( meshShapeNames, cachePath ):
    
    cachePath = cachePath.replace( '\\', '/' )
    meshs = bulidMeshFromData( meshShapeNames )
    
    xmlFiles = []
    for root, dirs, names in os.walk( cachePath ):
        for name in names:
            if name[-4:].lower() == '.xml':
                xmlFiles.append( name )
    
    for mesh in meshs:
        xmlFileName = mesh.replace( ':', '_' )+'.xml'
        if not xmlFileName in xmlFiles: continue
        
        xmlFilePath = cachePath + '/' + xmlFileName
        
        deformer = cmds.createNode( 'historySwitch' )
        cacheNode = cmds.createNode( 'cacheFile' )
        
        cmds.connectAttr( cacheNode+'.outCacheData[0]', deformer+'.inPositions[0]')
        cmds.connectAttr( cacheNode+'.inRange',         deformer+'.playFromCache' )
        cmds.connectAttr( 'time1.outTime', cacheNode+'.time' )
        
        cmds.setAttr( cacheNode+'.cachePath', cachePath, type='string' )
        cmds.setAttr( cacheNode+'.cacheName', mesh.replace( ':', '_' ), type='string' )
        
        timeUnit = getTimeUnitFromFile()
        if timeUnit:
            cmds.currentUnit( time=timeUnit )
        
        startFrame, endFrame = getStartAndEndFrameFromXmlFile( xmlFilePath )
        cmds.playbackOptions( animationStartTime = startFrame, animationEndTime= endFrame,
                              minTime = startFrame+5, maxTime= endFrame-5 )
        
        cmds.setAttr( cacheNode+'.startFrame',    startFrame )
        cmds.setAttr( cacheNode+'.sourceStart',   startFrame )
        cmds.setAttr( cacheNode+'.sourceEnd',     endFrame )
        cmds.setAttr( cacheNode+'.originalStart', startFrame )
        cmds.setAttr( cacheNode+'.originalEnd',   endFrame )

        origMesh = sgModelDag.getOrigShape( mesh )
        
        cmds.connectAttr( origMesh+'.worldMesh', deformer+'.undeformedGeometry[0]' )
        cmds.connectAttr( deformer+'.outputGeometry[0]', mesh+'.inMesh', f=1 )
Exemplo n.º 8
0
def addWobbleDeform( mainCtl, targets ):
  
    import math
    if not type( targets ) in [ type(()), type([]) ]:
        targets = [targets]

    failedTargets = []
    for target in targets:
        vtxList = cmds.ls( target+'.vtx[*]', fl=1 )
        topVtxPos = [0,0,0]
        bottomVtxPos = [0,10000,0]
        for vtx in vtxList:
            pos = cmds.xform( vtx, q=1, ws=1, t=1 )
            if math.fabs( pos[1] ) > math.fabs( topVtxPos[1] ):
                topVtxPos = pos
            if math.fabs( pos[1] ) < math.fabs( bottomVtxPos[1] ):
                bottomVtxPos = pos
        
        if( (topVtxPos[0]-bottomVtxPos[0])**2 + (topVtxPos[1]-bottomVtxPos[1])**2 + (topVtxPos[2]-bottomVtxPos[2])**2 ) < 0.001:
            failedTargets.append( target )
            continue 
        crv = cmds.curve( p=[bottomVtxPos,topVtxPos], d=1 )
        cmds.rebuildCurve( crv, ch=0, d=3, s=10 )
        
        sgRigCurve.createSgWobbleCurve( crv, False )
        
        copyAttrs = [ 'globalEnvelope', 'globalTimeMult', 'globalOffset' ]
        
        for copyAttr in copyAttrs:
            sgRigAttribute.copyAttribute( crv+'.'+copyAttr, mainCtl )
            cmds.connectAttr( mainCtl+'.'+copyAttr, crv+'.'+copyAttr )

        wire = cmds.deformer( target, type='wire' )[0]
        crvOrig = sgModelDag.getOrigShape( crv )
        crvShape= sgModelDag.getShape( crv )

        cmds.connectAttr( crvOrig+'.local', wire+'.baseWire[0]' )
        cmds.connectAttr( crvShape+'.local', wire+'.deformedWire[0]' )

        cmds.setAttr( wire+'.rotation', 0.2 )
        cmds.setAttr( wire+'.dropoffDistance[0]', 10 )
    
    return failedTargets