一、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 ...
随机推荐
- 苹果5S指纹扫描识别传感器Touch ID有利于iPhone的安全性
iPhone5S新增的指纹扫描识别传感器 Touch ID,黑客花了大量的时间表明指纹验证是可以被破解的.即使它可能被黑客攻击,对iPhone5S的安全性而言,仍然具有极大的好处. 为什么一个容易被破 ...
- nodejs 安装配置 for ubuntu
安装nodejs sudo apt-get update sudo apt-get install nodejs -g #全局安装 安装npm sudo apt-get install npm #查 ...
- js实现cookie记住密码
近来做记住密码时,用js的实现方式做了一下. login.jsp页面代码 <%@ page language="java" import="java.util.*& ...
- tableView
Table View简单描述: 在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View ...
- jdbc 配置
jdbc 配置 Class.forName("com.mysql.jdbc.Driver") ;//加载数据库驱动 Connection conn=null; String ur ...
- JQUERY操作html--获取和设置内容、属性、回调函数
一:jQuery - 获取内容和属性 1.获得内容 - text().html() 以及 val() text() - 返回所选元素的文本内容 html() - 返回所选元素的内容(包括 HTML 标 ...
- Objective-c——UI基础开发第十二天(相册展示)
一.知识点 模仿新特性 UICollectionViewFlowLayout自定义布局 相册 瀑布流(淘宝购物之类的 二.复习 a.UICollectionView 和 tableview共享一套AP ...
- Android——手机内部文件存储(作业)
作业:把用户的注册信息存储到文件里,登录成功后读出并显示出来 activity_practice2的layout文件: <?xml version="1.0" encodin ...
- 关于 MAXScript 中文路径返回上级目录(精简版)
之前写过一个 关于 MAXScript 中文路径返回上级目录 的博文 今天无意中发现了一个更简单的方法 代码如下: fn newfile filepath = ( nf = getfilenamepa ...
- CSS 样式的优先级
1. 同一元素引用了多个样式时,排在后面的样式属性的优先级高 例如,下面的 div,同时引用了 [.default] 和 [.user] 中的样式,其中 [.user] 样式中的 width 属性会替 ...