def generate_all_uv_tile_previews(self, res_max=1024):
        """Regenerate all UV-tile preview textures.

        Args:
            res_max (int, optional): Maximum resolution. Defaults to 1024.
        """
        # set the resolution...
        try:
            hrg_texmax_attr = 'hardwareRenderingGlobals.textureMaxResolution'
            cmds.setAttr(hrg_texmax_attr, res_max)
            m = '>> Set {0} > {1}'.format(hrg_texmax_attr, res_max)
            self.logger.info(m)
        except Exception as e:
            m = '>> Failed to set {0} > {1}'.format(hrg_texmax_attr, str(e))
            self.logger.info(m)

        # generate for all file nodes in *RIG shaders...
        f_nodes = cmds.ls(typ='file')
        if f_nodes:
            for f_node in f_nodes:
                uvtm_attr = '{}.uvTilingMode'.format(f_node)
                uvtq_attr = '{}.uvTileProxyQuality'.format(f_node)

                uvtm_val = cmds.getAttr(uvtm_attr)
                uvtq_val = cmds.getAttr(uvtq_attr)
                if uvtm_val != 0 and uvtq_val != 0:
                    try:
                        cmds.ogs(rup=f_node)
                        m = '>> UV Tile Preview > {}'.format(f_node)
                        self.logger.info(m)
                    except Exception as e:
                        m = '>> Failed UV Tile Preview {0} > {1}'.format(
                            f_node, str(e))
                        self.logger.info(m)
Beispiel #2
0
def setAllPanelsToRenderer(renderer, reset=True):
    """Set all the models panels to the specified renderer. It will do a reset of everything regarding the Viewport 2.0 if no model panels use it.
    Possible values: base_OpenGL_Renderer, hwRender_OpenGL_Renderer, vp2Renderer
    """
    modelPanels = cmds.getPanel(type='modelPanel') or []
    for panel in modelPanels:
        cmds.modelEditor(panel, edit=True, rendererName=renderer)
    if reset or os.environ.get('MAYA_DISABLE_VP2_WHEN_POSSIBLE', False):
        cmds.ogs(reset=True)
Beispiel #3
0
def setAllPanelsToRenderer(renderer, reset=True):
    """Set all the models panels to the specified renderer. It will do a reset of everything regarding the Viewport 2.0 if no model panels use it.
    Possible values: base_OpenGL_Renderer, hwRender_OpenGL_Renderer, vp2Renderer
    """
    modelPanels = cmds.getPanel(type='modelPanel') or []
    for panel in modelPanels:
        cmds.modelEditor(panel, edit=True, rendererName=renderer)
    if reset or os.environ.get('MAYA_DISABLE_VP2_WHEN_POSSIBLE', False):
        cmds.ogs(reset=True)
Beispiel #4
0
def _apply_kealeye_rig_mapping():
    """Apply rig mapping from Sean Kealeye MocapTools.

    This brings in the HSL rig, binds it to the MotionBurner skeleton,
    then bakes the anim. The MotionBurner rig is left in the scene
    for comparison but it is placed in a group and hidden.
    """
    print 'APPLY KEALEYE RIG MAP'
    assert cmds.ogs(query=True, pause=True)
    fr_tools.install_mocap_tools()
    from MocapTools.Scripts import PsyopMocapTools

    # Apply kealeye bake
    print 'BAKING CONTROL RIG SCENE'
    PsyopMocapTools.mocapSetupTools().bakeControlRigScene(incFace=True)

    # Clean up scene
    cmds.currentTime(1)  # Update anim
    cmds.select([
        _node for _node in cmds.ls('SK_Tier1_Male_CR:*', long=True, dag=True)
        if _node.count('|') == 1
    ])
    _grp = cmds.group(name='CaptureRig_GRP')
    cmds.setAttr(_grp + '.visibility', False)
    _editor = ui.get_active_model_panel()
    cmds.modelEditor(_editor, edit=True, nurbsCurves=True)
Beispiel #5
0
def pause_viewports(pause=True):
    """Pause viewports.

    This is a wrapper for the cmds.ogs function which acts as a toggle, which
    can be a bit unpredictable sometimes.

    Args:
        pause (bool): pause state to apply
    """
    _paused = cmds.ogs(query=True, pause=True)
    if pause:
        if _paused:
            print 'VIEWPORTS ALREADY PAUSED'
        else:
            print 'PAUSING VIEWPORTS'
            cmds.ogs(pause=True)
    else:
        if not _paused:
            print 'VIEWPORTS ALREADY UNPAUSED'
        else:
            print 'UNPAUSING VIEWPORTS'
            cmds.ogs(pause=True)
