Qt 3D rendering is slow

Viewed 591

I m using Qt 3D to visualise point cloud data. I have modified the example given here: simple-cpp example. I have added the code to read a file containing 99477 points. Following code snippet shows how I m filling the Entity class with point cloud data.

for (int i = 0; i < X.size(); i++)
{
    Qt3DCore::QEntity *sphereEntity = new Qt3DCore::QEntity(rootEntity);
    Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh;
    sphereMesh->setRadius(0.05);

    Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform;

    sphereTransform->setTranslation(QVector3D(X[i], Y[i], Z[i]));
    sphereEntity->addComponent(sphereMesh);
    sphereEntity->addComponent(sphereTransform);
    sphereEntity->addComponent(material);
}

The code is crashes after around 10 minustes after Qt3DExtras::Qt3DWindow::show() is called. The terminal output is as below:

17:53:33: Starting /home/suraj/Qt/Examples/Qt-5.15.2/qt3d/build-simple-cpp-
Desktop_Qt_5_15_2_GCC_64bit-Release/simple-cpp ...
Point cloud size: 99477 points.
18:00:06: The program has unexpectedly finished.
18:00:06: The process was ended forcefully.
18:00:06: /home/suraj/Qt/Examples/Qt-5.15.2/qt3d/build-simple-cpp-Desktop_Qt_5_15_2_GCC_64bit-Release/simple-cpp crashed.

So I decreased the number of points to ~18000, then it is able to load the scene but with some delay in seconds.

Can anyone guide me on this?

1 Answers

Default number of rings and slices for QSphereMesh is 16. Those are basically vertical and horizontal sphere subdivisions. That means each of your spheres is made out of 480 triangles. Because you are drawing 99477 spheres that means you are drawing 47,748,960 triangles. That can be a lot for integrated GPU. To fix this you can try to use smaller integer for rings and slices for each sphere or you can try to implement instancing. For example if you set rings and slices to 3 You would draw only 1,193,724 triangles.

Related