[Interest] Rendering simple QPainterPath with Qt3D

Sean Harmer sean.harmer at kdab.com
Mon Mar 14 10:03:43 CET 2016


On Monday 14 Mar 2016 16:50:32 Ch'Gans wrote:
> Hi there,
> 
> I have an application that use heavily the Qt graphics view framework,
> where each item represent a flat, solid object on a layer of material.
> They all have a "simple" shape, that is they only use line and arcs
> and have no windings/overlaps. Items represents a deposit of material
> or a material cut-off.
> The application uses several QGraphicsScene to manage items on a set
> of "material layers", that are (in the real physical world) stacked on
> top of each other to form a sort of sandwich.
> 
> I would like to have a 3D view of my "stack of 2D layers" world by
> simply extruding vertically all my items by the thickness of the layer
> they belong to, and displaying all the stacked layers in 3D.
> 
> I had a look at Qt 3D source code, especially the classes derived from
> QMesh and QGeometry (Cuboid, Cylinder, Sphere, ...). And of course had
> a look at all the Qt3D example.
> 
> By the look of it, it seems to me that I should create a custom
> QMesh/QGeometry to render in 3D all my 2D items. I haven't try to code
> anything, I'm just trying to see what could be done and what would be
> the right approach.
> 
> Could anyone shed some light on how I could achieve this, like is the
> custom QMEsh/Geometry the right approach for this kind of problems?

If you want to extrude, then yes you need actual geometry so investigating 
QGeometry is the way to go. Basically, you provide a QBuffer containing your 
per-vertex data (positions, but maybe also normal vectors if you want 
lighting, texture coordinates if you want to apply a texture, vertex colors if 
you want to use the per-vertex colour material etc).

You then define one or more QAttributes that correspond to these per-vertex 
attributes. The QAttributes describe the layout of the data in the QBuffer.

You can then specify the QGeometry that contains the attributes in a 
QGeometryRenderer component.

The tricky part is converting your QPainterPaths into geometry and extruding 
it and storing it in the buffer. This is something we'd like to add a helper 
for at some point but we don't have anything for it yet. There is however, 
some private API in QtGui. Take a look at:

QTriangleSet Q_GUI_EXPORT qTriangulate(const QPainterPath &path, const 
QTransform &matrix = QTransform(), qreal lod = 1);

in src/gui/opengl/qtriangulator_p.h

You may need to copy/paste this into your own project and adjust it as the 
implementation relies upon having a current OpenGL context iirc. Shoudl give 
you most of what you need though.
 
> Note: I've never used the Qt 3D framegraph, and I'm not very familiar
> with OpenGL

You shouldn't need to worry about the framegraph, just use the ForwardRenderer 
one. Hopefully you shouldn't need to care about OpenGL either other than 
preparing the vertex data as described above.

Cheers,

Sean


> 
> Thanks,
> Chris
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-- 
Dr Sean Harmer | sean.harmer at kdab.com | Managing Director UK
KDAB (UK) Ltd, a KDAB Group company
Tel. +44 (0)1625 809908; Sweden (HQ) +46-563-540090
Mobile: +44 (0)7545 140604
KDAB - Qt Experts



More information about the Interest mailing list