QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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  , mVertexBuffer( new Qt3DRender::QBuffer( this ) )
24 {
25 
26  mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
27  mPositionAttribute->setBuffer( mVertexBuffer );
28  mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
29  mPositionAttribute->setVertexSize( 3 );
30  mPositionAttribute->setByteOffset( 0 );
31  mPositionAttribute->setByteStride( 3 * sizeof( float ) );
32  mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
33 
34  addAttribute( mPositionAttribute );
35 
36 }
37 
38 void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
39 {
40  QByteArray vertexBufferData;
41  vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
42  float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
43  int idx = 0;
44  for ( const auto &v : vertices )
45  {
46  rawVertexArray[idx++] = v.x();
47  rawVertexArray[idx++] = v.y();
48  rawVertexArray[idx++] = v.z();
49  }
50 
51  mVertexCount = vertices.count();
52  mVertexBuffer->setData( vertexBufferData );
53 
54  emit countChanged( mVertexCount );
55 
56 }
57 
59 {
60  return mVertexCount;
61 }
62 
63 
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.