Tuesday, October 4, 2011

Light Manipulator for internal fluid light

At long last I've finished my MEL script that adds a directional light as a controler for a fluids internal light.

You must first select the fluid and then run the script.

This version creates a directional light and locator that whose translation is locked and whose visibility is off. At some point I might update it to exclude the creation of these two nodes.

Here's the code. I'll provide a link to download the file shortly.


string $fluidSelected[0] = `ls -sl `;
string $lightManipulator = "lightManipulator";
string $fluidAndLightMainipulator = $fluidSelected[0] + "_" + $lightManipulator;  //gets name of fluid and add "lightManipulater"
loadPlugin "C:/Program Files/Autodesk/Maya2012/bin/plug-ins/decomposeMatrix";
createNode decomposeMatrix -n decomposeM;
pickWalk -d down; //selects shape node of fluid conatiner
vector $fluidShapeLightVector = `getAttr ($fluidSelected[0] +".directionalLight")`; //retrieves vector value of fluids internal light
directionalLight -n $fluidAndLightMainipulator;// creates light that will be the manipulator
string $fluidAndLightMainipulatorProxy = $fluidAndLightMainipulator + "Proxy";
directionalLight -n $fluidAndLightMainipulatorProxy; // creates light that will be moved by manipulator
connectAttr -f ($fluidAndLightMainipulator + ".rotate") ($fluidAndLightMainipulatorProxy + ".rotate");
setAttr -lock true ($fluidAndLightMainipulatorProxy + ".t");
setAttr ($fluidAndLightMainipulatorProxy + "Shape" + ".overrideEnabled") 1;
setAttr ($fluidAndLightMainipulatorProxy + "Shape" + ".overrideVisibility") 0;
spaceLocator -n lightLocation;
setAttr lightLocation.translate ($fluidShapeLightVector.x) ($fluidShapeLightVector.y) ($fluidShapeLightVector.z);
connectAttr -f lightLocationShape.worldMatrix[0] decomposeM.inputMatrix;
setAttr lightLocationShape.overrideEnabled 1;
setAttr lightLocationShape.overrideVisibility 0;
string $fluidSelectedShapeArry[0] = `listRelatives -s $fluidSelected`;
string $fluidSelectedShape = $fluidSelectedShapeArry[0];
print $fluidSelectedShape;
connectAttr -f decomposeM.outputTranslate ($fluidSelectedShape + ".directionalLight");

vector $indtialLocatorTranslate = `getAttr lightLocation.translate`;
float $initialRotation[] = `angleBetween -euler -v1 0 0 1 -v2 ($indtialLocatorTranslate.x) ($indtialLocatorTranslate.y) ($indtialLocatorTranslate.z)`;
setAttr ($fluidAndLightMainipulator + ".rotate") $initialRotation[0] $initialRotation[1] $initialRotation[2];
select -r lightLocation;
select -add ($fluidAndLightMainipulatorProxy);
parent;
select -r fluid1_lightManipulator ;
select -add ($fluidSelected[0]) ;
parent;

No comments:

Post a Comment