PDA

View Full Version : New To Maya Api... Trying To Make Sculpting Brush


sckulp
04-08-2009, 01:50 AM
Hello,

I am trying to learn how to use the Maya API by making a type of sculpting brush. I have it working almost perfectly, except for a couple things...

When the user drags the cursor over the model, I want the model to visually deform in real time. Right now, as the user drags the cursor, the model doesn't change, but one the user releases the mouse button, everything gets changed all at once. I do not even have a doRelease function in my MPxContext class -- just doPress and doRelease.

Also, when the user drags, I'd like a box around the cursor that shows the selected area. Right now, I have it draw a square, and that part works, but the screen doesn't clear for each time step. So when the user drags, a long string of little squares follows along with it. The squares go away after the user releases, though (maybe it has something to do with the problem above?). Here is the relevant section of code:

m_View.beginOverlayDrawing();

// clear the overlay planes
m_View.clearOverlayPlane();

// Set up the orthographic projection matix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluOrtho2D( 0.0f, m_View.portWidth(),
0.0f, m_View.portHeight() );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

// Set line width
glLineWidth( 1.0 );

// Draw rectangle
glBegin( GL_LINE_LOOP );
glVertex2i( min.h, min.v );
glVertex2i( min.h, max.v );
glVertex2i( max.h, max.v );
glVertex2i( max.h, min.v );
glEnd();

// done drawing our overlay on the viewport
m_View.endOverlayDrawing();



One last thing (for now)... Whenever I want to use my brushtool, I have to load the program, enter "smoothbrush" (my plugin name) into the command line, and then enter "setToolTo smoothbrushX" where X is some number. Is there a way to streamline this? Maybe make a button or something?

Thanks in advance!

Buexe
04-08-2009, 10:19 PM
but there is a dodrag function in the MPxContext class. Why don`t you use it?

sckulp
04-08-2009, 11:00 PM
I do use dodrag, as well as dopress. The problem is, the screen does not refresh as the mouse is being dragged, but it does refresh when it is released.

I found that when I tried using my plugin on my laptop, it is working perfectly. I think the problem is, my laptop has a (weak) workstation graphics card (Quadro something), whereas my desktop has a gaming graphics card (8800GT). Is there anyway to work around this issue? There has to be, since all pre-built tools look fine on my desktop, there is no refresh issue there...

Keilun
04-09-2009, 09:45 PM
Can you elaborate further on where that draw code is being called? When does it get called?

Have you tried forcing the view to refresh during your doDrag? It's hard to tell why it isn't refreshing without seeing your code.

And as far as streamlining the tool. You can create a script that creates one single instance of your custom context and then sets the tool to it.

Eg.

global proc string smoothBrushTool()
{
global string $gSmoothBrushCtx;
if ($gSmoothBrushCtx== "")
$gSmoothBrushCtx= "theSmoothBrushTool";

string $cmd = ("smoothBrushCtx -exists " + $gSmoothBrushCtx);
string $result = eval ($cmd);
if ($result)
return $gSmoothBrushCtx;

$gSmoothBrushCtx= `smoothBrushCtx $gSmoothBrushCtx`;

setToolTo $smoothBrushCtx;
return $gSmoothBrushCtx;
}

That would create a singleton of your context and set the tool to it, whenever you invoke that procedure. Then just plop that procedure call into your shelf and it should set it.

CGTalk Moderation
04-09-2009, 09:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.