Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 22-11-2008, 01: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, 10: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, 10: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

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.