当前位置:   article > 正文

Qt 3D 接口整体介绍(转)_no type named qt3drender in namespace qobjloader

no type named qt3drender in namespace qobjloader

转自 https://blog.csdn.net/qq_38880380/article/details/111056424

----------------------------------------------
概述
- 请阅读QtHelp: Qt 3D Overview
    https://www.kdab.com/overview-qt3d-2-0-part-1/
    http://blog.csdn.net/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}
        ]
    }

从文件中加载场景
    Entity {
        components: [
            SceneLoader {source: "qrc:/assets/test_scene.dae"}
        ]
    }


----------------------------------------------
Camera
import Qt3D.Core 2.0
import Qt3D.Render 2.0
----------------------------------------------
第一人称三角透视相机
    Camera {
        id: mainCamera
        objectName: "mainCamera"
        projectionType: CameraLens.PerspectiveProjection
        fieldOfView: 22.5
        aspectRatio: _window.width / _window.height
        onAspectRatioChanged: console.log( "aspectRatio = " + aspectRatio )
        nearPlane:   0.01
        farPlane:    1000.0
        viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
        upVector:   Qt.vector3d( 0.0, 1.0, 0.0 )
    }
    FirstPersonCameraController { camera: mainCamera }


轨道透视相机(右键按住拖动,可对准原点旋转相机)
    components: [
        RenderSettings {
            activeFrameGraph: ForwardRenderer {
                clearColor: Qt.rgba(0, 0.5, 1, 1)
                camera: camera
            }
        },
        InputSettings { }
    ]
    Camera {
        id: camera
        projectionType: CameraLens.PerspectiveProjection
        fieldOfView: 45
        aspectRatio: 16/9
        nearPlane : 0.1
        farPlane : 1000.0
        position: Qt.vector3d( 0.0, 0.0, -40.0 )
        upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
        viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
    }
    OrbitCameraController { camera: camera}

多角度观测
    Viewport {
          id: mainViewport
          normalizedRect: Qt.rect(0, 0, 1, 1)
          ClearBuffers {
              buffers: ClearBuffers.ColorDepthBuffer
          }

          Viewport {
              id: topLeftViewport
              normalizedRect: Qt.rect(0, 0, 0.5, 0.5)
              CameraSelector { id: cameraSelectorTopLeftViewport }
          }
          Viewport {
              id: topRightViewport
              normalizedRect: Qt.rect(0.5, 0, 0.5, 0.5)
              CameraSelector { id: cameraSelectorTopRightViewport }
          }
          Viewport {
              id: bottomLeftViewport
              normalizedRect: Qt.rect(0, 0.5, 0.5, 0.5)
              CameraSelector { id: cameraSelectorBottomLeftViewport }
          }
          Viewport {
              id: bottomRightViewport
              normalizedRect: Qt.rect(0.5, 0.5, 0.5, 0.5)
              CameraSelector { id: cameraSelectorBottomRightViewport }
          }
      }




----------------------------------------------
Light
----------------------------------------------
方向光(平行光,如太阳)
    Enity {
        components: [
            DirectionalLight {
                worldDirection: Qt.vector3d(0.3, -3.0, 0.0).normalized();
                color: "#fbf9ce"
                intensity: 0.3
            }
        ]
    }

点光源(如灯泡)
    Entity {
        components: [
            PointLight {
                color: "red"
                intensity: 0.3
                constantAttenuation: 1.0
                linearAttenuation: 0.0
                quadraticAttenuation: 0.0025
            }
        ]
    }

聚光(如舞台聚光灯)
    Entity {
        components: [
            SpotLight {
                localDirection: Qt.vector3d(0.0, -1.0, 0.0)
                color: "white"
                intensity: 0.6
            }
        ]
    }





----------------------------------------------
Material(材质)
贴图相关概念
    https://zhidao.baidu.com/question/167602912.html
    http://www.cnblogs.com/xiuj/p/5875461.html
    -------------------------------------------
    ambient                 : 环境色。物体自己发出的光。
    diffuse map             : 漫反射贴图(色彩贴图), 它的作用是给模型上颜色和材质
    specular map            : 高光贴图,不同材质,在光照下,它们的反射光的强弱都不同
    normal map              : 法线贴图.用来表现凹凸
    -------------------------------------------
    gloss map               : 指示着色器对物体的表面的某些部分着色更亮一点,某些部分更暗一点,因为Gloss Maps只需要单通道, 可用alpha通道的图或灰度图
    emboss bump map         : 做表面的浮雕效果的
    opacity map             : 透明贴图。透明通道制作头发或者损坏的衣服布料等等可以用到
    shininess               : 光泽(0-1)
    lighting map 和 AO map  : 让材质制作更加逼真,更加方便
Qt3D中材质
    用Material组件编写
    提供了几种材质组件,通常是几种贴图方式的组合
        PhongMaterial
        DiffuseMapMaterial
        NormalDiffuseMapMaterial
        GoochMaterial
----------------------------------------------
简单色彩材质
    色彩材质
        ColorMaterial{
            diffuseColor: Qt.rgba(0.2, 0.5, 0.3, 1.0)
            specularColor: Qt.rgba(0, 0, 0, 1.0)
        }
    Phong 基础光照模型材质
        PhongMaterial {
            ambient: Qt.rgba( 0.02, 0.02, 0.02, 1.0 )
            diffuse: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )
            specular: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )
            shininess: 1.0
        }
    PhongAlphaMaterial(带透明通道的基础Phong光照模型材质)
        PhongMaterial {
            ambient: Qt.rgba( 0.02, 0.02, 0.02, 1.0 )
            diffuse: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )
            specular: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )
            shininess: 1.0
            alpha: 0.8
        }
    GoochMaterial
        Gooch光照渲染模型。
        常用于CAD和CAM程序,完全拟真不是该模型的目标,
        该模型同时使用 color 和 brightness 来显示3d表面的弯曲部分;
        该模型混合了漫反射光/冷光/暖光来产生渐变色带,冷光和暖光分别由alpha和beta参数影响。色带区间:[cool + alpha * diffuse, warm + beta * diffuse]
        参数
            shininess : real
            diffuse : color
            specular : color
            coolColor : color
            warmColor : color
            alpha : real
            beta : real
    PerVertexColorMaterial
        Default implementation for rendering the color properties set for each vertex
        帮助上没有任何参数



漫反射贴图材质(Phong光照模型)
    漫反射贴图材质(漫反射由贴图提供)
        DiffuseMapMaterial {
            diffuse: "assets/chest/diffuse.webp"
            specular: Qt.rgba( 0.2, 0.2, 0.2, 1.0 )
            shininess: 2.0
            ambient: color
            textureScale: 1.0
        }
    漫反射高光贴图材质(漫反射和高光均有贴图提供)
        DiffuseSpecularMapMaterial{
            diffuse: "assets/chest/diffuse.webp"
            specular: "assets/chest/specular.webp"
            shininess: 2.0
            ambient: color
            textureScale: 1.0
        }


凹凸贴图材质(用贴图来模拟细节,减小建模复杂度)
    法线漫反射贴图材质(实现了phong光照和凹凸贴图模型)
        NormalDiffuseMapMaterial {
            ambient: Qt.rgba( 0.05, 0.05, 0.05, 1.0 )
            shininess: 5.0
            textureScale: 1.0
            diffuse: "assets/houseplants/pot.webp"
            normal: "assets/houseplants/pot_normal.webp"
            specular: Qt.rgba( 0.75, 0.75, 0.75, 1.0 )
            }
    法线漫反射贴图质(和前一个的区别?)
        NormalDiffuseMapAlphaMaterial {
            ambient: Qt.rgba( 0.05, 0.05, 0.05, 1.0 )
            shininess: 1.0
            textureScale: 1.0
            diffuse: "qrc:/images/songtitle.png"
            normal: "qrc:/images/normalmap.png"
            specular: color
            }
    法线漫反射高光贴图材质(高光可以指定贴图)
        NormalDiffuseSpecularMapMaterial {
            ambient: Qt.rgba( 0.05, 0.05, 0.05, 1.0 )
            shininess: 10.0
            textureScale: 10.0
            diffuse:  "assets/textures/pattern_09/diffuse.webp"
            normal:   "assets/textures/pattern_09/normal.webp"
            specular: "assets/textures/pattern_09/specular.webp"
            }


