QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 #include "qgsbillboardgeometry.h"
19 
21  : Qt3DRender::QGeometry( parent )
22  , mPositionAttribute( new Qt3DRender::QAttribute( this ) )
23 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
24  , mVertexBuffer( new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, this ) )
25 #else
26  , mVertexBuffer( new Qt3DRender::QBuffer( this ) )
27 #endif
28 {
29 
30  mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
31  mPositionAttribute->setBuffer( mVertexBuffer );
32  mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
33  mPositionAttribute->setVertexSize( 3 );
34  mPositionAttribute->setByteOffset( 0 );
35  mPositionAttribute->setByteStride( 3 * sizeof( float ) );
36  mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
37 
38  addAttribute( mPositionAttribute );
39 
40 }
41 
42 void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
43 {
44  QByteArray vertexBufferData;
45  vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
46  float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
47  int idx = 0;
48  for ( const auto &v : vertices )
49  {
50  rawVertexArray[idx++] = v.x();
51  rawVertexArray[idx++] = v.y();
52  rawVertexArray[idx++] = v.z();
53  }
54 
55  mVertexCount = vertices.count();
56  mVertexBuffer->setData( vertexBufferData );
57 
58  emit countChanged( mVertexCount );
59 
60 }
61 
63 {
64  return mVertexCount;
65 }
66 
67 
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.