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. QPlaneMesh geometry is null

QPlaneMesh geometry is null

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 234 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.
  • U Offline
    U Offline
    ugonight
    wrote on last edited by
    #1

    I am using Qt 6.7.0.

    I want to get the coordinates of the four corners of a QPlaneMesh, but QPlaneMesh::geometry() is NULL.

    #include <QGuiApplication>
    
    #include <Qt3DInput/QInputAspect>
    
    #include <Qt3DRender>
    #include <Qt3DExtras>
    #include <Qt3DCore>
    
    Qt3DCore::QEntity* createScene()
    {
        // Root entity
        Qt3DCore::QEntity* rootEntity = new Qt3DCore::QEntity;
    
        // Material
        auto material = new Qt3DExtras::QPhongMaterial(rootEntity);
    
        // Plane
        auto planeEntity = new Qt3DCore::QEntity(rootEntity);
        auto planeMesh = new Qt3DExtras::QPlaneMesh;
        planeMesh->setWidth(5);
        planeMesh->setHeight(5);
    
        auto planeTransform = new Qt3DCore::QTransform;
        planeTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f));
    
        planeEntity->addComponent(planeMesh);
        planeEntity->addComponent(planeTransform);
        planeEntity->addComponent(material);
    
        auto geometry = planeMesh->geometry(); // null
        for (auto attribute : geometry->attributes())
        {
            // ...
        }
    
        return rootEntity;
    }
    
    int main(int argc, char* argv[])
    {
        QGuiApplication app(argc, argv);
        Qt3DExtras::Qt3DWindow view;
    
        Qt3DCore::QEntity* scene = createScene();
    
        // Camera
        Qt3DRender::QCamera* camera = view.camera();
        camera->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);
        camera->setPosition(QVector3D(0, 0, 40.0f));
        camera->setViewCenter(QVector3D(0, 0, 0));
    
        // For camera controls
        Qt3DExtras::QOrbitCameraController* camController = new Qt3DExtras::QOrbitCameraController(scene);
        camController->setLinearSpeed(50.0f);
        camController->setLookSpeed(180.0f);
        camController->setCamera(camera);
    
        view.setRootEntity(scene);
        view.show();
    
        return app.exec();
    }
    

    I used the code on the following page as a reference, but does it not work with the current version? Or is there some additional processing that needs to be added?
    https://stackoverflow.com/questions/65886488/qt3d-can-i-list-all-vertexes-from-qt3drenderqgeometryrenderer

    U 1 Reply Last reply
    0
    • U ugonight

      I am using Qt 6.7.0.

      I want to get the coordinates of the four corners of a QPlaneMesh, but QPlaneMesh::geometry() is NULL.

      #include <QGuiApplication>
      
      #include <Qt3DInput/QInputAspect>
      
      #include <Qt3DRender>
      #include <Qt3DExtras>
      #include <Qt3DCore>
      
      Qt3DCore::QEntity* createScene()
      {
          // Root entity
          Qt3DCore::QEntity* rootEntity = new Qt3DCore::QEntity;
      
          // Material
          auto material = new Qt3DExtras::QPhongMaterial(rootEntity);
      
          // Plane
          auto planeEntity = new Qt3DCore::QEntity(rootEntity);
          auto planeMesh = new Qt3DExtras::QPlaneMesh;
          planeMesh->setWidth(5);
          planeMesh->setHeight(5);
      
          auto planeTransform = new Qt3DCore::QTransform;
          planeTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 45.0f));
      
          planeEntity->addComponent(planeMesh);
          planeEntity->addComponent(planeTransform);
          planeEntity->addComponent(material);
      
          auto geometry = planeMesh->geometry(); // null
          for (auto attribute : geometry->attributes())
          {
              // ...
          }
      
          return rootEntity;
      }
      
      int main(int argc, char* argv[])
      {
          QGuiApplication app(argc, argv);
          Qt3DExtras::Qt3DWindow view;
      
          Qt3DCore::QEntity* scene = createScene();
      
          // Camera
          Qt3DRender::QCamera* camera = view.camera();
          camera->lens()->setPerspectiveProjection(45.0f, 16.0f / 9.0f, 0.1f, 1000.0f);
          camera->setPosition(QVector3D(0, 0, 40.0f));
          camera->setViewCenter(QVector3D(0, 0, 0));
      
          // For camera controls
          Qt3DExtras::QOrbitCameraController* camController = new Qt3DExtras::QOrbitCameraController(scene);
          camController->setLinearSpeed(50.0f);
          camController->setLookSpeed(180.0f);
          camController->setCamera(camera);
      
          view.setRootEntity(scene);
          view.show();
      
          return app.exec();
      }
      

      I used the code on the following page as a reference, but does it not work with the current version? Or is there some additional processing that needs to be added?
      https://stackoverflow.com/questions/65886488/qt3d-can-i-list-all-vertexes-from-qt3drenderqgeometryrenderer

      U Offline
      U Offline
      ugonight
      wrote on last edited by ugonight
      #2

      It was possible to obtain it via the QGeometryView class like planeMesh->view()->geometry().

      1 Reply Last reply
      0
      • U ugonight has marked this topic as solved on

      • Login

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