自定义材质(使用Shader技术实现)
    示例1
        Material {
            id: instancedPhongMaterial
            effect: Effect {
                techniques: Technique {
                    graphicsApiFilter {
                        api: GraphicsApiFilter.OpenGL
                        profile: GraphicsApiFilter.CoreProfile
                        minorVersion: 2
                        majorVersion: 3
                    }
                    filterKeys: FilterKey { name: "renderingStyle"; value: "forward" }
                    renderPasses: RenderPass {
                        shaderProgram: ShaderProgram {
                            vertexShaderCode: loadSource("qrc:/instanced.vert")
                            fragmentShaderCode: loadSource("qrc:/instanced.frag")
                        }
                    }
                }
            }
        }
    线框材质
        请查看官方示例“Wireframe qml example”
        WireframeMaterial {
            id: wireframeMaterial
            effect: WireframeEffect {}
            ambient: Qt.rgba( 0.2, 0.0, 0.0, 1.0 )
            diffuse: Qt.rgba( 0.8, 0.0, 0.0, 1.0 )
        }
    详见官方示例:Planets qml example
    Texture2D {
          id: diffuseTexture
          minificationFilter: Texture.LinearMipMapLinear
          magnificationFilter: Texture.Linear
          wrapMode {
              x: WrapMode.Repeat
              y: WrapMode.Repeat
          }
          generateMipMaps: true
          maximumAnisotropy: 16.0
          TextureImage {source: "qrc:/texturePalette.png"}
     }


----------------------------------------------
Layer(QLayer>)
类似ps中的图层,可在程序中控制某些图层显示隐藏
----------------------------------------------
  import Qt3D.Core 2.0
  import Qt3D.Render 2.0
  Entity {
      id: root
      components: RenderSettings {
          Viewport {
              ClearBuffers {
                  buffers: ClearBuffers.ColorDepthBuffer
                  CameraSelector {
                      camera: mainCamera
                      LayerFilter {layers: [layer1]}
                  }
              }
          }
      }
      Camera { id: mainCamera }

      // scene
      Entity {
          id: renderableEntity
          components: [ mesh, layer1 ]
      }
      Layer { id: layer1 }
      GeometryRenderer { id: mesh }
  }




----------------------------------------------
TechniqueFilter e
----------------------------------------------
import Qt3D.Core 2.0
import Qt3D.Render 2.0
TechniqueFilter {
    property alias camera: cameraSelector.camera
    property alias window: surfaceSelector.surface

    id: root
    objectName : "techniqueFilter"
    matchAll: [ FilterKey { name: "renderingStyle"; value: "forward" } ]  // Select the forward rendering Technique of any used Effect

    RenderSurfaceSelector {
        id: surfaceSelector
        Viewport {
            id: viewport
            objectName : "viewport"
            normalizedRect: Qt.rect(0.0, 0.0, 1.0, 1.0)
            CameraSelector {
                id : cameraSelector
                objectName : "cameraSelector"
                ClearBuffers {
                    buffers : ClearBuffers.ColorDepthBuffer
                    clearColor: "black"
                    SortPolicy {
                        sortTypes: [
                            SortPolicy.StateChangeCost,
                            SortPolicy.Material
                        ]
                    }
                }
            }
        }
    }
}


----------------------------------------------
AspectEngine
----------------------------------------------
3d模拟是AspectEngine来执行等
AbstractAspect
    Behavior 处理组件数据

RenderAspect
InputAspect
LoginAspect




----------------------------------------------
FrameGraph & ViewPort & Layer
描述了后期处理逻辑,如:阴影/透明/后期处理/多视图/选择渲染
import Qt3D.Core 2.0
import Qt3D.Render 2.0
----------------------------------------------
默认的RenderSetting
    Entity {
        Camera { id:camera ... }
        FirstPersonCameraController {camera:camera}
        components: [
            RenderSetting{
                activeFrameGraph : ForwardRenderer {camera:camera, clearColor:"transparent"},
                InputSetting{}
            }
        ]
        ...
    }

自定义RenderSetting(多视图)
    RenderSettings {
      id: quadViewportFrameGraph
      property alias topLeftCamera: cameraSelectorTopLeftViewport.camera;
      property alias topRightCamera: cameraSelectorTopRightViewport.camera;
      property alias bottomLeftCamera: cameraSelectorBottomLeftViewport.camera;
      property alias bottomRightCamera: cameraSelectorBottomRightViewport.camera;
      property alias window: surfaceSelector.surface

      activeFrameGraph: RenderSurfaceSelector {
          id: surfaceSelector
          Viewport {
              id: mainViewport
              normalizedRect: Qt.rect(0, 0, 1, 1)

              ClearBuffers {
                  buffers: ClearBuffers.ColorDepthBuffer
              }

              Viewport {
                  id: topLeftViewport
                  normalizedRect: Qt.rect(0, 0, 0.5, 0.5)
                  CameraSelector { id: cameraSelectorTopLeftViewport }
              }

              Viewport {
                  id: topRightViewport
                  normalizedRect: Qt.rect(0.5, 0, 0.5, 0.5)
                  CameraSelector { id: cameraSelectorTopRightViewport }
              }

              Viewport {
                  id: bottomLeftViewport
                  normalizedRect: Qt.rect(0, 0.5, 0.5, 0.5)
                  CameraSelector { id: cameraSelectorBottomLeftViewport }
              }

              Viewport {
                  id: bottomRightViewport
                  normalizedRect: Qt.rect(0.5, 0.5, 0.5, 0.5)
                  CameraSelector { id: cameraSelectorBottomRightViewport }
              }
          }
      }
  }

选择图层渲染
    RenderSurfaceSelector{
        RenderTargetSelector{
            target: sceneTarget
            CameraSelector{
                camera: mainCamera
                ClearBuffer {
                    buffers: ClearBuffers.ColorDepthBuffer
                    clearColor: "white"
                    NoDraw{}
                }
                LayerFilter{
                    layers: [objectsLayer]
                    RenderPassFilter{
                        matchAny: FilterKey{name: "renderPass"; value: "allObjects"}
                    }
                }
                LayerFilter{
                    layers: [enviromentLayer]
                }
            }
        }
    }


----------------------------------------------
CustomMaterial & Effect
----------------------------------------------
import Qt3D.Core 2.0
import Qt3D.Render 2.0
Material {
    // 定义材质的参数
    id: root
    property color ambient: Qt.rgba( 0.05, 0.05, 0.05, 1.0 )
    property color diffuse: Qt.rgba( 0.7, 0.7, 0.7, 1.0 )
    property color specular: Qt.rgba( 0.95, 0.95, 0.95, 1.0 )
    property real shininess: 150.0
    property real lineWidth: 0.8
    property color lineColor: Qt.rgba( 0.0, 0.0, 0.0, 1.0 )
    parameters: [
        Parameter { name: "ka"; value: Qt.vector3d(root.ambient.r, root.ambient.g, root.ambient.b) },
        Parameter { name: "kd"; value: Qt.vector3d(root.diffuse.r, root.diffuse.g, root.diffuse.b) },
        Parameter { name: "ks"; value: Qt.vector3d(root.specular.r, root.specular.g, root.specular.b) },
        Parameter { name: "shininess"; value: root.shininess },
        Parameter { name: "line.width"; value: root.lineWidth },
        Parameter { name: "line.color"; value: root.lineColor }
    ]

    // 具体的效果实现逻辑(使用Shader实现)
    effect: Effect {
        parameters: [
            Parameter { name: "ka";  value: Qt.vector3d( 0.1, 0.1, 0.1 ) },
            Parameter { name: "kd";  value: Qt.vector3d( 0.7, 0.7, 0.7 ) },
            Parameter { name: "ks";  value: Qt.vector3d( 0.95, 0.95, 0.95 ) },
            Parameter { name: "shininess"; value: 150.0 }
        ]
        techniques: [
            Technique {
                graphicsApiFilter {
                    api: GraphicsApiFilter.OpenGL
                    profile: GraphicsApiFilter.CoreProfile
                    majorVersion: 3
                    minorVersion: 1
                }
                filterKeys: [ FilterKey { name: "renderingStyle"; value: "forward" } ]
                parameters: [
                    Parameter { name: "light.position"; value: Qt.vector4d( 0.0, 0.0, 0.0, 1.0 ) },
                    Parameter { name: "light.intensity"; value: Qt.vector3d( 1.0, 1.0, 1.0 ) },
                    Parameter { name: "line.width"; value: 1.0 },
                    Parameter { name: "line.color"; value: Qt.vector4d( 1.0, 1.0, 1.0, 1.0 ) }
                ]
                // 渲染通道
                renderPasses: [
                    RenderPass {
                        shaderProgram: ShaderProgram {
                            vertexShaderCode:   loadSource("qrc:/Materials/Shaders/robustwireframe.vert")
                            geometryShaderCode: loadSource("qrc:/Materials/Shaders/robustwireframe.geom")
                            fragmentShaderCode: loadSource("qrc:/Materials/Shaders/robustwireframe.frag")
                        }
                    }
                ]
            }
        ]
    }
}
shader 详见Qt3D.Shader章节




