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. if i have a vertex array,and a normal array ,how to render 3DObject without conversion?
Forum Updated to NodeBB v4.3 + New Features

if i have a vertex array,and a normal array ,how to render 3DObject without conversion?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 1 Posters 1.0k 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
    jimfar
    wrote on last edited by
    #1

    i just know now rendering a object into QT3D engine must be like this ,"one vertext and one normal,
    one vertext and one normal,one vertext and one normal......"but i wanna the datastruct is like this "a A set of vertices and A set of noramls" ,and the count of vertices is equal to noramls, how to render this mesh ? who could help me

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jimfar
      wrote on last edited by
      #2
              int nVerts =2946;
              QByteArray vertexBufferData;
      		QByteArray normalBufferData;
              auto vertexDataBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, customGeometry);
      		auto normalDataBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, customGeometry);
      
      		/////vertexs is a array of vertex
      		/////pnormals is a array of normal 
       	    vertexBufferData = vertexBufferData.setRawData((char*)vertexs, nVerts * sizeof(float[3])); 	
      		normalBufferData = normalBufferData.setRawData((char*)pnormals, nVerts * sizeof(float[3])); 
      		 vertexBufferData += normalBufferData;
      		vertexDataBuffer->setData(vertexBufferData);
      
      
             const quint32 stride = (0 + 1) * sizeof(float[3]);
      		auto positionAttribute = new Qt3DRender::QAttribute();
      		positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
      		positionAttribute->setBuffer(vertexDataBuffer);
      		positionAttribute->setDataType(Qt3DRender::QAttribute::Float);
      		positionAttribute->setDataSize( 3);//xyz
      		positionAttribute->setVertexSize(3);
      		positionAttribute->setByteOffset(0);
      		positionAttribute->setByteStride(stride);
      		positionAttribute->setCount(nVerts);
      		positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
      
      
      		auto normalAttribute = new Qt3DRender::QAttribute();
      		normalAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
      		normalAttribute->setBuffer(vertexDataBuffer);
      		normalAttribute->setDataType(Qt3DRender::QAttribute::Float);
      		normalAttribute->setDataSize(3);//xyz
      		normalAttribute->setByteOffset(nVerts * sizeof(float[3]));
      		normalAttribute->setByteStride(stride);
      		normalAttribute->setCount(nVerts);
      		normalAttribute->setName(Qt3DRender::QAttribute::defaultNormalAttributeName());
      
              auto customMeshRenderer = new Qt3DRender::QGeometryRenderer;
      		auto customGeometry = new Qt3DRender::QGeometry(customMeshRenderer);
      		customGeometry->addAttribute(positionAttribute);
      		customMeshRenderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
      		customMeshRenderer->setGeometry(customGeometry);
      		customMeshRenderer->setVertexCount(nVerts);
      

      this is code snippet,why it cant render ?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jimfar
        wrote on last edited by
        #3

        ByteStride is right and ByteOffset is also right (nVerts * sizeof(float[3])) why it dosent work

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jimfar
          wrote on last edited by
          #4

          maybe i dont grasp the true meaning of these api ,who could give me some advice ..

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jimfar
            wrote on last edited by
            #5

            glDrawArrays (GLenum mode, GLint first, GLsizei count); does QT3D have the similar api or apis to implementate the similar function

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jimfar
              wrote on last edited by
              #6

              ok i found a way to fixed this problem by using geometry shader to calculate the normal,and then i can just need vertex and index to render my object .more detail about using geometry shader to calculate the normal, please see QT3D example "wireframe.pro"

              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