Exemplo n.º 1
0
def SetupSimScene(platform):
    
    
    
    # get the current scene path and extract fields from it
    # using the work template:
    scene_path = os.path.abspath(cmds.file(query=True, sn=True))
    fields = work_template.get_fields(scene_path)
    publish_version = fields["version"]

    #prepare all the paths and variables
    clothFile = "Z:/work/00719_grandpa/assets/Props/Main_Outift/publish/mainOutfit.cloth.v001.ma"
    abcFile = "Y:/RENDERS/00719_grandpa/000_dummy/0000/cache/grandpa.abc"
    ncachePath = "Y:/RENDERS/00719_grandpa/000_dummy/0000/cache/nCache"
    abcNodes = "shoes l_eye r_eye topTeeth bottomTeeth body"
    
    #loading alembic plugin
    cmds.loadPlugin('AbcImport.mll')
    
    #import all the necessary data
    pm.newFile(f=1, type='mayaAscii')
    pm.importFile(clothFile)
    pm.AbcImport(abcFile, mode="import", ct=abcNodes, ftr=True, crt=True, sts=True)
    
    #query time data
    startTime=pm.playbackOptions(q=True,animationStartTime=True)
    endTime=pm.playbackOptions(q=True,animationEndTime=True)
    
    pm.currentTime(startTime)
    
    #find all nCloth objects
    clothObjects = pm.ls(type='nCloth')
    
    #create simulation cache for all nCloth nodes in the scene
    print ('caching theses nCloth objects: ' + str(clothObjects))
    cacheFiles = pm.cacheFile(cnd=clothObjects, st=startTime, et=endTime, dir=ncachePath, dtf=True, fm='OneFile', r=True, ws=True)
    
    #apply created cache to simulated objects
    cacheShapes = pm.ls('outputCloth*')
    i=0
    for shape in cacheShapes:
        switch = mel.eval('createHistorySwitch(\"' + str(shape) + '\",false)')
        cacheNode = pm.cacheFile(f=cacheFiles[i], cnm=str(shape), ia='%s.inp[0]' % switch ,attachFile=True, dir=ncachePath)
        pm.setAttr( '%s.playFromCache' % switch, 1 )
        i += 1
Exemplo n.º 2
0
def mc2mdd(mcPath):
    '''Converts a .mcc file to a .mdd file in the same directory'''
    # ___ define mdd path/name
    mddpath = op.splitext(mcPath)[0].replace('\\', '/')
    fps = '25'
    # ___ MC to PC2 to MDD
    mcName = op.basename(mddpath)
    mcPath = op.dirname(mddpath) + '/'
    pc2 = mddpath + ".pc2"
    pc.cacheFile(pc2=0, pcf=pc2, f=mcName, dir=mcPath)
    p = subprocess.Popen([
        "R:\\Pipe_Repo\\Users\\Qurban\\applications\\PC2_MDD.exe", pc2,
        mddpath + ".mdd", fps
    ],
                         bufsize=2048,
                         shell=True)
    p.wait()
    os.remove(pc2)
Exemplo n.º 3
0
	def assignCacheFile( self, obj, *args ):
		shapeNode = obj.getShape()
		if not self.hasUniqueName( shapeNode ):
			shapeNode = shapeNode.split('|')[-1]

		cacheFile = os.path.join( pm.textField( self.cacheFolderTextField, q=True, text=True ), '%s.xml'%shapeNode )
		switch = pm.mel.createHistorySwitch(obj.getShape(), False)
		cacheNode = pm.cacheFile(f=cacheFile, cnm=obj.getShape(), ia=pm.PyNode(switch).inp[0] ,attachFile=True)
		print cacheNode
		pm.PyNode(switch).playFromCache.set( True )
Exemplo n.º 4
0
    def assignCacheFile(self, obj, *args):
        shapeNode = obj.getShape()
        if not self.hasUniqueName(shapeNode):
            shapeNode = shapeNode.split('|')[-1]

        cacheFile = os.path.join(
            pm.textField(self.cacheFolderTextField, q=True, text=True),
            '%s.xml' % shapeNode)
        switch = pm.mel.createHistorySwitch(obj.getShape(), False)
        cacheNode = pm.cacheFile(f=cacheFile,
                                 cnm=obj.getShape(),
                                 ia=pm.PyNode(switch).inp[0],
                                 attachFile=True)
        print cacheNode
        pm.PyNode(switch).playFromCache.set(True)
Exemplo n.º 5
0
    def maya_sim_setup(self, fields, tk, ctx):

        print 'setting up maya Sim scene'

        #referencing latest cloth setup
        assets = su.getLatestShotAssets(self, 'cloth')
        clothFile = assets[0]['path']['local_path_windows']
        print clothFile
        #setup reference plate

        assets = ['grandpa', 'start_null']

        cmds.file(newFile=True, force=True)
        pm.importFile(clothFile)
        #loading alembic plugin
        pm.loadPlugin('AbcImport.mll')

        for asset in assets:
            fields['Asset'] = asset

            cache_alembic = tk.templates['cache_alembic']
            abcFile = cache_alembic.apply_fields(fields)

            ncache = tk.templates['maya_nCache']
            ncachePath = ncache.apply_fields(fields)

            if asset == 'grandpa':
                abcNodes = "shoes l_eye r_eye topTeeth bottomTeeth body"
            else:
                abcNodes = "start_null"

            #import alembic
            print abcFile
            pm.AbcImport(abcFile,
                         mode="import",
                         ct=abcNodes,
                         ftr=True,
                         crt=True,
                         sts=True)

        #query time data
        startTime = cmds.playbackOptions(q=True, animationStartTime=True)
        endTime = cmds.playbackOptions(q=True, animationEndTime=True)

        pm.currentTime(startTime)
        pm.currentTime(startTime + 1)
        pm.currentTime(startTime)

        pm.PyNode('nucleus*').startFrame.set(startTime)

        #find all nCloth objects
        clothObjects = pm.ls(type='nCloth')

        #create simulation cache for all nCloth nodes in the scene
        print('caching theses nCloth objects: ' + str(clothObjects))
        cacheFiles = pm.cacheFile(cnd=clothObjects,
                                  st=startTime,
                                  et=endTime,
                                  dir=ncachePath,
                                  dtf=True,
                                  fm='OneFile',
                                  r=True,
                                  ws=True)

        #apply created cache to simulated objects
        cacheShapes = pm.ls('outputCloth*')
        i = 0
        for shape in cacheShapes:
            switch = mel.eval('createHistorySwitch(\"' + str(shape) +
                              '\",false)')
            cacheNode = pm.cacheFile(f=cacheFiles[i],
                                     cnm=str(shape),
                                     ia='%s.inp[0]' % switch,
                                     attachFile=True,
                                     dir=ncachePath)
            pm.setAttr('%s.playFromCache' % switch, 1)
            i += 1
Exemplo n.º 6
0
def importNHairCache(hairSystemNode=None, filePath=None):
    """
    Attach nHair cache.
    :param hairSystemNode: `PyNode` hair system node to attach the cache to
    :param filePath: `string` nCache .xml file path
    :return:
    """
    selection = pm.ls(sl=True, type=["transform", "hairSystem"])
    if not hairSystemNode:
        if selection:
            if selection[0].nodeType() == "hairSystem":
                hairSystemNode = selection[0]
            else:
                shapeNode = selection[0].getShape()
                if shapeNode and shapeNode.nodeType() == "hairSystem":
                    hairSystemNode = shapeNode
        if not hairSystemNode:
            print "Please select/input a hairSystem node to import cache files."
            return False

    if not filePath:
        filePath = pm.fileDialog2(fileFilter="*.xml",
                                  dialogStyle=2,
                                  fileMode=1)
        if not filePath:
            return False
        else:
            filePath = filePath[0]
    baseDirectory = os.path.split(filePath)[0]
    cacheName = os.path.splitext(os.path.basename(filePath))[0]
    # check if is already connected to a cache
    if hairSystemNode.playFromCache.isConnected():
        replaceCache = pm.confirmDialog(
            title="Replace Cache",
            message="{0} is already connected to a cache, "
            "do you want to replace the current one?".format(
                hairSystemNode.name()),
            button=["Yes", "No"],
            defaultButton="Yes",
            cancelButton="No",
            dismissString="No")
        if replaceCache == "No":
            return False
        else:
            oldCache = hairSystemNode.playFromCache.connections(
                type="cacheFile")[0]
            pm.delete(oldCache)
    channelNames = getChannelNames(filePath)
    print channelNames
    cacheNodeName = pm.cacheFile(af=True,
                                 f=cacheName,
                                 dir=baseDirectory,
                                 cnm=channelNames,
                                 ia=[
                                     "{0}.hairCounts".format(hairSystemNode),
                                     "{0}.vertexCounts".format(hairSystemNode),
                                     "{0}.positions".format(hairSystemNode)
                                 ])
    pm.PyNode(cacheNodeName).inRange.connect(hairSystemNode.playFromCache,
                                             f=True)
    pm.select(cacheNodeName)
    return True
    def maya_sim_setup(self, fields, tk, ctx):
        
        print 'setting up maya Sim scene'
              
        #referencing latest cloth setup
        assets=su.getLatestShotAssets(self,'cloth')
        clothFile = assets[0]['path']['local_path_windows']
        print clothFile
        #setup reference plate
        
        assets = ['grandpa', 'start_null']
        
        cmds.file(newFile=True, force=True)
        pm.importFile(clothFile)
        #loading alembic plugin
        pm.loadPlugin('AbcImport.mll')
        
        for asset in assets:
            fields['Asset']=asset
            
            cache_alembic=tk.templates['cache_alembic']
            abcFile = cache_alembic.apply_fields(fields)
            
            ncache=tk.templates['maya_nCache']
            ncachePath=ncache.apply_fields(fields)
            
            if asset=='grandpa':
                abcNodes = "shoes l_eye r_eye topTeeth bottomTeeth body"
            else:
                abcNodes = "start_null"
       
            #import alembic
            print abcFile
            pm.AbcImport(abcFile, mode="import", ct=abcNodes, ftr=True, crt=True, sts=True)

       
        #query time data
        startTime=cmds.playbackOptions(q=True,animationStartTime=True)
        endTime=cmds.playbackOptions(q=True,animationEndTime=True)
        
        pm.currentTime(startTime)
        pm.currentTime(startTime + 1)
        pm.currentTime(startTime)
        
        pm.PyNode('nucleus*').startFrame.set(startTime)
        

        #find all nCloth objects
        clothObjects = pm.ls(type='nCloth')
        
        #create simulation cache for all nCloth nodes in the scene
        print ('caching theses nCloth objects: ' + str(clothObjects))
        cacheFiles = pm.cacheFile(cnd=clothObjects, st=startTime, et=endTime, dir=ncachePath, dtf=True, fm='OneFile', r=True, ws=True)
        
        #apply created cache to simulated objects
        cacheShapes = pm.ls('outputCloth*')
        i=0
        for shape in cacheShapes:
            switch = mel.eval('createHistorySwitch(\"' + str(shape) + '\",false)')
            cacheNode = pm.cacheFile(f=cacheFiles[i], cnm=str(shape), ia='%s.inp[0]' % switch ,attachFile=True, dir=ncachePath)
            pm.setAttr( '%s.playFromCache' % switch, 1 )
            i += 1