----------------------------------------------
ObjectPicker & animation(5.9)
https://www.kdab.com/qt-3d-animation-easter-teaser/
ClipAnimator 5.9 提供。可加载设计好的动画
----------------------------------------------
Entity {
    id: cube
    components: [
        Transform {
            id: cubeTransform
        },
        Mesh {
            source: "qrc:/assets/egg/egg.obj"
        },
        TexturedMetalRoughMaterial {
            baseColor: TextureLoader {
                format: Texture.SRGB8_Alpha8
                source: "qrc:/assets/egg/basecolor.png"
            }
            metalness: TextureLoader { source: "qrc:/assets/egg/metalness.png" }
            roughness: TextureLoader { source: "qrc:/assets/egg/roughness.png" }
            normal: TextureLoader { source: "qrc:/assets/egg/normal.png" }
            ambientOcclusion: TextureLoader { source: "qrc:/assets/egg/ambientocclusion.png" }
        },
        ObjectPicker {
            onClicked: animator.running = true
        },
        ClipAnimator {
            id: animator
            loops: 3
            clip: AnimationClipLoader { source: "qrc:/jumpinganimation.json" }
            channelMapper: ChannelMapper {
                mappings: [
                    ChannelMapping { channelName: "Location"; target: cubeTransform; property: "translation" },
                    ChannelMapping { channelName: "Rotation"; target: cubeTransform; property: "rotation" },
                    ChannelMapping { channelName: "Scale"; target: cubeTransform; property: "scale3D" }
                ]
            }
        }
    ]
}




----------------------------------------------
-- 批量生成对象
----------------------------------------------
   NodeInstantiator {
      id: collection
      property int maxCount: parent.numberOfBars
      model: maxCount
      delegate: BarEntity {
          id: cubicEntity
          entityMesh: CuboidMesh {xExtent: 0.1; yExtent: 0.1; zExtent: 0.1}
          rotationTimeMs: sceneRoot.barRotationTimeMs
          entityIndex: index
          entityCount: sceneRoot.numberOfBars
          entityAnimationsState: animationState
          magnitude: 0
      }
    }

    NodeInstantiator {
        id: grid
        model: rows * columns
        property int rows: 6
        property int columns: 11

        Entity {
            property int _row: index / grid.columns
            property int _col: index % grid.columns

            components: [ sphereTransform, sphereMesh, sphereMaterial ]
            SphereMesh {
                id: sphereMesh
                slices: 60
                rings: 60
                radius: 0.65
            }
            Transform {
                id: sphereTransform
                translation: Qt.vector3d(-7.5 + _col * 1.5, -4.0 + _row * 1.5, 0)
            }
            MetalRoughMaterial {
                id: sphereMaterial
                baseColor: scene.baseColor
                metalness: 0.2 * _row
                roughness: 0.1 * _col
            }
        }
    }


----------------------------------------------
------------------------------------------------
KeyboardInput
    可响应键盘消息


LogicComponent
    可设置逻辑。如物体位置/精灵创建/离屏销毁等。


FrameGraph
    如何渲染场景


CameraSelector NoDraw
    Viewport {
      CameraSelector {
          ClearBuffers {
              buffers: ClearBuffers.ColorDepthBuffer
              NoDraw { } // Prevents from drawing anything
          }
          RenderPassFilter {
              ...
          }
          RenderPassFilter {
              ...
          }
      }
    }

ClearBuffers
    ClearBuffers {
      buffers: ClearBuffers.DepthBuffer
      CameraSelector {
          id: lightCameraSelector
      }
    }


