18#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
19#include <Qt3DRender/QAttribute>
20#include <Qt3DRender/QBuffer>
21#include <Qt3DRender/QGeometry>
27#include <Qt3DCore/QAttribute>
28#include <Qt3DCore/QBuffer>
29#include <Qt3DCore/QGeometry>
43QgsLineVertexData::QgsLineVertexData()
46 vertices << QVector3D();
51 altClamping = clamping;
54 renderContext = context;
58QByteArray QgsLineVertexData::createVertexBuffer()
60 QByteArray vertexBufferData;
61 vertexBufferData.resize( vertices.size() * 3 *
sizeof(
float ) );
62 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
64 for (
const auto &v : std::as_const( vertices ) )
66 rawVertexArray[idx++] = v.
x();
67 rawVertexArray[idx++] = v.y();
68 rawVertexArray[idx++] = v.z();
70 return vertexBufferData;
73QByteArray QgsLineVertexData::createIndexBuffer()
75 QByteArray indexBufferData;
76 indexBufferData.resize( indexes.size() *
sizeof(
int ) );
77 unsigned int *rawIndexArray =
reinterpret_cast<unsigned int *
>( indexBufferData.data() );
79 for (
unsigned int indexVal : std::as_const( indexes ) )
81 rawIndexArray[idx++] = indexVal;
83 return indexBufferData;
86Qt3DQGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *parent )
89 vertexBuffer->setData( createVertexBuffer() );
92 indexBuffer->setData( createIndexBuffer() );
94 QgsDebugMsgLevel( QString(
"vertex buffer %1 MB index buffer %2 MB " ).arg( vertexBuffer->data().count() / 1024. / 1024. ).arg( indexBuffer->data().count() / 1024. / 1024. ), 2 );
97 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
98 positionAttribute->setBuffer( vertexBuffer );
99 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
100 positionAttribute->setVertexSize( 3 );
101 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
102 positionAttribute->setByteOffset( 0 );
103 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
106 indexAttribute->setAttributeType( Qt3DQAttribute::IndexAttribute );
107 indexAttribute->setBuffer( indexBuffer );
108 indexAttribute->setByteOffset( 0 );
109 indexAttribute->setByteStride(
sizeof( uint ) );
110 indexAttribute->setVertexBaseType( Qt3DQAttribute::UnsignedInt );
113 geom->addAttribute( positionAttribute );
114 geom->addAttribute( indexAttribute );
119void QgsLineVertexData::addLineString(
const QgsLineString &lineString,
float extraHeightOffset )
122 indexes << vertices.count();
125 switch ( altBinding )
134 for (
int i = 0; i < lineString.
vertexCount(); ++i )
137 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, renderContext );
139 vertices << QVector3D( static_cast< float >( p.
x() - origin.x() ),
140 static_cast< float >( p.
y() - origin.y() ),
142 indexes << vertices.count() - 1;
146 indexes << vertices.count() - 1;
151void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength,
float extraHeightOffset )
154 switch ( altBinding )
163 for (
int i = 0; i < lineString.
vertexCount(); ++i )
166 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, renderContext );
167 float z2 = z + verticalLength;
170 indexes << vertices.count();
172 vertices << QVector3D( static_cast< float >( p.
x() - origin.x() ),
173 static_cast< float >( p.
y() - origin.y() ),
175 indexes << vertices.count() - 1;
176 vertices << QVector3D( static_cast< float >( p.
x() - origin.x() ),
177 static_cast< float >( p.
y() - origin.y() ),
179 indexes << vertices.count() - 1;
182 indexes << vertices.count() - 1;
AltitudeClamping
Altitude clamping.
AltitudeBinding
Altitude binding.
@ Centroid
Clamp just centroid of feature.
@ Vertex
Clamp every vertex of feature.
static float clampAltitude(const QgsPoint &p, Qgis::AltitudeClamping altClamp, Qgis::AltitudeBinding altBind, float offset, const QgsPoint ¢roid, const Qgs3DRenderContext &context)
Clamps altitude of a vertex according to the settings, returns Z value.
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
Line string geometry type, with support for z-dimension and m-values.
QgsPoint pointN(int i) const
Returns the specified point from inside the line string.
QgsPoint centroid() const override
Returns the centroid of the geometry.
Point geometry type, with support for z-dimension and m-values.
Class for storage of 3D vectors similar to QVector3D, with the difference that it uses double precisi...
double x() const
Returns X coordinate.
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
#define QgsDebugMsgLevel(str, level)