[osg-users] Mesh reduction with indexes modification

Roberto Vicini roberto.vicini1_2014 at libero.it
Tue Feb 2 14:16:30 PST 2016


Hi,

I'm using osg for reproduce SRTM data into a scene and all works fine.
Now i want to reduce triangle in the scene by maintaining same vertex array and modify index buffer in order to skip some of the vertices in vertex array.
I use indexed GL_TRIANGLES.
This is the code i use for indexing traingles


Code:

int factor = 8;
m_indexArray->resize(m_indexArray->size()/factor);
  for (int i = 0; i<(m_rows - 1)/factor; i++){
    for (int j = 0; j<(m_columns - 1)/factor; j++){
      int vertexIndex = (i* m_columns) + j;

      (*m_indexArray)[index++] = factor*(vertexIndex);
      (*m_indexArray)[index++] = factor*(vertexIndex + m_columns);			 
      (*m_indexArray)[index++] = factor*(vertexIndex  + 1);

      (*m_indexArray)[index++] = factor*(vertexIndex + 1);
      (*m_indexArray)[index++] = factor*(vertexIndex + m_columns );			 
      (*m_indexArray)[index++] = factor*(vertexIndex + m_columns  +1);
    }
}




Where:
m_rows is row count of mesh.
m_columns is col count of mesh
factor is a variable i use to reduce triangles.
m_indexArray is of type osg::ref_ptr<osg::DrawElementsUInt>.

As i said i use a "factor" variable in order to reduce indexed vertices. if factor == 1 then i have full resolution mesh (original mesh)
because indexing cover all vertices. if i choose (and it must be a power of two) factor == 2 or 4 or 8 and so on i obtain 
reduced mesh. In particular if i choose factor = 2 then i got a mesh with 1/4 of triangles and so on.

The mesh in the scene is rapresented as expect but i have a problem. With values of factor > 1 when i move into the scene
may occur some "interruption". The camera movement seems to break some tenths of second and after resume.
This strange behavior seems to verify randomly when scene is on, but surely when i set values of factor > 1.
May be the indexing does not cover all vertices?

Thank you!

Cheers,
roberto[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66178#66178








More information about the osg-users mailing list