博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
七、context command
阅读量:5325 次
发布时间:2019-06-14

本文共 5149 字,大约阅读时间需要 17 分钟。

context command是用来新建自己的工具,可以调用OPENGL,获取鼠标操作函数,在view窗口画自己想画的东西。(我是这麽理解的,可以以后再确定一下)

下面是一个context command的例子,通过例子来说明context command的代码怎么写,又怎么样来activate。

 

包含的头文件:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

 

1. 定义继承于MPxContext的类:

const char helpString[] =            "Click with left button or drag with middle button to select";class marqueeContext : public MPxContext{public:    marqueeContext();    virtual void    toolOnSetup( MEvent & event );    // Default viewport or hardware viewport methods override, will not be triggered in viewport 2.0.    virtual MStatus    doPress( MEvent & event );    virtual MStatus    doDrag( MEvent & event );    virtual MStatus    doRelease( MEvent & event );    virtual MStatus    doEnterRegion( MEvent & event );    // Viewport 2.0 methods, will only be triggered in viewport 2.0.    virtual MStatus        doPress ( MEvent & event,     MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context);    virtual MStatus        doRelease( MEvent & event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context);    virtual MStatus        doDrag ( MEvent & event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context);private:    // Marquee draw method in default viewport or hardware viewport with immediate OpenGL call    void                    drawMarqueeGL();    // Common operation to handle when pressed    void                    doPressCommon( MEvent & event );    // Common operation to handle when released    void                    doReleaseCommon( MEvent & event );    short                    start_x, start_y;    short                    last_x, last_y;    bool                    fsDrawn;    MGlobal::ListAdjustment    listAdjustment;    M3dView                    view;};

其中doPress(), doRelease(), doDrag()函数,为函数重载,以方便不同版本的view进行绘制。

doPressCommon(), doReleaseCommon(), drawMarqueeGL()函数为上面三个函数不同版本之间的共同部分。以doDrag()为例子,具体参看document。

MStatus marqueeContext::doDrag( MEvent & event )//// Drag out the marquee (using OpenGL)//{    view.beginXorDrawing();    if (fsDrawn) {        // Redraw the marquee at its old position to erase it.        drawMarqueeGL();    }    fsDrawn = true;    //    Get the marquee's new end position.    event.getPosition( last_x, last_y );    // Draw the marquee at its new position.    drawMarqueeGL();    view.endXorDrawing();    return MS::kSuccess;        }

void marqueeContext::drawMarqueeGL()

{
  glBegin( GL_LINE_LOOP );
    glVertex2i( start_x, start_y );
    glVertex2i( last_x, start_y );
    glVertex2i( last_x, last_y );
    glVertex2i( start_x, last_y );
  glEnd();
}

2. 编好自己的MPxContext之后,创建MPxContextCommand的子类来创建context 命令,该命令用来创建context工具。

class marqueeContextCmd : public MPxContextCommand{public:                            marqueeContextCmd();    virtual MPxContext*    makeObj();    static    void*        creator();};marqueeContextCmd::marqueeContextCmd() {}MPxContext* marqueeContextCmd::makeObj(){    return new marqueeContext();}void* marqueeContextCmd::creator(){    return new marqueeContextCmd;}

3. 最后通过MFnPlugin函数注册context command:

MStatus initializePlugin( MObject obj ){    MStatus        status;    MFnPlugin    plugin( obj, PLUGIN_COMPANY, "12.0", "Any");    status = plugin.registerContextCommand( "marqueeToolContext",                                            marqueeContextCmd::creator );    return status;}MStatus uninitializePlugin( MObject obj ){    MStatus        status;    MFnPlugin    plugin( obj );    status = plugin.deregisterContextCommand( "marqueeToolContext" );    return status;}

4. Adding a context command to the Maya shelf

There are two ways to "activate" or make your context the current context in Maya. The first is through the use of the setToolTo command. This command takes the name of a context (tool) and makes it the current context.

A second method is by making an icon to represent your context and putting it in the Maya tool shelf. The Maya tool shelf can store two kinds of buttons, command buttons and tool buttons. When the tool is activated, its icon is displayed next to the standard Maya tools in the toolbar.

The following is a set of MEL commands you can use to create a context and tool button for the context.

marqueeToolContext marqueeToolContext1;setParent Shelf1;    //注意这的shelf1应该用shelf子目录的名字代替,例如Custom toolButton -cl toolCluster -t marqueeToolContext1 -i1 "marqueeTool.xpm" marqueeTool1;

This MEL code instantiates an instance of the marqueeToolContext and adds it to the "Common" tools shelf.

marqueeTool.xpm, the icon for the tool, must be in the XBMLANGPATH to be found and added to the UI. If it is not found, a blank spot will appear on the shelf, but the tool will still be usable.

This code could either be sourced by hand from the MEL command window, or it could be invoked with in the initializePlugin() method of the plug-in.

 

转载于:https://www.cnblogs.com/bubbler/p/5156788.html

你可能感兴趣的文章
给C#学习者的建议 - CLR Via C# 读后感
查看>>
Recover Binary Search Tree
查看>>
Java 实践:生产者与消费者
查看>>
[转]IOCP--Socket IO模型终结篇
查看>>
js 获取视频的第一帧
查看>>
各种正则验证
查看>>
观察者模式(Observer)
查看>>
python中numpy.r_和numpy.c_
查看>>
egret3D与2D混合开发,画布尺寸不一致的问题
查看>>
freebsd 实现 tab 命令 补全 命令 提示
查看>>
struts1和struts2的区别
查看>>
函数之匿名函数
查看>>
shell习题第16题:查用户
查看>>
实验4 [bx]和loop的使用
查看>>
Redis常用命令
查看>>
2018.11.06 bzoj1040: [ZJOI2008]骑士(树形dp)
查看>>
2019.02.15 bzoj5210: 最大连通子块和(链分治+ddp)
查看>>
redis cluster 集群资料
查看>>
微软职位内部推荐-Sr. SE - Office incubation
查看>>
微软职位内部推荐-SOFTWARE ENGINEER II
查看>>