Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set 3d object(QCylinderMesh, QSphereMesh) bounding volume to make QObjectPicker work an accurate way
QtWS25 Last Chance

How to set 3d object(QCylinderMesh, QSphereMesh) bounding volume to make QObjectPicker work an accurate way

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fisher103
    wrote on last edited by
    #1

    the creation of the Cylinder looks below:
    void Window3D::createCylinder()
    {

    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?

    m.sueM 1 Reply Last reply
    0
    • F fisher103

      the creation of the Cylinder looks below:
      void Window3D::createCylinder()
      {

      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?

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi @fisher103

      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.

      -Michael.

      F 1 Reply Last reply
      1
      • m.sueM m.sue

        Hi @fisher103

        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.

        -Michael.

        F Offline
        F Offline
        fisher103
        wrote on last edited by fisher103
        #3

        @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.

        m.sueM 1 Reply Last reply
        0
        • F fisher103

          @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.

          m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          Hi @fisher103

          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);
          

          -Michael.

          F 1 Reply Last reply
          1
          • m.sueM m.sue

            Hi @fisher103

            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);
            

            -Michael.

            F Offline
            F Offline
            fisher103
            wrote on last edited by
            #5

            @m.sue I went to the opensource code, it real works. thanks, Michael..

            H 1 Reply Last reply
            1
            • F fisher103

              @m.sue I went to the opensource code, it real works. thanks, Michael..

              H Offline
              H Offline
              hhughe11
              wrote on last edited by
              #6

              @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?

              F 1 Reply Last reply
              0
              • H hhughe11

                @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?

                F Offline
                F Offline
                fisher103
                wrote on last edited by
                #7

                @hhughe11 use code like this in your qt3dwindow

                Qt3DRender::QRenderSettings *settings =
                qobject_castQt3DRender::QRenderSettings* (activeFrameGraph()->parent());
                if (settings)
                settings->pickingSettings()->setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking);

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved