Maya的Mel Command命令插件详解
好酷屋教程网小编为您收集和整理了Maya的Mel Command命令插件详解的相关教程:MelCommand命令插件Mel(MayaEmbededLanguage)命令指的能够在命令解释器里运行的命令。所有的自定义命令要从MpxCommand类继承,看如下代码MyCommand.hvie
MelCommand命令插件Mel(MayaEmbededLanguage)命令指的能够在命令解释器里运行的命令。所有的自定义命令要从MpxCommand类继承,看如下代码MyCommand.hviewplaincopyprint?#ifndef__MYCOMMAND_H__#define__MYCOMMAND_H__#ifdefWIN32#ifndefNT_pLUGIN#defineNT_pLUGIN#endif#endif#include#include#include#include#include#include////brief///thesimplepxCommand.classSimpleCommand:publicMpxCommand{public:////brief///constructor&&destructorSimpleCommand(){std::cout<<“SimpleCommandConstructed!”<<std::endl;}virtual~SimpleCommand(){std::cout<<“~SimpleCommandDestructed!”<<std::endl;}////brief///executesthiscommand.////param///args(in)theargumentlistspecified////ret///returnMS::kSuccessorMS::kFailurevirtualMStatusdoIt(constMArgList&args);////brief///thisfunctionisusedbymayatocreateanewinstanceofthisclass.staticvoid*creator(){returnnewSimpleCommand;}};#endif///__MYCOMMAND_H__#ifndef__MYCOMMAND_H__#define__MYCOMMAND_H__#ifdefWIN32#ifndefNT_pLUGIN#defineNT_pLUGIN#endif#endif#include#include#include#include#include#include////brief///thesimplepxCommand.classSimpleCommand:publicMpxCommand{public:////brief///constructor&&destructorSimpleCommand(){std::cout<<“SimpleCommandConstructed!”<<std::endl;}virtual~SimpleCommand(){std::cout<<“~SimpleCommandDestructed!”<<std::endl;}////brief///executesthiscommand.////param///args(in)theargumentlistspecified////ret///returnMS::kSuccessorMS::kFailurevirtualMStatusdoIt(constMArgList&args);////brief///thisfunctionisusedbymayatocreateanewinstanceofthisclass.staticvoid*creator(){returnnewSimpleCommand;}};#endif///__MYCOMMAND_H__SimpleCommand类需要改写virtual函数doIt(constMArglist&args);staticvoid*creator()用于生成一个类对象.下面看一下SimpleCommand的实现代码SimpleCommand.cppviewplaincopyprint?#include#include”MyCommand.h”MStatusSimpleCommand::doIt(constMArgList&args){std::cout<<“executeSimpleCommand:”<<std::endl;returnMS::kSuccess;}#include#include”MyCommand.h”MStatusSimpleCommand::doIt(constMArgList&args){std::cout<<“executeSimpleCommand:”<<std::endl;returnMS::kSuccess;}可以看到SimpleCommand::doIt()只是简单地打印出字符串,这是为观察SimpleCommand对象的行为做准备.SimpleCommand类的实例用于执行具体的任务,那么该对象由谁创建并触发doIt()呢?命令对象的注册我们需要注册该命令对象,并且在输入命令的时候(这里使用”HelloWorld”),maya创建该对象并触发doIt().看如下注册代码plugMain.cppviewplaincopyprint?#include”MyCommand.h”#include#include#ifdefWIN32#defineMLL_EXpORT__declspec(dllexport)#else#defineMLL_EXpORT#endif////brief///initializeplugin////param///obj(in)thepluginhandle////ret///returnMS::kSuccessifOK.////NOTE:///invokedonlyoncebyMayawhenDLLisloaded.MLL_EXpORTMStatusinitializeplugin(MObjectobj){MFnpluginplugin(obj,”JettHuang”,”1.0″,”Any”);///registerthecommandMStatusstatus=plugin.registerCommand(“HelloWorld”,SimpleCommand::creator);if(!status){status.perror(“Failedtoregister/”HelloWorld/”/n”);returnstatus;}else{std::cout<<“initializeplugin”<<std::endl;}returnstatus;}////brief///unintializeplugin////param///obj(in)thepluginhandletoun-register////ret///MS::kSuccessifOK.MLL_EXpORTMStatusuninitializeplugin(MObjectobj){MFnpluginplugin(obj);///deregisterthepxCommandMStatusstatus=plugin.deregisterCommand(“HelloWorld”);if(!status){status.perror(“failedtoderegister/”HelloWorld/”/n”);returnstatus;}else{std::cout<<“uninitializeplugin”<<std::endl;}returnstatus;}#include”MyCommand.h”#include#include#ifdefWIN32#defineMLL_EXpORT__declspec(dllexport)#else#defineMLL_EXpORT#endif////brief///initializeplugin////param///obj(in)thepluginhandle////ret///returnMS::kSuccessifOK.////NOTE:///invokedonlyoncebyMayawhenDLLisloaded.MLL_EXpORTMStatusinitializeplugin(MObjectobj){MFnpluginplugin(obj,”JettHuang”,”1.0″,”Any”);///registerthecommandMStatusstatus=plugin.registerCommand(“HelloWorld”,SimpleCommand::creator);if(!status){status.perror(“Failedtoregister/”HelloWorld/”/n”);returnstatus;}else{std::cout<<“initializeplugin”<<std::endl;}returnstatus;}////brief///unintializeplugin////param///obj(in)thepluginhandletoun-register////ret///MS::kSuccessifOK.MLL_EXpORTMStatusuninitializeplugin(MObjectobj){MFnpluginplugin(obj);///deregisterthepxCommandMStatusstatus=plugin.deregisterCommand(“HelloWorld”);if(!status){status.perror(“failedtoderegister/”HelloWorld/”/n”);returnstatus;}else{std::cout<<“uninitializeplugin”<<std::endl;}returnstatus;}Maya中的插件是一个动态链接库,只不过后缀名为mll.MLL_EXpORTMStatusinitializeplugin(MObjectobj)和MLL_EXpORTMStatusuninitializeplugin(MObjectobj)是该DLL的导出函数,前者将在DLL加载时被调用;后者将在DLL被卸载时调用.///registerthecommandMStatusstatus=plugin.registerCommand(“HelloWorld”,SimpleCommand::creator);注册了命令”HelloWorld”,并告诉Maya:函数SimpleCommand::creator()将会返回命令对象.///deregisterthepxCommandMStatusstatus=plugin.deregisterCommand(“HelloWorld”);注销命令.完整的SourceCode下载URL:http://download.csdn.net/source/2700425运行并观察1.将Build成功的插件MyCommand.mll放入Maya的安装目录下的/bin/plug-ins/;2.在Maya中加载插件,菜单路径为:Window–>Settings/preferences–>pluginManager;3.在脚本命令窗口输入:HelloWorld4.查看输入结果由此看出,每执行一次HelloWorld,都会创建一个SimpleCommand对象实例,执行完毕后销毁!
以上就是好酷屋教程网小编为您收集和整理的Maya的Mel Command命令插件详解相关内容,如果对您有帮助,请帮忙分享这篇文章^_^
本文来源: https://www.haoku5.com/IT/643ba59d82a73733b107bd9f.html
相关推荐