SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / running command on entry to a bounding box
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 22-11-2008, 12:22 PM   #1
bendingiscool
Subscriber
 
bendingiscool's Avatar
 
Join Date: Jul 2006
Location: London
Posts: 567
Thanks: 0
Thanked 1 Time in 1 Post
Default 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
bendingiscool is offline   Reply With Quote
Old 22-11-2008, 09:22 PM   #2
Xander-0
Registered User
 
Xander-0's Avatar
 
Join Date: Feb 2005
Location: This Place
Posts: 220
Thanks: 0
Thanked 2 Times in 1 Post
Default

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

http://X4nd5r.deviantart.com
Xander-0 is offline   Reply With Quote
Old 23-11-2008, 09:22 AM   #3
bendingiscool
Subscriber
 
bendingiscool's Avatar
 
Join Date: Jul 2006
Location: London
Posts: 567
Thanks: 0
Thanked 1 Time in 1 Post
Default

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.
bendingiscool is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.