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();
113 for (
int i = 0; i < lineString.
vertexCount(); ++i )
118 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
119 indexes << vertices.count() - 1;
123 indexes << vertices.count() - 1;
128 void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength,
float extraHeightOffset )
134 for (
int i = 0; i < lineString.
vertexCount(); ++i )
138 float z2 = z + verticalLength;
141 indexes << vertices.count();
143 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
144 indexes << vertices.count() - 1;
145 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z2, -( p.
y() - mapSettings->origin().y() ) );
146 indexes << vertices.count() - 1;
149 indexes << vertices.count() - 1;
AltitudeClamping
how to handle altitude of vector features
AltitudeBinding
how to handle clamping of vertices of individual features
@ AltBindCentroid
Clamp just centroid of feature.
static float clampAltitude(const QgsPoint &p, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::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.
#define QgsDebugMsgLevel(str, level)