def testSelectionFlag(self):
        makeRobot()
        MayaCmds.select('bottom', 'leftArm', 'head')
        self.__files.append(util.expandFileName('selectionTest_partial.abc'))
        MayaCmds.AbcExport(j='-sl -root head -root body -root lower -file ' +
                           self.__files[-1])

        self.__files.append(util.expandFileName('selectionTest.abc'))
        MayaCmds.AbcExport(j='-sl -file ' + self.__files[-1])

        MayaCmds.AbcImport(self.__files[-1], m='open')
        self.failUnless(MayaCmds.objExists("robot|head"))
        self.failUnless(MayaCmds.objExists("robot|body|leftArm"))
        self.failUnless(MayaCmds.objExists("robot|lower|bottom"))

        self.failIf(MayaCmds.objExists("robot|body|rightArm"))
        self.failIf(MayaCmds.objExists("robot|body|chest"))
        self.failIf(MayaCmds.objExists("robot|lower|rightLeg"))
        self.failIf(MayaCmds.objExists("robot|lower|leftLeg"))

        MayaCmds.AbcImport(self.__files[-2], m='open')
        self.failUnless(MayaCmds.objExists("head"))
        self.failUnless(MayaCmds.objExists("body|leftArm"))
        self.failUnless(MayaCmds.objExists("lower|bottom"))

        # we didnt actually select any meshes so there shouldnt
        # be any in the scene
        self.failIf(MayaCmds.ls(type='mesh'))
Пример #2
0
    def testAnimIKRW(self):

        name = createJoints()
        handleName = MayaCmds.ikHandle(sj=name, ee='joint4')[0]
        MayaCmds.currentTime(1, update=True)
        MayaCmds.setKeyframe(handleName, breakdown=0, hierarchy='none', controlPoints=False, shape=False)
        MayaCmds.currentTime(16, update=True)
        MayaCmds.move(-1.040057, -7.278225, 6.498725, r=True)
        MayaCmds.setKeyframe(handleName, breakdown=0, hierarchy='none', controlPoints=False, shape=False)

        self.__files.append(util.expandFileName('testAnimIKRW.abc'))
        self.__files.append(util.expandFileName('testAnimIKRW01_08.abc'))
        self.__files.append(util.expandFileName('testAnimIKRW09-16.abc'))

        # write to files
        MayaCmds.AbcExport(j='-fr 1 8 -root %s -f %s' % (name, self.__files[-2]))
        MayaCmds.AbcExport(j='-fr 9 16 -root %s -f %s' % (name, self.__files[-1]))
        MayaCmds.select(name)
        MayaCmds.group(name='original')

        subprocess.call(self.__abcStitcher + self.__files[-3:])

        # read from file
        MayaCmds.AbcImport(self.__files[-3], mode='import')

        # make sure the translate and rotation are the same
        nodes1 = ["|original|joint1", "|original|joint1|joint2", "|original|joint1|joint2|joint3", "|original|joint1|joint2|joint3|joint4"]
        nodes2 = ["|joint1", "|joint1|joint2", "|joint1|joint2|joint3", "|joint1|joint2|joint3|joint4"]

        for t in range(1, 25):
            MayaCmds.currentTime(t, update=True)
            for i in range(0, 4):
                self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i]+'.tx'), MayaCmds.getAttr(nodes2[i]+'.tx'), 4)
                self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i]+'.ty'), MayaCmds.getAttr(nodes2[i]+'.ty'), 4)
                self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i]+'.tz'), MayaCmds.getAttr(nodes2[i]+'.tz'), 4)
Пример #3
0
    def testNamespace(self):
        self.buildScene()
        self.__files.append(util.expandFileName('testNamespace_foo_a.abc'))
        self.__files.append(util.expandFileName('testNamespace_bar_a.abc'))
        self.__files.append(util.expandFileName('testNamespace_a.abc'))

        MayaCmds.AbcExport(j='-root foo:a -fr 1 4 -file ' + self.__files[-3])
        MayaCmds.AbcExport(j='-root bar:a -fr 1 4 -file ' + self.__files[-2])
        MayaCmds.AbcExport(j='-root a -fr 1 4 -file ' + self.__files[-1])

        self.buildStatic()
        MayaCmds.AbcImport(self.__files[-3], connect='foo:a')
        self.failUnless(
            'testNamespace_foo_a_AlembicNode.outPolyMesh[0]' == MayaCmds.
            connectionInfo("|foo:a|foo:b|foo:bShape.inMesh", sfd=True))

        MayaCmds.AbcImport(self.__files[-2], connect='bar:a')
        self.failUnless(
            'testNamespace_bar_a_AlembicNode.outPolyMesh[0]' == MayaCmds.
            connectionInfo("|bar:a|bar:b|bar:bShape.inMesh", sfd=True))

        MayaCmds.AbcImport(self.__files[-1], connect='a')
        self.failUnless(
            'testNamespace_a_AlembicNode.outPolyMesh[0]' ==
            MayaCmds.connectionInfo("|a|b|bShape.inMesh", sfd=True))
Пример #4
0
    def verifyProps(self, root, nodeName, wfgAndMoblur):

        # write to files
        if wfgAndMoblur:
            # reset __files so we wont try to tear down files that dont exist
            self.__files = [self.__files[0]]
            MayaCmds.AbcExport(j='-atp SPT_ -fr 1 24 -wfg -frs -0.25 -frs 0.0 -frs 0.25 -root %s -file %s' % (root, self.__files[0]))
        else:
            MayaCmds.AbcExport(j='-atp SPT_ -fr 1 14 -root %s -file %s' % (root, self.__files[1]))
            MayaCmds.AbcExport(j='-atp SPT_ -fr 15 24 -root %s -file %s' % (root, self.__files[2]))

            subprocess.call(self.__abcStitcher + self.__files)

        # read file and verify data
        MayaCmds.AbcImport(self.__files[0], mode='open')

        t = 1  # frame 1
        MayaCmds.currentTime(t, update=True)
        self.failUnlessEqual(0, MayaCmds.getAttr(nodeName + '.SPT_int8'),
            '%s.SPT_int8 != 0 at frame %d' % (nodeName, t))
        self.failUnlessEqual(100, MayaCmds.getAttr(nodeName + '.SPT_int16'),
            '%s.SPT_int16 != 100 at frame %d' % (nodeName, t))
        self.failUnlessEqual(1000, MayaCmds.getAttr(nodeName + '.SPT_int32'),
            '%s.SPT_int32 != 1000 at frame %d' % (nodeName, t))
        self.failUnlessAlmostEqual(0.57777777,
            MayaCmds.getAttr(nodeName + '.SPT_float'), 4,
            '%s.SPT_float != 0.57777777 at frame %d' % (nodeName, t))
        self.failUnlessAlmostEqual(5.045643545457,
            MayaCmds.getAttr(nodeName + '.SPT_double'), 7,
            '%s.SPT_double != 5.045643545457 at frame %d' % (nodeName, t))

        t = 12  # frame 12
        MayaCmds.currentTime(t, update=True)
        self.failUnlessEqual(8, MayaCmds.getAttr(nodeName + '.SPT_int8'),
            '%s.SPT_int8 != 8 at frame %d' % (nodeName, t))
        self.failUnlessEqual(16, MayaCmds.getAttr(nodeName + '.SPT_int16'),
            '%s.SPT_int16 != 16 at frame %d' % (nodeName, t))
        self.failUnlessEqual(32, MayaCmds.getAttr(nodeName + '.SPT_int32'),
            '%s.SPT_int32 != 32 at frame %d' % (nodeName, t))
        self.failUnlessAlmostEqual(3.141592654,
            MayaCmds.getAttr(nodeName + '.SPT_float'), 4,
            '%s.SPT_float != 3.141592654 at frame %d' % (nodeName, t))
        self.failUnlessAlmostEqual(3.1415926547,
            MayaCmds.getAttr(nodeName + '.SPT_double'), 7,
            '%s.SPT_double != 3.141592654 at frame %d' % (nodeName, t))

        t = 24  # frame 24
        MayaCmds.currentTime(t, update=True)
        self.failUnlessEqual(0, MayaCmds.getAttr(nodeName + '.SPT_int8'),
            '%s.SPT_int8 != 0 at frame %d' % (nodeName, t))
        self.failUnlessEqual(100, MayaCmds.getAttr(nodeName + '.SPT_int16'),
            '%s.SPT_int16 != 100 at frame %d' % (nodeName, t))
        self.failUnlessEqual(1000, MayaCmds.getAttr(nodeName + '.SPT_int32'),
            '%s.SPT_int32 != 1000 at frame %d' % (nodeName, t))
        self.failUnlessAlmostEqual(0.57777777,
            MayaCmds.getAttr(nodeName + '.SPT_float'), 4,
            '%s.SPT_float != 0.57777777 at frame %d' % (nodeName, t))
        self.failUnlessAlmostEqual(5.045643545457,
            MayaCmds.getAttr(nodeName + '.SPT_double'), 7,
            '%s.SPT_double != 5.045643545457 at frame %d' % (nodeName, t))
