QGIS API Documentation 3.39.0-Master (47f7b3a4989)
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#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
19#include <Qt3DRender/QAttribute>
20#include <Qt3DRender/QGeometry>
21typedef Qt3DRender::QAttribute Qt3DQAttribute;
22typedef Qt3DRender::QGeometry Qt3DQGeometry;
23typedef Qt3DRender::QBuffer Qt3DQBuffer;
24#else
25#include <Qt3DCore/QAttribute>
26#include <Qt3DCore/QGeometry>
27typedef Qt3DCore::QAttribute Qt3DQAttribute;
28typedef Qt3DCore::QGeometry Qt3DQGeometry;
29typedef Qt3DCore::QBuffer Qt3DQBuffer;
30#endif
31
32#include "qgsaabb.h"
33
34
36
37Qgs3DWiredMesh::Qgs3DWiredMesh( Qt3DCore::QNode *parent )
38 : Qt3DRender::QGeometryRenderer( parent )
39 , mPositionAttribute( new Qt3DQAttribute( this ) )
40 , mVertexBuffer( new Qt3DQBuffer( this ) )
41{
42 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
43 mPositionAttribute->setBuffer( mVertexBuffer );
44 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
45 mPositionAttribute->setVertexSize( 3 );
46 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
47
48 mGeom = new Qt3DQGeometry( this );
49 mGeom->addAttribute( mPositionAttribute );
50
51 setInstanceCount( 1 );
52 setIndexOffset( 0 );
53 setFirstInstance( 0 );
54 setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines );
55 setGeometry( mGeom );
56}
57
58Qgs3DWiredMesh::~Qgs3DWiredMesh() = default;
59
60void Qgs3DWiredMesh::setVertices( const QList<QVector3D> &vertices )
61{
62 QByteArray vertexBufferData;
63 vertexBufferData.resize( static_cast<int>( static_cast<long>( vertices.size() ) * 3 * sizeof( float ) ) );
64 float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
65 int idx = 0;
66 for ( const QVector3D &v : std::as_const( vertices ) )
67 {
68 rawVertexArray[idx++] = v.x();
69 rawVertexArray[idx++] = v.y();
70 rawVertexArray[idx++] = v.z();
71 }
72
73 mVertexBuffer->setData( vertexBufferData );
74 setVertexCount( vertices.count() );
75}
76
77void Qgs3DWiredMesh::setVertices( const QList<QgsAABB> &bboxes )
78{
79 QList<QVector3D> vertices;
80 for ( const QgsAABB &bbox : bboxes )
81 vertices << bbox.verticesForLines();
82
83 setVertices( vertices );
84}
85
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry