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