一、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 ...
随机推荐
- Model2模型介绍
在JSP课程中有 Model1 模型的介绍 模型二: 实例接JSP课程,先去看JSP课程了
- Asp.net MVC 视图(四)
强类型辅助方法 模板辅助方法 Asp.net MVC中的模板辅助方法利用元数据和模板构建HTML,即:模板辅助方法可以通过使用数据注解,在运行时使用合适的任何“编辑器”来生成合适的HTML标记元数据包 ...
- JVM-类加载机制
虚拟机类加载机制 虚拟机把描述的类的数据从class文件加载到内存后,并对数据进行校验,转换解析和初始化,最终形成可以被虚拟机直接使用的Java类型,这就是虚拟机的类加载机制. 类加载的时机 类被 ...
- MAC机中安装ruby环境--转载
http://www.cnblogs.com/pingfan1990/p/4957162.html
- Python time模块学习
Python time模块提供了一些用于管理时间和日期的C库函数,由于它绑定到底层C实现,因此一些细节会基于具体的平台. 一.壁挂钟时间 1.time() time模块的核心函数time(),它返回纪 ...
- SCC(强连通分量)
1.定义: 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(SC---strongly connected). 有向图中的极大强连通子图,成为强连通分量(SCC---strongly ...
- JS 点击复制Copy (share)
分享自:http://www.cnblogs.com/athens/archive/2013/01/16/2862981.html 1.实现点击按钮,复制文本框中的的内容 1 <script t ...
- Sprint第二个冲刺(第十天)
一.Sprint 计划会议: 现在总结一下情况,正在做的3个功能的完成程度已经达到了80%,过几天就可以完成了.也把之前做的修改界面放入fragment中,方便修改管理.效果图如下: 二.Sprint ...
- CVE-2014-6271 Bash漏洞利用工具
CVE-2014-6271 Bash漏洞利用工具 Exploit 1 (CVE-2014-6271) env x='() { :;}; echo vulnerable' bash -c "e ...
- springfox.documentation.service.ApiInfo配置示例
Java Code Examples for springfox.documentation.service.ApiInfo The following are top voted examples ...