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 Qt3DRender::QBuffer *vertexBuffer =
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, parent );
74 vertexBuffer->setData( createVertexBuffer() );
76 Qt3DRender::QBuffer *indexBuffer =
new Qt3DRender::QBuffer( Qt3DRender::QBuffer::IndexBuffer, parent );
77 indexBuffer->setData( createIndexBuffer() );
79 QgsDebugMsg( QString(
"vertex buffer %1 MB index buffer %2 MB " ).arg( vertexBuffer->data().count() / 1024. / 1024. ).arg( indexBuffer->data().count() / 1024. / 1024. ) );
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->setName( Qt3DRender::QAttribute::defaultPositionAttributeName() );
88 Qt3DRender::QAttribute *indexAttribute =
new Qt3DRender::QAttribute( parent );
89 indexAttribute->setAttributeType( Qt3DRender::QAttribute::IndexAttribute );
90 indexAttribute->setBuffer( indexBuffer );
91 indexAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedInt );
93 Qt3DRender::QGeometry *geom =
new Qt3DRender::QGeometry;
94 geom->addAttribute( positionAttribute );
95 geom->addAttribute( indexAttribute );
99 void QgsLineVertexData::addLineString(
const QgsLineString &lineString,
float extraHeightOffset )
102 indexes << vertices.count();
108 for (
int i = 0; i < lineString.
vertexCount(); ++i )
111 float z =
Qgs3DUtils::clampAltitude( p, altClamping, altBinding, baseHeight + extraHeightOffset, centroid, *mapSettings );
113 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
114 indexes << vertices.count() - 1;
118 indexes << vertices.count() - 1;
124 void QgsLineVertexData::addVerticalLines(
const QgsLineString &lineString,
float verticalLength )
130 for (
int i = 0; i < lineString.
vertexCount(); ++i )
134 float z2 = z + verticalLength;
137 indexes << vertices.count();
139 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z, -( p.
y() - mapSettings->origin().y() ) );
140 indexes << vertices.count() - 1;
141 vertices << QVector3D( p.
x() - mapSettings->origin().x(), z2, -( p.
y() - mapSettings->origin().y() ) );
142 indexes << vertices.count() - 1;
145 indexes << vertices.count() - 1;
AltitudeClamping
how to handle altitude of vector features
QgsPoint centroid() const override
Returns the centroid of the geometry.
3 Definition of the world
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
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.
Point geometry type, with support for z-dimension and m-values.
AltitudeBinding
how to handle clamping of vertices of individual features
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.
Clamp just centroid of feature.