QObjectPicker works strange with QCuboidMesh

67 Views Asked by At

I have Qt6.2.4. QObjectPicker picks entity even I click by mouse close to entity.

For test this case you can modify basic shapes example. If I click on red point on image I got "picked" cuboid. Why?

    // Cuboid shape data
    //   ... 
    Qt3DRender::QObjectPicker *cubePicker = new Qt3DRender::QObjectPicker(cuboid);
    connect(cubePicker, &Qt3DRender::QObjectPicker::pressed, this, [] (Qt3DRender::QPickEvent *pick) {
         qDebug() << "pick = " << pick->worldIntersection() << ", " << pick->entity()->objectName();
    });
    
   //Cuboid
   {
        // ...
        m_cuboidEntity->addComponent(cubePicker);
        m_cuboidEntity->setObjectName("Cuboid 1");
   }

Output:

pick =  QVector3D(4.56187, -0.592511, 0.443995) ,  "Cuboid 1"

enter image description here

1

There are 1 best solutions below

0
e.n.shirokov On BEST ANSWER

Qt3DWindow has render settings. It contains QPickingSettings where there is pickMethod(). By default it uses bounding sphere volume picking (PickingSettings.BoundingVolumePicking). You should choose PickingSettings.TrianglePicking. It is the solution.

Qt3DRender::QPickingSettings *pikingSettings = view->renderSettings()->pickingSettings();
pikingSettings->setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking);