Shaders

Arnoldaovs

Arnold AOV related

getAllAovNodes()
checkAovNameExists(name)

checks for the existence of all aov nodes .name, if a match is found then True, if not False

Parameters:

name (str) – name of the AOV

Return exists:

does the name exist on any of the aiAOV nodes?

Rtype exists:

bool

createAOV(aovName)

Creates a custom AOV with the name given keeps it unique by doing checks, the aovName is not the node name

Parameters:

aovName

Returns:

Return type:

getAllAOVsAndNames()
createAiWriteColor(nodeName='aiWriteColor', imageNumber=0, matteColor=(0, 0, 0), message=True)

Creates a aiWriteColor Node in Maya, to be used in a RGBA Mattes (AOVs)

Parameters:
  • imageNumber (str) – The name of the aiWriteColor node in Maya to be created

  • message (bool) – If on will return the create message to Maya

Return aiWriteColor:

The name of the aiWriteColor Node in Maya that was created

createRGBMatteAOV(nodeList, matteColor, imageNumber)

Creates RGB mattes to shading groups associated with an nodeList, usually meshes, shaders or shading groups 1. Creates the AOV image node if it doesn’t already exist 2. Creates a aiWriteColor node and assigns the attributes correctly to match the AOV name 3. Connects between the shader and the shading group

Parameters:
  • nodeList (list) – node list, can be objects, shaders or shading group names

  • matteColor (tuple) – the color of the matte to create

  • imageNumber (int) – the matte AOV image number

createRGBMatteAOVSelected(matteColor, imageNumber)

Creates RGB mattes to shading groups associated with a selection, usually meshes, shaders or shading groups 1. Creates the AOV image node if it doesn’t already exist 2. Creates a aiWriteColor node and assigns the attributes correctly to match the AOV name 3. Connects between the shader and the shading group

Parameters:
  • matteColor (tuple) – the color of the matte to create

  • imageNumber (int) – the matte AOV image number

aiMaskSet()

function from http://therenderblog.com/creating-id-mask-passes-using-python-based-on-selection-sets/ Not tested good example of AOV code

Arnolddisplacement

createDisplacementNodes(nodeList, imagePath='', displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1.0, bounds=0.1)

Creates a displacement setup for Arnold

Builds the shader node networks and changes the Arnold mesh attributes too Shading Group and Mesh selection is automatic nodeList can be any selection type related to a shader. eg mesh, transform, shader or shading group

Parameters:
  • nodeList (list) – list of nodes names that could be or are related to the shading group

  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

  • autoBump (bool) – autobump is a setting for regular displacement only and potentially adds a bump for fine details

  • maxDivisions (int) – max divisions is the highest level of subdivides the mesh can go

  • scaleMultiplier (float) – the scale multiplier of the displacement

  • bounds (float) – Increase this value if clipping occurs in the displacement

Return shadingGroupList:

list of the shading groups names that now have displacement nodes

Rtype shadingGroupList:

list

Return fileNodeList:

list of the fileNodes (texture) names that have been created

Rtype fileNodeList:

list

Return place2dTextureNodeList:

list of the place2dTextureNode names that have been created

Rtype place2dTextureNodeList:

list

createDisplacementNodesSelected(imagePath='', displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1)

Creates a displacement setup for Arnold from a selection Will build the node networks and change the mesh attributes too the selection can be any selection type related to a shaders, meshes, transforms, shaders or shading groups

Parameters:
  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

Return shadingGroupList:

list of the shading groups names that now have displacement nodes

Rtype shadingGroupList:

list

Return fileNodeList:

list of the fileNodes (texture) names that have been created

Rtype fileNodeList:

list

Return place2dTextureNodeList:

list of the place2dTextureNode names that have been created

Rtype place2dTextureNodeList:

list

deleteDisplacementNodes(meshList, fileNodeList, place2dTextureNodeList, displaceNode)

Deletes a displacement setup for Arnold

Deletes the displacement nodes and resets the mesh subdivision attributes to be off

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

  • displaceNode (str) – the Arnold displacement node type “displacementShader”

getDisplacementAttrValues(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode)

Retrieves the main attribute values of the displacement setup, usually for the UI

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

  • displaceNode (str) – the Arnold displacement node type “displacementShader”

Returns:

Return type:

setDisplacementAttrValues(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode, attrDict, message=False)

Sets all attributes on the displacement network

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • shadingGroupList (list(str)) – List of shading Group names

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

  • displaceNode (str) – the Arnold displacement node type “displacementShader”

  • attrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • message (bool) – Report the message to the user?

updateMeshes(newConnectionsList, breakConnectionsList, attrDict, enabled)

When a new mesh is connected, update the mesh to match the settings of the shader displacement

Parameters:
  • newConnectionsList (list(str)) – A list of Maya meshes to update, these are newly connected

  • breakConnectionsList (list(str)) – A list of Maya meshes to update, these are no longer part of the network

  • attrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • enabled (bool) – Is the displacement enabled? Affects .aiSubdivType attribute

setEnabled(meshList, displaceNode, enableValue=True, autoBump=False)

Sets the enable state of the entire displacement network

In Arnold use aiSubdivType on each mesh and disconnect the displacement from the sahder

Parameters:
  • meshList (list(str)) – A list of mesh names

  • enableValue (nool) – Enable True or disable False

getEnabled(meshList)

Gets the enable state of the entire displacement network

In Arnold just query aiSubdivType on each mesh

Parameters:

meshList (list(str)) – A list of mesh names

Return enableValue:

Enable True or disable False

Rtype enableValue:

bool

Arnoldshaders

Arnold related shader functions

loadArnold()

Load Arnold

mtoaVersionNumber()

Returns the version number of the mtoa plugin and not Arnold!

Return major:

the major version number 4.2.1 will be 4

Rtype major:

int

Return minor:

the minor version number 4.2.1 will be 2

Rtype minor:

int

Return patch:

the major version number 4.2.1 will be 1

Rtype patch:

int

createAiStandardSurface(shaderName='shader_ARN', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a aiSurfaceStandard Shader In Maya

:param shaderName:The name of the aiSurfaceStandard shader in Maya to be created :type shaderName:str :param specOff: If True the specular weight is set to 0 (off) :type specOff: bool :param message:If on will return the create message to Maya :type message:bool :return:The name of the pxr shader in Maya that was created :type message:str (possibly unicode)

createAiShadowMatte(shaderName='shadowMatte_ARN', message=True)

Creates a aiShadowMatte Shader In Maya Shadow mattes are for shadows only and or reflections, usually for comping

:param shaderName:The name of the aiSurfaceStandard shader in Maya to be created :type shaderName:str :param message:If on will return the create message to Maya :type message:bool :return:The name of the pxr shader in Maya that was created :type message:str (possibly unicode)

assignNewAiStandardSurface(objList, shaderName='shader_ARN', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5), selectShader=True)

Creates a aiStandardSurface Shader and assigns it to the objList

Parameters:
  • objList – List of object names

  • shaderName (str) – The name of the aiStandardSurface shader in Maya to be created

  • specOff (bool) – If True the specular weight is set to 0 (off)

  • message (bool) – If on will return the create message to Maya

Return shaderName:

The name of the aiStandardSurface shader in Maya that was created

assignNewAiShadowMatte(objList, shaderName='shadowMatte_ARN', message=True, selectShader=True)

Creates a aiShadowMatte Shader and assigns it to the objList Shadow mattes are for shadows only and or reflections, usually for comping

Parameters:
  • objList – List of object names

  • shaderName (str) – The name of the aiShadowMatte shader in Maya to be created

  • message (bool) – If on will return the create message to Maya

Return shaderName:

The name of the aiShadowMatte shader in Maya that was created

