【问题标题】:Transparent object in QT3DQT3D中的透明对象
【发布时间】:2017-06-30 09:01:43
【问题描述】:

我需要能够在 QT3D 中更改网格对象的透明度。我使用 Scene3D 组件作为包含默认 ForwardRenderer 的根。

components: [
    RenderSettings {
        activeFrameGraph: ForwardRenderer {
            clearColor: Qt.rgba(0, 0, 0, 1)
            camera: camera


        }
    },
    // Event Source will be set by the Qt3DQuickWindow
    InputSettings { }
]

我的 3D 对象由 Mesh、Transform 和 PhongMaterial 组成。

任何帮助将不胜感激。

【问题讨论】:

    标签: qt qml qt5 qt3d


    【解决方案1】:

    代码没问题。您可以更改模型以查看效果。完整代码为:

    import QtQuick 2.0
    import QtQuick.Controls 1.4
    import QtQuick.Layouts 1.2
    import QtQuick.Dialogs 1.2
    import QtQuick.Scene3D 2.0
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Extras 2.0
    import Qt3D.Input 2.0 
    
    Teapot{
        x: 0; y:0; z:0;
        material: PhongAlphaMaterial{
            ambient: Qt.rgba( 1, 0, 0, 1.0 )
            diffuse: Qt.rgba( 1, 0, 0, 1.0 )
            specular: Qt.rgba(1, 0, 0, 1.0 )
            shininess: 1.0
            alpha: 0.5
        }
    }
    

    茶壶图片

    【讨论】:

    • 非常感谢您的帮助。代码实际上是完全正确的。我发现了这个问题。我的构建基于 QT5.7.0,我的 3D 实体在 Scene3D 中呈现。当在 Scene3D 中使用 PhongAlphaMaterial 时,我发现 QT 5.7.0 中存在一个已知错误。我采用了代码库并在 QT5.8 中构建它,它运行良好。非常感谢您的帮助。
    • 不客气! Qt 3D 正在开发中,并且经常更改它的 api 来修复错误。现在安装 Qt 5.9.1 是个不错的选择:-)
    【解决方案2】:

    只需使用 PhongAlphaMaterial:

    PhongAlphaMaterial{
        id: redMaterial
        ambient: Qt.rgba( 1, 0, 0, 1.0 )
        diffuse: Qt.rgba( 1, 0, 0, 1.0 )
        specular: Qt.rgba(1, 0, 0, 1.0 )
        shininess: 1.0
        alpha: 0.4
    }
    

    【讨论】:

    • 好的,我会尝试并回复您。非常感谢。
    • 我刚刚尝试了 PhongAlphaMaterial 但它导致我的对象只是显示为黑色。它有一个非常小的物体红色轮廓
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多