QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgschunkboundsentity_p.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgschunkboundsentity_p.cpp
3 --------------------------------------
4 Date : July 2017
5 Copyright : (C) 2017 by Martin Dobias
6 Email : wonder dot sk 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
17
18#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
19#include <Qt3DRender/QBuffer>
20typedef Qt3DRender::QBuffer Qt3DQBuffer;
21#else
22#include <Qt3DCore/QBuffer>
23typedef Qt3DCore::QBuffer Qt3DQBuffer;
24#endif
25#include <Qt3DExtras/QPhongMaterial>
26
27#include "qgsaabb.h"
28
29
31
32LineMeshGeometry::LineMeshGeometry( Qt3DCore::QNode *parent )
33 : QGeometry( parent )
34 , mPositionAttribute( new Qt3DQAttribute( this ) )
35 , mVertexBuffer( new Qt3DQBuffer( this ) )
36{
37 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
38 mPositionAttribute->setBuffer( mVertexBuffer );
39 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
40 mPositionAttribute->setVertexSize( 3 );
41 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
42
43 addAttribute( mPositionAttribute );
44}
45
46void LineMeshGeometry::setVertices( const QList<QVector3D> &vertices )
47{
48 QByteArray vertexBufferData;
49 vertexBufferData.resize( vertices.size() * 3 * sizeof( float ) );
50 float *rawVertexArray = reinterpret_cast<float *>( vertexBufferData.data() );
51 int idx = 0;
52 for ( const auto &v : vertices )
53 {
54 rawVertexArray[idx++] = v.x();
55 rawVertexArray[idx++] = v.y();
56 rawVertexArray[idx++] = v.z();
57 }
58
59 mVertexCount = vertices.count();
60 mVertexBuffer->setData( vertexBufferData );
61}
62
63
64// ----------------
65
66
67AABBMesh::AABBMesh( Qt3DCore::QNode *parent )
68 : Qt3DRender::QGeometryRenderer( parent )
69{
70 setInstanceCount( 1 );
71 setIndexOffset( 0 );
72 setFirstInstance( 0 );
73 setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines );
74
75 mLineMeshGeo = new LineMeshGeometry( this );
76 setGeometry( mLineMeshGeo );
77}
78
79void AABBMesh::setBoxes( const QList<QgsAABB> &bboxes )
80{
81 QList<QVector3D> vertices;
82 for ( const QgsAABB &bbox : bboxes )
83 vertices << bbox.verticesForLines();
84 mLineMeshGeo->setVertices( vertices );
85 setVertexCount( mLineMeshGeo->vertexCount() );
86}
87
88
89// ----------------
90
91
92QgsChunkBoundsEntity::QgsChunkBoundsEntity( Qt3DCore::QNode *parent )
93 : Qt3DCore::QEntity( parent )
94{
95 mAabbMesh = new AABBMesh;
96 addComponent( mAabbMesh );
97
98 Qt3DExtras::QPhongMaterial *bboxesMaterial = new Qt3DExtras::QPhongMaterial;
99 bboxesMaterial->setAmbient( Qt::red );
100 addComponent( bboxesMaterial );
101}
102
103void QgsChunkBoundsEntity::setBoxes( const QList<QgsAABB> &bboxes )
104{
105 mAabbMesh->setBoxes( bboxes );
106}
107
3
Definition: qgsaabb.h:34
Qt3DCore::QAttribute Qt3DQAttribute
Definition: qgs3daxis.cpp:28
Qt3DCore::QBuffer Qt3DQBuffer
Definition: qgs3daxis.cpp:30
Qt3DCore::QBuffer Qt3DQBuffer