Showing posts with label Maya. Show all posts
Showing posts with label Maya. Show all posts

Thursday, February 5, 2009

Maya tips I

 

To display the information of selected mesh

, using polygon heads up display.

Display -> Heads up display -> Poly Count

 3253860811

 3253860779

 

 

 

 

To lower the resolution of existing model:

Mesh -> Reduce

3254687740

Tuesday, February 3, 2009

Maya Obj file format

The .obj file format supports both polygonal objects and free-form objects. Polygonal geometry uses points, lines, and faces to define objects while free-form geometry uses curves and surfaces.

File structure: (syntax)

Vertex data:

geometry vertices (v x y z / v x y z w)

texture vertices (vt u / vt u v / vt u v w)

vertex normals (vn i j k)

parameter space vertices (vp u / vp u v / vp u v w)

Free-form curve/surface attributes

rational or no-rational forms of curve or surface type: basis matrix, Bezier, B-spline, Cardinal, Taylor (cstype)

degree (deg)

basis matrix (bmat)

step size (step)

Elements

point (p)

line (l)

face (f)

curve (curv)

2D curve (curv2)

surface (surf)

Free-form curve/surface body statements

parameter values (parm)

outer trimming loop (trim)

inner trimming loop (hole)

special curve (scrv)

special point (sp)

end statement (end)

Connectivity between free-form surfaces

connect (con)

Grouping

group name (g)

smoothing group (s)

merging group (mg)

object name (o)

Display/render attributes

bevel interpolation (bevel)

color interpolation (c_interp)

dissolve interpolation (d_interp)

level of detail (lod)

material name (usemtl)

material library (mtllib)

shadow casting (shadow_obj)

ray tracing (trace_obj)

curve approximation technique (ctech)

surface approximation technique (stech)

A typical .obj file:

image

 

Referencing groups of vertices

Some elements, such as faces and surfaces, may have a triple of numbers that reference vertex data. These numbers are the reference numbers for a geometric vertex, a texture vertex, and a vertex normal.

Each triplet of numbers specifies a geometric vertex, texture vertex, and vertex normal. The reference numbers must be in order and must be separated by slashes (/).

The first reference number is the geometric vertex.

The second reference number is the texture vertex. It follows the first slash.

The third reference number is the vertex normal. It follows the second slash.

A four-sided face element:

f 1/1/1 2/2/2 3/3/3 4/4/4

f v/vt/vn v/vt/vn v/vt/vn v/vt/vn

 

Much more details can be found here: Download

Monday, February 2, 2009

[Maya] Note 1

Function to create a sphere data:

MObject MFnSphereData::create
(
double
rad = 1,

MStatus *
ReturnStatus = NULL

)

 

C:\Program Files\Autodesk\Maya2009\docs\Maya2009\en_US\index.html

 

Notice:

When you use MString in your code, do remember to include the header file "<maya/MString.h>". Moreover, in C++, you must not use following format:

MString cmd;

cmd="sphere -r "+radius;

Instead, using:

MString cmd;

cmd="sphere -r ";

cmd+=radius;

As MString class has provide the operator +=, in this way it will work correctly. Or, using the first format, the "+" won't work well. And usually, it cause the cmd string to be "".

Sunday, February 1, 2009

[Maya] About surfaces

1. Maya stores more complex data types, such as NURBS surfaces, as special geometry data. In order to be able to create and store this kind of data, you need to use the appropriate MFGeometryData function  set.

2. To get the data of an input NURBS surface, use MFnNurbsSurfaceData to create a new object, and copy the original surface data to this new created one.

3. To access and change the NURBS surface data, MFnNurbsSurface function is need.

4. All the surface control vertices (CVs) are retrieved and stored in an array using the MFnNurbsSurface's getCVs function. Also for individual get and set using getCV and setCV.

5. Using setCVs to modify the control vertices.

6. Using MFnNurbsSurface's updateSurface() to update the surface.

7. MFnGenericAttribute allows you to define a variety of different data types that will accept.

Saturday, January 31, 2009

[Maya] Clock plug-in

Function:

Set the time of the 3d clock, then the hour hand and minute hand move to the right position.

 

Code and the Clock file:

http://www.rayfile.com/files/a39e730c-ef9c-11dd-8c0e-0014221b798a/

 

Main Tech:

doIt()

undoIt()

redoIt()

isUndoable()

MDagPath

query and edit mode

MArgDatabase for dealing with input parameters

MFnTransform for transforming the clock hands

setResult for returning the query result

 

Snapshot:

Capture

[Maya] Using MSyntax and MArgDatabase to handle the input parameters

Function:

Based on the previous code, implement the same function as before: create a bunch of cylinders along the selected curve.

 

Main Code:

Initialise the flags:

const char *numberFlag="-n", *numberLongFlag="-nmuber";
const char *radiusFlag="-r", *radiusLongFlag="-radius";
const char *heightFlag="-h", *heightLongFlag="-height";


doIt function:



MStatus Posts1Cmd::doIt(const MArgList &args)
{
int nPosts=5;
double radius=0.5;
double height=5.0;

MArgDatabase argData(syntax(),args);

if(argData.isFlagSet(numberFlag))
argData.getFlagArgument(numberFlag,0,nPosts);

if(argData.isFlagSet(radiusFlag))
argData.getFlagArgument(radiusFlag,0,radius);

if(argData.isFlagSet(heightFlag))
argData.getFlagArgument(heightFlag,0,height);


...



MSyntax function:



MSyntax Posts1Cmd::newSyntax()
{
MSyntax syntax;
syntax.addFlag(numberFlag,numberLongFlag,MSyntax::kLong);
syntax.addFlag(radiusFlag,radiusLongFlag,MSyntax::kDouble);
syntax.addFlag(heightFlag,heightLongFlag,MSyntax::kDouble);
return syntax;
}



static MSyntax newSyntax();


Modification of initializations function:



stat=pluginFn.registerCommand("posts1", 


Posts1Cmd::creator, 


Posts1Cmd::newSyntax);

[Maya] Plug-in development II

Function:

Create a bunch of cylinders along the selected curve. The number of cylinders, the radius and the height can be specified through parameters.

 

Main Code:

MStatus Posts1Cmd::doIt(const MArgList &args)
{
int nPosts=5;
double radius=0.5;
double height=5.0;

unsigned index;
index=args.flagIndex("n", "number");
if(MArgList::kInvalidArgIndex!=index)
args.get(index+1,nPosts);

index=args.flagIndex("r","radius");
if(MArgList::kInvalidArgIndex!=index)
args.get(index+1, radius);

index=args.flagIndex("h", "height");
if(MArgList::kInvalidArgIndex!=index)
args.get(index+1,height);

MSelectionList selection;
MGlobal::getActiveSelectionList(selection);

MDagPath dagPath;
MFnNurbsCurve curveFn;
double heightRatio=height/radius;

MItSelectionList iter(selection, MFn::kNurbsCurve);
for(;!iter.isDone();iter.next())
{
iter.getDagPath(dagPath);
curveFn.setObject(dagPath);

double tStart, tEnd;
curveFn.getKnotDomain(tStart, tEnd);

MPoint pt;
int i;
double t;
double tIncr=(tEnd-tStart)/(nPosts-1);
for(i=0,t=tStart;i<nPosts;i++, t+=tIncr)
{
curveFn.getPointAtParam(t,pt,MSpace::kWorld);
pt.y+=0.5*height;

MGlobal::executeCommand(MString("cylinder -pivot ")+pt.x+" "+pt.y+" "+pt.z+
" -radius "+radius+" -axis 0 1 0 -heightRatio "+heightRatio);
}
}

return MS::kSuccess;
}


 



Snapshot:



Capture

[Maya] The two shelf button to load and unload the plugin

As developing maya plug-in, we need to load the plug-in to maya to test whether it works well or not. Then we need to refine it in VS. Before unloading the plug-in in maya, it will throw errors because the loaded plug-in is not allowed to access!

Therefore, it's better to have load and unload button to ease our process.

 

Load the plugin:
{
string $pluginFile="D:\\Projects\\Maya\\MayaPlugin\\Posts1\\Debug\\Posts1.mll";
loadPlugin $pluginFile;
}


 



Unload the plugin:


{
string $pluginFile="D:\\Projects\\Maya\\MayaPlugin\\Posts1\\Debug\\Posts1.mll";
if(`pluginInfo -query -loaded $pluginFile` && !`pluginInfo -query -unloadOk $pluginFile`)
file -f -new;
unloadPlugin Posts1.mll;
}




The pluginFile is the plug-in file we developed.

[Maya] Maya plugin development 1

Following the steps on the book Maya Complete Programming I, Chapter 4, Page 310-315, I have tried out the first plug-in created using C++ ( except the HelloWorld plug-in).

Function:

Creating five cylinders along the selected curve.

Source:

http://www.rayfile.com/files/2287b778-eed8-11dd-8ba3-0019d11a795f/

Snapshot:

Capture

[Maya] Maya plugin development 1

Following the steps on the book Maya Complete Programming I, Chapter 4, Page 310-315, I have tried out the first plug-in created using C++ ( except the HelloWorld plug-in).

Function:

Creating five cylinders along the selected curve.

Source:

http://www.rayfile.com/files/2287b778-eed8-11dd-8ba3-0019d11a795f/

Snapshot:

Capture

Google+