标签:
mel.
eval
(
‘select -r mesh_000%d:MeshShape;‘
%
frameid)
这里涉及到 mesh的名称,可以看到里面的名称
是与网格的名称对应的,如果你不按照
mesh_0000.obj的命名,那么脚本中相关的名称要改一下
import re import maya.api.OpenMaya as api import maya.mel as mel global cnt global framenum framenum = 3 cnt = 0 global countmax countmax = 100000 global labelColorFilePath labelColorFilePath = r ‘D:\zzb\squat2\squat2_coloring.seg‘ def paintColor(): for frameid in range (framenum): mel. eval ( ‘select -r mesh_000%d:MeshShape;‘ % frameid) mel. eval ( ‘polyColorPerVertex -r 0.5 -g 0.5 -b 0.5 -a 1 -cdo;‘ ) fColor = open (labelColorFilePath, ‘r‘ ) lineColor = fColor.readline() p = re. compile ( ‘\s+‘ ) count = 0 rgbVal = [ 1.0 , 0.0 , 0.0 , 1.0 ] selectionList = api.MGlobal.getActiveSelectionList() nodeDagPath = selectionList.getDagPath( 0 ) mfnMesh = api.MFnMesh(nodeDagPath) cArray = [] while lineColor: lineColor = lineColor.strip( ‘ ‘ ) lineColor = lineColor.strip( ‘\n‘ ) splitesult = p.split(lineColor) #cmds.select(‘MeshShape.vtx[%d]‘ % count) rgbVal[ 0 ] = ( float (splitesult[ 0 ])) rgbVal[ 1 ] = ( float (splitesult[ 1 ])) rgbVal[ 2 ] = ( float (splitesult[ 2 ])) #cmds.polyColorPerVertex( rgb = rgbVal , notUndoable = True) c = api.MColor(rgbVal) cArray.append(c) count + = 1 lineColor = fColor.readline() if count > countmax: break fColor.close() iArray = [i for i in xrange (count)] mfnMesh.setVertexColors(cArray, iArray) global cnt cnt + = 1 print cnt paintColor() |
import re import maya.cmds as cmds import maya.mel as mel global count count = 0 global framenum framenum = 3 for frameid in range ( 0 , framenum): print count mel. eval ( ‘string $surfaceShader_%d = `createNode surfaceShader`;‘ % (frameid + 1 )) mel. eval ( ‘sets -renderable true -noSurfaceShader true -empty -name surfaceShader%dSG;‘ % (frameid + 1 )) mel. eval ( ‘connectAttr -f surfaceShader%d.outColor surfaceShader%dSG.surfaceShader;‘ % (frameid + 1 ,frameid + 1 )) mel. eval ( ‘string $mib_amb_occlusion_%d = `createNode mib_amb_occlusion`;‘ % (frameid + 1 ) ) mel. eval ( ‘connectAttr -force mib_amb_occlusion%d.outValue surfaceShader%d.outColor;‘ % (frameid + 1 ,frameid + 1 )) mel. eval ( ‘string $mentalrayVertexColors_%d = `createNode mentalrayVertexColors`;‘ % (frameid + 1 )) mel. eval ( ‘connectAttr -force mesh_000%d:MeshShape.colorSet[0].colorName mentalrayVertexColors%d.cpvSets[0];‘ % (frameid ,frameid + 1 )) mel. eval ( ‘connectAttr -f mentalrayVertexColors%d.outColor mib_amb_occlusion%d.bright; ‘ % (frameid + 1 ,frameid + 1 )) mel. eval ( ‘disconnectAttr mesh_000%d:MeshShape.instObjGroups[0] initialShadingGroup.dagSetMembers[%d];‘ % (frameid ,frameid) ) mel. eval ( ‘connectAttr -force mesh_000%d:MeshShape.instObjGroups[0] surfaceShader%dSG.dagSetMembers[0];‘ % (frameid ,frameid + 1 )) mel. eval ( ‘setAttr "mib_amb_occlusion%d.samples" 256;‘ % (frameid + 1 ) ) count + = 1 |
mel.
eval
(
‘setAttr "mib_amb_occlusion%d.samples" 256;‘
%
(frameid
+
1
) )
设定samples 值为256 ,可根据自己的情况设定
标签:
原文地址:http://blog.csdn.net/u011520133/article/details/51024342