How to update the segments of a BufferGeometry?

I have created the following scene, and I want to access the segments and update them using a slider as demonstrated this DEMO.

This is what I have:

image

What I use to create the subdivided cubes:

BV_Subdivide(5);

BV_Subdivide(numOfSubdivisions) {
                //Declare a Vector3
                var tempV = new THREE.Vector3();
                numOfSubdivisions = 5;
                
                for(var i=0; i<bv_List.length; i++) {

                    //Compute the bounding volumes of all selected objects
                    bv_List[i].geometry.computeBoundingBox();
                    bv_List[i].geometry.boundingBox.getSize( tempV );
                    
                    //Create a new Buffer Geometry for each object
                    var thisBufferGeometry = new THREE.BoxBufferGeometry( 
                        tempV.x, 
                        tempV.y, 
                        tempV.z, 
                        numOfSubdivisions, 
                        numOfSubdivisions, 
                        numOfSubdivisions 
                    );
                    
                    //Create a grid BV
                    var subdividedBox = GridBoxGeometry(thisBufferGeometry, false);
                    
                    //Calculate the center of the bounding volume
                    bv_List[i].geometry.boundingBox.getCenter(tempV);
                    
                    //Update the position of the new BV
                    subdividedBox.translate(tempV.x, tempV.y, tempV.z);
                    
                    //Create new LineSegments for each object and assign BV Geometry and Material
                    var grid = new THREE.LineSegments(subdividedBox, new THREE.LineBasicMaterial({
                        color: "aqua"
                    }));
                    
                    bv_Final_List[i] = grid;
                    
                    scene_Main.add(grid); //Add Final BV in the scene
                }
            },

How to update the segments of the buffer geometry after the declaration?

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

           //Update segments for each object

           //Render?
     }
}

Not quite sure what you mean by segments.
But if you mean update vertices and the mesh geometry the following link might help:
How to update things

1 Like

I would just re-create them:

BV_Update() {

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

          scene_Main.remove( bv_Final_List[ i ] );

     }

    BV_Subdivide(numOfSubdivisions);

}
2 Likes

I would use shaders for that purpose.

That’s too complicated for me, I have like a month experience with this library.

Thanks I’ll try work on this