introducing qt3d 2.0: a qt framework for 3d …...history qt3d originally developed by the brisbane...
TRANSCRIPT
Introducing Qt3D 2.0: a Qt framework for 3D rendering and visualisationJames Turner
KDAB
Agenda
● Introduction● History● Goals
● Simple QML example● Advanced QML example
● Entity component model● Simple C++ example● Framegraph configuration● Conclusions
History
● Qt3D originally developed by the Brisbane office● Various previews / “labs” status in Qt 4 history● First major release: 1.0 (targeting Qt 4.8.1, but not bundled with it)
● Unfortunately, also last release● Not part of any Qt 5 releases
Qt3D 1.0
● C++ and QML APIs● To define geometry (simple shapes, meshes)● To define geometry materials (Phong + texture)● To define the scene properties (camera, lights, picking)
Qt3D 1.0 Problems
● Very simple render engine● Solid colours, Phong lighting, simple front/back texturing, EOF● Rendering not configurable: simple forward GL2 / ES2 renderer
● Little to no extensibility of the scene in non-graphical aspects● Physics, audio, …
● Slow!● Non batched rendering● Does not scale
● Development stopped when Nokia ditched Qt
Qt3D 2.0
● In late 2013 KDAB took over Qt3D development● Complete new design
● Data driven renderer● Entity/Component design, as found in several modern 3D engines
Goals
● C++ and QML APIs for everything● Extensible
● User-defined render techniques● Not just 3D geometry
● Constraint solving systems, physics, audio, …● Efficient
● Heavily threaded● Tries to batch as much as possible
● Offer alternatives to VTK and similar visualization solutions
Non goals
● Invent Yet Another 3D Simulation Engine● Not the same scope● Lack of manpower
● Force everyone to use the same rendering techniques● By providing a subset of what we deem “useful”, and ignoring all the other interesting use cases
● Duplicate technologies already in Qt● mainly OpenGL-wrapping APIs
Simple QML example
● Scene defined entirely in QML● Framegraph defined entirely in QML● Simple animations (“for free”)
Entity Component System
● Each element of a scene is an node (QObject subclass)● The entire scene is a tree of nodes
● Certain nodes are entities● Any entity is composed by 0 or more components
● Mesh● Transformation● Audio source● …
● F.i.: a 3D shape is an entity with a mesh component (and a transformation)● Totally extensible system
Entity Component System
Entity Component System
● Traditional problem: have a class and want to extend it with extra logic● E.g. a class for 3D shapes, and we want to add audio to it
● Traditional solution:● Introduce a base class for audio emitters● Refactor the class into a “Base3DShape” (or maybe “Base3DObject”)● Multiple inheritance● Rinse and repeat for any combination of logic (physics, AI, ...)
Entity Component System
● Traditional problem: have a class and want to extend it with extra logic● E.g. a class for 3D shapes, and we want to add audio to it
● Component-based solution:● Add a audio emitter component to the entity● ???● Profit!
Entity Component System
Aspects
● Aspects walk through the scene and pick up interesting information about entities
● ... attached as components● Examples:
● Rendering aspect (looks for meshes, transformations, materials, etc.)● Audio aspect (looks for audio emitters, listeners, transformations, etc.)● Physics aspect● ...
● A threaded job system triggers when the components change and aspects need to update their status
● More details in the following talk
Aspects
More advanced QML example
● Load some mesh files● Qt3D 2.0 can use assimp for loading meshes, scenes, etc. in a variety of formats
● Use multiple render passes● Render to an offscreen surface
Framegraph configuration
● The way the Qt3D renderer works is totally configurable● Allows custom-defined rendering techniques
● Forward● Wireframe● Deferred● … your imagination/requirements
● Some standard techniques available out of the box
Framegraph configuration
● Framegraph configuration is not hardwired in C++● Unlike QtQuick's scene graph, which is OK for QtQuick but not flexible for arbitrary 3D
● The configuration is expressed within the scene by adding a framegraph node● Data-driven
● Described by a C++ or QML tree of nodes
Framegraph configuration
● Material / Effect / Technique classes to define● How a mesh looks like● How to get the wanted effect depending on the framegraph configuration and GPU capabilities
● The framegraph will pick a set of suitable techniques to render the geometry● i.e. the Techniques matching the criteria configured in the framegraph
Framegraph configuration example
● Each path from a leaf to the framegraph root is a possible “configuration”● Selectors, filters used to establish how that configuration works
● Currently switch between configurations is automatic● Soon™, APIs for controlling what configurations are active/inactive
Basic C++ example
● A C++ API, matching the QML one, is available● Maybe a little too verbose and low level for now● Prefer QML?
TODOs
● Lots of API polishing ● Picking
● Possibly as an aspect on its own, for different strategies● More builtin aspects
● OpenAL audio, …● Integration with QtQuick2 scenes
● Having a QtQuick2 overlay on top of a Qt3D scene● Having a Qt3D scene rendered into a QtQuick2 item
● Docs and examples!
Conclusions
● Qt3D 2.0 is a modern engine for visualizing 3D scenes● Rendering entirely customizable via Techniques● Logic of scenes extensible through the Aspects system● Code available in the wip/newapi branch of the qt3d module● Tech preview coming with Qt 5.4
Questions?
Thank you!
If you're interested in the low-level details of Qt3D 2.0, don't miss the next talk in this room:
Behind the Scenes of Qt3D 2.0