Created
February 11, 2022 10:16
-
-
Save zclongpop123/69195f4178302a3d168531bfd5e394b2 to your computer and use it in GitHub Desktop.
转换Arnold材质到lambert材质
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#======================================== | |
# author: Changlong.Zang | |
# mail: [email protected] | |
# time: Mon Aug 30 18:42:43 2021 | |
#======================================== | |
import traceback | |
import pymel.core as pm | |
import maya.OpenMaya as OpenMaya | |
#--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | |
def main(): | |
''' | |
''' | |
sg_nodes = pm.ls(typ='shadingEngine') | |
for sg in sg_nodes: | |
if sg in ('initialParticleSE', 'initialShadingGroup'): | |
continue | |
#- | |
members = pm.sets(sg, q=True) | |
if len(members) == 0: | |
continue | |
#- | |
shading_node = sg.surfaceShader.connections() | |
if not shading_node: | |
continue | |
if not pm.nodeType(shading_node[0]).startswith('ai'): | |
continue | |
#- | |
if not shading_node[0].baseColor.isConnected() and shading_node[0].subsurfaceColor.isConnected(): | |
shading_node[0].subsurfaceColor.connections()[0].outColor >> shading_node[0].baseColor | |
#- | |
color_plug = shading_node[0].baseColor.__apiobject__() | |
iterator = OpenMaya.MItDependencyGraph(color_plug, OpenMaya.MFn.kFileTexture, OpenMaya.MItDependencyGraph.kUpstream) | |
texture_node = None | |
while not iterator.isDone(): | |
texture_node = pm.PyNode(OpenMaya.MFnDependencyNode(iterator.currentItem()).name()) | |
iterator.next() | |
#- | |
if texture_node: | |
lambert_node = pm.shadingNode('lambert', name=shading_node[0], asShader=True) | |
lambert_sg = pm.createNode('shadingEngine', name='{0}SG'.format(lambert_node)) | |
texture_node.outColor >> lambert_node.color | |
lambert_node.outColor >> lambert_sg.surfaceShader | |
try: | |
pm.delete(sg) | |
lambert_sg.addMembers([m.name() for m in members]) | |
except: | |
print lambert_node, members | |
print traceback.format_exc() | |
pm.mel.eval('hyperShadePanelMenuCommand("hyperShadePanel1", "deleteUnusedNodes");') | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment