Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   running command on entry to a bounding box (https://simplymaya.com/forum/showthread.php?t=31409)

bendingiscool 22-11-2008 01:22 PM

running command on entry to a bounding box
 
Hey guys,

Ok I have a cylinder moving around a scene, what I would like to do is run a command when the cylinder enters within the bounding box of a stationary cube and when it leaves.

Below is the expression I have so far, it gets the bounding box of each item and prints a word when it is within the same bounding box, at the moment it is only for the worldspace in X.

The problem is, it keeps printing the word when its inside the bounding box rather than just once on entry, any ideaas on how to get this to work?

//////////////////////
float $cylBBox[] = `xform -q -ws -boundingBox pCylinder1`;
float $cubeBBox[] = `xform -q -ws -boundingBox pCube1`;

if ( ($cylBBox[0] < $cubeBBox[0]) && ($cylBBox[3] < $cubeBBox[3]) )
{
print "whatever";
}
/////////////////////

Many thanks

Chris

Xander-0 22-11-2008 10:22 PM

Try substituting something like this...

if (( ($cylBBox[0] < $cubeBBox[0]) && ($cylBBox[3] < $cubeBBox[3])) && $boundingCheck)
{
print "whatever";
$boundingCheck = FALSE;
} else {
$boundingCheck = TRUE;
}

I think that should do it....
(been a while since I've messed with expressions in maya).

bendingiscool 23-11-2008 10:22 AM

Thanks fot the reply Xander, this is what I have so far...

//////////////////////////////
int $objectIsInside;// on/off switch
int $time = `currentTime -query`;// get current frame
float $cylBBox[] = `xform -q -ws -boundingBox pCylinder1`;// cylinder's BBox
float $cubeBBox[] = `xform -q -ws -boundingBox pCube1`;// cube'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 true set to yes
$objectIsInside = yes;//check if object is in BBox
}
} else {
if ($objectIsInside) //if true set to no
print ($time);//print current frame
$objectIsInside = no;//check if object is in BBox
}
//////////////////////////////

it stores the current frame when it enters the bounding box of the cube (am using this to chuck into a switch statement to go between animation clips), shall post more updates as I go.

Chris

PS: I'm guessing there must be a simpler, cleaner way to do this but this is working at the mo, any other solutions are very much welcome.


All times are GMT. The time now is 02:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018