X3DObject.GetBoundingBox

Introduced

v10.0 (2012)

Description

Returns the minimum and maximum coordinates for the visible bounding box of the X3DObject. If an input transform is specified, it is applied to the bounding box when it is calculated. Otherwsie, the bounding box that is returned will be in the object's local coordinate space.

If the bounding box is undefined then the minimum coordinates returned will be greater than the maximum coordinates. This could happen if the object is hidden or if the object does not contain any geometry.

Note: Only one coordinate needs to be tested to determine if the bounding box is undefined. (min X > max X)

C# Syntax

Object X3DObject.GetBoundingBox( Object in_pXfoObjectToBBoxSpace, Boolean in_bRecursive );

Scripting Syntax

oArray = X3DObject.GetBoundingBox( [Transform], [Recursive] );

Return Value

1-dimensional Array containing six values: the minimum X, Y and Z coordinates followed by the maximum X, Y, and Z coordinates of the bounding box.

Parameters

Parameter Type Description
Transform SITransformation Transform to be applied when the bounding box is calculated
Recursive Boolean If true include children, otherwise return bounding box for input X3DObject only.

Default Value: False

Examples

1. JScript Example

/*
	Example using no input transform
*/
// Create and move (rotate and translate) a torus
NewScene( null, false ) ;
var oTorus = ActiveSceneRoot.AddGeometry( "Torus", "MeshSurface" ) ;
SelectObj( oTorus ) ;
Rotate(null, 45, 0, 0, siAbsolute, siPivot, siObj, siX, null, null, null, null, null, null, null, 0, null) ;
Translate(null, 3, 2, 1, siAbsolute, siPivot, siObj, siX, null, null, null, null, null, null, null, null, null, 0, null) ;
// Find the bounding box
var vba = new VBArray( oTorus.GetBoundingBox() ) ;
var jsa = vba.toArray() ;
// Report the (local) min and max
Application.LogMessage( "min:" + jsa[0] + ", " + jsa[1] + ", " + jsa[2] ) ;
Application.LogMessage( "max:" + jsa[3] + ", " + jsa[4] + ", " + jsa[5] ) ;

2. JScript Example

// Example using an input transform to preserve scaling
//
// Create and move (rotate and translate) a torus
NewScene( null, false ) ;
var oTorus = ActiveSceneRoot.AddGeometry( "Torus", "MeshSurface" ) ;
SelectObj( oTorus ) ;
Scale(null, 0.5, 0.5, 1, siAbsolute, siGlobal, siObj, siY, null, null, null, null, null, null, null, 0, null) ;
oTransform = oTorus.Kinematics.Local.Transform ;
// Find the bounding box
var vba = new VBArray( oTorus.GetBoundingBox(oTransform) ) ;
var jsa = vba.toArray() ;
// Report the min and max
Application.LogMessage( "min:" + jsa[0] + ", " + jsa[1] + ", " + jsa[2] ) ;
Application.LogMessage( "max:" + jsa[3] + ", " + jsa[4] + ", " + jsa[5] ) ;
// Build a cube that shows the bounding box
var oCube = ActiveSceneRoot.AddPrimitive("Cube") ;
oCube.length = 1 ;
oCube.PosX = (jsa[0]+jsa[3])/2 ;
oCube.PosY = (jsa[1]+jsa[4])/2 ;
oCube.PosZ = (jsa[2]+jsa[5])/2 ;
oCube.sclx = jsa[3]-jsa[0] ;
oCube.scly = jsa[4]-jsa[1] ;
oCube.sclz = jsa[5]-jsa[2] ;

See Also

Geometry.GetBoundingBox Geometry.GetBoundingSphere Geometry.GetBoundingCapsule GetBBox