Qt Quick 3D旨在让那些熟悉QML开发的人能够使用非常少的学习成本实现3D开发,因此对于三维模型动画没有类似与Qt 3D中有个专门的Qt3DAnimation来控制动画效果,而是直接使用QML中的Animation对三维模型中属性进行控制,是不是很赞,下面介绍如何使用NumberAnimation控制摄像机自动旋转。效果如图:
源码:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick3D 1.15
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello Qt Quick 3D")
View3D {
id: view3D
anchors.fill: parent
environment: sceneEnvironment
SceneEnvironment {
id: sceneEnvironment
antialiasingQuality: SceneEnvironment.High
antialiasingMode: SceneEnvironment.MSAA
}
Node {
id: node
DirectionalLight {
id: directionalLight
}
Model {
id: cubeModel
source: "test.mesh"
DefaultMaterial {
id: cubeMaterial
diffuseColor: "#4aee45"
}
materials: cubeMaterial
}
}
Node{
id:cameraNode
PerspectiveCamera {
id: camera
z: 15
}
NumberAnimation {
id:camerAnimation
target: cameraNode
property: "eulerRotation.y"
duration: 5000
from: 0
to: -360
loops: Animation.Infinite
running: true
}
}
}
}
如果还需要添加一些控制功能,还可以添加SequentialAnimation和ParallelAnimation实现动画的组合效果,3D开发大门已经开启,尽情的展现你的才华吧!
示例工程GitHub地址:https://github.com/zjgo007/QtQuick3D/tree/master/Animation3dModel