[Maya API] I. Basic Type Description

1, Maya API basic structure

1.1 API Language Support

C ++ API (Application Programmer Interface) than the MEL and Python have better performance, you can use the API to create your own new node, MEL computing power of more than about 10 times, you can also use the API calls MEL script

Python API based API programming python may be used to build the C ++ API, Python API has now two versions 1.0 and 2.0

1.2 API compiled plug-suffix

Linux: .so

Window: .mll

Mac OS X: .bundle

Universal Plug: .py

1.3 API built-in library

OpenMaya basic operating tools

OpenMayaUI Interface Tools

OpenMayaAnim animation tools

OpenMayaFX special effects tools

OpenMayaRender rendering tools

1.4 API naming conventions

M classes - the basic data types similar to these basic types of string python

MFn - Function Function Tools

MIt - Iterator iterator type

MPx - agent types, extensions Maya feature requires an inherited class

To use the API, you need to put the node or an object is initialized to the beginning of the M type, API can identify

MFn: We can perform their operations by this method for different objects

MIt: For a number of objects need to access one by one, to use this iterator type, one by one using a loop to access their element

MPx: good writing plug-ins in this format, Maya plug-ins can be loaded according to well-defined format, written manually, Maya automatically identify

2.DependencyNode sum DagNode

DependencyNode Maya basic types of nodes

In maya, all nodes are a DependcyNode (node ​​dependent), all of our data are calculated dependent on the node, each node stores the calculated mutual we need between data nodes to form a network of nodes , and then form our final document. So a basic node is DependencyNody, similar to our material node, independent of a single node.

Maya DagNode is of a hierarchical relationship, that is to say in the syllabus, we can set his parent-child relationship. DagNode come from DenpendcyNode extension, DagNode have all DependcyNode method, you can use DependcyNode way to handle any DagNode, but this operation is similar to the hierarchy, such as access to superior-subordinate relationship object

3.Mobject Maya basic object pointer

Maya API type base type, all types inherit this. Representative of a pointer to a node

Mobject: Maya the most basic object, if you use the API, then, Mobject is a basic data that we handle, like python programming, a variable, although when a string or integer that is the basic object of a python. In the Maya API, which can not be handled as a string This node must be transformed in order to drive a MObject process, that any object in Maya is an Object, of course, similar to the processing of his name, property values, which kind of string or numeric exception, that this is a basic index. He points to each node, we are dealing with a particular node think he is a MObject.

How to check the Maya API documentation:

~ MObject destructor: Generally not use it, unless we write node, he will need to clean up memory

How to create a MObject?

We want to use the Maya API must first import OpenMaya

import Maya.OpenMaya as OpenMaya

Create a MObject

import Maya.OpenMaya as OpenMaya

OpenMaya.MObject()

Well, he generated a MObject, but the Object is empty because we did not give him a point to any object.

We need to pass a Object object, so we can borrow pymel to generate an object

import maya.OpenMaya as OpenMaya
import pymel.core as pm

ball_pml_node = pm.PyNode('pSphere1') #ball_pml_node为pymel节点,
ball_api_node = ball_pml_node.__apimobject__()  #生成了一个MDagPath,与OpenMaya.MObject相同, 
                                                #但它指向的是一个物体
ball_api_node.isNull()  #判断API节点是否为空
ball_api_node.apiType()  #api节点类型

我们在处理任何一个节点时,都要转化为MObject。任何一个DagNode,也就是说大纲里的物体都是一个DenpendecyNode也都拥有MObject,那么他当然有自己的一种索引方式,就是DagPath。

DagPath

我们可以新定义一个DagPath,也可以从另一个DagPath来生成一个新的DagPath,这个他就会追踪我们大纲里的一个节点,方法要比刚才的MObject要多,它还有静态的方法,也就是说我们可以通过一个刚才的类似于那种MObject来抓取他的DagPath,或者是直接从PyMel来生成。

静态方法的意思是:我们没有实例化一个结点之前我们就可以调用他的这些通用的方法。

import maya.OpenMaya as OpenMaya
import pymel.core as pm

ball_pml_node = pm.PyNode('pSphere1') #ball_pml_node为pymel节点,
ball_api_node = ball_pml_node.__apimobject__()  #生成了一个OpenMaya.MObject
                                                #但它指向的是一个物体

ball_dag_path = OpenMaya.MDagPath() #创建一个空的DagPath对象

OpenMaya.MDagPath.getAPathTo(ball_api_node,ball_dag_path)

"""
执行逻辑就是抓取MObject的DagPath存储到一个DagPath中
"""

ball_dag_path.fullPathName()  #在大纲里的一个长名

ball_dag_path.partitialPathName()  #在大纲的短名

总结:

MObject:任何一个节点,都通过把它交给API来处理。

MDagPath:可以把大纲里的物体通过它来交给API进行处理

MObject与MDagPath也是有联系的,我们可以通过MDagPath找到物体对应的MObject,也可以通过传入MObject,给物体定义好一个DagPath来处理他的层级关系。

发布了56 篇原创文章 · 获赞 1 · 访问量 1万+

Guess you like

Origin blog.csdn.net/weixin_41363156/article/details/103965540