凌雪
2018-07-30
来源 :网络
阅读 1445
评论 0
摘要:本文将带你了解Maya教程之Maya插件教程,希望本文对大家学Maya有所帮助
本文将带你了解Maya教程之Maya插件教程,希望本文对大家学Maya有所帮助
这里主要参考了一个例子,实现创建Maya插件的简单流程。原作只实现了MEL和C++,本文补充了Python版本,并说明了C++编写的.mll插件的调用流程。插件的背景如下:
大多数人听说Maya 2010问世之后,都是欣喜万分,终于可以感受新版本的Maya了。唯独Boss Fang听到这个消息后,一筹莫展,并怨恨交加。下面的三个插件都是实现这样一个想法。
(1)MEL版本
[cpp] view plain copy print?float $maya_version = 2010; string $boss = "bossFang"; string $person = "bossFang"; if($maya_version == 2010 && $person != $boss) { print("happy : )Enjoy Maya 2010 /n" ); } if($maya_version == 2010 && $person == $boss) { print(":( xxx! xxx! sign, why now? /n"); } float $maya_version = 2010;
string $boss = "bossFang";
string $person = "bossFang";
if($maya_version == 2010 && $person != $boss)
{
print("happy : )Enjoy Maya 2010 /n" );
}
if($maya_version == 2010 && $person == $boss)
{
print(":( xxx! xxx! sign, why now? /n");
}
打开Maya 2010 右下角的Script Editor,并将以上代码贴入,运行结果如下:
(2)Python版本
和MEL类似,代码如下:
[python] view plain copy print?maya_version = 2010 boss = 'bossFang' person = 'bossFang' if (maya_version == 2010 and person != boss): print 'happy : )Enjoy Maya 2010 /n' if (maya_version == 2010 and person == boss): print ':( xxx! xxx! sign, why now? /n' maya_version = 2010
boss = 'bossFang'
person = 'bossFang'
if (maya_version == 2010 and person != boss):
print 'happy : )Enjoy Maya 2010 /n'
if (maya_version == 2010 and person == boss):
print ':( xxx! xxx! sign, why now? /n'
运行结果如下所示:
(3)C++版本
下载Maya Plugin Wizard(网址)。并按照其中的MayaWizardReadme.txt文件安装该插件。
注意:MayaPluginWizard文件夹需要放在* VC/VCWizards,无论是对Regular Visual Studio或Visual Studio Express。
“Please check the versions of Maya that this plug-in is for:”选择自己安装的Maya版本,该插件现在已经支持从7.0到2011各个版本,我选择的是2010版本。
“What is the verder name for this plug-in?”中需要填写的是作者名称,如cgnerds。
“What type of plug-in would you like to create?”选择MEL Command,即可创建MEL命令型插件。
"Please enter the name of your plug-in here"中输入boss,即可执行该插件了。
“What libraries would you like to link with?”中选择需要连接的库。对于我们需要创建的简单插件来说,默认的库就可以了。
单击Finish完成设置。目前该插件默认Maya安装目录为C盘,需要自己修改为合适的盘符。
在boss::doIt()函数中如下代码,实现和(1)同样的功能。
[cpp] view plain copy print?MStatus boss::doIt( const MArgList& args ) // // Description: // implements the MEL boss command. // // Arguments: // args - the argument list that was passes to the command from MEL // // Return Value: // MS::kSuccess - command succeeded // MS::kFailure - command failed (returning this value will cause the // MEL script that is being run to terminate unless the // error is caught using a "catch" statement. // { MStatus stat = MS::kSuccess; MString info; MString boss("BossFang"); MString person("BossFang"); double maya_version = 2010; if(maya_version == 2010 && boss == person) { info = MString( ":( xxx! xxx! why now? /n" ); } if(maya_version == 2010 && boss != person) { info = MString( "happy :) Enjoy maya 2010 /n" ); } //显示字符串,相当于MEL中的print MGlobal::displayInfo(info); // Since this class is derived off of MPxCommand, you can use the // inherited methods to return values and set error messages // setResult( "boss command executed!/n" ); return stat; } MStatus boss::doIt( const MArgList& args )
//
// Description:
// implements the MEL boss command.
//
// Arguments:
// args - the argument list that was passes to the command from MEL
//
// Return Value:
// MS::kSuccess - command succeeded
// MS::kFailure - command failed (returning this value will cause the
// MEL script that is being run to terminate unless the
// error is caught using a "catch" statement.
//
{
MStatus stat = MS::kSuccess;
MString info;
MString boss("BossFang");
MString person("BossFang");
double maya_version = 2010;
if(maya_version == 2010 && boss == person)
{
info = MString( ":( xxx! xxx! why now? /n" );
}
if(maya_version == 2010 && boss != person)
{
info = MString( "happy :) Enjoy maya 2010 /n" );
}
//显示字符串,相当于MEL中的print
MGlobal::displayInfo(info);
// Since this class is derived off of MPxCommand, you can use the
// inherited methods to return values and set error messages
//
setResult( "boss command executed!/n" );
return stat;
}
程序运行后,会生成boss.mll文件,将其拷贝到D:/Program Files/Autodesk/Maya2010/bin/plug-ins目录下,重新打开Maya 2010,执行菜单Window->Settings/Preferences->Plug-in Manager打开插件加载窗口。将boss.mll后面的Loaded打钩,然后再次打开Script Editor,输入boss,显示结果如下:
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之Maya频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号