Exiting Bounding Box

Hey, back to bug some more

Here is some code to check when a cylinder enters a bounding box of a group of cubes. When it enters it prints a word, what I need is for it to record when it exits aswell.

CODE
int $objectIsInside;// on/off switch

float $cylBBox[] = xform -q -ws -boundingBox pCylinder1;// cylinder's BBox
float $cubeBBox[] = xform -q -ws -boundingBox group1;// group's BBox

if (     ($cylBBox[0] < $cubeBBox[0]) && ($cylBBox[2] > $cubeBBox[2]) ||//check X BBox
            ($cylBBox[3] < $cubeBBox[3]) && ($cylBBox[5] > $cubeBBox[5]) ||//check Y BBox
                ($cylBBox[3] < $cubeBBox[3]) && ($cylBBox[4] > $cubeBBox[4]) ||//check Z BBox
                    ($cylBBox[2] < $cubeBBox[2]) && ($cylBBox[0] > $cubeBBox[0]) ||//check -X BBox
                        ($cylBBox[4] < $cubeBBox[4]) && ($cylBBox[3] > $cubeBBox[3]) ) //check -Z BBox
{
     if (!$objectIsInside){// if not inside set to yes
      $objectIsInside = yes;// check if object is in BBox
    }
} else {
    if ($objectIsInside) // if inside set to no
        print "entered BBox";// print word
    $objectIsInside = no;// check if object is in BBox
}

It only prints the word when the cylinder enters the first bounding box, I presume this is because of the off switch, but I can't work out how to switch it back on when it leaves the bounding box so that it can be used again.

Anyhelp with this one would be great as I am not sure how to get it to turn back on.

Thanks, Chris

Just a question how do you plan to RUN the code? I mean its the sort fo code you can do but its not how you want to approach maya.

Hmm, I hadn't really thought about putting it another way, could you further explain please.

Chris

I tried some suggestions, made a couple of changes to sort out syntax, now it says its ok as is doesn't give any errors, but for some reason its not printing out anything, no matter where the cylinder is.

CODE
$boolPrinted = 0;

float $cylBBox[] = xform -q -ws -boundingBox pCylinder1;// cylinder's BBox
float $grpBBox[] = xform -q -ws -boundingBox group1;// group's BBox

if (     ($cylBBox[0] < $grpBBox[0]) && ($cylBBox[3] > $grpBBox[3]) ||//check X BBox
        ($cylBBox[2] < $grpBBox[2]) && ($cylBBox[5] > $grpBBox[5]) )//check Z BBox
{
    if ($boolPrinted == 0)
    {
print "Object is in";
$boolPrinted = 1;
    }
}
    else
    {
    if ($boolPrinted == 1)
    {
print "Object is out";
$boolPrinted = 0;
    }

}

The bouding box numbers should be ok but for some reason it isn't printing the words.

Any ideas on this one?

Thanks, Chris

this way uses no mel - is it still useful for you?

http://video.google.com/videoplay?docid=-5...32346&hl=en

QUOTE
Hmm, I hadn't really thought about putting it another way, could you further explain please.

Well see it comes down to how mel is related to the maya core. Its not sort of the tool you do computation with. So building control compuatation with mel is not exactly what you want. Mel is in sense a interfacing language, or journal language.

Some people instantly recongnize this for a fact once they see mel n more than one or 2 lines. Some do not because they have n such concept in their brain. I have found that explaining this thorughly is a bit hard. But i was reecently introduced to the original idea where it stems from so i have a better idea now. Tough mayas a very special offshot of this.

Thing is mayas core unit is the NODE, not script. So what you should eb doing is nodes that solve your problsm NOT code. In fact its very hard to do any sort of direct programming with mel. (this is why they added python totally perverting mayas core design, just wait 5 years and then tell me if it was good idea) This may seem like a limitation but brilliantly its not.

So maya script inetface wether or not its in mel consists of 3 things:

  • Controll logic and expressions
  • Gui hooks and descriptions
  • Node creation and manipulation commands
  • The gui in maya is separated form the rest so the way you approach doing anything in maya is by populating nodes to do your job with the express purpose of writing as little mel to node interfacing as possible. Now you don't really use mel to create nodes and thus any computation that you end up doing in mel is minimal. Hence mel doesn't need any complex data structuring capabilities becasue its expressly known that you wont be doing any algorithms in mel.

    So any proper mel code will result in a comment like this:
    QUOTE
    this way uses no mel - is it still useful for you?

    Wich is a misnomer, in actuality they DID use mel because the act of creating nodes is expressly domain of mel. So he cant create anything if it wasn't for the mel (or should we call it scripting) layer.So anytime somebod who is not a programmer suggests a solution without mel shows that they are better attuned to do mel than anybody who didn't. So mel is sort of a just a way to encapsulate things users do for faster interaction. Vrey rarely does this translate to extending maya or actually never. If you could do it with mel then maya expressly could do it already.

    So any time your doing computation in mel your very likely doing it on the worng side of interface. Mel is just a sortof way for you to describe in text for covinence with some logic to make it more verastile.

    Now then theres 1 thing that bridges the gap, its sort of in between, its teh expression engene sued in expression nodes and particle expression nodes. They should only use the subset ]Controll logic and expressions inside them and use the special expression nodes only syntax for inetrafceing. Leaving all/most mel comends outside the loop.

    If you wish to do nodes its a EXPLICIT JOB FOR THE API.

    For the gui teh thing si different, for this end maya provides extenssive querrying capabilities so you can build interfaces between theese. In teh gui you do have full progamming controll over things altough slightly indirectly. Dont mix thees up.

    Knowing maya is knowing how to use mel even if you don't write mel. Writing mel as code is not the best use of your time.