Solved PLY Object Does Not Show
-
I created a .ply file, which I tested with MeshLab, but does not display in Qt:
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
QUrl data = QUrl::fromLocalFile("/XXX/flyingwedge/flyingwedge.ply");
qDebug() << data.fileName();
Qt3DExtras::Qt3DWindow view;
Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity;
Qt3DCore::QEntity *flyingwedge = new Qt3DCore::QEntity(rootEntity);
Qt3DRender::QMaterial *material = new Qt3DExtras::QMetalRoughMaterial(rootEntity);
Qt3DRender::QMesh *flyingwedgeMesh = new Qt3DRender::QMesh;
flyingwedgeMesh->setMeshName("FlyingWedge");
flyingwedgeMesh->setSource(data);
Qt3DCore::QTransform *flyingwedgeTransform = new Qt3DCore::QTransform;
flyingwedgeTransform->setScale3D(QVector3D(10.0, 10.0, 10.0));
Qt3DRender::QFrontFace *frontFace = new Qt3DRender::QFrontFace(rootEntity);
frontFace->setDirection(Qt3DRender::QFrontFace::CounterClockWise);
flyingwedge->addComponent(flyingwedgeMesh);
flyingwedge->addComponent(material);
flyingwedge->addComponent(flyingwedgeTransform);
Qt3DRender::QCamera *camera = view.camera();
camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
camera->setPosition(QVector3D(0, 0, 40.0f));
camera->setViewCenter(QVector3D(0, 0, 0));
view.setRootEntity(rootEntity);
view.show();
return a.exec();
}
Another program that is identical to this program shows a torus mesh object fine. What am I missing? -
Hi,
You should add which version of Qt you are using and one which platform it is.
Might be a silly question but are you sure of the path of your .ply file ?
-
@SGaist Hello again.
Linux Mint, At least version 5.9. It seems to find the file when I debug and I get no error message. Is there a way to determine that the ply file was read?The .ply file is:
ply
format ascii 1.0
element vertex 5
property float32 x
property float32 y
property float32 z
element face 5
property list uint8 int32 vertex_index
end_header
0 0 0
10 5 0
10 -5 0
9 4 2
9 -4 2
3 0 4 3
3 0 3 1
4 4 2 1 3
3 0 2 4
3 0 1 2Anything else I can provide. I am at a loss at this point.
-
Update. I suspect that the problem in with the URL. I added:
QUrl data = QUrl::fromLocalFile("/home/XXX/flyingwedge/flyingwedge.ply"); qDebug() << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName();
and got:
true "/home/XXX/flyingwedge/flyingwedge.ply" false "flyingwedge.ply"
QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefinedWhich says the file does not exist. I guess that @SGaist was correct. Any pointer to the correct way to specify the path for the URL will be greatly appreciated.
-
I moved the file up one level and it works. Why I do not know, but I am no longer stymied; I can proceed.
-
Glad you found a solution and thanks for sharing !
Happy coding
-
It is three years later and I returned to this project, but it no longer works. What has changed to make ply files no longer create the correct meshes. Is there an example of a program the works correctly when a ply mesh is imported? Thanks.
-
Hi,
You should consider providing a minimal compilable example showing the issue.
-
This is similar to the one posted previously but shorter.
int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); Qt3DCore::QEntity *rootEntity = new Qt3DCore::QEntity; Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial(rootEntity); QUrl data = QUrl::fromLocalFile("/home/bobwilliams/flyingwedge.ply"); qDebug() << data.isValid() << data.toLocalFile() << QFileInfo(data.toLocalFile()).exists() << data.fileName(); QFileInfo info("/home/bobwilliams/triangle.ply"); qDebug() << info.exists(); Qt3DCore::QEntity *triangleEntity = new Qt3DCore::QEntity(rootEntity); Qt3DRender::QMesh *triangleMesh = new Qt3DRender::QMesh; triangleMesh->setMeshName("Triangle"); triangleMesh->setSource(data); triangleEntity->addComponent(triangleMesh); triangleEntity->addComponent(material); Qt3DExtras::Qt3DWindow view; Qt3DRender::QCamera *camera = view.camera(); camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); camera->setPosition(QVector3D(0, 0, 40.0f)); camera->setViewCenter(QVector3D(0, 0, 0)); view.setRootEntity(rootEntity); view.show(); return a.exec(); }
I get:
Starting /home/bobwilliams/build-untitled1-Desktop_Qt_5_8_0_GCC_64bit-Debug/untitled1...
true "/home/bobwilliams/flyingwedge.ply" true "flyingwedge.ply"
true
Qt3D.Core.Nodes: void Qt3DCore::QEntity::addComponent(Qt3DCore::QComponent*) Qt3DRender::QMesh(0x1516f10)
Qt3D.Core.Nodes: void Qt3DCore::QEntity::addComponent(Qt3DCore::QComponent*) Qt3DExtras::QPhongMaterial(0x1500000)
QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefinedDoes that help. I just checked and I am on 5.8 but I cannot update to the latest 5.x version.
-
@ofmrew I have egg on my face. I if you look at the .ply file you will see that I violated the rule that the vertices be in the range [-1 -1 -1] to [1 1 1]. Made the change and it worked.
-
Glad you found out and thanks for sharing !
Since you have it working now, please mark your thread as solved using the "Topic Tools" button or the three dotted menu on the right of the answer you deem correct so that other forum users may know a solution has been found :-)