How to properly use QSkyBoxEntity?

187 views Asked by At

I looked everywhere, but there are not any guides or explanations of how to use QSkyBoxEntity.

I created Entity and filled it with transform (set translation and 3d scale). Also changed name and extension.

When I'm trying to run program it says

"Qt3D.Renderer.OpenGL.Backend: Unable to find suitable Texture Unit for "skyboxTexture""

I checked several times and tried different png files but no luck.
My image
(I know it's fake transparency, but it shouldn't change anything, right?)

And here's part of a code:

Qt3DCore::QEntity *resultEntity = new Qt3DCore::QEntity;

    Qt3DExtras::QSkyboxEntity *skyboxEntity = new Qt3DExtras::QSkyboxEntity(resultEntity);
    skyboxEntity->setBaseName("skybox"); //I tried using path as well
    skyboxEntity->setExtension("png");

    Qt3DCore::QTransform *skyTransform = new Qt3DCore::QTransform(skyboxEntity);
    skyTransform->setTranslation(QVector3D(0.0f,0.0f,0.0f));
    skyTransform->setScale3D(QVector3D(0.1f,0.1f,0.1f));

    skyboxEntity->addComponent(skyTransform);
2

There are 2 answers

0
Volodymyr On BEST ANSWER

It's important to properly name files in order for skybox to work and use resource file for storing.

I recommend .tga, but other formats should work as well.

You can read about it here: https://doc.qt.io/qt-6/qml-qt3d-extras-skyboxentity.html

And here's example how it should look

3
Florian Blume On

Looks like it's not finding the skybox texture. Did you use an absolute path when you say "I tried using path as well"? The path you set is relative to the build path, i.e. it's not where your C++ file lies.

Alternatively, you could use a resources file and then load then image using

"qrc:/[prefix]/[filename without extension]"

You can also check out the Qt3D manual SkyBox test here:

https://github.com/qt/qt3d/tree/dev/tests/manual/skybox