Пример #5
0
    def testAnimCameraReadWrite(self):

        name = createCamera()
        MayaCmds.currentTime(1, update=True)
        MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture')
        MayaCmds.setKeyframe(name[1], attribute='focalLength')
        MayaCmds.setKeyframe(name[1], attribute='focusDistance')
        MayaCmds.setKeyframe(name[1], attribute='shutterAngle')
        MayaCmds.currentTime(24, update=True)
        MayaCmds.setKeyframe(name[1], attribute='horizontalFilmAperture',
            value=0.95)
        MayaCmds.setKeyframe(name[1], attribute='focalLength', value=40)
        MayaCmds.setKeyframe(name[1], attribute='focusDistance', value=5.4)
        MayaCmds.setKeyframe(name[1], attribute='shutterAngle', value=174.94)

        self.__files.append(util.expandFileName('testAnimCameraReadWrite.abc'))
        self.__files.append(util.expandFileName('testAnimCameraReadWrite01_14.abc'))
        self.__files.append(util.expandFileName('testAnimCameraReadWrite15-24.abc'))

        # write to files
        MayaCmds.AbcExport(j='-fr 1 14 -root %s -file %s' % (name[0], self.__files[-2]))
        MayaCmds.AbcExport(j='-fr 15 24 -root %s -file %s' % (name[0], self.__files[-1]))

        subprocess.call(self.__abcStitcher + self.__files[-3:])

        # read from file
        MayaCmds.AbcImport(self.__files[-3], mode='import')
        camList = MayaCmds.ls(type='camera')

        for t in range(1, 25):
            MayaCmds.currentTime(t, update=True)
            if not util.compareCamera(camList[0], camList[1]):
                self.fail('%s and %s are not the same at frame %d' %
                    (camList[0], camList[1], t))
    def test_agst(self):

        # animated geometry, static transform node
        nodename = 'agst_node'
        MayaCmds.polyCube(name=nodename)
        MayaCmds.select(nodename + '.vtx[0:8]')
        MayaCmds.setKeyframe(time=1.0)
        MayaCmds.scale(1.5, 1.5, 1.8)
        MayaCmds.setKeyframe(time=5.0)

        self.__files.append(
            util.expandFileName('agst_motionblur_noSampleGeo_Test.abc'))
        MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -wfg -root %s -file %s' %
                           (nodename, self.__files[-1]))

        # frameRange: 1, 2, 3, 4, 5, 6
        self.isFrameRangeTransAndFrameRangeShapeExists(self.__files[-1])

        self.__files.append(util.expandFileName('agst_motionblur_Test.abc'))
        MayaCmds.AbcExport(j='-fr 1 5 -step 0.5 -root %s -f %s' %
                           (nodename, self.__files[-1]))

        # frameRange: 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6
        self.isFrameRangeExists(self.__files[-1])

        self.__files.append(util.expandFileName('agst_noSampleGeo_Test.abc'))
        MayaCmds.AbcExport(j='-fr 1 5 -wfg -root %s -f %s' %
                           (nodename, self.__files[-1]))

        # frameRange: 1, 2, 3, 4, 5
        self.isFrameRangeExists(self.__files[-1])
Пример #7
0
    def testPreRollRanges(self):
        self.createXformNode()

        # Export (1, 10), [11, 100], (101, 109), [110, 200]
        __builtins__['framesList'] = []
        self.__files.append(util.expandFileName('testPreRollRanges1.abc'))
        MayaCmds.AbcExport(
            j='-fr 1 10 -pr -fr 11 100 -fr 101 109 -pr -fr 110 200 -root test -pfc framesList.append(#FRAME#) -file '
            + self.__files[-1])

        referenceList = []
        for i in range(11, 101):
            referenceList.append(i)
        for i in range(110, 201):
            referenceList.append(i)
        self.failUnlessEqual(framesList, referenceList)

        # Import
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # Test sampling points
        self.failUnlessXformValuesEqual([(11, 10), (100, 20), (110, 20),
                                         (200, 10)])

        # Test not-sampled points
        self.failUnlessXformValuesEqual([(1, 10), (105, 20), (205, 10)])

        # Another pre roll test
        MayaCmds.file(new=True, force=True)
        self.createXformNode()

        # Export [1, 10], (11, 99), [100, 110], (111, 200)
        __builtins__['framesList'] = []
        self.__files.append(util.expandFileName('testPreRollRanges2.abc'))
        MayaCmds.AbcExport(
            j='-fr 1 10 -fr 11 99 -pr -fr 100 110 -fr 111 200 -pr -root test -pfc framesList.append(#FRAME#) -file '
            + self.__files[-1])

        referenceList = []
        for i in range(1, 11):
            referenceList.append(i)
        for i in range(100, 111):
            referenceList.append(i)
        self.failUnlessEqual(framesList, referenceList)

        # Import
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # Test sampling points
        self.failUnlessXformValuesEqual([(1, 10), (3, 20), (10, 20), (100, 20),
                                         (110, 20)])

        # Test not-sampled points
        self.failUnlessXformValuesEqual([(11, 20), (50, 20), (200, 20)])
Пример #8
0
def exportAbc():
    argments = exportArgumentsCreator()

    if type(argments) is list:
        for argment in argments:
            try:
                cmds.AbcExport(j=argment)
            except:
                cmds.warning(argment+' is error,check the scene!')
                continue
    elif type(argments) is str:
        try:
            cmds.AbcExport(j=argment)
        except:
            cmds.warning('Export Error Occurs, Check the scene')
Пример #9
0
def export_abc(start_frame,
               end_frame,
               tar_path,
               root,
               uv_write=True,
               renderable_only=True,
               attribute=None):
    if isinstance(root, basestring):
        root = [root]
    if isinstance(attribute, basestring):
        attribute = [attribute]
    tar_dir = os.path.dirname(tar_path)
    if not os.path.isdir(tar_dir):
        os.makedirs(tar_dir)
    load_plugin("AbcExport.mll")
    j_base_string = "-frameRange {start_frame} {end_frame} -worldSpace" \
                    " -writeVisibility -file {tar_path}"
    if uv_write:
        j_base_string += " -uvWrite"
    if renderable_only:
        j_base_string += " -renderableOnly"
    if attribute:
        for attr in attribute:
            j_base_string += " -u %s" % attr
    for r in root:
        j_base_string += " -root %s" % r
    j_string = j_base_string.format(start_frame=start_frame,
                                    end_frame=end_frame,
                                    tar_path=tar_path)
    mc.AbcExport(j=j_string)
Пример #10
0
    def testStaticVisibility(self):
        poly1 = MayaCmds.polyPlane(sx=2, sy=2, w=1, h=1, ch=0)[0]
        group1 = MayaCmds.group()
        group2 = MayaCmds.createNode("transform")
        MayaCmds.select(group1, group2)
        group3 = MayaCmds.group()

        group4 = (MayaCmds.duplicate(group1, rr=1))[0]
        group5 = MayaCmds.group()

        MayaCmds.select(group3, group5)
        root = MayaCmds.group(name='root')

        MayaCmds.setAttr(group1 + '.visibility', 0)
        MayaCmds.setAttr(group2 + '.visibility', 0)
        MayaCmds.setAttr(group5 + '.visibility', 0)

        self.__files.append(util.expandFileName('staticVisibilityTest.abc'))
        MayaCmds.AbcExport(j='-wv -root %s -file %s' %
                           (root, self.__files[-1]))

        MayaCmds.AbcImport(self.__files[-1], m='open')
        self.failIf(MayaCmds.getAttr(group1 + '.visibility'))
        self.failIf(MayaCmds.getAttr(group2 + '.visibility'))
        self.failIf(MayaCmds.getAttr(group5 + '.visibility'))

        self.failUnless(MayaCmds.getAttr(group1 + '|' + poly1 + '.visibility'))
        self.failUnless(MayaCmds.getAttr(group4 + '|' + poly1 + '.visibility'))
        self.failUnless(MayaCmds.getAttr(group3 + '.visibility'))
        self.failUnless(MayaCmds.getAttr(group4 + '.visibility'))
        self.failUnless(MayaCmds.getAttr(root + '.visibility'))
Пример #11
0
def publishFile(abcFilename):
    #get workspace
    workspace = cmds.workspace(q=True, directory=True, rd=True)
    workspaceLen = len(workspace.split('/'))
    #get filename
    filename = cmds.file(q=True, sn=True)
    #get relative path (from scenes)
    relativePath = ''
    for dir in filename.split('/')[workspaceLen:-1]:
        relativePath += '%s/' % (dir)

    #string of objects to export
    exportString = ''
    sel = cmds.ls(sl=True)
    for item in sel:
        exportString += ' -root %s' % (item)

    #get timeline
    startFrame = int(cmds.playbackOptions(q=True, minTime=True))
    endFrame = int(cmds.playbackOptions(q=True, maxTime=True))

    #set folder to export to
    folderPath = '%scache/alembic/%s' % (workspace, relativePath)
    if not os.path.exists(folderPath):
        os.makedirs(folderPath)

    #check if plugin is already loaded
    if not cmds.pluginInfo('AbcImport', query=True, loaded=True):
        try:
            #load abcExport plugin
            cmds.loadPlugin('AbcImport')
        except:
            cmds.error('Could not load AbcImport plugin')

    #export .abc
    additionalAttr = ''
    #IO attributes
    additionalAttributes = ['alembicName', 'IOID', 'material']
    #redshift attributes
    additionalAttributes += [
        'rsObjectId', 'rsEnableSubdivision', 'rsMaxTessellationSubdivs',
        'rsDoSmoothSubdivision', 'rsMinTessellationLength',
        'rsOutOfFrustumTessellationFactor', 'rsEnableDisplacement',
        'rsMaxDisplacement', 'rsDisplacementScale'
    ]
    for attr in additionalAttributes:
        additionalAttr += ' -attr %s' % (attr)
    command = '-frameRange %d %d%s -uvWrite -writeVisibility -wholeFrameGeo -worldSpace -writeUVSets -dataFormat ogawa%s -file \"%scache/alembic/%s%s.abc\"' % (
        startFrame, endFrame, additionalAttr, exportString, workspace,
        relativePath, abcFilename)
    #load plugin
    if not cmds.pluginInfo('AbcExport', query=True, loaded=True):
        try:
            #load abcExport plugin
            cmds.loadPlugin('AbcExport')
        except:
            cmds.error('Could not load AbcExport plugin')
    #write to disk
    cmds.AbcExport(j=command)
    return '%scache/alembic/%s%s.abc' % (workspace, relativePath, abcFilename)
