Basket ExampleBasket in QMLThe QML version of the basket example is very similar in structure to the C++ version above, but much simpler. We start by defining a viewport with a specific camera position: import QtQuick 2.0 import Qt3D 1.0 Viewport { width: parent.width; height: parent.height fillColor: "#000000" camera: Camera { eye: Qt.vector3d(0, 4, 10) } We then add an Item3D object to load the basket model and apply the desired texture to it: Item3D { mesh: Mesh { source: "meshes/basket.bez" } effect: Effect { texture: "basket.jpg" } And then we apply an animation to the rotation component of the item's transform property: transform: [ Scale3D { scale: 1.5 }, Rotation3D { axis: Qt.vector3d(0, 1, 0) NumberAnimation on angle { running: true loops: Animation.Infinite from: 0 to: 360 duration: 2000 } } ] } } Basket in Qt3DThe Basket example shows how Qt3D can be used to draw an animated object covered in a texture. The basic application shell is similar to the Hello Teapot example. In this case, we create the basket object and add a texture to it as follows: QGLBuilder builder; builder << BasketPatches(); basket = builder.finalizedSceneNode(); QGLMaterial *mat = new QGLMaterial; QUrl url; url.setPath(QLatin1String(":/basket.jpg")); url.setScheme(QLatin1String("file")); mat->setTextureUrl(url); basket->setMaterial(mat); basket->setEffect(QGL::LitModulateTexture2D); For this animation, we want to spin the basket around its Y axis, once every 2 seconds. We first declare an angle property in the class declaration (calling update() will force the view to redraw whenever the angle changes): class BasketView : public QGLView { Q_OBJECT Q_PROPERTY(qreal angle READ angle WRITE setAngle) public: qreal angle() const { return m_angle; } void setAngle(qreal angle) { m_angle = angle; update(); } Then we create a QPropertyAnimation object that will update angle every time through the event loop with a new value between 0 and 360 degrees: QPropertyAnimation *animation; animation = new QPropertyAnimation(this, "angle", this); animation->setStartValue(0.0f); animation->setEndValue(360.0f); animation->setDuration(2000); animation->setLoopCount(-1); animation->start(); Now all we have to do is draw the basket using the angle property every time paintGL() is called: void BasketView::paintGL(QGLPainter *painter) { painter->modelViewMatrix().rotate(angle(), 0, 1, 0); painter->modelViewMatrix().scale(1.5f); basket->draw(painter); } Files: |