Beispiel #6
0
def _gather_system():

    device = dict()

    try:
        info = cmds.ogs(deviceInformation=True)

    except AttributeError:
        # Must be running in standalone, prior to standalone.initialize()
        pass

    else:
        try:
            for pair in info:
                key, value = pair.split(":", 1)
                device[key.strip().lower()] = value.strip().rstrip("\n.")
        except Exception:
            pass

    __.telemetry_data["system"].update({
        "time":
        datetime.datetime.now().strftime("%d-%m-%Y, %H:%M:%S"),

        # E.g. win32
        "os":
        sys.platform,

        # E.g. AMD64
        "machine":
        platform.machine(),

        # E.g. AMD64 Family 23 Model 49 Stepping 0, AuthenticAMD
        "processor":
        platform.processor(),

        # E.g. Geforce RTX 3090/PCIe/SSE2
        "gpu":
        device.get("adapter", "unknown"),
        "memory_cpu":
        device.get("cpu memory limit", -1.0),
        "memory_gpu":
        device.get("gpu memory limit", -1.0),

        # E.g. OpenGL 4.1
        "render_api":
        device.get("api", "unknown"),
    })
Beispiel #7
0
    def bake(self, method):
        """
        Bake Method
        Duplicate:
        Reparent to World: If the camera you want to bake has custom attributes or connections you do not want to break, click this.
        """

        sel = mc.ls(selection=True, long=True)
        if len(sel) != 1: # Check if only one object is selected.
            mc.warning("You must select a single camera.")
            return

        if self.getObjectType(sel) != "camera": # Check if selected object's type is camera.
            mc.warning("You must select a single camera.")
            return

        if mc.listRelatives(sel, parent=True) == None: # Check if selected camera's parent is 'world'.
            mc.warning("Selected camera is already a child of the parent, 'world'.")
            return


        selCamTrans = sel[0]
        selCamShape = mc.listRelatives(selCamTrans, shapes=True, fullPath=True)[0]

        minTime = mc.playbackOptions(q=True, minTime=True)
        maxTime = mc.playbackOptions(q=True, maxTime=True)

        #if method == "duplicate":
        #    dupCamTrans, dupCamShape = mc.camera(name=selCamTrans)
        #    print "WIP"

        if method == "reparentToWorld":
            worldLoc = mc.spaceLocator(name="worldLoc")[0]
            selCamRotateOrder = mc.getAttr(selCamTrans+".rotateOrder")
            mc.setAttr(worldLoc+".rotateOrder", selCamRotateOrder)

            pc = mc.parentConstraint(selCamTrans, worldLoc, maintainOffset=False)

            mc.ogs(pause=True)
            mc.bakeResults(worldLoc, simulation=True, attribute=["tx","ty","tz","rx","ry","rz"], time=(minTime, maxTime))
            mc.ogs(pause=True)

            mc.delete(pc) # Delete parent constraint.

            # Delete selected camera's translation and rotation attributes.
            mm.eval('cutKey -time ":" -hierarchy none  -at "tx" -at "ty" -at "tz" -at "rx" -at "ry" -at "rz" {cam};'.format(cam=selCamTrans))
            # Unparent selected camera to world
            unparentedSelCamTrans = mc.parent(selCamTrans, world=True)[0]

            # Cut worldLoc transform keys.
            mm.eval('cutKey -time ":" -hierarchy none  -at "tx" -at "ty" -at "tz" -at "rx" -at "ry" -at "rz" {loc};'.format(loc=worldLoc))
            # Paste worldLoc transform keys to unparentedSelCamTrans
            mm.eval('pasteKey -option replaceCompletely -copies 1 -connect 0 -timeOffset 0 -floatOffset 0 -valueOffset 0 "{cam}";'.format(cam=unparentedSelCamTrans))
            mc.delete(worldLoc)

            # If Reset Scale is checked, set unparentedSelCamTrans scaleXYZ value to 1.
            if self.options_resetScale_cb.isChecked():
                mc.setAttr(unparentedSelCamTrans+".sx", 1)
                mc.setAttr(unparentedSelCamTrans+".sy", 1)
                mc.setAttr(unparentedSelCamTrans+".sz", 1)

        # Close window
        self.close()
        self.deleteLater()

        # Save checkbox toggle state
        self.saveSettings()
