Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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



  •         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 ?



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



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



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



  • 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"


Log in to reply