Qt 3D tutorial (4) combined with Qt Quick to achieve the animation effect, qtquick
Qt 3D tutorial (4) combining Qt Quick for animation effect
The previous tutorial has brought you more practical results. This time we try to load two models and make PhongMaterial their shared material. In addition, with the help of the Qt Quick animation framework, we can make our 3D scenes dynamic!
Jiang caiyang's original article, first published at: http://blog.csdn.net/gamesdev/article/details/47132099. Welcome to the discussion.
This change is not as great as the previous one. You only need to modify main. qml to achieve the effect. The main. qml file is as follows:
import Qt3D 2.0import Qt3D.Renderer 2.0import QtQuick 2.5 as QuickEntity{ id: root Camera { id: camera position: Qt.vector3d( 0.0, 20.0, 100.0 ) projectionType: CameraLens.PerspectiveProjection fieldOfView: 45 aspectRatio: 16.0 / 9.0 nearPlane : 0.1 farPlane : 1000.0 upVector: Qt.vector3d( 0.0, 1.0, 0.0 ) viewCenter: Qt.vector3d( 0.0, 20.0, 0.0 ) } components: FrameGraph { ForwardRenderer { clearColor: Qt.rgba( 0.2, 0, 0, 1 ) camera: camera } } PhongMaterial { id: phongMaterial ambient: _settings.ambient diffuse: _settings.diffuse specular: _settings.specular shininess: _settings.shininess } Entity { Mesh { id: chestMesh source: "qrc:/assets/Chest.obj" enabled: _settings.showModel } components: [ chestMesh, phongMaterial ] } Entity { Mesh { id: trefoilMesh source: "qrc:/assets/trefoil.obj" enabled: _settings.showModel } Transform { id: transform Translate { translation: Qt.vector3d( 0, 30, 50 ) } Rotate { axis: Qt.vector3d( 0, 1, 0 ) Quick.NumberAnimation on angle { from: 0 to: 360 loops: Quick.Animation.Infinite duration: 2000 running: true } } } components: [ trefoilMesh, phongMaterial, transform ] } Configuration { controlledCamera: camera }}
Here we propose PhongMaterial separately to make it a shared material. In addition, we add another model, the clover ring model, and perform a series of transformations for it. I want to make this model rotate around the treasure chest model. So we introduced Qt Quick, and we made an animation for the rotating part, from 0 degrees to 360 degrees, and made an infinite loop. It is so simple that I can't wait to see the dynamic effect:
We can see that this ring model is rotated around the treasure chest model, and this effect is very appealing!
The code of this tutorial is in my github. interested colleagues can use git clone or directly download my git project to obtain all the source code of this tutorial.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.