Exemplo n.º 1
0
 def Vray_smooth(self, checked):
     selected_objects = cmds.ls(sl=True)
     objects_to_run = []
     for object in selected_objects:
         if 'Shape' in object:
             if object not in objects_to_run:
                 objects_to_run.append(object)
         else:
             object_children = cmds.listRelatives(children=True) or []
             for child in object_children:
                 if 'Shape' in child:
                     if child not in objects_to_run:
                         objects_to_run.append(child)
     for object in objects_to_run:
         node_type = cmds.nodeType(object)
         if node_type == 'mesh':
             if checked == 1:
                 cmds.vray("addAttributesFromGroup", object,
                           "vray_subdivision", 1)
             if checked == 0:
                 cmds.vray("addAttributesFromGroup", object,
                           "vray_subdivision", 0)
     smoothing_exists = 0
     for object in objects_to_run:
         node_type = cmds.nodeType(object)
         if node_type == 'mesh':
             smoothing_exists = cmds.objExists(object + '.vraySubdivUVs')
         print 'smoothing_exists = ', smoothing_exists
         if smoothing_exists == 0:
             self.button_Vray_smooth.setChecked(False)
         if smoothing_exists == 1:
             self.button_Vray_smooth.setChecked(True)
def addVrayObjectIds(shapes=None):
    """ Add a vray_objectID attribute to selected meshes

    :param shapes: Shapes to apply the attribute to. If shapes is None it will get
                   the shapes related to the current selection.
    """
    if shapes is None:
        shapes = mc.ls(sl=1, s=1, dag=1, lf=1, o=1, long=True)

    if shapes:
        # Can only add objectIds to mesh, nurbsSurface so lets filter it
        shapes = mc.ls(shapes, type=("mesh", "nurbsSurface"))

    if shapes:
        result = mc.promptDialog(title='Object ID value',
                                 message='Object ID:',
                                 button=['OK', 'Cancel'],
                                 defaultButton='OK',
                                 cancelButton='Cancel',
                                 dismissString='Cancel')

        if result == 'OK':
            value = int(mc.promptDialog(query=True, text=True))

            for shape in shapes:
                mc.vray("addAttributesFromGroup", shape, "vray_objectID", 1)
                mc.setAttr("{0}.{1}".format(shape, 'vrayObjectID'), value)
Exemplo n.º 3
0
 def create_light_blocker_method(self):
     print 'create_light_blocker'
     plane = cmds.polyPlane( sx=10, sy=15, w=15, h=20)
     plane_group_exists = cmds.objExists('light_blocker_group')
     if plane_group_exists == 0:
         cmds.group( em=True, name='light_blocker_group')
         cmds.parent(plane,'light_blocker_group')
     if plane_group_exists == 1:
         cmds.parent(plane,'light_blocker_group')
     light_blocker_shader = cmds.shadingNode("VRayMtl", asShader=True, name = 'light_blocker')
     shading_group = cmds.sets(renderable=True,noSurfaceShader=True,empty=True,name = light_blocker_shader + '_SG')
     cmds.connectAttr(light_blocker_shader + '.outColor',shading_group + '.surfaceShader')
     cmds.setAttr(light_blocker_shader + '.color', 0,0,0,type = 'double3')
     cmds.select(clear = True)
     plane = plane[0]
     cmds.select(plane)
     cmds.hyperShade(assign=light_blocker_shader)
     cmds.select(plane)
     vray_props_exists = cmds.objExists('light_blocker_props')
     if vray_props_exists == 0:
         props_node = cmds.vray("objectProperties", "add_single")
         cmds.rename(props_node,'light_blocker_props')
     if vray_props_exists == 1:
         cmds.vray("objectProperties", "assign_existing", "VRayObjectProperties", "light_blocker_props")
     cmds.setAttr("light_blocker_props.receiveShadows",0)
     cmds.setAttr("light_blocker_props.shadowVisibility",0)
     cmds.setAttr("light_blocker_props.refractionVisibility",0)
     cmds.setAttr("light_blocker_props.reflectionVisibility",0)
     cmds.setAttr("light_blocker_props.primaryVisibility",0)
def addVrayObjectIds(shapes=None):
    """ Add a vray_objectID attribute to selected meshes

    :param shapes: Shapes to apply the attribute to. If shapes is None it will get
                   the shapes related to the current selection.
    """
    if shapes is None:
        shapes = mc.ls(sl=1, s=1, dag=1, lf=1, o=1, long=True)

    if shapes:
        # Can only add objectIds to mesh, nurbsSurface so lets filter it
        shapes = mc.ls(shapes, type=("mesh", "nurbsSurface"))

    if shapes:
        result = mc.promptDialog(
            title="Object ID value",
            message="Object ID:",
            button=["OK", "Cancel"],
            defaultButton="OK",
            cancelButton="Cancel",
            dismissString="Cancel",
        )

        if result == "OK":
            value = int(mc.promptDialog(query=True, text=True))

            for shape in shapes:
                mc.vray("addAttributesFromGroup", shape, "vray_objectID", 1)
                mc.setAttr("{0}.{1}".format(shape, "vrayObjectID"), value)
Exemplo n.º 5
0
def addSubdivisions(ui, texture):
    """
    Add render subdivisions of a certain type
    :param material: The material used to find which shapes to subdivide
    :return: None
    """

    material = texture.textureSet

    # Get values from interface
    maxSubdivs = int(ui.maxSubdivIterVray.text())
    edgeLength = float(ui.subdivIterVray.text())

    # Find the shapes connected to the material
    shader = mc.listConnections(material + '.outColor', d=True)[0]
    meshes = mc.listConnections(shader, type='mesh')
    shapes = mc.listRelatives(meshes, s=True)

    if shapes:

        # For all shapes add the render subdivisions
        for mesh in shapes:
            mc.select(mesh, replace=True)
            mc.vray("addAttributesFromGroup", mesh, "vray_subdivision", 1)
            mc.vray("addAttributesFromGroup", mesh, "vray_subquality", 1)
            mc.setAttr(mesh + '.vrayOverrideGlobalSubQual', 1)
            mc.setAttr(mesh + '.vrayMaxSubdivs', maxSubdivs)
            mc.setAttr(mesh + '.vrayEdgeLength', edgeLength)
            mc.select(mesh, d=True)
Exemplo n.º 6
0
def createMultiDispNode(*args):
    a = cmds.ls(sl=True)
    numOfSel = len(a)
    if (numOfSel == 0):
        print "No object selected, can not create any Displacement node"
        print "Please select objects that you want"
    else:
        cmds.vray("objectProperties", "add_multiple", "VRayDisplacement")
Exemplo n.º 7
0
    def unset(self, nodes):
        if isinstance(nodes, string_types):
            nodes = [nodes]

        for node in nodes:
            if not self._compatible(node):
                continue

            cmds.vray("addAttributesFromGroup", node, self._name, 0)
Exemplo n.º 8
0
def createSingleDispNode(*args):
    curSel = cmds.ls(sl=True)
    if curSel == []:
        print "No object selected, can not create single Displacement node"
        print "Please select an object"
    else:
        cmds.vray("objectProperties", "add_single", "VRayDisplacement")
        for i in curSel:
            objName = (str(curSel[i]) + '_Displacement')
            cmds.rename('vrayDisplacement', objName)
def assignRandomColorToID():
    materialSelection = cmds.ls(mat=True)
    for material in materialSelection:
        cmds.vray("addAttributesFromGroup", material, "vray_material_id", 1)
        randomColour = [random.random() for i in range(3)]
        cmds.setAttr('%s.vrayColorId' % material,
                     randomColour[0],
                     randomColour[1],
                     randomColour[2],
                     type='double3')
