[Maya] Get artisan brush settings in paint script tool

Hi!
I’m writing a little paint script tool to deform the normals of a mesh. But I stuck on the brush settings…

Know someone how to get the brush information?
I mean the brush opacity and the profile alpha value every time I call my custom procedure.

Thanks,
Alessandro

Hey Alessandro,

I love artUserPaintCtx, here is some code from a tool I wrote way back, so it’s in mel.

I also have a video of it in use: Normals ToolBox & reference link to Autodesk Help: Painting with MEL scripts and the Paint Scripts Tool


So the artUserPaintCtx is split up into a couple of sections:

Calling the Paint to Start and creating a context:

ScriptPaintTool; artUserPaintCtx -e -tsc "BTB_NormalsPaint" `currentCtx`;

Setup of the Context:

global proc BTB_NormalsPaint( string $context )
{
	artUserPaintCtx -e
		-ic "BTB_InitNormalsPaint"
		-fc "BTB_FinishNormalsPaint"
		-svc "BTB_SetNormalsPaintValue"
		$context;
}

Setup, Complete and Compute Functions:

global proc string BTB_InitNormalsPaint(string $name)
{
	return ("-dt worldV -n local");
}

global proc BTB_FinishNormalsPaint( int $slot ){}

global proc BTB_SetNormalsPaintValue(int $slot, int $index, float $val, float $Dx, float $Dy, float $Dz, float $Nx, float $Ny, float $Nz)
{
	global string $BTB_NormalsPaintCurrentObject;
	global string $BTB_NormalsToolBoxErase;
	
	vector $finalNormal;
	
	// Get the Effect Value and Process the Normal
	
	vector $vTo;
	vector $vFrom;
	
	float $currentvertexNormals[] = `polyNormalPerVertex -q -xyz ($BTB_NormalsPaintCurrentObject + ".pnts[" + $index + "]")`;
	$vFrom = <<$currentvertexNormals[0],$currentvertexNormals[1],$currentvertexNormals[2]>>;
		
	
	if(`checkBox -q -v $BTB_NormalsToolBoxErase` == 1)
	{
		//Erase
		$vTo = unit(<<$Dx,$Dy,$Dz>>);
		
	}else
	{
		//Normal Paint
		$vTo = unit(<<$Nx,$Ny,$Nz>>);
	}
	
	$finalNormal = `BTB_Slerp $vFrom $vTo $val`;
	
	polyNormalPerVertex -xyz ($finalNormal.x) ($finalNormal.y) ($finalNormal.z) ($BTB_NormalsPaintCurrentObject + ".pnts[" + $index + "]");

}

“BTB_SetNormalsPaintValue” is computed for each vert that is effected by the paint stroke.

The parameters that I am using in the Function map to:

int $index = Vertex Index
float $val = Alpha Value
float $Dx, $Dy, $Dz = Vertex Surface Normal
float $Nx, $Ny, $Nz = Brush Stroke Normal

I hope this helped, at some stage I’ll be popping up an in-depth tutorial about this on my site.

-Butters

Hi Rob,
I know your tool! I’ve seen the video before start coding mine…and actually I was trying to duplicate your script behaviour :slight_smile:

thanks!

Nice tool! got a quick question…

When you do you access the vertex normal so it can be passed to the SetValueCommand?
From the sounds of the documentation, it seems like the flags goes from the Init to the Set Commands - when you get the vertex normal to pass to the setCmd?

Thanks.

EDIT:
nevermind, I haven’t had enough coffee, i see where it is coming from now!!

[QUOTE=Butters;18560]Hey Alessandro,

I love artUserPaintCtx, here is some code from a tool I wrote way back, so it’s in mel.

I also have a video of it in use: Normals ToolBox & reference link to Autodesk Help: Painting with MEL scripts and the Paint Scripts Tool


So the artUserPaintCtx is split up into a couple of sections:

Calling the Paint to Start and creating a context:

ScriptPaintTool; artUserPaintCtx -e -tsc "BTB_NormalsPaint" `currentCtx`;

Setup of the Context:

global proc BTB_NormalsPaint( string $context )
{
	artUserPaintCtx -e
		-ic "BTB_InitNormalsPaint"
		-fc "BTB_FinishNormalsPaint"
		-svc "BTB_SetNormalsPaintValue"
		$context;
}

Setup, Complete and Compute Functions:

global proc string BTB_InitNormalsPaint(string $name)
{
	return ("-dt worldV -n local");
}

global proc BTB_FinishNormalsPaint( int $slot ){}

global proc BTB_SetNormalsPaintValue(int $slot, int $index, float $val, float $Dx, float $Dy, float $Dz, float $Nx, float $Ny, float $Nz)
{
	global string $BTB_NormalsPaintCurrentObject;
	global string $BTB_NormalsToolBoxErase;
	
	vector $finalNormal;
	
	// Get the Effect Value and Process the Normal
	
	vector $vTo;
	vector $vFrom;
	
	float $currentvertexNormals[] = `polyNormalPerVertex -q -xyz ($BTB_NormalsPaintCurrentObject + ".pnts[" + $index + "]")`;
	$vFrom = <<$currentvertexNormals[0],$currentvertexNormals[1],$currentvertexNormals[2]>>;
		
	
	if(`checkBox -q -v $BTB_NormalsToolBoxErase` == 1)
	{
		//Erase
		$vTo = unit(<<$Dx,$Dy,$Dz>>);
		
	}else
	{
		//Normal Paint
		$vTo = unit(<<$Nx,$Ny,$Nz>>);
	}
	
	$finalNormal = `BTB_Slerp $vFrom $vTo $val`;
	
	polyNormalPerVertex -xyz ($finalNormal.x) ($finalNormal.y) ($finalNormal.z) ($BTB_NormalsPaintCurrentObject + ".pnts[" + $index + "]");

}

“BTB_SetNormalsPaintValue” is computed for each vert that is effected by the paint stroke.

The parameters that I am using in the Function map to:

int $index = Vertex Index
float $val = Alpha Value
float $Dx, $Dy, $Dz = Vertex Surface Normal
float $Nx, $Ny, $Nz = Brush Stroke Normal

I hope this helped, at some stage I’ll be popping up an in-depth tutorial about this on my site.

-Butters[/QUOTE]

Sure, When you create the initialization function you pass in that you want the normal of the poly to be passed as a parameter of the function.

global proc string BTB_InitNormalsPaint(string $name)
{
	return ("-dt worldV -n local");
}

so in this case the -n local signifies that you want the normal to be returned in the BTB_SetNormalsPaintValue function

Check out Write MEL Scripts for the Paint Scripts Tool and scroll down the the Initialize Command (-ic “InitializeCommand”) section and that will give you all the paramters you have available to pass to your main function

I hope this is what you meant.

~B)

Thanks, I got a simple paint command up and running, however, I am getting really poor performance when trying to paint on a plane with 64x64 divisions (4096 faces).

Any advice on how to speed up the painting?

Currently I am just getting the brush normal and applying to the vertex normal… i’m not doing any SLERP’ing with the original vertex normal or factoring in the brush profile.
just applying a polyNormalPerVertex inside the setValue command.

One more question, the Flood command is generating syntax errors. The SetValueCommand reads in the surfaceID, index, value, vertex normal and brush normal… but the flood operation is not sending enough data to the setCommand function, so an Error is generated: Wrong number of arguments on call to SetValueCommand.

how can a setValueCmd be set to accept a variable number of args?