Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get vertices, normals and indeces from Qt3DRender::QAttribute buffer of Qt3DRender::QGeometry
Forum Update on Monday, May 27th 2025

How to get vertices, normals and indeces from Qt3DRender::QAttribute buffer of Qt3DRender::QGeometry

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt3dopengl
2 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JulianM
    wrote on last edited by JulianM
    #1

    Hi,

    I thought will be simple task to get vertices, normals and indeces from any geometry in Qt3D. It was clear for me that I can get the components from particular Entity and from there to query for QGeometryRender,to get QAttribute with name vertexPosition , get Qt3DRender::QBuffer -> get it like QByteArray and then simply typecast it and parse it.
    The fact is I spent 4 hours and the buffer data comes empty/ size 0/. I tried with Qt3DExtras::QPlaneMesh - just to be simple clear - to get 1 or 2 triangles - but nothing comes .... on the other side the geometry is send to GPU and is drawn.

    Here is a snippet code

    const Qt3DRender::QGeometry *geometry = planeMesh->geometry();
    	for (Qt3DRender::QAttribute* attribute : geometry->attributes())
    	{
    	    /// just for information....
    		qDebug() <<attribute ->name();
    		qDebug() << attribute->vertexBaseType();
    		qDebug() << attribute->vertexSize();
    		qDebug() << attribute->buffer()->usage();
    		qDebug() << attribute->buffer()->accessType();
    		qDebug() << attribute->buffer()->data().length();/// here return 0
    	
    		if (attribute->name() == Qt3DRender::QAttribute::defaultPositionAttributeName())
    		{
    		    Qt3DRender::QBuffer *buffer = attribute->buffer();
    		    QByteArray vertexArray = buffer->data();
    		     vertexArray.detach();			
    	/// --- this way 
    		     float *reVertexArray = reinterpret_cast<float*>(vertexArray.data());		
            /// --- or this way 		
    	             int byteOffsetPos = attribute->byteOffset();
    		     int byteStridePos = attribute->byteStride();
    			
    		    if (buffer->type() == Qt3DRender::QBuffer::VertexBuffer)
                        {
    				quint32 trianglesCount = attribute->count()/ 3;
    				for (int j = 0; j < trianglesCount; ++j) 
                                     {
    					int idxPos = byteOffsetPos + j * 3 * byteStridePos;	
    					......
    

    I search on internet - mainly StackOverflow and found this
    https://stackoverflow.com/questions/46667975/qt3d-reading-raw-vertex-data-from-qgeometry

    and this
    https://stackoverflow.com/questions/52039817/understanding-the-mesh-created-by-qt3d

    I tried both of them... both of them not working.
    Can somebody help and post some solution.
    That will be really helpful, having in mind that Qt help or any information about Qt3D in c++ is close to nothing.

    Thanks

    m.sueM 1 Reply Last reply
    0
    • J JulianM

      Hi,

      I thought will be simple task to get vertices, normals and indeces from any geometry in Qt3D. It was clear for me that I can get the components from particular Entity and from there to query for QGeometryRender,to get QAttribute with name vertexPosition , get Qt3DRender::QBuffer -> get it like QByteArray and then simply typecast it and parse it.
      The fact is I spent 4 hours and the buffer data comes empty/ size 0/. I tried with Qt3DExtras::QPlaneMesh - just to be simple clear - to get 1 or 2 triangles - but nothing comes .... on the other side the geometry is send to GPU and is drawn.

      Here is a snippet code

      const Qt3DRender::QGeometry *geometry = planeMesh->geometry();
      	for (Qt3DRender::QAttribute* attribute : geometry->attributes())
      	{
      	    /// just for information....
      		qDebug() <<attribute ->name();
      		qDebug() << attribute->vertexBaseType();
      		qDebug() << attribute->vertexSize();
      		qDebug() << attribute->buffer()->usage();
      		qDebug() << attribute->buffer()->accessType();
      		qDebug() << attribute->buffer()->data().length();/// here return 0
      	
      		if (attribute->name() == Qt3DRender::QAttribute::defaultPositionAttributeName())
      		{
      		    Qt3DRender::QBuffer *buffer = attribute->buffer();
      		    QByteArray vertexArray = buffer->data();
      		     vertexArray.detach();			
      	/// --- this way 
      		     float *reVertexArray = reinterpret_cast<float*>(vertexArray.data());		
              /// --- or this way 		
      	             int byteOffsetPos = attribute->byteOffset();
      		     int byteStridePos = attribute->byteStride();
      			
      		    if (buffer->type() == Qt3DRender::QBuffer::VertexBuffer)
                          {
      				quint32 trianglesCount = attribute->count()/ 3;
      				for (int j = 0; j < trianglesCount; ++j) 
                                       {
      					int idxPos = byteOffsetPos + j * 3 * byteStridePos;	
      					......
      

      I search on internet - mainly StackOverflow and found this
      https://stackoverflow.com/questions/46667975/qt3d-reading-raw-vertex-data-from-qgeometry

      and this
      https://stackoverflow.com/questions/52039817/understanding-the-mesh-created-by-qt3d

      I tried both of them... both of them not working.
      Can somebody help and post some solution.
      That will be really helpful, having in mind that Qt help or any information about Qt3D in c++ is close to nothing.

      Thanks

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      @julianm

      You will have to set setSyncData(true); on the attribute-buffers and also synch the index buffers to get the right vertices.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved