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