[Interest] Rendering simple QPainterPath with Qt3D

Ch'Gans chgans at gna.org
Tue Mar 15 05:41:07 CET 2016


On 14 March 2016 at 22:03, Sean Harmer <sean.harmer at kdab.com> wrote:
> 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.


Wow!!!
Thanks for this explanation, it sounds so easy said this way! ;)

I saw this QAttribute thing, but didn't bother digging further. But
now I have a better picture on how all this works.
Again, thanks a lot for your enlightening comments.

Maybe it would be nice to have a cpp example that show this. That was
my blocker as I went through all the examples, there's the case where
you load your model from a file, there's an example where you use
built-in geometry (Cuboid, Sphere, ...), and that was it, nothing
about custom geometry. (Don't get me wrong I'm not ranting, what you
guys are doing is awesome, as it has always been.)

> 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.

Will have a look, thanks for pointing me that.

>
>> 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.

And thanks again for this tip, will have a deeper look at this ForwardRenderer.

Chris

>
> 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