--------------------------------------------------
三维旋转控制
--------------------------------------------------
    // 旋转
    Transform {
        id: modelTransform
        property real angle: 0
        matrix: {
            var m = cameraMatrix.inverted();
            m.translate(Qt.vector3d(6,
                                    -4 - (1.0 - showDetailsTransitionState) * 10,
                                    -20 * showDetailsTransitionState));
            m.rotate(modelTransform.angle, Qt.vector3d(0, 1, 0));  // 动画绕y轴旋转360度
            m.rotate(15, Qt.vector3d(0, 0, 1)); // 沿z轴倾斜15度
            return m;
        }
    }

    //
    Transform {
        id: cameraRotationTransform
        matrix: {
            var m = Qt.matrix4x4();
            m.rotate(-19 * window.carouselOffset, Qt.vector3d(0.0, 1.0, 0.0));
            m.rotate(5 * mainCamera.roll, Qt.vector3d(0.0, 0.0, 1.0));
            m.lookAt(Qt.vector3d( 0.0, 0.0, 0.0 ),
                     Qt.vector3d(-40 * Math.sin(mainCamera.yaw), mainCamera.roll * 3, -40 * Math.cos(mainCamera.yaw) ),
                     Qt.vector3d( 0.0, 1.0, 0.0 ));
            return m;
        }
    }

    Transform {
        id: modelTransform
        matrix: {
            var m = cameraMatrix.inverted();
            m.translate(Qt.vector3d(0.0, -1.5 + (1.5 * showDetailsTransitionState), -40));
            m.rotate(40 * Math.min(1.0, showDetailsTransitionState * 1.5), Qt.vector3d(0, 1, 0));
            m.translate(Qt.vector3d(-25 * Math.max(0, showDetailsTransitionState - 0.4), 0.0, 0.0));
            return m;
        }
    }
--------------------------------------------------
贴图位置的控制
--------------------------------------------------
import Qt3D.Core 2.0
import Qt3D.Render 2.0
Texture2D {
    property alias source: image.source
    minificationFilter: Texture.LinearMipMapLinear
    magnificationFilter: Texture.Linear
    generateMipMaps: true
    wrapMode {
        x: WrapMode.ClampToEdge
        y: WrapMode.ClampToEdge
    }
    TextureImage {
        id: image
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683
  • 684
  • 685
  • 686
  • 687
  • 688
  • 689
  • 690
  • 691
  • 692
  • 693
  • 694
  • 695
  • 696
  • 697
  • 698
  • 699
  • 700
  • 701
  • 702
  • 703
  • 704
  • 705
  • 706
  • 707
  • 708
  • 709
  • 710
  • 711
  • 712
  • 713
  • 714
  • 715
  • 716
  • 717
  • 718
  • 719
  • 720
  • 721
  • 722
  • 723
  • 724
  • 725
  • 726
  • 727
  • 728
  • 729
  • 730
  • 731
  • 732
  • 733
  • 734
  • 735
  • 736
  • 737
  • 738
  • 739
  • 740
  • 741
  • 742
  • 743
  • 744
  • 745
  • 746
  • 747
  • 748
  • 749
  • 750
  • 751
  • 752
  • 753
  • 754
  • 755
  • 756
  • 757
  • 758
  • 759
  • 760
  • 761
  • 762
  • 763
  • 764
  • 765
  • 766
  • 767
  • 768
  • 769
  • 770
  • 771
  • 772
  • 773
  • 774
  • 775
  • 776
  • 777
  • 778
  • 779
  • 780
  • 781
  • 782
  • 783
  • 784
  • 785
  • 786
  • 787
  • 788
  • 789
  • 790
  • 791
  • 792
  • 793
  • 794
  • 795
  • 796
  • 797
  • 798
  • 799
  • 800
  • 801
  • 802
  • 803
  • 804
  • 805
  • 806
  • 807
  • 808
  • 809
  • 810
  • 811
  • 812
  • 813
  • 814
  • 815
  • 816
  • 817
  • 818
  • 819
  • 820
  • 821
  • 822
  • 823
  • 824
  • 825
  • 826
  • 827
  • 828
  • 829
  • 830
  • 831
  • 832
  • 833
  • 834
  • 835
  • 836
  • 837
  • 838
  • 839
  • 840
  • 841
  • 842
  • 843
  • 844
  • 845
  • 846
  • 847
  • 848
  • 849
  • 850
  • 851
  • 852
  • 853
  • 854
  • 855
  • 856
  • 857
  • 858
  • 859
  • 860
  • 861
  • 862
  • 863
  • 864
  • 865
  • 866
  • 867
  • 868
  • 869
  • 870
  • 871
  • 872
  • 873
  • 874
  • 875
  • 876
  • 877
  • 878
  • 879
  • 880
  • 881
  • 882
  • 883
  • 884
  • 885
  • 886
  • 887
  • 888
  • 889
  • 890
  • 891
  • 892
  • 893
  • 894
  • 895
  • 896
  • 897
  • 898
  • 899
  • 900
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/619100
推荐阅读
相关标签
  

闽ICP备14008679号