Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't display correctly #5

Open
ArMaxik opened this issue Jul 9, 2019 · 6 comments · May be fixed by #8
Open

Doesn't display correctly #5

ArMaxik opened this issue Jul 9, 2019 · 6 comments · May be fixed by #8

Comments

@ArMaxik
Copy link

ArMaxik commented Jul 9, 2019

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 ArMaxik changed the title Don't Doesn't display correctly Jul 9, 2019
@ArMaxik
Copy link
Author

ArMaxik commented Jul 9, 2019

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
Copy link
Owner

florianblume commented Jul 11, 2019

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
Copy link
Owner

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
Copy link

kaajo commented Nov 16, 2022

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

@florianblume
Copy link
Owner

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
Copy link

kaajo commented Nov 16, 2022

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

@kaajo kaajo linked a pull request Nov 20, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants