19#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
20#include <Qt3DRender/QAttribute>
21#include <Qt3DRender/QBuffer>
22#include <Qt3DRender/QGeometry>
28#include <Qt3DCore/QAttribute>
29#include <Qt3DCore/QBuffer>
30#include <Qt3DCore/QGeometry>
44QgsLineVertexData::QgsLineVertexData()
47 vertices << QVector3D();
52 altClamping = clamping;
55 renderContext = context;
59QByteArray QgsLineVertexData::createVertexBuffer()
61 QByteArray vertexBufferData;
62 vertexBufferData.resize( vertices.size() * 3 *
sizeof(
float ) );
63 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
65 for (
const auto &v : std::as_const( vertices ) )
67 rawVertexArray[idx++] = v.
x();
68 rawVertexArray[idx++] = v.y();
69 rawVertexArray[idx++] = v.z();
71 return vertexBufferData;
74QByteArray QgsLineVertexData::createIndexBuffer()
76 QByteArray indexBufferData;
77 indexBufferData.resize( indexes.size() *
sizeof(
int ) );
78 unsigned int *rawIndexArray =
reinterpret_cast<unsigned int *
>( indexBufferData.data() );
80 for (
unsigned int indexVal : std::as_const( indexes ) )
82 rawIndexArray[idx++] = indexVal;
84 return indexBufferData;
87Qt3DQGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *parent )
90 vertexBuffer->setData( createVertexBuffer() );
93 indexBuffer->setData( createIndexBuffer() );
95 QgsDebugMsgLevel( QString(
"vertex buffer %1 MB index buffer %2 MB " ).arg( vertexBuffer->data().count() / 1024. / 1024. ).arg( indexBuffer->data().count() / 1024. / 1024. ), 2 );
98 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
99 positionAttribute->setBuffer( vertexBuffer );
100 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
101 positionAttribute->setVertexSize( 3 );
102 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
103 positionAttribute->setByteOffset( 0 );
104 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
107 indexAttribute->setAttributeType( Qt3DQAttribute::IndexAttribute );
108 indexAttribute->setBuffer( indexBuffer );
109 indexAttribute->setByteOffset( 0 );
110 indexAttribute->setByteStride(
sizeof( uint ) );
111 indexAttribute->setVertexBaseType( Qt3DQAttribute::UnsignedInt );
114 geom->addAttribute( positionAttribute );
115 geom->addAttribute( indexAttribute );
120void QgsLineVertexData::addLineString(
const QgsLineString &lineString,
float extraHeightOffset )
123 indexes << vertices.count();
126 switch ( altBinding )
135 for (
int i = 0; i < lineString.
vertexCount(); ++i )
138 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, renderContext );
140 vertices << QVector3D( static_cast<float>( p.
x() - origin.x() ),
static_cast<float>( p.
y() - origin.y() ), z );
141 indexes << vertices.count() - 1;
145 indexes << vertices.count() - 1;
150void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength,
float extraHeightOffset )
153 switch ( altBinding )
162 for (
int i = 0; i < lineString.
vertexCount(); ++i )
165 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, renderContext );
166 float z2 = z + verticalLength;
169 indexes << vertices.count();
171 vertices << QVector3D( static_cast<float>( p.
x() - origin.x() ),
static_cast<float>( p.
y() - origin.y() ), z );
172 indexes << vertices.count() - 1;
173 vertices << QVector3D( static_cast<float>( p.
x() - origin.x() ),
static_cast<float>( p.
y() - origin.y() ), z2 );
174 indexes << vertices.count() - 1;
177 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)