예제 #1
0
def exportTo(name, simplygon=False, unity=False, marmoset=False):
    if simplygon:
        simplygonInfo = readJson(SimplyGonJson)
        if name not in simplygonInfo['Execute']:
            simplygonInfo['Execute'].append(name)
        fbxName = os.path.join(r'F:\Share\simplygon\standby', '%s.fbx' % name)
        cmds.FBXExportEmbeddedTextures('-v', True)
        cmds.FBXExport('-file', fbxName, '-s')
        writeJson(SimplyGonJson, simplygonInfo)

    elif unity:
        unityInfo = readJson(UnityJson)
        unityDirPath = createDirectory(os.path.join(UnityProjectDir, name))
        try:
            cmds.select('s' + name)
        except:
            cmds.warning(u'未找到', 's' + name)
            return name

        if cmds.objExists('shadow'):
            try:
                cmds.parent('shadow', 's' + name)
            except:
                cmds.warning(u'未知原因')
                return name

        else:
            cmds.warning(u'缺少阴影')
            return name

        fbxName = os.path.join(unityDirPath, 's%s.fbx' % name)
        cmds.FBXExport('-file', fbxName, '-s')
        cmds.parent('shadow', world=True)

        upTextures(name, unityDirPath)
        unityInfo['Execute'].append(name)
        writeJson(UnityJson, unityInfo)
    elif marmoset:
        fbxDir = createDirectory(os.path.join(MarmosetDir, 'fbx'))
        fbxName = os.path.join(fbxDir, name + '.fbx')
        try:
            cmds.select('s' + name)
            cmds.FBXExport('-file', fbxName, '-s')
            upTextures(name, fbxDir)
            if name in MayaInfo['Marmoset']:
                MayaInfo['Marmoset'].remove(name)
            if name not in MarmosetInfo['Execute']:
                MarmosetInfo['Execute'].append(name)
        except:
            MayaInfo['Error']['Marmoset'].append(name)
        writeJson(MarmosetJson, MarmosetInfo)
        writeJson(MayaJson, MayaInfo)
예제 #2
0
파일: piliang.py 프로젝트: xbxcw/scripts
def exportFbxPlus(args, args1, path=mc.workspace(fn=True) + '/'):
    dir = path + 'FBX'
    if os.path.exists(dir) is False:
        os.makedirs(dir)
    for name, mesh in zip(args, args1):
        mc.select(mesh)
        mc.FBXExport('-file', dir + '/%s' % name, '-s')
예제 #3
0
    def publish(self, settings, item):
        """
        Executes the publish logic for the given item and settings.

        :param settings: Dictionary of Settings. The keys are strings, matching
            the keys returned in the settings property. The values are `Setting`
            instances.
        :param item: Item to process
        """

        publisher = self.parent

        # get the path to create and publish
        publish_path = item.properties["path"]

        # ensure the publish folder exists:
        publish_folder = os.path.dirname(publish_path)
        self.parent.ensure_folder_exists(publish_folder)
        
        # Export scene to FBX
        try:
            self.logger.info("Exporting scene to FBX {}".format(publish_path))
            cmds.FBXResetExport()
            cmds.FBXExportSmoothingGroups('-v', True)
            # Mel script equivalent: mel.eval('FBXExport -f "fbx_output_path"')
            cmds.FBXExport('-f', publish_path)
        except:
            self.logger.error("Could not export scene to FBX")
            return False

        # The file to publish is the FBX exported to the FBX output path
        # item.properties["path"] = fbx_output_path
            
        # let the base class register the publish
        super(MayaFBXPublishPlugin, self).publish(settings, item)
