Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. [Loading PLY file using QT3D]
Qt 6.11 is out! See what's new in the release blog

[Loading PLY file using QT3D]

Scheduled Pinned Locked Moved Solved Qt 6
2 Posts 1 Posters 662 Views
  • 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.
  • A Offline
    A Offline
    appdev
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      appdev
      wrote on last edited by
      #2

      Sorry, the file name was incorrect.

      Thank you again.

      Have a nice day y'all.

      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