I. Introduction to the Maya API

Source: Internet
Author: User
Tags wrappers

#include <maya/MSimple.h><maya/MIOStream.h>"Autodesk" "  - "  const marglist& args) {    ""0 ). Aschar () << Endl;     return ms::ksuccess;}

Marglist accepts command arguments from the Mel command input.

An example of creating a NURBS curve: You can learn the 1 command of parse, 2 to create a Mobject method. 3. Data structures in Maya use

#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::d oit (Constmarglist&args)    {Mstatus stat; Constunsigned deg =3;//Curve degree    Constunsigned NCVS = -;//Number of CVs    Constunsigned spans = ncvs-deg;//Number of spans    Constunsigned nknots = spans+2*deg-1;//Number of knots    DoubleRadius =4.0;//Helix radius    DoublePitch =0.5;//Helix Pitchunsigned i; //Parse the arguments.     for(i =0; I < args.length (); i++ )        if(Mstring ("- P") = = Args.asstring (i, &stat)&& Ms::ksuccess = =stat) {            DoubleTMP = Args.asdouble (++i, &stat); if(Ms::ksuccess = =stat) Pitch=tmp; }        Else if(Mstring ("- R") = = Args.asstring (i, &stat)&& Ms::ksuccess = =stat) {            DoubleTMP = Args.asdouble (++i, &stat); if(Ms::ksuccess = =stat) Radius=tmp;    } Mpointarray controlvertices;    Mdoublearray knotsequences; //Set up CVs and knots for the helix//     for(i =0; i < Ncvs; i++) Controlvertices.append (mpoint (RADIUS* COS ((Double) i), Pitch* (Double) I, Radius * sin ((Double))) ;  for(i =0; 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"; returnStat;}

Mobject is the parent of all node in Maya, and function sets is used to manipulate object.

Proxies is used to create objects other than Mobject in Maya. Includes the Command object, the file translator object, and the shader object.

Second, about the method of interacting with Maya:

1. There are 4 ways: wrappers, objects, function sets, proxies

2. Manipulating Maya's objects:

(1) Object type: Curves, surfaces, DAG nodes, dependency graph nodes, lights, shaders, textures,etc)

(2) The handle that manipulate these objects is mobject, and Mobject's destructor does not delete the object itself, only the handle object

You cannot use the pointer to point to Mobject, but use Mobjecthandle

3. Wrappers: Simple object such as math classes, vectors, matrices, they are generic C + + class wrappers, such as Mpointarray and Mdoublearray.

Do not declare wrapper in the loop, except for the static Mglobal

4. Object and function set are commonly used together.

Create a curve

= Curvefn.create (...);
    • Mfnnurbscurve Curvefn; Creates a new curve function set which contains methods for operating on curve objects, and the Create method in Particula R is used to create new curves.
    • Mobject curve = curvefn.create (...); Creates a new Maya curve object which you can then use however

If you add a third line:

= 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 is all Proxies, API Classes designed-for-you-derive from and create your own objec T types.

6.Mit-these classes is iterators and work on mobjects much the 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 Succee DS.

For example, args.asstring (i, &stat) could return Ms::kfailure if the index is greater than the number of Argu ments.

The role of the Mstatus class: (1) overloading the logical operators, which can be judged directly if. (2) can get Mstatuscode enumeration error Reason

(3) The ErrorString () method is used to obtain the mstring containing the error information.

(4) printing via perror () function

(5) Overload = =/! = operator, which can be compared with Mstatuscode

I. Introduction to the Maya API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.