I want to script material settings in Maya.
Applying a Texture in Python https://forums.cgsociety.org/t/applying-a-texture-in-python/1573565/7
Assigning a Material using Pymel https://discourse.techart.online/t/assigning-a-material-using-pymel/1240
Assuming to use maya.cmds
import maya.cmds as mc
Create a File shader and set the texture file path.
Create a shader node and connect the attribute (e.g. color
) of the shader to which you want to assign the texture to file.outColor
.
It seems that shaders cannot be assigned directly to objects (mesh), so via a shadingGroup node (a node that collects surface shader, volume shader, etc.).
Connect the .surfaceShader
of the shadingGroup node to the .outColor
of the file shader.
Assign shadingGroup to an object. There seem to be many ways, but maya.cmds makes sets easier?
mc.sets("geo", edit=True, forceElement="sg1")
The structure is as follows (I wonder if it is easier to understand if you check with Maya Node editor)
object(mesh) <- shadingGroup node (.surfaceShader) <- (.outColor) File shader (.fileTextureName) <- Texture filename
If you want to assign it as volume shader or displacement shader, you can change the attribute connected to shadingGroup.
Recommended Posts