Как правильно визуализировать прозрачную сетку в QQuickView - PullRequest
0 голосов
/ 02 апреля 2019

Я хочу встроить сцену Qt3D с прозрачными объектами в приложение на основе виджетов, используя класс QQuickView.Визуализация высокопрозрачной сетки с Qt3D (DiffuseSpecularMaterial со значением альфа-канала диффузного цвета 0,1 и alphaBlending, установленной в true) в QQuickView, однако, приводит к почти непрозрачной черной (цвет qquickview) сетке вместо очень прозрачной сетки с цветомфон трехмерной сцены, см. изображение:

enter image description here

Изменение цвета быстрого просмотра (см. код C ++, quickView-> setColor (...)) изменяет цвет, в котором сходится прозрачная сетка.

код C ++ с использованием QQuickView

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

    QApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
    QApplication app(argc, argv);
    QMainWindow mainWindow;

    QWidget* viewersContainerWidget = new QWidget();
    QGridLayout* m_viewersLayout = new QGridLayout(viewersContainerWidget);
    m_viewersLayout->setContentsMargins(0, 0, 0, 0);

    QQuickView *quickView = new QQuickView();
    quickView->setSource(QUrl("qrc:/main.qml"));
    quickView->setResizeMode(QQuickView::SizeRootObjectToView);
    quickView->setColor("transparent");
    QWidget *container = QWidget::createWindowContainer(quickView);
    container->setMinimumSize(800, 800);
    m_viewersLayout->addWidget(container, 0, 1);
    mainWindow.setCentralWidget(viewersContainerWidget);

    mainWindow.resize(800, 600);
    mainWindow.show();

    return app.exec();
}

код QML

Item {
    id: root3DViewer
    Scene3D {
        id: scene3DRoot
        anchors.fill: parent
        aspects: ["input", "logic"]

        Entity {
            id: sceneRoot

            Camera {
                id: camera
                projectionType: CameraLens.PerspectiveProjection
                nearPlane : 0.01
                farPlane : 1000.0
                fieldOfView: 45
                position: Qt.vector3d(0,0,-20)
                viewCenter: Qt.vector3d(0,0,2.5)
            }

            OrbitCameraController {
                camera: camera
            }


            components: [
                RenderSettings {
                     ForwardRenderer {
                        camera: camera
                        clearColor: "black"
                    }
                },
                InputSettings {}
            ]

            Entity {
                DirectionalLight {
                    id:directionalLight
                    worldDirection: camera.viewVector
                }
                components: [directionalLight]
            }



            Entity {
                id: sphereEntity
                DiffuseSpecularMaterial {
                    id: sphereMaterial
                    diffuse: Qt.rgba(1,0,0,0.9)
                    alphaBlending: true
                }
                Transform {
                    id: sphereTransform
                    translation: Qt.vector3d(0,0,0)
                }

                SphereMesh {
                    id: sphereMesh
                    radius: 1
                }
            components: [sphereTransform, sphereMaterial,sphereMesh]
            }
            Entity {
                id: cylinderEntity
                DiffuseSpecularMaterial {
                    id: cylinderMaterial
                    diffuse: Qt.rgba(0,0,1,0.1)
                    alphaBlending: true
                }
                Transform {
                    id: cylinderTransform
                    translation: Qt.vector3d(0,0,5)
                }

                CylinderMesh {
                    id: cylinderMesh
                    length: 4
                    radius: 1
                }
            components: [cylinderTransform, cylinderMaterial,cylinderMesh]
            }

        }
    }
}

Использование Qt3DQuickWindow вместо этого работает как ожидалось (сеткастановится очень прозрачным и принимает цвет фона трехмерной сцены, см. правильный рендеринг:

enter image description here

C ++ с использованием Qt3DQuickWindow

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

    Qt3DExtras::Quick::Qt3DQuickWindow view;
    view.resize(1600, 800);
    view.engine()->qmlEngine()->rootContext()->setContextProperty("_window", &view);
    view.setSource(QUrl("qrc:/main.qml"));
    view.show();

    return app.exec();
}

Как я могу получить правильный рендеринг прозрачной сетки в QQuickView?

Спасибо

...