18 #include <Qt3DRender/QAttribute>
19 #include <Qt3DRender/QBuffer>
20 #include <Qt3DRender/QGeometry>
29 QgsLineVertexData::QgsLineVertexData()
32 vertices << QVector3D();
37 altClamping = clamping;
43 QByteArray QgsLineVertexData::createVertexBuffer()
45 QByteArray vertexBufferData;
46 vertexBufferData.resize( vertices.size() * 3 *
sizeof(
float ) );
47 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
49 for (
const auto &v : std::as_const( vertices ) )
51 rawVertexArray[idx++] = v.x();
52 rawVertexArray[idx++] = v.y();
53 rawVertexArray[idx++] = v.z();
55 return vertexBufferData;
58 QByteArray QgsLineVertexData::createIndexBuffer()
60 QByteArray indexBufferData;
61 indexBufferData.resize( indexes.size() *
sizeof(
int ) );
62 unsigned int *rawIndexArray =
reinterpret_cast<unsigned int *
>( indexBufferData.data() );
64 for (
unsigned int indexVal : std::as_const( indexes ) )
66 rawIndexArray[idx++] = indexVal;
68 return indexBufferData;
71 Qt3DRender::QGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *parent )
73 Qt3DRender::QBuffer *vertexBuffer =
new Qt3DRender::QBuffer( parent );
74 vertexBuffer->setData( createVertexBuffer() );
76 Qt3DRender::QBuffer *indexBuffer =
new Qt3DRender::QBuffer( parent );
77 indexBuffer->setData( createIndexBuffer() );
79 QgsDebugMsgLevel( QString(
"vertex buffer %1 MB index buffer %2 MB " ).arg( vertexBuffer->data().count() / 1024. / 1024. ).arg( indexBuffer->data().count() / 1024. / 1024. ), 2 );
81 Qt3DRender::QAttribute *positionAttribute =
new Qt3DRender::QAttribute( parent );
82 positionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
83 positionAttribute->setBuffer( vertexBuffer );
84 positionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
85 positionAttribute->setVertexSize( 3 );
86 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
87 positionAttribute->setByteOffset( 0 );
88 positionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
90 Qt3DRender::QAttribute *indexAttribute =
new Qt3DRender::QAttribute( parent );
91 indexAttribute->setAttributeType( Qt3DRender::QAttribute::IndexAttribute );
92 indexAttribute->setBuffer( indexBuffer );
93 indexAttribute->setByteOffset( 0 );
94 indexAttribute->setByteStride(
sizeof( uint ) );
95 indexAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedInt );
97 Qt3DRender::QGeometry *geom =
new Qt3DRender::QGeometry;
98 geom->addAttribute( positionAttribute );
99 geom->addAttribute( indexAttribute );
104 void QgsLineVertexData::addLineString(
const QgsLineString &lineString,
float extraHeightOffset )
107 indexes << vertices.count();
110 switch ( altBinding )
119 for (
int i = 0; i < lineString.
vertexCount(); ++i )
124 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
125 indexes << vertices.count() - 1;
129 indexes << vertices.count() - 1;
134 void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength,
float extraHeightOffset )
137 switch ( altBinding )
146 for (
int i = 0; i < lineString.
vertexCount(); ++i )
150 float z2 = z + verticalLength;
153 indexes << vertices.count();
155 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
156 indexes << vertices.count() - 1;
157 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z2, -( p.
y() - mapSettings->origin().y() ) );
158 indexes << vertices.count() - 1;
161 indexes << vertices.count() - 1;