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 QCullFace
and 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);
}