Example #1
0
def arsenal_proxyShaderAutoConnect(ignoreNamespace = False):
    if ignoreNamespace:
        print '[Arsenal ToolBox] Namespace ignored'
    else:
        print '[Arsenal ToolBox] Namespace not ignored'
    proxyMaterialNodes = pm.ls(type='VRayMeshMaterial')
    allMaterials = pm.ls(materials=True)
    materialClean = list(set(allMaterials) - set(proxyMaterialNodes))
    if len(proxyMaterialNodes) == 0:
        OpenMaya.MGlobal.displayWarning('No VRayMeshMaterial in the scene !')
    for proxyMaterialNode in proxyMaterialNodes:
        numberOfSlot = proxyMaterialNode.shaderNames.get(size=True)
        for i in range(numberOfSlot):
            nameSlot = pm.getAttr(proxyMaterialNode + '.shaderNames[' + str(i) + ']')
            if pm.connectionInfo(proxyMaterialNode + '.shaders[' + str(i) + ']', isDestination=True):
                connected = pm.connectionInfo(proxyMaterialNode + '.shaders[' + str(i) + ']', sourceFromDestination=True)
                pm.disconnectAttr(connected, proxyMaterialNode + '.shaders[' + str(i) + ']')
                print '[Arsenal ToolBox] Disconnect ' + proxyMaterialNode + '.shaders[' + str(i) + ']'
            for myMat in materialClean:
                okConnect = False
                if ignoreNamespace:
                    if myMat.split(':')[-1] == nameSlot.split(':')[-1]:
                        okConnect = True
                elif myMat == nameSlot:
                    okConnect = True
                if okConnect:
                    pm.connectAttr(myMat + '.outColor', proxyMaterialNode + '.shaders[' + str(i) + ']', f=True)
                    print '[Arsenal ToolBox] ' + proxyMaterialNode + '.shaders[' + str(i) + '] connected.'
Example #2
0
    def create_blinn(self):
        """
        creates a blinn for observing how light interacts with the surface of an object
        """
        oSel = pm.ls(sl=True)

        self.normal_shader = pm.shadingNode('blinn', asShader=True)
        self.normal_shading_group = pm.sets(renderable=True,
                                            noSurfaceShader=True,
                                            empty=True)
        pm.connectAttr('%s.outColor' % self.normal_shader,
                       '%s.surfaceShader' % self.normal_shading_group)
        for objs in oSel:
            pm.select(objs)
            pm.hyperShade(assign='%s' % self.normal_shader)
        pm.select(oSel)
Example #3
0
 def refreshArsenalPassMember(self, myRenderLayer = None, progressBarUpdate = None):
     if myRenderLayer.name() != 'defaultRenderLayer':
         if pm.getAttr(myRenderLayer.name() + '.global') == 0:
             myMemberRenderLayer = myRenderLayer.listMembers(fullNames=True)
             if myMemberRenderLayer is None:
                 return 
             myMemberRenderLayer = list(set(myMemberRenderLayer))
             myMemberArsenalPass = pm.PyNode(myRenderLayer.name() + '_arsenalPass.passMembers').inputs(shapes=True)
             difference = list(set(myMemberRenderLayer).symmetric_difference(set(myMemberArsenalPass)))
             if difference:
                 for (i, myMember,) in enumerate(difference):
                     if not pm.PyNode(myMember + '.message').isConnectedTo(myRenderLayer.name() + '_arsenalPass.passMembers', checkOtherArray=True):
                         if progressBarUpdate is not None:
                             progressBarUpdate(numStep=len(difference), value=i, text='Pass ' + myRenderLayer.name() + ' step 1 : connect passMembers %v of %m ...')
                         pm.connectAttr(myMember + '.message', myRenderLayer.name() + '_arsenalPass.passMembers', force=True, nextAvailable=True)
                     else:
                         if progressBarUpdate is not None:
                             progressBarUpdate(numStep=len(difference), value=i, text='Pass ' + myRenderLayer.name() + ' step 1 : disconnect passMembers %v of %m ...')
                         pm.PyNode(myMember + '.message').disconnect(destination=myRenderLayer.name() + '_arsenalPass.passMembers', nextAvailable=True)
