/* createWire.mel V1.21 - Maya3.0
This script may be freely distributed. Modify at your own risk.
Author: Dirk Bialluch (DirkBi@Software2000.de)
Thanks must go to Duncan Brinsmead for some help and tips regarding the Paint Effects integration.
Creation date: 19.11.1999
Last update: 15.10.2000
Description
Please refer to tool help menu.
History
V1.1 FIXED
-naming bug removed
ENHANCED
-radius slider will extend range
-UI layout rearranged
NEW
-create paint effect strokes along poly edges
-set paint effects size attributes
-make brush screenspace width resolution independent
-call visor to select brush
-reset template brush
-set brush color 1
V1.11 FIXED
-brush width attribute will now be connected, if screenspace
width is turned off
V1.12 FIXED
-UI frame layout height will now be recognized by the SGI version
V1.2 CHANGED
-single edge selection is no longer supported
-history cannot be toggled off anymore
NEW
-curves, geometry and paint effects grouped individually by object
-nurbs surfaces are now supported
-select nurbs isoparm direction (u, v, both)
-set isoparm density factor
-help window
V1.21
FIXED
-uv density values swapped to match the surface direction
*/
//
// Create UI
//
global proc createWire ()
{
int $uiLabelWidth = 156;
int $uiInputWidth = 250;
int $uiExtraWidth = 35;
int $uiWidth = $uiLabelWidth + $uiInputWidth + $uiExtraWidth;
if ((`window -exists cw_ui`) == true)
deleteUI cw_ui;
window
-maximizeButton false
-resizeToFitChildren false
-menuBar true
-menuBarVisible true
-title "Create Wire V1.2"
-iconName "Create Wire"
cw_ui;
menu
-label "Edit"
-tearOff false;
menuItem
-label "Reset Create Wire Tool"
-c "cw_storeRecallUI reset; createWire";
menu
-label "Help"
-tearOff false;
menuItem
-label "Help with Create Wire Tool"
-c "cw_help 1";
menuItem
-divider true;
menuItem
-label "Script Information"
-c "cw_help 2";
string $cw1_form = `formLayout -numberOfDivisions 100`;
string $cw1_scroll = `scrollLayout -hst 16 -vst 16 -childResizable true -minChildWidth $uiWidth`;
columnLayout -adjustableColumn true -rowSpacing 5;
// input geometry settings
frameLayout
-label "Input Geometry Settings"
-labelAlign "center"
-cll true
-lw $uiWidth
-mh 3
-borderStyle "etchedIn"
-cc "cw_adjustUI"
-ec "cw_adjustUI"
-bv true
cw_igsFrame;
columnLayout -adjustableColumn true;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth;
text -l "Nurbs Surface Direction";
radioButtonGrp
-columnWidth 1 50
-columnWidth 2 50
-columnWidth 3 50
-numberOfRadioButtons 3
-select 1
-labelArray3 "UV" "U" "V"
-cc "cw_adjustUI"
cw_uvDirection;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 3
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
-columnWidth 2 80
cw_isoparmDensityU;
text -l "Isoparm Density U";
floatField
-w 80
-value 1
-min 1
-max 4
-precision 3
-cc "cw_adjustUI"
cw_isoparmDensityU;
text -l "Factor";
setParent ..;
rowLayout
-numberOfColumns 3
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
-columnWidth 2 80
cw_isoparmDensityV;
text -l "Isoparm Density V";
floatField
-w 80
-value 1
-min 1
-max 4
-precision 3
-cc "cw_adjustUI"
cw_isoparmDensityV;
text -l "Factor";
setParent ..;
setParent ..;
setParent ..;
// nurbs tube geometry
frameLayout
-label "Nurbs Tube Geometry"
-labelAlign "center"
-cll true
-lw $uiWidth
-mh 3
-borderStyle "etchedIn"
-cc "cw_adjustUI"
-ec "cw_adjustUI"
-bv true
cw_ntgFrame;
columnLayout -adjustableColumn true;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth;
text -l "Create Tubes";
checkBox
-h 20
-label ""
-value true
-cc "cw_adjustUI"
cw_createTube;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_tubeRadiusR;
text -l "Tube Radius";
floatField
-w 80
-value .1
-min 0
-precision 3
-cc "cw_adjustUI"
cw_tubeRadius;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 3
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
-columnWidth 2 $uiInputWidth
cw_tubeSectionsR;
text -l "Tube Sections";
intSliderGrp
-field true
-sliderStep 1
-value 4
-minValue 4
-maxValue 16
-cc "cw_adjustUI"
cw_tubeSections;
text -l "4-16";
setParent ..;
setParent ..;
setParent ..;
// nurbs sphere geometry
frameLayout
-label "Nurbs Sphere Geometry"
-labelAlign "center"
-cll true
-lw $uiWidth
-mh 3
-borderStyle "etchedIn"
-cc "cw_adjustUI"
-ec "cw_adjustUI"
-bv true
cw_nsgFrame;
columnLayout -adjustableColumn true;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth;
text -l "Create Spheres";
checkBox
-h 20
-label ""
-value true
-cc "cw_adjustUI"
cw_createSphere;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_sphereRadiusR;
text -l "Sphere Radius";
floatField
-w 80
-value .2
-min 0
-precision 3
-cc "cw_adjustUI"
cw_sphereRadius;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 3
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
-columnWidth 2 $uiInputWidth
cw_sphereSectionsR;
text -l "Sphere Sections";
intSliderGrp
-field true
-sliderStep 1
-value 4
-minValue 4
-maxValue 16
-cc "cw_adjustUI"
cw_sphereSections;
text -l "4-16";
setParent ..;
rowLayout
-numberOfColumns 3
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
-columnWidth 2 $uiInputWidth
cw_sphereSpansR;
text -l "Sphere Spans";
intSliderGrp
-field true
-sliderStep 1
-value 2
-minValue 2
-maxValue 16
-cc "cw_adjustUI"
cw_sphereSpans;
text -l "4-16";
setParent ..;
setParent ..;
setParent ..;
// paint effects
frameLayout
-label "Paint Effects"
-labelAlign "center"
-cll true
-lw $uiWidth
-mh 3
-borderStyle "etchedIn"
-cc "cw_adjustUI"
-ec "cw_adjustUI"
-bv true
cw_peFrame;
columnLayout -adjustableColumn true;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth;
text -l "Create Paint Effects";
checkBox
-h 20
-label ""
-value true
-cc "cw_adjustUI"
cw_createPaintEffects;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_setBrushSizeR;
text -l "Set Brush Size";
checkBox
-h 20
-label ""
-value false
-cc "cw_adjustUI"
cw_setBrushSize;
setParent ..;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_globalScaleR;
text -l "Global Scale";
floatField
-value 1
-min 0
-precision 3
-cc "cw_adjustUI"
cw_globalScale;
setParent ..;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_brushWidthR;
text -l "Brush Width";
floatField
-value .1
-min 0
-precision 3
-cc "cw_adjustUI"
cw_brushWidth;
setParent ..;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_screenspaceWidthR;
text -l "Screenspace Width";
checkBox
-h 20
-label ""
-value false
-cc "cw_adjustUI"
cw_screenspaceWidth;
setParent ..;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_resolutionIndependentR;
text -l "Resolution Independent";
checkBox
-h 20
-label ""
-value false
-cc "cw_adjustUI"
cw_resolutionIndependent;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 2
-cal 2 "center"
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_setBrushColor1R;
text -l "Set Brush Color 1";
checkBox
-h 20
-label ""
-value false
-cc "cw_adjustUI"
cw_setBrushColor1;
setParent ..;
rowLayout
-numberOfColumns 2
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_brushColor1R;
text -l "Brush Color 1";
colorSliderGrp
-rgb 1 1 1
cw_brushColor1;
setParent ..;
separator -h 8;
rowLayout
-numberOfColumns 2
-cal 2 "center"
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_visorR;
text -l "Select Brush Preset";
button
-w 80
-label "Visor"
-command "tearOffPanel Visor VisorPanel true";
setParent ..;
rowLayout
-numberOfColumns 2
-cal 2 "center"
-cat 1 "right" 5
-columnWidth 1 $uiLabelWidth
cw_resetR;
text -l "Reset Template Brush";
button
-w 80
-label "Reset"
-command "ResetTemplateBrush";
setParent ..;
setParent ..;
setParent ..;
setParent ..;
setParent ..;
setParent ..;
$cw_button = `button
-label "Create Wire"
-command "cw_main"
cw_button`;
$cw_close = `button
-label "Close"
-command "deleteUI cw_ui"`;
// set form layouts
formLayout -edit
-attachForm $cw1_scroll "top" 2
-attachForm $cw1_scroll "left" 2
-attachControl $cw1_scroll "bottom" 2 $cw_button
-attachForm $cw1_scroll "right" 2
-attachNone $cw_button "top"
-attachForm $cw_button "left" 2
-attachForm $cw_button "bottom" 2
-attachPosition $cw_button "right" 2 50
-attachNone $cw_close "top"
-attachPosition $cw_close "left" 2 50
-attachForm $cw_close "bottom" 2
-attachForm $cw_close "right" 2
$cw1_form;
// create motionControl exit scriptJob (delete help window)
scriptJob
-parent cw_ui
-uiDeleted cw_ui cw_exit;
// restore UI settings
cw_storeRecallUI recall;
cw_adjustUI;
showWindow cw_ui;
}
//
// quit motionControl
//
global proc cw_exit ()
{
if ( `window -exists cw_help` )
deleteUI cw_help;
}
//
// adjust UI settings
//
global proc cw_adjustUI ()
{
if ( !`checkBox -q -v cw_createTube` && !`checkBox -q -v cw_createSphere` && !`checkBox -q -v cw_createPaintEffects` )
button -e -enable false cw_button;
else
button -e -enable true cw_button;
if ( !`checkBox -q -v cw_createTube` )
{
rowLayout -e -enable false cw_tubeRadiusR;
rowLayout -e -enable false cw_tubeSectionsR;
}
else
{
rowLayout -e -enable true cw_tubeRadiusR;
rowLayout -e -enable true cw_tubeSectionsR;
}
if ( !`checkBox -q -v cw_createSphere` )
{
rowLayout -e -enable false cw_sphereRadiusR;
rowLayout -e -enable false cw_sphereSectionsR;
rowLayout -e -enable false cw_sphereSpansR;
}
else
{
rowLayout -e -enable true cw_sphereRadiusR;
rowLayout -e -enable true cw_sphereSectionsR;
rowLayout -e -enable true cw_sphereSpansR;
}
if ( !`checkBox -q -v cw_createPaintEffects` )
{
rowLayout -e -enable false cw_globalScaleR;
rowLayout -e -enable false cw_brushWidthR;
rowLayout -e -enable false cw_setBrushSizeR;
rowLayout -e -enable false cw_visorR;
rowLayout -e -enable false cw_screenspaceWidthR;
rowLayout -e -enable false cw_resolutionIndependentR;
rowLayout -e -enable false cw_setBrushColor1R;
rowLayout -e -enable false cw_brushColor1R;
rowLayout -e -enable false cw_resetR;
}
else
{
rowLayout -e -enable true cw_setBrushSizeR;
rowLayout -e -enable true cw_visorR;
rowLayout -e -enable true cw_setBrushColor1R;
rowLayout -e -enable true cw_brushColor1R;
rowLayout -e -enable true cw_resetR;
if ( !`checkBox -q -v cw_setBrushSize` )
{
rowLayout -e -enable false cw_globalScaleR;
rowLayout -e -enable false cw_brushWidthR;
rowLayout -e -enable false cw_screenspaceWidthR;
rowLayout -e -enable false cw_resolutionIndependentR;
}
else
{
rowLayout -e -enable true cw_globalScaleR;
rowLayout -e -enable true cw_brushWidthR;
rowLayout -e -enable true cw_screenspaceWidthR;
rowLayout -e -enable true cw_resolutionIndependentR;
if ( !`checkBox -q -v cw_screenspaceWidth` )
rowLayout -e -enable false cw_resolutionIndependentR;
else
rowLayout -e -enable true cw_resolutionIndependentR;
}
if ( !`checkBox -q -v cw_setBrushColor1` )
rowLayout -e -enable false cw_brushColor1R;
else
rowLayout -e -enable true cw_brushColor1R;
}
// store UI settings
cw_storeRecallUI store;
}
//
// store/recall UI
//
global proc cw_storeRecallUI ( string $mode )
{
string $floatFieldList[] = {
"cw_isoparmDensityU",
"cw_isoparmDensityV",
"cw_tubeRadius",
"cw_sphereRadius",
"cw_globalScale",
"cw_brushWidth"
};
string $intFieldList[] = {
};
string $intSliderGrpList[] = {
"cw_tubeSections",
"cw_sphereSections",
"cw_sphereSpans"
};
string $checkBoxList[] = {
"cw_createTube",
"cw_createSphere",
"cw_createPaintEffects",
"cw_setBrushSize",
"cw_screenspaceWidth",
"cw_resolutionIndependent",
"cw_setBrushColor1"
};
string $radioButtonGrpList[] = {
"cw_uvDirection"
};
string $frameLayoutList[] = {
"cw_igsFrame",
"cw_ntgFrame",
"cw_nsgFrame",
"cw_peFrame"
};
int $cnt;
if ( $mode == "store" )
{
for ( $cnt = 0; $cnt < size( $floatFieldList ); $cnt++ )
optionVar -floatValue $floatFieldList[$cnt] `floatField -q -value $floatFieldList[$cnt]`;
for ( $cnt = 0; $cnt < size( $intFieldList ); $cnt++ )
optionVar -intValue $intFieldList[$cnt] `intField -q -value $intFieldList[$cnt]`;
for ( $cnt = 0; $cnt < size( $intSliderGrpList ); $cnt++ )
optionVar -intValue $intSliderGrpList[$cnt] `intSliderGrp -q -value $intSliderGrpList[$cnt]`;
for ( $cnt = 0; $cnt < size( $checkBoxList ); $cnt++ )
optionVar -intValue $checkBoxList[$cnt] `checkBox -q -value $checkBoxList[$cnt]`;
for ( $cnt = 0; $cnt < size( $radioButtonGrpList ); $cnt++ )
optionVar -intValue $radioButtonGrpList[$cnt] `radioButtonGrp -q -select $radioButtonGrpList[$cnt]`;
for ( $cnt = 0; $cnt < size( $frameLayoutList ); $cnt++ )
optionVar -intValue $frameLayoutList[$cnt] `frameLayout -q -collapse $frameLayoutList[$cnt]`;
float $rgb[] = `colorSliderGrp -q -rgb cw_brushColor1`;
optionVar -floatValue cw_brushColor1R $rgb[0];
optionVar -floatValue cw_brushColor1G $rgb[1] ;
optionVar -floatValue cw_brushColor1B $rgb[2] ;
}
if ( $mode == "recall" )
{
for ( $cnt = 0; $cnt < size( $floatFieldList ); $cnt++ )
if ( `optionVar -exists $floatFieldList[$cnt]` )
floatField -e -value `optionVar -q $floatFieldList[$cnt]` $floatFieldList[$cnt];
for ( $cnt = 0; $cnt < size( $intFieldList ); $cnt++ )
if ( `optionVar -exists $intFieldList[$cnt]` )
intField -e -value `optionVar -q $intFieldList[$cnt]` $intFieldList[$cnt];
for ( $cnt = 0; $cnt < size( $intSliderGrpList ); $cnt++ )
if ( `optionVar -exists $intSliderGrpList[$cnt]` )
intSliderGrp -e -value `optionVar -q $intSliderGrpList[$cnt]` $intSliderGrpList[$cnt];
for ( $cnt = 0; $cnt < size( $checkBoxList ); $cnt++ )
if ( `optionVar -exists $checkBoxList[$cnt]` )
checkBox -e -value `optionVar -q $checkBoxList[$cnt]` $checkBoxList[$cnt];
for ( $cnt = 0; $cnt < size( $radioButtonGrpList ); $cnt++ )
if ( `optionVar -exists $radioButtonGrpList[$cnt]` )
radioButtonGrp -e -select `optionVar -q $radioButtonGrpList[$cnt]` $radioButtonGrpList[$cnt];
for ( $cnt = 0; $cnt < size( $frameLayoutList ); $cnt++ )
if ( `optionVar -exists $frameLayoutList[$cnt]` )
frameLayout -e -collapse `optionVar -q $frameLayoutList[$cnt]` $frameLayoutList[$cnt];
if ( `optionVar -exists cw_brushColor1R` && `optionVar -exists cw_brushColor1G` && `optionVar -exists cw_brushColor1B` )
colorSliderGrp -e -rgb `optionVar -q cw_brushColor1R` `optionVar -q cw_brushColor1G` `optionVar -q cw_brushColor1B` cw_brushColor1;
}
if ( $mode == "reset" )
{
for ( $cnt = 0; $cnt < size( $floatFieldList ); $cnt++ )
optionVar -remove $floatFieldList[$cnt];
for ( $cnt = 0; $cnt < size( $intFieldList ); $cnt++ )
optionVar -remove $intFieldList[$cnt];
for ( $cnt = 0; $cnt < size( $intSliderGrpList ); $cnt++ )
optionVar -remove $intSliderGrpList[$cnt];
for ( $cnt = 0; $cnt < size( $checkBoxList ); $cnt++ )
optionVar -remove $checkBoxList[$cnt];
for ( $cnt = 0; $cnt < size( $radioButtonGrpList ); $cnt++ )
optionVar -remove $radioButtonGrpList[$cnt];
for ( $cnt = 0; $cnt < size( $frameLayoutList ); $cnt++ )
optionVar -remove $frameLayoutList[$cnt];
optionVar -remove cw_brushColor1R;
optionVar -remove cw_brushColor1G;
optionVar -remove cw_brushColor1B;
}
}
//
// Create nurbs tube from curve
//
proc string[] cw_crv2Tube ( string $crv, float $radius, int $sections )
{
// get start pos and tan of curve in world space
float $pos[] = `pointOnCurve -pr .0001 -position $crv`;
float $tan[] = `pointOnCurve -pr .0001 -tangent $crv`;
// make circle at start matching curve tangent
string $profile[] = `circle -c $pos[0] $pos[1] $pos[2] -nr $tan[0] $tan[1] $tan[2] -r $radius -sections $sections`;
xform -cp $profile[0];
// extrude spiral
string $spiral[] = `extrude -fixedPath true -ucp true -upn true -et 2 $profile[0] $crv`;
// return spiral surface, profile curve, profile shape
return {$spiral[0], $profile[0], $profile[1]};
}
//
// create tube geometry
//
proc cw_createTubes (
string $sourceObject,
string $curveList[],
float $tubeRadius,
int $tubeSections )
{
string $circleList[];
string $tubeList[];
// add Tube Radius attribute
addAttr -sn "tr" -ln "tubeRadius" -at "float" -min 0 $sourceObject;
setAttr -keyable on ( $sourceObject + ".tubeRadius" ) $tubeRadius;
// add Tube Sections attribute
addAttr -sn "tse" -ln "tubeSections" -at "short" -min 4 $sourceObject;
setAttr -keyable on ( $sourceObject + ".tubeSections" ) $tubeSections;
// create tube group
string $tubeGroup = `group -em -n ( $sourceObject + "WireTubes" )`;
for ( $cnt = 0; $cnt < size( $curveList ); $cnt++ )
{
// create tube geometry
string $tube[] = `cw_crv2Tube $curveList[$cnt] $tubeRadius $tubeSections`;
$circleList[$cnt] = $tube[1];
$tubeList[$cnt] = $tube[0];
// connect history attributes
connectAttr -f ( $sourceObject + ".tubeRadius" ) ( $tube[2] + ".radius" );
connectAttr -f ( $sourceObject + ".tubeSections" ) ( $tube[2] + ".sections" );
parent $tube[0] $tubeGroup;
}
string $circleGroup = `group -em -n ( $sourceObject + "circles" )`;
parent $circleList $circleGroup;
hide $circleGroup;
}
//
// create sphere geometry
//
proc cw_createSpheresFromMesh (
string $sourceObject,
float $sphereRadius,
int $sphereSections,
int $sphereSpans )
{
// create object group
string $sphereGroup = `group -em -n ( $sourceObject + "WireSpheres" )`;
// add Sphere Radius attribute
addAttr -sn "sr" -ln "sphereRadius" -at "float" -min 0 $sourceObject;
setAttr -keyable on ( $sourceObject + ".sphereRadius" ) $sphereRadius;
// add Sphere Sections attribute
addAttr -sn "sse" -ln "sphereSections" -at "short" -min 4 $sourceObject;
setAttr -keyable on ( $sourceObject + ".sphereSections" ) $sphereSections;
// add Sphere Spans attribute
addAttr -sn "ssp" -ln "sphereSpans" -at "short" -min 2 $sourceObject;
setAttr -keyable on ( $sourceObject + ".sphereSpans" ) $sphereSpans;
// get number of vertices in poly mesh
int $vertexNum[] = `polyEvaluate -v $sourceObject`;
for ( $vCnt = 0; $vCnt < $vertexNum[0]; $vCnt++ )
{
// create sphere
string $sphere[] = `sphere -r $sphereRadius -sections $sphereSections -spans $sphereSpans`;
float $pos[] = `pointPosition ( $sourceObject + ".vtx[" + $vCnt + "]" )`;
move $pos[0] $pos[1] $pos[2] $sphere[0];
// connect attributes
connectAttr -f ( $sourceObject + ".sphereRadius" ) ( $sphere[1] + ".radius" );
connectAttr -f ( $sourceObject + ".sphereSections" ) ( $sphere[1] + ".sections" );
connectAttr -f ( $sourceObject + ".sphereSpans" ) ( $sphere[1] + ".spans" );
parent $sphere[0] $sphereGroup;
}
}
proc cw_createSpheresFromSurface (
string $sourceObject,
float $sphereRadius,
int $sphereSections,
int $sphereSpans,
float $isoparmDensityU,
float $isoparmDensityV )
{
// create object group
string $sphereGroup = `group -em -n ( $sourceObject + "WireSpheres" )`;
// add Sphere Radius attribute
addAttr -sn "sr" -ln "sphereRadius" -at "float" -min 0 $sourceObject;
setAttr -keyable on ( $sourceObject + ".sphereRadius" ) $sphereRadius;
// add Sphere Sections attribute
addAttr -sn "sse" -ln "sphereSections" -at "short" -min 4 $sourceObject;
setAttr -keyable on ( $sourceObject + ".sphereSections" ) $sphereSections;
// add Sphere Spans attribute
addAttr -sn "ssp" -ln "sphereSpans" -at "short" -min 2 $sourceObject;
setAttr -keyable on ( $sourceObject + ".sphereSpans" ) $sphereSpans;
int $spansU = `getAttr ( $sourceObject + ".spansU" )`;
int $spansV = `getAttr ( $sourceObject + ".spansV" )`;
$spansU *= $isoparmDensityU;
$spansV *= $isoparmDensityV;
for ( $uCnt = 0; $uCnt <= $spansU; $uCnt++ )
{
for ( $vCnt = 0; $vCnt <= $spansV; $vCnt++ )
{
string $infoNode = `pointOnSurface -ch on -top true -u ( float ( $uCnt ) / float ( $spansU ) ) -v ( float ( $vCnt ) / float ( $spansV ) ) $sourceObject`;
// create sphere
string $sphere[] = `sphere -r $sphereRadius -sections $sphereSections -spans $sphereSpans`;
connectAttr -f ( $infoNode + ".position" ) ( $sphere[0] + ".translate" );
// connect attributes
connectAttr -f ( $sourceObject + ".sphereRadius" ) ( $sphere[1] + ".radius" );
connectAttr -f ( $sourceObject + ".sphereSections" ) ( $sphere[1] + ".sections" );
connectAttr -f ( $sourceObject + ".sphereSpans" ) ( $sphere[1] + ".spans" );
parent $sphere[0] $sphereGroup;
}
}
}
//
// create paint effects
//
proc cw_createPaintEffects (
string $sourceObject,
string $curveList[],
int $cos,
float $globalScale,
float $brushWidth,
int $setBrushSize,
int $screenspaceWidth,
int $resolutionIndependent,
int $setBrushColor1,
float $brushColor1[] )
{
// create strokes
string $brush = `getDefaultBrush`;
string $newBrush[] = `duplicate -ic $brush`;
brushStartSetup( $newBrush[0], 1 );
connectAttr time1.outTime ( $newBrush[0] + ".time" );
// create stroke group
string $strokeGroup = `group -em -n ( $sourceObject + "WireStrokes" )`;
int $spans;
for ( $cCnt = 0; $cCnt < size( $curveList ); $cCnt++ )
{
string $newStroke = `stroke -seed $cCnt -pressure true`;
connectAttr ( $newBrush[0] + ".outBrush") ( $newStroke + ".brush" );
$spans = `getAttr ( $curveList[$cCnt]+ ".spans" )`;
$spans *= 6; // Scaling factor for the smoothness of the curve once converted. Currently 6 samples per span.
setAttr ( $newStroke + ".pathCurve[0].samples" ) $spans;
setAttr ( $newStroke + ".useNormal" ) 0;
setAttr ( $newStroke + ".normalY" ) 1.0;
string $sourceShape[] = `listRelatives -s $sourceObject`;
if ( $cos )
{
string $cFS = `createNode curveFromSurfaceCoS`;
connectAttr ( $curveList[$cCnt] + ".ws[0]" ) ( $cFS + ".curveOnSurface" );
connectAttr ( $sourceShape[0] + ".ws[0]" ) ( $cFS + ".inputSurface" );
connectAttr ( $cFS + ".oc" ) ( $newStroke + ".pathCurve[0].curve" );
}
else
connectAttr ( $curveList[$cCnt] + ".ws" ) ( $newStroke + ".pathCurve[0].curve" );
setAttr ( $newStroke + ".perspective" ) 1;
setAttr ( $newStroke + ".displayPercent" ) 20;
parent -r $newStroke $strokeGroup;
}
if ( $setBrushSize )
{
// add brush attributes
addAttr -sn "bw" -ln "brushWidth" -at "float" -min 0 $sourceObject;
setAttr -keyable on ( $sourceObject + ".brushWidth" ) $brushWidth;
addAttr -sn "gs" -ln "globalScale" -at "float" -min 0 $sourceObject;
setAttr -keyable on ( $sourceObject + ".globalScale" ) $globalScale;
// connect attributes
connectAttr -f ( $sourceObject + ".globalScale" ) ( $newBrush[0] + ".globalScale" );
// set screenspace width
if ( $screenspaceWidth )
{
setAttr ( $newBrush[0] + ".screenspaceWidth" ) 1;
if ( $resolutionIndependent )
{
// create nodes for screenwidth <-> render resolution relationship
// $newBrush[0].brushWidth = $wireGroup * 1 / defaultResolution.width * 640
string $divNode1 = `createNode multiplyDivide`;
string $divNode2 = `createNode multiplyDivide`;
string $multNode = `createNode multiplyDivide`;
setAttr ( $divNode1 + ".operation" ) 2;
setAttr ( $divNode1 + ".input2X" ) 320;
setAttr ( $multNode + ".operation" ) 1;
setAttr ( $divNode2 + ".operation" ) 2;
setAttr ( $divNode2 + ".input1X" ) 1;
connectAttr defaultResolution.width ( $divNode1 + ".input1X" );
connectAttr ( $divNode1 + ".outputX" ) ( $divNode2 + ".input2X" );
connectAttr ( $divNode2 + ".outputX" ) ( $multNode + ".input2X" );
connectAttr ( $sourceObject + ".brushWidth" ) ( $multNode + ".input1X" );
connectAttr ( $multNode + ".outputX" ) ( $newBrush[0] + ".brushWidth" );
}
else
connectAttr -f ( $sourceObject + ".brushWidth" ) ( $newBrush[0] + ".brushWidth" );
}
else
{
connectAttr -f ( $sourceObject + ".brushWidth" ) ( $newBrush[0] + ".brushWidth" );
setAttr ( $newBrush[0] + ".screenspaceWidth" ) 0;
}
}
// set brush color 1
if ( $setBrushColor1 )
setAttr ( $newBrush[0] + ".color1" ) $brushColor1[0] $brushColor1[1] $brushColor1[2];
}
//
// Main procedure
//
global proc cw_main ()
{
// get UI values
int $uvDirection = `radioButtonGrp -q -select cw_uvDirection`;
float $isoparmDensityU = `floatField -q -v cw_isoparmDensityU`;
float $isoparmDensityV = `floatField -q -v cw_isoparmDensityV`;
int $createTube = `checkBox -q -v cw_createTube`;
float $tubeRadius = `floatField -q -v cw_tubeRadius`;
int $tubeSections = `intSliderGrp -q -v cw_tubeSections`;
int $createSphere = `checkBox -q -v cw_createSphere`;
float $sphereRadius = `floatField -q -v cw_sphereRadius`;
int $sphereSections = `intSliderGrp -q -v cw_sphereSections`;
int $sphereSpans = `intSliderGrp -q -v cw_sphereSpans`;
int $createPaintEffects = `checkBox -q -v cw_createPaintEffects`;
float $globalScale = `floatField -q -v cw_globalScale`;
float $brushWidth = `floatField -q -v cw_brushWidth`;
int $setBrushSize = `checkBox -q -v cw_setBrushSize`;
int $screenspaceWidth = `checkBox -q -v cw_screenspaceWidth`;
int $resolutionIndependent = `checkBox -q -v cw_resolutionIndependent`;
int $setBrushColor1 = `checkBox -q -v cw_setBrushColor1`;
float $brushColor1[] = `colorSliderGrp -q -rgb cw_brushColor1`;
// filter selected nodes / components
string $selMeshes[] = `filterExpand -sm 12`;
string $selSurfaces[] = `filterExpand -sm 10`;
if ( !size ( $selMeshes ) && !size ( $selSurfaces ) )
error "No polygon or nurbs objects selected";
waitCursor -state on;
string $curveList[] = {};
// process selected meshes
for ( $mCnt = 0; $mCnt < size( $selMeshes ); $mCnt++ )
{
// check if mesh has already been used for wire creation
if ( `attributeQuery -exists -n $selMeshes[$mCnt] tubeRadius` || `attributeQuery -exists -n $selMeshes[$mCnt] sphereRadius` || `attributeQuery -exists -n $selMeshes[$mCnt] brushWidth` )
warning ( "Object \"" + $selMeshes[$mCnt] + "\" already connected to existing wire geometry - wire creation skipped" );
else
{
// create curve group
string $curveGroup = `group -em -n ( $selMeshes[$mCnt] + "WireCurves" )`;
hide $curveGroup;
$curveList = {};
// convert selected mesh shape nodes to edges
int $edgeNum[] = `polyEvaluate -e $selMeshes[$mCnt]`; // get number of edges in poly mesh
// convert edges to nurbs curves
for ( $edgeCnt = 0; $edgeCnt < $edgeNum[0]; $edgeCnt++ )
{
// convert current edge to vertices
string $vertex[] = `polyListComponentConversion -fromEdge -toVertex ( $selMeshes[$mCnt] + ".e[" + $edgeCnt + "]" )`;
// convert from object.vtx[0:1] to two single vertices
string $buffer1[];
string $buffer2[];
if ( `tokenize $vertex[0] ":" $buffer1` > 1 ) // are vertices set to [x:x] ?
{
tokenize $buffer1[1] "]" $buffer2;
int $vertex2 = int ( $buffer2[0] );
tokenize $buffer1[0] "[" $buffer2;
int $vertex1 = int ( $buffer2[1] );
$vertex[0] = $buffer2[0] + "[" + $vertex1 + "]";
$vertex[1] = $buffer2[0] + "[" + $vertex2 + "]";
}
float $pos1[] = `pointPosition $vertex[0]`;
float $pos2[] = `pointPosition $vertex[1]`;
string $curve = `curve -d 1 -p $pos1[0] $pos1[1] $pos1[2] -p $pos2[0] $pos2[1] $pos2[2]`;
// parent nurbs curve to group
string $curveParent[] = `parent -r $curve $curveGroup`;
$curveList[$edgeCnt] = $curveParent[0];
}
if ( $createTube )
cw_createTubes
$selMeshes[$mCnt]
$curveList
$tubeRadius
$tubeSections;
if ( $createSphere )
cw_createSpheresFromMesh
$selMeshes[$mCnt]
$sphereRadius
$sphereSections
$sphereSpans;
if ( $createPaintEffects )
cw_createPaintEffects
$selMeshes[$mCnt]
$curveList
0
$globalScale
$brushWidth
$setBrushSize
$screenspaceWidth
$resolutionIndependent
$setBrushColor1
$brushColor1;
}
}
// process selected surfaces
string $curveListU[] = {};
string $curveListV[] = {};
for ( $sCnt = 0; $sCnt < size( $selSurfaces ); $sCnt++ )
{
// check if surface has already been used for wire creation
if ( `attributeQuery -exists -n $selSurfaces[$sCnt] tubeRadius` || `attributeQuery -exists -n $selSurfaces[$sCnt] sphereRadius` || `attributeQuery -exists -n $selSurfaces[$sCnt] brushWidth` )
warning ( "Object \"" + $selSurfaces[$sCnt] + "\" already connected to existing wire geometry - wire creation skipped" );
else
{
$curveList = {};
float $minValueU = `getAttr ( $selSurfaces[$sCnt] + ".minValueU" )`;
float $maxValueU = `getAttr ( $selSurfaces[$sCnt] + ".maxValueU" )`;
int $spansU = `getAttr ( $selSurfaces[$sCnt] + ".spansU" )`;
$spansU *= $isoparmDensityU;
int $degreeU = `getAttr ( $selSurfaces[$sCnt] + ".degreeU" )`;
float $minValueV = `getAttr ( $selSurfaces[$sCnt] + ".minValueV" )`;
float $maxValueV = `getAttr ( $selSurfaces[$sCnt] + ".maxValueV" )`;
int $spansV = `getAttr ( $selSurfaces[$sCnt] + ".spansV" )`;
$spansV *= $isoparmDensityV;
int $degreeV = `getAttr ( $selSurfaces[$sCnt] + ".degreeV" )`;
// convert isoparms to curves on surface
if ( $uvDirection == 1 || $uvDirection == 3 ) // u direction
{
// create curve on surface
for ( $iCnt = 0; $iCnt <= $spansV; $iCnt++ )
{
// build curve creation command string
string $cosCmd = "curveOnSurface -d " + $degreeU;
for ( $cCnt = 0; $cCnt < ( $degreeU + 1 ) / 2; $cCnt++ )
$cosCmd = $cosCmd + " -uv " + $minValueU + " " + ( ( $maxValueV - $minValueV ) * float ( $iCnt ) / float ( $spansV ) + $minValueV );
for ( $cCnt = 1; $cCnt < $spansU; $cCnt++ )
$cosCmd = $cosCmd + " -uv " + ( ( $maxValueU - $minValueU ) * float ( $cCnt ) / float ( $spansU ) + $minValueU ) + " " +
( ( $maxValueV - $minValueV ) * float ( $iCnt ) / float ( $spansV ) + $minValueV );
for ( $cCnt = 0; $cCnt < ( $degreeU + 1 ) / 2; $cCnt++ )
$cosCmd = $cosCmd + " -uv " + $maxValueU + " " + ( ( $maxValueV - $minValueV ) * float ( $iCnt ) / float ( $spansV ) + $minValueV );
int $knot = 0;
for ( $cCnt = 0; $cCnt < $degreeU; $cCnt++ )
$cosCmd = $cosCmd + " -k " + $knot;
$knot++;
for ( $cCnt = 1; $cCnt < $spansU; $cCnt++ )
$cosCmd = $cosCmd + " -k " + ( $knot++ );
for ( $cCnt = 0; $cCnt < $degreeU; $cCnt++ )
$cosCmd = $cosCmd + " -k " + $knot;
$cosCmd = $cosCmd + " " + $selSurfaces[$sCnt];
$curveList[size( $curveList )] = `eval $cosCmd`;
}
}
if ( $uvDirection == 1 || $uvDirection == 2 ) // v direction
{
// create curve on surface
for ( $iCnt = 0; $iCnt <= $spansU; $iCnt++ )
{
string $cosCmd = "curveOnSurface -d " + $degreeV;
for ( $cCnt = 0; $cCnt < ( $degreeV + 1 ) / 2; $cCnt++ )
$cosCmd = $cosCmd + " -uv " + ( ( $maxValueU - $minValueU ) * float ( $iCnt ) / float ( $spansU ) + $minValueU ) + " " + $minValueV;
for ( $cCnt = 1; $cCnt < $spansV; $cCnt++ )
$cosCmd = $cosCmd + " -uv " + ( ( $maxValueU - $minValueU ) * float ( $iCnt ) / float ( $spansU ) + $minValueU ) + " " +
( ( $maxValueV - $minValueV ) * float ( $cCnt ) / float ( $spansV ) + $minValueV );
for ( $cCnt = 0; $cCnt < ( $degreeV + 1 ) / 2; $cCnt++ )
$cosCmd = $cosCmd + " -uv " + ( ( $maxValueU - $minValueU ) * float ( $iCnt ) / float ( $spansU ) + $minValueU ) + " " + $maxValueV;
int $knot = 0;
for ( $cCnt = 0; $cCnt < $degreeV; $cCnt++ )
$cosCmd = $cosCmd + " -k " + $knot;
$knot++;
for ( $cCnt = 1; $cCnt < $spansV; $cCnt++ )
$cosCmd = $cosCmd + " -k " + ( $knot++ );
for ( $cCnt = 0; $cCnt < $degreeV; $cCnt++ )
$cosCmd = $cosCmd + " -k " + $knot;
$cosCmd = $cosCmd + " " + $selSurfaces[$sCnt];
$curveList[size( $curveList )] = `eval $cosCmd`;
}
}
if ( $createTube )
cw_createTubes
$selSurfaces[$sCnt]
$curveList
$tubeRadius
$tubeSections;
if ( $createSphere )
cw_createSpheresFromSurface
$selSurfaces[$sCnt]
$sphereRadius
$sphereSections
$sphereSpans
$isoparmDensityU
$isoparmDensityV;
if ( $createPaintEffects )
cw_createPaintEffects
$selSurfaces[$sCnt]
$curveList
1
$globalScale
$brushWidth
$setBrushSize
$screenspaceWidth
$resolutionIndependent
$setBrushColor1
$brushColor1;
}
}
waitCursor -state off;
}
// end of script
There are no threads for this page.
Be the first to start a new thread.