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);
        scene_Main.add(BV);
    }
    stage_6_declared = true;
}

console.log(box3) returns:
image
image

Please any help would be great.

Can you explain what do you mean by subdivision?

This basically

image

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
                    
      scene_Main.add(BV); //Add object to the scene
   }
},

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"
       }));

       scene_Main.add(grid);
   }
},

The color changes but there is no subdivision.

image

image

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
      scene_Main.add(BV); //Add object to the scene
  }
},

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 ); 
      scene_Main.add(grid);
  }
},

image

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 );

image

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

Please try:

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
      scene_Main.add(BV); //Add object to the scene
  }
},

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"
      }));

      scene_Main.add(grid);
  }
},
1 Like

Oh, this was supposed to be .getCenter( grid.position );

Works great!

image

2 Likes

also i restored the deleted question. sorry i didn’t realise other would find helpful.

1 Like