18 #include <Qt3DRender/QAttribute>    19 #include <Qt3DRender/QBuffer>    20 #include <Qt3DRender/QBufferDataGenerator>    31   mVertexBuffer = 
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, 
this );
    34   const int stride = tmpTess.
stride();
    36   mPositionAttribute = 
new Qt3DRender::QAttribute( 
this );
    37   mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
    38   mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
    39   mPositionAttribute->setVertexSize( 3 );
    40   mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
    41   mPositionAttribute->setBuffer( mVertexBuffer );
    42   mPositionAttribute->setByteStride( stride );
    43   addAttribute( mPositionAttribute );
    47     mNormalAttribute = 
new Qt3DRender::QAttribute( 
this );
    48     mNormalAttribute->setName( Qt3DRender::QAttribute::defaultNormalAttributeName() );
    49     mNormalAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
    50     mNormalAttribute->setVertexSize( 3 );
    51     mNormalAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
    52     mNormalAttribute->setBuffer( mVertexBuffer );
    53     mNormalAttribute->setByteStride( stride );
    54     mNormalAttribute->setByteOffset( 3 * 
sizeof( 
float ) );
    55     addAttribute( mNormalAttribute );
    61   QgsTessellator tessellator( origin.
x(), origin.
y(), mWithNormals, mInvertNormals, mAddBackFaces );
    62   for ( 
int i = 0; i < polygons.count(); ++i )
    65     float extr = extrusionHeightPerPolygon.
isEmpty() ? extrusionHeight : extrusionHeightPerPolygon.at( i );
    66     tessellator.addPolygon( *polygon, extr );
    69   qDeleteAll( polygons );
    71   QByteArray data( ( 
const char * )tessellator.data().constData(), tessellator.data().count() * 
sizeof( float ) );
    72   int nVerts = data.count() / tessellator.stride();
    74   mVertexBuffer->setData( data );
    75   mPositionAttribute->setCount( nVerts );
    76   if ( mNormalAttribute )
    77     mNormalAttribute->setCount( nVerts );
 
A class to represent a 2D point. 
 
int stride() const
Returns size of one vertex entry in bytes. 
 
3 Class that takes care of tessellation of polygons into triangles. 
 
void setPolygons(const QList< QgsPolygon *> &polygons, const QgsPointXY &origin, float extrusionHeight, const QList< float > &extrusionHeightPerPolygon=QList< float >())
Initializes vertex buffer from given polygons. Takes ownership of passed polygon geometries. 
 
QgsTessellatedPolygonGeometry(QNode *parent=nullptr)
Constructor. 
 
bool isEmpty() const override
Returns true if the geometry is empty.