QPlaneMesh geometry is null
Solved
General and Desktop
-
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 -