//makeColorDirectionalLightsOnMesh ver1.0 //made by Takahiro Nakajima //http://nkj.lib.net/ //You can use this script with your own risk. //Overview: //This makes directional lights on selected object's each vertex. //The lights' colors are made by the vertices' colors. //How to use: //1)Select a mesh object which has vertex colors. //2)Run this script to make lights and a parent object(group) of them. //You can change all light's intensity at the same time with using "Value" attribute of the group object. //---------------------------------------------------------------------- proc objSync(string$referObj,string$subObj,int$type) { //This synchronizes $subObj's position or rotation to $referObj's. //$type sets modes: // 0 = position // 1 = rotation // 2 = position and rotation //------- float $pos[] = `xform -q -ws -t $referObj`; float $rot[] = `xform -q -ws -ro $referObj`; switch($type) { case 0: xform -ws -t $pos[0] $pos[1] $pos[2] $subObj; break; case 1: xform -ws -ro $rot[0] $rot[1] $rot[2] $subObj; break; case 2: xform -ws -t $pos[0] $pos[1] $pos[2] $subObj; xform -ws -ro $rot[0] $rot[1] $rot[2] $subObj; break; } } //---------------------------------------------------------------------- proc string makeColorDirectionalLightsOnMesh(string$mesh) { //This makes directional lights on $mesh's each vertex. //The lights' colors become the same as vertices' colors. //After making lights, lights' intensities are controlled by a group object. //The return value is a group object which is a parent and controller of lights. //------ select -cl; //Get the number of vertices. int $polyNumList[] = `polyEvaluate -v $mesh`; int $polyNum = $polyNumList[0]; //Make an empty group; string $grp = `group -em`; addAttr -ln "value" -at "float" $grp; setAttr -k 1 ($grp + ".value"); setAttr ($grp + ".value") 1.0; objSync $mesh $grp 2; //Make lights. int $count; for($count=0;$count<$polyNum;$count++) { //Get the color values of the vertex. string $vtx = $mesh + ".vtx[" + $count + "]"; float $colorValue[] = `polyColorPerVertex -q -rgb $vtx`; //Convert RGB to HSV. vector $RGB = <<$colorValue[0],$colorValue[1],$colorValue[2]>>; vector $HSV = `rgb_to_hsv $RGB`; float $i = $HSV.z; $HSV = <<$HSV.x, $HSV.y, 1.0>>; $RGB = `hsv_to_rgb $HSV`; float $r = $RGB.x; float $g = $RGB.y; float $b = $RGB.z; //Make a light. string $lightShape = `directionalLight -d 0 -rgb $r $g $b -i 1.0 -rs 0`; string $light[] = `listRelatives -p $lightShape`; objSync $vtx $light[0] 0; //Parent parent $light[0] $grp; //Set a direction. string $constrain[] = `aimConstraint -aim 0 0 -1 $mesh $light[0]`; delete $constrain; //Make an expression. string $word = $light[0] + ".intensity = " + $grp + ".value * " + $i; expression -s $word; //Set attribute. setAttr ($light[0] + ".emitSpecular") 0; } return $grp; } //---------------------------------------------------------------------- { string $object[] = `ls -sl`; string $lightGrp = `makeColorDirectionalLightsOnMesh $object[0]`; select $lightGrp; rename $lightGrp ("fakeGILightGrp_" + $object[0]); } //---------------------------------------------------------------------- //The end of the script.