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

Friday, January 30, 2009

Hello world!

As the problems when using CSDN blog are still not been solved, I really feel angry about that site this time. Though I still like the style that blog provides, I am really frustrated about its stopping photo album and other services. Moreover, the most important thing is that I can't use the Windows Live Writer tool to publish my blogs. I don't know why nobody fixing that problem.

Although very reluctant, I decide to change to another blog site which is here.

Original posts are all here: http://blog.csdn.net/itroy

Hope myself a good experience here!

Happy new year to everyone!

And have a new begining for me!

Hello world!

As the problems when using CSDN blog are still not been solved, I really feel angry about that site this time. Though I still like the style that blog provides, I am really frustrated about its stopping photo album and other services. Moreover, the most important thing is that I can't use the Windows Live Writer tool to publish my blogs. I don't know why nobody fixing that problem.

Although very reluctant, I decide to change to another blog site which is here.

Original posts are all here: http://blog.csdn.net/itroy

Hope myself a good experience here!

Happy new year to everyone!

And have a new begining for me!
Google+