# Is it possible to subdivide a Box3Helper?

Hi, I’m trying to demonstrate BoundingVolume SUBDIVISION, and I was thinking if it’s able to subdivide a Box3Helper. Or how to convert the Box3Helper to an object?

My Example:

createBoundingVolumes() {

for(var i=0; i<groupOfObjects.length; i++) {
var BV = new THREE.BoxHelper( groupOfObjects[i], 0xffff00 );
var box3 = new THREE.Box3();
box3.setFromObject(BV);
}
stage_6_declared = true;
}

console.log(box3) returns:

Please any help would be great.

Can you explain what do you mean by subdivision?

This basically

And then I want to remove the cubes that does NOT contain a mesh.

Hi!
Have a look at GridBoxGeometry and Grid Collection

1 Like

UPDATE

Is there a way to return the bufferGeometry of BoxHelper?

I tried using this

function BV_Create(){

for(var i=0; i<groupOfObjects.length; i++) {

var BV = new THREE.BoxHelper( groupOfObjects[i], 0xffff00 );
BV.update();

bv_List[i] = BV;
bv_List[i].material.visible = false; //Set true in draw() function

}
},

function BV_Subdivide()  {

for(var i=0; i<bv_List.length; i++) {

var thisBufferGeometry = new THREE.BoxBufferGeometry().fromGeometry(bv_List[i]); //Also tried bv_List[i].geometry

var subdividedBox = GridBoxGeometry(thisBufferGeometry, true / false);

var grid = new THREE.LineSegments(subdividedBox, new THREE.LineBasicMaterial({
color: "aqua"
}));

}
},

The color changes but there is no subdivision.

Any ideas?

The BoxBufferGeometry can’t be constructed the way you’ve tried. Please try:

//Declare a Vector3
var tempV = new THREE.Vector3();
...
// In the loop:
bv_List[i].computeBoundingBox();
bv_List[i].boundingBox.getSize( tempV );
var thisBufferGeometry = new THREE.BoxBufferGeometry( tempV.x, tempV.y, tempV.z, segmentsX, segmentsY, segmentsZ );

segmentsX, Y, Z are the number of subdivisions on each axis.

After creating the grid, do

bv_List[i].boundingBox.getCenter( grid.position );

UPDATE:

BV_Create() {
for(var i=0; i<groupOfObjects.length; i++) {
var BV = new THREE.BoxHelper( groupOfObjects[i], 0xffff00 );
BV.update();
bv_List[i] = BV;
bv_List[i].material.visible = false; //Set true in draw() function
}
},

BV_Subdivide() {

var tempV = new THREE.Vector3(); //Declare a Vector3

for(var i=0; i<bv_List.length; i++)  {
bv_List[i].geometry.computeBoundingBox();
bv_List[i].geometry.boundingBox.getSize( tempV );
var thisBufferGeometry = new THREE.BoxBufferGeometry( tempV.x, tempV.y, tempV.z, 3, 3, 3 );

var subdividedBox = GridBoxGeometry(thisBufferGeometry, false);
var grid = new THREE.LineSegments(subdividedBox, new THREE.LineBasicMaterial({
color: "aqua"
}));

//Line 638 - Error message
bv_List[i].geometry.boundingBox.getCenter( thisBufferGeometry.position );
}
},

I found out that by using either of this it will create want I want but in the wrong position.

bv_List[i].geometry.boundingBox.getCenter( bv_List[i].object.position );
bv_List[i].geometry.boundingBox.getCenter( groupOfObjects[i].position );

PLEASE do not delete your old posts, they are useful for reference. Without them what I say has no meaning.

BV_Create() {
for(var i=0; i<groupOfObjects.length; i++) {
var BV = new THREE.BoxHelper( groupOfObjects[i], 0xffff00 );
BV.update();
bv_List[i] = BV;
bv_List[i].material.visible = false; //Set true in draw() function
}
},

BV_Subdivide() {

var tempV = new THREE.Vector3(); //Declare a Vector3

for(var i=0; i<bv_List.length; i++)  {
bv_List[i].geometry.computeBoundingBox();
bv_List[i].geometry.boundingBox.getSize( tempV );
var thisBufferGeometry = new THREE.BoxBufferGeometry( tempV.x, tempV.y, tempV.z, 3, 3, 3 );

var subdividedBox = GridBoxGeometry(thisBufferGeometry, false);

bv_List[i].geometry.boundingBox.getCenter( tempV );
subdividedBox.translate( tempV.x, tempV.y, tempV.z );

var grid = new THREE.LineSegments(subdividedBox, new THREE.LineBasicMaterial({
color: "aqua"
}));