QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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
35 : QGeometry( parent )
36 , mPositionAttribute( new Qt3DQAttribute( this ) )
37 , mVertexBuffer( new Qt3DQBuffer( this ) )
38{
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}
51
52void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
53{
54 QByteArray vertexBufferData;
55 vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
56 float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
57 int idx = 0;
58 for ( const auto &v : vertices )
59 {
60 rawVertexArray[idx++] = v.x();
61 rawVertexArray[idx++] = v.y();
62 rawVertexArray[idx++] = v.z();
63 }
64
65 mVertexCount = vertices.count();
66 mVertexBuffer->setData( vertexBufferData );
67
68 emit countChanged( mVertexCount );
69
70}
71
73{
74 return mVertexCount;
75}
76
77
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
Definition qgs3daxis.cpp:28
Qt3DCore::QBuffer Qt3DQBuffer
Definition qgs3daxis.cpp:30
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer