PDA

View Full Version : Find the shortest path between 2 points in a mesh



franco.amato
26th March 2023, 18:46
Good morning,
premising that I am completely new to 3d programming the only knowledge I have are the studies I did at university more than 20 years ago..
I would like to develop a basic app able to import 3d mesh data from ply files and, after taking 2 points on the surface, should be able to find the shortest path between them.

I started modifying the basicshapes-cpp Qt demo to import the polygon data from an external ply file instead of creating the shapes from coding.
The basic app compile and run successfully, but when I load a shape from the files I have, I can not see it centered or I see it too small.

Here the code I've used (code modified from basichapes-cpp demo):


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);
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->setAlignment(Qt::AlignTop);
hLayout->addWidget(container, 1);
hLayout->addLayout(vLayout);

widget->setWindowTitle(QStringLiteral("Basic Mesh Viewer"));

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, 1000.0f);
cameraEntity->setPosition(QVector3D(0, 0, -1.0f));
cameraEntity->setUpVector(QVector3D(0, 1, 0));
cameraEntity->setViewCenter(QVector3D(0, 0, 0));

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("monster.ply");

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();
}

I would like to have the following help:

* Understand why I see the shape infinitely small and how to fix it
* Understand how I can center the shape in the screen and big enough so I can see it well
* Understand how to add mouse interaction so I can zoom/move the scene
* After a mouse left click, understand how I can get the coordinates of a specific polygon so that a shortest path algorithm can be applied.

Thank you very much

d_stranz
27th March 2023, 21:51
I would look at the coordinates of the object you are trying to import and see how those compare with the coordinates you have set for your camera's front and back planes and camera position. Either the imported object's dimensions are tiny or it is in the far distance in the viewing frustrum compared to the camera location.