def __init__(self, project, pose = None, parent = uiH.getMayaWindow() ): if uiH.USEPYQT: super(base, self).__init__(parent) else: super(PoseThumbnailCreatorUi, self).__init__(parent) self.setupUi(self) self.project = project self.pose = pose layout = mui.MQtUtil.fullName(long(shiboken.getCppPointer(self.viewport_lay)[0])) self.cam = mn.Node( 'Capture_Pose' ) if not self.cam.exists: self.camShape = mn.createNode( 'camera', ss = True ) self.camShape.parent.name = 'Capture_Pose' mc.viewSet( self.cam.name, p = True ) self.cam.shape.a.focalLength.v = 100 self.cam.a.v.v = 0 self.executer = mc.modelPanel( mbv = False, camera = self.cam.name, p = layout ) mc.modelEditor(self.executer, e = True, grid = 0, da = "smoothShaded", allObjects = 0, nurbsSurfaces = 1, polymeshes = 1, subdivSurfaces = 1 ) #self.viewport_lay.addWidget( uiH.toQtObject( self.executer ) ) self.setObjectName( 'PoseThumbnailCreatorUi' ) self._makeConnections() self.saveCameraPreset = 0 #READ, 1.. WRITE self.settings = sti.Settings() gen = self.settings.General skin = gen[ "skin" ] if skin: uiH.loadSkin( self, skin ) if pose: self.poseName_le.setText( pose.name ) self.fillSections()
def YupZup(): if cmds.upAxis(q=True, axis=True) == "y": cmds.upAxis(ax="z", rv=True) else: cmds.upAxis(ax="y", rv=True) for cam in cmds.listCameras(): cmds.viewSet(cam, animate=False, home=True) cmds.viewFit(all=True)
def createCam(s): if not cmds.objExists(s.camName): s.camera = cmds.camera(n=s.camName)[0] else: s.camera = cmds.ls(s.camName)[0] cmds.viewSet(s.camera, p=True) # Move camera to perspective position cmds.setAttr("%s.focalLength" % s.camera, 500) cmds.setAttr("%s.horizontalFilmAperture" % s.camera, 5) cmds.setAttr("%s.verticalFilmAperture" % s.camera, 5) cmds.setAttr("%s.visibility" % s.camera, 0)
def snapShot(output_folder, isolate=True, fit=False): """ Generate viewport snapshot. """ # Get current selection, frame and panel currentSel = mc.ls(sl=True) currentFrame = mc.currentTime(q=True) currentPanel = mc.playblast(ae=True) # Isolate the current object if isolate: mc.isolateSelect(currentPanel, state=1) mc.isolateSelect(currentPanel, addSelected=True) # Frame view to selection if fit: mc.viewFit(fitFactor=1) # Store current selection and deselect all mc.select(cl=True) # Generate playblast mc.playblast( completeFilename=os.path.join(output_folder, 'preview.jpg'), #mc.playblast(filename=os.path.join(output_folder, 'preview'), frame=(currentFrame), framePadding=4, rawFrameNumbers=True, width=512, height=288, percent=100, format='image', compression='jpg', quality=90, viewer=False, offScreen=True, clearCache=True, showOrnaments=False) # Turn off isolate selection if isolate: mc.isolateSelect(currentPanel, state=0) # Reset view if fit: mc.viewSet(previousView=True) # Reselect original selection for sel in currentSel: mc.select(sel, add=True)
def createCam(s): if not cmds.objExists(s.camName): s.camera = cmds.camera(n=s.camName)[0] else: s.camera = cmds.ls(s.camName)[0] cmds.viewSet(s.camera, p=True) # Move camera to perspective position sel = cmds.ls(sl=True) objs = [a for a in s.data if cmds.objExists(a)] if objs: cmds.select(objs, r=True) cmds.viewFit(s.camera, f=0.5) cmds.select(sel, r=True) cmds.setAttr("%s.focalLength" % s.camera, 500) cmds.setAttr("%s.horizontalFilmAperture" % s.camera, 5) cmds.setAttr("%s.verticalFilmAperture" % s.camera, 5) cmds.setAttr("%s.visibility" % s.camera, 0)
def ImgplaneDone(self,*args): """ Sets the imageplanes if the Set button is pressed """ #reset default viewports [cmds.viewSet(cam, animate=True, home=True) for cam in ['persp', 'top', 'front', 'side'] ] #read the textfield for paths frontShape=cmds.textField('fronti', q=True, text=True) topShape=cmds.textField('topi', q=True, text=True) sideShape=cmds.textField('sidei', q=True, text=True) backShape=cmds.textField('backi', q=True, text=True) if backShape: inst=setimageplane() inst.makeBackCam("backShape") campath={'frontShape':frontShape,'topShape':topShape,'sideShape':sideShape,'backShape':backShape} for eachCam in campath: if len(campath[eachCam])>0:## check if the path is entered ## create a new image plane imagePlaneName = cmds.createNode("imagePlane") ## assign the imagePlane to the camera mel.eval( 'cameraImagePlaneUpdate "%s" "%s";' % (eachCam, imagePlaneName) ) hipv=cmds.checkBox('hip',q=True,value=True) if hipv==1: mel.eval( 'setAttr '+imagePlaneName +'.displayOnlyIfCurrent on;') else: mel.eval( 'setAttr '+imagePlaneName +'.displayOnlyIfCurrent off;') ## Connect the image to imagePlane imagePlaneFile = campath[eachCam] cmds.setAttr( "%s.imageName" % imagePlaneName, imagePlaneFile, type="string") version=mel.eval('getApplicationVersionAsFloat') if version>2012: Flag=True xyzCenter="imageCenter" elif version<=2012: Flag=True xyzCenter= "center" else: Flag=False if Flag==True: ##Move back imageplanes if eachCam=='backShape': mel.eval( 'setAttr '+imagePlaneName +'.'+xyzCenter+'Z 30;') mel.eval( 'lookThroughModelPanel back modelPanel1;') elif eachCam=='frontShape': mel.eval( 'setAttr '+imagePlaneName +'.'+xyzCenter+'Z -30;') elif eachCam=='sideShape': mel.eval( 'setAttr '+imagePlaneName +'.'+xyzCenter+'X -30;') elif eachCam=='topShape': mel.eval( 'setAttr '+imagePlaneName +'.'+xyzCenter+'Y -30;') else: pass
def take_screenshot(cam_name): cmds.select(allDagObjects=True) #place the camera to front view and fit the entire obj inside the camera view cmds.viewSet(f=True, fit=True) #take screenshot from the selected view-point, here front formatManager = createImageFormats.ImageFormats() cmds.setAttr('hardwareRenderingGlobals.renderMode', 4) cmds.setAttr('hardwareRenderingGlobals.lightingMode', 0) mel.eval('RenderViewWindow') tmp_image_path = cmds.ogsRender(cam=cam_name) formatManager.pushRenderGlobalsForDesc('PNG') cmds.refresh(cv=True, fe="jpg", fn="imageSnapshot")
def _changeGrid(self, gSize, gSpacing, gDivisions, gcGridA, gcGridHl, gcGrid, fClipping, nClipping, trans, *args): """ Sets several grid settings Color: gridAxis, gridHighlight, grid Distance: nearClipPlan, farClipPlan Camera: X,Y,Z """ cmds.grid(size=gSize, spacing=gSpacing, divisions=gDivisions) cmds.displayColor('gridAxis', gcGridA, q=True, dormant=True) cmds.displayColor('gridHighlight', gcGridHl, q=True, dormant=True) cmds.displayColor('grid', gcGrid, q=True, dormant=True) cmds.setAttr('perspShape.farClipPlane', fClipping) cmds.setAttr('perspShape.nearClipPlane', nClipping) cmds.setAttr('top.translateY', trans) cmds.setAttr('front.translateZ', trans) cmds.setAttr('side.translateX', trans) cmds.viewSet(home=True, animate=True)
def main(path): # if(os.path.splitext(path)[1] == '.fbx'): # cmds.loadPlugin('fbxmaya.mll') cmds.file(path, o=True, f=True) cmds.viewSet('perspShape', p=True) cmds.viewFit('perspShape', all=True) cmds.viewSet('perspShape', p=True) meshes = cmds.ls(type='mesh') maxMeshes = 0 for mesh in meshes: numTris = cmds.polyEvaluate(mesh, t=True) if maxMeshes < numTris: maxMeshes = numTris cmds.select(mesh) cmds.viewFit('perspShape', fitFactor=1.0) a = cmds.getAttr('persp.translate') aa = a[0] cmds.viewFit('perspShape', fitFactor=0.7) b = cmds.getAttr('persp.translate') bb = b[0] result = [x + x - y for (x, y) in zip(aa, bb)] print(result) cmds.setAttr('persp.translateX', result[0]) cmds.setAttr('persp.translateY', result[1]) cmds.setAttr('persp.translateZ', result[2]) cmds.setAttr('perspShape.renderable', 1) cmds.setAttr('defaultRenderGlobals.enableDefaultLight', 1) cmds.setAttr('defaultResolution.width', 640) cmds.setAttr('defaultResolution.height', 480) cmds.setAttr('defaultRenderGlobals.imageFormat', 8) cmds.setAttr('defaultRenderGlobals.animation', 0) cmds.setAttr('defaultRenderGlobals.outFormatControl', 0) cmds.setAttr('defaultRenderGlobals.periodInExt', 0) cmds.setAttr('defaultRenderGlobals.putFrameBeforeExt', 1) # cmds.displayPref(wsa='none') # cmds.hide(cmds.ls(type='joint')) fixTexturePath(path) cmds.render(batch=True)
def setConnection(self): self.connect( self.reloadCam_btn , SIGNAL( 'clicked()' ) , self.refreshList ) self.connect( self.viewBackward_btn , SIGNAL( 'clicked()' ) , lambda : cmds.viewSet(pv=1) ) self.connect( self.viewForward_btn , SIGNAL( 'clicked()' ) , lambda : cmds.viewSet(nv=1) ) self.connect( self.cam_list , SIGNAL('itemDoubleClicked(QListWidgetItem *)') , self.selectCam ) self.connect( self.resetField_btn , SIGNAL('clicked()') , self.resetField ) self.connect( self.resolution_btn , SIGNAL('clicked()') , self.onOffResl ) self.connect( self.filmOrigin_btn , SIGNAL('clicked()') , self.onOffFilmOrigin ) self.connect( self.safeFrame_btn , SIGNAL('clicked()') , self.onOffSafeFrame ) self.connect( self.nearClipPlane_spin , SIGNAL('valueChanged(double )') , lambda value : self.setcamNearClip(value) ) self.connect( self.farClipPlane_spin , SIGNAL('valueChanged(double )') , lambda value : self.setcamFarClip(value) ) self.connect( self.overscan_spin , SIGNAL('valueChanged(double )') , lambda value : self.setCamOverscan(value) ) self.connect( self.horizontalFilmOffset_spin , SIGNAL('valueChanged(double )') , lambda value : self.setcamHorizOffset(value) ) self.connect( self.verticalFilmOffset_spin , SIGNAL('valueChanged(double )') , lambda value : self.setcamVertOffset(value) ) self.connect( self.focalLength_spin , SIGNAL('valueChanged(double )') , lambda value : self.setCamFocalLength(value) ) self.connect( self.selCamName_btn , SIGNAL('clicked()') , lambda : self.inputPreviewName( sender='camName' ) ) self.connect( self.sceneName_btn , SIGNAL('clicked()') , lambda : self.inputPreviewName( sender='sceneName' ) ) self.connect( self.renderPreview_btn , SIGNAL('clicked()') , self.renderPreview )
def __init__(self, project, pose=None, parent=uiH.getMayaWindow()): if uiH.USEPYQT: super(base, self).__init__(parent) else: super(PoseThumbnailCreatorUi, self).__init__(parent) self.setupUi(self) self.project = project self.pose = pose layout = mui.MQtUtil.fullName( long(shiboken.getCppPointer(self.viewport_lay)[0])) self.cam = mn.Node('Capture_Pose') if not self.cam.exists: self.camShape = mn.createNode('camera', ss=True) self.camShape.parent.name = 'Capture_Pose' mc.viewSet(self.cam.name, p=True) self.cam.shape.a.focalLength.v = 100 self.cam.a.v.v = 0 self.executer = mc.modelPanel(mbv=False, camera=self.cam.name, p=layout) mc.modelEditor(self.executer, e=True, grid=0, da="smoothShaded", allObjects=0, nurbsSurfaces=1, polymeshes=1, subdivSurfaces=1) #self.viewport_lay.addWidget( uiH.toQtObject( self.executer ) ) self.setObjectName('PoseThumbnailCreatorUi') self._makeConnections() self.saveCameraPreset = 0 #READ, 1.. WRITE self.settings = sti.Settings() gen = self.settings.General skin = gen["skin"] if skin: uiH.loadSkin(self, skin) if pose: self.poseName_le.setText(pose.name) self.fillSections()
import maya.cmds as cmds # Enables polygon borders and sets the edge width to 4 # cmds.polyOptions(np=True, db=True, sb=4) # Sets Undo amount to infinite # cmds.undoInfo(infinity=True) # Makes the viewcube visible # cmds.viewManip(visible=True) cmds.optionVar(iv=('viewCubeShowCube', 1)) # Sets the Z axis to be up # cmds.upAxis(ax='z', rv=True) # Sets the near and far clip for the persp view camera # cmds.setAttr('perspShape.nearClipPlane', 1) cmds.setAttr('perspShape.farClipPlane', 100000) # Sets the near and far clip for the top view camera # cmds.setAttr('topShape.nearClipPlane', 1) cmds.setAttr('topShape.farClipPlane', 100000) # Sets the near and far clip for the front view camera # cmds.setAttr('frontShape.nearClipPlane', 1) cmds.setAttr('frontShape.farClipPlane', 100000) # Sets the near and far clip for the side view camera # cmds.setAttr('sideShape.nearClipPlane', 1) cmds.setAttr('sideShape.farClipPlane', 100000) # To change the grid spacing and subdivisions # cmds.grid(spacing=16, d=1) # To change the grid length and width # cmds.grid(size=512) # Turns off the What's New Highlight Settings window at startup cmds.whatsNewHighlight(showStartupDialog=False) # Sets the view back to default. The same as if you were to hit the home button on the viewcube cmds.viewSet('persp', animate=True, home=True)