[Interest] Qt3D - QObjectPicker doesn't work with multiple QLayers and QLayerFilters

Mike Krus mike.krus at kdab.com
Thu Aug 22 17:18:55 CEST 2024


Hi

the frame affects picking in a couple of ways:
- the layer filter, entities should only be pickable if the filter accepts the entities, otherwise they would be ignored
- the camera and viewport that are active in the branch (this affect the picking ray that gets tested)

I’m assuming in your case the only difference is the layer filter?

If seems like there may be an issue with the dynamic nature of your scene graph and 
Qt3D’s backend not being updated properly.

A few things to try:
- when creating new entities, create them without a parent, add the components and children, then set the parent
- if possible with your scene graph, maybe have separate parents for opaque and transparent entities (rather than
  mixing them under the same parent), and add the layer component to the parent entities rather then each entity
  (making sure you mark it as recursive).

I don’t think these should change the issue but might be something worth trying.

If you have a small example I can use to reproduce the issue, please create a bug report and assign it to me.


Mike


> On 22 Aug 2024, at 14:19, Sakthi G <sakthi.g at vjcs.com> wrote:
> 
> Hello, We have a Qt3D application where we have multiple QLayers for different types of meshes. We have found out that QObjectPicker doesn’t work properly with multiple QLayers. It doesn’t get triggered consistently if the entity has layer component which is not filtered at the top of the framegraph.
>  Consider the following simplified framegraph with two layer filter branches, one for opaque and one for transparent objects:
>    Qt3DRender::QViewport* mainViewport = new Qt3DRender::QViewport(renderSurfaceSelector);
>         mainViewport->setNormalizedRect(QRectF(0, 0, 1.0, 1.0));
>          Qt3DRender::QCameraSelector* cameraSelector = new Qt3DRender::QCameraSelector(mainViewport);
>         cameraSelector->setCamera(view->camera());
>          Qt3DRender::QRenderStateSet* renderStateSet = new Qt3DRender::QRenderStateSet(cameraSelector);
>         {
>         Qt3DRender::QDepthTest* depthTest = new Qt3DRender::QDepthTest;
>         depthTest->setDepthFunction(Qt3DRender::QDepthTest::LessOrEqual);
>         renderStateSet->addRenderState(depthTest);
>          Qt3DRender::QCullFace* cullFace = new Qt3DRender::QCullFace(renderStateSet);
>         cullFace->setMode(Qt3DRender::QCullFace::NoCulling);
>         renderStateSet->addRenderState(cullFace);
>   }
>   // Opaque branch
>         Qt3DRender::QLayerFilter* layerFilterOpaque = new Qt3DRender::QLayerFilter(renderStateSet);
>         layerFilterOpaque->addLayer(opaqueLayer);
>         // Transparent branch
>         Qt3DRender::QLayerFilter* layerFilterTransparent = new Qt3DRender::QLayerFilter(renderStateSet);
>         layerFilterTransparent->addLayer(transparentLayer);
>  When we dynamically add meshes to the scene, we check if the default material is transparent and assign the respective layers like this:
>   if (transparent)
>         {
>             entity->addComponent(transparentLayer);               
>         }
>         else
>         {
>             entity->addComponent(opaqueLayer);               
>         }
>  After this, when we click on the dynamically added mesh, only entities with opaqueLayer get triggered 100% of time, entities with transparentLayer gets triggered inconsistently, and sometimes, it gets triggered if we click the backface of the mesh. The hit ratio is around 20%.
>  If we swap the order of layer filters in framegraph, the transparentLayer entities get triggered 100% of time and the opaqueLayer entities get triggered inconsistently. So we think that it is the framegraph which is causing this problem.  But if we modify a material and change the layers of an existing entity(with opaqueLayer), QObjectPicker gets triggered all the time. The following code demonstrates how we do that:
>  pickedEntity->addComponent(transparentLayer);
> pickedEntity->removeComponent(opaqueLayer);
> pickedEntity->setEnabled(false);
> pickedEntity->setEnabled(true);
>  Additionally, we also found that if the same scene with the above mentioned framegraph only contains dynamically created entities with transparentLayer as a component, QObjectPicker is not triggered at all.  How to fix this issue? Why does it work if we modify the layer after creating it with opaqueLayer, but not when adding dynamically while creating? Does QObjectPicker depend on how we setup the framegraph? We couldn’t find any documentation/code/forum posts linking QLayer/QLayerFilter with QObjectPicker. Your help is truly appreciated.
>  Regards,
> Sakthi
> Sakthi.g at vjcs.com
>  ********************************************************************************************************************************************************************
> This e-mail is confidential and is used for VJCS official communication.
> It may also be legally privileged. If you have received this message in error, please delete all copies of it from your system and
> notify the sender by return e-mail. If you are not intended recipient, you may not copy, print, forward,
> disclose or use any part of it. This message has been scanned for viruses and dangerous content by VJCS Mail Scanner,
> and is believed to be clean.
> 
> Visit us at www.vjcs.com
> ******************************************************************************************************************************************************************** _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest


—
Mike Krus | mike.krus at kdab.com | Senior Software Engineer & Teamlead
KDAB (UK) Ltd., a KDAB Group company
Tel: UK Office +44 1625 809908   Mobile +44 7833 491941
KDAB - The Qt Experts, C++, OpenGL Experts



More information about the Interest mailing list