0

I have an entity formed of multiple triangles (custom mesh called bigEntity).
I want to create an entity (a triangle called littleEntity) with the exact same position of an existing triangle of the bigEntity but with a different color.

The probleme here is that the littleEntity is created but doesn't appear on screen. I create this littleEntity after the bigEntity. It should appear on screen no? Is there a way to do it ?

I know there is this, but i don't want to touch framegraph, and i'm not sure that it would be sufficient.

Here a simplified code of the issue :

    QList<QPair<int, QVector3D>> listVertices;
    listVertices.append(qMakePair(1, QVector3D(-2,2,0)));
    listVertices.append(qMakePair(1, QVector3D(-1, 2, 0)));
    listVertices.append(qMakePair(1, QVector3D(-1, 0, 0)));
    listVertices.append(qMakePair(1, QVector3D(-2, 2, 0)));
    listVertices.append(qMakePair(1, QVector3D(-1, 0, 0)));
    listVertices.append(qMakePair(1, QVector3D(-2, 0, 0)));

    Qt3DCore::QEntity * bigEntity = this->m_sceneBuilder->createInstancedShape(listVertices, 3, Qt::yellow, this->m_rootEntity);

    listVertices.clear();
    listVertices.append(qMakePair(1, QVector3D(-2, 2, 0)));
    listVertices.append(qMakePair(1, QVector3D(-1, 2, 0)));
    listVertices.append(qMakePair(1, QVector3D(-1, 0, 0)));

    Qt3DCore::QEntity * littleEntity = this->m_sceneBuilder->createShape(listVertices, Qt::blue, this->m_rootEntity);

    //if i add tranform, i can see the littleEntity
    /*Qt3DCore::QTransform *transform = new Qt3DCore::QTransform();
    transform->setTranslation(QVector3D(0.1, 0.1, 0.1));
    littleEntity->addComponent(transform);*/

Knowing that createShape and createInstancedShape just create custom mesh using QGeometryRenderer and QGeometry and return the QEntity created.

When i draw littleEntity before bigEntity it work, but in my program i can't do that ..

Romain
  • 44
  • 6
  • 1
    Not sure about Qt3d, but in OpenGL, the depth buffer could be cleared before drawing the _little entity_ or the depth test could be disabled. (Mostly, this is not an option but if - it's very simple.) Another option would be to modify the depth test function for the _little entity_ using [GL_LEQUAL](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDepthFunc.xhtml) instead of `GL_LESS` (the default) but I'm not sure about z buffer fighting issues of that solution. My last resort would be to use [glPolygonOffset](https://www.cs.rit.edu/~ncs/Courses/570/UserGuide/OpenGLonWin-14.html). – Scheff's Cat Jul 22 '20 at 08:51
  • Thank's, i will try that and i'll come back to you – Romain Jul 22 '20 at 08:58
  • _When i draw littleEntity before bigEntity it work_ That's another simple solution (if applicable) but I'm afraid for this the [Z buffer fighting](https://learnopengl.com/Advanced-OpenGL/Depth-testing) issue as well. (Please, scroll down to subject _Z-fighting_ in the linked page - I couldn't find an anchor for this subject.) – Scheff's Cat Jul 22 '20 at 09:05
  • Well i changed the depth test function of the qt3DWindow (that old the scene) from Less to LessOrEqual and it did the work. Thank you for informing me of the risks that can occure. I will keep you informed. I think you can post it as a solution – Romain Jul 22 '20 at 09:13
  • Glad that I could help you. Though, I'm afraid that my experience with Qt3d is less than yours. So, how about a [self-answer](https://stackoverflow.com/help/self-answer)? I will be happy to up-vote if you can teach me something. (Qt3d is on my todo list but stacked under a lot of other exciting things.) ;-) – Scheff's Cat Jul 22 '20 at 09:21

0 Answers0