Beispiel #8
0
def capture_viewport(size=1.0):
    """Saves a versioned capture to the ``capture_folder`` defined in the
    preferences.

    The script will output to an image sequence and if FFFmpeg can be found
    converts it to a h264 movie file.
    It will also try to create a ``latest`` folder with a copy of the last
    exported image sequence.

    """
    ext = 'png'
    scene_info = QtCore.QFileInfo(cmds.file(q=True, expandName=True))

    # CAPTURE_DESTINATION
    capture_folder, workspace, base_destination_path = \
        base.capture_viewport_destination()

    _dir = QtCore.QFileInfo(base_destination_path).dir()
    if not _dir.exists():
        _dir.mkpath('.')

    # Use our custom ModelPanel picker to select the viewport we want to
    # capture
    from . import main

    picker = main.PanelPicker()
    picker.exec_()
    panel = picker.panel

    # Cancel if no selection was made
    if not panel:
        return

    # Make sure we have selected a valid panel as not all panels are modelEditors
    if panel is None or cmds.objectTypeUI(panel) != 'modelEditor':
        s = 'Activate a viewport before starting a capture.'
        raise RuntimeError(s)

    camera = cmds.modelPanel(panel, query=True, camera=True)

    # The panel settings using capture.py and update it with our
    # custom settings. See `base.CaptureOptions` for the hard-coded
    # defaults we're using here
    options = capture.parse_view(panel)
    options['viewport_options'].update(base.CaptureOptions)

    # Hide existing panels
    current_state = {}
    for panel in cmds.getPanel(type='modelPanel'):
        if not cmds.modelPanel(panel, exists=True):
            continue

        try:
            ptr = OpenMayaUI.MQtUtil.findControl(panel)
            if not ptr:
                continue
            panel_widget = shiboken2.wrapInstance(int(ptr), QtWidgets.QWidget)
            current_state[panel] = panel_widget.isVisible()
            if panel_widget:
                panel_widget.hide()
        except:
            log.error('# An error occured hiding {}'.format(panel))

    width = int(cmds.getAttr('defaultResolution.width') * size)
    height = int(cmds.getAttr('defaultResolution.height') * size)

    try:
        capture.capture(
            camera=camera,
            width=width,
            height=height,
            display_options=base.DisplayOptions,
            camera_options=base.CameraOptions,
            viewport2_options=options['viewport2_options'],
            viewport_options=options['viewport_options'],
            format='image',
            compression=ext,
            filename=base_destination_path,
            overwrite=True,
            viewer=False
        )
        log.success(f'Capture saved to {_dir.path()}')
    except:
        raise
    finally:
        cmds.ogs(reset=True)

        # Show hidden panels
        for panel in cmds.getPanel(type='modelPanel'):
            if not cmds.modelPanel(panel, exists=True):
                continue
            try:
                ptr = OpenMayaUI.MQtUtil.findControl(panel)
                if not ptr:
                    continue
                panel_widget = shiboken2.wrapInstance(
                    int(ptr), QtWidgets.QWidget
                )
                if panel_widget:
                    if panel in current_state:
                        panel_widget.setVisible(current_state[panel])
                    else:
                        panel_widget.setVisible(True)
            except:
                print(f'# Could not restore {panel} after capture')

    # Publish output
    publish_capture(workspace, capture_folder, scene_info, ext)

    # Push and reveal output
    path = base.CAPTURE_FILE.format(
        workspace=workspace,
        capture_folder=capture_folder,
        scene=scene_info.baseName(),
        frame='{}'.format(int(cmds.playbackOptions(q=True, minTime=True))).zfill(
            base.DefaultPadding
        ),
        ext=ext
    )
    push_capture(path)
    reveal_capture(path)
