def import_vertex_color(mesh, texture): u"""頂点カラーをテクスチャからインポート Args: mesh (unicode): 対象のMesh texture (unicode): 対象のテクスチャパス """ if not os.path.isfile(texture): dialog.open_warning_dialog(u"指定されたファイルが見つかりません。") return cmds.select(cl=True) default_ctx = cmds.currentCtx() mel.eval("artAttrColorPerVertexToolScript 4;") cmds.select(mesh) cmds.artAttrPaintVertexCtx(cmds.currentCtx(), e=True, importfileload=texture) cmds.setToolTo(default_ctx) cmds.select(cl=True) cmds.select(mesh, add=True) mel.eval('doBakeNonDefHistory( 1, {"prePost"});') # ブレンドシェイプのinputTargetsにも頂点カラーが伝播するので削除する input_targets = _get_input_targets(mesh) if input_targets: cmds.select(input_targets) cmds.polyColorPerVertex(remove=True) for t in input_targets: cmds.setAttr(t + ".displayColors", 0) dialog.open_in_view_message("Import Color Vertex", u"頂点カラーのインポートが完了しました。")
def saveTexture(fileName, fileType): maya.mel.eval("PaintVertexColorTool;") context = cmds.currentCtx() cmds.artAttrPaintVertexCtx(context, whichTool="colorPerVertex", e=True, efm='rgba', eft=fileType, esf=fileName)
def J_checkPolyTrapped(closestValue=0, farthestValue=1, saveVColor=False, model=0): selection = cmds.ls(sl=True) sel = om2.MGlobal.getActiveSelectionList() #基础比对模型 pBaseMesh = om2.MFnMesh(sel.getComponent(0)[0]) #目标检查模型 pTargetMesh = om2.MFnMesh(sel.getComponent(1)[0]) # faceCount = pTargetMesh.numPolygons vertexDistance = [] resample = False if closestValue >= farthestValue: closestValue = 100 farthestValue = 0 resample = True #改顶点色显示 targetObj = sel.getComponent(1)[0].fullPathName() if not pTargetMesh.displayColors: cmds.setAttr(targetObj + ".displayColors", 1) pointsPos = pTargetMesh.getPoints(om2.MSpace.kWorld) for item in pointsPos: posNor = pBaseMesh.getClosestPointAndNormal( item, om2.MSpace.kWorld) #return tuple (mpoint, mvector,int) pointDistance = item.distanceTo(posNor[0]) pointDirection = item - posNor[0] pointDistance = pointDistance * (om2.MVector( pointDirection.x, pointDirection.y, pointDirection.z).normalize().__mul__(posNor[1].normalize())) vertexDistance.append(pointDistance) colors = [] vertexIds = [] for i in range(len(vertexDistance)): greenColor = pymel.util.arrays.linstep(closestValue, farthestValue, vertexDistance[i]) redColor = pymel.util.arrays.linstep( 0, 1, (1 - greenColor) * math.copysign(1, vertexDistance[i])) colors.append(om2.MColor([redColor, greenColor, 0, 1])) vertexIds.append(i) pTargetMesh.setVertexColors(colors, vertexIds) cmds.select(selection[1]) mel.eval("PaintVertexColorTool") cmds.artAttrPaintVertexCtx("artAttrColorPerVertexContext", edit=True, exportfilesave="c:/tmp.iff") else: pTargetMesh.displayColors = False
def checkPaintingContext(): """ Checks the painting context to check that everything is in order """ resetContext = False if cmds.artAttrCtx("artAttrColorPerVertexContext", exists=True): resetContext = False mel.eval("PaintVertexColorTool;") # make sure the paint vertex context exists if resetContext: cmds.resetTool('artAttrColorPerVertexContext') cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', stampProfile="gaussian", e=True)
def loadTexture(fileName, fileType): if (fileName == None or len(fileName) == 0): return maya.mel.eval("PaintVertexColorTool;") context = cmds.currentCtx() cmds.artAttrPaintVertexCtx(context, whichTool="colorPerVertex", e=True, ifm="rgba", ifl=fileName) mesh = getMesh() if isMainColorSet(): subColorSets = SUB_COLOR_SETS colors = mesh.getVertexColors(MAIN_COLOR_SET) else: subColorSets = [mesh.currentColorSetName()] colors = mesh.getVertexColors(subColorSets[0]) # filter unused channel for subColorSet in subColorSets: mesh.setCurrentColorSetName(subColorSet) useR = int(subColorSet == R_CHANNEL or subColorSet == MAIN_COLOR_SET) useG = int(subColorSet == G_CHANNEL or subColorSet == MAIN_COLOR_SET) useB = int(subColorSet == B_CHANNEL or subColorSet == MAIN_COLOR_SET) useA = int(subColorSet == A_CHANNEL) numColors = len(colors) subColors = om.MColorArray(numColors, om.MColor((1.0, 1.0, 1.0, 1.0))) for i in xrange(numColors): color = colors[i] subColors[i] = om.MColor((color.r * useR + color.a * useA, color.g * useG + color.a * useA, color.b * useB + color.a * useA, 1)) mesh.setVertexColors(subColors, getIncrementIter(numColors))
def paint(RGBA, paintType, cClamp=["none", 0, 1], aClamp=["none", 0, 1], colorSet="controlSetA"): """ Set artisan context with painting and brush parameters for artAttrPaintVertexCtx Args: RGBA (list): Channels to paint e.g. [ 0, 1, 0, 0 ] paintType (str): "additive" or "subtract" cClamp (list): Clamping settings for color [clamp, clamplower, clampupper] aClamp (list): Clamping settings for alpha [clamp, clamplower, clampupper] colorSet (str): Color set to paint into """ # SET UP ARTISAN CONTEXT # set channels to RGBA and enable paint tool attributes cmds.radioButtonGrp('artAttrColorChannelChoices', sl=2, e=True) # set to RGBA in artisan UI cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', paintRGBA=True, e=True) # set to RGBA cmds.floatSliderGrp('colorPerVertexAlpha', en=True, e=True) # enable alpha painting cmds.floatFieldGrp('colorPerVertexMinMaxAlphaValue', en=True, e=True) # enable alpha min max cmds.checkBoxGrp('artAttrAlphaClampChkBox', en=True, e=True) # enable alpha clamp checkbox # before stroke command cmds.artAttrPaintVertexCtx( 'artAttrColorPerVertexContext', bsc= "artAttrPaintVertexCtx -edit -showactive 0 artAttrColorPerVertexContext", e=True) # after stroke command cmds.artAttrPaintVertexCtx( 'artAttrColorPerVertexContext', asc= "artAttrPaintVertexCtx -edit -showactive 1 artAttrColorPerVertexContext", e=True) # PREPARE MESHES selected = cmds.ls(sl=True) shapes = lib.getShapes(selected) enableVtxCtrl(shapes) # SET UP PAINTING PARAMETERS cmds.polyColorSet(shapes, currentColorSet=True, cs=colorSet) # sets the current color set of all shapes cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', selectedattroper=paintType, e=True) # add or substract color cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', cl4=RGBA, e=True) # define channels to paint cmds.floatSliderGrp('colorPerVertexAlpha', value=RGBA[3], e=True) # set alpha painting value cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', opacity=0.2, e=True) # set opacity to 0.2 cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', accopacity=True, e=True) # oppacity accumulates cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', clamp=cClamp[0], e=True) # color clamp cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', clamplower=cClamp[1], e=True) # lower clamp cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', clampupper=cClamp[2], e=True) # upper clamp cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', alphaclamp=aClamp[0], e=True) # alpha clamp cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', alphaclamplower=aClamp[1], e=True) # alpha lower clamp cmds.artAttrPaintVertexCtx('artAttrColorPerVertexContext', alphaclampupper=aClamp[2], e=True) #alpha upper clamp