Script_Maya.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:3D_Software_and_Python 作者: p4vv37 项目源码 文件源码
def prepare_scene(path):
    """
    The function sets the basic parameters of the scene: time range and render settings.

    :param path: string - The directory with necessary files
    """

    cmds.playbackOptions(min=0, max=260)  # Set the animation range

    cmds.autoKeyframe(state=False)  # Make sure, that the AutoKey button is disabled

    plugins_dirs = mel.getenv("MAYA_PLUG_IN_PATH") # Mental Ray plugin is necessaryfor this script to run propperly.
    # Next lines check if the plugin is avaible and installs it or displays an allert window.
    # The plugins are accualy files placed in "MAYA_PLUG_IN_PATH" directories, so this script gets those paths
    # and checks if there is a mental ray plugin file.

    for plugins_dir in plugins_dirs.split(';'):
        for filename in glob.glob(plugins_dir + '/*'): # For every filename in every directory of MAYA_PLUG_IN_PATH
            if 'Mayatomr.mll' in filename: # if there is a mental ray plugin file then make sure it is loaded
                if not cmds.pluginInfo('Mayatomr', query=True, loaded=True):
                    cmds.loadPlugin('Mayatomr', quiet=True)
                cmds.setAttr('defaultRenderGlobals.ren', 'mentalRay', type='string') # Set the render engine to MR
                # Next lines are a workaround for some bugs. The first one is that the render settings window has to be
                # opened before setting attributes of the render. If it would not be, thhen Maya would display an error
                # saying that such options do not exist.
                # The second bug is that after running this scrpt the window was blank and it was impossible to set
                # parameters. This is a common bug and it can be repaired by closing this window with
                # cmds.deleteUI('unifiedRenderGlobalsWindow') command

                cmds.RenderGlobalsWindow()
                cmds.refresh(f=True)
                cmds.deleteUI('unifiedRenderGlobalsWindow')
                cmds.setAttr('miDefaultOptions.finalGather', 1)
                cmds.setAttr('miDefaultOptions.miSamplesQualityR', 1)
                cmds.setAttr('miDefaultOptions.lightImportanceSamplingQuality', 2)
                cmds.setAttr('miDefaultOptions.finalGather', 1)
                break
        else:
            continue
        break
    else:
        print("Mental Ray plugin is not avaible. It can be found on the Autodesk website: ",
              "https://knowledge.autodesk.com/support/maya/downloads/caas/downloads/content/",
              "mental-ray-plugin-for-maya-2016.html")
        alert_box =  QtGui.QMessageBox()
        alert_box.setText("Mental Ray plugin is not avaible. It can be found on the Autodesk website: " +
              "https://knowledge.autodesk.com/support/maya/downloads/caas/downloads/content/" +
              "mental-ray-plugin-for-maya-2016.html")
        alert_box.exec_()

    cam = cmds.camera(name="RenderCamera", focusDistance=35, position=[-224.354, 79.508, 3.569],
                      rotation=[-19.999,-90,0])  # create camera to set background (imageplane)
    # Set Image Plane for camera background
    cmds.imagePlane(camera=cmds.ls(cam)[1], fileName=(path.replace("\\", "/") + '/bg.bmp'))
    cmds.setAttr("imagePlaneShape1.depth", 400)
    cmds.setAttr("imagePlaneShape1.fit", 4)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号