Beispiel #9
0
    def bake(self, mode):
        # Get List of selected Transform Nodes
        selTransList = mc.ls(selection=True, transforms=True, long=True)

        locList = []
        pcList = []
        ocList = []
        scList = []
        for trans in selTransList:
            # Create Locator
            #loc = mc.spaceLocator(name="baked{0}".format(trans))[0]
            loc = mc.spaceLocator(name="bakerLoc_#")[0]
            locList.append(loc)

            # Set Rotate Order
            if self.rotateOrder_inherit_rb.isChecked(): mc.setAttr(loc+".rotateOrder", mc.getAttr(trans+".rotateOrder"))
            if self.rotateOrder_xyz_rb.isChecked(): mc.setAttr(loc+".rotateOrder", 0)
            if self.rotateOrder_yzx_rb.isChecked(): mc.setAttr(loc+".rotateOrder", 1)
            if self.rotateOrder_zxy_rb.isChecked(): mc.setAttr(loc+".rotateOrder", 2)
            if self.rotateOrder_xzy_rb.isChecked(): mc.setAttr(loc+".rotateOrder", 3)
            if self.rotateOrder_yxz_rb.isChecked(): mc.setAttr(loc+".rotateOrder", 4)
            if self.rotateOrder_zyx_rb.isChecked(): mc.setAttr(loc+".rotateOrder", 5)

            if self.point_groupbox.isChecked():
                pskip = ""
                if self.point_x_cb.isChecked() == False: pskip += ", skip='x'"
                if self.point_y_cb.isChecked() == False: pskip += ", skip='y'"
                if self.point_z_cb.isChecked() == False: pskip += ", skip='z'"
                exec("pc = mc.pointConstraint(trans, loc, maintainOffset=False {0})".format(pskip))
                pcList.append(pc)
            if self.orient_groupbox.isChecked():
                oskip = ""
                if self.orient_x_cb.isChecked() == False: oskip += ", skip='x'"
                if self.orient_y_cb.isChecked() == False: oskip += ", skip='y'"
                if self.orient_z_cb.isChecked() == False: oskip += ", skip='z'"
                exec("oc = mc.orientConstraint(trans, loc, maintainOffset=False {0})".format(oskip))
                ocList.append(oc)
            if self.scale_groupbox.isChecked():
                sskip = ""
                if self.scale_x_cb.isChecked() == False: sskip += ", skip='x'"
                if self.scale_y_cb.isChecked() == False: sskip += ", skip='y'"
                if self.scale_z_cb.isChecked() == False: sskip += ", skip='z'"
                exec("sc = mc.scaleConstraint(trans, loc, maintainOffset=False {0})".format(sskip))
                scList.append(sc)

        # Bake
        if self.start_frame_le.text() != self.end_frame_le.text(): # If Start & End Frame is not same, Bake.
            mc.ogs(pause=True)
            mc.bakeResults(locList, simulation=True, attribute=["tx","ty","tz","rx","ry","rz","sx","sy","sz"], time=(self.start_frame_le.text(), self.end_frame_le.text()))
            mc.ogs(pause=True)

        # Delete Constraints
        for pc in pcList:
            try:
                mc.delete(pc)
            except:
                pass
        for oc in ocList:
            try:
                mc.delete(oc)
            except:
                pass
        for sc in scList:
            try:
                mc.delete(sc)
            except:
                pass

        mc.select(clear=True)


        ## Close Window ##
        if mode == "bake":
            self.close()
            self.deleteLater()
Beispiel #10
0
    def testIsolateSelection(self):
        cmds.file(os.path.abspath('IsolateSelectionTest.ma'),
                  open=True,
                  force=True)

        # Isolate selection seems to only apply to the interactive viewports,
        # and not to ogsRenders. However, it's difficult for us to render
        # viewports with exact sizes to do baseline comparisons. Since isolate
        # selection needs to work with selection hit-testing as well, we use
        # that as a proxy for checking that isolate selection draws properly.
        panel1 = self._MakeModelPanel()
        panel2 = self._MakeModelPanel()

        # Load all assemblies.
        UsdMaya.LoadReferenceAssemblies()
        self._HitTest(panel1, True, True, True)
        self._HitTest(panel2, True, True, True)

        # Isolate CubeModel1.
        cmds.select("CubeModel1")
        cmds.isolateSelect(panel1, state=True)
        self._HitTest(panel1, True, False, False)
        self._HitTest(panel2, True, True, True)

        # Isolate CubeModel2 and CubeModel3.
        cmds.select("CubeModel2", "CubeModel3")
        cmds.isolateSelect(panel1, loadSelected=True)
        self._HitTest(panel1, False, True, True)

        # Get out of isolate selection.
        cmds.isolateSelect(panel1, state=False)
        self._HitTest(panel1, True, True, True)

        # Enter isolate selection on panel2 this time.
        cmds.select("CubeModel2", "CubeModel3")
        cmds.isolateSelect(panel2, state=True)
        self._HitTest(panel1, True, True, True)
        self._HitTest(panel2, False, True, True)

        # Then add an isolate selection to panel1 again.
        cmds.select("CubeModel1", "CubeModel2")
        cmds.isolateSelect(panel1, state=True)
        self._HitTest(panel1, True, True, False)
        self._HitTest(panel2, False, True, True)

        # Unload assemblies.
        UsdMaya.UnloadReferenceAssemblies()
        self._HitTest(panel1, False, False, False)
        self._HitTest(panel2, False, False, False)

        # Reload assemblies.
        UsdMaya.LoadReferenceAssemblies()

        # XXX: A regression appears to have been introduced some time around
        # the release of Maya 2020.
        # When using the "Show -> Isolate Select" feature in a particular
        # viewport, if your isolated selection includes assemblies and you
        # unload and reload those assemblies while "Isolate Select -> View
        # Selected" is turned on, those assemblies will not be visible when
        # they are reloaded, nor can they be selected. They continue to be
        # visible and selectable in other viewports, and turning off "View
        # Selected" will make them visible and selectable in the previously
        # filtered viewport.
        # It's not quite clear whether this regression has to do specifically
        # with the assembly framework or is instead more generally related to
        # some set membership state being lost as nodes are created or
        # destroyed while a viewport is being filtered.
        # To work around this for now, in Maya 2020+ we force a renderer reset
        # to make the isolated assemblies visible and selectable in the
        # filtered viewport.
        # This regression is tracked in the following issues:
        #     Autodesk Issue ID: BSPR-35674
        #     Pixar Issue ID: MAYA-2808
        if cmds.about(apiVersion=True) > 20200000:
            cmds.ogs(reset=True)

        self._HitTest(panel1, True, True, False)
        self._HitTest(panel2, False, True, True)
Beispiel #11
0
    def save_changes(self):
        """Start the export process.

        """
        self._interrupt_requested = False

        items = self.mayaexport_set_editor.currentData()
        _k = self.mayaexport_set_editor.currentText()
        if not items:
            raise RuntimeError(f'{_k} is empty.')

        file_path = self.db_source()
        if not self.db_source():
            raise RuntimeError('The output path is not set.')

        file_info = QtCore.QFileInfo(file_path)

        # Let's make sure destination folder exists
        _dir = file_info.dir()
        if not _dir.exists():
            if not _dir.mkpath('.'):
                raise OSError(f'Could not create {_dir.path()}')
        if not _dir.isReadable():
            raise OSError(f'{_dir.path()} is not readable')

        if file_info.exists():
            mbox = ui.MessageBox(f'{file_info.fileName()} already exists.',
                                 'Are you sure you want to overwrite it?',
                                 buttons=[ui.YesButton, ui.NoButton])
            if mbox.exec_() == QtWidgets.QDialog.Rejected:
                return
            if not QtCore.QFile(file_path).remove():
                raise RuntimeError(f'Could not remove {file_info.fileName()}.')

        # Frame range
        if self.mayaexport_timeline_editor.isChecked():
            start = cmds.playbackOptions(query=True, animationStartTime=True)
            end = cmds.playbackOptions(query=True, animationEndTime=True)
        else:
            start = cmds.currentTime(query=True)
            end = cmds.currentTime(query=True)

        # Plugin
        k = self.mayaexport_type_editor.currentData()
        if not k:
            raise RuntimeError('Must select an export type.')

        if PRESETS[k]['plugins']:
            for plugin in PRESETS[k]['plugins']:
                if not cmds.pluginInfo(plugin, loaded=True, q=True):
                    cmds.loadPlugin(plugin, quiet=True)

        state = cmds.ogs(pause=True, query=True)
        if PRESETS[k]['ogs_pause'] and not state:
            cmds.ogs(pause=True)

        try:
            sel = cmds.ls(selection=True)
            t = cmds.currentTime(query=True)

            self.init_progress_bar()
            self.progress_widget.setMinimum(int(start))
            self.progress_widget.setMaximum(int(end))
            self.progress_widget.setRange(int(start), int(end))
            self.progress_widget.open()

            action = getattr(self, PRESETS[k]['action'])
            action(file_path, items, int(start), int(end))
            common.signals.fileAdded.emit(file_path)

            if self.mayaexport_reveal_editor.isChecked():
                from .. import actions
                actions.reveal(file_path)
            if not self.mayaexport_keepopen_editor.isChecked():
                self.close()
        except:
            raise
        finally:
            self.progress_widget.close()
            cmds.currentTime(t, edit=True)
            cmds.select(clear=True)
            cmds.select(sel, replace=True)
            if PRESETS[k]['ogs_pause'] and not state:
                cmds.ogs(pause=True)
            self.check_version()
