How to set 3d object(QCylinderMesh, QSphereMesh) bounding volume to make QObjectPicker work an accurate way
the creation of the Cylinder looks below:
m_cylinderMesh = new Qt3DExtras::QCylinderMesh(); m_cylinderTransfrom = new Qt3DCore::QTransform(); m_cylinderMaterial = new Qt3DExtras::QPhongMaterial(); Qt3DRender::QObjectPicker *cylinderPick = new Qt3DRender::QObjectPicker(); connect(cylinderPick, SIGNAL(clicked(Qt3DRender::QPickEvent *)), this, SLOT(slotItemPicked(Qt3DRender::QPickEvent *))); m_cylinder = new Qt3DCore::QEntity(m_pRootEntity); m_cylinder->addComponent(m_cylinderMesh); m_cylinder->addComponent(m_cylinderTransfrom); m_cylinder->addComponent(m_cylinderMaterial); m_cylinder->addComponent(cylinderPick); m_cylinderMesh->setRadius(0.5); m_cylinderMesh->setLength(3); m_cylinderMesh->setRings(20); m_cylinderMesh->setSlices(20); m_cylinderTransfrom->setTranslation(QVector3D(-4, 4, 0));//set position
when clicked out around the object, it emit signal too, it seems the bounding volume is a sphere with radius = Cylinder.height.
when we create a sphere with QSphereMesh, picker works well. can somebody suppose a solution?
I never used the object picker, so far. But I read about a QPickingSettings class, did you try it?
There is also the localIntersection() (in local coordinates of the cylinder) function of the QPickEvent. So you should be able to check for an exact hit yourself.
@m.sue localIntersection() of QPickEvent cannot work if you dont change pick method, because other items behide it cannot be triggered with mouse event.
use QPickingSettings in my code work but change the default scene environment setting causes lots of cpu using and react unsmooth.
my code like this
m_renderSettings = new Qt3DRender::QRenderSettings(m_pRootEntity); m_renderSettings->pickingSettings()->setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking); m_renderSettings->setRenderPolicy(Qt3DRender::QRenderSettings::OnDemand); m_renderer = new Qt3DExtras::QForwardRenderer(); m_renderer->setCamera(m_cameraEntity); m_renderer->setSurface(this); m_renderSettings->setActiveFrameGraph(m_renderer); m_pRootEntity->addComponent(m_renderSettings);
qt5.9 Qt3dwindow can use renderSettings() directly but not for 5.8
is there any exmaple, thanks.
This is how I did it in earlier versions:
Qt3DRender::QRenderSettings *settings= qobject_cast<Qt3DRender::QRenderSettings*> activeFrameGraph()->parent()); if (settings) settings->setRenderPolicy(Qt3DRender::QRenderSettings::OnDemand);
@m.sue I went to the opensource code, it real works. thanks, Michael..
@fisher103 I am so glad I found this post, I am having the exact same issue, except I am displaying a custom shape drawn from vertices and indices. How did you solve this?
@hhughe11 use code like this in your qt3dwindow
Qt3DRender::QRenderSettings *settings =