예제 #4
0
    def exportSM(self, directory):

        # This code selects the joints and meshes only.
        meshes = cmds.ls(selection=True)

        for x in meshes:
            if cmds.objectType(x, isType="joint"):
                print "Nope not SM"
            else:

                # Select the mesh and joints to export
                cmds.select(meshes)

                smFilePath = directory + self.whichAsset.currentText(
                ) + "\\" + "Meshes" + "\\"
                path = self.getPath(smFilePath)

                sceneName = cmds.file(query=True,
                                      sceneName=True,
                                      shortName=True)

                fileName = sceneName.split(".")

                print smFilePath + str(fileName[0]) + ".fbx"

                try:
                    cmds.FBXResetExport()
                    cmds.FBXExportShapes("-v", True)
                    # cmds.FBXExportShapes("-q")

                    cmds.FBXExportSmoothingGroups("-v", True)
                    # cmds.FBXExportSmoothingGroups("-q")
                    cmds.FBXExportTangents("-v", True)
                    # cmds.FBXExportTangents("-q")
                    cmds.FBXExportSmoothMesh("-v", True)
                    # cmds.FBXExportSmoothMesh("-q")
                    cmds.FBXExportReferencedAssetsContent("-v", True)
                    # cmds.FBXExportReferencedAssetsContent("-q")

                    # Connections
                    cmds.FBXExportInputConnections("-v", False)
                    # cmds.FBXExportInputConnections("-q")

                    # Axis Conversion
                    cmds.FBXExportUpAxis("y")
                    # cmds.FBXExportUpAxis("-q")

                    cmds.FBXExportFileVersion("-v", "FBX201400")

                    # Export!
                    cmds.FBXExportInAscii("-v", True)
                    cmds.FBXExport("-f",
                                   smFilePath + str(fileName[0]) + ".fbx",
                                   "-s")

                except RuntimeError, err:
                    print str(err)
예제 #5
0
 def _maya_export_fbx(self, fbx_output_path):
     # Export scene to FBX
     try:
         self.logger.info("Exporting scene to FBX {}".format(fbx_output_path))
         cmds.FBXResetExport()
         cmds.FBXExportSmoothingGroups('-v', True)
         # Mel script equivalent: mel.eval('FBXExport -f "fbx_output_path"')
         cmds.FBXExport('-f', fbx_output_path)
     except:
         self.logger.error("Could not export scene to FBX")
         return False
         
     return True
예제 #6
0
    def export_fbx(self, fbx_args):
        """
        Export to FBX given a list of arguments.

        :param fbx_args: The list of arguments for fbx command to execute
        :return: True if successful, False otherwise.
        """
        selected_groups = cmds.ls(sl=True)
        if selected_groups:
            self.logger.debug('Exporting => {}'.format(selected_groups))
        else:
            self.logger.debug('Exporting all')

        try:
            cmds.FBXResetExport()

            # Extra checkboxes to set prior to export
            cmds.FBXExportSmoothingGroups('-v', True)
            cmds.FBXExportTangents('-v', True)
            cmds.FBXExportSmoothMesh('-v', True)
            cmds.FBXExportReferencedAssetsContent('-v', True)
            cmds.FBXExportBakeComplexAnimation('-v', fbx_args[2])
            cmds.FBXExportEmbeddedTextures('-v', fbx_args[3])
            cmds.FBXExportFileVersion('-v', FBX_EXPORT_VERSION)

            cmds.FBXExportGenerateLog('-v', False)
            self.logger.debug('FBX args => {}'.format(fbx_args))
            self.logger.debug("cmds.FBXExport('-f', {0}, {1})".format(
                fbx_args[0], fbx_args[1]))
            cmds.FBXExport('-f', fbx_args[0], fbx_args[1])

        except Exception as e:
            self.logger.error("Could not export {} to FBX. {}".format(
                selected_groups, e))
            return False

        return True
예제 #7
0
def exportFBX(path, selection=True):
    if selection is True:
        cmds.FBXExport('-file', path, '-s')
    if selection is False:
        cmds.FBXExport('-file', path)
예제 #8
0
        #Set exportpath and name without extension
        exportName = os.path.join(unityPath, rawName)
        print 'Exported: ' + fileName + ' to: \n' + unityPath + '\n'
        #Set export settings
        cmds.loadPlugin('fbxmaya.mll')
        mel.eval('FBXResetExport')
        mel.eval('FBXExportSmoothingGroups -v true')
        #Tangents and binormals
        #mel.eval('FBXExportTriangulate -v true')
        mel.eval('FBXExportTangents -v true')
        #mel.eval('FBXExportAnimationOnly -v true')
        #mel.eval('FBXExportQuaternion -v euler')
        mel.eval('FBXExportBakeComplexAnimation -v true')
        mel.eval('FBXExportBakeResampleAnimation -v true')
        #mel.eval('FBXExportConstraints -v true')
        #Eventuellt: mel.eval('FBXExportBakeResampleAll -v true')
        #deformed models
        mel.eval('FBXExportShapes -v true')
        mel.eval('FBXExportSkins -v true')
        #children?
        mel.eval('FBXExportInputConnections -v true')
        mel.eval('FBXExportScaleFactor 1.0')
        mel.eval('FBXExportUpAxis y')
        mel.eval('FBXExportFileVersion "FBX201400/201500"') 
        mel.eval('FBXExportConvertUnitString "cm"')
        mel.eval('FBXExportInAscii -v true')
        mel.eval('FBXExportGenerateLog -v true')
        #Export files 
        cmds.FBXExport('-file', exportName + '.fbx'.format(unityPath,fileName), '-s')