Example #4
0
 def duplicatePass(self, layer = None, name = None):
     if layer is None:
         OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
         return 
     if name is None:
         OpenMaya.MGlobal.displayError('[Arsenal] You must to enter a name')
         return 
     if not self.checkStringName(text=name):
         OpenMaya.MGlobal.displayError('[Arsenal] You must to choose a valid name')
         return 
     newLayer = pm.mel.eval('duplicate -ic -n ' + name + ' ' + self.passName[layer].passName)[0]
     pm.lockNode(self.passName[layer].passName + '_arsenalPass', lock=False)
     newArsenalPass = pm.mel.eval('duplicate -ic -n ' + name + '_arsenalPass ' + self.passName[layer].passName + '_arsenalPass')[0]
     pm.lockNode(self.passName[layer].passName + '_arsenalPass', lock=True)
     pm.lockNode(newArsenalPass, lock=True)
     pm.connectAttr(newLayer + '.message', newArsenalPass + '.passName', f=True)
     if pm.PyNode(newLayer) not in self.passName:
         self.passName[pm.PyNode(newLayer)] = ArsenalPass()
         self.passName[pm.PyNode(newLayer)].passName = newLayer
         self.selectPass(layer=pm.PyNode(newLayer))
Example #5
0
    def addObjects(self, selection = None, renderPass = None, attribute = None):
        if selection is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select some poly object(s)')
            return 
        if renderPass is None:
            OpenMaya.MGlobal.displayError('[Arsenal] You must to select a pass')
            return 
        self.multiMatteAttributes(myRenderLayer=renderPass)
        cmd = 'self.passName[renderPass].' + str(attribute) + ' = ' + str(selection).replace('nt.', 'pm.nt.')
        exec cmd
        exec 'newValue = self.passName[renderPass].' + str(attribute)
        arsenalPass = pm.PyNode(renderPass + '_arsenalPass.' + attribute)
        for mySelect in newValue:
            arrayList = arsenalPass.getArrayIndices()
            finalNumber = 0
            if arrayList:
                finalNumber = arrayList[-1] + 1
            if mySelect not in pm.listConnections(renderPass + '_arsenalPass.' + attribute, destination=False, source=True):
                pm.connectAttr(mySelect + '.message', renderPass + '_arsenalPass.' + attribute + '[' + str(finalNumber) + ']', f=True)

        print '[Arsenal] Object(s) add done.'
Example #6
0
    def create_shader(self, sh):
        lamb = pm.shadingNode("lambert", asShader=True, name=sh)
        tex_nd = pm.shadingNode("file",
                                asTexture=True,
                                name=sh + "_fileTexture")
        tex_nd.fileTextureName.set(self.tex_path + self.tex_dict[sh])
        tex2d_nd = pm.shadingNode("place2dTexture",
                                  asUtility=True,
                                  name=sh + "_2dTex")

        att_list = [
            ".vertexUvOne", ".rotateUV", ".offset", ".repeatUV", ".stagger",
            ".wrapV", ".mirrorU", ".mirrorV", ".coverage", ".wrapU",
            ".vertexCameraOne", ".vertexUvThree", ".rotateFrame",
            ".vertexUvTwo", ".translateFrame", ".noiseUV"
        ]

        pm.connectAttr(str(tex2d_nd) + ".outUV", str(tex_nd) + ".uv")
        pm.connectAttr(
            str(tex2d_nd) + ".outUvFilterSize",
            str(tex_nd) + ".uvFilterSize")
        for att in att_list:
            pm.connectAttr(str(tex2d_nd) + att, str(tex_nd) + att)

        tex_nd.outColor.connect(lamb.color)
        return None
Example #7
0
import pymel.all as pm

sel = pm.ls(sl=True)
src = sel.pop(0)

cpos = pm.ClosestPointOnSurface()
pm.connectAttr(src.getShape().worldSpace, cpos.inputSurface)
pm.select(None)

for obj in sel:
    cpos.inPosition.set(obj.getTranslation(space='world'))
    uv = (cpos.u.get(), cpos.v.get())
    print uv

    fol = pm.Follicle()
    src.local >> fol.inputSurface
    src.getShape().worldMatrix[0] >> fol.inputWorldMatrix
    fol.outRotate >> fol.getParent().rotate
    fol.outTranslate >> fol.getParent().translate

    fol.parameterU.set(uv[0])
    fol.parameterV.set(uv[1])

    pm.parentConstraint(fol.getParent(), obj, mo=True)

#pm.delete(cpos)

pm.select(src, sel)
Example #8
0
import pymel.all as pm

sel = pm.ls(sl=True)
src = sel.pop(0)

cpos = pm.ClosestPointOnSurface()
pm.connectAttr( src.getShape().worldSpace, cpos.inputSurface )
pm.select(None)