Beispiel #12
0
 def _on_exit(self):
     if _cmds.ogs(query=True, pause=True) != self.paused:
         _cmds.ogs(pause=True)
Beispiel #13
0
 def _on_enter(self):
     self.paused = _cmds.ogs(query=True, pause=True)
     if not self.paused:
         _cmds.ogs(pause=True)
Beispiel #14
0
def ExportFusionCamera(Cam,
                       TheFileName=""):  # for each camera, export a .comp file
    print("Exporting Camera :" + Cam)
    if TheFileName == "":
        FileTypes = "Comp Files (*.comp);;All Files (*.*)"
        TheFileName = mc.fileDialog2(cap="File name for camera comp file?",
                                     fileFilter=FileTypes,
                                     ds=1,
                                     fm=0)[0]

    # get the shape, fov, etc of the camera
    Shapes = mc.listRelatives(Cam, s=True)
    for ThisShape in Shapes:  # find the camera shape
        if mc.nodeType(ThisShape) == "camera":
            Shape = ThisShape

    # for every frame collect the transform data and fov data. must be done on
    # every frame since I cant get handles in fusions to correctly support
    # Maya's various curve types
    PositionXArray = []
    PositionYArray = []
    PositionZArray = []

    RotationXArray = []
    RotationYArray = []
    RotationZArray = []
    FOVArray = []
    FirstFrame = int(mc.playbackOptions(q=True, min=True))
    LastFrame = int(mc.playbackOptions(q=True, max=True))
    try:
        mc.ogs(pause=True)  # pauses the viewport to make it faster
    except BaseException:
        pass
    for Frame in range(FirstFrame, LastFrame + 2):

        CurrentFrame = mc.currentTime(q=True)  # store for later

        # go to every frame. Sadly, no easy way to get some parts of the data
        # otherwise
        mc.currentTime(Frame)
        PositionXArray.append(Round(mc.getAttr(Cam + ".tx")))
        PositionYArray.append(Round(mc.getAttr(Cam + ".ty")))
        PositionZArray.append(Round(mc.getAttr(Cam + ".tz")))

        RotationXArray.append(Round(mc.getAttr(Cam + ".rx")))
        RotationYArray.append(Round(mc.getAttr(Cam + ".ry")))
        RotationZArray.append(Round(mc.getAttr(Cam + ".rz")))

        FOVArray.append(Round(mc.camera(Shape, q=True, hfv=True)))

    mc.currentTime(CurrentFrame)
    try:
        mc.ogs(pause=True)
    except BaseException:
        pass

    # convert the collected data into a .comp file
    FileString = "{\n"
    FileString += "Tools = ordered(){\n"
    FileString += Shape + " = Camera3D{\n"
    FileString += "    CtrlWZoom = false,\n"
    FileString += "                Inputs = {\n"
    FileString += '    ["Transform3DOp.Translate.X"] = Input{\n'
    FileString += '    SourceOp = "' + Shape + 'XOffset",\n'
    FileString += '               Source = "Value",\n'
    FileString += " },\n"
    FileString += '["Transform3DOp.Translate.Y"] = Input{\n'
    FileString += '    SourceOp = "' + Shape + 'YOffset",\n'
    FileString += '               Source = "Value",\n'
    FileString += "},\n"
    FileString += '["Transform3DOp.Translate.Z"] = Input{\n'
    FileString += '    SourceOp = "' + Shape + 'ZOffset",\n'
    FileString += '               Source = "Value",\n'
    FileString += "},\n"
    FileString += '["Transform3DOp.Rotate.X"] = Input{\n'
    FileString += '    SourceOp = "' + Shape + 'XRotation",\n'
    FileString += '               Source = "Value",\n'
    FileString += "},\n"
    FileString += '["Transform3DOp.Rotate.Y"] = Input{\n'
    FileString += '    SourceOp = "' + Shape + 'YRotation",\n'
    FileString += '               Source = "Value",\n'
    FileString += "},\n"
    FileString += '["Transform3DOp.Rotate.Z"] = Input{\n'
    FileString += '    SourceOp = "' + Shape + 'ZRotation",\n'
    FileString += '               Source = "Value",\n'
    FileString += "},\n"
    FileString += '["Transform3DOp.ScaleLock"] = Input{Value = 0,},\n'
    FileString += "PerspFarClip = Input\n"
    FileString += "{Value = 10000,},\n"
    FileString += "AovType = Input { Value = 1, },\n"
    FileString += "AoV = Input{\n"
    FileString += '    SourceOp = "' + Shape + 'AngleofView",\n'
    FileString += '               Source = "Value",\n'
    FileString += "},\n"
    FileString += "FLength = Input{Value = 23.3333333558239,},\n"
    FileString += "PlaneOfFocus = Input{Value = 5,},\n"
    FileString += '["Stereo.Mode"] = Input{Value = FuID{"Mono"},},\n'

    # these are hardcoded values, based on our project
    FileString += "FilmBack = Input { Value = 1, },\n"
    FileString += 'FilmGate = Input { Value = FuID { "User" }, },\n'
    FileString += "ApertureW = Input{Value = 1.417,},\n"
    FileString += "ApertureH = Input{Value = 0.945,},\n"
    FileString += 'ResolutionGateFit = Input { Value = FuID { "Width" }, },\n'
    # end of hardcoded stuff

    FileString += '["SurfacePlaneInputs.ObjectID.ObjectID"] = Input{Value = 1,},\n'
    FileString += '["MtlStdInputs.MaterialID"] = Input{Value = 1,},\n'
    FileString += "},\n"
    FileString += "ViewInfo = OperatorInfo{Pos = {-5.87854, -16.3528}},\n"
    FileString += "},\n"

    FileString += AddKeyArray(
        Shape + "XOffset",
        "Red = 250, Green = 59, Blue = 49",
        PositionXArray,
        FirstFrame,
        LastFrame,
    )  # add position x keys
    FileString += AddKeyArray(
        Shape + "YOffset",
        "Red = 252, Green = 131, Blue = 47 ",
        PositionYArray,
        FirstFrame,
        LastFrame,
    )  # add position y keys
    FileString += AddKeyArray(
        Shape + "ZOffset",
        "Red = 254, Green = 207, Blue = 46 ",
        PositionZArray,
        FirstFrame,
        LastFrame,
    )  # add position z keys

    FileString += AddKeyArray(
        Shape + "XRotation",
        "Red = 255, Green = 128, Blue = 12",
        RotationXArray,
        FirstFrame,
        LastFrame,
    )  # add rot x keys
    FileString += AddKeyArray(
        Shape + "YRotation",
        "Red = 128, Green = 255, Blue = 128",
        RotationYArray,
        FirstFrame,
        LastFrame,
    )  # add rot ykeys
    FileString += AddKeyArray(
        Shape + "ZRotation",
        "Red = 108, Green = 229, Blue = 117",
        RotationZArray,
        FirstFrame,
        LastFrame,
    )  # add rot z keys

    FileString += AddKeyArray(
        Shape + "AngleofView",
        "Red = 8, Green = 229, Blue = 117",
        FOVArray,
        FirstFrame,
        LastFrame,
        IsLast=True,
    )  # add focal length keys

    FileString += "}\n"
    FileString += "}"

    # output the collected data
    WriteStringToFile(FileString, TheFileName)
    print("DONE EXPORTING CAMERA")
