QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgs3dwiredmesh_p.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgs3dwiredmesh_p.cpp
3 --------------------------------------
4 Date : March 2022
5 Copyright : (C) 2022 by Jean Felder
6 Email : jean dot felder at oslandia 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 "qgs3dwiredmesh_p.h"
17
18#include "qgsaabb.h"
19
20#include <Qt3DCore/QAttribute>
21#include <Qt3DCore/QGeometry>
22
23#include "moc_qgs3dwiredmesh_p.cpp"
24
26
27Qgs3DWiredMesh::Qgs3DWiredMesh( Qt3DCore::QNode *parent )
28 : Qt3DRender::QGeometryRenderer( parent )
29 , mPositionAttribute( new Qt3DCore::QAttribute( this ) )
30 , mVertexBuffer( new Qt3DCore::QBuffer( this ) )
31{
32 mPositionAttribute->setAttributeType( Qt3DCore::QAttribute::VertexAttribute );
33 mPositionAttribute->setBuffer( mVertexBuffer );
34 mPositionAttribute->setVertexBaseType( Qt3DCore::QAttribute::Float );
35 mPositionAttribute->setVertexSize( 3 );
36 mPositionAttribute->setName( Qt3DCore::QAttribute::defaultPositionAttributeName() );
37
38 mGeom = new Qt3DCore::QGeometry( this );
39 mGeom->addAttribute( mPositionAttribute );
40
41 setInstanceCount( 1 );
42 setIndexOffset( 0 );
43 setFirstInstance( 0 );
44 setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines );
45 setGeometry( mGeom );
46}
47
48Qgs3DWiredMesh::~Qgs3DWiredMesh() = default;
49
50void Qgs3DWiredMesh::setVertices( const QList<QVector3D> &vertices )
51{
52 QByteArray vertexBufferData;
53 vertexBufferData.resize( static_cast<int>( static_cast<long>( vertices.size() ) * 3 * sizeof( float ) ) );
54 float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
55 int idx = 0;
56 for ( const QVector3D &v : std::as_const( vertices ) )
57 {
58 rawVertexArray[idx++] = v.x();
59 rawVertexArray[idx++] = v.y();
60 rawVertexArray[idx++] = v.z();
61 }
62
63 mVertexBuffer->setData( vertexBufferData );
64 setVertexCount( vertices.count() );
65}
66
67void Qgs3DWiredMesh::setVertices( const QList<QgsAABB> &bboxes )
68{
69 QList<QVector3D> vertices;
70 for ( const QgsAABB &bbox : bboxes )
71 vertices << bbox.verticesForLines();
72
73 setVertices( vertices );
74}
75
Axis-aligned bounding box - in world coords.
Definition qgsaabb.h:35