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
Forum Updated to NodeBB v4.3 + New Features

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.2k Views 1 Watching
  • 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 23 Jun 2017, 10:05 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 1 Reply Last reply 23 Jun 2017, 11:19
    0
    • F fisher103
      23 Jun 2017, 10:05

      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 Offline
      M Offline
      m.sue
      wrote on 23 Jun 2017, 11:19 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 25 Jun 2017, 02:53
      1
      • M m.sue
        23 Jun 2017, 11:19

        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 25 Jun 2017, 02:53 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 1 Reply Last reply 26 Jun 2017, 07:58
        0
        • F fisher103
          25 Jun 2017, 02:53

          @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 Offline
          M Offline
          m.sue
          wrote on 26 Jun 2017, 07:58 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 26 Jun 2017, 13:15
          1
          • M m.sue
            26 Jun 2017, 07:58

            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 26 Jun 2017, 13:15 last edited by
            #5

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

            H 1 Reply Last reply 11 Jul 2017, 21:48
            1
            • F fisher103
              26 Jun 2017, 13:15

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

              H Offline
              H Offline
              hhughe11
              wrote on 11 Jul 2017, 21:48 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 14 Jul 2017, 03:20
              0
              • H hhughe11
                11 Jul 2017, 21:48

                @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 14 Jul 2017, 03:20 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