/* author: Vladislav Bakic website: http://www.vladislavbakic.com email: vladislav.bakic@gmail.com license: Apache 2.0 License */ //String array index utility, to be able to return only one element from a command global proc string _si(string $array[], int $index){ string $return = ""; $index = ($index%size($array)); if($index < 0){ $index = size($array) + $index; if($index < 0) $index = 0; } if($index < size($array) && $index >= 0) $return = $array[$index]; return $return; } // Get the transfomr node from the shape proc string getTransform( string $shape ) { if ( "transform" != `nodeType $shape` ){ string $parents[] = `listRelatives -fullPath -parent $shape`; $shape = $parents[0]; } return $shape; } //Get current viewport camera, else assign the persp1 camera global proc string getCurrentCamera(){ string $camera; string $panel = `getPanel -wf`; if ( "modelPanel" == `getPanel -to $panel` ) $camera = `modelEditor -q -camera $panel`; if($camera == "") return "persp"; if(`nodeType $camera` == "camera") $camera = getTransform( $camera ); return $camera; } //Create the locator, closest point on mesh or surface, aim constraint, geo constraint and the expression global proc hiliteMove() { //get the selection string $sel[2] = stringArrayRemoveDuplicates(stringArrayCatenate(`ls -sl`, `ls -sl -dag -lf`)); string $light, $mesh, $type, $geo, $class = ""; string $cpm; //load nearestPointOnMesh if (!`pluginInfo -q -l "nearestPointOnMesh"`){ loadPlugin "nearestPointOnMesh"; } //find the light and the geo for ($i=0;$i>;\nfloat $camera[3];\n$camera[0] = "+$cam+".translateX;\n$camera[1] = "+$cam+".translateY;\n$camera[2] = "+$cam+".translateZ;\n\nvector $in = <<$camera[0]-$hilite[0],$camera[1]-$hilite[1],$camera[2]-$hilite[2]>>;\nfloat $ii = $in;\n$in = <<($in.x)/$ii*$distance,($in.y)/$ii*$distance,($in.z)/$ii*$distance>>;\nfloat $normalSurface[3];\n"+$normStr+"\n\nvector $normal = <<$normalSurface[0], $normalSurface[1], $normalSurface[2]>>;\n\nvector $result = $in - 2 * (($in.x*$normal.x + $in.y*$normal.y + $in.z*$normal.z)) * $normal;\n\n$result = <<((-$result.x)+$hilite[0]), ((-$result.y)+$hilite[1]), ((-$result.z)+$hilite[2])>>;\nfloat $intesity = $result;\n if($selection[0]==\""+$loc+"\" || $active){\n\t"+$light+".translateX = ($result.x);\n\t"+$light+".translateY = ($result.y);\n\t"+$light+".translateZ = ($result.z);}") -o "" -ae 1 -uc all`; //script job to remove the closest point on surface and the expression if we delete the locator int $job = `scriptJob -ro true -attributeDeleted ($loc+".tx") ("delete "+$exp+" "+$cpm)`; select -r $loc; DisplayShaded; DisplayLight; } //trow an error else { error("You must select a geometry and a light!"); } } //invoke the script hiliteMove()