Qt 3d

本文详细探讨了Qt 3D框架的使用,包括场景构建、模型加载、渲染技术等方面,揭示了如何在Qt应用中创建引人入胜的3D图形体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述
- 请阅读QtHelp: Qt 3D Overview 
    https://www.kdab.com/overview-qt3d-2-0-part-1/
    http://blog.youkuaiyun.com/iron_lzn/article/details/51363959
- 上youtube 搜索 Qt 3D 视频
- 上kdab公司的网站,Qt3D的主要代码都是kdab公司提供的
- 建模示例:https://www.kdab.com/qt-3d-animation-easter-teaser/
----------------------------------------------
功能
    2D and 3D rendering     : 2d/3d渲染
    Meshes and Geometry     : 面片和坐标
    Materials               : 材质
    Shaders                 : 着色器
    Shadow mapping          : 阴影贴图(一种实时阴影技术)
    Ambient occlusion       : 环境光遮蔽(一种全局光技术)
    High dynamic range      : 高动态范围(HDR)
    Deferred rendering      : 延迟渲染(一种多光源渲染技术)
    Multitexturing          : 多材质
    Instanced rendering     : 实例渲染
    Uniform Buffer Objects  : 统一缓冲对象(HBO)
    
相关库
    QT += 3dcore 3drender 3dinput 3dlogic 3dextras
    #include <Qt3DCore>
    #include <Qt3DRender>
    #include <Qt3DInput>
    #include <Qt3DLogic>
    #include <Qt3DExtras>
    QT += 3dcore 3drender 3dinput 3dlogic 3dextras qml quick 3dquick
    import Qt3D.Core 2.0      // 节点实体模型,基础变化
    import Qt3D.Render 2.0    // 相机,缓冲,滤镜,图层,面片,光照,特效,材质,Shader,
    import Qt3D.Input 2.0     // 输入
    import Qt3D.Logic 2.0     // 每帧动画控制
    import Qt3D.Extras 2.0    // 第一人称相机,轨道相机,反射贴图,基础模型等
    
继承关系
    Node                            // qt3d 所有类的基类
        Entity                      // 
            Camera                  // 
        Component3D                 // 
            Layer                   // 
            Transform               // 
            CameraLens              // 
            ComputeCommand          // 
            FrameAction             // 
            InputSettings           // 
            KeyboardHandler         // 
            GeometryRenderer        // 
                Mesh                // 面片
                ConeMesh            // 圆锥体 ConeMesh {
   
   bottomRadius: 0.05; topRadius: 0; length : 0.1; rings : 10; slices: 10},
                CuboidMesh          // 长方体
                CylinderMesh        // 圆柱体 CylinderMesh{
   
   length : size; radius : 0.05; rings : 10; slices: 10}
                PlaneMesh           // 平面  PlaneMesh {
   
   width: 1.0; height: 1.0; meshResolution: Qt.size(2, 2)}
                SphereMesh          // 球体  SphereMesh {
   
   radius: 1}
                TorusMesh           // 三叶体
            Light                   // 光照基类
                DirectionLight      // 方向光(如太阳)
                PointLight          // 电光源(如灯泡)
                SportLight          // 聚光
            Material                               // 
                Texture2D                          // 
                DiffuseMapMaterial                 // 漫反射贴图材质
                DiffuseSpecularMapMaterial         // 漫反射高光贴图材质
                GoochMaterial                      // Gooch shading model, popular in CAD and CAM applications
                NormalDiffuseMapMaterial           // 
                NormalDiffuseMapAlphaMaterial      // 
                NormalDiffuseSpecularMapMaterial   // 
                PhongMaterial                      // 
                PhongAlphaMaterial                 // 
                PerVertexColorMaterial             // 
        AbstractTextureImage        // 
        Effect                      // 
        FilterKey                   // 
        FrameGraphNode              // FrameGraph 配置基类,用于控制渲染
            LayerFilter             // 层过滤(只显示指定层的对象)
            CameraSelector          // 相机选择器 
            ClearBuffers            // enables clearing of the specific render target buffers with specific values
            DispatchCompute         // FrameGraph node to issue work for the compute shader on GPU
            FrustumCulling          // enables frustum culling of the drawable entities based on the camera view and Geometry bounds of the entities
            NoDraw                  // Prevents from drawing anything
            RenderCapture           // Used to request render capture. User can specify a captureId to identify the request.
            RenderSurfaceSelector   // be used to select the surface
            RenderTargetSelector    // s used to select active RenderTarget for the FrameGraph
            RenderPassFilter        // 
            RenderStateSet          // 
            SortPolicy              // 
            TechniqueFilter         // 
            Viewport                // 
        KeyboardDevice              // 
        RenderPass                  // 
        RenderState                 // 
        RenderTargetOutput          // 
        ShaderPrograme
        CameraController
            FirstPersonCameraController  // 第一人称相机控制器(类似cs)
            OrbitCameraController        // 轨道相机控制器(围绕物体旋转)
        Geometry                    // 
            ConeGeometry            // allows creation of a cone in 3D space
            CuboidGeometry          // allows creation of a cuboid in 3D space.
            CylinderGeometry        // 
            PlaneGeometry           // 
            SphereGeometry          // 
            TorusGeometry           // 


eg
    CuboidMesh {
   
   
        id: mesh
        property real multiplier: 0.0256
        xExtent: 512 * multiplier
        yExtent: 768 * multiplier
        zExtent: 2.0
        yzMeshResolution: Qt.size(20, 20)
        xzMeshResolution: Qt.size(20, 20)
        xyMeshResolution: Qt.size(20, 20)
    }

显示OpenGL版本
    Rectangle {
   
   
        color: "black"
        Text {
            color: "white"
            anchors.centerIn: parent
            text: "Open%4 %1.%2 %3"
                .arg(OpenGLInfo.majorVersion)
                .arg(OpenGLInfo.minorVersion)
                .arg({0: "NoProfile", 1: "CoreProfile", 2: "CompatibilityProfile"}[OpenGLInfo.profile])
                .arg({
   
   0: "Unspecified", 1: "GL", 2: "GLES"}[OpenGLInfo.renderableType])
            styleColor: "#8b8b8b"
            style: Text.Sunken
            font.pointSize: 24
            onTextChanged: {
   
   
                Resources.setGlInfo(OpenGLInfo);
            }
        }
    }

----------------------------------------------
Scene3D
提供3d运行场景,嵌在普通qml中
----------------------------------------------
属性
    activeCamera : Camera3D
    activeLight : Light3D
    devicePixelRatio : float
    graphPositionQuery : point
    invalidSelectionPoint : point
    primarySubViewport : rect
    secondarySubViewport : rect
    secondarySubviewOnTop : bool
    selectionQueryPosition : point
    slicingActive : bool
    viewport : rect 
    
示例
    Scene3D {
   
   
      id: scene3d
      anchors.fill: parent
      anchors.margins: 10
      focus: true
      aspects: ["input", "logic"]
      cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
      AnimatedEntity {
    
    }
    }
          
    

----------------------------------------------
Entity
Entity有个属性component,里面可以容纳 Mesh, Transformation, Audio, Material.....,
这是一种很灵活的方式,可简化3d对象类的层次,也便于扩展。
----------------------------------------------
标准写法
    Entity {
   
   
        components: [
            Mesh {source: "assets/obj/toyplane.obj"},
            PhongMaterial {
   
   diffuse: "white"; shininess: 50}
        ]
    }
    
从文件中加载场景
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值