Monday, March 15, 2010

Mel : Matchmover's Handy Tool

with camera offset x y and overscan attribute you can pan left right and zoom on to the imageplane without affecting camera transform node. this is really handy specially for matchmoving when you are trying to lineup camera to the track geometry or fixing camera and you want to zoom into the imageplane really close without affecting camera.


global proc drag_Xpan(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
dragAttrContext dxpan;
dragAttrContext -edit -ct ($camShapeName[0] +".horizontalFilmOffset") dxpan;
setToolTo dxpan;
}


global proc drag_Ypan(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
dragAttrContext dypan;
dragAttrContext -edit -ct ($camShapeName[0] +".verticalFilmOffset") dypan;
setToolTo dypan;
}


global proc drag_Zoom(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
dragAttrContext dzoom;
dragAttrContext -edit -ct ($camShapeName[0] +".overscan") dzoom;
setToolTo dzoom;
}


global proc resetCam(){
string $camName[] = `ls -sl`;
string $camShapeName[] = `listRelatives -s $camName[0]`;
setAttr ($camShapeName[0] +".horizontalFilmOffset") 0;
setAttr ($camShapeName[0] +".verticalFilmOffset") 0;
setAttr ($camShapeName[0] +".overscan") 1;
}

To test these procedures i am going to add these to the my custom maya shelf. if you want you can make hotkey for these to make it even quicker. its your choice. i personally use hotkeys for these. dig in thru my earlier post to see how to make hotkey thru mel.

but just for testing purpose i am adding them to shelf.


scriptToShelf "X" "drag_Xpan;" "1";
scriptToShelf "Y" "drag_Ypan;" "1";
scriptToShelf "Y" "drag_Zoom;" "1";
scriptToShelf "reset" "resetCam;" "1";


Select a camera and look thru that camera in current model panel. load any image in the imageplane so that we can test these procedures better to see whats happening. test them one at a time using middle mouse drag screen left-right. hold control key while dragging middle mouse will make the drag slower and once you done you can reset them to default value.

hope this is helpful. please make any suggestion if you have any.

Mel: Measure Distance

Maya has this Measure tool which pretty much does the job but i always felt lazy to go thru Create Menu / Measure tool and click on vertices one after other with snap on. too many things to do to get simple distance between two points. i made this script handy for myself for quick checks specially when i have survey information and measurement from set. you can simply make this global procedure in your user/maya/script path and assign hotkey to even make it quicker. it saves time when you want to query lots of measurements and cross check track data scale from tracking software in 3D. pretty sure this can be handy even for modelers, animator and fx guys. script currently works for transform, mesh, nurbsCurve type of nodes. you can modify it further to include different nodes based on your needs.

script is self explanatory. also if you have any suggestion to make this script better please share.

global proc getdistance(){

string $currentsel[] = `ls -sl -fl`;
if ($currentsel[0] == "") error "You must select two nodes or vertex to measure the distance";
else {

int $numofvertex = size($currentsel);

if($numofvertex > 2) error "More than 2 nodes selected. Make selection again with only two nodes to measure distance between them";
else {
if(`objectType -isType "mesh" $currentsel[0]` || `objectType -isType "nurbsCurve" $currentsel[0]`)
{

vector $va = `pointPosition $currentsel[0]`;
vector $vb = `pointPosition $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);

}
else if (`objectType -isType "transform" $currentsel[0]`)
{

vector $va = `xform -q -ws -a -rp $currentsel[0]`;
vector $vb = `xform -q -ws -a -rp $currentsel[1]`;
vector $distpos = $va - $vb;
float $d = `mag <<$distpos.x, $distpos.y, $distpos.z>>`;
string $unit= `currentUnit -query -linear`;
print ($d + "\t" + $unit);

}

}
}



}

Reposition

supernova is on a distinguished road
Default Reposition using For loop

Reposition

Let say If you want to reposition one object to the other, you can use for loop variation. the script runs through for loop for every string that are declared in first line. try this out. make couple of polyCube and place them at different 3D location. select source object first and then target object (that you want to repostion to the first cube) and execute this in script editor.

string $attributeList[] = {"tx", "ty", "tz", "rx", "ry", "rz", "sx", "sy", "sz"};
string $sel[] = `ls -sl`;
string $attribute;
for($attribute in $attributeList) {
setAttr ($sel[1] + "." + $attribute) `getAttr ($sel[0] + "." + $attribute)`;



line 1 : storing all shortnames for tranform attribute in string array (eg: tx = tranformX)
line 2 : declaring string array for storing selected object names
line 3: declaring string that will run through for loop in next line. this line is not needed as maya automatically declares $attr as string type when you use for loop as in line 4
line 4: for loop . to process each string in the array list in line 1 you can use a variation of the for loop that is specialized for use with arrays like this
line 5: setting second selected object transform attribute from first selected object.

If you want any particular channel (like only translate Z and rotate Y ) and not all of them then you use channelBox query like this. make sure you selected the channel in main channel box and run these lines.

string $attributeList[] = `channelBox -q -sma "mainChannelBox"`;
string $sel[] = `ls -sl`;
string $attribute;
for($attribute in $attributeList) {
setAttr ($sel[1] + "." + $attribute) `getAttr ($sel[0] + "." + $attribute)`;
}

Integration/Tracking Demo Reel 2018 on Youtube