def addUIDrawables(self, obj_path, draw_manager, frame_context, data): """ """ if not isinstance(data, DDHUDBorderData): return camera_path = frame_context.getCurrentCameraPath() camera = om.MFnCamera(camera_path) if data.camera_name and camera_exists(data.camera_name) and not is_camera_match(camera_path, data.camera_name): return mask_width, mask_height = get_mask_size(camera, frame_context) vp_x, vp_y, vp_width, vp_height = frame_context.getViewportDimensions() vp_half_height = 0.5 * vp_height mask_half_height = 0.5 * mask_height mask_bottom_y = vp_half_height - mask_half_height mask_top_y = vp_half_height + mask_half_height top_border_height = int(mask_top_y - mask_height * data.top_border_size) top_background_size = (int(vp_width), vp_height - top_border_height) bottom_border_height = int(mask_height * data.bottom_border_size + mask_bottom_y) bottom_background_size = (int(vp_width), bottom_border_height) draw_manager.beginDrawable() draw_border(draw_manager, om.MPoint(0, top_border_height), top_background_size, data.top_border_color) draw_border(draw_manager, om.MPoint(0, 0), bottom_background_size, data.bottom_border_color)
def _press(self): """Method to be executed when the mouse button is pressed. Get the current camera and it's settings. """ self._view = om2UI.M3dView().active3dView() self._mfn = om2.MFnCamera(self._view.getCamera()) # Exit, if it's not a perspective view. if self._mfn.isOrtho(): logger.warning("Quick Zoom only works in a perspective view.") return # If the current modifier is the ctrl key toggle the pan/zoom # state. modifier = cmds.draggerContext(CONTEXT_NAME, query=True, modifier=True) if modifier == "ctrl": self.togglePanZoom() return # Get all necessary info about the view and camera settings. self._ratio = self._mfn.aspectRatio() self._hPan = self._mfn.horizontalPan self._vPan = self._mfn.verticalPan self._width = float(self._view.portWidth()) self._height = float(self._view.portHeight())
def worldPositionToScreen(camera, point, width, height): cam = om2.MFnCamera(camera) transMat = cam.getPath().inclusiveMatrix().inverse() fullMat = om2.MPoint(point) * transMat * om2.MMatrix( cam.projectionMatrix().matrix()) return [(fullMat[0] / fullMat[3] * 0.5 + 0.5) * width, (fullMat[1] / fullMat[3] * 0.5 + 0.5) * height]
def _createInScene(self, node, name): if node is None: name = "_".join([name or self.__class__.__name__, "meta"]) node = nodes.createDagNode(name, "camera") self._handle = om2.MObjectHandle(node) if node.hasFn(om2.MFn.kDagNode): self._mfn = om2.MFnDagNode(node) else: self._mfn = om2.MFnDependencyNode(node) if node.hasFn(om2.MFn.kTransform): node = list( nodes.iterChildren(self.mobject(), False, om2.MFn.kCamera))[0] self.camMfn = om2.MFnCamera(node)
def addUIDrawables(self, obj_path, draw_manager, frame_context, data): """ """ if not isinstance(data, DDHUDData): return camera_path = frame_context.getCurrentCameraPath() camera = om.MFnCamera(camera_path) if data.camera_name and camera_exists(data.camera_name) and not is_camera_match(camera_path, data.camera_name): return mask_width, mask_height = get_mask_size(camera, frame_context) vp_x, vp_y, vp_width, vp_height = frame_context.getViewportDimensions() vp_half_width = 0.5 * vp_width vp_half_height = 0.5 * vp_height mask_half_width = 0.5 * mask_width mask_x = vp_half_width - mask_half_width mask_half_height = 0.5 * mask_height mask_top_y = vp_half_height + mask_half_height border_height = int(0.05 * mask_height * data.border_h) background_size = (int(data.border_w*border_height), int(data.border_h*border_height)) draw_manager.beginDrawable() draw_manager.setFontName(data.font_name) draw_manager.setFontSize(int((border_height - border_height * 0.15) * data.font_scale)) draw_manager.setColor(data.font_color) new_x = data.x * mask_width + mask_x new_y = -data.y * mask_height + mask_top_y if data.border: draw_border(draw_manager, om.MPoint(new_x, new_y), background_size, data.border_color) draw_text(draw_manager, om.MPoint(new_x, new_y), data.text, omr.MUIDrawManager.kLeft, background_size)
def addUIDrawables(self, objPath, drawManager, frameContext, data): """ """ if not isinstance(data, ViewMaskData): return camera_path = frameContext.getCurrentCameraPath() camera = om.MFnCamera(camera_path) if data.camera_name and self.cameraExists( data.camera_name) and not self.isCameraMatch( camera_path, data.camera_name): return camera_aspect_ratio = camera.aspectRatio() device_aspect_ratio = cmds.getAttr( "defaultResolution.deviceAspectRatio") vp_x, vp_y, vp_width, vp_height = frameContext.getViewportDimensions() vp_half_width = 0.5 * vp_width vp_half_height = 0.5 * vp_height vp_aspect_ratio = vp_width / float(vp_height) scale = 1.0 if camera.filmFit == om.MFnCamera.kHorizontalFilmFit: mask_width = vp_width / camera.overscan mask_height = mask_width / device_aspect_ratio elif camera.filmFit == om.MFnCamera.kVerticalFilmFit: mask_height = vp_height / camera.overscan mask_width = mask_height * device_aspect_ratio elif camera.filmFit == om.MFnCamera.kFillFilmFit: if vp_aspect_ratio < camera_aspect_ratio: if camera_aspect_ratio < device_aspect_ratio: scale = camera_aspect_ratio / vp_aspect_ratio else: scale = device_aspect_ratio / vp_aspect_ratio elif camera_aspect_ratio > device_aspect_ratio: scale = device_aspect_ratio / camera_aspect_ratio mask_width = vp_width / camera.overscan * scale mask_height = mask_width / device_aspect_ratio elif camera.filmFit == om.MFnCamera.kOverscanFilmFit: if vp_aspect_ratio < camera_aspect_ratio: if camera_aspect_ratio < device_aspect_ratio: scale = camera_aspect_ratio / vp_aspect_ratio else: scale = device_aspect_ratio / vp_aspect_ratio elif camera_aspect_ratio > device_aspect_ratio: scale = device_aspect_ratio / camera_aspect_ratio mask_height = vp_height / camera.overscan / scale mask_width = mask_height * device_aspect_ratio else: om.MGlobal.displayError("[ZShotMask] Unknown Film Fit value") return mask_half_width = 0.5 * mask_width mask_x = vp_half_width - mask_half_width mask_half_height = 0.5 * mask_height mask_bottom_y = vp_half_height - mask_half_height mask_top_y = vp_half_height + mask_half_height border_height = int(0.05 * mask_height * data.border_scale) background_size = (int(mask_width), border_height) drawManager.beginDrawable() drawManager.setFontName(data.font_name) drawManager.setFontSize( int((border_height - border_height * 0.15) * data.font_scale)) drawManager.setColor(data.font_color) if data.top_border: self.drawBorder(drawManager, om.MPoint(mask_x, mask_top_y - border_height), background_size, data.border_color) if data.bottom_border: self.drawBorder(drawManager, om.MPoint(mask_x, mask_bottom_y), background_size, data.border_color) self.drawText( drawManager, om.MPoint(mask_x + data.text_padding, mask_top_y - border_height), data.text_fields[0], omr.MUIDrawManager.kLeft, background_size) self.drawText(drawManager, om.MPoint(vp_half_width, mask_top_y - border_height), data.text_fields[1], omr.MUIDrawManager.kCenter, background_size) self.drawText( drawManager, om.MPoint(mask_x + mask_width - data.text_padding, mask_top_y - border_height), data.text_fields[2], omr.MUIDrawManager.kRight, background_size) self.drawText(drawManager, om.MPoint(mask_x + data.text_padding, mask_bottom_y), data.text_fields[3], omr.MUIDrawManager.kLeft, background_size) self.drawText(drawManager, om.MPoint(vp_half_width, mask_bottom_y), data.text_fields[4], omr.MUIDrawManager.kCenter, background_size) self.drawText( drawManager, om.MPoint(mask_x + mask_width - data.text_padding, mask_bottom_y), data.text_fields[5], omr.MUIDrawManager.kRight, background_size) drawManager.endDrawable()
def draw(self, view, path, style, status): # collect data cameraPath = view.getCamera() camera = om.MFnCamera(cameraPath) fnDagNode = om.MFnDagNode(path.extendToShape()) cameraName = fnDagNode.findPlug("camera", False).asString() textFields = [] for i in range(0, len(ViewMaskLocator.TEXT_ATTRS), 2): textFields.append( fnDagNode.findPlug(ViewMaskLocator.TEXT_ATTRS[i], False).asString()) counterPadding = fnDagNode.findPlug("counterPadding", False).asInt() if counterPadding < 1: counterPadding = 1 elif counterPadding > 6: counterPadding = 6 # textFields[4] = "{0}/{1:.1f}".format(cameraPath.partialPathName(), camera.focalLength) # currentTime = int(cmds.currentTime(q=True)) # counterPosition = fnDagNode.findPlug("counterPosition", False).asInt() # if counterPosition > 0 and counterPosition <= len(ViewMaskLocator.TEXT_ATTRS) / 2: # textFields[counterPosition - 1] = "{0}".format(str(currentTime).zfill(counterPadding), ) textPadding = fnDagNode.findPlug("textPadding", False).asInt() fontName = 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() # fontColor = om.MColor((r, g, b, a)) fontColor = QtGui.QColor(r * 255, g * 255, b * 255, a * 255) fontScale = 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() # borderColor = om.MColor((r, g, b, a)) borderColor = QtGui.QColor(r * 255, g * 255, b * 255, a * 255) borderScale = fnDagNode.findPlug("borderScale", False).asFloat() topBorder = fnDagNode.findPlug("topBorder", False).asBool() bottomBorder = fnDagNode.findPlug("bottomBorder", False).asBool() # draw----------------------------------------------------------- if cameraName and cameraName in cmds.listCameras( ) and not self.isCameraMatch(cameraPath, cameraName): return cameraAspectRatio = camera.aspectRatio() deviceAspectRatio = cmds.getAttr("defaultResolution.deviceAspectRatio") vpWidth = view.portWidth() vpHeight = view.portHeight() vpHalfWidth = 0.5 * vpWidth vpHalfHeight = 0.5 * vpHeight vpAspectRatio = vpWidth / float(vpHeight) scale = 1.0 if camera.filmFit == om.MFnCamera.kHorizontalFilmFit: # maskWidth = vpWidth / camera.overscan maskWidth = vpWidth / camera.overscan maskHeight = maskWidth / deviceAspectRatio elif camera.filmFit == om.MFnCamera.kVerticalFilmFit: # maskHeight = vpHeight / camera.overscan maskHeight = vpHeight / camera.overscan maskWidth = maskHeight * deviceAspectRatio elif camera.filmFit == om.MFnCamera.kFillFilmFit: if vpAspectRatio < cameraAspectRatio: if cameraAspectRatio < deviceAspectRatio: scale = cameraAspectRatio / vpAspectRatio else: scale = deviceAspectRatio / vpAspectRatio elif cameraAspectRatio > deviceAspectRatio: scale = deviceAspectRatio / cameraAspectRatio # maskWidth = vpWidth / camera.overscan * scale maskWidth = vpWidth / camera.overscan * scale maskHeight = maskWidth / deviceAspectRatio elif camera.filmFit == om.MFnCamera.kOverscanFilmFit: if vpAspectRatio < cameraAspectRatio: if cameraAspectRatio < deviceAspectRatio: scale = cameraAspectRatio / vpAspectRatio else: scale = deviceAspectRatio / vpAspectRatio elif cameraAspectRatio > deviceAspectRatio: scale = deviceAspectRatio / cameraAspectRatio # maskHeight = vpHeight / camera.overscan / scale maskHeight = vpHeight / camera.overscan / scale maskWidth = maskHeight * deviceAspectRatio else: om.MGlobal.displayError("[ViewMask] Unknown Film Fit value") return maskHalfWidth = 0.5 * maskWidth maskX = vpHalfWidth - maskHalfWidth maskHalfHeight = 0.5 * maskHeight maskBottomY = vpHalfHeight - maskHalfHeight maskTopY = vpHalfHeight + maskHalfHeight borderHeight = int(0.05 * maskHeight * borderScale) bgSize = (int(maskWidth), borderHeight) # Getting the OpenGL renderer import maya.OpenMayaRender as v1omr import maya.OpenMayaUI as v1omui glRenderer = v1omr.MHardwareRenderer.theRenderer() glFT = glRenderer.glFunctionTable() # Pushed current state glFT.glPushAttrib(v1omr.MGL_CURRENT_BIT) # Enabled Blend mode (to enable transparency) glFT.glEnable(v1omr.MGL_BLEND) # Defined Blend function glFT.glBlendFunc(v1omr.MGL_SRC_ALPHA, v1omr.MGL_ONE_MINUS_SRC_ALPHA) # create x-ray view and will be seen always glFT.glDisable(v1omr.MGL_DEPTH_TEST) # Starting the OpenGL drawing view.beginGL() # # 设置字体,字体大小,字体颜色 # # viewport 1无法自定义字体和字体大小 # view.setDrawColor(fontColor) # todo 绘制文字 # self.drawText(view, om.MPoint(maskX + textPadding, maskTopY - borderHeight), textFields[0], # v1omui.M3dView.kLeft) # self.drawText(view, om.MPoint(vpHalfWidth, maskTopY - borderHeight), textFields[1], # v1omui.M3dView.kCenter) # self.drawText(view, om.MPoint(maskX + maskWidth - textPadding, maskTopY - borderHeight), # textFields[2], v1omui.M3dView.kRight) # self.drawText(view, om.MPoint(maskX + textPadding, maskBottomY), textFields[3], # v1omui.M3dView.kLeft) # self.drawText(view, om.MPoint(vpHalfWidth, maskBottomY), textFields[4], v1omui.M3dView.kCenter # ) # self.drawText(view, om.MPoint(maskX + maskWidth - textPadding, maskBottomY), textFields[5], # v1omui.M3dView.kRight) # ------------------------------------------------------- # 生成MImage开始 mask_image = QtGui.QImage(maskWidth, maskHeight, QtGui.QImage.Format_ARGB32) mask_image.fill(QtCore.Qt.transparent) painter = QtGui.QPainter() # begin draw painter.begin(mask_image) # 绘制中 # 先绘制border borderPen = QtGui.QPen(borderColor) borderBrush = QtGui.QBrush(borderColor) painter.setPen(borderPen) painter.setBrush(borderBrush) if topBorder: painter.drawRect( 0, 0, int(maskWidth), int(borderHeight), ) if bottomBorder: painter.drawRect( 0, int(maskHeight - borderHeight), int(maskWidth), int(borderHeight), ) # 再绘制text # Text pen textPen = QtGui.QPen(fontColor, 2) try: textFont = QtGui.QFont(fontName, fontScale * 12) except Exception: textFont = QtGui.QFont("Times New Roman", fontScale * 12) painter.setPen(textPen) painter.setFont(textFont) maxTextWidth = 640 painter.drawText( QtCore.QRect(textPadding, 0, maxTextWidth, borderHeight), QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, textFields[0]) painter.drawText( QtCore.QRect(maskWidth / 2 - maxTextWidth / 2, 0, maxTextWidth, borderHeight), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, textFields[1]) painter.drawText( QtCore.QRect(maskWidth - maxTextWidth - textPadding, 0, maxTextWidth, borderHeight), QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter, textFields[2]) painter.drawText( QtCore.QRect(textPadding, maskHeight - borderHeight, maxTextWidth, borderHeight), QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, textFields[3]) painter.drawText( QtCore.QRect(maskWidth / 2 - maxTextWidth / 2, maskHeight - borderHeight, maxTextWidth, borderHeight), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter, textFields[4]) painter.drawText( QtCore.QRect(maskWidth - maxTextWidth - textPadding, maskHeight - borderHeight, maxTextWidth, borderHeight), QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter, textFields[5]) painter.end() ptr = mask_image.constBits() api_img = om.MImage() api_img.setRGBA(True) api_img.setPixels(bytearray(ptr), int(maskWidth), int(maskHeight)) api_img.verticalFlip() # 生成结束 # ----------------------------------------------------- view.writeColorBuffer(api_img, int(maskX), int(maskBottomY)) glFT.glDisable(v1omr.MGL_BLEND) glFT.glEnable(v1omr.MGL_DEPTH_TEST) # Restore the state glFT.glPopAttrib() # Ending the OpenGL drawing view.endGL()
def __init__(self, camera_name): selection_list = om.MSelectionList() selection_list.add(camera_name) cam_dag_path = selection_list.getDagPath(0) self.camera = om.MFnCamera(cam_dag_path) world_to_cam = om.MFloatMatrix(cam_dag_path.inclusiveMatrixInverse()) projection = self.camera.projectionMatrix() post_projection = self.camera.postProjectionMatrix() # MFloatMatrix = [x-axis, y-axis, z-axis, translate] view_projection = world_to_cam * projection * post_projection # Right = translate - x-axis self.right = Plane( view_projection[3] - view_projection[0], view_projection[7] - view_projection[4], view_projection[11] - view_projection[8], view_projection[15] - view_projection[12], ) # Left = translate + x-axis self.left = Plane( view_projection[3] + view_projection[0], view_projection[7] + view_projection[4], view_projection[11] + view_projection[8], view_projection[15] + view_projection[12], ) # Bottom = translate + y-axis self.bottom = Plane( view_projection[3] + view_projection[1], view_projection[7] + view_projection[5], view_projection[11] + view_projection[9], view_projection[15] + view_projection[13], ) # Top = translate - y-axis self.top = Plane( view_projection[3] - view_projection[1], view_projection[7] - view_projection[5], view_projection[11] - view_projection[9], view_projection[15] - view_projection[13], ) # Far = translate + z-axis self.far = Plane( view_projection[3] + view_projection[2], view_projection[7] + view_projection[6], view_projection[11] + view_projection[10], view_projection[15] + view_projection[14], ) # Near = translate - z-axis self.near = Plane( view_projection[3] - view_projection[2], view_projection[7] - view_projection[6], view_projection[11] - view_projection[10], view_projection[15] - view_projection[14], ) self.planes = [ self.right, self.left, self.bottom, self.top, self.far, self.near ]
def addUIDrawables(self, obj_path, draw_manager, frame_context, data): if not isinstance(data, MagicMaskData): return camera_path = frame_context.getCurrentCameraPath() camera = OpenMaya.MFnCamera(camera_path) camera_aspect_ratio = camera.aspectRatio() device_aspect_ratio = pm.general.getAttr( 'defaultResolution.deviceAspectRatio') viewport_x, viewport_y, viewport_width, viewport_height = frame_context.getViewportDimensions( ) viewport_aspect_ratio = viewport_width / float(viewport_height) scale = 1.0 if camera.filmFit == OpenMaya.MFnCamera.kHorizontalFilmFit: mask_width = viewport_width / camera.overscan mask_height = mask_width / device_aspect_ratio elif camera.filmFit == OpenMaya.MFnCamera.kVerticalFilmFit: mask_height = viewport_height / camera.overscan mask_width = mask_height * device_aspect_ratio elif camera.filmFit in (OpenMaya.MFnCamera.kFillFilmFit, OpenMaya.MFnCamera.kOverscanFilmFit): if camera_aspect_ratio > device_aspect_ratio: scale = device_aspect_ratio / camera_aspect_ratio elif viewport_aspect_ratio < camera_aspect_ratio: scale = min(camera_aspect_ratio, device_aspect_ratio) / viewport_aspect_ratio else: pass if camera.filmFit == OpenMaya.MFnCamera.kFillFilmFit: mask_width = viewport_width / camera.overscan * scale mask_height = mask_width / device_aspect_ratio else: mask_height = viewport_height / camera.overscan / scale mask_width = mask_height * device_aspect_ratio else: OpenMaya.MGlobal.displayError('[MagicMask] Unknown Film Fit Value') return mask_x = 0.5 * (viewport_width - mask_width) mask_y_top = 0.5 * (viewport_height + mask_height) mask_y_bottom = 0.5 * (viewport_height - mask_height) if not data.crop_enabled: border_height = int(0.1 * mask_height * data.border_scale) else: if not data.crop_use_custom: border_height = int( (mask_height - mask_width / data.crop_preset) / 2.0) else: border_height = int( (mask_height - mask_width / (data.crop_custom_width / data.crop_custom_height)) / 2.0) if border_height <= 0: OpenMaya.MGlobal.displayWarning( "MagicMask's height pixel <= 0 ({0}), current crop preset not " "suit for current scene render size.".format(border_height)) return background_size = (int(mask_width), border_height) # draw mask draw_manager.beginDrawable() if data.top_border_enabled: draw_manager.text2d(OpenMaya.MPoint(mask_x, mask_y_top - border_height), ' ', alignment=OpenMayaRender.MUIDrawManager.kLeft, backgroundSize=background_size, backgroundColor=data.border_color, dynamic=False) if data.bottom_border_enabled: draw_manager.text2d(OpenMaya.MPoint(mask_x, mask_y_bottom), ' ', alignment=OpenMayaRender.MUIDrawManager.kLeft, backgroundSize=background_size, backgroundColor=data.border_color, dynamic=False) draw_manager.setColor(data.top_text_color) draw_manager.setFontSize( int(border_height * 0.25 * data.top_text_scale)) draw_manager.setFontWeight(data.top_text_font_weight) self.draw_text( draw_manager, OpenMaya.MPoint(mask_x + data.top_text_padding, mask_y_top - border_height), data.text_fields[0], OpenMayaRender.MUIDrawManager.kLeft, background_size) self.draw_text( draw_manager, OpenMaya.MPoint(viewport_width * 0.5, mask_y_top - border_height), data.text_fields[1], OpenMayaRender.MUIDrawManager.kCenter, background_size) self.draw_text( draw_manager, OpenMaya.MPoint(mask_x + mask_width - data.top_text_padding, mask_y_top - border_height), data.text_fields[2], OpenMayaRender.MUIDrawManager.kRight, background_size) draw_manager.setColor(data.bottom_text_color) draw_manager.setFontSize( int(border_height * 0.25 * data.bottom_text_scale)) draw_manager.setFontWeight(data.bottom_text_font_weight) self.draw_text( draw_manager, OpenMaya.MPoint(mask_x + data.bottom_text_padding, mask_y_bottom), data.text_fields[3], OpenMayaRender.MUIDrawManager.kLeft, background_size) self.draw_text(draw_manager, OpenMaya.MPoint(viewport_width * 0.5, mask_y_bottom), data.text_fields[4], OpenMayaRender.MUIDrawManager.kCenter, background_size) self.draw_text( draw_manager, OpenMaya.MPoint(mask_x + mask_width - data.bottom_text_padding, mask_y_bottom), data.text_fields[5], OpenMayaRender.MUIDrawManager.kRight, background_size) draw_manager.endDrawable()
def prepareForDraw(self, obj_path, camera_path, frame_context, old_data): data = old_data if not isinstance(data, MagicMaskData): data = MagicMaskData() mask_node = OpenMaya.MFnDagNode(obj_path) data.text_fields = [] for attribute in MagicMaskNode.TEXT_ATTRIBUTES: data.text_fields.append( mask_node.findPlug(attribute, False).asString()) data.top_text_padding = mask_node.findPlug('top_text_padding', False).asInt() data.bottom_text_padding = mask_node.findPlug('bottom_text_padding', False).asInt() data.top_text_scale = mask_node.findPlug('top_text_scale', False).asFloat() data.bottom_text_scale = mask_node.findPlug('bottom_text_scale', False).asFloat() top_text_color_r = mask_node.findPlug('top_text_colorR', False).asFloat() top_text_color_g = mask_node.findPlug('top_text_colorG', False).asFloat() top_text_color_b = mask_node.findPlug('top_text_colorB', False).asFloat() top_text_color_a = mask_node.findPlug('top_text_alpha', False).asFloat() data.top_text_color = OpenMaya.MColor( (top_text_color_r, top_text_color_g, top_text_color_b, top_text_color_a)) top_text_font_weight_plug = mask_node.findPlug('top_text_font_weight', False) top_text_font_weight_attr = OpenMaya.MFnEnumAttribute( top_text_font_weight_plug.attribute()) data.top_text_font_weight = FONT_WEIGHT_MAP.get( top_text_font_weight_attr.fieldName( top_text_font_weight_plug.asShort())) bottom_text_color_r = mask_node.findPlug('bottom_text_colorR', False).asFloat() bottom_text_color_g = mask_node.findPlug('bottom_text_colorG', False).asFloat() bottom_text_color_b = mask_node.findPlug('bottom_text_colorB', False).asFloat() bottom_text_color_a = mask_node.findPlug('bottom_text_alpha', False).asFloat() data.bottom_text_color = OpenMaya.MColor( (bottom_text_color_r, bottom_text_color_g, bottom_text_color_b, bottom_text_color_a)) bottom_text_font_weight_plug = mask_node.findPlug( 'bottom_text_font_weight', False) bottom_text_font_weight_attr = OpenMaya.MFnEnumAttribute( bottom_text_font_weight_plug.attribute()) data.bottom_text_font_weight = FONT_WEIGHT_MAP.get( bottom_text_font_weight_attr.fieldName( bottom_text_font_weight_plug.asShort())) border_color_r = mask_node.findPlug('border_colorR', False).asFloat() border_color_g = mask_node.findPlug('border_colorG', False).asFloat() border_color_b = mask_node.findPlug('border_colorB', False).asFloat() border_color_a = mask_node.findPlug('border_alpha', False).asFloat() data.border_color = OpenMaya.MColor( (border_color_r, border_color_g, border_color_b, border_color_a)) counter_position = mask_node.findPlug('counter_position', False).asInt() if 0 <= counter_position < MagicMaskNode.TEXT_POSITION_NUMBER: offset_frame = mask_node.findPlug('frame_offset', False).asInt() counter_padding = mask_node.findPlug('counter_padding', False).asInt() current_frame = int(OpenMayaAnim.MAnimControl.currentTime().value) end_frame = int(OpenMayaAnim.MAnimControl.maxTime().value) frame_string = '{0} / {1}'.format( str(current_frame + offset_frame).zfill(counter_padding), str(end_frame + offset_frame).zfill(counter_padding)) cut_frame_enabled = mask_node.findPlug('cut_frame_enabled', False).asBool() if cut_frame_enabled: cut_in = mask_node.findPlug('cut_in', False).asInt() cut_out = mask_node.findPlug('cut_out', False).asInt() cut_string = '{0}-{1}'.format(cut_in, cut_out) data.text_fields[counter_position] = '{0} | {1}'.format( cut_string, frame_string) else: data.text_fields[counter_position] = frame_string data.top_border_enabled = mask_node.findPlug('top_border_enabled', False).asBool() data.bottom_border_enabled = mask_node.findPlug( 'bottom_border_enabled', False).asBool() data.border_scale = mask_node.findPlug('border_scale', False).asFloat() data.crop_enabled = mask_node.findPlug('crop_enabled', False).asBool() crop_preset_plug = mask_node.findPlug('crop_preset', False) crop_preset_attr = OpenMaya.MFnEnumAttribute( crop_preset_plug.attribute()) data.crop_preset = CROP_MAP.get( crop_preset_attr.fieldName(crop_preset_plug.asShort())) data.crop_use_custom = mask_node.findPlug('crop_use_custom', False).asBool() data.crop_custom_width = mask_node.findPlug('crop_custom_width', False).asFloat() data.crop_custom_height = mask_node.findPlug('crop_custom_height', False).asFloat() focal_length_position = mask_node.findPlug('focal_length_position', False).asInt() if 0 <= focal_length_position < MagicMaskNode.TEXT_POSITION_NUMBER: camera_path = frame_context.getCurrentCameraPath() camera = OpenMaya.MFnCamera(camera_path) focal_length_string = 'Focal Length: %.2f' % camera.focalLength data.text_fields[focal_length_position] = focal_length_string return data
def prepareForDraw(self, objPath, cameraPath, frameContext, oldData): ## Retrieve data cache (create if does not exist) data = oldData if not isinstance(data, MntLocatorNode): data = MntLocatorNodeData() typeList = ['Bone', 'Circle', 'Square', 'Skull', 'Pelvis', 'RibCage', 'Sphere', 'Disc', 'circle3D'] statutColorList = ['Yellow' , 'Red', 'Blue'] MSelList = OpenMaya.MSelectionList() MSelList.add(objPath) MObj = MSelList.getDependNode(0) size = OpenMaya.MFnDependencyNode(MObj).findPlug('size', False).asFloat() isAreaVisible = OpenMaya.MFnDependencyNode(MObj).findPlug('area_Visibility', False).asBool() iconType = OpenMaya.MFnDependencyNode(MObj).findPlug('iconType', False).asInt() iconMainAxis = OpenMaya.MFnDependencyNode(MObj).findPlug('iconMainAxis', False).asInt() localPositionX = OpenMaya.MFnDependencyNode(MObj).findPlug('localPositionX', False).asFloat() localPositionY = OpenMaya.MFnDependencyNode(MObj).findPlug('localPositionY', False).asFloat() localPositionZ = OpenMaya.MFnDependencyNode(MObj).findPlug('localPositionZ', False).asFloat() color = OpenMaya.MFnDependencyNode(MObj).findPlug('color', False).asMDataHandle().asFloat3() opacity = OpenMaya.MFnDependencyNode(MObj).findPlug('opacity', False).asFloat() label = OpenMaya.MFnDependencyNode(MObj).findPlug('label', False).asString() data.hierarchicalLink = OpenMaya.MFnDependencyNode(MObj).findPlug('show_hierarchical_links', False).asBool() data.lineWidth = OpenMaya.MFnDependencyNode(MObj).findPlug('line_width', False).asFloat() data.lineColor = OpenMaya.MFnDependencyNode(MObj).findPlug('line_color', False).asMDataHandle().asFloat3() data.dottedLine = OpenMaya.MFnDependencyNode(MObj).findPlug('use_dotted_line', False).asBool() MObjFn = OpenMaya.MFnDagNode(MObj) MObjParent = MObjFn.parent(0) fnMObjParent = OpenMaya.MFnDependencyNode(MObjParent) worldMatrixAttr = fnMObjParent.attribute("worldMatrix") matrixPlug = OpenMaya.MPlug(MObjParent, worldMatrixAttr) matrixPlug = matrixPlug.elementByLogicalIndex(0) worldMatrixObject = matrixPlug.asMObject() worldMatrixData = OpenMaya.MFnMatrixData(worldMatrixObject) worldMatrix = worldMatrixData.matrix() worldMatrixTransform = OpenMaya.MTransformationMatrix(worldMatrix) worldScale = worldMatrixTransform.scale(4) data.pointArray = OpenMaya.MPointArray() # Creates data for hierarchical line display. MSelList.clear() MFnDagTransNode = OpenMaya.MFnDagNode(MObjParent) MObjParentNode = MFnDagTransNode.parent(0) MFnDependencyParentNode = OpenMaya.MFnDependencyNode(MObjParentNode) if MFnDependencyParentNode.name() != 'world': try: MFnDagParent = OpenMaya.MFnDagNode(MObjParentNode) parentLocalMatrix = MFnDagParent.transformationMatrix() '''parentShapePath = MFnDagParent.getPath().extendToShape()''' parentShapePath = MFnDagParent.getPath().extendToShape() MSelList.add(parentShapePath) MObjParentShape = MSelList.getDependNode(0) MFnDependencyNodeParentShape = OpenMaya.MFnDependencyNode(MObjParentShape) '''if MFnDependencyNodeParentShape.typeName == 'mnt_locator':''' # Gets Local matrix localMatrix = MFnDagTransNode.transformationMatrix() # _________________ # Gets Offset Matrix offsetMatrixAttr = MFnDependencyParentNode.attribute('offsetParentMatrix') offsetMatrixPlug = OpenMaya.MPlug(MObjParent, offsetMatrixAttr) offsetMatrixPlugObj = offsetMatrixPlug.asMObject() offsetMatrixData = OpenMaya.MFnMatrixData(offsetMatrixPlugObj) offsetMatrix = offsetMatrixData.matrix() # ________________________ # Calculates final matrix outputMatrix = localMatrix.__mul__(offsetMatrix).inverse() # _______________________ # Adds position to node data if data.dottedLine == False: data.pointArray.append(OpenMaya.MPoint(0,0,0)) data.pointArray.append(OpenMaya.MPoint(outputMatrix[12], outputMatrix[13], outputMatrix[14])) else: dotsNumber = OpenMaya.MFnDependencyNode(MObj).findPlug('dots_number', False).asInt() for i in range(0, 2 * dotsNumber): u = float(i)/(2 * dotsNumber) point = OpenMaya.MPoint(u * outputMatrix[12], u * outputMatrix[13], u * outputMatrix[14]) data.pointArray.append(point) # __________________________ except: pass # ___________________________________________ # Manages billboards textureManager = MyTextureManager() status = OpenMayaUI.M3dView.displayStatus(objPath) if iconType < 6: if status == OpenMayaUI.M3dView.kLead or status == OpenMayaUI.M3dView.kActive: if self.getHighlightState(fnMObjParent.name()) == True: texture = textureManager.acquireTexture(MntLocatorNode.iconFolder + 'mnt' + typeList[iconType] + 'Yellow.png') else: texture = textureManager.acquireTexture(MntLocatorNode.iconFolder + 'mnt' + typeList[iconType] + 'Red.png') if status == OpenMayaUI.M3dView.kActiveAffected: texture = textureManager.acquireTexture(MntLocatorNode.iconFolder + 'mnt' + typeList[iconType] + 'Green.png') if status == OpenMayaUI.M3dView.kDormant: texture = textureManager.acquireTexture(MntLocatorNode.iconFolder + 'mnt' + typeList[iconType] + 'Blue.png') textureD = texture.textureDescription() # __________________ if iconType >= 6 or label != '': if status == OpenMayaUI.M3dView.kLead or status == OpenMayaUI.M3dView.kActive: data.color = OpenMaya.MColor((1.0, 0.7, 0.2, opacity + 0.2)) if status == OpenMayaUI.M3dView.kActiveAffected: data.color = OpenMaya.MColor((1.0, 0.2, 0.2, opacity + 0.1)) if status == OpenMayaUI.M3dView.kDormant: data.color = OpenMaya.MColor((color[0], color[1], color[2], opacity)) if iconType == 8: self.createCircle3DBuffer(size/2, (localPositionX, localPositionY, localPositionZ), iconMainAxis) view = OpenMayaUI.M3dView.active3dView() objWorldMatrix = objPath.exclusiveMatrix() cameraObject = OpenMaya.MFnCamera(cameraPath) cameraWorldMatrix = cameraPath.exclusiveMatrix() camObjvector = OpenMaya.MVector( cameraWorldMatrix[12] - objWorldMatrix[12],\ cameraWorldMatrix[13] - objWorldMatrix[13],\ cameraWorldMatrix[14] - objWorldMatrix[14]) if isAreaVisible == False: areaOpacity = 0.0 else: areaOpacity = 1.0 viewWidth = OpenMayaUI.M3dView.portWidth(view) viewHeight = OpenMayaUI.M3dView.portHeight(view) localMatrix = OpenMaya.MMatrix(((1, 0, 0,0),\ (0, 1, 0,0),\ (0, 0, 1,0),\ (localPositionX, localPositionY, localPositionZ, 1))) tmpMatrix = localMatrix.__mul__(objWorldMatrix) if cameraObject.isOrtho() == False: factor = (camObjvector.length() / cameraObject.focalLength) / (float(viewWidth) / float(viewHeight)) * 0.5 else: factor = (cameraObject.orthoWidth) / (float(viewWidth) / float(viewHeight))/80 if iconType < 6: data.screenPos = view.worldToView(OpenMaya.MPoint(tmpMatrix[12], tmpMatrix[13], tmpMatrix[14])) data.screenSize = 0.5 * textureD.fHeight * size data.texture = texture data.worldSizeX = (data.screenSize / 28) / worldScale[0] * factor data.worldSizeY = (data.screenSize / 28) / worldScale[1] * factor data.worldSizeZ = (data.screenSize / 28) / worldScale[2] * factor #point = OpenMaya.MPoint() #direction = OpenMaya.MVector() #view.viewToWorld(int(data.screenSize), int(data.screenSize), point, direction) #print(point) #print(direction) #data.worldSizeX = point[0] #data.worldSizeY = point[1] #data.worldSizeZ = point[2] data.areaOpacity = areaOpacity # Manages 3D icons main axis data.upVector = OpenMaya.MVector(0, 0, 0) if iconMainAxis == 0: data.upVector = OpenMaya.MVector(1, 0, 0) elif iconMainAxis == 1: data.upVector = OpenMaya.MVector(0, 1, 0) else: data.upVector = OpenMaya.MVector(0, 0, 1) # __________________________ data.size = size data.iconType = iconType data.localPosition = OpenMaya.MPoint(localPositionX, localPositionY, localPositionZ) data.label = label data.interactiveRefresh = OpenMaya.MFnDependencyNode(MObj).findPlug('interactiveRefresh', False).asBool() return data
def prepareForDraw(path, camera_path, frame_context, previous_data, viewport_version): """ prepare for draw :param path - node path (MDagPath) :param camera_path - camera node path (MDagPath) :param frame_context - frame context (OpenMayaRender.MFrameContext) :param previous_data - user data (OpenMayaRender.MUserData) :param viewport_version - viewport version (int) """ from camerahudlib.private.plugin import Plugin # re-initialize data data = previous_data if not isinstance(data, PluginData): data = PluginData() # get used node node = path.node() if node.isNull(): return None # get render manager plug = OpenMaya.MPlug(node, Plugin.aHudIndex) hud_index = plug.asInt() if hud_index < 0: return None manager = PluginDrawManager(hud_index) data.manager = manager resolution_width = manager.width() resolution_height = manager.height() resolution_aspect = float(resolution_width) / float(resolution_height) vertical_resolution_aperture = 1.0 horizontal_resolution_aperture = 1.0 data.resolutionWidth = resolution_width data.resolutionHeight = resolution_height # update viewport canvas rectangle if frame_context is None: view = OpenMayaUI.M3dView.active3dView() viewport_width = view.portWidth() viewport_height = view.portHeight() viewport_x = viewport_width * 0.5 viewport_y = viewport_height * 0.5 else: origin_x, origin_y, viewport_width, viewport_height = frame_context.getViewportDimensions( ) viewport_x = origin_x + viewport_width * 0.5 viewport_y = origin_y + viewport_height * 0.5 data.width = viewport_width data.height = viewport_height data.viewport.apply(viewport_x, viewport_y, viewport_width, viewport_height) data.port.inherit(data.viewport) # update camera option camera = OpenMaya.MFnCamera(camera_path) if camera.panZoomEnabled: zoom = camera.zoom pan_x = camera.horizontalPan pan_y = camera.verticalPan else: zoom = 1.0 pan_x = 0.0 pan_y = 0.0 lens_squeeze_ratio = camera.lensSqueezeRatio horizontal_film_aperture = camera.horizontalFilmAperture vertical_film_aperture = camera.verticalFilmAperture data.camera = camera_path.fullPathName().rsplit("|", 2)[1] data.cameraFocalLenght = camera.focalLength data.cameraFocusDistance = camera.focusDistance # calculate aspect ratio aspect_ratio = horizontal_film_aperture / vertical_film_aperture viewport_aspect_ratio = data.viewport.aspectRatio() # calculate film fit film_fit = camera.filmFit resolution_film_fit = film_fit if film_fit == OpenMaya.MFnCamera.kFillFilmFit: if viewport_aspect_ratio < aspect_ratio: film_fit = OpenMaya.MFnCamera.kVerticalFilmFit else: film_fit = OpenMaya.MFnCamera.kHorizontalFilmFit if resolution_aspect < aspect_ratio: resolution_film_fit = OpenMaya.MFnCamera.kVerticalFilmFit else: resolution_film_fit = OpenMaya.MFnCamera.kHorizontalFilmFit elif film_fit == OpenMaya.MFnCamera.kOverscanFilmFit: if viewport_aspect_ratio < aspect_ratio: film_fit = OpenMaya.MFnCamera.kHorizontalFilmFit else: film_fit = OpenMaya.MFnCamera.kVerticalFilmFit if resolution_aspect < aspect_ratio: resolution_film_fit = OpenMaya.MFnCamera.kHorizontalFilmFit else: resolution_film_fit = OpenMaya.MFnCamera.kVerticalFilmFit # calculate resolution aperture if resolution_film_fit == OpenMaya.MFnCamera.kHorizontalFilmFit: horizontal_resolution_aperture = horizontal_film_aperture vertical_resolution_aperture = horizontal_film_aperture / resolution_aspect elif resolution_film_fit == OpenMaya.MFnCamera.kVerticalFilmFit: vertical_resolution_aperture = vertical_film_aperture horizontal_resolution_aperture = vertical_film_aperture * resolution_aspect data.fit = film_fit # calculate pixel scale if film_fit == OpenMaya.MFnCamera.kHorizontalFilmFit: pixel_scale = data.viewport.width( ) / camera.overscan / horizontal_film_aperture / zoom pixel_resolution_scale = data.viewport.width( ) / camera.overscan / horizontal_resolution_aperture / zoom else: pixel_scale = data.viewport.height( ) / camera.overscan / vertical_film_aperture / zoom pixel_resolution_scale = data.viewport.height( ) / camera.overscan / vertical_resolution_aperture / zoom pixel_scale_x = pixel_scale * lens_squeeze_ratio pixel_resolution_scale_x = pixel_resolution_scale * lens_squeeze_ratio data.pixelScale = pixel_scale data.pixelResolutionScale = pixel_resolution_scale # update port gate position data.port.move(data.port.x() - (pan_x * pixel_scale), data.port.y() - (pan_y * pixel_scale)) # update film canvas rectangle width = (horizontal_film_aperture * pixel_scale_x) height = (vertical_film_aperture * pixel_scale) data.film.apply(data.port.x(), data.port.y(), width, height) # calculate interface fit to resolution scale data.scale = ((viewport_width / width) / (viewport_height / height)) # update image canvas rectangle width = (horizontal_film_aperture * pixel_scale_x) height = (vertical_film_aperture * pixel_scale) data.image.apply(data.port.x(), data.port.y(), width, height) # update render canvas rectangle width = (horizontal_resolution_aperture * pixel_resolution_scale_x) height = (vertical_resolution_aperture * pixel_resolution_scale) data.render.apply(data.port.x(), data.port.y(), width, height) # update safe action canvas rectangle width = (horizontal_film_aperture * pixel_scale_x) * 0.9 height = (vertical_film_aperture * pixel_scale) * 0.9 data.safeAction.apply(data.port.x(), data.port.y(), width, height) # update safe title canvas rectangle width = (horizontal_film_aperture * pixel_scale_x) * 0.8 height = (vertical_film_aperture * pixel_scale) * 0.8 data.safeTitle.apply(data.port.x(), data.port.y(), width, height) # update safe render title canvas rectangle width = data.render.width() * 0.8 height = data.render.height() * 0.8 data.renderSafeTitle.apply(data.port.x(), data.port.y(), width, height) # update safe render action canvas rectangle width = data.render.width() * 0.9 height = data.render.height() * 0.9 data.renderSafeAction.apply(data.port.x(), data.port.y(), width, height) # update region rectangle for each drawing request for request_key in data.manager: request = data.manager[request_key] if request.uiDraw: gate = data.gate(request.uiResolutionGate) real_x, real_y, real_width, real_height = request.uiRegionPosition.x, request.uiRegionPosition.y, request.uiRegion.x, request.uiRegion.y # calculate real region value width_percentage = (gate.width() / 100.0) height_percentage = (gate.height() / 100.0) real_x *= width_percentage real_y *= height_percentage real_width *= width_percentage real_height *= height_percentage # calculate region position if request.uiHorisontalAttach == constants.kAttachHorizontalLeft: x = (gate.x() - (gate.width() * 0.5) + real_width * 0.5) + real_x elif request.uiHorisontalAttach == constants.kAttachHorizontalRight: x = (gate.x() + (gate.width() * 0.5) - real_width * 0.5) + real_x elif request.uiHorisontalAttach == constants.kAttachHorizontalMiddle: x = gate.x() + real_x else: x = real_x if request.uiVerticalAttach == constants.kAttachVerticalTop: y = (gate.y() + (gate.height() * 0.5) - real_height * 0.5) + real_y elif request.uiVerticalAttach == constants.kAttachVerticalBottom: y = (gate.y() - (gate.height() * 0.5) + real_height * 0.5) + real_y elif request.uiVerticalAttach == constants.kAttachVerticalMiddle: y = gate.y() + real_y else: y = real_y width = int(real_width) height = int(real_height) # apply region rectangle request.region.apply(x, y, width, height) # update region position list size = len(request.uiRegionPositionList) point_index = 0 for point in request.uiPositionList: if point_index >= size: region_point = OpenMaya.MPoint() request.uiRegionPositionList.append(region_point) size += 1 else: region_point = request.uiRegionPositionList[ point_index] # calculate real position value region_point.x = point.x * (real_width / 100.0) region_point.y = point.y * (real_height / 100.0) point_index += 1 request.uiRegionPositionList = request.uiRegionPositionList[: point_index + 1] return data
# iterate over each selected object and use the appropriate function set # to query type specific data for i in range(selection.length()): if i > 0: print('-----') obj = selection.getDependNode(i) #return MObject print("API Type: {0}".format(obj.apiTypeStr)) if obj.hasFn(om.MFn.kDependencyNode ): #Check if function set is compatible with the MObject depend_fn = om.MFnDependencyNode( obj) # Attach supported function set to MObject print("Dependency Node: {0}".format( depend_fn.name())) # use function set to query data if obj.hasFn(om.MFn.kTransform): transform_fn = om.MFnTransform(obj) print("Translation: {0}".format( transform_fn.translation(om.MSpace.kTransform))) elif obj.hasFn(om.MFn.kMesh): mesh_fn = om.MFnMesh(obj) print("Mesh vertices: {0}".format(mesh_fn.getVertices())) elif obj.hasFn(om.MFn.kCamera): camera_fn = om.MFnCamera(obj) print("Clipping Planes: {0}, {1}".format( camera_fn.nearClippingPlane, camera_fn.farClippingPlane))
def J_exportSelections2json(frameRange=''): if frameRange == "": frameRange = [ cmds.playbackOptions(query=True, minTime=True), cmds.playbackOptions(query=True, maxTime=True) ] sel = om.MSelectionList(om.MGlobal.getActiveSelectionList()) #sel=cmds.ls(sl=True) for item in range(0, sel.length()): outData = {} filePath = cmds.file(query=True, sceneName=True).replace( cmds.file(query=True, sceneName=True, shortName=True), '') if cmds.file(query=True, sceneName=True, shortName=True) == '': cmds.confirmDialog(title=u'错误', message=u'文件未保存,或者需要另存为mb格式', button='好吧') return jsonFile = filePath + '/' + cmds.file( query=True, sceneName=True, shortName=True)[0:-3] + sel.getComponent( item)[0].partialPathName().replace(":", "") + "@" + str( frameRange[0]) + "_" + str(frameRange[1]) + '.txt' frameData = [] if sel.getComponent(item)[0].extendToShape().apiType() == 250: cameraNode = om.MFnCamera( sel.getComponent(item)[0].extendToShape()) aOfv = cameraNode.horizontalFieldOfView() for i in range(int(frameRange[0]), int(frameRange[1])): cmds.currentTime(i) trNode = om.MTransformationMatrix( sel.getComponent(item)[0].inclusiveMatrix()) position = [ trNode.translation(4)[0] * (-0.01), trNode.translation(4)[1] * (0.01), trNode.translation(4)[2] * (0.01) ] rotationQuaternion = [ trNode.rotation(True)[0] * (-1), trNode.rotation(True)[1] * (-1), trNode.rotation(True)[2], trNode.rotation(True)[3] ] frameData.append({ 'pos': position, 'rot': rotationQuaternion, 'fov': str( math.atan(math.tan(aOfv * 0.5) / 1.7777778) * 360 / 3.141592) }) outData['frame'] = frameData elif sel.getComponent(item)[0].extendToShape().apiType() == 296: for i in range(int(frameRange[0]), int(frameRange[1])): cmds.currentTime(i) trNode = om.MTransformationMatrix( sel.getComponent(item)[0].inclusiveMatrix()) position = [ trNode.translation(4)[0] * (-0.01), trNode.translation(4)[1] * (0.01), trNode.translation(4)[2] * (0.01) ] rotationQuaternion = [ trNode.rotation(True)[0] * (-1), trNode.rotation(True)[1] * (-1), trNode.rotation(True)[2], trNode.rotation(True)[3] ] scale = [ trNode.scale(4)[0], trNode.scale(4)[1], trNode.scale(4)[2] ] frameData.append({ 'pos': position, 'rot': rotationQuaternion, 'scale': scale }) outData['frame'] = frameData outFile = open(jsonFile, 'w') outFile.write( json.dumps([outData], encoding='utf-8', ensure_ascii=False)) outFile.close() os.startfile(filePath)
def addUIDrawables(self, objPath, drawManager, frameContext, data): DEBUG_C = 1 if (DEBUG_C): print( "glDrawDrawOverride________________________________________addUIDrawables - GET DATA" ) #glDrawData* data = (glDrawData*)dataRaw; #if (!data) { return; } cameraFn = ompy.MFnCamera(data.cameraPath) cameraTrsf = ompy.MFnDagNode(cameraFn.parent(0)) camMatrix = MMatrixToMFloatMatrix(cameraTrsf.transformationMatrix()) camPlaneNearDistance = cameraFn.nearClippingPlane camPlaneFarDistance = cameraFn.farClippingPlane if (DEBUG_C): print( "glDrawDrawOverride________________________________________addUIDrawables - DRAW" ) drawManager.beginDrawable() iCoords = 0 exitDrawing = False for i in range(0, len(data.shapes)): #________________________________________GET COORDS FOR BUILDING ONE SHAPE nbrElementForBuild = self.shapeToNbrElemForBuild[data.shapes[i]] coordsForBuild = ompy.MFloatPointArray() ssOffsetsForBuild = ompy.MFloatVectorArray() for j in range(0, nbrElementForBuild): if (len(data.coords) <= iCoords): exitDrawing = True break coordsForBuild.append(data.coords[iCoords]) ssOffsetsForBuild.append(data.screenSpaceOffsets[iCoords]) iCoords += 1 if (exitDrawing == True): break #________________________________________DRAW BUILD CONVERT COORDS distIncr = 0.001 foregroundDist = camPlaneNearDistance + 0.02 backgroundDist = camPlaneFarDistance - 0.02 coords = ompy.MFloatPointArray() size = 1.0 thickness = 1.0 if ((data.drawPlaneMode == 1) and (0 < coordsForBuild.length())): #FOREGROUND coords = snapCoordsOnCameraPlane(camMatrix, foregroundDist, coordsForBuild) size = snapLengthOnCameraPlane(camMatrix, foregroundDist, coordsForBuild[0], data.sizes[i]) #thickness = data.thicknesses[i] foregroundDist += distIncr elif ((data.drawPlaneMode == 2) and (0 < coordsForBuild.length())): #sBACKGROUND coords = snapCoordsOnCameraPlane(camMatrix, backgroundDist, coordsForBuild) size = snapLengthOnCameraPlane(camMatrix, backgroundDist, coordsForBuild[0], data.sizes[i]) #thickness = data.thicknesses[i] backgroundDist -= distIncr else: coords = coordsForBuild size = data.sizes[i] #thickness = data.thicknesses[i] ssOffsets = ompy.MFloatVectorArray(ssOffsetsForBuild) #________________________________________DRAW SHAPE if (self.shapesNames[data.shapes[i]] == "segment"): glDrawSegments(drawManager, camMatrix, coords, ssOffsets, data.colors[i], 0, 1.0) elif (self.shapesNames[data.shapes[i]] == "triangle"): pass #glDrawTriangles( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.pColors[i]) elif (self.shapesNames[data.shapes[i]] == "pointTriangle"): pass #glDrawPointTriangle( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.fills[i], size, thickness) elif (self.shapesNames[data.shapes[i]] == "pointSquare"): pass #glDrawPointSquare( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.fills[i], size, thickness) elif (self.shapesNames[data.shapes[i]] == "pointCircle"): pass #glDrawPointCircle( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.fills[i], size, thickness) elif (self.shapesNames[data.shapes[i]] == "pointStar"): pass #glDrawPointStar( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.fills[i], size, thickness) elif (self.shapesNames[data.shapes[i]] == "pointCross"): pass #glDrawPointCross( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.fills[i], size, thickness) elif (self.shapesNames[data.shapes[i]] == "vector"): pass #glDrawVector( drawManager, camMatrix, coords, ssOffsets, data.colors[i], data.fills[i], size, thickness) elif (self.shapesNames[data.shapes[i]] == "text"): glDrawText(drawManager, camMatrix, coords, ssOffsets, data.names[i], data.colors[i], True, size, 1.0) drawManager.endDrawable()