florianblume / Qt3D-OffscreenRenderer

This project is based on the Qt 3D basic shapes C++ example.
GNU General Public License v3.0
56 stars 17 forks source link

Doesn't display correctly #5

Open ArMaxik opened 5 years ago

ArMaxik commented 5 years ago

Hi, i'm trying to run your code, just replace MainWidget::MainWidget(QWidget *parent) like this:

MainWidget::MainWidget(QWidget *parent) : QWidget(parent)
{
    setWindowTitle(QStringLiteral("Basic shapes"));

    QLabel *graphicsLabel = new QLabel();
    graphicsLabel->setGeometry(QRect(0, 0, 400, 400));
    graphicsLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    QPushButton *genButton = new QPushButton();
    genButton->setText("Generate");
    genButton->setMaximumWidth(100);

    QHBoxLayout *hLayout = new QHBoxLayout(this);
    hLayout->addWidget(graphicsLabel, 1);
    hLayout->addWidget(genButton);

    Qt3DCore::QEntity *rootEntity = new  Qt3DCore::QEntity();

    Qt3DRender::QCamera *cameraEntity = new Qt3DRender::QCamera(rootEntity);
    cameraEntity->lens()->setPerspectiveProjection(45.0f, 1.0, 0.1f, 1000.0f);
    cameraEntity->setPosition(QVector3D(0, 20.0, 0));
    cameraEntity->setViewCenter(QVector3D(0, 0, 0));

    // Set up a light to illuminate the shapes.
    Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity);
    Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity);
    light->setColor("white");
    light->setIntensity(1);
    lightEntity->addComponent(light);
    Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity);
    lightTransform->setTranslation(cameraEntity->position());
    lightEntity->addComponent(lightTransform);
    // Plane
    Qt3DExtras::QPlaneMesh *plane = new Qt3DExtras::QPlaneMesh();
    plane->setWidth(2.0);
    plane->setHeight(2.0);

    Qt3DCore::QTransform *planeTr = new Qt3DCore::QTransform();
    planeTr->setScale(5.0);
    planeTr->setRotationX(19);
    planeTr->setRotationY(13);
    planeTr->setRotationZ(10);
    // Material
    Qt3DExtras::QPhongMaterial *mat = new Qt3DExtras::QPhongMaterial();
    mat->setDiffuse(Qt::green);
    // Plane ent
    Qt3DCore::QEntity *planeEnt = new  Qt3DCore::QEntity(rootEntity);
    planeEnt->addComponent(plane);
    planeEnt->addComponent(planeTr);
    planeEnt->addComponent(mat);

    // Create the offscreen engine. This is the object which is responsible for handling the 3D scene itself.
    offscreenEngine = new OffscreenEngine(cameraEntity, QSize(1200, 800));

    // The offscreen engine delegate handles requesting frames from the engine, and drawing their results in the graphics label.
    offscreenEngineDelegate = new OffscreenEngineDelegate(offscreenEngine, graphicsLabel);

    // Set our scene to be rendered by the offscreen engine.
    offscreenEngine->setSceneRoot(rootEntity);
}

And i get big green strip over the plane image: image It's doesn't work and with other rotations of plane. Can you help please? I've spent a lot of time and did't find what's wrong.

ArMaxik commented 5 years ago

i've just found out, that this bug also present in yours example. If you move any entity to 0 0 0 point, rotate and scale it, for example, like this:

// scenemodifier.cpp
cylinderTransform->setScale(1.0f);
cylinderTransform->setRotationX(13);
cylinderTransform->setRotationY(-6);
cylinderTransform->setRotationZ(-1);
cylinderTransform->setTranslation(QVector3D(0.0f, 0.0f, 0.0));

You see the same issue image

florianblume commented 5 years ago

I don't have time to look into this issue at the moment as I'm currently writing my master's thesis. One thing you could try is to add the objects in the same manner to the original basic shapes example.

florianblume commented 4 years ago

I just read your issue again and feel like I've experienced this bug in other contexts (i.e. without offscreen rendering), too. Is there any update from your side on this? Might be fixed in newer Qt versions.

kaajo commented 1 year ago

Tested on Qt 5.15.2 and the bug is still there. Some remarks:

florianblume commented 1 year ago

I remember I had a similar issue somewhere else and the solution in the link you posted to add a QNoDraw node worked back then but it doesn't seem to do the trick here in this case which.

kaajo commented 1 year ago

I will prepare a PR. I think I have found a solution.