Пример #12
0
    def testWholeFrameGeo(self):
        self.createXformNode()
        self.createCubeNode()

        # Export [2, 4]{-0.2, 0, 0.2}:2 [10, 10]{-0.5, 0, 0.5} -wfg
        # i.e. xform: 1.8, 2, 2.2, 3.8, 4, 4.2, 9.5, 10, 10.5
        #   geometry: 2, 4, 10
        __builtins__['framesList'] = []
        self.__files.append(util.expandFileName('testWholeFrameGeos.abc'))
        MayaCmds.AbcExport(j='-fr 2 4 -s 2 -frs -0.2 -frs 0 -frs 0.2 -fr 10 10 -frs -0.5 -frs 0 -frs 0.5 -wfg -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1])

        self.failUnlessEqual(framesList, [1.8, 2, 2.2, 3.8, 4, 4.2, 9.5, 10, 10.5])

        # Import
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # Test sampling xform points
        self.failUnlessXformValuesEqual([(1.8, 14), (2, 15), (2.2, 16), (3.8, 20), (4, 20), (4.2, 20), (9.5, 20), (10, 20), (10.5, 15)])

        # Test not-sampled xform points
        self.failUnlessXformValuesEqual([(2.8, 17.5), (3, 18), (3.2, 18.5)])  # lerp

        # Test sampling mesh points
        self.failUnlessCubeWidthEqual([(2, 20), (4, 20), (10, 20)])

        # Test not-sampled cube points
        # No subsample for the cube
        self.failUnlessCubeWidthEqual([(2.2, 20), (3.8, 20), (4.2, 20)])
Пример #13
0
    def testThreeFrameRanges(self):
        self.createXformNode()

        # Export 3 frame ranges: [1,3], [10,11], [110, 200]
        __builtins__['framesList'] = []
        self.__files.append(util.expandFileName('testThreeFrameRanges.abc'))
        MayaCmds.AbcExport(j='-fr 1 3 -fr 10 11 -fr 110 200 -root test -pfc framesList.append(#FRAME#) -file ' + self.__files[-1])

        referenceList = []
        for i in range(1, 4):
            referenceList.append(i)
        for i in range(10, 12):
            referenceList.append(i)
        for i in range(110, 201):
            referenceList.append(i)
        self.failUnlessEqual(framesList, referenceList)

        # Import
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # Test sampling points
        self.failUnlessXformValuesEqual([(1, 10), (3, 20), (10, 20), (11, 10), (110, 20), (200, 10)])

        # Test not-sampled points
        self.failUnlessXformValuesEqual([(7, 20), (60.5, 15)])  # lerp
Пример #14
0
def abcExporter(exportedName):
    #Check abcPlugins load
    if not cmds.pluginInfo("AbcExport", q=True, loaded=True):
        cmds.loadPlugin("AbcExport")
        cmds.pluginInfo("AbcExport", edit=True, autoload=True)
        cmds.pluginInfo("AbcImport", edit=True, autoload=True)

    #Nom du fichier ABC - Où sauvegarder le fichier ABC - Quelles frames à exporter
    ABCSFrame = cmds.textField('ABCSF', query=True, text=True)
    ABCEFrame = cmds.textField('ABCEF', query=True, text=True)
    ABCSavePath = cmds.textField('ABCSPath', query=True, text=True) + '\\'
    ABCFileName = cmds.textField('ABCFName', query=True, text=True)
    ABCExt = ".abc"
    ABCFileName_reformat = ABCFileName + '_' + exportedName + ABCExt  #Path
    ABCFilePath = os.path.join(ABCSavePath, ABCFileName_reformat)

    #Prepare the selection
    sel = cmds.ls(sl=1, l=1)
    z = ""
    for i in sel:
        z += " -root " + i

    #Save the abc File
    command = "-frameRange " + str(ABCSFrame) + " " + str(
        ABCEFrame
    ) + " -stripNamespaces -uvWrite -worldSpace -dataFormat ogawa" + z + " -file " + ABCFilePath
    cmds.AbcExport(j=command)
Пример #15
0
    def export_file_abc(cls, list_objects, file_dir, file_name, file_ext,
                        frame_start, frame_end):

        # load plugins
        list_plugins = ['AbcExport.so', 'AbcImport.so']
        for i in list_plugins:
            if not mc.pluginInfo(i, q=True, loaded=True):
                mc.loadPlugin(i)
        # cmd_frame_range
        cmd_frame_range = " ".join(
            ["-frameRange", str(frame_start),
             str(frame_end)])
        # cmd_options
        cmd_options = " ".join([
            "-uvWrite", "-worldSpace", "-writeVisibility", "-dataFormat ogawa",
            "-writeUVSets"
        ])
        # cmd_root: items to export
        cmd_root = ""
        for i in list_objects:
            root_each = " ".join(["-root", i]) + " "
            cmd_root += root_each
        # cmd_path
        path_full = os.path.join(file_dir, '.'.join(
            (file_name, file_ext))).replace("\\", "/")
        cmd_path = " ".join(["-file", path_full])
        # cmd
        cmd = " ".join([cmd_frame_range, cmd_options, cmd_root, cmd_path])
        # do export
        mc.AbcExport(j=cmd)
Пример #16
0
def exportAbcMesh(scene, isStaticMesh=True):
	"""
	Export Alembics mesh from specified maya scene, with isStaticMesh boolean to control whether to export 1 single frame or animation with full frame range 
	"""
	if os.path.isfile(scene):
		cmds.file(scene, open=True, force=True)

		meshes = cmds.listRelatives(cmds.ls(type='mesh', v=True), p=True, fullPath=True)
		cmds.select(meshes)

		# string which returns the long root path to the mesh name
		abcStr = ''
		for obj in cmds.ls(sl=True, l=True):
			abcStr += ' -root ' + obj

		cmds.loadPlugin("AbcExport.so")

		if isStaticMesh:
			# export static mesh: 1 single frame
			start, end = 1,1
		else:
			# export mesh animation: min & max time of the frame range
			start, end = cmds.playbackOptions(q=True, minTime=True), cmds.playbackOptions(q=True, maxTime=True) 

		# swap the maya file for abc
		exportPath = scene.replace('.ma', '.abc')
		abcStr = '%s -frameRange %s %s -uvWrite -file %s' % (abcStr, start, end, exportPath)
		cmds.AbcExport(j = abcStr)
		return exportPath
Пример #17
0
def maya2Abc(mayaParent,
             mayaSelection,
             filepath,
             startFrame=None,
             endFrame=None,
             abcOptions=''):
    # check that we actually have elements in the mayaSelection
    if mayaSelection:
        # create the directory if it doesn't exist
        dir = os.path.dirname(filepath)
        if not os.path.isdir(dir):
            os.makedirs(dir)
        abcCommandString = abcOptions + ' -root ' + ' -root '.join(
            mayaSelection) + ' -uvWrite -file ' + filepath
        # add Python callback to store bounding box information
        #abcCommandString = 'pythonPerFrameCallback=maya2scenegraphXML.maya2abcCallback(mayaNode="'+mayaParent+'",frame=#FRAME#,bounds=#BOUNDSARRAY#) ' + abcCommandString
        abcCommandString = '-pythonPerFrameCallback maya2scenegraphXML.maya2abcCallback(mayaNode="' + mayaParent + '",frame=#FRAME#,bounds=#BOUNDSARRAY#) ' + abcCommandString
        if startFrame is not None and endFrame is not None:
            abcCommandString = '-frameRange ' + str(startFrame) + ' ' + str(
                endFrame) + ' ' + abcCommandString
            #abcCommandString = 'range ' + str(startFrame) + ' ' + str(endFrame) + ' ' + abcCommandString

        print "Command string: %s" % abcCommandString
        cmds.AbcExport(j=abcCommandString)
    else:
        print "Warning: %s doesn't have any children to export as a component" % mayaParent
Пример #18
0
def makeAlembic(refName, publishString):
    try:
        #check if plug is already loaded
        if not cmds.pluginInfo('AbcExport', query=True, loaded=True):
            try:
                #load abcExport plugin
                cmds.loadPlugin('AbcExport')
            except:
                cmds.error('Could not load AbcExport plugin')
        #make folder
        modelFolder = '%scache/alembic/models' % (cmds.workspace(q=True,
                                                                 rd=True))
        if not os.path.exists(modelFolder):
            os.makedirs(modelFolder)
        #export .abc
        additionalAttr = ''
        #IO attributes
        additionalAttributes = [
            'alembicName', 'material', 'IOID', 'connections'
        ]
        #redshift attributes
        additionalAttributes += [
            'rsObjectId', 'rsEnableSubdivision', 'rsMaxTessellationSubdivs',
            'rsDoSmoothSubdivision', 'rsMinTessellationLength',
            'rsOutOfFrustumTessellationFactor', 'rsEnableDisplacement',
            'rsMaxDisplacement', 'rsDisplacementScale'
        ]
        for attr in additionalAttributes:
            additionalAttr += ' -attr %s' % (attr)
        command = '-frameRange 1 1%s -stripNamespaces -uvWrite -worldSpace -writeVisibility -writeUVSets -dataFormat ogawa -root %s -file models/%s.abc' % (
            additionalAttr, publishString, refName)
        cmds.AbcExport(j=command)
        return '%s/%s.abc' % (modelFolder, refName)
    except:
        return 'unable to export .abc'
Пример #19
0
    def export_abc(self, file, shapes_list):

        start = str(self.range[0])
        end = str(self.range[1])

        percent_step = 100.0/(int(end)-int(start))
        script = "import maya.cmds as cmds\\n"
        script += "import time\\n"
        script += "current_frame = cmds.currentTime( query=True )\\n"
        script += "percent = (current_frame - {})*{}\\n".format(int(start), round(percent_step, 1))
        script += "print('percent:'+str(percent))\\n"
        script += "time.sleep(0.01)"

        command = "-frameRange "
        command += start
        command += " "
        command += end
        command += " -step 1"
        command += " -frameRelativeSample -0.2 -frameRelativeSample 0 -frameRelativeSample 0.2 -attr GuerillaTags -writeVisibility -writeUVSets -uvWrite -worldSpace "
        for shape in shapes_list:
            command += '-root {} '.format(shape)
        command += '-pythonPerFrameCallback "{}"'.format(script)
        command += " -dataFormat ogawa -file "
        command += file
        logging.info(command)
        cmds.AbcExport(j=command)
Пример #20
0
 def testStaticTransformPropReadWrite(self):
     nodeName = MayaCmds.createNode('transform')
     self.setProps(nodeName)
     self.__files.append(util.expandFileName('staticPropTransform.abc'))
     MayaCmds.AbcExport(j='-atp SPT_ -root %s -file %s' %
                        (nodeName, self.__files[-1]))
     self.verifyProps(nodeName, self.__files[-1])
    def testSubD(self):
        trans = MayaCmds.polyPlane(n='plane', sx=1, sy=1, ch=False)[0]
        shape = MayaCmds.pickWalk(d='down')[0]
        MayaCmds.addAttr(attributeType='bool',
                         defaultValue=1,
                         keyable=True,
                         longName='SubDivisionMesh')
        MayaCmds.select(trans + '.vtx[0:3]', r=True)
        MayaCmds.move(0, 1, 0, r=True)
        MayaCmds.currentTime(1, update=True)
        MayaCmds.setKeyframe()
        MayaCmds.currentTime(2, update=True)
        MayaCmds.move(0, 5, 0, r=True)
        MayaCmds.setKeyframe()

        self.__files.append(util.expandFileName('testSubDInterpolation.abc'))
        MayaCmds.AbcExport(j='-fr 1 2 -root %s -file %s' %
                           (trans, self.__files[-1]))
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        MayaCmds.currentTime(1.004, update=True)
        ty = MayaCmds.getAttr(shape + '.vt[0]')[0][1]
        self.failUnlessAlmostEqual(1.02, ty)

        setTime = MayaCmds.currentTime(1.422, update=True)
        alpha = (setTime - 1) / (2 - 1)
        ty = MayaCmds.getAttr(shape + '.vt[0]')[0][1]
        self.failUnlessAlmostEqual(ty, (1 - alpha) * 1.0 + alpha * 6.0, 3)
Пример #22
0
    def testStaticIKRW(self):

        name = createJoints()
        MayaCmds.ikHandle(sj=name, ee='joint4')
        MayaCmds.move(-1.040057, -7.278225, 6.498725, r=True)

        # write to file
        self.__files.append(util.expandFileName('testStaticIK.abc'))
        MayaCmds.AbcExport(j='-root %s -f %s' % (name, self.__files[-1]))
        MayaCmds.select(name)
        MayaCmds.group(name='original')

        # read from file
        MayaCmds.AbcImport(self.__files[-1], mode='import')

        # make sure the translate and rotation are the same
        nodes1 = [
            "|original|joint1", "|original|joint1|joint2",
            "|original|joint1|joint2|joint3",
            "|original|joint1|joint2|joint3|joint4"
        ]
        nodes2 = [
            "|joint1", "|joint1|joint2", "|joint1|joint2|joint3",
            "|joint1|joint2|joint3|joint4"
        ]
        for i in range(0, 4):
            self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i] + '.tx'),
                                       MayaCmds.getAttr(nodes2[i] + '.tx'), 4)
            self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i] + '.ty'),
                                       MayaCmds.getAttr(nodes2[i] + '.ty'), 4)
            self.failUnlessAlmostEqual(MayaCmds.getAttr(nodes1[i] + '.tz'),
                                       MayaCmds.getAttr(nodes2[i] + '.tz'), 4)
