2025-06-04 03:22:50 +02:00

353 lines
8.0 KiB
Plaintext

global proc AEDirectXShaderTemplate ( string $node )
{
editorTemplate -beginScrollLayout;
editorTemplate -label "Maya Viewer Color" -addControl "color" ;
editorTemplate -callCustom AEDirectXNew AEDirectXReplace $node;
editorTemplate -endLayout;
// Hide "Extra Attributes" UI for dynamic attributes.
editorTemplate -addExtraControls;
editorTemplate -endScrollLayout;
}
global proc AEDirectXNew( string $messagePlug )
{
AEDirectXReplace($messagePlug);
}
proc DxFxParameterLayout( string $shaderNode )
{
string $dxfxScript= `getAttr ($shaderNode + ".FxScript")`;
eval( $dxfxScript );
}
global proc DxFxScriptTest(string $shaderNode )
{
string $dxfxWindow= "FxShaderTest";
if ( `window -exists $dxfxWindow` )
deleteUI $dxfxWindow;
window -widthHeight 200 300 $dxfxWindow;
if ( `frameLayout -exists dxfxAEFrame` )
deleteUI dxfxAEFrame;
frameLayout -label "DirectX Effect Parameters"
-borderStyle "etchedIn"
-collapsable true
-marginWidth 10
-visible true
dxfxAEFrame;
{
columnLayout -adjustableColumn true -columnAlign "left";
{
DxFxParameterLayout($shaderNode);
setParent ..;
}
setParent ..;
}
showWindow $dxfxWindow;
}
global proc string plugNode( string $plug )
{
string $buffer[];
tokenize($plug, ".", $buffer);
return $buffer[0];
}
global proc dxfxDeleteAttribute(string $AttrName, string $Node)
{
if( `attributeExists $AttrName $Node` )
{
catch( `deleteAttr -attribute $AttrName $Node` );
}
}
global proc dxfxStackDown(int $change)
{
int $index;
for($index= $change; $index < 0; $index++)
{
setParent ..;
setParent ..;
}
}
global proc dxfxStackUp( string $UIName, int $NoChildren)
{
if($NoChildren)
{
columnLayout -adjustableColumn true;
}
else
{
frameLayout -label $UIName
-borderStyle "out"
-font "smallPlainLabelFont"
-marginWidth 10
-collapse true
-collapsable true
-visible true;
}
columnLayout -adjustableColumn true;
}
global proc dxfxControlColorCreate(string $UIName, string $plug, int $length)
{
string $colorUIName = $UIName;
if($length == 4)
$colorUIName = ($colorUIName + ".rgb");
string $colorSlider = `colorSliderGrp -label $colorUIName`;
string $quotedColorSlider = ("\"" + $colorSlider + "\"");
string $quotedPlug = ("\"" + $plug + "\"");
string $callback = "dxfxControlColorCallback( " + $quotedColorSlider + " , " + $quotedPlug + " )";
float $P0Value= `getAttr ($plug + "[0]")`;
float $P1Value= `getAttr ($plug + "[1]")`;
float $P2Value= `getAttr ($plug + "[2]")`;
//print ("ColorValues: " + $P0Value + " " + $P1Value + " " + $P2Value + " ");
colorSliderGrp -edit -rgbValue $P0Value $P1Value $P2Value $colorSlider;
//print ("ColorValues2: " + $P0Value + " " + $P1Value + " " + $P2Value + " ");
colorSliderGrp -edit -changeCommand $callback $colorSlider;
if($length == 4)
{
string $alphaPlug = ($plug + "[3]");
string $alphaUIName = ($UIName + ".a");
dxfxControlSliderCreate( "float", $alphaUIName, 0.0, 1.0, 0.01, $alphaPlug);;
}
}
global proc dxfxControlColorCallback(string $control, string $plug)
{
float $colorValues[3]= `colorSliderGrp -q -rgbValue $control`;
setAttr ($plug + "[0]") $colorValues[0];
setAttr ($plug + "[1]") $colorValues[1];
setAttr ($plug + "[2]") $colorValues[2];
}
global proc dxfxControlSliderCreate(string $type, string $UIName, float $min, float $max, float $step, string $plug)
{
string $quotedUIName = ("\"" + $UIName + "\"");
string $Slider;
if(0 == strcmp( $type, "float" ))
{
float $floatMin = $min;
float $floatMax = $max;
float $floatStep = $step;
$Slider = `floatSliderGrp -label $UIName -minValue $floatMin -maxValue $floatMax -step $floatStep -field true`;
}
else
{
if(0 == strcmp( $type, "int" ))
{
int $intMin = $min;
int $intMax = $max;
int $intStep = $step;
$Slider = `intSliderGrp -label $UIName -minValue $intMin -maxValue $intMax -step $intStep -field true`;
}
else
{
if(0 == strcmp( $type, "bool" ))
{
$Slider = `intSliderGrp -label $UIName -minValue 0 -maxValue 1 -step 1 -field true`;
}
else
{
return;
}
}
}
connectControl $Slider $plug;
}
global proc dxfxControlScalarCreate(string $type, string $UIName, string $plug)
{
string $control;
if(0 == strcmp( $type, "float" ))
{
$control = "floatFieldGrp";
}
else
{
if(0 == strcmp( $type, "int" ))
{
$control = "intFieldGrp";
}
else
{
if(0 == strcmp( $type, "bool" ))
{
$control = "checkBoxGrp";
}
else
{
return;
}
}
}
string $command = ( $control + " -numberOfFields 1" + " -label \"" + $UIName + "\"" + " -columnWidth 2 220" );
string $rowCtrl= eval($command);
connectControl -index 2 $rowCtrl $plug;
}
global proc dxfxControlVectorCreate(string $type, string $UIName, string $plug, int $length)
{
dxfxControlMatrixCreate($type, $UIName, $plug, 1, $length);
}
global proc dxfxControlMatrixCreate(string $type, string $UIName, string $plug, int $rows, int $columns )
{
string $control;
if(0 == strcmp( $type, "float" ))
{
$control = "floatFieldGrp";
}
else
{
if(0 == strcmp( $type, "int" ))
{
$control = "intFieldGrp";
}
else
{
if(0 == strcmp( $type, "bool" ))
{
$control = "checkBoxGrp";
}
else
{
return;
}
}
}
int $rowIndex;
for($rowIndex= 0; $rowIndex < $rows; $rowIndex++)
{
string $command;
int $columnIndex;
$command = ($control + " -numberOfFields " + $columns );
if($rowIndex == 0)
$command = ($command + " -label \"" + $UIName + "\"");
for( $columnIndex = 0; $columnIndex < $columns; $columnIndex++ )
{
$command = ($command + " -columnWidth " + ($columnIndex + 2) + " " + (220 / $columns) );
}
string $rowCtrl= eval($command);
for( $columnIndex = 0; $columnIndex < $columns; $columnIndex++ )
{
int $plugIndex = ( $rowIndex * $rows ) + $columnIndex;
string $subPlugName = ($plug + "[" + $plugIndex + "]");
connectControl -index ( $columnIndex + 2 ) $rowCtrl $subPlugName;
}
}
}
global proc dxfxControlStringCreate(string $UIName, string $plug)
{
string $rowCtrl= `textFieldGrp -label $UIName`;
connectControl -index 2 $rowCtrl $plug;
}
global proc dxfxControlTextureCreate(string $UIName, string $plug)
{
string $quotedPlug = ("\"" + $plug + "\"");
string $buttonCmd = ("setAttr -type \"string\" " + $quotedPlug + " `fileDialog -directoryMask \"*.dds;*.jpg;*.bmp;*.tga;*.png;*.ppm;*.dib;*.hdr;*.pfm\"`;");
string $rowCtrl= `textFieldButtonGrp -label $UIName -buttonLabel "..." -buttonCommand $buttonCmd`;
connectControl -index 2 $rowCtrl $plug;
}
global proc AEDirectXReplace( string $messagePlug )
{
string $shaderNode = plugNode($messagePlug);
{
string $dxfxFileAttribute = $shaderNode + ".FxFile";
string $dxfxFile= `getAttr $dxfxFileAttribute`;
string $dxfxSetFile = "setAttr -type \"string\" " + $dxfxFileAttribute + " `fileDialog -directoryMask \"*.fx\"`";
string $dxfxReloadFile = "setAttr -type \"string\" " + $dxfxFileAttribute + " `getAttr -asString " + $dxfxFileAttribute + "`";
if ( `textFieldButtonGrp -exists dxfxFileControl` )
deleteUI dxfxFileControl;
textFieldButtonGrp
-label "DirectX Effect File"
-text $dxfxFile
-editable false
-buttonLabel "..."
-buttonCommand $dxfxSetFile
dxfxFileControl;
scriptJob
-parent dxfxFileControl
-replacePrevious
-killWithScene
-runOnce false
-compressUndo true
-attributeChange $dxfxFileAttribute "refreshAE;";
if ( `button -exists dxfxReloadControl` )
deleteUI dxfxReloadControl;
button
-label "Reload Effect File"
-command $dxfxReloadFile
dxfxReloadControl;
if ( `frameLayout -exists dxfxRollOut` )
deleteUI dxfxRollOut;
frameLayout -label "DirectX Effect Parameters"
-collapse false
-collapsable true
-visible false
dxfxRollOut;
{
columnLayout -adjustableColumn true;
{
DxFxParameterLayout($shaderNode);
setParent ..;
}
layout -edit -visible true dxfxRollOut;
setParent ..;
}
setParent ..;
setUITemplate -popTemplate;
}
}