Exemplo n.º 10
0
def addVrayOpenSubdivAttr():
    '''add Vray OpenSubdiv attr to enable smooth mesh render'''
    sel = pm.selected()
    if not sel:
        return
    for o in sel:
        if str(cm.getAttr('defaultRenderGlobals.ren')) == 'vray':
            obShape = pm.listRelatives(o, shapes=True)[0]
            cm.vray('addAttributesFromGroup', obShape, "vray_opensubdiv", 1)
            pm.setAttr(obShape + ".vrayOsdPreserveMapBorders", 2)
Exemplo n.º 11
0
    def doIt(self, argList):

        st = cmds.ls(sl=1)
        cmds.createRenderLayer(st)
        cmds.vray("objectProperties", "add_single")
        cmds.editRenderLayerGlobals(currentRenderLayer="renderLayer")
        cmds.setAttr("vrayobjectproperties.primaryVisibility", 0)
        cmds.editRenderLayerAdjustment(
            "vrayobjectproperties.primaryVisibility")
        cmds.setAttr("vrayobjectproperties.primaryVisibility", 1)
        cmds.rename("renderLayer", str(st))
        cmds.rename("vrayobjectproperties", str(st))
Exemplo n.º 12
0
    def set(self, nodes):
        if isinstance(nodes, string_types):
            nodes = [nodes]

        for node in nodes:
            if not self._compatible(node):
                continue

            cmds.vray("addAttributesFromGroup", node, self._name, 1)

            for attr in self._vray_attrs():
                path = node + "." + attr
                value = getattr(self, attr)
                if value is not None:
                    self._cmds_setAttr(path, value)
def addVraySubdivisionAttribute(shapes=None):
    """ Add a v-ray subdivision attribute to selected meshes

    :param shapes: Shapes to apply the attribute to. If shapes is None it will get
                   the shapes related to the current selection.
    """

    if shapes is None:
        shapes = mc.ls(sl=1, s=1, dag=1, lf=1, o=1, long=True)

    if shapes:
        # Only apply to mesh or nurbsSurface (other shapes can't contain the vray_subdivision attribute)
        shapes = mc.ls(shapes, type=("mesh", "nurbsSurface"))

    if shapes:
        for shape in shapes:
            mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 1)
    else:
        raise RuntimeError("No shapes found to apply the vray_subdivision attribute group to.")
def addVrayMaterialIds(materials=None):
    """ Add a vray_material_id attribute to selected materials (and related materials from objects)

    :param materials: Materials to apply the attribute to. If materials is None it will get
                      the materials related to the current selection.
    """
    if materials is None:
        # Get selected materials
        materials = mc.ls(sl=1, mat=1)

        # Get materials related to selection (material from object)
        # And add those materials to the material list we already have
        sel = mc.ls(sl=1)
        if sel:
            sel_history = mc.listHistory(sel, f=1)
            if sel_history:
                sel_connections = mc.listConnections(sel_history)
                if sel_connections:
                    connected_materials = mc.ls(sel_connections, mat=True)
                    if connected_materials:
                        materials = set(materials)
                        materials.update(connected_materials)
                        materials = list(materials)
    else:
        # filter input to materials only
        materials = mc.ls(materials, mat=1)

    if not materials:
        raise RuntimeError("No materials found")

    if materials:
        result = mc.promptDialog(title='Material ID value',
                                 message='Material ID:',
                                 button=['OK', 'Cancel'],
                                 defaultButton='OK',
                                 cancelButton='Cancel',
                                 dismissString='Cancel')

        if result == 'OK':
            value = int(mc.promptDialog(query=True, text=True))
            for mat in materials:
                mc.vray("addAttributesFromGroup", mat, "vray_material_id", 1)
                mc.setAttr("{0}.{1}".format(mat, 'vrayMaterialId'), value)
def addVrayMaterialIds(materials=None):
    """ Add a vray_material_id attribute to selected materials (and related materials from objects)

    :param materials: Materials to apply the attribute to. If materials is None it will get
                      the materials related to the current selection.
    """
    if materials is None:
        # Get selected materials
        materials = mc.ls(sl=1, mat=1)

        # Get materials related to selection (material from object)
        # And add those materials to the material list we already have
        sel = mc.ls(sl=1)
        if sel:
            sel_history = mc.listHistory(sel,f=1)
            if sel_history:
                sel_connections = mc.listConnections(sel_history)
                if sel_connections:
                    connected_materials = mc.ls(sel_connections, mat=True)
                    if connected_materials:
                        materials = set(materials)
                        materials.update(connected_materials)
                        materials = list(materials)
    else:
        # filter input to materials only
        materials = mc.ls(materials, mat=1)

    if not materials:
        raise RuntimeError("No materials found")

    if materials:
        result = mc.promptDialog(title='Material ID value',
                                    message='Material ID:',
                                    button=['OK', 'Cancel'],
                                    defaultButton='OK',
                                    cancelButton='Cancel',
                                    dismissString='Cancel')

        if result == 'OK':
            value = int(mc.promptDialog(query=True, text=True))
            for mat in materials:
                mc.vray("addAttributesFromGroup", mat, "vray_material_id", 1)
                mc.setAttr("{0}.{1}".format(mat, 'vrayMaterialId'), value)
def addVraySubdivisionAttribute(shapes=None):
    """ Add a v-ray subdivision attribute to selected meshes

    :param shapes: Shapes to apply the attribute to. If shapes is None it will get
                   the shapes related to the current selection.
    """

    if shapes is None:
        shapes = mc.ls(sl=1, s=1, dag=1, lf=1, o=1, long=True)

    if shapes:
        # Only apply to mesh or nurbsSurface (other shapes can't contain the vray_subdivision attribute)
        shapes = mc.ls(shapes, type=("mesh", "nurbsSurface"))

    if shapes:
        for shape in shapes:
            mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 1)
    else:
        raise RuntimeError(
            "No shapes found to apply the vray_subdivision attribute group to."
        )
Exemplo n.º 17
0
    def addVraySubdivisions(self, material):

        # Get values from interface
        maxSubdivs = int(self.maxSubdivIterVray.text())
        edgeLength = float(self.subdivIterVray.text())

        # Find the shapes connected to the material
        shader = mc.listConnections(material + '.outColor', d=True)[0]
        meshes = mc.listConnections(shader, type='mesh')
        shapes = mc.listRelatives(meshes, s=True)

        if shapes:

            # For all shapes add the render subdivisions
            for mesh in shapes:

                mc.select(mesh, replace=True)
                mc.vray("addAttributesFromGroup", mesh, "vray_subdivision", 1)
                mc.vray("addAttributesFromGroup", mesh, "vray_subquality", 1)
                mc.setAttr(mesh + '.vrayOverrideGlobalSubQual', 1)
                mc.setAttr(mesh + '.vrayMaxSubdivs', maxSubdivs)
                mc.setAttr(mesh + '.vrayEdgeLength', edgeLength)
                mc.select(mesh, d=True)
Exemplo n.º 18
0
def renderButtonPush(*args):
    xTile = cmds.intSliderGrp("intFieldName1", query=True, value=True)
    yTile = cmds.intSliderGrp("intFieldName2", query=True, value=True)
    xOffset = cmds.intSliderGrp("intFieldName3", query=True, value=True)
    yOffset = cmds.intSliderGrp("intFieldName4", query=True, value=True)

    cancel = 0

    x = xOffset
    if (xTile - 1) < xOffset:
        x = xTile - 1
    y = yOffset
    if (yTile - 1) < yOffset:
        y = yTile - 1

    outWidth = float(cmds.getAttr("defaultResolution.width"))
    outHeight = float(cmds.getAttr("defaultResolution.height"))
    xTileLenght = outWidth / xTile
    yTileLenght = outHeight / yTile
    print x, y
    for x in range(x, xTile):
        if cancel == 1:
            print "Canceling X"
            break
        for y in range(y, yTile):
            if cancel == 1:
                print "Canceling Y"
                break
            print "Starting [", x, "] [", y, "] ", datetime.datetime.now()
            cmds.vray("vfbControl", "-setregion", (int(x * xTileLenght)),
                      (int(y * yTileLenght)), (int((x + 1) * xTileLenght)),
                      (int((y + 1) * yTileLenght)))
            cmds.vrend()
            y += 1
        x += 1
        y = 0
Exemplo n.º 19
0
    def vrayMeshSetup(self, mesh):

        shape = cmds.listRelatives(mesh, shapes=True)

        for shapes in shape:
            cmds.vray("addAttributesFromGroup", shapes, "vray_subdivision", 1)
            cmds.vray("addAttributesFromGroup", shapes, "vray_subquality", 1)
            cmds.vray("addAttributesFromGroup", shapes, "vray_displacement", 1)
            cmds.setAttr(shapes + ".vraySubdivEnable", 1)
            cmds.setAttr(shapes + ".vraySubdivUVs", 0)
            cmds.setAttr(shapes + ".vrayEdgeLength", 4)
            cmds.setAttr(shapes + ".vrayDisplacementType", 1)
            cmds.setAttr(shapes + ".vrayDisplacementKeepContinuity", 1)
            cmds.setAttr(shapes + ".vray2dDisplacementFilterTexture", 0)
            cmds.setAttr(shapes + ".vrayDisplacementUseBounds", 0)
Exemplo n.º 20
0
def openVrayVFB(*args):
    cmds.loadPlugin("vrayformaya", quiet=True)
    cmds.pluginInfo('vrayformaya', edit=True, autoload=True)
    cmds.setAttr("defaultRenderGlobals.currentRenderer", "vray", type="string")
    cmds.vray("showVFB")
Exemplo n.º 21
0
def createVrayShadingNetwork(materialName,texturesUsing):
	#get current version of maya
	version = mc.about(version = 1)
	version = int(version)
	#if the version is newer than 2016 ,we can use the colormanagement directly
	if version >= 2016:
		#create vray mtl
		vrayMtl = mc.shadingNode('VRayMtl',asShader = 1,n = materialName)
		mc.setAttr(vrayMtl + '.bumpMapType',1)
		try:
			mc.setAttr(vrayMtl + '.brdfType' , 3)
		except:
			mc.warning('当前版本vray没有ggx_brdf,效果可能不好,请注意')

		#create place2dtexture
		UVnode = mc.shadingNode('place2dTexture',au =1)
		#connect textures to material
		for textureUsing in texturesUsing.keys():

			if 'Diffuse' in textureUsing:
				mc.connectAttr(texturesUsing[textureUsing] + '.outColor',vrayMtl + '.diffuseColor')
				mc.setAttr(texturesUsing[textureUsing] + '.colorSpace','sRGB',type = 'string')
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'Reflection' in textureUsing:
				mc.connectAttr(texturesUsing[textureUsing] + '.outColor',vrayMtl + '.reflectionColor')
				mc.setAttr(texturesUsing[textureUsing] + '.colorSpace','sRGB',type = 'string')
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'Glossiness' in textureUsing:
				mc.connectAttr(texturesUsing[textureUsing] + '.outAlpha',vrayMtl + '.reflectionGlossiness')
				mc.setAttr(texturesUsing[textureUsing] + '.colorSpace','Raw',type = 'string')
				mc.setAttr(texturesUsing[textureUsing] + '.alphaIsLuminance', 1)
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'ior' in textureUsing:
				mc.setAttr(vrayMtl + '.lockFresnelIORToRefractionIOR',0)
				mc.connectAttr(texturesUsing[textureUsing] + '.outAlpha',vrayMtl + '.fresnelIOR')
				mc.setAttr(texturesUsing[textureUsing] + '.colorSpace','Raw',type = 'string')
				mc.setAttr(texturesUsing[textureUsing] + '.alphaIsLuminance', 1)
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'Normal' in textureUsing:
				mc.connectAttr(texturesUsing[textureUsing] + '.outColor',vrayMtl + '.bumpMap')
				mc.setAttr(texturesUsing[textureUsing] + '.colorSpace','Raw',type = 'string')
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			
	else:
		#create vray mtl
		vrayMtl = mc.shadingNode('VRayMtl',asShader = 1,n = materialName)
		mc.setAttr(vrayMtl + '.bumpMapType',1)
		try:
			mc.setAttr(vrayMtl + '.brdfType' , 3)
		except:
			mc.warning('当前版本vray没有ggx_brdf,效果可能不好,请注意')
		#create place2dtexture
		UVnode = mc.shadingNode('place2dTexture',au =1)
		#connect textures to material
		for textureUsing in texturesUsing.keys():
			if 'Diffuse' in textureUsing:
				mc.connectAttr(texturesUsing[textureUsing] + '.outColor',vrayMtl + '.diffuseColor')
				mc.vray('addAttributesFromGroup',texturesUsing[textureUsing],'vray_file_gamma' ,1)
				mc.setAttr(texturesUsing[textureUsing] + '.vrayFileColorSpace',2)
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'Reflection' in textureUsing:
				mc.connectAttr(texturesUsing[textureUsing] + '.outColor',vrayMtl + '.reflectionColor')
				mc.vray('addAttributesFromGroup',texturesUsing[textureUsing],'vray_file_gamma' ,1)
				mc.setAttr(texturesUsing[textureUsing] + '.vrayFileColorSpace',2)
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'Glossiness' in textureUsing:
				'''
				gammaCorret = mc.shadingNode('gammaCorrect',au = 1)
				mc.setAttr(gammaCorret + '.gammaX',2.2)
				mc.setAttr(gammaCorret + '.gammaY',2.2)
				mc.setAttr(gammaCorret + '.gammaZ',2.2)
				'''
				mc.vray('addAttributesFromGroup',texturesUsing[textureUsing],'vray_file_gamma' ,1)
				mc.setAttr(texturesUsing[textureUsing] + '.vrayFileColorSpace',0)
				mc.connectAttr(texturesUsing[textureUsing] + '.outAlpha',vrayMtl + '.reflectionGlossiness')
				mc.setAttr(texturesUsing[textureUsing] + '.alphaIsLuminance', 1)
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])

			elif 'ior' in textureUsing:
				mc.setAttr(vrayMtl + '.lockFresnelIORToRefractionIOR',0)
				'''
				gammaCorret = mc.shadingNode('gammaCorrect',au = 1)
				mc.setAttr(gammaCorret + '.gammaX',2.2)
				mc.setAttr(gammaCorret + '.gammaY',2.2)
				mc.setAttr(gammaCorret + '.gammaZ',2.2)
				'''
				mc.vray('addAttributesFromGroup',texturesUsing[textureUsing],'vray_file_gamma' ,1)
				mc.setAttr(texturesUsing[textureUsing] + '.vrayFileColorSpace',0)
				mc.connectAttr(texturesUsing[textureUsing] + '.outAlpha',vrayMtl + '.fresnelIOR')
				mc.setAttr(texturesUsing[textureUsing] + '.alphaIsLuminance', 1)
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
			elif 'Normal' in textureUsing:
				'''
				gammaCorret = mc.shadingNode('gammaCorrect',au = 1)
				mc.setAttr(gammaCorret + '.gammaX',2.2)
				mc.setAttr(gammaCorret + '.gammaY',2.2)
				mc.setAttr(gammaCorret + '.gammaZ',2.2)
				'''
				mc.connectAttr(texturesUsing[textureUsing] + '.outColor',vrayMtl + '.bumpMap')
				connectUVNodeToTextureNode(UVnode,texturesUsing[textureUsing])
