-
-
Save aigcoder/459930c742781581a51cd2a2e84759c9 to your computer and use it in GitHub Desktop.
minimalistic maya locator with viewport 2.0 draw override
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
| # encoding: utf8 | |
| import maya.api.OpenMaya as om | |
| import maya.api.OpenMayaUI as omui | |
| import maya.api.OpenMayaRender as omr | |
| def maya_useNewAPI(): | |
| pass | |
| class VP2Locator(omui.MPxLocatorNode): | |
| id = om.MTypeId(0x83000) | |
| drawDbClassification = 'drawdb/geometry/vp2locator' | |
| drawRegistrantId = 'vp2locator_ri' | |
| @staticmethod | |
| def creator(): | |
| return VP2Locator() | |
| @staticmethod | |
| def initialize(): | |
| #attributes are created here | |
| pass | |
| def __init__(self): | |
| omui.MPxLocatorNode.__init__(self) | |
| class VP2LocatorData(om.MUserData): | |
| def __init__(self): | |
| om.MUserData.__init__(self, False) | |
| self.color = om.MColor((0.6, 0.2, 0.5)) | |
| self.lines = om.MPointArray() | |
| self.lines.append(om.MPoint(1, 1, 0)) | |
| self.lines.append(om.MPoint(1, -1, 0)) | |
| self.lines.append(om.MPoint(-1, -1, 0)) | |
| self.lines.append(om.MPoint(-1, 1, 0)) | |
| self.lines.append(om.MPoint(-1.2, 0, 0)) | |
| self.lines.append(om.MPoint(1.2, 0, 0)) | |
| class VP2LocatorDrawOverride(omr.MPxDrawOverride): | |
| @staticmethod | |
| def creator(obj): | |
| return VP2LocatorDrawOverride(obj) | |
| def __init__(self, obj): | |
| omr.MPxDrawOverride.__init__(self, obj, None, False) | |
| def supportedDrawAPIs(self): | |
| return omr.MRenderer.kOpenGL | omr.MRenderer.kDirectX11 | omr.MRenderer.kOpenGLCoreProfile | |
| def prepareForDraw(self, objPath, cameraPath, frameContext, oldData): | |
| data = oldData | |
| if not isinstance(data, VP2LocatorData): | |
| data = VP2LocatorData() | |
| # my drawing is static, no need to modify data | |
| return data | |
| def hasUIDrawables(self): | |
| return True | |
| def addUIDrawables(self, objPath, drawManager, frameContext, data): | |
| """ | |
| @type objPath: om.MDagPath | |
| @type drawManager: omr.MUIDrawManager | |
| @type frameContext: omr.MFrameContext | |
| @type data: VP2LocatorData | |
| """ | |
| locator_data = data | |
| if not isinstance(locator_data, VP2LocatorData): | |
| return | |
| drawManager.beginDrawable() | |
| drawManager.setColor(locator_data.color) | |
| drawManager.mesh(omr.MUIDrawManager.kLines, locator_data.lines) | |
| drawManager.endDrawable() | |
| def initializePlugin(obj): | |
| plugin = om.MFnPlugin(obj, 'ilya radovilsky', '1.0') | |
| plugin.registerNode('vp2Locator', VP2Locator.id, VP2Locator.creator, VP2Locator.initialize, | |
| om.MPxNode.kLocatorNode, VP2Locator.drawDbClassification) | |
| omr.MDrawRegistry.registerDrawOverrideCreator(VP2Locator.drawDbClassification, VP2Locator.drawRegistrantId, | |
| VP2LocatorDrawOverride.creator) | |
| def uninitializePlugin(obj): | |
| plugin = om.MFnPlugin(obj) | |
| plugin.deregisterNode(VP2Locator.id) | |
| omr.MDrawRegistry.deregisterDrawOverrideCreator(VP2Locator.drawDbClassification, VP2Locator.drawRegistrantId) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment