18 #include <Qt3DRender/QBuffer>
19 #include <Qt3DExtras/QPhongMaterial>
26 LineMeshGeometry::LineMeshGeometry( Qt3DCore::QNode *parent )
28 , mPositionAttribute( new
Qt3DRender::QAttribute( this ) )
29 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
32 , mVertexBuffer( new
Qt3DRender::QBuffer( this ) )
35 mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
36 mPositionAttribute->setBuffer( mVertexBuffer );
37 mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
38 mPositionAttribute->setVertexSize( 3 );
39 mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
41 addAttribute( mPositionAttribute );
44 void LineMeshGeometry::setVertices(
const QList<QVector3D> &vertices )
46 QByteArray vertexBufferData;
47 vertexBufferData.resize( vertices.size() * 3 *
sizeof(
float ) );
48 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
50 for (
const auto &v : vertices )
52 rawVertexArray[idx++] = v.x();
53 rawVertexArray[idx++] = v.y();
54 rawVertexArray[idx++] = v.z();
57 mVertexCount = vertices.count();
58 mVertexBuffer->setData( vertexBufferData );
65 AABBMesh::AABBMesh( Qt3DCore::QNode *parent )
68 setInstanceCount( 1 );
70 setFirstInstance( 0 );
71 setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines );
73 mLineMeshGeo =
new LineMeshGeometry(
this );
74 setGeometry( mLineMeshGeo );
77 void AABBMesh::setBoxes(
const QList<QgsAABB> &bboxes )
79 QList<QVector3D> vertices;
80 Q_FOREACH (
const QgsAABB &bbox, bboxes )
81 vertices << bbox.verticesForLines();
82 mLineMeshGeo->setVertices( vertices );
83 setVertexCount( mLineMeshGeo->vertexCount() );
90 QgsChunkBoundsEntity::QgsChunkBoundsEntity( Qt3DCore::QNode *parent )
93 mAabbMesh =
new AABBMesh;
94 addComponent( mAabbMesh );
96 Qt3DExtras::QPhongMaterial *bboxesMaterial =
new Qt3DExtras::QPhongMaterial;
97 bboxesMaterial->setAmbient( Qt::red );
98 addComponent( bboxesMaterial );
101 void QgsChunkBoundsEntity::setBoxes(
const QList<QgsAABB> &bboxes )
103 mAabbMesh->setBoxes( bboxes );