print '\nBatch Export Successful!'
 
예제 #9
0
def P5exporter():

    ############# Check if scene is set to Meteres #########################
    if cmds.currentUnit(query=True, linear=True) == 'm':

        ###### Makes sure the scene is saved ####################
        if cmds.file(q=True, modified=True):
            cmds.SaveScene()

        PLUGIN = 'fbxmaya.mll'

        ###################### Find scene path ##################
        if cmds.file(q=True, sn=True):

            maSaveLocation = cmds.file(q=True, sn=True)
            convertedPath = os.path.dirname(os.path.abspath(maSaveLocation))

        else:
            cmds.warning('Scene is still not saved')

        #################### Convert MA save path to new FBX path ##########

        expPath = GetPath.GetPath('fbx', maSaveLocation)
        expPathMel = expPath.replace('\\', '/')

        ############## Duplicate, combine and rename ###################
        def duplicateCombine(selection, name):
            children = cmds.listRelatives(selection, path=True)
            if len(children) == 1:
                cmds.duplicate(children[0], n=name)
                cmds.parent(name, 'LOD0_')
            else:
                cmds.delete(cmds.polyUnite(cmds.duplicate(children), n=name),
                            ch=True)
                cmds.parent(name, 'LOD0_')

        ####################### Pivot Check ############################
        def pivotCheck(selection):
            for i in selection:
                if not cmds.xform(
                        '%s.scalePivot' %
                    (i), q=True, ws=True, t=True) == [0.0, 0.0, 0.0]:
                    cmds.warning(
                        'One or more pivots are not in the center of the scene'
                    )
                    return True

        myObjects = []

        mySelection = cmds.ls(selection=True, long=True)

        expDict = {}

        currentObjects = mySelection
        finished = False

        if currentObjects:
            while finished == False:
                currentObjectsList = []
                for obj in currentObjects:
                    children = cmds.listRelatives(obj,
                                                  type='transform',
                                                  fullPath=True)
                    if children == None:
                        myObjects.append(obj)
                        finished = True
                    else:
                        for child in children:
                            currentObjectsList.append(child)

                if currentObjectsList == []:
                    finished = True
                else:
                    currentObjects = currentObjectsList

            listCheck = []

            for i in myObjects:
                x = myObjects.index(i)
                splitName = myObjects[x].split('|')[1:4]
                print splitName
                newName = '|'.join(splitName)
                toFullName = '|' + newName
                FBXName = re.sub(
                    '__*', '_', '%s_%s' % (splitName[1], splitName[2])
                )  #re.sub removes any duoble accurences of '_'
                listForExpFunction = (toFullName, FBXName)
                expDict[FBXName] = toFullName
                if not listForExpFunction[0] in listCheck:
                    listCheck.append(listForExpFunction[0])
                    if not os.path.isdir(os.path.abspath(expPath)):
                        os.makedirs(os.path.abspath(expPath))

        successful = None
        successfulItems = []
        for key in expDict:

            mel.eval('FBXResetExport')

            ########### Set FBX export settings ########################
            mel.eval('FBXExportTangents -v true')
            mel.eval('FBXExportSmoothingGroups -v true')
            mel.eval('FBXExportInputConnections -v 0')
            mel.eval('FBXExportConvertUnitString "cm"')
            mel.eval('FBXExportUpAxis y')
            mel.eval('FBXExportFileVersion "FBX201400/201500"')
            mel.eval('FBXExportInAscii -v true')
            successful = True
            successfulItems.append(key)
            duplicateCombine(expDict[key],
                             key)  # Duplicates and merges the models
            cmds.select(key)  # Select new merged object
            cmds.FBXExport('-file', expPathMel + '/' + key + '.fbx',
                           '-s')  # Export selected object
            cmds.delete(key)  # delete Duplicate.
            print('Successfully exported ' + key + '.fbx to ' + expPath)

        if successful:
            successfulMessage = ('\n'.join(successfulItems))
            confirmDialog = cmds.confirmDialog(
                messageAlign='center',
                title='Successful export',
                message='Successfully exported objects:\n%s' %
                (successfulMessage),
                cancelButton='OK',
                button=['OK', 'Open Folder'],
                defaultButton='OK')
            if confirmDialog == 'Open Folder':
                os.startfile(expPath)
    else:
        cmds.warning('The scene scale is not set to meter')