Пример #23
0
    def export(frameRange=[0, 0], attrs=list(), root=None, filename=''):

        root_pointer = ''
        if root:
            if not cmds.objExists(root):
                logger.info("root is not in scene")
                return

            root_pointer = " -root {}".format(root)

        start = 0
        end = 120
        range = "-frameRange {0} {1} ".format(start, end)

        vars = ""
        if attrs:
            for a in attrs:
                vars += " -attr {}".format(a)

        save_name = " -file {}".format(filename)
        uv = " -uvWrite"
        ws = " -worldSpace"
        dataFormat = ' -dataFormat ogawa'
        command = range + vars + root_pointer + dataFormat + uv + ws + save_name

        # logger.info(command)

        cmds.AbcExport(j=command)
Пример #24
0
    def testStep(self):
        self.createXformNode()

        # Export [1, 10]:5 [100, 200]:10
        __builtins__['framesList'] = []
        self.__files.append(util.expandFileName('testStepRanges.abc'))
        MayaCmds.AbcExport(
            j='-fr 0 10 -s 5 -fr 100 200 -s 10 -root test -pfc framesList.append(#FRAME#) -file '
            + self.__files[-1])

        referenceList = []
        for i in range(0, 11, 5):
            referenceList.append(i)
        for i in range(100, 201, 10):
            referenceList.append(i)
        self.failUnlessEqual(framesList, referenceList)

        # Import
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # Test sampling points
        self.failUnlessXformValuesEqual([(0, 10), (5, 20), (10, 20), (100, 20),
                                         (110, 20), (200, 10)])

        # Test not-sampled points
        self.failUnlessXformValuesEqual([(2.5, 15)])  # lerp
