为了展示一个好看的3D模型,需要对模型设置背景,设置三维材质,设置周围光线,设置模型阴影等等。下面示例展示了一个比较好看的三维模型效果,大家可以先在C4D等调整好模型效果,然后将三维工程转换为.mesh和.qml,转换方法看我文章:Qt Quick 3D中将3D场景(如.obj)转换为.mesh
在该示例中简单的实现了鼠标控制三维模型位置和缩放,自定义背景图片,模型动画等,感兴趣的或者刚刚接触Qt Quick 3D开发的可以下载了看看。示例最终效果:
其中要注意的是,需要自定义背景图片时,需要设置View3D的背景色为透明,设置方法为:
Window {
width: 480
height: 450
visible: true
title: qsTr("Hello Qt Quick 3D")
color: "#00192e"
Image{
opacity: 0.3
anchors.fill: parent
source: "qrc:/bg1.png"
fillMode: Image.PreserveAspectCrop
}
View3D {
id: view3D
anchors.fill: parent
environment: SceneEnvironment {
id: sceneEnvironment
//需要设置3D视图背景透明
backgroundMode: SceneEnvironment.Transparent
clearColor: "transparent"
antialiasingQuality: SceneEnvironment.High
antialiasingMode: SceneEnvironment.MSAA
}
}
}
完整项目代码下载
GitHub:
https://github.com/zjgo007/QtQuick3D/tree/master/View3Dhttps://github.com/zjgo007/QtQuick3D/tree/master/View3DCSDN下载:https://download.csdn.net/download/zjgo007/80962858https://download.csdn.net/download/zjgo007/80962858