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

Sakthi G sakthi.g at vjcs.com
Thu Aug 22 15:19:59 CEST 2024


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
********************************************************************************************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240822/0cbe3128/attachment.htm>


More information about the Interest mailing list