qt3d how to render custom vertices which can be composed a set of triangle



  • 1.the key point i cant construct the data structure for vertices and normal



  • Hi! What do you got so far?



  • yes it can render now with sets of triangle ,,but now i wanna to use index to render ,since it have much duplicate point ..how could i render



  • my now code is
    Qt3DRender::QGeometry *geometry = new Qt3DRender::QGeometry;

    	auto  m_positionAttr =   new Qt3DRender::QAttribute(geometry);
    	//auto  m_colorAttr =      new Qt3DRender::QAttribute(geometry);
    	 auto  m_indexAttr =      new Qt3DRender::QAttribute(geometry);
    	auto  m_NORAttr =        new Qt3DRender::QAttribute(geometry);
    
    	auto m_positionBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, geometry);
    	//auto m_colorBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, geometry);
    	 auto m_indexBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::IndexBuffer, geometry);
    
    	auto m_NORBuffer = new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, geometry);
    
    	uint vsize = p3dparser->mmeshs[0].mVertices.size();
    	uint isize = p3dparser->mmeshs[0].mIndices.size();
    	//Configure the attributes access
    	QByteArray colorData;
    	uint size1 = sizeof(QVector3D);
    	//positionData.resize(vsize * 3 * sizeof(float));
    	QByteArray mNormals, mindexs;
    	char*pdata = (char*)&p3dparser->mmeshs[0].mVertices[0][0];
    	mindexs.resize(vsize * sizeof(uint));
    	uint*pindexs = (uint*)mindexs.data();
    	for (int i = 0; i <vsize; i++)
    		pindexs[i] = i;
    	 
    	const uint nVerts = vsize;
    	const uint size = nVerts * 3 * sizeof(float);
    	QByteArray positionBytes, noramlbytes;
    	positionBytes.resize(size);
    
    	vsize = nVerts;
    	memcpy(positionBytes.data(), pdata, size);
    	m_positionBuffer->setData(positionBytes);
    
    
    	uint facenum = vsize / 3;
    	uint j = 0, i = 0;
    	mNormals.resize(vsize * 2 * sizeof(Vector3));
    	Vector3*vertex = &p3dparser->mmeshs[0].mVertices[0];
    	Vector3*pnormal = (Vector3*)mNormals.data();
    	
    	Vector3 n;
    	FindMinMax((QVector3D*)vertex, vsize);
    	movetocenterbyOC((QVector3D*)vertex, vsize,mcenter);
    	uint cnt = 0, index1 = 0, count = 0;
    	
    	for (j = 0; j <vsize * 2; )
    	{
    		if (j % 6 == 0) {
    			  CalcNormal(&vertex[cnt],n);
          	}
    
    		 pnormal[j++] = vertex[cnt++];
    		pnormal[j++] = n;
    	}
    
    	m_NORBuffer->setData(mNormals);	 			 
    	const quint32 elementSize = 3 + 3;
    	const quint32 stride = elementSize * sizeof(float);
    	//m_colorBuffer->setData(colorData);
    	m_positionAttr->setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
    	m_positionAttr->setVertexBaseType(Qt3DRender::QAttribute::Float);
    	m_positionAttr->setDataSize(3);
    	m_positionAttr->setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
    	m_positionAttr->setBuffer(m_NORBuffer);
    	m_positionAttr->setCount(vsize);
    	m_positionAttr->setByteStride(stride);
    	//m_positionAttr->setProperty();
    
    	m_NORAttr->setName(Qt3DRender::QAttribute::defaultNormalAttributeName());
    	m_NORAttr->setVertexBaseType(Qt3DRender::QAttribute::Float);
    	m_NORAttr->setDataSize(3);
    	m_NORAttr->setAttributeType(Qt3DRender::QAttribute::VertexAttribute);
    	m_NORAttr->setBuffer(m_NORBuffer);
    	m_NORAttr->setCount(vsize);
    	m_NORAttr->setByteOffset(3 * sizeof(float));
    	m_NORAttr->setByteStride(stride);
    
    
    	geometry->addAttribute(m_positionAttr);
    	geometry->addAttribute(m_NORAttr);
      //  geometry->addAttribute(m_indexAttr);
    	
    	auto renderer  = new Qt3DRender::QGeometryRenderer(m3dentity);
    	geometry ->setParent(m3dentity);
    	renderer ->setVerticesPerPatch(3);
    	renderer ->setGeometry(geometry);
    	renderer ->setPrimitiveType(renderer ->Triangles);
    	 
    	
    	addnode(renderer);


  • could anyone know how the render the no repeat point with QT3D


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.