def combineChannels(self, switchToMain, *args): currentChannel = None for mesh in getMeshIter(): currentChannel = mesh.currentColorSetName() validateChannels() iter = getMeshIter() # combine SUB_COLOR_SETS' into MAIN_COLOR_SET for mesh in iter: rColors = mesh.getVertexColors(R_CHANNEL) gColors = mesh.getVertexColors(G_CHANNEL) bColors = mesh.getVertexColors(B_CHANNEL) aColors = mesh.getVertexColors(A_CHANNEL) colors = om.MColorArray(mesh.numVertices, om.MColor((1, 1, 1, 1))) for i in xrange(mesh.numVertices): colors[i] = om.MColor( (rColors[i].r, gColors[i].g, bColors[i].b, aColors[i].r)) mesh.setCurrentColorSetName(MAIN_COLOR_SET) mesh.setVertexColors(colors, getIncrementIter(mesh.numVertices)) mesh.syncObject() if switchToMain: currentChannel = MAIN_COLOR_SET if currentChannel != None: for mesh in getMeshIter(): mesh.setCurrentColorSetName(currentChannel) self.updateUi()
def fillColor(color, colorName): validateChannels() channel = getCurrentColorSetNames()[0] colorName = COLOR_SET_NAMES[channel] if colorName == None else colorName warnMessage = "Fill %s channel's color to %s?" % (channel, colorName) resetAll = channel == MAIN_COLOR_SET if resetAll: warnMessage = "Fill all channels color to %s?" % (colorName) result = cmds.confirmDialog(title='Warning', message=warnMessage, button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel') if result != "OK": return for mesh in getMeshIter(): colors = mesh.getVertexColors(MAIN_COLOR_SET) numColors = len(colors) if resetAll: for colorSet in RESERVED_SETS: defaultColor = COLOR_SET_COLORS[colorSet] newColor = [a * b for a, b in zip(color, defaultColor)] newColors = om.MColorArray(numColors, om.MColor(newColor)) mesh.setCurrentColorSetName(colorSet) mesh.setVertexColors(newColors, getIncrementIter(numColors)) else: defaultColor = COLOR_SET_COLORS[channel] newColor = [a * b for a, b in zip(color, defaultColor)] newColors = om.MColorArray(numColors, om.MColor(newColor)) mesh.setVertexColors(newColors, getIncrementIter(numColors))
def updateDG(self): '''Retrieve and prepare data for drawing''' self.resolution = self.get_resolution() self.width = self.resolution self.height = self.resolution plug = om.MPlug(self.obj, Swatch.inColor) in_plugs = plug.connectedTo(True, False) if in_plugs: in_in_plugs = in_plugs[0].connectedTo(True, False) color_plug = in_in_plugs[0] if in_in_plugs else in_plugs[0] if color_plug.attribute().apiTypeStr != 'kAttribute3Float': self.color = om.MColor([1, 1, 1]) self.set_texture(None) color_node = color_plug.node() if color_node.apiTypeStr == 'kFileTexture': depfn = om.MFnDependencyNode(color_node) file = depfn.findPlug('fileTextureName', False).asString() self.set_texture( TEXTURE_MANAGER.acquireTexture('', color_plug, self.width, self.height, False)) else: self.set_texture( TEXTURE_MANAGER.acquireTexture('', color_plug, self.width, self.height, False)) else: self.set_texture(None) self.color = om.MColor(self.get_color())
def prepareForDraw(self, obj_path, camera_path, frame_context, old_data): """ """ data = old_data if not isinstance(data, DDHUDData): data = DDHUDData() fnDagNode = om.MFnDagNode(obj_path) # 需要先获取数据 data.camera_name = fnDagNode.findPlug("camera", False).asString() data.text = fnDagNode.findPlug("text", False).asString() data.font_name = fnDagNode.findPlug("fontName", False).asString() data.x = fnDagNode.findPlug("X", False).asFloat() data.y = fnDagNode.findPlug("Y", False).asFloat() r = fnDagNode.findPlug("fontColorR", False).asFloat() g = fnDagNode.findPlug("fontColorG", False).asFloat() b = fnDagNode.findPlug("fontColorB", False).asFloat() a = fnDagNode.findPlug("fontAlpha", False).asFloat() data.font_color = om.MColor((r, g, b, a)) data.font_scale = fnDagNode.findPlug("fontScale", False).asFloat() data.border = fnDagNode.findPlug("border", False).asBool() r = fnDagNode.findPlug("borderColorR", False).asFloat() g = fnDagNode.findPlug("borderColorG", False).asFloat() b = fnDagNode.findPlug("borderColorB", False).asFloat() a = fnDagNode.findPlug("borderAlpha", False).asFloat() data.border_color = om.MColor((r, g, b, a)) data.border_w = fnDagNode.findPlug("borderWidth", False).asFloat() data.border_h = fnDagNode.findPlug("borderHeight", False).asFloat() return data
def prepareForDraw(self, objPath, cameraPath, frameContext, oldData): depNode = om.MFnDependencyNode(objPath.node()) obj = depNode.userNode() isSelected = isPathSelected(objPath) self.xray = obj.xray plug = om.MPlug(objPath.node(), zRigHandle.colorAttr) self.color = om.MColor(om.MFnNumericData(plug.asMObject()).getData()) alpha = om.MPlug(objPath.node(), zRigHandle.alphaAttr).asFloat() self.color.a = alpha if isSelected: self.borderColor = omr.MGeometryUtilities.wireframeColor(objPath) else: plug = om.MPlug(objPath.node(), zRigHandle.borderColorAttr) self.borderColor = om.MColor( om.MFnNumericData(plug.asMObject()).getData()) # If no color has been set and we're on the default of (-1,-1,-1), use the main color, # so in the common case where you want to use the same color you don't have to set both. if self.borderColor.r == -1 and self.borderColor.g == -1 and self.borderColor.b == -1: self.borderColor = om.MColor(self.color) self.borderColor.a = om.MPlug( objPath.node(), zRigHandle.borderAlphaAttr).asFloat() self.shape = obj.getShape()
def addUIDrawables(self, objPath, drawManager, frameContext, data): locatordata = data status = OpenMayaUI.M3dView.displayStatus(objPath) if not isinstance(locatordata, MntLocatorNodeData): return elif OpenMayaAnim.MAnimControl.isPlaying() == True: return elif OpenMayaRender.MFrameContext.inUserInteraction() == True and data.interactiveRefresh == False: return drawManager.beginDrawable(OpenMayaRender.MUIDrawManager.kSelectable) if data.iconType < 6: color = OpenMaya.MColor((0.1, 0.2, 0.4, data.areaOpacity)) drawManager.setColor(color) drawManager.box(data.localPosition, OpenMaya.MVector(0, 1, 0), OpenMaya.MVector(1, 0, 0), data.worldSizeX, data.worldSizeY, data.worldSizeZ, True) drawManager.beginDrawInXray() drawManager.setTexture(data.texture) drawManager.rect2d(OpenMaya.MPoint(data.screenPos[0], data.screenPos[1]), OpenMaya.MVector(0, 1), data.screenSize, data.screenSize, True) drawManager.endDrawInXray() if data.label != '': drawManager.setColor(data.color) drawManager.setFontSize(11) drawManager.text2d(OpenMaya.MPoint(data.screenPos[0] + 16, data.screenPos[1]), data.label, alignment = OpenMayaRender.MUIDrawManager.kLeft) if data.iconType == 6: drawManager.setColor(data.color) drawManager.sphere(data.localPosition, data.size, 16, 8, True) if data.iconType == 7: drawManager.setColor(data.color) drawManager.circle(data.localPosition, data.upVector, data.size, 32, True) if data.iconType == 8: drawManager.setColor(data.color) drawManager.mesh(4, self.pointsArray, None, None, self.indicesArray, None) if data.hierarchicalLink == True: if data.pointArray.__len__() > 1: drawManager.beginDrawInXray() drawManager.setColor(OpenMaya.MColor((data.lineColor[0], data.lineColor[1], data.lineColor[2],1))) drawManager.setLineWidth(data.lineWidth) if data.dottedLine == False: drawManager.line(data.pointArray[0], data.pointArray[1]) else: for i in range(0, data.pointArray.__len__(), 2): drawManager.line(data.pointArray[i], data.pointArray[i + 1]) drawManager.endDrawInXray() drawManager.endDrawable()
def __init__(self): super(HelperData, self).__init__(False) ## don't delete after draw self.surface_color = om.MColor([1.0, 0.0, 0.0, 0.25]) self.wire_color = om.MColor([1.0, 0.0, 0.0]) self.points = om.MPointArray() self.triangles_indices = [] self.lines_indices = []
def prepareForDraw(self, obj_path, camera_path, frame_context, old_data): """ """ data = old_data if not isinstance(data, ZShotMaskData): data = ZShotMaskData() fnDagNode = om.MFnDagNode(obj_path) data.camera_name = fnDagNode.findPlug("camera", False).asString() data.text_fields = [] for i in range(0, len(ZShotMaskLocator.TEXT_ATTRS), 2): data.text_fields.append( fnDagNode.findPlug(ZShotMaskLocator.TEXT_ATTRS[i], False).asString()) counter_padding = fnDagNode.findPlug("counterPadding", False).asInt() if counter_padding < 1: counter_padding = 1 elif counter_padding > 6: counter_padding = 6 current_time = int(cmds.currentTime(q=True)) counter_position = fnDagNode.findPlug("counterPosition", False).asInt() if counter_position > 0 and counter_position <= len( ZShotMaskLocator.TEXT_ATTRS) / 2: data.text_fields[counter_position - 1] = "{0}".format( str(current_time).zfill(counter_padding)) data.text_padding = fnDagNode.findPlug("textPadding", False).asInt() data.font_name = fnDagNode.findPlug("fontName", False).asString() r = fnDagNode.findPlug("fontColorR", False).asFloat() g = fnDagNode.findPlug("fontColorG", False).asFloat() b = fnDagNode.findPlug("fontColorB", False).asFloat() a = fnDagNode.findPlug("fontAlpha", False).asFloat() data.font_color = om.MColor((r, g, b, a)) data.font_scale = fnDagNode.findPlug("fontScale", False).asFloat() r = fnDagNode.findPlug("borderColorR", False).asFloat() g = fnDagNode.findPlug("borderColorG", False).asFloat() b = fnDagNode.findPlug("borderColorB", False).asFloat() a = fnDagNode.findPlug("borderAlpha", False).asFloat() data.border_color = om.MColor((r, g, b, a)) data.border_scale = fnDagNode.findPlug("borderScale", False).asFloat() data.top_border = fnDagNode.findPlug("topBorder", False).asBool() data.bottom_border = fnDagNode.findPlug("bottomBorder", False).asBool() return data
def addUIDrawables(self, objPath, drawManager, frameContext, data): if not isinstance(data, GuideSpineData): return normalVector = OpenMaya.MVector([1.0, 0.0, 0.0]) bounding = OpenMaya.MBoundingBox(data.boundingBoxCorner1, data.boundingBoxCorner2) up = OpenMaya.MVector.kYaxisVector width = bounding.depth / 2.0 height = bounding.height / 2.0 dormantBorderColor = OpenMaya.MColor([0.0, 0.0, 0.8, 1.0]) leadBorderColor = OpenMaya.MColor([1.0, 1.0, 1.0, 1.0]) activeBorderColor = OpenMaya.MColor([0.4, 0.8, 1.0, 1.0]) lineColor = OpenMaya.MColor([1.0, 1.0, 1.0, 1.0]) fillColor = OpenMaya.MColor([0.0, 0.0, 1.0, 1.0]) fillColor.a = 0.4 borderWidth = 1.0 lineWidth = 2.0 displayStatus = OpenMayaRender.MGeometryUtilities.displayStatus( objPath) selected = True if displayStatus == util.DisplayStatus.Lead: borderColor = leadBorderColor borderWidth = 2.0 elif displayStatus == util.DisplayStatus.Active: borderColor = activeBorderColor borderWidth = 2.0 else: # kActiveAffected, kDormant, kHilite. borderColor = dormantBorderColor borderWidth = 1.0 selected = False drawManager.beginDrawable() drawManager.setColor(borderColor) drawManager.setLineWidth(borderWidth) drawManager.rect(bounding.center, up, normalVector, width, height, filled=False) # drawManager.setColor(fillColor) # drawManager.rect(bounding.center, up, normalVector, width, height, filled=True) # drawManager.setColor(OpenMaya.MColor([1.0, 1.0, 1.0, 1.0])) # for position in data.outputPoints: # drawManager.sphere(position, 0.5, filled=False) drawManager.endDrawable()
def __init__(self): """ Initialize camera render ui manager draw request. """ self.uiDraw = False self.uiType = constants.kText self.uiSize = 1.0 self.uiColor = OpenMaya.MColor([0.0, 0.0, 0.0]) self.uiResolutionGate = constants.kViewportGate self.uiDrawResolutionGate = True self.region = Canvas(0, 0, 0, 0) self.uiRegion = OpenMaya.MVector(0.0, 0.0, 0.0) self.uiRegionPosition = OpenMaya.MPoint(0.0, 0.0, 0.0) self.uiRegionColor = OpenMaya.MColor([0.0, 0.0, 0.0]) self.uiTextBackgroundColor = None self.uiRegionIsFilled = False self.uiDrawRegion = False self.uiHorisontalAttach = constants.kAttachHorizontalLeft self.uiVerticalAttach = constants.kAttachVerticalTop self.uiHorisontalAlignment = constants.kHorizontalAlignmentLeft self.uiVerticalAlignment = constants.kVerticalAlignmentTop self.uiRadius = 1.0 self.uiFilled = 1.0 self.uiLineStyle = constants.kLineSolid self.uiLineWidth = 2.0 self.uiPositionList = [] self.uiRegionPositionList = [] self.uiText = "Text" self.uiTextDynamic = False self.uiFitToResolutionGate = True self.uiFontStyle = None self.uiFontStyleSize = OpenMayaRender.MUIDrawManager.kDefaultFontSize self.uiFontStyleStretch = OpenMayaRender.MUIDrawManager.kStretchUnstretched self.uiFontStyleWeight = constants.kFontStyleWeightLight self.uiFontStyleIncline = constants.kFontStyleInclineNormal self.uiFontStyleLine = constants.kFontStyleLineNone self.file = "" self.year = "" self.month = "" self.day = "" self.hour = "" self.minute = ""
class ValueBarLocatorData(OpenMaya.MUserData): """Class for handling node attribute values. Instanced to hold cached attribute values. Class globals used as attribute default values. """ # default values inputValue = 0.0 barAim = (0.0, 1.0, 0.0) barUp = (0.0, 0.0, 1.0) barWidth = 0.05 barColor = (0.0, 1.0, 0.0) barAlpha = 0.5 barHasMin = True barMinValue = 0.0 barMinVisibility = True barMinColor = (0.0, 0.0, 1.0) barHasMax = True barMaxValue = 1.0 barMaxVisibility = True barMaxColor = (1.0, 0.0, 0.0) # calculated values start_point = OpenMaya.MPoint(0.0, 0.0, 0.0) aim_vector = OpenMaya.MVector() up_vector = OpenMaya.MVector() normal_vector = OpenMaya.MVector() start_value = 0.0 end_value = 0.0 bar_height = 0.0 bar_center_point = OpenMaya.MPoint() min_bar_height = 0.0 min_center_point = OpenMaya.MPoint() max_bar_height = 0.0 max_center_point = OpenMaya.MPoint() bar_m_color = OpenMaya.MColor() min_m_color = OpenMaya.MColor() max_m_color = OpenMaya.MColor() def __init__(self): OpenMaya.MUserData.__init__(self, False) # don't delete after draw
def draw(self, view, path, style, status): """ Legacy viewport draw function if in legacy - once on init, twice on frame change, selection, navigation """ print "drawing in legacy..." # Getting the OpenGL Renderer glRenderer = OpenMayaRenderv1.MHardwareRenderer.theRenderer() # Getting all classes from the renderer glFT = glRenderer.glFunctionTable() view.beginGL() glFT.glPushAttrib(OpenMayaRenderv1.MGL_ALL_ATTRIB_BITS) glFT.glPushMatrix() glFT.glDepthRange(0, 0) glFT.glEnable(OpenMayaRenderv1.MGL_LINE_SMOOTH) glFT.glEnable(OpenMayaRenderv1.MGL_POINT_SMOOTH) glFT.glEnable(OpenMayaRenderv1.MGL_BLEND) glFT.glDisable(OpenMayaRenderv1.MGL_LIGHTING) glFT.glBlendFunc(OpenMayaRenderv1.MGL_SRC_ALPHA, OpenMayaRenderv1.MGL_ONE_MINUS_SRC_ALPHA) # Setting a color for Viewport draw color1 = OpenMaya.MColor(0.0, 1.0, 0.0, 1.0) color2 = OpenMaya.MColor(1.0, 1.0, 1.0, 1.0) # Draw points glFT.glPointSize(12.0) glFT.glBegin(OpenMayaRenderv1.MGL_POINTS) glFT.glColor4f(color1[0], color1[1], color1[2], 1) for point in self.points: glFT.glVertex3f(point[0], point[1], point[2]) glFT.glEnd() # Draw lines glFT.glLineWidth(3.0) glFT.glBegin(OpenMayaRenderv1.MGL_LINE_STRIP) glFT.glColor4f(color2[0], color2[1], color2[2], 1) for point in self.points: glFT.glVertex3f(point[0], point[1], point[2]) glFT.glEnd() # Wrap glFT.glDisable(OpenMayaRenderv1.MGL_BLEND) glFT.glDisable(OpenMayaRenderv1.MGL_LINE_SMOOTH) glFT.glDisable(OpenMayaRenderv1.MGL_POINT_SMOOTH) glFT.glEnable(OpenMayaRenderv1.MGL_LIGHTING) glFT.glPopMatrix() glFT.glPopAttrib() view.endGL()
def draw(self, view, path, style, status): ## Get the size ## thisNode = self.thisMObject() plug = om.MPlug( thisNode, footPrint.size ) sizeVal = plug.asMDistance() multiplier = sizeVal.asCentimeters() global sole, soleCount global heel, heelCount view.beginGL() ## drawing in VP1 views will be done using V1 Python APIs: import maya.OpenMayaRender as v1omr glRenderer = v1omr.MHardwareRenderer.theRenderer() glFT = glRenderer.glFunctionTable() if ( style == omui.M3dView.kFlatShaded ) or ( style == omui.M3dView.kGouraudShaded ): ## Push the color settings ## glFT.glPushAttrib( v1omr.MGL_CURRENT_BIT ) # Show both faces glFT.glDisable( v1omr.MGL_CULL_FACE ) if status == omui.M3dView.kActive: view.setDrawColor( 13, omui.M3dView.kActiveColors ) else: view.setDrawColor( 13, omui.M3dView.kDormantColors ) glFT.glBegin( v1omr.MGL_TRIANGLE_FAN ) for i in range(soleCount-1): glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier ) glFT.glEnd() glFT.glBegin( v1omr.MGL_TRIANGLE_FAN ) for i in range(heelCount-1): glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier ) glFT.glEnd() glFT.glPopAttrib() ## Draw the outline of the foot ## glFT.glBegin( v1omr.MGL_LINES ) for i in range(soleCount-1): glFT.glVertex3f( sole[i][0] * multiplier, sole[i][1] * multiplier, sole[i][2] * multiplier ) glFT.glVertex3f( sole[i+1][0] * multiplier, sole[i+1][1] * multiplier, sole[i+1][2] * multiplier ) for i in range(heelCount-1): glFT.glVertex3f( heel[i][0] * multiplier, heel[i][1] * multiplier, heel[i][2] * multiplier ) glFT.glVertex3f( heel[i+1][0] * multiplier, heel[i+1][1] * multiplier, heel[i+1][2] * multiplier ) glFT.glEnd() view.endGL() ## Draw the name of the footPrint view.setDrawColor( om.MColor( (0.1, 0.8, 0.8, 1.0) ) ) view.drawText( "Footprint", om.MPoint( 0.0, 0.0, 0.0 ), omui.M3dView.kCenter )
def prepareForDraw(self, objPath, cameraPath, frameContext, oldData): data = oldData if not isinstance(data, GuideHandleData): data = GuideHandleData() controlNode = objPath.node() data.childPositions = OpenMaya.MPointArray() plug = OpenMaya.MPlug(controlNode, self.GuideClass.childPosition) fnData = OpenMaya.MFnNumericData() for i in xrange(plug.numElements()): handle = plug.elementByPhysicalIndex(i) fnData.setObject(handle.asMObject()) pt = OpenMaya.MPoint(fnData.getData()) data.childPositions.append(pt) plug.setAttribute(self.GuideClass.handleMatrix) handleMatrix = OpenMaya.MFnMatrixData(plug.asMObject()).matrix() data.inverseMatrix = handleMatrix.inverse() plug.setAttribute(self.GuideClass.handleColor) colorData = OpenMaya.MFnNumericData(plug.asMObject()) data.handleColor = OpenMaya.MColor(colorData.getData()) plug.setAttribute(self.GuideClass.jointMatrix) jointMatrix = OpenMaya.MFnMatrixData(plug.asMObject()).matrix() data.jointMatrix = jointMatrix * data.inverseMatrix plug.setAttribute(self.GuideClass.guide) data.hasGuide = plug.isConnected return data
def get_falloff(vertex_distance_list, vertex_value_list): """ :param vertex_distance_list: float list with distances of nearby vertices. Must be same length as vertex_value list. :param vertex_value_list: Can be and array of MVectors, MColors, Floats. :return: Sum of the vertex_value_list with weight given to closer vertices. """ if sum(vertex_distance_list) == 0: distances_percentages = [(x / 1) for x in vertex_distance_list] else: distances_percentages = [(x / sum(vertex_distance_list)) for x in vertex_distance_list] """Setting this so that the greater the distance value, the less weight it's vertex_value adds.""" inverse_distance_percentage = [1 - x for x in distances_percentages] """Normalizing the inverse distance to multiply with the vertex values""" normalize_inverse_percentage = [ x / sum(inverse_distance_percentage) for x in inverse_distance_percentage ] """Multiply each vertex value with normalized inverse percentage and then gather the sum of that list, this will be the new sampled value. Closer verts with contribute more to the sum.""" new_vertex_value = \ [vertex_value_list[x] * normalize_inverse_percentage[x] for x in range(len(normalize_inverse_percentage))] value_sum = om2.MColor((0, 0, 0, 1)) for i in new_vertex_value: value_sum += i return value_sum
def addUIDrawables(self, objPath, drawManager, frameContext, data): locatordata = data if not isinstance(locatordata, footPrintData): return drawManager.beginDrawable() ##Draw the foot print solid/wireframe drawManager.setColor(locatordata.fColor) drawManager.setDepthPriority(5) if (frameContext.getDisplayStyle() & omr.MFrameContext.kGouraudShaded): drawManager.mesh(omr.MGeometry.kTriangles, locatordata.fSoleTriangleList) drawManager.mesh(omr.MGeometry.kTriangles, locatordata.fHeelTriangleList) drawManager.mesh(omr.MUIDrawManager.kClosedLine, locatordata.fSoleLineList) drawManager.mesh(omr.MUIDrawManager.kClosedLine, locatordata.fHeelLineList) ## Draw a text "Foot" pos = om.MPoint(0.0, 0.0, 0.0) ## Position of the text textColor = om.MColor((0.1, 0.8, 0.8, 1.0)) ## Text color drawManager.setColor(textColor) drawManager.setFontSize(omr.MUIDrawManager.kSmallFontSize) drawManager.text(pos, "Footprint", omr.MUIDrawManager.kCenter) drawManager.endDrawable()
def addUIDrawables(self, objPath, drawManager, frameContext, data): '''This function is the draw call. Args: objPath: The DAG path to the locator node drawManager: The MUIDrawManager object used for drawing frameContext: A frame context data: The data required to draw ''' drawManager.beginDrawable() # Draw the foot print solid/wireframe # drawManager.setColor(locatordata.fColor) colour = om.MColor() colour.g = 1.0 drawManager.setColor(colour) drawManager.setDepthPriority(5) if (frameContext.getDisplayStyle() & omr.MFrameContext.kGouraudShaded): for centre, radius in zip(self.m_centres, self.m_radii): drawManager.sphere(centre, radius, True) else: for centre, radius in zip(self.m_centres, self.m_radii): drawManager.sphere(centre, radius, False) drawManager.endDrawable()
def prepareForDraw(self, obj, cam, frame_context, data, verbose=0): """Retrieve data cache (create if does not exist). Args: obj (MDagPath): path to object being drawn cam (MDagPath): path to viewport camera frame_context (MFrameContext): frame context data (MeshXRayerData): previous data verbose (int): print process data Returns: (MeshXRayerData): node data """ lprint('PREPARE FOR DRAW', verbose=verbose) _data = data if not isinstance(_data, MeshXRayerData): _data = MeshXRayerData() lprint(' - USING EXISTING DATA', _data, verbose=verbose) lprint(' - DATA', _data, verbose=verbose) # Read in_mesh plug lprint(' - OBJ', obj, verbose=verbose) _node = obj.node() _in_mesh_plug = om.MPlug(_node, MeshXRayer.in_mesh) lprint(' - IN MESH PLUG', _in_mesh_plug, verbose=verbose) _data.mesh_tris.clear() if _in_mesh_plug.isNull: return None if _in_mesh_plug.asMDataHandle().type() != om.MFnData.kMesh: return None _in_mesh_handle = _in_mesh_plug.asMDataHandle().asMesh() _in_mesh = om.MFnMesh(_in_mesh_handle) # Read mesh triangles _mesh_pts = _in_mesh.getPoints() for _poly_id in range(_in_mesh.numPolygons): _vtx_ids = _in_mesh.getPolygonVertices(_poly_id) for _vtx_id in _vtx_ids[:3]: _data.mesh_tris.append(_mesh_pts[_vtx_id]) lprint(' - IN MESH', _in_mesh, len(_in_mesh.getPoints()), verbose=verbose) # Read col/hide_angle + draw toggles _col_plug = om.MPlug(_node, MeshXRayer.color) _data.color = om.MColor( [_col_plug.child(_idx).asFloat() for _idx in range(3)]) _data.hide_angle = om.MPlug(_node, MeshXRayer.hide_angle).asFloat() _data.draw_control = om.MPlug(_node, MeshXRayer.draw_control).asBool() _data.draw_mesh = om.MPlug(_node, MeshXRayer.draw_mesh).asBool() _obj_pos = hom.HMatrix(obj.inclusiveMatrix()).pos() _cam_pos = hom.HMatrix(cam.inclusiveMatrix()).pos() _data.mesh_to_cam = _cam_pos - _obj_pos return _data
def __init__(self): om.MUserData.__init__(self, False) ## don't delete after draw self.fColor = om.MColor() self.fSoleLineList = om.MPointArray() self.fSoleTriangleList = om.MPointArray() self.fHeelLineList = om.MPointArray() self.fHeelTriangleList = om.MPointArray()
def __init__(self): om.MUserData.__init__(self, False) ## don't delete after draw ######VECTOR self.fColor = om.MColor() self.fsourcePt = om.MPoint() self.faimPt = om.MPoint() self.fWidth = 1.0
def __init__(self): # The false tells it not to delete after its used super(LocatorData, self).__init__(False) self.shape = None # The shape index that is being drawn self.color = om.MColor() # Holds the color to draw self.lineList = om.MPointArray() # The list of lines to draw self.triangleList = om.MPointArray() # A list of triangles to draw
def apply_api_colors(colors, indices, obj): import maya.api.OpenMaya as api colors = [api.MColor(i) for i in colors] selectionList = api.MSelectionList() selectionList.add(obj) nodeDagPath = selectionList.getDagPath(0) mfnMesh = api.MFnMesh(nodeDagPath) mfnMesh.setVertexColors(colors, indices)
def addUIDrawables(self, objPath, drawManager, frameContext, data): if not isinstance(data, GuideHandleData): return displayStatus = OpenMayaRender.MGeometryUtilities.displayStatus(objPath) selected = displayStatus == util.DisplayStatus.Lead or displayStatus == util.DisplayStatus.Active mainColor = data.handleColor if selected: mainColor = OpenMaya.MColor([1.0, 1.0, 1.0, 1.0]) connectorColor = OpenMaya.MColor(mainColor) connectorColor.a = 0.6 center = OpenMaya.MPoint(0.0, 0.0, 0.0) radius = 1.0 colorR = OpenMaya.MColor([1.0, 0.0, 0.0, 1.0]) colorG = OpenMaya.MColor([0.0, 1.0, 0.0, 1.0]) colorB = OpenMaya.MColor([0.0, 0.0, 1.0, 1.0]) viewDirection = OpenMaya.MVector(frameContext.getTuple(frameContext.kViewDirection)) viewDirection *= data.inverseMatrix drawManager.beginDrawable() drawManager.beginDrawInXray() drawManager.setColor(mainColor) drawManager.sphere(center, radius, filled=True) if data.childPositions: self.drawConnectors(drawManager, data.childPositions, viewDirection, connectorColor) if data.hasGuide: x = OpenMaya.MVector(data.jointMatrix[0], data.jointMatrix[1], data.jointMatrix[2]).normal() y = OpenMaya.MVector(data.jointMatrix[4], data.jointMatrix[5], data.jointMatrix[6]).normal() z = OpenMaya.MVector(data.jointMatrix[8], data.jointMatrix[9], data.jointMatrix[10]).normal() pos = OpenMaya.MPoint(data.jointMatrix[12], data.jointMatrix[13], data.jointMatrix[14]) drawManager.setColor(colorR) drawManager.line(pos, pos + x) drawManager.setColor(colorG) drawManager.line(pos, pos + y) drawManager.setColor(colorB) drawManager.line(pos, pos + z) drawManager.endDrawInXray() drawManager.endDrawable()
def static_compare(mesh, target, clamp=10, world=True): """ Compares two meshes on a given static frame. Sets a vertex color value to show the distance values. :param mesh: The name or path to the mesh to visualize on. :param target: The name or path of the mesh we are comparing against. :param clamp: The value to clamp against. All values be scaled accordingly. :param world: Whether to compare in world space or object space. """ # Get the Dag Paths to the mesh shapes mesh = get_shape(mesh) target = get_shape(target) # Turn on visualization of the vertex colors on the shape mesh_path = mesh.fullPathName() mc.polyOptions(mesh_path, colorShadedDisplay=True) # Get Mesh objects from the shapes. mesh_mesh = om.MFnMesh(mesh) target_mesh = om.MFnMesh(target) # For each mesh, get their points space = om.MSpace.kWorld if world else om.MSpace.kObject mesh_points = mesh_mesh.getPoints(space) target_points = target_mesh.getPoints(space) print("mesh points = ", len(mesh_points)) print("target points = ", len(target_points)) colors = om.MColorArray() ids = [] # Loop through to calculate the colors for i, mpoint in enumerate(mesh_points): tpoint = target_points[i] # Get the distance between the vertices. distance = math.sqrt(((mpoint.x - tpoint.x)**2) + ((mpoint.y - tpoint.y)**2) + ((mpoint.z - tpoint.z)**2)) # If our distance is not zero, then process it if distance: # First scale according to the clamp value scaled = distance / clamp # Then clamp it off at 1 clamped = min(scaled, 1) # Finally we only want half its value since our base color is 50% grey distance = clamped / 2.0 # Start from 50% grey and bias to the red channel as distance grows color = om.MColor((0.5 + distance, 0.5 - distance, 0.5 - distance)) colors.append(color) ids.append(i) # Apply the colors mesh_mesh.setVertexColors(colors, ids)
def glDrawTriangles(drawManager, camMatrix, coords, ssOffsets, color, colors): colorsArray = ompy.MColorArray() for i in range(0, coords.length()): if (colors.length() == 0): colorsArray.append( ompy.MColor([color[0], color[1], color[2], color[3]])) else: colorsArray.append( ompy.MColor( [colors[i][0], colors[i][1], colors[i][2], colors[i][3]])) for i in range(0, coords.length()): coords[i] += utils_screenTo3dOffset( camMatrix, coords[i], ssOffsets[min(i, ssOffsets.length() - 1)]) drawManager.mesh(ompyr.MUIDrawManager.kTriangles, coords, None, colorsArray)
def draw_text(draw_manager, position, text, alignment, background_size): if not len(text): return draw_manager.text2d( position, text, alignment=alignment, backgroundSize=background_size, backgroundColor=OpenMaya.MColor((0.0, 0.0, 0.0, 0.0)), dynamic=False )
def drawText(self, drawManager, position, text, alignment, bgSize): """ """ if (len(text) > 0): drawManager.text2d(position, text, alignment=alignment, backgroundSize=bgSize, backgroundColor=om.MColor((0.0, 0.0, 0.0, 0.0)))
def addUIDrawables(self, objPath, drawManager, frameContext, data): # Viewport 2.0 addUIDrawables(Draw) Function locatordata = data if not isinstance(locatordata, TemplateLocatorData): return drawManager.beginDrawable() textColor = OpenMaya.MColor((1.0, 1.0, 1.0, 1.0)) drawManager.setColor(textColor) drawManager.text(OpenMaya.MPoint(0, 1, 0), "3D SPACE TEXT", OpenMayaRender.MUIDrawManager.kLeft) textColor = OpenMaya.MColor((0.5, 0.3, 0.4, 1.0)) drawManager.setColor(textColor) drawManager.text2d(OpenMaya.MPoint(500, 500), "2D SPACE TEXT", OpenMayaRender.MUIDrawManager.kLeft) drawManager.endDrawable()
def __init__(self): om.MUserData.__init__(self, False) self.fUIType = kText self.fColor = om.MColor((1., 0., 0., 1.)) self.fLineWidth = 2 self.fLineStyle = omr.MUIDrawManager.kSolid self.fIsFilled = False self.fRadius = 1. self.fDraw2D = False self.fPosition = om.MPoint(0.0, 0.0, 0.001) # text self.fText = "uiDrawManager-Text" self.fTextFontSize = omr.MUIDrawManager.kDefaultFontSize self.fFontFaceIndex = 0 self.fTextAlignment = omr.MUIDrawManager.kLeft self.fTextIncline = omr.MUIDrawManager.kInclineNormal self.fTextWeight = omr.MUIDrawManager.kWeightBold self.fTextStretch = omr.MUIDrawManager.kStretchUnstretched self.fTextLine = 0 self.fTextBoxSize = [0, 0] self.fTextBoxColor = om.MColor((0., 1., 1., 1.)) # point self.fPointSize = 2. # line self.fLineStartPoint = om.MPoint(0.0, 0.0, 0.0) self.fLineEndPoint = om.MPoint(1.0, 1.0, 1.0) # rect self.fRectUp = om.MVector(0.0, 1.0, 0.0) self.fRectNormal = om.MVector(0.0, 0.0, 1.0) self.fRectScale = [1., 1.] # quad self.fQuadVertex = [ om.MPoint(0.0, 0.0, 0.0), om.MPoint(1.0, 0.0, 0.0), om.MPoint(1.0, 1.0, 0.0), om.MPoint(0.0, 1.0, 0.0) ] # circle self.fCircleNormal = om.MVector(0.0, 0.0, 1.0) # arc self.fArcStart = om.MVector(1.0, 0.0, 0.0) self.fArcEnd = om.MVector(0.0, 1.0, 0.0) self.fArcNormal = om.MVector(0.0, 0.0, 1.0)
def _initializeTemporalyVariables(self): # type: () -> None self.xcolor = om.MColor(om.MVector(1, 0, 0)) self.xmat = om.MMatrix( ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (1, 0, 0, 1))) self.ycolor = om.MColor(om.MVector(0, 1, 0)) self.ymat = om.MMatrix( ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 1, 0, 1))) self.zcolor = om.MColor(om.MVector(0, 0, 1)) self.zmat = om.MMatrix( ((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 1, 1))) self.grayColor = om.MColor(om.MVector(0.3, 0.3, 0.3)) self.coneRadius = 0.1 self.coneHeight = 0.6