Beer glass scene creation
This course contains a little bit of everything with modeling, UVing, texturing and dynamics in Maya, as well as compositing multilayered EXR's in Photoshop.
# 1 22-11-2008 , 01:22 PM
bendingiscool's Avatar
Subscriber
Join Date: Jul 2006
Location: London
Posts: 567

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

# 2 22-11-2008 , 10:22 PM
Xander-0's Avatar
Registered User
Join Date: Feb 2005
Location: This Place
Posts: 220
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).


Book Wise

https://X4nd5r.deviantart.com
# 3 23-11-2008 , 10:22 AM
bendingiscool's Avatar
Subscriber
Join Date: Jul 2006
Location: London
Posts: 567
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.

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads