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;
57QByteArray QgsLineVertexData::createVertexBuffer()
59 QByteArray vertexBufferData;
60 vertexBufferData.resize( vertices.size() * 3 *
sizeof(
float ) );
61 float *rawVertexArray =
reinterpret_cast<float *
>( vertexBufferData.data() );
63 for (
const auto &v : std::as_const( vertices ) )
65 rawVertexArray[idx++] = v.x();
66 rawVertexArray[idx++] = v.y();
67 rawVertexArray[idx++] = v.z();
69 return vertexBufferData;
72QByteArray QgsLineVertexData::createIndexBuffer()
74 QByteArray indexBufferData;
75 indexBufferData.resize( indexes.size() *
sizeof(
int ) );
76 unsigned int *rawIndexArray =
reinterpret_cast<unsigned int *
>( indexBufferData.data() );
78 for (
unsigned int indexVal : std::as_const( indexes ) )
80 rawIndexArray[idx++] = indexVal;
82 return indexBufferData;
85Qt3DQGeometry *QgsLineVertexData::createGeometry( Qt3DCore::QNode *parent )
88 vertexBuffer->setData( createVertexBuffer() );
91 indexBuffer->setData( createIndexBuffer() );
93 QgsDebugMsgLevel( QString(
"vertex buffer %1 MB index buffer %2 MB " ).arg( vertexBuffer->data().count() / 1024. / 1024. ).arg( indexBuffer->data().count() / 1024. / 1024. ), 2 );
96 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
97 positionAttribute->setBuffer( vertexBuffer );
98 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
99 positionAttribute->setVertexSize( 3 );
100 positionAttribute->setByteStride( 3 *
sizeof(
float ) );
101 positionAttribute->setByteOffset( 0 );
102 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
105 indexAttribute->setAttributeType( Qt3DQAttribute::IndexAttribute );
106 indexAttribute->setBuffer( indexBuffer );
107 indexAttribute->setByteOffset( 0 );
108 indexAttribute->setByteStride(
sizeof( uint ) );
109 indexAttribute->setVertexBaseType( Qt3DQAttribute::UnsignedInt );
112 geom->addAttribute( positionAttribute );
113 geom->addAttribute( indexAttribute );
118void QgsLineVertexData::addLineString(
const QgsLineString &lineString,
float extraHeightOffset )
121 indexes << vertices.count();
124 switch ( altBinding )
133 for (
int i = 0; i < lineString.
vertexCount(); ++i )
138 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
139 indexes << vertices.count() - 1;
143 indexes << vertices.count() - 1;
148void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength,
float extraHeightOffset )
151 switch ( altBinding )
160 for (
int i = 0; i < lineString.
vertexCount(); ++i )
164 float z2 = z + verticalLength;
167 indexes << vertices.count();
169 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
170 indexes << vertices.count() - 1;
171 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z2, -( p.
y() - mapSettings->origin().y() ) );
172 indexes << vertices.count() - 1;
175 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 height, const QgsPoint ¢roid, const Qgs3DMapSettings &map)
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.
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry
#define QgsDebugMsgLevel(str, level)