Пример #25
0
def exportAlembic(exportPath, minFrame, maxFrame):
    def getCurrentModelPanels():
        pannels = cmds.getPanel(vis=1)
        modelPanels = []
        for pannel in pannels:
            if cmds.modelPanel(pannel, ex=1):
                modelPanels.append(pannel)
        return modelPanels

    def getTopTransformNodes():
        topNodes = cmds.ls(sl=1)
        if not topNodes:
            sels = cmds.ls(l=1, type='transform')
            topNodes = []
            for sel in sels:
                if len(sel.split('|')) == 2:
                    topNodes.append(sel)
        return topNodes

    makeFolder(os.path.dirname(exportPath))

    exportRoots = getTopTransformNodes()

    rootStr = ''
    for exportRoot in exportRoots:
        rootStr += ' -root %s ' % exportRoot

    cmds.AbcExport( j="-frameRange %d %d -noNormals -ro -uvWrite -wholeFrameGeo -writeVisibility -eulerFilter"\
                " -dataFormat ogawa %s -file %s" %( minFrame, maxFrame, rootStr, exportPath ) )
Пример #26
0
    def testPolyUVs(self):
        MayaCmds.polyCube(name='cube')
        cubeObj = getObjFromName('cubeShape')
        fnMesh = OpenMaya.MFnMesh(cubeObj)

        # get the name of the current UV set
        uvSetName = fnMesh.currentUVSetName()

        uArray = OpenMaya.MFloatArray()
        vArray = OpenMaya.MFloatArray()
        fnMesh.getUVs(uArray, vArray, uvSetName)

        newUArray = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 2, -1, -1]
        newVArray = [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 1, 0, 1]
        for i in range(0, 14):
            uArray[i] = newUArray[i]
            vArray[i] = newVArray[i]
        fnMesh.setUVs(uArray, vArray, uvSetName)

        self.__files.append(util.expandFileName('polyUvsTest.abc'))
        MayaCmds.AbcExport(j='-uv -root cube -file ' + self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        MayaCmds.select('cube.map[0:13]', replace=True)
        uvs = MayaCmds.polyEditUV(query=True)
        for i in range(0, 14):
            self.failUnlessAlmostEqual(newUArray[i], uvs[2 * i], 4,
                                       'map[%d].u is not the same' % i)
            self.failUnlessAlmostEqual(newVArray[i], uvs[2 * i + 1], 4,
                                       'map[%d].v is not the same' % i)
Пример #27
0
    def exportAbc(self, root, frameRange=(1, 24), suffix="", **kargs):

        self.__abc_files.append(
            expandFileName('testAnimParticleReadWrite_%s.abc' % suffix))

        # seed on first frame
        cmds.currentTime(1)
        maya.mel.eval("seed(1)")

        # First, eval time from one to frameRange start to avoid a possible jump
        for i in range(1, frameRange[0]):
            cmds.currentTime(i)

        # Format argument for extra atrbutes
        argStr = " "
        for item in kargs:
            if isinstance(kargs[item], (tuple, list)):
                for element in kargs[item]:
                    argStr += " -%s %s" % (item, element)
            else:
                argStr += " -%s %s" % (item, kargs[item])

        # Export
        stdoutWrite("writefile: %s" % self.__abc_files[-1])
        cmds.AbcExport(j='-fr %d %d -root %s %s -file ' %
                       (frameRange[0], frameRange[1], root, argStr) +
                       self.__abc_files[-1])
Пример #28
0
 def export_out (self):
     self._splitShotName()
     mel = "-frameRange {0} {1} -uvWrite -writeVisibility -dataFormat ogawa -root |cloth_rig|output|out_export|mortando|geo -file P:/bm2/seq/{2}/sho/{3}/cloth/out/bm2_seqsho_seq_{2}_sho_{3}_cloth_mortando_main_out.abc". format(0, self.cut_out, self.shotNumber, self.seqName)
     file = cmds.AbcExport (j=mel)
     file_path_list = []
     file_path_list[0] = file
     self._sendToDropbox(file_path_list, 10)
Пример #29
0
def export_abc(abc_file_name, start_frame, end_frame, selected=True):
    load_plugin()

    def get_export_objects():
        if selected:
            objects = mc.ls(sl=1)
        else:
            all_trans = mc.ls(assemblies=1)
            cameras = mc.ls(cameras=1)
            cam_trans = [mc.listRelatives(cam, parent=1)[0] for cam in cameras]
            objects = list(set(all_trans) - set(cam_trans))
        return objects

    objects = get_export_objects()
    if not objects:
        return
    abc_file_name = abc_file_name.replace('\\', '/')
    j_string = '-framerange {start_frame} {end_frame} -attr Matinfo ' \
               '-uvWrite -worldSpace -writeVisibility -file {tar_path}'
    j_string = j_string.format(start_frame=start_frame,
                               end_frame=end_frame,
                               tar_path=abc_file_name)
    for i in objects:
        j_string += ' -root %s' % i
    print j_string
    mc.AbcExport(j=j_string)
    print "[OF] info: export abc successful"
Пример #30
0
    def testAnimMeshReload(self):

        MayaCmds.polyCube(name='mesh')
        MayaCmds.setKeyframe('meshShape.vtx[0:7]', time=[1, 24])
        MayaCmds.setKeyframe('meshShape.vtx[0:7]')
        MayaCmds.currentTime(12, update=True)
        MayaCmds.select('meshShape.vtx[0:7]')
        MayaCmds.scale(5, 5, 5, r=True)
        MayaCmds.setKeyframe('meshShape.vtx[0:7]', time=[12])
        self.__files.append(util.expandFileName('testAnimMeshReadWrite.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root mesh -f ' + self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # save as a maya file
        self.__files.append(util.expandFileName('test.mb'))
        MayaCmds.file(rename=self.__files[-1])
        MayaCmds.file(save=True)

        # reload as a maya file
        MayaCmds.file(self.__files[-1], open=True)
        MayaCmds.AbcImport(self.__files[-2], mode='import')

        retVal = True
        mesh1 = '|mesh|meshShape'
        mesh2 = '|mesh1|meshShape'
        for t in range(1, 25):
            MayaCmds.currentTime(t, update=True)
            if not util.compareMesh(mesh1, mesh2):
                self.fail('%s and %s were not equal at frame %d' % (mesh1,
                    mesh2, t))