Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt 5.15.2 Q3D Object picking does not work on custom geomentry



  • Hello everyone
    Yet again I was trying to do something custom in Q3D and faced the following problem.
    I've made a custom geometry following instructions in examples and (actually) modifing the QTorusMesh class from the source.

    Somehow I've managed to draw what I wanted but the object picking functionnality refuses to work properly on my mesh.
    I noticed that if I make geometry to be drawn in reverse order (the slices of my srface would go in oposite direction giving the inverse figure in the end), the picking starts working but not on the whole surface but somewhere in the central area.
    I tryied:

    • changing places of vertex indicies (switching on/off the visibility of the face and doesn't afect picking)
    • changing normal directions (seens to be irrelevant at all)
    • changing tangents (same result)
    • crying and laughing (same result)

    I've read this topic
    https://forum.qt.io/topic/96709/qobjectpicker-qpickingsettings-trianglepicking-doesn-t-work-with-custom-mesh/3
    but it does not seem to be the case.

    I would very like to know how te intersection mechanism works. The code is gigantic amd my best gues is render-backend to look through.

    Thanks for any ideas!



  • Ok... now my logic is over....
    I've switched off pickingin all the objects but one and ...

    This way picking works

            Qt3DCore::QTransform *transform = new Qt3DCore::QTransform();
            transform->setScale(4.0f);// this line
            transform->setTranslation(QVector3D(15.0f, -10.0f, 0.0f));
    
            Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial();
            material->setDiffuse(QColor(QRgb(0x665423)));
    
            m_twoCylinderFilletEntity = new Qt3DCore::QEntity(m_rootEntity);
            m_twoCylinderFilletEntity->setObjectName("m_twoCylinderFilletEntity");
            {
                m_objectPicker = new Qt3DRender::QObjectPicker(m_twoCylinderFilletEntity);
                m_objectPickers.push_back(m_objectPicker);
                connect(m_objectPicker,&Qt3DRender::QObjectPicker::clicked,
                        this,&SceneModifier::clickedHandler);
            }
            m_twoCylinderFilletEntity->addComponent(m_twoCylinderFilletMesh);
            m_twoCylinderFilletEntity->addComponent(material);
            m_twoCylinderFilletEntity->addComponent(transform);
            m_twoCylinderFilletEntity->addComponent(m_objectPicker);
    

    This way it DOES NOT

    Qt3DCore::QTransform *transform = new Qt3DCore::QTransform();
            transform->setScale(1.0f);// this line
            transform->setTranslation(QVector3D(15.0f, -10.0f, 0.0f));
    
            Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial();
            material->setDiffuse(QColor(QRgb(0x665423)));
    
            m_twoCylinderFilletEntity = new Qt3DCore::QEntity(m_rootEntity);
            m_twoCylinderFilletEntity->setObjectName("m_twoCylinderFilletEntity");
            {
                m_objectPicker = new Qt3DRender::QObjectPicker(m_twoCylinderFilletEntity);
                m_objectPickers.push_back(m_objectPicker);
                connect(m_objectPicker,&Qt3DRender::QObjectPicker::clicked,
                        this,&SceneModifier::clickedHandler);
            }
            m_twoCylinderFilletEntity->addComponent(m_twoCylinderFilletMesh);
            m_twoCylinderFilletEntity->addComponent(material);
            m_twoCylinderFilletEntity->addComponent(transform);
            m_twoCylinderFilletEntity->addComponent(m_objectPicker);
    

    I specifically duplicated the whole code to show that nothing else but the scale in QTransformation has changed. I just can't get it how scaling can possibly affect intersection calculation....
    Please some one explain me this because I really have no idea what the developers tried to acheive.

    I'm also seriously considering gving out Qt Q3D as my project choice becasuse such unexpected behaviour is very difficult to debug and maintain. The Q3D seems VERY IMMATURE, bug prone and constantly changing from version to version.
    The fron-end/back-end architecture does not give any particular advandages in such situation but obfuscates the source and pulls down the debug process into trial-and-error.

    Probably for some simple projects without some advance (but actually NOT that advanced) geometric processing Q3D is ok. If so I'd like to see complite documentation (and not just for QML which will never be the one and only mean for interface development, Python or Lua in this sence would be better choice as a scripting and configuration mechanism).



  • I wonder if there is a minimum size for object picking?



  • I'm back once again. Don't beleave it myself though.
    After a little bit more experimentaion the following knowledge is obtained:

    • this bug is NOT only with custom mesh but with any mesh (even from Qt3DExtras)
    • it seems to have something with bounding volume:
      in the function bool HierarchicalEntityPicker::collectHits(NodeManagers *manager, Entity *root) (pickboundingvolumeutils.cpp)
      line 786 :queryResult = rayCasting.query(m_ray, current.entity->worldBoundingVolume());
      line 787: if (accepted && queryResult.m_distance >= 0.f && (current.hasObjectPicker || !m_objectPickersRequired))
      the if statement is not fullfilled for small volumes. The worldBoundingVolume() returns structure with m_raidious == -1 (but the object being clicked is perfectly fine)

    Maybe developers could spend some time and debug it as they understand what's going on much better than I do.
    Also some workaround for the current Qt 5.15.2 version is appreciated!


Log in to reply