def createVrayLatLongStereoRig():
    import maya.cmds as cmds
    import maya.mel as mel

    # ---------------------------------------------------------------------
    # Setup the default Maya Settings
    # ---------------------------------------------------------------------
    cmds.loadPlugin("stereoCamera", qt=True)

    # Make sure the Vray plugin was loaded
    forceVrayLoad()

    # Show the Render Settings Window so the Post Translator Action can be loaded
    mel.eval('unifiedRenderGlobalsWindow;')

    # Check if the vray settings element exists in the scene
    domeCreateVraySettingsNode()

    # ---------------------------------------------------------------------
    # Create the stereo rig
    # ---------------------------------------------------------------------

    #import maya.app.stereo.stereoCameraMenus as stereoCameraMenus
    #stereoCameraMenus.buildCreateMenu()
    #import maya.app.stereo.stereoCameraRig
    #maya.app.stereo.stereoCameraRig.createStereoCameraRig()

    from maya.app.stereo import stereoCameraRig

    # Set the default rig to an VrayLatLongStereoCamera
    cmds.stereoRigManager(defaultRig='VrayLatLongStereoCamera')

    # Add the camera rig to the scene
    rig = stereoCameraRig.createStereoCameraRig('VrayLatLongStereoCamera')
    #[u'VrayLatLongCamera', u'VrayLatLongCameraLeft', u'VrayLatLongCameraRight']

    #Get the stereo camera rig shape nodes for the center/right/left cameras
    rig_center_shape_name = getObjectShapeNode(rig[0])
    #[u'stereoCameraCenterCamShape', u'stereoCameraFrustum'] #

    rig_left_shape_name = getObjectShapeNode(rig[1])
    # Result: [u'stereoCameraLeftShape'] #

    rig_right_shape_name = getObjectShapeNode(rig[2])
    # Result: [u'stereoCameraRightShape'] #
    """
  cmds.setAttr( rig[0]+'.rotateX', 90)
  cmds.setAttr( rig[0]+'.rotateY', 0)
  cmds.setAttr( rig[0]+'.rotateZ', 0)
  
  """

    # Changes the render settings to set the stereo camera to be a renderable camera
    cmds.setAttr(rig_left_shape_name[0] + '.renderable',
                 1)  #stereoCameraLeftShape
    cmds.setAttr(rig_right_shape_name[0] + '.renderable',
                 1)  #stereoCameraRightShape
    cmds.setAttr('topShape.renderable', 0)
    cmds.setAttr('sideShape.renderable', 0)
    cmds.setAttr('frontShape.renderable', 0)
    cmds.setAttr('perspShape.renderable', 0)

    #Set up the default AA sampling quality
    setDomeSamplingQuality()

    #---------------------------------------------------------------------------
    # Enable Real-time 3D in the OpenGL viewport
    # using a PreRender and PostRender MEL script
    #---------------------------------------------------------------------------
    #import maya.cmds as cmds

    #PreRender MEL:
    #cmds.setAttr( 'defaultRenderGlobals.preMel', "source \"domeRender.mel\"; domemaster3DPreRenderMEL();", type='string')
    #PostRender MEL:
    #cmds.setAttr( 'defaultRenderGlobals.postMel' , "source \"domeRender.mel\"; domemaster3DPostRenderMEL();", type='string')

    #enable realtime 3D
    #mel.eval("source \"domeRender.mel\"; domemaster3DPostRenderMEL();");

    return rig
Esempio n. 2
0
def sag_mirrorCam():
        if not pluginInfo( 'decomposeMatrix', query = True, loaded = True):
                loadPlugin( 'decomposeMatrix', quiet = True )

        selList = ls( sl = True )

        transList = []
        for each in selList:
                if objectType( each ) == 'transform' or objectType( each ) == 'stereoRigTransform':
                        transList.append( each )

        loc = spaceLocator( name = 'mirrorCam_loc' )[0]

        for each in transList:
                baseLoc = spaceLocator( name = 'mirrorCam_baseLoc' )[0]
                aimLoc = spaceLocator( name = 'mirrorCam_aimLoc' )[0]
                upLoc = spaceLocator( name = 'mirrorCam_upLoc' )[0]

                setAttr( aimLoc + '.tz', -1 )
                setAttr( upLoc + '.ty', 1 )
                setAttr( baseLoc + '.v', 0 )

                parent( aimLoc, upLoc, baseLoc )

                multMtx = createNode( 'multMatrix', name = 'mirrorCam_multMatrix' )
                decompMtx = createNode( 'decomposeMatrix', name = 'mirrorCam_decomposeMatrix' )

                connectAttr( each + '.worldMatrix', multMtx + '.matrixIn[0]' )
                connectAttr( loc + '.worldInverseMatrix', multMtx + '.matrixIn[1]' )
                maya.mel.eval( 'setAttr ' + multMtx + '.matrixIn[2] -type "matrix" 1 0 0 0 0 1 0 0 0 0 -1 0 0 0 0 1;' )
                connectAttr( loc + '.worldMatrix', multMtx + '.matrixIn[3]' )

                connectAttr( multMtx + '.matrixSum', decompMtx + '.inputMatrix' )

                setAttr( baseLoc + '.rotateOrder', getAttr( each + '.rotateOrder' ) )
                connectAttr( decompMtx + '.outputTranslate', baseLoc + '.t' )
                connectAttr( decompMtx + '.outputRotate', baseLoc + '.r' )
                connectAttr( decompMtx + '.outputScale', baseLoc + '.s' )

                cam = ''
                # DUPLICATE CAMERA
                if nodeType( each ) == 'stereoRigTransform':
                        # DUPLICATE STEREO CAMERA
                        eachShape = listRelatives( each, type = 'stereoRigCamera' )[0]

                        cam = stereoCameraRig.createStereoCameraRig( rigName = 'StereoCamera' )

                        cam[0] = rename( cam[0], 'mirrorCam_' + each.split( ':' )[-1] )
                        cam[1] = rename( cam[1], 'mirrorCam_' + each.split( ':' )[-1][:-1] + 'L' )
                        cam[2] = rename( cam[2], 'mirrorCam_' + each.split( ':' )[-1][:-1] + 'R' )

                        camShape = listRelatives( cam[0], type = 'stereoRigCamera' )[0]

                        attrListShape = set(['horizontalFilmAperture', 'verticalFilmAperture', 'shakeOverscan', 'shakeOverscanEnabled', 'horizontalFilmOffset',
                                             'verticalFilmOffset', 'shakeEnabled', 'horizontalShake', 'verticalShake', 'stereoHorizontalImageTranslateEnabled',
                                             'stereoHorizontalImageTranslate', 'preScale', 'filmTranslateH', 'filmTranslateV', 'horizontalRollPivot', 'verticalRollPivot',
                                             'filmRollValue', 'filmRollOrder', 'postScale', 'filmFit', 'filmFitOffset', 'focalLength', 'lensSqueezeRatio', 'cameraScale',
                                             'triggerUpdate', 'fStop', 'focusDistance', 'shutterAngle', 'centerOfInterest', 'tumblePivotX',
                                             'tumblePivotY', 'tumblePivotZ', 'usePivotAsLocalSpace', 'depthOfField',
                                             'useExploreDepthFormat', 'backgroundColorR', 'backgroundColorG', 'backgroundColorB', 'focusRegionScale',
                                             'toeInAdjust', 'filmOffsetRightCam', 'filmOffsetLeftCam', 'stereo', 'interaxialSeparation', 'zeroParallax'])

                        attrListTransform = set(['translate', 'rotate', 'scale'])

                        for eachAttr in attrListShape:
                                connectAttr( eachShape + '.' + eachAttr, camShape + '.' + eachAttr )

                        for eachAttr in attrListTransform:
                                connectAttr( each + '.' + eachAttr, cam[0] + '.' + eachAttr )

                        stereoShapes = listRelatives( each, allDescendents = True, type = 'camera' )
                        connectAttr( stereoShapes[1] + '.filmTranslateH', cam[1] + '.filmTranslateH' )
                        connectAttr( stereoShapes[2] + '.filmTranslateH', cam[2] + '.filmTranslateH' )

                        for eachCam in cam:
                                setAttr( eachCam + '.bestFitClippingPlanes', 0 )

                        cam = cam[0]
                else:
                        # DUPLICATE NON-STEREO CAMERA
                        cam = duplicate( each, ic = True )[0]

                        camName = 'mirrorCam_' + each
                        if each.rfind( ':' ) > -1:
                                camName = 'mirrorCam_' + each[each.rfind( ':' )+1:]
                        cam = rename( cam, camName )

                attrs = [ 't', 'tx', 'ty', 'tz', 'r', 'rx', 'ry', 'rz', 's', 'sx', 'sy', 'sz', 'v' ]
                for attr in attrs:
                        setAttr( cam + '.' + attr, lock = False, keyable = True )

                attrs += [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ', 'scaleX', 'scaleY', 'scaleZ', 'visibility', 'translate', 'rotate', 'scale' ]
                for attr in attrs:
                        conns = listConnections( cam + '.' + attr, s = True, d = False, c = True, p = True )
                        if conns != None:
                                for i in xrange( 0, len( conns ), 2 ):
                                        disconnectAttr( conns[i+1], conns[i] )

                if listRelatives( cam, parent = True ) != None:
                        parent( cam, world = True )

                select( baseLoc, cam, replace = True )
                pointConstraint( mo = False )
                select( aimLoc, cam, replace = True )
                aimConstraint( mo = False, aimVector = (0, 0, -1), upVector = (0, 1, 0), worldUpType = 'object', worldUpObject = upLoc )

                group( [ loc, baseLoc, cam ], name = 'mirror_cam_grp' )

                select( loc, replace = True )
def createArnoldLatLongStereoRig():
  import maya.cmds as cmds
  import maya.mel as mel
  
  # ---------------------------------------------------------------------
  # Setup the default Maya Settings
  # ---------------------------------------------------------------------
  cmds.loadPlugin( "stereoCamera", qt=True )
  
  # Make sure the Arnold plugin was loaded
  forceArnoldLoad()

  # ---------------------------------------------------------------------
  # Create the stereo rig
  # ---------------------------------------------------------------------
  
  #import maya.app.stereo.stereoCameraMenus as stereoCameraMenus
  #stereoCameraMenus.buildCreateMenu()
  #import maya.app.stereo.stereoCameraRig
  #maya.app.stereo.stereoCameraRig.createStereoCameraRig()
  
  from maya.app.stereo import stereoCameraRig
  
  # Set the default rig to an ArnoldLatLongStereoCamera
  cmds.stereoRigManager(defaultRig='ArnoldLatLongStereoCamera')
  
  # Add the camera rig to the scene
  rig = stereoCameraRig.createStereoCameraRig('ArnoldLatLongStereoCamera')
  #[u'ArnoldLatLongCamera', u'ArnoldLatLongCameraLeft', u'ArnoldLatLongCameraRight']
  
  #Get the stereo camera rig shape nodes for the center/right/left cameras
  rig_center_shape_name = getObjectShapeNode(rig[0])
  #[u'stereoCameraCenterCamShape', u'stereoCameraFrustum'] #

  rig_left_shape_name = getObjectShapeNode(rig[1])
  # Result: [u'stereoCameraLeftShape'] #

  rig_right_shape_name = getObjectShapeNode(rig[2])
  # Result: [u'stereoCameraRightShape'] #
  
  """
  cmds.setAttr( rig[0]+'.rotateX', 90)
  cmds.setAttr( rig[0]+'.rotateY', 0)
  cmds.setAttr( rig[0]+'.rotateZ', 0)
  
  """
  
  # Changes the render settings to set the stereo camera to be a renderable camera
  cmds.setAttr( rig_left_shape_name[0]+'.renderable', 1) #stereoCameraLeftShape
  cmds.setAttr( rig_right_shape_name[0]+'.renderable', 1) #stereoCameraRightShape
  cmds.setAttr( 'topShape.renderable', 0)
  cmds.setAttr( 'sideShape.renderable', 0)
  cmds.setAttr( 'frontShape.renderable', 0)
  cmds.setAttr( 'perspShape.renderable', 0)

  #Set up the default AA sampling quality
  setDomeSamplingQuality()
  
  #---------------------------------------------------------------------------
  # Enable Real-time 3D in the OpenGL viewport 
  # using a PreRender and PostRender MEL script
  #---------------------------------------------------------------------------
  #import maya.cmds as cmds

  #PreRender MEL:
  #cmds.setAttr( 'defaultRenderGlobals.preMel', "source \"domeRender.mel\"; domemaster3DPreRenderMEL();", type='string')
  #PostRender MEL:
  #cmds.setAttr( 'defaultRenderGlobals.postMel' , "source \"domeRender.mel\"; domemaster3DPostRenderMEL();", type='string')

  #enable realtime 3D
  #mel.eval("source \"domeRender.mel\"; domemaster3DPostRenderMEL();");
  
  return rig
Esempio n. 4
0
    def create(self, *args):
        """
		Create the Maya nodes per the specification of this template. 
		"""
        if self.checkMultibyte():
            return

        rigs = cmds.stereoRigManager(listRigs=True)
        defaultCam = cmds.stereoRigManager(query=True, defaultRig=True)
        standardDefault = defaultRigType.rigTypeName

        swapWithDefault = False
        askedUserAlready = False
        for i in range(self.layers()):
            rtype = self.rigTypeForLayer(i)
            if rtype not in rigs:
                if rtype == standardDefault and defaultCam != standardDefault:
                    # Check to make sure we haven't already asked the user
                    # for this create call.  There are multiple layers
                    # of a multi-rig and we don't want to ask the user
                    # the same question multiple times.
                    #
                    if not askedUserAlready:
                        swapWithDefault = swapDefault(standardDefault,
                                                      defaultCam)
                        askedUserAlready = True
                    if not swapWithDefault:
                        stereoCameraErrors.displayError('kRigNotFound', rtype)
                        return
                else:
                    stereoCameraErrors.displayError('kRigNotFound', rtype)
                    return

        camSet = None
        camSetType = self.cameraSetNodeType()
        val = cmds.objectType(tagFromType=camSetType)
        if val > 0:
            camSet = cmds.createNode(camSetType, name=self._templateName)
        else:
            stereoCameraErrors.displayError('kCameraSetNotFound', camSetType)
            return

        masterPrefix = self._camSetPrefix.replace(' ', '_')

        uniqueRigs = []
        for i in range(self.layers()):
            rtype = self.rigTypeForLayer(i)
            if rtype == standardDefault and swapWithDefault:
                rtype = defaultCam
                stereoCameraErrors.displayWarning('kDefaultRigSwap', rtype)

            if rtype not in uniqueRigs:
                uniqueRigs.append(rtype)
            layerPrefix = self.layerPrefixForLayer(i).replace(' ', '_')
            prefix = masterPrefix + layerPrefix
            autoCreateSet = self.autoCreateSet(i)
            rig = stereoCameraRig.createStereoCameraRig(rtype)
            objSet = None
            if autoCreateSet:
                objSet = cmds.createNode('objectSet', name=prefix + 'Set')
            stereoCameraSets.addNewRigToSet(rig[0], camSet, objSet)
            baseName = rig[0]
            for r in rig:
                cmds.rename(r, r.replace(baseName, prefix))

        # Notify once to all unique rigs that we have finished
        # building the multi rig.
        #
        for u in uniqueRigs:
            stereoCameraSets.notifyCameraSetCreateFinished(camSet, u)
Esempio n. 5
0
    def sk_sceneCameraBK(self ,shotInfos = [],shotType = sk_infoConfig.sk_infoConfig().checkShotType() , stereoCam = 0,stereoMode = 1,step = 1,bkCam = '' ):
        if not shotInfos:
            shotInfo = sk_infoConfig.sk_infoConfig().checkShotInfo()
        else:
            shotInfo = shotInfos
        camBase = ''
        camFind = 1
        if bkCam:
            camBase = bkCam
        else:
            if shotType == 2:
                camBase = 'cam_' + str(shotInfo[1]) + '_' + str(shotInfo[2])
            if shotType == 3:
                camBase = 'cam_' + str(shotInfo[1]) + '_' + str(shotInfo[2]) + '_' + str(shotInfo[3])
            if '.' in camBase:
                camBase = camBase.split('.')[0]
            if stereoMode:
                camBase += '_stCam'
            # 判断cam在不在
            if not camBase:
                camFind = 0
            if not mc.ls(camBase):
                camFind = 0
            else:
                if len(mc.ls(camBase)) != 1:
                    camFind = 0
        if not camFind:
            #errorInfo = (u'==========No Correct Cam[%s],or More Than One Cam[%s],please Fix the Camera Name=========='%(camBase,camBase))
            errorInfo = (u'==========未找到正版cam[%s],或cam名字不合法==========\n'%camBase)
            print errorInfo
            sk_infoConfig.sk_infoConfig().checkErrorWindows(errorInfo)
            sk_infoConfig.errorCode = errorInfo
            mc.error(errorInfo)

        # 准备工作
        # 时间轴信息
        io = (mc.playbackOptions(q=1, minTime=1)-10, mc.playbackOptions(q=1, maxTime=1)+10)

        # 一次BK开始
        locTemp = mc.spaceLocator()
        cons = mc.parentConstraint(camBase , locTemp , maintainOffset = 0)

        # 一次烘焙
        mc.bakeResults(locTemp,  t = io,
                simulation = 0,
                sampleBy=step,
                disableImplicitControl=1,
                preserveOutsideKeys=1,
                sparseAnimCurveBake=1,
                removeBakedAttributeFromLayer=0,
                bakeOnOverrideLayer=0,
                controlPoints=0,
                shape=1)
        mc.delete(cons)

        # 复制出信息
        camNeed = (camBase.split('|')[-1] + '_baked')
        checkCam = mc.ls(camNeed,l=1)
        if checkCam:
            mc.delete(checkCam)
        if stereoMode:
            pluginName = 'stereoCamera'
            if not mc.pluginInfo(pluginName,q= 1,loaded = 1):
                mc.loadPlugin(pluginName)
            from maya.app.stereo import stereoCameraRig
            camNew = stereoCameraRig.createStereoCameraRig(rigName='StereoCamera')
            camNew = mc.rename(camNew[0],camNeed)
            shapesOld = mc.listRelatives(camBase,s=1,f=1)
            shapesNew = mc.listRelatives(camNew,s=1,f=1)
            for i in range(len(shapesOld)):
                # 连接
                self.sk_bakeStereoCameraConnect(shapesOld[i],shapesNew[i])
        else:
            camNew = mc.duplicate(camBase,returnRootsOnly = 1,inputConnections = 1)
            camNew = mc.rename(camNew[0],camNeed.split('|')[-1])

        # cam mode不需要sx,sy,sz和v
        noNeedList = ['.sx','.sy','.sz','.v']
        for checkAttr in noNeedList:
            camAttr = camNew + checkAttr
            cons = mc.listConnections(camAttr,s=1,d=0,plugs=1)
            mc.setAttr(camAttr,l=0)
            if cons:
                mc.disconnectAttr(cons[0],camAttr)
            lockState = mc.getAttr(camAttr,l=1)
            if lockState:
                tempAttr = mc.connectionInfo(camAttr,gla=1)
                if tempAttr:
                    mc.setAttr(tempAttr,l=0)
            mc.setAttr(camAttr,1)

        # 清理目标camera物体
        chilrdNodes = mc.listRelatives(camNew,ad = 1,f=1)
        for checkNode in chilrdNodes:
            if not mc.ls(checkNode):
                continue
            checkType = mc.nodeType(checkNode)
            if checkType in ['camera','stereoRigFrustum','stereoRigCamera']:
                continue
            deleteState = 1
            if checkType in ['transform']:
                child = mc.listRelatives(checkNode,s=1,f=1)
                if not child:
                    deleteState = 0
                else:
                    for checkChild in child:
                        checkType = mc.nodeType(checkChild)
                        if checkType in ['camera','stereoRigFrustum','stereoRigCamera']:
                            deleteState = 0
            if deleteState:
                mc.delete(checkNode)
        # 解锁
        from idmt.maya.commonCore.core_mayaCommon import sk_sceneTools
        reload(sk_sceneTools)
        sk_sceneTools.sk_sceneTools().checkLockObjs([camNeed],0,1)

        # 祛除translate和rotate的约束
        if shotInfo[0] !='nj':
            camNewFull = mc.ls(camNew,l=1)[0]
            if len(camNewFull.split('|')) != 2:
                mc.parent(camNew,world = 1)
            for attr in ['.tx','.ty','.tz','.rx','.ry','.rz']:
                mc.setAttr((camNew + attr), lock = False)
                consAttr = mc.listConnections((camNew + attr),s=1,d=0,plugs=1)
                if not consAttr:
                    continue
                mc.disconnectAttr(consAttr[0],(camNew + attr))

        # 二次BK开始
        cons = mc.parentConstraint(locTemp , camNew , maintainOffset = 0)

        # 二次烘焙
        mc.bakeResults(camNew,  t=io,
                simulation = 0,
                sampleBy=step,
                disableImplicitControl = 1 ,
                preserveOutsideKeys = 1 ,
                sparseAnimCurveBake = 1 ,
                removeBakedAttributeFromLayer = 0 ,
                bakeOnOverrideLayer = 0 ,
                controlPoints = 0 ,
                shape = 1 )

        if stereoMode:
            camShape = mc.listRelatives(camNew,s = 1,ni=1)[0]
            childGrps = mc.listRelatives(camNew,c=1,type = 'transform')
            leftGrp = ''
            rightGrp = ''
            for checkGrp in childGrps:
                if 'Left' in checkGrp:
                    leftGrp = checkGrp
                if 'Right' in checkGrp:
                    rightGrp = checkGrp
            # 重新处理立体连接
            leftGrpAttr = '%s|%s.tx'%(camNew,leftGrp)
            tempAttr = mc.connectionInfo(leftGrpAttr,gla=1)
            if tempAttr:
                mc.setAttr(tempAttr,l=0)
            cons = mc.listConnections(leftGrpAttr,s=1,d=0,plugs=1)
            if shotInfo[0] in ['do6'] and cons:
                mel.eval('source "channelBoxCommand.mel"')
                mel.eval('CBunlockAttr %s'%leftGrpAttr)
            if cons:
                mc.disconnectAttr(cons[0],leftGrpAttr)
            mc.expression(s = '%s=-0.5*%s.interaxialSeparation'%(leftGrpAttr,camShape),o = leftGrp )

            rightGrpAttr = '%s|%s.tx'%(camNew,rightGrp)
            tempAttr = mc.connectionInfo(rightGrpAttr,gla=1)
            if tempAttr:
                mc.setAttr(tempAttr,l=0)
            cons = mc.listConnections(rightGrpAttr,s=1,d=0,plugs=1)
            if shotInfo[0] =='do6' and cons:
                mel.eval('source "channelBoxCommand.mel"')
                mel.eval('CBunlockAttr %s' %rightGrpAttr)
            if cons:
                mc.disconnectAttr(cons[0],rightGrpAttr)
            mc.expression(s = '%s=0.5*%s.interaxialSeparation'%(rightGrpAttr,camShape),o = rightGrp )

            # pairx
            rigShape = mc.listRelatives(camNew,s=1,type = 'stereoRigCamera')[0]
            rigFrustum = mc.listRelatives(camNew,s=1,type = 'stereoRigFrustum')[0]
            print '------------tMode'
            print camShape
            print rigShape
            mc.connectAttr('%s.zeroParallax'%camShape,'%s.zeroParallax'%camNew,f=1)
            mc.connectAttr('%s.zeroParallax'%camShape,'%s.zeroParallax'%rigFrustum,f=1)

            # center
            attrs = ['.filmOffsetLeftCam','.filmOffsetRightCam','.interaxialSeparation','.stereo','.toeInAdjust']
            centerPre = camNeed
            centerShape = centerPre + 'CenterCamShape'
            centerGrp = centerPre
            for attr in attrs:
                mc.setAttr((centerGrp + attr),l = 0)
                mc.connectAttr((centerShape + attr),(centerGrp + attr) ,f = 1)
        cons = mc.listConnections(camNew,s = 1 ,type = 'constraint')
        if cons:
            cons = list(set(cons))
            mc.delete(cons)
        # 清理shape的某些信息
        camNewShape = mc.listRelatives(camNew,s=1,type = 'camera',f=1)
        shapeCons = mc.listConnections(camNewShape,s=1,d=0,c=1,plugs=1)
        if shapeCons:
            consNum = len(shapeCons)
            for num in range(consNum/2):
                consAttr = shapeCons[num*2+1]
                if '>' in consAttr:
                    consAttr = consAttr.split('>')[-1]
                consNode = consAttr.split('.')[0]
                # 判断
                nodeType = mc.nodeType(consNode)
                if 'animCurve' in nodeType:
                    continue
                checkAttr = shapeCons[num*2+1]
                if (not mc.referenceQuery(checkAttr.split('.')[0],inr = 1)) and mc.getAttr(checkAttr,l=1):
                    mc.setAttr(checkAttr,l=0)
                checkAttr = shapeCons[num*2]
                if (not mc.referenceQuery(checkAttr.split('.')[0],inr = 1)) and mc.getAttr(checkAttr,l=1):
                    mc.setAttr(checkAttr,l=0)
                # 断开
                mc.disconnectAttr(shapeCons[num*2+1],shapeCons[num*2])

        # 善后,清理
        mc.delete(locTemp)

        # 属性
        baseShape = mc.listRelatives(camBase,s=1,f=1)[0]
        newShape = mc.listRelatives(camNew,s=1,type = 'camera',f=1)[0]
        fixAttrList = ['.horizontalFilmAperture','.verticalFilmAperture','.filmFit']
        for attr in fixAttrList:
            newAttr = newShape + attr
            if not mc.ls(newAttr):
                continue
            oldAttr = baseShape + attr
            mc.setAttr(newAttr,l=0)
            mc.setAttr(newAttr,mc.getAttr(oldAttr))

        # 处理scale,属性打1
        for attr in ['.sx','.sy','.sz']:
            cons = mc.listConnections((camNew + attr),s=1,d=0,plugs=1)
            if cons:
                mc.disconnectAttr(cons[0],(camNew + attr))
            mc.setAttr((camNew + attr),l=0)
            mc.setAttr((camNew + attr),1)

        # 恢复立体连接
        # 锁、出组
        fixCamList = []
        if stereoMode:
            camShapes = mc.listRelatives(camNew,ad=1,type='camera',f=1)
            fixCamList = mc.listRelatives(camShapes,p=1,type='transform',f=1)
        sk_sceneTools.sk_sceneTools().checkLockObjs(fixCamList,1,1)
        for checkCam in fixCamList:
            attrs = mc.listAttr(checkCam,k=1)
            if not attrs:
                continue
            for attr in attrs:
                mc.setAttr((checkCam + '.' +attr),l = 1)
Esempio n. 6
0
def zwz_CreateStereoCamera_menu():
    #def zwz_CreateStereoCamera_menu():
    #左眼摄像机
    LMCamera = CreatMyCamera_zwz('L_M', [0, 0, 0])
    LLCamera = CreatMyCamera_zwz('L_L', [0, 60, 0])
    LRCamera = CreatMyCamera_zwz('L_R', [0, -60, 0])
    #右眼摄像机
    RMCamera = CreatMyCamera_zwz('R_M', [0, 0, 0])
    RLCamera = CreatMyCamera_zwz('R_L', [0, 60, 0])
    RRCamera = CreatMyCamera_zwz('R_R', [0, -60, 0])
    #立体摄像机
    mm.eval('loadPlugin -qt "stereoCamera";')
    from maya.app.stereo import stereoCameraRig
    myStereo = stereoCameraRig.createStereoCameraRig(rigName='StereoCamera')
    CenterShape = mc.listRelatives(myStereo[0], s=True, pa=True)
    mc.setAttr("%s.horizontalFilmAperture" % CenterShape[0], 1)
    mc.setAttr("%s.verticalFilmAperture" % CenterShape[0], 1)
    mc.setAttr("%s.focalLength" % CenterShape[0], 21.997)
    mc.setAttr("%s.interaxialSeparation" % CenterShape[0], 0.068)
    mc.setAttr("%s.farClipPlane" % CenterShape[0], 1000000)
    mc.setAttr("%s.stereo" % CenterShape[0], 1)
    mc.setAttr("%s.zeroParallax" % CenterShape[0], 5)
    mc.setAttr("%s.translate" % myStereo[1], l=False)
    mc.setAttr("%s.rotate" % myStereo[1], l=False)
    mc.setAttr("%s.translate" % myStereo[2], l=False)
    mc.setAttr("%s.rotate" % myStereo[2], l=False)
    mc.disconnectAttr('%s.stereoLeftOffset' % myStereo[0],
                      '%s.translateX' % myStereo[1])
    mc.disconnectAttr('%s.stereoLeftAngle' % myStereo[0],
                      '%s.rotateY' % myStereo[1])
    mc.disconnectAttr('%s.stereoRightOffset' % myStereo[0],
                      '%s.translateX' % myStereo[2])
    mc.disconnectAttr('%s.stereoRightAngle' % myStereo[0],
                      '%s.rotateY' % myStereo[2])
    mc.pointConstraint(LMCamera[0], myStereo[1], w=1)
    mc.orientConstraint(LMCamera[0], myStereo[1], w=1)
    mc.pointConstraint(RMCamera[0], myStereo[2], w=1)
    mc.orientConstraint(RMCamera[0], myStereo[2], w=1)
    LockObjectTRS(myStereo[0], True)
    LGroup = mc.group(LMCamera[0], LLCamera[0], LRCamera[0], n='L_Cameras')
    LGroup = mc.ls(LGroup, l=True)[0]
    mc.xform(LGroup, t=[-0.034, 0, 0])
    LockObjectTRS(LGroup, True)
    RGroup = mc.group(RMCamera[0],
                      RLCamera[0],
                      RRCamera[0],
                      n='R_Cameras',
                      absolute=True)
    RGroup = mc.ls(RGroup, l=True)[0]
    mc.xform(RGroup, t=[0.034, 0, 0])
    LockObjectTRS(RGroup, True)
    myGroup = mc.group(LGroup, RGroup, myStereo[0], n='Cam_Rig')
    mc.setAttr('%s.visibility' % myGroup, 0)
    #测试摄像机
    TMCamera = CreatMyCamera_zwz('Test_M_T', [0, 0, 0])
    LockObjectTRS(TMCamera[0], False)
    mc.pointConstraint(TMCamera[0], myGroup, w=1)
    mc.orientConstraint(TMCamera[0], myGroup, w=1)
    mc.scaleConstraint(TMCamera[0], myGroup, w=1)
    LockObjectTRS(myGroup, True)
    TLCamera = CreatMyCamera_zwz('Test_L', [0, 60, 0])
    mc.setAttr('%s.template' % TLCamera[1][0], 1)
    TRCamera = CreatMyCamera_zwz('Test_R', [0, -60, 0])
    mc.setAttr('%s.template' % TRCamera[1][0], 1)
    mc.parent(TLCamera[0], TMCamera[0])
    mc.parent(TRCamera[0], TMCamera[0])
    TMCamera[1] = mc.rename(TMCamera[1], 'Test_M')
    myLocator = mc.spaceLocator(n='Constrain_for_animation', p=(0, 0, 0))
    mc.xform(myLocator, s=[10, 10, 10])
    mc.pointConstraint(TMCamera[0], myLocator, w=1)
    mc.orientConstraint(TMCamera[0], myLocator, w=1)
    testGroup = mc.group(TMCamera, myLocator, n='Test_Cam_Rig')
    LockObjectTRS(testGroup, False)
    HideObjectAttr(testGroup, False)
    LockObjectTRS(myLocator[0], True)