Exemplo n.º 22
0
    def texture_replace_no_gui(self):
        #number_of_textures = 10
        textures_to_swap = []
        viable_node_types = ['file']
        textures = cmds.ls(selection = True)
        for texture in textures:
            object_type = cmds.nodeType(texture)
            if object_type in viable_node_types:
                textures_to_swap.append(texture)
        print 'textures_to_swap = ',textures_to_swap
        number_of_selected_textures = len(textures_to_swap)
        print 'number_of_selected_textures = ',number_of_selected_textures
        if number_of_selected_textures > 1:
            i = 0
            while i < number_of_selected_textures:
                #splitting out the old and new texture names
                new_fileTex = textures_to_swap[i]
                old_fileTex = textures_to_swap[i+1]
                key_words = ['alpha','substrate','matte','mettalic']
                vray_gamma_node_exists_old = cmds.attributeQuery('vrayFileGammaValue',node = old_fileTex,exists = True)
                vray_gamma_node_exists_new = cmds.attributeQuery('vrayFileGammaValue',node = new_fileTex,exists = True)
                if vray_gamma_node_exists_new == 0:
                  if vray_gamma_node_exists_old == 1:
                      file_path_name = cmds.getAttr(new_fileTex + '.fileTextureName')
                      for key_word in key_words:
                          if key_word not in file_path_name:
                              cmds.vray("addAttributesFromGroup", new_fileTex, "vray_file_gamma", 1)
                print " "
                print new_fileTex + " swapping with " + old_fileTex
                print "---"
                #starting the replace

                #transferAttr settings for new texture
                old_file_texture_attr_dic = {}
                new_file_texture_attr_dic = {}
                old_file_texture_attrs = cmds.listAttr(old_fileTex,k = True)
                attrAppend = ["filter","filterOffset","filterType"]
                attrRemove = ["aiUserOptions","defaultColorMgtGlobals.cmEnabled","defaultColorMgtGlobals.configFileEnabled","defaultColorMgtGlobals.configFilePath","workingSpaceName","filter","filterOffset","filterType","frameOffset","oldFileAttr_mod"]
                for attr in attrAppend:
                    old_file_texture_attrs.append(attr)
                for attr in attrRemove:
                    if attr in old_file_texture_attrs:
                        old_file_texture_attrs.remove(attr)
                #print 'old_file_texture_attrs = ',old_file_texture_attrs
                new_file_texture_attrs = cmds.listAttr(new_fileTex,k = True)
                for attr in attrAppend:
                    new_file_texture_attrs.append(attr)
                for attr in attrRemove:
                    if attr in new_file_texture_attrs:
                        new_file_texture_attrs.remove(attr)
                for new_fileTexAttr in new_file_texture_attrs:
                    new_fileTexAttr_Value = cmds.getAttr(new_fileTex + "." + new_fileTexAttr)
                    new_file_texture_attr_dic[new_fileTexAttr] = new_fileTexAttr_Value
                #print 'old_file_texture_attrs = ',old_file_texture_attrs
                connected_oldFileAttrs = ['exposure','defaultColorR','defaultColorG','defaultColorB','colorGainR','colorGainG','colorGainB','colorOffsetR','colorOffsetG','colorOffsetB','alphaGain','alphaOffset']
                connected_oldFileAttrs_connected = []
                RGB_attrs = ['defaultColorR','defaultColorG','defaultColorB','colorGainR','colorGainG','colorGainB','colorOffsetR','colorOffsetG','colorOffsetB']
                oldFileAttr_RGB_list = []
                oldFileAttr_connections = []
                for oldFileAttr in old_file_texture_attrs:
                    #print 'old_fileTex = ',old_fileTex
                    #print 'oldFileAttr = ',oldFileAttr
                    if oldFileAttr in connected_oldFileAttrs:
                        if oldFileAttr in RGB_attrs:
                            oldFileAttr = oldFileAttr[:-1]
                        #print oldFileAttr
                        #print '(*old_fileTex + "." + oldFileAttr) = ',(old_fileTex + "." + oldFileAttr)
                        oldFileAttr_connections = cmds.listConnections((old_fileTex + "." + oldFileAttr)) or []
                    #print '*oldFileAttr_connections = ',oldFileAttr_connections
                    number_oldFileAttr_connections = len(oldFileAttr_connections)
                    #print '*number_oldFileAttr_connections = ',number_oldFileAttr_connections
                    if number_oldFileAttr_connections == 0:
                        oldFileAttrValue = cmds.getAttr(old_fileTex + "." + oldFileAttr)
                        old_file_texture_attr_dic[oldFileAttr] = oldFileAttrValue
                    if number_oldFileAttr_connections > 0:
                        oldFileAttr_RGB_list.append(oldFileAttr)
                        #print '* oldFileAttr_RGB_list = ',oldFileAttr_RGB_list
                #print 'connected_oldFileAttrs = ',connected_oldFileAttrs
                #print 'oldFileAttr_RGB_list = ',oldFileAttr_RGB_list
                source_connections_modified = []
                destination_connections_modified = []
                #grab the old texure incoming connections
                connections_source_old = cmds.listConnections(old_fileTex, plugs = True, connections = True, destination = False)or []
                #grab the old texure outgoing connections
                connections_destination_old = cmds.listConnections(old_fileTex, connections = True, plugs = True, source = False) or []
                #how many incoming connections and outgoing connections are there
                connection_source_size = len(connections_source_old)
                connection_destination_size = len(connections_destination_old)
                #if the incoming connections source size is more than 0, replace the old texture in the incoming connections list
                if connection_source_size != 0:
                    for connection in connections_source_old:
                        connection_modified = connection.replace(old_fileTex,new_fileTex)
                        source_connections_modified.append(connection_modified)
                #if the outgoing connections size is more than 0, replace the old texture in the outgoing connections list
                if connection_destination_size != 0:
                    for connection in connections_destination_old:
                        connection_modified = connection.replace(old_fileTex,new_fileTex)
                        destination_connections_modified.append(connection_modified)
                source_connections_modified_size = len(source_connections_modified)
                #connect the old source node to the new texture
                inIter = 0
                outIter = 1
                while outIter < source_connections_modified_size:
                    if connections_source_old[outIter] != "defaultColorMgtGlobals.cmEnabled" and connections_source_old[outIter] != "defaultColorMgtGlobals.configFileEnabled" and connections_source_old[outIter] != "defaultColorMgtGlobals.configFilePath" and connections_source_old[outIter] != "defaultColorMgtGlobals.workingSpaceName":
                        print "connecting " + connections_source_old[outIter] + " to "  + source_connections_modified[inIter]
                        cmds.connectAttr(connections_source_old[outIter],source_connections_modified[inIter],force = True)
                    outIter = outIter + 2
                    inIter = inIter + 2
                destination_connections_modified_size = len(destination_connections_modified)
                #connect the new texture to the old destination node
                inIter = 0
                outIter = 1
                while outIter < destination_connections_modified_size:
                    if ".message" not in destination_connections_modified[inIter]:
                        print "connecting " + destination_connections_modified[inIter] + " to " + connections_destination_old[outIter]
                        cmds.connectAttr(destination_connections_modified[inIter],connections_destination_old[outIter], force = True)
                    outIter = outIter + 2
                    inIter = inIter + 2
                print 'new_file_texture_attr_dic = ',new_file_texture_attr_dic
                for new_fileTexAttr in new_file_texture_attrs:
                    #print ' '
                    #print 'new_fileTexAttr = ',new_fileTexAttr
                    #print 'oldFileAttr_RGB_list = ',oldFileAttr_RGB_list
                    if new_fileTexAttr in RGB_attrs:
                        new_fileTexAttr_mod = new_fileTexAttr[:-1]
                    else:
                        new_fileTexAttr_mod = new_fileTexAttr
                    #print 'new_fileTexAttr_mod = ',new_fileTexAttr_mod
                    if new_fileTexAttr_mod not in oldFileAttr_RGB_list:
                        #print 'new_file_texture_attr_dic = ',new_file_texture_attr_dic
                        #if new_fileTexAttr in new_file_texture_attr_dic:
                        attrExists = cmds.attributeQuery(new_fileTexAttr,node = new_fileTex,exists = True)
                        if attrExists == 1:
                          #print 'unlocking, new_fileTex + "." + new_fileTexAttr = ',new_fileTex + "." + new_fileTexAttr
                          cmds.setAttr(new_fileTex + "." + new_fileTexAttr, lock=0 )
                          #print 'new_fileTexAttr = ',new_fileTexAttr
                          #print 'old_file_texture_attr_dic = ',old_file_texture_attr_dic
                          print "setting " + str(new_fileTex) + "." + str(new_fileTexAttr) + " to " + str(old_file_texture_attr_dic[new_fileTexAttr_mod])
                          attr_value = old_file_texture_attr_dic[new_fileTexAttr_mod]
                          #print 'attr_value = ',attr_value
                          if 'defaultColor' in new_fileTexAttr or 'colorGain' in new_fileTexAttr or 'colorOffset' in new_fileTexAttr:
                              #print 'found RGB list attr'
                              if 'R' == new_fileTexAttr[-1]:
                                  #print 'found R'
                                  attr_value = attr_value[0]
                                  #print 'attr_value = ',attr_value
                                  attr_value = attr_value[0]
                                  #print 'attr_value = ',attr_value
                              if 'G' == new_fileTexAttr[-1]:
                                  #print 'found G'
                                  attr_value = attr_value[0]
                                  #print 'attr_value = ',attr_value
                                  attr_value = attr_value[1]
                                  #print 'attr_value = ',attr_value
                              if 'B' == new_fileTexAttr[-1]:
                                  #print 'found B'
                                  attr_value = attr_value[0]
                                  #print 'attr_value = ',attr_value
                                  attr_value = attr_value[2]
                                  #print 'attr_value = ',attr_value
                          #print 'attr_value = ',attr_value
                          cmds.setAttr(new_fileTex + "." + new_fileTexAttr,attr_value)
                    else:
                        print '!! found a connection for ' + new_fileTexAttr
                i = i + 2
            cmds.select(clear = True)
            new_fileTex = ''
            old_fileTex = ''
