Martin Smith
Martin Smith

Reputation: 63

Transparent object in QT3D

I need to be able to change the transparency of a mesh object in QT3D. I am using a Scene3D component as the root which contains a default ForwardRenderer.

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


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

My 3D object is made up of a Mesh, Transform and PhongMaterial.

Any help would be greatly appreciated.

Upvotes: 3

Views: 3058

Answers (2)

Surfsky
Surfsky

Reputation: 96

The code is ok. You can change your model to see the effect. The full code is:

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
    }
}

Teapot image

Upvotes: 2

Surfsky
Surfsky

Reputation: 96

Just use 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
}

Upvotes: 0

Related Questions