KDAB on Qt: Overview of Qt3D 2.0 – Part 2

trefoil-wireframe

An Example of Rendering with Qt3D

In the previous article we learned about the requirements and high-level architecture of Qt3D 2.0. In order to put some of this into context and to give you a concrete example of how it looks to draw something in Qt3D using the QML API, we will now briefly show the important parts of one of the simple examples that will ship with Qt3D. We will start off simple and just draw a single entity (a trefoil knot) but to make it slightly more interesting we will use a custom set of shaders to implement a single-pass wireframe rendering method. This is what we will draw:

As mentioned in the previous article, the renderer aspect looks for entities that have some geometry, a material and optionally a transformation. These are all specified in the form of subclasses of QComponent which have been exported to the QML engine in the form of Mesh, Material and Transform respectively. So let’s use these components to make a custom QML item in TrefoilKnot.qml

import Qt3D 2.0
import Qt3D.Render 2.0

Entity {
    id: root

    property alias x: translation.dx
    property alias y: translation.dy
    property alias z: translation.dz
    property alias scale: scaleTransform.scale
    property alias theta: thetaRotation.angle
    property alias phi: phiRotation.angle
    property Material material

    components: [ transform, mesh, root.material ]

    Transform {
        id: transform
        Translate { id: translation }
        Scale { id: scaleTransform }
        Rotate{ id: thetaRotation; axis: Qt.vector3d( 1.0, 0.0, 0.0 ) }
        Rotate{ id: phiRotation;   axis: Qt.vector3d( 0.0, 1.0, 0.0 ) }
    }

    Mesh {
        id: mesh
        source: ":/assets/obj/trefoil.obj"
    }
}

Let’s break this down to see what’s going on here. We start off by importing the Qt3D 2.0 module that provides the Entity type and value type helpers like Qt.vector3d(). We also import the Qt3D.Render 2.0 module …read more

Source:: http://www.kdab.com/overview-qt3d-2-0-part-2/

      

Leave a Reply