Doc > Expressions > bbox

Doc > Expressions > bbox

Returns the bbox of a geometry, or a component of the bbox.

Description

It takes 1, 2 or 3 arguments.

bbox(<input_index_or_node_path>, <bbox_vector>, <vector_component>)

  • <input_index_or_node_path> is a number or a string
  • <bbox_vector> is a string, either 'min' or 'max'
  • <vector_component> is a string, either 'x', 'y' or 'z'

Usage

  • bbox(0) - returns the bbox of the input node, as a THREE.Box3
  • bbox('/geo1/box') - returns the bbox of the node /geo1/box, as a THREE.Box3
  • bbox('/geo1/box', 'min') - returns the min vector of the bbox, as a THREE.Vector3
  • bbox('/geo1/box', 'min', 'x') - returns the x component of min vector of the bbox, as a number

Edit code in JsFiddle , Codepen , view in a new tab or Open in the Editor


// create a scene
const scene = new PolyScene();
const root = scene.root();

// create a box and a sphere
const geo = root.createNode('geo');
const sphere = geo.createNode('sphere');
const box = geo.createNode('box');
const torus = geo.createNode('torus');
const merge1 = geo.createNode('merge');
const merge2 = geo.createNode('merge');

merge1.setInput(0, sphere);
merge1.setInput(1, box);
box.p.center.x.set(3);

merge2.setInput(0, merge1);
merge2.setInput(1, torus);
merge2.flags.display.set(true);

torus.p.radius.set(`bbox('../${merge1.name()}').max.x`);
torus.p.radiusTube.set(0.15);
torus.p.segmentsRadial.set(5);
torus.p.segmentsTube.set(60);
torus.p.direction.set([0, 0, 1]);

// add a light
root.createNode('hemisphereLight');

// create a camera
const perspectiveCamera1 = root.createNode('perspectiveCamera');
perspectiveCamera1.p.t.set([5, 5, 5]);
// add orbitControls
const events1 = perspectiveCamera1.createNode('eventsNetwork');
const orbitsControls = events1.createNode('cameraOrbitControls');
perspectiveCamera1.p.controls.setNode(orbitsControls);

// mount the viewer
const element = document.getElementById('app');
perspectiveCamera1.createViewer(element);