QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsbillboardgeometry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsbillboardgeometry.cpp
3 --------------------------------------
4 Date : Jul 2019
5 Copyright : (C) 2019 by Ismail Sunni
6 Email : imajimatika at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include <QVector3D>
17
18#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
19#include <Qt3DRender/QAttribute>
20#include <Qt3DRender/QBuffer>
21
22typedef Qt3DRender::QAttribute Qt3DQAttribute;
23typedef Qt3DRender::QBuffer Qt3DQBuffer;
24#else
25#include <Qt3DCore/QAttribute>
26#include <Qt3DCore/QBuffer>
27
28typedef Qt3DCore::QAttribute Qt3DQAttribute;
29typedef Qt3DCore::QBuffer Qt3DQBuffer;
30#endif
31
33#include "moc_qgsbillboardgeometry.cpp"
34
36 : QGeometry( parent )
37 , mPositionAttribute( new Qt3DQAttribute( this ) )
38 , mVertexBuffer( new Qt3DQBuffer( this ) )
39{
40 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
41 mPositionAttribute->setBuffer( mVertexBuffer );
42 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
43 mPositionAttribute->setVertexSize( 3 );
44 mPositionAttribute->setByteOffset( 0 );
45 mPositionAttribute->setByteStride( 3 * sizeof( float ) );
46 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
47
48 addAttribute( mPositionAttribute );
49}
50
51void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
52{
53 QByteArray vertexBufferData;
54 vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
55 float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
56 int idx = 0;
57 for ( const auto &v : vertices )
58 {
59 rawVertexArray[idx++] = v.x();
60 rawVertexArray[idx++] = v.y();
61 rawVertexArray[idx++] = v.z();
62 }
63
64 mVertexCount = vertices.count();
65 mVertexBuffer->setData( vertexBufferData );
66
67 emit countChanged( mVertexCount );
68}
69
71{
72 return mVertexCount;
73}
void countChanged(int count)
Signal when the number of points changed.
void setPoints(const QVector< QVector3D > &vertices)
Set the points for the billboard with vertices.
QgsBillboardGeometry(Qt3DCore::QNode *parent=nullptr)
Constructor of QgsBillboardGeometry.
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer