18 #include <Qt3DRender/QBuffer> 19 #include <Qt3DExtras/QPhongMaterial> 26 LineMeshGeometry::LineMeshGeometry( Qt3DCore::QNode *parent )
28 , mPositionAttribute( new
Qt3DRender::QAttribute( this ) )
31 mPositionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
32 mPositionAttribute->setBuffer( mVertexBuffer );
33 mPositionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
34 mPositionAttribute->setVertexSize( 3 );
35 mPositionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
37 addAttribute( mPositionAttribute );
40 void LineMeshGeometry::setVertices(
const QList<QVector3D> &vertices )
42 QByteArray vertexBufferData;
43 vertexBufferData.resize( vertices.size() * 3 *
sizeof( float ) );
44 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
46 for (
const auto &v : vertices )
48 rawVertexArray[idx++] = v.x();
49 rawVertexArray[idx++] = v.y();
50 rawVertexArray[idx++] = v.z();
53 mVertexCount = vertices.count();
54 mVertexBuffer->setData( vertexBufferData );
61 AABBMesh::AABBMesh( Qt3DCore::QNode *parent )
64 setInstanceCount( 1 );
66 setFirstInstance( 0 );
67 setPrimitiveType( Qt3DRender::QGeometryRenderer::Lines );
69 mLineMeshGeo =
new LineMeshGeometry(
this );
70 setGeometry( mLineMeshGeo );
73 void AABBMesh::setBoxes(
const QList<QgsAABB> &bboxes )
75 QList<QVector3D> vertices;
76 Q_FOREACH (
const QgsAABB &bbox, bboxes )
77 vertices << bbox.verticesForLines();
78 mLineMeshGeo->setVertices( vertices );
79 setVertexCount( mLineMeshGeo->vertexCount() );
86 QgsChunkBoundsEntity::QgsChunkBoundsEntity(
Qt3DCore::QNode *parent )
89 mAabbMesh =
new AABBMesh;
90 addComponent( mAabbMesh );
92 Qt3DExtras::QPhongMaterial *bboxesMaterial =
new Qt3DExtras::QPhongMaterial;
93 bboxesMaterial->setAmbient( Qt::red );
94 addComponent( bboxesMaterial );
97 void QgsChunkBoundsEntity::setBoxes(
const QList<QgsAABB> &bboxes )
99 mAabbMesh->setBoxes( bboxes );
3 Axis-aligned bounding box - in world coords.