Cernhfs Qt3d Basics
Cernhfs Qt3d Basics
Cernhfs Qt3d Basics
3D Basics
CERN HSF Visualization workshop, 28/03/2017
p.1
Introducing Qt Quick What is Qt Quick?
Introducing Qt Quick
Design-oriented
Easy deployment
Qt 3D Basics
Designed to be scalable
Feature Set
Typical inheritance hierarchy All fine until customer requires new feature:
Is traditional fixed composition the panacea? The Entity/Component data split gives flexibility to manage the API
The System separation moves the behavior away from data avoiding
dependencies between Components
Inheritance:
Relationships baked in at design time
Complex inheritance hierarchies: deep, wide, multiple inheritance
Features tend to migrate to base class
Fixed Composition
Relationships still baked in at design time
Fixed maximum feature scope
Lots of functional domain details in the scene object
If functional domain objects contain both data and behavior they will
have lots of inter-dependencies Hello Donut
Entity Component System
Allows changes at runtime
Avoids inheritance limitations
Has additional costs:
More QObjects
Different to most OOP developer's experience
We don't have to bake in assumptions to Qt 3D that we can't later
change when adding features.
Good practice having root QML API is a mirror of the C++ API
Entity to represent the
scene C++ class names like the rest of Qt
Demo qt3d/ex-hellodonut-qml
Qt3DCore::QEntity
It inherits from Qt3DCore::QNode
It just aggregates Qt3DCore::QComponents
Qt3DCore::QComponent
Qt 3D ECS Explained
It inherits from Qt3DCore::QNode
Actual data is provided by its subclasses
Qt3DCore::QTransform
Qt3DRender::QMesh
Qt3DRender::QMaterial
...
Qt 3D provides
Qt3DRender::QRenderAspect
Qt3DInput::QInputAspect
Qt3DLogic::QLogicAspect
Qt Demo examples/qt3d/basicshapes-cpp
If a Qt3DCore::QEntity only has a Even with shapes and materials we would see nothing
shape it will appear black
We need some lights
The Qt3DRender::QMaterial ... luckily Qt 3D sets a default one for us if none is provided
component provides a surface
appearance In general we want some control of the scene lighting
Demo qt3d/sol-textured-scene
Demo qt3d/ex-glsl
Demo qt3d/ex-object-picker
Demo qt3d/ex-object-picker-qml
Interacting with the scene p.42 Interacting with the scene p.43
To handle input we first need to generate input events Physical devices provide only discrete events
Subclasses of Qt3DInput::QAbstractPhysicalDevice represent input Hard to use them to control a value over time
devices
Logical device provides a way to:
Qt3DInput::QKeyboardDevice
Have an analog view on a physical device
Qt3DInput::QMouseDevice Aggregate several physical devices in a
Others can be added later unified device
On it's own a device doesn't do much Combined with input handler
Input handlers expose signals emitted in response to events
Demo qt3d/ex-mouse-handler-qml
Interacting with the scene p.44 Interacting with the scene p.45
Putting it All Together: Moving Boxes Integrating with QtQuick using Scene3D
Focused box appears bigger Takes an Entity as child which will be your whole scene
The arrows move the box on the plane Loaded aspects are controlled with the aspects property
Page up/down rotate the box on its Y axis Hover events are only accepted if the hoverEnabled property is true
Boxes light up when on mouse hover
Interacting with the scene p.46 Interacting with the scene p.47
The Qt 3D Frame Graph All these and others require control over how we render the Scene Graph
The nodes of the Frame Graph form a tree It is important to structure your Frame Graph properly for performance
reasons
The entities of the Scene Graph form a tree
Might lead to deep and narrow trees
The Frame Graph and Scene Graph are linearized into render commands
Simplest case being a one pass forward renderer
Camera describes a point of view on a Our Viewports all display the same scene...
scene
But they can display different subsets of the
Viewport allows to split the render surface scene using layers
in several areas
Attach each entity to a Layer
They can be nested for further splitting
Have each Viewport display a subset of the
CameraSelector allows to select a camera
entities using LayerFilter
to render in a Viewport
Demo qt3d/ex-viewports
Multiple passes
Post-Processing Effects
Demo qt3d/ex-gaussian-blur
Demo qt3d/ex-multiple-effects
The Qt 3D Frame Graph p.54 Beyond the Tip of the Iceberg p.55
Texture mipmaps
Cube Maps
Instanced rendering
etc.
The Future of Qt 3D
Demo qt3d/sol-asteroids
Demo qt3d/ex-instanced-geometry