//PointOnSurfaceAndCurve.mel // // Date: 2006/01/20 // Author: Dai Sato dstruevision@dstruevision.com http://www.dstruevision.com // Procedure Name: PointOnSurfaceAndCurve // // Description: This scripts enable you to constrain an object to nurbs surface or curve. global proc POSAC_jobStarter(string $window){ $jobNum = `scriptJob -parent $window -e "SelectionChanged" "POSAC_showSelection()"`; } global proc POSAC_showSelection() { string $selectedTab = `tabLayout -q -selectTab POSAC_Tab`; if($selectedTab == "Surface") { string $selection[] = `ls -sl`; if(!($selection[0]=="")) { text -e -label $selection[0] POSAC_targetSurface; if($selection[1]!="") { text -e -label $selection[1] POSAC_SurfaceConstrainedObject; } else { text -e -label "No object is selected" POSAC_SurfaceConstrainedObject; } } else { text -e -label "No object is selected" POSAC_targetSurface; } } else { string $selection[] = `ls -sl`; if(!($selection[0]=="")) { text -e -label $selection[0] POSAC_targetCurve; if($selection[1]!="") { text -e -label $selection[1] POSAC_CurveConstrainedObject; } else { text -e -label "No object is selected" POSAC_CurveConstrainedObject; } } else { text -e -label "No object is selected" POSAC_targetCurve; } } } global proc POSAC_surface_constrain() { string $selection[] = `ls -sl`; if(!($selection[0]=="")) { string $tempNode = $selection[0]; string $tempHis[] = `listHistory $selection[0]`; string $node = `nodeType $tempHis[0]`; if($node == "nurbsSurface") { if($selection[1]!="") { string $temp_PosNode = `createNode pointOnSurfaceInfo`; connectAttr -f ($tempHis[0] +".worldSpace[0]") ($temp_PosNode +".inputSurface"); connectAttr -f ($temp_PosNode+".position") ($selection[1]+".translate"); select -cl; select $temp_PosNode; text -e -label "No object is selected" POSAC_targetSurface; text -e -label "No object is selected" POSAC_SurfaceConstrainedObject; } else { text -e -label "No object is selected" POSAC_SurfaceConstrainedObject; } } else { text -e -label "Select NurbsSurface!!" POSAC_targetSurface; } } } global proc POSAC_curve_constrain() { string $selection[] = `ls -sl`; if(!($selection[0]=="")) { string $tempNode = $selection[0]; string $tempHis[] = `listHistory $selection[0]`; string $node = `nodeType $tempHis[0]`; if($node == "nurbsCurve") { if($selection[1]!="") { string $temp_PosNode = `createNode pointOnCurveInfo`; connectAttr -f ($tempHis[0] +".worldSpace[0]") ($temp_PosNode +".inputCurve"); connectAttr -f ($temp_PosNode+".position") ($selection[1]+".translate"); setAttr ($temp_PosNode+".turnOnPercentage") 1; select -cl; select $temp_PosNode; text -e -label "No object is selected" POSAC_targetCurve; text -e -label "No object is selected" POSAC_CurveeConstrainedObject; } else { text -e -label "No object is selected" POSAC_CurveConstrainedObject; } } else { text -e -label "Select NurbsCurve!!" POSAC_targetCurve; } } } global proc POSAC_sliderChange(int $flag) { string $selection[] = `ls -sl`; if($selection[0]!="") { $nodeType = `nodeType $selection[0]`; if($nodeType == "pointOnSurfaceInfo") { switch ($flag) { case 1: float $sliderValue = `floatSlider -q -v surfaceU_Slider`; floatField -edit -v $sliderValue surfaceU_Field; setAttr ($selection[0]+".parameterU") $sliderValue; break; case 2: float $sliderValue = `floatSlider -q -v surfaceV_Slider`; floatField -edit -v $sliderValue surfaceV_Field; setAttr ($selection[0]+".parameterV") $sliderValue; break; default: break; } } if($nodeType == "pointOnCurveInfo") { switch ($flag) { case 3: print "YES"; float $sliderValue = `floatSlider -q -v curveU_Slider`; floatField -edit -v $sliderValue curveU_Field; setAttr ($selection[0]+".parameter") $sliderValue; break; default: break; } } } } global proc POSAC_fieldChange(int $flag) { string $selection[] = `ls -sl`; if($selection[0]!="") { $nodeType = `nodeType $selection[0]`; if($nodeType == "pointOnSurfaceInfo") { switch ($flag) { case 1: float $fieldValue = `floatField -q -v surfaceU_Field`; floatSlider -edit -v $fieldValue surfaceU_Slider; setAttr ($selection[0]+".parameterU") $fieldValue; break; case 2: float $fieldValue = `floatField -q -v surfaceV_Field`; floatSlider -edit -v $fieldValue surfaceV_Slider; setAttr ($selection[0]+".parameterV") $fieldValue; break; default: break; } } if($nodeType == "pointOnCurveInfo") { switch ($flag) { case 3: print "YES"; float $fieldValue = `floatField -q -v curveU_Field`; floatSlider -edit -v $fieldValue curveU_Slider; setAttr ($selection[0]+".parameter") $fieldValue; break; default: break; } } } } global proc PointOnSurfaceAndCurve (){ if ((`window -ex POSAC_Window`) == true) deleteUI POSAC_Window; string $window = `window -t "PointOnSurfaceAndCurve" -s false -mnb true -mxb true -mb true POSAC_Window`; tabLayout POSAC_Tab; columnLayout -rs 2 Surface; text -label "TARGET SURFACE"; text -label "No object is selected" POSAC_targetSurface; text -label "OBJECT TO BE CONSTRAINED:"; text -label "No object is selected" POSAC_SurfaceConstrainedObject; text -label ""; text -label "U Parameter"; rowColumnLayout -numberOfRows 1; floatField -en true -w 45 -min 0.000 -max 1.000 -value 0.000 -precision 3 -cc "POSAC_fieldChange(1)" surfaceU_Field; floatSlider -en true -w 120 -min 0.000 -max 1.000 -value 0.000 -step 0.1 -dc "POSAC_sliderChange(1)" surfaceU_Slider; setParent Surface; text -label "V Parameter"; rowColumnLayout -numberOfRows 1; floatField -en true -w 45 -min 0.000 -max 1.000 -value 0.000 -precision 3 -cc "POSAC_fieldChange(2)" surfaceV_Field; floatSlider -en true -w 120 -min 0.000 -max 1.000 -value 0.000 -step 0.1 -dc "POSAC_sliderChange(2)" surfaceV_Slider; setParent Surface; columnLayout -rs 8; button -l "Constrain" -w 80 -h 30 -c "POSAC_surface_constrain()"; setParent POSAC_Tab; columnLayout -rs 2 Curve; text -label "TARGET CURVE:"; text -label "No object is selected" POSAC_targetCurve; text -label "OBJECT TO BE CONSTRAINED:"; text -label "No object is selected" POSAC_CurveConstrainedObject; text -label ""; text -label "Parameter"; rowColumnLayout -numberOfRows 1; floatField -en true -w 45 -min 0.000 -max 1.000 -value 0.000 -precision 3 -cc "POSAC_fieldChange(3)" curveU_Field; floatSlider -en true -w 120 -min 0.000 -max 1.000 -value 0.000 -step 0.1 -dc "POSAC_sliderChange(3)" curveU_Slider; setParent Curve; columnLayout -rs 8; button -l "Constrain" -w 80 -h 30 -c "POSAC_curve_constrain()"; setParent POSAC_Tab; window -e -width 200 -height 300 POSAC_Window; showWindow POSAC_Window; POSAC_jobStarter($window); }