Please note that there are lots of better scripts out there to do similar task. However, I made such scripts as one aspect of learning Maya. So, any comments to improve my scripting skill are welcome.
Let's start...
This simple MEL (Maya Embedded Language) script is to create required node networks for selected single node camera so it has mental ray physical_lens_dof shader attached.
Here's the script:
string $tempCam[] = `ls -sl -dag`;
string $camShape = $tempCam[1];
string $selectedCam = $tempCam[0];
First line is to query selected camera into an array string. Users must select one camera first. When I made this script I use single node camera, so I haven't try it on two or three nodes camera.
Second line is to select the camera shape node from the array string 1.
Third line is to select the camera transform node from array string 0.addAttr -min 0 -dv 0.2 -ln Blur -at double -k true $selectedCam;
After the camera selected, we add attribute named "Blur" in the camera transform node.createNode distanceBetween -n distanceLength;Simply just create distanceBetween node name "distanceLength". You could name this differently but you have to remember this name. Or you may not name this at all and use default name assigned by maya.createNode multiplyDivide -n reverseVal;
Simply create mutliplyDivide node name "reverseVal". Again u could just use maya default name.mrCreateCustomNode -asUtility "" physical_lens_dof;
Create mental ray physical_lens_dof node.string $tempDofNode[] = `ls -sl`;
string $lensDof = $tempDofNode[0];
First line here, to create container for selected node, which is the pyisical_lens_dof node. Because it's in array string, we need to convert it to array by declareing it into a new string array $lensDof.connectAttr -f ($lensDof + ".message") ($camShape + ".miLensShader");
Attach physical_lens_dof into selected camera shape lens shader.setAttr "reverseVal.input2X" -1;
Set the value of the reverseVal input2 x into negative one (-1)spaceLocator -n camPoint;
spaceLocator -n focusPoint;
Now lets create two locators to control the distance of the camera and the focus point. First line here to create first locator name "camPoint", where this locator will be contrained to camera. Second line here to create second locator name "focusPoint" which will be the focus point of the camera.connectAttr -f ($selectedCam + ".Blur") ($lensDof + ".radius");
Create connections between the added attribute "Blur" of the camera transform node to physical_lens_dof radius attribute. In other words, the camera blur attribute is the driver control of the radius lens shader.connectAttr -f camPoint.translate distanceLength.point1;
Create connections from first locator name camPoint translate attribute into distanceBetween node name distanceLength point1 attribute.connectAttr -f focusPoint.translate distanceLength.point2;
Create connections from first locator name focusPoint translate attribute into distanceBetween node name distanceLength point2 attribute.
connectAttr -f distanceLength.distance reverseVal.input1X;
Connect distanceLength distance value into reverseVal input1 X. In mental ray physical_lens_dof, it only work in negative value for the plane attribute.connectAttr -f reverseVal.outputX ($lensDof + ".plane");Connect reverseVal outputX into physical_lens_dof plane attribute. As explain earlier, this plane attribute required negative value. I have no idea why.pointConstraint -offset 0 0 0 -weight 1 $selectedCam camPoint;
aimConstraint -o 0 0 0 -aim 0 0 -1 -w 1 focusPoint $selectedCam; Finally, point constrained camPoint to seelcted camera, so camPoint locator will move where ever the camera moves. I dunno if parent works, cuz with point constrain, the translate value of camera will go down into the camPoint translate value.
Lastly, aim constrain selected camera to focusPoint locator. So that where ever the camera moves, it will always aim (look at) the focusPoint locator.So... there it goes. I know there could be better ways about how the camera setup with the locator, or how the attribute control each nodes. But for simple camera with simple dof setting, I hope this script will do the thing, u know. By the way, if you copy paste the script, dont forget to strip out all the blue texts. And dont forget.. use mental ray for the renderer ;P
Enjoy.
Let's start...
This simple MEL (Maya Embedded Language) script is to create required node networks for selected single node camera so it has mental ray physical_lens_dof shader attached.
Here's the script:
string $tempCam[] = `ls -sl -dag`;
string $camShape = $tempCam[1];
string $selectedCam = $tempCam[0];
First line is to query selected camera into an array string. Users must select one camera first. When I made this script I use single node camera, so I haven't try it on two or three nodes camera.
Second line is to select the camera shape node from the array string 1.
Third line is to select the camera transform node from array string 0.addAttr -min 0 -dv 0.2 -ln Blur -at double -k true $selectedCam;
After the camera selected, we add attribute named "Blur" in the camera transform node.createNode distanceBetween -n distanceLength;Simply just create distanceBetween node name "distanceLength". You could name this differently but you have to remember this name. Or you may not name this at all and use default name assigned by maya.createNode multiplyDivide -n reverseVal;
Simply create mutliplyDivide node name "reverseVal". Again u could just use maya default name.mrCreateCustomNode -asUtility "" physical_lens_dof;
Create mental ray physical_lens_dof node.string $tempDofNode[] = `ls -sl`;
string $lensDof = $tempDofNode[0];
First line here, to create container for selected node, which is the pyisical_lens_dof node. Because it's in array string, we need to convert it to array by declareing it into a new string array $lensDof.connectAttr -f ($lensDof + ".message") ($camShape + ".miLensShader");
Attach physical_lens_dof into selected camera shape lens shader.setAttr "reverseVal.input2X" -1;
Set the value of the reverseVal input2 x into negative one (-1)spaceLocator -n camPoint;
spaceLocator -n focusPoint;
Now lets create two locators to control the distance of the camera and the focus point. First line here to create first locator name "camPoint", where this locator will be contrained to camera. Second line here to create second locator name "focusPoint" which will be the focus point of the camera.connectAttr -f ($selectedCam + ".Blur") ($lensDof + ".radius");
Create connections between the added attribute "Blur" of the camera transform node to physical_lens_dof radius attribute. In other words, the camera blur attribute is the driver control of the radius lens shader.connectAttr -f camPoint.translate distanceLength.point1;
Create connections from first locator name camPoint translate attribute into distanceBetween node name distanceLength point1 attribute.connectAttr -f focusPoint.translate distanceLength.point2;
Create connections from first locator name focusPoint translate attribute into distanceBetween node name distanceLength point2 attribute.
connectAttr -f distanceLength.distance reverseVal.input1X;
Connect distanceLength distance value into reverseVal input1 X. In mental ray physical_lens_dof, it only work in negative value for the plane attribute.connectAttr -f reverseVal.outputX ($lensDof + ".plane");Connect reverseVal outputX into physical_lens_dof plane attribute. As explain earlier, this plane attribute required negative value. I have no idea why.pointConstraint -offset 0 0 0 -weight 1 $selectedCam camPoint;
aimConstraint -o 0 0 0 -aim 0 0 -1 -w 1 focusPoint $selectedCam; Finally, point constrained camPoint to seelcted camera, so camPoint locator will move where ever the camera moves. I dunno if parent works, cuz with point constrain, the translate value of camera will go down into the camPoint translate value.
Lastly, aim constrain selected camera to focusPoint locator. So that where ever the camera moves, it will always aim (look at) the focusPoint locator.So... there it goes. I know there could be better ways about how the camera setup with the locator, or how the attribute control each nodes. But for simple camera with simple dof setting, I hope this script will do the thing, u know. By the way, if you copy paste the script, dont forget to strip out all the blue texts. And dont forget.. use mental ray for the renderer ;P
Enjoy.
Komentar
Posting Komentar
Monggo komennya