Qt3d svg 或 png 纹理,不透明度 = 0 QPlaneMesh 上的 QTextureMaterial

Qt3d svg or png Texture with opacity=0 QTextureMaterial on QPlaneMesh

我尝试将包含opacity=0 区域的svg 图像添加到QPlaneMesh 上的QTextureMaterial 中,但它显示Plane 的背景始终为灰色。

我希望飞机能捕捉到我的图像并穿透到opacity=0区域的其他物体。

svg 文件如 https://image.flaticon.com/icons/svg/3154/3154348.svg .

代码:

// Background
        Qt3DCore::QEntity *planeEntity = new Qt3DCore::QEntity(rootEntity);
        Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh(planeEntity);
        planeMesh->setHeight(2);
        planeMesh->setWidth(2);

        Qt3DExtras::QTextureMaterial *planeMaterial = new Qt3DExtras::QTextureMaterial(planeEntity);
        Qt3DRender::QTexture2D *planeTexture = new Qt3DRender::QTexture2D(planeMaterial);
        FlippedTextureImage *planeTextureImage = new FlippedTextureImage(planeTexture);
        planeTextureImage->setSize(QSize(3507, 3000));
        planeTexture->addTextureImage(planeTextureImage);
        planeMaterial->setTexture(planeTexture);

        Qt3DCore::QTransform *planeTransform = new Qt3DCore::QTransform(planeEntity);
        planeTransform->setRotationX(90);
        planeTransform->setTranslation(QVector3D(0, 0, 0));

        Qt3DExtras::QPhongAlphaMaterial *pam2 = new Qt3DExtras::QPhongAlphaMaterial(planeEntity);
        pam2->setAlpha(0);

        planeEntity->addComponent(planeMesh);
        planeEntity->addComponent(pam2);
        planeEntity->addComponent(planeMaterial);
        planeEntity->addComponent(planeTransform);
class FlippedTextureImage : public Qt3DRender::QPaintedTextureImage
{
public:
    FlippedTextureImage(Qt3DCore::QNode *parent = Q_NULLPTR):Qt3DRender::QPaintedTextureImage(parent) {}
    void paint(QPainter *painter) override {
        QSvgRenderer renderer(QString(qApp->applicationDirPath() + "/gift.svg"));
        QImage image(3000, 3000, QImage::Format_RGBA64);  // 512x512 RGBA
        image.fill(0x00ffffff);                           // white background
        QPainter painter2(&image);
        renderer.render(&painter2);
        painter->drawImage(0, 0, image);
    }
};

and run code like this

QTextureMaterial 不支持纹理中的透明度。

查看 了解如何自己实现纹理透明度。 Qt3D 中没有开箱即用的解决方案。