QT Quick 3D 渲染之场景构建(一)

发布时间:2026/11/2 6:11:49
QT Quick 3D 渲染之场景构建(一) main.qmlimport QtQuick import QtQuick3D import QtQuick3D.AssetUtils import QtQuick3D.Helpers import QtQuick3D.Particles3D import QtQuick3D.Xr import QtQuick.Controls // qt 6.8 Window { visible: true width: 640 height: 480 title: qsTr(3D scene) // predefine camera Node { id: standAloneScene Node { PerspectiveCamera { id: cameraPerspectiveOne z: 600 } PropertyAnimation on eulerRotation.x { loops: Animation.Infinite duration: 5000 to: -360 from: 0 } } PerspectiveCamera { id: cameraPerspectiveTwo position: Qt.vector3d(0, 200, 300) eulerRotation.x: -30 z: 600 } OrthographicCamera { id: cameraOrthographicLeft x: -600 eulerRotation.y: -90 } } Rectangle { id: topLeft anchors.top: parent.top anchors.left: parent.left width: parent.width * 0.5 height: parent.height * 0.5 color: #848895 border.color: black View3D { anchors.fill: parent camera: activeCamera // 使用相机 PerspectiveCamera { // 定义透视投影3D-2D相机 id: activeCamera z: 400 } DirectionalLight { // 光源 color: white eulerRotation.x: -30 // 欧拉角度 eulerRotation.y: -70 } Model { x: -100 source: #Cube // 内置Mesh materials: PrincipledMaterial { // 材质着色 baseColor: red } } Model { x: 100 source: #Sphere // 内置Mesh materials: PrincipledMaterial { // 材质着色 baseColor: green } } environment: SceneEnvironment { // 背景色 clearColor: skyblue backgroundMode: SceneEnvironment.Color } WasdController { // wasd键控制相机 controlledObject: activeCamera } } Label { text: Front anchors.top: parent.top anchors.left: parent.left anchors.margins: 10 color: #222840 font.pointSize: 14 } } Rectangle { id: topRight anchors.top: parent.top anchors.right: parent.right width: parent.width * 0.5 height: parent.height * 0.5 color: #848895 border.color: black View3D { id: topRightView anchors.fill: parent importScene: standAloneScene camera: cameraOrthographicLeft DirectionalLight { color: white } PointLight { y: 200 color: #d9c62b brightness: 5 castsShadow: true // 阴影投射 shadowFactor: 75 Model { // 寻找光源位置白色小立方体 source: #Cube scale: Qt.vector3d(0.01, 0.01, 0.01) materials: PrincipledMaterial { lighting: PrincipledMaterial.NoLighting } } } Model { position: Qt.vector3d(0, -200, 0) source: #Cylinder scale: Qt.vector3d(2, 0.2, 1) materials: [ PrincipledMaterial { // 多材质着色 baseColor: red } ] } Model { position: Qt.vector3d(0, 150, 0) source: #Sphere materials: [ PrincipledMaterial { baseColor: blue } ] SequentialAnimation on y { loops: Animation.Infinite NumberAnimation { duration: 3000 to: -150 from: 150 easing.type: Easing.InQuad } NumberAnimation { duration: 3000 to: 150 from: -150 easing.type: Easing.OutQuad } } } WaterBottle { id: modelInstance scale: Qt.vector3d(10, 10, 10) NumberAnimation on eulerRotation.y { from: 0 to: 360 duration: 3000 loops: Animation.Infinite } } environment: SceneEnvironment { // 天空盒背景 backgroundMode: SceneEnvironment.SkyBox lightProbe: Texture { textureData: ProceduralSkyTextureData { } } } } Label { text: Front anchors.top: parent.top anchors.right: parent.right anchors.margins: 10 color: #222840 font.pointSize: 14 } RoundButton { text: Camera 1 anchors.centerIn: parent anchors.bottom: parent.top anchors.margins: 10 highlighted: topRightView.camera cameraPerspectiveOne implicitWidth: 100 onClicked: { topRightView.camera cameraPerspectiveOne } } } Button { anchors.right: parent.right text: debug onClicked: debugView.visible !debugView.visible DebugView { // render statics data id: debugView source: topRightView anchors.top: parent.bottom anchors.right: parent.right } } }效果展示创作不易小小的支持一下吧

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询