18 #include <Qt3DRender/QAttribute> 19 #include <Qt3DRender/QBuffer> 20 #include <Qt3DRender/QGeometry> 21 #include <Qt3DRender/QGeometryRenderer> 22 #include <Qt3DExtras/QPhongMaterial> 29 class LineMeshGeometry :
public Qt3DRender::QGeometry
32 LineMeshGeometry( Qt3DCore::QNode *parent =
nullptr );
36 return mVertices.size();
39 void setVertices( QList<QVector3D> vertices );
42 Qt3DRender::QAttribute *mPositionAttribute =
nullptr;
43 Qt3DRender::QBuffer *mVertexBuffer =
nullptr;
44 QList<QVector3D> mVertices;
49 LineMeshGeometry::LineMeshGeometry( Qt3DCore::QNode *parent )
51 , mPositionAttribute( new
Qt3DRender::QAttribute( this ) )
54 mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
55 mPositionAttribute->setBuffer( mVertexBuffer );
56 mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
57 mPositionAttribute->setVertexSize( 3 );
58 mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
60 addAttribute( mPositionAttribute );
63 void LineMeshGeometry::setVertices( QList<QVector3D> vertices )
65 QByteArray vertexBufferData;
66 vertexBufferData.resize( vertices.size() * 3 *
sizeof( float ) );
67 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
69 for (
const auto &v : vertices )
71 rawVertexArray[idx++] = v.x();
72 rawVertexArray[idx++] = v.y();
73 rawVertexArray[idx++] = v.z();
74 mVertices.append( v );
77 mVertexBuffer->setData( vertexBufferData );
85 class AABBMesh :
public Qt3DRender::QGeometryRenderer
88 AABBMesh( Qt3DCore::QNode *parent =
nullptr );
90 void setBoxes(
const QList<QgsAABB> &bboxes );
93 LineMeshGeometry *mLineMeshGeo =
nullptr;
97 AABBMesh::AABBMesh( Qt3DCore::QNode *parent )
100 setInstanceCount( 1 );
102 setFirstInstance( 0 );
103 setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines );
105 mLineMeshGeo =
new LineMeshGeometry(
this );
106 setGeometry( mLineMeshGeo );
109 void AABBMesh::setBoxes(
const QList<QgsAABB> &bboxes )
111 QList<QVector3D> vertices;
112 Q_FOREACH (
const QgsAABB &bbox, bboxes )
113 vertices << bbox.verticesForLines();
114 mLineMeshGeo->setVertices( vertices );
115 setVertexCount( mLineMeshGeo->vertexCount() );
122 QgsChunkBoundsEntity::QgsChunkBoundsEntity( Qt3DCore::QNode *parent )
125 mAabbMesh =
new AABBMesh;
126 addComponent( mAabbMesh );
128 Qt3DExtras::QPhongMaterial *bboxesMaterial =
new Qt3DExtras::QPhongMaterial;
129 bboxesMaterial->setAmbient( Qt::red );
130 addComponent( bboxesMaterial );
133 void QgsChunkBoundsEntity::setBoxes(
const QList<QgsAABB> &bboxes )
135 mAabbMesh->setBoxes( bboxes );
3 Axis-aligned bounding box - in world coords.