/* GlueCluster 1.0 par Cedric Release 14/05/2006 With this script your can create a 'glue cluster' : it's a cluster who stay in place and follow a deformed object. Usefull for correct a skin problem at a specific frame, or create a simple muscle system Needed scripts : rivet, polyVertexContraint and addDolliculeContraint Script testé en prod... a prioris sans bug. Se met entre le smooth et entre les deformers... ToDo : -increment automatique des noms -createSet -editmemeberSet facile -paintWeight facile */ global proc CNclusterGlue() { global string $CNgc_edges[]; int $enableBt = 0; if ((`window -ex CNclusterGlueWindow`) == true) deleteUI CNclusterGlueWindow; window -t "Glue Cluster" -h 335 -width 236 -s 1 -resizeToFitChildren false CNclusterGlueWindow ; columnLayout -adjustableColumn true; rowLayout -numberOfColumns 2 -columnWidth2 210 15; text -align "center" -l " glueCluster1.0 by Cédric"; //button -h 18 -l "?" -c "muppic_Help;"; setParent ..; separator -h 20 ; setParent ..; // string $form = `formLayout`; string $tabs = `tabLayout -innerMarginWidth 2 -innerMarginHeight 2 -w 50`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachForm $tabs "bottom" 0 -attachForm $tabs "right" 0 $form; string $child1 = `columnLayout -adjustableColumn true`; separator -h 20 ; rowColumnLayout -numberOfColumns 2 -columnAttach 1 "right" 0 -columnWidth 1 40 -columnWidth 2 140; text -label "Name"; textField -tx "glueCluster" nameField; setParent ..; separator -style "none" -h 10 ; string $typeRadio = `radioButtonGrp -cc3 "button -edit -en 0 buttonEdges;text -edit -en 0 textEdge;" -cc2 "button -edit -en 1 buttonEdges;text -edit -en 1 textEdge;" -cc1 "button -edit -en 0 buttonEdges;text -edit -en 0 textEdge;" -numberOfRadioButtons 3 -cw4 35 65 55 60 -label "Type" -labelArray3 "Follicule" "Rivet" "vtxRivet" -select 3 radioButtonType`; separator -h 20 ; if (`size($CNgc_edges)` == 0) text -en 0 -align "center" -l "please select 2 edges" textEdge; else text -en 0 -align "center" -l ("2 edges : " + $CNgc_edges[0] + " & " + $CNgc_edges[1]) textEdge; button -en 0 -l "Select!" -c "GCedges_store" buttonEdges; separator -h 20 ; //checkBoxGrp -numberOfCheckBoxes 1 -cw2 110 50 -label "before polySmooth?" -value1 true CNGCbeforeSmooth; //separator -h 20 ; button -h 30 -l "-CREATION-" -bgc 0.3 1 0.3 -c "CNglueCluster_create"; setParent ..; string $child2 = `columnLayout -adjustableColumn true`; separator -h 10 ; text -align "center" -l "glueCluster pivot"; button -l "enter in glueCluster pivot mode" -c "CNgc_pivot begin"; button -l "ok, it's finish" -c "CNgc_pivot finish"; setParent ..; tabLayout -edit -tabLabel $child1 "Create" -tabLabel $child2 "Edit" $tabs; showWindow CNclusterGlueWindow; } //************************************************************************************************************ //************************************************************************************************************ global proc CNglueCluster_create() { //------------------------ int $debugMode = 1; if ($debugMode == 1) print "//CNclusterGluer debug...\n"; //----------------------- //init global string $CNgc_edges[]; string $curSel[] = `ls -sl`; int $intSystemType = `radioButtonGrp -q -select radioButtonType`; string $nameOfSystem = `textField -q -tx nameField`; string $makeLocator[]; string $buffer[]; string $shapesOfFollicule[]; string $shapes[]; string $tempName[]; string $lastDeformer[]; string $offsetGroup; int $CNsize; int $increment = 0; string $nameOfRivet; string $rivetConnection[]; string $realLastDeform; int $thereIsPolySmooth = 0; string $deformerOfpolySmooth[]; string $nameOfSmoothNode; string $newPolySmooth2[]; float $characSmooth[]; string $listOfSmoothConnections[]; //verification de non valide if (`objExists ( $nameOfSystem + "_GCcontraint" )`) CNglueCluster_errorWin ("please choose an other name"); if ( ( $intSystemType == 3 ) && (`size($curSel)` != 1 ) ) CNglueCluster_errorWin ("please select only ONE vertex in vtxRivet mode\n You can add vertex after... please be cool..."); // take the last deformer tokenize $curSel[0] "." $buffer; if ($debugMode == 1) print ( "//______buffer\n" ); if ($debugMode == 1) print ( $buffer ); $shapes = `listRelatives -s -ni -path $buffer[0]`; if ($debugMode == 1) print "SHAPES\n"; if ($debugMode == 1) print $shapes; $lastDeformer = `listConnections -d 0 -s 1 $shapes[0]`; $CNsize = `size $lastDeformer`; for ( $singleLastDeformer in $lastDeformer ) { //eliminer les noeud tweak, les layers et les objets set de l'enregistrement if ( ( `nodeType $singleLastDeformer` != "objectSet" ) && ( `nodeType $singleLastDeformer` != "displayLayer" ) && ( `nodeType $singleLastDeformer` != "tweak" ) && ( `nodeType $singleLastDeformer` != "blendShape1GroupId" ) && ( `nodeType $singleLastDeformer` != "groupId" ) ) { $realLastDeform = $singleLastDeformer; } //et surtout voir si il y a un polySmooth... if ( `nodeType $singleLastDeformer` == "polySmoothFace" ) { $thereIsPolySmooth = 1; $deformerOfpolySmooth = `listConnections -d 0 -s 1 $realLastDeform`; } } if ($debugMode == 1) { print "_____deformers\n"; print $lastDeformer; print "_____last deformers\n"; //print $lastDeformer[$CNsize-2]; print $realLastDeform; print "\n"; print "_____polySmooth?\n"; print $thereIsPolySmooth; print "\n"; print $deformerOfpolySmooth; } //intervertir si il y a un polySmooth if ( $thereIsPolySmooth == 1 ) { $nameOfSmoothNode = $realLastDeform; $realLastDeform = $deformerOfpolySmooth[0]; $listOfSmoothConnections = `listConnections -s 1 -d 0 -c 1 -p 1 -t transform $nameOfSmoothNode`; if ($debugMode == 1) { print "_____il y a un poly, il y aura inversion des noms... le nom est\n"; print $nameOfSmoothNode; print "\n_____son deformer est\n"; print $realLastDeform; print "\n_____ses connections sont \n"; print $listOfSmoothConnections; print "\n_____le polysmooth est efface\n"; } //recuperer le smooth $characSmooth[0] = `getAttr ($nameOfSmoothNode + ".method")`; $characSmooth[1] = `getAttr ($nameOfSmoothNode + ".continuity")`; $characSmooth[3] = `getAttr ($nameOfSmoothNode + ".divisions")`; $characSmooth[4] = `getAttr ($nameOfSmoothNode + ".smoothUVs")`; $characSmooth[5] = `getAttr ($nameOfSmoothNode + ".keepBorder")`; $characSmooth[6] = `getAttr ($nameOfSmoothNode + ".keepSelectionBorder")`; $characSmooth[7] = `getAttr ($nameOfSmoothNode + ".keepHardEdge")`; $characSmooth[8] = `getAttr ($nameOfSmoothNode + ".keepMapBorders")`; $characSmooth[9] = `getAttr ($nameOfSmoothNode + ".keepTessellation")`; $characSmooth[10] = `getAttr ($nameOfSmoothNode + ".subdivisionLevels")`; $characSmooth[11] = `getAttr ($nameOfSmoothNode + ".divisionsPerEdge")`; $characSmooth[12] = `getAttr ($nameOfSmoothNode + ".pushStrength")`; $characSmooth[13] = `getAttr ($nameOfSmoothNode + ".roundness")`; //effacer! delete $nameOfSmoothNode; } //------------------- //create cluster string $clusterName[] = `cluster `; $clusterName[0] = `rename $clusterName[0] ( $nameOfSystem + "_cluster" )`; $clusterHandleName = `rename $clusterName[1] ( $nameOfSystem + "_clusterHandle" )`; string $groupName = `group -em `; $groupName = `rename $groupName ( $nameOfSystem + "_group" )`; if ($debugMode == 1) print ("__________CLUSTER HIERARCHIE " + $clusterName[0] + " _____ " + $groupName + "\n"); //create group AND DO NOT FORGET TO FREEZE!! string $makeAlign[] = `parentConstraint $clusterHandleName $groupName`; delete $makeAlign; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $groupName; //creation follicule methode... if ( $intSystemType == 1 ) { $makeLocator = `spaceLocator -p 0 0 0 `; $makeLocator[0] = `rename $makeLocator[0] ( $nameOfSystem + "_GChandle" )`; $makeAlign = `parentConstraint $clusterHandleName $makeLocator[0]`; delete $makeAlign; select -r $makeLocator; //create follicule system and rename it select -r $buffer[0] $makeLocator[0]; addFolliculeConstraint; $tempName = `pickWalk -d up`; rename $tempName ( $nameOfSystem + "_GCcontraint" ); select -r $makeLocator[0]; $tempName = `pickWalk -d up`; $shapesOfFollicule = `listRelatives -s -ni -path $tempName[0]`; if ($debugMode == 1) print $shapesOfFollicule; //merci Carlo... connectAttr -f ( $realLastDeform + ".outputGeometry[0]" ) ( $shapesOfFollicule[0] + ".inputMesh" ); connectAttr -f ( $groupName + ".worldInverseMatrix[0]" ) ( $clusterName[0] + ".bindPreMatrix" ); //creation du system hierarchique makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $makeLocator; parent $clusterHandleName $groupName; parent $groupName $tempName ; parentConstraint -mo $makeLocator $clusterHandleName; //pour permettre l'offset $offsetGroup = `group $makeLocator`; $offsetGroup = `rename $offsetGroup ( $nameOfSystem + "_offsetGroup" )`; hide $clusterHandleName; select -r $makeLocator[0]; } //creation rivet methode... if ( $intSystemType == 2 ) { $makeLocator = `spaceLocator -p 0 0 0 `; $makeLocator[0] = `rename $makeLocator[0] ( $nameOfSystem + "_GChandle" )`; $makeAlign = `parentConstraint $clusterHandleName $makeLocator[0]`; delete $makeAlign; select -r $makeLocator; select -r $CNgc_edges; $nameOfRivet = `rivet`; $nameOfRivet = `rename $nameOfRivet ( $nameOfSystem + "_GCrivet" )`; //passer les etapes pour recuperer les 2 curvesfrommesh $rivetConnection = `listConnections -d 0 -s 1 $nameOfRivet`; $rivetConnection = `listConnections -d 0 -s 1 $rivetConnection`; $rivetConnection = `listConnections -d 0 -s 1 $rivetConnection`; if ($debugMode == 1) print "____connections du rivet_\n"; if ($debugMode == 1) print $rivetConnection; //merci Carlo... connectAttr -f ( $realLastDeform + ".outputGeometry[0]" ) ( $rivetConnection[0] + ".inputMesh" ); connectAttr -f ( $realLastDeform + ".outputGeometry[0]" ) ( $rivetConnection[1] + ".inputMesh" ); connectAttr -f ( $groupName + ".worldInverseMatrix[0]" ) ( $clusterName[0] + ".bindPreMatrix" ); //creation du system hierarchique //group $makeLocator; parent $clusterHandleName $groupName; parent $groupName $nameOfRivet ; parent $makeLocator $nameOfRivet; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $makeLocator; parentConstraint -mo $makeLocator $clusterHandleName; //pour permettre l'offset $offsetGroup = `group $makeLocator`; $offsetGroup = `rename $offsetGroup ( $nameOfSystem + "_offsetGroup" )`; hide $clusterHandleName; $shapes = `listRelatives -s -ni -path $nameOfRivet`; setAttr ( $shapes[0] + ".visibility" ) 0; select -r $makeLocator[0]; } //rivetvtx system if ( $intSystemType == 3 ) { $makeLocator = `spaceLocator -p 0 0 0 `; $makeLocator[0] = `rename $makeLocator[0] ( $nameOfSystem + "_GChandle" )`; $makeAlign = `parentConstraint $clusterHandleName $makeLocator[0]`; delete $makeAlign; select -r $makeLocator; //create follicule system and rename it select -r $curSel[0] $makeLocator[0]; TIMV_PolygonVertexConstraint; TIMV_PolygonVertexConstraint_FUNC; deleteUI PolygonVertexConstraintWindow; $tempName = `pickWalk -d up`; $nameOfRivet = `rename $tempName ( $nameOfSystem + "_GCrivet" )`; //$nameOfRivet = `rename $tempName ( $nameOfSystem + "_GCcontraint" )`; //passer les etapes pour recuperer les 2 curvesfrommesh $rivetConnection = `listConnections -d 0 -s 1 $nameOfRivet`; $rivetConnection = `listConnections -d 0 -s 1 $rivetConnection`; $rivetConnection = `listConnections -d 0 -s 1 $rivetConnection`; if ($debugMode == 1) print "____connections du rivet_\n"; if ($debugMode == 1) print $rivetConnection; //merci Carlo... connectAttr -f ( $realLastDeform + ".outputGeometry[0]" ) ( $rivetConnection[0] + ".inputMesh" ); connectAttr -f ( $realLastDeform + ".outputGeometry[0]" ) ( $rivetConnection[1] + ".inputMesh" ); connectAttr -f ( $groupName + ".worldInverseMatrix[0]" ) ( $clusterName[0] + ".bindPreMatrix" ); //creation du system hierarchique //makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $makeLocator; parent $clusterHandleName $groupName; parent $groupName $nameOfRivet ; parentConstraint -mo $makeLocator $clusterHandleName; $offsetGroup = `group $makeLocator[0]`; $offsetGroup = `rename $offsetGroup ( $nameOfSystem + "_offsetGroup" )`; //$mainGroup = `group $offsetGroup`; //$mainGroup = `rename $mainGroup ( $nameOfSystem + "_mainGroup" )`; //parent $groupName $mainGroup ; hide $clusterHandleName; select -r $makeLocator[0]; } //si il y avait un polySmooth, en reappliquer un if ( $thereIsPolySmooth == 1 ) { $newPolySmooth2 = `polySmooth -mth $characSmooth[0] -dv $characSmooth[3] -c $characSmooth[1] -kb $characSmooth[5] -ksb $characSmooth[6] -khe $characSmooth[7] -kt $characSmooth[9] -kmb $characSmooth[8] -suv 1 -sl $characSmooth[10] -dpe $characSmooth[11] -ps $characSmooth[12] -ro $characSmooth[13] -ch 1 $buffer[0]`; rename $newPolySmooth2[0] $nameOfSmoothNode; for ($i = 0; $i < `size($listOfSmoothConnections)`; $i+=2) { connectAttr $listOfSmoothConnections[$i+1] $listOfSmoothConnections[$i]; print ("//reconnection : " + $listOfSmoothConnections[$i+1] + " to " + $listOfSmoothConnections[$i] + "\n"); } warning "//GCclusterGlue attempt to replace a new polySmooth... please verify if its good..."; } select -r $makeLocator[0]; } //************************************************************************************************************ //************************************************************************************************************ global proc GCedges_store() { global string $CNgc_edges[]; string $curSel[] = `filterExpand -sm 32 -ex 1`; string $currentName; int $currentChoise; if ( `size($curSel)` != 2 ) CNglueCluster_errorWin "please select 2 EDGES!"; else { $currentName = `textField -q -tx nameField`; $CNgc_edges = $curSel; CNclusterGlue; textField -e -tx $currentName nameField; radioButtonGrp -e -select 2 radioButtonType; button -edit -en 1 buttonEdges; text -edit -en 1 textEdge; } } global proc CNgc_pivot (string $action) { string $curSel[] = `ls -sl`; string $offset[]; string $connections[]; string $nameOfCluster[]; string $nameOfCluster2; if ( `size($curSel)` != 1 ) CNglueCluster_errorWin "please select only 1 glueCluster!"; switch ( $action ) { case "begin": $connections = `listConnections -d 1 -s 0 $curSel[0]`; $nameOfCluster = `listConnections -d 0 -s 1 $connections`; delete $connections[0]; $offset = `pickWalk -d up`; //cree un moyen de se souvenir du cluster addAttr -ln nameOfCluster -dt "string" $offset; setAttr -e -keyable true ($offset[0] + ".nameOfCluster"); setAttr -type "string" ($offset[0] + ".nameOfCluster") $nameOfCluster; manipMoveContext -e -mode 1 Move;manipRotateContext -e -mode 0 Rotate; updateLockSelectionIcon; print "//now you can move the pivot. Do not forget to exit by the UI...\n"; break; case "finish": string $nameOfCluster2 = `getAttr ( $curSel[0]+ ".nameOfCluster" )`; deleteAttr ( $curSel[0]+ ".nameOfCluster" ); updateLockSelectionIcon; $curSel = `pickWalk -d down`; parentConstraint -mo $curSel[0] $nameOfCluster2; print "//You have edited the pivot and exited from this mode. Good day...\n"; break; } } //************************************************************************************************************ //************************************************************************************************************ global proc CNglueCluster_errorWin(string $phrase) { confirmDialog -t "glueCluster error" -m $phrase -b "Ok, ok..." -db "ok..."; error ("//" + $phrase +"\n"); }