code snippet - is node or cachedGeom vertex - inside oriented box
mCasual
Posts: 4,607
who knows maybe someday someone will see it and later remember it's here
the idea is we take the world-space vertex position,
apply the inverse of the transform of the oriented bounding box
then we check if that position is in the oriented bounding box's ''local bounding box"
to test this
-create a little ball and a cube
-animate the ball over 30 frames going in and out of the cube
-select a little ball, then select a rotated/translated cube
-run the script
the script will make the ball small when it's outside, and larger when it's inside
var node = Scene.getSelectedNode( 0 );
var cube = Scene.getSelectedNode( 1 )
var scaler = node.getScaleControl();
var tick = Scene.getTimeStep();
for( i = 0; i <= 30; i++ )
{
var t = i * tick;
var dOBB = cube.getWSOrientedBox( t );
var dLBox = dOBB.localBox;
var dTrans = dOBB.transform ;
var dUnTrans = dTrans.inverse();
var bInBox = inBox( node.getWSPos( t ), dLBox, dUnTrans );
if( bInBox )
scaler.setValue( t, 1 );
else
scaler.setValue( t, .5 );
}
function inBox( v, bb, dUnTrans )
{
var vv = dUnTrans.multMatrixVec( v );
if( ( vv.x > bb.minX ) && ( vv.x < bb.maxX ) )
{
if( ( vv.y > bb.minY ) && ( vv.y < bb.maxY ) )
{
if( ( vv.z > bb.minZ ) && ( vv.z < bb.maxZ ) )
{
return( true );
}
}
}
return( false );
}
pop.gif
768 x 640 - 571K
Post edited by mCasual on
Comments
Wow thanks, that's a neat way to address the issue