Beispiel #15
0
def playblast(camera,
              maya_playblast_kwargs,
              model_editor_kwargs=None,
              ambient_occlusion=True,
              generate_uvtiles_previews=False,
              context_managers=None):
    """
    @maya_playblast_kwargs: maya.cmds.playblast kwargs

    @model_editor_kwargs: maya.cmds.modelEditor kwargs

    @ambient_occlusion can be True for default settings OR it can be passed a
        dict with the attributes values for the "hardwareRenderingGlobals" node
            - ssaoRadius
            - ssaoFilterRadius
            - ssaoAmount
            - ssaoEnable
            - ssaoSamples
            - multiSampleEnable
    """
    model_editor_kwargs = model_editor_kwargs or dict()
    try:
        start = maya_playblast_kwargs['startTime']
        end = maya_playblast_kwargs['endTime']
        frames_str = '%i -> %i' % (start, end)
    except KeyError:
        frames_str = str(maya_playblast_kwargs['frame'])

    if mc.about(batch=True):
        # BATCH
        set_single_camera_renderable(camera)
        set_attr('hardwareRenderingGlobals', 'textureMaxResolution', 256)
        mc.colorManagementPrefs(edit=True, outputTransformEnabled=True)
        lights_display_layer = mc.createDisplayLayer(mc.ls(lights=True))
        set_attr(lights_display_layer, 'visibility', False)
        result = None
        try:
            # # disable textures (default = 4):
            # set_attr('hardwareRenderingGlobals', 'renderMode', 1)
            t1 = time.time()

            def force_eval(mtime, _):
                # Without dgdirty some animation were not updated in mayapy
                mc.dgdirty(allPlugs=True)

            callback = om.MDGMessage.addTimeChangeCallback(force_eval)
            try:
                mc.evaluationManager(mode='off')
                result = mc.playblast(**maya_playblast_kwargs)
            finally:
                om.MEventMessage.removeCallback(callback)
            t2 = time.time()
            print('Playblast took %.2f seconds to render' % (t2 - t1))
        finally:
            print(lights_display_layer)
            mc.delete(lights_display_layer)
            mc.colorManagementPrefs(edit=True, outputTransformEnabled=False)
        return result
    else:
        # GUI
        context_managers = context_managers or []

        full_model_editor_kwargs = DEFAULT_MODEL_EDITOR_KWARGS.copy()
        full_model_editor_kwargs.update(model_editor_kwargs)
        context_managers.append(
            temp_tearoff_viewport(camera, full_model_editor_kwargs))

        if ambient_occlusion:
            if isinstance(ambient_occlusion, dict):
                occlusion_settings = ambient_occlusion
            else:
                occlusion_settings = None
            context_managers.append(temp_ambient_occlusion(occlusion_settings))

        with nested(*context_managers):
            print('Playblasting %s.' % frames_str)
            if generate_uvtiles_previews:
                # reset needed when opening + playblasting multiple scenes:
                mc.ogs(reset=True)
                mm.eval('generateAllUvTilePreviews;')
            return mc.playblast(**maya_playblast_kwargs)
