0

I want to generate VBO and EBO for subdivided plane, I draw with GL_TRIANGLES, I want to know effective way to do this. Eventually it will be a huge cube consists from 6 subdivided plane, so, i can't imagine alghorithm to generate VBO and EBO for subdivide.

What i have as input data: cube

std::vector<float> vertices = 
    {
         // +Y SIDE                                             //Colors
        -0.5f,  0.5f, -0.5f,                                    0.0f, 1.0f, 0.0f,
         0.5f,  0.5f, -0.5f,                                    0.0f, 1.0f, 0.0f,  
        -0.5f,  0.5f,  0.5f,                                    0.0f, 1.0f, 0.0f,  
         0.5f,  0.5f,  0.5f,                                    0.0f, 1.0f, 0.0f,
        
         // -Y SIDE
        -0.5f,  -0.5f, -0.5f,                                   0.0f, 1.0f, 0.0f, 
         0.5f,  -0.5f, -0.5f,                                   0.0f, 1.0f, 0.0f, 
        -0.5f,  -0.5f,  0.5f,                                   0.0f, 1.0f, 0.0f, 
         0.5f,  -0.5f,  0.5f,                                   0.0f, 1.0f, 0.0f,
        
         // +X SIDE
        0.5f,  0.5f,  0.5f,                                     1.0f, 0.0f, 0.0f, 
        0.5f,  0.5f, -0.5f,                                     1.0f, 0.0f, 0.0f, 
        0.5f, -0.5f,  0.5f,                                     1.0f, 0.0f, 0.0f,  
        0.5f, -0.5f, -0.5f,                                     1.0f, 0.0f, 0.0f,
        
         // -X SIDE
        -0.5f,  0.5f,  0.5f,                                    1.0f, 0.0f, 0.0f, 
        -0.5f,  0.5f, -0.5f,                                    1.0f, 0.0f, 0.0f, 
        -0.5f, -0.5f,  0.5f,                                    1.0f, 0.0f, 0.0f, 
        -0.5f, -0.5f, -0.5f,                                    1.0f, 0.0f, 0.0f,
        
         // +Z SIDE
        -0.5f,  0.5f, 0.5f,                                     0.0f, 0.0f, 1.0f,  
         0.5f,  0.5f, 0.5f,                                     0.0f, 0.0f, 1.0f,  
        -0.5f, -0.5f, 0.5f,                                     0.0f, 0.0f, 1.0f,  
         0.5f, -0.5f, 0.5f,                                     0.0f, 0.0f, 1.0f,
         // -Z SIDE
        
        -0.5f,  0.5f, -0.5f,                                    0.0f, 0.0f, 1.0f,
         0.5f,  0.5f, -0.5f,                                    0.0f, 0.0f, 1.0f,
        -0.5f, -0.5f, -0.5f,                                    0.0f, 0.0f, 1.0f,
         0.5f, -0.5f, -0.5f,                                    0.0f, 0.0f, 1.0f
    };
    
       
    std::vector<unsigned int> indices = 
    {
        // +Y   
        1,  2,  0,  3,  2,  1,
    // -Y 
        4, 6, 5, 5, 6, 7,
        
        // +X
        8, 9, 10, 9, 11, 10,
    // -X
    14, 13, 12, 14, 15, 13,
    
    // +Z 
        17, 18, 16, 19, 18, 17,
    // -Z
    20, 22, 21, 21, 22, 23
    };

So, i want to write a function witch accept subdivision and change my indeces and vertices vectors, just loop over existed planes in cube and subdivide it

  • Step 1: Imagine the algorithm. Any first-year programmer should be able to imagine how to generate the coordinates for an axis-aligned subdivided plane - it's not much different from those "print a pyramid of stars" problems. – user253751 Mar 31 '22 at 09:39
  • Roughly. For each triangle create three new vertices which are the mid-points of each edge. Then use the original 3 and new 3 vertices to create four new triangles. Repeat as often as necessary. – PeteBlackerThe3rd Mar 31 '22 at 11:20
  • see this [sphere recursive triangulation](https://stackoverflow.com/a/29139125/2521214) for some ideas/inspiration ... its almost the same task just slightly more math involved due to normalization to sphere surface which is not your case ... – Spektre Apr 01 '22 at 07:32

0 Answers0