MAYA MEL帮助文档中文翻译.docx

上传人:b****7 文档编号:9492138 上传时间:2023-02-04 格式:DOCX 页数:13 大小:19.83KB
下载 相关 举报
MAYA MEL帮助文档中文翻译.docx_第1页
第1页 / 共13页
MAYA MEL帮助文档中文翻译.docx_第2页
第2页 / 共13页
MAYA MEL帮助文档中文翻译.docx_第3页
第3页 / 共13页
MAYA MEL帮助文档中文翻译.docx_第4页
第4页 / 共13页
MAYA MEL帮助文档中文翻译.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

MAYA MEL帮助文档中文翻译.docx

《MAYA MEL帮助文档中文翻译.docx》由会员分享,可在线阅读,更多相关《MAYA MEL帮助文档中文翻译.docx(13页珍藏版)》请在冰豆网上搜索。

MAYA MEL帮助文档中文翻译.docx

MAYAMEL帮助文档中文翻译

MAYAMEL帮助文档中文翻译—Chapter1相关背景

2009-12-1919:

45

Chapter1相关背景

一,MEL概况:

MEL是maya内部使用的脚本语言,maya的图形用户界面就是用MEL写成,MEL提供简单的方式来扩展maya的功能。

用maya图形界面能做到的任何事情都能用MEL来自动完成,熟悉MEL能加深对maya的理解。

使用MEL有一定的优势,即使你不会编程语言。

例如:

在maya中利用图形用户界面来完成一些事情是很容易的事情,当你完成一些操作后,脚本编辑框里面会生成一些MEL命令,拖拽这些命令到搁板,maya会在搁板上生成一个按钮,点击这个按钮便执行刚才的操作。

然而,学习MEL将为你开启一个新的世界,MEL可以帮助你制作一些特殊的效果,为你节约很多的时间,这些是用maya图形用户界面很慢做到的。

下面是你可以用MEL来完成的一些例子:

*绕开maya用户界面,创建快捷方式,存取一些高级特性。

*定义maya的用户界面,改变一些基础的默认设置。

*创建属于自己的程序和脚本,以完成模型、动画、动力学和渲染任务。

//原文:

MELOverview

MELTMisascriptinglanguageattheheartofMaya.Maya’suserinterfaceiscreatedusingMEL,andMELprovidesaneasywaytoextendthefunctionalityofMaya.EverythingyoucandousingMaya’sgraphicalinterfacecanbeautomatedandextendedusingMEL.FamiliaritywithMELcandeepenyourunderstandingofandexpertisewithMaya.

YoucantakeadvantageofMELwithoutlearningprogramming.Forexample,it’seasyinMayatoperformsomeactionswiththegraphicalinterface,thendragthecommandsthatresultedfromtheScriptEditortotheshelftocreateabutton.However,learningMELwillopenupnewworldstoyou,allowingyouproduceeffectsandsavetimeinwaysimpossibleusingthegraphicalinterface.

HerearesomeexamplesofthingsyoucandowithMEL:

BypassMaya’suserinterface,quicklycreateshortcuts,andaccessadvancedfeatures.

CustomizeMaya’sinterfaceandchangedefaultsonascene-by-scenebasis.

Createproceduresandscriptsforcustommodeling,animation,dynamics,andrenderingtasks.

--------------------------------------------------------------------------------------------------------------------(12.19)

二,关于这本MEL和表达式的书

这本书主要用来说明怎么用MEL语言来创建脚本。

maya有数千条命令,以来完成各种各样的功能需求,有一些非常特别。

一些通常使用的非常重要的函数,在本书的“有用的函数”这部分中把它们单独列出来了。

但是要想找到任意一个,或者全部MEL命令的话,还请查阅maya帮助文档中的MEL命令参考文档。

//原文:

TheMELandexpressionsbook

ThisbookexplainshowtocreatescriptsintheMELlanguage.

Mayahasliterallythousandsofcommandstoperformvariousfunctions,someveryspecific.Wehavehighlightedthefunctionsmostusefulingeneralprogramminginthe“Usefulfunctions”sectionofthisbook.However,tofindoutaboutanyandallMELcommands,refertotheMELcommandreferencedocumentationinMayaHelp.

--------------------------------------------------------------------------------------------------------------------(12.20)

三,MEL最作为程序设计语言。

作为一门语言,MEL是从UNIX的脚本语言移植而来,这意味着MEL在执行命令去完成一些事情方面是非常强大的,甚至优于其他语言中的构造数据结构、执行函数、面向对象方法。

你用来控制maya的很多命令,执行起来就像UNIX里面的命令行那样有效:

短小的代码,跟着很多的选项,用来修改定制对象的行为。

心里保持着MEL来自于UNIX的SHELL脚本血统,有助你去理解它的一些怪异面貌(quirkieraspect)。

*********快速浏览:

赋值:

赋值运算在MEL中也是用“=”号来完成,这跟C,JAVA中一样,也有有一些快捷的操作符,例如:

(+=,-=,/=,*=,++,--,etc.).

MEL是强类型语言(stronglytypedlanguage,这个不明白什么意思,可能是想C++那样必先强制先定义类型,然后再使用的那种),但是在很多场合它都允许隐性声明。

在声明一个变量的时候,同时可以声明变量的类型,并随意指定它的初始值。

MEL的变量名字由“$”符号为前缀(这点在开始使用MEL的时候很不习惯,有点quirkier),后面再加上字母,然后可以是字母,数字,下划线的组合。

MEL的数据类型,有平常使用的普通类型:

整型(就是整数),浮点型(就是实数),字符型(就是字符了),它还有向量,数组,矩阵这些数据类型(这些类型的含义后面慢慢介绍)。

int$a=5;//定义一个整型变量“$a”,给变量“$a”指定了一个初始值为5。

float$b=3.456;//定义一个浮点型变量“$b”,给变量“$b”指定了一个初始值为3.456。

vector$v=<<1.2,3.4,6.5>>;//定义一个向量型变量“$V”。

float$ar[]={1.2,3.4,4.5};//定义一个元素为浮点类型数据的数组。

matrix$mtx[3][2];//定义一个矩阵;

在maya中不能定义一个由很多数组数据组成的数组;

很多时候,MEL会自动进行数据类型的转换;

//原文:

MELforprogrammers

Asalanguage,MELisdescendedfromUNIXshellscripting.ThismeansMELisstrongly

basedonexecutingcommandstoaccomplishthings(likeexecutingcommandsinaUNIX

shell),ratherthanmanipulatingdatastructures,callingfunctions,orusingobject

orientedmethodsasinotherlanguages.

MostcommandsyouusetocontrolMayaactlikeUNIXcommand-lineutilities:

little

stand-aloneprogramswithmanyoptionsthatmodifytheirbehavior.

KeepingtheshellscriptingoriginsofMELinmindwillhelpyouunderstandsome

ofitsquirkieraspects.

Quickoverview

Assignmentandvalues

TheassignmentoperatorinMEListheequalsign(=).MELalsohasshortcut

assignmentoperatorslikeCandJava(+=,-=,/=,*=,++,--,etc.).

MELisastronglytypedlanguage,howeveritallowsimplicitdeclarationandtyping

inmostinstances.Whenyoudeclareavariableyoualsodeclareitstypeandcanoptionally

assignaninitialvalue.

Variablenamesstartwitha$,followedbyaletter,thenanycombinationofletters,

numbers,andunderscores.UnlikePERL,alltypesofvariables(scalarandcompound)

startwith$.

MELhastheusualinteger(int),floatingpoint(float)andstringdatatypes.

Italsohasavectordatatypewhichisatripleoffloats(whichcanbeusefulwhen

workingwith3Ddata),arrays(avariable-sizedlist,inwhichallelementsareofthe

sametype),andmatrices(matrix,afixed-sizetwodimensionaltableoffloats).

Itemsinanarraymustallbeofthesametype.

int$a=5;

float$b=3.456;

vector$v=<<1.2,3.4,6.5>>;

float$ar[]={1.2,3.4,4.5};//Anarrayoffloats

matrix$mtx[3][2];//A3x2matrixoffloats

YoucannotmakeanarrayofarraysinMEL.

MELautomaticallyconvertstypeswheneverpossible.

----------------------------------------------------------------------------------(12.21)

控制和循环语句的声明和操作:

MEL控制语句的声明跟C非常类似:

if( $a==$b){

...

}elseif($a>$b){

...

}else{

...

}

$a=($b>10)?

$c:

($c-10);

switch($color){

case"blue":

...

break;

case$c1:

...

break;

default:

...

break;

}

while($a

...

}

do{

...

}while($a>0);

int$i;

for($i=10;$i>0;$i--){

print($i+"...\n");

}

print("Blastoff!

!

!

");

string$arry[3]={"red","green","blue"};

for($kin$arry){

...

}

定义和执行函数(Definingandcallingprocedures,根据后面的意思,应该是定义一个函数):

用以下的语法来自定义一个函数:

global(全局)proc(自定义函数的关键词)(返回值类型)(自定义函数的名称)

(参数列表)){

...(执行语句)

return;

}

globalprocfloatsquareAndAdd(float$x,float$y){

return$x*$x+$y;

}

square(5.0,2.0);

27

如果不加前面的“global”这个关键词的话,定义的函数只能在这个脚本文件中使用,就是说加上关键字

“global”的话,此自定义函数在其他脚本文件中也可以使用。

如果函数没有返回值,则可省去返回值类型,

执行语句中也不需要返回语句:

globalprocmsg(){

print("Helloworld\n");

}

注释:

MEL使用C++风格的注释,单行命令使用"//"来注释,即一行代码中"//"后面的字符为注释,使用“/*”和

"*/"包围起来的字符都是注释部分,可以换行;

MEL风格:

MEL有很多特征,会绊倒有经验的程序员:

每一句声明语句,都要以符号";"为结束的标志:

if($a>$b)

{

print("Hello");

};

两个双引号是必须的!

不像其它一些脚本语言,MEL中输入一个有返回值的表达式,MEL不会自动输出返回的值,反而会提示语法错误。

3+5;

//Error:

3+5;//

//Error:

Syntaxerror//

print(3+5);

8

MEL允许你用命令语法和函数语法这两种语法来书写代码,用命令式语法来书写代码,可以省去引号,和用空格

来代替逗号,如:

setAttr("mySphere1.translateX",10);//函数式语法

setAttrmySphere1.translateX10;//命令式语法

函数式语法会自动返回一个值,如果用命令式语法的话,就需把命令有单引号括起来:

$a=getAttr("mySphere.translateX");//Functionsyntax

$b=`getAttrmySphere.translateY`;//Commandsyntax

//原文:

Controlandloopingstatementsandoperators

MEL’scontrolstatementsareverysimilartoCandJava.

if( $a==$b){

...

}elseif($a>$b){

...

}else{

...

}

$a=($b>10)?

$c:

($c-10);

switch($color){

case"blue":

...

break;

case$c1:

...

break;

default:

...

break;

}

while($a

...

}

do{

...

}while($a>0);

int$i;

for($i=10;$i>0;$i--){

print($i+"...\n");

}

print("Blastoff!

!

!

");

string$arry[3]={"red","green","blue"};

for($kin$arry){

...

}

Definingandcallingprocedures

Youcreateuser-definedproceduresusingthefollowingsyntax:

globalproc){

...

return;

}

globalprocfloatsquareAndAdd(float$x,float$y){

return$x*$x+$y;

}

square(5.0,2.0);

27

Ifyouleaveouttheglobalkeywordtheprocedureisonlyavailableinthescript

fileinwhichitisdefined.

Iftheproceduredoesnotreturnavalue,leaveoutthereturntypekeywordanddo

notincludeareturnstatement.

globalprocmsg(){

print("Helloworld\n");

}

Comments

MELusesC++stylesingle-linecommentsprecededby//andfreeformcommentssurrounded

by/*and*/.

MELisms

TherearesomeaspectsofMELprogrammingthatwilltripupexperiencedprogrammersas

wellasbeginners.

EverystatementinMELmustendwithasemi-colon(;),evenattheendofablock.

if($a>$b){print("Hello");};

//Bothsemicolonsarerequired!

Unlikesomescriptinglanguages/environments(butliketheLogolanguage),stating

anexpressionthatreturnsavaluedoesnotautomaticallyprintthevalueinMEL.Insteaditcausesanerror.

3+5;

//Error:

3+5;//

//Error:

Syntaxerror//

print(3+5);

8

InMEL,youoftenusethesamecommandtocreatethings,editexistingthings,andqueryinformationabout

existingthings.Ineachcase,aflagcontrolswhat(create,edit,orquery)thecommanddoes.

//Createaspherenamed"mySphere"withradius5

sphere-radius5-name"mySphere";

//EdittheradiusofmySphere

sphere-edit-radius"mySphere";

//PrinttheradiusofmySphere

sphere-query-radius

MELallowsyoutotypecommandsincommandsyntax

(similartoUNIXshellcommands)andfunctionsyntax.

Incommandsyntaxyoucanleaveoffquotationmarksaround

single-wordstringsandseparateargumentswithspacesinsteadofcommas.

setAttr("mySphere1.translateX",10);//Functionsyntax

setAttrmySphere1.translateX10;//Commandsyntax

Functionsyntaxautomaticallyreturnsavalue.Togetareturn

valueusingcommandsyntax,youmustenclosethecommandinbackquotes.

$a=getAttr("mySphere.translateX");//Functionsyntax

$b=`getAttrmySphere.translateY`;//Commandsyntax

----------------------------------------------------------------------------------(12.23)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 文学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1