assignSelectedNewAiStandardSurface(shaderName='shader_ARN', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a aiStandardSurface Shader and assigns it to the current selection

Parameters:
  • shaderName (str) – The name of the aiStandardSurface shader in Maya to be created

  • specOff (bool) – If True the specular weight is set to 0 (off)

  • message (bool) – If on will return the create message to Maya

Return shaderName:

The name of the aiStandardSurface shader in Maya that was created

assignSelectedNewAiShadowMatte(shaderName='shadowMatte_ARN', message=True)

Creates a aiShadowMatte Shader and assigns it to the current selection Shadow mattes are for shadows only and or reflections, usually for comping

Parameters:
  • shaderName (str) – The name of the aiShadowMatte shader in Maya to be created

  • message (bool) – If on will return the create message to Maya

Return shaderName:

The name of the aiShadowMatte shader in Maya that was created

showHideArnoldChannelAttrs(showAttr=False)

Hides (or shows) all the Arnold attributes that annoyingly get keys in rigs

Parameters:

showAttr (bool) – if False will hide all the attributes in the scene, True will unhide

Buildtexturedshader

from zoo.libs.maya.cmds.shaders import buildtexturedshader textureDict = buildtexturedshader.testTextureDictFromPath() # test data buildtexturedshader.buildTexturedShader(textureDict, shaderType=”standardSurface”, shaderName=””)

textureDictFromPath(path, textureList, searchSuffixList)

Creates a dictionary of shader paths. search suffix is the key and the path is the value.

textureList is

Parameters:
  • path (str) – The path of the directory where the files live.

  • textureList (list(str)) – Filenames (not paths) of files on disk, some filenames may not be textures and will be ignored.

  • searchSuffixList (list(str)) – A list of the available suffixes to find the textures by suffix.

Return textureDict:

A dictionary with search suffixing as keys and texture paths as values, might change

Rtype textureDict:

dict(str: str)

testTextureDictFromPath()

Creates a texture dict test data for testing

buildTexturedShader(textureDict, shaderType='standardSurface', shaderName='')

Creates a new shader with textures from a texture dictionary.

Parameters:
  • textureDict (dict(str: str)) – A dictionary with search suffixing as keys and texture paths as values, might change

  • shaderType (str) – The type of shader to build, supported shader types in shdrmultconstants

  • shaderName (str) – The optional name of the shader, if empty will create the shader name from the textures.

Return shdInstance:

A Zoo shader instance object

Rtype shaderInstance:

zoo.libs.maya.cmds.shaders.shadertypes.shaderbase.ShaderBase

Return txtr_nodes_dict:

attrTypes are the keys and texture node lists are the values.

Rtype txtr_nodes_dict:

dict(str: list(str))

Convertshaders

Converts shaders from one type to another.

New style shader code uses zoo’s shader instances.

from zoo.libs.maya.cmds.shaders import convertshaders convertshaders.convertShaderSelection(convertToShaderType=”standardSurface”, reassign=True, message=True)

convertshaders.swatchColorsToNewRenderSpaceScene()

boolWeightAttr(weight, color)

While converting, the final shader may miss a weight attribute, so before setting force the color to have the weight factored into it already. So force the weight to be either one or zero.

Parameters:
  • weight (float) – The weight attribute in a shader pair (weight/color)

  • color (list(float)) – The color attribute in a shader pair (weight/color)

Return weight:

The resulting weight attribute in a shader pair (weight/color)

Rtype weight:

float

Return color:

The resulting color attribute in a shader pair (weight/color)

Rtype color:

list(float)

correctMissingWeight(color)

Shaders that are getting converted may be missing a weight attribute, so set it to be 1.0 if color or 0.0 if not

Parameters:

color (list(float)) – The color attribute in a shader pair (weight/color)

Return weight:

The resulting weight attribute in a shader pair (weight/color)

Rtype weight:

float

correctShaderPairAttr(attrDict, weightKey, colorKey)

While converting, shaders commonly are missing a weight attribute. Eg. diffuseColor and diffuseWeight, the diffuseWeight attribute may be missing.

While converting either:

  1. The existing shader is missing a weight attr

  2. The destination (newly converted) shader is missing a weight attr

The function corrects both by setting the existing weight value to be either 1.0 or 0.0.

It also corrects color values if weight is set to a number in between zero and one. Eg. weight is 0.34 so adjusts the color accordingly and sets the weight to one.

Parameters:
  • attrDict (dict(str)) – A shader dictionary of values generic shader keys with values as per shdm

  • weightKey (str) – The dictionary key of the weight eg. “gDiffuseWeight”

  • colorKey (str) – The dictionary key of the color eg. gDiffuseColor_srgb

Return attrDict:

The corrected shader dictionary of values generic shader keys with values as per shdm

Rtype attrDict:

dict(str)

correctAttrs(attrDict, fromShaderInst, newShaderInst)

Corrects shader pairs ready for applying the converted values. See correctShaderPairAttr() for more info.

Parameters:
  • attrDict (dict(str)) – A shader dictionary of values generic shader keys with values as per shdm

  • fromShaderInst (shaderbase.ShaderBase) – The shader instance that is being converted

  • newShaderInst (shaderbase.ShaderBase) – The newly created shader instance

Return attrDict:

The corrected shader dictionary of values generic shader keys with values as per shdm

Rtype attrDict:

dict(str)

selectedShaders(message=True)

returns selected shaders in the scene as shader instances. None if None found

Parameters:

message (bool) – report a message to the user

Return shaders:

A list of shader names

Rtype shaders:

list(str)

convertShader(shaderName, convertToShaderType='standardSurface', reassign=True, removeShaders=False, maintainConnections=True, message=True)

Converts a shader to a new shader type, supports attributes and not textures atm.

Supports shdm.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • shaderName (str) – The name of the shader to convert

  • convertToShaderType (str) – The new shader type eg “aiStandardSurface” see shdm.SHADERTYPE_SUFFIX_DICT

  • reassign (bool) – Reassign the shader assignments to geometry after creating?

  • removeShaders (bool) – Delete the previous shaders after converting?

  • maintainConnections (bool) – Maintains any previous connections, copy pastes old textures into new shader.

  • message (bool) – Report a message to the user?

Return shaderInstance:

A zoo shader instance of the newly created shader

Rtype shaderInstance:

shaderbase.ShaderBase

convertShaderList(shaderList, convertToShaderType='standardSurface', reassign=True, removeShaders=False, maintainConnections=True, message=True)

Converts a shader list to a new shader type, supports attributes and not textures atm.

Supports shdm.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • shaderList (list(str)) – A list of maya shader names

  • convertToShaderType (str) – The new shader type eg “aiStandardSurface” see shdm.SHADERTYPE_SUFFIX_DICT

  • reassign (bool) – Reassign the shader assignments to geometry after creating?

  • removeShaders (bool) – Delete the previous shaders after converting?

  • maintainConnections (bool) – Maintains any previous connections, copy pastes old textures into new shader.

  • message (bool) – Report a message to the user?

Return shaderInstances:

A list of zoo shader instance of the newly created shader

Rtype shaderInstances:

list(shaderbase.ShaderBase)

convertShaderSelection(convertToShaderType='standardSurface', reassign=True, removeShaders=False, maintainConnections=True, message=True)

Converts a selected shaders or objects to a new shader type, supports attributes and no textures atm.

Supports shdm.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • convertToShaderType (str) – The new shader type eg “aiStandardSurface” see shdm.SHADERTYPE_SUFFIX_DICT

  • reassign (bool) – Reassign the shader assignments to geometry after creating?

  • removeShaders (bool) – Delete the previous shaders after converting?

  • maintainConnections (bool) – Maintains any previous connections, copy pastes old textures into new shader.

  • message (bool) – Report a message to the user?

Return shaderInstances:

A list of zoo shader instance of the newly created shader

Rtype shaderInstances:

list(shaderbase.ShaderBase)

convertShaderScene(convertToShaderType='standardSurface', reassign=True, removeShaders=False, maintainConnections=True, assignedShadersOnly=True, message=True)

Converts all shaders in the scene to a new shader type, supports attributes and no textures atm.

If shaders are found who’s shader type is not supported then the shader will be ignored.

Supports shdm.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • convertToShaderType (str) – The new shader type eg “aiStandardSurface” see shdm.SHADERTYPE_SUFFIX_DICT

  • reassign (bool) – Reassign the shader assignments to geometry after creating?

  • removeShaders (bool) – Delete the previous shaders after converting?

  • maintainConnections (bool) – Maintains any previous connections, copy pastes old textures into new shader.

  • assignedShadersOnly (bool) – Only converts shaders that are assigned to geo

  • message (bool) – Report a message to the user?

Return shaderInstances:

A list of zoo shader instance of the newly created shader

Rtype shaderInstances:

list(shaderbase.ShaderBase)

convertShaderSaveScene(fileName, convertToShaderType, removeShaders=False, maintainConnections=True, message=True)

Saves the current file to a full path filename and converts all shaders in the scene.

Any shaders that cannot be converted are ignored.

Supports shdm.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • fileName (str) – The full path filename to save

  • shaderType (str) – The new shader to convert to type eg “aiStandardSurface” see shdm.SHADERTYPE_SUFFIX_DICT

  • removeShaders (bool) – Remove the old shaders from the saved file?

  • maintainConnections (bool) – Maintains any previous connections, copy pastes old textures into new shader.

  • message (bool) – Report a message to the user

openConvertFileSave(openPath, shaderType, oldRenderer='Maya', removeShaders=False, maintainConnections=True, useRendererSuffix=True, message=True)

Opens an existing file and saves out a new file with new shaders.

  • c:APathsomeFile_STRD.ma

  • c:APathsomeFile_arnold.ma

Supports shdm.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • openPath (str) – The path of the file to open and convert

  • shaderType (str) – The new shader type to convert to eg “aiStandardSurface” see shdm.SHADERTYPE_SUFFIX_DICT

  • oldRenderer (str) – Usually “Maya” removed the suffix from the name while saving.

  • removeShaders (bool) – Remove the old shaders from the saved file?

  • maintainConnections (bool) – Maintains any previous connections, copy pastes old textures into new shader.

  • useRendererSuffix (bool) – Save the file with the renderer suffix lowercase “_arnold” or use the shader “_ARN”

  • message (bool) – Report a message to the user

swatchColorsToNewRenderSpace(shaderName, originalRenderSpace='scene-linear Rec.709-sRGB', message=True)

Upgrades swatch colors for a single shader from the originalRenderSpace to the scene current space.

Used to upgrade scenes from old linear space in 2020 to new ACES color space.

Affects supported zoo shaders only.

Upgrades attributes

  • diffuse color

  • specular color

  • coat color

  • emission color

Default Rendering Spaces:

  • scene-linear Rec.709-sRGB

  • ACEScg

  • ACES2065-1

  • scene-linear DCI-P3 D65

  • Rec.2020

Parameters:
  • shaderName (str) – Then name of the shader to upgrade/convert swatch colors

  • originalSpace (str) – The original color space usually “linear”

  • message (bool) – Report a message to the user?

Return success:

True if successfully converted

Rtype success:

False

swatchColorsToNewRenderSpaceScene(originalRenderSpace='scene-linear Rec.709-sRGB', message=True)

Upgrades swatch colors for all shaders in the scene from the originalRenderSpace to the scene current space.

Affects supported zoo shaders only.

Upgrades attributes

  • diffuse color

  • specular color

  • coat color

  • emission color

Parameters:

message (bool) – Report messages to the user

swatchColorsToNewRenderSpaceSel(originalRenderSpace='scene-linear Rec.709-sRGB', message=True)

Upgrades swatch colors for selected shaders usually from the originalRenderSpace to the scene current space.

Affects supported zoo shaders only.

Upgrades attributes

  • diffuse color

  • specular color

  • coat color

  • emission color

Parameters:

message (bool) – Report messages to the user

Createshadernetwork

createSGOnShader(shader)

Creates a shading group for the given shader and connects it, usually needed if one doesn’t exist

Parameters:

shader (str) – the shader name

Return shadingGroup:

the shading group name

Rtype shadingGroup:

str

createRampShaderFacingRatio(shaderName='rampSamplerInfo_shad', report=False)

Creates an ambient ramp shader useful for facing ratio tasks”

:param shaderName:name of the shader node :type shaderName:str :param report:display report message? :type report:bool :return rampShader:name of the ramp shader :type rampShader:str

createAnimCurveUL2Keys(curveName='animUL_crv', value1=0, float1=0, value2=1, float2=1, report=False, weighted=1)

Creates an (UL unit length) anim curve useful in shader creation, also can be used in rigs and for various tasks

:param curveName:name of the curve :type curveName:str :param value1:first key value :type value1:float :param float1:first key float value (sometimes time value) :type float1:float :param value2:second key value :type value2:float :param float2:second key float value (sometimes time value) :type float2:float :param report:display report message? :type report:bool :param weighted: Is the curve weighted (0) or non weighted tangents (1) :type weighted: bool :return curveNode:name of the returned animCurve Node :type curveNode:str

prepareColorOutput(textureNode)
Returns the output attribute of the texture node, different renderers have different out attr

Should also change this to find outcolor as most Maya nodes have an outcolor not only “file”

Parameters:

textureNode

Returns:

Return type:

createMultiplyDivideColor()

Creates the node network rgbToHsv > multiplyDivide > hsvToRgb Useful for hue sat value adjustment when the renderer can’t handle Maya’s newer nodes.

Return multiplyNode:

the multiply node

Rtype multiplyNode:

str

Return hsvToRgb:

the hsvToRgb node

Rtype hsvToRgb:

str

Return rgbToHsv:

the rgbToHsv node

Rtype rgbToHsv:

str

connectMultiplyDivideColor(textureNode)

Connect the node setup (rgbToHsv > multiplyDivide > hsvToRgb) to the given texture’s out also maintain the current conenctions input to (usually the shader) if already connected

Parameters:

textureNode (str) – Then texture nodes name, can be multiple node types see prepareColorOutput()

Return successState:

True if the operation was successful

Rtype successState:

bool

connectMultiplyDivideColorSelected()

Connect the node setup (rgbToHsv > multiplyDivide > hsvToRgb) to the given texture’s out Texture node should be selected by the user

createLambertMaterial(shaderName='shader_VP2', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a lambert Shader In Maya

:param shaderName:The name of the RedshiftMaterial shader in Maya to be created :type shaderName:str :param specOff: If True the specular weight is set to 0 (off) :type specOff: bool :param message:If on will return the create message to Maya :type message:bool :return:The name of the redshift material shader in Maya that was created :type message:str (possibly unicode)

Displacementmulti

displaceMessageNodeSetup(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displacementNode, renderer, autoBump)

Connects displacement nodes to a network node named “zooDisplacement_*” (NW_DISPLACE_NODE)

The network node can be handy later, for deleting or managing objects, return back to default states etc

Parameters:
  • meshList (list) – list of Maya mesh names strings (nodes)

  • shadingGroupList (list) – list of Maya shading group names strings (nodes)

  • fileNodeList (list) – list of Maya node file node names strings (nodes)

  • renderer (bool) – The renderer name

  • renderer – The autobump value, we store this value for Renderman and Arnold and disable enable the network

Return place2dTextureNodeList:

The string Maya name of the network node created

Rtype place2dTextureNodeList:

str

getDisplaceNetworkNode(nodeList)

From a node list, find the displacement network nodes and return them as a list

Parameters:

nodeList (list(str)) – Any maya node list

Return networkNodeList:

A list of Displacement Network names. Empty list if nothing found.

Rtype networkNodeList:

list(str)

getDisplaceNetworkSelected()

From the selected objects or sel nodes, find the displacement network nodes and return them as a list

Return networkNodeList:

A list of Displacement Network names. Empty list if nothing found.

Rtype networkNodeList:

list(str)

getDisplaceNetworkNodeAll()

Gets all displacement nodes in the scene and returns them as a list

Return networkNodes:

a list of displacement network nodes in the scene

Rtype networkNodes:

list(str)

getDisplacementNetworkItems(networkNode)

Given a displacement network node name return its objects and shaders

Parameters:
  • renderer (str) – The renderer nice name

  • networkNode (str) – Name of the network node that relates to the displacement needing deletion

createDisplacementRenderer(renderer, nodeList, imagePath='', displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1, networkNodes=True, recreated=False, bounds=0.1)

Creates displacement on multiple renderers based on nice names. “Arnold”, “Renderman”, “Redshift” From a given node list

Parameters:
  • renderer (str) – renderer nice name “Arnold”, “Renderman”, “Redshift”

  • nodeList (list) – list of nodes names that could be or are related to the shading group

  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

  • networkNodes (bool) – create the network nodes for deletion and displacement management

  • recreated (bool) – Only for messages, reports “recreated” to the user instead of ‘created’

  • bounds (bool) – Renderman only setting that can cull objects if too low

createDisplacementNodes(nodeList, renderer, imagePath='', displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1, recreated=False, bounds=0.1)
createDisplacementSelectedRenderer(renderer, imagePath='', displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1, recreated=False, bounds=0.1)

Creates displacement on multiple renderers based on nice names. “Arnold”, “Renderman”, “Redshift” From selection

The selection can be any selection type related to a shaders, meshes, transforms, shaders or shading groups

Parameters:
  • renderer (str) – renderer nice name “Arnold”, “Renderman”, “Redshift”

  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

  • recreated (bool) – Only for messages, reports “recreated” to the user instead of ‘created’

  • bounds (float) – Can cull objects if too low, so may need to use a larger value for all renderers

Return meshList:

list of the mesh shape names that now are affected by the displacement

Rtype meshList:

list

Return shadingGroupList:

list of the shading groups names that now have displacement nodes

Rtype shadingGroupList:

list

Return fileNodeList:

list of the fileNodes (texture) names that have been created

Rtype fileNodeList:

list

Return place2dTextureNodeList:

list of the place2dTextureNode names that have been created

Rtype place2dTextureNodeList:

list

checkValidDisplacementNetwork(shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode, renderer)

Checks the displacement network is valid, see getDisplacementNetworkAttrs() for documentation

This checks if the displacement has been broken, ie the user most likely manually deleted nodes.

Return displacementValid:

True if valid, False if not valid (broken)

Rtype displacementValid:

forceMeshShapes(meshList)

Helper function that makes sure a mesh list is returned as shape nodes, ignores intermediate shape originals

Parameters:

meshList (list(str)) – A list of meshes, can be shape nodes or transforms

Return shapeList:

Now a pure shape list of mesh nodes, filters out intermediate objects

Rtype shapeList:

list(str)

getShaderAndNetworkMeshes(networkNode, shader)

Returns the mesh shape list that is attached to the network node, and also returns the shapes/faces connected the shader.

This is used for comparing the current shader assignments with the displacement nodes.

Parameters:
  • networkNode (str) – A displacement network node

  • shader (str) – A shader name

Return networkShapesList:

The mesh shapes attached to the network node

Rtype networkShapesList:

list(str)

Return shadMeshList:

The mesh shapes connected to the shader, can be faces

Rtype shadMeshList:

list(str)

connectNewMeshesToNetwork(networkNode, shader, message=True)

Checks if a new object has been created and adds it to the meshList on the network node.

Compares the meshList from the network node with the meshList from the shader assignment

If a new mesh from shader assignments is not in the network meshList then connect it.

Parameters:
  • networkNode (str) – A displacement network node name

  • shader (str) – The shader name of the network node, usually grab it from the shading group

  • message (bool) – Report new connections to the user?

Return connectedMeshes:

a list of meshes that were connected, should be an empty list most of the time

Rtype connectedMeshes:

list(str)

disconnectUnusedMeshesFromNetwork(networkNode, shader, message=True)

Checks the shader assigned mesh shapes against the network node shapes, if mismatch will disconnect meshes

Parameters:
  • networkNode (str) – A displacement network node

  • shader (str) – A shader name

  • message (bool) – report the message to the user?

Return disconnectedMeshes:

Any disconnected meshes that have been disconnected, can be empty

Rtype disconnectedMeshes:

list(str)

getDisplacementNetworkAttrs(networkNode)

From a displacement network node return all the network node’s related UI attribute values in a dictionary

DISP_ATTR_TYPE: str “Tangent” or “Object” DISP_ATTR_DIVISIONS: int (Redshift Arnold only, Renderman returns to 4) DISP_ATTR_SCALE: Float DISP_ATTR_AUTOBUMP: Bool DISP_ATTR_IMAGEPATH: string The file path DISP_ATTR_RENDERER: float (Renderman only)

Parameters:

networkNode (str) – A displacement network node name

Return displacementAttrValDict:

A dictionary with the values of the UI attributes

Rtype displacementAttrValDict:

dict()

getDisplacementNetworkAttrsSel(renderer)

Type: Tangent or Object Divisions: int (Redshift Arnold) Scale: Float Auto Bump: Bool Image Path: string Bounds: float (Renderman only)

Parameters:

renderer

Returns:

Return type:

setDisplacementNetworkAttrs(displacementAttrDict, renderer, networkNode, message=True)

Sets displacement attributes on the Displacement Network

Parameters:
  • displacementAttrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • renderer (str) – Name of the renderer

  • networkNode (str) – A displacement network node name

  • message (bool) – Report the message to the user?

Return success:

True if successful, False if not

Rtype success:

bool

setDisplacementNetworkAttrsNodes(nodeList, displacementAttrDict, renderer, message=True)

Sets all attributes on the network nodes associated with nodeList names

Parameters:
  • nodeList (list(str)) – A list of any nodes names, often from selection

  • displacementAttrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • renderer (str) – Name of the renderer

  • message (bool) – Report the message to the user?

Return success:

True if successful, False if not

Rtype success:

bool

setDisplacementNetworkAttrsSel(displacementAttrDict, renderer)

Sets displacement attributes on the Displacement Network

Parameters:
  • displacementAttrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • renderer (str) – Name of the renderer

Return success:

True if successful, False if not

Rtype success:

bool

updateMeshes(renderer, newConnectionsList, breakConnectionsList, attrDict, enabled)

When a new mesh is connected, update the mesh to match the settings of the shader displacement

Parameters:
  • renderer (str) – The nice name of the renderer

  • newConnectionsList (list(str)) – A list of Maya meshes to update, these are newly connected

  • breakConnectionsList (list(str)) – A list of Maya meshes to update, these are no longer part of the network

  • attrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • enabled (bool) – Is the displacement enabled? Affects .aiSubdivType attribute

enableDisplacement(networkNode, renderer, enableValue=1)

Enables the displacement network so that it renders or doesn’t render.

Parameters:
  • networkNode (str) – A displacement network node name

  • renderer (str) – The name of the renderer

  • enableValue (bool) – True is enabled False is disabled

enableDisplacementSG(shadingGroup, renderer, enableValue=True)

Enables the displacement network so that it renders or doesn’t render. Takes the shading group.

Parameters:
  • shadingGroup (str) – A shading group name

  • renderer (str) – The name of the renderer

  • enableValue (bool) – True is enabled False is disabled

enableDisableAll(renderer, enableValue=1, message=True)

Enables or disables all network nodes in the scene

Parameters:
  • renderer (str) – The nice name of the renderer

  • enableValue (int) – 1 is enabled 0 is off (could also be a bool)

  • message (bool) – Report the messages to the user?

getEnableDisplacement(networkNode, renderer)

Retrieves the enable state of the displacement network as True (enabled) or False (disabled)

Takes a network node

Parameters:
  • networkNode (str) – A displacement network node name

  • renderer (str) – The name of the renderer

Return isEnabled:

True is enabled, False is disabled

Rtype isEnabled:

bool

getEnableDisplacementSG(shadingGroup, renderer)

Retrieves the enable state of the displacement network as True (enabled) or False (disabled)

Takes a shading group

Parameters:
  • shadingGroup (str) – A shading group name

  • renderer (str) – The name of the renderer

Return isEnabled:

True is enabled, False is disabled

Rtype isEnabled:

bool

deleteDisplacementRenderer(renderer, meshList, fileNodeList, otherNodeList, displaceNode)

Deletes the displacement setup for a given renderer.

Note will delete texture nodes even if they are used on other attributes. Uncommon in rendering

Does not delete the displacement node

Parameters:
  • renderer (str) – The renderer nice name

  • meshList (list(str)) – list of the mesh shape names that are affected by the displacement

  • fileNodeList (list(str)) – list of the fileNodes (texture) names that have been created

  • otherNodeList (list(str)) – list of the place2dTextureNode names that have been created

  • displaceNode (list(str)) – the main displacement node

Return success:

True if successful

Rtype success:

bool

deleteDisplacementNetwork(networkNode, message=True)

Given a displacement network node name, delete it’s displacement setup

Parameters:
  • renderer (str) – The renderer nice name

  • networkNode (str) – Name of the network node that relates to the displacement needing deletion

deleteBrokenDisplaceNetwork(networkNode)
deleteDisplacementNetworkNodes(nodeList, message=True)
deleteDisplacementNetworkSelected(message=True)

From the selected objects or sel nodes, find the displacement network and delete it.

Parameters:
  • renderer (str) – The renderer nice name

  • message (bool) – Report the message to the user

deleteBrokenDisplacementAll()

Deletes all broken networks in the scene

selectNode(shadingGroup, nodeKey='zooDisplacementNetwork', selectNetworkNode=False)

Selects a node from the network using the dictionary keys:

NW_DISPLACE_NODE = “zooDisplacementNetwork” NW_DISPLACE_MESH_ATTR = “zooDisplaceMeshConnect” NW_DISPLACE_SG_ATTR = “zooDisplaceSGConnect” NW_DISPLACE_FILE_ATTR = “zooDisplaceFileConnect” NW_DISPLACE_PLACE2D_ATTR = “zooDisplacePlace2dConnect” NW_DISPLACE_NODE_ATTR = “zooDisplaceNode”

Parameters:
  • shadingGroup (str) – The shading group node name that connects to all ncloth objects

  • nodeKey (str) – The dictionary key representing an attribute of the network node that links to the objects

  • selectNetworkNode (bool) – If True will ignore all other kwargs and select the network node only

selectShader(shaderName)

Simple function to select the shader by its name

Randomshaders

Module for assigning and managing randomized shaders

Author: Andrew Silke

split(lst, n)

Divide a list into a list of multiple lists

https://stackoverflow.com/questions/2130016/splitting-a-list-into-n-parts-of-approximately-equal-length

Parameters:
  • lst (list()) – any python list

  • n (int) – The number of lists to create

Return listsInList:

returns a list of lists, the list is now split into n lists.

Rtype listsInList:

list(list)

indexInList(lst, index)

Simple function that returns True False if an index is in a list

Parameters:
  • lst (list()) – any python list

  • index (int) – the index number of a list

Return isInList:

True if the index is in a list, False if not.

Rtype isInList:

bool

class RandomShader

Bases: object

Class for assigning random colors to an object selection, maybe shells in the future

setObjs(objList)

Adds the objects to the class as a zapi node list self.nodeList

Parameters:

objList (list(str)) – A list of object names

setSelectedObjs()
setShaderAmount(shaderAmount)
setColor(color)
setValueRangeColor(color, valueRangeFloat)
setSaturationRangeColor(color, saturationRangeFloat)
setHueRangeColor(color, hueRangeFloat)
setAffectShells(affectShells)
setShaderBaseName(shaderBaseName)
setShaderType(shaderType)
setRenderer(renderer)
setSuffix(suffix)
shadersColorable()
lockColor(color)

Records the current color as a HSV color and single values for easy access

Parameters:

color (list(float)) – The current color from the UI, no randomization.

updateHue(hueRangeFloat)

Used by sliders to interactively update the hue range of the randomize colors

See self.updateSaturation() for the math.

Parameters:

hueRangeFloat (float) – The hue range to randomize as a single float

updateSaturation(saturationRangeFloat)

Used by sliders to interactively update the saturation range of the randomize colors

Math is:

colSat = 0.9 # the initial color saturation curSat = 0.95 # the current color saturation rangeSatFloat = 0.2 # the current range of saturation diff = curSat - colSat # the difference between the initial and current saturation multiply = diff / rangeSatFloat # the multiply value to use in the new calculation newValue = colSat + (rangeX * multiply) # the new result

Parameters:

saturationRangeFloat (float) – The saturation range to randomize as a single float

updateValue(valueRangeFloat)

Used by sliders to interactively update the value range of the randomize colors

See self.updateSaturation() for the math.

Parameters:

valueRangeFloat (float) – The value range to randomize as a single float

updateColor(color)

Updates the main color to randomize.

Parameters:

color (list(float)) – The color to randomize in sRGB float (0.5, 0.5, 0.5)

assignShaders()

Assigns the shaders, assumes all preparation of the data has completed

updateShaderAmount(shaderAmount)

Updates the amount of shaders used in the randomize. And deletes or creates new shaders.

Parameters:

shaderAmount (int) – The amount of shaders to distribute for the randomize.

updateShaderNames(shaderBaseName)

Renames all the shader names on existing shaders if they exist

reseedColors()

Reseeds/randomizes the colors and update applies them to all objects

reseedAssignments()

Reseed/Randomizes the object/shader assignments and applies them to all objects

averageColor(colorList)

Finds the average color of a list, colors can be None and the list can be empty

Parameters:

colorList – A list of colors, some entries can be None or the list can be empty.

Return averageColor:

The average color of all the colors, can return an empty list

Rtype averageColor:

useShaders()

Uses the selected shaders and adds them to randomize

Return shaderAmount:

The amount of shaders found

Rtype shaderAmount:

int

Return shaderAverageColor:

The Average color of the shaders

Rtype shaderAverageColor:

list(float)

randomizeShaders()

This button starts the randomize, will assign the shaders but is not used in updating.

clearCache()

Resets the cache fresh, deletes the randomize and shader data

exists()

Returns whether the current instance contains data

Return exists:

Does the data exist?

Rtype exists:

bool

Redshiftaovs

openRenderSettingsTabAOV()

Opens the render settings at the AOV tab

createAOV(type='Puzzle Matte', nodeName='')

Creates a redshift AOV, possible types…

“Depth”, “Puzzle Matte”, “Motion Vectors”, “ObjectID”, “Diffuse Lighting”, “Diffuse Lighting Raw”, “Diffuse Filter”, “Specular Lighting”, “Sub Surface Scatter”, “Sub Surface Scatter Raw”, “Reflections”, “Reflections Raw”, “Reflections Filter”, “Refractions”, “Refractions Raw”, “Refractions Filter”, “Emission”, “Global Illumination”, “Global Illumination Raw”, “Caustics”, “Caustics Raw”, “Ambient Occlusion”, “Shadows”, “Normals”, “Bump Normals”, “Matte”, “Volume Lighting”, “Volume Fog Tint”, “Volume Fog Emission”, “Translucency Lighting Raw”, “Translucency Filter”, “Translucency GI Raw”, “Total Diffuse Lighting Raw”, “Total Translucency Lighting Raw”, “Object-Space Positions”, “Object-Space Bump Normals”, “Background”

Parameters:
  • type (str) – the style of AOV to be created

  • nodeName (str) – the name of the node to be created, if empty will create with default name

Return nodeName:

the name of the node created, note! this is not checked, may not be unique until the code is fixed

Rtype nodeName:

str

createAOVPuzzleMatte(imageNumber, nodeName='rsAov_PuzzleMatte', message=True)

Creates a puzzleMatte AOV (rgb Matte) node only and adds it to the list in the AOV tab under Render Settings checks for unique names as not sure how return the node name in redshift .mel

Parameters:
  • nodeName (str) – the name of the node to be created, if empty will create with default name

  • message (bool) – Report the message to the user

Return nodeName:

the name of the node created

Rtype nodeName:

str

Return matteNodeNumber:

the number of the matte node starts at 0

Rtype matteNodeNumber:

int

checkPuzzleMatteColorExists(colorStr, imageNumber)

Checks to see if the puzzle mate number already exists Does this by cycling through all nodes named “rsAov_PuzzleMatte” To see if the appropriate value and number already exists

Parameters:
  • colorStr (str) – “Red”, “Green”, “Blue” or “Black”

  • imageNumber (int) – the image number starts at 0

Return returnState:

1 means found, 2 means color is not R G or B, 3 means it wasn’t found, 4 the matte is black

Rtype returnState:

int

setMatteSG(shaderGroup, matteColor, imageNumber)

Sets a matte in Redshift, assumes all nodes are called something like “rsAov_PuzzleMatte” so can break, this is the default in Redshift assumes names like “rsAov_PuzzleMatte”, “rsAov_PuzzleMatte001”, “rsAov_PuzzleMatte002”

Parameters:
  • shaderGroup (str) – the name of the shading group

  • matteColor (tuple) – color in srgb (0,0,1)

  • imageNumber (int) – the image number starts at 0

setMatteSelected(matteColor, imageNumber)
Parameters:
  • matteColor

  • imageNumber (int) – the image number starts at 0

Returns:

Return type:

Redshiftdisplacement

createDisplacementNodes(nodeList, imagePath='', displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1, bounds=1.0)

Creates a displacement setup for Redshift Builds the shader node networks and changes the Redshift mesh attributes too Shading Group and Mesh selection is automatic nodeList can be any selection type related to a shader. eg mesh, transform, shader or shading group

Parameters:
  • nodeList (list) – list of nodes names that could be or are related to the shading group

  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

  • autoBump (bool) – enable the autoBump checkbox?

  • maxDivisions (int) – The maximum divisions of the displacement

  • scaleMultiplier (float) – Multiplies the intensity of the displacement by this amount

  • bounds (float) – The clipping bounds, usually set low on displacement in Redshift is “Maximum Displacement”

Return shadingGroupList:

list of the shading groups names that now have displacement nodes

Rtype shadingGroupList:

list

Return fileNodeList:

list of the fileNodes (texture) names that have been created

Rtype fileNodeList:

list

Return place2dTextureNodeList:

list of the place2dTextureNode names that have been created

Rtype place2dTextureNodeList:

list

createDisplacementNodesSelected(displacementType='VDM', tangentType='tangent', autoBump=False, maxDivisions=5, scaleMultiplier=1, bounds=1.0)

Creates a displacement setup for Redshift from a selection Will build the node networks and change the mesh attributes too the selection can be any selection type related to a shaders, meshes, transforms, shaders or shading groups

Parameters:
  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

Return meshList:

list of the mesh names that now have displacement nodes

Rtype meshList:

list

Return shadingGroupList:

list of the shading groups names that now have displacement nodes

Rtype shadingGroupList:

list

Return fileNodeList:

list of the fileNodes (texture) names that have been created

Rtype fileNodeList:

list

Return place2dTextureNodeList:

list of the place2dTextureNode names that have been created

Rtype place2dTextureNodeList:

list

deleteDisplacementNodes(meshList, fileNodeList, place2dTextureNodeList)

Deletes a displacement setup for Redshift

Deletes the displacement nodes and resets the mesh subdivision attributes to be off

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

getDisplacementAttrValues(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode)

Retrieves the main attribute values of the displacement setup, usually for the UI

TODO: could export with a dictionary would be cleaner

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • shadingGroupList (list(str)) – List of shading group names

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

  • displaceNode (str) – the Arnold displacement node type “displacementShader”

Return dtype:

displacement type “Tangent” or “Object”

Rtype dtype:

str

Return divisions:

The amount of displacment divisions

Rtype divisions:

int

Return scale:

The scale of the displacement

Rtype scale:

float

Return autoBump:

Is the autobump on or off?

Rtype autoBump:

bool

Return image:

The full image file path

Rtype image:

str

Return bounds:

The clipping bounds of the displacement

Rtype bounds:

setDisplacementAttrValues(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode, attrDict, message=False)

Sets the attributes for the vector displacement setup

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • shadingGroupList (list(str)) – List of shading group names

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

  • displaceNode (str) – the Arnold displacement node type “displacementShader”

  • attrDict (dict) – The dictionary with values to set, see shdmulticonstants.py for a list of keys

  • message (bool) – report the message to the user?

updateMeshes(newConnectionsList, breakConnectionsList, displacementAttrDict, enabled)

When a new mesh is connected, update the mesh to match the settings of the shader displacement

Parameters:
  • newConnectionsList (list(str)) – A list of Maya meshes to update, these are new connections

  • breakConnectionsList (list(str)) – A list of Maya meshes to update, these are no longer part of the network

  • displacementAttrDict (dict()) – Dictionary with displacement attr values see keys DISP_ATTR in shdmulticonstants.py

  • enabled (bool) – Is the displacement enabled?

setEnabled(meshList, enableValue=True)

Sets the enable state of the entire displacement network

In Redshift just use rsEnableSubdivision on each mesh

Parameters:
  • meshList (list(str)) – A list of mesh names

  • enableValue (nool) – Enable True or disable False

getEnabled(meshList)

Gets the enable state of the entire displacement network

In Redshift just query rsEnableSubdivision on each mesh

Parameters:

meshList (list(str)) – A list of mesh names

Return enableValue:

Enable True or disable False

Rtype enableValue:

bool

Redshiftshaders

Redshift related shader functions

loadRedshift()

Loads the Redshift renderer

createRedshiftMaterial(shaderName='shader_RS', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a RedshiftMaterial shader.

Parameters:
  • shaderName (str) – The name of the RedshiftMaterial shader in Maya to be created

  • specWeight (bool) – If True the specular weight is set to 0 (off)

  • message (bool) – If on will return the create message to Maya

Returns:

The name of the newly created redshift material

Type:

str

createRedshiftMatteShadowCatcher(shaderName='shadowMatte_RS', message=True)

Creates a RedshiftMatteShadowCatcher Shader In Maya.

Shadow mattes are for shadows only and or reflections, usually for compositing.

Parameters:
  • shaderName (str) – The name of the RedshiftMatteShadowCatcher shader in Maya to be created

  • message (bool) – If on will return the create message to Maya

Returns:

The name of the newly created RedshiftMatteShadowCatcher shader

Type:

str

assignNewRedshiftMaterial(objList, shaderName='shader_RS', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5), selectShader=True)

Creates a RedshiftMaterial Shader and assigns it to the objList.

If None will just create the shader.

Parameters:
  • objList – List of object names, transform nodes.

  • shaderName (str) – The name of the RedshiftMaterial shader in Maya to be created

  • specWeight (bool) – If True the specular weight is set to 0 (off)

  • message (bool) – If on will return the create message to Maya

Returns:

The name of the RedshiftMaterial shader in Maya that was created

Type:

str

assignNewRedshiftMatteShadowCatcher(objList, shaderName='shadowMatte_RS', message=True, selectShader=True)

Creates a RedshiftMatteShadowCatcher Shader and assigns it to the objList.

Shadow mattes are for shadows only and or reflections, usually for compositing.

Parameters:
  • objList – List of object names, transform nodes.

  • shaderName (str) – The name of the RedshiftMatteShadowCatcher shader in Maya to be created

  • message (bool) – If on will return the create message to Maya

Returns:

The name of the RedshiftMatteShadowCatcher shader in Maya that was created

Type:

str

assignSelectedNewRedshiftMaterial(shaderName='shader_RS', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a RedshiftMaterial Shader and assigns it to the current selection

Parameters:
  • shaderName (str) – The name of the RedshiftMaterial shader in Maya to be created.

  • specWeight (bool) – If True the specular weight is set to 0 (off).

  • message (bool) – If on will return the create message to Maya.

Returns:

The name of the redshift shader in Maya that was created.

Type:

str

assignSelectedNewRedshiftMatteShadowCatcher(shaderName='shadowMatte_RS', message=True)

Creates a RedshiftMatteShadowCatcher Shader and assigns it to the current selection Shadow mattes are for shadows only and or reflections, usually for comping

Parameters:
  • shaderName (str) – The name of the RedshiftMatteShadowCatcher shader in Maya to be created.

  • message (bool) – If on will return the create message to Maya.

Returns:

The name of the newly created RedshiftMatteShadowCatcher shader.

Type:

str

Rendermanaovs

Renderman AOV matte related, Renderman has changed and supports RGB mattes differently now.

import rfm2
pdict = {'name': 'MatteID1', 'label': 'MatteID1',
         'type': 'color', 'default': (1, 0, 0),
         'connectable': False}
rfm2.ui.user_attrs.user_attrs_add('rman_userAttrs', ['nurbsSphere1'], pdict)
createPxrMatteID(textureName='PxrMatteID', matteNumber=0, message=True)

Creates a PxrMatteID Texture in Maya, these are used for RGBA Mattes (AOVs)

Parameters:
  • textureName – The name of the pxrMatteID node in Maya to be created

  • message (bool) – If on will return the create message to Maya

Return pxrMatteID:

The name of the pxrMatteID Node in Maya that was created

rmanCreateRenderSettingsMatteAOV(matteNumber)

Creates a Renderman Matte AOV in nodes, Render Settings will need to be reopened for settings to apply

If node setup already exists should bail

Annoying function possibly and easier way with rfm2 api

Parameters:

matteNumber (int) – The number of the image to create starts at 0

rmanAddAttrMatte(rendermanShader, matteNumber=0, matteColor=(1, 0, 0))

Creates an attribute for pxrMattes this defines the matte color on a shader

:param pxrSurfaceShader:The Shader name that the attr is added to :param matteNumber:The image number of the matte, starts at 0 :param matteColor:the color of the matte as a rgb tuple (1, 0, 0) is red :return:

getColorStringFromTuple(matteColor)

changes a tuple (0, 1, 1) into a string “green”

Parameters:

matteColor (tuple) – color as a tuple (0, 0, 1) is blue

Return colorString:

color as a string

Rtype colorString:

str

connectPxrMatteID(rendermanShader, pxrMatteID=None, matteNumber=0, matteColor=(1, 0, 0))

When a Shader is selected will create and connect the PxrMatteID for RGB Mattes (AOVs) Can pass in specific node names

need to check if object matte is already connected

connectPxrMatteIDSelected(matteNumber, matteColor, pxrMatteID=None)

From the selected shader/s or object transforms assign the matte color to be the given color by nodes.

Filters v21 Renderman Shaders only

Still needs to be able to reassign colors and image number if node already exists

Parameters:
  • matteNumber (int) – The number of the image starting at 0, mattes can be across more than one image.

  • matteColor (tuple) – The linear color of the matte as rgb tuple. Eg. (1.0, 0.0, 0.0) is red.

  • pxrMatteID (str) – The name of the incoming node assigned to the shader, it will be created if None.

Rendermandisplacement

createVectorDisplacement(shadingGroupList, imagePath='', tangentType='tangent', scaleMultiplier=1, message=True, selectFilenode=True)

Creates a vector displacement setup for Renderman on the given shading groups Builds the node networks required

Return shadingGroupList:

list of the shading groups names that now have displacement nodes

Rtype shadingGroupList:

list

Parameters:
  • imagePath (str) – Optional path of the image, can be left empty str “”

  • tangentType (str) – either “tangent” or “object”

  • scaleMultiplier (float) – the scale multiplier of the displacement

  • message (bool) – display messages for the user success warnings etc

  • selectFilenode (bool) – at the end of creation select the filenode for adding the texture?

Return pxrDisplaceList:

list of pxrDisplace nodes that were created

Rtype pxrDisplaceList:

list

Return PxrDisplaceTransformList:

list of PxrDisplaceTransform nodes that were created

Rtype PxrDisplaceTransformList:

list

Return PxrTextureList:

list of PxrTexture nodes that were created

Rtype PxrTextureList:

list

createDisplacement(nodeList, imagePath='', displacementType='VDM', tangentType='tangent', scaleMultiplier=1, bounds=0.1, selectFilenode=True)

Creates a displacement setup for Renderman Builds the shader node networks required Shading Group and Mesh selection is automatic nodeList can be any selection type related to a shader. eg mesh, transform, shader or shading group

Parameters:
  • nodeList (list) – list of nodes names that could be or are related to the shading group

  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

  • scaleMultiplier (float) – the scale multiplier of the displacement

  • bounds (float) – The scale of the displacement bounds, displacement setting that can cull objects if too low

  • selectFilenode (bool) – at the end of creation select the filenode for adding the texture?

createDisplacementSelected(imagePath='', displacementType='VDM', tangentType='tangent', scaleMultiplier=1, selectFilenode=True)

Creates a displacement setup for Renderman from a selection Builds the shader node networks required Shading Group and Mesh selection is automatic nodeList can be any selection type related to a shader. eg mesh, transform, shader or shading group

Parameters:
  • imagePath (str) – Optional path of the image, can be left empty str “”

  • displacementType (str) – either “VDM” (vector displacement map) or “height” (b&w)

  • tangentType (str) – either “tangent” or “object”

  • scaleMultiplier (float) – the scale multiplier of the displacement

  • selectFilenode (bool) – at the end of creation select the filenode for adding the texture?

deleteDisplacementNodes(meshList, fileNodeList, otherNodeList)

Deletes a displacement setup for Renderman

Deletes the displacement nodes and resets the mesh subdivision attributes to be off

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • fileNodeList (list(str)) – list of texture nodes, will be deleted

  • otherNodeList (list()) – list of other displacement nodes, will be deleted

getDisplacementAttrValues(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode)

Retrieves the main attribute values of the displacement setup, usually for the UI

Parameters:
  • meshList (list(str)) – The list of meshes affected by the displacement, subdivision will be turned off

  • fileNodeList (list(str)) – list of texture file nodes, will be deleted

  • place2dTextureNodeList (list()) – list of 2d place texture file nodes, will be deleted

  • displaceNode (str) – the Arnold displacement node type “displacementShader”

Returns:

Return type:

setDisplacementAttrValues(meshList, shadingGroupList, fileNodeList, place2dTextureNodeList, displaceNode, attrDict, message=False)
setEnabled(displaceNode, enableValue=True)

Sets the enable state of the entire displacement network

In Renderman use .enabled on the PxrDisplace node

Parameters:
  • displaceNode (str) – A PxrDisplace node

  • enableValue (bool) – Enable True or disable False

getEnabled(displaceNode)

Gets the enable state of the entire displacement network

In Renderman query .enabled on the PxrDisplace node

Parameters:

displaceNode (str) – A PxrDisplace node

Return enableValue:

Enable True or disable False

Rtype enableValue:

bool

Rendermanshaders

Renderman related shader functions

loadRenderman()

Loads Renderman

createPxrSurface(shaderName='shader_PXR', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a PxrSurface Shader In Maya

:param shaderName:The name of the pxr shader in Maya to be created :type shaderName:str :param message:If on will return the create message to Maya :type message:bool :return:The name of the pxr shader in Maya that was created :type message:str (possibly unicode)

assignNewPxrSurface(objList, shaderName='shader_PXR', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5), selectShader=True)

Creates a PxrSurface Shader and assigns it to the objList.

Parameters:
  • objList – List of object names

  • shaderName (str) – The name of the PxrSurface shader in Maya to be created

  • specOff (bool) – If True the specular weight is set to 0 (off)

  • message (bool) – If on will return the create message to Maya

Returns:

The name of the RedshiftMaterial shader in Maya that was created

Type:

str

assignSelectedNewPxrSurface(shaderName='shader_PXR', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a PxrSurface Shader and assigns it to the current selection

:param shaderName:The name of the pxr shader in Maya to be created :type shaderName:str :param specWeight: The weight of the specular layer (not working) :type specWeight: float :param rgbColor: The initial color fo the shader (not working) :type rgbColor: list() :param message: Report message to the user? :type message: bool :return shaderName: The name of the shader :type shaderName: str

createPxrLayerSurface(shaderName='shader_PXR', specWeight=0.0, rgbColor=(0.5, 0.5, 0.5), message=True)

Creates a PXR Layer Surface shader, a layered shader, returns all nodes.

:param shaderName:The name of the pxr shader in Maya to be created :type shaderName:str :param specWeight: The weight of the specular layer (not working) :type specWeight: float :param rgbColor: The initial color fo the shader (not working) :type rgbColor: list() :param message: Report message to the user? :type message: bool :return shader: The name of the shader :type shader: str :return layerMixer: The name the mixer node :type layerMixer: str :return layer1: The name layer 1 node :type layer1: str :return layer2: The name layer 2 node :type layer2: str

setShadowHoldout(objList, message=True)

Creates a shadow holdout (shadow matte) for the selected objects. In Renderman the mesh attribute Mesh Shape > Render Stats > Hold-Out is ticked to be on. Renderman will Render the shader as per usual but it will be invisible. So the reflective properties of the object/s are set via their shaders.

Parameters:
  • objList – List of object names

  • message (bool) – If on will return the create message to Maya

Return objList:

Rtype objList:

setSelectedShadowHoldout(message=True)

Creates a shadow holdout (shadow matte) for the selected objects. In Renderman the mesh attribute Mesh Shape > Render Stats > Hold-Out is ticked to be on. Renderman will Render the shader as per usual but it will be invisible. So the reflective properties of the object/s are set via their shaders.

:param message:If on will return the create message to Maya :type message: bool :return selObjs: the objects set to holdout on :rtype selObjs: list

Shadermulti

The new shadermultirenderer, will take over from shader multi renderer

Use this module to access shaders without knowing their renderer or shader type.

Example use:

from zoo.libs.maya.cmds.shaders import shadermulti
shaderInstances = shadermulti.shaderInstancesFromSelected()

from zoo.libs.maya.cmds.shaders import shadermulti
shaderInstances = shadermulti.shaderInstanceFromShader("shaderName")

Author: Andrew Silke

removeShaderSuffix(shaderName)

removes a shader suffix of a shadername. Iterates through suffixes in the dictionary shdcn.SHADERTYPE_SUFFIX_DICT Does not rename an object, just a string operation.

Supports suffixes in shdcn.SHADERTYPE_SUFFIX_DICT

Parameters:

shaderName (str) – The name of a shader

Return shaderNoSuffix:

The name with the suffix potentially removed

Rtype shaderNoSuffix:

str

emptyInstance(shaderName='')

Creates an empty shader instance for use when no shader is selected

shaderInstance(shaderType, shaderName='', create=False, ingest=True, suffixName=False)

Creates or ingests (loads) a shader instance of a specific shader type.

Supports shdcn.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

Parameters:
  • shaderType (str) – The type of shader to create eg “aiStandardSurface” see shdcn.SHADERTYPE_SUFFIX_DICT

  • shaderName (str) – The name of the shader to create

  • suffixName (bool) – Add an autosuffix for the shader name? Example shader_STRD

  • create (bool) – True if creating a new shader, False if using an existing shader

  • ingest (bool) – False if creating a new shader, True if using an existing shader

Return shaderInstance:

A zoo shader instance of the specified shader

Rtype shaderInstance:

shaderbase.ShaderBase

shaderInstanceFromShader(shaderName, suffixName=False)

Loads a shader instance from an existing shader. Auto detects the shader type.

Supports shdcn.SHADER_TYPE_LIST:

“standardSurface” “lambert”, “blinn”, “phong”, “phongE”, “aiStandardSurface”, “VRayMtl”, “RedshiftMaterial”, “PxrSurface”

if no shader exists then returns None

Parameters:
  • shaderName (str) – The name of the shader

  • suffixName (bool) – Add an autosuffix for the shader name? Example shader_STRD

Return shaderInstance:

A zoo shader instance of the specified shader, None if the shader does not exist

Rtype shaderInstance:

shaderbase.ShaderBase

createShaderInstanceType(shaderType, shaderName='', suffixName=False)

Creates a new shader of shader type with a shader name and returns the shader instance.

Parameters:
  • shaderType (str) – The type of shader to create eg “aiStandardSurface” see shdcn.SHADERTYPE_SUFFIX_DICT

  • shaderName (str) – The name of the shader

  • suffixName (bool) – Add an autosuffix for the shader name? Example shader_STRD

Return shaderInstance:

A zoo shader instance of the specified shader

Rtype shaderInstance:

shaderbase.ShaderBase

createAssignShdInstType(shaderType, shaderName='', suffixName=False)

Creates and assigns a new shader to sel geo. From shader type with a shader name and returns a shader instance.

Parameters:
  • shaderType (str) – The type of shader to create eg “aiStandardSurface” see shdcn.SHADERTYPE_SUFFIX_DICT

  • shaderName (str) – The optional name of the shader

  • suffixName (bool) – Add an autosuffix for the shader name? Example shader_STRD

Return shaderInstance:

A zoo shader instance of the specified shader

Rtype shaderInstance:

shaderbase.ShaderBase

createDefaultShadRenderer(renderer, shaderName='', suffixName=False, assignGeo=True, message=False)

Creates a default shader of the current renderer type

Parameters:
  • renderer (str) – The render nice name “Arnold” “Redshift” etc.

  • shaderName (str) – The name of the shader, if “” will be a default shader name

  • suffixName (bool) – Add an autosuffix for the shader name? Example shader_STRD

  • assignGeo (bool) – Will assign to currently selected geo if Ture

  • message (bool) – Report a message to the user?

Return shaderInstance:

A zoo shader instance of the specified shader

Rtype shaderInstance:

shaderbase.ShaderBase

createDefaultShadRendererAuto(shaderName='', suffixName=False, assignGeo=True, message=False)

Creates a default shader and assigns to geo of the currently loaded renderer in Zoo Tools Pro

multirenderersettings.currentRenderer()

Parameters:
  • shaderName (str) – The name of the shader, if “” will be a default shader name

  • suffixName (bool) – Add an autosuffix for the shader name? Example shader_STRD

  • assignGeo (bool) – Will assign to currently selected geo if Ture

  • message (bool) – Report a message to the user?

Return shaderInstance:

A zoo shader instance of the specified shader

Rtype shaderInstance:

shaderbase.ShaderBase

shaderInstancesFromNodes(nodes)

From shaders geometry or shading groups return a list of associated zoo shader instances

Parameters:

nodes (list(str)) – Maya nodes, geometry, shaders or shading groups

Return shaderInstances:

A list of zoo shader instances

Rtype shaderInstances:

list(shaderbase.ShaderBase)

shaderInstancesFromSelected(message=True)

From selected shaders geometry or shading groups return a list of associated zoo shader instances

Parameters:

message (bool) – Report warnings to the user?

Return shaderInstances:

A list of zoo shader instances

Rtype shaderInstances:

list(shaderbase.ShaderBase)

getShadersSceneShaderType(shaderType)
getShaderType(shader)
assignValuesSelected(shaderDict, noneIsDefault=False, message=True)
Parameters:
  • shaderDict (dict()) – Generic shader dictionary with values.

  • noneIsDefault (bool) – Will apply defaults if the value of the key is None or doesn’t exist

  • message (bool) – Report a message to the user?

Return dictApplied:

Was the dictionary values applied?

Rtype dictApplied:

bool

copyShaderSelected(message=True)

Copies a shaders name and zoo supported attributes to a singleton class:

shaderTrackerInst = shaderutils.ZooShaderTrackerSingleton()

Supports both selected shader and objects. Finds the first instance and uses it to extract the name and values.

Parameters:

message (bool) – Report a message to the user?

Return shaderData:

A shader dictionary with values and a shader name.

Rtype shaderData:

tuple(dict, str)

pasteShaderSelected(message=True)

Pastes a shader from the shader name, the shader name must exist in the scene.

Uses the shader tracker singleton class to paste from:

shaderTrackerInst = shaderutils.ZooShaderTrackerSingleton()

Existing shader assignments are replaced.

Parameters:

message (bool) – Report a message to the user?

Return shaderName:

The name of a shader

Rtype shaderName:

str

pasteShaderAttrsSelected(message=True)

Pastes shader data onto the currently selected shaders. Shader data is from a dictionary with zoo supported attributes. Shaders remain with tweaked values.

Uses the shader tracker singleton class to paste from:

shaderTrackerInst = shaderutils.ZooShaderTrackerSingleton()

Parameters:

message (bool) – Report a message to the user?

Return shaderInstances:

A list of shader instances with new values.

Rtype shaderInstances:

list(shaderbase.ShaderBase)

Shadermultirenderer

getShadersSceneRenderer(rendererNiceName)

Returns all shaders in a scene of the renderer, only supported shaders as per RENDERERSHADERS

Parameters:

rendererNiceName (str) – the nice name of the renderer

Return shaderList:

A list of shaders of the renderer type

Rtype shaderList:

list(str)

getShadersSceneShaderType(shaderType)
getRendererFromShaderType(shaderType)

given an Shader Type return the nice name of the renderer

Parameters:

shaderType (str) – the type of the shader eg “PxrSurface”

Return renderer:

Nice name of the supported renderer

Rtype renderer:

str

listCompatibleShaders()

returns a list of all the compatible shader types, “RedshiftMaterial”, “PxrSurface” etc

Return compatibleShaderList:

shader node type names

Rtype compatibleShaderList:

list

getAllSupportedRenderers()

returns all supported renderers in order from the RENDERERSHADERS dict

getAllSupportedShaders(newShaders=False)

returns all the supported shader types in order from the RENDERERSHADERS dict

if oldstyle shaders use RENDERERSHADERS:

[“RedshiftMaterial”, “PxrSurface”, “PxrLayeredSurface”, “aiStandardSurface”]

if newShaders use SHADER_TYPE_LIST:
[STANDARD_SURFACE, LAMBERT, BLINN, PHONG, PHONGE, AI_STANDARD_SURFACE, VRAY_MTL,

REDSHIFT_MATERIAL, PXR_SURFACE]

Parameters:

newShaders (bool) – if style is new shaders use the SHADER_TYPE_LIST with more shader types

Return allShadersList:

A list of all the supported shader types

Rtype allShadersList:

list(str)

testIfSupportedShader(shader, newShaders=False)

Tests to see if the shader is supported

Parameters:

shader (str) – a shader name

Return isSupported:

The node type of the shader if it’s supported, None if not supported

Rtype isSupported:

bool

autoTypeShader(rendererNiceName)

Returns the most common uber shader from a given renderer nice name

Parameters:

rendererNiceName (str) – the nice name of the renderer

Return shaderType:

the type of the shader node

Rtype shaderType:

str

convertShaderDictToLinearColor(shaderDict)

Converts a shader dict (not nested) to linear color by finding attributes with suffixes “_srgb” and converting those

Parameters:
  • shaderDict (dict) – a dict of shader attributes with generic shader attributes as keys, not a nested dict

  • shaderDict – shader attributes now with srgb colors converted to linear

convertPresetShadersDictToLinear(presetShadersDict)

Converts a presetShaderDict (generic preset shader info) to be in linear color by finding attributes with suffixes “_srgb” and converting those

Parameters:

presetShadersDict (dict) – nested dictionary of preset generic shader info (maya attr)

Return presetShadersDict:

preset generic shader info now in linear color

Rtype presetShadersDict:

dict

getShaderDict(filename='shaderpresets_ior.json', convertSrgbToLinear=True)

Loads the .json file of the shader presets

Parameters:

filename (str) – the name of the json file, filename only, should be in same directory as this file

Return presetShaderDict:

The .json file as a python dict

Rtype presetShaderDict:

dict

getShaderPresetNamesList(presetShadersDict, firstInList='Matte Grey')

retrieves the Preset Shader names in alphabetical order [“Copper”, “Car Paint Blue”, “Car Paint Red”] First in list must exist in the list or it will fail

Parameters:
  • presetShadersDict (dict) – nested dictionary of preset generic shader info (maya attr)

  • firstInList (bool) – if exists chooses this value at the top of the list, if empty or none no changes will be made

Return presetShadersList:

list of shaders in alphabetical order

Rtype presetShadersList:

list

redshiftMaterialAttributes()

attribute conversion names for RedshiftMaterial Shader

Return shaderDict:

redshiftMaterialAttributes dictionary

Rtype shaderDict:

dict

aiStandardSurfaceAttributes()

attribute conversion names for aiStandardSurface Shader

Return shaderDict:

aiStandardSurface dictionary

Rtype shaderDict:

dict

pxrSurfaceAttributes()

attribute conversion names for PxrSurface Shader

Return shaderDict:

PxrSurface dictionary

Rtype shaderDict:

dict

pxrSurfaceFixAttrValues(shaderDict)

this function fixes the pxrSurface attributes while applying as it is missing the spec and coat weights, and the default mode is in artistic not physical for spec and coat Some math has to be done in srgb color, incoming is in linear and outgoing too

Parameters:
  • shaderDict (dict) – a dict of shader attributes with generic shader attributes as keys, not a nested dict

  • shaderDict – a dict of shader attributes with generic shader attributes as keys, not a nested dict

aiSurfaceStandardFixAttrValues(shaderDict)

Fixes the aiSurfaceStandard as the color is always white, no matter so should be used on the weight

Newer versions of Arnold are no better, tried using the if and else on Arnold version but it’s still wrong.

legacy code:

mtoaMajorVersion = arnoldshaders.mtoaVersionNumber()[0]
if mtoaMajorVersion < 4:

convert color to hsv

Parameters:
  • shaderDict (dict) – a dict of shader attributes with generic shader attributes as keys, not a nested dict

  • shaderDict – a dict of shader attributes with generic shader attributes as keys, not a nested dict

getShadersSelectedRenderer(renderer, reportSelError=False)

Returns all shaders associated with the selection and then filters them by the given Renderer

Parameters:
  • renderer (str) – “Arnold”, “Redshift” or “Renderman”

  • reportSelError (bool) – Give a message if there are issues to the user

Return shaderList:

Shaders related to selected object of the rendertype from RENDERERSHADERS dict

Rtype shaderList:

list(str)

getFirstSupportedShaderSelected(reportSelError=False, newShaders=False, message=True)

Find a the first supported shader from selected

Parameters:
  • reportSelError (bool) – Report selection issues to the user

  • message (bool) – report messages to the user?

Return shaderName:

the name of the first found shader

Rtype shaderName:

str

Return shaderType:

the Maya type of the first found shader

Rtype shaderType:

str

buildNameWithSuffix(shaderName, suffix, renderer)

Returns the shader name given the name without a suffix, the suffix bool (checkbox) and the renderer

Parameters:
  • shaderName (str) – The name of the shader without it’s suffix

  • suffix (bool) – Is there a suffix or not?

  • renderer (str) – The nice name of the renderer

Return fullShaderName:

The full shader name with suffix if the suffix = True

Rtype fullShaderName:

str

supportedShaderType(shader, message=True)

Get the supported shader type, None if it is not supported.

Parameters:
  • shader (str) – The name of a shader that exists in Maya

  • message (bool) – report messages to the user

Return shaderType:

The node type of the shader if supported, None if not supported.

Rtype shaderType:

str

renameShaderUniqueSuffix(oldName, newName, message=True)

renames a shader and auto adds the appropriate suffix

Parameters:
  • oldName (str) – the old/current shader name

  • newName (str) – the new name without a suffix

  • message (bool) – shows the result message to the user

Return shaderNewName:

the shader’s new name, shader has been renamed to this

Rtype shaderNewName:

str

getShaderAttributesDict(shaderType)

Returns the shader attributes of a given shader type. Shader type will be important when multi shader support.

Parameters:

shaderType (str) – The type of shader redshiftMaterial, PxrSurface etc

Return attrDict:

the attributes with conversions types as a dictionary

Rtype attrDict:

dict

getShaderPresetShaders(shaderType, convertSrgbToLinear=True)

Given a shader type will return the shaderDict (from .json file) now with all the attributes renamed to suit the current shader type ie. RedshiftMaterial diffuseColor attribute becomes, diffuse_color

Parameters:

shaderType (str) – The type of shader RedshiftMaterial, PxrSurface etc

Returns:

the shaderDict now with new attribute keys to match the current shader

Return type:

dict

setPresetShaderAttrs(shaderName, presetShaderName, shaderType)

Will set the maya shader’s attributes to the preset type shader type must be given and attributes will be converted “shader1”, “Gold”, “PxrSurface”

Parameters:
  • shaderName (str) – The maya name of the shader, could be any user defined name

  • presetShaderName (str) – the key name of the shader preset Gold Matte Grey

  • shaderType (str) – the type of shader, RedshiftMaterial PxrSurface alStandardSurface etc

setShaderAttrs(shaderName, shaderType, shaderDict, convertSrgbToLinear=True, reportMessage=True)

Will set the maya shader’s attributes to the preset type, this is from a single shader input not presets

Parameters:
  • shaderName (str) – The maya name of the shader, could be any user defined name

  • shaderType (str) – the type of shader, RedshiftMaterial pxrSurface alStandardSurface etc

  • shaderDict (dict) – a dict of shader attributes with generic shader attributes as keys, not a nested dict

  • reportMessage (bool) – report the success message or hid it?

createShaderTypeObjList(shaderType, objList=None, shaderName='shader', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a shader give the type, supports main monolithic shaders in Redshift, Arnold and Renderman Assigns to an object list if it exists

Parameters:
  • shaderType (str) – the type of shader, RedshiftMaterial PxrSurface alStandardSurface etc

  • objList (list()) – list to assign the shader to, can be None

  • shaderName (str) – The maya name of the shader, could be any user defined name

  • specWeight (float) – the default specular weight

  • message (bool) – return the messages to the user

  • rgbColor (tuple) – the diffuse color of the shader

Return shaderName:

the shader name created

Rtype shaderName:

str

createShaderTypeSelected(shaderType, shaderName='shader', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a shader give the type, supports main monolithic shaders in Redshift, Arnold and Renderman

Parameters:
  • shaderType (str) – the type of shader, RedshiftMaterial PxrSurface alStandardSurface etc

  • shaderName (str) – The maya name of the shader, could be any user defined name

  • specWeight (float) – the default specular weight

  • message (bool) – return the messages to the user

  • rgbColor (tuple) – the diffuse color of the shader

Return shaderName:

the shader name created

Rtype shaderName:

str

createShaderType(shaderType, shaderName='shader', specWeight=0.0, message=True, rgbColor=(0.5, 0.5, 0.5))

Creates a shader of the given type

Parameters:
  • shaderType (str) – the type of shader, RedshiftMaterial PxrSurface alStandardSurface etc

  • shaderName (str) – The maya name of the shader, could be any user defined name

  • specWeight (float) – the default specular weight

  • message (bool) – return the messages to the user

  • rgbColor (tuple) – the diffuse color of the shader

Return shaderName:

The maya name of the shader, could be any user defined name

Rtype shaderName:

str

checkShaderRendererMatch(shader, renderer)

checks the shader type and current renderer match, returns True if match, False if not a match

Used in UIs to check is correct

Parameters:
  • shader (str) – shader name

  • renderer (str) – renderer name

Returns:

Match, True if the shader is of the renderer type

Return type:

bool

getShaderTexturedAttrs(shader, renderer)

Returns a list of attributes that have incoming source connections, usually textures.

Attributes are generic attributes and not the shader’s attributes

Parameters:

shader (str) – The shader node name

Return genericKeyList:

A list of generic attributes that have incoming source connections

Rtype genericKeyList:

list(str)

getTexturedInfo(shader, renderer)

Creates a dictionary with texture information. Used by convert renderer to rehook textures

Example:

{“gDiffuseColor_srgb”: “fileTexture01.outColor”, “gSpecRoughness”: “fileTexture02.outAlpha”}

No textures will be an empty dict.

Parameters:
  • shader (str) – A maya shader node

  • renderer (str) – Renderer name

Return shaderTextureDict:

Dictionary with generic attributes as keys and “node.attribute” as values

Rtype shaderTextureDict:

getShaderAttributes(shader)

Pulls shader attributes from the given shader and enters them into a generic attributes dict

Note: Querying textured attributes returns either black or zero, may have to handle later

Parameters:

shader (str) – The shader name

Return attributesDict:

dictionary of generic shader attributes correctly converted

Rtype attributesDict:

dict()

getShaderSelected(reportNoneFoundError=False, newShaders=False, shaderName='')

Pulls shader attributes from the given selection and enters them into a generic attributes dict will cycle through a list returning one shader, the first legitimate type found

Parameters:
  • reportNoneFoundError (bool) – Report none found to the user

  • shaderName (bool) – Return this if it’s in the scene and nothing else was found

Return attributesDict:

dictionary of generic shader attributes correctly converted

Rtype attributesDict:

dict

getShaderList(shaderList)

From a shader list pull the shader attributes into a dictionary of attributes Returns a nested dict with each key the shader name

Parameters:

shaderList (list) – a list of shader names, should be in scen no error checking

Return shaderListAttributesDict:

a nested dictionary of the shader name, then the dict of generic attribute values

Rtype shaderListAttributesDict:

dict

getShaderObjectAssignDict(shader, removeSuffix=True)

Pulls nested dict with the shader information as a generic dict, shadername, and object/face assignements

Parameters:

shader (str) – Maya shader name

Return shaderObjAssignDict:

dict containing shader info such as the attributesDict, shader name and obj assignments

Rtype shaderObjAssignDict:

getMultiShaderObjAssignDict(shaderList, removeSuffix=True)

Returns a multi shader dict, keys are the shader names, contents are nested dicts with attribute, name and object/face assignment details

Parameters:

shaderList (list) – a list of Maya shader names

Return multiShaderGenericDict:

keys are the shader names, with attribute, name and object/face assignment details

Rtype multiShaderGenericDict:

dict

getMultiShaderObjAssignDictSelected(removeSuffix=True)

Returns a multi shader dict, from selected objects/shaders keys are the shader names, contents are nested dicts with attribute, name and object/face assignment details

Return multiShaderGenericDict:

keys are the shader names, with attribute, name and object/face assignment details

Rtype multiShaderGenericDict:

dict

getMultiShaderObjAssignDictScene(removeSuffix=True, checkNonUnique=False)

Returns a multi shader dict, from scene, currently mesh objects only keys are the shader names, contents are nested dicts with attribute, name and object/face assignment details

Return multiShaderGenericDict:

keys are the shader names, with attribute, name and object/face assignment details

Rtype multiShaderGenericDict:

dict

createApplyShaderWithDict(shaderName, genericShaderDict, rendererNiceName, addSuffix=True, overwrite=True)

Creates shaders if they don’t already exist If shader exists and overwrite is on delete the old shader, if overwite is off then add a suffix to the new shader so there are no conflicts

Parameters:
  • shaderName (str) – The name of the shader, usually without a suffix

  • genericShaderDict (dict) – generic shader dictionary with attribute settings only

  • rendererNiceName (str) – the nice name of the renderer

  • addSuffix (bool) – add a suffix to the shader name or the renderer type

  • overwrite (bool) – delete the shader if it exists or keep it and apply the attribute settings?

Return shaderName:

the name of the shader

Rtype shaderName:

str

createShaderApplyToObjFace(shaderName, genericShaderDict, objFace, rendererNiceName, addSuffix=True, overwrite=True)

Creates a shader and applies it to an object/face list will overwite existing shaders if overwite is on, if off will use existing shaders can add suffix of the renderer type

Parameters:
  • shaderName (str) – The name of the shader, usually without a suffix

  • genericShaderDict (dict) – generic shader dictionary with attribute settings only

  • objFace (list) – a list of polygon objects and faces in Maya format that it uses to make selections

  • rendererNiceName (str) – renderer nice name “Arnold”, “Renderman”, “Redshift”

  • addSuffix (bool) – add a suffix to the shader name or the renderer type

  • overwrite (bool) – delete the shader if it exists or keep it and apply the attribute settings?

createShaderApplyToObjFaceCheck(shaderName, genericShaderDict, objFace, rendererNiceName, addSuffix=True, overwrite=True)

Creates a shader and check if obj exists and if so applies it the object/face list will overwite existing shaders if overwite is on, if off will use existing shaders can add suffix of the renderer type

Parameters:
  • shaderName (str) – The name of the shader, usually without a suffix

  • genericShaderDict (dict) – generic shader dictionary with attribute settings only

  • objFace (list) – a list of polygon objects and faces in Maya format that it uses to make selections

  • rendererNiceName (str) – renderer nice name “Arnold”, “Renderman”, “Redshift”

  • addSuffix (bool) – add a suffix to the shader name or the renderer type

  • overwrite (bool) – delete the shader if it exists or keep it and apply the attribute settings?

applyMultiShaderDictObjAssign(multiShaderGenericDict, rendererNiceName, addSuffix=True, overwrite=True)

Apples a multiShaderGenericDict, by creating the shader if it doesn’t exist and assigning to the objects/faces will overwite existing shaders if overwite is on, if off will rename the incoming shaders to have a unique prefix can add suffix of the renderer type

Parameters:
  • multiShaderGenericDict (dict) – keys are the shader names, with attribute, name and object/face assignment details

  • rendererNiceName (str) – renderer nice name “Arnold”, “Renderman”, “Redshift”

  • addSuffix (bool) – add a suffix to the shader name or the renderer type

  • overwrite (bool) – delete the shader if it exists or keep it and apply the attribute settings?

Return shaderList:

list of shaders

Rtype shaderList:

list

deleteShader(shaderName, checkValid=True, deleteShaderNetwork=True, message=False)

Deletes a compatible shader from the Maya scene

Parameters:
  • shaderName (str) – The name of a Maya supported shader

  • shaderName – The name of a Maya supported shader

  • shaderName – The name of a Maya supported shader

  • deleteShaderNetwork (bool) – Delete all texture nodes etc connected to the shader

deleteShadersDict(rendererNiceName, shaderDict, deleteNetwork=True)

Deletes all shaders and shading groups from a shader dict, can also delete the entire network (default True)

Parameters:
  • rendererNiceName (str) – the name of the renderer to delete from “Arnold”

  • shaderDict (dict) – The shader dictionary with shader names as keys

  • deleteNetwork (dict) – Delete the entire shading network? Or just the shader and shading group?

createMatteAOVRenderer(rendererNiceName, matteColor, imageNumber)

Given a renderer nice name, create an AOV rgb matte supports “Arnold”, “Renderman”, “Redshift”

Parameters:
  • renderer (str) – renderer nice name “Arnold”, “Renderman”, “Redshift”

  • matteColor (tuple) – color of the matte, certain renderers only do pure r g b. In 0-1 values (0.0, 0.0, 1.0)

  • imageNumber (int) – the image number, each rgb only has 3 spots per image. Image numbering usually starts at 0

Return rendererFound:

was the renderer nice name in the list

Rtype rendererFound:

bool

Shaderpresets_ior

Sets the Default Presets for the shaderpresets_ior.json

Shaderutils

from zoo.libs.maya.cmds.shaders import shaderutils shaderutils.getAllShaders()

from zoo.libs.maya.cmds.shaders import shaderutils shaderutils.assignShader(objFaceList, shader)

importAndAssignShader(filePath, shaderName='', mayaFileType='mayaAscii')

Imports a maya file and finds the first shader of the current renderer and assigns it to the current selection

Parameters:
  • shaderName – It will attempt to import shader with the matching name.

  • filePath (str) – The file path of the maya file to be imported

  • mayaFileType (str) – The file type of the maya file “mayaAscii” or “mayaBinary”

Return newNodes:

A list of new nodes imported as string names

Rtype newNodes:

list(str)

Return firstShader:

The name of the first shader imported

Rtype firstShader:

str

class ImportAssignShader(filePath, shaderName='', mayaFileType='ma')

Bases: object

doIt()

Run the import and assign shader code

Returns:

stripNamespace(shader)
duplicateChoicePopup(newShader)

Choose one of the options

Parameters:

newShader

Returns:

cleanNamespaces()
reselectObjects()

Reselect original objects

Returns:

cleanImports()

Delete any of the imported data in the scene

Returns:

getShaderFromSG(shadingGroup)

Returns the main shader from a shading group, this assumes only one shader is related to the shadering group This will have to ignore extra shaders deeper in the node network if there are many nested/layered shaders

Parameters:

shadingGroup (str) – The name of the shading group

Return shader:

the shader name

Rtype shader:

str

getShadersFromSGList(shadingGroupSet)

Returns a list of shaders from a set of shading groups

Parameters:

shadingGroupSet (set) – set of shading group names

Return shaderList:

Rtype shaderList:

getShadingGroupFromShader(shader)

Returns the Shading Group from a shader

Parameters:

shader (string) – the shader name

Return shadingGroup:

the shading group node (can easily be None if not assigned)

Rtype shadingGroup:

str

getShadingGroupFromShaderList(shaderList)
getShadingGroupsFromObj(mayaObj)

Returns all the Shading Groups related to a mesh or nurbsSurface object

Parameters:

mayaObj (str) – A transform or shape node that is or has a “mesh” or “nurbsSurface” node

Return shadingGroupList:

list of shading group names

Rtype shadingGroupList:

list

getShadingGroupsObjList(nodeList)

Returns all the Shading Groups related to an object list

Note

Only supports geometry, does not support selected shaders etc

see function getShadingGroupsFromNodes() for all nodes

Parameters:

nodeList (list) – list of Maya Object names

Return shadingGroupList:

list of shading group names

Rtype shadingGroupList:

list

getShadersObjList(objList)

Gets a list of shader names related to a object list

Note

Only supports geometry, does not support selected shaders etc

see function getShadersFromNodes() for all nodes

Used for matte assignments only

Parameters:

objList (list) – List of Maya Objects as strings

Returns:

Return type:

list

getShadersSelected(reportMessage=True)

From selection return all related shaders as a list This includes shape nodes, transforms, shaders (will return themselves) and shadingGroups

Parameters:

reportMessage (bool) – report the message back to the user?

Return shaderList:

A list of shader names

Rtype shaderList:

list

getShaderWildcard(wildcardName)

Finds all shaders in a scene with the given suffix

Parameters:

wildcardName (str) – The suffix name

Return shaderList:

the shaders

Rtype shaderList:

list

getShadersShadeNode(shapeNode)

Get the related shaders connected to the given shapeNode

Parameters:

shapeNode (str) – name of the shape node

Return shaderList:

the shader names

Rtype shaderList:

list

getShadersShapeNodeList(shapeNodeList)

Returns the shaders attached to a list of shape nodes

Parameters:

shapeNodeList (str) – list of shape node names

Return shaderList:

the shader names

Rtype shaderList:

list

shaderAndAssignmentsFromObj(objTransform, message=True)

Returns a shader list and a selection list from the selected mesh object, can included face selection.

Assumes the transform only has one mesh shape node. Used in transferShaderTopology()

Example 1 return:

["redShadingGroup"]
[["|pSphere3"]]

Example 2 return:

["redShadingGroup", "blueShadingGroup]
[["|pSphere3.f[0:47]", "|pSphere3.f[101:222]"], ["|pSphere3.f[48:100]", "|pSphere3.f[223:228]"]]
Parameters:
  • objTransform (str) – Maya transform node name should have a mesh shape nodes as children (ie a mesh object)

  • message (bool) – Return messages to the user om2.MGlobal

Return shadingGroupList:

List of shading groups assigned to the object, can be multiple if face assigned

Rtype shadingGroupList:

list(str)

Return objectsFacesList:

List of shader assignments to this object, can be face assigned, see function description

Rtype objectsFacesList:

list(list(str))

transferShaderTopology(sourceObject, targetObject, ignoreTopologyMismatch=True, message=True)

Transfers shader/s from one object to another with matching topology, handles face assignment

Copies the shaders from the source object and copies them onto the target object

Objects must be transforms and can have “mesh” or “nurbsSurface” shapes

Todo

Nurbs does not support multiple shaders yet

Parameters:
  • sourceObject (str) – The source object name to copy the shader info from, should be a long name

  • targetObject (str) – The target object name to copy the shader info onto, should be a long name

  • ignoreTopologyMismatch (bool) – Ignores the topology difference and copies the first shader found

  • message (bool) – Return messages to the user om2.MGlobal

Returns:

True if the transfer succeeded via matching topology False if not

Return type:

bool

transferShaderTopologySelected(message=True)

Transfers shader/s from one object to another with matching topology, handles face assignment

The first object in the selection’s shader/s are copied to all other selected objects

Objects must be transforms and can have “mesh” or “nurbsSurface” shapes TODO: Nurbs does not support multiple shaders yet

Parameters:

message (bool) – Return messages to the user om2.MGlobal

getAllShadersAndObjectFaceAssigns(filterOnlyUsed=False, filterShaderType=None)

Gets all shaders, shading groups and their face assignments in the scene if filterOnlyUsed then return only those with scene assignments, ie not unused shaders

Parameters:

filterOnlyUsed (bool) – only return used shaders, shaders that contain assignments, obj or face etc

Return shaderList:

list of shader names

Rtype shaderList:

list

Return shadingGroupList:

list of shading group names

Rtype shadingGroupList:

list

Returns:

list of face/obj assignements

Return type:

list

getAllShaders()

return all shaders types that could be created in a scene

Returns:

list of shader names

Return type:

list

getObjectsFacesAssignedToSG(shadingGroup, longName=True)

gets objects and faces of the given shading group

Parameters:
  • shadingGroup (str) – the shading group name

  • longName (str) – return all longnames, will return only clashing nodes as long if false

Returns:

list of objects and faces as names with [1:233]

Return type:

list

getObjectsFacesAssignedToShader(shader, longName=True)

gets objects and faces of the given shader

Parameters:

shader (str) – the shader name

Returns:

list of objects and faces as names with [1:233]

Return type:

list

assignShadingGroup(objFaceList, shadingGroup)

Assigns the shader to an object/face list

Parameters:
  • objFaceList (list) – list of objects and faces for the assignment

  • shadingGroup (str) – the shading group name to assign

Returns:

the shading group name assigned

Return type:

str

assignShader(objFaceList, shader)

Assigns the shader to an object/face list

Parameters:
  • objFaceList (list) – list of objects and faces for the assignment

  • shader (str) – the shader name to assign

Returns:

the shading group name assigned

Return type:

str

assignShaderCheck(objFaceList, shader)

Assigns the shader to an object/face list, checks to see if the object exists before assigning

Parameters:
  • objFaceList (list) – list of objects and faces for the assignment

  • shader (str) – the shader name to assign

assignShaderSelected(shader)

Assigns the given shader to current selection

Parameters:

shader (str) – The shader name

getShadingGroupsFromNodes(nodeList)

Finds shaders assigned to current node list, Includes shape nodes, transforms, shaders and shadingGroups (will return themselves)

Parameters:

nodeList (list) – list of maya node names, can be any nodes

Return shadingGroupList:

List of shading group names associated with the given nodes

Rtype shadingGroupList:

list

getShadingGroupsFromSelectedNodes()

finds shaders assigned to current selection of nodes This includes shape nodes, transforms, shaders and shadingGroups (will return themselves)

Return shadingGroupList:

List of shading group names associated with the given nodes

Rtype shadingGroupList:

list

getShadersFromNodes(nodeList)

Will return a shader list from given nodes, This includes shape nodes, transforms, shaders (will return themselves) and shadingGroups

Parameters:

nodeList (list) – list of maya node names, can be any nodes

Return shaderList:

List of Shader Names associated with the nodeList

Rtype shaderList:

list

getShadersFromSelectedNodes(allDescendents=False, reportSelError=False)

Will return a shader list from given selection of nodes, This includes shape nodes, transforms, shaders (will return themselves) and shadingGroups Also can retrieve shaders on all descendents of the selected objects

Parameters:
  • allDescendents (bool) – will include allDescendants of the selection, children and grandchildren etc

  • reportSelError (bool) – Report selection issues to the user

Return shaderList:

List of Shader Names associated with the selected nodeList

Rtype shaderList:

list

selectMeshFaceFromShaderName(shaderName)

Selects objects and faces assigned from a shader

Parameters:

shaderName (str) – The name of a Maya shader

selectMeshFaceFromShaderNames(shaderNames)

Selects objects and faces assigned to multiple shaders

Parameters:

shaderNames (list(str)) – A list of Maya shader names

selectMeshFaceFromShaderSelection(message=True)

Selects objects and faces assigned to multiple shaders found in either mesh face or shader selection.

Parameters:

message (bool) – report a message to the user?

getMeshFaceFromShaderNodes(nodeList, selectMesh=True, objectsOnly=False)

Will return a mesh shape node list from given nodeList, This includes shape nodes, transforms, shaders (will return themselves) and shadingGroups

Parameters:
  • nodeList (list) – list of maya node names, can be any nodes

  • selectMesh (bool) – Select the returned meshes and potential faces?

  • objectsOnly (bool) – Only return (and potentially select) meshes, not faces

Return meshList:

List of mesh node names, can be transforms (needs fixing possibly to be only shapes)

Rtype meshList:

list

getMeshFaceFromShaderSelection(selectMesh=True, objectsOnly=False)

Will return a mesh (shape) node list from given selection of nodes, This includes shape nodes, transforms, shaders (will return themselves) and shadingGroups

Parameters:
  • selectMesh (bool) – Select the returned meshes and potential faces?

  • objectsOnly (bool) – Only return and potentially select meshes, not faces

Return meshFaceList:

List of mesh node names, and potentially face names, not transforms

Rtype meshFaceList:

list

transferAssign(objFaceList)

from a list take the first objects shader (it can be a shader or shading group too) and assign it to the remaining list objects

Parameters:

objFaceList (list) – list of maya objects and or face selection

transferAssignSelection(message=True)

from a selection take the first object’s shader (it can be a shader or shading group itself too) and assign it to the remaining list objects, this is like copy shader from an object to objects

Parameters:

message (bool) – report warnings to the user

removeShaderSuffix(shaderName)

Removes the shader suffix from a shader name, will remove all shader suffix names for any renderer

Will remove suffix for all renderers

Parameters:

shaderName (str) – the Maya shader name

Return shaderName:

the Maya shader name now with suffix removed

Rtype shaderName:

str

removeShaderSuffixRenderer(shaderName, renderer)

Removes the shader suffix from a shader name, will remove all shader suffix names for any renderer

Will remove on for the given renderer.

Parameters:

shaderName (str) – A Maya shader name

Return shaderName:

the Maya shader name now with suffix removed

Rtype shaderName:

str

removeShaderSuffixList(shaderNameList, renderer)
Parameters:
  • shaderNameList (list(str)) – List of shader names

  • renderer (str) – A renderer nicename

Return shaderRenamedList:

Shader list now renamed

Rtype shaderRenamedList:

getShaderNameFromNode(node, removeSuffix=False)

from the given node return the shader name that’s attached to it can remove the suffix if it’s in the dict rendererManage.ALLRENDERERSUFFIX

Parameters:
  • node (str) – any maya node, should be shader related but is ok if not, will just fail to find a shader

  • removeSuffix (bool) – removes the suffix name if it’s in the rendererManage.ALLRENDERERSUFFIX dict

Return shaderName:

the shader name

Rtype shaderName:

str

getShaderNameFromNodeSelected(removeSuffix=False)

from the first selected object return the shader name that’s attached to it can remove the suffix if it’s in the dict rendererManage.ALLRENDERERSUFFIX

Parameters:

removeSuffix (bool) – removes the suffix name if it’s in the rendererManage.ALLRENDERERSUFFIX dict

Return shaderName:

the shader name

Rtype shaderName:

str

connectSurfaceShaderToViewportShader(surfaceShader, viewportShadingGroup, renderer, connectedCount=0)

Connects the surface shader (usually the renderer shader) to the viewport shaders shading group Usually via the surface attribute. Useful while rendering in an engine whilst having the shaders looking nice in the viewport. This is a single shader setup

Parameters:
  • surfaceShader (str) – the renderers shader to be connected to the viewport shaders shading group

  • viewportShadingGroup (str) – the viewport shaders shading group name

  • connectedCount (int) – useful for looping and messaging, usually used by another function for counting connections

  • renderer (str) – which renderer are you using “redshift”, “arnold”, “vray”, mentalRay”, “renderman”. Only Redshift is supported

Return connectedCount:

Was the connection made, if so return this number as a +1

Rtype connectedCount:

int

saveSelectedShader(directory, saveType='auto')

Saves selected shader

Parameters:
  • directory (str) – The directory to save the shader

  • saveType (str) – “auto” saves ma and if unknown nodes saves mb, “ma” saves .ma and “mb” saves .mb

Returns:

Return type:

uniqueFileName(dirPath, name, ext='ma')

Generates a unique file name based on the directory path

Parameters:
  • dirPath

  • name

  • ext

Returns:

exportShader(shader, path, type_='ma')

Export shader to file path

Parameters:
  • shader

  • path

Returns:

assignSurfaceShaderWildcard(surfaceSuffix='RS', viewportSuffix='VP2', renderer='redshift')

Connects the surface shader (usually the renderer shader) to the viewport shader via the surface attribute. Useful while rendering in an engine whilst having the shaders looking nice in the viewport. works off matching suffix shader names eg skin_RS => skin_VP2’s shading group To Do 1. checks if the shader is already connected, if not disconnects the current connection and reconnects 2. disconnect

Parameters:
  • surfaceSuffix (str) – The user defined suffix of the renderer shader

  • viewportSuffix (str) – The user defined suffix of the viewport shader

  • renderer (str) – which renderer are you using “redshift”, “arnold”, “vray”, mentalRay”, “renderman”. Only Redshift is supported

cleanNamespaces(objs, prefix='')

Remove the namespace

Parameters:
  • objs

  • prefix

Returns:

renameShader(shader, newName, shaderGroup=True)

Rename the shader and the shader group

Parameters:
  • shader

  • newName

  • shaderGroup

Returns:

replaceShader(oldShader, newShader)

Replaces all objects with the old shader with the new shader

Parameters:
  • oldShader

  • newShader

Returns:

shaderExists(name)

Returns True if shader exists

Parameters:

name

Returns:

deleteShaderNetwork(shaderName)

deletes the shader network of a shader

Parameters:

shaderName (str) – the name of the shader

Return shaderNodes:

all nodes deleted

Rtype shaderNodes:

list

deleteShaderNetworkList(shaderList)

Deletes the shading network of a shading node

Parameters:

shaderList (list) – a list of maya shader names

Return shaderNodeDeletedList:

Rtype shaderNodeDeletedList:

shaderOpenAttrEditor()

Selects the shader of the selected object and opens the attribute editor.

Returns:

Return type:

selectNodeOrShaderAttrEditor()

This script selects the shader or the selected nodes:

  1. Selects the node if selected in the channel box and opens the attribute editor

  2. Or if a transform node is selected, select the shaders of the current selection and open attr editor

Return selectedReturn:

A list of the currently selected objects/shader nodes

Rtype selectedReturn:

list

renameShadingGroup(shaderName)
renameShadingGroupsScene()
class ZooShaderTrackerSingleton(*args, **kwargs)

Bases: object

Used by the shader marking menu other UIs

Shdmultconstants

Misc shader constants

from zoo.libs.maya.cmds.shaders import shdmultconstants shdmultconstants.ARNOLD

Author: Andrew Silke

Toggleshaders

Toggles/Swaps Shaders in a scene, usually given by two suffix’s Can mod this later for doing various things with two sets of shaders such as linking shaders to shading groups of Arnold and Redshift too. Main shader toggle is most handy in Renderman where shaders cannot be overidden for the viewport in the shading group.

findFirstWildcardShader(suffix1, suffix2)

This checks the scene for polygon meshes and returns the first suffix that it finds in a shader name This may be either suffix1 or suffix2

Parameters:
  • suffix1 (str) – the name of the first suffix

  • suffix2 (str) – the name of the second suffix

Return suffix:

either the name of suffix1 or suffix1

Rtype suffix:

str

toggleShader(shaderFromSuffix, shaderToSuffix)

Toggles all shaders in a scene swapping the shaders with the given suffix’s. Swap goes from shaderFrom and applies it to shaderToSuffix so the shaderToSuffix are assigned Only works on polygons, not currently NURBS

Parameters:
  • shaderFromSuffix

  • shaderToSuffix

toggleShaderAuto(shader1Suffix='VP2', shader2Suffix='PXR')

Toggles all shaders in a scene swapping the shaders with the given suffix’s. The swap is based off the first shader found in the scene that includes either suffix So the swap is automatic and will swap all shaders with the corresponding suffix’s Only works on polygons, not currently NURBS

Parameters:
  • shader1Suffix (str) – the suffix of the first set of shader names PXR would match to skinShader_PXR

  • shader2Suffix (str) – the suffix of the second set of shader names viewport would match to skinShader_viewport