为什么最后创建的 Qt3DCore::QEntity 总是在我的场景视图的前景中?

Why is the last created Qt3DCore::QEntity always in the foreground of my scene view?

在我的Qt3D场景中,我的 3D 对象没有根据它们的空间定位显示。最后创建的 QEntity 总是在前景中,无论我如何旋转相机。 在我的示例中,QEntity redBigSphere 始终位于前景,即使在相机设置中指定的默认视图中它在空间上位于 smallGreenSphere 之后。

main.cpp:

#include <QGuiApplication>
#include <Qt3DCore>
#include <Qt3DRender>
#include <Qt3DExtras>

Qt3DCore::QEntity* createTestScene() {

  Qt3DCore::QEntity* root = new Qt3DCore::QEntity;
  Qt3DCore::QEntity* smallGreenSphere = new Qt3DCore::QEntity(root);
  Qt3DCore::QEntity* redBigSphere = new Qt3DCore::QEntity(root);

  Qt3DExtras::QSphereMesh* bigMesh = new Qt3DExtras::QSphereMesh;
  bigMesh->setRadius(5);
  bigMesh->setRings(100);
  bigMesh->setSlices(20);

  Qt3DExtras::QSphereMesh* smallMesh = new Qt3DExtras::QSphereMesh;
  smallMesh->setRadius(2);
  smallMesh->setRings(100);
  smallMesh->setSlices(20);

  Qt3DExtras::QPhongMaterial* redMaterial = new Qt3DExtras::QPhongMaterial;
  redMaterial->setSpecular(Qt::white);
  redMaterial->setShininess(10);
  redMaterial->setAmbient(Qt::red);

  Qt3DExtras::QPhongMaterial* greenMaterial = new Qt3DExtras::QPhongMaterial;
  greenMaterial->setSpecular(Qt::white);
  greenMaterial->setShininess(10);
  greenMaterial->setAmbient(Qt::green);

  Qt3DCore::QTransform* transform =  new Qt3DCore::QTransform;
  transform->setTranslation(QVector3D(0,0,10));

  redBigSphere->addComponent(redMaterial);
  redBigSphere->addComponent(bigMesh);

  smallGreenSphere->addComponent(greenMaterial);
  smallGreenSphere->addComponent(smallMesh);
  smallGreenSphere->addComponent(transform);

  return root;
}


int main(int argc, char* argv[]) {

  QGuiApplication app(argc, argv);
  Qt3DExtras::Qt3DWindow view;
  Qt3DCore::QEntity* scene = createTestScene();

  // camera
  Qt3DRender::QCamera *camera = view.camera();
  camera->lens()->setPerspectiveProjection(45, 16./9., 0.1,1000.);
  camera->setPosition(QVector3D(30., 0, 60.));
  camera->setViewCenter(QVector3D(0, 0, 0));

  // manipulator
  Qt3DExtras::QOrbitCameraController* manipulator = new Qt3DExtras::QOrbitCameraController(scene);
  manipulator->setLinearSpeed(50);
  manipulator->setLookSpeed(180);
  manipulator->setCamera(camera);

view.setRootEntity(scene);

view.show();

return app.exec();
}

(结果图片:http://imgur.com/a/A7tIW

如果我交换实例化的顺序,smallGreenSphere总是在前台。

Qt3DCore::QEntity* redBigSphere = new Qt3DCore::QEntity(root);
Qt3DCore::QEntity* smallGreenSphere = new Qt3DCore::QEntity(root);

(结果图片:http://imgur.com/a/fygTU

无论实例化顺序如何,如何获得正确的 3D 视图?

我是 Qt 和 Qt3D 的新手,所以请在您的回答中考虑这一点。 (由于我名气不大,只能提供图片链接。)

我在 Qt 论坛上更详细地发布了这个问题,人们可以在那里复制它。 https://forum.qt.io/topic/74419/a-weird-bug-why-is-there-no-spatial-depth-in-my-3d-scene/24

这个问题似乎与 Qt5.7.0 有关。但是,Qt5.7.1 现在对我来说效果很好。