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 : qgis::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 : qgis::as_const( indexes ) )
66 rawIndexArray[idx++] = indexVal;
68 return indexBufferData;
71 Qt3DRender::QGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *parent )
73 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
74 Qt3DRender::QBuffer *vertexBuffer =
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, parent );
76 Qt3DRender::QBuffer *vertexBuffer =
new Qt3DRender::QBuffer( parent );
78 vertexBuffer->setData( createVertexBuffer() );
80 #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
81 Qt3DRender::QBuffer *indexBuffer =
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::IndexBuffer, parent );
83 Qt3DRender::QBuffer *indexBuffer =
new Qt3DRender::QBuffer( parent );
85 indexBuffer->setData( createIndexBuffer() );
87 QgsDebugMsgLevel( QString(
"vertex buffer %1 MB index buffer %2 MB " ).arg( vertexBuffer->data().count() / 1024. / 1024. ).arg( indexBuffer->data().count() / 1024. / 1024. ), 2 );
89 Qt3DRender::QAttribute *positionAttribute =
new Qt3DRender::QAttribute( parent );
90 positionAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
91 positionAttribute->setBuffer( vertexBuffer );
92 positionAttribute->setVertexBaseType( Qt3DRender::QAttribute::Float );
93 positionAttribute->setVertexSize( 3 );
94 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
95 positionAttribute->setByteOffset( 0 );
96 positionAttribute->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
98 Qt3DRender::QAttribute *indexAttribute =
new Qt3DRender::QAttribute( parent );
99 indexAttribute->setAttributeType( Qt3DRender::QAttribute::IndexAttribute );
100 indexAttribute->setBuffer( indexBuffer );
101 indexAttribute->setByteOffset( 0 );
102 indexAttribute->setByteStride(
sizeof( uint ) );
103 indexAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedInt );
105 Qt3DRender::QGeometry *geom =
new Qt3DRender::QGeometry;
106 geom->addAttribute( positionAttribute );
107 geom->addAttribute( indexAttribute );
112 void QgsLineVertexData::addLineString(
const QgsLineString &lineString,
float extraHeightOffset )
115 indexes << vertices.count();
121 for (
int i = 0; i < lineString.
vertexCount(); ++i )
124 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, *mapSettings );
126 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
127 indexes << vertices.count() - 1;
131 indexes << vertices.count() - 1;
137 void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength,
float extraHeightOffset )
143 for (
int i = 0; i < lineString.
vertexCount(); ++i )
146 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, *mapSettings );
147 float z2 = z + verticalLength;
150 indexes << vertices.count();
152 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
153 indexes << vertices.count() - 1;
154 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z2, -( p.
y() - mapSettings->origin().y() ) );
155 indexes << vertices.count() - 1;
158 indexes << vertices.count() - 1;