GUI Madness!
by TheRiverside on Nov.06, 2009, under MEL Scripting Final
Well, tonight’s been a pretty long and trying night…
As part of my MEL scripting final project, I’m trying to expand upon a “light dropper” script writen by Jordan Rempel (http://jordanrempel.com/links.html). This script creates a spotlight with the same translation and rotation value as the perspective camera. Simple… but pretty cool!
I’m trying to provide the user with the ability to press a button, drop a light (in this case a spot light) at the location of the perspective camera, and quickly look through it using a pre-defined modelPanel. I would also like to be able to have an object selected. The light would then auto-correct its rotation (while keeping its translation values the same as the perspective camera) and essentially focus on said object. The user would then have the freedom to fine-tune the light’s location interactively without having to go to “Look Through Selected”, adjust, then switch back to perspective mode. Every type of Maya light should have a dedicated button.
I honestly thought that this was a pretty straight-forward task. It was not meant to be the major part of my final by any means… I have a lot to learn…
Before I could really start, I had to create a rough User Interface consisting of a button to create the spotlight and a modelPanel with which to look through the light (as well as some other layout elements… trying to plan ahead). I’m quickly starting to feel that modelPanels are the devil. To make a long story short, I’ve been wading through layout and parenting issues for hours. ModelPanels seem to interact much differently with Interfaces than other objects. Also, aparently modelPanels are not deleted when windows are closed. Thus, if the script is run a second time, the explicit name I gave the modelPanel is no longer unique, resulting in the script crashing. I tried letting Maya name the modelPanel and storing it under a variable to call back later. However, say the script is run two dozen times. There are two dozen newly-created modelPanels now cluttering up your scene.
Anyway, I now have a very temporary GUI to work with. After all this, beginning to write the light generation procedure seemed extremely easy. There are, however, a good many kinks that can’t really be worked out until I figure out a way to manage the modelPanel issue.
I shall now leave you with a script I accidently wrote…
When trying to figure out the best way to judge the distance between an object and the newly created light, I came up with this:
global proc dcg_distanceBetweenObjects()
{
string $selection[] = `ls -selection`;
float $translateObject1[] = `xform -query -translation $selection[0]`;
float $translateObject2[] = `xform -query -translation $selection[1]`;
string $distanceBetween = `distanceDimension -endPoint $translateObject1[0] $translateObject1[1] $translateObject1[2]
-startPoint $translateObject2[0] $translateObject2[1] $translateObject2[2]`;
}
Simply select two objects and run the script (excluding the “global proc” line). A “distanceDimension” will be created used to interactively show the distance between them.
aaaaaaand it’s 4:12 in the AM…
Goodnight.