[Loading PLY file using QT3D]
Solved
Qt 6
-
Hello guys,
I hope you're all doing well.
So I've looked for some examples on how to laod a ply file in Qt and found one on this forum.
int main(int argc, char* argv[]) { QApplication app(argc, argv); Qt3DExtras::Qt3DWindow *view = new Qt3DExtras::Qt3DWindow(); view->defaultFrameGraph()->setClearColor(QColor(QRgb(0x4d4d4f))); QWidget *container = QWidget::createWindowContainer(view); QSize screenSize = view->screen()->size(); container->setMinimumSize(QSize(200, 100)); container->setMaximumSize(screenSize); QWidget *widget = new QWidget; QHBoxLayout *hLayout = new QHBoxLayout(widget); hLayout->addWidget(container, 1); widget->setWindowTitle(QStringLiteral("Basic shapes")); Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect; view->registerAspect(input); // Root entity Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity(); // Camera Qt3DRender::QCamera *cameraEntity = view->camera(); cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 100000.0f); cameraEntity->setPosition(QVector3D(-30000, 0, 20000.0f)); cameraEntity->setUpVector(QVector3D(0, 0, 1)); cameraEntity->setViewCenter(QVector3D(0, 0, 10000)); Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(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(cameraEntity->position()); lightEntity->addComponent(lightTransform); //Loading .ply data QUrl data = QUrl::fromLocalFile("C:/Users/nahra/3DModel_qt3d/Model3D/challengone.PLY"); qDebug() << data << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName(); Qt3DRender::QMesh *bodyMesh = new Qt3DRender::QMesh(); bodyMesh->setMeshName("bodyMesh"); bodyMesh->setSource(data); Qt3DCore::QTransform *bodyTransform = new Qt3DCore::QTransform; bodyTransform->setScale3D(QVector3D(10.0, 10.0, 10.0)); Qt3DExtras::QPhongMaterial *bodyMaterial = new Qt3DExtras::QPhongMaterial(); bodyMaterial->setDiffuse(QColor(QRgb(0x928327))); Qt3DCore::QEntity *plyEntity = new Qt3DCore::QEntity(rootEntity); plyEntity->addComponent(bodyMesh); plyEntity->addComponent(bodyMaterial); plyEntity->addComponent(bodyTransform); // Set root object of the scene view->setRootEntity(rootEntity); // Show window widget->show(); widget->resize(1200, 800); return app.exec(); }
However the program seems to not read the ply file since the scene is empty.
I created a qrc file in which I put the 3D model (ply file) and I'm sure the path is correct.
I don't really get what's wrong with the app.
please help.
Thank you all.