PDA

View Full Version : creating sliders for camera attributes


deadalvs
04-14-2008, 02:42 AM
hi !

i wanted to ask this:

(i'm currently taking a matchmoving class, so i have often to zoom into the image plane for better seeing details)

i'd like to try to make a script that lists all renderable and non-orthogonal cameras and then create a window with sliders for the following attributes:

horizontal film offset
vertical film offset
overscan

a tab for each camera should be created in a simple window. each tab should be named as the camera.

i have never worked with sliders before, so maybe someone could give me a few hints or important tips.

(also, i'd like to implement a reset button for the values and an update button to recalc the whole window if cameras have been created or deleted ... )

DOor
04-14-2008, 03:57 PM
there is an attribute slider you can use that will can be attached to a specific attribute of a node. I currently cant look at the exact command or flags for this but it is in the mel command reference. these will be your best bet because they will automatically adjust the attributes and update as they are changed manually in the attrEditor.

I recommend starting there.

deadalvs
04-15-2008, 08:15 AM
hey man, thanks !

yep, i found the command and that's just what i need. perfect.

but what bothers me more atm is the problem how to put put a new tab (or delete) in the actual window. i mean for every cam i'd like to have this small triangle to hide/show each camera's attributes. so that'd need a layout for each cam. well.

you got any idea how to create these ?

DOor
04-15-2008, 03:04 PM
The tab system is a fairly complex layout. Each tab requires a child layout (row, column, form, etc) and you would have to keep track of all the layouts you created.

Off the top of my head you may be able to do a workaround.
When you "update" the UI you can make a procedure to:

1) delete the tabLayout given the name $tabLayoutName. (I think this will delete the child layouts as well)
2) create a new blank tabLayout with the same name using $tabLayoutName.
3) gather a list of cameras in the scene.
4) for each camera create a new layout that will display all its info
5) attach each layout to the tabLayout and name the tab the same as the camera.


deleteUI -control $tabLayoutName;
tabLayout $tabLayoutName;

string $cameraList[] = `ls -cameras`;

for ($cam in $cameraList) { string $tabChild = `columnLayout`;
tabLayout -e -tabLabel $tabChild $cam $tabLayoutName;
}



In the example above you would obviously want a more complex layout than columnLayout for each camera. Unfortunately I do not have access to maya right now to do any testing.

I am sure there are other methods we can attempt to achieve the same results but this is the first thing I could think of.


Alternatively you could avoid using the tab layouts and use either a menu or optionMenu to select a camera and update the display of the layouts instead. this would probably be easier but I know how seductive those tabs can be!

deadalvs
04-17-2008, 08:00 AM
lemme try ...

deadalvs
04-17-2008, 09:16 AM
there ya go:

version 1 ... :beer:




d_updateInspectorGUI;
global proc d_updateInspectorGUI(){
// deleteUI "d_IPIWin";
if (`window -exists "d_IPIWin"` == 1){deleteUI "d_IPIWin";}

window -t "ImagePlaneInspector_V1" d_IPIWin;
columnLayout -adjustableColumn 1 mainLayout;
frameLayout -l "Info" -cll true -collapse 1 infoLayout;
columnLayout -adjustableColumn 1;
text -l "scripted by deadalvs";
text -l "april '08";
setParent..;
setParent..;
string $cameraArray[] = `ls -cameras`;
for ($eachCamera in $cameraArray){
frameLayout -l ($eachCamera + " controls") -cll true -collapse 1 ($eachCamera + " controlLayout");
columnLayout;
attrFieldSliderGrp -min 0 -max 2 -at ($eachCamera+".overscan");
attrFieldSliderGrp -min -0.5 -max 0.5 -at ($eachCamera+".horizontalFilmOffset");
attrFieldSliderGrp -min -0.5 -max 0.5 -at ($eachCamera+".verticalFilmOffset");
setParent..;
setParent..;
//end for ($eachCamera in $cameraArray){
}
columnLayout -adjustableColumn 1;
button -h 40 -l "reset overscans and film offsets" -command "d_resetCameraAttributes();";
button -h 20 -l "update Inspector GUI" -command "d_updateInspectorGUI();";
showWindow d_IPIWin;
//end d_updateInspectorGUI
}

///////////////////////////////////////////////////////////////

global proc d_resetCameraAttributes(){
string $cameraArray[] = `ls -cameras`;
for ($eachCamera in $cameraArray){
setAttr ($eachCamera + ".overscan") 1;
setAttr ($eachCamera + ".horizontalFilmOffset") 0;
setAttr ($eachCamera + ".verticalFilmOffset") 0;
}
//end d_resetCameraAttributes
}

deadalvs
04-17-2008, 10:06 AM
V. 1.1
new with look-thru functionality (button for each camera)
((works on every model panel))


d_updateInspectorGUI;
global proc d_updateInspectorGUI(){
// deleteUI "d_IPIWin";
if (`window -exists "d_IPIWin"` == 1){deleteUI "d_IPIWin";}

window -t "ImagePlaneInspector_V1" d_IPIWin;
columnLayout -adjustableColumn 1 mainLayout;
frameLayout -l "Info" -cll true -collapse 1 infoLayout;
columnLayout -adjustableColumn 1;
text -l "scripted by deadalvs";
text -l "april '08";
setParent..;
setParent..;
string $cameraArray[] = `ls -cameras`;
for ($eachCamera in $cameraArray){
frameLayout -l ($eachCamera + " controls") -cll true -collapse 1 ($eachCamera + " controlLayout");
columnLayout;
attrFieldSliderGrp -min 0 -max 2 -at ($eachCamera+".overscan");
attrFieldSliderGrp -min -0.5 -max 0.5 -at ($eachCamera+".horizontalFilmOffset");
attrFieldSliderGrp -min -0.5 -max 0.5 -at ($eachCamera+".verticalFilmOffset");
string $buttoncommand = "d_lookThruThisCam(\"" + $eachCamera + "\")";
button -h 20 -w 420-l "look thru" -command ($buttoncommand);
setParent..;
setParent..;
//end for ($eachCamera in $cameraArray){
}
columnLayout -adjustableColumn 1;
button -h 40 -l "reset overscans and film offsets" -command "d_resetCameraAttributes();";
button -h 30 -l "update Inspector GUI" -command "d_updateInspectorGUI();";
showWindow d_IPIWin;
//end d_updateInspectorGUI
}

///////////////////////////////////////////////////////////////

global proc d_resetCameraAttributes(){
string $cameraArray[] = `ls -cameras`;
for ($eachCamera in $cameraArray){
setAttr ($eachCamera + ".overscan") 1;
setAttr ($eachCamera + ".horizontalFilmOffset") 0;
setAttr ($eachCamera + ".verticalFilmOffset") 0;
}
//end d_resetCameraAttributes
}

///////////////////////////////////////////////////////////////

global proc d_findActiveCameraPanel(){
global string $activeCamPanel;
string $allPanels[] = `getPanel -vis`;
string $camPanel = "";
for($i=0;$i<size($allPanels);$i++)
{
if(`match "^modelPanel" $allPanels[$i]` == "modelPanel")
{
global string $activeCamPanel;
$camPanel = $allPanels[$i];
$activeCamPanel = $camPanel;
break;
}
}
//end d_findActiveCameraPanel
}

///////////////////////////////////////////////////////////////

global proc d_lookThruThisCam(string $desiredView){
global string $activeCamPanel;
d_findActiveCameraPanel;
lookThroughModelPanel $desiredView $activeCamPanel;
//end d_lookThruThisCam
}

deadalvs
04-17-2008, 10:37 AM
oh man..

has anyone an idea about why the perspective cams work perfectly with the sliders and the orthogonal ones don't ? they're treated the same ! simply with the attrFieldSliderGrp command ...
:banghead:

DOor
04-17-2008, 02:44 PM
I had a similar problem with one of my scripts recently with the same problem.. I ended up not using orthographic cams :hmm:

the orthographic cams are a completely different camera type of camera shape and even though they have the offset attributes those only effect perspective cams.


Looking at the attributes breifly you could try using the Film Translate attribute instead. it appears to work like an offset and starts at 0, 0. you would just need to add a condition statement to check if the camera has the orthographic flag set and then adjust/connect attributes accordingly.

deadalvs
04-17-2008, 07:41 PM
hi eric !

yeah, the film translate kinda moves the film back, but as the name of the script says, i want to be able to check parts of the image plane without physically moving the camera by zooming. so that's not an option... *sigh*

so i'll just leave a note in the info tab about this.

instead of the check you mentioned, one can also just fill two arrays with different portions of attributes:
string $cameraPArray[] = `listCameras -p`;
string $cameraOArray[] = `listCameras -0`;

code so far now:


d_updateInspectorGUI;
global proc d_updateInspectorGUI(){
// deleteUI "d_IPIWin";
if (`window -exists "d_IPIWin"` == 1){deleteUI "d_IPIWin";}

window -t "ImagePlaneInspector_V1" d_IPIWin;
columnLayout -adjustableColumn 1 mainLayout;
frameLayout -l "Info" -cll true -collapse 1 infoLayout;
columnLayout -adjustableColumn 1;
text -l "";
text -l "scripted by deadalvs";
text -l "april '08";
text -l "";
text -l "the hor. and vert. film offsets seem not to";
text -l " work with orthocams. so these attributes";
text -l "are not included in ortho-cams";
text -l "";
setParent..;
setParent..;
//perspective cams
string $cameraPArray[] = `listCameras -p`;
for ($eachCamera in $cameraPArray){
frameLayout -l ($eachCamera + " controls") -cll true -collapse 1 ($eachCamera + " controlLayout");
columnLayout;
attrFieldSliderGrp -min 2.5 -max 650 -at ($eachCamera+".focalLength");
attrFieldSliderGrp -min 0 -max 2 -at ($eachCamera+".overscan");
attrFieldSliderGrp -min -0.5 -max 0.5 -at ($eachCamera+".horizontalFilmOffset");
attrFieldSliderGrp -min -0.5 -max 0.5 -at ($eachCamera+".verticalFilmOffset");
string $buttoncommand = "d_lookThruThisCam(\"" + $eachCamera + "\")";
button -h 20 -w 420-l "look thru" -command ($buttoncommand);
setParent..;
setParent..;
//end for ($eachCamera in $cameraPArray){
}
//orthographic cams
string $cameraOArray[] = `listCameras -o`;
for ($eachCamera in $cameraOArray){
frameLayout -l ($eachCamera + " controls") -cll true -collapse 1 ($eachCamera + " controlLayout");
columnLayout;
attrFieldSliderGrp -min 0 -max 2 -at ($eachCamera+".overscan");
string $buttoncommand = "d_lookThruThisCam(\"" + $eachCamera + "\")";
button -h 20 -w 420-l "look thru" -command ($buttoncommand);
setParent..;
setParent..;
//end for ($eachCamera in $cameraOArray){
}
columnLayout -adjustableColumn 1;
button -h 40 -l "reset overscans and film offsets" -command "d_resetCameraAttributes();";
button -h 20 -l "update Inspector GUI" -command "d_updateInspectorGUI();";
showWindow d_IPIWin;
//end d_updateInspectorGUI
}

///////////////////////////////////////////////////////////////

global proc d_resetCameraAttributes(){
string $cameraArray[] = `ls -cameras`;
for ($eachCamera in $cameraArray){
setAttr ($eachCamera + ".overscan") 1;
setAttr ($eachCamera + ".horizontalFilmOffset") 0;
setAttr ($eachCamera + ".verticalFilmOffset") 0;
}
//end d_resetCameraAttributes
}

///////////////////////////////////////////////////////////////

global proc d_findActiveCameraPanel(){
global string $activeCamPanel;
string $allPanels[] = `getPanel -vis`;
string $camPanel = "";
for($i=0;$i<size($allPanels);$i++)
{
if(`match "^modelPanel" $allPanels[$i]` == "modelPanel")
{
global string $activeCamPanel;
$camPanel = $allPanels[$i];
$activeCamPanel = $camPanel;
break;
}
}
//end d_findActiveCameraPanel
}

///////////////////////////////////////////////////////////////

global proc d_lookThruThisCam(string $desiredView){
global string $activeCamPanel;
d_findActiveCameraPanel;
lookThroughModelPanel $desiredView $activeCamPanel;
//end d_lookThruThisCam
}

CGTalk Moderation
04-17-2008, 07:41 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.