Qt 5.12--3D功能接口介绍

1 简介

Qt 3D为Qt C ++和Qt Quick应用程序中的2D和3D渲染提供支持的近实时仿真系统功能。
Qt3D资料和官方的例程比较少,且API 接口的文档写得又比较简略,CSDN等技术网站能搜到的资料太少,在google和stackoverflow 搜索相关问题也是。博主猜测在Qt的应用场景中使用3D要么比较少,要么就是涉及的公司不开源。

2 Qt3D 1.0版本(淘汰)

  • Viewport:整个场景的视口。是3D的根元素定义了场景和摄像机,是整个场景的最外层;
  • Camera:他作为Viewport的一个属性,定义了观察位置及方向的投影,同时也支持立体投影;
  • Item3D:在场景中创建3D对象。创建一个Item3D后就必须指定一个Mesh。可以设置父类形成一个Item3D树(和Qt里面对象树差不多)。
  • Mesh:主要是来加载几何图形,可以通过文件自动的加载几何图像,文件格式支持3ds、dae、bez、obj。
  • Effect:为item在screen中渲染effect。这些effect包括灯光、材质、纹理。
  • ShaderPrograme:指定一个片段和一堆顶点。如果自定义属性和顶点着色器以相同的名称存在,着色器程序会自动将它们绑定到片段和顶点着色器。
  • Material:为effect提供属性,如灯光演示等属性。
  • Transformations:目前有4种转换Rotation3D、Translation3D、Scale3D、LookAtTransform。这里有个要注意的地方,这里的场景其实也是个矩阵,他是一个叉乘。转换再平移和平移再转换的结果是不同的。

3 Qt3D 2.0版本

QML类型分为三个模块:Qt3D,Qt3D.Input和Qt3D.Renderer。

import Qt3D 2.0

Camera
CameraLens
Component3D
Configuration
Entity
EntityLoader
MatrixTransform
Node
NodeInstantiator

import Qt3D.Input 2.0

KeyEvent
KeyboardController
KeyboardInput

import Qt3D.Renderer 2.0

AbstractTextureImage
Annotation
BlendState
BlendStateSeparate
FrameGraph
FrameGraphNode
Layer
LayerFilter
OpenGLFilter
ParameterMapping
PointLight
SpotLight
TextureImage

  • Entity为一个空壳,专门放3D组件的
    是Node一个子类,可以聚合几个Component3D实例来指定其行为。 一个方面可以决定只处理由单个Transform组件组成的实体,而另一个方面可以专注于MouseHandler。
    属性:components : list
    Entity/Component数据拆分可灵活管理API,系统分离使行为远离数据避免
    组件之间的依赖关系(MVC)
    在这里插入图片描述
  • RenderSettings:设置一个场景,一般Viewport就放到这里面
  • Transform:用于指定 Items 的高级转换
    (1)Rotation 旋转变换
    (2)Scale 比例变换
    (3)Translate 平移变换
    (4)Matrix4x4 齐次变换
  • Geometry :Geometry类型用于将Attribute对象列表组合在一起,以形成Qt3D能够使用GeometryRenderer渲染的几何形状。 可以设置特殊属性,以计算形状的边界体积。
    (1)attributes : list
    (2)boundingVolumePositionAttribute : Attribute
    (3)maxExtent : vector3d
    (4)minExtent : vector3d
  • Material:为effect提供属性,如灯光演示等属性。
  • PhongMaterial:提供材质照明效果的默认实现
    (1)ambient : color
    环境光是物体在没有任何其他光源的情况下发出的颜色。
    (2)diffuse : color
    漫反射是灯光在粗糙表面反射时发出的颜色。
    (3)shininess : real
    镜面反射是在灯光下为发亮的表面反射而发出的颜色。
    (4)specular : color
    表面的光泽度由漂浮性控制。
  • PropertyAnimation
  • Camera

meshes
materials
shaders
shadow mapping
ambient occlusion
high dynamic range
deferred rendering
multitexturing
instanced rendering
uniform buffer objects

4 示例步骤

在这里插入图片描述

  • 有一个root Entity表示场景
  • 场景中每个对象一个Entity
  • 每个对象的Entity中添加component子类来表示对象行为
  • 对一个Entity来说
    (1)需要 mesh 几何来描述它的形状
    (2)需要 material 描述它的表面外观
  • QML API是C++ API的封装
  • QML元素名称和C++命名区别就是一个Q
    (1)如Qt3DCore::QNode vs Node
    (2)如Qt3DCore::QEntity vs Entity

参考

1、Qt 3D QML Types
2、Scene3D QML Type
3、Qt3D文档阅读笔记-Qt3D老版本知识点及使用新版本的运行
4、Qt 5.12学习笔记–3D基础
5、Qt学习之路——— 坐标系统
6、qt qml中PropertyAnimation的几种使用方法
7、introduction-qt3d
8、Qt 3D
9、Qt 3D Overview
10、Qt 3D Examples

This directory contains the Qt3D project for Qt5: * Qt3D QML bindings and * Qt3D C++ APIs Building Qt3D ================== Qt5 is a rapidly changing bleeding edge environment. This branch is our initial support for it and thus is also rapidly changing and bleeding edge. This branch is experimental, and unsupported. This information is provided for advanced use only. No guarantees about API stability or even if this works at all are supplied, use at your own risk. First fetch the Qt5 source tree and Qt3D master branch: cd ~/depot git clone ssh://codereview.qt-project.org:29418/qt/qt5.git cd qt5 ./init-repository --codereview-username \ --module-subset=qtbase,qtsvg,qtdeclarative,qttools,qtxmlpatterns,qtdoc,qlalr,qtrepotools,qtqa,qtlocation,qt3d git submodule foreach "git fetch gerrit && git reset --hard gerrit/master" cd qt3d scp -p -P 29418 codereview.qt-project.org:hooks/commit-msg .git/hooks/ git fetch gerrit git checkout --track -b master gerrit/master If you are reading this file then somehow you probably already got this far anyway. Now build Qt5, which will also build Qt3D as a module: cd ~/build mkdir qt5 cd qt5 ~/depot/qt5/configure -developer-build -opensource -confirm-license -no-webkit -no-phonon -nomake tests \ -nomake examples -declarative -opengl -svg && make -j 4 What's in Qt3D ================== Directory structure: src/threed/ This is the main library of the Qt3D project, containing abstractions for cross-platform GL, shaders, lighting models, and so on. src/plugins/ Scene format loading plugins. src/imports/ QML import plugins. util/ Various utilities that are useful when working with Qt3D. examples/ Some examples of using Qt3D QML bindings and Qt3D C++ API. demos/ Some more complex demos of using Qt3D QML bindings and Qt3D C++ API. tests/auto/qml3d/ Unit tests for the QML bindings. tests/auto/threed/ Unit tests for the C++ API doc/ Documentation. devices/symbian/ Symbian deployment file Documentation ============= The documentation can be generated with "make docs". It will be placed into "doc/html" in the build directory. Packages ======== This section is only for those developing Qt3D. Read on to discover how the building of packages works. This section is also important if you want to change how the structure of the Qt3D pro files work. To build Qt3D, run: qmake && make The .pro files will cause the toolchain to place the libraries, QML files and meshes of Qt3D directly into place, as part of the compile process. The files go into the bin/ directory, and the executables can be run directly from there. If you are doing a developer build, plugins will be installed in such a way that Qt will find them. After building the tree the install step is invoked using the INSTALL_ROOT environment export to cause the installation rules to place all the files into a sandboxed install tree, ready for packaging: INSTALL_ROOT=tmp make install Examples ======== Some examples require assimp library to parse the content. Go to http://assimp.sourceforge.net/ and build and install the assimp library. Then configure Qt3D to include assimp and run qmake && make.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

worthsen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值