1

I am following the basic shape c++ example for understanding/ learning Qt3D. Instead of using predefined Qt3DExtras meshes, I am using a .ply file to create a mesh. This works fine and I am able to view my mesh. However, If I try to view the mesh form other side by rotating the camera, it becomes invisible. I believe the correct term for this is called culling (correct me if I am wrong). How do I prevent this from happening to the ply mesh.

Note: I have read another question here and from what I understand, I have to use QCullFace. I have gone through the official doc for QCullFaceand tried to include it in my code, but to no avail. Following is my code snippet for reference:

MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_view = new Qt3DExtras::Qt3DWindow();//Qt3DExtras::Qt3DWindow
    m_view->defaultFrameGraph()->setClearColor(QColor(QRgb(0xFFFFFF)));
    QWidget *container = QWidget::createWindowContainer(m_view);
    ui->horizontalLayout_3D->addWidget(container);

    Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect;
    m_view->registerAspect(input);

    // Root entity
    m_rootEntity = new Qt3DCore::QEntity();

    // Camera
    m_cameraEntity = m_view->camera();// Qt3DRender::QCamera   
    m_cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 100000.0f);
    m_cameraEntity->setUpVector(QVector3D(1, 1, 0));
    m_cameraEntity->setPosition(QVector3D(3000.0f, 0.0f, 0.0f));
    m_cameraEntity->setViewCenter(QVector3D(0, 0, 0));
    //Light
    Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(m_rootEntity);
    Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
    light->setColor("white");
    light->setIntensity(1);
    lightEntity->addComponent(light);
    Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
    lightTransform->setTranslation(m_cameraEntity->position());
    lightEntity->addComponent(lightTransform);

    // For camera controls 
    m_camController = new Qt3DExtras::QOrbitCameraController(m_rootEntity);//Qt3DRender::QCamera
    m_camController->setCamera(m_cameraEntity);
    m_camController->setLookSpeed(200);
    m_camController->setLinearSpeed(1000);

/*Tried to add the following referring QCullFace official doc. It has no effect
    Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass();

    // Create a front face culling render state
    Qt3DRender::QCullFace *cullFront = new Qt3DRender::QCullFace();
    cullFront->setMode(Qt3DRender::QCullFace::NoCulling);

    // Add the render state to the render pass
    renderPass->addRenderState(cullFront);

*/    
//3D entity
    m_ROI1_Entity = new Qt3DCore::QEntity(m_rootEntity);//Qt3DCore::QEntity
    m_ROI1material = new Qt3DExtras::QPhongMaterial(m_rootEntity);

    //material
    m_ROI1Mesh = new Qt3DRender::QMesh(m_rootEntity);//Qt3DRender::QMesh
    m_ROI1Mesh->setSource(QUrl(QUrl::fromLocalFile("myPlyFile.ply")));

    //transform
    m_ROI1Transform = new Qt3DCore::QTransform();//Qt3DCore::QTransform
    m_ROI1Transform->setScale(0.5f);//680.0f
    m_ROI1Transform->setTranslation(QVector3D(0.0f, 0.0f, 0.0f));
    m_ROI1Transform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), -90.0f));
    m_ROI1_Entity->addComponent(m_ROI1Mesh);
    m_ROI1_Entity->addComponent(m_ROI1material);
    m_ROI1_Entity->addComponent(m_ROI1Transform);
    m_view->setRootEntity(m_rootEntity);

}
Rishu Singh
  • 49
  • 1
  • 11
  • This sounds like the backside of your 3d model uses the wrong [polygon winding order](https://www.khronos.org/opengl/wiki/Face_Culling). To test this: try inverting the default winding order using the `QFrontFace` render state – Botje Jan 03 '20 at 15:14
  • @Botje Tried using `QFrontFace` with both `Qt3DRender::QFrontFace::CounterClockWise` as well as `Qt3DRender::QFrontFace::ClockWise` parameters. The issue is still seen. Maybe, I am not adding it properly. Could you point me in right direction on how to add `QFrontFace` properly – Rishu Singh Jan 03 '20 at 15:46
  • @RishuSingh See [this answer](https://stackoverflow.com/a/51839858/12177714) – avttrue Jan 03 '20 at 18:27
  • @avttrue I am adding qCullFace just like the one used in the example in the linked answer. However, issue is still observed. Any other example that I can follow? – Rishu Singh Jan 06 '20 at 05:40
  • @RishuSingh I may have misunderstood you, but [here](https://github.com/avttrue/qt3dtest3/blob/master/core/3d/sceneview.cpp) is my attempt to use ```Qt3DRender:: QCullFace``` and it is successful. – avttrue Jan 06 '20 at 19:19

0 Answers0