# Play around with mc.ls and mc.listRelatives until you feel somewhat familiar.

# To be continued. :)
# Now you should know the difference between transforms and their children shapes.
# Let's get all transform nodes that end with "*_SMOOTH" and add a subdivision attribute to it's children mesh shapes.

import maya.cmds as mc
# Get all transform nodes that end with _SMOOTH
nodes = mc.ls("*_SMOOTH", type="transform")
if nodes:
    # Get the children shapes of type mesh
    meshes = mc.listRelatives(nodes, children=True, shapes=True, type="mesh")
    # If we found children meshes, then for every mesh shape node add the vray_subdivision attribute.
    if meshes:
        for mesh in meshes:
            mc.vray("addAttributesFromGroup", "vray_subdivision", mesh, 1)

# We can do something similar for all nurbsCurves that we want to make renderable. If we have given a specific suffix
# to the nodes we can easily address them.
# So I've discussed with the team and we went for "_EXTREMELY_RENDERABLE_CURVE" as a suffix on the transform node of
# the nurbsCurves.

# Ah yeah, let's get those transforms!
import maya.cmds as mc
nodes = mc.ls("*_EXTREMELY_RENDERABLE_CURVE", type="transform")
print nodes

# So we play around and test if it is giving us the nodes. Did you try it?
# Then go on and get the children nurbsCurve shape nodes.

if nodes:
Exemplo n.º 24
0
def objectProperties(cmd, type=None, nodes=None, name=None):
    """ Adds/removes objectProperties to/from input nodes.

    This is currently an experimental implementation, behaviour and naming of functions/keywords may change.
    Even though our focus is to stay as backwards compatible as possible we can't ensure this in the long run
    for experimental implementations.

    :param cmd: The string command to run for the objectProperties.
                Possible values are: "add_single", "add_multiple", "remove", "remove_sub"
    :type  cmd: str

    :param type: The objectProperties type to operate on. If None provided the default "VRayObjectProperties" is used.
    :type  type: str

    :param nodes: The nodes to operate on. If None provided the current selection is used.
    :type  nodes: list

    :param name: Rename the created nodes to `name`. If None provided nodes will get default name.
    :type  name: str

    :return: If objectProperties nodes are created it returns the newly created nodes. If no nodes have been created,
             but there are related objectProperties nodes that have been deletd those will be returned.

                e.g.

                For "add_single" it will return the newly created objectProperties nodes.

                For "remove" cmd it will return the removed/deleted objectProperties nodes.
    :rtype: list

    """
    # Since the objectProperties command operates on selection when we provide a nodes list
    # we override the selection and store the current selection to set it back afterwards
    if nodes is not None:
        pre_sel = mc.ls(sl=1)
        mc.select(nodes, r=1)

    # Store the currently connected sets of the type that we will be creating
    # Then we can check again afterwards, the new sets not in this old list will be the ones that have been created.
    sel = mc.ls(sl=1)
    if not sel:
        return []

    # We're using the type to filter the connected sets to a list as small as possible. (Optimization)
    # Therefore if None is provided (default is used) we convert it to its actual default type name.
    if type is None:
        type = "VRayObjectProperties"

    pre_connected_sets = set(getConnectedSets(sel, type=type))

    # Create the object properties
    mc.vray("objectProperties", cmd, type)

    # Get the actual objectProperties nodes that have been created
    post_connected_sets = set(getConnectedSets(sel, type=type))
    new_sets = post_connected_sets - pre_connected_sets

    # If there are new sets than the objectProperties commands created something
    if new_sets:
        if name is not None:
            # Rename all nodes and capture the new names directly into the list
            new_sets = [mc.rename(s, name) for s in new_sets]

        if nodes is not None:
            # Since the user might have selected a set that has been deleted by the vray command.
            # We first get the list of pre_sel nodes that actually still exist and select those.
            pre_sel = mc.ls(pre_sel, long=True)
            if pre_sel:
                mc.select(pre_sel, r=1)
            else:
                mc.select(d=1)

        return list(new_sets)

    # If no new sets were created it's likely that something has been deleted instead.
    deleted_sets = pre_connected_sets - post_connected_sets
    if deleted_sets:
        # Return the names of the deleted nodes
        return list(deleted_sets)

    # If we get over here nothing changed.
    return []
# To be continued. :)
# Now you should know the difference between transforms and their children shapes.
# Let's get all transform nodes that end with "*_SMOOTH" and add a subdivision attribute to it's children mesh shapes.

import maya.cmds as mc

# Get all transform nodes that end with _SMOOTH
nodes = mc.ls("*_SMOOTH", type="transform")
if nodes:
    # Get the children shapes of type mesh
    meshes = mc.listRelatives(nodes, children=True, shapes=True, type="mesh")
    # If we found children meshes, then for every mesh shape node add the vray_subdivision attribute.
    if meshes:
        for mesh in meshes:
            mc.vray("addAttributesFromGroup", "vray_subdivision", mesh, 1)

# We can do something similar for all nurbsCurves that we want to make renderable. If we have given a specific suffix
# to the nodes we can easily address them.
# So I've discussed with the team and we went for "_EXTREMELY_RENDERABLE_CURVE" as a suffix on the transform node of
# the nurbsCurves.

# Ah yeah, let's get those transforms!
import maya.cmds as mc

nodes = mc.ls("*_EXTREMELY_RENDERABLE_CURVE", type="transform")
print nodes

# So we play around and test if it is giving us the nodes. Did you try it?
# Then go on and get the children nurbsCurve shape nodes.
Exemplo n.º 26
0
# This allows us to use Maya's command features in our code.
# For example we can list all mesh shapes in our scene, like:

print mc.ls(type="mesh")

# But hey, you came here to do some v-ray for maya magic.
#
# This is the moment where you make sure the vrayformaya.mll is loaded in your Plug-in Manager.
# You can find it in: Window > Settings/Preferences > Plug-in Manager
# Search for the vrayformaya.mll and make sure the loaded checkbox is checked.
#
# Basically most of the stuff you can do with commands provided from the V-ray for Maya plug-in is done through a
# command called ``vray``. Commands created by plug-ins are available in the maya.cmds namespace.
# In short we can do something like:

mc.vray()

# Note that this doesn't give any errors, but it doesn't do anything either.
# By having a look at the wiki documentation on this repository you'll find what you can provide as arguments:
# https://github.com/BigRoy/mayaVrayCommandDocs/wiki
#
# Many people getting started with v-ray for maya scripting are doing it to help ease the adding of v-ray attributes.
# So let's start there. Adding v-ray attributes is done through the ``vray`` command with the action
# ``addAttributesFromGroup``. More information here:
# https://github.com/BigRoy/mayaVrayCommandDocs/wiki/vray-addAttributesFromGroup
#
# The example on that page shows us:

shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
for shape in shapes:
    mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 1)
Exemplo n.º 27
0
 def texture_replace(self):
     number_of_textures = len(self.textures_for_swap)
     i = 0
     while i < number_of_textures:
       #splitting out the old and new texture names
       new_fileTex = self.textures_for_swap[i]
       old_fileTex = self.textures_for_swap[i+1]
       key_words = ['alpha','substrate','matte','mettalic']
       vray_gamma_node_exists_old = cmds.attributeQuery('vrayFileGammaValue',node = old_fileTex,exists = True)
       vray_gamma_node_exists_new = cmds.attributeQuery('vrayFileGammaValue',node = new_fileTex,exists = True)
       #print 'vray_gamma_node_exists_old = ',vray_gamma_node_exists_old
       #print 'vray_gamma_node_exists_new = ',vray_gamma_node_exists_new
       if vray_gamma_node_exists_new == 0:
           if vray_gamma_node_exists_old == 1:
               file_path_name = cmds.getAttr(new_fileTex + '.fileTextureName')
               for key_word in key_words:
                   if key_word not in file_path_name:
                       #print 'adding gamma node'
                       cmds.vray("addAttributesFromGroup", new_fileTex, "vray_file_gamma", 1)
       print " "
       print new_fileTex + " swapping with " + old_fileTex
       #print "---"
       #starting the replace
       source_connections_modified = []
       destination_connections_modified = []
       #grab the old texure incoming connections
       connections_source_old = cmds.listConnections(old_fileTex, plugs = True, connections = True, destination = False)or []
       #grab the old texure outgoing connections
       connections_destination_old = cmds.listConnections(old_fileTex, connections = True, plugs = True, source = False) or []
       #how many incoming connections and outgoing connections are there
       connection_source_size = len(connections_source_old)
       connection_destination_size = len(connections_destination_old)
       #if the incoming connections source size is more than 0, replace the old texture in the incoming connections list
       if connection_source_size != 0:
           for connection in connections_source_old:
               connection_modified = connection.replace(old_fileTex,new_fileTex)
               source_connections_modified.append(connection_modified)
       #if the outgoing connections size is more than 0, replace the old texture in the outgoing connections list
       if connection_destination_size != 0:
           for connection in connections_destination_old:
               connection_modified = connection.replace(old_fileTex,new_fileTex)
               destination_connections_modified.append(connection_modified)
       source_connections_modified_size = len(source_connections_modified)
       #connect the old source node to the new texture
       inIter = 0
       outIter = 1
       while outIter < source_connections_modified_size:
           if connections_source_old[outIter] != "defaultColorMgtGlobals.cmEnabled" and connections_source_old[outIter] != "defaultColorMgtGlobals.configFileEnabled" and connections_source_old[outIter] != "defaultColorMgtGlobals.configFilePath" and connections_source_old[outIter] != "defaultColorMgtGlobals.workingSpaceName":
               #print "connecting " + connections_source_old[outIter] + " to "  + source_connections_modified[inIter]
               cmds.connectAttr(connections_source_old[outIter],source_connections_modified[inIter],force = True)
           outIter = outIter + 2
           inIter = inIter + 2
       destination_connections_modified_size = len(destination_connections_modified)
       #connect the new texture to the old destination node
       inIter = 0
       outIter = 1
       while outIter < destination_connections_modified_size:
           if ".message" not in destination_connections_modified[inIter]:
               #print "connecting " + destination_connections_modified[inIter] + " to " + connections_destination_old[outIter]
               cmds.connectAttr(destination_connections_modified[inIter],connections_destination_old[outIter], force = True)
           outIter = outIter + 2
           inIter = inIter + 2
       #transferAttr settings for new texture
       old_file_texture_attr_dic = {}
       new_file_texture_attr_dic = {}
       old_file_texture_attrs = cmds.listAttr(old_fileTex,k = True)
       attrAppend = ["filter","filterOffset","filterType"]
       attrRemove = ["aiUserOptions","defaultColorMgtGlobals.cmEnabled","defaultColorMgtGlobals.configFileEnabled","defaultColorMgtGlobals.configFilePath","workingSpaceName"]
       for attr in attrAppend:
           old_file_texture_attrs.append(attr)
       for attr in attrRemove:
           if attr in old_file_texture_attrs:
               old_file_texture_attrs.remove(attr)
       new_file_texture_attrs = cmds.listAttr(new_fileTex,k = True)
       for attr in attrAppend:
           new_file_texture_attrs.append(attr)
       for attr in attrRemove:
           if attr in new_file_texture_attrs:
               new_file_texture_attrs.remove(attr)
       for oldFileAttr in old_file_texture_attrs:
           oldFileAttrValue = cmds.getAttr(old_fileTex + "." + oldFileAttr)
           old_file_texture_attr_dic[oldFileAttr] = oldFileAttrValue
       for new_fileTexAttr in new_file_texture_attrs:
           new_fileTexAttr_Value = cmds.getAttr(new_fileTex + "." + new_fileTexAttr)
           new_file_texture_attr_dic[new_fileTexAttr] = new_fileTexAttr_Value
       for new_fileTexAttr in new_file_texture_attrs:
           if new_fileTexAttr in new_file_texture_attr_dic:
               attrExists = cmds.attributeQuery(new_fileTexAttr,node = new_fileTex,exists = True)
               if attrExists == 1:
                   #print "setting " + str(new_fileTex) + "." + str(new_fileTexAttr) + " to " + str(old_file_texture_attr_dic[new_fileTexAttr])
                   cmds.setAttr(new_fileTex + "." + new_fileTexAttr,old_file_texture_attr_dic[new_fileTexAttr])
       i = i + 2
     cmds.select(clear = True)
     self.texture_thumbnails_listWidget.clear()
     new_fileTex = ''
     old_fileTex = ''
Exemplo n.º 28
0
def rrCheckbox(checkBoxRenderRegion, reg, *args):
    global gReg
    zeroes = ['0', '0', '0', '0']
    tRes = cmds.vray("vfbControl", "-getregion")
    if tRes != zeroes:
        gReg = tRes
    rrstate = cmds.checkBox(checkBoxRenderRegion, value=True, query=True)
    if rrstate == 0:
        if gReg != zeroes:
            cmds.vray("vfbControl", "-setregion", gReg[0], gReg[1], gReg[2],
                      gReg[3])
        else:
            cmds.vray("vfbControl", "-setregion", reg[0], reg[1], reg[2],
                      reg[3])
        cmds.vray("vfbControl", "-setregion", "reset")
    if rrstate == 1:
        cmds.vray("vfbControl", "-setregionenabled", 1)
        if gReg != zeroes:
            cmds.vray("vfbControl", "-setregion", gReg[0], gReg[1], gReg[2],
                      gReg[3])
        else:
            cmds.vray("vfbControl", "-setregion", reg[0], reg[1], reg[2],
                      reg[3])
    return (reg)
Exemplo n.º 29
0
def renthumbsWin():
    user_track()
    name = "Batch_Review"
    global gReg
    gReg = ('0', '0', '0', '0')
    zeroes = ('0', '0', '0', '0')
    windowSize = (200, 100)
    if (cmds.window(name, exists=True)):
        cmds.deleteUI(name)
    window = cmds.window(name,
                         title=name,
                         width=350,
                         height=50,
                         bgc=(.2, .2, .2),
                         s=False)
    cmds.columnLayout("mainColumn", adjustableColumn=True)
    cmds.rowLayout("nameRowLayout01", numberOfColumns=15, parent="mainColumn")
    cmds.text(label="preset quality:  ")
    checkBoxLow = cmds.checkBox(label="low", value=False)
    checkBoxMid = cmds.checkBox(
        label="mid",
        value=True,
    )
    checkBoxHigh = cmds.checkBox(label="high", value=False)
    cmds.text(label="                             ")
    cmds.text(label="resolution:  ")
    intField_res = cmds.intField(v=1000, width=45)
    #print 'intField_res = ',intField_res
    cmds.intField(intField_res,
                  changeCommand=partial(set_resolution, intField_res),
                  edit=True)
    cmds.text(label="  ")
    cmds.text(label="threshold:  ")
    floatField_thrhld = cmds.floatField(v=.5, width=45)
    cmds.floatField(floatField_thrhld,
                    changeCommand=partial(set_threshhold, floatField_thrhld),
                    edit=True)
    cmds.checkBox(checkBoxLow,
                  changeCommand=partial(checkBoxCheckLow, checkBoxLow,
                                        checkBoxMid, checkBoxHigh,
                                        intField_res, floatField_thrhld),
                  edit=True)
    cmds.checkBox(checkBoxMid,
                  changeCommand=partial(checkBoxCheckMid, checkBoxLow,
                                        checkBoxMid, checkBoxHigh,
                                        intField_res, floatField_thrhld),
                  edit=True)
    cmds.checkBox(checkBoxHigh,
                  changeCommand=partial(checkBoxCheckHigh, checkBoxLow,
                                        checkBoxMid, checkBoxHigh,
                                        intField_res, floatField_thrhld),
                  edit=True)
    cmds.rowLayout("nameRowLayout02", numberOfColumns=10, parent="mainColumn")
    cmds.text(label="  ")
    cmds.rowLayout("nameRowLayout03", numberOfColumns=5, parent="mainColumn")
    renderButton = cmds.button(label="render", width=100, bgc=(.6, .8, 1))
    cmds.text(label="  ")
    cmds.button(label="cancel renders",
                command=partial(cancelOPs),
                bgc=(1, .3, .3))
    cmds.rowLayout("nameRowLayout04", numberOfColumns=10, parent="mainColumn")
    cmds.text(label="  ")
    cmds.rowLayout("nameRowLayout05", numberOfColumns=10, parent="mainColumn")
    checkBoxRenderRegion = cmds.checkBox(label="use render region",
                                         value=False)
    cmds.text(label="  ")
    cmds.text(label="  ")
    reg = cmds.vray("vfbControl", "-getregion")
    if reg != gReg and reg != zeroes:
        gReg = reg
    cmds.vray("vfbControl", "-setregion", "reset")
    cmds.checkBox(checkBoxRenderRegion,
                  changeCommand=partial(rrCheckbox, checkBoxRenderRegion, reg),
                  edit=True)
    cmds.rowLayout("nameRowLayout06", numberOfColumns=10, parent="mainColumn")
    AOVstate = cmds.getAttr("vraySettings.relements_enableall")
    checkBoxAOV = cmds.checkBox(label="elements", value=AOVstate)
    cmds.checkBox(checkBoxAOV,
                  changeCommand=partial(checkBoxAOVchange, checkBoxAOV),
                  edit=True)
    cmds.button(renderButton,
                command=partial(renderThumbs, checkBoxLow, checkBoxMid,
                                checkBoxHigh, checkBoxRenderRegion,
                                intField_res, floatField_thrhld),
                edit=True)
    cmds.showWindow()
Exemplo n.º 30
0
def renderThumbs(checkBoxLow, checkBoxMid, checkBoxHigh, checkBoxRenderRegion,
                 intField_res, floatField_thrhld, *args):
    global cancel
    cams = cmds.ls(type="camera")
    cancel = 0
    popup_win = 0
    no_cam_set_list = []
    cmds.loadPlugin('vrayformaya', quiet=True)
    cmds.pluginInfo('vrayformaya', edit=True, autoload=True)
    cmds.setAttr("defaultRenderGlobals.ren", "vray", type="string")

    curLay = cmds.editRenderLayerGlobals(currentRenderLayer=True, query=True)
    changeLay = curLay

    rls = cmds.ls(type="renderLayer")
    renCams = cmds.ls(type="camera")
    renCam = "persp"

    lowBut = cmds.checkBox(checkBoxLow, value=True, query=True)
    midBut = cmds.checkBox(checkBoxMid, value=True, query=True)
    highBut = cmds.checkBox(checkBoxHigh, value=True, query=True)
    globopt_cache_geom_plugins = cmds.getAttr(
        'vraySettings.globopt_cache_geom_plugins')
    #print 'globopt_cache_geom_plugins = ',globopt_cache_geom_plugins

    print " "
    print "-- batch_review --"

    res = cmds.intField(intField_res, v=True, query=True)
    thr = cmds.floatField(floatField_thrhld, v=True, query=True)

    if lowBut == 1:
        cmds.setAttr("vraySettings.dmcThreshold", thr)
        cmds.setAttr("vraySettings.width", res)
        cmds.setAttr("vraySettings.height", res)
        cmds.setAttr("vraySettings.globopt_cache_geom_plugins", 1)
        cmds.setAttr("vraySettings.globopt_ray_maxIntens_on", 1)
        #cmds.setAttr('vraySettings.globopt_cache_geom_plugins',globopt_cache_geom_plugins)
        print " "
        print "---"
        print "quality = %s, dmcThreshold = %s" % (res, thr)
    if midBut == 1:
        cmds.setAttr("vraySettings.dmcThreshold", thr)
        cmds.setAttr("vraySettings.width", res)
        cmds.setAttr("vraySettings.height", res)
        cmds.setAttr("vraySettings.globopt_cache_geom_plugins", 1)
        cmds.setAttr("vraySettings.globopt_ray_maxIntens_on", 1)
        #cmds.setAttr('vraySettings.globopt_cache_geom_plugins',globopt_cache_geom_plugins)
        print " "
        print "---"
        print "quality = %s, dmcThreshold = %s" % (res, thr)
    if highBut == 1:
        cmds.setAttr("vraySettings.dmcThreshold", thr)
        cmds.setAttr("vraySettings.width", res)
        cmds.setAttr("vraySettings.height", res)
        cmds.setAttr("vraySettings.globopt_cache_geom_plugins", 1)
        cmds.setAttr("vraySettings.globopt_ray_maxIntens_on", 1)
        #cmds.setAttr('vraySettings.globopt_cache_geom_plugins',globopt_cache_geom_plugins)
        print " "
        print "---"
        print "quality = %s, dmcThreshold = %s" % (res, thr)

    print "--- "
    print " "

    for rl in rls:
        found_cam = 0
        if rl != "defaultRenderLayer" and cancel == 0:
            rlState = cmds.getAttr(rl + ".renderable")
            if rlState == 1:
                print ' '
                print "rende layer = ", rl
                cmds.editRenderLayerGlobals(currentRenderLayer=rl)
                for cam in cams:
                    camState = cmds.getAttr(cam + ".renderable")
                    if camState == 1:
                        rrState = cmds.checkBox(checkBoxRenderRegion,
                                                value=True,
                                                query=True)
                        reg = cmds.vray("vfbControl", "-getregion")
                        if rrState == 0:
                            cmds.vray("vfbControl", "-setregion", "reset")
                        if rrState == 1:
                            cmds.vray("vfbControl", "-setregionenabled", 1)
                            cmds.vray("vfbControl", "-setregion", reg[0],
                                      reg[1], reg[2], reg[3])
                        mayaString = "renderWindowRenderCamera render renderView " + cam
                        print 'using ' + cam + ' for ' + rl
                        maya.mel.eval(mayaString)
                        cmds.vray("vfbControl", "-historysave")
                        cmds.vray("vfbControl", "-historyselect", 0)
                        #dte = datetime.now().strftime('%H:%M:%S')
                        dte = datetime.now().strftime('%H:%M')
                        editStr = rl + "," + cam
                        cmds.vray("vfbControl", "-historycomment", editStr)
                        print " "
                        found_cam = 1
                if found_cam == 0:
                    print 'no camera link found, using persp cam for ', rl
                    cam = 'persp'
                    rrState = cmds.checkBox(checkBoxRenderRegion,
                                            value=True,
                                            query=True)
                    reg = cmds.vray("vfbControl", "-getregion")
                    if rrState == 0:
                        cmds.vray("vfbControl", "-setregion", "reset")
                    if rrState == 1:
                        cmds.vray("vfbControl", "-setregionenabled", 1)
                        cmds.vray("vfbControl", "-setregion", reg[0], reg[1],
                                  reg[2], reg[3])
                    mayaString = "renderWindowRenderCamera render renderView " + cam
                    maya.mel.eval(mayaString)
                    cmds.vray("vfbControl", "-historysave")
                    cmds.vray("vfbControl", "-historyselect", 0)
                    dte = datetime.now().strftime('%H:%M:%S')
                    editStr = rl + "," + cam
                    cmds.vray("vfbControl", "-historycomment", editStr)
                    popup_win = 1
                    no_cam_set_list.append(rl)
Exemplo n.º 31
0
def vraySubdivisions():
    shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
    for shape in shapes:
        mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 3)
Exemplo n.º 32
0
def objectProperties(cmd,
                     type=None,
                     nodes=None,
                     name=None):
    """ Adds/removes objectProperties to/from input nodes.

    This is currently an experimental implementation, behaviour and naming of functions/keywords may change.
    Even though our focus is to stay as backwards compatible as possible we can't ensure this in the long run
    for experimental implementations.

    :param cmd: The string command to run for the objectProperties.
                Possible values are: "add_single", "add_multiple", "remove", "remove_sub"
    :type  cmd: str

    :param type: The objectProperties type to operate on. If None provided the default "VRayObjectProperties" is used.
    :type  type: str

    :param nodes: The nodes to operate on. If None provided the current selection is used.
    :type  nodes: list

    :param name: Rename the created nodes to `name`. If None provided nodes will get default name.
    :type  name: str

    :return: If objectProperties nodes are created it returns the newly created nodes. If no nodes have been created,
             but there are related objectProperties nodes that have been deletd those will be returned.

                e.g.

                For "add_single" it will return the newly created objectProperties nodes.

                For "remove" cmd it will return the removed/deleted objectProperties nodes.
    :rtype: list

    """
    # Since the objectProperties command operates on selection when we provide a nodes list
    # we override the selection and store the current selection to set it back afterwards
    if nodes is not None:
        pre_sel = mc.ls(sl=1)
        mc.select(nodes, r=1)

    # Store the currently connected sets of the type that we will be creating
    # Then we can check again afterwards, the new sets not in this old list will be the ones that have been created.
    sel = mc.ls(sl=1)
    if not sel:
        return []

    # We're using the type to filter the connected sets to a list as small as possible. (Optimization)
    # Therefore if None is provided (default is used) we convert it to its actual default type name.
    if type is None:
        type = "VRayObjectProperties"

    pre_connected_sets = set(getConnectedSets(sel, type=type))

    # Create the object properties
    mc.vray("objectProperties", cmd, type)

    # Get the actual objectProperties nodes that have been created
    post_connected_sets = set(getConnectedSets(sel, type=type))
    new_sets = post_connected_sets - pre_connected_sets

    # If there are new sets than the objectProperties commands created something
    if new_sets:
        if name is not None:
            # Rename all nodes and capture the new names directly into the list
            new_sets = [mc.rename(s, name) for s in new_sets]

        if nodes is not None:
            # Since the user might have selected a set that has been deleted by the vray command.
            # We first get the list of pre_sel nodes that actually still exist and select those.
            pre_sel = mc.ls(pre_sel, long=True)
            if pre_sel:
                mc.select(pre_sel, r=1)
            else:
                mc.select(d=1)

        return list(new_sets)

    # If no new sets were created it's likely that something has been deleted instead.
    deleted_sets = pre_connected_sets - post_connected_sets
    if deleted_sets:
        # Return the names of the deleted nodes
        return list(deleted_sets)

    # If we get over here nothing changed.
    return []
vray addAttributesFromGroup file7 vray_file_gamma 1;
'vrayFileColorSpace'

#gamma correct
import maya.cmds as cmds
if cmds.objExists('file7'+'.'+'vrayFileColorSpace'):
    cmds.setAttr('file7'+'.'+'vrayFileColorSpace',1)
else:
    cmds.vray('addAttributesFromGroup','file7','vray_file_gamma' ,1)
    cmds.setAttr('file7'+'.'+'vrayFileColorSpace',1)
    
    
Exemplo n.º 34
0
def addVrayOID():
    shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
    for shape in shapes:
        mc.vray("addAttributesFromGroup", shape, "vray_objectID", 1)
Exemplo n.º 35
0
def addVrayOSD(userDepth=2):
    shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
    for shape in shapes:
        mc.vray("addAttributesFromGroup", shape, "vray_opensubdiv", 1)
        mc.setAttr(shape + '.vrayOsdSubdivDepth', userDepth)
Exemplo n.º 36
0
def vraySubdivisions():
    shapes = mc.ls(sl=1, dag=1, lf=1, s=1)
    for shape in shapes:
        mc.vray("addAttributesFromGroup", shape, "vray_subdivision", 3)