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. qt3d how to render custom vertices which can be composed a set of triangle
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.2k Views 1 Watching
  • 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

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

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! What do you got so far?

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

        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

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

          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);
          
          1 Reply Last reply
          0
          • J Offline
            J Offline
            jimfar
            wrote on last edited by
            #5

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

            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