QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
41 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
42 mPositionAttribute->setBuffer( mVertexBuffer );
43 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
44 mPositionAttribute->setVertexSize( 3 );
45 mPositionAttribute->setByteOffset( 0 );
46 mPositionAttribute->setByteStride( 3 * sizeof( float ) );
47 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
48
49 addAttribute( mPositionAttribute );
50
51}
52
53void QgsBillboardGeometry::setPoints( const QVector<QVector3D> &vertices )
54{
55 QByteArray vertexBufferData;
56 vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
57 float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
58 int idx = 0;
59 for ( const auto &v : vertices )
60 {
61 rawVertexArray[idx++] = v.x();
62 rawVertexArray[idx++] = v.y();
63 rawVertexArray[idx++] = v.z();
64 }
65
66 mVertexCount = vertices.count();
67 mVertexBuffer->setData( vertexBufferData );
68
69 emit countChanged( mVertexCount );
70
71}
72
74{
75 return mVertexCount;
76}
77
78
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