-
Notifications
You must be signed in to change notification settings - Fork 1
/
daPanAndScan1.1.mel
269 lines (172 loc) · 7.08 KB
/
daPanAndScan1.1.mel
1
//copyright 2007 Daniel Arzabe////For suggestions: [email protected]////This tool will allow the user to interactively track and zoom the current camera's image plane//by clicking and dragging in the workspace.////It can be used to model accurately from photographic references using a camera that matches the //focal length and film back settings of the camera used to capture the image. ////Tracking and zooming the image plane will retain the registration of the model to the image plane.////To load the script:// -Source the script daPanAndScanTool.mel// -Save the following script to shelf with appropriate name: daPanAndScanToolOptions()// This command runs the tool options. // -Save the following script to shelf with appropriate name: daSetPanAndScanTool()// This command sets the daPanAndScan tool.//////To use the tool:// -execute: daPanAndScanToolOptions()// This command allows you to set the sensitivity values. The sensitivity of the tool is dependent on// the size and resolution of your image. Experiment and reset the image plane if necessary.//// -execute: daSetPanAndScanTool()// This command enters the tool with the current settings. // LMB Click drag to pan and scan. // LMB, PRESS CTRL and click drag tozoom. // Drag right = zoom in// Drag left = zoom out// MMB Click to reset imagePlane////enjoy!!!//global vaiablesglobal float $contextHorzPress;global float $contextVertPress;global float $contextDepth;global float $panSensitivity = .0001;global float $zoomSensitivity = .007;global string $whichCamShape[];global string $panFloatField;global string $zoomFloatField;global proc daResetCameraImagePlane(){ string $pane = `getPanel -wf`; //figure out the camera in the current view in order to use its values in the window string $whichCam = `modelPanel -q -camera $pane`; $whichCamShape = `ls -dag -shapes -ap $whichCam`; setAttr ($whichCamShape[0] + ".verticalFilmOffset") 0; setAttr ($whichCamShape[0] + ".horizontalFilmOffset") 0; setAttr ($whichCamShape[0] + ".overscan") 1.3; camera -e -displayFilmGate off -displayResolution on -overscan 1.3 $whichCam;}proc float[] daGetCameraImagePlaneValues(){ string $pane = `getPanel -wf`; float $cameraValues[]; //figure out the camera in the current view in order to use its values in the window string $whichCam = `modelPanel -q -camera $pane`; $whichCamShape = `ls -dag -shapes -ap $whichCam`; $cameraValues[0] = `getAttr ($whichCamShape[0] + ".horizontalFilmOffset")`; $cameraValues[1] = `getAttr ($whichCamShape[0] + ".overscan")`; return $cameraValues ;}// Proc called on pressglobal proc daPanAndScanContextPress(){ global float $contextVertPress; global float $contextHorzPress; global string $whichCamShape[]; float $pressPosition[] = `draggerContext -query -anchorPoint daPanAndScanContext`; $contextHorzPress = $pressPosition[0]; $contextVertPress = $pressPosition[1]; string $pane = `getPanel -wf`; //figure out the camera in the current view in order to use its values in the window string $whichCam = `modelPanel -q -camera $pane`; $whichCamShape = `ls -dag -shapes -ap $whichCam`; //print($whichCamShape[0] + " \n"); }global proc daPanAndScanContextRelease(float $panSensitivity, float $zoomSensitivity ){ global float $contextHorzPress; global float $contextVertPress; global string $whichCamShape[]; string $modifier = `draggerContext -query -modifier daPanAndScanContext`; string $buttonPressed = `draggerContext -query -button daPanAndScanContext`; if($buttonPressed == 2) { daResetCameraImagePlane(); } else { float $offsetX; float $offsetY; float $offsetDepth; float $dragPosition[] = `draggerContext -query -dragPoint daPanAndScanContext`; $offsetX = ($contextHorzPress - $dragPosition[0]) * $panSensitivity; $offsetY = ($contextVertPress - $dragPosition[1]) * $panSensitivity; $offsetDepth = ($contextHorzPress - $dragPosition[0]) * $zoomSensitivity; //print("Zoom: " + $zoomSensitivity + " Pan: " + $panSensitivity + "\n"); float $tempHorz = `getAttr ($whichCamShape[0] + ".horizontalFilmOffset")`; float $tempVert = `getAttr ($whichCamShape[0] + ".verticalFilmOffset")`; float $tempDepth = `getAttr ($whichCamShape[0] + ".overscan")`; if($modifier != "ctrl") { setAttr ($whichCamShape[0] + ".horizontalFilmOffset") ($tempHorz + $offsetX); setAttr ($whichCamShape[0] + ".verticalFilmOffset") ($tempVert + $offsetY); } else { if(($tempDepth + $offsetDepth) <= .01) { warning "Drag value exceeds the camera's overscan minimum value. Try dragging shorter distance."; } else { setAttr ($whichCamShape[0] + ".overscan") (($tempDepth + $offsetDepth)); } } }}// Create the dragger contextdraggerContext -pressCommand "daPanAndScanContextPress" -releaseCommand "daPanAndScanContextRelease($panSensitivity, $zoomSensitivity)" -cursor "track" daPanAndScanContext;global proc daGetPanSensitivity(string $panFloatField){ global float $panSensitivity; global string $panFloatField; $panSensitivity = `floatField -q -v $panFloatField`; //print ("Pan Sensitivity: " + $panSensitivity + "\n");}global proc daGetZoomSensitivity(string $zoomFloatField){ global float $zoomSensitivity; global string $zoomFloatField; $zoomSensitivity = `floatField -q -v $zoomFloatField`; //print ("Zoom Sensitivity: " + $zoomSensitivity + "\n");}global proc daSetPanAndScanTool(){ setToolTo daPanAndScanContext;}global proc daPanAndScanToolOptions(){ global string $panFloatField; global string $zoomFloatField; global float $panSensitivity; global float $zoomSensitivity; window -title "daPanAndScanTool Settings" -wh 200 100 -rtf true -mnb false -mxb false; rowColumnLayout -numberOfRows 3 -rowHeight 1 50 -rowHeight 2 25 -rowHeight 3 25 -w 200; rowColumnLayout -numberOfColumns 2 -columnWidth 1 140 -columnWidth 2 60; text -label "Pan Sensitivity " -align "right" -ann "LMB click and drag in the workspace"; $panFloatField = `floatField -precision 5 -step .00001 -min .00001 -max .01 -value $panSensitivity -annotation "Larger values are more sensitive. Use values between .00001 and .001 for best results"`; text -label "Zoom Sensitivity " -align "right" -ann "CTRL and LMB click and drag in the workspace. Drag right = zoom in"; $zoomFloatField = `floatField -precision 5 -step .00001 -min .0001 -max .01 -value $zoomSensitivity -annotation "Larger values are more sensitive. Use values between .001 and .009 for best results"`; setParent..; button -label "Reset Image Plane" -annotation "MMB click to reset imagePlane" -command daResetCameraImagePlane; button -label "Pan And Scan" -annotation "Active camera must have an imagePlane" -command daSetPanAndScanTool; floatField -e -changeCommand ( "daGetPanSensitivity($panFloatField)" ) $panFloatField; floatField -e -changeCommand ( "daGetZoomSensitivity($zoomFloatField)" ) $zoomFloatField; showWindow;}