A weird bug? Why is there no spatial depth in my 3D scene?
-
@Finn said in A weird bug? Why is there no spatial depth in my 3D scene?:
Maybe this is the origin of my problems?
It's certainly possble.
sudo make install
Why do that? Your distro already provides a Qt release so my suspicion is there are some files (partially) overwritten. What I suggest is to reinstall you distro's Qt (by means of the package manager), then to configure the Qt you downloaded with a prefix (don't forget to
make clean
before doing the configure, or even to delete the whole folder and recreate it through the Qt installer), e.g.:./configure -prefix /opt/Qt-5.7
make
and then it's safe tomake install
, because the files will go to/opt/Qt-5.7
.
Then you can configure a kit in creator (assuming this is what you use) that will use this version of Qt (in/opt/Qt-5.7
).wrote on 22 Dec 2016, 14:10 last edited by@kshegunov No, I completely reinstalled everything to the folder
/opt/Qt-5.7
by following your instructions and those in the tutorial (https://wiki.qt.io/Install_Qt_5_on_Ubuntu). Before, I deleted everything but the result is the same. So far I usedCLion2016
and now I also tried theQtCreator
- still the same outcome.I also added some axes (x=red, y=green, z=blue), which are instantiated after the spheres.
Other ideas?
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* bigRedSphere = 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)); bigRedSphere->addComponent(redMaterial); bigRedSphere->addComponent(bigMesh); smallGreenSphere->addComponent(greenMaterial); smallGreenSphere->addComponent(smallMesh); smallGreenSphere->addComponent(transform); Qt3DCore::QEntity* xaxis = new Qt3DCore::QEntity(root); Qt3DCore::QEntity* yaxis = new Qt3DCore::QEntity(root); Qt3DCore::QEntity* zaxis = new Qt3DCore::QEntity(root); Qt3DExtras::QCylinderMesh* cylinderMesh = new Qt3DExtras::QCylinderMesh; cylinderMesh->setRadius(0.2); cylinderMesh->setLength(20); cylinderMesh->setRings(100); cylinderMesh->setSlices(20); Qt3DExtras::QPhongMaterial* blueMaterial = new Qt3DExtras::QPhongMaterial; blueMaterial->setSpecular(Qt::white); blueMaterial->setShininess(10); blueMaterial->setAmbient(Qt::blue); double pi = 3.14159265359; Qt3DCore::QTransform* xTransform = new Qt3DCore::QTransform(); xTransform->setTranslation(QVector3D(10,0,0)); xTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0,0,1),90)); Qt3DCore::QTransform* yTransform = new Qt3DCore::QTransform(); yTransform->setTranslation(QVector3D(0,10,0)); Qt3DCore::QTransform* zTransform = new Qt3DCore::QTransform(); zTransform->setTranslation(QVector3D(0,0,10)); zTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),90)); xaxis->addComponent(cylinderMesh); xaxis->addComponent(redMaterial); xaxis->addComponent(xTransform); yaxis->addComponent(cylinderMesh); yaxis->addComponent(greenMaterial); yaxis->addComponent(yTransform); zaxis->addComponent(cylinderMesh); zaxis->addComponent(blueMaterial); zaxis->addComponent(zTransform); 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(45,15,45)); 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(); }
CMakeLists.txt
cmake_minimum_required(VERSION 3.2) project(QtCreatorTest) find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets 3DCore 3DExtras 3DRender 3DInput ) add_executable("${PROJECT_NAME}_main" main.cpp) target_link_libraries("${PROJECT_NAME}_main" Qt5::Core Qt5::Gui Qt5::Widgets Qt5::3DCore Qt5::3DExtras Qt5::3DRender Qt5::3DInput )
-
@kshegunov No, I completely reinstalled everything to the folder
/opt/Qt-5.7
by following your instructions and those in the tutorial (https://wiki.qt.io/Install_Qt_5_on_Ubuntu). Before, I deleted everything but the result is the same. So far I usedCLion2016
and now I also tried theQtCreator
- still the same outcome.I also added some axes (x=red, y=green, z=blue), which are instantiated after the spheres.
Other ideas?
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* bigRedSphere = 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)); bigRedSphere->addComponent(redMaterial); bigRedSphere->addComponent(bigMesh); smallGreenSphere->addComponent(greenMaterial); smallGreenSphere->addComponent(smallMesh); smallGreenSphere->addComponent(transform); Qt3DCore::QEntity* xaxis = new Qt3DCore::QEntity(root); Qt3DCore::QEntity* yaxis = new Qt3DCore::QEntity(root); Qt3DCore::QEntity* zaxis = new Qt3DCore::QEntity(root); Qt3DExtras::QCylinderMesh* cylinderMesh = new Qt3DExtras::QCylinderMesh; cylinderMesh->setRadius(0.2); cylinderMesh->setLength(20); cylinderMesh->setRings(100); cylinderMesh->setSlices(20); Qt3DExtras::QPhongMaterial* blueMaterial = new Qt3DExtras::QPhongMaterial; blueMaterial->setSpecular(Qt::white); blueMaterial->setShininess(10); blueMaterial->setAmbient(Qt::blue); double pi = 3.14159265359; Qt3DCore::QTransform* xTransform = new Qt3DCore::QTransform(); xTransform->setTranslation(QVector3D(10,0,0)); xTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0,0,1),90)); Qt3DCore::QTransform* yTransform = new Qt3DCore::QTransform(); yTransform->setTranslation(QVector3D(0,10,0)); Qt3DCore::QTransform* zTransform = new Qt3DCore::QTransform(); zTransform->setTranslation(QVector3D(0,0,10)); zTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1,0,0),90)); xaxis->addComponent(cylinderMesh); xaxis->addComponent(redMaterial); xaxis->addComponent(xTransform); yaxis->addComponent(cylinderMesh); yaxis->addComponent(greenMaterial); yaxis->addComponent(yTransform); zaxis->addComponent(cylinderMesh); zaxis->addComponent(blueMaterial); zaxis->addComponent(zTransform); 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(45,15,45)); 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(); }
CMakeLists.txt
cmake_minimum_required(VERSION 3.2) project(QtCreatorTest) find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets 3DCore 3DExtras 3DRender 3DInput ) add_executable("${PROJECT_NAME}_main" main.cpp) target_link_libraries("${PROJECT_NAME}_main" Qt5::Core Qt5::Gui Qt5::Widgets Qt5::3DCore Qt5::3DExtras Qt5::3DRender Qt5::3DInput )
Moderatorswrote on 22 Dec 2016, 16:08 last edited by kshegunov 7 May 2018, 13:16@Finn
This is really strange. I ran your code and it works perfectly fine for me (I use qmake with a kit for Qt 5.7 though). Here's what I see:
And my project file is absolutely standard:
QT += core gui 3dcore 3drender 3dextras TARGET = balls-test TEMPLATE = app SOURCES += main.cpp
[Edit: Fixed broken link]
-
@Finn
This is really strange. I ran your code and it works perfectly fine for me (I use qmake with a kit for Qt 5.7 though). Here's what I see:
And my project file is absolutely standard:
QT += core gui 3dcore 3drender 3dextras TARGET = balls-test TEMPLATE = app SOURCES += main.cpp
[Edit: Fixed broken link]
wrote on 23 Dec 2016, 10:59 last edited by@kshegunov I tried using
qmake
for building but again the same outcome. -
@kshegunov I tried using
qmake
for building but again the same outcome.Honestly, I'd be surprised if there was a difference between using
cmake
andqmake
. And to be completely frank I don't know what might be the cause of the problem. My current best advice is to either bring the question to the mailing list, where hopefully one of the developers of Qt3D will pick it up (but after you check there's no open bugs on this), or try and wait for some other suggestion from other of our members here.Kind regards.
-
Honestly, I'd be surprised if there was a difference between using
cmake
andqmake
. And to be completely frank I don't know what might be the cause of the problem. My current best advice is to either bring the question to the mailing list, where hopefully one of the developers of Qt3D will pick it up (but after you check there's no open bugs on this), or try and wait for some other suggestion from other of our members here.Kind regards.
wrote on 30 Dec 2016, 12:06 last edited by FinnI tried it on my private MacBook Pro with MacOS Sierra 10.12.1 and installed Qt5 via
brew install qt5
. The result is still the same. What on earth can be the reason that it is working for you guys and not for me? Do I need some other libraries or build options? -
wrote on 30 Dec 2016, 20:22 last edited by
-
Sorry, as a noobie, I can't offer any insight, but I ran the code, and I'm getting the same as Finn. I'm on Qt 5.7 on Win 10.
Could it be CPU or GPU related? I'm on a 6coreAMD machine.
wrote on 30 Dec 2016, 20:56 last edited by@Ian-Bray Thank you for your reply, this was very helpful! I would suggest that someone more experienced than me should report this as a bug.
-
@Ian-Bray Thank you for your reply, this was very helpful! I would suggest that someone more experienced than me should report this as a bug.
@Finn said in A weird bug? Why is there no spatial depth in my 3D scene?:
this was very helpfu
Indeed, it was.
I would suggest that someone more experienced than me should report this as a bug.
There's nothing to it, you just describe the problem and attach the screenshots and the code from upstairs as a minimal reproducible example (preferably with a simple project file). As for the problem itself it may be helpful if we can squeeze some more information out. I may be running a newer (or older) version of Qt compared to you. Can you both state the full version (with patch number). I'm running Qt 5.7.2 built from git some time ago on a Linux 4.8.11 kernel.
-
@Finn said in A weird bug? Why is there no spatial depth in my 3D scene?:
this was very helpfu
Indeed, it was.
I would suggest that someone more experienced than me should report this as a bug.
There's nothing to it, you just describe the problem and attach the screenshots and the code from upstairs as a minimal reproducible example (preferably with a simple project file). As for the problem itself it may be helpful if we can squeeze some more information out. I may be running a newer (or older) version of Qt compared to you. Can you both state the full version (with patch number). I'm running Qt 5.7.2 built from git some time ago on a Linux 4.8.11 kernel.
wrote on 30 Dec 2016, 22:43 last edited byI'm using qt-opensource-windows-x86-mingw530-5.7.0 on Win 10, if I get a chance I'll try it on Linux later.
-
wrote on 31 Dec 2016, 14:00 last edited by
Sorry, this isn't going to be helpful. Just to report that both slabs of code crashed on Qt 5.7.1 GCC 64 on latest Mint.
Possibly due to lack of RAM. Not sure. -
Sorry, this isn't going to be helpful. Just to report that both slabs of code crashed on Qt 5.7.1 GCC 64 on latest Mint.
Possibly due to lack of RAM. Not sure.wrote on 3 Jan 2017, 07:59 last edited by@Ian-Bray With Qt 5.7.1 the example works now perfectly fine for me.
-
Then probably it's a bug that was fixed with the patch version in the meantime. Cheers!
-
wrote on 3 Jan 2017, 12:57 last edited by
@Finn Thanks Finn. I'll update later!
-
wrote on 5 Jan 2017, 15:20 last edited by
@kshegunov Must have been quite a big one. I ran the 3d Materials Example on 5.7.0 two days ago - it was horrible. I updated to 5.7.1 yesterday and ran it again - works perfect now.
-
@kshegunov Must have been quite a big one. I ran the 3d Materials Example on 5.7.0 two days ago - it was horrible. I updated to 5.7.1 yesterday and ran it again - works perfect now.
Well, 5.7.0 was Qt3D's first official release, and the code hasn't matured as much as the other modules, so some bumps along the road are expected. My biggest beef with Qt3D actually is its very thin documentation, but I'm sure that'll improve with time.:)
-
I want to use
Qt3D
withinQt5.7
to plot a 3D scene (a chemical molecule) which I want to rotate.
The problem is that my 3D objects are not displayed according to their spatial positioning. The last createdQEntity
is always in the foreground, regardless of how I rotate the camera.
In the minimum working example below, theQEntity
smallGreenSphere
is always in the foreground even though it is spatially positioned behindbigRedSphere
in the default view specified in the camera settings.
To rephrase the problem: My 3D scene has no depth.Please note that
smallGreenSphere
is instantiated afterbigRedSphere
in themain.cpp
file shown below:#include <QGuiApplication> #include <Qt3DCore> #include <Qt3DRender> #include <Qt3DExtras> Qt3DCore::QEntity* createTestScene() { Qt3DCore::QEntity* root = new Qt3DCore::QEntity; Qt3DCore::QEntity* bigRedSphere = new Qt3DCore::QEntity(root); Qt3DCore::QEntity* smallGreenSphere = 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)); bigRedSphere->addComponent(redMaterial); bigRedSphere->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(); }
This results in the following scene:
Please note that I did not rotate anything manually and that this is the output of the code above.If I now swap the order of instantiation in
createTestScene()
byQt3DCore::QEntity* smallGreenSphere = new Qt3DCore::QEntity(root); Qt3DCore::QEntity* bigRedSphere = new Qt3DCore::QEntity(root);
so that
bigRedSphere
is now instantiated aftersmallGreenSphere
, thebigRedSphere
is always in the foreground and the resulting scene (again without manual rotation) looks like this:This proves that the order of instantiation determines what sphere is displayed in the foreground.
How can I obtain the correct 3D view regardless of the order of instantiation? Do I have to use some different rendering technique?
Thanks in advance for your help and please consider that I am new to Qt, Qt3D, and rendering in your answer.wrote on 31 Dec 2019, 13:05 last edited byFor further reference this issue seems solved as described in this post.