for obj in sel :
    cpos.inPosition.set( obj.getTranslation( space='world') )
    uv = ( cpos.u.get(), cpos.v.get() )
    print uv
    
    fol = pm.Follicle()
    src.local >> fol.inputSurface
    src.getShape().worldMatrix[0] >> fol.inputWorldMatrix
    fol.outRotate >> fol.getParent().rotate
    fol.outTranslate >> fol.getParent().translate
    
    fol.parameterU.set( uv[0] )
    fol.parameterV.set( uv[1] )

    pm.parentConstraint( fol.getParent(), obj, mo=True )

    
#pm.delete(cpos)

pm.select( src, sel )
Example #9
0
def setup_ik_spline(**kwargs):
    curve = kwargs.get("curve", None)
    joint_chain = kwargs.get("joint_chain", None)
    auto_curve = kwargs.get("auto_curve", True)
    use_curve = kwargs.get("use_curve", None)
    spans = kwargs.get("number_of_spans", 4)
    ctrl_jnts = kwargs.get("num_control_joints", 3)
    ik_name = kwargs.get("ik_name", "ikHandle")
    scale_stretch = kwargs.get("scale_stretch", False)
    create_dense_chain = kwargs.get("dense_chain", False)
    dense_division = kwargs.get("dense_chain_divisions", 3)
    auto_simplify = kwargs.get("auto_simplify_curve", False)
    stretch_exp = kwargs.get("stretch_exp", False)
    global_scale_check = kwargs.get("global_scale_check", False)
    global_scale_attr = kwargs.get("global_scale_attr", None)

    pm.select(joint_chain, hierarchy=True)
    joint_chain = pm.ls(selection=True)
    if not isinstance(joint_chain[0], pm.Joint):
        pm.displayInfo("selection should be of type joint")
        return None
    if len(joint_chain) < 2:
        pm.displayInfo("Chain should consist of more than one joint")
        return None

    if (global_scale_check):
        if (global_scale_attr is None):
            pm.displayInfo("Please input global scale attribute")
            return None
        else:
            obj = global_scale_attr.split(".")[0]
            global_attr = global_scale_attr.split(".")[1]
            check_global_attr = pm.attributeQuery(global_attr,
                                                  node=obj,
                                                  exists=True)
            if not check_global_attr:
                pm.displayInfo("Invalid global scale attribute")
                return None

    start_jnt = joint_chain[0]
    end_joint = joint_chain[-1]

    if create_dense_chain:
        rep_chain = pm.duplicate(joint_chain)
        start_jnt = rep_chain[0]
        end_joint = rep_chain[-1]
        dense_chain(joints=rep_chain, joints_inbetween=dense_division)
        rep_chain.append(end_joint)
        for index in range(len(joint_chain)):
            pm.parentConstraint(rep_chain[index],
                                joint_chain[index],
                                maintainOffset=False)
            #pm.scaleConstraint(rep_chain[index], joint_chain[index], maintainOffset=False)
            pm.connectAttr(
                str(rep_chain[index]) + ".scale",
                str(joint_chain[index]) + ".scale")
        pm.select(start_jnt, hierarchy=True)
        new_chain = pm.ls(selection=True)

    crv = ""

    #print "START", start_jnt
    #print "END",end_joint

    if auto_curve:
        ik_handle, eff, crv = pm.ikHandle(startJoint=start_jnt,
                                          createCurve=auto_curve,
                                          solver="ikSplineSolver",
                                          numSpans=spans,
                                          endEffector=end_joint,
                                          simplifyCurve=auto_simplify)

    else:
        crv = pm.PyNode(use_curve)
        ik_handle, eff = pm.ikHandle(startJoint=start_jnt,
                                     curve=use_curve,
                                     solver="ikSplineSolver",
                                     endEffector=end_joint,
                                     createCurve=False)

    crv.inheritsTransform.set(0)

    pm.rename(ik_handle, ik_name + "IK_Handle")
    pm.rename(crv, ik_name + "IK_Curve")

    ik_curve_shp = crv.getShape()
    crv_info_node = pm.createNode("curveInfo")
    pm.connectAttr(ik_curve_shp + ".worldSpace", crv_info_node + ".inputCurve")
    '''
    if stretch_exp:
        if create_dense_chain:
            stretch_expression(joints = new_chain, curve_info_node = crv_info_node, connect_scale = scale_stretch,
                               expression_name = ik_name+"_stretch_expression")
        else:
            stretch_expression(joints = joint_chain, curve_info_node = crv_info_node, connect_scale = scale_stretch,
                               expression_name = ik_name+"_stretch_expression")
    '''

    if ctrl_jnts:
        if ctrl_jnts == 1:
            print "Minimum 2 joints needed as controllers"
            print "skipping control joint creation process"
            pm.displayInfo("Minimum 2 joints needed as controllers")
        else:
            ctrl_jnts = joints_along_curve(number_of_joints=ctrl_jnts,
                                           curve=crv,
                                           bind_curve_to_joint=True)
            pm.select(clear=True)
            ctr_jnt_gp = pm.group(ctrl_jnts, name="control_joints")
            #print "JNT NAME", ctr_jnt_gp

    if stretch_exp:
        pm.addAttr(ctrl_jnts[-1],
                   longName="Stretch",
                   attributeType="enum",
                   enumName="off:on",
                   keyable=True)
        print "ATTRIBUTE TO", str(ctrl_jnts[-1])
        if create_dense_chain:
            stretch_expression(joints=new_chain,
                               curve_info_node=crv_info_node,
                               connect_scale=scale_stretch,
                               expression_name=ik_name + "_stretch_expression",
                               ctrl_attr=str(ctrl_jnts[-1]) + ".Stretch",
                               glbl_scl_stat=global_scale_check,
                               glbl_scl_attr=global_scale_attr)
        else:
            stretch_expression(joints=joint_chain,
                               curve_info_node=crv_info_node,
                               connect_scale=scale_stretch,
                               expression_name=ik_name + "_stretch_expression",
                               ctrl_attr=str(ctrl_jnts[-1]) + ".Stretch",
                               glbl_scl_stat=global_scale_check,
                               glbl_scl_attr=global_scale_attr)

    final_group = pm.group(name=ik_name + "_ik_group", empty=True)
    pm.parent(joint_chain[0], final_group)
    pm.parent(crv, final_group)
    pm.parent(ik_handle, final_group)
    if ctrl_jnts > 1:
        pm.parent(ctr_jnt_gp, final_group)
    if create_dense_chain:
        pm.select(clear=True)
        dense_grp = pm.group(start_jnt, name="dense_chain_group")
        pm.parent(dense_grp, final_group)

    return None
