一、Maya API简介
#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进行比较
一、Maya API简介的更多相关文章
- Maya API编程快速入门
一.Maya API编程简介 Autodesk® Maya® is an open product. This means that anyone outside of Autodesk can ch ...
- Web Api 简介
ASP.NET Web API 简介 ASP.NET MVC 4 包含了 ASP.NET Web API, 这是一个创建可以连接包括浏览器.移动设备等多种客户端的 Http 服务的新框架, ASP. ...
- ZooKeeper系列4:ZooKeeper API简介及编程
问题导读: 1.ZooKeeper API 共包含几个包? 2.如何使用ZooKeeper API 创建zookeeper应用程序? 1)ZooKeeper API 简介 ZooKeeper AP ...
- WebSocket API简介
WebSocket是html5新增加的一种通信协议,目前流行的浏览器都支持这个协议,例如Chrome,Safari,Firefox,Opera,IE等等,对该协议支持最早的应该是chrome,从chr ...
- 构建简单的 C++ 服务组件,第 1 部分: 服务组件体系结构 C++ API 简介
构建简单的 C++ 服务组件,第 1 部分: 服务组件体系结构 C++ API 简介 熟悉将用于 Apache Tuscany SCA for C++ 的 API.您将通过本文了解该 API 的主要组 ...
- Raphael Js矢量库API简介:
Raphael Js矢量库API简介:Raphael Javascript 是一个 Javascript的矢量库. 2010年6月15日,著名的JavaScript库ExtJS与触摸屏代码库项目jQT ...
- 开放数据接口 API 简介与使用场景、调用方法
此文章对开放数据接口 API 进行了功能介绍.使用场景介绍以及调用方法的说明,供用户在使用数据接口时参考之用. 在给大家分享的一系列软件开发视频课程中,以及在我们的社区微信群聊天中,都积极地鼓励大家开 ...
- Monkey脚本API简介
一.API简介 LaunchActivity(pkg_name, cl_name):启动应用的Activity.参数:包名和启动的Activity. Tap(x, y, tapDuration): 模 ...
- Maya API Test
import maya.OpenMaya as OpenMaya import maya.OpenMayaMPx as OpenMayaMPx sl = OpenMaya.MSelectionList ...
随机推荐
- Android 每次访问网络时,都需要判断是否有网络
/** * 在执行网络操作之前判断网络是否链接可用 * * @return true 可用 false 不可用 */ private boolean isOnline() { Connectivity ...
- 黑马程序员——【Java高新技术】——JDK1.5新特性:静态导入、可变参数、增强型for循环、自动装箱拆箱、枚举
---------- android培训.java培训.期待与您交流! ---------- 一.静态导入 1.import和import static区别: (1)import 是导入一个类或某个包 ...
- BZOJ 2286 树链剖分+DFS序+虚树+树形DP
第一次学习虚树,就是把无关的点去掉.S里维护一条链即可. #include <iostream> #include <cstring> #include <cstdio& ...
- Caffe 源碼閱讀(三) caffe.cpp
补:主要函数运行顺序: main>>GetBrewFunction>>train>>Solve 從main函數說起: 1.gflags庫中爲main函數設置usag ...
- 相同vlan之间的相互访问
- macos下sed小试
linux下替换是这么干的 sed -i "s/xxxxxxxxxx/video_capture_module/g" project.pbxproj 但是macos下略有不同,照搬 ...
- Windows 下的 Sublime Text 2 配置汇总, Sublime Text 3 亦可借鉴
1)软件下载地址:http://www.sublimetext.com/2 2)安装 Package Control ,方便安装和管理插件,网络资源很多,这里附上一篇:http://www.imjef ...
- 数论 UVA 11388
这道题是关于两个数的最大公约数和最小公倍数的题目.给你两个数字g,l,分别表示最大公约数和最小公倍数.要求你找到两个数a,b,要求这两个数的最大公约数和最小公倍数为所给的两个数.如果存在多组数字符合这 ...
- c# winform 关闭窗体时同时结束线程实现思路
Thread th = new Thread(Excute); th.IsBackground = true;这样就解决问题了. 这个属性的意思就是把线程设置为后台线程. 然后关闭进程的同时,线程也会 ...
- Docker SSH
1. Dockerfile -->docker build -t centos6-ssh https://git.oschina.net/feedao/Docker_shell/raw/st ...