#include <maya/MSimple.h>
#include <maya/MIOStream.h>
DeclareSimpleCommand( hello, "Autodesk", "");
MStatus hello::doIt( const MArgList& args )
{
cout << "Hello " << args.asString( ).asChar() << endl;
return MS::kSuccess;
}

MArgList接受来自MEL command输入的命令参数。

一个创建NURBS CURVE的例子: 可以学到1命令的parse, 2创建MObject的方法。3. Maya中的数据结构使用

#include <math.h>
#include <maya/MSimple.h>
#include <maya/MIOStream.h>
#include <maya/MFnNurbsCurve.h>
#include <maya/MPointArray.h>
#include <maya/MDoubleArray.h>
#include <maya/MPoint.h>
DeclareSimpleCommand( helix, "Autodesk - Example", "3.0");
MStatus helix::doIt( const MArgList& args )
{
MStatus stat;
const unsigned deg = ; // Curve Degree
const unsigned ncvs = ; // Number of CVs
const unsigned spans = ncvs - deg; // Number of spans
const unsigned nknots = spans+*deg-;// Number of knots
double radius = 4.0; // Helix radius
double pitch = 0.5; // Helix pitch
unsigned i;
// Parse the arguments.
for ( i = ; i < args.length(); i++ )
if ( MString( "-p" ) == args.asString( i, &stat )
&& MS::kSuccess == stat)
{
double tmp = args.asDouble( ++i, &stat );
if ( MS::kSuccess == stat )
pitch = tmp;
}
else if ( MString( "-r" ) == args.asString( i, &stat )
&& MS::kSuccess == stat)
{
double tmp = args.asDouble( ++i, &stat );
if ( MS::kSuccess == stat )
radius = tmp;
}
MPointArray controlVertices;
MDoubleArray knotSequences;
// Set up cvs and knots for the helix
//
for (i = ; i < ncvs; i++)
controlVertices.append( MPoint( radius * cos( (double)i ),
pitch * (double)i, radius * sin( (double)i ) ) );
for (i = ; i < nknots; i++)
knotSequences.append( (double)i );
// Now create the curve
//
MFnNurbsCurve curveFn;
MObject curve = curveFn.create( controlVertices,
knotSequences, deg,
MFnNurbsCurve::kOpen,
false, false,
MObject::kNullObj,
&stat );
if ( MS::kSuccess != stat )
cout << "Error creating curve.\n";
return stat;
}

MObject是maya中所有node的父类,function sets用来对object进行操作。

Proxies用来创建除了maya中除了MObject之外对象。包括 command对象,file translator对象,和shader的对象。

二、关于和MAYA交互的方法:

1. 有4中方式:wrappers, objects, function sets, proxies

2. 操纵maya的objects:

(1)object类型:curves, surfaces, DAG nodes, dependency graph nodes, lights, shaders, textures,etc)

(2)操作这些object 的handle是MObject, MObject的析构函数不会delete object本身,只会delete the handle object

不能使用指针指向MObject,而是用MobjectHandle

3. Wrappers:简单的object,例如math classes, vectors, matrices, 他们是普通c++类的包装,例如MPointArray 和MDoubleArray。

在循环中不要申明wrapper, 除了静态的MGlobal

4. object 和 function set通常一起使用。

创建一条curve

MFnNurbsCurve curveFn;
MObject curve = curveFn.create( ... );
  • MFnNurbsCurve curveFn; creates a new curve function set which contains methods for operating on curve objects, and the create method in particular is used to create new curves.
  • MObject curve = curveFn.create( ... );creates a new Maya curve object which you can then use however you like

If you add a third line:

curve = curveFn.create( ... );

a second curve is created and the curve MObject now references the new curve. The first curve still exists—it simply is no longer referenced by the MObject handle.

5. Proxies:

  • MPx - Classes with this prefix are all Proxies, API classes designed for you to derive from and create your own object types.

6.MIt - These classes are iterators and work on MObjects much the way a function set does.

7. Error Check:

The addition of &stat to the asString() and asDouble() methods allows you to check if the casting operation succeeds.

For example, args.asString(i, &stat) could return MS::kFailure if the index is greater than the number of arguments。

MStatus类的作用:(1)重载了逻辑运算符,可以直接if进行判断。(2)可以获得MstatusCode枚举出错原因

(3)通过errorString()方法获得包含error信息的Mstring

(4)通过perror()函数打印

(5)重载== /!=运算符,可以和Mstatuscode进行比较

最新文章

  1. HTML静态网页 格式与布局
  2. CentOS 6.5 EasyPR环境搭建
  3. jquery 获取select框选中的值示例一则
  4. HDU&#160;1301&#160;Jungle&#160;Roads&#160;(最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads
  5. javascript 可控速度的上下拉菜单
  6. UVA 11248 - Frequency Hopping(网络流量)
  7. Object-c中间initialize 与 辛格尔顿
  8. ORACLE-EXP和IMP方法介绍
  9. Hive DQL详解
  10. CSS3 弹性盒子
  11. 你可以这么理解五种I/O模型
  12. vue文档全局api笔记1
  13. 判断闰年(Java)
  14. 在用UEditor往后台传数据写入数据库时,出现错误:从客户端(NewsContent=&quot;&lt;p&gt;&lt;img src=&quot;http://...&quot;)中检测到有潜在危险的 Request.。。。
  15. Spring-事务管理(Transaction)
  16. [BZOJ4571][SCOI2016]美味(贪心+主席树)
  17. Qt程序打包,自动拷贝依赖文件
  18. SQL Inserted和deleted详解
  19. QTP如何准确识别Dialog中的对象
  20. ganglia笔记:rrds目录

热门文章

  1. 图表控件的学习===》hightChart 和 Chartjs的使用
  2. android 自定义view -- 实现自定义 邮箱验证的Edittext
  3. js中的offsetWidth岁的BUG
  4. Windows下Redis的安装使用
  5. LintCode First Position of Target
  6. PHP面向对象(分页)
  7. ajax 中$.each(json,function(index,item){ }); 中的2个参数表示什么意思?
  8. 大道至简---软件工程实践者的思想------------java伪代码形式读后感第一章
  9. 各种数据分析图demo
  10. Windows性能查看器:系统的性能信息(I/O,IIS最大连接数,Sql) ,以及解决 asp.net IIS 一二百多用户并发