#reload(P5_tools.P5FBXexporter)
예제 #10
0
파일: shenqi.py 프로젝트: xbxcw/scripts
    mc.select(mc.listRelatives(mc.ls(geometry=True), p=True, path=True),
              r=True)
    nodes = mc.ls(sl=True)
    edges = mc.ls(mc.polyListComponentConversion(te=True), fl=True)
    a = []
    b = []
    for edge in edges:
        mc.select(edge)
        uvs = mc.ls(mc.polyListComponentConversion(tuv=True), fl=True)
        for uv in uvs:
            p = mc.polyEditUV(uv, query=True)
            a.append(p)
        if len(a) == 4:

            if a[0] == a[1] and a[2] == a[3]:
                b.append(edge)
            elif a[0] == a[2] and a[1] == a[3]:
                b.append(edge)
            elif a[0] == a[3] and a[1] == a[2]:
                b.append(edge)
        a = []
        mc.progressBar(progress, edit=True, step=1, maxValue=len(edges))
    mc.select(b)
    mc.SewUVs()

    mc.FBXExport('-file', 'C:/Users/Intime/Desktop/aa/a%d' % i)  # 导出模型

    mc.file(new=True, force=True)  # 刷新场景

    i += 1
    bb -= 1
예제 #11
0
파일: han.py 프로젝트: xbxcw/scripts
textures = []
for folder in folders:
    i = 0
    transforms = []
    obj = myFolder + folder + '/' + mc.getFileList(folder=myFolder + folder,
                                                   filespec='*.obj')[0]
    mc.file(obj, i=True, ns='wang%02d' % i)
    geometry = mc.ls(geometry=True)
    mc.hyperShade(a=shader, assign=True)
    shader = mc.shadingNode('blinn', asShader=True)
    file_node = mc.shadingNode('file', asTexture=True)
    mc.setAttr(file_node + '.fileTextureName',
               'D:\HKW\danrenzuoyi\sourceimages\Hanjiangfu\T_Cabinet01_B.png',
               type="string")
    mc.connectAttr('%s.outColor' % file_node, '%s.color' % shader)
    mc.FBXExport('-file', 'C:/Users/HYC/Desktop/aa/' + geometry[0])
    mc.file(new=True, force=True)

shader = mc.shadingNode('blinn', asShader=True)
file_node = mc.shadingNode('file', asTexture=True)
mc.setAttr(file_node + '.fileTextureName',
           'D:\HKW\danrenzuoyi\sourceimages\Hanjiangfu\T_Cabinet01_B.png',
           type="string")
shading_group = mc.sets(renderable=True, noSurfaceShader=True, empty=True)
mc.connectAttr('%s.outColor' % shader, '%s.surfaceShader' % shading_group)
mc.connectAttr('%s.outColor' % file_node, '%s.color' % shader)

# 材质球部分
shader = mc.shadingNode('blinn', asShader=True)  # 材质球
file_node = mc.shadingNode('file', asTexture=True)  # 图片
mc.setAttr(file_node + '.fileTextureName',
예제 #12
0
파일: shenqi1.py 프로젝트: xbxcw/scripts
def exportFbx(path, name, geometry):
    dir = path + 'FBX'
    if os.path.exists(dir) is False:
        os.makedirs(dir)
    mc.select(geometry)
    mc.FBXExport('-file', dir + '/%s' % name, '-s')
예제 #13
0
            cmds.connectAttr(content_tex + '.outColor', out_mat[0] + '.color')
            if color_map_tex != None:
                #cmds.delete( color_map_tex )
                del_list.append(color_map_tex)
            #cmds.delete( fileNode )
            del_list.append(fileNode)

    del_list = {}.fromkeys(del_list).keys()
    for tex in del_list:
        cmds.delete(tex)

    split_group = f.split("/")
    if len(split_group) == 1:
        split_group = f.split("\\")

    fileName = split_group[-1]

    name, postfix = fileName.split('.')
    fileName = name + '.fbx'
    print fileName

    if not os.path.exists(export_path):
        os.makedirs(export_path)
    newPath = join(export_path, fileName).replace('\\', '/')

    print 'export fbx :' + newPath

    cmds.FBXExport('-file', newPath, '-a')

    print 'export fbx done!'