Beispiel #16
0
def _blast_work(work,
                seq=None,
                build_cam_func=None,
                view=False,
                force=False,
                blast_=True,
                verbose=0):
    """Blast the given work file.

    Args:
        work (FrasierWork): work file to blast
        seq (TTOutputFileSeq): output image sequence
        build_cam_func (fn): function to build blast cam
        view (bool): view images on blast
        force (bool): force overwrite existing images
        blast_ (bool): execute blast
        verbose (int): print process data
    """
    _seq = seq or work.blast

    if cmds.ogs(query=True, pause=True):
        cmds.ogs(pause=True)
    assert not cmds.ogs(query=True, pause=True)

    print 'BLAST', _seq
    print ' - FRAMES', _seq.find_range()
    if not force and _seq.exists(verbose=1):
        print ' - ALREADY EXISTS'
        return

    if not host.cur_scene() == work.path:
        cmds.file(work.path, open=True, prompt=False, force=force)

    _build_cam_func = build_cam_func or _build_blast_cam
    _cam = _build_cam_func()
    print ' - CAM', _cam, type(_cam)

    # Look through cam
    _panel = ui.get_active_model_panel()
    _editor = ui.get_active_model_panel(as_editor=True)
    cmds.modelPanel(_panel, edit=True, camera=_cam)
    cmds.refresh()
    _cur_cam = cmds.modelPanel(_panel, query=True, camera=True)
    print ' - CUR CAM', _cur_cam
    assert _cur_cam == _cam

    # Apply blast settings
    cmds.modelEditor(_editor,
                     edit=True,
                     grid=False,
                     locators=False,
                     cameras=False,
                     nurbsCurves=False,
                     dimensions=False,
                     joints=False)
    cmds.camera(_cam,
                edit=True,
                displayFilmGate=False,
                displayResolution=False,
                overscan=1)
    pm.PyNode("hardwareRenderingGlobals").multiSampleEnable.set(True)
    cmds.setAttr(_cam.shp + '.nearClipPlane', 0.5)

    # Execute blast
    if not blast_:
        return
    blast(seq=_seq, res=(1280, 720), verbose=verbose)
    if view:
        _seq.view()
    print ' - BLASTED', _seq