Example #10
0
    def createCtrl(self, name):
        #cameraName = camera[0].name()
        cameraShape = self.camera.getShape()

        # 그룹 리깅
        constraint = pm.group(n=name + "_constraint", em=True)
        offset = pm.group(n=name + "_offset")
        shakeTransform = pm.group(n=name + "_Shake")
        offsetTz = pm.group(n=name + "_offsetTz")
        offsetTy = pm.group(n=name + "_offsetTy")
        offsetTx = pm.group(n=name + "_offsetTx")
        tz = pm.group(n=name + "_tz")
        rz = pm.group(n=name + "_rz")
        rx = pm.group(n=name + "_rx")
        ry = pm.group(n=name + "_ry")
        ctrl = pm.group(n=name + "_Ctrl")
        pm.setAttr(ctrl + ".displayHandle", 1)
        pm.setAttr(ctrl + ".overrideEnabled", 1)
        pm.setAttr(ctrl + ".overrideColor", 7)  #dark_green

        # Display
        dispGrp = pm.group(n=name + "_Template_Grp", em=1)
        pm.parent(dispGrp, ctrl)
        pm.setAttr(dispGrp + ".overrideEnabled", 1)
        pm.setAttr(dispGrp + ".overrideDisplayType", 1)
        pm.setAttr(dispGrp + ".overrideColor", 7)  #dark_green

        dispNodeList = []
        dispNodeList.extend(self.displayConnect([ctrl, tz]))
        dispNodeList.extend(self.displayConnect([tz, offsetTx]))
        dispNodeList.extend(self.displayConnect([offsetTx, offsetTy]))
        dispNodeList.extend(self.displayConnect([offsetTy, offsetTz]))

        # Outline
        for dispNode in dispNodeList:
            dispNode.rename(name + '_' + dispNode.name())

        pm.parent(dispNodeList, dispGrp)

        # Add attribute
        # Camera attribute
        pm.addAttr(ctrl, ln="Camera", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Camera", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="focalLength",
                   dv=35,
                   at='double',
                   nn="FocalLength (mm)",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="overscan",
                   dv=1,
                   at='double',
                   nn="Overscan",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="frameRange",
                   at='double2',
                   nn="Frame Range (frame)")
        pm.addAttr(ctrl,
                   ln="startFrame",
                   p='frameRange',
                   at='double',
                   nn="Start Frame",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="endFrame",
                   p='frameRange',
                   at='double',
                   nn="End Frame",
                   keyable=True)
        # Tumble attribute
        pm.addAttr(ctrl, ln="Tumble", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Tumble", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="tumbleTranslateZ",
                   at='double',
                   nn="Tumble Translate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="tumbleRotate", at='double3', nn="Tumble Rotate")
        pm.addAttr(ctrl,
                   ln="tumbleRotateX",
                   p='tumbleRotate',
                   at='double',
                   nn="Tumble Rotate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="tumbleRotateY",
                   p='tumbleRotate',
                   at='double',
                   nn="Tumble Rotate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="tumbleRotateZ",
                   p='tumbleRotate',
                   at='double',
                   nn="Tumble Rotate Z",
                   keyable=True)
        # Shake attribute
        pm.addAttr(ctrl, ln="Shake", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Shake", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="time",
                   keyable=False,
                   at='double',
                   nn="Shake Time (second)")
        pm.addAttr(ctrl,
                   ln="timeOffset",
                   keyable=False,
                   at='double',
                   nn="Shake Time Offset (second)")
        pm.addAttr(ctrl, ln="shake1", at='double2', nn=u"Shake 1st (진폭, 주기)")
        pm.addAttr(ctrl,
                   ln="shakeAmplitude1",
                   p='shake1',
                   at='double',
                   nn=u"Shake 1st (진폭)",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeFrequency1",
                   p='shake1',
                   at='double',
                   nn=u"Frequency 1st (주기)",
                   keyable=True)
        pm.addAttr(ctrl, ln="noise1", at='double3', nn="Shake Noise 1st")
        pm.addAttr(ctrl,
                   ln="noise1X",
                   p='noise1',
                   at='double',
                   nn="Shake Noise 1 X")
        pm.addAttr(ctrl,
                   ln="noise1Y",
                   p='noise1',
                   at='double',
                   nn="Shake Noise 1 Y")
        pm.addAttr(ctrl,
                   ln="noise1Z",
                   p='noise1',
                   at='double',
                   nn="Shake Noise 1 Z")
        pm.addAttr(ctrl, ln="shake2", at='double2', nn=u"Shake 2nd (진폭, 주기)")
        pm.addAttr(ctrl,
                   ln="shakeAmplitude2",
                   p='shake2',
                   at='double',
                   nn=u"Shake 2nd (진폭)",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeFrequency2",
                   p='shake2',
                   at='double',
                   nn=u"Frequency 2nd (주기)",
                   keyable=True)
        pm.addAttr(ctrl, ln="noise2", at='double3', nn="Shake Noise 2nd")
        pm.addAttr(ctrl,
                   ln="noise2X",
                   p='noise2',
                   at='double',
                   nn="Shake Noise 2 X")
        pm.addAttr(ctrl,
                   ln="noise2Y",
                   p='noise2',
                   at='double',
                   nn="Shake Noise 2 Y")
        pm.addAttr(ctrl,
                   ln="noise2Z",
                   p='noise2',
                   at='double',
                   nn="Shake Noise 2 Z")
        pm.addAttr(ctrl,
                   ln="shakeTranslate",
                   at='double3',
                   nn="Shake Translate")
        pm.addAttr(ctrl,
                   ln="shakeTranslateX",
                   p='shakeTranslate',
                   at='double',
                   nn="Shake Translate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeTranslateY",
                   p='shakeTranslate',
                   at='double',
                   nn="Shake Translate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeTranslateZ",
                   p='shakeTranslate',
                   at='double',
                   nn="Shake Translate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="shakeRotate", at='double3', nn="Shake Rotate")
        pm.addAttr(ctrl,
                   ln="shakeRotateX",
                   p='shakeRotate',
                   at='double',
                   nn="Shake Rotate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeRotateY",
                   p='shakeRotate',
                   at='double',
                   nn="Shake Rotate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="shakeRotateZ",
                   p='shakeRotate',
                   at='double',
                   nn="Shake Rotate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="shakeScale", at='double', dv=1.0, keyable=True)
        pm.addAttr(ctrl, ln="timeScale", at='double', dv=1.0, keyable=True)
        # Offset attribute
        pm.addAttr(ctrl, ln="Offset", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Offset", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="offsetTranslate",
                   at='double3',
                   nn="Offset Translate")
        pm.addAttr(ctrl,
                   ln="offsetTranslateX",
                   p='offsetTranslate',
                   at='double',
                   nn="Offset Translate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetTranslateY",
                   p='offsetTranslate',
                   at='double',
                   nn="Offset Translate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetTranslateZ",
                   p='offsetTranslate',
                   at='double',
                   nn="Offset Translate Z",
                   keyable=True)
        pm.addAttr(ctrl, ln="offsetRotate", at='double3', nn="Offset Rotate")
        pm.addAttr(ctrl,
                   ln="offsetRotateX",
                   p='offsetRotate',
                   at='double',
                   nn="Offset Rotate X",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetRotateY",
                   p='offsetRotate',
                   at='double',
                   nn="Offset Rotate Y",
                   keyable=True)
        pm.addAttr(ctrl,
                   ln="offsetRotateZ",
                   p='offsetRotate',
                   at='double',
                   nn="Offset Rotate Z",
                   keyable=True)
        # Display attribute
        pm.addAttr(ctrl, ln="Display", en="Option:", at="enum")
        pm.setAttr(ctrl + ".Display", e=1, channelBox=True)
        pm.addAttr(ctrl,
                   ln="cameraScale",
                   dv=1,
                   at='double',
                   nn="Camera Scale",
                   keyable=True)
        pm.addAttr(ctrl,
                   en="off:on:",
                   nn="Display Ctrler",
                   ln="displayCtrler",
                   keyable=1,
                   at="enum",
                   dv=1)

        # Connect Attr
        pm.connectAttr(ctrl + ".cameraScale", name + ".sx")
        pm.connectAttr(ctrl + ".cameraScale", name + ".sy")
        pm.connectAttr(ctrl + ".cameraScale", name + ".sz")
        pm.connectAttr(ctrl + ".focalLength", cameraShape + ".focalLength")
        pm.connectAttr(ctrl + ".overscan", cameraShape + ".overscan")
        pm.connectAttr(ctrl + ".tumbleRotateX", rx + ".rx")
        pm.connectAttr(ctrl + ".tumbleRotateY", ry + ".ry")
        pm.connectAttr(ctrl + ".tumbleRotateZ", rz + ".rz")
        pm.connectAttr(ctrl + ".tumbleTranslateZ", tz + ".tz")
        pm.connectAttr(ctrl + ".offsetTranslateX", offsetTx + ".tx")
        pm.connectAttr(ctrl + ".offsetTranslateY", offsetTy + ".ty")
        pm.connectAttr(ctrl + ".offsetTranslateZ", offsetTz + ".tz")
        pm.connectAttr(ctrl + ".offsetRotate", offset + ".r")
        pm.connectAttr(ctrl + ".displayCtrler", dispGrp + ".v")

        # Lock and Hide unused attr
        attrList = [
            "_ry.tx", "_ry.ty", "_ry.tz", "_ry.rx", "_ry.rz", "_ry.sx",
            "_ry.sy", "_ry.sz", "_ry.v", "_rx.tx", "_rx.ty", "_rx.tz",
            "_rx.ry", "_rx.rz", "_rx.sx", "_rx.sy", "_rx.sz", "_rx.v",
            "_rz.tx", "_rz.ty", "_rz.tz", "_rz.rx", "_rz.ry", "_rz.sx",
            "_rz.sy", "_rz.sz", "_rz.v", "_tz.tx", "_tz.ty", "_tz.rx",
            "_tz.ry", "_tz.rz", "_tz.sx", "_tz.sy", "_tz.sz", "_tz.v",
            "_offsetTx.ty", "_offsetTx.tz", "_offsetTx.rx", "_offsetTx.ry",
            "_offsetTx.rz", "_offsetTx.sx", "_offsetTx.sy", "_offsetTx.sz",
            "_offsetTx.v", "_offsetTy.tx", "_offsetTy.tz", "_offsetTy.rx",
            "_offsetTy.ry", "_offsetTy.rz", "_offsetTy.sx", "_offsetTy.sy",
            "_offsetTy.sz", "_offsetTy.v", "_offsetTz.tx", "_offsetTz.ty",
            "_offsetTz.rx", "_offsetTz.ry", "_offsetTz.rz", "_offsetTz.sx",
            "_offsetTz.sy", "_offsetTz.sz", "_offsetTz.v", "_offset.sx",
            "_offset.sy", "_offset.sz", "_offset.v", "_Ctrl.sx", "_Ctrl.sy",
            "_Ctrl.sz"
        ]

        for attr in attrList:
            pm.setAttr(name + attr, lock=True, channelBox=False, keyable=False)
        pm.setAttr(cameraShape + ".orthographic",
                   lock=False,
                   channelBox=False,
                   keyable=True)
        pm.setAttr(cameraShape + ".orthographicWidth",
                   lock=False,
                   channelBox=False,
                   keyable=True)

        # Constraint camera
        const = pm.parentConstraint(constraint,
                                    self.camera,
                                    n=name + '_parentConstraint')
        pm.setAttr(const + ".nds", lock=True, channelBox=False, keyable=False)
        pm.setAttr(const + ".int", lock=True, channelBox=False, keyable=False)
        pm.setAttr(const + ".w0", lock=True, channelBox=False, keyable=False)
        pm.parent(const, ctrl)

        # Add and Connect message
        attr = "camera"
        nodes = [self.camera, ctrl]
        for node in nodes:
            if node.hasAttr(attr):
                node.deleteAttr(attr)
            pm.addAttr(node,
                       ln=attr,
                       multi=1,
                       attributeType="message",
                       indexMatters=False)

        for node in nodes:
            for i in range(0, 2):
                pm.connectAttr('{}.message'.format(nodes[i].name()),
                               '{}.{}[{}]'.format(node.name(), attr, str(i)),
                               f=1)

        # Return
        self.ctrl = ctrl
        uitConvertsion = self.ctrl.outputs(type="unitConversion")
        for uit in uitConvertsion:
            pm.rename(uit.name(), name + '_' + uit.name())

        del self.extNode[:]
        self.extNode.extend([
            constraint, offset, shakeTransform, offsetTz, offsetTy, offsetTx,
            tz, rz, rx, ry, ctrl
        ])
        self.extNode.extend(dispNodeList)
        self.extNode.extend(uitConvertsion)
        pm.select(self.ctrl, r=1)
        return ctrl
Example #11
0
    def refreshArsenalPass(self, progressBarUpdate = None):
        allRenderLayers = pm.RenderLayer.listAllRenderLayers()
        for myRenderLayer in allRenderLayers:
            arsenalPassName = myRenderLayer.name() + '_arsenalPass'
            aresenalConnected = myRenderLayer.listConnections(destination=True, source=False, type='arsenalPass')
            ajustements = pm.editRenderLayerAdjustment(myRenderLayer, query=True, layer=True)
            if len(aresenalConnected) == 0:
                if not pm.objExists(arsenalPassName):
                    pm.createNode('arsenalPass', name=arsenalPassName)
                    pm.lockNode(arsenalPassName, lock=True)
                pm.connectAttr(myRenderLayer.name() + '.message', arsenalPassName + '.passName', force=True)
            elif str(aresenalConnected[0]) != arsenalPassName:
                pm.lockNode(aresenalConnected[0], lock=False)
                pm.rename(aresenalConnected[0], arsenalPassName)
                pm.lockNode(arsenalPassName, lock=True)
                self.passName[myRenderLayer].passName = myRenderLayer.name()
            attributesFastArsenal = ['lightSelectAllNormal',
             'lightSelectAllDiffuse',
             'lightSelectAllRaw',
             'lightSelectAllSpecular',
             'vrayLambert',
             'multimatteMaskName',
             'vrayMaterialID',
             'vrayProxyObjectID']
            attributesFastVray = ['giOn',
             'primaryEngine',
             'secondaryEngine',
             'imap_detailEnhancement',
             'aoOn',
             'globopt_mtl_glossy',
             'globopt_mtl_reflectionRefraction',
             'globopt_mtl_doMaps',
             'globopt_light_doShadows',
             'aaFilterOn',
             'globopt_geom_displacement',
             'cam_mbOn',
             'cam_dofOn',
             'cam_overrideEnvtex',
             'sys_distributed_rendering_on']
            attributesConnectionArsenal = ['passMembers',
             'blackHoleMembers',
             'blackHoleMembersReceiveShd',
             'giMembersGenerate',
             'giMembersReceive',
             'primaryMembersOff',
             'reflectionMembersOff',
             'refractionMembersOff',
             'shadowCastsMembersOff',
             'lightSelectNormalMembers',
             'lightSelectDiffuseMembers',
             'lightSelectRawMembers',
             'lightSelectSpecularMembers']
            self.multiMatteAttributes(myRenderLayer=myRenderLayer, attributesConnectionArsenal=attributesConnectionArsenal)
            for (i, attribut,) in enumerate(attributesFastArsenal):
                if progressBarUpdate is not None:
                    progressBarUpdate(numStep=100, value=i, text='Pass ' + myRenderLayer.name() + ' step 2 : init FastArsenal %v of %m ...')
                self.initAttributes(attribut=attribut, renderPass=myRenderLayer)

            for (i, attribut,) in enumerate(attributesFastVray):
                self.initAttributes(attribut=attribut, renderPass=myRenderLayer, fromRenderGlobal=True)
                if progressBarUpdate is not None:
                    progressBarUpdate(numStep=100, value=i, text='Pass ' + myRenderLayer.name() + ' step 3 : init FastVray %v of %m ...')
                if myRenderLayer.name() != 'defaultRenderLayer':
                    if ajustements is None or 'vraySettings.' + attribut not in ajustements:
                        self.overrideAttribute(renderPass=myRenderLayer, node=arsenalPassName, attribute=attribut, always=True)
                    else:
                        self.overrideAttribute(renderPass=myRenderLayer, node=arsenalPassName, attribute=attribut, always=False)

            for (i, attribut,) in enumerate(attributesConnectionArsenal):
                if progressBarUpdate is not None:
                    progressBarUpdate(numStep=100, value=i, text='Pass ' + myRenderLayer.name() + ' step 4 : init FastConnection %v of %m ...')
                self.initAttributes(attribut=attribut, renderPass=myRenderLayer, connection=True)

            if progressBarUpdate is not None:
                progressBarUpdate(numStep=100, value=100, text='Done...')
Example #12
0
    def importPass(self, paths = list()):
        if not paths:
            return 
        for path in paths:
            splited = path.split('.')
            splited.pop(-1)
            arpassinfo = '.'.join(splited) + '.arpassinfo'
            strFile = self.readTxtFile(path=arpassinfo)
            objectsNotFound = []
            if strFile:
                dico = eval(strFile)
                if not pm.objExists(dico['layer']['name']):
                    renderLayer = pm.createRenderLayer(name=dico['layer']['name'], g=dico['layer']['global'])
                else:
                    renderLayer = pm.PyNode(dico['layer']['name'])
                arsenalPassName = renderLayer.name() + '_arsenalPass'
                if pm.objExists(arsenalPassName):
                    pm.lockNode(arsenalPassName, lock=False)
                    pm.delete(arsenalPassName)
                pm.importFile(path, defaultNamespace=True)
                if renderLayer.name() != 'defaultRenderLayer':
                    for member in dico['layer']['members']:
                        listMembers = dico['layer']['members'][member]
                        if pm.objExists(listMembers[0]):
                            renderLayer.addMembers(listMembers[0])
                        elif pm.objExists(listMembers[1]):
                            if len(pm.ls(listMembers[1])) == 1:
                                renderLayer.addMembers(listMembers[1])
                        elif pm.objExists(listMembers[2]):
                            if len(pm.ls(listMembers[2])) == 1:
                                renderLayer.addMembers(listMembers[2])
                        elif pm.objExists(listMembers[3]):
                            if len(pm.ls(listMembers[3])) == 1:
                                renderLayer.addMembers(listMembers[3])
                        else:
                            objectsNotFound.append(listMembers[0])

                for member in dico['connections']:
                    dicoMembers = dico['connections'][member]
                    dsts = dicoMembers['destination']
                    listMembers = dicoMembers['sources']
                    if pm.objExists(listMembers[0]):
                        for dst in dsts:
                            pm.connectAttr(listMembers[0], dst, f=True)

                    elif pm.objExists(listMembers[1]):
                        if len(pm.ls(listMembers[1])) == 1:
                            for dst in dsts:
                                pm.connectAttr(listMembers[1], dst, f=True)

                    elif pm.objExists(listMembers[2]):
                        if len(pm.ls(listMembers[2])) == 1:
                            for dst in dsts:
                                pm.connectAttr(listMembers[2], dst, f=True)

                    elif pm.objExists(listMembers[3]):
                        if len(pm.ls(listMembers[3])) == 1:
                            for dst in dsts:
                                pm.connectAttr(listMembers[3], dst, f=True)


            else:
                OpenMaya.MGlobal.displayError('[Arsenal] Can not open ' + arpassinfo)
                return 
            if objectsNotFound:
                OpenMaya.MGlobal.displayError('[Arsenal] Object(s) not found in the scene : \n' + '\n'.join(objectsNotFound))
                return 
            self.refreshArsenalPass()